= $start_date "; } if (!is_null($end_date)) { $end_date = (int)date('Ymd', strtotime($end_date)); $sql_all_contract .= " AND MainAll.BillDate <= $end_date "; } if ((in_array($user_id, array('M0060', 'M0175'))) || (in_array(accountidToDepartId($user_id), array('220', '210', '321')))) { } else { $sql_all_contract .= " AND (MainAll.PersonId = '$user_id'"; if (count($follower) > 0) { $column_str = "('$user_id'" . ",'"; $column_str .= implode("','", $follower); $column_str .= "')"; $sql_all_contract .= " OR MainAll.PersonId IN $column_str)"; } else { $sql_all_contract .= ")"; }; } $str_numbers = ""; $query_all_contract = $conn->query($sql_all_contract); if (is_iterable($query_all_contract)) { foreach ($query_all_contract as $contract_numbers) { if (!in_array($contract_numbers['BillNo'], $contractNumbers)) { array_push($contractNumbers, $contract_numbers['BillNo']); $arrayData[$contract_numbers['BillNo']]['BillNo'] = isset($contract_numbers['BillNo']) ? $contract_numbers['BillNo'] : '--'; $arrayData[$contract_numbers['BillNo']]['BillDate'] = isset($contract_numbers['BillDate']) ? $contract_numbers['BillDate'] : '--'; $arrayData[$contract_numbers['BillNo']]['CustomerId'] = isset($contract_numbers['BizPartnerId']) ? $contract_numbers['BizPartnerId'] : '--'; $arrayData[$contract_numbers['BillNo']]['CustomerName'] = isset($contract_numbers['BizPartnerName']) ? $contract_numbers['BizPartnerName'] : '--'; $arrayData[$contract_numbers['BillNo']]['CustomerAddress'] = isset($contract_numbers['ContactAddress']) ? $contract_numbers['ContactAddress'] : '--'; $arrayData[$contract_numbers['BillNo']]['OAmountWithTax'] = isset($contract_numbers['OAmountWithTax']) ? $contract_numbers['OAmountWithTax'] : 0; $arrayData[$contract_numbers['BillNo']]['PersonId'] = isset($contract_numbers['PersonId']) ? $contract_numbers['PersonId'] : '--'; $arrayData[$contract_numbers['BillNo']]['DeptId'] = isset($contract_numbers['DeptId']) ? $contract_numbers['DeptId'] : '--'; $arrayData[$contract_numbers['BillNo']]['PersonName'] = isset($contract_numbers['PersonName']) ? $contract_numbers['PersonName'] : '--'; $arrayData[$contract_numbers['BillNo']]['DeptName'] = isset($contract_numbers['DeptName']) ? $contract_numbers['DeptName'] : '--'; $arrayData[$contract_numbers['BillNo']]['ShortName'] = isset($contract_numbers['ShortName']) ? $contract_numbers['ShortName'] : '--'; $arrayData[$contract_numbers['BillNo']]['ManagerId'] = isset($contract_numbers['LeaderId']) ? $contract_numbers['LeaderId'] : '--'; $arrayData[$contract_numbers['BillNo']]['ManagerName'] = isset($contract_numbers['LeaderName']) ? $contract_numbers['LeaderName'] : '--'; $arrayData[$contract_numbers['BillNo']]['invoice_budget'] = 0; $arrayData[$contract_numbers['BillNo']]['received_budget'] = 0; $arrayData[$contract_numbers['BillNo']]['receivable_budget'] = 0; $arrayData[$contract_numbers['BillNo']]['collect_budget'] = 0; $arrayData[$contract_numbers['BillNo']]['A40001'] = 0; $arrayData[$contract_numbers['BillNo']]['A40008'] = 0; $arrayData[$contract_numbers['BillNo']]['collect_month'] = 0; $arrayData[$contract_numbers['BillNo']]['facility_status'] = ""; $arrayData[$contract_numbers['BillNo']]['facility'] = array(); $arrayData[$contract_numbers['BillNo']]['facility_num'] = 0; $arrayData[$contract_numbers['BillNo']]['total_budget'] = $contract_numbers['OAmountWithTax']; $sum_total_budget += $contract_numbers['OAmountWithTax']; $sum_contract += 1; } } $str_numbers .= "('" . implode("','", $contractNumbers) . "')"; } // T8 銷售訂單 作番總金額、作番A40001金額、作番A40008金額、合約A40001金額、合約A40008金額 $sql_contract_budget = "SELECT A.BillNo, A.OAmountWithTax,A.CU_MaterialId, A.MaterialId FROM salSalesOrderDetail AS A LEFT JOIN salSalesOrder AS B ON A.BillNo=B.BillNo WHERE B.ModeId='M' AND A.ItemType=1 "; $query_contract_budget = $conn->query($sql_contract_budget); foreach ($query_contract_budget as $contract_budget) { if (isset($arrayData[$contract_budget['BillNo']])) { $arrayData[$contract_budget['BillNo']][$contract_budget['MaterialId']] += $contract_budget['OAmountWithTax']; if (isset($arrayData[$contract_budget['BillNo']]['facility']) && isset($arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']])) { $arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']]['total_budget'] += $contract_budget['OAmountWithTax']; if (isset($arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']][$contract_budget['MaterialId']])) { $arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']][$contract_budget['MaterialId']] += $contract_budget['OAmountWithTax']; } else { $arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']][$contract_budget['MaterialId']] = $contract_budget['OAmountWithTax']; } } else { $arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']]['total_budget'] = $contract_budget['OAmountWithTax']; $arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']][$contract_budget['MaterialId']] = $contract_budget['OAmountWithTax']; $arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']]['status'] = ""; $sum_facility += 1; $arrayData[$contract_budget['BillNo']]['facility_num'] += 1; } switch ($contract_budget['MaterialId']) { case "A40001": $sum_A40001 += $contract_budget['OAmountWithTax']; break; case "A40008": $sum_A40008 += $contract_budget['OAmountWithTax']; break; } } } //T8 銷售訂單 階段收款計畫 $sql_PayStage = "SELECT a.RowNo, a.BillNo, s.BillDate, a.PayStage, a.PlanPayAmt, a.PlanPayDate, s.BizPartnerId, s.PersonId FROM salOrderStagePay AS a LEFT JOIN salSalesOrder AS s on a.BillNo = s.BillNo WHERE s.ModeId = 'M' AND (s.CurrentState=2 OR s.CurrentState=4) "; if (!empty($str_numbers)) { $sql_PayStage .= " AND s.BillNo IN " . $str_numbers; } $query_PayStage = $conn->query($sql_PayStage); // 把階段收款計畫放進arrayData內 foreach ($query_PayStage as $PayStage) { if (isset($arrayData[$PayStage['BillNo']])) { $arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]['PayStage'] = $PayStage['PayStage']; $arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]['PlanPayAmt'] = $PayStage['PlanPayAmt']; $arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]['PlanPayDate'] = $PayStage['PlanPayDate']; $arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]['stage'] = ''; if (isset($arrayData[$PayStage['BillNo']]['facility']) && is_iterable($arrayData[$PayStage['BillNo']]['facility'])) { foreach ($arrayData[$PayStage['BillNo']]['facility'] as $key => &$value) { $tmpkey = $key . $PayStage['RowNo']; $arrayData[$PayStage['BillNo']]['facility'][$key]['PayStage'][$tmpkey] = $arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]; $arrayData[$PayStage['BillNo']]['facility'][$key]['PayStage'][$tmpkey]['PlanPayAmt'] = $arrayData[$PayStage['BillNo']]['facility'][$key]['PayStage'][$tmpkey]['PlanPayAmt'] * get_ratio($key, $PayStage['BillNo'], $arrayData); $arrayData[$PayStage['BillNo']]['facility'][$key]['PayStage'][$tmpkey]['facilityno'] = $key; if (isset($PayStage_array[$PayStage['BillNo']])) { $PayStage_array[$PayStage['BillNo']] = array_merge($PayStage_array[$PayStage['BillNo']], $arrayData[$PayStage['BillNo']]['facility'][$key]['PayStage']); } else { $PayStage_array[$PayStage['BillNo']] = $arrayData[$PayStage['BillNo']]['facility'][$key]['PayStage']; } $arrayData[$PayStage['BillNo']]['facility'][$key]['PayStage'] = array(); } } } } //作番大日程 $sql_wip = "SELECT tmp2.*, d.name AS depart_name FROM( SELECT a.manager, a2.name as manager_name, a.name, a.department_id, w.salesid, w.contractno, w.facilityno, w.estimated_shipping_date, w.real_contract_arrival_date, w.actual_tofactory_date, w.real_arrival_date, w.install_end_date, w.tryrun_end_date, w.official_check_date, w.delivery_date from wipwholestatus AS w left join account AS a ON w.salesid = a.accountid left join account AS a2 ON a2.accountid = a.manager where w.status = '1' AND w.contract_type='A' )AS tmp2 left join ( SELECT DISTINCT department_id, name FROM department ) AS d ON d.department_id = tmp2.department_id "; // 將作番大日程新梯資料存入array中方便查詢 // 作番號 -> estimated_shipping_date 預計出港日; real_contract_arrival_date 預計出貨日; real_arrival_date 實際出貨日; // install_end_date 安裝完畢日; tryrun_end_date 試車完畢日; official_check_date 官檢日; delivery_date 移交完畢日 $wip_array = array(); $query_wip = mysqli_query($link, $sql_wip); foreach ($query_wip as $wip) { $wip_array[$wip['facilityno']]['estimated_shipping_date'] = $wip['estimated_shipping_date']; $wip_array[$wip['facilityno']]['real_contract_arrival_date'] = $wip['real_contract_arrival_date']; $wip_array[$wip['facilityno']]['real_arrival_date'] = $wip['real_arrival_date']; $wip_array[$wip['facilityno']]['install_end_date'] = $wip['install_end_date']; $wip_array[$wip['facilityno']]['tryrun_end_date'] = $wip['tryrun_end_date']; $wip_array[$wip['facilityno']]['official_check_date'] = $wip['official_check_date']; $wip_array[$wip['facilityno']]['delivery_date'] = $wip['delivery_date']; if (isset($arrayData[$wip['contractno']]) && isset($arrayData[$wip['contractno']]['facility'][$wip['facilityno']])) { if ($wip['delivery_date'] != NULL && $wip['delivery_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['delivery_date'])) { $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['delivery_date'] . "已移交"; $arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) ; "; } elseif ($wip['official_check_date'] != NULL && $wip['official_check_date'] != '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['official_check_date'])) { $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['official_check_date'] . "官檢完畢"; $arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) ; "; } elseif ($wip['tryrun_end_date'] != NULL && $wip['tryrun_end_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['tryrun_end_date'])) { $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['tryrun_end_date'] . "試車完畢"; $arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢) ; "; } elseif ($wip['install_end_date'] != NULL && $wip['install_end_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['install_end_date'])) { $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['install_end_date'] . "安裝完畢"; $arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) ; "; } elseif ($wip['real_arrival_date'] != NULL && $wip['real_arrival_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['real_arrival_date'])) { $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['real_arrival_date'] . "貨抵工地"; $arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) ; "; } elseif ($wip['real_contract_arrival_date'] != NULL && $wip['real_contract_arrival_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['real_contract_arrival_date'])) { $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['real_contract_arrival_date'] . "預計出貨"; $arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['real_contract_arrival_date'] . "預計出貨) ; "; } elseif ($wip['estimated_shipping_date'] != NULL && $wip['estimated_shipping_date'] !== '1970-01-01' && $wip['delivery_date'] !== '1970-01-11' && !empty($wip['estimated_shipping_date'])) { $arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $wip['estimated_shipping_date'] . "預計出港"; $arrayData[$wip['contractno']]['facility_status'] .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計出港) ; "; } } } // 合約收款階段內容分類 $sign60 = array('簽訂後60天', '簽約60日', '簽約後60天', '簽訂後60日內', '訂金支付後60天'); $sign90 = array('簽約後90天', '簽約後90日', '簽訂後90天'); $sign120 = array('簽約後120天', '簽約後120日', '簽訂後120天', '合約簽訂後120天'); $sign0 = array('簽約', '簽訂', '合約簽訂', '訂金'); $arrival = array('貨抵工地', '貨底工地', '工地動工'); $final6 = array('核可函取得後6個月', '得合格函後6個月'); foreach ($PayStage_array as $key => &$value) { foreach ($value as $paykey => &$payvalue) { if (isset($wip_array[$payvalue['facilityno']])) { switch ($payvalue['PayStage']) { case '寶佳出貨前30天': $payvalue['stage'] = '訂金'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $signtime = $estimate_time - (30 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) { $estimate_time = strtotime($wip['real_contract_arrival_date']); $signtime = $estimate_time - (30 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case '寶佳出貨後10天': $payvalue['stage'] = '二次款'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $signtime = $estimate_time + (10 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case '貨抵工地後90天': $payvalue['stage'] = '貨抵工地款'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $signtime = $estimate_time + (90 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case '安裝試車後90天': $payvalue['stage'] = '試車款'; if ($wip_array[$payvalue['facilityno']]['tryrun_end_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['tryrun_end_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['tryrun_end_date'])) { $estimate_time = strtotime($wip['tryrun_end_date']); $signtime = $estimate_time + (90 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case '交車後270天': $payvalue['stage'] = '尾款'; if ($wip_array[$payvalue['facilityno']]['delivery_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['delivery_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['delivery_date'])) { $estimate_time = strtotime($wip['delivery_date']); $signtime = $estimate_time + (270 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case (in_array($payvalue['PayStage'], $arrival)): $payvalue['stage'] = '貨抵工地款'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $signtime = $estimate_time + (10 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case '二次款': $payvalue['stage'] = '二次款'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time); } elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) { $estimate_time = strtotime($wip['real_contract_arrival_date']); $payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time); } else { $payvalue['PlanPayDate'] = NULL; } break; case (stristr($payvalue['PayStage'], '出貨前30') || stristr($payvalue['PayStage'], '簽約(出貨前30天)') || stristr($payvalue['PayStage'], '建照核發時')): $payvalue['stage'] = '二次款'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $signtime = $estimate_time - (30 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) { $estimate_time = strtotime($wip['real_contract_arrival_date']); $signtime = $estimate_time - (30 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case (stristr($payvalue['PayStage'], '出貨前60')): $payvalue['stage'] = '二次款'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $signtime = $estimate_time - (60 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) { $estimate_time = strtotime($wip['real_contract_arrival_date']); $signtime = $estimate_time - (60 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case (stristr($payvalue['PayStage'], '出貨前90')): $payvalue['stage'] = '二次款'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $signtime = $estimate_time - (90 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) { $estimate_time = strtotime($wip['real_contract_arrival_date']); $signtime = $estimate_time - (90 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case (stristr($payvalue['PayStage'], '出貨前120')): $payvalue['stage'] = '二次款'; if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) { $estimate_time = strtotime($wip['real_arrival_date']); $signtime = $estimate_time - (120 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) { $estimate_time = strtotime($wip['real_contract_arrival_date']); $signtime = $estimate_time - (120 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); } else { $payvalue['PlanPayDate'] = NULL; } break; case "簽定30天內": $payvalue['stage'] = '二次款'; $estimate_time = strtotime($arrayData[$key]['PayStage'][1]['PlanPayDate']); $signtime = $estimate_time + (30 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); break; case (in_array($payvalue['PayStage'], $sign60)): $payvalue['stage'] = '二次款'; $estimate_time = strtotime($arrayData[$key]['PayStage'][1]['PlanPayDate']); $signtime = $estimate_time + (60 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); break; case (in_array($payvalue['PayStage'], $sign90)): $payvalue['stage'] = '二次款'; $estimate_time = strtotime($arrayData[$key]['PayStage'][1]['PlanPayDate']); $signtime = $estimate_time + (90 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); break; case (in_array($payvalue['PayStage'], $sign120)): $payvalue['stage'] = '二次款'; $estimate_time = strtotime($arrayData[$key]['PayStage'][1]['PlanPayDate']); $signtime = $estimate_time + (120 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); break; case (stristr($payvalue['PayStage'], '簽訂後30')): $payvalue['stage'] = '二次款'; $estimate_time = strtotime($arrayData[$key]['PayStage'][1]['PlanPayDate']); $signtime = $estimate_time + (30 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $signtime); break; case (in_array($payvalue['PayStage'], $sign0)): $payvalue['stage'] = '訂金'; $estimate_time = strtotime($arrayData[$key]['PayStage'][1]['PlanPayDate']); $payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time); break; case (stristr($payvalue['PayStage'], '試車')): $payvalue['stage'] = '試車款'; if ($wip_array[$payvalue['facilityno']]['tryrun_end_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['tryrun_end_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['tryrun_end_date'])) { $estimate_time = strtotime($wip['tryrun_end_date']); $payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time); } else { $payvalue['PlanPayDate'] = NULL; } break; case (stristr($payvalue['PayStage'], '安裝') || stristr($payvalue['PayStage'], '貨抵工地且完工')): $payvalue['stage'] = '安裝款'; if ($wip_array[$payvalue['facilityno']]['install_end_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['install_end_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['install_end_date'])) { $estimate_time = strtotime($wip['install_end_date']); $payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time); } else { $payvalue['PlanPayDate'] = NULL; } break; case (in_array($payvalue['PayStage'], $final6)): $payvalue['stage'] = '尾款'; if ($wip_array[$payvalue['facilityno']]['delivery_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['delivery_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['delivery_date'])) { $estimate_time = strtotime($wip['delivery_date']); $estimate_time = $estimate_time + (180 * 86400); $payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time); } else { $payvalue['PlanPayDate'] = NULL; } break; case (stristr($payvalue['PayStage'], '合格') || stristr($payvalue['PayStage'], '驗收') || stristr($payvalue['PayStage'], '驗收')): $payvalue['stage'] = '官檢驗收款'; if ($wip_array[$payvalue['facilityno']]['official_check_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['official_check_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['official_check_date'])) { $estimate_time = strtotime($wip['official_check_date']); $payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time); } else { $payvalue['PlanPayDate'] = NULL; } break; case (stristr($payvalue['PayStage'], '交車') || stristr($payvalue['PayStage'], '移交') || stristr($payvalue['PayStage'], '完工') || stristr($payvalue['PayStage'], '許可') || stristr($payvalue['PayStage'], '核可')): $payvalue['stage'] = '交車款'; if ($wip_array[$payvalue['facilityno']]['delivery_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['delivery_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['delivery_date'])) { $estimate_time = strtotime($wip['delivery_date']); $payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time); } else { $payvalue['PlanPayDate'] = NULL; } break; default: $payvalue['PlanPayDate'] = NULL; break; } if (strtotime($payvalue['PlanPayDate']) < 975686400) { $payvalue['PlanPayDate'] = NULL; } } else { $payvalue['PlanPayDate'] = NULL; $payvalue['stage'] = "大日程無作番"; } } } // 在$PayStage_array中排序 foreach ($PayStage_array as $key => $value) { uasort($PayStage_array[$key], 'comparePlanPayDate'); } // 加入序號 foreach ($PayStage_array as &$payStage) { $sequenceNumber = 1; foreach ($payStage as $tk => &$pstage) { $pstage['sequenceNumber'] = $sequenceNumber; $sequenceNumber += 1; } } // 整理好的收款階段放入 $final_paystage $final_paystage = array(); foreach ($PayStage_array as $key => &$payStage) { if (is_iterable($payStage)) { foreach ($payStage as $key2 => $pstage) { $final_paystage[$key][$pstage['sequenceNumber']] = $pstage; } } } // 發票資訊 $sql_invoice = "SELECT Detail.BillNo AS InvoiceBillNo, Detail.MaterialId, Detail.LAmountWithTax, Main.InvoiceNo, Main.InvoiceDate, Main.InvoiceState, CheckAll.FromSalSalesOrder AS BillNo FROM arSellInvoiceMaterial AS Detail LEFT JOIN arSellInvoice AS Main ON Detail.BillNo=Main.BillNo LEFT JOIN ( SELECT CheckDetail.BillNo, CheckDetail.FromSalSalesOrder, CheckDetail.RowNo FROM arCheckBillDetail AS CheckDetail ) AS CheckAll ON CheckAll.BillNo= Detail.FromBillNo AND Detail.FromRowCode = CheckAll.RowNo WHERE Main.InvoiceState!=2 AND LEN(CheckAll.FromSalSalesOrder)>0"; $query_invoice = $conn->query($sql_invoice); //發票資訊回填到arrayData foreach ($query_invoice as $invoice) { if (isset($arrayData[$invoice['BillNo']])) { $arrayData[$invoice['BillNo']]['invoice_budget'] += $invoice['LAmountWithTax']; } } // 核銷資訊 $sql_received = "SELECT CheckDetail.OrderBillNo, arWriteOffBillDetail.FromBillNo AS CheckBillNo, arWriteOffBillDetail.FromRowCode AS CheckRowCode, arWriteOffBillDetail.CurrStandOffOAmount, CheckDetail.TypeId FROM arWriteOffBillDetail LEFT JOIN (SELECT arCheckBillDetail.BillNo, arCheckBillDetail.RowCode, arCheckBillDetail.FromSalSalesOrder AS OrderBillNo, salSalesOrder.TypeId, salSalesOrder.ModeId FROM arCheckBillDetail LEFT JOIN salSalesOrder ON salSalesOrder.BillNo =arCheckBillDetail.FromSalSalesOrder ) AS CheckDetail ON CheckDetail.BillNo=arWriteOffBillDetail.FromBillNo AND arWriteOffBillDetail.FromRowCode = CheckDetail.RowCode WHERE CheckDetail.ModeId = 'M'"; $query_received = $conn->query($sql_received); // 核銷資訊回填到arrayData foreach ($query_received as $received) { if (isset($arrayData[$received['OrderBillNo']])) { $arrayData[$received['OrderBillNo']]['received_budget'] += $received['CurrStandOffOAmount']; } } // 將發票與核銷資訊 分別計算作番收款階段金額 與 催收次數 $today = strtotime(date('Y-m-t')); foreach ($final_paystage as $key => &$value) { $tmpinvoice = $arrayData[$key]['invoice_budget']; $tmpreceived = $arrayData[$key]['received_budget']; for ($sequenceNumber = 1; $sequenceNumber <= count($value); $sequenceNumber++) { if (isset($value[$sequenceNumber]['PlanPayDate'])) { $collect_month = collect_month(strtotime($value[$sequenceNumber]['PlanPayDate'])); if ($today > strtotime($value[$sequenceNumber]['PlanPayDate'])) { $value[$sequenceNumber]['hadtopay'] = 'V'; $arrayData[$key]['receivable_budget'] += $value[$sequenceNumber]['PlanPayAmt']; } else { $value[$sequenceNumber]['hadtopay'] = '--'; } } else { $collect_month = 0; $value[$sequenceNumber]['hadtopay'] = '--'; } if ($tmpinvoice > $value[$sequenceNumber]['PlanPayAmt']) { $value[$sequenceNumber]['invoice_budget'] = $value[$sequenceNumber]['PlanPayAmt']; $tmpinvoice = $tmpinvoice - $value[$sequenceNumber]['invoice_budget']; } elseif ($tmpinvoice > 0) { $value[$sequenceNumber]['invoice_budget'] = $tmpinvoice; $tmpinvoice = 0; } else { $value[$sequenceNumber]['invoice_budget'] = 0; } if ($tmpreceived > $value[$sequenceNumber]['PlanPayAmt']) { $value[$sequenceNumber]['received_budget'] = $value[$sequenceNumber]['PlanPayAmt']; $tmpreceived -= $value[$sequenceNumber]['received_budget']; } elseif ($tmpreceived > 0) { $value[$sequenceNumber]['received_budget'] = $tmpreceived; $tmpreceived = 0; } else { $value[$sequenceNumber]['received_budget'] = 0; } if ($collect_month > 0 && $value[$sequenceNumber]['PlanPayAmt'] > $value[$sequenceNumber]['received_budget']) { $value[$sequenceNumber]['collect_month'] = $collect_month; } else { $value[$sequenceNumber]['collect_month'] = 0; } } } //合約資料填回arrayData foreach ($final_paystage as $key => $value) { for ($sequence = 1; $sequence <= count($value); $sequence++) { if (isset($arrayData[$key]) && isset($arrayData[$key]['facility']) && isset($arrayData[$key]['facility'][$value[$sequence]['facilityno']]) && isset($arrayData[$key]['facility'][$value[$sequence]['facilityno']]['PayStage'])) { array_push($arrayData[$key]['facility'][$value[$sequence]['facilityno']]['PayStage'], $value[$sequence]); foreach ($arrayData[$key]['PayStage'] as $arkey => &$arvalue) { if ($arvalue['PayStage'] == $value[$sequence]['PayStage']) { if (isset($arvalue['receivable_budget']) && isset($arvalue['received_budget']) && isset($arvalue['invoice_budget'])) { $arvalue['receivable_budget'] += $value[$sequence]['PlanPayAmt']; $arvalue['received_budget'] += $value[$sequence]['received_budget']; $arvalue['invoice_budget'] += $value[$sequence]['invoice_budget']; if ($arvalue['collect_month'] < $value[$sequence]['collect_month']) { $arvalue['collect_month'] = $value[$sequence]['collect_month']; } $sum_receivable_budget += $value[$sequence]['PlanPayAmt']; $sum_received_budget += $value[$sequence]['received_budget']; $sum_invoice_budget += $value[$sequence]['invoice_budget']; } else { $arvalue['stage'] = $value[$sequence]['stage']; $arvalue['receivable_budget'] = $value[$sequence]['PlanPayAmt']; $arvalue['received_budget'] = $value[$sequence]['received_budget']; $arvalue['invoice_budget'] = $value[$sequence]['invoice_budget']; $arvalue['collect_month'] = $value[$sequence]['collect_month']; $sum_receivable_budget += $value[$sequence]['PlanPayAmt']; $sum_received_budget += $value[$sequence]['received_budget']; $sum_invoice_budget += $value[$sequence]['invoice_budget']; } if ($value[$sequence]['collect_month'] > $arrayData[$key]['collect_month']) { $arrayData[$key]['collect_month'] = $value[$sequence]['collect_month']; } } } } } } $average_A40001 = $sum_A40001 / $sum_facility; $average_A40008 = $sum_A40008 / $sum_facility; $average_facility_budget = $sum_total_budget / $sum_facility; $average_contract_budget = $sum_total_budget / $sum_contract; $average_contract_facility = $sum_facility / $sum_contract; // excel 結果 // 0 合約號; 1 單據日期; 2 客戶編號; 3 客戶名稱; 4 客戶地址; 5 部門ID; 6 部門名稱; 7 營業員工號; 8 營業員名稱; 9 部門主管工號; 10 部門主管名稱; // 11 合約總金額; 12 A40001總金額; 13 A40008總金額; 14 目前應收金額; 15 已開發票金額; 16 已收金額; 17 催收金額; 18 催收次數; 19 作番總數; 20 作番狀態 // 21 訂金名稱; 22 訂金金額; 23 應收金額; 24 已開發票金額; 25 已收金額; 26 催收金額; 27 催收次數; // 28 二次款名稱; 29 二次款金額; 30 應收金額; 31 已開發票金額; 32 已收金額; 33 催收金額; 34 催收次數; $excel_contract_array = array(); $excel_contract_boga_array= array(); $excel_contract_noboga_array= array(); // 0 作番號; 1 合約號; 2 合約單據日期; 3 客戶編號; 4 客戶名稱; 5 客戶地址; 6 部門ID; 7 部門名稱; 8 營業員工號; 9 營業員名稱; 10 部門主管工號; 11 部門主管名稱; // 12 作番總金額; 13 A40001 金額; 14 A40008 金額; 15 目前應收金額; 16 已開發票金額; 17 已收金額; 18 催收金額; 19 催收次數; 20 作番狀態 $excel_facility_array = array(); foreach ($arrayData as $key => $value) { // echo $key . "
********************
"; $excel_contract_array[$key]=array_fill(0, 76, ''); $excel_contract_array[$key][0] = (isset($value['BillNo']) && !is_null($value['BillNo'])) ? $value['BillNo'] : ''; $excel_contract_array[$key][1] = (isset($value['BillDate']) && !is_null($value['BillDate'])) ? $value['BillDate'] : ''; $excel_contract_array[$key][2] = (isset($value['CustomerId']) && !is_null($value['CustomerId'])) ? $value['CustomerId'] : ''; $excel_contract_array[$key][3] = (isset($value['CustomerName']) && !is_null($value['CustomerName'])) ? $value['CustomerName'] : ''; $excel_contract_array[$key][4] = (isset($value['CustomerAddress']) && !is_null($value['CustomerAddress'])) ? $value['CustomerAddress'] : ''; $excel_contract_array[$key][5] = (isset($value['DeptId']) && !is_null($value['DeptId'])) ? $value['DeptId'] : ''; $excel_contract_array[$key][6] = (isset($value['DeptName']) && !is_null($value['DeptName'])) ? $value['DeptName'] : ''; $excel_contract_array[$key][7] = (isset($value['PersonId']) && !is_null($value['PersonId'])) ? $value['PersonId'] : ''; $excel_contract_array[$key][8] = (isset($value['PersonName']) && !is_null($value['PersonName'])) ? $value['PersonName'] : ''; $excel_contract_array[$key][9] = (isset($value['ManagerId']) && !is_null($value['ManagerId'])) ? $value['ManagerId'] : ''; $excel_contract_array[$key][10] = (isset($value['ManagerName']) && !is_null($value['ManagerName'])) ? $value['ManagerName'] : ''; $excel_contract_array[$key][11] = (isset($value['OAmountWithTax']) && !is_null($value['OAmountWithTax'])) ? $value['OAmountWithTax'] : 0; $excel_contract_array[$key][12] = (isset($value['A40001']) && !is_null($value['A40001'])) ? $value['A40001'] : 0; $excel_contract_array[$key][13] = (isset($value['A40008']) && !is_null($value['A40008'])) ? $value['A40008'] : 0; $excel_contract_array[$key][14] = (isset($value['receivable_budget']) && !is_null($value['receivable_budget'])) ? $value['receivable_budget'] : 0; $excel_contract_array[$key][15] = (isset($value['invoice_budget']) && !is_null($value['invoice_budget'])) ? $value['invoice_budget'] : 0; $excel_contract_array[$key][16] = (isset($value['received_budget']) && !is_null($value['received_budget'])) ? $value['received_budget'] : 0; $excel_contract_array[$key][17] = $excel_contract_array[$key][14] - $excel_contract_array[$key][16]; $excel_contract_array[$key][18] = (isset($value['collect_month']) && !is_null($value['collect_month'])) ? $value['collect_month'] : 0; $excel_contract_array[$key][19] = (isset($value['facility_num']) && !is_null($value['facility_num'])) ? $value['facility_num'] : 0; $excel_contract_array[$key][20] = (isset($value['facility_status']) && !is_null($value['facility_status'])) ? $value['facility_status'] : 0; if (isset($value['PayStage']) && is_iterable($value['PayStage'])) { $isBoga = 0; if(stristr($value['PayStage'][1]['PayStage'],'寶佳')){ $isBoga=1; $excel_contract_boga_array[$key]=array_fill(0, 76, ''); $excel_contract_boga_array[$key][0] = (isset($value['BillNo']) && !is_null($value['BillNo'])) ? $value['BillNo'] : ''; $excel_contract_boga_array[$key][1] = (isset($value['BillDate']) && !is_null($value['BillDate'])) ? $value['BillDate'] : ''; $excel_contract_boga_array[$key][2] = (isset($value['CustomerId']) && !is_null($value['CustomerId'])) ? $value['CustomerId'] : ''; $excel_contract_boga_array[$key][3] = (isset($value['CustomerName']) && !is_null($value['CustomerName'])) ? $value['CustomerName'] : ''; $excel_contract_boga_array[$key][4] = (isset($value['CustomerAddress']) && !is_null($value['CustomerAddress'])) ? $value['CustomerAddress'] : ''; $excel_contract_boga_array[$key][5] = (isset($value['DeptId']) && !is_null($value['DeptId'])) ? $value['DeptId'] : ''; $excel_contract_boga_array[$key][6] = (isset($value['DeptName']) && !is_null($value['DeptName'])) ? $value['DeptName'] : ''; $excel_contract_boga_array[$key][7] = (isset($value['PersonId']) && !is_null($value['PersonId'])) ? $value['PersonId'] : ''; $excel_contract_boga_array[$key][8] = (isset($value['PersonName']) && !is_null($value['PersonName'])) ? $value['PersonName'] : ''; $excel_contract_boga_array[$key][9] = (isset($value['ManagerId']) && !is_null($value['ManagerId'])) ? $value['ManagerId'] : ''; $excel_contract_boga_array[$key][10] = (isset($value['ManagerName']) && !is_null($value['ManagerName'])) ? $value['ManagerName'] : ''; $excel_contract_boga_array[$key][11] = (isset($value['OAmountWithTax']) && !is_null($value['OAmountWithTax'])) ? $value['OAmountWithTax'] : 0; $excel_contract_boga_array[$key][12] = (isset($value['A40001']) && !is_null($value['A40001'])) ? $value['A40001'] : 0; $excel_contract_boga_array[$key][13] = (isset($value['A40008']) && !is_null($value['A40008'])) ? $value['A40008'] : 0; $excel_contract_boga_array[$key][14] = (isset($value['receivable_budget']) && !is_null($value['receivable_budget'])) ? $value['receivable_budget'] : 0; $excel_contract_boga_array[$key][15] = (isset($value['invoice_budget']) && !is_null($value['invoice_budget'])) ? $value['invoice_budget'] : 0; $excel_contract_boga_array[$key][16] = (isset($value['received_budget']) && !is_null($value['received_budget'])) ? $value['received_budget'] : 0; $excel_contract_boga_array[$key][17] = $excel_contract_array[$key][14] - $excel_contract_array[$key][16]; $excel_contract_boga_array[$key][18] = (isset($value['collect_month']) && !is_null($value['collect_month'])) ? $value['collect_month'] : 0; $excel_contract_boga_array[$key][19] = (isset($value['facility_num']) && !is_null($value['facility_num'])) ? $value['facility_num'] : 0; $excel_contract_boga_array[$key][20] = (isset($value['facility_status']) && !is_null($value['facility_status'])) ? $value['facility_status'] : 0; }else{ $excel_contract_noboga_array[$key]=array_fill(0, 76, ''); $excel_contract_noboga_array[$key][0] = (isset($value['BillNo']) && !is_null($value['BillNo'])) ? $value['BillNo'] : ''; $excel_contract_noboga_array[$key][1] = (isset($value['BillDate']) && !is_null($value['BillDate'])) ? $value['BillDate'] : ''; $excel_contract_noboga_array[$key][2] = (isset($value['CustomerId']) && !is_null($value['CustomerId'])) ? $value['CustomerId'] : ''; $excel_contract_noboga_array[$key][3] = (isset($value['CustomerName']) && !is_null($value['CustomerName'])) ? $value['CustomerName'] : ''; $excel_contract_noboga_array[$key][4] = (isset($value['CustomerAddress']) && !is_null($value['CustomerAddress'])) ? $value['CustomerAddress'] : ''; $excel_contract_noboga_array[$key][5] = (isset($value['DeptId']) && !is_null($value['DeptId'])) ? $value['DeptId'] : ''; $excel_contract_noboga_array[$key][6] = (isset($value['DeptName']) && !is_null($value['DeptName'])) ? $value['DeptName'] : ''; $excel_contract_noboga_array[$key][7] = (isset($value['PersonId']) && !is_null($value['PersonId'])) ? $value['PersonId'] : ''; $excel_contract_noboga_array[$key][8] = (isset($value['PersonName']) && !is_null($value['PersonName'])) ? $value['PersonName'] : ''; $excel_contract_noboga_array[$key][9] = (isset($value['ManagerId']) && !is_null($value['ManagerId'])) ? $value['ManagerId'] : ''; $excel_contract_noboga_array[$key][10] = (isset($value['ManagerName']) && !is_null($value['ManagerName'])) ? $value['ManagerName'] : ''; $excel_contract_noboga_array[$key][11] = (isset($value['OAmountWithTax']) && !is_null($value['OAmountWithTax'])) ? $value['OAmountWithTax'] : 0; $excel_contract_noboga_array[$key][12] = (isset($value['A40001']) && !is_null($value['A40001'])) ? $value['A40001'] : 0; $excel_contract_noboga_array[$key][13] = (isset($value['A40008']) && !is_null($value['A40008'])) ? $value['A40008'] : 0; $excel_contract_noboga_array[$key][14] = (isset($value['receivable_budget']) && !is_null($value['receivable_budget'])) ? $value['receivable_budget'] : 0; $excel_contract_noboga_array[$key][15] = (isset($value['invoice_budget']) && !is_null($value['invoice_budget'])) ? $value['invoice_budget'] : 0; $excel_contract_noboga_array[$key][16] = (isset($value['received_budget']) && !is_null($value['received_budget'])) ? $value['received_budget'] : 0; $excel_contract_noboga_array[$key][17] = $excel_contract_array[$key][14] - $excel_contract_array[$key][16]; $excel_contract_noboga_array[$key][18] = (isset($value['collect_month']) && !is_null($value['collect_month'])) ? $value['collect_month'] : 0; $excel_contract_noboga_array[$key][19] = (isset($value['facility_num']) && !is_null($value['facility_num'])) ? $value['facility_num'] : 0; $excel_contract_noboga_array[$key][20] = (isset($value['facility_status']) && !is_null($value['facility_status'])) ? $value['facility_status'] : 0; } foreach ($value['PayStage'] as $paykey => $payvalue) { switch ($payvalue['stage']) { case "訂金": $excel_contract_array[$key][21] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_array[$key][22] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_array[$key][23] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_array[$key][24] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_array[$key][25] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_array[$key][26] = $excel_contract_array[$key][23] - $excel_contract_array[$key][25]; $excel_contract_array[$key][27] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; if($isBoga == 1){ $excel_contract_boga_array[$key][21] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_boga_array[$key][22] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_boga_array[$key][23] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_boga_array[$key][24] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_boga_array[$key][25] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_boga_array[$key][26] = $excel_contract_array[$key][23] - $excel_contract_array[$key][25]; $excel_contract_boga_array[$key][27] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; }else{ $excel_contract_noboga_array[$key][21] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_noboga_array[$key][22] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_noboga_array[$key][23] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_noboga_array[$key][24] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_noboga_array[$key][25] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_noboga_array[$key][26] = $excel_contract_array[$key][23] - $excel_contract_array[$key][25]; $excel_contract_noboga_array[$key][27] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; } break; case "二次款": $excel_contract_array[$key][28] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_array[$key][29] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_array[$key][30] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_array[$key][31] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_array[$key][32] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_array[$key][33] = $excel_contract_array[$key][30] - $excel_contract_array[$key][32]; $excel_contract_array[$key][34] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; if($isBoga ==1){ $excel_contract_boga_array[$key][28] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_boga_array[$key][29] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_boga_array[$key][30] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_boga_array[$key][31] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_boga_array[$key][32] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_boga_array[$key][33] = $excel_contract_array[$key][30] - $excel_contract_array[$key][32]; $excel_contract_boga_array[$key][34] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; }else{ $excel_contract_noboga_array[$key][28] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_noboga_array[$key][29] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_noboga_array[$key][30] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_noboga_array[$key][31] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_noboga_array[$key][32] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_noboga_array[$key][33] = $excel_contract_array[$key][30] - $excel_contract_array[$key][32]; $excel_contract_noboga_array[$key][34] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; } break; case "貨抵工地款": $excel_contract_array[$key][35] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_array[$key][36] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_array[$key][37] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_array[$key][38] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_array[$key][39] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_array[$key][40] = $excel_contract_array[$key][37] - $excel_contract_array[$key][39]; $excel_contract_array[$key][41] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; if($isBoga == 1){ $excel_contract_boga_array[$key][35] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_boga_array[$key][36] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_boga_array[$key][37] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_boga_array[$key][38] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_boga_array[$key][39] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_boga_array[$key][40] = $excel_contract_array[$key][37] - $excel_contract_array[$key][39]; $excel_contract_boga_array[$key][41] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; }else{ $excel_contract_noboga_array[$key][35] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_noboga_array[$key][36] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_noboga_array[$key][37] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_noboga_array[$key][38] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_noboga_array[$key][39] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_noboga_array[$key][40] = $excel_contract_array[$key][37] - $excel_contract_array[$key][39]; $excel_contract_noboga_array[$key][41] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; } break; case "安裝款": $excel_contract_array[$key][42] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_array[$key][43] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_array[$key][44] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_array[$key][45] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_array[$key][46] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_array[$key][47] = $excel_contract_array[$key][44] - $excel_contract_array[$key][46]; $excel_contract_array[$key][48] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; $excel_contract_noboga_array[$key][42] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_noboga_array[$key][43] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_noboga_array[$key][44] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_noboga_array[$key][45] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_noboga_array[$key][46] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_noboga_array[$key][47] = $excel_contract_array[$key][44] - $excel_contract_array[$key][46]; $excel_contract_noboga_array[$key][48] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; break; case "試車款": $excel_contract_array[$key][49] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_array[$key][50] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_array[$key][51] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_array[$key][52] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_array[$key][53] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_array[$key][54] = $excel_contract_array[$key][51] - $excel_contract_array[$key][53]; $excel_contract_array[$key][55] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; if($isBoga ==1){ $excel_contract_boga_array[$key][49] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_boga_array[$key][50] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_boga_array[$key][51] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_boga_array[$key][52] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_boga_array[$key][53] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_boga_array[$key][54] = $excel_contract_array[$key][51] - $excel_contract_array[$key][53]; $excel_contract_boga_array[$key][55] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; }else{ $excel_contract_noboga_array[$key][49] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_noboga_array[$key][50] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_noboga_array[$key][51] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_noboga_array[$key][52] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_noboga_array[$key][53] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_noboga_array[$key][54] = $excel_contract_array[$key][51] - $excel_contract_array[$key][53]; $excel_contract_noboga_array[$key][55] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; } break; case "官檢驗收款": $excel_contract_array[$key][56] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_array[$key][57] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_array[$key][58] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_array[$key][59] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_array[$key][60] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_array[$key][61] = $excel_contract_array[$key][58] - $excel_contract_array[$key][60]; $excel_contract_array[$key][62] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; $excel_contract_noboga_array[$key][56] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_noboga_array[$key][57] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_noboga_array[$key][58] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_noboga_array[$key][59] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_noboga_array[$key][60] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_noboga_array[$key][61] = $excel_contract_array[$key][58] - $excel_contract_array[$key][60]; $excel_contract_noboga_array[$key][62] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; break; case "交車款": $excel_contract_array[$key][63] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_array[$key][64] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_array[$key][65] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_array[$key][66] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_array[$key][67] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_array[$key][68] = $excel_contract_array[$key][65] - $excel_contract_array[$key][67]; $excel_contract_array[$key][69] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; $excel_contract_noboga_array[$key][63] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_noboga_array[$key][64] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_noboga_array[$key][65] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_noboga_array[$key][66] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_noboga_array[$key][67] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_noboga_array[$key][68] = $excel_contract_array[$key][65] - $excel_contract_array[$key][67]; $excel_contract_noboga_array[$key][69] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; break; case "尾款": $excel_contract_array[$key][70] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_array[$key][71] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_array[$key][72] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_array[$key][73] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_array[$key][74] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_array[$key][75] = $excel_contract_array[$key][72] - $excel_contract_array[$key][74]; $excel_contract_array[$key][76] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; if($isBoga ==1){ $excel_contract_boga_array[$key][70] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_boga_array[$key][71] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_boga_array[$key][72] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_boga_array[$key][73] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_boga_array[$key][74] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_boga_array[$key][75] = $excel_contract_array[$key][72] - $excel_contract_array[$key][74]; $excel_contract_boga_array[$key][76] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; }else{ $excel_contract_noboga_array[$key][70] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--'; $excel_contract_noboga_array[$key][71] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? $payvalue['PlanPayAmt'] : 0; $excel_contract_noboga_array[$key][72] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0; $excel_contract_noboga_array[$key][73] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? $payvalue['invoice_budget'] : 0; $excel_contract_noboga_array[$key][74] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0; $excel_contract_noboga_array[$key][75] = $excel_contract_array[$key][72] - $excel_contract_array[$key][74]; $excel_contract_noboga_array[$key][76] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? $payvalue['collect_month'] : 0; } break; } } } } $total_data = json_encode($excel_contract_array); $boga_data = json_encode($excel_contract_boga_array); $noboga_data = json_encode($excel_contract_noboga_array); ?>