@extends('layouts.master') @section('css') @endsection @section('title') {{ __('home.home') }} @stop @section('page-header') @endsection @section('content') @can('Home') {{-- ========================================================================= --}} {{-- 1. العمليات الحسابية وتجهيز البيانات (مطابقة 100% للمنطق الأصلي) --}} {{-- ========================================================================= --}} @php $avt = App\Models\Avt::find(1); $saleavt = $avt->AVT ?? 0.15; // 1. مبيعات اليوم $totalPriceToday = 0; $invoicesToday = App\Models\invoices::whereDate('created_at', date('Y-m-d'))->where('save', 1)->get(); foreach ($invoicesToday as $product) { $totalPriceToday += round($product->cashamount, 2) + round($product->bankamount, 2) + round($product->Bank_transfer, 2) + round($product->creaditamount, 2); } $Invoices_returnToday = App\Models\return_sales::whereDate('created_at', date('Y-m-d'))->get(); $valuewithoudtaxToday = 0; foreach ($Invoices_returnToday as $returnsale) { $valuewithoudtaxToday += ($returnsale->return_Unit_Price * $returnsale->return_quantity) - $returnsale->discountvalue - $returnsale->discountoninvoice; } $todayEarnings = round($totalPriceToday, 2) - round($valuewithoudtaxToday + $valuewithoudtaxToday * $saleavt, 2); // 2. مبيعات الشهر $invoicesMonth = App\Models\invoices::whereDate('created_at', '>=', date('Y-m') . '-1')->whereDate('created_at', '<=', date('Y-m-d '))->where('save', 1)->get(); $totalPriceMonth = 0; foreach ($invoicesMonth as $product) { $totalPriceMonth += round($product->cashamount, 2) + round($product->bankamount, 2) + round($product->Bank_transfer, 2) + round($product->creaditamount, 2); } $Invoices_returnMonth = App\Models\return_sales::whereDate('created_at', '>=', date('Y-m') . '-1')->whereDate('created_at', '<=', date('Y-m-d '))->get(); $valuewithoudtaxMonth = 0; foreach ($Invoices_returnMonth as $returnsale) { $valuewithoudtaxMonth += ($returnsale->return_Unit_Price * $returnsale->return_quantity) - $returnsale->discountvalue - $returnsale->discountoninvoice; } $monthEarnings = $totalPriceMonth - round($valuewithoudtaxMonth + $valuewithoudtaxMonth * $saleavt, 2); // 3. مشتريات اليوم $purchasesTodaySum = 0; foreach (App\Models\resource_purchases::whereDate('created_at', date('Y-m-d'))->where('save', 1)->get() as $invoice) { $purchasesTodaySum += $invoice->In_debt + ($invoice['shipping fee'] ?? 0); } // 4. مشتريات الشهر $purchasesMonthSum = 0; foreach (App\Models\resource_purchases::whereDate('created_at', '>=', date('Y-m') . '-1')->whereDate('created_at', '<=', date('Y-m-d '))->where('save', 1)->get() as $invoice) { $purchasesMonthSum += $invoice->In_debt + ($invoice['shipping fee'] ?? 0); } // 5. مديونيات الموردين والعملاء $creadit_customers = App\Models\financial_accounts::where('orginal_type', 1)->get(); $credit_suppliers = App\Models\financial_accounts::where('orginal_type', 2)->get(); $creadit_customer_amount = 0; $credit_supplier_amount = 0; foreach ($creadit_customers as $creadit_customer) { $creadit_customer_amount += ($creadit_customer->debtor_current - $creadit_customer->creditor_current); } foreach ($credit_suppliers as $credit_supplier) { $credit_supplier_amount += ($credit_supplier->creditor_current - $credit_supplier->debtor_current); } // 6. المرتجعات $returnSales = App\Models\return_sales::whereDate('created_at', '=', date("Y-m-d"))->get(); $resource_purchases = App\Models\resource_purchases::whereDate('created_at', '>=', date("Y-m-d"))->where('recoveredـpieces', '!=', 0)->get(); $returnsalseList = []; $resource_purchasesList = []; foreach ($returnSales as $sale) { if (!in_array($sale->invoice_id, $returnsalseList)) { $returnsalseList[] = $sale->invoice_id; } } foreach ($resource_purchases as $resource_purchase) { $resource_purchasesList[] = $resource_purchase->id; } @endphp {{-- ========================================================================= --}} {{-- 2. شبكة الكروت الإحصائية --}} {{-- ========================================================================= --}}
{{ __('home.salesdoday') }}

{{ App\Models\invoices::whereDate('created_at', date('Y-m-d'))->where('save',1)->count() }} {{ __('home.invoice') }}

{{ __('home.TODAYEARNINGS') }}

{{ number_format($todayEarnings, 2) }} {{ __('home.SAR') }}

{{ __('home.PRODUCT_number_SOLD') }}

{{ App\Models\invoices::whereDate('created_at', '>=', date('Y-m') . '-1')->where('save',1)->whereDate('created_at', '<=', date('Y-m-d '))->count() }} {{ __('home.invoice') }}

{{ __('home.TOTAL_EARNINGS_Month') }}

{{ number_format($monthEarnings, 2) }} {{ __('home.SAR') }}

{{ __('home.creadit_customer_amount') }}

{{ number_format($creadit_customer_amount, 2) }} {{ __('home.SAR') }}

{{ __('home.credit_supplier_amount') }}

{{ number_format($credit_supplier_amount, 2) }} {{ __('home.SAR') }}

{{ __('home.purchasesdoday') }}

{{ App\Models\resource_purchases::whereDate('created_at', date('Y-m-d'))->where('save',1)->count() }} {{ __('home.invoice') }}

{{ __('home.TODAYpurchases') }}

{{ number_format($purchasesTodaySum, 2) }} {{ __('home.SAR') }}

{{ __('home.purchases_number_SOLD') }}

{{ App\Models\resource_purchases::whereDate('created_at', '>=', date('Y-m') . '-1')->whereDate('created_at', '<=', date('Y-m-d '))->where('save',1)->count() }} {{ __('home.invoice') }}

{{ __('home.TOTAL_purchases_Month') }}

{{ number_format($purchasesMonthSum, 2) }} {{ __('home.SAR') }}

{{ __('home.numberodreturnsSale') }}

{{ count($returnsalseList) }} {{ __('home.invoice') }}

{{ __('home.numberodreturnsPurchases') }}

{{ count($resource_purchasesList) }} {{ __('home.invoice') }}

{{-- ========================================================================= --}} {{-- 3. كارد الرسم البياني لمقارنة المبيعات والمشتريات --}} {{-- ========================================================================= --}} @php $currentYear = date('Y'); $salesChartMonthly = []; $purchasesChartMonthly = []; for ($m = 1; $m <= 12; $m++) { $startDate = sprintf('%s-%02d-01', $currentYear, $m); $endDate = ($m == 12) ? sprintf('%s-12-31 23:59:59', $currentYear) : sprintf('%s-%02d-01', $currentYear, $m + 1); $salesChartMonthly[] = App\Models\invoices::whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<', $endDate)->count(); $purchasesChartMonthly[] = App\Models\resource_purchases::whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<', $endDate)->count(); } $chartjs2 = app() ->chartjs->name('lineChartTest') ->type('line') ->size(['width' => 400, 'height' => 140]) ->labels(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']) ->datasets([ [ 'label' => __('home.sales'), 'backgroundColor' => 'rgba(16, 185, 129, 0.15)', 'borderColor' => '#10b981', 'pointBorderColor' => '#10b981', 'pointBackgroundColor' => '#ffffff', 'pointHoverBackgroundColor' => '#10b981', 'pointHoverBorderColor' => '#ffffff', 'data' => $salesChartMonthly, ], [ 'label' => __('home.purchases'), 'backgroundColor' => 'rgba(59, 130, 246, 0.15)', 'borderColor' => '#3b82f6', 'pointBorderColor' => '#3b82f6', 'pointBackgroundColor' => '#ffffff', 'pointHoverBackgroundColor' => '#3b82f6', 'pointHoverBorderColor' => '#ffffff', 'data' => $purchasesChartMonthly, ], ]) ->options([]); @endphp
مقارنة حركة المبيعات والمشتريات خلال العام ({{ date('Y') }})
{!! $chartjs2->render() !!}
@endcan @endsection @section('js') @endsection