![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/inventory.corals.io/Corals/modules/Inventory/Classes/ |
<?php namespace Corals\Modules\Inventory\Classes; use Corals\Modules\Inventory\Classes\Scopes\CreatedAtBetweenScope; use Corals\Modules\Inventory\Models\Order; class Supplier { protected $start_date; protected $end_date; public function __construct() { $this->start_date = request()->get('start_date', now()->startOfMonth()); $this->end_date = request()->get('end_date', now()->endOfMonth()); } public function ordersCount($supplier_id) { $orders_count = Order::query()->select('inv_orders.*') ->where('inv_orders.supplier_id', '=', $supplier_id); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($orders_count, $this->start_date, $this->end_date); return $orders_count->count(); } public function financialReceivablesForSupplier($supplier_id) { $financial_receivables = Order::query()->select('inv_orders.*') ->where('inv_orders.supplier_id', '=', $supplier_id); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($financial_receivables, $this->start_date, $this->end_date); return $financial_receivables->sum('total'); } public function paidFinancialReceivablesForSupplier($supplier_id) { $paid_financial_receivables = Order::query()->select('inv_orders.*') ->join('payment_transactions', 'payment_transactions.sourcable_id', '=', 'inv_orders.id') ->where('inv_orders.type', '=', 'inventory_order') ->where('inv_orders.supplier_id', '=', $supplier_id); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($paid_financial_receivables, $this->start_date, $this->end_date); return $paid_financial_receivables->sum('paid_amount'); } public function remainingFinancialReceivablesForSupplier($supplier_id) { return $this->financialReceivablesForSupplier($supplier_id) - $this->paidFinancialReceivablesForSupplier($supplier_id); } }