$cog_types = explode(',', COG_ITEM_TYPES);
if (!in_array($inventory->fields['inventory_type'], $cog_types)) {
    $inventory->fields['quantity_on_hand'] = 'NA';
}
// load branch stock ( must be before BOM loading )
$inventory->fields['branch_qty_in_stock'] = strval(load_store_stock($sku, $bID));
// Load the assembly information
$assy_cost = 0;
if ($inventory->fields['inventory_type'] == 'as' || $inventory->fields['inventory_type'] == 'sa') {
    $result = $db->Execute("select sku, qty from " . TABLE_INVENTORY_ASSY_LIST . " where ref_id = '" . $iID . "'");
    $bom = array();
    while (!$result->EOF) {
        $sql = "select description_short, item_cost, quantity_on_hand from " . TABLE_INVENTORY . " where sku = '" . $result->fields['sku'] . "'";
        $sku_cost = $db->Execute($sql);
        $assy_cost += $result->fields['qty'] * $sku_cost->fields['item_cost'];
        $branch_qty_in_stock = $bID ? strval(load_store_stock($result->fields['sku'], $bID)) : $sku_cost->fields['quantity_on_hand'];
        //echo 'branch stock = ' . $branch_qty_in_stock . '<br />';
        $bom[] = array('qty' => $result->fields['qty'], 'sku' => $result->fields['sku'], 'description_short' => $sku_cost->fields['description_short'], 'item_cost' => $sku_cost->fields['item_cost'], 'quantity_on_hand' => $branch_qty_in_stock);
        $result->MoveNext();
    }
} else {
    $assy_cost = $inventory->fields['item_cost'];
}
// load where used
$result = $db->Execute("select ref_id, qty from " . TABLE_INVENTORY_ASSY_LIST . " where sku = '" . $sku . "'");
if ($result->RecordCount() == 0) {
    $sku_usage = array(JS_INV_TEXT_USAGE_NONE);
} else {
    $sku_usage = array(JS_INV_TEXT_USAGE);
    while (!$result->EOF) {
        $stock = $db->Execute("select sku, description_short from " . TABLE_INVENTORY . " where id = '" . $result->fields['ref_id'] . "'");
    $inventory_array['quantity_on_hand'] = 'NA';
}
// load branch stock ( must be before BOM loading )
$inventory_array['branch_qty_in_stock'] = strpos(COG_ITEM_TYPES, $inventory_array['inventory_type']) === false ? 'NA' : strval(load_store_stock($sku, $bID));
//$debug .= 'qty in stock = ' . $inventory_array['quantity_on_hand'] . ' and branch qty = ' . $inventory_array['branch_qty_in_stock'];
// Load the assembly information
$assy_cost = 0;
if ($inventory_array['inventory_type'] == 'ma' || $inventory_array['inventory_type'] == 'sa') {
    $result = $db->Execute("select sku, qty from " . TABLE_INVENTORY_ASSY_LIST . " where ref_id = '{$iID}'");
    $bom = array();
    while (!$result->EOF) {
        $sql = "select description_short, inventory_type, item_cost, quantity_on_hand from " . TABLE_INVENTORY . " where sku = '" . $result->fields['sku'] . "'";
        $sku_cost = $db->Execute($sql);
        $assy_cost += $result->fields['qty'] * $sku_cost->fields['item_cost'];
        if (in_array($sku_cost->fields['inventory_type'], $cog_types)) {
            $qty_in_stock = strval(load_store_stock($result->fields['sku'], $bID));
        } else {
            $qty_in_stock = 'NA';
        }
        $bom[] = array('qty' => $result->fields['qty'], 'sku' => $result->fields['sku'], 'description_short' => $sku_cost->fields['description_short'], 'item_cost' => $sku_cost->fields['item_cost'], 'quantity_on_hand' => $qty_in_stock);
        $result->MoveNext();
    }
} else {
    $assy_cost = $inventory_array['item_cost'];
}
// load where used
$sku_usage = array();
$result = $db->Execute("select ref_id, qty from " . TABLE_INVENTORY_ASSY_LIST . " where sku = '{$sku}'");
if ($result->RecordCount() > 0) {
    while (!$result->EOF) {
        $stock = $db->Execute("select sku, description_short from " . TABLE_INVENTORY . " where id='" . $result->fields['ref_id'] . "' and inactive = '0'");
 <thead class="ui-widget-header">
  <tr><?php 
echo $list_header;
?>
</tr>
 </thead>
 <tbody class="ui-widget-content">
  <?php 
$odd = true;
while (!$query_result->EOF) {
    $display_stock = true;
    if (strpos(COG_ITEM_TYPES, $query_result->fields['inventory_type']) === false) {
        $display_stock = false;
        $return_stock = TEXT_NA;
    } elseif (ENABLE_MULTI_BRANCH) {
        $store_stock = load_store_stock($query_result->fields['sku'], $store_id);
    }
    switch ($account_type) {
        default:
        case 'c':
            $price = inv_calculate_sales_price(1, $query_result->fields['id'], 0, 'c');
            break;
        case 'v':
            $price = inv_calculate_sales_price(1, $query_result->fields['id'], 0, 'v');
            break;
    }
    $bkgnd = $query_result->fields['inactive'] == 1 ? ' style="background-color:pink"' : '';
    ?>
  <tr class="<?php 
    echo $odd ? 'odd' : 'even';
    ?>
Example #4
0
 function get_qty()
 {
     global $db;
     if (in_array('quantity_on_hand', $this->not_used_fields)) {
         return;
     }
     $sql = " select id, short_name, primary_name from " . TABLE_CONTACTS . " c join " . TABLE_ADDRESS_BOOK . " a on c.id = a.ref_id where c.type = 'b' order by short_name ";
     $result = $db->Execute($sql);
     $qty = load_store_stock($this->sku, 0);
     $this->qty_per_store[0] = $qty;
     $this->quantity_on_hand = $qty;
     if (ENABLE_MULTI_BRANCH) {
         $this->qty_table = '<table class="ui-widget" style="border-collapse:collapse;width:100%">' . chr(10);
         $this->qty_table .= '  <thead class="ui-widget-header">' . chr(10);
         $this->qty_table .= '	  <tr>';
         $this->qty_table .= '		<th>' . GEN_STORE_ID . '</th>';
         $this->qty_table .= '		<th>' . INV_HEADING_QTY_IN_STOCK . '</th>';
         $this->qty_table .= '    </tr>' . chr(10);
         $this->qty_table .= '  </thead>' . chr(10);
         $this->qty_table .= '  <tbody class="ui-widget-content">' . chr(10);
         $this->qty_table .= '    <tr>';
         $this->qty_table .= '      <td>' . COMPANY_ID . '</td>';
         $this->qty_table .= '      <td align="center">' . $qty . '</td>';
         $this->qty_table .= '    </tr>' . chr(10);
         while (!$result->EOF) {
             $qty = load_store_stock($this->sku, $result->fields['id']);
             $this->qty_per_store[$result->fields['id']] = $qty;
             $this->quantity_on_hand += $qty;
             $this->qty_table .= '<tr>';
             $this->qty_table .= '  <td>' . $result->fields['primary_name'] . '</td>';
             $this->qty_table .= '  <td align="center">' . $qty . '</td>';
             $this->qty_table .= '</tr>' . chr(10);
             $result->MoveNext();
         }
         $this->qty_table .= '  </tbody>' . chr(10);
         $this->qty_table .= '</table>' . chr(10);
     }
 }
</tr>
<?php 
$java_string = 'var assy_list = new Array(' . $query_result->RecordCount() . ');' . chr(10);
$pointer = 0;
while (!$query_result->EOF) {
    $sku = $query_result->fields['sku'];
    $inactive = $query_result->fields['inactive'];
    $weight = $query_result->fields['item_weight'];
    $stock = $query_result->fields['quantity_on_hand'];
    // set the quantity on hand to big for non-cogs type items
    $display_stock = true;
    if (!in_array($query_result->fields['inventory_type'], $inv_cogs_calculated_types)) {
        $display_stock = false;
        $return_stock = 'NA';
    } elseif (ENABLE_MULTI_BRANCH) {
        $store_stock = load_store_stock($sku, $store_id);
        $return_stock = $store_stock;
    } else {
        $return_stock = $stock;
    }
    $on_order = $query_result->fields['quantity_on_order'];
    $taxable = $query_result->fields['item_taxable'];
    $lead_time = $query_result->fields['lead_time'];
    $acct_cogs = $query_result->fields['account_cost_of_sales'];
    switch ($account_type) {
        default:
        case 'c':
            $price = $query_result->fields['full_price'];
            $acct = $query_result->fields['account_sales_income'];
            $desc = addslashes($query_result->fields['description_short']);
            break;
     $field_list->MoveNext();
 }
 $full_inv_query = $query == '' ? '*' : substr($query, 0, -2);
 $sql = "select " . $full_inv_query . " from " . TABLE_INVENTORY . " where id = " . $id . " order by sku";
 $inventory = $db->Execute($sql);
 $cInfo = new objectInfo($inventory->fields);
 // gather the history
 $sku_history = gather_history($inventory->fields['sku']);
 // get the branch stock
 if (ENABLE_MULTI_BRANCH) {
     $sql = " select id, short_name from " . TABLE_CONTACTS . " where type = 'b'";
     $result = $db->Execute($sql);
     $store_stock = array();
     $store_stock[] = array('store' => COMPANY_ID, 'qty' => load_store_stock($inventory->fields['sku'], 0));
     while (!$result->EOF) {
         $store_stock[] = array('store' => $result->fields['short_name'], 'qty' => load_store_stock($inventory->fields['sku'], $result->fields['id']));
         $result->MoveNext();
     }
 }
 // master stock, fetch attributes
 if ($cInfo->inventory_type == 'ms') {
     $result = $db->Execute("select * from " . TABLE_INVENTORY_MS_LIST . " where sku = '" . $cInfo->sku . "'");
     $cInfo->ms_attr_0 = $result->RecordCount() > 0 ? $result->fields['attr_0'] : '';
     $cInfo->attr_name_0 = $result->RecordCount() > 0 ? $result->fields['attr_name_0'] : '';
     $cInfo->ms_attr_1 = $result->RecordCount() > 0 ? $result->fields['attr_1'] : '';
     $cInfo->attr_name_1 = $result->RecordCount() > 0 ? $result->fields['attr_name_1'] : '';
     $attr_array0 = array();
     if ($cInfo->ms_attr_0) {
         $temp = explode(',', $cInfo->ms_attr_0);
         for ($i = 0; $i < count($temp); $i++) {
             $code = substr($temp[$i], 0, strpos($temp[$i], ':'));
 if (strpos(COG_ITEM_TYPES, $inv_type) === false) {
     $messageStack->add(INV_XFER_ERROR_NO_COGS_REQD, 'error');
     $error = true;
 }
 // quantity needs to be greater than zero
 if ($qty < 0) {
     $messageStack->add(INV_XFER_ERROR_QTY_ZERO, 'error');
     $error = true;
 }
 // source and dest need to be different
 if ($source_store_id == $dest_store_id) {
     $messageStack->add(INV_XFER_ERROR_SAME_STORE_ID, 'error');
     $error = true;
 }
 // source store needs to have enough
 $source_stock = load_store_stock($sku, $source_store_id);
 if ($source_stock < $qty) {
     $messageStack->add(INV_XFER_ERROR_NOT_ENOUGH_SKU, 'error');
     $error = true;
 }
 // process the request, first subtract from the source store
 if (!$error) {
     $glEntry = new journal();
     $glEntry->id = '';
     // all transactions are considered new
     $glEntry->journal_id = JOURNAL_ID;
     $glEntry->post_date = $post_date;
     $glEntry->period = $period;
     $glEntry->store_id = $source_store_id;
     $glEntry->admin_id = $_SESSION['admin_id'];
     $glEntry->purchase_invoice_id = db_prepare_input($_POST['purchase_invoice_id']);