diff --git a/wms/T8_Authorization_from_bpm.php b/wms/T8_Authorization_from_bpm.php index 8012feac..e67c83d5 100644 --- a/wms/T8_Authorization_from_bpm.php +++ b/wms/T8_Authorization_from_bpm.php @@ -11,15 +11,15 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119") // $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, '91EB2CB12C3F8211', false); + $sign = hash_hmac('SHA256', $data, 'A21181F1EE4966D3', false); ///測試區 + // $sign = hash_hmac('SHA256', $data, '91EB2CB12C3F8211', false); // echo $sign; - $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'; - // $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; + // $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://10.10.145.2:880//twWebAPI/GetAuth'; + // $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth'; /// 正式區 // $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'; //GroupId : TEST測試區 ; MASADA正式區 @@ -28,7 +28,8 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119") "Pwd: $user_password", "TimestampUTC: $now", "Sign: $sign", - "GroupId:MASADA" + "GroupId:TEST" + // "GroupId:MASADA" ]; $ch = curl_init(); diff --git a/wms/bonus/maintainance_bonus.php b/wms/bonus/maintainance_bonus.php index ee2ab36b..d5fca570 100644 --- a/wms/bonus/maintainance_bonus.php +++ b/wms/bonus/maintainance_bonus.php @@ -24,7 +24,7 @@ $bonus_status = [ '5' => '人事審核確認' ]; $clause = ''; -if ($user_id != 'M0225') { +if ($user_id != 'M0225' || $user_id != 'M0012' || $user_id != 'M0029') { $clause .= "AND receiver == '$user_id'"; } if (!empty($_GET['check'])) { diff --git a/wms/bonus/maintance/maintaenance_contract_bonus.php b/wms/bonus/maintance/maintaenance_contract_bonus.php new file mode 100644 index 00000000..b267eef9 --- /dev/null +++ b/wms/bonus/maintance/maintaenance_contract_bonus.php @@ -0,0 +1,748 @@ += 3001 and $fee_per_st <= 3499): + $sales_bonus = ($fee_per_st) * 0.7; + break; + case ($fee_per_st >= 3500 and $fee_per_st <= 3999): + $sales_bonus = ($fee_per_st) * 0.8; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st) * 0.9; + break; + }; + #地區經理經理獎金($region_manager_bonus) + $region_manager_bonus = 170; + #專任契約經理獎金($regular_contract_manger_bonus) + if (($regular_contract_manger_id) != '') { + $regular_contract_manger_bonus = 100; + } + break; + + case "free_to_charge": + switch ($fee_per_st) { + case ($fee_per_st <= 3000): + $sales_bonus = ($fee_per_st) * 0.3; + break; + case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + $sales_bonus = ($fee_per_st) * 0.35; + break; + case ($fee_per_st >= 3500 and $fee_per_st <= 3999): + $sales_bonus = ($fee_per_st) * 0.4; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st) * 0.5; + break; + }; + #地區經理經理獎金($region_manager_bonus) + $region_manager_bonus = 100; + #專任契約經理獎金($regular_contract_manger_bonus) + if (($regular_contract_manger_id) != '') { + $regular_contract_manger_bonus = 100; + } + break; + + case "renew_priceissue": + switch ($fee_per_st) { + case ($fee_per_st <= 3000): + $sales_bonus = ($fee_per_st) * 0.25; + break; + case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + $sales_bonus = ($fee_per_st) * 0.3; + break; + case ($fee_per_st >= 3500 and $fee_per_st <= 3999): + $sales_bonus = ($fee_per_st) * 0.35; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st) * 0.4; + break; + }; + #地區經理經理獎金($region_manager_bonus) + $region_manager_bonus = 100; + #專任契約經理獎金($regular_contract_manger_bonus) + if (($regular_contract_manger_id) != '') { + $regular_contract_manger_bonus = 100; + } + break; + }; + + #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) + switch ($discount) { + case ($discount < 0.6): + $sales_bonus = $sales_bonus * 0.7; + break; + case ($discount >= 0.6 and $discount < 0.8): + $sales_bonus = $sales_bonus * 0.8; + break; + case ($discount >= 0.8): + $sales_bonus = $sales_bonus * 1.0; + break; + }; + + #簽約年數($contract_years):1年(1),超過1年(above) + + switch ($contract_years) { + case $contract_years == "one": + #契約員獎金 + array_push($bonus_array, [ + "bonus_type" => "1", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #地區經理經理獎金 + array_push($bonus_array, [ + "bonus_type" => "2", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #專任契約經理獎金 + if (($regular_contract_manger_id) != '') { + array_push($bonus_array, [ + "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 +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + } + $result_array = [ + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + break; + + case $contract_years == "above_two": + /*** 以下第1年獎金 ***/ + #契約員獎金 + array_push($bonus_array, [ + "bonus_type" => "1", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #地區經理經理獎金 + array_push($bonus_array, [ + "bonus_type" => "2", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #專任契約經理獎金 + if (($regular_contract_manger_id) != '') { + array_push($bonus_array, [ + "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 +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + } + /*** 以上第1年獎金 ***/ + + /*** 以下第2年獎金 ***/ + #第2年契約員獎金 + array_push($bonus_array, [ + "bonus_type" => "1", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +13 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #第2年地區經理經理獎金 + array_push($bonus_array, [ + "bonus_type" => "2", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +13 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #第2年專任契約經理獎金 + if (($regular_contract_manger_id) != '') { + array_push($bonus_array, [ + "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 +13 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + } + /*** 以上第2年獎金 ***/ + + $result_array = [ + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + break; + } + } 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; +}; + +## 4/1 後套用 2.1 版本 +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; + + #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) + switch ($contract_type) { + case "new": + #契約員獎金($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 <= 3499): + $sales_bonus = ($fee_per_st) * 0.7; + break; + case ($fee_per_st >= 3500 and $fee_per_st <= 3999): + $sales_bonus = ($fee_per_st) * 0.8; + break; + case ($fee_per_st >= 4000): + $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) * 0.48; + break; + 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): + $sales_bonus = ($fee_per_st) * 0.64; + break; + case ($fee_per_st >= 4000): + $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) * 0.42; + break; + 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): + $sales_bonus = ($fee_per_st) * 0.56; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st) * 0.63; + break; + }; + break; + }; + + #地區處長獎金($region_director_bonus) + $region_director_bonus = 170; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 300; + break; + + case "free_to_charge": + 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 <= 3499): + $sales_bonus = ($fee_per_st) * 0.35; + break; + case ($fee_per_st >= 3500 and $fee_per_st <= 3999): + $sales_bonus = ($fee_per_st) * 0.4; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st) * 0.45; + break; + }; + #地區處長獎金($region_director_bonus) + $region_director_bonus = 170; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 300; + break; + + case "renew_priceissue": + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.25; + break; + 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): + $sales_bonus = ($fee_per_st) * 0.35; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st) * 0.4; + break; + }; + #地區處長獎金($region_director_bonus) + $region_director_bonus = 170; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 300; + break; + }; + + #地區處長獎金 + array_push($bonus_array, [ + "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 +1 months")), #預計發放時間 + "bonus_regulation" => "第1次款項收回後,次月發放" #發放規定 + ]); + + #專任契約經理獎金 + if ($regular_contract_manger_id != '') { + array_push($bonus_array, [ + "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 +1 months")), #預計發放時間 + "bonus_regulation" => "第1次款項收回後,次月發放" #發放規定 + ]); + } + + #契約員獎金 + switch ($payment_period) { + #年付 + case "annually": + array_push($bonus_array, [ + "bonus_type" => "1", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + break; + + #半年付 + case "semiannually": + $payment_ratio_due_array = array(0.5, 0.5); + $payday_due_array = array(1, 7); + 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" => "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + + #季付 + case "quarterly": + $payment_ratio_due_array = array(0.25, 0.25, 0.25, 0.25); + $payday_due_array = array(1, 4, 7, 10); + 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" => "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + + #2月1次 + case "bimonthly": + $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) { + $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" => "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + + #月付 + case "monthly": + $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) { + $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" => "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + 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; +}; + + +## 五年以上長約 +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" => "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")), #預計發放時間 + "bonus_regulation" => "訂金收回後次月發放" #發放規定 + ]); + + #專任契約經理獎金 + if ($regular_contract_manger_id != '') { + array_push($bonus_array, [ + "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")), #預計發放時間 + "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" => "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" => "每次收款後,按收款比率次月發放" #發放規定 + ]); + } + + 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" => "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" => "每次收款後,按收款比率次月發放" #發放規定 + ]); + } + 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" => "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + 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" => "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + 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" => "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" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + 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/maintance/maintenance_contract_bonus_v2_0.php b/wms/bonus/maintance/maintenance_contract_bonus_v2_0.php index c2cadb3e..c665f1bd 100644 --- a/wms/bonus/maintance/maintenance_contract_bonus_v2_0.php +++ b/wms/bonus/maintance/maintenance_contract_bonus_v2_0.php @@ -36,28 +36,29 @@ result_array[ */ +## 3/31 前套用 2.0 版本 - -function maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, $discount, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_manger_id, $regular_contract_manger_id){ +function maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, $discount, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_manger_id, $regular_contract_manger_id) +{ $bonus_array = []; - if ($ver == "2.0"){ - + if ($ver == "2.0") { + #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) - switch ($contract_type){ + switch ($contract_type) { case "new": #契約員獎金($sales_bonus) 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; - break; + $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; }; #地區經理經理獎金($region_manager_bonus) @@ -69,16 +70,16 @@ function maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, 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; - break; + $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; - break; + $sales_bonus = ($fee_per_st) * 0.4; + break; case ($fee_per_st >= 4000): - $sales_bonus = ($fee_per_st - $commission_fee) * 0.5; + $sales_bonus = ($fee_per_st) * 0.5; break; }; #地區經理經理獎金($region_manager_bonus) @@ -86,29 +87,29 @@ function maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, #專任契約經理獎金($regular_contract_manger_bonus) $regular_contract_manger_bonus = 100; break; - + 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_manager_bonus) $region_manager_bonus = 100; #專任契約經理獎金($regular_contract_manger_bonus) $regular_contract_manger_bonus = 100; break; }; - + #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) switch ($discount) { case ($discount < 0.6): @@ -121,128 +122,125 @@ function maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, $sales_bonus = $sales_bonus * 1.0; break; }; - + #簽約年數($contract_years):1年(1),超過1年(above) - - switch ($contract_years){ + + switch ($contract_years) { case $contract_years == "one": #契約員獎金 - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "契約員獎金", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_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" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_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" => "合約簽回及保養款項收回的次月一次性發" #發放規定 - ]); - + ]); + $result_array = [ - "ver"=>$ver, #獎金版本 - "result_status"=>"success", #計算結果 - "bonus_array"=>$bonus_array #獎金水庫 + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 ]; break; case $contract_years == "above_two": /*** 以下第1年獎金 ***/ #契約員獎金 - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "契約員獎金", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_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" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_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" => "合約簽回及保養款項收回的次月一次性發" #發放規定 - ]); - /*** 以上第1年獎金 ***/ - - /*** 以下第2年獎金 ***/ + ]); + /*** 以上第1年獎金 ***/ + + /*** 以下第2年獎金 ***/ #第2年契約員獎金 - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "契約員獎金", #獎金名稱 "bonus_receiver" => $sales_id, #發放人員 "bonus_amount" => round($sales_bonus), #金額 - "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +13 months")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +13 months")), #預計發放時間 "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 ]); - + #第2年地區經理經理獎金 - array_push($bonus_array,[ + array_push($bonus_array, [ "bonus_type" => "地區經理獎金", #獎金名稱 "bonus_receiver" => $region_manger_id, #發放人員 "bonus_amount" => round($region_manager_bonus), #金額 - "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +13 months")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +13 months")), #預計發放時間 "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 - ]); + ]); #第2年專任契約經理獎金 - 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 +13 months")), #預計發放時間 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +13 months")), #預計發放時間 "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 - ]); - /*** 以上第2年獎金 ***/ - + ]); + /*** 以上第2年獎金 ***/ + $result_array = [ - "ver"=>$ver, #獎金版本 - "result_status"=>"success", #計算結果 - "bonus_array"=>$bonus_array #獎金水庫 + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 ]; break; } - }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/bonus/maintance/maintenance_contract_bonus_v2_0_examination.php b/wms/bonus/maintance/maintenance_contract_bonus_v2_0_examination.php index de316b53..3fe834f6 100644 --- a/wms/bonus/maintance/maintenance_contract_bonus_v2_0_examination.php +++ b/wms/bonus/maintance/maintenance_contract_bonus_v2_0_examination.php @@ -44,113 +44,118 @@ require_once("maintenance_contract_bonus_v2_0.php"); #獎金測試 $examination_array = [ #錯誤版本 - ["1.0","new","one",0.8,4000,333, "2014-07-01", "M0001", "M0002", "M0003"], + ["1.0", "new", "one", 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約 - ["2.0","new","one",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 - ["2.0","new","one",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 - ["2.0","new","one",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 - ["2.0","new","one",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 - ["2.0","new","one",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 - ["2.0","new","one",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 - ["2.0","new","one",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 - ["2.0","new","one",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 - ["2.0","new","one",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 - ["2.0","new","one",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 - ["2.0","new","one",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 - ["2.0","new","one",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 - ["2.0","new","above_two",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 - ["2.0","new","above_two",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 - ["2.0","new","above_two",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 - ["2.0","new","above_two",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 - ["2.0","new","above_two",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 - ["2.0","new","above_two",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 - ["2.0","new","above_two",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 - ["2.0","new","above_two",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 - ["2.0","new","above_two",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 - ["2.0","new","above_two",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 - ["2.0","new","above_two",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 - ["2.0","new","above_two",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、4000元 + ["2.0", "new", "one", 0.8, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 + ["2.0", "new", "one", 0.8, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 + ["2.0", "new", "one", 0.8, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 + ["2.0", "new", "one", 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 + ["2.0", "new", "one", 0.7, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 + ["2.0", "new", "one", 0.7, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 + ["2.0", "new", "one", 0.7, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 + ["2.0", "new", "one", 0.7, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 + ["2.0", "new", "one", 0.6, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 + ["2.0", "new", "one", 0.6, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 + ["2.0", "new", "one", 0.6, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 + ["2.0", "new", "one", 0.6, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 + ["2.0", "new", "above_two", 0.8, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 + ["2.0", "new", "above_two", 0.8, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 + ["2.0", "new", "above_two", 0.8, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 + ["2.0", "new", "above_two", 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 + ["2.0", "new", "above_two", 0.7, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 + ["2.0", "new", "above_two", 0.7, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 + ["2.0", "new", "above_two", 0.7, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 + ["2.0", "new", "above_two", 0.7, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 + ["2.0", "new", "above_two", 0.6, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 + ["2.0", "new", "above_two", 0.6, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 + ["2.0", "new", "above_two", 0.6, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 + ["2.0", "new", "above_two", 0.6, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、4000元 #免保轉有費(free_to_charge) - ["2.0","free_to_charge","one",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 - ["2.0","free_to_charge","one",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 - ["2.0","free_to_charge","one",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 - ["2.0","free_to_charge","one",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 - ["2.0","free_to_charge","one",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 - ["2.0","free_to_charge","one",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 - ["2.0","free_to_charge","one",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 - ["2.0","free_to_charge","one",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 - ["2.0","free_to_charge","one",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 - ["2.0","free_to_charge","one",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 - ["2.0","free_to_charge","one",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 - ["2.0","free_to_charge","one",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 - ["2.0","free_to_charge","above_two",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 - ["2.0","free_to_charge","above_two",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 - ["2.0","free_to_charge","above_two",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 - ["2.0","free_to_charge","above_two",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 - ["2.0","free_to_charge","above_two",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 - ["2.0","free_to_charge","above_two",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 - ["2.0","free_to_charge","above_two",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 - ["2.0","free_to_charge","above_two",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 - ["2.0","free_to_charge","above_two",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 - ["2.0","free_to_charge","above_two",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 - ["2.0","free_to_charge","above_two",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 - ["2.0","free_to_charge","above_two",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、4000元 + ["2.0", "free_to_charge", "one", 0.8, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 + ["2.0", "free_to_charge", "one", 0.8, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 + ["2.0", "free_to_charge", "one", 0.8, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 + ["2.0", "free_to_charge", "one", 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 + ["2.0", "free_to_charge", "one", 0.7, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 + ["2.0", "free_to_charge", "one", 0.7, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 + ["2.0", "free_to_charge", "one", 0.7, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 + ["2.0", "free_to_charge", "one", 0.7, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 + ["2.0", "free_to_charge", "one", 0.6, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 + ["2.0", "free_to_charge", "one", 0.6, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 + ["2.0", "free_to_charge", "one", 0.6, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 + ["2.0", "free_to_charge", "one", 0.6, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 + ["2.0", "free_to_charge", "above_two", 0.8, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 + ["2.0", "free_to_charge", "above_two", 0.8, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 + ["2.0", "free_to_charge", "above_two", 0.8, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 + ["2.0", "free_to_charge", "above_two", 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 + ["2.0", "free_to_charge", "above_two", 0.7, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 + ["2.0", "free_to_charge", "above_two", 0.7, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 + ["2.0", "free_to_charge", "above_two", 0.7, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 + ["2.0", "free_to_charge", "above_two", 0.7, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 + ["2.0", "free_to_charge", "above_two", 0.6, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 + ["2.0", "free_to_charge", "above_two", 0.6, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 + ["2.0", "free_to_charge", "above_two", 0.6, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 + ["2.0", "free_to_charge", "above_two", 0.6, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、4000元 #續簽約(原價或僅契約金額異動)(renew_priceissue) - ["2.0","renew_priceissue","one",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 - ["2.0","renew_priceissue","one",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 - ["2.0","renew_priceissue","one",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 - ["2.0","renew_priceissue","one",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 - ["2.0","renew_priceissue","one",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 - ["2.0","renew_priceissue","one",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 - ["2.0","renew_priceissue","one",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 - ["2.0","renew_priceissue","one",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 - ["2.0","renew_priceissue","one",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 - ["2.0","renew_priceissue","one",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 - ["2.0","renew_priceissue","one",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 - ["2.0","renew_priceissue","one",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 - ["2.0","renew_priceissue","above_two",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 - ["2.0","renew_priceissue","above_two",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 - ["2.0","renew_priceissue","above_two",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 - ["2.0","renew_priceissue","above_two",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 - ["2.0","renew_priceissue","above_two",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 - ["2.0","renew_priceissue","above_two",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 - ["2.0","renew_priceissue","above_two",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 - ["2.0","renew_priceissue","above_two",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 - ["2.0","renew_priceissue","above_two",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 - ["2.0","renew_priceissue","above_two",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 - ["2.0","renew_priceissue","above_two",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 - ["2.0","renew_priceissue","above_two",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"] #新簽約、2年以上、折扣率0.6、4000元 + ["2.0", "renew_priceissue", "one", 0.8, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 + ["2.0", "renew_priceissue", "one", 0.8, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 + ["2.0", "renew_priceissue", "one", 0.8, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 + ["2.0", "renew_priceissue", "one", 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 + ["2.0", "renew_priceissue", "one", 0.7, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 + ["2.0", "renew_priceissue", "one", 0.7, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 + ["2.0", "renew_priceissue", "one", 0.7, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 + ["2.0", "renew_priceissue", "one", 0.7, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 + ["2.0", "renew_priceissue", "one", 0.6, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 + ["2.0", "renew_priceissue", "one", 0.6, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 + ["2.0", "renew_priceissue", "one", 0.6, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 + ["2.0", "renew_priceissue", "one", 0.6, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 + ["2.0", "renew_priceissue", "above_two", 0.8, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 + ["2.0", "renew_priceissue", "above_two", 0.8, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 + ["2.0", "renew_priceissue", "above_two", 0.8, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 + ["2.0", "renew_priceissue", "above_two", 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 + ["2.0", "renew_priceissue", "above_two", 0.7, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 + ["2.0", "renew_priceissue", "above_two", 0.7, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 + ["2.0", "renew_priceissue", "above_two", 0.7, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 + ["2.0", "renew_priceissue", "above_two", 0.7, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 + ["2.0", "renew_priceissue", "above_two", 0.6, 3000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 + ["2.0", "renew_priceissue", "above_two", 0.6, 3200, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 + ["2.0", "renew_priceissue", "above_two", 0.6, 3500, 333, "2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 + ["2.0", "renew_priceissue", "above_two", 0.6, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"] #新簽約、2年以上、折扣率0.6、4000元 ]; +$a = [ + 'new' => '新簽約', + 'free_to_charge' => '免保轉有費', + 'renew_priceissue' => '續約' +]; +$b = [ + 'one' => '一年', + 'above_two' => '一年以上' +]; - -for($i = 0; $i"; echo "計算結果:" . $result["result_status"] . "
"; + echo "輸入參數說明: " . $a[$examination_array[$i][1]] . "、" . $b[$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] . "
"; 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] . "
"; - 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]["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/bonus/other/maintenance_contract_bonus_v2_1.php b/wms/bonus/other/maintenance_contract_bonus_v2_1.php index 9015a83c..0f6d3227 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1.php @@ -46,8 +46,8 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, // $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, 2); + // $discount = ($fee_per_st - $commission_fee) / $elevator_list_price; #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) switch ($contract_type) { diff --git a/wms/contract/api/T8api.php b/wms/contract/api/T8api.php index 88d8dffa..88cbd8ad 100644 --- a/wms/contract/api/T8api.php +++ b/wms/contract/api/T8api.php @@ -12,7 +12,7 @@ function T8salIncomeApply($data, $api_url) // exit; $header = [ "CHI_Authorization :" . $validation, - "GroupId:MASADA" + "GroupId:TEST" ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $api_url); // 设置请求的URL diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php index e2aedd43..60519045 100644 --- a/wms/contract/api/getContractData.php +++ b/wms/contract/api/getContractData.php @@ -24,10 +24,9 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont $stmt->execute(); $elevators = $stmt->fetchAll(PDO::FETCH_ASSOC); $count = COUNT($elevators); - // foreach ($elevators as $key => $elevator) { - - // $elevator['discount'] = ($elevator['sold_price'] / $elevator['stand_price']) * 100; - // } + foreach ($elevators as $key => $elevator) { + $elevator['discount'] = round(($elevator['sold_price'] / $elevator['stand_price']), 2); + } $contract['elevators'] = $elevators; $contract['num'] = $count; @@ -150,28 +149,13 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont foreach ($option_results as $key => $option) { if ($option['item_qty'] == $result['item_qty']) { $result['option_price'] += intval($option['item_unit_price']); - // echo '1..'; - // echo "
";
-                        // print_r($option['item_unit_price']);
-                        // echo "
"; } else if ($option['item_qty'] / $result['item_qty'] != 1) { $item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數 $result['option_price'] += intval($option['item_unit_price']) * $item_qty; - // echo '2..'; - // echo "
";
-                        // print_r(intval($option['item_unit_price']) . ' *' . $item_qty . '=' . intval($option['item_unit_price']) * $item_qty);
-                        // echo "
"; } else { $result['option_price'] += $option['item_unit_price'] * intval($option['item_qty']); - // echo '3..'; } - // echo '
';
-                    // print_r($option['item_no'] . '--->' . $option['item_unit_price'] . '--->' . $option['item_qty']);
-                    // echo '
'; } - - // print_r($result['option_price']); - // exit(); } // 查詢保固延長 $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='E' AND option_relate_spec = :item_no"; diff --git a/wms/contract/api/getT8NewContractData.php b/wms/contract/api/getT8NewContractData.php index 2d348558..4b5d0513 100644 --- a/wms/contract/api/getT8NewContractData.php +++ b/wms/contract/api/getT8NewContractData.php @@ -3,7 +3,8 @@ require_once('../conn.php'); $sql = "SELECT BillNo, -- 合約號 - OAmount -- 合約未稅金額 + OAmount, -- 合約未稅金額 + OAmountWithTax -- 含稅金額 FROM salSalesOrder WHERE 1=1"; $stmt = $connT8->prepare($sql); $stmt->execute(); @@ -19,41 +20,76 @@ foreach ($result as $key => $result) { $no = $result['BillNo']; $result_master['BillNo'] = $no; $firstChar = substr($no, 0, 1); - if ($firstChar == 'M' && $key <= 100) { + if ($firstChar == 'M' && $key <= 50) { + // 查詢客戶名稱 是否為戰略客戶 $sql = "SELECT BizPartnerName FROM comBusinessPartner WHERE BizPartnerId = '$no' "; $stmt = $connT8->prepare($sql); $stmt->execute(); $customer_name = $stmt->fetch(PDO::FETCH_ASSOC); - // $result_master[] = $result; - $sql = "SELECT + + // 查詢作番號,與每台電梯在合約的價格、站比 + $sql = "SELECT * FROM salSalesOrderDetail WHERE BillNo = '$no' AND ItemType = 0"; + $stmt = $connT8->prepare($sql); + $stmt->execute(); + $elevator_facilityno = $stmt->fetchAll(PDO::FETCH_ASSOC); + foreach ($elevator_facilityno as $elevator) { + $facilityno = $elevator['MaterialId']; + $sql = "SELECT + BillNo, + MaterialId, + OAmountWithTax, -- 含稅金額 + SPrice --未稅 + FROM salSalesOrderDetail WHERE BillNo = '$no' AND CU_MaterialId = '$facilityno' AND ItemType = '1' "; + $stmt = $connT8->prepare($sql); + $stmt->execute(); + $elevator_amount = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // 單台電梯價格 + $elevator_price = 0; + foreach ($elevator_amount as $amount) { + $elevator_price = $elevator_price + intval($amount['SPrice']); + } + //電梯在合約內所佔的比例 + $elevator_prince_proportion = intval($result['OAmount']) / $elevator_price; + // exit; + + $sql = "SELECT BillNo, -- 合約號 PayStage, -- 收款階段 PlanPercentage, -- 收款比例 PlanPayAmt -- 收款金額 FROM salOrderStagePay WHERE BillNo = '$no'"; - $stmt = $connT8->prepare($sql); - $stmt->execute(); - $Detail = $stmt->fetchAll(PDO::FETCH_ASSOC); - if (!empty($Detail)) { - foreach ($Detail as $key => $detail) { - $detail['PlanPercentage'] = (float)$detail['PlanPercentage']; - $Detail[$key]['PlanPercentage'] = $detail['PlanPercentage']; // 比例轉小數第二位 - $Detail[$key]['PlanPayAmt'] = intval($detail['PlanPayAmt']); // 比例金額轉整數 + $stmt = $connT8->prepare($sql); + $stmt->execute(); + $Detail = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (!empty($Detail)) { + foreach ($Detail as $key => $detail) { + $elevator_inContract_payPrice = $elevator_prince_proportion * $detail['PlanPercentage']; + $Detail[$key]['facilityno'] = $facilityno; + $detail['PlanPercentage'] = (float)$detail['PlanPercentage']; + $Detail[$key]['PlanPercentage'] = $detail['PlanPercentage']; // 比例轉小數第二位 + $Detail[$key]['contract_price_total'] = intval($detail['PlanPayAmt']); // 比例金額轉整數 + $Detail[$key]['elevator_inContract_payPrice'] = round($elevator_inContract_payPrice * intval($detail['PlanPayAmt']), 2); + } - } + if (mb_substr($Detail[0]['PayStage'], 0, 2) == '寶佳') { + $result_master['customer_status'] = 'strategy_customer'; + } else if (!empty($customer_name) && mb_substr($customer_name['BizPartnerName'], 0, 1) == '【') { + $result_master['customer_status'] = 'strategy_customer'; + } else { + $result_master['customer_status'] = 'general_customer'; + } - if (mb_substr($Detail[0]['PayStage'], 0, 2) == '寶佳') { - $result_master['customer_status'] = 'strategy_customer'; - } else if (!empty($customer_name) && mb_substr($customer_name['BizPartnerName'], 0, 1) == '【') { - $result_master['customer_status'] = 'strategy_customer'; - } else { - $result_master['customer_status'] = 'general_customer'; + $result_master['total_price'] = intval($result['OAmount']); + $result_master['elevotor_pay_detail'] = $Detail; + $result_arr[] = $result_master; + // echo "
";
+                // print_r($result_arr);
+                // echo "
"; } - - $result_master['total_price'] = intval($result['OAmount']); - $result_master['detail'] = $Detail; - $result_arr[] = $result_master; } + // exit; + // $result_master[] = $result; } } diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index 9522defe..0a80ae1b 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -10,383 +10,393 @@ include_once("./upload_chk.php"); ini_set('date.timezone', 'Asia/Taipei'); //保養簽回 if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['contracttype']) && $_POST['contracttype'] == 'b') { - try { - $created_at = date('Y-m-d H:i:s'); - $contractno = !empty($_POST['contractno']) ? $_POST['contractno'] : null; - $total_price = !empty($_POST['total_price']) ? $_POST['total_price'] : null; - $vat = !empty($_POST['vat']) ? $_POST['vat'] : null; - $mtype = !empty($_POST['mtype']) ? $_POST['mtype'] : null; - $opendoor = !empty($_POST['opendoor']) ? $_POST['opendoor'] : null; - $phone = !empty($_POST['phone']) ? $_POST['phone'] : null; - $email = !empty($_POST['email']) ? $_POST['email'] : null; - $mworker = !empty($_POST['mworker']) ? $_POST['mworker'] : null; - // $mcycle = !empty($_POST['mcycle']) ? $_POST['mcycle'] : null; - $salesman = !empty($_POST['salesman']) ? $_POST['salesman'] : null; - $contract_begin_date = !empty($_POST['contract_begin_date']) ? $_POST['contract_begin_date'] : null; - $contract_end_date = !empty($_POST['contract_end_date']) ? $_POST['contract_end_date'] : null; - $address = !empty($_POST['address']) ? $_POST['address'] : null; - $area = !empty($_POST['area']) ? $_POST['area'] : null; - $customer = !empty($_POST['customer']) ? $_POST['customer'] : null; - $partyA = !empty($_POST['partyA']) ? $_POST['partyA'] : null; - $partyAaddress = !empty($_POST['partyAaddress']) ? $_POST['partyAaddress'] : null; - $partyAphone = !empty($_POST['partyAphone']) ? $_POST['partyAphone'] : null; - $partyAemail = !empty($_POST['partyAemail']) ? $_POST['partyAemail'] : null; - $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; - $user_name = !empty($_POST['user_name']) ? $_POST['user_name'] : null; - $num = !empty($_POST['num']) ? $_POST['num'] : null; - $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); - $stmt->execute(); - $accountData = $stmt->fetch(PDO::FETCH_ASSOC); - - $depId = $accountData['department_id']; - // validate - //create facility table - $createFacilityNo = new CreateFacilityNo(); - $dailyNecessities = [ - 'MAE100' => 'X', - 'MAM200' => 'W', - 'MAH100' => 'H', - 'MAQ100' => 'Z', - 'MAF100' => 'F', - 'MAZ100' => 'B', - ]; - - $maintain_times = [ - '1' => 'em', //月保 - '2' => 'bw' // 雙周保 - ]; - $facility_arr = []; - foreach ($elevators as $elevator) { - $facility_arr[] = $dailyNecessities[$elevator['spec']]; - } - echo json_encode($facility_arr); - // 電梯做番號 - $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); - echo json_encode($facilityno); - T8insert($_POST, $facilityno, $depId, $connT8); - // if ($user_id == 'M0225') { - // echo '
';
-        //     print_r($facilityno);
-        //     echo '
'; - // exit(); - // } - $fail_arr = []; - if ($contractno === '') return $fail_arr[] = '合約號為必填'; - if ($total_price == '') $fail_arr[] = '合約總價為必填'; - if ($vat == '') $fail_arr[] = '統一編號為必填'; - if ($mtype == '') $fail_arr[] = '維修型態為必填'; - if ($phone == '') $fail_arr[] = '客戶電話為必填'; - // if ($email == '') $fail_arr[] = 'Email為必填'; - if ($mworker == '') $fail_arr[] = '保養員為必填'; - // if ($mcycle == '') $fail_arr[] = '保養頻率為必填'; - if ($salesman == '') $fail_arr[] = '營業員為必填'; - if ($contract_begin_date == '') $fail_arr[] = '合約開始時間為必填'; - if ($contract_end_date == '') $fail_arr[] = '合約結束時間為必填'; - 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 ($num == '') $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(); - } - /// 獎金計算 - $aaa = bonusCreate($_POST, $facilityno, $conn); - if (!empty($aaa) && $aaa['status'] == 2) { - header("HTTP/1.1 422 Unprocessable Entity"); - echo $aaa['data']; - exit(); - } - //create account table - $accounttype = "A"; - $accountid = $vat; - $pwd = "123"; - $name = $partyA; - $tel = $phone ?? ''; - $repairerid = $mworker; - $creater = $user_id; - $create_at = date('Y-m-d H:i:s'); - - $conn->beginTransaction(); + // try { + $created_at = date('Y-m-d H:i:s'); + $contractno = !empty($_POST['contractno']) ? $_POST['contractno'] : null; + $total_price = !empty($_POST['total_price']) ? $_POST['total_price'] : null; + $vat = !empty($_POST['vat']) ? $_POST['vat'] : null; + $mtype = !empty($_POST['mtype']) ? $_POST['mtype'] : null; + $opendoor = !empty($_POST['opendoor']) ? $_POST['opendoor'] : null; + $phone = !empty($_POST['phone']) ? $_POST['phone'] : null; + $email = !empty($_POST['email']) ? $_POST['email'] : null; + $mworker = !empty($_POST['mworker']) ? $_POST['mworker'] : ''; + // $mcycle = !empty($_POST['mcycle']) ? $_POST['mcycle'] : null; + $salesman = !empty($_POST['salesman']) ? $_POST['salesman'] : null; + $contract_begin_date = !empty($_POST['contract_begin_date']) ? $_POST['contract_begin_date'] : null; + $contract_end_date = !empty($_POST['contract_end_date']) ? $_POST['contract_end_date'] : null; + $address = !empty($_POST['address']) ? $_POST['address'] : null; + $area = !empty($_POST['area']) ? $_POST['area'] : null; + $customer = !empty($_POST['customer']) ? $_POST['customer'] : null; + $partyA = !empty($_POST['partyA']) ? $_POST['partyA'] : null; + $partyAaddress = !empty($_POST['partyAaddress']) ? $_POST['partyAaddress'] : null; + $partyAphone = !empty($_POST['partyAphone']) ? $_POST['partyAphone'] : null; + $partyAemail = !empty($_POST['partyAemail']) ? $_POST['partyAemail'] : null; + $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; + $user_name = !empty($_POST['user_name']) ? $_POST['user_name'] : null; + $num = !empty($_POST['num']) ? $_POST['num'] : null; + $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; + $signing_date = !empty($_POST['signing_date']) ? $_POST['signing_date'] : null; + + $sql = "SELECT * FROM account WHERE accountid = '$salesman'"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $accountData = $stmt->fetch(PDO::FETCH_ASSOC); + + $depId = $accountData['department_id']; + // validate + //create facility table + $createFacilityNo = new CreateFacilityNo(); + $dailyNecessities = [ + 'MAE100' => 'X', + 'MAM200' => 'W', + 'MAH100' => 'H', + 'MAQ100' => 'Z', + 'MAF100' => 'F', + 'MAZ100' => 'B', + ]; - $sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)"; + $maintain_times = [ + '1' => 'em', //月保 + '2' => 'bw' // 雙周保 + ]; + $facility_arr = []; + foreach ($elevators as $elevator) { + $facility_arr[] = $dailyNecessities[$elevator['spec']]; + } + echo json_encode($facility_arr); + // 電梯做番號 + $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); + echo json_encode($facilityno); + T8insert($_POST, $facilityno, $depId, $connT8); + // exit(); + // if ($user_id == 'M0225') { + // echo '
';
+    //     print_r($facilityno);
+    //     echo '
'; + // exit(); + // } + $fail_arr = []; + if ($contractno === '') return $fail_arr[] = '合約號為必填'; + if ($total_price == '') $fail_arr[] = '合約總價為必填'; + if ($salesman == '') $fail_arr[] = '營業員為必填'; + if ($contract_begin_date == '') $fail_arr[] = '合約開始時間為必填'; + if ($contract_end_date == '') $fail_arr[] = '合約結束時間為必填'; + if ($address == '') $fail_arr[] = '地址為必填'; + if ($area == '') $fail_arr[] = '區域為必填'; + if ($customer == '') $fail_arr[] = '客戶為必填'; + if ($num == '') $fail_arr[] = '電梯數量為必填'; + if ($payType == '') $fail_arr[] = '分期方式為必填'; + if ($contract_type == '') $fail_arr[] = '合約類別為必填'; + + //------------------- + // if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; + // if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; + // if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; + // if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; + // if ($vat == '') $fail_arr[] = '統一編號為必填'; + // if ($mtype == '') $fail_arr[] = '維修型態為必填'; + // if ($phone == '') $fail_arr[] = '客戶電話為必填'; + // if ($email == '') $fail_arr[] = 'Email為必填'; + // if ($mworker == '') $fail_arr[] = '保養員為必填'; + // if ($mcycle == '') $fail_arr[] = '保養頻率為必填'; + if (count($fail_arr) > 0) { + header("HTTP/1.1 422 Unprocessable Entity"); + echo json_encode($fail_arr); + exit(); + } + /// 獎金計算 + $aaa = bonusCreate($_POST, $facilityno, $conn); + if (!empty($aaa) && $aaa['status'] == 2) { + header("HTTP/1.1 422 Unprocessable Entity"); + echo $aaa['data']; + exit(); + } + // exit(); + //create account table + $accounttype = "A"; + $accountid = $vat; + $pwd = "123"; + $name = $partyA; + $tel = $phone ?? ''; + $repairerid = $mworker; + $creater = $user_id; + $create_at = date('Y-m-d H:i:s'); + + // exit(); + + + + $conn->beginTransaction(); + + $sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)"; + $stmt = $conn->prepare($sql_str); + $stmt->bindParam(':accounttype', $accounttype); + $stmt->bindParam(':accountid', $accountid); + $stmt->bindParam(':pwd', $pwd); + $stmt->bindParam(':name', $name); + $stmt->bindParam(':tel', $tel); + $stmt->bindParam(':address', $address); + $stmt->bindParam(':email', $email); + $stmt->bindParam(':repairerid', $repairerid); + $stmt->bindParam(':creater', $creater); + $stmt->bindParam(':create_at', $create_at); + // $stmt->execute(); + + //create contract table + + $contracttype = $mtype; + $company = $partyA; + $taxid = $vat; + $tel = $phone; + $promiser = $partyA; + $contractperson = $partyA; + + $contractaddress = $address; + $contracttel = $phone; + $contractemail = $email; + $contract_employee = $salesman; + $start_date = $contract_begin_date; + $end_date = $contract_end_date; + + $sql_str = "INSERT INTO contract (contracttype, contractno, company, taxid, address, tel, promiser, contractperson, contractaddress, contracttel, contractemail, contract_employee, start_date, end_date, creater, create_at) VALUES (:contracttype, :contractno, :company, :taxid, :address, :tel, :promiser, :contractperson, :contractaddress, :contracttel, :contractemail, :contract_employee, :start_date, :end_date, :creater, :create_at)"; + $stmt = $conn->prepare($sql_str); + $stmt->bindParam(':contracttype', $contracttype); + $stmt->bindParam(':contractno', $contractno); + $stmt->bindParam(':company', $company); + $stmt->bindParam(':taxid', $taxid); + $stmt->bindParam(':address', $address); + $stmt->bindParam(':tel', $tel); + $stmt->bindParam(':promiser', $promiser); + $stmt->bindParam(':contractperson', $contractperson); + $stmt->bindParam(':contractaddress', $contractaddress); + $stmt->bindParam(':contracttel', $contracttel); + $stmt->bindParam(':contractemail', $contractemail); + $stmt->bindParam(':contract_employee', $contract_employee); + $stmt->bindParam(':start_date', $start_date); + $stmt->bindParam(':end_date', $end_date); + $stmt->bindParam(':creater', $creater); + $stmt->bindParam(':create_at', $create_at); + // $stmt->execute(); + + //create facility table + // $createFacilityNo = new CreateFacilityNo(); + // $dailyNecessities = [ + // 'MAE100' => 'X', + // 'MAM200' => 'W', + // 'MAH100' => 'H', + // 'MAQ100' => 'Z', + // 'MAF100' => 'F', + // 'MAZ100' => 'B', + // ]; + + // $maintain_times = [ + // '1' => 'em', //月保 + // '2' => 'bw' // 雙周保 + // ]; + // $facility_arr = []; + // foreach ($elevators as $elevator) { + // $facility_arr[] = $dailyNecessities[$elevator['spec']]; + // } + // echo json_encode($facility_arr); + // // 電梯做番號 + // $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); + // // if ($user_id == 'M0225') { + // // echo '
';
+    // //     print_r($facilityno);
+    // //     echo '
'; + // // exit(); + // // } + // echo json_encode($facilityno); + // echo '-------'; + $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid"; + $stmt = $conn->prepare($sql_str); + $stmt->bindParam(':accountid', $mworker); + $stmt->execute(); + $worker = $stmt->fetch(PDO::FETCH_ASSOC); + $customerid = $vat; + $define = "B"; + $repairtype = $mtype; + $repairerid = $mworker; + $repairername = $worker['name']; + foreach ($elevators as $idx => $elevator) { + // 民國年轉換西元年 + $ROCuseful_date = $elevator['useful_date']; + $click = explode("-", $ROCuseful_date); + $click[0] = intval($click[0]) + 1911; + $ADuseful_date = implode("-", $click); + + $sql_str = "INSERT INTO facility (contractno, define, facilityno, latitude, longitude, customerid, weight, numberofpassenger, numberofstop, numberoffloor, opentype, speed, repairtype, maintainance, facility_kind, address, repairerid, repairername, creater, create_at, area, takecertificatedate, licensedate) + VALUES (:contractno, :define, :facilityno, :latitude, :longitude, :customerid, :weight, :numberofpassenger, :numberofstop, :numberoffloor, :opentype, :speed, :repairtype, :maintainance, :facility_kind, :address, :repairerid, :repairername, :creater, :create_at, :area, :takecertificatedate, :licensedate)"; $stmt = $conn->prepare($sql_str); - $stmt->bindParam(':accounttype', $accounttype); - $stmt->bindParam(':accountid', $accountid); - $stmt->bindParam(':pwd', $pwd); - $stmt->bindParam(':name', $name); - $stmt->bindParam(':tel', $tel); + $stmt->bindParam(':contractno', $contractno); + $stmt->bindParam(':define', $define); + $stmt->bindParam(':facilityno', $facilityno[$idx]); + $stmt->bindParam(':latitude', $elevator['latitude']); + $stmt->bindParam(':longitude', $elevator['longitude']); + $stmt->bindParam(':customerid', $customerid); + $stmt->bindParam(':weight', $elevator['weight']); + $stmt->bindParam(':numberofpassenger', $elevator['persons']); + $stmt->bindParam(':numberofstop', $elevator['stop']); + $stmt->bindParam(':numberoffloor', $elevator['floors']); + $stmt->bindParam(':opentype', $elevator['opendoor']); + $stmt->bindParam(':speed', $elevator['speed']); + $stmt->bindParam(':repairtype', $repairtype); + $stmt->bindParam(':maintainance', $elevator['maintainance']); + $stmt->bindParam(':facility_kind', $elevator['spec']); $stmt->bindParam(':address', $address); - $stmt->bindParam(':email', $email); $stmt->bindParam(':repairerid', $repairerid); + $stmt->bindParam(':repairername', $repairername); $stmt->bindParam(':creater', $creater); $stmt->bindParam(':create_at', $create_at); - $stmt->execute(); - - //create contract table - - $contracttype = $mtype; - $company = $partyA; - $taxid = $vat; - $tel = $phone; - $promiser = $partyA; - $contractperson = $partyA; - - $contractaddress = $address; - $contracttel = $phone; - $contractemail = $email; - $contract_employee = $salesman; - $start_date = $contract_begin_date; - $end_date = $contract_end_date; + $stmt->bindParam(':area', $area); + $stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']); + $stmt->bindParam(':licensedate', $ADuseful_date); + // $result = $stmt->execute(); + } - $sql_str = "INSERT INTO contract (contracttype, contractno, company, taxid, address, tel, promiser, contractperson, contractaddress, contracttel, contractemail, contract_employee, start_date, end_date, creater, create_at) VALUES (:contracttype, :contractno, :company, :taxid, :address, :tel, :promiser, :contractperson, :contractaddress, :contracttel, :contractemail, :contract_employee, :start_date, :end_date, :creater, :create_at)"; - $stmt = $conn->prepare($sql_str); - $stmt->bindParam(':contracttype', $contracttype); - $stmt->bindParam(':contractno', $contractno); - $stmt->bindParam(':company', $company); - $stmt->bindParam(':taxid', $taxid); - $stmt->bindParam(':address', $address); - $stmt->bindParam(':tel', $tel); - $stmt->bindParam(':promiser', $promiser); - $stmt->bindParam(':contractperson', $contractperson); - $stmt->bindParam(':contractaddress', $contractaddress); - $stmt->bindParam(':contracttel', $contracttel); - $stmt->bindParam(':contractemail', $contractemail); - $stmt->bindParam(':contract_employee', $contract_employee); - $stmt->bindParam(':start_date', $start_date); - $stmt->bindParam(':end_date', $end_date); - $stmt->bindParam(':creater', $creater); - $stmt->bindParam(':create_at', $create_at); - $stmt->execute(); + //create schedule table - //create facility table - // $createFacilityNo = new CreateFacilityNo(); - // $dailyNecessities = [ - // 'MAE100' => 'X', - // 'MAM200' => 'W', - // 'MAH100' => 'H', - // 'MAQ100' => 'Z', - // 'MAF100' => 'F', - // 'MAZ100' => 'B', - // ]; - - // $maintain_times = [ - // '1' => 'em', //月保 - // '2' => 'bw' // 雙周保 - // ]; - // $facility_arr = []; - // foreach ($elevators as $elevator) { - // $facility_arr[] = $dailyNecessities[$elevator['spec']]; - // } - // echo json_encode($facility_arr); - // // 電梯做番號 - // $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); - // // if ($user_id == 'M0225') { - // // echo '
';
-        // //     print_r($facilityno);
-        // //     echo '
'; - // // exit(); - // // } - // echo json_encode($facilityno); - // echo '-------'; - $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid"; - $stmt = $conn->prepare($sql_str); - $stmt->bindParam(':accountid', $mworker); - $stmt->execute(); - $worker = $stmt->fetch(PDO::FETCH_ASSOC); - $customerid = $vat; - $define = "B"; - $repairtype = $mtype; - $repairerid = $mworker; - $repairername = $worker['name']; - foreach ($elevators as $idx => $elevator) { - // 民國年轉換西元年 - $ROCuseful_date = $elevator['useful_date']; - $click = explode("-", $ROCuseful_date); - $click[0] = intval($click[0]) + 1911; - $ADuseful_date = implode("-", $click); - - $sql_str = "INSERT INTO facility (contractno, define, facilityno, latitude, longitude, customerid, weight, numberofpassenger, numberofstop, numberoffloor, opentype, speed, repairtype, maintainance, facility_kind, address, repairerid, repairername, creater, create_at, area, takecertificatedate, licensedate) - VALUES (:contractno, :define, :facilityno, :latitude, :longitude, :customerid, :weight, :numberofpassenger, :numberofstop, :numberoffloor, :opentype, :speed, :repairtype, :maintainance, :facility_kind, :address, :repairerid, :repairername, :creater, :create_at, :area, :takecertificatedate, :licensedate)"; + // $comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date); + // $comboArr = json_decode($comboNo->getComboNo(), true); + foreach ($facilityno as $no) { + $comboNo = new CreateComboNo($maintain_times[$elevator['maintain_times']], $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(':define', $define); - $stmt->bindParam(':facilityno', $facilityno[$idx]); - $stmt->bindParam(':latitude', $elevator['latitude']); - $stmt->bindParam(':longitude', $elevator['longitude']); - $stmt->bindParam(':customerid', $customerid); - $stmt->bindParam(':weight', $elevator['weight']); - $stmt->bindParam(':numberofpassenger', $elevator['persons']); - $stmt->bindParam(':numberofstop', $elevator['stop']); - $stmt->bindParam(':numberoffloor', $elevator['floors']); - $stmt->bindParam(':opentype', $elevator['opendoor']); - $stmt->bindParam(':speed', $elevator['speed']); - $stmt->bindParam(':repairtype', $repairtype); - $stmt->bindParam(':maintainance', $elevator['maintainance']); - $stmt->bindParam(':facility_kind', $elevator['spec']); - $stmt->bindParam(':address', $address); + $stmt->bindParam(':facilityno', $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); - $stmt->bindParam(':area', $area); - $stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']); - $stmt->bindParam(':licensedate', $ADuseful_date); - $result = $stmt->execute(); + // $result = $stmt->execute(); } - - //create schedule table - - // $comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date); - // $comboArr = json_decode($comboNo->getComboNo(), true); - foreach ($facilityno as $no) { - $comboNo = new CreateComboNo($maintain_times[$elevator['maintain_times']], $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', $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(); - } + } + // create contract_b_signed_back table + $contract_type = $mtype; + $company = $customer; + $customer_no = $vat; + $salesperson = $salesman; + $customer_phone = $phone; + $customer_email = $email; + $repairman = $mworker; + // $cycle = $mcycle; + $contact_person = $partyA; + $contact_address = $partyAaddress; + $contact_phone = $partyAphone; + $contract_email = $partyAemail; + $elevators_number = $num; + $bonus = 1000; + $max_bonus = 2000; + + if (!empty($files)) { + $englisharr = range('a', 'z'); + $file = $_FILES['files']; + $file_name = $file['name']; + $file_type = $file['type']; + $tmp_name = $file['tmp_name']; + $file_size = $file['size']; + $error = $file['error']; + $newfiles = []; + foreach ($files as $file) { + $i = 0; //新陣列的索引編號 + foreach ($file as $key => $val) { + $newfiles[$i]['name'] = $files['name'][$key]; + $newfiles[$i]['type'] = $files['type'][$key]; + $newfiles[$i]['tmp_name'] = $files['tmp_name'][$key]; + $newfiles[$i]['error'] = $files['error'][$key]; + $newfiles[$i]['size'] = $files['size'][$key]; + $i++; + } //foreach 第2層 end } - // create contract_b_signed_back table - $contract_type = $mtype; - $company = $customer; - $customer_no = $vat; - $salesperson = $salesman; - $customer_phone = $phone; - $customer_email = $email; - $repairman = $mworker; - // $cycle = $mcycle; - $contact_person = $partyA; - $contact_address = $partyAaddress; - $contact_phone = $partyAphone; - $contract_email = $partyAemail; - $elevators_number = $num; - $bonus = 1000; - $max_bonus = 2000; - - if (!empty($files)) { - $englisharr = range('a', 'z'); - $file = $_FILES['files']; - $file_name = $file['name']; - $file_type = $file['type']; - $tmp_name = $file['tmp_name']; - $file_size = $file['size']; - $error = $file['error']; - $newfiles = []; - foreach ($files as $file) { - $i = 0; //新陣列的索引編號 - foreach ($file as $key => $val) { - $newfiles[$i]['name'] = $files['name'][$key]; - $newfiles[$i]['type'] = $files['type'][$key]; - $newfiles[$i]['tmp_name'] = $files['tmp_name'][$key]; - $newfiles[$i]['error'] = $files['error'][$key]; - $newfiles[$i]['size'] = $files['size'][$key]; - $i++; - } //foreach 第2層 end - } - $max_size = 4096 * 4096; //設定允許上傳檔案容量的最大值(1M) - $allow_ext = array('jpeg', 'jpg', 'png', 'JPG', 'JPEG', 'PNG', 'GIF'); //設定允許上傳檔案的類型 - $path = '../images/contracts/'; - if (!file_exists($path)) { - mkdir($path); + $max_size = 4096 * 4096; //設定允許上傳檔案容量的最大值(1M) + $allow_ext = array('jpeg', 'jpg', 'png', 'JPG', 'JPEG', 'PNG', 'GIF'); //設定允許上傳檔案的類型 + $path = '../images/contracts/'; + if (!file_exists($path)) { + mkdir($path); + } + $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 + $datetime = (string)date('YmdHis'); + $files_id = 'b' . $datetime; // 保養=>b + 日期時間 + foreach ($newfiles as $key => $file) { + $randNum = rand(1000, 9999); + $randEnglish = $englisharr[rand(0, 25)]; + $file_name = 'b' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum . $file['name']; + $msg = upload_chk($file, $path, $max_size, $allow_ext, $file_name); + if ($msg == 1) { + $msg = '檔案傳送成功!'; + $sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)"; + $stmt = $conn->prepare($sql_str); + $stmt->bindParam(':files_id', $files_id); + $stmt->bindParam(':file_name', $file_name); + $stmt->bindParam(':file_mime', $file['type']); + $stmt->bindParam(':file_size', $file['size']); + $stmt->bindParam(':created_at', $created_at); + $stmt->bindParam(':created_by', $user_id); + $stmt->execute(); } - $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 - $datetime = (string)date('YmdHis'); - $files_id = 'b' . $datetime; // 保養=>b + 日期時間 - foreach ($newfiles as $key => $file) { - $randNum = rand(1000, 9999); - $randEnglish = $englisharr[rand(0, 25)]; - $file_name = 'b' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum . $file['name']; - $msg = upload_chk($file, $path, $max_size, $allow_ext, $file_name); - if ($msg == 1) { - $msg = '檔案傳送成功!'; - $sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)"; - $stmt = $conn->prepare($sql_str); - $stmt->bindParam(':files_id', $files_id); - $stmt->bindParam(':file_name', $file_name); - $stmt->bindParam(':file_mime', $file['type']); - $stmt->bindParam(':file_size', $file['size']); - $stmt->bindParam(':created_at', $created_at); - $stmt->bindParam(':created_by', $user_id); - $stmt->execute(); - } - $msg_result .= '第' . ($key + 1) . '個上傳檔案的結果:' . $msg . '
'; - $src_name = $path . $file['name']; - if (file_exists($src_name)) { - //副檔名 - $extname = pathinfo($src_name, PATHINFO_EXTENSION); - //主檔名 - $basename = basename($src_name, '.' . $extname); - } + $msg_result .= '第' . ($key + 1) . '個上傳檔案的結果:' . $msg . '
'; + $src_name = $path . $file['name']; + if (file_exists($src_name)) { + //副檔名 + $extname = pathinfo($src_name, PATHINFO_EXTENSION); + //主檔名 + $basename = basename($src_name, '.' . $extname); } - } else { - $files = null; } - $sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price,payType, customer_phone, customer_email, repairman, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by) - VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :payType ,:customer_phone, :customer_email, :repairman, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by)"; - $stmt = $conn->prepare($sql_str); - $stmt->bindParam(":contract_no", $contractno); - $stmt->bindParam(":contract_type", $contract_type); - $stmt->bindParam(":company", $company); - $stmt->bindParam(":customer_no", $customer_no); - $stmt->bindParam(":salesperson", $salesperson); - $stmt->bindParam(":contract_start_date", $contract_begin_date); - $stmt->bindParam(":contract_end_date", $contract_end_date); - $stmt->bindParam(":total_price", $total_price); - $stmt->bindParam(":customer_phone", $customer_phone); - $stmt->bindParam(":customer_email", $customer_email); - $stmt->bindParam(":repairman", $repairman); - // $stmt->bindParam(":cycle", $cycle); // 保養頻率在做番上,這邊不 insert。 - $stmt->bindParam(":contact_person", $contact_person); - $stmt->bindParam(":contact_address", $contact_address); - $stmt->bindParam(":contact_phone", $contact_phone); - $stmt->bindParam(":contact_email", $contact_email); - $stmt->bindParam(":elevators_number", $elevators_number); - $stmt->bindParam(":area", $area); - $stmt->bindParam(":address", $address); - $stmt->bindParam(":files_id", $files_id); - $stmt->bindParam(":bonus", $bonus); - $stmt->bindParam(":max_bonus", $max_bonus); - $stmt->bindParam(":created_at", $created_at); - $stmt->bindParam(":created_by", $user_id); - $stmt->bindParam(':payType', $payType); - - $stmt->execute(); - - // T8insert($_POST, $facilityno); - - header('Content-Type: application/json'); - $jsonData = json_encode($files); - - $conn->commit(); - } catch (PDOException $e) { - $conn->rollback(); - http_response_code(404); - echo $e->getMessage(); - die('Error!:' . $e->getMessage()); + } else { + $files = null; } + $sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price,payType, customer_phone, customer_email, repairman, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by,signing_date) + VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :payType ,:customer_phone, :customer_email, :repairman, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by,:signing_date)"; + $stmt = $conn->prepare($sql_str); + $stmt->bindParam(":contract_no", $contractno); + $stmt->bindParam(":contract_type", $contract_type); + $stmt->bindParam(":company", $company); + $stmt->bindParam(":customer_no", $customer_no); + $stmt->bindParam(":salesperson", $salesperson); + $stmt->bindParam(":contract_start_date", $contract_begin_date); + $stmt->bindParam(":contract_end_date", $contract_end_date); + $stmt->bindParam(":total_price", $total_price); + $stmt->bindParam(":customer_phone", $customer_phone); + $stmt->bindParam(":customer_email", $customer_email); + $stmt->bindParam(":repairman", $repairman); + // $stmt->bindParam(":cycle", $cycle); // 保養頻率在做番上,這邊不 insert。 + $stmt->bindParam(":contact_person", $contact_person); + $stmt->bindParam(":contact_address", $contact_address); + $stmt->bindParam(":contact_phone", $contact_phone); + $stmt->bindParam(":contact_email", $contact_email); + $stmt->bindParam(":elevators_number", $elevators_number); + $stmt->bindParam(":area", $area); + $stmt->bindParam(":address", $address); + $stmt->bindParam(":files_id", $files_id); + $stmt->bindParam(":bonus", $bonus); + $stmt->bindParam(":max_bonus", $max_bonus); + $stmt->bindParam(":created_at", $created_at); + $stmt->bindParam(":created_by", $user_id); + $stmt->bindParam(':payType', $payType); + $stmt->bindParam(':signing_date', $signing_date); + + // $stmt->execute(); + + // T8insert($_POST, $facilityno); + + header('Content-Type: application/json'); + $jsonData = json_encode($files); + + $conn->commit(); + // } catch (PDOException $e) { + // $conn->rollback(); + // http_response_code(404); + // echo $e->getMessage(); + // die('Error!:' . $e->getMessage()); + // } }; function T8insert($data, $facilityno, $depId, $connT8) @@ -401,20 +411,21 @@ function T8insert($data, $facilityno, $depId, $connT8) $customer = !empty($data['customer']) ? $data['customer'] : null; //企業名稱 $phone = !empty($data['phone']) ? $data['phone'] : null; //客戶電話 $vat = !empty($data['vat']) ? $data['vat'] : null; //統編 - $email = !empty($data['email']) ? $data['email'] : null; + // $email = !empty($data['email']) ? $data['email'] : null; $salesman = !empty($data['salesman']) ? $data['salesman'] : null; // 銷售人員 - $partyA = !empty($data['partyA']) ? $data['partyA'] : null; //客戶名稱 / 業務聯絡人 - $partyAaddress = !empty($data['partyAaddress']) ? $data['partyAaddress'] : null; // 業務聯絡人地址 + $partyA = !empty($data['customer']) ? $data['customer'] : null; //客戶名稱 / 業務聯絡人 + // $partyAaddress = !empty($data['partyAaddress']) ? $data['partyAaddress'] : null; // 業務聯絡人地址 $contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : null; $contract_end_date = !empty($data['contract_end_date']) ? $data['contract_end_date'] : null; - $num = !empty($data['num']) ? $data['num'] : null; // 電梯數量 + // $num = !empty($data['num']) ? $data['num'] : null; // 電梯數量 $elevators = !empty($data['elevators']) ? json_decode($data['elevators'], true) : []; //電梯 - $area = !empty($data['area']) ? $data['area'] : null; //縣市 Ex. A->台北 , B-> ..。 + // $area = !empty($data['area']) ? $data['area'] : null; //縣市 Ex. A->台北 , B-> ..。 $payType = !empty($data['payType']) ? $data['payType'] : null; $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; + $invoice = !empty($_POST['invoice']) ? $_POST['invoice'] : ''; + $invoice_address = !empty($_POST['invoice_address']) ? $_POST['invoice_address'] : ''; - - $connT8->beginTransaction(); + // $connT8->beginTransaction(); $sql = "SELECT * FROM comCustomer WHERE BizPartnerId = :BizPartnerId"; $stmt = $connT8->prepare($sql); @@ -436,19 +447,18 @@ function T8insert($data, $facilityno, $depId, $connT8) // 若 客戶資料為空,新增一筆到 comCustomer // 新增客戶資料 $sql = "INSERT INTO comBusinessPartner - (BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,EMail,CreatorId,CreateTime,BizPartnerTypeId) - VALUES(:BizPartnerId,:BizPartnerName,1,'TW',:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:EMail,:CreatorId,:CreateTime,'10')"; + (BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,CreatorId,CreateTime,BizPartnerTypeId) + VALUES(:BizPartnerId,:BizPartnerName,1,'TW',:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:CreatorId,:CreateTime,'10')"; $stmt = $connT8->prepare($sql); $stmt->bindParam(':BizPartnerId', $contractno); $stmt->bindParam(':BizPartnerName', $partyA); $stmt->bindParam(':WorkTelNo', $phone); $stmt->bindParam(':TaxNo', $vat); - $stmt->bindParam(':EnterpriseName', $customer); //企業名稱 - $stmt->bindParam(':ContactAddress', $partyAaddress); - $stmt->bindParam(':EMail', $email); + $stmt->bindParam(':EnterpriseName', $invoice); //企業名稱 //發票抬頭 + $stmt->bindParam(':ContactAddress', $invoice_address); + // $stmt->bindParam(':EMail', $email); $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); $sql = "INSERT INTO comCustomer @@ -461,7 +471,6 @@ function T8insert($data, $facilityno, $depId, $connT8) $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':InvoiceAddress', $address); $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); } else { // // 若客戶資料不為空,更新該客戶資訊。 @@ -487,7 +496,7 @@ function T8insert($data, $facilityno, $depId, $connT8) TaxNo=:TaxNo, EnterpriseName=:EnterpriseName, ContactAddress=:ContactAddress, - EMail=:EMail, + -- EMail=:EMail, LastOperatorId=:LastOperatorId, LastOperateTime=:LastOperateTime WHERE BizPartnerId = :BizPartnerId @@ -496,9 +505,9 @@ function T8insert($data, $facilityno, $depId, $connT8) $stmt->bindParam(':BizPartnerName', $partyA); $stmt->bindParam(':WorkTelNo', $phone); $stmt->bindParam(':TaxNo', $vat); - $stmt->bindParam(':EnterpriseName', $customer); - $stmt->bindParam(':ContactAddress', $partyAaddress); - $stmt->bindParam(':EMail', $email); + $stmt->bindParam(':EnterpriseName', $invoice); + $stmt->bindParam(':ContactAddress', $invoice_address); + // $stmt->bindParam(':EMail', $email); $stmt->bindParam(':LastOperatorId', $user_id); $stmt->bindParam(':LastOperateTime', $createTime); $stmt->bindParam(':BizPartnerId', $contractno); @@ -539,9 +548,7 @@ function T8insert($data, $facilityno, $depId, $connT8) $row = 0; // // 新增電梯數 foreach ($elevators as $index => $elevator) { - // echo '
';
-        // print_r($elevator);
-        // echo '
'; + $facility_no = $facilityno[$index]; $sql = "INSERT INTO comMaterial (FOrgid,MaterialId,MaterialTypeId,MaterialCategoryId,CreatorId,CreateTime) @@ -613,7 +620,7 @@ function T8insert($data, $facilityno, $depId, $connT8) } } - $connT8->commit(); + // $connT8->commit(); // $insertime = settype($insertTime, 'integer'); @@ -652,9 +659,10 @@ function T8insert($data, $facilityno, $depId, $connT8) $API_body[] = $salIncomeApplyDetail; // 呼叫 API echo '
';
-    print_r($API_body);
+    print_r(json_encode($API_body));
     echo '
'; - $api_url = 'http://10.10.145.2:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; + // $api_url = 'http://10.10.145.2:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; + $api_url = "http://60.244.87.101:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData"; $result = T8salIncomeApply($API_body, $api_url); if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') { @@ -668,8 +676,9 @@ function T8insert($data, $facilityno, $depId, $connT8) 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"); + + require_once("../../bonus/maintance/maintaenance_contract_bonus.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'] : ''; @@ -702,12 +711,12 @@ function bonusCreate($data, $facilityno, $conn) $commission_fee = !empty($elevator['service_expense']) ? $elevator['service_expense'] : ''; //服務費(月/台) $receivable_date_due = $payDay; //第一筆保養款項收回日 $sales_id = $salesman; //營業人員 - $discount = $elevator['discount']; + $discount = $elevator['discount'] / 100; $region_director_id = $elevator['manager']; $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; + // echo $years; if ($maintain_months == '') $fail_arr[] = "保養月費為必填"; if ($fee_per_st == '') $fail_arr[] = "契約金額為必填"; if ($elevator_list_price == '') $fail_arr[] = "牌價為必填"; @@ -720,44 +729,75 @@ function bonusCreate($data, $facilityno, $conn) } $renew_priceissue_bonus = []; // $years = ($maintain_months % 12) == 0 ? $maintain_months / 12 : ''; + // 如果保養合約 大於一年 if (!empty($maintain_months)) { - if ($maintain_months > 12 && $contract_type == 'new') { - // 第一年為 "新簽約" - $results = maintenance_contract_bonus_v2_1( - $ver, - $contract_type, - $payment_period, - $elevator_list_price, - $fee_per_st, - $commission_fee, - $receivable_date_due, - $sales_id, - $region_director_id, - $regular_contract_manger_id - ); - for ($i = 1; $i <= $years - 1; $i++) { - $contract_type = 'renew_priceissue'; - $receivable_date_due_renew = date("Y-m-d", strtotime("$receivable_date_due + $i year")); - // 第二年以上改 "續約" - $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( + if ($ver == '2.1') { + 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_renew, + $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'; - $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( + for ($i = 1; $i <= $years - 1; $i++) { + $contract_type = 'renew_priceissue'; + $receivable_date_due_renew = date("Y-m-d", strtotime("$receivable_date_due + $i year")); + // 第二年以上改 "續約" + $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due_renew, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($maintain_months > 12 && $contract_type == 'renew_priceissue') { + // 超過一年的 "續約" + for ($i = 0; $i < $years; $i++) { + $contract_type = 'renew_priceissue'; + $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($maintain_months >= 60 && $contract_type = 'longcontract_m1_free_charge') { + // 五年以上長約 + $results = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $maintain_months, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } else { + $results = maintenance_contract_bonus_v2_1( $ver, $contract_type, $payment_period, @@ -770,37 +810,27 @@ function bonusCreate($data, $facilityno, $conn) $regular_contract_manger_id ); } - } else if ($maintain_months >= 60 && $contract_type = 'longcontract_m1_free_charge') { - // 五年以上長約 - $results = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( - $ver, - $contract_type, - $payment_period, - $maintain_months, - $elevator_list_price, - $fee_per_st, - $commission_fee, - $receivable_date_due, - $sales_id, - $region_director_id, - $regular_contract_manger_id - ); - } else { - $results = maintenance_contract_bonus_v2_1( + } else if ($ver == '2.0') { + $contract_years = $years > 2 ? 'above_two' : 'one'; + // echo $contract_years; + + $discount = round($elevator['discount'], 2); + $results = maintenance_contract_bonus_v2_0( $ver, $contract_type, - $payment_period, - $elevator_list_price, - $fee_per_st, - $commission_fee, - $receivable_date_due, + $contract_years, + $discount, // 折扣率 + $fee_per_st, //售價 + $receivable_date_due, // 第一筆金額繳款時間 $sales_id, $region_director_id, $regular_contract_manger_id ); } } - + echo "
";
+            print_r($results);
+            echo "
"; $bonus_json = [ 'contract_type' => $contract_type, 'total' => $elevator_list_price, diff --git a/wms/contract/api/test copy.json b/wms/contract/api/test copy.json index cb1ba7c7..d6490c33 100644 --- a/wms/contract/api/test copy.json +++ b/wms/contract/api/test copy.json @@ -1,115 +1,72 @@ [ { - "name": "MainSalesOrder", - "rows": [ - { - "BillNo": "M24020076", - "BillDate": 20240320, - "TypeId": "SO", - "FOrgId": "1000", - "OrgId": "1000", - "ModeId": "M", - "BizPartnerId": "M24020076", - "CurrId": "TWD", - "CurrOAmount": 1, - "CurrLAmount": 1, - "PersonId": "M0073", - "DueToId": "M24020076", - "TradeConditionId": "", - "TaxId": "ST005", - "CreditorCompId": "1001", - "CreditorOrgId": "1000", - "CreatorId": "M0225" - } - ] + "apply_key": "MB24010007", + "register_code": "036B017432", + "elevator_brand": "1", + "elevator_kind": "A", + "spec": "MAE100", + "weight": 550, + "speed": 60, + "stop": 12, + "floors": 12, + "persons": 8, + "elevator_num": 0, + "useful_years": 83, + "last_check_date": 1121109, + "speed_governors_check_expense": 0, + "maintain_times": 1, + "is_m1_bundle": "N", + "maintainance": "A", + "maintain_months": "12", + "maintain_period": 1, + "stand_price": 3140, + "contract_price": 1666.67, + "sold_price": 1667, + "commission_expense": null, + "management_expense": null, + "annual_survey_expense": 0, + "service_expense": 2, + "cmstatus": "Y", + "updated_at": null, + "creater": null, + "created_at": "2024-01-10 11:16:26", + "discount": 0.5301496815286625, + "bonus_verson": "2.0", + "manager": "M0137" }, { - "name": "SubOrder", - "rows": [ - { - "TaxId": "ST005", - "RequirementDate": 20240320, - "ConsignmentDate": 20240320, - "BillNo": "M24020076", - "RowCode": 1, - "ItemType": 1, - "MaterialId": "A40001", - "SUnitId": "SET", - "SQuantity": 1, - "SPrice": 910000, - "CU_MaterialId": "4MW00001" - }, - { - "TaxId": "ST005", - "RequirementDate": 20240320, - "ConsignmentDate": 20240320, - "BillNo": "M24020076", - "RowCode": 2, - "ItemType": 1, - "MaterialId": "A40008", - "SUnitId": "SET", - "SQuantity": 1, - "SPrice": 390000, - "CU_MaterialId": "4MW00001" - }, - { - "TaxId": "ST005", - "RequirementDate": 20240320, - "ConsignmentDate": 20240320, - "BillNo": "M24020076", - "RowCode": 3, - "ItemType": 0, - "MaterialId": "4MW00001", - "SUnitId": "SET", - "SQuantity": 1, - "SPrice": 0, - "CU_MaterialId": "4MW00001" - } - ] - }, - { - "name": "salOrderStagePay", - "rows": [ - { - "PayStage": "簽約", - "PlanPercentage": 0.2, - "PlanPayAmt": 260000, - "PlanPayDate": 20240420, - "BillNo": "M24020076", - "RowCode": 1, - "RowNo": 1, - "UnWriteOffOAmount": 260000 - }, - { - "PayStage": "貨抵工地", - "PlanPercentage": 0.5, - "PlanPayAmt": 650000, - "PlanPayDate": 20241220, - "BillNo": "M24020076", - "RowCode": 2, - "RowNo": 2, - "UnWriteOffOAmount": 650000 - }, - { - "PayStage": "試車完工", - "PlanPercentage": 0.2, - "PlanPayAmt": 260000, - "PlanPayDate": 20250120, - "BillNo": "M24020076", - "RowCode": 3, - "RowNo": 3, - "UnWriteOffOAmount": 260000 - }, - { - "PayStage": "交車", - "PlanPercentage": 0.1, - "PlanPayAmt": 130000, - "PlanPayDate": 20250220, - "BillNo": "M24020076", - "RowCode": 4, - "RowNo": 4, - "UnWriteOffOAmount": 130000 - } - ] + "apply_key": "MB24010007", + "register_code": "036B032903", + "elevator_brand": "1", + "elevator_kind": "A", + "spec": "MAE100", + "weight": 450, + "speed": 60, + "stop": 7, + "floors": 7, + "persons": 6, + "elevator_num": 0, + "useful_years": 83, + "last_check_date": 1121109, + "speed_governors_check_expense": 0, + "maintain_times": 1, + "is_m1_bundle": "N", + "maintainance": "A", + "maintain_months": "12", + "maintain_period": 1, + "stand_price": 2540, + "contract_price": 1666.67, + "sold_price": 1667, + "commission_expense": null, + "management_expense": null, + "annual_survey_expense": 0, + "service_expense": 2, + "cmstatus": "Y", + "updated_at": null, + "creater": null, + "created_at": "2024-01-10 11:16:26", + "discount": 0.6553818897637795, + "bonus_verson": "2.0", + "manager": "M0137" } ] \ No newline at end of file diff --git a/wms/contract/conn.php b/wms/contract/conn.php index bbfd1c50..5ac49515 100644 --- a/wms/contract/conn.php +++ b/wms/contract/conn.php @@ -34,9 +34,9 @@ try { //設定主動以警告的形式報錯 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - // $connT8 = new PDO("sqlsrv:Server=220.130.203.251;Database=T8TEST", "M0225", "IFFBU1E="); + $connT8 = new PDO("sqlsrv:Server=220.130.203.251;Database=T8TEST", "M0225", "IFFBU1E="); // $connT8 = new PDO("sqlsrv:Server=10.10.145.2;Database=T8MASADA", "masada", "@m222222"); - $connT8 = new PDO("sqlsrv:Server=220.130.203.251;Database=T8MASADA", "masada", "@m222222"); + // $connT8 = new PDO("sqlsrv:Server=220.130.203.251;Database=T8MASADA", "masada", "@m222222"); if ($connT8) { diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 92aaf7d0..cab62f7e 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -64,7 +64,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); - 立約人 + 客戶名稱

未填寫

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

未填寫

- 合約開始時間 + 電梯台數

未填寫

電梯數量需大於0

- - 統一編號/身分證 + 分期方式 - -

未填寫

+ +

未填寫

- 維修型態 + + + + 簽約日 + + +

未填寫

+ 合約開始時間 + + +

未填寫

+ + 合約終止時間 + + +

未填寫

+ + + 契約成交價 @@ -118,26 +141,33 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); + 發票抬頭 + + + + + 統一編號/身分證 + + + + 客戶電話 -

未填寫

+ - Email - - -

未填寫

- - 保養員 + 區域 - + + -

未填寫

+

未填寫

+ + - 分期方式 - - -

未填寫

- + - - 業務聯繫人 + + - 區域 - - -

未填寫

- 詳細地址 + 發票地址 + + + + + 現場地址

未填寫

- 附件 - - + 保養員 + + + + 合約類別 @@ -211,9 +234,21 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); - + + + + + 合約附件 + + + + + + + +