diff --git a/wms/account-receivable-renovate-excel.php b/wms/account-receivable-renovate-excel.php new file mode 100644 index 00000000..77341d5a --- /dev/null +++ b/wms/account-receivable-renovate-excel.php @@ -0,0 +1,42 @@ +getActiveSheet(); +// file_put_contents('account-receivable.txt', json_encode($Bill)); + +$colomnHeader = [ + '合約號', '作番號', '部門編號', '部門名稱', '主管工號','主管名稱', '營業員工號', '營業員名稱', '客戶名稱', '抬頭', '統編', '通訊地址', + '收款階段名稱', '應收日期','是否應收', '應收金額', '已開金額','未開金額', '已收金額','催收金額', '催收次數' +]; +$sheet->fromArray($colomnHeader, NULL, 'A1'); +$rowIndex = 2; +foreach ($Bill as $key => $value) { + + $sheet->fromArray($value, NULL, 'A' . $rowIndex); + $column = [ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R','S','T' + ]; + foreach ($column as $col) { + $sheet->getColumnDimension($col)->setAutoSize(true); + } + $rowIndex++; +} +$writer = new Xlsx($spreadsheet); +$excelFileName = 'account-receivable-renovate.xlsx'; +$writer->save($excelFileName); + +echo $excelFileName; +?> + \ No newline at end of file diff --git a/wms/account-receivable-renovate-index.php b/wms/account-receivable-renovate-index.php index 08777c0a..63c1f588 100644 --- a/wms/account-receivable-renovate-index.php +++ b/wms/account-receivable-renovate-index.php @@ -25,11 +25,12 @@ $sql_contractNumber = "SELECT Distinct BillNo FROM salSalesOrder WHERE ModeId = // T8發票 (有專案的發票) $sql_invoice = "SELECT DISTINCT a.InvoiceNo, a.InvoiceTime,a.OAmountWithTax,a.InvoiceState, -b.ProjectId +b.FromSalSalesOrder FROM arSellInvoice as a -LEFT JOIN arSellInvoiceMaterial as b +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.ProjectId)>0 +WHERE DATALENGTH(b.FromSalSalesOrder)>0 ORDER BY InvoiceTime ASC"; // T8核銷 @@ -61,11 +62,9 @@ SELECT * FROM account_received "; // 設定權限:看到自己的/下屬的,資訊處跟財會處可以看全部的 if ((in_array($user_id, array('M0060', 'M0175'))) || (in_array(accountidToDepartId($user_id), array('220', '210')))) { } else { - $sql_contract .= "AND (s.PersonId = '$user_id'"; // $sql_received .= " AND (PersonId = '$user_id'"; $sql_opening .= " OR person_id = '$user_id'"; $sql_contractNumber .= " AND (PersonId = '$user_id'"; - $sql_contract_budget .= " AND (PersonId = '$user_id'"; if (count($follower) > 0) { $column_str = "('$user_id'" . ",'"; $column_str .= implode("','", $follower); @@ -76,7 +75,6 @@ if ((in_array($user_id, array('M0060', 'M0175'))) || (in_array(accountidToDepart $sql_opening .= " OR person_id IN $column_str)"; // $sql_contract_budget .= " OR PersonId IN $column_str )ORDER BY BillNo, CU_MaterialId"; } else { - $sql_contract .= ")"; // $sql_received .= ")"; $sql_opening .= ")"; $sql_contractNumber .= ")"; @@ -128,19 +126,25 @@ FROM department ON d.department_id = tmp2.department_id"; //T8 銷售訂單 階段收款計畫 -$sql_contract = "SELECT a.BillNo,s.BillDate, a.RowNo, a.PayStage, a.PlanPayAmt, a.PlanPayDate,s.BizPartnerId,c.BizPartnerName, s.PersonId, +$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 salSalesOrder AS s on a.BillNo = s.BillNo -LEFT JOIN comBusinessPartner AS c ON s.BizPartnerId=c.BizPartnerId -WHERE s.BillNo IN $str_numbers "; +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 "; +} + // 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 AND A.BillNo IN $str_numbers "; - +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']; @@ -153,6 +157,11 @@ foreach ($contract as $cont) { $TaxNo = $cont['TaxNo']; $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 安裝收款日期 @@ -161,6 +170,9 @@ foreach ($contract as $cont) { 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; @@ -197,11 +209,26 @@ $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) { $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']; $arrayData[$BillNo][$cont['MaterialId']] += $cont['OAmountWithTax']; if (isset($arrayData[$BillNo]['facility'][$cont['CU_MaterialId']])) { @@ -273,11 +300,11 @@ 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']][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']]['A40001'] = (isset($contract_budget[$wip['contractno']]['A40001']) && !is_null($contract_budget[$wip['contractno']]['A40001'])) ? $contract_budget[$wip['contractno']]['A40001'] : 0; $arrayData[$wip['contractno']]['A40008'] = (isset($contract_budget[$wip['contractno']]['A40008']) && !is_null($contract_budget[$wip['contractno']]['A40008'])) ? $contract_budget[$wip['contractno']]['A40008'] : 0; @@ -299,120 +326,122 @@ $sign_array = ['訂金', '簽約', '合約']; // 將所有facility的paystage放入一個array以便計算順序 $allPayStages = []; foreach ($arrayData as &$value) { - if (is_iterable($value['facility'])) { + if (isset($value['facility']) && is_iterable($value['facility'])) { foreach ($value['facility'] as $fakey => &$facility) { - $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); - $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); - $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); - $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); - $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); - $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); - $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); - $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); - $facility['PayStage'][$stage]['PlanPayDate'] = date("Ymd", strtotime("+ $haveNumber months", strtotime($wipwhole_status[$fakey]['real_contract_arrival_date']))); - } - break; - default: - break; - }; - default: - break; + 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); + $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); + $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); + $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); + $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); + $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); + $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); + $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); + $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']; } - } - if (isset($allPayStages[$value[10]])) { - $allPayStages[$value[10]] = array_merge($allPayStages[$value[10]], $facility['PayStage']); - } else { - $allPayStages[$value[10]] = $facility['PayStage']; } } } @@ -440,9 +469,9 @@ foreach ($allPayStages as $key => &$payStage) { // [invoice][發票號碼][0 發票日期, 1 發票金額, 2 發票狀態, 3 收款日期, 4 收款金額, 5 手續費, 6 核銷單號] foreach ($invoice_data as $invoice) { - if (isset($arrayData[$invoice['ProjectId']])) { - $arrayData[$invoice['ProjectId']]['invoice_budget'] += intval($invoice['OAmountWithTax']); - $arrayData[$invoice['ProjectId']]['invoice'][$invoice['InvoiceNo']] = [date("Ymd", strtotime($invoice['InvoiceTime'])), $invoice['OAmountWithTax'], $invoice['InvoiceState']]; + 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']]; } } @@ -457,34 +486,34 @@ foreach ($received_array as $received) { } } // $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'])){ +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++){ + for ($sequence = 1; $sequence <= count($payStage); $sequence++) { $collect_month = collect_month(strtotime($payStage[$sequence]['PlanPayDate'])); - if($tmpInvoice >$payStage[$sequence]['PayAmount']){ + if ($tmpInvoice > $payStage[$sequence]['PayAmount']) { $payStage[$sequence]['InvoiceAmount'] = $payStage[$sequence]['PayAmount']; $tmpInvoice -= $payStage[$sequence]['PayAmount']; - }else{ + } else { $payStage[$sequence]['InvoiceAmount'] = $tmpInvoice; $tmpInvoice = 0; } - if($tmpReceived >$payStage[$sequence]['PayAmount']){ + if ($tmpReceived > $payStage[$sequence]['PayAmount']) { $payStage[$sequence]['receivedAmount'] = $payStage[$sequence]['PayAmount']; $tmpReceived -= $payStage[$sequence]['PayAmount']; - }else{ + } else { $payStage[$sequence]['receivedAmount'] = $tmpReceived; $tmpReceived = 0; } - if($collect_month>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']){ + if ($collect_month > 0 && $payStage[$sequence]['PayAmount'] > $payStage[$sequence]['receivedAmount']) { $payStage[$sequence]['collect_month'] = $collect_month; - }else{ + } else { $payStage[$sequence]['collect_month'] = 0; } } @@ -499,164 +528,71 @@ foreach($final_paystage as $key => &$payStage){ // echo "---------------------
"; // } -foreach ($arrayData as &$value) { - // if (is_iterable($value['facility'])) { - // foreach ($value['facility'] as $fakey => &$facility) { - // // foreach ($facility['PayStage'] as $index => &$payStage) { - // // // $payStage['sequenceNumber'] = $allPayStages[$value[10]][$index]['sequenceNumber']; - // // echo $index." => "; - // // print_r($payStage); - // // echo "
"; - // // } - // echo $fakey." => "; - // print_r($facility); - // echo "
"; - // } - // } - print_r($value); - echo "---------------------
"; -} -exit(); -//========================================================================================================================================================= - - -//產生excel的array +// foreach ($arrayData as &$value) { +// if (is_iterable($value['facility'])) { +// foreach ($value['facility'] as $fakey => &$facility) { +// // foreach ($facility['PayStage'] as $index => &$payStage) { +// // // $payStage['sequenceNumber'] = $allPayStages[$value[10]][$index]['sequenceNumber']; +// // echo $index." => "; +// // print_r($payStage); +// // echo "
"; +// // } +// echo $fakey." => "; +// print_r($facility); +// echo "
"; +// } +// } +// print_r($value); +// echo "---------------------
"; +// } +// foreach ($final_paystage as $key => $payStage) { +// echo $key . "
"; +// for ($sequence = 1; $sequence <= count($payStage); $sequence++) { +// print_r($payStage[$sequence]); +// echo "
"; +// } +// echo "---------------------
"; +// } +// exit(); +// 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(); -$boga_array = array(); -$exclude_boga_array = array(); -$facility_array = array(); -$facility_boga_array = array(); -$facility_exclude_boga_array = array(); +$today = strtotime(date('Ymt')); foreach ($arrayData as $key => $value) { - $sum_A40001 += isset($value['A40001']) ? $value['A40001'] : 0; - $sum_A40008 += isset($value['A40008']) ? $value['A40008'] : 0; - $sum_total_budget += $value['total_budget']; - $sum_facility += $value['total_facility_num']; - $value['sign'][3] = (isset($value['sign'][3])) ? $value['sign'][3] : 0; - $value['second'][3] = (isset($value['second'][3])) ? $value['second'][3] : 0; - $value['arrive'][3] = (isset($value['arrive'][3])) ? $value['arrive'][3] : 0; - $value['install'][3] = (isset($value['install'][3])) ? $value['install'][3] : 0; - $value['tryrun'][3] = (isset($value['tryrun'][3])) ? $value['tryrun'][3] : 0; - $value['check'][3] = (isset($value['check'][3])) ? $value['check'][3] : 0; - $value['delivery'][3] = (isset($value['delivery'][3])) ? $value['delivery'][3] : 0; - $value['final'][3] = (isset($value['final'][3])) ? $value['final'][3] : 0; - $value[9] = (isset($value[9])) ? Date('Ymd', strtotime($value[9])) : 0; - $contractstage = array('sign', 'second', 'arrive', 'install', 'tryrun', 'check', 'delivery', 'final'); - foreach ($contractstage as $i) { - $value[$i]['max'] = (empty($value[$i]['max']) || is_null($value[$i]['max'])) ? 0 : $value[$i]['max']; - $value[$i]['min'] = (empty($value[$i]['min']) || is_null($value[$i]['min'])) ? 0 : $value[$i]['min']; - $value[$i][4] = (isset($value[$i][4])) ? $value[$i][4] : 0; - $value[$i][5] = (isset($value[$i][5])) ? $value[$i][5] : 0; - $value['A40001'] = (isset($value['A40001'])) ? $value['A40001'] : 0; - $value['A40008'] = (isset($value['A40008'])) ? $value['A40008'] : 0; - }; - - if (isset($value['sign'][0]) && $value['sign'][0] == "寶佳出貨前30天") { - $boga_array[$key] = [ - $value[9], $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], - number_format(round($value['sign'][1])), number_format(round($value['sign'][3])), number_format(round($value['sign'][6])), number_format(round($value['sign'][7])), number_format(round($value['sign'][4])), number_format(round($value['sign'][5])), $value['sign']['max'], $value['sign']['min'], - number_format(round($value['second'][1])), number_format(round($value['second'][3])), number_format(round($value['second'][6])), number_format(round($value['second'][7])), number_format(round($value['second'][4])), number_format(round($value['second'][5])), $value['second']['max'], $value['second']['min'], - number_format(round($value['arrive'][1])), number_format(round($value['arrive'][3])), number_format(round($value['arrive'][6])), number_format(round($value['arrive'][7])), number_format(round($value['arrive'][4])), number_format(round($value['arrive'][5])), $value['arrive']['max'], $value['arrive']['min'], - number_format(round($value['install'][1])), number_format(round($value['install'][3])), number_format(round($value['install'][6])), number_format(round($value['install'][7])), number_format(round($value['install'][4])), number_format(round($value['install'][5])), $value['install']['max'], $value['install']['min'], - number_format(round($value['tryrun'][1])), number_format(round($value['tryrun'][3])), number_format(round($value['tryrun'][6])), number_format(round($value['tryrun'][7])), number_format(round($value['tryrun'][4])), number_format(round($value['tryrun'][5])), $value['tryrun']['max'], $value['tryrun']['min'], - number_format(round($value['check'][1])), number_format(round($value['check'][3])), number_format(round($value['check'][6])), number_format(round($value['check'][7])), number_format(round($value['check'][4])), number_format(round($value['check'][5])), $value['check']['max'], $value['check']['min'], - number_format(round($value['delivery'][1])), number_format(round($value['delivery'][3])), number_format(round($value['delivery'][6])), number_format(round($value['delivery'][7])), number_format(round($value['delivery'][4])), number_format(round($value['delivery'][5])), $value['delivery']['max'], $value['delivery']['min'], - number_format(round($value['final'][1])), number_format(round($value['final'][3])), number_format(round($value['final'][6])), number_format(round($value['final'][7])), number_format(round($value['final'][4])), number_format(round($value['final'][5])), $value['final']['max'], $value['final']['min'], - number_format(round($value['A40001'])), number_format(round($value['A40008'])), number_format(round($value['total_budget'])), number_format(round($value['receivable_budget'])), number_format(round($value['invoice_budget'])), number_format(round($value['received_budget'])), $value['total_facility_num'], str_replace('
', '; ', $value['facilities']) - ]; - } else { - $exclude_boga_array[$key] = [ - $value[9], $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], - number_format(round($value['sign'][1])), number_format(round($value['sign'][3])), number_format(round($value['sign'][6])), number_format(round($value['sign'][7])), number_format(round($value['sign'][4])), number_format(round($value['sign'][5])), $value['sign']['max'], $value['sign']['min'], - number_format(round($value['second'][1])), number_format(round($value['second'][3])), number_format(round($value['second'][6])), number_format(round($value['second'][7])), number_format(round($value['second'][4])), number_format(round($value['second'][5])), $value['second']['max'], $value['second']['min'], - number_format(round($value['arrive'][1])), number_format(round($value['arrive'][3])), number_format(round($value['arrive'][6])), number_format(round($value['arrive'][7])), number_format(round($value['arrive'][4])), number_format(round($value['arrive'][5])), $value['arrive']['max'], $value['arrive']['min'], - number_format(round($value['install'][1])), number_format(round($value['install'][3])), number_format(round($value['install'][6])), number_format(round($value['install'][7])), number_format(round($value['install'][4])), number_format(round($value['install'][5])), $value['install']['max'], $value['install']['min'], - number_format(round($value['tryrun'][1])), number_format(round($value['tryrun'][3])), number_format(round($value['tryrun'][6])), number_format(round($value['tryrun'][7])), number_format(round($value['tryrun'][4])), number_format(round($value['tryrun'][5])), $value['tryrun']['max'], $value['tryrun']['min'], - number_format(round($value['check'][1])), number_format(round($value['check'][3])), number_format(round($value['check'][6])), number_format(round($value['check'][7])), number_format(round($value['check'][4])), number_format(round($value['check'][5])), $value['check']['max'], $value['check']['min'], - number_format(round($value['delivery'][1])), number_format(round($value['delivery'][3])), number_format(round($value['delivery'][6])), number_format(round($value['delivery'][7])), number_format(round($value['delivery'][4])), number_format(round($value['delivery'][5])), $value['delivery']['max'], $value['delivery']['min'], - number_format(round($value['final'][1])), number_format(round($value['final'][3])), number_format(round($value['final'][6])), number_format(round($value['final'][7])), number_format(round($value['final'][4])), number_format(round($value['final'][5])), $value['final']['max'], $value['final']['min'], - number_format(round($value['A40001'])), number_format(round($value['A40008'])), number_format(round($value['total_budget'])), number_format(round($value['receivable_budget'])), number_format(round($value['invoice_budget'])), number_format(round($value['received_budget'])), $value['total_facility_num'], str_replace('
', '; ', $value['facilities']) - ]; - } - - $excel_aray[$key] = [ - $value[9], $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], - number_format(round($value['sign'][1])), number_format(round($value['sign'][3])), number_format(round($value['sign'][6])), number_format(round($value['sign'][7])), number_format(round($value['sign'][4])), number_format(round($value['sign'][5])), $value['sign']['max'], $value['sign']['min'], - number_format(round($value['second'][1])), number_format(round($value['second'][3])), number_format(round($value['second'][6])), number_format(round($value['second'][7])), number_format(round($value['second'][4])), number_format(round($value['second'][5])), $value['second']['max'], $value['second']['min'], - number_format(round($value['arrive'][1])), number_format(round($value['arrive'][3])), number_format(round($value['arrive'][6])), number_format(round($value['arrive'][7])), number_format(round($value['arrive'][4])), number_format(round($value['arrive'][5])), $value['arrive']['max'], $value['arrive']['min'], - number_format(round($value['install'][1])), number_format(round($value['install'][3])), number_format(round($value['install'][6])), number_format(round($value['install'][7])), number_format(round($value['install'][4])), number_format(round($value['install'][5])), $value['install']['max'], $value['install']['min'], - number_format(round($value['tryrun'][1])), number_format(round($value['tryrun'][3])), number_format(round($value['tryrun'][6])), number_format(round($value['tryrun'][7])), number_format(round($value['tryrun'][4])), number_format(round($value['tryrun'][5])), $value['tryrun']['max'], $value['tryrun']['min'], - number_format(round($value['check'][1])), number_format(round($value['check'][3])), number_format(round($value['check'][6])), number_format(round($value['check'][7])), number_format(round($value['check'][4])), number_format(round($value['check'][5])), $value['check']['max'], $value['check']['min'], - number_format(round($value['delivery'][1])), number_format(round($value['delivery'][3])), number_format(round($value['delivery'][6])), number_format(round($value['delivery'][7])), number_format(round($value['delivery'][4])), number_format(round($value['delivery'][5])), $value['delivery']['max'], $value['delivery']['min'], - number_format(round($value['final'][1])), number_format(round($value['final'][3])), number_format(round($value['final'][6])), number_format(round($value['final'][7])), number_format(round($value['final'][4])), number_format(round($value['final'][5])), $value['final']['max'], $value['final']['min'], - number_format(round($value['A40001'])), number_format(round($value['A40008'])), number_format(round($value['total_budget'])), number_format(round($value['receivable_budget'])), number_format(round($value['invoice_budget'])), number_format(round($value['received_budget'])), $value['total_facility_num'], str_replace('
', '; ', $value['facilities']) - ]; - - //['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 min 最早應收月份 max 最晚應收月份 - //[合約號]['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數 - if (isset($value['facility'])) { - foreach ($value['facility'] as $valkey => $val) { - foreach ($contractstage as $stage) { - $val[$stage][0] = (!(isset($val[$stage][0])) || is_null($val[$stage][0])) ? "-" : $val[$stage][0]; - $val[$stage][1] = (!(isset($val[$stage][1])) || is_null($val[$stage][1])) ? 0 : $val[$stage][1]; - $val[$stage][2] = (!(isset($val[$stage][2])) || is_null($val[$stage][2])) ? "-" : $val[$stage][2]; - $val[$stage][3] = (!(isset($val[$stage][3])) || is_null($val[$stage][3])) ? 0 : $val[$stage][3]; - $val[$stage][4] = (!(isset($val[$stage][4])) || is_null($val[$stage][4])) ? 0 : $val[$stage][4]; - $val[$stage][5] = (!(isset($val[$stage][5])) || is_null($val[$stage][5])) ? 0 : $val[$stage][5]; - $val[$stage][6] = (!(isset($val[$stage][6])) || is_null($val[$stage][6])) ? 0 : $val[$stage][6]; + if (isset($final_paystage[$key])) { + for ($sequence = 1; $sequence <= count($final_paystage[$key]); $sequence++) { + $keyname = $key . $final_paystage[$key][$sequence]['sequenceNumber']; + $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]; + $havetopay = ($today >= $thisPayStage['PlanPayDate']) ? "V" : "--"; + switch ($havetopay) { + case "V": + $unInvoiceAmount = $thisPayStage['PayAmount'] - $thisPayStage['InvoiceAmount']; + $unReceivedAmount = $thisPayStage['PayAmount'] - $thisPayStage['receivedAmount']; + break; + default: + break; } - $facility_array[$valkey] = [ - $value[9], $valkey, $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], - $val['sign'][0], number_format(round($val['sign'][1])), $val['sign'][2], number_format(round($val['sign'][3])), number_format(round($val['sign'][4])), number_format(round($val['sign'][5])), number_format(round($val['sign'][6])), - $val['second'][0], number_format(round($val['second'][1])), $val['second'][2], number_format(round($val['second'][3])), number_format(round($val['second'][4])), number_format(round($val['second'][5])), number_format(round($val['second'][6])), - $val['arrive'][0], number_format(round($val['arrive'][1])), $val['arrive'][2], number_format(round($val['arrive'][3])), number_format(round($val['arrive'][4])), number_format(round($val['arrive'][5])), number_format(round($val['arrive'][6])), - $val['install'][0], number_format(round($val['install'][1])), $val['install'][2], number_format(round($val['install'][3])), number_format(round($val['install'][4])), number_format(round($val['install'][5])), number_format(round($val['install'][6])), - $val['tryrun'][0], number_format(round($val['tryrun'][1])), $val['tryrun'][2], number_format(round($val['tryrun'][3])), number_format(round($val['tryrun'][4])), number_format(round($val['tryrun'][5])), number_format(round($val['tryrun'][6])), - $val['check'][0], number_format(round($val['check'][1])), $val['check'][2], number_format(round($val['check'][3])), number_format(round($val['check'][4])), number_format(round($val['check'][5])), number_format(round($val['check'][6])), - $val['delivery'][0], number_format(round($val['delivery'][1])), $val['delivery'][2], number_format(round($val['delivery'][3])), number_format(round($val['delivery'][4])), number_format(round($val['delivery'][5])), number_format(round($val['delivery'][6])), - $val['final'][0], number_format(round($val['final'][1])), $val['final'][2], number_format(round($val['final'][3])), number_format(round($val['final'][4])), number_format(round($val['final'][5])), number_format(round($val['final'][6])), - str_replace('
', '; ', $val['status']), number_format(round($val['A40001'])), number_format(round($val['A40008'])), number_format(round($val['total_budget'])), number_format(round($val['receivable_budget'])) + $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'])) + ]; - if ($value['sign'][0] == "寶佳出貨前30天") { - $facility_boga_array[$valkey] = [ - $value[9], $valkey, $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], - $val['sign'][0], number_format(round($val['sign'][1])), $val['sign'][2], number_format(round($val['sign'][3])), number_format(round($val['sign'][4])), number_format(round($val['sign'][5])), number_format(round($val['sign'][6])), - $val['second'][0], number_format(round($val['second'][1])), $val['second'][2], number_format(round($val['second'][3])), number_format(round($val['second'][4])), number_format(round($val['second'][5])), number_format(round($val['second'][6])), - $val['arrive'][0], number_format(round($val['arrive'][1])), $val['arrive'][2], number_format(round($val['arrive'][3])), number_format(round($val['arrive'][4])), number_format(round($val['arrive'][5])), number_format(round($val['arrive'][6])), - $val['install'][0], number_format(round($val['install'][1])), $val['install'][2], number_format(round($val['install'][3])), number_format(round($val['install'][4])), number_format(round($val['install'][5])), number_format(round($val['install'][6])), - $val['tryrun'][0], number_format(round($val['tryrun'][1])), $val['tryrun'][2], number_format(round($val['tryrun'][3])), number_format(round($val['tryrun'][4])), number_format(round($val['tryrun'][5])), number_format(round($val['tryrun'][6])), - $val['check'][0], number_format(round($val['check'][1])), $val['check'][2], number_format(round($val['check'][3])), number_format(round($val['check'][4])), number_format(round($val['check'][5])), number_format(round($val['check'][6])), - $val['delivery'][0], number_format(round($val['delivery'][1])), $val['delivery'][2], number_format(round($val['delivery'][3])), number_format(round($val['delivery'][4])), number_format(round($val['delivery'][5])), number_format(round($val['delivery'][6])), - $val['final'][0], number_format(round($val['final'][1])), $val['final'][2], number_format(round($val['final'][3])), number_format(round($val['final'][4])), number_format(round($val['final'][5])), number_format(round($val['final'][6])), - str_replace('
', '; ', $val['status']), number_format(round($val['A40001'])), number_format(round($val['A40008'])), number_format(round($val['total_budget'])), number_format(round($val['receivable_budget'])) - ]; - } else { - $facility_exclude_boga_array[$valkey] = [ - $value[9], $valkey, $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], - $val['sign'][0], number_format(round($val['sign'][1])), $val['sign'][2], number_format(round($val['sign'][3])), number_format(round($val['sign'][4])), number_format(round($val['sign'][5])), number_format(round($val['sign'][6])), - $val['second'][0], number_format(round($val['second'][1])), $val['second'][2], number_format(round($val['second'][3])), number_format(round($val['second'][4])), number_format(round($val['second'][5])), number_format(round($val['second'][6])), - $val['arrive'][0], number_format(round($val['arrive'][1])), $val['arrive'][2], number_format(round($val['arrive'][3])), number_format(round($val['arrive'][4])), number_format(round($val['arrive'][5])), number_format(round($val['arrive'][6])), - $val['install'][0], number_format(round($val['install'][1])), $val['install'][2], number_format(round($val['install'][3])), number_format(round($val['install'][4])), number_format(round($val['install'][5])), number_format(round($val['install'][6])), - $val['tryrun'][0], number_format(round($val['tryrun'][1])), $val['tryrun'][2], number_format(round($val['tryrun'][3])), number_format(round($val['tryrun'][4])), number_format(round($val['tryrun'][5])), number_format(round($val['tryrun'][6])), - $val['check'][0], number_format(round($val['check'][1])), $val['check'][2], number_format(round($val['check'][3])), number_format(round($val['check'][4])), number_format(round($val['check'][5])), number_format(round($val['check'][6])), - $val['delivery'][0], number_format(round($val['delivery'][1])), $val['delivery'][2], number_format(round($val['delivery'][3])), number_format(round($val['delivery'][4])), number_format(round($val['delivery'][5])), number_format(round($val['delivery'][6])), - $val['final'][0], number_format(round($val['final'][1])), $val['final'][2], number_format(round($val['final'][3])), number_format(round($val['final'][4])), number_format(round($val['final'][5])), number_format(round($val['final'][6])), - str_replace('
', '; ', $val['status']), number_format(round($val['A40001'])), number_format(round($val['A40008'])), number_format(round($val['total_budget'])), number_format(round($val['receivable_budget'])) - ]; - } } } } -$average_A40001 = round($sum_A40001 / $sum_facility, 2); -$average_A40008 = round($sum_A40008 / $sum_facility, 2); -$average_budget = round($sum_total_budget / $sum_facility, 2); - $total_data = json_encode($excel_aray); -$boga_data = json_encode($boga_array); -$exclude_boga_data = json_encode($exclude_boga_array); -$facility_data = json_encode($facility_array); -$facility_boga_data = json_encode($facility_boga_array); -$facility_exclude_boga_data = json_encode($facility_exclude_boga_array); ?>