<?
// 기본 설정 로딩
require_once 'config.php';
require_once 'function.php';
require_once 'lib.php';

//HTML 시작

switch ($_GET[mode]) {
    case "today":
        //당일
        $count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = CURDATE() ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC";
        $msg = "당일 미납리스트";
        $checkall2 = "checked";
        break;
    case "1day":
        //1일전
        $count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 1 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC ";
        $date = str_replace('-', '/', $date);
        $date = date('Y-m-d', strtotime($date . "+1 days"));
        $msg = "1일전 미납리스트($date)";
        $checkall3 = "checked";
        break;
    case "2day":
        //2일전
        $count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 2 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC ";
        $date = str_replace('-', '/', $date);
        $date = date('Y-m-d', strtotime($date . "+2 days"));
        $msg = "2일전 미납리스트($date)";
        $checkall4 = "checked";
        break;
    case "3day":
        //3일전
        $count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 3 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC ";
        $date = str_replace('-', '/', $date);
        $date = date('Y-m-d', strtotime($date . "+3 days"));
        $msg = "3일전 미납리스트($date)";
        $checkall5 = "checked";
        break;

    case "custom":
        //커스텀
        //$count = "SELECT count(servicedb.server_code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = CURDATE() Group By server_code ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC";
        $count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 1 DAY) Group By server_code ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC";
        $msg = "커스텀 미납리스트($date)+1일";
        $checkall6 = "checked";
        break;

    default:
        //전체
        $count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC ";
        $msg = "전체 미납리스트";
        $checkall1 = "checked";
        break;
}
?>

 <form method="get" action="#">
        <input type="radio" name="mode" value="all" <?=$checkall1?>>전체
        <input type="radio" name="mode" value="today" <?=$checkall2?>>당일
        <input type="radio" name="mode" value="1day" <?=$checkall3?>>1일전
        <input type="radio" name="mode" value="2day" <?=$checkall4?>>2일전
        <input type="radio" name="mode" value="3day" <?=$checkall5?>>3일전
<!--        <input type="radio" name="mode" value="custom" <?=$checkall6?>>커스텀(수정중)<br>-->
        <input type="hidden" name="ea" value="<?=$_GET[ea]?>">
        <input type="submit" value="확인">
 </form>
<?
$list_no = (!$_GET[ea]) ? '50' : $_GET[ea];

$total_num = mysql_fetch_array(mysql_query($count, $db_connect));

$total = $total_num[0];
if ($list_no > $total) {$list_no = $total;}
$total_page = ($total != '0') ? ceil($total / $list_no) : '0';

$page = $_GET[curPage];

if (!$page) {$page = 1;} elseif ($page >= $total_page) {$page = $total_page;} else { $page = $page;}

$next_page = ($page-'1') * $list_no;
$next_no = $next_page + $list_no;

switch ($_GET[mode]) {
    case "today":
        //당일
        $query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = CURDATE() ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC limit " . $next_page . "," . $next_no;
        break;
    case "1day":
        //1일전
        $query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 1 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC  limit " . $next_page . "," . $next_no;
        break;
    case "2day":
        //2일전
        $query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 2 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC  limit " . $next_page . "," . $next_no;
        break;
    case "3day":
        //3일전
        $query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 3 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC  limit " . $next_page . "," . $next_no;
        break;

    case "custom":
        //커스텀
        //$query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = CURDATE() Group By server_code ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC  limit ".$next_page.",".$next_no;
        $query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 1 DAY) Group By server_code ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC  limit " . $next_page . "," . $next_no;
        break;

    default:
        //전체
        $query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND  adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC  limit " . $next_page . "," . $next_no;
        break;
}

$result = @mysql_query($query, $db_connect) or die($db_q_error);
?>
<!--미납 서버 대수 : <?=$total?>-->
<?=$msg?> <a class="btn btn-outline btn-default"  href="IdcDepositNonPaymentListExcel.dep">엑셀</a>
<div class="table-responsive" id="table">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th style="text-align:center;width:100px;">고객명</th>
<th style="text-align:center;width:60px;">종류</th>
<th style="text-align:center;width:130px;">장비명</th>
<th style="text-align:center;width:120px;">IP</th>
<th style="text-align:center;width:100px;">결제일</th>
<th style="text-align:center;width:100px;">서비스 가격</th>
<th style="text-align:center;width:100px;">과금상태</th>
<th style="text-align:center;width:100px;">미납과금</th>
<!--<th>청구서 발행 대상</th>-->
<th style="text-align:center;">비고</th>
</tr>
</thead>
<tbody>
<?

for ($i = $next_page; $i < $next_no; $i++) {
    $data = mysql_fetch_assoc($result);
    $num = ($total) - $i;
    $reg_date = date("Y/m/d H:i", $data['reg_date']);
    ?>


<tr>
<!-- <td><input type="radio"></td>
<td><?=$data[Client_Code]?></td>
-->
<td style="text-align:center;"><a href="/IdcDepositNonPaymentList.dep?searchContent=<?=$data[Client_Name]?>"><?=$data[Client_Name]?></a></td>
<td style="text-align:center;"><?=$data[adddb_case]?></td>
<td style="text-align:center;"><?=$data[server_code]?></td>
<td style="text-align:center;"><?=$data[service_ip]?></td>
<!--<td><?=$data[service_code]?></td>-->

<td style="text-align:center;"><?=$data[service_payment_date]?></td>
<td style="text-align:center;"><?=$data[service_amount]?></td>
<!--<td><?=$data[adddb_payment]?></td>-->
<td style="text-align:center;"><?=$data[adddb_accountStatus]?></td>
<td style="text-align:center;"><?=$data[adddb_nonpayment]?></td>
<!--<td><?=$data[adddb_accountStatus]?></td>-->
<!--<td></td>-->
<td><?=$data[service_note]?></td>
</td>
</tr>
<?}?>
</tbody>
<tfoot></tfoot>
</table>
<div align='center'>
<?
$setup_dir = "http://" . $_SERVER['HTTP_HOST'] . ":6752";
$page_scale = 10;
$page3 = floor(($total_page-'1') / $page_scale);
$n_page = floor(($page-'1') / $page_scale);

if ($n_page > 0) {

    $p_start = (($n_page - 1) * $page_scale)+'1';
    $link = "<a onfocus=blur() href='" . $setup_dir . "/IdcDepositNonPaymentListMK.dep?mode=$_GET[mode]&ea=$_GET[ea]&curPage=" . $p_start . "'>";
    $link .= "<<";
    $link .= "</a>";
    echo $link . " ";
}
$is = ($n_page * $page_scale)+'1';
for ($i = $is; $i < $is + $page_scale; $i++) {

    if ($i < $total_page+'1') {
        if ($i == $page) {$ib = "<b>$i</b>";} else { $ib = $i;}
        $link = "<a onfocus=blur() href='" . $setup_dir . "/IdcDepositNonPaymentListMK.dep?mode=$_GET[mode]&ea=$_GET[ea]&curPage=" . $i . "'>";
        $link .= $ib;
        $link .= "</a>";
        echo $link . " ";
    }
}
if ($n_page < $page3) {
    $link = "<a onfocus=blur() href='" . $setup_dir . "/IdcDepositNonPaymentListMK.dep?mode=$_GET[mode]&ea=$_GET[ea]&curPage=" . $i . "'>";
    $link .= ">>";
    $link .= "</a>";
    echo $link;
}
?>
</div>



<?
//DB닫기
mysql_close($db_connect);
?>
<!--<div id='exec_time'><?=sprintf('%0.3f', getmicrotime() - $MK_start)?> sec</div>-->
