Exemplo n.º 1
0
function getCloths($groupId, $expand)
{
    global $country, $previsionCountry, $clothCountry;
    $country = isset($previsionCountry) ? $previsionCountry : $country;
    $country = isset($clothCountry) ? $clothCountry : $country;
    $condition = '';
    if (isset($groupId)) {
        $condition = ' AND c.groupId = ' . $groupId;
    }
    $query = "SELECT * FROM cloths c WHERE c.country = '{$country}' " . $condition . " ORDER BY c.name";
    $result = mysql_query($query);
    if (!$expand == 'FULL') {
        return fetch_array($result);
    }
    // FULL expand => fill also providers and previsions of the cloths
    $rows = array();
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $row['providers'] = getProviders($row['id'], $expand);
        $row['previsions'] = getPrevisions($row['id'], 'false', $expand, null, null, null, null, null);
        $row['plotters'] = getPlotters($row['id'], 'false', null, null);
        $row['djais'] = getDjais($row['id'], $expand);
        if ($expand == 'WITH_ROLLS') {
            $row['rolls'] = getClothRolls($row['id'], true);
        }
        $sumDjais = 0;
        foreach ($row['djais'] as $value) {
            $sumDjais += $value['amount'];
        }
        $row['sumDjais'] = $sumDjais;
        $intransit = getInTransit($row['id']);
        $sumInTransit = 0;
        foreach ($intransit as $order) {
            foreach ($order['products'] as $product) {
                if ($product['clothId'] == $row['id']) {
                    $sumInTransit += $product['amount'];
                }
            }
        }
        $row['sumInTransit'] = $sumInTransit;
        $tobuy = getToBuy($row['id']);
        $sumToBuy = 0;
        foreach ($tobuy as $order) {
            foreach ($order['products'] as $product) {
                if ($product['clothId'] == $row['id']) {
                    $sumToBuy += $product['amount'];
                }
            }
        }
        $row['sumToBuy'] = $sumToBuy;
        array_push($rows, $row);
    }
    return $rows;
}
Exemplo n.º 2
0
<?php

// Get list of all users or one in particualr if the id is given
include_once '../include/headers.php';
include_once '../include/dbutils.php';
include_once '../include/main.php';
include_once 'domain/cloths.php';
db_connect();
$expand = isset($_GET['expand']) ? $_GET['expand'] : null;
$clothId = isset($_GET['clothId']) ? $_GET['clothId'] : null;
if (isset($_GET['djaiNumber'])) {
    $value = getDjai($_GET['djaiNumber'], $expand);
} else {
    $value = getDjais($clothId, $expand);
}
//return JSON array
exit(json_encode($value));