$data) :
-
+ $bonus_json = json_decode($data['bonus_json']);
+ $bonus_kind = !empty($bonus_json->bonus_kind) ? $bonus_json->bonus_kind : '';
$contract_no = $data['contract_no'];
$json = json_decode($data['bonus_json']);
$total = empty($json->total) ? 0 : $json->total;
@@ -187,13 +194,12 @@ function isPay($contract_no, $connT8)
= $data['contract_no'] ?>
= $data['customer'] ?>
= $data['facility_no'] ?>
- = $bonus_type[$data['bonus_type']] ?>
+
= $data['bonus_verson'] ?>
= $fee_per_st ?>
= $total ?>
= $commission_fee ?>
= $data['receiver'] ?>
- = $data['pay_day_due'] ?>
= $data['amount'] ?>
= $data['bonus_actual'] ?>
@@ -225,7 +231,7 @@ function isPay($contract_no, $connT8)
- 查看詳情
+
@@ -336,6 +342,7 @@ function isPay($contract_no, $connT8)
form.append('pay_day', pay_day)
form.append('amount', amount);
form.append('postType', 'a');
+ form.append('contract_type', 'new');
axios.post('./api/postStatus.php', form).then((res) => {
if (res.data == 'Success') {
alert('更新成功');
diff --git a/wms/bonus/other/maintenance_contract_bonus_v2_1.php b/wms/bonus/other/maintenance_contract_bonus_v2_1.php
index 27959883..086dbbf1 100644
--- a/wms/bonus/other/maintenance_contract_bonus_v2_1.php
+++ b/wms/bonus/other/maintenance_contract_bonus_v2_1.php
@@ -43,10 +43,11 @@ result_array[
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;
+ $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 10);
#契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue)
switch ($contract_type) {
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
index 70a19f40..db37fd30 100644
--- 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
@@ -120,7 +120,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
};
#付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually)
array_push($bonus_array, [
- "bonus_type" => "地區處長獎金", #獎金名稱
+ "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")), #預計發放時間
@@ -130,7 +130,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
#專任契約經理獎金
if ($regular_contract_manger_id != '') {
array_push($bonus_array, [
- "bonus_type" => "專任契約經理獎金", #獎金名稱
+ "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")), #預計發放時間
@@ -162,11 +162,11 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
- "bonus_type" => "契約員獎金", #獎金名稱
+ "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" => "每月收款後,按收款比率次月發放" #發放規定
+ "bonus_regulation" => "每次收款後,按收款比率次月發放" #發放規定
]);
}
@@ -191,11 +191,11 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
- "bonus_type" => "契約員獎金", #獎金名稱
+ "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" => "每月收款後,按收款比率次月發放" #發放規定
+ "bonus_regulation" => "每次收款後,按收款比率次月發放" #發放規定
]);
}
break;
@@ -219,7 +219,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
- "bonus_type" => "契約員獎金", #獎金名稱
+ "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")), #預計發放時間
@@ -227,7 +227,6 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
]);
}
break;
- break;
#雙月繳
case 'bimonthly':
$a = $payment_period_amount / 2;
@@ -248,7 +247,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
- "bonus_type" => "契約員獎金", #獎金名稱
+ "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")), #預計發放時間
@@ -278,7 +277,7 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
- "bonus_type" => "契約員獎金", #獎金名稱
+ "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")), #預計發放時間
diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php
index 5534b8eb..7d31dcbb 100644
--- a/wms/contract/api/getContractData.php
+++ b/wms/contract/api/getContractData.php
@@ -73,14 +73,17 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
$stmt->execute();
$elevators_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$elevators_detail_arr = [];
-
- $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' ";
- $stmt = $conn->prepare($sql);
- $stmt->bindParam(':mid', $mid);
- $stmt->execute();
- $option_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $option_arr = [];
-
+ $contract_elevator_qty = 0;
+ // $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' ";
+ // $stmt = $conn->prepare($sql);
+ // $stmt->bindParam(':mid', $mid);
+ // $stmt->execute();
+ // $option_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ // $option_arr = [];
+
+ foreach ($elevators_results as $keys) {
+ $contract_elevator_qty += $keys['item_qty'];
+ }
foreach ($elevators_results as $keys => $result) {
$item_no = $result['item_no']; //電梯項次
// 電梯 OPTION
@@ -91,36 +94,87 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
$stmt->execute();
$option_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$option_arr[] = $option_results;
+ // echo "";
+ // print_r($option_arr);
+ // echo " ";
if (!empty($option_results)) {
$result['option_price'] = 0;
// 電梯 OPTION 價格分別加到各台電梯
- foreach ($option_arr[$keys] as $key => $option) {
+ foreach ($option_results as $key => $option) {
if ($option['item_qty'] == $result['item_qty']) {
$result['option_price'] += intval($option['item_unit_price']);
- echo '1..';
- } else if ($option['item_qty'] > $result['item_qty'] != 1) {
+ // 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 '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 '3..';
}
- echo '';
- print_r($option['item_no'] . '--->' . $option['item_unit_price']);
- echo ' ';
+ // echo '';
+ // print_r($option['item_no'] . '--->' . $option['item_unit_price'] . '--->' . $option['item_qty']);
+ // echo ' ';
}
- print_r($result['option_price']);
- exit();
+ // print_r($result['option_price']);
+ // exit();
}
+ // 查詢保固延長
+ $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='E' AND option_relate_spec = :item_no";
+ $stmt = $conn->prepare($sql);
+ $stmt->bindParam(':mid', $mid);
+ $stmt->bindParam(':item_no', $item_no);
+ $stmt->execute();
+ $other_option_arr = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ if (!empty($other_option_arr)) {
+ $result['option_other_price'] = 0;
+ // 電梯 OPTION 價格分別加到各台電梯
+ foreach ($other_option_arr as $key => $option) {
+ if ($option['item_qty'] == $result['item_qty']) {
+ $result['option_other_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_other_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_other_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_other_price']);
+ // exit();
+ }
+
+
$note = explode(',', $result['note']);
$result['spec'] = $note[0]; //型號
$result['person'] = $note[1]; // 人承
$result['floor'] = $note[2]; // 樓層
$result['speed'] = $note[3]; // 速度
- for ($i = 0; $i < $result['item_qty']; $i++) {
+ $count_qty = $result['item_qty'];
+ for ($i = 0; $i < $count_qty; $i++) {
+ $result['elevator_price'] = round($result['item_price_ct'] / $result['item_qty']); //合約單台電提價格
+ $result['commission_fee'] = round($contract['special_fee']) / $contract_elevator_qty;
$result['item_no'] = $i + 1;
+ $result['item_qty'] = 1;
array_push($elevators_detail_arr, $result);
}
}
@@ -137,7 +191,7 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
header('Content-Type: application/json');
// 將 JSON 回應返回給客戶端
- // echo $contractResponse;
+ echo $contractResponse;
} catch (PDOException $e) {
die("ERROR!!!: " . $e->getMessage());
}
diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php
index e8dca10f..445d0b5b 100644
--- a/wms/contract/api/postContractData.php
+++ b/wms/contract/api/postContractData.php
@@ -35,6 +35,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$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);
@@ -72,7 +73,6 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
// exit();
// }
echo json_encode($facilityno);
- /// 獎金計算
$fail_arr = [];
if ($contractno === '') return $fail_arr[] = '合約號為必填';
if ($total_price == '') $fail_arr[] = '合約總價為必填';
@@ -93,17 +93,21 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填';
if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填';
if ($num == '') $fail_arr[] = '電梯數量為必填';
- if ($payType == '') $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();
}
// T8insert($_POST, $facilityno, $depId);
+ /// 獎金計算
$aaa = bonusCreate($_POST, $facilityno, $conn);
- echo '';
- print_r($aaa);
- echo ' ';
+ if ($aaa['status'] == 2) {
+ header("HTTP/1.1 422 Unprocessable Entity");
+ echo $aaa['data'];
+ exit();
+ }
exit;
//create account table
$accounttype = "A";
@@ -683,6 +687,7 @@ function bonusCreate($data, $facilityno, $conn)
'A40005' => 'semiannually', // 半年繳
'A40003' => 'monthly' //月繳
];
+
$fail_arr = [];
$payDay = getNext25thDate($contract_begin_date);
foreach ($elevators as $key => $elevator) {
@@ -690,7 +695,7 @@ function bonusCreate($data, $facilityno, $conn)
$ver = $elevator['bonus_verson']; //獎金版本
$payment_period = $payment[$payType]; //付款方式
$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) : ''; //作翻契約金額 (不含稅)
+ $fee_per_st = !empty($elevator['sold_price']) ? intval(round($elevator['sold_price'] / 1.05, 2)) : ''; //作翻契約金額 (不含稅)
$commission_fee = !empty($elevator['service_expense']) ? $elevator['service_expense'] : ''; //服務費(月/台)
$receivable_date_due = $payDay; //第一筆保養款項收回日
$sales_id = $salesman; //營業人員
@@ -699,7 +704,7 @@ function bonusCreate($data, $facilityno, $conn)
$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;
if ($maintain_months == '') $fail_arr[] = "保養月費為必填";
if ($fee_per_st == '') $fail_arr[] = "契約金額為必填";
if ($elevator_list_price == '') $fail_arr[] = "牌價為必填";
@@ -710,12 +715,12 @@ function bonusCreate($data, $facilityno, $conn)
return $fail_arr;
break;
}
-
+ $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,
@@ -728,27 +733,28 @@ function bonusCreate($data, $facilityno, $conn)
$region_director_id,
$regular_contract_manger_id
);
- for ($i = 0; $i < $maintain_months - 1; $i++) {
+ for ($i = 1; $i <= $years - 1; $i++) {
$contract_type = 'renew_priceissue';
- // 第二年以上改續約
- $result2 = maintenance_contract_bonus_v2_1(
+ $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,
+ $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';
- $result2 = maintenance_contract_bonus_v2_1(
+ $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1(
$ver,
$contract_type,
$payment_period,
@@ -761,9 +767,9 @@ function bonusCreate($data, $facilityno, $conn)
$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(
+ } 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,
@@ -791,6 +797,7 @@ function bonusCreate($data, $facilityno, $conn)
);
}
}
+
$bonus_json = [
'contract_type' => $contract_type,
'total' => $elevator_list_price,
@@ -800,22 +807,10 @@ function bonusCreate($data, $facilityno, $conn)
'receivable_date_due' => $receivable_date_due,
'discount' => $discount
];
- if ($results['result_status'] != 'error') {
- foreach ($results['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();
- }
- if (!empty($result2)) {
- foreach ($results2['bonus_array'] as $i => $result) {
+ if (!empty($results)) {
+
+ if ($results['result_status'] != 'error') {
+ foreach ($results['bonus_array'] as $i => $result) {
$bonus_type = $result['bonus_type'];
$pay_day = $result['pay_day_due'];
@@ -823,15 +818,43 @@ function bonusCreate($data, $facilityno, $conn)
$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();
+ }
+ }
+ if (!empty($renew_priceissue_bonus)) {
+ // echo '1';
+ foreach ($renew_priceissue_bonus as $renew_priceissue_bonus) {
+ foreach ($renew_priceissue_bonus['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();
+ $stmt = $conn->prepare($sql);
+ $stmt->execute();
+ }
}
}
+ $request = [
+ "status" => "1",
+ "data" => "Success"
+ ];
+ } else {
+ $request = [
+ "status" => "2",
+ "data" => "create_bonus_error"
+ ];
}
// exit();
}
+ return $request;
// exit();
} catch (PDOException $e) {
http_response_code(404);
diff --git a/wms/contract/api/postNewContractData.php b/wms/contract/api/postNewContractData.php
index 6180e4d4..a62d6e95 100644
--- a/wms/contract/api/postNewContractData.php
+++ b/wms/contract/api/postNewContractData.php
@@ -48,7 +48,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
if (empty($qc)) $fail_arr[] = '請選擇QC或官檢';
if (count($fail_arr) > 0) {
header("HTTP/1.1 422 Unprocessable Entity");
- echo json_encode($fail_arr);
+ echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE);
exit();
}
//create facility table
@@ -69,8 +69,14 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
}
$facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums));
- BounsCount($_POST, $conn, $facilityno);
- exit();
+ $bonus_result = BounsCount($_POST, $conn, $facilityno);
+ if (!empty($bonus_result) && $bonus_result['status'] == "2") {
+ $fail_arr[] = '獎金計算錯誤,請再檢查或連繫資訊人員';
+ // header("HTTP/1.1 422 Unprocessable Entity");
+ echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE);
+ exit();
+ }
+ // exit();
$conn->beginTransaction();
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC";
@@ -118,7 +124,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$stmt->bindParam(':file_size', $file['size']);
$stmt->bindParam(':created_at', $created_at);
$stmt->bindParam(':created_by', $created_by);
- $stmt->execute();
+ // $stmt->execute();
} else {
throw new PDOException('檔案上傳失敗:' . $msg);
}
@@ -151,7 +157,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$stmt->bindParam(":created_at", $created_at);
$stmt->bindParam(":created_by", $created_by);
$stmt->bindParam(":qc", $qc);
- $stmt->execute();
+ // $stmt->execute();
$result = $conn->commit();
@@ -304,13 +310,17 @@ function BounsCount($data, $conn, $facilityno)
$bonus_v1_0_date = '2024-01-02';
$bonus_v2_0_date = '2024-01-03';
$contract_type = $data['contract_type'];
-
+ $total = $data['price_total'];
$type = $contractType[$contract_type]; //戰略客戶 or 一般客戶
// $elevator_knockdown_price = $data['price_total']; //受價總額
$elevators = json_decode($data['elevators_detail_arr'], true);
-
+ $contract_no = $data['contractno'];
$salesman = $data['salesman'];
$manager = $data['manager'];
+ $contract_kind = 1;
+ $create_id = $data['user_id'];
+ $create_at = date("Y-m-d H:i:s");
+ $status = 1;
@@ -318,28 +328,109 @@ function BounsCount($data, $conn, $facilityno)
$result_bonus_arr = [];
if ($signing_date <= $bonus_v1_0_date) {
$ver = '1.0';
- foreach ($elevators as $i => $elevator) {
+ foreach ($elevators as $key => $elevator) {
- $elevator_knockdown_price = $elevator['item_price_ct'];
+ $elevator_knockdown_price = $elevator['elevator_price']; // 單台電梯售價
+ $elevator_list_price = $elevator['option_other_price'] + $elevator['option_price'] + $elevator['elevator_price']; //牌價
$result_bonus = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager);
- $result_bonus['facility'] = $facilityno[$i];
- $result_bonus_arr[] = $result_bonus;
+ $facility_no = $facilityno[$key];
+ $bonus_json = [
+ 'contract_type' => $type,
+ 'total' => $elevator_list_price,
+ 'fee_per_st' => $elevator_knockdown_price
+ ];
+
+ if (!empty($result_bonus)) {
+ if ($result_bonus['result_status'] != "error") {
+ foreach ($result_bonus['bonus_array'] as $i => $result) {
+ $bonus_type = explode('-', $result['bonus_type']);
+ $pay_man_type = $bonus_type[0]; //發放類別
+ $bonus_kind = $bonus_type[1];
+ $amount = $result['bonus_amount']; //獎金水庫
+ $bonus_receiver = $result['bonus_receiver']; //發放人員
+ $bonus_json['payment_schedul_due'] = $result['payment_schedul_due'];
+ $bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation'];
+ $bonus_json['bonus_kind'] = $bonus_kind;
+ $a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE);
+ $sql = "INSERT INTO bonus
+ (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES
+ ($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at')
+ ";
+ $stmt = $conn->prepare($sql);
+ $stmt->execute();
+ }
+ $request = [
+ "status" => "1",
+ "data" => "Success"
+ ];
+ return $request;
+ }
+ $request = [
+ "status" => "2",
+ "data" => "create_bonus_error"
+ ];
+ return $request;
+ }
}
} else if ($signing_date >= $bonus_v2_0_date) {
$ver = '2.0';
- foreach ($elevators as $i => $elevator) {
+ foreach ($elevators as $key => $elevator) {
$elevator_type = $dailyNecessities[$elevator['spec']];
- $elevator_list_price = $elevator[''];
- $result_bonus = elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $sales_id, $region_manger_id);
+ $elevator_list_price = $elevator['option_other_price'] + $elevator['option_price'] + $elevator['elevator_price'];
+ $elevator_knockdown_price = $elevator['elevator_price'];
+ $commission_fee = $elevator['commission_fee'];
+ $result_bonus = elevator_new_deal_bonus_v2_0(
+ $ver,
+ $type,
+ $elevator_type,
+ $elevator_list_price,
+ $elevator_knockdown_price,
+ $salesman,
+ $manager
+ );
+ // echo '';
+ // print_r($result_bonus);
+ // echo ' ';
+ $facility_no = $facilityno[$key];
+ $bonus_json = [
+ 'contract_type' => $type,
+ 'total' => $elevator_list_price,
+ 'fee_per_st' => $elevator_knockdown_price
+ ];
+ if (!empty($result_bonus)) {
+ if ($result_bonus['result_status'] != "error") {
+ foreach ($result_bonus['bonus_array'] as $i => $result) {
+ $bonus_type = explode('-', $result['bonus_type']);
+ $pay_man_type = $bonus_type[0]; //發放類別
+ $bonus_kind = $bonus_type[1];
+ $amount = $result['bonus_amount']; //獎金水庫
+ $bonus_receiver = $result['bonus_receiver']; //發放人員
+ $bonus_json['payment_schedul_due'] = $result['payment_schedul_due'];
+ $bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation'];
+ $bonus_json['bonus_kind'] = $bonus_kind;
+ $a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE);
+ $sql = "INSERT INTO bonus
+ (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES
+ ($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at')
+ ";
+ $stmt = $conn->prepare($sql);
+ $stmt->execute();
+ }
+ }
+ $request = [
+ "status" => "1",
+ "data" => "Success"
+ ];
+ } else {
+ $request = [
+ "status" => "2",
+ "data" => "create_bonus_error"
+ ];
+ }
}
}
- // foreach ($elevators as $elevator) {
- // $elevator_knockdown_price = $elevator['item_price_ct'];
- // }
- echo '';
- print_r($result_bonus_arr);
- echo ' ';
- exit();
+ return $request;
+
try {
} catch (PDOException $e) {
header("HTTP/1.1 500 Internal Server Error");
diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php
index cbec41c1..56af787c 100644
--- a/wms/contract/contract-input.php
+++ b/wms/contract/contract-input.php
@@ -209,6 +209,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
新簽約
免保轉有費
續簽約
+ 長約
@@ -449,9 +450,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
-
-
-
+