10994015 1 year ago
parent
commit
cf6c136a63
  1. 130
      wms/T8_APItest.php
  2. 21
      wms/T8_Authorization.php
  3. 18
      wms/T8_Authorization_from_bpm.php
  4. 27
      wms/account-receivable-excel.php
  5. 368
      wms/account-receivable-index-ing.php
  6. 367
      wms/account-receivable-index.php
  7. 22906
      wms/account_receivable_sql_file.sql
  8. BIN
      wms/assemble_warehouse.xlsx
  9. 370
      wms/cont/sign_list.php
  10. 41
      wms/contract/api/T8salIncomeApply.php
  11. 136
      wms/contract/api/postContractData.php
  12. 186
      wms/contract/api/test.json
  13. 157
      wms/contract/api/testT8API.php
  14. 6
      wms/contract/js/alpine.js
  15. 1
      wms/frame/api_getdata.php
  16. 244
      wms/frame/pending.php
  17. 40
      wms/fun_global.php
  18. 65
      wms/mkt/pricereview-check.php
  19. 75
      wms/mkt/pricereview-index.php
  20. 59
      wms/mkt/pricereview-record-check.php
  21. 117
      wms/mkt/pricereview_mi-api.php
  22. 58
      wms/mkt/pricereview_renovate-index.php
  23. 1
      wms/schedule-index.php
  24. 43
      wms/sign/list.php

130
wms/T8_APItest.php

@ -3,70 +3,72 @@ include "T8_Authorization.php";
echo "ii";
?>
<script>
get_Auth();
window.addEventListener('message', function(event) {
if (event.origin === "http://localhost:3000" && (typeof event.data === "string")) {
// if (event.origin === "https://masada.com.tw" && (typeof event.data === "string")) {
var validation = event.data;
console.log("event");
console.log(validation);
let validation = get_Auth();
// window.addEventListener('message', function(event) {
// console.log('123')
// if (event.origin === "http://localhost:3000" && (typeof event.data === "string")) {
// if (event.origin === "https://masada.com.tw" && (typeof event.data === "string")) {
console.log(validation)
// var validation = event.data;
// console.log("event");
// console.log(validation);
// var corsurl = 'http://cors-anywhere.herokuapp.com/';
var apiurl = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData';
headerParam = {
CHI_Authorization: `${validation}`,
};
var body = [{
"name": "salIncomeApplyMaster",
"rows": [{
"BillNo": "B23100061",
"BillDate": 20231220,
"OrgId": "1000",
"FOrgId": "1000",
"TypeId": "RAS",
"BpOrgId": "1000",
"BizPartnerId": "B23100061",
"CurrId": "TWD",
"CurrOAmount": 1,
"CurrLAmount": 1,
"PersonId": "M0065",
"DtOrgId": "1000",
"DueToId": "B23100061",
"TaxId": "ST005",
"CompId": "1001"
}]
},
{
"name": "salIncomeApplyDetail",
"rows": [{
"BillNo": "B23100061",
"IncomeId": "A40004",
"TaxId": "ST005",
"RowCode": 1,
"ItemType": "1",
"SPrice": 10000,
"SQuantity": 0,
"FromSourceTag": 0,
"FromBillNo": ""
}]
}
];
var json = JSON.stringify(body);
obj = {
type: 'POST',
// url: `${corsurl}${apiurl}`,
url: `${apiurl}`,
dataType: 'json',
headers: headerParam,
data: json,
// dataType: "json",
success: function(res) {
console.log(res.Status);
console.log(res.ErrorMsg);
console.log(res.Data);
}
};
jQuery.ajax(obj);
// var corsurl = 'http://cors-anywhere.herokuapp.com/';
var apiurl = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData';
headerParam = {
CHI_Authorization: `${validation}`,
};
var body = [{
"name": "salIncomeApplyMaster",
"rows": [{
"BillNo": "B23100061",
"BillDate": 20231220,
"OrgId": "1000",
"FOrgId": "1000",
"TypeId": "RAS",
"BpOrgId": "1000",
"BizPartnerId": "B23100061",
"CurrId": "TWD",
"CurrOAmount": 1,
"CurrLAmount": 1,
"PersonId": "M0065",
"DtOrgId": "1000",
"DueToId": "B23100061",
"TaxId": "ST005",
"CompId": "1001"
}]
},
{
"name": "salIncomeApplyDetail",
"rows": [{
"BillNo": "B23100061",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 12,
"ItemType": "1",
"SPrice": 10000,
"SQuantity": 1,
"FromSourceTag": 0,
"FromBillNo": ""
}]
}
})
];
var json = JSON.stringify(body);
obj = {
type: 'POST',
// url: `${corsurl}${apiurl}`,
url: `${apiurl}`,
dataType: 'json',
headers: headerParam,
data: json,
// dataType: "json",
success: function(res) {
console.log(res.Status);
console.log(res.ErrorMsg);
console.log(res.Data);
}
};
jQuery.ajax(obj);
// }
// })
</script>

21
wms/T8_Authorization.php

@ -1,21 +1,23 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<?php
$now = gmdate("YmdHis");
$data = 'admin.' . $now;
$currentTime = time();
$twoMinutesLater = $currentTime - (2 * 60);
$now = gmdate("YmdHis", $twoMinutesLater);
$data = 'M0000.' . $now;
$sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false);
?>
<script>
function get_Auth() {
var api_key = 'B2D6395D2883E26C';
var api_key = '964C834F7BF2BB70';
var validation = "";
// var corsurl = 'http://cors-anywhere.herokuapp.com/';
// var apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
var apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'
headerParam = {
UserId: 'admin',
Pwd: 'chi',
UserId: 'M0000',
Pwd: 'M012290493119',
TimestampUTC: <?= $now ?>,
Sign: '<?= $sign ?>'
};
@ -27,12 +29,15 @@ $sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false);
headers: headerParam,
success: function(res) {
validation = res.Data['CHI_Authorization'];
console.log("validation:", validation);
window.parent.postMessage(validation, 'http://localhost:3000');
console.log(validation);
// console.log(res);
// console.log()
// window.parent.postMessage(validation,'http://localhost:3000');
// window.parent.postMessage(validation,'https://masada.com.tw');
return validation;
}
};
jQuery.ajax(obj);
// return jQuery.ajax(obj);
}
</script>

18
wms/T8_Authorization_from_bpm.php

@ -5,16 +5,18 @@ $user_password = "M012290493119";
function get_Auth($user_id = "M0000", $user_password = "M012290493119")
{
$currentTime = time();
$twoMinutesLater = $currentTime - (2 * 60);
$now = gmdate("YmdHis");
$now = gmdate("YmdHis", $twoMinutesLater);
$data = "$user_id." . $now;
$sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false);
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
// $apiurl = 'https://erp.masada.com.tw:880/twWebAPI/GetAuth';
// $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
$apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth';
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
// $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth';
$apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
$headerParam = [
"UserId: $user_id",
@ -29,15 +31,21 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119")
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerParam);
$response = curl_exec($ch);
echo $response;
if ($response === false) {
echo 'Curl error: ' . curl_error($ch);
echo '123Curl error: ' . curl_error($ch);
} else {
// print_r($response);
// exit;
$result = json_decode($response, true);
$validation = $result['Data']['CHI_Authorization'];
echo '<pre>';
print_r($result);
echo '</pre>';
return $validation;
}
curl_close($ch);
}
// $data = [];
// get_Auth();

27
wms/account-receivable-excel.php

@ -13,6 +13,7 @@ $Bill = json_decode(file_get_contents("php://input"), true);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// file_put_contents('account-receivable.txt', json_encode($Bill));
// file_put_contents('account-receivable.txt', json_encode($Bill));
if ($type == 'facility') {
$colomnHeader = [
'作番號', '合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭',
@ -24,7 +25,7 @@ if ($type == 'facility') {
'官檢款名稱', '官檢款合約金額', '官檢款應收日期', '官檢款目前應收金額', '官檢款已收金額', '官檢款催收金額', '官檢款催收次數',
'交車款名稱', '交車款合約金額', '交車款應收日期', '交車款目前應收金額', '交車款已收金額', '交車款催收金額', '交車款催收次數',
'尾款名稱', '尾款金額', '尾款應收日期', '尾款應收金額', '尾款已收金額', '尾款催收金額', '尾款催收次數',
'作番狀態', '合約-設備金額','合約-安裝金額','作番合約總金額', '作番總應收金額'
'作番狀態', '合約-設備金額', '合約-安裝金額', '作番合約總金額', '作番總應收金額'
];
$sheet->fromArray($colomnHeader, NULL, 'A1');
$rowIndex = 2;
@ -34,7 +35,7 @@ if ($type == 'facility') {
$column = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP','BQ','BR'
'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR'
];
foreach ($column as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
@ -48,26 +49,26 @@ if ($type == 'facility') {
} else {
$colomnHeader = [
'合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭',
'訂金', '訂金目前應收', '訂金已開票金額','訂金未開票金額', '訂金已收金額', '訂金催收金額', '訂金最大催收次數', '訂金最小催收次數',
'二次款', '二次款目前應收', '二次款已開票金額','二次款未開票金額', '二次款已收金額', '二次款催收金額', '二次款最大催收次數', '二次款最小催收次數',
'貨抵工地款', '貨抵工地款目前應收', '貨抵工地款已開票金額','貨抵工地款未開票金額', '貨抵工地款已收金額', '貨抵工地款催收金額', '貨抵工地款最大催收次數', '貨抵工地款最小催收次數',
'安裝款', '安裝款目前應收', '安裝款已開票金額','安裝款未開票金額', '安裝款已收金額', '安裝款催收金額', '安裝款最大催收次數', '安裝款最小催收次數',
'試車款', '試車款目前應收', '試車款已開票金額','試車款未開票金額', '試車款已收金額', '試車款催收金額', '試車款最大催收次數', '試車款最小催收次數',
'官檢款', '官檢款目前應收', '官檢款已開票金額','官檢款未開票金額', '官檢款已收金額', '官檢款催收金額', '官檢款最大催收次數', '官檢款最小催收次數',
'交車款', '交車款目前應收', '交車款已開票金額','交車款未開票金額', '交車款已收金額', '交車款催收金額', '交車款最大催收次數', '交車款最小催收次數',
'尾款', '尾款目前應收', '尾款已開票金額','尾款未開票金額', '尾款已收金額', '尾款催收金額', '尾款最大催收次數', '尾款最小催收次數',
'合約設備金額','合約安裝金額','合約總金額', '目前應收', '已開發票金額', '已收金額', '作番總數', '作番狀態'
'訂金', '訂金目前應收', '訂金已開票金額', '訂金未開票金額', '訂金已收金額', '訂金催收金額', '訂金最大催收次數', '訂金最小催收次數',
'二次款', '二次款目前應收', '二次款已開票金額', '二次款未開票金額', '二次款已收金額', '二次款催收金額', '二次款最大催收次數', '二次款最小催收次數',
'貨抵工地款', '貨抵工地款目前應收', '貨抵工地款已開票金額', '貨抵工地款未開票金額', '貨抵工地款已收金額', '貨抵工地款催收金額', '貨抵工地款最大催收次數', '貨抵工地款最小催收次數',
'安裝款', '安裝款目前應收', '安裝款已開票金額', '安裝款未開票金額', '安裝款已收金額', '安裝款催收金額', '安裝款最大催收次數', '安裝款最小催收次數',
'試車款', '試車款目前應收', '試車款已開票金額', '試車款未開票金額', '試車款已收金額', '試車款催收金額', '試車款最大催收次數', '試車款最小催收次數',
'官檢款', '官檢款目前應收', '官檢款已開票金額', '官檢款未開票金額', '官檢款已收金額', '官檢款催收金額', '官檢款最大催收次數', '官檢款最小催收次數',
'交車款', '交車款目前應收', '交車款已開票金額', '交車款未開票金額', '交車款已收金額', '交車款催收金額', '交車款最大催收次數', '交車款最小催收次數',
'尾款', '尾款目前應收', '尾款已開票金額', '尾款未開票金額', '尾款已收金額', '尾款催收金額', '尾款最大催收次數', '尾款最小催收次數',
'合約設備金額', '合約安裝金額', '合約總金額', '目前應收', '已開發票金額', '已收金額', '作番總數', '作番狀態'
];
$sheet->fromArray($colomnHeader, NULL, 'A1');
$rowIndex = 2;
foreach ($Bill as $key => $value) {
$sheet->fromArray($value, NULL, 'A' . $rowIndex);
$sheet->fromArray($value, NULL, 'A' . $rowIndex, true);
$column = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ',
'CA','CB','CC'
'CA', 'CB', 'CC'
];
foreach ($column as $col) {
if ($col == 'CB') {

368
wms/account-receivable-index-ing.php

@ -103,6 +103,7 @@ if (!(in_array(accountidToDepartId($user_id), array('220', '210')))) {
$sql_opening .= " OR person_id = '$user_id'";
$sql .= " WHERE salesid = '$user_id'";
$sql_contract_budget .= " AND (PersonId = '$user_id'";
$sql_contract_budget .= " AND (PersonId = '$user_id'";
if (count($follower) > 0) {
$column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower);
@ -112,16 +113,19 @@ if (!(in_array(accountidToDepartId($user_id), array('220', '210')))) {
$sql_opening .= " OR person_id IN $column_str)";
$sql .= " OR salesid IN $column_str ORDER BY contractno";
$sql_contract_budget .= " OR PersonId IN $column_str ORDER BY BillNo, CU_MaterialId)";
$sql_contract_budget .= " OR PersonId IN $column_str ORDER BY BillNo, CU_MaterialId)";
} else {
$sql_contract .= ")";
// $sql_received .= ")";
$sql_opening .= ")";
$sql .= " ORDER BY contractno";
$sql_contract_budget .= ")";
$sql_contract_budget .= ")";
};
} else {
$sql .= " ORDER BY contractno";
$sql_contract_budget .= "ORDER BY BillNo, CU_MaterialId";
$sql_contract_budget .= "ORDER BY BillNo, CU_MaterialId";
}
$contract = $conn->query($sql_contract);
@ -211,6 +215,7 @@ foreach ($contract as $cont) {
$arrayData[$BillNo]['facilities'] = "";
$arrayData[$BillNo]['total_facility_num'] = $arrayData[$BillNo]['delivery_num'] = $arrayData[$BillNo]['check_num'] = $arrayData[$BillNo]['tryrun_num'] = $arrayData[$BillNo]['install_num'] = $arrayData[$BillNo]['arrive_num'] = $arrayData[$BillNo]['second_num'] = $arrayData[$BillNo]['sign_num'] = $arrayData[$BillNo]['receivable_budget'] = 0;
$arrayData[$BillNo]['total_list'] = $arrayData[$BillNo]['sign_list'] = $arrayData[$BillNo]['second_list'] = $arrayData[$BillNo]['arrive_list'] = $arrayData[$BillNo]['install_list'] = $arrayData[$BillNo]['tryrun_list'] = $arrayData[$BillNo]['check_list'] = $arrayData[$BillNo]['delivery_list'] = $arrayData[$BillNo]['final_list'] = [];
$arrayData[$BillNo]['total_list'] = $arrayData[$BillNo]['sign_list'] = $arrayData[$BillNo]['second_list'] = $arrayData[$BillNo]['arrive_list'] = $arrayData[$BillNo]['install_list'] = $arrayData[$BillNo]['tryrun_list'] = $arrayData[$BillNo]['check_list'] = $arrayData[$BillNo]['delivery_list'] = $arrayData[$BillNo]['final_list'] = [];
}
if (stristr($PayStage, '二次款') || (stristr($PayStage, '出貨前') && $PayStage != "寶佳出貨前30天") || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60') || stristr($PayStage, '寶佳出貨後10天')) {
$arrayData[$BillNo]['second'][0] = $PayStage;
@ -401,6 +406,7 @@ foreach ($wipwhole_array as $wip) {
if ($arrayData[$wip['contractno']]['sign'][0] == "寶佳出貨前30天") {
$facility_status = "";
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
$today = strtotime(date('Ymd'));
$contractday = strtotime($arrayData[$wip['contractno']]['sign'][2]);
$month = collect_month($contractday);
@ -409,6 +415,7 @@ foreach ($wipwhole_array as $wip) {
if ($today > $contractday) {
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
$facility_status = $wip['facilityno'] . " (出貨前30天" . $arrayData[$wip['contractno']]['sign'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
//二次款
@ -419,6 +426,7 @@ foreach ($wipwhole_array as $wip) {
if ($today > $contractday) {
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$facility_status = $wip['facilityno'] . " (出貨後10天" . $arrayData[$wip['contractno']]['second'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
//貨抵工地款
@ -431,6 +439,7 @@ foreach ($wipwhole_array as $wip) {
if ($today > $contractday) {
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive'][2] = strval(date('Y-m-d', $contractday));
$facility_status = $wip['facilityno'] . " (貨抵工地後90天" . $arrayData[$wip['contractno']]['arrive'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
@ -444,6 +453,7 @@ foreach ($wipwhole_array as $wip) {
if ($today > $contractday) {
$arrayData[$wip['contractno']]['tryrun_num'] += 1;
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['tryrun'][2] = strval(date('Y-m-d', $contractday));
$facility_status = $wip['facilityno'] . " (試車後90天" . $arrayData[$wip['contractno']]['tryrun'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
@ -458,6 +468,8 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['delivery_num'] += 1;
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['delivery'][2] = strval(date('Y-m-d', $contractday));
$facility_status = $wip['facilityno'] . " (交車後270天" . $arrayData[$wip['contractno']]['delivery'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
@ -476,6 +488,7 @@ foreach ($wipwhole_array as $wip) {
} else {
$signtime = strtotime($arrayData[$wip['contractno']]['sign'][2]);
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
$month = collect_month($signtime);
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['sign'][6] = $month;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['sign'][2] = strval(date('Ymd', $signtime));
@ -490,14 +503,19 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) <br>";
$arrayData[$wip['contractno']]['tryrun_num'] += 1;
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['install_num'] += 1;
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if ($arrayData[$wip['contractno']]['delivery'][0] == "交車後270天") {
$estimate_delivery_time = strtotime($wip['delivery_date']);
@ -507,6 +525,8 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['delivery_num'] += 1;
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
}
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['delivery'][6] = $month;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['delivery'][2] = strval(date('Ymd', $arrivetime));
@ -518,8 +538,11 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['delivery_num'] += 1;
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['check_num'] += 1;
array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['delivery'][2] = strval($wip['delivery_date']);
$deliverytime = strtotime($wip['delivery_date']);
$month = collect_month($deliverytime);
@ -591,16 +614,22 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) <br>";
$arrayData[$wip['contractno']]['check_num'] += 1;
array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['tryrun_num'] += 1;
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['install_num'] += 1;
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if (!empty($wip['official_check_date']) && $wip['official_check_date'] != NULL) {
array_push($arrayData[$wip['contractno']]['check']['min'], strtotime(strval($wip['official_check_date'])));
array_push($arrayData[$wip['contractno']]['check']['max'], strtotime(strval($wip['official_check_date'])));
@ -678,14 +707,19 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢) <br>";
$arrayData[$wip['contractno']]['tryrun_num'] += 1;
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['install_num'] += 1;
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if (!empty($wip['tryrun_end_date']) && $wip['tryrun_end_date'] != NULL) {
array_push($arrayData[$wip['contractno']]['tryrun']['min'], strtotime(strval($wip['tryrun_end_date'])));
array_push($arrayData[$wip['contractno']]['tryrun']['max'], strtotime(strval($wip['tryrun_end_date'])));
@ -741,12 +775,16 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) <br>";
$arrayData[$wip['contractno']]['install_num'] += 1;
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) {
$installtime = strtotime($wip['install_end_date']);
$month = collect_month($installtime);
@ -794,10 +832,13 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) <br>";
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") {
$estimate_delivery_time = strtotime($wip['real_arrival_date']);
@ -827,11 +868,14 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (已達二次款收款條件) <br>";
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
} else {
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if ($wip['real_contract_arrival_date'] != NULL) {
$arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['real_contract_arrival_date'] . "預計出貨日) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['real_contract_arrival_date'] . "預計出貨日) <br>";
@ -870,6 +914,30 @@ foreach ($wipwhole_array as $wip) {
// }
// }
// foreach ($arrayData as $key => $value) {
// echo $key."<br>";
// print_r($value['total_list']);
// echo " / 總 ";
// print_r($value['sign_list']);
// echo " / 訂金 <br>";
// print_r($value['arrive_list']);
// echo " / 貨抵 ";
// print_r($value['install_list']);
// echo " / 安裝 <br>";
// print_r($value['tryrun_list']);
// echo " / 試車 ";
// print_r($value['check_list']);
// echo " / 官檢 <br>";
// print_r($value['delivery_list']);
// echo " / 移交 ";
// print_r($value['final_list']);
// echo " / 結案 <br>";
// echo "---------------------------<br>";
// foreach($value['sign_list'] as $fac){
// echo $fac."=========";
// }
// }
// 計算每個合約的應收款、作番總數
$today_date = new DateTime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m-d')))));
@ -894,6 +962,25 @@ foreach ($arrayData as &$value) {
$value['final'][3] = $value['final'][1] * $final_ratio;
$value['receivable_budget'] = $value['sign'][3] + $value['second'][3] + $value['arrive'][3] + $value['install'][3] + $value['tryrun'][3] + $value['check'][3] + $value['delivery'][3] + $value['final'][3];
}
//['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數
$sign_ratio = get_ratio($value['sign_list'], $value[10], $contract_budget);
$value['sign'][3] = $value['sign'][1] * $sign_ratio;
$second_ratio = get_ratio($value['second_list'], $value[10], $contract_budget);
$value['second'][3] = $value['second'][1] * $second_ratio;
$arrive_ratio = get_ratio($value['arrive_list'], $value[10], $contract_budget);
$value['arrive'][3] = $value['arrive'][1] * $arrive_ratio;
$install_ratio = get_ratio($value['install_list'], $value[10], $contract_budget);
$value['install'][3] = $value['install'][1] * $install_ratio;
$tryrun_ratio = get_ratio($value['tryrun_list'], $value[10], $contract_budget);
$value['tryrun'][3] = $value['tryrun'][1] * $tryrun_ratio;
$check_ratio = get_ratio($value['check_list'], $value[10], $contract_budget);
$value['check'][3] = $value['check'][1] * $check_ratio;
$delivery_ratio = get_ratio($value['delivery_list'], $value[10], $contract_budget);
$value['delivery'][3] = $value['delivery'][1] * $delivery_ratio;
$final_ratio = get_ratio($value['final_list'], $value[10], $contract_budget);
$value['final'][3] = $value['final'][1] * $final_ratio;
$value['receivable_budget'] = $value['sign'][3] + $value['second'][3] + $value['arrive'][3] + $value['install'][3] + $value['tryrun'][3] + $value['check'][3] + $value['delivery'][3] + $value['final'][3];
}
//['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數
// 計算每台作番金額與各階段應收金額
foreach ($value['facility'] as &$val) {
@ -1262,6 +1349,284 @@ foreach ($arrayData as $key => &$data) {
$data['final'][7] = 0;
}
}
//['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 4 已收金額 5 催收金額 6 已開發票金額 7 未開發票金額 min 最早應收月份 max 最晚應收月份
foreach ($arrayData as $key => &$data) {
$tmp_data = $data['received_budget'];
$tmp_invoice = $data['invoice_budget'];
if ($data['sign'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['sign'][3]) >= 0) {
$data['sign'][4] = $data['sign'][3];
$tmp_data -= $data['sign'][3];
} else {
$data['sign'][4] = $tmp_data;
$tmp_data = 0;
}
$data['sign'][5] = $data['sign'][3] - $data['sign'][4];
} else {
$data['sign'][4] = 0;
$data['sign'][5] = $data['sign'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['sign'][3]) >= 0) {
$data['sign'][6] = $data['sign'][3];
$tmp_invoice -= $data['sign'][3];
} else {
$data['sign'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['sign'][7] = $data['sign'][3] - $data['sign'][6];
} else {
$data['sign'][6] = 0;
$data['sign'][7] = $data['sign'][3];
}
} else {
$data['sign'][4] = 0;
$data['sign'][5] = 0;
$data['sign'][6] = 0;
$data['sign'][7] = 0;
}
if ($data['second'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['second'][3]) >= 0) {
$data['second'][4] = $data['second'][3];
$tmp_data -= $data['second'][3];
} else {
$data['second'][4] = $tmp_data;
$tmp_data = 0;
}
$data['second'][5] = $data['second'][3] - $data['second'][4];
} else {
$data['second'][4] = 0;
$data['second'][5] = $data['second'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['second'][3]) >= 0) {
$data['second'][6] = $data['second'][3];
$tmp_invoice -= $data['second'][3];
} else {
$data['second'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['second'][7] = $data['second'][3] - $data['second'][6];
} else {
$data['second'][6] = 0;
$data['second'][7] = $data['second'][3];
}
} else {
$data['second'][4] = 0;
$data['second'][5] = 0;
$data['second'][6] = 0;
$data['second'][7] = 0;
}
if ($data['arrive'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['arrive'][1]) >= 0) {
$data['arrive'][4] = $data['arrive'][3];
$tmp_data -= $data['arrive'][3];
} else {
$data['arrive'][4] = $tmp_data;
$tmp_data = 0;
}
$data['arrive'][5] = $data['arrive'][3] - $data['arrive'][4];
} else {
$data['arrive'][4] = 0;
$data['arrive'][5] = $data['arrive'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['arrive'][3]) >= 0) {
$data['arrive'][6] = $data['arrive'][3];
$tmp_invoice -= $data['arrive'][3];
} else {
$data['arrive'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['arrive'][7] = $data['arrive'][3] - $data['arrive'][6];
} else {
$data['arrive'][6] = 0;
$data['arrive'][7] = $data['arrive'][3];
}
} else {
$data['arrive'][4] = 0;
$data['arrive'][5] = 0;
$data['arrive'][6] = 0;
$data['arrive'][7] = 0;
}
if ($data['install'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['install'][1]) >= 0) {
$data['install'][4] = $data['install'][3];
$tmp_data -= $data['install'][3];
} else {
$data['install'][4] = $tmp_data;
$tmp_data = 0;
}
$data['install'][5] = $data['install'][3] - $data['install'][4];
} else {
$data['install'][4] = 0;
$data['install'][5] = $data['install'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['install'][3]) >= 0) {
$data['install'][6] = $data['install'][3];
$tmp_invoice -= $data['install'][3];
} else {
$data['install'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['install'][7] = $data['install'][3] - $data['install'][6];
} else {
$data['install'][6] = 0;
$data['install'][7] = $data['install'][3];
}
} else {
$data['install'][4] = 0;
$data['install'][5] = 0;
$data['install'][6] = 0;
$data['install'][7] = 0;
}
if ($data['tryrun'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['tryrun'][1]) >= 0) {
$data['tryrun'][4] = $data['tryrun'][3];
$tmp_data -= $data['tryrun'][3];
} else {
$data['tryrun'][4] = $tmp_data;
$tmp_data = 0;
}
$data['tryrun'][5] = $data['tryrun'][3] - $data['tryrun'][4];
} else {
$data['tryrun'][4] = 0;
$data['tryrun'][5] = $data['tryrun'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['tryrun'][3]) >= 0) {
$data['tryrun'][6] = $data['tryrun'][3];
$tmp_invoice -= $data['tryrun'][3];
} else {
$data['tryrun'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['tryrun'][7] = $data['tryrun'][3] - $data['tryrun'][6];
} else {
$data['tryrun'][6] = 0;
$data['tryrun'][7] = $data['tryrun'][3];
}
} else {
$data['tryrun'][4] = 0;
$data['tryrun'][5] = 0;
$data['tryrun'][6] = 0;
$data['tryrun'][7] = 0;
}
if ($data['check'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['check'][1]) >= 0) {
$data['check'][4] = $data['check'][3];
$tmp_data -= $data['check'][3];
} else {
$data['check'][4] = $tmp_data;
$tmp_data = 0;
}
$data['check'][5] = $data['check'][3] - $data['check'][4];
} else {
$data['check'][4] = 0;
$data['check'][5] = $data['check'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['check'][3]) >= 0) {
$data['check'][6] = $data['check'][3];
$tmp_invoice -= $data['check'][3];
} else {
$data['check'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['check'][7] = $data['check'][3] - $data['check'][6];
} else {
$data['check'][6] = 0;
$data['check'][7] = $data['check'][3];
}
} else {
$data['check'][4] = 0;
$data['check'][5] = 0;
$data['check'][6] = 0;
$data['check'][7] = 0;
}
if ($data['delivery'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['delivery'][1]) >= 0) {
$data['delivery'][4] = $data['delivery'][3];
$tmp_data -= $data['delivery'][3];
} else {
$data['delivery'][4] = $tmp_data;
$tmp_data = 0;
}
$data['delivery'][5] = $data['delivery'][3] - $data['delivery'][4];
} else {
$data['delivery'][4] = 0;
$data['delivery'][5] = $data['delivery'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['delivery'][3]) >= 0) {
$data['delivery'][6] = $data['delivery'][3];
$tmp_invoice -= $data['delivery'][3];
} else {
$data['delivery'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['delivery'][7] = $data['delivery'][3] - $data['delivery'][6];
} else {
$data['delivery'][6] = 0;
$data['delivery'][7] = $data['delivery'][3];
}
} else {
$data['delivery'][4] = 0;
$data['delivery'][5] = 0;
$data['delivery'][6] = 0;
$data['delivery'][7] = 0;
}
if ($data['final'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['final'][1]) >= 0) {
$data['final'][4] = $data['final'][3];
$tmp_data -= $data['final'][3];
} else {
$data['final'][4] = $tmp_data;
$tmp_data = 0;
}
$data['final'][5] = $data['final'][3] - $data['final'][4];
} else {
$data['final'][4] = 0;
$data['final'][5] = $data['final'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['final'][3]) >= 0) {
$data['final'][6] = $data['final'][3];
$tmp_invoice -= $data['final'][3];
} else {
$data['final'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['final'][7] = $data['final'][3] - $data['final'][6];
} else {
$data['final'][6] = 0;
$data['final'][7] = $data['final'][3];
}
} else {
$data['final'][4] = 0;
$data['final'][5] = 0;
$data['final'][6] = 0;
$data['final'][7] = 0;
}
}
//產生excel的array
$excel_aray = array();
@ -1289,6 +1654,8 @@ foreach ($arrayData as $key => $value) {
$value[$i]['min'] = (empty($value[$i]['min']) || is_null($value[$i]['min'])) ? 0 : $value[$i]['min'];
$value[$i][4] = (isset($value[$i][4])) ? $value[$i][4] : 0;
$value[$i][5] = (isset($value[$i][5])) ? $value[$i][5] : 0;
$value[$i][4] = (isset($value[$i][4])) ? $value[$i][4] : 0;
$value[$i][5] = (isset($value[$i][5])) ? $value[$i][5] : 0;
};
if ($value['sign'][0] == "寶佳出貨前30天") {
@ -1332,6 +1699,7 @@ foreach ($arrayData as $key => $value) {
number_format(round($value['A40001'])), number_format(round($value['A40008'])), number_format(round($value['total_budget'])), number_format(round($value['receivable_budget'])), number_format(round($value['invoice_budget'])), number_format(round($value['received_budget'])), $value['total_facility_num'], str_replace('<br>', '; ', $value['facilities'])
];
//['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 min 最早應收月份 max 最晚應收月份
//[合約號]['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數
foreach ($value['facility'] as $valkey => $val) {

367
wms/account-receivable-index.php

@ -103,6 +103,7 @@ if (!(in_array(accountidToDepartId($user_id), array('220', '210')))) {
$sql_opening .= " OR person_id = '$user_id'";
$sql .= " WHERE salesid = '$user_id'";
$sql_contract_budget .= " AND (PersonId = '$user_id'";
$sql_contract_budget .= " AND (PersonId = '$user_id'";
if (count($follower) > 0) {
$column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower);
@ -118,10 +119,13 @@ if (!(in_array(accountidToDepartId($user_id), array('220', '210')))) {
$sql_opening .= ")";
$sql .= " ORDER BY contractno";
$sql_contract_budget .= ")";
$sql_contract_budget .= ")";
};
} else {
} else {
$sql .= " ORDER BY contractno";
$sql_contract_budget .= "ORDER BY BillNo, CU_MaterialId";
$sql_contract_budget .= "ORDER BY BillNo, CU_MaterialId";
}
$contract = $conn->query($sql_contract);
@ -211,6 +215,7 @@ foreach ($contract as $cont) {
$arrayData[$BillNo]['facilities'] = "";
$arrayData[$BillNo]['total_facility_num'] = $arrayData[$BillNo]['delivery_num'] = $arrayData[$BillNo]['check_num'] = $arrayData[$BillNo]['tryrun_num'] = $arrayData[$BillNo]['install_num'] = $arrayData[$BillNo]['arrive_num'] = $arrayData[$BillNo]['second_num'] = $arrayData[$BillNo]['sign_num'] = $arrayData[$BillNo]['receivable_budget'] = 0;
$arrayData[$BillNo]['total_list'] = $arrayData[$BillNo]['sign_list'] = $arrayData[$BillNo]['second_list'] = $arrayData[$BillNo]['arrive_list'] = $arrayData[$BillNo]['install_list'] = $arrayData[$BillNo]['tryrun_list'] = $arrayData[$BillNo]['check_list'] = $arrayData[$BillNo]['delivery_list'] = $arrayData[$BillNo]['final_list'] = [];
$arrayData[$BillNo]['total_list'] = $arrayData[$BillNo]['sign_list'] = $arrayData[$BillNo]['second_list'] = $arrayData[$BillNo]['arrive_list'] = $arrayData[$BillNo]['install_list'] = $arrayData[$BillNo]['tryrun_list'] = $arrayData[$BillNo]['check_list'] = $arrayData[$BillNo]['delivery_list'] = $arrayData[$BillNo]['final_list'] = [];
}
if (stristr($PayStage, '二次款') || (stristr($PayStage, '出貨前') && $PayStage != "寶佳出貨前30天") || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60') || stristr($PayStage, '寶佳出貨後10天')) {
$arrayData[$BillNo]['second'][0] = $PayStage;
@ -401,6 +406,7 @@ foreach ($wipwhole_array as $wip) {
if ($arrayData[$wip['contractno']]['sign'][0] == "寶佳出貨前30天") {
$facility_status = "";
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
$today = strtotime(date('Ymd'));
$contractday = strtotime($arrayData[$wip['contractno']]['sign'][2]);
$month = collect_month($contractday);
@ -409,6 +415,7 @@ foreach ($wipwhole_array as $wip) {
if ($today > $contractday) {
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
$facility_status = $wip['facilityno'] . " (出貨前30天" . $arrayData[$wip['contractno']]['sign'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
//二次款
@ -419,6 +426,7 @@ foreach ($wipwhole_array as $wip) {
if ($today > $contractday) {
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$facility_status = $wip['facilityno'] . " (出貨後10天" . $arrayData[$wip['contractno']]['second'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
//貨抵工地款
@ -431,6 +439,7 @@ foreach ($wipwhole_array as $wip) {
if ($today > $contractday) {
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive'][2] = strval(date('Y-m-d', $contractday));
$facility_status = $wip['facilityno'] . " (貨抵工地後90天" . $arrayData[$wip['contractno']]['arrive'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
@ -444,6 +453,7 @@ foreach ($wipwhole_array as $wip) {
if ($today > $contractday) {
$arrayData[$wip['contractno']]['tryrun_num'] += 1;
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['tryrun'][2] = strval(date('Y-m-d', $contractday));
$facility_status = $wip['facilityno'] . " (試車後90天" . $arrayData[$wip['contractno']]['tryrun'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
@ -458,6 +468,8 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['delivery_num'] += 1;
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['delivery'][2] = strval(date('Y-m-d', $contractday));
$facility_status = $wip['facilityno'] . " (交車後270天" . $arrayData[$wip['contractno']]['delivery'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
@ -476,6 +488,7 @@ foreach ($wipwhole_array as $wip) {
} else {
$signtime = strtotime($arrayData[$wip['contractno']]['sign'][2]);
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
$month = collect_month($signtime);
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['sign'][6] = $month;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['sign'][2] = strval(date('Ymd', $signtime));
@ -490,14 +503,19 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) <br>";
$arrayData[$wip['contractno']]['tryrun_num'] += 1;
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['install_num'] += 1;
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if ($arrayData[$wip['contractno']]['delivery'][0] == "交車後270天") {
$estimate_delivery_time = strtotime($wip['delivery_date']);
@ -507,6 +525,8 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['delivery_num'] += 1;
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
}
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['delivery'][6] = $month;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['delivery'][2] = strval(date('Ymd', $arrivetime));
@ -518,8 +538,11 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['delivery_num'] += 1;
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['check_num'] += 1;
array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['delivery'][2] = strval($wip['delivery_date']);
$deliverytime = strtotime($wip['delivery_date']);
$month = collect_month($deliverytime);
@ -591,16 +614,22 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) <br>";
$arrayData[$wip['contractno']]['check_num'] += 1;
array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['tryrun_num'] += 1;
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['install_num'] += 1;
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if (!empty($wip['official_check_date']) && $wip['official_check_date'] != NULL) {
array_push($arrayData[$wip['contractno']]['check']['min'], strtotime(strval($wip['official_check_date'])));
array_push($arrayData[$wip['contractno']]['check']['max'], strtotime(strval($wip['official_check_date'])));
@ -741,12 +770,16 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) <br>";
$arrayData[$wip['contractno']]['install_num'] += 1;
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) {
$installtime = strtotime($wip['install_end_date']);
$month = collect_month($installtime);
@ -794,10 +827,13 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) <br>";
$arrayData[$wip['contractno']]['arrive_num'] += 1;
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") {
$estimate_delivery_time = strtotime($wip['real_arrival_date']);
@ -827,11 +863,14 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (已達二次款收款條件) <br>";
$arrayData[$wip['contractno']]['second_num'] += 1;
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']);
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
} else {
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
if ($wip['real_contract_arrival_date'] != NULL) {
$arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['real_contract_arrival_date'] . "預計出貨日) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['real_contract_arrival_date'] . "預計出貨日) <br>";
@ -870,6 +909,30 @@ foreach ($wipwhole_array as $wip) {
// }
// }
// foreach ($arrayData as $key => $value) {
// echo $key."<br>";
// print_r($value['total_list']);
// echo " / 總 ";
// print_r($value['sign_list']);
// echo " / 訂金 <br>";
// print_r($value['arrive_list']);
// echo " / 貨抵 ";
// print_r($value['install_list']);
// echo " / 安裝 <br>";
// print_r($value['tryrun_list']);
// echo " / 試車 ";
// print_r($value['check_list']);
// echo " / 官檢 <br>";
// print_r($value['delivery_list']);
// echo " / 移交 ";
// print_r($value['final_list']);
// echo " / 結案 <br>";
// echo "---------------------------<br>";
// foreach($value['sign_list'] as $fac){
// echo $fac."=========";
// }
// }
// 計算每個合約的應收款、作番總數
$today_date = new DateTime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m-d')))));
@ -894,6 +957,25 @@ foreach ($arrayData as &$value) {
$value['final'][3] = $value['final'][1] * $final_ratio;
$value['receivable_budget'] = $value['sign'][3] + $value['second'][3] + $value['arrive'][3] + $value['install'][3] + $value['tryrun'][3] + $value['check'][3] + $value['delivery'][3] + $value['final'][3];
}
//['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數
$sign_ratio = get_ratio($value['sign_list'], $value[10], $contract_budget);
$value['sign'][3] = $value['sign'][1] * $sign_ratio;
$second_ratio = get_ratio($value['second_list'], $value[10], $contract_budget);
$value['second'][3] = $value['second'][1] * $second_ratio;
$arrive_ratio = get_ratio($value['arrive_list'], $value[10], $contract_budget);
$value['arrive'][3] = $value['arrive'][1] * $arrive_ratio;
$install_ratio = get_ratio($value['install_list'], $value[10], $contract_budget);
$value['install'][3] = $value['install'][1] * $install_ratio;
$tryrun_ratio = get_ratio($value['tryrun_list'], $value[10], $contract_budget);
$value['tryrun'][3] = $value['tryrun'][1] * $tryrun_ratio;
$check_ratio = get_ratio($value['check_list'], $value[10], $contract_budget);
$value['check'][3] = $value['check'][1] * $check_ratio;
$delivery_ratio = get_ratio($value['delivery_list'], $value[10], $contract_budget);
$value['delivery'][3] = $value['delivery'][1] * $delivery_ratio;
$final_ratio = get_ratio($value['final_list'], $value[10], $contract_budget);
$value['final'][3] = $value['final'][1] * $final_ratio;
$value['receivable_budget'] = $value['sign'][3] + $value['second'][3] + $value['arrive'][3] + $value['install'][3] + $value['tryrun'][3] + $value['check'][3] + $value['delivery'][3] + $value['final'][3];
}
//['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數
// 計算每台作番金額與各階段應收金額
foreach ($value['facility'] as &$val) {
@ -1262,6 +1344,284 @@ foreach ($arrayData as $key => &$data) {
$data['final'][7] = 0;
}
}
//['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 4 已收金額 5 催收金額 6 已開發票金額 7 未開發票金額 min 最早應收月份 max 最晚應收月份
foreach ($arrayData as $key => &$data) {
$tmp_data = $data['received_budget'];
$tmp_invoice = $data['invoice_budget'];
if ($data['sign'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['sign'][3]) >= 0) {
$data['sign'][4] = $data['sign'][3];
$tmp_data -= $data['sign'][3];
} else {
$data['sign'][4] = $tmp_data;
$tmp_data = 0;
}
$data['sign'][5] = $data['sign'][3] - $data['sign'][4];
} else {
$data['sign'][4] = 0;
$data['sign'][5] = $data['sign'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['sign'][3]) >= 0) {
$data['sign'][6] = $data['sign'][3];
$tmp_invoice -= $data['sign'][3];
} else {
$data['sign'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['sign'][7] = $data['sign'][3] - $data['sign'][6];
} else {
$data['sign'][6] = 0;
$data['sign'][7] = $data['sign'][3];
}
} else {
$data['sign'][4] = 0;
$data['sign'][5] = 0;
$data['sign'][6] = 0;
$data['sign'][7] = 0;
}
if ($data['second'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['second'][3]) >= 0) {
$data['second'][4] = $data['second'][3];
$tmp_data -= $data['second'][3];
} else {
$data['second'][4] = $tmp_data;
$tmp_data = 0;
}
$data['second'][5] = $data['second'][3] - $data['second'][4];
} else {
$data['second'][4] = 0;
$data['second'][5] = $data['second'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['second'][3]) >= 0) {
$data['second'][6] = $data['second'][3];
$tmp_invoice -= $data['second'][3];
} else {
$data['second'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['second'][7] = $data['second'][3] - $data['second'][6];
} else {
$data['second'][6] = 0;
$data['second'][7] = $data['second'][3];
}
} else {
$data['second'][4] = 0;
$data['second'][5] = 0;
$data['second'][6] = 0;
$data['second'][7] = 0;
}
if ($data['arrive'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['arrive'][1]) >= 0) {
$data['arrive'][4] = $data['arrive'][3];
$tmp_data -= $data['arrive'][3];
} else {
$data['arrive'][4] = $tmp_data;
$tmp_data = 0;
}
$data['arrive'][5] = $data['arrive'][3] - $data['arrive'][4];
} else {
$data['arrive'][4] = 0;
$data['arrive'][5] = $data['arrive'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['arrive'][3]) >= 0) {
$data['arrive'][6] = $data['arrive'][3];
$tmp_invoice -= $data['arrive'][3];
} else {
$data['arrive'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['arrive'][7] = $data['arrive'][3] - $data['arrive'][6];
} else {
$data['arrive'][6] = 0;
$data['arrive'][7] = $data['arrive'][3];
}
} else {
$data['arrive'][4] = 0;
$data['arrive'][5] = 0;
$data['arrive'][6] = 0;
$data['arrive'][7] = 0;
}
if ($data['install'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['install'][1]) >= 0) {
$data['install'][4] = $data['install'][3];
$tmp_data -= $data['install'][3];
} else {
$data['install'][4] = $tmp_data;
$tmp_data = 0;
}
$data['install'][5] = $data['install'][3] - $data['install'][4];
} else {
$data['install'][4] = 0;
$data['install'][5] = $data['install'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['install'][3]) >= 0) {
$data['install'][6] = $data['install'][3];
$tmp_invoice -= $data['install'][3];
} else {
$data['install'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['install'][7] = $data['install'][3] - $data['install'][6];
} else {
$data['install'][6] = 0;
$data['install'][7] = $data['install'][3];
}
} else {
$data['install'][4] = 0;
$data['install'][5] = 0;
$data['install'][6] = 0;
$data['install'][7] = 0;
}
if ($data['tryrun'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['tryrun'][1]) >= 0) {
$data['tryrun'][4] = $data['tryrun'][3];
$tmp_data -= $data['tryrun'][3];
} else {
$data['tryrun'][4] = $tmp_data;
$tmp_data = 0;
}
$data['tryrun'][5] = $data['tryrun'][3] - $data['tryrun'][4];
} else {
$data['tryrun'][4] = 0;
$data['tryrun'][5] = $data['tryrun'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['tryrun'][3]) >= 0) {
$data['tryrun'][6] = $data['tryrun'][3];
$tmp_invoice -= $data['tryrun'][3];
} else {
$data['tryrun'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['tryrun'][7] = $data['tryrun'][3] - $data['tryrun'][6];
} else {
$data['tryrun'][6] = 0;
$data['tryrun'][7] = $data['tryrun'][3];
}
} else {
$data['tryrun'][4] = 0;
$data['tryrun'][5] = 0;
$data['tryrun'][6] = 0;
$data['tryrun'][7] = 0;
}
if ($data['check'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['check'][1]) >= 0) {
$data['check'][4] = $data['check'][3];
$tmp_data -= $data['check'][3];
} else {
$data['check'][4] = $tmp_data;
$tmp_data = 0;
}
$data['check'][5] = $data['check'][3] - $data['check'][4];
} else {
$data['check'][4] = 0;
$data['check'][5] = $data['check'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['check'][3]) >= 0) {
$data['check'][6] = $data['check'][3];
$tmp_invoice -= $data['check'][3];
} else {
$data['check'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['check'][7] = $data['check'][3] - $data['check'][6];
} else {
$data['check'][6] = 0;
$data['check'][7] = $data['check'][3];
}
} else {
$data['check'][4] = 0;
$data['check'][5] = 0;
$data['check'][6] = 0;
$data['check'][7] = 0;
}
if ($data['delivery'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['delivery'][1]) >= 0) {
$data['delivery'][4] = $data['delivery'][3];
$tmp_data -= $data['delivery'][3];
} else {
$data['delivery'][4] = $tmp_data;
$tmp_data = 0;
}
$data['delivery'][5] = $data['delivery'][3] - $data['delivery'][4];
} else {
$data['delivery'][4] = 0;
$data['delivery'][5] = $data['delivery'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['delivery'][3]) >= 0) {
$data['delivery'][6] = $data['delivery'][3];
$tmp_invoice -= $data['delivery'][3];
} else {
$data['delivery'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['delivery'][7] = $data['delivery'][3] - $data['delivery'][6];
} else {
$data['delivery'][6] = 0;
$data['delivery'][7] = $data['delivery'][3];
}
} else {
$data['delivery'][4] = 0;
$data['delivery'][5] = 0;
$data['delivery'][6] = 0;
$data['delivery'][7] = 0;
}
if ($data['final'][3] > 0) {
if ($tmp_data > 0) {
if (($tmp_data - $data['final'][1]) >= 0) {
$data['final'][4] = $data['final'][3];
$tmp_data -= $data['final'][3];
} else {
$data['final'][4] = $tmp_data;
$tmp_data = 0;
}
$data['final'][5] = $data['final'][3] - $data['final'][4];
} else {
$data['final'][4] = 0;
$data['final'][5] = $data['final'][3];
}
if ($tmp_invoice > 0) {
if (($tmp_invoice - $data['final'][3]) >= 0) {
$data['final'][6] = $data['final'][3];
$tmp_invoice -= $data['final'][3];
} else {
$data['final'][6] = $tmp_invoice;
$tmp_invoice = 0;
}
$data['final'][7] = $data['final'][3] - $data['final'][6];
} else {
$data['final'][6] = 0;
$data['final'][7] = $data['final'][3];
}
} else {
$data['final'][4] = 0;
$data['final'][5] = 0;
$data['final'][6] = 0;
$data['final'][7] = 0;
}
}
//產生excel的array
$excel_aray = array();
@ -1332,6 +1692,7 @@ foreach ($arrayData as $key => $value) {
number_format(round($value['A40001'])), number_format(round($value['A40008'])), number_format(round($value['total_budget'])), number_format(round($value['receivable_budget'])), number_format(round($value['invoice_budget'])), number_format(round($value['received_budget'])), $value['total_facility_num'], str_replace('<br>', '; ', $value['facilities'])
];
//['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 min 最早應收月份 max 最晚應收月份
//[合約號]['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數
foreach ($value['facility'] as $valkey => $val) {
@ -1389,6 +1750,7 @@ $average_A40001 = round($sum_A40001 / $sum_facility, 2);
$average_A40008 = round($sum_A40008 / $sum_facility, 2);
$average_budget = round($sum_total_budget / $sum_facility, 2);
$total_data = json_encode($excel_aray);
$total_data = json_encode($excel_aray);
$boga_data = json_encode($boga_array);
$exclude_boga_data = json_encode($exclude_boga_array);
@ -1448,6 +1810,7 @@ $facility_exclude_boga_data = json_encode($facility_exclude_boga_array);
<button type="button" style="width: 12%;" onclick="downloadFacilityData('ExcludeData')" class="btn btn-info btn-md">不含寶佳作番收款明細<span class="glyphicon glyphicon-download-alt"></span></button>
<button type="button" style="width: 12%;" onclick="downloadFacilityData('BogaData')" class="btn btn-warning btn-md">寶佳作番收款明細<span class="glyphicon glyphicon-download-alt"></span></button>
</div>
</div>
@ -1642,11 +2005,13 @@ include "./footer.php";
}
xhr.send(JSON.stringify({
Bill: <?= $total_data ?>
Bill: <?= $total_data ?>
}));
}
function bogaData() {
console.log(<?= $boga_data ?>);
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/account-receivable-excel.php?type=boga&<?= $token_link ?>";
xhr.open('POST', url, true);
@ -1675,9 +2040,11 @@ include "./footer.php";
if (content == 'AllData') {
var BillData = <?= $facility_data ?>;
var filename = "作番應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";
} else if (content == 'ExcludeData') {
} else if (content == 'ExcludeData') {
var BillData = <?= $facility_exclude_boga_data ?>;
var filename = "不含寶佳作番應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";
} else if (content == 'BogaData') {
} else if (content == 'BogaData') {
var BillData = <?= $facility_boga_data ?>;
var filename = "寶佳作番應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";

22906
wms/account_receivable_sql_file.sql

File diff suppressed because it is too large

BIN
wms/assemble_warehouse.xlsx

Binary file not shown.

370
wms/cont/sign_list.php

@ -3,34 +3,77 @@ require_once "../header.php";
// 載入db.php來連結資料庫
$table = 'con_maintance_examine_apply';
$para = "function_name=pricereview&" . $token_link;
// 待我簽核進入
if (!empty($_GET['system_id']) && !empty($_GET['flow_id'])) {
$system_id = $_SERVER['REQUEST_METHOD'] == 'GET' ? @$_GET['system_id'] : @$_POST['system_id'];
$where_system_id = " and a.system_id like '" . $system_id . "%'";
$flow_id = $_SERVER['REQUEST_METHOD'] == 'GET' ? @$_GET['flow_id'] : @$_POST['flow_id'];
$where_flow_id = " and b.flow_id like '" . $flow_id . "%'";
$sql_get = "SELECT d.form_id,c.form_key, a.system_id,b.flow_id ,a.system_name,c.current_assigner,
concat(c.current_assigner ,'-',f_return_name(c.current_assigner)) current_assigner_name ,
flow_name,c.update_date ,c.create_date,b.path,d.flow_code FROM system_main a,flow_main b ,subflow
c,flow d
WHERE a.system_id=b.system_id
AND b.flow_id=d.flow_id
AND c.current_assigner='$user_id'
AND d.flow_id=b.flow_id
AND c.form_key=d.form_key
$where_system_id
$where_flow_id
";
// echo '<pre>';
// print_r($sql_get);
// echo '</pre>';
$result = mysqli_query($link, $sql_get);
if ($result == false) {
die(mysqli_error($link));
}
$res_get = mysqli_fetch_all(mysqli_query($link, $sql_get), MYSQLI_ASSOC);
$status_arr = ["Y1" => "暫存", "YS" => "簽核中", "YY" => "結案同意", "YN" => "結案不同意"];
#可編輯的列
// $editableColumn = [
// 'apply_key' => [
// 'label' => "評審單號", "value" => "", "tag" => 'text',
// 'attr' => [
// 'readonly=true ',
// 'class' => 'form-control form-control-sm'
// ]
// ],
// 'vol_no' => ['label' => "卷號", "value" => "", "tag" => 'text', 'attr' => ['readonly=true ', 'class' => 'form-control form-control-sm']],
// 'address' => ['label' => "現場地址", "value" => "", "tag" => 'text', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
// 'case_name' => ['label' => "現場名稱", "value" => "", "tag" => 'text', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
// 'brand' => ['label' => "電梯品牌", "value" => "", "tag" => 'select', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
// 'num' => ['label' => "電梯臺數", "value" => "", "tag" => 'number', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
// 'salesman' => ['label' => "營業員", "value" => "", "tag" => 'text', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
// 'maintain_kind' => ['label' => "保養方式", "value" => "", "tag" => 'select', 'attr' => ['class' => 'form-control form-control-sm']],
// 'contract_begin_date' => ['label' => "契約期限開始", "value" => "", "tag" => 'date', 'attr' => ['required', 'class' => 'date form-control form-control-sm']],
// 'contract_end_date' => ['label' => "契約期限結束", "value" => "", "tag" => 'date', 'attr' => ['required', 'class' => 'date form-control form-control-sm']],
// 'contract_kind' => ['label' => "契約性質", "value" => "", "tag" => 'select', 'attr' => ['class' => 'form-control form-control-sm']],
// 'platform_company' => ['label' => "加盟公司名稱", "value" => "", "tag" => 'text', 'attr' => ['class' => 'form-control form-control-sm']],
// 'platforom_company_tel' => ['label' => "加盟公司電話", "value" => "", "tag" => 'text', 'attr' => ['class' => 'form-control form-control-sm']],
// //'payment_kind' => ['label' => "付款方式", "value" => "", "tag" => 'select', 'attr' => ['required', 'class' => 'form-control form-control-sm'], 'options' => $payment_kind_opt],
foreach ($res_get as $key => $data) {
// 結案隱藏
if ($data['flow_code'] !== 'Z') {
$test = $data['form_key'];
// $sql = "SELECT mid FROM pricereview_sign WHERE id = $test";
// $result = mysqli_fetch_all(mysqli_query($link, $sql), MYSQLI_ASSOC);
// echo '<pre>';
// print_r($result);
// echo '</pre>';
$id[] = $test;
}
}
$inClause = implode(',', $id);
}
// ];
#可編輯的列
$editableColumn = [
'apply_key' => [
'label' => "評審單號", "value" => "", "tag" => 'text',
'attr' => [
'readonly=true ',
'class' => 'form-control form-control-sm'
]
],
'vol_no' => ['label' => "卷號", "value" => "", "tag" => 'text', 'attr' => ['readonly=true ', 'class' => 'form-control form-control-sm']],
'address' => ['label' => "現場地址", "value" => "", "tag" => 'text', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
'case_name' => ['label' => "現場名稱", "value" => "", "tag" => 'text', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
'brand' => ['label' => "電梯品牌", "value" => "", "tag" => 'select', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
'num' => ['label' => "電梯臺數", "value" => "", "tag" => 'number', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
'salesman' => ['label' => "營業員", "value" => "", "tag" => 'text', 'attr' => ['required', 'class' => 'form-control form-control-sm']],
'maintain_kind' => ['label' => "保養方式", "value" => "", "tag" => 'select', 'attr' => ['class' => 'form-control form-control-sm']],
'contract_begin_date' => ['label' => "契約期限開始", "value" => "", "tag" => 'date', 'attr' => ['required', 'class' => 'date form-control form-control-sm']],
'contract_end_date' => ['label' => "契約期限結束", "value" => "", "tag" => 'date', 'attr' => ['required', 'class' => 'date form-control form-control-sm']],
'contract_kind' => ['label' => "契約性質", "value" => "", "tag" => 'select', 'attr' => ['class' => 'form-control form-control-sm']],
'platform_company' => ['label' => "加盟公司名稱", "value" => "", "tag" => 'text', 'attr' => ['class' => 'form-control form-control-sm']],
'platforom_company_tel' => ['label' => "加盟公司電話", "value" => "", "tag" => 'text', 'attr' => ['class' => 'form-control form-control-sm']],
//'payment_kind' => ['label' => "付款方式", "value" => "", "tag" => 'select', 'attr' => ['required', 'class' => 'form-control form-control-sm'], 'options' => $payment_kind_opt],
];
// 設置一個空陣列來放資料
$data = array();
@ -45,7 +88,7 @@ $res = mysqli_query($link, $sql);
$row = mysqli_fetch_row($res);
$user_department_id = $row[0];
mysqli_free_result($res);
if (in_array($user_department_id, $depart_arr) || $user_id == "M0008" || $user_id == "M0012" || $user_id == "M0006" || $user_id == "M0189" || $user_id == "TEST01" || $user_id == "TEST02" || $user_id == "TEST03" || $user_id == "M0225") $where = "";
if (in_array($user_department_id, $depart_arr) || $user_id == "M0008" || $user_id == "M0012" || $user_id == "M0006" || $user_id == "M0189" || $user_id == "TEST01" || $user_id == "TEST02" || $user_id == "TEST03" || $user_id == "TEST04") $where = "";
// 電梯廠牌
$elevator_brand_arr = [];
@ -55,32 +98,49 @@ while ($row = mysqli_fetch_row($res)) {
$elevator_brand_arr[$row[0]] = $row[1];
}
mysqli_free_result($res);
$sql = "SELECT
apply_key,
vol_no,
address,
case_name,
brand ,
num ,
salesman as salesman_id,
f_return_name(salesman) salesman,
f_return_content('maintain_kind',maintain_kind ) maintain_kind,
date_format(contract_begin_date,'%Y/%m/%d') contract_begin_date,
date_format(contract_end_date,'%Y/%m/%d') contract_end_date ,
f_return_content('contract_kind',contract_kind ) contract_kind,
platform_company,
platforom_company_tel,
form_key,
status,
f_return_content('payment_kind',payment_kind ) payment_kind FROM $table
where 1=1 $where ORDER BY vol_no";
if (!empty($res_get)) {
$sql = "SELECT
apply_key,
vol_no,
address,
case_name,
brand ,
num ,
f_return_name(salesman) salesman,
f_return_content('maintain_kind',maintain_kind ) maintain_kind,
date_format(contract_begin_date,'%Y/%m/%d') contract_begin_date,
date_format(contract_end_date,'%Y/%m/%d') contract_end_date ,
f_return_content('contract_kind',contract_kind ) contract_kind,
platform_company,
platforom_company_tel,
form_key,
f_return_content('payment_kind',payment_kind ) payment_kind FROM $table WHERE form_key IN ($inClause) ";
} else {
$sql = "SELECT
apply_key,
vol_no,
address,
case_name,
brand ,
num ,
f_return_name(salesman) salesman,
f_return_content('maintain_kind',maintain_kind ) maintain_kind,
date_format(contract_begin_date,'%Y/%m/%d') contract_begin_date,
date_format(contract_end_date,'%Y/%m/%d') contract_end_date ,
f_return_content('contract_kind',contract_kind ) contract_kind,
platform_company,
platforom_company_tel,
form_key,
f_return_content('payment_kind',payment_kind ) payment_kind FROM $table
where 1=1 $where ORDER BY vol_no";
}
// echo $sql;
$data = mysqli_query($link, $sql);
// echo '<pre>';
// print_r($sql);
// print_r($data);
// echo '</pre>';
?>
<?php
@ -96,175 +156,59 @@ if ($data) :
}
?>
<!-- <link rel="stylesheet" href="common.css"> -->
<style>
#table_index2 {
table-layout: fixed;
width: 100%;
}
#table_index2_filter {
float: right;
}
#table_index2_paginate {
float: right;
}
div.dataTables_scrollHead table.dataTable {
margin-bottom: 0 !important;
border-bottom-width: 0;
}
div.dataTables_scrollBody table.dataTable {
border-top-width: 0;
}
/*
.col-sm-12 {
width: auto;
}
*/
img {
width: 125px;
}
.width_style_1 {
width: 125px;
}
label {
display: inline-flex;
margin-bottom: .5rem;
margin-top: .5rem;
}
div a:hover {
text-decoration: none;
}
.btn-sm {
font-size: 14px;
margin: 2px 0;
line-height: 90%;
}
.glyphicon-ok,
.glyphicon-ban-circle {
font-size: 130%;
}
.btn-secondary {
color: #fff;
background-color: #6c757d;
border-color: #6c757d;
}
<link rel="stylesheet" href="common.css">
.btn-secondary:hover {
color: #fff;
background-color: #5a6268;
border-color: #545b62;
}
.applybtn {
color: #fff;
background-color: #1484c4;
display: block;
border-radius: 4px;
padding: 4px 2px;
font-size: 13px;
<div style="overflow-x:auto;">
<form method='get' action='#'>
<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>
<table id="table_index" class="table table-striped table-bordered" style="width:98%">
<thead>
<?php
echo "<tr>";
foreach ($editableColumn as $key => $val) {
echo "<th>" . $val['label'] . "</th>";
}
echo "<th>是否結案</th>";
// echo "<th>刪除</th>";
echo "</tr>";
?>
</thead>
<tbody>
<?php foreach ($data as $row) : ?>
<tr>
<?php
foreach ($editableColumn as $key => $val) {
if ($key == 'apply_key') {
echo "<td> <a href='query_form.php?apply_key=$row[$key]&token=" . $_GET['token'] . "'>" . $row[$key] . "</td>";
} elseif ($key == 'brand') {
echo "<td>" . (!empty($row[$key]) ? $elevator_brand_arr[$row[$key]] : "") . "</td>";
} else {
echo "<td>" . $row[$key] . "</td>";
}
}
//list($signer)=DB::fields(");
//echo " select f_return_name(current_assigner) signer from subflow where form_key='". $row['form_key'] ."'"; ". (is_array($row['form_key'])?'': $row['form_key']) ."
list($signer) = mysqli_fetch_array(mysqli_query($link, "select max(f_return_name(current_assigner) ) signer from subflow where form_key='" . $row['form_key'] . "'"));
.applybtn:hover {
background-color: #1494f9;
color: #fff;
}
</style>
<script>
$(function() {
$('#table_index2').DataTable({
"scrollX": true,
"pageLength": 50
});
/*
var api = $('#table_index').dataTable().api();
//var order = api.order();
//console.log(order);
api
.order([0, "desc"])
.draw();
*/
});
</script>
<link rel="stylesheet" href="../crm/common.css">
echo "<td>" . (empty($signer) ? "結案" : "N") . "</td>";
<div style="overflow-x:auto; white-space:nowrap;">
<table id="table_index2" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>評審單號</th>
<th>卷號</th>
<th>現場地址</th>
<th>現場名稱</th>
<th>電梯品牌</th>
<th>電梯台數</th>
<th>營業員</th>
<th>保養方式</th>
<th>契約期限開始</th>
<th>契約期限結束</th>
<th>契約性質</th>
<th>加盟公司名稱</th>
<th>加盟公司電話</th>
<!-- <th>加盟公司電話</th> -->
<th>是否結案</th>
<th>合約下載</th>
</tr>
</thead>
<tbody>
<?php foreach ($data as $row) :
$oneself = ($row['salesman'] == $user_id) ? 1 : 0;
?>
<tr>
<td><a href="query_form.php?apply_key=<?= $row['apply_key'] ?>&token=<?= $_GET['token'] ?>"><?= $row['apply_key'] ?></a></td>
<td><?php echo $row['vol_no'] ?></td>
<td><?php echo $row['address'] ?></td>
<td><?php echo $row['case_name'] ?></td>
<td><?php echo $row['brand'] ?></td>
<td><?php echo $row['num'] ?></td>
<td><?php echo $row['salesman'] ?></td>
<td><?php echo $row['maintain_kindd'] ?></td>
<td><?php echo $row['contract_begin_date'] ?></td>
<td><?php echo $row['contract_end_date'] ?></td>
<td><?php echo $row['contract_kind'] ?></td>
<td><?php echo $row['platform_company'] ?></td>
<td><?php echo $row['platforom_company_tel'] ?></td>
?>
<?php list($signer) = mysqli_fetch_array(mysqli_query($link, "select max(f_return_name(current_assigner) ) signer from subflow where form_key='" . $row['form_key'] . "'")); ?>
<td><?php echo empty($signer) ? '結案' : 'N' ?></td>
<td>
<a class="applybtn" href="../contract-repair/contract_maintance.php?apply_key=<?php echo $row['apply_key'] . '&' . $para; ?>">
<?php if (($row['status'] == 'YY' && $oneself)) {
echo '申請';
} else {
echo '檢視';
} ?>
</a>
<?php if ($row['status'] == 'YY' && ($user_id == "M0060" || $user_id == "M0107" || $user_id == "M0174" || $user_id == 'M0225') && $row['applystatus'] == 1) : ?>
<a class="applybtn" href="../contract-repaire/contract_maintance.php?id=<?php echo $row['id'] . '&' . $para; ?>">待簽核</a><br>
<?php endif; ?>
<?php if ($row['status'] != 'Y1') : ?>
<span style="font-size:13px;font-weight:600">--</span>
<?php endif; ?>
<?php if (($row['status'] === 'YY' && $row['applystatus'] == 3 && ($user_id == "M0107" || $user_id == "M0060")) || $user_id == "M0174" || $user_id == 'M0225') : ?>
<a class="applybtn" href="../contract-repair/contract-download.php?apply_key=<?php echo $row['apply_key'] . '&' . $para ?>">下載</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php

41
wms/contract/api/T8salIncomeApply.php

@ -0,0 +1,41 @@
<?php
require_once("../../T8_Authorization_from_bpm.php");
function T8API($data)
{
// echo '<pre>';
// print_r(json_encode($data));
// echo '</pre>';
$api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData';
$validation = get_Auth();
$header = [
"CHI_Authorization :" . $validation
];
$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($data));
$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'];
return $result;
} else {
// echo '<pre>';
// print_r($result);
// echo '</pre>';
return $result;
}
}
curl_close($ch);
}
// T8API($data);

136
wms/contract/api/postContractData.php

@ -327,7 +327,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
// $stmt->bindParam(':CreateTime', $createTime);
// $stmt->execute();
// T8insert($_POST, $facilityno);
T8insert($_POST, $facilityno);
header('Content-Type: application/json');
$jsonData = json_encode($files);
@ -344,7 +344,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
function T8insert($data, $facilityno)
{
require_once("../connt8.php");
// include "../../T8_Authorization.php";
// 引入 T8 API 連線
require_once("./T8salIncomeApply.php");
$contractno = !empty($data['contractno']) ? $data['contractno'] : null; // 合約號
$address = !empty($data['address']) ? $data['address'] : null; // 客戶地址
@ -360,6 +361,7 @@ function T8insert($data, $facilityno)
$num = !empty($data['num']) ? $data['num'] : null; // 電梯數量
$elevators = !empty($data['elevators']) ? json_decode($data['elevators'], true) : []; //電梯
$area = !empty($data['area']) ? $data['area'] : null; //縣市 Ex. A->台北 , B-> ..。
$payType = !empty($data['payType']) ? $data['payType'] : null;
$user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null;
@ -372,7 +374,9 @@ function T8insert($data, $facilityno)
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$date = date('Y-m-sH-s-i');
$date_1 = date('Y-m-s');
$createTime = str_replace("-", '', $date);
$insertTime = str_replace('-', '', $date_1);
$beginDate = str_replace("-", '', $contract_begin_date);
$endDate = str_replace("-", '', $contract_end_date);
if ($contractno == '') {
@ -464,23 +468,25 @@ function T8insert($data, $facilityno)
$type = 'C5';
}
}
// echo '<pre>';
// print_r($type);
// echo '</pre>';
// //新增於 comProject。合約 table
$sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,ValidityFromDate,ValidityToDate,CreateTime,CreatorId,IsInUsed)
VALUES(:ProjectId,:ProjectName,:TypeId,:ValidityFromDate,:ValidityToDate,:CreateTime,:CreatorId,1)";
$sql = "SELECT * FROM comProject WHERE ProjectId = :ProjectId";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':ProjectId', $contractno);
$stmt->bindParam(':ProjectName', $customer);
$stmt->bindParam(':TypeId', $type);
$stmt->bindParam(':ValidityFromDate', $beginDate);
$stmt->bindParam(':ValidityToDate', $endDate);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->execute();
$resultProject = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($resultProject)) {
//新增於 comProject。合約 table
$sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,ValidityFromDate,ValidityToDate,CreateTime,CreatorId,IsInUsed)
VALUES(:ProjectId,:ProjectName,:TypeId,:ValidityFromDate,:ValidityToDate,:CreateTime,:CreatorId,1)";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':ProjectId', $contractno);
$stmt->bindParam(':ProjectName', $customer);
$stmt->bindParam(':TypeId', $type);
$stmt->bindParam(':ValidityFromDate', $beginDate);
$stmt->bindParam(':ValidityToDate', $endDate);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->execute();
}
// // 新增電梯數
foreach ($elevators as $index => $elevator) {
@ -515,36 +521,76 @@ function T8insert($data, $facilityno)
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
}
// 分期代碼計算
$IncomeId = [
'A40006' => 1,
'A40007' => 4,
'A40003' => 12,
'A40004' => 6,
'A40005' => 2
];
//分幾期 => 總共保養月 / 分期月
$SQuantity = $elevator['maintain_months'] / $IncomeId[$payType];
// 依每台電梯去加入各個的付款項
for ($i = 1; $i <= $IncomeId[$payType]; $i++) {
$rows_data = [
"BillNo" => "$contractno",
"IncomeId" => "$payType",
"TaxId" => "ST005",
"RowCode" => $i,
"RowNo" => $i,
"ItemType" => 1,
"SPrice" => $elevator['sold_price'],
"SQuantity" => $SQuantity,
"ProjectId" => "$contractno",
"FromSourceTag" => 0,
"CU_MaterialId" => "$facilityno[$index]"
];
$salIncomeApplyDetail_rows[] = $rows_data;
}
}
?>
<!-- <script src="./js/axios/axios.min.js"></script>
<script>
const form = new FormData();
form.append('BillNo', <?php echo $contractno ?>);
form.append('BillDate', );
form.append('');
form.append('');
form.append('');
form.append('');
form.append('');
axios.post('https://127.0.0.1:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData', form).then(res => {
console.log(res.status);
if (res.status == 200) {
alert('成功');
}
}).catch(err => {
console.log(err);
let code = err.response.data;
if (code == 422) {
console.log(err);
}
if (code == 500) {
alert('儲存失敗!可能為下載錯誤:\n' + error.response.data);
}
})
</script> -->
<?php
$connT8->commit();
// $insertime = settype($insertTime, 'integer');
$salIncomeApplyMaster_rows = [
"BillNo" => "$contractno",
"BillDate" => $insertTime,
"OrgId" => "1000",
"FOrgId" => "1000",
"TypeId" => "RAS",
"BpOrgId" => "1000",
"BizPartnerId" => "$contractno",
"CurrId" => "TWD",
"CurrOAmount" => 1,
"CurrLAmount" => 1,
"PersonId" => "$salesman",
"DtOrgId" => "1000",
"DueToId" => "$contractno",
"TaxId" => "ST005",
"CompId" => "1001",
"CreatorId" => "$user_id"
];
$salIncomeApplyMaster = [
'name' => "salIncomeApplyMaster",
'rows' => [$salIncomeApplyMaster_rows]
];
$salIncomeApplyDetail = [
'name' => "salIncomeApplyDetail",
'rows' => $salIncomeApplyDetail_rows
];
$API_body[] = $salIncomeApplyMaster;
$API_body[] = $salIncomeApplyDetail;
// 呼叫 API
$result = T8API($API_body);
if ($result['Status'] == 'Error') {
http_response_code(404);
die('Error!:' . $result['ErrorMsg']);
}
}

186
wms/contract/api/test.json

@ -0,0 +1,186 @@
[
{
"name": "salIncomeApplyMaster",
"rows": [
{
"BillNo": "B23100060",
"BillDate": "20240122",
"OrgId": "1000",
"FOrgId": "1000",
"TypeId": "RAS",
"BpOrgId": "1000",
"BizPartnerId": "B23100060",
"CurrId": "TWD",
"CurrOAmount": 1,
"CurrLAmount": 1,
"PersonId": "M0065",
"DtOrgId": "1000",
"DueToId": "B23100060",
"TaxId": "ST005",
"CompId": "1001",
"CreatorId": "M0225"
}
]
},
{
"name": "salIncomeApplyDetail",
"rows": [
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"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",
"RowCode": 7,
"RowNo": 7,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
},
{
"BillNo": "B23100060",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 8,
"RowNo": 8,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"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",
"IncomeId": "A40003",
"TaxId": "ST005",
"RowCode": 12,
"RowNo": 12,
"ItemType": 1,
"SPrice": 1250,
"SQuantity": 1,
"ProjectId": "B23100060",
"FromSourceTag": 0,
"CU_MaterialId": "4TH53801"
}
]
}
]

157
wms/contract/api/testT8API.php

@ -1,77 +1,86 @@
<?php
$now = gmdate("YmdHis");
$data = 'M0000.' . $now;
$sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false);
?>
require_once('../../T8_Authorization_from_bpm.php');
require_once('../connt8.php');
$sql = "SELECT * FROM salIncomeApplyMaster WHERE BillNo = '3TX10701' ";
$stmt = $connT8->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo '<pre>';
print_r($result);
echo '</pre>';
// $date = date("Y-m-d");
// $date1 = str_replace('-', '', $date);
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<script>
var body = [{
"name": "salIncomeApplyMaster",
"rows": [{
"BillNo": "Z001",
"BillDate": 20160811,
"OrgId": "1000",
"FOrgId": "1000",
"TypeId": "RR",
"BpOrgId": "1000",
"BizPartnerId": "C002",
"CurrId": "RMB",
"CurrOAmount": 1,
"CurrLAmount": 1,
"PersonId": "T001",
"DtOrgId": "1000",
"DueToId": "C002",
"TaxId": "123",
"CompId": "1000"
}]
},
{
"name": "salIncomeApplyDetail",
"rows": [{
"BillNo": "Z001",
"IncomeId": "F203",
"TaxId": "ST003",
"RowCode": 1,
"ItemType": "1",
"SPrice": 50,
"SQuantity": 1,
"FromSourceTag": 0,
"FromBillNo": "123"
}]
}
]
// $arr = [
// "date" => $date1
// ];
var json = JSON.stringify(body);
console.log(json);
// obj = {
// type: 'POST',
// // url: `${corsurl}${apiurl}`,
// url: `${apiurl}`,
// dataType: 'json',
// headers: headerParam,
// data: json,
// // dataType: "json",
// success: function(res) {
// console.log(res.Status);
// console.log(res.ErrorMsg);
// console.log(res.Data);
// }
// };
// jQuery.ajax(obj);
// // }
// })
$.ajax({
url: 'https://127.0.0.1:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData',
method: 'POST',
dataType: 'json',
// headers: headerParam,
data: body,
success: function(res) {
console.log('Success');
},
error: function(err) {
console.log(err);
}
})
</script>
// echo '<pre>';
// print_r($arr);
// echo '</pre>';
// $validation = get_Auth();
// $data = [
// [
// "name" => "OtherStockOutMtable",
// "rows" => [
// [
// "BillNo" => "00850110", // 單據編號 varchar(20)
// "BillDate" => 20210427, // 單據日期 int
// "OrgId" => "1000", //組織 varchar(20)
// "FOrgId" => "1000", //核算組織 varchar(20)
// "TypeId" => "OS", //單據類型 varchar(10)
// "BizPartnerId" => "", //往來對象(供應商) 可為空
// "PersonId" => "C0003", // 經辦人員 varchar(20)
// "DeptId" => "250", // 經辦部門 varchar(20)
// "CompId" => "1001" // 公司 varchar(20)
// ]
// ]
// ], [
// "name" => "OtherStockOutDetail",
// "rows" => [
// [
// "BillNo" => "00850110", //單據編號 varchar(20)
// "RowCode" => 1, // 序號 int(10)
// "MaterialId" => "MX00021003", // 產品代碼 -> 產品集成 varchar(40)
// "SupplyOrgId" => "1000", // 供貨組織代碼 varchar(20)
// "SQuantity" => 1, // 交易數量 numeric(19)
// "WarehouseId" => "100" // 倉庫代碼 varchar(20)
// ]
// ]
// ]
// ];
// $data = file_get_contents('test.json');
// echo '<pre>';
// print_r($data);
// echo '</pre>';
// $api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/STKOTHERSTOCKOUT/PostERPData';
// $header = [
// "CHI_Authorization :" . $validation
// ];
// $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);
// curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// $response = curl_exec($ch);
// if ($response === false) {
// echo 'Curl error: ' . curl_error($ch);
// } else {
// $result = json_decode($response, true);
// if ($result['Status'] == 'Error') {
// echo '<pre>';
// print_r($result);
// echo '</pre>';
// echo 'API 傳入錯誤,' . $result['ErrorMsg'];
// } else {
// echo '<pre>';
// print_r($result['Status']);
// echo '</pre>';
// return $result;
// }
// }
// curl_close($ch);

6
wms/contract/js/alpine.js

@ -964,7 +964,7 @@ const contractInput = () => {
num: '', //電梯數量
disabled: false, //資料庫是否有電梯數量資料
elevators: [], //機種、載重、人乘、樓停、樓層、速度、緯度、經度、開門方式、保養別、廠牌、竣檢日、許可證日期
payType: ''
payType: '' //付款方式
},
customize: false,
step: 1,
@ -1037,7 +1037,7 @@ const contractInput = () => {
this.data.disabled = (res.data.num > 0) ? true : false;
this.data.elevators = res.data.elevators
let cityIndex = this.data.address.indexOf('市');
console.log(cityIndex);
// console.log(cityIndex);
if (cityIndex == -1) {
// cityIndex = this.data.address.indexOf('縣');
}
@ -1122,7 +1122,7 @@ const contractInput = () => {
form.append('files[]', this.data.files[i]);
}
axios.post('./api/postContractData.php', form).then(res => {
console.log(res);
// console.log(res);
if (res.status === 200) {
alert('儲存成功');
this.step = 1

1
wms/frame/api_getdata.php

@ -166,6 +166,7 @@ function get_pending($token)
$res = mysqli_query($link, $sql);
while ($row = mysqli_fetch_row($res)) {
// print_r($row);
$data[$i]["sid"] = $row[0];
$data[$i]["sname"] = $row[1];
$data[$i]["fid"] = $row[2];

244
wms/frame/pending.php

@ -1,110 +1,136 @@
<?php
$token = $_REQUEST["token"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
<title>待我簽核</title>
<link rel="stylesheet" href="css/plugins/fontawesome-free/css/all.min.css">
<link rel="stylesheet" href="css/dist/css/adminlte.min.css">
<script src="../css/jquery.min.js"></script>
<script src="../css/bootstrap.min.js"></script>
<style>
.content-wrapper {
background-color: #fff;
}
.col-lg-6 {
padding:8px 0 0 0!important;
}
.card {
height: 90vh;
line-height: 14 px;
font-size: 14px;
}
.card-header {
background-color: #f4f6f9;
padding-left: 16px;
}
.card-body ol {
font-size: 14px;
margin-left: -30px;
}
.nav-pills .nav-link {
color: #446887;
}
h5 svg {
vertical-align: baseline;
}
h5 a {
color: #000;
}
@media screen and (max-width: 992px){
.card {
height: 95vh;
}
}
</style>
</head>
<body>
<div class="wrapper">
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Main content -->
<div class="content">
<div class="container">
<div class="row">
<!-- /.col-md-6 -->
<div class="col-lg-6">
<div class="card">
<div class="card-header">
<h5 class="card-title m-0"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16"><path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/><path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/></svg>
<a href="/wms/sign/list.php?function_name=show&token=<?php echo $token; ?>" target="_parent">待我簽核</a></h5>
</div>
<div class="card-body p-0">
Loading...
</div>
</div>
</div>
<!-- /.col-md-6 -->
</div>
<!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
</div>
<script>
$(document).ready(function() {
here();
});
function here() {
var URL = 'api_getdata.php';
$.ajax({
type: "GET",
data: {p: 'pending', token: '<?php echo $token; ?>'},
url: URL,
success: function (msg) {
var obj = JSON.parse(msg);
console.log(obj);
var myhtml = '';
if (obj.st == 'ok') {
myhtml += '<ul class="nav nav-pills flex-column">';
for (i=1; i<=Object.keys(obj.content).length; i++) {
myhtml += '<li class="nav-item"><a href="/wms/sign/list.php?system_id='+obj.content[i].sid+'&flow_id='+obj.content[i].fid+'&function_name=show&token=<?php echo $token; ?>" class="nav-link" target="_parent">'+obj.content[i].sname+' > '+obj.content[i].fname+'('+obj.content[i].cnt+')</a></li>';
}
if (Object.keys(obj.content).length == 6) {
myhtml += '<li class="nav-item"><a href="/wms/sign/list.php?function_name=show&token=<?php echo $token; ?>" class="nav-link" target="_parent">.... 顯示更多</a></li>';
}
myhtml += '</ul>';
$('.card-body').empty().append(myhtml);
}
}
})
}
</script>
</body>
<?php
$token = $_REQUEST["token"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
<title>待我簽核</title>
<link rel="stylesheet" href="css/plugins/fontawesome-free/css/all.min.css">
<link rel="stylesheet" href="css/dist/css/adminlte.min.css">
<script src="../css/jquery.min.js"></script>
<script src="../css/bootstrap.min.js"></script>
<style>
.content-wrapper {
background-color: #fff;
}
.col-lg-6 {
padding: 8px 0 0 0 !important;
}
.card {
height: 90vh;
line-height: 14 px;
font-size: 14px;
}
.card-header {
background-color: #f4f6f9;
padding-left: 16px;
}
.card-body ol {
font-size: 14px;
margin-left: -30px;
}
.nav-pills .nav-link {
color: #446887;
}
h5 svg {
vertical-align: baseline;
}
h5 a {
color: #000;
}
@media screen and (max-width: 992px) {
.card {
height: 95vh;
}
}
</style>
</head>
<body>
<div class="wrapper">
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Main content -->
<div class="content">
<div class="container">
<div class="row">
<!-- /.col-md-6 -->
<div class="col-lg-6">
<div class="card">
<div class="card-header">
<h5 class="card-title m-0"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
<path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z" />
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z" />
</svg>
<a href="/wms/sign/list.php?function_name=show&token=<?php echo $token; ?>" target="_parent">待我簽核</a>
</h5>
</div>
<div class="card-body p-0">
Loading...
</div>
</div>
</div>
<!-- /.col-md-6 -->
</div>
<!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
</div>
<script>
$(document).ready(function() {
here();
});
function here() {
var URL = 'api_getdata.php';
$.ajax({
type: "GET",
data: {
p: 'pending',
token: '<?php echo $token; ?>'
},
url: URL,
success: function(msg) {
var obj = JSON.parse(msg);
console.log(msg);
var myhtml = '';
if (obj.st == 'ok') {
myhtml += '<ul class="nav nav-pills flex-column">';
for (i = 1; i <= Object.keys(obj.content).length; i++) {
if (obj.content[i].fname == '新梯價審流程') {
myhtml += '<li class="nav-item"><a href="/wms/mkt/pricereview-index.php?system_id=' + obj.content[i].sid + '&flow_id=' + obj.content[i].fid + '&function_name=show&token=<?php echo $token; ?>" class="nav-link" target="_parent">' + obj.content[i].sname + ' > ' + obj.content[i].fname + '(' + obj.content[i].cnt + ')</a></li>';
} else if (obj.content[i].fname == '汰改價審流程') {
myhtml += '<li class="nav-item"><a href="/wms/mkt/pricereview_renovate-index.php?system_id=' + obj.content[i].sid + '&flow_id=' + obj.content[i].fid + '&function_name=show&token=<?php echo $token; ?>" class="nav-link" target="_parent">' + obj.content[i].sname + ' > ' + obj.content[i].fname + '(' + obj.content[i].cnt + ')</a></li>';
} else if (obj.content[i].fname == '契约價審流程') {
myhtml += '<li class="nav-item"><a href="/wms/cont/sign_list.php?system_id=' + obj.content[i].sid + '&flow_id=' + obj.content[i].fid + '&function_name=show&token=<?php echo $token; ?>" class="nav-link" target="_parent">' + obj.content[i].sname + ' > ' + obj.content[i].fname + '(' + obj.content[i].cnt + ')</a></li>';
} else {
myhtml += '<li class="nav-item"><a href="/wms/sign/list.php?system_id=' + obj.content[i].sid + '&flow_id=' + obj.content[i].fid + '&function_name=show&token=<?php echo $token; ?>" class="nav-link" target="_parent">' + obj.content[i].sname + ' > ' + obj.content[i].fname + '(' + obj.content[i].cnt + ')</a></li>';
}
}
if (Object.keys(obj.content).length == 6) {
myhtml += '<li class="nav-item"><a href="/wms/sign/list.php?function_name=show&token=<?php echo $token; ?>" class="nav-link" target="_parent">.... 顯示更多</a></li>';
}
myhtml += '</ul>';
$('.card-body').empty().append(myhtml);
}
}
})
}
</script>
</body>
</html>

40
wms/fun_global.php

@ -91,20 +91,28 @@ function pricereview_class($rate, $user_id, &$ret = [], $special_fee)
$res = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($res)) {
if ($row["manager"] == "M0001") return; // 董事長略過
if ($row["manager"] != "M0060" && $row["manager"] != "M0006" && $row["manager"] != "M0008") {
$ret[1] = $row["manager"] . ",,";
pricereview_class($rate, $row["manager"], $ret, $special_fee);
if ($user_id == 'TEST01') {
$ret[1] = "test04,,";
$ret[2] = "test02,,";
$ret[3] = "test03,,";
$ret[4] = "test05,,";
return $ret;
} else {
$ret[2] = "M0175,,<##>M0107,,"; // 業務部專員:M0024許伃廷、M0107許紓晴 M0175陳君敏 (第2關有多位審核人)
$ret[3] = "M0060,,"; // 業務協理
if ($rate < 80 || $special_fee > 0) {
$ret[4] = "M0006,,"; // 總經理
if ($row["manager"] != "M0060" && $row["manager"] != "M0006" && $row["manager"] != "M0008") {
$ret[1] = $row["manager"] . ",,";
pricereview_class($rate, $row["manager"], $ret, $special_fee);
} else {
$ret[2] = "M0024,,<##>M0107,,"; // 業務部專員:M0024許伃廷、M0107許紓晴(第2關有多位審核人)
$ret[3] = "M0060,,"; // 業務協理
if ($rate < 80 || $special_fee > 0) {
$ret[4] = "M0006,,"; // 總經理
}
}
return $ret;
}
}
mysqli_free_result($res);
return $ret;
}
/**
* 汰改(契約)價審簽核順位
@ -122,10 +130,18 @@ function pricereview_renovate_class($rate, $user_id, $renovate_flag)
$res = mysqli_query($link, $sql);
if ($row = mysqli_fetch_assoc($res)) {
if ($row["manager"] == "M0001") return; // 董事長略過
if ($row["manager"] != "M0060" && $row["manager"] != "M0006" && $row["manager"] != "M0008") {
$ret[1] = $row["manager"];
if ($row["manager"] == "TEST04" || $user_id = 'TEST01') {
$ret[1] = "test04,,";
$ret[2] = "test02,,";
$ret[3] = "test03,,";
$ret[4] = "test05,,";
return $ret;
} else {
$ret[1] = $user_id;
if ($row["manager"] != "M0060" && $row["manager"] != "M0006" && $row["manager"] != "M0008") {
$ret[1] = $row["manager"];
} else {
$ret[1] = $user_id;
}
}
}
$ret[1] = "M0029";

65
wms/mkt/pricereview-check.php

@ -58,7 +58,7 @@ foreach ($res as $data) {
mysqli_free_result($res_a);
// 瀏覽MI權限
$depart_id = accountidToDepartId($user_id);
if ($depart_id == "320" || $depart_id == "321" || $depart_id == "20") $viewmi = 1;
if ($depart_id == "320" || $depart_id == "321" || $depart_id == "20" || $user_id == 'TEST04') $viewmi = 1;
else $viewmi = 0;
$sql = "select * from pricereview_sign where mid = '$id'";
@ -68,22 +68,26 @@ foreach ($res as $data) {
if (!empty($row_s["sign1"])) list($person1, $status1, $dtte1) = explode(",", $row_s["sign1"]);
else $person1 = $status1 = $dtte1 = "";
if (!empty($row_s["sign2"])) {
if ($st == 2 && (preg_match("/Y/", $row_s["sign2"]) || preg_match("/N/", $row_s["sign2"]))) {
echo "<script>";
echo "alert('請勿重覆審核!');";
echo "location.href='pricereview-index.php?function_name=pricereview&" . $token_link . "';";
echo "</script>";
exit;
}
$sign2_arr = explode("<##>", $row_s["sign2"]); // M0024,,<##>M0175,,
$person2_arr = [];
foreach ($sign2_arr as $v) {
list($person2, $status2, $dtte2) = explode(",", $v);
if (strlen($v) == 7) { // 未審
$person2_arr[] = $person2;
} else {
unset($person2_arr);
break;
if ($user_id == "TEST02") {
list($person2, $status2, $dtte2) = explode(",", $row_s["sign2"]);
} else {
if ($st == 2 && (preg_match("/Y/", $row_s["sign2"]) || preg_match("/N/", $row_s["sign2"]))) {
echo "<script>";
echo "alert('請勿重覆審核!');";
echo "location.href='pricereview-index.php?function_name=pricereview&" . $token_link . "';";
echo "</script>";
exit;
}
$sign2_arr = explode("<##>", $row_s["sign2"]); // M0024,,<##>M0175,,
$person2_arr = [];
foreach ($sign2_arr as $v) {
list($person2, $status2, $dtte2) = explode(",", $v);
if (strlen($v) == 7) { // 未審
$person2_arr[] = $person2;
} else {
unset($person2_arr);
break;
}
}
}
} else $person2 = $status2 = $dtte2 = "";
@ -118,13 +122,13 @@ foreach ($res as $data) {
if ($st == 1 && ($person1 == $user_id) && ($status1 == "") || $user_id == 'TEST04') {
$sign_on = 1;
}
if ($st == 2 && ($person2 == $user_id || (isset($person2_arr) && in_array($user_id, $person2_arr))) && ($status2 == "")) {
if ($st == 2 && ($person2 == $user_id || (isset($person2_arr) && in_array($user_id, $person2_arr))) && ($status2 == "") || $user_id == 'TEST02') {
$sign_on = 1;
}
if ($st == 3 && ($person3 == $user_id) && ($status3 == "")) {
if ($st == 3 && ($person3 == $user_id) && ($status3 == "") || $user_id == 'TEST03') {
$sign_on = 1;
}
if ($st == 4 && ($person4 == $user_id) && ($status4 == "")) {
if ($st == 4 && ($person4 == $user_id) && ($status4 == "") || $user_id == 'TEST05') {
$sign_on = 1;
}
// $sign_total=關卡數
@ -254,6 +258,7 @@ foreach ($res as $data) {
function getMI(id) {
var formdata = new FormData();
formdata.append('pa', id);
// formdata.append('user_id', <?= $user_id ?>);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
@ -286,12 +291,12 @@ foreach ($res as $data) {
mihtml += "<h5>OPTION</h5>";
console.log(data.content[k]);
Object.keys(data.content[k][14]).forEach(function(m) {
if(data.content[k][14][m][0] != '') {
if (data.content[k][14][m][0] != '') {
mihtml += "<li>" + data.content[k][14][m][0] + ":" + commafy(data.content[k][14][m][1]) + "</li>";
}
});
Object.keys(data.content[k][16]).forEach(function(m) {
if(data.content[k][16][m][0] != ''){
if (data.content[k][16][m][0] != '') {
mihtml += "<li>" + data.content[k][16][m][0] + ":" + commafy(data.content[k][16][m][1]) + "</li>";
}
});
@ -556,7 +561,7 @@ foreach ($res as $data) {
$item_amt_B_all = 0;
$total_qty = 0;
foreach ($option_arr as $item_no => $val) {
if($val['item_qty'] <= 0){
if ($val['item_qty'] <= 0) {
continue;
}
$total_qty = $total_qty + $val['item_qty'];
@ -575,11 +580,11 @@ foreach ($res as $data) {
$idx++;
}
?>
<?php if($total_qty > 0): ?>
<tr>
<td colspan="4">小計</td>
<td colspan="3"><input type="text" name="option_amt" id="option_amt" class="form-control dollar-right" size="8" value="<?= number_format($item_amt_B_all); ?>"></td>
</tr>
<?php if ($total_qty > 0) : ?>
<tr>
<td colspan="4">小計</td>
<td colspan="3"><input type="text" name="option_amt" id="option_amt" class="form-control dollar-right" size="8" value="<?= number_format($item_amt_B_all); ?>"></td>
</tr>
<?php endif; ?>
</tbody>
</table>
@ -940,7 +945,7 @@ foreach ($res as $data) {
<li>營業權限85%以上;85-80%呈至區處長審核;80%以下呈至總經理審核。</li>
</ul>
</div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
@ -1016,7 +1021,7 @@ foreach ($res as $data) {
<input type="text" name="checker" id="checker" value="<?= $user_id; ?>" readonly>
<button type="submit" name="status" id="status_n" value="N" onclick="if (!confirm('確定不同意?')) return false;"><?php echo ($sign_total == $st) ? "結案(不同意)" : "不同意(退回)"; ?></button>
<button type="submit" name="status" id="status_y" value="Y" onclick="if (!confirm('確定同意?')) return false;">同意(上呈)</button>
<?php if ($st == 3) : ?>
<?php if ($st == 3 || $st == 4) : ?>
<button type="submit" name="status" id="status_yy" value="YY" onclick="if (!confirm('確定同意?')) return false;">同意(結案)</button>
<?php endif; ?>
<?php } else { ?>

75
wms/mkt/pricereview-index.php

@ -5,14 +5,67 @@ include "../header.php";
$accountname_arr = accountid2name();
$status_arr = ["Y1" => "暫存", "YS" => "簽核中", "YY" => "結案同意", "YN" => "結案不同意"];
// $pricereviewID = $_GET['id'];
// 設置一個空陣列來放資料
// 從待我簽核進來
if (!empty($_GET['system_id']) && !empty($_GET['flow_id'])) {
$system_id = $_SERVER['REQUEST_METHOD'] == 'GET' ? @$_GET['system_id'] : @$_POST['system_id'];
$where_system_id = " and a.system_id like '" . $system_id . "%'";
$flow_id = $_SERVER['REQUEST_METHOD'] == 'GET' ? @$_GET['flow_id'] : @$_POST['flow_id'];
$where_flow_id = " and b.flow_id like '" . $flow_id . "%'";
$sql_get = "SELECT d.form_id,c.form_key, a.system_id,b.flow_id ,a.system_name,c.current_assigner,
concat(c.current_assigner ,'-',f_return_name(c.current_assigner)) current_assigner_name ,
flow_name,c.update_date ,c.create_date,b.path,d.flow_code FROM system_main a,flow_main b ,subflow
c,flow d
WHERE a.system_id=b.system_id
AND b.flow_id=d.flow_id
AND c.current_assigner='$user_id'
AND d.flow_id=b.flow_id
AND c.form_key=d.form_key
$where_system_id
$where_flow_id
";
// echo '<pre>';
// print_r($sql_get);
// echo '</pre>';
$result = mysqli_query($link, $sql_get);
if ($result == false) {
die(mysqli_error($link));
}
$res_get = mysqli_fetch_all(mysqli_query($link, $sql_get), MYSQLI_ASSOC);
foreach ($res_get as $key => $data) {
// 結案隱藏
if ($data['flow_code'] !== 'Z') {
$test = $data['form_id'];
// $sql = "SELECT mid FROM pricereview_sign WHERE id = $test";
// $result = mysqli_fetch_all(mysqli_query($link, $sql), MYSQLI_ASSOC);
// echo '<pre>';
// print_r($result);
// echo '</pre>';
$id[] = $test;
}
}
$inClause = implode(',', $id);
// echo '<pre>';
// print_r($inClause);
// echo '</pre>';
}
$data = array();
// sql語法存在變數中
$sql_cmd = sql_myself($user_id, "pricereview_main .creater");
$sql = "select pricereview_main.*, contract_new_apply.status as applystatus, contract_new_apply.progress as applyprogress from pricereview_main left join contract_new_apply on pricereview_main.id = contract_new_apply.mid where pricereview_main.creater = '$user_id' and pricereview_main.status like 'Y%' and pricereview_main.ekind = '新梯' order by pricereview_main.id";
// M0024許伃廷,M0107許紓晴,,M0175陳君敏,M0189權限全開
if ($user_id == "M0024" || $user_id == 'M0026' || $user_id == "M0107" || $user_id == "M0174" || $user_id == "M0175" ||$user_id == "M0189" || $user_id == "TEST01" || $user_id == "TEST02" || $user_id == "TEST03" || $user_id == "TEST04") {
if ($user_id == "M0024" || $user_id == 'M0026' || $user_id == "M0107" || $user_id == "M0174" || $user_id == "M0175" || $user_id == "M0189" || $user_id == "TEST01" || $user_id == "TEST02" || $user_id == "TEST03" || $user_id == "TEST04") {
$sql_cmd = "where create_at >= '2023-01-01 00:00:00'";
$sql = "select pricereview_main.*, contract_new_apply.status as applystatus, contract_new_apply.progress as applyprogress from pricereview_main left join contract_new_apply on pricereview_main.id = contract_new_apply.mid where create_at >= '2023-01-01 00:00:00' and pricereview_main.status like 'Y%' and pricereview_main.ekind = '新梯' order by pricereview_main.id";
}
@ -23,6 +76,14 @@ if ($user_id == "M0060") {
if (empty($sql_cmd)) $sql = "select pricereview_main.*, contract_new_apply.status as applystatus, contract_new_apply.progress as applyprogress from pricereview_main left join contract_new_apply on pricereview_main.id = contract_new_apply.mid where pricereview_main.status like 'Y%' and pricereview_main.ekind = '新梯' order by pricereview_main.id";
else $sql = "select pricereview_main.*, contract_new_apply.status as applystatus, contract_new_apply.progress as applyprogress from pricereview_main left join contract_new_apply on contract_new_apply.mid = pricereview_main.id $sql_cmd and pricereview_main.status like 'Y%' and pricereview_main.ekind = '新梯' order by pricereview_main.id";
if (!empty($res_get)) {
$sql = "SELECT pricereview_main.*,contract_new_apply.status as applystatus, contract_new_apply.progress as applyprogress
from pricereview_main
left join contract_new_apply on contract_new_apply.mid = pricereview_main.id
$sql_cmd and pricereview_main.status like 'Y%' and pricereview_main.id IN ($inClause) AND pricereview_main.ekind = '新梯' order by pricereview_main.id";
// echo $sql;
}
$data = mysqli_query($link, $sql);
$para = "function_name=pricereview&" . $token_link;
@ -162,6 +223,7 @@ if ($data) :
<tbody>
<?php
foreach ($data as $data) :
$sign1 = $sign2 = $sign3 = $sign4 = "";
$oneself = ($data["creater"] == $user_id) ? 1 : 0; // 是否為營業員本人
// 簽核狀況
@ -338,7 +400,7 @@ if ($data) :
elseif ($ustatus == "N") $str = "<span class=\"glyphicon glyphicon-ban-circle\" title=\"不同意\"></span>";
$str .= "<br>" . $accountname_arr[$uperson] . "<br>" . $udtte;
} else {
if (($data["status"] == "YS") && ($ss_arr["sign_st"] == 2) && (in_array($user_id, $ss_arr["sign_nt"]))) {
if (($data["status"] == "YS") && ($ss_arr["sign_st"] == 2) && (in_array($user_id, $ss_arr["sign_nt"])) || $user_id == 'TEST02') {
$str = "<span class=\"glyphicon glyphicon-user\"></span>";
$str = "待簽核";
$str = "<a href=\"pricereview-check.php?st=2&id=" . $data["id"] . "&" . $para . "\" class=\"btn btn-primary btn-sm\">" . $str . "</a>";
@ -383,13 +445,16 @@ if ($data) :
<td>
<?php
$str = $uperson = $ustatus = $udtte = "";
if (!empty($sign3)) list($uperson, $ustatus, $udtte) = explode(",", $sign3);
if ($ustatus) {
if ($ustatus == "Y" || $ustatus == "YY") $str = "<span class=\"glyphicon glyphicon-ok\" title=\"同意\"></span>";
elseif ($ustatus == "N") $str = "<span class=\"glyphicon glyphicon-ban-circle\" title=\"不同意\"></span>";
$str .= "<br>" . $accountname_arr[$uperson] . "<br>" . $udtte;
} else {
if (($data["status"] == "YS") && ($ss_arr["sign_st"] == 3) && (in_array($user_id, $ss_arr["sign_nt"]))) {
// if ($user_id == 'test03') {
if (($data["status"] == "YS") && ($ss_arr["sign_st"] == 3) && (in_array($user_id, $ss_arr["sign_nt"])) || $user_id == 'TEST03') {
$str = "<span class=\"glyphicon glyphicon-user\"></span>";
$str = "待簽核";
$str = "<a href=\"pricereview-check.php?st=3&id=" . $data["id"] . "&" . $para . "\" class=\"btn btn-primary btn-sm\">" . $str . "</a>";
@ -435,7 +500,7 @@ if ($data) :
elseif ($ustatus == "N") $str = "<span class=\"glyphicon glyphicon-ban-circle\" title=\"不同意\"></span>";
$str .= "<br>" . $accountname_arr[$uperson] . "<br>" . $udtte;
} else {
if (($data["status"] == "YS") && ($ss_arr["sign_st"] == 4) && (in_array($user_id, $ss_arr["sign_nt"]))) {
if (($data["status"] == "YS") && ($ss_arr["sign_st"] == 4) && (in_array($user_id, $ss_arr["sign_nt"])) || $user_id == 'TEST05') {
$str = "<span class=\"glyphicon glyphicon-user\"></span>";
$str = "待簽核";
$str = "<a href=\"pricereview-check.php?st=4&id=" . $data["id"] . "&" . $para . "\" class=\"btn btn-primary btn-sm\">" . $str . "</a>";

59
wms/mkt/pricereview-record-check.php

@ -25,21 +25,25 @@ if (isset($_POST['status'])) {
if ($st == 1) {
$sql = "sign1 = '$checker,$status,$check_date', sign1_note = '$sign_note'";
} elseif ($st == 2) {
if ($sign_now > 1) {
echo "<script>";
echo "alert('請勿重覆審核。');";
echo "location.href='pricereview-index.php?function_name=pricereview&".$token_link."';";
echo "</script>";
exit;
}
$sign2_ori_arr = explode("<##>", $sign2_ori);
$sign2_upd_arr = [];
foreach ($sign2_ori_arr as $k => $v) {
list($a, $b, $c) = explode(",", $v);
if ($a == $checker) $sign2_upd_arr[$k] = $checker.",".$status.",".$check_date;
else $sign2_upd_arr[$k] = $v;
if ($user_id == 'TEST02') {
$sql = "sign2 = '$checker,$status,$check_date', sign2_note = '$sign_note'";
} else {
if ($sign_now > 1) {
echo "<script>";
echo "alert('請勿重覆審核。');";
echo "location.href='pricereview-index.php?function_name=pricereview&" . $token_link . "';";
echo "</script>";
exit;
}
$sign2_ori_arr = explode("<##>", $sign2_ori);
$sign2_upd_arr = [];
foreach ($sign2_ori_arr as $k => $v) {
list($a, $b, $c) = explode(",", $v);
if ($a == $checker) $sign2_upd_arr[$k] = $checker . "," . $status . "," . $check_date;
else $sign2_upd_arr[$k] = $v;
}
$sql = "sign2 = '" . implode("<##>", $sign2_upd_arr) . "', sign2_note = '$sign_note'";
}
$sql = "sign2 = '".implode("<##>", $sign2_upd_arr)."', sign2_note = '$sign_note'";
} elseif ($st == 3) {
$sql = "sign3 = '$checker,$status,$check_date', sign3_note = '$sign_note'";
} else {
@ -48,7 +52,7 @@ if (isset($_POST['status'])) {
if ($status == "N") {
$sql2 .= "status = 'YN'";
$end_flow = 1;
} elseif ($sign_total == ($sign_now+1)) {
} elseif ($sign_total == ($sign_now + 1)) {
if ($user_id == "M0006") {
$final_price_total = str_replace(",", "", $final_price_total);
if ($final_price_total > 0) {
@ -60,11 +64,10 @@ if (isset($_POST['status'])) {
$sql2 .= "status = 'YY'";
}
$end_flow = 1;
}elseif($status == 'YY'){
} elseif ($status == 'YY') {
$sql2 .= "status = 'YY'";
$end_flow = 1;
}
else {
} else {
$do_assign = 1;
}
if ($item_no_all) {
@ -106,9 +109,9 @@ if (isset($_POST['status'])) {
$next_signer[] = substr($v, 0, 5);
}
} elseif (strlen($row[1]) == 8) {
$next_signer = substr(str_replace(",","",$row[1]), 1);
$next_signer = substr(str_replace(",", "", $row[1]), 1);
} elseif (strlen($row[2]) == 8) {
$next_signer = substr(str_replace(",","",$row[2]), 1);
$next_signer = substr(str_replace(",", "", $row[2]), 1);
}
do_assign("prm01", $id, $contractno_h, $next_signer, $st);
@ -117,11 +120,11 @@ if (isset($_POST['status'])) {
$ret = accountid2email($next_signer);
if (!empty($ret)) {
foreach ($ret as $uid => $uemail) {
$mail_list[] = [$uid, $uemail];
$mail_list[] = [$uid, $uemail];
}
include dirname(__DIR__)."/class/Cmail.php";
include dirname(__DIR__) . "/class/Cmail.php";
$sendmail = new Cmail;
$title = "【新梯價審通知】卷號:".$contractno_h;
$title = "【新梯價審通知】卷號:" . $contractno_h;
$content = "<p>您有待簽核案件,請至<a href=\"http://oa.masada.com.tw\">客戶管理 > 價格審查_新梯</a>,點擊「待簽核」進行作業,謝謝!</p>";
//print_r($mail_list);
$sendmail->sendx($title, $content, $mail_list);
@ -131,13 +134,13 @@ if (isset($_POST['status'])) {
end_flow("prm", "prm01", $id, $contractno_h);
}
}
mysqli_close($link);
echo "<script type ='text/JavaScript'>";
if($fromsign == 1){
echo "location.href='../sign/list.php?system_id=prm&flow_id=prm01&function_name=show&".$token_link."';";
}else{
echo "location.href='pricereview-check.php?id=".$id."&function_name=pricereview&".$token_link."';";
if ($fromsign == 1) {
echo "location.href='../sign/list.php?system_id=prm&flow_id=prm01&function_name=show&" . $token_link . "';";
} else {
echo "location.href='pricereview-check.php?id=" . $id . "&function_name=pricereview&" . $token_link . "';";
}
echo "</script>";
}

117
wms/mkt/pricereview_mi-api.php

@ -1,4 +1,5 @@
<?php
/**
* by單台計算MI
* @url /wms/mkt/pricereview_mi-api.php
@ -22,8 +23,9 @@ ob_end_clean();
$rarr = array('st' => 'ok', 'err' => '');
try {
if (empty($_POST) || empty($_POST["pa"])) throw new \Exception("parameter empty");
if (empty($_POST) || empty($_POST["pa"])) throw new \Exception("parameter empty");
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
foreach ($_POST as $k => $v) {
$$k = htmlspecialchars(stripslashes(trim($v)));
}
@ -33,17 +35,19 @@ try {
if (strpos($pa, ",")) list($id, $opt) = explode(",", $pa);
else $id = $pa;
$person2weight_arr = [ "6" => "450",
"8" => "550",
"9" => "600",
"10" => "700",
"11" => "750",
"12" => "800",
"13" => "900",
"15" => "1000",
"17" => "1150",
"20" => "1350",
"24" => "1600"];
$person2weight_arr = [
"6" => "450",
"8" => "550",
"9" => "600",
"10" => "700",
"11" => "750",
"12" => "800",
"13" => "900",
"15" => "1000",
"17" => "1150",
"20" => "1350",
"24" => "1600"
];
$elev_arr = $elev_opt_arr = $pv_arr = $opt_elev_arr = $mi_arr = [];
$i = $weight = $elev_qty_all = 0;
@ -84,7 +88,7 @@ try {
$special_fee = $row[0];
mysqli_free_result($res);
$specarr[0] = "服務費";
$specarr[1] = round($special_fee/$elev_qty_all, 0);
$specarr[1] = round($special_fee / $elev_qty_all, 0);
// 電梯所屬OPTION
$opt_sel_id_arr = [];
@ -102,7 +106,7 @@ try {
$opt_sel_id_arr[] = $row[0];
}
}
/*
$pv_arr["price_id"] = $row[1];
$pv_arr["item_spec"] = $row[2];
@ -114,7 +118,6 @@ try {
$elev_opt_arr[$v][] = $pv_arr;
}
*/
}
mysqli_free_result($res);
$opt_nosel_id_arr = array_diff(array_keys($opt_elev_arr), $opt_sel_id_arr);
@ -143,7 +146,7 @@ try {
$res = mysqli_query($link, $sql);
while ($row = mysqli_fetch_row($res)) {
$exarr[$j][0] = $row[1];
$exarr[$j][1] = round($row[2]/$elev_qty_all, 0);
$exarr[$j][1] = round($row[2] / $elev_qty_all, 0);
$ex_fee += $exarr[$j][1];
$j++;
}
@ -155,57 +158,57 @@ try {
$sql3 = "select item_spec, item_qty, note from pricereview_item where mid = '$id' and item_group = 'C'";
$res_i = mysqli_query($link, $sql3);
while ($row_i = mysqli_fetch_assoc($res_i)) {
$sql4 = "select min_floors, price, price_plus from dismantle_mi_option where spec = '".$row_i["item_spec"]."' ";
$sql4 = "select min_floors, price, price_plus from dismantle_mi_option where spec = '" . $row_i["item_spec"] . "' ";
$sql4 .= "and version_date = '2023-09-04'";
$sql4 .= "and ($row_i[note] between min_floors and max_floors) ";
$res_d = mysqli_query($link, $sql4);
if ($row_d = mysqli_fetch_assoc($res_d)) {
$dismantle_amt += ($row_d["price"] + $row_d["price_plus"]*($row_i["note"] - $row_d["min_floors"]))*$row_i["item_qty"];
$polishing_amt += 3000*$row_i["note"];
$dismantle_amt += ($row_d["price"] + $row_d["price_plus"] * ($row_i["note"] - $row_d["min_floors"])) * $row_i["item_qty"];
$polishing_amt += 3000 * $row_i["note"];
}
mysqli_free_result($res_d);
}
mysqli_free_result($res_i);
}
$dismantle_fee = round($dismantle_amt/$elev_qty_all, 0);
$polishing_fee = round($polishing_amt/$elev_qty_all, 0);
$dismantle_fee = round($dismantle_amt / $elev_qty_all, 0);
$polishing_fee = round($polishing_amt / $elev_qty_all, 0);
//print_r($elev_arr);
//print_r($opt_elev_arr);
//print_r($opt_nosel_id_arr);
//print_r($mn_elev_arr);
//print_r($ex_arr);exit;
foreach ($elev_arr as $item_no => $v) {
// 電梯MI
$sql2 = "select o.*, r.* from elevator_mi_option o, elevator_quotation_rule r ";
$sql2 .= "where o.quotation_no = r.quotation_no and o.elevator_type = '".$v['etype']."' ";
$sql2 .= "where o.quotation_no = r.quotation_no and o.elevator_type = '" . $v['etype'] . "' ";
$sql2 .= "and ($v[item_weight] between o.min_weight and o.max_weight) ";
$sql2 .= "and ($v[floors] between o.min_floors and o.max_floors) ";
$sql2 .= "and ($v[speed] between o.min_speed and o.max_speed) ";
if ($v["etype"] == "MAQ100" || $v["etype"] == "MAP100") {
$sql2 .= "and (o.model_no = '".$v["persons"]."') ";
$sql2 .= "and (o.model_no = '" . $v["persons"] . "') ";
}
$res_e = mysqli_query($link, $sql2);
if ($row_e = mysqli_fetch_assoc($res_e)) {
// 加價:先不納入
$row_e["option_price"] = 0;
// 基准采购成本+±1停材料费+设计费+出口费用
$part1 = $row_e["purchase_cost"]+($v["floors"]-$row_e["base_floor"])*$row_e["material_plus"]+$row_e["design"]*$row_e["design_hour"]+$row_e["export_fee"];
$part1 = $row_e["purchase_cost"] + ($v["floors"] - $row_e["base_floor"]) * $row_e["material_plus"] + $row_e["design"] * $row_e["design_hour"] + $row_e["export_fee"];
// 利潤
$profit = round($part1*$row_e["profit"]+$row_e["equip_profit"], 0);
$profit = round($part1 * $row_e["profit"] + $row_e["equip_profit"], 0);
// 設備
$equipment_ntd = round(($part1+$profit)*$row_e["equipment"], 0);
$equipment_ntd = round(($part1 + $profit) * $row_e["equipment"], 0);
// 報關+運輸
$customs = round($equipment_ntd*$row_e["shipping"], 0)+$row_e["customs_shipping"];
$customs = round($equipment_ntd * $row_e["shipping"], 0) + $row_e["customs_shipping"];
// 安裝基價
$install_base = $row_e["install_price"]+$row_e["trial_price"]+$row_e["install_coef"]*$row_e["install_plus"]+$row_e["trial_coef"]*$row_e["trial_plus"];
$install_base = $row_e["install_price"] + $row_e["trial_price"] + $row_e["install_coef"] * $row_e["install_plus"] + $row_e["trial_coef"] * $row_e["trial_plus"];
// 安裝成本
$install_price = round($install_base+($row_e["install_plus"]+$row_e["trial_plus"])*($v["floors"]-$row_e["base_floor"]), 0);
$install_price = round($install_base + ($row_e["install_plus"] + $row_e["trial_plus"]) * ($v["floors"] - $row_e["base_floor"]), 0);
// 起吊+木箱+耗材
$woods = $row_e["crane"]+$row_e["wooden_box"]+$row_e["consume"]+$row_e["consumables"];
$woods = $row_e["crane"] + $row_e["wooden_box"] + $row_e["consume"] + $row_e["consumables"];
// MI
$mi = $equipment_ntd+$customs+$row_e["unloading"]+$row_e["transport_site"]+$install_price+$row_e["free1y"]+$woods+$row_e["option_price"];
$mi = $equipment_ntd + $customs + $row_e["unloading"] + $row_e["transport_site"] + $install_price + $row_e["free1y"] + $woods + $row_e["option_price"];
/*
$install_price = $row_e["install_price"] + $row_e["install_plus"]*($floors - $row_e["min_floors"]); // 安裝
@ -261,25 +264,26 @@ try {
$sql4 = "select o.base_floor, o.base_floor_plus, o.price, r.equipment, p.price 'OP' ";
$sql4 .= "from option_mi o, elevator_quotation_rule r, option_price p ";
$sql4 .= "where o.quotation_no = r.quotation_no and o.option_price_id = p.id ";
$sql4 .= "and o.option_price_id = ".$opt_elev_arr[$val]["price_id"]." ";
$sql4 .= "and ($v[item_weight] between o.min_weight and o.max_weight) and o.open_kind = '".$v["item_op"]."'";
$sql4 .= "and o.option_price_id = " . $opt_elev_arr[$val]["price_id"] . " ";
$sql4 .= "and ($v[item_weight] between o.min_weight and o.max_weight) and o.open_kind = '" . $v["item_op"] . "'";
$res_om = mysqli_query($link, $sql4);
if ($row_om = mysqli_fetch_assoc($res_om)) {
$row_om['price'] = (int)ceil($row_om['price']);
$plus = ($v["floors"] > $row_om["base_floor"]) ? ($v["floors"] - $row_om["base_floor"])*$row_om["base_floor_plus"] : 0;
$plus = ($v["floors"] > $row_om["base_floor"]) ? ($v["floors"] - $row_om["base_floor"]) * $row_om["base_floor_plus"] : 0;
// 特例
if ($opt_elev_arr[$val]["price_id"] == "256" && ($v["floors"] < $row_om["base_floor"])) $row_om["price"] = 9815;
if ($opt_elev_arr[$val]["price_id"] == "266" && $v["floors"] >= 20) $plus += 44.8; // 15层,14.6元/层(19层内,跳20层再追加44.8元)
if ($row_om["price"] == 0) $row_om["price"] = $row_om["OP"]*0.6; // 實體且沒成本的:抓牌價6成
if ($row_om["price"] == 0) $row_om["price"] = $row_om["OP"] * 0.6; // 實體且沒成本的:抓牌價6成
// 含此option的電梯總台數
$myelev_qty = 0;
foreach ($opt_elev_arr[$val]["elev_no"] as $pval) {
$myelev_qty += $elev_arr[$pval]["item_qty"];
}
// 分配:OPTION數量除以電梯總台數
$option_amt = round(0+($row_om["price"]+$plus)*($opt_elev_arr[$val]["item_qty"]/$myelev_qty)*$row_om["equipment"], 0);
$option_amt = round(0 + ($row_om["price"] + $plus) * ($opt_elev_arr[$val]["item_qty"] / $myelev_qty) * $row_om["equipment"], 0);
$option_fee += $option_amt; // option總金額
$oparr[$j][1] = $option_amt;
} else {
$oparr[$j][1] = 0;
@ -301,8 +305,8 @@ try {
$myelev_qty += $elev_arr[$pval]["item_qty"];
}
// 分配:延保總價除以電梯總台數
$mn_amt += round(0+($mn_elev_arr[$val]["item_price_bp"]/$myelev_qty), 0);
$mnarr[$j][0] = $mn_elev_arr[$val]["item_spec"]."保養費";
$mn_amt += round(0 + ($mn_elev_arr[$val]["item_price_bp"] / $myelev_qty), 0);
$mnarr[$j][0] = $mn_elev_arr[$val]["item_spec"] . "保養費";
$mnarr[$j][1] = $mn_amt;
$mn_fee += $mn_amt;
$j++;
@ -338,7 +342,7 @@ try {
*/
// 拆台數
for ($n = 0; $n<$v["item_qty"]; $n++) {
for ($n = 0; $n < $v["item_qty"]; $n++) {
$mi_arr[$i][0] = $mi + $dismantle_fee + $polishing_fee + $option_fee + $ex_fee + $mn_fee;
/*
$mi_arr[$i][1] = $row_e["purchase_cost"];
@ -348,23 +352,23 @@ try {
$mi_arr[$i][5] = $profit_amt;
$mi_arr[$i][6] = $quotation;
*/
$mi_arr[$i][1] = 0+$equipment_ntd;
$mi_arr[$i][2] = 0+$customs;
$mi_arr[$i][3] = 0+$row_e["unloading"];
$mi_arr[$i][4] = 0+$row_e["transport_site"];
$mi_arr[$i][5] = 0+$install_price;
$mi_arr[$i][6] = 0+$row_e["free1y"];
$mi_arr[$i][7] = 0+$woods;
$mi_arr[$i][1] = 0 + $equipment_ntd;
$mi_arr[$i][2] = 0 + $customs;
$mi_arr[$i][3] = 0 + $row_e["unloading"];
$mi_arr[$i][4] = 0 + $row_e["transport_site"];
$mi_arr[$i][5] = 0 + $install_price;
$mi_arr[$i][6] = 0 + $row_e["free1y"];
$mi_arr[$i][7] = 0 + $woods;
$mi_arr[$i][8] = $row_e["equipment"];
$mi_arr[$i][9] = 0+$row_e["option_price"];
$mi_arr[$i][10] = 0+$dismantle_fee;
$mi_arr[$i][11] = 0+$polishing_fee;
$mi_arr[$i][12] = $mi_arr[$i][1]+$mi_arr[$i][2]+$mi_arr[$i][3]+$mi_arr[$i][4]+$mi_arr[$i][5]+$mi_arr[$i][6]+$mi_arr[$i][7]+$mi_arr[$i][9]+$mi_arr[$i][10]+$mi_arr[$i][11];
$mi_arr[$i][13] = $option_fee+$ex_fee+$mn_fee+$special_fee;
$mi_arr[$i][9] = 0 + $row_e["option_price"];
$mi_arr[$i][10] = 0 + $dismantle_fee;
$mi_arr[$i][11] = 0 + $polishing_fee;
$mi_arr[$i][12] = $mi_arr[$i][1] + $mi_arr[$i][2] + $mi_arr[$i][3] + $mi_arr[$i][4] + $mi_arr[$i][5] + $mi_arr[$i][6] + $mi_arr[$i][7] + $mi_arr[$i][9] + $mi_arr[$i][10] + $mi_arr[$i][11];
$mi_arr[$i][13] = $option_fee + $ex_fee + $mn_fee + $special_fee;
$mi_arr[$i][14] = $oparr;
$mi_arr[$i][15] = 0+$ex_fee;
$mi_arr[$i][15] = 0 + $ex_fee;
$mi_arr[$i][16] = $exarr;
$mi_arr[$i][17] = 0+$mn_fee;
$mi_arr[$i][17] = 0 + $mn_fee;
$mi_arr[$i][18] = $mnarr;
$mi_arr[$i][19] = $specarr;
$i++;
@ -374,11 +378,10 @@ try {
}
$rarr["content"] = $mi_arr;
}catch(\Exception $e) {
} catch (\Exception $e) {
$rarr['st'] = 'err';
$rarr['err'] = $e->getMessage();
}
echo json_encode($rarr, JSON_UNESCAPED_UNICODE);
exit;
?>

58
wms/mkt/pricereview_renovate-index.php

@ -6,6 +6,56 @@ $accountname_arr = accountid2name();
$status_arr = ["Y1" => "暫存", "YS" => "簽核中", "YY" => "結案同意", "YN" => "結案不同意"];
// 待我簽核跳
if (!empty($_GET['system_id']) && !empty($_GET['flow_id'])) {
$system_id = $_SERVER['REQUEST_METHOD'] == 'GET' ? @$_GET['system_id'] : @$_POST['system_id'];
$where_system_id = " and a.system_id like '" . $system_id . "%'";
$flow_id = $_SERVER['REQUEST_METHOD'] == 'GET' ? @$_GET['flow_id'] : @$_POST['flow_id'];
$where_flow_id = " and b.flow_id like '" . $flow_id . "%'";
$sql_get = "SELECT d.form_id,c.form_key, a.system_id,b.flow_id ,a.system_name,c.current_assigner,
concat(c.current_assigner ,'-',f_return_name(c.current_assigner)) current_assigner_name ,
flow_name,c.update_date ,c.create_date,b.path,d.flow_code FROM system_main a,flow_main b ,subflow
c,flow d
WHERE a.system_id=b.system_id
AND b.flow_id=d.flow_id
AND c.current_assigner='$user_id'
AND d.flow_id=b.flow_id
AND c.form_key=d.form_key
$where_system_id
$where_flow_id
";
$result = mysqli_query($link, $sql_get);
if ($result == false) {
die(mysqli_error($link));
}
$res_get = mysqli_fetch_all(mysqli_query($link, $sql_get), MYSQLI_ASSOC);
// echo '<pre>';
// print_r($sql_get);
// echo '</pre>';
foreach ($res_get as $key => $data) {
// 結案隱藏
if ($data['flow_code'] !== 'Z') {
$test = $data['form_id'];
// $sql = "SELECT mid FROM pricereview_sign WHERE id = $test";
// $result = mysqli_fetch_all(mysqli_query($link, $sql), MYSQLI_ASSOC);
// echo '<pre>';
// print_r($result);
// echo '</pre>';
$id[] = $test;
}
}
$inClause = implode(',', $id);
}
// 設置一個空陣列來放資料
$data = array();
// sql語法存在變數中
@ -17,12 +67,18 @@ if ($user_id == "M0024" || $user_id == "M0107" || $user_id == "M0012" || $user_i
if ($user_id == "M0008") {
$sql_cmd = "where creater in (select accountid from account where department_id like '5%')";
}
if (!empty($res_get)) {
$sql_cmd = "where id IN ($inClause)";
}
// if ($user_id == "M0060") {
// $sql_cmd = "where creater in (select accountid from account where (department_id like '3%' or department_id like '5%'))";
// }
if (empty($sql_cmd)) $sql = "select * from pricereview_main where status like 'Y%' and ekind = '汰改' order by id";
else $sql = "select * from pricereview_main $sql_cmd and status like 'Y%' and ekind = '汰改' order by id";
// echo '<pre>';
// print_r($sql);
// echo '</pre>';
$data = mysqli_query($link, $sql);

1
wms/schedule-index.php

@ -39,6 +39,7 @@ if (!empty($sql_cmd2)) {
//$sql = "SELECT * FROM schedule $sql_cmd ORDER BY id";
$sql = "SELECT * FROM schedule $sql_cmd ORDER BY id desc";
$sql = "SELECT * FROM schedule $sql_cmd ORDER BY id desc";
if (!$page_close) $sql .= " limit $page_from, $page_each";
//echo $sql;

43
wms/sign/list.php

@ -73,32 +73,27 @@ $where_system_id = " and a.system_id like '" . $system_id . "%'";
$flow_id = $_SERVER['REQUEST_METHOD'] == 'GET' ? @$_GET['flow_id'] : @$_POST['flow_id'];
$where_flow_id = " and b.flow_id like '" . $flow_id . "%'";
$sql_get = "
select
c.form_key,
a.system_id,
b.flow_id ,
a.system_name,
c.current_assigner,
concat(
c.current_assigner ,
'-',f_return_name(c.current_assigner)
) current_assigner_name ,
flow_name,
c.update_date ,
c.create_date,
b.path,
d.flow_code
from system_main a,flow_main b ,subflow c,flow d
where a.system_id=b.system_id
and b.flow_id=d.flow_id
and c.current_assigner='$user_id'
and d.flow_id=b.flow_id
and c.form_key=d.form_key
$sql_get = "SELECT d.form_id,c.form_key, a.system_id,b.flow_id ,a.system_name,c.current_assigner,
concat(c.current_assigner ,'-',f_return_name(c.current_assigner)) current_assigner_name ,
flow_name,c.update_date ,c.create_date,b.path,d.flow_code FROM system_main a,flow_main b ,subflow
c,flow d
WHERE a.system_id=b.system_id
AND b.flow_id=d.flow_id
AND c.current_assigner='$user_id'
AND d.flow_id=b.flow_id
AND c.form_key=d.form_key
and b.flow_id NOT IN ('wws04')
$where_system_id
$where_flow_id
";
//echo $sql_get;
";
// echo '<pre>';
// print_r($sql_get);
// echo '</pre>';
$result = mysqli_query($link, $sql_get);
if ($result == false) {
die(mysqli_error($link));
}
$res_get = mysqli_fetch_all(mysqli_query($link, $sql_get), MYSQLI_ASSOC);
$system_name_opt = array_map(function ($item) {

Loading…
Cancel
Save