/
home
/
efamember
/
domains
/
efa-member.com
/
public_html
/
main
/
ajax
/
working_billing
/
up file
home
<?php session_start(); include('../../../config/main_function.php'); $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); if ($connection) { $member_id_check = $_POST['member_id_check']; $count_member = count($member_id_check); $create_user_id = mysqli_real_escape_string($connection, $_POST['ref_member_id']); $temp_id = explode(".", $member_id); $create_user_id = bigsara_decode($temp_id[0], $temp_id[1]); $billing_id = getRandomID(10, 'tbl_billing_head', 'billing_id'); $billing_no = getRunNO($size = 4, "BL" . $text = date('y') + 43. . date('m'), 'tbl_billing_head', 'billing_no'); $billing_date = date("Y-m-d"); $sql_head = "INSERT INTO tbl_billing_head SET billing_id = '$billing_id', create_user_id = '$create_user_id', billing_no = '$billing_no', billing_date = '$billing_date', member_id = '$member_id', ref_invoice_id = '$ref_number', customer_name = '$customer_name', customer_tax_no = '$customer_tax_no', customer_phone = '$customer_phone', customer_address = '$customer_address', customer_email = '$customer_email', discount_amount = '0', discount_type = '0', total_amount = '0', remark = '$recipt_remark' "; $res_head = mysqli_query($connection, $sql_head) or die($connection->error); $list_order = 1; foreach ($member_id_check as $member_id) { $billing_detail_id = getRandomID(10, 'tbl_billing_detail', 'billing_detail_id'); $sql = "SELECT pack.unit_price ,coup.discount_amount ,coup.discount_type ,mem.register_level ,detail.title_name ,detail.member_name ,detail.member_name_en FROM tbl_member mem LEFT JOIN tbl_member_detail detail ON detail.member_id = mem.member_id LEFT JOIN tbl_package_price pack ON pack.member_type = mem.register_level LEFT JOIN tbl_member_payment pay ON pay.member_id = mem.member_id LEFT JOIN tbl_discount_coupon coup ON coup.coupon_id = pay.coupon_id WHERE mem.member_id = '$member_id'"; $res = mysqli_query($connection, $sql); $row = mysqli_fetch_assoc($res); if ($row['register_level'] == 'g9k1s') { $member_level = 'ทั่วไป'; } elseif ($row['register_level'] == 'kki22') { $member_level = 'วิสามัญ'; } elseif ($row['register_level'] == 'x9fkq') { $member_level = 'สามัญ.'; } $temp_title = explode(" ", getTitle_name($row['title_name'])); $title_th = $temp_title[0]; $title_en = $temp_title[2]; $cost_per_unit = $row['unit_price']; if ($row['discount_amount'] != "") { $discount_per_unit = $row['discount_amount']; } else { $discount_per_unit = 0; } $total_amount = $cost_per_unit - $discount_per_unit; $product_name = "ค่าสมัครสมาชิก " . ($row['member_name'] != '' ? $title_th . $row['member_name'] : $title_en . $row['member_name_en']) . " ระดับ" . $member_level; $sql_detail = "INSERT INTO tbl_billing_detail SET billing_detail_id = '$billing_detail_id', billing_id = '$billing_id', product_name = '$product_name', unit = 'รายการ', quantity = '1', cost_per_unit = '$cost_per_unit', discount_per_unit = '$discount_per_unit', discount_type = '$discount_type', total_amount = '$total_amount', list_order = '$list_order' "; $res_detail = mysqli_query($connection, $sql_detail) or die($connection->error); $list_order++; } $sql_update = "UPDATE tbl_billing_head SET total_amount = (SELECT SUM(total_amount) AS total_amount FROM tbl_billing_detail WHERE billing_id ='$billing_id') WHERE billing_id = '$billing_id'"; $res_update = mysqli_query($connection, $sql_update) or die($connection->error); if ($res_update) { $arr['result'] = 1; } else { $arr['result'] = 0; } // if ($list_order - 1 == $count_member) { // $arr['result'] = 1; // } else { // $arr['result'] = 0; // } } else { $arr['result'] = 9; } echo json_encode($arr);