1
0

Giant Update

This commit is contained in:
Wian Drs
2026-07-31 13:57:11 +07:00
parent f68d967c8b
commit b0d08211ec
112 changed files with 6674 additions and 3 deletions
+78
View File
@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature;
use App\Models\Customer;
use App\Models\Tenant;
use App\Models\User;
use App\Services\Billing\BillingProfileService;
use App\Services\Billing\InvoiceService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class BillingWorkflowTest extends TestCase
{
use RefreshDatabase;
public function test_invoice_moves_from_running_to_overdue_and_paid(): void
{
$tenant = Tenant::create(['tenant_code' => 'BILL-A', 'tenant_name' => 'Billing Tenant']);
$owner = User::factory()->create(['access_level' => 'tenant_owner']);
$owner->userTenants()->create(['tenant_id' => $tenant->id, 'is_default' => true]);
$profile = app(BillingProfileService::class)->create([
'name' => 'Bulanan Reguler',
'invoice_day' => 1,
'send_day' => 2,
'warning_day' => 10,
'isolation_day' => 15,
'tax_type' => 'exclusive',
'tax_rate' => 11,
], $owner, $tenant->id);
$customer = Customer::create([
'tenant_id' => $tenant->id,
'customer_code' => 'CUST-BILL',
'name' => 'Customer Billing',
'status' => 'active',
'billing_profile_id' => $profile->id,
]);
$service = app(InvoiceService::class);
$invoice = $service->create([
'customer_id' => $customer->id,
'period_start' => now()->startOfMonth()->toDateString(),
'period_end' => now()->endOfMonth()->toDateString(),
'issue_date' => now()->subDays(20)->toDateString(),
'send_date' => now()->subDays(18)->toDateString(),
'warning_date' => now()->subDays(10)->toDateString(),
'isolation_date' => now()->subDay()->toDateString(),
'subtotal' => 100000,
], $owner, $tenant->id);
$this->assertSame('overdue', $invoice->status);
$this->assertSame('111000.00', $invoice->total);
$this->assertCount(1, $service->list('overdue', ['per_page' => 10], $owner, $tenant->id));
$paid = $service->pay($invoice, ['amount' => 111000, 'payment_method' => 'cash'], $owner);
$this->assertSame('paid', $paid->status);
$this->assertSame('paid', $paid->payment_status);
$this->assertSame('0.00', $paid->balance);
$this->assertCount(1, $service->list('paid', ['per_page' => 10], $owner, $tenant->id));
}
public function test_profile_and_invoice_lists_are_tenant_scoped(): void
{
$tenantA = Tenant::create(['tenant_code' => 'BILL-LA', 'tenant_name' => 'Billing A']);
$tenantB = Tenant::create(['tenant_code' => 'BILL-LB', 'tenant_name' => 'Billing B']);
$owner = User::factory()->create(['access_level' => 'tenant_owner']);
$owner->userTenants()->create(['tenant_id' => $tenantA->id, 'is_default' => true]);
$master = User::factory()->create(['is_master' => true, 'access_level' => 'master_admin']);
$service = app(BillingProfileService::class);
$base = ['invoice_day' => 1, 'send_day' => 2, 'warning_day' => 10, 'isolation_day' => 15, 'tax_type' => 'non_tax'];
$service->create([...$base, 'name' => 'Profile A'], $owner, $tenantA->id);
$service->create([...$base, 'name' => 'Profile B', 'tenant_id' => $tenantB->id], $master, null);
$result = $service->list(['per_page' => 100], $owner, $tenantA->id);
$this->assertSame(['Profile A'], $result->getCollection()->pluck('name')->all());
}
}
+98
View File
@@ -0,0 +1,98 @@
<?php
namespace Tests\Feature;
use App\Models\BillingProfile;
use App\Models\NasMikrotik;
use App\Models\NasPackageProfile;
use App\Models\Tenant;
use App\Models\User;
use App\Models\WilayahDesa;
use App\Models\WilayahKabupaten;
use App\Models\WilayahKecamatan;
use App\Models\WilayahProvinsi;
use App\Services\Customer\CustomerService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CustomerWorkflowTest extends TestCase
{
use RefreshDatabase;
public function test_customer_moves_through_order_active_inactive_and_trash_lifecycle(): void
{
$tenant = Tenant::create(['tenant_code' => 'CUST-A', 'tenant_name' => 'Customer Tenant']);
$owner = User::factory()->create(['access_level' => 'tenant_owner']);
$owner->userTenants()->create(['tenant_id' => $tenant->id, 'is_default' => true]);
$provinsi = WilayahProvinsi::create(['kode' => '01', 'nama' => 'Provinsi']);
$kabupaten = WilayahKabupaten::create(['provinsi_id' => $provinsi->id, 'kode' => '0101', 'nama' => 'Kabupaten']);
$kecamatan = WilayahKecamatan::create(['kabupaten_id' => $kabupaten->id, 'kode' => '010101', 'nama' => 'Kecamatan']);
$desa = WilayahDesa::create(['kecamatan_id' => $kecamatan->id, 'kode' => '01010101', 'nama' => 'Desa']);
$profile = NasPackageProfile::create([
'tenant_id' => $tenant->id,
'name' => '10 Mbps',
'service_type' => 'ppp',
]);
$nas = NasMikrotik::create([
'tenant_id' => $tenant->id,
'name' => 'Router Customer',
'connection_type' => 'api',
'host' => '10.0.0.1',
]);
$billingProfile = BillingProfile::create([
'tenant_id' => $tenant->id,
'name' => 'Tagihan Customer',
'invoice_day' => 1,
'send_day' => 2,
'warning_day' => 10,
'isolation_day' => 15,
'tax_type' => 'non_tax',
]);
$service = app(CustomerService::class);
$customer = $service->create([
'name' => 'Customer Satu',
'installation_address' => 'Jalan Pengujian',
'provinsi_id' => $provinsi->id,
'kabupaten_id' => $kabupaten->id,
'kecamatan_id' => $kecamatan->id,
'desa_id' => $desa->id,
], $owner, $tenant->id);
$this->assertSame('order', $customer->status);
$customer = $service->activate($customer, [
'package_profile_id' => $profile->id,
'nas_mikrotik_id' => $nas->id,
'billing_profile_id' => $billingProfile->id,
]);
$this->assertSame('active', $customer->status);
$this->assertNotNull($customer->activated_at);
$customer = $service->deactivate($customer);
$this->assertSame('inactive', $customer->status);
$service->trash($customer);
$this->assertNotNull($customer->fresh()->deleted_at);
$restored = $service->restore($service->find($customer->id, true));
$this->assertNull($restored->deleted_at);
$this->assertSame('inactive', $restored->status);
}
public function test_customer_list_is_isolated_by_active_tenant(): void
{
$tenantA = Tenant::create(['tenant_code' => 'CUST-LA', 'tenant_name' => 'Tenant A']);
$tenantB = Tenant::create(['tenant_code' => 'CUST-LB', 'tenant_name' => 'Tenant B']);
$owner = User::factory()->create(['access_level' => 'tenant_owner']);
$owner->userTenants()->create(['tenant_id' => $tenantA->id, 'is_default' => true]);
$service = app(CustomerService::class);
$service->create(['name' => 'Customer A'], $owner, $tenantA->id);
$master = User::factory()->create(['is_master' => true, 'access_level' => 'master_admin']);
$service->create(['tenant_id' => $tenantB->id, 'name' => 'Customer B'], $master, null);
$result = $service->list('orders', ['per_page' => 100], $owner, $tenantA->id);
$this->assertSame(['Customer A'], $result->getCollection()->pluck('name')->all());
}
}