<?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='qccheck';
$page='QC Product Check';
$dtnow = date("Y-m-d h:i:s", time());
?>

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

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

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

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


        if(isset($_SESSION['axes_qcitem'])){
            if(is_array($_SESSION['axes_qcitem'])){
            $max=count($_SESSION['axes_qcitem']);
            for($i=0;$i<$max;$i++){       
            $pid=$_SESSION['axes_qcitem'][$i]['pid'];
            $amount=$_SESSION['axes_qcitem'][$i]['amo'];
            $qty=$_SESSION['axes_qcitem'][$i]['qty'];     
            $sql="INSERT INTO tbl_prorequisition (proid,pid,qty,amount) VALUES ('$proid','$pid','$qty','$amount')";
            mysqli_query($con,$sql) or die(mysqli_error($con)); 
                
            }}}
            unset($_SESSION['axes_qcitem']);    

    $act =remove_junk(escape('Product Receive: '.$invno));    
    write_activity($aid,'PRR','QC Check And Requisition',$act);   
    save_msg('s','Data Successfully Saved!');
    }else{
    save_msg('w','Data Fail to Saved!');   
    }
    echo "<script>window.location='prr_qcchecklist.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_qccheckcre.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">
                                                        <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">

                                                        <div class="col-md-4">
                                                            <div class="form-group">
                                                                <label>Product</label>
                                                                <select class="form-control select2" name="pid" id="pid">
                                                                <option value="">-Select-</option>
                                                                <?php									
                                                                $queryc=mysqli_query($con,"SELECT * FROM tbl_item WHERE status='1' ORDER BY id ASC")or die(mysqli_error($con));
                                                                while ($row=mysqli_fetch_array($queryc)){
                                                                ?>
                                                                <option value="<?php echo $row['id'];?>"><?php echo $row['code'].' - '.$row['name'];?></option>
                                                                <?php } ?>
                                                                </select>    
                                                            </div>
                                                        </div>

                                                        <div class="col-md-3">
                                                            <div class="form-group">
                                                                <label>Qty</label>
                                                                <input type="text" name="qty" id="qty" maxlength="12" value="" onkeypress="return isNumberKey(event)" class="form-control" placeholder="e.g 2"  />
                                                            </div>    
                                                        </div>

                                                        <div class="col-md-4">
                                                            <div class="form-group">
                                                                <label>Cost</label>
                                                                <input type="text" maxlength="64" class="form-control" name="amo"  id="amo" value="" placeholder="e.g 5000">
                                                            </div>
                                                        </div>
                                                       
                                                        <div class="col-md-1">
                                                            <div class="form-group">
                                                                <label>&nbsp;</label>    
                                                                <input type="button" id="addpro" class="btn btn-flat bg-red" value="Add"/>    
                                                            </div>
                                                        </div> 
                                                    </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 id="itemdata">

                                                                </tbody>
                                                                <tfoot id="itemfoot">

                                                                </tfoot>    
                                                            </table> 
                                                        </div>    
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12"> 
                                                            <div class="form-group">    
                                                                <label>QC Note</label>
                                                                <textarea class="form-control" name="qc_note" id="qc_note" maxlength="250" rows="5" placeholder="Qc 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_qc" 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_qccheckcre.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=0 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>    