diff --git a/wms/account-receivable-excel.php b/wms/account-receivable-excel.php
new file mode 100644
index 00000000..72f0ead9
--- /dev/null
+++ b/wms/account-receivable-excel.php
@@ -0,0 +1,46 @@
+$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('
','\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}";
+?>
\ No newline at end of file
diff --git a/wms/account-receivable-index.php b/wms/account-receivable-index.php
index e33f2b75..945d4adb 100644
--- a/wms/account-receivable-index.php
+++ b/wms/account-receivable-index.php
@@ -121,7 +121,8 @@ foreach ($contract as $cont) {
}
foreach ($arrayData as $key => $value) {
- $sql = "SELECT
+ if (array_key_exists($key, $arrayData) && isset($arrayData[$key])) {
+ $sql = "SELECT
tmp2.*,
d.name AS depart_name
FROM(
@@ -156,94 +157,97 @@ 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'];
- $value[16] = isset($wip['department_id']) ? $wip['department_id'] : '';
- $value[17] = isset($wip['salesid']) ? $wip['salesid'] : '';
- if ($wip['delivery_date'] != NULL) {
- $facitities .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交)
";
- $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'] . "官檢完畢)
";
- $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'] . "試車完畢)
";
- $total_facility_num += 1;
- $arrive_num += 1;
- $tryrun_num += 1;
- } elseif ($wip['install_end_date'] != NULL) {
- $facitities .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢)
";
- $total_facility_num += 1;
- $arrive_num += 1;
- } elseif ($wip['real_arrival_date'] != NULL) {
- $facitities .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地)
";
- $total_facility_num += 1;
- $arrive_num += 1;
- } elseif ($wip['actual_tofactory_date'] != NULL) {
- $facitities .= $wip['facilityno'] . " (" . $wip['actual_tofactory_date'] . "實際到觀音日)
";
- $total_facility_num += 1;
- } elseif ($wip['estimated_shipping_date'] != NULL) {
- $facitities .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計到港)
";
- $total_facility_num += 1;
- } else {
- $facitities .= $wip['facilityno'] . " (預計到港日待確認)
";
- $total_facility_num += 1;
+ $facitities = "";
+ $total_facility_num = 0;
+ $arrive_num = 0;
+ $tryrun_num = 0;
+ $delivery_num = 0;
+ $official_num = 0;
+ $value[16]='';
+ $value[17]='';
+ $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'];
+ $value[16] = is_null($wip['department_id']) ? '' : $wip['department_id'];
+ $value[17] = is_null($wip['salesid']) ? '' : $wip['salesid'];
+ if ($wip['delivery_date'] != NULL) {
+ $facitities .= $wip['facilityno'] . " (" . $wip['delivery_date'] . "已移交)
";
+ $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'] . "官檢完畢)
";
+ $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'] . "試車完畢)
";
+ $total_facility_num += 1;
+ $arrive_num += 1;
+ $tryrun_num += 1;
+ } elseif ($wip['install_end_date'] != NULL) {
+ $facitities .= $wip['facilityno'] . " (" . $wip['install_end_date'] . "安裝完畢)
";
+ $total_facility_num += 1;
+ $arrive_num += 1;
+ } elseif ($wip['real_arrival_date'] != NULL) {
+ $facitities .= $wip['facilityno'] . " (" . $wip['real_arrival_date'] . "貨抵工地)
";
+ $total_facility_num += 1;
+ $arrive_num += 1;
+ } elseif ($wip['actual_tofactory_date'] != NULL) {
+ $facitities .= $wip['facilityno'] . " (" . $wip['actual_tofactory_date'] . "實際到觀音日)
";
+ $total_facility_num += 1;
+ } elseif ($wip['estimated_shipping_date'] != NULL) {
+ $facitities .= $wip['facilityno'] . " (" . $wip['estimated_shipping_date'] . "預計到港)
";
+ $total_facility_num += 1;
+ } else {
+ $facitities .= $wip['facilityno'] . " (預計到港日待確認)
";
+ $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);
- $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 {
+ $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);
$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;
+ $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];
- } else {
- $status = 0;
+
+ 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
+ ];
}
+
}
-
- 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);
@@ -353,13 +357,29 @@ $data = json_encode($receivable_array);