<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	$sidenav_file=APPPATH.'views/include/sidenav.php';
	require($sidenav_file);	?>
<!-- BEGIN: Content-->
    <div class="app-content content">
      <div class="content-overlay"></div>
      <div class="content-wrapper">
        <div class="content-header row">
          <div class="content-header-left col-md-6 col-12 mb-2 breadcrumb-new">
            <h3 class="content-header-title mb-0 d-inline-block">GRN Invoice </h3>
            <div class="row breadcrumbs-top d-inline-block">
              <div class="breadcrumb-wrapper col-12">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="#">Home</a>
                  </li>
                  <li class="breadcrumb-item"><a href="#">Purchase Order</a>
                  </li>
                  <li class="breadcrumb-item active">GRN Invoice 
                  </li>
                </ol>
              </div>
            </div>
          </div>
         
        </div>
        <div class="content-body"><section class="card">
  <div id="invoice-template" class="card-body p-4">
       <!-- Invoice Items Details -->
    <div id="invoice-items-details" class="pt-2">
      <div class="row">
        <div class="table-responsive col-12">
        <?php
          foreach($get_ordered_gnr as $grn)
        ?>
       
          <table  id="tableID" border="1" style="border:1px solid!important;" class="table table-bordered zero-configuration">
                    <tr class="main_heading">
                      <th  colspan="17">Goods Received Note (GRN) Invoice View<span class="pull-right"><?php echo $grn->user_name; ?></span></th>
                    </tr>
                    <tr class="data_details">
                      <th colspan="3"><span>PO No : </span><?php echo $grn->purchase_no; ?></th>
                      <th colspan="3"><span>PO Date : </span><?php echo $grn->purchase_date; ?></th>
                      <th colspan="3"><span>GRN No : </span><?php echo $grn->grn_no; ?></th>
                      <th colspan="3"><span>GRN Date : </span><?php echo $grn->grn_date; ?></th>
                      <th colspan="3"><span>Supplier Name : </span><?php echo $grn->venders_name; ?></th>
                      <th colspan="2" >Invoice : <?php echo $grn->invoice_no; ?></th>
                    </tr>
                    <tr class="data_details">
                      <th colspan="8"><span>Purchase Order </th>
                        <th colspan="9"><span>Goods Receive Notes</th>
                        </tr>
                      
                          <tr class="data_heading">
                            <th colspan="3">Product Name</th>
                            <th>UOM</th>
                            <th>Qty</th>
                            <th>Price</th>
                            <th>Qty</th>
                            <th colspan="2">Price</th>
                            <th>Tax(%)</th>
                            <th>Tax Amt</th>
                            <th colspan="3">Total Amount</th>
                            <th colspan="2">Remarks</th>                          
                          </tr>
                       
                          <?php
                           $count = 1;
                            foreach($grn_item as $data){

                              ?>
                              <tr>
                                <td colspan="3"><?php echo $data->item_name; ?></td>
                                <td><?php echo $data->unit_measurement; ?></td>
                                <td><?php echo $data->required_qty; ?></td>
                                <td><?php echo $data->item_price; ?></td>
                                <td><?php echo $data->grn_item_qty; ?></td>
                                <td colspan="2"><?php echo $data->grn_item_price; ?></td>
                                <td><?php echo $data->grn_tax; ?></td>
                                <td><?php echo $data->grn_tax_amount; ?></td>
                                <td colspan="3"><?php echo $data->grn_grand; ?></td>
								<td colspan="2"><?php echo $data->grn_remarks; ?></td>
                              </tr>
                              
                          <?php $count++; } ?>
                          
                          
                          <?php
                            
                              foreach($grn_sumamount as $gsum){  
                            ?>
                            <tr>
                              <th colspan="10" >Total Amount</th>
                              <th ><?php echo $gsum->sum_tax_amount; ?></th>
                              <th colspan="3"><?php echo $gsum->sum_amount; ?></th>
                              <td colspan="2"></td>
                            </tr>
                            <?php if($grn->courier != 0) { ?>
                              <tr>
                                <td colspan="11" >Courier Charge</td>
                                <!--<td colspan="10"></td>
                                <td style="font-weight:bold"><?php //echo $row['courier']; ?></td>-->
                                <td colspan="3"><?php echo $grn->courier; ?></td>
                                <td colspan="2"></td>
                              </tr>
                            <?php } ?>
                            <?php if($grn->transport != 0) { ?>
                              <tr>
                                
                                <td colspan="11" >Transport Charge</td>
                                <!--<td colspan="10"></td>
                                <td style="font-weight:bold"><?php //echo $row1['sum_tax_amount']; ?></td>-->
                                <td colspan="3"><?php echo $grn->transport; ?></td>
                                <td colspan="2"></td>
                              </tr>
                            <?php } ?>
                            <?php if($grn->insurance != 0) { ?>
                              <tr>
                                
                                <td colspan="11" >Insurance Charge</td>
                                <!--
                                <td colspan="10"></td>
                                <td style="font-weight:bold"><?php //echo $row1['sum_tax_amount']; ?></td>-->
                                <td colspan="3"><?php echo $grn->insurance; ?></td>
                                <td colspan="2"></td>
                              </tr>
                            <?php } ?>
                            <tr>
                                <th colspan="10" >Total Charge</th>
                          <td ><?php //echo $row1['sum_tax_amount']; ?></td>
                          <th colspan="3"><strong><?php echo $grn->tot_amt; ?></strong></th>
                          <td colspan="2"></td>
                        </tr>
                        <tr>
                          <td colspan="10" >Round Off</td>
                          <td ><?php //echo $row1['sum_tax_amount']; ?></td>
                          <td colspan="3"><strong><?php echo $grn->round_off; ?></strong></td>
                          <td colspan="2"></td>
                        </tr>
                        <tr>
                          <th colspan="10" >Final Charge</th>
                          <td ><?php //echo $row1['sum_tax_amount']; ?></td>
                          <th colspan="3"><strong><?php echo $grn->total_amount; ?></strong></th>
                          <td colspan="2"></td>
                        </tr>
                            <?php
                            }
                          ?>  
                          
                       
               
                <tr>
                <th colspan="17">Rejected Products</th>
                </tr>
                <tr class="data_heading">
                  <th colspan="3">Product Name</th>
                  <th>UOM</th>
                  <th>PO Qty</th>
                  <th>GRN Qty</th>
                  <th colspan="2">GRN Price</th>
                  <th>RJN Qty</th>
                  <th>Price</th>
                  <th>Tax</th>
                  <th colspan="3">Amount</th>
                  <th colspan="2">Remarks</th>
                </tr>
              
                        <?php
               
         foreach($rejection_view as $rejv){ 
    ?>   
                <?php
                  $rmid = $rejv->rejection_id;
                  $count = 1;
                 
                   $query3 = $this->db->query("SELECT *,ROUND(J.rejection_total_amount,2) as rejection_total_amount FROM purchase_order P inner join purchase_order_item  I on  P.purchase_id=I.purchase_id inner join purchase_order_grn O on I.purchase_order_id=O.purchase_order_id inner join  purchase_order_rejection J on O.purchase_grn_id=J.purchase_grn_id where J.rejection_id='$rmid' and J.rejection_qty !=''");
                      foreach($query3->result_array() as $row6){
                  
                    ?>
                    <tr class="data_list">
                      <td><?php echo $row6['item_name']; ?></td>
                      <td><?php echo $row6['unit_measurement']; ?></td>
                      <td><?php echo $row6['required_qty']; ?></td>
                      <td><?php echo $row6['grn_item_qty']; ?></td>
                      <td><?php echo $row6['grn_item_price']; ?></td>
                      <td><?php echo $row6['rejection_qty']; ?></td>
                      <td><?php echo $row6['rejection_price']; ?></td>
                      <td><?php echo $row6['rejection_tax']; ?></td>                 
                      <td><input type="hidden" class="rej_amt" value="<?php echo $row6['rejection_total_amount']; ?>"><?php echo $row6['rejection_total_amount']; ?></td>
                      <td><?php echo $row6['rejection_remarks']; ?></td>
                    </tr>
                     
                <?php $count++; } ?>
                
                <?php } ?>
                
                  <tr>
                    <th colspan="11" >Total Amount</th>
                    <th colspan="3"><input type="hidden" id="grn_amt" value="<?php echo $grn->total_amount; ?>">
                      <strong><span id="rej_tot"> </span>
                      </strong></th>
                    <td colspan="2"></td>
                  </tr>
                  <tr> 
                  <th colspan="11" >GRN Total After Rejection </th>
                    <th colspan="3"><strong><span id="rej_aftr_tot"> </span></strong></th>
                    <td colspan="2"></td>
                
                    
              </tbody>
            </table>
      
                    </div>
                    </div>
                </div>    
                    <br/>
				<!--	<form class="form" autocomplete="off" action="<?php //echo site_url('Purchase/exportGRN');?>" method="post">
                    <div class="row">
                       <div class="col-md-4">
						<input type="hidden" name="grn_id" id="grn_id" value="<?php //echo $grn->gnr_id ?>" >
                        <button type="submit" class="btn btn-primary" >
							<i class="la la-check-square-o"></i> Export
						</button>
						
                      </div>
                    </div>
					</form>-->
					<button onclick="method(btn)" class="btn btn-info pull-right">Export to Excel</button>
                  </div>
                </div>
                <br/>
                
   
      <div class="row hidden-print">
        <div class="col-md-12">
          <?php if($grn->invoice_upload != ""){
            
          ?>
            <!--<span class="click-file" id="click-file" target="1"> View File</span>-->
            <?php
            
             
              $i = 0;
              foreach($grn_upload as $gupload){
                $imageURL = $gupload->file_name;
            ?>
            <?php if($gupload->gstatus == 'Grn Status'){ ?>
            <a href="#demo1<?php echo $i; ?>" class='btn btn-primary category_list' data-toggle='collapse'>View File</a>
            <!--<div class="show-document" id="div1">-->
            <div id="demo1<?php echo $i; ?>" class='collapse'>
              <img src="<?php echo base_url(); ?><?php echo $imageURL; ?>" class="img-rounded" alt="Grn Document" style="width:90%!important;">
              
            </div>
            <?php } ?>
            <?php 
              $i++;
              } 
            ?>
            <?php } ?>
        </div>
      </div>
      <div id="image_preview"></div>
      <div class="doc_viewer">
        <!--<iframe id="viewer" frameborder="0" scrolling="yes" width="950" height="500"></iframe>-->
        <img id="viewer" />
      </div>
  </div>
</section>
</section>
<!-- // Basic form layout section end -->
        </div>
      </div>
    </div>
    <?php //require('include/theme_customizer.php');?>

   <?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>
  <script>
              jQuery(document).ready(function() {
                /*function close_accordion_section() {
                  jQuery('.uk-accordion .accordion-section-title').removeClass('active');
                  jQuery('.uk-accordion .accordion-section-content').slideUp(300).removeClass('open');
                }*/
                jQuery('.uk-accordion-title').click(function(e) {
                  // Grab current anchor value
                  $('#accordion').css({display:'block'});
                  var currentAttrValue = jQuery(this).attr('href');
                  if(jQuery(e.target).is('.active')) {
                    close_accordion_section();
                    }else {
                    close_accordion_section();
                    // Add active class to section title
                    jQuery(this).addClass('active');
                    // Open up the hidden content panel
                    jQuery('.uk-accordion ' + currentAttrValue).slideDown(300).addClass('open'); 
                  }
                  e.preventDefault();
                });
              });
            </script>  
            <script type='text/javascript'>//<![CDATA[
               $(document).ready(function(){
                $(".tiptext").mouseover(function() {
                  $(this).children(".description").show();
                  }).mouseout(function() {
                  $(this).children(".description").hide();
                });
              });//]]> 
            </script>
                       
            <script>
  $(document).ready(function(){
    var tot = $('#grn_amt').val();
    var sum = 0;
    //alert(tot);
    $('.rej_amt').each(function() {
      sum += Number($(this).val());
    });
    var sum1 = (parseFloat(tot) - parseFloat(sum)).toFixed(2)
    //alert(sum1);
    $('#rej_aftr_tot').html(sum1);
    $('#rej_tot').html(sum);
    
    
    var tot2 = $('#grn_amt1').val();
    var sum2 = 0;
    //alert(tot);
    $('.rej_amt1').each(function() {
      sum2 += Number($(this).val());
    });
    var sum4 = (parseFloat(tot) - parseFloat(sum2)).toFixed(2)
    //alert(sum1);
    $('#rej_aftr_tot1').html(sum4);
    $('#rej_tot1').html(sum2);
  });
</script>
<script type="text/javascript">
      $(document).ready(function () {
        $('.image_file').change(function () {
          var val = $(this).val().toLowerCase();
          var regex = new RegExp("(.*?)\.(jpg|png|jpeg|JPG)$");
          if(!(regex.test(val))) {
            $(this).val('');
            //alert('Please select correct file format');
            document.getElementById('errfn2').innerHTML="Please upload only image file";
          } }); });
    </script> 
    <script type="text/javascript">
       $(document).ready(function () {
         $('.image_file').change(function () {
      // function PreviewImage() {
          pdffile=document.getElementById("grn_in_upload").files[0];
          pdffile_url=URL.createObjectURL(pdffile);
          $('#viewer').attr('src',pdffile_url);
         // }
         });
       });
    </script>
    
    <script>
      function preview_image() 
      {
        var total_file=document.getElementById("grn_in_upload").files.length;
        for(var i=0;i<total_file;i++)
        {
          $('#image_preview').append("<img src='"+URL.createObjectURL(event.target.files[i])+"'><br>");
        }
      }
    </script>
    <script type="text/javascript">
	var btn='NewReport';
	</script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js_pdf/tableToExcel.js"></script>
	<script type="text/javascript">
	function method(s) {
	//alert(s);
	//tableToExcel('table', s);
	tableToExcel('tableID', s);
	}
	</script>