function sale_summery($connection) { $nToalClosing = 0; $TotalSale = 0; $discount_amount = 0; $net_sale = 0; $closing_balance = 0; $sql = "SELECT sales.created_at AS now_date \n FROM sales\n INNER JOIN sales_details ON sales_details.sale_id = sales.sale_id\n WHERE sales.created_at BETWEEN '2016-04-04' AND '2016-04-11'\n GROUP BY now_date"; $result = mysqli_query($connection, $sql); while ($row = mysqli_fetch_array($result)) { $CurrentDate = date("Y-m-d", strtotime($row['now_date'])); $TotalSale = GetTotalSale($connection, $CurrentDate) - GetDiscount($connection, $CurrentDate); $discount_amount = GetDiscount($connection, $CurrentDate); $net_sale = $TotalSale - $discount_amount; $CurrentDate1 = date("d-m-Y", strtotime($row['now_date'])); // Insert into master $sqlInsertMaster = "INSERT INTO \n vouchermaster (vm_date, vm_type, vm_desc, vm_amount )\n VALUES ('" . $CurrentDate . "', 'CR', '" . $CurrentDate1 . " Net Sale', '" . $net_sale . "')"; $resultInsertMaster = mysqli_query($connection, $sqlInsertMaster); // Insert into detail $sqlInsertMaster1 = "INSERT INTO \n voucherdetail (vd_vm_id, vd_coa_code, vd_desc, vd_debit, vd_credit )\n VALUES ('" . $resultInsertMaster . "', '0', '" . $CurrentDate1 . " Net Sale', '" . $net_sale . "',0)"; $resultInsertMaster1 = mysqli_query($connection, $sqlInsertMaster1); $sqlInsertMaster2 = "INSERT INTO \n voucherdetail (vd_vm_id, vd_coa_code, vd_desc, vd_debit, vd_credit )\n VALUES ('" . $resultInsertMaster . "', '414002', '" . $CurrentDate1 . " Net Sale', 0, '" . $net_sale . "')"; $resultInsertMaster2 = mysqli_query($connection, $sqlInsertMaster2); } }
function sale_summery($connection) { $nToalClosing = 0; $TotalSale = 0; $discount_amount = 0; $net_sale = 0; $closing_balance = 0; $sql = "SELECT `sales`.`created_at` AS now_date \n FROM sales\n INNER JOIN `sales_details` ON `sales_details`.`sale_id` = `sales`.`sale_id`\n GROUP BY now_date"; $result = mysqli_query($connection, $sql); while ($row = mysqli_fetch_array($result)) { $CurrentDate = date("Y-m-d", strtotime($row['now_date'])); // For 150 Price $Array150 = PriceTypeCount($connection, $CurrentDate, 150); // For 180 Price $Array180 = PriceTypeCount($connection, $CurrentDate, 180); // For 200 Price $Array200 = PriceTypeCount($connection, $CurrentDate, 200); // For 100 Price $Array100 = PriceTypeCount($connection, $CurrentDate, 100); // For 20 Price $Array20 = PriceTypeCount($connection, $CurrentDate, 20); // For 220 Price $Array220 = PriceTypeCount($connection, $CurrentDate, 220); // Water 40 $Array40 = PriceTypeCount($connection, $CurrentDate, 40); // Water 70 $Array70 = PriceTypeCount($connection, $CurrentDate, 70); $TotalSale = GetTotalSale($connection, $CurrentDate) - GetDiscount($connection, $CurrentDate); $discount_amount = GetDiscount($connection, $CurrentDate); $net_sale = $TotalSale - $discount_amount; // Insert data into sale_summery table $total_expense = GetExpense($connection, $CurrentDate); $closing_balance = $closing_balance + $net_sale - $total_expense; $sqlInsert = "INSERT INTO \n sale_summery (`current_date`, ice_20, ice_100, ice_150, ice_180, ice_200, ice_220, wt_40, wt_70, total_sale, discount_amount, net_sale, total_expense, closing_balance )\n VALUES ('" . $CurrentDate . "', '" . $Array20 . "', '" . $Array100 . "', '" . $Array150 . "', '" . $Array180 . "', '" . $Array200 . "', '" . $Array220 . "', '" . $Array40 . "', '" . $Array70 . "', '" . $TotalSale . "', '" . $discount_amount . "', '" . $net_sale . "', '" . $total_expense . "', '" . $closing_balance . "' )"; $resultInsert = mysqli_query($connection, $sqlInsert); } }
$user_id = Session::get('user_id'); $arrayPrice = DB::table('sales')->join('sales_details', 'sales.sale_id', '=', 'sales_details.sale_id')->join('products', 'products.id', '=', 'sales_details.product_id')->select(DB::raw('SUM(`product_qty`) AS PriceType'))->whereRaw('sales_details.created_at LIKE "%' . $strDate . '%" AND sales.shop_id = ' . $shop_id . ' AND products.product_price = ' . $nPrice . ' AND `return_id` = 0')->get(); $PriceType = $arrayPrice[0]->PriceType; return $PriceType; } // Get Discount function GetDiscount($strDate, $shop_id) { //$arrayDiscount = array(); $user_id = Session::get('user_id'); $arrayDiscount = DB::table('sales')->select(DB::raw('SUM(discount_amount) AS DiscountAmount'))->whereRaw('sales.created_at LIKE "%' . $strDate . '%" AND sales.shop_id = ' . $shop_id . ' AND sales.return_id = 0 ')->get(); $Discount = $arrayDiscount[0]->DiscountAmount; return $Discount; } $TodayDate = date("Y-m-d"); $AllTotal = str_replace(",", "", $TotalSale) - str_replace(",", "", GetDiscount($TodayDate, $shop_id)); ?> <table class="table table-striped m-b-0"> <?php if ($shop_id == 0) { $shop_id = 1; } ?> <thead> <tr> <td width="146" style="font-weight:bold;">{{ (int)PriceTypeCount($TodayDate,20,$shop_id) }}/20</td> <td width="112" style="font-weight:bold;">{{ (int)PriceTypeCount($TodayDate,100,$shop_id) }}/100</td> <td width="91" style="font-weight:bold;">{{ (int)PriceTypeCount($TodayDate,150,$shop_id) }}/150</td> <td width="105" style="font-weight:bold;">{{ (int)PriceTypeCount($TodayDate,180,$shop_id) }}/180</td> <td width="198" style="font-weight:bold;">{{ (int)PriceTypeCount($TodayDate,200,$shop_id) }}/200</td>