|
|
@ -4,56 +4,73 @@ include "header.php"; |
|
|
|
$follower = find_follow($user_id); |
|
|
|
$arrayData = []; |
|
|
|
$receivable_array = []; |
|
|
|
$sql_received = "SELECT * FROM arWriteOffBillDetail WHERE (DATALENGTH(OrderBillNo) >0)"; |
|
|
|
// T8發票 (有專案的發票) |
|
|
|
$sql_invoice = "SELECT DISTINCT |
|
|
|
a.InvoiceNo, a.InvoiceTime,a.OAmountWithTax,a.InvoiceState, |
|
|
|
b.ProjectId |
|
|
|
FROM arSellInvoice as a |
|
|
|
LEFT JOIN arSellInvoiceMaterial as b |
|
|
|
ON a.BillNo=b.BillNo |
|
|
|
WHERE DATALENGTH(b.ProjectId)>0"; |
|
|
|
|
|
|
|
// T8核銷 |
|
|
|
$sql_received = "SELECT |
|
|
|
a.BillNo, a.WriteOffBizPartnerId,a.PayWriteOffOAmount, |
|
|
|
b.FromBillDate AS ReceivedDate,b.CurrWOFeeOAmt AS Fee, |
|
|
|
c.OrderBillNo, c.checkBillNo, c.InvoiceNo, c.BillDate AS CheckBillDate |
|
|
|
FROM arWriteOffBill AS a |
|
|
|
LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo |
|
|
|
LEFT JOIN |
|
|
|
(SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail |
|
|
|
LEFT JOIN |
|
|
|
(SELECT |
|
|
|
arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo |
|
|
|
FROM arCheckBill |
|
|
|
LEFT JOIN arCheckBillInvInfo |
|
|
|
ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1 |
|
|
|
ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c |
|
|
|
ON a.BillNo=c.BillNo |
|
|
|
WHERE DATALENGTH(c.OrderBillNo) >0"; |
|
|
|
|
|
|
|
$sql_contract = "SELECT a.BillNo, a.PayStage, a.PlanPayAmt, a.PlanPayDate,s.BizPartnerId,c.BizPartnerName, s.PersonId, |
|
|
|
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.ModeId = 'M' AND (s.CurrentState=2 OR s.CurrentState=4) "; |
|
|
|
|
|
|
|
// 期初收款資訊 |
|
|
|
$sql_opening = " |
|
|
|
SELECT * FROM account_received "; |
|
|
|
|
|
|
|
// 設定權限:看到自己的/下屬的,資訊處跟財會處可以看全部的 |
|
|
|
if (!(in_array(accountidToDepartId($user_id), array('220', '210')))) { |
|
|
|
$sql_contract .= "AND (s.PersonId = '$user_id'"; |
|
|
|
$sql_received .= " AND (PersonId = '$user_id'"; |
|
|
|
$sql_opening .= " OR person_id = '$user_id'"; |
|
|
|
if (count($follower) > 0) { |
|
|
|
$column_str = "('$user_id'" . ",'"; |
|
|
|
$column_str .= implode("','", $follower); |
|
|
|
$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)"; |
|
|
|
} else { |
|
|
|
$sql_contract .= ")"; |
|
|
|
$sql_received .= ")"; |
|
|
|
$sql_opening .= ")"; |
|
|
|
}; |
|
|
|
} |
|
|
|
$sign60 = array('簽訂後60天', '簽約60日', '簽約後60天', '簽訂後60日內', '訂金支付後60天'); |
|
|
|
$sign90 = array('簽約後90天', '簽約後90日', '簽訂後90天'); |
|
|
|
$sign120 = array('簽約後120天', '簽約後120日', '簽訂後120天'); |
|
|
|
|
|
|
|
$contract = $conn->query($sql_contract); |
|
|
|
$received_array = $conn->query($sql_received); |
|
|
|
$opening_data = mysqli_query($link, $sql_opening); |
|
|
|
$invoice_data = $conn->query($sql_invoice); |
|
|
|
|
|
|
|
|
|
|
|
// 取收款資料 account_received |
|
|
|
// $received_data = mysqli_query($link, $sql_received); |
|
|
|
// foreach ($received_data as $received) { |
|
|
|
// if ($received['BillNo'] == 'SO20230801001') { |
|
|
|
// $BillNo = 'M230947'; |
|
|
|
// } elseif ($received['BillNo'] == 'SO20230801002') { |
|
|
|
// $BillNo = 'M231067'; |
|
|
|
// } else { |
|
|
|
// $BillNo = $received['BillNo']; |
|
|
|
// }; |
|
|
|
// if (isset($received_array[$BillNo])) { |
|
|
|
// $received_array[$BillNo][0] += $received['invoice_amount']; |
|
|
|
// $received_array[$BillNo][1] += $received['received_amount']; |
|
|
|
// $received['status'] = (intval($received['status']) < 4) ? intval($received['status']) : 0; |
|
|
|
// if ($received_array[$BillNo][2] < intval($received['status'])) { |
|
|
|
// $received_array[$BillNo][2] = intval($received['status']); |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// $received_array[$BillNo][0] = $received['invoice_amount']; |
|
|
|
// $received_array[$BillNo][1] = $received['received_amount']; |
|
|
|
// $received_array[$BillNo][2] = (intval($received['status']) < 4) ? intval($received['status']) : 0; |
|
|
|
// } |
|
|
|
// } |
|
|
|
// 合約收款階段內容分類 |
|
|
|
$sign60 = array('簽訂後60天', '簽約60日', '簽約後60天', '簽訂後60日內', '訂金支付後60天'); |
|
|
|
$sign90 = array('簽約後90天', '簽約後90日', '簽訂後90天'); |
|
|
|
$sign120 = array('簽約後120天', '簽約後120日', '簽訂後120天'); |
|
|
|
|
|
|
|
// 將T8合約收款階段資料依據款別分類放進arraData裡 |
|
|
|
foreach ($contract as $cont) { |
|
|
@ -71,7 +88,7 @@ foreach ($contract as $cont) { |
|
|
|
$EnterpriseName = $cont['EnterpriseName']; |
|
|
|
$TaxNo = $cont['TaxNo']; |
|
|
|
$ContactAddress = $cont['ContactAddress']; |
|
|
|
//['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 ['second'] 0 二次款名 1 二次款金額 2 收款日期 ['arrive'] 0 貨抵工地款名稱 1 貨抵工地款金額 2 貨抵工地收款日期 ['install'] 0 安裝款名 1 安裝金額 2 安裝收款日期 |
|
|
|
//['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 3 應收金額 min 最早應收月份 max 最晚應收月份 ['second'] 0 二次款名 1 二次款金額 2 收款日期 ['arrive'] 0 貨抵工地款名稱 1 貨抵工地款金額 2 貨抵工地收款日期 ['install'] 0 安裝款名 1 安裝金額 2 安裝收款日期 |
|
|
|
//['tryrun'] 0 試車款名 1試車金額 2 試車收款日期 ['check'] 0 官檢款名 1 官檢金額 2 官檢收款日期 ['delivery'] 0 交車款名 1 交車金額 2 交車收款日期 ['final'] 0 尾款名 1 尾款金額 2 尾款收款日期 |
|
|
|
if (!(isset($arrayData[$BillNo]))) { |
|
|
|
// 0 部門id 1 部門名稱 2 經理名稱 3 營業員id 4 營業員名稱 5 客戶名稱 6 抬頭 7 統編 8 通訊地址 |
|
|
@ -80,8 +97,13 @@ foreach ($contract as $cont) { |
|
|
|
$arrayData[$BillNo][6] = $EnterpriseName; |
|
|
|
$arrayData[$BillNo][7] = $TaxNo; |
|
|
|
$arrayData[$BillNo][8] = $ContactAddress; |
|
|
|
$arrayData[$BillNo]['received']= array(); |
|
|
|
$arrayData[$BillNo]['total_budget'] = 0; |
|
|
|
$arrayData[$BillNo]['invoice'] = array(); |
|
|
|
$arrayData[$BillNo]['received_budget'] = 0; |
|
|
|
$arrayData[$BillNo]['invoice_budget'] = 0; |
|
|
|
$arrayData[$BillNo]['sign'][1] = $arrayData[$BillNo]['second'][1] = $arrayData[$BillNo]['arrive'][1] = $arrayData[$BillNo]['install'][1] = $arrayData[$BillNo]['tryrun'][1] = $arrayData[$BillNo]['check'][1] = $arrayData[$BillNo]['delivery'][1] = $arrayData[$BillNo]['final'][1] = 0; |
|
|
|
$arrayData[$BillNo]['sign']['min'] = $arrayData[$BillNo]['second']['min'] = $arrayData[$BillNo]['arrive']['min'] = $arrayData[$BillNo]['install']['min'] = $arrayData[$BillNo]['tryrun']['min'] = $arrayData[$BillNo]['check']['min'] = $arrayData[$BillNo]['delivery']['min'] = $arrayData[$BillNo]['final']['min'] = array(); |
|
|
|
$arrayData[$BillNo]['sign']['max'] = $arrayData[$BillNo]['second']['max'] = $arrayData[$BillNo]['arrive']['max'] = $arrayData[$BillNo]['install']['max'] = $arrayData[$BillNo]['tryrun']['max'] = $arrayData[$BillNo]['check']['max'] = $arrayData[$BillNo]['delivery']['max'] = $arrayData[$BillNo]['final']['max'] = array(); |
|
|
|
$arrayData[$BillNo]['facilities'] = ""; |
|
|
|
$arrayData[$BillNo]['total_facility_num'] = $arrayData[$BillNo]['delivery_num'] = $arrayData[$BillNo]['check_num'] = $arrayData[$BillNo]['tryrun_num'] = $arrayData[$BillNo]['install_num'] = $arrayData[$BillNo]['arrive_num'] = $arrayData[$BillNo]['second_num'] = $arrayData[$BillNo]['receivable_budget'] = 0; |
|
|
|
} |
|
|
@ -89,6 +111,7 @@ foreach ($contract as $cont) { |
|
|
|
$arrayData[$BillNo]['second'][0] = $PayStage; |
|
|
|
$arrayData[$BillNo]['second'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['second'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
if (isset($arrayData[$BillNo]['sign'][2]) && !is_null($arrayData[$BillNo]['sign'][2])) { |
|
|
|
$signtime = strtotime(strval($arrayData[$BillNo]['sign'][2])); |
|
|
|
if (in_array($PayStage, $sign60)) { |
|
|
@ -113,33 +136,43 @@ foreach ($contract as $cont) { |
|
|
|
$arrayData[$BillNo]['sign'][0] = $PayStage; |
|
|
|
$arrayData[$BillNo]['sign'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['sign'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
array_push($arrayData[$BillNo]['sign']['min'], intval(substr($PlanPayDate, 4, 2))); |
|
|
|
array_push($arrayData[$BillNo]['sign']['max'], intval(substr($PlanPayDate, 4, 2))); |
|
|
|
} elseif (stristr($PayStage, '試車')) { |
|
|
|
$arrayData[$BillNo]['tryrun'][0] = $PayStage; |
|
|
|
$arrayData[$BillNo]['tryrun'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['tryrun'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
} elseif (stristr($PayStage, '安裝') || stristr($PayStage, '貨抵工地且完工')) { |
|
|
|
$arrayData[$BillNo]['install'][0] = $PayStage; |
|
|
|
$arrayData[$BillNo]['install'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['install'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
} elseif (stristr($PayStage, '貨抵工地') || stristr($PayStage, '貨底工地')) { |
|
|
|
$arrayData[$BillNo]['arrive'][0] = $PayStage; |
|
|
|
$arrayData[$BillNo]['arrive'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['arrive'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
} elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月') || stristr($PayStage, '交車')) { |
|
|
|
$arrayData[$BillNo]['delivery'][0] = $PayStage; |
|
|
|
$arrayData[$BillNo]['delivery'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['delivery'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
} elseif (stristr($PayStage, '合格') || stristr($PayStage, '驗收') || stristr($PayStage, '許可') || stristr($PayStage, '核可')) { |
|
|
|
$arrayData[$BillNo]['check'][0] = $PayStage; |
|
|
|
$arrayData[$BillNo]['check'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['check'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
} elseif (stristr($PayStage, '驗收完成')) { |
|
|
|
$arrayData[$BillNo]['final'][0] = $PayStage; |
|
|
|
$arrayData[$BillNo]['final'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['final'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
} else { |
|
|
|
$arrayData[$BillNo]['other'][1] = $PayAmount; |
|
|
|
$arrayData[$BillNo]['other'][2] = $PlanPayDate; |
|
|
|
$arrayData[$BillNo]['total_budget'] += $PayAmount; |
|
|
|
} |
|
|
|
} |
|
|
|
$sql = "SELECT |
|
|
@ -189,12 +222,24 @@ foreach ($wipwhole_array as $wip) { |
|
|
|
$estimate_delivery_time = strtotime($wip['estimated_shipping_date']); |
|
|
|
$secondtime = $estimate_delivery_time - (30 * 86400); |
|
|
|
$secondtime = date('Ymd', $secondtime); |
|
|
|
if (empty($wip['estimated_shipping_date'])) { |
|
|
|
$arrayData[$wip['contractno']]['second']['min'] = 0; |
|
|
|
} else { |
|
|
|
array_push($arrayData[$wip['contractno']]['second']['max'], intval(substr($wip['estimated_shipping_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['second']['min'], intval(substr($wip['estimated_shipping_date'], 5, 2))); |
|
|
|
} |
|
|
|
$arrayData[$wip['contractno']]['second'][2] = intval($secondtime); |
|
|
|
} elseif (isset($arrayData[$wip['contractno']]['second'][0]) && stristr($arrayData[$wip['contractno']]['second'][0], '出貨前90天')) { |
|
|
|
$estimate_delivery_time = strtotime($wip['estimated_shipping_date']); |
|
|
|
$secondtime = $estimate_delivery_time - (90 * 86400); |
|
|
|
$secondtime = date('Ymd', $secondtime); |
|
|
|
$arrayData[$wip['contractno']]['second'][2] = intval($secondtime); |
|
|
|
if (empty($wip['estimated_shipping_date'])) { |
|
|
|
$arrayData[$wip['contractno']]['second']['min'] = 0; |
|
|
|
} else { |
|
|
|
array_push($arrayData[$wip['contractno']]['second']['max'], intval(substr($wip['estimated_shipping_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['second']['min'], intval(substr($wip['estimated_shipping_date'], 5, 2))); |
|
|
|
} |
|
|
|
} |
|
|
|
if ($wip['delivery_date'] != NULL) { |
|
|
|
$arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) <br>"; |
|
|
@ -205,6 +250,24 @@ foreach ($wipwhole_array as $wip) { |
|
|
|
$arrayData[$wip['contractno']]['install_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['arrive_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['second_num'] += 1; |
|
|
|
array_push($arrayData[$wip['contractno']]['delivery']['min'], intval(substr($wip['delivery_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['delivery']['max'], intval(substr($wip['delivery_date'], 5, 2))); |
|
|
|
if (!empty($wip['official_check_date']) && $wip['official_check_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['check']['min'], intval(substr($wip['official_check_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['check']['max'], intval(substr($wip['official_check_date'], 5, 2))); |
|
|
|
} |
|
|
|
if (!empty($wip['tryrun_end_date']) && $wip['tryrun_end_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['tryrun']['min'], intval(substr($wip['tryrun_end_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['tryrun']['max'], intval(substr($wip['tryrun_end_date'], 5, 2))); |
|
|
|
} |
|
|
|
if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['install']['min'], intval(substr($wip['install_end_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['install']['max'], intval(substr($wip['install_end_date'], 5, 2))); |
|
|
|
} |
|
|
|
if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['min'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['max'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
} |
|
|
|
} elseif ($wip['official_check_date'] != NULL) { |
|
|
|
$arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) <br>"; |
|
|
|
$arrayData[$wip['contractno']]['total_facility_num'] += 1; |
|
|
@ -213,6 +276,20 @@ foreach ($wipwhole_array as $wip) { |
|
|
|
$arrayData[$wip['contractno']]['install_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['arrive_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['second_num'] += 1; |
|
|
|
array_push($arrayData[$wip['contractno']]['check']['min'], intval(substr($wip['official_check_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['check']['max'], intval(substr($wip['official_check_date'], 5, 2))); |
|
|
|
if (!empty($wip['tryrun_end_date']) && $wip['tryrun_end_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['tryrun']['min'], intval(substr($wip['tryrun_end_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['tryrun']['max'], intval(substr($wip['tryrun_end_date'], 5, 2))); |
|
|
|
} |
|
|
|
if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['install']['min'], intval(substr($wip['install_end_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['install']['max'], intval(substr($wip['install_end_date'], 5, 2))); |
|
|
|
} |
|
|
|
if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['min'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['max'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
} |
|
|
|
} elseif ($wip['tryrun_end_date'] != NULL) { |
|
|
|
$arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢) <br>"; |
|
|
|
$arrayData[$wip['contractno']]['total_facility_num'] += 1; |
|
|
@ -220,17 +297,41 @@ foreach ($wipwhole_array as $wip) { |
|
|
|
$arrayData[$wip['contractno']]['install_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['arrive_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['second_num'] += 1; |
|
|
|
if (!empty($wip['tryrun_end_date']) && $wip['tryrun_end_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['tryrun']['min'], intval(substr($wip['tryrun_end_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['tryrun']['max'], intval(substr($wip['tryrun_end_date'], 5, 2))); |
|
|
|
} |
|
|
|
if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['install']['min'], intval(substr($wip['install_end_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['install']['max'], intval(substr($wip['install_end_date'], 5, 2))); |
|
|
|
} |
|
|
|
if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['min'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['max'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
} |
|
|
|
} elseif ($wip['install_end_date'] != NULL) { |
|
|
|
$arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) <br>"; |
|
|
|
$arrayData[$wip['contractno']]['total_facility_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['install_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['arrive_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['second_num'] += 1; |
|
|
|
if (!empty($wip['install_end_date']) && $wip['install_end_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['install']['min'], intval(substr($wip['install_end_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['install']['max'], intval(substr($wip['install_end_date'], 5, 2))); |
|
|
|
} |
|
|
|
if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['min'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['max'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
} |
|
|
|
} elseif ($wip['real_arrival_date'] != NULL) { |
|
|
|
$arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) <br>"; |
|
|
|
$arrayData[$wip['contractno']]['total_facility_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['arrive_num'] += 1; |
|
|
|
$arrayData[$wip['contractno']]['second_num'] += 1; |
|
|
|
if (!empty($wip['real_arrival_date']) && $wip['real_arrival_date'] != NULL) { |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['min'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
array_push($arrayData[$wip['contractno']]['arrive']['max'], intval(substr($wip['real_arrival_date'], 5, 2))); |
|
|
|
} |
|
|
|
} elseif (($arrayData[$wip['contractno']]['second'] != NULL) && (isset($arrayData[$wip['contractno']]['second'][2])) && ($arrayData[$wip['contractno']]['second'][2] <= date('Ymd'))) { |
|
|
|
if ($wip['estimated_shipping_date'] != NULL) { |
|
|
|
$arrayData[$wip['contractno']]['facilities'] .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計出貨日) <br>"; |
|
|
@ -258,20 +359,60 @@ foreach ($wipwhole_array as $wip) { |
|
|
|
|
|
|
|
foreach ($arrayData as &$value) { |
|
|
|
if ($value['total_facility_num'] > 0) { |
|
|
|
$month = 11; |
|
|
|
$value['receivable_budget'] = $value['sign'][1] + ($value['second'][1] * ($value['second_num'] / $value['total_facility_num'])) + |
|
|
|
($value['arrive'][1] * ($value['arrive_num'] / $value['total_facility_num'])) + ($value['install'][1] * ($value['install_num'] / $value['total_facility_num'])) + |
|
|
|
($value['tryrun'][1] * ($value['tryrun_num'] / $value['total_facility_num'])) + ($value['check'][1] * ($value['check_num'] / $value['total_facility_num'])) + |
|
|
|
(($value['delivery'][1] + $value['final'][1]) * ($value['delivery_num'] / $value['total_facility_num'])); |
|
|
|
$value['sign'][3] = $value['sign'][1]; |
|
|
|
$value['second'][3] = $value['second'][1] * ($value['second_num'] / $value['total_facility_num']); |
|
|
|
$value['arrive'][3] = $value['arrive'][1] * ($value['arrive_num'] / $value['total_facility_num']); |
|
|
|
$value['install'][3] = $value['install'][1] * ($value['install_num'] / $value['total_facility_num']); |
|
|
|
$value['tryrun'][3] = $value['tryrun'][1] * ($value['tryrun_num'] / $value['total_facility_num']); |
|
|
|
$value['check'][3] = $value['check'][1] * ($value['check_num'] / $value['total_facility_num']); |
|
|
|
$value['delivery'][3] = $value['delivery'][1] * ($value['delivery_num'] / $value['total_facility_num']); |
|
|
|
$value['final'][3] = $value['final'][1] * ($value['delivery_num'] / $value['total_facility_num']); |
|
|
|
} |
|
|
|
$value['sign']['max'] = empty($value['sign']['max']) ? 0 : (($month - max($value['sign']['max'])) < 0 ? 0 : ($month - max($value['sign']['max']))); |
|
|
|
$value['sign']['min'] = empty($value['sign']['min']) ? 0 : (($month - min($value['sign']['min'])) < 0 ? 0 : ($month - min($value['sign']['min']))); |
|
|
|
$value['second']['max'] = empty($value['second']['max']) ? 0 : (($month - max($value['second']['max'])) < 0 ? 0 : ($month - max($value['second']['max']))); |
|
|
|
$value['second']['min'] = empty($value['second']['min']) ? 0 : (($month - min($value['second']['min'])) < 0 ? 0 : ($month - min($value['second']['min']))); |
|
|
|
$value['arrive']['max'] = empty($value['arrive']['max']) ? 0 : (($month - max($value['arrive']['max'])) < 0 ? 0 : ($month - max($value['arrive']['max']))); |
|
|
|
$value['arrive']['min'] = empty($value['arrive']['min']) ? 0 : (($month - min($value['arrive']['min'])) < 0 ? 0 : ($month - min($value['arrive']['min']))); |
|
|
|
$value['install']['max'] = empty($value['install']['max']) ? 0 : (($month - max($value['install']['max'])) < 0 ? 0 : ($month - max($value['install']['max']))); |
|
|
|
$value['install']['min'] = empty($value['install']['min']) ? 0 : (($month - min($value['install']['min'])) < 0 ? 0 : ($month - min($value['install']['min']))); |
|
|
|
$value['tryrun']['max'] = empty($value['tryrun']['max']) ? 0 : (($month - max($value['tryrun']['max'])) < 0 ? 0 : ($month - max($value['tryrun']['max']))); |
|
|
|
$value['tryrun']['min'] = empty($value['tryrun']['min']) ? 0 : (($month - min($value['tryrun']['min'])) < 0 ? 0 : ($month - min($value['tryrun']['min']))); |
|
|
|
$value['check']['max'] = empty($value['check']['max']) ? 0 : (($month - max($value['check']['max'])) < 0 ? 0 : ($month - max($value['check']['max']))); |
|
|
|
$value['check']['min'] = empty($value['check']['min']) ? 0 : (($month - min($value['check']['min'])) < 0 ? 0 : ($month - min($value['check']['min']))); |
|
|
|
$value['delivery']['max'] = empty($value['delivery']['max']) ? 0 : (($month - max($value['delivery']['max'])) < 0 ? 0 : ($month - max($value['delivery']['max']))); |
|
|
|
$value['delivery']['min'] = empty($value['delivery']['min']) ? 0 : (($month - min($value['delivery']['min'])) < 0 ? 0 : ($month - min($value['delivery']['min']))); |
|
|
|
$value['final']['max'] = empty($value['final']['max']) ? 0 : (($month - max($value['final']['max'])) < 0 ? 0 : ($month - max($value['final']['max']))); |
|
|
|
$value['final']['min'] = empty($value['final']['min']) ? 0 : (($month - min($value['final']['min'])) < 0 ? 0 : ($month - min($value['final']['min']))); |
|
|
|
} |
|
|
|
// array_push($arrayData[$wip['contractno']]['received'], ['assaaa',123124,'sdrfrqa']); |
|
|
|
|
|
|
|
foreach($received_array as $received){ |
|
|
|
|
|
|
|
if(isset($arrayData[$received['OrderBillNo']])){ |
|
|
|
array_push($arrayData[$received['OrderBillNo']]['received'], [$received['BillNo'],$received['WriteOffBizPartnerId'],$received['OrderBillNo'],]); |
|
|
|
|
|
|
|
// [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']]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 把核銷單的內容補到發票資料中 |
|
|
|
foreach ($received_array as $received) { |
|
|
|
if ($received['OrderBillNo'] == 'SO20230801001') { |
|
|
|
$BillNo = 'M230947'; |
|
|
|
} elseif ($received['OrderBillNo'] == 'SO20230801002') { |
|
|
|
$BillNo = 'M231067'; |
|
|
|
} else { |
|
|
|
$BillNo = $received['OrderBillNo']; |
|
|
|
}; |
|
|
|
if (isset($arrayData[$BillNo])) { |
|
|
|
if (isset($arrayData[$BillNo]['invoice'][$received['InvoiceNo']])) { |
|
|
|
$arrayData[$BillNo]['received_budget'] += $received['PayWriteOffOAmount']; |
|
|
|
array_push($arrayData[$BillNo]['invoice'][$received['InvoiceNo']], date($received['ReceivedDate']), $received['PayWriteOffOAmount'], $received['Fee'], $received['BillNo']); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$data = json_encode($arrayData); |
|
|
@ -315,35 +456,59 @@ $data = json_encode($arrayData); |
|
|
|
} |
|
|
|
</style> |
|
|
|
<button type="button" onclick="downloadData()" class="btn btn-warning btn-lg pull-right"><span class="glyphicon glyphicon-download-alt"></span></button> |
|
|
|
|
|
|
|
<div style="width:98%;margin:1%"> |
|
|
|
<div style="width:98%;margin:1% ;overflow-x: auto;"> |
|
|
|
<table id="table_index" class="table table-striped table-bordered" style="width:100%;"> |
|
|
|
<thead> |
|
|
|
<tr> |
|
|
|
<th style="width: 120px;">合約號</th> |
|
|
|
<th style="width: 120px;">部門</th> |
|
|
|
<th style="width: 80px;">經理</th> |
|
|
|
<th style="width: 80px;">營業員</th> |
|
|
|
<th>客戶名稱</th> |
|
|
|
<!-- <th style="width: 100px;">簽約款</th> |
|
|
|
<th style="width: 100px;">二次款</th> |
|
|
|
<th style="width: 100px;">貨抵工地款</th> |
|
|
|
<th style="width: 100px;">安裝款</th> |
|
|
|
<th style="width: 100px;">試車款</th> |
|
|
|
<th style="width: 100px;">官檢款</th> |
|
|
|
<th style="width: 100px;">交車款</th> |
|
|
|
<th style="width: 100px;">尾款</th> --> |
|
|
|
<th style="width: 100px;">目前應收</th> |
|
|
|
<!-- <th style="width: 150px;">未開發票金額</th> |
|
|
|
<th style="width: 100px;">未收金額</th> --> |
|
|
|
<th>作番狀態</th> |
|
|
|
<th style="width: 120px;">經理</th> |
|
|
|
<th style="width: 120px;">營業員</th> |
|
|
|
<th style="width: 120px;">客戶名稱</th> |
|
|
|
<th style="width: 120px;">簽約款</th> |
|
|
|
<th style="width: 120px;">應收簽約金額</th> |
|
|
|
<th style="width: 120px;">簽約最大催收次數</th> |
|
|
|
<th style="width: 120px;">簽約最小催收次數</th> |
|
|
|
<th style="width: 120px;">二次款</th> |
|
|
|
<th style="width: 120px;">應收二次金額</th> |
|
|
|
<th style="width: 120px;">二次最大催收次數</th> |
|
|
|
<th style="width: 120px;">二次最小催收次數</th> |
|
|
|
<th style="width: 120px;">貨抵工地款</th> |
|
|
|
<th style="width: 120px;">應收貨抵工地金額</th> |
|
|
|
<th style="width: 120px;">貨抵工地最大催收次數</th> |
|
|
|
<th style="width: 120px;">貨抵工地最小催收次數</th> |
|
|
|
<th style="width: 120px;">安裝款</th> |
|
|
|
<th style="width: 120px;">應收安裝金額</th> |
|
|
|
<th style="width: 120px;">安裝最大催收次數</th> |
|
|
|
<th style="width: 120px;">安裝最小催收次數</th> |
|
|
|
<th style="width: 120px;">試車款</th> |
|
|
|
<th style="width: 120px;">應收試車金額</th> |
|
|
|
<th style="width: 120px;">試車最大催收次數</th> |
|
|
|
<th style="width: 120px;">試車最小催收次數</th> |
|
|
|
<th style="width: 120px;">官檢款</th> |
|
|
|
<th style="width: 120px;">應收官檢金額</th> |
|
|
|
<th style="width: 120px;">官檢最大催收次數</th> |
|
|
|
<th style="width: 120px;">官檢最小催收次數</th> |
|
|
|
<th style="width: 120px;">移交款</th> |
|
|
|
<th style="width: 120px;">應收移交金額</th> |
|
|
|
<th style="width: 120px;">移交最大催收次數</th> |
|
|
|
<th style="width: 120px;">移交最小催收次數</th> |
|
|
|
<th style="width: 120px;">尾款</th> |
|
|
|
<th style="width: 120px;">應收尾款金額</th> |
|
|
|
<th style="width: 120px;">尾款最大催收次數</th> |
|
|
|
<th style="width: 120px;">尾款最小催收次數</th> |
|
|
|
<th style="width: 120px;">合約總金額</th> |
|
|
|
<th style="width: 120px;" style="width: 120px;">目前應收</th> |
|
|
|
<th style="width: 120px;" style="width: 120px;">已開發票金額</th> |
|
|
|
<th style="width: 120px;">已收金額</th> |
|
|
|
<!-- <th>作番狀態</th> --> |
|
|
|
<!-- <th style="width: 100px;">收款狀態</th> --> |
|
|
|
<th style="width: 100px;">操作</th> |
|
|
|
|
|
|
|
</tr> |
|
|
|
</thead> |
|
|
|
<tbody> |
|
|
|
<?php |
|
|
|
foreach ($arrayData as $key =>$value) { |
|
|
|
foreach ($arrayData as $key => $value) { |
|
|
|
?> |
|
|
|
<tr> |
|
|
|
<th><?= $key ?></th> |
|
|
@ -351,19 +516,45 @@ $data = json_encode($arrayData); |
|
|
|
<td><?= $value[2] ?></td> |
|
|
|
<td><?= $value[4] ?></td> |
|
|
|
<td><?= $value[5] ?></td> |
|
|
|
<!-- <td style="text-align: end;"><?= number_format(round($value['sign'][1])) ?></td>
|
|
|
|
<td style="text-align: end;"><?= number_format(round($value['second'][1])) ?></td> |
|
|
|
<td style="text-align: end;"><?= number_format(round($value['arrive'][1])) ?></td> |
|
|
|
<td style="text-align: end;"><?= number_format(round($value['install'][1])) ?></td> |
|
|
|
<td style="text-align: end;"><?= number_format(round($value['tryrun'][1])) ?></td> |
|
|
|
<td style="text-align: end;"><?= number_format(round($value['check'][1])) ?></td> |
|
|
|
<td style="text-align: end;"><?= number_format(round($value['delivery'][1])) ?></td> |
|
|
|
<td style="text-align: end;"><?= number_format(round($value['final'][1])) ?></td> --> |
|
|
|
<td style="text-align: end;"><?= number_format(round($value['receivable_budget'])) ?></td> |
|
|
|
<!-- <td style="text-align: end;"><?= number_format(round($value['total_facility_num'])) ?></td> --> |
|
|
|
<td style="text-align: start;"><?= $value['facilities'] ?></td> |
|
|
|
<td><?= number_format(round($value['sign'][1])) ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['sign'][3]) ? number_format(round($value['sign'][3])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['sign']['min']) ? $value['sign']['min'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['sign']['max']) ? $value['sign']['max'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['second'][1]) ? number_format(round($value['second'][1])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['second'][3]) ? number_format(round($value['second'][3])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['second']['min']) ? $value['second']['min'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['second']['max']) ? $value['second']['max'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['arrive'][1]) ? number_format(round($value['arrive'][1])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['arrive'][3]) ? number_format(round($value['arrive'][3])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['arrive']['min']) ? $value['arrive']['min'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['arrive']['max']) ? $value['arrive']['max'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['install'][1]) ? number_format(round($value['install'][1])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['install'][3]) ? number_format(round($value['install'][3])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['install']['min']) ? $value['install']['min'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['install']['max']) ? $value['install']['max'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['tryrun'][1]) ? number_format(round($value['tryrun'][1])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['tryrun'][3]) ? number_format(round($value['tryrun'][3])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['tryrun']['min']) ? $value['tryrun']['min'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['tryrun']['max']) ? $value['tryrun']['max'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['check'][1]) ? number_format(round($value['check'][1])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['check'][3]) ? number_format(round($value['check'][3])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['check']['min']) ? $value['check']['min'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['check']['max']) ? $value['check']['max'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['delivery'][1]) ? number_format(round($value['delivery'][1])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['delivery'][3]) ? number_format(round($value['delivery'][3])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['delivery']['min']) ? $value['delivery']['min'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['delivery']['max']) ? $value['delivery']['max'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['final'][1]) ? number_format(round($value['final'][1])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['final'][3]) ? number_format(round($value['final'][3])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['final']['min']) ? $value['final']['min'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['final']['max']) ? $value['final']['max'] : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['total_budget']) ? number_format(round($value['total_budget'])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['receivable_budget']) ? number_format(round($value['receivable_budget'])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['invoice_budget']) ? number_format(round($value['invoice_budget'])) : '--' ?></td> |
|
|
|
<td style="text-align: end;"><?= isset($value['received_budget']) ? number_format(round($value['received_budget'])) : '--' ?></td> |
|
|
|
<!-- <td style="text-align: start;"><?= $value['facilities'] ?></td>
|
|
|
|
<td><button type="button" onclick="sendData('<?= $key ?>')" class="btn btn-primary btn-sm"><span class=" glyphicon glyphicon-search"></span></button> |
|
|
|
</td> |
|
|
|
</td> --> |
|
|
|
</tr> |
|
|
|
<?php |
|
|
|
} |
|
|
@ -372,7 +563,7 @@ $data = json_encode($arrayData); |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
<script> |
|
|
|
function downloadData() { |
|
|
|
function test() { |
|
|
|
var BillData = <?= $data ?>; |
|
|
|
var form = document.createElement("form"); |
|
|
|
form.method = 'POST'; |
|
|
@ -386,6 +577,30 @@ $data = json_encode($arrayData); |
|
|
|
form.submit(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function downloadData() { |
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
var url = window.location.origin + "/wms/account-receivable-excel.php?<?= $token_link ?>"; |
|
|
|
xhr.open('POST', url, true); |
|
|
|
xhr.setRequestHeader('Content-Type', 'application/json'); |
|
|
|
xhr.onreadystatechange = function() { |
|
|
|
if (xhr.readyState === 4 && xhr.status === 200) { |
|
|
|
var file_path = xhr.responseText; |
|
|
|
var link = document.createElement('a'); |
|
|
|
var name = "應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx"; |
|
|
|
link.setAttribute('href', window.location.origin + "/wms/account-receivable.xlsx"); |
|
|
|
link.setAttribute('download', name); |
|
|
|
link.style.display = 'none'; |
|
|
|
document.body.appendChild(link); |
|
|
|
link.click(); |
|
|
|
document.body.removeChild(link); |
|
|
|
} |
|
|
|
} |
|
|
|
xhr.send(JSON.stringify({ |
|
|
|
Bill: <?= $data ?> |
|
|
|
})); |
|
|
|
} |
|
|
|
|
|
|
|
function sendData(BillNo) { |
|
|
|
var BillData = <?= $data ?>; |
|
|
|
var Bill = BillData[BillNo]; |
|
|
|