Inventory Discrepancy Notes

In SiteBuilder version 2.72 and up, you can edit inventory stock numbers by selecting 'Products' in the storeadmin area, then selecting 'Edit Inventory' at the bottom of the screen, under Quick Inventory Update. This is a great way to update counts quickly, but if a customer orders an item while that screen is open, the values on the screen will override the current database counts.

This modification, which will be included in version 2.82, will show any discrepancies between the counts on the form (whether you update the counts or not) and whatever is currently in the database. It does not make any changes to the stock levels; it simply shows a message so that the store admin can manually check counts for those items.

This also only adds an error message when using the Quick Inventory Update. It will not display a message when editing the item inventory through the product screen.

To add this mod to version 2.72 or 2.81 sites:

  1. Open the itemlist.php file in the /storeadmin/ folder.

  2. Find the lines:

    // UPDATE INVENTORY
    else if ($itemlistmode == "inv")
    {
  3. Just below those lines, add:

    // START CHECK CURRENT INVENTORY VALUES
    function nullornot($inval)
    {
    if ($inval=='' AND $inval!='0')
    $inval = 'empty';
    return $inval;
    }
    
    // SHOW ERROR MESSAGE
    function inventory_errormsg($attname, $originalindb, $formcount, $newcount)
    {
    $errsmsg = "";
    if ($originalindb != $formcount)
    {
    $errsmsg = "
    "; $errsmsg .= "There is an inventory discrepancy with $attname:
      "; $errsmsg .= "
    • The stock quantity changed to $originalindb after this page was opened.
    • "; $errsmsg .= "
    • The stock quantity on this page "; if ($formcount == $newcount) $errsmsg .= "is currently $formcount"; else $errsmsg .= "was initially $formcount (and is now $newcount)"; $errsmsg .= ".
    • "; $errsmsg .= "
    "; } return $errsmsg; } // CREATE LIST OF CURRENT INVENTORY VALUES $display_error = ''; foreach($itemid AS $idkey => $idvalue) { // GET ITEM DATA $getcurrcount = mysql_query("SELECT Item, Catalog, Inventory FROM " .SB_DB_PREFIX ."_items WHERE ID='" .$idvalue ."' LIMIT 1", $dblink); if(mysql_num_rows($getcurrcount)==1) { $getcurrrow = mysql_fetch_row($getcurrcount); $iteminv_name = stripslashes($getcurrrow[0]); if(!empty($getcurrrow[1])) $iteminv_name = "#" .$getcurrrow[1] ." " .$iteminv_name; $iteminv_db = nullornot($getcurrrow[2]); // GET CURRENT DATABASE COUNTS $idkey = array_search($idvalue, $itemid); // NO OPTIONS if ($optcount[$idkey]==0) { $iteminv_old = nullornot($oldinv[$idkey]); $iteminv_new = nullornot($inv[$idkey]); $display_error .= inventory_errormsg($iteminv_name, $iteminv_db, $iteminv_old, $iteminv_new); } // HAS OPTIONS else { foreach(${"inv_" .$idkey} AS $optkey => $optvalue) { $att_name = ${"attname_" .$idkey}[$optkey]; $attinv_old = nullornot(${"oldinv_" .$idkey}[$optkey]); $attinv_new = nullornot(${"inv_" .$idkey}[$optkey]); $getcurratt = mysql_query("SELECT Quantity FROM " .SB_DB_PREFIX ."_inventory WHERE ProductID='" .$idvalue ."' AND Attribute='" .addslash_mq($att_name) ."' LIMIT 1", $dblink); // HAS SOME INVENTORY COUNTS if(mysql_num_rows($getcurratt)==1) { $currattrow = mysql_fetch_row($getcurratt); $attinv_db = nullornot($currattrow [0]); $display_error .= inventory_errormsg($iteminv_name ." " .$att_name, $attinv_db, $attinv_old, $attinv_new); } // NO INVENTORY COUNTS else $display_error .= inventory_errormsg($iteminv_name ." " .$att_name, 'empty', $attinv_old, $attinv_new); } } } } echo $display_error; // END CHECK CURRENT INVENTORY VALUES
  4. Change the line:

    echo "";

    to:

    echo "";
    echo "";
  5. Change the line:

    echo "";
    

    to:

    echo "";
    echo "";
  6. Add the lines:

    echo "";
    echo "";
    echo "";
    echo "";

    Just before the lines:

    ?>
    
  7. Optional! Add the following classes:

    .invupdate {
    border: 1px solid #990000;
    background-color: #F4DCDC;
    margin: 1px;
    text-align: center;
    }
    
    .invset {
    border: 1px solid #999999;
    margin: 1px;
    text-align: center;
    }

    to the style.css file in the /includes/ folder within the /storeadmin/ folder. (This is strictly cosmetic; it will turn the box red when a store owner changes the inventory quantity.)

  8. Save and reload the itemlist.php file (and the style.css file if you updated it).