<?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="#">Inward View</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">
                    <?php
					foreach($prd_req as $pr)
				?>
                  <table class="table table-bordered table-responsive-lg">
                    
						
								<h4 class="heading_a uk-margin-bottom" >Product Inward View</h4>
								<thead>
									<tr>
										<th>REQ No : <?php echo $pr->pr_req_no; ?></th>
										<th>REQ Date : <?php echo $pr->request_date; ?></th>
										<th>INW No : <?php echo $pr->req_rec_no; ?></th>
										<th>INW Date : <?php echo $pr->receipt_date; ?></th>
										<th>Department : <?php echo $pr->dept; ?></th>
										<th>DC No. : <?php echo $pr->dc_no; ?></th>
									</tr>
							</table>
							<table class="table table-bordered table-responsive-lg">
								<thead>
									<tr>
										<th colspan="2"><strong>Product Name</strong></th>
										<th><strong>REQ Qty</strong></th>
										<th><strong>INW Qty</strong></th>
										<th colspan="2"><strong>Remarks</strong></th>													
									</tr>
								</thead>
								<tbody>
									<?php
										$count = 1;
										foreach($prd_req_item as $pritem){
											?>
											
											<tr>
												<td colspan="2"><?php echo $pritem->item_name; ?></td>
												<td><?php echo $pritem->required_qty; ?></td>
												<td><?php echo $pritem->quantity; ?></td>
												<td colspan="2"><?php echo $pritem->rc_remarks; ?></td>												
											</tr>
											
									<?php $count++; } ?>	
									
								</tbody>
							</table>
						
						<br/>
							<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-center">
                                  <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>
                            </div>
						</div>
					</div>
					</br>
					<?php if($pr->bill_upload == ""){ ?>
					<form class="uk-form-stacked" id="upload_form" method="post" action="<?php echo site_url('ProductRequest/dcUpload');?>" enctype="multipart/form-data" autocomplete="off">
					<div class="md-card hidden-print">
						<div class="md-card-content">
						<h4>Invoice Upload</h4>
							<div class="row">
								<div class="col-md-3">
									<div class="form-group">
										<!--<label>INVOICE UPLOAD</label>-->
										<input name="rcp_id" id="rcp_id" type="hidden" class="textbox" value="<?php echo $pr->req_rec_id ?>">
										<input type="file" name="bill_upload" id="bill_upload" class="form-control image_file" />
										<div id="errfn2" ></div>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<input type="submit" name="upload" id="upload"  class="btn btn-primary" value="Upload">
									</div>
								</div>
							</div>
						</div>
					</div>
					</form>	
					</br>
					<?php } ?>
					<div class="row hidden-print">
						<div class="col-md-12">
							<?php if($pr->bill_upload != ""){ ?>
								<!--<span class="click-file" id="click-file" target="1"> View File</span>-->
								<a href="#invoice_view" class='btn btn-primary category_list' data-toggle='collapse'>View File</a>
								<!--<div class="show-document" id="div1">-->
								<div id="invoice_view" class='collapse'>
									<img src="<?php echo $pr->bill_upload; ?>" class="img-rounded" alt="DC Invoice">
								</div>
							<?php } ?>
						</div>
					</div>
					<div class="doc_viewer">
						<!--<iframe id="viewer" frameborder="0" scrolling="yes" width="950" height="500"></iframe>-->
						<img id="viewer" />
					</div>
					
					<form class="uk-form-stacked" action="<?php echo site_url('ProductRequest/addinwardComunication');?>" id="upload_form" method="post" autocomplete="off">
						<div class="md-card">
							<div class="md-card-content">
							<h4>Communication Ticket</h4>
							<br/>
								<?php
									$rcp_id = $pr->req_rec_id;
									foreach($prd_req as $pr)
									
								
									$query = $this->db->query("select * from cmn_ticket as A inner join(select ticket_no,max(ticket_id) as maxtid,inw_id from cmn_ticket where inw_id='$rcp_id' group by inw_id) as B on A.inw_id=B.inw_id and A.ticket_id=B.maxtid");
									foreach($query->result_array() as $rm_row) 
								?>
								<div class="row" >
									<div class="col-md-6">
										<div class="form-group">
											<!--<label for="exampleInputEmail1">Remarks</label>-->
										<?php 
										if($query->num_rows() > 0){
										?>
										<input type="text" name="rmk_date" id="rmk_date" class="form-control" value="<?php echo date('Y-m-d'); ?>" readonly />
											<textarea name="remark" id="remark" class="form-control" rows="5" placeholder="Remarks" >Rejection : By <?php echo $rm_row['dept']; ?><?php echo "\n"; ?><?php echo $rm_row['remarks']; ?><?php echo "\n"; ?>Ref : <?php echo $rm_row['inw_no']; ?>, <?php echo date('d-m-Y',strtotime($rm_row['inw_date'])); ?>, DC No : <?php echo $rm_row['dc_no']; ?></textarea>
											<?php } else { ?>
											<textarea name="remark" id="remark" class="form-control" rows="5" placeholder="Remarks" ></textarea>
											<?php } ?>
											<input type="hidden" name="inw_no" id="inw_no" class="form-control" value="<?php echo $pr->req_rec_no; ?>" readonly />
											<input type="hidden" name="inw_date" id="inw_date" class="form-control" value="<?php echo $pr->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 $pr->dc_no; ?>" readonly />
											<input type="hidden" name="inw_id" id="inw_id" class="form-control" value="<?php echo $rcp_id; ?>" readonly />
											<input type="hidden" name="branch" id="branch" class="form-control" value="<?php echo $pr->branchname; ?>" readonly />
											<?php
												$log_id = $_SESSION['user_id'];
												
											$q1 = $this->db->query("select * from user where user_id='1'");	
											foreach($q1->result_array() as $ph_rw) 
											$q2 = $this->db->query("select * from user where user_id='39'");	
											foreach($q2->result_array() as $ph_rw2) 
												$q3 = $this->db->query("select * from user where user_id='$log_id'");	
											foreach($q3->result_array() as $ph_rw3) 
												
												
											$q4 = $this->db->query("select * from user where user_id='37'");	
											foreach($q4->result_array() as $ph_rw4) 	
											?>
											<input type="hidden" name="ph_no" id="ph_no" class="form-control" value="<?php echo $ph_rw['ph_no']; ?>,<?php echo $ph_rw2['ph_no']; ?>,<?php echo $ph_rw3['ph_no']; ?>,<?php echo $ph_rw4['ph_no']; ?>" readonly />
										</div>
									</div>
									<div class="col-md-3">
										<div class="form-group">
											<input type="submit" name="tsubmit" id="tsubmit"  class="btn btn-primary" value="Submit" onClick="return in_ticket();" >
										</div>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
		</div>
<?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>
		<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("bill_upload").files[0];
					pdffile_url=URL.createObjectURL(pdffile);
					$('#viewer').attr('src',pdffile_url);
			   // }
				 });
			 });
		</script>
</body>
</html>