Commit a51871c2 authored by Cédric Houbart's avatar Cédric Houbart
Browse files

Fix base_product module

parent f3064ff0
......@@ -59,10 +59,10 @@ function import_csv($csv) {
//check
$category = \Pasteque\CategoriesService::getByName($tab['category']);
$tax_cat = \Pasteque\TaxesService::getByName($tab['tax_cat']);
$taxCat = \Pasteque\TaxesService::getByName($tab['tax_cat']);
if ($tax_cat && $category) {
$prod = readProductLine($tab, $category, $tax_cat);
if ($taxCat && $category) {
$prod = readProductLine($tab, $category, $taxCat);
$product_exist = \Pasteque\ProductsService::getByRef($prod->reference);
if ($product_exist !== null ) {
// update product
......@@ -102,7 +102,7 @@ function import_csv($csv) {
. "category: '%s' doesn't exist", PLUGIN_NAME,
$csv->getCurrentLineNumber(), $tab['category']);
}
if (!$tax_cat) {
if (!$taxCat) {
$error_mess[] = \i18n("On line %d: "
. "Tax category: '%s' doesn't exist", PLUGIN_NAME,
$csv->getCurrentLineNumber(), $tab['tax_cat']);
......@@ -135,7 +135,7 @@ function readProductLine($line, $category, $taxCat) {
}
$product = new \Pasteque\Product($line['reference'], $line['label'],
$priceSell, $category->id, $dispOrder,
$taxCat, $visible, $scaled);
$taxCat->id, $visible, $scaled);
if (isset($line['barcode'])) {
$product->barcode = $line['barcode'];
}
......@@ -158,7 +158,7 @@ function readProductLine($line, $category, $taxCat) {
* else update stockDiarry and stockCurr.
*/
function manage_stock_level($id, $array) {
$level = \Pasteque\StocksService::getLevel($id);
$level = \Pasteque\StocksService::getLevel($id, "0", null);
$min = null;
$max = null;
if (isset($array['stock_min'])) {
......@@ -178,7 +178,7 @@ function manage_stock_level($id, $array) {
return \Pasteque\StocksService::updateLevel($level);
} else {
// Create a new level
$level = new \Pasteque\StockLevel($id, "000", $min, $max);
$level = new \Pasteque\StockLevel($id, "0", null, $min, $max);
return \Pasteque\StocksService::createLevel($level);
}
}
......
......@@ -29,6 +29,10 @@ if (isset($_POST['id'])) {
// Update tax category
$taxCat = \Pasteque\TaxCat::__build($_POST['id'], $_POST['label']);
$taxCatId = \Pasteque\TaxesService::updateCat($taxCat);
if ($taxCatId === false) {
$error = \i18n("Unable to save tax.", PLUGIN_NAME);
// Continue as taxes can be updated anyway
}
// rebuild tax rates
$taxValues = array();
foreach ($_POST as $key => $value) {
......@@ -49,7 +53,9 @@ if (isset($_POST['id'])) {
foreach ($taxValues as $id => $data) {
$tax = \Pasteque\Tax::__build($id, $taxCat->id, $data['label'],
$data['startDate'], floatval($data['rate']));
\Pasteque\TaxesService::updateTax($tax);
if (!\Pasteque\TaxesService::updateTax($tax)) {
$error = \i18n("Unable to save tax.", PLUGIN_NAME);
}
}
// new tax rate?
if (isset($_POST['label-new']) && isset($_POST['rate-new'])) {
......@@ -60,7 +66,12 @@ if (isset($_POST['id'])) {
}
$tax = new \Pasteque\Tax($_POST['id'], $_POST['label-new'],
$start, floatval($_POST['rate-new']));
\Pasteque\TaxesService::createTax($tax);
if (!\Pasteque\TaxesService::createTax($tax)) {
$error = \i18n("Unable to save tax.", PLUGIN_NAME);
}
}
if ($error === null) {
$message = \i18n("Tax saved", PLUGIN_NAME);
}
} else if (isset($_POST['label'])) {
// Create tax category
......@@ -74,15 +85,19 @@ if (isset($_POST['id'])) {
} else {
$start = \i18nRevDate($_POST['new-startDate']);
}
$tax = new \Pasteque\Tax($taxCatId, $_POST['new-label'],
$start, floatval($_POST['new-rate']));
\Pasteque\TaxesService::createTax($tax);
$tax = new \Pasteque\Tax($taxCatId, $_POST['label-new'],
$start, floatval($_POST['rate-new']));
if (\Pasteque\TaxesService::createTax($tax)) {
$message = \i18n("Tax saved", PLUGIN_NAME);
} else {
$error = \i18n("Unable to save tax.", PLUGIN_NAME);
}
}
}
$tax_cat = null;
$taxCat = null;
if (isset($_GET['id'])) {
$tax_cat = \Pasteque\TaxesService::get($_GET['id']);
$taxCat = \Pasteque\TaxesService::get($_GET['id']);
}
?>
<h1><?php \pi18n("Edit tax", PLUGIN_NAME); ?></h1>
......@@ -93,8 +108,8 @@ if (isset($_GET['id'])) {
<form class="edit" action="<?php echo \Pasteque\get_current_url(); ?>" method="post">
<fieldset>
<legend><?php \pi18n("TaxCategory"); ?></legend>
<?php \Pasteque\form_hidden("edit", $tax_cat, "id"); ?>
<?php \Pasteque\form_input("edit", "TaxCat", $tax_cat, "label", "string", array("required" => true)); ?>
<?php \Pasteque\form_hidden("edit", $taxCat, "id"); ?>
<?php \Pasteque\form_input("edit", "TaxCat", $taxCat, "label", "string", array("required" => true)); ?>
</fieldset>
<table cellpadding="0" cellspacing="0">
<thead>
......@@ -105,13 +120,13 @@ if (isset($_GET['id'])) {
</tr>
</thead>
<tbody id="list">
<?php foreach ($tax_cat->taxes as $tax) { ?>
<?php if ($taxCat !== null) { foreach ($taxCat->taxes as $tax) { ?>
<tr>
<td><?php \Pasteque\form_input($tax->id, "Tax", $tax, "label", "string", array("required" => true, "nolabel" => true, "nameid" => true)); ?></td>
<td><?php \Pasteque\form_input($tax->id, "Tax", $tax, "rate", "float", array("required" => true, "nolabel" => true, "nameid" => true)); ?></td>
<td><?php \Pasteque\form_input($tax->id, "Tax", $tax, "startDate", "date", array("required" => true, "nolabel" => true, "nameid" => true)); ?></td>
</tr>
<?php } ?>
<?php } }?>
<tr>
<td><?php \Pasteque\form_input("new", "Tax", null, "label", "string", array("nolabel" => true, "nameid" => true)); ?></td>
<td><?php \Pasteque\form_input("new", "Tax", null, "rate", "float", array("nolabel" => true, "nameid" => true)); ?></td>
......@@ -125,8 +140,8 @@ if (isset($_GET['id'])) {
</div>
</form>
<?php if ($tax_cat !== NULL) { ?>
<?php if ($taxCat !== null) { ?>
<form action="<?php echo \Pasteque\get_module_url_action(PLUGIN_NAME, 'taxes'); ?>" method="post">
<?php \Pasteque\form_delete("taxcat", $tax_cat->id); ?>
<?php \Pasteque\form_delete("taxcat", $taxCat->id); ?>
</form>
<?php } ?>
......@@ -29,6 +29,8 @@
"Rates": "Rates",
"New tax rate": "New rate",
"Unable to delete tax. Tax cannot be deleted when in use.": "Unable to delete tax. Tax cannot be deleted when in use.",
"Unable to save tax.": "Unable to save tax.",
"Tax saved": "Tax saved",
"File": "Fichier",
"send": "send",
......
......@@ -28,6 +28,8 @@
"Rates": "Taux",
"New tax rate": "Nouveau taux",
"Unable to delete tax. Tax cannot be deleted when in use.": "Impossible de supprimer la taxe. Une taxe ne peut pas être supprimée lorsqu'elle est utilisée.",
"Unable to save tax.": "Impossible d'enregistrer la taxe.",
"Tax saved": "Taxe enregistrée",
"send": "envoyer",
"File": "Fichier",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment