feat: add total field to purchases and update related logic for payment processing

This commit is contained in:
2026-07-07 10:16:28 -03:00
parent 362e888e46
commit 7b2a741884
9 changed files with 377 additions and 56 deletions

View File

@@ -19,15 +19,19 @@ class PurchaseResource extends JsonResource
? $this->resource->getRelation('items')
: collect();
$subtotal = $items->reduce(
fn (float $carry, $item): float => $carry + ((float) $item->precio_unitario * $item->cantidad),
0.0,
);
$subtotal = $items->isNotEmpty()
? $items->reduce(
fn (float $carry, $item): float => $carry + ((float) $item->precio_unitario * $item->cantidad),
0.0,
)
: (float) ($this->total ?? 0);
$total = $items->reduce(
fn (float $carry, $item): float => $carry + (float) $item->total,
0.0,
);
$total = $items->isNotEmpty()
? $items->reduce(
fn (float $carry, $item): float => $carry + (float) $item->total,
0.0,
)
: (float) ($this->total ?? 0);
return [
'id' => $this->id,