| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hkosl.com/innoutstorage/webadmin/ |
Upload File : |
<?php
require_once('check_login.php');
//checking data
$message = "";
$_SESSION["roughly_size"] = $_POST["roughly_size"];
$_SESSION["total_discounted_price"] = $_POST["total_discounted_price"];
$_SESSION["deposit"] = $_POST["deposit"];
$_SESSION["total_retail_price"] = $_POST["total_retail_price"];
if (empty($_POST["room_id"])) {
$message .= "請選擇要租用的倉庫。\\n\\n";
}
if (empty($_POST["roughly_size"])) {
$message .= "請輸入大約面積。\\n\\n";
}
if (empty($_POST["total_discounted_price"])) {
$message .= "請輸入每月租金。\\n\\n";
} else {
if (!is_numeric($_POST["total_discounted_price"]) || $_POST["total_discounted_price"] < 0) {
$message .= "每月租金應是正數數字。\\n\\n";
}
}
if (!isset($_POST["deposit"])) {
$message .= "請輸入按金。\\n\\n";
} else {
if (!is_numeric($_POST["deposit"]) || $_POST["deposit"] < 0) {
$message .= "按金應是正數數字。\\n\\n";
}
}
if (empty($_POST["rent_month"])) {
$message .= "請選擇租用期月份。\\n\\n";
} else {
if (!is_numeric($_POST["rent_month"])) {
$message .= "租用期月份應是數字。\\n\\n";
}
}
/*if (!isset($_POST["prepaid_month"])) {
$message .= "請選擇預繳月份。\\n\\n";
} else {
if (!is_numeric($_POST["prepaid_month"])) {
$message .= "預繳月份應是數字。\\n\\n";
}
}*/
if ( (!isset($_POST["prepaid_month"]) || $_POST["prepaid_month"] == 0) && isset($_POST["free_first_month"]) && $_POST["free_first_month"] == 1) {
$message .= "免首月月費須要客戶選擇預繳。\\n\\n";
}
if(isset($_POST["free_first_month"]) && $_POST["free_first_month"] == 1 && isset($_POST["prepaid_month"]) && $_POST["prepaid_month"] > 0){
if($_POST["biggest_retail_price"] <= 0 || $_POST["biggest_discounted_price"] <= 0){
$message .= "免首月月費計算有問題,請重新整理頁面並再嘗試。\\n\\n";
}
}
if (!isset($_POST["discount_amount"])) {
$message .= "請輸入優惠金額。\\n\\n";
} else if (!is_numeric($_POST["discount_amount"]) || $_POST["discount_amount"] < 0 ) {
$message .= "優惠金額應是正數數字。\\n\\n";
}
if (!isset($_POST["last_paid"])) {
$message .= "請輸入已付款項。\\n\\n";
} else {
if (!is_numeric($_POST["last_paid"]) || $_POST["last_paid"] < 0 ) {
$message .= "已付款項應是正數數字。\\n\\n";
}else{
if( ($_POST["last_paid"] - $_POST["deposit"]) > ($_POST["rent_month"]*$_POST["total_discounted_price"])){
$message .= "已付款項不應大於總租金金額和按金的總和,請適當增加租用月份。\\n\\n";
}
}
}
if (empty($_POST["warehousing_date"])) {
$message .= "請輸入入倉日期。\\n\\n";
} else {
if (!validateDate($_POST["warehousing_date"], "Y-m-d")) {
$message .= "請輸入正確的入倉日期。\\n\\n";
}
}
if (empty($_POST["rent_from"])) {
$message .= "請輸入生效日期。\\n\\n";
} else {
if (!validateDate($_POST["rent_from"], "Y-m-d")) {
$message .= "租約期生效日期出錯。\\n\\n";
}
}
if (empty($_POST["rent_to"])) {
$message .= "請輸入租約期完結日期。\\n\\n";
} else {
if (!validateDate($_POST["rent_to"], "Y-m-d")) {
$message .= "租約期完結日期出錯。\\n\\n";
}
}
//check delivery service content
if ($_POST["delivery_service"] == 1) {
if (empty($_POST["delivery_date"])) {
$message .= "請輸入服務日期。\\n\\n";
} else {
if (!validateDate($_POST["delivery_date"], "Y-m-d")) {
$message .= "服務日期出錯。\\n\\n";
}
}
if (empty($_POST["delivery_from"])) {
$message .= "請輸入起點。\\n\\n";
}
if (empty($_POST["delivery_to"])) {
$message .= "請輸入終點。\\n\\n";
}
}
//按金付款方式
if (empty($_POST["paymethod"])) {
$message .= "請選擇按金付款方式。\\n\\n";
}else{
if($_POST["paymethod"] == "CHEQUE"){
/*if(empty($_POST["bank_name"])){
$message .= "請輸入 按金付款方式 銀行名稱 。\\n\\n";
}
if(empty($_POST["cheque_num"])){
$message .= "請輸入 按金付款方式 支票號碼 。\\n\\n";
}*/
}
if($_POST["paymethod"] == "BANKIN"){
/*if(empty($_POST["paymethod_other2"])){
$message .= "請輸入付款方式-銀行入數 。\\n\\n";
}*/
}
if($_POST["paymethod"] == "OTHER"){
if(empty($_POST["paymethod_other"])){
$message .= "請輸入 按金付款方式 付款方式-其他 。\\n\\n";
}
}
}
//租金付款方式
if (empty($_POST["paymethod2"])) {
$message .= "請選擇租金付款方式。\\n\\n";
}else{
if($_POST["paymethod2"] == "CHEQUE"){
/*if(empty($_POST["bank_name"])){
$message .= "請輸入 租金付款方式 銀行名稱 。\\n\\n";
}
if(empty($_POST["cheque_num"])){
$message .= "請輸入 租金付款方式 支票號碼 。\\n\\n";
}*/
}
if($_POST["paymethod2"] == "BANKIN"){
/*if(empty($_POST["paymethod2_other2"])){
$message .= "請輸入付款方式-銀行入數 。\\n\\n";
}*/
}
if($_POST["paymethod2"] == "OTHER"){
if(empty($_POST["paymethod_other2"])){
$message .= "請輸入 租金付款方式 付款方式-其他 。\\n\\n";
}
}
}
if (!isset($_POST["order_total"])) {
$message .= "合約總計出錯。\\n\\n";
}
if (!isset($_POST["final_order_total"])) {
$message .= "合約總計(折扣後)出錯。\\n\\n";
}
foreach($_POST["qty"] as $key => $qty){
if(!is_numeric($qty) || $qty < 0){
$message .= "數量應是正數數字。\\n\\n";
break;
}
}
$discount_info = array();
$total_deduct = 0;
$order_room = array();
$i = 0;
$location_id = 0;
if(!empty($_POST["room_id"])){
foreach($_POST["room_id"] as $key => $room){
$order_room[$i]["room_id"] = $_POST["room_id"][$key];
$order_room[$i]["room_code"] = $_POST["room_code"][$key];
$order_room[$i]["retail_price"] = $_POST["retail_price"][$key];
//$_SESSION["warehousing"][2]["order_discount"]
//not stable with post discounted price, change to using order discount and do calculation
if(!empty($_SESSION["warehousing"][2]["order_discount"])){
foreach($_SESSION["warehousing"][2]["order_discount"] as $order_discount){
if($order_discount["room_id"] == $_POST["room_id"][$key]){
$order_room[$i]["discounted_price"] = round($_POST["retail_price"][$key] - $order_discount["monthly_deduct"], 1);
}
}
}else{
$order_room[$i]["discounted_price"] = $_POST["discounted_price"][$key];
}
//$order_room[$i]["discounted_price"] = $_POST["discounted_price"][$key];
$order_room[$i]["location_id"] = $_POST["location_id"][$key];
//check if different location exits
if($i == 0){
$location_id = $_POST["location_id"][$key];
}
else{
if($location_id != $_POST["location_id"][$key]){
$message .= "你不可以選取不同地點的倉庫。\\n\\n";
break;
}
}
$i++;
}
}else{
$message .= "請選取要租用的倉庫。\\n\\n";
}
if(floor($_POST["final_order_total"]) < 0){
$message .= "合約總計(折扣後) 金額不能小於0,請適當增加租用月份或調整其他設定。\\n\\n";
}
if($_POST["total_discounted_price"] > 0 && ceil( ($_POST["last_paid"] - $_POST["deposit"]) / $_POST["total_discounted_price"]) > $_POST["rent_month"]){
$message .= "最少應租用".ceil( ($_POST["last_paid"] - $_POST["deposit"]) / $_POST["total_discounted_price"])."月。\\n\\n";
}
/*if(isset($_POST["prepaid_month"]) && $_POST["prepaid_month"] > 0 && ($_POST["paymethod"] == "UNPAID" || $_POST["paymethod2"] == "UNPAID")){
$message .= "合約選擇預繳,按金和租金付款方式不可以是未付。\\n\\n";
}*/
if(!empty($_POST["free_first_month"])){
$total_deduct += round($_POST["biggest_discounted_price"]-$_POST["biggest_retail_price"]*0.5, 1);
}
//direct deduct
if(!empty($_POST["free_2_month_deduct"])){
$total_deduct += $_POST["free_2_month_deduct"];
}else{
$free_2_month_deduct = 0;
}
if(!empty($_POST["last_paid"])){
$total_deduct += $_POST["last_paid"];
}
$total_deduct += $_POST["discount_amount"];
if($_POST["discount_deduct"] != $total_deduct){
$message .= "折扣扣減計算出錯,請與我們聯絡。\\n\\n";
}
if (!empty($message)) {
echo "<script>alert('" . $message . "'); history.back();</script>";
//echo "<script>alert('" . $message . "');</script>";
exit;
}
//record warehousing order in session
$_SESSION["warehousing"][2]["order_room"] = $order_room;
$_SESSION["warehousing"][2]["roughly_size"] = $_POST["roughly_size"];
$_SESSION["warehousing"][2]["total_retail_price"] = round($_POST["total_retail_price"],1);
$_SESSION["warehousing"][2]["total_discounted_price"] = round($_POST["total_discounted_price"],1);
$_SESSION["warehousing"][2]["deposit"] = round($_POST["deposit"],1);
$_SESSION["warehousing"][2]["rent_month"] = $_POST["rent_month"];
$_SESSION["warehousing"][2]["biggest_retail_price"] = $_POST["biggest_retail_price"];
$_SESSION["warehousing"][2]["biggest_discounted_price"] = $_POST["biggest_discounted_price"];
if(isset($_POST["prepaid_month"])){
$_SESSION["warehousing"][2]["prepaid_month"] = $_POST["rent_month"];
$_SESSION["warehousing"][2]["prepaid_amount"] = round($_POST["total_discounted_price"],1)*$_POST["rent_month"]+round($_POST["deposit"],1);
if($_POST["last_paid"] > 0){
$_SESSION["warehousing"][2]["prepaid_amount"] -= $_POST["last_paid"];
}
}else{
$_SESSION["warehousing"][2]["prepaid_month"] = 0;
$_SESSION["warehousing"][2]["prepaid_amount"] = 0;
}
//if free_first_month > 0 --> has free first month
if(!empty($_POST["free_first_month"])){
$_SESSION["warehousing"][2]["free_first_month"] = 1;
$_SESSION["warehousing"][2]["free_first_month_deduct"] = round($_SESSION["warehousing"][2]["biggest_discounted_price"]-$_SESSION["warehousing"][2]["biggest_retail_price"]*0.5, 1);
if(isset($_POST["prepaid_month"])){
$_SESSION["warehousing"][2]["prepaid_amount"] -= $_SESSION["warehousing"][2]["free_first_month_deduct"];
}
}else{
$_SESSION["warehousing"][2]["free_first_month"] = 0;
$_SESSION["warehousing"][2]["free_first_month_deduct"] = 0;
}
//free_2_month_deduct
$_SESSION["warehousing"][2]["free_2_month_deduct"] = $_POST["free_2_month_deduct"];
if(isset($_POST["prepaid_month"])){
$_SESSION["warehousing"][2]["prepaid_amount"] -= $_SESSION["warehousing"][2]["free_2_month_deduct"];
}
$_SESSION["warehousing"][2]["discount_amount"] = $_POST["discount_amount"];
if(isset($_POST["prepaid_month"])){
$_SESSION["warehousing"][2]["prepaid_amount"] -= $_SESSION["warehousing"][2]["discount_amount"];
}
$_SESSION["warehousing"][2]["last_paid"] = $_POST["last_paid"];
$_SESSION["warehousing"][2]["warehousing_date"] = $_POST["warehousing_date"];
$_SESSION["warehousing"][2]["rent_from"] = $_POST["rent_from"];
$_SESSION["warehousing"][2]["rent_to"] = $_POST["rent_to"];
$_SESSION["warehousing"][2]["delivery_service"] = $_POST["delivery_service"];
if($_POST["delivery_service"] == 1){
$_SESSION["warehousing"][2]["delivery_date"] = $_POST["delivery_date"];
$_SESSION["warehousing"][2]["delivery_from"] = $_POST["delivery_from"];
$_SESSION["warehousing"][2]["delivery_to"] = $_POST["delivery_to"];
}
$_SESSION["warehousing"][2]["remark"] = $_POST["remark"];
$_SESSION["warehousing"][2]["paymethod"] = $_POST["paymethod"];
if($_POST["paymethod"] == "CHEQUE"){
$_SESSION["warehousing"][2]["bank_name"] = $_POST["bank_name"];
$_SESSION["warehousing"][2]["cheque_num"] = $_POST["cheque_num"];
}
if($_POST["paymethod"] == "OTHER"){
$_SESSION["warehousing"][2]["paymethod_other"] = $_POST["paymethod_other"];
}
if($_POST["paymethod"] == "BANKIN"){
$_SESSION["warehousing"][2]["paymethod_other"] = $_POST["paymethod_other2"];
}
$_SESSION["warehousing"][2]["paymethod2"] = $_POST["paymethod2"];
if($_POST["paymethod2"] == "CHEQUE"){
$_SESSION["warehousing"][2]["bank_name2"] = $_POST["bank_name2"];
$_SESSION["warehousing"][2]["cheque_num2"] = $_POST["cheque_num2"];
}
if($_POST["paymethod2"] == "OTHER"){
$_SESSION["warehousing"][2]["paymethod_other2"] = $_POST["paymethod_other2"];
}
if($_POST["paymethod2"] == "BANKIN"){
$_SESSION["warehousing"][2]["paymethod_other2"] = $_POST["paymethod_other22"];
}
$_SESSION["warehousing"][2]["discount_deduct"] = round($_POST["discount_deduct"], 1);
$_SESSION["warehousing"][2]["order_total"] = round($_POST["order_total"], 1);
$_SESSION["warehousing"][2]["final_order_total"] = round($_POST["final_order_total"], 1);
$_SESSION["warehousing"][2]["location_id"] = $location_id;
$location_info = get_location($location_id);
$_SESSION["warehousing"][2]["branch_id"] = $location_info["branch_id"];
$_SESSION["warehousing"][2]["company_id"] = $location_info["company_id"];
//room key
//$_SESSION["warehousing"][2]["room_key"] = implode(",", $_POST["room_key"]);
$_SESSION["warehousing"][2]["room_key"] = $_POST["room_key"];
//$_SESSION["warehousing"][2]["order_discount"] = $_SESSION["discount_info"];
//order product
$order_product = array();
$k = 0;
foreach($_POST["qty"] as $key => $qty){
if(!empty($qty) && (int)$qty > 0){
$order_product[$k]["product_id"] = $_POST["product_id"][$key];
$order_product[$k]["product_name"] = $_POST["product_name"][$key];
$order_product[$k]["qty"] = $_POST["qty"][$key];
$order_product[$k]["price"] = $_POST["price"][$key];
$k++;
}
}
$_SESSION["warehousing"][2]["order_product"] = $order_product;
$_SESSION["warehousing"][2]["pass"] = true;
//go to step 3
header("Location: warehousing_step3.php");