0) {
$column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower);
$column_str .= "')";
$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 {
$sql .= " OR cd.LeaderId = '$user_id')";
$sql_writeOff .= " OR cd.LeaderId = '$user_id')";
};
}
if (!is_null($start_date)) {
$start_date = (int)date('Ymd', strtotime($start_date));
$sql .= " AND siam.CU_ContractStart >= $start_date ";
}
if (!is_null($end_date)) {
$end_date = (int)date('Ymd', strtotime($end_date));
$sql .= " AND siam.CU_ContractStart <= $end_date ";
}
if (!is_null($start_SignDate)) {
$start_SignDate = (int)date('Ymd', strtotime($start_SignDate));
$sql .= " AND siam.BillDate >= $start_SignDate ";
}
if (!is_null($end_SignDate)) {
$end_SignDate = (int)date('Ymd', strtotime($end_SignDate));
$sql .= " AND siam.BillDate <= $end_SignDate ";
}
$sql .= "
ORDER BY
siam.PersonId ASC,
siam.BillNo ASC,
siamd.RowCode ASC";
$sql_writeOff.=" GROUP BY
wod.FromBillNo
,arCheckBill.LAmountWithTax";
$writeoff = array();
$query_T8 = $conn->query($sql);
$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'));
$table = "";
for ($i = 0; $i < count($rows); $i++) {
$row = $rows[$i];
$tmpname = $row['ProjectId'] . $row['RowCode'];
$data[$tmpname] = $row;
$data[$tmpname]['CU_EstPayDate'] = date('Y-m-d', strtotime($row['CU_EstPayDate']));
$data[$tmpname]['havetopay'] = strtotime($row['CU_EstPayDate']) > $today ? '--' : 'V';
$datahavetopay = strtotime($row['CU_EstPayDate']) > $today ? 0 : 1;
$data[$tmpname]['collecttime'] = collect_month(strtotime($row['CU_EstPayDate']));
$data[$tmpname]['invoicedate'] = is_null($row['InvoiceTime']) ? null : date('Y-m-d', strtotime($row['InvoiceTime']));
$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'];
$facility_no = $row['CU_MaterialId'];
$RowCode = $row['RowCode'];
$BillNo = $row['BillNo'];
$data[$tmpname]['receivable_date'] = (is_null($row['CU_EstPayDate'])) ? null : date('Y-m-d', strtotime($row['CU_EstPayDate']));
$receivable_date = (is_null($data[$tmpname]['receivable_date'])) ? null : $data[$tmpname]['receivable_date'];
$budget = (is_null($row['OAmountWithTax'])) ? 0 : $row['OAmountWithTax'];
$invoiceNo = $row['InvoiceNo'];
$tableinvoice_state = is_null($invoiceNo) ? 0 : 1;
$data[$tmpname]['invoice_budget'] = is_null($row['InvoiceOAmount']) ? 0 : $row['InvoiceOAmount'];
$invoice_budget = (is_null($data[$tmpname]['invoice_budget'])) ? 0 : $data[$tmpname]['invoice_budget'];
$table_writeoff = ($data[$tmpname]['WriteOff'] =='V') ? 1 : 0;
$table1 = "INSERT INTO account_receivable_maintainance(
`contract_no`,
`facility_no`,
`RowCode`,
`BillNo`,
`budget`,
`receivable`,
`invoice_state`,
`invoice_budget`,
`received`
";
$table2 = ") VALUES(
'$contract_no',
'$facility_no',
'$RowCode',
'$BillNo',
$budget,
$datahavetopay,
$tableinvoice_state,
$invoice_budget,
$table_writeoff
";
$table1 .= is_null($receivable_date) ? "" : ",`receivable_date`";
$table2 .= is_null($receivable_date) ? "" : ",'$receivable_date'";
$table1 .= is_null($invoicedate) ? "" : ",`invoice_date`";
$table2 .= is_null($invoicedate) ? "" : ",'$invoicedate'";
$table1 .= is_null($invoiceNo) ? "" : ",`invoice_no`";
$table2 .= is_null($invoiceNo) ? "" : ",'$invoiceNo'";
$table .= $table1 . $table2 . "); \n";
}
// $file_path = 'account_receivable_maintainance_sql.sql';
// if (file_put_contents($file_path, $table) !== false) {
// echo "SQL文件已成功生成:{$file_path}";
// }else{
// "fail";
// }
// foreach ($data as $key => $row) {
// echo $key . "
";
// print_r($row);
// echo "
------------
";
// }
// exit();
?>
合約號 | 序號 | 作番號 | 部門 | 契約員 | 客戶名稱 | 應收日期 | 是否應收 | 款別金額 | 是否收齊 | 催收次數 |
---|---|---|---|---|---|---|---|---|---|---|
= $row['ProjectId']; ?> | = $row['RowCode']; ?> | = $row['CU_MaterialId']; ?> | = $row['DeptId'] . " " . $row['DeptName']; ?> |
= $row['PersonId'] . " " . $row['PersonName']; ?> |
= $row['BizPartnerId'] . " " . $row['BizPartnerName']; ?> |
= $row['CU_EstPayDate']; ?> | = $row['havetopay']; ?> | = number_format(round($row['OAmountWithTax'])); ?> | = $row['WriteOff']; ?> | = (($row['havetopay'] == "V") && ($row['WriteOff'] !== 'V'))? $row['collecttime']:0; ?> |