<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>EHONGMD</title>
  <?php
  include '_plugin.php';
  include '_connect.php';
?>
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">

<?php
include '_header.php';
include '_menu.php';
?>
<?php
  // $DMY_1 = $_POST['DMY_1'];
  // $DMY_2 = $_POST['DMY_2'];
?>
  <div class="content-wrapper">
    <section class="content">
      <div class="row">
      <!-- ค้นหา -->
      <!-- ตาราง -->
      <?php include 'act_search_2.php' ?>

      <div class="col-md-12">
        <div class="box box-success">
          <div class="box-header">
            <h3 class="box-title"><p class="text-success">รายงาน พ.ร.บ. ซ้ำ</p></h3>
            <p class="text-warning">วันที่ <?php echo $calcdate; ?> ถึงวันที่ <?php echo $calcdate25; ?></p>
          </div>
          <div class="box-body">
            <div class="form-group">
              <table id="example" class="table table-striped table-bordered" style="width:100%">
                <thead style="white-space: nowrap">
                  <tr>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>No.</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>สาขา</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>วันที่ในใบเสร็จ</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>เลขที่สัญญา</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>ชื่อ-สกุล</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>รหัสบริการ พ.ร.บ.</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>ประเภท</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>บริษัทบันทึกบัญชี</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>เลขที่ในใบเสร็จ</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>จำนวนเงิน</b></th>
                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>ชื่อพนักงาน</b></th>

                    <th colspan="2" style="background-color:black; color:#fff; text-align:center;"><b>ค่าใช้จ่าย พ.ร.บ. ซ้ำ</b></th>

                    <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><b>หมายเหตุ</b></th>
                  </tr>
                  <tr>
                    <th style="background-color:black; color:#fff; text-align:center;">มี</th>
                    <th style="background-color:black; color:#fff; text-align:center;">จำนวนเงิน</th>
                  </tr>
                </thead>
                <tbody style="white-space: nowrap">
                  <?php
                  // where a.status<>'V' and a.fee_no='11' and a.bill_date between '$DMY_1' and '$DMY_2'
                  $sql = "SELECT a.bill_no as xbill_no,a.bill_date as xbill_date,*,a.rectime as xrectime from [EHONGDB].[dbo].[reg_billdata] a
                  left outer JOIN(select bill_no as reg_bill_no,plcno,plcdate,plcexp from [EHONGDB].[dbo].[reg_billdatadocument] WHERE FEE_NO = '11' and (plcno is not null) ) ax1 on(ax1.reg_bill_no=a.bill_no)
                  left outer join(SELECT * FROM [EHONGDB].[dbo].[reg_bill]) b on(a.bill_no=b.bill_no)
                  left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                  left outer join(SELECT * FROM [EHONGDB].[dbo].[REG_GWORK]) d on(b.g_id=d.G_ID)
                  left outer join(SELECT BILL_NO as EBILL_NO,ACT_DATE FROM [CONFIG].[dbo].[ACT_EXPOST]) e on(a.bill_no=e.EBILL_NO)
                  left outer JOIN(SELECT BILL_NO as sBILL_NO,ACT_STATUS,ACT_USDATE FROM CONFIG.dbo.ACT_STATUSEXPOST) dx on(a.bill_no=dx.sBILL_NO)
                  left outer join(SELECT bill_no as bill_no2,FEE_NO,FEE_NAME,FEE_PRICE AS FEE_PRICE2 FROM [EHONGDB].[dbo].[reg_billdata] WHERE FEE_NO = '12') abc on(a.bill_no=abc.bill_no2)
                  left outer join(SELECT EMP_ID,TNAME,FNAME,LNAME FROM [EHONGDB].[dbo].[EMPLOYEE]) emp on(b.AUDIT_NO=emp.EMP_ID)
                  WHERE a.CT_NO IN
                  (SELECT CT_NO FROM [EHONGDB].[dbo].[reg_billdata]
                  where status<>'V' and fee_no='11' and bill_date between '$DMY_1' and '$DMY_2'
                  GROUP BY CT_NO HAVING COUNT(*) > 1)
                  and a.status<>'V' and a.fee_no='11' and a.bill_date between '$DMY_1' and '$DMY_2'
                  order by a.CT_NO";
                  // echo $sql;
                  $select=$conn->prepare($sql);
                  $select->execute();
                  $item = 1;
                  $B10 = '10.00';
                  $SUMFEE_SUMPRICE = '0';
                  $SUMFEE_PRICE = '0';
                  $SUMB10 = '0';
                  $SUM_x1 = '0';
                  $SUM_x2 = '0';
                  $SUM2FEE_PRICE = '0';
                  $SUM2FEE_PRICE1 = '0';
                  $FEE_PRICE3 = '0';
                  $FEE_PRICE3x2x = '0';
                  while($fetch=$select->fetch()){
                    if ($fetch['BILL_DATE'] != '') {
                      $BILL_DATE1 = substr($fetch['BILL_DATE'],0,4)+543; $BILL_DATE2 = substr($fetch['BILL_DATE'],5,2); $BILL_DATE3 = substr($fetch['BILL_DATE'],8,2);
                      $BILL_DATE = $BILL_DATE3."/".$BILL_DATE2."/".$BILL_DATE1;
                    } else {
                      $BILL_DATE = '';
                    }
                    if ($fetch['ACT_DATE'] != '') {
                      $ACT_DATE1 = substr($fetch['ACT_DATE'],0,4)+543; $ACT_DATE2 = substr($fetch['ACT_DATE'],5,2); $ACT_DATE3 = substr($fetch['ACT_DATE'],8,2);
                      $ACT_DATE = $ACT_DATE3."/".$ACT_DATE2."/".$ACT_DATE1;
                    } else {
                      $ACT_DATE = '';
                    }
                    if ($fetch['ACT_USDATE'] != '') {
                      $ACT_USDATE1 = substr($fetch['ACT_USDATE'],0,4)+543; $ACT_USDATE2 = substr($fetch['ACT_USDATE'],5,2); $ACT_USDATE3 = substr($fetch['ACT_USDATE'],8,2);
                      $ACT_USDATE = $ACT_USDATE3."/".$ACT_USDATE2."/".$ACT_USDATE1;
                    } else {
                      $ACT_USDATE = '';
                    }
                    if ($fetch['plcdate'] != '') {
                      $plcdate1 = substr($fetch['plcdate'],0,4)+543; $plcdate2 = substr($fetch['plcdate'],5,2); $plcdate3 = substr($fetch['plcdate'],8,2);
                      $plcdate = $plcdate3."/".$plcdate2."/".$plcdate1;
                    } else {
                      $plcdate = '';
                    }
                    $BILL_NOXX1 = $fetch['BILL_NO'];
                  $FEE_PRICE = number_format($fetch['FEE_PRICE']-$B10,2);
                  // $FEE_SUMPRICE = number_format($fetch['FEE_SUMPRICE'],2);
                  // $FEE_SUMPRICE = number_format(350,2);
                  if ($fetch['FEE_SUMPRICE'] != '0') {
                    if ($fetch['CC_SIZE'] < '75') {
                      $FEE_SUMPRICE = number_format(190,2);
                    }
                    if ($fetch['CC_SIZE'] >= '75') {
                      $FEE_SUMPRICE = number_format(350,2);
                    }
                    if ($fetch['CC_SIZE'] > '125') {
                      $FEE_SUMPRICE = number_format(450,2);
                    }
                    if ($fetch['CC_SIZE'] > '150') {
                      $FEE_SUMPRICE = number_format(700,2);
                    }
                    $FEE_PRICE2 = number_format($fetch['FEE_PRICE'],2);
                    $FEE_PRICE3x = number_format($fetch['FEE_PRICE2'],2);
                    $SUM_1 = number_format(($FEE_SUMPRICE-$B10-$FEE_PRICE)/1.07,2);
                    $SUM_2 = number_format(($SUM_1*0.07),2);
                    $SUMFEE_SUMPRICE += $FEE_SUMPRICE;
                    $SUM_x1 += $SUM_1;
                    $SUM_x2 += $SUM_2;
                    $SUM2FEE_PRICE = number_format(($FEE_PRICE2+$FEE_PRICE3x)-$FEE_SUMPRICE,2);
                    $SUM2FEE_PRICE1 += number_format($SUM2FEE_PRICE,2);
                    $FEE_PRICE3 += number_format($FEE_PRICE2,2);
                    $FEE_PRICE3x2x += $FEE_PRICE3x;
                  }
                  else {
                    $FEE_SUMPRICE = '';
                    $FEE_PRICE3x = '';
                    $SUM_1 = '';
                    $SUM_2 = '';
                    $FEE_PRICE2 = '';
                    $SUM2FEE_PRICE = '';
                  }
                  include 'act_sum_1.php';
                  $SUMFEE_PRICE += $FEE_PRICE;
                  $SUMB10 += $B10;

                  ?>
                  <tr>
                    <td style="background-color:; color:; text-align:right;"><?php echo number_format($item); ?>.</td>
                    <td style="background-color:; color:; text-align:;"><?php echo $fetch['BR_ID']." : ".$fetch['BR_NAME']; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $BILL_DATE; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $fetch['CT_NO']; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $fetch['PS_NAME']; ?></td>
                    <td style="background-color:; color:red; text-align:right;"><?php echo $FEE_STATUSX; ?></td>
                    <td style="background-color:; color:red; text-align:;"><?php echo $FEE_STATUSX1; ?></td>
                    <td style="background-color:; color:blue; text-align:;"><?php echo $CROP_NAME; ?></td>
                    <td style="background-color:; color:; text-align:;"><a class="text-red" href="http://192.168.10.51/xehong-linux/printrx.php?sid=sale&fid=payregbillnew&flg=1&bill_no=<?php echo $BILL_NOXX1; ?>" target='_blank'><?php echo $BILL_NOXX1; ?></a></td>
                    <td style="background-color:; color:blue; text-align:right;"><?php echo $FEE_PRICE2; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $fetch['TNAME'].$fetch['FNAME']." ".$fetch['LNAME']; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php //echo $CHKMENOME; ?></td>
                    <td style="background-color:; color:; text-align:;"></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $fetch['BILL_HINT']; ?></td>
                  </tr>
                  <?php $item++; } ?>
                </tbody>
                <tfoot>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b>รวม</b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b><?php echo number_format($FEE_PRICE3,2); ?></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                  <td colspan="" style="background-color:black; color:#fff; text-align:center;"><b></b></td>
                </tfoot>
            </table>
            </div>
          </div>
        </div>
      </div>

      </div>
    </section>
  </div>
</div>

<?php
// include '_footer.php';
// include '_form.php';
?>
<div class="control-sidebar-bg"></div>
<?php include '_script_2.php'; ?>
<?php include 'scroll.php' ?>
</body>
</html>
