Browse Source

新增拉每個作番的金額

gary
Ellin 1 year ago
parent
commit
459a014003
  1. 362
      wms/account-receivable-index-ing.php
  2. 54
      wms/account-receivable-test.php

362
wms/account-receivable-index-ing.php

@ -1,7 +1,4 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Sign;
include "header.php";
$follower = find_follow($user_id);
@ -42,6 +39,11 @@ LEFT JOIN salSalesOrder AS s on a.BillNo = s.BillNo
LEFT JOIN comBusinessPartner AS c ON s.BizPartnerId=c.BizPartnerId
WHERE s.ModeId = 'M' AND (s.CurrentState=2 OR s.CurrentState=4) ";
// T8 銷售訂單 作番金額
$sql_contract_budget = "SELECT A.BillNo, A.OAmountWithTax,A.CU_MaterialId FROM salSalesOrderDetail AS A
LEFT JOIN salSalesOrder AS B ON A.BillNo=B.BillNo
WHERE B.ModeId='M' AND A.ItemType=1 ";
//作番大日程
$sql = "SELECT
tmp2.*,
@ -91,6 +93,7 @@ if (!(in_array(accountidToDepartId($user_id), array('220', '210')))) {
// $sql_received .= " AND (PersonId = '$user_id'";
$sql_opening .= " OR person_id = '$user_id'";
$sql .= " WHERE salesid = '$user_id'";
$sql_contract_budget.= " AND (PersonId = '$user_id'";
if (count($follower) > 0) {
$column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower);
@ -99,20 +102,39 @@ if (!(in_array(accountidToDepartId($user_id), array('220', '210')))) {
// $sql_received .= " OR PersonId IN $column_str)";
$sql_opening .= " OR person_id IN $column_str)";
$sql .= " OR salesid IN $column_str ORDER BY contractno";
$sql_contract_budget .= " OR PersonId IN $column_str ORDER BY BillNo, CU_MaterialId)";
} else {
$sql_contract .= ")";
// $sql_received .= ")";
$sql_opening .= ")";
$sql .= " ORDER BY contractno";
$sql_contract_budget .= ")";
};
} else {
}else{
$sql .= " ORDER BY contractno";
$sql_contract_budget .= "ORDER BY BillNo, CU_MaterialId";
}
$contract = $conn->query($sql_contract);
$received_array = $conn->query($sql_received);
$opening_data = mysqli_query($link, $sql_opening);
$invoice_data = $conn->query($sql_invoice);
$contract_budget_data = $conn->query($sql_contract_budget);
$contract_budget = array();
foreach ($contract_budget_data as $cont) {
if(isset($contract_budget[$cont['BillNo']])){
$contract_budget[$cont['BillNo']]['total'] += $cont['OAmountWithTax'];
}else{
$contract_budget[$cont['BillNo']]['total'] = $cont['OAmountWithTax'];
}
if(isset($contract_budget[$cont['BillNo']][$cont['CU_MaterialId']])){
$contract_budget[$cont['BillNo']][$cont['CU_MaterialId']] += $cont['OAmountWithTax'];
}else{
$contract_budget[$cont['BillNo']][$cont['CU_MaterialId']] = $cont['OAmountWithTax'];
};
}
// 合約收款階段內容分類
@ -155,6 +177,7 @@ foreach ($contract as $cont) {
$arrayData[$BillNo]['sign']['max'] = $arrayData[$BillNo]['second']['max'] = $arrayData[$BillNo]['arrive']['max'] = $arrayData[$BillNo]['install']['max'] = $arrayData[$BillNo]['tryrun']['max'] = $arrayData[$BillNo]['check']['max'] = $arrayData[$BillNo]['delivery']['max'] = $arrayData[$BillNo]['final']['max'] = array();
$arrayData[$BillNo]['facilities'] = "";
$arrayData[$BillNo]['total_facility_num'] = $arrayData[$BillNo]['delivery_num'] = $arrayData[$BillNo]['check_num'] = $arrayData[$BillNo]['tryrun_num'] = $arrayData[$BillNo]['install_num'] = $arrayData[$BillNo]['arrive_num'] = $arrayData[$BillNo]['second_num'] = $arrayData[$BillNo]['sign_num'] = $arrayData[$BillNo]['receivable_budget'] = 0;
$arrayData[$BillNo]['total_facility_list']= $arrayData[$BillNo]['sign_list'] = $arrayData[$BillNo]['second_list'] = $arrayData[$BillNo]['arrive_list'] = $arrayData[$BillNo]['install_list'] = $arrayData[$BillNo]['tryrun_list'] = $arrayData[$BillNo]['check_list'] = $arrayData[$BillNo]['delivery_list'] = $arrayData[$BillNo]['final_list'] = [];
}
if (stristr($PayStage, '二次款') || (stristr($PayStage, '出貨前') && $PayStage != "寶佳出貨前30天") || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60') || stristr($PayStage, '寶佳出貨後10天')) {
$arrayData[$BillNo]['second'][0] = $PayStage;
@ -340,7 +363,8 @@ foreach ($wipwhole_array as $wip) {
if ($arrayData[$wip['contractno']]['sign'][0] == "寶佳出貨前30天") {
$facility_status = "";
// if ($arrayData[$wip['contractno']]['sign'][2])
array_push($arrayData[$wip['contractno']]['total_list'], $wip['facilityno']);
//-##############################################################################################################################################
$today = strtotime(date('Ymd'));
$contractday = strtotime($arrayData[$wip['contractno']]['sign'][2]);
$month = collect_month($contractday);
@ -348,6 +372,7 @@ foreach ($wipwhole_array as $wip) {
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['sign'][2] = $arrayData[$wip['contractno']]['sign'][2];
if ($today > $contractday) {
$arrayData[$wip['contractno']]['sign_num'] += 1;
array_push($arrayData[$wip['contractno']]['sign_list'], $wip['facilityno']);
$facility_status = $wip['facilityno'] . " (出貨前30天" . $arrayData[$wip['contractno']]['sign'][2] . "已過) <br>";
$arrayData[$wip['contractno']]['facility'][$wip['facilityno']]['status'] = $facility_status;
//二次款
@ -748,13 +773,17 @@ foreach ($wipwhole_array as $wip) {
}
}
}
print_r($contract_budget['D23070082']);
echo "<br>";
exit();
// 計算每個合約的應收款、作番總數
$today_date = new DateTime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m-d')))));
$contractstage = array('sign', 'second', 'arrive', 'install', 'tryrun', 'check', 'delivery', 'final');
foreach ($arrayData as &$value) {
if ($value['total_facility_num'] > 0) {
$value['receivable_budget'] = $value['sign'][1] * ($value['sign_num'] / $value['total_facility_num']) + ($value['second'][1] * ($value['second_num'] / $value['total_facility_num'])) +
$value['receivable_budget'] = $value['sign'][1] * ($contract_budget[$value[10]]['total'] / $contract_budget[$value[10]]['total']) + ($value['second'][1] * ($value['second_num'] / $value['total_facility_num'])) +
($value['arrive'][1] * ($value['arrive_num'] / $value['total_facility_num'])) + ($value['install'][1] * ($value['install_num'] / $value['total_facility_num'])) +
($value['tryrun'][1] * ($value['tryrun_num'] / $value['total_facility_num'])) + ($value['check'][1] * ($value['check_num'] / $value['total_facility_num'])) +
(($value['delivery'][1] + $value['final'][1]) * ($value['delivery_num'] / $value['total_facility_num']));
@ -971,6 +1000,327 @@ foreach ($arrayData as $key => $value) {
}
}
}
$data = json_encode($excel_aray);
$boga_data = json_encode($boga_array);
$exclude_boga_data = json_encode($exclude_boga_array);
$facility_data = json_encode($facility_array);
$facility_boga_data = json_encode($facility_boga_array);
$facility_exclude_boga_data = json_encode($facility_exclude_boga_array);
?>
<style>
table {
table-layout: fixed;
width: 100%;
}
td {
word-wrap: break-word;
}
img {
width: 125px;
}
.width_style_1 {
width: 125px;
}
table {
width: 100%;
}
#table_index_filter {
float: right;
}
#table_index_paginate {
float: right;
}
label {
display: inline-flex;
margin-bottom: .5rem;
margin-top: .5rem;
}
</style>
<div style="width: 98%;margin: 1%;">
<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="exclude_bogaData()" class="btn btn-info">不含寶佳<span class="glyphicon glyphicon-download-alt"></span></button>
<button type="button" style="width: 12%;" onclick="bogaData()" class="btn btn-warning">寶佳<span class="glyphicon glyphicon-download-alt"></span></button>
</div>
</div>
<div style="width: 98%;margin: 1%;">
<div class="btn-group btn-group-md" style="width: 100%;">
<button type="button" style="width: 12%;" onclick="downloadFacilityData('AllData')" class="btn btn-success btn-md">作番收款明細<span class="glyphicon glyphicon-download-alt"></span></button>
<button type="button" style="width: 12%;" onclick="downloadFacilityData('ExcludeData')" class="btn btn-info btn-md">不含寶佳作番收款明細<span class="glyphicon glyphicon-download-alt"></span></button>
<button type="button" style="width: 12%;" onclick="downloadFacilityData('BogaData')" class="btn btn-warning btn-md">寶佳作番收款明細<span class="glyphicon glyphicon-download-alt"></span></button>
</div>
</div>
<div style="width:98%;margin:1% ;overflow-x: auto;">
<table id="table_index" class="table table-striped table-bordered" style="width:100%;">
<thead>
<tr>
<th style="width: 120px;">合約號</th>
<th style="width: 120px;">部門</th>
<th style="width: 120px;">經理</th>
<th style="width: 120px;">營業員</th>
<th style="width: 120px;">客戶名稱</th>
<th style="width: 120px;">簽約款</th>
<th style="width: 120px;">應收簽約金額</th>
<th style="width: 120px;">簽約最小催收次數</th>
<th style="width: 120px;">簽約最大催收次數</th>
<th style="width: 120px;">二次款</th>
<th style="width: 120px;">應收二次金額</th>
<th style="width: 120px;">二次最小催收次數</th>
<th style="width: 120px;">二次最大催收次數</th>
<th style="width: 120px;">貨抵工地款</th>
<th style="width: 120px;">應收貨抵工地金額</th>
<th style="width: 120px;">貨抵工地最小催收次數</th>
<th style="width: 120px;">貨抵工地最大催收次數</th>
<th style="width: 120px;">安裝款</th>
<th style="width: 120px;">應收安裝金額</th>
<th style="width: 120px;">安裝最小催收次數</th>
<th style="width: 120px;">安裝最大催收次數</th>
<th style="width: 120px;">試車款</th>
<th style="width: 120px;">應收試車金額</th>
<th style="width: 120px;">試車最小催收次數</th>
<th style="width: 120px;">試車最大催收次數</th>
<th style="width: 120px;">官檢款</th>
<th style="width: 120px;">應收官檢金額</th>
<th style="width: 120px;">官檢最小催收次數</th>
<th style="width: 120px;">官檢最大催收次數</th>
<th style="width: 120px;">移交款</th>
<th style="width: 120px;">應收移交金額</th>
<th style="width: 120px;">移交最小催收次數</th>
<th style="width: 120px;">移交最大催收次數</th>
<th style="width: 120px;">尾款</th>
<th style="width: 120px;">應收尾款金額</th>
<th style="width: 120px;">尾款最小催收次數</th>
<th style="width: 120px;">尾款最大催收次數</th>
<th style="width: 120px;">合約總金額</th>
<th style="width: 120px;" style="width: 120px;">目前應收</th>
<th style="width: 120px;" style="width: 120px;">已開發票金額</th>
<th style="width: 120px;">已收金額</th>
<!-- <th>作番狀態</th> -->
<th style="width: 350px;">收款狀態</th>
</tr>
</thead>
<tbody>
<?php
foreach ($arrayData as $key => $value) {
?>
<tr>
<th><a onclick="showContract('<?= $key ?>')"><?= $key ?> </a></th>
<td><?= $value[1] ?></td>
<td><?= $value[2] ?></td>
<td><?= $value[4] ?></td>
<td><?= $value[5] ?></td>
<td><?= number_format(round($value['sign'][1])) ?></td>
<td style="text-align: end;"><?= isset($value['sign'][3]) ? number_format(round($value['sign'][3])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['sign']['min']) ? $value['sign']['min'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['sign']['max']) ? $value['sign']['max'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['second'][1]) ? number_format(round($value['second'][1])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['second'][3]) ? number_format(round($value['second'][3])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['second']['min']) ? $value['second']['min'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['second']['max']) ? $value['second']['max'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['arrive'][1]) ? number_format(round($value['arrive'][1])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['arrive'][3]) ? number_format(round($value['arrive'][3])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['arrive']['min']) ? $value['arrive']['min'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['arrive']['max']) ? $value['arrive']['max'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['install'][1]) ? number_format(round($value['install'][1])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['install'][3]) ? number_format(round($value['install'][3])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['install']['min']) ? $value['install']['min'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['install']['max']) ? $value['install']['max'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['tryrun'][1]) ? number_format(round($value['tryrun'][1])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['tryrun'][3]) ? number_format(round($value['tryrun'][3])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['tryrun']['min']) ? $value['tryrun']['min'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['tryrun']['max']) ? $value['tryrun']['max'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['check'][1]) ? number_format(round($value['check'][1])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['check'][3]) ? number_format(round($value['check'][3])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['check']['min']) ? $value['check']['min'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['check']['max']) ? $value['check']['max'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['delivery'][1]) ? number_format(round($value['delivery'][1])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['delivery'][3]) ? number_format(round($value['delivery'][3])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['delivery']['min']) ? $value['delivery']['min'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['delivery']['max']) ? $value['delivery']['max'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['final'][1]) ? number_format(round($value['final'][1])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['final'][3]) ? number_format(round($value['final'][3])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['final']['min']) ? $value['final']['min'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['final']['max']) ? $value['final']['max'] : '--' ?></td>
<td style="text-align: end;"><?= isset($value['total_budget']) ? number_format(round($value['total_budget'])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['receivable_budget']) ? number_format(round($value['receivable_budget'])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['invoice_budget']) ? number_format(round($value['invoice_budget'])) : '--' ?></td>
<td style="text-align: end;"><?= isset($value['received_budget']) ? number_format(round($value['received_budget'])) : '--' ?></td>
<td style="text-align: start;"><?= $value['facilities'] ?></td>
<!-- <td><button type="button" onclick="sendData('<?= $key ?>')" class="btn btn-primary btn-sm"><span class=" glyphicon glyphicon-search"></span></button>
</td> -->
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<script>
function showContract(BillNo) {
window.open('account-receivable-contract.php?BillNo=' + BillNo + '&<?= $token_link ?>', '發票範例', config = 'height=600, width=1200');
console.log(BillNo);
}
function test() {
var BillData = <?= $boga_data ?>;
var form = document.createElement("form");
form.method = 'POST';
form.action = "account-receivable-excel.php?type=facility&<?= $token_link ?>";
var input = document.createElement("input");
input.type = "hidden";
input.name = "Bill";
input.value = JSON.stringify(BillData);
form.appendChild(input);
document.body.appendChild(form);
form.submit();
}
function downloadData() {
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/account-receivable-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-test.xlsx");
link.setAttribute('download', name);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
// xhr.send(JSON.stringify({
// Bill: <?= $data ?>
// })
// );
xhr.send(JSON.stringify({
Bill: <?= $data ?>
}));
}
function bogaData() {
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/account-receivable-excel.php?type=boga&<?= $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-test.xlsx");
link.setAttribute('download', name);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
xhr.send(JSON.stringify({
Bill: <?= $boga_data ?>
}));
}
function downloadFacilityData(content) {
if (content == 'AllData') {
var BillData = <?= $facility_data ?>;
var filename = "作番應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";
}
else if(content == 'ExcludeData') {
var BillData = <?= $facility_exclude_boga_data ?>;
var filename = "不含寶佳作番應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";
}
else if(content == 'BogaData'){
var BillData = <?= $facility_boga_data ?>;
var filename = "寶佳作番應收帳款" + "<?= date('Y-m-d-Hm') ?>" + ".xlsx";
}
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/account-receivable-excel.php?type=facility&<?= $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');
link.setAttribute('href', window.location.origin + "/wms/account-receivable-facility.xlsx");
link.setAttribute('download', filename);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
xhr.send(JSON.stringify({
Bill: BillData
}));
}
function exclude_bogaData() {
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/account-receivable-excel.php?type=exclude_boga&<?= $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-test.xlsx");
link.setAttribute('download', name);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
xhr.send(JSON.stringify({
Bill: <?= $exclude_boga_data ?>
}));
}
function sendData(BillNo) {
var BillData = <?= $data ?>;
var Bill = BillData[BillNo];
var form = document.createElement("form");
form.method = 'POST';
form.action = "account-receivable-check.php?<?= $token_link ?>";
var input = document.createElement("input");
input.type = "hidden";
input.name = "Bill";
input.value = JSON.stringify(Bill);
form.appendChild(input);
document.body.appendChild(form);
form.submit();
}
</script>
$table = "";
//[stage] 0 款名 1金額 2 應收款日期

54
wms/account-receivable-test.php

@ -9,24 +9,36 @@
// echo $test;
include './header.php';
$sql = "SELECT
salOrderStagePay.BillNo,
salOrderStagePay.PayStage
FROM salOrderStagePay
LEFT JOIN salSalesOrder
ON salSalesOrder.BillNo = salOrderStagePay.BillNo WHERE salSalesOrder.ModeId = 'M' AND (salSalesOrder.CurrentState=2 OR salSalesOrder.CurrentState=4) ";
$query = $conn->query($sql);
$contracts = array();
foreach ($query as $row) {
if (!array_key_exists($row['BillNo'], $contracts)) {
$contracts[$row['BillNo']] = [$row['BillNo'], $row['PayStage']];
}else{
array_push($contracts[$row['BillNo']], $row['PayStage']);
}
}
foreach($contracts as $contract){
foreach($contract as $con){
echo $con.";";
}
echo "<br>";
}
// $sql = "SELECT
// salOrderStagePay.BillNo,
// salOrderStagePay.PayStage
// FROM salOrderStagePay
// LEFT JOIN salSalesOrder
// ON salSalesOrder.BillNo = salOrderStagePay.BillNo WHERE salSalesOrder.ModeId = 'M' AND (salSalesOrder.CurrentState=2 OR salSalesOrder.CurrentState=4) ";
// $query = $conn->query($sql);
// $contracts = array();
// foreach ($query as $row) {
// if (!array_key_exists($row['BillNo'], $contracts)) {
// $contracts[$row['BillNo']] = [$row['BillNo'], $row['PayStage']];
// }else{
// array_push($contracts[$row['BillNo']], $row['PayStage']);
// }
// }
// foreach($contracts as $contract){
// foreach($contract as $con){
// echo $con.";";
// }
// echo "<br>";
// }
//只有一個作番的銷售訂單
// $sql = "select salSalesOrderDetail.BillNo,count(salSalesOrderDetail.MaterialId) AS number from salSalesOrderDetail
// LEFT JOIN salSalesOrder ON salSalesOrder.BillNo=salSalesOrderDetail.BillNo
// where salSalesOrderDetail.ItemType=0 AND salSalesOrder.ModeId='M'
// group by salSalesOrderDetail.BillNo ORDER BY number";
// $query = $conn->query($sql);
// foreach($query as $row){
// if($row['number']==1){
// echo $row['BillNo']."<br>";
// }
// }

Loading…
Cancel
Save