<?php
if(isset($_POST['upload']))
{
$file = $_FILES['uploadexcel']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
$count = 0;
while(($filesop = fgetcsv($handle, 10000, ",")) !== false)
{
$c++;
if($c>1)
{
$designation = mysqli_real_escape_string($cn,trim($filesop[0]));
$customerName = mysqli_real_escape_string($cn,trim($filesop[1]));
$companyName = mysqli_real_escape_string($cn,trim($filesop[2]));
$mobile = mysqli_real_escape_string($cn,trim($filesop[3]));
$email = mysqli_real_escape_string($cn,trim($filesop[4]));
$state = mysqli_real_escape_string($cn,trim($filesop[5]));
$city = mysqli_real_escape_string($cn,trim($filesop[6]));
$gst = mysqli_real_escape_string($cn,trim($filesop[7]));
$address = mysqli_real_escape_string($cn,trim($filesop[8]));
//Check Designation
$sqlDesignation = mysqli_query($cn, "select * from `tbl_designation` where name='$designation'");
if(mysqli_num_rows($sqlDesignation)>0)
{
$sqlDesignationData = mysqli_fetch_array($sqlDesignation);
$designation_id = $sqlDesignationData['id'];
}
else
{
$designation_id = 'N/A';
}
//Check Employee Already exits
$sqlEmployee = mysqli_query($cn, "select * from `tbl_employee` where `mobile`='$mobile' and `designation_id` IN(2,3,4)");
if(mysqli_num_rows($sqlEmployee)>0)
{
$mobile = "Already Exists";
}
//Check State
$sqlState = mysqli_query($cn, "select * from `tbl_state` where name='$state'");
if(mysqli_num_rows($sqlState)>0)
{
$sqlStateData = mysqli_fetch_array($sqlState);
$state_id = $sqlStateData['id'];
}
else
{
$state_id = 'N/A';
}
//Check City
$sqlCity = mysqli_query($cn, "select * from `tbl_city` where name='$city'");
if(mysqli_num_rows($sqlCity)>0)
{
$sqlCityData = mysqli_fetch_array($sqlCity);
$city_id = $sqlCityData['id'];
}
else
{
$city_id = 'N/A';
}
if(!empty($customerName))
{
mysqli_query($cn,"insert into `tbl_employee_excel` set `name`='$customerName', `company_name`='$companyName', `mobile`='$mobile', `email`='$email', `designation_id`='$designation_id', `state_id`='$state_id', `city_id`='$city_id', `gst`='$gst', `address`='$address', `date`=Now();");
$count++;
}
}
}
$_SESSION['updateCount'] = $count;
}
?>
<div class="col-md-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">Upload Dealer / Distributor / Retailer</h4>
<form class="forms-sample" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="exampleInputCity1">Name</label>
<input type="file" class="form-control" name="uploadexcel" placeholder="Upload Excel" required>
</div>
</div>
</div>
<button type="submit" class="btn btn-success mr-2" name="upload">SUBMIT</button>
<a href="excel/dealer-sample.csv" class="btn mr-2" style="float:right;"><i class="mdi mdi-file-excel"></i> DOWNLOAD SAMPLE</a>
</form>
</div>
</div>
</div>
<br><br>
<form method="post" enctype="multipart/form-data">
<button type="submit" class="btn btn btn-danger mr-2" style="float:right;display:none;"><i class="mdi mdi-trash"></i> Delete</button>
<button type="submit" class="btn btn btn-success mr-2" style="float:right;display:none;"><i class="mdi mdi-trash"></i> Verify</button>
<br><br>
<div class="col-lg-12 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4 class="card-title">Dealer / Distributor / Retailer List</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>
<div class="form-check form-check-flat">
<label class="form-check-label">
<input type="checkbox" class="form-check-input newOrder" name="dealer_id[]" value="<?php echo $sqlEmployeeData['id'];?>"> Select All
</label>
</div>
</th>
<th>customer Type</th>
<th>Name</th>
<th>Company Name</th>
<th>Mobile</th>
<th>Email</th>
<th>GST</th>
<th>State</th>
<th>City</th>
<th>Address</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$sqlEmployee = mysqli_query($cn,"SELECT * FROM `tbl_employee_excel` order by name");
while($sqlEmployeeData = mysqli_fetch_array($sqlEmployee))
{
$status = 0;
if($sqlEmployeeData['designation_id']>0)
{
$sqlDesignation = mysqli_query($cn, "select * from `tbl_designation` where id='".$sqlEmployeeData['designation_id']."'");
$sqlDesignationData = mysqli_fetch_array($sqlDesignation);
$designation_id = $sqlDesignationData['name'];
}
else
{
$designation_id = '<span style="color:red;">'.$sqlEmployeeData['designation_id'].'</span>';
$status = 1;
}
if($sqlEmployeeData['mobile']>0)
{
$mobile = $sqlEmployeeData['mobile'];
}
else
{
$mobile = '<span style="color:red;">'.$sqlEmployeeData['mobile'].'</span>';
$status = 1;
}
if($sqlEmployeeData['state_id']>0)
{
$sqlState = mysqli_query($cn,"select * from `tbl_state` where id='".$sqlEmployeeData['state_id']."'");
$sqlStateData = mysqli_fetch_array($sqlState);
$state_id = $sqlStateData['name'];
}
else
{
$state_id = '<span style="color:red;">'.$sqlEmployeeData['state_id'].'</span>';
$status = 1;
}
if($sqlEmployeeData['city_id']>0)
{
$sqlCity = mysqli_query($cn,"select * from `tbl_city` where id='".$sqlEmployeeData['city_id']."'");
$sqlCityData = mysqli_fetch_array($sqlCity);
$city_id = $sqlCityData['name'];
}
else
{
$city_id = '<span style="color:red;">'.$sqlEmployeeData['city_id'].'</span>';
$status = 1;
}
?>
<tr <?php if($status==1){?>style="background:#f0aeae;color:#FFF;"<?php }?>>
<td>
<div class="form-check form-check-flat">
<label class="form-check-label">
<input type="checkbox" class="form-check-input newOrder" name="dealer_id[]" value="<?php echo $sqlEmployeeData['id'];?>">
</label>
</div>
</td>
<td><?php echo $designation_id;?></td>
<td><?php echo $sqlEmployeeData['name'];?></td>
<td><?php echo $sqlEmployeeData['company_name'];?></td>
<td><?php echo $mobile;?></td>
<td><?php echo $sqlEmployeeData['email'];?></td>
<td><?php echo $sqlEmployeeData['gst'];?></td>
<td><?php echo $state_id;?></td>
<td><?php echo $city_id;?></td>
<td><?php echo $sqlEmployeeData['address'];?></td>
<td>
<a href="home.php?pages=distributorRegistation&delete_id=<?php echo $sqlEmployeeData['id'];?>" class="btn btn-outline-danger btn-sm" onclick="return deleteConfirm();">Delete</a>
</td>
</tr>
<?php }?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</form>
<style>
.nav-tabs .nav-link {
border: 1px solid transparent;
border-top-left-radius: 0.15rem;
border-top-right-radius: 0.15rem;
}
.nav-link {
display: block;
padding: 1rem 0.5rem;
}
.form-check .form-check-label {
font-size: 13px;
line-height: 1.9;
}
.form-check .form-check-label input:checked + .input-helper::after {
width: 18px;
opacity: 1;
line-height: 0px;
filter: alpha(opacity=100);
-webkit-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
transform: scale(1);
}
</style>