function get_ms_list() { global $db; $master = explode('-', $this->sku); $this->master = $master[0]; $result = $db->Execute("select * from " . TABLE_INVENTORY_MS_LIST . " where sku = '" . $this->master . "'"); $this->ms_attr_0 = $result->RecordCount() > 0 ? $result->fields['attr_0'] : ''; $this->attr_name_0 = $result->RecordCount() > 0 ? $result->fields['attr_name_0'] : ''; $this->ms_attr_1 = $result->RecordCount() > 0 ? $result->fields['attr_1'] : ''; $this->attr_name_1 = $result->RecordCount() > 0 ? $result->fields['attr_name_1'] : ''; if ($this->ms_attr_0) { $temp = explode(',', $this->ms_attr_0); for ($i = 0; $i < count($temp); $i++) { $code = substr($temp[$i], 0, strpos($temp[$i], ':')); $desc = substr($temp[$i], strpos($temp[$i], ':') + 1); $this->attr_array0[] = array('id' => $code . ':' . $desc, 'text' => $code . ' : ' . $desc); $temp_ms0[$code] = $desc; } } if ($this->ms_attr_1) { $temp = explode(',', $this->ms_attr_1); for ($i = 0; $i < count($temp); $i++) { $code = substr($temp[$i], 0, strpos($temp[$i], ':')); $desc = substr($temp[$i], strpos($temp[$i], ':') + 1); $this->attr_array1[] = array('id' => $code . ':' . $desc, 'text' => $code . ' : ' . $desc); $temp_ms1[$code] = $desc; } } $result = $db->Execute("select * from " . TABLE_INVENTORY . " where sku like '" . $this->master . "-%' and inventory_type = 'mi' and sku<>'" . $this->sku . "'"); $i = 0; while (!$result->EOF) { $temp = explode('-', $result->fields['sku']); $this->child_array[$i] = array('id' => $result->fields['id'], 'sku' => $result->fields['sku'], 'inactive' => $result->fields['inactive'], 'desc' => $result->fields['description_short'], '0' => $temp_ms0[substr($temp[1], 0, 2)], '1' => strlen($temp[1]) > 2 ? $temp_ms1[substr($temp[1], 2, 4)] : '', 'on_hand' => $result->fields['quantity_on_hand'], 'on_order' => $result->fields['quantity_on_order'], 'on_sales' => $result->fields['quantity_on_sales_order'], 'min_stock' => $result->fields['minimum_stock_level'], 'reorder_qty' => $result->fields['reorder_quantity'], 'tax' => $result->fields['item_taxable']); $temp = inv_calculate_sales_price(1, $result->fields['id'], 0, 'v'); $this->child_array[$i]['cost'] = $temp['price']; $temp = inv_calculate_sales_price(1, $result->fields['id'], 0, 'c'); $this->child_array[$i]['price'] = $temp['price']; $i++; $result->MoveNext(); } }
function save() { global $db, $messageStack, $security_level, $currencies; $bom_list = array(); for ($x = 0; $x < count($_POST['assy_sku']); $x++) { $bom_list[$x] = array('ref_id' => $this->id, 'sku' => db_prepare_input($_POST['assy_sku'][$x]), 'description' => db_prepare_input($_POST['assy_desc'][$x]), 'qty' => $currencies->clean_value(db_prepare_input($_POST['assy_qty'][$x]))); $result = $db->Execute("select id from " . TABLE_INVENTORY . " where sku = '" . $_POST['assy_sku'][$x] . "'"); if (($result->RecordCount() == 0 || $currencies->clean_value($_POST['assy_qty'][$x]) == 0) && ($_POST['assy_sku'][$x] = !'')) { // show error, bad sku, negative quantity. error check sku is valid and qty > 0 $error = $messageStack->add(INV_ERROR_BAD_SKU . db_prepare_input($_POST['assy_sku'][$x]), 'error'); } else { $prices = inv_calculate_sales_price(abs($this->bom[$x]['qty']), $result->fields['id'], 0, 'v'); $bom_list[$x]['item_cost'] = strval($prices['price']); $prices = inv_calculate_sales_price(abs($this->bom[$x]['qty']), $result->fields['id'], 0, 'c'); $bom_list[$x]['full_price'] = strval($prices['price']); } } $this->bom = $bom_list; $current_situation = $db->Execute("select * from " . TABLE_INVENTORY . " where id = '" . $this->id . "'"); $sql_data_array = parent::save(); if ($sql_data_array == false) { return false; } $result = $db->Execute("select last_journal_date, quantity_on_hand from " . TABLE_INVENTORY . " where id = " . $this->id); $this->allow_edit_bom = ($result->fields['last_journal_date'] == '0000-00-00 00:00:00' || $result->fields['last_journal_date'] == '') && ($result->fields['quantity_on_hand'] == 0 || $result->fields['quantity_on_hand'] == '') ? true : false; if ($error) { return false; } if ($this->allow_edit_bom == true) { // only update if no posting has been performed $result = $db->Execute("delete from " . TABLE_INVENTORY_ASSY_LIST . " where ref_id = " . $this->id); foreach ($bom_list as $list_array) { unset($list_array['item_cost']); unset($list_array['full_price']); db_perform(TABLE_INVENTORY_ASSY_LIST, $list_array, 'insert'); } } $sql_data_array['inventory_type'] = 'ia'; // split attributes $attr0 = array(); $attr1 = array(); if ($this->ms_attr_0 != '') { $attr0 = explode(',', $this->ms_attr_0); } if ($this->ms_attr_1 != '') { $attr1 = explode(',', $this->ms_attr_1); } if (empty($attr0)) { $this->get_ms_list(); return false; // no attributes, nothing to do } // build skus $sku_list = array(); for ($i = 0; $i < count($attr0); $i++) { $idx0 = explode(':', $attr0[$i]); if (empty($attr1)) { if ($idx0[0] != '') { $sku_list[] = $this->sku . '-' . $idx0[0]; $variables[$this->sku . '-' . $idx0[0]]['idx0'] = $idx0[1]; } } else { for ($j = 0; $j < count($attr1); $j++) { $idx1 = explode(':', $attr1[$j]); if ($idx0[0] != '' && $idx1[0] != '') { $sku_list[] = $this->sku . '-' . $idx0[0] . $idx1[0]; $variables[$this->sku . '-' . $idx0[0] . $idx1[0]]['idx0'] = $idx0[1]; $variables[$this->sku . '-' . $idx0[0] . $idx1[0]]['idx1'] = $idx1[1]; } } } } // either update, delete or insert sub skus depending on sku list $result = $db->Execute("select sku from " . TABLE_INVENTORY . " where inventory_type = 'ia' and sku like '" . $this->sku . "-%'"); $existing_sku_list = array(); while (!$result->EOF) { $existing_sku_list[] = $result->fields['sku']; $result->MoveNext(); } $delete_list = array_diff($existing_sku_list, $sku_list); $update_list = array_intersect($existing_sku_list, $sku_list); $insert_list = array_diff($sku_list, $update_list); foreach ($insert_list as $sku) { // first insert new sku's with all fields $sql_data_array['sku'] = $sku; $sql_data_array['description_short'] = sprintf($this->description_short, $variables[$sku]['idx0'], $variables[$sku]['idx1']); $sql_data_array['description_purchase'] = sprintf($this->description_purchase, $variables[$sku]['idx0'], $variables[$sku]['idx1']); $sql_data_array['description_sales'] = sprintf($this->description_sales, $variables[$sku]['idx0'], $variables[$sku]['idx1']); db_perform(TABLE_INVENTORY, $sql_data_array, 'insert'); $new_id = db_insert_id(); foreach ($this->purchase_array as $purchase_row) { $purchase_data_array = array('sku' => $sku, 'vendor_id' => $purchase_row['vendor_id'], 'description_purchase' => sprintf($purchase_row['description_purchase'], $variables[$sku]['idx0'], $variables[$sku]['idx1']), 'item_cost' => $purchase_row['item_cost'], 'purch_package_quantity' => $purchase_row['purch_package_quantity'], 'purch_taxable' => $purchase_row['purch_taxable'], 'price_sheet_v' => $purchase_row['price_sheet_v']); db_perform(TABLE_INVENTORY_PURCHASE, $purchase_data_array, 'insert'); } foreach ($bom_list as $list_array) { $list_array['ref_id'] = $new_id; unset($list_array['item_cost']); unset($list_array['full_price']); db_perform(TABLE_INVENTORY_ASSY_LIST, $list_array, 'insert'); } } if ($this->id != '') { //only update fields that are changed otherwise fields in the child could be overwritten foreach ($current_situation->fields as $key => $value) { // remove fields where the parent is unchanged because the childeren could have different values in these fields. switch ($key) { case 'description_short': if ($this->description_short == $value) { unset($sql_data_array[$key]); } break; case 'description_purchase': if ($this->description_purchase == $value) { unset($sql_data_array[$key]); } break; case 'description_sales': if ($this->description_sales == $value) { unset($sql_data_array[$key]); } break; default: if ($sql_data_array[$key] == $value) { unset($sql_data_array[$key]); } } } } foreach ($update_list as $sku) { //update with reduced number of fields. $sql_data_array['sku'] = $sku; if (isset($sql_data_array['description_short'])) { $sql_data_array['description_short'] = sprintf($this->description_short, $variables[$sku]['idx0'], $variables[$sku]['idx1']); } if (isset($sql_data_array['description_purchase'])) { $sql_data_array['description_purchase'] = sprintf($this->description_purchase, $variables[$sku]['idx0'], $variables[$sku]['idx1']); } if (isset($sql_data_array['description_sales'])) { $sql_data_array['description_sales'] = sprintf($this->description_sales, $variables[$sku]['idx0'], $variables[$sku]['idx1']); } db_perform(TABLE_INVENTORY, $sql_data_array, 'update', "sku = '" . $sku . "'"); foreach ($this->backup_purchase_array as $backUpKey => $backUpRow) { $backUpRow['description_purchase'] = sprintf($backUpRow['description_purchase'], $variables[$sku]['idx0'], $variables[$sku]['idx1']); $purchase_data_array = null; if ($backUpRow['action'] == 'delete') { $result = $db->Execute("delete from " . TABLE_INVENTORY_PURCHASE . " where sku = '" . $sku . "' and vendor_id = '" . $backUpRow['vendor_id'] . "'"); } else { if ($backUpRow['action'] == 'insert') { $purchase_data_array = $backUpRow; unset($purchase_data_array['id']); unset($purchase_data_array['action']); $purchase_data_array['sku'] = $sku; db_perform(TABLE_INVENTORY_PURCHASE, $purchase_data_array, 'insert'); } else { /*on purpose removed this part because iam not sure what to update and what not * $purchase_data_array = $backUpRow; unset($purchase_data_array['id']); unset($purchase_data_array['action']); foreach($backUpRow as $key => $value) { if($key == 'action' || $key == 'id' ) break; if($this->purchase_array[$backUpKey][$key] == $value){ unset($purchase_data_array[$key]); } } db_perform(TABLE_INVENTORY_PURCHASE, $purchase_data_array, 'update', "sku = '" . $sku. "' and vendor_id = '".$backUpRow['vendor_id']."'");*/ } } } $result = $db->Execute("select id, last_journal_date, quantity_on_hand from " . TABLE_INVENTORY . " where sku = '" . $sku . "'"); $this->allow_edit_bom = ($result->fields['last_journal_date'] == '0000-00-00 00:00:00' || $result->fields['last_journal_date'] == '') && ($result->fields['quantity_on_hand'] == 0 || $result->fields['quantity_on_hand'] == '') ? true : false; if ($this->allow_edit_bom == true) { // only update if no posting has been performed $temp = $db->Execute("delete from " . TABLE_INVENTORY_ASSY_LIST . " where ref_id = " . $result->fields['id']); foreach ($bom_list as $list_array) { $list_array['ref_id'] = $result->fields['id']; unset($list_array['item_cost']); unset($list_array['full_price']); db_perform(TABLE_INVENTORY_ASSY_LIST, $list_array, 'insert'); } } } if (count($delete_list) && $security_level < 4) { $messageStack->add(ERROR_NO_PERMISSION, 'error'); $this->get_ms_list(); return false; } foreach ($delete_list as $sku) { $temp = $this->ia_check_remove($sku); if ($temp === true) { $result = $db->Execute("delete from " . TABLE_INVENTORY . " where sku = '" . $sku . "'"); $result = $db->Execute("delete from " . TABLE_INVENTORY_PURCHASE . " where sku = '" . $sku . "'"); $result = $db->Execute("select id, last_journal_date, quantity_on_hand from " . TABLE_INVENTORY . " where sku = '" . $sku . "'"); $temp = $db->Execute("delete from " . TABLE_INVENTORY_ASSY_LIST . " where ref_id = " . $result->fields['id']); } elseif ($temp === false) { $result = $db->Execute("update " . TABLE_INVENTORY . " set inactive = '1' where sku = '" . $sku . "'"); } } // update/insert into inventory_ms_list table $result = $db->Execute("select id from " . TABLE_INVENTORY_MS_LIST . " where sku = '" . $this->sku . "'"); $exists = $result->RecordCount(); $data_array = array('sku' => $this->sku, 'attr_0' => $this->ms_attr_0, 'attr_name_0' => $this->attr_name_0, 'attr_1' => $this->ms_attr_1, 'attr_name_1' => $this->attr_name_1); if ($exists) { db_perform(TABLE_INVENTORY_MS_LIST, $data_array, 'update', "id = " . $result->fields['id']); } else { db_perform(TABLE_INVENTORY_MS_LIST, $data_array, 'insert'); } $this->get_ms_list(); return true; }
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'"); if ($stock->RecordCount() > 0) { $sku_usage[] = TEXT_QUANTITY . ' ' . $result->fields['qty'] . ' ' . TEXT_SKU . ': ' . $stock->fields['sku'] . ' - ' . $stock->fields['description_short']; } $result->MoveNext(); } } if (sizeof($sku_usage) > 0) { array_unshift($sku_usage, JS_INV_TEXT_USAGE); } else { $sku_usage = array(JS_INV_TEXT_USAGE_NONE); } // load prices, tax $prices = inv_calculate_sales_price(abs($qty), $iID, $cID, $vendor ? 'v' : 'c'); $sales_price = strval($prices['price']); $inventory_array['item_taxable'] = strval($prices['sales_tax']); $inventory_array['purch_taxable'] = strval($prices['purch_tax']); //$debug .= 'sales_tax = ' . $prices['sales_tax'] . ' and purch tax = ' . $prices['purch_tax'] . ' and price = ' . $sales_price . chr(10); // Load default tax to use if ($cID) { } // load sku stock status and open orders switch ($jID) { case '9': case '10': case '12': case '19': // check for stock available for SO, Customer Quote and Sales if ($qty > $inventory_array['branch_qty_in_stock'] && strpos(COG_ITEM_TYPES, $inventory_array['inventory_type']) !== false) {
$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'] . "'"); $sku_usage[] = TEXT_QUANTITY . ' ' . $result->fields['qty'] . ' ' . TEXT_SKU . ': ' . $stock->fields['sku'] . ' - ' . $stock->fields['description_short']; $result->MoveNext(); } } // load price $sales_price = strval(inv_calculate_sales_price(abs($qty), $iID, $cID)); // load sku stock status and open orders $stock_note = array(); switch ($jID) { case '3': case '4': case '6': // case '21': break; case '9': case '10': case '12': // case '19': // check for stock available for SO, Customer Quote and Sales if ($qty > $inventory->fields['branch_qty_in_stock'] && strpos(COG_ITEM_TYPES, $inventory->fields['inventory_type']) !== false) { $stock_note = array(ORD_INV_STOCK_LOW);
$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'; ?> " style="cursor:pointer" onclick="setReturnItem(<?php echo $query_result->fields['id']; ?> )"> <td<?php echo $bkgnd; ?> ><?php
$db->Execute("update " . TABLE_INVENTORY_SPECIAL_PRICES . " set price_levels = '" . $price_levels . "' \n\t\t\twhere inventory_id = " . $id . " and price_sheet_id = " . $sheet_id); } if ($type == 'c') { $db->Execute("UPDATE " . TABLE_INVENTORY . " SET price_sheet = '{$sheet_name}', last_update= '" . date('Y-m-d') . "' WHERE id = {$id}"); } else { $db->Execute("UPDATE " . TABLE_INVENTORY . " a JOIN " . TABLE_INVENTORY_PURCHASE . " b ON a.sku = b.sku SET b.price_sheet_v = '{$sheet_name}', a.last_update= '" . date('Y-m-d') . "' WHERE a.id = {$id} and b.id = '{$vendor_id}' "); } } $tab_id++; } gen_add_audit_log(INV_LOG_PRICE_MGR . TEXT_UPDATE, $inventory_details->fields['sku'] . ' - ' . $inventory_details->fields['description_short']); break; default: } /***************** prepare to display templates *************************/ $temp = inv_calculate_sales_price(1, $id, 0, 'v'); $item_cost = $temp['price']; // some preliminary information $sql = "select id, sheet_name, revision, default_sheet, default_levels from " . TABLE_PRICE_SHEETS . " \n\twhere inactive = '0' and type = '{$type}' and \n\t(expiration_date is null or expiration_date = '0000-00-00' or expiration_date >= '" . date('Y-m-d') . "') \n\torder by sheet_name"; $price_sheets = $db->Execute($sql); // retrieve special pricing for this inventory item $result = $db->Execute("select price_sheet_id, price_levels \n\tfrom " . TABLE_INVENTORY_SPECIAL_PRICES . " where inventory_id = " . $id); $special_prices = array(); while (!$result->EOF) { $special_prices[$result->fields['price_sheet_id']] = $result->fields['price_levels']; $result->MoveNext(); } $include_header = false; $include_footer = false; $include_template = 'template_main.php'; define('PAGE_TITLE', $type == 'v' ? BOX_PURCHASE_PRICE_SHEETS : BOX_SALES_PRICE_SHEETS);
function save() { global $db, $currencies, $messageStack; $bom_list = array(); for ($x = 0; $x < count($_POST['assy_sku']); $x++) { $bom_list[$x] = array('ref_id' => $this->id, 'sku' => db_prepare_input($_POST['assy_sku'][$x]), 'description' => db_prepare_input($_POST['assy_desc'][$x]), 'qty' => $currencies->clean_value(db_prepare_input($_POST['assy_qty'][$x]))); $result = $db->Execute("select id from " . TABLE_INVENTORY . " where sku = '" . $_POST['assy_sku'][$x] . "'"); if (($result->RecordCount() == 0 || $currencies->clean_value($_POST['assy_qty'][$x]) == 0) && ($_POST['assy_sku'][$x] = !'')) { // show error, bad sku, negative quantity. error check sku is valid and qty > 0 $error = $messageStack->add(INV_ERROR_BAD_SKU . db_prepare_input($_POST['assy_sku'][$x]), 'error'); } else { $prices = inv_calculate_sales_price(abs($this->bom[$x]['qty']), $result->fields['id'], 0, 'v'); $bom_list[$x]['item_cost'] = strval($prices['price']); $prices = inv_calculate_sales_price(abs($this->bom[$x]['qty']), $result->fields['id'], 0, 'c'); $bom_list[$x]['full_price'] = strval($prices['price']); } } $this->bom = $bom_list; if (!parent::save()) { return false; } $result = $db->Execute("select last_journal_date, quantity_on_hand from " . TABLE_INVENTORY . " where id = " . $this->id); $this->allow_edit_bom = ($result->fields['last_journal_date'] == '0000-00-00 00:00:00' || $result->fields['last_journal_date'] == '') && ($result->fields['quantity_on_hand'] == 0 || $result->fields['quantity_on_hand'] == '') ? true : false; if ($error) { return false; } if ($this->allow_edit_bom == true) { // only update if no posting has been performed $result = $db->Execute("delete from " . TABLE_INVENTORY_ASSY_LIST . " where ref_id = " . $this->id); while ($list_array = array_shift($bom_list)) { unset($list_array['item_cost']); unset($list_array['full_price']); db_perform(TABLE_INVENTORY_ASSY_LIST, $list_array, 'insert'); } } return true; }
#print_bar { display:none; } div{ /* page-break-after: always; */ page-break-inside: avoid; } } </style> <div id="print_bar"> <a href="#" onclick="window.print(); return false;"> Imprimir </a></div> <?php $items = $db->Execute("select inv.id as id,inv.sku as sku, description_sales as descr from `etiquetas_pendientes` ep INNER JOIN `inventory` inv on ep.sku = inv.sku"); $etiquetas_pendientes = array(); while (!$items->EOF) { $sku_id = $items->fields['id']; $precio = inv_calculate_sales_price(1, $sku_id); ?> <div class="producto"> <div class="descripcion"><?php echo $items->fields['descr']; ?> </div> <div class="precio"><strong>$ <?php echo $precio; ?> </strong></div> <div class="sku">sku: <?php echo $items->fields['sku']; ?> </div> </div>