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.
<?php
header('Content-type: text/html; charset=utf-8');
ini_set('display_errors',"1");
ini_set('memory_limit','50000M');
require_once ('../db.php');
$conn = db_connect();
$today = date("Y-m-d");
$now = date("m/d/y h:i:s");
$rejectedSKU = array();
$lowestPrices = array();
$x=0;
$page=1;
$UseDate=date("Y-m-d", strtotime("-6 months",strtotime($today)));
$csvContent = "";
$i = 0;
$conn->query("update inventory set upload = 1 where quantity > 0 and ourPrice > 50 and ourPrice < 100 ");
$update = $conn->query("SELECT sku,i.isbn13,i.quantity,fillzPrice,ourPrice,cost,b.weight,b.title,i.quantity as qty,
book_condition.book_condition,taped.feature AS taped,i.date_created,
book_type.book_text,defect.defect,i.additional_note,i.additional_feature,feature.feature,water.feature AS water,note.note,
fixed,static,location,b.author,publisher,commission_level,follette_title.new_price,follette_title.usedbuying_price,bw.Price AS bwPrice,bw.NewPrice AS newPrice,bb.price AS bytePrice,ingram.price AS ingramPrice,
amtext.price AS aprice,nebraska.price AS nprice,tichenor.price AS tprice,s.price AS sterlingPrice,
feature.book_type_3,i.book_type_id,
buyer_type.buyer_type,source.source, i.source_date, note.book_type_2, i.csmt,i.cu, i.manual,i.taped_id,i.feature_id,
book_type.book_code,water.book_type_4 ,b.pub_date,b.binding
from inventory i
LEFT JOIN book b on i.isbn13 = b.isbn13
LEFT JOIN defect ON i.defect_id = defect.defect_id
LEFT JOIN book_condition ON defect.condition_id = book_condition.condition_id
LEFT JOIN feature ON i.feature_id = feature.feature_id
LEFT JOIN taped on i.taped_id = taped.taped_id
LEFT JOIN water on i.additional_feature = water.feature_id
LEFT JOIN note ON i.note_id = note.note_id
LEFT JOIN location ON i.location_id = location.location_id
LEFT JOIN source ON i.source_id = source.source_id
LEFT JOIN buyer_type ON source.buyer_type_id = buyer_type.buyer_type_id
LEFT JOIN book_type ON i.book_type_id = book_type.book_type_id
LEFT JOIN follette_title ON i.isbn13 = follette_title.isbn13
LEFT JOIN amtext ON i.isbn13 = amtext.isbn13
LEFT JOIN nebraska ON i.isbn13 = nebraska.isbn13
LEFT JOIN tichenor ON i.isbn13 = tichenor.isbn13
LEFT JOIN book_winner AS bw ON i.isbn13 = bw.isbn13
LEFT JOIN bookbyte AS bb ON i.isbn13 = bb.isbn
LEFT JOIN ingram ON i.isbn13 = ingram.isbn
LEFT JOIN sterling AS s ON i.isbn13 = s.isbn13
WHERE i.upload = 1 AND i.ourPrice > 50 and i.ourPrice < 100 AND i.location_id > 0");
while ($row = $update->fetch_assoc()) {
$quantity1 = 0;
$quantity2=$row['quantity'];
$title = str_replace('"','',$row['title']);
$created= $row['date_created'];
$sku = $row['sku'];
$isbn = $row['isbn13'];
$weight = $row['weight'];
$edition = $row['edition'];
$fillz = $row['fillzPrice'];
$ourPrice = $row['ourPrice'];
$cond = $row['book_condition'];
$State = $row['book_condition'];
$damage= $row['Damage'];
$bookTypeId = $row['book_type_id'];
$bookCode = $row['book_code'];
$additional_note = $row['additional_note'];
$feature_feature = $row['feature.feature'];
$taped_feature = $row['taped'];
$additional_feature = $row['additional_feature'];
$location = $row['location'];
$fixed = $row['fixed'];
$static = $row['static'];
$cost = $row['cost'];
$cost2= $row['cost'];
$comm = $row['commission_level'];
$amtext = $row['aprice'];
$follett = $row['usedbuying_price'];
$follettnew = $row['new_price'];
$tich = $row['tprice'];
$nebraska =$row['nprice'] ;
$sterling = $row['sterlingPrice'];
$ingram = $row['ingramPrice'];
$bookbyte = $row['bytePrice'];
$bookWin = $row['bwPrice'];
$newPrice = $row['newPrice'];
$junk=0;
$exped = "y";
$csmt = $row['csmt'];
if($csmt == 1) {
$csmt ="CSMT";
} else {
$csmt = "";
}
$cu = $row['cu'];
if($cu ==1) {
$cu="CU";
} else {
$cu="";
}
if (($row['cu']==1) && ($quantity2>0)) {
if ($maxprice==null){
$maxprice=0;
}
if($maxprice==0){
$cu2=0;
}
}
elseif (($row['cu']==0) && ($quantity2>0)) {
if ((($bookTypeId=="2") || ($bookTypeId=="5") || ($bookTypeId=="6") || ($bookTypeId=="7") || ($tpd == "TPD" )) &&
(($row['book_type_4']!="WATER") || ($cond != "Poor"))){
if ($maxprice2==null){
$maxprice2=0;
}
if ($maxprice2>0){
$cu2=1;
}
}
elseif (($row['book_type_4']!="WATER") || ($cond != "Poor") || ($bookTypeId!="2") || ($bookTypeId!="5") || ($bookTypeId!="6") || ($bookTypeId!="7") || ($tpd != "TPD" )) {
if ($maxprice==null){
$maxprice=0;
}
if ($maxprice>0){
$cu2=1;
}
}
}
if ($cu2==1){
$cu="CU";
}
$manual = $row['manual'];
if($manual == 1){
$manual = "manual";
} else {
$manual = "";
}
$tpd = $row['taped_id'];
$feature_id = $row['feature_id'];
if($tpd==34 || $tpd==35 || $feature_id==34 || $feature_id==35) {
$tpd = "TPD";
}
if($static == 1){
$static = "Static";
} else {
$static = "";
}
$water = $row['water'];
$itemNote = $row['book_text'];
$itemNote .=" " .$row['defect'];
$itemNote .=" " .trim($row['additional_note']);
$itemNote .=" " .$row['feature'];
$itemNote .=" " .$row['taped'];
$itemNote .=" " .$water;
$itemNote .=" " .$row['note'];
$source = $row['buyer_type'];
$source .=$row['source'];
$source .=$row['source_date'];
$source .=$row['book_type_2'];
$source .=$csmt;
$source .=$cu;
$source .=$manual;
$source .=$row['book_code'];
$source .=$row['book_type_4'];
$source .=$tpd;
$source .= $static;
$createDate = new DateTime($created);
$strip = $createDate->format('Y-m-d');
if($weight<3.99) {
$willShip = Y;
} else {
$willShip = N;
}
if($weight>4.8 && (($ourPrice - $cost)<9)) {
$exped = "n";
}
if($fillz == 0){
if($ourPrice < 2.99 && ($weight >=2 && $weight<=2.99)) {
$exped = "n";
}
} elseif (($fillz > 0 && $fillz <2.99) && ($weight >=2 && $weight<=2.99)) {
$exped = "n";
} elseif (($fillz >0 && $fillz <=4.99) && ($weight >=3 && $weight<=8.99)) {
$exped = "n";
} elseif (($fillz >0 && $fillz <=6.49) && ($weight >=9 )) {
$exped = "n";
}
$qty = $conn->query("SELECT quantity FROM qty_skus WHERE sku = $sku LIMIT 1");
$num_row = $qty->num_rows;
if($num_row>0) {
$rows=$qty->fetch_assoc();
$quantity = $rows['quantity'];
$quantity1 = $rows['quantity'];
} else {
$quantity = $row['quantity'];
}
if ($fixed == 1) {
$fixed = "Fixed";
} else {
$fixed = "";
}
$locations = $location;
$locations .= $fixed;
//SWITCH STATEMENT FOR CONDITION
switch ($cond) {
case "New":
$condition = 11;
break;
case "Fine":
$condition = 1;
break;
case "Very Good":
$condition = 2;
break;
case "Good":
$condition = 3;
break;
case "Poor":
$condition = 4;
break;
default:
$condition = 0;
}
if ($strip > $UseDate){
$check='yes';
}
elseif ($strip <= $UseDate){
$check='no';
}
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