@@ -8,6 +8,7 @@ use App\Models\PurchaseAward;
|
||||
use App\Models\Quotation;
|
||||
use App\Models\StockMovement;
|
||||
use App\Models\User;
|
||||
use App\Services\AgreementOrderLimits;
|
||||
use App\Services\ConflictGuard;
|
||||
use App\Services\InventoryDispositions;
|
||||
use App\Services\InventoryLots;
|
||||
@@ -18,6 +19,7 @@ use App\Services\ReceiptWorkflow;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use App\Services\StockWorkflow;
|
||||
use App\Services\SupplyCoordination;
|
||||
use App\Services\SupplyPlanning;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@@ -203,6 +205,17 @@ test('confirmed delivery feeds replenishment in base units and supplies the same
|
||||
expect($coordination->remainingDelivery($record))->toBe(6000)
|
||||
->and($coordination->events($this->f['stock']->id, $this->f['warehouse']->id, today()->toDateString())['receipts'][0]['quantity'])->toBe(6000)
|
||||
->and(StockMovement::query()->sole()->quantity_milli)->toBe(18000);
|
||||
$csv = $this->get('/compras/fornecimento.csv?view=deliveries')->assertOk()->streamedContent();
|
||||
$stream = fopen('php://temp', 'w+');
|
||||
fwrite($stream, $csv);
|
||||
rewind($stream);
|
||||
$rows = [];
|
||||
while (($row = fgetcsv($stream, null, ';', '"', '')) !== false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
fclose($stream);
|
||||
expect($rows[3][8])->toBe('2')->and($rows[3][9])->toBe('cx')->and($rows[3][11])->toBe('6')
|
||||
->and($rows[3][16])->toBe('un')->and($rows[3][17])->toBe('12/1')->and($rows[3][18])->toBe($this->conversion['source']);
|
||||
$bad = $data;
|
||||
$bad['conversion']['numerator'] = '24';
|
||||
expect(fn () => $coordination->save($this->f['receiver'], 'delivery', supplyInput($bad, 'save', $record)))->toThrow(ValidationException::class);
|
||||
@@ -230,3 +243,51 @@ test('receipt reversal negates the physical movement and restores documentary pe
|
||||
->and(app(ReceiptWorkflow::class)->progress($this->f['order'])['lines'][0]['delivery_pending_milli'])->toBe(2000)
|
||||
->and(app(StockWorkflow::class)->balance($this->f['stock']->id, $this->f['warehouse']->id)['quantity'])->toBe(0);
|
||||
});
|
||||
|
||||
test('receipt reuses the per order agreement conversion and destination without reentering the frozen basis', function () {
|
||||
config(['agreement_order_limits.qa_enabled' => true]);
|
||||
supplyGrant($this->f['issuer'], ['procurement', 'supply_prepare', 'supply_read']);
|
||||
supplyGrant($this->f['receiver'], ['warehouse', 'supply_review']);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$planning = app(SupplyPlanning::class);
|
||||
$draft = $planning->save($this->f['issuer'], 'agreement', supplyInput(['stock_item_id' => $this->f['stock']->id, 'warehouse_id' => $this->f['warehouse']->id,
|
||||
'supplier_id' => $this->f['order']->supplier_id, 'habitual' => false, 'valid_from' => today()->toDateString(), 'valid_until' => today()->addMonth()->toDateString(),
|
||||
'origin' => 'local', 'currency' => 'MZN', 'price_minor' => 10000, 'lead_days' => 4, 'reference' => 'QA-ORDER-RECEIPT-BRIDGE', 'order_limit_amount' => '200.00', 'order_limit_quantity' => '24.000']));
|
||||
$this->actingAs($this->f['receiver']);
|
||||
$agreement = $planning->save($this->f['receiver'], 'agreement', supplyInput([], 'approve', $draft));
|
||||
// A new synthetic issued source; existing immutable fixture orders are never amended retroactively.
|
||||
$request = $this->f['r']->replicate();
|
||||
$request->forceFill(['number' => 'REQ-CONTRACT-BRIDGE'])->save();
|
||||
$item = $this->f['r']->items()->sole()->replicate();
|
||||
$item->forceFill(['requisition_id' => $request->id, 'catalogue_snapshot' => ['stock_item_id' => $this->f['stock']->id]])->save();
|
||||
$oldAward = PurchaseAward::query()->findOrFail($this->f['order']->purchase_award_id);
|
||||
$quote = Quotation::query()->findOrFail($oldAward->quotation_id)->replicate();
|
||||
$quote->forceFill(['requisition_id' => $request->id])->save();
|
||||
$award = $oldAward->replicate();
|
||||
$award->forceFill(['requisition_id' => $request->id, 'quotation_id' => $quote->id])->save();
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$frozen = DB::transaction(function () use ($request, $quote, $item, $agreement) {
|
||||
app(ConflictGuard::class)->lockCompany($this->f['issuer']);
|
||||
|
||||
return app(AgreementOrderLimits::class)->freeze($this->f['issuer'], $quote, $request,
|
||||
[[...$this->f['line']->toArray(), 'requisition_item_id' => $item->id]],
|
||||
[['requisition_item_id' => $item->id, 'agreement_id' => $agreement->id, 'conversion' => $this->conversion]]);
|
||||
});
|
||||
$order = $this->f['order']->replicate();
|
||||
$order->forceFill(['number' => 'OC-CONTRACT-BRIDGE', 'requisition_id' => $request->id, 'purchase_award_id' => $award->id,
|
||||
'snapshot' => [...$this->f['order']->snapshot, ...$frozen]])->save();
|
||||
$line = $this->f['line']->replicate();
|
||||
$line->forceFill(['purchase_order_id' => $order->id, 'requisition_item_id' => $item->id])->save();
|
||||
$this->actingAs($this->f['receiver']);
|
||||
$body = $this->body;
|
||||
$body['items'][0]['purchase_order_item_id'] = $line->id;
|
||||
$body['items'][0]['stock_item_id'] = null;
|
||||
unset($body['items'][0]['conversion']);
|
||||
$bad = $body;
|
||||
$bad['warehouse_id'] = null;
|
||||
$this->postJson('/ordens/'.$order->id.'/recepcoes', $bad)->assertUnprocessable();
|
||||
$id = $this->postJson('/ordens/'.$order->id.'/recepcoes', $body)->assertCreated()->json('id');
|
||||
expect(GoodsReceipt::query()->findOrFail($id)->items()->sole()->accepted_milli)->toBe(2000)
|
||||
->and(StockMovement::query()->sole()->quantity_milli)->toBe(24000)
|
||||
->and($order->fresh()->snapshot)->toBe($order->snapshot)->and($order->total_minor)->toBe(20000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user