@ -2,18 +2,11 @@
include "header.php";
$sum_facility = 0;
// M1
$sum_A40002 = 0;
// 設備
$sum_A40009 = 0;
// 安裝
$sum_A40010 = 0;
$sum_total_budget = 0;
$average_budget = 0;
$average_A40002 = 0;
$average_A40009 = 0;
$average_A40010 = 0;
$start_date = empty($_POST['date_start']) ? null : $_POST['date_start'];
$end_date = empty($_POST['date_end']) ? null : $_POST['date_end'];
/* 比較應收日期
@param $a array
@ -33,7 +26,6 @@ $find_manager = array();
foreach ($managers as $manager) {
$find_manager[$manager['accountid']] = $manager;
}
$follower = find_follow($user_id);
$arrayData = array();
$receivable_array = [];
@ -58,6 +50,14 @@ Main.CurrentState
LEFT JOIN comGroupPerson AS Person ON MainAll.PersonId= Person.PersonId
LEFT JOIN comDepartment AS Dept ON MainAll.DeptId= Dept.DeptId
WHERE MainAll.TypeId = 'SP' AND (MainAll.CurrentState=2 OR MainAll.CurrentState=4) ";
if(!is_null($start_date)){
$start_date = (int)date('Ymd', strtotime($start_date));
$sql_contractNumber .= " AND MainAll.BillDate >= $start_date ";
}
if(!is_null($end_date)){
$end_date = (int)date('Ymd', strtotime($end_date));
$sql_contractNumber .= " AND MainAll.BillDate < = $end_date ";
}
if ((in_array($user_id, array('M0008', 'M0012'))) || (in_array(accountidToDepartId($user_id), array('220', '210', '501')))) {
} else {
$sql_contractNumber .= " AND (MainAll.PersonId = '$user_id'";
@ -76,47 +76,61 @@ $query_contract_number = $conn->query($sql_contractNumber);
if (is_iterable($query_contract_number)) {
foreach ($query_contract_number as $contract_numbers) {
array_push($contractNumbers, $contract_numbers['BillNo']);
$arrayData[$contract_numbers['BillNo']]['BillNo'] = $contract_numbers['BillNo'];
$arrayData[$contract_numbers['BillNo']]['BillDate'] = $contract_numbers['BillDate'];
$arrayData[$contract_numbers['BillNo']]['CustomerId'] = $contract_numbers['BizPartnerId'];
$arrayData[$contract_numbers['BillNo']]['CustomerAddress'] = $contract_numbers['ContactAddress'];
$arrayData[$contract_numbers['BillNo']]['OAmountWithTax'] = $contract_numbers['OAmountWithTax'];
$arrayData[$contract_numbers['BillNo']]['PersonId'] = $contract_numbers['PersonId'];
$arrayData[$contract_numbers['BillNo']]['DeptId'] = $contract_numbers['DeptId'];
$arrayData[$contract_numbers['BillNo']]['PersonName'] = $contract_numbers['PersonName'];
$arrayData[$contract_numbers['BillNo']]['DeptName'] = $contract_numbers['DeptName'];
$arrayData[$contract_numbers['BillNo']]['ShortName'] = $contract_numbers['ShortName'];
$arrayData[$contract_numbers['BillNo']]['ManagerId'] = $find_manager[$contract_numbers['PersonId']]['manager'];
$arrayData[$contract_numbers['BillNo']]['ManagerName'] = $find_manager[$contract_numbers['PersonId']]['manager_name'];
$arrayData[$contract_numbers['BillNo']]['BillNo'] = isset($contract_numbers['BillNo']) ? $contract_numbers['BillNo'] : '--';
$arrayData[$contract_numbers['BillNo']]['BillDate'] = isset($contract_numbers['BillDate']) ? $contract_numbers['BillDate'] : '--';
$arrayData[$contract_numbers['BillNo']]['CustomerId'] = isset($contract_numbers['BizPartnerId']) ? $contract_numbers['BizPartnerId'] : '--';
$arrayData[$contract_numbers['BillNo']]['CustomerName'] = isset($contract_numbers['BizPartnerName']) ? $contract_numbers['BizPartnerName'] : '--';
$arrayData[$contract_numbers['BillNo']]['CustomerAddress'] = isset($contract_numbers['ContactAddress']) ? $contract_numbers['ContactAddress'] : '--';
$arrayData[$contract_numbers['BillNo']]['OAmountWithTax'] = isset($contract_numbers['OAmountWithTax']) ? $contract_numbers['OAmountWithTax'] : 0;
$arrayData[$contract_numbers['BillNo']]['PersonId'] = isset($contract_numbers['PersonId']) ? $contract_numbers['PersonId'] : '--';
$arrayData[$contract_numbers['BillNo']]['DeptId'] = isset($contract_numbers['DeptId']) ? $contract_numbers['DeptId'] : '--';
$arrayData[$contract_numbers['BillNo']]['PersonName'] = isset($contract_numbers['PersonName']) ? $contract_numbers['PersonName'] : '--';
$arrayData[$contract_numbers['BillNo']]['DeptName'] = isset($contract_numbers['DeptName']) ? $contract_numbers['DeptName'] : '--';
$arrayData[$contract_numbers['BillNo']]['ShortName'] = isset($contract_numbers['ShortName']) ? $contract_numbers['ShortName'] : '--';
$arrayData[$contract_numbers['BillNo']]['ManagerId'] = !empty($find_manager[$contract_numbers['PersonId']]['manager']) ? $find_manager[$contract_numbers['PersonId']]['manager'] : '--';
$arrayData[$contract_numbers['BillNo']]['ManagerName'] = !empty($find_manager[$contract_numbers['PersonId']]['manager_name']) ? $find_manager[$contract_numbers['PersonId']]['manager_name'] : '--';
$arrayData[$contract_numbers['BillNo']]['invoice_budget'] = 0;
$arrayData[$contract_numbers['BillNo']]['received_budget'] = 0;
$arrayData[$contract_numbers['BillNo']]['receivable_budget'] = 0;
$sum_total_budget += $contract_numbers['OAmountWithTax'];
}
$str_numbers = "('" . implode("','", $contractNumbers) . "')";
}
// T8發票 (有專案的發票)
$sql_invoice = "SELECT Detail.BillNo AS InvoiceBillNo, Detail.MaterialId, Detail.LAmountWithTax, Main.InvoiceNo, CheckAll.FromSalSalesOrder AS BillNo FROM arSellInvoiceMaterial AS Detail
LEFT JOIN arSellInvoice AS Main ON Detail.BillNo=Main.BillNo
LEFT JOIN (
SELECT CheckDetail.BillNo, CheckDetail.FromSalSalesOrder FROM arCheckBillDetail AS CheckDetail ) AS CheckAll ON CheckAll.BillNo= Detail.FromBillNo
WHERE Detail.ItemType=0";
// T8發票
$sql_invoice = "SELECT
Detail.BillNo AS InvoiceBillNo,
Detail.MaterialId,
Detail.LAmountWithTax,
Main.InvoiceNo,
CheckAll.FromSalSalesOrder AS BillNo
FROM arSellInvoiceMaterial AS Detail
LEFT JOIN arSellInvoice AS Main ON Detail.BillNo=Main.BillNo
LEFT JOIN (
SELECT CheckDetail.BillNo, CheckDetail.FromSalSalesOrder, CheckDetail.RowNo
FROM arCheckBillDetail AS CheckDetail )
AS CheckAll ON CheckAll.BillNo= Detail.FromBillNo AND Detail.FromRowCode = CheckAll.RowNo
WHERE Detail.ItemType=0 AND Main.InvoiceState!=2";
// T8核銷
$sql_received = "SELECT
a.BillNo, a.WriteOffBizPartnerId,a.PayWriteOffOAmount,
b.FromBillDate AS ReceivedDate,b.CurrWOFeeOAmt AS Fee,
c.OrderBillNo, c.checkBillNo, c.InvoiceNo, c.BillDate AS CheckBillDate
FROM arWriteOffBill AS a
LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo
LEFT JOIN
(SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail
LEFT JOIN
(SELECT
arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo
FROM arCheckBill
LEFT JOIN arCheckBillInvInfo
ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1
ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c
ON a.BillNo=c.BillNo
WHERE DATALENGTH(c.OrderBillNo) >0";
CheckDetail.OrderBillNo,
arWriteOffBillDetail.FromBillNo AS CheckBillNo,
arWriteOffBillDetail.FromRowCode AS CheckRowCode,
arWriteOffBillDetail.CurrStandOffOAmount
FROM arWriteOffBillDetail
LEFT JOIN
(SELECT
arCheckBillDetail.BillNo,
arCheckBillDetail.RowCode,
arCheckBillDetail.FromSalSalesOrder AS OrderBillNo,
salSalesOrder.TypeId
FROM arCheckBillDetail
LEFT JOIN salSalesOrder
ON salSalesOrder.BillNo =arCheckBillDetail.FromSalSalesOrder )
AS CheckDetail
ON CheckDetail.BillNo=arWriteOffBillDetail.FromBillNo AND arWriteOffBillDetail.FromRowCode = CheckDetail.RowCode
WHERE CheckDetail.TypeId = 'SP'";
//T8 銷售訂單 階段收款計畫
@ -134,6 +148,15 @@ $allPayStages = array();
foreach ($PayStage as $stage) {
$allPayStages[$stage['BillNo']][$stage['PayStage']]['PlanPayAmt'] = $stage['PlanPayAmt'];
$allPayStages[$stage['BillNo']][$stage['PayStage']]['PlanPayDate'] = $stage['PlanPayDate'];
$month = collect_month(strtotime($stage['PlanPayDate']));
if (strtotime($stage['PlanPayDate']) > strtotime(date('Y-m-t', strtotime('now')))) {
$allPayStages[$stage['BillNo']][$stage['PayStage']]['receivable_ornot'] = '--';
} else {
$allPayStages[$stage['BillNo']][$stage['PayStage']]['receivable_ornot'] = 'Y';
}
$allPayStages[$stage['BillNo']][$stage['PayStage']]['month'] = $month;
$allPayStages[$stage['BillNo']][$stage['PayStage']]['received'] = 0;
$allPayStages[$stage['BillNo']][$stage['PayStage']]['invoice'] = 0;
}
foreach ($allPayStages as $paykey => $pay) {
uasort($allPayStages[$paykey], 'comparePlanPayDate');
@ -153,6 +176,9 @@ foreach ($allPayStages as $key => &$payStage) {
foreach ($payStage as $key2 => $pstage) {
if (isset($arrayData[$key])) {
$arrayData[$key]['PayStage'][$pstage['sequenceNumber']] = $pstage;
if (isset($pstage['receivable_ornot']) & & $pstage['receivable_ornot'] == 'Y') {
$arrayData[$key]['receivable_budget'] += $pstage['PlanPayAmt'];
}
}
}
}
@ -160,11 +186,9 @@ foreach ($allPayStages as $key => &$payStage) {
foreach ($invoice_data as $inv) {
if (isset($arrayData[$inv['BillNo']])) {
if(isset($arrayData[$inv['BillNo']]['invoice']['total'])) {
$arrayData[$inv['BillNo']]['invoice']['total'] += $inv['LAmountWithTax'];
} else {
$arrayData[$inv['BillNo']]['invoice']['total'] = $inv['LAmountWithTax'];
}
$arrayData[$inv['BillNo']]['invoice_budget'] += $inv['LAmountWithTax'];
if (isset($arrayData[$inv['BillNo']]['invoice'][$inv['InvoiceNo']])) {
$arrayData[$inv['BillNo']]['invoice'][$inv['InvoiceNo']] += $inv['LAmountWithTax'];
} else {
@ -172,453 +196,64 @@ foreach ($invoice_data as $inv) {
}
}
}
foreach($arrayData as $key => & $value){
echo $key."< br > ";
echo "< br > -------< br > ";
if(isset($value['invoice'])){
foreach($value['invoice'] as $invkey => $invvalue){
echo $invkey."< br > ";
echo $invvalue."< br > ";
}
}
echo "< br > ---------------------------< br > ";
}
exit();
// T8 銷售訂單 作番金額
$sql_contract_budget = "SELECT A.BillNo,A.MaterialId, A.OAmountWithTax,A.CU_MaterialId FROM salSalesOrderDetail AS A
LEFT JOIN salSalesOrder AS B ON A.BillNo=B.BillNo
WHERE B.ModeId='T' AND A.ItemType=1 ";
if (isset($str_numbers)) {
$sql_contract_budget .= "AND A.BillNo IN $str_numbers ";
}
$contract_data = array();
// 將T8合約收款階段資料依據款別分類放進arraData裡
foreach ($contract as $cont) {
$BillNo = $cont['BillNo'];
$BillDate = $cont['BillDate'];
$PayStage = $cont['PayStage'];
$PlanPayDate = $cont['PlanPayDate'];
$PayAmount = $cont['PlanPayAmt'];
$partnerName = $cont['BizPartnerName'];
$EnterpriseName = $cont['EnterpriseName'];
$TaxNo = $cont['TaxNo'];
$ContactAddress = $cont['ContactAddress'];
$RowNo = $cont['RowNo'];
$salesId = $cont['PersonId'];
//['type'] A:比照新梯、B:純分期、C:其他
//['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 min 最早應收月份 max 最晚應收月份 ['second'] 0 二次款名 1 二次款金額 2 收款日期 ['arrive'] 0 貨抵工地款名稱 1 貨抵工地款金額 2 貨抵工地收款日期 ['install'] 0 安裝款名 1 安裝金額 2 安裝收款日期
//['tryrun'] 0 試車款名 1試車金額 2 試車收款日期 ['check'] 0 官檢款名 1 官檢金額 2 官檢收款日期 ['delivery'] 0 交車款名 1 交車金額 2 交車收款日期 ['final'] 0 尾款名 1 尾款金額 2 尾款收款日期
//['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數
if (!(isset($arrayData[$BillNo]))) {
// 0 部門id 1 部門名稱 2 經理名稱 3 營業員id 4 營業員名稱 5 客戶名稱 6 抬頭 7 統編 8 通訊地址 9 T8單據日期 10 合約號
$arrayData[$BillNo] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
$arrayData[$BillNo][0] = $cont['DeptId'];
$arrayData[$BillNo][1] = $cont['DeptName'];
$arrayData[$BillNo][3] = $salesId;
$arrayData[$BillNo][5] = $partnerName;
$arrayData[$BillNo][6] = $EnterpriseName;
$arrayData[$BillNo][7] = $TaxNo;
$arrayData[$BillNo][8] = $ContactAddress;
$arrayData[$BillNo][9] = $BillDate;
$arrayData[$BillNo][10] = $BillNo;
$arrayData[$BillNo]['total_budget'] = 0;
$arrayData[$BillNo]['invoice'] = array();
$arrayData[$BillNo]['received_budget'] = 0;
$arrayData[$BillNo]['invoice_budget'] = 0;
$arrayData[$BillNo]['A40002'] = $arrayData[$BillNo]['A40009'] = $arrayData[$BillNo]['A40010'] = 0;
$arrayData[$BillNo]['total_facility_num'] = 0;
}
$arrayData[$BillNo]['PayStage'][$RowNo]['type'] = 0;
$arrayData[$BillNo]['PayStage'][$RowNo]['name'] = $PayStage;
$arrayData[$BillNo]['PayStage'][$RowNo]['PlanPayDate'] = $PlanPayDate;
$arrayData[$BillNo]['PayStage'][$RowNo]['PayAmount'] = $PayAmount;
// 判斷type
$wipStage = ['簽約', '訂金', '貨抵工地', '完工', '試車', '安裝', '驗收', '完工', '交車', '尾款', '合約'];
foreach ($wipStage as $wipstage) {
if (strpos($PayStage, $wipstage) !== false) {
$arrayData[$BillNo]['PayStage'][$RowNo]['type'] = "A";
}
}
$haveNumber = (int) filter_var(str_replace('-', '', $PayStage), FILTER_SANITIZE_NUMBER_INT);
if ($haveNumber > 0 & & $arrayData[$BillNo]['PayStage'][$RowNo]['type'] === 0) {
$arrayData[$BillNo]['PayStage'][$RowNo]['type'] = "B";
} elseif ($haveNumber > 0 & & $arrayData[$BillNo]['PayStage'][$RowNo]['type'] == 'A') {
$arrayData[$BillNo]['PayStage'][$RowNo]['type'] = "C";
foreach ($received_array as $received) {
if (isset($arrayData[$received['OrderBillNo']]) & & isset($received['CurrStandOffOAmount']) & & $received['CurrStandOffOAmount'] > 0) {
$arrayData[$received['OrderBillNo']]['received_budget'] += $received['CurrStandOffOAmount'];
}
}
$contract_budget_data = $conn->query($sql_contract_budget);
// 將T8銷售訂單明細 每個作番金額存入arrayData
$contract_budget = array();
foreach ($contract_budget_data as $cont) {
$BillNo = $cont['BillNo'];
if (isset($arrayData[$BillNo])) {
$salesid = $arrayData[$BillNo][3];
if (isset($find_manager[$salesid])) {
$arrayData[$BillNo][2] = $find_manager[$salesid]['manager_name'];
$arrayData[$BillNo][4] = $find_manager[$salesid]['name'];
$arrayData[$BillNo][11] = $find_manager[$salesid]['manager'];
}
$arrayData[$BillNo]['total_budget'] += $cont['OAmountWithTax'];
$sum_total_budget += $cont['OAmountWithTax'];
$arrayData[$BillNo][$cont['MaterialId']] += $cont['OAmountWithTax'];
switch ($cont['MaterialId']) {
case "A40002":
$sum_A40002 += $cont['OAmountWithTax'];
break;
case "A40009":
$sum_A40009 += $cont['OAmountWithTax'];
break;
case "A40010":
$sum_A40010 += $cont['OAmountWithTax'];
break;
}
if (isset($arrayData[$BillNo]['facility'][$cont['CU_MaterialId']])) {
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['total_budget'] += $cont['OAmountWithTax'];
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']][$cont['MaterialId']] += $cont['OAmountWithTax'];
} else {
$sum_facility += 1;
$arrayData[$BillNo]['total_facility_num'] += 1;
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['total_budget'] = $cont['OAmountWithTax'];
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['A40002'] = $arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['A40009'] = $arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['A40010'] = 0;
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']][$cont['MaterialId']] = $cont['OAmountWithTax'];
}
}
if (isset($contract_budget[$cont['BillNo']])) {
$contract_budget[$cont['BillNo']]['total'] += $cont['OAmountWithTax'];
foreach ($arrayData as $key => & $value) {
if (!isset($value['PayStage'])) {
$value['receivable_budget'] = $value['OAmountWithTax'];
} else {
$contract_budget[$cont['BillNo']]['total'] = $cont['OAmountWithTax'];
}
if (isset($contract_budget[$cont['BillNo']][$cont['MaterialId']])) {
$contract_budget[$cont['BillNo']][$cont['MaterialId']] += $cont['OAmountWithTax'];
} else {
$contract_budget[$cont['BillNo']][$cont['MaterialId']] = $cont['OAmountWithTax'];
}
if (isset($contract_budget[$cont['BillNo']]['facility'][$cont['CU_MaterialId']])) {
$contract_budget[$cont['BillNo']]['facility'][$cont['CU_MaterialId']]['total'] += $cont['OAmountWithTax'];
$contract_budget[$cont['BillNo']]['facility'][$cont['CU_MaterialId']][$cont['MaterialId']] += $cont['OAmountWithTax'];
} else {
$contract_budget[$cont['BillNo']]['facility'][$cont['CU_MaterialId']]['total'] = $cont['OAmountWithTax'];
$contract_budget[$cont['BillNo']]['facility'][$cont['CU_MaterialId']]['A40002'] = 0;
$contract_budget[$cont['BillNo']]['facility'][$cont['CU_MaterialId']]['A40009'] = 0;
$contract_budget[$cont['BillNo']]['facility'][$cont['CU_MaterialId']]['A40010'] = 0;
$contract_budget[$cont['BillNo']]['facility'][$cont['CU_MaterialId']][$cont['MaterialId']] = $cont['OAmountWithTax'];
};
}
/*計算作番佔合約的金額比例
@param $facility_no string => 作番號
@param $contract_budget_billno array => $contract_budget[合約號]
return float */
function get_contract_ratio($facility_no, $contract_budget_billno)
{
$ratio = 0;
if (isset($contract_budget_billno['facility'][$facility_no])) {
if (empty($contract_budget_billno['total'])) {
} else {
$ratio += $contract_budget_billno['facility'][$facility_no]['total'] / $contract_budget_billno['total'];
}
}
return $ratio;
}
//取作番大日程作番與時程 進arrayData
// real_contract_arrival_date 預計出貨日
// real_arrival_date 實際出貨日
$today = strtotime(date('Ymd'));
$wipwhole_array = mysqli_query($link, $sql);
$wipwhole_status = array();
foreach ($wipwhole_array as $wip) {
//[合約號]['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數
if (isset($arrayData[$wip['contractno']])) {
// 整理合約資料
// $arrayData[$wip['contractno']][0] = $wip['department_id'];;
// $arrayData[$wip['contractno']][1] = $wip['depart_name'];
// $arrayData[$wip['contractno']][2] = $wip['manager_name'];
// $arrayData[$wip['contractno']][3] = $wip['salesid'];
// $arrayData[$wip['contractno']][4] = $wip['name'];
$arrayData[$wip['contractno']][10] = $wip['contractno'];
$arrayData[$wip['contractno']]['A40002'] = (isset($contract_budget[$wip['contractno']]['A40002']) & & !is_null($contract_budget[$wip['contractno']]['A40002'])) ? $contract_budget[$wip['contractno']]['A40002'] : 0;
$arrayData[$wip['contractno']]['A40009'] = (isset($contract_budget[$wip['contractno']]['A40009']) & & !is_null($contract_budget[$wip['contractno']]['A40009'])) ? $contract_budget[$wip['contractno']]['A40009'] : 0;
// [合約號]['facility'][作番號]['no']
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['no'] = $wip['facilityno'];
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = "";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['total_budget'] = 0;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['receivable_budget'] = 0;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['collect_budget'] = 0;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['A40002'] = (isset($contract_budget[$wip['contractno']][$wip['facilityno']]['A40002']) & & !is_null($contract_budget[$wip['contractno']][$wip['facilityno']]['A40002'])) ? $contract_budget[$wip['contractno']][$wip['facilityno']]['A40002'] : 0;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['A40009'] = (isset($contract_budget[$wip['contractno']][$wip['facilityno']]['A40009']) & & !is_null($contract_budget[$wip['contractno']][$wip['facilityno']]['A40009'])) ? $contract_budget[$wip['contractno']][$wip['facilityno']]['A40009'] : 0;
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['A40010'] = (isset($contract_budget[$wip['contractno']][$wip['facilityno']]['A40010']) & & !is_null($contract_budget[$wip['contractno']][$wip['facilityno']]['A40010'])) ? $contract_budget[$wip['contractno']][$wip['facilityno']]['A40010'] : 0;
}
$wipwhole_status[$wip['facilityno']] = $wip;
}
// 整理arrayData[合約]['PayStage']進 (新增) arrayData[合約]['facility'][作番號][PayStage]
$sign_array = ['訂金', '簽約', '合約'];
// 將所有facility的paystage放入一個array以便計算順序
$allPayStages = [];
foreach ($arrayData as & $value) {
if (isset($value['facility']) & & is_iterable($value['facility'])) {
foreach ($value['facility'] as $fakey => & $facility) {
if (isset($contract_budget[$value[10]])) {
$ratio = get_contract_ratio($fakey, $contract_budget[$value[10]]);
for ($stage = 1; $stage < (count($value['PayStage']) + 1); $stage++) {
$facility['PayStage'][$stage] = $value['PayStage'][$stage];
$facility['PayStage'][$stage]['facilityno'] = $fakey;
//算每個作番的金額
$facility['PayStage'][$stage]['PayAmount'] = $value['PayStage'][$stage]['PayAmount'] * $ratio;
//算每個作番每個收款階段的收款時間
switch ($facility['PayStage'][$stage]['type']) {
case "A":
switch ($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'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['tryrun_end_date']));
}
break;
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'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date']));
}
break;
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'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date']));
}
break;
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'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date']));
}
break;
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'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['delivery_date']));
}
break;
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'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['install_end_date']));
}
break;
case (stristr($facility['PayStage'][$stage]['name'], '貨抵工地')):
if (isset($wipwhole_status[$fakey]['real_arrival_date']) & & $wipwhole_status[$fakey]['real_arrival_date'] !== NULL & & !empty($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'])) {
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime($wipwhole_status[$fakey]['real_contract_arrival_date']));
}
break;
default:
break;
};
case "B":
break;
case "C":
switch ($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'])) {
$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'])));
}
break;
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'])) {
$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'])));
}
break;
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'])) {
$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'])));
}
break;
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'])) {
$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'])));
}
break;
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'])) {
$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'])));
}
break;
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'])) {
$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'])));
}
break;
case (stristr($facility['PayStage'][$stage]['name'], '貨抵工地')):
if (isset($wipwhole_status[$fakey]['real_arrival_date']) & & $wipwhole_status[$fakey]['real_arrival_date'] !== NULL & & !empty($wipwhole_status[$fakey]['real_arrival_date'])) {
$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_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;
$facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['real_contract_arrival_date'])));
}
break;
default:
break;
};
default:
break;
}
$tmpReceived = $value['received_budget'];
$tmpInvoice = $value['invoice_budget'];
if (is_iterable($value['PayStage'])) {
for ($sequence = 1; $sequence < = count($value['PayStage']); $sequence++) {
if ($value['PayStage'][$sequence]['PlanPayAmt'] > $tmpInvoice) {
$value['PayStage'][$sequence]['invoice'] = $tmpInvoice;
$tmpInvoice = 0;
} else {
$value['PayStage'][$sequence]['invoice'] = $value['PayStage'][$sequence]['PlanPayAmt'];
$tmpInvoice -= $value['PayStage'][$sequence]['PlanPayAmt'];
}
if (isset($allPayStages[$value[10]])) {
$allPayStages[$value[10]] = array_merge($allPayStages[$value[10]], $facility['PayStage']);
if ($value['PayStage'][$sequence]['PlanPayAmt'] > $tmpReceived) {
$value['PayStage'][$sequence]['received'] = $tmpReceived;
$tmpReceived = 0;
} else {
$allPayStages[$value[10]] = $facility['PayStage'];
$value['PayStage'][$sequence]['received'] = $value['PayStage'][$sequence]['PlanPayAmt'];
$tmpReceived -= $value['PayStage'][$sequence]['PlanPayAmt'];
}
}
}
$value['received_budget'] = $tmpReceived;
}
}
foreach ($allPayStages as $paykey => $pay) {
uasort($allPayStages[$paykey], 'comparePlanPayDate');
}
foreach ($allPayStages as & $payStage) {
$sequenceNumber = 1;
foreach ($payStage as $tk => & $pstage) {
$pstage['sequenceNumber'] = $sequenceNumber;
$sequenceNumber += 1;
}
}
// 整理好的收款階段
$final_paystage = array();
foreach ($allPayStages as $key => & $payStage) {
if (is_iterable($payStage)) {
foreach ($payStage as $key2 => $pstage) {
$final_paystage[$key][$pstage['sequenceNumber']] = $pstage;
}
}
}
// [invoice][發票號碼][0 發票日期, 1 發票金額, 2 發票狀態, 3 收款日期, 4 收款金額, 5 手續費, 6 核銷單號]
foreach ($invoice_data as $invoice) {
if (isset($arrayData[$invoice['FromSalSalesOrder']])) {
$arrayData[$invoice['FromSalSalesOrder']]['invoice_budget'] += intval($invoice['OAmountWithTax']);
$arrayData[$invoice['FromSalSalesOrder']]['invoice'][$invoice['InvoiceNo']] = [date("Ymd", strtotime($invoice['InvoiceTime'])), $invoice['OAmountWithTax'], $invoice['InvoiceState']];
}
}
// 把核銷單的內容補到發票資料中
foreach ($received_array as $received) {
$BillNo = $received['OrderBillNo'];
if (isset($arrayData[$BillNo])) {
if (isset($arrayData[$BillNo]['invoice'][$received['InvoiceNo']])) {
$arrayData[$BillNo]['received_budget'] += $received['PayWriteOffOAmount'];
array_push($arrayData[$BillNo]['invoice'][$received['InvoiceNo']], date($received['ReceivedDate']), $received['PayWriteOffOAmount'], $received['Fee'], $received['BillNo']);
}
}
}
// $final_paystage ['type'] ['PlanPayDate'] ['PayAmount'] ['facilityno'] ['sequenceNumber'] ['name'] ['InvoiceAmount'] ['receivedAmount']
foreach ($final_paystage as $key => & $payStage) {
if (isset($arrayData[$key]['invoice_budget']) & & isset($arrayData[$key]['received_budget'])) {
$tmpInvoice = $arrayData[$key]['invoice_budget'];
$tmpReceived = $arrayData[$key]['received_budget'];
for ($sequence = 1; $sequence < = count($payStage); $sequence++) {
$collect_month = collect_month(strtotime($payStage[$sequence]['PlanPayDate']));
if ($tmpInvoice > $payStage[$sequence]['PayAmount']) {
$payStage[$sequence]['InvoiceAmount'] = $payStage[$sequence]['PayAmount'];
$tmpInvoice -= $payStage[$sequence]['PayAmount'];
} else {
$payStage[$sequence]['InvoiceAmount'] = $tmpInvoice;
$tmpInvoice = 0;
}
if ($tmpReceived > $payStage[$sequence]['PayAmount']) {
$payStage[$sequence]['receivedAmount'] = $payStage[$sequence]['PayAmount'];
$tmpReceived -= $payStage[$sequence]['PayAmount'];
} else {
$payStage[$sequence]['receivedAmount'] = $tmpReceived;
$tmpReceived = 0;
}
if ($collect_month > 0) {
// $arrayData[$key]['facility'][$payStage[$sequence]['facilityno']]['receivable_budget']+=$payStage[$sequence]['PayAmount'];
}
if ($collect_month > 0 & & $payStage[$sequence]['PayAmount'] > $payStage[$sequence]['receivedAmount']) {
$payStage[$sequence]['collect_month'] = $collect_month;
} else {
$payStage[$sequence]['collect_month'] = 0;
}
}
if ($value['receivable_budget'] > 0 & & $value['received_budget'] < $value['receivable_budget']) {
$value['month'] = collect_month(strtotime($value['BillDate']));
} else {
$value['month'] = 0;
}
}
// 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 通訊地址
// 11 收款階段名稱 12 應收日期 13 收款金額 14 已開金額 15 已收金額 16 催收次數
$excel_aray = array();
$today = strtotime(date('Ymt'));
foreach ($arrayData as $key => $value) {
if (isset($final_paystage[$key])) {
for ($sequence = 1; $sequence < = count($final_paystage[$key]); $sequence++) {
$value[4] = (isset($value[4]) & & !empty($value[4])) ? $value[4] : '--';
$value[5] = (isset($value[5]) & & !empty($value[5])) ? $value[5] : '--';
$value[6] = (isset($value[6]) & & !empty($value[6])) ? $value[6] : '--';
$value[7] = (isset($value[7]) & & !empty($value[7])) ? $value[7] : '--';
$value[8] = (isset($value[8]) & & !empty($value[8])) ? $value[8] : '--';
$value[11] = (isset($value[11]) & & !empty($value[11])) ? $value[11] : '--';
$value[12] = (isset($value[12]) & & !empty($value[12])) ? date('Y/m/d', strtotime($value[12])) : '--';
$thisPayStage = $final_paystage[$key][$sequence];
$keyname = $key . "/" . $final_paystage[$key][$sequence]['facilityno'] . "/" . $value[5];
$havetopay = ($today >= strtotime($thisPayStage['PlanPayDate'])) ? "V" : "--";
switch ($havetopay) {
case "V":
$unInvoiceAmount = $thisPayStage['PayAmount'] - $thisPayStage['InvoiceAmount'];
$unReceivedAmount = $thisPayStage['PayAmount'] - $thisPayStage['receivedAmount'];
break;
default:
$unInvoiceAmount = 0;
$unReceivedAmount = 0;
break;
}
$excel_aray[$keyname] = [
$value[10], $thisPayStage['facilityno'], $value[0], $value[1], $value[11], $value[2], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8],
$thisPayStage['name'], $thisPayStage['PlanPayDate'], $havetopay,
number_format(round($thisPayStage['PayAmount'])),
number_format(round($thisPayStage['InvoiceAmount'])), number_format(round($unInvoiceAmount)),
number_format(round($thisPayStage['receivedAmount'])), number_format(round($unReceivedAmount)),
number_format(round($thisPayStage['collect_month']))
];
}
}
$uninvoice_budget = $value['OAmountWithTax'] - $value['invoice_budget'];
$unreceive_budget = $value['receivable_budget'] - $value['received_budget'];
$excel_aray[$key] = [
$value['BillNo'], date('Y-m-d', strtotime($value['BillDate'])), $value['CustomerId'], $value['CustomerName'],
$value['DeptName'], $value['PersonId'], $value['PersonName'],
$value['ManagerId'], $value['ManagerName'],
number_format(round($value['OAmountWithTax'])), number_format(round($value['receivable_budget'])),
number_format(round($value['invoice_budget'])), number_format(round($uninvoice_budget)),
number_format(round($value['received_budget'])), $unreceive_budget, $value['month']
];
}
$total_data = json_encode($excel_aray);
//計算總作番數、金額、A40002、A40009、A40010金額與平均
$average_budget = round($sum_total_budget / $sum_facility);
$average_A40002 = round($sum_A40002 / $sum_facility);
$average_A40009 = round($sum_A40009 / $sum_facility);
$average_A40010 = round($sum_A40010 / $sum_facility);
foreach ($arrayData as $key => $data) {
echo $key . "< br > ";
print_r($data);
echo "< br > -----------------------------< br > ";
}
exit();
?>
< style >
table {
@ -673,99 +308,74 @@ exit();
< / div >
< div class = "container" >
< div class = "text-center" style = "margin-bottom: 20px;" >
< h3 > < strong > 合約 (汰改)統整資訊 < / strong > < / h3 >
< h3 > < strong > 零件 & 維修 應收帳款 < / strong > < / h3 >
< / div >
< form class = "form-horizontal" >
< div class = "form-group" >
< div class = "col-md-3" >
< label for = "sum_total_budget" > 合約總金額< / label >
< input type = "text" class = "form-control" id = "sum_total_budget" name = "sum_total_budget" value = " <? = number_format ( $sum_total_budget ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "sum_A40002" > M1總金額< / label >
< input type = "text" class = "form-control" id = "sum_A40002" name = "sum_A40002" value = " <? = number_format ( $sum_A40002 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "sum_A40009" > 設備總金額< / label >
< input type = "text" class = "form-control" id = "sum_A40009" name = "sum_A40009" value = " <? = number_format ( $sum_A40009 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "sum_A40010" > 安裝總金額< / label >
< input type = "text" class = "form-control" id = "sum_A40010" name = "sum_A40010" value = " <? = number_format ( $sum_A40010 ) ?> " disabled >
< / div >
< / div >
< div class = "form-group" >
< div class = "col-md-6" >
< label for = "sum_facility" > 總台數< / label >
< input type = "text" class = "form-control" id = "sum_facility" name = "sum_facility" value = " <? = number_format ( $sum_facility ) ?> " disabled >
< / div >
< / div >
< div class = "form-group" >
< div class = "col-md-3" >
< label for = "average_budget" > 平均金額< / label >
< input type = "text" class = "form-control" id = "average_budget" name = "average_budget" value = " <? = number_format ( $average_budget ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "average_A40002" > M1平均金額< / label >
< input type = "text" class = "form-control" id = "average_A40002" name = "average_A40002" value = " <? = number_format ( $average_A40002 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "average_A40009" > 設備平均金額< / label >
< input type = "text" class = "form-control" id = "average_A40009" name = "average_A40009" value = " <? = number_format ( $average_A40009 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "average_A40010" > 安裝平均金額< / label >
< input type = "text" class = "form-control" id = "average_A40010" name = "average_A40010" value = " <? = number_format ( $average_A40010 ) ?> " disabled >
< / div >
< / div >
< form class = "form-horizontal" id = 'myForm' method = 'post' action = 'account-receivable-repair-index.php? <? = $token_link ?> ' >
< table class = "table table-striped table-bordered" style = 'width:98%;text-align:center;margin:0 auto' >
< tbody >
< tr >
< th class = "text-center" > 合約日期< / th >
< td colspan = "2" >
< input type = "date" class = 'form-control' id = 'date_start' name = 'date_start' style = 'width:40%;display:inline;' >
~
< input type = "date" class = 'form-control' id = 'date_end' name = 'date_end' style = 'width:40%;display:inline;' >
< button type = "submit" class = "btn btn-primary btn-sm" > 搜尋< / button >
< / td >
< / tr >
< / tbody >
< / table >
< / form >
< div class = "form-group" >
< div class = "col-md-3" >
< label for = "sum_total_budget" > 合約總金額< / label >
< input type = "text" class = "form-control" id = "sum_total_budget" name = "sum_total_budget" value = " <? = number_format ( $sum_total_budget ) ?> " disabled >
< / div >
< / div >
< / div >
<?php
include "./footer.php";
?>
< div style = "width: 20%;float:right;margin-right:5%; " >
< label > 查詢條件< / label >
< input type = "text" id = "search" name = "search" class = "form-control" placeholder = "請輸入合約號/作番號/ 客戶名稱" oninput = "searchData()" >
< input type = "text" id = "search" name = "search" class = "form-control" placeholder = "請輸入合約號/客戶名稱" oninput = "searchData()" >
< / div >
< div style = "width: 98%; margin:1%;" style = "overflow-x:auto;" >
< table class = "table table-striped table-bordered" style = "width:100%" >
< thead >
< tr >
< th style = 'text-align:center;vertical-align: middle;width:120px' > 合約號< / th >
< th style = 'text-align:center;vertical-align: middle;width:120px' > 作番號< / th >
< th style = 'text-align:center;vertical-align: middle;width:140px' > 合約號< / th >
< th style = 'text-align:center;vertical-align: middle;width:100px' > 合約日期< / th >
< th style = 'text-align:center;vertical-align: middle;' > 客戶編號< / th >
< th style = 'text-align:center;vertical-align: middle;width:140px' > 客戶名稱< / th >
< th style = 'text-align:center;vertical-align: middle;width:110px' > 部門< / th >
< th style = 'text-align:center;vertical-align: middle;' > 主管< / th >
< th style = 'text-align:center;vertical-align: middle;' > 契約員< / th >
< th style = 'text-align:center;vertical-align: middle;width:130px' > 客戶名稱< / th >
< th style = 'text-align:center;vertical-align: middle;' > 收款階段< / th >
< th style = 'text-align:center;vertical-align: middle;' > 應收日期< / th >
< th style = 'text-align:center;vertical-align: middle;' > 是否應收< / th >
< th style = 'text-align:end;vertical-align: middle;' > 應收金額< / th >
< th style = 'text-align:end;vertical-align: middle;' > 已開金額< / th >
< th style = 'text-align:end;vertical-align: middle;' > 未開金額< / th >
< th style = 'text-align:end;vertical-align: middle;' > 已收金額< / th >
< th style = 'text-align:end;vertical-align: middle;' > 催收金額< / th >
< th style = 'text-align:center;vertical-align: middle;' > 合約總金額< / th >
< th style = 'text-align:center;vertical-align: middle;' > 應收金額< / th >
< th style = 'text-align:center;vertical-align: middle;' > 已開金額< / th >
< th style = 'text-align:center;vertical-align: middle;' > 未開金額< / th >
< th style = 'text-align:center;vertical-align: middle;' > 已收金額< / th >
< th style = 'text-align:center;vertical-align: middle;' > 催收金額< / th >
< th style = 'text-align:center;vertical-align: middle;' > 催收次數< / th >
< / tr >
< / thead >
< tbody >
<?php foreach ( $excel_aray as $key => $row ) { ?>
< tr class = "data-row" style = "display: '';" id = " <? = $key ; ?> " >
< td > <? = $row [ 0 ]; ?> </ td >
< td > <? = $row [ 1 ]; ?> </ td >
< td > <? = $row [ 2 ] . "<br>" . $row [ 3 ]; ?> </ td >
< td > <? = $row [ 4 ] . "<br>" . $row [ 5 ]; ?> </ td >
< td > <? = $row [ 6 ] . "<br>" . $row [ 7 ]; ?> </ td >
< td > <? = $row [ 8 ]; ?> </ td >
< td > <? = $row [ 12 ]; ?> </ td >
< td > <? = $row [ 13 ]; ?> </ td >
< td > <? = $row [ 14 ]; ?> </ td >
< td > <? = $row [ 15 ]; ?> </ td >
< td > <? = $row [ 16 ]; ?> </ td >
< td > <? = $row [ 17 ]; ?> </ td >
< td > <? = $row [ 18 ]; ?> </ td >
< td > <? = $row [ 19 ]; ?> </ td >
< td > <? = $row [ 20 ]; ?> </ td >
< td style = 'text-align:center;vertical-align: middle;' > <? = $row [ 0 ]; ?> </ td >
< td style = 'text-align:center;vertical-align: middle;' > <? = $row [ 1 ]; ?> </ td >
< td style = 'text-align:center;vertical-align: middle;' > <? = $row [ 2 ] ?> </ td >
< td style = 'text-align:center;vertical-align: middle;' > <? = $row [ 3 ] ?> </ td >
< td style = 'text-align:center;vertical-align: middle;' > <? = $row [ 4 ] ?> </ td >
< td style = 'text-align:center;vertical-align: middle;' > <? = $row [ 7 ] . "<br>" . $row [ 8 ]; ?> </ td >
< td style = 'text-align:center;vertical-align: middle;' > <? = $row [ 5 ] . "<br>" . $row [ 6 ]; ?> </ td >
< td style = 'text-align:end;vertical-align: middle;' > <? = $row [ 9 ]; ?> </ td >
< td style = 'text-align:end;vertical-align: middle;' > <? = $row [ 10 ]; ?> </ td >
< td style = 'text-align:end;vertical-align: middle;' > <? = $row [ 11 ]; ?> </ td >
< td style = 'text-align:end;vertical-align: middle;' > <? = $row [ 12 ]; ?> </ td >
< td style = 'text-align:end;vertical-align: middle;' > <? = $row [ 13 ]; ?> </ td >
< td style = 'text-align:end;vertical-align: middle;' > <? = $row [ 14 ]; ?> </ td >
< td style = 'text-align:end;vertical-align: middle;' > <? = $row [ 15 ]; ?> </ td >
< / tr >
<?php } ?>
< / tbody >
@ -778,7 +388,6 @@ include "./footer.php";
var rows = document.getElementsByClassName('data-row');
for (var i = 0; i < rows.length ; i + + ) {
var rowText = rows[i].textContent.toLowerCase();
// var rowText = rows[i].id.toLowerCase();
if (rowText.includes(searchTerm)) {
console.log(rowText);
rows[i].style.display = '';
@ -790,15 +399,15 @@ include "./footer.php";
function downloadData() {
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/account-receivable-renovate-excel.php?type=all & <? = $token_link ?> ";
var url = window.location.origin + "/wms/account-receivable-renovate-excel.php?type=repair & <? = $token_link ?> ";
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 & & xhr.status === 200) {
var file_path = xhr.responseText;
var link = document.createElement('a');
var name = "汰改 應收帳款" + "<? = date ( 'Y-m-d-Hm' ) ?> " + ".xlsx";
link.setAttribute('href', window.location.origin + "/wms/account-receivable-renovate .xlsx");
var name = "零件& 修理 應收帳款" + "<? = date ( 'Y-m-d-Hm' ) ?> " + ".xlsx";
link.setAttribute('href', window.location.origin + "/wms/account-receivable-repair .xlsx");
link.setAttribute('download', name);
link.style.display = 'none';
document.body.appendChild(link);