diff --git a/wms/rib02-purReceive-submit.php b/wms/T8-purReceive-submit.php similarity index 96% rename from wms/rib02-purReceive-submit.php rename to wms/T8-purReceive-submit.php index ba87bc27..aa917201 100644 --- a/wms/rib02-purReceive-submit.php +++ b/wms/T8-purReceive-submit.php @@ -1,89 +1,89 @@ - - \ No newline at end of file diff --git a/wms/rib02-purchase-submit.php b/wms/T8-purchase-submit.php similarity index 97% rename from wms/rib02-purchase-submit.php rename to wms/T8-purchase-submit.php index 13f042fa..216b4906 100644 --- a/wms/rib02-purchase-submit.php +++ b/wms/T8-purchase-submit.php @@ -1,89 +1,89 @@ - - \ No newline at end of file diff --git a/wms/T8_Authorization.php b/wms/T8_Authorization.php index a1a756ce..dce65c91 100644 --- a/wms/T8_Authorization.php +++ b/wms/T8_Authorization.php @@ -14,12 +14,13 @@ $sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false); var validation = ""; // var corsurl = 'http://cors-anywhere.herokuapp.com/'; // var apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; - var apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth' + // var apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth' headerParam = { UserId: 'M0000', Pwd: 'M012290493119', TimestampUTC: , - Sign: '' + Sign: '', + GroupId: 'TEST', }; obj = { type: 'get', @@ -30,7 +31,7 @@ $sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false); success: function(res) { validation = res.Data['CHI_Authorization']; console.log(validation); - // console.log(res); + console.log(res); // console.log() // window.parent.postMessage(validation,'http://localhost:3000'); // window.parent.postMessage(validation,'https://masada.com.tw'); @@ -40,4 +41,5 @@ $sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false); jQuery.ajax(obj); // return jQuery.ajax(obj); } + get_Auth(); \ No newline at end of file diff --git a/wms/T8_Authorization_from_bpm.php b/wms/T8_Authorization_from_bpm.php index 3e8708b2..7c206023 100644 --- a/wms/T8_Authorization_from_bpm.php +++ b/wms/T8_Authorization_from_bpm.php @@ -24,11 +24,13 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119") // $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth'; // $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'; + //GroupId : TEST測試區 ; MASADA正式區 $headerParam = [ "UserId: $user_id", "Pwd: $user_password", "TimestampUTC: $now", - "Sign: $sign" + "Sign: $sign", + "GroupId: TEST" ]; $ch = curl_init(); @@ -51,4 +53,4 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119") curl_close($ch); } // $data = []; -// get_Auth(); +get_Auth(); diff --git a/wms/WriteOff.xlsx b/wms/WriteOff.xlsx index 61407291..6bb1cd82 100644 Binary files a/wms/WriteOff.xlsx and b/wms/WriteOff.xlsx differ diff --git a/wms/account-receivable-index-ing.php b/wms/account-receivable-index-ing.php index ced50411..722cc971 100644 --- a/wms/account-receivable-index-ing.php +++ b/wms/account-receivable-index-ing.php @@ -2158,9 +2158,14 @@ include "./footer.php"; //[合約號]['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數 ?> - +
+
+ + +
+
- +
@@ -2180,7 +2185,7 @@ include "./footer.php"; $value) { ?> - + @@ -2246,6 +2251,21 @@ include "./footer.php";
合約號
\ No newline at end of file diff --git a/wms/account-receivable-renovate-index.php b/wms/account-receivable-renovate-index.php index 90f18d98..a4f2f82e 100644 --- a/wms/account-receivable-renovate-index.php +++ b/wms/account-receivable-renovate-index.php @@ -25,11 +25,13 @@ $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核銷 $sql_received = "SELECT @@ -51,35 +53,23 @@ ON a.BillNo=c.BillNo WHERE DATALENGTH(c.OrderBillNo) >0"; - -//ORDER BY contractno - // 期初收款資訊 $sql_opening = " 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); $column_str .= "')"; $sql_contractNumber .= " OR PersonId IN $column_str)"; - // $sql_contract .= " OR s.PersonId IN $column_str)"; - // $sql_received .= " OR PersonId IN $column_str)"; $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 .= ")"; - // $sql_contract_budget .= ")"; }; } @@ -127,19 +117,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']; @@ -152,6 +148,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 安裝收款日期 @@ -160,6 +161,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; @@ -196,11 +200,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']])) { @@ -253,24 +272,13 @@ function get_contract_ratio($facility_no, $contract_budget_billno) return $ratio; } -/* 計算比例 -@param $facility_list array -@param $contract_no string -@param $contract_budget array -return float */ -function get_ratio($facility_list, $contract_no, $contract_budget) +/* 比較應收日期 +@param $a array +@param $b array +return int */ +function comparePlanPayDate($a, $b) { - $ratio = 0; - if (empty($facility_list)) { - return 0; - } else { - foreach ($facility_list as $every) { - if (isset($contract_budget[$contract_no][$every]['total']) && isset($contract_budget[$contract_no]['total'])) { - $ratio += $contract_budget[$contract_no][$every]['total'] / $contract_budget[$contract_no]['total']; - } - } - return $ratio; - } + return strtotime($a['PlanPayDate']) - strtotime($b['PlanPayDate']); } //取作番大日程作番與時程 進arrayData @@ -283,11 +291,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; @@ -297,670 +305,170 @@ foreach ($wipwhole_array as $wip) { $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']]['A40001'] = (isset($contract_budget[$wip['contractno']][$wip['facilityno']]['A40001']) && !is_null($contract_budget[$wip['contractno']][$wip['facilityno']]['A40001'])) ? $contract_budget[$wip['contractno']][$wip['facilityno']]['A40001'] : 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']]['A40008'] = (isset($contract_budget[$wip['contractno']][$wip['facilityno']]['A40008']) && !is_null($contract_budget[$wip['contractno']][$wip['facilityno']]['A40008'])) ? $contract_budget[$wip['contractno']][$wip['facilityno']]['A40008'] : 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 (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]['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($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($arrayData as $key => $value){ - echo $key."
"; - print_r($value); - echo "
--------------------------
"; +foreach ($allPayStages as $paykey => $pay) { + uasort($allPayStages[$paykey], 'comparePlanPayDate'); } -exit(); -//========================================================================================================================================================= - -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']]['total_facility_num'] += 1; - $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; - // [合約號]['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']]['A40001'] = (isset($contract_budget[$wip['contractno']][$wip['facilityno']]['A40001']) && !is_null($contract_budget[$wip['contractno']][$wip['facilityno']]['A40001'])) ? $contract_budget[$wip['contractno']][$wip['facilityno']]['A40001'] : 0; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['A40008'] = (isset($contract_budget[$wip['contractno']][$wip['facilityno']]['A40008']) && !is_null($contract_budget[$wip['contractno']][$wip['facilityno']]['A40008'])) ? $contract_budget[$wip['contractno']][$wip['facilityno']]['A40008'] : 0; - - $contractstage = array('sign', 'second', 'arrive', 'install', 'tryrun', 'check', 'delivery', 'final'); - - //根據作番狀態填入facilities,計算各階段數量、一個合約有幾個作番,增加作番資料 - // real_contract_arrival_date 預計出貨日=預計到貨日=預計貨抵工地 - // real_arrival_date 實際出貨日=實際到貨日=實際貨抵工地 - - - $signtime = strtotime($arrayData[$wip['contractno']]['sign'][2]); - array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']); - $month = collect_month($signtime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['sign'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['sign'][2] = strval(date('Ymd', $signtime)); - if (isset($arrayData[$wip['contractno']]['second'][2]) && ($arrayData[$wip['contractno']]['second'][2] !== NULL)) { - $secondtime = strtotime($arrayData[$wip['contractno']]['second'][2]); - $month = collect_month($secondtime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['second'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['second'][2] = strval(date('Ymd', $secondtime)); - } - if ($wip['delivery_date'] != NULL) { - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交)
"; - $arrayData[$wip['contractno']]['tryrun_num'] += 1; - array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['install_num'] += 1; - array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['arrive_num'] += 1; - array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['second_num'] += 1; - array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['sign_num'] += 1; - array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']); - - if ($arrayData[$wip['contractno']]['delivery'][0] == "交車後270天") { - $estimate_delivery_time = strtotime($wip['delivery_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $month = collect_month($arrivetime); - if ($today > $arrivetime) { - $arrayData[$wip['contractno']]['delivery_num'] += 1; - array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']); - array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']); - } - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['delivery'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['delivery'][2] = strval(date('Ymd', $arrivetime)); - $arrivetime = date('Ymd', $arrivetime); - $arrayData[$wip['contractno']]['delivery'][2] = strval($secondtime); - array_push($arrayData[$wip['contractno']]['delivery']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['delivery']['max'], strtotime(strval($arrivetime))); - } else { - $arrayData[$wip['contractno']]['delivery_num'] += 1; - array_push($arrayData[$wip['contractno']]['delivery_list'], $wip['facilityno']); - array_push($arrayData[$wip['contractno']]['final_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['check_num'] += 1; - array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['delivery'][2] = strval($wip['delivery_date']); - $deliverytime = strtotime($wip['delivery_date']); - $month = collect_month($deliverytime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['delivery'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['delivery'][2] = strval(date('Ymd', $deliverytime)); - array_push($arrayData[$wip['contractno']]['delivery']['min'], strtotime(strval($wip['delivery_date']))); - array_push($arrayData[$wip['contractno']]['delivery']['max'], strtotime(strval($wip['delivery_date']))); - } - if (!empty($wip['official_check_date']) && $wip['official_check_date'] != NULL) { - array_push($arrayData[$wip['contractno']]['check']['min'], strtotime(strval($wip['official_check_date']))); - array_push($arrayData[$wip['contractno']]['check']['max'], strtotime(strval($wip['official_check_date']))); - $checktime = strtotime($wip['official_check_date']); - $month = collect_month($checktime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['check'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['check'][2] = strval(date('Ymd', $checktime)); - } - if (!empty($wip['tryrun_end_date']) && $wip['tryrun_end_date'] != NULL) { - if ($arrayData[$wip['contractno']]['tryrun'][0] == "安裝試車後90天") { - $estimate_delivery_time = strtotime($wip['tryrun_end_date']); - $tryruntime = $estimate_delivery_time + (90 * 86400); - $tryruntime = date('Ymd', $secondtime); - $arrayData[$wip['contractno']]['tryrun'][2] = strval($secondtime); - array_push($arrayData[$wip['contractno']]['tryrun']['min'], strtotime(strval($tryruntime))); - array_push($arrayData[$wip['contractno']]['tryrun']['max'], strtotime(strval($tryruntime))); - $month = collect_month($tryruntime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][2] = strval(date('Ymd', $tryruntime)); - } else { - $arrayData[$wip['contractno']]['tryrun'][2] = strval($wip['tryrun_end_date']); - array_push($arrayData[$wip['contractno']]['tryrun']['min'], strtotime(strval($wip['tryrun_end_date']))); - array_push($arrayData[$wip['contractno']]['tryrun']['max'], strtotime(strval($wip['tryrun_end_date']))); - $tryruntime = strtotime($wip['tryrun_end_date']); - $month = collect_month($tryruntime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][2] = strval(date('Ymd', $tryruntime)); - } - } - if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) { - array_push($arrayData[$wip['contractno']]['install']['min'], strtotime(strval($wip['install_end_date']))); - array_push($arrayData[$wip['contractno']]['install']['max'], strtotime(strval($wip['install_end_date']))); - $installtime = strtotime($wip['install_end_date']); - $month = collect_month($installtime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['install'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['install'][2] = strval(date('Ymd', $installtime)); - } - if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { - if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") { - $estimate_delivery_time = strtotime($wip['real_arrival_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrivetime = date('Ymd', $secondtime); - $arrayData[$wip['contractno']]['arrive'][2] = strval($secondtime); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($arrivetime))); - } else { - $arrivetime = strtotime($wip['real_arrival_date']); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrayData[$wip['contractno']]['arrive'][2] = strval($wip['real_arrival_date']); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($wip['real_arrival_date']))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($wip['real_arrival_date']))); - } - } - } elseif ($wip['official_check_date'] != NULL) { - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢)
"; - $arrayData[$wip['contractno']]['check_num'] += 1; - array_push($arrayData[$wip['contractno']]['check_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['tryrun_num'] += 1; - array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['install_num'] += 1; - array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['arrive_num'] += 1; - array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['second_num'] += 1; - array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['sign_num'] += 1; - array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']); - if (!empty($wip['official_check_date']) && $wip['official_check_date'] != NULL) { - array_push($arrayData[$wip['contractno']]['check']['min'], strtotime(strval($wip['official_check_date']))); - array_push($arrayData[$wip['contractno']]['check']['max'], strtotime(strval($wip['official_check_date']))); - $checktime = strtotime($wip['official_check_date']); - $month = collect_month($checktime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['check'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['check'][2] = strval(date('Ymd', $checktime)); - } - - if (!empty($wip['tryrun_end_date']) && $wip['tryrun_end_date'] != NULL) { - if (isset($arrayData[$wip['contractno']]['tryrun'][0]) && $arrayData[$wip['contractno']]['tryrun'][0] == "安裝試車後90天") { - $estimate_delivery_time = strtotime($wip['tryrun_end_date']); - $tryruntime = $estimate_delivery_time + (90 * 86400); - $month = collect_month($tryruntime); - $tryruntime = date('Ymd', $tryruntime); - $arrayData[$wip['contractno']]['tryrun'][2] = strval($secondtime); - array_push($arrayData[$wip['contractno']]['tryrun']['min'], strtotime(strval($tryruntime))); - array_push($arrayData[$wip['contractno']]['tryrun']['max'], strtotime(strval($tryruntime))); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][2] = strval($tryruntime); - } else { - $tryruntime = strtotime($wip['tryrun_end_date']); - $month = collect_month($tryruntime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][2] = strval(date('Ymd', $tryruntime)); - $arrayData[$wip['contractno']]['tryrun'][2] = strval($wip['tryrun_end_date']); - array_push($arrayData[$wip['contractno']]['tryrun']['min'], strtotime(strval($wip['tryrun_end_date']))); - array_push($arrayData[$wip['contractno']]['tryrun']['max'], strtotime(strval($wip['tryrun_end_date']))); - } - } - if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) { - $installtime = strtotime($wip['install_end_date']); - $month = collect_month($installtime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['install'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['install'][2] = strval(date('Ymd', $installtime)); - array_push($arrayData[$wip['contractno']]['install']['min'], strtotime(strval($wip['install_end_date']))); - array_push($arrayData[$wip['contractno']]['install']['max'], strtotime(strval($wip['install_end_date']))); - } - if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { - if (isset($arrayData[$wip['contractno']]['arrive'][0]) && $arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") { - $estimate_delivery_time = strtotime($wip['real_arrival_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrivetime = date('Ymd', $secondtime); - $arrayData[$wip['contractno']]['arrive'][2] = strval($secondtime); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($arrivetime))); - } else { - $arrayData[$wip['contractno']]['arrive'][2] = strval($wip['real_arrival_date']); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($wip['real_arrival_date']))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($wip['real_arrival_date']))); - $arrivetime = strtotime($wip['real_arrival_date']); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - } - } else { - if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") { - $estimate_delivery_time = strtotime($wip['real_contract_arrival_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $arrivetime = date('Ymd', $secondtime); - $arrayData[$wip['contractno']]['arrive'][2] = strval($secondtime); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($arrivetime))); - } else { - $arrayData[$wip['contractno']]['arrive'][2] = strval($wip['real_contract_arrival_date']); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($wip['real_contract_arrival_date']))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($wip['real_contract_arrival_date']))); - } - } - } elseif ($wip['tryrun_end_date'] != NULL) { - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢)
"; - $arrayData[$wip['contractno']]['tryrun_num'] += 1; - array_push($arrayData[$wip['contractno']]['tryrun_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['install_num'] += 1; - array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['arrive_num'] += 1; - array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['second_num'] += 1; - array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['sign_num'] += 1; - array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']); - if (!empty($wip['tryrun_end_date']) && $wip['tryrun_end_date'] != NULL) { - array_push($arrayData[$wip['contractno']]['tryrun']['min'], strtotime(strval($wip['tryrun_end_date']))); - array_push($arrayData[$wip['contractno']]['tryrun']['max'], strtotime(strval($wip['tryrun_end_date']))); - $tryruntime = strtotime($wip['tryrun_end_date']); - $month = collect_month($tryruntime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['tryrun'][2] = strval(date('Ymd', $tryruntime)); - } - if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) { - array_push($arrayData[$wip['contractno']]['install']['min'], strtotime(strval($wip['install_end_date']))); - array_push($arrayData[$wip['contractno']]['install']['max'], strtotime(strval($wip['install_end_date']))); - $installtime = strtotime($wip['install_end_date']); - $month = collect_month($installtime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['install'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['install'][2] = strval(date('Ymd', $installtime)); - } - if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { - if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") { - $estimate_delivery_time = strtotime($wip['real_arrival_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrivetime = date('Ymd', $arrivetime); - $arrayData[$wip['contractno']]['arrive'][2] = strval($arrivetime); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($arrivetime))); - } else { - $arrivetime = strtotime($wip['real_arrival_date']); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrayData[$wip['contractno']]['arrive'][2] = strval($wip['real_arrival_date']); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($wip['real_arrival_date']))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($wip['real_arrival_date']))); - } - } else { - if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") { - $estimate_delivery_time = strtotime($wip['real_contract_arrival_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $arrivetime = date('Ymd', $arrivetime); - $arrayData[$wip['contractno']]['arrive'][2] = strval($arrivetime); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($arrivetime))); - } else { - $arrayData[$wip['contractno']]['arrive'][2] = strval($wip['real_contract_arrival_date']); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($wip['real_contract_arrival_date']))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($wip['real_contract_arrival_date']))); - } - } - } elseif ($wip['install_end_date'] != NULL) { - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢)
"; - $arrayData[$wip['contractno']]['install_num'] += 1; - array_push($arrayData[$wip['contractno']]['install_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['arrive_num'] += 1; - array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['second_num'] += 1; - array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['sign_num'] += 1; - array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']); - if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) { - $installtime = strtotime($wip['install_end_date']); - $month = collect_month($installtime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['install'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['install'][2] = strval(date('Ymd', $installtime)); - array_push($arrayData[$wip['contractno']]['install']['min'], strtotime(strval($wip['install_end_date']))); - array_push($arrayData[$wip['contractno']]['install']['max'], strtotime(strtotime(strval($wip['install_end_date'])))); - } - if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { - if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") { - $estimate_delivery_time = strtotime($wip['real_arrival_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrivetime = date('Ymd', $arrivetime); - $arrayData[$wip['contractno']]['arrive'][2] = strval($arrivetime); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($arrivetime))); - } else { - $arrivetime = strtotime($wip['real_arrival_date']); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrayData[$wip['contractno']]['arrive'][2] = strval($wip['real_arrival_date']); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($wip['real_arrival_date']))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($wip['real_arrival_date']))); - } - } else { - if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") { - $estimate_delivery_time = strtotime($wip['real_contract_arrival_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $arrivetime = date('Ymd', $secondtime); - $arrayData[$wip['contractno']]['arrive'][2] = strval($secondtime); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($arrivetime))); - } else { - $arrayData[$wip['contractno']]['arrive'][2] = strval($wip['real_contract_arrival_date']); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($wip['real_contract_arrival_date']))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($wip['real_contract_arrival_date']))); - } - } - } elseif ($wip['real_arrival_date'] != NULL) { - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地)
"; - $arrayData[$wip['contractno']]['arrive_num'] += 1; - array_push($arrayData[$wip['contractno']]['arrive_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['second_num'] += 1; - array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['sign_num'] += 1; - array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']); - - if ($arrayData[$wip['contractno']]['arrive'][0] == "貨抵工地後90天") { - $estimate_delivery_time = strtotime($wip['real_arrival_date']); - $arrivetime = $estimate_delivery_time + (90 * 86400); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrivetime = date('Ymd', $arrivetime); - $arrayData[$wip['contractno']]['arrive'][2] = strval($arrivetime); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($arrivetime))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($arrivetime))); - } else { - $arrivetime = strtotime($wip['real_arrival_date']); - $month = collect_month($arrivetime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['arrive'][2] = strval(date('Ymd', $arrivetime)); - $arrayData[$wip['contractno']]['arrive'][2] = strval($wip['real_arrival_date']); - array_push($arrayData[$wip['contractno']]['arrive']['min'], strtotime(strval($wip['real_arrival_date']))); - array_push($arrayData[$wip['contractno']]['arrive']['max'], strtotime(strval($wip['real_arrival_date']))); - } - } elseif (($arrayData[$wip['contractno']]['second'] != NULL) && (isset($arrayData[$wip['contractno']]['second'][2])) && ($arrayData[$wip['contractno']]['second'][2] <= date('Ymd'))) { - $secondtime = strtotime($arrayData[$wip['contractno']]['second'][2]); - $month = collect_month($secondtime); - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['second'][6] = $month; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['second'][2] = strval(date('Ymd', $secondtime)); - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (已達二次款收款條件)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (已達二次款收款條件)
"; - $arrayData[$wip['contractno']]['second_num'] += 1; - array_push($arrayData[$wip['contractno']]['second_list'], $wip['facilityno']); - $arrayData[$wip['contractno']]['sign_num'] += 1; - array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']); - } else { - $arrayData[$wip['contractno']]['sign_num'] += 1; - array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']); - if ($wip['real_contract_arrival_date'] != NULL) { - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['real_contract_arrival_date'] . "預計出貨日)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['real_contract_arrival_date'] . "預計出貨日)
"; - } elseif ($wip['estimated_shipping_date'] != NULL) { - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計出港日)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計出港日)
"; - } else { - $arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (預計出港日待確認)
"; - $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['facilityno'] . " (預計出港日待確認)
"; - } - } +foreach ($allPayStages as &$payStage) { + $sequenceNumber = 1; + foreach ($payStage as $tk => &$pstage) { + $pstage['sequenceNumber'] = $sequenceNumber; + $sequenceNumber += 1; } } -// foreach ($arrayData as $key => $value) { -// echo $key."
"; -// print_r($value['total_list']); -// echo " / 總 "; -// print_r($value['sign_list']); -// echo " / 訂金
"; -// print_r($value['arrive_list']); -// echo " / 貨抵 "; -// print_r($value['install_list']); -// echo " / 安裝
"; -// print_r($value['tryrun_list']); -// echo " / 試車 "; -// print_r($value['check_list']); -// echo " / 官檢
"; -// print_r($value['delivery_list']); -// echo " / 移交 "; -// print_r($value['final_list']); -// echo " / 結案
"; -// echo "---------------------------
"; -// foreach($value['sign_list'] as $fac){ -// echo $fac."========="; -// } -// } - - -// 計算每個合約的應收款、作番總數 -$today_date = new DateTime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m-d'))))); -$contractstage = array('sign', 'second', 'arrive', 'install', 'tryrun', 'check', 'delivery', 'final'); -foreach ($arrayData as &$value) { - if ($value['total_facility_num'] > 0) { - $sign_ratio = get_ratio($value['sign_list'], $value[10], $contract_budget); - $value['sign'][3] = $value['sign'][1] * $sign_ratio; - $second_ratio = get_ratio($value['second_list'], $value[10], $contract_budget); - $value['second'][3] = $value['second'][1] * $second_ratio; - $arrive_ratio = get_ratio($value['arrive_list'], $value[10], $contract_budget); - $value['arrive'][3] = $value['arrive'][1] * $arrive_ratio; - $install_ratio = get_ratio($value['install_list'], $value[10], $contract_budget); - $value['install'][3] = $value['install'][1] * $install_ratio; - $tryrun_ratio = get_ratio($value['tryrun_list'], $value[10], $contract_budget); - $value['tryrun'][3] = $value['tryrun'][1] * $tryrun_ratio; - $check_ratio = get_ratio($value['check_list'], $value[10], $contract_budget); - $value['check'][3] = $value['check'][1] * $check_ratio; - $delivery_ratio = get_ratio($value['delivery_list'], $value[10], $contract_budget); - $value['delivery'][3] = $value['delivery'][1] * $delivery_ratio; - $final_ratio = get_ratio($value['final_list'], $value[10], $contract_budget); - $value['final'][3] = $value['final'][1] * $final_ratio; - $value['receivable_budget'] = $value['sign'][3] + $value['second'][3] + $value['arrive'][3] + $value['install'][3] + $value['tryrun'][3] + $value['check'][3] + $value['delivery'][3] + $value['final'][3]; - } - //['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數 - // 計算每台作番金額與各階段應收金額 - if (isset($value['facility'])) { - foreach ($value['facility'] as &$val) { - foreach ($contractstage as $stage) { - if (isset($value[$stage][0]) && !empty($value[$stage][0])) { - $val[$stage][0] = $value[$stage][0]; - if (isset($contract_budget[$value[10]]['total']) && isset($contract_budget[$value[10]][$val['no']]['total'])) { - $ratio = $contract_budget[$value[10]][$val['no']]['total'] / $contract_budget[$value[10]]['total']; - } else { - $ratio = 0; - } - $val[$stage][1] = $value[$stage][1] * $ratio; - $val[$stage][3] = (!(isset($val[$stage][6])) || $val[$stage][6] == 0) ? 0 : $val[$stage][1]; - $val['total_budget'] += $val[$stage][1]; - $val['receivable_budget'] += $val[$stage][3]; - } - } +// 整理好的收款階段 +$final_paystage = array(); +foreach ($allPayStages as $key => &$payStage) { + if (is_iterable($payStage)) { + foreach ($payStage as $key2 => $pstage) { + $final_paystage[$key][$pstage['sequenceNumber']] = $pstage; } } - - - - // 計算最大催收次數與最小催收次數 - foreach ($contractstage as $i) { - if (!empty($value[$i]['min']) && count($value[$i]['min']) > 0) { - $latest_timestamp = max($value[$i]['min']); - $latest_date = new DateTime(); - $latest_date->setTimestamp($latest_timestamp); - if ($latest_date < $today_date) { - $interval = $latest_date->diff($today_date); - $month = $interval->format('%m'); - $value[$i]['min'] = $month; - } else { - $value[$i]['min'] = 0; - } - } else { - $value[$i]['min'] = 0; - }; - if (!empty($value[$i]['max']) && count($value[$i]['max']) > 0) { - $latest_timestamp = min($value[$i]['max']); - $latest_date = new DateTime(); - $latest_date->setTimestamp($latest_timestamp); - if ($latest_date < $today_date) { - $interval = $latest_date->diff($today_date); - $month = $interval->format('%m'); - $value[$i]['max'] = $month; - } else { - $value[$i]['max'] = 0; - } - } else { - $value[$i]['max'] = 0; - }; - } } -// [合約號][作番號][款別] ['con'] [金額]/[合約預計收款日期] -// [合約號][作番號][款別] ['inv'] [金額]/[發票開立日期] -// [合約號][作番號][款別] ['rec'] [金額]/[實際收款日期] -foreach ($wipwhole_array as $wip) { - if (isset($arrayData[$wip['contractno']]) && isset($arrayData[$wip['contractno']][$wip['facilityno']]) && !empty($arrayData[$wip['contractno']]['total_facility_num'])) { - $stagearray = array('sign', 'second', 'arrive', 'install', 'tryrun', 'check', 'delivery', 'final'); - foreach ($stagearray as $stage) { - $arrayData[$wip['contractno']][$wip['facilityno']][$stage]['con'] = $arrayData[$wip['contractno']][$stage][1] / $arrayData[$wip['contractno']]['total_facility_num']; - } - } -} // [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']]; } } // 把核銷單的內容補到發票資料中 foreach ($received_array as $received) { - if ($received['OrderBillNo'] == 'SO20230801001') { - $BillNo = 'M230947'; - } elseif ($received['OrderBillNo'] == 'SO20230801002') { - $BillNo = 'M231067'; - } else { - $BillNo = $received['OrderBillNo']; - }; + $BillNo = $received['OrderBillNo']; if (isset($arrayData[$BillNo])) { if (isset($arrayData[$BillNo]['invoice'][$received['InvoiceNo']])) { $arrayData[$BillNo]['received_budget'] += $received['PayWriteOffOAmount']; @@ -968,903 +476,82 @@ foreach ($received_array as $received) { } } } - -//['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 4 已收金額 5 催收金額 6 已開發票金額 7 未開發票金額 min 最早應收月份 max 最晚應收月份 -foreach ($arrayData as $key => &$data) { - //['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數 - //作番 - $facilities = array(); - if (isset($data['facility'])) { - foreach ($data['facility'] as $fakey => $val) { - array_push($facilities, $fakey); - } - } - - $tmp_data = $data['received_budget']; - $tmp_invoice = $data['invoice_budget']; - //------------------------------------------------------------------------------------------------------------------------------------ - if (isset($data['sign'][3]) && $data['sign'][3] > 0) { - if ($tmp_data > 0) { - if (($tmp_data - $data['sign'][3]) >= 0) { - $data['sign'][4] = $data['sign'][3]; - $tmp_data -= $data['sign'][3]; - $tmp_facility_received = $data['sign'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['sign'][3]) && $data['facility'][$this_facility]['sign'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['sign'][3]) { - $data['facility'][$this_facility]['sign'][4] = $data['facility'][$this_facility]['sign'][3]; - $data['facility'][$this_facility]['sign'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['sign'][3]; - } else { - $data['facility'][$this_facility]['sign'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['sign'][5] = $data['facility'][$this_facility]['sign'][3] - $data['facility'][$this_facility]['sign'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['sign'][4] = 0; - $data['facility'][$this_facility]['sign'][5] = $data['facility'][$this_facility]['sign'][3]; - } - } else { - $data['facility'][$this_facility]['sign'][4] = 0; - $data['facility'][$this_facility]['sign'][5] = 0; - } - if ($data['facility'][$this_facility]['sign'][5] == 0) { - $data['facility'][$this_facility]['sign'][6] = 0; - } - } - } else { - $data['sign'][4] = $tmp_data; - $tmp_data = 0; - $tmp_facility_received = $data['sign'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['sign'][3]) && $data['facility'][$this_facility]['sign'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['sign'][3]) { - $data['facility'][$this_facility]['sign'][4] = $data['facility'][$this_facility]['sign'][3]; - $data['facility'][$this_facility]['sign'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['sign'][3]; - } else { - $data['facility'][$this_facility]['sign'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['sign'][5] = $data['facility'][$this_facility]['sign'][3] - $data['facility'][$this_facility]['sign'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['sign'][4] = 0; - $data['facility'][$this_facility]['sign'][5] = $data['facility'][$this_facility]['sign'][3]; - } - } else { - $data['facility'][$this_facility]['sign'][4] = 0; - $data['facility'][$this_facility]['sign'][5] = 0; - } - if ($data['facility'][$this_facility]['sign'][5] == 0) { - $data['facility'][$this_facility]['sign'][6] = 0; - } - } - } - $data['sign'][5] = $data['sign'][3] - $data['sign'][4]; - } else { - $data['sign'][4] = 0; - $data['sign'][5] = $data['sign'][3]; - foreach ($facilities as $this_facility) { - $data['facility'][$this_facility]['sign'][4] = 0; - $data['facility'][$this_facility]['sign'][5] = $data['facility'][$this_facility]['sign'][3]; - if ($data['facility'][$this_facility]['sign'][5] == 0) { - $data['facility'][$this_facility]['sign'][6] = 0; - } - } - } - if ($tmp_invoice > 0) { - if (($tmp_invoice - $data['sign'][3]) >= 0) { - $data['sign'][6] = $data['sign'][3]; - $tmp_invoice -= $data['sign'][3]; - } else { - $data['sign'][6] = $tmp_invoice; - $tmp_invoice = 0; - } - $data['sign'][7] = $data['sign'][3] - $data['sign'][6]; - } else { - $data['sign'][6] = 0; - $data['sign'][7] = $data['sign'][3]; - } - } else { - $data['sign'][4] = 0; - $data['sign'][5] = 0; - $data['sign'][6] = 0; - $data['sign'][7] = 0; - } - if (isset($data['second'][3]) && $data['second'][3] > 0) { - if ($tmp_data > 0) { - if (($tmp_data - $data['second'][3]) >= 0) { - $data['second'][4] = $data['second'][3]; - $tmp_data -= $data['second'][3]; - $tmp_facility_received = $data['second'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['second'][3]) && $data['facility'][$this_facility]['second'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['second'][3]) { - $data['facility'][$this_facility]['second'][4] = $data['facility'][$this_facility]['second'][3]; - $data['facility'][$this_facility]['second'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['second'][3]; - } else { - $data['facility'][$this_facility]['second'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['second'][5] = $data['facility'][$this_facility]['second'][3] - $data['facility'][$this_facility]['second'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['second'][4] = 0; - $data['facility'][$this_facility]['second'][5] = $data['facility'][$this_facility]['second'][3]; - } - } else { - $data['facility'][$this_facility]['second'][4] = 0; - $data['facility'][$this_facility]['second'][5] = 0; - $data['facility'][$this_facility]['second'][6] = 0; - } - if ($data['facility'][$this_facility]['second'][5] == 0) { - $data['facility'][$this_facility]['second'][6] = 0; - } - } - } else { - $data['second'][4] = $tmp_data; - $tmp_data = 0; - $tmp_facility_received = $data['second'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['second'][3]) && $data['facility'][$this_facility]['second'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['second'][3]) { - $data['facility'][$this_facility]['second'][4] = $data['facility'][$this_facility]['second'][3]; - $data['facility'][$this_facility]['second'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['second'][3]; - } else { - $data['facility'][$this_facility]['second'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['second'][5] = $data['facility'][$this_facility]['second'][3] - $data['facility'][$this_facility]['second'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['second'][4] = 0; - $data['facility'][$this_facility]['second'][5] = $data['facility'][$this_facility]['second'][3]; - } - } else { - $data['facility'][$this_facility]['second'][4] = 0; - $data['facility'][$this_facility]['second'][5] = 0; - $data['facility'][$this_facility]['second'][6] = 0; - } - if ($data['facility'][$this_facility]['second'][5] == 0) { - $data['facility'][$this_facility]['second'][6] = 0; - } - } - } - $data['second'][5] = $data['second'][3] - $data['second'][4]; - } else { - $data['second'][4] = 0; - $data['second'][5] = $data['second'][3]; - foreach ($facilities as $this_facility) { - $data['facility'][$this_facility]['second'][4] = 0; - $data['facility'][$this_facility]['second'][5] = $data['facility'][$this_facility]['second'][3]; - if ($data['facility'][$this_facility]['second'][5] == 0) { - $data['facility'][$this_facility]['second'][6] = 0; - } - } - } - if ($tmp_invoice > 0) { - if (($tmp_invoice - $data['second'][3]) >= 0) { - $data['second'][6] = $data['second'][3]; - $tmp_invoice -= $data['second'][3]; +// $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 { - $data['second'][6] = $tmp_invoice; - $tmp_invoice = 0; + $payStage[$sequence]['InvoiceAmount'] = $tmpInvoice; + $tmpInvoice = 0; } - $data['second'][7] = $data['second'][3] - $data['second'][6]; - } else { - $data['second'][6] = 0; - $data['second'][7] = $data['second'][3]; - } - } else { - $data['second'][4] = 0; - $data['second'][5] = 0; - $data['second'][6] = 0; - $data['second'][7] = 0; - } - if (isset($data['arrive'][3]) && $data['arrive'][3] > 0) { + if ($tmpReceived > $payStage[$sequence]['PayAmount']) { - if ($tmp_data > 0) { - if (($tmp_data - $data['arrive'][1]) >= 0) { - $data['arrive'][4] = $data['arrive'][3]; - $tmp_data -= $data['arrive'][3]; - $tmp_facility_received = $data['arrive'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['arrive'][3]) && $data['facility'][$this_facility]['arrive'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['arrive'][3]) { - $data['facility'][$this_facility]['arrive'][4] = $data['facility'][$this_facility]['arrive'][3]; - $data['facility'][$this_facility]['arrive'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['arrive'][3]; - } else { - $data['facility'][$this_facility]['arrive'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['arrive'][5] = $data['facility'][$this_facility]['arrive'][3] - $data['facility'][$this_facility]['arrive'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['arrive'][4] = 0; - $data['facility'][$this_facility]['arrive'][5] = $data['facility'][$this_facility]['arrive'][3]; - } - } else { - $data['facility'][$this_facility]['arrive'][4] = 0; - $data['facility'][$this_facility]['arrive'][5] = 0; - $data['facility'][$this_facility]['arrive'][6] = 0; - } - if ($data['facility'][$this_facility]['arrive'][5] == 0) { - $data['facility'][$this_facility]['arrive'][6] = 0; - } - } + $payStage[$sequence]['receivedAmount'] = $payStage[$sequence]['PayAmount']; + $tmpReceived -= $payStage[$sequence]['PayAmount']; } else { - $data['arrive'][4] = $tmp_data; - $tmp_data = 0; - $tmp_facility_received = $data['arrive'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['arrive'][3]) && $data['facility'][$this_facility]['arrive'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['arrive'][3]) { - $data['facility'][$this_facility]['arrive'][4] = $data['facility'][$this_facility]['arrive'][3]; - $data['facility'][$this_facility]['arrive'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['arrive'][3]; - } else { - $data['facility'][$this_facility]['arrive'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['arrive'][5] = $data['facility'][$this_facility]['arrive'][3] - $data['facility'][$this_facility]['arrive'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['arrive'][4] = 0; - $data['facility'][$this_facility]['arrive'][5] = $data['facility'][$this_facility]['arrive'][3]; - } - } else { - $data['facility'][$this_facility]['arrive'][4] = 0; - $data['facility'][$this_facility]['arrive'][5] = 0; - $data['facility'][$this_facility]['arrive'][6] = 0; - } - if ($data['facility'][$this_facility]['arrive'][5] == 0) { - $data['facility'][$this_facility]['arrive'][6] = 0; - } - } + $payStage[$sequence]['receivedAmount'] = $tmpReceived; + $tmpReceived = 0; } - $data['arrive'][5] = $data['arrive'][3] - $data['arrive'][4]; - } else { - $data['arrive'][4] = 0; - $data['arrive'][5] = $data['arrive'][3]; - foreach ($facilities as $this_facility) { - $data['facility'][$this_facility]['arrive'][4] = 0; - $data['facility'][$this_facility]['arrive'][5] = $data['facility'][$this_facility]['arrive'][3]; - if ($data['facility'][$this_facility]['arrive'][5] == 0) { - $data['facility'][$this_facility]['arrive'][6] = 0; - } + if ($collect_month > 0) { + // $arrayData[$key]['facility'][$payStage[$sequence]['facilityno']]['receivable_budget']+=$payStage[$sequence]['PayAmount']; } - } - if ($tmp_invoice > 0) { - if (($tmp_invoice - $data['arrive'][3]) >= 0) { - $data['arrive'][6] = $data['arrive'][3]; - $tmp_invoice -= $data['arrive'][3]; + if ($collect_month > 0 && $payStage[$sequence]['PayAmount'] > $payStage[$sequence]['receivedAmount']) { + $payStage[$sequence]['collect_month'] = $collect_month; } else { - $data['arrive'][6] = $tmp_invoice; - $tmp_invoice = 0; + $payStage[$sequence]['collect_month'] = 0; } - $data['arrive'][7] = $data['arrive'][3] - $data['arrive'][6]; - } else { - $data['arrive'][6] = 0; - $data['arrive'][7] = $data['arrive'][3]; } - } else { - $data['arrive'][4] = 0; - $data['arrive'][5] = 0; - $data['arrive'][6] = 0; - $data['arrive'][7] = 0; - } - - if (isset($data['install'][3]) && $data['install'][3] > 0) { - - if ($tmp_data > 0) { - if (($tmp_data - $data['install'][1]) >= 0) { - $data['install'][4] = $data['install'][3]; - $tmp_data -= $data['install'][3]; - $tmp_facility_received = $data['install'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['install'][3]) && $data['facility'][$this_facility]['install'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['install'][3]) { - $data['facility'][$this_facility]['install'][4] = $data['facility'][$this_facility]['install'][3]; - $data['facility'][$this_facility]['install'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['install'][3]; - } else { - $data['facility'][$this_facility]['install'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['install'][5] = $data['facility'][$this_facility]['install'][3] - $data['facility'][$this_facility]['install'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['install'][4] = 0; - $data['facility'][$this_facility]['install'][5] = $data['facility'][$this_facility]['install'][3]; - } - } else { - $data['facility'][$this_facility]['install'][4] = 0; - $data['facility'][$this_facility]['install'][5] = 0; - $data['facility'][$this_facility]['install'][6] = 0; - } - if ($data['facility'][$this_facility]['install'][5] == 0) { - $data['facility'][$this_facility]['install'][6] = 0; - } - } - } else { - $data['install'][4] = $tmp_data; - $tmp_data = 0; - $tmp_facility_received = $data['install'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['install'][3]) && $data['facility'][$this_facility]['install'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['install'][3]) { - $data['facility'][$this_facility]['install'][4] = $data['facility'][$this_facility]['install'][3]; - $data['facility'][$this_facility]['install'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['install'][3]; - } else { - $data['facility'][$this_facility]['install'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['install'][5] = $data['facility'][$this_facility]['install'][3] - $data['facility'][$this_facility]['install'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['install'][4] = 0; - $data['facility'][$this_facility]['install'][5] = $data['facility'][$this_facility]['install'][3]; - } - } else { - $data['facility'][$this_facility]['install'][4] = 0; - $data['facility'][$this_facility]['install'][5] = 0; - $data['facility'][$this_facility]['install'][6] = 0; - } - if ($data['facility'][$this_facility]['install'][5] == 0) { - $data['facility'][$this_facility]['install'][6] = 0; - } - } - } - $data['install'][5] = $data['install'][3] - $data['install'][4]; - } else { - $data['install'][4] = 0; - $data['install'][5] = $data['install'][3]; - foreach ($facilities as $this_facility) { - $data['facility'][$this_facility]['install'][4] = 0; - $data['facility'][$this_facility]['install'][5] = $data['facility'][$this_facility]['install'][3]; - if ($data['facility'][$this_facility]['install'][5] == 0) { - $data['facility'][$this_facility]['install'][6] = 0; - } - } - } - if ($tmp_invoice > 0) { - if (($tmp_invoice - $data['install'][3]) >= 0) { - $data['install'][6] = $data['install'][3]; - $tmp_invoice -= $data['install'][3]; - } else { - $data['install'][6] = $tmp_invoice; - $tmp_invoice = 0; - } - $data['install'][7] = $data['install'][3] - $data['install'][6]; - } else { - $data['install'][6] = 0; - $data['install'][7] = $data['install'][3]; - } - } else { - $data['install'][4] = 0; - $data['install'][5] = 0; - $data['install'][6] = 0; - $data['install'][7] = 0; - } - - - if (isset($data['tryrun'][3]) && $data['tryrun'][3] > 0) { - if ($tmp_data > 0) { - if (($tmp_data - $data['tryrun'][1]) >= 0) { - $data['tryrun'][4] = $data['tryrun'][3]; - $tmp_data -= $data['tryrun'][3]; - $tmp_facility_received = $data['tryrun'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['tryrun'][3]) && $data['facility'][$this_facility]['tryrun'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['tryrun'][3]) { - $data['facility'][$this_facility]['tryrun'][4] = $data['facility'][$this_facility]['tryrun'][3]; - $data['facility'][$this_facility]['tryrun'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['tryrun'][3]; - } else { - $data['facility'][$this_facility]['tryrun'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['tryrun'][5] = $data['facility'][$this_facility]['tryrun'][3] - $data['facility'][$this_facility]['tryrun'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['tryrun'][4] = 0; - $data['facility'][$this_facility]['tryrun'][5] = $data['facility'][$this_facility]['tryrun'][3]; - } - } else { - $data['facility'][$this_facility]['tryrun'][4] = 0; - $data['facility'][$this_facility]['tryrun'][5] = 0; - $data['facility'][$this_facility]['tryrun'][6] = 0; - } - if ($data['facility'][$this_facility]['tryrun'][5] == 0) { - $data['facility'][$this_facility]['tryrun'][6] = 0; - } - } - } else { - $data['tryrun'][4] = $tmp_data; - $tmp_data = 0; - $tmp_facility_received = $data['tryrun'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['tryrun'][3]) && $data['facility'][$this_facility]['tryrun'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['tryrun'][3]) { - $data['facility'][$this_facility]['tryrun'][4] = $data['facility'][$this_facility]['tryrun'][3]; - $data['facility'][$this_facility]['tryrun'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['tryrun'][3]; - } else { - $data['facility'][$this_facility]['tryrun'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['tryrun'][5] = $data['facility'][$this_facility]['tryrun'][3] - $data['facility'][$this_facility]['tryrun'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['tryrun'][4] = 0; - $data['facility'][$this_facility]['tryrun'][5] = $data['facility'][$this_facility]['tryrun'][3]; - } - } else { - $data['facility'][$this_facility]['tryrun'][4] = 0; - $data['facility'][$this_facility]['tryrun'][5] = 0; - $data['facility'][$this_facility]['tryrun'][6] = 0; - } - if ($data['facility'][$this_facility]['tryrun'][5] == 0) { - $data['facility'][$this_facility]['tryrun'][6] = 0; - } - } - } - $data['tryrun'][5] = $data['tryrun'][3] - $data['tryrun'][4]; - } else { - $data['tryrun'][4] = 0; - $data['tryrun'][5] = $data['tryrun'][3]; - foreach ($facilities as $this_facility) { - $data['facility'][$this_facility]['tryrun'][4] = 0; - $data['facility'][$this_facility]['tryrun'][5] = $data['facility'][$this_facility]['tryrun'][3]; - if ($data['facility'][$this_facility]['tryrun'][5] == 0) { - $data['facility'][$this_facility]['tryrun'][6] = 0; - } - } - } - if ($tmp_invoice > 0) { - if (($tmp_invoice - $data['tryrun'][3]) >= 0) { - $data['tryrun'][6] = $data['tryrun'][3]; - $tmp_invoice -= $data['tryrun'][3]; - } else { - $data['tryrun'][6] = $tmp_invoice; - $tmp_invoice = 0; - } - $data['tryrun'][7] = $data['tryrun'][3] - $data['tryrun'][6]; - } else { - $data['tryrun'][6] = 0; - $data['tryrun'][7] = $data['tryrun'][3]; - } - } else { - $data['tryrun'][4] = 0; - $data['tryrun'][5] = 0; - $data['tryrun'][6] = 0; - $data['tryrun'][7] = 0; - } - - if (isset($data['check'][3]) && $data['check'][3] > 0) { - if ($tmp_data > 0) { - if (($tmp_data - $data['check'][1]) >= 0) { - $data['check'][4] = $data['check'][3]; - $tmp_data -= $data['check'][3]; - $tmp_facility_received = $data['check'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['check'][3]) && $data['facility'][$this_facility]['check'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['check'][3]) { - $data['facility'][$this_facility]['check'][4] = $data['facility'][$this_facility]['check'][3]; - $data['facility'][$this_facility]['check'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['check'][3]; - } else { - $data['facility'][$this_facility]['check'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['check'][5] = $data['facility'][$this_facility]['check'][3] - $data['facility'][$this_facility]['check'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['check'][4] = 0; - $data['facility'][$this_facility]['check'][5] = $data['facility'][$this_facility]['check'][3]; - } - } else { - $data['facility'][$this_facility]['check'][4] = 0; - $data['facility'][$this_facility]['check'][5] = 0; - $data['facility'][$this_facility]['check'][6] = 0; - } - if ($data['facility'][$this_facility]['check'][5] == 0) { - $data['facility'][$this_facility]['check'][6] = 0; - } - } - } else { - $data['check'][4] = $tmp_data; - $tmp_data = 0; - $tmp_facility_received = $data['check'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['check'][3]) && $data['facility'][$this_facility]['check'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['check'][3]) { - $data['facility'][$this_facility]['check'][4] = $data['facility'][$this_facility]['check'][3]; - $data['facility'][$this_facility]['check'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['check'][3]; - } else { - $data['facility'][$this_facility]['check'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['check'][5] = $data['facility'][$this_facility]['check'][3] - $data['facility'][$this_facility]['check'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['check'][4] = 0; - $data['facility'][$this_facility]['check'][5] = $data['facility'][$this_facility]['check'][3]; - } - } else { - $data['facility'][$this_facility]['check'][4] = 0; - $data['facility'][$this_facility]['check'][5] = 0; - $data['facility'][$this_facility]['check'][6] = 0; - } - if ($data['facility'][$this_facility]['check'][5] == 0) { - $data['facility'][$this_facility]['check'][6] = 0; - } - } - } - $data['check'][5] = $data['check'][3] - $data['check'][4]; - } else { - $data['check'][4] = 0; - $data['check'][5] = $data['check'][3]; - foreach ($facilities as $this_facility) { - $data['facility'][$this_facility]['check'][4] = 0; - $data['facility'][$this_facility]['check'][5] = $data['facility'][$this_facility]['check'][3]; - if ($data['facility'][$this_facility]['check'][5] == 0) { - $data['facility'][$this_facility]['check'][6] = 0; - } - } - } - if ($tmp_invoice > 0) { - if (($tmp_invoice - $data['check'][3]) >= 0) { - $data['check'][6] = $data['check'][3]; - $tmp_invoice -= $data['check'][3]; - } else { - $data['check'][6] = $tmp_invoice; - $tmp_invoice = 0; - } - $data['check'][7] = $data['check'][3] - $data['check'][6]; - } else { - $data['check'][6] = 0; - $data['check'][7] = $data['check'][3]; - } - } else { - $data['check'][4] = 0; - $data['check'][5] = 0; - $data['check'][6] = 0; - $data['check'][7] = 0; - } - if (isset($data['delivery'][3]) && $data['delivery'][3] > 0) { - if ($tmp_data > 0) { - if (($tmp_data - $data['delivery'][1]) >= 0) { - $data['delivery'][4] = $data['delivery'][3]; - $tmp_data -= $data['delivery'][3]; - $tmp_facility_received = $data['delivery'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['delivery'][3]) && $data['facility'][$this_facility]['delivery'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['delivery'][3]) { - $data['facility'][$this_facility]['delivery'][4] = $data['facility'][$this_facility]['delivery'][3]; - $data['facility'][$this_facility]['delivery'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['delivery'][3]; - } else { - $data['facility'][$this_facility]['delivery'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['delivery'][5] = $data['facility'][$this_facility]['delivery'][3] - $data['facility'][$this_facility]['delivery'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['delivery'][4] = 0; - $data['facility'][$this_facility]['delivery'][5] = $data['facility'][$this_facility]['delivery'][3]; - } - } else { - $data['facility'][$this_facility]['delivery'][4] = 0; - $data['facility'][$this_facility]['delivery'][5] = 0; - $data['facility'][$this_facility]['delivery'][6] = 0; - } - if ($data['facility'][$this_facility]['delivery'][5] == 0) { - $data['facility'][$this_facility]['delivery'][6] = 0; - } - } - } else { - $data['delivery'][4] = $tmp_data; - $tmp_data = 0; - $tmp_facility_received = $data['delivery'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['delivery'][3]) && $data['facility'][$this_facility]['delivery'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['delivery'][3]) { - $data['facility'][$this_facility]['delivery'][4] = $data['facility'][$this_facility]['delivery'][3]; - $data['facility'][$this_facility]['delivery'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['delivery'][3]; - } else { - $data['facility'][$this_facility]['delivery'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['delivery'][5] = $data['facility'][$this_facility]['delivery'][3] - $data['facility'][$this_facility]['delivery'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['delivery'][4] = 0; - $data['facility'][$this_facility]['delivery'][5] = $data['facility'][$this_facility]['delivery'][3]; - } - } else { - $data['facility'][$this_facility]['delivery'][4] = 0; - $data['facility'][$this_facility]['delivery'][5] = 0; - $data['facility'][$this_facility]['delivery'][6] = 0; - } - if ($data['facility'][$this_facility]['delivery'][5] == 0) { - $data['facility'][$this_facility]['delivery'][6] = 0; - } - } - } - $data['delivery'][5] = $data['delivery'][3] - $data['delivery'][4]; - } else { - $data['delivery'][4] = 0; - $data['delivery'][5] = $data['delivery'][3]; - foreach ($facilities as $this_facility) { - $data['facility'][$this_facility]['delivery'][4] = 0; - $data['facility'][$this_facility]['delivery'][5] = $data['facility'][$this_facility]['delivery'][3]; - if ($data['facility'][$this_facility]['sign'][5] == 0) { - $data['facility'][$this_facility]['sign'][6] = 0; - } - } - } - if ($tmp_invoice > 0) { - if (($tmp_invoice - $data['delivery'][3]) >= 0) { - $data['delivery'][6] = $data['delivery'][3]; - $tmp_invoice -= $data['delivery'][3]; - } else { - $data['delivery'][6] = $tmp_invoice; - $tmp_invoice = 0; - } - $data['delivery'][7] = $data['delivery'][3] - $data['delivery'][6]; - } else { - $data['delivery'][6] = 0; - $data['delivery'][7] = $data['delivery'][3]; - } - } else { - $data['delivery'][4] = 0; - $data['delivery'][5] = 0; - $data['delivery'][6] = 0; - $data['delivery'][7] = 0; - } - - if (isset($data['final'][3]) && $data['final'][3] > 0) { - if ($tmp_data > 0) { - if (($tmp_data - $data['final'][1]) >= 0) { - $data['final'][4] = $data['final'][3]; - $tmp_data -= $data['final'][3]; - $tmp_facility_received = $data['final'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['final'][3]) && $data['facility'][$this_facility]['final'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['final'][3]) { - $data['facility'][$this_facility]['final'][4] = $data['facility'][$this_facility]['final'][3]; - $data['facility'][$this_facility]['final'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['final'][3]; - } else { - $data['facility'][$this_facility]['final'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['final'][5] = $data['facility'][$this_facility]['final'][3] - $data['facility'][$this_facility]['final'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['final'][4] = 0; - $data['facility'][$this_facility]['final'][5] = $data['facility'][$this_facility]['final'][3]; - } - } else { - $data['facility'][$this_facility]['final'][4] = 0; - $data['facility'][$this_facility]['final'][5] = 0; - $data['facility'][$this_facility]['final'][6] = 0; - } - if ($data['facility'][$this_facility]['final'][5] == 0) { - $data['facility'][$this_facility]['final'][6] = 0; - } - } - } else { - $data['final'][4] = $tmp_data; - $tmp_data = 0; - $tmp_facility_received = $data['final'][4]; - foreach ($facilities as $this_facility) { - if (isset($data['facility'][$this_facility]['final'][3]) && $data['facility'][$this_facility]['final'][3] > 0) { - if ($tmp_facility_received > 0) { - if ($tmp_facility_received >= $data['facility'][$this_facility]['final'][3]) { - $data['facility'][$this_facility]['final'][4] = $data['facility'][$this_facility]['final'][3]; - $data['facility'][$this_facility]['final'][5] = 0; - $tmp_facility_received -= $data['facility'][$this_facility]['final'][3]; - } else { - $data['facility'][$this_facility]['final'][4] = $tmp_facility_received; - $data['facility'][$this_facility]['final'][5] = $data['facility'][$this_facility]['final'][3] - $data['facility'][$this_facility]['final'][4]; - $tmp_facility_received = 0; - } - } else { - $data['facility'][$this_facility]['final'][4] = 0; - $data['facility'][$this_facility]['final'][5] = $data['facility'][$this_facility]['final'][3]; - } - } else { - $data['facility'][$this_facility]['final'][4] = 0; - $data['facility'][$this_facility]['final'][5] = 0; - $data['facility'][$this_facility]['final'][6] = 0; - } - if ($data['facility'][$this_facility]['final'][5] == 0) { - $data['facility'][$this_facility]['final'][6] = 0; - } - } - } - $data['final'][5] = $data['final'][3] - $data['final'][4]; - } else { - $data['final'][4] = 0; - $data['final'][5] = $data['final'][3]; - foreach ($facilities as $this_facility) { - $data['facility'][$this_facility]['final'][4] = 0; - $data['facility'][$this_facility]['final'][5] = $data['facility'][$this_facility]['final'][3]; - } - if ($data['facility'][$this_facility]['final'][5] == 0) { - $data['facility'][$this_facility]['final'][6] = 0; - } - } - if ($tmp_invoice > 0) { - if (($tmp_invoice - $data['final'][3]) >= 0) { - $data['final'][6] = $data['final'][3]; - $tmp_invoice -= $data['final'][3]; - } else { - $data['final'][6] = $tmp_invoice; - $tmp_invoice = 0; - } - $data['final'][7] = $data['final'][3] - $data['final'][6]; - } else { - $data['final'][6] = 0; - $data['final'][7] = $data['final'][3]; - } - } else { - $data['final'][4] = 0; - $data['final'][5] = 0; - $data['final'][6] = 0; - $data['final'][7] = 0; } } - -//產生excel的array +// 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']) - ]; + 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'])) - //['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]; - } - $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'])) ]; - 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); ?>
- - - -
-
-
-
- - - - +
-
-

合約 (新梯)統整資訊

+

合約 (汰改)統整資訊

-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- - -
-
-
- - - -
- +
+ + +
+
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - $value) { - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + $row) { ?> + + + + + + + + + + + + + + + + - +
合約號部門經理營業員客戶名稱簽約款應收簽約金額簽約最小催收次數簽約最大催收次數二次款應收二次金額二次最小催收次數二次最大催收次數貨抵工地款應收貨抵工地金額貨抵工地最小催收次數貨抵工地最大催收次數安裝款應收安裝金額安裝最小催收次數安裝最大催收次數試車款應收試車金額試車最小催收次數試車最大催收次數官檢款應收官檢金額官檢最小催收次數官檢最大催收次數移交款應收移交金額移交最小催收次數移交最大催收次數尾款應收尾款金額尾款最小催收次數尾款最大催收次數合約總金額目前應收已開發票金額已收金額收款狀態合約號作番號部門主管契約員客戶名稱收款階段應收日期是否應收應收金額已開金額未開金額已收金額催收金額催收次數
" . $row[3]; ?>" . $row[5]; ?>" . $row[7]; ?>
- \ No newline at end of file diff --git a/wms/account-receivable-renovate.xlsx b/wms/account-receivable-renovate.xlsx new file mode 100644 index 00000000..3c8c5dcf Binary files /dev/null and b/wms/account-receivable-renovate.xlsx differ diff --git a/wms/account-receivable-test.php b/wms/account-receivable-test.php index 65ab59fc..52c6056c 100644 --- a/wms/account-receivable-test.php +++ b/wms/account-receivable-test.php @@ -374,9 +374,17 @@ $P_all = " // echo $value['facilityno']. ";" . $value['actual_tofactory_date'] . "
"; // } -$sql_paystage = "SELECT A.PayStage, A.BillNo FROM salOrderStagePay AS A -LEFT JOIN salSalesOrder AS s on a.BillNo = s.BillNo WHERE s.ModeId = 'T' AND (s.CurrentState=2 OR s.CurrentState=4)"; -$query_paystage = $conn->query($sql_paystage); -foreach($query_paystage as $key => $value) { - echo $value['PayStage'] .";".$value['BillNo']. "
"; +// $sql_paystage = "SELECT A.PayStage, A.BillNo FROM salOrderStagePay AS A +// LEFT JOIN salSalesOrder AS s on a.BillNo = s.BillNo WHERE s.ModeId = 'T' AND (s.CurrentState=2 OR s.CurrentState=4)"; +// $query_paystage = $conn->query($sql_paystage); +// foreach($query_paystage as $key => $value) { +// echo $value['PayStage'] .";".$value['BillNo']. "
"; +// } + +$sql = "SELECT A.BillNo,B.CU_MaterialId, B.ProjectId FROM salSalesOrder AS A +LEFT JOIN salSalesOrderDetail AS B ON A.BillNo=B.BillNo +WHERE A.ModeId='T' AND B.ItemType=0 AND A.BillNo != B.ProjectId AND A.CurrentState=4"; +$query = $conn->query($sql); +foreach($query as $key => $value) { + echo $value['BillNo'] .";".$value['CU_MaterialId'].";".$value['ProjectId']. "
"; } \ No newline at end of file diff --git a/wms/bons/api/get.php b/wms/bons/api/get.php new file mode 100644 index 00000000..b50687a3 --- /dev/null +++ b/wms/bons/api/get.php @@ -0,0 +1,75 @@ +prepare($sql); +$stmt->execute(); +$data = $stmt->fetch(PDO::FETCH_ASSOC); +$data['amount'] = intval($data['amount']); +$checkBillNo = $data['CBno']; + + +$sql = "SELECT + 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 c.checkBillNo = '$checkBillNo' + "; + +$stmt = $connT8->prepare($sql); +$stmt->execute(); +$check = $stmt->fetch(PDO::FETCH_ASSOC); + + + +$CU_MaterialId = $data['facility']; +$sql = "SELECT SQuantity FROM salIncomeApplyDetail WHERE BillNo = :contract_no AND CU_MaterialId = :CU_MaterialId"; +$stmt = $connT8->prepare($sql); +$stmt->bindParam(':contract_no', $contract_no); +$stmt->bindParam(':CU_MaterialId', $CU_MaterialId); +$stmt->execute(); +$result = $stmt->fetchAll(PDO::FETCH_ASSOC); +$count = COUNT($result); +$data['maintain_month'] = intval($count * $result[0]['SQuantity']); + + + + +if (!empty($check['CheckBillDate'])) { + header('Content-Type: application/json'); + echo json_encode($data); +} else { + echo false; + exit; +} +// } diff --git a/wms/bons/bons_index.php b/wms/bons/bons_index.php new file mode 100644 index 00000000..0ee7058a --- /dev/null +++ b/wms/bons/bons_index.php @@ -0,0 +1,135 @@ + + + + + + + + + + + +
+
+ +
+ + + + + + + + + + + +
+

獎金計算

+
+ + + + +
+
+
\ No newline at end of file diff --git a/wms/bons/elevator_new/elevator_new_deal_bonus_v1_0.php b/wms/bons/elevator_new/elevator_new_deal_bonus_v1_0.php new file mode 100644 index 00000000..7d45b3a1 --- /dev/null +++ b/wms/bons/elevator_new/elevator_new_deal_bonus_v1_0.php @@ -0,0 +1,125 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + + +function elevator_new_deal_bonus_v1_0($ver, $contract_type, $elevator_knockdown_price, $sales_id, $region_manger_id){ + $bonus_array = []; + if ($ver == "1.0"){ + + #合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer) + switch ($contract_type){ + case "strategy_customer": + #契約員獎金($sales_bonus) + $sales_bonus = $elevator_knockdown_price * 0.007; + #地區經理經理獎金($region_manager_bonus) + $region_manager_bonus = 400; + break; + + case "general_customer": + #契約員獎金($sales_bonus) + $sales_bonus = $elevator_knockdown_price * 0.015; + #區域經理獎金($region_manager_bonus) + $region_manager_bonus = 600; + break; + }; + + #營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% + array_push($bonus_array,[ + "bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus * 0.2), #金額 + "payment_schedul_due" => "deposit", #訂金已收款20% + "payment_schedul_regulation" => "訂金已收款20%,發放總獎金20%" #發放規定 + ]); + + #營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% + array_push($bonus_array,[ + "bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus * 0.5), #金額 + "payment_schedul_due" => "shipping", #訂金已收款20% + "payment_schedul_regulation" => "出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%" #發放規定 + ]); + + #營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% + array_push($bonus_array,[ + "bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus * 0.3), #金額 + "payment_schedul_due" => "acceptance", #訂金已收款20% + "payment_schedul_regulation" => "驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%" #發放規定 + ]); + + #區域經理獎金水庫-----訂金已收款100%,發放總獎金50% + array_push($bonus_array,[ + "bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus * 0.5), #金額 + "payment_schedul_due" => "deposit", #訂金已收款100% + "payment_schedul_regulation" => "訂金已收款100%,發放總獎金50%" #發放規定 + ]); + + #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% + array_push($bonus_array,[ + "bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus * 0.5), #金額 + "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100% + "payment_schedul_regulation" => "貨到工地款(含)之前所有款項已收款100%,發放總獎金50%" #發放規定 + ]); + + $result_array = [ + "ver"=>$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "bonus_array"=>$bonus_array #獎金水庫 + ]; + }else{ + array_push($bonus_array,[ + "bonus_type" => "error", #獎金名稱 + "bonus_receiver" => "error", #發放人員 + "bonus_amount" => 0, #金額 + "payment_schedul_due" => "9999-1-1", #預計發放時間 + "payment_schedul_regulation" => "error" #發放規定 + ]); + + $result_array = [ + "ver"=>$ver, #獎金版本 + "result_status"=>"error", #計算結果 + "bonus_array"=>$bonus_array #獎金水庫 + ]; + }; + + return $result_array; +}; + +?> \ No newline at end of file diff --git a/wms/bons/elevator_new/elevator_new_deal_bonus_v1_0_examination.php b/wms/bons/elevator_new/elevator_new_deal_bonus_v1_0_examination.php new file mode 100644 index 00000000..97c47660 --- /dev/null +++ b/wms/bons/elevator_new/elevator_new_deal_bonus_v1_0_examination.php @@ -0,0 +1,72 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + +require_once("elevator_new_deal_bonus_v1_0.php"); + +#$ver, $contract_type, $elevator_knockdown_price, $sales_id, $region_manger_id + +#獎金測試 +$examination_array = [ + #錯誤版本 + ["2.0","strategy_customer",1000000,"M0001", "M0003"], + #戰略客戶(strategy_customer) + ["1.0","strategy_customer",1000000,"M0001", "M0003"], #戰略客戶 + + #一般客戶(general_customer) + ["1.0","general_customer",1000000,"M0001", "M0003"] #一般客戶 +]; + + + +for($i = 0; $i"; + echo "計算結果:" . $result["result_status"] . "
"; + echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . "
"; + for($j = 0; $j"; + }; + echo "-------------------------" . "
"; + +}; + + +?> diff --git a/wms/bons/elevator_new/elevator_new_deal_bonus_v2_0.php b/wms/bons/elevator_new/elevator_new_deal_bonus_v2_0.php new file mode 100644 index 00000000..84dde3cd --- /dev/null +++ b/wms/bons/elevator_new/elevator_new_deal_bonus_v2_0.php @@ -0,0 +1,164 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + + +function elevator_new_deal_bonus_v2_0($ver, $contract_type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $sales_id, $region_manger_id){ + $bonus_array = []; + if ($ver == "2.0"){ + $discount = round($elevator_knockdown_price / $elevator_list_price, 3); #銷售點數,取到小數點第三位。 + + #合約總類($contract_type):戰略客戶(strategy_customer)、一般客戶(general_customer) + switch ($contract_type){ + case "strategy_customer": + #契約員獎金($sales_bonus) + $sales_bonus = $elevator_knockdown_price * 0.007; + #地區經理提成獎金($region_manager_bonus) + $region_manager_bonus = 400; + break; + + case "general_customer": + switch ($elevator_type) { + #客梯(passenger)、貨梯(cargo) + case ($elevator_type == "passenger" or $elevator_type == "cargo"): + switch ($discount) { + case ($discount >= 1.0): + $sales_bonus = $elevator_knockdown_price * 0.02; + break; + case ($discount >= 0.9 and $discount < 1.0): + $sales_bonus = $elevator_knockdown_price * 0.018; + break; + case ($discount >= 0.75 and $discount < 0.9): + $sales_bonus = $elevator_knockdown_price * 0.015; + break; + case ($discount < 0.75): + $sales_bonus = $elevator_knockdown_price * 0.008; + break; + }; + break; + + #小電梯(dumbwaiter)、平台梯(flatbase)、強驅(positive_drive) + case ($elevator_type == "dumbwaiter" or $elevator_type == "flatbase" or $elevator_type == "positive_drive"): + switch ($discount) { + case ($discount >= 1.0): + $sales_bonus = $elevator_knockdown_price * 0.02; + break; + case ($discount >= 0.9 and $discount < 1.0): + $sales_bonus = $elevator_knockdown_price * 0.018; + break; + case ($discount >= 0.72 and $discount < 0.9): + $sales_bonus = $elevator_knockdown_price * 0.015; + break; + case ($discount < 0.72): + $sales_bonus = $elevator_knockdown_price * 0.008; + break; + }; + break; + }; + #區域經理提成獎金($region_manager_bonus) + $region_manager_bonus = 600; + break; + }; + + #營銷人員銷售獎金水庫-----訂金已收款20%,發放總獎金20% + array_push($bonus_array,[ + "bonus_type" => "營銷人員銷售獎金-訂金段", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus * 0.2), #金額 + "payment_schedul_due" => "deposit", #訂金已收款20% + "payment_schedul_regulation" => "訂金已收款20%,發放總獎金20%" #發放規定 + ]); + + #營銷人員銷售獎金水庫-----出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50% + array_push($bonus_array,[ + "bonus_type" => "營銷人員銷售獎金-出貨款段", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus * 0.5), #金額 + "payment_schedul_due" => "shipping", #訂金已收款20% + "payment_schedul_regulation" => "出貨前期所有款項已收齊,且出貨款已收款50%,發放總獎金50%" #發放規定 + ]); + + #營銷人員銷售獎金水庫-----驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30% + array_push($bonus_array,[ + "bonus_type" => "營銷人員銷售獎金-驗收款段", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus * 0.3), #金額 + "payment_schedul_due" => "acceptance", #訂金已收款20% + "payment_schedul_regulation" => "驗收前期所有款項已收齊,且驗收款已收款30%,發放總獎金30%" #發放規定 + ]); + + #區域經理提成獎金水庫-----訂金已收款100%,發放總獎金50% + array_push($bonus_array,[ + "bonus_type" => "區域經理提成獎金-訂金段", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus * 0.5), #金額 + "payment_schedul_due" => "deposit", #訂金已收款100% + "payment_schedul_regulation" => "訂金已收款100%,發放總獎金50%" #發放規定 + ]); + + #區域經理獎金水庫-----貨到工地款(含)之前所有款項已收款100%,發放總獎金50% + array_push($bonus_array,[ + "bonus_type" => "區域經理提成獎金-貨到工地款段", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus * 0.5), #金額 + "payment_schedul_due" => "deliveried", #貨到工地款(含)之前所有款項已收款100% + "payment_schedul_regulation" => "貨到工地款(含)之前所有款項已收款100%,發放總獎金50%" #發放規定 + ]); + + $result_array = [ + "ver"=>$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "bonus_array"=>$bonus_array #獎金水庫 + ]; + }else{ + array_push($bonus_array,[ + "bonus_type" => "error", #獎金名稱 + "bonus_receiver" => "error", #發放人員 + "bonus_amount" => 0, #金額 + "payment_schedul_due" => "9999-1-1", #預計發放時間 + "payment_schedul_regulation" => "error" #發放規定 + ]); + + $result_array = [ + "ver"=>$ver, #獎金版本 + "result_status"=>"error", #計算結果 + "bonus_array"=>$bonus_array #獎金水庫 + ]; + }; + + return $result_array; +}; + +?> \ No newline at end of file diff --git a/wms/bons/elevator_new/elevator_new_deal_bonus_v2_0_examination.php b/wms/bons/elevator_new/elevator_new_deal_bonus_v2_0_examination.php new file mode 100644 index 00000000..771b791b --- /dev/null +++ b/wms/bons/elevator_new/elevator_new_deal_bonus_v2_0_examination.php @@ -0,0 +1,116 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + +require_once("elevator_new_deal_bonus_v2_0.php"); + +#$ver, $contract_type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $sales_id, $region_manger_id + +#獎金測試 +$examination_array = [ + #錯誤版本 + ["1.0","strategy_customer","passenger",1000000,1000000,"M0001", "M0003"], + #戰略客戶(strategy_customer) + ["2.0","strategy_customer","passenger",1000000,1000000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數100% + ["2.0","strategy_customer","passenger",1000000,900000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數90% + ["2.0","strategy_customer","passenger",1000000,750000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數75% + ["2.0","strategy_customer","passenger",1000000,600000,"M0001", "M0003"], #戰略客戶、客梯、銷售點數60% + ["2.0","strategy_customer","cargo",1000000,1000000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數100% + ["2.0","strategy_customer","cargo",1000000,900000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數90% + ["2.0","strategy_customer","cargo",1000000,750000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數75% + ["2.0","strategy_customer","cargo",1000000,600000,"M0001", "M0003"], #戰略客戶、貨梯、銷售點數60% + ["2.0","strategy_customer","dumbwaiter",1000000,1000000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數100% + ["2.0","strategy_customer","dumbwaiter",1000000,900000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數90% + ["2.0","strategy_customer","dumbwaiter",1000000,720000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數75% + ["2.0","strategy_customer","dumbwaiter",1000000,600000,"M0001", "M0003"], #戰略客戶、小電梯、銷售點數60% + ["2.0","strategy_customer","flatbase",1000000,1000000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數100% + ["2.0","strategy_customer","flatbase",1000000,900000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數90% + ["2.0","strategy_customer","flatbase",1000000,720000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數75% + ["2.0","strategy_customer","flatbase",1000000,600000,"M0001", "M0003"], #戰略客戶、平台梯、銷售點數60% + ["2.0","strategy_customer","positive_drive",1000000,1000000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數100% + ["2.0","strategy_customer","positive_drive",1000000,900000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數90% + ["2.0","strategy_customer","positive_drive",1000000,720000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數75% + ["2.0","strategy_customer","positive_drive",1000000,600000,"M0001", "M0003"], #戰略客戶、強驅、銷售點數60% + + #一般客戶(general_customer) + ["2.0","general_customer","passenger",1000000,1000000,"M0001", "M0003"], #一般客戶、客梯、銷售點數100% + ["2.0","general_customer","passenger",1000000,900000,"M0001", "M0003"], #一般客戶、客梯、銷售點數90% + ["2.0","general_customer","passenger",1000000,750000,"M0001", "M0003"], #一般客戶、客梯、銷售點數75% + ["2.0","general_customer","passenger",1000000,600000,"M0001", "M0003"], #一般客戶、客梯、銷售點數60% + ["2.0","general_customer","cargo",1000000,1000000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數100% + ["2.0","general_customer","cargo",1000000,900000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數90% + ["2.0","general_customer","cargo",1000000,750000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數75% + ["2.0","general_customer","cargo",1000000,600000,"M0001", "M0003"], #一般客戶、貨梯、銷售點數60% + ["2.0","general_customer","dumbwaiter",1000000,1000000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數100% + ["2.0","general_customer","dumbwaiter",1000000,900000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數90% + ["2.0","general_customer","dumbwaiter",1000000,720000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數75% + ["2.0","general_customer","dumbwaiter",1000000,600000,"M0001", "M0003"], #一般客戶、小電梯、銷售點數60% + ["2.0","general_customer","flatbase",1000000,1000000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數100% + ["2.0","general_customer","flatbase",1000000,900000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數90% + ["2.0","general_customer","flatbase",1000000,720000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數75% + ["2.0","general_customer","flatbase",1000000,600000,"M0001", "M0003"], #一般客戶、平台梯、銷售點數60% + ["2.0","general_customer","positive_drive",1000000,1000000,"M0001", "M0003"], #一般客戶、強驅、銷售點數100% + ["2.0","general_customer","positive_drive",1000000,900000,"M0001", "M0003"], #一般客戶、強驅、銷售點數90% + ["2.0","general_customer","positive_drive",1000000,720000,"M0001", "M0003"], #一般客戶、強驅、銷售點數75% + ["2.0","general_customer","positive_drive",1000000,600000,"M0001", "M0003"] #一般客戶、強驅、銷售點數60% +]; + + + +for($i = 0; $i"; + echo "計算結果:" . $result["result_status"] . "
"; + echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " " + . $examination_array[$i][5] . " " . $examination_array[$i][6] . "
"; + for($j = 0; $j"; + }; + echo "-------------------------" . "
"; + +}; + + +?> diff --git a/wms/bons/maintainance_contract_payment_status.php b/wms/bons/maintainance_contract_payment_status.php new file mode 100644 index 00000000..ed76f046 --- /dev/null +++ b/wms/bons/maintainance_contract_payment_status.php @@ -0,0 +1,399 @@ +query($sql); + +function getContractnoDetails($link, $user_id, $contractno = null) +{ + $sql = " + SELECT + c.contractno + FROM contract AS c + LEFT JOIN con_maintance_examine_apply AS cmea + ON c.contractno = cmea.vol_no + WHERE 1 = 1 + AND cmea.salesman IN (" . getAccountids($link, $user_id) . ") + "; + if (!empty($contractno)) { + $sql .= " + AND c.contractno = '$contractno' + "; + } + $result = mysqli_query($link, $sql); + $data = []; + foreach ($result as $row) { + array_push($data, $row['contractno']); + } + return "'" . implode("','", $data) . "'"; +} + +function getSalesmanNo($link, $contractno) +{ + $sql = " + SELECT + cmea.salesman + FROM contract AS c + LEFT JOIN con_maintance_examine_apply AS cmea + ON c.contractno = cmea.vol_no + WHERE 1 = 1 + AND c.contractno IN ('$contractno') + "; + $result = mysqli_query($link, $sql); + $data = []; + foreach ($result as $row) + return $row['salesman']; + return ""; +} +function getSalesmanName($link, $contractno) +{ + $sql = " + SELECT + a.name + FROM contract AS c + LEFT JOIN con_maintance_examine_apply AS cmea + ON c.contractno = cmea.vol_no + LEFT JOIN account AS a + ON cmea.salesman = a.accountid + WHERE 1 = 1 + AND c.contractno IN ('$contractno') + "; + $result = mysqli_query($link, $sql); + $data = []; + foreach ($result as $row) + return $row['name']; + return ""; +} + +function getAccountids($link, $user_id) +{ + $sql = " + SELECT + accountid + FROM account + WHERE 1 = 1 + AND (accountid = '$user_id' + OR accountid IN ( + SELECT + accountid + FROM account + WHERE 1 = 1 + AND manager = '$user_id' + AND accounttype IN ('B','E','M','W') + ) + ) + "; + $result = mysqli_query($link, $sql); + $data = []; + foreach ($result as $row) { + array_push($data, $row['accountid']); + } + return "'" . implode("','", $data) . "'"; +} + +function checkArCheckBillStatus($row) +{ + $CU_EstPayDate = $row['CU_EstPayDate']; + $BillNo2 = $row['BillNo2']; + if (substr($CU_EstPayDate, 0, 6) <= date("Ym")) { + if (empty($BillNo2)) { + return "未轉應收確認單"; + } else { + return "已轉應收確認單"; + } + } else { + return "時間未到"; + } +} + +function arSellInvoiceMaterial($row) +{ + + $CU_EstPayDate = $row['CU_EstPayDate']; + $InvoiceName = $row['InvoiceName']; + + if (substr($CU_EstPayDate, 0, 6) <= date("Ym")) { + if (empty($InvoiceName)) { + return "未開發票"; + } else { + return "已開發票"; + } + } else { + return "時間未到"; + } +} + +function checkArWriteOffBill($conn, $row) +{ + $BillNo = $row['BillNo2']; + + $sql = " + 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 c.checkBillNo = '$BillNo' + "; + + $del = $conn->query($sql); + $i = 0; + foreach ($del as $row) + $i++; + if (empty($i)) { + return "未收款"; + } else { + return "已收款"; + } +} + +?> + + + + + + + + +
+
+ + + + + + + + + + + + + +
+

保養合約-應收款項明細

+
合約號 + + + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
營業人員/契約人員合約號標示號電梯編號預計請款日催收次數應收申請單狀態請款金額(未轉應收)請款金額(已轉應收)應收申請單號發票狀態發票單標示號發票單號發票明細發票金額發票號碼核銷
+ "; + echo getSalesmanName($link, $row['BillNo']); + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +There is no record!"; +endif; + +#代表結束連線 +mysqli_close($link); + +include "footer.php"; +?> \ No newline at end of file diff --git a/wms/bons/maintance/maintenance_contract_bonus_v2_0.php b/wms/bons/maintance/maintenance_contract_bonus_v2_0.php new file mode 100644 index 00000000..c2cadb3e --- /dev/null +++ b/wms/bons/maintance/maintenance_contract_bonus_v2_0.php @@ -0,0 +1,248 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + + +function maintenance_contract_bonus_v2_0($ver, $contract_type, $contract_years, $discount, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_manger_id, $regular_contract_manger_id){ + $bonus_array = []; + if ($ver == "2.0"){ + + #契約總類($contract_type):新簽約(new)、免保轉有費(free_to_charge)、續簽約(原價或僅契約金額異動)(renew_priceissue) + switch ($contract_type){ + case "new": + #契約員獎金($sales_bonus) + switch ($fee_per_st) { + case ($fee_per_st <= 3000): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.6; + break; + case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.7; + break; + case ($fee_per_st >= 3500 and $fee_per_st <= 3999): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.8; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.9; + break; + }; + #地區經理經理獎金($region_manager_bonus) + $region_manager_bonus = 170; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 300; + break; + + case "free_to_charge": + switch ($fee_per_st) { + case ($fee_per_st <= 3000): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.3; + break; + case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.35; + break; + case ($fee_per_st >= 3500 and $fee_per_st <= 3999): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.4; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.5; + break; + }; + #地區經理經理獎金($region_manager_bonus) + $region_manager_bonus = 100; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 100; + break; + + case "renew_priceissue": + switch ($fee_per_st) { + case ($fee_per_st <= 3000): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.25; + break; + case ($fee_per_st >= 3001 and $fee_per_st <= 3499): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.3; + break; + case ($fee_per_st >= 3500 and $fee_per_st <= 3999): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.35; + break; + case ($fee_per_st >= 4000): + $sales_bonus = ($fee_per_st - $commission_fee) * 0.4; + break; + }; + #地區經理經理獎金($region_manager_bonus) + $region_manager_bonus = 100; + #專任契約經理獎金($regular_contract_manger_bonus) + $regular_contract_manger_bonus = 100; + break; + }; + + #合約折扣率($discount):大於80%以上(含)(above_80)、60-79%(含)以上(60_to_79)、折扣率59% (含)以下(below_59) + switch ($discount) { + case ($discount < 0.6): + $sales_bonus = $sales_bonus * 0.7; + break; + case ($discount >= 0.6 and $discount < 0.8): + $sales_bonus = $sales_bonus * 0.8; + break; + case ($discount >= 0.8): + $sales_bonus = $sales_bonus * 1.0; + break; + }; + + #簽約年數($contract_years):1年(1),超過1年(above) + + switch ($contract_years){ + case $contract_years == "one": + #契約員獎金 + array_push($bonus_array,[ + "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #地區經理經理獎金 + array_push($bonus_array,[ + "bonus_type" => "地區經理獎金", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #專任契約經理獎金 + array_push($bonus_array,[ + "bonus_type" => "專任契約經理獎金", #獎金名稱 + "bonus_receiver" => $regular_contract_manger_id, #發放人員 + "bonus_amount" => round($regular_contract_manger_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + $result_array = [ + "ver"=>$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "bonus_array"=>$bonus_array #獎金水庫 + ]; + break; + + case $contract_years == "above_two": + /*** 以下第1年獎金 ***/ + #契約員獎金 + array_push($bonus_array,[ + "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #地區經理經理獎金 + array_push($bonus_array,[ + "bonus_type" => "地區經理獎金", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #專任契約經理獎金 + array_push($bonus_array,[ + "bonus_type" => "專任契約經理獎金", #獎金名稱 + "bonus_receiver" => $regular_contract_manger_id, #發放人員 + "bonus_amount" => round($regular_contract_manger_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +1 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + /*** 以上第1年獎金 ***/ + + /*** 以下第2年獎金 ***/ + #第2年契約員獎金 + array_push($bonus_array,[ + "bonus_type" => "契約員獎金", #獎金名稱 + "bonus_receiver" => $sales_id, #發放人員 + "bonus_amount" => round($sales_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +13 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #第2年地區經理經理獎金 + array_push($bonus_array,[ + "bonus_type" => "地區經理獎金", #獎金名稱 + "bonus_receiver" => $region_manger_id, #發放人員 + "bonus_amount" => round($region_manager_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +13 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + + #第2年專任契約經理獎金 + array_push($bonus_array,[ + "bonus_type" => "專任契約經理獎金", #獎金名稱 + "bonus_receiver" => $regular_contract_manger_id, #發放人員 + "bonus_amount" => round($regular_contract_manger_bonus), #金額 + "pay_day_due" => date("Y-m-d",strtotime("$receivable_date_due +13 months")), #預計發放時間 + "bonus_regulation" => "合約簽回及保養款項收回的次月一次性發" #發放規定 + ]); + /*** 以上第2年獎金 ***/ + + $result_array = [ + "ver"=>$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "bonus_array"=>$bonus_array #獎金水庫 + ]; + break; + } + }else{ + array_push($bonus_array,[ + "bonus_type" => "error", #獎金名稱 + "bonus_receiver" => "error", #發放人員 + "bonus_amount" => 0, #金額 + "pay_day_due" => "9999-1-1", #預計發放時間 + "bonus_regulation" => "error" #發放規定 + ]); + $result_array = [ + "ver"=>$ver, #獎金版本 + "result_status"=>"error", #計算結果 + "bonus_array"=>$bonus_array #獎金水庫 + ]; + } + + return $result_array; +}; + + +?> diff --git a/wms/bons/maintance/maintenance_contract_bonus_v2_0_examination.php b/wms/bons/maintance/maintenance_contract_bonus_v2_0_examination.php new file mode 100644 index 00000000..de316b53 --- /dev/null +++ b/wms/bons/maintance/maintenance_contract_bonus_v2_0_examination.php @@ -0,0 +1,156 @@ +$ver, #獎金版本 + "result_status"=>"success", #計算結果 + "$bonus_array"=>$bonus_array #所有獎金水庫 + ]; + +*/ + + +require_once("maintenance_contract_bonus_v2_0.php"); + + + +#獎金測試 +$examination_array = [ + #錯誤版本 + ["1.0","new","one",0.8,4000,333, "2014-07-01", "M0001", "M0002", "M0003"], + #新簽約 + ["2.0","new","one",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 + ["2.0","new","one",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 + ["2.0","new","one",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 + ["2.0","new","one",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 + ["2.0","new","one",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 + ["2.0","new","one",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 + ["2.0","new","one",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 + ["2.0","new","one",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 + ["2.0","new","one",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 + ["2.0","new","one",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 + ["2.0","new","one",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 + ["2.0","new","one",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 + ["2.0","new","above_two",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 + ["2.0","new","above_two",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 + ["2.0","new","above_two",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 + ["2.0","new","above_two",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 + ["2.0","new","above_two",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 + ["2.0","new","above_two",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 + ["2.0","new","above_two",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 + ["2.0","new","above_two",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 + ["2.0","new","above_two",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 + ["2.0","new","above_two",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 + ["2.0","new","above_two",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 + ["2.0","new","above_two",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、4000元 + + #免保轉有費(free_to_charge) + ["2.0","free_to_charge","one",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 + ["2.0","free_to_charge","one",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 + ["2.0","free_to_charge","one",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 + ["2.0","free_to_charge","one",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 + ["2.0","free_to_charge","one",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 + ["2.0","free_to_charge","one",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 + ["2.0","free_to_charge","one",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 + ["2.0","free_to_charge","one",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 + ["2.0","free_to_charge","one",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 + ["2.0","free_to_charge","one",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 + ["2.0","free_to_charge","one",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 + ["2.0","free_to_charge","one",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 + ["2.0","free_to_charge","above_two",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 + ["2.0","free_to_charge","above_two",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 + ["2.0","free_to_charge","above_two",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 + ["2.0","free_to_charge","above_two",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 + ["2.0","free_to_charge","above_two",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 + ["2.0","free_to_charge","above_two",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 + ["2.0","free_to_charge","above_two",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 + ["2.0","free_to_charge","above_two",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 + ["2.0","free_to_charge","above_two",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 + ["2.0","free_to_charge","above_two",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 + ["2.0","free_to_charge","above_two",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 + ["2.0","free_to_charge","above_two",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、4000元 + + #續簽約(原價或僅契約金額異動)(renew_priceissue) + ["2.0","renew_priceissue","one",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3000元 + ["2.0","renew_priceissue","one",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3200元 + ["2.0","renew_priceissue","one",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、3500元 + ["2.0","renew_priceissue","one",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.8、4000元 + ["2.0","renew_priceissue","one",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3000元 + ["2.0","renew_priceissue","one",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3200元 + ["2.0","renew_priceissue","one",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、3500元 + ["2.0","renew_priceissue","one",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.7、4000元 + ["2.0","renew_priceissue","one",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3000元 + ["2.0","renew_priceissue","one",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3200元 + ["2.0","renew_priceissue","one",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、3500元 + ["2.0","renew_priceissue","one",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、1年、折扣率0.6、4000元 + ["2.0","renew_priceissue","above_two",0.8,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3000元 + ["2.0","renew_priceissue","above_two",0.8,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3200元 + ["2.0","renew_priceissue","above_two",0.8,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、3500元 + ["2.0","renew_priceissue","above_two",0.8,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.8、4000元 + ["2.0","renew_priceissue","above_two",0.7,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3000元 + ["2.0","renew_priceissue","above_two",0.7,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3200元 + ["2.0","renew_priceissue","above_two",0.7,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、3500元 + ["2.0","renew_priceissue","above_two",0.7,4000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.7、4000元 + ["2.0","renew_priceissue","above_two",0.6,3000,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3000元 + ["2.0","renew_priceissue","above_two",0.6,3200,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3200元 + ["2.0","renew_priceissue","above_two",0.6,3500,333,"2014-07-01", "M0001", "M0002", "M0003"], #新簽約、2年以上、折扣率0.6、3500元 + ["2.0","renew_priceissue","above_two",0.6,4000,333,"2014-07-01", "M0001", "M0002", "M0003"] #新簽約、2年以上、折扣率0.6、4000元 +]; + + + +for($i = 0; $i"; + echo "計算結果:" . $result["result_status"] . "
"; + echo "輸入參數:" . $examination_array[$i][1] . " " . $examination_array[$i][2] . " " . $examination_array[$i][3] . " " . $examination_array[$i][4] . " " + . $examination_array[$i][5] . " " . $examination_array[$i][6] . " " . $examination_array[$i][7]. " " . $examination_array[$i][8] . "
"; + for($j = 0; $j"; + }; + echo "-------------------------" . "
"; + +}; + + +?> diff --git a/wms/contract-repair/contract-repair-input.php b/wms/contract-repair/contract-repair-input.php index 67c069e4..d85fa1bd 100644 --- a/wms/contract-repair/contract-repair-input.php +++ b/wms/contract-repair/contract-repair-input.php @@ -48,7 +48,6 @@ $contract_stauts = ["合約簽回", "採購", "工程發包", "工程中", "修 報價單編號 -