Browse Source

新梯、保養獎金計算

main
Cheng 1 year ago
parent
commit
2f1afae09e
  1. 95
      wms/bonus/api/postStatus.php
  2. 146
      wms/bonus/bonus_person.php
  3. 20
      wms/bonus/elevator_new/elevator_new_deal_bonus.php
  4. 366
      wms/bonus/maintainance_bonus.php
  5. 0
      wms/bonus/maintainance_bonus_detail.php
  6. 37
      wms/bonus/new_bonus.php
  7. 3
      wms/bonus/other/maintenance_contract_bonus_v2_1.php
  8. 19
      wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php
  9. 94
      wms/contract/api/getContractData.php
  10. 65
      wms/contract/api/postContractData.php
  11. 131
      wms/contract/api/postNewContractData.php
  12. 5
      wms/contract/contract-input.php
  13. 16
      wms/contract/js/alpine.js

95
wms/bonus/api/postStatus.php

@ -2,6 +2,7 @@
require_once("../../contract/conn.php"); require_once("../../contract/conn.php");
if (!empty($_POST['id']) && !empty($_POST['postType']) && $_POST['postType'] == 'a') { if (!empty($_POST['id']) && !empty($_POST['postType']) && $_POST['postType'] == 'a') {
if ($_POST['contract_type'] == 'maintainance') {
try { try {
$id = empty($_POST['id']) ? '' : $_POST['id']; $id = empty($_POST['id']) ? '' : $_POST['id'];
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
@ -19,6 +20,19 @@ if (!empty($_POST['id']) && !empty($_POST['postType']) && $_POST['postType'] ==
echo $e->getMessage(); echo $e->getMessage();
die('Error!:' . $e->getMessage()); die('Error!:' . $e->getMessage());
} }
} else if ($_POST['contract_type'] == 'new') {
try {
$id = empty($_POST['id']) ? '' : $_POST['id'];
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
$amount = empty($_POST['amount']) ? '' : $_POST['amount'];
header("HTTP/1.1 200 success!");
echo 'Success';
} catch (PDOException $e) {
echo $e->getMessage();
die('Error!:' . $e->getMessage());
}
}
} }
// 獎金確認發放,並更新獎金 OR 實際發放時間 // 獎金確認發放,並更新獎金 OR 實際發放時間
if (!empty($_POST['postType']) && $_POST['postType'] == 'b') { if (!empty($_POST['postType']) && $_POST['postType'] == 'b') {
@ -109,3 +123,84 @@ if (!empty($_POST['postType']) && $_POST['postType'] == 'd') {
} }
// echo 'ddddd'; // echo 'ddddd';
} }
// 查看T8 是否收款
if (!empty($_POST['postType']) && $_POST['postType'] == 'e') {
$sql = "SELECT contract_no FROM bonus WHERE contract_type = 3 AND T8api_status = 1 ";
$stmt = $conn->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
// echo "<pre>";
// print_r($results);
// echo "</pre>";
foreach ($results as $result) {
$contract_no = $result['contract_no'];
$a = isPay($contract_no, $connT8);
if ($a == '1') {
try {
$sql = "UPDATE bonus SET T8api_status = 2 WHERE contract_no = :contract_no";
$stmt = $conn->prepare($sql);
$stmt->bindParam(":contract_no", $contract_no);
$stmt->execute();
header("HTTP/1.1 200 success!");
echo 'Success';
} catch (PDOException $e) {
echo $e->getMessage();
die('Error!:' . $e->getMessage());
}
}
}
}
function isPay($contract_no, $connT8)
{
// echo $contract_no;
$sql = "SELECT
a.BillNo,
b.OTaxAmt as amount,
a.CU_EstPayDate as createDate,
b.PersonId as personId,
c.BillNo as CBno,
c.CU_MaterialId as facility
FROM salIncomeApplyDetail as a
LEFT JOIN salIncomeApplyMaster as b ON a.BillNo = b.BillNo
LEFT JOIN (
SELECT aMaster.BillNo,aMaster.BizPartnerId,aDetail.CU_MaterialId FROM arCheckBill as aMaster
LEFT JOIN arCheckBillDetail as aDetail ON aMaster.BizPartnerId = aDetail.FromBillNo
WHERE aMaster.BizPartnerId = '$contract_no' AND aMaster.TypeId = 'RVS'
) AS c ON a.BillNo = c.BizPartnerId
WHERE a.BillNo = '$contract_no'
AND a.RowNo = '1'
";
$stmt = $connT8->prepare($sql);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
// $data['amount'] = intval($data['amount']);
if (!empty($data['CBno']) && $data['CBno'] != '') {
$checkBillNo = $data['CBno'];
$sql = "SELECT
c.BillDate AS CheckBillDate
FROM arWriteOffBill AS a
LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo
LEFT JOIN
(SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail
LEFT JOIN
(SELECT
arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo
FROM arCheckBill
LEFT JOIN arCheckBillInvInfo
ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1
ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c
ON a.BillNo=c.BillNo
WHERE c.checkBillNo = '$checkBillNo'
";
$stmt = $connT8->prepare($sql);
$stmt->execute();
return '1';
} else {
return '2';
}
}

146
wms/bonus/bonus_person.php

@ -0,0 +1,146 @@
<?php
include_once("../header.php");
// require_once('./connT8.php');
require("../contract/conn.php");
$now = date("Y-m-d");
$oneMonthAgo = date("Y-m-d", strtotime("$now +1 months"));
$oneMonthAgo1 = date("m", strtotime($oneMonthAgo));
$clause = "";
if ($_GET['check'] == 'maintainance') {
if (!empty($_GET)) {
$month = $_GET['months_select'];
$years = $_GET['years']; // 當前年份
$days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $years);
$select_date = date("$years-$month-01");
$select_date1 = date("$years-$month-$days_in_month");
echo $select_date1;
$clause .= "AND pay_day_due >='$select_date' AND pay_day_due <= '$select_date1' ";
} else {
$clause .= "AND pay_day_due >= '$now' AND pay_day_due <= '$oneMonthAgo' ";
}
// $clause .= "AND pay_day_due >= '$now' AND pay_day_due <= '$oneMonthAgo' ";
$sql = "SELECT a.receiver,a.amount,b.name FROM bonus AS a
LEFT JOIN account AS b ON a.receiver = b.accountid
WHERE 1=1 AND contract_type = 3 $clause ORDER BY a.receiver ASC";
$stmt = $conn->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$person_arr = [];
$bonus_arr = [];
$count = 0;
$a = 0;
$j = 0;
}
for ($i = 0; $i < COUNT($results); $i++) {
$a++;
if ($i + 1 < COUNT($results)) {
if ($results[$i]['receiver'] != $results[$i + 1]['receiver']) {
$amount = 0;
if ($i != $j) {
for ($j; $j <= $i; $j++) {
$amount += $results[$j]['amount'];
}
$person_arr['person_id'] = $results[$i]['receiver'];
$person_arr['person'] = $results[$i]['name'];
$person_arr['bonus'] = $amount;
array_push($bonus_arr, $person_arr);
} else {
$amount += $results[$j]['amount'];
$person_arr['person_id'] = $results[$i]['receiver'];
$person_arr['person'] = $results[$i]['name'];
$person_arr['bonus'] = $amount;
array_push($bonus_arr, $person_arr);
}
$j = $i + 1;
}
} else {
$amount = 0;
for ($j; $j <= $i; $j++) {
$amount += $results[$j]['amount'];
}
$amount += $results[$i]['amount'];
$person_arr['person_id'] = $results[$i]['receiver'];
$person_arr['bonus'] = $amount;
$person_arr['person'] = $results[$i]['name'];
array_push($bonus_arr, $person_arr);
}
}
?>
<div style="overflow-x:auto;margin-top:12px">
<!-- <a href="contract-newelevator-input.php?function_name=repair&<?php echo $token_link; ?>" class="btn btn-info btn-sm">
<span class="glyphicon glyphicon-plus"></span>
</a> -->
<table class='table query-table table-striped table-bordered display compact' style='width:98%;text-align:center;margin:0 auto'>
<thead>
<tr>
<td colspan="8">
<h3 style='text-align:center'><?= !empty($years) ? $years : date('Y') ?><?= !empty($month) ? $month : $oneMonthAgo1 ?>月份、個人獎金計算</h3>
</td>
</tr>
</thead>
</table>
<form method='get' action=''>
<table class='table table-striped table-bordered' style='width:70%;text-align:center;margin:0 auto'>
<tbody>
<tr>
<th style="text-align:center;vertical-align:middle;">年份</th>
<td>
<select name="years" id="">
<?php for ($i = 2020; $i <= 2030; $i++) { ?>
<option value="<?= $i ?>" <?php echo isset($_GET["years"]) && $_GET["years"] == $i ? 'selected' : ''; ?>>
<?= $i ?>
</option> <?php } ?>
</select>
</td>
<th style="text-align:center;vertical-align:middle;">月份</th>
<td>
<select name="months_select" id="">
<?php for ($i = 1; $i <= 12; $i++) { ?>
<option value="<?= $i ?>" <?php echo isset($_GET["months_select"]) && $_GET["months_select"] == $i ? 'selected' : ''; ?>>
<?= $i ?>
</option> <?php } ?>
</select>
</td>
<!-- <td><input type="text" class="form-control" name="months_select" value="<?php if (isset($_GET["facilityno"])) echo $_GET["facilityno"]; ?>"></td> -->
<!--<th>保養員姓名</th> -->
<td style="text-align:center;vertical-align:middle;width:80px"><button type="submit" style='text-align:center; margin:0 auto' class="btn btn-info btn-sm">查詢</button></td>
</tr>
</tbody>
</table>
<input type="hidden" name="function_name" value="schedule_index">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
<table id="table_index" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<!-- <th>項次</th> -->
<th>工號</th>
<th>姓名</th>
<th>總獎金水庫(實發總價)</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($bonus_arr)) {
foreach ($bonus_arr as $key => $bonus) {
?>
<tr>
<!-- <td><?php echo $key ?></td> -->
<td><?php echo $bonus['person_id'] ?></td>
<td><?php echo $bonus['person'] ?></td>
<td><?php echo $bonus['bonus'] ?></td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>

20
wms/bonus/elevator_new/elevator_new_deal_bonus.php

@ -59,7 +59,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
#營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% #營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 "bonus_type" => "1-訂金段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員 "bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($sales_bonus * 0.2), #金額 "bonus_amount" => round($sales_bonus * 0.2), #金額
"payment_schedul_due" => "deposit", #訂金已收款20% "payment_schedul_due" => "deposit", #訂金已收款20%
@ -68,7 +68,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
#營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% #營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 "bonus_type" => "1-出貨款段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員 "bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($sales_bonus * 0.5), #金額 "bonus_amount" => round($sales_bonus * 0.5), #金額
"payment_schedul_due" => "shipping", #訂金已收款20% "payment_schedul_due" => "shipping", #訂金已收款20%
@ -77,7 +77,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
#營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% #營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 "bonus_type" => "1-驗收款段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員 "bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($sales_bonus * 0.3), #金額 "bonus_amount" => round($sales_bonus * 0.3), #金額
"payment_schedul_due" => "acceptance", #訂金已收款20% "payment_schedul_due" => "acceptance", #訂金已收款20%
@ -86,7 +86,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
#區域經理提成獎金水庫-----訂金已收款100%,發放總獎金50% #區域經理提成獎金水庫-----訂金已收款100%,發放總獎金50%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 "bonus_type" => "2-訂金段", #獎金名稱
"bonus_receiver" => $region_manger_id, #發放人員 "bonus_receiver" => $region_manger_id, #發放人員
"bonus_amount" => round($region_manager_bonus * 0.5), #金額 "bonus_amount" => round($region_manager_bonus * 0.5), #金額
"payment_schedul_due" => "deposit", #訂金已收款100% "payment_schedul_due" => "deposit", #訂金已收款100%
@ -95,7 +95,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
#區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 "bonus_type" => "2-貨到工地款段", #獎金名稱
"bonus_receiver" => $region_manger_id, #發放人員 "bonus_receiver" => $region_manger_id, #發放人員
"bonus_amount" => round($region_manager_bonus * 0.5), #金額 "bonus_amount" => round($region_manager_bonus * 0.5), #金額
"payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100% "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100%
@ -150,7 +150,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_
#營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% #營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 "bonus_type" => "1-訂金段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員 "bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($sales_bonus * 0.2), #金額 "bonus_amount" => round($sales_bonus * 0.2), #金額
"payment_schedul_due" => "deposit", #訂金已收款20% "payment_schedul_due" => "deposit", #訂金已收款20%
@ -159,7 +159,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_
#營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% #營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 "bonus_type" => "1-出貨款段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員 "bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($sales_bonus * 0.5), #金額 "bonus_amount" => round($sales_bonus * 0.5), #金額
"payment_schedul_due" => "shipping", #訂金已收款20% "payment_schedul_due" => "shipping", #訂金已收款20%
@ -168,7 +168,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_
#營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% #營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 "bonus_type" => "1-驗收款段", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員 "bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($sales_bonus * 0.3), #金額 "bonus_amount" => round($sales_bonus * 0.3), #金額
"payment_schedul_due" => "acceptance", #訂金已收款20% "payment_schedul_due" => "acceptance", #訂金已收款20%
@ -177,7 +177,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_
#區域經理獎金水庫-----訂金已收款100%,發放總獎金50% #區域經理獎金水庫-----訂金已收款100%,發放總獎金50%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 "bonus_type" => "2-訂金段", #獎金名稱
"bonus_receiver" => $region_manger_id, #發放人員 "bonus_receiver" => $region_manger_id, #發放人員
"bonus_amount" => round($region_manager_bonus * 0.5), #金額 "bonus_amount" => round($region_manager_bonus * 0.5), #金額
"payment_schedul_due" => "deposit", #訂金已收款100% "payment_schedul_due" => "deposit", #訂金已收款100%
@ -186,7 +186,7 @@ function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_
#區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50%
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 "bonus_type" => "2-貨到工地款段", #獎金名稱
"bonus_receiver" => $region_manger_id, #發放人員 "bonus_receiver" => $region_manger_id, #發放人員
"bonus_amount" => round($region_manager_bonus * 0.5), #金額 "bonus_amount" => round($region_manager_bonus * 0.5), #金額
"payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100% "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100%

366
wms/bonus/maintainance_bonus.php

@ -0,0 +1,366 @@
<?php
include_once("../header.php");
// require_once('./connT8.php');
require("../contract/conn.php");
$now = date("Y-m-d");
$contract_type = [
'1' => '新梯',
'2' => '汰改',
'3' => '保養'
];
$bonus_type = [
'1' => '契約人獎金',
'2' => '區經理獎金',
'3' => '專任契約經理獎金'
];
$bonus_status = [
'1' => '未確認',
'2' => '應發已確認',
'3' => '應發未確認',
'4' => '暫不發放',
'5' => '人事審核確認'
];
$clause = '';
if ($user_id != 'M0225') {
$clause .= "AND receiver == '$user_id'";
}
if (!empty($_GET['check'])) {
// 人事發放作業,應為一個月內
if ($_GET['check'] == 4) {
$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 a.status IN (1,2,5)";
} else if ($_GET['check'] == 2) {
$clause .= "AND a.status = 1";
} else if ($_GET['check'] == 3) {
$clause .= "AND a.status IN (2,5)";
}
}
$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 AND a.contract_type = 3";
$stmt = $conn->prepare($sql);
$stmt->execute();
$datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
$now = new DateTime();
$oneMonthAgo = $now->modify('+1 month');
$id = [];
foreach ($datas as $data) {
$id[] = $data['id'];
}
$id_str = implode(',', $id);
// 查看 T8 是否有收款明細
// require("./api/get.php");
?>
<link rel="stylesheet" href="../contract-repair/styles/style.css">
<link rel="stylesheet" href="../contract-repair/semantic/dist/semantic.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script defer src="../contract-repair/js/alpinejs/cdn.min.js"></script>
<script src="../contract-repair/js/alpine.js"></script>
<script src="../contract-repair/js/axios/axios.min.js"></script>
<!-- <script src="../contract-repair/js/jquery/jquery-3.1.1.min.js"></script> -->
<script src="../contract-repair/semantic/dist/semantic.min.js"></script>
<div class="bonus_index" x-data="bonusIndexTest">
<div class="form" method="post" id="form" enctype="multipart/form-data">
<div style="overflow-x:auto;margin-top:12px">
<table class='table query-table table-striped table-bordered display compact' style='width:98%;text-align:center;margin:0 auto'>
<thead>
<tr>
<td colspan="8">
<h3 style='text-align:center'>(契約)獎金計算</h3>
</td>
</tr>
</thead>
</table>
<!-- <a href="bonus_index1.php?function_name=bonus&token=<?php echo $token; ?>" class="btn btn-info btn-sm">
<span class="glyphicon glyphicon-plus"></span>
</a> -->
<a href="/wms/bonus/bonus.php?function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (!isset($_GET['check'])) ? "btn btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 所有獎金</a>
<!-- <a href="/wms/bonus/bonus.php?check=1&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 1) ? "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=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_person.php?check=maintainance&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%">
<button class="btn btn-primary float-end" style="float: right;" onclick="isPay()">查看是否收款</button>
<?php if (!empty($_GET['check']) && $_GET['check'] == '4') { ?>
<button class="btn btn-primary float-end" style="float: right;" onclick="All('<?= $id_str ?>')">鎖定並發放</button>
<?php } ?>
<thead>
<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>
<th>實發金額</th>
<th>狀態</th>
<?php
if (!empty($_GET['check']) && $_GET['check'] == '4') {
?>
<th>實際發放時間</th>
<th>發放 / 詳情</th>
<?php } else { ?>
<th>詳情</th>
<?php
} ?>
</tr>
</thead>
<tbody>
<?php if (!empty($datas)) {
foreach ($datas as $key => $data) :
$contract_no = $data['contract_no'];
$json = json_decode($data['bonus_json']);
$total = empty($json->total) ? 0 : $json->total;
$fee_per_st = empty($json->fee_per_st) ? 0 : $json->fee_per_st;
$commission_fee = empty($json->commission_fee) ? 0 : $json->commission_fee;
// $isPay = isPay($data['contract_no'], $connT8);
?>
<tr>
<td><?= $data['id'] ?></td>
<td><?= $data['contract_no'] ?></td>
<td><?= $data['customer'] ?></td>
<td><?= $data['facility_no'] ?></td>
<td><?= $bonus_type[$data['bonus_type']] ?></td>
<td><?= $data['bonus_verson'] ?></td>
<td><?= $fee_per_st ?></td>
<td><?= $total ?></td>
<td><?= $commission_fee ?></td>
<td><?= $data['receiver'] ?></td>
<td><?= $data['pay_day_due'] ?></td>
<td><?= $data['amount'] ?></td>
<td><?= $data['bonus_actual'] ?></td>
<td>
<?= $bonus_status[$data['status']] ?>
<!-- <span><?= ($isPay == 1) ? '已收款' : '未收款' ?></span> -->
</td>
<?php if (!empty($_GET['check']) && $_GET['check'] == '4') {
if ($data['status'] == '3' || $data['status'] == '1') { ?>
<td> -- </td>
<td>
<?php
// if ($isPay == 1) {
?>
<button onclick="issue(<?= $data['id'] ?>,'<?= $user_id ?>','<?= $data['pay_day_due'] ?>','<?= $data['amount'] ?>')" type="button" class="btn applybtn" name='issuePay'>發放獎金</button>
<?php
// } else if ($payday < $oneMonthAgo) {
?>
<a href="bonus_detail.php?id=<?= $data['id'] ?>&token=<?php echo $token; ?>" class="applybtncheck">查看詳情</a>
<?php
// }
?>
</td>
<!-- <td><input type="date" value="<?= $data['pay_day'] ?>"></td> -->
<?php } else { ?>
<td><?= $data['pay_day'] ?></td>
<td><a href="bonus_check.php?id=<?= $data['id'] ?>&token=<?php echo $token; ?>" class="applybtncheck">查看詳情</a></td>
<?php }
} else { ?>
<td><a href="bonus_check.php?id=<?= $data['id'] ?>&token=<?php echo $token; ?>" class="applybtncheck">查看詳情</a></td>
<?php } ?>
</tr>
<?php
endforeach;
} ?>
</tbody>
</table>
</div>
</div>
<!-- </div> -->
<style>
table {
table-layout: fixed;
width: 100%;
}
td {
word-wrap: break-word;
}
.width_st yle_1 {
width: 125px;
}
table {
width: 100%;
}
#table_index_filter {
float: right;
}
#table_index_paginate {
table-layout: fixed;
width: 100%;
}
label {
display: inline-flex;
margin-bottom: .5rem;
margin-top: .5rem;
}
.btn-secondary {
color: #fff;
background-color: #6c757d;
border-color: #6c757d;
}
.btn-secondary:hover {
color: #fff;
background-color: #5a6268;
border-color: #545b62;
}
.applybtn {
color: #fff;
background-color: #1484c4;
/* display: block; */
border-radius: 5px;
/* padding: 5px 2px; */
font-size: 13px;
line-height: 1;
display: grid;
place-items: center;
/* 水平和垂直居中 */
/* height: 2%vh; */
/* 100%视窗高度,可根据需要调整 */
}
.applybtncheck {
color: #fff;
background-color: #eea236;
/* display: block; */
border-radius: 4px;
padding: 4px 2px;
font-size: 13px;
line-height: 1;
display: grid;
place-items: center;
/* 水平和垂直居中 */
height: 2%vh;
/* 100%视窗高度,可根据需要调整 */
}
.applybtncheck:hover {
background-color: #f0ad4e;
color: #fff;
}
.applybtn:hover {
background-color: #1494f9;
color: #fff;
}
</style>
<script>
const datas = <?php echo json_encode($datas); ?>;
function issue(id, user_id, pay_day, amount) {
// consolelog(id);
const form = new FormData();
form.append('id', id)
form.append('user_id', user_id);
form.append('pay_day', pay_day)
form.append('amount', amount);
form.append('postType', 'a');
form.append('contract_type', 'maintainance');
axios.post('./api/postStatus.php', form).then((res) => {
if (res.data == 'Success') {
alert('更新成功');
location.reload();
}
}).catch((err) => {
})
}
function All(data) {
let arr = data.split(",");
const form = new FormData();
form.append('id', arr);
form.append('user_id', '<?= $user_id ?>')
form.append('postType', 'd');
if (confirm('是否發放全部獎金')) {
axios.post('./api/postStatus.php', form).then((res) => {
if (res.status == 200) {
alert('更新成功');
location.reload();
}
}).catch((err) => {
});
}
}
function isPay() {
const form = new FormData();
form.append('user_id', '<?= $user_id ?>');
form.append('postType', 'e');
// if (confirm('是否發放全部獎金')) {
axios.post('./api/postStatus.php', form).then((res) => {
if (res.status == 200) {
alert('更新成功');
// location.reload();
}
}).catch((err) => {
});
// }
}
// $(function() {
// $("button[name=issuePay]").click(function() {
// console.log(123);
// })
// })
// function init() {
// this.isPay();
// }
// const bonusIndex = () => {
// return {
// async isPay() {
// // console.log(123)
// for (let i = 0; i < datas.length; i++) {
// await axios.get('./api/get.php?contract_no=' + datas[i].contract_no).then(res => {
// let isPay = res.data;
// // this.data.isPay.push(isPay); // 更新 x-data 中的数据
// this.isPays.push(isPay);
// }).catch(err => {
// })
// }
// console.log(this.isPays);
// }
// }
// }
</script>

0
wms/bonus/bonus_detail.php → wms/bonus/maintainance_bonus_detail.php

37
wms/bonus/bonus.php → wms/bonus/new_bonus.php

@ -42,7 +42,7 @@ if (!empty($_GET['check'])) {
$sql = "SELECT a.*,b.customer FROM bonus AS a $sql = "SELECT a.*,b.customer FROM bonus AS a
LEFT JOIN con_maintance_examine_apply AS b ON a.contract_no = b.vol_no LEFT JOIN con_maintance_examine_apply AS b ON a.contract_no = b.vol_no
WHERE 1=1 $clause"; WHERE 1=1 $clause AND a.contract_type = 1 ORDER BY a.id DESC";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
$datas = $stmt->fetchAll(PDO::FETCH_ASSOC); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
@ -124,23 +124,30 @@ function isPay($contract_no, $connT8)
<div class="bonus_index" x-data="bonusIndexTest"> <div class="bonus_index" x-data="bonusIndexTest">
<div class="form" method="post" id="form" enctype="multipart/form-data"> <div class="form" method="post" id="form" enctype="multipart/form-data">
<div style="overflow-x:auto;margin-top:12px"> <div style="overflow-x:auto;margin-top:12px">
<table class='table query-table table-striped table-bordered display compact' style='width:98%;text-align:center;margin:0 auto'>
<thead>
<tr>
<td colspan="8">
<h3 style='text-align:center'>(契約)獎金計算</h3>
</td>
</tr>
</thead>
</table>
<!-- <a href="bonus_index1.php?function_name=bonus&token=<?php echo $token; ?>" class="btn btn-info btn-sm"> <!-- <a href="bonus_index1.php?function_name=bonus&token=<?php echo $token; ?>" class="btn btn-info btn-sm">
<span class="glyphicon glyphicon-plus"></span> <span class="glyphicon glyphicon-plus"></span>
</a> --> </a> -->
<a href="/wms/bonus/bonus.php?function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (!isset($_GET['check'])) ? "btn btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 所有獎金</a> <a href="/wms/bonus/new_bonus.php?function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (!isset($_GET['check'])) ? "btn btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 所有獎金</a>
<!-- <a href="/wms/bonus/bonus.php?check=1&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 1) ? "btn-primary" : "btn-secondary"; ?> btn-sm categoryBtn"> 應發獎金</a> --> <!-- <a href="/wms/bonus/bonus.php?check=1&function_name=bonus&token=<?php echo $token; ?>" class=" btn <?php echo (isset($_GET['check']) && $_GET['check'] == 1) ? "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/new_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/new_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/new_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> <a href="/wms/bonus/bonus_person.php?check=new&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>
@ -154,7 +161,6 @@ function isPay($contract_no, $connT8)
<th>牌價</th> <th>牌價</th>
<th>服務費</th> <th>服務費</th>
<th>應發人員</th> <th>應發人員</th>
<th>預計發放時間</th>
<th>應發獎金水庫</th> <th>應發獎金水庫</th>
<th>實發金額</th> <th>實發金額</th>
<th>狀態</th> <th>狀態</th>
@ -165,7 +171,7 @@ function isPay($contract_no, $connT8)
<th>發放 / 詳情</th> <th>發放 / 詳情</th>
<?php } else { ?> <?php } else { ?>
<th>詳情</th> <!-- <th>詳情</th> -->
<?php <?php
} ?> } ?>
</tr> </tr>
@ -173,7 +179,8 @@ function isPay($contract_no, $connT8)
<tbody> <tbody>
<?php if (!empty($datas)) { <?php if (!empty($datas)) {
foreach ($datas as $key => $data) : foreach ($datas as $key => $data) :
$bonus_json = json_decode($data['bonus_json']);
$bonus_kind = !empty($bonus_json->bonus_kind) ? $bonus_json->bonus_kind : '';
$contract_no = $data['contract_no']; $contract_no = $data['contract_no'];
$json = json_decode($data['bonus_json']); $json = json_decode($data['bonus_json']);
$total = empty($json->total) ? 0 : $json->total; $total = empty($json->total) ? 0 : $json->total;
@ -187,13 +194,12 @@ function isPay($contract_no, $connT8)
<td><?= $data['contract_no'] ?></td> <td><?= $data['contract_no'] ?></td>
<td><?= $data['customer'] ?></td> <td><?= $data['customer'] ?></td>
<td><?= $data['facility_no'] ?></td> <td><?= $data['facility_no'] ?></td>
<td><?= $bonus_type[$data['bonus_type']] ?></td> <td><?php echo $bonus_type[$data['bonus_type']] . '-' . $bonus_kind ?></td>
<td><?= $data['bonus_verson'] ?></td> <td><?= $data['bonus_verson'] ?></td>
<td><?= $fee_per_st ?></td> <td><?= $fee_per_st ?></td>
<td><?= $total ?></td> <td><?= $total ?></td>
<td><?= $commission_fee ?></td> <td><?= $commission_fee ?></td>
<td><?= $data['receiver'] ?></td> <td><?= $data['receiver'] ?></td>
<td><?= $data['pay_day_due'] ?></td>
<td><?= $data['amount'] ?></td> <td><?= $data['amount'] ?></td>
<td><?= $data['bonus_actual'] ?></td> <td><?= $data['bonus_actual'] ?></td>
<td> <td>
@ -225,7 +231,7 @@ function isPay($contract_no, $connT8)
<?php } <?php }
} else { ?> } else { ?>
<td><a href="bonus_check.php?id=<?= $data['id'] ?>&token=<?php echo $token; ?>" class="applybtncheck">查看詳情</a></td> <!-- <td><a href="bonus_check.php?id=<?= $data['id'] ?>&token=<?php echo $token; ?>" class="applybtncheck">查看詳情</a></td> -->
<?php } ?> <?php } ?>
</tr> </tr>
@ -336,6 +342,7 @@ function isPay($contract_no, $connT8)
form.append('pay_day', pay_day) form.append('pay_day', pay_day)
form.append('amount', amount); form.append('amount', amount);
form.append('postType', 'a'); form.append('postType', 'a');
form.append('contract_type', 'new');
axios.post('./api/postStatus.php', form).then((res) => { axios.post('./api/postStatus.php', form).then((res) => {
if (res.data == 'Success') { if (res.data == 'Success') {
alert('更新成功'); alert('更新成功');

3
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 = '') 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 = []; $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);
$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) #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue)
switch ($contract_type) { switch ($contract_type) {

19
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) #付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually)
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "地區處長獎金", #獎金名稱 "bonus_type" => "2", #獎金名稱
"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 +12 months")), #預計發放時間 "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 != '') { if ($regular_contract_manger_id != '') {
array_push($bonus_array, [ array_push($bonus_array, [
"bonus_type" => "專任契約經理獎金", #獎金名稱 "bonus_type" => "3", #獎金名稱
"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 +12 months")), #預計發放時間 "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])); #最後一次金額 $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" => "1", #獎金名稱
"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] year")), #預計發放時間 "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])); #最後一次金額 $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" => "1", #獎金名稱
"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;
@ -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])); #最後一次金額 $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" => "1", #獎金名稱
"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")), #預計發放時間
@ -227,7 +227,6 @@ function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract
]); ]);
} }
break; break;
break;
#雙月繳 #雙月繳
case 'bimonthly': case 'bimonthly':
$a = $payment_period_amount / 2; $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])); #最後一次金額 $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" => "1", #獎金名稱
"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")), #預計發放時間
@ -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])); #最後一次金額 $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" => "1", #獎金名稱
"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")), #預計發放時間

94
wms/contract/api/getContractData.php

@ -73,14 +73,17 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
$stmt->execute(); $stmt->execute();
$elevators_results = $stmt->fetchAll(PDO::FETCH_ASSOC); $elevators_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$elevators_detail_arr = []; $elevators_detail_arr = [];
$contract_elevator_qty = 0;
$sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' "; // $sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' ";
$stmt = $conn->prepare($sql); // $stmt = $conn->prepare($sql);
$stmt->bindParam(':mid', $mid); // $stmt->bindParam(':mid', $mid);
$stmt->execute(); // $stmt->execute();
$option_results = $stmt->fetchAll(PDO::FETCH_ASSOC); // $option_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$option_arr = []; // $option_arr = [];
foreach ($elevators_results as $keys) {
$contract_elevator_qty += $keys['item_qty'];
}
foreach ($elevators_results as $keys => $result) { foreach ($elevators_results as $keys => $result) {
$item_no = $result['item_no']; //電梯項次 $item_no = $result['item_no']; //電梯項次
// 電梯 OPTION // 電梯 OPTION
@ -91,36 +94,87 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
$stmt->execute(); $stmt->execute();
$option_results = $stmt->fetchAll(PDO::FETCH_ASSOC); $option_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$option_arr[] = $option_results; $option_arr[] = $option_results;
// echo "<pre>";
// print_r($option_arr);
// echo "</pre>";
if (!empty($option_results)) { if (!empty($option_results)) {
$result['option_price'] = 0; $result['option_price'] = 0;
// 電梯 OPTION 價格分別加到各台電梯 // 電梯 OPTION 價格分別加到各台電梯
foreach ($option_arr[$keys] as $key => $option) { foreach ($option_results as $key => $option) {
if ($option['item_qty'] == $result['item_qty']) { if ($option['item_qty'] == $result['item_qty']) {
$result['option_price'] += intval($option['item_unit_price']); $result['option_price'] += intval($option['item_unit_price']);
echo '1..'; // echo '1..';
} else if ($option['item_qty'] > $result['item_qty'] != 1) { // echo "<pre>";
// print_r($option['item_unit_price']);
// echo "</pre>";
} else if ($option['item_qty'] / $result['item_qty'] != 1) {
$item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數 $item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數
$result['option_price'] += intval($option['item_unit_price']) * $item_qty; $result['option_price'] += intval($option['item_unit_price']) * $item_qty;
echo '2..'; // echo '2..';
// echo "<pre>";
// print_r(intval($option['item_unit_price']) . ' *' . $item_qty . '=' . intval($option['item_unit_price']) * $item_qty);
// echo "</pre>";
} else { } else {
$result['option_price'] += $option['item_unit_price'] * intval($option['item_qty']); $result['option_price'] += $option['item_unit_price'] * intval($option['item_qty']);
echo '3..'; // echo '3..';
}
// echo '<pre>';
// print_r($option['item_no'] . '--->' . $option['item_unit_price'] . '--->' . $option['item_qty']);
// echo '</pre>';
}
// 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 "<pre>";
// print_r($option['item_unit_price']);
// echo "</pre>";
} 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 "<pre>";
// print_r(intval($option['item_unit_price']) . ' *' . $item_qty . '=' . intval($option['item_unit_price']) * $item_qty);
// echo "</pre>";
} else {
$result['option_other_price'] += $option['item_unit_price'] * intval($option['item_qty']);
// echo '3..';
} }
echo '<pre>'; // echo '<pre>';
print_r($option['item_no'] . '--->' . $option['item_unit_price']); // print_r($option['item_no'] . '--->' . $option['item_unit_price'] . '--->' . $option['item_qty']);
echo '</pre>'; // echo '</pre>';
} }
print_r($result['option_price']); // print_r($result['option_other_price']);
exit(); // 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]; // 速度
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_no'] = $i + 1;
$result['item_qty'] = 1;
array_push($elevators_detail_arr, $result); array_push($elevators_detail_arr, $result);
} }
} }
@ -137,7 +191,7 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont
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());
} }

65
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; $files = !empty($_FILES['files']) ? $_FILES['files'] : null;
$elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : [];
$payType = !empty($_POST['payType']) ? $_POST['payType'] : null; $payType = !empty($_POST['payType']) ? $_POST['payType'] : null;
$contract_type = !empty($_POST['contract_type']) ? $_POST['contract_type'] : null;
$sql = "SELECT * FROM account WHERE accountid = '$salesman'"; $sql = "SELECT * FROM account WHERE accountid = '$salesman'";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
@ -72,7 +73,6 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
// exit(); // exit();
// } // }
echo json_encode($facilityno); echo json_encode($facilityno);
/// 獎金計算
$fail_arr = []; $fail_arr = [];
if ($contractno === '') return $fail_arr[] = '合約號為必填'; if ($contractno === '') return $fail_arr[] = '合約號為必填';
if ($total_price == '') $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 ($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 ($contract_type == '') $fail_arr[] = '合約類別為必填';
if (count($fail_arr) > 0) { if (count($fail_arr) > 0) {
header("HTTP/1.1 422 Unprocessable Entity"); header("HTTP/1.1 422 Unprocessable Entity");
echo json_encode($fail_arr); echo json_encode($fail_arr);
exit(); exit();
} }
// T8insert($_POST, $facilityno, $depId); // T8insert($_POST, $facilityno, $depId);
/// 獎金計算
$aaa = bonusCreate($_POST, $facilityno, $conn); $aaa = bonusCreate($_POST, $facilityno, $conn);
echo '<pre>'; if ($aaa['status'] == 2) {
print_r($aaa); header("HTTP/1.1 422 Unprocessable Entity");
echo '</pre>'; echo $aaa['data'];
exit();
}
exit; exit;
//create account table //create account table
$accounttype = "A"; $accounttype = "A";
@ -683,6 +687,7 @@ function bonusCreate($data, $facilityno, $conn)
'A40005' => 'semiannually', // 半年繳 'A40005' => 'semiannually', // 半年繳
'A40003' => 'monthly' //月繳 'A40003' => 'monthly' //月繳
]; ];
$fail_arr = []; $fail_arr = [];
$payDay = getNext25thDate($contract_begin_date); $payDay = getNext25thDate($contract_begin_date);
foreach ($elevators as $key => $elevator) { foreach ($elevators as $key => $elevator) {
@ -690,7 +695,7 @@ function bonusCreate($data, $facilityno, $conn)
$ver = $elevator['bonus_verson']; //獎金版本 $ver = $elevator['bonus_verson']; //獎金版本
$payment_period = $payment[$payType]; //付款方式 $payment_period = $payment[$payType]; //付款方式
$elevator_list_price = !empty(intval($elevator['stand_price'])) ? intval($elevator['stand_price']) : ''; //牌價 $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'] : ''; //服務費(月/台) $commission_fee = !empty($elevator['service_expense']) ? $elevator['service_expense'] : ''; //服務費(月/台)
$receivable_date_due = $payDay; //第一筆保養款項收回日 $receivable_date_due = $payDay; //第一筆保養款項收回日
$sales_id = $salesman; //營業人員 $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'] : ''; $regular_contract_manger_id = !empty($elevator['regular_contract_manger_id']) ? $elevator['regular_contract_manger_id'] : '';
$maintain_months = intval($elevator['maintain_months']); $maintain_months = intval($elevator['maintain_months']);
$years = $maintain_months / 12; $years = $maintain_months / 12;
echo $years;
if ($maintain_months == '') $fail_arr[] = "保養月費為必填"; if ($maintain_months == '') $fail_arr[] = "保養月費為必填";
if ($fee_per_st == '') $fail_arr[] = "契約金額為必填"; if ($fee_per_st == '') $fail_arr[] = "契約金額為必填";
if ($elevator_list_price == '') $fail_arr[] = "牌價為必填"; if ($elevator_list_price == '') $fail_arr[] = "牌價為必填";
@ -710,12 +715,12 @@ function bonusCreate($data, $facilityno, $conn)
return $fail_arr; return $fail_arr;
break; break;
} }
$renew_priceissue_bonus = [];
// $years = ($maintain_months % 12) == 0 ? $maintain_months / 12 : ''; // $years = ($maintain_months % 12) == 0 ? $maintain_months / 12 : '';
// 如果保養合約 大於一年 // 如果保養合約 大於一年
if (!empty($maintain_months)) { if (!empty($maintain_months)) {
if ($maintain_months > 12 && $contract_type == 'new') { if ($maintain_months > 12 && $contract_type == 'new') {
// 第一年為新簽約 // 第一年為 "新簽約"
$results = maintenance_contract_bonus_v2_1( $results = maintenance_contract_bonus_v2_1(
$ver, $ver,
$contract_type, $contract_type,
@ -728,27 +733,28 @@ function bonusCreate($data, $facilityno, $conn)
$region_director_id, $region_director_id,
$regular_contract_manger_id $regular_contract_manger_id
); );
for ($i = 0; $i < $maintain_months - 1; $i++) { for ($i = 1; $i <= $years - 1; $i++) {
$contract_type = 'renew_priceissue'; $contract_type = 'renew_priceissue';
// 第二年以上改續約 $receivable_date_due_renew = date("Y-m-d", strtotime("$receivable_date_due + $i year"));
$result2 = maintenance_contract_bonus_v2_1( // 第二年以上改 "續約"
$renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1(
$ver, $ver,
$contract_type, $contract_type,
$payment_period, $payment_period,
$elevator_list_price, $elevator_list_price,
$fee_per_st, $fee_per_st,
$commission_fee, $commission_fee,
$receivable_date_due, $receivable_date_due_renew,
$sales_id, $sales_id,
$region_director_id, $region_director_id,
$regular_contract_manger_id $regular_contract_manger_id
); );
} }
} else if ($maintain_months > 12 && $contract_type == 'renew_priceissue') { } else if ($maintain_months > 12 && $contract_type == 'renew_priceissue') {
// 超過一年的續約 // 超過一年的 "續約"
for ($i = 0; $i < $years; $i++) { for ($i = 0; $i < $years; $i++) {
$contract_type = 'renew_priceissue'; $contract_type = 'renew_priceissue';
$result2 = maintenance_contract_bonus_v2_1( $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1(
$ver, $ver,
$contract_type, $contract_type,
$payment_period, $payment_period,
@ -761,9 +767,9 @@ function bonusCreate($data, $facilityno, $conn)
$regular_contract_manger_id $regular_contract_manger_id
); );
} }
} else if ($maintain_months >= 60) { } else if ($maintain_months >= 60 && $contract_type = 'longcontract_m1_free_charge') {
$contract_type = 'longcontract_m1_free_charge'; // 五年以上長約
$result = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( $results = maintenance_longterm_contract_m1_free_charge_bonus_v2_1(
$ver, $ver,
$contract_type, $contract_type,
$payment_period, $payment_period,
@ -791,6 +797,7 @@ function bonusCreate($data, $facilityno, $conn)
); );
} }
} }
$bonus_json = [ $bonus_json = [
'contract_type' => $contract_type, 'contract_type' => $contract_type,
'total' => $elevator_list_price, 'total' => $elevator_list_price,
@ -800,6 +807,8 @@ function bonusCreate($data, $facilityno, $conn)
'receivable_date_due' => $receivable_date_due, 'receivable_date_due' => $receivable_date_due,
'discount' => $discount 'discount' => $discount
]; ];
if (!empty($results)) {
if ($results['result_status'] != 'error') { if ($results['result_status'] != 'error') {
foreach ($results['bonus_array'] as $i => $result) { foreach ($results['bonus_array'] as $i => $result) {
@ -814,8 +823,11 @@ function bonusCreate($data, $facilityno, $conn)
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
} }
if (!empty($result2)) { }
foreach ($results2['bonus_array'] as $i => $result) { 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']; $bonus_type = $result['bonus_type'];
$pay_day = $result['pay_day_due']; $pay_day = $result['pay_day_due'];
@ -826,12 +838,23 @@ function bonusCreate($data, $facilityno, $conn)
(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,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')"; ($bonus_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$receiver','$pay_day',$status,'$a','$create_id','$create_at')";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
// $stmt->execute(); $stmt->execute();
} }
} }
} }
$request = [
"status" => "1",
"data" => "Success"
];
} else {
$request = [
"status" => "2",
"data" => "create_bonus_error"
];
}
// exit(); // exit();
} }
return $request;
// exit(); // exit();
} catch (PDOException $e) { } catch (PDOException $e) {
http_response_code(404); http_response_code(404);

131
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 (empty($qc)) $fail_arr[] = '請選擇QC或官檢';
if (count($fail_arr) > 0) { if (count($fail_arr) > 0) {
header("HTTP/1.1 422 Unprocessable Entity"); header("HTTP/1.1 422 Unprocessable Entity");
echo json_encode($fail_arr); echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE);
exit(); exit();
} }
//create facility table //create facility table
@ -69,8 +69,14 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
} }
$facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums)); $facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums));
BounsCount($_POST, $conn, $facilityno); $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();
}
// exit();
$conn->beginTransaction(); $conn->beginTransaction();
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; $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(':file_size', $file['size']);
$stmt->bindParam(':created_at', $created_at); $stmt->bindParam(':created_at', $created_at);
$stmt->bindParam(':created_by', $created_by); $stmt->bindParam(':created_by', $created_by);
$stmt->execute(); // $stmt->execute();
} else { } else {
throw new PDOException('檔案上傳失敗:' . $msg); 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_at", $created_at);
$stmt->bindParam(":created_by", $created_by); $stmt->bindParam(":created_by", $created_by);
$stmt->bindParam(":qc", $qc); $stmt->bindParam(":qc", $qc);
$stmt->execute(); // $stmt->execute();
$result = $conn->commit(); $result = $conn->commit();
@ -304,13 +310,17 @@ function BounsCount($data, $conn, $facilityno)
$bonus_v1_0_date = '2024-01-02'; $bonus_v1_0_date = '2024-01-02';
$bonus_v2_0_date = '2024-01-03'; $bonus_v2_0_date = '2024-01-03';
$contract_type = $data['contract_type']; $contract_type = $data['contract_type'];
$total = $data['price_total'];
$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); $elevators = json_decode($data['elevators_detail_arr'], true);
$contract_no = $data['contractno'];
$salesman = $data['salesman']; $salesman = $data['salesman'];
$manager = $data['manager']; $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 = []; $result_bonus_arr = [];
if ($signing_date <= $bonus_v1_0_date) { if ($signing_date <= $bonus_v1_0_date) {
$ver = '1.0'; $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 = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager);
$result_bonus['facility'] = $facilityno[$i]; $facility_no = $facilityno[$key];
$result_bonus_arr[] = $result_bonus; $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) { } else if ($signing_date >= $bonus_v2_0_date) {
$ver = '2.0'; $ver = '2.0';
foreach ($elevators as $i => $elevator) { foreach ($elevators as $key => $elevator) {
$elevator_type = $dailyNecessities[$elevator['spec']]; $elevator_type = $dailyNecessities[$elevator['spec']];
$elevator_list_price = $elevator['']; $elevator_list_price = $elevator['option_other_price'] + $elevator['option_price'] + $elevator['elevator_price'];
$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_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 '<pre>';
// print_r($result_bonus);
// echo '</pre>';
$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();
} }
} }
// foreach ($elevators as $elevator) { $request = [
// $elevator_knockdown_price = $elevator['item_price_ct']; "status" => "1",
// } "data" => "Success"
echo '<pre>'; ];
print_r($result_bonus_arr); } else {
echo '</pre>'; $request = [
exit(); "status" => "2",
"data" => "create_bonus_error"
];
}
}
}
return $request;
try { try {
} catch (PDOException $e) { } catch (PDOException $e) {
header("HTTP/1.1 500 Internal Server Error"); header("HTTP/1.1 500 Internal Server Error");

5
wms/contract/contract-input.php

@ -209,6 +209,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<option value="new">新簽約</option> <option value="new">新簽約</option>
<option value="free_to_charge">免保轉有費</option> <option value="free_to_charge">免保轉有費</option>
<option value="renew_priceissue">續簽約</option> <option value="renew_priceissue">續簽約</option>
<option value="longcontract_m1_free_charge">長約</option>
</select> </select>
</td> </td>
</tr> </tr>
@ -449,9 +450,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
</div> </div>
</div> </div>
<script src="./js/jquery/jquery-3.1.1.min.js"></script>
<script src="semantic/dist/semantic.min.js"></script>
<script src="./js/alpine.js"></script>
<script> <script>
const user_id = '<?php echo $user_id; ?>' const user_id = '<?php echo $user_id; ?>'
const user_name = '<?php echo $user_name; ?>' const user_name = '<?php echo $user_name; ?>'

16
wms/contract/js/alpine.js

@ -810,7 +810,7 @@ const contractNewInput = () => {
return { return {
init() { }, init() { },
data: { data: {
contractno: 'M23110004', contractno: 'M24020029',
customer: '', customer: '',
manager: '', manager: '',
vat: '', vat: '',
@ -827,7 +827,7 @@ const contractNewInput = () => {
signing_date: '', //合約簽訂日期 signing_date: '', //合約簽訂日期
elevators: [], // 電梯種類 Array elevators: [], // 電梯種類 Array
elevators_detail_arr: [], // 電梯台數 Array elevators_detail_arr: [], // 電梯台數 Array
nums: '', //電梯數量 nums: 0, //電梯數量
}, },
step: 1, step: 1,
isLoading: false, isLoading: false,
@ -838,6 +838,7 @@ const contractNewInput = () => {
if (this.step == 1) { if (this.step == 1) {
this.getContractDate(); this.getContractDate();
} else if (this.step == 2) { } else if (this.step == 2) {
if (this.data.nums <= 0) return alert('請填寫電梯數量!')
this.getElevatorsData(); this.getElevatorsData();
} else if (this.step == 3) { } else if (this.step == 3) {
this.getElevatorsData(); this.getElevatorsData();
@ -1106,16 +1107,18 @@ const contractInput = () => {
this.isLoading = false this.isLoading = false
return return
} }
console.log(res.data.service_expense);
if (!this.customize) { if (!this.customize) {
this.data.elevators = res.data.elevators; this.data.elevators = res.data.elevators;
for (let i = 0; i < res.data.elevators.length; i++) { for (let i = 0; i < res.data.elevators.length; i++) {
// 合約總價格。 // 合約總價格。
this.data.total_price = Number(res.data.elevators[i].sold_price) + Number(this.data.total_price); this.data.total_price = Math.round(Number(res.data.elevators[i].sold_price) + Number(this.data.total_price));
// 服務費 (以單筆合約記,但計算獎金須傳入單月服務費) // 服務費 (以單筆合約記,但計算獎金須傳入單月服務費)
this.data.elevators[i].service_expense = Math.round(this.data.elevators[i].service_expense / res.data.elevators[i]); this.data.elevators[i].service_expense = Math.round(this.data.elevators[i].service_expense / res.data.elevators[i].maintain_months);
// 折扣率 // 折扣率
this.data.elevators[i].discount = Math.round(((res.data.elevators[i].sold_price / res.data.elevators[i].stand_price) + this.data.elevators[i].service_expense) * 100); this.data.elevators[i].discount = ((res.data.elevators[i].sold_price - this.data.elevators[i].service_expense) / res.data.elevators[i].stand_price);
this.data.elevators[i].sold_price = Math.round(res.data.elevators[i].sold_price);
} }
this.data.total_price = Number(res.data.elevators[0].maintain_months) * this.data.total_price; this.data.total_price = Number(res.data.elevators[0].maintain_months) * this.data.total_price;
this.data.salesman = res.data.salesman this.data.salesman = res.data.salesman
@ -1245,7 +1248,8 @@ const contractInput = () => {
this.data.zip = '' this.data.zip = ''
this.data.partyAphone = '' this.data.partyAphone = ''
this.data.partyAemail = '' this.data.partyAemail = ''
this.data.payType = '' this.data.payType = '';
this.data.contract_type = ''
} }
this.isLoading = false this.isLoading = false
}).catch(error => { }).catch(error => {

Loading…
Cancel
Save