<?php require_once('header.php'); 
$client_id=$_POST['client_id'];
if(isset($_POST['courier_id']))
{ $courier_company_id=$_POST['courier_id']; }

/*Pickup Entry Initially Array Variable Start*/
        $gst_t='';
        $gst_amount_cal='';
        $sgst='';
        $cgst='';
        $temp_a_weight='';
        $awb_codes='';
        $error_msg=array();
        $genCscs=array();
        $create_cscs_status=array();
        $pl3_awb_update_number=array();
        $pl3_awb=array();
        $courier_companies=array();
        $cscs_awb=array();
        $ref_no=array();
        $order_type=array();
        $collectable_amount=array();
        $business_mode=array();
        $b2b_b2c=array();
        $f_name=array();
        $addr=array();
        $c_city=array();
        $c_state=array();
        $c_pincode=array();
        $c_phone=array();
        $consignee_name=array();
        $consignee_address=array();
        $consignee_city=array();
        $consignee_state=array();
        $consignee_pincode=array();
        $consignee_phone=array();
        $product_description=array();
        $quantity=array();
        $actual_weight=array();
        $volumetric_weight=array();
        $volumetric_length=array();
        $volumetric_breadth=array();
        $volumetric_height=array();
        $charged_weight=array();
        $taxable_value=array();
        $hsn_code=array();
        $discount=array();
        $grate=array();
        $mrp=array();
        $ewaybill=array();
        $buyer_gst=array();
        $seller_gst=array();
        $rto_name=array();
        $rto_address=array();
        $rto_city=array();
        $rto_state=array();
        $rto_pincode=array();
        $rto_phone=array();
        $boxes=array();
        $invoice_value=array();
        $gst_amount=array();
        $pickup_date=array();
        
        
        $vw_cal='';
/*Pickup Entry Initially Array Variable Start*/

if(isset($_POST["Import"])){
    try{
	    $filename=$_FILES["file"]["tmp_name"];
		 if($_FILES["file"]["size"] > 0)
		 {
		  	$file = fopen($filename, "r");
		  	$ri=0; $j=0; $failed_count=0;$clientLocation='';
	         while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
	         {
	             if($emapData==''){
	                 break;
	             }
	             if($ri>0 && $emapData!='')
	             {
	               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) 
                         {
                                $full_name = $row['full_name'];
                                $address = $row['address'];
                                $city = $row['city'];
                                $state = $row['state'];
                                $phone = $row['phone'];
                                $pincode = $row['pincode'];
                                $clientLocation = $row['location'];
                         } 
	                 }
	                 else{ 
	                     $error_msg[]="Pls Select Client Name";
	                 }
	                if($clientType=="Admin")
	                {  
    	                 if($courier_company_id=='')
    	                 {
    	                     $error_msg[]="Pls Select Courier Company";
    	                 }
	                }
	                 
	                 
	                  /********************* Check Inputs ***************************/
	                 /*CSCS AWB*/   
	                 if($emapData[1]=='' || empty($emapData[1])) 
	                 { 
								$create_cscs_status[]=1;
								$cscs_awb[]='';
	                 } 
	                 else 
	                 {
	                 $create_cscs_status[]=2;
    	                    $cscs_awb_no=$emapData[1]; 
	                        $statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE cscs_awb='$cscs_awb_no'");
							$statement->execute();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							$count = $statement->rowCount();
							if($count>0)
							{
							    $error_msg[]="Row Number ".$ri." CSCS AWB Number Already Exists...";
							}
							else
							{
							    $cscs_awb[]=$emapData[1];
							}
	                 }
	                 
	                    if(count($cscs_awb)>0)
	                 {
	                     foreach(array_count_values($cscs_awb) as $num => $value)
                        {
                            if($value>1 && $num!='' && !empty($num))
                            {
                            	$error_msg[]=$num." CSCS AWB Number is having duplicate value of ".$value." times in our csv file";
                            }
                        }
	                 }
	                 
	                 
	                 /*3PL AWB(2)*/ 
	                 if($clientType=="Admin"){ 
                	                 if($emapData[2]=='' || empty($emapData[2]))
                	                 { 
                                            $pl3_awb[]="";
                                            $courier_companies[]="";
                	                 }
                	                 else 
                	                 { 
                	                        $pl3_awb_no=$emapData[2];
                	                     	$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE 3pl_awb='$pl3_awb_no'");
                							$statement->execute();
                							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
                							$count = $statement->rowCount();
                							if($count>0)
                							{
                							    $error_msg[]="Row Number ".$ri." 3PL AWB Number Already Exist...";
                							}
                							else
                							{
                							   $pl3_awb[]=$emapData[2]; 
                							   $pl3_awb_update_number[]= $emapData[2]; 
                							   $courier_companies[]=$courier_company_id;
                							}
                							
                							$statement = $pdo->prepare("SELECT * FROM `tbl_awb` WHERE status=0 and courier_id=$courier_company_id and awb_code='$pl3_awb_no'");
                							$statement->execute();
                							$result = $statement->fetchAll(PDO::FETCH_ASSOC);;
                                            if(!$result)
                                            {
                                              $error_msg[]=" 3PL AWB Number is ".$pl3_awb_no." Not Available...";
                                            }
                							
                	                 }
                	                 
                	                 
                	                 
                	                 if(count($pl3_awb)>0)
                	                 {
                	                     foreach(array_count_values($pl3_awb) as $num => $value)
                                        {
                                            if($value>1 && $num !='' && !empty($num))
                                            {
                                            	$error_msg[]=$num." 3PL AWB Number is having duplicate value of ".$value." times in our csv file";
                                            }
                                        }
                	                 }
	                 }
	                 else /*Client Panel*/
	                 {
	                     if($emapData[2]!='') 
    	                 {
    								$error_msg[]="Row Number ".$ri." It's Auto-Generated column leave it as empty";
    	                 } 
    	                 else
    	                 $pl3_awb[]="";
	                 }
	                 /*Ref No(3)*/  
	                 if($emapData[3]==''|| empty($emapData[3])) 
	                 {
	                     $error_msg[]="Row Number ".$ri." Ref Number Can't be empty...";
	                 }
	                 else { 
	                        $ref_n=$emapData[3];
	                        $statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE ref_no=?");
							$statement->execute(array($ref_n));
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							$count = $statement->rowCount();
							if($count>0)
							{
							   $error_msg[]="Row Number ".$ri." Ref No Already Exist...";
							}
							else
							{
							   $ref_no[]=$ref_n;
							}
	                 }
	                 
	                      if(count($ref_no)>0)
	                 {
	                     foreach(array_count_values($ref_no) as $num => $value)
                        {
                            if($value>1)
                            {
                            	$error_msg[]=$num."Row Number ".$ri." Reference Number is having duplicate value of ".$value." times in our csv file";
                            }
                        }
	                 }
	                 
	     /*Order Type(4)*/ if($emapData[4]=='' || empty($emapData[4]))
	                 {  
	                     $error_msg[]="Row Number ".$ri." Order Type Can't Be Empty...";
	                 }elseif(strtolower($emapData[4]) == 'cod' || strtolower($emapData[4]) == 'prepaid')
	                 {
	                    $emapData[4]=strtolower($emapData[4]);
	                    $order_type[]=strtolower($emapData[4]);
	                    }else {
	                        $error_msg[]="Row Number ".$ri." Order Type Must Be COD or PREPAID..."; 
	                        
	                    }
	                 /*Collectable Amount(5)*/if($emapData[5]=='') { $error_msg[]="Row Number ".$ri." Invalid Collectable Amount";  }else{ $collectable_amount[]=$emapData[5];}
	                 
	                /*	Business Mode (Required)(6)*/  if($emapData[6]==''|| empty($emapData[6])) { $error_msg[]="Row Number ".$ri." Business Mode Can't Be Empty..."; } elseif(strtolower($emapData[6])=='air' ||strtolower($emapData[6])=='surface'){ $emapData[6]=strtolower($emapData[6]);$business_mode[]=strtolower($emapData[6]); }else { $error_msg[]="Row Number ".$ri." Business Mode Must Be AIR or SURFACE..."; }
	                 
	                 /*	B2B/B2C(7)*/ if($emapData[7]==''|| empty($emapData[7])) { $error_msg[]="Row Number ".$ri." B2B/B2C Can't Be Empty..."; } elseif(strtolower($emapData[7])=='b2b' ||strtolower($emapData[7])=='b2c'){ $emapData[7]=strtolower($emapData[7]);$b2b_b2c[]=strtolower($emapData[7]); }else { $error_msg[]="Row Number ".$ri." B2B/B2C Must Be B2B or B2C..."; } 
	   
	                 /*Shipper Name(8)*/   if($emapData[8]==''|| empty($emapData[8])){  $emapData[8]=$full_name;$f_name[]=$full_name; }else{ $f_name[]=$emapData[8];}    
	                 
	                 /* Shipper Address(9) */  if($emapData[9]=='' || empty($emapData[9])){  $emapData[9]=$address;$addr[]=$address; }else{ $emapData[9]=str_replace("'","",$emapData[9]);$addr[]=str_replace("'","",$emapData[9]);  }
	                 
	                 /* Shipper City(10) */    if($emapData[10]==''|| empty($emapData[10])){  $emapData[10]=$city;$c_city[]=$city; }else{ $c_city[]=$emapData[10];}
	                 
	                /*  Shipper State(11) */ if($emapData[11]==''|| empty($emapData[11])){ $emapData[11]=$state;$c_state[]=$state; }else{ $c_state[]=$emapData[11];}
	                 
	                 /* Shipper Pincode(12) */ if($emapData[12]==''|| empty($emapData[12])|| !is_numeric($emapData[12])){ $emapData[12]=$pincode;$c_pincode[]=$pincode; }else{$c_pincode[]=$emapData[12];}
	                 
	                 /* Shipper Phone(13) */ if($emapData[13]==''|| empty($emapData[13])|| !is_numeric($emapData[13])){ $emapData[13]=$phone;$c_phone[]=$phone; }else{$c_phone[]=$emapData[13];}
	               
	                   if($emapData[14]==''|| empty($emapData[14]))/* Consignee Name(14) */
	                 {
	                       $error_msg[]="Row Number ".$ri." Consignee Name Can't Be Empty...";   
	                 }
	                 else
	                 {
	                     $consignee_name[]=$emapData[14];
	                 }
	                   if($emapData[15]==''|| empty($emapData[15]))/* Consignee Address(15) */
	                 {
	                     $error_msg[]="Row Number ".$ri." Consignee Address Can't Be Empty...";   
	                 }
	                 else
	                 {
	                     $consignee_address[]=str_replace("'","",$emapData[15]); 
	                 }
	                 
	                   if($emapData[16]==''|| empty($emapData[16]))/* Consignee City(16) */
	                 {
	                     
	                       $error_msg[]="Row Number ".$ri." Consignee City Can't Be Empty...";   
	                 } 
	                  else
	                 {
	                     $consignee_city[]=$emapData[16];
	                 }
	                 if($emapData[17]==''|| empty($emapData[17]))/* Consignee State(17) */
	                 {
	                     $error_msg[]="Row Number ".$ri." Consignee State Can't Be Empty...";   
	                 }  
	                  else
	                 {
	                    $consignee_state[]=$emapData[17];
	                 }
	                 if(is_numeric($emapData[18]))/* Consignee Pincode(18) */
	                 {
                         /* Check Availability of the consignee pincode */ 
        	                 if($emapData[6]!='' && $emapData[7]!='' && $emapData[18]!='' && !empty($emapData[6]) && !empty($emapData[7]) && !empty($emapData[18]))
        	                 {
                            	$pincode_mode = strtolower($emapData[6]);
                                $pincode_type = strtolower($emapData[7]);
                                $pincode = $emapData[18];
                                if($pincode_mode=='air')
                                {
                                   $mode='air';
                                }
                                elseif($pincode_mode=='surface')
                                {
                                  $mode='road';  
                                }
                                else
            	                 {
            	                     $error_msg[]="Row Number ".$ri." Invalid Consignee PincodeMode...";
            	                 }
                        	$statement = $pdo->prepare("SELECT * FROM pincode where pin_code=".$pincode);
        					$statement->execute();
        					$result = $statement->fetchAll(PDO::FETCH_ASSOC);
        					$total_pincode = $statement->rowCount();
                            if($total_pincode>0){  $consignee_pincode[]=$emapData[18]; }  else   {  $error_msg[]="Row Number ".$ri." Service Not Available For This Consignee Pincode..."; }
        	                 }
        	                 
        	                 /* Check Availability of the consignee pincode */ 
	                 }
	                 else
	                 {
	                     $error_msg[]="Row Number ".$ri." Consignee Pincode Can't Be Empty...";
	                 }
	                 if($emapData[19]=='' || empty($emapData[19]) || !is_numeric($emapData[19]))/* Consignee Phone(19) */
	                 {
	                       $error_msg[]="Row Number ".$ri." Consignee Phone Can't Be Empty...";
	                 }
	                  else
	                 {
	                      $consignee_phone[]=$emapData[19];
	                 }
	                 
	                    if($emapData[20]=='' || empty($emapData[20]))/* Product Description(20) */
	                 {
	                       $product_description[]='';
	                       
	                 }
	                 else
	                 {
	                     $product_description[]=$emapData[20];
	                 }
	                    if($emapData[21]=='' || !is_numeric($emapData[21]))/* Quantity(21) */
	                 {
	                       $error_msg[]="Row Number ".$ri." Invalid Quantity ..."; 
	                 }
	                 else
	                 {
	                     $quantity[]=$emapData[21];
	                 }
	                 
	                 
	               if($emapData[22]=='' || !is_numeric($emapData[22]))/* Actual Weight(22) */
	                 {
	                       $error_msg[]="Row Number ".$ri." Invalid Actual Weight...";
	                 }
	                 else
	                 {
	                     $actual_weight[]=$emapData[22];
	                     $temp_a_weight=$emapData[22];;
	                 }
	                   
	                    if($emapData[23]=='' || !is_numeric($emapData[23]))/* Volumetric Weight(23) */
	                 {
	                     if(is_numeric($emapData[24]) && is_numeric($emapData[25]) && is_numeric($emapData[26]) )
	                     {
	                         $vw_cal=((($emapData[24]*$emapData[25]*$emapData[26])/5000)*$emapData[44]);
	                         //$emapData[23]=$vw_cal;
	                         $volumetric_weight[]=$vw_cal;
	                     }
	                     else
	                     {
	                         $volumetric_weight[]=0;
	                         $vw_cal=0;
	                     }
	                     
    
	                 }
	                 else
	                 {
	                     $vw_cal=$emapData[23];
	                      $volumetric_weight[]=$emapData[23];
	                 }
	                    if(is_numeric($emapData[24]))/* Vol.Length(24) */
	                 {
	                       $volumetric_length[]=$emapData[24];
	                 }
	                  else
	                 {
	                      $volumetric_length[]='';
	                 }
	                    if(is_numeric($emapData[25]))/* Vol.Breadth(25) */
	                 {
	                      $volumetric_breadth[]=$emapData[25];
	                 }
	                  else
	                 {
	                     $volumetric_breadth[]='';
	                 }
	                    if(is_numeric($emapData[26]))/* Vol.Height(26) */
	                 {
	                      $volumetric_height[]=$emapData[26];
	                 }
	                  else
	                 {
	                     $volumetric_height[]='';
	                 }
	                 
	                 if($emapData[27]==''|| !is_numeric($emapData[27]))/* Charged Weight(27) */
	                 {
	                       if(is_numeric($temp_a_weight) && is_numeric($vw_cal))
	                       {
    	                        if($temp_a_weight>$vw_cal)
    	                       {
    	                           $charged_weight[]=$temp_a_weight;
    	                       }
    	                       else
    	                       {
    	                           $charged_weight[]=$vw_cal;
    	                       }
	                       }
	                       else
	                       { $charged_weight[]=0; }
	                 }
	                 else
	                 {
	                     $charged_weight[]=$emapData[27];
	                 }
	                 
	                 
	                    if($emapData[29]!='')/* Taxable Value(29) */
	                 {
	                       $taxable_value[]= $emapData[29];
	                 }
	                else
	                 {
	                     $error_msg[]="Row Number ".$ri." Taxable Value Can't be empty,otherwise we can't calculate Invoice value...";
	                 }
	                    if($emapData[30]!='' || !empty($emapData[30]))/* HSN Code(30) */
	                 {
	                    $hsn_code_test=$emapData[30];
	                    $statement = $pdo->prepare("SELECT * FROM tbl_hsncode where hsncode='$hsn_code_test'");
						$statement->execute();
						$result = $statement->fetchAll(PDO::FETCH_ASSOC);
						$count = $statement->rowCount();
                        if($count==1)
                        {
                            $hsn_code[]= $emapData[30]; 
                        }
                        else
                        {
                           $error_msg[]="Row Number ".$ri." HSN Code is invalid..."; 
                        }
	                       
	                 }
	                  else
	                 {
	                     $error_msg[]="Row Number ".$ri." HSN Code Can't be empty,otherwise we can't calculate Invoice value...";
	                 }
	                 
	                    if($emapData[31]!='')/* Discount(31) */
	                 {
	                       $discount[]=$emapData[31];
	                 }
	                 else
	                 {
	                     $discount[]=''; 
	                 }
	                  if($emapData[32]!='')/* Gst Type(32) */
	                 {
	                     $emapData[32]=strtolower($emapData[32]);
	                     if($emapData[32]=='igst'){ $grate[]='gr_igst';  $gst_t='gr_igst';}
	                     elseif($emapData[32]=='cgst'){ $grate[]='gr_cgst'; $gst_t='gr_cgst'; }
	                 }
	                   else
	                 {
	                     $error_msg[]="Row Number ".$ri." Gst Type Can't be empty,otherwise we can't calculate Invoice value and GST amount...";
	                 }
	                 
	                 
	                    if($emapData[34]!='')/* MRP(34) */
	                 {
	                      $mrp[]= $emapData[34];
	                 }
	                 else
	                 {
	                     $mrp[]='';
	                 }
	                 
	                    if($emapData[35]!='')/* Ewaybill(35) */
	                 {
	                       $ewaybill[]=$emapData[35];
	                 }
	                  else
	                 {
	                     $ewaybill[]='';
	                 }
	                     if($emapData[36]!='')/* Buyer Gst(36) */
	                 {
	                       $buyer_gst[]=$emapData[36];
	                 }
	                  else
	                 {
	                     $buyer_gst[]='';
	                 }
	                     if($emapData[37]!='')/* Seller Gst(37) */
	                 {
	                       $seller_gst[]=$emapData[37];
	                 }
	                   else
	                 {
	                     $seller_gst[]='';
	                 }
	                 
	                 
	                     if($emapData[38]=='')/* RTO Name(38) */
	                 {
	                       $rto_name[]=$full_name;
	                 }
	                 else{  $rto_name[]=$emapData[38]; }
	                 
	                     if($emapData[39]=='')/* RTO Address(39) */
	                 {
	                       $rto_address[]=$address;
	                 }
	                 else
	                 {
	                     $rto_address[]=str_replace("'","",$emapData[39]);    
	                 }
	                 
	                     if($emapData[40]=='')/* RTO City(40) */
	                 {
	                       $rto_city[]=$city;
	                 } 
	                 else{  $rto_city[]=$emapData[40]; } 
	                 if($emapData[41]=='')/* RTO State(41) */
	                 {
	                        $rto_state[]=$state;
	                 }else { $rto_state[]=$emapData[41]; }
	                 
	                     if($emapData[42]=='' || empty($emapData[42]))/* RTO Pincode(42) */
	                 {
	                       $rto_pincode[]=$pincode;
	                 }
	                 else {$rto_pincode[]=$emapData[42];}
	                     if($emapData[43]=='' || empty($emapData[43]))/* RTO Phone(43) */
	                 {
	                       $rto_phone[]=$phone;
	                 }else {$rto_phone[]=$emapData[43];}
	                 
	                    if($emapData[44]!='' && !empty($emapData[44]) && is_numeric($emapData[44]))/* No.of Boxes(44) */
	                 {
	                       $boxes[]= $emapData[44];
	                 }
	                  else
	                 {
	                     $error_msg[]="Row Number ".$ri." Number of boxes Invalid";
	                 }
	                
	                 if($emapData[45]==''|| empty($emapData[45]))/* Pickup Entry Date(17) */
	                 {
	                     $pickup_date[]=$date;   
	                 }  
	                  else
	                 {
	                   // $day=date_create($emapData[45]);
	                   // $created=date_format($day,'Y-m-d');
	                   // $pickup_date[]=$created;
	                    
	                    
	                           $given=$emapData[45];
                                $len=strlen($given);
                                if($len==10){
                                $date=date_create_from_format("d-m-Y",$given);
                                $created= date_format($date,"Y-m-d");
                                 $pickup_date[] = $created;
                                }elseif($len==8)
                                {
                                $date=date_create_from_format("d-m-y",$given);
                                $created= date_format($date,"Y-m-d");
                                 $pickup_date[] = $created;
                                }
                                else
                                {
                                $error_msg[] = "Row Number " . $ri . " Invalid Date Format (Format should be 23-02-2055 OR 23-02-55)...";
                                }
	                 }
	                
	                
	                
	                /*Calculate the GST percentage based on hsncode*/ 
	                 if($emapData[30]!='')
	                 {
	                    $hsn_code1=$emapData[30];
	                    $statement = $pdo->prepare("SELECT * FROM tbl_hsncode where hsncode='$hsn_code1'");
						$statement->execute();
						$result = $statement->fetchAll(PDO::FETCH_ASSOC);
						$count = $statement->rowCount();
                         foreach ($result as $row) 
                         {
                                $hsncode1 = $row['hsncode'];
                                $igst = $row['igst'];
                                $cgst = $row['cgst'];
                                $sgst = $row['sgst'];
                         } 
	                 }
	                 /*Calculate the GST percentage based on hsncode*/ 
	                 
	               
	                  
	                 /* Calculate the GST Amount and Invoice Value */ 
                     
                     $tax_value=floatval($emapData[29]);
                     
                     if($gst_t=='gr_igst'){ $gst_amount_cal= ($tax_value*$igst)/100; }
                     elseif($gst_t=='gr_cgst'){ $csgst=floatval($cgst)+floatval($sgst);   $gst_amount_cal= ($tax_value*$csgst)/100;}
                     
                     $invoice_value_cal=floatval($tax_value)+floatval($gst_amount_cal);
                     
                       if(!is_numeric($emapData[28]))/* Invoice Value(28) */
	                 {
	                       $invoice_value[]=$invoice_value_cal;
	                 }
	                 else
	                 {
	                     $invoice_value[]=$emapData[28];
	                 }
	                 
	                 if(is_numeric($emapData[33]))/* Gst Amount(33) */
	                 {
	                      $gst_amount[]= $emapData[33];
	                 }
	                 else
	                 {
	                     $gst_amount[]=$gst_amount_cal;
	                 }
	 	             }
				        $ri++;
		    }
		
	         fclose($file);
	       
	           
/*if($clientType=="Admin")
{ 	       
    	        $statement = $pdo->prepare("SELECT * FROM `tbl_awb` WHERE status=0 and courier_id=$courier_company_id");
    			$statement->execute();
    			$result = $statement->fetchAll(PDO::FETCH_ASSOC);
    			$count_3pl = $statement->rowCount();
                if($count_3pl < count($pl3_awb))
                {
                    $error_msg[]="Insufficient 3PL AWB Number(Available:".$count_3pl." | Required: ".count($pl3_awb)." )...";
                }
}*/

	       
	        
if(count($error_msg)>0)
{
?>
<style>
/* WAVE */

@-webkit-keyframes burst {
  0% {
    opacity: .6;
  }

  50% {
    -webkit-transform: scale(1.8);
    transform: scale(1.8);
    opacity: 0;
  }

  100% {
    opacity: 0;
  }
}

@keyframes burst {
  0% {
    opacity: .6;
  }

  50% {
    -webkit-transform: scale(1.8);
    -ms-transform: scale(1.8);
    transform: scale(1.8);
    opacity: 0;
  }

  100% {
    opacity: 0;
  }
}

.faa-burst.animated,
.faa-burst.animated-hover:hover,
.faa-parent.animated-hover:hover > .faa-burst {
  -webkit-animation: burst 3s infinite linear;
  animation: burst 3s infinite linear;
}
</style>
<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><br>
<i class='fa fa-exclamation-triangle faa-burst animated fa-4x' style='font-size:148px;color:red;'></i>
<br>
</center>

 <div class="alert alert-danger alert-dismissible"  style='margin-left: 2%;margin-right: 2%;overflow:scroll;'>
<!--	    <a href="#" class="close" data-dismiss="alert" onclick='location.reload();' aria-label="close">Close &times;</a>-->
		    <table class="table">
		        <tr>
		        <th>S.No</th>
		        <th>Status</th>
		        </tr>
		        <?php $ii=0;
foreach($error_msg as $msg)
{ ?>
     <tr>
		    <td><?php echo $ii+1 ?></td>
		    <td><?php echo $msg ?></td>
		    </tr>
<?php $ii++;  }?>
</table>
</div>
<?php }
else
{ ?>
<!--CSCS AWB (Required)(1)	3PL AWB (Required)(2)	Ref No (Required)(3)	Order Type(Optional )(4)	Collectable Amount(Optional )(5)	Business Mode (Required)(6)-->
<!--	               B2B/B2C(7)	Shipper Name(Required)(8)	Shipper Address( Optional )(9)	Shipper City( Optional )(10)	Shipper State( Optional )(11)	Shipper Pincode( Optional )(12)-->
<!--	               Shipper Phone(Required & Avoid Duplicate Numbers )(13)	Consignee Name(Required)(14)	Consignee Address( Optional )(15)	Consignee City( Optional )(16)	-->
<!--	               Consignee State( Optional )(17)	Consignee Pincode( Optional )(18)	Consignee Phone(Required )(19)	Product Description( Optional )(20)	Quantity(Required)(21)-->
<!--	               Actual Weight(Required)(22)	Volumetric Weight(Optional if you having length,breadth,height)(23)	Vol.Length(Optional if you having Volumetric Weight)(24)-->
<!--	               Vol.Breadth(Optional if you having Volumetric Weight)(25)	Vol.Height(Optional if you having Volumetric Weight)(26)	Charged Weight(Required)(27)	-->
<!--	               Invoice Value( Optional )(28)	Taxable Value( Optional )(29)	HSN Code( Optional )(30)	Discount( Optional )(31)	Gst Type( Optional )(32)	Gst Amount( Optional )(33)	-->
<!--	               MRP( Optional )(34)	Ewaybill( Optional )(35)	Buyer Gst( Optional )(36)	Seller Gst( Optional )(37)	RTO Name(Required )(38)	RTO Address( Optional )(39)	RTO City( Optional )(40)-->
<!--	               RTO State( Optional )(41)	RTO Pincode( Optional )(42)	RTO Phone(Required )(43) No.of Boxes(Required )(43)-->
    <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 class="alert alert-success alert-dismissible"  style='margin-left: 2%;margin-right: 2%;overflow:scroll;'>
	   <!-- <a href="#" class="close" data-dismiss="alert" onclick='location.reload();' aria-label="close">Close &times;</a>-->
		    <table class="table table-responsive" >
		        <tr class="table-success">
		        <th>S.No</th>
		        <th>Status</th>
		        <th>CSCS AWB</th>
		       <?php  if($clientType=="Admin"){?> <th>3PL AWB</th><?php }?>
		        <th>Ref No</th>
		        <th>Order Type</th>
		        <th>Collectable Amount</th>
		        <th>Business Mode</th>
		        <th>Business Type</th>
		        <th>Shipper Name</th>
		        <th>Shipper Address</th>
		        <th>Shipper City</th>
		        <th>Shipper State</th>
		        <th>Shipper Pincode</th>
		        <th>Shipper Phone</th>
		        <th>Consignee Name</th>
		        <th>Consignee Address</th>
		        <th>Consignee City</th>
		        <th>Consignee State</th>
		        <th>Consignee Pincode</th>
		        <th>Consignee Phone</th>
		        <th>Product Description</th>
		        <th>Quantity </th>
		        <th>Actual Weight </th>
		        <th>vol.Weight </th>
		        <th>Vol.Length </th>
		        <th>Vol.Breadth </th>
		        <th>Vol.Height </th>
		        <th>Charged Weight </th>
		        <th>Invoice Value </th>
		        <th>Taxable Value </th>
		        <th>HSN Code </th>
		        <th>Discount </th>
		        <th>Gst Type </th>
		        <th>Gst Amount </th>
		        <th>MRP </th>
		        <th>Ewaybill </th>
		        <th>Buyer Gst </th>
		        <th>Seller Gst </th>
		        <th>RTO Name </th>
		        <th>RTO Address </th>
		        <th>RTO City </th>
		        <th>RTO State </th>
		        <th>RTO Pincode </th>
		        <th>RTO Phone </th>
		        <th>No.of Boxes </th>
		        <th>Date </th>
		        </tr>
		    <?php
		    $k=0;
		     foreach($pl3_awb as $pl3_awbs)
		     {
		         echo "";
		         $status='failed';
		         
		           /******************** 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());
                    
                    if($create_cscs_status[$k]==1){
                        $increment=1;
                        do {
                            $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_nos=$row['big_id']+$increment;
                                        $cscs_awb_value=100000+$awb_nos;
                                    }
                                    else
                                    {
                                        $cscs_awb_value=100001;
                                    }
                				}
                			$statement = $pdo->prepare("SELECT * FROM pickup_entry WHERE cscs_awb='$cscs_awb_value'");
                			$statement->execute();
                			$total_cscs = $statement->rowCount();
                			$increment++;	
                            } while ($total_cscs != 0);
                            
                            $generated_cscs=$cscs_awb_value;
                            $autoGen=1;
                    }else
                    {
                        $generated_cscs=$cscs_awb[$k];
                        $autoGen=2;
                    }
	             
	            	 $statement = $pdo->prepare("INSERT INTO pickup_entry (`autoGen`,`client_id`,`courier_id`, `cscs_awb`, `3pl_awb`, `ref_no`, `order_type`, `collectable_amount`,`business_mode`,`business_type`, `shipper_name`,
	            	 `shipper_address`, `shipper_city`, `shipper_state`, `shipper_pincode`, `shipper_phone`, `consignee_name`, `consignee_address`, `consignee_city`, `consignee_state`,
	            	 `consignee_pincode`, `consignee_phone`, `product_description`, `quantity`, `a_weight`,`v_weight`, `vw_length`, `vw_breadth`, `vw_height`, `c_weight`,
	            	 `invoice_value`, `taxable_value`, `hsn_code`, `discount`, `gst_rate`, `gst_amount`, `mrp`, `ewaybill`, `buyer_gst`, `seller_gst`,`rto_name`, `rto_address`, 
	            	 `rto_city`, `rto_state`, `rto_pincode`, `rto_phone`, `delete_status`,  `date_added`,`boxes`,`status_code`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
	            	 $result=$statement->execute(array($autoGen,$client_id,$courier_companies[$k],$generated_cscs,$pl3_awb[$k],$ref_no[$k],$order_type[$k],$collectable_amount[$k],$business_mode[$k],$b2b_b2c[$k],$f_name[$k],
	            	 $addr[$k],$c_city[$k],$c_state[$k],$c_pincode[$k],$c_phone[$k],$consignee_name[$k],$consignee_address[$k],$consignee_city[$k],$consignee_state[$k],$consignee_pincode[$k],$consignee_phone[$k],$product_description[$k],$quantity[$k],
	            	 $actual_weight[$k],$volumetric_weight[$k],$volumetric_length[$k],$volumetric_breadth[$k],$volumetric_height[$k],$charged_weight[$k],$invoice_value[$k],$taxable_value[$k],$hsn_code[$k],$discount[$k],$grate[$k],$gst_amount[$k],$mrp[$k],$ewaybill[$k],$buyer_gst[$k],$seller_gst[$k],$rto_name[$k],$rto_address[$k],$rto_city[$k],$rto_state[$k],$rto_pincode[$k],$rto_phone[$k],'0',$pickup_date[$k],$boxes[$k],'1'));
	            
	                 if($result){
	                     $status='success';
                		/*Tracking Module Start*/
                		$statement = $pdo->prepare("INSERT INTO tbl_tracking (pickup_entry_id,user_id,location,status,status_code,description,remark,created_at) VALUES (?,?,?,?,?,?,?,?)");
                	    $result1 =$statement->execute(array($ai_id,$client_id,$clientLocation,'pending','1','Shipment Softdata Created Successfully','Material Safe...',$pickup_date[$k]));
    	                $j++;
	                 }
		         
		         
		         
		     ?>
		     <tbody>
		    <tr class="table-active">
		    <td><?php echo $k+1 ?></td>
		    <td><?php echo  $status ;?></td>
		    <td><?php echo $generated_cscs ?></td>
		    <?php  if($clientType=="Admin"){?><td><?php echo $pl3_awbs ?></td><?php }?>
		    <td><?php echo $ref_no[$k] ?></td>
		    <td><?php echo $order_type[$k]  ?></td>
		    <td><?php echo $collectable_amount[$k]  ?></td>
		    <td><?php echo strtoupper($business_mode[$k]); ?></td>
		    <td><?php echo strtoupper($b2b_b2c[$k]); ?></td>
		    <td><?php echo $f_name[$k] ?></td>
		    <td><?php echo $addr[$k] ?></td>
		    <td><?php echo $c_city[$k] ?></td>
		    <td><?php echo $c_state[$k] ?></td>
		    <td><?php echo $c_pincode[$k] ?></td>
		    <td><?php echo $c_phone[$k] ?></td>
		    <td><?php echo $consignee_name[$k] ?></td>
		    <td><?php echo $consignee_address[$k] ?></td>
		    <td><?php echo $consignee_city[$k] ?></td>
		    <td><?php echo $consignee_state[$k] ?></td>
		    <td><?php echo $consignee_pincode[$k] ?></td>
		    <td><?php echo $consignee_phone[$k] ?></td>
		    <td><?php echo $product_description[$k] ?></td>
		    <td><?php echo $quantity[$k] ?></td>
		    <td><?php echo $actual_weight[$k] ?></td>
		    <td><?php echo $volumetric_weight[$k] ?></td>
		    <td><?php echo $volumetric_length[$k] ?></td>
		    <td><?php echo $volumetric_breadth[$k] ?></td>
		    <td><?php echo $volumetric_height[$k] ?></td>
		    <td><?php echo $charged_weight[$k] ?></td>
		    <td><?php echo $invoice_value[$k] ?></td>
		    <td><?php echo $taxable_value[$k] ?></td>
		    <td><?php echo $hsn_code[$k] ?></td>
		    <td><?php echo $discount[$k] ?></td>
		    <td><?php if($grate[$k]=='gr_cgst') {echo 'CGST'; }elseif($grate[$k]=='gr_igst') {echo 'IGST'; }  ?></td>
		    <td><?php echo $gst_amount[$k] ?></td>
		    <td><?php echo $mrp[$k] ?></td>
		    <td><?php echo $ewaybill[$k] ?></td>
		    <td><?php echo $buyer_gst[$k] ?></td>
		    <td><?php echo $seller_gst[$k] ?></td>
		    <td><?php echo $rto_name[$k] ?></td>
		    <td><?php echo $rto_address[$k] ?></td>
		    <td><?php echo $rto_city[$k] ?></td>
		    <td><?php echo $rto_state[$k] ?></td>
		    <td><?php echo $rto_pincode[$k] ?></td>
		    <td><?php echo $rto_phone[$k] ?></td>
		    <td><?php echo $boxes[$k] ?></td>
		    <td><?php echo $pickup_date[$k] ?></td>
		    </tr>
		    
		    <?php $k++; }?>
		    </tbody>
			</table>
	</div>    
<!--</body>
</html>-->
		    <?php
		    /*  Updating the tbl_awb list for used awb numbers*/
		    if(count($pl3_awb_update_number)>0){
		                foreach($pl3_awb_update_number as $pl3_awbs )
		                {
		                 $statement = $pdo->prepare("UPDATE `tbl_awb` set status=1 WHERE awb_code='$pl3_awbs'");
		                 $statement->execute();
		                }
		    }
                         }
                          }
                           }
    
    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'); ?>
