prepare($sql_str);
$stmt->bindParam(':vol_no', $vol_no);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->execute();
$contract = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($attatch1)){
$file = $attatch1;
$file_name = $file['name'];
$file_type = $file['type'];
$tmp_name = $file['tmp_name'];
$file_size = $file['size'];
$error = $file['error'];
$rand = strval(rand(1000,1000000));
$now = (string)date('YmdHis');
$imgsrc = 'm'.$now.$rand.$file_name;
$allow_ext = array('jpeg', 'jpg', 'png', 'gif','JPG','JPEG','PNG','pdf','PDF','docx', 'doc', 'DOCX', 'DOC', 'xlsx', 'xls', 'XLSX', 'XLS');
//設定上傳位置
$path = './pricereview-uploads/';
$attatch1_src = $path.$imgsrc;
if (!file_exists($path)) { mkdir($path); }
if ($error == 0) {
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
if (!in_array($ext, $allow_ext)) {
echo "";
exit('檔案類型不符合,請選擇 jpg、png、excel、word 、pdf檔案');
}
$result = move_uploaded_file($tmp_name, '.'.$attatch1_src);
} else {
//這裡表示上傳有錯誤, 匹配錯誤編號顯示對應的訊息
switch ($error) {
case 1: echo '上傳檔案超過 upload_max_filesize 容量最大值'; break;
case 2: echo '上傳檔案超過 post_max_size 總容量最大值'; break;
case 3: echo '檔案只有部份被上傳'; break;
case 4: echo '沒有檔案被上傳'; break;
case 6: echo '找不到主機端暫存檔案的目錄位置'; break;
case 7: echo '檔案寫入失敗'; break;
case 8: echo '上傳檔案被PHP程式中斷,表示主機端系統錯誤'; break;
}
}
}else{
if($contract){
$attatch1_src = $contract['attatch1'];
}
}
if(!empty($attatch2)){
$file = $attatch2;
$file_name = $file['name'];
$file_type = $file['type'];
$tmp_name = $file['tmp_name'];
$file_size = $file['size'];
$error = $file['error'];
$rand = strval(rand(1000,1000000));
$now = (string)date('YmdHis');
$imgsrc = 'm'.$now.$rand.$file_name;
$allow_ext = array('jpeg', 'jpg', 'png', 'gif','JPG','JPEG','PNG','pdf','PDF','docx', 'doc', 'DOCX', 'DOC', 'xlsx', 'xls', 'XLSX', 'XLS');
//設定上傳位置
$path = './pricereview-uploads/';
$attatch2_src = $path.$imgsrc;
if (!file_exists($path)) { mkdir($path); }
if ($error == 0) {
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
if (!in_array($ext, $allow_ext)) {
echo "";
exit('檔案類型不符合,請選擇 jpg、png、excel、word 、pdf檔案');
}
$result = move_uploaded_file($tmp_name, '.'.$attatch2_src);
} else {
//這裡表示上傳有錯誤, 匹配錯誤編號顯示對應的訊息
switch ($error) {
case 1: echo '上傳檔案超過 upload_max_filesize 容量最大值'; break;
case 2: echo '上傳檔案超過 post_max_size 總容量最大值'; break;
case 3: echo '檔案只有部份被上傳'; break;
case 4: echo '沒有檔案被上傳'; break;
case 6: echo '找不到主機端暫存檔案的目錄位置'; break;
case 7: echo '檔案寫入失敗'; break;
case 8: echo '上傳檔案被PHP程式中斷,表示主機端系統錯誤'; break;
}
}
}else{
if($contract){
$attatch2_src = $contract['attatch2'];
}
}
$conn->beginTransaction();
try{
if(!$contract){
$sql_str = "INSERT INTO con_maintance_examine_apply (apply_key, vol_no, customer, address, case_name ,brand, num, salesman, maintain_kind, contract_begin_date, contract_end_date, contract_kind, payment_kind, progress_remark, service_fee, total_price, total_sale_price, penalty, deposit_rate, keep_rate, warranty_rate, memo, status, attatch1, attatch2, creater, create_at)
VALUES (:apply_key, :vol_no, :customer, :address, :case_name ,:brand, :num, :salesman, :maintain_kind, :contract_begin_date, :contract_end_date, :contract_kind, :payment_kind, :progress_remark, :service_fee, :total_price, :total_sale_price, :penalty, :deposit_rate, :keep_rate, :warranty_rate, :memo, :status, :attatch1, :attatch2, :creater, :create_at)";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->bindParam(':vol_no', $vol_no);
$stmt->bindParam(':customer', $customer);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':case_name', $case_name);
$stmt->bindParam(':brand', $brand);
$stmt->bindParam(':num', $num);
$stmt->bindParam(':salesman', $salesman);
$stmt->bindParam(':maintain_kind', $maintain_kind);
$stmt->bindParam(':contract_begin_date', $contract_begin_date);
$stmt->bindParam(':contract_end_date', $contract_end_date);
$stmt->bindParam(':contract_kind', $contract_kind);
$stmt->bindParam(':payment_kind', $payment_kind);
$stmt->bindParam(':progress_remark', $progress_remark);
$stmt->bindParam(':service_fee', $serviceFee);
$stmt->bindParam(':total_price', $total_price);
$stmt->bindParam(':total_sale_price', $total_sale_price);
$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', $remark);
$stmt->bindParam(':status', $status);
$stmt->bindParam(':attatch1', $attatch1_src);
$stmt->bindParam(':attatch2', $attatch2_src);
$stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $current_date);
$stmt->execute();
$sql_str = "INSERT INTO con_maintance_examine_clear (apply_key, item_no, register_code, elevator_brand, elevator_kind, spec, weight, speed, stop, floors, persons, elevator_num, useful_years, last_check_date, speed_governors_check_expense, maintain_times, is_m1_bundle, maintain_months, maintain_period, maintain_method, stand_price, contract_price, sold_price, commission_expense, management_expense, annual_survey_expense, service_expense, cmstatus, updated_at, creater, created_at)
VALUES (:apply_key, :item_no, :register_code, :elevator_brand, :elevator_kind, :spec, :weight, :speed, :stop, :floors, :persons, :elevator_num, :useful_years, :last_check_date, :speed_governors_check_expense, :maintain_times, :is_m1_bundle, :maintain_months, :maintain_period, :maintain_method, :stand_price, :contract_price, :sold_price, :commission_expense, :management_expense, :annual_survey_expense, :service_expense, :cmstatus, :updated_at, :creater, :created_at) ";
foreach($elevators as $elevator){
if(empty($elevator['permitNumber'])) $register_code = "A";
if($elevator['spec'] == "MAE100") $elevator_kind = "A";
if($elevator['spec'] == "MAF100") $elevator_kind = "B";
if($elevator['spec'] == "MAM200") $elevator_kind = "D";
if($elevator['spec'] == "MAH100") $elevator_kind = "E";
$speed_governors_check_expense = null;
$maintain_times = 1;
$commission_expense = null;
$management_expense = null;
$service_expense = ($elevator['sale_price'] / $total_sale_price) * $serviceFee;
$cmstatus = "Y";
$cycle = (int)$elevator['cycle'];
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->bindParam(':item_no', $elevator['id']);
$stmt->bindParam(':register_code', $register_code);
$stmt->bindParam(':elevator_brand', $elevator['brand']);
$stmt->bindParam(':elevator_kind', $elevator_kind);
$stmt->bindParam(':spec', $elevator['spec']);
$stmt->bindParam(':weight', $elevator['weight']);
$stmt->bindParam(':speed', $elevator['speed']);
$stmt->bindParam(':stop', $elevator['stop']);
$stmt->bindParam(':floors', $elevator['stop']);
$stmt->bindParam(':persons', $elevator['person']);
$stmt->bindParam(':elevator_num', $elevator['qty']);
$stmt->bindParam(':useful_years', $elevator['checkYear']);
$stmt->bindParam(':last_check_date', $elevator['lastDate']);
$stmt->bindParam(':speed_governors_check_expense', $speed_governors_check_expense);
$stmt->bindParam(':maintain_times', $maintain_times);
$stmt->bindParam(':is_m1_bundle', $elevator['m1']);
$stmt->bindParam(':maintain_months', $elevator['months']);
$stmt->bindParam(':maintain_period', $cycle);
$stmt->bindParam(':maintain_method', $elevator['method']);
$stmt->bindParam(':stand_price', $elevator['price']);
$stmt->bindParam(':contract_price', $elevator['sale_price']);
$stmt->bindParam(':sold_price', $elevator['sale_price']);
$stmt->bindParam(':commission_expense', $elevator['commission_expense']);
$stmt->bindParam(':management_expense', $elevator['management_expense']);
$stmt->bindParam(':annual_survey_expense', $elevator['yearCheckFee']);
$stmt->bindParam(':service_expense', $elevator['service_expense']);
$stmt->bindParam(':cmstatus', $cmstatus);
$stmt->bindParam(':updated_at', $updated_at);
$stmt->bindParam(':creater', $creater);
$stmt->bindParam(':created_at', $current_date);
$stmt->execute();
}
$sql_str = "INSERT INTO pricereview_maintain_item (mid, price_id, item_no, item_group, item_spec, option_relate_spec, item_unit_price, item_qty, item_price_bp, memo)
VALUES (:mid, :price_id, :item_no, :item_group, :item_spec, :option_relate_spec, :item_unit_price, :item_qty, :item_price_bp, :memo)";
foreach($otherOptions as $option){
$item_price_bp = $option['price']*$option['num'];
$option_relate_spec = (count($option['toElevator']) > 0) ? $option['toElevator'][0]['id'] : null;
$item_group = "E";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':mid', $apply_key);
$stmt->bindParam(':price_id', $option['pr_no']);
$stmt->bindParam(':item_no', $option['id']);
$stmt->bindParam(':item_group', $item_group);
$stmt->bindParam(':item_spec', $option['name']);
$stmt->bindParam(':option_relate_spec', $option_relate_spec);
$stmt->bindParam(':item_unit_price', $option['price']);
$stmt->bindParam(':item_qty', $option['num']);
$stmt->bindParam(':item_price_bp', $item_price_bp);
$stmt->bindParam(':memo', $option['memo']);
$stmt->execute();
}
}else{
$sql_str = "UPDATE con_maintance_examine_apply SET
case_name=:case_name,
num=:num,
maintain_kind=:maintain_kind,
contract_kind=:contract_kind,
payment_kind=:payment_kind,
contract_begin_date=:contract_begin_date,
contract_end_date=:contract_end_date,
service_fee=:service_fee,
total_price=:total_price,
total_sale_price=:total_sale_price,
penalty=:penalty,
deposit_rate=:deposit_rate,
keep_rate=:keep_rate,
warranty_rate=:warranty_rate,
memo=:memo,
brand=:brand,
status=:status,
attatch1=:attatch1,
attatch2=:attatch2,
updated_at=:updated_at,
progress_remark=:progress_remark
WHERE apply_key=:apply_key AND vol_no=:vol_no";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->bindParam(':vol_no', $vol_no);
$stmt->bindParam(':case_name', $case_name);
$stmt->bindParam(':num', $num);
$stmt->bindParam(':maintain_kind', $maintain_kind);
$stmt->bindParam(':contract_begin_date', $contract_begin_date);
$stmt->bindParam(':contract_end_date', $contract_end_date);
$stmt->bindParam(':contract_kind', $contract_kind);
$stmt->bindParam(':payment_kind', $payment_kind);
$stmt->bindParam(':progress_remark', $progress_remark);
$stmt->bindParam(':service_fee', $serviceFee);
$stmt->bindParam(':total_price', $total_price);
$stmt->bindParam(':total_sale_price', $total_sale_price);
$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', $remark);
$stmt->bindParam(':brand', $brand);
$stmt->bindParam(':status', $status);
$stmt->bindParam(':attatch1', $attatch1_src);
$stmt->bindParam(':attatch2', $attatch2_src);
$stmt->bindParam(':updated_at', $current_date);
$stmt->execute();
//整機單價
$sql_str = "SELECT * FROM con_maintance_examine_clear WHERE (apply_key, cmstatus) = (:apply_key, 'Y')";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->execute();
$oldElevators = $stmt->fetchAll(PDO::FETCH_ASSOC);
$oldItemsNo = (array)array_column($oldElevators, 'item_no');
$newItemsNo = (array)array_column($elevators, 'id');
$onlyInOldIds = array_values(array_diff($oldItemsNo, $newItemsNo)); // 只有舊的有,新傳入的沒有,所以刪除(delete)
$onlyInNewIds = array_values(array_diff($newItemsNo, $oldItemsNo)); //只有新傳入的有,舊的沒有,所以新增(insert)
$inBothIds = array_values(array_intersect($oldItemsNo, $newItemsNo)); //舊的跟新的都有,所以要更新(update)
foreach($onlyInOldIds as $oldIdx){
// $sql_str = "DELETE FROM con_maintance_examine_clear WHERE apply_key=:apply_key AND item_no=:item_no";
$sql_str = "UPDATE con_maintance_examine_clear SET cmstatus = 'D' WHERE apply_key=:apply_key AND item_no=:item_no";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->bindParam(':item_no', $oldIdx);
$stmt->execute();
}
foreach($onlyInNewIds as $newidx){
$sql_str = "INSERT INTO con_maintance_examine_clear (apply_key, item_no, register_code, elevator_brand, elevator_kind, spec, weight, speed, stop, floors, persons, elevator_num, useful_years, last_check_date, speed_governors_check_expense, maintain_times, is_m1_bundle, maintain_months, maintain_period, maintain_method, stand_price, contract_price, sold_price, commission_expense, management_expense, annual_survey_expense, service_expense, cmstatus, updated_at, creater, created_at)
VALUES (:apply_key, :item_no, :register_code, :elevator_brand, :elevator_kind, :spec, :weight, :speed, :stop, :floors, :persons, :elevator_num, :useful_years, :last_check_date, :speed_governors_check_expense, :maintain_times, :is_m1_bundle, :maintain_months, :maintain_period, :maintain_method, :stand_price, :contract_price, :sold_price, :commission_expense, :management_expense, :annual_survey_expense, :service_expense, :cmstatus, :updated_at, :creater, :created_at) ";
$elevator = array_values(array_filter($elevators, fn($el)=> $el['id'] == $newidx))[0];
$register_code = empty($elevator['permitNumber']) ? "A" : $elevator['permitNumber'];
if($elevator['spec'] == "MAE100") $elevator_kind = "A";
if($elevator['spec'] == "MAF100") $elevator_kind = "B";
if($elevator['spec'] == "MAM200") $elevator_kind = "D";
if($elevator['spec'] == "MAH100") $elevator_kind = "E";
$speed_governors_check_expense = null;
$maintain_times = 1;
$commission_expense = null;
$management_expense = null;
$service_expense = ($elevator['sale_price'] / $total_sale_price) * $serviceFee;
$cmstatus = "Y";
$cycle = (int)$elevator['cycle'];
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->bindParam(':item_no', $elevator['id']);
$stmt->bindParam(':register_code', $register_code);
$stmt->bindParam(':elevator_brand', $elevator['brand']);
$stmt->bindParam(':elevator_kind', $elevator_kind);
$stmt->bindParam(':spec', $elevator['spec']);
$stmt->bindParam(':weight', $elevator['weight']);
$stmt->bindParam(':speed', $elevator['speed']);
$stmt->bindParam(':stop', $elevator['stop']);
$stmt->bindParam(':floors', $elevator['stop']);
$stmt->bindParam(':persons', $elevator['person']);
$stmt->bindParam(':elevator_num', $elevator['qty']);
$stmt->bindParam(':useful_years', $elevator['checkYear']);
$stmt->bindParam(':last_check_date', $elevator['lastDate']);
$stmt->bindParam(':speed_governors_check_expense', $speed_governors_check_expense);
$stmt->bindParam(':maintain_times', $maintain_times);
$stmt->bindParam(':is_m1_bundle', $elevator['m1']);
$stmt->bindParam(':maintain_months', $elevator['months']);
$stmt->bindParam(':maintain_period', $cycle);
$stmt->bindParam(':maintain_method', $elevator['method']);
$stmt->bindParam(':stand_price', $elevator['price']);
$stmt->bindParam(':contract_price', $elevator['sale_price']);
$stmt->bindParam(':sold_price', $elevator['sale_price']);
$stmt->bindParam(':commission_expense', $elevator['commission_expense']);
$stmt->bindParam(':management_expense', $elevator['management_expense']);
$stmt->bindParam(':annual_survey_expense', $elevator['yearCheckFee']);
$stmt->bindParam(':service_expense', $elevator['service_expense']);
$stmt->bindParam(':cmstatus', $cmstatus);
$stmt->bindParam(':updated_at', $updated_at);
$stmt->bindParam(':creater', $creater);
$stmt->bindParam(':created_at', $current_date);
$stmt->execute();
}
foreach($inBothIds as $bothidx){
$sql_str = "UPDATE con_maintance_examine_clear SET
register_code=:register_code,
elevator_brand=:elevator_brand,
elevator_kind=:elevator_kind,
spec=:spec,
weight=:weight,
speed=:speed,
stop=:stop,
floors=:floors,
persons=:persons,
elevator_num=:elevator_num,
useful_years=:useful_years,
last_check_date=:last_check_date,
speed_governors_check_expense=:speed_governors_check_expense,
maintain_times=:maintain_times,
is_m1_bundle=:is_m1_bundle,
maintain_months=:maintain_months,
maintain_period=:maintain_period,
maintain_method=:maintain_method,
stand_price=:stand_price,
contract_price=:contract_price,
sold_price=:sold_price,
commission_expense=:commission_expense,
management_expense=:management_expense,
annual_survey_expense=:annual_survey_expense,
service_expense=:service_expense,
cmstatus=:cmstatus,
updated_at=:updated_at
WHERE (apply_key, item_no) = (:apply_key, :item_no)";
$elevator = array_values(array_filter($elevators, fn($el)=> $el['id'] == $bothidx))[0];
$register_code = empty($elevator['permitNumber']) ? "A" : $elevator['permitNumber'];
if($elevator['spec'] == "MAE100") $elevator_kind = "A";
if($elevator['spec'] == "MAF100") $elevator_kind = "B";
if($elevator['spec'] == "MAM200") $elevator_kind = "D";
if($elevator['spec'] == "MAH100") $elevator_kind = "E";
$speed_governors_check_expense = null;
$maintain_times = 1;
$commission_expense = null;
$management_expense = null;
$service_expense = ($elevator['sale_price'] / $total_sale_price) * $serviceFee;
$cmstatus = "Y";
$cycle = (int)$elevator['cycle'];
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->bindParam(':register_code', $register_code);
$stmt->bindParam(':elevator_brand', $elevator['brand']);
$stmt->bindParam(':elevator_kind', $elevator_kind);
$stmt->bindParam(':spec', $elevator['spec']);
$stmt->bindParam(':weight', $elevator['weight']);
$stmt->bindParam(':speed', $elevator['speed']);
$stmt->bindParam(':stop', $elevator['stop']);
$stmt->bindParam(':floors', $elevator['stop']);
$stmt->bindParam(':persons', $elevator['person']);
$stmt->bindParam(':elevator_num', $elevator['qty']);
$stmt->bindParam(':useful_years', $elevator['checkYear']);
$stmt->bindParam(':last_check_date', $elevator['lastDate']);
$stmt->bindParam(':speed_governors_check_expense', $speed_governors_check_expense);
$stmt->bindParam(':maintain_times', $maintain_times);
$stmt->bindParam(':is_m1_bundle', $elevator['m1']);
$stmt->bindParam(':maintain_months', $elevator['months']);
$stmt->bindParam(':maintain_period', $cycle);
$stmt->bindParam(':maintain_method', $elevator['method']);
$stmt->bindParam(':stand_price', $elevator['price']);
$stmt->bindParam(':contract_price', $elevator['sale_price']);
$stmt->bindParam(':sold_price', $elevator['sale_price']);
$stmt->bindParam(':commission_expense', $elevator['commission_expense']);
$stmt->bindParam(':management_expense', $elevator['management_expense']);
$stmt->bindParam(':annual_survey_expense', $elevator['yearCheckFee']);
$stmt->bindParam(':service_expense', $elevator['service_expense']);
$stmt->bindParam(':cmstatus', $cmstatus);
$stmt->bindParam(':updated_at', $updated_at);
$stmt->bindParam(':item_no', $bothidx);
$stmt->execute();
}
//除外項目
$sql_str = "SELECT * FROM pricereview_maintain_item WHERE (mid, item_group) = (:apply_key, 'E')";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->execute();
$item_other_options = $stmt->fetchAll(PDO::FETCH_ASSOC);
$oldOtherOptionsNo = (array)array_column($item_other_options, 'item_no');
$newOtherOptioinNo = (array)array_column($otherOptions, 'id');
$onlyInOtherOptionOldIds = array_values(array_diff($oldOtherOptionsNo, $newOtherOptioinNo));
$onlyInOtherOptionNewIds = array_values(array_diff($newOtherOptioinNo, $oldOtherOptionsNo));
$inBothOtherOptionIds = array_values(array_intersect($oldOtherOptionsNo, $newOtherOptioinNo));
foreach($onlyInOtherOptionOldIds as $oldotheroptionidx){
$sql_str = "DELETE FROM pricereview_maintain_item WHERE (mid, item_no, item_group) = (:apply_key, :item_no, 'E')";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->bindParam(':item_no', $oldotheroptionidx);
$stmt->execute();
}
foreach($onlyInOtherOptionNewIds as $newotheroptionidx){
$option = array_values(array_filter($otherOptions, fn($el)=> $el['id'] == $newotheroptionidx))[0];
$sql_str = "INSERT INTO pricereview_maintain_item (mid, price_id, item_no, item_group, item_spec, option_relate_spec, item_unit_price, item_qty, item_price_bp, memo)
VALUES (:mid, :price_id, :item_no, :item_group, :item_spec, :option_relate_spec, :item_unit_price, :item_qty, :item_price_bp, :memo)";
$item_price_bp = $option['price']*$option['num'];
$option_relate_spec = (count($option['toElevator']) > 0) ? $option['toElevator'][0]['id'] : null;
$item_group = "E";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':mid', $apply_key);
$stmt->bindParam(':price_id', $option['pr_no']);
$stmt->bindParam(':item_no', $option['id']);
$stmt->bindParam(':item_group', $item_group);
$stmt->bindParam(':item_spec', $option['name']);
$stmt->bindParam(':option_relate_spec', $option_relate_spec);
$stmt->bindParam(':item_unit_price', $option['price']);
$stmt->bindParam(':item_qty', $option['num']);
$stmt->bindParam(':item_price_bp', $item_price_bp);
$stmt->bindParam(':memo', $option['memo']);
$stmt->execute();
}
foreach($inBothOtherOptionIds as $bothotheroptionidx){
$option = array_values(array_filter($otherOptions, fn($el)=> $el['id'] == $bothotheroptionidx))[0];
$sql_str = "UPDATE pricereview_maintain_item SET item_spec=:item_spec, price_id=:price_id, option_relate_spec=:option_relate_spec, item_unit_price = :item_unit_price, item_qty = :item_qty, item_price_bp = :item_price_bp, memo = :memo
WHERE (mid, item_no, item_group) = (:apply_key, :item_no, :item_group)";
$item_group = "E";
$item_price_bp = $option['price']*$option['num'];
$option_relate_spec = (count($option['toElevator']) > 0) ? $option['toElevator'][0]['id'] : null;
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->bindParam(':item_no', $option['id']);
$stmt->bindParam(':price_id', $option['pr_no']);
$stmt->bindParam(':item_group', $item_group);
$stmt->bindParam(':item_spec', $option['name']);
$stmt->bindParam(':option_relate_spec', $option_relate_spec);
$stmt->bindParam(':item_unit_price', $option['price']);
$stmt->bindParam(':item_qty', $option['num']);
$stmt->bindParam(':item_price_bp', $item_price_bp);
$stmt->bindParam(':memo', $option['memo']);
$stmt->execute();
}
}
if($status == "YS"){
$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 = "M0012,,";
$sign3 = "M0008,,";
$sign_total = 3;
//服務費大於0 或是 價率低於0.8送至總經理(M0006)
if(false && ($serviceFee > 0 || ($total_sale_price / $total_price) < 0.8)){
$sign4 = "M0006,,";
$sign_total = 4;
}
$sql_str = "INSERT INTO pricereview_maintain_sign (mid, sign1, sign1_note, sign2, sign2_note, sign3, sign3_note, sign4, sign4_note, sign_total, created_at, created_by)
VALUES (:mid, :sign1, :sign1_note, :sign2, :sign2_note, :sign3, :sign3_note, :sign4, :sign4_note, :sign_total, :created_at, :created_by)";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':mid', $apply_key);
$stmt->bindParam(':sign1', $sign1);
$stmt->bindParam(':sign1_note', $sign1_note);
$stmt->bindParam(':sign2', $sign2);
$stmt->bindParam(':sign2_note', $sign2_note);
$stmt->bindParam(':sign3', $sign3);
$stmt->bindParam(':sign3_note', $sign3_note);
$stmt->bindParam(':sign4', $sign4);
$stmt->bindParam(':sign4_note', $sign4_note);
$stmt->bindParam(':sign_total', $sign_total);
$stmt->bindParam(':created_at', $current_date);
$stmt->bindParam(':created_by', $creater);
$stmt->execute();
include_once "./postFlow.php";
$form_key = null;
$createFlow = createFlow($apply_key, $manager, "A", "保養", $form_key);
include_once "./postSystemNotice.php";
$sql_str = "SELECT * FROM con_maintance_examine_apply WHERE apply_key = :apply_key ORDER BY create_at DESC LIMIT 1";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->execute();
$contract = $stmt->fetch(PDO::FETCH_ASSOC);
$kind = 1;
$related_id = $apply_key;
$title = "保養價審待簽通知(".$vol_no."," .$customer. ")";
$content = "待簽核";
$content = "合約號:".$vol_no . "
";
$content .= "客戶名稱:" . $customer . "
";
$content .= "案件名稱:" . $case_name . "
";
$content .= "時間" . $current_date;
// $content .= "