diff --git a/wms/T8_Authorization_from_bpm.php b/wms/T8_Authorization_from_bpm.php
index 7c206023..b862a81d 100644
--- a/wms/T8_Authorization_from_bpm.php
+++ b/wms/T8_Authorization_from_bpm.php
@@ -3,10 +3,7 @@
// $user_id = "M0000";
// $user_password = "M012290493119";
-$user_id = "M0117";
-$user_password = "90493119";
-
-echo $validation = get_Auth($user_id, $user_password);
+// echo $validation = get_Auth($user_id, $user_password);
function get_Auth($user_id = "M0000", $user_password = "M012290493119")
{
@@ -16,8 +13,9 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119")
// $now = gmdate("YmdHis");
$now = gmdate("YmdHis", strtotime("-2 minutes"));
$data = "$user_id." . $now;
- $sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false);
+ $sign = hash_hmac('SHA256', $data, 'A21181F1EE4966D3', false);
+ // echo $sign;
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
$apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
@@ -30,7 +28,7 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119")
"Pwd: $user_password",
"TimestampUTC: $now",
"Sign: $sign",
- "GroupId: TEST"
+ "GroupId:TEST"
];
$ch = curl_init();
@@ -53,4 +51,4 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119")
curl_close($ch);
}
// $data = [];
-get_Auth();
+// get_Auth();
diff --git a/wms/account-receivable-contract.xlsx b/wms/account-receivable-contract.xlsx
new file mode 100644
index 00000000..cb3cc542
Binary files /dev/null and b/wms/account-receivable-contract.xlsx differ
diff --git a/wms/account-receivable-excel.php b/wms/account-receivable-excel.php
index db546b37..64fab766 100644
--- a/wms/account-receivable-excel.php
+++ b/wms/account-receivable-excel.php
@@ -12,19 +12,54 @@ $array_data = array();
$Bill = json_decode(file_get_contents("php://input"), true);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
-// file_put_contents('account-receivable.txt', json_encode($Bill));
-if ($type == 'facility') {
+
+if ($type == 'newContract') {
+ $colomnHeader = [
+ '合約號', '客戶名稱', '營業員', '合約金額', '台數', '作番狀態', '催收金額', '催收次數', '訂金催收金額', '訂金催收次數', '二次款催收金額', '二次款催收次數',
+ '貨抵工地款催收金額', '貨抵工地款催收次數',
+ '安裝款催收金額', '安裝款催收次數',
+ '試車款催收金額', '試車款催收次數',
+ '官檢驗收催收金額', '官檢驗收催收次數',
+ '交車款催收金額', '交車款催收次數',
+ '尾款催收金額', '尾款催收次數'
+ ];
+
+ file_put_contents('account-receivable.txt', json_encode($Bill, JSON_UNESCAPED_UNICODE));
+ $sheet->fromArray($colomnHeader, NULL, 'A1');
+ $rowIndex = 2;
+ foreach ($Bill as $key => $value) {
+
+ $sheet->fromArray($value, NULL, 'A' . $rowIndex);
+ $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'
+ ];
+ foreach ($column as $col) {
+ if ($col == 'F') {
+ $sheet->getColumnDimension('F')->setWidth(35);
+ $sheet->getStyle('F')->getAlignment()->setWrapText(true);
+ } else {
+ // $sheet->getColumnDimension($col)->setAutoSize(true);
+ $sheet->getColumnDimension($col)->setWidth(10);
+ $sheet->getStyle($col)->getAlignment()->setWrapText(true);
+ }
+ }
+ $rowIndex++;
+ }
+ $writer = new Xlsx($spreadsheet);
+ $excelFileName = 'account-receivable-contract.xlsx';
+ $writer->save($excelFileName);
+} elseif ($type == 'facility') {
$colomnHeader = [
- 'T8單據日期','作番號', '合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭',
- '訂金名稱', '訂金合約金額', '訂金應收日期', '訂金目前應收金額','訂金已開金額','訂金未開金額', '訂金已收金額', '訂金催收金額', '訂金催收次數',
- '二次款名稱', '二次款合約金額', '二次款應收日期', '二次款目前應收金額','二次款已開金額','二次款未開金額', '二次款已收金額', '二次款催收金額', '二次款催收次數',
- '貨抵工地款名稱', '貨抵工地款合約金額', '貨抵工地款應收日期', '貨抵工地款目前應收金額','貨抵工地款已開金額','貨抵工地款未開金額', '貨抵工地款已收金額', '貨抵工地款催收金額', '貨抵工地款催收次數',
- '安裝款名稱', '安裝款合約金額', '安裝款應收日期', '安裝款目前應收金額','安裝款已開金額','安裝款未開金額', '安裝款已收金額', '安裝款催收金額', '安裝款催收次數',
- '試車款名稱', '試車款合約金額', '試車款應收日期', '試車款目前應收金額','試車款已開金額','試車款未開金額', '試車款已收金額', '試車款催收金額', '試車款催收次數',
- '官檢款名稱', '官檢款合約金額', '官檢款應收日期', '官檢款目前應收金額','官檢款已開金額','官檢款未開金額', '官檢款已收金額', '官檢款催收金額', '官檢款催收次數',
- '交車款名稱', '交車款合約金額', '交車款應收日期', '交車款目前應收金額','交車款已開金額','交車款未開金額', '交車款已收金額', '交車款催收金額', '交車款催收次數',
- '尾款名稱', '尾款金額', '尾款應收日期', '尾款應收金額','尾款已開金額','尾款未開金額', '尾款已收金額', '尾款催收金額', '尾款催收次數',
- '作番狀態', '合約-設備金額','合約-安裝金額','作番合約總金額', '作番總應收金額'
+ 'T8單據日期', '作番號', '合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭',
+ '訂金名稱', '訂金合約金額', '訂金應收日期', '訂金目前應收金額', '訂金已開金額', '訂金未開金額', '訂金已收金額', '訂金催收金額', '訂金催收次數',
+ '二次款名稱', '二次款合約金額', '二次款應收日期', '二次款目前應收金額', '二次款已開金額', '二次款未開金額', '二次款已收金額', '二次款催收金額', '二次款催收次數',
+ '貨抵工地款名稱', '貨抵工地款合約金額', '貨抵工地款應收日期', '貨抵工地款目前應收金額', '貨抵工地款已開金額', '貨抵工地款未開金額', '貨抵工地款已收金額', '貨抵工地款催收金額', '貨抵工地款催收次數',
+ '安裝款名稱', '安裝款合約金額', '安裝款應收日期', '安裝款目前應收金額', '安裝款已開金額', '安裝款未開金額', '安裝款已收金額', '安裝款催收金額', '安裝款催收次數',
+ '試車款名稱', '試車款合約金額', '試車款應收日期', '試車款目前應收金額', '試車款已開金額', '試車款未開金額', '試車款已收金額', '試車款催收金額', '試車款催收次數',
+ '官檢款名稱', '官檢款合約金額', '官檢款應收日期', '官檢款目前應收金額', '官檢款已開金額', '官檢款未開金額', '官檢款已收金額', '官檢款催收金額', '官檢款催收次數',
+ '交車款名稱', '交車款合約金額', '交車款應收日期', '交車款目前應收金額', '交車款已開金額', '交車款未開金額', '交車款已收金額', '交車款催收金額', '交車款催收次數',
+ '尾款名稱', '尾款金額', '尾款應收日期', '尾款應收金額', '尾款已開金額', '尾款未開金額', '尾款已收金額', '尾款催收金額', '尾款催收次數',
+ '作番狀態', '合約-設備金額', '合約-安裝金額', '作番合約總金額', '作番總應收金額'
];
$sheet->fromArray($colomnHeader, NULL, 'A1');
$rowIndex = 2;
@@ -34,7 +69,7 @@ if ($type == 'facility') {
$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', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
- 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP','BQ','BR','BK'
+ 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BK'
];
foreach ($column as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
@@ -47,16 +82,16 @@ if ($type == 'facility') {
$writer->save($excelFileName);
} else {
$colomnHeader = [
- 'T8單據日期','合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭',
- '訂金', '訂金目前應收', '訂金已開票金額','訂金未開票金額', '訂金已收金額', '訂金催收金額', '訂金最大催收次數', '訂金最小催收次數',
- '二次款', '二次款目前應收', '二次款已開票金額','二次款未開票金額', '二次款已收金額', '二次款催收金額', '二次款最大催收次數', '二次款最小催收次數',
- '貨抵工地款', '貨抵工地款目前應收', '貨抵工地款已開票金額','貨抵工地款未開票金額', '貨抵工地款已收金額', '貨抵工地款催收金額', '貨抵工地款最大催收次數', '貨抵工地款最小催收次數',
- '安裝款', '安裝款目前應收', '安裝款已開票金額','安裝款未開票金額', '安裝款已收金額', '安裝款催收金額', '安裝款最大催收次數', '安裝款最小催收次數',
- '試車款', '試車款目前應收', '試車款已開票金額','試車款未開票金額', '試車款已收金額', '試車款催收金額', '試車款最大催收次數', '試車款最小催收次數',
- '官檢款', '官檢款目前應收', '官檢款已開票金額','官檢款未開票金額', '官檢款已收金額', '官檢款催收金額', '官檢款最大催收次數', '官檢款最小催收次數',
- '交車款', '交車款目前應收', '交車款已開票金額','交車款未開票金額', '交車款已收金額', '交車款催收金額', '交車款最大催收次數', '交車款最小催收次數',
- '尾款', '尾款目前應收', '尾款已開票金額','尾款未開票金額', '尾款已收金額', '尾款催收金額', '尾款最大催收次數', '尾款最小催收次數',
- '合約設備金額','合約安裝金額','合約總金額', '目前應收', '已開發票金額', '已收金額', '作番總數', '作番狀態'
+ 'T8單據日期', '合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭',
+ '訂金', '訂金目前應收', '訂金已開票金額', '訂金未開票金額', '訂金已收金額', '訂金催收金額', '訂金最大催收次數', '訂金最小催收次數',
+ '二次款', '二次款目前應收', '二次款已開票金額', '二次款未開票金額', '二次款已收金額', '二次款催收金額', '二次款最大催收次數', '二次款最小催收次數',
+ '貨抵工地款', '貨抵工地款目前應收', '貨抵工地款已開票金額', '貨抵工地款未開票金額', '貨抵工地款已收金額', '貨抵工地款催收金額', '貨抵工地款最大催收次數', '貨抵工地款最小催收次數',
+ '安裝款', '安裝款目前應收', '安裝款已開票金額', '安裝款未開票金額', '安裝款已收金額', '安裝款催收金額', '安裝款最大催收次數', '安裝款最小催收次數',
+ '試車款', '試車款目前應收', '試車款已開票金額', '試車款未開票金額', '試車款已收金額', '試車款催收金額', '試車款最大催收次數', '試車款最小催收次數',
+ '官檢款', '官檢款目前應收', '官檢款已開票金額', '官檢款未開票金額', '官檢款已收金額', '官檢款催收金額', '官檢款最大催收次數', '官檢款最小催收次數',
+ '交車款', '交車款目前應收', '交車款已開票金額', '交車款未開票金額', '交車款已收金額', '交車款催收金額', '交車款最大催收次數', '交車款最小催收次數',
+ '尾款', '尾款目前應收', '尾款已開票金額', '尾款未開票金額', '尾款已收金額', '尾款催收金額', '尾款最大催收次數', '尾款最小催收次數',
+ '合約設備金額', '合約安裝金額', '合約總金額', '目前應收', '已開發票金額', '已收金額', '作番總數', '作番狀態'
];
$sheet->fromArray($colomnHeader, NULL, 'A1');
@@ -67,7 +102,7 @@ if ($type == 'facility') {
'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', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ',
- 'CA','CB','CC','CD'
+ 'CA', 'CB', 'CC', 'CD'
];
foreach ($column as $col) {
if ($col == 'CC') {
diff --git a/wms/account-receivable-facility.xlsx b/wms/account-receivable-facility.xlsx
index 9c5fbaa6..24109745 100644
Binary files a/wms/account-receivable-facility.xlsx and b/wms/account-receivable-facility.xlsx differ
diff --git a/wms/account-receivable-new-index.php b/wms/account-receivable-new-index.php
index e4cd3eb7..59fc1f88 100644
--- a/wms/account-receivable-new-index.php
+++ b/wms/account-receivable-new-index.php
@@ -7,11 +7,12 @@ $sum_contract = 0;
$sum_A40001 = 0;
$sum_A40008 = 0;
$sum_total_budget = 0;
-$average_budget = 0;
+$average_facility_budget = 0;
$average_A40001 = 0;
$average_A40008 = 0;
$sum_invoice_budget = 0;
$sum_received_budget = 0;
+$sum_receivable_budget = 0;
$sum_collect_budget = 0;
// 主要array
@@ -122,6 +123,7 @@ if ((in_array($user_id, array('M0060', 'M0175'))) || (in_array(accountidToDepart
$sql_all_contract .= ")";
};
}
+$sql_all_contract .= " ORDER BY MainAll.PersonId ASC ";
$str_numbers = "";
$query_all_contract = $conn->query($sql_all_contract);
if (is_iterable($query_all_contract)) {
@@ -147,11 +149,13 @@ if (is_iterable($query_all_contract)) {
$arrayData[$contract_numbers['BillNo']]['collect_budget'] = 0;
$arrayData[$contract_numbers['BillNo']]['A40001'] = 0;
$arrayData[$contract_numbers['BillNo']]['A40008'] = 0;
+ $arrayData[$contract_numbers['BillNo']]['collect_month'] = 0;
$arrayData[$contract_numbers['BillNo']]['facility_status'] = "";
$arrayData[$contract_numbers['BillNo']]['facility'] = array();
+ $arrayData[$contract_numbers['BillNo']]['facility_num'] = 0;
$arrayData[$contract_numbers['BillNo']]['total_budget'] = $contract_numbers['OAmountWithTax'];
$sum_total_budget += $contract_numbers['OAmountWithTax'];
- $sum_contract +=1;
+ $sum_contract += 1;
}
}
$str_numbers .= "('" . implode("','", $contractNumbers) . "')";
@@ -176,18 +180,17 @@ foreach ($query_contract_budget as $contract_budget) {
$arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']]['total_budget'] = $contract_budget['OAmountWithTax'];
$arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']][$contract_budget['MaterialId']] = $contract_budget['OAmountWithTax'];
$arrayData[$contract_budget['BillNo']]['facility'][$contract_budget['CU_MaterialId']]['status'] = "";
- $sum_facility +=1;
+ $sum_facility += 1;
+ $arrayData[$contract_budget['BillNo']]['facility_num'] += 1;
}
- switch($contract_budget['CU_MaterialId']){
+ switch ($contract_budget['MaterialId']) {
case "A40001":
$sum_A40001 += $contract_budget['OAmountWithTax'];
break;
case "A40008":
$sum_A40008 += $contract_budget['OAmountWithTax'];
break;
-
}
-
}
}
@@ -215,6 +218,7 @@ foreach ($query_PayStage as $PayStage) {
$arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]['PayStage'] = $PayStage['PayStage'];
$arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]['PlanPayAmt'] = $PayStage['PlanPayAmt'];
$arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]['PlanPayDate'] = $PayStage['PlanPayDate'];
+ $arrayData[$PayStage['BillNo']]['PayStage'][$PayStage['RowNo']]['stage'] = '';
if (isset($arrayData[$PayStage['BillNo']]['facility']) && is_iterable($arrayData[$PayStage['BillNo']]['facility'])) {
foreach ($arrayData[$PayStage['BillNo']]['facility'] as $key => &$value) {
$tmpkey = $key . $PayStage['RowNo'];
@@ -323,11 +327,11 @@ foreach ($PayStage_array as $key => &$value) {
case '寶佳出貨前30天':
$payvalue['stage'] = '訂金';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
$signtime = $estimate_time - (30 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) {
- $estimate_time = strtotime($wip['real_contract_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']);
$signtime = $estimate_time - (30 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
@@ -337,7 +341,7 @@ foreach ($PayStage_array as $key => &$value) {
case '寶佳出貨後10天':
$payvalue['stage'] = '二次款';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
$signtime = $estimate_time + (10 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
@@ -347,7 +351,7 @@ foreach ($PayStage_array as $key => &$value) {
case '貨抵工地後90天':
$payvalue['stage'] = '貨抵工地款';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
$signtime = $estimate_time + (90 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
@@ -357,7 +361,7 @@ foreach ($PayStage_array as $key => &$value) {
case '安裝試車後90天':
$payvalue['stage'] = '試車款';
if ($wip_array[$payvalue['facilityno']]['tryrun_end_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['tryrun_end_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['tryrun_end_date'])) {
- $estimate_time = strtotime($wip['tryrun_end_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['tryrun_end_date']);
$signtime = $estimate_time + (90 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
@@ -367,43 +371,53 @@ foreach ($PayStage_array as $key => &$value) {
case '交車後270天':
$payvalue['stage'] = '尾款';
if ($wip_array[$payvalue['facilityno']]['delivery_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['delivery_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['delivery_date'])) {
- $estimate_time = strtotime($wip['delivery_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['delivery_date']);
$signtime = $estimate_time + (270 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
$payvalue['PlanPayDate'] = NULL;
}
break;
+ case '交車後180天':
+ $payvalue['stage'] = '尾款';
+ if ($wip_array[$payvalue['facilityno']]['delivery_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['delivery_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['delivery_date'])) {
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['delivery_date']);
+ $signtime = $estimate_time + (180 * 86400);
+ $payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
+ } else {
+ $payvalue['PlanPayDate'] = NULL;
+ }
+ break;
case (in_array($payvalue['PayStage'], $arrival)):
$payvalue['stage'] = '貨抵工地款';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
- $signtime = $estimate_time + (10 * 86400);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
+ $signtime = $estimate_time;
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
- $payvalue['PlanPayDate'] = NULL;
+ $payvalue['PlanPayDate'] = 'NULL';
}
break;
case '二次款':
$payvalue['stage'] = '二次款';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
$payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time);
} elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) {
- $estimate_time = strtotime($wip['real_contract_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']);
$payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time);
} else {
$payvalue['PlanPayDate'] = NULL;
}
break;
- case (stristr($payvalue['PayStage'], '出貨前30') || stristr($payvalue['PayStage'], '簽約(出貨前30天)') ||stristr($payvalue['PayStage'], '建照核發時')):
+ case (stristr($payvalue['PayStage'], '出貨前30') || stristr($payvalue['PayStage'], '簽約(出貨前30天)') || stristr($payvalue['PayStage'], '建照核發時')):
$payvalue['stage'] = '二次款';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
$signtime = $estimate_time - (30 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) {
- $estimate_time = strtotime($wip['real_contract_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']);
$signtime = $estimate_time - (30 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
@@ -413,11 +427,11 @@ foreach ($PayStage_array as $key => &$value) {
case (stristr($payvalue['PayStage'], '出貨前60')):
$payvalue['stage'] = '二次款';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
$signtime = $estimate_time - (60 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) {
- $estimate_time = strtotime($wip['real_contract_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']);
$signtime = $estimate_time - (60 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
@@ -427,11 +441,11 @@ foreach ($PayStage_array as $key => &$value) {
case (stristr($payvalue['PayStage'], '出貨前90')):
$payvalue['stage'] = '二次款';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
$signtime = $estimate_time - (90 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) {
- $estimate_time = strtotime($wip['real_contract_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']);
$signtime = $estimate_time - (90 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
@@ -441,11 +455,11 @@ foreach ($PayStage_array as $key => &$value) {
case (stristr($payvalue['PayStage'], '出貨前120')):
$payvalue['stage'] = '二次款';
if ($wip_array[$payvalue['facilityno']]['real_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_arrival_date'])) {
- $estimate_time = strtotime($wip['real_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_arrival_date']);
$signtime = $estimate_time - (120 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} elseif ($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['real_contract_arrival_date'])) {
- $estimate_time = strtotime($wip['real_contract_arrival_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['real_contract_arrival_date']);
$signtime = $estimate_time - (120 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $signtime);
} else {
@@ -490,7 +504,7 @@ foreach ($PayStage_array as $key => &$value) {
case (stristr($payvalue['PayStage'], '試車')):
$payvalue['stage'] = '試車款';
if ($wip_array[$payvalue['facilityno']]['tryrun_end_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['tryrun_end_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['tryrun_end_date'])) {
- $estimate_time = strtotime($wip['tryrun_end_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['tryrun_end_date']);
$payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time);
} else {
$payvalue['PlanPayDate'] = NULL;
@@ -499,7 +513,7 @@ foreach ($PayStage_array as $key => &$value) {
case (stristr($payvalue['PayStage'], '安裝') || stristr($payvalue['PayStage'], '貨抵工地且完工')):
$payvalue['stage'] = '安裝款';
if ($wip_array[$payvalue['facilityno']]['install_end_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['install_end_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['install_end_date'])) {
- $estimate_time = strtotime($wip['install_end_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['install_end_date']);
$payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time);
} else {
$payvalue['PlanPayDate'] = NULL;
@@ -508,7 +522,7 @@ foreach ($PayStage_array as $key => &$value) {
case (in_array($payvalue['PayStage'], $final6)):
$payvalue['stage'] = '尾款';
if ($wip_array[$payvalue['facilityno']]['delivery_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['delivery_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['delivery_date'])) {
- $estimate_time = strtotime($wip['delivery_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['delivery_date']);
$estimate_time = $estimate_time + (180 * 86400);
$payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time);
} else {
@@ -518,7 +532,7 @@ foreach ($PayStage_array as $key => &$value) {
case (stristr($payvalue['PayStage'], '合格') || stristr($payvalue['PayStage'], '驗收') || stristr($payvalue['PayStage'], '驗收')):
$payvalue['stage'] = '官檢驗收款';
if ($wip_array[$payvalue['facilityno']]['official_check_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['official_check_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['official_check_date'])) {
- $estimate_time = strtotime($wip['official_check_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['official_check_date']);
$payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time);
} else {
$payvalue['PlanPayDate'] = NULL;
@@ -527,7 +541,7 @@ foreach ($PayStage_array as $key => &$value) {
case (stristr($payvalue['PayStage'], '交車') || stristr($payvalue['PayStage'], '移交') || stristr($payvalue['PayStage'], '完工') || stristr($payvalue['PayStage'], '許可') || stristr($payvalue['PayStage'], '核可')):
$payvalue['stage'] = '交車款';
if ($wip_array[$payvalue['facilityno']]['delivery_date'] !== null && strtotime($wip_array[$payvalue['facilityno']]['delivery_date']) > 975686400 && !empty($wip_array[$payvalue['facilityno']]['delivery_date'])) {
- $estimate_time = strtotime($wip['delivery_date']);
+ $estimate_time = strtotime($wip_array[$payvalue['facilityno']]['delivery_date']);
$payvalue['PlanPayDate'] = date('Y-m-d', $estimate_time);
} else {
$payvalue['PlanPayDate'] = NULL;
@@ -596,6 +610,18 @@ foreach ($query_invoice as $invoice) {
}
}
+//未在T8的收款資料
+$sql_wms = "SELECT * FROM account_received WHERE type='M' AND BillNo IN $str_numbers";
+$query_wms = mysqli_query($link, $sql_wms);
+foreach ($query_wms as $wms) {
+ if (isset($arrayData[$wms['BillNo']]) && isset($arrayData[$wms['BillNo']]['invoice_budget'])) {
+ $arrayData[$wms['BillNo']]['invoice_budget'] += $wms['invoice_budget'];
+ }
+ if (isset($arrayData[$wms['BillNo']]) && isset($arrayData[$wms['BillNo']]['received_budget'])) {
+ $arrayData[$wms['BillNo']]['received_budget'] += $wms['received_budget'];
+ }
+}
+
// 核銷資訊
$sql_received = "SELECT
CheckDetail.OrderBillNo,
@@ -636,7 +662,6 @@ foreach ($final_paystage as $key => &$value) {
$collect_month = collect_month(strtotime($value[$sequenceNumber]['PlanPayDate']));
if ($today > strtotime($value[$sequenceNumber]['PlanPayDate'])) {
$value[$sequenceNumber]['hadtopay'] = 'V';
- $arrayData[$key]['receivable_budget'] += $value[$sequenceNumber]['PlanPayAmt'];
} else {
$value[$sequenceNumber]['hadtopay'] = '--';
}
@@ -644,9 +669,9 @@ foreach ($final_paystage as $key => &$value) {
$collect_month = 0;
$value[$sequenceNumber]['hadtopay'] = '--';
}
- if ($tmpinvoice >= $value[$sequenceNumber]['PlanPayAmt']) {
+ if ($tmpinvoice > $value[$sequenceNumber]['PlanPayAmt']) {
$value[$sequenceNumber]['invoice_budget'] = $value[$sequenceNumber]['PlanPayAmt'];
- $tmpinvoice -= $value[$sequenceNumber]['invoice_budget'];
+ $tmpinvoice = $tmpinvoice - $value[$sequenceNumber]['invoice_budget'];
} elseif ($tmpinvoice > 0) {
$value[$sequenceNumber]['invoice_budget'] = $tmpinvoice;
$tmpinvoice = 0;
@@ -655,7 +680,7 @@ foreach ($final_paystage as $key => &$value) {
}
if ($tmpreceived > $value[$sequenceNumber]['PlanPayAmt']) {
$value[$sequenceNumber]['received_budget'] = $value[$sequenceNumber]['PlanPayAmt'];
- $tmpinvoice -= $value[$sequenceNumber]['received_budget'];
+ $tmpreceived -= $value[$sequenceNumber]['received_budget'];
} elseif ($tmpreceived > 0) {
$value[$sequenceNumber]['received_budget'] = $tmpreceived;
$tmpreceived = 0;
@@ -670,17 +695,9 @@ foreach ($final_paystage as $key => &$value) {
}
}
-// foreach($final_paystage as $key => $value) {
-// echo $key."
";
-// echo "---------------------
";
-// foreach($value as $key2 => $value2) {
-// echo $key2."
";
-// print_r($value2);
-// echo "
";
-// }
-// echo "
==================
";
-// }
-// exit();
+
+
+//合約資料填回arrayData
foreach ($final_paystage as $key => $value) {
for ($sequence = 1; $sequence <= count($value); $sequence++) {
if (isset($arrayData[$key]) && isset($arrayData[$key]['facility']) && isset($arrayData[$key]['facility'][$value[$sequence]['facilityno']]) && isset($arrayData[$key]['facility'][$value[$sequence]['facilityno']]['PayStage'])) {
@@ -688,18 +705,37 @@ foreach ($final_paystage as $key => $value) {
foreach ($arrayData[$key]['PayStage'] as $arkey => &$arvalue) {
if ($arvalue['PayStage'] == $value[$sequence]['PayStage']) {
if (isset($arvalue['receivable_budget']) && isset($arvalue['received_budget']) && isset($arvalue['invoice_budget'])) {
- $arvalue['receivable_budget'] += $value[$sequence]['PlanPayAmt'];
$arvalue['received_budget'] += $value[$sequence]['received_budget'];
$arvalue['invoice_budget'] += $value[$sequence]['invoice_budget'];
+ if ($value[$sequence]['hadtopay'] == 'V') {
+ $arvalue['receivable_budget'] += $value[$sequence]['PlanPayAmt'];
+ $arrayData[$key]['receivable_budget'] += $value[$sequence]['PlanPayAmt'];
+ } else {
+ $arvalue['receivable_budget'] = 0;
+ }
if ($arvalue['collect_month'] < $value[$sequence]['collect_month']) {
$arvalue['collect_month'] = $value[$sequence]['collect_month'];
}
+ $sum_receivable_budget += $value[$sequence]['PlanPayAmt'];
+ $sum_received_budget += $value[$sequence]['received_budget'];
+ $sum_invoice_budget += $value[$sequence]['invoice_budget'];
} else {
$arvalue['stage'] = $value[$sequence]['stage'];
- $arvalue['receivable_budget'] = $value[$sequence]['PlanPayAmt'];
+ if ($value[$sequence]['hadtopay'] == 'V') {
+ $arvalue['receivable_budget'] = $value[$sequence]['PlanPayAmt'];
+ $arrayData[$key]['receivable_budget'] += $value[$sequence]['PlanPayAmt'];
+ } else {
+ $arvalue['receivable_budget'] = 0;
+ }
$arvalue['received_budget'] = $value[$sequence]['received_budget'];
$arvalue['invoice_budget'] = $value[$sequence]['invoice_budget'];
$arvalue['collect_month'] = $value[$sequence]['collect_month'];
+ $sum_receivable_budget += $value[$sequence]['PlanPayAmt'];
+ $sum_received_budget += $value[$sequence]['received_budget'];
+ $sum_invoice_budget += $value[$sequence]['invoice_budget'];
+ }
+ if ($value[$sequence]['collect_month'] > $arrayData[$key]['collect_month']) {
+ $arrayData[$key]['collect_month'] = $value[$sequence]['collect_month'];
}
}
}
@@ -707,15 +743,620 @@ foreach ($final_paystage as $key => $value) {
}
}
-// 存進excel_array
-$excel_array = array();
+$average_A40001 = $sum_A40001 / $sum_facility;
+$average_A40008 = $sum_A40008 / $sum_facility;
+$average_facility_budget = $sum_total_budget / $sum_facility;
+$average_contract_budget = $sum_total_budget / $sum_contract;
+$average_contract_facility = $sum_facility / $sum_contract;
+
+
+// excel 結果
+// 0 合約號; 1 單據日期; 2 客戶編號; 3 客戶名稱; 4 客戶地址; 5 部門ID; 6 部門名稱; 7 營業員工號; 8 營業員名稱; 9 部門主管工號; 10 部門主管名稱;
+// 11 合約總金額; 12 A40001總金額; 13 A40008總金額; 14 目前應收金額; 15 已開發票金額; 16 已收金額; 17 催收金額; 18 催收次數; 19 作番總數; 20 作番狀態
+// 21 訂金名稱; 22 訂金金額; 23 應收金額; 24 已開發票金額; 25 已收金額; 26 催收金額; 27 催收次數;
+// 28 二次款名稱; 29 二次款金額; 30 應收金額; 31 已開發票金額; 32 已收金額; 33 催收金額; 34 催收次數;
+$excel_contract_array = array();
+$excel_contract_all_array = array();
+$excel_contract_boga_array = array();
+$excel_contract_noboga_array = array();
+
+$excel_facility_array = array();
foreach ($arrayData as $key => $value) {
- echo $key . "
********************
";
- print_r($value);
- // foreach($value['facility'] as $key2 => $value2) {
- // echo $key2."
";
- // print_r($value2['PayStage']);
- // echo "
";
- // }
- echo "
-------------------------------
";
+
+ $excel_contract_array[$key] = array_fill(0, 76, '');
+ $excel_contract_array[$key][0] = (isset($value['BillNo']) && !is_null($value['BillNo'])) ? $value['BillNo'] : '';
+ $excel_contract_array[$key][1] = (isset($value['BillDate']) && !is_null($value['BillDate'])) ? $value['BillDate'] : '';
+ $excel_contract_array[$key][2] = (isset($value['CustomerId']) && !is_null($value['CustomerId'])) ? $value['CustomerId'] : '';
+ $excel_contract_array[$key][3] = (isset($value['CustomerName']) && !is_null($value['CustomerName'])) ? $value['CustomerName'] : '';
+ $excel_contract_array[$key][4] = (isset($value['CustomerAddress']) && !is_null($value['CustomerAddress'])) ? $value['CustomerAddress'] : '';
+ $excel_contract_array[$key][5] = (isset($value['DeptId']) && !is_null($value['DeptId'])) ? $value['DeptId'] : '';
+ $excel_contract_array[$key][6] = (isset($value['DeptName']) && !is_null($value['DeptName'])) ? $value['DeptName'] : '';
+ $excel_contract_array[$key][7] = (isset($value['PersonId']) && !is_null($value['PersonId'])) ? $value['PersonId'] : '';
+ $excel_contract_array[$key][8] = (isset($value['PersonName']) && !is_null($value['PersonName'])) ? $value['PersonName'] : '';
+ $excel_contract_array[$key][9] = (isset($value['ManagerId']) && !is_null($value['ManagerId'])) ? $value['ManagerId'] : '';
+ $excel_contract_array[$key][10] = (isset($value['ManagerName']) && !is_null($value['ManagerName'])) ? $value['ManagerName'] : '';
+ $excel_contract_array[$key][11] = (isset($value['OAmountWithTax']) && !is_null($value['OAmountWithTax'])) ? number_format(round($value['OAmountWithTax'])) : '0';
+ $excel_contract_array[$key][12] = (isset($value['A40001']) && !is_null($value['A40001'])) ? number_format(round($value['A40001'])) : '0';
+ $excel_contract_array[$key][13] = (isset($value['A40008']) && !is_null($value['A40008'])) ? number_format(round($value['A40008'])) : '0';
+ $excel_contract_array[$key][14] = (isset($value['receivable_budget']) && !is_null($value['receivable_budget'])) ? $value['receivable_budget'] : 0;
+ $excel_contract_array[$key][15] = (isset($value['invoice_budget']) && !is_null($value['invoice_budget'])) ? number_format(round($value['invoice_budget'])) : '0';
+ $excel_contract_array[$key][16] = (isset($value['received_budget']) && !is_null($value['received_budget'])) ? $value['received_budget'] : 0;
+ $excel_contract_array[$key][17] = number_format(round($excel_contract_array[$key][14] - $excel_contract_array[$key][16]));
+ $excel_contract_array[$key][18] = (isset($value['collect_month']) && !is_null($value['collect_month'])) ? number_format(round($value['collect_month'])) : '0';
+ $excel_contract_array[$key][19] = (isset($value['facility_num']) && !is_null($value['facility_num'])) ? number_format(round($value['facility_num'])) : '0';
+ $excel_contract_array[$key][20] = (isset($value['facility_status']) && !is_null($value['facility_status'])) ? $value['facility_status'] : '--';
+ $excel_contract_array[$key][14] = number_format(round($excel_contract_array[$key][14]));
+ $excel_contract_array[$key][16] = number_format(round($excel_contract_array[$key][16]));
+ if ($excel_contract_array[$key][17] > 1 && isset($value['PayStage']) && is_iterable($value['PayStage'])) {
+ $excel_contract_all_array[$key] = array_fill(0, 24, 0);
+ $excel_contract_all_array[$key][0] = $excel_contract_array[$key][0];
+ $excel_contract_all_array[$key][1] = $excel_contract_array[$key][3];
+ $excel_contract_all_array[$key][2] = $excel_contract_array[$key][8];
+ $excel_contract_all_array[$key][3] = $excel_contract_array[$key][11];
+ $excel_contract_all_array[$key][4] = $excel_contract_array[$key][19];
+ $excel_contract_all_array[$key][5] = $excel_contract_array[$key][20];
+ $excel_contract_all_array[$key][6] = $excel_contract_array[$key][17];
+ $excel_contract_all_array[$key][7] = $excel_contract_array[$key][18];
+ $isBoga = 0;
+ if (stristr($value['PayStage'][1]['PayStage'], '寶佳')) {
+ $isBoga = 1;
+ $excel_contract_boga_array[$key] = array_fill(0, 24, '');
+ $excel_contract_boga_array[$key][0] = $excel_contract_array[$key][0];
+ $excel_contract_boga_array[$key][1] = $excel_contract_array[$key][3];
+ $excel_contract_boga_array[$key][2] = $excel_contract_array[$key][8];
+ $excel_contract_boga_array[$key][3] = $excel_contract_array[$key][11];
+ $excel_contract_boga_array[$key][4] = $excel_contract_array[$key][19];
+ $excel_contract_boga_array[$key][5] = $excel_contract_array[$key][20];
+ $excel_contract_boga_array[$key][6] = $excel_contract_array[$key][17];
+ $excel_contract_boga_array[$key][7] = $excel_contract_array[$key][18];
+ } else {
+ $excel_contract_noboga_array[$key] = array_fill(0, 24, '');
+ $excel_contract_noboga_array[$key][0] = $excel_contract_array[$key][0];
+ $excel_contract_noboga_array[$key][1] = $excel_contract_array[$key][3];
+ $excel_contract_noboga_array[$key][2] = $excel_contract_array[$key][8];
+ $excel_contract_noboga_array[$key][3] = $excel_contract_array[$key][11];
+ $excel_contract_noboga_array[$key][4] = $excel_contract_array[$key][19];
+ $excel_contract_noboga_array[$key][5] = $excel_contract_array[$key][20];
+ $excel_contract_noboga_array[$key][6] = $excel_contract_array[$key][17];
+ $excel_contract_noboga_array[$key][7] = $excel_contract_array[$key][18];
+ }
+ foreach ($value['PayStage'] as $paykey => $payvalue) {
+ switch ($payvalue['stage']) {
+ case "訂金":
+ $excel_contract_array[$key][21] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--';
+ $excel_contract_array[$key][22] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? number_format(round($payvalue['PlanPayAmt'])) : '0';
+ $excel_contract_array[$key][23] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0;
+ $excel_contract_array[$key][24] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? number_format(round($payvalue['invoice_budget'])) : '0';
+ $excel_contract_array[$key][25] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0;
+ $excel_contract_array[$key][26] = number_format(round($excel_contract_array[$key][23] - $excel_contract_array[$key][25]));
+ $excel_contract_array[$key][27] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if (isset($excel_contract_all_array[$key])) {
+ $excel_contract_all_array[$key][8] = number_format(round($excel_contract_array[$key][23] - $excel_contract_array[$key][25]));
+ $excel_contract_all_array[$key][9] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if ($isBoga == 1) {
+ $excel_contract_boga_array[$key][8] = $excel_contract_all_array[$key][8];
+ $excel_contract_boga_array[$key][9] = $excel_contract_all_array[$key][9];
+ } else {
+ $excel_contract_noboga_array[$key][8] = $excel_contract_all_array[$key][8];
+ $excel_contract_noboga_array[$key][9] = $excel_contract_all_array[$key][9];
+ }
+ }
+ $excel_contract_array[$key][23] = number_format(round($excel_contract_array[$key][23]));
+ $excel_contract_array[$key][25] = number_format(round($excel_contract_array[$key][25]));
+
+
+ break;
+ case "二次款":
+ $excel_contract_array[$key][28] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--';
+ $excel_contract_array[$key][29] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? number_format(round($payvalue['PlanPayAmt'])) : '0';
+ $excel_contract_array[$key][30] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0;
+ $excel_contract_array[$key][31] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? number_format(round($payvalue['invoice_budget'])) : '0';
+ $excel_contract_array[$key][32] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0;
+ $excel_contract_array[$key][33] = number_format(round($excel_contract_array[$key][30] - $excel_contract_array[$key][32]));
+ $excel_contract_array[$key][34] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if (isset($excel_contract_all_array[$key])) {
+ $excel_contract_all_array[$key][10] = number_format(round($excel_contract_array[$key][30] - $excel_contract_array[$key][32]));
+ $excel_contract_all_array[$key][11] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if ($isBoga == 1) {
+ $excel_contract_boga_array[$key][10] = $excel_contract_all_array[$key][10];
+ $excel_contract_boga_array[$key][11] = $excel_contract_all_array[$key][11];
+ } else {
+ $excel_contract_noboga_array[$key][10] = $excel_contract_all_array[$key][10];
+ $excel_contract_noboga_array[$key][11] = $excel_contract_all_array[$key][11];
+ }
+ }
+
+ $excel_contract_array[$key][30] = number_format(round($excel_contract_array[$key][30]));
+ $excel_contract_array[$key][32] = number_format(round($excel_contract_array[$key][32]));
+
+
+ break;
+ case "貨抵工地款":
+ $excel_contract_array[$key][35] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--';
+ $excel_contract_array[$key][36] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? number_format(round($payvalue['PlanPayAmt'])) : '0';
+ $excel_contract_array[$key][37] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0;
+ $excel_contract_array[$key][38] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? number_format(round($payvalue['invoice_budget'])) : '0';
+ $excel_contract_array[$key][39] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0;
+ $excel_contract_array[$key][40] = number_format(round($excel_contract_array[$key][37] - $excel_contract_array[$key][39]));
+ $excel_contract_array[$key][41] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if (isset($excel_contract_all_array[$key])) {
+ $excel_contract_all_array[$key][12] = number_format(round($excel_contract_array[$key][37] - $excel_contract_array[$key][39]));
+ $excel_contract_all_array[$key][13] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if ($isBoga == 1) {
+ $excel_contract_boga_array[$key][12] = $excel_contract_all_array[$key][12];
+ $excel_contract_boga_array[$key][13] = $excel_contract_all_array[$key][13];
+ } else {
+ $excel_contract_noboga_array[$key][12] = $excel_contract_all_array[$key][12];
+ $excel_contract_noboga_array[$key][13] = $excel_contract_all_array[$key][13];
+ }
+ }
+ $excel_contract_array[$key][37] = number_format(round($excel_contract_array[$key][37]));
+ $excel_contract_array[$key][39] = number_format(round($excel_contract_array[$key][39]));
+
+ break;
+ case "安裝款":
+ $excel_contract_array[$key][42] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--';
+ $excel_contract_array[$key][43] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? number_format(round($payvalue['PlanPayAmt'])) : '0';
+ $excel_contract_array[$key][44] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0;
+ $excel_contract_array[$key][45] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? number_format(round($payvalue['invoice_budget'])) : '0';
+ $excel_contract_array[$key][46] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0;
+ $excel_contract_array[$key][47] = number_format(round($excel_contract_array[$key][44] - $excel_contract_array[$key][46]));
+ $excel_contract_array[$key][48] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if (isset($excel_contract_all_array[$key])) {
+ $excel_contract_all_array[$key][14] = number_format(round($excel_contract_array[$key][44] - $excel_contract_array[$key][46]));
+ $excel_contract_all_array[$key][15] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ $excel_contract_noboga_array[$key][14] = $excel_contract_all_array[$key][14];
+ $excel_contract_noboga_array[$key][15] = $excel_contract_all_array[$key][15];
+ }
+ $excel_contract_array[$key][44] = number_format(round($excel_contract_array[$key][44]));
+ $excel_contract_array[$key][46] = number_format(round($excel_contract_array[$key][46]));
+ break;
+ case "試車款":
+ $excel_contract_array[$key][49] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--';
+ $excel_contract_array[$key][50] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? number_format(round($payvalue['PlanPayAmt'])) : '0';
+ $excel_contract_array[$key][51] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0;
+ $excel_contract_array[$key][52] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? number_format(round($payvalue['invoice_budget'])) : '0';
+ $excel_contract_array[$key][53] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0;
+ $excel_contract_array[$key][54] = number_format(round($excel_contract_array[$key][51] - $excel_contract_array[$key][53]));
+ $excel_contract_array[$key][55] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if (isset($excel_contract_all_array[$key])) {
+ $excel_contract_all_array[$key][16] = number_format(round($excel_contract_array[$key][51] - $excel_contract_array[$key][53]));
+ $excel_contract_all_array[$key][17] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if ($isBoga == 1) {
+ $excel_contract_boga_array[$key][16] = $excel_contract_all_array[$key][16];
+ $excel_contract_boga_array[$key][17] = $excel_contract_all_array[$key][17];
+ } else {
+ $excel_contract_noboga_array[$key][16] = $excel_contract_all_array[$key][16];
+ $excel_contract_noboga_array[$key][17] = $excel_contract_all_array[$key][17];
+ }
+ }
+ $excel_contract_array[$key][51] = number_format(round($excel_contract_array[$key][51]));
+ $excel_contract_array[$key][53] = number_format(round($excel_contract_array[$key][53]));
+
+ break;
+ case "官檢驗收款":
+ $excel_contract_array[$key][56] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--';
+ $excel_contract_array[$key][57] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? number_format(round($payvalue['PlanPayAmt'])) : '0';
+ $excel_contract_array[$key][58] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0;
+ $excel_contract_array[$key][59] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? number_format(round($payvalue['invoice_budget'])) : '0';
+ $excel_contract_array[$key][60] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0;
+ $excel_contract_array[$key][61] = number_format(round($excel_contract_array[$key][58] - $excel_contract_array[$key][60]));
+ $excel_contract_array[$key][62] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if (isset($excel_contract_all_array[$key])) {
+ $excel_contract_all_array[$key][18] = number_format(round($excel_contract_array[$key][58] - $excel_contract_array[$key][60]));
+ $excel_contract_all_array[$key][19] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+
+ $excel_contract_noboga_array[$key][18] = $excel_contract_all_array[$key][18];
+ $excel_contract_noboga_array[$key][19] = $excel_contract_all_array[$key][19];
+ }
+ $excel_contract_array[$key][58] = number_format(round($excel_contract_array[$key][58]));
+ $excel_contract_array[$key][60] = number_format(round($excel_contract_array[$key][60]));
+
+ break;
+ case "交車款":
+ $excel_contract_array[$key][63] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--';
+ $excel_contract_array[$key][64] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? number_format(round($payvalue['PlanPayAmt'])) : '0';
+ $excel_contract_array[$key][65] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0;
+ $excel_contract_array[$key][66] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? number_format(round($payvalue['invoice_budget'])) : '0';
+ $excel_contract_array[$key][67] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0;
+ $excel_contract_array[$key][68] = number_format(round($excel_contract_array[$key][65] - $excel_contract_array[$key][67]));
+ $excel_contract_array[$key][69] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if (isset($excel_contract_all_array[$key])) {
+ $excel_contract_all_array[$key][20] = number_format(round($excel_contract_array[$key][65] - $excel_contract_array[$key][67]));
+ $excel_contract_all_array[$key][21] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ $excel_contract_noboga_array[$key][20] = $excel_contract_all_array[$key][20];
+ $excel_contract_noboga_array[$key][21] = $excel_contract_all_array[$key][21];
+ }
+ $excel_contract_array[$key][65] = number_format(round($excel_contract_array[$key][65]));
+ $excel_contract_array[$key][67] = number_format(round($excel_contract_array[$key][67]));
+
+ break;
+ case "尾款":
+ $excel_contract_array[$key][70] = (isset($payvalue['PayStage']) && !is_null($payvalue['PayStage'])) ? $payvalue['PayStage'] : '--';
+ $excel_contract_array[$key][71] = (isset($payvalue['PlanPayAmt']) && !is_null($payvalue['PlanPayAmt'])) ? number_format(round($payvalue['PlanPayAmt'])) : '0';
+ $excel_contract_array[$key][72] = (isset($payvalue['receivable_budget']) && !is_null($payvalue['receivable_budget'])) ? $payvalue['receivable_budget'] : 0;
+ $excel_contract_array[$key][73] = (isset($payvalue['invoice_budget']) && !is_null($payvalue['invoice_budget'])) ? number_format(round($payvalue['invoice_budget'])) : '0';
+ $excel_contract_array[$key][74] = (isset($payvalue['received_budget']) && !is_null($payvalue['received_budget'])) ? $payvalue['received_budget'] : 0;
+ $excel_contract_array[$key][75] = number_format(round($excel_contract_array[$key][72] - $excel_contract_array[$key][74]));
+ $excel_contract_array[$key][76] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if (isset($excel_contract_all_array[$key])) {
+ $excel_contract_all_array[$key][22] = number_format(round($excel_contract_array[$key][72] - $excel_contract_array[$key][74]));
+ $excel_contract_all_array[$key][23] = (isset($payvalue['collect_month']) && !is_null($payvalue['collect_month'])) ? number_format(round($payvalue['collect_month'])) : '0';
+ if ($isBoga == 1) {
+ $excel_contract_boga_array[$key][22] = $excel_contract_all_array[$key][22];
+ $excel_contract_boga_array[$key][23] = $excel_contract_all_array[$key][23];
+ } else {
+ $excel_contract_noboga_array[$key][22] = $excel_contract_all_array[$key][22];
+ $excel_contract_noboga_array[$key][23] = $excel_contract_all_array[$key][23];
+ }
+ }
+ $excel_contract_array[$key][72] = number_format(round($excel_contract_array[$key][72]));
+ $excel_contract_array[$key][74] = number_format(round($excel_contract_array[$key][74]));
+
+ break;
+ }
+ }
+ }
+ // 0 作番號; 1 合約號; 2 合約單據日期; 3 客戶編號; 4 客戶名稱; 5 客戶地址; 6 部門ID; 7 部門名稱; 8 營業員工號; 9 營業員名稱; 10 部門主管工號; 11 部門主管名稱;
+ // 12 作番總金額; 13 A40001 金額; 14 A40008 金額; 15 目前應收金額; 16 已開發票金額; 17 已收金額; 18 催收金額; 19 催收次數; 20 作番狀態
+ if (isset($value['facility']) && is_iterable($value['facility'])) {
+ foreach ($value['facility'] as $fkey => $fvalue) {
+ $excel_facility_array[$fkey] = [$fkey, $key, $value['BillDate']];
+ $excel_facility_array[$key][2] = (isset($value['CustomerId']) && !is_null($value['CustomerId'])) ? $value['CustomerId'] : '';
+ $excel_facility_array[$key][3] = (isset($value['CustomerName']) && !is_null($value['CustomerName'])) ? $value['CustomerName'] : '';
+ $excel_facility_array[$key][4] = (isset($value['CustomerAddress']) && !is_null($value['CustomerAddress'])) ? $value['CustomerAddress'] : '';
+ $excel_facility_array[$key][5] = (isset($value['DeptId']) && !is_null($value['DeptId'])) ? $value['DeptId'] : '';
+ $excel_facility_array[$key][6] = (isset($value['DeptName']) && !is_null($value['DeptName'])) ? $value['DeptName'] : '';
+ $excel_facility_array[$key][7] = (isset($value['PersonId']) && !is_null($value['PersonId'])) ? $value['PersonId'] : '';
+ $excel_facility_array[$key][8] = (isset($value['PersonName']) && !is_null($value['PersonName'])) ? $value['PersonName'] : '';
+ $excel_facility_array[$key][9] = (isset($value['ManagerId']) && !is_null($value['ManagerId'])) ? $value['ManagerId'] : '';
+ }
+ }
}
+
+$total_data = json_encode($excel_contract_all_array);
+$boga_data = json_encode($excel_contract_boga_array);
+$noboga_data = json_encode($excel_contract_noboga_array);
+?>
+
+
+
合約號 | +部門 | +主管 | +營業員 | +客戶 | + +作番狀態 | +合約-設備金額 | +合約-安裝金額 | +合約總金額 | +合約目前應收 | +已開發票金額 | +已收金額金額 | +催收金額金額 | +催收次數 | +作番數量 | + +訂金 名稱 |
+ 訂金 合約金額 |
+ 訂金 應收金額 |
+ 訂金 已開金額 |
+ 訂金 已收金額 |
+ 訂金 催收金額 |
+ 訂金 催收次數 |
+
+ 二次款 名稱 |
+ 二次款 合約金額 |
+ 二次款 應收金額 |
+ 二次款 已開金額 |
+ 二次款 已收金額 |
+ 二次款 催收金額 |
+ 二次款 催收次數 |
+
+ 貨抵工地款 名稱 |
+ 貨抵工地款 合約金額 |
+ 貨抵工地款 應收金額 |
+ 貨抵工地款 已開金額 |
+ 貨抵工地款 已收金額 |
+ 貨抵工地款 催收金額 |
+ 貨抵工地款 催收次數 |
+
+ 安裝款 名稱 |
+ 安裝款 合約金額 |
+ 安裝款 應收金額 |
+ 安裝款 已開金額 |
+ 安裝款 已收金額 |
+ 安裝款 催收金額 |
+ 安裝款 催收次數 |
+
+ 試車款 名稱 |
+ 試車款 合約金額 |
+ 試車款 應收金額 |
+ 試車款 已開金額 |
+ 試車款 已收金額 |
+ 試車款 催收金額 |
+ 試車款 催收次數 |
+
+ 官檢驗收款 名稱 |
+ 官檢驗收款 合約金額 |
+ 官檢驗收款 應收金額 |
+ 官檢驗收款 已開金額 |
+ 官檢驗收款 已收金額 |
+ 官檢驗收款 催收金額 |
+ 官檢驗收款 催收次數 |
+
+ 交車款 名稱 |
+ 交車款 合約金額 |
+ 交車款 應收金額 |
+ 交車款 已開金額 |
+ 交車款 已收金額 |
+ 交車款 催收金額 |
+ 交車款 催收次數 |
+
+ 尾款 名稱 |
+ 尾款 合約金額 |
+ 尾款 應收金額 |
+ 尾款 已開金額 |
+ 尾款 已收金額 |
+ 尾款 催收金額 |
+ 尾款 催收次數 |
+
+
+
+
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
= $key ?> | += $value['DeptId'] . " " . $value['DeptName'] ?> |
+ = $value['ManagerId'] . " " . $value['ManagerName'] ?> |
+ = $value['PersonId'] . " " . $value['PersonName'] ?> |
+ = $value['CustomerId'] . " " . $value['CustomerName'] ?> |
+
+ = $value['facility_status'] ?> | += number_format(round($value['A40001'])) ?> | += number_format(round($value['A40008'])) ?> | += number_format(round($value['total_budget'])) ?> | += number_format(round($value['receivable_budget'])) ?> | += number_format(round($value['invoice_budget'])) ?> | += number_format(round($value['received_budget'])) ?> | += number_format(round($value['collect_budget'])) ?> | += $value['collect_month'] ?> | += $value['facility_num'] ?> | + += $excel_contract_array[$key][21] ?> | += $excel_contract_array[$key][22] ?> | += $excel_contract_array[$key][23] ?> | += $excel_contract_array[$key][24] ?> | += $excel_contract_array[$key][25] ?> | += $excel_contract_array[$key][26] ?> | += $excel_contract_array[$key][27] ?> | + += $excel_contract_array[$key][28] ?> | += $excel_contract_array[$key][29] ?> | += $excel_contract_array[$key][30] ?> | += $excel_contract_array[$key][31] ?> | += $excel_contract_array[$key][32] ?> | += $excel_contract_array[$key][33] ?> | += $excel_contract_array[$key][34] ?> | + += $excel_contract_array[$key][35] ?> | += $excel_contract_array[$key][36] ?> | += $excel_contract_array[$key][37] ?> | += $excel_contract_array[$key][38] ?> | += $excel_contract_array[$key][39] ?> | += $excel_contract_array[$key][40] ?> | += $excel_contract_array[$key][41] ?> | + += $excel_contract_array[$key][42] ?> | += $excel_contract_array[$key][43] ?> | += $excel_contract_array[$key][44] ?> | += $excel_contract_array[$key][45] ?> | += $excel_contract_array[$key][46] ?> | += $excel_contract_array[$key][47] ?> | += $excel_contract_array[$key][48] ?> | + += $excel_contract_array[$key][49] ?> | += $excel_contract_array[$key][50] ?> | += $excel_contract_array[$key][51] ?> | += $excel_contract_array[$key][52] ?> | += $excel_contract_array[$key][53] ?> | += $excel_contract_array[$key][54] ?> | += $excel_contract_array[$key][55] ?> | + += $excel_contract_array[$key][56] ?> | += $excel_contract_array[$key][57] ?> | += $excel_contract_array[$key][58] ?> | += $excel_contract_array[$key][59] ?> | += $excel_contract_array[$key][60] ?> | += $excel_contract_array[$key][61] ?> | += $excel_contract_array[$key][62] ?> | + += $excel_contract_array[$key][63] ?> | += $excel_contract_array[$key][64] ?> | += $excel_contract_array[$key][65] ?> | += $excel_contract_array[$key][66] ?> | += $excel_contract_array[$key][67] ?> | += $excel_contract_array[$key][68] ?> | += $excel_contract_array[$key][69] ?> | + += $excel_contract_array[$key][70] ?> | += $excel_contract_array[$key][71] ?> | += $excel_contract_array[$key][72] ?> | += $excel_contract_array[$key][73] ?> | += $excel_contract_array[$key][74] ?> | += $excel_contract_array[$key][75] ?> | += isset($excel_contract_array[$key][76]) ? $excel_contract_array[$key][76] : 0 ?> | + +
'; +// print_r($result['bonus_json']); +// echo ''; +$bonus_json = json_decode($result['bonus_json']); + +$paykind = [ + 'monthly' => '月繳', + 'bimonthly' => '雙月繳', + 'quarterly' => '季繳', + 'semiannually' => '半年繳', + 'annually' => '年繳' +]; + +$maintain_type = [ + 'new' => '新簽約', + 'free_to_charge' => '免保轉有費', + 'renew_priceissue' => '續簽約' +]; +?> + + + + + + + + + + +
+ 獎金計算+ |
+ |||||||
+ 獎金確認項+ |
+ + + + | +||||||
合約號 | ++ + | +合約類別 | +
+
+ 未填寫 + |
+ 作番號 | ++ + | + +獎金適用版本 | ++ + | +
保養類別 | ++ + | +付款方式 | ++ + | +合約付款日 | ++ + | +應發獎金 | ++ + | +
作番總價 | ++ + | +牌價 | ++ + | +服務費 | ++ + | +價率 | ++ + | + +
實發獎金 | ++ + | +實發時間 | ++ | +備註 | ++ | + | + |
'; - // print_r(json_encode($data)); - // echo ''; $api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; $validation = get_Auth(); + echo '
'; + print_r(json_encode($data)); + echo ''; $header = [ - "CHI_Authorization :" . $validation + "CHI_Authorization :" . $validation, + "GroupId:TEST" ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $api_url); // 设置请求的URL @@ -20,6 +21,7 @@ function T8API($data) curl_setopt($ch, CURLOPT_POST, 1); // 使用 POST curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); + if ($response === false) { echo 'Curl error: ' . curl_error($ch); } else { @@ -32,6 +34,7 @@ function T8API($data) // print_r($result); return $result; } + return $result; } curl_close($ch); diff --git a/wms/contract/api/getComboNo.php b/wms/contract/api/getComboNo.php index c258be15..265d4096 100644 --- a/wms/contract/api/getComboNo.php +++ b/wms/contract/api/getComboNo.php @@ -1,59 +1,62 @@ -'BW002', - 'month'=>'EM002', - 'quarter'=>'EQ002', - 'half'=>'HY002', - 'year'=>'EY002' - ]; - private $bwarr = [ - 'week','month','week','month','week','quarter', - 'week','month','week','month','week','half', - 'week','month','week','month','week','quarter', - 'week','month','week','month','week','year' - ]; - private $emarr = [ - 'month','month','quarter','month','month','half', - 'month','month','quarter','month','month','year' - ]; - private $combo; - private $startdate; - private $enddate; - public function __construct($combo, $startdate, $enddate){ - $this->combo = $combo; - $this->startdate = $startdate; - $this->enddate = $enddate; - } - public function getComboNo(){ - $comboarr = (array) $this->combo === 'bw' ? $this->bwarr : $this->emarr; - - $startdate = new DateTime($this->startdate); - $enddate = new DateTime($this->enddate); - - $interval = date_diff($startdate, $enddate); - - $months = $interval->y * 12 + $interval->m; - $months = $this->combo === 'bw' ? $months*2 : $months; - - $newarr = []; - $idx = 0; - $ori_first_month = date('m', strtotime($this->startdate)); - $first_day = date('Y-m-d', strtotime($this->startdate. ' + 3 days')); - $new_first_month = date('m', strtotime($first_day)); - if($ori_first_month != $new_first_month){ - $first_day = date('Y-m-t', strtotime($this->startdate)); - } - $scheduleDate = new DateTime($first_day); - for ($i = 0; $i < $months; $i++){ - $newarr[] = [$this->comboarr[$comboarr[$idx]], $scheduleDate->format("Y-m-d")]; - $idx ++; - $scheduleDate = $startdate->modify("+1 month"); - if($idx >= count($comboarr)){ - $idx = 0; - } - } - return json_encode($newarr); - } -} \ No newline at end of file + 'BW002', + 'month' => 'EM002', + 'quarter' => 'EQ002', + 'half' => 'HY002', + 'year' => 'EY002' + ]; + private $bwarr = [ + 'week', 'month', 'week', 'month', 'week', 'quarter', + 'week', 'month', 'week', 'month', 'week', 'half', + 'week', 'month', 'week', 'month', 'week', 'quarter', + 'week', 'month', 'week', 'month', 'week', 'year' + ]; + private $emarr = [ + 'month', 'month', 'quarter', 'month', 'month', 'half', + 'month', 'month', 'quarter', 'month', 'month', 'year' + ]; + private $combo; + private $startdate; + private $enddate; + public function __construct($combo, $startdate, $enddate) + { + $this->combo = $combo; + $this->startdate = $startdate; + $this->enddate = $enddate; + } + public function getComboNo() + { + $comboarr = (array) $this->combo === 'bw' ? $this->bwarr : $this->emarr; + + $startdate = new DateTime($this->startdate); + $enddate = new DateTime($this->enddate); + + $interval = date_diff($startdate, $enddate); + + $months = $interval->y * 12 + $interval->m; + $months = $this->combo === 'bw' ? $months * 2 : $months; + + $newarr = []; + $idx = 0; + $ori_first_month = date('m', strtotime($this->startdate)); + $first_day = date('Y-m-d', strtotime($this->startdate . ' + 3 days')); + $new_first_month = date('m', strtotime($first_day)); + if ($ori_first_month != $new_first_month) { + $first_day = date('Y-m-d', strtotime($this->startdate)); + } + $scheduleDate = new DateTime($first_day); + for ($i = 0; $i <= $months; $i++) { + $newarr[] = [$this->comboarr[$comboarr[$idx]], $scheduleDate->format("Y-m-d")]; + $idx++; + $scheduleDate = $scheduleDate->modify("+1 month"); + if ($idx >= count($comboarr)) { + $idx = 0; + } + } + return json_encode($newarr); + } +} diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php index 0f7f89c8..253e8d54 100644 --- a/wms/contract/api/getContractData.php +++ b/wms/contract/api/getContractData.php @@ -1,7 +1,7 @@ -prepare($sql_str); $stmt->bindParam(':vol_no', $contractno); $stmt->execute(); - $contract= $stmt->fetch(PDO::FETCH_ASSOC); + $contract = $stmt->fetch(PDO::FETCH_ASSOC); - if(empty($contract)){ + if (empty($contract)) { echo false; exit; } @@ -21,42 +21,99 @@ if(isset($_GET['contractno']) && $_GET['contractno']!='' && isset($_GET['contrac $stmt = $conn->prepare($sql_str); $stmt->bindParam(':apply_key', $apply_key); $stmt->execute(); - $elevators= $stmt->fetchAll(PDO::FETCH_ASSOC); + $elevators = $stmt->fetchAll(PDO::FETCH_ASSOC); $count = COUNT($elevators); + // foreach ($elevators as $key => $elevator) { + + // $elevator['discount'] = ($elevator['sold_price'] / $elevator['stand_price']) * 100; + // } $contract['elevators'] = $elevators; $contract['num'] = $count; $contractResponse = json_encode($contract); - + // 設定回應標頭為 JSON header('Content-Type: application/json'); - + // 將 JSON 回應返回給客戶端 echo $contractResponse; // echo json_encode($contractResponse); - }catch (PDOException $e ){ - die("ERROR!!!: ". $e->getMessage()); + } catch (PDOException $e) { + die("ERROR!!!: " . $e->getMessage()); } } -if(isset($_GET['contractno']) && $_GET['contractno']!='' && isset($_GET['contracttype']) && $_GET['contracttype']=='m'){ - try{ +if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 'm') { + try { $contractno = $_GET['contractno']; - $sql_str = "SELECT * FROM hope_elevator_customer WHERE vol_no = :vol_no ORDER BY created_at DESC"; + $sql_str = "SELECT a.*,b.lm_tel,b.uscc,b.manager,b.linkman FROM pricereview_main AS a + LEFT JOIN hope_elevator_customer AS b ON a.contractno = b.vol_no + WHERE a.contractno = :contractno AND a.status != 'YN' "; $stmt = $conn->prepare($sql_str); - $stmt->bindParam(':vol_no', $contractno); + $stmt->bindParam(':contractno', $contractno); $stmt->execute(); - $contract= $stmt->fetch(PDO::FETCH_ASSOC); + $contract = $stmt->fetch(PDO::FETCH_ASSOC); + + $salesman = $contract['person']; + $sql = "SELECT * FROM account WHERE accountid = :accountid "; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':accountid', $salesman); + $stmt->execute(); + $account_detail = $stmt->fetch(PDO::FETCH_ASSOC); + $contract['manager'] = $account_detail['manager']; + $contract['salesman_departno'] = $account_detail['department_id']; + + + $mid = $contract['id']; + $sql = "SELECT * FROM pricereview_item WHERE mid = :mid AND item_group = 'A' "; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':mid', $mid); + $stmt->execute(); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + $elevators_detail_arr = []; + foreach ($results as $keys => $result) { + $note = explode(',', $result['note']); + $result['spec'] = $note[0]; //型號 + $result['person'] = $note[1]; // 人承 + $result['floor'] = $note[2]; // 樓層 + $result['speed'] = $note[3]; // 速度 + for ($i = 0; $i < $result['item_qty']; $i++) { + $result['item_no'] = $i + 1; + array_push($elevators_detail_arr, $result); + } + } + $count = COUNT($elevators_detail_arr); + + $contract['elevators'] = $results; + $contract['elevators_detail_arr'] = $elevators_detail_arr; + $contract['nums'] = $count; + // echo '
'; + // print_r($contract); + // echo ''; + // exit; $contractResponse = json_encode($contract); - // 設定回應標頭為 JSON header('Content-Type: application/json'); - + // 將 JSON 回應返回給客戶端 echo $contractResponse; - }catch (PDOException $e ){ - die("ERROR!!!: ". $e->getMessage()); + } catch (PDOException $e) { + die("ERROR!!!: " . $e->getMessage()); } } +if (!empty($_GET['contracttype']) && $_GET['contracttype'] == 'accountManger' && !empty($_GET['salesman'])) { + try { + $salesman = $_GET['salesman']; + $sql = "SELECT manager FROM account WHERE accountid = :accountid"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':accountid', $salesman); + $stmt->execute(); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + header('Content-Type:application/json'); + echo json_encode($result); + } catch (PDOException $e) { + die("ERROR!!!:" . $e->getMessage()); + } +} diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index 2a9e082c..29038b9f 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -18,7 +18,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $phone = !empty($_POST['phone']) ? $_POST['phone'] : null; $email = !empty($_POST['email']) ? $_POST['email'] : null; $mworker = !empty($_POST['mworker']) ? $_POST['mworker'] : null; - $mcycle = !empty($_POST['mcycle']) ? $_POST['mcycle'] : null; + // $mcycle = !empty($_POST['mcycle']) ? $_POST['mcycle'] : null; $salesman = !empty($_POST['salesman']) ? $_POST['salesman'] : null; $contract_begin_date = !empty($_POST['contract_begin_date']) ? $_POST['contract_begin_date'] : null; $contract_end_date = !empty($_POST['contract_end_date']) ? $_POST['contract_end_date'] : null; @@ -35,17 +35,53 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $files = !empty($_FILES['files']) ? $_FILES['files'] : null; $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; $payType = !empty($_POST['payType']) ? $_POST['payType'] : null; + + $sql = "SELECT * FROM account WHERE accountid = '$salesman'"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $accountData = $stmt->fetch(PDO::FETCH_ASSOC); + + $depId = $accountData['department_id']; // validate + //create facility table + $createFacilityNo = new CreateFacilityNo(); + $dailyNecessities = [ + 'MAE100' => 'X', + 'MAM200' => 'W', + 'MAH100' => 'H', + 'MAQ100' => 'Z', + 'MAF100' => 'F', + 'MAZ100' => 'B', + ]; + + $maintain_times = [ + '1' => 'em', //月保 + '2' => 'bw' // 雙周保 + ]; + $facility_arr = []; + foreach ($elevators as $elevator) { + $facility_arr[] = $dailyNecessities[$elevator['spec']]; + } + echo json_encode($facility_arr); + // 電梯做番號 + $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); + // if ($user_id == 'M0225') { + // echo '
'; + // print_r($facilityno); + // echo ''; + // exit(); + // } + echo json_encode($facilityno); + /// 獎金計算 $fail_arr = []; if ($contractno === '') return $fail_arr[] = '合約號為必填'; - if ($total_price == '') $fail_arr[] = '合約總價為必填'; if ($vat == '') $fail_arr[] = '統一編號為必填'; if ($mtype == '') $fail_arr[] = '維修型態為必填'; if ($phone == '') $fail_arr[] = '客戶電話為必填'; - if ($email == '') $fail_arr[] = 'Email為必填'; + // if ($email == '') $fail_arr[] = 'Email為必填'; if ($mworker == '') $fail_arr[] = '保養員為必填'; - if ($mcycle == '') $fail_arr[] = '保養頻率為必填'; + // if ($mcycle == '') $fail_arr[] = '保養頻率為必填'; if ($salesman == '') $fail_arr[] = '營業員為必填'; if ($contract_begin_date == '') $fail_arr[] = '合約開始時間為必填'; if ($contract_end_date == '') $fail_arr[] = '合約結束時間為必填'; @@ -63,7 +99,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c echo json_encode($fail_arr); exit(); } - + T8insert($_POST, $facilityno, $depId); + bonusCreate($_POST, $facilityno, $conn); //create account table $accounttype = "A"; $accountid = $vat; @@ -75,6 +112,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $create_at = date('Y-m-d H:i:s'); $conn->beginTransaction(); + // bonusCreate($_POST, $facilityno, $conn); + // exit(); $sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)"; $stmt = $conn->prepare($sql_str); @@ -127,30 +166,35 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->execute(); //create facility table - $createFacilityNo = new CreateFacilityNo(); - $dailyNecessities = [ - 'MAE100' => 'X', - 'MAM200' => 'W', - 'MAH100' => 'H', - 'MAQ100' => 'Z', - 'MAF100' => 'F', - 'MAZ100' => 'B', - ]; - $facility_arr = []; - foreach ($elevators as $elevator) { - $facility_arr[] = $dailyNecessities[$elevator['spec']]; - } - echo json_encode($facility_arr); - // 電梯做番號 - $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); - // if ($user_id == 'M0225') { - // echo '
'; - // print_r($facilityno); - // echo ''; - // exit(); + // $createFacilityNo = new CreateFacilityNo(); + // $dailyNecessities = [ + // 'MAE100' => 'X', + // 'MAM200' => 'W', + // 'MAH100' => 'H', + // 'MAQ100' => 'Z', + // 'MAF100' => 'F', + // 'MAZ100' => 'B', + // ]; + + // $maintain_times = [ + // '1' => 'em', //月保 + // '2' => 'bw' // 雙周保 + // ]; + // $facility_arr = []; + // foreach ($elevators as $elevator) { + // $facility_arr[] = $dailyNecessities[$elevator['spec']]; // } - echo json_encode($facilityno); - echo '-------'; + // echo json_encode($facility_arr); + // // 電梯做番號 + // $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); + // // if ($user_id == 'M0225') { + // // echo '
'; + // // print_r($facilityno); + // // echo ''; + // // exit(); + // // } + // echo json_encode($facilityno); + // echo '-------'; $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid"; $stmt = $conn->prepare($sql_str); $stmt->bindParam(':accountid', $mworker); @@ -162,6 +206,12 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $repairerid = $mworker; $repairername = $worker['name']; foreach ($elevators as $idx => $elevator) { + // 民國年轉換西元年 + $ROCuseful_date = $elevator['useful_date']; + $click = explode("-", $ROCuseful_date); + $click[0] = intval($click[0]) + 1911; + $ADuseful_date = implode("-", $click); + $sql_str = "INSERT INTO facility (contractno, define, facilityno, latitude, longitude, customerid, weight, numberofpassenger, numberofstop, numberoffloor, opentype, speed, repairtype, maintainance, facility_kind, address, repairerid, repairername, creater, create_at, area, takecertificatedate, licensedate) VALUES (:contractno, :define, :facilityno, :latitude, :longitude, :customerid, :weight, :numberofpassenger, :numberofstop, :numberoffloor, :opentype, :speed, :repairtype, :maintainance, :facility_kind, :address, :repairerid, :repairername, :creater, :create_at, :area, :takecertificatedate, :licensedate)"; $stmt = $conn->prepare($sql_str); @@ -187,15 +237,17 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(':create_at', $create_at); $stmt->bindParam(':area', $area); $stmt->bindParam(':takecertificatedate', $elevator['takecertificatedate']); - $stmt->bindParam(':licensedate', $elevator['useful_date']); + $stmt->bindParam(':licensedate', $ADuseful_date); $result = $stmt->execute(); } //create schedule table - $comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date); - $comboArr = json_decode($comboNo->getComboNo(), true); + // $comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date); + // $comboArr = json_decode($comboNo->getComboNo(), true); foreach ($facilityno as $no) { + $comboNo = new CreateComboNo($maintain_times[$elevator['maintain_times']], $contract_begin_date, $contract_end_date); + $comboArr = json_decode($comboNo->getComboNo(), true); foreach ($comboArr as $combo) { $sql_str = 'INSERT INTO schedule (contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES (:contractno, :facilityno, :combono, :repairerid, :repairername, :duedate, :creater, :create_at)'; $stmt = $conn->prepare($sql_str); @@ -218,7 +270,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $customer_phone = $phone; $customer_email = $email; $repairman = $mworker; - $cycle = $mcycle; + // $cycle = $mcycle; $contact_person = $partyA; $contact_address = $partyAaddress; $contact_phone = $partyAphone; @@ -285,8 +337,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c } else { $files = null; } - $sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price,payType, customer_phone, customer_email, repairman, cycle, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by) - VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :payType ,:customer_phone, :customer_email, :repairman, :cycle, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by)"; + $sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price,payType, customer_phone, customer_email, repairman, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by) + VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :payType ,:customer_phone, :customer_email, :repairman, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by)"; $stmt = $conn->prepare($sql_str); $stmt->bindParam(":contract_no", $contractno); $stmt->bindParam(":contract_type", $contract_type); @@ -299,7 +351,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->bindParam(":customer_phone", $customer_phone); $stmt->bindParam(":customer_email", $customer_email); $stmt->bindParam(":repairman", $repairman); - $stmt->bindParam(":cycle", $cycle); + // $stmt->bindParam(":cycle", $cycle); // 保養頻率在做番上,這邊不 insert。 $stmt->bindParam(":contact_person", $contact_person); $stmt->bindParam(":contact_address", $contact_address); $stmt->bindParam(":contact_phone", $contact_phone); @@ -316,20 +368,9 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->execute(); - // $date = date('Y-m-sH-s-i'); - // $createTime = str_replace("-", '', $date); - // $sql = "INSERT INTO comCustomer(BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime)VALUES(:BizPartnerId,:PersonId,:CreatorId,1,:InvoiceAddress,:CreateTime)"; - // $stmt = $connT8->prepare($sql); - // $stmt->bindParam(':BizPartnerId', $contractno); - // $stmt->bindParam(':PersonId', $salesman); - // $stmt->bindParam(':CreatorId', $user_id); - // $stmt->bindParam(':InvoiceAddress', $address); - // $stmt->bindParam(':CreateTime', $createTime); - - // $stmt->execute(); - T8insert($_POST, $facilityno); + // T8insert($_POST, $facilityno); - header('Content-Type: application/json'); + // header('Content-Type: application/json'); $jsonData = json_encode($files); $conn->commit(); @@ -341,7 +382,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c } }; -function T8insert($data, $facilityno) +function T8insert($data, $facilityno, $depId) { require_once("../connt8.php"); // 引入 T8 API 連線 @@ -362,7 +403,6 @@ function T8insert($data, $facilityno) $elevators = !empty($data['elevators']) ? json_decode($data['elevators'], true) : []; //電梯 $area = !empty($data['area']) ? $data['area'] : null; //縣市 Ex. A->台北 , B-> ..。 $payType = !empty($data['payType']) ? $data['payType'] : null; - $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; @@ -372,9 +412,9 @@ function T8insert($data, $facilityno) $stmt = $conn->prepare($sql); $stmt->bindParam(':BizPartnerId', $contractno); $stmt->execute(); - $result = $stmt->fetchAll(PDO::FETCH_ASSOC); - $date = date('Y-m-sH-s-i'); - $date_1 = date('Y-m-s'); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + $date = date('Y-m-dH-s-i'); + $date_1 = date('Y-m-d'); $createTime = str_replace("-", '', $date); $insertTime = str_replace('-', '', $date_1); $beginDate = str_replace("-", '', $contract_begin_date); @@ -493,12 +533,12 @@ function T8insert($data, $facilityno) // echo '
'; // print_r($elevator); // echo ''; - + $facility_no = $facilityno[$index]; $sql = "INSERT INTO comMaterial (FOrgid,MaterialId,MaterialTypeId,MaterialCategoryId,CreatorId,CreateTime) VALUES ('1000',:MaterialId,'10','E',:CreatorId,:CreateTime)"; $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facilityno[$index]); + $stmt->bindParam(':MaterialId', $facility_no); $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':CreateTime', $createTime); $stmt->execute(); @@ -507,7 +547,7 @@ function T8insert($data, $facilityno) (MaterialTypeId,MaterialId,MaterialName,MaterialCategoryId,IsInUsed,UnitId,CreatorId,CreateTime) VALUES ('10',:MaterialId,:MaterialName,'E',1,'SET',:CreatorId,:CreateTime)"; $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facilityno[$index]); + $stmt->bindParam(':MaterialId', $facility_no); $stmt->bindParam(':MaterialName', $customer); $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':CreateTime', $createTime); @@ -517,7 +557,7 @@ function T8insert($data, $facilityno) (Orgid,MaterialTypeId,MaterialId,CurrId,SUnitId,TaxId,CreatorId,CreateTime) VALUES ('1000','10',:MaterialId,'TWD','SET','ST005',:CreatorId,:CreateTime)"; $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facilityno[$index]); + $stmt->bindParam(':MaterialId', $facility_no); $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':CreateTime', $createTime); $stmt->execute(); @@ -533,6 +573,9 @@ function T8insert($data, $facilityno) //分幾期 => 總共保養月 / 分期月 $SQuantity = $elevator['maintain_months'] / $IncomeId[$payType]; + $date_1 = getNext25thDate($contract_begin_date); + + // 依每台電梯去加入各個的付款項 for ($i = 0; $i < $IncomeId[$payType]; $i++) { $row++; @@ -547,14 +590,16 @@ function T8insert($data, $facilityno) "RowCode" => $row, "RowNo" => $row, "ItemType" => 1, - "SPrice" => $elevator['sold_price'], + "SPrice" => intval($elevator['sold_price']), "SQuantity" => $SQuantity, "ProjectId" => "$contractno", - "FromSourceTag" => 0, - "CU_MaterialId" => "$facilityno[$index]", - "CU_EstPayDate" => "$payDay" + "CU_MaterialId" => "$facility_no", + "CU_EstPayDate" => intval($payDay) ]; $salIncomeApplyDetail_rows[] = $rows_data; + // echo '
'; + // print_r($salIncomeApplyDetail_rows); + // echo ''; } } @@ -564,7 +609,7 @@ function T8insert($data, $facilityno) // $insertime = settype($insertTime, 'integer'); $salIncomeApplyMaster_rows = [ "BillNo" => "$contractno", - "BillDate" => $insertTime, + "BillDate" => intval($insertTime), "OrgId" => "1000", "FOrgId" => "1000", "TypeId" => "RAS", @@ -578,7 +623,10 @@ function T8insert($data, $facilityno) "DueToId" => "$contractno", "TaxId" => "ST005", "CompId" => "1001", - "CreatorId" => "$user_id" + "CreatorId" => "$user_id", + "CreateTime" => intval($insertTime), + "DeptId" => "$depId", + "IsPriceWithTax" => 1 ]; $salIncomeApplyMaster = [ @@ -593,6 +641,9 @@ function T8insert($data, $facilityno) $API_body[] = $salIncomeApplyMaster; $API_body[] = $salIncomeApplyDetail; // 呼叫 API + // echo '
'; + // print_r($API_body); + // echo ''; $result = T8API($API_body); if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') { @@ -601,3 +652,102 @@ function T8insert($data, $facilityno) die('Error!:' . $result['ErrorMsg']); } } + + +function bonusCreate($data, $facilityno, $conn) +{ + try { + require_once("../../bonus/other/maintenance_contract_bonus_v2_1.php"); + $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; + $contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : ''; + $salesman = !empty($data['salesman']) ? $data['salesman'] : ''; + $payType = !empty($data['payType']) ? $data['payType'] : ''; + $status = 1; + $bonus_json = []; + $create_id = $data['user_id']; + $create_at = date('Y-m-d'); + $contract_no = !empty($data['contractno']) ? $data['contractno'] : ''; + $contract_kind = 3; + + $payment = [ + 'A40006' => 'annually', //年繳 + 'A40007' => 'quarterly', //季繳 + 'A40004' => 'bimonthly', // 雙月繳 + 'A40005' => 'semiannually', // 半年繳 + 'A40003' => 'monthly' //月繳 + ]; + + $payDay = getNext25thDate($contract_begin_date); + foreach ($elevators as $key => $elevator) { + // print_r($payDay); + // echo '
'; + // print_r($elevator); + // echo ''; + // exit; + $facility_no = $facilityno[$key]; + $ver = $elevator['bonus_verson']; //獎金版本 + $contract_type = $elevator['contract_type']; //合約類別 + $payment_period = $payment[$payType]; //付款方式 + $elevator_list_price = intval($elevator['stand_price']); //牌價 + $fee_per_st = $elevator['contract_price']; //作翻契約金額 + $commission_fee = $elevator['service_expense']; //服務費(月) + $receivable_date_due = $payDay; //第一筆保養款項收回日 + $sales_id = $salesman; //營業人員 + $discount = $elevator['discount']; + $region_director_id = $elevator['manager']; + $regular_contract_manger_id = !empty($elevator['regular_contract_manger_id']) ? $elevator['regular_contract_manger_id'] : ''; + $results = maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id); + + $bonus_json = [ + 'contract_type' => $contract_type, + 'total' => $elevator_list_price, + 'fee_per_st' => $fee_per_st, + 'commission_fee' => $commission_fee, + 'paykind' => $payment_period, + 'receivable_date_due' => $receivable_date_due, + 'discount' => $discount + ]; + if ($results['result_status'] != 'error') { + foreach ($results['bonus_array'] as $i => $result) { + + $bonus_type = $result['bonus_type']; + $pay_day = $result['pay_day_due']; + $amount = $result['bonus_amount']; + $receiver = $result['bonus_receiver']; + $a = json_encode($bonus_json); + $sql = "INSERT INTO bonus + (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,pay_day_due,status,bonus_json,create_id,create_at) VALUES + ($bonus_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$receiver','$pay_day',$status,'$a','$create_id','$create_at')"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + } + } + } + // exit(); + } catch (PDOException $e) { + http_response_code(404); + echo $e->getMessage(); + die('Error!:' . $e->getMessage()); + } +} + +// 計算保養開始日期的當月25號 +function getNext25thDate($dateString) +{ + // 將傳入的日期字串轉換成 Unix 時間戳記 + $timestamp = strtotime($dateString); + + // 取得該日期的日期 + $day = date('d', $timestamp); + + // 如果日期大於 25,則回傳下個月的 25 號日期 + if ($day > 25) { + // 增加一個月 + $timestamp = strtotime('+1 month', $timestamp); + } + + // 設定日期為 25 號 + $targetDate = date('Y-m-25', $timestamp); + + return $targetDate; +} diff --git a/wms/contract/api/postNewContractData.php b/wms/contract/api/postNewContractData.php index 001fe1f5..d94dac12 100644 --- a/wms/contract/api/postNewContractData.php +++ b/wms/contract/api/postNewContractData.php @@ -1,139 +1,325 @@ - 0) { - header("HTTP/1.1 422 Unprocessable Entity"); - echo json_encode($fail_arr); - exit(); - } - - - $conn->beginTransaction(); - - $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; - $stmt = $conn -> prepare($sql_str); - $stmt -> bindParam(":accountid",$salesman); - $stmt -> execute(); - $saleman = $stmt->fetch(PDO::FETCH_ASSOC); - $salesman_name = $saleman['name']; - if(!empty($files)){ - $englisharr = range('a', 'z'); - $files = $_FILES['files']; - $newfiles = []; - foreach( $files as $file ){ - $i = 0; //新陣列的索引編號 - foreach( $file as $key => $val ){ - $newfiles[$i]['name'] = $files['name'][$key]; - $newfiles[$i]['type'] = $files['type'][$key]; - $newfiles[$i]['tmp_name'] = $files['tmp_name'][$key]; - $newfiles[$i]['error'] = $files['error'][$key]; - $newfiles[$i]['size'] = $files['size'][$key]; - $i++; - } //foreach 第2層 end - } - $max_size = 4096*4096; //設定允許上傳檔案容量的最大值(1M) - $allow_ext = array('jpeg', 'jpg', 'png','JPG','JPEG','PNG','GIF'); //設定允許上傳檔案的類型 - $path = '../images/contracts/'; - if (!file_exists($path)) { mkdir($path); } - $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 - $datetime = (string)date('YmdHis'); - $files_id = 'm' . $datetime; // 保養=>b + 日期時間 - foreach( $newfiles as $key => $file ){ - $randNum = rand(1000,9999); - $randEnglish = $englisharr[rand(0,25)]; - $file_name = 'm' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum.$file['name']; - $msg = upload_chk( $file,$path, $max_size, $allow_ext, $file_name ); - if($msg==1){ - $msg = '檔案傳送成功!'; - $sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)"; - $stmt = $conn -> prepare($sql_str); - $stmt -> bindParam(':files_id' ,$files_id); - $stmt -> bindParam(':file_name' ,$file_name); - $stmt -> bindParam(':file_mime' ,$file['type']); - $stmt -> bindParam(':file_size' ,$file['size']); - $stmt -> bindParam(':created_at' ,$created_at); - $stmt -> bindParam(':created_by' ,$created_by); - $stmt ->execute(); - }else{ - throw new PDOException('檔案上傳失敗:' . $msg); - } - $msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '
'; + print_r($facilityno); + echo ''; + exit(); + $conn->beginTransaction(); + + $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; + $stmt = $conn->prepare($sql_str); + $stmt->bindParam(":accountid", $salesman); + $stmt->execute(); + $saleman = $stmt->fetch(PDO::FETCH_ASSOC); + $salesman_name = $saleman['name']; + if (!empty($files)) { + $englisharr = range('a', 'z'); + $files = $_FILES['files']; + $newfiles = []; + foreach ($files as $file) { + $i = 0; //新陣列的索引編號 + foreach ($file as $key => $val) { + $newfiles[$i]['name'] = $files['name'][$key]; + $newfiles[$i]['type'] = $files['type'][$key]; + $newfiles[$i]['tmp_name'] = $files['tmp_name'][$key]; + $newfiles[$i]['error'] = $files['error'][$key]; + $newfiles[$i]['size'] = $files['size'][$key]; + $i++; + } //foreach 第2層 end + } + $max_size = 4096 * 4096; //設定允許上傳檔案容量的最大值(1M) + $allow_ext = array('jpeg', 'jpg', 'png', 'JPG', 'JPEG', 'PNG', 'GIF'); //設定允許上傳檔案的類型 + $path = '../images/contracts/'; + if (!file_exists($path)) { + mkdir($path); + } + $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 + $datetime = (string)date('YmdHis'); + $files_id = 'm' . $datetime; // 保養=>b + 日期時間 + foreach ($newfiles as $key => $file) { + $randNum = rand(1000, 9999); + $randEnglish = $englisharr[rand(0, 25)]; + $file_name = 'm' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum . $file['name']; + $msg = upload_chk($file, $path, $max_size, $allow_ext, $file_name); + if ($msg == 1) { + $msg = '檔案傳送成功!'; + $sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)"; + $stmt = $conn->prepare($sql_str); + $stmt->bindParam(':files_id', $files_id); + $stmt->bindParam(':file_name', $file_name); + $stmt->bindParam(':file_mime', $file['type']); + $stmt->bindParam(':file_size', $file['size']); + $stmt->bindParam(':created_at', $created_at); + $stmt->bindParam(':created_by', $created_by); + $stmt->execute(); + } else { + throw new PDOException('檔案上傳失敗:' . $msg); + } + $msg_result .= '第' . ($key + 1) . '個上傳檔案的結果:' . $msg . '
'; + // print_r($data); + // echo ''; + // exit; + require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php"); + $signing_date = $data['signing_date']; + $bonus_v1_0_date = '2024-01-02'; + $bonus_v2_0_date = '2024-01-03'; + $contractType = [ + '1' => 'strategy_customer', + '2' => 'general_customer' + ]; + $contract_type = $data['contract_type']; + + $type = $contractType[$contract_type]; //戰略客戶 or 一般客戶 + $elevator_knockdown_price = $data['price_total']; //受價總額 + + $salesman = $data['salesman']; + $manager = $data['manager']; + + $result_bonus = []; + if ($signing_date <= $bonus_v1_0_date) { + $ver = '1.0'; + $result_bonus = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager); + } else if ($signing_date >= $bonus_v2_0_date) { + $ver = '2.0'; + // $result_bonus = elevator_new_deal_bonus_v2_0($ver,$contract_type,); + } + + echo '
'; + print_r($result_bonus); + echo ''; + exit(); + try { + } catch (PDOException $e) { + header("HTTP/1.1 500 Internal Server Error"); + die('Error!:' . $e->getMessage()); + } +} diff --git a/wms/contract/api/testT8API.php b/wms/contract/api/testT8API.php index 59730e98..9512cbc8 100644 --- a/wms/contract/api/testT8API.php +++ b/wms/contract/api/testT8API.php @@ -1,21 +1,36 @@ '; -// print_r($countDay); -// echo ''; -// exit(); -$SQuantity = 2; -// $b = 24 / $a; -for ($i = 0; $i < 12; $i++) { - $paymonth = $i * $SQuantity; - $countDay = date('Y-m-d', strtotime("$date + $paymonth months")); - $payDay = str_replace('-', '', $countDay); - echo '
'; - print_r($payDay); - echo ''; -} +?> + + +
未填寫
-未填寫
未填寫
-未填寫
+未填寫
-未填寫
未填寫
未填寫
+標準價+Option價格+與其他電梯共同分擔的費用貨價格
+合約號 | -- - | -- - | - -|||||
合約號 | ++ + | ++ + | + +|||||
- 業務確認項- |
-
- |
- ||||||
客戶名稱 | -
-
- 未填寫 - |
- 負責人 | -
-
- 未填寫 - |
- 統一編號/身分證 | -
-
- 未填寫 - |
- 營業員 | -
-
-
-
- 未填寫 - |
-
聯繫人 | -
-
- 未填寫 - |
- 聯繫人電話 | -
-
- 未填寫 - |
- QC和官檢 | -
-
- 未填寫 - |
- 案件名稱 | -
-
- 未填寫 - |
-
地址 | -
-
- 未填寫 - |
-
- 附件上傳 | -- - | -||||
+ 業務確認項+ |
+
+ |
+ ||||||
客戶名稱 | +
+
+ 未填寫 + |
+ 負責人 | +
+
+ 未填寫 + |
+ 統一編號/身分證 | +
+
+ 未填寫 + |
+ 營業員 | +
+
+
+
+ 未填寫 + |
+
電梯數量 | ++ + | +聯繫人 | +
+
+ 未填寫 + |
+ 聯繫人電話 | +
+
+ 未填寫 + |
+ 案件名稱 | +
+
+ 未填寫 + |
+
合約簽訂日期 | +
+
+ 未填寫 + |
+ 客戶類型 | ++ + | +附件上傳 | ++ + | +||
+ + | +|||||||
電梯型號 | ++ + | +開門方式 | ++ + | +電梯載重 | ++ + | +電梯人乘 | ++ + | + +
電梯速度 | ++ + | +電梯樓停 | ++ + | +電梯樓層 | ++ + | +合約交期(到工地) | ++ + | +
QC和官檢 | +
+
+ 未填寫 + |
+ 工地負責人 | ++ + | +工務部門負責人 | ++ + | ++ | + |
現場地址 | ++ + | +經度 | ++ + | +緯度 | ++ + | +||
+ |
'; +// print_r($hope_customer_status); +// echo ''; + + +?> + + + + + +
有望客戶基本資料 | + + +|||||||
---|---|---|---|---|---|---|---|
卷號 | ++ | 客戶名稱 | ++ | 負責人 | ++ | 客戶來源 | ++ |
地址 | ++ | 案件名稱 | ++ | 市話 / 手機 | ++ | 業主方聯繫人 | ++ |
營業員 | ++ | 台數 | ++ | 預定成交日 | ++ | 有望客戶狀態 | ++ |
有望客戶狀態 | ++ |
洽商進度 | + + ++ + | + +
---|
項次 | +電梯 | +人乘/ 載重 |
+ 停數 | +速度(m/min) | +保養月數 | +保養次數(月) | +保養方式 | +公司發布價(月) | +數量 | +公司發布價(總價) | +售價(月) | +售價(總價) | +
+ | + + | ++ + | ++ + | ++ + + + + + + + + + + + | ++ + | ++ + | ++ + | +