diff --git a/wms/account-receivable-repair-index.php b/wms/account-receivable-repair-index.php index 475999f0..49d50385 100644 --- a/wms/account-receivable-repair-index.php +++ b/wms/account-receivable-repair-index.php @@ -15,28 +15,89 @@ $average_A40002 = 0; $average_A40009 = 0; $average_A40010 = 0; +/* 比較應收日期 +@param $a array +@param $b array +return int */ +function comparePlanPayDate($a, $b) +{ + return strtotime($a['PlanPayDate']) - strtotime($b['PlanPayDate']); +} + +// 查WMS 契約員主管 +$sql_manager = "SELECT A.accountid, A.name, A.manager, B.name AS manager_name FROM account AS A +LEFT JOIN account AS B ON A.manager = B.accountid "; +$managers = mysqli_query($link, $sql_manager); + +$find_manager = array(); +foreach ($managers as $manager) { + $find_manager[$manager['accountid']] = $manager; +} $follower = find_follow($user_id); -$arrayData = []; +$arrayData = array(); $receivable_array = []; // T8所有合約號 -$sql_contractNumber = "SELECT Distinct BillNo FROM salSalesOrder WHERE TypeId = 'SP' AND (CurrentState=2 OR CurrentState=4) "; +$sql_contractNumber = "SELECT MainAll.* , +Person.PersonName, +Dept.DeptName FROM + (SELECT +Main.BillNo, +Main.BillDate, +Main.BizPartnerId, +Biz.ShortName, +Biz.BizPartnerName, +Biz.ContactAddress, +Main.OAmountWithTax, +Main.PersonId, +Main.DeptId, +Main.TypeId, +Main.CurrentState + FROM salSalesOrder AS Main + LEFT JOIN comBusinessPartner AS Biz ON Biz.BizPartnerId = Main.BizPartnerId) AS MainAll + 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 ((in_array($user_id, array('M0008', 'M0012'))) || (in_array(accountidToDepartId($user_id), array('220', '210', '501')))) { +} else { + $sql_contractNumber .= " AND (MainAll.PersonId = '$user_id'"; + if (count($follower) > 0) { + $column_str = "('$user_id'" . ",'"; + $column_str .= implode("','", $follower); + $column_str .= "')"; + $sql_contractNumber .= " OR MainAll.PersonId IN $column_str)"; + } else { + $sql_contractNumber .= ")"; + }; +} -// 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 "; +$contractNumbers = array(); +$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']; + } + $str_numbers = "('" . implode("','", $contractNumbers) . "')"; +} // T8發票 (有專案的發票) -$sql_invoice = "SELECT DISTINCT -a.InvoiceNo, a.InvoiceTime,a.OAmountWithTax,a.InvoiceState, -b.FromSalSalesOrder -FROM arSellInvoice as a -LEFT JOIN (SELECT CH.FromSalSalesOrder, SE.* FROM arSellInvoiceMaterial AS SE -LEFT JOIN arCheckBillDetail AS CH ON SE.FromBillNo=CH.BillNo) as b -ON a.BillNo=b.BillNo -WHERE DATALENGTH(b.FromSalSalesOrder)>0 -ORDER BY InvoiceTime ASC"; +$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_received = "SELECT @@ -58,48 +119,86 @@ ON a.BillNo=c.BillNo WHERE DATALENGTH(c.OrderBillNo) >0"; -// 期初收款資訊 -$sql_opening = " -SELECT * FROM account_received "; -// 設定權限:看到自己的/下屬的,資訊處跟財會處可以看全部的 -if ((in_array($user_id, array('M0060', 'M0175'))) || (in_array(accountidToDepartId($user_id), array('220', '210')))) { -} else { - $sql_opening .= " OR person_id = '$user_id'"; - $sql_contractNumber .= " AND (PersonId = '$user_id'"; - if (count($follower) > 0) { - $column_str = "('$user_id'" . ",'"; - $column_str .= implode("','", $follower); - $column_str .= "')"; - $sql_contractNumber .= " OR PersonId IN $column_str)"; - $sql_opening .= " OR person_id IN $column_str)"; - } else { - $sql_opening .= ")"; - $sql_contractNumber .= ")"; - }; +//T8 銷售訂單 階段收款計畫 +$sql_paystage = "SELECT * from salOrderStagePay"; +if (isset($str_numbers)) { + $sql_paystage .= " WHERE BillNo IN $str_numbers "; + $sql_invoice .= " AND CheckAll.FromSalSalesOrder IN $str_numbers "; } -$contractNumbers = array(); -$query_contract_number = $conn->query($sql_contractNumber); -foreach ($query_contract_number as $contract_numbers) { - array_push($contractNumbers, $contract_numbers['BillNo']); - $str_numbers = "('" . implode("','", $contractNumbers) . "')"; +$PayStage = $conn->query($sql_paystage); +$received_array = $conn->query($sql_received); +$invoice_data = $conn->query($sql_invoice); + +$allPayStages = array(); +foreach ($PayStage as $stage) { + $allPayStages[$stage['BillNo']][$stage['PayStage']]['PlanPayAmt'] = $stage['PlanPayAmt']; + $allPayStages[$stage['BillNo']][$stage['PayStage']]['PlanPayDate'] = $stage['PlanPayDate']; } -//T8 銷售訂單 階段收款計畫 -$sql_contract = "SELECT a.BillNo,s.BillDate, a.RowNo, a.PayStage, a.PlanPayAmt, a.PlanPayDate,s.BizPartnerId,c.BizPartnerName, s.PersonId, s.DeptId, s.DeptName, -c.EnterpriseName, c.TaxNo, c.ContactAddress FROM salOrderStagePay AS a -LEFT JOIN (SELECT O.*, DE.DeptName FROM salSalesOrder AS O LEFT JOIN comDepartment AS DE ON O.DeptId=DE.DeptId) AS s on a.BillNo = s.BillNo -LEFT JOIN comBusinessPartner AS c ON s.BizPartnerId=c.BizPartnerId "; -if (isset($str_numbers)) { - $sql_contract .= "WHERE s.BillNo IN $str_numbers "; +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) { + if (isset($arrayData[$key])) { + $arrayData[$key]['PayStage'][$pstage['sequenceNumber']] = $pstage; + } + } + } +} +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']; + } + if (isset($arrayData[$inv['BillNo']]['invoice'][$inv['InvoiceNo']])) { + $arrayData[$inv['BillNo']]['invoice'][$inv['InvoiceNo']] += $inv['LAmountWithTax']; + } else { + $arrayData[$inv['BillNo']]['invoice'][$inv['InvoiceNo']] = $inv['LAmountWithTax']; + } + } +} +foreach($arrayData as $key => &$value){ + echo $key."
"; + echo "
-------
"; + if(isset($value['invoice'])){ + foreach($value['invoice'] as $invkey => $invvalue){ + echo $invkey."
"; + echo $invvalue."
"; + } + } + echo "
---------------------------
"; +} + + +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 = $conn->query($sql_contract); + $contract_data = array(); -$manager_list = array(); // 將T8合約收款階段資料依據款別分類放進arraData裡 foreach ($contract as $cont) { $BillNo = $cont['BillNo']; @@ -113,10 +212,6 @@ foreach ($contract as $cont) { $ContactAddress = $cont['ContactAddress']; $RowNo = $cont['RowNo']; $salesId = $cont['PersonId']; - if (!in_array($salesId, $manager_list)) { - array_push($manager_list, $salesId); - } - //['type'] A:比照新梯、B:純分期、C:其他 //['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 min 最早應收月份 max 最晚應收月份 ['second'] 0 二次款名 1 二次款金額 2 收款日期 ['arrive'] 0 貨抵工地款名稱 1 貨抵工地款金額 2 貨抵工地收款日期 ['install'] 0 安裝款名 1 安裝金額 2 安裝收款日期 @@ -159,20 +254,10 @@ foreach ($contract as $cont) { $arrayData[$BillNo]['PayStage'][$RowNo]['type'] = "C"; } } -$received_array = $conn->query($sql_received); -$opening_data = mysqli_query($link, $sql_opening); -$invoice_data = $conn->query($sql_invoice); + $contract_budget_data = $conn->query($sql_contract_budget); -// 查WMS 契約員主管 -$sql_manager = "SELECT A.accountid, A.name, A.manager, B.name AS manager_name FROM account AS A -LEFT JOIN account AS B ON A.manager = B.accountid "; -$managers = mysqli_query($link, $sql_manager); -$find_manager = array(); -foreach ($managers as $manager) { - $find_manager[$manager['accountid']] = $manager; -} // 將T8銷售訂單明細 每個作番金額存入arrayData $contract_budget = array(); foreach ($contract_budget_data as $cont) { @@ -185,11 +270,24 @@ foreach ($contract_budget_data as $cont) { $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; @@ -236,21 +334,164 @@ function get_contract_ratio($facility_no, $contract_budget_billno) return $ratio; } -/* 比較應收日期 -@param $a array -@param $b array -return int */ -function comparePlanPayDate($a, $b) -{ - return strtotime($a['PlanPayDate']) - strtotime($b['PlanPayDate']); -} //取作番大日程作番與時程 進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; + } + } + if (isset($allPayStages[$value[10]])) { + $allPayStages[$value[10]] = array_merge($allPayStages[$value[10]], $facility['PayStage']); + } else { + $allPayStages[$value[10]] = $facility['PayStage']; + } + } + } + } +} foreach ($allPayStages as $paykey => $pay) { uasort($allPayStages[$paykey], 'comparePlanPayDate'); } @@ -366,7 +607,18 @@ foreach ($arrayData as $key => $value) { } } $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 . "
"; + print_r($data); + echo "
-----------------------------
"; +} +exit(); ?>