From 1d3989ba9c9f6f1576d2c07c196127944df768c9 Mon Sep 17 00:00:00 2001 From: Cheng Date: Mon, 26 Feb 2024 18:02:29 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=96=B0=E6=A2=AF=E5=A5=91=E7=B4=84?= =?UTF-8?q?=E7=8D=8E=E9=87=91=E5=92=8C=E7=B0=BD=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wms/bonus/bonus.php | 18 ++- .../other/maintenance_contract_bonus_v2_1.php | 52 ++++--- ...erm_contract_m1_free_charge_bonus_v2_1.php | 127 +++++++++--------- wms/contract/api/getContractData.php | 59 ++++++-- wms/contract/api/postContractData.php | 25 ++-- wms/contract/api/postNewContractData.php | 63 ++++++--- wms/contract/contract-input.php | 20 +-- wms/contract/js/alpine.js | 3 +- 8 files changed, 222 insertions(+), 145 deletions(-) diff --git a/wms/bonus/bonus.php b/wms/bonus/bonus.php index 4e0b84fd..63bec621 100644 --- a/wms/bonus/bonus.php +++ b/wms/bonus/bonus.php @@ -32,15 +32,17 @@ 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 status IN (1,2,5)"; + $clause .= "AND a.status IN (1,2,5)"; } else if ($_GET['check'] == 2) { - $clause .= "AND status = 1"; + $clause .= "AND a.status = 1"; } else if ($_GET['check'] == 3) { - $clause .= "AND status IN (2,5)"; + $clause .= "AND a.status IN (2,5)"; } } -$sql = "SELECT * FROM bonus WHERE 1=1 $clause"; +$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"; $stmt = $conn->prepare($sql); $stmt->execute(); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -130,17 +132,21 @@ function isPay($contract_no, $connT8) btn-sm categoryBtn"> 未發獎金 btn-sm categoryBtn"> 已發獎金 btn-sm categoryBtn"> 人事發放作業 + btn-sm categoryBtn"> 獎金總計(人) + + + - + @@ -178,8 +184,8 @@ function isPay($contract_no, $connT8) ?> - + diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1.php b/wms/bonus/other/maintenance_contract_bonus_v2_1.php index 610da6d7..598202d4 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1.php @@ -55,48 +55,48 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case ($discount >= 0.8): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.6; + $sales_bonus = ($fee_per_st) * 0.6; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.7; + $sales_bonus = ($fee_per_st) * 0.7; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.8; + $sales_bonus = ($fee_per_st) * 0.8; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.9; + $sales_bonus = ($fee_per_st) * 0.9; break; }; break; case ($discount >= 0.6 and $discount < 0.8): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.48; + $sales_bonus = ($fee_per_st) * 0.48; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.56; + $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.64; + $sales_bonus = ($fee_per_st) * 0.64; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.72; + $sales_bonus = ($fee_per_st) * 0.72; break; }; break; case ($discount < 0.6): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.42; + $sales_bonus = ($fee_per_st) * 0.42; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.49; + $sales_bonus = ($fee_per_st) * 0.49; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.56; + $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.63; + $sales_bonus = ($fee_per_st) * 0.63; break; }; break; @@ -111,16 +111,16 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "free_to_charge": switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.3; + $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.35; + $sales_bonus = ($fee_per_st) * 0.35; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.4; + $sales_bonus = ($fee_per_st) * 0.4; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.45; + $sales_bonus = ($fee_per_st) * 0.45; break; }; #地區處長獎金($region_director_bonus) @@ -132,16 +132,16 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "renew_priceissue": switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.25; + $sales_bonus = ($fee_per_st) * 0.25; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.3; + $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.35; + $sales_bonus = ($fee_per_st) * 0.35; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.4; + $sales_bonus = ($fee_per_st) * 0.4; break; }; #地區處長獎金($region_director_bonus) @@ -226,7 +226,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, #2月1次 case "bimonthly": - $payment_ratio_due_array = array(0.166, 0.166, 0.166, 0.166, 0.166, 0.166); + $payment_ratio_due_array = array(); + for ($i = 0; $i < 6; $i++) { + array_push($payment_ratio_due_array, 1 / 6); + } $payday_due_array = array(1, 3, 5, 7, 9, 11); for ($i = 0; $i < count($payment_ratio_due_array); $i++) { if ($i < count($payment_ratio_due_array) - 1) { @@ -246,7 +249,12 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, #月付 case "monthly": - $payment_ratio_due_array = array(0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083); + $payment_ratio_due_array = array(); + // $payment_ratio_due_array = array(); + for ($i = 0; $i < 12; $i++) { + array_push($payment_ratio_due_array, 1 / 12); + } + $payday_due_array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); for ($i = 0; $i < count($payment_ratio_due_array); $i++) { if ($i < count($payment_ratio_due_array) - 1) { diff --git a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php index 7122fbd3..d29650b2 100644 --- a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php @@ -41,12 +41,13 @@ result_array[ -function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract_type, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id){ +function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract_type, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id) +{ $bonus_array = []; - if ($ver == "2.1"){ + if ($ver == "2.1") { $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); #契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge) - switch ($contract_type){ + switch ($contract_type) { case "longcontract_m1_free_charge": #契約員獎金($sales_bonus) #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) @@ -54,57 +55,57 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract case ($discount >= 0.8): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.6; + $sales_bonus = ($fee_per_st) * 0.6; break; case ($fee_per_st > 300 and $fee_per_st <= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.7; - break; + $sales_bonus = ($fee_per_st) * 0.7; + break; case ($fee_per_st > 4000 and $fee_per_st <= 5000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.8; + $sales_bonus = ($fee_per_st) * 0.8; break; case ($fee_per_st > 5000 and $fee_per_st <= 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.9; - break; + $sales_bonus = ($fee_per_st) * 0.9; + break; case ($fee_per_st > 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 1.0; + $sales_bonus = ($fee_per_st) * 1.0; break; }; break; case ($discount >= 0.6 and $discount < 0.8): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.42; + $sales_bonus = ($fee_per_st) * 0.42; break; case ($fee_per_st > 300 and $fee_per_st <= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.49; - break; + $sales_bonus = ($fee_per_st) * 0.49; + break; case ($fee_per_st > 4000 and $fee_per_st <= 5000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.56; + $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st > 5000 and $fee_per_st <= 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.63; - break; + $sales_bonus = ($fee_per_st) * 0.63; + break; case ($fee_per_st > 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.7; + $sales_bonus = ($fee_per_st) * 0.7; break; }; break; case ($discount < 0.6): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.3; + $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st > 300 and $fee_per_st <= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.35; - break; + $sales_bonus = ($fee_per_st) * 0.35; + break; case ($fee_per_st > 4000 and $fee_per_st <= 5000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.4; + $sales_bonus = ($fee_per_st) * 0.4; break; case ($fee_per_st > 5000 and $fee_per_st <= 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.45; - break; + $sales_bonus = ($fee_per_st) * 0.45; + break; case ($fee_per_st > 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.5; + $sales_bonus = ($fee_per_st) * 0.5; break; }; break; @@ -116,81 +117,77 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract $regular_contract_manger_bonus = 300; break; }; - + #地區處長獎金、專任契約經理、契約員獎金 - switch ($payment_period_amount){ - #簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金 - #總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期, + switch ($payment_period_amount) { + #簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金 + #總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期, case $payment_period_amount >= 60: #地區處長獎金 - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "地區處長獎金", #獎金名稱 "bonus_receiver" => $region_director_id, #發放人員 "bonus_amount" => round($region_director_bonus), #金額 - "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 "bonus_regulation" => "訂金收回後次月發放" #發放規定 - ]); + ]); #專任契約經理獎金 - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "專任契約經理獎金", #獎金名稱 "bonus_receiver" => $regular_contract_manger_id, #發放人員 "bonus_amount" => round($regular_contract_manger_bonus), #金額 - "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 "bonus_regulation" => "訂金收回後次月發放" #發放規定 - ]); - + ]); + #產生契約員每個月的獎金應發比例 $payment_ratio_due_array = array(); for ($i = 0; $i < $payment_period_amount; $i++) { - array_push($payment_ratio_due_array, 1/$payment_period_amount); - } - + array_push($payment_ratio_due_array, 1 / $payment_period_amount); + } + $payday_due_array = array(); for ($i = 0; $i < $payment_period_amount; $i++) { - array_push($payday_due_array, $i+1 ); - } - - for($i = 0; $i < count($payment_ratio_due_array); $i++) { - if($i < count($payment_ratio_due_array) - 1){ + array_push($payday_due_array, $i + 1); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 - }else{ + } else { $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 - }; - array_push($bonus_array,[ + }; + array_push($bonus_array, [ "bonus_type" => "契約員獎金", #獎金名稱 "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")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 - ]); - } + ]); + } break; } - + $result_array = [ - "ver"=>$ver, #獎金版本 - "result_status"=>"success", #計算結果 - "bonus_array"=>$bonus_array #獎金水庫 + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 ]; - - }else{ - array_push($bonus_array,[ + } else { + array_push($bonus_array, [ "bonus_type" => "error", #獎金名稱 "bonus_receiver" => "error", #發放人員 "bonus_amount" => 0, #金額 "pay_day_due" => "9999-1-1", #預計發放時間 "bonus_regulation" => "error" #發放規定 - ]); + ]); $result_array = [ - "ver"=>$ver, #獎金版本 - "result_status"=>"error", #計算結果 - "bonus_array"=>$bonus_array #獎金水庫 - ]; + "ver" => $ver, #獎金版本 + "result_status" => "error", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; } - + return $result_array; }; - - -?> diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php index 253e8d54..5534b8eb 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) { + + $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 => $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; + if (!empty($option_results)) { + $result['option_price'] = 0; + // 電梯 OPTION 價格分別加到各台電梯 + foreach ($option_arr[$keys] 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) { + $item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數 + $result['option_price'] += intval($option['item_unit_price']) * $item_qty; + echo '2..'; + } else { + $result['option_price'] += $option['item_unit_price'] * intval($option['item_qty']); + echo '3..'; + } + echo '
';
+                    print_r($option['item_no'] . '--->' . $option['item_unit_price']);
+                    echo '
'; + } + + print_r($result['option_price']); + exit(); + } $note = explode(',', $result['note']); - $result['spec'] = $note[0]; //型號 + $result['spec'] = $note[0]; //型號 $result['person'] = $note[1]; // 人承 $result['floor'] = $note[2]; // 樓層 $result['speed'] = $note[3]; // 速度 @@ -82,21 +124,20 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont array_push($elevators_detail_arr, $result); } } + // print_r(COUNT($option_results)); + $count = COUNT($elevators_detail_arr); - $contract['elevators'] = $results; + $contract['elevators'] = $elevators_results; $contract['elevators_detail_arr'] = $elevators_detail_arr; $contract['nums'] = $count; - // echo '
';
-        // print_r($contract);
-        // echo '
'; - // exit; + $contractResponse = json_encode($contract); // 設定回應標頭為 JSON 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 29038b9f..d3ecf356 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -88,10 +88,10 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c if ($address == '') $fail_arr[] = '地址為必填'; if ($area == '') $fail_arr[] = '區域為必填'; if ($customer == '') $fail_arr[] = '客戶為必填'; - if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; - if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; - if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; - if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; + // if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; + // if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; + // if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; + // if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; if ($num == '') $fail_arr[] = '電梯數量為必填'; if ($payType == '') $fail_arr[] = '付款方式為必填'; if (count($fail_arr) > 0) { @@ -99,7 +99,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c echo json_encode($fail_arr); exit(); } - T8insert($_POST, $facilityno, $depId); + // T8insert($_POST, $facilityno, $depId); bonusCreate($_POST, $facilityno, $conn); //create account table $accounttype = "A"; @@ -127,7 +127,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':repairerid', $repairerid); $stmt->bindParam(':creater', $creater); $stmt->bindParam(':create_at', $create_at); - $stmt->execute(); + // $stmt->execute(); //create contract table @@ -163,7 +163,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':end_date', $end_date); $stmt->bindParam(':creater', $creater); $stmt->bindParam(':create_at', $create_at); - $stmt->execute(); + // $stmt->execute(); //create facility table // $createFacilityNo = new CreateFacilityNo(); @@ -238,7 +238,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':area', $area); $stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']); $stmt->bindParam(':licensedate', $ADuseful_date); - $result = $stmt->execute(); + // $result = $stmt->execute(); } //create schedule table @@ -259,7 +259,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':duedate', $combo[1]); $stmt->bindParam(':creater', $creater); $stmt->bindParam(':create_at', $create_at); - $result = $stmt->execute(); + // $result = $stmt->execute(); } } // create contract_b_signed_back table @@ -366,7 +366,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(":created_by", $user_id); $stmt->bindParam(':payType', $payType); - $stmt->execute(); + // $stmt->execute(); // T8insert($_POST, $facilityno); @@ -665,7 +665,7 @@ function bonusCreate($data, $facilityno, $conn) $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; @@ -689,7 +689,7 @@ function bonusCreate($data, $facilityno, $conn) $contract_type = $elevator['contract_type']; //合約類別 $payment_period = $payment[$payType]; //付款方式 $elevator_list_price = intval($elevator['stand_price']); //牌價 - $fee_per_st = $elevator['contract_price']; //作翻契約金額 + $fee_per_st = $elevator['sold_price']; //作翻契約金額 $commission_fee = $elevator['service_expense']; //服務費(月) $receivable_date_due = $payDay; //第一筆保養款項收回日 $sales_id = $salesman; //營業人員 @@ -722,6 +722,7 @@ function bonusCreate($data, $facilityno, $conn) $stmt->execute(); } } + // exit(); } // exit(); } catch (PDOException $e) { diff --git a/wms/contract/api/postNewContractData.php b/wms/contract/api/postNewContractData.php index d94dac12..6180e4d4 100644 --- a/wms/contract/api/postNewContractData.php +++ b/wms/contract/api/postNewContractData.php @@ -27,7 +27,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $elevators_nums = $_POST['nums']; $elevators = json_decode($_POST['elevators'], true); $elevators_detail_arr = json_decode($_POST['elevators_detail_arr'], true); - BounsCount($_POST, $conn); + // echo '
';
     // print_r($elevators);
     // echo '
'; @@ -54,12 +54,12 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c //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,9 +68,8 @@ 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 '
'; + + BounsCount($_POST, $conn, $facilityno); exit(); $conn->beginTransaction(); @@ -282,39 +281,63 @@ function T8Insert($data) } -function BounsCount($data, $conn) +function BounsCount($data, $conn, $facilityno) { // echo '
';
-  // print_r($data);
+  // print_r($facilityno);
   // 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'; + $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']; $type = $contractType[$contract_type]; //戰略客戶 or 一般客戶 - $elevator_knockdown_price = $data['price_total']; //受價總額 + // $elevator_knockdown_price = $data['price_total']; //受價總額 + $elevators = json_decode($data['elevators_detail_arr'], true); $salesman = $data['salesman']; $manager = $data['manager']; + + $result_bonus = []; + $result_bonus_arr = []; 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); + foreach ($elevators as $i => $elevator) { + + $elevator_knockdown_price = $elevator['item_price_ct']; + $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; + } } else if ($signing_date >= $bonus_v2_0_date) { $ver = '2.0'; - // $result_bonus = elevator_new_deal_bonus_v2_0($ver,$contract_type,); + foreach ($elevators as $i => $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); + } } - + // foreach ($elevators as $elevator) { + // $elevator_knockdown_price = $elevator['item_price_ct']; + // } echo '
';
-  print_r($result_bonus);
+  print_r($result_bonus_arr);
   echo '
'; exit(); try { diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 114cea2f..58acb4a8 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -111,7 +111,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -158,7 +158,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);

未填寫

- + - + - - + + - + diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index b2ad1eb9..db386702 100644 --- a/wms/contract/js/alpine.js +++ b/wms/contract/js/alpine.js @@ -1090,7 +1090,8 @@ const contractInput = () => { contract_type: '', manager: '', regular_contract_manger_id: '', - bonus_verson: '' + bonus_verson: '', + sold_price: '' }) } }, From 8408a410e63329e3e46c5b0cdc004b7a05849729 Mon Sep 17 00:00:00 2001 From: Cheng Date: Tue, 27 Feb 2024 17:37:18 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=9D=E9=A4=8A=E7=8D=8E=E9=87=91?= =?UTF-8?q?=E8=A8=88=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../other/maintenance_contract_bonus_v2_1.php | 24 +- ...enance_contract_bonus_v2_1_examination.php | 8 +- ...m_contract_m1_free_charge_bonus_v2_1_1.php | 312 ++++++++++++++++++ ..._m1_free_charge_bonus_v2_1_examination.php | 174 +++++++--- wms/contract/api/postContractData.php | 140 +++++++- wms/contract/contract-input.php | 54 +-- wms/contract/js/alpine.js | 55 +-- 7 files changed, 649 insertions(+), 118 deletions(-) create mode 100644 wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1.php b/wms/bonus/other/maintenance_contract_bonus_v2_1.php index 598202d4..27959883 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1.php @@ -45,7 +45,9 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, { $bonus_array = []; if ($ver == "2.1") { - $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); + // $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); + $discount = ($fee_per_st - $commission_fee) / $elevator_list_price; + #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) switch ($contract_type) { case "new": @@ -54,10 +56,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, switch ($discount) { case ($discount >= 0.8): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.6; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.7; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -70,10 +72,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, break; case ($discount >= 0.6 and $discount < 0.8): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.48; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -86,10 +88,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, break; case ($discount < 0.6): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.42; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.49; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -110,10 +112,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "free_to_charge": switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.3; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.35; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -131,10 +133,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "renew_priceissue": switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.25; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php b/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php index d68bdb7d..5b26e9c8 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php @@ -270,9 +270,9 @@ $examination_array = [ // echo '10、專任契約經理員工號($regular_contract_manger_id)
'; for ($i = 0; $i < count($examination_array); $i++) { - $fee_per_st = $examination_array[$i][3]; - $commission_fee = $examination_array[$i][5]; - $elevator_list_price = $examination_array[$i][4]; + $fee_per_st = $examination_array[$i][4]; //作番金額 + $commission_fee = $examination_array[$i][5]; // 服務費 + $elevator_list_price = $examination_array[$i][3]; // 牌價 $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); // echo "$fee_per_st - $commission_fee / $elevator_list_price "; @@ -314,7 +314,7 @@ for ($i = 0; $i < count($examination_array); $i++) { ]; echo "獎金版本:" . $result["ver"] . "
"; echo "計算結果:" . $result["result_status"] . "
"; - echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$examination_array[$i][2]] . "、牌價" . $examination_array[$i][3] . "元、簽約價" . $examination_array[$i][4] . "元、服務費600元(折扣率" . $discount . ")、契約人員 : " . $examination_array[$i][7] . "、區經理 : " . $examination_array[$i][8] . " 、契約經理 : " . $examination_array[$i][9] . "
"; + echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$examination_array[$i][2]] . "、牌價" . $examination_array[$i][3] . "元、簽約價" . $examination_array[$i][4] . "元、服務費" . $commission_fee . "元(折扣率" . $discount . ")、契約人員 : " . $examination_array[$i][7] . "、區經理 : " . $examination_array[$i][8] . " 、契約經理 : " . $examination_array[$i][9] . "
"; echo "輸入參數:" . $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] . "
"; 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 new file mode 100644 index 00000000..70a19f40 --- /dev/null +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php @@ -0,0 +1,312 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + + +function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($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 = '') +{ + $bonus_array = []; + if ($ver == "2.1") { + $discount = ($fee_per_st - $commission_fee) / $elevator_list_price; + #契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge) + switch ($contract_type) { + case "longcontract_m1_free_charge": + #契約員獎金($sales_bonus) + #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) + switch ($discount) { + case ($discount >= 0.8): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.6; + break; + case ($fee_per_st >= 3000 and $fee_per_st < 4000): + $sales_bonus = ($fee_per_st) * 0.7; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.8; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.9; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 1.0; + break; + }; + break; + case ($discount >= 0.6 and $discount < 0.8): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.42; + break; + case ($fee_per_st >= 3000 and $fee_per_st <= 4000): + $sales_bonus = ($fee_per_st) * 0.49; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.56; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.63; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 0.7; + break; + }; + break; + case ($discount < 0.6): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.3; + break; + case ($fee_per_st >= 3000 and $fee_per_st < 4000): + $sales_bonus = ($fee_per_st) * 0.35; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.4; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.45; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 0.5; + break; + }; + break; + }; + + #地區處長獎金($region_director_bonus) + $region_director_bonus = 170; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 300; + break; + }; + #付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) + array_push($bonus_array, [ + "bonus_type" => "地區處長獎金", #獎金名稱 + "bonus_receiver" => $region_director_id, #發放人員 + "bonus_amount" => round($region_director_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +12 months")), #預計發放時間 + "bonus_regulation" => "訂金收回後次月發放" #發放規定 + ]); + + #專任契約經理獎金 + if ($regular_contract_manger_id != '') { + array_push($bonus_array, [ + "bonus_type" => "專任契約經理獎金", #獎金名稱 + "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")), #預計發放時間 + "bonus_regulation" => "訂金收回後次月發放" #發放規定 + ]); + } + + #地區處長獎金、專任契約經理、契約員獎金 + switch ($payment_period) { + #簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金 + #總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期, + #年繳 + case 'annually': + $payment_ratio_due_array = array(); + $a = $payment_period_amount / 12; + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, $i + 1); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + + break; + #半年繳 + case 'semiannually': + $payment_ratio_due_array = array(); + $a = $payment_period_amount / 6; + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 6); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + #季繳 + case 'quarterly': + $a = $payment_period_amount / 3; + $payment_ratio_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 4); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + break; + #雙月繳 + case 'bimonthly': + $a = $payment_period_amount / 2; + $payment_ratio_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 2); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + break; + #月繳 + case 'monthly': + + #產生契約員每個月的獎金應發比例 + $payment_ratio_due_array = array(); + for ($i = 0; $i < $payment_period_amount; $i++) { + array_push($payment_ratio_due_array, 1 / $payment_period_amount); + } + + $payday_due_array = array(); + for ($i = 0; $i < $payment_period_amount; $i++) { + array_push($payday_due_array, $i + 1); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + } + + $result_array = [ + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + } else { + array_push($bonus_array, [ + "bonus_type" => "error", #獎金名稱 + "bonus_receiver" => "error", #發放人員 + "bonus_amount" => 0, #金額 + "pay_day_due" => "9999-1-1", #預計發放時間 + "bonus_regulation" => "error" #發放規定 + ]); + $result_array = [ + "ver" => $ver, #獎金版本 + "result_status" => "error", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + } + + return $result_array; +}; diff --git a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php index 0c42a890..3e0c3af0 100644 --- a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php @@ -40,62 +40,150 @@ result_array[ */ -require_once("maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php"); - -#$ver, $contract_type, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id - - +require_once("maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php"); #獎金測試 $examination_array = [ #錯誤版本 - ["1.0","longcontract_m1_free_charge",60,0.8,4000,333, "2014-07-01", "M0001", "M0002", "M0003"], + // ["1.0", 'annually', "longcontract_m1_free_charge", 60, 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #60期 - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) - + //付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 600, "2014-07-01", "M0001", "M0002"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 1200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 2200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 3200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 4200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 5200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 1230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 3000, 1230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 2230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 3230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 4230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 5230, "2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) + + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) ]; -for($i = 0; $i "契約員獎金", #獎金名稱 + // "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" => "每月收款後,按收款比率次月發放" #發放規定 + // ]); + // } + // echo '
';
+	// 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"] . "
"; echo "計算結果:" . $result["result_status"] . "
"; - echo "輸入參數:" . $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] . "
"; - for($j = 0; $j"; + echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][4] . " " + . $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7] . " " . $examination_array[$i][8] . " " + . $examination_array[$i][9] . "
"; + $n = 0; + for ($j = 0; $j < count($result["bonus_array"]); $j++) { + if ($result["bonus_array"][$j]["bonus_receiver"] == "M0001") { + + $n++; + echo '[' . $n . ']'; + } echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " " - . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["pay_day_due"] . " " - . $result["bonus_array"][$j]["bonus_regulation"] . "
"; + . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["pay_day_due"] . " " + . $result["bonus_array"][$j]["bonus_regulation"] . "
"; }; echo "-------------------------" . "
"; - }; - - -?> diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index d3ecf356..e8dca10f 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -88,10 +88,10 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c if ($address == '') $fail_arr[] = '地址為必填'; if ($area == '') $fail_arr[] = '區域為必填'; if ($customer == '') $fail_arr[] = '客戶為必填'; - // if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; - // if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; - // if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; - // if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; + if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; + if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; + if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; + if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; if ($num == '') $fail_arr[] = '電梯數量為必填'; if ($payType == '') $fail_arr[] = '付款方式為必填'; if (count($fail_arr) > 0) { @@ -100,7 +100,11 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c exit(); } // T8insert($_POST, $facilityno, $depId); - bonusCreate($_POST, $facilityno, $conn); + $aaa = bonusCreate($_POST, $facilityno, $conn); + echo '
';
+        print_r($aaa);
+        echo '
'; + exit; //create account table $accounttype = "A"; $accountid = $vat; @@ -658,10 +662,13 @@ 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']; @@ -676,28 +683,114 @@ function bonusCreate($data, $facilityno, $conn) 'A40005' => 'semiannually', // 半年繳 '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['sold_price']; //作翻契約金額 - $commission_fee = $elevator['service_expense']; //服務費(月) + $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) : ''; //作翻契約金額 (不含稅) + $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; + + 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; + } + // $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 = 0; $i < $maintain_months - 1; $i++) { + $contract_type = 'renew_priceissue'; + // 第二年以上改續約 + $result2 = 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 > 12 && $contract_type == 'renew_priceissue') { + // 超過一年的續約 + for ($i = 0; $i < $years; $i++) { + $contract_type = 'renew_priceissue'; + $result2 = 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'; + $result = 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, 'total' => $elevator_list_price, @@ -721,6 +814,21 @@ function bonusCreate($data, $facilityno, $conn) $stmt = $conn->prepare($sql); $stmt->execute(); } + if (!empty($result2)) { + foreach ($results2['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(); + } + } } // exit(); } diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 58acb4a8..cbec41c1 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -57,8 +57,8 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);

業務確認項

@@ -158,7 +158,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);

未填寫

- + - + + + + + - - - + + + + - - - - - - + + diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index db386702..ad56eb3b 100644 --- a/wms/contract/js/alpine.js +++ b/wms/contract/js/alpine.js @@ -1016,6 +1016,7 @@ const contractInput = () => { disabled: false, //資料庫是否有電梯數量資料 elevators: [], //機種、載重、人乘、樓停、樓層、速度、緯度、經度、開門方式、保養別、廠牌、竣檢日、許可證日期 payType: '', //付款方式 + contract_type: '' // bonus_verson: 2.1, // manager: '', // regular_contract_manger_id: '', @@ -1048,6 +1049,7 @@ const contractInput = () => { data.bonus_verson = 2.1; }, getManager() { + for (let i = 0; i < this.data.elevators.length; i++) { this.getBonusVerson(this.data.elevators[i]); axios.get('./api/getContractData.php?contracttype=accountManger&salesman=' + this.data.salesman).then(res => { @@ -1070,29 +1072,31 @@ const contractInput = () => { } }, createElevator() { - for (let i = 0; i < this.data.num; i++) { - this.data.elevators.push({ - spec: '', //規格 - weight: '', //載重 - speed: '', //速度 - persons: '', //人乘 - stop: '', //樓停 - floors: '', //樓層 - latitude: '', //緯度 - longitude: '', //經度 - elevator_brand: '', //廠牌 - opendoor: '', //開門方式 - maintainance: '', //保養別 - takecertificatedate: '', //竣檢日 - useful_date: '', //許可證有效日期 - maintain_times: '', //保養頻率 - discount: '', //折價率 - contract_type: '', - manager: '', - regular_contract_manger_id: '', - bonus_verson: '', - sold_price: '' - }) + if (this.data.num != this.data.elevators.length) { + for (let i = 0; i < this.data.num; i++) { + this.data.elevators.push({ + spec: '', //規格 + weight: '', //載重 + speed: '', //速度 + persons: '', //人乘 + stop: '', //樓停 + floors: '', //樓層 + latitude: '', //緯度 + longitude: '', //經度 + elevator_brand: '', //廠牌 + opendoor: '', //開門方式 + maintainance: '', //保養別 + takecertificatedate: '', //竣檢日 + useful_date: '', //許可證有效日期 + maintain_times: '', //保養頻率 + discount: '', //折價率 + // contract_type: '', + manager: '', + regular_contract_manger_id: '', + bonus_verson: '', + sold_price: '' + }) + } } }, getContractDate() { @@ -1109,7 +1113,7 @@ const contractInput = () => { this.data.total_price = Number(res.data.elevators[i].sold_price) + Number(this.data.total_price); // 服務費 (以單筆合約記,但計算獎金須傳入單月服務費) - this.data.elevators[i].service_expense = Math.round(this.data.elevators[i].service_expense / 12); + this.data.elevators[i].service_expense = Math.round(this.data.elevators[i].service_expense / res.data.elevators[i]); // 折扣率 this.data.elevators[i].discount = Math.round(((res.data.elevators[i].sold_price / res.data.elevators[i].stand_price) + this.data.elevators[i].service_expense) * 100); } @@ -1206,7 +1210,8 @@ const contractInput = () => { form.append('num', this.data.num); form.append('elevators', JSON.stringify(this.data.elevators)); form.append('contracttype', 'b'); - form.append('payType', this.data.payType) + form.append('payType', this.data.payType); + form.append('contract_type', this.data.contract_type); // 如果有附件檔案,可以逐一加入 for (var i = 0; i < this.data.files.length; i++) { From 2978a669f28606d6fdfaabb28b291e46bec6cee4 Mon Sep 17 00:00:00 2001 From: Cheng Date: Mon, 26 Feb 2024 18:02:29 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=96=B0=E6=A2=AF=E5=A5=91=E7=B4=84?= =?UTF-8?q?=E7=8D=8E=E9=87=91=E5=92=8C=E7=B0=BD=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wms/bonus/bonus.php | 18 ++- .../other/maintenance_contract_bonus_v2_1.php | 52 ++++--- ...erm_contract_m1_free_charge_bonus_v2_1.php | 127 +++++++++--------- wms/contract/api/getContractData.php | 59 ++++++-- wms/contract/api/postContractData.php | 25 ++-- wms/contract/api/postNewContractData.php | 63 ++++++--- wms/contract/contract-input.php | 20 +-- wms/contract/js/alpine.js | 3 +- 8 files changed, 222 insertions(+), 145 deletions(-) diff --git a/wms/bonus/bonus.php b/wms/bonus/bonus.php index 4e0b84fd..63bec621 100644 --- a/wms/bonus/bonus.php +++ b/wms/bonus/bonus.php @@ -32,15 +32,17 @@ 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 status IN (1,2,5)"; + $clause .= "AND a.status IN (1,2,5)"; } else if ($_GET['check'] == 2) { - $clause .= "AND status = 1"; + $clause .= "AND a.status = 1"; } else if ($_GET['check'] == 3) { - $clause .= "AND status IN (2,5)"; + $clause .= "AND a.status IN (2,5)"; } } -$sql = "SELECT * FROM bonus WHERE 1=1 $clause"; +$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"; $stmt = $conn->prepare($sql); $stmt->execute(); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -130,17 +132,21 @@ function isPay($contract_no, $connT8) btn-sm categoryBtn"> 未發獎金 btn-sm categoryBtn"> 已發獎金 btn-sm categoryBtn"> 人事發放作業 + btn-sm categoryBtn"> 獎金總計(人)
項次合約類別 合約號合約名稱 作番號 獎金類別 獎金版本
契約成交價 - +

未填寫

區域 @@ -374,28 +374,28 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); 獎金適用版本 - +
作番契約金額(月) 牌價(標準價) - +

標準價+Option價格+與其他電梯共同分擔的費用貨價格

服務費 - + 折扣率(%)折扣率(%)
(作番契約金額+服務費/台數) / 牌價 * 100
地區處長員工號 專任契約經理員工號
- - +
區域 @@ -201,7 +201,17 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
合約類別 + +
獎金適用版本
作番契約金額(月)
服務費 + + 牌價(標準價)

標準價+Option價格+與其他電梯共同分擔的費用貨價格

服務費 - - 折扣率(%)
(作番契約金額+服務費/台數) / 牌價 * 100
地區處長員工號 專任契約經理員工號
+ + + - + @@ -178,8 +184,8 @@ function isPay($contract_no, $connT8) ?> - + diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1.php b/wms/bonus/other/maintenance_contract_bonus_v2_1.php index 610da6d7..598202d4 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1.php @@ -55,48 +55,48 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case ($discount >= 0.8): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.6; + $sales_bonus = ($fee_per_st) * 0.6; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.7; + $sales_bonus = ($fee_per_st) * 0.7; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.8; + $sales_bonus = ($fee_per_st) * 0.8; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.9; + $sales_bonus = ($fee_per_st) * 0.9; break; }; break; case ($discount >= 0.6 and $discount < 0.8): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.48; + $sales_bonus = ($fee_per_st) * 0.48; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.56; + $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.64; + $sales_bonus = ($fee_per_st) * 0.64; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.72; + $sales_bonus = ($fee_per_st) * 0.72; break; }; break; case ($discount < 0.6): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.42; + $sales_bonus = ($fee_per_st) * 0.42; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.49; + $sales_bonus = ($fee_per_st) * 0.49; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.56; + $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.63; + $sales_bonus = ($fee_per_st) * 0.63; break; }; break; @@ -111,16 +111,16 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "free_to_charge": switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.3; + $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.35; + $sales_bonus = ($fee_per_st) * 0.35; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.4; + $sales_bonus = ($fee_per_st) * 0.4; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.45; + $sales_bonus = ($fee_per_st) * 0.45; break; }; #地區處長獎金($region_director_bonus) @@ -132,16 +132,16 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "renew_priceissue": switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.25; + $sales_bonus = ($fee_per_st) * 0.25; break; case ($fee_per_st >= 3001 and $fee_per_st <= 3499): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.3; + $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.35; + $sales_bonus = ($fee_per_st) * 0.35; break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.4; + $sales_bonus = ($fee_per_st) * 0.4; break; }; #地區處長獎金($region_director_bonus) @@ -226,7 +226,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, #2月1次 case "bimonthly": - $payment_ratio_due_array = array(0.166, 0.166, 0.166, 0.166, 0.166, 0.166); + $payment_ratio_due_array = array(); + for ($i = 0; $i < 6; $i++) { + array_push($payment_ratio_due_array, 1 / 6); + } $payday_due_array = array(1, 3, 5, 7, 9, 11); for ($i = 0; $i < count($payment_ratio_due_array); $i++) { if ($i < count($payment_ratio_due_array) - 1) { @@ -246,7 +249,12 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, #月付 case "monthly": - $payment_ratio_due_array = array(0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083); + $payment_ratio_due_array = array(); + // $payment_ratio_due_array = array(); + for ($i = 0; $i < 12; $i++) { + array_push($payment_ratio_due_array, 1 / 12); + } + $payday_due_array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); for ($i = 0; $i < count($payment_ratio_due_array); $i++) { if ($i < count($payment_ratio_due_array) - 1) { diff --git a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php index 7122fbd3..d29650b2 100644 --- a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php @@ -41,12 +41,13 @@ result_array[ -function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract_type, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id){ +function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract_type, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id) +{ $bonus_array = []; - if ($ver == "2.1"){ + if ($ver == "2.1") { $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); #契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge) - switch ($contract_type){ + switch ($contract_type) { case "longcontract_m1_free_charge": #契約員獎金($sales_bonus) #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) @@ -54,57 +55,57 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract case ($discount >= 0.8): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.6; + $sales_bonus = ($fee_per_st) * 0.6; break; case ($fee_per_st > 300 and $fee_per_st <= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.7; - break; + $sales_bonus = ($fee_per_st) * 0.7; + break; case ($fee_per_st > 4000 and $fee_per_st <= 5000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.8; + $sales_bonus = ($fee_per_st) * 0.8; break; case ($fee_per_st > 5000 and $fee_per_st <= 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.9; - break; + $sales_bonus = ($fee_per_st) * 0.9; + break; case ($fee_per_st > 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 1.0; + $sales_bonus = ($fee_per_st) * 1.0; break; }; break; case ($discount >= 0.6 and $discount < 0.8): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.42; + $sales_bonus = ($fee_per_st) * 0.42; break; case ($fee_per_st > 300 and $fee_per_st <= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.49; - break; + $sales_bonus = ($fee_per_st) * 0.49; + break; case ($fee_per_st > 4000 and $fee_per_st <= 5000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.56; + $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st > 5000 and $fee_per_st <= 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.63; - break; + $sales_bonus = ($fee_per_st) * 0.63; + break; case ($fee_per_st > 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.7; + $sales_bonus = ($fee_per_st) * 0.7; break; }; break; case ($discount < 0.6): switch ($fee_per_st) { case ($fee_per_st <= 3000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.3; + $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st > 300 and $fee_per_st <= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.35; - break; + $sales_bonus = ($fee_per_st) * 0.35; + break; case ($fee_per_st > 4000 and $fee_per_st <= 5000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.4; + $sales_bonus = ($fee_per_st) * 0.4; break; case ($fee_per_st > 5000 and $fee_per_st <= 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.45; - break; + $sales_bonus = ($fee_per_st) * 0.45; + break; case ($fee_per_st > 6000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.5; + $sales_bonus = ($fee_per_st) * 0.5; break; }; break; @@ -116,81 +117,77 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract $regular_contract_manger_bonus = 300; break; }; - + #地區處長獎金、專任契約經理、契約員獎金 - switch ($payment_period_amount){ - #簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金 - #總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期, + switch ($payment_period_amount) { + #簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金 + #總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期, case $payment_period_amount >= 60: #地區處長獎金 - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "地區處長獎金", #獎金名稱 "bonus_receiver" => $region_director_id, #發放人員 "bonus_amount" => round($region_director_bonus), #金額 - "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 "bonus_regulation" => "訂金收回後次月發放" #發放規定 - ]); + ]); #專任契約經理獎金 - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "專任契約經理獎金", #獎金名稱 "bonus_receiver" => $regular_contract_manger_id, #發放人員 "bonus_amount" => round($regular_contract_manger_bonus), #金額 - "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 "bonus_regulation" => "訂金收回後次月發放" #發放規定 - ]); - + ]); + #產生契約員每個月的獎金應發比例 $payment_ratio_due_array = array(); for ($i = 0; $i < $payment_period_amount; $i++) { - array_push($payment_ratio_due_array, 1/$payment_period_amount); - } - + array_push($payment_ratio_due_array, 1 / $payment_period_amount); + } + $payday_due_array = array(); for ($i = 0; $i < $payment_period_amount; $i++) { - array_push($payday_due_array, $i+1 ); - } - - for($i = 0; $i < count($payment_ratio_due_array); $i++) { - if($i < count($payment_ratio_due_array) - 1){ + array_push($payday_due_array, $i + 1); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 - }else{ + } else { $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 - }; - array_push($bonus_array,[ + }; + array_push($bonus_array, [ "bonus_type" => "契約員獎金", #獎金名稱 "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")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 - ]); - } + ]); + } break; } - + $result_array = [ - "ver"=>$ver, #獎金版本 - "result_status"=>"success", #計算結果 - "bonus_array"=>$bonus_array #獎金水庫 + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 ]; - - }else{ - array_push($bonus_array,[ + } else { + array_push($bonus_array, [ "bonus_type" => "error", #獎金名稱 "bonus_receiver" => "error", #發放人員 "bonus_amount" => 0, #金額 "pay_day_due" => "9999-1-1", #預計發放時間 "bonus_regulation" => "error" #發放規定 - ]); + ]); $result_array = [ - "ver"=>$ver, #獎金版本 - "result_status"=>"error", #計算結果 - "bonus_array"=>$bonus_array #獎金水庫 - ]; + "ver" => $ver, #獎金版本 + "result_status" => "error", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; } - + return $result_array; }; - - -?> diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php index 253e8d54..5534b8eb 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) { + + $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 => $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; + if (!empty($option_results)) { + $result['option_price'] = 0; + // 電梯 OPTION 價格分別加到各台電梯 + foreach ($option_arr[$keys] 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) { + $item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數 + $result['option_price'] += intval($option['item_unit_price']) * $item_qty; + echo '2..'; + } else { + $result['option_price'] += $option['item_unit_price'] * intval($option['item_qty']); + echo '3..'; + } + echo '
';
+                    print_r($option['item_no'] . '--->' . $option['item_unit_price']);
+                    echo '
'; + } + + print_r($result['option_price']); + exit(); + } $note = explode(',', $result['note']); - $result['spec'] = $note[0]; //型號 + $result['spec'] = $note[0]; //型號 $result['person'] = $note[1]; // 人承 $result['floor'] = $note[2]; // 樓層 $result['speed'] = $note[3]; // 速度 @@ -82,21 +124,20 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont array_push($elevators_detail_arr, $result); } } + // print_r(COUNT($option_results)); + $count = COUNT($elevators_detail_arr); - $contract['elevators'] = $results; + $contract['elevators'] = $elevators_results; $contract['elevators_detail_arr'] = $elevators_detail_arr; $contract['nums'] = $count; - // echo '
';
-        // print_r($contract);
-        // echo '
'; - // exit; + $contractResponse = json_encode($contract); // 設定回應標頭為 JSON 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 29038b9f..d3ecf356 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -88,10 +88,10 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c if ($address == '') $fail_arr[] = '地址為必填'; if ($area == '') $fail_arr[] = '區域為必填'; if ($customer == '') $fail_arr[] = '客戶為必填'; - if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; - if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; - if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; - if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; + // if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; + // if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; + // if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; + // if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; if ($num == '') $fail_arr[] = '電梯數量為必填'; if ($payType == '') $fail_arr[] = '付款方式為必填'; if (count($fail_arr) > 0) { @@ -99,7 +99,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c echo json_encode($fail_arr); exit(); } - T8insert($_POST, $facilityno, $depId); + // T8insert($_POST, $facilityno, $depId); bonusCreate($_POST, $facilityno, $conn); //create account table $accounttype = "A"; @@ -127,7 +127,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':repairerid', $repairerid); $stmt->bindParam(':creater', $creater); $stmt->bindParam(':create_at', $create_at); - $stmt->execute(); + // $stmt->execute(); //create contract table @@ -163,7 +163,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':end_date', $end_date); $stmt->bindParam(':creater', $creater); $stmt->bindParam(':create_at', $create_at); - $stmt->execute(); + // $stmt->execute(); //create facility table // $createFacilityNo = new CreateFacilityNo(); @@ -238,7 +238,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':area', $area); $stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']); $stmt->bindParam(':licensedate', $ADuseful_date); - $result = $stmt->execute(); + // $result = $stmt->execute(); } //create schedule table @@ -259,7 +259,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':duedate', $combo[1]); $stmt->bindParam(':creater', $creater); $stmt->bindParam(':create_at', $create_at); - $result = $stmt->execute(); + // $result = $stmt->execute(); } } // create contract_b_signed_back table @@ -366,7 +366,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(":created_by", $user_id); $stmt->bindParam(':payType', $payType); - $stmt->execute(); + // $stmt->execute(); // T8insert($_POST, $facilityno); @@ -665,7 +665,7 @@ function bonusCreate($data, $facilityno, $conn) $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; @@ -689,7 +689,7 @@ function bonusCreate($data, $facilityno, $conn) $contract_type = $elevator['contract_type']; //合約類別 $payment_period = $payment[$payType]; //付款方式 $elevator_list_price = intval($elevator['stand_price']); //牌價 - $fee_per_st = $elevator['contract_price']; //作翻契約金額 + $fee_per_st = $elevator['sold_price']; //作翻契約金額 $commission_fee = $elevator['service_expense']; //服務費(月) $receivable_date_due = $payDay; //第一筆保養款項收回日 $sales_id = $salesman; //營業人員 @@ -722,6 +722,7 @@ function bonusCreate($data, $facilityno, $conn) $stmt->execute(); } } + // exit(); } // exit(); } catch (PDOException $e) { diff --git a/wms/contract/api/postNewContractData.php b/wms/contract/api/postNewContractData.php index d94dac12..6180e4d4 100644 --- a/wms/contract/api/postNewContractData.php +++ b/wms/contract/api/postNewContractData.php @@ -27,7 +27,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $elevators_nums = $_POST['nums']; $elevators = json_decode($_POST['elevators'], true); $elevators_detail_arr = json_decode($_POST['elevators_detail_arr'], true); - BounsCount($_POST, $conn); + // echo '
';
     // print_r($elevators);
     // echo '
'; @@ -54,12 +54,12 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c //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,9 +68,8 @@ 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 '
'; + + BounsCount($_POST, $conn, $facilityno); exit(); $conn->beginTransaction(); @@ -282,39 +281,63 @@ function T8Insert($data) } -function BounsCount($data, $conn) +function BounsCount($data, $conn, $facilityno) { // echo '
';
-  // print_r($data);
+  // print_r($facilityno);
   // 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'; + $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']; $type = $contractType[$contract_type]; //戰略客戶 or 一般客戶 - $elevator_knockdown_price = $data['price_total']; //受價總額 + // $elevator_knockdown_price = $data['price_total']; //受價總額 + $elevators = json_decode($data['elevators_detail_arr'], true); $salesman = $data['salesman']; $manager = $data['manager']; + + $result_bonus = []; + $result_bonus_arr = []; 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); + foreach ($elevators as $i => $elevator) { + + $elevator_knockdown_price = $elevator['item_price_ct']; + $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; + } } else if ($signing_date >= $bonus_v2_0_date) { $ver = '2.0'; - // $result_bonus = elevator_new_deal_bonus_v2_0($ver,$contract_type,); + foreach ($elevators as $i => $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); + } } - + // foreach ($elevators as $elevator) { + // $elevator_knockdown_price = $elevator['item_price_ct']; + // } echo '
';
-  print_r($result_bonus);
+  print_r($result_bonus_arr);
   echo '
'; exit(); try { diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 114cea2f..58acb4a8 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -111,7 +111,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -158,7 +158,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);

未填寫

- + - + - - + + - + diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index b2ad1eb9..db386702 100644 --- a/wms/contract/js/alpine.js +++ b/wms/contract/js/alpine.js @@ -1090,7 +1090,8 @@ const contractInput = () => { contract_type: '', manager: '', regular_contract_manger_id: '', - bonus_verson: '' + bonus_verson: '', + sold_price: '' }) } }, From f1aca066250b6c8ca403801102a6fe36307d19d5 Mon Sep 17 00:00:00 2001 From: Cheng Date: Tue, 27 Feb 2024 17:37:18 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=9D=E9=A4=8A=E7=8D=8E=E9=87=91?= =?UTF-8?q?=E8=A8=88=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../other/maintenance_contract_bonus_v2_1.php | 24 +- ...enance_contract_bonus_v2_1_examination.php | 8 +- ...m_contract_m1_free_charge_bonus_v2_1_1.php | 312 ++++++++++++++++++ ..._m1_free_charge_bonus_v2_1_examination.php | 174 +++++++--- wms/contract/api/postContractData.php | 140 +++++++- wms/contract/contract-input.php | 54 +-- wms/contract/js/alpine.js | 55 +-- 7 files changed, 649 insertions(+), 118 deletions(-) create mode 100644 wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1.php b/wms/bonus/other/maintenance_contract_bonus_v2_1.php index 598202d4..27959883 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1.php @@ -45,7 +45,9 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, { $bonus_array = []; if ($ver == "2.1") { - $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); + // $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); + $discount = ($fee_per_st - $commission_fee) / $elevator_list_price; + #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) switch ($contract_type) { case "new": @@ -54,10 +56,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, switch ($discount) { case ($discount >= 0.8): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.6; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.7; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -70,10 +72,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, break; case ($discount >= 0.6 and $discount < 0.8): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.48; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -86,10 +88,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, break; case ($discount < 0.6): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.42; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.49; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -110,10 +112,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "free_to_charge": switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.3; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.35; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -131,10 +133,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "renew_priceissue": switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.25; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php b/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php index d68bdb7d..5b26e9c8 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php @@ -270,9 +270,9 @@ $examination_array = [ // echo '10、專任契約經理員工號($regular_contract_manger_id)
'; for ($i = 0; $i < count($examination_array); $i++) { - $fee_per_st = $examination_array[$i][3]; - $commission_fee = $examination_array[$i][5]; - $elevator_list_price = $examination_array[$i][4]; + $fee_per_st = $examination_array[$i][4]; //作番金額 + $commission_fee = $examination_array[$i][5]; // 服務費 + $elevator_list_price = $examination_array[$i][3]; // 牌價 $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); // echo "$fee_per_st - $commission_fee / $elevator_list_price "; @@ -314,7 +314,7 @@ for ($i = 0; $i < count($examination_array); $i++) { ]; echo "獎金版本:" . $result["ver"] . "
"; echo "計算結果:" . $result["result_status"] . "
"; - echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$examination_array[$i][2]] . "、牌價" . $examination_array[$i][3] . "元、簽約價" . $examination_array[$i][4] . "元、服務費600元(折扣率" . $discount . ")、契約人員 : " . $examination_array[$i][7] . "、區經理 : " . $examination_array[$i][8] . " 、契約經理 : " . $examination_array[$i][9] . "
"; + echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$examination_array[$i][2]] . "、牌價" . $examination_array[$i][3] . "元、簽約價" . $examination_array[$i][4] . "元、服務費" . $commission_fee . "元(折扣率" . $discount . ")、契約人員 : " . $examination_array[$i][7] . "、區經理 : " . $examination_array[$i][8] . " 、契約經理 : " . $examination_array[$i][9] . "
"; echo "輸入參數:" . $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] . "
"; 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 new file mode 100644 index 00000000..70a19f40 --- /dev/null +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php @@ -0,0 +1,312 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + + +function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($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 = '') +{ + $bonus_array = []; + if ($ver == "2.1") { + $discount = ($fee_per_st - $commission_fee) / $elevator_list_price; + #契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge) + switch ($contract_type) { + case "longcontract_m1_free_charge": + #契約員獎金($sales_bonus) + #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) + switch ($discount) { + case ($discount >= 0.8): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.6; + break; + case ($fee_per_st >= 3000 and $fee_per_st < 4000): + $sales_bonus = ($fee_per_st) * 0.7; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.8; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.9; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 1.0; + break; + }; + break; + case ($discount >= 0.6 and $discount < 0.8): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.42; + break; + case ($fee_per_st >= 3000 and $fee_per_st <= 4000): + $sales_bonus = ($fee_per_st) * 0.49; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.56; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.63; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 0.7; + break; + }; + break; + case ($discount < 0.6): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.3; + break; + case ($fee_per_st >= 3000 and $fee_per_st < 4000): + $sales_bonus = ($fee_per_st) * 0.35; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.4; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.45; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 0.5; + break; + }; + break; + }; + + #地區處長獎金($region_director_bonus) + $region_director_bonus = 170; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 300; + break; + }; + #付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) + array_push($bonus_array, [ + "bonus_type" => "地區處長獎金", #獎金名稱 + "bonus_receiver" => $region_director_id, #發放人員 + "bonus_amount" => round($region_director_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +12 months")), #預計發放時間 + "bonus_regulation" => "訂金收回後次月發放" #發放規定 + ]); + + #專任契約經理獎金 + if ($regular_contract_manger_id != '') { + array_push($bonus_array, [ + "bonus_type" => "專任契約經理獎金", #獎金名稱 + "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")), #預計發放時間 + "bonus_regulation" => "訂金收回後次月發放" #發放規定 + ]); + } + + #地區處長獎金、專任契約經理、契約員獎金 + switch ($payment_period) { + #簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金 + #總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期, + #年繳 + case 'annually': + $payment_ratio_due_array = array(); + $a = $payment_period_amount / 12; + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, $i + 1); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + + break; + #半年繳 + case 'semiannually': + $payment_ratio_due_array = array(); + $a = $payment_period_amount / 6; + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 6); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + #季繳 + case 'quarterly': + $a = $payment_period_amount / 3; + $payment_ratio_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 4); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + break; + #雙月繳 + case 'bimonthly': + $a = $payment_period_amount / 2; + $payment_ratio_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 2); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + break; + #月繳 + case 'monthly': + + #產生契約員每個月的獎金應發比例 + $payment_ratio_due_array = array(); + for ($i = 0; $i < $payment_period_amount; $i++) { + array_push($payment_ratio_due_array, 1 / $payment_period_amount); + } + + $payday_due_array = array(); + for ($i = 0; $i < $payment_period_amount; $i++) { + array_push($payday_due_array, $i + 1); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + } + + $result_array = [ + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + } else { + array_push($bonus_array, [ + "bonus_type" => "error", #獎金名稱 + "bonus_receiver" => "error", #發放人員 + "bonus_amount" => 0, #金額 + "pay_day_due" => "9999-1-1", #預計發放時間 + "bonus_regulation" => "error" #發放規定 + ]); + $result_array = [ + "ver" => $ver, #獎金版本 + "result_status" => "error", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + } + + return $result_array; +}; diff --git a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php index 0c42a890..3e0c3af0 100644 --- a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php @@ -40,62 +40,150 @@ result_array[ */ -require_once("maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php"); - -#$ver, $contract_type, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id - - +require_once("maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php"); #獎金測試 $examination_array = [ #錯誤版本 - ["1.0","longcontract_m1_free_charge",60,0.8,4000,333, "2014-07-01", "M0001", "M0002", "M0003"], + // ["1.0", 'annually', "longcontract_m1_free_charge", 60, 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #60期 - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) - + //付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 600, "2014-07-01", "M0001", "M0002"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 1200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 2200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 3200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 4200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 5200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 1230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 3000, 1230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 2230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 3230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 4230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 5230, "2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) + + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) ]; -for($i = 0; $i "契約員獎金", #獎金名稱 + // "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" => "每月收款後,按收款比率次月發放" #發放規定 + // ]); + // } + // echo '
';
+	// 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"] . "
"; echo "計算結果:" . $result["result_status"] . "
"; - echo "輸入參數:" . $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] . "
"; - for($j = 0; $j"; + echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][4] . " " + . $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7] . " " . $examination_array[$i][8] . " " + . $examination_array[$i][9] . "
"; + $n = 0; + for ($j = 0; $j < count($result["bonus_array"]); $j++) { + if ($result["bonus_array"][$j]["bonus_receiver"] == "M0001") { + + $n++; + echo '[' . $n . ']'; + } echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " " - . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["pay_day_due"] . " " - . $result["bonus_array"][$j]["bonus_regulation"] . "
"; + . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["pay_day_due"] . " " + . $result["bonus_array"][$j]["bonus_regulation"] . "
"; }; echo "-------------------------" . "
"; - }; - - -?> diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index d3ecf356..e8dca10f 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -88,10 +88,10 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c if ($address == '') $fail_arr[] = '地址為必填'; if ($area == '') $fail_arr[] = '區域為必填'; if ($customer == '') $fail_arr[] = '客戶為必填'; - // if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; - // if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; - // if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; - // if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; + if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; + if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; + if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; + if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; if ($num == '') $fail_arr[] = '電梯數量為必填'; if ($payType == '') $fail_arr[] = '付款方式為必填'; if (count($fail_arr) > 0) { @@ -100,7 +100,11 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c exit(); } // T8insert($_POST, $facilityno, $depId); - bonusCreate($_POST, $facilityno, $conn); + $aaa = bonusCreate($_POST, $facilityno, $conn); + echo '
';
+        print_r($aaa);
+        echo '
'; + exit; //create account table $accounttype = "A"; $accountid = $vat; @@ -658,10 +662,13 @@ 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']; @@ -676,28 +683,114 @@ function bonusCreate($data, $facilityno, $conn) 'A40005' => 'semiannually', // 半年繳 '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['sold_price']; //作翻契約金額 - $commission_fee = $elevator['service_expense']; //服務費(月) + $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) : ''; //作翻契約金額 (不含稅) + $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; + + 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; + } + // $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 = 0; $i < $maintain_months - 1; $i++) { + $contract_type = 'renew_priceissue'; + // 第二年以上改續約 + $result2 = 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 > 12 && $contract_type == 'renew_priceissue') { + // 超過一年的續約 + for ($i = 0; $i < $years; $i++) { + $contract_type = 'renew_priceissue'; + $result2 = 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'; + $result = 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, 'total' => $elevator_list_price, @@ -721,6 +814,21 @@ function bonusCreate($data, $facilityno, $conn) $stmt = $conn->prepare($sql); $stmt->execute(); } + if (!empty($result2)) { + foreach ($results2['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(); + } + } } // exit(); } diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 58acb4a8..cbec41c1 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -57,8 +57,8 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);

業務確認項

@@ -158,7 +158,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);

未填寫

- + - + + + + + - - - + + + + - - - - - - + + diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index db386702..ad56eb3b 100644 --- a/wms/contract/js/alpine.js +++ b/wms/contract/js/alpine.js @@ -1016,6 +1016,7 @@ const contractInput = () => { disabled: false, //資料庫是否有電梯數量資料 elevators: [], //機種、載重、人乘、樓停、樓層、速度、緯度、經度、開門方式、保養別、廠牌、竣檢日、許可證日期 payType: '', //付款方式 + contract_type: '' // bonus_verson: 2.1, // manager: '', // regular_contract_manger_id: '', @@ -1048,6 +1049,7 @@ const contractInput = () => { data.bonus_verson = 2.1; }, getManager() { + for (let i = 0; i < this.data.elevators.length; i++) { this.getBonusVerson(this.data.elevators[i]); axios.get('./api/getContractData.php?contracttype=accountManger&salesman=' + this.data.salesman).then(res => { @@ -1070,29 +1072,31 @@ const contractInput = () => { } }, createElevator() { - for (let i = 0; i < this.data.num; i++) { - this.data.elevators.push({ - spec: '', //規格 - weight: '', //載重 - speed: '', //速度 - persons: '', //人乘 - stop: '', //樓停 - floors: '', //樓層 - latitude: '', //緯度 - longitude: '', //經度 - elevator_brand: '', //廠牌 - opendoor: '', //開門方式 - maintainance: '', //保養別 - takecertificatedate: '', //竣檢日 - useful_date: '', //許可證有效日期 - maintain_times: '', //保養頻率 - discount: '', //折價率 - contract_type: '', - manager: '', - regular_contract_manger_id: '', - bonus_verson: '', - sold_price: '' - }) + if (this.data.num != this.data.elevators.length) { + for (let i = 0; i < this.data.num; i++) { + this.data.elevators.push({ + spec: '', //規格 + weight: '', //載重 + speed: '', //速度 + persons: '', //人乘 + stop: '', //樓停 + floors: '', //樓層 + latitude: '', //緯度 + longitude: '', //經度 + elevator_brand: '', //廠牌 + opendoor: '', //開門方式 + maintainance: '', //保養別 + takecertificatedate: '', //竣檢日 + useful_date: '', //許可證有效日期 + maintain_times: '', //保養頻率 + discount: '', //折價率 + // contract_type: '', + manager: '', + regular_contract_manger_id: '', + bonus_verson: '', + sold_price: '' + }) + } } }, getContractDate() { @@ -1109,7 +1113,7 @@ const contractInput = () => { this.data.total_price = Number(res.data.elevators[i].sold_price) + Number(this.data.total_price); // 服務費 (以單筆合約記,但計算獎金須傳入單月服務費) - this.data.elevators[i].service_expense = Math.round(this.data.elevators[i].service_expense / 12); + this.data.elevators[i].service_expense = Math.round(this.data.elevators[i].service_expense / res.data.elevators[i]); // 折扣率 this.data.elevators[i].discount = Math.round(((res.data.elevators[i].sold_price / res.data.elevators[i].stand_price) + this.data.elevators[i].service_expense) * 100); } @@ -1206,7 +1210,8 @@ const contractInput = () => { form.append('num', this.data.num); form.append('elevators', JSON.stringify(this.data.elevators)); form.append('contracttype', 'b'); - form.append('payType', this.data.payType) + form.append('payType', this.data.payType); + form.append('contract_type', this.data.contract_type); // 如果有附件檔案,可以逐一加入 for (var i = 0; i < this.data.files.length; i++) { From 2f1afae09efd6727eb526049573a39fb72ae6b8c Mon Sep 17 00:00:00 2001 From: Cheng Date: Thu, 29 Feb 2024 20:14:00 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=96=B0=E6=A2=AF=E3=80=81=E4=BF=9D?= =?UTF-8?q?=E9=A4=8A=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); + } +} + +?> +
+ +
項次合約類別 合約號合約名稱 作番號 獎金類別 獎金版本
契約成交價 - +

未填寫

區域 @@ -374,28 +374,28 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); 獎金適用版本 - +
作番契約金額(月) 牌價(標準價) - +

標準價+Option價格+與其他電梯共同分擔的費用貨價格

服務費 - + 折扣率(%)折扣率(%)
(作番契約金額+服務費/台數) / 牌價 * 100
地區處長員工號 專任契約經理員工號
- - +
區域 @@ -201,7 +201,17 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
合約類別 + +
獎金適用版本
作番契約金額(月)
服務費 + + 牌價(標準價)

標準價+Option價格+與其他電梯共同分擔的費用貨價格

服務費 - - 折扣率(%)
(作番契約金額+服務費/台數) / 牌價 * 100
地區處長員工號 專任契約經理員工號
+ + + + + + +
+

月份、個人獎金計算

+
+
+ + + + + + + + + + + + +
年份 + + 月份 + +
+ + +
+ + + + + + + + + + + + + $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); - - - + - - - -

輸入地址以獲取經緯度

- - - - -
- - - \ No newline at end of file +// [ +// { +// //salSalesOrder +// "name": "MainSalesOrder", +// "rows": [ +// { +// "BillNo": "Z001", //合約單號 +// "BillDate": 20210420, //簽約日期 +// "TypeId": "SO", // +// "FOrgId": "1000", +// "OrgId": "1000", +// "ModeId": "T", // T汰改 M新梯 +// "BizPartnerId": "M0225", //創建人ID +// "CurrId": "TWD", +// "CurrOAmount": 1, +// "CurrLAmount": 1, +// "PersonId": "M0225", //業務人員 +// "DueToId": "512", //業務部門 +// "TradeConditionId": "", +// "TaxId": "ST005", +// "CreditorCompId": "1000", +// "CreditorOrgId": "1000", +// "CreditorCurrOAmount": 1, +// "CreditorCurrLAmount": 1, +// "CompId": "1000" +// } +// ] +// }, +// { +// //salSalesOrderDetail +// "name": "SubOrder", +// "rows": [ +// { +// "SupplyCompId": "1001", +// "SupplyOrgId": "1000", +// "TaxId": "ST005", +// "RequirementDate": 20210420, //出貨日期 +// "ConsignmentDate": 20210420, //發貨日期 +// "DispatchCompId": "1001", +// "DispatchOrgId": "1000", +// "BillNo": "Z001", //合約號 +// "RowCode": 1, //全部筆數排列 +// "ItemType": 0, +// "MaterialId": "Z001", //作番號 +// "SUnitId": "SET", +// "SQuantity": 1, //交易數量 +// "SPrice": 1 //交易價格 +// } +// ] +// }, +// { +// "name": "salOrderStagePay", +// "rows": [ +// { +// "BillNo": "", +// "RowCode": "", +// "RowNo": "", +// "PayStage": "ST003", //收款階段 +// "PlanPercentage": "Z001", //計劃收款比例(%) +// "PlanPayAmt": 1, //計劃收款金額 +// "PlanPayDate": 1, //計劃收款日期 1.第一筆都是簽約日 +// "UnWriteOffOAmount": 1 //未核銷金額 +// } +// ] +// } +// ] +require_once("../../T8_Authorization_from_bpm.php"); + +$api_url = "https://erp.masada.com.tw:780/twWebAPI/V1/SALSALESORDER/PostERPData"; + +$validation = get_Auth(); + +$MainSalesOrder_row = [ + "BillNo" => "M24020076", //合約單號 + "BillDate" => 20210420, //簽約日期 + "TypeId" => "SO", // + "FOrgId" => "1000", + "OrgId" => "1000", + "ModeId" => "M", // T汰改 M新梯 + "BizPartnerId" => "M24020076", //客戶代碼 + "CurrId" => "TWD", + "CurrOAmount" => 1, + "CurrLAmount" => 1, + "PersonId" => "M0225", //業務人員 + "DueToId" => "M24020076", //債務方 + "TradeConditionId" => "", + "TaxId" => "ST005", + "CreditorCompId" => "1001", + "CreditorOrgId" => "1000", + // "CompId" => "1001", + // "CreditorCurrOAmount" => 1, + // "CreditorCurrLAmount" => 1 +]; +// //salSalesOrderDetail +// $SubOrder_row = []; +for ($i = 0; $i < 3; $i++) { + if ($i == 0) { + $row = [ + // "SupplyCompId" => "1001", + // "SupplyOrgId" => "1000", + "TaxId" => "ST005", + "RequirementDate" => 20210420, //出貨日期 + "ConsignmentDate" => 20210420, //發貨日期 + // "DispatchCompId" => "1001", + // "DispatchOrgId" => "1000", + "BillNo" => "M24020076", //合約號 + "RowCode" => $i, //全部筆數排列 + "ItemType" => 1, + "MaterialId" => "A40001", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) + "SUnitId" => "SET", + "SQuantity" => 1, //交易數量 + "SPrice" => 50000 //交易價格 + ]; + } + if ($i == 1) { + $row = [ + // "SupplyCompId" => "1001", + // "SupplyOrgId" => "1000", + "TaxId" => "ST005", + "RequirementDate" => 20210420, //出貨日期 + "ConsignmentDate" => 20210420, //發貨日期 + // "DispatchCompId" => "1001", + // "DispatchOrgId" => "1000", + "BillNo" => "M24020076", //合約號 + "RowCode" => $i, //全部筆數排列 + "ItemType" => 1, + "MaterialId" => "A40008", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) + "SUnitId" => "SET", + "SQuantity" => 1, //交易數量 + "SPrice" => 700000 //交易價格 + ]; + } + if ($i == 2) { + $row = [ + // "SupplyCompId" => "1001", + // "SupplyOrgId" => "1000", + "TaxId" => "ST005", + "RequirementDate" => 20210420, //出貨日期 + "ConsignmentDate" => 20210420, //發貨日期 + // "DispatchCompId" => "1001", + // "DispatchOrgId" => "1000", + "BillNo" => "M24020076", //合約號 + "RowCode" => $i, //全部筆數排列 + "ItemType" => 0, + "MaterialId" => "4MH00669", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) + "SUnitId" => "SET", + "SQuantity" => 1, //交易數量 + "SPrice" => 0 //交易價格 + ]; + } + $SubOrder_row[] = $row; +} + +// // $salOrderStagePay_row = []; +// // // for ($i = 0; $i < 2; $i) { +// // // if ($i == 0) { +// // // $row = [ +// // // "BillNo" => "M24010201", +// // // "RowCode" => 1, +// // // "RowNo" => 1, +// // // "PayStage" => "簽約", //收款階段 +// // // "PlanPercentage" => 0.10, //計劃收款比例(%) +// // // "PlanPayAmt" => 100000, //計劃收款金額 +// // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 +// // // "UnWriteOffOAmount" => 100000 //未核銷金額 +// // // ]; +// // // } +// // // if ($i == 1) { +// // // $row = [ +// // // "BillNo" => "M24010201", +// // // "RowCode" => 1, +// // // "RowNo" => 1, +// // // "PayStage" => "貨抵工地", //收款階段 +// // // "PlanPercentage" => 0.40, //計劃收款比例(%) +// // // "PlanPayAmt" => 100000, //計劃收款金額 +// // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 +// // // "UnWriteOffOAmount" => 100000 //未核銷金額 +// // // ]; +// // // } +// // // if ($i == 2) { +// // // $row = [ +// // // "BillNo" => "M24010201", +// // // "RowCode" => 1, +// // // "RowNo" => 1, +// // // "PayStage" => "試車完工", //收款階段 +// // // "PlanPercentage" => 0.30, //計劃收款比例(%) +// // // "PlanPayAmt" => 100000, //計劃收款金額 +// // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 +// // // "UnWriteOffOAmount" => 100000 //未核銷金額 +// // // ]; +// // // } +// // // if ($i == 3) { +// // // $row = [ +// // // "BillNo" => "M24010201", +// // // "RowCode" => 1, +// // // "RowNo" => 1, +// // // "PayStage" => "交車", //收款階段 +// // // "PlanPercentage" => 0.20, //計劃收款比例(%) +// // // "PlanPayAmt" => 100000, //計劃收款金額 +// // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 +// // // "UnWriteOffOAmount" => 100000 //未核銷金額 +// // // ]; +// // // } +// // // $salOrderStagePay_row[] = $row; +// // // } +$salOrderStagePay_row = []; +$roww = [ + "PayStage" => "簽約", //收款階段 + "PlanPercentage" => 0.5, //計劃收款比例(%) + "PlanPayAmt" => 375000, //計劃收款金額 + "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 + "BillNo" => "M24020076", + "RowCode" => 1, + "RowNo" => 1, + "UnWriteOffOAmount" => 375000 //未核銷金額 +]; +$roww2 = [ + "PayStage" => "貨抵工地", + "PlanPercentage" => 0.5, + "PlanPayAmt" => 375000, + "PlanPayDate" => 20240101, + "BillNo" => "M24020076", + "RowCode" => 2, + "RowNo" => 2, + "UnWriteOffOAmount" => 375000 +]; +$salOrderStagePay_row[] = $roww; + +$MainSalesOrder = [ + "name" => "MainSalesOrder", + 'rows' => [$MainSalesOrder_row] +]; +$SubOrder = [ + "name" => "SubOrder", + "rows" => $SubOrder_row +]; +$salOrderStagePay = [ + "name" => "salOrderStagePay", + "rows" => $salOrderStagePay_row +]; + +$APIbody = []; +$APIbody[] = $MainSalesOrder; +$APIbody[] = $SubOrder; +$APIbody[] = $salOrderStagePay; +// $data = file_get_contents('test copy.json'); +// $arr = json_decode($data, true); +// echo "
";
+// 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 10ef98d8..92aaf7d0 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -452,8 +452,11 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); - + + + \ No newline at end of file diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index 4c4d6d36..104ab4f7 100644 --- a/wms/contract/js/alpine.js +++ b/wms/contract/js/alpine.js @@ -810,7 +810,7 @@ const contractNewInput = () => { return { init() { }, data: { - contractno: 'M24020029', + contractno: 'M24020076', customer: '', manager: '', vat: '', @@ -827,6 +827,7 @@ const contractNewInput = () => { signing_date: '', //合約簽訂日期 elevators: [], // 電梯種類 Array elevators_detail_arr: [], // 電梯台數 Array + pay_arr: [], //電梯付款種類 nums: 0, //電梯數量 }, step: 1, @@ -902,6 +903,7 @@ const contractNewInput = () => { this.data.elevators = res.data.elevators; this.data.elevators_detail_arr = res.data.elevators_detail_arr; this.data.nums = res.data.nums; + this.data.pay_arr = res.data.pay_arr; } this.step = 2 this.isLoading = false @@ -929,6 +931,7 @@ const contractNewInput = () => { form.append('contract_type', this.data.contract_type); form.append('elevators_detail_arr', JSON.stringify(this.data.elevators_detail_arr)); form.append('elevators', JSON.stringify(this.data.elevators)); + form.append('pay_arr', JSON.stringify(this.data.pay_arr)); form.append('contracttype', 'm'); form.append('user_id', user_id); for (var i = 0; i < this.data.files.length; i++) { From 79d4fecce6acc8d90dec812cf475969e2ab64faa Mon Sep 17 00:00:00 2001 From: Cheng Date: Mon, 4 Mar 2024 20:25:19 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=96=B0=E6=A2=AF=E3=80=81=E4=BF=9D?= =?UTF-8?q?=E9=A4=8A=E7=B0=BD=E5=9B=9E&=E7=8D=8E=E9=87=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elevator_new_deal_bonus_v2_0.php | 73 +- ...evator_new_deal_bonus_v2_0_examination.php | 121 +-- wms/contract/api/T8api.php | 2 +- wms/contract/api/getContractData.php | 15 - wms/contract/api/postContractData.php | 1 + wms/contract/api/postNewContractData.php | 761 +++++++++++------- wms/contract/api/test copy.json | 407 ++++++++-- wms/contract/api/test.json | 2 +- wms/contract/api/testT8API.php | 127 ++- wms/contract/contract-newelevator-input.php | 14 +- wms/contract/js/alpine.js | 13 +- 11 files changed, 989 insertions(+), 547 deletions(-) diff --git a/wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0.php b/wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0.php index 84dde3cd..15f87514 100644 --- a/wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0.php +++ b/wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0.php @@ -35,13 +35,14 @@ result_array[ -function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $sales_id, $region_manger_id){ +function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $sales_id, $region_manger_id) +{ $bonus_array = []; - if ($ver == "2.0"){ + if ($ver == "2.0") { $discount = round($elevator_knockdown_price / $elevator_list_price, 3); #銷售點數,取到小數點第三位。 - + #合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer) - switch ($contract_type){ + switch ($contract_type) { case "strategy_customer": #契約員獎金($sales_bonus) $sales_bonus = $elevator_knockdown_price * 0.007; @@ -51,7 +52,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele case "general_customer": switch ($elevator_type) { - #客梯(passenger)、貨梯(cargo) + #客梯(passenger)、貨梯(cargo) case ($elevator_type == "passenger" or $elevator_type == "cargo"): switch ($discount) { case ($discount >= 1.0): @@ -62,14 +63,14 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele break; case ($discount >= 0.75 and $discount < 0.9): $sales_bonus = $elevator_knockdown_price * 0.015; - break; + break; case ($discount < 0.75): $sales_bonus = $elevator_knockdown_price * 0.008; - break; + break; }; - break; - - #小電梯(dumbwaiter)、平台梯(flatbase)、強驅(positive_drive) + break; + + #小電梯(dumbwaiter)、平台梯(flatbase)、強驅(positive_drive) case ($elevator_type == "dumbwaiter" or $elevator_type == "flatbase" or $elevator_type == "positive_drive"): switch ($discount) { case ($discount >= 1.0): @@ -80,7 +81,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele break; case ($discount >= 0.72 and $discount < 0.9): $sales_bonus = $elevator_knockdown_price * 0.015; - break; + break; case ($discount < 0.72): $sales_bonus = $elevator_knockdown_price * 0.008; break; @@ -91,74 +92,72 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele $region_manager_bonus = 600; break; }; - + #營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.2), #金額 "payment_schedul_due" => "deposit", #訂金已收款20% "payment_schedul_regulation" => "訂金已收款20%,發放總獎金20%" #發放規定 ]); - + #營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.5), #金額 "payment_schedul_due" => "shipping", #訂金已收款20% "payment_schedul_regulation" => "出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%" #發放規定 - ]); - + ]); + #營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus * 0.3), #金額 "payment_schedul_due" => "acceptance", #訂金已收款20% "payment_schedul_regulation" => "驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%" #發放規定 - ]); + ]); #區域經理提成獎金水庫-----訂金已收款100%,發放總獎金50% - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 "bonus_receiver" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_bonus * 0.5), #金額 "payment_schedul_due" => "deposit", #訂金已收款100% "payment_schedul_regulation" => "訂金已收款100%,發放總獎金50%" #發放規定 - ]); - + ]); + #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 "bonus_receiver" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_bonus * 0.5), #金額 "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100% "payment_schedul_regulation" => "貨到工地款(含)之前所有款項已收款100%,發放總獎金50%" #發放規定 - ]); + ]); $result_array = [ - "ver"=>$ver, #獎金版本 - "result_status"=>"success", #計算結果 - "bonus_array"=>$bonus_array #獎金水庫 - ]; - }else{ - array_push($bonus_array,[ + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + } else { + array_push($bonus_array, [ "bonus_type" => "error", #獎金名稱 "bonus_receiver" => "error", #發放人員 "bonus_amount" => 0, #金額 "payment_schedul_due" => "9999-1-1", #預計發放時間 "payment_schedul_regulation" => "error" #發放規定 ]); - + $result_array = [ - "ver"=>$ver, #獎金版本 - "result_status"=>"error", #計算結果 - "bonus_array"=>$bonus_array #獎金水庫 + "ver" => $ver, #獎金版本 + "result_status" => "error", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 ]; }; - + return $result_array; }; - -?> \ No newline at end of file diff --git a/wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0_examination.php b/wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0_examination.php index 771b791b..600d4071 100644 --- a/wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0_examination.php +++ b/wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0_examination.php @@ -41,76 +41,85 @@ require_once("elevator_new_deal_bonus_v2_0.php"); #獎金測試 $examination_array = [ #錯誤版本 - ["1.0","strategy_customer","passenger",1000000,1000000,"M0001", "M0003"], + ["1.0", "strategy_customer", "passenger", 1000000, 1000000, "M0001", "M0003"], #戰略客戶(strategy_customer) - ["2.0","strategy_customer","passenger",1000000,1000000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數100% - ["2.0","strategy_customer","passenger",1000000,900000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數90% - ["2.0","strategy_customer","passenger",1000000,750000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數75% - ["2.0","strategy_customer","passenger",1000000,600000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數60% - ["2.0","strategy_customer","cargo",1000000,1000000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數100% - ["2.0","strategy_customer","cargo",1000000,900000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數90% - ["2.0","strategy_customer","cargo",1000000,750000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數75% - ["2.0","strategy_customer","cargo",1000000,600000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數60% - ["2.0","strategy_customer","dumbwaiter",1000000,1000000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數100% - ["2.0","strategy_customer","dumbwaiter",1000000,900000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數90% - ["2.0","strategy_customer","dumbwaiter",1000000,720000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數75% - ["2.0","strategy_customer","dumbwaiter",1000000,600000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數60% - ["2.0","strategy_customer","flatbase",1000000,1000000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數100% - ["2.0","strategy_customer","flatbase",1000000,900000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數90% - ["2.0","strategy_customer","flatbase",1000000,720000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數75% - ["2.0","strategy_customer","flatbase",1000000,600000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數60% - ["2.0","strategy_customer","positive_drive",1000000,1000000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數100% - ["2.0","strategy_customer","positive_drive",1000000,900000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數90% - ["2.0","strategy_customer","positive_drive",1000000,720000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數75% - ["2.0","strategy_customer","positive_drive",1000000,600000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數60% + ["2.0", "strategy_customer", "passenger", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、客梯、銷售點數100% + ["2.0", "strategy_customer", "passenger", 1000000, 900000, "M0001", "M0003"], #戰略客戶、客梯、銷售點數90% + ["2.0", "strategy_customer", "passenger", 1000000, 750000, "M0001", "M0003"], #戰略客戶、客梯、銷售點數75% + ["2.0", "strategy_customer", "passenger", 1000000, 600000, "M0001", "M0003"], #戰略客戶、客梯、銷售點數60% + ["2.0", "strategy_customer", "cargo", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、貨梯、銷售點數100% + ["2.0", "strategy_customer", "cargo", 1000000, 900000, "M0001", "M0003"], #戰略客戶、貨梯、銷售點數90% + ["2.0", "strategy_customer", "cargo", 1000000, 750000, "M0001", "M0003"], #戰略客戶、貨梯、銷售點數75% + ["2.0", "strategy_customer", "cargo", 1000000, 600000, "M0001", "M0003"], #戰略客戶、貨梯、銷售點數60% + ["2.0", "strategy_customer", "dumbwaiter", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、小電梯、銷售點數100% + ["2.0", "strategy_customer", "dumbwaiter", 1000000, 900000, "M0001", "M0003"], #戰略客戶、小電梯、銷售點數90% + ["2.0", "strategy_customer", "dumbwaiter", 1000000, 720000, "M0001", "M0003"], #戰略客戶、小電梯、銷售點數75% + ["2.0", "strategy_customer", "dumbwaiter", 1000000, 600000, "M0001", "M0003"], #戰略客戶、小電梯、銷售點數60% + ["2.0", "strategy_customer", "flatbase", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、平台梯、銷售點數100% + ["2.0", "strategy_customer", "flatbase", 1000000, 900000, "M0001", "M0003"], #戰略客戶、平台梯、銷售點數90% + ["2.0", "strategy_customer", "flatbase", 1000000, 720000, "M0001", "M0003"], #戰略客戶、平台梯、銷售點數75% + ["2.0", "strategy_customer", "flatbase", 1000000, 600000, "M0001", "M0003"], #戰略客戶、平台梯、銷售點數60% + ["2.0", "strategy_customer", "positive_drive", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、強驅、銷售點數100% + ["2.0", "strategy_customer", "positive_drive", 1000000, 900000, "M0001", "M0003"], #戰略客戶、強驅、銷售點數90% + ["2.0", "strategy_customer", "positive_drive", 1000000, 720000, "M0001", "M0003"], #戰略客戶、強驅、銷售點數75% + ["2.0", "strategy_customer", "positive_drive", 1000000, 600000, "M0001", "M0003"], #戰略客戶、強驅、銷售點數60% #一般客戶(general_customer) - ["2.0","general_customer","passenger",1000000,1000000,"M0001", "M0003"], #一般客戶、客梯、銷售點數100% - ["2.0","general_customer","passenger",1000000,900000,"M0001", "M0003"], #一般客戶、客梯、銷售點數90% - ["2.0","general_customer","passenger",1000000,750000,"M0001", "M0003"], #一般客戶、客梯、銷售點數75% - ["2.0","general_customer","passenger",1000000,600000,"M0001", "M0003"], #一般客戶、客梯、銷售點數60% - ["2.0","general_customer","cargo",1000000,1000000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數100% - ["2.0","general_customer","cargo",1000000,900000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數90% - ["2.0","general_customer","cargo",1000000,750000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數75% - ["2.0","general_customer","cargo",1000000,600000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數60% - ["2.0","general_customer","dumbwaiter",1000000,1000000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數100% - ["2.0","general_customer","dumbwaiter",1000000,900000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數90% - ["2.0","general_customer","dumbwaiter",1000000,720000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數75% - ["2.0","general_customer","dumbwaiter",1000000,600000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數60% - ["2.0","general_customer","flatbase",1000000,1000000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數100% - ["2.0","general_customer","flatbase",1000000,900000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數90% - ["2.0","general_customer","flatbase",1000000,720000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數75% - ["2.0","general_customer","flatbase",1000000,600000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數60% - ["2.0","general_customer","positive_drive",1000000,1000000,"M0001", "M0003"], #一般客戶、強驅、銷售點數100% - ["2.0","general_customer","positive_drive",1000000,900000,"M0001", "M0003"], #一般客戶、強驅、銷售點數90% - ["2.0","general_customer","positive_drive",1000000,720000,"M0001", "M0003"], #一般客戶、強驅、銷售點數75% - ["2.0","general_customer","positive_drive",1000000,600000,"M0001", "M0003"] #一般客戶、強驅、銷售點數60% + ["2.0", "general_customer", "passenger", 1000000, 1000000, "M0001", "M0003"], #一般客戶、客梯、銷售點數100% + ["2.0", "general_customer", "passenger", 1000000, 900000, "M0001", "M0003"], #一般客戶、客梯、銷售點數90% + ["2.0", "general_customer", "passenger", 1000000, 750000, "M0001", "M0003"], #一般客戶、客梯、銷售點數75% + ["2.0", "general_customer", "passenger", 1000000, 600000, "M0001", "M0003"], #一般客戶、客梯、銷售點數60% + ["2.0", "general_customer", "cargo", 1000000, 1000000, "M0001", "M0003"], #一般客戶、貨梯、銷售點數100% + ["2.0", "general_customer", "cargo", 1000000, 900000, "M0001", "M0003"], #一般客戶、貨梯、銷售點數90% + ["2.0", "general_customer", "cargo", 1000000, 750000, "M0001", "M0003"], #一般客戶、貨梯、銷售點數75% + ["2.0", "general_customer", "cargo", 1000000, 600000, "M0001", "M0003"], #一般客戶、貨梯、銷售點數60% + ["2.0", "general_customer", "dumbwaiter", 1000000, 1000000, "M0001", "M0003"], #一般客戶、小電梯、銷售點數100% + ["2.0", "general_customer", "dumbwaiter", 1000000, 900000, "M0001", "M0003"], #一般客戶、小電梯、銷售點數90% + ["2.0", "general_customer", "dumbwaiter", 1000000, 720000, "M0001", "M0003"], #一般客戶、小電梯、銷售點數75% + ["2.0", "general_customer", "dumbwaiter", 1000000, 600000, "M0001", "M0003"], #一般客戶、小電梯、銷售點數60% + ["2.0", "general_customer", "flatbase", 1000000, 1000000, "M0001", "M0003"], #一般客戶、平台梯、銷售點數100% + ["2.0", "general_customer", "flatbase", 1000000, 900000, "M0001", "M0003"], #一般客戶、平台梯、銷售點數90% + ["2.0", "general_customer", "flatbase", 1000000, 720000, "M0001", "M0003"], #一般客戶、平台梯、銷售點數75% + ["2.0", "general_customer", "flatbase", 1000000, 600000, "M0001", "M0003"], #一般客戶、平台梯、銷售點數60% + ["2.0", "general_customer", "positive_drive", 1000000, 1000000, "M0001", "M0003"], #一般客戶、強驅、銷售點數100% + ["2.0", "general_customer", "positive_drive", 1000000, 900000, "M0001", "M0003"], #一般客戶、強驅、銷售點數90% + ["2.0", "general_customer", "positive_drive", 1000000, 720000, "M0001", "M0003"], #一般客戶、強驅、銷售點數75% + ["2.0", "general_customer", "positive_drive", 1000000, 600000, "M0001", "M0003"] #一般客戶、強驅、銷售點數60% ]; -for($i = 0; $i '戰略客戶', + 'general_customer' => '一般客戶' + ]; + //作番機種($elevator_type):客梯(passenger)、貨梯(cargo)、小電梯(dumbwaiter)、平台梯(flatbase)、強驅(positive_drive) + $elevator = [ + "passenger" => "客梯", + "cargo" => "貨梯", + "dumbwaiter" => "小電梯", + "flatbase" => "平台踢", + "positive_drive" => "強驅" + ]; echo "獎金版本:" . $result["ver"] . "
"; echo "計算結果:" . $result["result_status"] . "
"; + echo "參數說明: " . $customer[$examination_array[$i][1]] . " 、 " . $elevator[$examination_array[$i][2]] . "、 作番表價:" . $examination_array[$i][3] . " 、 作番賣價: " . $examination_array[$i][4] . "、 營業員員工號:" . $examination_array[$i][5] . " 、 區域經理員工號:" . $examination_array[$i][6] . "
"; echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " " - . $examination_array[$i][5] . " " . $examination_array[$i][6] . "
"; - for($j = 0; $j"; + for ($j = 0; $j < count($result["bonus_array"]); $j++) { echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " " - . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["payment_schedul_due"] . " " - . $result["bonus_array"][$j]["payment_schedul_regulation"] . "
"; + . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["payment_schedul_due"] . " " + . $result["bonus_array"][$j]["payment_schedul_regulation"] . "
"; }; echo "-------------------------" . "
"; - }; - - -?> diff --git a/wms/contract/api/T8api.php b/wms/contract/api/T8api.php index 7bf12c6f..245a318d 100644 --- a/wms/contract/api/T8api.php +++ b/wms/contract/api/T8api.php @@ -7,7 +7,7 @@ function T8salIncomeApply($data, $api_url) // $api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; $validation = get_Auth(); // echo '
';
-    // print_r(json_encode($data));
+    // print_r(json_encode($data, JSON_UNESCAPED_UNICODE));
     // echo '
'; $header = [ "CHI_Authorization :" . $validation, diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php index 667c33b7..e2aedd43 100644 --- a/wms/contract/api/getContractData.php +++ b/wms/contract/api/getContractData.php @@ -186,28 +186,13 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont 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 ' } - // echo '
';
-                    // print_r($option['item_no'] . '--->' . $option['item_unit_price'] . '--->' . $option['item_qty']);
-                    // echo '
'; } - - // print_r($result['option_other_price']); - // exit(); } diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index 6b9b210b..243b9ad3 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -620,6 +620,7 @@ function T8insert($data, $facilityno, $depId) "SPrice" => intval($elevator['sold_price']), "SQuantity" => $SQuantity, "ProjectId" => "$contractno", + "FromBillNo" => "$contractno", "CU_MaterialId" => "$facility_no", "CU_EstPayDate" => intval($payDay) ]; diff --git a/wms/contract/api/postNewContractData.php b/wms/contract/api/postNewContractData.php index 2a1ebca5..6fd5756c 100644 --- a/wms/contract/api/postNewContractData.php +++ b/wms/contract/api/postNewContractData.php @@ -1,10 +1,16 @@ + "; + // print_r($elevators_detail_arr); + // echo ""; + // exit(); $files = !empty($_FILES['files']) ? $_FILES['files'] : null; $files_id = null; @@ -67,19 +76,131 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums)); 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(); - // } + $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); @@ -125,7 +246,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); } @@ -158,7 +279,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(); @@ -194,6 +315,15 @@ function T8Insert($data, $facilityno, $connT8) $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' => '二次款', @@ -228,7 +358,6 @@ function T8Insert($data, $facilityno, $connT8) $stmt->bindParam(':TaxNo', $vat); $stmt->bindParam(':EnterpriseName', $partyA); //企業名稱 $stmt->bindParam(':ContactAddress', $partyAaddress); - // $stmt->bindParam(':EMail', $email); $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':CreateTime', $createTime); $stmt->execute(); @@ -236,8 +365,8 @@ function T8Insert($data, $facilityno, $connT8) $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')"; + (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')"; @@ -253,6 +382,7 @@ function T8Insert($data, $facilityno, $connT8) // // 若客戶資料不為空,更新該客戶資訊。 $sql = "UPDATE comCustomer SET PersonId=:PersonId, + ConditionId='0008', InvoiceAddress=:InvoiceAddress, LastOperatorId=:LastOperatorId, LastOperateTime=:LastOperateTime @@ -306,176 +436,208 @@ function T8Insert($data, $facilityno, $connT8) $stmt->bindParam(':CreatorId', $user_id); $stmt->execute(); } - - foreach ($elevators as $index => $elevator) { - $count = 1; - // 產品集成維護 - $facility_no = $facilityno[$index]; - $MaterialName = "$partyA($facility_no)"; - $sql = "INSERT INTO comMaterial + $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(); + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':MaterialId', $facility_no); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); - $sql = "INSERT INTO comMaterialGroup + $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 + $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(); + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':MaterialId', $facility_no); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); - $sql = "INSERT INTO plsMaterialPlanData + $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(); + $stmt = $connT8->prepare($sql); + $stmt->bindParam(':MaterialId', $facility_no); + $stmt->bindParam(':CreatorId', $user_id); + $stmt->bindParam(':CreateTime', $createTime); + $stmt->execute(); - $sql = "INSERT INTO comMaterialSales + $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(); + $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; + } - // 階段收款資訊 - $salOrderStagePay_row = []; - $equipment_total = 0; - $install_total = 0; - $equipment_total = $pay_arr['equipment_total']; - $install_total = $pay_arr['install_total']; - foreach ($pay_arr['elevotor_pay_detail'] as $key => $detail) { - $PayStage = $pay_kind[$detail['kind']]; - $PlanPercentage = intval($detail['pay_scale']) / 100; - $rows = [ - "PayStage" => "$PayStage", //收款階段 - "PlanPercentage" => $PlanPercentage, //計劃收款比例(%) - "PlanPayAmt" => $detail['amount'], //計劃收款金額 - "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 - "BillNo" => "$contractno", - "RowCode" => $key + 1, - "RowNo" => $key + 1, - "UnWriteOffOAmount" => $detail['amount'] //未核銷金額 + // 設備 + $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 ]; - $salOrderStagePay_row[] = $rows; + $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++; } - - // 設備 - $row1 = [ + $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", - "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 //交易價格 + "CreditorCompId" => "1001", + "CreditorOrgId" => "1000", + "CreatorId" => "$user_id" + // "CompId" => "1001", + // "CreditorCurrOAmount" => 1, + // "CreditorCurrLAmount" => 1 ]; - $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 //交易價格 + $MainSalesOrder = [ + "name" => "MainSalesOrder", + 'rows' => [$MainSalesOrder_row] ]; - $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 //交易價格 + $SubOrder = [ + "name" => "SubOrder", + "rows" => $SubOrder_row + ]; + $salOrderStagePay = [ + "name" => "salOrderStagePay", + "rows" => $salOrderStagePay_row ]; - $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" => "$user_id", //業務人員 - "DueToId" => "$contractno", //債務方 - "TradeConditionId" => "", - "TaxId" => "ST005", - "CreditorCompId" => "1001", - "CreditorOrgId" => "1000", - // "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 "
"; + $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(); @@ -487,153 +649,168 @@ function T8Insert($data, $facilityno, $connT8) function BounsCount($data, $conn, $facilityno) { - // echo '
';
-  // print_r($facilityno);
-  // echo '
'; - // exit; - 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 - ]; + 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 + 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(); + $stmt = $conn->prepare($sql); + $stmt->execute(); + } + $request = [ + "status" => "1", + "data" => "Success" + ]; + return $request; } $request = [ - "status" => "1", - "data" => "Success" + "status" => "2", + "data" => "create_bonus_error" ]; 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) { - $elevator_type = $dailyNecessities[$elevator['spec']]; - $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 + } 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(); + $stmt = $conn->prepare($sql); + $stmt->execute(); + } } + $request = [ + "status" => "1", + "data" => "Success" + ]; + } else { + $request = [ + "status" => "2", + "data" => "create_bonus_error" + ]; } - $request = [ - "status" => "1", - "data" => "Success" - ]; - } else { - $request = [ - "status" => "2", - "data" => "create_bonus_error" - ]; } } - } - return $request; - - try { + 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 index 5df03461..b9dd2f3f 100644 --- a/wms/contract/api/test copy.json +++ b/wms/contract/api/test copy.json @@ -3,22 +3,23 @@ "name": "MainSalesOrder", "rows": [ { - "BillNo": "M24020076", - "BillDate": 20240305, + "BillNo": "M23110121", + "BillDate": 20240313, "TypeId": "SO", "FOrgId": "1000", "OrgId": "1000", "ModeId": "M", - "BizPartnerId": "M24020076", + "BizPartnerId": "M23110121", "CurrId": "TWD", "CurrOAmount": 1, "CurrLAmount": 1, - "PersonId": "M0225", - "DueToId": "M24020076", + "PersonId": "M0042", + "DueToId": "M23110121", "TradeConditionId": "", "TaxId": "ST005", "CreditorCompId": "1001", - "CreditorOrgId": "1000" + "CreditorOrgId": "1000", + "CreatorId": "M0225" } ] }, @@ -27,87 +28,371 @@ "rows": [ { "TaxId": "ST005", - "RequirementDate": 20240305, - "ConsignmentDate": 20240305, - "BillNo": "M24020076", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", "RowCode": 1, "ItemType": 1, "MaterialId": "A40001", "SUnitId": "SET", "SQuantity": 1, - "SPrice": 910000 + "SPrice": 3904000, + "CU_MaterialId": "4MH00836" }, { "TaxId": "ST005", - "RequirementDate": 20240305, - "ConsignmentDate": 20240305, - "BillNo": "M24020076", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", "RowCode": 2, "ItemType": 1, "MaterialId": "A40008", "SUnitId": "SET", "SQuantity": 1, - "SPrice": 390000 + "SPrice": 976000, + "CU_MaterialId": "4MH00836" }, { "TaxId": "ST005", - "RequirementDate": 20240305, - "ConsignmentDate": 20240305, - "BillNo": "M24020076", + "RequirementDate": 20240313, + "ConsignmentDate": 20240313, + "BillNo": "M23110121", "RowCode": 3, "ItemType": 0, - "MaterialId": "4MW00705", + "MaterialId": "4MH00836", "SUnitId": "SET", "SQuantity": 1, - "SPrice": 0 + "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": 260000, - "PlanPayDate": 20240101, - "BillNo": "M24020076", - "RowCode": 0, - "RowNo": 0, - "UnWriteOffOAmount": 260000 - }, - { - "PayStage": "貨抵工地", - "PlanPercentage": 0.5, - "PlanPayAmt": 650000, - "PlanPayDate": 20240101, - "BillNo": "M24020076", - "RowCode": 1, - "RowNo": 1, - "UnWriteOffOAmount": 650000 - }, - { - "PayStage": "試車完工", - "PlanPercentage": 0.2, - "PlanPayAmt": 260000, - "PlanPayDate": 20240101, - "BillNo": "M24020076", - "RowCode": 2, - "RowNo": 2, - "UnWriteOffOAmount": 260000 - }, - { - "PayStage": "交車", - "PlanPercentage": 0.1, - "PlanPayAmt": 130000, - "PlanPayDate": 20240101, - "BillNo": "M24020076", - "RowCode": 3, - "RowNo": 3, - "UnWriteOffOAmount": 130000 - } - ] + { + "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 c0585164..da130a89 100644 --- a/wms/contract/api/test.json +++ b/wms/contract/api/test.json @@ -27,7 +27,7 @@ ] }, { - //salSalesOrderDetail + // salSalesOrderDetail "name": "SubOrder", "rows": [ { diff --git a/wms/contract/api/testT8API.php b/wms/contract/api/testT8API.php index 89077ffc..e9d2f04f 100644 --- a/wms/contract/api/testT8API.php +++ b/wms/contract/api/testT8API.php @@ -1,9 +1,5 @@ "M24020076", //合約單號 + "BillNo" => "$contract_no", //合約單號 "BillDate" => 20210420, //簽約日期 "TypeId" => "SO", // "FOrgId" => "1000", "OrgId" => "1000", "ModeId" => "M", // T汰改 M新梯 - "BizPartnerId" => "M24020076", //客戶代碼 + "BizPartnerId" => "$contract_no", //客戶代碼 "CurrId" => "TWD", "CurrOAmount" => 1, "CurrLAmount" => 1, - "PersonId" => "M0225", //業務人員 - "DueToId" => "M24020076", //債務方 + "PersonId" => "M0177", //業務人員 + "DueToId" => "$contract_no", //債務方 "TradeConditionId" => "", "TaxId" => "ST005", "CreditorCompId" => "1001", "CreditorOrgId" => "1000", - // "CompId" => "1001", - // "CreditorCurrOAmount" => 1, - // "CreditorCurrLAmount" => 1 + "CreatorId" => "M0225" + ]; // //salSalesOrderDetail // $SubOrder_row = []; @@ -104,13 +128,13 @@ for ($i = 0; $i < 3; $i++) { "ConsignmentDate" => 20210420, //發貨日期 // "DispatchCompId" => "1001", // "DispatchOrgId" => "1000", - "BillNo" => "M24020076", //合約號 + "BillNo" => "$contract_no", //合約號 "RowCode" => $i, //全部筆數排列 "ItemType" => 1, "MaterialId" => "A40001", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) "SUnitId" => "SET", "SQuantity" => 1, //交易數量 - "SPrice" => 50000 //交易價格 + "SPrice" => 100000 //交易價格 ]; } if ($i == 1) { @@ -122,25 +146,21 @@ for ($i = 0; $i < 3; $i++) { "ConsignmentDate" => 20210420, //發貨日期 // "DispatchCompId" => "1001", // "DispatchOrgId" => "1000", - "BillNo" => "M24020076", //合約號 + "BillNo" => "$contract_no", //合約號 "RowCode" => $i, //全部筆數排列 "ItemType" => 1, "MaterialId" => "A40008", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) "SUnitId" => "SET", "SQuantity" => 1, //交易數量 - "SPrice" => 700000 //交易價格 + "SPrice" => 650000 //交易價格 ]; } if ($i == 2) { $row = [ - // "SupplyCompId" => "1001", - // "SupplyOrgId" => "1000", "TaxId" => "ST005", "RequirementDate" => 20210420, //出貨日期 "ConsignmentDate" => 20210420, //發貨日期 - // "DispatchCompId" => "1001", - // "DispatchOrgId" => "1000", - "BillNo" => "M24020076", //合約號 + "BillNo" => "$contract_no", //合約號 "RowCode" => $i, //全部筆數排列 "ItemType" => 0, "MaterialId" => "4MH00669", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) @@ -152,65 +172,14 @@ for ($i = 0; $i < 3; $i++) { $SubOrder_row[] = $row; } -// // $salOrderStagePay_row = []; -// // // for ($i = 0; $i < 2; $i) { -// // // if ($i == 0) { -// // // $row = [ -// // // "BillNo" => "M24010201", -// // // "RowCode" => 1, -// // // "RowNo" => 1, -// // // "PayStage" => "簽約", //收款階段 -// // // "PlanPercentage" => 0.10, //計劃收款比例(%) -// // // "PlanPayAmt" => 100000, //計劃收款金額 -// // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 -// // // "UnWriteOffOAmount" => 100000 //未核銷金額 -// // // ]; -// // // } -// // // if ($i == 1) { -// // // $row = [ -// // // "BillNo" => "M24010201", -// // // "RowCode" => 1, -// // // "RowNo" => 1, -// // // "PayStage" => "貨抵工地", //收款階段 -// // // "PlanPercentage" => 0.40, //計劃收款比例(%) -// // // "PlanPayAmt" => 100000, //計劃收款金額 -// // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 -// // // "UnWriteOffOAmount" => 100000 //未核銷金額 -// // // ]; -// // // } -// // // if ($i == 2) { -// // // $row = [ -// // // "BillNo" => "M24010201", -// // // "RowCode" => 1, -// // // "RowNo" => 1, -// // // "PayStage" => "試車完工", //收款階段 -// // // "PlanPercentage" => 0.30, //計劃收款比例(%) -// // // "PlanPayAmt" => 100000, //計劃收款金額 -// // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 -// // // "UnWriteOffOAmount" => 100000 //未核銷金額 -// // // ]; -// // // } -// // // if ($i == 3) { -// // // $row = [ -// // // "BillNo" => "M24010201", -// // // "RowCode" => 1, -// // // "RowNo" => 1, -// // // "PayStage" => "交車", //收款階段 -// // // "PlanPercentage" => 0.20, //計劃收款比例(%) -// // // "PlanPayAmt" => 100000, //計劃收款金額 -// // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 -// // // "UnWriteOffOAmount" => 100000 //未核銷金額 -// // // ]; -// // // } -// // // $salOrderStagePay_row[] = $row; -// // // } + $salOrderStagePay_row = []; $roww = [ "PayStage" => "簽約", //收款階段 "PlanPercentage" => 0.5, //計劃收款比例(%) "PlanPayAmt" => 375000, //計劃收款金額 "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 - "BillNo" => "M24020076", + "BillNo" => "$contract_no", "RowCode" => 1, "RowNo" => 1, "UnWriteOffOAmount" => 375000 //未核銷金額 @@ -220,12 +189,14 @@ $roww2 = [ "PlanPercentage" => 0.5, "PlanPayAmt" => 375000, "PlanPayDate" => 20240101, - "BillNo" => "M24020076", + "BillNo" => "$contract_no", "RowCode" => 2, "RowNo" => 2, "UnWriteOffOAmount" => 375000 ]; $salOrderStagePay_row[] = $roww; +$salOrderStagePay_row[] = $roww2; + $MainSalesOrder = [ "name" => "MainSalesOrder", @@ -250,9 +221,9 @@ $APIbody[] = $salOrderStagePay; // print_r($data); // echo ""; -// echo "
";
-// print_r(json_encode($APIbody, JSON_UNESCAPED_UNICODE));
-// echo "
"; +echo "
";
+print_r(json_encode($APIbody, JSON_UNESCAPED_UNICODE));
+echo "
"; // exit(); $header = [ diff --git a/wms/contract/contract-newelevator-input.php b/wms/contract/contract-newelevator-input.php index 75992ffc..70d83b32 100644 --- a/wms/contract/contract-newelevator-input.php +++ b/wms/contract/contract-newelevator-input.php @@ -134,7 +134,17 @@ $persons = array_map(function ($person) {
- + + @@ -187,7 +197,7 @@ $persons = array_map(function ($person) {
牌價 服務費 應發人員預計發放時間 應發獎金水庫 實發金額 狀態發放 / 詳情 詳情
@@ -225,7 +231,7 @@ function isPay($contract_no, $connT8) - 查看詳情
區域 + +
QC和官檢 - diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index 104ab4f7..59d63b01 100644 --- a/wms/contract/js/alpine.js +++ b/wms/contract/js/alpine.js @@ -829,6 +829,8 @@ const contractNewInput = () => { elevators_detail_arr: [], // 電梯台數 Array pay_arr: [], //電梯付款種類 nums: 0, //電梯數量 + area_no: 'T', + contract_arrival_date: '' }, step: 1, isLoading: false, @@ -868,14 +870,15 @@ const contractNewInput = () => { this.data.elevators_detail_arr[i].longitude = ''; // 緯度 this.data.elevators_detail_arr[i].manage = ''; // 工地負責人 this.data.elevators_detail_arr[i].qc = ''; // QC和官檢 - this.data.elevators_detail_arr[i].contract_arrival_date = ''; //合約交期(到工地) + this.data.elevators_detail_arr[i].contract_arrival_date = this.data.contract_arrival_date; //合約交期(到工地) + // this.data.elevators_detail_arr[i].area_no = ''; //區域 } this.step = 3; this.isLoading = false; } else if (this.step == 3) { console.log(this.data.elevators_detail_arr); - this.step = 4; - this.isLoading = false; + // this.step = 4; + // this.isLoading = false; } }, getContractDate() { @@ -889,7 +892,7 @@ const contractNewInput = () => { return } if (!this.customize) { - console.log(res.data); + console.log(res.data.customer); this.data.customer = res.data.company this.data.manager = res.data.manager this.data.vat = res.data.uscc @@ -904,6 +907,7 @@ const contractNewInput = () => { this.data.elevators_detail_arr = res.data.elevators_detail_arr; this.data.nums = res.data.nums; this.data.pay_arr = res.data.pay_arr; + this.data.contract_arrival_date = res.data.facilitok_date; } this.step = 2 this.isLoading = false @@ -919,6 +923,7 @@ const contractNewInput = () => { form.append('customer', this.data.customer); form.append('manager', this.data.manager); form.append('vat', this.data.vat); + form.append('area_no', this.data.area_no); form.append('case_name', this.data.case_name); form.append('linkman', this.data.linkman); form.append('lm_tel', this.data.lm_tel); From 35c6da8e710c0ce0de6c95f67e04ba3006e05d25 Mon Sep 17 00:00:00 2001 From: Ellin Date: Tue, 5 Mar 2024 18:05:58 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=87=89=E6=94=B6?= =?UTF-8?q?=E5=B8=B3=E6=AC=BE(=E4=BF=9D=E9=A4=8A)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + wms/T8_Authorization_from_bpm.php | 15 +- wms/account-receivable-maintainance-index.php | 523 ++++++++++++++++++ 3 files changed, 531 insertions(+), 8 deletions(-) create mode 100644 wms/account-receivable-maintainance-index.php 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) { ?> + + + + + + + + + + + + + + + + + + + +
合約號序號作番號部門主管契約員客戶名稱應收日期是否應收應收金額已收金額催收金額催收次數
" . $row['DeptName']; ?>" . $row['LeaderName']; ?>" . $row['PersonName']; ?>" . $row['BizPartnerName']; ?>1))? $row['collecttime']:0; ?>
+
+ + \ No newline at end of file