|
|
|
@@ -85,6 +85,65 @@ it('previews monthly split changes without moving orders or creating collections
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$aprilOrder['id']))->toBe((int)$invoiceCollection['id']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('previews only explicit monthly split invoice collection ids', function (): void {
|
|
|
|
|
api_test_covers('POST /collected-invoices/split-by-month', 'preview-scope');
|
|
|
|
|
|
|
|
|
|
$customer = api_fixtures()->createUser(['display_name' => 'Scoped Preview Monthly Split Customer']);
|
|
|
|
|
$department = api_fixtures()->createDepartment();
|
|
|
|
|
$targetCollection = api_fixtures()->createInvoiceCollection([
|
|
|
|
|
'customer_number' => $customer['customer_number'],
|
|
|
|
|
]);
|
|
|
|
|
$ignoredCollection = api_fixtures()->createInvoiceCollection([
|
|
|
|
|
'customer_number' => $customer['customer_number'],
|
|
|
|
|
]);
|
|
|
|
|
$targetMarchOrder = api_fixtures()->createOrder([
|
|
|
|
|
'customer_id' => $customer['customer_number'],
|
|
|
|
|
'department_id' => $department['id'],
|
|
|
|
|
'invoice_collection_id' => $targetCollection['id'],
|
|
|
|
|
'created_at' => '2096-03-15 10:00:00',
|
|
|
|
|
]);
|
|
|
|
|
$targetAprilOrder = api_fixtures()->createOrder([
|
|
|
|
|
'customer_id' => $customer['customer_number'],
|
|
|
|
|
'department_id' => $department['id'],
|
|
|
|
|
'invoice_collection_id' => $targetCollection['id'],
|
|
|
|
|
'created_at' => '2096-04-02 10:00:00',
|
|
|
|
|
]);
|
|
|
|
|
$ignoredMarchOrder = api_fixtures()->createOrder([
|
|
|
|
|
'customer_id' => $customer['customer_number'],
|
|
|
|
|
'department_id' => $department['id'],
|
|
|
|
|
'invoice_collection_id' => $ignoredCollection['id'],
|
|
|
|
|
'created_at' => '2096-03-16 10:00:00',
|
|
|
|
|
]);
|
|
|
|
|
$ignoredAprilOrder = api_fixtures()->createOrder([
|
|
|
|
|
'customer_id' => $customer['customer_number'],
|
|
|
|
|
'department_id' => $department['id'],
|
|
|
|
|
'invoice_collection_id' => $ignoredCollection['id'],
|
|
|
|
|
'created_at' => '2096-04-03 10:00:00',
|
|
|
|
|
]);
|
|
|
|
|
$session = api_fixtures()->createUserSession(['split_collected_invoice']);
|
|
|
|
|
|
|
|
|
|
$response = api_client()->post('/collected-invoices/split-by-month', [
|
|
|
|
|
'dateFrom' => '2096-03-01',
|
|
|
|
|
'dateTo' => '2096-04-30',
|
|
|
|
|
'invoice_collection_ids' => [$targetCollection['id']],
|
|
|
|
|
'preview' => true,
|
|
|
|
|
], $session['headers']);
|
|
|
|
|
|
|
|
|
|
$response
|
|
|
|
|
->assertStatus(200)
|
|
|
|
|
->assertEnvelope()
|
|
|
|
|
->assertSuccess();
|
|
|
|
|
|
|
|
|
|
$payload = $response->data();
|
|
|
|
|
expect($payload['processed_count'] ?? null)->toBe(1)
|
|
|
|
|
->and($payload['changed_count'] ?? null)->toBe(1)
|
|
|
|
|
->and($payload['changed'][0]['invoice_collection_id'] ?? null)->toBe((int)$targetCollection['id'])
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$targetMarchOrder['id']))->toBe((int)$targetCollection['id'])
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$targetAprilOrder['id']))->toBe((int)$targetCollection['id'])
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$ignoredMarchOrder['id']))->toBe((int)$ignoredCollection['id'])
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$ignoredAprilOrder['id']))->toBe((int)$ignoredCollection['id']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('splits a selected March and April collected invoice into monthly collections', function (): void {
|
|
|
|
|
api_test_covers('POST /collected-invoices/split-by-month', 'happy');
|
|
|
|
|
|
|
|
|
@@ -139,6 +198,74 @@ it('splits a selected March and April collected invoice into monthly collections
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('splits only explicit monthly split invoice collection ids', function (): void {
|
|
|
|
|
api_test_covers('POST /collected-invoices/split-by-month', 'scope');
|
|
|
|
|
|
|
|
|
|
$customer = api_fixtures()->createUser(['display_name' => 'Scoped Monthly Split Customer']);
|
|
|
|
|
$department = api_fixtures()->createDepartment();
|
|
|
|
|
$targetCollection = api_fixtures()->createInvoiceCollection([
|
|
|
|
|
'customer_number' => $customer['customer_number'],
|
|
|
|
|
'created_at' => '2096-03-01 00:00:01',
|
|
|
|
|
]);
|
|
|
|
|
$ignoredCollection = api_fixtures()->createInvoiceCollection([
|
|
|
|
|
'customer_number' => $customer['customer_number'],
|
|
|
|
|
'created_at' => '2096-03-01 00:00:01',
|
|
|
|
|
]);
|
|
|
|
|
$targetMarchOrder = api_fixtures()->createOrder([
|
|
|
|
|
'customer_id' => $customer['customer_number'],
|
|
|
|
|
'department_id' => $department['id'],
|
|
|
|
|
'invoice_collection_id' => $targetCollection['id'],
|
|
|
|
|
'created_at' => '2096-03-15 10:00:00',
|
|
|
|
|
]);
|
|
|
|
|
$targetAprilOrder = api_fixtures()->createOrder([
|
|
|
|
|
'customer_id' => $customer['customer_number'],
|
|
|
|
|
'department_id' => $department['id'],
|
|
|
|
|
'invoice_collection_id' => $targetCollection['id'],
|
|
|
|
|
'created_at' => '2096-04-02 10:00:00',
|
|
|
|
|
]);
|
|
|
|
|
$ignoredMarchOrder = api_fixtures()->createOrder([
|
|
|
|
|
'customer_id' => $customer['customer_number'],
|
|
|
|
|
'department_id' => $department['id'],
|
|
|
|
|
'invoice_collection_id' => $ignoredCollection['id'],
|
|
|
|
|
'created_at' => '2096-03-16 10:00:00',
|
|
|
|
|
]);
|
|
|
|
|
$ignoredAprilOrder = api_fixtures()->createOrder([
|
|
|
|
|
'customer_id' => $customer['customer_number'],
|
|
|
|
|
'department_id' => $department['id'],
|
|
|
|
|
'invoice_collection_id' => $ignoredCollection['id'],
|
|
|
|
|
'created_at' => '2096-04-03 10:00:00',
|
|
|
|
|
]);
|
|
|
|
|
$session = api_fixtures()->createUserSession(['split_collected_invoice']);
|
|
|
|
|
$createdCollectionIds = [];
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$response = api_client()->post('/collected-invoices/split-by-month', [
|
|
|
|
|
'dateFrom' => '2096-03-01',
|
|
|
|
|
'dateTo' => '2096-04-30',
|
|
|
|
|
'invoice_collection_ids' => [$targetCollection['id']],
|
|
|
|
|
], $session['headers']);
|
|
|
|
|
|
|
|
|
|
$response
|
|
|
|
|
->assertStatus(200)
|
|
|
|
|
->assertEnvelope()
|
|
|
|
|
->assertSuccess();
|
|
|
|
|
|
|
|
|
|
$payload = $response->data();
|
|
|
|
|
$createdCollectionIds = (array)($payload['changed'][0]['created_invoice_collection_ids'] ?? []);
|
|
|
|
|
$aprilCollectionId = (int)($createdCollectionIds[0] ?? 0);
|
|
|
|
|
|
|
|
|
|
expect($payload['processed_count'] ?? null)->toBe(1)
|
|
|
|
|
->and($payload['changed_count'] ?? null)->toBe(1)
|
|
|
|
|
->and($aprilCollectionId)->toBeGreaterThan(0)
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$targetMarchOrder['id']))->toBe((int)$targetCollection['id'])
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$targetAprilOrder['id']))->toBe($aprilCollectionId)
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$ignoredMarchOrder['id']))->toBe((int)$ignoredCollection['id'])
|
|
|
|
|
->and(monthly_split_order_collection_id((int)$ignoredAprilOrder['id']))->toBe((int)$ignoredCollection['id']);
|
|
|
|
|
} finally {
|
|
|
|
|
monthly_split_cleanup_collections($createdCollectionIds);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('sets closed_at to month end when split month has ended', function (): void {
|
|
|
|
|
api_test_covers('POST /collected-invoices/split-by-month', 'closed-at');
|
|
|
|
|
|
|
|
|
@@ -345,3 +472,27 @@ it('rejects invalid monthly split date ranges', function (): void {
|
|
|
|
|
->assertEnvelope()
|
|
|
|
|
->assertSuccess(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects invalid explicit monthly split invoice collection ids', function (): void {
|
|
|
|
|
api_test_covers('POST /collected-invoices/split-by-month', 'invalid-scope');
|
|
|
|
|
|
|
|
|
|
$session = api_fixtures()->createUserSession(['split_collected_invoice']);
|
|
|
|
|
|
|
|
|
|
api_client()->post('/collected-invoices/split-by-month', [
|
|
|
|
|
'dateFrom' => '2096-03-01',
|
|
|
|
|
'dateTo' => '2096-04-30',
|
|
|
|
|
'invoice_collection_ids' => ['not-a-number'],
|
|
|
|
|
], $session['headers'])
|
|
|
|
|
->assertStatus(400)
|
|
|
|
|
->assertEnvelope()
|
|
|
|
|
->assertSuccess(false);
|
|
|
|
|
|
|
|
|
|
api_client()->post('/collected-invoices/split-by-month', [
|
|
|
|
|
'dateFrom' => '2096-03-01',
|
|
|
|
|
'dateTo' => '2096-04-30',
|
|
|
|
|
'invoice_collection_ids' => [],
|
|
|
|
|
], $session['headers'])
|
|
|
|
|
->assertStatus(400)
|
|
|
|
|
->assertEnvelope()
|
|
|
|
|
->assertSuccess(false);
|
|
|
|
|
});
|
|
|
|
|