![]() 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; use Corals\Modules\Inventory\Models\Transaction; use Corals\Modules\Payment\Common\Models\Transaction as PaymentTransaction; class Dashboard { 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 salesOrdersCount(): int { $sales_order_count = Order::salesOrder(); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($sales_order_count, $this->start_date, $this->end_date); return $sales_order_count->count(); } public function inventoryOrdersCount(): int { $inventory_orders_count = Order::inventoryOrder(); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($inventory_orders_count, $this->start_date, $this->end_date); return $inventory_orders_count->count(); } public function pendingSalesOrders() { $pending_sales_order = Order::salesOrder()->where('status', '=', 'pending'); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($pending_sales_order, $this->start_date, $this->end_date); return $pending_sales_order->get(); } public function completedInventoryOrdersCount(): int { $completed_inventory_orders_count = Order::inventoryOrder()->where('status', '=', 'completed'); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($completed_inventory_orders_count, $this->start_date, $this->end_date); return $completed_inventory_orders_count->count(); } public function completedSalesOrdersCount(): int { $completed_sales_orders_count = Order::salesOrder()->where('status', '=', 'completed'); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($completed_sales_orders_count, $this->start_date, $this->end_date); return $completed_sales_orders_count->count(); } public function cancelledOrdersCount(): int { $cancelled_orders_count = Order::query()->where('status', '=', 'cancelled'); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($cancelled_orders_count, $this->start_date, $this->end_date); return $cancelled_orders_count->count();; } public function InventoryTransactionsCount(): int { $inventory_transactions_count = Transaction::query(); (new CreatedAtBetweenScope('inv_transactions'))->apply($inventory_transactions_count, $this->start_date, $this->end_date); return $inventory_transactions_count->count(); } public function PaymentTransactionsCount(): int { $payment_transactions_count = PaymentTransaction::query(); (new CreatedAtBetweenScope('payment_transactions','transaction_date'))->apply($payment_transactions_count, $this->start_date, $this->end_date); return $payment_transactions_count->count(); } public function expansesTotal() { $expenses_total = Order::inventoryOrder(); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($expenses_total, $this->start_date, $this->end_date); return $expenses_total->sum('total'); } public function orderRevenueTotal() { $order_revenue_total = Order::salesOrder(); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($order_revenue_total, $this->start_date, $this->end_date); return $order_revenue_total->sum('total'); } public function paidExpansesTotal() { $paid_expenses_total = PaymentTransaction::query()->where('type', '=', 'expense'); (new CreatedAtBetweenScope('payment_transactions','transaction_date'))->apply($paid_expenses_total, $this->start_date, $this->end_date); return $paid_expenses_total->sum('paid_amount'); } public function paidOrderRevenueTotal() { $paid_order_revenue_total = PaymentTransaction::query()->where('type', '=', 'order_revenue'); (new CreatedAtBetweenScope('payment_transactions','transaction_date'))->apply($paid_order_revenue_total, $this->start_date, $this->end_date); return $paid_order_revenue_total->sum('paid_amount'); } public function expensesRemaining() { return $this->expansesTotal() - $this->paidExpansesTotal(); } public function orderRevenueRemaining() { return $this->orderRevenueTotal() - $this->paidOrderRevenueTotal(); } public function missingOrdersItems() { $missing_order = Order::query()->select('inv_orders.*', 'inventory_value', 'name', 'quantity')->join('inv_order_items', 'inv_order_items.order_id', '=', 'inv_orders.id') ->join('inv_items', 'inv_items.code', '=', 'inv_order_items.item_code') ->join('inv_inventory_has_items', 'inv_inventory_has_items.item_id', '=', 'inv_items.id') ->where('inv_order_items.type', '=', 'Item') ->where('inv_orders.status', '=', 'pending') ->where('inv_orders.type', '=', 'sales_order') ->where('inv_inventory_has_items.inventory_value', '<', '0'); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($missing_order, $this->start_date, $this->end_date); return $missing_order->get(); } public function unpaidInventoryOrders() { $unpaid_order = Order::query()->select('inv_orders.*','inv_order_items.quantity') ->join('inv_order_items', 'inv_order_items.order_id', '=', 'inv_orders.id') ->join('inv_suppliers', 'inv_orders.supplier_id', '=', 'inv_suppliers.id') ->where('inv_order_items.type', '=', 'Item') ->where('inv_orders.type', '=', 'inventory_order') ->whereRaw("JSON_EXTRACT(billing,'$.payment_status') != 'paid'"); (new CreatedAtBetweenScope('inv_orders','order_date'))->apply($unpaid_order, $this->start_date, $this->end_date); return $unpaid_order->get(); } }