include_once '../include/main.php'; include_once 'domain/rolls.php'; db_connect(); $expand = isset($_GET['expand']) ? $_GET['expand'] : null; if (isset($_GET['id'])) { $value = getRolls($_GET['id']); } else { if (isset($_GET['all'])) { $distincts = isset($_GET['distincts']) ? $_GET['distincts'] : false; $value = getAllRolls($distincts); } else { if (isset($_GET['possibleRolls'])) { $value = getPossibleRolls($_GET['clothId'], $_GET['plotterId'], $_GET['cutId']); } else { if (isset($_GET['lotes'])) { $value = getRollLotes($_GET['rollNumber']); } else { if (isset($_GET['cuts'])) { // all the cuts of the given roll $rollId = isset($_GET['rollId']) ? $_GET['rollId'] : null; $clothId = isset($_GET['clothId']) ? $_GET['clothId'] : null; $value = getRollCuts($rollId, $clothId); } else { $value = getRolls($_GET['productId'], $_GET['orderId']); } } } } } //return JSON array exit(json_encode($value));
function getProducts($providerId, $productId) { global $country; $productCondition = ""; if (isset($productId)) { $productCondition = " AND productId = '" . $productId . "'"; } $query = "SELECT p.*, c.name, c.id as clothId FROM products p join cloths c on c.id = p.clothId WHERE p.providerId = '{$providerId}' {$productCondition} ORDER BY c.name"; $result = mysql_query($query); $productsResult = fetch_array($result); $products = array(); foreach ($productsResult as $product) { $product['rolls'] = getRolls($product['productId'], null); // sum stock using rolls of the cloth and only rolls already here (incoming=false) $sumStock = 0; $sumStockTemp = 0; $sumStockDef = 0; foreach ($product['rolls'] as $value) { $sumStock += $value['mts']; if ($value['type'] == 'TEMP') { $sumStockTemp += $value['mts']; } if ($value['type'] == 'DEF') { $sumStockDef += $value['mts']; } } // sum to the stock manual enterings $manuals = getManualStocks($product['productId']); foreach ($manuals as $value) { $sumStock += $value['mts']; if ($value['type'] == 'TEMP') { $sumStockTemp += $value['mts']; } if ($value['type'] == 'DEF') { $sumStockDef += $value['mts']; } } $product['stock'] = $sumStock; $product['stockTemp'] = $sumStockTemp; $product['stockDef'] = $sumStockDef; array_push($products, $product); } return $products; }