<?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">Inward</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="#">Request Pending List</a>
                  </li>
                  <li class="breadcrumb-item active">Inward
                  </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">
          <table class="table table-bordered">
            <thead>
				<?php
					foreach($inward as $inw)
				?>
				<tr class="main_heading">
					<th colspan="6"><?php echo $inw->branchname; ?> - Inward View</span></th>
				</tr>
				 <tr class="data_details">
					<th>REQ No : <?php echo $inw->mat_req_no; ?></th>
					<th>REQ Date : <?php echo $inw->request_date; ?></th>
					<th>RCP No : <?php echo $inw->req_rec_no; ?></th>
					<th>RCP Date : <?php echo $inw->receipt_date; ?></th>
					<th>Store Name : <?php echo $inw->store; ?></th>
					<th>DC No : <?php echo $inw->invoice_no; ?></th>
				</tr>
				<tr class="data_heading">
					<th>Sl.No</th>
					<th colspan="2">Product Name</th>
					<th>REQ Qty</th>
					<th>RCP Qty</th>
					<th>Remarks</th>
				</tr>
            </thead>
            <tbody>
             <?php
			$count=1;
			foreach($inward_item as $initem){
			?>
				<tr class="data_list">
					<td><?php echo $count; ?></td>
					<td colspan="2"><?php echo $initem->it_name; ?></td>
					<td><?php echo $initem->required_qty; ?></td>
					<td><?php echo $initem->quantity; ?></td>
					<td><?php echo $initem->rc_remarks; ?></td>
				</tr>
			<?php 
				$count++; 
				} 
			?>
			</tbody>
          </table>
        </div>
      </div>
  
    </div>

    <!-- Invoice Footer -->
    <div id="invoice-footer">
      <div class="row">
        <div class="col-sm-7 col-12 text-center text-sm-left">
          <!--<h6>Terms & Condition</h6>
          <p>Test pilot isn't always the healthiest business.</p>-->
        </div>
        <div class="col-sm-5 col-12 text-right">
          <button type="button" id="print_receipt" class="btn btn-info print_receipt  btn-sm my-1"><i class="fa ft-printer"></i></button>
        </div>
      </div>
	  
	 
    <?php
    $brname = $_SESSION['branch_name'];
    if($brname!='CW4_CEO' && $brname!='CW5_CEO')
    {
    ?>
     <form class="form" autocomplete="off" action="<?php echo site_url('MaterialRequest/inwardTicket');?>" method="post" enctype="multipart/form-data">
     	<h4 class="print_receipt">Communication Ticket</h4>
		   <div class="row justify-content-md-right print_receipt">
			
			<?php foreach($inward_rmk as $inw_rmk) ?>
			  
				<div class="col-md-6">
				  <div class="form-group">
				  <?php if($inward_rmk) { ?>
					<textarea name="remark" id="remark" class="form-control" rows="5" col="10" placeholder="Remarks" >Rejection : By <?php echo $inw_rmk->dept; ?><?php echo "\n"; ?><?php echo $inw_rmk->remarks; ?><?php echo "\n"; ?>Ref : <?php echo $inw_rmk->inw_no; ?>, <?php echo date('d-m-Y',strtotime($inw_rmk->inw_date)); ?>, DC No : <?php echo $inw_rmk->dc_no; ?></textarea>
					<?php } else { ?>
					<textarea name="remark" id="remark" class="form-control" rows="5" col="10" placeholder="Remarks" ></textarea>
					<?php } ?>
					<input type="hidden" name="rmk_date" id="rmk_date" class="form-control" value="<?php echo date('Y-m-d'); ?>" readonly />
					<input type="hidden" name="inw_no" id="inw_no" class="form-control" value="<?php echo $inw->req_rec_no; ?>" readonly />
					<input type="hidden" name="inw_date" id="inw_date" class="form-control" value="<?php echo $inw->receipt_date; ?>" readonly />
					<input type="hidden" name="dept" id="dept" class="form-control" value="<?php echo $_SESSION['full_name']; ?>" readonly />
					<input type="hidden" name="dc_no" id="dc_no" class="form-control" value="<?php echo $inw->invoice_no; ?>" readonly />
					<input type="hidden" name="inw_id" id="inw_id" class="form-control" value="<?php echo $inw->req_rec_id; ?>" readonly />
					<input type="hidden" name="branch" id="branch" class="form-control" value="<?php echo $inw->branchname; ?>" readonly />
					<input type="hidden" name="br_id" id="br_id" class="form-control" value="<?php echo $inw->branch_id; ?>" readonly />
				  </div>
				</div>
				<div class="col-md-3">
				  <div class="form-group">
				      <?php
					    $user = 'CEO';
						$q1 = $this->db->query("SELECT * FROM user where username='$user'");
						foreach($q1->result_array() as $r1) 
						$phone_no = $r1['ph_no'];
						
						$user2 = 'Chef';
						$q2 = $this->db->query("SELECT * FROM user where username='$user2'");
						foreach($q2->result_array() as $r2) 
						$phone_no2 = $r2['ph_no'];
						
						$user3 = 'Pride Bakers';
						$q3 = $this->db->query("SELECT * FROM user where username='$user3'");
						foreach($q3->result_array() as $r3) 
						$phone_no3 = $r3['ph_no'];
						
						$user4 = $_SESSION['username'];;
						$q4 = $this->db->query("SELECT * FROM user where username='$user4'");
						foreach($q4->result_array() as $r4) 
						$phone_no4 = $r4['ph_no'];
					?>
					<input type="hidden" name="ph_no" id="ph_no" value="<?php echo $phone_no ?>,<?php echo $phone_no2 ?>,<?php echo $phone_no3 ?>,<?php echo $phone_no4 ?>" >
					<input type="submit" name="tsubmit" id="tsubmit" class="btn btn-primary btn-sm" value="Submit" onClick="return in_ticket();" >
				  </div>
				</div>
			   </div>
		</form>
		<?php } ?>
      </br>
     
     
    <?php	  
	 if($brname!='CW4_CEO' && $brname!='CW5_CEO')
    {
    ?>
      <?php if($inw->bill_upload == ""){ ?>
    <form class="form" id="upload_form" action="<?php echo site_url('MaterialRequest/dcUpload');?>"  method="post" enctype="multipart/form-data">
    	<div class="row justify-content-md-right hidden-print print_receipt">
	  <div class="md-card">
		<div class="md-card-content">
		<h4>Invoice Upload</h4>
		  <div class="row">
			<div class="col-md-6">
			  <div class="form-group">
			    <input name="rcp_id" id="rcp_id" type="hidden" class="textbox" value="<?php echo $inw->req_rec_id; ?>">
				<input type="file" name="bill_upload[]" id="bill_upload" class="form-control image_file" accept="image/*" multiple />
				<div id="errfn2" style="color:red;"></div>
			  </div>
			</div>
			<div class="col-md-3">
			  <div class="form-group">
				<input type="submit" name="upload" id="upload"  class="btn btn-primary btn-sm" value="Upload">
			  </div>
			</div>
		  </div>
		</div>
	  </div>
	</div>
	</form>
      </br>
      <?php } } ?>
      
	  
	  <div class="row print_receipt">
        <div class="col-md-12">
          <?php if($inw->bill_upload != ""){
            
          ?>
            <?php
            
             
              $i = 0;
              foreach($dc_up as $dcup){
                $imageURL = $dcup->file_name;
            ?>
            <?php if($dcup->gstatus == 'Pride Grn'){ ?>
            <a href="#demo1<?php echo $i; ?>" class='btn btn-primary category_list' data-toggle='collapse'>View File</a>
            <div id="demo1<?php echo $i; ?>" class='collapse'>
              <img src="<?php echo base_url(); ?><?php echo $imageURL; ?>" class="img-rounded" alt="DC Document" style="width: 90%;">
              
            </div>
            <?php } ?>
            <?php 
              $i++;
              } 
            ?>
            <?php } ?>
        </div>
      </div>
	  <div id="image_preview"></div>
    </div>
	
	
    <!-- Invoice Footer -->

  </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>
	$("#print_receipt").click(function() {
		window.print();
		setTimeout("closePrintView()", 50);
	});
	function closePrintView() {
		window.location = '<?php echo site_url('MaterialRequest/prideReceiptList');?>';
	} 
</script>
<script>
$('.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 proper image format";
            $('#image_preview').empty();
          }
          else
        {
            preview_image();
            document.getElementById('errfn2').innerHTML="";
        }
            
        });
        
  function preview_image() 
  {
	var total_file=document.getElementById("bill_upload").files.length;
	for(var i=0;i<total_file;i++)
	{
	  $('#image_preview').append("<img style='width: 90%!important;' src='"+URL.createObjectURL(event.target.files[i])+"'><br>");
	}
  }
</script>
	