ESH/save_bill.php

93 lines
2.8 KiB
PHP
Raw Normal View History

2024-10-23 18:28:06 +05:30
<?php
include('includes/config/config.php');
include("includes/functions.php");
include('log_entry.php');
error_log(print_r($_POST, true));
$noOfRows = $_POST['count_items'];
error_log("count:" . $noOfRows);
// $bill_id = $_POST['bill_id'];
// $bill_no = $_POST['bill_no'];
$bill_date = $_POST['bill_date'];
$patient_id = $_POST['patient_id'];
// $client_id = $_REQUEST['client_id'];
// error_log("client id:" . $client_id);
// $total_amount_bf_discount = $_POST['total_amount_bf_discount'];
// $total_discount_amount = $_POST['total_discount_amount'];
// $discount_voucher = $_POST['discount_voucher'];
// $Pay_mod = $_POST['Pay_mod'];
$final_bill_amount = $_POST['total'];
// $amount_paid_patient = $_POST['amount_paid_patient'];
// $amount_pending_company = $_POST['amount_pending_company'];
// $bill_status = $_POST['bill_status'];
//echo $procurement_refno;
$query_initial = "";
$endquery = "";
//begin();
if (!empty($bill_id)) {
$query_initial = "update bill_master set ";
$endquery = " where bill_id = '" . $bill_id . "' ";
} else {
$month = date('n');
$year = date('Y');
// if ($month > 3) {
// $year = $year;
// } else {
// $year = $year - 1;
// }
$query_bill_no = "select max( CAST(substring(bill_no,locate('/',bill_no)+1,length(bill_no)-(5+locate('/',bill_no))) as UNSIGNED) ) from bill_master where bill_no like '%$year%'";
error_log("bill generate query:" . $query_bill_no);
$result_bill_no = @mysqli_query($conn, $query_bill_no);
$row_bill_no = mysqli_fetch_row($result_bill_no);
$bill_no = 'GHCL/' . ($row_bill_no[0] + 1) . '/' . $year;
$query_initial = "insert into bill_master set bill_no = '" . $bill_no . "', ";
}
$query = $query_initial . "
bill_date = STR_TO_DATE('" . $bill_date . "','%d/%m/%Y'),
patient_id = '" . $patient_id . "',
final_bill_amount = '" . $final_bill_amount . "',
ohc_type_id='" . $_SESSION['current_ohcttype'] . "',IsChargeable='" . $_POST['IsChargeable'] . "',
modified_by = '" . $_SESSION['user_id'] . "' " . $endquery;
error_log("bill master save query:" . $query);
if (!$result = @mysqli_query($conn, $query)) {
exit(mysqli_error($conn));
}
$bill_id = getFieldFromTable('bill_id', 'bill_master', 'bill_no', $bill_no);
$query_del = "DELETE from bill_details where bill_id = '$bill_id'";
$result_del = mysqli_query($conn, $query_del);
error_log($query_del);
for ($i = 0; $i < $noOfRows; $i++) {
$query1 = "insert into bill_details set bill_id='$bill_id',
product_list ='" . ${"product_list$i"} . "',
rate_per_unit ='" . ${"rate_per_unit$i"} . "',
qty ='" . ${"qty$i"} . "',
total_amount ='" . ${"total_amount$i"} . "'
";
error_log("bill details:" . $query1);
if (!$result1 = @mysqli_query($conn, $query1)) {
exit(mysqli_error($conn,));
}
}