You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
8.3 KiB
204 lines
8.3 KiB
<?php
|
|
require_once("../conn.php");
|
|
date_default_timezone_set('Asia/Taipei');
|
|
|
|
$contractno = $_POST['contractno'];
|
|
$ekind = $_POST['ekind'];
|
|
$person = $_POST['person'];
|
|
$company = $_POST['company'];
|
|
$case_name = $_POST['case_name'];
|
|
$address = $_POST['address'];
|
|
$compete = "";
|
|
$price_lowest = $_POST['price_lowest'];
|
|
$price_total = $_POST['price_total'];
|
|
$price_rate = $_POST['price_rate'];
|
|
$special_fee = $_POST['special_fee'];
|
|
$predeal_date = $_POST['predeal_date'];
|
|
$penalty = $_POST['penalty'];
|
|
$deposit_rate = $_POST['deposit_rate'];
|
|
$warranty_rate = $_POST['warranty_rate'];
|
|
$keep_rate = $_POST['keep_rate'];
|
|
$memo = $_POST['memo'];
|
|
$status = $_POST['status'];
|
|
$attatch1 = $_POST['attatch1'] =='' ? NULL : $_POST['attatch1'];
|
|
$attatch2 = $_POST['attatch2'] =='' ? NULL : $_POST['attatch2'];
|
|
$creater = "M0174";
|
|
$create_at = date("Y-m-d H:i:s");
|
|
|
|
|
|
$elevators = $_POST['elevators'];
|
|
$options = $_POST['options'];
|
|
$otherOptions = $_POST['otherOptions'];
|
|
$maintainOptions = $_POST['maintainOptions'];
|
|
|
|
$paymentRatio = $_POST['paymentRatio'];
|
|
|
|
$conn->beginTransaction();
|
|
|
|
try{
|
|
|
|
$sql_str = "INSERT INTO pricereview_main (contractno, ekind, person, company, case_name, address, compete, price_lowest, price_total, price_rate, special_fee, predeal_date, facilitok_date, penalty, deposit_rate, keep_rate, warranty_rate, memo, status, attatch1, attatch2, creater, create_at)
|
|
VALUES (:contractno, :ekind, :person, :company, :case_name, :address, :compete, :price_lowest, :price_total, :price_rate, :special_fee, :predeal_date, :facilitok_date, :penalty, :deposit_rate, :keep_rate, :warranty_rate, :memo, :status, :attatch1, :attatch2, :creater, :create_at)";
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':contractno', $contractno);
|
|
$stmt->bindParam(':ekind', $ekind);
|
|
$stmt->bindParam(':person', $person);
|
|
$stmt->bindParam(':company', $company);
|
|
$stmt->bindParam(':case_name', $case_name);
|
|
$stmt->bindParam(':address', $address);
|
|
$stmt->bindParam(':compete', $compete);
|
|
$stmt->bindParam(':price_lowest', $price_lowest);
|
|
$stmt->bindParam(':price_total', $price_total);
|
|
$stmt->bindParam(':price_rate', $price_rate);
|
|
$stmt->bindParam(':special_fee', $special_fee);
|
|
$stmt->bindParam(':predeal_date', $predeal_date);
|
|
$stmt->bindParam(':facilitok_date', $facilitok_date);
|
|
$stmt->bindParam(':penalty', $penalty);
|
|
$stmt->bindParam(':deposit_rate', $deposit_rate);
|
|
$stmt->bindParam(':keep_rate', $keep_rate);
|
|
$stmt->bindParam(':warranty_rate', $warranty_rate);
|
|
$stmt->bindParam(':memo', $memo);
|
|
$stmt->bindParam(':status', $status);
|
|
$stmt->bindParam(':attatch1', $attatch1);
|
|
$stmt->bindParam(':attatch2', $attatch2);
|
|
$stmt->bindParam(':creater', $creater);
|
|
$stmt->bindParam(':create_at', $create_at);
|
|
$stmt->execute();
|
|
$mid = $conn->lastInsertId();
|
|
|
|
//insert 整機單價
|
|
|
|
|
|
//insert options 加價
|
|
$sql_str = "INSERT INTO pricereview_item (mid, price_id, item_no, item_group, item_spec, option_relate_spec, item_unit_price, item_qty, item_price_bp)
|
|
VALUES (:mid, :price_id, :item_no, :item_group, :item_spec, :option_relate_spec, :item_unit_price, :item_qty, :item_price_bp)";
|
|
|
|
foreach(json_decode($options, true) as $option){
|
|
$price_id = $option['id'];
|
|
$item_no = $option['key'] + 1;
|
|
$item_group = "B";
|
|
$item_spec = $option['name'] . $option['memo'];
|
|
$option_relate_spec = $option['toElevator'][0]['id'];
|
|
$item_unit_price = $option['price'];
|
|
$item_qty = $option['qty'];
|
|
$item_price_bp = $option['price'] * $option['qty'];
|
|
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':mid', $mid);
|
|
$stmt->bindParam(':price_id', $price_id);
|
|
$stmt->bindParam(':item_no', $item_no);
|
|
$stmt->bindParam(':item_group', $item_group);
|
|
$stmt->bindParam(':item_spec', $item_spec);
|
|
$stmt->bindParam(':option_relate_spec', $option_relate_spec);
|
|
$stmt->bindParam(':item_unit_price', $item_unit_price);
|
|
$stmt->bindParam(':item_qty', $item_qty);
|
|
$stmt->bindParam(':item_price_bp', $item_price_bp);
|
|
$stmt->execute();
|
|
}
|
|
|
|
//insert 除外項目
|
|
$sql_str = "INSERT INTO pricereview_item (mid, item_no, item_group, item_spec, option_relate_spec, item_unit_price, item_qty, item_price_bp)
|
|
VALUES (:mid, :item_no, :item_group, :item_spec, :option_relate_spec, :item_unit_price, :item_qty, :item_price_bp)";
|
|
|
|
foreach(json_decode($otherOptions, true) as $option){
|
|
$item_no = $option['id'] + 1;
|
|
$item_group = "E";
|
|
$item_spec = $option['name'];
|
|
$option_relate_spec = $option['toElevator'][0]['id'];
|
|
$item_unit_price = $option['price'];
|
|
$item_qty = $option['num'];
|
|
$item_price_bp = $option['price'] * $option['num'];
|
|
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':mid', $mid);
|
|
$stmt->bindParam(':item_no', $item_no);
|
|
$stmt->bindParam(':item_group', $item_group);
|
|
$stmt->bindParam(':item_spec', $item_spec);
|
|
$stmt->bindParam(':option_relate_spec', $option_relate_spec);
|
|
$stmt->bindParam(':item_unit_price', $item_unit_price);
|
|
$stmt->bindParam(':item_qty', $item_qty);
|
|
$stmt->bindParam(':item_price_bp', $item_price_bp);
|
|
$stmt->execute();
|
|
}
|
|
|
|
$sql_str = "INSERT INTO pricereview_item (mid, item_no, item_group, item_spec, option_relate_spec, item_unit_price, item_qty, item_price_bp)
|
|
VALUES (:mid, :item_no, :item_group, :item_spec, :option_relate_spec, :item_unit_price, :item_qty, :item_price_bp)";
|
|
//insert 保養延長
|
|
foreach(json_decode($maintainOptions, true) as $option){
|
|
$item_no = $option['id'] + 1;
|
|
$item_group = "D";
|
|
$item_spec = $option['toElevator'][0]['model'];
|
|
$option_relate_spec = $option['toElevator'][0]['id'];
|
|
$item_unit_price = $option['price'];
|
|
$item_qty = $option['num'];
|
|
$item_price_bp = $option['price'] * $option['num'];
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':mid', $mid);
|
|
$stmt->bindParam(':item_no', $item_no);
|
|
$stmt->bindParam(':item_group', $item_group);
|
|
$stmt->bindParam(':item_spec', $item_spec);
|
|
$stmt->bindParam(':option_relate_spec', $option_relate_spec);
|
|
$stmt->bindParam(':item_unit_price', $item_unit_price);
|
|
$stmt->bindParam(':item_qty', $item_qty);
|
|
$stmt->bindParam(':item_price_bp', $item_price_bp);
|
|
$stmt->execute();
|
|
}
|
|
|
|
|
|
$sql_str = "INSERT INTO pricereview_pay (mid, pay_kind, pay_scale, pay_amount, pay_period)
|
|
VALUES (:mid, :pay_kind, :pay_scale, :pay_amount, :pay_period)";
|
|
|
|
foreach(json_decode($paymentRatio, true) as $key=>$pay){
|
|
$pay_kind = $key +1;
|
|
$pay_scale = $pay['scale'] == '' ? 0 : $pay['scale'];
|
|
$pay_amount = $pay['scale']/100 * $price_total;
|
|
$pay_period = $pay['ticket'];
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':mid', $mid);
|
|
$stmt->bindParam(':pay_kind', $pay_kind);
|
|
$stmt->bindParam(':pay_scale', $pay_scale);
|
|
$stmt->bindParam(':pay_amount', $pay_amount);
|
|
$stmt->bindParam(':pay_period', $pay_period);
|
|
$stmt->execute();
|
|
}
|
|
|
|
$sql_str = "SELECT * FROM account WHERE accountid = :accountid";
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':accountid', $creater);
|
|
$stmt->execute();
|
|
$account = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
$manager = $account['manager'];
|
|
|
|
$sign1 = "$manager,,"; //區處長
|
|
$sign2 = NULL; // 業務承辦人
|
|
$sign3 = "M0060,,"; //業務部協理
|
|
|
|
//是否呈核至總經理(M0006)
|
|
if($price_rate < 80 || $special_fee > 0){
|
|
$sign4 = "M0006,,";
|
|
$sign_total = 4;
|
|
}else{
|
|
$sign4 = NULL;
|
|
$sign_total = 3;
|
|
}
|
|
|
|
$sql_str = "INSERT INTO pricereview_sign (mid, sign1, sign2, sign3, sign4, sign_total)
|
|
VALUES (:mid, :sign1, :sign2, :sign3, :sign4, :sign_total)";
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':mid', $mid);
|
|
$stmt->bindParam(':sign1', $sign1);
|
|
$stmt->bindParam(':sign2', $sign2);
|
|
$stmt->bindParam(':sign3', $sign3);
|
|
$stmt->bindParam(':sign4', $sign4);
|
|
$stmt->bindParam(':sign_total', $sign_total);
|
|
$stmt->execute();
|
|
|
|
|
|
echo "success";
|
|
|
|
$conn->commit();
|
|
}catch (PDOException $e) {
|
|
$conn->rollback();
|
|
echo $e->getMessage();
|
|
die('Error!:' . $e->getMessage());
|
|
}
|