PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE courier_charges (`id` int,`fromKg` int,`toKg` int,`tn_own` int, `tn_other` int, `south_own` int, `south_other` int, `roi` int) ; INSERT INTO courier_charges (`id`,`fromKg`,`toKg`,`tn_own`,`tn_other`,`south_own`,`south_other`,`roi`) VALUES (1, 0, 1,0,0,20,20,150) ;
Copy Clear
Copy Format Clear
<?php $state = "TamilNadu"; $south = 0; $own_items = array("cnt"=>"2", "weight"=>"2.5"); $not_own_items = array("cnt"=>"2", "weight"=>"0.75"); if($state!='') { //{{New code begin //Weight multiplier $own_items_weight_multiplier = floor($own_items['weight']); $not_own_items_weight_multiplier = floor($not_own_items['weight']); $own_items_fractional_weight=$own_items['weight']-$own_items_weight_multiplier; $not_own_items_fractional_weight=$not_own_items['weight']-$not_own_items_weight_multiplier; //New code end }} $shipping = 0; $Oshipping = 0; if($own_items['cnt'] > 0) { $charge = mysqli->query("select * from courier_charges where ".$own_items['weight']." between fromKg and toKg")->getRowArray(); if($south==0) $shipping = $shipping + $charge['tn_own']; /*else if($south==1) $shipping = $own_items['weight'] * ($shipping + $charge['south_own']);*/ //{{New code begin else if($south==1){ $charge = $this->db->query("select * from courier_charges where ".$own_items_weight_multiplier." between fromKg and toKg")->getRowArray(); $shipping = $shipping + $charge['south_own']; } //New code end}} else if($south==2) $shipping = $shipping + $charge['roi']; } $diffWeight = 0; $extraWghtCost = 0; if($not_own_items['cnt'] > 0) { $Ocharge = $this->db->query("select * from courier_charges where ".$not_own_items['weight']." between fromKg and toKg")->getRowArray(); /*if($south==0) $Oshipping = $not_own_items['weight'] * ($Oshipping + $Ocharge['tn_other']);*/ //{{New code begin if($south==0) $Oshipping = $Oshipping + $Ocharge['tn_other']; //New code end}} else if($south==1) { /*$totWeight = $own_items['weight'] + $not_own_items['weight']; if(ceil($totWeight) > $totWeight) { $diffWeight = ceil($totWeight) - $totWeight; $extraWghtCost = $diffWeight * 20; } $Oshipping = $not_own_items['weight'] * ($Oshipping + $Ocharge['south_other']); */ //{{New code begin $Ocharge = $this->db->query("select * from courier_charges where ".$own_items_weight_multiplier." between fromKg and toKg")->getRowArray(); $Oshipping = $Oshipping + $Ocharge['south_other']; //New code end}} } else if($south==2) $Oshipping = $Oshipping + $Ocharge['roi']; } //Extra weight calculation /*$totWeight = $own_items['weight'] + $not_own_items['weight']; if(ceil($totWeight) > $totWeight) { $diffWeight = ceil($totWeight) - $totWeight; $extraWghtCost = $diffWeight * 20; }*/ //{{New code begin $totWeight= ceil($own_items_fractional_weight+$not_own_items_fractional_weight); $extraWghtCost =$totWeight*20; //New code end}} //echo $extraWghtCost; exit; $this->db->table('cart_temp_shipping')->where('unique_id',$unique_id)->delete(); $session_data = session()->get('user_in'); $insert['cusId'] = $session_data->cusId; $insert['unique_id'] = $unique_id; $insert['totalWeight'] = $own_items['weight'] + $not_own_items['weight']; $insert['shipping'] = $shipping + $Oshipping + $extraWghtCost; $insert['grandTotal'] = $own_items['total'] + $not_own_items['total'] + $shipping + $Oshipping + $extraWghtCost; $this->db->table('cart_temp_shipping')->insert($insert); echo 'true'; } else echo 'false'; ?>
Show:  
Copy Clear