Пример #1
0
    UPDATE products AS p SET
        p.normal_price = ?,
        p.special_price = ?,
        p.modified = ?,
        p.specialpricemethod = ?,
        p.specialquantity = ?,
        p.specialgroupprice = ?,
        p.discounttype = ?,
        p.mixmatchcode = ?,
        p.start_date = ?,
        p.end_date = ?
    WHERE p.upc = ?';
/**
  Update all records on each lane before proceeding
  to the next lane. Hopefully faster / more efficient
*/
for ($i = 0; $i < count($FANNIE_LANES); $i++) {
    $lane_sql = new SQLManager($FANNIE_LANES[$i]['host'], $FANNIE_LANES[$i]['type'], $FANNIE_LANES[$i]['op'], $FANNIE_LANES[$i]['user'], $FANNIE_LANES[$i]['pw']);
    if (!isset($lane_sql->connections[$FANNIE_LANES[$i]['op']]) || $lane_sql->connections[$FANNIE_LANES[$i]['op']] === false) {
        // connect failed
        continue;
    }
    $updateP = $lane_sql->prepare($updateQ);
    foreach ($upcs as $upc => $data) {
        $lane_sql->execute($updateP, array($data['normal_price'], $data['special_price'], $data['modified'], $data['specialpricemethod'], $data['specialquantity'], $data['specialgroupprice'], $data['discounttype'], $data['mixmatchcode'], $data['start_date'], $data['end_date'], $upc));
    }
}
$update = new ProdUpdateModel($sql);
$updateType = $batchInfoW['discountType'] == 0 ? ProdUpdateModel::UPDATE_PC_BATCH : ProdUpdateModel::UPDATE_BATCH;
$update->logManyUpdates(array_keys($upcs), $updateType);
echo "Batch {$batchID} has been forced";
Пример #2
0
 function process_file($linedata)
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $idP = $dbc->prepare("\n            SELECT vendorID \n            FROM vendors \n            WHERE vendorName='GARDEN OF LIFE' \n            ORDER BY vendorID");
     $idR = $dbc->execute($idP);
     if ($dbc->num_rows($idR) == 0) {
         $this->error_details = 'Cannot find vendor';
         return false;
     }
     $idW = $dbc->fetchRow($idR);
     $VENDOR_ID = $idW['vendorID'];
     $clean = $dbc->prepare('
         DELETE 
         FROM vendorItems
         WHERE 
         vendorID=?
             AND upc NOT IN (
                 SELECT upc
                 FROM VendorBreakdowns
                 WHERE vendorID=?
             )');
     $dbc->execute($clean, array($VENDOR_ID, $VENDOR_ID));
     $SKU = $this->get_column_index('sku');
     $BRAND = $this->get_column_index('brand');
     $DESCRIPTION = $this->get_column_index('desc');
     $UPC = $this->get_column_index('upc');
     $REG_COST = $this->get_column_index('cost');
     $SIZE = $this->get_column_index('size');
     $TYPE = $this->get_column_index('type');
     $extraP = $dbc->prepare_statement("update prodExtra set cost=? where upc=?");
     $prodP = $dbc->prepare('
         UPDATE products
         SET cost=?,
             modified=' . $dbc->now() . '
         WHERE upc=?
             AND default_vendor_id=?');
     $itemP = $dbc->prepare("\n            INSERT INTO vendorItems (\n                brand, \n                sku,\n                size,\n                upc,\n                units,\n                cost,\n                description,\n                vendorDept,\n                vendorID,\n                saleCost,\n                modified,\n                srp\n            ) VALUES (\n                'GARDEN OF LIFE',\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                0,\n                ?,\n                0,\n                ?,\n                0\n            )");
     $updated_upcs = array();
     $CARTON_PATTERN = '/\\s*\\((\\d+) .+ per carton\\)\\s*/i';
     $TRAY_PATTERN = '/\\s*\\((\\d+) .+\\)\\s*/';
     foreach ($linedata as $data) {
         if (!is_array($data)) {
             continue;
         }
         if (!isset($data[$UPC])) {
             continue;
         }
         // grab data from appropriate columns
         $sku = $SKU !== false ? $data[$SKU] : '';
         $description = $data[$DESCRIPTION];
         $upc = str_replace(' ', '', $data[$UPC]);
         $upc = substr($upc, 0, strlen($upc) - 1);
         $upc = BarcodeLib::padUPC($upc);
         $size = $SIZE !== false ? $data[$SIZE] : '';
         if (is_numeric($size)) {
             $size .= 'CT';
         }
         $type = strtolower($data[$TYPE]);
         $qty = 1;
         // zeroes isn't a real item, skip it
         $reg = trim($data[$REG_COST]);
         // blank spreadsheet cell
         // can't process items w/o price (usually promos/samples anyway)
         if (empty($reg)) {
             continue;
         }
         // syntax fixes. kill apostrophes in text fields,
         // trim $ off amounts as well as commas for the
         // occasional > $1,000 item
         $description = str_replace("'", "", $description);
         $reg = str_replace('$', "", $reg);
         $reg = str_replace(",", "", $reg);
         $reg = trim($reg);
         // skip the item if prices aren't numeric
         // this will catch the 'label' line in the first CSV split
         // since the splits get returned in file system order,
         // we can't be certain *when* that chunk will come up
         if (!is_numeric($reg)) {
             continue;
         }
         $description = preg_replace("/[^-]/", "", $description);
         if ($type == 'tray') {
             if (preg_match($TRAY_PATTERN, $description, $matches)) {
                 $size = $matches[1] . 'CT';
                 $description = preg_replace($TRAY_PATTERN, '', $description);
             } elseif (preg_match('/(\\d+)/', $description, $matches)) {
                 $size = $matches[1] . 'CT';
             }
         } elseif ($type == 'carton') {
             if (preg_match($CARTON_PATTERN, $description, $matches)) {
                 $size = $matches[1] . 'CT';
                 $description = preg_replace($CARTON_PATTERN, '', $description);
             } elseif (preg_match('/(\\d+)/', $description, $matches)) {
                 $size = $matches[1] . 'CT';
             }
         }
         // need unit cost, not case cost
         $reg_unit = $reg / $qty;
         $dbc->execute($extraP, array($reg_unit, $upc));
         $dbc->execute($prodP, array($reg_unit, $upc, $VENDOR_ID));
         $updated_upcs[] = $upc;
         $args = array($sku === false ? '' : $sku, $size === false ? '' : $size, $upc, $qty, $reg_unit, $description, $VENDOR_ID, date('Y-m-d H:i:s'));
         $dbc->execute($itemP, $args);
     }
     $updateModel = new ProdUpdateModel($dbc);
     $updateModel->logManyUpdates($updated_upcs, ProdUpdateModel::UPDATE_EDIT);
     return true;
 }
Пример #3
0
function forceBatch($batchID)
{
    global $sql, $FANNIE_SERVER_DBMS, $FANNIE_LANES;
    $batchInfoQ = $sql->prepare("SELECT batchType,discountType FROM batches WHERE batchID = ?");
    $batchInfoR = $sql->execute($batchInfoQ, array($batchID));
    $batchInfoW = $sql->fetch_array($batchInfoR);
    $forceQ = "";
    $forceLCQ = "";
    $forceMMQ = "";
    if ($batchInfoW['discountType'] != 0) {
        $forceQ = "UPDATE products AS p\n            INNER JOIN batchList AS l\n            ON p.upc=l.upc\n            INNER JOIN batches AS b\n            ON l.batchID=b.batchID\n            SET p.start_date = b.startDate, \n            p.end_date=b.endDate,\n            p.special_price=l.salePrice,\n            p.specialgroupprice=CASE WHEN l.salePrice < 0 THEN -1*l.salePrice ELSE l.salePrice END,\n            p.specialpricemethod=l.pricemethod,\n            p.specialquantity=l.quantity,\n            p.discounttype=b.discounttype,\n            p.mixmatchcode = CASE \n            WHEN l.pricemethod IN (3,4) AND l.salePrice >= 0 THEN convert(l.batchID,char)\n            WHEN l.pricemethod IN (3,4) AND l.salePrice < 0 THEN convert(-1*l.batchID,char)\n            WHEN l.pricemethod = 0 AND l.quantity > 0 THEN concat('b',convert(l.batchID,char))\n            ELSE p.mixmatchcode \n            END    \n            WHERE l.upc not like 'LC%'\n            and l.batchID = ?";
        $forceLCQ = "UPDATE products AS p\n            INNER JOIN upcLike AS v \n            ON v.upc=p.upc\n            INNER JOIN batchList as l \n            ON l.upc=concat('LC',convert(v.likecode,char))\n            INNER JOIN batches AS b \n            ON b.batchID=l.batchID\n            set p.special_price = l.salePrice,\n            p.end_date = b.endDate,p.start_date=b.startDate,\n                p.specialgroupprice=CASE WHEN l.salePrice < 0 THEN -1*l.salePrice ELSE l.salePrice END,\n            p.specialpricemethod=l.pricemethod,\n            p.specialquantity=l.quantity,\n            p.discounttype = b.discounttype,\n                p.mixmatchcode = CASE \n                WHEN l.pricemethod IN (3,4) AND l.salePrice >= 0 THEN convert(l.batchID,char)\n                WHEN l.pricemethod IN (3,4) AND l.salePrice < 0 THEN convert(-1*l.batchID,char)\n                WHEN l.pricemethod = 0 AND l.quantity > 0 THEN concat('b',convert(l.batchID,char))\n                ELSE p.mixmatchcode \n                END    \n            where l.batchID=?";
        if ($FANNIE_SERVER_DBMS == 'MSSQL') {
            $forceQ = "UPDATE products\n                SET start_date = b.startDate, \n                end_date=b.endDate,\n                special_price=l.salePrice,\n                    specialgroupprice=CASE WHEN l.salePrice < 0 THEN -1*l.salePrice ELSE l.salePrice END,\n                specialpricemethod=l.pricemethod,\n                specialquantity=l.quantity,\n                discounttype=b.discounttype,\n                mixmatchcode = CASE \n                WHEN l.pricemethod IN (3,4) AND l.salePrice >= 0 THEN convert(varchar,l.batchID)\n                WHEN l.pricemethod IN (3,4) AND l.salePrice < 0 THEN convert(varchar,-1*l.batchID)\n                WHEN l.pricemethod = 0 AND l.quantity > 0 THEN 'b'+convert(varchar,l.batchID)\n                ELSE p.mixmatchcode \n                END    \n                FROM products as p, \n                batches as b, \n                batchList as l \n                WHERE l.upc = p.upc\n                and l.upc not like 'LC%'\n                and b.batchID = l.batchID\n                and b.batchID = ?";
            $forceLCQ = "update products set special_price = l.salePrice,\n                end_date = b.endDate,start_date=b.startDate,\n                discounttype = b.discounttype,\n                specialpricemethod=l.pricemethod,\n                specialquantity=l.quantity,\n                        specialgroupprice=CASE WHEN l.salePrice < 0 THEN -1*l.salePrice ELSE l.salePrice END,\n                mixmatchcode = CASE \n                    WHEN l.pricemethod IN (3,4) AND l.salePrice >= 0 THEN convert(varchar,l.batchID)\n                    WHEN l.pricemethod IN (3,4) AND l.salePrice < 0 THEN convert(varchar,-1*l.batchID)\n                    WHEN l.pricemethod = 0 AND l.quantity > 0 THEN 'b'+convert(varchar,l.batchID)\n                    ELSE p.mixmatchcode \n                END    \n                from products as p left join\n                upcLike as v on v.upc=p.upc left join\n                batchList as l on l.upc='LC'+convert(varchar,v.likecode)\n                left join batches as b on b.batchID = l.batchID\n                where b.batchID=?";
        }
    } else {
        $forceQ = "UPDATE products AS p\n              INNER JOIN batchList AS l\n              ON l.upc=p.upc\n              SET p.normal_price = l.salePrice,\n              p.modified = now()\n              WHERE l.upc not like 'LC%'\n              AND l.batchID = ?";
        $forceLCQ = "UPDATE products AS p\n            INNER JOIN upcLike AS v\n            ON v.upc=p.upc INNER JOIN\n            batchList as b on b.upc=concat('LC',convert(v.likecode,char))\n            set p.normal_price = b.salePrice,\n               p.modified=now()\n            where b.batchID=?";
        if ($FANNIE_SERVER_DBMS == 'MSSQL') {
            $forceQ = "UPDATE products\n                  SET normal_price = l.salePrice,\n                  modified = getdate()\n                  FROM products as p,\n                  batches as b,\n                  batchList as l\n                  WHERE l.upc = p.upc\n                  AND l.upc not like 'LC%'\n                  AND b.batchID = l.batchID\n                  AND b.batchID = ?";
            $forceLCQ = "update products set normal_price = b.salePrice,\n                modified=getdate()\n                from products as p left join\n                upcLike as v on v.upc=p.upc left join\n                batchList as b on b.upc='LC'+convert(varchar,v.likecode)\n                where b.batchID=?";
        }
    }
    $forceP = $sql->prepare($forceQ);
    $forceR = $sql->execute($forceP, array($batchID));
    $forceLCP = $sql->prepare($forceLCQ);
    $forceLCR = $sql->execute($forceLCP, array($batchID));
    $columnsP = $sql->prepare('
        SELECT p.upc,
            p.normal_price,
            p.special_price,
            p.modified,
            p.specialpricemethod,
            p.specialquantity,
            p.specialgroupprice,
            p.discounttype,
            p.mixmatchcode,
            p.start_date,
            p.end_date
        FROM products AS p
            INNER JOIN batchList AS b ON p.upc=b.upc
        WHERE b.batchID=?');
    $lcColumnsP = $sql->prepare('
        SELECT p.upc,
            p.normal_price,
            p.special_price,
            p.modified,
            p.specialpricemethod,
            p.specialquantity,
            p.specialgroupprice,
            p.discounttype,
            p.mixmatchcode,
            p.start_date,
            p.end_date
        FROM products AS p
            INNER JOIN upcLike AS u ON p.upc=u.upc
            INNER JOIN batchList AS b 
                ON b.upc = ' . $sql->concat("'LC'", $sql->convert('u.likeCode', 'CHAR'), '') . '
        WHERE b.batchID=?');
    /**
      Get changed columns for each product record
    */
    $upcs = array();
    $columnsR = $sql->execute($columnsP, array($batchID));
    while ($w = $sql->fetch_row($columnsR)) {
        $upcs[$w['upc']] = $w;
    }
    $columnsR = $sql->execute($lcColumnsP, array($batchID));
    while ($w = $sql->fetch_row($columnsR)) {
        $upcs[$w['upc']] = $w;
    }
    $updateQ = '
        UPDATE products AS p SET
            p.normal_price = ?,
            p.special_price = ?,
            p.modified = ?,
            p.specialpricemethod = ?,
            p.specialquantity = ?,
            p.specialgroupprice = ?,
            p.discounttype = ?,
            p.mixmatchcode = ?,
            p.start_date = ?,
            p.end_date = ?
        WHERE p.upc = ?';
    /**
      Update all records on each lane before proceeding
      to the next lane. Hopefully faster / more efficient
    */
    for ($i = 0; $i < count($FANNIE_LANES); $i++) {
        $lane_sql = new SQLManager($FANNIE_LANES[$i]['host'], $FANNIE_LANES[$i]['type'], $FANNIE_LANES[$i]['op'], $FANNIE_LANES[$i]['user'], $FANNIE_LANES[$i]['pw']);
        if (!isset($lane_sql->connections[$FANNIE_LANES[$i]['op']]) || $lane_sql->connections[$FANNIE_LANES[$i]['op']] === false) {
            // connect failed
            continue;
        }
        $updateP = $lane_sql->prepare($updateQ);
        foreach ($upcs as $upc => $data) {
            $lane_sql->execute($updateP, array($data['normal_price'], $data['special_price'], $data['modified'], $data['specialpricemethod'], $data['specialquantity'], $data['specialgroupprice'], $data['discounttype'], $data['mixmatchcode'], $data['start_date'], $data['end_date'], $upc));
        }
    }
    $update = new ProdUpdateModel($sql);
    $updateType = $batchInfoW['discountType'] == 0 ? ProdUpdateModel::UPDATE_PC_BATCH : ProdUpdateModel::UPDATE_BATCH;
    $update->logManyUpdates(array_keys($upcs), $updateType);
}
Пример #4
0
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $idP = $dbc->prepare_statement("SELECT vendorID FROM vendors WHERE vendorName='UNFI' ORDER BY vendorID");
     $idR = $dbc->exec_statement($idP);
     if ($dbc->num_rows($idR) == 0) {
         $this->error_details = 'Cannot find vendor';
         return False;
     }
     $idW = $dbc->fetchRow($idR);
     $VENDOR_ID = $idW['vendorID'];
     $SKU = $this->get_column_index('sku');
     $BRAND = $this->get_column_index('brand');
     $DESCRIPTION = $this->get_column_index('desc');
     $QTY = $this->get_column_index('qty');
     $SIZE1 = $this->get_column_index('size');
     $UPC = $this->get_column_index('upc');
     $CATEGORY = $this->get_column_index('cat');
     $REG_COST = $this->get_column_index('cost');
     $NET_COST = $this->get_column_index('saleCost');
     $SRP = $this->get_column_index('srp');
     $FLAGS = $this->get_column_index('flags');
     // PLU items have different internal UPCs
     // map vendor SKUs to the internal PLUs
     $SKU_TO_PLU_MAP = array();
     $skusP = $dbc->prepare_statement('SELECT sku, upc FROM vendorSKUtoPLU WHERE vendorID=?');
     $skusR = $dbc->execute($skusP, array($VENDOR_ID));
     while ($skusW = $dbc->fetch_row($skusR)) {
         $SKU_TO_PLU_MAP[$skusW['sku']] = $skusW['upc'];
     }
     $extraP = $dbc->prepare_statement("update prodExtra set cost=? where upc=?");
     $prodP = $dbc->prepare('
         UPDATE products
         SET cost=?,
             numflag= numflag | ? | ?,
             modified=' . $dbc->now() . '
         WHERE upc=?
             AND default_vendor_id=?');
     $itemP = $dbc->prepare("\n            INSERT INTO vendorItems (\n                brand, \n                sku,\n                size,\n                upc,\n                units,\n                cost,\n                description,\n                vendorDept,\n                vendorID,\n                saleCost,\n                modified,\n                srp\n            ) VALUES (\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?\n            )");
     $srpP = false;
     if ($dbc->tableExists('vendorSRPs')) {
         $srpP = $dbc->prepare_statement("INSERT INTO vendorSRPs (vendorID, upc, srp) VALUES (?,?,?)");
     }
     $updated_upcs = array();
     $rounder = new \COREPOS\Fannie\API\item\PriceRounder();
     foreach ($linedata as $data) {
         if (!is_array($data)) {
             continue;
         }
         if (!isset($data[$UPC])) {
             continue;
         }
         // grab data from appropriate columns
         $sku = $SKU !== false ? $data[$SKU] : '';
         $sku = str_pad($sku, 7, '0', STR_PAD_LEFT);
         $brand = $data[$BRAND];
         $description = $data[$DESCRIPTION];
         $qty = $data[$QTY];
         $size = $SIZE1 !== false ? $data[$SIZE1] : '';
         $prodInfo = $FLAGS !== false ? $data[$FLAGS] : '';
         $flag = 0;
         $upc = substr($data[$UPC], 0, 13);
         // zeroes isn't a real item, skip it
         if ($upc == "0000000000000") {
             continue;
         }
         if (isset($SKU_TO_PLU_MAP[$sku])) {
             $upc = $SKU_TO_PLU_MAP[$sku];
             if (substr($size, -1) == '#' && substr($upc, 0, 3) == '002') {
                 $qty = trim($size, '# ');
                 $size = '#';
             } elseif (substr($size, -2) == 'LB' && substr($upc, 0, 3) == '002') {
                 $qty = trim($size, 'LB ');
                 $size = 'LB';
             }
         }
         $category = $data[$CATEGORY];
         $reg = trim($data[$REG_COST]);
         $net = $NET_COST !== false ? trim($data[$NET_COST]) : 0.0;
         // blank spreadsheet cell
         if (empty($net)) {
             $net = 0;
         }
         $srp = trim($data[$SRP]);
         // can't process items w/o price (usually promos/samples anyway)
         if (empty($reg) or empty($srp)) {
             continue;
         }
         // syntax fixes. kill apostrophes in text fields,
         // trim $ off amounts as well as commas for the
         // occasional > $1,000 item
         $brand = str_replace("'", "", $brand);
         $description = str_replace("'", "", $description);
         $reg = str_replace('$', "", $reg);
         $reg = str_replace(",", "", $reg);
         $net = str_replace('$', "", $net);
         $net = str_replace(",", "", $net);
         $srp = str_replace('$', "", $srp);
         $srp = str_replace(",", "", $srp);
         // sale price isn't really a discount
         if ($reg == $net) {
             $net = 0;
         }
         // skip the item if prices aren't numeric
         // this will catch the 'label' line in the first CSV split
         // since the splits get returned in file system order,
         // we can't be certain *when* that chunk will come up
         if (!is_numeric($reg) or !is_numeric($srp)) {
             continue;
         }
         $srp = $rounder->round($srp);
         // set organic flag on OG1 (100%) or OG2 (95%)
         $organic_flag = 0;
         if (strstr($prodInfo, 'OG2') || strstr($prodInfo, 'OG1')) {
             $organic_flag = 17;
         }
         // set gluten-free flag on g
         $gf_flag = 0;
         if (strstr($prodInfo, 'g')) {
             $gf_flag = 18;
         }
         // need unit cost, not case cost
         $reg_unit = $reg / $qty;
         $net_unit = $net / $qty;
         $dbc->exec_statement($extraP, array($reg_unit, $upc));
         $dbc->exec_statement($prodP, array($reg_unit, $organic_flag, $gf_flag, $upc, $VENDOR_ID));
         $updated_upcs[] = $upc;
         $args = array($brand, $sku === false ? '' : $sku, $size === false ? '' : $size, $upc, $qty, $reg_unit, $description, $category, $VENDOR_ID, $net_unit, date('Y-m-d H:i:s'), $srp);
         $dbc->execute($itemP, $args);
         if ($srpP) {
             $dbc->exec_statement($srpP, array($VENDOR_ID, $upc, $srp));
         }
     }
     $updateModel = new ProdUpdateModel($dbc);
     $updateModel->logManyUpdates($updated_upcs, ProdUpdateModel::UPDATE_EDIT);
     return true;
 }
Пример #5
0
 /**
   Cleanup after forcibly starting or stopping a sales batch
   - Update lane item records to reflect on/off sale
   - Log changes to prodUpdate
   @param $id [int] batchID
   @param $updateType [cost] ProdUpdateModel update type
   @param $has_limit [boolean] products.special_limit and batches.transLimit
     columns are present
   
   Separate method since it's identical for starting
   and stopping  
 */
 private function finishForce($id, $updateType, $has_limit = true)
 {
     $columnsP = $this->connection->prepare('
         SELECT p.upc,
             p.normal_price,
             p.special_price,
             p.modified,
             p.specialpricemethod,
             p.specialquantity,
             p.specialgroupprice,
             ' . ($has_limit ? 'p.special_limit,' : '') . '
             p.discounttype,
             p.mixmatchcode,
             p.start_date,
             p.end_date
         FROM products AS p
             INNER JOIN batchList AS b ON p.upc=b.upc
         WHERE b.batchID=?');
     $lcColumnsP = $this->connection->prepare('
         SELECT p.upc,
             p.normal_price,
             p.special_price,
             p.modified,
             p.specialpricemethod,
             p.specialquantity,
             p.specialgroupprice,
             ' . ($has_limit ? 'p.special_limit,' : '') . '
             p.discounttype,
             p.mixmatchcode,
             p.start_date,
             p.end_date
         FROM products AS p
             INNER JOIN upcLike AS u ON p.upc=u.upc
             INNER JOIN batchList AS b 
                 ON b.upc = ' . $this->connection->concat("'LC'", $this->connection->convert('u.likeCode', 'CHAR'), '') . '
         WHERE b.batchID=?');
     /**
       Get changed columns for each product record
     */
     $upcs = array();
     $columnsR = $this->connection->execute($columnsP, array($id));
     while ($w = $this->connection->fetch_row($columnsR)) {
         $upcs[$w['upc']] = $w;
     }
     $columnsR = $this->connection->execute($lcColumnsP, array($id));
     while ($w = $this->connection->fetch_row($columnsR)) {
         $upcs[$w['upc']] = $w;
     }
     $updateQ = '
         UPDATE products AS p SET
             p.normal_price = ?,
             p.special_price = ?,
             p.modified = ?,
             p.specialpricemethod = ?,
             p.specialquantity = ?,
             p.specialgroupprice = ?,
             p.discounttype = ?,
             p.mixmatchcode = ?,
             p.start_date = ?,
             p.end_date = ?
             ' . ($has_limit ? ',p.special_limit = ?' : '') . '
         WHERE p.upc = ?';
     /**
       Update all records on each lane before proceeding
       to the next lane. Hopefully faster / more efficient
     */
     $FANNIE_LANES = FannieConfig::config('LANES');
     for ($i = 0; $i < count($FANNIE_LANES); $i++) {
         $lane_sql = new SQLManager($FANNIE_LANES[$i]['host'], $FANNIE_LANES[$i]['type'], $FANNIE_LANES[$i]['op'], $FANNIE_LANES[$i]['user'], $FANNIE_LANES[$i]['pw']);
         if (!isset($lane_sql->connections[$FANNIE_LANES[$i]['op']]) || $lane_sql->connections[$FANNIE_LANES[$i]['op']] === false) {
             // connect failed
             continue;
         }
         $updateP = $lane_sql->prepare($updateQ);
         foreach ($upcs as $upc => $data) {
             $args = array($data['normal_price'], $data['special_price'], $data['modified'], $data['specialpricemethod'], $data['specialquantity'], $data['specialgroupprice'], $data['discounttype'], $data['mixmatchcode'], $data['start_date'], $data['end_date']);
             if ($has_limit) {
                 $args[] = $data['special_limit'];
             }
             $args[] = $upc;
             $lane_sql->execute($updateP, $args);
         }
     }
     $update = new ProdUpdateModel($this->connection);
     $update->logManyUpdates(array_keys($upcs), $updateType);
 }
Пример #6
0
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $idP = $dbc->prepare_statement("SELECT vendorID FROM vendors WHERE vendorName='UNFI' ORDER BY vendorID");
     $VENDOR_ID = $dbc->getValue($idP);
     if ($VENDOR_ID === false) {
         $this->error_details = 'Cannot find vendor';
         return False;
     }
     $VENDOR_ID = $idW['vendorID'];
     $ruleType = FormLib::get('ruleType');
     $review = FormLib::get('reviewDate');
     $SKU = $this->get_column_index('sku');
     $QTY = $this->get_column_index('qty');
     $UPC = $this->get_column_index('upc');
     $REG_COST = $this->get_column_index('cost');
     $NET_COST = $this->get_column_index('saleCost');
     $SRP = $this->get_column_index('srp');
     // PLU items have different internal UPCs
     // map vendor SKUs to the internal PLUs
     $SKU_TO_PLU_MAP = array();
     $skusP = $dbc->prepare_statement('SELECT sku, upc FROM vendorSKUtoPLU WHERE vendorID=?');
     $skusR = $dbc->execute($skusP, array($VENDOR_ID));
     while ($skusW = $dbc->fetch_row($skusR)) {
         $SKU_TO_PLU_MAP[$skusW['sku']] = $skusW['upc'];
     }
     $extraP = $dbc->prepare_statement("update prodExtra set cost=?,variable_pricing=1 where upc=?");
     $prodP = $dbc->prepare('
         UPDATE products
         SET cost=?,
             modified=' . $dbc->now() . '
         WHERE upc=?
             AND default_vendor_id=?');
     $itemP = $dbc->prepare('
         UPDATE vendorItems
         SET cost=?,
             saleCost=?,
             srp=?,
             modified=?
         WHERE sku=?
             AND vendorID=?');
     $srpP = false;
     if ($dbc->tableExists('vendorSRPs')) {
         $srpP = $dbc->prepare_statement("INSERT INTO vendorSRPs (vendorID, upc, srp) VALUES (?,?,?)");
     }
     $updated_upcs = array();
     $upcP = $dbc->prepare('SELECT price_rule_id FROM products WHERE upc=? AND inUse=1');
     $ruleP = $dbc->prepare('SELECT * FROM PriceRules WHERE priceRuleID=?');
     $ruleInsP = $dbc->prepare('
         INSERT INTO PriceRules 
             (priceRuleTypeID, maxPrice, reviewDate, details)
         VALUES 
             (?, ?, ?, ?)
     ');
     $ruleUpP = $dbc->prepare('
         UPDATE PriceRules
         SET priceRuleTypeID=?,
             maxPrice=?,
             reviewDate=?,
             details=?
         WHERE priceRuleID=?');
     $prodRuleP = $dbc->prepare('UPDATE products SET price_rule_id=? WHERE upc=?');
     foreach ($linedata as $data) {
         if (!is_array($data)) {
             continue;
         }
         if (!isset($data[$UPC])) {
             continue;
         }
         // grab data from appropriate columns
         $sku = $SKU !== false ? $data[$SKU] : '';
         $sku = str_pad($sku, 7, '0', STR_PAD_LEFT);
         $qty = $data[$QTY];
         $upc = substr($data[$UPC], 0, 13);
         // zeroes isn't a real item, skip it
         if ($upc == "0000000000000") {
             continue;
         }
         if (isset($SKU_TO_PLU_MAP[$sku])) {
             $upc = $SKU_TO_PLU_MAP[$sku];
             if (substr($size, -1) == '#' && substr($upc, 0, 3) == '002') {
                 $qty = trim($size, '# ');
             } elseif (substr($size, -2) == 'LB' && substr($upc, 0, 3) == '002') {
                 $qty = trim($size, 'LB ');
             }
         }
         $reg = trim($data[$REG_COST]);
         $net = $NET_COST !== false ? trim($data[$NET_COST]) : 0.0;
         // blank spreadsheet cell
         if (empty($net)) {
             $net = 0;
         }
         $srp = trim($data[$SRP]);
         // can't process items w/o price (usually promos/samples anyway)
         if (empty($reg) or empty($srp)) {
             continue;
         }
         // syntax fixes. kill apostrophes in text fields,
         // trim $ off amounts as well as commas for the
         // occasional > $1,000 item
         $reg = str_replace('$', "", $reg);
         $reg = str_replace(",", "", $reg);
         $net = str_replace('$', "", $net);
         $net = str_replace(",", "", $net);
         $srp = str_replace('$', "", $srp);
         $srp = str_replace(",", "", $srp);
         // sale price isn't really a discount
         if ($reg == $net) {
             $net = 0;
         }
         // skip the item if prices aren't numeric
         // this will catch the 'label' line in the first CSV split
         // since the splits get returned in file system order,
         // we can't be certain *when* that chunk will come up
         if (!is_numeric($reg) or !is_numeric($srp)) {
             continue;
         }
         // need unit cost, not case cost
         $reg_unit = $reg / $qty;
         $net_unit = $net / $qty;
         $dbc->exec_statement($extraP, array($reg_unit, $upc));
         $dbc->exec_statement($prodP, array($reg_unit, $upc, $VENDOR_ID));
         $updated_upcs[] = $upc;
         $args = array($reg_unit, $net_unit, $srp, date('Y-m-d H:i:s'), $sku, $VENDOR_ID);
         $dbc->execute($itemP, $args);
         if ($srpP) {
             $dbc->exec_statement($srpP, array($VENDOR_ID, $upc, $srp));
         }
         $rule_id = $dbc->getValue($upcP, array($upc));
         $ruleR = $dbc->execute($ruleP, array($rule_id));
         if ($rule_id > 1 && $dbc->numRows($ruleR)) {
             // update existing rule with latest price
             $args = array($ruleType, $srp, $review, 'NCG MAX ' . $srp, $rule_id);
             $dbc->execute($ruleUpP, $args);
         } else {
             // create a new pricing rule
             // attach it to the item
             $args = array($ruleType, $srp, $review, 'NCG MAX ' . $srp);
             $dbc->execute($ruleInsP, $args);
             $rule_id = $dbc->insertID();
             $dbc->execute($prodRuleP, array($rule_id, $upc));
         }
     }
     $updateModel = new ProdUpdateModel($dbc);
     $updateModel->logManyUpdates($updated_upcs, ProdUpdateModel::UPDATE_EDIT);
     return true;
 }