Browse Source

對帳系統跟更新T8 API

gary
Ellin 1 year ago
parent
commit
f863da5b68
  1. 11
      wms/T8_APItest.php
  2. 12
      wms/T8_Authorization.php
  3. 169
      wms/account-receivable-index.php

11
wms/T8_APItest.php

@ -5,13 +5,14 @@ echo "ii";
<script> <script>
get_Auth(); get_Auth();
window.addEventListener('message', function(event) { window.addEventListener('message', function(event) {
if (event.origin === "http://localhost:3000" && (typeof event.data === "string")) { // if (event.origin === "http://localhost:3000" && (typeof event.data === "string")) {
if (event.origin === "https://masada.com.tw" && (typeof event.data === "string")) {
var validation = event.data; var validation = event.data;
console.log("event"); console.log("event");
console.log(validation); console.log(validation);
// var corsurl = 'http://cors-anywhere.herokuapp.com/'; // var corsurl = 'http://cors-anywhere.herokuapp.com/';
var apiurl = 'http://60.244.87.101:880/twWebAPI/V1/APCHECKBILL/PostERPData'; var apiurl = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALDISPATCHLIST/GetERPData?pkValue=SS20230825001';
headerParam = { headerParam = {
CHI_Authorization: `${validation}`, CHI_Authorization: `${validation}`,
}; };
@ -71,13 +72,13 @@ echo "ii";
]; ];
var json = JSON.stringify(body); var json = JSON.stringify(body);
obj = { obj = {
type: 'POST', type: 'GET',
// url: `${corsurl}${apiurl}`, // url: `${corsurl}${apiurl}`,
url: `${apiurl}`, url: `${apiurl}`,
// dataType: 'json', // dataType: 'json',
headers: headerParam, headers: headerParam,
data: json, // data: json,
dataType: "json", // dataType: "json",
success: function(res) { success: function(res) {
console.log(res.Status); console.log(res.Status);
console.log(res.ErrorMsg); console.log(res.ErrorMsg);

12
wms/T8_Authorization.php

@ -2,16 +2,17 @@
<?php <?php
$now = gmdate("YmdHis"); $now = gmdate("YmdHis");
$data = 'M0000.' . $now; $data = 'M0000.' . $now;
$sign = hash_hmac('SHA256', $data, '964C834F7BF2BB70', false); $sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false);
?> ?>
<script> <script>
function get_Auth() { function get_Auth() {
var api_key = '964C834F7BF2BB70'; var api_key = 'B2D6395D2883E26C';
var validation = ""; var validation = "";
// var corsurl = 'http://cors-anywhere.herokuapp.com/'; // var corsurl = 'http://cors-anywhere.herokuapp.com/';
var apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; // var apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
var apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'
headerParam = { headerParam = {
UserId: 'M0000', UserId: 'M0000',
Pwd: 'M012290493119', Pwd: 'M012290493119',
@ -26,10 +27,11 @@ $sign = hash_hmac('SHA256', $data, '964C834F7BF2BB70', false);
headers: headerParam, headers: headerParam,
success: function(res) { success: function(res) {
validation = res.Data['CHI_Authorization']; validation = res.Data['CHI_Authorization'];
window.parent.postMessage(validation,'http://localhost:3000'); // window.parent.postMessage(validation,'http://localhost:3000');
// window.parent.postMessage(validation,'https://masada.com.tw'); window.parent.postMessage(validation,'https://masada.com.tw');
} }
}; };
jQuery.ajax(obj); jQuery.ajax(obj);
console.log(validation);
} }
</script> </script>

169
wms/account-receivable-index.php

@ -8,17 +8,83 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx as xls;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
$arrayData = []; $arrayData = [];
$sql = "SELECT echo "合約號,部門,經理,營業員,簽約款,二次款,貨抵工地款,安裝款,試車款,交車款,取得許可證約交款,取得許可函後6個月約交款,狀態</br>";
// $T8_array = mysqli_fetch_all($T8_array, MYSQLI_ASSOC);
// $sql_depid = "SELECT department_id, name from department";
// $dept_query = mysqli_query($link, $sql_depid);
// $deptype = mysqli_fetch_all($dept_query, MYSQLI_ASSOC);
$sql_contract = "SELECT a.BillNo, a.PayStage, a.PlanPayAmt FROM salOrderStagePay AS a
LEFT JOIN salSalesOrder AS s on a.BillNo = s.BillNo WHERE s.ModeId = 'M' AND (s.CurrentState=2 OR s.CurrentState=4) ";
$contract = $conn->query($sql_contract);
foreach ($contract as $cont) {
// print_r($cont);
// echo "<br>";
$BillNo = $cont['BillNo'];
$PayStage = $cont['PayStage'];
$PayAmount = $cont['PlanPayAmt'];
if (isset($arrayData[$BillNo])) {
if (stristr($PayStage, '二次款') || stristr($PayStage, '出貨前') || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60')) {
$arrayData[$BillNo][5] = $PayAmount;
} elseif ($PayStage == '簽約' || stristr($PayStage, '簽定') || stristr($PayStage, '簽訂') || stristr($PayStage, '訂金')) {
$arrayData[$BillNo][4] = $PayAmount;
} elseif (stristr($PayStage, '貨抵工地') || stristr($PayStage, '貨底工地')) {
$arrayData[$BillNo][6] = $PayAmount;
} elseif (stristr($PayStage, '安裝')) {
$arrayData[$BillNo][7] = $PayAmount;
} elseif (stristr($PayStage, '試車')) {
$arrayData[$BillNo][8] = $PayAmount;
} elseif (stristr($PayStage, '交車') || stristr($PayStage, '完工') || stristr($PayStage, '驗收')) {
$arrayData[$BillNo][9] = $PayAmount;
} elseif (stristr($PayStage, '取得合格函') || stristr($PayStage, '取得許可函')) {
$arrayData[$BillNo][10] = $PayAmount;
} elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月')) {
$arrayData[$BillNo][11] = $PayAmount;
} else {
$arrayData[$BillNo][12] = $PayAmount;
}
} else {
$arrayData[$BillNo] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
if (stristr($PayStage, '二次款') || stristr($PayStage, '出貨前') || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60')) {
$arrayData[$BillNo][5] = $PayAmount;
} elseif ($PayStage == '簽約' || stristr($PayStage, '簽定') || stristr($PayStage, '簽訂') || stristr($PayStage, '訂金')) {
$arrayData[$BillNo][4] = $PayAmount;
} elseif (stristr($PayStage, '貨抵工地') || stristr($PayStage, '貨底工地')) {
$arrayData[$BillNo][6] = $PayAmount;
} elseif (stristr($PayStage, '安裝')) {
$arrayData[$BillNo][7] = $PayAmount;
} elseif (stristr($PayStage, '試車')) {
$arrayData[$BillNo][8] = $PayAmount;
} elseif (stristr($PayStage, '交車') || stristr($PayStage, '完工') || stristr($PayStage, '驗收')) {
$arrayData[$BillNo][9] = $PayAmount;
} elseif (stristr($PayStage, '取得合格函') || stristr($PayStage, '取得許可函')) {
$arrayData[$BillNo][10] = $PayAmount;
} elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月')) {
$arrayData[$BillNo][11] = $PayAmount;
} else {
$arrayData[$BillNo][12] = $PayAmount;
}
}
}
foreach ($arrayData as $key => $value) {
$sql = "SELECT
tmp2.*, tmp2.*,
d.name AS depart_name d.name AS depart_name
FROM( FROM(
SELECT SELECT
a.manager, a.manager,
a2.name as manager_name,
a.name, a.name,
a.department_id, a.department_id,
w.salesid, w.salesid,
w.contractno, w.contractno,
w.facilityno, w.facilityno,
w.estimated_shipping_date,
w.actual_tofactory_date,
w.real_arrival_date, w.real_arrival_date,
w.install_end_date, w.install_end_date,
w.tryrun_end_date, w.tryrun_end_date,
@ -28,7 +94,8 @@ left join account AS a
ON w.salesid = a.accountid ON w.salesid = a.accountid
left join account AS a2 left join account AS a2
ON a2.accountid = a.manager ON a2.accountid = a.manager
where w.status = '1' where w.status = '1' AND w.contractno='" . $key . "'" . "
)AS tmp2 )AS tmp2
left join ( left join (
SELECT DISTINCT SELECT DISTINCT
@ -38,84 +105,28 @@ FROM department
) AS d ) AS d
ON d.department_id = tmp2.department_id"; ON d.department_id = tmp2.department_id";
$facitities = "";
$wipwhole_array = mysqli_query($link, $sql); $wipwhole_array = mysqli_query($link, $sql);
// $T8_array = mysqli_fetch_all($T8_array, MYSQLI_ASSOC); foreach ($wipwhole_array as $wip) {
foreach ($wipwhole_array as $wip) { $value[0] = $wip['depart_name'];
// print_r($wip); $value[1] = $wip['manager_name'];
// echo "<br>"; $value[2] = $wip['name'];
} if ($wip['delivery_date'] != NULL) {
echo "<br>"; $facitities .= $wip['facilityno'] . "(" . $wip['delivery_date'] . "已移交);\n";
// $sql_depid = "SELECT department_id, name from department"; } elseif ($wip['tryrun_end_date'] != NULL) {
// $dept_query = mysqli_query($link, $sql_depid); $facitities .= $wip['facilityno'] . "(" . $wip['tryrun_end_date'] . "試車完畢);\n";
// $deptype = mysqli_fetch_all($dept_query, MYSQLI_ASSOC); } elseif ($wip['install_end_date'] != NULL) {
$facitities .= $wip['facilityno'] . "(" . $wip['install_end_date'] . "安裝完畢);\n";
} elseif ($wip['real_arrival_date'] != NULL) {
$sql_contract = "SELECT a.BillNo, a.PayStage, a.PlanPayAmt FROM salOrderStagePay AS a $facitities .= $wip['facilityno'] . "(".$wip['real_arrival_date'] . "貨抵工地);\n";
LEFT JOIN salSalesOrder AS s on a.BillNo = s.BillNo WHERE s.ModeId = 'M'"; } elseif ($wip['actual_tofactory_date'] != NULL) {
$contract = $conn->query($sql_contract); $facitities .= $wip['facilityno'] . "(" . $wip['actual_tofactory_date'] . "實際到觀音日);\n";
foreach ($contract as $cont) { }elseif ($wip['estimated_shipping_date'] != NULL) {
// print_r($cont); $facitities .= $wip['facilityno'] . "(" . $wip['estimated_shipping_date'] . "預計到港);\n";
// echo "<br>"; }else {
$BillNo = $cont['BillNo']; $facitities .= $wip['facilityno'] . "(預計到港日待確認);\n";
$PayStage = $cont['PayStage'];
$PayAmount = $cont['PlanPayAmt'];
if (isset($arrayData[$BillNo])) {
if ($PayStage == '簽約' || stristr($PayStage, '簽定') || stristr($PayStage, '簽訂') || stristr($PayStage, '訂金')) {
$arrayData[$BillNo][0] = $PayAmount;
} elseif (stristr($PayStage, '二次款') || stristr($PayStage, '出貨前') || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時')) {
$arrayData[$BillNo][1] = $PayAmount;
} elseif (stristr($PayStage, '貨抵工地')||stristr($PayStage, '貨底工地')) {
$arrayData[$BillNo][2] = $PayAmount;
} elseif (stristr($PayStage, '安裝')) {
$arrayData[$BillNo][3] = $PayAmount;
} elseif (stristr($PayStage, '試車')) {
$arrayData[$BillNo][4] = $PayAmount;
} elseif (stristr($PayStage, '交車') || stristr($PayStage, '完工') || stristr($PayStage, '驗收')) {
$arrayData[$BillNo][5] = $PayAmount;
} elseif (stristr($PayStage, '取得合格函') || stristr($PayStage, '取得許可函')) {
$arrayData[$BillNo][6] = $PayAmount;
} elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月')) {
$arrayData[$BillNo][7] = $PayAmount;
}else{
$arrayData[$BillNo][8] = $PayAmount;
} }
} else {
$arrayData[$BillNo] = [0, 0, 0, 0, 0, 0, 0, 0];
} }
echo $key . "," . $value[0] . "," . $value[1] . "," . $value[2] . "," . $value[4] . "," . $value[5] . "," . $value[6] . "," . $value[7] . "," . $value[8] . "," . $value[9] . "," . $value[10] . "," . $value[11] . ",". $facitities . "<br>";
// echo "<br>"."--------------------------------"."<br>";
// array_push($arrayData,$payment);
// print_r($payment);
// echo "<br>---------------------------<br>";
} }
foreach ($arrayData as $key => $value) {
print_r($key);
echo "<br>";
print_r($value);
echo "<br>-----------------------------<br>";
}
echo "<br>###########################<br>";
//產生excel
// $spreadsheet = new Spreadsheet();
// $sheet = $spreadsheet->getActiveSheet();
// $colArr = ['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'];
// $colTitleArr = ['合約號','付款階段','付款金額'];
// $sheet->setTitle('預收款清單');
// for ($i = 0; $i <count($colArr); $i++){
// $sheet->setCellValue($colArr[$i].'1', $colTitleArr[$i]);
// }
// $i=2;
// for ($j=0; $j <count($payment); $j++){
// $sheet->setCellValue($colArr[$j].$i, $payment[$j][$i]);
// $i++;
// }

Loading…
Cancel
Save