<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/cartfunctions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
    get_pagesecurity('54','creates','P');
	$_SESSION['cuPages']='prr_qccheckcre.php';   
	$cuPage='prr_qccheckcre.php';    
	$aid=$_SESSION['uid'];
	$brid=$_SESSION['abrid'];    
}else{
	header('Location:../index.php');
	exit;    
}
$mhead='repair';
$menuh='Product Check';
$phead='engcheck';
$page='Engineer Product Check';
$dtnow = date("Y-m-d h:i:s", time());
?>

<?php 
if(isset($_POST['save_eng'])){
      
    $qc_note = remove_junk(escape($_POST['eng_note']));

    $proid = remove_junk(escape($_POST['proid']));
    $invno = remove_junk(escape($_POST['invno']));

    $cost=total_qcvalue();
          
    $sql="UPDATE tbl_proreceive SET eng_note='$qc_note',status='2' WHERE id=$proid";
    $result = mysqli_query($con,$sql) or die(mysqli_error($con));

       
    $efid=mysqli_affected_rows($con);    
    if($efid>0){

    $act =remove_junk(escape('Product Receive: '.$invno));    
    write_activity($aid,'PRR','Engineer Check',$act);   
    save_msg('s','Data Successfully Saved!');
    }else{
    save_msg('w','Data Fail to Saved!');   
    }
    echo "<script>window.location='prr_engchecklist.php'</script>";     
	
}
?>
<?php

include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>


<div class="content-wrapper">
	<?php include('../layout/page_head.php'); ?>
	<!-- Main content -->
	<section class="content">
		<div class="row">
            <div class="col-md-12">
                <div class="box box-solid">
                        <div class="box-header with-border">
                            <h3 class="box-title">Product Check & Problem Finding</h3>
                        </div>
                        <div class="box-body">
                             <?php echo display_msg();?>  
                                   <?php if(isset($_POST['id'])){
                                    $id=$_POST['id'];
                                    $sql21="SELECT * FROM tbl_proreceive WHERE id='$id'";
                                    $query21=mysqli_query($con,$sql21)or die(mysqli_error($con));
                                    $row=mysqli_fetch_array($query21);
                                    ?>  
                                    
                                    <form  action="prr_engcheckcre.php"  enctype="multipart/form-data" method="post" accept-charset="utf-8">
                                        <div class="col-md-12 popup_details_div">
                                            <div class="col-md-1"></div>
                                            <div class="col-md-10">
                                                <div class="col-md-12">
                                                    

                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <div class="form-group">
                                                                <label>Invoice</label>    
                                                                <input type="text" name="cusid" maxlength="45"  id="cusid" value='<?php echo $row['invno']; ?>' class="form-control" readonly/>
                                                                <input type="hidden" name="proid" maxlength="45"  id="proid" value='<?php echo $row['id']; ?>' class="form-control" readonly/>
                                                            </div>    
                                                        </div>
                                                        <div class="col-md-4">
                                                            <div class="form-group">
                                                                <label>Receive Date</label>    
                                                                <input type="text" name="rdate" maxlength="18" value='<?php echo date("d M Y", strtotime($row['rdate']));; ?>' id="rdate" class="form-control"  readonly/>
                                                            </div>    
                                                        </div>  
                                                        <div class="col-md-4">
                                                            <div class="form-group">
                                                                <label>Delivery Date</label>    
                                                                <input type="text" name="ddate" maxlength="18" value='<?php echo date("d M Y", strtotime($row['rdate']));; ?>' id="ddate" class="form-control"  readonly/>
                                                            </div>    
                                                        </div>      
                                                    </div>

                                                    <div class="row">
                                                        <div class="col-md-6">
                                                            <div class="form-group">
                                                                <label>Customer Name</label>    
                                                                <input type="text" name="cusid" maxlength="45"  id="cusid" value='<?php echo get_fild_data('tbl_customer',$row['cusid'],'name'); ?>' class="form-control" readonly/>
                                                            </div>    
                                                        </div>
                                                        <div class="col-md-6">
                                                            <div class="form-group">
                                                                <label>Customer Number</label>    
                                                                <input type="text" name="invno" maxlength="18" value='<?php echo get_fild_data('tbl_customer',$row['cusid'],'cnumber'); ?>' id="number" class="form-control"  readonly/>
                                                            </div>    
                                                        </div>      
                                                    </div>
                                                    <div class="row">
                                                        <h4>Customer Product</h4>
                                                    </div> 

                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <table class="table table-bordered table-striped">
                                                                <thead>    
                                                                    <th style="width:40px; text-align:center">SN</th>
                                                                    <th>Product</th>
                                                                    <th>Serial</th>
                                                                    <th>Qty</th>   
                                                                </thead>
                                                                <tbody>
                                                                    <?php
                                                                        $sqls="SELECT * FROM tbl_proreceivedetails WHERE proid='$id'";
                                                                        $querys=mysqli_query($con,$sqls)or die(mysqli_error($con));
                                                                        while($rows=mysqli_fetch_array($querys)){
                                                                    ?>
                                                                        <tr>
                                                                            <td><?php echo count_id();?></td>
                                                                            <td><?php echo get_fild_data('tbl_item',$rows['pid'],'name'); ?></td>
                                                                            <td><?php echo $rows['serial'];?></td>
                                                                            <td><?php echo $rows['qty'];?></td>

                                                                        </tr>
                                                                    <?php 
                                                                        }
                                                                    ?>
                                                                </tbody>
                                                                   
                                                            </table> 
                                                        </div>    
                                                    </div>
                                                    
                                                    <div class="row">
                                                        <h4>Requisition Product</h4>
                                                    </div> 
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <table class="table table-bordered table-striped">
                                                                <thead>    
                                                                    <th style="width:40px; text-align:center">SN</th>
                                                                    <th>Product</th>
                                                                    <th>Qty</th>
                                                                    <th>Amount</th>
                                                                    <th style="width:40px; text-align:center"><a class="empty" style="cursor: pointer;"><i class="fa fa-trash"></i></a></th>    
                                                                </thead>
                                                                <tbody >
                                                                <?php
                                                                        $sqlsd="SELECT * FROM tbl_prorequisition WHERE proid='$id'";
                                                                        $querysd=mysqli_query($con,$sqls)or die(mysqli_error($con));
                                                                        while($rowsd=mysqli_fetch_array($querysd)){
                                                                    ?>
                                                                        <tr>
                                                                            <td><?php echo count_id();?></td>
                                                                            <td><?php echo get_fild_data('tbl_item',$rowsd['pid'],'name'); ?></td>
                                                                            <td><?php echo $rowsd['qty'];?></td>
                                                                            <td><?php echo $rowsd['amount'];?></td>

                                                                        </tr>
                                                                    <?php 
                                                                        }
                                                                    ?>
                                                                </tbody>
                                                               
                                                            </table> 
                                                        </div>    
                                                    </div>

                                                    <div class="row">
                                                        <div class="col-md-6"> 
                                                            <div class="form-group">    
                                                                <label>Problem Note</label>
                                                                <textarea class="form-control" name="qc_note" id="note" maxlength="250" rows="5"><?php echo $row['note']; ?></textarea> 
                                                               
                                                            </div>        
                                                        </div>
                                                        <div class="col-md-6"> 
                                                            <div class="form-group">    
                                                                <label>QC Note</label>
                                                                <textarea class="form-control" name="qc_note" id="qc_note" maxlength="250" rows="5"><?php echo $row['qc_note']; ?></textarea> 
                                                               
                                                            </div>        
                                                        </div>
                                                    </div> 

                                                    <div class="row">
                                                        <div class="col-md-12"> 
                                                            <div class="form-group">    
                                                                <label>Engineer Note</label>
                                                                <textarea class="form-control" name="eng_note" id="eng_note" maxlength="250" rows="5" placeholder="Engineer Note"></textarea> 
                                                                <input type="hidden" maxlength="15" class="form-control" name="rcvsave" value="1" readonly>       
                                                            </div>        
                                                        </div>
                                                    </div> 




                                                </div>


                                            </div>    
                                            <div class="col-md-1"></div>    
                                        </div>
                                        <div class="clearfix" ></div>
                                        <div class="col-md-12 nopadding widgets_area"></div>    
                                        <div class="row"style="margin-top: 15px" >
                                            <div class="col-md-8 "></div>
                                            <div class="col-md-4 text-right" >
                                                <input type="submit" name="save_eng" id="save" class="btn btn-flat bg-purple btn-sm" value="Save"/> <a href="prod_processproductlist.php" class="btn btn-flat bg-gray  ">Close</a>
                                            </div> 
                                        </div>     
                                    </form>  
                                <?php }else{ ?>
                                    <form  action="prr_engcheckcre.php"  enctype="multipart/form-data" method="post" accept-charset="utf-8">
                                        <div class="col-md-12 popup_details_div">
                                            <div class="col-md-1"></div>
                                            <div class="col-md-10">
                                                <div class="col-md-12">    
                                                    <div class="row">  
                                                        <div class="col-md-6">
                                                            <div class="form-group">
                                                                <label>Product Receive Invoice</label>   
                                                                    <select class="form-control select2" name="id" id="id">
                                                                        <option value="">-Select-</option>
                                                                        <?php									
                                                                        $querys=mysqli_query($con,"SELECT * FROM tbl_proreceive WHERE status=1 ORDER BY id DESC")or die(mysqli_error($con));
                                                                        while ($rows=mysqli_fetch_array($querys)){
                                                                        ?>
                                                                            <option value="<?php echo $rows['id'];?>"><?php echo $rows['invno'];?>-<?php echo get_fild_data('tbl_customer',$rows['cusid'],'name');?></option>
                                                                        <?php } ?>    
                                                                    </select>    
                                                                </div>    
                                                            </div>   
                                                        </div>
                                                    </div>
                                                </div>   
                                            </div>    
                                            <div class="col-md-1"></div>    
                                        </div>
                                        <div class="clearfix" ></div>
                                        <div class="col-md-11 nopadding widgets_area"></div>    
                                        <div class="row"style="margin-top: 15px" >
                                            <div class="col-md-6 "></div>
                                            <div class="col-md-4 text-right" >
                                                <input type="submit" name="save_deli" id="save" class="btn btn-flat bg-purple btn-sm" value="Save"/> <a href="prod_processproductlist.php" class="btn btn-flat bg-gray">Close</a>
                                            </div> 
                                        </div>  
                                        <hr>   
                                    </form> 
                               <?php } ?> 
                
                          
                        </div>
                </div>
            </div>
		</div>
		
		<?php include('../layout/quick.php');?>    
	</section>
	<!-- /.main content -->    
</div>


<?php 
include('../layout/footer.php');
?>
<!-- page script --> 

<script>

$(document).ready(function (){ 
var rdate = new LiveValidation('rdate');
rdate.add(Validate.Presence);
});
    

    
ReadData();
function ReadData(){
$.ajax({
url: "prr_qccheckview.php",
method: "POST",
data:{ 
body:1
},
success: function(data){
$('#itemdata').html(data);
}
})

$.ajax({
url: "prr_qccheckview.php",
method: "POST",
data:{ 
foot:1
},
success: function(data){
$('#itemfoot').html(data);
}
})    
};    

function ReadFoot(){
$.ajax({
url: "prr_qccheckview.php",
method: "POST",
data:{ 
foot:1
},
success: function(data){
$('#itemfoot').html(data);
}
})	
}
    
$(document).on('click', '#addpro', function(e) {
pid = $('#pid').val();
amo = $('#amo').val();
qty = $('#qty').val();
toastr.options = {'positionClass': 'toast-top-center'};

if(pid == '-Select-' || pid == ''){
toastr.info('Please Select Product!');
return;
};    
     

$.ajax({
url: 'axe_cart.php',
type: 'post',
data: {getqccheck:1,pid:pid,amo:amo,qty:qty},
success:function(data) {
$("#pid").val("").trigger("change");    
$('#amo').val("");
$('#qty').val("");
ReadData();
}
});    
    
e.preventDefault();     
});
    
   
  

$(document).on('click','.empty',function() {
$.ajax({
url: 'axe_cart.php',
method: "POST",
data:{ 
qcdata: 1
},
success: function(data){
ReadData();    
}
});    
});    

$(document).on('click', '.remove', function () {
var id = $(this).attr('id');
$.ajax({
url: 'axe_cart.php',
method: "POST",
data:{ 
qcremove: id
},
success: function(data){
ReadData();
}
});    
});    

</script>


</html>    