From 2f1afae09efd6727eb526049573a39fb72ae6b8c Mon Sep 17 00:00:00 2001 From: Cheng Date: Thu, 29 Feb 2024 20:14:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E6=A2=AF=E3=80=81=E4=BF=9D=E9=A4=8A?= =?UTF-8?q?=E7=8D=8E=E9=87=91=E8=A8=88=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wms/bonus/api/postStatus.php | 125 +++++- wms/bonus/bonus_person.php | 146 +++++++ .../elevator_new/elevator_new_deal_bonus.php | 20 +- wms/bonus/maintainance_bonus.php | 366 ++++++++++++++++++ ...tail.php => maintainance_bonus_detail.php} | 0 wms/bonus/{bonus.php => new_bonus.php} | 37 +- .../other/maintenance_contract_bonus_v2_1.php | 3 +- ...m_contract_m1_free_charge_bonus_v2_1_1.php | 19 +- wms/contract/api/getContractData.php | 94 ++++- wms/contract/api/postContractData.php | 95 +++-- wms/contract/api/postNewContractData.php | 133 ++++++- wms/contract/contract-input.php | 5 +- wms/contract/js/alpine.js | 16 +- 13 files changed, 922 insertions(+), 137 deletions(-) create mode 100644 wms/bonus/bonus_person.php create mode 100644 wms/bonus/maintainance_bonus.php rename wms/bonus/{bonus_detail.php => maintainance_bonus_detail.php} (100%) rename wms/bonus/{bonus.php => new_bonus.php} (83%) diff --git a/wms/bonus/api/postStatus.php b/wms/bonus/api/postStatus.php index 86f9f88d..0ebcd723 100644 --- a/wms/bonus/api/postStatus.php +++ b/wms/bonus/api/postStatus.php @@ -2,22 +2,36 @@ require_once("../../contract/conn.php"); if (!empty($_POST['id']) && !empty($_POST['postType']) && $_POST['postType'] == 'a') { - try { - $id = empty($_POST['id']) ? '' : $_POST['id']; - $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; - $amount = empty($_POST['amount']) ? '' : $_POST['amount']; - $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; - $review_at = date("Y-m-d H:i:s"); - $sql = "UPDATE bonus SET status = 2 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day',update_id='$user_id',update_at='$review_at' WHERE id = $id"; - $stmt = $conn->prepare($sql); - $stmt->execute(); + if ($_POST['contract_type'] == 'maintainance') { + try { + $id = empty($_POST['id']) ? '' : $_POST['id']; + $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; + $amount = empty($_POST['amount']) ? '' : $_POST['amount']; + $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; + $review_at = date("Y-m-d H:i:s"); + $sql = "UPDATE bonus SET status = 2 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day',update_id='$user_id',update_at='$review_at' WHERE id = $id"; + $stmt = $conn->prepare($sql); + $stmt->execute(); - header("HTTP/1.1 200 success!"); - echo 'Success'; - } catch (PDOException $e) { - header("HTTP/1.1 404 failed!"); - echo $e->getMessage(); - die('Error!:' . $e->getMessage()); + header("HTTP/1.1 200 success!"); + echo 'Success'; + } catch (PDOException $e) { + header("HTTP/1.1 404 failed!"); + echo $e->getMessage(); + die('Error!:' . $e->getMessage()); + } + } else if ($_POST['contract_type'] == 'new') { + try { + $id = empty($_POST['id']) ? '' : $_POST['id']; + $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; + $amount = empty($_POST['amount']) ? '' : $_POST['amount']; + + header("HTTP/1.1 200 success!"); + echo 'Success'; + } catch (PDOException $e) { + echo $e->getMessage(); + die('Error!:' . $e->getMessage()); + } } } // 獎金確認發放,並更新獎金 OR 實際發放時間 @@ -109,3 +123,84 @@ if (!empty($_POST['postType']) && $_POST['postType'] == 'd') { } // echo 'ddddd'; } +// 查看T8 是否收款 +if (!empty($_POST['postType']) && $_POST['postType'] == 'e') { + $sql = "SELECT contract_no FROM bonus WHERE contract_type = 3 AND T8api_status = 1 "; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + // echo "
";
+    // 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); + } +} + +?> +
+ + + + + + + + +
+

月份、個人獎金計算

+
+
+ + + + + + + + + + + + +
年份 + + 月份 + +
+ + +
+ + + + + + + + + + + + + $bonus) { + ?> + + + + + + + + +
工號姓名總獎金水庫(實發總價)
+
\ No newline at end of file diff --git a/wms/bonus/elevator_new/elevator_new_deal_bonus.php b/wms/bonus/elevator_new/elevator_new_deal_bonus.php index c26e747d..7138e787 100644 --- a/wms/bonus/elevator_new/elevator_new_deal_bonus.php +++ b/wms/bonus/elevator_new/elevator_new_deal_bonus.php @@ -59,7 +59,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele #營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% array_push($bonus_array, [ - "bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 + "bonus_type" => "1-訂金段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.2), #金額 "payment_schedul_due" => "deposit", #訂金已收款20% @@ -68,7 +68,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele #營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% array_push($bonus_array, [ - "bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 + "bonus_type" => "1-出貨款段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.5), #金額 "payment_schedul_due" => "shipping", #訂金已收款20% @@ -77,7 +77,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele #營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% array_push($bonus_array, [ - "bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 + "bonus_type" => "1-驗收款段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.3), #金額 "payment_schedul_due" => "acceptance", #訂金已收款20% @@ -86,7 +86,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele #區域經理提成獎金水庫-----訂金已收款100%,發放總獎金50% array_push($bonus_array, [ - "bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 + "bonus_type" => "2-訂金段", #獎金名稱 "bonus_receiver" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_bonus * 0.5), #金額 "payment_schedul_due" => "deposit", #訂金已收款100% @@ -95,7 +95,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% array_push($bonus_array, [ - "bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 + "bonus_type" => "2-貨到工地款段", #獎金名稱 "bonus_receiver" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_bonus * 0.5), #金額 "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100% @@ -150,7 +150,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_ #營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% array_push($bonus_array, [ - "bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 + "bonus_type" => "1-訂金段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.2), #金額 "payment_schedul_due" => "deposit", #訂金已收款20% @@ -159,7 +159,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_ #營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% array_push($bonus_array, [ - "bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 + "bonus_type" => "1-出貨款段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.5), #金額 "payment_schedul_due" => "shipping", #訂金已收款20% @@ -168,7 +168,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_ #營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% array_push($bonus_array, [ - "bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 + "bonus_type" => "1-驗收款段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.3), #金額 "payment_schedul_due" => "acceptance", #訂金已收款20% @@ -177,7 +177,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_ #區域經理獎金水庫-----訂金已收款100%,發放總獎金50% array_push($bonus_array, [ - "bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 + "bonus_type" => "2-訂金段", #獎金名稱 "bonus_receiver" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_bonus * 0.5), #金額 "payment_schedul_due" => "deposit", #訂金已收款100% @@ -186,7 +186,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_ #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% array_push($bonus_array, [ - "bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 + "bonus_type" => "2-貨到工地款段", #獎金名稱 "bonus_receiver" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_bonus * 0.5), #金額 "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100% diff --git a/wms/bonus/maintainance_bonus.php b/wms/bonus/maintainance_bonus.php new file mode 100644 index 00000000..ee2ab36b --- /dev/null +++ b/wms/bonus/maintainance_bonus.php @@ -0,0 +1,366 @@ + '新梯', + '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 = 3"; + +$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"); +?> + + + + + + + + +
+
+
+ + + + + + + +
+

(契約)獎金計算

+
+ + btn-sm categoryBtn"> 所有獎金 + + btn-sm categoryBtn"> 未發獎金 + btn-sm categoryBtn"> 已發獎金 + btn-sm categoryBtn"> 人事發放作業 + btn-sm categoryBtn"> 獎金總計(人) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $data) : + + $contract_no = $data['contract_no']; + $json = json_decode($data['bonus_json']); + $total = empty($json->total) ? 0 : $json->total; + $fee_per_st = empty($json->fee_per_st) ? 0 : $json->fee_per_st; + $commission_fee = empty($json->commission_fee) ? 0 : $json->commission_fee; + // $isPay = isPay($data['contract_no'], $connT8); + + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
項次合約號合約名稱作番號獎金類別獎金版本作番金額(月)牌價服務費應發人員預計發放時間應發獎金水庫實發金額狀態實際發放時間發放 / 詳情詳情
+ + + -- + + + + 查看詳情 + + 查看詳情查看詳情
+
+
+ + + + + \ No newline at end of file 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/bonus.php b/wms/bonus/new_bonus.php similarity index 83% rename from wms/bonus/bonus.php rename to wms/bonus/new_bonus.php index 63bec621..c595e442 100644 --- a/wms/bonus/bonus.php +++ b/wms/bonus/new_bonus.php @@ -42,7 +42,7 @@ if (!empty($_GET['check'])) { $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"; +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); @@ -124,23 +124,30 @@ function isPay($contract_no, $connT8)
+ + + + + + + +
+

(契約)獎金計算

+
- btn-sm categoryBtn"> 所有獎金 + btn-sm categoryBtn"> 所有獎金 - btn-sm categoryBtn"> 未發獎金 - btn-sm categoryBtn"> 已發獎金 - btn-sm categoryBtn"> 人事發放作業 - btn-sm categoryBtn"> 獎金總計(人) + btn-sm categoryBtn"> 未發獎金 + btn-sm categoryBtn"> 已發獎金 + btn-sm categoryBtn"> 人事發放作業 + btn-sm categoryBtn"> 獎金總計(人) - - - @@ -154,7 +161,6 @@ function isPay($contract_no, $connT8) - @@ -165,7 +171,7 @@ function isPay($contract_no, $connT8) - + @@ -173,7 +179,8 @@ function isPay($contract_no, $connT8) $data) : - + $bonus_json = json_decode($data['bonus_json']); + $bonus_kind = !empty($bonus_json->bonus_kind) ? $bonus_json->bonus_kind : ''; $contract_no = $data['contract_no']; $json = json_decode($data['bonus_json']); $total = empty($json->total) ? 0 : $json->total; @@ -187,13 +194,12 @@ function isPay($contract_no, $connT8) - + - + @@ -336,6 +342,7 @@ function isPay($contract_no, $connT8) form.append('pay_day', pay_day) form.append('amount', amount); form.append('postType', 'a'); + form.append('contract_type', 'new'); axios.post('./api/postStatus.php', form).then((res) => { if (res.data == 'Success') { alert('更新成功'); diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1.php b/wms/bonus/other/maintenance_contract_bonus_v2_1.php index 27959883..086dbbf1 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1.php @@ -43,10 +43,11 @@ result_array[ function 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 = '') { + // $fee_per_st = round($fee_per_st); $bonus_array = []; if ($ver == "2.1") { // $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); - $discount = ($fee_per_st - $commission_fee) / $elevator_list_price; + $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 10); #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) switch ($contract_type) { diff --git a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php index 70a19f40..db37fd30 100644 --- a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php @@ -120,7 +120,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract }; #付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) array_push($bonus_array, [ - "bonus_type" => "地區處長獎金", #獎金名稱 + "bonus_type" => "2", #獎金名稱 "bonus_receiver" => $region_director_id, #發放人員 "bonus_amount" => round($region_director_bonus), #金額 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +12 months")), #預計發放時間 @@ -130,7 +130,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract #專任契約經理獎金 if ($regular_contract_manger_id != '') { array_push($bonus_array, [ - "bonus_type" => "專任契約經理獎金", #獎金名稱 + "bonus_type" => "3", #獎金名稱 "bonus_receiver" => $regular_contract_manger_id, #發放人員 "bonus_amount" => round($regular_contract_manger_bonus), #金額 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +12 months")), #預計發放時間 @@ -162,11 +162,11 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 }; array_push($bonus_array, [ - "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_type" => "1", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($current_bonus), #金額 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] year")), #預計發放時間 - "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + "bonus_regulation" => "每次收款後,按收款比率次月發放" #發放規定 ]); } @@ -191,11 +191,11 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 }; array_push($bonus_array, [ - "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_type" => "1", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($current_bonus), #金額 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 - "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + "bonus_regulation" => "每次收款後,按收款比率次月發放" #發放規定 ]); } break; @@ -219,7 +219,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 }; array_push($bonus_array, [ - "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_type" => "1", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($current_bonus), #金額 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 @@ -227,7 +227,6 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract ]); } break; - break; #雙月繳 case 'bimonthly': $a = $payment_period_amount / 2; @@ -248,7 +247,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 }; array_push($bonus_array, [ - "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_type" => "1", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($current_bonus), #金額 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 @@ -278,7 +277,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 }; array_push($bonus_array, [ - "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_type" => "1", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($current_bonus), #金額 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php index 5534b8eb..7d31dcbb 100644 --- a/wms/contract/api/getContractData.php +++ b/wms/contract/api/getContractData.php @@ -73,14 +73,17 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont $stmt->execute(); $elevators_results = $stmt->fetchAll(PDO::FETCH_ASSOC); $elevators_detail_arr = []; - - $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' "; - $stmt = $conn->prepare($sql); - $stmt->bindParam(':mid', $mid); - $stmt->execute(); - $option_results = $stmt->fetchAll(PDO::FETCH_ASSOC); - $option_arr = []; - + $contract_elevator_qty = 0; + // $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' "; + // $stmt = $conn->prepare($sql); + // $stmt->bindParam(':mid', $mid); + // $stmt->execute(); + // $option_results = $stmt->fetchAll(PDO::FETCH_ASSOC); + // $option_arr = []; + + foreach ($elevators_results as $keys) { + $contract_elevator_qty += $keys['item_qty']; + } foreach ($elevators_results as $keys => $result) { $item_no = $result['item_no']; //電梯項次 // 電梯 OPTION @@ -91,36 +94,87 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont $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_arr[$keys] as $key => $option) { + foreach ($option_results as $key => $option) { if ($option['item_qty'] == $result['item_qty']) { $result['option_price'] += intval($option['item_unit_price']); - echo '1..'; - } else if ($option['item_qty'] > $result['item_qty'] != 1) { + // 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 '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 '3..'; } - echo '
';
-                    print_r($option['item_no'] . '--->' . $option['item_unit_price']);
-                    echo '
'; + // echo '
';
+                    // print_r($option['item_no'] . '--->' . $option['item_unit_price'] . '--->' . $option['item_qty']);
+                    // echo '
'; } - print_r($result['option_price']); - exit(); + // 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']); + // 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_other_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_other_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_other_price']); + // exit(); + } + + $note = explode(',', $result['note']); $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); } } @@ -137,7 +191,7 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont header('Content-Type: application/json'); // 將 JSON 回應返回給客戶端 - // echo $contractResponse; + echo $contractResponse; } catch (PDOException $e) { die("ERROR!!!: " . $e->getMessage()); } diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index e8dca10f..445d0b5b 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,17 +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); + /// 獎金計算 $aaa = bonusCreate($_POST, $facilityno, $conn); - echo '
';
-        print_r($aaa);
-        echo '
'; + if ($aaa['status'] == 2) { + header("HTTP/1.1 422 Unprocessable Entity"); + echo $aaa['data']; + exit(); + } exit; //create account table $accounttype = "A"; @@ -683,6 +687,7 @@ function bonusCreate($data, $facilityno, $conn) 'A40005' => 'semiannually', // 半年繳 'A40003' => 'monthly' //月繳 ]; + $fail_arr = []; $payDay = getNext25thDate($contract_begin_date); foreach ($elevators as $key => $elevator) { @@ -690,7 +695,7 @@ function bonusCreate($data, $facilityno, $conn) $ver = $elevator['bonus_verson']; //獎金版本 $payment_period = $payment[$payType]; //付款方式 $elevator_list_price = !empty(intval($elevator['stand_price'])) ? intval($elevator['stand_price']) : ''; //牌價 - $fee_per_st = !empty(round($elevator['sold_price'] / 1.05, 2)) ? round($elevator['sold_price'] / 1.05, 2) : ''; //作翻契約金額 (不含稅) + $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; //營業人員 @@ -699,7 +704,7 @@ function bonusCreate($data, $facilityno, $conn) $regular_contract_manger_id = !empty($elevator['regular_contract_manger_id']) ? $elevator['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[] = "牌價為必填"; @@ -710,12 +715,12 @@ function bonusCreate($data, $facilityno, $conn) 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, @@ -728,27 +733,28 @@ function bonusCreate($data, $facilityno, $conn) $region_director_id, $regular_contract_manger_id ); - for ($i = 0; $i < $maintain_months - 1; $i++) { + for ($i = 1; $i <= $years - 1; $i++) { $contract_type = 'renew_priceissue'; - // 第二年以上改續約 - $result2 = maintenance_contract_bonus_v2_1( + $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, + $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'; - $result2 = maintenance_contract_bonus_v2_1( + $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( $ver, $contract_type, $payment_period, @@ -761,9 +767,9 @@ function bonusCreate($data, $facilityno, $conn) $regular_contract_manger_id ); } - } else if ($maintain_months >= 60) { - $contract_type = 'longcontract_m1_free_charge'; - $result = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( + } 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, @@ -791,6 +797,7 @@ function bonusCreate($data, $facilityno, $conn) ); } } + $bonus_json = [ 'contract_type' => $contract_type, 'total' => $elevator_list_price, @@ -800,22 +807,10 @@ 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 - (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(); - } - if (!empty($result2)) { - foreach ($results2['bonus_array'] as $i => $result) { + 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']; @@ -823,15 +818,43 @@ function bonusCreate($data, $facilityno, $conn) $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(); + } + } + 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(); + $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 6180e4d4..a62d6e95 100644 --- a/wms/contract/api/postNewContractData.php +++ b/wms/contract/api/postNewContractData.php @@ -48,7 +48,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c if (empty($qc)) $fail_arr[] = '請選擇QC或官檢'; if (count($fail_arr) > 0) { header("HTTP/1.1 422 Unprocessable Entity"); - echo json_encode($fail_arr); + echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); exit(); } //create facility table @@ -69,8 +69,14 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c } $facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums)); - BounsCount($_POST, $conn, $facilityno); - exit(); + $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(); + } + // exit(); $conn->beginTransaction(); $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; @@ -118,7 +124,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':file_size', $file['size']); $stmt->bindParam(':created_at', $created_at); $stmt->bindParam(':created_by', $created_by); - $stmt->execute(); + // $stmt->execute(); } else { throw new PDOException('檔案上傳失敗:' . $msg); } @@ -151,7 +157,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(":created_at", $created_at); $stmt->bindParam(":created_by", $created_by); $stmt->bindParam(":qc", $qc); - $stmt->execute(); + // $stmt->execute(); $result = $conn->commit(); @@ -304,13 +310,17 @@ function BounsCount($data, $conn, $facilityno) $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; @@ -318,28 +328,109 @@ function BounsCount($data, $conn, $facilityno) $result_bonus_arr = []; if ($signing_date <= $bonus_v1_0_date) { $ver = '1.0'; - foreach ($elevators as $i => $elevator) { + foreach ($elevators as $key => $elevator) { - $elevator_knockdown_price = $elevator['item_price_ct']; + $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); - $result_bonus['facility'] = $facilityno[$i]; - $result_bonus_arr[] = $result_bonus; + $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 $i => $elevator) { + foreach ($elevators as $key => $elevator) { $elevator_type = $dailyNecessities[$elevator['spec']]; - $elevator_list_price = $elevator['']; - $result_bonus = elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $sales_id, $region_manger_id); + $elevator_list_price = $elevator['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" + ]; + } } } - // foreach ($elevators as $elevator) { - // $elevator_knockdown_price = $elevator['item_price_ct']; - // } - echo '
';
-  print_r($result_bonus_arr);
-  echo '
'; - exit(); + return $request; + try { } catch (PDOException $e) { header("HTTP/1.1 500 Internal Server Error"); diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index cbec41c1..56af787c 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -209,6 +209,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); + @@ -449,9 +450,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); - - - +
牌價 服務費 應發人員預計發放時間 應發獎金水庫 實發金額 狀態發放 / 詳情 詳情
@@ -225,7 +231,7 @@ function isPay($contract_no, $connT8) - 查看詳情