diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1.php b/wms/bonus/other/maintenance_contract_bonus_v2_1.php index 598202d4..27959883 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1.php @@ -45,7 +45,9 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, { $bonus_array = []; if ($ver == "2.1") { - $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); + // $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); + $discount = ($fee_per_st - $commission_fee) / $elevator_list_price; + #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) switch ($contract_type) { case "new": @@ -54,10 +56,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, switch ($discount) { case ($discount >= 0.8): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.6; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.7; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -70,10 +72,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, break; case ($discount >= 0.6 and $discount < 0.8): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.48; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.56; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -86,10 +88,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, break; case ($discount < 0.6): switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.42; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.49; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -110,10 +112,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "free_to_charge": switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.3; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.35; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): @@ -131,10 +133,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, case "renew_priceissue": switch ($fee_per_st) { - case ($fee_per_st <= 3000): + case ($fee_per_st < 3000): $sales_bonus = ($fee_per_st) * 0.25; break; - case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + case ($fee_per_st >= 3000 and $fee_per_st <= 3499): $sales_bonus = ($fee_per_st) * 0.3; break; case ($fee_per_st >= 3500 and $fee_per_st <= 3999): diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php b/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php index d68bdb7d..5b26e9c8 100644 --- a/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php +++ b/wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php @@ -270,9 +270,9 @@ $examination_array = [ // echo '10、專任契約經理員工號($regular_contract_manger_id)
'; for ($i = 0; $i < count($examination_array); $i++) { - $fee_per_st = $examination_array[$i][3]; - $commission_fee = $examination_array[$i][5]; - $elevator_list_price = $examination_array[$i][4]; + $fee_per_st = $examination_array[$i][4]; //作番金額 + $commission_fee = $examination_array[$i][5]; // 服務費 + $elevator_list_price = $examination_array[$i][3]; // 牌價 $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); // echo "$fee_per_st - $commission_fee / $elevator_list_price "; @@ -314,7 +314,7 @@ for ($i = 0; $i < count($examination_array); $i++) { ]; echo "獎金版本:" . $result["ver"] . "
"; echo "計算結果:" . $result["result_status"] . "
"; - echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$examination_array[$i][2]] . "、牌價" . $examination_array[$i][3] . "元、簽約價" . $examination_array[$i][4] . "元、服務費600元(折扣率" . $discount . ")、契約人員 : " . $examination_array[$i][7] . "、區經理 : " . $examination_array[$i][8] . " 、契約經理 : " . $examination_array[$i][9] . "
"; + echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$examination_array[$i][2]] . "、牌價" . $examination_array[$i][3] . "元、簽約價" . $examination_array[$i][4] . "元、服務費" . $commission_fee . "元(折扣率" . $discount . ")、契約人員 : " . $examination_array[$i][7] . "、區經理 : " . $examination_array[$i][8] . " 、契約經理 : " . $examination_array[$i][9] . "
"; echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " " . $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7] . " " . $examination_array[$i][8] . " " . $examination_array[$i][9] . "
"; diff --git a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php new file mode 100644 index 00000000..70a19f40 --- /dev/null +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php @@ -0,0 +1,312 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + + +function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract_type, $payment_period, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id = '') +{ + $bonus_array = []; + if ($ver == "2.1") { + $discount = ($fee_per_st - $commission_fee) / $elevator_list_price; + #契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge) + switch ($contract_type) { + case "longcontract_m1_free_charge": + #契約員獎金($sales_bonus) + #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) + switch ($discount) { + case ($discount >= 0.8): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.6; + break; + case ($fee_per_st >= 3000 and $fee_per_st < 4000): + $sales_bonus = ($fee_per_st) * 0.7; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.8; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.9; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 1.0; + break; + }; + break; + case ($discount >= 0.6 and $discount < 0.8): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.42; + break; + case ($fee_per_st >= 3000 and $fee_per_st <= 4000): + $sales_bonus = ($fee_per_st) * 0.49; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.56; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.63; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 0.7; + break; + }; + break; + case ($discount < 0.6): + switch ($fee_per_st) { + case ($fee_per_st < 3000): + $sales_bonus = ($fee_per_st) * 0.3; + break; + case ($fee_per_st >= 3000 and $fee_per_st < 4000): + $sales_bonus = ($fee_per_st) * 0.35; + break; + case ($fee_per_st >= 4000 and $fee_per_st < 5000): + $sales_bonus = ($fee_per_st) * 0.4; + break; + case ($fee_per_st >= 5000 and $fee_per_st < 6000): + $sales_bonus = ($fee_per_st) * 0.45; + break; + case ($fee_per_st >= 6000): + $sales_bonus = ($fee_per_st) * 0.5; + break; + }; + break; + }; + + #地區處長獎金($region_director_bonus) + $region_director_bonus = 170; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 300; + break; + }; + #付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) + array_push($bonus_array, [ + "bonus_type" => "地區處長獎金", #獎金名稱 + "bonus_receiver" => $region_director_id, #發放人員 + "bonus_amount" => round($region_director_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +12 months")), #預計發放時間 + "bonus_regulation" => "訂金收回後次月發放" #發放規定 + ]); + + #專任契約經理獎金 + if ($regular_contract_manger_id != '') { + array_push($bonus_array, [ + "bonus_type" => "專任契約經理獎金", #獎金名稱 + "bonus_receiver" => $regular_contract_manger_id, #發放人員 + "bonus_amount" => round($regular_contract_manger_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +12 months")), #預計發放時間 + "bonus_regulation" => "訂金收回後次月發放" #發放規定 + ]); + } + + #地區處長獎金、專任契約經理、契約員獎金 + switch ($payment_period) { + #簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金 + #總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期, + #年繳 + case 'annually': + $payment_ratio_due_array = array(); + $a = $payment_period_amount / 12; + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, $i + 1); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($current_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] year")), #預計發放時間 + "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + + break; + #半年繳 + case 'semiannually': + $payment_ratio_due_array = array(); + $a = $payment_period_amount / 6; + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 6); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($current_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 + "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + #季繳 + case 'quarterly': + $a = $payment_period_amount / 3; + $payment_ratio_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 4); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($current_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 + "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + break; + #雙月繳 + case 'bimonthly': + $a = $payment_period_amount / 2; + $payment_ratio_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payment_ratio_due_array, 1 / $a); + } + + $payday_due_array = array(); + for ($i = 0; $i < $a; $i++) { + array_push($payday_due_array, ($i + 1) * 2); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($current_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 + "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + break; + #月繳 + case 'monthly': + + #產生契約員每個月的獎金應發比例 + $payment_ratio_due_array = array(); + for ($i = 0; $i < $payment_period_amount; $i++) { + array_push($payment_ratio_due_array, 1 / $payment_period_amount); + } + + $payday_due_array = array(); + for ($i = 0; $i < $payment_period_amount; $i++) { + array_push($payday_due_array, $i + 1); + } + + for ($i = 0; $i < count($payment_ratio_due_array); $i++) { + if ($i < count($payment_ratio_due_array) - 1) { + $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 + } else { + $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 + }; + array_push($bonus_array, [ + "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($current_bonus), #金額 + "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 + "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + ]); + } + break; + } + + $result_array = [ + "ver" => $ver, #獎金版本 + "result_status" => "success", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + } else { + array_push($bonus_array, [ + "bonus_type" => "error", #獎金名稱 + "bonus_receiver" => "error", #發放人員 + "bonus_amount" => 0, #金額 + "pay_day_due" => "9999-1-1", #預計發放時間 + "bonus_regulation" => "error" #發放規定 + ]); + $result_array = [ + "ver" => $ver, #獎金版本 + "result_status" => "error", #計算結果 + "bonus_array" => $bonus_array #獎金水庫 + ]; + } + + return $result_array; +}; diff --git a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php index 0c42a890..3e0c3af0 100644 --- a/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php +++ b/wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php @@ -40,62 +40,150 @@ result_array[ */ -require_once("maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php"); - -#$ver, $contract_type, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id - - +require_once("maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php"); #獎金測試 $examination_array = [ #錯誤版本 - ["1.0","longcontract_m1_free_charge",60,0.8,4000,333, "2014-07-01", "M0001", "M0002", "M0003"], + // ["1.0", 'annually', "longcontract_m1_free_charge", 60, 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"], #60期 - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) - ["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) - ["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) - + //付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 600, "2014-07-01", "M0001", "M0002"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 1200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 2200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 3200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 4200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 5200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 1230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 3000, 1230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 2230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 3230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 4230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) + ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 5230, "2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) + + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) + // ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) ]; -for($i = 0; $i "契約員獎金", #獎金名稱 + // "bonus_receiver" => $sales_id, #發放人員 + // "bonus_amount" => round($current_bonus), #金額 + // "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] year")), #預計發放時間 + // "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 + // ]); + // } + // echo '
';
+	// print_r($bonus_array);
+	// echo '
'; + // exit(); $result = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( - $examination_array[$i][0], - $examination_array[$i][1], - $examination_array[$i][2], - $examination_array[$i][3], - $examination_array[$i][4], - $examination_array[$i][5], - $examination_array[$i][6], - $examination_array[$i][7], - $examination_array[$i][8], - $examination_array[$i][9] + $ver, + $contract_type, + $payment_period, + $payment_period_amount, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id ); + + $discount = (($fee_per_st - $commission_fee) / $elevator_list_price); + #新簽約、月繳、牌價3000、簽約價3000元、服務費600元(折扣率0.8) + $contract_type = [ + 'new' => '新簽約', + 'free_to_charge' => '免保轉有費', + 'renew_priceissue' => '續簽約(原價或僅契約金額異動)', + 'longcontract_m1_free_charge' => '五年長約' + + ]; + // 付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually) + $pay_kind = [ + 'monthly' => '月繳', + 'bimonthly' => '雙月繳', + 'quarterly' => '季繳', + 'semiannually' => '半年繳', + 'annually' => '年繳' + ]; + + // + $bonus_type = [ + '1' => '契約員獎金', + '2' => '區經理獎金', + '3' => '契約經理獎金' + ]; echo "獎金版本:" . $result["ver"] . "
"; echo "計算結果:" . $result["result_status"] . "
"; - echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " " - . $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7]. " " . $examination_array[$i][8] . " " - . $examination_array[$i][9] . "
"; - for($j = 0; $j"; + echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][4] . " " + . $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7] . " " . $examination_array[$i][8] . " " + . $examination_array[$i][9] . "
"; + $n = 0; + for ($j = 0; $j < count($result["bonus_array"]); $j++) { + if ($result["bonus_array"][$j]["bonus_receiver"] == "M0001") { + + $n++; + echo '[' . $n . ']'; + } echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " " - . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["pay_day_due"] . " " - . $result["bonus_array"][$j]["bonus_regulation"] . "
"; + . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["pay_day_due"] . " " + . $result["bonus_array"][$j]["bonus_regulation"] . "
"; }; echo "-------------------------" . "
"; - }; - - -?> diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index d3ecf356..e8dca10f 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -88,10 +88,10 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c if ($address == '') $fail_arr[] = '地址為必填'; if ($area == '') $fail_arr[] = '區域為必填'; if ($customer == '') $fail_arr[] = '客戶為必填'; - // if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; - // if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; - // if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; - // if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; + if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; + if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; + if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; + if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; if ($num == '') $fail_arr[] = '電梯數量為必填'; if ($payType == '') $fail_arr[] = '付款方式為必填'; if (count($fail_arr) > 0) { @@ -100,7 +100,11 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c exit(); } // T8insert($_POST, $facilityno, $depId); - bonusCreate($_POST, $facilityno, $conn); + $aaa = bonusCreate($_POST, $facilityno, $conn); + echo '
';
+        print_r($aaa);
+        echo '
'; + exit; //create account table $accounttype = "A"; $accountid = $vat; @@ -658,10 +662,13 @@ function bonusCreate($data, $facilityno, $conn) { try { require_once("../../bonus/other/maintenance_contract_bonus_v2_1.php"); + require_once("../../bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php"); + $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; $contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : ''; $salesman = !empty($data['salesman']) ? $data['salesman'] : ''; $payType = !empty($data['payType']) ? $data['payType'] : ''; + $contract_type = $data['contract_type']; //合約類別 $status = 1; $bonus_json = []; $create_id = $data['user_id']; @@ -676,28 +683,114 @@ function bonusCreate($data, $facilityno, $conn) 'A40005' => 'semiannually', // 半年繳 'A40003' => 'monthly' //月繳 ]; - + $fail_arr = []; $payDay = getNext25thDate($contract_begin_date); foreach ($elevators as $key => $elevator) { - // print_r($payDay); - // echo '
';
-            // print_r($elevator);
-            // echo '
'; - // exit; $facility_no = $facilityno[$key]; $ver = $elevator['bonus_verson']; //獎金版本 - $contract_type = $elevator['contract_type']; //合約類別 $payment_period = $payment[$payType]; //付款方式 - $elevator_list_price = intval($elevator['stand_price']); //牌價 - $fee_per_st = $elevator['sold_price']; //作翻契約金額 - $commission_fee = $elevator['service_expense']; //服務費(月) + $elevator_list_price = !empty(intval($elevator['stand_price'])) ? intval($elevator['stand_price']) : ''; //牌價 + $fee_per_st = !empty(round($elevator['sold_price'] / 1.05, 2)) ? round($elevator['sold_price'] / 1.05, 2) : ''; //作翻契約金額 (不含稅) + $commission_fee = !empty($elevator['service_expense']) ? $elevator['service_expense'] : ''; //服務費(月/台) $receivable_date_due = $payDay; //第一筆保養款項收回日 $sales_id = $salesman; //營業人員 $discount = $elevator['discount']; $region_director_id = $elevator['manager']; $regular_contract_manger_id = !empty($elevator['regular_contract_manger_id']) ? $elevator['regular_contract_manger_id'] : ''; - $results = maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id); + $maintain_months = intval($elevator['maintain_months']); + $years = $maintain_months / 12; + + if ($maintain_months == '') $fail_arr[] = "保養月費為必填"; + if ($fee_per_st == '') $fail_arr[] = "契約金額為必填"; + if ($elevator_list_price == '') $fail_arr[] = "牌價為必填"; + if ($region_director_id == '') $fail_arr[] = '區處長為必填'; + if ($sales_id == '') $fail_arr[] = "契約人為必填"; + + if (COUNT($fail_arr) > 0) { + return $fail_arr; + break; + } + // $years = ($maintain_months % 12) == 0 ? $maintain_months / 12 : ''; + // 如果保養合約 大於一年 + if (!empty($maintain_months)) { + if ($maintain_months > 12 && $contract_type == 'new') { + // 第一年為新簽約 + $results = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + for ($i = 0; $i < $maintain_months - 1; $i++) { + $contract_type = 'renew_priceissue'; + // 第二年以上改續約 + $result2 = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($maintain_months > 12 && $contract_type == 'renew_priceissue') { + // 超過一年的續約 + for ($i = 0; $i < $years; $i++) { + $contract_type = 'renew_priceissue'; + $result2 = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($maintain_months >= 60) { + $contract_type = 'longcontract_m1_free_charge'; + $result = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $maintain_months, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } else { + $results = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } $bonus_json = [ 'contract_type' => $contract_type, 'total' => $elevator_list_price, @@ -721,6 +814,21 @@ function bonusCreate($data, $facilityno, $conn) $stmt = $conn->prepare($sql); $stmt->execute(); } + if (!empty($result2)) { + foreach ($results2['bonus_array'] as $i => $result) { + + $bonus_type = $result['bonus_type']; + $pay_day = $result['pay_day_due']; + $amount = $result['bonus_amount']; + $receiver = $result['bonus_receiver']; + $a = json_encode($bonus_json); + $sql = "INSERT INTO bonus + (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,pay_day_due,status,bonus_json,create_id,create_at) VALUES + ($bonus_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$receiver','$pay_day',$status,'$a','$create_id','$create_at')"; + $stmt = $conn->prepare($sql); + // $stmt->execute(); + } + } } // exit(); } diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 58acb4a8..cbec41c1 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -57,8 +57,8 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);

業務確認項

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

未填寫

- + 區域 @@ -201,7 +201,17 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); - + + 合約類別 + + + + + 獎金適用版本 - - 作番契約金額(月) - + + + 服務費 + + + 牌價(標準價)

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

- 服務費 - - - - 折扣率(%)
(作番契約金額+服務費/台數) / 牌價 * 100 - - - 地區處長員工號 專任契約經理員工號 + + diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index db386702..ad56eb3b 100644 --- a/wms/contract/js/alpine.js +++ b/wms/contract/js/alpine.js @@ -1016,6 +1016,7 @@ const contractInput = () => { disabled: false, //資料庫是否有電梯數量資料 elevators: [], //機種、載重、人乘、樓停、樓層、速度、緯度、經度、開門方式、保養別、廠牌、竣檢日、許可證日期 payType: '', //付款方式 + contract_type: '' // bonus_verson: 2.1, // manager: '', // regular_contract_manger_id: '', @@ -1048,6 +1049,7 @@ const contractInput = () => { data.bonus_verson = 2.1; }, getManager() { + for (let i = 0; i < this.data.elevators.length; i++) { this.getBonusVerson(this.data.elevators[i]); axios.get('./api/getContractData.php?contracttype=accountManger&salesman=' + this.data.salesman).then(res => { @@ -1070,29 +1072,31 @@ const contractInput = () => { } }, createElevator() { - for (let i = 0; i < this.data.num; i++) { - this.data.elevators.push({ - spec: '', //規格 - weight: '', //載重 - speed: '', //速度 - persons: '', //人乘 - stop: '', //樓停 - floors: '', //樓層 - latitude: '', //緯度 - longitude: '', //經度 - elevator_brand: '', //廠牌 - opendoor: '', //開門方式 - maintainance: '', //保養別 - takecertificatedate: '', //竣檢日 - useful_date: '', //許可證有效日期 - maintain_times: '', //保養頻率 - discount: '', //折價率 - contract_type: '', - manager: '', - regular_contract_manger_id: '', - bonus_verson: '', - sold_price: '' - }) + if (this.data.num != this.data.elevators.length) { + for (let i = 0; i < this.data.num; i++) { + this.data.elevators.push({ + spec: '', //規格 + weight: '', //載重 + speed: '', //速度 + persons: '', //人乘 + stop: '', //樓停 + floors: '', //樓層 + latitude: '', //緯度 + longitude: '', //經度 + elevator_brand: '', //廠牌 + opendoor: '', //開門方式 + maintainance: '', //保養別 + takecertificatedate: '', //竣檢日 + useful_date: '', //許可證有效日期 + maintain_times: '', //保養頻率 + discount: '', //折價率 + // contract_type: '', + manager: '', + regular_contract_manger_id: '', + bonus_verson: '', + sold_price: '' + }) + } } }, getContractDate() { @@ -1109,7 +1113,7 @@ const contractInput = () => { this.data.total_price = Number(res.data.elevators[i].sold_price) + Number(this.data.total_price); // 服務費 (以單筆合約記,但計算獎金須傳入單月服務費) - this.data.elevators[i].service_expense = Math.round(this.data.elevators[i].service_expense / 12); + this.data.elevators[i].service_expense = Math.round(this.data.elevators[i].service_expense / res.data.elevators[i]); // 折扣率 this.data.elevators[i].discount = Math.round(((res.data.elevators[i].sold_price / res.data.elevators[i].stand_price) + this.data.elevators[i].service_expense) * 100); } @@ -1206,7 +1210,8 @@ const contractInput = () => { form.append('num', this.data.num); form.append('elevators', JSON.stringify(this.data.elevators)); form.append('contracttype', 'b'); - form.append('payType', this.data.payType) + form.append('payType', this.data.payType); + form.append('contract_type', this.data.contract_type); // 如果有附件檔案,可以逐一加入 for (var i = 0; i < this.data.files.length; i++) {