Implementa conferencia de facturas e consumo por empresa
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PurchasingRole;
|
||||
use App\Models\Budget;
|
||||
use App\Models\User;
|
||||
use App\Services\BudgetWorkflow;
|
||||
use App\Services\ConflictGuard;
|
||||
use App\Services\InvoiceWorkflow;
|
||||
use App\Services\ReceiptWorkflow;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
require_once __DIR__.'/ReceiptFixture.php';
|
||||
|
||||
/** Synthetic data: receiptFixture enforces an isolated test database. */
|
||||
function invoiceFixture(): array
|
||||
{
|
||||
$f = receiptFixture();
|
||||
app(ReceiptWorkflow::class)->confirm($f['receiver'], $f['order'], receiptPayload($f, '1.000'));
|
||||
$author = User::factory()->create(['tenant_id' => $f['tenant']->id, 'purchasing_role' => PurchasingRole::Finance]);
|
||||
$validator = User::factory()->create(['tenant_id' => $f['tenant']->id, 'purchasing_role' => PurchasingRole::Finance]);
|
||||
auth()->guard()->setUser($author);
|
||||
Budget::query()->create(['tenant_id' => $author->tenant_id, 'cost_center_id' => $f['r']->cost_center_id, 'year' => now()->year, 'amount_minor' => 20000, 'includes_tax' => true, 'created_by' => $author->id, 'approved_by' => $validator->id, 'reason' => 'Somente para teste isolado']);
|
||||
DB::transaction(function () use ($author, $f) {
|
||||
app(ConflictGuard::class)->lockCompany($author);
|
||||
app(BudgetWorkflow::class)->record($author, $f['r'], 'reserve', 10000, 10000);
|
||||
app(BudgetWorkflow::class)->record($author, $f['r'], 'commit', 10000, 10000);
|
||||
});
|
||||
$data = ['number' => 'FT-PG-1', 'issued_on' => today()->format('Y-m-d'), 'subtotal' => '60.00', 'tax' => '0.00', 'total' => '60.00', 'items' => [['purchase_order_item_id' => $f['line']->id, 'quantity' => '0.600', 'unit' => 'cx', 'unit_price' => '100.00', 'tax_rate' => '0']]];
|
||||
$invoice = app(InvoiceWorkflow::class)->register($author, $f['order'], $data);
|
||||
|
||||
return [...$f, 'author' => $author, 'validator' => $validator, 'invoice' => $invoice, 'data' => $data];
|
||||
}
|
||||
Reference in New Issue
Block a user