0) {
$column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower);
$column_str .= "')";
$sql .= " OR siam.PersonId IN $column_str OR cd.LeaderId = '$user_id')";
} else {
$sql .= " 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 .= " GROUP BY
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
siam.PersonId ASC,
siam.BillNo ASC,
siamd.RowCode ASC";
$query_T8 = $conn->query($sql);
$rows = $query_T8->fetchAll(PDO::FETCH_ASSOC);
$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 = $row['CU_EstPayDate'] > $today ? 0 : 1;
$data[$tmpname]['collecttime'] = collect_month(strtotime($row['CU_EstPayDate']));
$invoicedate = is_null($row['InvoiceTime']) ? null : date('Y-m-d', strtotime($row['InvoiceTime']));
$tableinvoice_state = is_null($invoicedate) ? 0 : 1;
$contract_no = $row['ProjectId'];
$facility_no = $row['CU_MaterialId'];
$RowCode = $row['RowCode'];
$BillNo = $row['BillNo'];
$receivable_date = date('Y-m-d', strtotime($row['CU_EstPayDate']));
$budget = $row['OAmountWithTax'];
$invoiceNo = $row['InvoiceNo'];
$invoice_budget = is_null($row['InvoiceOAmount']) ? 0 : $row['InvoiceOAmount'];
$table_writeoff_date = is_null($row['WriteOffDate']) ? null : date('Y-m-d', strtotime($row['WriteOffDate']));
$table_writeoff_amount = is_null($row['TotalCurrStandOffOAmount']) ? 0 : $row['TotalCurrStandOffOAmount'];
$table1 = "INSERT INTO account_receivable_maintainance(
`contract_no`,
`facility_no`,
`RowCode`,
`BillNo`,
`receivable_date`,
`budget`,
`receivable`,
`invoice_state`,
`invoice_budget`,
`received_budget`
";
$table2 = ") VALUES(
'$contract_no',
'$facility_no',
'$RowCode',
'$BillNo',
'$receivable_date',
$budget,
$datahavetopay,
$tableinvoice_state,
$invoice_budget,
$table_writeoff_amount
";
$table1 .= is_null($invoicedate) ? "" : ",`invoice_date`";
$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`";
$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 {
// echo "生成SQL文件时出现错误。";
// }
// foreach ($data as $key => $row) {
// echo $key . "
";
// print_r($row);
// echo "
------------
";
// }
// exit();
?>
合約號 | 序號 | 作番號 | 部門 | 主管 | 契約員 | 客戶名稱 | 應收日期 | 是否應收 | 應收金額 | 已收金額 | 催收金額 | 催收次數 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
= $row['ProjectId']; ?> | = $row['RowCode']; ?> | = $row['CU_MaterialId']; ?> | = $row['DeptId'] . " " . $row['DeptName']; ?> |
= $row['LeaderId'] . " " . $row['LeaderName']; ?> |
= $row['PersonId'] . " " . $row['PersonName']; ?> |
= $row['BizPartnerId'] . " " . $row['BizPartnerName']; ?> |
= $row['CU_EstPayDate']; ?> | = $row['havetopay']; ?> | = number_format(round($row['OAmountWithTax'])); ?> | = is_null($row['TotalCurrStandOffOAmount']) ? 0 : number_format(round($row['TotalCurrStandOffOAmount'])); ?> | = ($row['havetopay'] == "V")? (number_format(round($row['OAmountWithTax'] - $row['TotalCurrStandOffOAmount']))) :0; ?> | = (($row['havetopay'] == "V") && ($row['OAmountWithTax'] - $row['TotalCurrStandOffOAmount'] >1))? $row['collecttime']:0; ?> |