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); }
function import_csv($csv) { $error_mess = array(); $update = 0; $create = 0; $error = 0; while ($tab = $csv->readLine()) { $parentOk = false; if ($tab['Parent'] !== NULL) { $parent = \Pasteque\CategoriesService::getByName($tab['Parent']); $image = NULL; if ($parent) { $parentOk = true; $tab['Parent'] = $parent->id; } } else { // Category isn't subCategory $parentOk = true; } if ($parentOk) { $cat = new \Pasteque\Category($tab['Parent'], $tab['Designation'], $image, $tab['Ordre']); $category_exist = \Pasteque\CategoriesService::getByName($cat->label); //UPDATE category if ($category_exist) { $cat->id = $category_exist->id; if (\Pasteque\CategoriesService::updateCat($cat)) { $update++; } else { $error++; $error_mess[] = \i18n("On line %d: Cannot update category: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['Designation']); } //CREATE category } else { $id = \Pasteque\CategoriesService::createCat($cat); if ($id) { $create++; } else { $error++; $error_mess[] = \i18n("On line %d: Cannot create category: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['Designation']); } } } else { $error++; $error_mess[] = \i18n("On line %d: Category parent doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber()); } } $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $create, $update, $error); $csv->close(); \Pasteque\tpl_msg_box($message, $error_mess); }
// it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Pastèque is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Pastèque. If not, see <http://www.gnu.org/licenses/>. namespace ProductBarcodes; $message = NULL; $error = NULL; $categories = \Pasteque\CategoriesService::getAll(); $allProducts = \Pasteque\ProductsService::getAll(TRUE); $products = array(); foreach ($allProducts as $product) { if ($product->barcode !== NULL && $product->barcode != "") { $products[] = $product; } } ?> <h1><?php \pi18n("Tags", PLUGIN_NAME); ?> </h1> <?php \Pasteque\tpl_msg_box($message, $error);
<?php } ?> </table> <table cellpadding="0" cellspacing="0"> <thead> <th colspan="2"><?php \pi18n("Sales by category", PLUGIN_NAME); ?> </th> </thead> <tbody> <?php foreach ($zticket->catSales as $cat) { ?> <tr> <td><?php \pi18n(\Pasteque\CategoriesService::get($cat['id'])->label, PLUGIN_NAME); ?> </td> <td class="numeric"><?php \pi18nCurr($cat['amount']); ?> </td> </tr> <?php } ?> </table> <?php
$dispOrder = 0; if ($_POST['dispOrder'] !== "") { $dispOrder = intval($_POST['dispOrder']); } $cat = new \Pasteque\Category($_POST['reference'], $parent_id, $_POST['label'], $img, $dispOrder); $id = \Pasteque\CategoriesService::createCat($cat, $img); if ($id !== FALSE) { $message = \i18n("Category saved. <a href=\"%s\">Go to the category page</a>.", PLUGIN_NAME, \Pasteque\get_module_url_action(PLUGIN_NAME, 'category_edit', array('id' => $id))); } else { $error = \i18n("Unable to save changes"); } } } $category = NULL; if (isset($_GET['id'])) { $category = \Pasteque\CategoriesService::get($_GET['id']); } ?> <h1><?php \pi18n("Edit a category", PLUGIN_NAME); ?> </h1> <?php \Pasteque\tpl_msg_box($message, $error); ?> <form class="edit" action="<?php echo \Pasteque\get_current_url(); ?> " method="post" enctype="multipart/form-data">
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) { $content[$i][] = \i18n(\Pasteque\CategoriesService::get($cat["id"]->label, PLUGIN_NAME)); $content[$i][] = $cat["amount"]; $i++; } if ($i == 1) { $content[1][] = \i18n("No payment", PLUGIN_NAME); $content[1][] = ""; } echo \Pasteque\row(\Pasteque\standardTable($content));
\Pasteque\tpl_btn('btn-add', \Pasteque\get_module_url_action(PLUGIN_NAME, "product_edit"), \i18n('Add a product', PLUGIN_NAME), 'img/btn_add.png'); \Pasteque\tpl_btn('btn-import', \Pasteque\get_module_url_action(PLUGIN_NAME, "productsManagement"), \i18n('Import products', PLUGIN_NAME), 'img/btn_add.png'); \Pasteque\tpl_btn('btn-export ', \Pasteque\get_report_url(PLUGIN_NAME, "products_export"), \i18n('Export products', PLUGIN_NAME), 'img/btn_add.png'); ?> <div id="search"> <div class="title"><?php \pi18n("Search"); ?> </div> <h5><?php \pi18n("by category", PLUGIN_NAME); ?> </h5> <?php \Pasteque\tpl_form('select', 'category', \Pasteque\CategoriesService::getAll()); ?> </div> <p><?php \pi18n("%d products", PLUGIN_NAME, $totalProducts); ?> </p> <h2><?php \pi18n("Catalog", PLUGIN_NAME); ?> </h2> <?php \Pasteque\tpl_pagination($totalProducts, $range, $start);
function printCategory($printCategory, $level, &$par) { $par = !$par; if ($printCategory->hasImage) { $imgSrc = \Pasteque\PT::URL_ACTION_PARAM . "=img&w=category&id=" . $printCategory->id; } else { $imgSrc = \Pasteque\PT::URL_ACTION_PARAM . "=img&w=category"; } ?> <tr class="row-<?php echo $par ? 'par' : 'odd'; ?> "> <td> <?php for ($i = 0; $i < $level; $i++) { echo " "; } ?> <img class="thumbnail" src="?<?php echo $imgSrc; ?> " /> <td><?php echo $printCategory->label; ?> </td> <td class="edition"> <?php \Pasteque\tpl_btn("edition", \Pasteque\get_module_url_action(PLUGIN_NAME, 'category_edit', array("id" => $printCategory->id)), "", 'img/edit.png', \i18n('Edit'), \i18n('Edit')); ?> <form action="<?php echo \Pasteque\get_current_url(); ?> " method="post"><?php \Pasteque\form_delete("cat", $printCategory->id, \Pasteque\get_template_url() . 'img/delete.png'); ?> </form> </td> </tr> <?php $categories = \Pasteque\CategoriesService::getChildren($printCategory->id); $level++; foreach ($categories as $childCategory) { printCategory($childCategory, $level, $par); } }
public function __construct($report, $values) { $this->data = array(); $this->i = 0; $countedStock = array(); if (!isset($values['location'])) { $locSrv = new \Pasteque\LocationsService(); $locations = $locSrv->getAll(); $defaultLocationId = $locations[0]->id; $values['location'] = $defaultLocationId; } foreach ($values as $key => $value) { if (strpos($key, "qty-") === 0) { $productId = substr($key, 4); $qty = $value; $countedStock[$productId] = $qty; } } $categories = \Pasteque\CategoriesService::getAll(); $products = \Pasteque\ProductsService::getAll(TRUE); $prdCat = array(); // Build listing by categories foreach ($products as $product) { if ($product->categoryId !== \Pasteque\CompositionsService::CAT_ID) { $prdCat[$product->categoryId][] = $product; } } // Get stock to compare with counted stock $levels = array(); $rawLevels = \Pasteque\StocksService::getLevels($values['location']); foreach ($rawLevels as $level) { $levels[$level->productId] = $level; } foreach ($categories as $category) { if (isset($prdCat[$category->id])) { foreach ($prdCat[$category->id] as $product) { $counted = 0; if (isset($countedStock[$product->id])) { $counted = $countedStock[$product->id]; } $actual = 0; if (isset($levels[$product->id])) { $actual = $levels[$product->id]->qty; } if ($counted !== $actual) { $this->data[] = array("ref" => $product->reference, "counted" => $counted, "actual" => $actual, "diff" => $counted - $actual); } } } } }