Browse Source

Merge branch 'kaiyu'

gary
Ellin 1 year ago
parent
commit
0c1d041458
  1. 46
      wms/account-receivable-excel.php
  2. 190
      wms/account-receivable-index.php
  3. BIN
      wms/account-receivable.xlsx

46
wms/account-receivable-excel.php

@ -0,0 +1,46 @@
<?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){
for ($i = 0; $i < 17; $i++) {
$value[$i] = (isset($value[$i])) ? $value[$i] : 0;
}
$array_data[$key][0] = $value[0];
$array_data[$key][1] = $value[1];
$array_data[$key][2] = $value[2];
$array_data[$key][3] = $value[3];
$array_data[$key][4] = $value[4];
$array_data[$key][5] = $value[15];
$array_data[$key][6] = $value[16];
$array_data[$key][7] = $value[14];
$array_data[$key][8] = $value[5];
$array_data[$key][9] = $value[6];
$array_data[$key][10] = $value[7];
$array_data[$key][11] = $value[8];
$array_data[$key][12] = $value[9];
$array_data[$key][13] = $value[10];
$array_data[$key][14] = $value[11];
$array_data[$key][15] = $value[12];
$array_data[$key][16] = str_replace('<br>','\n',$value[13]);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$colomnHeader = ['合約號','部門','經理','營業員','客戶名稱','統一編號','聯絡地址','抬頭','簽約款',
'二次款','貨抵工地款','安裝款','試車款','官檢款','交車款','目前應收','作番狀態'];
$sheet->fromArray($colomnHeader,NULL,'A1');
$rowIndex = 2;
foreach($array_data as $key => $value){
$sheet->fromArray([$value], NULL, 'A' . $rowIndex);
$rowIndex++;
}
$writer = new Xlsx($spreadsheet);
$excelFileName = 'account-receivable.xlsx';
$writer->save($excelFileName);
echo "Excel 文件已生成:{$excelFileName}";
?>

190
wms/account-receivable-index.php

@ -121,7 +121,8 @@ foreach ($contract as $cont) {
} }
foreach ($arrayData as $key => $value) { foreach ($arrayData as $key => $value) {
$sql = "SELECT if (array_key_exists($key, $arrayData) && isset($arrayData[$key])) {
$sql = "SELECT
tmp2.*, tmp2.*,
d.name AS depart_name d.name AS depart_name
FROM( FROM(
@ -156,94 +157,97 @@ FROM department
) AS d ) AS d
ON d.department_id = tmp2.department_id"; ON d.department_id = tmp2.department_id";
$facitities = ""; $facitities = "";
$total_facility_num = 0; $total_facility_num = 0;
$arrive_num = 0; $arrive_num = 0;
$tryrun_num = 0; $tryrun_num = 0;
$delivery_num = 0; $delivery_num = 0;
$official_num = 0; $official_num = 0;
$wipwhole_array = mysqli_query($link, $sql); $value[16]='';
foreach ($wipwhole_array as $wip) { $value[17]='';
$value[0] = $wip['depart_name']; $wipwhole_array = mysqli_query($link, $sql);
$value[1] = $wip['manager_name']; foreach ($wipwhole_array as $wip) {
$value[2] = $wip['name']; $value[0] = $wip['depart_name'];
$value[16] = isset($wip['department_id']) ? $wip['department_id'] : ''; $value[1] = $wip['manager_name'];
$value[17] = isset($wip['salesid']) ? $wip['salesid'] : ''; $value[2] = $wip['name'];
if ($wip['delivery_date'] != NULL) { $value[16] = is_null($wip['department_id']) ? '' : $wip['department_id'];
$facitities .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) <br>"; $value[17] = is_null($wip['salesid']) ? '' : $wip['salesid'];
$total_facility_num += 1; if ($wip['delivery_date'] != NULL) {
$arrive_num += 1; $facitities .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交) <br>";
$tryrun_num += 1; $total_facility_num += 1;
$official_num += 1; $arrive_num += 1;
$delivery_num += 1; $tryrun_num += 1;
} elseif ($wip['official_check_date'] != NULL) { $official_num += 1;
$facitities .= $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) <br>"; $delivery_num += 1;
$total_facility_num += 1; } elseif ($wip['official_check_date'] != NULL) {
$arrive_num += 1; $facitities .= $wip['facilityno'] . " (" . $wip['official_check_date'] . "官檢完畢) <br>";
$tryrun_num += 1; $total_facility_num += 1;
$official_num += 1; $arrive_num += 1;
} elseif ($wip['tryrun_end_date'] != NULL) { $tryrun_num += 1;
$facitities .= $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢) <br>"; $official_num += 1;
$total_facility_num += 1; } elseif ($wip['tryrun_end_date'] != NULL) {
$arrive_num += 1; $facitities .= $wip['facilityno'] . " (" . $wip['tryrun_end_date'] . "試車完畢) <br>";
$tryrun_num += 1; $total_facility_num += 1;
} elseif ($wip['install_end_date'] != NULL) { $arrive_num += 1;
$facitities .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) <br>"; $tryrun_num += 1;
$total_facility_num += 1; } elseif ($wip['install_end_date'] != NULL) {
$arrive_num += 1; $facitities .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢) <br>";
} elseif ($wip['real_arrival_date'] != NULL) { $total_facility_num += 1;
$facitities .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) <br>"; $arrive_num += 1;
$total_facility_num += 1; } elseif ($wip['real_arrival_date'] != NULL) {
$arrive_num += 1; $facitities .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地) <br>";
} elseif ($wip['actual_tofactory_date'] != NULL) { $total_facility_num += 1;
$facitities .= $wip['facilityno'] . " (" . $wip['actual_tofactory_date'] . "實際到觀音日) <br>"; $arrive_num += 1;
$total_facility_num += 1; } elseif ($wip['actual_tofactory_date'] != NULL) {
} elseif ($wip['estimated_shipping_date'] != NULL) { $facitities .= $wip['facilityno'] . " (" . $wip['actual_tofactory_date'] . "實際到觀音日) <br>";
$facitities .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計到港) <br>"; $total_facility_num += 1;
$total_facility_num += 1; } elseif ($wip['estimated_shipping_date'] != NULL) {
} else { $facitities .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計到港) <br>";
$facitities .= $wip['facilityno'] . " (預計到港日待確認) <br>"; $total_facility_num += 1;
$total_facility_num += 1; } else {
$facitities .= $wip['facilityno'] . " (預計到港日待確認) <br>";
$total_facility_num += 1;
}
} }
} $receivable_budget = 0;
$receivable_budget = 0; //這是錢 4 簽約 5 二次款 6 貨抵工地 7 安裝 8 試車 9官檢 10 交車
//這是錢 4 簽約 5 二次款 6 貨抵工地 7 安裝 8 試車 9官檢 10 交車 //這是數量 arrive_num 貨抵工地 tryrun_num 試車安裝完畢 official_num 官檢完畢 delivery_num 移交
//這是數量 arrive_num 貨抵工地 tryrun_num 試車安裝完畢 official_num 官檢完畢 delivery_num 移交 if ($total_facility_num > 0) {
if ($total_facility_num > 0) { $receivable_budget = $value[4] + ($value[5] + $value[6]) * ($arrive_num / $total_facility_num) +
$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[7] + $value[8]) * ($tryrun_num / $total_facility_num) + ($value[9]) * ($official_num / $total_facility_num) + ($value[10]) * ($delivery_num / $total_facility_num);
+ ($value[10]) * ($delivery_num / $total_facility_num);
$uninvoice_budget = $receivable_budget;
$unreceived_budget = $receivable_budget;
$received_invoice = 0;
$received_budget = 0;
if (isset($received_array[$key][0])) {
$uninvoice_budget = $receivable_budget - $received_array[$key][0];
$received_invoice = $received_array[$key][0];
} else {
$uninvoice_budget = $receivable_budget; $uninvoice_budget = $receivable_budget;
}
if (isset($received_array[$key][1])) {
$unreceived_budget = $receivable_budget - $received_array[$key][1];
$received_budget = $received_array[$key][1];
} else {
$unreceived_budget = $receivable_budget; $unreceived_budget = $receivable_budget;
$received_invoice = 0;
$received_budget = 0;
if (isset($received_array[$key][0])) {
$uninvoice_budget = $receivable_budget - $received_array[$key][0];
$received_invoice = $received_array[$key][0];
} else {
$uninvoice_budget = $receivable_budget;
}
if (isset($received_array[$key][1])) {
$unreceived_budget = $receivable_budget - $received_array[$key][1];
$received_budget = $received_array[$key][1];
} else {
$unreceived_budget = $receivable_budget;
}
if (isset($received_array[$key][2])) {
$status = $received_array[$key][2];
} else {
$status = 0;
}
} }
if (isset($received_array[$key][2])) {
$status = $received_array[$key][2]; if (isset($key)) {
} else { $receivable_array[$key] = [
$status = 0; $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], $value[16], $value[17], $received_invoice, $received_budget,
$uninvoice_budget, $unreceived_budget, $status
];
} }
}
if (isset($key)) {
$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], $value[16], $value[17], $received_invoice, $received_budget,
$uninvoice_budget, $unreceived_budget, $status
];
} }
} }
$data = json_encode($receivable_array); $data = json_encode($receivable_array);
@ -353,13 +357,29 @@ $data = json_encode($receivable_array);
</table> </table>
</div> </div>
<script> <script>
// function sendData(BillNo) {
// console.log(BillNo);
// var BillData = <?= $data ?>;
// var Bill = BillData[BillNo];
// var form = document.createElement("form");
// form.method = 'POST';
// form.action = "account-receivable-excel.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();
// }
function sendData(BillNo) { function sendData(BillNo) {
console.log(BillNo);
var BillData = <?= $data ?>; var BillData = <?= $data ?>;
var Bill = BillData[BillNo]; var Bill = BillData;
var form = document.createElement("form"); var form = document.createElement("form");
form.method = 'POST'; form.method = 'POST';
form.action = "account-receivable-check.php?<?= $token_link ?>"; form.action = "account-receivable-excel.php?<?= $token_link ?>";
var input = document.createElement("input"); var input = document.createElement("input");
input.type = "hidden"; input.type = "hidden";
input.name = "Bill"; input.name = "Bill";

BIN
wms/account-receivable.xlsx

Binary file not shown.
Loading…
Cancel
Save