<!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>
	
	.bg-light{
	   background-color:#f2f2f2 !important;
	   padding:10px;
	   margin-bottom:10px;
	}
	
	.bg1{
	    float:left;
	    height:50px;
	    width:100%;
	 background-color:#e6f2ff;
	 padding:5px 10px;
	}
	
	.bg2{
	    float:left;
	    width:100%;
	    height:50px;
	 background-color:#cce6ff; 
	  padding:5px 10px;
	}
	
	
	
	    label {
    display: inline-block;
    margin-bottom: 0rem;
}

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

button:focus{

outline: none;

}

	</style>

</head>
	


<body class="hold-transition sidebar-mini">
	
<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>Import Dealer ROL Limit</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
if ($_REQUEST["import_file"] != "") { 
$row = 0;


$tempFileName = "./rol-import/".time().".csv";
 if ( is_uploaded_file( $_FILES["import"]['tmp_name']) ) {
	$fileCopied = copy( $_FILES["import"]['tmp_name'], $tempFileName);
	
	if($fileCopied)  {
	
		if (($handle = fopen($tempFileName, "r")) !== FALSE) {
		
		
			while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) 
			{
				
				$num = count($data);
				for ($c=0; $c < $num; $c++)
							 {
								 $arr[$row][$c] = $data[$c];
								//echo $data[$c]."<br>";
							}
				$row++;
			}
			
				
			for($i=1; $i<$row; $i++)
			{
				
			    $SqlCheck="SELECT * FROM  gold_dealer_rol_master Where Dealer_Code='".$arr[$i][0]."'";
				$Check=mysqli_query($Mainclass->dbh,$SqlCheck);
				$CountDlRol=mysqli_num_rows($Check);
				if($CountDlRol>0)
				{
			  
			     //$CrLimit=$arr[$i][1]+$arr[$i][2];
				 
			     $sql="update gold_dealer_rol_master set ROL_Limit='".$arr[$i][1]."' where Dealer_Code='".$arr[$i][0]."'";
				 $q=mysqli_query($Mainclass->dbh,$sql);	
				
				
				$rslt=$rslt+$q;
			
				
				$err.="<tr><td style='text-align:left;'>".$i."</td>";
				$err.="<td style='text-align:left;'>".$arr[$i][0]."</td>";
				$err.="<td style='text-align:left;'>Updated Sucessfully</td></tr>";
				}
				else{
					
					
				$sql="INSERT INTO `gold_dealer_rol_master` ( Dealer_Code,`ROL_Limit`,Valid_From, `Valid_To`,Entry_Date) VALUES ( '".trim($arr[$i][0])."','".trim($arr[$i][1])."','".trim($arr[$i][2])."', '".trim($arr[$i][3])."','".date('Y-m-d H:i:s')."')";
				$q=mysqli_query($Mainclass->dbh,$sql);	
				
				$err.="<tr><td style='text-align:left;'>".$i."</td>";
				$err.="<td style='text-align:left;'>".$arr[$i][0]."</td>";
				$err.="<td style='text-align:left;'>New imported Sucessfully</td></tr>";
				
				}
				
			 
			}
			fclose($handle);
			@unlink($tempFileName);
			$echo="File Upload Completed. See The Result.";
		}
		?>
		<script>divHide()</script>
		<?php
		
	}
	?>

	

	<?php
}
} 
//$msg= "Total ".$rslt." Product/Products Imported Sucessfully.";
?>





<div class="row">
    
  <form method="post" action="#" enctype="multipart/form-data">

<div class="col-sm-12">

<div id="infodiv" style="display:block;">
<div class="row" style="margin-top:5px; ">
<div class="col-sm-4" style="margin-bottom:5px;"><div class="form-group row">
<label class="col-sm-12 col-form-label">Import File </label>
<div class="col-sm-12">
<input type="file" class="" name="import" id="import" placeholder="" autocomplete="off" value=""  accept=".csv">
<a href="./rol-import/sample_rol_limit_format.csv" target="_blank" style="color:#0000FF; text-decoration:underline;">View Example File</a><br>
	<!--<span style="color: red;">* Only 500 products can be imported at a time.</span>-->
</div>
</div></div>
<div class="col-sm-2" style="margin-bottom:5px;"><div class="form-group row">
<label class="col-sm-12 col-form-label">&nbsp;</label>
<div class="col-sm-12">
<input name="import_file" type="submit" class="btn btn-primary m-b-0" value="UPLOAD" style="float:left; padding: 2px 14px; font-size:13px; width:100%;" >
</div>
</div></div>
<div class="col-sm-2" style="margin-bottom:5px;"><div class="form-group row">
<label class="col-sm-12 col-form-label">&nbsp;</label>
<!--<div class="col-sm-12">
<input name="result" type="button" class="btn btn-primary m-b-0" value="RESULT" style="float:left; padding: 2px 14px; font-size:13px; width:100%;" onClick="divHide()" >
</div>-->
	
</div></div>
<div class="col-sm-5" style="margin-bottom:5px;"><div class="form-group row"></div></div>
<!--<div id="result_dtl" style="display:block" ></div>-->

<?php
if($fileCopied)  {
?>
<div class="dt-responsive table-responsive" style="margin-top:30px;" id="result_dtl2">
<div class="col-sm-12 col-xs-12" style="margin-top:20px;" ><div class="form-group row" ><label class="col-sm-12 col-form-label" style="text-align:center; background-color:#263544; color:#FFFFFF; font-size:16px;">RESULT : <span style="font-size:15px; color:#f06693; "><?php if($rslt){ echo $msg ;}else{ echo "No Products Imported.";}?></span></label></div></div>
<table class="table table-columned" style="margin-top:20px;">
<thead>
<tr>
<th>SLN</th>
<th>Dealer Code</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php echo $err ?>
</tbody>
</table>
</div>

<?php
}
?>



</div>
</div>
<div class="card-header" style="padding-top:30px; padding-bottom:10px; float:left; width:100%; padding-left:0px; text-align:left;">
<?php 
if($Error!='')
{
	?>
<h5 style="font-size:18px;">Kindly add the following product in the product master before import:
</h5>
<div class="table-responsive" style="margin-top:20px;">
<table class="table table-columned">
<thead>
<tr>
<th>Product Code</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php echo $Error;?>
</tbody>
</table>
<?php
}
?>
</div>
</div>
</div>


</form>  




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





        <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
 <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>




</body>
</html>