You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

297 lines
12 KiB

<?php
include "header.php";
require_once dirname(__DIR__) . '/common/composer/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as xls;
//use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
$arrayData = [];
$receivable_array = [];
//4 簽約 5 二次款 6 貨抵工地 7 安裝 8 試車 9官檢 10 交車
//arrive_num 貨抵工地 tryrun_num 試車安裝完畢 official_num 官檢完畢 delivery_num 移交
// echo "合約號;部門;經理;營業員;客戶名稱;簽約款;二次款;貨抵工地款;安裝款;試車款;官檢款;交車款;目前應收;總作番數;貨抵;安裝試車;官檢;移交數;狀態</br>";
// $T8_array = mysqli_fetch_all($T8_array, MYSQLI_ASSOC);
// $sql_depid = "SELECT department_id, name from department";
// $dept_query = mysqli_query($link, $sql_depid);
// $deptype = mysqli_fetch_all($dept_query, MYSQLI_ASSOC);
$sql_contract = "SELECT a.BillNo, a.PayStage, a.PlanPayAmt,s.BizPartnerId,c.BizPartnerName,
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) ";
$contract = $conn->query($sql_contract);
foreach ($contract as $cont) {
// print_r($cont);
// echo "<br>";
if ($cont['BillNo'] == 'SO20230801001') {
$BillNo = 'M230947';
} elseif ($cont['BillNo'] == 'SO20230801002') {
$BillNo = 'M231067';
} else {
$BillNo = $cont['BillNo'];
};
$PayStage = $cont['PayStage'];
$PayAmount = $cont['PlanPayAmt'];
$partnerName = $cont['BizPartnerName'];
$EnterpriseName = $cont['EnterpriseName'];
$TaxNo = $cont['TaxNo'];
$ContactAddress = $cont['ContactAddress'];
//4 簽約 5 二次款 6 貨抵工地 7 安裝 8 試車 9官檢 10 交車
if (isset($arrayData[$BillNo])) {
if (stristr($PayStage, '二次款') || stristr($PayStage, '出貨前') || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60')) {
$arrayData[$BillNo][5] = $PayAmount;
} elseif ($PayStage == '簽約' || stristr($PayStage, '簽定') || stristr($PayStage, '簽訂') || stristr($PayStage, '訂金')) {
$arrayData[$BillNo][4] = $PayAmount;
} elseif (stristr($PayStage, '貨抵工地') || stristr($PayStage, '貨底工地')) {
$arrayData[$BillNo][6] = $PayAmount;
} elseif (stristr($PayStage, '試車') || stristr($PayStage, '驗收完成')) {
$arrayData[$BillNo][8] = $PayAmount;
} elseif (stristr($PayStage, '安裝')) {
$arrayData[$BillNo][7] = $PayAmount;
} elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月') || stristr($PayStage, '交車')) {
$arrayData[$BillNo][10] = $PayAmount;
} elseif (stristr($PayStage, '合格') || stristr($PayStage, '驗收') || stristr($PayStage, '許可') || stristr($PayStage, '核可')) {
$arrayData[$BillNo][9] = $PayAmount;
} else {
$arrayData[$BillNo][12] = $PayAmount;
}
} else {
$arrayData[$BillNo] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
$arrayData[$BillNo][3] = $partnerName;
$arrayData[$BillNo][13] = $EnterpriseName;
$arrayData[$BillNo][14] = $TaxNo;
$arrayData[$BillNo][15] = $ContactAddress;
if (stristr($PayStage, '二次款') || stristr($PayStage, '出貨前') || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60')) {
$arrayData[$BillNo][5] = $PayAmount;
} elseif ($PayStage == '簽約' || stristr($PayStage, '簽定') || stristr($PayStage, '簽訂') || stristr($PayStage, '訂金')) {
$arrayData[$BillNo][4] = $PayAmount;
} elseif (stristr($PayStage, '貨抵工地') || stristr($PayStage, '貨底工地')) {
$arrayData[$BillNo][6] = $PayAmount;
} elseif (stristr($PayStage, '試車') || stristr($PayStage, '驗收完成')) {
$arrayData[$BillNo][8] = $PayAmount;
} elseif (stristr($PayStage, '安裝')) {
$arrayData[$BillNo][7] = $PayAmount;
} elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月') || stristr($PayStage, '交車')) {
$arrayData[$BillNo][10] = $PayAmount;
} elseif (stristr($PayStage, '合格') || stristr($PayStage, '驗收') || stristr($PayStage, '許可') || stristr($PayStage, '核可')) {
$arrayData[$BillNo][9] = $PayAmount;
} else {
$arrayData[$BillNo][12] = $PayAmount;
}
}
}
foreach ($arrayData as $key => $value) {
$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.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.contractno='" . $key . "'" . "
)AS tmp2
left join (
SELECT DISTINCT
department_id,
name
FROM department
) AS d
ON d.department_id = tmp2.department_id";
$facitities = "";
$total_facility_num = 0;
$arrive_num = 0;
$tryrun_num = 0;
$delivery_num = 0;
$official_num = 0;
$wipwhole_array = mysqli_query($link, $sql);
foreach ($wipwhole_array as $wip) {
$value[0] = $wip['depart_name'];
$value[1] = $wip['manager_name'];
$value[2] = $wip['name'];
if ($wip['delivery_date'] != NULL) {
$facitities .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) <br>";
$total_facility_num += 1;
$arrive_num += 1;
$tryrun_num += 1;
$official_num += 1;
$delivery_num += 1;
} elseif ($wip['official_check_date'] != NULL) {
$facitities .= $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) <br>";
$total_facility_num += 1;
$arrive_num += 1;
$tryrun_num += 1;
$official_num += 1;
} elseif ($wip['tryrun_end_date'] != NULL) {
$facitities .= $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢) <br>";
$total_facility_num += 1;
$arrive_num += 1;
$tryrun_num += 1;
} elseif ($wip['install_end_date'] != NULL) {
$facitities .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) <br>";
$total_facility_num += 1;
$arrive_num += 1;
} elseif ($wip['real_arrival_date'] != NULL) {
$facitities .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) <br>";
$total_facility_num += 1;
$arrive_num += 1;
} elseif ($wip['actual_tofactory_date'] != NULL) {
$facitities .= $wip['facilityno'] . " (" . $wip['actual_tofactory_date'] . "實際到觀音日) <br>";
$total_facility_num += 1;
} elseif ($wip['estimated_shipping_date'] != NULL) {
$facitities .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計到港) <br>";
$total_facility_num += 1;
} else {
$facitities .= $wip['facilityno'] . " (預計到港日待確認) <br>";
$total_facility_num += 1;
}
}
$receivable_budget=0;
//這是錢 4 簽約 5 二次款 6 貨抵工地 7 安裝 8 試車 9官檢 10 交車
//這是數量 arrive_num 貨抵工地 tryrun_num 試車安裝完畢 official_num 官檢完畢 delivery_num 移交
if ($total_facility_num > 0) {
$receivable_budget = $value[4] + ($value[5] + $value[6]) * ($arrive_num / $total_facility_num) +
($value[7] + $value[8]) * ($tryrun_num / $total_facility_num) + ($value[9]) * ($official_num / $total_facility_num)
+ ($value[10]) * ($delivery_num / $total_facility_num);
}
// array_push($receivable_array, [$key, $value[0], $value[1], $value[2], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8], $value[9], $value[10], $receivable_budget, $facitities]);
$receivable_array[$key] = [$key, $value[0], $value[1], $value[2], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8], $value[9], $value[10], $receivable_budget, $facitities, $value[13],$value[14],$value[15]];
// echo $key . ";" . $value[0] . ";" . $value[1] . ";" . $value[2] . ";" . $value[3] . ";" . $value[4] . ";" . $value[5] . ";" . $value[6] . ";" . $value[7] . ";" . $value[8] . ";" . $value[9].";" . $value[10] . ";" . $receivable_budget . ";" . $total_facility_num . ";" . $arrive_num . ";". $tryrun_num . ";" .$official_num.";". $delivery_num . ";" . $facitities . "<br>";
}
$data = json_encode($receivable_array);
// echo "合約號;部門;經理;營業員;客戶名稱;簽約款;二次款;貨抵工地款;安裝款;試車款;官檢款;交車款;目前應收;總作番數;貨抵;安裝試車;官檢;移交數;狀態</br>";
?>
<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 style="width:98%;margin:1%">
<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: 150px;">目前應收</th>
<th>狀態</th>
<th style="width: 100px;">操作</th>
</tr>
</thead>
<tbody>
<?php
foreach ($receivable_array as $contract) {
?>
<tr>
<th><?= $contract[0] ?></th>
<td><?= $contract[1] ?></td>
<td><?= $contract[2] ?></td>
<td><?= $contract[3] ?></td>
<td><?= $contract[4] ?></td>
<!-- <td><?= round($contract[5]) ?></td>
<td><?= round($contract[6]) ?></td>
<td><?= round($contract[7]) ?></td>
<td><?= round($contract[8]) ?></td>
<td><?= round($contract[9]) ?></td>
<td><?= round($contract[10]) ?></td>
<td><?= round($contract[11]) ?></td> -->
<td><?= number_format(round($contract[12])) ?></td>
<td style="text-align: start;"><?= $contract[13] ?></td>
<td><button type="button" onclick="sendData('<?= $contract[0] ?>')" class="btn btn-primary btn-sm"><span class=" glyphicon glyphicon-search"></span></button>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<script>
function sendData(BillNo) {
console.log(BillNo);
var BillData = <?= $data ?>;
var Bill = BillData[BillNo];
console.log(Bill);
console.log(typeof(Bill));
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>