<?php include "common/user_log.php"; 

date_default_timezone_set('Asia/Colombo');
$date = date("Y-m-d");

if(isset($_GET['id'])) {
	$id = htmlspecialchars(trim($_GET['id']), ENT_QUOTES, 'UTF-8');
	$sql = "SELECT
projects_reg.pro_name,
contractor_reg.name AS supplier,
contractor_reg.address,
project_invoice.`date`,
project_invoice.pub_supplier,
project_invoice.tot_pay,
project_invoice.less_adv_pay,
project_invoice.invoice_no,
project_invoice.project,
project_invoice.payment_type,
project_invoice.advance,
project_invoice.less_reten_val,
project_invoice.note,
project_invoice.retention,
project_invoice.less_reten,
project_invoice.vat_retention,
project_invoice.gross_amount,
project_invoice.less_LD_val,
project_invoice.supplier AS con,
division.division,
project_invoice.vat_val,
project_invoice.vat
FROM
project_invoice
Inner Join projects_reg ON projects_reg.id = project_invoice.project
Inner Join contractor_reg ON project_invoice.supplier = contractor_reg.id
Inner Join division ON division.id = projects_reg.division
WHERE
project_invoice.flag =  '1' AND
project_invoice.id =  '$id'
";
	
	$sql_invq = mysqli_query($conn, $sql);
	if(mysqli_num_rows($sql_invq) == 0) {
		$id = '';
	
	} else {
		$sql_inv = mysqli_fetch_assoc($sql_invq);
		$pr_id = $sql_inv['project'];
		$sup = $sql_inv['con'];
		
		$sql_con = mysqli_fetch_assoc(mysqli_query($conn, "SELECT c_num, pro_sum FROM aworded_contractors WHERE project='$pr_id' AND supplier='$sup'"));

		date_default_timezone_set('Asia/Colombo');
		$date_today = date("Y-m-d");
	}
	
} else {
	$id = '';
}
if(empty($id)) { 
	$redirectUrl = "approved_invoices.php";
	echo "<script type=\"text/javascript\">";
	echo "window.location.href = '$redirectUrl'";
	echo "</script>";
}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>NWP Engineering Department</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="dist/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="dist/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="plugins/colorpicker/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="plugins/select2/select2.min.css">
	<!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load.  -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="bootstrap-sweetalert/lib/sweet-alert.css" />
  </head>
  <body class="hold-transition skin-blue sidebar-mini" onload="window.print();">
    <div class="wrapper">

      <header class="main-header">
        <!-- Logo -->
         <a href="home.php" class="logo">
          <!-- mini logo for sidebar mini 50x50 pixels -->
         <span class="logo-mini"><img src="img/logo.png" width="100"></span>
          <!-- logo for regular state and mobile devices -->
        <span class="logo-lg"><b><img src="img/logo.png" width="100"></b></span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
          <!-- Sidebar toggle button-->
          <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
			 <span class="logo-lg">
             &nbsp;&nbsp;<font face="Lucida Sans Unicode, Lucida Grande, sans-serif">NWP Engineering Department</font></span>
          </a>
		
          <div class="navbar-custom-menu">
            <ul class="nav navbar-nav">

              <!-- User Account: style can be found in dropdown.less -->
              <li class="dropdown user user-menu">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                  <img src="dist/img/user2-160x160.png" class="user-image" alt="User Image">
                  <span class="hidden-xs"><?php echo $name; ?></span>
                </a>
                <ul class="dropdown-menu">
                  <!-- User image -->
                  <li class="user-header">
                    <img src="dist/img/user2-160x160.png" class="img-circle" alt="User Image">
                    <p>
             NWP Engineering Department
                    
                    </p>
                  </li>
                  <!-- Menu Body -->
                 
                  <!-- Menu Footer-->
                  <li class="user-footer">
                    <div class="pull-left">
                      
                    </div>
                    <div class="pull-right">
                      <a href="distroy.php" class="btn btn-default btn-flat">Sign out</a>
                    </div>
                  </li>
                </ul>
              </li>
              <!-- Control Sidebar Toggle Button -->
              <li>
                <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
              </li>
            </ul>
          </div>
        </nav>
      </header>
      <!-- Left side column. contains the logo and sidebar -->
      <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
          <!-- Sidebar user panel -->
    <?php include "common/sidebar.php"; ?>  
     
        </section>
        <!-- /.sidebar -->
      </aside>

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">


        <!-- Main content -->
        <section class="content">

<style>
hr {
	border-top: 1px solid #222d32;
	margin: 0;
}
p {
    margin: 3px 8px 3px 8px;
}
.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {
	border-top: none;
	padding: 3px;
}
u {    
    border-bottom: 1px dotted #000;
    text-decoration: none;
	padding: 0 80px;
}
</style>		
		
<!-- ************************************************* -->

    <div style="background-color:#fff;"> 
      <!-- /.box-header -->
      <div class="box-body"> 
        
		<table class="table" border="0">	
		  <tr>
			<td></td>
			<td width="15%"></td>
			<td align="center" width="18%">General 35</td>
		  </tr>
		  <tr>
			<td rowspan="2">Payable within 30 days from the date of issue</td>
			<td>Voucher No</td>
			<td align="right">
			<table width="100%" border="1">
			   <tr>
				 <td height="25"><p style="margin:3px"><?php echo $sql_inv['invoice_no']; ?></p></td>
			   </tr>
			</table>
			</td>
		  </tr>
		  <tr>
			<td>Cheque No</td>
			<td align="right">
			<table width="100%" border="1">
			   <tr>
				 <td height="28"><p style="margin:3px"></p></td>
			   </tr>
			</table>			
			</td>
		  </tr>	
        </table>
		
		<table class="table" border="0">
		  <tr>
			<td>
			<h4 style="margin-top:-25px;"><b>SRI LANKA</b></h4>
			<table class="" border="0" width="100%">
				<tr><td width="15%">Station:</td><td width="85%" style="border-bottom: 1px dotted;">Regional Engineering Office, <?php echo $sql_inv['division']; ?></td></tr>
				<tr><td>Debit Particulars:</td><td style="border-bottom: 1px dotted;"></td></tr>
				<tr><td>Payable To:</td><td style="border-bottom: 1px dotted;"><?php if(empty($sql_inv['pub_supplier'])) { echo $sql_inv['supplier'].', '.$sql_inv['address']; } else { echo $sql_inv['pub_supplier']; }?></td></tr>
			</table>
			<br>
			</td>
		  </tr>
		</table>
		<table class="" border="1">
		  <tr>
			<td width="10%"><p>Date<p></td>
			<td><p>Detailed description of service rendered, work executed or goods supplied and Certificate of Approving officer, where necessary</p></td>
			<td width="15%" align="center">Rate</td>
			<td width="15%" valign="bottom"><p align="right">Rs. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cts</p></td>
		  </tr>
		  
		  <tr>
			<td rowspan="9" valign="top"><p><?php echo $sql_inv['date']; ?></p></td>
			<td>
			<p><?php echo $sql_inv['pro_name']; ?></p>
			<p>Contract Number: <b><?php echo $sql_con['c_num']; ?></b></p><p><?php echo $sql_inv['note']; ?></p>
			<br><p>Bill Amount <span class="pull-right"><?php 
			if($sql_inv['payment_type'] == 'Advance Payment') {
				$bill_amt = $sql_inv['advance'];
			
			} else if($sql_inv['payment_type'] == 'Retention Payment') {
				$bill_amt = $sql_inv['retention']; 
			
			} else {
				$bill_amt = $sql_inv['gross_amount']+$sql_inv['less_reten_val']; 
			}
			$tot_pay = $sql_inv['tot_pay']; 
			echo number_format($bill_amt, 2); ?></span></p>
			</td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
		  </tr>
		  <tr>
			<td><p>(-) Pre Payments <span class="pull-right"><?php $pre_pay = 0; echo number_format($pre_pay, 2); ?></span></p></td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
		  </tr>
		  <tr>
			<td><p class="pull-right"><?php $bal = $bill_amt-$pre_pay; echo number_format($bal, 2); ?></p><p>&nbsp;</p>
			<p>(-) <?php if($sql_inv['less_reten'] == 0) { echo '5'; } else { echo (int)$sql_inv['less_reten']; } ?>% Retention Amount<span class="pull-right"><?php if($sql_inv['payment_type'] == 'Part Payment') {
				$det_amt = $sql_inv['less_reten_val'];
			} else {$det_amt = 0; }  echo number_format($det_amt, 2);  ?></span></p></td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
		  </tr>
		  <tr>
			<td><p class="pull-right"><?php $bal2 = $bal-$det_amt; echo number_format($bal2, 2); ?></p><p>&nbsp;</p>
			<p>(-) Paid Advance <!--Less - Advance Payment--> <span class="pull-right"><?php $paid_adv = $sql_inv['less_adv_pay']; echo number_format($paid_adv, 2); ?></span></p>
			<p>(-) Less LD <span class="pull-right"><?php $less_ld = $sql_inv['less_LD_val']; echo number_format($less_ld, 2); ?></span></p>
			</td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
		  </tr>
		  <tr>
			<td><p class="pull-right"><?php $bal3 = $bal2-$paid_adv-$less_ld; echo number_format($bal3, 2); ?></p><p>&nbsp;</p>
			<hr style="width:20%;" class="pull-right"><p style="margin:0">&nbsp;</p>
			<p class="pull-right" style="margin-top:-20px"><?php echo number_format($bal3, 2); ?></p>
			<p>(+) <?php if($sql_inv['vat'] == 0) { echo '8'; } else { echo (int)$sql_inv['vat']; } ?>% VAT<span class="pull-right"><?php 
			if($sql_inv['payment_type'] == 'Retention Payment') {
				$vat = 0;
			} else {
				$vat = $sql_inv['vat_val'];
			}
			echo number_format($vat, 2); ?></span></p></td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
		  </tr>
		  <tr>
			<td><p class="pull-right"><?php $tot = $bal3+$vat; echo number_format($tot, 2); ?></p><p>&nbsp;</p>
			<hr style="width:20%;" class="pull-right">
			<p><b>Payment for the contractor</b></p></td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
			<td  style="border-bottom-color: transparent;" valign="bottom" align="right"><p><b><?php echo number_format($tot, 2); ?></b></p></td>
		  </tr>
		  <tr>
			<td><p><b><?php if($sql_inv['less_reten'] == 0) { echo '5'; } else { echo (int)$sql_inv['less_reten']; } ?>% retention amount for the savings account</b></p></td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
			<td style="border-bottom-color: transparent;" valign="bottom" align="right"><p><b><?php echo number_format($det_amt, 2); ?></b></p></td>
		  </tr>
		  <tr>
			<td><p><b><?php if($sql_inv['vat'] == 0) { echo '8'; } else { echo (int)$sql_inv['vat']; } ?>% VAT retention savings account</b></p></td>
			<td style="border-bottom-color: transparent;">&nbsp;</td>
			<td valign="bottom" align="right" style="border-bottom-color: transparent;"><p><b><?php 
			if($sql_inv['payment_type'] == 'Retention Payment') {
				$vatr = $sql_inv['vat_retention'];
				echo number_format($vatr, 2);
			
			} else {
				echo number_format(0, 2);
			}
			 ?></b></p></td>
		  </tr>
		  <tr>
			<td><br>
			<p>Authority for payment and reference to file</p></td>
			<td>&nbsp;</td>
			<td valign="top" align="right"><p><b>-</b></p></td>
		  </tr>
		  <tr>
			<td colspan="2">
			<p style="margin:5px">Prepared by &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..............................................................................................</p>
			<p style="margin:5px">Checked by &nbsp;&nbsp;..............................................................................................</p></td>
			<td><p>Total</p></td>
			<td align="right"><p><b><?php echo number_format($tot_pay, 2); ?></b></p></td>
		  </tr>
		</table>
		
		<table border="0">
		  <tr>
			<td colspan="2"><p align="justify" style="margin:10px 0">I certify from personal knowledge* /from the certificates in the relevant files* /that the above supplies* /services* /works* were duly authorized and performed and that the payment of Rupees <u><b><?php echo number_format($tot_pay, 2); ?></b></u> is in accordance with regulations*/ contract*/ fair and reasonable.</p></td>
		  </tr>
		  <tr>
			<td width="60%">Date: <?php echo $date_today; ?></td>
			<td><br><p align="center">................................................................</p><p align="center" style="margin-top:0">Signature and Title of Officer Certifying Expenditure.</p></td>
		  </tr>
		  <tr>
			<td colspan="2">Before certifying/paying, draw attention to F.RR. 135-140.<br><small>Note: *Strike out words inapplicable</small></td>
		  </tr>
		  <tr>
			<td colspan="2"><br>RECEIVED this .................................................... day of ................. 20....... in payment of the Account, overleaf the sum of Rupees ..................................................................... .................................................</td>
		  </tr>
		  <tr>
			<td width="60%">Witnesses: </td>
			<td><p align="center">................................................................</p><p align="center" style="margin-top:0">Signature of Receiver</p></td>
		  </tr>
		</table>
		<br><hr>
		
		<table>
		<tr><td><br>Signature of Paying Officer and Date</td>
		<td><br> &nbsp;&nbsp;&nbsp;&nbsp;......................................................................................................................</td></tr>
		</table>
		<br>
		<div style="border-bottom: 4px double #333;"></div>
		
		<table>
		<tr><td><br>General/Special Warrant No. &nbsp;&nbsp;&nbsp;&nbsp;...........................................................................of 20............</td></tr>
		
		<tr><td>Advance/Imprest Warrant No. &nbsp;&nbsp;&nbsp;&nbsp;..................................................................</td></tr>
		
		<tr><td>Authority No. &nbsp;&nbsp;&nbsp;&nbsp;...........................................................................of 20............</td></tr>
		</table>
		
      </div>
      <!-- /.box-body -->
    </div>
    
  </section>
   
      </div>
	      <!-- /.End table -->
<!-- ************************************************* -->
      
           <!-- /.col -->
              </div><!-- /.row -->
            </div><!-- /.box-body -->
            
          

          <div class="row">
            
    
    
      </div>
      <!-- /.col (right) -->
         

      </div>

      <!-- Control Sidebar -->
      <aside class="control-sidebar control-sidebar-dark">
        <!-- Create the tabs -->
        <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
          <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
          <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
        </ul>
        <!-- Tab panes -->
        <div class="tab-content">
          <!-- Home tab content -->
          <div class="tab-pane" id="control-sidebar-home-tab">
          </div><!-- /.tab-pane -->

          </div><!-- /.tab-pane -->
        </div>
      </aside><!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->

    <!-- jQuery 2.1.4 -->
    <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <!-- Select2 -->
    <script src="plugins/select2/select2.full.min.js"></script>
	<!-- DataTables -->
    <script src="plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- InputMask -->
    <script src="plugins/input-mask/jquery.inputmask.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
    <!-- date-range-picker -->
    <script src="plugins/daterangepicker_n/moment.min.js"></script>
    <script src="plugins/daterangepicker_n/daterangepicker.js"></script>
    <!-- bootstrap color picker -->
    <script src="plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <!-- bootstrap time picker -->
    <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <!-- SlimScroll 1.3.0 -->
    <script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- iCheck 1.0.1 -->
    <script src="plugins/iCheck/icheck.min.js"></script>
    <!-- FastClick -->
    <script src="plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>
    <script src="bootstrap-sweetalert/lib/sweet-alert.min.js"></script>
	
    <!-- Page script -->
    <script>
      $(function () {
        //Initialize Select2 Elements
        $(".select2").select2();

        //Datemask dd/mm/yyyy
        $("#datemask").inputmask("dd/mm/yyyy", {"placeholder": "yyyy-mm-dd"});
        //Datemask2 mm/dd/yyyy
        $("#datemask2").inputmask("mm/dd/yyyy", {"placeholder": "yyyy-mm-dd"});
        //Money Euro
        $("[data-mask]").inputmask();

        //Date range picker
        $('#reservation').daterangepicker();
        //Date range picker with time picker
       $('#date_start').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
       $('#date_comp').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
       $('#date_award').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});


       $('#date_start_up').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
       $('#date_comp_up').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
		   $('#date_award_up').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});


		   $('#exp_date_up').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
        //Date range as a button
        $('#daterange-btn').daterangepicker(
            {
              ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month')]
              },
              startDate: moment().subtract(29, 'days'),
           
            },
        function (start) {
          $('#reportrange span').html(start.format('MMMM D, YYYY'));
        }
        );

        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass: 'iradio_minimal-blue'
        });
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
          checkboxClass: 'icheckbox_minimal-red',
          radioClass: 'iradio_minimal-red'
        });
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
          checkboxClass: 'icheckbox_flat-green',
          radioClass: 'iradio_flat-green'
        });

        
      });
	  
      $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });
	</script>
		
</body>
</html>
