diff --git a/.gitignore b/.gitignore
index a344fd2a..44e45c2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,4 @@ wms/gary2.php
wms/chinese.php
phpinfo.php
wms/account_receivable_sql_file.sql
+wms/account_receivable_maintainance_sql.sql
diff --git a/wms/T8_Authorization_from_bpm.php b/wms/T8_Authorization_from_bpm.php
index 7d2ca5a8..0c81c268 100644
--- a/wms/T8_Authorization_from_bpm.php
+++ b/wms/T8_Authorization_from_bpm.php
@@ -4,9 +4,8 @@
// $user_password = "M012290493119";
// echo $validation = get_Auth($user_id, $user_password);
-
-// function get_Auth($user_id = "M0000", $user_password = "M012290493119")
-function get_Auth($user_id = "ADMIN", $user_password = "chi")
+// function get_Auth($user_id = "ADMIN", $user_password = "chi")
+function get_Auth($user_id = "M0000", $user_password = "M012290493119")
{
$currentTime = time();
$twoMinutesLater = $currentTime - (2 * 60);
@@ -14,14 +13,14 @@ function get_Auth($user_id = "ADMIN", $user_password = "chi")
// $now = gmdate("YmdHis");
$now = gmdate("YmdHis", strtotime("-2 minutes"));
$data = "$user_id." . $now;
- // $sign = hash_hmac('SHA256', $data, 'A21181F1EE4966D3', false);
- $sign = hash_hmac('SHA256', $data, 'A733DAD19527399E', false);
+ $sign = hash_hmac('SHA256', $data, '91EB2CB12C3F8211', false);
+ // $sign = hash_hmac('SHA256', $data, 'A733DAD19527399E', false); 普來特富
// echo $sign;
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
- // $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; -----
- $apiurl = 'http://101.132.66.206:880/twWebAPI/GetAuth';
+ $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
+ // $apiurl = 'http://101.132.66.206:880/twWebAPI/GetAuth'; 普來特富
// $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth';
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
@@ -31,7 +30,7 @@ function get_Auth($user_id = "ADMIN", $user_password = "chi")
"Pwd: $user_password",
"TimestampUTC: $now",
"Sign: $sign",
- "GroupId:ceshi"
+ "GroupId:MASADA"
];
$ch = curl_init();
diff --git a/wms/account-receivable-maintainance-index.php b/wms/account-receivable-maintainance-index.php
new file mode 100644
index 00000000..5295d065
--- /dev/null
+++ b/wms/account-receivable-maintainance-index.php
@@ -0,0 +1,523 @@
+ 0) {
+ $column_str = "('$user_id'" . ",'";
+ $column_str .= implode("','", $follower);
+ $column_str .= "')";
+ $sql .= " OR siam.PersonId IN $column_str OR cd.LeaderId = '$user_id')";
+ } else {
+ $sql .= " OR cd.LeaderId = '$user_id')";
+ };
+}
+if (!is_null($start_date)) {
+ $start_date = (int)date('Ymd', strtotime($start_date));
+ $sql .= " AND siam.CU_ContractStart >= $start_date ";
+}
+if (!is_null($end_date)) {
+ $end_date = (int)date('Ymd', strtotime($end_date));
+ $sql .= " AND siam.CU_ContractStart <= $end_date ";
+}
+if (!is_null($start_SignDate)) {
+ $start_SignDate = (int)date('Ymd', strtotime($start_SignDate));
+ $sql .= " AND siam.BillDate >= $start_SignDate ";
+}
+if (!is_null($end_SignDate)) {
+ $end_SignDate = (int)date('Ymd', strtotime($end_SignDate));
+ $sql .= " AND siam.BillDate <= $end_SignDate ";
+}
+$sql .= " GROUP BY
+siam.PersonId,
+cp.PersonName,
+cd.DeptId,
+cd.DeptName,
+cd.LeaderId,
+lcp.PersonName,
+siam.BizPartnerId,
+cbp.BizPartnerName,
+siamd.RowCode,
+siam.BillNo,
+siamd.ProjectId,
+siamd.CU_EstPayDate,
+siamd.UnTransCheckBLAmtWTax,
+siamd.HadTransCheckBLAmtWTax,
+siamd.OAmountWithTax,
+siamd.CU_MaterialId,
+acb_tmp.BillNo2,
+acb_tmp.RowCode2,
+acb_tmp.checkOAmount,
+asim.BillNo,
+asim.InvoiceName,
+asim.OAmountWithTax,
+asi.InvoiceNo,
+asi.InvoiceTime,
+writeoff.BillDate
+ORDER BY
+siam.PersonId ASC,
+siam.BillNo ASC,
+siamd.RowCode ASC";
+
+$query_T8 = $conn->query($sql);
+$rows = $query_T8->fetchAll(PDO::FETCH_ASSOC);
+$today = strtotime(date('Ymt'));
+$table = "";
+for ($i = 0; $i < count($rows); $i++) {
+ $row = $rows[$i];
+ $tmpname = $row['ProjectId'] . $row['RowCode'];
+ $data[$tmpname] = $row;
+ $data[$tmpname]['CU_EstPayDate'] = date('Y-m-d', strtotime($row['CU_EstPayDate']));
+ $data[$tmpname]['havetopay'] = strtotime($row['CU_EstPayDate']) > $today ? '--' : 'V';
+ $datahavetopay = $row['CU_EstPayDate'] > $today ? 0 : 1;
+ $data[$tmpname]['collecttime'] = collect_month(strtotime($row['CU_EstPayDate']));
+ $invoicedate = is_null($row['InvoiceTime']) ? null : date('Y-m-d', strtotime($row['InvoiceTime']));
+ $tableinvoice_state = is_null($invoicedate) ? 0 : 1;
+ $contract_no = $row['ProjectId'];
+ $facility_no = $row['CU_MaterialId'];
+ $RowCode = $row['RowCode'];
+ $BillNo = $row['BillNo'];
+ $receivable_date = date('Y-m-d', strtotime($row['CU_EstPayDate']));
+ $budget = $row['OAmountWithTax'];
+ $invoiceNo = $row['InvoiceNo'];
+ $invoice_budget = is_null($row['InvoiceOAmount']) ? 0 : $row['InvoiceOAmount'];
+ $table_writeoff_date = is_null($row['WriteOffDate']) ? null : date('Y-m-d', strtotime($row['WriteOffDate']));
+ $table_writeoff_amount = is_null($row['TotalCurrStandOffOAmount']) ? 0 : $row['TotalCurrStandOffOAmount'];
+ $table1 = "INSERT INTO account_receivable_maintainance(
+ `contract_no`,
+ `facility_no`,
+ `RowCode`,
+ `BillNo`,
+ `receivable_date`,
+ `budget`,
+ `receivable`,
+ `invoice_state`,
+ `invoice_budget`,
+ `received_budget`
+ ";
+ $table2 = ") VALUES(
+ '$contract_no',
+ '$facility_no',
+ '$RowCode',
+ '$BillNo',
+ '$receivable_date',
+ $budget,
+ $datahavetopay,
+ $tableinvoice_state,
+ $invoice_budget,
+ $table_writeoff_amount
+ ";
+ $table1 .= is_null($invoicedate) ? "" : ",`invoice_date`";
+ $table2 .= is_null($invoicedate) ? "" : ",'$invoicedate'";
+ $table1 .= is_null($table_writeoff_date) ? "" : ",`received_date`";
+ $table2 .= is_null($table_writeoff_date) ? "" : ",'$table_writeoff_date'";
+ $table1 .= is_null($invoiceNo) ? "" : ",`invoice_no`";
+ $table2 .= is_null($invoiceNo) ? "" : ",'$invoiceNo'";
+ $table .= $table1 . $table2 . "); \n";
+}
+// $file_path = 'account_receivable_maintainance_sql.sql';
+// if (file_put_contents($file_path, $table) !== false) {
+// echo "SQL文件已成功生成:{$file_path}";
+// } else {
+// echo "生成SQL文件时出现错误。";
+// }
+
+// foreach ($data as $key => $row) {
+// echo $key . "
";
+// print_r($row);
+// echo "
------------
";
+// }
+// exit();
+?>
+
+
+
合約號 | +序號 | +作番號 | +部門 | +主管 | +契約員 | +客戶名稱 | + +應收日期 | +是否應收 | +應收金額 | + +已收金額 | +催收金額 | +催收次數 | +
---|---|---|---|---|---|---|---|---|---|---|---|---|
= $row['ProjectId']; ?> | += $row['RowCode']; ?> | += $row['CU_MaterialId']; ?> | += $row['DeptId'] . " " . $row['DeptName']; ?> |
+ = $row['LeaderId'] . " " . $row['LeaderName']; ?> |
+ = $row['PersonId'] . " " . $row['PersonName']; ?> |
+ = $row['BizPartnerId'] . " " . $row['BizPartnerName']; ?> |
+
+ = $row['CU_EstPayDate']; ?> | += $row['havetopay']; ?> | += number_format(round($row['OAmountWithTax'])); ?> | + += is_null($row['TotalCurrStandOffOAmount']) ? 0 : number_format(round($row['TotalCurrStandOffOAmount'])); ?> | += ($row['havetopay'] == "V")? (number_format(round($row['OAmountWithTax'] - $row['TotalCurrStandOffOAmount']))) :0; ?> | += (($row['havetopay'] == "V") && ($row['OAmountWithTax'] - $row['TotalCurrStandOffOAmount'] >1))? $row['collecttime']:0; ?> | +
"; + // print_r($results); + // echo ""; + foreach ($results as $result) { + $contract_no = $result['contract_no']; + $a = isPay($contract_no, $connT8); + + if ($a == '1') { + try { + $sql = "UPDATE bonus SET T8api_status = 2 WHERE contract_no = :contract_no"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(":contract_no", $contract_no); + $stmt->execute(); + header("HTTP/1.1 200 success!"); + echo 'Success'; + } catch (PDOException $e) { + echo $e->getMessage(); + die('Error!:' . $e->getMessage()); + } + } + } +} + +function isPay($contract_no, $connT8) +{ + // echo $contract_no; + $sql = "SELECT + a.BillNo, + b.OTaxAmt as amount, + a.CU_EstPayDate as createDate, + b.PersonId as personId, + c.BillNo as CBno, + c.CU_MaterialId as facility +FROM salIncomeApplyDetail as a +LEFT JOIN salIncomeApplyMaster as b ON a.BillNo = b.BillNo +LEFT JOIN ( + SELECT aMaster.BillNo,aMaster.BizPartnerId,aDetail.CU_MaterialId FROM arCheckBill as aMaster + LEFT JOIN arCheckBillDetail as aDetail ON aMaster.BizPartnerId = aDetail.FromBillNo + WHERE aMaster.BizPartnerId = '$contract_no' AND aMaster.TypeId = 'RVS' + ) AS c ON a.BillNo = c.BizPartnerId +WHERE a.BillNo = '$contract_no' +AND a.RowNo = '1' +"; + $stmt = $connT8->prepare($sql); + $stmt->execute(); + $data = $stmt->fetch(PDO::FETCH_ASSOC); + // $data['amount'] = intval($data['amount']); + if (!empty($data['CBno']) && $data['CBno'] != '') { + $checkBillNo = $data['CBno']; + + $sql = "SELECT +c.BillDate AS CheckBillDate +FROM arWriteOffBill AS a +LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo +LEFT JOIN +(SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail +LEFT JOIN + (SELECT + arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo + FROM arCheckBill + LEFT JOIN arCheckBillInvInfo + ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1 +ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c +ON a.BillNo=c.BillNo +WHERE c.checkBillNo = '$checkBillNo' +"; + + $stmt = $connT8->prepare($sql); + $stmt->execute(); + + return '1'; + } else { + return '2'; + } +} diff --git a/wms/bonus/bonus_person.php b/wms/bonus/bonus_person.php new file mode 100644 index 00000000..1b01b289 --- /dev/null +++ b/wms/bonus/bonus_person.php @@ -0,0 +1,146 @@ +='$select_date' AND pay_day_due <= '$select_date1' "; + } else { + $clause .= "AND pay_day_due >= '$now' AND pay_day_due <= '$oneMonthAgo' "; + } + + // $clause .= "AND pay_day_due >= '$now' AND pay_day_due <= '$oneMonthAgo' "; + $sql = "SELECT a.receiver,a.amount,b.name FROM bonus AS a +LEFT JOIN account AS b ON a.receiver = b.accountid +WHERE 1=1 AND contract_type = 3 $clause ORDER BY a.receiver ASC"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $person_arr = []; + $bonus_arr = []; + $count = 0; + + $a = 0; + $j = 0; +} + +for ($i = 0; $i < COUNT($results); $i++) { + $a++; + if ($i + 1 < COUNT($results)) { + if ($results[$i]['receiver'] != $results[$i + 1]['receiver']) { + $amount = 0; + if ($i != $j) { + for ($j; $j <= $i; $j++) { + $amount += $results[$j]['amount']; + } + $person_arr['person_id'] = $results[$i]['receiver']; + $person_arr['person'] = $results[$i]['name']; + $person_arr['bonus'] = $amount; + array_push($bonus_arr, $person_arr); + } else { + $amount += $results[$j]['amount']; + $person_arr['person_id'] = $results[$i]['receiver']; + $person_arr['person'] = $results[$i]['name']; + $person_arr['bonus'] = $amount; + array_push($bonus_arr, $person_arr); + } + + $j = $i + 1; + } + } else { + $amount = 0; + for ($j; $j <= $i; $j++) { + $amount += $results[$j]['amount']; + } + $amount += $results[$i]['amount']; + $person_arr['person_id'] = $results[$i]['receiver']; + $person_arr['bonus'] = $amount; + $person_arr['person'] = $results[$i]['name']; + array_push($bonus_arr, $person_arr); + } +} + +?> +
+ = !empty($years) ? $years : date('Y') ?>年= !empty($month) ? $month : $oneMonthAgo1 ?>月份、個人獎金計算+ |
+
工號 | +姓名 | +總獎金水庫(實發總價) | +
---|---|---|
+ | + | + |
+ (契約)獎金計算+ |
+
項次 | -合約類別 | 合約號 | +合約名稱 | 作番號 | 獎金類別 | 獎金版本 | @@ -178,8 +140,8 @@ function isPay($contract_no, $connT8) ?>|||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
= $data['id'] ?> | -= $contract_type[$data['contract_type']] ?> | = $data['contract_no'] ?> | += $data['customer'] ?> | = $data['facility_no'] ?> | = $bonus_type[$data['bonus_type']] ?> | = $data['bonus_verson'] ?> | @@ -323,13 +285,14 @@ function isPay($contract_no, $connT8) const datas = ; function issue(id, user_id, pay_day, amount) { - // console.log(id); + // consolelog(id); const form = new FormData(); form.append('id', id) form.append('user_id', user_id); form.append('pay_day', pay_day) form.append('amount', amount); form.append('postType', 'a'); + form.append('contract_type', 'maintainance'); axios.post('./api/postStatus.php', form).then((res) => { if (res.data == 'Success') { alert('更新成功'); @@ -357,6 +320,22 @@ function isPay($contract_no, $connT8) }); } } + + function isPay() { + const form = new FormData(); + form.append('user_id', '= $user_id ?>'); + form.append('postType', 'e'); + // if (confirm('是否發放全部獎金')) { + axios.post('./api/postStatus.php', form).then((res) => { + if (res.status == 200) { + alert('更新成功'); + // location.reload(); + } + }).catch((err) => { + + }); + // } + } // $(function() { // $("button[name=issuePay]").click(function() { // console.log(123); diff --git a/wms/bonus/bonus_detail.php b/wms/bonus/maintainance_bonus_detail.php similarity index 100% rename from wms/bonus/bonus_detail.php rename to wms/bonus/maintainance_bonus_detail.php diff --git a/wms/bonus/new_bonus.php b/wms/bonus/new_bonus.php new file mode 100644 index 00000000..c595e442 --- /dev/null +++ b/wms/bonus/new_bonus.php @@ -0,0 +1,400 @@ + '新梯', + '2' => '汰改', + '3' => '保養' +]; + +$bonus_type = [ + '1' => '契約人獎金', + '2' => '區經理獎金', + '3' => '專任契約經理獎金' +]; + +$bonus_status = [ + '1' => '未確認', + '2' => '應發已確認', + '3' => '應發未確認', + '4' => '暫不發放', + '5' => '人事審核確認' +]; +$clause = ''; +if ($user_id != 'M0225') { + $clause .= "AND receiver == '$user_id'"; +} +if (!empty($_GET['check'])) { + // 人事發放作業,應為一個月內 + if ($_GET['check'] == 4) { + $oneMonthAgo = date("Y-m-d", strtotime("$now +1 months")); + // $clause .= "AND pay_day_due >= '$now' AND pay_day_due <= '$oneMonthAgo' AND status IN (1,2,5)"; + $clause .= "AND a.status IN (1,2,5)"; + } else if ($_GET['check'] == 2) { + $clause .= "AND a.status = 1"; + } else if ($_GET['check'] == 3) { + $clause .= "AND a.status IN (2,5)"; + } +} + +$sql = "SELECT a.*,b.customer FROM bonus AS a +LEFT JOIN con_maintance_examine_apply AS b ON a.contract_no = b.vol_no +WHERE 1=1 $clause AND a.contract_type = 1 ORDER BY a.id DESC"; +$stmt = $conn->prepare($sql); +$stmt->execute(); +$datas = $stmt->fetchAll(PDO::FETCH_ASSOC); + + +$now = new DateTime(); +$oneMonthAgo = $now->modify('+1 month'); + + +$id = []; +foreach ($datas as $data) { + $id[] = $data['id']; +} +$id_str = implode(',', $id); + +// 查看 T8 是否有收款明細 +// require("./api/get.php"); +function isPay($contract_no, $connT8) +{ + // echo $contract_no; + $sql = "SELECT + a.BillNo, + b.OTaxAmt as amount, + a.CU_EstPayDate as createDate, + b.PersonId as personId, + c.BillNo as CBno, + c.CU_MaterialId as facility + FROM salIncomeApplyDetail as a + LEFT JOIN salIncomeApplyMaster as b ON a.BillNo = b.BillNo + LEFT JOIN ( + SELECT aMaster.BillNo,aMaster.BizPartnerId,aDetail.CU_MaterialId FROM arCheckBill as aMaster + LEFT JOIN arCheckBillDetail as aDetail ON aMaster.BizPartnerId = aDetail.FromBillNo + WHERE aMaster.BizPartnerId = '$contract_no' AND aMaster.TypeId = 'RVS' + ) AS c ON a.BillNo = c.BizPartnerId + WHERE a.BillNo = '$contract_no' + AND a.RowNo = '1' + "; + $stmt = $connT8->prepare($sql); + $stmt->execute(); + $data = $stmt->fetch(PDO::FETCH_ASSOC); + // $data['amount'] = intval($data['amount']); + if (!empty($data['CBno']) && $data['CBno'] != '') { + $checkBillNo = $data['CBno']; + + $sql = "SELECT + c.BillDate AS CheckBillDate + FROM arWriteOffBill AS a + LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo + LEFT JOIN + (SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail + LEFT JOIN + (SELECT + arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo + FROM arCheckBill + LEFT JOIN arCheckBillInvInfo + ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1 + ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c + ON a.BillNo=c.BillNo + WHERE c.checkBillNo = '$checkBillNo' + "; + + $stmt = $connT8->prepare($sql); + $stmt->execute(); + + return '1'; + } else { + return '2'; + } +} +?> + + + + + + + + +
+ (契約)獎金計算+ |
+
項次 | +合約號 | +合約名稱 | +作番號 | +獎金類別 | +獎金版本 | +作番金額(月) | +牌價 | +服務費 | +應發人員 | +應發獎金水庫 | +實發金額 | +狀態 | + +實際發放時間 | +發放 / 詳情 | + + + + +||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
= $data['id'] ?> | += $data['contract_no'] ?> | += $data['customer'] ?> | += $data['facility_no'] ?> | ++ | = $data['bonus_verson'] ?> | += $fee_per_st ?> | += $total ?> | += $commission_fee ?> | += $data['receiver'] ?> | += $data['amount'] ?> | += $data['bonus_actual'] ?> | ++ = $bonus_status[$data['status']] ?> + + | + +-- | ++ + + + 查看詳情 + + | + + + += $data['pay_day'] ?> | +查看詳情 | + + + + + +
'; + // print_r($bonus_array); + // echo ''; + // exit(); $result = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( - $examination_array[$i][0], - $examination_array[$i][1], - $examination_array[$i][2], - $examination_array[$i][3], - $examination_array[$i][4], - $examination_array[$i][5], - $examination_array[$i][6], - $examination_array[$i][7], - $examination_array[$i][8], - $examination_array[$i][9] + $ver, + $contract_type, + $payment_period, + $payment_period_amount, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id ); + + $discount = (($fee_per_st - $commission_fee) / $elevator_list_price); + #新簽約、月繳、牌價3000、簽約價3000元、服務費600元(折扣率0.8) + $contract_type = [ + 'new' => '新簽約', + 'free_to_charge' => '免保轉有費', + 'renew_priceissue' => '續簽約(原價或僅契約金額異動)', + 'longcontract_m1_free_charge' => '五年長約' + + ]; + // 付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) + $pay_kind = [ + 'monthly' => '月繳', + 'bimonthly' => '雙月繳', + 'quarterly' => '季繳', + 'semiannually' => '半年繳', + 'annually' => '年繳' + ]; + + // + $bonus_type = [ + '1' => '契約員獎金', + '2' => '區經理獎金', + '3' => '契約經理獎金' + ]; echo "獎金版本:" . $result["ver"] . "
'; + // print_r(json_encode($data, JSON_UNESCAPED_UNICODE)); + // echo ''; $header = [ "CHI_Authorization :" . $validation, "GroupId:TEST" @@ -19,7 +19,7 @@ function T8API($data) 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)); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); $response = curl_exec($ch); if ($response === false) { diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php index 253e8d54..e2aedd43 100644 --- a/wms/contract/api/getContractData.php +++ b/wms/contract/api/getContractData.php @@ -1,5 +1,6 @@ prepare($sql); $stmt->bindParam(':mid', $mid); $stmt->execute(); - $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + $elevators_results = $stmt->fetchAll(PDO::FETCH_ASSOC); $elevators_detail_arr = []; - foreach ($results as $keys => $result) { + $contract_elevator_qty = 0; + $sql = "SELECT * FROM pricereview_pay WHERE mid = :mid"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':mid', $mid); + $stmt->execute(); + + $pay_amount = $stmt->fetchAll(PDO::FETCH_ASSOC); + $pay_arr = [ + 'equipment_total' => 0, //設備款 + 'install_total' => 0, //安裝款 + 'elevotor_pay_detail' => [] + ]; + $elevotor_pay_detail = []; + foreach ($pay_amount as $i => $pay) { + if ($pay['pay_kind'] <= 4) { + // 設備款總價 + $pay_arr['equipment_total'] += $pay['pay_amount']; + if ($pay['pay_scale'] > 0) { + $elevotor_pay_detail = [ + 'kind' => $pay['pay_kind'], + 'pay_scale' => $pay['pay_scale'], + 'pay_period' => $pay['pay_period'], + 'amount' => $pay['pay_amount'] + ]; + // $elevotor_pay_detail['pay_scale'] = $pay['pay_scale']; + // $pay_arr['elevotor_pay_detail']['kind'] = $pay['pay_kind']; + // $pay_arr['elevotor_pay_detail']['pay_scale'] = $pay['pay_scale']; + // $pay_arr['elevotor_pay_detail']['pay_period'] = $pay['pay_period']; + // $pay_arr['elevotor_pay_detail']['amount'] = $pay['pay_amount']; + array_push($pay_arr['elevotor_pay_detail'], $elevotor_pay_detail); + } + } else { + $pay_arr['install_total'] += $pay['pay_amount']; + if ($pay['pay_scale'] > 0) { + $a = $pay['pay_kind']; + $elevotor_pay_detail = [ + 'kind' => "$a", + 'pay_scale' => $pay['pay_scale'], + 'pay_period' => $pay['pay_period'], + 'amount' => $pay['pay_amount'] + ]; + array_push($pay_arr['elevotor_pay_detail'], $elevotor_pay_detail); + + // $elevotor_pay_detail[] = $pay['pay_kind']; + // $pay_arr['elevotor_pay_detail']['kind'] = $pay['pay_kind']; + // $pay_arr['elevotor_pay_detail']['pay_scale'] = $pay['pay_scale']; + // $pay_arr['elevotor_pay_detail']['pay_period'] = $pay['pay_period']; + // $pay_arr['elevotor_pay_detail']['amount'] = $pay['pay_amount']; + } + } + } + // echo "
"; + // print_r($pay_arr); + // echo ""; + + foreach ($elevators_results as $keys) { + $contract_elevator_qty += $keys['item_qty']; + } + foreach ($elevators_results as $keys => $result) { + $item_no = $result['item_no']; //電梯項次 + // 電梯 OPTION + $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' AND option_relate_spec = :item_no"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':mid', $mid); + $stmt->bindParam(':item_no', $item_no); + $stmt->execute(); + $option_results = $stmt->fetchAll(PDO::FETCH_ASSOC); + $option_arr[] = $option_results; + // echo "
"; + // print_r($option_arr); + // echo ""; + if (!empty($option_results)) { + $result['option_price'] = 0; + // 電梯 OPTION 價格分別加到各台電梯 + foreach ($option_results as $key => $option) { + if ($option['item_qty'] == $result['item_qty']) { + $result['option_price'] += intval($option['item_unit_price']); + // echo '1..'; + // echo "
"; + // print_r($option['item_unit_price']); + // echo ""; + } else if ($option['item_qty'] / $result['item_qty'] != 1) { + $item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數 + $result['option_price'] += intval($option['item_unit_price']) * $item_qty; + // echo '2..'; + // echo "
"; + // print_r(intval($option['item_unit_price']) . ' *' . $item_qty . '=' . intval($option['item_unit_price']) * $item_qty); + // echo ""; + } else { + $result['option_price'] += $option['item_unit_price'] * intval($option['item_qty']); + // echo '3..'; + } + // echo '
'; + // print_r($option['item_no'] . '--->' . $option['item_unit_price'] . '--->' . $option['item_qty']); + // echo ''; + } + + // print_r($result['option_price']); + // exit(); + } + // 查詢保固延長 + $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='E' AND option_relate_spec = :item_no"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':mid', $mid); + $stmt->bindParam(':item_no', $item_no); + $stmt->execute(); + $other_option_arr = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (!empty($other_option_arr)) { + $result['option_other_price'] = 0; + // 電梯 OPTION 價格分別加到各台電梯 + foreach ($other_option_arr as $key => $option) { + if ($option['item_qty'] == $result['item_qty']) { + $result['option_other_price'] += intval($option['item_unit_price']); + } else if ($option['item_qty'] / $result['item_qty'] != 1) { + $item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數 + $result['option_other_price'] += intval($option['item_unit_price']) * $item_qty; + } else { + $result['option_other_price'] += $option['item_unit_price'] * intval($option['item_qty']); + } + } + } + + $note = explode(',', $result['note']); - $result['spec'] = $note[0]; //型號 + $result['spec'] = $note[0]; //型號 $result['person'] = $note[1]; // 人承 $result['floor'] = $note[2]; // 樓層 $result['speed'] = $note[3]; // 速度 - for ($i = 0; $i < $result['item_qty']; $i++) { + $count_qty = $result['item_qty']; + for ($i = 0; $i < $count_qty; $i++) { + $result['elevator_price'] = round($result['item_price_ct'] / $result['item_qty']); //合約單台電提價格 + $result['commission_fee'] = round($contract['special_fee']) / $contract_elevator_qty; $result['item_no'] = $i + 1; + $result['item_qty'] = 1; array_push($elevators_detail_arr, $result); } } - $count = COUNT($elevators_detail_arr); - $contract['elevators'] = $results; + $count = COUNT($elevators_detail_arr); + $contract['elevators'] = $elevators_results; $contract['elevators_detail_arr'] = $elevators_detail_arr; + $contract['pay_arr'] = $pay_arr; $contract['nums'] = $count; - // echo '
'; - // print_r($contract); - // echo ''; - // exit; + $contractResponse = json_encode($contract); // 設定回應標頭為 JSON header('Content-Type: application/json'); diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index 6eb6dcaa..3b3d87f0 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -35,6 +35,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $files = !empty($_FILES['files']) ? $_FILES['files'] : null; $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; $payType = !empty($_POST['payType']) ? $_POST['payType'] : null; + $contract_type = !empty($_POST['contract_type']) ? $_POST['contract_type'] : null; $sql = "SELECT * FROM account WHERE accountid = '$salesman'"; $stmt = $conn->prepare($sql); @@ -72,7 +73,6 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c // exit(); // } echo json_encode($facilityno); - /// 獎金計算 $fail_arr = []; if ($contractno === '') return $fail_arr[] = '合約號為必填'; if ($total_price == '') $fail_arr[] = '合約總價為必填'; @@ -93,14 +93,21 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; if ($num == '') $fail_arr[] = '電梯數量為必填'; - if ($payType == '') $fail_arr[] = '付款方式為必填'; + if ($payType == '') $fail_arr[] = '分期方式為必填'; + if ($contract_type == '') $fail_arr[] = '合約類別為必填'; if (count($fail_arr) > 0) { header("HTTP/1.1 422 Unprocessable Entity"); echo json_encode($fail_arr); exit(); } T8insert($_POST, $facilityno, $depId); - bonusCreate($_POST, $facilityno, $conn); + /// 獎金計算 + $aaa = bonusCreate($_POST, $facilityno, $conn); + if ($aaa['status'] == 2) { + header("HTTP/1.1 422 Unprocessable Entity"); + echo $aaa['data']; + exit(); + } //create account table $accounttype = "A"; $accountid = $vat; @@ -112,8 +119,6 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $create_at = date('Y-m-d H:i:s'); $conn->beginTransaction(); - // bonusCreate($_POST, $facilityno, $conn); - // exit(); $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)"; $stmt = $conn->prepare($sql_str); @@ -370,7 +375,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c // T8insert($_POST, $facilityno); - // header('Content-Type: application/json'); + header('Content-Type: application/json'); $jsonData = json_encode($files); $conn->commit(); @@ -386,7 +391,7 @@ function T8insert($data, $facilityno, $depId) { require_once("../connt8.php"); // 引入 T8 API 連線 - require_once("./T8salIncomeApply.php"); + require_once("./T8api.php"); $contractno = !empty($data['contractno']) ? $data['contractno'] : null; // 合約號 $address = !empty($data['address']) ? $data['address'] : null; // 客戶地址 @@ -564,23 +569,45 @@ function T8insert($data, $facilityno, $depId) // 分期代碼計算 $IncomeId = [ - 'A40006' => 1, //年繳 - 'A40007' => 4, //季繳 - 'A40003' => 12, //月繳 - 'A40004' => 6, //雙月繳 - 'A40005' => 2 //半年繳 + 'A40006' => 12, //年繳 + 'A40007' => 3, //季繳 + 'A40003' => 1, //月繳 + 'A40004' => 2, //雙月繳 + 'A40005' => 6 //半年繳 ]; - //分幾期 => 總共保養月 / 分期月 - $SQuantity = $elevator['maintain_months'] / $IncomeId[$payType]; + // 幾年 + // $SQuantityYear = $elevator['maintain_months'] / 12; + //分幾期 () => 總共保養月 / 分期月 + $SQuantitya = $elevator['maintain_months'] / $IncomeId[$payType]; + $SQuantity = $IncomeId[$payType]; + // $paymonth = $IncomeId[$payType] * $SQuantity; $date_1 = getNext25thDate($contract_begin_date); - // 依每台電梯去加入各個的付款項 - for ($i = 0; $i < $IncomeId[$payType]; $i++) { + for ($i = 1; $i <= $SQuantitya; $i++) { $row++; // 計算分期款的收款月份 - $paymonth = $i * $SQuantity; + $paymonth = $i * $IncomeId[$payType]; + // switch($IncomeId[$payType]): + // case (1): + // $paymonth = $i * $IncomeId[$payType]; + // $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth years")); + // break; + // case (2): + // $paymonth = $i * $IncomeId[$payType]; + // $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months")); + // break; + // case (12): + // $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months")); + // break; + // case (6): + // $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months")); + // break; + // case (2): + // $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months")); + // break; + $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months")); $payDay = str_replace('-', '', $countDay); $rows_data = [ @@ -593,13 +620,11 @@ function T8insert($data, $facilityno, $depId) "SPrice" => intval($elevator['sold_price']), "SQuantity" => $SQuantity, "ProjectId" => "$contractno", + "FromBillNo" => "$contractno", "CU_MaterialId" => "$facility_no", "CU_EstPayDate" => intval($payDay) ]; $salIncomeApplyDetail_rows[] = $rows_data; - // echo '
'; - // print_r($salIncomeApplyDetail_rows); - // echo ''; } } @@ -644,7 +669,8 @@ function T8insert($data, $facilityno, $depId) // echo '
'; // print_r($API_body); // echo ''; - $result = T8API($API_body); + $api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; + $result = T8salIncomeApply($API_body, $api_url); if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') { @@ -658,14 +684,17 @@ function bonusCreate($data, $facilityno, $conn) { try { require_once("../../bonus/other/maintenance_contract_bonus_v2_1.php"); + require_once("../../bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php"); + $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; $contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : ''; $salesman = !empty($data['salesman']) ? $data['salesman'] : ''; $payType = !empty($data['payType']) ? $data['payType'] : ''; + $contract_type = $data['contract_type']; //合約類別 $status = 1; $bonus_json = []; $create_id = $data['user_id']; - $create_at = date('Y-m-d'); + $create_at = date('Y-m-d H:i:s'); $contract_no = !empty($data['contractno']) ? $data['contractno'] : ''; $contract_kind = 3; @@ -677,26 +706,115 @@ function bonusCreate($data, $facilityno, $conn) 'A40003' => 'monthly' //月繳 ]; + $fail_arr = []; $payDay = getNext25thDate($contract_begin_date); foreach ($elevators as $key => $elevator) { - // print_r($payDay); - // echo '
'; - // print_r($elevator); - // echo ''; - // exit; $facility_no = $facilityno[$key]; $ver = $elevator['bonus_verson']; //獎金版本 - $contract_type = $elevator['contract_type']; //合約類別 $payment_period = $payment[$payType]; //付款方式 - $elevator_list_price = intval($elevator['stand_price']); //牌價 - $fee_per_st = $elevator['contract_price']; //作翻契約金額 - $commission_fee = $elevator['service_expense']; //服務費(月) + $elevator_list_price = !empty(intval($elevator['stand_price'])) ? intval($elevator['stand_price']) : ''; //牌價 + $fee_per_st = !empty($elevator['sold_price']) ? intval(round($elevator['sold_price'] / 1.05, 2)) : ''; //作翻契約金額 (不含稅) + $commission_fee = !empty($elevator['service_expense']) ? $elevator['service_expense'] : ''; //服務費(月/台) $receivable_date_due = $payDay; //第一筆保養款項收回日 $sales_id = $salesman; //營業人員 $discount = $elevator['discount']; $region_director_id = $elevator['manager']; $regular_contract_manger_id = !empty($elevator['regular_contract_manger_id']) ? $elevator['regular_contract_manger_id'] : ''; - $results = maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id); + $maintain_months = intval($elevator['maintain_months']); + $years = $maintain_months / 12; + echo $years; + if ($maintain_months == '') $fail_arr[] = "保養月費為必填"; + if ($fee_per_st == '') $fail_arr[] = "契約金額為必填"; + if ($elevator_list_price == '') $fail_arr[] = "牌價為必填"; + if ($region_director_id == '') $fail_arr[] = '區處長為必填'; + if ($sales_id == '') $fail_arr[] = "契約人為必填"; + + if (COUNT($fail_arr) > 0) { + return $fail_arr; + break; + } + $renew_priceissue_bonus = []; + // $years = ($maintain_months % 12) == 0 ? $maintain_months / 12 : ''; + // 如果保養合約 大於一年 + if (!empty($maintain_months)) { + if ($maintain_months > 12 && $contract_type == 'new') { + // 第一年為 "新簽約" + $results = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + for ($i = 1; $i <= $years - 1; $i++) { + $contract_type = 'renew_priceissue'; + $receivable_date_due_renew = date("Y-m-d", strtotime("$receivable_date_due + $i year")); + // 第二年以上改 "續約" + $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due_renew, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($maintain_months > 12 && $contract_type == 'renew_priceissue') { + // 超過一年的 "續約" + for ($i = 0; $i < $years; $i++) { + $contract_type = 'renew_priceissue'; + $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($maintain_months >= 60 && $contract_type = 'longcontract_m1_free_charge') { + // 五年以上長約 + $results = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $maintain_months, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } else { + $results = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } $bonus_json = [ 'contract_type' => $contract_type, @@ -707,22 +825,54 @@ function bonusCreate($data, $facilityno, $conn) 'receivable_date_due' => $receivable_date_due, 'discount' => $discount ]; - if ($results['result_status'] != 'error') { - foreach ($results['bonus_array'] as $i => $result) { - - $bonus_type = $result['bonus_type']; - $pay_day = $result['pay_day_due']; - $amount = $result['bonus_amount']; - $receiver = $result['bonus_receiver']; - $a = json_encode($bonus_json); - $sql = "INSERT INTO bonus + if (!empty($results)) { + + if ($results['result_status'] != 'error') { + foreach ($results['bonus_array'] as $i => $result) { + + $bonus_type = $result['bonus_type']; + $pay_day = $result['pay_day_due']; + $amount = $result['bonus_amount']; + $receiver = $result['bonus_receiver']; + $a = json_encode($bonus_json); + $sql = "INSERT INTO bonus (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,pay_day_due,status,bonus_json,create_id,create_at) VALUES ($bonus_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$receiver','$pay_day',$status,'$a','$create_id','$create_at')"; - $stmt = $conn->prepare($sql); - $stmt->execute(); + $stmt = $conn->prepare($sql); + $stmt->execute(); + } + } + if (!empty($renew_priceissue_bonus)) { + // echo '1'; + foreach ($renew_priceissue_bonus as $renew_priceissue_bonus) { + foreach ($renew_priceissue_bonus['bonus_array'] as $i => $result) { + + $bonus_type = $result['bonus_type']; + $pay_day = $result['pay_day_due']; + $amount = $result['bonus_amount']; + $receiver = $result['bonus_receiver']; + $a = json_encode($bonus_json); + $sql = "INSERT INTO bonus + (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,pay_day_due,status,bonus_json,create_id,create_at) VALUES + ($bonus_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$receiver','$pay_day',$status,'$a','$create_id','$create_at')"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + } + } } + $request = [ + "status" => "1", + "data" => "Success" + ]; + } else { + $request = [ + "status" => "2", + "data" => "create_bonus_error" + ]; } + // exit(); } + return $request; // exit(); } catch (PDOException $e) { http_response_code(404); diff --git a/wms/contract/api/postNewContractData.php b/wms/contract/api/postNewContractData.php index d94dac12..6fd5756c 100644 --- a/wms/contract/api/postNewContractData.php +++ b/wms/contract/api/postNewContractData.php @@ -1,10 +1,16 @@ + '; - // print_r($elevators); - // echo ''; - // exit; + $area_no = $_POST['area_no']; + $elevators = json_decode($_POST['elevators'], JSON_UNESCAPED_UNICODE); + $elevators_detail_arr = json_decode($_POST['elevators_detail_arr'], JSON_UNESCAPED_UNICODE); + // echo "
"; + // print_r($elevators_detail_arr); + // echo ""; + // exit(); $files = !empty($_FILES['files']) ? $_FILES['files'] : null; $files_id = null; $fail_arr = []; - if (empty($contractno)) $fail_arr[] = '合約號為必填'; - if (empty($customer)) $fail_arr[] = '客戶名稱為必填'; - if (empty($manager)) $fail_arr[] = '負責人為必填'; - if (empty($vat)) $fail_arr[] = '統編/身分證為必填'; - if (empty($case_name)) $fail_arr[] = '案名為必填'; - if (empty($linkman)) $fail_arr[] = '聯絡人為必填'; - if (empty($lm_tel)) $fail_arr[] = '聯絡人電話為必填'; - if (empty($address)) $fail_arr[] = '地址為必填'; - if (empty($salesman)) $fail_arr[] = '營業員為必填'; - if (empty($qc)) $fail_arr[] = '請選擇QC或官檢'; - if (count($fail_arr) > 0) { - header("HTTP/1.1 422 Unprocessable Entity"); - echo json_encode($fail_arr); - exit(); - } + // if (empty($contractno)) $fail_arr[] = '合約號為必填'; + // if (empty($customer)) $fail_arr[] = '客戶名稱為必填'; + // if (empty($manager)) $fail_arr[] = '負責人為必填'; + // if (empty($vat)) $fail_arr[] = '統編/身分證為必填'; + // if (empty($case_name)) $fail_arr[] = '案名為必填'; + // if (empty($linkman)) $fail_arr[] = '聯絡人為必填'; + // if (empty($lm_tel)) $fail_arr[] = '聯絡人電話為必填'; + // if (empty($address)) $fail_arr[] = '地址為必填'; + // if (empty($salesman)) $fail_arr[] = '營業員為必填'; + // if (empty($qc)) $fail_arr[] = '請選擇QC或官檢'; + // if (count($fail_arr) > 0) { + // header("HTTP/1.1 422 Unprocessable Entity"); + // echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); + // exit(); + // } //create facility table $createFacilityNo = new CreateFacilityNo(); $dailyNecessities = [ - 'MAE100' => 'X', - 'MAM200' => 'W', - 'MAH100' => 'H', - 'MAQ100' => 'Z', - 'MAF100' => 'F', - 'MAZ100' => 'B', + 'MAE100' => 'X', //小機房客梯 + 'MAM200' => 'W', //無機房客梯 + 'MAH100' => 'H', //小電梯 + 'MAQ100' => 'Z', //強趨梯 + 'MAF100' => 'F', //貨梯 + 'MAP100' => 'B', //平台梯 ]; $arr = []; // 建立作番號 @@ -68,12 +74,133 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $arr[] = $dailyNecessities[$elevator['spec']]; } $facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums)); - echo '
'; - print_r($facilityno); - echo ''; + echo json_encode($facilityno); + + $bonus_result = BounsCount($_POST, $conn, $facilityno); + if (!empty($bonus_result) && $bonus_result['status'] == "2") { + $fail_arr[] = '獎金計算錯誤,請再檢查或連繫資訊人員'; + // header("HTTP/1.1 422 Unprocessable Entity"); + echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); + exit(); + } + + T8Insert($_POST, $facilityno, $connT8); exit(); $conn->beginTransaction(); + //create account table + $accounttype = "A"; + $accountid = $vat; + $pwd = "123"; + $name = $customer; + $tel = $lm_tel ?? ''; + $sql = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, creater, create_at) + VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address , :creater, :created_at)"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':accounttype', $accounttype); + $stmt->bindParam(':accountid', $contractno); + $stmt->bindParam(':pwd', $pwd); + $stmt->bindParam(':name', $customer); + $stmt->bindParam(':tel', $tel); + $stmt->bindParam(':address', $address); + $stmt->bindParam(':creater', $created_by); + $stmt->bindParam(':created_at', $created_at); + $stmt->execute(); + // exit(); + + //create table Wipwholestatus (作番大日程) + foreach ($elevators_detail_arr as $key => $value) { + $facilityno = $facilityno[$key]; // 作番 + $weight = $value['item_weight']; // 載重 + $person = $value['person']; // 人乘 + $floor = $value['floor']; // 樓層 + $open = $value['item_op']; // 開門方式 + $speed = $value['speed']; //速度 + $qc = $value['qc']; + $facility_kind = $value['spec']; //型號 + $contract_arrival_date = $value['contract_arrival_date']; //到工地日期 + $site_manager = $value['manage']; + $warehouseid = $value['warehouseid']; + $sql = "INSERT INTO Wipwholestatus + (contract_type,contractno,salesid,custom,accountid,site_manager,warehouseid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,area_no,address,contract_arrival_date,real_contract_arrival_date,qc_official_type,creater,create_at) VALUES + ('A',:contractno,:salesid,:custom,:accountid,:site_manager,:warehouseid,:facilityno,:weight,:numberofpassenger,:numberoffloor,:opentype,:speed,:facility_kind,:area_no,:address,:contract_arrival_date,:real_contract_arrival_date,:qc_official_type,:creater,:create_at)"; + // $sql = "INSERT INTO Wipwholestatus + // (contract_type,contractno,salesid,custom,accountid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,address,contract_arrival_date,qc_official_type,creater,create_at) VALUES + // ('A','$contractno','$salesman','$customer','$customer','$facilityno','$weight','$person','$floor','$open','$speed','$facility_kind','$address','$contract_arrival_date','$qc','$created_by','$created_at')"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':contractno', $contractno); + $stmt->bindParam(':salesid', $salesman); + $stmt->bindParam(':custom', $customer); + $stmt->bindParam(':accountid', $customer); + $stmt->bindParam(':site_manager', $site_manager); + $stmt->bindParam(':warehouseid', $warehouseid); + $stmt->bindParam(':facilityno', $facilityno); + $stmt->bindParam(':weight', $weight); + $stmt->bindParam(':numberofpassenger', $person); + $stmt->bindParam(':numberoffloor', $floor); + $stmt->bindParam(':opentype', $open); + $stmt->bindParam(':speed', $speed); + $stmt->bindParam(':facility_kind', $facility_kind); + $stmt->bindParam(':area_no', $area_no); + $stmt->bindParam(':address', $address); + $stmt->bindParam(':contract_arrival_date', $contract_arrival_date); + $stmt->bindParam(':real_contract_arrival_date', $contract_arrival_date); + $stmt->bindParam(':qc_official_type', $qc); + $stmt->bindParam(':creater', $created_by); + $stmt->bindParam(':create_at', $created_at); + $stmt->execute(); + $lastId = $conn->lastInsertId(); + // echo "
"; + // print_r($lastId); + // echo ""; + if (!empty($lastId)) { + echo '123'; + // 寫入待簽程狀態 A (營業) + do_wws_assign1($salesman, $lastId, 'A', $conn); + // // 寫入待簽程狀態 G (工務) + do_wws_assign1($warehouseid, $lastId, 'G', $conn); + } + + + // create table worksite (戰情室) + $latitude = $value['latitude']; + $longitude = $value['longitude']; + $sql = "INSERT INTO worksite + (latitude,longitude,facilitynum,facilityno,address,buildcompany,process,status,marchintotime,creater,create_at)VALUES + (:latitude,:longitude,'1',:facilityno,:address,:bulidcompany,'進行中','未工勘',:marchintotime,:creater,:create_at)"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':latitude', $latitude); + $stmt->bindParam(':longitude', $longitude); + $stmt->bindParam(':facilityno', $facilityno); + $stmt->bindParam(':address', $address); + $stmt->bindParam(':bulidcompany', $customer); + $stmt->bindParam(':marchintotime', $contract_arrival_date); + $stmt->bindParam(':creater', $created_by); + $stmt->bindParam(':create_at', $created_at); + $stmt->execute(); + + // create table schedule + $contract_begin_date = ''; + $contract_end_date = ''; // 一年 + $comboNo = new CreateComboNo('em', $contract_begin_date, $contract_end_date); + $comboArr = json_decode($comboNo->getComboNo(), true); + foreach ($comboArr as $combo) { + $sql_str = 'INSERT INTO schedule (contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES (:contractno, :facilityno, :combono, :repairerid, :repairername, :duedate, :creater, :create_at)'; + $stmt = $conn->prepare($sql_str); + $stmt->bindParam(':contractno', $contractno); + $stmt->bindParam(':facilityno', $facility_no); + $stmt->bindParam(':combono', $combo[0]); + $stmt->bindParam(':repairerid', $repairerid); + $stmt->bindParam(':repairername', $repairername); + $stmt->bindParam(':duedate', $combo[1]); + $stmt->bindParam(':creater', $creater); + $stmt->bindParam(':create_at', $create_at); + $result = $stmt->execute(); + } + } + + + $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; $stmt = $conn->prepare($sql_str); $stmt->bindParam(":accountid", $salesman); @@ -166,160 +293,524 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c } } -function T8Insert($data) +function T8Insert($data, $facilityno, $connT8) { - require_once("../connt8.php"); + try { + // 引入銷售訂單 API + require_once("./T8API.php"); - $contractno = $data['contractno']; - $partyA = $data['customer']; - $phone = $data['lm_tel']; - $vat = $data['vat']; - $partyAaddress = $data['address']; - $user_id = $data['user_id']; - $salesman = $data['salesman']; - $createAt = date("Y-m-dH-i-s"); - $elevators[] = $data['elevators']; - $createTime = str_replace('-', '', $createAt); + $contractno = $data['contractno']; + $partyA = $data['customer']; + $phone = $data['lm_tel']; + $vat = $data['vat']; + $partyAaddress = $data['address']; + $user_id = $data['user_id']; + $salesman = $data['salesman']; + $createAt = date("Y-m-dH-i-s"); - $connT8->beginTransaction(); + $elevators = !empty($data['elevators_detail_arr']) ? json_decode($data['elevators_detail_arr'], true) : []; //電梯 + $pay_arr = !empty($data['pay_arr']) ? json_decode($data['pay_arr'], true) : []; //電梯 - $sql = "SELECT * FROM comCustomer WHERE BizPartnerId = :BizPartnerId"; - $stmt = $conn->prepare($sql); - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->execute(); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - // 新增客戶 table - if (empty($result)) { - // 若 客戶資料為空,新增一筆到 comCustomer - // 新增客戶資料 - $sql = "INSERT INTO comBusinessPartner - (BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,EMail,CreatorId,CreateTime,BizPartnerTypeId) - VALUES(:BizPartnerId,:BizPartnerName,1,'TW',:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:EMail,:CreatorId,:CreateTime,'10')"; + $createTime = str_replace('-', '', $createAt); + $signing_date = intval(str_replace("-", '', $data['signing_date'])); //簽訂日期 + // echo + // $pay_kind = [ + // '1' => '簽約', + // '2' => '二次款', + // '3' => '貨抵工地', + // '4' => '材料其他', + // '5' => '試車完工', //安裝完畢 + // '6' => '交車' //交車 + // ]; + + $pay_kind = [ + '1' => '簽約', + '2' => '二次款', + '3' => '貨抵工地', + '4' => '材料其他', + '5' => '試車完工', //安裝完畢 + '6' => '交車' //交車 + ]; + + $sql = "SELECT * FROM comCustomer + WHERE BizPartnerId = :BizPartnerId + "; $stmt = $connT8->prepare($sql); $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->bindParam(':BizPartnerName', $partyA); //客戶名稱 - $stmt->bindParam(':WorkTelNo', $phone); - $stmt->bindParam(':TaxNo', $vat); - // $stmt->bindParam(':EnterpriseName', $customer); //企業名稱 - $stmt->bindParam(':ContactAddress', $partyAaddress); - $stmt->bindParam(':EMail', $email); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); + $result = $stmt->fetch(PDO::FETCH_ASSOC); - $sql = "INSERT INTO comCustomer - (OrgId,BizPartnerTypeId,CurrId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime,InvoiceId) - VALUES('1000','10','TWD',:BizPartnerId,:PersonId,:CreatorId,1,:InvoiceAddress,:CreateTime,'35')"; - $stmt = $connT8->prepare($sql); + // 新增客戶 table + if (empty($result)) { + // 若 客戶資料為空,新增一筆到 comCustomer + // 新增客戶資料 + $sql = "INSERT INTO comBusinessPartner + (BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,CreatorId,CreateTime,BizPartnerTypeId) + VALUES(:BizPartnerId,:BizPartnerName,1,'TW',:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:CreatorId,:CreateTime,'10')"; + // $sql = "INSERT INTO comBusinessPartner + // (BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,CreatorId,CreateTime,BizPartnerTypeId) + // VALUES('$contractno','$partyA',1,'TW','$phone',99999999,'$vat', '$partyA','$partyAaddress','$user_id',$createTime,'10')"; + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':BizPartnerId', $contractno); + $stmt->bindParam(':BizPartnerName', $partyA); //客戶名稱 + $stmt->bindParam(':WorkTelNo', $phone); + $stmt->bindParam(':TaxNo', $vat); + $stmt->bindParam(':EnterpriseName', $partyA); //企業名稱 + $stmt->bindParam(':ContactAddress', $partyAaddress); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->bindParam(':PersonId', $salesman); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':InvoiceAddress', $address); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); - } else { - // // 若客戶資料不為空,更新該客戶資訊。 - $sql = "UPDATE comCustomer SET + + $sql = "INSERT INTO comCustomer + (OrgId,BizPartnerTypeId,ConditionId,CurrId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime,InvoiceId) + VALUES('1000','10','TWD','0008',:BizPartnerId,:PersonId,:CreatorId,1,:InvoiceAddress,:CreateTime,'35')"; + // $sql = "INSERT INTO comCustomer + // (OrgId,BizPartnerTypeId,CurrId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime,InvoiceId) + // VALUES('1000','10','TWD','$contractno','$salesman','$user_id',1,'$partyAaddress','$createTime','35')"; + $stmt = $connT8->prepare($sql); + + $stmt->bindParam(':BizPartnerId', $contractno); + $stmt->bindParam(':PersonId', $salesman); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':InvoiceAddress', $partyAaddress); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); + } else { + // // 若客戶資料不為空,更新該客戶資訊。 + $sql = "UPDATE comCustomer SET PersonId=:PersonId, + ConditionId='0008', InvoiceAddress=:InvoiceAddress, LastOperatorId=:LastOperatorId, LastOperateTime=:LastOperateTime WHERE BizPartnerId=:BizPartnerId "; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':PersonId', $salesman); - $stmt->bindParam(':InvoiceAddress', $address); - $stmt->bindParam(':LastOperatorId', $user_id); - $stmt->bindParam(':LastOperateTime', $createTime); - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->execute(); + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':PersonId', $salesman); + $stmt->bindParam(':InvoiceAddress', $partyAaddress); + $stmt->bindParam(':LastOperatorId', $user_id); + $stmt->bindParam(':LastOperateTime', $createTime); + $stmt->bindParam(':BizPartnerId', $contractno); + $stmt->execute(); - $sql = "UPDATE comBusinessPartner SET + $sql = "UPDATE comBusinessPartner SET BizPartnerName=:BizPartnerName, WorkTelNo=:WorkTelNo, TaxNo=:TaxNo, EnterpriseName=:EnterpriseName, ContactAddress=:ContactAddress, - EMail=:EMail, LastOperatorId=:LastOperatorId, LastOperateTime=:LastOperateTime WHERE BizPartnerId = :BizPartnerId "; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':BizPartnerName', $partyA); - $stmt->bindParam(':WorkTelNo', $phone); - $stmt->bindParam(':TaxNo', $vat); - $stmt->bindParam(':EnterpriseName', $customer); - $stmt->bindParam(':ContactAddress', $partyAaddress); - $stmt->bindParam(':EMail', $email); - $stmt->bindParam(':LastOperatorId', $user_id); - $stmt->bindParam(':LastOperateTime', $createTime); - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->execute(); - } + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':BizPartnerName', $partyA); + $stmt->bindParam(':WorkTelNo', $phone); + $stmt->bindParam(':TaxNo', $vat); + $stmt->bindParam(':EnterpriseName', $partyA); + $stmt->bindParam(':ContactAddress', $partyAaddress); + // $stmt->bindParam(':EMail', $email); + $stmt->bindParam(':LastOperatorId', $user_id); + $stmt->bindParam(':LastOperateTime', $createTime); + $stmt->bindParam(':BizPartnerId', $contractno); + $stmt->execute(); + } - $sql = "SELECT * FROM comProject WHERE ProjectId = :ProjectId"; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':ProjectId', $contractno); - $stmt->execute(); - $resultProject = $stmt->fetchAll(PDO::FETCH_ASSOC); - if (empty($resultProject)) { - //新增於 comProject。合約 table - $sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,CreateTime,CreatorId,IsInUsed) - VALUES(:ProjectId,:ProjectName,'C0',:CreateTime,:CreatorId,1)"; + $sql = "SELECT * FROM comProject WHERE ProjectId = :ProjectId"; $stmt = $connT8->prepare($sql); $stmt->bindParam(':ProjectId', $contractno); - $stmt->bindParam(':ProjectName', $customer); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->bindParam(':CreatorId', $user_id); $stmt->execute(); + $resultProject = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (empty($resultProject)) { + //新增於 comProject。合約 table + $sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,CreateTime,CreatorId,IsInUsed) + VALUES(:ProjectId,:ProjectName,'C0',:CreateTime,:CreatorId,1)"; + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':ProjectId', $contractno); + $stmt->bindParam(':ProjectName', $partyA); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->execute(); + } + $sql = "SELECT * FROM salSalesOrder WHERE BillNo = :BillNo"; + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':BillNo', $contractno); + $contractT8 = $stmt->fetch(PDO::FETCH_ASSOC); + if (empty($contractT8)) { + foreach ($elevators as $index => $elevator) { + $count = 1; + // 產品集成維護 + $facility_no = $facilityno[$index]; + $MaterialName = "$partyA($facility_no)"; + $contract_arrival_a = $elevator['contract_arrival_date']; + + $sql = "INSERT INTO comMaterial + (FOrgid,MaterialId,MaterialTypeId,MaterialCategoryId,CreatorId,CreateTime,IsInUsed) + VALUES ('1000',:MaterialId,'10','A',:CreatorId,:CreateTime,1)"; + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':MaterialId', $facility_no); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); + + $sql = "INSERT INTO comMaterialGroup + (MaterialTypeId,MaterialId,MaterialName,MaterialCategoryId,IsInUsed,UnitId,CreatorId,CreateTime) + VALUES ('10',:MaterialId,:MaterialName,'A',1,'SET',:CreatorId,:CreateTime)"; + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':MaterialId', $facility_no); + $stmt->bindParam(':MaterialName', $MaterialName); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); + + $sql = "INSERT INTO comMaterialPurchases + (Orgid,MaterialTypeId,MaterialId,CurrId,SUnitId,TaxId,CreatorId,CreateTime) + VALUES ('1000','10',:MaterialId,'TWD','SET','ST005',:CreatorId,:CreateTime)"; + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':MaterialId', $facility_no); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); + + $sql = "INSERT INTO plsMaterialPlanData + (PlanRangeId,MaterialId,FOrgId,MaterialTypeId,CreatorId,CreateTime,DefaultDemandOrg) VALUES + (1000,:MaterialId,1000,10,:CreatorId,:CreateTime,1000) + "; + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':MaterialId', $facility_no); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); + + $sql = "INSERT INTO comMaterialSales + (OrgId,MAterialTypeId,MaterialId,CurrId,SUnitId,SupplyOrgId,CreatorId,CreateTime,IsInUsed) VALUES + (1000,10,:MaterialId,'TWD','SET',1000,:CreatorId,:CreateTime,1) + "; + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':MaterialId', $facility_no); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); + // 階段收款資訊 + $salOrderStagePay_row = []; + $equipment_total = 0; + $install_total = 0; + $equipment_total = $pay_arr['equipment_total']; + $install_total = $pay_arr['install_total']; + $count_a = 0; + $count_month = 1; + foreach ($pay_arr['elevotor_pay_detail'] as $key => $detail) { + if ($detail['kind'] == 3) { + $PlanPayDate = $contract_arrival_a; + } else if ($detail['kind'] > 3) { + $PlanPayDate = date("Y-m-d", strtotime($contract_arrival_a . '+' . $count_month . ' month')); + $count_month++; + } else { + $PlanPayDate = $signing_date; + $count_a++; + if ($count_a == 1) { + $PlanPayDate = date("Y-m-d", strtotime($signing_date . '+' . $count_a . ' month')); + } + } + + $contract_arrival_date = intval(str_replace("-", '', $PlanPayDate)); //貨到工地日 + + $PayStage = $pay_kind[$detail['kind']]; + $PlanPercentage = intval($detail['pay_scale']) / 100; + $rows = [ + "PayStage" => "$PayStage", //收款階段 + "PlanPercentage" => $PlanPercentage, //計劃收款比例(%) + "PlanPayAmt" => $detail['amount'], //計劃收款金額 + "PlanPayDate" => $contract_arrival_date, //計劃收款日期 1.第一筆都是簽約日 + "BillNo" => "$contractno", + "RowCode" => $key + 1, + "RowNo" => $key + 1, + "UnWriteOffOAmount" => $detail['amount'] //未核銷金額 + ]; + $salOrderStagePay_row[] = $rows; + } + + // 設備 + $row1 = [ + "TaxId" => "ST005", + "RequirementDate" => $signing_date, //出貨日期 + "ConsignmentDate" => $signing_date, //發貨日期 + "BillNo" => "$contractno", //合約號 + "RowCode" => $count, //全部筆數排列 + "ItemType" => 1, + "MaterialId" => "A40001", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) + "SUnitId" => "SET", + "SQuantity" => 1, //交易數量 + "SPrice" => $equipment_total, //交易價格 + "CU_MaterialId" => $facility_no + ]; + $count++; + // 安裝 + $row2 = [ + "TaxId" => "ST005", + "RequirementDate" => $signing_date, //出貨日期 + "ConsignmentDate" => $signing_date, //發貨日期 + "BillNo" => "$contractno", //合約號 + "RowCode" => $count, //全部筆數排列 + "ItemType" => 1, + "MaterialId" => "A40008", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) + "SUnitId" => "SET", + "SQuantity" => 1, //交易數量 + "SPrice" => $install_total, //交易價格 + "CU_MaterialId" => $facility_no + ]; + $count++; + // 產品(作番) + $row3 = [ + "TaxId" => "ST005", + "RequirementDate" => $signing_date, //出貨日期 + "ConsignmentDate" => $signing_date, //發貨日期 + "BillNo" => "$contractno", //合約號 + "RowCode" => $count, //全部筆數排列 + "ItemType" => 0, + "MaterialId" => "$facility_no", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) + "SUnitId" => "SET", + "SQuantity" => 1, //交易數量 + "SPrice" => 0, //交易價格 + "CU_MaterialId" => $facility_no // 歸屬作番號 + ]; + $count++; + $SubOrder_row[] = $row1; + $SubOrder_row[] = $row2; + $SubOrder_row[] = $row3; + $count++; + } + $MainSalesOrder_row = [ + "BillNo" => "$contractno", //合約單號 + "BillDate" => $signing_date, //簽約日期 + "TypeId" => "SO", // + "FOrgId" => "1000", + "OrgId" => "1000", + "ModeId" => "M", // T汰改 M新梯 + "BizPartnerId" => "$contractno", //客戶代碼 + "CurrId" => "TWD", + "CurrOAmount" => 1, + "CurrLAmount" => 1, + "PersonId" => "$salesman", //業務人員 + "DueToId" => "$contractno", //債務方 + "TradeConditionId" => "", + "TaxId" => "ST005", + "CreditorCompId" => "1001", + "CreditorOrgId" => "1000", + "CreatorId" => "$user_id" + // "CompId" => "1001", + // "CreditorCurrOAmount" => 1, + // "CreditorCurrLAmount" => 1 + ]; + $MainSalesOrder = [ + "name" => "MainSalesOrder", + 'rows' => [$MainSalesOrder_row] + ]; + $SubOrder = [ + "name" => "SubOrder", + "rows" => $SubOrder_row + ]; + $salOrderStagePay = [ + "name" => "salOrderStagePay", + "rows" => $salOrderStagePay_row + ]; + + $API_body = []; + $API_body[] = $MainSalesOrder; + $API_body[] = $SubOrder; + $API_body[] = $salOrderStagePay; + echo "
"; + print_r(json_encode($API_body, JSON_UNESCAPED_UNICODE)); + echo ""; + $api_url = "https://erp.masada.com.tw:780/twWebAPI/V1/SALSALESORDER/PostERPData"; + + $result = T8salIncomeApply($API_body, $api_url); + // echo "
"; + // print_r($result); + // echo ""; + if ($result['Status'] == 'Fails' || $result['Status'] == 'Error') { + echo $result['ErrorMsg']; + } + } else { + echo '資料已新增過,請洽資訊人員'; + } + $connT8->commit(); + } catch (PDOException $e) { + $connT8->rollback(); + header("HTTP/1.1 500 Internal Server Error"); + die('Error!:' . $e->getMessage()); } } -function BounsCount($data, $conn) +function BounsCount($data, $conn, $facilityno) { - // echo '
'; - // print_r($data); - // echo ''; - // exit; - require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php"); - $signing_date = $data['signing_date']; - $bonus_v1_0_date = '2024-01-02'; - $bonus_v2_0_date = '2024-01-03'; - $contractType = [ - '1' => 'strategy_customer', - '2' => 'general_customer' - ]; - $contract_type = $data['contract_type']; - - $type = $contractType[$contract_type]; //戰略客戶 or 一般客戶 - $elevator_knockdown_price = $data['price_total']; //受價總額 - - $salesman = $data['salesman']; - $manager = $data['manager']; - - $result_bonus = []; - if ($signing_date <= $bonus_v1_0_date) { - $ver = '1.0'; - $result_bonus = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager); - } else if ($signing_date >= $bonus_v2_0_date) { - $ver = '2.0'; - // $result_bonus = elevator_new_deal_bonus_v2_0($ver,$contract_type,); - } - - echo '
'; - print_r($result_bonus); - echo ''; - exit(); try { + require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php"); + $dailyNecessities = [ + 'MAE100' => 'passenger', //小機房 + 'MAM200' => 'passenger', //無機房 + 'MAH100' => 'dumbwaiter', //小電梯 + 'MAQ100' => 'positive_drive', //強趨梯 + 'MAF100' => 'cargo', //貨梯 + 'MAP100' => 'flatbase', // 平台踢 + ]; + $contractType = [ + '1' => 'strategy_customer', + '2' => 'general_customer' + ]; + $signing_date = $data['signing_date']; + $bonus_v1_0_date = '2024-01-02'; + $bonus_v2_0_date = '2024-01-03'; + $contract_type = $data['contract_type']; + $total = $data['price_total']; + $type = $contractType[$contract_type]; //戰略客戶 or 一般客戶 + // $elevator_knockdown_price = $data['price_total']; //受價總額 + $elevators = json_decode($data['elevators_detail_arr'], true); + $contract_no = $data['contractno']; + $salesman = $data['salesman']; + $manager = $data['manager']; + $contract_kind = 1; + $create_id = $data['user_id']; + $create_at = date("Y-m-d H:i:s"); + $status = 1; + + + + + + $result_bonus = []; + $result_bonus_arr = []; + if ($signing_date <= $bonus_v1_0_date) { + $ver = '1.0'; + foreach ($elevators as $key => $elevator) { + + $elevator_knockdown_price = $elevator['elevator_price']; // 單台電梯售價 + $elevator_list_price = $elevator['option_other_price'] + $elevator['option_price'] + $elevator['elevator_price']; //牌價 + $result_bonus = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager); + $facility_no = $facilityno[$key]; + $bonus_json = [ + 'contract_type' => $type, + 'total' => $elevator_list_price, + 'fee_per_st' => $elevator_knockdown_price + ]; + + if (!empty($result_bonus)) { + if ($result_bonus['result_status'] != "error") { + foreach ($result_bonus['bonus_array'] as $i => $result) { + $bonus_type = explode('-', $result['bonus_type']); + $pay_man_type = $bonus_type[0]; //發放類別 + $bonus_kind = $bonus_type[1]; + $amount = $result['bonus_amount']; //獎金水庫 + $bonus_receiver = $result['bonus_receiver']; //發放人員 + $bonus_json['payment_schedul_due'] = $result['payment_schedul_due']; + $bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation']; + $bonus_json['bonus_kind'] = $bonus_kind; + $a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE); + $sql = "INSERT INTO bonus + (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES + ($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at') + "; + $stmt = $conn->prepare($sql); + $stmt->execute(); + } + $request = [ + "status" => "1", + "data" => "Success" + ]; + return $request; + } + $request = [ + "status" => "2", + "data" => "create_bonus_error" + ]; + return $request; + } + } + } else if ($signing_date >= $bonus_v2_0_date) { + $ver = '2.0'; + foreach ($elevators as $key => $elevator) { + $option_other_price = !empty($elevator['option_other_price']) ? intval($elevator['option_other_price']) : 0; + $elevator_type = $dailyNecessities[$elevator['spec']]; + $elevator_list_price = $option_other_price + $elevator['option_price'] + $elevator['elevator_price']; + $elevator_knockdown_price = $elevator['elevator_price']; + $commission_fee = $elevator['commission_fee']; + $result_bonus = elevator_new_deal_bonus_v2_0( + $ver, + $type, + $elevator_type, + $elevator_list_price, + $elevator_knockdown_price, + $salesman, + $manager + ); + // echo '
'; + // print_r($result_bonus); + // echo ''; + $facility_no = $facilityno[$key]; + $bonus_json = [ + 'contract_type' => $type, + 'total' => $elevator_list_price, + 'fee_per_st' => $elevator_knockdown_price + ]; + if (!empty($result_bonus)) { + if ($result_bonus['result_status'] != "error") { + foreach ($result_bonus['bonus_array'] as $i => $result) { + $bonus_type = explode('-', $result['bonus_type']); + $pay_man_type = $bonus_type[0]; //發放類別 + $bonus_kind = $bonus_type[1]; + $amount = $result['bonus_amount']; //獎金水庫 + $bonus_receiver = $result['bonus_receiver']; //發放人員 + $bonus_json['payment_schedul_due'] = $result['payment_schedul_due']; + $bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation']; + $bonus_json['bonus_kind'] = $bonus_kind; + $a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE); + $sql = "INSERT INTO bonus + (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES + ($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at') + "; + $stmt = $conn->prepare($sql); + $stmt->execute(); + } + } + $request = [ + "status" => "1", + "data" => "Success" + ]; + } else { + $request = [ + "status" => "2", + "data" => "create_bonus_error" + ]; + } + } + } + return $request; } catch (PDOException $e) { header("HTTP/1.1 500 Internal Server Error"); die('Error!:' . $e->getMessage()); } } + +function do_wws_assign1($user_id, $form_id, $flow_code, $conn) +{ + $tds = date("Y-m-d H:i:s"); + + $sql = "select appwms.nextval('form_key') form_key"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + $form_key = $result['form_key']; + + $sql = "INSERT INTO flow (system_id, flow_id, form_key, form_id,flow_code) VALUES ('wws', 'wws01', '$form_key', '$form_id','$flow_code');"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + + $sql = "INSERT INTO subflow (form_key, seq, current_assigner, create_date) VALUES ('$form_key', '1', '$user_id', '$tds');"; + $stmt = $conn->prepare($sql); + $stmt->execute(); +} diff --git a/wms/contract/api/test copy.json b/wms/contract/api/test copy.json new file mode 100644 index 00000000..b9dd2f3f --- /dev/null +++ b/wms/contract/api/test copy.json @@ -0,0 +1,398 @@ +[ + { + "name": "MainSalesOrder", + "rows": [ + { + "BillNo": "M23110121", + "BillDate": 20240313, + "TypeId": "SO", + "FOrgId": "1000", + "OrgId": "1000", + "ModeId": "M", + "BizPartnerId": "M23110121", + "CurrId": "TWD", + "CurrOAmount": 1, + "CurrLAmount": 1, + "PersonId": "M0042", + "DueToId": "M23110121", + "TradeConditionId": "", + "TaxId": "ST005", + "CreditorCompId": "1001", + "CreditorOrgId": "1000", + "CreatorId": "M0225" + } + ] + }, + { + "name": "SubOrder", + "rows": [ + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 3904000, + "CU_MaterialId": "4MH00836" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 976000, + "CU_MaterialId": "4MH00836" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MH00836", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MH00836" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 3904000, + "CU_MaterialId": "4MH00837" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 976000, + "CU_MaterialId": "4MH00837" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MH00837", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MH00837" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 3904000, + "CU_MaterialId": "4MH00838" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 976000, + "CU_MaterialId": "4MH00838" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MH00838", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MH00838" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 3904000, + "CU_MaterialId": "4MH00839" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 976000, + "CU_MaterialId": "4MH00839" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MH00839", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MH00839" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 3904000, + "CU_MaterialId": "4MH00840" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 976000, + "CU_MaterialId": "4MH00840" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MH00840", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MH00840" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 3904000, + "CU_MaterialId": "4MH00841" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 976000, + "CU_MaterialId": "4MH00841" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MH00841", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MH00841" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 3904000, + "CU_MaterialId": "4MH00842" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 976000, + "CU_MaterialId": "4MH00842" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MH00842", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MH00842" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 3904000, + "CU_MaterialId": "4MH00843" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 976000, + "CU_MaterialId": "4MH00843" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MH00843", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MH00843" + } + ] + }, + { + "name": "salOrderStagePay", + "rows": [ + { + "PayStage": "簽約", + "PlanPercentage": 0.2, + "PlanPayAmt": 976000, + "PlanPayDate": 20240413, + "BillNo": "M23110121", + "RowCode": 1, + "RowNo": 1, + "UnWriteOffOAmount": 976000 + }, + { + "PayStage": "二次款", + "PlanPercentage": 0.4, + "PlanPayAmt": 1952000, + "PlanPayDate": 20240313, + "BillNo": "M23110121", + "RowCode": 2, + "RowNo": 2, + "UnWriteOffOAmount": 1952000 + }, + { + "PayStage": "貨抵工地", + "PlanPercentage": 0.2, + "PlanPayAmt": 976000, + "PlanPayDate": 20241104, + "BillNo": "M23110121", + "RowCode": 3, + "RowNo": 3, + "UnWriteOffOAmount": 976000 + }, + { + "PayStage": "試車完工", + "PlanPercentage": 0.1, + "PlanPayAmt": 488000, + "PlanPayDate": 20241204, + "BillNo": "M23110121", + "RowCode": 4, + "RowNo": 4, + "UnWriteOffOAmount": 488000 + }, + { + "PayStage": "交車", + "PlanPercentage": 0.1, + "PlanPayAmt": 488000, + "PlanPayDate": 20250104, + "BillNo": "M23110121", + "RowCode": 5, + "RowNo": 5, + "UnWriteOffOAmount": 488000 + } + ] + } +] \ No newline at end of file diff --git a/wms/contract/api/test.json b/wms/contract/api/test.json index 04729705..da130a89 100644 --- a/wms/contract/api/test.json +++ b/wms/contract/api/test.json @@ -1,185 +1,66 @@ [ { - "name": "salIncomeApplyMaster", + //salSalesOrder + "name": "MainSalesOrder", "rows": [ { - "BillNo": "B23100060", - "BillDate": "20240122", - "OrgId": "1000", + "BillNo": "Z001", //合約單號 + "BillDate": 20210420, //簽約日期 + "TypeId": "SO", // "FOrgId": "1000", - "TypeId": "RAS", - "BpOrgId": "1000", - "BizPartnerId": "B23100060", + "OrgId": "1000", + "ModeId": "T", // T汰改 M新梯 + "BizPartnerId": "M0225", //創建人ID "CurrId": "TWD", "CurrOAmount": 1, "CurrLAmount": 1, - "PersonId": "M0065", - "DtOrgId": "1000", - "DueToId": "B23100060", + "PersonId": "M0225", //業務人員 + "DueToId": "512", //業務部門 + "TradeConditionId": "", "TaxId": "ST005", - "CompId": "1001", - "CreatorId": "M0225" + "CreditorCompId": "1000", + "CreditorOrgId": "1000", + "CreditorCurrOAmount": 1, + "CreditorCurrLAmount": 1, + "CompId": "1000" } ] }, { - "name": "salIncomeApplyDetail", + // salSalesOrderDetail + "name": "SubOrder", "rows": [ { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 1, - "RowNo": 1, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 2, - "RowNo": 2, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 3, - "RowNo": 3, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 4, - "RowNo": 4, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 5, - "RowNo": 5, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 6, - "RowNo": 6, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", + "SupplyCompId": "1001", + "SupplyOrgId": "1000", "TaxId": "ST005", - "RowCode": 7, - "RowNo": 7, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 8, - "RowNo": 8, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 9, - "RowNo": 9, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 10, - "RowNo": 10, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, - { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 11, - "RowNo": 11, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" - }, + "RequirementDate": 20210420, //出貨日期 + "ConsignmentDate": 20210420, //發貨日期 + "DispatchCompId": "1001", + "DispatchOrgId": "1000", + "BillNo": "Z001", //合約號 + "RowCode": 1, //全部筆數排列 + "ItemType": 0, + "MaterialId": "Z001", //作番號 + "SUnitId": "SET", + "SQuantity": 1, //交易數量 + "SPrice": 1 //交易價格 + } + ] + }, + { + //salOrderStagePay + "name": "salOrderStagePay", + "rows": [ { - "BillNo": "B23100060", - "IncomeId": "A40003", - "TaxId": "ST005", - "RowCode": 12, - "RowNo": 12, - "ItemType": 1, - "SPrice": 1250, - "SQuantity": 1, - "ProjectId": "B23100060", - "FromSourceTag": 0, - "CU_MaterialId": "4TH53801" + "BillNo": "", + "RowCode": "", + "RowNo": "", + "PayStage": "ST003", //收款階段 + "PlanPercentage": "Z001", //計劃收款比例(%) + "PlanPayAmt": 1, //計劃收款金額 + "PlanPayDate": 1, //計劃收款日期 1.第一筆都是簽約日 + "UnWriteOffOAmount": 1 //未核銷金額 } ] } diff --git a/wms/contract/api/testT8API.php b/wms/contract/api/testT8API.php index 9512cbc8..e9d2f04f 100644 --- a/wms/contract/api/testT8API.php +++ b/wms/contract/api/testT8API.php @@ -1,36 +1,257 @@ - - -
"; +// print_r($data); +// echo ""; + +echo "
"; +print_r(json_encode($APIbody, JSON_UNESCAPED_UNICODE)); +echo ""; +// exit(); + +$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($APIbody, 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']; + print_r($result); + } else { + // print_r($result); + print_r($result); + } + print_r($result); +} + +curl_close($ch); diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 114cea2f..92aaf7d0 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -57,8 +57,10 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
未填寫
標準價+Option價格+與其他電梯共同分擔的費用貨價格
+標準價+Option價格+與其他電梯共同分擔的費用貨價格