function import_csv($csv) { $error = 0; $create = 0; $update = 0; $error_mess = array(); while ($tab = $csv->readLine()) { //init optionnal values $AllKeyPossible = array_merge($csv->getKeys(), $csv->getOptionalKeys()); $tab = initArray($AllKeyPossible, $tab); //check $category = \Pasteque\CategoriesService::getByName($tab['category']); $taxCat = \Pasteque\TaxesService::getByName($tab['tax_cat']); if ($taxCat && $category) { $prod = readProductLine($tab, $category, $taxCat); $product_exist = \Pasteque\ProductsService::getByRef($prod->reference); if ($product_exist !== null) { // update product $prod->id = $product_exist->id; $prod = mergeProduct($product_exist, $prod); //if update imposible an is occurred if (!\Pasteque\ProductsService::update($prod)) { $error++; $error_mess[] = \i18n("On line %d: " . "Cannot update product: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['label']); } else { // update stock_curr and stock_diary manage_stock_level($prod->id, $tab, FALSE); $update++; } } else { // create product $id = \Pasteque\ProductsService::create($prod); if ($id) { //create stock_curr and stock diary manage_stock_level($id, $tab, TRUE); $create++; } else { $error++; $error_mess[] = \i18n("On line %d: " . "Cannot create product: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['label']); } } } else { // Missing category or tax category $error++; if (!$category) { $error_mess[] = \i18n("On line %d " . "category: '%s' doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['category']); } if (!$taxCat) { $error_mess[] = \i18n("On line %d: " . "Tax category: '%s' doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['tax_cat']); } } } $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $create, $update, $error); return array($message, $error_mess); }
$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); ?>
/** 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); }
<td><?php \pi18n("Base", PLUGIN_NAME); ?> </td> <td><?php \pi18n("Amount", PLUGIN_NAME); ?> </td> </thead> <tbody> <?php foreach ($zticket->taxes as $tax) { ?> <tr> <td><?php echo \Pasteque\TaxesService::getTax($tax['id'])->label; ?> </td> <td class="numeric"><?php \pi18nCurr($tax['base']); ?> </td> <td class="numeric"><?php \pi18nCurr($tax['amount']); ?> </td> </tr> <?php } ?> </table>
// Add line var html = "<tr id=\"line-" + product['id'] + "\">\n"; html += "<td><img class=\"thumbnail\" src=\"" + product['img'] + "\" /></td>\n"; html += "<td>" + product['reference'] + "</td>\n"; html += "<td>" + product['label'] + "</td>\n"; html += "<td>" + product['vatSell'] + "</td>\n"; html += "<td class=\"price-cell\"><input class=\"price\" id=\"line-" + product['id'] + "\" type=\"numeric\" name=\"price-" + product['id'] + "\" value=\"" + price + "\" />\n"; html += "<td><a class=\"btn-delete\" href=\"\" onClick=\"javascript:deleteLine('" + product['id'] + "');return false;\"><?php \pi18n("Delete"); ?> </a></td>\n"; html += "</tr>\n"; jQuery("#list").append(html); } } jQuery(document).ready(function() { <?php if ($area !== null) { foreach ($area->getPrices() as $price) { $product = \Pasteque\ProductsService::get($price->productId); $taxCat = \Pasteque\TaxesService::get($product->taxCatId); $tax = $taxCat->getCurrentTax(); $vatPrice = $price->price * (1 + $tax->rate); echo "\t\tinitProduct(\"" . $price->productId . "\", " . $vatPrice . ");\n"; } } ?> }); </script> <?php
if (isset($_POST['discountRate'])) { $discountEnabled = isset($_POST['discountEnabled']) ? 1 : 0; $discountRate = $_POST['discountRate']; } $cmp = new \Pasteque\Product($_POST['reference'], $_POST['label'], $_POST['realsell'], $catId, null, $dispOrder, $taxCatId, $visible, $scaled, $_POST['priceBuy'], null, $_POST['barcode'], $img !== null, $discountEnabled, $discountRate); $cmp->groups = parseSubgroups($_POST['subgroupData'], $products); if (\Pasteque\CompositionsService::create($cmp, $img, null)) { $message = \i18n("Changes saved", PLUGIN_NAME); } else { $error = \i18n("Unable to save changes", PLUGIN_NAME); } } } if (isset($_GET['productId'])) { $composition = \Pasteque\CompositionsService::get($_GET['productId']); $taxCat = \Pasteque\TaxesService::get($composition->taxCatId); $tax = $taxCat->getCurrentTax(); $vatprice = $composition->priceSell * (1 + $tax->rate); $price = sprintf("%.2f", $composition->priceSell); } else { $vatprice = ""; $price = ""; $composition = NULL; } ?> <h1><?php \pi18n('Composition edit', PLUGIN_NAME); ?> </h1>
$content[$i][] = \i18n($payment->type); $content[$i][] = $amount; $i++; } if ($i == 0) { $content[1][] = \i18n("No payment", PLUGIN_NAME); $content[1][] = ""; } echo \Pasteque\row(\Pasteque\standardTable($content)); unset($content); $content[0][] = \i18n("Taxes", PLUGIN_NAME); $content[0][] = \i18n("Base", PLUGIN_NAME); $content[0][] = \i18n("Amount", PLUGIN_NAME); $i = 1; foreach ($zticket->taxes as $tax) { $content[$i][] = \Pasteque\TaxesService::getTax($tax["id"])->label; $content[$i][] = \i18nCurr($tax['base']); $content[$i][] = \i18nCurr($tax['amount']); $i++; } if ($i == 1) { $content[1][] = \i18n("No payment", PLUGIN_NAME); $content[1][] = ""; $content[1][] = ""; } echo \Pasteque\row(\Pasteque\standardTable($content)); unset($content); $content[0][] = \i18n("Sales by category", PLUGIN_NAME); $content[0][] = \i18n("Amount", PLUGIN_NAME); $i = 1; foreach ($zticket->catSales as $cat) {
$start = \i18nRevDate($_POST['new-startDate']); } $taxCat = new \Pasteque\TaxCat($_POST['label']); $tax = new \Pasteque\Tax(null, $_POST['label-new'], $start, floatval($_POST['rate-new'])); $taxCat->addTax($tax); $taxCatId = \Pasteque\TaxesService::createCat($taxCat); if ($taxCatId === false) { $error = \i18n("Unable to save tax.", PLUGIN_NAME); } else { $message = \i18n("Tax saved", PLUGIN_NAME); } } } $taxCat = null; if (isset($_GET['id'])) { $taxCat = \Pasteque\TaxesService::get($_GET['id']); } ?> <h1><?php \pi18n("Edit tax", PLUGIN_NAME); ?> </h1> <?php \Pasteque\tpl_msg_box($message, $error); ?> <!-- Tax category edit --> <form class="edit" action="<?php echo \Pasteque\get_current_url(); ?>