$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); ?> <form class="edit" action="<?php echo \Pasteque\get_current_url(); ?> " method="post" enctype="multipart/form-data">
$price = 0.0; break; } $qty = $value; if ($reason == \Pasteque\StockMove::REASON_TRANSFERT) { $destId = $_POST['destination']; $move = new \Pasteque\StockMove($time, \Pasteque\StockMove::REASON_OUT_MOVEMENT, $productId, $locationId, null, $qty, $price); $move2 = new \Pasteque\StockMove($time, \Pasteque\StockMove::REASON_IN_MOVEMENT, $productId, $destId, null, $qty, $price); if (\Pasteque\StocksService::addMove($move) && \Pasteque\StocksService::addMove($move2)) { $message = \i18n("Changes saved"); } else { $error = \i18n("Unable to save changes"); } } else { if ($reason == \Pasteque\StockMove::REASON_RESET) { $level = \Pasteque\StocksService::getLevel($productId, $locationId, null); $move = new \Pasteque\StockMove($time, $reason, $productId, $locationId, null, -$level->qty, $price); $move2 = new \Pasteque\StockMove($time, $reason, $productId, $locationId, null, $qty, $price); if (\Pasteque\StocksService::addMove($move) && \Pasteque\StocksService::addMove($move2)) { $message = \i18n("Changes saved"); } else { $error = \i18n("Unable to save changes"); } } else { $move = new \Pasteque\StockMove($time, $reason, $productId, $locationId, null, $qty, $price); if (\Pasteque\StocksService::addMove($move)) { $message = \i18n("Changes saved"); } else { $error = \i18n("Unable to save changes"); } }
/** Manage stockDiary and stockCurr whith id and location by default:"Principal" * check if fields 'stock_min' and 'stock_max' are set in array * if $create is true create a new entry in stockDiary and stockCurr in BDD * else update stockDiarry and stockCurr. */ function manage_stock_level($id, $array) { $level = \Pasteque\StocksService::getLevel($id, "0", null); $min = null; $max = null; if (isset($array['stock_min'])) { $min = $array['stock_min']; } if (isset($array['stock_max'])) { $max = $array['stock_max']; } if ($level !== null) { // Update existing level if ($min !== null) { $level->security = $min; } if ($max !== null) { $level->max = $max; } return \Pasteque\StocksService::updateLevel($level); } else { // Create a new level $level = new \Pasteque\StockLevel($id, "0", null, $min, $max); return \Pasteque\StocksService::createLevel($level); } }