@@ -56,7 +56,7 @@ final class ProcurementDeliveryInsights
|
||||
$today = $instant->setTimezone(config('app.timezone'))->toDateString();
|
||||
$coverage = array_fill_keys(array_keys(self::LABELS), 0);
|
||||
$records = [];
|
||||
$pendingLines = $unknownLines = 0;
|
||||
$pendingLines = $unknownLines = $unverifiedReceipts = 0;
|
||||
$reversed = array_keys(app(InventoryReversals::class)->corrections('receipt'));
|
||||
foreach (PurchaseOrder::query()->visibleTo($actor)->operational()->forRequisitions($requests)->with('items')->lazyById(100) as $order) {
|
||||
app(OrderPartsAccess::class)->origins($order);
|
||||
@@ -66,7 +66,7 @@ final class ProcurementDeliveryInsights
|
||||
->where('gr.tenant_id', $actor->tenant_id)->where('gr.purchase_order_id', $order->id)->whereNotIn('goods_receipt_items.id', $reversed)
|
||||
->orderBy('gr.received_on')->orderBy('gr.id')->orderBy('goods_receipt_items.id')
|
||||
->get(['goods_receipt_items.id', 'goods_receipt_items.purchase_order_item_id', 'goods_receipt_items.received_milli', 'gr.received_on'])->groupBy('purchase_order_item_id');
|
||||
$pending = $unknown = $latePending = $lateCompleted = $maxDays = 0;
|
||||
$pending = $unknown = $unverified = $latePending = $lateCompleted = $maxDays = 0;
|
||||
$details = [];
|
||||
foreach ($progress['lines'] as $line) {
|
||||
$item = $items->get($line['id']);
|
||||
@@ -85,10 +85,12 @@ final class ProcurementDeliveryInsights
|
||||
}
|
||||
}
|
||||
$verified = $verified && $quantity === $line['received_milli'];
|
||||
$unverified += $verified ? 0 : 1;
|
||||
$waiting = $line['received_milli'] < $line['ordered_milli'];
|
||||
$pending += $waiting ? 1 : 0;
|
||||
if (! $verified || $due === null || (! $waiting && $completed === null)) {
|
||||
$unknown++;
|
||||
|
||||
continue;
|
||||
}
|
||||
$end = $waiting ? $today : $completed;
|
||||
@@ -105,7 +107,9 @@ final class ProcurementDeliveryInsights
|
||||
$coverage[$state]++;
|
||||
$pendingLines += $pending;
|
||||
$unknownLines += $unknown;
|
||||
$unverifiedReceipts += $unverified;
|
||||
$records[] = ['id' => $order->id, 'number' => $order->number, 'state' => $state, 'pending_lines' => $pending, 'unknown_lines' => $unknown,
|
||||
'unverified_receipt_lines' => $unverified,
|
||||
'late_days' => $state === 'unknown' && $maxDays === 0 ? null : $maxDays,
|
||||
'quality_pending' => $progress['state'] === 'quality_pending', 'late_lines' => $details, 'href' => '/ordens/'.$order->id];
|
||||
}
|
||||
@@ -116,7 +120,7 @@ final class ProcurementDeliveryInsights
|
||||
$current = $page === null ? 1 : max(1, min($page, $last));
|
||||
|
||||
return ['method' => 'frozen_promised_dates_native_receipts_v1', 'generated_at' => $instant->toIso8601String(), 'view' => $view,
|
||||
'coverage' => $coverage, 'pending_lines' => $pendingLines, 'unknown_lines' => $unknownLines,
|
||||
'coverage' => $coverage, 'pending_lines' => $pendingLines, 'unknown_lines' => $unknownLines, 'unverified_receipt_lines' => $unverifiedReceipts,
|
||||
'records' => ['data' => $page === null ? $filtered : array_slice($filtered, ($current - 1) * 20, 20),
|
||||
'total' => count($filtered), 'current_page' => $current, 'last_page' => $last]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user