<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
$_SESSION['cuPages']='prr_receivelist.php';   
$cuPage='prr_receivelist.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];     
}else{
header('Location:../index.php');
exit;    
}
$mhead='repair';
$menuh='Product Repair';
$phead='qccheck';
$page='QC Product Check List';
$print='print';
$dtnow = date("Y-m-d h:i:s", time());
$today = strftime("%Y-%m-%d", time());
?>



<?php 
if(isset($_POST['delqccheck'])){
$id=$_POST['delqccheck'];
if(get_fild_data('tbl_proreceive',$id,'status')!=1){
save_msg('w','Qc Check Depend On Other Table!!!');
echo "<script>window.location='prr_qcchecklist.php'</script>";
return;    
}
$name= get_fild_data('tbl_proreceive',$id,'invno');    

$sql="UPDATE tbl_proreceive SET qc_note='',cost='',status='0' WHERE id=$id";
$query=mysqli_query($con,$sql)or die(mysqli_error($con));

$sqls="DELETE FROM tbl_prorequisition WHERE proid='$id'";
$querys=mysqli_query($con,$sqls)or die(mysqli_error($con));

$efid=mysqli_affected_rows($con);     
if($efid>0){
$act =remove_junk(escape('Invoice : '.$name));    
write_activity($aid,'PRR','Qc check has been deleted',$act);      
save_msg('s','Qc check Successfully Deleted!!!');
}else{
save_msg('w','Qc check Fail to Delete!!!');    
}
echo "<script>window.location='prr_qcchecklist.php'</script>";
}
?>

<?php 
if(isset($_POST['tfdate'])){
$fdate=$_POST['tfdate'];	
}else{
$fdate=date('Y-m-d', strtotime('-15 days', time()));	
}
if(isset($_POST['ttdate'])){
$tdate=$_POST['ttdate'];	
}else{
$tdate=$today;	
}
?>
<?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-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">QC Product Check Record</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<div class="col-md-12 table-responsive">
<table class="table table-bordered table-striped" id="datarec">
<thead>
<tr>
<th style="width:40px; text-align:center;">SN</th>   
<th>Date</th>
<th>Repair No</th>
<th>Customer</th>
<th>Delivery Date</th> 
<th>Cost</th>     
<th>Note</th>    
<th style="width:40px; text-align:center;">Action</th>    
</tr>
</thead>    
<tbody>  
<?php 
$sql="SELECT * FROM tbl_proreceive where status=1 ORDER BY id DESC";    
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($row=mysqli_fetch_array($query)){


?>
<tr>
<td class="text-center"><?php echo count_id();?></td>
<td><?php echo date("d M Y", strtotime($row['date']));?></td>
<td>   
<?php
echo show_addres(get_fild_data('tbl_customer',$row['cusid'],'name'),get_fild_data('tbl_customer',$row['cusid'],'cnumber'),get_fild_data('tbl_customer',$row['cusid'],'cemail'),'',get_fild_data('tbl_customer',$row['cusid'],'code'));
?>     
</td>  
<td><?php echo $row['invno'];?></td>
<td><?php echo date("d M Y", strtotime($row['ddate']));?></td>
<td><?php echo $row['cost'];?></td>
<td><?php echo $row['qc_note'];?></td>    
<td nowrap="">
<a class="btn btn-flat bg-purple details-claim" href="#" id="inv_<?php echo $row['id'].'_'.$row['cusid']; ?>"><i class="fa fa-eye cat-child"></i></a> 
  
<!-- <a class="btn btn-flat bg-purple details-invoice" href="#" id="src_<?php echo $row['id']; ?>"><i class="fa fa-edit cat-child"></i></a> -->

<a class="btn btn-flat bg-purple" href="#" onclick="remove_item('DL_<?php echo $row['id'];?>')"><i class="fa fa-trash"></i></a>
<form action="prr_qcchecklist.php" id="DL_<?php echo $row['id'];?>" method="post" >
<input type="hidden" name="delqccheck" value="<?php echo $row['id']; ?>" />
</form> 
</td>    
</tr>    
<?php } ?>

  
</tbody>   
</table>
</div>
<div class="clearfix" ></div>  
<div class="row"style="margin-top: 15px" >
<div class="col-md-12 table-responsive">    
<div class="col-md-8"></div>
<div class="col-md-4 text-right" >
<a href="prr_qccheckcre.php" class="btn btn-flat bg-purple">Add New</a>
</div>
</div>    
</div>    
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" id="hisdata">

</div>
</div>
</div>
</div>
</div>
</div>

<?php include('../layout/quick.php');?>    
</section>
<!-- /.main content -->
<?php include('../layout/rside.php'); ?>
<?php include('../layout/details.php'); ?>    
<?php include('../layout/print.php'); ?>    
</div>
<?php
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
ReadITEM();
function ReadITEM() {

    
$.ajax({
url: "prr_receive_cart.php",
method: "POST",
data:{viewitemhis:1},    
success: function(data) {
$('#hisdata').html(data);     
}
})   
}

$(document).on('click','.details-claim',function(e) {    
id_arr = $(this).attr('id');
id = id_arr.split("_");

$.ajax({
url: 'prr_qccheckviewlist.php',
method: "POST",
data:{ 
invid: id[1]
},
success: function(data){
$('#listitem').html(data);
pagelist();    
}
});    
    
$.ajax({
url: 'prr_qccheckviewinv.php',
method: "POST",
data:{ 
print: id[1]
},
success: function(data){
$('#invhold').html(data);
sethead();    
}
});
    
$('.right-side').toggle('slide', { direction: 'right' }, 300);    

e.preventDefault();
});

    
$('#listitem').on('click','li', function(){
   $(this).addClass('active').siblings().removeClass('active');
});
    
$(document).on('click', '.invpiv', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
$.ajax({
url: 'prr_qccheckviewinv.php',
method: "POST",
data:{ 
print: ids
},
beforeSend: function() {
//$("#invhold").fadeOut('slow');
},    
success: function(data){    
$('#invhold').html(data);
$("#invhold").fadeIn('slow');    
sethead();    
}
});     
});    
    
    
$(document).on('click', '#closepop', function() {
if($('.right-side-add').is(':visible')) {
$('.right-side-add').toggle('slide', { direction: 'right' }, 300); 
$('#addsitem').html('');
}
if($('.right-side').is(':visible')) {
$('.right-side').toggle('slide', { direction: 'right' }, 300); 
}    
});

$(document).on('click', '.details-invoice', function(e) {    
id_arr = $(this).attr('id');
id = id_arr.split("_");
ids=id[1];    
$.ajax({
url: "prr_receive_cart.php",
method: "POST",
data:{addsitem:1,item:ids},
success: function(data){
$('#addsitem').html(data);
$('.right-side-add').toggle('slide', { direction: 'right' }, 300);     
}
})    
e.preventDefault();    
});    
    
$(document).on('click', '#addnew', function(e) {
$.ajax({
url: "prr_receive_cart.php",
method: "POST",
data:{addsitem:1,item:0},
success: function(data){
$('#addsitem').html(data);
$('.right-side-add').toggle('slide', { direction: 'right' }, 300);     
}
})    
e.preventDefault();    
});
    
$(document).on('click', '#additem', function() { 
var cash_data = $('.addservice input, .addservice select, .addservice textarea');
toastr.options = {'positionClass': 'toast-top-center'};    
if(!chek_error()){   
return;   
}
$.ajax({
url: "prr_receive_cart.php",
data: cash_data,
type: 'post',
dataType: 'json',    
beforeSend: function () {
chek_error();    
},    
success: function(data){
if(data.status === "success"){
if($('.right-side-add').is(':visible')) { $('.right-side-add').toggle('slide', { direction: 'right' }, 300); }
$('#addsitem').html('');    
toastr.success(data.message);
ReadITEM();    
}else{
toastr.error(data.message);    
}         
}
})    
});
    
function remove_item(id) {
        bootbox.confirm({
            title: "Confirm",
            message: "Are you sure to delete ?",
            buttons: {
                confirm: {
                    label: 'Yes',
                    className: 'btn-flat bg-purple'
                },
                cancel: {
                    label: 'Cancel',
                    className: 'btn-flat bg-gray'
                }
            },
            callback: function (result) {
                if (result == true) {
                    document.getElementById(id).submit();
                }
            }
        });

    } 
    
$(document).on('click', '#closedet', function() {
$('#profile').html('');
$('#details').html('');    
if($('.right-side-details').is(':visible')) {
$('.right-side-details').toggle('slide', { direction: 'right' }, 300);
}     
});
    
$(document).on('click', '.detailsrec', function(e) {    
id_arr = $(this).attr('id');
id = id_arr.split("_");
if(id[1]==0)return;
$.ajax({
url: 'axe_details.php',
method: "POST",
data:{ 
cusdet: 1,cusid: id[1],type:id[0]
},
success: function(data){
$('#profile').html(data);    
}
});    
    
$.ajax({
url: 'axe_details.php',
method: "POST",
data:{ 
tradet: 1,cusid: id[1],type:id[0]
},
success: function(data){
$('#details').html(data);   
}
});    
    
$('.right-side-details').toggle('slide', { direction: 'right' }, 300);   
e.preventDefault();    
});    
</script>    
<!-- /page script -->
</html>    