<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
ini_set('display_errors', '1');

require_once("modules/EcmStockStates/EcmStockState.php");
$ss = new EcmStockState();

set_time_limit(1000000);

if (!isset($_GET['code'])) {
    die("A kody produktów to kto ma podać? AI?");
}

$codes = explode(",", $_GET['code']);
var_dump($codes);
$db = $GLOBALS['db'];
foreach ($codes as $code) {

    if ($code == "") continue;
    $p = $db->fetchByAssoc($db->query("select id from ecmproducts where code like '%" . $code . "' and deleted='0'"));

    echo $p['id'];
    $w = $db->query("select id from ecmstocks where deleted='0'");
    while ($r = $db->fetchByAssoc($w)) {

        $ss->UpdateStockState($r['id'], $p['id']);
    }
    $w = $db->query("select quantity,stock_name,price,product_code from ecmstockstates where product_id='" . $p['id'] . "' and deleted='0'");
    while ($s = $db->fetchByAssoc($w)) {
        echo $s['product_code'] . " " . $s['stock_name'] . " " . $s['quantity'] . " " . $s['price'] . "<br>";
    }
}