Example #1
0
/**
 * Insert or update the quickbooks_items table with the provided values.
 * Note: the nutrition_label_id and quickbooks_item_supplement_id field are both given the value of the provided.
 * @return 
 * @param $id String id of the item.
 * @param $description String
 * @param $price Decimal
 * @param $upc String
 * @param $grossWeightLb Decimal
 * @param $pack Integer
 * @param $unitWeightG Decimal
 * @param $caseCube Decimal
 * @param $uniqueInstructions String
 */
function insertOrUpdateQuickBooksItem($id, $description, $price, $upc, $grossWeightLb, $pack, $unitWeightG, $caseCube, $uniqueInstructions)
{
    global $GRAMS_PER_OUNCE;
    echo "\tInserting/updating QuickBooks item:\n";
    echoWithIndentAndCutoff("id", $id, "\t\t", 100);
    echoWithIndentAndCutoff("description", $description, "\t\t", 100);
    echoWithIndentAndCutoff("price", $price, "\t\t", 100);
    echoWithIndentAndCutoff("upc", $upc, "\t\t", 100);
    echoWithIndentAndCutoff("grossWeightLb", $grossWeightLb, "\t\t", 100);
    echoWithIndentAndCutoff("pack", $pack, "\t\t", 100);
    // The gross weight in ounces is not provided to this function, but we can calculate it from the gross weight in grams.
    $unitWeightOz = $unitWeightG / $GRAMS_PER_OUNCE;
    echoWithIndentAndCutoff("unitWeightOz", $unitWeightOz, "\t\t", 100);
    echoWithIndentAndCutoff("unitWeightG", $unitWeightG, "\t\t", 100);
    echoWithIndentAndCutoff("caseCube", $caseCube, "\t\t", 100);
    echoWithIndentAndCutoff("uniqueInstructions", $uniqueInstructions, "\t\t", 100);
    $itemId = mysql_real_escape_string($id);
    $description = mysql_real_escape_string($description);
    $price = mysql_real_escape_string($price);
    $upc = mysql_real_escape_string($upc);
    $grossWeightLb = mysql_real_escape_string($grossWeightLb);
    $pack = mysql_real_escape_string($pack);
    $unitWeightOz = mysql_real_escape_string($unitWeightOz);
    $unitWeightG = mysql_real_escape_string($unitWeightG);
    $caseCube = mysql_real_escape_string($caseCube);
    $caseCube = empty($caseCube) ? 'null' : $caseCube;
    $uniqueInstructions = mysql_real_escape_string($uniqueInstructions);
    // see if there's a quickbooks_item with this ide
    $quickBooksItemIdQuery = "SELECT id " . "FROM quickbooks_items " . "WHERE id = '{$id}'";
    $result = queryDb($quickBooksItemIdQuery);
    if (mysql_num_rows($result) == 0) {
        // quickbooks_item with this id doesn't exist
        $insertQuery = "INSERT INTO quickbooks_items " . "(id, description, price, upc, gross_weight_lb, pack, unit_weight_oz, unit_weight_g, case_cube, unique_instructions) " . "VALUES " . "('{$id}', '{$description}', {$price}, '{$upc}', {$grossWeightLb}, {$pack}, {$unitWeightOz}, {$unitWeightG}, {$caseCube}, '{$uniqueInstructions}')";
        queryDb($insertQuery);
    } else {
        // a quickbooks_item with this id already exists
        $updateQuery = "UPDATE quickbooks_items " . "SET description='{$description}', \n\t\t\t\t     price={$price}, upc='{$upc}', \n\t\t\t\t\t gross_weight_lb={$grossWeightLb}, \n\t\t\t\t\t pack={$pack}, \n\t\t\t\t\t unit_weight_oz={$unitWeightOz},\n\t\t\t\t\t unit_weight_g={$unitWeightG},\n\t\t\t\t\t case_cube={$caseCube},\n\t\t\t\t\t unique_instructions='{$uniqueInstructions}' " . "WHERE id='{$id}'";
        queryDb($updateQuery);
    }
}
Example #2
0
        $a = array();
        $a['conf_key'] = 'temperature_override';
        $a['conf_value'] = "{$new_temp}";
        $json = json_encode($a);
        queryDb('PUT', '/rest/configuration/' . $id, $json);
        echo $new_temp;
    }
    if (isset($_POST['change_configuration'])) {
        $output = queryDb('GET', '/rest/configuration?where=conf_key==' . $_POST['conf_key'], false);
        $conf_value = $output['_items'][0]['conf_value'];
        $id = $output['_items'][0]['_id'];
        $a = array();
        $a['conf_key'] = $_POST['conf_key'];
        $a['conf_value'] = $_POST['conf_value'];
        $json = json_encode($a);
        queryDb('PUT', '/rest/configuration/' . $id, $json);
    }
}
function queryDb($method, $end, $data)
{
    try {
        $url = 'http://localhost' . $end;
        $ch = curl_init();
        switch ($method) {
            case 'GET':
                curl_setopt($ch, CURLOPT_URL, "{$url}");
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                break;
            case 'POST':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
Example #3
0
/**
 * Insert or update the inventory_items table with the provided values.
 * @return 
 * @param $id String id of the item.
 * @param $description String
 * @param $unitOfMeasure String
 * @param $qtyOnHand Int
 * @param $qtyOnPO Int
 * @param $reorderPoint Int
 * @param $recipeDescription Text
 * @param $activeStatus Bit
 */
function insertOrUpdateInventoryItem($id, $description, $unitOfMeasure, $qtyOnHand, $qtyOnPO, $reorderPoint, $recipeDescription, $activeStatus)
{
    echo "\tInserting/updating Inventory item:\n";
    echoWithIndentAndCutoff("id", $id, "\t\t", 100);
    echoWithIndentAndCutoff("description", $description, "\t\t", 100);
    echoWithIndentAndCutoff("unit of measure", $unitOfMeasure, "\t\t", 100);
    echoWithIndentAndCutoff("qty on hand", $qtyOnHand, "\t\t", 100);
    echoWithIndentAndCutoff("qty on PO", $qtyOnPO, "\t\t", 100);
    echoWithIndentAndCutoff("Reorder Point", $reorderPoint, "\t\t", 100);
    echoWithIndentAndCutoff("Recipe Description", $recipeDescription, "\t\t", 100);
    echoWithIndentAndCutoff("Active Status", $activeStatus, "\t\t", 100);
    $itemId = mysql_real_escape_string($id);
    $description = mysql_real_escape_string($description);
    $unitOfMeasure = mysql_real_escape_string($unitOfMeasure);
    $qtyOnHand = mysql_real_escape_string($qtyOnHand);
    $qtyOnPO = mysql_real_escape_string($qtyOnPO);
    $reorderPoint = mysql_real_escape_string($reorderPoint);
    $recipeDescription = mysql_real_escape_string($recipeDescription);
    $activeStatus = mysql_real_escape_string($activeStatus);
    // see if there's a quickbooks_item with this ide
    $inventoryItemIdQuery = "SELECT id " . "FROM inventory_items " . "WHERE id = '{$id}'";
    $result = queryDb($inventoryItemIdQuery);
    if (mysql_num_rows($result) == 0) {
        // inventory_item with this id doesn't exist
        $insertQuery = "INSERT INTO inventory_items " . "(id, description, unit_of_measure, qty_on_hand, qty_on_PO, reorder_point, recipe_description, active_status) " . "VALUES " . "('{$id}', '{$description}', '{$unitOfMeasure}', '{$qtyOnHand}', '{$qtyOnPO}', '{$reorderPoint}', '{$recipeDescription}', '{$activeStatus}')";
        queryDb($insertQuery);
    } else {
        // an inventory_item with this id already exists
        $updateQuery = "UPDATE inventory_items " . "SET description='{$description}',\n\t\t\t\t\t unit_of_measure='{$unitOfMeasure}',\n\t\t\t\t\t qty_on_hand='{$qtyOnHand}',\n\t\t\t\t\t qty_on_PO='{$qtyOnPO}',\n\t\t\t\t\t reorder_point='{$reorderPoint}',\n\t\t\t\t\t recipe_description='{$recipeDescription}',\n\t\t\t\t\t active_status='{$activeStatus}' " . "WHERE id='{$id}'";
        queryDb($updateQuery);
    }
}
Example #4
0
 function deleteDbVars($clause = "", $id = -1)
 {
     include_once "db_funcs.php";
     $link = openDb();
     if (isset($clause) && $clause != "") {
         $query = "DELETE FROM {$this->name} where {$clause} ";
     } else {
         if ($id != -1) {
             $id_name = $this->getIdName();
             $query = "DELETE FROM {$this->name} where {$id_name} = {$id}";
         }
     }
     $result = queryDb($link, $query);
     closeDb($link);
     return $result;
 }
<?php

include_once "config.php";
include_once "functions.php";
$query = "SELECT * FROM movies";
$result = queryDb($conn, $query);
$movies = [];
if ($result) {
    //echo( "<br><br>The query returned the following results: <br>" );
    while ($row = mysqli_fetch_assoc($result)) {
        $movies[] = $row["name"];
        //echo "<br>Imdb-ID: " . $row["imdb_id"]. " - Movie name: " . $row["name"]. " - Year: " . $row["year"];
    }
    echo json_encode($movies);
}
function testRule($ruleName)
{
    global $isDev;
    global $allRulesSql;
    if (!$isDev) {
        echo "<span style=\"color: red\">Rule test unavailable: prototype was not generated with <tt>--dev</tt> option.</span>";
        return;
    }
    if (!$allRulesSql[$ruleName]) {
        echo "<span style=\"color: red\">Error: rule \"{$ruleName}\" does not exist.</span>";
        return;
    }
    echo "<a href=\"../Installer.php\" style=\"float:right\">Reset database</a>";
    echo "<h2>Testing rule {$ruleName}</h2>";
    $ruleSql = $allRulesSql[$ruleName];
    $ruleAdl = escapeHtmlAttrStr($ruleSql['ruleAdl']);
    echo "<b>ADL:</b>&nbsp;<tt style=\"color:blue\">{$ruleAdl}</tt><h4>Rule SQL</h4><pre>{$ruleSql['contentsSQL']}</pre><h4>results</h4>";
    $error = '';
    $rows = queryDb($ruleSql['contentsSQL'], $error);
    printBinaryTable($rows);
    echo "<h4>Rule violations SQL</h4><pre>{$ruleSql['violationsSQL']}</pre><h4>results</h4>";
    $rows = queryDb($ruleSql['violationsSQL'], $error);
    printBinaryTable($rows);
}
function DelPair($relation, $srcConcept, $srcAtom, $tgtConcept, $tgtAtom)
{
    if ($srcAtom === "") {
        ExecEngineSHOUTS("DelPair: srcAtom is empty string.");
    }
    if ($srcAtom === "") {
        ExecEngineSHOUTS("DelPair: tgtAtom is empty string.");
    }
    /* 
    $relationTableInfo from Generics.php 
    contains array with all relations, for each relation the following is specified: 
     - srcConcept : srcConcept of relation
     - tgtConcept : tgtConcept of relation
     - table : database table in which the relation is populated
     - srcCol : column of database table in which the srcConcept is placed
     - tgtCol : column of database table in which the tgtConcept is placed
    */
    global $relationTableInfo;
    /* 
    $tableColumInfo from Generics.php 
    contains array with all database tables and their columns, for each tablecolumn the following is specified: 
     - concept : the atoms of which concept are set here
     - unique : whether or not the value in the column must be unique. 'true' for properties
     - null   : whether or not the value in the column can be NULL. in case of UNI relations
    */
    global $tableColumnInfo;
    // check if $relation appears in $relationTableInfo
    $found = false;
    foreach ($relationTableInfo as $key => $arr) {
        if ($key == "rel_" . $relation . "_" . $srcConcept . "_" . $tgtConcept) {
            $found = true;
            $table = $arr['table'];
            $srcCol = $arr['srcCol'];
            $tgtCol = $arr['tgtCol'];
        }
    }
    if (!$found) {
        // Errors in ADL script may corrupt the database, so we die (leaving a suicide note)
        ExecEngineSHOUTS("ERROR: Cannot find {$relation}\\[{$srcConcept}\\*{$tgtConcept}\\] signature.");
        ExecEngineSays("DelPair({$relation},{$srcConcept},{$srcAtom},{$tgtConcept},{$tgtAtom})");
        ExecEngineSays("If you have defined this relation in Ampersand, then you must be sure to also have defined an INTERFACE that uses this relation (or else it does not show up in the PHP relation administration.");
        die;
    }
    // get table column properties for $srcCol and $tgtCol
    $srcColUnique = $tableColumnInfo[$table][$srcCol]['unique'];
    $srcColNull = $tableColumnInfo[$table][$srcCol]['null'];
    $tgtColUnique = $tableColumnInfo[$table][$tgtCol]['unique'];
    $tgtColNull = $tableColumnInfo[$table][$tgtCol]['null'];
    // SQL escape table, column and atom names
    $tableEsc = escapeSQL($table);
    $srcColEsc = escapeSQL($srcCol);
    $tgtColEsc = escapeSQL($tgtCol);
    $srcAtomEsc = escapeSQL($srcAtom);
    $tgtAtomEsc = escapeSQL($tgtAtom);
    // generate database query
    if ($srcColNull xor $tgtColNull) {
        if ($srcColNull) {
            $query = "UPDATE `{$tableEsc}` SET `{$srcColEsc}`=NULL WHERE `{$srcColEsc}`='{$srcAtomEsc}' AND `{$tgtColEsc}`='{$tgtAtomEsc}'";
        } else {
            $query = "UPDATE `{$tableEsc}` SET `{$tgtColEsc}`=NULL WHERE `{$srcColEsc}`='{$srcAtomEsc}' AND `{$tgtColEsc}`='{$tgtAtomEsc}'";
        }
    } elseif ($srcColNull and $tgtColNull) {
        $query = "DELETE FROM `{$tableEsc}` WHERE `{$srcColEsc}`='{$srcAtomEsc}' AND `{$tgtColEsc}`='{$tgtAtomEsc}';";
    } else {
        // neither srcCol nor tgtCol can be null ==> delete query
        $query = "DELETE FROM `{$tableEsc}` WHERE `{$srcColEsc}`='{$srcAtomEsc}' AND `{$tgtColEsc}`='{$tgtAtomEsc}';";
    }
    // execute database query
    queryDb($query);
    // log
    ExecEngineWhispers("Delete pair ({$srcAtom},{$tgtAtom}) from {$relation}({$srcConcept}*{$tgtConcept})");
    emitLog("DelPair({$relation},{$srcConcept},{$srcAtom},{$tgtConcept},{$tgtAtom})");
    emitLog($query);
}
Example #8
0
    echo "{$id} doesn't have a valid idBase";
    return;
}
// Note: this is vulnerable to abuse,
// as someone could construct a URL with arbitrary HTML, and we would create a PDF out of it.
if (!isset($_POST["html"])) {
    echo "HTML was not sent to generate a PDF.";
    return;
}
// Since we'll be sending this HTML to a web-service, we need to make sure slashes haven't been added.
$html = get_magic_quotes_gpc() ? stripslashes($_POST["html"]) : $_POST["html"];
// quickbook_item_supplements
$sizeKey = "size";
$productTypeKey = "productType";
$query = createSqlQuery("SELECT qbis.size as '{$sizeKey}'", ", qbis.product_type as '{$productTypeKey}'", "FROM quickbooks_item_supplements qbis", "WHERE qbis.id LIKE '{$idBase}-%'");
$result = queryDb($query);
if (mysql_num_rows($result) == 0) {
    // quickbooks_item_supplements with this id doesn't exist
    echo "No information for products with id base: {$idBase}.";
    return;
}
$row = mysql_fetch_assoc($result);
$productType = $row[$productTypeKey];
$size = $row[$sizeKey];
$htmlForPdfPath = getHtmlForPdfPath($productType, $size);
mkFileDirs($htmlForPdfPath);
file_put_contents($htmlForPdfPath, $html);
$htmlForPdfUrl = "http://" . $_SERVER['SERVER_NAME'] . "/" . getDirectoryPathFromRoot(__FILE__) . "/{$htmlForPdfPath}";
$pdfPath = getPdfPath($productType, $size);
$tmpPdfPath = $pdfPath . ".tmp";
if (!convertToPdf($htmlForPdfUrl, $tmpPdfPath, $errorMessage)) {
Example #9
0
/**
 * Inserts or updates a nutrition label for the provided $itemIdBase with provided values.
 * @return nothing returned
 * @param $itemIdBase String id of the quickbooks item id base this nutrition label is for
 * @param $usLabelImageId int id of the US label in the images table.
 * @param $cdnLabelImageId int id of the Canadian label in the images table.  Can be null.
 * @param $ingredientsText String the ingredients text for the label.
 * @param $allergensText String the allergens text for the label.
 */
function insertOrUpdateNutritionLabel($itemIdBase, $usLabelImageId, $cdnLabelImageId, $ingredientsText, $allergensText)
{
    // if the Canadian label is empty, set it to the string of null value for updating the database
    if (is_null($cdnLabelImageId)) {
        $cdnLabelImageId = 'null';
    }
    $ingredientsText = mysql_real_escape_string(trim($ingredientsText));
    $allergensText = mysql_real_escape_string(trim($allergensText));
    echo "\tInserting/updating nutrion label:\n";
    $columnValuePairs = array("id" => "'{$itemIdBase}'", "us_label_image_id" => $usLabelImageId, "cdn_label_image_id" => $cdnLabelImageId, "ingredients" => "'{$ingredientsText}'", "allergens" => "'{$allergensText}'");
    foreach ($columnValuePairs as $column => $value) {
        echoWithIndentAndCutoff($column, $value, "\t\t", 100);
    }
    // determine whether we have a nutrition label for the provided it
    $nutritionLabelIdQuery = createSqlQuery("SELECT id", "FROM nutrition_labels", "WHERE id = '{$itemIdBase}'");
    $result = queryDb($nutritionLabelIdQuery);
    if (mysql_num_rows($result) == 0) {
        // we don't have a label for this id
        if (empty($itemIdBase) || empty($usLabelImageId) || empty($ingredientsText) || empty($allergensText)) {
            echo "\t\tRequired value is missing.  Skipping...\n";
        }
        $insertQuery = createSqlInsertQuery("nutrition_labels", $columnValuePairs);
        queryDb($insertQuery);
    } else {
        // a nutrition label with this itemIdBase already exists
        $updateQuery = createSqlQuery("UPDATE nutrition_labels", createSqlSetString($columnValuePairs), "WHERE id='{$itemIdBase}'");
        queryDb($updateQuery);
    }
}
Example #10
0
    if (doesProductImageExist($productType, $size, $idBase, "CaseLabel")) {
        array_push($imageFilePaths, getProductImagePath($productType, $size, $idBase, "CaseLabel"));
        array_push($groupInformationComponents, getExtComponent("Case Label", getProductImageHtml($productType, $size, $idBase, "CaseLabel")));
    }
    $groupInformationPanel = getExtFormPanel("Group Information ({$pack})", $groupInformationComponents);
    array_push($extPanels, $groupInformationPanel);
}
// Determine whether a PDF needs to be generated for this product or not.
$pdfPath = getPdfPath($productType, $size);
$pdfExists = true;
if (file_exists($pdfPath)) {
    // Since the file exists, we need to determine if it has outdated information.
    $pdfLastModifiedTime = filemtime($pdfPath);
    $pdfLastModifiedTimeKey = "pdfLastModifiedTime";
    $quickBooksItemIdQuery = createSqlQuery("SELECT qbi.id", ", FROM_UNIXTIME({$pdfLastModifiedTime}) as '{$pdfLastModifiedTimeKey}'", ", qbi.last_modified_time as '{$qbiLastModifiedTimeKey}'", ", qbis.last_modified_time as '{$qbisLastModifiedTimeKey}'", ", nl.last_modified_time as '{$nlLastModifiedTimeKey}'", ", si.last_modified_time as '{$siLastModifiedTimeKey}'", ", pc.last_modified_time as '{$pcLastModifiedTimeKey}'", ", ks.last_modified_time as '{$ksLastModifiedTimeKey}'", "FROM (((((quickbooks_items qbi", "LEFT JOIN quickbooks_item_supplements qbis ON qbi.quickbooks_item_supplement_id = qbis.id)", "LEFT JOIN nutrition_labels nl ON qbis.nutrition_label_id = nl.id)", "LEFT JOIN storage_infos si ON qbis.storage_info_id = si.id)", "LEFT JOIN production_codes pc ON qbis.production_code_id = pc.id)", "LEFT JOIN kosher_statuses ks ON qbis.kosher_status_id = ks.id)", "WHERE qbi.id LIKE '{$idBase}-%'", "AND (qbi.last_modified_time > FROM_UNIXTIME({$pdfLastModifiedTime})", "OR qbis.last_modified_time > FROM_UNIXTIME({$pdfLastModifiedTime})", "OR nl.last_modified_time > FROM_UNIXTIME({$pdfLastModifiedTime})", "OR si.last_modified_time > FROM_UNIXTIME({$pdfLastModifiedTime})", "OR pc.last_modified_time > FROM_UNIXTIME({$pdfLastModifiedTime})", "OR ks.last_modified_time > FROM_UNIXTIME({$pdfLastModifiedTime}))");
    $result = queryDb($quickBooksItemIdQuery);
    if (mysql_num_rows($result) == 0) {
        // None of the database rows have been updated since the PDF was generated.
        // Check the images on the file-system to ensure they haven't been updated.
        foreach ($imageFilePaths as $imageFilePath) {
            if (filemtime($imageFilePath) > $pdfLastModifiedTime) {
                $pdfExists = false;
                break;
            }
        }
    } else {
        $pdfExists = false;
    }
} else {
    $pdfExists = false;
}
Example #11
0
<?php

// create the database connection and import common methods
require "../../Common/databaseConnection.php";
require "../../Common/util.php";
// Note: this code was derived from: http://www.anyexample.com/programming/php/php_mysql_example__image_gallery_(blob_storage).xml
$id = htmlspecialchars($_GET["id"]);
$imageQuery = join("\n", array("SELECT mime_type, UNIX_TIMESTAMP(last_modified_time), data", "FROM images", "WHERE id={$id}", "LIMIT 1"));
$result = queryDb($imageQuery);
if (mysql_num_rows($result) == 0) {
    die("No image with id: {$id}");
}
list($mimeType, $lastModifiedTime, $data) = mysql_fetch_row($result);
$HEADER_IF_MODIFIED_SINCE = "If-Modified-Since";
$HEADER_LAST_MODIFIED = "Last-Modified";
$HEADER_EXPIRES = "Expires";
$HEADER_CONTENT_LENGTH = "Content-Length";
$HEADER_CONTENT_TYPE = "Content-Type";
// Determine if we can send a "304" due to the client already having the current version.
$ifModifiedSinceHeader = $_SERVER[$HEADER_IF_MODIFIED_SINCE];
if ($ifModifiedSinceHeader && strtotime($ifModifiedSinceHeader) >= $lastModifiedTime) {
    // Send 304
    generateTimeHeader($HEADER_LAST_MODIFIED, $lastModifiedTime, 304);
    exit;
}
// output headers
generateTimeHeader($HEADER_LAST_MODIFIED, $lastModifiedTime, 200);
generateTimeHeader($HEADER_EXPIRES, $lastModifiedTime + 365 * 24 * 60 * 60, 200);
// Set expiration time +1 year
generateHeader($HEADER_CONTENT_LENGTH, strlen($data), 200);
generateHeader($HEADER_CONTENT_TYPE, $mimeType, 200);
Example #12
0
/**
 * Insert or update the sales_order_line_items table with the provided values.
 * @return 
 * @param $salesOrderId Integer id of the sales_order.
 * @param $quickBooksItemId String id of the quickboos_item.
 * @param $cases Integer of the number of cases.
 * @param $shipToAddressOne Decemal of the cost of the line item.
 */
function insertOrUpdateSalesOrderLineItem($salesOrderId, $quickBooksItemId, $cases, $amount)
{
    if ($quickBooksItemId == null) {
        echo "\tLine item does not have a QB Item id and will not be imported to database.\n";
    } else {
        echo "\tInserting/updating Sales Order Line Item:\n";
        echoWithIndentAndCutoff("salesOrderId", $salesOrderId, "\t\t", 100);
        echoWithIndentAndCutoff("quickBooksItemId", $quickBooksItemId, "\t\t", 100);
        echoWithIndentAndCutoff("cases", $cases, "\t\t", 100);
        echoWithIndentAndCutoff("amount", $amount, "\t\t", 100);
        $salesOrderId = mysql_real_escape_string($salesOrderId);
        $quickBooksItemId = mysql_real_escape_string($quickBooksItemId);
        $cases = mysql_real_escape_string($cases);
        $amount = mysql_real_escape_string($amount);
        // see if there's a sales_order_line_item with this sales_order_id and quickbooks_item_id
        $salesOrdersIdQuery = "SELECT id " . "FROM sales_order_line_items " . "WHERE sales_order_id = {$salesOrderId} and qb_item_id = '{$quickBooksItemId}'";
        $result = queryDb($salesOrdersIdQuery);
        echo "\tResults for query of sales order id (" . $salesOrderId . ") and  qb item id: (" . $quickBooksItemId . "): " . mysql_num_rows($result) . "\n";
        if (mysql_num_rows($result) == 0) {
            // sales_order with this id doesn't exist
            echo "\tline item with sales order id (" . $salesOrderId . ") and  qb item id: (" . $quickBooksItemId . ") does NOT exist\n";
            $insertQuery = "INSERT INTO sales_order_line_items " . "(sales_order_id, qb_item_id, cases, amount) " . "VALUES " . "({$salesOrderId}, '{$quickBooksItemId}', {$cases}, {$amount})";
            queryDb($insertQuery);
        } else {
            // a sales_order with this id already exists
            echo "\tline item with sales order id (" . $salesOrderId . ") and  qb item id: (" . $quickBooksItemId . ") DOES exist\n";
            $updateQuery = "UPDATE sales_order_line_items " . "SET cases=(cases+{$cases}), \n\t\t\t\t\t\t amount=(amount+{$amount}) " . "WHERE sales_order_id = {$salesOrderId} and qb_item_id = '{$quickBooksItemId}'";
            queryDb($updateQuery);
        }
    }
}