10994015 1 year ago
parent
commit
34593e3efb
  1. 179
      wms/account-receivable-maintainance-index.php

179
wms/account-receivable-maintainance-index.php

@ -26,16 +26,14 @@ SELECT
siamd.HadTransCheckBLAmtWTax, siamd.HadTransCheckBLAmtWTax,
siamd.OAmountWithTax, siamd.OAmountWithTax,
siamd.CU_MaterialId, siamd.CU_MaterialId,
acb_tmp.BillNo2, acb_tmp.BillNo2 AS checkBillNo,
acb_tmp.RowCode2, acb_tmp.RowCode2,
acb_tmp.checkOAmount, acb_tmp.checkOAmount,
asim.BillNo AS BillNo3, asim.BillNo AS BillNo3,
asim.InvoiceName, asim.InvoiceName,
asim.OAmountWithTax AS InvoiceOAmount, asim.OAmountWithTax AS InvoiceOAmount,
asi.InvoiceNo, asi.InvoiceNo,
asi.InvoiceTime, asi.InvoiceTime
writeoff.BillDate AS WriteOffDate,
SUM(arwobd.CurrStandOffOAmount) AS TotalCurrStandOffOAmount
FROM salIncomeApplyMaster AS siam -- 收入申請單 FROM salIncomeApplyMaster AS siam -- 收入申請單
LEFT JOIN salIncomeApplyDetail AS siamd -- 收入申請單明細 LEFT JOIN salIncomeApplyDetail AS siamd -- 收入申請單明細
ON siam.BillNo = siamd.BillNo ON siam.BillNo = siamd.BillNo
@ -66,26 +64,38 @@ SELECT
ON asim.BillNo = asi.BillNo ON asim.BillNo = asi.BillNo
LEFT JOIN comBusinessPartner AS cbp LEFT JOIN comBusinessPartner AS cbp
ON siam.BizPartnerId = cbp.BizPartnerId ON siam.BizPartnerId = cbp.BizPartnerId
LEFT JOIN
arWriteOffBillDetail AS arwobd
ON acb_tmp.BillNo2 = arwobd.FromBillNo
LEFT JOIN
arWriteOffBill AS writeoff ON arwobd.BillNo = writeoff.BillNo
WHERE 1 = 1 WHERE 1 = 1
"; ";
//核銷單 SQL
$sql_writeOff = "SELECT
wod.FromBillNo AS checkBillNo,
arCheckBill.LAmountWithTax,
SUM(wod.CurrWriteOffLAmount) AS TotalWriteOffAmount
FROM arWriteOffBillDetail AS wod
LEFT JOIN arCheckBill
ON arCheckBill.BillNo = wod.FromBillNo
LEFT JOIN comDepartment AS cd
ON cd.DeptId = arCheckBill.DeptId
WHERE arCheckBill.TypeId = 'RVS'";
$follower = find_follow($user_id); $follower = find_follow($user_id);
if ((in_array($user_id, array('M0008', 'M0012'))) || (in_array(accountidToDepartId($user_id), array('220', '210', '501')))) { if ((in_array($user_id, array('M0008', 'M0012'))) || (in_array(accountidToDepartId($user_id), array('220', '210', '501')))) {
} else { } else {
$sql .= " AND (siam.PersonId = '$user_id'"; $sql .= " AND (siam.PersonId = '$user_id'";
$sql_writeOff .= " AND (arCheckBill.PersonId = '$user_id'";
if (count($follower) > 0) { if (count($follower) > 0) {
$column_str = "('$user_id'" . ",'"; $column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower); $column_str .= implode("','", $follower);
$column_str .= "')"; $column_str .= "')";
$sql .= " OR siam.PersonId IN $column_str OR cd.LeaderId = '$user_id')"; $sql .= " OR siam.PersonId IN $column_str OR cd.LeaderId = '$user_id')";
$sql_writeOff .= " OR arCheckBill.PersonId IN $column_str OR cd.LeaderId = '$user_id')";
} else { } else {
$sql .= " OR cd.LeaderId = '$user_id')"; $sql .= " OR cd.LeaderId = '$user_id')";
$sql_writeOff .= " OR cd.LeaderId = '$user_id')";
}; };
} }
if (!is_null($start_date)) { if (!is_null($start_date)) {
$start_date = (int)date('Ymd', strtotime($start_date)); $start_date = (int)date('Ymd', strtotime($start_date));
$sql .= " AND siam.CU_ContractStart >= $start_date "; $sql .= " AND siam.CU_ContractStart >= $start_date ";
@ -102,39 +112,23 @@ if (!is_null($end_SignDate)) {
$end_SignDate = (int)date('Ymd', strtotime($end_SignDate)); $end_SignDate = (int)date('Ymd', strtotime($end_SignDate));
$sql .= " AND siam.BillDate <= $end_SignDate "; $sql .= " AND siam.BillDate <= $end_SignDate ";
} }
$sql .= " GROUP BY $sql .= "
siam.PersonId,
cp.PersonName,
cd.DeptId,
cd.DeptName,
cd.LeaderId,
lcp.PersonName,
siam.BizPartnerId,
cbp.BizPartnerName,
siamd.RowCode,
siam.BillNo,
siamd.ProjectId,
siamd.CU_EstPayDate,
siamd.UnTransCheckBLAmtWTax,
siamd.HadTransCheckBLAmtWTax,
siamd.OAmountWithTax,
siamd.CU_MaterialId,
acb_tmp.BillNo2,
acb_tmp.RowCode2,
acb_tmp.checkOAmount,
asim.BillNo,
asim.InvoiceName,
asim.OAmountWithTax,
asi.InvoiceNo,
asi.InvoiceTime,
writeoff.BillDate
ORDER BY ORDER BY
siam.PersonId ASC, siam.PersonId ASC,
siam.BillNo ASC, siam.BillNo ASC,
siamd.RowCode ASC"; siamd.RowCode ASC";
$sql_writeOff.=" GROUP BY
wod.FromBillNo
,arCheckBill.LAmountWithTax";
$writeoff = array();
$query_T8 = $conn->query($sql); $query_T8 = $conn->query($sql);
$rows = $query_T8->fetchAll(PDO::FETCH_ASSOC); $rows = $query_T8->fetchAll(PDO::FETCH_ASSOC);
$query_writeoff = $conn->query($sql_writeOff);
foreach($query_writeoff->fetchAll(PDO::FETCH_ASSOC) as $row){
$writeoff[$row['checkBillNo']]= ($row['TotalWriteOffAmount']==$row['LAmountWithTax'])?'V':'X';
}
$today = strtotime(date('Ymt')); $today = strtotime(date('Ymt'));
$table = ""; $table = "";
for ($i = 0; $i < count($rows); $i++) { for ($i = 0; $i < count($rows); $i++) {
@ -142,21 +136,29 @@ for ($i = 0; $i < count($rows); $i++) {
$tmpname = $row['ProjectId'] . $row['RowCode']; $tmpname = $row['ProjectId'] . $row['RowCode'];
$data[$tmpname] = $row; $data[$tmpname] = $row;
$data[$tmpname]['CU_EstPayDate'] = date('Y-m-d', strtotime($row['CU_EstPayDate'])); $data[$tmpname]['CU_EstPayDate'] = date('Y-m-d', strtotime($row['CU_EstPayDate']));
$receivable_date = $data[$tmpname]['CU_EstPayDate'];
$data[$tmpname]['havetopay'] = strtotime($row['CU_EstPayDate']) > $today ? '--' : 'V'; $data[$tmpname]['havetopay'] = strtotime($row['CU_EstPayDate']) > $today ? '--' : 'V';
$datahavetopay = $row['CU_EstPayDate'] > $today ? 0 : 1; $datahavetopay = strtotime($row['CU_EstPayDate']) > $today ? 0 : 1;
$data[$tmpname]['collecttime'] = collect_month(strtotime($row['CU_EstPayDate'])); $data[$tmpname]['collecttime'] = collect_month(strtotime($row['CU_EstPayDate']));
$invoicedate = is_null($row['InvoiceTime']) ? null : date('Y-m-d', strtotime($row['InvoiceTime'])); $data[$tmpname]['invoicedate'] = is_null($row['InvoiceTime']) ? null : date('Y-m-d', strtotime($row['InvoiceTime']));
$tableinvoice_state = is_null($invoicedate) ? 0 : 1; $invoicedate = $data[$tmpname]['invoicedate'];
$data[$tmpname]['invoice'] = is_null($data[$tmpname]['invoicedate']) ? 0 : 1;
if(!is_null($data[$tmpname]['checkBillNo']) && isset($writeoff[$data[$tmpname]['checkBillNo']])){
$data[$tmpname]['WriteOff'] = $writeoff[$data[$tmpname]['checkBillNo']];
}else{
$data[$tmpname]['WriteOff'] = '--';
}
$contract_no = $row['ProjectId']; $contract_no = $row['ProjectId'];
$facility_no = $row['CU_MaterialId']; $facility_no = $row['CU_MaterialId'];
$RowCode = $row['RowCode']; $RowCode = $row['RowCode'];
$BillNo = $row['BillNo']; $BillNo = $row['BillNo'];
$receivable_date = date('Y-m-d', strtotime($row['CU_EstPayDate'])); $data[$tmpname]['receivable_date'] = date('Y-m-d', strtotime($row['CU_EstPayDate']));
$budget = $row['OAmountWithTax']; $budget = $row['OAmountWithTax'];
$invoiceNo = $row['InvoiceNo']; $invoiceNo = $row['InvoiceNo'];
$invoice_budget = is_null($row['InvoiceOAmount']) ? 0 : $row['InvoiceOAmount']; $tableinvoice_state = is_null($invoiceNo) ? 0 : 1;
$table_writeoff_date = is_null($row['WriteOffDate']) ? null : date('Y-m-d', strtotime($row['WriteOffDate'])); $data[$tmpname]['invoice_budget'] = is_null($row['InvoiceOAmount']) ? 0 : $row['InvoiceOAmount'];
$table_writeoff_amount = is_null($row['TotalCurrStandOffOAmount']) ? 0 : $row['TotalCurrStandOffOAmount']; $invoice_budget = $data[$tmpname]['invoice_budget'];
$table_writeoff = ($data[$tmpname]['WriteOff'] =='V') ? 1 : 0;
$table1 = "INSERT INTO account_receivable_maintainance( $table1 = "INSERT INTO account_receivable_maintainance(
`contract_no`, `contract_no`,
`facility_no`, `facility_no`,
@ -167,7 +169,7 @@ for ($i = 0; $i < count($rows); $i++) {
`receivable`, `receivable`,
`invoice_state`, `invoice_state`,
`invoice_budget`, `invoice_budget`,
`received_budget` `received`
"; ";
$table2 = ") VALUES( $table2 = ") VALUES(
'$contract_no', '$contract_no',
@ -179,12 +181,10 @@ for ($i = 0; $i < count($rows); $i++) {
$datahavetopay, $datahavetopay,
$tableinvoice_state, $tableinvoice_state,
$invoice_budget, $invoice_budget,
$table_writeoff_amount $table_writeoff
"; ";
$table1 .= is_null($invoicedate) ? "" : ",`invoice_date`"; $table1 .= is_null($invoicedate) ? "" : ",`invoice_date`";
$table2 .= is_null($invoicedate) ? "" : ",'$invoicedate'"; $table2 .= is_null($invoicedate) ? "" : ",'$invoicedate'";
$table1 .= is_null($table_writeoff_date) ? "" : ",`received_date`";
$table2 .= is_null($table_writeoff_date) ? "" : ",'$table_writeoff_date'";
$table1 .= is_null($invoiceNo) ? "" : ",`invoice_no`"; $table1 .= is_null($invoiceNo) ? "" : ",`invoice_no`";
$table2 .= is_null($invoiceNo) ? "" : ",'$invoiceNo'"; $table2 .= is_null($invoiceNo) ? "" : ",'$invoiceNo'";
$table .= $table1 . $table2 . "); \n"; $table .= $table1 . $table2 . "); \n";
@ -249,17 +249,17 @@ for ($i = 0; $i < count($rows); $i++) {
} }
</style> </style>
<div style="width: 98%;margin: 1%;"> <!-- <div style="width: 98%;margin: 1%;">
<div class="btn-group btn-group-md " style="padding:10 px; width: 100%;"> <div class="btn-group btn-group-md " style="padding:10 px; width: 100%;">
<button type="button" style="width: 12%;" onclick="downloadData()" class="btn btn-success">下載 <span class="glyphicon glyphicon-download-alt"></span></button> <button type="button" style="width: 12%;" onclick="downloadData()" class="btn btn-success">下載 <span class="glyphicon glyphicon-download-alt"></span></button>
</div> </div>
</div> </div> -->
<div class="container"> <div class="container">
<div class="text-center" style="margin-bottom: 20px;"> <div class="text-center" style="margin-bottom: 20px;">
<h3><strong>應收帳款(保養)</strong></h3> <h3><strong>應收帳款(保養)</strong></h3>
</div> </div>
<hr> <hr>
<form class="form-horizontal" id='myForm' method='post' action='account-receivable-new-index.php?<?= $token_link ?>'> <form class="form-horizontal" id='myForm' method='post' action='account-receivable-maintainance-index.php?<?= $token_link ?>'>
<table class="table table-striped table-bordered" style='width:98%;text-align:center;margin:0 auto'> <table class="table table-striped table-bordered" style='width:98%;text-align:center;margin:0 auto'>
<tbody> <tbody>
<tr> <tr>
@ -271,7 +271,7 @@ for ($i = 0; $i < count($rows); $i++) {
</td> </td>
<td rowspan="2"> <td rowspan="2">
<button type="submit" class="btn btn-primary btn-sm">搜尋</button> <button type="submit" class="btn btn-primary btn-md">搜尋</button>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -286,19 +286,17 @@ for ($i = 0; $i < count($rows); $i++) {
<tr> <tr>
<th class="text-center" style="vertical-align: middle;">催收次數</th> <th class="text-center" style="vertical-align: middle;">催收次數</th>
<td colspan="3"> <td colspan="3">
<input type="text" class='form-control' id='search_collectstart' name='collect_time_start' style='width:30%;display:inline;' oninput="searchFront('collectstart')"> <input type="number" class='form-control' id='search_collectstart' name='search_collectstart' style='width:30%;display:inline;' onblur="searchFront('collectstart')">
≤ 催收次數 ≤ ≤ 催收次數 ≤
<input type="text" class='form-control' id='search_collectend' name='collect_time_end' style='width:30%;display:inline;' oninput="searchFront('collectend')"> <input type="number" class='form-control' id='search_collectend' name='search_collectend' style='width:30%;display:inline;' onblur="searchFront('collectend')">
<!-- <button type="submit" class="btn btn-primary btn-sm">搜尋</button> -->
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="text-center" style="vertical-align: middle;">催收金額</th> <th class="text-center" style="vertical-align: middle;">款別金額</th>
<td colspan="3"> <td colspan="3">
<input type="text" class='form-control' id='search_CBudgetstart' name='collect_budget_start' style='width:30%;display:inline;' onblur="searchFront('CBudgetstart')"> <input type="text" class='form-control' id='search_CBudgetstart' name='collect_budget_start' style='width:30%;display:inline;' onblur="searchFront('CBudgetstart')">
催收金額 ≤ 款別金額 ≤
<input type="text" class='form-control' id='search_CBudgetend' name='collect_budget_end' style='width:30%;display:inline;' onblur="searchFront('CBudgetend')"> <input type="text" class='form-control' id='search_CBudgetend' name='collect_budget_end' style='width:30%;display:inline;' onblur="searchFront('CBudgetend')">
<!-- <button type="submit" class="btn btn-primary btn-sm">搜尋</button> -->
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -314,10 +312,10 @@ for ($i = 0; $i < count($rows); $i++) {
<label for="search_dept">查詢部門</label> <label for="search_dept">查詢部門</label>
<input type="text" id="search_dept" name="search_dept" class="form-control" placeholder="請輸入部門" onblur="searchFront('dept')"> <input type="text" id="search_dept" name="search_dept" class="form-control" placeholder="請輸入部門" onblur="searchFront('dept')">
</div> </div>
<div class="col-md-4"> <!-- <div class="col-md-4">
<label for="search_manager">查詢主管</label> <label for="search_manager">查詢主管</label>
<input type="text" id="search_manager" name="search_manager" class="form-control" placeholder="請輸入主管工號/姓名" onblur="searchFront('manager')"> <input type="text" id="search_manager" name="search_manager" class="form-control" placeholder="請輸入主管工號/姓名" onblur="searchFront('manager')">
</div> </div> -->
</div> </div>
<div class="form-group"> <div class="form-group">
@ -351,18 +349,15 @@ include "./footer.php";
<th style='text-align:center;vertical-align: middle;'>序號</th> <th style='text-align:center;vertical-align: middle;'>序號</th>
<th style='text-align:center;vertical-align: middle;width:100px'>作番號</th> <th style='text-align:center;vertical-align: middle;width:100px'>作番號</th>
<th style='text-align:center;vertical-align: middle;width:110px'>部門</th> <th style='text-align:center;vertical-align: middle;width:110px'>部門</th>
<th style='text-align:center;vertical-align: middle;'>主管</th> <!-- <th style='text-align:center;vertical-align: middle;'>主管</th> -->
<th style='text-align:center;vertical-align: middle;'>契約員</th> <th style='text-align:center;vertical-align: middle;'>契約員</th>
<th style='text-align:center;vertical-align: middle;width:120px'>客戶名稱</th> <th style='text-align:center;vertical-align: middle;width:120px'>客戶名稱</th>
<th style='text-align:center;vertical-align: middle;'>應收日期</th> <th style='text-align:center;vertical-align: middle;'>應收日期</th>
<th style='text-align:center;vertical-align: middle;'>是否應收</th> <th style='text-align:center;vertical-align: middle;'>是否應收</th>
<th style='text-align:center;vertical-align: middle;'>應收金額</th> <th style='text-align:center;vertical-align: middle;'>款別金額</th>
<!-- <th style='text-align:center;vertical-align: middle;'>是否收齊</th>
<th style='text-align:end;vertical-align: middle;'>已開金額</th>
<th style='text-align:end;vertical-align: middle;'>未開金額</th> -->
<th style='text-align:center;vertical-align: middle;'>已收金額</th>
<th style='text-align:center;vertical-align: middle;'>催收金額</th>
<th style='text-align:center;vertical-align: middle;'>催收次數</th> <th style='text-align:center;vertical-align: middle;'>催收次數</th>
</tr> </tr>
</thead> </thead>
@ -373,17 +368,16 @@ include "./footer.php";
<td><?= $row['RowCode']; ?></td> <td><?= $row['RowCode']; ?></td>
<td class="facility"><?= $row['CU_MaterialId']; ?></td> <td class="facility"><?= $row['CU_MaterialId']; ?></td>
<td class="dept"><?= $row['DeptId'] . "<br>" . $row['DeptName']; ?></td> <td class="dept"><?= $row['DeptId'] . "<br>" . $row['DeptName']; ?></td>
<td class="manager"><?= $row['LeaderId'] . "<br>" . $row['LeaderName']; ?></td> <!-- <td class="manager"><?= $row['LeaderId'] . "<br>" . $row['LeaderName']; ?></td> -->
<td class="personId"><?= $row['PersonId'] . "<br>" . $row['PersonName']; ?></td> <td class="personId"><?= $row['PersonId'] . "<br>" . $row['PersonName']; ?></td>
<td class="customerid"><?= $row['BizPartnerId'] . "<br>" . $row['BizPartnerName']; ?></td> <td class="customerid"><?= $row['BizPartnerId'] . "<br>" . $row['BizPartnerName']; ?></td>
<td><?= $row['CU_EstPayDate']; ?></td> <td><?= $row['CU_EstPayDate']; ?></td>
<td><?= $row['havetopay']; ?></td> <td><?= $row['havetopay']; ?></td>
<td><?= number_format(round($row['OAmountWithTax'])); ?></td> <td class="CBudget"><?= number_format(round($row['OAmountWithTax'])); ?></td>
<td><?= $row['WriteOff']; ?></td>
<td><?= is_null($row['TotalCurrStandOffOAmount']) ? 0 : number_format(round($row['TotalCurrStandOffOAmount'])); ?></td> <td class="collect"><?= (($row['havetopay'] == "V") && ($row['WriteOff'] !== 'V'))? $row['collecttime']:0; ?></td>
<td class="CBudget"><?= ($row['havetopay'] == "V")? (number_format(round($row['OAmountWithTax'] - $row['TotalCurrStandOffOAmount']))) :0; ?></td>
<td class="collect"><?= (($row['havetopay'] == "V") && ($row['OAmountWithTax'] - $row['TotalCurrStandOffOAmount'] >1))? $row['collecttime']:0; ?></td>
</tr> </tr>
<?php } ?> <?php } ?>
</tbody> </tbody>
@ -405,30 +399,29 @@ include "./footer.php";
} }
} }
} }
// function downloadData() {
// var xhr = new XMLHttpRequest();
// var url = window.location.origin + "/wms/account-receivable-renovate-excel.php?type=all&<?= $token_link ?>";
// xhr.open('POST', url, true);
// xhr.setRequestHeader('Content-Type', 'application/json');
// xhr.onreadystatechange = function() {
// if (xhr.readyState === 4 && xhr.status === 200) {
// var file_path = xhr.responseText;
// var link = document.createElement('a');
// var name = "汰改應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";
// link.setAttribute('href', window.location.origin + "/wms/account-receivable-renovate.xlsx");
// link.setAttribute('download', name);
// link.style.display = 'none';
// document.body.appendChild(link);
// link.click();
// document.body.removeChild(link);
// }
// }
// xhr.send(JSON.stringify({
// Bill:
// }));
function downloadData() { // }
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/account-receivable-renovate-excel.php?type=all&<?= $token_link ?>";
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var file_path = xhr.responseText;
var link = document.createElement('a');
var name = "汰改應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";
link.setAttribute('href', window.location.origin + "/wms/account-receivable-renovate.xlsx");
link.setAttribute('download', name);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
xhr.send(JSON.stringify({
Bill: <?= $total_data ?>
}));
}
function searchFront(area) { function searchFront(area) {
var term = 'search_' + area; var term = 'search_' + area;

Loading…
Cancel
Save