<?php
  include '_connect.php';
?>
 <!DOCTYPE html>
<html>
<head>
<style>
table {
  border-collapse: collapse;
  width: 100%;
}
th, td {
  text-align: left;
  padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
  background-color: red;
  color: white;
}
.button {
  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {padding: 10px 24px;}
.button2 {padding: 12px 28px;}
.button3 {padding: 14px 40px;}
.button4 {padding: 32px 16px;}
.button5 {padding: 16px;}
</style>
</head>
<body>

<h2>แก้ไขค่า พ.ร.บ.</h2>
<form class="" action="edit_act1.php" method="post" target="_blank">
  <?php
    $BILL_NO = $_GET['BILL_NO'];
    $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 FEE_PRICE AS EDITFEE_PRICE, BILL_NO AS EDITBILL_NO,NOTE FROM CONFIG.dbo.ACT_EDIT) edit on(a.bill_no=edit.EDITBILL_NO)
    where a.status<>'V' and a.fee_no='11' and a.BILL_NO = '$BILL_NO'
    order by a.rectime,a.br_id,a.bill_date";
    $select=$conn->prepare($sql);
    $select->execute();
    $fetch=$select->fetch();
    $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';
    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 = '';
    }
    $BILL_NOXX1 = $fetch['BILL_NO'];
    if ($fetch['EDITFEE_PRICE'] == "") {
      $FEE_PRICE = number_format($fetch['FEE_PRICE']-$B10,2);
      $NOTE = "";
      $CL = "blue";
      $EDIT = "แก้ไข";
    }
    else {
      $FEE_PRICE = number_format($fetch['EDITFEE_PRICE'],2);
      $NOTE = $fetch['NOTE'];
      $CL = "green";
      $EDIT = "แก้ไขแล้ว";
    }
    // $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;
  ?>
  <table>
    <tr>
      <th>รายละเอียด</th>
      <th>ค่าใช้จ่าย พ.ร.บ. ที่เบิก (บาท)</th>
    </tr>
    <tr>
      <td>ค่ากระดาษ</td>
      <td> <input type="number" id="" name="FEE_PRICE" placeholder="0.00" value="<?php echo $FEE_PRICE; ?>"></td>
    </tr>

  </table>
  <input type="text" id="" name="BILL_DATE" value="<?php echo $BILL_DATE; ?>" hidden>
  <input type="text" id="" name="BILL_NO" value="<?php echo $fetch['BILL_NO']; ?>" hidden>
  <input type="text" id="" name="PS_NAME" value="<?php echo $fetch['PS_NAME']; ?>" hidden>
  <input type="text" id="" name="BRAND_NAME" value="<?php echo $fetch['BRAND_NAME']; ?>" hidden>
  <input type="text" id="" name="SERIAL_NO" value="<?php echo $fetch['SERIAL_NO']; ?>" hidden>
  <input type="text" id="" name="CC_SIZE" value="<?php echo $fetch['CC_SIZE']; ?>" hidden>
  <input type="text" id="" name="NOTE" value="ขยายเวลาให้ชนกับปีภาษี" hidden>

  <br>
  <hr>
  <br>
  <center>
    <input type="submit" name="" class="button button1" value="แก้ไข" onclick="window.opener=null; window.close();">
  </center>
</form>
</body>
</html>
