10994015 1 year ago
parent
commit
982ded377a
  1. 1
      .gitignore
  2. 15
      wms/T8_Authorization_from_bpm.php
  3. 523
      wms/account-receivable-maintainance-index.php
  4. 125
      wms/bonus/api/postStatus.php
  5. 146
      wms/bonus/bonus_person.php
  6. 20
      wms/bonus/elevator_new/elevator_new_deal_bonus.php
  7. 73
      wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0.php
  8. 121
      wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0_examination.php
  9. 99
      wms/bonus/maintainance_bonus.php
  10. 0
      wms/bonus/maintainance_bonus_detail.php
  11. 400
      wms/bonus/new_bonus.php
  12. 77
      wms/bonus/other/maintenance_contract_bonus_v2_1.php
  13. 8
      wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php
  14. 127
      wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php
  15. 311
      wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php
  16. 174
      wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php
  17. 12
      wms/contract/api/T8api.php
  18. 146
      wms/contract/api/getContractData.php
  19. 236
      wms/contract/api/postContractData.php
  20. 781
      wms/contract/api/postNewContractData.php
  21. 398
      wms/contract/api/test copy.json
  22. 211
      wms/contract/api/test.json
  23. 291
      wms/contract/api/testT8API.php
  24. 62
      wms/contract/contract-input.php
  25. 14
      wms/contract/contract-newelevator-input.php
  26. 84
      wms/contract/js/alpine.js

1
.gitignore

@ -29,3 +29,4 @@ wms/gary2.php
wms/chinese.php wms/chinese.php
phpinfo.php phpinfo.php
wms/account_receivable_sql_file.sql wms/account_receivable_sql_file.sql
wms/account_receivable_maintainance_sql.sql

15
wms/T8_Authorization_from_bpm.php

@ -4,9 +4,8 @@
// $user_password = "M012290493119"; // $user_password = "M012290493119";
// echo $validation = get_Auth($user_id, $user_password); // echo $validation = get_Auth($user_id, $user_password);
// function get_Auth($user_id = "ADMIN", $user_password = "chi")
// function get_Auth($user_id = "M0000", $user_password = "M012290493119") function get_Auth($user_id = "M0000", $user_password = "M012290493119")
function get_Auth($user_id = "ADMIN", $user_password = "chi")
{ {
$currentTime = time(); $currentTime = time();
$twoMinutesLater = $currentTime - (2 * 60); $twoMinutesLater = $currentTime - (2 * 60);
@ -14,14 +13,14 @@ function get_Auth($user_id = "ADMIN", $user_password = "chi")
// $now = gmdate("YmdHis"); // $now = gmdate("YmdHis");
$now = gmdate("YmdHis", strtotime("-2 minutes")); $now = gmdate("YmdHis", strtotime("-2 minutes"));
$data = "$user_id." . $now; $data = "$user_id." . $now;
// $sign = hash_hmac('SHA256', $data, 'A21181F1EE4966D3', false); $sign = hash_hmac('SHA256', $data, '91EB2CB12C3F8211', false);
$sign = hash_hmac('SHA256', $data, 'A733DAD19527399E', false); // $sign = hash_hmac('SHA256', $data, 'A733DAD19527399E', false); 普來特富
// echo $sign; // echo $sign;
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'; // $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
// $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; ----- $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
$apiurl = 'http://101.132.66.206:880/twWebAPI/GetAuth'; // $apiurl = 'http://101.132.66.206:880/twWebAPI/GetAuth'; 普來特富
// $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth'; // $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth';
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'; // $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
@ -31,7 +30,7 @@ function get_Auth($user_id = "ADMIN", $user_password = "chi")
"Pwd: $user_password", "Pwd: $user_password",
"TimestampUTC: $now", "TimestampUTC: $now",
"Sign: $sign", "Sign: $sign",
"GroupId:ceshi" "GroupId:MASADA"
]; ];
$ch = curl_init(); $ch = curl_init();

523
wms/account-receivable-maintainance-index.php

@ -0,0 +1,523 @@
<?php
include "header.php";
include "css/view/wipwhole-index.php";
// 設置一個空陣列來放資料
$data = array();
$start_date = empty($_POST['date_start']) ? null : $_POST['date_start'];
$end_date = empty($_POST['date_end']) ? null : $_POST['date_end'];
$start_SignDate = empty($_POST['date_Signstart']) ? null : $_POST['date_Signstart'];
$end_SignDate = empty($_POST['date_Signend']) ? null : $_POST['date_Signend'];
$sql = "
SELECT
siam.PersonId,
cp.PersonName,
cd.DeptId,
cd.DeptName,
cd.LeaderId,
lcp.PersonName AS LeaderName,
siam.BizPartnerId,
cbp.BizPartnerName,
siamd.RowCode,
siam.BillNo,
siamd.ProjectId,
siamd.CU_EstPayDate,
siamd.UnTransCheckBLAmtWTax ,
siamd.HadTransCheckBLAmtWTax,
siamd.OAmountWithTax,
siamd.CU_MaterialId,
acb_tmp.BillNo2,
acb_tmp.RowCode2,
acb_tmp.checkOAmount,
asim.BillNo AS BillNo3,
asim.InvoiceName,
asim.OAmountWithTax AS InvoiceOAmount,
asi.InvoiceNo,
asi.InvoiceTime,
writeoff.BillDate AS WriteOffDate,
SUM(arwobd.CurrStandOffOAmount) AS TotalCurrStandOffOAmount
FROM salIncomeApplyMaster AS siam -- 收入申請單
LEFT JOIN salIncomeApplyDetail AS siamd -- 收入申請單明細
ON siam.BillNo = siamd.BillNo
LEFT JOIN comGroupPerson AS cp -- 員工主檔
ON siam.PersonId = cp.PersonId
LEFT JOIN comDepartment AS cd -- 部門主檔
ON siam.DeptId = cd.DeptId
LEFT JOIN comGroupPerson AS lcp
ON lcp.PersonId= cd.LeaderId
LEFT JOIN (
SELECT
acbd.FromRowCode,
acb.FromBillNo,
acbd.BillNo AS BillNo2,
acbd.RowCode AS RowCode2,
acbd.LAmountWithTax AS checkOAmount
FROM arCheckBill AS acb -- 應收確認單
LEFT JOIN arCheckBillDetail AS acbd -- 應收確認單明細
ON acb.BillNo = acbd.BillNo
WHERE 1 = 1
AND acb.TypeId = 'RVS') AS acb_tmp
ON siamd.RowCode = acb_tmp.FromRowCode
AND siamd.BillNo = acb_tmp.FromBillNo
LEFT JOIN arSellInvoiceMaterial AS asim -- 買賣發票明細
ON asim.FromBillNo = acb_tmp.BillNo2
AND asim.RowCode = acb_tmp.RowCode2
LEFT JOIN arSellInvoice AS asi
ON asim.BillNo = asi.BillNo
LEFT JOIN comBusinessPartner AS cbp
ON siam.BizPartnerId = cbp.BizPartnerId
LEFT JOIN
arWriteOffBillDetail AS arwobd
ON acb_tmp.BillNo2 = arwobd.FromBillNo
LEFT JOIN
arWriteOffBill AS writeoff ON arwobd.BillNo = writeoff.BillNo
WHERE 1 = 1
";
$follower = find_follow($user_id);
if ((in_array($user_id, array('M0008', 'M0012'))) || (in_array(accountidToDepartId($user_id), array('220', '210', '501')))) {
} else {
$sql .= " AND (siam.PersonId = '$user_id'";
if (count($follower) > 0) {
$column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower);
$column_str .= "')";
$sql .= " OR siam.PersonId IN $column_str OR cd.LeaderId = '$user_id')";
} else {
$sql .= " OR cd.LeaderId = '$user_id')";
};
}
if (!is_null($start_date)) {
$start_date = (int)date('Ymd', strtotime($start_date));
$sql .= " AND siam.CU_ContractStart >= $start_date ";
}
if (!is_null($end_date)) {
$end_date = (int)date('Ymd', strtotime($end_date));
$sql .= " AND siam.CU_ContractStart <= $end_date ";
}
if (!is_null($start_SignDate)) {
$start_SignDate = (int)date('Ymd', strtotime($start_SignDate));
$sql .= " AND siam.BillDate >= $start_SignDate ";
}
if (!is_null($end_SignDate)) {
$end_SignDate = (int)date('Ymd', strtotime($end_SignDate));
$sql .= " AND siam.BillDate <= $end_SignDate ";
}
$sql .= " GROUP BY
siam.PersonId,
cp.PersonName,
cd.DeptId,
cd.DeptName,
cd.LeaderId,
lcp.PersonName,
siam.BizPartnerId,
cbp.BizPartnerName,
siamd.RowCode,
siam.BillNo,
siamd.ProjectId,
siamd.CU_EstPayDate,
siamd.UnTransCheckBLAmtWTax,
siamd.HadTransCheckBLAmtWTax,
siamd.OAmountWithTax,
siamd.CU_MaterialId,
acb_tmp.BillNo2,
acb_tmp.RowCode2,
acb_tmp.checkOAmount,
asim.BillNo,
asim.InvoiceName,
asim.OAmountWithTax,
asi.InvoiceNo,
asi.InvoiceTime,
writeoff.BillDate
ORDER BY
siam.PersonId ASC,
siam.BillNo ASC,
siamd.RowCode ASC";
$query_T8 = $conn->query($sql);
$rows = $query_T8->fetchAll(PDO::FETCH_ASSOC);
$today = strtotime(date('Ymt'));
$table = "";
for ($i = 0; $i < count($rows); $i++) {
$row = $rows[$i];
$tmpname = $row['ProjectId'] . $row['RowCode'];
$data[$tmpname] = $row;
$data[$tmpname]['CU_EstPayDate'] = date('Y-m-d', strtotime($row['CU_EstPayDate']));
$data[$tmpname]['havetopay'] = strtotime($row['CU_EstPayDate']) > $today ? '--' : 'V';
$datahavetopay = $row['CU_EstPayDate'] > $today ? 0 : 1;
$data[$tmpname]['collecttime'] = collect_month(strtotime($row['CU_EstPayDate']));
$invoicedate = is_null($row['InvoiceTime']) ? null : date('Y-m-d', strtotime($row['InvoiceTime']));
$tableinvoice_state = is_null($invoicedate) ? 0 : 1;
$contract_no = $row['ProjectId'];
$facility_no = $row['CU_MaterialId'];
$RowCode = $row['RowCode'];
$BillNo = $row['BillNo'];
$receivable_date = date('Y-m-d', strtotime($row['CU_EstPayDate']));
$budget = $row['OAmountWithTax'];
$invoiceNo = $row['InvoiceNo'];
$invoice_budget = is_null($row['InvoiceOAmount']) ? 0 : $row['InvoiceOAmount'];
$table_writeoff_date = is_null($row['WriteOffDate']) ? null : date('Y-m-d', strtotime($row['WriteOffDate']));
$table_writeoff_amount = is_null($row['TotalCurrStandOffOAmount']) ? 0 : $row['TotalCurrStandOffOAmount'];
$table1 = "INSERT INTO account_receivable_maintainance(
`contract_no`,
`facility_no`,
`RowCode`,
`BillNo`,
`receivable_date`,
`budget`,
`receivable`,
`invoice_state`,
`invoice_budget`,
`received_budget`
";
$table2 = ") VALUES(
'$contract_no',
'$facility_no',
'$RowCode',
'$BillNo',
'$receivable_date',
$budget,
$datahavetopay,
$tableinvoice_state,
$invoice_budget,
$table_writeoff_amount
";
$table1 .= is_null($invoicedate) ? "" : ",`invoice_date`";
$table2 .= is_null($invoicedate) ? "" : ",'$invoicedate'";
$table1 .= is_null($table_writeoff_date) ? "" : ",`received_date`";
$table2 .= is_null($table_writeoff_date) ? "" : ",'$table_writeoff_date'";
$table1 .= is_null($invoiceNo) ? "" : ",`invoice_no`";
$table2 .= is_null($invoiceNo) ? "" : ",'$invoiceNo'";
$table .= $table1 . $table2 . "); \n";
}
// $file_path = 'account_receivable_maintainance_sql.sql';
// if (file_put_contents($file_path, $table) !== false) {
// echo "SQL文件已成功生成:{$file_path}";
// } else {
// echo "生成SQL文件时出现错误。";
// }
// foreach ($data as $key => $row) {
// echo $key . "<br>";
// print_r($row);
// echo "<br>------------<br>";
// }
// exit();
?>
<style>
table {
table-layout: fixed;
width: 100%;
}
td {
word-wrap: break-word;
}
img {
width: 125px;
}
.width_style_1 {
width: 125px;
}
table {
width: 100%;
}
#table_index_filter {
float: right;
}
#table_index_paginate {
float: right;
}
label {
display: inline-flex;
margin-bottom: .5rem;
margin-top: .5rem;
}
.hiddenTable {
display: none;
}
.hidden {
display: none;
}
</style>
<div style="width: 98%;margin: 1%;">
<div class="btn-group btn-group-md " style="padding:10 px; width: 100%;">
<button type="button" style="width: 12%;" onclick="downloadData()" class="btn btn-success">下載 <span class="glyphicon glyphicon-download-alt"></span></button>
</div>
</div>
<div class="container">
<div class="text-center" style="margin-bottom: 20px;">
<h3><strong>應收帳款(保養)</strong></h3>
</div>
<hr>
<form class="form-horizontal" id='myForm' method='post' action='account-receivable-new-index.php?<?= $token_link ?>'>
<table class="table table-striped table-bordered" style='width:98%;text-align:center;margin:0 auto'>
<tbody>
<tr>
<th class="text-center" style="vertical-align: middle;">簽約日期</th>
<td colspan="2">
<input type="date" class='form-control' id='date_Signstart' name='date_Signstart' style='width:40%;display:inline;'>
<input type="date" class='form-control' id='date_Signend' name='date_Signend' style='width:40%;display:inline;'>
</td>
<td rowspan="2">
<button type="submit" class="btn btn-primary btn-sm">搜尋</button>
</td>
</tr>
<tr>
<th class="text-center" style="vertical-align: middle;">合約日期</th>
<td colspan="2">
<input type="date" class='form-control' id='date_start' name='date_start' style='width:40%;display:inline;'>
<input type="date" class='form-control' id='date_end' name='date_end' style='width:40%;display:inline;'>
<!-- <button type="submit" class="btn btn-primary btn-sm">搜尋</button> -->
</td>
</tr>
<tr>
<th class="text-center" style="vertical-align: middle;">催收次數</th>
<td colspan="3">
<input type="text" class='form-control' id='search_collectstart' name='collect_time_start' style='width:30%;display:inline;' oninput="searchFront('collectstart')">
≤ 催收次數 ≤
<input type="text" class='form-control' id='search_collectend' name='collect_time_end' style='width:30%;display:inline;' oninput="searchFront('collectend')">
<!-- <button type="submit" class="btn btn-primary btn-sm">搜尋</button> -->
</td>
</tr>
<tr>
<th class="text-center" style="vertical-align: middle;">催收金額</th>
<td colspan="3">
<input type="text" class='form-control' id='search_CBudgetstart' name='collect_budget_start' style='width:30%;display:inline;' onblur="searchFront('CBudgetstart')">
≤ 催收金額 ≤
<input type="text" class='form-control' id='search_CBudgetend' name='collect_budget_end' style='width:30%;display:inline;' onblur="searchFront('CBudgetend')">
<!-- <button type="submit" class="btn btn-primary btn-sm">搜尋</button> -->
</td>
</tr>
</tbody>
</table>
</form>
<hr>
<div class="form-group">
<div class="col-md-4">
<label for="search_contract">查詢合約號</label>
<input type="text" id="search_contract" name="search_contract" class="form-control" placeholder="請輸入合約號" onblur="searchFront('contract')">
</div>
<div class="col-md-4">
<label for="search_dept">查詢部門</label>
<input type="text" id="search_dept" name="search_dept" class="form-control" placeholder="請輸入部門" onblur="searchFront('dept')">
</div>
<div class="col-md-4">
<label for="search_manager">查詢主管</label>
<input type="text" id="search_manager" name="search_manager" class="form-control" placeholder="請輸入主管工號/姓名" onblur="searchFront('manager')">
</div>
</div>
<div class="form-group">
<div class="col-md-4">
<label for="search_personId">查詢契約員</label>
<input type="text" id="search_personId" name="search_personId" class="form-control" placeholder="請輸入契約員工號/姓名" onblur="searchFront('personId')">
</div>
<div class="col-md-4">
<label for="search_customerid">查詢客戶名稱</label>
<input type="text" id="search_customerid" name="search_customerid" class="form-control" placeholder="請輸入客戶名稱" onblur="searchFront('customerid')">
</div>
<div class="col-md-4">
<label for="search_facility">查詢作番號</label>
<input type="text" id="search_facility" name="search_facility" class="form-control" placeholder="請輸入作番號" onblur="searchFront('facility')">
</div>
</div>
</div>
<?php
include "./footer.php";
?>
<div style="width: 20%;float:right;margin-right:5%; ">
<label>查詢條件</label>
<input type="text" id="search" name="search" class="form-control" placeholder="請輸入合約號/作番號/客戶名稱" oninput="searchData()">
</div>
<div style="width: 98%; margin:1%;" style="overflow-x:auto;">
<table class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th style='text-align:center;vertical-align: middle;width:100px'>合約號</th>
<th style='text-align:center;vertical-align: middle;'>序號</th>
<th style='text-align:center;vertical-align: middle;width:100px'>作番號</th>
<th style='text-align:center;vertical-align: middle;width:110px'>部門</th>
<th style='text-align:center;vertical-align: middle;'>主管</th>
<th style='text-align:center;vertical-align: middle;'>契約員</th>
<th style='text-align:center;vertical-align: middle;width:120px'>客戶名稱</th>
<th style='text-align:center;vertical-align: middle;'>應收日期</th>
<th style='text-align:center;vertical-align: middle;'>是否應收</th>
<th style='text-align:center;vertical-align: middle;'>應收金額</th>
<!--
<th style='text-align:end;vertical-align: middle;'>已開金額</th>
<th style='text-align:end;vertical-align: middle;'>未開金額</th> -->
<th style='text-align:center;vertical-align: middle;'>已收金額</th>
<th style='text-align:center;vertical-align: middle;'>催收金額</th>
<th style='text-align:center;vertical-align: middle;'>催收次數</th>
</tr>
</thead>
<tbody>
<?php foreach ($data as $key => $row) { ?>
<tr class="data-row" style="display: '';" id="<?= $key; ?>">
<td class="contract"><?= $row['ProjectId']; ?></td>
<td><?= $row['RowCode']; ?></td>
<td class="facility"><?= $row['CU_MaterialId']; ?></td>
<td class="dept"><?= $row['DeptId'] . "<br>" . $row['DeptName']; ?></td>
<td class="manager"><?= $row['LeaderId'] . "<br>" . $row['LeaderName']; ?></td>
<td class="personId"><?= $row['PersonId'] . "<br>" . $row['PersonName']; ?></td>
<td class="customerid"><?= $row['BizPartnerId'] . "<br>" . $row['BizPartnerName']; ?></td>
<td><?= $row['CU_EstPayDate']; ?></td>
<td><?= $row['havetopay']; ?></td>
<td><?= number_format(round($row['OAmountWithTax'])); ?></td>
<td><?= is_null($row['TotalCurrStandOffOAmount']) ? 0 : number_format(round($row['TotalCurrStandOffOAmount'])); ?></td>
<td class="CBudget"><?= ($row['havetopay'] == "V")? (number_format(round($row['OAmountWithTax'] - $row['TotalCurrStandOffOAmount']))) :0; ?></td>
<td class="collect"><?= (($row['havetopay'] == "V") && ($row['OAmountWithTax'] - $row['TotalCurrStandOffOAmount'] >1))? $row['collecttime']:0; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<script>
function searchData() {
var searchTerm = document.getElementById('search').value.toLowerCase();
var rows = document.getElementsByClassName('data-row');
for (var i = 0; i < rows.length; i++) {
var rowText = rows[i].textContent.toLowerCase();
// var rowText = rows[i].id.toLowerCase();
if (rowText.includes(searchTerm)) {
console.log(rowText);
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
}
}
function downloadData() {
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/account-receivable-renovate-excel.php?type=all&<?= $token_link ?>";
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var file_path = xhr.responseText;
var link = document.createElement('a');
var name = "汰改應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";
link.setAttribute('href', window.location.origin + "/wms/account-receivable-renovate.xlsx");
link.setAttribute('download', name);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
xhr.send(JSON.stringify({
Bill: <?= $total_data ?>
}));
}
function searchFront(area) {
var term = 'search_' + area;
if (area == 'collectstart') {
var searchTerm = parseInt(document.getElementById(term).value);
var searchArea = document.getElementsByClassName('collect');
var rows = document.getElementsByClassName('data-row');
var criterion = parseInt(document.getElementById('search_collectend').value);
for (var i = 0; i < rows.length; i++) {
var rowText = parseInt(searchArea[i].textContent);
if (rowText >= searchTerm) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
if (criterion !== '' && rowText > criterion) {
rows[i].style.display = 'none';
}
}
} else if (area == 'collectend') {
var searchTerm = parseInt(document.getElementById(term).value);
var searchArea = document.getElementsByClassName('collect');
var rows = document.getElementsByClassName('data-row');
var criterion = parseInt(document.getElementById('search_collectstart').value);
for (var i = 0; i < rows.length; i++) {
var rowText = parseInt(searchArea[i].textContent);
if (rowText <= searchTerm) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
if (criterion !== '' && rowText < criterion) {
rows[i].style.display = 'none';
}
}
} else if (area == 'CBudgetstart') {
var searchTerm = parseInt(document.getElementById(term).value);
var searchArea = document.getElementsByClassName('CBudget');
var rows = document.getElementsByClassName('data-row');
var criterion = parseInt(document.getElementById('search_CBudgetend').value);
for (var i = 0; i < rows.length; i++) {
var rowText = parseInt(searchArea[i].textContent.replace(/,/g, ''));
if (isNaN(searchTerm) || searchTerm == 0) {
rows[i].style.display = '';
} else if (rowText >= searchTerm) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
if (criterion !== '' && rowText > criterion) {
rows[i].style.display = 'none';
}
}
} else if (area == 'CBudgetend') {
var searchTerm = parseInt(document.getElementById(term).value);
var searchArea = document.getElementsByClassName('CBudget');
var rows = document.getElementsByClassName('data-row');
var criterion = parseInt(document.getElementById('search_CBudgetstart').value);
for (var i = 0; i < rows.length; i++) {
var rowText = parseInt(searchArea[i].textContent.replace(/,/g, ''));
if (isNaN(searchTerm) || searchTerm == 0) {
rows[i].style.display = '';
} else if (rowText <= searchTerm) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
if (!isNaN(criterion) && rowText < criterion) {
rows[i].style.display = 'none';
}
}
} else {
var searchTerm = document.getElementById(term).value.toLowerCase();
var searchArea = document.getElementsByClassName(area);
var rows = document.getElementsByClassName('data-row');
for (var i = 0; i < rows.length; i++) {
var rowText = searchArea[i].textContent.toLowerCase();
if (rowText.includes(searchTerm)) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
}
}
}
function check(searchname) {
console.log(searchname);
}
</script>

125
wms/bonus/api/postStatus.php

@ -2,22 +2,36 @@
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') {
try { if ($_POST['contract_type'] == 'maintainance') {
$id = empty($_POST['id']) ? '' : $_POST['id']; try {
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; $id = empty($_POST['id']) ? '' : $_POST['id'];
$amount = empty($_POST['amount']) ? '' : $_POST['amount']; $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
$pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; $amount = empty($_POST['amount']) ? '' : $_POST['amount'];
$review_at = date("Y-m-d H:i:s"); $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day'];
$sql = "UPDATE bonus SET status = 2 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day',update_id='$user_id',update_at='$review_at' WHERE id = $id"; $review_at = date("Y-m-d H:i:s");
$stmt = $conn->prepare($sql); $sql = "UPDATE bonus SET status = 2 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day',update_id='$user_id',update_at='$review_at' WHERE id = $id";
$stmt->execute(); $stmt = $conn->prepare($sql);
$stmt->execute();
header("HTTP/1.1 200 success!"); header("HTTP/1.1 200 success!");
echo 'Success'; echo 'Success';
} catch (PDOException $e) { } catch (PDOException $e) {
header("HTTP/1.1 404 failed!"); header("HTTP/1.1 404 failed!");
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 實際發放時間
@ -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%

73
wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0.php

@ -35,13 +35,14 @@ result_array[
function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $sales_id, $region_manger_id){ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $sales_id, $region_manger_id)
{
$bonus_array = []; $bonus_array = [];
if ($ver == "2.0"){ if ($ver == "2.0") {
$discount = round($elevator_knockdown_price / $elevator_list_price, 3); #銷售點數,取到小數點第三位。 $discount = round($elevator_knockdown_price / $elevator_list_price, 3); #銷售點數,取到小數點第三位。
#合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer) #合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer)
switch ($contract_type){ switch ($contract_type) {
case "strategy_customer": case "strategy_customer":
#契約員獎金($sales_bonus) #契約員獎金($sales_bonus)
$sales_bonus = $elevator_knockdown_price * 0.007; $sales_bonus = $elevator_knockdown_price * 0.007;
@ -51,7 +52,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
case "general_customer": case "general_customer":
switch ($elevator_type) { switch ($elevator_type) {
#客梯(passenger)、貨梯(cargo) #客梯(passenger)、貨梯(cargo)
case ($elevator_type == "passenger" or $elevator_type == "cargo"): case ($elevator_type == "passenger" or $elevator_type == "cargo"):
switch ($discount) { switch ($discount) {
case ($discount >= 1.0): case ($discount >= 1.0):
@ -62,14 +63,14 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
break; break;
case ($discount >= 0.75 and $discount < 0.9): case ($discount >= 0.75 and $discount < 0.9):
$sales_bonus = $elevator_knockdown_price * 0.015; $sales_bonus = $elevator_knockdown_price * 0.015;
break; break;
case ($discount < 0.75): case ($discount < 0.75):
$sales_bonus = $elevator_knockdown_price * 0.008; $sales_bonus = $elevator_knockdown_price * 0.008;
break; break;
}; };
break; break;
#小電梯(dumbwaiter)、平台梯(flatbase)、強驅(positive_drive) #小電梯(dumbwaiter)、平台梯(flatbase)、強驅(positive_drive)
case ($elevator_type == "dumbwaiter" or $elevator_type == "flatbase" or $elevator_type == "positive_drive"): case ($elevator_type == "dumbwaiter" or $elevator_type == "flatbase" or $elevator_type == "positive_drive"):
switch ($discount) { switch ($discount) {
case ($discount >= 1.0): case ($discount >= 1.0):
@ -80,7 +81,7 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
break; break;
case ($discount >= 0.72 and $discount < 0.9): case ($discount >= 0.72 and $discount < 0.9):
$sales_bonus = $elevator_knockdown_price * 0.015; $sales_bonus = $elevator_knockdown_price * 0.015;
break; break;
case ($discount < 0.72): case ($discount < 0.72):
$sales_bonus = $elevator_knockdown_price * 0.008; $sales_bonus = $elevator_knockdown_price * 0.008;
break; break;
@ -91,74 +92,72 @@ function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $ele
$region_manager_bonus = 600; $region_manager_bonus = 600;
break; break;
}; };
#營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% #營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20%
array_push($bonus_array,[ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 "bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱
"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%
"payment_schedul_regulation" => "訂金已收款20%,發放總獎金20%" #發放規定 "payment_schedul_regulation" => "訂金已收款20%,發放總獎金20%" #發放規定
]); ]);
#營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% #營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%
array_push($bonus_array,[ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 "bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱
"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%
"payment_schedul_regulation" => "出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%" #發放規定 "payment_schedul_regulation" => "出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%" #發放規定
]); ]);
#營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% #營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%
array_push($bonus_array,[ array_push($bonus_array, [
"bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 "bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱
"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%
"payment_schedul_regulation" => "驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%" #發放規定 "payment_schedul_regulation" => "驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%" #發放規定
]); ]);
#區域經理提成獎金水庫-----訂金已收款100%,發放總獎金50% #區域經理提成獎金水庫-----訂金已收款100%,發放總獎金50%
array_push($bonus_array,[ array_push($bonus_array, [
"bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 "bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱
"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%
"payment_schedul_regulation" => "訂金已收款100%,發放總獎金50%" #發放規定 "payment_schedul_regulation" => "訂金已收款100%,發放總獎金50%" #發放規定
]); ]);
#區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50%
array_push($bonus_array,[ array_push($bonus_array, [
"bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 "bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱
"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%
"payment_schedul_regulation" => "貨到工地款(含)之前所有款項已收款100%,發放總獎金50%" #發放規定 "payment_schedul_regulation" => "貨到工地款(含)之前所有款項已收款100%,發放總獎金50%" #發放規定
]); ]);
$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, #金額
"payment_schedul_due" => "9999-1-1", #預計發放時間 "payment_schedul_due" => "9999-1-1", #預計發放時間
"payment_schedul_regulation" => "error" #發放規定 "payment_schedul_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;
}; };
?>

121
wms/bonus/elevator_new/elevator_new_deal_bonus_v2_0_examination.php

@ -41,76 +41,85 @@ require_once("elevator_new_deal_bonus_v2_0.php");
#獎金測試 #獎金測試
$examination_array = [ $examination_array = [
#錯誤版本 #錯誤版本
["1.0","strategy_customer","passenger",1000000,1000000,"M0001", "M0003"], ["1.0", "strategy_customer", "passenger", 1000000, 1000000, "M0001", "M0003"],
#戰略客戶(strategy_customer) #戰略客戶(strategy_customer)
["2.0","strategy_customer","passenger",1000000,1000000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數100% ["2.0", "strategy_customer", "passenger", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、客梯、銷售點數100%
["2.0","strategy_customer","passenger",1000000,900000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數90% ["2.0", "strategy_customer", "passenger", 1000000, 900000, "M0001", "M0003"], #戰略客戶、客梯、銷售點數90%
["2.0","strategy_customer","passenger",1000000,750000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數75% ["2.0", "strategy_customer", "passenger", 1000000, 750000, "M0001", "M0003"], #戰略客戶、客梯、銷售點數75%
["2.0","strategy_customer","passenger",1000000,600000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數60% ["2.0", "strategy_customer", "passenger", 1000000, 600000, "M0001", "M0003"], #戰略客戶、客梯、銷售點數60%
["2.0","strategy_customer","cargo",1000000,1000000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數100% ["2.0", "strategy_customer", "cargo", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、貨梯、銷售點數100%
["2.0","strategy_customer","cargo",1000000,900000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數90% ["2.0", "strategy_customer", "cargo", 1000000, 900000, "M0001", "M0003"], #戰略客戶、貨梯、銷售點數90%
["2.0","strategy_customer","cargo",1000000,750000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數75% ["2.0", "strategy_customer", "cargo", 1000000, 750000, "M0001", "M0003"], #戰略客戶、貨梯、銷售點數75%
["2.0","strategy_customer","cargo",1000000,600000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數60% ["2.0", "strategy_customer", "cargo", 1000000, 600000, "M0001", "M0003"], #戰略客戶、貨梯、銷售點數60%
["2.0","strategy_customer","dumbwaiter",1000000,1000000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數100% ["2.0", "strategy_customer", "dumbwaiter", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、小電梯、銷售點數100%
["2.0","strategy_customer","dumbwaiter",1000000,900000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數90% ["2.0", "strategy_customer", "dumbwaiter", 1000000, 900000, "M0001", "M0003"], #戰略客戶、小電梯、銷售點數90%
["2.0","strategy_customer","dumbwaiter",1000000,720000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數75% ["2.0", "strategy_customer", "dumbwaiter", 1000000, 720000, "M0001", "M0003"], #戰略客戶、小電梯、銷售點數75%
["2.0","strategy_customer","dumbwaiter",1000000,600000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數60% ["2.0", "strategy_customer", "dumbwaiter", 1000000, 600000, "M0001", "M0003"], #戰略客戶、小電梯、銷售點數60%
["2.0","strategy_customer","flatbase",1000000,1000000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數100% ["2.0", "strategy_customer", "flatbase", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、平台梯、銷售點數100%
["2.0","strategy_customer","flatbase",1000000,900000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數90% ["2.0", "strategy_customer", "flatbase", 1000000, 900000, "M0001", "M0003"], #戰略客戶、平台梯、銷售點數90%
["2.0","strategy_customer","flatbase",1000000,720000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數75% ["2.0", "strategy_customer", "flatbase", 1000000, 720000, "M0001", "M0003"], #戰略客戶、平台梯、銷售點數75%
["2.0","strategy_customer","flatbase",1000000,600000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數60% ["2.0", "strategy_customer", "flatbase", 1000000, 600000, "M0001", "M0003"], #戰略客戶、平台梯、銷售點數60%
["2.0","strategy_customer","positive_drive",1000000,1000000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數100% ["2.0", "strategy_customer", "positive_drive", 1000000, 1000000, "M0001", "M0003"], #戰略客戶、強驅、銷售點數100%
["2.0","strategy_customer","positive_drive",1000000,900000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數90% ["2.0", "strategy_customer", "positive_drive", 1000000, 900000, "M0001", "M0003"], #戰略客戶、強驅、銷售點數90%
["2.0","strategy_customer","positive_drive",1000000,720000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數75% ["2.0", "strategy_customer", "positive_drive", 1000000, 720000, "M0001", "M0003"], #戰略客戶、強驅、銷售點數75%
["2.0","strategy_customer","positive_drive",1000000,600000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數60% ["2.0", "strategy_customer", "positive_drive", 1000000, 600000, "M0001", "M0003"], #戰略客戶、強驅、銷售點數60%
#一般客戶(general_customer) #一般客戶(general_customer)
["2.0","general_customer","passenger",1000000,1000000,"M0001", "M0003"], #一般客戶、客梯、銷售點數100% ["2.0", "general_customer", "passenger", 1000000, 1000000, "M0001", "M0003"], #一般客戶、客梯、銷售點數100%
["2.0","general_customer","passenger",1000000,900000,"M0001", "M0003"], #一般客戶、客梯、銷售點數90% ["2.0", "general_customer", "passenger", 1000000, 900000, "M0001", "M0003"], #一般客戶、客梯、銷售點數90%
["2.0","general_customer","passenger",1000000,750000,"M0001", "M0003"], #一般客戶、客梯、銷售點數75% ["2.0", "general_customer", "passenger", 1000000, 750000, "M0001", "M0003"], #一般客戶、客梯、銷售點數75%
["2.0","general_customer","passenger",1000000,600000,"M0001", "M0003"], #一般客戶、客梯、銷售點數60% ["2.0", "general_customer", "passenger", 1000000, 600000, "M0001", "M0003"], #一般客戶、客梯、銷售點數60%
["2.0","general_customer","cargo",1000000,1000000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數100% ["2.0", "general_customer", "cargo", 1000000, 1000000, "M0001", "M0003"], #一般客戶、貨梯、銷售點數100%
["2.0","general_customer","cargo",1000000,900000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數90% ["2.0", "general_customer", "cargo", 1000000, 900000, "M0001", "M0003"], #一般客戶、貨梯、銷售點數90%
["2.0","general_customer","cargo",1000000,750000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數75% ["2.0", "general_customer", "cargo", 1000000, 750000, "M0001", "M0003"], #一般客戶、貨梯、銷售點數75%
["2.0","general_customer","cargo",1000000,600000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數60% ["2.0", "general_customer", "cargo", 1000000, 600000, "M0001", "M0003"], #一般客戶、貨梯、銷售點數60%
["2.0","general_customer","dumbwaiter",1000000,1000000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數100% ["2.0", "general_customer", "dumbwaiter", 1000000, 1000000, "M0001", "M0003"], #一般客戶、小電梯、銷售點數100%
["2.0","general_customer","dumbwaiter",1000000,900000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數90% ["2.0", "general_customer", "dumbwaiter", 1000000, 900000, "M0001", "M0003"], #一般客戶、小電梯、銷售點數90%
["2.0","general_customer","dumbwaiter",1000000,720000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數75% ["2.0", "general_customer", "dumbwaiter", 1000000, 720000, "M0001", "M0003"], #一般客戶、小電梯、銷售點數75%
["2.0","general_customer","dumbwaiter",1000000,600000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數60% ["2.0", "general_customer", "dumbwaiter", 1000000, 600000, "M0001", "M0003"], #一般客戶、小電梯、銷售點數60%
["2.0","general_customer","flatbase",1000000,1000000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數100% ["2.0", "general_customer", "flatbase", 1000000, 1000000, "M0001", "M0003"], #一般客戶、平台梯、銷售點數100%
["2.0","general_customer","flatbase",1000000,900000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數90% ["2.0", "general_customer", "flatbase", 1000000, 900000, "M0001", "M0003"], #一般客戶、平台梯、銷售點數90%
["2.0","general_customer","flatbase",1000000,720000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數75% ["2.0", "general_customer", "flatbase", 1000000, 720000, "M0001", "M0003"], #一般客戶、平台梯、銷售點數75%
["2.0","general_customer","flatbase",1000000,600000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數60% ["2.0", "general_customer", "flatbase", 1000000, 600000, "M0001", "M0003"], #一般客戶、平台梯、銷售點數60%
["2.0","general_customer","positive_drive",1000000,1000000,"M0001", "M0003"], #一般客戶、強驅、銷售點數100% ["2.0", "general_customer", "positive_drive", 1000000, 1000000, "M0001", "M0003"], #一般客戶、強驅、銷售點數100%
["2.0","general_customer","positive_drive",1000000,900000,"M0001", "M0003"], #一般客戶、強驅、銷售點數90% ["2.0", "general_customer", "positive_drive", 1000000, 900000, "M0001", "M0003"], #一般客戶、強驅、銷售點數90%
["2.0","general_customer","positive_drive",1000000,720000,"M0001", "M0003"], #一般客戶、強驅、銷售點數75% ["2.0", "general_customer", "positive_drive", 1000000, 720000, "M0001", "M0003"], #一般客戶、強驅、銷售點數75%
["2.0","general_customer","positive_drive",1000000,600000,"M0001", "M0003"] #一般客戶、強驅、銷售點數60% ["2.0", "general_customer", "positive_drive", 1000000, 600000, "M0001", "M0003"] #一般客戶、強驅、銷售點數60%
]; ];
for($i = 0; $i<count($examination_array); $i++){ for ($i = 0; $i < count($examination_array); $i++) {
$result = elevator_new_deal_bonus_v2_0( $result = elevator_new_deal_bonus_v2_0(
$examination_array[$i][0], $examination_array[$i][0],
$examination_array[$i][1], $examination_array[$i][1],
$examination_array[$i][2], $examination_array[$i][2],
$examination_array[$i][3], $examination_array[$i][3],
$examination_array[$i][4], $examination_array[$i][4],
$examination_array[$i][5], $examination_array[$i][5],
$examination_array[$i][6] $examination_array[$i][6]
); );
$customer = [
'strategy_customer' => '戰略客戶',
'general_customer' => '一般客戶'
];
//作番機種($elevator_type):客梯(passenger)、貨梯(cargo)、小電梯(dumbwaiter)、平台梯(flatbase)、強驅(positive_drive)
$elevator = [
"passenger" => "客梯",
"cargo" => "貨梯",
"dumbwaiter" => "小電梯",
"flatbase" => "平台踢",
"positive_drive" => "強驅"
];
echo "獎金版本:" . $result["ver"] . "<br>"; echo "獎金版本:" . $result["ver"] . "<br>";
echo "計算結果:" . $result["result_status"] . "<br>"; echo "計算結果:" . $result["result_status"] . "<br>";
echo "參數說明: " . $customer[$examination_array[$i][1]] . " 、 " . $elevator[$examination_array[$i][2]] . "、 作番表價:" . $examination_array[$i][3] . " 、 作番賣價: " . $examination_array[$i][4] . "、 營業員員工號:" . $examination_array[$i][5] . " 、 區域經理員工號:" . $examination_array[$i][6] . "<br>";
echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " " echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " "
. $examination_array[$i][5] . " " . $examination_array[$i][6] . "<br>"; . $examination_array[$i][5] . " " . $examination_array[$i][6] . "<br>";
for($j = 0; $j<count($result["bonus_array"]); $j++){ for ($j = 0; $j < count($result["bonus_array"]); $j++) {
echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " " echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " "
. $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["payment_schedul_due"] . " " . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["payment_schedul_due"] . " "
. $result["bonus_array"][$j]["payment_schedul_regulation"] . "<br>"; . $result["bonus_array"][$j]["payment_schedul_regulation"] . "<br>";
}; };
echo "-------------------------" . "<br>"; echo "-------------------------" . "<br>";
}; };
?>

99
wms/bonus/bonus.php → wms/bonus/maintainance_bonus.php

@ -32,15 +32,18 @@ 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 AND a.contract_type = 3";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
$datas = $stmt->fetchAll(PDO::FETCH_ASSOC); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
@ -49,7 +52,6 @@ $datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
$now = new DateTime(); $now = new DateTime();
$oneMonthAgo = $now->modify('+1 month'); $oneMonthAgo = $now->modify('+1 month');
$id = []; $id = [];
foreach ($datas as $data) { foreach ($datas as $data) {
$id[] = $data['id']; $id[] = $data['id'];
@ -58,58 +60,6 @@ $id_str = implode(',', $id);
// 查看 T8 是否有收款明細 // 查看 T8 是否有收款明細
// require("./api/get.php"); // require("./api/get.php");
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';
}
}
?> ?>
<link rel="stylesheet" href="../contract-repair/styles/style.css"> <link rel="stylesheet" href="../contract-repair/styles/style.css">
<link rel="stylesheet" href="../contract-repair/semantic/dist/semantic.min.css"> <link rel="stylesheet" href="../contract-repair/semantic/dist/semantic.min.css">
@ -122,6 +72,16 @@ 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> -->
@ -130,17 +90,19 @@ 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_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%"> <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') { ?> <?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 } ?> <?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 +140,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>
@ -323,13 +285,14 @@ function isPay($contract_no, $connT8)
const datas = <?php echo json_encode($datas); ?>; const datas = <?php echo json_encode($datas); ?>;
function issue(id, user_id, pay_day, amount) { function issue(id, user_id, pay_day, amount) {
// console.log(id); // consolelog(id);
const form = new FormData(); const form = new FormData();
form.append('id', id) form.append('id', id)
form.append('user_id', user_id); form.append('user_id', user_id);
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', 'maintainance');
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('更新成功');
@ -357,6 +320,22 @@ function isPay($contract_no, $connT8)
}); });
} }
} }
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() { // $(function() {
// $("button[name=issuePay]").click(function() { // $("button[name=issuePay]").click(function() {
// console.log(123); // console.log(123);

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

400
wms/bonus/new_bonus.php

@ -0,0 +1,400 @@
<?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 = 1 ORDER BY a.id DESC";
$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");
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';
}
}
?>
<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/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/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/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/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_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%">
<?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>
<?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) :
$bonus_json = json_decode($data['bonus_json']);
$bonus_kind = !empty($bonus_json->bonus_kind) ? $bonus_json->bonus_kind : '';
$contract_no = $data['contract_no'];
$json = json_decode($data['bonus_json']);
$total = empty($json->total) ? 0 : $json->total;
$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><?php echo $bonus_type[$data['bonus_type']] . '-' . $bonus_kind ?></td>
<td><?= $data['bonus_verson'] ?></td>
<td><?= $fee_per_st ?></td>
<td><?= $total ?></td>
<td><?= $commission_fee ?></td>
<td><?= $data['receiver'] ?></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) {
// console.log(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', 'new');
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() {
// $("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>

77
wms/bonus/other/maintenance_contract_bonus_v2_1.php

@ -43,9 +43,12 @@ 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;
#契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue)
switch ($contract_type) { switch ($contract_type) {
case "new": case "new":
@ -54,49 +57,49 @@ function maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period,
switch ($discount) { switch ($discount) {
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 >= 3000 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 >= 3000 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 >= 3000 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;
@ -110,17 +113,17 @@ 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 >= 3000 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)
@ -131,17 +134,17 @@ 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 >= 3000 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 +229,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 +252,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) {

8
wms/bonus/other/maintenance_contract_bonus_v2_1_examination.php

@ -270,9 +270,9 @@ $examination_array = [
// echo '10、專任契約經理員工號($regular_contract_manger_id)</br>'; // echo '10、專任契約經理員工號($regular_contract_manger_id)</br>';
for ($i = 0; $i < count($examination_array); $i++) { for ($i = 0; $i < count($examination_array); $i++) {
$fee_per_st = $examination_array[$i][3]; $fee_per_st = $examination_array[$i][4]; //作番金額
$commission_fee = $examination_array[$i][5]; $commission_fee = $examination_array[$i][5]; // 服務費
$elevator_list_price = $examination_array[$i][4]; $elevator_list_price = $examination_array[$i][3]; // 牌價
$discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2); $discount = round(($fee_per_st - $commission_fee) / $elevator_list_price, 2);
// echo "$fee_per_st - $commission_fee / $elevator_list_price "; // echo "$fee_per_st - $commission_fee / $elevator_list_price ";
@ -314,7 +314,7 @@ for ($i = 0; $i < count($examination_array); $i++) {
]; ];
echo "獎金版本:" . $result["ver"] . "<br>"; echo "獎金版本:" . $result["ver"] . "<br>";
echo "計算結果:" . $result["result_status"] . "<br>"; echo "計算結果:" . $result["result_status"] . "<br>";
echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$examination_array[$i][2]] . "、牌價" . $examination_array[$i][3] . "元、簽約價" . $examination_array[$i][4] . "元、服務費600元(折扣率" . $discount . ")、契約人員 : " . $examination_array[$i][7] . "、區經理 : " . $examination_array[$i][8] . " 、契約經理 : " . $examination_array[$i][9] . "<br>"; echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$examination_array[$i][2]] . "、牌價" . $examination_array[$i][3] . "元、簽約價" . $examination_array[$i][4] . "元、服務費" . $commission_fee . "元(折扣率" . $discount . ")、契約人員 : " . $examination_array[$i][7] . "、區經理 : " . $examination_array[$i][8] . " 、契約經理 : " . $examination_array[$i][9] . "<br>";
echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " " echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " "
. $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7] . " " . $examination_array[$i][8] . " " . $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7] . " " . $examination_array[$i][8] . " "
. $examination_array[$i][9] . "<br>"; . $examination_array[$i][9] . "<br>";

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;
}; };
?>

311
wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php

@ -0,0 +1,311 @@
<?php
/* 函數用法與參數
【1.輸入參數:】
獎金版本($ver):2.1
契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge)
作番契約金額($fee_per_st):3000元/月以下、3001-3499元/月、3500-3999元/月、4000元/月以上
牌價($elevator_list_price):該電梯的合約發佈(標準)價+Option價格+與其他電梯共同分擔的費用貨價格
該作番所佔的服務費金額($commission_fee)
合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) ; 契約折扣率=(簽約價格-服務費)/牌價
總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期,
付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually)
第一筆保養款項應收回日($receivable_date_due, array)
契約員員工號($sales_id)
地區處長員工號($region_director_id)
專任契約經理員工號($regular_contract_manger_id)
【2.函數中的變數說明】
契約員獎金($sales_bonus)
地區處長獎金($region_director_bonus)
專任契約經理獎金($regular_contract_manger_bonus)
獎金預計發放比例($payment_ratio_due_array)
當次應發獎金($current_bonus)
獎金預計發放日($payday_due_array)
獎金預計發放規定($payday_due_regulation):合約簽回及保養款項收回的次月一次性發
計算結果($result_status):success, error
獎金水庫(bonus_array)[
bonus_type:獎金名稱,
bonus_receiver:發放人員,
bonus_amount:金額,
pay_day_due:預計發放時間
bonus_regulation, 發放規定
]
【3.輸出數據】
result_array[
"ver"=>$ver, #獎金版本
"result_status"=>"success", #計算結果
"$bonus_array"=>$bonus_array #所有獎金水庫
];
*/
function maintenance_longterm_contract_m1_free_charge_bonus_v2_1($ver, $contract_type, $payment_period, $payment_period_amount, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id = '')
{
$bonus_array = [];
if ($ver == "2.1") {
$discount = ($fee_per_st - $commission_fee) / $elevator_list_price;
#契約總類($contract_type):簽長約並免費送M1 (longcontract_m1_free_charge)
switch ($contract_type) {
case "longcontract_m1_free_charge":
#契約員獎金($sales_bonus)
#合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59)
switch ($discount) {
case ($discount >= 0.8):
switch ($fee_per_st) {
case ($fee_per_st < 3000):
$sales_bonus = ($fee_per_st) * 0.6;
break;
case ($fee_per_st >= 3000 and $fee_per_st < 4000):
$sales_bonus = ($fee_per_st) * 0.7;
break;
case ($fee_per_st >= 4000 and $fee_per_st < 5000):
$sales_bonus = ($fee_per_st) * 0.8;
break;
case ($fee_per_st >= 5000 and $fee_per_st < 6000):
$sales_bonus = ($fee_per_st) * 0.9;
break;
case ($fee_per_st >= 6000):
$sales_bonus = ($fee_per_st) * 1.0;
break;
};
break;
case ($discount >= 0.6 and $discount < 0.8):
switch ($fee_per_st) {
case ($fee_per_st < 3000):
$sales_bonus = ($fee_per_st) * 0.42;
break;
case ($fee_per_st >= 3000 and $fee_per_st <= 4000):
$sales_bonus = ($fee_per_st) * 0.49;
break;
case ($fee_per_st >= 4000 and $fee_per_st < 5000):
$sales_bonus = ($fee_per_st) * 0.56;
break;
case ($fee_per_st >= 5000 and $fee_per_st < 6000):
$sales_bonus = ($fee_per_st) * 0.63;
break;
case ($fee_per_st >= 6000):
$sales_bonus = ($fee_per_st) * 0.7;
break;
};
break;
case ($discount < 0.6):
switch ($fee_per_st) {
case ($fee_per_st < 3000):
$sales_bonus = ($fee_per_st) * 0.3;
break;
case ($fee_per_st >= 3000 and $fee_per_st < 4000):
$sales_bonus = ($fee_per_st) * 0.35;
break;
case ($fee_per_st >= 4000 and $fee_per_st < 5000):
$sales_bonus = ($fee_per_st) * 0.4;
break;
case ($fee_per_st >= 5000 and $fee_per_st < 6000):
$sales_bonus = ($fee_per_st) * 0.45;
break;
case ($fee_per_st >= 6000):
$sales_bonus = ($fee_per_st) * 0.5;
break;
};
break;
};
#地區處長獎金($region_director_bonus)
$region_director_bonus = 170;
#專任契約經理獎金($regular_contract_manger_bonus)
$regular_contract_manger_bonus = 300;
break;
};
#付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually)
array_push($bonus_array, [
"bonus_type" => "2", #獎金名稱
"bonus_receiver" => $region_director_id, #發放人員
"bonus_amount" => round($region_director_bonus), #金額
"pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +12 months")), #預計發放時間
"bonus_regulation" => "訂金收回後次月發放" #發放規定
]);
#專任契約經理獎金
if ($regular_contract_manger_id != '') {
array_push($bonus_array, [
"bonus_type" => "3", #獎金名稱
"bonus_receiver" => $regular_contract_manger_id, #發放人員
"bonus_amount" => round($regular_contract_manger_bonus), #金額
"pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +12 months")), #預計發放時間
"bonus_regulation" => "訂金收回後次月發放" #發放規定
]);
}
#地區處長獎金、專任契約經理、契約員獎金
switch ($payment_period) {
#簽長約免費贈送控制系統,因屬於公司特殊政策,所以無汰改獎金,合約期內每月領取契約獎金
#總支付期數$payment_period_amount: 總支付期數,依規定5年約至少60期,
#年繳
case 'annually':
$payment_ratio_due_array = array();
$a = $payment_period_amount / 12;
for ($i = 0; $i < $a; $i++) {
array_push($payment_ratio_due_array, 1 / $a);
}
$payday_due_array = array();
for ($i = 0; $i < $a; $i++) {
array_push($payday_due_array, $i + 1);
}
for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
if ($i < count($payment_ratio_due_array) - 1) {
$current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額
} else {
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
"bonus_type" => "1", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($current_bonus), #金額
"pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] year")), #預計發放時間
"bonus_regulation" => "每次收款後,按收款比率次月發放" #發放規定
]);
}
break;
#半年繳
case 'semiannually':
$payment_ratio_due_array = array();
$a = $payment_period_amount / 6;
for ($i = 0; $i < $a; $i++) {
array_push($payment_ratio_due_array, 1 / $a);
}
$payday_due_array = array();
for ($i = 0; $i < $a; $i++) {
array_push($payday_due_array, ($i + 1) * 6);
}
for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
if ($i < count($payment_ratio_due_array) - 1) {
$current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額
} else {
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
"bonus_type" => "1", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($current_bonus), #金額
"pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間
"bonus_regulation" => "每次收款後,按收款比率次月發放" #發放規定
]);
}
break;
#季繳
case 'quarterly':
$a = $payment_period_amount / 3;
$payment_ratio_due_array = array();
for ($i = 0; $i < $a; $i++) {
array_push($payment_ratio_due_array, 1 / $a);
}
$payday_due_array = array();
for ($i = 0; $i < $a; $i++) {
array_push($payday_due_array, ($i + 1) * 4);
}
for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
if ($i < count($payment_ratio_due_array) - 1) {
$current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額
} else {
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
"bonus_type" => "1", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($current_bonus), #金額
"pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間
"bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定
]);
}
break;
#雙月繳
case 'bimonthly':
$a = $payment_period_amount / 2;
$payment_ratio_due_array = array();
for ($i = 0; $i < $a; $i++) {
array_push($payment_ratio_due_array, 1 / $a);
}
$payday_due_array = array();
for ($i = 0; $i < $a; $i++) {
array_push($payday_due_array, ($i + 1) * 2);
}
for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
if ($i < count($payment_ratio_due_array) - 1) {
$current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額
} else {
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
"bonus_type" => "1", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($current_bonus), #金額
"pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間
"bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定
]);
}
break;
break;
#月繳
case 'monthly':
#產生契約員每個月的獎金應發比例
$payment_ratio_due_array = array();
for ($i = 0; $i < $payment_period_amount; $i++) {
array_push($payment_ratio_due_array, 1 / $payment_period_amount);
}
$payday_due_array = array();
for ($i = 0; $i < $payment_period_amount; $i++) {
array_push($payday_due_array, $i + 1);
}
for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
if ($i < count($payment_ratio_due_array) - 1) {
$current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額
} else {
$current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
};
array_push($bonus_array, [
"bonus_type" => "1", #獎金名稱
"bonus_receiver" => $sales_id, #發放人員
"bonus_amount" => round($current_bonus), #金額
"pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] months")), #預計發放時間
"bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定
]);
}
break;
}
$result_array = [
"ver" => $ver, #獎金版本
"result_status" => "success", #計算結果
"bonus_array" => $bonus_array #獎金水庫
];
} else {
array_push($bonus_array, [
"bonus_type" => "error", #獎金名稱
"bonus_receiver" => "error", #發放人員
"bonus_amount" => 0, #金額
"pay_day_due" => "9999-1-1", #預計發放時間
"bonus_regulation" => "error" #發放規定
]);
$result_array = [
"ver" => $ver, #獎金版本
"result_status" => "error", #計算結果
"bonus_array" => $bonus_array #獎金水庫
];
}
return $result_array;
};

174
wms/bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_examination.php

@ -40,62 +40,150 @@ result_array[
*/ */
require_once("maintenance_longterm_contract_m1_free_charge_bonus_v2_1.php"); require_once("maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php");
#$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
#獎金測試 #獎金測試
$examination_array = [ $examination_array = [
#錯誤版本 #錯誤版本
["1.0","longcontract_m1_free_charge",60,0.8,4000,333, "2014-07-01", "M0001", "M0002", "M0003"], // ["1.0", 'annually', "longcontract_m1_free_charge", 60, 0.8, 4000, 333, "2014-07-01", "M0001", "M0002", "M0003"],
#60期 #60期
["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8) //付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually)
["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8) ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 600, "2014-07-01", "M0001", "M0002"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8)
["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8) ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8)
["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8) ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8)
["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8) ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8)
["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6) ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8)
["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6) ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8)
["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6) ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 1200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6)
["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6) ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 2200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6)
["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6) ["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 3200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6)
["2.1","longcontract_m1_free_charge",60,3000,3000,600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59) ["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 4200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6)
["2.1","longcontract_m1_free_charge",60,3000,4000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59) ["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 5200, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6)
["2.1","longcontract_m1_free_charge",60,3000,5000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59) ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 2999, 1230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59)
["2.1","longcontract_m1_free_charge",60,3000,6000,1600,"2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59) ["2.1", "longcontract_m1_free_charge", 'annually', 60, 3000, 3000, 1230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59)
["2.1","longcontract_m1_free_charge",60,3000,7000,1600,"2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59) ["2.1", "longcontract_m1_free_charge", 'semiannually', 60, 3000, 4000, 2230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59)
["2.1", "longcontract_m1_free_charge", 'quarterly', 60, 3000, 5000, 3230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59)
["2.1", "longcontract_m1_free_charge", 'bimonthly', 60, 3000, 6000, 4230, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59)
["2.1", "longcontract_m1_free_charge", 'monthly', 60, 3000, 7000, 5230, "2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費600元(折扣率0.8)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費1600元(折扣率0.8)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費2600元(折扣率0.8)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費3600元(折扣率0.8)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費4600元(折扣率0.8)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1200元(折扣率0.6)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2200元(折扣率0.6)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3200元(折扣率0.6)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4200元(折扣率0.6)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價7000元、服務費5200元(折扣率0.6)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 3000, 600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價3000元、服務費1230元(折扣率0.59)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 4000, 1600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價4000元、服務費2230元(折扣率0.59)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 5000, 2600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價5000元、服務費3230元(折扣率0.59)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 6000, 3600, "2014-07-01", "M0001", "M0002", "M0003"], #牌價3000、簽約價6000元、服務費4230元(折扣率0.59)
// ["2.1", "longcontract_m1_free_charge", '', 60, 3000, 7000, 4600, "2014-07-01", "M0001", "M0002", "M0003"] #牌價3000、簽約價7000元、服務費5230元(折扣率0.59)
]; ];
for($i = 0; $i<count($examination_array); $i++){ for ($i = 0; $i < count($examination_array); $i++) {
$ver = $examination_array[$i][0];
$contract_type = $examination_array[$i][1];
$payment_period = $examination_array[$i][2];
$payment_period_amount = $examination_array[$i][3];
$elevator_list_price = $examination_array[$i][4];
$fee_per_st = $examination_array[$i][5];
$commission_fee = $examination_array[$i][6];
$receivable_date_due = $examination_array[$i][7];
$sales_id = $examination_array[$i][8];
$region_director_id = $examination_array[$i][9];
$regular_contract_manger_id = empty($examination_array[$i][10]) ? '' : $examination_array[$i][10];
$a = $payment_period_amount / 12;
$sales_bonus = ($fee_per_st) * 0.6;
$bonus_array = [];
// $payment_ratio_due_array = array();
// for ($i = 0; $i < $a; $i++) {
// array_push($payment_ratio_due_array, 1 / $a);
// }
// $payday_due_array = array();
// for ($i = 0; $i < $a; $i++) {
// array_push($payday_due_array, $i + 1);
// }
// for ($i = 0; $i < count($payment_ratio_due_array); $i++) {
// if ($i < count($payment_ratio_due_array) - 1) {
// $current_bonus = round($sales_bonus * $payment_ratio_due_array[$i]); #金額
// } else {
// $current_bonus = round($sales_bonus - $i * round($sales_bonus * $payment_ratio_due_array[$i])); #最後一次金額
// };
// array_push($bonus_array, [
// "bonus_type" => "契約員獎金", #獎金名稱
// "bonus_receiver" => $sales_id, #發放人員
// "bonus_amount" => round($current_bonus), #金額
// "pay_day_due" => date("Y-m-d", strtotime("$receivable_date_due +$payday_due_array[$i] year")), #預計發放時間
// "bonus_regulation" => "每月收款後,按收款比率次月發放" #發放規定
// ]);
// }
// echo '<pre>';
// print_r($bonus_array);
// echo '</pre>';
// exit();
$result = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( $result = maintenance_longterm_contract_m1_free_charge_bonus_v2_1(
$examination_array[$i][0], $ver,
$examination_array[$i][1], $contract_type,
$examination_array[$i][2], $payment_period,
$examination_array[$i][3], $payment_period_amount,
$examination_array[$i][4], $elevator_list_price,
$examination_array[$i][5], $fee_per_st,
$examination_array[$i][6], $commission_fee,
$examination_array[$i][7], $receivable_date_due,
$examination_array[$i][8], $sales_id,
$examination_array[$i][9] $region_director_id,
$regular_contract_manger_id
); );
$discount = (($fee_per_st - $commission_fee) / $elevator_list_price);
#新簽約、月繳、牌價3000、簽約價3000元、服務費600元(折扣率0.8)
$contract_type = [
'new' => '新簽約',
'free_to_charge' => '免保轉有費',
'renew_priceissue' => '續簽約(原價或僅契約金額異動)',
'longcontract_m1_free_charge' => '五年長約'
];
// 付款方式$payment_period: 每月支付(monthly), 2月1次(bimonthly), 季付(quarterly), 半年付(semiannually), 年付(annually)
$pay_kind = [
'monthly' => '月繳',
'bimonthly' => '雙月繳',
'quarterly' => '季繳',
'semiannually' => '半年繳',
'annually' => '年繳'
];
//
$bonus_type = [
'1' => '契約員獎金',
'2' => '區經理獎金',
'3' => '契約經理獎金'
];
echo "獎金版本:" . $result["ver"] . "<br>"; echo "獎金版本:" . $result["ver"] . "<br>";
echo "計算結果:" . $result["result_status"] . "<br>"; echo "計算結果:" . $result["result_status"] . "<br>";
echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " "
. $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7]. " " . $examination_array[$i][8] . " " echo "傳入參數說明:" . $contract_type[$examination_array[$i][1]] . "、" . $pay_kind[$payment_period] . "、牌價" . $elevator_list_price . "元、簽約價" . $fee_per_st . "元、服務費" . $commission_fee . "元(折扣率" . $discount . ")、契約人員 : " . $sales_id .
. $examination_array[$i][9] . "<br>"; "、區經理 : " . $region_director_id . " 、契約經理 : " . $regular_contract_manger_id . "<br>";
for($j = 0; $j<count($result["bonus_array"]); $j++){ echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][4] . " "
. $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7] . " " . $examination_array[$i][8] . " "
. $examination_array[$i][9] . "<br>";
$n = 0;
for ($j = 0; $j < count($result["bonus_array"]); $j++) {
if ($result["bonus_array"][$j]["bonus_receiver"] == "M0001") {
$n++;
echo '[' . $n . ']';
}
echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " " echo "輸出結果:" . $result["bonus_array"][$j]["bonus_type"] . " " . $result["bonus_array"][$j]["bonus_receiver"] . " "
. $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["pay_day_due"] . " " . $result["bonus_array"][$j]["bonus_amount"] . " " . $result["bonus_array"][$j]["pay_day_due"] . " "
. $result["bonus_array"][$j]["bonus_regulation"] . "<br>"; . $result["bonus_array"][$j]["bonus_regulation"] . "<br>";
}; };
echo "-------------------------" . "<br>"; echo "-------------------------" . "<br>";
}; };
?>

12
wms/contract/api/T8salIncomeApply.php → wms/contract/api/T8api.php

@ -1,14 +1,14 @@
<?php <?php
require_once("../../T8_Authorization_from_bpm.php"); require_once("../../T8_Authorization_from_bpm.php");
function T8API($data) function T8salIncomeApply($data, $api_url)
{ {
$api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; // $api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData';
$validation = get_Auth(); $validation = get_Auth();
echo '<pre>'; // echo '<pre>';
print_r(json_encode($data)); // print_r(json_encode($data, JSON_UNESCAPED_UNICODE));
echo '</pre>'; // echo '</pre>';
$header = [ $header = [
"CHI_Authorization :" . $validation, "CHI_Authorization :" . $validation,
"GroupId:TEST" "GroupId:TEST"
@ -19,7 +19,7 @@ function T8API($data)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1); // 使用 POST curl_setopt($ch, CURLOPT_POST, 1); // 使用 POST
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
$response = curl_exec($ch); $response = curl_exec($ch);
if ($response === false) { if ($response === false) {

146
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,28 +71,152 @@ 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) { $contract_elevator_qty = 0;
$sql = "SELECT * FROM pricereview_pay WHERE mid = :mid";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':mid', $mid);
$stmt->execute();
$pay_amount = $stmt->fetchAll(PDO::FETCH_ASSOC);
$pay_arr = [
'equipment_total' => 0, //設備款
'install_total' => 0, //安裝款
'elevotor_pay_detail' => []
];
$elevotor_pay_detail = [];
foreach ($pay_amount as $i => $pay) {
if ($pay['pay_kind'] <= 4) {
// 設備款總價
$pay_arr['equipment_total'] += $pay['pay_amount'];
if ($pay['pay_scale'] > 0) {
$elevotor_pay_detail = [
'kind' => $pay['pay_kind'],
'pay_scale' => $pay['pay_scale'],
'pay_period' => $pay['pay_period'],
'amount' => $pay['pay_amount']
];
// $elevotor_pay_detail['pay_scale'] = $pay['pay_scale'];
// $pay_arr['elevotor_pay_detail']['kind'] = $pay['pay_kind'];
// $pay_arr['elevotor_pay_detail']['pay_scale'] = $pay['pay_scale'];
// $pay_arr['elevotor_pay_detail']['pay_period'] = $pay['pay_period'];
// $pay_arr['elevotor_pay_detail']['amount'] = $pay['pay_amount'];
array_push($pay_arr['elevotor_pay_detail'], $elevotor_pay_detail);
}
} else {
$pay_arr['install_total'] += $pay['pay_amount'];
if ($pay['pay_scale'] > 0) {
$a = $pay['pay_kind'];
$elevotor_pay_detail = [
'kind' => "$a",
'pay_scale' => $pay['pay_scale'],
'pay_period' => $pay['pay_period'],
'amount' => $pay['pay_amount']
];
array_push($pay_arr['elevotor_pay_detail'], $elevotor_pay_detail);
// $elevotor_pay_detail[] = $pay['pay_kind'];
// $pay_arr['elevotor_pay_detail']['kind'] = $pay['pay_kind'];
// $pay_arr['elevotor_pay_detail']['pay_scale'] = $pay['pay_scale'];
// $pay_arr['elevotor_pay_detail']['pay_period'] = $pay['pay_period'];
// $pay_arr['elevotor_pay_detail']['amount'] = $pay['pay_amount'];
}
}
}
// echo "<pre>";
// print_r($pay_arr);
// echo "</pre>";
foreach ($elevators_results as $keys) {
$contract_elevator_qty += $keys['item_qty'];
}
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;
// echo "<pre>";
// print_r($option_arr);
// echo "</pre>";
if (!empty($option_results)) {
$result['option_price'] = 0;
// 電梯 OPTION 價格分別加到各台電梯
foreach ($option_results as $key => $option) {
if ($option['item_qty'] == $result['item_qty']) {
$result['option_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_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_price'] += $option['item_unit_price'] * intval($option['item_qty']);
// 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']);
} 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;
} else {
$result['option_other_price'] += $option['item_unit_price'] * intval($option['item_qty']);
}
}
}
$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);
} }
} }
$count = COUNT($elevators_detail_arr);
$contract['elevators'] = $results; $count = COUNT($elevators_detail_arr);
$contract['elevators'] = $elevators_results;
$contract['elevators_detail_arr'] = $elevators_detail_arr; $contract['elevators_detail_arr'] = $elevators_detail_arr;
$contract['pay_arr'] = $pay_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');

236
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,14 +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);
bonusCreate($_POST, $facilityno, $conn); /// 獎金計算
$aaa = bonusCreate($_POST, $facilityno, $conn);
if ($aaa['status'] == 2) {
header("HTTP/1.1 422 Unprocessable Entity");
echo $aaa['data'];
exit();
}
//create account table //create account table
$accounttype = "A"; $accounttype = "A";
$accountid = $vat; $accountid = $vat;
@ -112,8 +119,6 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$create_at = date('Y-m-d H:i:s'); $create_at = date('Y-m-d H:i:s');
$conn->beginTransaction(); $conn->beginTransaction();
// bonusCreate($_POST, $facilityno, $conn);
// exit();
$sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)"; $sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)";
$stmt = $conn->prepare($sql_str); $stmt = $conn->prepare($sql_str);
@ -370,7 +375,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
// T8insert($_POST, $facilityno); // T8insert($_POST, $facilityno);
// header('Content-Type: application/json'); header('Content-Type: application/json');
$jsonData = json_encode($files); $jsonData = json_encode($files);
$conn->commit(); $conn->commit();
@ -386,7 +391,7 @@ function T8insert($data, $facilityno, $depId)
{ {
require_once("../connt8.php"); require_once("../connt8.php");
// 引入 T8 API 連線 // 引入 T8 API 連線
require_once("./T8salIncomeApply.php"); require_once("./T8api.php");
$contractno = !empty($data['contractno']) ? $data['contractno'] : null; // 合約號 $contractno = !empty($data['contractno']) ? $data['contractno'] : null; // 合約號
$address = !empty($data['address']) ? $data['address'] : null; // 客戶地址 $address = !empty($data['address']) ? $data['address'] : null; // 客戶地址
@ -564,23 +569,45 @@ function T8insert($data, $facilityno, $depId)
// 分期代碼計算 // 分期代碼計算
$IncomeId = [ $IncomeId = [
'A40006' => 1, //年繳 'A40006' => 12, //年繳
'A40007' => 4, //季繳 'A40007' => 3, //季繳
'A40003' => 12, //月繳 'A40003' => 1, //月繳
'A40004' => 6, //雙月繳 'A40004' => 2, //雙月繳
'A40005' => 2 //半年繳 'A40005' => 6 //半年繳
]; ];
//分幾期 => 總共保養月 / 分期月 // 幾年
$SQuantity = $elevator['maintain_months'] / $IncomeId[$payType]; // $SQuantityYear = $elevator['maintain_months'] / 12;
//分幾期 () => 總共保養月 / 分期月
$SQuantitya = $elevator['maintain_months'] / $IncomeId[$payType];
$SQuantity = $IncomeId[$payType];
// $paymonth = $IncomeId[$payType] * $SQuantity;
$date_1 = getNext25thDate($contract_begin_date); $date_1 = getNext25thDate($contract_begin_date);
// 依每台電梯去加入各個的付款項 // 依每台電梯去加入各個的付款項
for ($i = 0; $i < $IncomeId[$payType]; $i++) { for ($i = 1; $i <= $SQuantitya; $i++) {
$row++; $row++;
// 計算分期款的收款月份 // 計算分期款的收款月份
$paymonth = $i * $SQuantity; $paymonth = $i * $IncomeId[$payType];
// switch($IncomeId[$payType]):
// case (1):
// $paymonth = $i * $IncomeId[$payType];
// $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth years"));
// break;
// case (2):
// $paymonth = $i * $IncomeId[$payType];
// $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months"));
// break;
// case (12):
// $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months"));
// break;
// case (6):
// $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months"));
// break;
// case (2):
// $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months"));
// break;
$countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months")); $countDay = date('Y-m-d', strtotime("$date_1 + $paymonth months"));
$payDay = str_replace('-', '', $countDay); $payDay = str_replace('-', '', $countDay);
$rows_data = [ $rows_data = [
@ -593,13 +620,11 @@ function T8insert($data, $facilityno, $depId)
"SPrice" => intval($elevator['sold_price']), "SPrice" => intval($elevator['sold_price']),
"SQuantity" => $SQuantity, "SQuantity" => $SQuantity,
"ProjectId" => "$contractno", "ProjectId" => "$contractno",
"FromBillNo" => "$contractno",
"CU_MaterialId" => "$facility_no", "CU_MaterialId" => "$facility_no",
"CU_EstPayDate" => intval($payDay) "CU_EstPayDate" => intval($payDay)
]; ];
$salIncomeApplyDetail_rows[] = $rows_data; $salIncomeApplyDetail_rows[] = $rows_data;
// echo '<pre>';
// print_r($salIncomeApplyDetail_rows);
// echo '</pre>';
} }
} }
@ -644,7 +669,8 @@ function T8insert($data, $facilityno, $depId)
// echo '<pre>'; // echo '<pre>';
// print_r($API_body); // print_r($API_body);
// echo '</pre>'; // echo '</pre>';
$result = T8API($API_body); $api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData';
$result = T8salIncomeApply($API_body, $api_url);
if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') { if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') {
@ -658,14 +684,17 @@ function bonusCreate($data, $facilityno, $conn)
{ {
try { try {
require_once("../../bonus/other/maintenance_contract_bonus_v2_1.php"); require_once("../../bonus/other/maintenance_contract_bonus_v2_1.php");
require_once("../../bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php");
$elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : [];
$contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : ''; $contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : '';
$salesman = !empty($data['salesman']) ? $data['salesman'] : ''; $salesman = !empty($data['salesman']) ? $data['salesman'] : '';
$payType = !empty($data['payType']) ? $data['payType'] : ''; $payType = !empty($data['payType']) ? $data['payType'] : '';
$contract_type = $data['contract_type']; //合約類別
$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;
@ -677,26 +706,115 @@ function bonusCreate($data, $facilityno, $conn)
'A40003' => 'monthly' //月繳 'A40003' => 'monthly' //月繳
]; ];
$fail_arr = [];
$payDay = getNext25thDate($contract_begin_date); $payDay = getNext25thDate($contract_begin_date);
foreach ($elevators as $key => $elevator) { foreach ($elevators as $key => $elevator) {
// print_r($payDay);
// echo '<pre>';
// print_r($elevator);
// echo '</pre>';
// exit;
$facility_no = $facilityno[$key]; $facility_no = $facilityno[$key];
$ver = $elevator['bonus_verson']; //獎金版本 $ver = $elevator['bonus_verson']; //獎金版本
$contract_type = $elevator['contract_type']; //合約類別
$payment_period = $payment[$payType]; //付款方式 $payment_period = $payment[$payType]; //付款方式
$elevator_list_price = intval($elevator['stand_price']); //牌價 $elevator_list_price = !empty(intval($elevator['stand_price'])) ? intval($elevator['stand_price']) : ''; //牌價
$fee_per_st = $elevator['contract_price']; //作翻契約金額 $fee_per_st = !empty($elevator['sold_price']) ? intval(round($elevator['sold_price'] / 1.05, 2)) : ''; //作翻契約金額 (不含稅)
$commission_fee = $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; //營業人員
$discount = $elevator['discount']; $discount = $elevator['discount'];
$region_director_id = $elevator['manager']; $region_director_id = $elevator['manager'];
$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'] : '';
$results = maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id); $maintain_months = intval($elevator['maintain_months']);
$years = $maintain_months / 12;
echo $years;
if ($maintain_months == '') $fail_arr[] = "保養月費為必填";
if ($fee_per_st == '') $fail_arr[] = "契約金額為必填";
if ($elevator_list_price == '') $fail_arr[] = "牌價為必填";
if ($region_director_id == '') $fail_arr[] = '區處長為必填';
if ($sales_id == '') $fail_arr[] = "契約人為必填";
if (COUNT($fail_arr) > 0) {
return $fail_arr;
break;
}
$renew_priceissue_bonus = [];
// $years = ($maintain_months % 12) == 0 ? $maintain_months / 12 : '';
// 如果保養合約 大於一年
if (!empty($maintain_months)) {
if ($maintain_months > 12 && $contract_type == 'new') {
// 第一年為 "新簽約"
$results = maintenance_contract_bonus_v2_1(
$ver,
$contract_type,
$payment_period,
$elevator_list_price,
$fee_per_st,
$commission_fee,
$receivable_date_due,
$sales_id,
$region_director_id,
$regular_contract_manger_id
);
for ($i = 1; $i <= $years - 1; $i++) {
$contract_type = 'renew_priceissue';
$receivable_date_due_renew = date("Y-m-d", strtotime("$receivable_date_due + $i year"));
// 第二年以上改 "續約"
$renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1(
$ver,
$contract_type,
$payment_period,
$elevator_list_price,
$fee_per_st,
$commission_fee,
$receivable_date_due_renew,
$sales_id,
$region_director_id,
$regular_contract_manger_id
);
}
} else if ($maintain_months > 12 && $contract_type == 'renew_priceissue') {
// 超過一年的 "續約"
for ($i = 0; $i < $years; $i++) {
$contract_type = 'renew_priceissue';
$renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1(
$ver,
$contract_type,
$payment_period,
$elevator_list_price,
$fee_per_st,
$commission_fee,
$receivable_date_due,
$sales_id,
$region_director_id,
$regular_contract_manger_id
);
}
} else if ($maintain_months >= 60 && $contract_type = 'longcontract_m1_free_charge') {
// 五年以上長約
$results = maintenance_longterm_contract_m1_free_charge_bonus_v2_1(
$ver,
$contract_type,
$payment_period,
$maintain_months,
$elevator_list_price,
$fee_per_st,
$commission_fee,
$receivable_date_due,
$sales_id,
$region_director_id,
$regular_contract_manger_id
);
} else {
$results = maintenance_contract_bonus_v2_1(
$ver,
$contract_type,
$payment_period,
$elevator_list_price,
$fee_per_st,
$commission_fee,
$receivable_date_due,
$sales_id,
$region_director_id,
$regular_contract_manger_id
);
}
}
$bonus_json = [ $bonus_json = [
'contract_type' => $contract_type, 'contract_type' => $contract_type,
@ -707,22 +825,54 @@ function bonusCreate($data, $facilityno, $conn)
'receivable_date_due' => $receivable_date_due, 'receivable_date_due' => $receivable_date_due,
'discount' => $discount 'discount' => $discount
]; ];
if ($results['result_status'] != 'error') { if (!empty($results)) {
foreach ($results['bonus_array'] as $i => $result) {
if ($results['result_status'] != 'error') {
$bonus_type = $result['bonus_type']; foreach ($results['bonus_array'] as $i => $result) {
$pay_day = $result['pay_day_due'];
$amount = $result['bonus_amount']; $bonus_type = $result['bonus_type'];
$receiver = $result['bonus_receiver']; $pay_day = $result['pay_day_due'];
$a = json_encode($bonus_json); $amount = $result['bonus_amount'];
$sql = "INSERT INTO bonus $receiver = $result['bonus_receiver'];
$a = json_encode($bonus_json);
$sql = "INSERT INTO bonus
(bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,pay_day_due,status,bonus_json,create_id,create_at) VALUES (bonus_type,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();
}
}
if (!empty($renew_priceissue_bonus)) {
// echo '1';
foreach ($renew_priceissue_bonus as $renew_priceissue_bonus) {
foreach ($renew_priceissue_bonus['bonus_array'] as $i => $result) {
$bonus_type = $result['bonus_type'];
$pay_day = $result['pay_day_due'];
$amount = $result['bonus_amount'];
$receiver = $result['bonus_receiver'];
$a = json_encode($bonus_json);
$sql = "INSERT INTO bonus
(bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,pay_day_due,status,bonus_json,create_id,create_at) VALUES
($bonus_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$receiver','$pay_day',$status,'$a','$create_id','$create_at')";
$stmt = $conn->prepare($sql);
$stmt->execute();
}
}
} }
$request = [
"status" => "1",
"data" => "Success"
];
} else {
$request = [
"status" => "2",
"data" => "create_bonus_error"
];
} }
// exit();
} }
return $request;
// exit(); // exit();
} catch (PDOException $e) { } catch (PDOException $e) {
http_response_code(404); http_response_code(404);

781
wms/contract/api/postNewContractData.php

@ -1,10 +1,16 @@
<meta charset="UTF-8">
<?php <?php
// header("Content-Type: text/html; charset=utf-8");
// echo '你好';
// exit;
require_once("../conn.php"); require_once("../conn.php");
// include_once("../../fun_global.php");
include_once("./getFacilityNo.php"); include_once("./getFacilityNo.php");
include_once("./getComboNo.php"); include_once("./getComboNo.php");
include_once("./upload_chk.php"); include_once("./upload_chk.php");
ini_set('date.timezone', 'Asia/Taipei'); ini_set('date.timezone', 'Asia/Taipei');
if ($_SERVER['REQUEST_METHOD'] != 'POST') { if ($_SERVER['REQUEST_METHOD'] != 'POST') {
exit(); exit();
} }
@ -25,41 +31,41 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
$qc = $_POST["qc"]; $qc = $_POST["qc"];
$contracttype = $_POST["contracttype"]; $contracttype = $_POST["contracttype"];
$elevators_nums = $_POST['nums']; $elevators_nums = $_POST['nums'];
$elevators = json_decode($_POST['elevators'], true); $area_no = $_POST['area_no'];
$elevators_detail_arr = json_decode($_POST['elevators_detail_arr'], true); $elevators = json_decode($_POST['elevators'], JSON_UNESCAPED_UNICODE);
BounsCount($_POST, $conn); $elevators_detail_arr = json_decode($_POST['elevators_detail_arr'], JSON_UNESCAPED_UNICODE);
// echo '<pre>'; // echo "<pre>";
// print_r($elevators); // print_r($elevators_detail_arr);
// echo '</pre>'; // echo "</pre>";
// exit; // exit();
$files = !empty($_FILES['files']) ? $_FILES['files'] : null; $files = !empty($_FILES['files']) ? $_FILES['files'] : null;
$files_id = null; $files_id = null;
$fail_arr = []; $fail_arr = [];
if (empty($contractno)) $fail_arr[] = '合約號為必填'; // if (empty($contractno)) $fail_arr[] = '合約號為必填';
if (empty($customer)) $fail_arr[] = '客戶名稱為必填'; // if (empty($customer)) $fail_arr[] = '客戶名稱為必填';
if (empty($manager)) $fail_arr[] = '負責人為必填'; // if (empty($manager)) $fail_arr[] = '負責人為必填';
if (empty($vat)) $fail_arr[] = '統編/身分證為必填'; // if (empty($vat)) $fail_arr[] = '統編/身分證為必填';
if (empty($case_name)) $fail_arr[] = '案名為必填'; // if (empty($case_name)) $fail_arr[] = '案名為必填';
if (empty($linkman)) $fail_arr[] = '聯絡人為必填'; // if (empty($linkman)) $fail_arr[] = '聯絡人為必填';
if (empty($lm_tel)) $fail_arr[] = '聯絡人電話為必填'; // if (empty($lm_tel)) $fail_arr[] = '聯絡人電話為必填';
if (empty($address)) $fail_arr[] = '地址為必填'; // if (empty($address)) $fail_arr[] = '地址為必填';
if (empty($salesman)) $fail_arr[] = '營業員為必填'; // if (empty($salesman)) $fail_arr[] = '營業員為必填';
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
$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,12 +74,133 @@ 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>'; echo json_encode($facilityno);
print_r($facilityno);
echo '</pre>'; $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();
}
T8Insert($_POST, $facilityno, $connT8);
exit(); exit();
$conn->beginTransaction(); $conn->beginTransaction();
//create account table
$accounttype = "A";
$accountid = $vat;
$pwd = "123";
$name = $customer;
$tel = $lm_tel ?? '';
$sql = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, creater, create_at)
VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address , :creater, :created_at)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':accounttype', $accounttype);
$stmt->bindParam(':accountid', $contractno);
$stmt->bindParam(':pwd', $pwd);
$stmt->bindParam(':name', $customer);
$stmt->bindParam(':tel', $tel);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':creater', $created_by);
$stmt->bindParam(':created_at', $created_at);
$stmt->execute();
// exit();
//create table Wipwholestatus (作番大日程)
foreach ($elevators_detail_arr as $key => $value) {
$facilityno = $facilityno[$key]; // 作番
$weight = $value['item_weight']; // 載重
$person = $value['person']; // 人乘
$floor = $value['floor']; // 樓層
$open = $value['item_op']; // 開門方式
$speed = $value['speed']; //速度
$qc = $value['qc'];
$facility_kind = $value['spec']; //型號
$contract_arrival_date = $value['contract_arrival_date']; //到工地日期
$site_manager = $value['manage'];
$warehouseid = $value['warehouseid'];
$sql = "INSERT INTO Wipwholestatus
(contract_type,contractno,salesid,custom,accountid,site_manager,warehouseid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,area_no,address,contract_arrival_date,real_contract_arrival_date,qc_official_type,creater,create_at) VALUES
('A',:contractno,:salesid,:custom,:accountid,:site_manager,:warehouseid,:facilityno,:weight,:numberofpassenger,:numberoffloor,:opentype,:speed,:facility_kind,:area_no,:address,:contract_arrival_date,:real_contract_arrival_date,:qc_official_type,:creater,:create_at)";
// $sql = "INSERT INTO Wipwholestatus
// (contract_type,contractno,salesid,custom,accountid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,address,contract_arrival_date,qc_official_type,creater,create_at) VALUES
// ('A','$contractno','$salesman','$customer','$customer','$facilityno','$weight','$person','$floor','$open','$speed','$facility_kind','$address','$contract_arrival_date','$qc','$created_by','$created_at')";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':contractno', $contractno);
$stmt->bindParam(':salesid', $salesman);
$stmt->bindParam(':custom', $customer);
$stmt->bindParam(':accountid', $customer);
$stmt->bindParam(':site_manager', $site_manager);
$stmt->bindParam(':warehouseid', $warehouseid);
$stmt->bindParam(':facilityno', $facilityno);
$stmt->bindParam(':weight', $weight);
$stmt->bindParam(':numberofpassenger', $person);
$stmt->bindParam(':numberoffloor', $floor);
$stmt->bindParam(':opentype', $open);
$stmt->bindParam(':speed', $speed);
$stmt->bindParam(':facility_kind', $facility_kind);
$stmt->bindParam(':area_no', $area_no);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':contract_arrival_date', $contract_arrival_date);
$stmt->bindParam(':real_contract_arrival_date', $contract_arrival_date);
$stmt->bindParam(':qc_official_type', $qc);
$stmt->bindParam(':creater', $created_by);
$stmt->bindParam(':create_at', $created_at);
$stmt->execute();
$lastId = $conn->lastInsertId();
// echo "<pre>";
// print_r($lastId);
// echo "</pre>";
if (!empty($lastId)) {
echo '123';
// 寫入待簽程狀態 A (營業)
do_wws_assign1($salesman, $lastId, 'A', $conn);
// // 寫入待簽程狀態 G (工務)
do_wws_assign1($warehouseid, $lastId, 'G', $conn);
}
// create table worksite (戰情室)
$latitude = $value['latitude'];
$longitude = $value['longitude'];
$sql = "INSERT INTO worksite
(latitude,longitude,facilitynum,facilityno,address,buildcompany,process,status,marchintotime,creater,create_at)VALUES
(:latitude,:longitude,'1',:facilityno,:address,:bulidcompany,'進行中','未工勘',:marchintotime,:creater,:create_at)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':latitude', $latitude);
$stmt->bindParam(':longitude', $longitude);
$stmt->bindParam(':facilityno', $facilityno);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':bulidcompany', $customer);
$stmt->bindParam(':marchintotime', $contract_arrival_date);
$stmt->bindParam(':creater', $created_by);
$stmt->bindParam(':create_at', $created_at);
$stmt->execute();
// create table schedule
$contract_begin_date = '';
$contract_end_date = ''; // 一年
$comboNo = new CreateComboNo('em', $contract_begin_date, $contract_end_date);
$comboArr = json_decode($comboNo->getComboNo(), true);
foreach ($comboArr as $combo) {
$sql_str = 'INSERT INTO schedule (contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES (:contractno, :facilityno, :combono, :repairerid, :repairername, :duedate, :creater, :create_at)';
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':contractno', $contractno);
$stmt->bindParam(':facilityno', $facility_no);
$stmt->bindParam(':combono', $combo[0]);
$stmt->bindParam(':repairerid', $repairerid);
$stmt->bindParam(':repairername', $repairername);
$stmt->bindParam(':duedate', $combo[1]);
$stmt->bindParam(':creater', $creater);
$stmt->bindParam(':create_at', $create_at);
$result = $stmt->execute();
}
}
$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";
$stmt = $conn->prepare($sql_str); $stmt = $conn->prepare($sql_str);
$stmt->bindParam(":accountid", $salesman); $stmt->bindParam(":accountid", $salesman);
@ -166,160 +293,524 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
} }
} }
function T8Insert($data) function T8Insert($data, $facilityno, $connT8)
{ {
require_once("../connt8.php"); try {
// 引入銷售訂單 API
require_once("./T8API.php");
$contractno = $data['contractno']; $contractno = $data['contractno'];
$partyA = $data['customer']; $partyA = $data['customer'];
$phone = $data['lm_tel']; $phone = $data['lm_tel'];
$vat = $data['vat']; $vat = $data['vat'];
$partyAaddress = $data['address']; $partyAaddress = $data['address'];
$user_id = $data['user_id']; $user_id = $data['user_id'];
$salesman = $data['salesman']; $salesman = $data['salesman'];
$createAt = date("Y-m-dH-i-s"); $createAt = date("Y-m-dH-i-s");
$elevators[] = $data['elevators'];
$createTime = str_replace('-', '', $createAt);
$connT8->beginTransaction(); $elevators = !empty($data['elevators_detail_arr']) ? json_decode($data['elevators_detail_arr'], true) : []; //電梯
$pay_arr = !empty($data['pay_arr']) ? json_decode($data['pay_arr'], true) : []; //電梯
$sql = "SELECT * FROM comCustomer WHERE BizPartnerId = :BizPartnerId"; $createTime = str_replace('-', '', $createAt);
$stmt = $conn->prepare($sql); $signing_date = intval(str_replace("-", '', $data['signing_date'])); //簽訂日期
$stmt->bindParam(':BizPartnerId', $contractno); // echo
$stmt->execute(); // $pay_kind = [
$result = $stmt->fetch(PDO::FETCH_ASSOC); // '1' => '簽約',
// 新增客戶 table // '2' => '二次款',
if (empty($result)) { // '3' => '貨抵工地',
// 若 客戶資料為空,新增一筆到 comCustomer // '4' => '材料其他',
// 新增客戶資料 // '5' => '試車完工', //安裝完畢
$sql = "INSERT INTO comBusinessPartner // '6' => '交車' //交車
(BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,EMail,CreatorId,CreateTime,BizPartnerTypeId) // ];
VALUES(:BizPartnerId,:BizPartnerName,1,'TW',:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:EMail,:CreatorId,:CreateTime,'10')";
$pay_kind = [
'1' => '簽約',
'2' => '二次款',
'3' => '貨抵工地',
'4' => '材料其他',
'5' => '試車完工', //安裝完畢
'6' => '交車' //交車
];
$sql = "SELECT * FROM comCustomer
WHERE BizPartnerId = :BizPartnerId
";
$stmt = $connT8->prepare($sql); $stmt = $connT8->prepare($sql);
$stmt->bindParam(':BizPartnerId', $contractno); $stmt->bindParam(':BizPartnerId', $contractno);
$stmt->bindParam(':BizPartnerName', $partyA); //客戶名稱
$stmt->bindParam(':WorkTelNo', $phone);
$stmt->bindParam(':TaxNo', $vat);
// $stmt->bindParam(':EnterpriseName', $customer); //企業名稱
$stmt->bindParam(':ContactAddress', $partyAaddress);
$stmt->bindParam(':EMail', $email);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$sql = "INSERT INTO comCustomer // 新增客戶 table
(OrgId,BizPartnerTypeId,CurrId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime,InvoiceId) if (empty($result)) {
VALUES('1000','10','TWD',:BizPartnerId,:PersonId,:CreatorId,1,:InvoiceAddress,:CreateTime,'35')"; // 若 客戶資料為空,新增一筆到 comCustomer
$stmt = $connT8->prepare($sql); // 新增客戶資料
$sql = "INSERT INTO comBusinessPartner
(BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,CreatorId,CreateTime,BizPartnerTypeId)
VALUES(:BizPartnerId,:BizPartnerName,1,'TW',:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:CreatorId,:CreateTime,'10')";
// $sql = "INSERT INTO comBusinessPartner
// (BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,CreatorId,CreateTime,BizPartnerTypeId)
// VALUES('$contractno','$partyA',1,'TW','$phone',99999999,'$vat', '$partyA','$partyAaddress','$user_id',$createTime,'10')";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':BizPartnerId', $contractno);
$stmt->bindParam(':BizPartnerName', $partyA); //客戶名稱
$stmt->bindParam(':WorkTelNo', $phone);
$stmt->bindParam(':TaxNo', $vat);
$stmt->bindParam(':EnterpriseName', $partyA); //企業名稱
$stmt->bindParam(':ContactAddress', $partyAaddress);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
$stmt->bindParam(':BizPartnerId', $contractno);
$stmt->bindParam(':PersonId', $salesman);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':InvoiceAddress', $address);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
} else { $sql = "INSERT INTO comCustomer
// // 若客戶資料不為空,更新該客戶資訊。 (OrgId,BizPartnerTypeId,ConditionId,CurrId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime,InvoiceId)
$sql = "UPDATE comCustomer SET VALUES('1000','10','TWD','0008',:BizPartnerId,:PersonId,:CreatorId,1,:InvoiceAddress,:CreateTime,'35')";
// $sql = "INSERT INTO comCustomer
// (OrgId,BizPartnerTypeId,CurrId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime,InvoiceId)
// VALUES('1000','10','TWD','$contractno','$salesman','$user_id',1,'$partyAaddress','$createTime','35')";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':BizPartnerId', $contractno);
$stmt->bindParam(':PersonId', $salesman);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':InvoiceAddress', $partyAaddress);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
} else {
// // 若客戶資料不為空,更新該客戶資訊。
$sql = "UPDATE comCustomer SET
PersonId=:PersonId, PersonId=:PersonId,
ConditionId='0008',
InvoiceAddress=:InvoiceAddress, InvoiceAddress=:InvoiceAddress,
LastOperatorId=:LastOperatorId, LastOperatorId=:LastOperatorId,
LastOperateTime=:LastOperateTime LastOperateTime=:LastOperateTime
WHERE BizPartnerId=:BizPartnerId WHERE BizPartnerId=:BizPartnerId
"; ";
$stmt = $connT8->prepare($sql); $stmt = $connT8->prepare($sql);
$stmt->bindParam(':PersonId', $salesman); $stmt->bindParam(':PersonId', $salesman);
$stmt->bindParam(':InvoiceAddress', $address); $stmt->bindParam(':InvoiceAddress', $partyAaddress);
$stmt->bindParam(':LastOperatorId', $user_id); $stmt->bindParam(':LastOperatorId', $user_id);
$stmt->bindParam(':LastOperateTime', $createTime); $stmt->bindParam(':LastOperateTime', $createTime);
$stmt->bindParam(':BizPartnerId', $contractno); $stmt->bindParam(':BizPartnerId', $contractno);
$stmt->execute(); $stmt->execute();
$sql = "UPDATE comBusinessPartner SET $sql = "UPDATE comBusinessPartner SET
BizPartnerName=:BizPartnerName, BizPartnerName=:BizPartnerName,
WorkTelNo=:WorkTelNo, WorkTelNo=:WorkTelNo,
TaxNo=:TaxNo, TaxNo=:TaxNo,
EnterpriseName=:EnterpriseName, EnterpriseName=:EnterpriseName,
ContactAddress=:ContactAddress, ContactAddress=:ContactAddress,
EMail=:EMail,
LastOperatorId=:LastOperatorId, LastOperatorId=:LastOperatorId,
LastOperateTime=:LastOperateTime LastOperateTime=:LastOperateTime
WHERE BizPartnerId = :BizPartnerId WHERE BizPartnerId = :BizPartnerId
"; ";
$stmt = $connT8->prepare($sql); $stmt = $connT8->prepare($sql);
$stmt->bindParam(':BizPartnerName', $partyA); $stmt->bindParam(':BizPartnerName', $partyA);
$stmt->bindParam(':WorkTelNo', $phone); $stmt->bindParam(':WorkTelNo', $phone);
$stmt->bindParam(':TaxNo', $vat); $stmt->bindParam(':TaxNo', $vat);
$stmt->bindParam(':EnterpriseName', $customer); $stmt->bindParam(':EnterpriseName', $partyA);
$stmt->bindParam(':ContactAddress', $partyAaddress); $stmt->bindParam(':ContactAddress', $partyAaddress);
$stmt->bindParam(':EMail', $email); // $stmt->bindParam(':EMail', $email);
$stmt->bindParam(':LastOperatorId', $user_id); $stmt->bindParam(':LastOperatorId', $user_id);
$stmt->bindParam(':LastOperateTime', $createTime); $stmt->bindParam(':LastOperateTime', $createTime);
$stmt->bindParam(':BizPartnerId', $contractno); $stmt->bindParam(':BizPartnerId', $contractno);
$stmt->execute(); $stmt->execute();
} }
$sql = "SELECT * FROM comProject WHERE ProjectId = :ProjectId"; $sql = "SELECT * FROM comProject WHERE ProjectId = :ProjectId";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':ProjectId', $contractno);
$stmt->execute();
$resultProject = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($resultProject)) {
//新增於 comProject。合約 table
$sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,CreateTime,CreatorId,IsInUsed)
VALUES(:ProjectId,:ProjectName,'C0',:CreateTime,:CreatorId,1)";
$stmt = $connT8->prepare($sql); $stmt = $connT8->prepare($sql);
$stmt->bindParam(':ProjectId', $contractno); $stmt->bindParam(':ProjectId', $contractno);
$stmt->bindParam(':ProjectName', $customer);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->execute(); $stmt->execute();
$resultProject = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($resultProject)) {
//新增於 comProject。合約 table
$sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,CreateTime,CreatorId,IsInUsed)
VALUES(:ProjectId,:ProjectName,'C0',:CreateTime,:CreatorId,1)";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':ProjectId', $contractno);
$stmt->bindParam(':ProjectName', $partyA);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->execute();
}
$sql = "SELECT * FROM salSalesOrder WHERE BillNo = :BillNo";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':BillNo', $contractno);
$contractT8 = $stmt->fetch(PDO::FETCH_ASSOC);
if (empty($contractT8)) {
foreach ($elevators as $index => $elevator) {
$count = 1;
// 產品集成維護
$facility_no = $facilityno[$index];
$MaterialName = "$partyA($facility_no)";
$contract_arrival_a = $elevator['contract_arrival_date'];
$sql = "INSERT INTO comMaterial
(FOrgid,MaterialId,MaterialTypeId,MaterialCategoryId,CreatorId,CreateTime,IsInUsed)
VALUES ('1000',:MaterialId,'10','A',:CreatorId,:CreateTime,1)";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':MaterialId', $facility_no);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
$sql = "INSERT INTO comMaterialGroup
(MaterialTypeId,MaterialId,MaterialName,MaterialCategoryId,IsInUsed,UnitId,CreatorId,CreateTime)
VALUES ('10',:MaterialId,:MaterialName,'A',1,'SET',:CreatorId,:CreateTime)";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':MaterialId', $facility_no);
$stmt->bindParam(':MaterialName', $MaterialName);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
$sql = "INSERT INTO comMaterialPurchases
(Orgid,MaterialTypeId,MaterialId,CurrId,SUnitId,TaxId,CreatorId,CreateTime)
VALUES ('1000','10',:MaterialId,'TWD','SET','ST005',:CreatorId,:CreateTime)";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':MaterialId', $facility_no);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
$sql = "INSERT INTO plsMaterialPlanData
(PlanRangeId,MaterialId,FOrgId,MaterialTypeId,CreatorId,CreateTime,DefaultDemandOrg) VALUES
(1000,:MaterialId,1000,10,:CreatorId,:CreateTime,1000)
";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':MaterialId', $facility_no);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
$sql = "INSERT INTO comMaterialSales
(OrgId,MAterialTypeId,MaterialId,CurrId,SUnitId,SupplyOrgId,CreatorId,CreateTime,IsInUsed) VALUES
(1000,10,:MaterialId,'TWD','SET',1000,:CreatorId,:CreateTime,1)
";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':MaterialId', $facility_no);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
// 階段收款資訊
$salOrderStagePay_row = [];
$equipment_total = 0;
$install_total = 0;
$equipment_total = $pay_arr['equipment_total'];
$install_total = $pay_arr['install_total'];
$count_a = 0;
$count_month = 1;
foreach ($pay_arr['elevotor_pay_detail'] as $key => $detail) {
if ($detail['kind'] == 3) {
$PlanPayDate = $contract_arrival_a;
} else if ($detail['kind'] > 3) {
$PlanPayDate = date("Y-m-d", strtotime($contract_arrival_a . '+' . $count_month . ' month'));
$count_month++;
} else {
$PlanPayDate = $signing_date;
$count_a++;
if ($count_a == 1) {
$PlanPayDate = date("Y-m-d", strtotime($signing_date . '+' . $count_a . ' month'));
}
}
$contract_arrival_date = intval(str_replace("-", '', $PlanPayDate)); //貨到工地日
$PayStage = $pay_kind[$detail['kind']];
$PlanPercentage = intval($detail['pay_scale']) / 100;
$rows = [
"PayStage" => "$PayStage", //收款階段
"PlanPercentage" => $PlanPercentage, //計劃收款比例(%)
"PlanPayAmt" => $detail['amount'], //計劃收款金額
"PlanPayDate" => $contract_arrival_date, //計劃收款日期 1.第一筆都是簽約日
"BillNo" => "$contractno",
"RowCode" => $key + 1,
"RowNo" => $key + 1,
"UnWriteOffOAmount" => $detail['amount'] //未核銷金額
];
$salOrderStagePay_row[] = $rows;
}
// 設備
$row1 = [
"TaxId" => "ST005",
"RequirementDate" => $signing_date, //出貨日期
"ConsignmentDate" => $signing_date, //發貨日期
"BillNo" => "$contractno", //合約號
"RowCode" => $count, //全部筆數排列
"ItemType" => 1,
"MaterialId" => "A40001", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => $equipment_total, //交易價格
"CU_MaterialId" => $facility_no
];
$count++;
// 安裝
$row2 = [
"TaxId" => "ST005",
"RequirementDate" => $signing_date, //出貨日期
"ConsignmentDate" => $signing_date, //發貨日期
"BillNo" => "$contractno", //合約號
"RowCode" => $count, //全部筆數排列
"ItemType" => 1,
"MaterialId" => "A40008", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => $install_total, //交易價格
"CU_MaterialId" => $facility_no
];
$count++;
// 產品(作番)
$row3 = [
"TaxId" => "ST005",
"RequirementDate" => $signing_date, //出貨日期
"ConsignmentDate" => $signing_date, //發貨日期
"BillNo" => "$contractno", //合約號
"RowCode" => $count, //全部筆數排列
"ItemType" => 0,
"MaterialId" => "$facility_no", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => 0, //交易價格
"CU_MaterialId" => $facility_no // 歸屬作番號
];
$count++;
$SubOrder_row[] = $row1;
$SubOrder_row[] = $row2;
$SubOrder_row[] = $row3;
$count++;
}
$MainSalesOrder_row = [
"BillNo" => "$contractno", //合約單號
"BillDate" => $signing_date, //簽約日期
"TypeId" => "SO", //
"FOrgId" => "1000",
"OrgId" => "1000",
"ModeId" => "M", // T汰改 M新梯
"BizPartnerId" => "$contractno", //客戶代碼
"CurrId" => "TWD",
"CurrOAmount" => 1,
"CurrLAmount" => 1,
"PersonId" => "$salesman", //業務人員
"DueToId" => "$contractno", //債務方
"TradeConditionId" => "",
"TaxId" => "ST005",
"CreditorCompId" => "1001",
"CreditorOrgId" => "1000",
"CreatorId" => "$user_id"
// "CompId" => "1001",
// "CreditorCurrOAmount" => 1,
// "CreditorCurrLAmount" => 1
];
$MainSalesOrder = [
"name" => "MainSalesOrder",
'rows' => [$MainSalesOrder_row]
];
$SubOrder = [
"name" => "SubOrder",
"rows" => $SubOrder_row
];
$salOrderStagePay = [
"name" => "salOrderStagePay",
"rows" => $salOrderStagePay_row
];
$API_body = [];
$API_body[] = $MainSalesOrder;
$API_body[] = $SubOrder;
$API_body[] = $salOrderStagePay;
echo "<pre>";
print_r(json_encode($API_body, JSON_UNESCAPED_UNICODE));
echo "</pre>";
$api_url = "https://erp.masada.com.tw:780/twWebAPI/V1/SALSALESORDER/PostERPData";
$result = T8salIncomeApply($API_body, $api_url);
// echo "<pre>";
// print_r($result);
// echo "</pre>";
if ($result['Status'] == 'Fails' || $result['Status'] == 'Error') {
echo $result['ErrorMsg'];
}
} else {
echo '資料已新增過,請洽資訊人員';
}
$connT8->commit();
} catch (PDOException $e) {
$connT8->rollback();
header("HTTP/1.1 500 Internal Server Error");
die('Error!:' . $e->getMessage());
} }
} }
function BounsCount($data, $conn) function BounsCount($data, $conn, $facilityno)
{ {
// echo '<pre>';
// print_r($data);
// echo '</pre>';
// exit;
require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php");
$signing_date = $data['signing_date'];
$bonus_v1_0_date = '2024-01-02';
$bonus_v2_0_date = '2024-01-03';
$contractType = [
'1' => 'strategy_customer',
'2' => 'general_customer'
];
$contract_type = $data['contract_type'];
$type = $contractType[$contract_type]; //戰略客戶 or 一般客戶
$elevator_knockdown_price = $data['price_total']; //受價總額
$salesman = $data['salesman'];
$manager = $data['manager'];
$result_bonus = [];
if ($signing_date <= $bonus_v1_0_date) {
$ver = '1.0';
$result_bonus = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager);
} else if ($signing_date >= $bonus_v2_0_date) {
$ver = '2.0';
// $result_bonus = elevator_new_deal_bonus_v2_0($ver,$contract_type,);
}
echo '<pre>';
print_r($result_bonus);
echo '</pre>';
exit();
try { try {
require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php");
$dailyNecessities = [
'MAE100' => 'passenger', //小機房
'MAM200' => 'passenger', //無機房
'MAH100' => 'dumbwaiter', //小電梯
'MAQ100' => 'positive_drive', //強趨梯
'MAF100' => 'cargo', //貨梯
'MAP100' => 'flatbase', // 平台踢
];
$contractType = [
'1' => 'strategy_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'];
$total = $data['price_total'];
$type = $contractType[$contract_type]; //戰略客戶 or 一般客戶
// $elevator_knockdown_price = $data['price_total']; //受價總額
$elevators = json_decode($data['elevators_detail_arr'], true);
$contract_no = $data['contractno'];
$salesman = $data['salesman'];
$manager = $data['manager'];
$contract_kind = 1;
$create_id = $data['user_id'];
$create_at = date("Y-m-d H:i:s");
$status = 1;
$result_bonus = [];
$result_bonus_arr = [];
if ($signing_date <= $bonus_v1_0_date) {
$ver = '1.0';
foreach ($elevators as $key => $elevator) {
$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);
$facility_no = $facilityno[$key];
$bonus_json = [
'contract_type' => $type,
'total' => $elevator_list_price,
'fee_per_st' => $elevator_knockdown_price
];
if (!empty($result_bonus)) {
if ($result_bonus['result_status'] != "error") {
foreach ($result_bonus['bonus_array'] as $i => $result) {
$bonus_type = explode('-', $result['bonus_type']);
$pay_man_type = $bonus_type[0]; //發放類別
$bonus_kind = $bonus_type[1];
$amount = $result['bonus_amount']; //獎金水庫
$bonus_receiver = $result['bonus_receiver']; //發放人員
$bonus_json['payment_schedul_due'] = $result['payment_schedul_due'];
$bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation'];
$bonus_json['bonus_kind'] = $bonus_kind;
$a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE);
$sql = "INSERT INTO bonus
(bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES
($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at')
";
$stmt = $conn->prepare($sql);
$stmt->execute();
}
$request = [
"status" => "1",
"data" => "Success"
];
return $request;
}
$request = [
"status" => "2",
"data" => "create_bonus_error"
];
return $request;
}
}
} else if ($signing_date >= $bonus_v2_0_date) {
$ver = '2.0';
foreach ($elevators as $key => $elevator) {
$option_other_price = !empty($elevator['option_other_price']) ? intval($elevator['option_other_price']) : 0;
$elevator_type = $dailyNecessities[$elevator['spec']];
$elevator_list_price = $option_other_price + $elevator['option_price'] + $elevator['elevator_price'];
$elevator_knockdown_price = $elevator['elevator_price'];
$commission_fee = $elevator['commission_fee'];
$result_bonus = elevator_new_deal_bonus_v2_0(
$ver,
$type,
$elevator_type,
$elevator_list_price,
$elevator_knockdown_price,
$salesman,
$manager
);
// echo '<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();
}
}
$request = [
"status" => "1",
"data" => "Success"
];
} else {
$request = [
"status" => "2",
"data" => "create_bonus_error"
];
}
}
}
return $request;
} catch (PDOException $e) { } catch (PDOException $e) {
header("HTTP/1.1 500 Internal Server Error"); header("HTTP/1.1 500 Internal Server Error");
die('Error!:' . $e->getMessage()); die('Error!:' . $e->getMessage());
} }
} }
function do_wws_assign1($user_id, $form_id, $flow_code, $conn)
{
$tds = date("Y-m-d H:i:s");
$sql = "select appwms.nextval('form_key') form_key";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$form_key = $result['form_key'];
$sql = "INSERT INTO flow (system_id, flow_id, form_key, form_id,flow_code) VALUES ('wws', 'wws01', '$form_key', '$form_id','$flow_code');";
$stmt = $conn->prepare($sql);
$stmt->execute();
$sql = "INSERT INTO subflow (form_key, seq, current_assigner, create_date) VALUES ('$form_key', '1', '$user_id', '$tds');";
$stmt = $conn->prepare($sql);
$stmt->execute();
}

398
wms/contract/api/test copy.json

@ -0,0 +1,398 @@
[
{
"name": "MainSalesOrder",
"rows": [
{
"BillNo": "M23110121",
"BillDate": 20240313,
"TypeId": "SO",
"FOrgId": "1000",
"OrgId": "1000",
"ModeId": "M",
"BizPartnerId": "M23110121",
"CurrId": "TWD",
"CurrOAmount": 1,
"CurrLAmount": 1,
"PersonId": "M0042",
"DueToId": "M23110121",
"TradeConditionId": "",
"TaxId": "ST005",
"CreditorCompId": "1001",
"CreditorOrgId": "1000",
"CreatorId": "M0225"
}
]
},
{
"name": "SubOrder",
"rows": [
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 1,
"ItemType": 1,
"MaterialId": "A40001",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 3904000,
"CU_MaterialId": "4MH00836"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"ItemType": 1,
"MaterialId": "A40008",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 976000,
"CU_MaterialId": "4MH00836"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 3,
"ItemType": 0,
"MaterialId": "4MH00836",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 0,
"CU_MaterialId": "4MH00836"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 1,
"ItemType": 1,
"MaterialId": "A40001",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 3904000,
"CU_MaterialId": "4MH00837"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"ItemType": 1,
"MaterialId": "A40008",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 976000,
"CU_MaterialId": "4MH00837"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 3,
"ItemType": 0,
"MaterialId": "4MH00837",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 0,
"CU_MaterialId": "4MH00837"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 1,
"ItemType": 1,
"MaterialId": "A40001",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 3904000,
"CU_MaterialId": "4MH00838"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"ItemType": 1,
"MaterialId": "A40008",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 976000,
"CU_MaterialId": "4MH00838"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 3,
"ItemType": 0,
"MaterialId": "4MH00838",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 0,
"CU_MaterialId": "4MH00838"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 1,
"ItemType": 1,
"MaterialId": "A40001",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 3904000,
"CU_MaterialId": "4MH00839"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"ItemType": 1,
"MaterialId": "A40008",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 976000,
"CU_MaterialId": "4MH00839"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 3,
"ItemType": 0,
"MaterialId": "4MH00839",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 0,
"CU_MaterialId": "4MH00839"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 1,
"ItemType": 1,
"MaterialId": "A40001",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 3904000,
"CU_MaterialId": "4MH00840"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"ItemType": 1,
"MaterialId": "A40008",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 976000,
"CU_MaterialId": "4MH00840"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 3,
"ItemType": 0,
"MaterialId": "4MH00840",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 0,
"CU_MaterialId": "4MH00840"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 1,
"ItemType": 1,
"MaterialId": "A40001",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 3904000,
"CU_MaterialId": "4MH00841"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"ItemType": 1,
"MaterialId": "A40008",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 976000,
"CU_MaterialId": "4MH00841"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 3,
"ItemType": 0,
"MaterialId": "4MH00841",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 0,
"CU_MaterialId": "4MH00841"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 1,
"ItemType": 1,
"MaterialId": "A40001",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 3904000,
"CU_MaterialId": "4MH00842"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"ItemType": 1,
"MaterialId": "A40008",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 976000,
"CU_MaterialId": "4MH00842"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 3,
"ItemType": 0,
"MaterialId": "4MH00842",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 0,
"CU_MaterialId": "4MH00842"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 1,
"ItemType": 1,
"MaterialId": "A40001",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 3904000,
"CU_MaterialId": "4MH00843"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"ItemType": 1,
"MaterialId": "A40008",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 976000,
"CU_MaterialId": "4MH00843"
},
{
"TaxId": "ST005",
"RequirementDate": 20240313,
"ConsignmentDate": 20240313,
"BillNo": "M23110121",
"RowCode": 3,
"ItemType": 0,
"MaterialId": "4MH00843",
"SUnitId": "SET",
"SQuantity": 1,
"SPrice": 0,
"CU_MaterialId": "4MH00843"
}
]
},
{
"name": "salOrderStagePay",
"rows": [
{
"PayStage": "簽約",
"PlanPercentage": 0.2,
"PlanPayAmt": 976000,
"PlanPayDate": 20240413,
"BillNo": "M23110121",
"RowCode": 1,
"RowNo": 1,
"UnWriteOffOAmount": 976000
},
{
"PayStage": "二次款",
"PlanPercentage": 0.4,
"PlanPayAmt": 1952000,
"PlanPayDate": 20240313,
"BillNo": "M23110121",
"RowCode": 2,
"RowNo": 2,
"UnWriteOffOAmount": 1952000
},
{
"PayStage": "貨抵工地",
"PlanPercentage": 0.2,
"PlanPayAmt": 976000,
"PlanPayDate": 20241104,
"BillNo": "M23110121",
"RowCode": 3,
"RowNo": 3,
"UnWriteOffOAmount": 976000
},
{
"PayStage": "試車完工",
"PlanPercentage": 0.1,
"PlanPayAmt": 488000,
"PlanPayDate": 20241204,
"BillNo": "M23110121",
"RowCode": 4,
"RowNo": 4,
"UnWriteOffOAmount": 488000
},
{
"PayStage": "交車",
"PlanPercentage": 0.1,
"PlanPayAmt": 488000,
"PlanPayDate": 20250104,
"BillNo": "M23110121",
"RowCode": 5,
"RowNo": 5,
"UnWriteOffOAmount": 488000
}
]
}
]

211
wms/contract/api/test.json

@ -1,185 +1,66 @@
[ [
{ {
"name": "salIncomeApplyMaster", //salSalesOrder
"name": "MainSalesOrder",
"rows": [ "rows": [
{ {
"BillNo": "B23100060", "BillNo": "Z001", //
"BillDate": "20240122", "BillDate": 20210420, //
"OrgId": "1000", "TypeId": "SO", //
"FOrgId": "1000", "FOrgId": "1000",
"TypeId": "RAS", "OrgId": "1000",
"BpOrgId": "1000", "ModeId": "T", // T M
"BizPartnerId": "B23100060", "BizPartnerId": "M0225", //ID
"CurrId": "TWD", "CurrId": "TWD",
"CurrOAmount": 1, "CurrOAmount": 1,
"CurrLAmount": 1, "CurrLAmount": 1,
"PersonId": "M0065", "PersonId": "M0225", //
"DtOrgId": "1000", "DueToId": "512", //
"DueToId": "B23100060", "TradeConditionId": "",
"TaxId": "ST005", "TaxId": "ST005",
"CompId": "1001", "CreditorCompId": "1000",
"CreatorId": "M0225" "CreditorOrgId": "1000",
"CreditorCurrOAmount": 1,
"CreditorCurrLAmount": 1,
"CompId": "1000"
} }
] ]
}, },
{ {
"name": "salIncomeApplyDetail", // salSalesOrderDetail
"name": "SubOrder",
"rows": [ "rows": [
{ {
"BillNo": "B23100060", "SupplyCompId": "1001",
"IncomeId": "A40003", "SupplyOrgId": "1000",
"TaxId": "ST005",
"RowCode": 1,
"RowNo": 1,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 2,
"RowNo": 2,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 3,
"RowNo": 3,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 4,
"RowNo": 4,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 5,
"RowNo": 5,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 6,
"RowNo": 6,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005", "TaxId": "ST005",
"RowCode": 7, "RequirementDate": 20210420, //
"RowNo": 7, "ConsignmentDate": 20210420, //
"ItemType": 1, "DispatchCompId": "1001",
"SPrice": 1250, "DispatchOrgId": "1000",
"SQuantity": 1, "BillNo": "Z001", //
"ProjectId": "B23100060", "RowCode": 1, //
"FromSourceTag": 0, "ItemType": 0,
"CU_MaterialId": "4TH53801" "MaterialId": "Z001", //
}, "SUnitId": "SET",
{ "SQuantity": 1, //
"BillNo": "B23100060", "SPrice": 1 //
"IncomeId": "A40003", }
"TaxId": "ST005", ]
"RowCode": 8, },
"RowNo": 8, {
"ItemType": 1, //salOrderStagePay
"SPrice": 1250, "name": "salOrderStagePay",
"SQuantity": 1, "rows": [
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 9,
"RowNo": 9,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 10,
"RowNo": 10,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 11,
"RowNo": 11,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{ {
"BillNo": "B23100060", "BillNo": "",
"IncomeId": "A40003", "RowCode": "",
"TaxId": "ST005", "RowNo": "",
"RowCode": 12, "PayStage": "ST003", //
"RowNo": 12, "PlanPercentage": "Z001", //(%)
"ItemType": 1, "PlanPayAmt": 1, //
"SPrice": 1250, "PlanPayDate": 1, // 1.
"SQuantity": 1, "UnWriteOffOAmount": 1 //
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
} }
] ]
} }

291
wms/contract/api/testT8API.php

@ -1,36 +1,257 @@
<?php <?php
?>
// {
<head> // "BillNo": "Z001", //合約單號
<title>地址轉經緯度</title> // "BillDate": 20210420, //簽約日期
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> // "TypeId": "SO", //
</head> // "FOrgId": "1000",
// "OrgId": "1000",
<body> // "ModeId": "T", // T汰改 M新梯
<h1>輸入地址以獲取經緯度</h1> // "BizPartnerId": "M0225", //創建人ID
<form id="addressForm" method="post"> // "CurrId": "TWD",
<input type="text" id="addressInput" name="address" placeholder="輸入地址"> // "CurrOAmount": 1,
<button type="submit">查詢</button> // "CurrLAmount": 1,
</form> // "PersonId": "M0225", //業務人員
<div id="map"></div> // "DueToId": "512", //業務部門
// "TradeConditionId": "",
<script> // "TaxId": "ST005",
// 使用AJAX提交表單 // "CreditorCompId": "1000",
$(document).ready(function() { // "CreditorOrgId": "1000",
$("#addressForm").submit(function(event) { // "CreditorCurrOAmount": 1,
event.preventDefault(); // "CreditorCurrLAmount": 1,
var address = $("#addressInput").val(); // "CompId": "1000"
$.ajax({ // }
url: "get_lat_lng.php", // ]
type: "POST", // },
data: { // {
address: address // //salSalesOrderDetail
}, // "name": "SubOrder",
success: function(data) { // "rows": [
$("#map").html(data); // {
} // "SupplyCompId": "1001",
}); // "SupplyOrgId": "1000",
}); // "TaxId": "ST005",
}); // "RequirementDate": 20210420, //出貨日期
</script> // "ConsignmentDate": 20210420, //發貨日期
</body> // "DispatchCompId": "1001",
// "DispatchOrgId": "1000",
// "BillNo": "Z001", //合約號
// "RowCode": 1, //全部筆數排列
// "ItemType": 0,
// "MaterialId": "Z001", //作番號
// "SUnitId": "SET",
// "SQuantity": 1, //交易數量
// "SPrice": 1 //交易價格
// }
// ]
// },
// {
// "name": "salOrderStagePay",
// "rows": [
// {
// "BillNo": "",
// "RowCode": "",
// "RowNo": "",
// "PayStage": "ST003", //收款階段
// "PlanPercentage": "Z001", //計劃收款比例(%)
// "PlanPayAmt": 1, //計劃收款金額
// "PlanPayDate": 1, //計劃收款日期 1.第一筆都是簽約日
// "UnWriteOffOAmount": 1 //未核銷金額
// }
// ]
// }
// ]
require_once("../../T8_Authorization_from_bpm.php");
$api_url = "https://erp.masada.com.tw:780/twWebAPI/V1/SALSALESORDER/PostERPData";
$validation = get_Auth();
// $header = [
// "CHI_Authorization :" . $validation,
// "GroupId:TEST"
// ];
// $url = "https://erp.masada.com.tw:780/twWebAPI/V1/GLFEEWRITEOFF/DeleteERPData?pkValue=M24020032";
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
// $response = curl_exec($ch);
// if ($response === false) {
// echo 'Curl error: ' . curl_error($ch);
// } else {
// $result = json_decode($response, true);
// // 若 API 傳入失敗。
// if ($result['Status'] == 'Erroe') {
// echo 'API傳入失敗,' . $result['ErrorMsg'];
// print_r($result);
// } else {
// // print_r($result);
// print_r($result);
// }
// print_r($result);
// }
// curl_close($ch);
// exit();
$contract_no = "M24020003";
// $contract_no = "M24010109";
$MainSalesOrder_row = [
"BillNo" => "$contract_no", //合約單號
"BillDate" => 20210420, //簽約日期
"TypeId" => "SO", //
"FOrgId" => "1000",
"OrgId" => "1000",
"ModeId" => "M", // T汰改 M新梯
"BizPartnerId" => "$contract_no", //客戶代碼
"CurrId" => "TWD",
"CurrOAmount" => 1,
"CurrLAmount" => 1,
"PersonId" => "M0177", //業務人員
"DueToId" => "$contract_no", //債務方
"TradeConditionId" => "",
"TaxId" => "ST005",
"CreditorCompId" => "1001",
"CreditorOrgId" => "1000",
"CreatorId" => "M0225"
];
// //salSalesOrderDetail
// $SubOrder_row = [];
for ($i = 0; $i < 3; $i++) {
if ($i == 0) {
$row = [
// "SupplyCompId" => "1001",
// "SupplyOrgId" => "1000",
"TaxId" => "ST005",
"RequirementDate" => 20210420, //出貨日期
"ConsignmentDate" => 20210420, //發貨日期
// "DispatchCompId" => "1001",
// "DispatchOrgId" => "1000",
"BillNo" => "$contract_no", //合約號
"RowCode" => $i, //全部筆數排列
"ItemType" => 1,
"MaterialId" => "A40001", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => 100000 //交易價格
];
}
if ($i == 1) {
$row = [
// "SupplyCompId" => "1001",
// "SupplyOrgId" => "1000",
"TaxId" => "ST005",
"RequirementDate" => 20210420, //出貨日期
"ConsignmentDate" => 20210420, //發貨日期
// "DispatchCompId" => "1001",
// "DispatchOrgId" => "1000",
"BillNo" => "$contract_no", //合約號
"RowCode" => $i, //全部筆數排列
"ItemType" => 1,
"MaterialId" => "A40008", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => 650000 //交易價格
];
}
if ($i == 2) {
$row = [
"TaxId" => "ST005",
"RequirementDate" => 20210420, //出貨日期
"ConsignmentDate" => 20210420, //發貨日期
"BillNo" => "$contract_no", //合約號
"RowCode" => $i, //全部筆數排列
"ItemType" => 0,
"MaterialId" => "4MH00669", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => 0 //交易價格
];
}
$SubOrder_row[] = $row;
}
$salOrderStagePay_row = [];
$roww = [
"PayStage" => "簽約", //收款階段
"PlanPercentage" => 0.5, //計劃收款比例(%)
"PlanPayAmt" => 375000, //計劃收款金額
"PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日
"BillNo" => "$contract_no",
"RowCode" => 1,
"RowNo" => 1,
"UnWriteOffOAmount" => 375000 //未核銷金額
];
$roww2 = [
"PayStage" => "貨抵工地",
"PlanPercentage" => 0.5,
"PlanPayAmt" => 375000,
"PlanPayDate" => 20240101,
"BillNo" => "$contract_no",
"RowCode" => 2,
"RowNo" => 2,
"UnWriteOffOAmount" => 375000
];
$salOrderStagePay_row[] = $roww;
$salOrderStagePay_row[] = $roww2;
$MainSalesOrder = [
"name" => "MainSalesOrder",
'rows' => [$MainSalesOrder_row]
];
$SubOrder = [
"name" => "SubOrder",
"rows" => $SubOrder_row
];
$salOrderStagePay = [
"name" => "salOrderStagePay",
"rows" => $salOrderStagePay_row
];
$APIbody = [];
$APIbody[] = $MainSalesOrder;
$APIbody[] = $SubOrder;
$APIbody[] = $salOrderStagePay;
// $data = file_get_contents('test copy.json');
// $arr = json_decode($data, true);
// echo "<pre>";
// print_r($data);
// echo "</pre>";
echo "<pre>";
print_r(json_encode($APIbody, JSON_UNESCAPED_UNICODE));
echo "</pre>";
// exit();
$header = [
"CHI_Authorization :" . $validation,
"GroupId:TEST"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url); // 设置请求的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1); // 使用 POST
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($APIbody, JSON_UNESCAPED_UNICODE));
$response = curl_exec($ch);
if ($response === false) {
echo 'Curl error: ' . curl_error($ch);
} else {
$result = json_decode($response, true);
// 若 API 傳入失敗。
if ($result['Status'] == 'Erroe') {
echo 'API傳入失敗,' . $result['ErrorMsg'];
print_r($result);
} else {
// print_r($result);
print_r($result);
}
print_r($result);
}
curl_close($ch);

62
wms/contract/contract-input.php

@ -57,8 +57,10 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<h4>業務確認項</h4> <h4>業務確認項</h4>
</td> </td>
<td class="text-right" style='border-left:0px;'> <td class="text-right" style='border-left:0px;'>
<button type="button" id="btn_close" class="btn btn-default" onclick="window.history.back();">返回</button> <!-- <button type="button" id="btn_close" class="btn btn-default" onclick="window.history.back();">返回</button>
<button type="button" id="btn_close" class="btn btn-default" onclick="window.close();">關閉分頁</button> <button type="button" id="btn_close" class="btn btn-default" onclick="window.close();">關閉分頁</button> -->
<!-- <button type="button" id="btn_close" class="btn btn-default" onclick="window.history.back();">返回</button>
<button type="button" id="btn_close" class="btn btn-default" onclick="window.close();">關閉分頁</button> -->
</td> </td>
</tr> </tr>
<tr> <tr>
@ -111,7 +113,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>
@ -201,7 +203,18 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<input type="file" name="file[]" multiple draggable="true" @change="uploadFiles($event)" /> <input type="file" name="file[]" multiple draggable="true" @change="uploadFiles($event)" />
</td> </td>
</tr> </tr>
<tr>
<td style="vertical-align:middle">合約類別</td>
<td>
<select name="" id="" x-model="data.contract_type">
<option value="">請選擇</option>
<option value="new">新簽約</option>
<option value="free_to_charge">免保轉有費</option>
<option value="renew_priceissue">續簽約</option>
<option value="longcontract_m1_free_charge">長約</option>
</select>
</td>
</tr>
<!-- <tr> <!-- <tr>
<td></td> <td></td>
<td></td> <td></td>
@ -363,42 +376,48 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<td> <td>
<input type="text" x-model="elevator.maintain_months"> <input type="text" x-model="elevator.maintain_months">
</td> </td>
<td style="vertical-align:middle">合約類別</td> <!-- <td style="vertical-align:middle">合約類別</td> -->
<td> <!-- <td>
<select name="" id="" x-model="elevator.contract_type"> <select name="" id="" x-model="elevator.contract_type">
<option value="">請選擇</option> <option value="">請選擇</option>
<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>
</select> </select>
</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>
<td style="vertical-align:middle">作番契約金額(月)</td>
<td><input type="text" x-model="elevator.sold_price"></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 style="vertical-align:middle">牌價(標準價)</td>
<td> <td>
<input type="text" x-model="elevator.stand_price" disabled> <input type="text" x-model="elevator.service_expense">
<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.stand_price">
<p>標準價+Option價格+與其他電梯共同分擔的費用貨價格</p>
</td> </td>
<td style="vertical-align:middle">折扣率(%)</td>
<td><input type="text" x-model='elevator.discount' disabled></td>
</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>
<!-- <td style="vertical-align:middle">折扣率(%)</td>
<td colspan="2">
<input type="text" x-model='elevator.discount'>
<p>(作番契約金額+服務費/台數) / 牌價 * 100</p>
</td> -->
</tr> </tr>
<!-- <tr>
<td style="vertical-align:middle">地區處長員工號</td>
<td><input type="text" x-model="elevator.manager"></td>
<td style="vertical-align:middle">專任契約經理員工號</td>
<td><input type="text" x-model="elevator.regular_contract_manger_id"></td>
</tr> -->
</tbody> </tbody>
</template> </template>
</template> </template>
@ -439,4 +458,5 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<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; ?>'
// console.log(123);
</script> </script>

14
wms/contract/contract-newelevator-input.php

@ -134,7 +134,17 @@ $persons = array_map(function ($person) {
</td> </td>
</tr> </tr>
<tr> <tr>
<td style="vertical-align: middle">區域</td>
<td>
<select id="area_no" name="area_no" x-model="data.area_no">
<option value="">請選擇</option>
<option value="N">北區</option>
<option value="Y">宜蘭</option>
<option value="T">桃園</option>
<option value="C">中區</option>
<option value="K">南區</option>
</select>
</td>
</tr> </tr>
</tbody> </tbody>
</template> </template>
@ -187,7 +197,7 @@ $persons = array_map(function ($person) {
<tr> <tr>
<td style="vertical-align: middle">QC和官檢</td> <td style="vertical-align: middle">QC和官檢</td>
<td> <td>
<select class="" id="qc" x-model="data.qc"> <select class="" id="qc" x-model="elevator.qc">
<option value="">請選擇QC或官檢</option> <option value="">請選擇QC或官檢</option>
<option value="Q">只需QC</option> <option value="Q">只需QC</option>
<option value="O">只需官檢</option> <option value="O">只需官檢</option>

84
wms/contract/js/alpine.js

@ -810,7 +810,7 @@ const contractNewInput = () => {
return { return {
init() { }, init() { },
data: { data: {
contractno: 'M23110004', contractno: 'M24020076',
customer: '', customer: '',
manager: '', manager: '',
vat: '', vat: '',
@ -827,7 +827,10 @@ const contractNewInput = () => {
signing_date: '', //合約簽訂日期 signing_date: '', //合約簽訂日期
elevators: [], // 電梯種類 Array elevators: [], // 電梯種類 Array
elevators_detail_arr: [], // 電梯台數 Array elevators_detail_arr: [], // 電梯台數 Array
nums: '', //電梯數量 pay_arr: [], //電梯付款種類
nums: 0, //電梯數量
area_no: 'T',
contract_arrival_date: ''
}, },
step: 1, step: 1,
isLoading: false, isLoading: false,
@ -838,6 +841,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();
@ -866,14 +870,15 @@ const contractNewInput = () => {
this.data.elevators_detail_arr[i].longitude = ''; // 緯度 this.data.elevators_detail_arr[i].longitude = ''; // 緯度
this.data.elevators_detail_arr[i].manage = ''; // 工地負責人 this.data.elevators_detail_arr[i].manage = ''; // 工地負責人
this.data.elevators_detail_arr[i].qc = ''; // QC和官檢 this.data.elevators_detail_arr[i].qc = ''; // QC和官檢
this.data.elevators_detail_arr[i].contract_arrival_date = ''; //合約交期(到工地) this.data.elevators_detail_arr[i].contract_arrival_date = this.data.contract_arrival_date; //合約交期(到工地)
// this.data.elevators_detail_arr[i].area_no = ''; //區域
} }
this.step = 3; this.step = 3;
this.isLoading = false; this.isLoading = false;
} else if (this.step == 3) { } else if (this.step == 3) {
console.log(this.data.elevators_detail_arr); console.log(this.data.elevators_detail_arr);
this.step = 4; // this.step = 4;
this.isLoading = false; // this.isLoading = false;
} }
}, },
getContractDate() { getContractDate() {
@ -887,7 +892,7 @@ const contractNewInput = () => {
return return
} }
if (!this.customize) { if (!this.customize) {
console.log(res.data); console.log(res.data.customer);
this.data.customer = res.data.company this.data.customer = res.data.company
this.data.manager = res.data.manager this.data.manager = res.data.manager
this.data.vat = res.data.uscc this.data.vat = res.data.uscc
@ -901,6 +906,8 @@ const contractNewInput = () => {
this.data.elevators = res.data.elevators; this.data.elevators = res.data.elevators;
this.data.elevators_detail_arr = res.data.elevators_detail_arr; this.data.elevators_detail_arr = res.data.elevators_detail_arr;
this.data.nums = res.data.nums; this.data.nums = res.data.nums;
this.data.pay_arr = res.data.pay_arr;
this.data.contract_arrival_date = res.data.facilitok_date;
} }
this.step = 2 this.step = 2
this.isLoading = false this.isLoading = false
@ -916,6 +923,7 @@ const contractNewInput = () => {
form.append('customer', this.data.customer); form.append('customer', this.data.customer);
form.append('manager', this.data.manager); form.append('manager', this.data.manager);
form.append('vat', this.data.vat); form.append('vat', this.data.vat);
form.append('area_no', this.data.area_no);
form.append('case_name', this.data.case_name); form.append('case_name', this.data.case_name);
form.append('linkman', this.data.linkman); form.append('linkman', this.data.linkman);
form.append('lm_tel', this.data.lm_tel); form.append('lm_tel', this.data.lm_tel);
@ -928,6 +936,7 @@ const contractNewInput = () => {
form.append('contract_type', this.data.contract_type); form.append('contract_type', this.data.contract_type);
form.append('elevators_detail_arr', JSON.stringify(this.data.elevators_detail_arr)); form.append('elevators_detail_arr', JSON.stringify(this.data.elevators_detail_arr));
form.append('elevators', JSON.stringify(this.data.elevators)); form.append('elevators', JSON.stringify(this.data.elevators));
form.append('pay_arr', JSON.stringify(this.data.pay_arr));
form.append('contracttype', 'm'); form.append('contracttype', 'm');
form.append('user_id', user_id); form.append('user_id', user_id);
for (var i = 0; i < this.data.files.length; i++) { for (var i = 0; i < this.data.files.length; i++) {
@ -1016,6 +1025,7 @@ const contractInput = () => {
disabled: false, //資料庫是否有電梯數量資料 disabled: false, //資料庫是否有電梯數量資料
elevators: [], //機種、載重、人乘、樓停、樓層、速度、緯度、經度、開門方式、保養別、廠牌、竣檢日、許可證日期 elevators: [], //機種、載重、人乘、樓停、樓層、速度、緯度、經度、開門方式、保養別、廠牌、竣檢日、許可證日期
payType: '', //付款方式 payType: '', //付款方式
contract_type: ''
// bonus_verson: 2.1, // bonus_verson: 2.1,
// manager: '', // manager: '',
// regular_contract_manger_id: '', // regular_contract_manger_id: '',
@ -1048,6 +1058,7 @@ const contractInput = () => {
data.bonus_verson = 2.1; data.bonus_verson = 2.1;
}, },
getManager() { getManager() {
for (let i = 0; i < this.data.elevators.length; i++) { for (let i = 0; i < this.data.elevators.length; i++) {
this.getBonusVerson(this.data.elevators[i]); this.getBonusVerson(this.data.elevators[i]);
axios.get('./api/getContractData.php?contracttype=accountManger&salesman=' + this.data.salesman).then(res => { axios.get('./api/getContractData.php?contracttype=accountManger&salesman=' + this.data.salesman).then(res => {
@ -1070,28 +1081,31 @@ const contractInput = () => {
} }
}, },
createElevator() { createElevator() {
for (let i = 0; i < this.data.num; i++) { if (this.data.num != this.data.elevators.length) {
this.data.elevators.push({ for (let i = 0; i < this.data.num; i++) {
spec: '', //規格 this.data.elevators.push({
weight: '', //載重 spec: '', //規格
speed: '', //速度 weight: '', //載重
persons: '', //人乘 speed: '', //速度
stop: '', //樓停 persons: '', //人乘
floors: '', //樓層 stop: '', //樓停
latitude: '', //緯度 floors: '', //樓層
longitude: '', //經度 latitude: '', //緯度
elevator_brand: '', //廠牌 longitude: '', //經度
opendoor: '', //開門方式 elevator_brand: '', //廠牌
maintainance: '', //保養別 opendoor: '', //開門方式
takecertificatedate: '', //竣檢日 maintainance: '', //保養別
useful_date: '', //許可證有效日期 takecertificatedate: '', //竣檢日
maintain_times: '', //保養頻率 useful_date: '', //許可證有效日期
discount: '', //折價率 maintain_times: '', //保養頻率
contract_type: '', discount: '', //折價率
manager: '', // contract_type: '',
regular_contract_manger_id: '', manager: '',
bonus_verson: '' regular_contract_manger_id: '',
}) bonus_verson: '',
sold_price: ''
})
}
} }
}, },
getContractDate() { getContractDate() {
@ -1101,16 +1115,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 / 12); 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
@ -1205,7 +1221,8 @@ const contractInput = () => {
form.append('num', this.data.num); form.append('num', this.data.num);
form.append('elevators', JSON.stringify(this.data.elevators)); form.append('elevators', JSON.stringify(this.data.elevators));
form.append('contracttype', 'b'); form.append('contracttype', 'b');
form.append('payType', this.data.payType) form.append('payType', this.data.payType);
form.append('contract_type', this.data.contract_type);
// 如果有附件檔案,可以逐一加入 // 如果有附件檔案,可以逐一加入
for (var i = 0; i < this.data.files.length; i++) { for (var i = 0; i < this.data.files.length; i++) {
@ -1239,7 +1256,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