diff --git a/wms/cont/api/getElevatorPrice.php b/wms/cont/api/getElevatorPrice.php index dd073789..b8020fee 100644 --- a/wms/cont/api/getElevatorPrice.php +++ b/wms/cont/api/getElevatorPrice.php @@ -14,6 +14,7 @@ try{ "MAF100" => "B", "MAM200" => "D", "MAH100" => "E", + ""=>"" ]; // $elevator_type = match($spec){ // "MAE100" => "A", diff --git a/wms/cont/api/maintaenance_contract_bonus.php b/wms/cont/api/maintaenance_contract_bonus.php new file mode 100644 index 00000000..e54fe820 --- /dev/null +++ b/wms/cont/api/maintaenance_contract_bonus.php @@ -0,0 +1,761 @@ += 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/cont/api/postElevatorPricereview.php b/wms/cont/api/postElevatorPricereview.php index a02de093..3fea17ff 100644 --- a/wms/cont/api/postElevatorPricereview.php +++ b/wms/cont/api/postElevatorPricereview.php @@ -26,7 +26,7 @@ $status = $_POST['status']; $elevators = json_decode($_POST['elevators'], true); $otherOptions = json_decode($_POST['otherOptions'], true); $payment_kind = $_POST['pay_method']; -$current_date = date("Y-M-d H:i:s"); +$current_date = date("Y-m-d H:i:s"); $total_price = $_POST['total_price']; $total_sale_price = $_POST['total_sale_price']; @@ -161,8 +161,8 @@ try{ $stmt->bindParam(':create_at', $current_date); $stmt->execute(); - $sql_str = "INSERT INTO con_maintance_examine_clear (apply_key, item_no, register_code, elevator_brand, elevator_kind, spec, weight, speed, stop, floors, persons, elevator_num, useful_years, last_check_date, speed_governors_check_expense, maintain_times, is_m1_bundle, maintain_months, maintain_period, maintain_method, stand_price, contract_price, sold_price, commission_expense, management_expense, annual_survey_expense, service_expense, cmstatus, updated_at, creater, created_at) - VALUES (:apply_key, :item_no, :register_code, :elevator_brand, :elevator_kind, :spec, :weight, :speed, :stop, :floors, :persons, :elevator_num, :useful_years, :last_check_date, :speed_governors_check_expense, :maintain_times, :is_m1_bundle, :maintain_months, :maintain_period, :maintain_method, :stand_price, :contract_price, :sold_price, :commission_expense, :management_expense, :annual_survey_expense, :service_expense, :cmstatus, :updated_at, :creater, :created_at) "; + $sql_str = "INSERT INTO con_maintance_examine_clear (apply_key, item_no, register_code, elevator_brand, elevator_kind, spec, weight, speed, stop, floors, persons, elevator_num, useful_years, last_check_date, speed_governors_check_expense, maintain_times, is_m1_bundle, maintain_months, maintain_period, maintain_method, stand_price, contract_price, sold_price, commission_expense, management_expense, annual_survey_expense, service_expense, inspection_fee, cmstatus, updated_at, creater, created_at) + VALUES (:apply_key, :item_no, :register_code, :elevator_brand, :elevator_kind, :spec, :weight, :speed, :stop, :floors, :persons, :elevator_num, :useful_years, :last_check_date, :speed_governors_check_expense, :maintain_times, :is_m1_bundle, :maintain_months, :maintain_period, :maintain_method, :stand_price, :contract_price, :sold_price, :commission_expense, :management_expense, :annual_survey_expense, :service_expense, :inspection_fee, :cmstatus, :updated_at, :creater, :created_at) "; foreach($elevators as $elevator){ $register_code = (empty($elevator['permitNumber'])) ? "A" : $elevator['permitNumber']; @@ -207,6 +207,7 @@ try{ $stmt->bindParam(':management_expense', $elevator['management_expense']); $stmt->bindParam(':annual_survey_expense', $elevator['yearCheckFee']); $stmt->bindParam(':service_expense', $elevator['service_expense']); + $stmt->bindParam(':inspection_fee', $elevator['inspectionFee']); $stmt->bindParam(':cmstatus', $cmstatus); $stmt->bindParam(':updated_at', $updated_at); $stmt->bindParam(':creater', $creater); @@ -306,8 +307,8 @@ try{ $stmt->execute(); } foreach($onlyInNewIds as $newidx){ - $sql_str = "INSERT INTO con_maintance_examine_clear (apply_key, item_no, register_code, elevator_brand, elevator_kind, spec, weight, speed, stop, floors, persons, elevator_num, useful_years, last_check_date, speed_governors_check_expense, maintain_times, is_m1_bundle, maintain_months, maintain_period, maintain_method, stand_price, contract_price, sold_price, commission_expense, management_expense, annual_survey_expense, service_expense, cmstatus, updated_at, creater, created_at) - VALUES (:apply_key, :item_no, :register_code, :elevator_brand, :elevator_kind, :spec, :weight, :speed, :stop, :floors, :persons, :elevator_num, :useful_years, :last_check_date, :speed_governors_check_expense, :maintain_times, :is_m1_bundle, :maintain_months, :maintain_period, :maintain_method, :stand_price, :contract_price, :sold_price, :commission_expense, :management_expense, :annual_survey_expense, :service_expense, :cmstatus, :updated_at, :creater, :created_at) "; + $sql_str = "INSERT INTO con_maintance_examine_clear (apply_key, item_no, register_code, elevator_brand, elevator_kind, spec, weight, speed, stop, floors, persons, elevator_num, useful_years, last_check_date, speed_governors_check_expense, maintain_times, is_m1_bundle, maintain_months, maintain_period, maintain_method, stand_price, contract_price, sold_price, commission_expense, management_expense, annual_survey_expense, service_expense, inspection_fee, cmstatus, updated_at, creater, created_at) + VALUES (:apply_key, :item_no, :register_code, :elevator_brand, :elevator_kind, :spec, :weight, :speed, :stop, :floors, :persons, :elevator_num, :useful_years, :last_check_date, :speed_governors_check_expense, :maintain_times, :is_m1_bundle, :maintain_months, :maintain_period, :maintain_method, :stand_price, :contract_price, :sold_price, :commission_expense, :management_expense, :annual_survey_expense, :service_expense, :inspection_fee, :cmstatus, :updated_at, :creater, :created_at) "; $elevator = array_values(array_filter($elevators, fn($el)=> $el['id'] == $newidx))[0]; $register_code = empty($elevator['permitNumber']) ? "A" : $elevator['permitNumber']; if($elevator['spec'] == "MAE100") $elevator_kind = "A"; @@ -350,6 +351,7 @@ try{ $stmt->bindParam(':management_expense', $elevator['management_expense']); $stmt->bindParam(':annual_survey_expense', $elevator['yearCheckFee']); $stmt->bindParam(':service_expense', $elevator['service_expense']); + $stmt->bindParam(':inspection_fee', $elevator['inspectionFee']); $stmt->bindParam(':cmstatus', $cmstatus); $stmt->bindParam(':updated_at', $updated_at); $stmt->bindParam(':creater', $creater); @@ -383,6 +385,7 @@ try{ management_expense=:management_expense, annual_survey_expense=:annual_survey_expense, service_expense=:service_expense, + inspection_fee=:inspection_fee, cmstatus=:cmstatus, updated_at=:updated_at WHERE (apply_key, item_no) = (:apply_key, :item_no)"; @@ -429,6 +432,7 @@ try{ $stmt->bindParam(':management_expense', $elevator['management_expense']); $stmt->bindParam(':annual_survey_expense', $elevator['yearCheckFee']); $stmt->bindParam(':service_expense', $elevator['service_expense']); + $stmt->bindParam(':inspection_fee', $elevator['inspectionFee']); $stmt->bindParam(':cmstatus', $cmstatus); $stmt->bindParam(':updated_at', $updated_at); diff --git a/wms/cont/js/pricereviewAlpine.js b/wms/cont/js/pricereviewAlpine.js index 66bf4fed..e2c2eef9 100644 --- a/wms/cont/js/pricereviewAlpine.js +++ b/wms/cont/js/pricereviewAlpine.js @@ -38,10 +38,11 @@ const pricereviewCreate = ()=>{ method:'', //保養方式 checkYear:'', //竣工檢查年度 lastDate:'', // 上次年檢日期 - yearCheckFee:'', //年檢費用 + yearCheckFee:1260, //年檢費用 price:'', //公司發布價(月) qty:1, //電梯數量 sale_price:'', //契約報價 + inspectionFee:0, //檢驗費 }, otherOptions: otherOptions, modalOtherOptionInfo:{ @@ -63,6 +64,7 @@ const pricereviewCreate = ()=>{ warranty_rate: warranty_rate, attatch1:'', attatch2:'', + error:[], openCreateElevatorModal(){ this.modalShow.elevator = true; body.style.overflow = 'hidden'; @@ -84,10 +86,11 @@ const pricereviewCreate = ()=>{ method:'', //保養方式 checkYear:'', //竣工檢查年度 lastDate:'', // 上次年檢日期 - yearCheckFee:'', //年檢費用 + yearCheckFee:1260, //年檢費用 price:'', //公司發布價(月) qty:1, //電梯數量 sale_price:'', //契約報價 + inspectionFee:0, }; }, createElevatorFn(){ @@ -98,6 +101,7 @@ const pricereviewCreate = ()=>{ // if(this.modalElevatorInfo.speed == '') return alert("請選擇速度"); // if(this.modalElevatorInfo.brand == '') return alert("請選擇品牌"); // if(this.modalElevatorInfo.months == '') return alert("請輸入保養月數"); + if(this.modalElevatorInfo.m1 == 'Y' && this.modalElevatorInfo.months < 60) return alert('贈送M1保養月數不得小於60!') // if(this.modalElevatorInfo.method == '') return alert("請選擇保養方式"); // if(this.modalElevatorInfo.cycle == '') return alert("請選擇保養週期"); // if(this.modalElevatorInfo.checkYear == '') return alert("請輸入竣工檢查年度"); @@ -122,7 +126,8 @@ const pricereviewCreate = ()=>{ yearCheckFee: this.modalElevatorInfo.yearCheckFee, price: this.modalElevatorInfo.price, qty: this.modalElevatorInfo.qty, - sale_price: this.modalElevatorInfo.sale_price + sale_price: this.modalElevatorInfo.sale_price, + inspectionFee: this.modalElevatorInfo.inspectionFee }) this.hideCreateElevatorModal(); }, @@ -143,6 +148,7 @@ const pricereviewCreate = ()=>{ const price = this.elevators[idx].price; const qty = this.elevators[idx].qty; const sale_price = this.elevators[idx].sale_price; + const inspectionFee = this.elevators[idx].inspectionFee; this.total_spec ++; this.elevators.push({ id: this.total_spec, @@ -162,7 +168,8 @@ const pricereviewCreate = ()=>{ yearCheckFee: yearCheckFee, price: price, qty: qty, - sale_price: sale_price + sale_price: sale_price, + inspectionFee: inspectionFee }) }, removeElevator(id){ @@ -270,6 +277,25 @@ const pricereviewCreate = ()=>{ removeOtherOption(id){ this.otherOptions = this.otherOptions.filter(option=> option.id != id) }, + checkMonths(idx=null){ + if(this.elevators[idx].months < 60 && this.elevators[idx].m1 == 'Y'){ + alert('贈送M1保養月數不得小於60!') + this.elevators[idx].months = 60 + } + }, + changeMonths(idx=null){ + if(idx===null){ + if(this.modalElevatorInfo.m1 == 'N') return; + if(this.modalElevatorInfo.months < 60){ + this.modalElevatorInfo.months = 60 + } + return; + } + if(this.elevators[idx].m1 == 'N') return; + if(this.elevators[idx].months < 60){ + this.elevators[idx].months = 60 + } + }, get totalPrice(){ let total_price = this.elevators.reduce((accumulator, el) => accumulator + Number(el.price*el.months), 0); let total_other_price = this.otherOptions.reduce((accumulator, option) => accumulator + Number(option.price*option.num), 0); @@ -277,7 +303,7 @@ const pricereviewCreate = ()=>{ }, get totalSalePrice(){ let total_sale_price = this.elevators.reduce((accumulator, el) => accumulator + Number(el.sale_price*el.months), 0); - return total_sale_price + Number(this.serviceFee); + return total_sale_price; }, get totalElevatorsNum(){ let total_num = this.elevators.reduce((accumulator, el) => accumulator + Number(el.qty), 0); @@ -291,6 +317,9 @@ const pricereviewCreate = ()=>{ let total_other_price = this.otherOptions.reduce((accumulator, option) => accumulator + Number(option.price*option.num), 0); return total_other_price; }, + get discountRate(){ + return Math.round((Number(this.totalSalePrice) - Number(this.serviceFee)) / Number(this.totalPrice) * 1000) / 1000 + }, async getModalElevatorPrice(){ const spec = this.modalElevatorInfo.spec const person = this.modalElevatorInfo.person @@ -366,7 +395,53 @@ const pricereviewCreate = ()=>{ } }) }, + validation(){ + this.error = []; + if(this.totalElevatorsNum == 0) this.error.push("請至少輸入一種電梯"); + for(let i=0;i 0){ + let errortext = ''; + this.error.forEach(err=>{ + errortext += err+'\n'; + }) + alert(errortext) + console.log(this.error); + } + + return this.error.length > 0 ? false : true + + }, submit(){ + const validation = this.validation(); + if(!validation) return const form = new FormData(); form.append('vol_no', this.vol_no); form.append('apply_key', this.apply_key); @@ -420,7 +495,59 @@ const pricereviewCreate = ()=>{ if(attatch == 2){ this.attatch2 = e.target.files[0] } + }, + async getBonus(idx){ + let contract_type = ''; + if(this.contract_status == 1){ + contract_type = 'new' + }else if(this.contract_status == 2){ + contract_type = 'free_to_charge' + }else if(this.contract_status == 3){ + contract_type = 'renew_priceissue' + } + const contract_years = this.isDifferenceMoreThanAYear(this.startDate, this.endDate); + const receivable_date_due = this.getNext25thDate(this.startDate); + const res = await axios.get('./api/maintaenance_contract_bonus.php', {params: + { + 'contract_type':contract_type, + 'contract_years': contract_years, + 'discount': this.discountRate, + 'fee_per_st': this.elevators[idx].sale_price, + 'receivable_date_due':receivable_date_due, + 'sales_id': user_id, + 'region_manger_id': 'M0174', + 'regular_contract_manger_id': 'M0174', + }}) + + console.log(res.data); + + }, + isDifferenceMoreThanAYear(startDate, endDate) { + const oneYear = 1000 * 60 * 60 * 24 * 365; // 毫秒數 + const difference = Math.abs(endDate - startDate); + return difference > oneYear ? 'above_two' : 'one'; + }, + getNext25thDate(dateString) { + // 將傳入的日期字串轉換為 Date 物件 + let date = new Date(dateString); + + // 如果日期大於 25,則將月份加一 + if (date.getDate() > 25) { + // 增加一個月 + date.setMonth(date.getMonth() + 1); + } + + // 設定日期為 25 號 + date.setDate(25); + + // 將 Date 物件格式化為 YYYY-MM-DD 字串 + let year = date.getFullYear(); + let month = date.getMonth() + 1; // 月份是從 0 開始的,所以加 1 + month = month < 10 ? '0' + month : month; // 確保月份是兩位數 + + return `${year}-${month}-25`; } + } } @@ -436,6 +563,22 @@ const pricereviewCheck = ()=>{ }) this.elevators.forEach((elevator, idx)=>{ + if(elevator.maintain_method == 'A'){ + elevator.maintain_method = '全包' + }else if(elevator.maintain_method == 'B'){ + elevator.maintain_method = '半包' + }else if(elevator.maintain_method == 'C'){ + elevator.maintain_method = '清包' + } + if(elevator.maintain_period == 1){ + elevator.maintain_period = '月保' + }else if(elevator.maintain_period == 2){ + elevator.maintain_period = '月保兩次' + }else if(elevator.maintain_period == 3){ + elevator.maintain_period = '雙月保' + }else if(elevator.maintain_period == 4){ + elevator.maintain_period = '季保' + } this.elevators_total_price += elevator.stand_price*elevator.maintain_months this.otherOptions.forEach(option=>{ if(option.option_relate_spec == elevator.item_no){ @@ -450,6 +593,7 @@ const pricereviewCheck = ()=>{ } }) }) + console.log(this.elevators); if(payment_kind == "A40006"){ this.payment_kind = "年繳"; }else if(payment_kind == "A40007"){ diff --git a/wms/cont/pricereviewCheck.php b/wms/cont/pricereviewCheck.php index ee887c63..0c516bde 100644 --- a/wms/cont/pricereviewCheck.php +++ b/wms/cont/pricereviewCheck.php @@ -318,14 +318,31 @@ function getSignerName($signer){ - + +
+ 電梯資訊 + +
+
電梯規格 - 除外項目 + 附加項目