public static function onClosing() { $getLastOpen = Self::getLastOpen()->toArray(); #$lastOpen['created_at'] $lastOpen = $getLastOpen['created_at']; /** * Total de depositos * @var decimal */ $deposites = Till::where('action', Self::getActionTrans('deposit'))->where('created_at', '>=', $lastOpen)->get()->toArray(); $deposites = array_sum(array_column($deposites, 'cash')); /** * Total de Ventas * @var decimal */ $cash_sales = Till::where('action', Self::getActionTrans('sale'))->where('created_at', '>=', $lastOpen)->get()->toArray(); $cash_sales = array_sum(array_column($cash_sales, 'cash')); /** * Total de Ventas * @var decimal */ $payable_sales = Till::where('action', Self::getActionTrans('sale'))->where('created_at', '>=', $lastOpen)->get()->toArray(); $payable_sales = array_sum(array_column($payable_sales, 'payable')); /** * Total de Retiros * @var decimal */ $withdrawals = Till::where('action', Self::getActionTrans('withdrawal'))->where('created_at', '>=', $lastOpen)->get()->toArray(); $withdrawals = array_sum(array_column($withdrawals, 'cash')); $till = ['total_in_open_till' => $getLastOpen['till'], 'total_deposites' => $deposites, 'total_cash_sales' => $cash_sales, 'total_payable_sales' => $payable_sales, 'total_witdrawls' => $withdrawals, 'total_all_sales' => Calc::suma([$cash_sales, $payable_sales]), 'total_till' => Calc::resta([$cash_sales, $deposites, $getLastOpen['till']], [$withdrawals])]; return (object) $till; }
/** * ------------------------------------------------ * Set Subtotal * ------------------------------------------------ * Aplica el subotal en Model\Sale * según la suma de "ItemSale>subtotal" * * @return array $Items itemList */ public function setSubtotal() { /** * Recalculate Invoice QTY ItemsSale List */ $Items = ItemSale::where('sale_id', $this->saleId)->get()->toArray(); $operation = array_column($Items, 'subtotal'); if (!isset($operation)) { $operation = []; } $Sale = Sale::find($this->saleId); $Sale->subtotal = Calc::suma($operation); $Sale->save(); return $Sale->subtotal; }