This commit is contained in:
Laurent Destailleur 2015-04-08 12:22:52 +02:00
parent 15ba6716f5
commit 17fa1ce5b6
2 changed files with 64 additions and 57 deletions

View File

@ -167,6 +167,8 @@ ErrorGlobalVariableUpdater2=Missing parameter '%s'
ErrorGlobalVariableUpdater3=The requested data was not found in result ErrorGlobalVariableUpdater3=The requested data was not found in result
ErrorGlobalVariableUpdater4=SOAP client failed with error '%s' ErrorGlobalVariableUpdater4=SOAP client failed with error '%s'
ErrorGlobalVariableUpdater5=No global variable selected ErrorGlobalVariableUpdater5=No global variable selected
ErrorFieldMustBeANumeric=Field <b>%s</b> must be a numeric value
ErrorFieldMustBeAnInteger=Field <b>%s</b> must be an integer
# Warnings # Warnings
WarningMandatorySetupNotComplete=Mandatory setup parameters are not yet defined WarningMandatorySetupNotComplete=Mandatory setup parameters are not yet defined

View File

@ -43,6 +43,7 @@ $id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
$rowid=GETPOST('rowid','int'); $rowid=GETPOST('rowid','int');
$action=GETPOST('action', 'alpha'); $action=GETPOST('action', 'alpha');
$cancel=GETPOST('cancel', 'alpha');
$socid=GETPOST('socid', 'int'); $socid=GETPOST('socid', 'int');
$backtopage=GETPOST('backtopage','alpha'); $backtopage=GETPOST('backtopage','alpha');
$error=0; $error=0;
@ -77,6 +78,8 @@ if (! $sortorder) $sortorder="ASC";
* Actions * Actions
*/ */
if ($cancel) $action='';
$parameters=array('socid'=>$socid, 'id_prod'=>$id); $parameters=array('socid'=>$socid, 'id_prod'=>$id);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@ -97,59 +100,70 @@ if (empty($reshook))
} }
} }
if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel")) if ($action == 'updateprice')
{ {
$id_fourn=GETPOST("id_fourn"); $id_fourn=GETPOST("id_fourn");
if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn"); if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn");
$ref_fourn=GETPOST("ref_fourn"); $ref_fourn=GETPOST("ref_fourn");
if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn"); if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn");
$quantity=GETPOST("qty"); $quantity=GETPOST("qty");
$remise_percent=price2num(GETPOST('remise_percent','alpha')); $remise_percent=price2num(GETPOST('remise_percent','alpha'));
$npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0 ; $npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0 ;
$tva_tx = str_replace('*','', GETPOST('tva_tx','alpha')); $tva_tx = str_replace('*','', GETPOST('tva_tx','alpha'));
$tva_tx = price2num($tva_tx); $tva_tx = price2num($tva_tx);
$price_expression = GETPOST('eid', 'int') ? GETPOST('eid', 'int') : ''; // Discard expression if not in expression mode $price_expression = GETPOST('eid', 'int') ? GETPOST('eid', 'int') : ''; // Discard expression if not in expression mode
$delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : ''; $delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : '';
if ($tva_tx == '') if ($tva_tx == '')
{
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("VATRateForSupplierProduct")), 'errors');
}
if (empty($quantity))
{
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")), 'errors');
}
if (empty($ref_fourn))
{
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefSupplier")), 'errors');
}
if ($id_fourn <= 0)
{
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")), 'errors');
}
if ($_POST["price"] < 0 || $_POST["price"] == '')
{
if ($price_expression === '') // Return error of missing price only if price_expression not set
{ {
$error++; $error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")), 'errors'); $langs->load("errors");
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("VATRateForSupplierProduct")), 'errors');
} }
else if (! is_numeric($tva_tx))
{ {
$_POST["price"] = 0; $error++;
$langs->load("errors");
setEventMessage($langs->trans("ErrorFieldMustBeANumeric",'eeee'), 'errors');
}
if (empty($quantity))
{
$error++;
$langs->load("errors");
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")), 'errors');
}
if (empty($ref_fourn))
{
$error++;
$langs->load("errors");
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefSupplier")), 'errors');
}
if ($id_fourn <= 0)
{
$error++;
$langs->load("errors");
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")), 'errors');
}
if ($_POST["price"] < 0 || $_POST["price"] == '')
{
if ($price_expression === '') // Return error of missing price only if price_expression not set
{
$error++;
$langs->load("errors");
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")), 'errors');
}
else
{
$_POST["price"] = 0;
}
} }
}
$product = new ProductFournisseur($db); $product = new ProductFournisseur($db);
$result=$product->fetch($id); $result=$product->fetch($id);
if ($result <= 0) if ($result <= 0)
{ {
$error++; $error++;
setEventMessage($product->error, 'errors'); setEventMessages($product->error, $product->errors, 'errors');
} }
if (! $error) if (! $error)
@ -222,13 +236,10 @@ if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel"))
$db->rollback(); $db->rollback();
} }
} }
} else
{
if (GETPOST('cancel') == $langs->trans("Cancel")) $action = 'add_price';
{ }
$action = '';
header("Location: fournisseurs.php?id=".$_GET["id"]);
exit;
} }
} }
@ -253,10 +264,6 @@ if ($id || $ref)
{ {
if ($action <> 'edit' && $action <> 're-edit') if ($action <> 'edit' && $action <> 're-edit')
{ {
/*
* En mode visu
*/
$head=product_prepare_head($product); $head=product_prepare_head($product);
$titre=$langs->trans("CardProduct".$product->type); $titre=$langs->trans("CardProduct".$product->type);
$picto=($product->type== Product::TYPE_SERVICE?'service':'product'); $picto=($product->type== Product::TYPE_SERVICE?'service':'product');
@ -325,6 +332,8 @@ if ($id || $ref)
print '<input type="hidden" name="id_fourn" value="'.$socid.'">'; print '<input type="hidden" name="id_fourn" value="'.$socid.'">';
print '<input type="hidden" name="ref_fourn" value="'.$product->fourn_ref.'">'; print '<input type="hidden" name="ref_fourn" value="'.$product->fourn_ref.'">';
print '<input type="hidden" name="ref_fourn_price_id" value="'.$rowid.'">'; print '<input type="hidden" name="ref_fourn_price_id" value="'.$rowid.'">';
print '<input type="hidden" name="rowid" value="'.$rowid.'">';
print '<input type="hidden" name="socid" value="'.$socid.'">';
} }
else else
{ {
@ -487,11 +496,7 @@ if ($id || $ref)
print '</form>'; print '</form>';
} }
/* ************************************************************************** */ // Actions buttons
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "\n<div class=\"tabsAction\">\n"; print "\n<div class=\"tabsAction\">\n";