10994015 1 year ago
parent
commit
63b92b471b
  1. 1
      .gitignore
  2. 13
      wms/T8_Authorization_from_bpm.php
  3. 136
      wms/account-receivable-new-index.php
  4. 112
      wms/account-receivable-renovate-index.php
  5. 50320
      wms/account_receivable_sql_file.sql

1
.gitignore

@ -28,3 +28,4 @@ app/account_log/
wms/gary2.php wms/gary2.php
wms/chinese.php wms/chinese.php
phpinfo.php phpinfo.php
wms/account_receivable_sql_file.sql

13
wms/T8_Authorization_from_bpm.php

@ -5,7 +5,8 @@
// echo $validation = get_Auth($user_id, $user_password); // echo $validation = get_Auth($user_id, $user_password);
function get_Auth($user_id = "M0000", $user_password = "M012290493119") // function get_Auth($user_id = "M0000", $user_password = "M012290493119")
function get_Auth($user_id = "ADMIN", $user_password = "chi")
{ {
$currentTime = time(); $currentTime = time();
$twoMinutesLater = $currentTime - (2 * 60); $twoMinutesLater = $currentTime - (2 * 60);
@ -13,12 +14,14 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119")
// $now = gmdate("YmdHis"); // $now = gmdate("YmdHis");
$now = gmdate("YmdHis", strtotime("-2 minutes")); $now = gmdate("YmdHis", strtotime("-2 minutes"));
$data = "$user_id." . $now; $data = "$user_id." . $now;
$sign = hash_hmac('SHA256', $data, 'A21181F1EE4966D3', false); // $sign = hash_hmac('SHA256', $data, 'A21181F1EE4966D3', false);
$sign = hash_hmac('SHA256', $data, 'A733DAD19527399E', false);
// echo $sign; // echo $sign;
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'; // $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
$apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; // $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; -----
$apiurl = 'http://101.132.66.206:880/twWebAPI/GetAuth';
// $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth'; // $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth';
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'; // $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
@ -28,7 +31,7 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119")
"Pwd: $user_password", "Pwd: $user_password",
"TimestampUTC: $now", "TimestampUTC: $now",
"Sign: $sign", "Sign: $sign",
"GroupId:TEST" "GroupId:ceshi"
]; ];
$ch = curl_init(); $ch = curl_init();
@ -51,4 +54,4 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119")
curl_close($ch); curl_close($ch);
} }
// $data = []; // $data = [];
// get_Auth(); get_Auth();

136
wms/account-receivable-new-index.php

@ -169,6 +169,14 @@ $query_contract_budget = $conn->query($sql_contract_budget);
foreach ($query_contract_budget as $contract_budget) { foreach ($query_contract_budget as $contract_budget) {
if (isset($arrayData[$contract_budget['BillNo']])) { if (isset($arrayData[$contract_budget['BillNo']])) {
$arrayData[$contract_budget['BillNo']][$contract_budget['MaterialId']] += $contract_budget['OAmountWithTax']; $arrayData[$contract_budget['BillNo']][$contract_budget['MaterialId']] += $contract_budget['OAmountWithTax'];
// if($contract_budget['BillNo']=='SO20230801002'){
// echo $contract_budget['OAmountWithTax'];
// echo "<br>";
// echo $contract_budget['MaterialId'];
// echo "<br>";
// echo $contract_budget['CU_MaterialId'];
// echo "<br>";
// }
if (isset($arrayData[$contract_budget['BillNo']]['facility']) && isset($arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']])) { if (isset($arrayData[$contract_budget['BillNo']]['facility']) && isset($arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']])) {
$arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']]['total_budget'] += $contract_budget['OAmountWithTax']; $arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']]['total_budget'] += $contract_budget['OAmountWithTax'];
if (isset($arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']][$contract_budget['MaterialId']])) { if (isset($arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']][$contract_budget['MaterialId']])) {
@ -280,6 +288,15 @@ ON d.department_id = tmp2.department_id ";
$wip_array = array(); $wip_array = array();
$query_wip = mysqli_query($link, $sql_wip); $query_wip = mysqli_query($link, $sql_wip);
foreach ($query_wip as $wip) { foreach ($query_wip as $wip) {
$contractno = $wip['contractno'];
switch ($wip['contractno']) {
case 'M231067':
$contractno = 'SO20230801002';
break;
case 'M230947':
$contractno = 'SO20230801001';
break;
}
$wip_array[$wip['facilityno']]['estimated_shipping_date'] = $wip['estimated_shipping_date']; $wip_array[$wip['facilityno']]['estimated_shipping_date'] = $wip['estimated_shipping_date'];
$wip_array[$wip['facilityno']]['real_contract_arrival_date'] = $wip['real_contract_arrival_date']; $wip_array[$wip['facilityno']]['real_contract_arrival_date'] = $wip['real_contract_arrival_date'];
$wip_array[$wip['facilityno']]['real_arrival_date'] = $wip['real_arrival_date']; $wip_array[$wip['facilityno']]['real_arrival_date'] = $wip['real_arrival_date'];
@ -287,31 +304,32 @@ foreach ($query_wip as $wip) {
$wip_array[$wip['facilityno']]['tryrun_end_date'] = $wip['tryrun_end_date']; $wip_array[$wip['facilityno']]['tryrun_end_date'] = $wip['tryrun_end_date'];
$wip_array[$wip['facilityno']]['official_check_date'] = $wip['official_check_date']; $wip_array[$wip['facilityno']]['official_check_date'] = $wip['official_check_date'];
$wip_array[$wip['facilityno']]['delivery_date'] = $wip['delivery_date']; $wip_array[$wip['facilityno']]['delivery_date'] = $wip['delivery_date'];
if (isset($arrayData[$wip['contractno']]) && isset($arrayData[$wip['contractno']]['facility'][$wip['facilityno']])) { if (isset($arrayData[$contractno]) && isset($arrayData[$contractno]['facility'][$wip['facilityno']])) {
if ($wip['delivery_date'] != NULL && $wip['delivery_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['delivery_date'])) { if ($wip['delivery_date'] != NULL && $wip['delivery_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['delivery_date'])) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['delivery_date'] . "已移交"; $arrayData[$contractno]['facility'][$wip['facilityno']]['status'] = $wip['delivery_date'] . "已移交";
$arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) ; "; $arrayData[$contractno]['facility_status'] .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) ; ";
} elseif ($wip['official_check_date'] != NULL && $wip['official_check_date'] != '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['official_check_date'])) { } elseif ($wip['official_check_date'] != NULL && $wip['official_check_date'] != '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['official_check_date'])) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['official_check_date'] . "官檢完畢"; $arrayData[$contractno]['facility'][$wip['facilityno']]['status'] = $wip['official_check_date'] . "官檢完畢";
$arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) ; "; $arrayData[$contractno]['facility_status'] .= $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) ; ";
} elseif ($wip['tryrun_end_date'] != NULL && $wip['tryrun_end_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['tryrun_end_date'])) { } elseif ($wip['tryrun_end_date'] != NULL && $wip['tryrun_end_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['tryrun_end_date'])) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['tryrun_end_date'] . "試車完畢"; $arrayData[$contractno]['facility'][$wip['facilityno']]['status'] = $wip['tryrun_end_date'] . "試車完畢";
$arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢) ; "; $arrayData[$contractno]['facility_status'] .= $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢) ; ";
} elseif ($wip['install_end_date'] != NULL && $wip['install_end_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['install_end_date'])) { } elseif ($wip['install_end_date'] != NULL && $wip['install_end_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['install_end_date'])) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['install_end_date'] . "安裝完畢"; $arrayData[$contractno]['facility'][$wip['facilityno']]['status'] = $wip['install_end_date'] . "安裝完畢";
$arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) ; "; $arrayData[$contractno]['facility_status'] .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) ; ";
} elseif ($wip['real_arrival_date'] != NULL && $wip['real_arrival_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['real_arrival_date'])) { } elseif ($wip['real_arrival_date'] != NULL && $wip['real_arrival_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['real_arrival_date'])) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['real_arrival_date'] . "貨抵工地"; $arrayData[$contractno]['facility'][$wip['facilityno']]['status'] = $wip['real_arrival_date'] . "貨抵工地";
$arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) ; "; $arrayData[$contractno]['facility_status'] .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) ; ";
} elseif ($wip['real_contract_arrival_date'] != NULL && $wip['real_contract_arrival_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['real_contract_arrival_date'])) { } elseif ($wip['real_contract_arrival_date'] != NULL && $wip['real_contract_arrival_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['real_contract_arrival_date'])) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['real_contract_arrival_date'] . "預計出貨"; $arrayData[$contractno]['facility'][$wip['facilityno']]['status'] = $wip['real_contract_arrival_date'] . "預計出貨";
$arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . date('Y-m-d', strtotime($wip['real_contract_arrival_date'])) . "預計出貨) ; "; $arrayData[$contractno]['facility_status'] .= $wip['facilityno'] . " (" . date('Y-m-d', strtotime($wip['real_contract_arrival_date'])) . "預計出貨) ; ";
} elseif ($wip['estimated_shipping_date'] != NULL && $wip['estimated_shipping_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['estimated_shipping_date'])) { } elseif ($wip['estimated_shipping_date'] != NULL && $wip['estimated_shipping_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['estimated_shipping_date'])) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['estimated_shipping_date'] . "預計出港"; $arrayData[$contractno]['facility'][$wip['facilityno']]['status'] = $wip['estimated_shipping_date'] . "預計出港";
$arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計出港) ; "; $arrayData[$contractno]['facility_status'] .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計出港) ; ";
} }
} }
} }
// 合約收款階段內容分類 // 合約收款階段內容分類
$sign60 = array('簽訂後60天', '簽約60日', '簽約後60天', '簽訂後60日內', '訂金支付後60天'); $sign60 = array('簽訂後60天', '簽約60日', '簽約後60天', '簽訂後60日內', '訂金支付後60天');
$sign90 = array('簽約後90天', '簽約後90日', '簽訂後90天'); $sign90 = array('簽約後90天', '簽約後90日', '簽訂後90天');
@ -1021,6 +1039,94 @@ foreach ($arrayData as $key => &$value) {
$total_data = json_encode($excel_contract_all_array); $total_data = json_encode($excel_contract_all_array);
$boga_data = json_encode($excel_contract_boga_array); $boga_data = json_encode($excel_contract_boga_array);
$noboga_data = json_encode($excel_contract_noboga_array); $noboga_data = json_encode($excel_contract_noboga_array);
$table = "";
$testtotal =0;
// foreach ($arrayData as $key => $value) {
// if (isset($value['facility']) && is_iterable($value['facility'])) {
// foreach ($value['facility'] as $fkey => $fvalue) {
// // echo $fkey . "<br>";
// foreach ($fvalue['PayStage'] as $pkey => $pvalue) {
// // echo $pkey . "<br>";
// // print_r($pvalue);
// // echo "<br>";
// $invoice_budget = round($pvalue['invoice_budget']);
// $received_budget = round($pvalue['received_budget']);
// $budget = round($pvalue['PlanPayAmt']);
// $paydate = $pvalue['PlanPayDate'];
// switch ($pvalue['stage']) {
// case '訂金':
// $stageno = 100;
// break;
// case '二次款':
// $stageno = 200;
// break;
// case '貨抵工地款':
// $stageno = 300;
// break;
// case '安裝款':
// $stageno = 400;
// break;
// case '試車款':
// $stageno = 500;
// break;
// case '官檢驗收款':
// $stageno = 600;
// break;
// case '交車款':
// $stageno = 700;
// break;
// case '尾款':
// $stageno = 800;
// break;
// default:
// $stageno = 0;
// break;
// }
// switch ($pvalue['hadtopay']) {
// case "V":
// $hadtopay = 1;
// break;
// default:
// $hadtopay = 0;
// break;
// }
// $invoice = 0;
// if ($pvalue['invoice_budget'] > 1) {
// $invoice = 1;
// $invoice_state = 1;
// }
// $table1 = "INSERT INTO account_receivable(
// `contract_no`,
// `facility_no`,
// `stage`,
// `budget`,
// `receivable`,
// `invoice`,
// `invoice_budget`,
// `received_budget`";
// $table2 = ") VALUES ('$key','$fkey',$stageno,$budget,$hadtopay,$invoice,$invoice_budget,$received_budget";
// if (!is_null($paydate) && !empty($paydate)) {
// $table1 .= ",`receivable_date`";
// $table2 .= ",'$paydate'";
// }
// if (!is_null($invoice_state) && !empty($invoice_state)) {
// $table1 .= ",`invoice_state`";
// $table2 .= ",$invoice_state";
// }
// $table .= $table1 . $table2 . "); \n";
// }
// }
// }
// }
// $file_path = 'account_receivable_sql.sql';
// if (file_put_contents($file_path, $table) !== false) {
// echo "SQL文件已成功生成:{$file_path}";
// } else {
// echo "生成SQL文件时出现错误。";
// }
?> ?>
<style> <style>
table { table {

112
wms/account-receivable-renovate-index.php

@ -316,19 +316,19 @@ foreach ($contract_budget_data as $cont) {
switch ($cont['MaterialId']) { switch ($cont['MaterialId']) {
case 'A40002': case 'A40002':
$sum_A40002 += $cont['OAmountWithTax']; $sum_A40002 += $cont['OAmountWithTax'];
$sum_facility_A40002 +=1; $sum_facility_A40002 += 1;
break; break;
case 'A40009': case 'A40009':
$sum_A40009 += $cont['OAmountWithTax']; $sum_A40009 += $cont['OAmountWithTax'];
$sum_facility_A40009 +=1; $sum_facility_A40009 += 1;
break; break;
case 'A40010': case 'A40010':
$sum_A40010 += $cont['OAmountWithTax']; $sum_A40010 += $cont['OAmountWithTax'];
$sum_facility_A40010 +=1; $sum_facility_A40010 += 1;
break; break;
case 'A40019': case 'A40019':
$sum_A40019 += $cont['OAmountWithTax']; $sum_A40019 += $cont['OAmountWithTax'];
$sum_facility_A40019 +=1; $sum_facility_A40019 += 1;
break; break;
} }
@ -470,7 +470,7 @@ foreach ($wipwhole_array as $wip) {
} }
// 整理arrayData[合約]['PayStage']進 (新增) arrayData[合約]['facility'][作番號][PayStage] // 整理arrayData[合約]['PayStage']進 (新增) arrayData[合約]['facility'][作番號][PayStage]
$sign_array = ['訂金', '簽約', '合約']; $sign0 = array('簽約', '簽訂', '合約簽訂', '訂金', '訂金款', '訂金');
// 將所有facility的paystage放入一個array以便計算順序 // 將所有facility的paystage放入一個array以便計算順序
$allPayStages = []; $allPayStages = [];
foreach ($arrayData as &$value) { foreach ($arrayData as &$value) {
@ -490,31 +490,43 @@ foreach ($arrayData as &$value) {
case (stristr($facility['PayStage'][$stage]['name'], '試車')): case (stristr($facility['PayStage'][$stage]['name'], '試車')):
if (isset($wipwhole_status[$fakey]['tryrun_end_date']) && $wipwhole_status[$fakey]['tryrun_end_date'] !== NULL && !empty($wipwhole_status[$fakey]['tryrun_end_date'])) { if (isset($wipwhole_status[$fakey]['tryrun_end_date']) && $wipwhole_status[$fakey]['tryrun_end_date'] !== NULL && !empty($wipwhole_status[$fakey]['tryrun_end_date'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['tryrun_end_date'])); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['tryrun_end_date']));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '完工')): case (stristr($facility['PayStage'][$stage]['name'], '完工')):
if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) { if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date'])); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date']));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '尾款')): case (stristr($facility['PayStage'][$stage]['name'], '尾款')):
if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) { if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date'])); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date']));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '交車')): case (stristr($facility['PayStage'][$stage]['name'], '交車')):
if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) { if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date'])); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date']));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '驗收')): case (stristr($facility['PayStage'][$stage]['name'], '驗收')):
if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) { if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date'])); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date']));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '安裝')): case (stristr($facility['PayStage'][$stage]['name'], '安裝')):
if (isset($wipwhole_status[$fakey]['install_end_date']) && $wipwhole_status[$fakey]['install_end_date'] !== NULL && !empty($wipwhole_status[$fakey]['install_end_date'])) { if (isset($wipwhole_status[$fakey]['install_end_date']) && $wipwhole_status[$fakey]['install_end_date'] !== NULL && !empty($wipwhole_status[$fakey]['install_end_date'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['install_end_date'])); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['install_end_date']));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '貨抵工地')): case (stristr($facility['PayStage'][$stage]['name'], '貨抵工地')):
@ -522,9 +534,14 @@ foreach ($arrayData as &$value) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['real_arrival_date'])); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['real_arrival_date']));
} elseif (isset($wipwhole_status[$fakey]['real_contract_arrival_date']) && $wipwhole_status[$fakey]['real_contract_arrival_date'] !== NULL && !empty($wipwhole_status[$fakey]['real_contract_arrival_date'])) { } elseif (isset($wipwhole_status[$fakey]['real_contract_arrival_date']) && $wipwhole_status[$fakey]['real_contract_arrival_date'] !== NULL && !empty($wipwhole_status[$fakey]['real_contract_arrival_date'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['real_contract_arrival_date'])); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['real_contract_arrival_date']));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (in_array($facility['PayStage'][$stage]['name'], $sign0)):
break;
default: default:
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
break; break;
}; };
@ -537,36 +554,48 @@ foreach ($arrayData as &$value) {
if (isset($wipwhole_status[$fakey]['tryrun_end_date']) && $wipwhole_status[$fakey]['tryrun_end_date'] !== NULL && !empty($wipwhole_status[$fakey]['tryrun_end_date'])) { if (isset($wipwhole_status[$fakey]['tryrun_end_date']) && $wipwhole_status[$fakey]['tryrun_end_date'] !== NULL && !empty($wipwhole_status[$fakey]['tryrun_end_date'])) {
$haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1; $haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1;
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['tryrun_end_date']))); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['tryrun_end_date'])));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '完工')): case (stristr($facility['PayStage'][$stage]['name'], '完工')):
if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) { if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) {
$haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1; $haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1;
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['delivery_date']))); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['delivery_date'])));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '尾款')): case (stristr($facility['PayStage'][$stage]['name'], '尾款')):
if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) { if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) {
$haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1; $haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1;
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['delivery_date']))); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['delivery_date'])));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '交車')): case (stristr($facility['PayStage'][$stage]['name'], '交車')):
if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) { if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) {
$haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1; $haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1;
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['delivery_date']))); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['delivery_date'])));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '驗收')): case (stristr($facility['PayStage'][$stage]['name'], '驗收')):
if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) { if (isset($wipwhole_status[$fakey]['delivery_date']) && $wipwhole_status[$fakey]['delivery_date'] !== NULL && !empty($wipwhole_status[$fakey]['delivery_date'])) {
$haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1; $haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1;
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['delivery_date']))); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['delivery_date'])));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '安裝')): case (stristr($facility['PayStage'][$stage]['name'], '安裝')):
if (isset($wipwhole_status[$fakey]['install_end_date']) && $wipwhole_status[$fakey]['install_end_date'] !== NULL && !empty($wipwhole_status[$fakey]['install_end_date'])) { if (isset($wipwhole_status[$fakey]['install_end_date']) && $wipwhole_status[$fakey]['install_end_date'] !== NULL && !empty($wipwhole_status[$fakey]['install_end_date'])) {
$haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1; $haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1;
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['install_end_date']))); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['install_end_date'])));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
case (stristr($facility['PayStage'][$stage]['name'], '貨抵工地')): case (stristr($facility['PayStage'][$stage]['name'], '貨抵工地')):
@ -576,9 +605,12 @@ foreach ($arrayData as &$value) {
} elseif (isset($wipwhole_status[$fakey]['real_contract_arrival_date']) && $wipwhole_status[$fakey]['real_contract_arrival_date'] !== NULL && !empty($wipwhole_status[$fakey]['real_contract_arrival_date'])) { } elseif (isset($wipwhole_status[$fakey]['real_contract_arrival_date']) && $wipwhole_status[$fakey]['real_contract_arrival_date'] !== NULL && !empty($wipwhole_status[$fakey]['real_contract_arrival_date'])) {
$haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1; $haveNumber = ((int) filter_var(str_replace('-', '', $facility['PayStage'][$stage]['name']), FILTER_SANITIZE_NUMBER_INT)) - 1;
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['real_contract_arrival_date']))); $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['real_contract_arrival_date'])));
} else {
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
} }
break; break;
default: default:
$facility['PayStage'][$stage]['PlanPayDate'] = NULL;
break; break;
}; };
default: default:
@ -684,20 +716,22 @@ foreach ($final_paystage as $key => &$payStage) {
// 0 部門id 1 部門名稱 2 經理名稱 3 營業員id 4 營業員名稱 5 客戶名稱 6 抬頭 7 統編 8 通訊地址 9 T8單據日期 10 合約號 // 0 部門id 1 部門名稱 2 經理名稱 3 營業員id 4 營業員名稱 5 客戶名稱 6 抬頭 7 統編 8 通訊地址 9 T8單據日期 10 合約號
// 0 合約號 1 作番號 2 部門id 3 部門名稱 4 經理名稱 5 營業員id 6 營業員名稱 7 客戶名稱 8 抬頭 9 統編 10 通訊地址 // 0 合約號 1 作番號 2 部門id 3 部門名稱 4 經理名稱 5 營業員id 6 營業員名稱 7 客戶名稱 8 抬頭 9 統編 10 通訊地址
// 11 收款階段名稱 12 應收日期 13 收款金額 14 已開金額 15 已收金額 16 催收次數 // 11 收款階段名稱 12 應收日期 13 收款金額 14 已開金額 15 已收金額 16 催收次數
$table = "";
$excel_aray = array(); $excel_aray = array();
$print_array = array(); $print_array = array();
$today = strtotime(date('Ymt')); $today = strtotime(date('Ymt'));
foreach ($arrayData as $key => $value) { foreach ($arrayData as $key => $value) {
if (isset($final_paystage[$key])) { if (isset($final_paystage[$key])) {
for ($sequence = 1; $sequence <= count($final_paystage[$key]); $sequence++) { for ($sequence = 1; $sequence <= count($final_paystage[$key]); $sequence++) {
if(!is_null($value['ManagerId']) && $value['ManagerId'] !==''){ if (!is_null($value['ManagerId']) && $value['ManagerId'] !== '') {
$managerId = $value['ManagerId']; $managerId = $value['ManagerId'];
}else{ } else {
$managerId = $value[11]; $managerId = $value[11];
} }
if(!is_null($value['ManagerName']) && $value['ManagerName'] !==''){ if (!is_null($value['ManagerName']) && $value['ManagerName'] !== '') {
$managerName = $value['ManagerName']; $managerName = $value['ManagerName'];
}else{ } else {
$managerName = $value[2]; $managerName = $value[2];
} }
$value[4] = (isset($value[4]) && !empty($value[4])) ? $value[4] : '--'; $value[4] = (isset($value[4]) && !empty($value[4])) ? $value[4] : '--';
@ -709,9 +743,16 @@ foreach ($arrayData as $key => $value) {
$value[12] = (isset($value[12]) && !empty($value[12])) ? date('Y/m/d', strtotime($value[12])) : '--'; $value[12] = (isset($value[12]) && !empty($value[12])) ? date('Y/m/d', strtotime($value[12])) : '--';
$thisPayStage = $final_paystage[$key][$sequence]; $thisPayStage = $final_paystage[$key][$sequence];
$keyname = $key . "_" . $final_paystage[$key][$sequence]['facilityno'] . "_" . $sequence; $keyname = $key . "_" . $final_paystage[$key][$sequence]['facilityno'] . "_" . $sequence;
if (isset($final_paystage[$key][$sequence]['PlanPayDate']) && !empty($final_paystage[$key][$sequence]['PlanPayDate']) && $final_paystage[$key][$sequence]['PlanPayDate'] !== NULL) {
$havetopay = ($today >= strtotime($final_paystage[$key][$sequence]['PlanPayDate'])) ? "V" : "--"; $havetopay = ($today >= strtotime($final_paystage[$key][$sequence]['PlanPayDate'])) ? "V" : "--";
} else {
$havetopay = "--";
}
$table_hadtopay = 0;
switch ($havetopay) { switch ($havetopay) {
case "V": case "V":
$table_hadtopay = 1;
$unInvoiceAmount = $final_paystage[$key][$sequence]['PayAmount'] - $final_paystage[$key][$sequence]['InvoiceAmount']; $unInvoiceAmount = $final_paystage[$key][$sequence]['PayAmount'] - $final_paystage[$key][$sequence]['InvoiceAmount'];
$unReceivedAmount = $final_paystage[$key][$sequence]['PayAmount'] - $final_paystage[$key][$sequence]['receivedAmount']; $unReceivedAmount = $final_paystage[$key][$sequence]['PayAmount'] - $final_paystage[$key][$sequence]['receivedAmount'];
break; break;
@ -720,10 +761,15 @@ foreach ($arrayData as $key => $value) {
$unReceivedAmount = 0; $unReceivedAmount = 0;
break; break;
} }
if (is_null($thisPayStage['PlanPayDate']) || empty($thisPayStage['PlanPayDate'])) {
$thisplanpaydate = "--";
} else {
$thisplanpaydate = $thisPayStage['PlanPayDate'];
}
if ($havetopay == "V" && $unReceivedAmount > 1) { if ($havetopay == "V" && $unReceivedAmount > 1) {
$print_array[$keyname] = [ $print_array[$keyname] = [
$value[10], $thisPayStage['facilityno'], $value[0], $value[1], $value[11], $value['ManagerName'], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8], $value[10], $thisPayStage['facilityno'], $value[0], $value[1], $value[11], $value['ManagerName'], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8],
$thisPayStage['name'], $thisPayStage['PlanPayDate'], $havetopay, $thisPayStage['name'], $thisplanpaydate, $havetopay,
number_format(round($final_paystage[$key][$sequence]['PayAmount'])), number_format(round($final_paystage[$key][$sequence]['PayAmount'])),
number_format(round($final_paystage[$key][$sequence]['InvoiceAmount'])), number_format(round($unInvoiceAmount)), number_format(round($final_paystage[$key][$sequence]['InvoiceAmount'])), number_format(round($unInvoiceAmount)),
number_format(round($final_paystage[$key][$sequence]['receivedAmount'])), number_format(round($unReceivedAmount)), number_format(round($final_paystage[$key][$sequence]['receivedAmount'])), number_format(round($unReceivedAmount)),
@ -731,18 +777,58 @@ foreach ($arrayData as $key => $value) {
]; ];
} }
$table_budget = round($final_paystage[$key][$sequence]['PayAmount']);
$table_invoice_budget = round($final_paystage[$key][$sequence]['InvoiceAmount']);
$table_received_budget = round($final_paystage[$key][$sequence]['receivedAmount']);
$excel_aray[$keyname] = [ $excel_aray[$keyname] = [
$value[10], $thisPayStage['facilityno'], $value[0], $value[1], $managerId, $managerName, $value[3], $value[4], $value[5], $value[6], $value[7], $value[8], $value[10], $thisPayStage['facilityno'], $value[0], $value[1], $managerId, $managerName, $value[3], $value[4], $value[5], $value[6], $value[7], $value[8],
$thisPayStage['name'], $thisPayStage['PlanPayDate'], $havetopay, $thisPayStage['name'], $thisplanpaydate, $havetopay,
number_format(round($final_paystage[$key][$sequence]['PayAmount'])), number_format(round($final_paystage[$key][$sequence]['PayAmount'])),
number_format(round($final_paystage[$key][$sequence]['InvoiceAmount'])), number_format(round($unInvoiceAmount)), number_format(round($final_paystage[$key][$sequence]['InvoiceAmount'])), number_format(round($unInvoiceAmount)),
number_format(round($final_paystage[$key][$sequence]['receivedAmount'])), number_format(round($unReceivedAmount)), number_format(round($final_paystage[$key][$sequence]['receivedAmount'])), number_format(round($unReceivedAmount)),
number_format(round($final_paystage[$key][$sequence]['collect_month'])) number_format(round($final_paystage[$key][$sequence]['collect_month']))
]; ];
if ($final_paystage[$key][$sequence]['InvoiceAmount'] > 1) {
$invoice_state = 1;
} else {
$invoice_state = 0;
}
$table1 = "INSERT INTO account_receivable_renovate(
`contract_no`,
`facility_no`,
`stagename`,
`budget`,
`receivable`,
`invoice_state`,
`invoice_budget`,
`received_budget`
";
$table2 = ") VALUES (
'$value[10]',
'$thisPayStage[facilityno]',
'$thisPayStage[name]',
$table_budget,
$table_hadtopay,
$invoice_state,
$table_invoice_budget,
$table_received_budget
";
if (!is_null($final_paystage[$key][$sequence]['PlanPayDate']) && !empty($final_paystage[$key][$sequence]['PlanPayDate'])) {
$table1 .= ",`receivable_date`";
$receivable_date = date('Y-m-d', strtotime($final_paystage[$key][$sequence]['PlanPayDate']));
$table2 .= ",'$receivable_date' \n";
}
$table .= $table1 . $table2 . "); \n";
} }
} }
} }
// $file_path = 'account_receivable_renovate_sql.sql';
// if (file_put_contents($file_path, $table) !== false) {
// // echo "SQL文件已成功生成:{$file_path}";
// } else {
// // echo "生成SQL文件时出现错误。";
// }
$total_data = json_encode($print_array); $total_data = json_encode($print_array);
$average_budget = $sum_total_budget / $sum_facility; $average_budget = $sum_total_budget / $sum_facility;
$average_A40002 = $sum_A40002 / $sum_facility_A40002; $average_A40002 = $sum_A40002 / $sum_facility_A40002;
@ -1024,6 +1110,7 @@ include "./footer.php";
})); }));
} }
function searchFront(area) { function searchFront(area) {
var term = 'search_' + area; var term = 'search_' + area;
@ -1109,6 +1196,7 @@ include "./footer.php";
} }
} }
} }
function check(searchname) { function check(searchname) {
console.log(searchname); console.log(searchname);

50320
wms/account_receivable_sql_file.sql

File diff suppressed because it is too large
Loading…
Cancel
Save