客戶資料"; echo " 編號 稱謂 姓氏 名字 證明文件 文件號碼 聯絡電話 聯絡電郵 聯絡地址 "; } //$customer_name = get_customer_name($customer["firstname"], $customer["lastname"]); /*if($customer["title"] == "Mr"){ $title = "先生"; }else if($customer["title"] == "Mrs"){ $title = "女士"; }else if($customer["title"] == "Ms"){ $title = "小姐"; }else{ }*/ echo " " . ($customer["code"]) . " " . ($customer["title"]) . " " . rsa_crypt($customer["lastname"], 2) . " " . rsa_crypt($customer["firstname"], 2) . ""; if ($customer["typeid"] == "PERSONAL") { echo "身分證(個人)"; } if ($customer["typeid"] == "BUSINESS") { echo "商業登記證(公司)"; } echo " " . $identity . " " . rsa_crypt($customer["tel"], 2) . " " . rsa_crypt($customer["email"], 2) . " " . rsa_crypt($customer["address"], 2) . " "; } } if ($exist > 0) { echo ""; } } if ($_GET["for"] == "search_available_room") { $location_id = $_POST["location_id"]; $typeid = $_POST["typeid"]; $master_room_id = $_POST["master_room_id"]; if (empty($typeid) || empty($master_room_id) || empty($location_id)) exit; $sql = "select *, room.id as room_id, room.code as room_code from room room INNER JOIN location location ON room.location_id = location.id INNER JOIN master_room_price room_price ON room.master_room_id = room_price.master_room_id where room.deleted = 0 and room.status = 'OPEN' and room.typeid = ? and room.master_room_id = ? and room.location_id = ?"; $parameters = array($typeid, $master_room_id, $location_id); $room_info = bind_pdo($sql, $parameters, "selectall"); if (!empty($_SESSION["switch"])) { //allow to select customer rented room when do switching $extra_room_info = array(); foreach ($_SESSION["switch"]["ordered_room_id"] as $ordered_room_id) { $sql = "select *, room.id as room_id, room.code as room_code from room room INNER JOIN location location ON room.location_id = location.id INNER JOIN master_room_price room_price ON room.master_room_id = room_price.master_room_id where room.deleted = 0 and room.typeid = ? and room.master_room_id = ? and room.location_id = ? and room.id = ?"; $parameters = array($typeid, $master_room_id, $location_id, $ordered_room_id); //_log(basename($_SERVER['PHP_SELF']), "64091519", $sql, $parameters); $extra_room_info[] = bind_pdo($sql, $parameters, "selectone"); } if (!empty($extra_room_info)) { foreach ($extra_room_info as $this_room_info) { $room_info[] = $this_room_info; } } } $all_room_id = array(); $valid_room_info = array(); foreach ($room_info as $room) { if (!in_array($room["room_id"], $all_room_id)) { $all_room_id[] = $room["room_id"]; $valid_room_info[] = $room; } } $exist = 0; if (!empty($room_info) && $room_info[0]["room_id"] > 0) { foreach ($valid_room_info as $room) { if (empty($room)) break; $exist++; $master_room_info = get_master_room($room["master_room_id"]); if ($exist == 1) { echo ""; echo ""; } //check if this room selected $background = "background-color: #ffffff"; $available_room_selected_class = ""; $select_room_text = "選取"; if (!empty($_SESSION["selected_room_tr"])) { if (strpos($_SESSION["selected_room_tr"], $room["room_code"]) !== FALSE) { $background = "background-color: #7EBF3D"; $select_room_text = "已選取"; $available_room_selected_class = "available_room_selected"; } } echo " "; //need to check if master room discount exist, if exist -> discounted price -> master room discount if ($nowdate >= $room["effectivedate_from"] && $nowdate <= $room["effectivedate_to"]) { //discounted price valid echo ""; $set_discounted_price = $room["discounted_price"]; } else { echo ""; $set_discounted_price = $room["retail_price"]; } $discounted_price = $set_discounted_price; //check if this kind of room has prepaid / specific discount //$sql = "select *, discount.id as master_room_discount_id from master_room_discount discount INNER JOIN master_type_code mtcode ON discount.payment_term = mtcode.code where discount.master_room_id = ? and discount.deleted = ? and mtcode.typeid = ? and ? >= discount.effectivedate_from and ? <= discount.effectivedate_to order by discount.payment_term ASC"; $sql = "select *, discount.id as master_room_discount_id from master_room_discount discount INNER JOIN master_type_code mtcode ON discount.payment_term = mtcode.code where discount.master_room_id = ? and discount.deleted = ? and discount.status = ? and mtcode.typeid = ? and ? >= discount.effectivedate_from and ? <= discount.effectivedate_to order by mtcode.sort ASC "; $parameters = array($_POST["master_room_id"], 0, 1, "PAYMENT_TERM", date("Y-m-d"), date("Y-m-d")); $master_room_discount_info = bind_pdo($sql, $parameters, "selectall"); $discount_message = ""; if (!empty($master_room_discount_info)) { foreach ($master_room_discount_info as $master_room_discount) { //$discount_message .= $master_room_discount["name_tc"] . " -" . $master_room_discount["discount"] . $master_room_discount["discount_type"] . " / "; if ($master_room_discount["payment_term"] == "SPECIFIC_SIZE") { $class = "SPECIFIC_SIZE_DISCOUNT _DISCOUNT DISCOUNT_ID_" . $master_room_discount["master_room_discount_id"]; $discounted_price = $set_discounted_price * (100 - $master_room_discount["discount"]) / 100; } else { $class = "PREPAID_DISCOUNT _DISCOUNT DISCOUNT_ID_" . $master_room_discount["master_room_discount_id"]; if ($master_room_discount["is_final_discount"] == 1) { $class .= " IS_FINAL_DISCOUNT"; } $discounted_price = $set_discounted_price; } //$discount_message .= $master_room_discount["name_tc"] . " % 折扣 /
"; $discount_message .= $master_room_discount["name_tc"] . " % 折扣 /
"; } $discount_message = substr_replace($discount_message, "", -7); } /*echo "";*/ echo ""; /*echo "";*/ echo ""; echo ""; echo ""; echo ""; } if ($exist > 0) { echo "
可選擇倉庫
倉庫編號 尺寸 原價(月) 優惠價(月) 預繳 / 特價優惠 價格 價格(折扣後)
" . $room["room_code"] . " " . $master_room_info["length"] . "X" . $master_room_info["width"] . "X" . $master_room_info["height"] . " $" . numberformat($room["retail_price"], 2, "") . " $" . ($room["discounted_price"]) . " - " . $discount_message . " " . $discount_message . "
"; } } else { echo "沒有空置的倉庫可供租出。"; } } if ($_GET["for"] == "selected_room_tr") { $_SESSION["selected_room_tr"] = ($_POST["selected_room_tr"]); } if ($_GET["for"] == "prepaid_discount") { //var_dump($_POST); $prepaid_deduct = 0; if (!empty($_POST["order_total"]) && !empty($_POST["prepaid_month"]) && !empty($_POST["selected_room_id"])) { $order_total = $_POST["order_total"]; $prepaid_month = $_POST["prepaid_month"]; $selected_room_id_list = $_POST["selected_room_id"]; $selected_room_id = explode(",", $selected_room_id_list); foreach ($selected_room_id as $room_id) { $config_value_list = array(); $sql = "select * from master_room_discount mrdiscount INNER JOIN master_type_code mtcode ON mrdiscount.payment_term = mtcode.code where mtcode.typeid = 'PAYMENT_TERM' and mrdiscount.status = 1 and mrdiscount.deleted = 0 and mrdiscount.effectivedate_from <= ? and mrdiscount.effectivedate_to >= ? and mrdiscount.master_room_id = ? and ("; $room_info = get_room($room_id); $parameters = array(date("Y-m-d"), date("Y-m-d"), $room_info["master_room_id"]); /*for ($i = $prepaid_month; $i > 0; $i--) { $sql .= "mtcode.config_value = ? or "; $parameters[] = $i; } $sql = substr_replace($sql, "", -3);*/ $sql .= "mtcode.config_value = ? "; $parameters[] = $prepaid_month; $sql .= ") order by mtcode.config_value DESC, mrdiscount.lastupdate DESC"; /*var_dump($sql); var_dump($parameters);*/ $prepaid_discount_info = bind_pdo($sql, $parameters, "selectone"); //calculate prepaid deduct if ($prepaid_discount_info["discount_type"] == "%") { $prepaid_deduct += $order_total * $prepaid_discount_info["discount"] / 100; } else { $prepaid_deduct += $prepaid_discount_info["discount"]; } } } echo round($prepaid_deduct, 1); } if ($_GET["for"] == "ajax_calculate_monthly_rent") { $total_discounted_price = 0; $selected_room_id_list = $_REQUEST["selected_room_id_list"]; $selected_room_id_list = explode(",", $selected_room_id_list); $prepaid_month = $_REQUEST["prepaid_month"]; $selected_room_discount_id_list = $_REQUEST["selected_room_discount_id_list"]; $selected_room_discount_id_list = explode(",", $selected_room_discount_id_list); $selected_room_discount_id_value_list = $_REQUEST["selected_room_discount_id_value_list"]; $selected_room_discount_id_value_list = explode(",", $selected_room_discount_id_value_list); //var_dump($_REQUEST); $j = 0; $discount_info = array(); //$biggest_retail_price = 0; foreach ($selected_room_id_list as $key => $room_id) { //get the discounted price of each selected room $sql = "select *, room.id as room_id, room.code as room_code from room room INNER JOIN master_room_price room_price ON room.master_room_id = room_price.master_room_id where room.deleted = 0 and room.id = ? "; $parameters = array($room_id); $room_info = bind_pdo($sql, $parameters, "selectone"); //compare retail price and record the biggest one /*if($room_info["retail_price"] >= $biggest_retail_price){ $biggest_retail_price = $room_info["retail_price"]; }*/ if ($nowdate >= $room_info["effectivedate_from"] && $nowdate <= $room_info["effectivedate_to"]) { //discounted price valid $discounted_price = $room_info["discounted_price"]; } else { $discounted_price = $room_info["retail_price"]; } //do discount, start from prepaid if (!empty($prepaid_month)) { //get prepaid discount first $sql = "select *,mrdiscount.id as master_room_discount_id from master_room_discount mrdiscount INNER JOIN master_type_code mtcode ON mrdiscount.payment_term = mtcode.code where mrdiscount.deleted = ? and mrdiscount.status = ? and mrdiscount.payment_term IS NOT NULL and mrdiscount.payment_term != ? and mrdiscount.master_room_id = ? and mrdiscount.effectivedate_from <= ? and ? <= mrdiscount.effectivedate_to group by mrdiscount.payment_term order by config_value DESC"; $parameters = array(0, 1, "SPECIFIC_SIZE", $room_info["master_room_id"], date("Y-m-d"), date("Y-m-d")); $master_room_discount_info = bind_pdo($sql, $parameters, "selectall"); if (!empty($master_room_discount_info)) { foreach ($master_room_discount_info as $master_room_discount) { //if ($master_room_discount["discount_type"] == "%" && $master_room_discount["config_value"] <= $prepaid_month) { if ($master_room_discount["discount_type"] == "%" && $master_room_discount["config_value"] == $prepaid_month) { $latest_discount_value = $master_room_discount["discount"]; //discount id list foreach ($selected_room_discount_id_list as $list_key => $list) { $token = explode("DISCOUNT_ID_", $list); $this_discount_id = $token[1]; if ($this_discount_id == $master_room_discount["master_room_discount_id"]) { $latest_discount_value = $selected_room_discount_id_value_list[$list_key]; break; } } //$deduct = $discounted_price * $master_room_discount["discount"] / 100; $deduct = $discounted_price * $latest_discount_value / 100; $discount_info[$j]["master_room_discount_id"] = $master_room_discount["master_room_discount_id"]; $discount_info[$j]["master_room_id"] = $master_room_discount["master_room_id"]; $discount_info[$j]["discount_type"] = $master_room_discount["discount_type"]; //$discount_info[$j]["discount"] = $master_room_discount["discount"]; $discount_info[$j]["discount"] = $latest_discount_value; $discount_info[$j]["monthly_deduct"] = $deduct; $discount_info[$j]["room_id"] = $room_id; $discounted_price -= $deduct; //check if this is the final discount or not if ($master_room_discount["is_final_discount"] == 1 || $deduct > 0) { break; } } } } } //specific discount record $sql = "select * from master_room_discount mrdiscount where mrdiscount.deleted = ? and mrdiscount.payment_term = ? and mrdiscount.master_room_id = ? and mrdiscount.effectivedate_from <= ? and ? <= mrdiscount.effectivedate_to"; $parameters = array(0, "SPECIFIC_SIZE", $room_info["master_room_id"], date("Y-m-d"), date("Y-m-d")); $master_room_discount_info = bind_pdo($sql, $parameters, "selectone"); if (!empty($master_room_discount_info) && $master_room_discount_info["discount_type"] == "%") { $latest_discount_value = $master_room_discount_info["discount"]; //discount id list foreach ($selected_room_discount_id_list as $list_key => $list) { $token = explode("DISCOUNT_ID_", $list); $this_discount_id = $token[1]; if ($this_discount_id == $master_room_discount_info["master_room_discount_id"]) { $latest_discount_value = $selected_room_discount_id_value_list[$list_key]; break; } } //$deduct = $discounted_price * $master_room_discount_info["discount"] / 100; $deduct = $discounted_price * $latest_discount_value / 100; $discount_info[$j]["master_room_discount_id"] = $master_room_discount_info["id"]; $discount_info[$j]["master_room_id"] = $master_room_discount_info["master_room_id"]; $discount_info[$j]["discount_type"] = $master_room_discount_info["discount_type"]; //$discount_info[$j]["discount"] = $master_room_discount_info["discount"]; $discount_info[$j]["discount"] = $latest_discount_value; $discount_info[$j]["monthly_deduct"] = $deduct; $discount_info[$j]["room_id"] = $room_id; $discounted_price -= $deduct; } //check if this is the final discount or not if ($master_room_discount_info["is_final_discount"] == 1) { break; } $j++; $total_discounted_price += $discounted_price; } //record biggest price //$_SESSION["warehousing"][2]["biggest_retail_price"] = $biggest_retail_price; //record discount info into session $_SESSION["warehousing"][2]["order_discount"] = $discount_info; //output the total_discounted_price echo round($total_discounted_price, 1); } if ($_GET["for"] == "switch_order") { if (!empty($_GET["order_id"])) { $order_id = (int)$_GET["order_id"]; $order_info = get_order($order_id); if ($order_info["status"] == "VOID" || $order_info["status"] == "COMPLETED") { $order_status = get_master_type_code("ORDER_STATUS", $order_info["status"]); echo ""; exit; } $_SESSION["switch"]["order_info"] = $order_info; $_SESSION["switch"]["ordered_room_code"] = array(); $order_room_info = get_order_room($order_id); foreach ($order_room_info as $order_room) { $room_info = get_room($order_room["room_id"]); $_SESSION["switch"]["ordered_room_id"][] = $room_info["id"]; } $_SESSION["warehousing"][1]["customer_id"] = $order_info["customer_id"]; $customer_info = get_customer($order_info["customer_id"]); //record warehousing order in session $_SESSION["warehousing"][1]["new_customer"] = 0; $_SESSION["warehousing"][1]["customer_code"] = $customer_info["code"]; $_SESSION["warehousing"][1]["title"] = $customer_info["title"]; $_SESSION["warehousing"][1]["identity_type"] = $customer_info["typeid"]; if ($customer_info["typeid"] == "PERSONAL") { $_SESSION["warehousing"][1]["identity_id"] = rsa_crypt($customer_info["hkid"], 2); } else { $_SESSION["warehousing"][1]["identity_id"] = rsa_crypt($customer_info["hkbr"], 2); } $_SESSION["warehousing"][1]["lastname"] = rsa_crypt($customer_info["lastname"], 2); $_SESSION["warehousing"][1]["firstname"] = rsa_crypt($customer_info["firstname"], 2); $_SESSION["warehousing"][1]["companyname"] = $customer_info["companyname"]; $_SESSION["warehousing"][1]["email"] = rsa_crypt($customer_info["email"], 2); $_SESSION["warehousing"][1]["tel"] = rsa_crypt($customer_info["tel"], 2); $_SESSION["warehousing"][1]["address"] = rsa_crypt($customer_info["address"], 2); $_SESSION["warehousing"][1]["pass"] = TRUE; $_SESSION["warehousing"][1]["customer_first_order"] = FALSE; //calculate the remain money of last contract $total_return_amount = 0; $datetime1 = date_create($order_info["startdate"]); $datetime2 = date_create($nowdate); $interval = date_diff($datetime1, $datetime2); $used_month_num = (int)$interval->format("%m") + 1; $used_money_total = $used_month_num * $order_info["total_discounted_price"]; //get contract paid amount $sql = "select * from invoice where order_id = ? and status != ?"; $parameters = array($order_id, "VOID"); $order_invoice_info = bind_pdo($sql, $parameters, "selectall"); $total_order_product = 0; $total_rent = 0; $total_penalty = 0; $total_deposit = 0; $user_paid_amount_for_invoice = 0; $user_paid_amount_for_deposit = 0; //check invoice foreach ($order_invoice_info as $order_invoice) { $user_paid_amount_for_invoice += $order_invoice["amount"] - $order_invoice["balance"]; $invoice_dtl_info = get_invoice_detail($order_invoice["id"]); foreach ($invoice_dtl_info as $invoice_dtl) { if ($invoice_dtl["type"] == "ORDER_PRODUCT") { $total_order_product += $invoice_dtl["amount"]; } if ($invoice_dtl["type"] == "RENT") { $total_rent += $invoice_dtl["amount"]; } if ($invoice_dtl["type"] == "PENALTY") { $total_penalty += $invoice_dtl["amount"]; } } if (round($order_info["free_first_month_deduct"], 1) == round(($order_invoice["amount"] - $order_invoice["balance"]), 1)) { $total_order_product = 0; $total_penalty = 0; } } //$user_paid_amount_for_invoice_for_rent = $user_paid_amount_for_invoice - $total_order_product; $user_paid_amount_for_invoice_for_rent = $user_paid_amount_for_invoice - $total_order_product - $total_penalty; //check deposit $sql = "select * from deposit where order_id = ? and status != ?"; $parameters = array($order_id, "VOID"); $deposit_info = bind_pdo($sql, $parameters, "selectall"); foreach ($deposit_info as $deposit) { $user_paid_amount_for_deposit += $deposit["amount"] - $deposit["balance"]; $total_deposit += $deposit["amount"]; } $total_return_amount = $total_return_amount + (float)$user_paid_amount_for_invoice_for_rent; $total_return_amount = $total_return_amount - (float)$used_money_total; //var_dump(round($total_return_amount, 2)); $_SESSION["switch"]["total_return_amount"] = round($total_return_amount, 1); if ($_SESSION["switch"]["total_return_amount"] <= 0) { $_SESSION["switch"]["total_return_amount"] = 0; } echo ""; exit; } } if ($_GET["for"] == "cancel_switch") { unset($_SESSION["switch"]); unset($_SESSION["warehousing"]); unset($_SESSION["selected_room_tr"]); header("Location: order_index.php"); } if ($_GET["for"] == "clear_selected_room") { unset($_SESSION["selected_room_tr"]); unset($_SESSION["floor_plan_rent_room"]); header("Location: warehousing_step2.php"); } if ($_GET["for"] == "get_customer_unpaid") { if (!empty($_POST["customer_id"])) { $unpaid_payment = array(); $i = 0; /*if($_SESSION["_payment_type"] == "DEPOSIT"){ $sql = "select * from deposit where status = 'NEW' and deleted = 0 and balance != 0"; $deposit_info = bind_pdo($sql, NULL, "selectall"); foreach ($deposit_info as $deposit) { $order_info = get_order($deposit["order_id"]); if ($order_info["customer_id"] != $_POST["customer_id"]) continue; $unpaid_payment[$i]["payable_type"] = "DEPOSIT"; $unpaid_payment[$i]["payable_type_detail"] = ""; $unpaid_payment[$i]["payable_id"] = $deposit["id"]; $unpaid_payment[$i]["payable_code"] = $deposit["code"]; $unpaid_payment[$i]["ori_balance"] = $deposit["balance"]; $unpaid_payment[$i]["balance"] = $deposit["balance"]; $unpaid_payment[$i]["amount"] = $deposit["amount"]; $unpaid_payment[$i]["docdate"] = $deposit["docdate"]; $i++; } }elseif($_SESSION["_payment_type"] == "INVOICE"){ $sql = "select * from invoice where (status = 'NEW' or status = 'SENT') and deleted = 0 and balance != 0"; $invoice_info = bind_pdo($sql, NULL, "selectall"); foreach ($invoice_info as $invoice) { //$order_info = get_order($invoice["order_id"]); if ($invoice["customer_id"] != $_POST["customer_id"]) continue; $unpaid_payment[$i]["payable_type"] = "INVOICE"; $unpaid_payment[$i]["payable_id"] = $invoice["id"]; $unpaid_payment[$i]["payable_code"] = $invoice["code"]; $unpaid_payment[$i]["ori_balance"] = $invoice["balance"]; $unpaid_payment[$i]["balance"] = $invoice["balance"]; $unpaid_payment[$i]["amount"] = $invoice["amount"]; $unpaid_payment[$i]["docdate"] = $invoice["docdate"]; $i++; } }*/ $sql = "select * from deposit where status = 'NEW' and deleted = 0 and balance != 0 and customer_id = ?"; $deposit_info = bind_pdo($sql, array($_POST["customer_id"]), "selectall"); foreach ($deposit_info as $deposit) { /*$order_info = get_order($deposit["order_id"]); if ($order_info["customer_id"] != $_POST["customer_id"]) continue;*/ $unpaid_payment[$i]["payable_type"] = "DEPOSIT"; $unpaid_payment[$i]["payable_type_detail"] = ""; $unpaid_payment[$i]["payable_id"] = $deposit["id"]; $unpaid_payment[$i]["payable_code"] = $deposit["code"]; $unpaid_payment[$i]["ori_balance"] = $deposit["balance"]; $unpaid_payment[$i]["balance"] = $deposit["balance"]; $unpaid_payment[$i]["amount"] = $deposit["amount"]; $unpaid_payment[$i]["docdate"] = $deposit["docdate"]; $i++; } $sql = "select * from invoice where (status = 'NEW' or status = 'SENT') and deleted = 0 and balance != 0 and customer_id = ?"; $invoice_info = bind_pdo($sql, array($_POST["customer_id"]), "selectall"); foreach ($invoice_info as $invoice) { //$order_info = get_order($invoice["order_id"]); /*if ($invoice["customer_id"] != $_POST["customer_id"]) continue;*/ $unpaid_payment[$i]["payable_type"] = "INVOICE"; $unpaid_payment[$i]["payable_id"] = $invoice["id"]; $unpaid_payment[$i]["payable_code"] = $invoice["code"]; $unpaid_payment[$i]["ori_balance"] = $invoice["balance"]; $unpaid_payment[$i]["balance"] = $invoice["balance"]; $unpaid_payment[$i]["amount"] = $invoice["amount"]; $unpaid_payment[$i]["docdate"] = $invoice["docdate"]; $i++; } if (!empty($unpaid_payment)) { echo "
* 已選擇的應付款項將加入到這個付款當中

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $i = 0; foreach ($unpaid_payment as $payment) { echo ""; $payment_type = get_master_type_code("PAYMENT_TYPE", $payment["payable_type"]); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $i++; } echo ""; echo ""; echo ""; echo "
類別發票編號發票日期金額未付金額是次付款金額
" . $payment_type["name_tc"] . " " . $payment["payable_code"] . "" . $payment["docdate"] . "$" . numberformat($payment["amount"]) . "$" . numberformat($payment["balance"]) . "$
已付金額總數:
"; } else { echo "沒有應付款項。"; } } } if ($_GET["for"] == "get_order_rent_info") { $order_id = (int)$_POST["order_id"]; $order_info = get_order($order_id); $rent_start_date = $order_info["warehousing_date"]; $rent_month = $order_info["rent_month"]; $sql = "select *, inv_dtl.amount as inv_dtl_amount, inv.code as inv_code from invoice_dtl inv_dtl INNER JOIN invoice inv ON inv_dtl.invoice_id = inv.id where inv_dtl.type = ? and inv.order_id = ? and inv.status != ? order by month ASC "; $parameters = array("RENT", $order_id, "VOID"); $invoice_info = bind_pdo($sql, $parameters, "selectall"); if (!empty($invoice_info)) { $master_type_code = get_master_type_code("INVOICE_TYPE", "RENT"); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; //echo ""; echo ""; echo ""; echo ""; echo ""; $num_month = 0; for ($i = 1; $i <= $rent_month; $i++) { $exist = FALSE; //created invoice foreach ($invoice_info as $invoice) { if ($invoice["month"] == $i) { $exist = TRUE; $num_month++; $invoice_status = get_master_type_code("INVOICE_STATUS", $invoice["status"]); echo ""; echo ""; echo ""; echo ""; echo ""; $start_date = new DateTime($order_info["warehousing_date"]); $start_date->modify('+' . ($i - 1) . ' month'); $end_date = new DateTime($order_info["warehousing_date"]); if ($i == $rent_month) { $end_date->modify('+' . $i . ' month - 1 day'); } else { $end_date->modify('+' . $i . ' month'); } echo ""; echo ""; //echo ""; echo ""; echo ""; echo ""; echo ""; } } if (!$exist) { //non-created invoice $rent = $order_info["total_discounted_price"]; echo ""; echo ""; echo ""; echo ""; echo ""; $start_date = new DateTime($order_info["warehousing_date"]); $start_date->modify('+' . ($i - 1) . ' month'); $end_date = new DateTime($order_info["warehousing_date"]); if ($i == $rent_month) { $end_date->modify('+' . $i . ' month - 1 day'); } else { $end_date->modify('+' . $i . ' month'); } echo ""; echo ""; //echo ""; echo ""; echo ""; echo ""; echo ""; } } //extra rent invoice, non contract $sql = "select *, inv_dtl.amount as inv_dtl_amount, inv.code as inv_code from invoice_dtl inv_dtl INNER JOIN invoice inv ON inv_dtl.invoice_id = inv.id where inv_dtl.type = ? and inv.order_id = ? and inv.status != ? and inv_dtl.month > ? order by month ASC "; $parameters = array("RENT", $order_id, "VOID", $rent_month); $extra_rent_invoice_info = bind_pdo($sql, $parameters, "selectall"); if (!empty($extra_rent_invoice_info)) { foreach ($extra_rent_invoice_info as $extra_rent_invoice) { $invoice_status = get_master_type_code("INVOICE_STATUS", $extra_rent_invoice["status"]); $i = $extra_rent_invoice["month"]; echo ""; echo ""; echo ""; echo ""; echo ""; $start_date = new DateTime($order_info["warehousing_date"]); $start_date->modify('+' . ($i - 1) . ' month'); $end_date = new DateTime($order_info["warehousing_date"]); $end_date->modify('+' . $i . ' month - 1 day'); echo ""; echo ""; //echo ""; echo ""; echo ""; echo ""; echo ""; } } echo "
類型月份發票編號租用月份金額未繳款項繳費日期狀態備註
" . $master_type_code["name_tc"] . "第" . $i . "個月" . $invoice["inv_code"] . "" . $start_date->format('Y-m-d') . " - " . $end_date->format('Y-m-d') . "$" . numberformat($invoice["inv_dtl_amount"]) . "$" . $invoice["balance"] . "" . $invoice["duedate"] . "" . $invoice_status["name_tc"] . "" . nl2br($invoice["remark"]) . "
" . $master_type_code["name_tc"] . "第" . $i . "個月-" . $start_date->format('Y-m-d') . " - " . $end_date->format('Y-m-d') . "$" . numberformat($rent) . "$" . $rent . "" . Date('Y-m-d', strtotime($rent_start_date . "+" . ($i - 1) . " month")) . "未建立
" . $master_type_code["name_tc"] . "第" . $i . "個月" . $extra_rent_invoice["inv_code"] . "" . $start_date->format('Y-m-d') . " - " . $end_date->format('Y-m-d') . "$" . numberformat($extra_rent_invoice["inv_dtl_amount"]) . "$" . $invoice["balance"] . "" . $extra_rent_invoice["duedate"] . "" . $invoice_status["name_tc"] . "" . nl2br($extra_rent_invoice["remark"]) . "
"; echo "
選擇要新建的租金月份,然後儲存。"; } } if ($_GET["for"] == "floor_plan_rent_room") { if ($_POST["go_to_warehousing"] == 1) { if (!empty($_SESSION["floor_plan_rent_room"])) { $_SESSION["selected_room_tr"] = ' 選擇迷你倉
'; foreach ($_SESSION["floor_plan_rent_room"] as $selected_room) { $room = get_room($selected_room["room_id"]); $master_room_info = get_master_room($room["master_room_id"]); $master_room_price = get_master_room_price($room["master_room_id"]); $location_id = $master_room_info["location_id"]; //check if this room selected $background = "background-color: #ffffff"; if (!empty($_SESSION["selected_room_tr"])) { if (strpos($_SESSION["selected_room_tr"], $room["room_code"]) !== FALSE) { $background = "background-color: #7EBF3D"; } } $_SESSION["selected_room_tr"] .= " "; //need to check if master room discount exist, if exist -> discounted price -> master room discount if ($nowdate >= $master_room_price["effectivedate_from"] && $nowdate <= $master_room_price["effectivedate_to"]) { //discounted price valid $_SESSION["selected_room_tr"] .= ""; $set_discounted_price = $master_room_price["discounted_price"]; } else { $_SESSION["selected_room_tr"] .= ""; $set_discounted_price = $master_room_price["retail_price"]; } $discounted_price = $set_discounted_price; //check if this kind of room has prepaid / specific discount $sql = "select *, discount.id as master_room_discount_id from master_room_discount discount INNER JOIN master_type_code mtcode ON discount.payment_term = mtcode.code where discount.master_room_id = ? and discount.deleted = ? and mtcode.typeid = ? and ? >= effectivedate_from and ? <= effectivedate_to"; $parameters = array($_POST["master_room_id"], 0, "PAYMENT_TERM", date("Y-m-d"), date("Y-m-d")); $master_room_discount_info = bind_pdo($sql, $parameters, "selectall"); $discount_message = ""; foreach ($master_room_discount_info as $master_room_discount) { //$discount_message .= $master_room_discount["name_tc"] . " -" . $master_room_discount["discount"] . $master_room_discount["discount_type"] . " / "; if ($master_room_discount["payment_term"] == "SPECIFIC_SIZE") { $class = "SPECIFIC_SIZE_DISCOUNT _DISCOUNT DISCOUNT_ID_" . $master_room_discount["master_room_discount_id"]; $discounted_price = $set_discounted_price * (100 - $master_room_discount["discount"]) / 100; } else { $class = "PREPAID_DISCOUNT _DISCOUNT DISCOUNT_ID_" . $master_room_discount["master_room_discount_id"]; $discounted_price = $set_discounted_price; } $discount_message .= $master_room_discount["name_tc"] . " % 折扣 /
"; } $discount_message = substr_replace($discount_message, "", -7); $_SESSION["selected_room_tr"] .= ""; $_SESSION["selected_room_tr"] .= ""; $_SESSION["selected_room_tr"] .= ""; $_SESSION["selected_room_tr"] .= ""; $_SESSION["selected_room_tr"] .= ""; } $_SESSION["selected_room_tr"] .= '
已選取倉庫
倉庫編號 尺寸 原價(月) 優惠價(月) 預繳 / 指定倉庫優惠 價格 價格(折扣後)
" . $room["code"] . " " . $master_room_info["length"] . "X" . $master_room_info["width"] . "X" . $master_room_info["height"] . " $" . numberformat($master_room_price["retail_price"], 2, "") . " $" . $master_room_price["discounted_price"] . " N/A " . $discount_message . "
'; } } else { if (!isset($_SESSION["floor_plan_rent_room"])) { $_SESSION["floor_plan_rent_room"] = array(); } $found = FALSE; foreach ($_SESSION["floor_plan_rent_room"] as $selected_room) { if ($selected_room["room_id"] == $_POST["room_id"]) { $found = TRUE; } } if (!$found) { $_SESSION["floor_plan_rent_room"][] = array("room_id" => $_POST["room_id"], "master_room_id" => $_POST["master_room_id"], "room_code" => $_POST["room_code"]); } echo "success"; } } if ($_GET["for"] == "floor_plan_delete_room") { $room_id = $_POST["room_id"]; if (isset($_SESSION["floor_plan_rent_room"])) { foreach ($_SESSION["floor_plan_rent_room"] as $key => $selected_room) { if ($selected_room["room_id"] == $_POST["room_id"]) { unset($_SESSION["floor_plan_rent_room"][$key]); } } } } if ($_GET["for"] == "update_room") { if (!empty($_POST["room_id"])) { //update record $sql = "update room set status = ?, master_room_id = ?, lastupby = ?, lastupdate = ? where id = ?"; $parameters = array($_POST["room_status"], $_POST["master_room_id"], $_SESSION['cmsloginid'], $nowdate, $_POST["room_id"]); bind_pdo($sql, $parameters); activity_log('_ajax.php', 'update_room', $input = array('post' => $_POST, 'session' => $_SESSION, 'sql' => $sql, 'parameters' => $parameters), $data_before = array(), $data_after = array(), $step = 1); update_master_room_total_number(); echo "倉庫單位: " . $_POST["room_code"] . " 已更新。"; } else { echo "倉庫單位: " . $_POST["room_code"] . " 未能更新。"; } } if ($_GET["for"] == "check_room_contract") { if (!empty($_POST["room_id"])) { $sql = "select `order`.status, `order`.enddate, `order`.code from `room` inner join `order_room` on `order_room`.room_id = `room`.id inner join `order` on `order`.id = `order_room`.order_id where `order_room`.room_id = ? and `order`.enddate > ? and `order`.status = ? and `room`.status = ? order by `order_room`.id DESC limit 1"; $parameters = array($_POST["room_id"], date('Y-m-d'), 'NEW', 'RENTED'); $result = bind_pdo($sql, $parameters, 'selectone'); if (!empty($result)) { echo "倉庫單位: " . $_POST["room_code"] . " 已被合約 " . $result['code'] . " 佔用,請小心操作此單位。"; } } else { echo "找不到倉庫單位。"; } } if ($_GET["for"] == "order_discount") { //debug_log(123, $_POST); $prepaid_month = $_POST["prepaid_month"]; $selected_room_id_list = $_POST["selected_room_id_list"]; $selected_room_id_list = explode(",", $selected_room_id_list); $selected_room_discount_id_list = $_POST["selected_room_discount_id_list"]; $selected_room_discount_id_list = explode(",", $selected_room_discount_id_list); $selected_room_discount_id_value_list = $_POST["selected_room_discount_id_value_list"]; $selected_room_discount_id_value_list = explode(",", $selected_room_discount_id_value_list); $selected_room_discounted_price_list = $_POST["selected_room_discounted_price_list"]; $selected_room_discounted_price_list = explode(",", $selected_room_discounted_price_list); $selected_room_price_list = $_POST["selected_room_price_list"]; $selected_room_price_list = explode(",", $selected_room_price_list); $selected_room_prepaid_month_list = $_POST["selected_room_prepaid_month_list"]; $selected_room_prepaid_month_list = explode(",", $selected_room_prepaid_month_list); $j = 0; $discount_info = array(); arsort($selected_room_prepaid_month_list); foreach ($selected_room_prepaid_month_list as $key => $prepaid_month_list) { $selected_room_id_list_ordered[] = $selected_room_id_list[$key]; $selected_room_discount_id_list_ordered[] = $selected_room_discount_id_list[$key]; $selected_room_discount_id_value_list_ordered[] = $selected_room_discount_id_value_list[$key]; $selected_room_discounted_price_list_ordered[] = $selected_room_discounted_price_list[$key]; $selected_room_price_list_ordered[] = $selected_room_price_list[$key]; $selected_room_prepaid_month_list_ordered[] = $selected_room_prepaid_month_list[$key]; } if (!empty($selected_room_discount_id_list)) { foreach ($selected_room_discount_id_list as $key => $discount_id) { $valid_discount = FALSE; $token = explode("DISCOUNT_ID_", $selected_room_discount_id_list_ordered[$key]); if (empty($token[1])) continue; $this_discount_id = $token[1]; $room_info = get_room($selected_room_id_list_ordered[$key]); $master_room_discount_info = get_master_room_discount($this_discount_id); foreach ($discount_info as $discount) { if ($discount["payment_term"] != "SPECIFIC_SIZE" && $selected_room_id_list_ordered[$key] == $discount["room_id"]) { continue 2; } if ($discount["payment_term"] == "SPECIFIC_SIZE" && $selected_room_id_list_ordered[$key] == $discount["room_id"] && $discount["is_final_discount"] == 1) { continue 2; } } if ($master_room_discount_info["payment_term"] != "SPECIFIC_SIZE") { //prepaid discount $token2 = explode("MONTH_", $selected_room_prepaid_month_list_ordered[$key]); $this_prepaid_month = $token2[1]; //TODO:: must match month? //if ($prepaid_month >= $this_prepaid_month && !empty($prepaid_month)) { if ($prepaid_month == $this_prepaid_month && !empty($prepaid_month)) { $valid_discount = TRUE; } } else { //specific size discount $valid_discount = TRUE; } if ($valid_discount) { $discount_info[$j]["master_room_discount_id"] = $this_discount_id; $discount_info[$j]["master_room_id"] = $master_room_discount_info["master_room_id"]; $discount_info[$j]["discount_type"] = $master_room_discount_info["discount_type"]; $discount_info[$j]["price"] = $selected_room_price_list_ordered[$key]; $discount_info[$j]["disocunted_price"] = $selected_room_discounted_price_list_ordered[$key]; $discount_info[$j]["discount"] = $selected_room_discount_id_value_list_ordered[$key]; $deduct = $selected_room_price_list_ordered[$key] * $selected_room_discount_id_value_list_ordered[$key] / 100; $discount_info[$j]["monthly_deduct"] = $deduct; $discount_info[$j]["room_id"] = $selected_room_id_list_ordered[$key]; $discount_info[$j]["is_final_discount"] = $master_room_discount_info["is_final_discount"]; $discount_info[$j]["payment_term"] = $master_room_discount_info["payment_term"]; $j++; } } //record discount info into session $_SESSION["warehousing"][2]["order_discount"] = $discount_info; } else { $_SESSION["warehousing"][2]["order_discount"] = ""; } //var_dump($_SESSION["warehousing"][2]["order_discount"]); } if ($_GET["for"] == "overdue_email") { echo overdue_email($_POST["order_id"], $_POST["type_code"], $_POST["invoice_id"]); } if ($_GET["for"] == "invoice_email") { invoice_email($_GET["type"], $_GET["invoice_id"]); } /* -- done in terminate_order_modify 29/09/2022 if ($_GET["for"] == "terminate_order_penalty") { //create a penalty invoice of less than 14 announcement $order_info = get_order((int)$_GET["order_id"]); // check if withdraw_remuneration exist if (is_numeric($order_info["withdraw_remuneration"])){ echo ""; exit; } //generate a invoice, need to update when sum the total $sql = "select max(id) as max_id from invoice"; $new_invoice_code_num = bind_pdo($sql, NULL, "selectone"); $location_info = get_location($order_info["location_id"]); $invoice_code = $location_info["location_code"] . "-I" . date("y") . str_pad($new_invoice_code_num["max_id"] + 1, 4, "0", STR_PAD_LEFT); $amount = $_GET["penalty_amount"]; $duedate = $_GET["duedate"]; //$amount = numberformat($order_info["total_discounted_price"] / 30 * 14); $data = array( "order_id" => (int)$_GET["order_id"], "customer_id" => $order_info["customer_id"], "status" => "SENT", "code" => $invoice_code, "amount" => $amount, "balance" => $amount, "docdate" => $nowdate, "duedate" => $duedate, "createby" => $_SESSION['cmsloginid'], "createdate" => $nowdate, "lastupby" => $_SESSION['cmsloginid'], "lastupdate" => $nowdate ); $result = insert_record("invoice", $data); $invoice_id = $dbh->lastInsertId(); $data = array( "invoice_id" => $invoice_id, "type" => "PENALTY", "price" => $amount, "uom_price" => "PCS", "qty" => "1", "amount" => $amount, "remark" => "退倉通知賠償", "createby" => $_SESSION['cmsloginid'], "createdate" => $nowdate, "lastupby" => $_SESSION['cmsloginid'], "lastupdate" => $nowdate ); $result = insert_record("invoice_dtl", $data); if ($result && $invoice_id > 0) { // echo ""; echo ""; exit; } } */ if ($_GET["for"] == "add_extra_rent_invoice") { $message = ""; if (empty($_POST["order_id"])) { $message .= "缺少必須的資料,請重新嘗試。\\n\\n"; } if (!is_numeric($_POST["extra_rent_invoice_amount"]) || (float)$_POST["extra_rent_invoice_amount"] <= 0) { $message .= "請輸入正確的非合約期月份租金。\\n\\n"; } if (!empty($message)) { /*echo ""; exit;*/ echo $message; } else { $order_id = (int)$_POST["order_id"]; $order_info = get_order($order_id); $sql = "select * from invoice inv INNER JOIN invoice_dtl dtl ON inv.id = dtl.invoice_id where inv.order_id = ? order by month DESC limit 1"; $parameters = array($order_id); $invoice_info = bind_pdo($sql, $parameters, "selectone"); if (!empty($invoice_info)) { //if many location active, need to update this $location_info = get_location(1); $sql = "select max(id) as max_id from invoice"; $new_invoice_code_num = bind_pdo($sql, NULL, "selectone"); $invoice_code = $location_info["location_code"] . "-I" . date("y") . str_pad($new_invoice_code_num["max_id"] + 1, 4, "0", STR_PAD_LEFT); $date = new DateTime($order_info["warehousing_date"]); $date->modify('+' . ((int)$invoice_info["month"]) . ' month'); $data = array( "code" => $invoice_code, "order_id" => $order_id, "customer_id" => $order_info["customer_id"], "status" => "SENT", "amount" => $_POST["extra_rent_invoice_amount"], "balance" => $_POST["extra_rent_invoice_amount"], "docdate" => $nowdate, "duedate" => $date->format('Y-m-d'), "createby" => $_SESSION['cmsloginid'], "createdate" => $nowdate, "lastupby" => $_SESSION['cmsloginid'], "lastupdate" => $nowdate ); $result = insert_record("invoice", $data); $rent_invoice_id = $dbh->lastInsertId(); //insert rent invoice detail $data = array( "invoice_id" => $rent_invoice_id, "type" => "RENT", "remark" => "非合約期月份", "month" => ($invoice_info["month"] + 1), "price" => $_POST["extra_rent_invoice_amount"], "uom_price" => "MO", "qty" => "1", "amount" => $_POST["extra_rent_invoice_amount"] * 1, "createby" => $_SESSION['cmsloginid'], "createdate" => $nowdate, "lastupby" => $_SESSION['cmsloginid'], "lastupdate" => $nowdate ); $result = insert_record("invoice_dtl", $data); /*echo ""; exit;*/ //echo "success"; echo $rent_invoice_id; } else { //error $message = "這張合約出現問題,請先檢查合約是否有效。\\n\\n"; /*echo ""; exit;*/ echo $message; } } }