$item = getItemByID($link, $itemBarcode->ItemID); //$bBarcode = true; } else { $item = getItemByCode($link, $code); } if ($item) { //if($bBarcode){ if ($itemBarcode) { $item->barcode = $code; if ($itemBarcode->unitID) { $item->UnitID = $itemBarcode->unitID; } if ($itemBarcode->itemCombinationID) { $combinationInfo = getCombinationInfo($link, $item->ID, $itemBarcode->itemCombinationID); if ($combinationInfo) { $quantityOnHand = getQuantityOnHand($link, $item->ID, $itemBarcode->itemCombinationID); $item->optionID = $combinationInfo->ID; $item->optionUUID = $combinationInfo->UUID; $item->optionEID = $combinationInfo->ExternalID; $item->optionName = $combinationInfo->Name; $item->QuantityOnHand = $quantityOnHand; } } } $unitInfo = getUnitInfo($link, $item->UnitID); if ($unitInfo) { $item->unitName = $unitInfo->name; } $itemOptions = getItemOptions($link, $item->ID); error_log(json_encode($itemOptions)); if ($itemOptions) {
<?php include_once 'config.php'; try { if (isset($_GET['optionID']) && $_GET['optionID'] != "") { $optionID = $_GET['optionID']; $itemId = $_GET['itemId']; $aOptionDetails = json_decode($_GET['aOptionDetails']); $link = new PDO($db_url, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $handle = $link->prepare('SELECT' . ' id, name, externalID' . ' FROM ' . $table_optionDetail . ' WHERE OptionID = :optionID'); $handle->bindParam(':optionID', $optionID); $handle->execute(); if (($aResult = $handle->fetchAll(PDO::FETCH_OBJ)) !== false) { for ($numberOfRow = 0; $numberOfRow < count($aResult); $numberOfRow++) { $quantity = getQuantityOnHand($aOptionDetails, $itemId, $aResult[$numberOfRow]->id, $link); $aResult[$numberOfRow]->quantity = $quantity; } error_log(json_encode($aResult)); echo json_encode($aResult); } else { echo json_encode(false); } } else { echo json_encode(false); } } catch (PDOException $ex) { error_log($ex->getMessage()); print $ex->getMessage(); } function getQuantityOnHand($aOptionDetails, $itemId, $optionDetailId, $link) {
<?php include_once 'config.php'; try { if (isset($_GET['combination']) && $_GET['combination'] != "") { $combination = $_GET['combination']; $id = $_GET['ID']; $link = new PDO($db_url, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $handle = $link->prepare('SELECT ' . $table_itemCombination . '.ID, ' . $table_itemCombination . '.UUID, ' . $table_itemCombination . '.ExternalID, Name FROM ' . $table_itemCombination . ' LEFT JOIN ' . $table_optionDetail . ' ON ' . $table_optionDetail . '.ExternalID = ' . $table_itemCombination . '.ExternalID WHERE ItemID = :ID AND ' . $table_itemCombination . '.ExternalID = :combination'); $handle->bindParam(':ID', $id); $handle->bindParam(':combination', $combination); $handle->execute(); if ($result = $handle->fetchObject()) { $result->QuantityOnHand = getQuantityOnHand($link, $id, $result->ID); echo json_encode($result); } else { echo json_encode(false); } } else { echo json_encode(false); } } catch (PDOException $ex) { error_log($ex->getMessage()); print $ex->getMessage(); } function getQuantityOnHand($link, $itemID, $combinationID) { include 'config.php'; $handle = $link->prepare('SELECT QuantityOnHand FROM ' . $table_inventoryOnHand . ' WHERE ItemID = :itemID AND ItemCombinationID = :combinationID'); $handle->bindParam(':itemID', $itemID); $handle->bindParam(':combinationID', $combinationID);
// Se busca el código en la tabla de items. $item = getItemByCode($link, $code); if ($item) { $item->basePrice = $item->Price; $unitInfo = getUnitInfo($link, $item->UnitID); if ($unitInfo) { $item->unitName = $unitInfo->name; $item->unitDecimals = $unitInfo->decimals; } if ($item->UseCombination == 1) { $itemOptions = getItemOptions($link, $item->ID); if ($itemOptions) { $item->options = $itemOptions; } } else { $quantityOnHand = getQuantityOnHand($link, $item->ID, null); $item->QuantityOnHand = $quantityOnHand; } //error_log(json_encode($item)); echo json_encode($item); } else { echo json_encode(false); } } } else { echo json_encode(false); } } catch (PDOException $ex) { error_log($ex->getMessage()); echo $ex->getMessage(); }