<!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 ------ -->

  
  <!-- 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>
	
 <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>	
	
<script>

    function handel(e){

        if(e.keyCode === 13){

           //alert(11);

            add_stock();

        }



        return false;

    }

</script>

<script>

function add_stock()

{
	//$('#page_loder').show();
	$('#complete_original').prop('disabled',true);
	var Secret_Code=$('#scan_product').val();
	$('#complete_original').hide();
	//$('#complete_disabled').show();
	if(Secret_Code=='')

	{

		$('#scan_product').css("border-color","#FF0000");

		$('#scan_product').focus();

		return false;

	}

	else

	{
         
		$.ajax({

				url:'ajax_update_stock.php',

				type:'post',

				data:'Secret_Code='+Secret_Code,

				success:function(f)

				{
					//	$('#page_loder').hide();
					//alert(f);
					var arr=f.split("*");
					$Error=arr[0];
					$Challan=arr[1];

					if($Error==0)

					{
					
				//	alert('Success');

					//setTimeout(function(){ window.location.href='my-stock.php'; }, 1500);
					window.location.href='received-result.php?ch='+btoa($Challan);
					
					}

					else if($Error==1)

					{
						//$('#page_loder').hide();
						$('#complete_original').show();
						$('#complete_disabled').hide();
						alert('Wrong Secret Code');
						window.location.href='scan-product.php';
					}
					else if($Error==2)

					{
						//$('#page_loder').hide();
						$('#complete_original').show();
						$('#complete_disabled').hide();
						alert('Already Received');
						window.location.href='scan-product.php';
					}

				}

		

		

		});

	}

}

</script>	

</head>
	


<body class="hold-transition sidebar-mini" onload="get_data()">
	
<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>Receive 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">






<div class="row">
    


<div class="col-sm-12" ><div class="form-group row">
<label class="col-sm-12 col-form-label" >Dealer Code : <?php echo $_COOKIE['O_Code'];?></label>

</div></div>



<div class="col-sm-3" ><div class="form-group row">
<label class="col-sm-12 col-form-label" >Scan the Secret Code </label>
<div class="col-sm-12">
<input type="text" class="form-control" name="scan_product" id="scan_product" placeholder="Secret Code" autocomplete="off" value=""   onKeyPress="handel(event)">
</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" id="complete_original" type="button" class="btn btn-primary m-b-0" value="RECEIVE" style="width:100px;background-color:#0979d8;border: none;" onClick="add_stock()">
<input name="save_submit" id="complete_disabled" type="button" class="btn btn-primary m-b-0" value="RECEIVE" style="width:100px;background-color:#0979d8;border: none;display:none;">
</div>
</div></div>  




</div>

<div class="row">

<div class="col-12">
<div class="form-group d-flex align-items-center justify-content-start" style="gap:30px;">
<div class="" role="alert" id="con-alrt" style="color: #e85c5c;text-align: center;font-size: 15px;display: none;">* Please provide information in all the required fields</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 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>