Browse Source

新梯契約獎金和簽回

main
Cheng 1 year ago
parent
commit
1d3989ba9c
  1. 18
      wms/bonus/bonus.php
  2. 52
      wms/bonus/other/maintenance_contract_bonus_v2_1.php
  3. 127
      wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php
  4. 59
      wms/contract/api/getContractData.php
  5. 25
      wms/contract/api/postContractData.php
  6. 63
      wms/contract/api/postNewContractData.php
  7. 20
      wms/contract/contract-input.php
  8. 3
      wms/contract/js/alpine.js

18
wms/bonus/bonus.php

@ -32,15 +32,17 @@ if (!empty($_GET['check'])) {
if ($_GET['check'] == 4) { if ($_GET['check'] == 4) {
$oneMonthAgo = date("Y-m-d", strtotime("$now +1 months")); $oneMonthAgo = date("Y-m-d", strtotime("$now +1 months"));
// $clause .= "AND pay_day_due >= '$now' AND pay_day_due <= '$oneMonthAgo' AND status IN (1,2,5)"; // $clause .= "AND pay_day_due >= '$now' AND pay_day_due <= '$oneMonthAgo' AND status IN (1,2,5)";
$clause .= "AND status IN (1,2,5)"; $clause .= "AND a.status IN (1,2,5)";
} else if ($_GET['check'] == 2) { } else if ($_GET['check'] == 2) {
$clause .= "AND status = 1"; $clause .= "AND a.status = 1";
} else if ($_GET['check'] == 3) { } else if ($_GET['check'] == 3) {
$clause .= "AND status IN (2,5)"; $clause .= "AND a.status IN (2,5)";
} }
} }
$sql = "SELECT * FROM bonus WHERE 1=1 $clause"; $sql = "SELECT a.*,b.customer FROM bonus AS a
LEFT JOIN con_maintance_examine_apply AS b ON a.contract_no = b.vol_no
WHERE 1=1 $clause";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
$datas = $stmt->fetchAll(PDO::FETCH_ASSOC); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
@ -130,17 +132,21 @@ function isPay($contract_no, $connT8)
<a href="/wms/bonus/bonus.php?check=2&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 2) ? "btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 未發獎金</a> <a href="/wms/bonus/bonus.php?check=2&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 2) ? "btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 未發獎金</a>
<a href="/wms/bonus/bonus.php?check=3&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 3) ? "btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 已發獎金</a> <a href="/wms/bonus/bonus.php?check=3&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 3) ? "btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 已發獎金</a>
<a href="/wms/bonus/bonus.php?check=4&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 4) ? "btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 人事發放作業</a> <a href="/wms/bonus/bonus.php?check=4&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 4) ? "btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 人事發放作業</a>
<a href="/wms/bonus/bonus.php?check=5&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 5) ? "btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 獎金總計(人)</a>
<table id="table_index" class="table table-striped table-bordered" style="width:100%"> <table id="table_index" class="table table-striped table-bordered" style="width:100%">
<?php if (!empty($_GET['check']) && $_GET['check'] == '4') { ?> <?php if (!empty($_GET['check']) && $_GET['check'] == '4') { ?>
<button class="btn btn-primary float-end" style="float: right;" onclick="All('<?= $id_str ?>')">鎖定並發放</button> <button class="btn btn-primary float-end" style="float: right;" onclick="All('<?= $id_str ?>')">鎖定並發放</button>
<?php } else { ?>
<input type="text" name="account_name">
<button class="btn btn-primary float-end" style="float: right;">總計搜尋</button>
<?php } ?> <?php } ?>
<thead> <thead>
<tr> <tr>
<th>項次</th> <th>項次</th>
<th>合約類別</th>
<th>合約號</th> <th>合約號</th>
<th>合約名稱</th>
<th>作番號</th> <th>作番號</th>
<th>獎金類別</th> <th>獎金類別</th>
<th>獎金版本</th> <th>獎金版本</th>
@ -178,8 +184,8 @@ function isPay($contract_no, $connT8)
?> ?>
<tr> <tr>
<td><?= $data['id'] ?></td> <td><?= $data['id'] ?></td>
<td><?= $contract_type[$data['contract_type']] ?></td>
<td><?= $data['contract_no'] ?></td> <td><?= $data['contract_no'] ?></td>
<td><?= $data['customer'] ?></td>
<td><?= $data['facility_no'] ?></td> <td><?= $data['facility_no'] ?></td>
<td><?= $bonus_type[$data['bonus_type']] ?></td> <td><?= $bonus_type[$data['bonus_type']] ?></td>
<td><?= $data['bonus_verson'] ?></td> <td><?= $data['bonus_verson'] ?></td>

52
wms/bonus/other/maintenance_contract_bonus_v2_1.php

@ -55,48 +55,48 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period,
case ($discount >= 0.8): case ($discount >= 0.8):
switch ($fee_per_st) { switch ($fee_per_st) {
case ($fee_per_st <= 3000): case ($fee_per_st <= 3000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.6; $sales_bonus = ($fee_per_st) * 0.6;
break; break;
case ($fee_per_st >= 3001 and $fee_per_st <= 3499): case ($fee_per_st >= 3001 and $fee_per_st <= 3499):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.7; $sales_bonus = ($fee_per_st) * 0.7;
break; break;
case ($fee_per_st >= 3500 and $fee_per_st <= 3999): case ($fee_per_st >= 3500 and $fee_per_st <= 3999):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.8; $sales_bonus = ($fee_per_st) * 0.8;
break; break;
case ($fee_per_st >= 4000): case ($fee_per_st >= 4000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.9; $sales_bonus = ($fee_per_st) * 0.9;
break; break;
}; };
break; break;
case ($discount >= 0.6 and $discount < 0.8): case ($discount >= 0.6 and $discount < 0.8):
switch ($fee_per_st) { switch ($fee_per_st) {
case ($fee_per_st <= 3000): case ($fee_per_st <= 3000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.48; $sales_bonus = ($fee_per_st) * 0.48;
break; break;
case ($fee_per_st >= 3001 and $fee_per_st <= 3499): case ($fee_per_st >= 3001 and $fee_per_st <= 3499):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.56; $sales_bonus = ($fee_per_st) * 0.56;
break; break;
case ($fee_per_st >= 3500 and $fee_per_st <= 3999): case ($fee_per_st >= 3500 and $fee_per_st <= 3999):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.64; $sales_bonus = ($fee_per_st) * 0.64;
break; break;
case ($fee_per_st >= 4000): case ($fee_per_st >= 4000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.72; $sales_bonus = ($fee_per_st) * 0.72;
break; break;
}; };
break; break;
case ($discount < 0.6): case ($discount < 0.6):
switch ($fee_per_st) { switch ($fee_per_st) {
case ($fee_per_st <= 3000): case ($fee_per_st <= 3000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.42; $sales_bonus = ($fee_per_st) * 0.42;
break; break;
case ($fee_per_st >= 3001 and $fee_per_st <= 3499): case ($fee_per_st >= 3001 and $fee_per_st <= 3499):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.49; $sales_bonus = ($fee_per_st) * 0.49;
break; break;
case ($fee_per_st >= 3500 and $fee_per_st <= 3999): case ($fee_per_st >= 3500 and $fee_per_st <= 3999):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.56; $sales_bonus = ($fee_per_st) * 0.56;
break; break;
case ($fee_per_st >= 4000): case ($fee_per_st >= 4000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.63; $sales_bonus = ($fee_per_st) * 0.63;
break; break;
}; };
break; break;
@ -111,16 +111,16 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period,
case "free_to_charge": case "free_to_charge":
switch ($fee_per_st) { switch ($fee_per_st) {
case ($fee_per_st <= 3000): case ($fee_per_st <= 3000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.3; $sales_bonus = ($fee_per_st) * 0.3;
break; break;
case ($fee_per_st >= 3001 and $fee_per_st <= 3499): case ($fee_per_st >= 3001 and $fee_per_st <= 3499):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.35; $sales_bonus = ($fee_per_st) * 0.35;
break; break;
case ($fee_per_st >= 3500 and $fee_per_st <= 3999): case ($fee_per_st >= 3500 and $fee_per_st <= 3999):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.4; $sales_bonus = ($fee_per_st) * 0.4;
break; break;
case ($fee_per_st >= 4000): case ($fee_per_st >= 4000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.45; $sales_bonus = ($fee_per_st) * 0.45;
break; break;
}; };
#地區處長獎金($region_director_bonus) #地區處長獎金($region_director_bonus)
@ -132,16 +132,16 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period,
case "renew_priceissue": case "renew_priceissue":
switch ($fee_per_st) { switch ($fee_per_st) {
case ($fee_per_st <= 3000): case ($fee_per_st <= 3000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.25; $sales_bonus = ($fee_per_st) * 0.25;
break; break;
case ($fee_per_st >= 3001 and $fee_per_st <= 3499): case ($fee_per_st >= 3001 and $fee_per_st <= 3499):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.3; $sales_bonus = ($fee_per_st) * 0.3;
break; break;
case ($fee_per_st >= 3500 and $fee_per_st <= 3999): case ($fee_per_st >= 3500 and $fee_per_st <= 3999):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.35; $sales_bonus = ($fee_per_st) * 0.35;
break; break;
case ($fee_per_st >= 4000): case ($fee_per_st >= 4000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.4; $sales_bonus = ($fee_per_st) * 0.4;
break; break;
}; };
#地區處長獎金($region_director_bonus) #地區處長獎金($region_director_bonus)
@ -226,7 +226,10 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period,
#2月1次 #2月1次
case "bimonthly": case "bimonthly":
$payment_ratio_due_array = array(0.166, 0.166, 0.166, 0.166, 0.166, 0.166); $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); $payday_due_array = array(1, 3, 5, 7, 9, 11);
for ($i = 0; $i < count($payment_ratio_due_array); $i++) { for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
if ($i < count($payment_ratio_due_array) - 1) { if ($i < count($payment_ratio_due_array) - 1) {
@ -246,7 +249,12 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period,
#月付 #月付
case "monthly": case "monthly":
$payment_ratio_due_array = array(0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083, 0.083); $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); $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++) { for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
if ($i < count($payment_ratio_due_array) - 1) { if ($i < count($payment_ratio_due_array) - 1) {

127
wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php

@ -41,12 +41,13 @@ result_array[
function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($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){ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($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)
{
$bonus_array = []; $bonus_array = [];
if ($ver == "2.1"){ 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);
#契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge) #契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge)
switch ($contract_type){ switch ($contract_type) {
case "longcontract_m1_free_charge": case "longcontract_m1_free_charge":
#契約員獎金($sales_bonus) #契約員獎金($sales_bonus)
#合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59)
@ -54,57 +55,57 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
case ($discount >= 0.8): case ($discount >= 0.8):
switch ($fee_per_st) { switch ($fee_per_st) {
case ($fee_per_st <= 3000): case ($fee_per_st <= 3000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.6; $sales_bonus = ($fee_per_st) * 0.6;
break; break;
case ($fee_per_st > 300 and $fee_per_st <= 4000): case ($fee_per_st > 300 and $fee_per_st <= 4000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.7; $sales_bonus = ($fee_per_st) * 0.7;
break; break;
case ($fee_per_st > 4000 and $fee_per_st <= 5000): case ($fee_per_st > 4000 and $fee_per_st <= 5000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.8; $sales_bonus = ($fee_per_st) * 0.8;
break; break;
case ($fee_per_st > 5000 and $fee_per_st <= 6000): case ($fee_per_st > 5000 and $fee_per_st <= 6000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.9; $sales_bonus = ($fee_per_st) * 0.9;
break; break;
case ($fee_per_st > 6000): case ($fee_per_st > 6000):
$sales_bonus = ($fee_per_st - $commission_fee) * 1.0; $sales_bonus = ($fee_per_st) * 1.0;
break; break;
}; };
break; break;
case ($discount >= 0.6 and $discount < 0.8): case ($discount >= 0.6 and $discount < 0.8):
switch ($fee_per_st) { switch ($fee_per_st) {
case ($fee_per_st <= 3000): case ($fee_per_st <= 3000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.42; $sales_bonus = ($fee_per_st) * 0.42;
break; break;
case ($fee_per_st > 300 and $fee_per_st <= 4000): case ($fee_per_st > 300 and $fee_per_st <= 4000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.49; $sales_bonus = ($fee_per_st) * 0.49;
break; break;
case ($fee_per_st > 4000 and $fee_per_st <= 5000): case ($fee_per_st > 4000 and $fee_per_st <= 5000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.56; $sales_bonus = ($fee_per_st) * 0.56;
break; break;
case ($fee_per_st > 5000 and $fee_per_st <= 6000): case ($fee_per_st > 5000 and $fee_per_st <= 6000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.63; $sales_bonus = ($fee_per_st) * 0.63;
break; break;
case ($fee_per_st > 6000): case ($fee_per_st > 6000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.7; $sales_bonus = ($fee_per_st) * 0.7;
break; break;
}; };
break; break;
case ($discount < 0.6): case ($discount < 0.6):
switch ($fee_per_st) { switch ($fee_per_st) {
case ($fee_per_st <= 3000): case ($fee_per_st <= 3000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.3; $sales_bonus = ($fee_per_st) * 0.3;
break; break;
case ($fee_per_st > 300 and $fee_per_st <= 4000): case ($fee_per_st > 300 and $fee_per_st <= 4000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.35; $sales_bonus = ($fee_per_st) * 0.35;
break; break;
case ($fee_per_st > 4000 and $fee_per_st <= 5000): case ($fee_per_st > 4000 and $fee_per_st <= 5000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.4; $sales_bonus = ($fee_per_st) * 0.4;
break; break;
case ($fee_per_st > 5000 and $fee_per_st <= 6000): case ($fee_per_st > 5000 and $fee_per_st <= 6000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.45; $sales_bonus = ($fee_per_st) * 0.45;
break; break;
case ($fee_per_st > 6000): case ($fee_per_st > 6000):
$sales_bonus = ($fee_per_st - $commission_fee) * 0.5; $sales_bonus = ($fee_per_st) * 0.5;
break; break;
}; };
break; break;
@ -116,81 +117,77 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
$regular_contract_manger_bonus = 300; $regular_contract_manger_bonus = 300;
break; break;
}; };
#地區處長獎金、專任契約經理、契約員獎金 #地區處長獎金、專任契約經理、契約員獎金
switch ($payment_period_amount){ switch ($payment_period_amount) {
#簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金 #簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金
#總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期, #總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期,
case $payment_period_amount >= 60: case $payment_period_amount >= 60:
#地區處長獎金 #地區處長獎金
array_push($bonus_array,[ array_push($bonus_array, [
"bonus_type" => "地區處長獎金", #獎金名稱 "bonus_type" => "地區處長獎金", #獎金名稱
"bonus_receiver" => $region_director_id, #發放人員 "bonus_receiver" => $region_director_id, #發放人員
"bonus_amount" => round($region_director_bonus), #金額 "bonus_amount" => round($region_director_bonus), #金額
"pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間
"bonus_regulation" => "訂金收回後次月發放" #發放規定 "bonus_regulation" => "訂金收回後次月發放" #發放規定
]); ]);
#專任契約經理獎金 #專任契約經理獎金
array_push($bonus_array,[ array_push($bonus_array, [
"bonus_type" => "專任契約經理獎金", #獎金名稱 "bonus_type" => "專任契約經理獎金", #獎金名稱
"bonus_receiver" => $regular_contract_manger_id, #發放人員 "bonus_receiver" => $regular_contract_manger_id, #發放人員
"bonus_amount" => round($regular_contract_manger_bonus), #金額 "bonus_amount" => round($regular_contract_manger_bonus), #金額
"pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +1 months")), #預計發放時間
"bonus_regulation" => "訂金收回後次月發放" #發放規定 "bonus_regulation" => "訂金收回後次月發放" #發放規定
]); ]);
#產生契約員每個月的獎金應發比例 #產生契約員每個月的獎金應發比例
$payment_ratio_due_array = array(); $payment_ratio_due_array = array();
for ($i = 0; $i < $payment_period_amount; $i++) { for ($i = 0; $i < $payment_period_amount; $i++) {
array_push($payment_ratio_due_array, 1/$payment_period_amount); array_push($payment_ratio_due_array, 1 / $payment_period_amount);
} }
$payday_due_array = array(); $payday_due_array = array();
for ($i = 0; $i < $payment_period_amount; $i++) { for ($i = 0; $i < $payment_period_amount; $i++) {
array_push($payday_due_array, $i+1 ); array_push($payday_due_array, $i + 1);
} }
for($i = 0; $i < count($payment_ratio_due_array); $i++) { for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
if($i < count($payment_ratio_due_array) - 1){ if ($i < count($payment_ratio_due_array) - 1) {
$current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額 $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額
}else{ } else {
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額 $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
}; };
array_push($bonus_array,[ array_push($bonus_array, [
"bonus_type" => "契約員獎金", #獎金名稱 "bonus_type" => "契約員獎金", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員 "bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($current_bonus), #金額 "bonus_amount" => round($current_bonus), #金額
"pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間 "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間
"bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定 "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定
]); ]);
} }
break; break;
} }
$result_array = [ $result_array = [
"ver"=>$ver, #獎金版本 "ver" => $ver, #獎金版本
"result_status"=>"success", #計算結果 "result_status" => "success", #計算結果
"bonus_array"=>$bonus_array #獎金水庫 "bonus_array" => $bonus_array #獎金水庫
]; ];
} else {
}else{ array_push($bonus_array, [
array_push($bonus_array,[
"bonus_type" => "error", #獎金名稱 "bonus_type" => "error", #獎金名稱
"bonus_receiver" => "error", #發放人員 "bonus_receiver" => "error", #發放人員
"bonus_amount" => 0, #金額 "bonus_amount" => 0, #金額
"pay_day_due" => "9999-1-1", #預計發放時間 "pay_day_due" => "9999-1-1", #預計發放時間
"bonus_regulation" => "error" #發放規定 "bonus_regulation" => "error" #發放規定
]); ]);
$result_array = [ $result_array = [
"ver"=>$ver, #獎金版本 "ver" => $ver, #獎金版本
"result_status"=>"error", #計算結果 "result_status" => "error", #計算結果
"bonus_array"=>$bonus_array #獎金水庫 "bonus_array" => $bonus_array #獎金水庫
]; ];
} }
return $result_array; return $result_array;
}; };
?>

59
wms/contract/api/getContractData.php

@ -1,5 +1,6 @@
<?php <?php
require_once('../conn.php'); require_once('../conn.php');
// 保養
if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 'b') { if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 'b') {
try { try {
$contractno = $_GET['contractno']; $contractno = $_GET['contractno'];
@ -43,6 +44,7 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
} }
} }
// 新梯
if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 'm') { if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 'm') {
try { try {
$contractno = $_GET['contractno']; $contractno = $_GET['contractno'];
@ -69,11 +71,51 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->bindParam(':mid', $mid); $stmt->bindParam(':mid', $mid);
$stmt->execute(); $stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); $elevators_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$elevators_detail_arr = []; $elevators_detail_arr = [];
foreach ($results as $keys => $result) {
$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 => $result) {
$item_no = $result['item_no']; //電梯項次
// 電梯 OPTION
$sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' AND option_relate_spec = :item_no";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':mid', $mid);
$stmt->bindParam(':item_no', $item_no);
$stmt->execute();
$option_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$option_arr[] = $option_results;
if (!empty($option_results)) {
$result['option_price'] = 0;
// 電梯 OPTION 價格分別加到各台電梯
foreach ($option_arr[$keys] 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) {
$item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數
$result['option_price'] += intval($option['item_unit_price']) * $item_qty;
echo '2..';
} else {
$result['option_price'] += $option['item_unit_price'] * intval($option['item_qty']);
echo '3..';
}
echo '<pre>';
print_r($option['item_no'] . '--->' . $option['item_unit_price']);
echo '</pre>';
}
print_r($result['option_price']);
exit();
}
$note = explode(',', $result['note']); $note = explode(',', $result['note']);
$result['spec'] = $note[0]; //型號 $result['spec'] = $note[0]; //型號
$result['person'] = $note[1]; // 人承 $result['person'] = $note[1]; // 人承
$result['floor'] = $note[2]; // 樓層 $result['floor'] = $note[2]; // 樓層
$result['speed'] = $note[3]; // 速度 $result['speed'] = $note[3]; // 速度
@ -82,21 +124,20 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
array_push($elevators_detail_arr, $result); array_push($elevators_detail_arr, $result);
} }
} }
// print_r(COUNT($option_results));
$count = COUNT($elevators_detail_arr); $count = COUNT($elevators_detail_arr);
$contract['elevators'] = $results; $contract['elevators'] = $elevators_results;
$contract['elevators_detail_arr'] = $elevators_detail_arr; $contract['elevators_detail_arr'] = $elevators_detail_arr;
$contract['nums'] = $count; $contract['nums'] = $count;
// echo '<pre>';
// print_r($contract);
// echo '</pre>';
// exit;
$contractResponse = json_encode($contract); $contractResponse = json_encode($contract);
// 設定回應標頭為 JSON // 設定回應標頭為 JSON
header('Content-Type: application/json'); header('Content-Type: application/json');
// 將 JSON 回應返回給客戶端 // 將 JSON 回應返回給客戶端
echo $contractResponse; // echo $contractResponse;
} catch (PDOException $e) { } catch (PDOException $e) {
die("ERROR!!!: " . $e->getMessage()); die("ERROR!!!: " . $e->getMessage());
} }

25
wms/contract/api/postContractData.php

@ -88,10 +88,10 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
if ($address == '') $fail_arr[] = '地址為必填'; if ($address == '') $fail_arr[] = '地址為必填';
if ($area == '') $fail_arr[] = '區域為必填'; if ($area == '') $fail_arr[] = '區域為必填';
if ($customer == '') $fail_arr[] = '客戶為必填'; if ($customer == '') $fail_arr[] = '客戶為必填';
if ($partyA == '') $fail_arr[] = '業務聯繫人為必填'; // if ($partyA == '') $fail_arr[] = '業務聯繫人為必填';
if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填'; // if ($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填';
if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填'; // if ($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填';
if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填'; // if ($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填';
if ($num == '') $fail_arr[] = '電梯數量為必填'; if ($num == '') $fail_arr[] = '電梯數量為必填';
if ($payType == '') $fail_arr[] = '付款方式為必填'; if ($payType == '') $fail_arr[] = '付款方式為必填';
if (count($fail_arr) > 0) { if (count($fail_arr) > 0) {
@ -99,7 +99,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
echo json_encode($fail_arr); echo json_encode($fail_arr);
exit(); exit();
} }
T8insert($_POST, $facilityno, $depId); // T8insert($_POST, $facilityno, $depId);
bonusCreate($_POST, $facilityno, $conn); bonusCreate($_POST, $facilityno, $conn);
//create account table //create account table
$accounttype = "A"; $accounttype = "A";
@ -127,7 +127,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$stmt->bindParam(':repairerid', $repairerid); $stmt->bindParam(':repairerid', $repairerid);
$stmt->bindParam(':creater', $creater); $stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at); $stmt->bindParam(':create_at', $create_at);
$stmt->execute(); // $stmt->execute();
//create contract table //create contract table
@ -163,7 +163,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$stmt->bindParam(':end_date', $end_date); $stmt->bindParam(':end_date', $end_date);
$stmt->bindParam(':creater', $creater); $stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at); $stmt->bindParam(':create_at', $create_at);
$stmt->execute(); // $stmt->execute();
//create facility table //create facility table
// $createFacilityNo = new CreateFacilityNo(); // $createFacilityNo = new CreateFacilityNo();
@ -238,7 +238,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$stmt->bindParam(':area', $area); $stmt->bindParam(':area', $area);
$stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']); $stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']);
$stmt->bindParam(':licensedate', $ADuseful_date); $stmt->bindParam(':licensedate', $ADuseful_date);
$result = $stmt->execute(); // $result = $stmt->execute();
} }
//create schedule table //create schedule table
@ -259,7 +259,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$stmt->bindParam(':duedate', $combo[1]); $stmt->bindParam(':duedate', $combo[1]);
$stmt->bindParam(':creater', $creater); $stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at); $stmt->bindParam(':create_at', $create_at);
$result = $stmt->execute(); // $result = $stmt->execute();
} }
} }
// create contract_b_signed_back table // create contract_b_signed_back table
@ -366,7 +366,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$stmt->bindParam(":created_by", $user_id); $stmt->bindParam(":created_by", $user_id);
$stmt->bindParam(':payType', $payType); $stmt->bindParam(':payType', $payType);
$stmt->execute(); // $stmt->execute();
// T8insert($_POST, $facilityno); // T8insert($_POST, $facilityno);
@ -665,7 +665,7 @@ function bonusCreate($data, $facilityno, $conn)
$status = 1; $status = 1;
$bonus_json = []; $bonus_json = [];
$create_id = $data['user_id']; $create_id = $data['user_id'];
$create_at = date('Y-m-d'); $create_at = date('Y-m-d H:i:s');
$contract_no = !empty($data['contractno']) ? $data['contractno'] : ''; $contract_no = !empty($data['contractno']) ? $data['contractno'] : '';
$contract_kind = 3; $contract_kind = 3;
@ -689,7 +689,7 @@ function bonusCreate($data, $facilityno, $conn)
$contract_type = $elevator['contract_type']; //合約類別 $contract_type = $elevator['contract_type']; //合約類別
$payment_period = $payment[$payType]; //付款方式 $payment_period = $payment[$payType]; //付款方式
$elevator_list_price = intval($elevator['stand_price']); //牌價 $elevator_list_price = intval($elevator['stand_price']); //牌價
$fee_per_st = $elevator['contract_price']; //作翻契約金額 $fee_per_st = $elevator['sold_price']; //作翻契約金額
$commission_fee = $elevator['service_expense']; //服務費(月) $commission_fee = $elevator['service_expense']; //服務費(月)
$receivable_date_due = $payDay; //第一筆保養款項收回日 $receivable_date_due = $payDay; //第一筆保養款項收回日
$sales_id = $salesman; //營業人員 $sales_id = $salesman; //營業人員
@ -722,6 +722,7 @@ function bonusCreate($data, $facilityno, $conn)
$stmt->execute(); $stmt->execute();
} }
} }
// exit();
} }
// exit(); // exit();
} catch (PDOException $e) { } catch (PDOException $e) {

63
wms/contract/api/postNewContractData.php

@ -27,7 +27,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$elevators_nums = $_POST['nums']; $elevators_nums = $_POST['nums'];
$elevators = json_decode($_POST['elevators'], true); $elevators = json_decode($_POST['elevators'], true);
$elevators_detail_arr = json_decode($_POST['elevators_detail_arr'], true); $elevators_detail_arr = json_decode($_POST['elevators_detail_arr'], true);
BounsCount($_POST, $conn);
// echo '<pre>'; // echo '<pre>';
// print_r($elevators); // print_r($elevators);
// echo '</pre>'; // echo '</pre>';
@ -54,12 +54,12 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
//create facility table //create facility table
$createFacilityNo = new CreateFacilityNo(); $createFacilityNo = new CreateFacilityNo();
$dailyNecessities = [ $dailyNecessities = [
'MAE100' => 'X', 'MAE100' => 'X', //小機房客梯
'MAM200' => 'W', 'MAM200' => 'W', //無機房客梯
'MAH100' => 'H', 'MAH100' => 'H', //小電梯
'MAQ100' => 'Z', 'MAQ100' => 'Z', //強趨梯
'MAF100' => 'F', 'MAF100' => 'F', //貨梯
'MAZ100' => 'B', 'MAP100' => 'B', //平台梯
]; ];
$arr = []; $arr = [];
// 建立作番號 // 建立作番號
@ -68,9 +68,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$arr[] = $dailyNecessities[$elevator['spec']]; $arr[] = $dailyNecessities[$elevator['spec']];
} }
$facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums)); $facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums));
echo '<pre>';
print_r($facilityno); BounsCount($_POST, $conn, $facilityno);
echo '</pre>';
exit(); exit();
$conn->beginTransaction(); $conn->beginTransaction();
@ -282,39 +281,63 @@ function T8Insert($data)
} }
function BounsCount($data, $conn) function BounsCount($data, $conn, $facilityno)
{ {
// echo '<pre>'; // echo '<pre>';
// print_r($data); // print_r($facilityno);
// echo '</pre>'; // echo '</pre>';
// exit; // exit;
require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php"); require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php");
$signing_date = $data['signing_date']; $dailyNecessities = [
$bonus_v1_0_date = '2024-01-02'; 'MAE100' => 'passenger', //小機房
$bonus_v2_0_date = '2024-01-03'; 'MAM200' => 'passenger', //無機房
'MAH100' => 'dumbwaiter', //小電梯
'MAQ100' => 'positive_drive', //強趨梯
'MAF100' => 'cargo', //貨梯
'MAP100' => 'flatbase', // 平台踢
];
$contractType = [ $contractType = [
'1' => 'strategy_customer', '1' => 'strategy_customer',
'2' => 'general_customer' '2' => 'general_customer'
]; ];
$signing_date = $data['signing_date'];
$bonus_v1_0_date = '2024-01-02';
$bonus_v2_0_date = '2024-01-03';
$contract_type = $data['contract_type']; $contract_type = $data['contract_type'];
$type = $contractType[$contract_type]; //戰略客戶 or 一般客戶 $type = $contractType[$contract_type]; //戰略客戶 or 一般客戶
$elevator_knockdown_price = $data['price_total']; //受價總額 // $elevator_knockdown_price = $data['price_total']; //受價總額
$elevators = json_decode($data['elevators_detail_arr'], true);
$salesman = $data['salesman']; $salesman = $data['salesman'];
$manager = $data['manager']; $manager = $data['manager'];
$result_bonus = []; $result_bonus = [];
$result_bonus_arr = [];
if ($signing_date <= $bonus_v1_0_date) { if ($signing_date <= $bonus_v1_0_date) {
$ver = '1.0'; $ver = '1.0';
$result_bonus = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager); foreach ($elevators as $i => $elevator) {
$elevator_knockdown_price = $elevator['item_price_ct'];
$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;
}
} else if ($signing_date >= $bonus_v2_0_date) { } else if ($signing_date >= $bonus_v2_0_date) {
$ver = '2.0'; $ver = '2.0';
// $result_bonus = elevator_new_deal_bonus_v2_0($ver,$contract_type,); foreach ($elevators as $i => $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);
}
} }
// foreach ($elevators as $elevator) {
// $elevator_knockdown_price = $elevator['item_price_ct'];
// }
echo '<pre>'; echo '<pre>';
print_r($result_bonus); print_r($result_bonus_arr);
echo '</pre>'; echo '</pre>';
exit(); exit();
try { try {

20
wms/contract/contract-input.php

@ -111,7 +111,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
</td> </td>
<td style="vertical-align: middle">契約成交價</td> <td style="vertical-align: middle">契約成交價</td>
<td> <td>
<input class="form-control disabled_select" type="text" name="tel" x-model="data.total_price" :disabled="data.disabled"> <input class="form-control disabled_select" type="number" name="tel" x-model="data.total_price" :disabled="data.disabled">
<p class="alerttext" x-show="data.total_price==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p> <p class="alerttext" x-show="data.total_price==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p>
</td> </td>
</tr> </tr>
@ -158,7 +158,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<p class="alerttext" x-show="data.payType==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p> <p class="alerttext" x-show="data.payType==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p>
</td> </td>
</tr> </tr>
<tr> <!-- <tr>
<td style="vertical-align: middle">業務聯繫人</td> <td style="vertical-align: middle">業務聯繫人</td>
<td> <td>
<input type="text" x-model="data.partyA" name="partyA" /> <input type="text" x-model="data.partyA" name="partyA" />
@ -179,7 +179,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<input class="form-control disabled_select" type="email" name="contracttel" x-model="data.partyAemail"> <input class="form-control disabled_select" type="email" name="contracttel" x-model="data.partyAemail">
<p class="alerttext" x-show="data.partyAemail==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p> <p class="alerttext" x-show="data.partyAemail==''"><i class="fa-solid fa-circle-xmark"></i>未填寫</p>
</td> </td>
</tr> </tr> -->
<tr> <tr>
<td style="vertical-align: middle">區域</td> <td style="vertical-align: middle">區域</td>
<td> <td>
@ -374,28 +374,28 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
</td> </td>
<td style="vertical-align:middle">獎金適用版本</td> <td style="vertical-align:middle">獎金適用版本</td>
<td> <td>
<input type="text" x-model="elevator.bonus_verson" disabled="disabled"> <input type="text" x-model="elevator.bonus_verson">
</td> </td>
</tr> </tr>
<tr> <tr>
<td style="vertical-align:middle">作番契約金額(月)</td> <td style="vertical-align:middle">作番契約金額(月)</td>
<td><input type="text" x-model="elevator.sold_price" disabled></td> <td><input type="text" x-model="elevator.sold_price"></td>
<td style="vertical-align:middle">牌價(標準價)</td> <td style="vertical-align:middle">牌價(標準價)</td>
<td> <td>
<input type="text" x-model="elevator.stand_price" disabled> <input type="text" x-model="elevator.stand_price">
<p>標準價+Option價格+與其他電梯共同分擔的費用貨價格</p> <p>標準價+Option價格+與其他電梯共同分擔的費用貨價格</p>
</td> </td>
<td style="vertical-align:middle">服務費</td> <td style="vertical-align:middle">服務費</td>
<td> <td>
<input type="text" x-model="elevator.service_expense" disabled> <input type="text" x-model="elevator.service_expense">
</td> </td>
<td style="vertical-align:middle">折扣率(%)</td> <td style="vertical-align:middle">折扣率(%) <br />(作番契約金額+服務費/台數) / 牌價 * 100</td>
<td><input type="text" x-model='elevator.discount' disabled></td> <td><input type="text" x-model='elevator.discount'></td>
</tr> </tr>
<tr> <tr>
<td style="vertical-align:middle">地區處長員工號</td> <td style="vertical-align:middle">地區處長員工號</td>
<td><input type="text" x-model="elevator.manager" disabled></td> <td><input type="text" x-model="elevator.manager"></td>
<td style="vertical-align:middle">專任契約經理員工號</td> <td style="vertical-align:middle">專任契約經理員工號</td>
<td><input type="text" x-model="elevator.regular_contract_manger_id"></td> <td><input type="text" x-model="elevator.regular_contract_manger_id"></td>
</tr> </tr>

3
wms/contract/js/alpine.js

@ -1090,7 +1090,8 @@ const contractInput = () => {
contract_type: '', contract_type: '',
manager: '', manager: '',
regular_contract_manger_id: '', regular_contract_manger_id: '',
bonus_verson: '' bonus_verson: '',
sold_price: ''
}) })
} }
}, },

Loading…
Cancel
Save