|
|
@ -1,4 +1,7 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Sign; |
|
|
|
|
|
|
|
include "header.php"; |
|
|
|
|
|
|
|
$follower = find_follow($user_id); |
|
|
@ -39,6 +42,45 @@ 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 = "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 "; |
|
|
|
|
|
|
|
//ORDER BY contractno |
|
|
|
|
|
|
|
// 期初收款資訊 |
|
|
|
$sql_opening = " |
|
|
|
SELECT * FROM account_received "; |
|
|
@ -46,20 +88,25 @@ 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_received .= " AND (PersonId = '$user_id'"; |
|
|
|
$sql_opening .= " OR person_id = '$user_id'"; |
|
|
|
$sql .= " WHERE salesid = '$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_received .= " OR PersonId IN $column_str)"; |
|
|
|
$sql_opening .= " OR person_id IN $column_str)"; |
|
|
|
$sql .= " OR salesid IN $column_str ORDER BY contractno"; |
|
|
|
} else { |
|
|
|
$sql_contract .= ")"; |
|
|
|
$sql_received .= ")"; |
|
|
|
// $sql_received .= ")"; |
|
|
|
$sql_opening .= ")"; |
|
|
|
$sql .= " ORDER BY contractno"; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
$sql .= " ORDER BY contractno"; |
|
|
|
} |
|
|
|
|
|
|
|
$contract = $conn->query($sql_contract); |
|
|
@ -183,41 +230,7 @@ foreach ($contract as $cont) { |
|
|
|
//取作番大日程作番與時程 |
|
|
|
// real_contract_arrival_date 預計出貨日 |
|
|
|
// real_arrival_date 實際出貨日 |
|
|
|
$sql = "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 ORDER BY contractno"; |
|
|
|
$wipwhole_array = mysqli_query($link, $sql); |
|
|
|
foreach ($wipwhole_array as $wip) { |
|
|
|
$today = strtotime(date('Ymd')); |
|
|
@ -515,7 +528,7 @@ foreach ($wipwhole_array as $wip) { |
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($wip['tryrun_end_date']) && $wip['tryrun_end_date'] != NULL) { |
|
|
|
if ( isset($arrayData[$wip['contractno']]['tryrun'][0]) && $arrayData[$wip['contractno']]['tryrun'][0] == "安裝試車後90天") { |
|
|
|
if (isset($arrayData[$wip['contractno']]['tryrun'][0]) && $arrayData[$wip['contractno']]['tryrun'][0] == "安裝試車後90天") { |
|
|
|
$estimate_delivery_time = strtotime($wip['tryrun_end_date']); |
|
|
|
$tryruntime = $estimate_delivery_time + (90 * 86400); |
|
|
|
$month = collect_month($tryruntime); |
|
|
@ -846,6 +859,8 @@ $excel_aray = array(); |
|
|
|
$boga_array = array(); |
|
|
|
$exclude_boga_array = array(); |
|
|
|
$facility_array = array(); |
|
|
|
$facility_boga_array = array(); |
|
|
|
$facility_exclude_boga_array = array(); |
|
|
|
foreach ($arrayData as $key => $value) { |
|
|
|
$value['sign'][3] = (isset($value['sign'][3])) ? $value['sign'][3] : 0; |
|
|
|
$value['second'][3] = (isset($value['second'][3])) ? $value['second'][3] : 0; |
|
|
@ -916,7 +931,7 @@ foreach ($arrayData as $key => $value) { |
|
|
|
$val[$stage][6] = (!(isset($val[$stage][6])) || is_null($val[$stage][6])) ? 0 : $val[$stage][6]; |
|
|
|
} |
|
|
|
$facility_array[$valkey] = [ |
|
|
|
$key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], $valkey, |
|
|
|
$valkey, $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], |
|
|
|
$val['sign'][0], $val['sign'][1], $val['sign'][2], $val['sign'][3], $val['sign'][4], $val['sign'][5], $val['sign'][6], |
|
|
|
$val['second'][0], $val['second'][1], $val['second'][2], $val['second'][3], $val['second'][4], $val['second'][5], $val['second'][6], |
|
|
|
$val['arrive'][0], $val['arrive'][1], $val['arrive'][2], $val['arrive'][3], $val['arrive'][4], $val['arrive'][5], $val['arrive'][6], |
|
|
@ -927,316 +942,82 @@ foreach ($arrayData as $key => $value) { |
|
|
|
$val['final'][0], $val['final'][1], $val['final'][2], $val['final'][3], $val['final'][4], $val['final'][5], $val['final'][6], |
|
|
|
str_replace('<br>', '; ', $val['status']), $val['total_budget'], $val['receivable_budget'] |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
// foreach($facility_array as $key=>$value){ |
|
|
|
// echo $key; |
|
|
|
// echo '<br>'; |
|
|
|
// print_r($value); |
|
|
|
// echo '<br><br>'; |
|
|
|
// } |
|
|
|
|
|
|
|
$data = json_encode($excel_aray); |
|
|
|
$boga_data = json_encode($boga_array); |
|
|
|
$exclude_boga_data = json_encode($exclude_boga_array); |
|
|
|
$facility_data = json_encode($facility_array); |
|
|
|
|
|
|
|
?> |
|
|
|
<style> |
|
|
|
table { |
|
|
|
table-layout: fixed; |
|
|
|
width: 100%; |
|
|
|
} |
|
|
|
|
|
|
|
td { |
|
|
|
word-wrap: break-word; |
|
|
|
} |
|
|
|
|
|
|
|
img { |
|
|
|
width: 125px; |
|
|
|
} |
|
|
|
|
|
|
|
.width_style_1 { |
|
|
|
width: 125px; |
|
|
|
} |
|
|
|
|
|
|
|
table { |
|
|
|
width: 100%; |
|
|
|
} |
|
|
|
|
|
|
|
#table_index_filter { |
|
|
|
float: right; |
|
|
|
} |
|
|
|
|
|
|
|
#table_index_paginate { |
|
|
|
float: right; |
|
|
|
} |
|
|
|
|
|
|
|
label { |
|
|
|
display: inline-flex; |
|
|
|
margin-bottom: .5rem; |
|
|
|
margin-top: .5rem; |
|
|
|
|
|
|
|
} |
|
|
|
</style> |
|
|
|
<div class="btn-group btn-group-lg" style="padding:10 px;"> |
|
|
|
<button type="button" onclick="downloadData()" class="btn btn-success">全部<span class="glyphicon glyphicon-download-alt"></span></button> |
|
|
|
<button type="button" onclick="exclude_bogaData()" class="btn btn-info">不含寶佳<span class="glyphicon glyphicon-download-alt"></span></button> |
|
|
|
<button type="button" onclick="bogaData()" class="btn btn-warning">寶佳<span class="glyphicon glyphicon-download-alt"></span></button> |
|
|
|
</div> |
|
|
|
<div style="padding: 10px;"> |
|
|
|
<button type="button" onclick="downloadFacilityData()" class="btn btn-primary btn-lg">合約作番明細<span class="glyphicon glyphicon-download-alt"></span></button> |
|
|
|
</div> |
|
|
|
<div> |
|
|
|
<?php |
|
|
|
if (in_array(accountidToDepartId($user_id), array('220', '210')) || $user_id == 'M0060') { |
|
|
|
?> |
|
|
|
<!-- <a href="facility-price.php?<?= $token_link ?>" class="btn btn-primary btn-lg pull-right">合約作番明細</span></a> --> |
|
|
|
<?php |
|
|
|
} |
|
|
|
?> |
|
|
|
</div> |
|
|
|
<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: 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: 350px;">收款狀態</th> |
|
|
|
|
|
|
|
</tr> |
|
|
|
</thead> |
|
|
|
<tbody> |
|
|
|
<?php |
|
|
|
foreach ($arrayData as $key => $value) { |
|
|
|
?> |
|
|
|
<tr> |
|
|
|
<th><a onclick="showContract('<?= $key ?>')"><?= $key ?> </a></th> |
|
|
|
<td><?= $value[1] ?></td> |
|
|
|
<td><?= $value[2] ?></td> |
|
|
|
<td><?= $value[4] ?></td> |
|
|
|
<td><?= $value[5] ?></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> --> |
|
|
|
</tr> |
|
|
|
<?php |
|
|
|
} |
|
|
|
?> |
|
|
|
</tbody> |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
<script> |
|
|
|
function showContract(BillNo) { |
|
|
|
window.open('account-receivable-contract.php?BillNo=' + BillNo + '&<?= $token_link ?>', '發票範例', config = 'height=600, width=1200'); |
|
|
|
console.log(BillNo); |
|
|
|
} |
|
|
|
|
|
|
|
function test() { |
|
|
|
var BillData = <?= $boga_data ?>; |
|
|
|
var form = document.createElement("form"); |
|
|
|
form.method = 'POST'; |
|
|
|
form.action = "account-receivable-excel.php?type=facility&<?= $token_link ?>"; |
|
|
|
var input = document.createElement("input"); |
|
|
|
input.type = "hidden"; |
|
|
|
input.name = "Bill"; |
|
|
|
input.value = JSON.stringify(BillData); |
|
|
|
form.appendChild(input); |
|
|
|
document.body.appendChild(form); |
|
|
|
form.submit(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function downloadData() { |
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
var url = window.location.origin + "/wms/account-receivable-excel.php?type=all&<?= $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-test.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 ?> |
|
|
|
// }) |
|
|
|
// ); |
|
|
|
xhr.send(JSON.stringify({ |
|
|
|
Bill: <?= $data ?> |
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function bogaData() { |
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
var url = window.location.origin + "/wms/account-receivable-excel.php?type=boga&<?= $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-test.xlsx"); |
|
|
|
link.setAttribute('download', name); |
|
|
|
link.style.display = 'none'; |
|
|
|
document.body.appendChild(link); |
|
|
|
link.click(); |
|
|
|
document.body.removeChild(link); |
|
|
|
} |
|
|
|
if ($value['sign'][0] == "寶佳出貨前30天") { |
|
|
|
$facility_boga_array[$valkey] = [ |
|
|
|
$valkey, $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], |
|
|
|
$val['sign'][0], $val['sign'][1], $val['sign'][2], $val['sign'][3], $val['sign'][4], $val['sign'][5], $val['sign'][6], |
|
|
|
$val['second'][0], $val['second'][1], $val['second'][2], $val['second'][3], $val['second'][4], $val['second'][5], $val['second'][6], |
|
|
|
$val['arrive'][0], $val['arrive'][1], $val['arrive'][2], $val['arrive'][3], $val['arrive'][4], $val['arrive'][5], $val['arrive'][6], |
|
|
|
$val['install'][0], $val['install'][1], $val['install'][2], $val['install'][3], $val['install'][4], $val['install'][5], $val['install'][6], |
|
|
|
$val['tryrun'][0], $val['tryrun'][1], $val['tryrun'][2], $val['tryrun'][3], $val['tryrun'][4], $val['tryrun'][5], $val['tryrun'][6], |
|
|
|
$val['check'][0], $val['check'][1], $val['check'][2], $val['check'][3], $val['check'][4], $val['check'][5], $val['check'][6], |
|
|
|
$val['delivery'][0], $val['delivery'][1], $val['delivery'][2], $val['delivery'][3], $val['delivery'][4], $val['delivery'][5], $val['delivery'][6], |
|
|
|
$val['final'][0], $val['final'][1], $val['final'][2], $val['final'][3], $val['final'][4], $val['final'][5], $val['final'][6], |
|
|
|
str_replace('<br>', '; ', $val['status']), $val['total_budget'], $val['receivable_budget'] |
|
|
|
]; |
|
|
|
} else { |
|
|
|
$facility_exclude_boga_array[$valkey] = [ |
|
|
|
$valkey, $key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6], |
|
|
|
$val['sign'][0], $val['sign'][1], $val['sign'][2], $val['sign'][3], $val['sign'][4], $val['sign'][5], $val['sign'][6], |
|
|
|
$val['second'][0], $val['second'][1], $val['second'][2], $val['second'][3], $val['second'][4], $val['second'][5], $val['second'][6], |
|
|
|
$val['arrive'][0], $val['arrive'][1], $val['arrive'][2], $val['arrive'][3], $val['arrive'][4], $val['arrive'][5], $val['arrive'][6], |
|
|
|
$val['install'][0], $val['install'][1], $val['install'][2], $val['install'][3], $val['install'][4], $val['install'][5], $val['install'][6], |
|
|
|
$val['tryrun'][0], $val['tryrun'][1], $val['tryrun'][2], $val['tryrun'][3], $val['tryrun'][4], $val['tryrun'][5], $val['tryrun'][6], |
|
|
|
$val['check'][0], $val['check'][1], $val['check'][2], $val['check'][3], $val['check'][4], $val['check'][5], $val['check'][6], |
|
|
|
$val['delivery'][0], $val['delivery'][1], $val['delivery'][2], $val['delivery'][3], $val['delivery'][4], $val['delivery'][5], $val['delivery'][6], |
|
|
|
$val['final'][0], $val['final'][1], $val['final'][2], $val['final'][3], $val['final'][4], $val['final'][5], $val['final'][6], |
|
|
|
str_replace('<br>', '; ', $val['status']), $val['total_budget'], $val['receivable_budget'] |
|
|
|
]; |
|
|
|
} |
|
|
|
xhr.send(JSON.stringify({ |
|
|
|
Bill: <?= $boga_data ?> |
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
function downloadFacilityData() { |
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
var url = window.location.origin + "/wms/account-receivable-excel.php?type=facility&<?= $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-facility.xlsx"); |
|
|
|
link.setAttribute('download', name); |
|
|
|
link.style.display = 'none'; |
|
|
|
document.body.appendChild(link); |
|
|
|
link.click(); |
|
|
|
document.body.removeChild(link); |
|
|
|
} |
|
|
|
$table = ""; |
|
|
|
|
|
|
|
//[stage] 0 款名 1金額 2 應收款日期 |
|
|
|
//['facility'] [作番號][款別]0 款項名稱 1 合約金額 2 應收日期 3 應收金額 4 已收金額 5 催收金額 6 催收次數 |
|
|
|
// 0 部門id 1 部門名稱 2 經理名稱 3 營業員id 4 營業員名稱 5 客戶名稱 6 抬頭 7 統編 8 通訊地址 |
|
|
|
// [合約號]['facility'][作番號]['no'] |
|
|
|
//['receivable_budget'] / ['total_facility_num'] / ['total_budget'] |
|
|
|
//('sign', 'second', 'arrive', 'install', 'tryrun', 'check', 'delivery', 'final'); |
|
|
|
foreach ($arrayData as $key => $value) { |
|
|
|
foreach($value['facility'] as $fakey => $facility) { |
|
|
|
foreach ($contractstage as $stage) { |
|
|
|
switch ($stage) { |
|
|
|
case 'sign':$stageno = 0;break; |
|
|
|
case 'second':$stageno=1;break; |
|
|
|
case 'arrive':$stageno=2;break; |
|
|
|
case 'install':$stageno=3;break; |
|
|
|
case 'tryrun':$stageno=4;break; |
|
|
|
case 'check':$stageno=5;break; |
|
|
|
case 'delivery':$stageno=6;break; |
|
|
|
case 'final':$stageno=7;break; |
|
|
|
} |
|
|
|
} |
|
|
|
xhr.send(JSON.stringify({ |
|
|
|
Bill: <?= $facility_data ?> |
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function exclude_bogaData() { |
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
var url = window.location.origin + "/wms/account-receivable-excel.php?type=exclude_boga&<?= $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-test.xlsx"); |
|
|
|
link.setAttribute('download', name); |
|
|
|
link.style.display = 'none'; |
|
|
|
document.body.appendChild(link); |
|
|
|
link.click(); |
|
|
|
document.body.removeChild(link); |
|
|
|
if (isset($value[$stage]) && isset($value[$stage][0]) && !empty($value[$stage][0])) { |
|
|
|
if($value[$stage][3] >0){ |
|
|
|
$stage3 = 1; |
|
|
|
}else{ |
|
|
|
$stage3 = 0; |
|
|
|
} |
|
|
|
$budget = $value[$stage][1]; |
|
|
|
$receivable_date = $value[$stage][2]; |
|
|
|
$table .= "INSERT INTO account_receivable ( |
|
|
|
`contract_no`, |
|
|
|
`facility_no`, |
|
|
|
`stage`, |
|
|
|
`budget`, |
|
|
|
`receivable_date`, |
|
|
|
`receivable`) VALUES ('$key','$fakey',$stageno,$budget,$receivable_date,$stage3); \n"; |
|
|
|
} |
|
|
|
} |
|
|
|
xhr.send(JSON.stringify({ |
|
|
|
Bill: <?= $exclude_boga_data ?> |
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$file_path = 'account_receivable_sql_file.sql'; |
|
|
|
|
|
|
|
|
|
|
|
function sendData(BillNo) { |
|
|
|
var BillData = <?= $data ?>; |
|
|
|
var Bill = BillData[BillNo]; |
|
|
|
var form = document.createElement("form"); |
|
|
|
form.method = 'POST'; |
|
|
|
form.action = "account-receivable-check.php?<?= $token_link ?>"; |
|
|
|
var input = document.createElement("input"); |
|
|
|
input.type = "hidden"; |
|
|
|
input.name = "Bill"; |
|
|
|
input.value = JSON.stringify(Bill); |
|
|
|
form.appendChild(input); |
|
|
|
document.body.appendChild(form); |
|
|
|
form.submit(); |
|
|
|
} |
|
|
|
</script> |
|
|
|
if (file_put_contents($file_path, $table) !== false) { |
|
|
|
echo "SQL文件已成功生成:{$file_path}"; |
|
|
|
} else { |
|
|
|
echo "生成SQL文件时出现错误。"; |
|
|
|
} |
|
|
|
// echo $table; |