Browse Source

契約簽回

main
Cheng 1 year ago
parent
commit
3aa59d03d5
  1. 4
      wms/bonus/api/postSchedule.php
  2. 244
      wms/bonus/elevator_new/elevator_new_deal_bonus_v1_0_1.php
  3. 80
      wms/bonus/elevator_new/elevator_new_deal_bonus_v1_0_examination.php
  4. 38
      wms/class/T8API.php
  5. 8
      wms/contract/api/T8api.php
  6. 804
      wms/contract/api/postContractData.php
  7. 83
      wms/contract/api/test copy.json
  8. 17
      wms/contract/api/testT8API.php
  9. 10
      wms/contract/api/testocde.php
  10. 20
      wms/contract/contract-input.php
  11. 9
      wms/contract/js/alpine.js
  12. 18
      wms/schedule-edit.php
  13. 22
      wms/schedule-index.php
  14. 66
      wms/schedule-setting-repaire-update.php
  15. 192
      wms/schedule-setting-repaire.php

4
wms/bonus/api/postSchedule.php

@ -1,4 +0,0 @@
<?php
include_once "./wms/contract/conn.php";
$contractno = !empty($_POST['contractno']) ? $_POST['contractno'] : '';
$facilityno = !empty($_POST['facilityno']) ? $_POST['facilityno'] : '';

244
wms/bonus/elevator_new/elevator_new_deal_bonus_v1_0_1.php

@ -7,7 +7,9 @@
【1.輸入參數:】 【1.輸入參數:】
獎金版本($ver):1.0 獎金版本($ver):1.0
合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer) 合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer)
作番賣價($elevator_knockdown_price):電梯的合約最後成交價 1.0 作番賣價($elevator_knockdown_price):電梯的合約最後成交價
1.0_1 作番賣價($elevator_knockdown_price) : 電梯合約價格收款階段比例金額
營業員員工號($sales_id) 營業員員工號($sales_id)
區域經理員工號($region_manger_id) 區域經理員工號($region_manger_id)
@ -34,80 +36,186 @@ result_array[
*/ */
/* paykind_arr =[
[
pay_kind -- 1=訂金、2=二次款、3=貨到工地款、4=材料其他、5=安裝完畢、6=驗收款、7=其他安裝款
pay_scale -- 百分比
pay_amount -- 金額
],
[
]
]
*/
function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_price, $elevator_pay_kind, $sales_id, $region_manger_id) function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_pay_kind, $sales_id, $region_manger_id)
{ {
// echo "<pre>";
// print_r($elevator_pay_kind);
// echo "</pre>";
// exit;
$bonus_array = []; $bonus_array = [];
if ($ver == "1.0") { if ($ver == "1.0") {
#合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer) #合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer)
switch ($contract_type) { foreach ($elevator_pay_kind as $elevator_pay_kind) {
case "strategy_customer": switch ($contract_type) {
#契約員獎金($sales_bonus) case "strategy_customer":
$sales_bonus = $elevator_knockdown_price * 0.007; #契約員獎金($sales_bonus)
#地區經理經理獎金($region_manager_bonus) $sales_bonus = $elevator_pay_kind['pay_amount'] * 0.007;
$region_manager_bonus = 400; #地區經理經理獎金($region_manager_bonus)
break; $region_manager_bonus = 400;
break;
case "general_customer":
#契約員獎金($sales_bonus) case "general_customer":
$sales_bonus = $elevator_knockdown_price * 0.015; #契約員獎金($sales_bonus)
#區域經理獎金($region_manager_bonus) $sales_bonus = $elevator_pay_kind['pay_amount'] * 0.015;
$region_manager_bonus = 600; #區域經理獎金($region_manager_bonus)
break; $region_manager_bonus = 600;
}; break;
};
#營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% $pay_scale = $elevator_pay_kind['pay_scale'];
array_push($bonus_array, [ // echo "<pre>";
"bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 // print_r($pay_scale);
"bonus_receiver" => $sales_id, #發放人員 // echo "</pre>";
"bonus_amount" => round($sales_bonus * 0.2), #金額 switch ($elevator_pay_kind['pay_kind']) {
"payment_schedul_due" => "deposit", #訂金已收款20%
"payment_schedul_regulation" => "訂金已收款20%,發放總獎金20%" #發放規定 case '1':
]); array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱
#營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% "bonus_receiver" => $sales_id, #發放人員
array_push($bonus_array, [ "bonus_amount" => $sales_bonus, #金額
"bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 "payment_schedul_due" => "deposit", #訂金已收款20%
"bonus_receiver" => $sales_id, #發放人員 "payment_schedul_regulation" => "訂金已收款$pay_scale%,發放總獎金$pay_scale%" #發放規定
"bonus_amount" => round($sales_bonus * 0.5), #金額 ]);
"payment_schedul_due" => "shipping", #訂金已收款20%
"payment_schedul_regulation" => "出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%" #發放規定 array_push($bonus_array, [
]); "bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱
"bonus_receiver" => $region_manger_id, #發放人員
#營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% "bonus_amount" => round($region_manager_bonus * 0.5), #金額
array_push($bonus_array, [ "payment_schedul_due" => "deposit", #訂金已收款100%
"bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 "payment_schedul_regulation" => "訂金已收款100%,發放總獎金50%" #發放規定
"bonus_receiver" => $sales_id, #發放人員 ]);
"bonus_amount" => round($sales_bonus * 0.3), #金額 break;
"payment_schedul_due" => "acceptance", #訂金已收款20% case '2':
"payment_schedul_regulation" => "驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%" #發放規定 array_push($bonus_array, [
]); "bonus_type" => "營銷人員銷售獎金-二次段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
#區域經理獎金水庫-----訂金已收款100%,發放總獎金50% "bonus_amount" => $sales_bonus, #金額
array_push($bonus_array, [ "payment_schedul_due" => "twice", #訂金已收款20%
"bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 "payment_schedul_regulation" => "訂金已收款$pay_scale%,發放總獎金$pay_scale%" #發放規定
"bonus_receiver" => $region_manger_id, #發放人員 ]);
"bonus_amount" => round($region_manager_bonus * 0.5), #金額 break;
"payment_schedul_due" => "deposit", #訂金已收款100% case '3':
"payment_schedul_regulation" => "訂金已收款100%,發放總獎金50%" #發放規定 array_push($bonus_array, [
]); "bonus_type" => "營銷人員銷售獎金-貨到工地款段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
#區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% "bonus_amount" => $sales_bonus, #金額
array_push($bonus_array, [ "payment_schedul_due" => "shipping", #訂金已收款20%
"bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 "payment_schedul_regulation" => "出貨前期所有款項已收齊,且出貨款已收款$pay_scale%,發放總獎金$pay_scale%" #發放規定
"bonus_receiver" => $region_manger_id, #發放人員 ]);
"bonus_amount" => round($region_manager_bonus * 0.5), #金額
"payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100% array_push($bonus_array, [
"payment_schedul_regulation" => "貨到工地款(含)之前所有款項已收款100%,發放總獎金50%" #發放規定 "bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱
]); "bonus_receiver" => $region_manger_id, #發放人員
"bonus_amount" => round($region_manager_bonus * 0.5), #金額
$result_array = [ "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100%
"ver" => $ver, #獎金版本 "payment_schedul_regulation" => "貨到工地款(含)之前所有款項已收款100%,發放總獎金50%" #發放規定
"result_status" => "success", #計算結果 ]);
"bonus_array" => $bonus_array #獎金水庫 break;
];
case '4':
array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-材料其他段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => $sales_bonus, #金額
"payment_schedul_due" => "other", #訂金已收款20%
"payment_schedul_regulation" => "訂金已收款$pay_scale%,發放總獎金$pay_scale%" #發放規定
]);
break;
case '5':
array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-安裝完畢段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => $sales_bonus, #金額
"payment_schedul_due" => "installed", #訂金已收款20%
"payment_schedul_regulation" => "訂金已收款$pay_scale%,發放總獎金$pay_scale%" #發放規定
]);
break;
case '6':
array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => $sales_bonus, #金額
"payment_schedul_due" => "acceptance", #訂金已收款20%
"payment_schedul_regulation" => "驗收前期所有款項已收齊,且驗收款已收款$pay_scale%,發放總獎金$pay_scale%" #發放規定
]);
break;
case '7':
array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-安裝其他段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => $sales_bonus, #金額
"payment_schedul_due" => "installOther", #訂金已收款20%
"payment_schedul_regulation" => "訂金已收款$pay_scale%,發放總獎金$pay_scale%" #發放規定
]);
break;
}
#營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20%
// array_push($bonus_array, [
// "bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱
// "bonus_receiver" => $sales_id, #發放人員
// "bonus_amount" => round($sales_bonus * 0.2), #金額
// "payment_schedul_due" => "deposit", #訂金已收款20%
// "payment_schedul_regulation" => "訂金已收款20%,發放總獎金20%" #發放規定
// ]);
#營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%
// array_push($bonus_array, [
// "bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱
// "bonus_receiver" => $sales_id, #發放人員
// "bonus_amount" => round($sales_bonus * 0.5), #金額
// "payment_schedul_due" => "shipping", #訂金已收款20%
// "payment_schedul_regulation" => "出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%" #發放規定
// ]);
#營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%
// array_push($bonus_array, [
// "bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱
// "bonus_receiver" => $sales_id, #發放人員
// "bonus_amount" => round($sales_bonus * 0.3), #金額
// "payment_schedul_due" => "acceptance", #訂金已收款20%
// "payment_schedul_regulation" => "驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%" #發放規定
// ]);
#區域經理獎金水庫-----訂金已收款100%,發放總獎金50%
// array_push($bonus_array, [
// "bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱
// "bonus_receiver" => $region_manger_id, #發放人員
// "bonus_amount" => round($region_manager_bonus * 0.5), #金額
// "payment_schedul_due" => "deposit", #訂金已收款100%
// "payment_schedul_regulation" => "訂金已收款100%,發放總獎金50%" #發放規定
// ]);
// #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50%
// array_push($bonus_array, [
// "bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱
// "bonus_receiver" => $region_manger_id, #發放人員
// "bonus_amount" => round($region_manager_bonus * 0.5), #金額
// "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100%
// "payment_schedul_regulation" => "貨到工地款(含)之前所有款項已收款100%,發放總獎金50%" #發放規定
// ]);
$result_array = [
"ver" => $ver, #獎金版本
"result_status" => "success", #計算結果
"bonus_array" => $bonus_array #獎金水庫
];
}
} else { } else {
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "error", #獎金名稱 "bonus_type" => "error", #獎金名稱

80
wms/bonus/elevator_new/elevator_new_deal_bonus_v1_0_examination.php

@ -1,9 +1,15 @@
<?php <?php
/* 函數用法與參數 /*
獎金辦法 1.0_1 說明,需要查看合約收入的款項去發放該款項的獎金
函數用法與參數
【1.輸入參數:】 【1.輸入參數:】
獎金版本($ver):1.0 獎金版本($ver):1.0
合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer) 合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer)
作番賣價($elevator_knockdown_price):電梯的合約最後成交價 1.0 作番賣價($elevator_knockdown_price):電梯的合約最後成交價
1.0_1 作番賣價($elevator_knockdown_price) : 電梯合約價格收款階段比例金額
營業員員工號($sales_id) 營業員員工號($sales_id)
區域經理員工號($region_manger_id) 區域經理員工號($region_manger_id)
@ -30,43 +36,77 @@ result_array[
*/ */
/* paykind_arr =[
[
pay_kind -- 1=訂金、2=二次款、3=貨到工地款、4=材料其他、5=安裝完畢、6=驗收款、7=其他安裝款
pay_scale -- 百分比
pay_amount -- 金額
],
[
]
]
*/
require_once("elevator_new_deal_bonus_v1_0.php"); require_once("elevator_new_deal_bonus_v1_0_1.php");
#$ver, $contract_type, $elevator_knockdown_price, $sales_id, $region_manger_id #$ver, $contract_type, $elevator_knockdown_price, $sales_id, $region_manger_id
#獎金測試 #獎金測試
$pay_kind_arr = [
[
"pay_kind" => '1',
"pay_scale" => 20,
"pay_amount" => 318000
],
[
"pay_kind" => '3',
"pay_scale" => 50,
"pay_amount" => 795000
],
[
"pay_kind" => '5',
"pay_scale" => 20,
"pay_amount" => 318000
],
[
"pay_kind" => '6',
"pay_scale" => 10,
"pay_amount" => 159000
]
];
$examination_array = [ $examination_array = [
#錯誤版本 #錯誤版本
["2.0","strategy_customer",1000000,"M0001", "M0003"], ["1.0", "strategy_customer", ($pay_kind_arr), "M0001", "M0003"],
#戰略客戶(strategy_customer) #戰略客戶(strategy_customer)
["1.0","strategy_customer",1000000,"M0001", "M0003"], #戰略客戶 // ["1.0", "strategy_customer", 1000000, "M0001", "M0003"], #戰略客戶
#一般客戶(general_customer) // #一般客戶(general_customer)
["1.0","general_customer",1000000,"M0001", "M0003"] #一般客戶 ["1.0", "general_customer", $pay_kind_arr, "M0001", "M0003"] #一般客戶
]; ];
for($i = 0; $i<count($examination_array); $i++){ for ($i = 0; $i < count($examination_array); $i++) {
$result = elevator_new_deal_bonus_v1_0( $result = elevator_new_deal_bonus_v1_0(
$examination_array[$i][0], $examination_array[$i][0],
$examination_array[$i][1], $examination_array[$i][1],
$examination_array[$i][2], $examination_array[$i][2],
$examination_array[$i][3], $examination_array[$i][3],
$examination_array[$i][4] $examination_array[$i][4]
); );
// echo "<pre>";
// print_r($examination_array);
// echo "</pre>";
echo "獎金版本:" . $result["ver"] . "<br>"; echo "獎金版本:" . $result["ver"] . "<br>";
echo "計算結果:" . $result["result_status"] . "<br>"; echo "計算結果:" . $result["result_status"] . "<br>";
echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . "<br>"; echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . "<br>";
for($j = 0; $j<count($result["bonus_array"]); $j++){ for ($j = 0; $j < count($result["bonus_array"]); $j++) {
echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " " echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " "
. $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["payment_schedul_due"] . " " . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["payment_schedul_due"] . " "
. $result["bonus_array"][$j]["payment_schedul_regulation"] . "<br>"; . $result["bonus_array"][$j]["payment_schedul_regulation"] . "<br>";
}; };
echo "-------------------------" . "<br>"; echo "-------------------------" . "<br>";
}; };
?>

38
wms/class/T8API.php

@ -0,0 +1,38 @@
<?php
require_once("../T8_Authorization_from_bpm.php");
function T8salIncomeApply($data, $api_url)
{
$validation = get_Auth();
$header = [
"CHI_Authorization :" . $validation,
"GroupId:TEST"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url); // 设置请求的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1); // 使用 POST
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
$response = curl_exec($ch);
if ($response === false) {
echo 'Curl error: ' . curl_error($ch);
} else {
$result = json_decode($response, true);
// 若 API 傳入失敗。
if ($result['Status'] == 'Erroe') {
echo 'API傳入失敗,' . $result['ErrorMsg'];
return $result;
} else {
// print_r($result);
return $result;
}
return $result;
}
curl_close($ch);
}

8
wms/contract/api/T8api.php

@ -4,12 +4,8 @@ require_once("../../T8_Authorization_from_bpm.php");
function T8salIncomeApply($data, $api_url) function T8salIncomeApply($data, $api_url)
{ {
// $api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData';
$validation = get_Auth(); $validation = get_Auth();
echo '<pre>';
print_r($validation);
echo '</pre>';
// exit;
$header = [ $header = [
"CHI_Authorization :" . $validation, "CHI_Authorization :" . $validation,
"GroupId:TEST" "GroupId:TEST"
@ -29,7 +25,7 @@ function T8salIncomeApply($data, $api_url)
$result = json_decode($response, true); $result = json_decode($response, true);
// 若 API 傳入失敗。 // 若 API 傳入失敗。
if ($result['Status'] == 'Erroe') { if ($result['Status'] == 'Erroe') {
echo 'API傳入失敗,' . $result['ErrorMsg']; // echo 'API傳入失敗,' . $result['ErrorMsg'];
return $result; return $result;
} else { } else {
// print_r($result); // print_r($result);

804
wms/contract/api/postContractData.php

@ -1,4 +1,3 @@
<?php <?php
header("Content-Type: text/html; charset=utf-8"); header("Content-Type: text/html; charset=utf-8");
require_once("../conn.php"); require_once("../conn.php");
@ -11,434 +10,443 @@ include_once("../../class/Cmail.php");
ini_set('date.timezone', 'Asia/Taipei'); ini_set('date.timezone', 'Asia/Taipei');
//保養簽回 //保養簽回
if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['contracttype']) && $_POST['contracttype'] == 'b') { if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['contracttype']) && $_POST['contracttype'] == 'b') {
// try { try {
$mail = new Cmail(); $mail = new Cmail();
$created_at = date('Y-m-d H:i:s'); $created_at = date('Y-m-d H:i:s');
$contractno = !empty($_POST['contractno']) ? $_POST['contractno'] : null; $contractno = !empty($_POST['contractno']) ? $_POST['contractno'] : null;
$total_price = !empty($_POST['total_price']) ? $_POST['total_price'] : null; $total_price = !empty($_POST['total_price']) ? $_POST['total_price'] : null;
$vat = !empty($_POST['vat']) ? $_POST['vat'] : null; $vat = !empty($_POST['vat']) ? $_POST['vat'] : null;
$mtype = !empty($_POST['mtype']) ? $_POST['mtype'] : null; $mtype = !empty($_POST['mtype']) ? $_POST['mtype'] : null;
$opendoor = !empty($_POST['opendoor']) ? $_POST['opendoor'] : null; $opendoor = !empty($_POST['opendoor']) ? $_POST['opendoor'] : null;
$phone = !empty($_POST['phone']) ? $_POST['phone'] : null; $phone = !empty($_POST['phone']) ? $_POST['phone'] : null;
$email = !empty($_POST['email']) ? $_POST['email'] : null; $email = !empty($_POST['email']) ? $_POST['email'] : null;
$mworker = !empty($_POST['mworker']) ? $_POST['mworker'] : ''; $mworker = !empty($_POST['mworker']) ? $_POST['mworker'] : '';
// $mcycle = !empty($_POST['mcycle']) ? $_POST['mcycle'] : null; // $mcycle = !empty($_POST['mcycle']) ? $_POST['mcycle'] : null;
$salesman = !empty($_POST['salesman']) ? $_POST['salesman'] : null; $salesman = !empty($_POST['salesman']) ? $_POST['salesman'] : null;
$contract_begin_date = !empty($_POST['contract_begin_date']) ? $_POST['contract_begin_date'] : null; $contract_begin_date = !empty($_POST['contract_begin_date']) ? $_POST['contract_begin_date'] : null;
$contract_end_date = !empty($_POST['contract_end_date']) ? $_POST['contract_end_date'] : null; $contract_end_date = !empty($_POST['contract_end_date']) ? $_POST['contract_end_date'] : null;
$address = !empty($_POST['address']) ? $_POST['address'] : null; $address = !empty($_POST['address']) ? $_POST['address'] : null;
$area = !empty($_POST['area']) ? $_POST['area'] : null; $area = !empty($_POST['area']) ? $_POST['area'] : null;
$customer = !empty($_POST['customer']) ? $_POST['customer'] : null; $customer = !empty($_POST['customer']) ? $_POST['customer'] : null;
$partyA = !empty($_POST['partyA']) ? $_POST['partyA'] : null; $partyA = !empty($_POST['partyA']) ? $_POST['partyA'] : null;
$partyAaddress = !empty($_POST['partyAaddress']) ? $_POST['partyAaddress'] : null; $partyAaddress = !empty($_POST['partyAaddress']) ? $_POST['partyAaddress'] : null;
$partyAphone = !empty($_POST['partyAphone']) ? $_POST['partyAphone'] : null; $partyAphone = !empty($_POST['partyAphone']) ? $_POST['partyAphone'] : null;
$partyAemail = !empty($_POST['partyAemail']) ? $_POST['partyAemail'] : null; $partyAemail = !empty($_POST['partyAemail']) ? $_POST['partyAemail'] : null;
$user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null;
$user_name = !empty($_POST['user_name']) ? $_POST['user_name'] : null; $user_name = !empty($_POST['user_name']) ? $_POST['user_name'] : null;
$num = !empty($_POST['num']) ? $_POST['num'] : null; $num = !empty($_POST['num']) ? $_POST['num'] : null;
$files = !empty($_FILES['files']) ? $_FILES['files'] : null; $files = !empty($_FILES['files']) ? $_FILES['files'] : null;
$elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : [];
$payType = !empty($_POST['payType']) ? $_POST['payType'] : null; $payType = !empty($_POST['payType']) ? $_POST['payType'] : null;
$contract_type = !empty($_POST['contract_type']) ? $_POST['contract_type'] : null; $contract_type = !empty($_POST['contract_type']) ? $_POST['contract_type'] : null;
$signing_date = !empty($_POST['signing_date']) ? $_POST['signing_date'] : null; $signing_date = !empty($_POST['signing_date']) ? $_POST['signing_date'] : null;
$token = !empty($_POST['token']) ? $_POST['token'] : ''; $token = !empty($_POST['token']) ? $_POST['token'] : '';
$maintance_manager = !empty($_POST['maintance_manager']) ? $_POST['maintance_manager'] : '';
$sql = "SELECT * FROM account WHERE accountid = '$salesman'"; $sql = "SELECT * FROM account WHERE accountid = '$salesman'";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
$accountData = $stmt->fetch(PDO::FETCH_ASSOC); $accountData = $stmt->fetch(PDO::FETCH_ASSOC);
$depId = $accountData['department_id']; $depId = $accountData['department_id'];
// validate // validate
//create facility table //create facility table
$createFacilityNo = new CreateFacilityNo(); $createFacilityNo = new CreateFacilityNo();
$dailyNecessities = [ $dailyNecessities = [
'MAE100' => 'X', 'MAE100' => 'X',
'MAM200' => 'W', 'MAM200' => 'W',
'MAH100' => 'H', 'MAH100' => 'H',
'MAQ100' => 'Z', 'MAQ100' => 'Z',
'MAF100' => 'F', 'MAF100' => 'F',
'MAZ100' => 'B', 'MAZ100' => 'B',
]; ];
$maintain_times = [ $maintain_times = [
'1' => 'em', //月保 '1' => 'em', //月保
'2' => 'bw' // 雙周保 '2' => 'bw' // 雙周保
]; ];
$facility_arr = []; $facility_arr = [];
foreach ($elevators as $elevator) { foreach ($elevators as $elevator) {
$facility_arr[] = $dailyNecessities[$elevator['spec']]; $facility_arr[] = $dailyNecessities[$elevator['spec']];
} }
// echo json_encode($facility_arr); // echo json_encode($facility_arr);
// 電梯做番號 // 電梯做番號
$facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num);
// exit(); // exit();
// if ($user_id == 'M0225') { // if ($user_id == 'M0225') {
// echo '<pre>'; // echo '<pre>';
// print_r($facilityno); // print_r($facilityno);
// echo '</pre>'; // echo '</pre>';
// exit(); // exit();
// } // }
$fail_arr = []; $fail_arr = [];
// if ($contractno === '') return $fail_arr[] = '合約號為必填'; // if ($contractno === '') return $fail_arr[] = '合約號為必填';
if ($total_price == '') $fail_arr[] = '合約總價為必填'; if ($total_price == '') $fail_arr[] = '合約總價為必填';
if ($salesman == '') $fail_arr[] = '營業員為必填'; if ($salesman == '') $fail_arr[] = '營業員為必填';
if ($contract_begin_date == '') $fail_arr[] = '合約開始時間為必填'; if ($contract_begin_date == '') $fail_arr[] = '合約開始時間為必填';
if ($contract_end_date == '') $fail_arr[] = '合約結束時間為必填'; if ($contract_end_date == '') $fail_arr[] = '合約結束時間為必填';
if ($address == '') $fail_arr[] = '地址為必填'; if ($address == '') $fail_arr[] = '地址為必填';
if ($area == '') $fail_arr[] = '區域為必填'; if ($area == '') $fail_arr[] = '區域為必填';
if ($customer == '') $fail_arr[] = '客戶為必填'; if ($customer == '') $fail_arr[] = '客戶為必填';
if ($num == '') $fail_arr[] = '電梯數量為必填'; if ($num == '') $fail_arr[] = '電梯數量為必填';
if ($payType == '') $fail_arr[] = '分期方式為必填'; if ($payType == '') $fail_arr[] = '分期方式為必填';
if ($contract_type == '') $fail_arr[] = '合約類別為必填'; if ($contract_type == '') $fail_arr[] = '合約類別為必填';
if ($maintance_manager == '') $fail_arr[] = '保養經理為必填';
//-------------------
// if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; //-------------------
// if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; // if ($partyA == '') $fail_arr[] = '業務聯繫人為必填';
// if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; // if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填';
// if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; // if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填';
// if ($vat == '') $fail_arr[] = '統一編號為必填'; // if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填';
// if ($mtype == '') $fail_arr[] = '維修型態為必填'; // if ($vat == '') $fail_arr[] = '統一編號為必填';
// if ($phone == '') $fail_arr[] = '客戶電話為必填'; // if ($mtype == '') $fail_arr[] = '維修型態為必填';
// if ($email == '') $fail_arr[] = 'Email為必填'; // if ($phone == '') $fail_arr[] = '客戶電話為必填';
// if ($mworker == '') $fail_arr[] = '保養員為必填'; // if ($email == '') $fail_arr[] = 'Email為必填';
// if ($mcycle == '') $fail_arr[] = '保養頻率為必填'; // if ($mworker == '') $fail_arr[] = '保養員為必填';
if (count($fail_arr) > 0) { // if ($mcycle == '') $fail_arr[] = '保養頻率為必填';
header("HTTP/1.1 422 Unprocessable Entity"); if (count($fail_arr) > 0) {
echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); header("HTTP/1.1 422 Unprocessable Entity");
echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE);
exit();
}
exit(); exit();
} T8insert($_POST, $facilityno, $depId, $connT8);
// T8insert($_POST, $facilityno, $depId, $connT8);
/// 獎金計算
$aaa = bonusCreate($_POST, $facilityno, $conn);
if (!empty($aaa) && $aaa['status'] == 2) {
header("HTTP/1.1 422 Unprocessable Entity");
echo $aaa['data'];
exit(); exit();
} /// 獎金計算
// exit(); $aaa = bonusCreate($_POST, $facilityno, $conn);
//create account table if (!empty($aaa) && $aaa['status'] == 2) {
$accounttype = "A"; header("HTTP/1.1 422 Unprocessable Entity");
$accountid = $vat; echo $aaa['data'];
$pwd = "123"; exit();
$name = $partyA; }
$tel = $phone ?? ''; // exit();
$repairerid = $mworker; //create account table
$creater = $user_id; $accounttype = "A";
$create_at = date('Y-m-d H:i:s'); $accountid = $vat;
$pwd = "123";
// exit(); $name = $partyA;
$tel = $phone ?? '';
$repairerid = $mworker;
$creater = $user_id;
$create_at = date('Y-m-d H:i:s');
// exit();
$conn->beginTransaction();
$sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)"; $conn->beginTransaction();
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':accounttype', $accounttype);
$stmt->bindParam(':accountid', $accountid);
$stmt->bindParam(':pwd', $pwd);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':tel', $tel);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':repairerid', $repairerid);
$stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at);
$stmt->execute();
//create contract table $sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)";
$contracttype = $mtype;
$company = $partyA;
$taxid = $vat;
$tel = $phone;
$promiser = $partyA;
$contractperson = $partyA;
$contractaddress = $address;
$contracttel = $phone;
$contractemail = $email;
$contract_employee = $salesman;
$start_date = $contract_begin_date;
$end_date = $contract_end_date;
$sql_str = "INSERT INTO contract (contracttype, contractno, company, taxid, address, tel, promiser, contractperson, contractaddress, contracttel, contractemail, contract_employee, start_date, end_date, creater, create_at) VALUES (:contracttype, :contractno, :company, :taxid, :address, :tel, :promiser, :contractperson, :contractaddress, :contracttel, :contractemail, :contract_employee, :start_date, :end_date, :creater, :create_at)";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':contracttype', $contracttype);
$stmt->bindParam(':contractno', $contractno);
$stmt->bindParam(':company', $company);
$stmt->bindParam(':taxid', $taxid);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':tel', $tel);
$stmt->bindParam(':promiser', $promiser);
$stmt->bindParam(':contractperson', $contractperson);
$stmt->bindParam(':contractaddress', $contractaddress);
$stmt->bindParam(':contracttel', $contracttel);
$stmt->bindParam(':contractemail', $contractemail);
$stmt->bindParam(':contract_employee', $contract_employee);
$stmt->bindParam(':start_date', $start_date);
$stmt->bindParam(':end_date', $end_date);
$stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at);
$stmt->execute();
//create facility table
// $createFacilityNo = new CreateFacilityNo();
// $dailyNecessities = [
// 'MAE100' => 'X',
// 'MAM200' => 'W',
// 'MAH100' => 'H',
// 'MAQ100' => 'Z',
// 'MAF100' => 'F',
// 'MAZ100' => 'B',
// ];
// $maintain_times = [
// '1' => 'em', //月保
// '2' => 'bw' // 雙周保
// ];
// $facility_arr = [];
// foreach ($elevators as $elevator) {
// $facility_arr[] = $dailyNecessities[$elevator['spec']];
// }
// echo json_encode($facility_arr);
// // 電梯做番號
// $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num);
// // if ($user_id == 'M0225') {
// // echo '<pre>';
// // print_r($facilityno);
// // echo '</pre>';
// // exit();
// // }
// echo json_encode($facilityno);
// echo '-------';
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid AND accounttype IN ('B','E','M','W')";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':accountid', $mworker);
$stmt->execute();
$worker = $stmt->fetch(PDO::FETCH_ASSOC);
$customerid = $vat;
$repairtype = $mtype;
$repairerid = $mworker;
$define = "B";
$repairername = !empty($worker) ? $worker['name'] : '';
foreach ($elevators as $idx => $elevator) {
// 民國年轉換西元年
$ROCuseful_date = $elevator['useful_date'];
$click = explode("-", $ROCuseful_date);
$click[0] = intval($click[0]) + 1911;
$ADuseful_date = implode("-", $click);
$sql_str = "INSERT INTO facility (contractno, define, facilityno, latitude, longitude, customerid, weight, numberofpassenger, numberofstop, numberoffloor, opentype, speed, repairtype, maintainance, facility_kind, address, repairerid, repairername, creater, create_at, area, takecertificatedate, licensedate)
VALUES (:contractno, :define, :facilityno, :latitude, :longitude, :customerid, :weight, :numberofpassenger, :numberofstop, :numberoffloor, :opentype, :speed, :repairtype, :maintainance, :facility_kind, :address, :repairerid, :repairername, :creater, :create_at, :area, :takecertificatedate, :licensedate)";
$stmt = $conn->prepare($sql_str); $stmt = $conn->prepare($sql_str);
$stmt->bindParam(':contractno', $contractno); $stmt->bindParam(':accounttype', $accounttype);
$stmt->bindParam(':define', $define); $stmt->bindParam(':accountid', $accountid);
$stmt->bindParam(':facilityno', $facilityno[$idx]); $stmt->bindParam(':pwd', $pwd);
$stmt->bindParam(':latitude', $elevator['latitude']); $stmt->bindParam(':name', $name);
$stmt->bindParam(':longitude', $elevator['longitude']); $stmt->bindParam(':tel', $tel);
$stmt->bindParam(':customerid', $customerid);
$stmt->bindParam(':weight', $elevator['weight']);
$stmt->bindParam(':numberofpassenger', $elevator['persons']);
$stmt->bindParam(':numberofstop', $elevator['stop']);
$stmt->bindParam(':numberoffloor', $elevator['floors']);
$stmt->bindParam(':opentype', $elevator['opendoor']);
$stmt->bindParam(':speed', $elevator['speed']);
$stmt->bindParam(':repairtype', $repairtype);
$stmt->bindParam(':maintainance', $elevator['maintainance']);
$stmt->bindParam(':facility_kind', $elevator['spec']);
$stmt->bindParam(':address', $address); $stmt->bindParam(':address', $address);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':repairerid', $repairerid); $stmt->bindParam(':repairerid', $repairerid);
$stmt->bindParam(':repairername', $repairername);
$stmt->bindParam(':creater', $creater); $stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at); $stmt->bindParam(':create_at', $create_at);
$stmt->bindParam(':area', $area); $stmt->execute();
$stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']);
$stmt->bindParam(':licensedate', $ADuseful_date);
$result = $stmt->execute();
}
$sql = "SELECT * FROM account WHERE accountid = '$user_id' ";
$stmt = $conn->prepare($sql);
$stmt->execute();
$user_detail = $stmt->fetch(PDO::FETCH_ASSOC);
//create contract table
//create schedule table $contracttype = $mtype;
// $comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date); $company = $partyA;
// $comboArr = json_decode($comboNo->getComboNo(), true); $taxid = $vat;
foreach ($facilityno as $key => $no) { $tel = $phone;
$comboNo = new CreateComboNo($maintain_times[$elevator['maintain_times']], $contract_begin_date, $contract_end_date); $promiser = $partyA;
$comboArr = json_decode($comboNo->getComboNo(), true); $contractperson = $partyA;
foreach ($comboArr as $combo) { $contractaddress = $address;
$sql_str = 'INSERT INTO schedule $contracttel = $phone;
(contractno, facilityno, combono, repairerid, repairername,customer_login_name, duedate, creater, create_at) VALUES $contractemail = $email;
(:contractno, :facilityno, :combono, :repairerid, :repairername, :customer_login_name,:duedate, :creater, :create_at)'; $contract_employee = $salesman;
$start_date = $contract_begin_date;
$end_date = $contract_end_date;
$sql_str = "INSERT INTO contract (contracttype, contractno, company, taxid, address, tel, promiser, contractperson, contractaddress, contracttel, contractemail, contract_employee, start_date, end_date, creater, create_at) VALUES (:contracttype, :contractno, :company, :taxid, :address, :tel, :promiser, :contractperson, :contractaddress, :contracttel, :contractemail, :contract_employee, :start_date, :end_date, :creater, :create_at)";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':contracttype', $contracttype);
$stmt->bindParam(':contractno', $contractno);
$stmt->bindParam(':company', $company);
$stmt->bindParam(':taxid', $taxid);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':tel', $tel);
$stmt->bindParam(':promiser', $promiser);
$stmt->bindParam(':contractperson', $contractperson);
$stmt->bindParam(':contractaddress', $contractaddress);
$stmt->bindParam(':contracttel', $contracttel);
$stmt->bindParam(':contractemail', $contractemail);
$stmt->bindParam(':contract_employee', $contract_employee);
$stmt->bindParam(':start_date', $start_date);
$stmt->bindParam(':end_date', $end_date);
$stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at);
$stmt->execute();
//create facility table
// $createFacilityNo = new CreateFacilityNo();
// $dailyNecessities = [
// 'MAE100' => 'X',
// 'MAM200' => 'W',
// 'MAH100' => 'H',
// 'MAQ100' => 'Z',
// 'MAF100' => 'F',
// 'MAZ100' => 'B',
// ];
// $maintain_times = [
// '1' => 'em', //月保
// '2' => 'bw' // 雙周保
// ];
// $facility_arr = [];
// foreach ($elevators as $elevator) {
// $facility_arr[] = $dailyNecessities[$elevator['spec']];
// }
// echo json_encode($facility_arr);
// // 電梯做番號
// $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num);
// // if ($user_id == 'M0225') {
// // echo '<pre>';
// // print_r($facilityno);
// // echo '</pre>';
// // exit();
// // }
// echo json_encode($facilityno);
// echo '-------';
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid AND accounttype IN ('B','E','M','W')";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':accountid', $mworker);
$stmt->execute();
$worker = $stmt->fetch(PDO::FETCH_ASSOC);
$customerid = $vat;
$repairtype = $mtype;
$repairerid = $mworker;
$define = "B";
$repairername = !empty($worker) ? $worker['name'] : '';
foreach ($elevators as $idx => $elevator) {
// 民國年轉換西元年
$ROCuseful_date = $elevator['useful_date'];
$click = explode("-", $ROCuseful_date);
$click[0] = intval($click[0]) + 1911;
$ADuseful_date = implode("-", $click);
$sql_str = "INSERT INTO facility (contractno, define, facilityno, latitude, longitude, customerid, weight, numberofpassenger, numberofstop, numberoffloor, opentype, speed, repairtype, maintainance, facility_kind, address, repairerid, repairername, creater, create_at, area, takecertificatedate, licensedate)
VALUES (:contractno, :define, :facilityno, :latitude, :longitude, :customerid, :weight, :numberofpassenger, :numberofstop, :numberoffloor, :opentype, :speed, :repairtype, :maintainance, :facility_kind, :address, :repairerid, :repairername, :creater, :create_at, :area, :takecertificatedate, :licensedate)";
$stmt = $conn->prepare($sql_str); $stmt = $conn->prepare($sql_str);
$stmt->bindParam(':contractno', $contractno); $stmt->bindParam(':contractno', $contractno);
$stmt->bindParam(':facilityno', $no); $stmt->bindParam(':define', $define);
$stmt->bindParam(':combono', $combo[0]); $stmt->bindParam(':facilityno', $facilityno[$idx]);
$stmt->bindParam(':latitude', $elevator['latitude']);
$stmt->bindParam(':longitude', $elevator['longitude']);
$stmt->bindParam(':customerid', $customerid);
$stmt->bindParam(':weight', $elevator['weight']);
$stmt->bindParam(':numberofpassenger', $elevator['persons']);
$stmt->bindParam(':numberofstop', $elevator['stop']);
$stmt->bindParam(':numberoffloor', $elevator['floors']);
$stmt->bindParam(':opentype', $elevator['opendoor']);
$stmt->bindParam(':speed', $elevator['speed']);
$stmt->bindParam(':repairtype', $repairtype);
$stmt->bindParam(':maintainance', $elevator['maintainance']);
$stmt->bindParam(':facility_kind', $elevator['spec']);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':repairerid', $repairerid); $stmt->bindParam(':repairerid', $repairerid);
$stmt->bindParam(':repairername', $repairername); $stmt->bindParam(':repairername', $repairername);
$stmt->bindParam(':duedate', $combo[1]);
$stmt->bindParam(':customer_login_name', $customer);
$stmt->bindParam(':creater', $creater); $stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at); $stmt->bindParam(':create_at', $create_at);
$stmt->bindParam(':area', $area);
$stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']);
$stmt->bindParam(':licensedate', $ADuseful_date);
$result = $stmt->execute(); $result = $stmt->execute();
} }
$sql = "SELECT * FROM account WHERE accountid = '$user_id' ";
// $regular_contract_manger_id = $elevators[$idx]['regular_contract_manger_id'];
// $sql = "SELECT * FROM account WHERE accountid = '' ";
$regular_contract_manger_id = !empty($elevators[$key]['regular_contract_manger_id']) ? $elevators[$key]['regular_contract_manger_id'] : '';
// if ($regular_contract_manger_id != '') {
$sql = "SELECT * FROM account WHERE accountid = '$regular_contract_manger_id' ";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
$regular_contract_manger_mail = $stmt->fetch(PDO::FETCH_ASSOC); $user_detail = $stmt->fetch(PDO::FETCH_ASSOC);
$mail_title = "保養計畫 : 合約號:" . $contractno . "作番號:" . $no . "-營業經理提交至設計階段"; //create schedule table
$mail_content = "保養計畫 : 合約號:" . $contractno . "作番號:" . $no . "-營業經理提交至設計階段 <a href='https://www.masada.com.tw/wms/schedule-index.php?contractno=$contractno&facilityno=$no&token=$token'>點我</a>"; // $comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date);
// exit(); // $comboArr = json_decode($comboNo->getComboNo(), true);
$mail->sendx( foreach ($facilityno as $key => $no) {
$mail_title, $comboNo = new CreateComboNo($maintain_times[$elevator['maintain_times']], $contract_begin_date, $contract_end_date);
$mail_content, $comboArr = json_decode($comboNo->getComboNo(), true);
[
// [$user_id, $user_detail['email']], foreach ($comboArr as $combo) {
// [$regular_contract_manger_id, $regular_contract_manger_mail['mail']], $sql_str = 'INSERT INTO schedule
['M0225', 'lkmd555@masada.com.tw'] (contractno, facilityno, combono, repairerid, repairername,customer_login_name, duedate, creater, create_at) VALUES
], (:contractno, :facilityno, :combono, :repairerid, :repairername, :customer_login_name,:duedate, :creater, :create_at)';
"永佳捷科技"
);
// echo 'send';
// }
}
// create contract_b_signed_back table
$contract_type = $mtype;
$company = $customer;
$customer_no = $vat;
$salesperson = $salesman;
$customer_phone = $phone;
$customer_email = $email;
$repairman = $mworker;
// $cycle = $mcycle;
$contact_person = $partyA;
$contact_address = $partyAaddress;
$contact_phone = $partyAphone;
$contract_email = $partyAemail;
$elevators_number = $num;
$bonus = 1000;
$max_bonus = 2000;
if (!empty($files)) {
$englisharr = range('a', 'z');
$file = $_FILES['files'];
$file_name = $file['name'];
$file_type = $file['type'];
$tmp_name = $file['tmp_name'];
$file_size = $file['size'];
$error = $file['error'];
$newfiles = [];
foreach ($files as $file) {
$i = 0; //新陣列的索引編號
foreach ($file as $key => $val) {
$newfiles[$i]['name'] = $files['name'][$key];
$newfiles[$i]['type'] = $files['type'][$key];
$newfiles[$i]['tmp_name'] = $files['tmp_name'][$key];
$newfiles[$i]['error'] = $files['error'][$key];
$newfiles[$i]['size'] = $files['size'][$key];
$i++;
} //foreach 第2層 end
}
$max_size = 4096 * 4096; //設定允許上傳檔案容量的最大值(1M)
$allow_ext = array('jpeg', 'jpg', 'png', 'JPG', 'JPEG', 'PNG', 'GIF'); //設定允許上傳檔案的類型
$path = '../images/contracts/';
if (!file_exists($path)) {
mkdir($path);
}
$msg_result = ''; //負責接收所有檔案檢測後的回傳訊息
$datetime = (string)date('YmdHis');
$files_id = 'b' . $datetime; // 保養=>b + 日期時間
foreach ($newfiles as $key => $file) {
$randNum = rand(1000, 9999);
$randEnglish = $englisharr[rand(0, 25)];
$file_name = 'b' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum . $file['name'];
$msg = upload_chk($file, $path, $max_size, $allow_ext, $file_name);
if ($msg == 1) {
$msg = '檔案傳送成功!';
$sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)";
$stmt = $conn->prepare($sql_str); $stmt = $conn->prepare($sql_str);
$stmt->bindParam(':files_id', $files_id); $stmt->bindParam(':contractno', $contractno);
$stmt->bindParam(':file_name', $file_name); $stmt->bindParam(':facilityno', $no);
$stmt->bindParam(':file_mime', $file['type']); $stmt->bindParam(':combono', $combo[0]);
$stmt->bindParam(':file_size', $file['size']); $stmt->bindParam(':repairerid', $repairerid);
$stmt->bindParam(':created_at', $created_at); $stmt->bindParam(':repairername', $repairername);
$stmt->bindParam(':created_by', $user_id); $stmt->bindParam(':duedate', $combo[1]);
$stmt->execute(); $stmt->bindParam(':customer_login_name', $customer);
$stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at);
$result = $stmt->execute();
}
// $regular_contract_manger_id = $elevators[$idx]['regular_contract_manger_id'];
// $sql = "SELECT * FROM account WHERE accountid = '' ";
$sql = "SELECT * FROM account WHERE accountid = '$maintance_manager' ";
$stmt = $conn->prepare($sql);
$stmt->execute();
$maintance_manager_detail = $stmt->fetch(PDO::FETCH_ASSOC);
// 寄郵件給 輸入合約助理,請他安排保養計畫
// 北北基 : M0090
// 保養組長 桃竹 : M0223
// 中部 : M0161
// 南部 : M0077
// 保養組長之後調整
$mail_title = "保養計畫 : 合約號:" . $contractno . "作番號:" . $no . "-請安排此作番的保養人員";
$mail_content = "保養計畫 : 合約號:" . $contractno . "作番號:" . $no . "-請安排此作番的保養人員 <a href='https://www.masada.com.tw/wms/schedule-index.php?contractno=$contractno&facilityno=$no&token=$token'>點我</a>";
// exit();
$mail->sendx(
$mail_title,
$mail_content,
[
// [$user_id, $user_detail['email']],
// [$maintance_manager, $maintance_manager_detail['email']],
// ['M0012', 'Yingying@masada.com.tw']
// [$regular_contract_manger_id, $regular_contract_manger_mail['mail']],
['M0225', 'lkmd555@masada.com.tw']
// ['M0012', 'Yingying@masada.com.tw']
],
"永佳捷科技"
);
// echo 'send';
// }
}
// create contract_b_signed_back table
$contract_type = $mtype;
$company = $customer;
$customer_no = $vat;
$salesperson = $salesman;
$customer_phone = $phone;
$customer_email = $email;
$repairman = $mworker;
// $cycle = $mcycle;
$contact_person = $partyA;
$contact_address = $partyAaddress;
$contact_phone = $partyAphone;
$contract_email = $partyAemail;
$elevators_number = $num;
$bonus = 1000;
$max_bonus = 2000;
if (!empty($files)) {
$englisharr = range('a', 'z');
$file = $_FILES['files'];
$file_name = $file['name'];
$file_type = $file['type'];
$tmp_name = $file['tmp_name'];
$file_size = $file['size'];
$error = $file['error'];
$newfiles = [];
foreach ($files as $file) {
$i = 0; //新陣列的索引編號
foreach ($file as $key => $val) {
$newfiles[$i]['name'] = $files['name'][$key];
$newfiles[$i]['type'] = $files['type'][$key];
$newfiles[$i]['tmp_name'] = $files['tmp_name'][$key];
$newfiles[$i]['error'] = $files['error'][$key];
$newfiles[$i]['size'] = $files['size'][$key];
$i++;
} //foreach 第2層 end
} }
$msg_result .= '第' . ($key + 1) . '個上傳檔案的結果:' . $msg . '<br/>'; $max_size = 4096 * 4096; //設定允許上傳檔案容量的最大值(1M)
$src_name = $path . $file['name']; $allow_ext = array('jpeg', 'jpg', 'png', 'JPG', 'JPEG', 'PNG', 'GIF'); //設定允許上傳檔案的類型
if (file_exists($src_name)) { $path = '../images/contracts/';
//副檔名 if (!file_exists($path)) {
$extname = pathinfo($src_name, PATHINFO_EXTENSION); mkdir($path);
//主檔名
$basename = basename($src_name, '.' . $extname);
} }
$msg_result = ''; //負責接收所有檔案檢測後的回傳訊息
$datetime = (string)date('YmdHis');
$files_id = 'b' . $datetime; // 保養=>b + 日期時間
foreach ($newfiles as $key => $file) {
$randNum = rand(1000, 9999);
$randEnglish = $englisharr[rand(0, 25)];
$file_name = 'b' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum . $file['name'];
$msg = upload_chk($file, $path, $max_size, $allow_ext, $file_name);
if ($msg == 1) {
$msg = '檔案傳送成功!';
$sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':files_id', $files_id);
$stmt->bindParam(':file_name', $file_name);
$stmt->bindParam(':file_mime', $file['type']);
$stmt->bindParam(':file_size', $file['size']);
$stmt->bindParam(':created_at', $created_at);
$stmt->bindParam(':created_by', $user_id);
$stmt->execute();
}
$msg_result .= '第' . ($key + 1) . '個上傳檔案的結果:' . $msg . '<br/>';
$src_name = $path . $file['name'];
if (file_exists($src_name)) {
//副檔名
$extname = pathinfo($src_name, PATHINFO_EXTENSION);
//主檔名
$basename = basename($src_name, '.' . $extname);
}
}
} else {
$files = null;
} }
} else { $sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price,payType, customer_phone, customer_email, repairman, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by,signing_date)
$files = null;
}
$sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price,payType, customer_phone, customer_email, repairman, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by,signing_date)
VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :payType ,:customer_phone, :customer_email, :repairman, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by,:signing_date)"; VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :payType ,:customer_phone, :customer_email, :repairman, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by,:signing_date)";
$stmt = $conn->prepare($sql_str); $stmt = $conn->prepare($sql_str);
$stmt->bindParam(":contract_no", $contractno); $stmt->bindParam(":contract_no", $contractno);
$stmt->bindParam(":contract_type", $contract_type); $stmt->bindParam(":contract_type", $contract_type);
$stmt->bindParam(":company", $company); $stmt->bindParam(":company", $company);
$stmt->bindParam(":customer_no", $customer_no); $stmt->bindParam(":customer_no", $customer_no);
$stmt->bindParam(":salesperson", $salesperson); $stmt->bindParam(":salesperson", $salesperson);
$stmt->bindParam(":contract_start_date", $contract_begin_date); $stmt->bindParam(":contract_start_date", $contract_begin_date);
$stmt->bindParam(":contract_end_date", $contract_end_date); $stmt->bindParam(":contract_end_date", $contract_end_date);
$stmt->bindParam(":total_price", $total_price); $stmt->bindParam(":total_price", $total_price);
$stmt->bindParam(":customer_phone", $customer_phone); $stmt->bindParam(":customer_phone", $customer_phone);
$stmt->bindParam(":customer_email", $customer_email); $stmt->bindParam(":customer_email", $customer_email);
$stmt->bindParam(":repairman", $repairman); $stmt->bindParam(":repairman", $repairman);
// $stmt->bindParam(":cycle", $cycle); // 保養頻率在做番上,這邊不 insert。 // $stmt->bindParam(":cycle", $cycle); // 保養頻率在做番上,這邊不 insert。
$stmt->bindParam(":contact_person", $contact_person); $stmt->bindParam(":contact_person", $contact_person);
$stmt->bindParam(":contact_address", $contact_address); $stmt->bindParam(":contact_address", $contact_address);
$stmt->bindParam(":contact_phone", $contact_phone); $stmt->bindParam(":contact_phone", $contact_phone);
$stmt->bindParam(":contact_email", $contact_email); $stmt->bindParam(":contact_email", $contact_email);
$stmt->bindParam(":elevators_number", $elevators_number); $stmt->bindParam(":elevators_number", $elevators_number);
$stmt->bindParam(":area", $area); $stmt->bindParam(":area", $area);
$stmt->bindParam(":address", $address); $stmt->bindParam(":address", $address);
$stmt->bindParam(":files_id", $files_id); $stmt->bindParam(":files_id", $files_id);
$stmt->bindParam(":bonus", $bonus); $stmt->bindParam(":bonus", $bonus);
$stmt->bindParam(":max_bonus", $max_bonus); $stmt->bindParam(":max_bonus", $max_bonus);
$stmt->bindParam(":created_at", $created_at); $stmt->bindParam(":created_at", $created_at);
$stmt->bindParam(":created_by", $user_id); $stmt->bindParam(":created_by", $user_id);
$stmt->bindParam(':payType', $payType); $stmt->bindParam(':payType', $payType);
$stmt->bindParam(':signing_date', $signing_date); $stmt->bindParam(':signing_date', $signing_date);
$stmt->execute(); $stmt->execute();
// T8insert($_POST, $facilityno); // T8insert($_POST, $facilityno);
$conn->commit(); $conn->commit();
header('Content-Type: application/json'); header('Content-Type: application/json');
$jsonData = json_encode($files); $jsonData = json_encode($files);
// Cmail->sendx; // Cmail->sendx;
// } catch (PDOException $e) { } catch (PDOException $e) {
// $conn->rollback(); $conn->rollback();
// http_response_code(404); http_response_code(404);
// echo $e->getMessage(); echo $e->getMessage();
// die('Error!:' . $e->getMessage()); die('Error!:' . $e->getMessage());
// } }
}; };
function T8insert($data, $facilityno, $depId, $connT8) function T8insert($data, $facilityno, $depId, $connT8)
@ -630,7 +638,10 @@ function T8insert($data, $facilityno, $depId, $connT8)
]; ];
// 幾年 // 幾年
// $SQuantityYear = $elevator['maintain_months'] / 12; // $SQuantityYear = $elevator['maintain_months'] / 12;
// 單台電梯契約報價
$price_of_month = intval($elevator['sold_price']); $price_of_month = intval($elevator['sold_price']);
print_r($price_of_month);
exit;
//分幾期 () => 總共保養月 / 分期月 //分幾期 () => 總共保養月 / 分期月
$SQuantitya = $elevator['maintain_months'] / $IncomeId[$payType]; $SQuantitya = $elevator['maintain_months'] / $IncomeId[$payType];
$SQuantity = $IncomeId[$payType]; $SQuantity = $IncomeId[$payType];
@ -710,14 +721,17 @@ function T8insert($data, $facilityno, $depId, $connT8)
$API_body[] = $salIncomeApplyMaster; $API_body[] = $salIncomeApplyMaster;
$API_body[] = $salIncomeApplyDetail; $API_body[] = $salIncomeApplyDetail;
// 呼叫 API // 呼叫 API
// echo '<pre>'; echo '<pre>';
// print_r(json_encode($API_body)); print_r(json_encode($API_body));
// echo '</pre>'; echo '</pre>';
// exit();
// $api_url = 'http://10.10.145.2:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; //正式區 // $api_url = 'http://10.10.145.2:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; //正式區
$api_url = "http://60.244.87.101:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData"; //測試區 $api_url = "http://60.244.87.101:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData"; //測試區
$result = T8salIncomeApply($API_body, $api_url); $result = T8salIncomeApply($API_body, $api_url);
// echo '<pre>';
// print_r($result);
// echo '</pre>';
// exit();
if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') { if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') {
http_response_code(404); http_response_code(404);
die('Error!:' . $result['ErrorMsg']); die('Error!:' . $result['ErrorMsg']);

83
wms/contract/api/test copy.json

@ -1,40 +1,43 @@
{ [
"apply_key": "MB24010007", {
"register_code": "036B017432", "apply_key": "11111111",
"elevator_brand": "1", "register_code": "B32510261185",
"elevator_kind": "A", "elevator_brand": "1",
"spec": "MAE100", "elevator_kind": "E",
"weight": 550, "spec": "MAH100",
"speed": 60, "weight": "450",
"stop": 12, "speed": "45.00",
"floors": 12, "stop": "3",
"persons": 8, "floors": "3",
"elevator_num": 0, "persons": "6",
"useful_years": 83, "elevator_num": "0",
"last_check_date": 1121109, "useful_years": "106",
"speed_governors_check_expense": 0, "last_check_date": "1",
"maintain_times": 1, "speed_governors_check_expense": "0",
"is_m1_bundle": "N", "maintain_times": "1",
"maintainance": "A", "is_m1_bundle": "N",
"maintain_months": 12, "maintainance": "B",
"maintain_period": 1, "maintain_months": "12",
"stand_price": 3140, "maintain_period": "1",
"contract_price": 1666.67, "stand_price": "1250.00",
"sold_price": 1667, "contract_price": "1250.00",
"commission_expense": null, "sold_price": 1250,
"management_expense": null, "commission_expense": null,
"annual_survey_expense": 0, "management_expense": null,
"service_expense": 8, "annual_survey_expense": "0.00",
"cmstatus": "Y", "service_expense": 0,
"updated_at": null, "cmstatus": "Y",
"creater": null, "updated_at": null,
"created_at": "2024-01-10 11:16:26", "creater": null,
"discount": 53, "created_at": "2024-02-26 15:24:23",
"opendoor": "2S", "discount": 100,
"latitude": "112", "latitude": "112",
"longitude": "11", "longitude": "11",
"takecertificatedate": "112", "takecertificatedate": "112",
"useful_date": "113-01-01", "opendoor": "2PCO",
"bonus_verson": "2.0", "useful_date": "113-01-01",
"manager": "M0137" "bonus_verson": "2.0",
} "manager": "M0029",
"regular_contract_manger_id": "M0054"
}
]

17
wms/contract/api/testT8API.php

@ -1,17 +0,0 @@
<?php
include_once("../conn.php");
$sql = "SELECT * FROM salIncomeApplyDetail WHERE BillNo ='B24010032'";
$stmt = $connT8->prepare($sql);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$aaa = intval($result['OAmountWithTax']) - 24;
$sql = "UPDATE salIncomeApplyDetail SET OAmountWithTax = $aaa WHERE BillNo = 'B24010032' AND RowCode = '1'";
$stmt = $connT8->prepare($sql);
$stmt->execute();
echo "<pre>";
print_r($result['OAmountWithTax']);
echo "</pre>";

10
wms/contract/api/testocde.php

@ -0,0 +1,10 @@
<?php
include_once("../conn.php");
$sql = "SELECT * FROM pricereview_pay WHERE mid = '441'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$pay_kind = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "<pre>";
print_r($pay_kind);
echo "</pre>";

20
wms/contract/contract-input.php

@ -214,13 +214,23 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<input type="text" x-model="data.address" /> <input type="text" x-model="data.address" />
<p class="alerttext" x-show="data.address==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p> <p class="alerttext" x-show="data.address==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p>
</td> </td>
<td style="vertical-align: middle">保養員</td>
<td style="vertical-align: middle">保養經理</td>
<td> <td>
<select class="ui search dropdown" name="repairer_name" x-model="data.mworker"> <select class="ui search dropdown" name="repairer_name" x-model="data.maintance_manager">
<option value="">選擇保養員</option> <option value="">選擇保養經理</option>
<?php foreach ($workers as $worker) { ?> <option value="M0090">M0090--顏慶豪(北北基)</option>
<option value="M0223">M0223--鄭登元(桃竹)</option>
<option value="M0161">M0161--鄭永典(中區)</option>
<option value="M0077">M0077--鍾玉龍(南區)</option>
<!-- <?php foreach ($workers as $worker) {
// 北北基 : M0090
// 保養組長 桃竹 : M0223
// 中部 : M0161
// 南部 : M0077
?>
<option value="<?php echo $worker['accountid']; ?>"><?php echo $worker['name'] ?></option> <option value="<?php echo $worker['accountid']; ?>"><?php echo $worker['name'] ?></option>
<?php } ?> <?php } ?> -->
</select> </select>
<!-- <p class="alerttext" x-show="data.mworker==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p> --> <!-- <p class="alerttext" x-show="data.mworker==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p> -->
</td> </td>

9
wms/contract/js/alpine.js

@ -1012,7 +1012,7 @@ const contractInput = () => {
}, },
cities: [], cities: [],
data: { data: {
contractno: 'B24010030', contractno: '',
total_price: '', //合約總價 total_price: '', //合約總價
vat: '', //統一編號 vat: '', //統一編號
mtype: 'A', //維修型態 mtype: 'A', //維修型態
@ -1038,7 +1038,8 @@ const contractInput = () => {
payType: '', //付款方式 payType: '', //付款方式
contract_type: 'new', contract_type: 'new',
signing_date: '', signing_date: '',
token: token token: token,
maintance_manager: ''
// bonus_verson: 2.1, // bonus_verson: 2.1,
// manager: '', // manager: '',
// regular_contract_manger_id: '', // regular_contract_manger_id: '',
@ -1138,7 +1139,7 @@ const contractInput = () => {
if (!this.customize) { if (!this.customize) {
this.data.elevators = res.data.elevators; this.data.elevators = res.data.elevators;
for (let i = 0; i < res.data.elevators.length; i++) { for (let i = 0; i < res.data.elevators.length; i++) {
// 合約總價格。 // 合約總價格 (月)
this.data.total_price = Math.round(Number(res.data.elevators[i].sold_price) + Number(this.data.total_price)); this.data.total_price = Math.round(Number(res.data.elevators[i].sold_price) + Number(this.data.total_price));
// 服務費 (以單筆合約記,但計算獎金須傳入單月服務費) // 服務費 (以單筆合約記,但計算獎金須傳入單月服務費)
@ -1148,6 +1149,7 @@ const contractInput = () => {
this.data.elevators[i].sold_price = Math.round(res.data.elevators[i].sold_price); this.data.elevators[i].sold_price = Math.round(res.data.elevators[i].sold_price);
} }
console.log(this.data.elevators); console.log(this.data.elevators);
// 合約總價
this.data.total_price = Number(res.data.elevators[0].maintain_months) * this.data.total_price; this.data.total_price = Number(res.data.elevators[0].maintain_months) * this.data.total_price;
this.data.salesman = res.data.salesman this.data.salesman = res.data.salesman
this.data.contract_begin_date = res.data.contract_begin_date this.data.contract_begin_date = res.data.contract_begin_date
@ -1245,6 +1247,7 @@ const contractInput = () => {
form.append('payType', this.data.payType); form.append('payType', this.data.payType);
form.append('contract_type', this.data.contract_type); form.append('contract_type', this.data.contract_type);
form.append('signing_date', this.data.signing_date); form.append('signing_date', this.data.signing_date);
form.append('maintance_manager', this.data.maintance_manager);
// 如果有附件檔案,可以逐一加入 // 如果有附件檔案,可以逐一加入
for (var i = 0; i < this.data.files.length; i++) { for (var i = 0; i < this.data.files.length; i++) {

18
wms/schedule-edit.php

@ -149,7 +149,7 @@ foreach ($data as $data) :
<div> <div>
<br> <br>
<button type="submit" name="update">確認</button> <button type="submit" name="update">確認</button>
<button onclick="updateRepaire(<?= $data['contractno'] ?>,<?= $data['facilityno'] ?>)" style="text-align: right;">更新此作番保養人員</button> <!-- <button onclick="updateRepaire(<?= $data['contractno'] ?>,<?= $data['facilityno'] ?>)" style="text-align: right;">更新此作番保養人員</button> -->
</div> </div>
<input type="hidden" name="token" value="<?php echo $token; ?>"> <input type="hidden" name="token" value="<?php echo $token; ?>">
</form> </form>
@ -160,22 +160,10 @@ foreach ($data as $data) :
endforeach; endforeach;
include "footer.php"; include "footer.php";
include_once "./bonus/api/postSchedule.php" // include_once "./bonus/api/postSchedule.php"
?> ?>
<script src="../contract-repair/js/axios/axios.min.js"></script> <script src="../contract-repair/js/axios/axios.min.js"></script>
<script> <script>
function updateRepaire(contractno, facilityno) {
const form = new FormData();
form.append("contractno", contractno);
form.append("facilityno", facilityno);
axios.post('./bonus/api/postSchedule.php', form).then((res) => {
if (res.data == 'Success') {
alert('更新成功');
location.reload();
}
}).catch((err) => {
})
}
</script> </script>

22
wms/schedule-index.php

@ -36,10 +36,14 @@ if (!empty($sql_cmd2)) {
else $sql_cmd .= $sql_cmd2; else $sql_cmd .= $sql_cmd2;
$page_close = 1; // 不分頁 $page_close = 1; // 不分頁
} }
$clause = "WHERE id IN (
SELECT MIN(id)
FROM schedule
GROUP BY contractno
)";
//$sql = "SELECT * FROM schedule $sql_cmd ORDER BY id"; //$sql = "SELECT * FROM schedule $sql_cmd ORDER BY id";
$sql = "SELECT * FROM schedule $sql_cmd ORDER BY id desc"; $sql = "SELECT DISTINCT contractno, schedule.* FROM schedule $sql_cmd ORDER BY CASE WHEN repairerid IS NULL THEN 0 ELSE 1 END, id";
$sql = "SELECT * FROM schedule $sql_cmd ORDER BY id desc"; // $sql = "SELECT * FROM schedule $sql_cmd ORDER BY id desc";
if (!$page_close) $sql .= " limit $page_from, $page_each"; if (!$page_close) $sql .= " limit $page_from, $page_each";
// echo $sql; // echo $sql;
@ -192,7 +196,8 @@ if ($data) :
<th>建檔時間</th> <th>建檔時間</th>
<?php if ($user_auth & 2) { ?> <?php if ($user_auth & 2) { ?>
<th>修改</th> <th>修改</th>
<th>刪除</th> <!-- <th>刪除</th> -->
<th>安排保養計畫人員</th>
<?php } ?> <?php } ?>
</tr> </tr>
</thead> </thead>
@ -250,11 +255,16 @@ if ($data) :
</p> </p>
</td> </td>
<td> <td>
<p> <!-- <p>
<a href="schedule-delete.php?id=<?php echo $data['id']; ?>&<?php echo $token_link; ?>" class="btn btn-info btn-sm" onClick="return confirm('Are you sure you want to delete?')"> <a href="schedule-delete.php?id=<?php echo $data['id']; ?>&<?php echo $token_link; ?>" class="btn btn-info btn-sm" onClick="return confirm('Are you sure you want to delete?')">
<span class="glyphicon glyphicon-remove"></span> <span class="glyphicon glyphicon-remove"></span>
</a> </a>
</p> </p> -->
<?php if (empty($data['repairerid'])) { ?>
<p>
<a href="schedule-setting-repaire.php?id=<?= $data['id'] ?>&<?php echo $token_link; ?>"" class=" btn btn-info btn-sm">安排</a>
</p>
<?php } ?>
</td> </td>
<?php } ?> <?php } ?>
</tr> </tr>

66
wms/schedule-setting-repaire-update.php

@ -0,0 +1,66 @@
<?php
include "header.php";
include_once "./contract/conn.php";
if (isset($_POST['update'])) {
function user_input($data)
{
$data1 = trim($data);
$data2 = stripslashes($data1);
$data3 = htmlspecialchars($data2);
return $data3;
}
$id = $_POST['id'];
$sql = "SELECT * FROM schedule WHERE id = '$id'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$checkRepaireIsit = $stmt->fetch(PDO::FETCH_ASSOC);
if (!empty($checkRepaireIsit)) {
echo "<script type ='text/JavaScript'>";
echo "alert('此單號已經有保養人員');";
echo "location.href='schedule-index.php?function_name=schedule&" . $token_link . "';";
echo "</script>";
}
$contractno = user_input($_POST["contractno"]);
$facilityno = user_input($_POST["facilityno"]);
$repairerid = user_input($_POST["repairerid"]);
$creater = user_input($_POST["creater"]);
$create_at = date('Y/m/d H:i:s');
$sql = "SELECT name FROM account WHERE accountid = '$repairerid'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$account = $stmt->fetch(PDO::FETCH_ASSOC);
$repairername = $account['name'];
$db_query = "UPDATE schedule set
repairerid = '$repairerid',
repairername = '$repairername',
updater = '$creater',
update_at = '$create_at' WHERE contractno='$contractno' AND facilityno='$facilityno'";
$stmt = $conn->prepare($db_query);
$stmt->execute();
$affected = $stmt->rowCount();
if ($affected > 0) {
echo "<script type ='text/JavaScript'>";
echo "alert('update成功');";
echo "location.href='schedule-index.php?function_name=schedule&" . $token_link . "';";
echo "</script>";
} elseif ($affected == 0) {
echo "<script type ='text/JavaScript'>";
echo "alert('無新增資料');";
echo "location.href='schedule-index.php?function_name=schedule&" . $token_link . "';";
echo "</script>";
} else {
echo "{$db_query} 語法執行失敗,錯誤訊息SSS: ";
}
}

192
wms/schedule-setting-repaire.php

@ -0,0 +1,192 @@
<?php
include "header.php";
include_once "./contract/conn.php";
$id = isset($_GET['id']) ? $_GET['id'] : die('ERROR: Record ID not found.');
$data = array();
// sql語法存在變數中
$db_query = "SELECT * FROM schedule WHERE id=$id";
// 用mysqli_query方法執行(sql語法)將結果存在變數中
$data = mysqli_query($link, $db_query);
$sql = "SELECT * FROM account WHERE accounttype = 'B' ";
$stmt = $conn->prepare($sql);
$stmt->execute();
$repaire = $stmt->fetchAll(PDO::FETCH_ASSOC);
/*
include "inc/record_update.php";
try {
// 設置一個空陣列來放資料
$data = array();
// sql語法存在變數中
$db_query = "SELECT * FROM expert WHERE id=$id";
// 用mysqli_query方法執行(sql語法)將結果存在變數中
$data = mysqli_query($link,$db_query);
}catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
*/
foreach ($data as $data) :
?>
<div class="container">
<form class="form-inline" method="post" action="schedule-setting-repaire-update.php" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div>
<label for="contractno">合約號</label>
<input type="text" name="contractno" id="contractno" value="<?php echo $data['contractno']; ?>" disabled>
</div>
<div>
<label for="facilityno">作番號</label>
<input type="text" name="facilityno" id="facilityno" value="<?php echo $data['facilityno']; ?>" disabled>
</div>
<!--
<div>
<label for="combono">保養套餐編號</label>
<input type="text" name="combono" id="combono" value="<?php echo $data['combono']; ?>">
</div> -->
<div>
<label for="repairerid">保養人員工號</label>
<select name="repairerid" id="repairerid">
<option value=""></option>
<?php
foreach ($repaire as $repaire) {
?>
<option value="<?= $repaire['accountid'] ?>"><?php echo $repaire['accountid'] . '---' . $repaire['name'] ?></option>
<?php
}
?>
</select>
</div>
<!--
<div>
<label for="repairername">保養人員姓名</label>
<input type="text" name="repairername" id="repairername" value="<?php echo $data['repairername']; ?>">
</div> -->
<!--
<div>
<label for="duedate">應保養日期</label>
<input type="text" name="duedate" id="duedate" value="<?php echo $data['duedate']; ?>">
</div>
<div>
<label for="actualdate">實際保養日期</label>
<input type="text" name="actualdate" id="actualdate" data-date-format="yyyy-mm-dd" value="<?php echo $data['actualdate']; ?>">
</div>
<div>
<label for="item">保養項目編號</label>
<input type="text" name="item" id="item" value="<?php echo $data['item']; ?>">
</div>
<div>
<label for="item_detail">保養項目內容</label>
<input type="text" name="item_detail" id="item_detail" value="<?php echo $data['item_detail']; ?>">
</div> -->
<!-- <div>
<label for="result">保養結果</label>
<input type="text" name="result" id="result" value="<?php echo $data['result']; ?>">
</div> -->
<!--
<div>
<label for="evidences">上傳照片</label>
<input type="text" name="evidences" id="evidences" >
</div>
-->
<!-- <div>
<label for="descriptons">說明</label>
<input type="text" name="descriptons" id="descriptons" value="<?php echo $data['descriptons']; ?>">
</div>
<div>
<label for="customer_login_id">客戶評價登入帳號</label>
<input type="text" name="customer_login_id" id="customer_login_id" value="<?php echo $data['customer_login_id']; ?>">
</div>
<div>
<label for="customer_login_name">客戶姓名</label>
<input type="text" name="customer_login_name" id="customer_login_name" value="<?php echo $data['customer_login_name']; ?>">
</div>
<div>
<label for="stars">保養品質/評價等級(1-5星)</label>
<input type="text" name="stars" id="stars" onkeyup="if(value<0)value=0;if(value>5)value=5;value=value.replace(/^\D*(\d*(?:\.\d)?).*$/g, '$1')" value="<?php echo $data['stars_c1']; ?>">
</div>
<div>
<label for="stars2">服務態度/評價等級(1-5星)</label>
<input type="text" name="stars2" id="stars2" onkeyup="if(value<0)value=0;if(value>5)value=5;value=value.replace(/^\D*(\d*(?:\.\d)?).*$/g, '$1')" value="<?php echo $data['stars_c2']; ?>">
</div>
<div>
<label for="details">內容</label>
<input type="text" name="details" id="details" value="<?php echo $data['details']; ?>">
</div> -->
<!--
<div>
<label for="customer_signature">簽名檔</label>
<input type="text" name="customer_signature" id="customer_signature" value="<?php echo $data['customer_signature']; ?>">
</div>
-->
<div>
<label for="creater">建檔人</label>
<input type="text" name="creater" id="creater" value="<?php echo $data['creater']; ?>" readonly>
</div>
<div>
<br>
<button type="submit" name="update">確認</button>
<!-- <button onclick="updateRepaire(<?= $data['contractno'] ?>,<?= $data['facilityno'] ?>,<?= $user_id ?>)" style="text-align: right;">更新此作番保養人員</button> -->
</div>
<input type="hidden" name="token" value="<?php echo $token; ?>">
<input type="hidden" name="reqaire" id="reqaire" value="">
</form>
</div>
<?php
endforeach;
include "footer.php";
// include_once "./bonus/api/postSchedule.php"
?>
<script src="./contract-repair/js/axios/axios.min.js"></script>
<script>
document.getElementById('repairerid').onchange = function() {
var repaireridValue = this.value;
// 根據選擇的值做相應的處理
document.getElementById('reqaire').value = repaireridValue;
console.log(repaireridValue);
};
// function updateRepaire(contractno, facilityno, user_id) {
// const form = new FormData();
// form.append("contractno", contractno);
// form.append("facilityno", facilityno);
// form.append("user_id", user_id)
// axios.post('./bonus/api/postSchedule.php', form).then((res) => {
// if (res.data == 'Success') {
// alert('更新成功');
// location.reload();
// }
// }).catch((err) => {
// })
// }
</script>
Loading…
Cancel
Save