'; + // 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"] . "
'; + 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);
未填寫
標準價+Option價格+與其他電梯共同分擔的費用貨價格