<?php
include "../../backend/db/db.php";
session_start();
if(isset($_SESSION['user'])) {
	$log = htmlspecialchars(trim($_SESSION['user']), ENT_QUOTES, 'UTF-8');
}

if(empty($log)) {     
  $redirectUrl = "../../home";
  echo "<script type=\"text/javascript\">";
  echo "window.location.href = '$redirectUrl'";
  echo "</script>";
	 
} else {
  $sqlu = "SELECT name,id FROM contractor_reg WHERE SIDA_no='$log' and del='0'";
  $resultu = mysqli_query($conn, $sqlu);
  $countu = mysqli_num_rows($resultu);
  
  if($countu == 1) {  
	$rowc = mysqli_fetch_assoc($resultu);
	$name =  $rowc['name'];
	$uid = $rowc['id'];
  
  } else {
	$redirectUrl = "../../home";
	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="../../backend/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../../backend/dist/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../../backend/dist/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="../../backend/plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="../../backend/plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="../../backend/plugins/colorpicker/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="../../backend/plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="../../backend/plugins/select2/select2.min.css">
	<!-- DataTables -->
    <link rel="stylesheet" href="../../backend/plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../../backend/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="../../backend/dist/css/skins/_all-skins.min.css">
	<link rel="stylesheet" href="../../backend/bootstrap-sweetalert/lib/sweet-alert.css" />

  </head>
  <body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">

      <header class="main-header">
        <!-- Logo -->
        <a href="index" class="logo">
          <!-- mini logo for sidebar mini 50x50 pixels -->
          <span class="logo-mini"><img src="../../backend/img/logo.png" width="100"></span>
          <!-- logo for regular state and mobile devices -->
          <span class="logo-lg"><b><img src="../../backend/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="../../backend/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="../../backend/dist/img/user2-160x160.png" class="img-circle" alt="User Image">
                    <p>
                   NWP Engineering Department
                      <small></small>
                    </p>
					
                  </li>
                  <!-- Menu Body -->
                 
                  <!-- Menu Footer-->
                  <li class="user-footer">
                    <div class="pull-left">
                      
                    </div>
                    <div class="pull-right">
                      <a href="../log-out" 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 --> 
		  <div class="user-panel">
			<div class="pull-left image"> <img src="../../backend/dist/img/user2-160x160.png" class="img-circle" alt="User Image"> </div>
			<div class="pull-left info">
			  <p><?php echo $name; ?></p>
			  <a href="#"><i class="fa fa-circle text-success"></i> Online</a> </div>
		  </div>
		  <!-- search form --> 
		 
		  <ul class="sidebar-menu">
           <li class="header"><font color="#00CCFF">MAIN NAVIGATION</font></li>
		   <li class="treeview"> <a href="index" target="_parent"> <i class="fa fa-home"></i> <span>Dashboard</span> <i class="fa fa-angle-left pull-right"></i> </a> </li>
		   <li class="treeview"> <a href="project-invoice" target="_parent"> <i class="fa fa-file"></i> <span>Project Invoices</span> <i class="fa fa-angle-left pull-right"></i> </a> </li>
		   <li class="treeview"> <a href="change-password" target="_parent"> <i class="fa fa-lock"></i> <span>Change Password</span> <i class="fa fa-angle-left pull-right"></i> </a> </li>
		  </ul>	   
        
        </section>

        <!-- /.sidebar -->
      </aside>

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Project Invoice
          </h1>
          
    <ol class="breadcrumb">
      <li><a href="index"><i class="fa fa-home"></i> Home</a></li>
    </ol>
        </section>

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

<!-- ************************************************* -->


             

 <div class="box box-info">

 <form id="form_invoice" method="get" action="project-invoice">
            <div class="box-body">

              <div class="form-group"> 
				<label>Select Project:<font color="#FF0000"><strong>*</strong></font></label>
				  <select class="form-control select2" id="project" name="prj" style="width: 100%;" required>
					<option value="">Select Project...</option>
					<?php
					$sql="SELECT
projects_reg.pro_name,
project_invoice.project
FROM
project_invoice
Inner Join projects_reg ON project_invoice.project = projects_reg.id
WHERE
project_invoice.supplier =  '$uid'
GROUP BY
project_invoice.project,
project_invoice.supplier
";
					$result=mysqli_query($conn, $sql);
					while ($row = mysqli_fetch_array($result)){ ?>
					<option value="<?php echo $row['project']; ?>"><?php echo $row['pro_name']; ?></option>
				  <?php } ?>
				  </select>
			  
			  </div>
			  
			<div class="form-group"> 
			  <label>Select Invoice:<font color="#FF0000"><strong>*</strong></font></label>
			  <select class="form-control" id="inv_no" name="inv" style="width: 100%;" required>
				<option value="">Select Invoice...</option>
			  </select>
			</div>			  

            <div class="box-footer">
              <button class="btn btn-primary">SEARCH</button>
            </div>
			
			 </div>
			 
</form>
			
			   </div>
			   
			   
	<?php if(isset($_GET['prj']) && isset($_GET['inv'])) {
		$pid = htmlspecialchars(strip_tags(trim($_GET['prj'])), ENT_QUOTES, 'UTF-8');
		$inv = htmlspecialchars(strip_tags(trim($_GET['inv'])), ENT_QUOTES, 'UTF-8');
		
		$sql_invq = mysqli_query($conn, "SELECT * FROM project_invoice WHERE project='$pid' AND invoice_no='$inv' AND project_invoice.supplier =  '$uid'");
		
		if(mysqli_num_rows($sql_invq) == 0) {
		
		} else {
			$sql_inv = mysqli_fetch_assoc($sql_invq);
			$type = $sql_inv['payment_type'];
			$flag = $sql_inv['flag'];
	?>
			 <div class="panel box box-info" id="pro_det"> 
                <div class="box-header with-border"> 
                  <h4 class="box-title"> <a data-toggle="collapse" data-parent="#accordion" href="#pass"> 
                 Project Invoice Details</a> </h4>
                </div>
                <div id="pass" class="panel-collapse collapse in"> 
                  <div class="box-body">	
				
			<div class="row">
				<div class="col-sm-12"> 
				  <h4><b>Invoice No: </b> <?php echo $inv;?> 
				  </h4>
				</div>
			
				<div class="col-sm-12"> 
				  <p><b>Project Name: </b><?php $sqlp = mysqli_fetch_assoc(mysqli_query($conn, "SELECT pro_name FROM projects_reg WHERE id='$pid'")); echo $sqlp['pro_name']; ?></p>
				</div>
				
				<div class="col-sm-12"> 
				  <p><b>Date: </b> <?php echo $sql_inv['date']; ?> 
				  </p>
				</div>

				<div class="col-sm-12"> 
				  <p><b>Payment Method: </b> <?php echo $type;?> 
				  </p>
				</div>				
				
				<div class="col-sm-12"> 
				  <p><b>Status: </b> <?php if($flag == '2') { echo 'Rejected'; } else if($flag == '1') { echo 'Approved'; } else if($flag == '0') { echo 'Pending Approval'; } ?> 
				  </p>
				</div>
			</div>
			<br>		

					<div class="form-group">
					  <label>Contract Amount</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['con_amount']; ?>" readonly>
					</div>
					
					<div class="form-group">
					  <label>Pr. Sum (Total)</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['pro_sum']; ?>" readonly>
					</div>
					
					<div class="form-group">
					  <label>Project Value</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['pro_val']; ?>" readonly>
					</div>	
					
				<?php if($type == 'Advance Payment') { ?>
				
					<div class="form-group">
					  <label>Advance (%)</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['adv_val']; ?>" readonly>
					</div>
					
					<div class="form-group">
					  <label>Advance Payment</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['advance']; ?>" readonly>
					</div>
				
					<div class="row " style="display:none1">
						<div class="form-group"> 
							<label for="" class="col-sm-2 col-md-1 col-xs-4 control-label" style="padding-top: 7px;">VAT:</label>
							<div class="col-sm-2 col-xs-4 col-md-1"> 
							  <input type="text" class="form-control" value="<?php echo $sql_inv['vat']; ?>" readonly>
							</div>
							<label for="" class="col-sm-1 col-md-1 col-xs-2 control-label" style="padding-top: 7px; padding-left: 0;">% :</label>
							<div class="col-sm-3 col-xs-12"> 
							  <input type="text" class="form-control" value="<?php echo $sql_inv['vat_val']; ?>" readonly>
							</div>
						</div>
					</div><br>
					
					<div class="form-group">
					  <label>Total Payment</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['tot_pay']; ?>" readonly>
					</div>
				
				<?php } else if($type == 'Retention Payment') { ?>
				
					<div class="form-group">
					  <label>Retention (Deposit):</label>
					  <input type="text" class="form-control clr" id="retentiond" name="retentiond" autocomplete="off" readonly value="<?php echo $sql_inv['retention']; ?>">
					</div>
					
					<div class="row vatfinal form-group"><br>
						<div class=""> 
							<label for="" class="col-sm-2 col-md-2 col-xs-4 control-label" style="padding-top: 7px;">VAT for Retention:</label>
							<div class="col-sm-2 col-xs-4 col-md-1"> 
							  <input type="text" class="form-control clr" id="vatfinal" name="vatfinal" autocomplete="off" readonly value="<?php echo $sql_inv['vat']; ?>">
							</div>
							<label for="" class="col-sm-1 col-md-2 col-xs-2 control-label" style="padding-top: 7px; padding-left: 0;">% :</label>
							<div class="col-sm-3 col-xs-12"> 
							  <input type="text" class="form-control clr" id="vat_retenf" name="vat_retenf" autocomplete="off" readonly value="<?php echo $sql_inv['vat_retention']; ?>">
							</div>
						</div><br><br>
					</div>
				
					<div class="form-group">
					  <label>Total Payment:</label>
					  <input type="text" class="form-control clr" id="tot_payf" name="tot_payf" autocomplete="off" readonly value="<?php echo $sql_inv['tot_pay']; ?>">
					</div>
				
				<?php } else { ?>
				
				<div id="part_pay">
					<div class="form-group">
					  <label>Gross Amount</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['gross_amount']; ?>" readonly>
					</div>
					
					<div class="form-group">
					  <label>Previous Gross Amount</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['prv_gross_amount']; ?>" readonly>
					</div>
					
					<div class="form-group">
					  <label>Gross Amount Payable</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['gross_amount_pay']; ?>" readonly>
					</div>
			
					<div class="row">
						<div class="form-group"> 
							<label for="" class="col-sm-12 col-md-2 col-xs-12 control-label" style="padding-top: 7px;">Less - Retention</label>
							<div class="col-sm-2 col-xs-4 col-md-1" style="padding-left: 0px;"> 
							  <input type="text" class="form-control" value="<?php echo $sql_inv['less_reten']; ?>" readonly>
							</div>
							<label for="" class="col-sm-1 col-md-1 col-xs-2 control-label" style="padding-top: 7px; padding-left: 0;">% :</label>
							<div class="col-sm-3 col-xs-12"> 
							  <input type="text" class="form-control" value="<?php echo $sql_inv['less_reten_val']; ?>" readonly>
							</div>
						</div>
					</div><br>
					
					<div class="form-group">
					  <label>Balance</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['balance_1']; ?>" readonly>
					</div>
					
					<div class="form-group">
					  <label>Less - Advance Payment</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['less_adv_pay']; ?>" readonly>
					</div>
					
					<div class="form-group">
					  <label>Balance</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['balance_2']; ?>" readonly>
					</div>
					
					<div class="row">
						<div class="form-group"> 
							<label for="" class="col-sm-12 col-md-2 col-xs-12 control-label" style="padding-top: 7px;">Less - LD</label>
							<div class="col-sm-2 col-xs-4 col-md-2" style="padding-left: 0px;"> 
							  <input type="text" class="form-control" value="<?php echo $sql_inv['less_LD']; ?>" readonly>
							</div>
							
							<div class="col-sm-3 col-xs-12"> 
							  <input type="text" class="form-control" value="<?php echo $sql_inv['less_LD_val']; ?>" readonly>
							</div>
						</div>
					</div><br>					
					
					<div class="form-group">
					  <label>Net Amount Payable</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['net_amount_pay']; ?>" readonly>
					</div>
					
					<div class="row vat">
						<div class="form-group"> 
							<label for="" class="col-sm-2 col-md-1 col-xs-4 control-label" style="padding-top: 7px;">VAT</label>
							<div class="col-sm-3 col-xs-4 col-md-2"> 
							  <input type="text" class="form-control" value="<?php echo $sql_inv['vat']; ?>" readonly>
							</div>
							<label for="" class="col-sm-1 col-md-1 col-xs-2 control-label" style="padding-top: 7px; padding-left: 0;">% :</label>
							<div class="col-sm-3 col-xs-12"> 
							  <input type="text" class="form-control" value="<?php echo $sql_inv['vat_val']; ?>" readonly>
							</div>
						</div>
					</div><br>

					<div class="form-group">
					  <label>Amount to be paid</label>
					  <input type="text" class="form-control" value="<?php echo $sql_inv['paid_amount']; ?>" readonly>
					</div>
				
				</div>
				<?php } ?>
				
			   </div>
			   
                </div>
              </div> 			   
			   
			   
		<?php }} ?>   

</section>

<!-- ************************************************* -->
      
           <!-- /.col -->
              </div><!-- /.row -->
            </div><!-- /.box-body -->
            
          

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

      </div>
<footer class="main-footer"> 
<div class="pull-right hidden-xs">
          
        </div>  <strong>&copy; 2018 NWP Engineering Department.</strong> All Rights Reserved.
      </footer>

      <!-- 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="../../backend/plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../../backend/bootstrap/js/bootstrap.min.js"></script>
    <!-- Select2 -->
    <script src="../../backend/plugins/select2/select2.full.min.js"></script>
	<!-- DataTables -->
    <script src="../../backend/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../../backend/plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- InputMask -->
    <script src="../../backend/plugins/input-mask/jquery.inputmask.js"></script>
    <script src="../../backend/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="../../backend/plugins/input-mask/jquery.inputmask.extensions.js"></script>
    <!-- date-range-picker -->
    <script src="../../backend/plugins/daterangepicker/moment.min.js"></script>
    <script src="../../backend/plugins/daterangepicker/daterangepicker.js"></script>
    <!-- bootstrap color picker -->
    <script src="../../backend/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <!-- bootstrap time picker -->
    <script src="../../backend/plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <!-- SlimScroll 1.3.0 -->
    <script src="../../backend/plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- iCheck 1.0.1 -->
    <script src="../../backend/plugins/iCheck/icheck.min.js"></script>
    <!-- FastClick -->
    <script src="../../backend/plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../../backend/dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../../backend/dist/js/demo.js"></script>
    <script src="../../backend/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
		   $('#reservationtime').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'
        });

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

/*******************************************************************************/
	  
$('#project').change(function () {
  var id = $(this).val();
  load_invoice(id);
  $('#pro_det').hide();
});	

function load_invoice(pid) {
  $.post('connection/contractors_conn.php', {'get_invoice': 'data', pid: pid}, function (data) {
	  $("#inv_no").html(data);
  });
  $('#pro_det').show();
}
  
</script>
	
</body>
</html>
