diff --git a/wms/account-receivable-excel.php b/wms/account-receivable-excel.php
index 72f0ead9..2441e3f3 100644
--- a/wms/account-receivable-excel.php
+++ b/wms/account-receivable-excel.php
@@ -26,7 +26,7 @@ foreach($Bill as $key=>$value){
$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]);
+ $array_data[$key][16] = str_replace('
','; ',$value[13]);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
@@ -36,6 +36,7 @@ $sheet->fromArray($colomnHeader,NULL,'A1');
$rowIndex = 2;
foreach($array_data as $key => $value){
$sheet->fromArray([$value], NULL, 'A' . $rowIndex);
+ $sheet->getStyle('Q' . $rowIndex)->getAlignment()->setWrapText(true);
$rowIndex++;
}
$writer = new Xlsx($spreadsheet);
diff --git a/wms/account-receivable-index.php b/wms/account-receivable-index.php
index 945d4adb..b0109528 100644
--- a/wms/account-receivable-index.php
+++ b/wms/account-receivable-index.php
@@ -1,11 +1,5 @@
query($sql_contract);
// 取收款資料 account_received
@@ -59,6 +55,8 @@ foreach ($received_data as $received) {
$received_array[$BillNo][2] = (intval($received['status']) < 4) ? intval($received['status']) : 0;
}
}
+
+// 將T8合約收款階段資料依據款別分類放進arraData裡
foreach ($contract as $cont) {
// print_r($cont);
// echo "
";
@@ -70,55 +68,212 @@ foreach ($contract as $cont) {
$BillNo = $cont['BillNo'];
};
$PayStage = $cont['PayStage'];
+ $PlanPayDate = $cont['PlanPayDate'];
$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;
+ //['sign'] 0 款項名稱 1 簽約金額 2 簽約日期 ['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 通訊地址
+ $arrayData[$BillNo] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+ $arrayData[$BillNo][5] = $partnerName;
+ $arrayData[$BillNo][6] = $EnterpriseName;
+ $arrayData[$BillNo][7] = $TaxNo;
+ $arrayData[$BillNo][8] = $ContactAddress;
+ }
+ if (stristr($PayStage, '二次款') || stristr($PayStage, '出貨前') || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60')) {
+ $arrayData[$BillNo]['second'][0] = $PayStage;
+ $arrayData[$BillNo]['second'][1] = $PayAmount;
+ $arrayData[$BillNo]['second'][2] = $PlanPayDate;
+ if (isset($arrayData[$BillNo]['sign'][2]) && !is_null($arrayData[$BillNo]['sign'][2])) {
+ $signtime = strtotime(strval($arrayData[$BillNo]['sign'][2]));
+ if (in_array($PayStage, $sign60)) {
+ $secondtime = $signtime - (60 * 86400);
+ $secondtime = date('Ymd', $secondtime);
+ $arrayData[$BillNo]['second'][2] = intval($secondtime);
+ } elseif (in_array($PayStage, $sign90)) {
+ $secondtime = $signtime - (90 * 86400);
+ $secondtime = date('Ymd', $secondtime);
+ $arrayData[$BillNo]['second'][2] = intval($secondtime);
+ } elseif (in_array($PayStage, $sign120)) {
+ $secondtime = $signtime - (120 * 86400);
+ $secondtime = date('Ymd', $secondtime);
+ $arrayData[$BillNo]['second'][2] = intval($secondtime);
+ } elseif (stristr($PayStage, '簽訂後30天')) {
+ $secondtime = $signtime - (30 * 86400);
+ $secondtime = date('Ymd', $secondtime);
+ $arrayData[$BillNo]['second'][2] = intval($secondtime);
+ }
}
+ } elseif ($PayStage == '簽約' || stristr($PayStage, '簽定') || stristr($PayStage, '簽訂') || stristr($PayStage, '訂金') || stristr($PayStage, '工地動工')) {
+ $arrayData[$BillNo]['sign'][0] = $PayStage;
+ $arrayData[$BillNo]['sign'][1] = $PayAmount;
+ $arrayData[$BillNo]['sign'][2] = $PlanPayDate;
+ } elseif (stristr($PayStage, '試車') || stristr($PayStage, '驗收完成')) {
+ $arrayData[$BillNo]['tryrun'][0] = $PayStage;
+ $arrayData[$BillNo]['tryrun'][1] = $PayAmount;
+ $arrayData[$BillNo]['tryrun'][2] = $PlanPayDate;
+ } elseif (stristr($PayStage, '安裝') || stristr($PayStage, '貨抵工地且完工')) {
+ $arrayData[$BillNo]['install'][0] = $PayStage;
+ $arrayData[$BillNo]['install'][1] = $PayAmount;
+ $arrayData[$BillNo]['install'][2] = $PlanPayDate;
+ } elseif (stristr($PayStage, '貨抵工地') || stristr($PayStage, '貨底工地')) {
+ $arrayData[$BillNo]['arrive'][0] = $PayStage;
+ $arrayData[$BillNo]['arrive'][1] = $PayAmount;
+ $arrayData[$BillNo]['arrive'][2] = $PlanPayDate;
+ } elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月') || stristr($PayStage, '交車')) {
+ $arrayData[$BillNo]['delivery'][0] = $PayStage;
+ $arrayData[$BillNo]['delivery'][1] = $PayAmount;
+ $arrayData[$BillNo]['delivery'][2] = $PlanPayDate;
+ } elseif (stristr($PayStage, '合格') || stristr($PayStage, '驗收') || stristr($PayStage, '許可') || stristr($PayStage, '核可')) {
+ $arrayData[$BillNo]['check'][0] = $PayStage;
+ $arrayData[$BillNo]['check'][1] = $PayAmount;
+ $arrayData[$BillNo]['check'][2] = $PlanPayDate;
} 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;
+
+ $arrayData[$BillNo]['other'][1] = $PayAmount;
+ $arrayData[$BillNo]['other'][2] = $PlanPayDate;
+ }
+}
+$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.contract_type='A'
+)AS tmp2
+left join (
+SELECT DISTINCT
+ department_id,
+ name
+FROM department
+
+) AS d
+ON d.department_id = tmp2.department_id";
+$wipwhole_array = mysqli_query($link, $sql);
+foreach ($wipwhole_array as $wip) {
+ if (isset($arrayData[$wip['contractno']])) {
+ $arrayData[$wip['contractno']][0] = $wip['department_id'];;
+ $arrayData[$wip['contractno']][1] = $wip['depart_name'];
+ $arrayData[$wip['contractno']][2] = $wip['manager_name'];
+ $arrayData[$wip['contractno']][3] = $wip['salesid'];
+ $arrayData[$wip['contractno']][4] = $wip['name'];
+ if (isset($arrayData[$wip['contractno']]['second']) && stristr($arrayData[$wip['contractno']]['second'][0], '出貨前30天')) {
+ $estimate_delivery_time = strtotime(strval($arrayData[$wip['contractno']]['second'][2]));
+ $secondtime = $estimate_delivery_time - (30 * 86400);
+ $secondtime = date('Ymd', $secondtime);
+ $arrayData[$wip['contractno']]['second'][2] = intval($secondtime);
+ } elseif (isset($arrayData[$wip['contractno']]['second']) && stristr($arrayData[$wip['contractno']]['second'][0], '出貨前90天')) {
+ $estimate_delivery_time = strtotime(strval($arrayData[$wip['contractno']]['second'][2]));
+ $secondtime = $estimate_delivery_time - (90 * 86400);
+ $secondtime = date('Ymd', $secondtime);
+ $arrayData[$wip['contractno']]['second'][2] = intval($secondtime);
+ }
+ $facitities = "";
+ $total_facility_num = 0;
+ $arrive_num = 0;
+ $tryrun_num = 0;
+ $delivery_num = 0;
+ $official_num = 0;
+ 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 {
- $arrayData[$BillNo][12] = $PayAmount;
+ $facitities .= $wip['facilityno'] . " (預計到港日待確認)
";
+ $total_facility_num += 1;
+ }
+ if ($total_facility_num > 0) {
+ $receivable_budget= $arrayData[$wip['contractno']]['sign'][1];
+ // $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 {
+ $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;
+ }
}
}
}
+exit();
+foreach ($arrayData as $key => $value) {
+ echo $key . "
";
+ print_r($value);
+ echo "
";
+}
+
+//D23070086
+//Array ( [0] => 312 [1] => 桃竹營銷部 [2] => 張莉凱 [3] => M0074 [4] => 章又仁 [5] => 永融營造(大園學八街) [6] => 永融營造工程有限公司 [7] => 13010305 [8] => 桃園市平鎮區環南路184號7樓之2 [9] => 0 [10] => 0 [11] => 0 [12] => 0 [sign] => Array ( [0] => 簽約 [1] => 210000.000000 [2] => 20230825 ) [arrive] => Array ( [0] => 貨抵工地 [1] => 525000.000000 [2] => 20231231 ) [tryrun] => Array ( [0] => 安裝試車 [1] => 210000.000000 [2] => 20240131 ) [delivery] => Array ( [0] => 交車 [1] => 105000.000000 [2] => 20240301 ) )
+
+
+exit();
foreach ($arrayData as $key => $value) {
if (array_key_exists($key, $arrayData) && isset($arrayData[$key])) {
@@ -163,8 +318,8 @@ ON d.department_id = tmp2.department_id";
$tryrun_num = 0;
$delivery_num = 0;
$official_num = 0;
- $value[16]='';
- $value[17]='';
+ $value[16] = '';
+ $value[17] = '';
$wipwhole_array = mysqli_query($link, $sql);
foreach ($wipwhole_array as $wip) {
$value[0] = $wip['depart_name'];
@@ -246,7 +401,6 @@ ON d.department_id = tmp2.department_id";
$uninvoice_budget, $unreceived_budget, $status
];
}
-
}
}
diff --git a/wms/account-receivable.xlsx b/wms/account-receivable.xlsx
index b27e61a0..ff6ba785 100644
Binary files a/wms/account-receivable.xlsx and b/wms/account-receivable.xlsx differ
diff --git a/wms/rib01-create.php b/wms/rib01-create.php
index 7c42f97a..09ea8c1f 100644
--- a/wms/rib01-create.php
+++ b/wms/rib01-create.php
@@ -127,8 +127,8 @@ if ($MaxBillNo < 10) {
echo "selected";
} ?>> -->
+ echo "selected";
+ } ?>>
@@ -142,18 +142,15 @@ if ($MaxBillNo < 10) {