ok

Mini Shell

Direktori : /home2/selectio/www/lilyexpresslive/software/admin/
Upload File :
Current File : /home2/selectio/www/lilyexpresslive/software/admin/pickup-entry-bulk-upload-status-1.php

<?php require_once ('header.php');
$client_id = $_POST['client_id'];

/*Pickup Entry Initially Array Variable Start*/
date_default_timezone_set('Asia/Kolkata');
$date = date('Y/m/d h:i:s a', time());
$error_msg="";
/*Pickup Entry Initially Array Variable Start*/

if (isset($_POST["Import"]))
{
    try
    {
        $ri = 0;
        $filename = $_FILES["file"]["tmp_name"];
        if ($_FILES["file"]["size"] > 0)
        {
            $file = fopen($filename, "r");
            $ri = 0;
            $clientLocation = '';

            if ($client_id != '')
            {
                $table_header=1;//1-show,0-hide
                $statement = $pdo->prepare("SELECT * FROM tbl_user where id='$client_id'");
                $statement->execute();
                $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                $client_count = $statement->rowCount();
                if($client_count>0){
                    $gst_no = $result[0]['gst_no'];
                    $clientLocation = $result[0]['location'];
                    /*Data Processing Start*/
                         while (($emapData = fgetcsv($file, 10000, ",")) !== false)
                        {
                            /*common variable declaration start*/
                                $data_insert_status=1;
                                $is_one_time_customer=0;//0-no ,1-yes
                                $error_msg="";
                                $address = "";
                                $customer_id = "";
                                $cust_name = "";
                                $cust_phone = "";
                                $city = "";
                                $state = "";
                                $pincode = "";
                                $destination = "";
                                $pick_entry_date="";
                             /*common variable declaration End*/
                            if ($emapData == '')
                            {
                                break;
                            }
                            if ($ri > 0 && $emapData != '')
                            {
                                /*Coulumn-1+++++++Customer Type Check Start*/
                                    if ($emapData[0] == '' || empty($emapData[0]))
                                    {
                                        $error_msg .= "Row Number " . $ri . " Customer type Can't be empty...";
                                        $data_insert_status=0;
                                    }else
                                    {
                                        if($emapData[0]==2)
                                        {
                                        $cust_code1 = $emapData[1];
                                        $statement = $pdo->prepare("SELECT * FROM tbl_customer where cust_code='$cust_code1'");
                                        $statement->execute();
                                        $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                                        $count = $statement->rowCount();
                                        if($count>0)
                                        {
                                            $error_msg .= "<br>Row Number " . $ri . " DB Code Already Exists...";
                                            $data_insert_status=0;
                                        }
                                        }
                                    }
                                /*Customer Type Check End*/
                                
                                /*Column-2 Customer DB Code*/
                                   if ($emapData[1] == '' || empty($emapData[1]))
                                    {
                                        $error_msg .= "<br>Row Number " . $ri . " DB Code Can't be empty...";
                                        $data_insert_status=0;
                                    }
                                    elseif ($emapData[0] == 1) //1-regular customer,2-onetime customer
                                    {
                                        $cust_code = $emapData[1];
                                        $statement = $pdo->prepare("SELECT * FROM tbl_customer where cust_code='$cust_code'");
                                        $statement->execute();
                                        $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                                        $count = $statement->rowCount();
                                        if($count>0){
                                        foreach ($result as $row)
                                        {
                                            $address = $row['cust_address'];
                                            $customer_id = $row['cust_id'];
                                            $cust_name = $row['cust_name'];
                                            $cust_phone = $row['cust_phone'];
                                            $city = $row['cust_city'];
                                            $state = $row['cust_state'];
                                            $pincode = $row['cust_zip'];
                                            $destination = $row['destination_city'];
                                        }
                                    }
                                        else
                                        {
                                            $error_msg .= "Row Number " . $ri . " Invalid DB Code...";
                                            $data_insert_status=0;
                                        }
                                    }//onetime customer
                                    else{
                                        $is_one_time_customer=1;
                                        $cust_code = $emapData[1];
                                        $statement = $pdo->prepare("SELECT * FROM tbl_customer where cust_code='$cust_code'");
                                        $statement->execute();
                                        $count = $statement->rowCount();
                                        if($count>0){
                                            $error_msg .= "Row Number " . $ri . " One time customer Db code already existing...";
                                            $data_insert_status=0;
                                        }else{
                                            $customer_id = "";
                                            $cust_name = $emapData[3];
                                                $temp_addr = $emapData[4];
                                                if(strlen($temp_addr)>110){
                                                    $ad_count=strlen($temp_addr);
                                                    $error_msg .= "Row Number " . $ri . " Address character should less than 110, but it has $ad_count...";
                                                    $data_insert_status=0;
                                                }
                                                else{
                                                    $address[]=$temp_addr;
                                                }
                                            $city = $emapData[5];
                                            $state = $emapData[6];
                                            $destination = $emapData[7];
                                            $pincode = $emapData[8];
                                            $cust_phone = $emapData[9];
                                        }
                                    }
                                /*Column-2 Customer DB Code End*/
                    
                                /*AWB Number Checking Start*/
                                    if ($emapData[2] == '' || empty($emapData[2]))
                                    {
                                        $error_msg .= "Row Number " . $ri . " AWB Number Can't be empty...";
                                        $data_insert_status=0;
                                    }
                                    else
                                    {
                                        $statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE ref_no=?");
                                        $statement->execute(array($emapData[2]));
                                        $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                                        $count = $statement->rowCount();
                                        if ($count > 0)
                                        {
                                            $error_msg.= "Row Number " . $ri . " AWB No Already Exist...";
                                            $data_insert_status=0;
                                        }
                                    }
                                /*AWB Number Checking End*/
                                
                                /*Shipment Date Start*/
                                    if ($emapData[10] == '' || empty($emapData[10]))
                                    {
                                       $pick_entry_date = $date;
                                    }
                                    else
                                    {
                                        $given=$emapData[10];
                                        $len=strlen($given);
                                        if($len==10){
                                            $date=date_create_from_format("d-m-Y",$given);
                                            $created= date_format($date,"Y-m-d");
                                            $pick_entry_date = $created;
                                        }elseif($len==8)
                                        {
                                            $date=date_create_from_format("d-m-y",$given);
                                            $created= date_format($date,"Y-m-d");
                                            $pick_entry_date = $created;
                                        }else
                                        {
                                            $error_msg .= "Row Number " . $ri . " Invalid Date Format (Format should be 23-02-2055 OR 23-02-55)...";
                                            $data_insert_status=0;
                                        }
                                    }
                                /*Shipment Date End*/
                    
/*Sql data insert Process Start */ 
if($data_insert_status==1){
    
}
elseif($table_header==1 && $data_insert_status==0){ $table_header=0; //condition foer showing table header ?>
            <table class="table table-responsive" >
		        <tr class="table-success">
		        <th>S.No</th>
		        <th>Error Details</th>
		        <th>Customer Type</th>
		        <th>DB Code</th>
		        <th>AWB Number</th>
				<th>Customer Name</th>
				<th>Address</th>
				<th>City</th>
				<th>State</th>
				<th>Destination City</th>
				<th>Pincode</th>
				<th>Mobile</th>
				<th>Actual Weight</th>
				<th>Charged Weight</th>
				<th>No.Of Pics</th>
				<th>Pickup Entry Date</th>
		        </tr>
		        <tbody>
<?php }else{ //condition foer showing table data ?>
    <tr class="table-active">
        <td><?php echo $ri ?></td>
        <td><?php echo $error_msg ?></td>
        <td><?php echo $emapData[0] ?></td>
        <td><?php echo $emapData[1] ?></td>
        <td><?php echo $emapData[2] ?></td>
        <td><?php echo $emapData[3] ?></td>
        <td><?php echo $emapData[4] ?></td>
        <td><?php echo $emapData[5] ?></td>
        <td><?php echo $emapData[6] ?></td>
        <td><?php echo $emapData[7] ?></td>
        <td><?php echo $emapData[8] ?></td>
        <td><?php echo $emapData[9] ?></td>
        <td><?php echo $emapData[10] ?></td>
        <td><?php echo $emapData[11] ?></td>
        <td><?php echo $emapData[12] ?></td>
        <td><?php echo $emapData[13] ?></td>
	</tr>	    
<?php }

/*Sql data insert Process end */  
                    
                            }
                            $ri++;
                        }
                        
                    /*Data processing End*/
                }else{
                    $error_msg .= "Selected Client Name Invalid...";
                }
            }else{
                $error_msg .= "Select Client Name...";
            }
            fclose($file);
        }//$_FILES["file"]["size"] > 0 condition
    }//try part close
    catch(Exception $e)
    {
        echo "<center><h3>Back to Pickup Entry Bulk Upload &emsp;&emsp;<a href='pickup-entry-bulk-upload.php' class='btn btn-danger btn-md'>Back</a></h3></center>";
        echo "<div class='alert alert-danger alert-dismissible' style='margin-left: 2%;margin-right: 2%;margin-top: 22%;'>";
        echo '<center>Message: ' . $e->getMessage();
        echo '<br>Error found in uploaded CSV file.Please follow the bulk upload terms and conditions</center>';
        echo '</div>';
    }
}

?>
<?php require_once ('footer.php'); ?>

Zerion Mini Shell 1.0