ok

Mini Shell

Direktori : /home2/selectio/public_html/lilyexpresslive/software/admin/
Upload File :
Current File : /home2/selectio/public_html/lilyexpresslive/software/admin/pickup-entry-bulk-upload-status.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());
$c_type = array();
$ref_no = array();
$reference = array();
$c_pincode = array();
$c_address = array();
$c_city = array();
$c_state = array();
$c_phone = array();
$a_weight = array();
$c_weight = array();
$description = array();
$errData = array();
$nop = array();
$cust_id='';
$error_msg = array();
$error_msg_status = array();
$c_destination = array();
$c_pickup_date = array();
$isErrorSpotted=0;
$errorFound=0;
$installedData=0;
/*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;
            $j = 0;
            $failed_count = 0;
            $clientLocation = '';

            if ($client_id != '')
            {
                $statement = $pdo->prepare("SELECT * FROM tbl_user where id='$client_id'");
                $statement->execute();
                $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                foreach ($result as $row)
                {
                    $gst_no = $row['gst_no'];
                    $clientLocation = $row['location'];
                }
            }
            else
            {
                $error_msg[$ri] = "Pls Select Client Name";
            }

            while (($emapData = fgetcsv($file, 10000, ",")) !== false)
            {
                $error_msg_status[$ri]=0;
                if ($emapData == '')
                {
                    break;
                }
                if ($ri > 0 && $emapData != '')
                {
                    /*Customer Type(0)*/
                        $c_type[]=$emapData[0];
                    if ($emapData[0] == '' || empty($emapData[0]))
                    {
                        $error_msg[$ri] .= "Row Number " . $ri . " Customer type Can't be empty...";
                        $error_msg_status[$ri]=1;
                    }
                    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[$ri] .= "Row Number " . $ri . " DB Code Already Exists...";
                            $error_msg_status[$ri]=1;
                            
                        }
                        }
                    }

                    /*DB Code(1)*/
                    
                    if ($emapData[1] == '' || empty($emapData[1]))
                    {
                        $db_code[] = "";
                        $error_msg[$ri] .= "Row Number " . $ri . " DB Code Can't be empty...";
                    }
                    elseif ($emapData[0] == 1)
                    {
                        $db_code[] = $emapData[1];
                        $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[$ri] .= "Row Number " . $ri . " Invalid DB Code...";
                            $error_msg_status[$ri]=1;
                        }
                    }
                    else
                    {
                        $db_code[] = $emapData[1];
                    }
                        
                    /*AWB No(2)*/
                    $ref_no[] = $emapData[2];
                    
                    if ($emapData[2] == '' || empty($emapData[2]))
                    {
                        $error_msg[$ri] .= "Row Number " . $ri . " AWB Number Can't be empty...";
                        $error_msg_status[$ri]=1;
                    }
                    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[$ri] .= "Row Number " . $ri . " AWB No Already Exist...";
                            $error_msg_status[$ri]=1;
                        }
                        
                    }

                    if (count($ref_no) > 0)
                    {
                        foreach (array_count_values($ref_no) as $num => $value)
                        {
                            if ($value > 1)
                            {
                                $error_msg[$ri] .= $num . " Row Number " . $ri . " AWB Number is having duplicate value of " . $value . " times in our csv file";
                                $error_msg_status[$ri]=1;
                            }
                        }
                    }

                    /*Customer Name(3)*/
                    if (($emapData[3] == '' || empty($emapData[3])) && $emapData[0] == 2)
                    {
                        $c_name[] = '';
                        $error_msg[$ri] .= "Row Number " . $ri . " Customer Name Can't Be Empty...";
                        $error_msg_status[$ri]=1;
                    }
                    elseif (($emapData[3] == '' || empty($emapData[3])) && $emapData[0] == 1)
                    {
                        $c_name[] = $cust_name;
                    }
                    else
                    {
                        $c_name[] = $emapData[3];
                    }

                    /*Address(4)*/
                    if (($emapData[4] == '' || empty($emapData[4])) && $emapData[0] == 2)
                    {
                        $c_address[] = '';
                        $error_msg[$ri] .= "Row Number " . $ri . " Address Can't Be Empty...";
                        $error_msg_status[$ri]=1;
                    }
                    elseif (($emapData[3] == '' || empty($emapData[4])) && $emapData[0] == 1)
                    {
                        $c_address[] = $address;
                    }
                    else
                    {
                        $temp_addr = $emapData[4];
                        
                        if(strlen($temp_addr)>110)
                            {
                                $ad_count=strlen($temp_addr);
                           $error_msg[$ri] .= "Row Number " . $ri . " Address character should less than 110, but it has $ad_count...";
                           $error_msg_status[$ri]=1;
                            }
                            else
                            {
                            $c_address[]=$temp_addr;
                            }
                    }

                    /*City(5)*/
                    if (($emapData[5] == '' || empty($emapData[5])) && $emapData[0] == 2)
                    {
                        $c_city[] = '';
                        $error_msg[$ri] .= "Row Number " . $ri . " City Can't Be Empty...";
                        $error_msg_status[$ri]=1;
                    }
                    elseif (($emapData[5] == '' || empty($emapData[5])) && $emapData[0] == 1)
                    {
                        $c_city[] = $city;
                    }
                    else
                    {
                        $c_city[] = $emapData[5];
                    }

                    /*State(6)*/
                    if (($emapData[6] == '' || empty($emapData[6])) && $emapData[0] == 2)
                    {
                        $c_state[] = '';
                        $error_msg[$ri] .= "Row Number " . $ri . " State Can't Be Empty...";
                        $error_msg_status[$ri]=1;
                    }
                    elseif (($emapData[6] == '' || empty($emapData[6])) && $emapData[0] == 1)
                    {
                        $c_state[] = $state;
                    }
                    else
                    {
                        $c_state[] = $emapData[6];
                    }
                    /*Destination City(7)*/
                    if (($emapData[7] == '' || empty($emapData[7])) && $emapData[0] == 2)
                    {
                        $c_destination[] = '';
                        $error_msg[$ri] .= "Row Number " . $ri . " Destination City Can't Be Empty...";
                        $error_msg_status[$ri]=1;
                    }
                    elseif (($emapData[7] == '' || empty($emapData[7])) && $emapData[0] == 1)
                    {
                        $c_destination[] = $destination;
                    }
                    else
                    {
                        $c_destination[] = $emapData[7];
                    }

                    /*Pincode(8)*/
                    if (($emapData[8] == '' || empty($emapData[8])) && $emapData[0] == 2)
                    {
                        $c_pincode[] = '';
                        $error_msg[$ri] .= "Row Number " . $ri . " Pincode Can't Be Empty...";
                        $error_msg_status[$ri]=1;
                    }
                    elseif (($emapData[8] == '' || empty($emapData[8])) && $emapData[0] == 1)
                    {
                        $c_pincode[] = $pincode;
                    }
                    else
                    {
                        $c_pincode[] = $emapData[8];
                    }
                    /*Phone(9)*/
                    if (($emapData[9] == '' || empty($emapData[9])) && $emapData[0] == 2)
                    {
                        $c_phone[] = '';
                        $error_msg[$ri] .= "Row Number " . $ri . " Phone Can't Be Empty...";
                        $error_msg_status[$ri]=1;
                    }
                    elseif (($emapData[9] == '' || empty($emapData[9])) && $emapData[0] == 1)
                    {
                        $c_phone[] = $cust_phone;
                    }
                    else
                    {
                        $c_phone[] = $emapData[9];
                    }
                    /*Pickup Date(10)*/
                    if ($emapData[10] == '' || empty($emapData[10]))
                    {
                        $c_pickup_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");
                                 $c_pickup_date[] = $created;
                                }elseif($len==8)
                                {
                                $date=date_create_from_format("d-m-y",$given);
                                $created= date_format($date,"Y-m-d");
                                 $c_pickup_date[] = $created;
                                }
                                else
                                {
                                $error_msg[$ri] .= "Row Number " . $ri . " Invalid Date Format (Format should be 23-02-2055 OR 23-02-55)...";
                                $error_msg_status[$ri]=1;
                                }
                        
                    }

                    if ($emapData[11] == '' || empty($emapData[11]))
                    {
                        $a_weight[] = '';
                    }
                    else
                    {
                        $a_weight[] = $emapData[11];
                    }
                    if ($emapData[12] == '' || empty($emapData[12]))
                    {
                        $c_weight[] = '';
                    }
                    else
                    {
                        $c_weight[] = $emapData[12];
                    }
                    if ($emapData[13] == '' || empty($emapData[13]))
                    {
                        $nop[] = '';
                    }
                    else
                    {
                        $nop[] = $emapData[13];
                    }

                    if ($emapData[14] == '' || empty($emapData[14]))
                    {
                        $description[] = '1';
                    }
                    else
                    {
                        $description[] = $emapData[14];
                    }
                    // if (is_numeric($emapData[14]) && $emapData[14]>0){
                    //     $description[] = $emapData[14];
                    // }else{
                    //             /*$error_msg[$ri] .= "Row Number " . $ri . " Invalid Content description Id";
                    //             $error_msg_status[$ri]=1;*/
                    //             $description[] = '1';
                    // }
                        }
                        $ri++;
                        }
                    fclose($file);
                    { ?>
    <center><h3>Back to pickup Entry &emsp;&emsp;<a href="pending-modicare-pickup-entry.php" class="btn btn-success btn-md">Back</a></h3></center>
    <div  style='overflow:scroll;'>
	   <!-- <a href="#" class="close" data-dismiss="alert" onclick='location.reload();' aria-label="close">Close &times;</a>-->
		    <table id="projectSpreadsheet"  style="font-size: 12px;">
		        <tr class="table-success">
		        <th style="width: 3%;text-align: center;">S.No</th>
		        <th style="width: 10%;text-align: center;">Error Details</th>
		        <th style="width: 7%;text-align: center;">Customer Type</th>
		        <th style="width: 7%;text-align: center;">DB Code</th>
		        <th style="width: 7%;text-align: center;">AWB Number</th>
				<th style="width: 10%;text-align: center;">Customer Name</th>
				<th style="width: 20%;text-align: center;">Address</th>
				<th style="width: 7%;text-align: center;">City</th>
				<th style="width: 7%;text-align: center;">State</th>
				<th style="width: 7%;text-align: center;">Destination City</th>
				<th style="width: 7%;text-align: center;">Pincode</th>
				<th style="width: 7%;text-align: center;">Mobile</th>
				
				<th style="width: 7%;text-align: center;">Pickup Entry Date</th>
				<th style="width: 7%;text-align: center;">Actual Weight</th>
				<th style="width: 7%;text-align: center;">Charged Weight</th>
				<th style="width: 7%;text-align: center;">No.Of Pics</th>
				<th style="width: 7%;text-align: center;">Content Description</th>
		        </tr>
		        <tbody id="tbodyid">
		    <?php
		    $iiiiiii=count($ref_no);
		          $k = 0;
                        $kj = 0;
                        for($g=1;$g<$ri;$g++)
                        //foreach ($ref_no as $ref)
                        {
                            $ggggg=$error_msg_status[$g];
                           // echo "<script>alert($ggggg);</script>";
                            $status = '<button class="btn btn-md btn-danger">Failed</button>';
                            if($ggggg==0)
                            {
                            

                            /******************** Check if service is available or not along with its available services ******************/
                            $statement = $pdo->prepare("SHOW TABLE STATUS LIKE 'pickup_entry'");
                            $statement->execute();
                            $result = $statement->fetchAll();
                            foreach ($result as $row)
                            {
                                $ai_id = $row[10];
                            }

                            date_default_timezone_set('Asia/Kolkata');
                            $date = date('Y/m/d h:i:s a', time());

                            // 	**********************************  Generate AWB No Start ********************************************
                            $statement = $pdo->prepare("SELECT MAX(id) as big_id FROM pickup_entry");
                            $statement->execute();
                            $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                            foreach ($result as $row)
                            {
                                $bid = $row['big_id'];
                                if ($bid != '')
                                {
                                    $awb_n = $row['big_id'] + 1;
                                    $awb_no = 1000001 + $awb_n;
                                }
                                else
                                {
                                    $awb_no = 1000001;
                                }

                            }

                            $pic_status = 'pending';
                            $pic_desc='Shipment soft data uploaded successfully';
                            
                            if ($c_type[$k] == 2)
                            {
                                $statement = $pdo->prepare("SHOW TABLE STATUS LIKE 'tbl_customer'");
                                $statement->execute();
                                $result = $statement->fetchAll();
                                foreach ($result as $row)
                                {
                                    $cust_id = $row[10];
                                }
                                $statement = $pdo->prepare("INSERT INTO tbl_customer (client_id,cust_code,cust_type,cust_name,cust_address,cust_zip,cust_phone,cust_city,cust_state,destination_city) VALUES (?,?,?,?,?,?,?,?,?,?)");
                                $statement->execute(array(
                                    $_POST['client_id'],
                                    $db_code[$k],
                                    'one_time',
                                    $c_name[$k],
                                    $c_address[$k],
                                    $c_pincode[$k],
                                    $c_phone[$k],
                                    $c_city[$k],
                                    $c_state[$k],
                                    $c_destination[$k]
                                ));
                                
                                $custs_name=$c_name[$k];
$custs_db_code=$db_code[$k];
                            }
                            else
                            {
                                $statement = $pdo->prepare("SELECT * FROM tbl_customer where cust_code='$db_code[$k]'");
                                $statement->execute();
                                $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                                foreach ($result as $row)
                                {
                                    $cust_id = $row['cust_id'];
                                    $custs_name = $row['cust_name'];
                                    $custs_db_code=$row['cust_code'];
                                }
                            }

                            // 	**********************************  Generate AWB No End ********************************************
                            

                            $statement = $pdo->prepare("INSERT INTO pickup_entry (awb_no,ref_no,client_id,status,pincode,shipping_mode,customer_id,address,city,state,phone,c_weight,a_weight,content_desc,total_charges,other_charges,payment_mode,pics,gst_no,destination,created_at,last_updated_status_date,delivered_date,pickup_customer_name,pickup_customer_dbcode) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
                            $result = $statement->execute(array(
                                $awb_no,
                                $ref_no[$k],
                                $_POST['client_id'],
                                $pic_status,
                                $c_pincode[$k],
                                'Air',
                                $cust_id,
                                $c_address[$k],
                                $c_city[$k],
                                $c_state[$k],
                                $c_phone[$k],
                                $a_weight[$k],
                                $c_weight[$k],
                                $description[$k],
                                0,
                                0,
                                'credit',
                                $nop[$k],
                                $gst_no,
                                $c_destination[$k],
                                $c_pickup_date[$k],
                                $c_pickup_date[$k],
                                $c_pickup_date[$k],
                                $custs_name,
                                $custs_db_code
                            ));

                            if ($result)
                            {
                                $installedData++;
                                $status = '<button class="btn btn-md btn-primary">Success</button>';

                                /*Tracking Module Start*/
                                $statement = $pdo->prepare("INSERT INTO tbl_tracking (pickup_entry_id,user_id,location,status,description,remark,created_at) VALUES (?,?,?,?,?,?,?)");
                                $result1 = $statement->execute(array(
                                    $ai_id,
                                    $client_id,
                                    $clientLocation,
                                    $pic_status,
                                    $pic_desc,
                                    'Material Safe...',
                                    $c_pickup_date[$k]
                                ));
                                $j++;
                            }
?>
		    <?php
		    $k++;
                        
                        
                            }
                            else{
                                $errorFound++;
                            $isErrorSpotted=1;
                    
                            $errData['sno'][]=$k+1;
                            $errData['dbCode'][]=$db_code[$k];
                            $errData['awbno'][]=$ref_no[$k];
                            $errData['cust_name'][]=$c_name[$k];
                            $errData['cust_address'][]=$c_address[$k];
                            $errData['cust_city'][]=$c_city[$k];
                            $errData['cust_state'][]=$c_state[$k];
                            $errData['cust_destination'][]=$c_destination[$k];
                            $errData['cust_pincode'][]=$c_pincode[$k];
                            $errData['cust_phone'][]=$c_phone[$k];
                            $errData['cust_pickupDate'][]=$c_pickup_date[$k];
                            $errData['cust_aWeight'][]=$a_weight[$k];
                            $errData['cust_cWeight'][]=$c_weight[$k];
                            $errData['cust_nop'][]=$nop[$k];
                            $errData['cust_content'][]=$description[$k];
                            $errData['reason'][]=$error_msg[$k+1];
                            $errData['cust_type'][]=$c_type[$k];
                            
                            $kj++;
                            ?>
                            
                                
             <tr class="table-active">
		    <td style="width: 3%;text-align: center;"><?php echo $k + 1 ?></td>
		    <td style="width: 10%;text-align: left;"><?php echo $error_msg[$k+1]; ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $c_type[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $db_code[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $ref_no[$k] ?></td>
		    <td style="width: 10%;text-align: left;"><?php echo $c_name[$k] ?></td>
		    <td style="width: 20%;text-align: left;"><?php echo $c_address[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $c_city[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $c_state[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $c_destination[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $c_pincode[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $c_phone[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $c_pickup_date[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $a_weight[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $c_weight[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $nop[$k] ?></td>
		    <td style="width: 7%;text-align: center;"><?php echo $description[$k] ?></td>
		    
		    </tr>
                              <?php  $k++;
                              
                            }
                        } ?>
                        
		    </tbody>
			</table>
	<?php
	if($isErrorSpotted==1){
	   $errData= http_build_query($errData);
	   ?>
	   <h4>
	       <?=$errorFound?> Errors found in this report. You can download error report 
	       <a href="#" id="xx" class="btn btn-md btn-danger">Download Error Report</a>
	   </h4>
       <?php } ?>
	<?php if($installedData>0){?><br><h4><?=$installedData?> Pickup entries inserted successfully</h4><?php } ?>
	</div>    
		    <?php
                    }
                }
            }
    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>';
    }
}

?>

<script type="text/javascript">

$(document).ready(function () {

	function exportTableToCSV($table, filename) {
    
        var $rows = $table.find('tr:has(td),tr:has(th)'),
    
            // Temporary delimiter characters unlikely to be typed by keyboard
            // This is to avoid accidentally splitting the actual contents
            tmpColDelim = String.fromCharCode(11), // vertical tab character
            tmpRowDelim = String.fromCharCode(0), // null character
    
            // actual delimiter characters for CSV format
            colDelim = '","',
            rowDelim = '"\r\n"',
    
            // Grab text from table into CSV formatted string
            csv = '"' + $rows.map(function (i, row) {
                var $row = $(row), $cols = $row.find('td,th');
    
                return $cols.map(function (j, col) {
                    var $col = $(col), text = $col.text();
    
                    return text.replace(/"/g, '""'); // escape double quotes
    
                }).get().join(tmpColDelim);
    
            }).get().join(tmpRowDelim)
                .split(tmpRowDelim).join(rowDelim)
                .split(tmpColDelim).join(colDelim) + '"',
    
            
    
            // Data URI
            csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
            
            console.log(csv);
            
        	if (window.navigator.msSaveBlob) { // IE 10+
        		//alert('IE' + csv);
        		window.navigator.msSaveOrOpenBlob(new Blob([csv], {type: "text/plain;charset=utf-8;"}), "csvname.csv")
        	} 
        	else {
        		$(this).attr({ 'download': filename, 'href': csvData, 'target': '_blank' }); 
        	}
    }
    
    // This must be a hyperlink
    $("#xx").on('click', function (event) {
    	
        exportTableToCSV.apply(this, [$('#projectSpreadsheet'), 'export.csv']);
        
        // IF CSV, don't do event.preventDefault() or return false
        // We actually need this to be a typical hyperlink
    });

});
	</script>
<?php require_once ('footer.php'); ?>

Zerion Mini Shell 1.0