diff --git a/wms/cont/api/maintaenance_contract_bonus.php b/wms/cont/api/maintaenance_contract_bonus.php index e54fe820..5dd975a5 100644 --- a/wms/cont/api/maintaenance_contract_bonus.php +++ b/wms/cont/api/maintaenance_contract_bonus.php @@ -5,19 +5,28 @@ $ver = isset($_GET['ver']) ? $_GET['ver'] : null; $contract_type = isset($_GET['contract_type']) ? trim($_GET['contract_type']) : null; // 请注意删除可能的尾随空格 $contract_years = isset($_GET['contract_years']) ? $_GET['contract_years'] : null; $discount = isset($_GET['discount']) ? $_GET['discount'] : null; -$fee_per_st = isset($_GET['fee_per_st']) ? $_GET['fee_per_st'] : null; +$fee_per_st = isset($_GET['fee_per_st']) ? (int)$_GET['fee_per_st'] : null; $receivable_date_due = isset($_GET['receivable_date_due']) ? $_GET['receivable_date_due'] : null; $sales_id = isset($_GET['sales_id']) ? $_GET['sales_id'] : null; +$payment_period = isset($_GET['payment_period']) ? $_GET['payment_period'] : null; $region_manager_id = isset($_GET['region_manager_id']) ? $_GET['region_manager_id'] : null; $regular_contract_manager_id = isset($_GET['regular_contract_manager_id']) ? $_GET['regular_contract_manager_id'] : null; -$bonus = maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, $discount, $fee_per_st, $receivable_date_due, $sales_id, $region_manager_id, $regular_contract_manager_id); +if($ver == '2.0'){ + $bonus = maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, $discount, $fee_per_st, $receivable_date_due, $sales_id, $region_manager_id, $regular_contract_manager_id); +} +if($ver == '2.1'){ + $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 = ''); +} + + echo json_encode($bonus); function maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, $discount, $fee_per_st, $receivable_date_due, $sales_id, $region_manger_id, $regular_contract_manger_id = '') { $bonus_array = []; if ($ver == "2.0") { - + $sales_bonus = 0; + $region_manager_bonus = 0; #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) switch ($contract_type) { case "new": @@ -232,12 +241,12 @@ function maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, }; ## 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 = '') +function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, $discount, $fee_per_st, $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 = 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) diff --git a/wms/cont/api/postElevatorPricereview.php b/wms/cont/api/postElevatorPricereview.php index 3fea17ff..070f2b2b 100644 --- a/wms/cont/api/postElevatorPricereview.php +++ b/wms/cont/api/postElevatorPricereview.php @@ -12,6 +12,7 @@ $num = $_POST['num']; $salesman = $_POST['salesman']; $contract_begin_date = $_POST['contract_begin_date']; $contract_end_date = $_POST['contract_end_date']; +$sign_day = $_POST['signDay']; $contract_kind = $_POST['contract_kind']; $progress_remark = $_POST['progress_status']; $serviceFee = $_POST['serviceFee']; @@ -129,8 +130,8 @@ if(!empty($attatch2)){ $conn->beginTransaction(); try{ if(!$contract){ - $sql_str = "INSERT INTO con_maintance_examine_apply (apply_key, vol_no, customer, address, case_name ,brand, num, salesman, maintain_kind, contract_begin_date, contract_end_date, contract_kind, payment_kind, progress_remark, service_fee, total_price, total_sale_price, penalty, deposit_rate, keep_rate, warranty_rate, memo, status, attatch1, attatch2, creater, create_at) - VALUES (:apply_key, :vol_no, :customer, :address, :case_name ,:brand, :num, :salesman, :maintain_kind, :contract_begin_date, :contract_end_date, :contract_kind, :payment_kind, :progress_remark, :service_fee, :total_price, :total_sale_price, :penalty, :deposit_rate, :keep_rate, :warranty_rate, :memo, :status, :attatch1, :attatch2, :creater, :create_at)"; + $sql_str = "INSERT INTO con_maintance_examine_apply (apply_key, vol_no, customer, address, case_name ,brand, num, salesman, maintain_kind, contract_begin_date, contract_end_date, contract_kind, payment_kind, progress_remark, service_fee, total_price, total_sale_price, penalty, deposit_rate, keep_rate, warranty_rate, memo, status, attatch1, attatch2, sign_day, creater, create_at) + VALUES (:apply_key, :vol_no, :customer, :address, :case_name ,:brand, :num, :salesman, :maintain_kind, :contract_begin_date, :contract_end_date, :contract_kind, :payment_kind, :progress_remark, :service_fee, :total_price, :total_sale_price, :penalty, :deposit_rate, :keep_rate, :warranty_rate, :memo, :status, :attatch1, :attatch2, :sign_day, :creater, :create_at)"; $stmt = $conn->prepare($sql_str); $stmt->bindParam(':apply_key', $apply_key); $stmt->bindParam(':vol_no', $vol_no); @@ -157,6 +158,7 @@ try{ $stmt->bindParam(':status', $status); $stmt->bindParam(':attatch1', $attatch1_src); $stmt->bindParam(':attatch2', $attatch2_src); + $stmt->bindParam(':sign_day', $sign_day); $stmt->bindParam(':creater', $creater); $stmt->bindParam(':create_at', $current_date); $stmt->execute(); @@ -256,6 +258,7 @@ try{ status=:status, attatch1=:attatch1, attatch2=:attatch2, + sign_day=:sign_day, updated_at=:updated_at, progress_remark=:progress_remark WHERE apply_key=:apply_key AND vol_no=:vol_no"; @@ -282,6 +285,7 @@ try{ $stmt->bindParam(':status', $status); $stmt->bindParam(':attatch1', $attatch1_src); $stmt->bindParam(':attatch2', $attatch2_src); + $stmt->bindParam(':sign_day', $signDay); $stmt->bindParam(':updated_at', $current_date); $stmt->execute(); diff --git a/wms/cont/js/pricereviewAlpine.js b/wms/cont/js/pricereviewAlpine.js index e2c2eef9..2513c024 100644 --- a/wms/cont/js/pricereviewAlpine.js +++ b/wms/cont/js/pricereviewAlpine.js @@ -23,6 +23,7 @@ const pricereviewCreate = ()=>{ pay_method:payment_kind, // 付款方式 startDate:contract_begin_date, //合約開始日期 endDate:contract_end_date, // 合約結束日期 + signDay: signDay, //預計簽約日 brand:brand, modalElevatorInfo:{ spec:'', @@ -91,6 +92,7 @@ const pricereviewCreate = ()=>{ qty:1, //電梯數量 sale_price:'', //契約報價 inspectionFee:0, + bonus:'' }; }, createElevatorFn(){ @@ -127,7 +129,8 @@ const pricereviewCreate = ()=>{ price: this.modalElevatorInfo.price, qty: this.modalElevatorInfo.qty, sale_price: this.modalElevatorInfo.sale_price, - inspectionFee: this.modalElevatorInfo.inspectionFee + inspectionFee: this.modalElevatorInfo.inspectionFee, + bonus:'' }) this.hideCreateElevatorModal(); }, @@ -149,6 +152,7 @@ const pricereviewCreate = ()=>{ const qty = this.elevators[idx].qty; const sale_price = this.elevators[idx].sale_price; const inspectionFee = this.elevators[idx].inspectionFee; + const bonus = this.elevators[idx].bonus; this.total_spec ++; this.elevators.push({ id: this.total_spec, @@ -169,7 +173,8 @@ const pricereviewCreate = ()=>{ price: price, qty: qty, sale_price: sale_price, - inspectionFee: inspectionFee + inspectionFee: inspectionFee, + bonus: bonus }) }, removeElevator(id){ @@ -365,8 +370,9 @@ const pricereviewCreate = ()=>{ form.append('brand', this.brand); form.append('num', this.totalElevatorsNum); form.append('salesman', this.salesman); - form.append('contract_begin_date', this.startDate); + form.append('signDay', this.startDate); form.append('contract_end_date', this.endDate); + form.append('contract_begin_date', this.signDay); form.append('contract_kind', this.contract_status); form.append('progress_status', this.progress_status); form.append('serviceFee', this.serviceFee); @@ -426,6 +432,7 @@ const pricereviewCreate = ()=>{ if(this.case_name == '') this.error.push("請輸入案件名稱"); if(this.startDate == '' || this.startDate == '0000-00-00') this.error.push("請輸入合約開始日期"); if(this.endDate == '' ||this.endDate == '0000-00-00') this.error.push("請輸入合約結束日期"); + if(this.signDay == '' ||this.signDay == '0000-00-00') this.error.push("請輸入預計簽約日期"); if(this.error.length > 0){ let errortext = ''; @@ -454,6 +461,7 @@ const pricereviewCreate = ()=>{ form.append('salesman', this.salesman); form.append('contract_begin_date', this.startDate); form.append('contract_end_date', this.endDate); + form.append('signDay', this.signDay); form.append('contract_kind', this.contract_status); form.append('progress_status', this.progress_status); form.append('serviceFee', this.serviceFee); @@ -497,7 +505,10 @@ const pricereviewCreate = ()=>{ } }, async getBonus(idx){ + if(this.contract_status == "") return alert("請選擇契約性質") let contract_type = ''; + let version = ''; + let payment_period = ''; if(this.contract_status == 1){ contract_type = 'new' }else if(this.contract_status == 2){ @@ -505,10 +516,24 @@ const pricereviewCreate = ()=>{ }else if(this.contract_status == 3){ contract_type = 'renew_priceissue' } + this.getBonusVersion(this.signDay) + + if(this.pay_method == "A40003"){ + payment_period = 'monthly' + }else if(this.pay_method == "A40004"){ + payment_period = "bimonthly" + }else if(this.pay_method == "A40007"){ + payment_period = "quarterly" + }else if(this.pay_method == "A40005"){ + payment_period = "semiannually" + }else if(this.pay_method == "A40006"){ + payment_period = "annually" + } 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: { + 'ver':'2.0', 'contract_type':contract_type, 'contract_years': contract_years, 'discount': this.discountRate, @@ -517,8 +542,9 @@ const pricereviewCreate = ()=>{ 'sales_id': user_id, 'region_manger_id': 'M0174', 'regular_contract_manger_id': 'M0174', + 'payment_period': payment_period }}) - + this.elevators[idx].bonus = Number(res.data.bonus_array[0].bonus_amount) console.log(res.data); }, @@ -527,6 +553,12 @@ const pricereviewCreate = ()=>{ const difference = Math.abs(endDate - startDate); return difference > oneYear ? 'above_two' : 'one'; }, + getBonusVersion(dateString) { + const targetDate = new Date('2024-04-01'); + const dateToCheck = new Date(dateString); + + return dateToCheck > targetDate ? '2.1' : '2.0'; + }, getNext25thDate(dateString) { // 將傳入的日期字串轉換為 Date 物件 let date = new Date(dateString); @@ -546,7 +578,29 @@ const pricereviewCreate = ()=>{ month = month < 10 ? '0' + month : month; // 確保月份是兩位數 return `${year}-${month}-25`; - } + }, + generateTestData(){ + this.modalElevatorInfo = { + spec:'MAE100', + person:'10', + weight:'700', + stop:'10', + speed:'60', + permitNumber:'TEST', //許可證號碼 + brand:'永大', //品牌 + m1:'N', //贈送M1 + months:12, // 保養月數 + cycle:'1', // 保養週期 + method:'A', //保養方式 + checkYear:'100', //竣工檢查年度 + lastDate:'2023-01-01', // 上次年檢日期 + yearCheckFee:1260, //年檢費用 + price:'4400', //公司發布價(月) + qty:1, //電梯數量 + sale_price:'2500', //契約報價 + inspectionFee:0, //檢驗費 + }; + }, } } diff --git a/wms/cont/pricereviewCreate.php b/wms/cont/pricereviewCreate.php index 9a4dbc64..e50ad30d 100644 --- a/wms/cont/pricereviewCreate.php +++ b/wms/cont/pricereviewCreate.php @@ -171,7 +171,7 @@ function getApplyKey($p_yyyymm, $seq_name){
價格審查(契約)基本資料 | +價格審查(契約)基本資料 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
預計簽約日期 | ++ + 請填寫預計簽約日期 + | 合約開始日期 | @@ -447,6 +455,14 @@ function getApplyKey($p_yyyymm, $seq_name){ | ||||||||||||
+ + | ++ + | +