vendredi 30 septembre 2016

If else if statments not working

I have worked on this code for a week, as to not have to ask for assistance but i cannot find the problem with the code, so here goes I have a series of if and elseif statements that change two variable outputs $costs and $change. They are not working properly. i have attached the code.

if ($strip <= $UseDate){
                
                if($row['commission_level'] == 1) {
                $maxprice3=max(($follettnew),($junk),($amtext*1.71),($newPrice),($sterling*1.71),($nebraska*1.2),($tich*1.25),($ingram*1.2),($bookbyte));
                
                if ($maxprice3>0){

                $costs=$maxprice3;
                $change="1";
                }
                elseif ($maxprice3==0) {
                        $costs = 0;
                        $change="2";
                } 
        }
                elseif (($bookTypeId=="1") || ($bookTypeId=="9")|| ($bookTypeId=="10")|| ($bookTypeId=="11")){
                        $maxprice=max(($follett),($junk),($amtext*1.37),($nebraska*1.2),($tich*1.25),($sterling*1.37),($bookWin),($ingram*1.2),($bookbyte));
                                if ($maxprice>0){
                                
                                                        $costs = $maxprice;
                                                        $change=3;
                                                
                                                }
                                                elseif ($maxprice==0) {
                                                        $costs=$cost2;
                                                        $change=4;
                                                }
                                
                                
        }

                
                if      (($bookTypeId=="2") || ($bookTypeId=="5") || ($bookTypeId=="6") || ($bookTypeId=="7") || ($tpd =="TPD" )){
                                $maxprice2=max(($amtext*1.37),($junk),($sterling*1.37));        
                                if ($maxprice2>0){
                                        
                                                        $costs = $maxprice2;
                                                        $change=1;
                                                                                }
                                if ($maxprice2==0) {
                                        $costs = 0;
                                        $change=2;
                                        }
                        }
                
                if($damage=="DMG" || $damage=="WATER"|| $condition==3 || $bookTypeId==3 ) {
                                $costs = 0;
                                $change=3;
                        }
                
        
        
        }

else {
        
        if($row['commission_level'] == 1) {
        $maxprice3=max(($follettnew),($junk),($amtext*1.71),($newPrice),($sterling*1.71),($nebraska*1.2),($tich*1.25),($ingram*1.2),($bookbyte));
                if ($maxprice3>0){

                $costs=$maxprice3;
                $change="1N";
                }
                elseif ($maxprice3==0) {
                        $costs = $cost2;
                        $change="2N";
                } 
        }
        elseif (($bookTypeId=="1") || ($bookTypeId=="9")|| ($bookTypeId=="10")|| ($bookTypeId=="11")){
                        $maxprice=max(($follett),($junk),($amtext*1.37),($nebraska*1.2),($tich*1.25),($sterling*1.37),($bookWin),($ingram*1.2),($bookbyte));
                                if ($maxprice>0){
                                        if($cost<$maxprice){                                 
                                                        $costs = $maxprice;
                                                        $change="15N";
                                                                                }
                                elseif ($maxprice==0) {
                                        $costs = $cost2;
                                        $change="16N";
                                        }
                        }
        }
        
        if      (($bookTypeId=="2") || ($bookTypeId=="5") || ($bookTypeId=="6") || ($bookTypeId=="7") || ($tpd =="TPD" )){
                                $maxprice2=max(($amtext*1.37),($junk),($sterling*1.37));                
                                if ($maxprice2>0){
                                        if($cost<$maxprice2){                                        
                                                        $costs = $maxprice2;
                                                        $change="3N";
                                                                                }
                                elseif ($maxprice2==0) {
                                        $costs = $cost2;
                                        $change="4N";
                                        }
                        }
        }
                
                if($damage=="DMG" || $damage=="WATER" || $condition==3 || $bookTypeId==3 ) {
                                $costs = 0;
                                $change="5N";
                        }
                
                        


        
                                
        }
        
else{
        $costs=$cost2;
}
        


if($condition==4) {
                                $costs = 0;
                                $change="25A";
                        }


        
if($location == "FBA") {
        $place = "Amazon_NA";
} else {
        $place = "";
        }       
        
        if ($bookTypeId==8){
        $category='Custom';
}
elseif ($bookTypeId==1){
        $category='Book';
}
elseif ($bookTypeId==9){
        $category='DVD/CD';
}
else{
        $category='Special Edition';
}

$conn->query("UPDATE inventory SET cu=$cu2 WHERE sku= $sku");


$export[$x] = array('item-name' => $title,
                    'sku' => $sku,
                    'quantity' =>$quantity,
                    'item-note' => $itemNote,
                    'will-ship-internationally' =>$willShip,
                    'product-id' => $isbn,
                    'price' => number_format($ourPrice,2,'.',''),
                    'expedited-shipping' =>$exped,
                    'item-condition' =>$condition,
                    'location' => $locations,
                    'author' => stripslashes($row['author']),
                    'publisher' => stripslashes($row['publisher']),
                    'condition-id' => $condition,
                    'Cost' => number_format($costs,2,'.',''),
                    'Source' => $source,
                    'pubdate' =>$row['pub_date'],
                    'Media' => $row['binding'],
                    'condition' => $cond,
                    'fulfillment-center-id' => $place,
                        'Original Cost'=>number_format($cost,2,'.',''),
                        'Original Cost2'=>number_format($cost2,2,'.',''),
                        'max new price'=>$maxprice,
                        'max new price2'=>$maxprice2,
                        'NEW MAXPRICE'=>$maxprice3,
                        'created'=>$strip,
                        'conditionCost'=>$conditionCost,
                        'check'=>$check,
                        'Commisi'=>$row['commission_level'],
                        'Usedate'=>$UseDate,
                        'Follett'=>$follett,
                        'FolletNew'=> $follettnew,
                        'Amtext'=>$amtext,
                        'Nebraska' =>$nebraska,
                        'tichenor' => $tich,
                        'sterling'=>$sterling,
                        'bookwinner' =>      $bookWin,
                        'ingram'=> $ingram,
                        'bookbyte'=>$bookbyte,
                        'change'=>$change,
                        'damage'=>$damage,
                        'BookTypeID'=>$bookTypeId,
                    );



        $x++;
        $conn->query("UPDATE inventory SET upload=0 WHERE sku= $sku");
        
        } //END OF WHILE STATEMENT

this runs through a while statement and collects anywhere from 20 to 1,200,000 records (it runs no problem but the change and the cost do not come out they way they should)

any help would be greatly appreciated

Aucun commentaire:

Enregistrer un commentaire