Esempio n. 1
0
                $error = \i18n("Unable to save changes");
            }
        }
    }
}
$product = NULL;
$vatprice = "";
$price = "";
if (isset($_GET['id'])) {
    $product = \Pasteque\ProductsService::get($_GET['id']);
    $taxCat = \Pasteque\TaxesService::get($product->taxCatId);
    $tax = $taxCat->getCurrentTax();
    $vatprice = $product->priceSell * (1 + $tax->rate);
    $price = sprintf("%.2f", $product->priceSell);
}
$taxes = \Pasteque\TaxesService::getAll();
$categories = \Pasteque\CategoriesService::getAll();
$providers = \Pasteque\ProvidersService::getAll();
$level = NULL;
if ($stocks === TRUE && $product != NULL) {
    $level = \Pasteque\StocksService::getLevel($product->id);
}
?>
<h1><?php 
\pi18n("Edit a product", PLUGIN_NAME);
?>
</h1>

<?php 
\Pasteque\tpl_msg_box($message, $error);
?>
Esempio n. 2
0
/** Main csv import function given a csv object */
function import_csv($csv)
{
    $error = 0;
    $creations = 0;
    $updates = 0;
    $error_mess = array();
    $srv = new \Pasteque\TariffAreasService();
    $allAreas = $srv->getAll();
    $taxCats = \Pasteque\TaxesService::getAll();
    $areas = array();
    $areasRef = array();
    while ($tab = $csv->readLine()) {
        //check
        $area = null;
        $ref = null;
        if (isset($areas[$tab['area']])) {
            $area = $areas[$tab['area']];
            $ref = $areasRef[$tab['area']];
        } else {
            foreach ($allAreas as $a) {
                if ($a->label == $tab['area']) {
                    // Set reference for update and recreate a new to
                    // delete non imported prices
                    $areasRef[$tab['area']] = $a;
                    $area = \Pasteque\TariffArea::__build($a->id, $a->label, $a->dispOrder);
                    $areas[$tab['area']] = $area;
                    break;
                }
            }
        }
        // Create area if not found
        if ($area === null) {
            $area = new \Pasteque\TariffArea($tab['area'], 100);
            $area->id = $srv->create($area);
            if ($area->id === false) {
                $error++;
                $error_mess[] = \i18n("Line %d: Unable to create area %s", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['area']);
                continue;
            }
            $areas[$tab['area']] = $area;
            $areasRef[$tab['area']] = null;
        }
        $product = \Pasteque\ProductsService::getByRef($tab['reference']);
        if ($product === null) {
            $error++;
            $error_mess[] = \i18n("Line %d: '%s' doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['reference']);
            continue;
        }
        $taxCat = null;
        foreach ($taxCats as $tc) {
            if ($tc->id == $product->taxCatId) {
                $taxCat = $tc;
                break;
            }
        }
        // Check if price should be updated
        $priceFound = false;
        $sellPrice = $tab['sellVat'] / (1 + $taxCat->getCurrentTax()->rate);
        if ($ref !== null) {
            foreach ($ref->getPrices() as $price) {
                if ($price->productId == $product->id) {
                    // Update
                    $area->addPrice($product->id, $sellPrice);
                    $priceFound = true;
                    $updates++;
                    break;
                }
            }
        }
        if (!$priceFound) {
            // Add a price
            $area->addPrice($product->id, $sellPrice);
            $creations++;
        }
    }
    // Update data
    foreach ($areas as $name => $area) {
        if ($srv->update($area) === false) {
            $error++;
            $error_message[] = \i18n("Unable to save tariff area %d", PLUGIN_NAME, $name);
        }
    }
    $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $creations, $updates, $error);
    return array($message, $error_mess);
}