10994015 1 year ago
parent
commit
737b616831
  1. 1
      .gitignore
  2. 133
      app/app-wipproduction-log.php
  3. 2
      app/db/database.php
  4. BIN
      wms/WriteOff.xlsx
  5. BIN
      wms/account-receivable-.xlsx
  6. 160
      wms/account-receivable-check.php
  7. 63
      wms/account-receivable-excel.php
  8. 351
      wms/account-receivable-index.php
  9. 3
      wms/account-receivable-test.php
  10. BIN
      wms/account-receivable-test.xlsx
  11. BIN
      wms/account-receivable.xlsx
  12. 35
      wms/assemble_warehouse.php
  13. BIN
      wms/assemble_warehouse.xlsx
  14. BIN
      wms/assemlbe_warehouse.xlsx
  15. 7
      wms/header.php

1
.gitignore

@ -24,3 +24,4 @@ wms/excel/estimated_shipping_date_report.xlsx
wms/mkt/WriteOffRepair.xlsx
wms/contract/images/contracts
wms/test.php
app/account_log/

133
app/app-wipproduction-log.php

@ -23,7 +23,107 @@ $data = array(); # 設置一個空陣列來放資料is
if ($user_id == 'A000000001') {
$sql = "SELECT * FROM wipproduction where (facilityno = '$facilityno') order by id desc"; # sql語法存在變數中
} else {
$sql = "
if (in_array($facilityno, [
'3JX01701', '3JX01702', '3JX01703', '3JX01704', '3JX01705', '3JX01706', '3JX01707', '3JX01708', '3JX01709', '3JX01710', '3JX01711'
])) {
$sql = "
SELECT
'0' AS id,
facilityno,
'2024-06-30' AS issue_time,
'生產中' AS 'process',
'bg-success' AS 'light_color',
'' AS memo,
creater,
create_at
FROM wipwholestatus
WHERE facilityno = '$facilityno'
UNION
SELECT
'1' AS id,
facilityno,
SUBSTR(estimated_shipping_date,1,10) AS issue_time,
'生產完成' AS 'process',
'bg-success' AS 'light_color',
'' AS memo,
creater,
create_at
FROM wipwholestatus
WHERE facilityno = '$facilityno'
AND estimated_shipping_date != ''
AND estimated_shipping_date IS NOT NULL
UNION
SELECT
'2' AS id,
facilityno,
SUBSTR(estimated_shipping_schedule_date,1,10) AS issue_time,
'預計攬收' AS 'process',
'bg-success' AS 'light_color',
'' AS memo,
creater,
create_at
FROM wipwholestatus
WHERE facilityno = '$facilityno'
AND estimated_shipping_schedule_date != ''
AND estimated_shipping_schedule_date IS NOT NULL
UNION
SELECT
'3' AS id,
facilityno,
SUBSTR(actual_tofactory_date,1,10) AS issue_time,
'攬收成功(桃園)' AS 'process',
'bg-success' AS 'light_color',
'' AS memo,
creater,
create_at
FROM wipwholestatus
WHERE facilityno = '$facilityno'
AND actual_tofactory_date != ''
AND actual_tofactory_date IS NOT NULL
UNION
SELECT
'4' AS id,
facilityno,
'2023-05-10' AS issue_time,
'預計出貨日' AS 'process',
'bg-success' AS 'light_color',
'' AS memo,
creater,
create_at
FROM wipwholestatus
WHERE facilityno = '$facilityno'
AND real_contract_arrival_date != ''
AND real_contract_arrival_date IS NOT NULL
UNION
SELECT
'5' AS id,
facilityno,
SUBSTR(real_arrival_date,1,10) AS issue_time,
'出貨' AS 'process',
'bg-success' AS 'light_color',
'' AS memo,
creater,
create_at
FROM wipwholestatus
WHERE facilityno = '$facilityno'
AND real_arrival_date != ''
AND real_arrival_date IS NOT NULL
ORDER BY id DESC
";
} else {
$sql = "
SELECT
'0' AS id,
facilityno,
@ -206,6 +306,7 @@ if ($user_id == 'A000000001') {
ORDER BY id DESC
";
}
}
$data = mysqli_query($link, $sql); # 用mysqli_query方法執行(sql語法)將結果存在變數中
@ -249,22 +350,22 @@ include "include-header.php";
$j = $j + 1;
// if (!empty($data['issue_time'])) {
?>
<div class="item">
<span class="time"><?php echo $data['issue_time']; ?></span>
<?php
// if ($j == 1) {
// echo "<div class='dot bg-warning'></div>";
// } else {
// echo "<div class='dot'></div>";
// }
?>
<div class="dot <?php echo $data['light_color']; ?>"></div>
<div class="content">
<h4 class="title"><?php echo $data['process']; ?></h4>
<div class="text"><?php echo $data['memo']; ?></div>
</div>
<div class="item">
<span class="time"><?php echo $data['issue_time']; ?></span>
<?php
// if ($j == 1) {
// echo "<div class='dot bg-warning'></div>";
// } else {
// echo "<div class='dot'></div>";
// }
?>
<div class="dot <?php echo $data['light_color']; ?>"></div>
<div class="content">
<h4 class="title"><?php echo $data['process']; ?></h4>
<div class="text"><?php echo $data['memo']; ?></div>
</div>
<!--
</div>
<!--
<div class="item">
<span class="time">09-01 17:34</span>
<div class="dot"></div>

2
app/db/database.php

@ -1,5 +1,5 @@
<?php
$envFile = __DIR__ . '/../.env'; // .env 文件的路径
$envFile = dirname(dirname(dirname(__FILE__))) . '\.env'; // .env 文件的路径
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

BIN
wms/WriteOff.xlsx

Binary file not shown.

BIN
wms/account-receivable-.xlsx

Binary file not shown.

160
wms/account-receivable-check.php

@ -2,35 +2,7 @@
include "./header.php";
$Bill = $_POST['Bill'];
$Bill = json_decode($Bill, true);
print_r($Bill);
// $sql_received = "SELECT * from account_received where BillNo = '$Bill[0]' ORDER BY `pay_id` ASC";
// $pay_received = mysqli_query($link, $sql_received);
// $had_received_amount = intval(0);
// $had_invoice_amount=intval(0);
// $status_summary = intval(0);
// if (mysqli_num_rows($pay_received) > 0) {
// foreach ($pay_received as $received) {
// $had_received_amount += intval($received['received_amount']);
// $had_invoice_amount += intval($received['invoice_amount']);
// if(in_array(intval($received['status']),array(0,4,5,99))){
// $tem_status = intval(0);
// }else{
// $tem_status = intval($received['status']);
// }
// if($status_summary < $tem_status){
// $status_summary = $tem_status;
// }
// }
// }
// $unreceived_amount = intval($Bill[12]) - intval($had_received_amount);
// $uninvoice_amount = intval($Bill[12]) - intval($had_invoice_amount);
// $Bill[19] =$had_invoice_amount;
// $Bill[20] =$had_received_amount;
// $Bill[21] =$uninvoice_amount;
// $Bill[22] =$unreceived_amount;
// $Bill[23] =$status_summary;
$data = json_encode($Bill);
?>
<style>
@ -53,7 +25,7 @@ $data = json_encode($Bill);
</div>
<div class="container">
<div class="text-center" style="margin-bottom: 20px;">
<h3><strong><?= $Bill[4] ?></strong></h3>
<h3><strong><?= $Bill[5] ?></strong></h3>
</div>
<form class="form-horizontal">
<div class="form-group">
@ -98,32 +70,7 @@ $data = json_encode($Bill);
<table class="table table-striped table-bordered" style="width:100%;">
<thead>
<tr>
<th>目前應收</th>
<!-- <th>已開發票金額</th>
<th>未開發票金額</th>
<th>已收金額</th>
<th>未收金額</th> -->
</tr>
</thead>
<tbody>
<tr>
<td><?= number_format(round($Bill['receivable_budget'])) ?></td>
<!-- <td><?= number_format(round($Bill[19])) ?></td>
<td><?= number_format(round($Bill[21])) ?></td>
<td><?= number_format(round($Bill[20])) ?></td>
<td><?= number_format(round($Bill[22])) ?></td> -->
</tr>
</tbody>
</table>
</div>
<div style="width: auto; margin-top: 30px;">
<table class="table table-striped table-bordered" style="width:100%;">
<thead>
<tr>
<th></th>
<th>簽約款</th>
<th>二次款</th>
<th>貨抵工地款</th>
@ -137,6 +84,7 @@ $data = json_encode($Bill);
</thead>
<tbody>
<tr>
<td>合約金額</td>
<td><?= number_format(round($Bill['sign'][1])) ?></td>
<td><?= number_format(round($Bill['second'][1])) ?></td>
<td><?= number_format(round($Bill['arrive'][1])) ?></td>
@ -145,10 +93,47 @@ $data = json_encode($Bill);
<td><?= number_format(round($Bill['check'][1])) ?></td>
<td><?= number_format(round($Bill['delivery'][1])) ?></td>
<td><?= number_format(round($Bill['final'][1])) ?></td>
</tr>
<tr>
<td>目前應收</td>
<td><?= number_format(round($Bill['sign'][3])) ?></td>
<td><?= number_format(round($Bill['second'][3])) ?></td>
<td><?= number_format(round($Bill['arrive'][3])) ?></td>
<td><?= number_format(round($Bill['install'][3])) ?></td>
<td><?= number_format(round($Bill['tryrun'][3])) ?></td>
<td><?= number_format(round($Bill['check'][3])) ?></td>
<td><?= number_format(round($Bill['delivery'][3])) ?></td>
<td><?= number_format(round($Bill['final'][3])) ?></td>
</tr>
</tbody>
</table>
<div style="width: auto; margin-top: 30px;">
<table class="table table-striped table-bordered" style="width:100%;">
<thead>
<tr>
<th>目前應收</th>
<th>已開發票金額</th>
<th>未開發票金額</th>
<th>已收金額</th>
<th>未收金額</th>
</tr>
</thead>
<tbody>
<tr>
<td><?= number_format(round($Bill['receivable_budget'])) ?></td>
<td><?= number_format(round($Bill['invoice_budget'])) ?></td>
<td><?= number_format(round($Bill['receivable_budget'] - $Bill['invoice_budget'])) ?></td>
<td><?= number_format(round($Bill['received_budget'])) ?></td>
<td><?= number_format(round($Bill['invoice_budget'] - $Bill['received_budget'])) ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<?php
@ -158,8 +143,8 @@ include "./footer.php";
<?php
if ((accountidToDepartId($user_id) == '220') || ($user_id == "M0209")) {
?>
<button type="button" onclick="create('create',0)" class="btn btn-primary btn-sm pull-right" style="margin-right: 10%;margin-bottom: 10px;">
新增收款紀錄<span class=" glyphicon glyphicon-plus"></span></button>
<!-- <button type="button" onclick="create('create',0)" class="btn btn-primary btn-sm pull-right" style="margin-right: 10%;margin-bottom: 10px;">
新增收款紀錄<span class=" glyphicon glyphicon-plus"></span></button> -->
<?php
}
?>
@ -167,29 +152,42 @@ if ((accountidToDepartId($user_id) == '220') || ($user_id == "M0209")) {
<table class="table table-striped table-bordered" style="width:100%;">
<thead>
<tr>
<th>發票號碼</th>
<th>發票日期</th>
<th>發票狀態</th>
<th>發票金額</th>
<th>發票號碼</th>
<th>收款日期</th>
<th>收款金額</th>
<th>備註</th>
<th>狀態</th>
<?php if ((accountidToDepartId($user_id) == '220') || ($user_id == "M0209")) { ?>
<th style="width: 10%;">功能</th>
<?php } ?>
<th>內含手續費</th>
<!-- <th>備註</th>
<th>狀態</th> -->
</tr>
</thead>
<tbody>
<?php if ($pay_received) {
foreach ($pay_received as $received) { ?>
<?php if ($Bill['invoice'] != Null) {
foreach ($Bill['invoice'] as $key => $invoice) { ?>
<tr>
<td><?= $received['invoice_date'] ?></td>
<td><?= number_format($received['invoice_amount']) ?></td>
<td><?= $received['invoice_no'] ?></td>
<td><?= $received['received_date'] ?></td>
<td><?= number_format($received['received_amount']) ?></td>
<td><?= $received['remark'] ?></td>
<td><?= $key ?></td>
<td><?= $invoice[0] ?></td>
<td><?php switch ($invoice[2]) {
case 0:
echo "藍字";
break;
case 1:
echo "紅字";
break;
case 2:
echo "作廢";
break;
} ?></td>
<td><?= isset($invoice[1])? number_format($invoice[1]):0 ?></td>
<td><?= isset($invoice[3])? $invoice[3]:' ' ?></td>
<td><?= isset($invoice[4])? number_format($invoice[4]):0 ?></td>
<td><?= isset($invoice[5])? number_format($invoice[5]):0 ?></td>
<!-- <td><?= $received['remark'] ?></td>
<td style="text-align: center;">
<?php
switch ($received['status']) {
@ -215,21 +213,13 @@ if ((accountidToDepartId($user_id) == '220') || ($user_id == "M0209")) {
echo "完成";
break;
}
?></td>
<?php if ((accountidToDepartId($user_id) == '220') || ($user_id == "M0209")) { ?>
<td>
<button type="button" onclick="create('edit',<?= $received['pay_id'] ?>)" class="btn btn-warning btn-sm pull-right" style="margin-right: 10%;margin-bottom: 10px;">
<span class="glyphicon glyphicon-pencil"></span></button>
<!-- <a href="account-receivable-received-delete.php?id=<?php echo $received['pay_id'] ?>&<?= $token_link ?>" class="btn btn-danger btn-sm">
<span class=" glyphicon glyphicon-trash"></span>
</a> -->
</td>
<?php } ?>
?></td> -->
</tr>
<?php }
} ?>
}
?>
</tbody>
</table>
</div>

63
wms/account-receivable-excel.php

@ -1,51 +1,58 @@
<?php
include "./header.php";
require_once dirname(__DIR__) . '/common/composer/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$Bill = $_POST['Bill'];
$array_data = array();
$Bill = json_decode($Bill, true);
foreach($Bill as $key=>$value){
foreach ($Bill as $key => $value) {
// for ($i = 0; $i < 17; $i++) {
// $value[$i] = (isset($value[$i])) ? $value[$i] : 0;
// }
$array_data[$key][0] = $key;
$array_data[$key][1] = $value[1];
$array_data[$key][2] = $value[2];
$array_data[$key][3] = $value[4];
$array_data[$key][4] = $value[5];
$array_data[$key][5] = $value[7];
$array_data[$key][6] = $value[8];
$array_data[$key][7] = $value[6];
$array_data[$key][8] = $value['sign'][1];
$array_data[$key][9] = $value['second'][1];
$array_data[$key][10] = $value['arrive'][1];
$array_data[$key][11] = $value['install'][1];
$array_data[$key][12] = $value['tryrun'][1];
$array_data[$key][13] = $value['check'][1];
$array_data[$key][14] = $value['delivery'][1];
$array_data[$key][15] = $value['final'][1];
$array_data[$key][16] = $value['receivable_budget'];
$array_data[$key][17] = str_replace('<br>','; ',$value['facilities']);
$value['sign'][3] = (isset($value['sign'][3])) ? $value['sign'][3] : 0;
$value['second'][3] = (isset($value['second'][3])) ? $value['second'][3] : 0;
$value['arrive'][3] = (isset($value['arrive'][3])) ? $value['arrive'][3] : 0;
$value['install'][3] = (isset($value['install'][3])) ? $value['install'][3] : 0;
$value['tryrun'][3] = (isset($value['tryrun'][3])) ? $value['tryrun'][3] : 0;
$value['check'][3] = (isset($value['check'][3])) ? $value['check'][3] : 0;
$value['delivery'][3] = (isset($value['delivery'][3])) ? $value['delivery'][3] : 0;
$value['final'][3] = (isset($value['final'][3])) ? $value['final'][3] : 0;
$array_data[$key] = [
$key, $value[1], $value[2], $value[4], $value[5], $value[7], $value[8], $value[6],
$value['sign'][1], $value['second'][1], $value['arrive'][1], $value['install'][1], $value['tryrun'][1], $value['check'][1], $value['delivery'][1], $value['final'][1],
$value['sign'][3], $value['second'][3], $value['arrive'][3], $value['install'][3], $value['tryrun'][3], $value['check'][3], $value['delivery'][3], $value['final'][3],
$value['receivable_budget'], $value['invoice_budget'], $value['received_budget'], str_replace('<br>', '; ', $value['facilities'])
];
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$colomnHeader = ['合約號','部門','經理','營業員','客戶名稱','統一編號','聯絡地址','抬頭','簽約款',
'二次款','貨抵工地款','安裝款','試車款','官檢款','交車款','尾款','目前應收','作番狀態'];
$sheet->fromArray($colomnHeader,NULL,'A1');
$colomnHeader = [
'合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭',
'簽約款', '二次款', '貨抵工地款', '安裝款', '試車款', '官檢款', '交車款', '尾款',
'目前應收簽約款', '目前應收二次款', '目前應收貨抵工地款', '目前應收安裝款', '目前應收試車款', '目前應收官檢款', '目前應收交車款', '目前應收尾款',
'目前應收', '已開發票金額', '已收金額', '作番狀態'
];
$sheet->fromArray($colomnHeader, NULL, 'A1');
$rowIndex = 2;
foreach($array_data as $key => $value){
foreach ($array_data as $key => $value) {
$sheet->fromArray([$value], NULL, 'A' . $rowIndex);
$sheet->getStyle('R' . $rowIndex)->getAlignment()->setWrapText(true);
$sheet->getStyle('AB' . $rowIndex)->getAlignment()->setWrapText(true);
$column = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA'];
foreach($column as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}
$rowIndex++;
}
$writer = new Xlsx($spreadsheet);
$excelFileName = 'account-receivable.xlsx';
$excelFileName = 'account-receivable-test.xlsx';
$writer->save($excelFileName);
echo $excelFileName;
?>
<script>
<!-- <script>
window.location.href = "account-receivable-index.php?<?= $token_link ?>";
</script>
</script> -->

351
wms/account-receivable-index.php

@ -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];

3
wms/account-receivable-test.php

@ -0,0 +1,3 @@
<?php
$test = [8,9,3,4];
echo min($test);

BIN
wms/account-receivable-test.xlsx

Binary file not shown.

BIN
wms/account-receivable.xlsx

Binary file not shown.

35
wms/assemble_warehouse.php

@ -0,0 +1,35 @@
<?php
include "./header.php";
require_once dirname(__DIR__) . '/common/composer/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$sql = "SELECT
A.BillNo,A.MaterialId, C.MaterialName,A.Quantity,A.UnConfirmSQty,A.WarehouseId,A.MarkerNo,A.CU_MaterialId,
B.Quantity AS StkQty,B.WarehouseId AS StkWarehouseId,B.MarkerNo AS StkMarkerNo
FROM stkAssySubMatInfo A
LEFT JOIN stkWareHouseAccountDetail B ON A.MaterialId = B.MaterialId AND A.MarkerNo = B.MarkerNo
LEFT JOIN comMaterialGroup AS C ON A.MaterialId = C.MaterialId
WHERE A.UnConfirmSQty != 0";
$assemble_warehouse_query = $conn->query($sql);
$array =array();
echo "組裝單號;組裝料號;組裝數量;未出庫數量;目前庫存倉別;組裝子件預留標示號;庫存數量;庫存倉別;庫存預留標示號"."<br>";
foreach($assemble_warehouse_query as $key=> $assemble){
$array[$key] = [$assemble['BillNo'],$assemble['MaterialId'],$assemble['MaterialName'],$assemble['Quantity'],$assemble['UnConfirmSQty'],$assemble['WarehouseId'],$assemble['MarkerNo'],$assemble['StkQty'],$assemble['StkWarehouseId'],$assemble['StkMarkerNo']];
// echo $assemble['BillNo'].";".$assemble['MaterialId'].";".$assemble['Quantity'].";".$assemble['UnConfirmSQty'].";".$assemble['WarehouseId'].";".$assemble['MarkerNo'].";".$assemble['StkQty'].";".$assemble['StkWarehouseId'].";".$assemble['StkMarkerNo'];
// echo "<br>";
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$colomnHeader = ['組裝單號','組裝料號','料號名稱','組裝數量','未出庫數量','目前庫存倉別','組裝子件預留標示號','庫存數量','庫存倉別','庫存預留標示號'];
$sheet->fromArray($colomnHeader,NULL,'A1');
$rowIndex = 2;
foreach($array as $key => $value){
$sheet->fromArray([$value], NULL, 'A' . $rowIndex);
$sheet->getStyle('R' . $rowIndex)->getAlignment()->setWrapText(true);
$rowIndex++;
}
$writer = new Xlsx($spreadsheet);
$excelFileName = 'assemble_warehouse.xlsx';
$writer->save($excelFileName);

BIN
wms/assemble_warehouse.xlsx

Binary file not shown.

BIN
wms/assemlbe_warehouse.xlsx

Binary file not shown.

7
wms/header.php

@ -6,6 +6,11 @@
// $maintenancePeriod = "2023-11-17 15:30 AM 至 17:30 PM";
// $maintenancePage = new MaintenancePage($maintenancePeriod);
// $maintenancePage->displayPage();
header("Expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
function CreateToken($user_id, $user_name)
{
@ -56,6 +61,7 @@ try {
*****************************/
$token = isset($_REQUEST["token"]) ? $_REQUEST["token"] : "";
if (count(explode(".", $token)) > 1) {
$token_link = "token=" . $_REQUEST["token"];
list($user_id, $enc_user_name, $login_dt) = explode(".", $token);
@ -85,6 +91,7 @@ if (count(explode(".", $token)) > 1) {
}
}
include 'IncludeCommon.php';
$includecommon = new IncludeCommon();
$accounttype = getAccounttype($link, $user_id);

Loading…
Cancel
Save