where('ShopID', '=', $shopID) ->whereBetween('created_at', [$date, date('Y-m-d', strtotime($date . '+1 day'))]) ->get(); $refunds = DB::select("SELECT InvoiceID, TotalPrice, created_at, RefundShopID, Discount, Qty FROM invoice_product_refund_mapping WHERE RefundShopID = $shopID AND created_at BETWEEN '$date' AND DATE_ADD('$date', INTERVAL 1 DAY);"); $cards = DB::select("SELECT cpt.TransactionAmount, inv.InvoiceID, inv.ShopID FROM customer_payment_transaction AS cpt, invoice AS inv WHERE inv.ShopID = $shopID AND inv.created_at BETWEEN '$date' AND DATE_ADD('$date', INTERVAL 1 DAY) AND inv.InvoiceID = cpt.InvoiceID AND cpt.MethodID <> 0;"); $banks = DB::select("SELECT bank_ledger.Deposit , bank_ledger.Withdraw FROM bank_ledger WHERE ShopID = $shopID AND created_at BETWEEN '$date' AND DATE_ADD('$date', INTERVAL 1 DAY) AND bank_ledger.Type IN ('SelfDeposit', 'SelfWithdraw');"); $expenses = DB::select("SELECT expense_category.CategoryName, expense.Amount, Notes FROM expense, expense_category WHERE expense.ShopID = $shopID AND expense.created_at BETWEEN '$date' AND DATE_ADD('$date', INTERVAL 1 DAY) AND expense.CategoryID = expense_category.CategoryID;"); $qtys = DB::select("SELECT ProductID, Qty, created_at FROM invoice_product_mapping WHERE SellingShopID = $shopID AND created_at BETWEEN '$date' AND DATE_ADD('$date', INTERVAL 1 DAY);"); $purchases = DB::select("SELECT vendor.VendorName, purchase_invoice.TotalPrice FROM purchase_invoice, vendor WHERE purchase_invoice.ShopID = $shopID AND purchase_invoice.created_at BETWEEN '$date' AND DATE_ADD('$date', INTERVAL 1 DAY) AND vendor.VendorID = purchase_invoice.VendorID;"); $vendorPayments = DB::select("SELECT vendor.VendorName, vendor_ledger.Debit FROM vendor_ledger, vendor WHERE vendor_ledger.ShopID = $shopID AND vendor_ledger.created_at BETWEEN '$date' AND DATE_ADD('$date', INTERVAL 1 DAY) AND vendor.VendorID = vendor_ledger.VendorID;"); $duePays = DB::select(" SELECT customer_ledger.Debit, customer.FirstName, customer_ledger.Type, bank.BankName FROM customer INNER JOIN customer_ledger ON customer.CustomerID = customer_ledger.CustomerID LEFT JOIN bank_ledger ON bank_ledger.LedgerID = customer_ledger.BankLedgerID LEFT JOIN bank ON bank_ledger.BankID = bank.BankID WHERE customer.ShopID = ? AND customer_ledger.created_at BETWEEN ? AND DATE_ADD(?, INTERVAL 1 DAY) AND customer_ledger.Type IN ('Payment', 'BankPayment') ", [$shopID, $date, $date]); $vendorPayBank = DB::select("SELECT Withdraw FROM bank_ledger WHERE bank_ledger.ShopID = $shopID AND bank_ledger.created_at BETWEEN '$date' AND DATE_ADD('$date', INTERVAL 1 DAY) AND bank_ledger.Type = 'VendorBankWithdraw' ;"); $shopName = DB::select("SELECT ShopName FROM shop WHERE shopID = $shopID"); $date = Carbon::parse($date); // Parse the input date $nextDate = $date->copy()->addDay(); // Add 1 day to $date $methods = DB::table('invoice') ->leftJoin('customer_payment_transaction', 'customer_payment_transaction.InvoiceID', '=', 'invoice.InvoiceID') ->leftJoin('payment_method', 'payment_method.ID', '=', 'customer_payment_transaction.MethodID') ->select( 'payment_method.MethodName', 'customer_payment_transaction.MethodID', DB::raw('SUM(customer_payment_transaction.TransactionAmount) as TotalSum') ) ->where('invoice.ShopID', '=', $shopID) ->where('customer_payment_transaction.MethodID', '<>', 0) ->whereBetween('invoice.created_at', [$date->toDateString(), $nextDate->toDateString()]) ->groupBy('customer_payment_transaction.MethodID', 'payment_method.MethodName') // Group by payment method ->get(); $salary = DB::table('employee_ledger_new')->join('employee','employee.EmployeeID','employee_ledger_new.EmployeeID') ->where('type','<>','return') ->where('employee.ShopID', '=', $shopID) ->whereBetween('employee_ledger_new.created_at',[$date->toDateString(), $nextDate->toDateString()]) ->select('employee_ledger_new.*','employee.Name')->get(); $totalSale = 0; $totalDiscountCashSale = 0; $totalDiscountDueSale = 0; $totalDiscount = 0; $totalRefund = 0; $totalRefundCash = 0; $totalRefundDue = 0; $totalVendorPays = 0; $totalDue = 0; $totalCardPay = 0; $totalBankDeposite = 0; $totalBankWithdraw = 0; $totalExpense = 0; $totalDuePayCash = 0; $totalDuePayBank = 0; $totalQtys = 0; $totalItems = []; $totalRefundItems = 0; $DueCustomers = []; $totalPurchaseInvoices = count($purchases); $totalPurchase = 0; $totalvp = 0; $totalSalary = 0; $totalInvoices = count($invoices); foreach ($invoices as $invoice) { $totalSale += $invoice->SubTotal; if($invoice->ReturnedMoney >= 0){ $totalDiscountCashSale += $invoice->Discount; } else{ $totalDiscountDueSale += $invoice->Discount; } $totalDiscount = $totalDiscountCashSale + $totalDiscountDueSale; if ($invoice->ReturnedMoney < 0) { array_push($DueCustomers, [$invoice->InvoiceID, abs($invoice->ReturnedMoney)]); $totalDue += abs($invoice->ReturnedMoney); } } foreach ($DueCustomers as &$dc) { $v = DB::select("SELECT CustomerID FROM customer_invoice_mapping WHERE InvoiceID = ?", [$dc[0]]); if (!empty($v)) { $customer = DB::select("SELECT FirstName FROM customer WHERE CustomerID = ?", [$v[0]->CustomerID]); if (!empty($customer)) { $dc[] = $customer[0]->FirstName; } } } foreach ($refunds as $refund) { $res = DB::select("SELECT ReturnedMoney FROM invoice WHERE InvoiceID = ?",[$refund->InvoiceID]); if($res[0]->ReturnedMoney < 0){ $totalRefundDue += ($refund->TotalPrice - $refund->Discount); } if($res[0]->ReturnedMoney >= 0){ $totalRefundCash += ($refund->TotalPrice - $refund->Discount); } $totalRefund = $totalRefundCash + $totalRefundDue; $totalRefundItems += $refund->Qty; } foreach ($vendorPayments as $vendorpay) { $totalVendorPays += $vendorpay->Debit; } foreach ($cards as $card) { $totalCardPay += $card->TransactionAmount; } foreach ($banks as $bank) { $totalBankDeposite += $bank->Deposit; $totalBankWithdraw += $bank->Withdraw; } foreach ($expenses as $expense) { $totalExpense += $expense->Amount; } foreach ($duePays as $duePay) { if ($duePay->Type === "Payment") { $totalDuePayCash += $duePay->Debit; } if ($duePay->Type === "BankPayment") { $totalDuePayBank += $duePay->Debit; } } foreach($vendorPayBank as $vp){ $totalvp += $vp->Withdraw; } foreach ($qtys as $qty) { $totalQtys += $qty->Qty; if (!in_array($qty->ProductID, $totalItems)) { array_push($totalItems, $qty->ProductID); } } foreach ($purchases as $purchase) { $totalPurchase += $purchase->TotalPrice; } foreach($salary as $a){ $totalSalary += $a->Amount; } $totalCat = count($totalItems); $totalSales = $totalSale - ( $totalDiscount + $totalRefund); // $totalSale = $totalSale - ( $totalDiscount + $totalRefund); $totalDuePay = $totalDuePayCash + $totalDuePayBank; $cashTender = $totalSale - $totalCardPay; $cashTenders = $cashTender-( $totalDiscount + $totalRefund); $cashVP = $totalVendorPays - $totalvp; $totalCashOut = ($totalDiscountCashSale + $totalRefundCash + $totalVendorPays + $totalDue + $totalBankDeposite + $totalExpense + $totalSalary); // $cash = $totalSale - $totalCashOut; $cash = $cashTender - $totalCashOut; $totalDue = $totalDue - $totalRefundDue; $finalCash = $cash + $totalDuePayCash + $totalBankWithdraw; $report = [ 'Total Sale' => $totalSales, 'Card Payment' => $totalCardPay, 'Total Discount' => $totalDiscount, 'Total Refund' => $totalRefund, 'Total Vendor Payment' => $totalVendorPays, 'Total Customer Due' => $totalDue, 'Total Bank Deposite' => $totalBankDeposite, 'Total Expense' => $totalExpense, 'Total Cash Reduce from sale' => $totalCashOut, 'Remainning Cash' => $cash, 'Total Customer Due Payment' => $totalDuePay, 'By bank' => $totalDuePayBank, 'By cash' => $totalDuePayCash, 'Total Bank Withdraw' => $totalBankWithdraw, 'Final Cash' => $finalCash, 'purchase' => $totalPurchase, 'purchaseInvoice' => $totalPurchaseInvoices, 'Total Vendor Payement Bank'=>$totalvp, 'Total Vendor Payement Cash'=>$cashVP, 'finalCash'=> $finalCash, 'total Discount From Cash'=> $totalDiscountCashSale, 'total Discount From Due'=> $totalDiscountDueSale, 'total Refund From Cash'=> $totalRefundCash, 'total Refund From Due'=> $totalRefundDue, 'Total Expense Payement Cash'=>0, 'Total Expense Payement Bank'=>0, 'salaries' => $salary, 'totalSalary' => $totalSalary ]; $groupedSalaries = collect($report['salaries'])->groupBy('EmployeeID')->map(function ($items) { return (object)[ 'EmployeeID' => $items->first()->EmployeeID, 'Name' => $items->first()->Name, 'Amount' => $items->sum('Amount'), ]; })->values(); // Optional: reset numeric keys $report['groupedSalaries'] = $groupedSalaries; $activities = [ 'Total Invoiced' => $totalInvoices, 'Total Items Sold' => $totalCat, 'Total Quantities Sold' => $totalQtys, 'Total Refunded Items' => $totalRefundItems ]; // return $activities; // return ['report' => $report, 'shopName' => $shopName[0]->ShopName, 'date' => $date, 'activities' => $activities, 'DueCustomers'=>$DueCustomers, 'CashTender'=>$cashTender, 'expenses'=>$expenses]; // return $vendorPayments; return view('report.daily_report.dailyReportRevice', ['report' => $report, 'shopName' => $shopName[0]->ShopName, 'date' => $date, 'activities' => $activities, 'DueCustomers' => $DueCustomers, 'CashTender' => $cashTenders, 'expenses' => $expenses, 'purchases' => $purchases, 'dues' => $duePays, 'vendorPayments'=>$vendorPayments, 'methods'=>$methods]); } }

Daily Report

Shop: {{$shopName}}

Report Date : {{ $date }}

Print Date : {{ date('d/m/Y h:i A') }}

@foreach($methods as $method) @endforeach @foreach($DueCustomers as $x) @endforeach @foreach($dues as $x) @endforeach @foreach($purchases as $x) @endforeach @foreach($vendorPayments as $x) @if(round($x->Debit,0)>0) @endif @endforeach @foreach($expenses as $expense) @endforeach @foreach($report['groupedSalaries'] as $salary) @endforeach
Today Sale {{$report['Total Sale']}}
Cash Tender {{$CashTender}}
Card Tender {{$report['Card Payment']}}
{{ $method->MethodName ?? 'Cash' }} {{ number_format($method->TotalSum, 0) }}
Total Discout {{$report['Total Discount']}}
Total Refund {{$report['Total Refund']}}
Customer Total Due {{$report['Total Customer Due']}}
Customer's Name Amount
{{$x[2]}} {{$x[1]}}
Customer Total Due Pay {{$report['Total Customer Due Payment']}}
By Cash {{$report['By cash']}}
By Banking {{$report['By bank']}}
Customer's Name Amount
{{$x->FirstName}} {{round($x->Debit,0)}} {{$x->BankName}}
Total Purchase {{$report['purchaseInvoice']}}
Total Purchase Invoice {{$report['purchase']}}
Vendor's Name Amount
{{$x->VendorName}} {{round($x->TotalPrice,0)}}
Total Vendor Payment {{$report['Total Vendor Payment']}}
By Cash {{$report['Total Vendor Payement Cash']}}
By Banking {{$report['Total Vendor Payement Bank']}}
Vendor's Name Amount
{{$x->VendorName}} {{round($x->Debit,0)}}
Total Expenses {{$report['Total Expense']}}
By Cash {{$report['Total Expense Payement Cash']}}
By Banking {{$report['Total Expense Payement Bank']}}
Category Amount
{{ $expense->CategoryName }} --[ {{ $expense->Notes }} ] {{ round($expense->Amount,0) }}
Total Employee Salary {{$report['totalSalary']}}
Name Amount
{{ $salary->Name }} {{ round($salary->Amount, 0) }}
Banking Activities Amount
Deposite {{$report['Total Bank Deposite']}}
Withdraw {{$report['Total Bank Withdraw']}}
Final Cash {{round($report['finalCash'],0)}}