<!DOCTYPE html>
<html lang="en">
<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Chandrani Pearls Gold Billing</title>
  <link rel="icon" type="image/jpg" href="dist/img/favicon.png?v=2">
  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">

    <!-- -=---- searchable dropdown link css ------ -->
  <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
   <!-- -=---- searchable dropdown link css ------ -->
   <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  
  <!-- DataTables -->
  <link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
	<link rel="stylesheet" href="dist/css/custom.css?v=2">
	<style>
	    label {
    display: inline-block;
    margin-bottom: 0rem;
}

.text-primary{
    color:#0a6abb !important;
}

button:focus{

outline: none;

}

	</style>
	
	<style type="text/css">
.table_header{
background-color:#263544;
text-align:center;
color:#FFFFFF;
font-size:13px;
padding:4px 0px;
}
.table_body{
background-color:#e7eef6;
text-align:center;
color:#000000;
font-size:13px;
padding:4px 0px;
}
.total_leftdiv{
float:left;
padding-left:10px;
text-align:left;
font-size:13px;
color:#000000;
padding-bottom:4px;
font-weight:500;
}
.total_rightdiv{
float:right;
padding-left:10px;
text-align:right;
font-size:13px;
color:#000000;
padding-bottom:4px;
font-weight:600;
}
.btn_div{
background-color:#FFFFFF;
border:0px;
text-align:left;
font-weight:600px !important;
outline:0px !important;
cursor:pointer;
}


.footer-copyright-area {

position: fixed;

bottom: 60px;

width: 75%;

background: #d0d0d0;

padding: 10px 0px;

text-align: right;

color:#263544;

font-weight:600;

font-size:14px; 

padding-right:20px;

z-index:500;

border-radius:4px;

}
</style>

<script>
 function handel1(event) {
    if (event.key === "Enter") {
        add_catagory();
        event.preventDefault(); // prevent form submission if inside a form
    }
}
</script>
	
<script>
function get_category()
{
	//var Indent_No=$('#Indent_No').val();
	
	var Order_No='<?php echo $_REQUEST['Order_No'] ?>';
	
	$.ajax({
				url:'ajax_view_scan2_indent.php',
				type:'POST',
				data:'Order_No='+Order_No,
				success:function(f)
				{
					//alert(f);																														
					$('#view_div').html(f);									
					$(".various").fancybox({			
					maxWidth	: 500,			
					maxHeight	: 450,			
					fitToView	: true,				
					width		: '100%',	
					height		: '100%',		
					autoSize	: false,				
					closeClick	: false,				
					openEffect	: 'none',		
					closeEffect	: 'none',		
					});
				}		
			
				})
}
</script>

	

</head>
	


<body class="hold-transition sidebar-mini" onLoad="get_category()">
	
<div class="wrapper">




  <!-- Navbar -->
    <?php include ("topheader.php"); ?>
  <!-- Main Sidebar Container -->
    <?php include ("sidemenu.php"); ?>








  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
 
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h3>Final Scan Product</h3>
                </div>
                <div class="col-sm-6">
                    
                </div>
            </div>
        </div>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            
            <!-- /.card -->
            <div class="card">
            
              
              <!-- /.card-header -->
			  
	
			  
              <div class="card-body">

<?php
$SqCheckIndent="select * from gold_indent_master where Order_No='".$_REQUEST['Order_No']."'";
$RsCheckIndent=mysqli_query($Mainclass->dbh,$SqCheckIndent);
$FchIndent=mysqli_fetch_array($RsCheckIndent);


?>




<div class="row">
    
<div class="col-sm-3" ><div class="form-group row">
<label class="col-sm-12 col-form-label" >Dealer</label>
<div class="col-sm-12">
<select class="form-control" name="dealer" id="dealer" onChange="emptyborders()" onKeyPress="handel(event)" disabled="disabled">

<option value="">Select Dealer</option>
<?php
$dealer_List=$Mainclass->Fetch_multiple_data("dealer_master","Order_Code,Dealer_Name","Dealer_Name!=''");
foreach($dealer_List as $get_dealer)
{
?>
<option value="<?php echo $get_dealer['Order_Code'];?>"<?php if($get_dealer['Order_Code']==$FchIndent['Dealer_Code']){echo "selected";}?>><?php echo $get_dealer['Dealer_Name'];?></option>
<?php
}
?>
</select>
</div>
</div></div>

<div class="col-sm-3" ><div class="form-group row">
<label class="col-sm-12 col-form-label" >Indent No</label>
<div class="col-sm-12">
<input type="text" class="form-control" name="Indent_No" id="Indent_No" placeholder="Indent No" autocomplete="off" value="<?php echo $FchIndent['Indent_No']; ?>"  onKeyDown="emptyborders()" onKeyPress="handel1(event)" disabled="disabled">
</div>
</div></div>
<!--
<div class="col-sm-1" ><div class="form-group row">
<label class="col-sm-12 col-form-label" >Consignment Stn</label>
<div class="col-sm-12">
<input type="checkbox" class="" name="Con_Stn" id="Con_Stn"  autocomplete="off" value="Yes" style="float:left;width:20px;height:20px;" disabled <?php if($FchIndent['Consignment_Stn']==1){echo "checked";}?>>
</div>
</div></div>-->



</div>

<!--<div class="row" style="margin-top:20px;">


</div>-->


<div class="row" style="margin-top:20px;">
<div class="col-sm-3" ><div class="form-group row">
<label class="col-sm-12 col-form-label">Product Code </label>
<div class="col-sm-12">
<input type="text" class="form-control" name="Product_Code" id="Product_Code" placeholder="Product Code" autocomplete="off" value="" style="" onKeyDown="handel1(event);emptyborders()" onKeyPress="">
</div>
</div></div>




<div class="col-sm-2" ><div class="form-group row">
<label class="col-sm-12 col-form-label">&nbsp;</label>
<div class="col-sm-12">
<input name="save_submit" type="button" class="btn btn-primary m-b-0" value="ADD" style="float:left; padding: 3px 14px; font-size:13px;" onClick="add_catagory()">
</div>
</div></div>

</div>




<div class="row" style="margin-top:5px;">
<div class="dt-responsive table-responsive" style="margin-top:20px; margin-left:15px; margin-right:15px;" id="view_div">
</div>
</div>

</div>









</div>











             
	




              <!-- /.card-body -->

            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->


    <?php include ("footer.php"); ?>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->


  </aside>
  <!-- /.control-sidebar -->
</div>




<!-- ./wrapper -->
<!-- jQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="plugins/jszip/jszip.min.js"></script>
<script src="plugins/pdfmake/pdfmake.min.js"></script>
<script src="plugins/pdfmake/vfs_fonts.js"></script>
<script src="plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
     // "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>





<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" ></script>

<script>
function Complete_Indent()
{  
 var Order_No='<?php echo $_REQUEST['Order_No'] ?>';   
 
 var Ref_No='<?php echo $FchIndent['Ref_Order_No'] ?>';
 //alert(Indent_No);  
 $.ajax({		
 url:'aj-complete-scan1.php',	
 type:'POST',	
 data: 'Order_No=' + Order_No,	
 success:function(f)		
 {		
 //alert(f);		
 alert("Temp Stn Successfully Completed");	

	 if(Ref_No=="")
	 {
	      window.location.href='scan_indent.php';	
	 }
     else{
	     window.location.href='pending_indent.php';	
	 }	 
 }
 })
 }
 </script>

<script>
function add_catagory()
{
	var Product_Code=$('#Product_Code').val();
	var Indent_No='<?php echo $FchIndent['Indent_No'] ?>';
	var Order_No='<?php echo $_REQUEST['Order_No'] ?>';
	var dealer='<?php echo $FchIndent['Dealer_Code'] ?>';
	

	
	/*if(dealer=='')
	{
		$('#dealer').css('border-color','#FB0206');
		$('#dealer').focus();
		return false;
	}*/
	
	if(Product_Code=='' || Product_Code.length < 15)
	{
		$('#Product_Code').css('border-color','#FB0206');
		$('#Product_Code').focus();
		return false;
	}
	if(Indent_No=='')
	{
		$('#Indent_No').css('border-color','#FB0206');
		$('#Indent_No').focus();
		return false;
	}
	else
	{
	   	//alert(Product_Code);
	
		$.ajax({
				url:'ajx_scan2_product.php',
				type:'POST',
				data:'Order_No='+Order_No+'&Product_Code='+Product_Code+'&Indent_No='+Indent_No+'&dealer='+dealer,
				success:function(f)
				{
				 // alert(f);
				 
				    if(f=="Not Found")
					{
					   //alert('Product Not Found');
					   
					  
						
						  Swal.fire({
								title: 'Error!',
								text: 'Product Not Found',
								icon: 'error', // This sets the icon to an error symbol
								showConfirmButton:true,
							});
							
					   
					}                    
					else if(f=="Already exist")	
					{					    
					 
						
						 Swal.fire({
								title: 'Error!',
								text: 'Indent Already Completed',
								icon: 'error', // This sets the icon to an error symbol
								showConfirmButton:true,
							});
					  
					}
					else if(f=="Stock Out")
					{
					   
						
						 Swal.fire({
								title: 'Error!',
								text: 'Warehouse Product stock not available',
								icon: 'error', // This sets the icon to an error symbol
								showConfirmButton:true,
							});
					
					}
					else if(f=="Your Credit limit has exceeded")
					{
					  
					   
						
						Swal.fire({
								title: 'Error!',
								text: 'Dealer Credit limit has exceeded',
								icon: 'error', // This sets the icon to an error symbol
								showConfirmButton:true,
							});
					
					}
				    else if(f==0)
					{
					   Swal.fire({
								title: 'Error!',
								text: 'Invalid Scan',
								icon: 'error', // This sets the icon to an error symbol
								showConfirmButton:true,
							});
						
					}
					else
					{
						
					  get_category();
					  $('#Product_Code').val('');
				
					}
				 
				 
				}		
			
				})
	}
}
function emptyborders()
{
	var Category=$('#cat_name').val();
	var Category_Code=$('#cat_code').val();	
	if(Category!='')
	{
		$('#cat_name').css('border-color','');
	}
	
	if(Category_Code!='')
	{
		$('#cat_code').css('border-color','');		
	}
	
}
</script>

 <script>
function Check_Scan2()
{

	 var Order_No='<?php echo $_REQUEST['Order_No'];?>';   

	$.ajax({
		url:'check-scan2.php',
		type:'POST',
		data: 'Order_No=' + Order_No,
		success:function(f)
		{
		
    
		   if(f>'0')
		   {
			   
			    Swal.fire({
                title: 'Are you sure?',
                text: 'No of final scan products is less than first scan products. Are you sure to complete final scan status',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'Yes, continue',
                cancelButtonText: 'No, cancel',
                toast: false, // Toast is not ideal for confirmations
                position: 'center',
				}).then((result) => {
					if (result.isConfirmed) {
						//console.log('User confirmed to continue.');
						// Add your logic for confirmation here
						
						Complete_Scan2();
						
					} else {
						//console.log('User canceled.');
						// Add your logic for cancellation here
						//window.location.href='create-stn.php?Order_No='+f;	
					}
				}); 
			   
			   
			   
			   
			
			}
			else
		   {
		   
		       Complete_Scan2()
		   }
		
			
		}
	  })
}
</script>

<script>
function Complete_Scan2()
{  
  var Order_No='<?php echo $_REQUEST['Order_No'];?>';   
  var Ref_No='<?php echo $FchIndent['Ref_Order_No'] ?>';
  
  
                Swal.fire({
                title: 'Are you sure?',
                text: 'Are you sure you want to complete this final scan STN? Once completed, no further changes can be made.',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'Yes, continue',
                cancelButtonText: 'No, cancel',
                toast: false, // Toast is not ideal for confirmations
                position: 'center',
				}).then((result) => {
					if (result.isConfirmed) {
						
						 $.ajax({		
						 url:'aj-complete-scan2.php',	
						 type:'POST',	
						 data: 'Order_No=' + Order_No,	
						 success:function(f)		
						 {		


									    Swal.fire({
											icon: 'success', // Sets the icon to success
											title: 'Submission Successful!',
											text: 'Final Scan Successfully Completed',
											width: '450px',
											showConfirmButton: true,
											confirmButtonText: 'OK'
										}).then(function() {
										  
											if(Ref_No=="")
											 {
												  window.location.href='pending-stn.php';	
											 }
											 else{
												 window.location.href='pending_indent.php';	
											 }	
										  
										});

							 
						 }
						 })
						
						
						
					} else {
						//console.log('User canceled.');
						// Add your logic for cancellation here
						
					}
				});
			  
  
  
  
  
 
 //alert(Indent_No);  

 }
 </script>

  
<script type="text/javascript">


function form_valid(){


var p_cate = $('#p_cate').val();
var m_type = $('#m_type').val();
var design_id = $('#design_id').val();
var design_qty = $('#design_qty').val();
var vendor_name = $('#vendor_name').val();
var v_designcode = $('#v_designcode').val();


var flag = 0;


if(p_cate==""){

$('#p_cate').next('.select2').find('.select2-selection--single').css('border-color', '#e85c5c');

$('#con-alrt').show();

flag++;

}
else{

$('#p_cate').next('.select2').find('.select2-selection--single').css('border-color', '');
}


if(m_type==""){

$('#m_type').css('border-color', '#e85c5c');

$('#con-alrt').show();

flag++;

}
else{

$('#m_type').css('border-bottom-color', '');
}

if(design_id==""){

$('#design_id').css('border-color', '#e85c5c');

$('#con-alrt').show();

flag++;

}
else{

$('#design_id').css('border-bottom-color', '');
}



if(design_qty==""){

$('#design_qty').css('border-color', '#e85c5c');

$('#con-alrt').show();

flag++;

}
else{

$('#design_qty').css('border-bottom-color', '');
}




if(vendor_name==""){

$('#vendor_name').css('border-color', '#e85c5c');

$('#con-alrt').show();

flag++;

}
else{

$('#vendor_name').css('border-bottom-color', '');

$('#con-alrt').hide();
}


if(v_designcode==""){

$('#v_designcode').css('border-color', '#e85c5c'); 

flag++;

}
else{

$('#v_designcode').css('border-bottom-color', '');

}



if(flag>0){

return false ;

}



else{

var data = {
    p_cate: p_cate,
    design_id: design_id,
    m_type: m_type,
    design_qty: design_qty,
    vendor_name: vendor_name,
    v_designcode: v_designcode,
};

$.ajax({
  url:'ajax-add-temp-pro.php',
  type:'POST',
 data: data,
  success:function(f){

window.location.href="add_product_new.php?i="+btoa(f);

  }

  }); 

}

}

function remove_error(){

$('.err').css('border-color', '');

$('.label.ui.selection.fluid.dropdown.multiple').css('border-bottom-color', '');

$('#p_cate').next('.select2').find('.select2-selection--single').css('border-color', '');


}



</script>



<script type="text/javascript">
  

// $(document).ready(function(){

// $("input").on('input',function(){

// $('.err').css('border-bottom-color', '');

// });

// });


</script>


<!-- -=---- searchable dropdown link script ------ -->

<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" rel="stylesheet" />

<script src="https://code.jquery.com/jquery-3.1.1.min.js"integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
<script>
        $('.ui.dropdown').dropdown();
</script>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>

    <!-- -=---- searchable dropdown link script ------ -->
 
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
  function formatState (state) {
  if (!state.id) {
    return state.text;
  }

  var baseUrl = "/user/pages/images/flags";
  var $state = $(
    '<span><img class="img-flag" /> <span></span></span>'
  );

  // Use .text() instead of HTML string concatenation to avoid script injection issues
  $state.find("span").text(state.text);
  // $state.find("img").attr("src", baseUrl + "/" + state.element.value.toLowerCase() + ".png");

  return $state;
};


$("#p_cate").select2({
  templateSelection: formatState
});

</script>

<script>
  

function get_design_code(){

var p_cate = $('#p_cate').val();
var m_type = $('#m_type').val();



$.ajax({
url:'ajax-get-design-code.php',
type:'POST',
data:{p_cate:p_cate,m_type:m_type},
success:function(f){

$('#design_id').html(f);

}
});


}


function get_data(){

var p_cate = $('#p_cate').val();
var m_type = $('#m_type').val();
var design_id = $('#design_id').val();


if(design_id==""){

$('#design_details_div').html('');

}

if(design_id!=""){

$.ajax({
url:'ajax-get-design-data.php',
type:'POST',
data:{design_id:design_id},
success:function(f){

$('#design_details_div').html(f);

}
});

}

else{

$('#design_details_div').html('');

}

}

function product_form_valid(per) {
    let count = Number(per) - 1;
    let new_id = $('#new_id').val();

    let g_weights = [];
    let d_carats = [];
	let s_carats = [];
    let igi_nos = [];
    let hm_nos = [];

    for (let i = 1; i <= count; i++) {
        let g_weight = $('#g_weight' + i).val();
        let d_carat = $('#d_carat' + i).val();
		let s_carat = $('#s_carat' + i).val();
        let igi_no = $('#igi_no' + i).val();
        let hm_no = $('#hm_no' + i).val();

        if (g_weight) g_weights.push(g_weight);
        if (d_carat) d_carats.push(d_carat);
		if (s_carat) s_carats.push(s_carat);
        if (igi_no) igi_nos.push(igi_no);
        if (hm_no) hm_nos.push(hm_no);
    }

    if (g_weights.length < count || d_carats.length < count || s_carats.length < count) {
        Swal.fire({
            icon: 'warning',
            title: 'Check Again!',
            text: "Please provide information in all the required fields.",
            width: '450px',
            background: '#045b62',
            color: '#fff',
            confirmButtonText: 'Ok',
            confirmButtonColor: "#013033",
            showConfirmButton: true,
        });
        return;
    }

    $.ajax({
        url: 'ajax-final-add-product.php',
        type: 'POST',
        data: {
            g_weights: g_weights,
            d_carats: d_carats,
			s_carats: s_carats,
            igi_nos: igi_nos,
            hm_nos: hm_nos,
            new_id: new_id,
            count: count
        },
        success: function(response) {

            //alert(response);
            
            Swal.fire({
icon: 'success',
title: 'Success',
text: 'Product added successfully',
width: '450px',
showConfirmButton:false,
timer:3000,
}).then(function() {
window.location.href="add_product_new.php";
});
            

        }
    });
}

</script>


</body>
</html>