$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); } } // Get Discount function GetDiscount($connection, $strDate) { $sql = "SELECT SUM(discount_amount) AS DiscountAmount \n FROM sales\n WHERE sales.created_at LIKE '%" . $strDate . "%'"; $result = mysqli_query($connection, $sql); $row = mysqli_fetch_array($result); $Discount = $row['DiscountAmount']; return $Discount; } // Get Total Sale function GetTotalSale($connection, $strDate) { $sql = "SELECT SUM(sales_details.product_price) AS TotalPrice \n FROM sales \n INNER JOIN sales_details ON sales_details.sale_id = sales.sale_id\n INNER JOIN products ON products.id = sales_details.product_id\n WHERE sales.created_at LIKE '%" . $strDate . "%'"; $result = mysqli_query($connection, $sql); $row = mysqli_fetch_array($result); $TotalPrice = $row['TotalPrice']; return $TotalPrice; } sale_summery($connection); mysqli_close($connection);
} // Get Discount function GetDiscount($connection, $strDate) { $sql = "SELECT SUM(discount_amount) AS DiscountAmount \n FROM sales\n WHERE sales.created_at LIKE '%" . $strDate . "%'"; $result = mysqli_query($connection, $sql); $row = mysqli_fetch_array($result); $Discount = $row['DiscountAmount']; return $Discount; } // Get Expense function GetExpense($connection, $strDate) { $TotalExpense = 0; $sql = "SELECT SUM(`vd_debit`) AS TotalExpense \n FROM vouchermaster\n INNER JOIN `voucherdetail` ON `voucherdetail`.`vd_vm_id` = `vouchermaster`.`vm_id`\n WHERE vm_date LIKE '%" . $strDate . "%' AND `vd_coa_code` <> 0"; $result = mysqli_query($connection, $sql); $row = mysqli_fetch_array($result); $TotalExpense = $row['TotalExpense']; return $TotalExpense; } // Get Total Sale function GetTotalSale($connection, $strDate) { $sql = "SELECT SUM(sales_details.product_price) AS TotalPrice \n FROM sales \n INNER JOIN sales_details ON sales_details.sale_id = sales.sale_id\n INNER JOIN products ON products.`id` = sales_details.product_id\n WHERE sales.created_at LIKE '%" . $strDate . "%'"; $result = mysqli_query($connection, $sql); $row = mysqli_fetch_array($result); $TotalPrice = $row['TotalPrice']; return $TotalPrice; } sale_summery($connection, $YesterDayDate); mysqli_close($connection);