@ -3,6 +3,10 @@
include "header.php";
$sum_facility = 0;
$sum_facility_A40002 = 0;
$sum_facility_A40009 = 0;
$sum_facility_A40010 = 0;
$sum_facility_A40019 = 0;
// M1
$sum_A40002 = 0;
// 設備
@ -37,6 +41,8 @@ $receivable_array = [];
// T8所有合約號
$sql_contractNumber = "SELECT MainAll.* ,
Person.PersonName,
Dept.LeaderId,
Leader.PersonName AS LeaderName,
Dept.DeptName FROM
(SELECT
Main.BillNo,
@ -55,6 +61,7 @@ Main.CurrentState
LEFT JOIN comBusinessPartner AS Biz ON Biz.BizPartnerId = Main.BizPartnerId) AS MainAll
LEFT JOIN comGroupPerson AS Person ON MainAll.PersonId= Person.PersonId
LEFT JOIN comDepartment AS Dept ON MainAll.DeptId= Dept.DeptId
LEFT JOIN comGroupPerson AS Leader ON Dept.LeaderId = Leader.PersonId
WHERE MainAll.ModeId = 'T' AND (MainAll.CurrentState=2 OR MainAll.CurrentState=4) ";
if (!is_null($start_date)) {
@ -67,7 +74,7 @@ if (!is_null($end_date)) {
}
if ((in_array($user_id, array('M0060', 'M0175'))) || (in_array(accountidToDepartId($user_id), array('220', '210', '321')))) {
} else {
$sql_contractNumber .= " AND (MainAll.PersonId = '$user_id'";
$sql_contractNumber .= " AND (Leader.PersonId = '$user_id' OR MainAll.PersonId = '$user_id'";
if (count($follower) > 0) {
$column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower);
@ -199,10 +206,15 @@ FROM department
ON d.department_id = tmp2.department_id";
//T8 銷售訂單 階段收款計畫
$sql_contract = "SELECT a.BillNo,s.BillDate, a.RowNo, a.PayStage, a.PlanPayAmt, a.PlanPayDate,s.BizPartnerId,c.BizPartnerName, s.PersonId, s.DeptId, s.DeptName,
$sql_contract = "SELECT a.BillNo,s.BillDate, a.RowNo, a.PayStage, a.PlanPayAmt, a.PlanPayDate,s.BizPartnerId,c.BizPartnerName, s.PersonId,
Person.PersonName,
s.DeptId, s.DeptName, Leader.PersonId AS ManagerId,
Leader.PersonName AS ManagerName,
c.EnterpriseName, c.TaxNo, c.ContactAddress FROM salOrderStagePay AS a
LEFT JOIN (SELECT O.*, DE.DeptName FROM salSalesOrder AS O LEFT JOIN comDepartment AS DE ON O.DeptId=DE.DeptId) AS s on a.BillNo = s.BillNo
LEFT JOIN comBusinessPartner AS c ON s.BizPartnerId=c.BizPartnerId ";
LEFT JOIN (SELECT O.*, DE.DeptName, DE.LeaderId FROM salSalesOrder AS O LEFT JOIN comDepartment AS DE ON O.DeptId=DE.DeptId) AS s on a.BillNo = s.BillNo
LEFT JOIN comBusinessPartner AS c ON s.BizPartnerId=c.BizPartnerId
LEFT JOIN comGroupPerson AS Person ON s.PersonId = Person.PersonId
LEFT JOIN comGroupPerson AS Leader ON s.LeaderId = Leader.PersonId ";
// if (isset($str_numbers)) {
// $sql_contract .= "WHERE s.BillNo IN $str_numbers ";
// }
@ -231,6 +243,8 @@ foreach ($contract as $cont) {
$ContactAddress = $cont['ContactAddress'];
$RowNo = $cont['RowNo'];
$salesId = $cont['PersonId'];
$managerId = $cont['ManagerId'];
$managerName = $cont['ManagerName'];
if (!in_array($salesId, $manager_list)) {
array_push($manager_list, $salesId);
}
@ -252,6 +266,9 @@ foreach ($contract as $cont) {
$arrayData[$BillNo][8] = $ContactAddress;
$arrayData[$BillNo][9] = $BillDate;
$arrayData[$BillNo][10] = $BillNo;
$arrayData[$BillNo]['salesName'] = $cont['PersonName'];
$arrayData[$BillNo]['ManagerId'] = $managerId;
$arrayData[$BillNo]['ManagerName'] = $managerName;
$arrayData[$BillNo]['total_budget'] = 0;
$arrayData[$BillNo]['invoice'] = array();
$arrayData[$BillNo]['received_budget'] = 0;
@ -295,6 +312,26 @@ $contract_budget = array();
foreach ($contract_budget_data as $cont) {
$BillNo = $cont['BillNo'];
if (isset($arrayData[$BillNo])) {
$sum_total_budget += $cont['OAmountWithTax'];
switch ($cont['MaterialId']) {
case 'A40002':
$sum_A40002 += $cont['OAmountWithTax'];
$sum_facility_A40002 +=1;
break;
case 'A40009':
$sum_A40009 += $cont['OAmountWithTax'];
$sum_facility_A40009 +=1;
break;
case 'A40010':
$sum_A40010 += $cont['OAmountWithTax'];
$sum_facility_A40010 +=1;
break;
case 'A40019':
$sum_A40019 += $cont['OAmountWithTax'];
$sum_facility_A40019 +=1;
break;
}
$salesid = $arrayData[$BillNo][3];
if (isset($find_manager[$salesid])) {
$arrayData[$BillNo][2] = $find_manager[$salesid]['manager_name'];
@ -307,6 +344,7 @@ foreach ($contract_budget_data as $cont) {
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['total_budget'] += $cont['OAmountWithTax'];
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']][$cont['MaterialId']] += $cont['OAmountWithTax'];
} else {
$sum_facility += 1;
$arrayData[$BillNo]['total_facility_num'] += 1;
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['total_budget'] = $cont['OAmountWithTax'];
$arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['A40002'] = $arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['A40009'] = $arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['A40010'] = $arrayData[$BillNo]['facility'][$cont['CU_MaterialId']]['A40019'] = 0;
@ -593,6 +631,7 @@ foreach ($received_array as $received) {
$arrayData[$BillNo]['received_budget'] += $received['CurrStandOffOAmount'];
// array_push($arrayData[$BillNo]['invoice'][$received['InvoiceNo']], date($received['ReceivedDate']), $received['PayWriteOffOAmount'], $received['Fee'], $received['BillNo']);
// }
}
}
//未在T8的收款資料
@ -651,6 +690,16 @@ $today = strtotime(date('Ymt'));
foreach ($arrayData as $key => $value) {
if (isset($final_paystage[$key])) {
for ($sequence = 1; $sequence < = count($final_paystage[$key]); $sequence++) {
if(!is_null($value['ManagerId']) & & $value['ManagerId'] !==''){
$managerId = $value['ManagerId'];
}else{
$managerId = $value[11];
}
if(!is_null($value['ManagerName']) & & $value['ManagerName'] !==''){
$managerName = $value['ManagerName'];
}else{
$managerName = $value[2];
}
$value[4] = (isset($value[4]) & & !empty($value[4])) ? $value[4] : '--';
$value[5] = (isset($value[5]) & & !empty($value[5])) ? $value[5] : '--';
$value[6] = (isset($value[6]) & & !empty($value[6])) ? $value[6] : '--';
@ -673,7 +722,7 @@ foreach ($arrayData as $key => $value) {
}
if ($havetopay == "V" & & $unReceivedAmount > 1) {
$print_array[$keyname] = [
$value[10], $thisPayStage['facilityno'], $value[0], $value[1], $value[11], $value[2 ], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8],
$value[10], $thisPayStage['facilityno'], $value[0], $value[1], $value[11], $value['ManagerName' ], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8],
$thisPayStage['name'], $thisPayStage['PlanPayDate'], $havetopay,
number_format(round($final_paystage[$key][$sequence]['PayAmount'])),
number_format(round($final_paystage[$key][$sequence]['InvoiceAmount'])), number_format(round($unInvoiceAmount)),
@ -683,7 +732,7 @@ foreach ($arrayData as $key => $value) {
];
}
$excel_aray[$keyname] = [
$value[10], $thisPayStage['facilityno'], $value[0], $value[1], $value[11], $value[2] , $value[3], $value[4], $value[5], $value[6], $value[7], $value[8],
$value[10], $thisPayStage['facilityno'], $value[0], $value[1], $managerId, $managerName , $value[3], $value[4], $value[5], $value[6], $value[7], $value[8],
$thisPayStage['name'], $thisPayStage['PlanPayDate'], $havetopay,
number_format(round($final_paystage[$key][$sequence]['PayAmount'])),
number_format(round($final_paystage[$key][$sequence]['InvoiceAmount'])), number_format(round($unInvoiceAmount)),
@ -695,6 +744,11 @@ foreach ($arrayData as $key => $value) {
}
}
$total_data = json_encode($print_array);
$average_budget = $sum_total_budget / $sum_facility;
$average_A40002 = $sum_A40002 / $sum_facility_A40002;
$average_A40009 = $sum_A40009 / $sum_facility_A40009;
$average_A40010 = $sum_A40010 / $sum_facility_A40010;
$average_A40019 = $sum_A40019 / $sum_facility_A40019;
?>
< style >
@ -752,6 +806,126 @@ $total_data = json_encode($print_array);
< div class = "text-center" style = "margin-bottom: 20px;" >
< h3 > < strong > 合約 (汰改)統整資訊< / strong > < / h3 >
< / div >
< form class = "form-horizontal" >
< div class = "form-group" >
< div class = "col-md-3" >
< label for = "sum_total_budget" > 合約總金額< / label >
< input type = "text" class = "form-control" id = "sum_total_budget" name = "sum_total_budget" value = " <? = number_format ( $sum_total_budget ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "sum_facility" > 總台數< / label >
< input type = "text" class = "form-control" id = "sum_facility" name = "sum_facility" value = " <? = number_format ( $sum_facility ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "average_budget" > 作番平均金額 (元/台)< / label >
< input type = "text" class = "form-control" id = "average_budget" name = "average_budget" value = " <? = number_format ( $average_budget ) ?> " disabled >
< / div >
< / div >
< div class = "form-group" >
< div class = "col-md-3" >
< label for = "sum_A40002" > M1總金額< / label >
< input type = "text" class = "form-control" id = "sum_A40002" name = "sum_A40002" value = " <? = number_format ( $sum_A40002 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "sum_A40009" > 設備總金額< / label >
< input type = "text" class = "form-control" id = "sum_A40009" name = "sum_A40009" value = " <? = number_format ( $sum_A40009 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "sum_A40010" > 安裝總金額< / label >
< input type = "text" class = "form-control" id = "sum_A40010" name = "sum_A40010" value = " <? = number_format ( $sum_A40010 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "sum_A40019" > M4總金額< / label >
< input type = "text" class = "form-control" id = "sum_A40019" name = "sum_A40019" value = " <? = number_format ( $sum_A40019 ) ?> " disabled >
< / div >
< / div >
< div class = "form-group" >
< div class = "col-md-3" >
< label for = "average_A40002" > M1平均金額 (元/台)< / label >
< input type = "text" class = "form-control" id = "average_A40002" name = "average_A40002" value = " <? = number_format ( $average_A40002 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "average_A40009" > 設備平均金額 (元/台)< / label >
< input type = "text" class = "form-control" id = "average_A40009" name = "average_A40009" value = " <? = number_format ( $average_A40009 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "average_A40010" > 安裝平均金額 (元/台)< / label >
< input type = "text" class = "form-control" id = "average_A40010" name = "average_A40010" value = " <? = number_format ( $average_A40010 ) ?> " disabled >
< / div >
< div class = "col-md-3" >
< label for = "average_A40019" > M4平均金額 (元/台)< / label >
< input type = "text" class = "form-control" id = "average_A40019" name = "average_A40019" value = " <? = number_format ( $average_A40019 ) ?> " disabled >
< / div >
< / div >
< / form >
< hr >
< form class = "form-horizontal" id = 'myForm' method = 'post' action = 'account-receivable-new-index.php? <? = $token_link ?> ' >
< table class = "table table-striped table-bordered" style = 'width:98%;text-align:center;margin:0 auto' >
< tbody >
< tr >
< th class = "text-center" style = "vertical-align: middle;" > 合約日期< / th >
< td colspan = "2" >
< input type = "date" class = 'form-control' id = 'date_start' name = 'date_start' style = 'width:40%;display:inline;' >
~
< input type = "date" class = 'form-control' id = 'date_end' name = 'date_end' style = 'width:40%;display:inline;' >
< button type = "submit" class = "btn btn-primary btn-sm" > 搜尋< / button >
< / td >
< / tr >
< tr >
< th class = "text-center" style = "vertical-align: middle;" > 催收次數< / th >
< td colspan = "2" >
< input type = "text" class = 'form-control' id = 'search_collectstart' name = 'collect_time_start' style = 'width:10%;display:inline;' oninput = "searchFront('collectstart')" >
≤ 催收次數 ≤
< input type = "text" class = 'form-control' id = 'search_collectend' name = 'collect_time_end' style = 'width:10%;display:inline;' oninput = "searchFront('collectend')" >
<!-- <button type="submit" class="btn btn - primary btn - sm">搜尋</button> -->
< / td >
< / tr >
< tr >
< th class = "text-center" style = "vertical-align: middle;" > 催收金額< / th >
< td colspan = "2" >
< input type = "text" class = 'form-control' id = 'search_CBudgetstart' name = 'collect_budget_start' style = 'width:40%;display:inline;' onblur = "searchFront('CBudgetstart')" >
≤ 催收金額 ≤
< input type = "text" class = 'form-control' id = 'search_CBudgetend' name = 'collect_budget_end' style = 'width:40%;display:inline;' onblur = "searchFront('CBudgetend')" >
<!-- <button type="submit" class="btn btn - primary btn - sm">搜尋</button> -->
< / td >
< / tr >
< / tbody >
< / table >
< / form >
< hr >
< div class = "form-group" >
< div class = "col-md-4" >
< label for = "search_contract" > 查詢合約號< / label >
< input type = "text" id = "search_contract" name = "search_contract" class = "form-control" placeholder = "請輸入合約號" onblur = "searchFront('contract')" >
< / div >
< div class = "col-md-4" >
< label for = "search_dept" > 查詢部門< / label >
< input type = "text" id = "search_dept" name = "search_dept" class = "form-control" placeholder = "請輸入部門" onblur = "searchFront('dept')" >
< / div >
< div class = "col-md-4" >
< label for = "search_manager" > 查詢主管< / label >
< input type = "text" id = "search_manager" name = "search_manager" class = "form-control" placeholder = "請輸入主管工號/姓名" onblur = "searchFront('manager')" >
< / div >
< / div >
< div class = "form-group" >
< div class = "col-md-4" >
< label for = "search_personId" > 查詢契約員< / label >
< input type = "text" id = "search_personId" name = "search_personId" class = "form-control" placeholder = "請輸入契約員工號/姓名" onblur = "searchFront('personId')" >
< / div >
< div class = "col-md-4" >
< label for = "search_customerid" > 查詢客戶名稱< / label >
< input type = "text" id = "search_customerid" name = "search_customerid" class = "form-control" placeholder = "請輸入客戶名稱" onblur = "searchFront('customerid')" >
< / div >
< div class = "col-md-4" >
< label for = "search_facility" > 查詢作番號< / label >
< input type = "text" id = "search_facility" name = "search_facility" class = "form-control" placeholder = "請輸入作番號" onblur = "searchFront('facility')" >
< / div >
< / div >
< / div >
<?php
include "./footer.php";
@ -785,12 +959,12 @@ include "./footer.php";
< tbody >
<?php foreach ( $excel_aray as $key => $row ) { ?>
< tr class = "data-row" style = "display: '';" id = " <? = $key ; ?> " >
< td > <? = $row [ 0 ]; ?> </ td >
< td > <? = $row [ 1 ]; ?> </ td >
< td > <? = $row [ 2 ] . "<br>" . $row [ 3 ]; ?> </ td >
< td > <? = $row [ 4 ] . "<br>" . $row [ 5 ]; ?> </ td >
< td > <? = $row [ 6 ] . "<br>" . $row [ 7 ]; ?> </ td >
< td > <? = $row [ 8 ]; ?> </ td >
< td class = "contract" > <? = $row [ 0 ]; ?> </ td >
< td class = "facility" > <? = $row [ 1 ]; ?> </ td >
< td class = "dept" > <? = $row [ 2 ] . "<br>" . $row [ 3 ]; ?> </ td >
< td class = "manager" > <? = $row [ 4 ] . "<br>" . $row [ 5 ]; ?> </ td >
< td class = "personId" > <? = $row [ 6 ] . "<br>" . $row [ 7 ]; ?> </ td >
< td class = "customerid" > <? = $row [ 8 ]; ?> </ td >
< td > <? = $row [ 12 ]; ?> </ td >
< td > <? = $row [ 13 ]; ?> </ td >
< td > <? = $row [ 14 ]; ?> </ td >
@ -803,8 +977,8 @@ include "./footer.php";
< td > <? = $row [ 16 ]; ?> </ td >
< td > <? = $row [ 17 ]; ?> </ td >
< td > <? = $row [ 18 ]; ?> </ td >
< td > <? = $row [ 19 ]; ?> </ td >
< td > <? = $row [ 20 ]; ?> </ td >
< td class = "CBudget" > <? = $row [ 19 ]; ?> </ td >
< td class = "collect" > <? = $row [ 20 ]; ?> </ td >
< / tr >
<?php } ?>
< / tbody >
@ -850,7 +1024,91 @@ include "./footer.php";
}));
}
function searchFront(area) {
var term = 'search_' + area;
if (area == 'collectstart') {
var searchTerm = parseInt(document.getElementById(term).value);
var searchArea = document.getElementsByClassName('collect');
var rows = document.getElementsByClassName('data-row');
var criterion = parseInt(document.getElementById('search_collectend').value);
for (var i = 0; i < rows.length ; i + + ) {
var rowText = parseInt(searchArea[i].textContent);
if (rowText >= searchTerm) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
if (criterion !== '' & & rowText > criterion) {
rows[i].style.display = 'none';
}
}
} else if (area == 'collectend') {
var searchTerm = parseInt(document.getElementById(term).value);
var searchArea = document.getElementsByClassName('collect');
var rows = document.getElementsByClassName('data-row');
var criterion = parseInt(document.getElementById('search_collectstart').value);
for (var i = 0; i < rows.length ; i + + ) {
var rowText = parseInt(searchArea[i].textContent);
if (rowText < = searchTerm) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
if (criterion !== '' & & rowText < criterion ) {
rows[i].style.display = 'none';
}
}
} else if (area == 'CBudgetstart') {
var searchTerm = parseInt(document.getElementById(term).value);
var searchArea = document.getElementsByClassName('CBudget');
var rows = document.getElementsByClassName('data-row');
var criterion = parseInt(document.getElementById('search_CBudgetend').value);
for (var i = 0; i < rows.length ; i + + ) {
var rowText = parseInt(searchArea[i].textContent.replace(/,/g, ''));
if (isNaN(searchTerm) || searchTerm == 0) {
rows[i].style.display = '';
} else if (rowText >= searchTerm) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
if (criterion !== '' & & rowText > criterion) {
rows[i].style.display = 'none';
}
}
} else if (area == 'CBudgetend') {
var searchTerm = parseInt(document.getElementById(term).value);
var searchArea = document.getElementsByClassName('CBudget');
var rows = document.getElementsByClassName('data-row');
var criterion = parseInt(document.getElementById('search_CBudgetstart').value);
for (var i = 0; i < rows.length ; i + + ) {
var rowText = parseInt(searchArea[i].textContent.replace(/,/g, ''));
if (isNaN(searchTerm) || searchTerm == 0) {
rows[i].style.display = '';
} else if (rowText < = searchTerm) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
if (!isNaN(criterion) & & rowText < criterion ) {
rows[i].style.display = 'none';
}
}
} else {
var searchTerm = document.getElementById(term).value.toLowerCase();
var searchArea = document.getElementsByClassName(area);
var rows = document.getElementsByClassName('data-row');
for (var i = 0; i < rows.length ; i + + ) {
var rowText = searchArea[i].textContent.toLowerCase();
if (rowText.includes(searchTerm)) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
}
}
}
function check(searchname) {
console.log(searchname);