You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

469 lines
17 KiB

<?php
// ini_set('display_errors', 'on');
$real_arrival_date_start = empty($_REQUEST['real_arrival_date_start']) ? date("Y") . '-01' : $_REQUEST['real_arrival_date_start'];
$real_arrival_date_end = empty($_REQUEST['real_arrival_date_end']) ? date("Y-m") : $_REQUEST['real_arrival_date_end'];
$radsY = SUBSTR($real_arrival_date_start, 0, 4);
$radsM = SUBSTR($real_arrival_date_start, 5, 2);
$radeY = SUBSTR($real_arrival_date_end, 0, 4);
$radeM = SUBSTR($real_arrival_date_end, 5, 2);
include "header.php";
// 出貨台數
function getShipping($type, $mtype, $radsY, $radsM, $year, $month)
{
global $link;
$sql = "
SELECT
count(*) AS all_count
FROM wipwholestatus
WHERE status = '1'
AND (
real_arrival_date IS NOT NULL
AND real_arrival_date != ''
)
AND real_arrival_date BETWEEN '$radsY-$radsM-01' AND '$year-$month-31'
";
$sql .= !empty($type) ? " AND contract_type = '$type'" : "";
$sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : "";
// echo $sql . "<br/>";
$result = mysqli_query($link, $sql);
$data = mysqli_fetch_array($result, MYSQLI_ASSOC);
return $data['all_count'];
}
// 試車完台數
function getInstalling($type, $mtype, $radsY, $radsM, $year, $month)
{
global $link;
$sql = "
SELECT
count(*) AS all_count
-- real_arrival_date,
-- tryrun_end_date
FROM wipwholestatus
WHERE status = '1'
AND (
real_arrival_date IS NOT NULL
AND real_arrival_date != ''
)
AND real_arrival_date BETWEEN '$radsY-$radsM-01' AND '$year-$month-31'
AND tryrun_end_date <= '$year-$month-31'
AND tryrun_end_date != ''
AND tryrun_end_date IS NOT NULL
";
$sql .= !empty($type) ? " AND contract_type = '$type'" : "";
$sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : "";
// echo $sql."<br/>";
$result = mysqli_query($link, $sql);
$data = mysqli_fetch_array($result, MYSQLI_ASSOC);
return $data['all_count'];
}
// 工收台數
function getEnding($type, $mtype, $radsY, $radsM, $year, $month)
{
global $link;
$sql = "
SELECT
count(
*
) AS all_count
-- real_arrival_date,
-- delivery_date,
-- official_check_date
FROM wipwholestatus
WHERE status = '1'
AND real_arrival_date BETWEEN '$radsY-$radsM-01' AND '$year-$month-31'
AND (delivery_date BETWEEN '$radsY-$radsM-01' AND '$year-$month-31'
OR
official_check_date BETWEEN '$radsY-$radsM-01' AND '$year-$month-31'
)
";
$sql .= !empty($type) ? " AND contract_type = '$type'" : "";
$sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : "";
// echo $sql . "<br/>";
$result = mysqli_query($link, $sql);
$data = mysqli_fetch_array($result, MYSQLI_ASSOC);
return $data['all_count'];
}
// 在裝中台數
function getInstalling2($type, $mtype, $radsY, $radsM, $year, $month)
{
global $link;
$sql = "
SELECT
count(*) AS all_count
-- delivery_date,
-- official_check_date
FROM wipwholestatus
WHERE status = '1'
AND real_arrival_date BETWEEN '$radsY-$radsM-01' AND '$year-$month-31'
AND (
delivery_date IS NULL
OR delivery_date = ''
OR delivery_date >= '$year-$month-31'
)
AND(
official_check_date IS NULL
OR official_check_date = ''
OR official_check_date >= '$year-$month-31'
)
";
$sql .= !empty($type) ? " AND contract_type = '$type'" : "";
$sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : "";
$result = mysqli_query($link, $sql);
$data = mysqli_fetch_array($result, MYSQLI_ASSOC);
return $data['all_count'];
}
?>
<form id='myForm' method='post' action='wipwhole-wipinstallstatus-index.php?<?= $token_link ?>'>
<table class='table query-table table-striped table-bordered display compact' style='width:98%;text-align:center;margin:0 auto'>
<thead>
<tr>
<td>
<h3 style='text-align:center'>在裝中統計表</h3>
</td>
</tr>
</thead>
<tbody>
<tr>
<td style='text-align:center'>
<?php
if ((int)$radsY . $radsM > (int)$radeY . $radeM) {
echo "<span class='text-danger'>結束時間不可小於開始時間</span>";
}
?>
</td>
</tr>
<tr>
<td style='text-align:center'>
<input type="month" class='form-control' id='real_contract_arrival_date_start' name='real_arrival_date_start' value="<?php echo $real_arrival_date_start; ?>" style='width:20%;display:inline;'>
<input type="month" class='form-control' id='real_arrival_date_end' name='real_arrival_date_end' value="<?php echo $real_arrival_date_end; ?>" style='width:20%;display:inline;'>
</td>
</tr>
<tr>
<td style='text-align:center'>
<button type="submit" style='text-align:center; margin:0 auto' class="btn btn-primary btn-sm">查詢</button>
<button type="button" style='text-align:center; margin:0 auto' class="btn btn-primary btn-sm" onclick='clean_all_input()'>清除</button>
<!-- <button type="button" style='text-align:center; margin:0 auto' class="btn btn-primary btn-sm" onclick='generateButton()'>匯出excel</button> -->
</td>
</tr>
</tfoot>
</table>
</form>
<?php
if ((int)$radsY . $radsM > (int)$radeY . $radeM) {
exit;
}
?>
<table class="table table-striped table-bordered" style="width:98.5%;overflow-x:auto">
<thead>
<tr>
<th style="width:150px;" rowspan="2">出貨年月</th>
<?php
$start_y = $radsY;
for ($radsYi = $radsY; $radsYi <= $radeY; $radsYi++) {
$start_month = 1;
$end_month = 12;
// 迴圈第一年
if ($start_y == $radsYi) {
$start_month = $radsM;
} else {
$start_month = 1;
}
// 迴圈最後一年
if ($radsYi == $radeY) {
$end_month = $radeM;
}
?>
<th style='text-align:center;' colspan="<?php echo $end_month * 4 ?>"><?php echo $radsYi . '年'; ?></th>
<?php
}
?>
<!-- <th style='width:200px' colspan="3" rowspan="2">總計(全部)</th> -->
</tr>
<tr>
<!-- <th style="width:150px;"></th> -->
<?php
$start_y = $radsY;
for ($radsYi = $radsY; $radsYi <= $radeY; $radsYi++) {
$start_month = 1;
$end_month = 12;
// 迴圈第一年
if ($start_y == $radsYi) {
$start_month = $radsM;
} else {
$start_month = 1;
}
// 迴圈最後一年
if ($radsYi == $radeY) {
$end_month = $radeM;
}
for ($start_month; $start_month <= $end_month; $start_month++) {
?>
<th style='width:200px;text-align:center;' colspan="4"><?php echo (int)$start_month . '月'; ?></th>
<?php
}
?>
<?php
}
?>
<!-- <th style='width:200px' colspan="3" rowspan="2"></th> -->
</tr>
<tr>
<th>種類</th>
<?php
$start_y = $radsY;
for ($radsYi = $radsY; $radsYi <= $radeY; $radsYi++) {
$start_month = 1;
$end_month = 12;
// 迴圈第一年
if ($start_y == $radsYi) {
$start_month = $radsM;
} else {
$start_month = 1;
}
// 迴圈最後一年
if ($radsYi == $radeY) {
$end_month = $radeM;
}
for ($start_month; $start_month <= $end_month; $start_month++) {
?>
<th style="background-color:#CECECE;">出貨</th>
<th style="background-color:#DEDEDE;">工收</th>
<th style="background-color:#EEEEEE;">試車完</th>
<th style="background-color:#FFFFFF;">在裝中</th>
<?php
}
?>
<?php
}
?>
<!-- <th style="background-color:#FF8040;">出貨</th>
<th style="background-color:#FFAF60;">工收</th>
<th style="background-color:#9D9D9D;">試車完</th> -->
</tr>
</thead>
<tbody>
<tr>
<td>新梯</td>
<?php
$a_count = 0;
$b_count = 0;
$c_count = 0;
for ($radsYi = $radsY; $radsYi <= $radeY; $radsYi++) {
$start_month = 1;
$end_month = 12;
// 迴圈第一年
if ($start_y == $radsYi) {
$start_month = $radsM;
} else {
$start_month = 1;
}
// 迴圈最後一年
if ($radsYi == $radeY) {
$end_month = $radeM;
}
for ($start_month; $start_month <= $end_month; $start_month++) {
// 新梯出貨
$all_count = 0;
$all_count = getShipping("A", "", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#CECECE;'>$all_count</td>";
// 新梯工收
$all_count = 0;
$all_count = getEnding("A", "", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#DEDEDE;'>$all_count</td>";
// 新梯試車完
$all_count = 0;
$all_count = getInstalling("A", "", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#EEEEEE;'>$all_count</td>";
// 新梯在裝中
$all_count = 0;
$all_count = getInstalling2("A", "", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#FFFFFF;'>$all_count</td>";
}
?>
<?php
}
// echo "<td style='background-color:#FF8040;'>$a_count</td>";
// echo "<td style='background-color:#FFAF60;'>$b_count</td>";
// echo "<td style='background-color:#9D9D9D;'>$c_count</td>";
?>
</tr>
<tr>
<td>M1</td>
<?php
$a_count = 0;
$b_count = 0;
$c_count = 0;
for ($radsYi = $radsY; $radsYi <= $radeY; $radsYi++) {
$start_month = 1;
$end_month = 12;
// 迴圈第一年
if ($start_y == $radsYi) {
$start_month = $radsM;
} else {
$start_month = 1;
}
// 迴圈最後一年
if ($radsYi == $radeY) {
$end_month = $radeM;
}
for ($start_month; $start_month <= $end_month; $start_month++) {
// M1出貨
$all_count = 0;
$all_count = getShipping("B", "M1", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#CECECE;'>$all_count</td>";
// M1工收
$all_count = 0;
$all_count = getEnding("B", "M1", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#DEDEDE;'>$all_count</td>";
// M1試車完
$all_count = 0;
$all_count = getInstalling("B", "M1", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#EEEEEE;'>$all_count</td>";
// M1在裝中
$all_count = 0;
$all_count = getInstalling2("B", "M1", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#FFFFFF;'>$all_count</td>";
}
?>
<?php
}
// echo "<td style='background-color:#FF8040;'>$a_count</td>";
// echo "<td style='background-color:#FFAF60;'>$b_count</td>";
// echo "<td style='background-color:#9D9D9D;'>$c_count</td>";
?>
</tr>
<tr>
<td>MA</td>
<?php
$a_count = 0;
$b_count = 0;
$c_count = 0;
for ($radsYi = $radsY; $radsYi <= $radeY; $radsYi++) {
$start_month = 1;
$end_month = 12;
// 迴圈第一年
if ($start_y == $radsYi) {
$start_month = $radsM;
} else {
$start_month = 1;
}
// 迴圈最後一年
if ($radsYi == $radeY) {
$end_month = $radeM;
}
for ($start_month; $start_month <= $end_month; $start_month++) {
// MA出貨
$all_count = 0;
$all_count = getShipping("B", "MA", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#CECECE;'>$all_count</td>";
// MA工收
$all_count = 0;
$all_count = getEnding("B", "MA", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#DEDEDE;'>$all_count</td>";
// MA試車完
$all_count = 0;
$all_count = getInstalling("B", "MA", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#EEEEEE;'>$all_count</td>";
// MA在裝中
$all_count = 0;
$all_count = getInstalling2("B", "MA", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#FFFFFF;'>$all_count</td>";
}
?>
<?php
}
// echo "<td style='background-color:#FF8040;'>$a_count</td>";
// echo "<td style='background-color:#FFAF60;'>$b_count</td>";
// echo "<td style='background-color:#9D9D9D;'>$c_count</td>";
?>
</tr>
<tr>
<td>合計</td>
<?php
$a_count = 0;
$b_count = 0;
$c_count = 0;
for ($radsYi = $radsY; $radsYi <= $radeY; $radsYi++) {
$start_month = 1;
$end_month = 12;
// 迴圈第一年
if ($start_y == $radsYi) {
$start_month = $radsM;
} else {
$start_month = 1;
}
// 迴圈最後一年
if ($radsYi == $radeY) {
$end_month = $radeM;
}
for ($start_month; $start_month <= $end_month; $start_month++) {
// 出貨
$all_count = 0;
$all_count = getShipping("", "", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#CECECE;'>$all_count</td>";
// 工收
$all_count = 0;
$all_count = getEnding("", "", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#DEDEDE;'>$all_count</td>";
// 試車完
$all_count = 0;
$all_count = getInstalling("", "", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#EEEEEE;'>$all_count</td>";
// 在裝中
$all_count = 0;
$all_count = getInstalling2("", "", $radsY, $radsM, $radsYi, str_pad($start_month, 2, "0", STR_PAD_LEFT));
echo "<td style='background-color:#FFFFFF;'>$all_count</td>";
}
?>
<?php
}
// echo "<td style='background-color:#FF8040;'>$a_count</td>";
// echo "<td style='background-color:#FFAF60;'>$b_count</td>";
// echo "<td style='background-color:#9D9D9D;'>$c_count</td>";
?>
</tr>
</tbody>
</table>
<script>
</script>