示例#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;
}
示例#2
0
function fillClothDisponibility(&$clothsDisponibility, $clothId)
{
    // check if we already have the values in the array
    $c = findClothById($clothId, $clothsDisponibility);
    if (!$c) {
        $c = new stdClass();
        $c->id = $clothId;
        $sumInTransit = 0;
        $inTransitType = array();
        foreach (getInTransit($clothId) as $order) {
            foreach ($order['products'] as $product) {
                if ($product['clothId'] == $clothId) {
                    $sumInTransit += $product['amount'];
                    // $inTransitType = $order['deliveryType'];
                    $transit = new stdClass();
                    $transit->type = $order['deliveryType'];
                    $transit->amount = $product['amount'];
                    $transit->used = 0;
                    array_push($inTransitType, $transit);
                }
            }
        }
        $c->mtsInTransit = $sumInTransit;
        $c->inTransitType = $inTransitType;
        // available stock (available in rolls - plotters)
        $providers = getProviders($clothId);
        $sumAvailable = 0;
        foreach ($providers as $provider) {
            $sumAvailable += $provider['stock'];
        }
        $plotters = getPlotters($clothId, 'false', null, null);
        $sumPlotters = 0;
        foreach ($plotters as $plotter) {
            $sumPlotters += $plotter['mtsDesign'];
        }
        $c->mtsAvailable = $sumAvailable;
        // - $sumPlotters; // we dont rest the plotters, we consider available if still in plotter
        $c->mtsPlotter = $sumPlotters;
        // extra info for the second iteration of ufa and uft set
        $c->totalUFA = 0;
        $c->totalUFT = 0;
        $c->sumNewUFA = 0;
        $c->sumNewUFT = 0;
        array_push($clothsDisponibility, $c);
    }
}