Fix: form is not allowed into a table. This break some javascript and

make some browsers crazy.
This commit is contained in:
Laurent Destailleur 2013-11-17 23:25:25 +01:00
parent 45aac81b71
commit 48570f599a
11 changed files with 2086 additions and 1919 deletions

View File

@ -634,13 +634,27 @@ else if ($action == "setabsolutediscount" && $user->rights->propal->creer)
} }
// Add line // Add line
else if ($action == "addline" && $user->rights->propal->creer) else if (($action == 'addline' || $action == 'addline_predef') && $user->rights->propal->creer)
{ {
$idprod=GETPOST('idprod', 'int'); // Set if we used free entry or predefined product
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):''))); if (GETPOST('addline_libre'))
$price_ht = GETPOST('price_ht'); {
$tva_tx = (GETPOST('tva_tx')?GETPOST('tva_tx'):0); $predef='';
$predef=((! empty($idprod) && $conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : ''); $idprod=0;
$product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
$price_ht = GETPOST('price_ht');
$tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
}
if (GETPOST('addline_predefined'))
{
$predef=(($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
$idprod=GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):''));
$price_ht = '';
$tva_tx = '';
}
$qty = GETPOST('qty'.$predef);
$remise_percent=GETPOST('remise_percent'.$predef);
//Extrafields //Extrafields
$extrafieldsline = new ExtraFields($db); $extrafieldsline = new ExtraFields($db);
@ -673,7 +687,7 @@ else if ($action == "addline" && $user->rights->propal->creer)
$error++; $error++;
} }
if (! $error && (GETPOST('qty') >= 0) && (! empty($product_desc) || ! empty($idprod))) if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod)))
{ {
$pu_ht=0; $pu_ht=0;
$pu_ttc=0; $pu_ttc=0;
@ -791,8 +805,8 @@ else if ($action == "addline" && $user->rights->propal->creer)
} }
// Margin // Margin
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):''); $fournprice=(GETPOST('fournprice'.$predef)?GETPOST('fournprice'.$predef):'');
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); $buyingprice=(GETPOST('buying_price'.$predef)?GETPOST('buying_price'.$predef):'');
$date_start=dol_mktime(0, 0, 0, GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_start=dol_mktime(0, 0, 0, GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
$date_end=dol_mktime(0, 0, 0, GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); $date_end=dol_mktime(0, 0, 0, GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
@ -804,7 +818,7 @@ else if ($action == "addline" && $user->rights->propal->creer)
$info_bits=0; $info_bits=0;
if ($tva_npr) $info_bits |= 0x01; if ($tva_npr) $info_bits |= 0x01;
if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) if (! empty($price_min) && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min)))
{ {
$mesg = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency)); $mesg = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency));
setEventMessage($mesg, 'errors'); setEventMessage($mesg, 'errors');
@ -815,12 +829,12 @@ else if ($action == "addline" && $user->rights->propal->creer)
$result=$object->addline( $result=$object->addline(
$desc, $desc,
$pu_ht, $pu_ht,
GETPOST('qty'), $qty,
$tva_tx, $tva_tx,
$localtax1_tx, $localtax1_tx,
$localtax2_tx, $localtax2_tx,
$idprod, $idprod,
GETPOST('remise_percent'), $remise_percent,
$price_base_type, $price_base_type,
$pu_ttc, $pu_ttc,
$info_bits, $info_bits,
@ -854,7 +868,6 @@ else if ($action == "addline" && $user->rights->propal->creer)
unset($_POST['qty']); unset($_POST['qty']);
unset($_POST['type']); unset($_POST['type']);
unset($_POST['idprod']);
unset($_POST['remise_percent']); unset($_POST['remise_percent']);
unset($_POST['price_ht']); unset($_POST['price_ht']);
unset($_POST['price_ttc']); unset($_POST['price_ttc']);
@ -866,10 +879,16 @@ else if ($action == "addline" && $user->rights->propal->creer)
unset($_POST['buying_price']); unset($_POST['buying_price']);
unset($_POST['np_marginRate']); unset($_POST['np_marginRate']);
unset($_POST['np_markRate']); unset($_POST['np_markRate']);
// old method
unset($_POST['np_desc']);
unset($_POST['dp_desc']); unset($_POST['dp_desc']);
unset($_POST['idprod']);
unset($_POST['qty_predef']);
unset($_POST['remise_percent_predef']);
unset($_POST['fournprice_predef']);
unset($_POST['buying_price_predef']);
unset($_POST['np_marginRate_predef']);
unset($_POST['np_markRate_predef']);
unset($_POST['np_desc']);
} }
else else
{ {
@ -1162,7 +1181,7 @@ else if ($action == 'update_extras')
$ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if($ret < 0) $error++; if($ret < 0) $error++;
if (! $error) if (! $error)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
@ -1179,7 +1198,7 @@ else if ($action == 'update_extras')
} }
else if ($reshook < 0) $error++; else if ($reshook < 0) $error++;
} }
if ($error) $action = 'edit_extras'; if ($error) $action = 'edit_extras';
} }
@ -1924,11 +1943,11 @@ else
print '<input type="hidden" name="attribute" value="'.$key.'">'; print '<input type="hidden" name="attribute" value="'.$key.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
print $extrafields->showInputField($key,$value); print $extrafields->showInputField($key,$value);
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">'; print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>'; print '</form>';
} }
else else
@ -2003,15 +2022,25 @@ else
* Lines * Lines
*/ */
// Show object lines
$result = $object->getLinesArray();
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">
<input type="hidden" name="action" value="'.(($action != 'editline')?'addline':'updateligne').'">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="'.$object->id.'">
';
if (! empty($conf->use_javascript_ajax) && $object->statut == 0) if (! empty($conf->use_javascript_ajax) && $object->statut == 0)
{ {
include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
} }
print '<table id="tablelines" class="noborder" width="100%">'; print '<table id="tablelines" class="noborder noshadow" width="100%">';
// Show object lines
$result = $object->getLinesArray();
if (! empty($object->lines)) if (! empty($object->lines))
$ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1); $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1);
@ -2047,8 +2076,9 @@ else
print '</table>'; print '</table>';
print '</div>'; print "</form>\n";
print "\n";
dol_fiche_end();
if ($action == 'statut') if ($action == 'statut')
{ {

View File

@ -323,7 +323,7 @@ else if ($action == 'add' && $user->rights->commande->creer)
$lines[$i]->fetch_optionals($lines[$i]->rowid); $lines[$i]->fetch_optionals($lines[$i]->rowid);
$array_option=$lines[$i]->array_options; $array_option=$lines[$i]->array_options;
} }
$result = $object->addline( $result = $object->addline(
$desc, $desc,
$lines[$i]->subprice, $lines[$i]->subprice,
@ -564,18 +564,31 @@ else if ($action == 'setnote_private' && $user->rights->commande->creer)
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
/* // Add a new line
* Ajout d'une ligne produit dans la commande
*/
else if ($action == 'addline' && $user->rights->commande->creer) else if ($action == 'addline' && $user->rights->commande->creer)
{ {
$langs->load('errors'); $langs->load('errors');
$error = false; $error = false;
$idprod=GETPOST('idprod', 'int'); // Set if we used free entry or predefined product
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):''))); if (GETPOST('addline_libre'))
$price_ht = GETPOST('price_ht'); {
$tva_tx = (GETPOST('tva_tx')?GETPOST('tva_tx'):0); $predef='';
$idprod=0;
$product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
$price_ht = GETPOST('price_ht');
$tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
}
if (GETPOST('addline_predefined'))
{
$predef=(($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
$idprod=GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):''));
$price_ht = '';
$tva_tx = '';
}
$qty = GETPOST('qty'.$predef);
$remise_percent=GETPOST('remise_percent'.$predef);
//Extrafields //Extrafields
$extrafieldsline = new ExtraFields($db); $extrafieldsline = new ExtraFields($db);
@ -591,7 +604,7 @@ else if ($action == 'addline' && $user->rights->commande->creer)
} }
} }
if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && (GETPOST('qty') < 0)) if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && ($qty < 0))
{ {
setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors'); setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors');
$error = true; $error = true;
@ -606,7 +619,7 @@ else if ($action == 'addline' && $user->rights->commande->creer)
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
$error++; $error++;
} }
if (! GETPOST('qty') && GETPOST('qty') == '') if ($qty == '')
{ {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors'); setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
$error = true; $error = true;
@ -617,10 +630,9 @@ else if ($action == 'addline' && $user->rights->commande->creer)
$error = true; $error = true;
} }
if (! $error && (GETPOST('qty') >= 0) && (! empty($product_desc) || ! empty($idprod))) if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod)))
{ {
// Clean parameters // Clean parameters
$predef=((! empty($idprod) && $conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
$date_start=dol_mktime(0, 0, 0, GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_start=dol_mktime(0, 0, 0, GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
$date_end=dol_mktime(0, 0, 0, GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); $date_end=dol_mktime(0, 0, 0, GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
$price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT'); $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT');
@ -737,8 +749,8 @@ else if ($action == 'addline' && $user->rights->commande->creer)
} }
// Margin // Margin
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):''); $fournprice=(GETPOST('fournprice'.$predef)?GETPOST('fournprice'.$predef):'');
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); $buyingprice=(GETPOST('buying_price'.$predef)?GETPOST('buying_price'.$predef):'');
// Local Taxes // Local Taxes
$localtax1_tx= get_localtax($tva_tx, 1, $object->client); $localtax1_tx= get_localtax($tva_tx, 1, $object->client);
@ -749,7 +761,7 @@ else if ($action == 'addline' && $user->rights->commande->creer)
$info_bits=0; $info_bits=0;
if ($tva_npr) $info_bits |= 0x01; if ($tva_npr) $info_bits |= 0x01;
if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) if (! empty($price_min) && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min)))
{ {
$mesg = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency)); $mesg = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency));
setEventMessage($mesg, 'errors'); setEventMessage($mesg, 'errors');
@ -760,12 +772,12 @@ else if ($action == 'addline' && $user->rights->commande->creer)
$result = $object->addline( $result = $object->addline(
$desc, $desc,
$pu_ht, $pu_ht,
GETPOST('qty'), $qty,
$tva_tx, $tva_tx,
$localtax1_tx, $localtax1_tx,
$localtax2_tx, $localtax2_tx,
$idprod, $idprod,
GETPOST('remise_percent'), $remise_percent,
$info_bits, $info_bits,
0, 0,
$price_base_type, $price_base_type,
@ -803,7 +815,6 @@ else if ($action == 'addline' && $user->rights->commande->creer)
unset($_POST['qty']); unset($_POST['qty']);
unset($_POST['type']); unset($_POST['type']);
unset($_POST['idprod']);
unset($_POST['remise_percent']); unset($_POST['remise_percent']);
unset($_POST['price_ht']); unset($_POST['price_ht']);
unset($_POST['price_ttc']); unset($_POST['price_ttc']);
@ -815,10 +826,16 @@ else if ($action == 'addline' && $user->rights->commande->creer)
unset($_POST['buying_price']); unset($_POST['buying_price']);
unset($_POST['np_marginRate']); unset($_POST['np_marginRate']);
unset($_POST['np_markRate']); unset($_POST['np_markRate']);
// old method
unset($_POST['np_desc']);
unset($_POST['dp_desc']); unset($_POST['dp_desc']);
unset($_POST['idprod']);
unset($_POST['qty_predef']);
unset($_POST['remise_percent_predef']);
unset($_POST['fournprice_predef']);
unset($_POST['buying_price_predef']);
unset($_POST['np_marginRate_predef']);
unset($_POST['np_markRate_predef']);
unset($_POST['np_desc']);
} }
else else
{ {
@ -1182,7 +1199,7 @@ else if ($action == 'update_extras')
$ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if($ret < 0) $error++; if($ret < 0) $error++;
if (! $error) if (! $error)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
@ -1199,7 +1216,7 @@ else if ($action == 'update_extras')
} }
else if ($reshook < 0) $error++; else if ($reshook < 0) $error++;
} }
if ($error) $action = 'edit_extras'; if ($error) $action = 'edit_extras';
} }
@ -1449,7 +1466,7 @@ if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->righ
/* /*
* View * View
*/ */
llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes'); llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
@ -1460,9 +1477,9 @@ $formorder = new FormOrder($db);
/********************************************************************* /*********************************************************************
* *
* Mode creation * Mode creation
* *
*********************************************************************/ *********************************************************************/
if ($action == 'create' && $user->rights->commande->creer) if ($action == 'create' && $user->rights->commande->creer)
{ {
print_fiche_titre($langs->trans('CreateOrder')); print_fiche_titre($langs->trans('CreateOrder'));
@ -1506,7 +1523,7 @@ if ($action == 'create' && $user->rights->commande->creer)
$objectsrc->fetch($originid); $objectsrc->fetch($originid);
if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines();
$objectsrc->fetch_thirdparty(); $objectsrc->fetch_thirdparty();
//Replicate extrafields //Replicate extrafields
$objectsrc->fetch_optionals($originid); $objectsrc->fetch_optionals($originid);
$object->array_options=$objectsrc->array_options; $object->array_options=$objectsrc->array_options;
@ -2311,25 +2328,34 @@ else
/* /*
* Lines * Lines
*/ */
$result = $object->getLinesArray(); $result = $object->getLinesArray();
$numlines = count($object->lines);
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">
<input type="hidden" name="action" value="'.(($action != 'editline')?'addline':'updateligne').'">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="'.$object->id.'">
';
if (! empty($conf->use_javascript_ajax) && $object->statut == 0) if (! empty($conf->use_javascript_ajax) && $object->statut == 0)
{ {
include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
} }
print '<table id="tablelines" class="noborder" width="100%">'; print '<table id="tablelines" class="noborder noshadow" width="100%">';
// Show object lines // Show object lines
if (! empty($object->lines)) if (! empty($object->lines))
$ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1); $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1);
$numlines = count($object->lines);
/* /*
* Form to add new line * Form to add new line
*/ */
if ($object->statut == 0 && $user->rights->commande->creer) if ($object->statut == 0 && $user->rights->commande->creer)
{ {
if ($action != 'editline') if ($action != 'editline')
@ -2359,7 +2385,10 @@ else
} }
} }
print '</table>'; print '</table>';
print '</div>';
print "</form>\n";
dol_fiche_end();
/* /*

File diff suppressed because it is too large Load Diff

View File

@ -999,6 +999,9 @@ class Contrat extends CommonObject
$pu=$pu_ttc; $pu=$pu_ttc;
} }
// Check parameters
if (empty($remise_percent)) $remise_percent=0;
// Calcul du total TTC et de la TVA pour la ligne a partir de // Calcul du total TTC et de la TVA pour la ligne a partir de
// qty, pu, remise_percent et txtva // qty, pu, remise_percent et txtva
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker

View File

@ -158,9 +158,9 @@ if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear'))
$datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
} }
// Add contract
if ($action == 'add' && $user->rights->contrat->creer) if ($action == 'add' && $user->rights->contrat->creer)
{ {
// Check // Check
if (empty($datecontrat)) if (empty($datecontrat))
{ {
@ -339,9 +339,30 @@ else if ($action == 'classin' && $user->rights->contrat->creer)
$object->setProject(GETPOST('projectid')); $object->setProject(GETPOST('projectid'));
} }
// Add a new line
else if ($action == 'addline' && $user->rights->contrat->creer) else if ($action == 'addline' && $user->rights->contrat->creer)
{ {
if (! GETPOST('qty')) // Set if we used free entry or predefined product
if (GETPOST('addline_libre'))
{
$predef='';
$idprod=0;
$product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
$price_ht = GETPOST('price_ht');
$tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
}
if (GETPOST('addline_predefined'))
{
$predef=(($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
$idprod=GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):''));
$price_ht = '';
$tva_tx = '';
}
$qty = GETPOST('qty'.$predef);
$remise_percent=GETPOST('remise_percent'.$predef);
if ($qty == '')
{ {
setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")),'errors'); setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")),'errors');
$error++; $error++;
@ -362,41 +383,19 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
} }
$ret=$object->fetch_thirdparty(); $ret=$object->fetch_thirdparty();
$date_start=''; // Clean parameters
$date_end=''; $date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
// Si ajout champ produit libre $date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
if (GETPOST('mode') == 'libre') $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT');
{
if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear'))
{
$date_start=dol_mktime(GETPOST('date_start_slhour'), GETPOST('date_start_slmin'), 0, GETPOST('date_start_slmonth'), GETPOST('date_start_slday'), GETPOST('date_start_slyear'));
}
if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear'))
{
$date_end=dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear'));
}
}
// Si ajout champ produit predefini
if (GETPOST('mode') == 'predefined')
{
if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear'))
{
$date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
}
if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear'))
{
$date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
}
}
// Ecrase $pu par celui du produit // Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit // Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit // Ecrase $txtva par celui du produit
// Ecrase $base_price_type par celui du produit // Ecrase $base_price_type par celui du produit
if (GETPOST('idprod')) if ($idprod > 0)
{ {
$prod = new Product($db); $prod = new Product($db);
$prod->fetch(GETPOST('idprod')); $prod->fetch($idprod);
$tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id); $tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id);
$tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id); $tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id);
@ -426,22 +425,21 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
} }
else else
{ {
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
} }
} }
$desc = $prod->description; $desc=$prod->description;
$desc.= $prod->description && GETPOST('np_desc') ? "\n" : ""; $desc=dol_concatdesc($desc,$product_desc);
$desc.= GETPOST('np_desc');
} }
else else
{ {
$pu_ht=GETPOST('price_ht'); $pu_ht=GETPOST('price_ht');
$price_base_type = 'HT'; $price_base_type = 'HT';
$tva_tx=GETPOST('tva_tx')?str_replace('*','',GETPOST('tva_tx')):0; // tva_tx field may be disabled, so we use vat rate 0 $tva_tx=GETPOST('tva_tx')?str_replace('*','',GETPOST('tva_tx')):0; // tva_tx field may be disabled, so we use vat rate 0
$tva_npr=preg_match('/\*/',GETPOST('tva_tx'))?1:0; $tva_npr=preg_match('/\*/',GETPOST('tva_tx'))?1:0;
$desc=GETPOST('dp_desc'); $desc=$product_desc;
} }
$localtax1_tx=get_localtax($tva_tx,1,$object->societe); $localtax1_tx=get_localtax($tva_tx,1,$object->societe);
@ -457,23 +455,23 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
$info_bits=0; $info_bits=0;
if ($tva_npr) $info_bits |= 0x01; if ($tva_npr) $info_bits |= 0x01;
if($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) if($price_min && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min)))
{ {
$object->error = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency)); $object->error = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency));
$result = -1 ; $result = -1 ;
} }
else else
{ {
// Insert line // Insert line
$result = $object->addline( $result = $object->addline(
$desc, $desc,
$pu_ht, $pu_ht,
GETPOST('qty'), $qty,
$tva_tx, $tva_tx,
$localtax1_tx, $localtax1_tx,
$localtax2_tx, $localtax2_tx,
GETPOST('idprod'), $idprod,
GETPOST('remise_percent'), $remise_percent,
$date_start, $date_start,
$date_end, $date_end,
$price_base_type, $price_base_type,
@ -506,7 +504,6 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
unset($_POST['qty']); unset($_POST['qty']);
unset($_POST['type']); unset($_POST['type']);
unset($_POST['idprod']);
unset($_POST['remise_percent']); unset($_POST['remise_percent']);
unset($_POST['price_ht']); unset($_POST['price_ht']);
unset($_POST['price_ttc']); unset($_POST['price_ttc']);
@ -516,6 +513,16 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
unset($_POST['product_desc']); unset($_POST['product_desc']);
unset($_POST['fournprice']); unset($_POST['fournprice']);
unset($_POST['buying_price']); unset($_POST['buying_price']);
unset($_POST['dp_desc']);
unset($_POST['idprod']);
unset($_POST['qty_predef']);
unset($_POST['remise_percent_predef']);
unset($_POST['fournprice_predef']);
unset($_POST['buying_price_predef']);
unset($_POST['np_marginRate_predef']);
unset($_POST['np_markRate_predef']);
unset($_POST['np_desc']);
} }
else else
{ {
@ -948,7 +955,7 @@ else
if ($action == 'delete') if ($action == 'delete')
{ {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete",'',0,1); print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete",'',0,1);
} }
/* /*
@ -969,7 +976,7 @@ else
$text=$langs->trans('ConfirmValidateContract',$numref); $text=$langs->trans('ConfirmValidateContract',$numref);
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ValidateAContract"),$text,"confirm_valid",'',0,1); print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ValidateAContract"),$text,"confirm_valid",'',0,1);
} }
/* /*
@ -978,7 +985,7 @@ else
if ($action == 'close') if ($action == 'close')
{ {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1); print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1);
} }
/* /*
@ -1306,6 +1313,7 @@ else
} }
print "</table>"; print "</table>";
print "</form>\n"; print "</form>\n";
@ -1472,6 +1480,7 @@ else
* Desactiver la ligne de contrat * Desactiver la ligne de contrat
*/ */
print '<form name="closeline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.$object->lines[$cursorline-1]->id.'&amp;action=closeline" method="post">'; print '<form name="closeline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.$object->lines[$cursorline-1]->id.'&amp;action=closeline" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
@ -1525,13 +1534,22 @@ else
} }
//print '</table>'; //print '</table>';
// Form to add new line // Form to add new line
if ($user->rights->contrat->creer && ($object->statut >= 0)) if ($user->rights->contrat->creer && ($object->statut >= 0))
{ {
$dateSelector=1; $dateSelector=1;
print '<br>'; print "\n";
print '<table id="tablelines" class="noborder" width="100%">'; // Array with (n*2)+1 lines print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">
<input type="hidden" name="action" value="'.(($action != 'editline')?'addline':'updateligne').'">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="'.$object->id.'">
';
print '<br>';
print '<table id="tablelines" class="noborder noshadow" width="100%">'; // Array with (n*2)+1 lines
// Trick to not show product entries // Trick to not show product entries
$savproductenabled=$conf->product->enabled; $savproductenabled=$conf->product->enabled;
@ -1567,13 +1585,12 @@ else
// Restore correct setup // Restore correct setup
$conf->product->enabled = $savproductenabled; $conf->product->enabled = $savproductenabled;
print '</form>';
print '</table>'; print '</table>';
print '</form>';
} }
dol_fiche_end();
print '</div>';
/* /*
@ -1642,11 +1659,13 @@ llxFooter();
$db->close(); $db->close();
?> ?>
<?php <?php
if ($conf->margin->enabled) { if ($conf->margin->enabled && $action == 'editline')
{
?> ?>
<script type="text/javascript"> <script type="text/javascript">
<?php if ($action == 'editline') { ?>
$(document).ready(function() { $(document).ready(function() {
var idprod = $("input[name='idprod']").val(); var idprod = $("input[name='idprod']").val();
var fournprice = $("input[name='fournprice']").val(); var fournprice = $("input[name='fournprice']").val();
@ -1695,6 +1714,8 @@ $(document).ready(function() {
$('#buying_price').show(); $('#buying_price').show();
} }
}); });
<?php } ?>
</script> </script>
<?php } ?>
<?php
}
?>

View File

@ -33,7 +33,7 @@
* @param string $urloption More parameters on URL request * @param string $urloption More parameters on URL request
* @param int $minLength Minimum number of chars to trigger that Ajax search * @param int $minLength Minimum number of chars to trigger that Ajax search
* @param int $autoselect Automatic selection if just one value * @param int $autoselect Automatic selection if just one value
* @param array $ajaxoptions Multiple options array * @param array $ajaxoptions Multiple options array (Ex: array('update'=>array('field1','field2'...)) will reset field1 and field2 once select done
* @return string Script * @return string Script
*/ */
function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array()) function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array())

View File

@ -32,12 +32,6 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
<!-- BEGIN PHP TEMPLATE freeproductline_create.tpl.php --> <!-- BEGIN PHP TEMPLATE freeproductline_create.tpl.php -->
<form name="addproduct" id="addproduct" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id; ?>#add" method="POST">
<input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>">
<input type="hidden" name="action" value="addline">
<input type="hidden" name="mode" value="libre">
<input type="hidden" name="id" value="<?php echo $this->id; ?>">
<tr class="liste_titre nodrag nodrop"> <tr class="liste_titre nodrag nodrop">
<td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>> <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
<div id="add"></div> <div id="add"></div>
@ -116,7 +110,7 @@ else {
</td> </td>
<td align="right"><?php <td align="right"><?php
if ($seller->tva_assuj == "0") echo '<input type="hidden" name="np_tva_tx" value="0">0'; if ($seller->tva_assuj == "0") echo '<input type="hidden" name="tva_tx" value="0">0';
else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer); else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer);
?> ?>
</td> </td>
@ -137,7 +131,7 @@ else {
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'">%</td>'; echo '<td align="right"><input type="text" size="2" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'">%</td>';
} }
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { if (! empty($conf->global->DISPLAY_MARK_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'">%</td>'; echo '<td align="right"><input type="text" size="2" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'">%</td>';
} }
} }
@ -155,7 +149,7 @@ else {
} }
?> ?>
<td align="center" valign="middle" colspan="<?php echo $colspan; ?>"> <td align="center" valign="middle" colspan="<?php echo $colspan; ?>">
<input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline_libre"> <input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline_libre" id="addline_libre">
</td> </td>
<?php <?php
//Line extrafield //Line extrafield
@ -196,9 +190,9 @@ if (! empty($conf->service->enabled) && $dateSelector)
if (! empty($object->element) && $object->element == 'contrat') if (! empty($object->element) && $object->element == 'contrat')
{ {
print $langs->trans("DateStartPlanned").' '; print $langs->trans("DateStartPlanned").' ';
$form->select_date('',"date_start_sl",$usehm,$usehm,1,"addline_sl"); $form->select_date('',"date_start",$usehm,$usehm,1,"addline_sl");
print ' &nbsp; '.$langs->trans("DateEndPlanned").' '; print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
$form->select_date('',"date_end_sl",$usehm,$usehm,1,"addline_sl"); $form->select_date('',"date_end",$usehm,$usehm,1,"addline_sl");
} }
else else
{ {
@ -214,7 +208,6 @@ if (! empty($conf->service->enabled) && $dateSelector)
} }
?> ?>
</form>
<?php <?php
if (! empty($usemargins) && $user->rights->margins->creer) if (! empty($usemargins) && $user->rights->margins->creer)
@ -223,34 +216,29 @@ if (! empty($usemargins) && $user->rights->margins->creer)
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
var npRate = null;
<?php <?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?> if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
npRate = "np_marginRate"; $('#addline_libre').click(function (e) {
<?php } return checkFreeLine(e, "np_marginRate");
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
npRate = "np_markRate";
<?php }
?>
$("form#addproduct").submit(function(e) {
if (npRate) return checkFreeLine(e, npRate);
else return true;
});
if (npRate == 'np_marginRate') {
$("input[name='np_marginRate']:first").blur(function(e) {
return checkFreeLine(e, npRate);
}); });
$("input[name='np_marginRate']:first").blur(function(e) {
return checkFreeLine(e, "np_marginRate");
});
<?php
} }
else { if (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
if (npRate == 'np_markRate') { $('#addline_libre').click(function (e) {
$("input[name='np_markRate']:first").blur(function(e) { return checkFreeLine(e, "np_markRate");
return checkFreeLine(e, npRate); });
}); $("input[name='np_markRate']:first").blur(function(e) {
} return checkFreeLine(e, "np_markRate");
});
<?php
} }
?>
}); });
// TODO This works for french numbers only
function checkFreeLine(e, npRate) function checkFreeLine(e, npRate)
{ {
var buying_price = $("input[name='buying_price']:first"); var buying_price = $("input[name='buying_price']:first");
@ -261,14 +249,14 @@ if (! empty($usemargins) && $user->rights->margins->creer)
return true; return true;
if (! $.isNumeric(rate.val().replace(',','.'))) if (! $.isNumeric(rate.val().replace(',','.')))
{ {
alert('<?php echo $langs->trans("rateMustBeNumeric"); ?>'); alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
e.stopPropagation(); e.stopPropagation();
setTimeout(function () { rate.focus() }, 50); setTimeout(function () { rate.focus() }, 50);
return false; return false;
} }
if (npRate == "np_markRate" && rate.val() >= 100) if (npRate == "np_markRate" && rate.val() >= 100)
{ {
alert('<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>'); alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
e.stopPropagation(); e.stopPropagation();
setTimeout(function () { rate.focus() }, 50); setTimeout(function () { rate.focus() }, 50);
return false; return false;
@ -284,12 +272,14 @@ if (! empty($usemargins) && $user->rights->margins->creer)
np_price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100)); np_price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
} }
} }
$("input[name='price_ht']:first").val(formatFloat(np_price)); $("input[name='price_ht']:first").val(roundFloat(np_price));
return true; return true;
} }
function roundFloat(num) { // TODO This works for french numbers only
function roundFloat(num)
{
var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>; var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>;
var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>; var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
@ -312,10 +302,6 @@ if (! empty($usemargins) && $user->rights->margins->creer)
return parseFloat(amount).toFixed(rounding); return parseFloat(amount).toFixed(rounding);
} }
function formatFloat(num) {
return roundFloat(num).replace('.', ',');
}
</script> </script>
<?php <?php
} }

View File

@ -28,15 +28,8 @@
?> ?>
<!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php --> <!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->
<form id="editproduct" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id.'#'.$line->id; ?>" method="POST">
<input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>"> <?php
<input type="hidden" name="action" value="updateligne">
<input type="hidden" name="usenewupdatelineform" value="1" />
<input type="hidden" name="id" value="<?php echo $this->id; ?>">
<input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
<input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
<input type="hidden" id="product_id" name="productid" value="<?php echo (! empty($line->fk_product)?$line->fk_product:0); ?>" />
<?php
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
$coldisplay=2; $coldisplay=2;
} else { } else {
@ -45,7 +38,11 @@ if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
?> ?>
<tr <?php echo $bc[$var]; ?>> <tr <?php echo $bc[$var]; ?>>
<td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>> <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
<div id="<?php echo $line->id; ?>"></div> <div id="line_<?php echo $line->id; ?>"></div>
<input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
<input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
<input type="hidden" id="product_id" name="productid" value="<?php echo (! empty($line->fk_product)?$line->fk_product:0); ?>" />
<?php <?php
if ($conf->global->MAIN_FEATURES_LEVEL > 1) if ($conf->global->MAIN_FEATURES_LEVEL > 1)
@ -187,12 +184,15 @@ if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
</tr> </tr>
<?php } ?> <?php } ?>
</form>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() {
<?php if ($conf->global->MAIN_FEATURES_LEVEL > 1) { ?> <?php
if ($conf->global->MAIN_FEATURES_LEVEL > 1) // TODO A virer
{
?>
jQuery(document).ready(function() {
if ($('#product_type').val() == 0) { if ($('#product_type').val() == 0) {
$('#service_duration_area').hide(); $('#service_duration_area').hide();
@ -290,7 +290,9 @@ $(document).ready(function() {
} }
}); });
function update_price(input, output) { // update_price
function update_price(input, output)
{
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', { $.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', {
'amount': $('#' + input).val(), 'amount': $('#' + input).val(),
'output': output, 'output': output,
@ -368,10 +370,19 @@ $(document).ready(function() {
}); });
<?php } ?> <?php } ?>
<?php } ?> });
<?php if (! empty($conf->margin->enabled)) { ?> <?php } // End MAIN_LEVEL_FEATURES > 1 ?>
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
<?php
if (! empty($conf->margin->enabled))
{
?>
jQuery(document).ready(function()
{
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
if (data && data.length > 0) { if (data && data.length > 0) {
var options = ''; var options = '';
var trouve=false; var trouve=false;
@ -405,99 +416,101 @@ $(document).ready(function() {
$("#fournprice").hide(); $("#fournprice").hide();
$('#buying_price').show(); $('#buying_price').show();
} }
}, 'json'); }, 'json');
<?php } ?>
});
var npRate = null;
<?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
npRate = "marginRate";
<?php }
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
npRate = "markRate";
<?php }
?>
$("form#editproduct").submit(function(e) { <?php
if (npRate) return checkEditLine(e, npRate); if (! empty($conf->global->DISPLAY_MARGIN_RATES))
else return true; {
}); ?>
if (npRate == 'marginRate') { $('#savelinebutton').click(function (e) {
$("input[name='marginRate']:first").blur(function(e) { return checkEditLine(e, "marginRate");
return checkEditLine(e, npRate); });
}); $("input[name='np_marginRate']:first").blur(function(e) {
} return checkEditLine(e, "marginRate");
else { });
if (npRate == 'markRate') { <?php
$("input[name='markRate']:first").blur(function(e) {
return checkEditLine(e, npRate);
});
}
}
function checkEditLine(e, npRate)
{
var buying_price = $("input[name='buying_price']:first");
var remise = $("input[name='remise_percent']:first");
var rate = $("input[name='"+npRate+"']:first");
if (rate.val() == '')
return true;
if (! $.isNumeric(rate.val().replace(',','.')))
{
alert('<?php echo $langs->trans("rateMustBeNumeric"); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
if (npRate == "markRate" && rate.val() >= 100)
{
alert('<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
var price = 0;
if (remise.val().replace(',','.') != 100)
{
if (npRate == "marginRate")
price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
else {
if (npRate == "markRate")
price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
} }
if (! empty($conf->global->DISPLAY_MARK_RATES))
{
?>
$('#savelinebutton').click(function (e) {
return checkEditLine(e, "markRate");
});
$("input[name='np_markRate']:first").blur(function(e) {
return checkEditLine(e, "markRate");
});
<?php
}
?>
});
// TODO This works for french numbers only
function checkEditLine(e, npRate)
{
var buying_price = $("input[name='buying_price']:first");
var remise = $("input[name='remise_percent']:first");
var rate = $("input[name='"+npRate+"']:first");
if (rate.val() == '')
return true;
if (! $.isNumeric(rate.val().replace(',','.')))
{
alert('<?php echo $langs->trans("rateMustBeNumeric"); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
if (npRate == "markRate" && rate.val() >= 100)
{
alert('<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
var price = 0;
if (remise.val().replace(',','.') != 100)
{
if (npRate == "marginRate")
price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
else {
if (npRate == "markRate")
price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
}
}
$("input[name='price_ht']:first").val(roundFloat(price));
return true;
} }
$("input[name='price_ht']:first").val(formatFloat(price));
return true; // TODO This works for french numbers only
} function roundFloat(num) {
function roundFloat(num) { var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>;
var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>; var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
var amount = num.toString().replace(',','.'); // should be useless var amount = num.toString().replace(',','.'); // should be useless
var nbdec = 0; var nbdec = 0;
var rounding = main_rounding; var rounding = main_rounding;
var pos = amount.indexOf('.'); var pos = amount.indexOf('.');
var decpart = ''; var decpart = '';
if (pos >= 0) if (pos >= 0)
decpart = amount.substr(pos+1).replace('/0+$/i',''); // Supprime les 0 de fin de partie decimale decpart = amount.substr(pos+1).replace('/0+$/i',''); // Supprime les 0 de fin de partie decimale
nbdec = decpart.length; nbdec = decpart.length;
if (nbdec > rounding) if (nbdec > rounding)
rounding = nbdec; rounding = nbdec;
// Si on depasse max // Si on depasse max
if (rounding > main_max_dec_shown) if (rounding > main_max_dec_shown)
{ {
rounding = main_max_dec_shown; rounding = main_max_dec_shown;
} }
//amount = parseFloat(amount) + (1 / Math.pow(100, rounding)); // to avoid floating-point errors //amount = parseFloat(amount) + (1 / Math.pow(100, rounding)); // to avoid floating-point errors
return parseFloat(amount).toFixed(rounding); return parseFloat(amount).toFixed(rounding);
} }
function formatFloat(num) { <?php
return roundFloat(num).replace('.', ',');
} }
?>
</script> </script>
<!-- END PHP TEMPLATE objectline_edit.tpl.php --> <!-- END PHP TEMPLATE objectline_edit.tpl.php -->

View File

@ -32,12 +32,6 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
<!-- BEGIN PHP TEMPLATE predefinedproductline_create.tpl.php --> <!-- BEGIN PHP TEMPLATE predefinedproductline_create.tpl.php -->
<form name="addpredefinedproduct" id="addpredefinedproduct" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id; ?>#add" method="POST">
<input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>">
<input type="hidden" name="action" value="addline">
<input type="hidden" name="mode" value="predefined">
<input type="hidden" name="id" value="<?php echo $this->id; ?>">
<tr class="liste_titre nodrag nodrop"> <tr class="liste_titre nodrag nodrop">
<td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>>
<?php <?php
@ -128,25 +122,25 @@ else {
?> ?>
</td> </td>
<td align="right"><input type="hidden" name="price_ht"><input type="text" size="2" name="qty" class="flat" value="1"></td> <td align="right"><input type="hidden" name="price_ht_predef"><input type="text" size="2" name="qty_predef" class="flat" value="1"></td>
<td align="right" class="nowrap"><input type="text" size="1" class="flat" name="remise_percent" value="<?php echo $buyer->remise_percent; ?>"><span class="hideonsmartphone">%</span></td> <td align="right" class="nowrap"><input type="text" size="1" class="flat" name="remise_percent_predef" value="<?php echo $buyer->remise_percent; ?>"><span class="hideonsmartphone">%</span></td>
<?php <?php
$colspan = 4; $colspan = 4;
if (! empty($usemargins)) if (! empty($usemargins))
{ {
?> ?>
<td align="right"> <td align="right">
<select id="fournprice" name="fournprice" class="flat" style="display: none;"></select> <select id="fournprice_predef" name="fournprice_predef" class="flat" style="display: none;"></select>
<input type="text" size="5" id="buying_price" name="buying_price" class="flat" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>"> <input type="text" size="5" id="buying_price_predef" name="buying_price_predef" class="flat" value="<?php echo (isset($_POST["buying_price_predef"])?$_POST["buying_price_predef"]:''); ?>">
</td> </td>
<?php <?php
if ($user->rights->margins->creer) if ($user->rights->margins->creer)
{ {
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'">%</td>'; echo '<td align="right"><input type="text" size="2" name="np_marginRate_predef" value="'.(isset($_POST["np_marginRate_predef"])?$_POST["np_marginRate_predef"]:'').'">%</td>';
} }
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { if (! empty($conf->global->DISPLAY_MARK_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'">%</td>'; echo '<td align="right"><input type="text" size="2" name="np_markRate_predef" value="'.(isset($_POST["np_markRate_predef"])?$_POST["np_markRate_predef"]:'').'">%</td>';
} }
} }
else else
@ -163,7 +157,7 @@ else {
} }
?> ?>
<td align="center" valign="middle" colspan="<?php echo $colspan; ?>"> <td align="center" valign="middle" colspan="<?php echo $colspan; ?>">
<input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline_predefined"> <input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline_predefined" id="addline_predefined">
</td> </td>
<?php <?php
//Line extrafield //Line extrafield
@ -203,9 +197,9 @@ if (! empty($conf->service->enabled) && $dateSelector)
if (! empty($object->element) && $object->element == 'contrat') if (! empty($object->element) && $object->element == 'contrat')
{ {
print $langs->trans("DateStartPlanned").' '; print $langs->trans("DateStartPlanned").' ';
$form->select_date('',"date_start",$usehm,$usehm,1,"addline"); $form->select_date('',"date_start_predef",$usehm,$usehm,1,"addline");
print ' &nbsp; '.$langs->trans("DateEndPlanned").' '; print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
$form->select_date('',"date_end",$usehm,$usehm,1,"addline"); $form->select_date('',"date_end_predef",$usehm,$usehm,1,"addline");
} }
else else
{ {
@ -221,7 +215,6 @@ if (! empty($conf->service->enabled) && $dateSelector)
} }
?> ?>
</form>
<?php <?php
if (! empty($usemargins) && $user->rights->margins->creer) if (! empty($usemargins) && $user->rights->margins->creer)
@ -230,52 +223,48 @@ if (! empty($usemargins) && $user->rights->margins->creer)
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
var npRate = null;
<?php <?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?> if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
npRate = "np_marginRate"; $('#addline_predefined').click(function (e) {
<?php } return checkLine(e, "np_marginRate_predef");
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
npRate = "np_markRate";
<?php }
?>
$("form#addpredefinedproduct").submit(function(e) {
if (npRate) return checkLine(e, npRate);
else return true;
});
if (npRate == 'np_marginRate') {
$("input[name='np_marginRate']:last").blur(function(e) {
return checkLine(e, npRate);
}); });
$("input[name='np_marginRate_predef']:last").blur(function(e) {
return checkLine(e, "np_marginRate_predef");
});
<?php
} }
else { if (! empty($conf->global->DISPLAY_MARK_RATES)) {
if (npRate == 'np_markRate') { ?>
$("input[name='np_markRate']:last").blur(function(e) { $('#addline_predefined').click(function (e) {
return checkLine(e, npRate); return checkLine(e, "np_markRate_predef");
}); });
} $("input[name='np_marginRate_predef']:last").blur(function(e) {
return checkLine(e, "np_markRate_predef");
});
<?php
} }
?>
}); });
// TODO This works for french numbers only
function checkLine(e, npRate) function checkLine(e, npRate)
{ {
var buying_price = $("input[name='buying_price']:last"); var buying_price = $("input[name='buying_price_predef']:last");
var remise = $("input[name='remise_percent']:last"); var remise = $("input[name='remise_percent_predef']:last");
var rate = $("input[name='"+npRate+"']:last"); var rate = $("input[name='"+npRate+"']:last");
if (rate.val() == '') if (rate.val() == '')
return true; return true;
if (! $.isNumeric(rate.val().replace(',','.'))) if (! $.isNumeric(rate.val().replace(',','.')))
{ {
alert('<?php echo $langs->trans("rateMustBeNumeric"); ?>'); alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
e.stopPropagation(); e.stopPropagation();
setTimeout(function () { rate.focus() }, 50); setTimeout(function () { rate.focus() }, 50);
return false; return false;
} }
if (npRate == "np_markRate" && rate.val() >= 100) if (npRate == "np_markRate_predef" && rate.val() >= 100)
{ {
alert('<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>'); alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
e.stopPropagation(); e.stopPropagation();
setTimeout(function () { rate.focus() }, 50); setTimeout(function () { rate.focus() }, 50);
return false; return false;
@ -284,18 +273,19 @@ if (! empty($usemargins) && $user->rights->margins->creer)
var np_price = 0; var np_price = 0;
if (remise.val().replace(',','.') != 100) if (remise.val().replace(',','.') != 100)
{ {
if (npRate == "np_marginRate") if (npRate == "np_marginRate_predef")
np_price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100)); np_price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
else { else {
if (npRate == "np_markRate") if (npRate == "np_markRate_predef")
np_price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100)); np_price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
} }
} }
$("input[name='price_ht']:last").val(formatFloat(np_price)); $("input[name='price_ht_predef']:last").val(roundFloat(np_price));
return true; return true;
} }
// TODO This works for french numbers only
function roundFloat(num) { function roundFloat(num) {
var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>; var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>;
var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>; var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
@ -319,16 +309,12 @@ if (! empty($usemargins) && $user->rights->margins->creer)
return parseFloat(amount).toFixed(rounding); return parseFloat(amount).toFixed(rounding);
} }
function formatFloat(num) {
return roundFloat(num).replace('.', ',');
}
jQuery(document).ready(function() { jQuery(document).ready(function() {
$("#idprod").change(function() $("#idprod").change(function()
{ {
$("#fournprice options").remove(); $("#fournprice_predef options").remove();
$("#fournprice").hide(); $("#fournprice_predef").hide();
$("#buying_price").val("").show(); $("#buying_price_predef").val("").show();
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', { 'idprod': $(this).val() }, function(data) { $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', { 'idprod': $(this).val() }, function(data) {
if (data && data.length > 0) if (data && data.length > 0)
{ {
@ -339,19 +325,19 @@ if (! empty($usemargins) && $user->rights->margins->creer)
options += '<option value="'+this.id+'" price="'+this.price+'"'; options += '<option value="'+this.id+'" price="'+this.price+'"';
if (i == 1) { if (i == 1) {
options += ' selected'; options += ' selected';
$("#buying_price").val(this.price); $("#buying_price_predef").val(this.price);
} }
options += '>'+this.label+'</option>'; options += '>'+this.label+'</option>';
}); });
options += '<option value=""><?php echo $langs->trans("InputPrice"); ?></option>'; options += '<option value=""><?php echo $langs->trans("InputPrice"); ?></option>';
$("#buying_price").hide(); $("#buying_price_predef").hide();
$("#fournprice").html(options).show(); $("#fournprice_predef").html(options).show();
$("#fournprice").change(function() { $("#fournprice_predef").change(function() {
var selval = $(this).find('option:selected').attr("price"); var selval = $(this).find('option:selected').attr("price");
if (selval) if (selval)
$("#buying_price").val(selval).hide(); $("#buying_price_predef").val(selval).hide();
else else
$('#buying_price').show(); $('#buying_price_predef').show();
}); });
} }
}, },

View File

@ -181,160 +181,195 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
$langs->load('errors'); $langs->load('errors');
$error = 0; $error = 0;
if (GETPOST('pu') < 0 && GETPOST('qty') < 0) // Set if we used free entry or predefined product
if (GETPOST('addline_libre'))
{
$predef='';
$idprod=0;
$product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
$price_ht = GETPOST('price_ht');
$tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
}
if (GETPOST('addline_predefined'))
{
$predef=(($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
$idprod=GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):''));
$price_ht = '';
$tva_tx = '';
}
$qty = GETPOST('qty'.$predef);
$remise_percent=GETPOST('remise_percent'.$predef);
if (GETPOST('addline_libre') && GETPOST('pu') < 0 && $qty < 0)
{ {
setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors'); setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors');
$error++; $error++;
} }
if (! GETPOST('idprodfournprice') && GETPOST('type') < 0) if (GETPOST('addline_libre') && ! GETPOST('idprodfournprice') && GETPOST('type') < 0)
{ {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors'); setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
$error++; $error++;
} }
if (! GETPOST('idprodfournprice') && (! GETPOST('pu') || GETPOST('pu')=='')) // Unit price can be 0 but not '' if (! GETPOST('addline_predefined') && (! GETPOST('pu') || GETPOST('pu')=='')) // Unit price can be 0 but not ''
{ {
setEventMessage($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), 'errors'); setEventMessage($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), 'errors');
$error++; $error++;
} }
if (! GETPOST('idprodfournprice') && ! GETPOST('np_desc') && ! GETPOST('dp_desc')) if (! GETPOST('addline_predefined') && ! GETPOST('np_desc') && ! GETPOST('dp_desc'))
{ {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors'); setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
$error++; $error++;
} }
if (! GETPOST('idprodfournprice') && (! GETPOST('qty') || GETPOST('qty') == '') if ((! GETPOST('addline_predefined') && (! GETPOST('qty') || GETPOST('qty') == ''))
|| GETPOST('idprodfournprice') && (! GETPOST('pqty') || GETPOST('pqty') == '')) || (GETPOST('addline_predefined') && (! GETPOST('qty_predef') || GETPOST('qty_predef') == '')))
{ {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors'); setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
$error++; $error++;
} }
if (! $error && ((GETPOST('qty') || GETPOST('pqty')) && ((GETPOST('pu') && (GETPOST('np_desc') || GETPOST('dp_desc'))) || GETPOST('idprodfournprice')))) // Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
if (GETPOST('addline_predefined') || GETPOST('idprodfournprice')) // With combolist idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
{ {
// Ecrase $pu par celui du produit $idprod=0;
// Ecrase $desc par celui du produit $productsupplier = new ProductFournisseur($db);
// Ecrase $txtva par celui du produit
if (GETPOST('idprodfournprice')) // >0 or -1
{
$qty = GETPOST('qty') ? GETPOST('qty') : GETPOST('pqty');
$productsupplier = new ProductFournisseur($db); if (GETPOST('idprodfournprice') == '')
$idprod=$productsupplier->get_buyprice($_POST['idprodfournprice'], $qty); // Just to see if a price exists for the quantity. Not used to found vat {
$idprod=-1;
}
if (GETPOST('idprodfournprice') > 0)
{
$idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat
}
if ($idprod > 0) if ($idprod > 0)
{ {
$res=$productsupplier->fetch($idprod); $res=$productsupplier->fetch($idprod);
// cas special pour lequel on a les meme reference que le fournisseur $label = $productsupplier->libelle;
// $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle;
$label = $productsupplier->libelle;
$desc = $productsupplier->description; $desc = $productsupplier->description;
$desc.= $productsupplier->description && $_POST['np_desc'] ? "\n" : ""; if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
$desc.= $_POST['np_desc'];
$remise_percent = GETPOST('remise_percent') ? GETPOST('remise_percent') : GETPOST('p_remise_percent'); $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice'));
$type = $productsupplier->type;
$tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice')); // Local Taxes
$type = $productsupplier->type; $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
$localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
// Local Taxes $result=$object->addline(
$localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty); $desc,
$localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty); $productsupplier->fourn_pu,
$qty,
$tva_tx,
$localtax1_tx,
$localtax2_tx,
$productsupplier->id,
GETPOST('idprodfournprice'),
$productsupplier->fourn_ref,
$remise_percent,
'HT',
$type
);
}
if ($idprod == 0)
{
// Product not selected
$error++;
$langs->load("errors");
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ProductOrService")), 'errors');
}
if ($idprod == -1)
{
// Quantity too low
$error++;
$langs->load("errors");
setEventMessage($langs->trans("ErrorQtyTooLowForThisSupplier"), 'errors');
}
}
else
{
$type=$_POST["type"];
$desc=$_POST['dp_desc'];
$tva_tx = price2num($_POST['tva_tx']);
$result=$object->addline( // Local Taxes
$desc, $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
$pu, // FIXME $pu is not defined $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
$qty,
$tva_tx,
$localtax1_tx,
$localtax2_tx,
$productsupplier->id,
GETPOST('idprodfournprice'),
$productsupplier->fourn_ref,
$remise_percent,
'HT',
$type
);
}
if ($idprod == -1)
{
// Quantity too low
setEventMessage($langs->trans("ErrorQtyTooLowForThisSupplier"), 'errors');
}
}
else
{
$type=$_POST["type"];
$desc=$_POST['dp_desc'];
$tva_tx = price2num($_POST['tva_tx']);
// Local Taxes if (! $product_desc)
$localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty); {
$localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")), 'errors');
}
else
{
if (!empty($_POST['pu']))
{
$price_base_type = 'HT';
$ht = price2num($_POST['pu']);
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type);
}
else
{
$ttc = price2num($_POST['amountttc']);
$ht = $ttc / (1 + ($tauxtva / 100));
$price_base_type = 'HT';
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type);
}
}
}
if (! $_POST['dp_desc']) //print "xx".$tva_tx; exit;
{ if (! $error && $result > 0)
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")), 'errors'); {
} $ret=$object->fetch($object->id); // Reload to get new records
else
{
if (!empty($_POST['pu']))
{
$price_base_type = 'HT';
$ht = price2num($_POST['pu']);
$result=$object->addline($desc, $ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $_POST['remise_percent'], $price_base_type, 0, $type);
}
else
{
$ttc = price2num($_POST['amountttc']);
$ht = $ttc / (1 + ($tauxtva / 100));
$price_base_type = 'HT';
$result=$object->addline($desc, $ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $_POST['remise_percent'], $price_base_type, $ttc, $type);
}
}
}
//print "xx".$tva_tx; exit; if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
if ($result > 0) {
{ // Define output language
$ret=$object->fetch($object->id); // Reload to get new records $outputlangs = $langs;
$newlang=GETPOST('lang_id','alpha');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
{ }
// Define output language
$outputlangs = $langs;
$newlang=GETPOST('lang_id','alpha');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); unset($_POST['qty']);
} unset($_POST['type']);
unset($_POST['qty']); unset($_POST['remise_percent']);
unset($_POST['type']); unset($_POST['dp_desc']);
unset($_POST['idprodfournprice']); unset($_POST['pu']);
unset($_POST['remmise_percent']); unset($_POST['tva_tx']);
unset($_POST['dp_desc']); unset($_POST['label']);
unset($_POST['np_desc']); unset($localtax1_tx);
unset($_POST['pu']); unset($localtax2_tx);
unset($_POST['tva_tx']);
unset($localtax1_tx); unset($_POST['idprodfournprice']);
unset($localtax2_tx); unset($_POST['qty_predef']);
} unset($_POST['remise_percent_predef']);
else unset($_POST['fournprice_predef']);
{ unset($_POST['buying_price_predef']);
setEventMessage($object->error, 'errors'); unset($_POST['np_desc']);
} }
else
{
setEventMessage($object->error, 'errors');
} }
} }
/* /*
* Mise a jour d'une ligne dans la commande * Mise a jour d'une ligne dans la commande
*/ */
else if ($action == 'updateligne' && $user->rights->fournisseur->commande->creer && $_POST['save'] == $langs->trans('Save')) else if ($action == 'update_line' && $user->rights->fournisseur->commande->creer && $_POST['save'] == $langs->trans('Save'))
{ {
if ($_POST["elrowid"]) if ($_POST["elrowid"])
{ {
@ -630,7 +665,7 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) /
// Save last template used to generate document // Save last template used to generate document
if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
$outputlangs = $langs; $outputlangs = $langs;
if (GETPOST('lang_id')) if (GETPOST('lang_id'))
{ {
@ -973,7 +1008,7 @@ if ($action=="create")
$societe=new Societe($db); $societe=new Societe($db);
$societe->fetch($socid); $societe->fetch($socid);
} }
$cond_reglement_id = $societe->cond_reglement_supplier_id; $cond_reglement_id = $societe->cond_reglement_supplier_id;
$mode_reglement_id = $societe->mode_reglement_supplier_id; $mode_reglement_id = $societe->mode_reglement_supplier_id;
@ -1005,7 +1040,7 @@ if ($action=="create")
print '</tr>'; print '</tr>';
print '</td></tr>'; print '</td></tr>';
// Payment term // Payment term
print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">'; print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
$form->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id'); $form->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id');
@ -1061,7 +1096,7 @@ elseif (! empty($object->id))
if ($action == 'delete') if ($action == 'delete')
{ {
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
} }
// Clone confirmation // Clone confirmation
@ -1073,7 +1108,7 @@ elseif (! empty($object->id))
); );
// Paiement incomplet. On demande si motif = escompte ou autre // Paiement incomplet. On demande si motif = escompte ou autre
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
} }
/* /*
@ -1097,7 +1132,7 @@ elseif (! empty($object->id))
} }
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1);
} }
/* /*
@ -1120,7 +1155,7 @@ elseif (! empty($object->id))
} }
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", $formquestion, 1, 1, 240); print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", $formquestion, 1, 1, 240);
} }
/* /*
@ -1129,7 +1164,7 @@ elseif (! empty($object->id))
if ($action == 'refuse') if ($action == 'refuse')
{ {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1); print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1);
} }
/* /*
@ -1138,7 +1173,7 @@ elseif (! empty($object->id))
if ($action == 'cancel') if ($action == 'cancel')
{ {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1); print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1);
} }
/* /*
@ -1148,7 +1183,7 @@ elseif (! empty($object->id))
{ {
$date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2); print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2);
} }
/* /*
@ -1157,7 +1192,7 @@ elseif (! empty($object->id))
if ($action == 'delete_product_line') if ($action == 'delete_product_line')
{ {
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2);
} }
/* /*
@ -1381,8 +1416,20 @@ elseif (! empty($object->id))
/* /*
* Lines * Lines
*/ */
print '<table class="noborder" width="100%">';
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?etat=1&id='.$object->id.(($action != 'edit_line')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">
<input type="hidden" name="action" value="'.(($action != 'edit_line')?'addline':'update_line').'">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="'.$object->id.'">
<input type="hidden" name="facid" value="'.$object->id.'">
<input type="hidden" name="socid" value="'.$societe->id.'">
';
print '<table id="tablelines" class="noborder noshadow" width="100%">';
$num = count($object->lines); $num = count($object->lines);
$i = 0; $total = 0; $i = 0; $total = 0;
@ -1422,8 +1469,8 @@ elseif (! empty($object->id))
$type=1; $type=1;
} }
// Ligne en mode visu // Edit line
if ($action != 'editline' || $_GET['rowid'] != $line->id) if ($action != 'edit_line' || $_GET['rowid'] != $line->id)
{ {
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
@ -1478,7 +1525,7 @@ elseif (! empty($object->id))
print '<td align="right" class="nowrap">'.price($line->total_ht).'</td>'; print '<td align="right" class="nowrap">'.price($line->total_ht).'</td>';
if ($object->statut == 0 && $user->rights->fournisseur->commande->creer) if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
{ {
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$line->id.'#'.$line->id.'">'; print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit_line&amp;rowid='.$line->id.'#'.$line->id.'">';
print img_edit(); print img_edit();
print '</a></td>'; print '</a></td>';
@ -1495,16 +1542,14 @@ elseif (! empty($object->id))
} }
// Ligne en mode update // Ligne en mode update
if ($action == 'editline' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $line->id)) if ($action == 'edit_line' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $line->id))
{ {
print "\n"; print "\n";
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;etat=1&amp;ligne_id='.$line->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="elrowid" value="'.$_GET['rowid'].'">';
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td>'; print '<td>';
print '<input type="hidden" name="elrowid" value="'.$_GET['rowid'].'">';
print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $line->fk_product > 0) if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $line->fk_product > 0)
{ {
@ -1546,7 +1591,6 @@ elseif (! empty($object->id))
print '<td align="center" colspan="4"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; print '<td align="center" colspan="4"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>'; print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>';
print '</tr>' . "\n"; print '</tr>' . "\n";
print "</form>\n";
} }
$i++; $i++;
} }
@ -1554,7 +1598,7 @@ elseif (! empty($object->id))
/* /*
* Form to add new line * Form to add new line
*/ */
if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action <> 'editline') if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action <> 'edit_line')
{ {
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
@ -1571,19 +1615,6 @@ elseif (! empty($object->id))
// TODO Use the predefinedproductline_create.tpl.php file // TODO Use the predefinedproductline_create.tpl.php file
// Add free products/services form // Add free products/services form
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#add" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addline">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#idprodfournprice\').change(function() {
if (jQuery(\'#idprodfournprice\').val() > 0) jQuery(\'#np_desc\').focus();
});
});
</script>';
$var=true; $var=true;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td>'; print '<td>';
@ -1611,14 +1642,20 @@ elseif (! empty($object->id))
print '<td align="right"><input type="text" name="pu" size="5" value="'.GETPOST('pu').'"></td>'; print '<td align="right"><input type="text" name="pu" size="5" value="'.GETPOST('pu').'"></td>';
print '<td align="right"><input type="text" name="qty" value="'.(GETPOST('qty')?GETPOST('qty'):'1').'" size="2"></td>'; print '<td align="right"><input type="text" name="qty" value="'.(GETPOST('qty')?GETPOST('qty'):'1').'" size="2"></td>';
print '<td align="right" class="nowrap"><input type="text" name="remise_percent" size="1" value="'.(GETPOST('remise_percent')?GETPOST('remise_percent'):$object->thirdparty->remise_percent).'"><span class="hideonsmartphone">%</span></td>'; print '<td align="right" class="nowrap"><input type="text" name="remise_percent" size="1" value="'.(GETPOST('remise_percent')?GETPOST('remise_percent'):$object->thirdparty->remise_percent).'"><span class="hideonsmartphone">%</span></td>';
print '<td align="center" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'"></td>'; print '<td align="center" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline_libre"></td>';
print '</tr>'; print '</tr>';
print '</form>';
// Ajout de produits/services predefinis // Ajout de produits/services predefinis
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
{ {
print '<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#idprodfournprice\').change(function() {
if (jQuery(\'#idprodfournprice\').val() > 0) jQuery(\'#np_desc\').focus();
});
});
</script>';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td colspan="3">'; print '<td colspan="3">';
print $langs->trans("AddNewLine").' - '; print $langs->trans("AddNewLine").' - ';
@ -1636,21 +1673,16 @@ elseif (! empty($object->id))
print '<td colspan="4">&nbsp;</td>'; print '<td colspan="4">&nbsp;</td>';
print '</tr>'; print '</tr>';
print '<form id="addpredefinedproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#add" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addline">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td colspan="3">'; print '<td colspan="3">';
$ajaxoptions=array( $ajaxoptions=array(
'update' => array('pqty' => 'qty', 'p_remise_percent' => 'discount'), 'update' => array('qty_predef' => 'qty_predef', 'remise_percent_predef' => 'remise_percent_predef'),
'option_disabled' => 'addPredefinedProductButton', 'option_disabled' => 'addPredefinedProductButton',
'error' => $langs->trans("NoPriceDefinedForThisSupplier") 'error' => $langs->trans("NoPriceDefinedForThisSupplier")
); );
$form->select_produits_fournisseurs($object->fourn_id, '', 'idprodfournprice', '', '', $ajaxoptions); $form->select_produits_fournisseurs($object->fourn_id, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions);
if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>'; if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>';
@ -1666,16 +1698,17 @@ elseif (! empty($object->id))
$doleditor->Create(); $doleditor->Create();
print '</td>'; print '</td>';
print '<td align="right"><input type="text" size="2" id="pqty" name="pqty" value="'.(GETPOST('pqty')?GETPOST('pqty'):'1').'"></td>'; print '<td align="right"><input type="text" size="2" id="qty_predef" name="qty_predef" value="'.(GETPOST('qty_predef')?GETPOST('qty_predef'):'1').'"></td>';
print '<td align="right" class="nowrap"><input type="text" size="1" id="p_remise_percent" name="p_remise_percent" value="'.(GETPOST('p_remise_percent')?GETPOST('p_remise_percent'):$object->thirdparty->remise_percent).'"><span class="hideonsmartphone">%</span></td>'; print '<td align="right" class="nowrap"><input type="text" size="1" id="remise_percent_predef" name="remise_percent_predef" value="'.(GETPOST('remise_percent_predef')?GETPOST('remise_percent_predef'):$object->thirdparty->remise_percent).'"><span class="hideonsmartphone">%</span></td>';
print '<td align="center" colspan="4"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans('Add').'"></td>'; print '<td align="center" colspan="4"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans('Add').'" name="addline_predefined"></td>';
print '</tr>'; print '</tr>';
print '</form>';
} }
} }
print '</table>'; print '</table>';
print '</div>';
print '</form>';
dol_fiche_end();
if ($action != 'presend') if ($action != 'presend')
@ -1683,7 +1716,7 @@ elseif (! empty($object->id))
/** /**
* Boutons actions * Boutons actions
*/ */
if ($user->societe_id == 0 && $action != 'editline' && $action != 'delete') if ($user->societe_id == 0 && $action != 'edit_line' && $action != 'delete')
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
@ -1801,9 +1834,9 @@ elseif (! empty($object->id))
* Linked object block * Linked object block
*/ */
$somethingshown=$object->showLinkedObjectBlock(); $somethingshown=$object->showLinkedObjectBlock();
print '</div><div class="fichehalfright"><div class="ficheaddleft">'; print '</div><div class="fichehalfright"><div class="ficheaddleft">';
// List of actions on element // List of actions on element
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';

View File

@ -477,7 +477,7 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
} }
// Modification d'une ligne // Modification d'une ligne
elseif ($action == 'update_line') elseif ($action == 'update_line' && $user->rights->fournisseur->facture->creer)
{ {
if (GETPOST('etat') == '1' && ! GETPOST('cancel')) // si on valide la modification if (GETPOST('etat') == '1' && ! GETPOST('cancel')) // si on valide la modification
{ {
@ -524,8 +524,32 @@ elseif ($action == 'update_line')
} }
} }
elseif ($action == 'addline') elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
{ {
$langs->load('errors');
$error=0;
// Set if we used free entry or predefined product
if (GETPOST('addline_libre'))
{
$predef='';
$idprod=0;
$product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
$price_ht = GETPOST('price_ht');
$tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
}
if (GETPOST('addline_predefined'))
{
$predef=(($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
$idprod=GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):''));
$price_ht = '';
$tva_tx = '';
}
$qty = GETPOST('qty'.$predef);
$remise_percent=GETPOST('remise_percent'.$predef);
$ret=$object->fetch($id); $ret=$object->fetch($id);
if ($ret < 0) if ($ret < 0)
{ {
@ -534,10 +558,10 @@ elseif ($action == 'addline')
} }
$ret=$object->fetch_thirdparty(); $ret=$object->fetch_thirdparty();
if (GETPOST('search_idprodfournprice') || GETPOST('idprodfournprice')) // With combolist idprodfournprice is > 0 or -1, with autocomplete, idprodfournprice is > 0 or '' if (GETPOST('addline_predefined') || GETPOST('search_idprodfournprice') || GETPOST('idprodfournprice')) // With combolist idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
{ {
$idprod=0; $idprod=0;
$product=new Product($db); $productsupplier=new ProductFournisseur($db);
if (GETPOST('idprodfournprice') == '') if (GETPOST('idprodfournprice') == '')
{ {
@ -545,33 +569,39 @@ elseif ($action == 'addline')
} }
if (GETPOST('idprodfournprice') > 0) if (GETPOST('idprodfournprice') > 0)
{ {
$idprod=$product->get_buyprice(GETPOST('idprodfournprice'), $_POST['qty']); // Just to see if a price exists for the quantity. Not used to found vat $idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat
} }
if ($idprod > 0) if ($idprod > 0)
{ {
$result=$product->fetch($idprod); $result=$productsupplier->fetch($idprod);
// cas special pour lequel on a les meme reference que le fournisseur $label = $productsupplier->libelle;
// $label = '['.$product->ref.'] - '. $product->libelle;
$label = $product->description;
$label.= $product->description && $_POST['np_desc'] ? "\n" : "";
$label.= $_POST['np_desc'];
$tvatx=get_default_tva($object->thirdparty, $mysoc, $product->id, $_POST['idprodfournprice']); $desc = $productsupplier->description;
$npr = get_default_npr($object->thirdparty, $mysoc, $product->id, $_POST['idprodfournprice']); if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
$tvatx=get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
$npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
$localtax1tx= get_localtax($tvatx, 1, $mysoc,$object->thirdparty); $localtax1tx= get_localtax($tvatx, 1, $mysoc,$object->thirdparty);
$localtax2tx= get_localtax($tvatx, 2, $mysoc,$object->thirdparty); $localtax2tx= get_localtax($tvatx, 2, $mysoc,$object->thirdparty);
$remise_percent=GETPOST('remise_percent');
$type = $product->type;
$result=$object->addline($label, $product->fourn_pu, $tvatx, $localtax1tx, $localtax2tx, $_POST['qty'], $idprod, $remise_percent, '', '', 0, $npr); $type = $productsupplier->type;
$result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1tx, $localtax2tx, $qty, $idprod, $remise_percent, '', '', 0, $npr);
}
if ($idprod == 0)
{
// Product not selected
$error++;
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ProductOrService")).'</div>';
} }
if ($idprod == -1) if ($idprod == -1)
{ {
// Quantity too low // Quantity too low
$error++;
$langs->load("errors"); $langs->load("errors");
$mesg='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>';
} }
@ -583,35 +613,37 @@ elseif ($action == 'addline')
$tauxtva = price2num($tauxtva); $tauxtva = price2num($tauxtva);
$localtax1tx= get_localtax($tauxtva, 1, $mysoc,$object->thirdparty); $localtax1tx= get_localtax($tauxtva, 1, $mysoc,$object->thirdparty);
$localtax2tx= get_localtax($tauxtva, 2, $mysoc,$object->thirdparty); $localtax2tx= get_localtax($tauxtva, 2, $mysoc,$object->thirdparty);
$remise_percent=GETPOST('remise_percent');
if (! $_POST['dp_desc']) if (! $product_desc)
{ {
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")).'</div>';
} }
else else
{ {
$type = $_POST["type"]; $type = $_POST["type"];
if (! empty($_POST['amount']))
if (! empty($_POST['amount']))
{ {
$ht = price2num($_POST['amount']); $ht = price2num($_POST['amount']);
$price_base_type = 'HT'; $price_base_type = 'HT';
//$desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0) //print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0
$result=$object->addline($_POST['dp_desc'], $ht, $tauxtva, $localtax1tx, $localtax2tx, $_POST['qty'], 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type); $result=$object->addline($product_desc, $ht, $tauxtva, $localtax1tx, $localtax2tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type);
} }
else else
{ {
$ttc = price2num($_POST['amountttc']); $ttc = price2num($_POST['amountttc']);
$ht = $ttc / (1 + ($tauxtva / 100)); $ht = $ttc / (1 + ($tauxtva / 100));
$price_base_type = 'HT'; $price_base_type = 'HT';
$result=$object->addline($_POST['dp_desc'], $ht, $tauxtva,$localtax1tx, $localtax2tx, $_POST['qty'], 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type); //print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0
$result=$object->addline($product_desc, $ht, $tauxtva,$localtax1tx, $localtax2tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type);
} }
} }
} }
//print "xx".$tva_tx; exit; //print "xx".$tva_tx; exit;
if ($result > 0) if (! $error && $result > 0)
{ {
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
@ -622,7 +654,8 @@ elseif ($action == 'addline')
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{
$result=supplier_invoice_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); $result=supplier_invoice_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) if ($result <= 0)
{ {
@ -633,15 +666,20 @@ elseif ($action == 'addline')
unset($_POST['qty']); unset($_POST['qty']);
unset($_POST['type']); unset($_POST['type']);
unset($_POST['idprodfournprice']);
unset($_POST['remise_percent']); unset($_POST['remise_percent']);
unset($_POST['dp_desc']); unset($_POST['dp_desc']);
unset($_POST['np_desc']);
unset($_POST['pu']); unset($_POST['pu']);
unset($_POST['tva_tx']); unset($_POST['tva_tx']);
unset($_POST['label']); unset($_POST['label']);
unset($localtax1_tx); unset($localtax1_tx);
unset($localtax2_tx); unset($localtax2_tx);
unset($_POST['idprodfournprice']);
unset($_POST['qty_predef']);
unset($_POST['remise_percent_predef']);
unset($_POST['fournprice_predef']);
unset($_POST['buying_price_predef']);
unset($_POST['np_desc']);
} }
else if (empty($mesg)) else if (empty($mesg))
{ {
@ -1103,6 +1141,7 @@ if ($action == 'create')
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">'; print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">'; print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref // Ref
@ -1374,6 +1413,7 @@ else
*/ */
$head = facturefourn_prepare_head($object); $head = facturefourn_prepare_head($object);
$titre=$langs->trans('SupplierInvoice'); $titre=$langs->trans('SupplierInvoice');
dol_fiche_head($head, 'card', $titre, 0, 'bill'); dol_fiche_head($head, 'card', $titre, 0, 'bill');
dol_htmloutput_mesg($mesg); dol_htmloutput_mesg($mesg);
@ -1542,7 +1582,7 @@ else
{ {
if ($societe->localtax1_assuj=="1") $nbrows++; if ($societe->localtax1_assuj=="1") $nbrows++;
if ($societe->localtax2_assuj=="1") $nbrows++; if ($societe->localtax2_assuj=="1") $nbrows++;
} }
print '<td rowspan="'.$nbrows.'" valign="top">'; print '<td rowspan="'.$nbrows.'" valign="top">';
$sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid, p.fk_bank,'; $sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid, p.fk_bank,';
@ -1790,8 +1830,21 @@ else
/* /*
* Lines * Lines
*/ */
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?etat=1&id='.$object->id.(($action != 'edit_line')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">
<input type="hidden" name="action" value="'.(($action != 'edit_line')?'addline':'update_line').'">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="'.$object->id.'">
<input type="hidden" name="facid" value="'.$object->id.'">
<input type="hidden" name="socid" value="'.$societe->id.'">
';
print '<br>'; print '<br>';
print '<table class="noborder" width="100%">'; print '<table id="tablelines" class="noborder noshadow" width="100%">';
$var=1; $var=1;
$num=count($object->lines); $num=count($object->lines);
for ($i = 0; $i < $num; $i++) for ($i = 0; $i < $num; $i++)
@ -1833,13 +1886,13 @@ else
// Edit line // Edit line
if ($object->statut == 0 && $action == 'edit_line' && $_GET['etat'] == '0' && $_GET['lineid'] == $object->lines[$i]->rowid) if ($object->statut == 0 && $action == 'edit_line' && $_GET['etat'] == '0' && $_GET['lineid'] == $object->lines[$i]->rowid)
{ {
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;etat=1&amp;lineid='.$object->lines[$i]->rowid.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update_line">';
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
// Show product and description // Show product and description
print '<td>'; print '<td>';
print '<input type="hidden" name="lineid" value="'.$object->lines[$i]->rowid.'">';
if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $object->lines[$i]->fk_product) if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $object->lines[$i]->fk_product)
{ {
print '<input type="hidden" name="idprod" value="'.$object->lines[$i]->fk_product.'">'; print '<input type="hidden" name="idprod" value="'.$object->lines[$i]->fk_product.'">';
@ -1888,11 +1941,10 @@ else
print '<td align="right" class="nowrap">&nbsp;</td>'; print '<td align="right" class="nowrap">&nbsp;</td>';
print '<td align="center" colspan="2"><input type="submit" class="button" value="'.$langs->trans('Save').'">'; print '<td align="center" colspan="2"><input type="submit" class="button" name="save" value="'.$langs->trans('Save').'">';
print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>'; print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>';
print '</tr>'; print '</tr>';
print '</form>';
} }
else // Affichage simple de la ligne else // Affichage simple de la ligne
{ {
@ -1972,7 +2024,7 @@ else
/* /*
* Form to add new line * Form to add new line
*/ */
if ($object->statut == 0 && $action != 'edit_line') if ($object->statut == 0 && $action != 'edit_line')
{ {
@ -1992,11 +2044,6 @@ else
print '</tr>'; print '</tr>';
// Add free products/services form // Add free products/services form
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addline" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="facid" value="'.$object->id.'">';
print '<input type="hidden" name="socid" value="'.$societe->id.'">';
$var=true; $var=true;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td>'; print '<td>';
@ -2022,23 +2069,30 @@ else
print $form->load_tva('tauxtva',(GETPOST('tauxtva')?GETPOST('tauxtva'):-1),$societe,$mysoc); print $form->load_tva('tauxtva',(GETPOST('tauxtva')?GETPOST('tauxtva'):-1),$societe,$mysoc);
print '</td>'; print '</td>';
print '<td align="right">'; print '<td align="right">';
print '<input size="4" name="amount" type="text">'; print '<input size="4" name="amount" type="text" value="'.GETPOST("amount").'">';
print '</td>'; print '</td>';
print '<td align="right">'; print '<td align="right">';
print '<input size="4" name="amountttc" type="text">'; print '<input size="4" name="amountttc" type="text" value="'.GETPOST("amountttc").'">';
print '</td>'; print '</td>';
print '<td align="right">'; print '<td align="right">';
print '<input size="1" name="qty" type="text" value="1">'; print '<input size="1" name="qty" type="text" value="1" value="'.GETPOST("qty").'">';
print '</td>'; print '</td>';
print '<td align="right" class="nowrap"><input size="1" name="remise_percent" type="text" value="'.(GETPOST('remise_percent')?GETPOST('remise_percent'):'0').'"><span class="hideonsmartphone">%</span></td>'; print '<td align="right" class="nowrap"><input size="1" name="remise_percent" type="text" value="'.(GETPOST('remise_percent')?GETPOST('remise_percent'):'0').'"><span class="hideonsmartphone">%</span></td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td align="center" valign="middle" colspan="2"><input type="submit" class="button" value="'.$langs->trans('Add').'"></td></tr>'; print '<td align="center" valign="middle" colspan="2"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline_libre"></td></tr>';
print '</form>';
// Ajout de produits/services predefinis // Ajout de produits/services predefinis
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
{ {
print '<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#idprodfournprice\').change(function() {
if (jQuery(\'#idprodfournprice\').val() > 0) jQuery(\'#np_desc\').focus();
});
});
</script>';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td colspan="4">'; print '<td colspan="4">';
print $langs->trans("AddNewLine").' - '; print $langs->trans("AddNewLine").' - ';
@ -2057,30 +2111,16 @@ else
print '<td colspan="4">&nbsp;</td>'; print '<td colspan="4">&nbsp;</td>';
print '</tr>'; print '</tr>';
// TODO Use the predefinedproductline_create.tpl.php file
print '<form name="addline_predef" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addline" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="socid" value="'. $object->socid .'">';
print '<input type="hidden" name="facid" value="'.$object->id.'">';
print '<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#idprodfournprice\').change(function() {
if (jQuery(\'#idprodfournprice\').val() > 0) jQuery(\'#np_desc\').focus();
});
});
</script>';
$var=! $var; $var=! $var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td colspan="4">'; print '<td colspan="4">';
$ajaxoptions=array( $ajaxoptions=array(
'update' => array('pqty' => 'qty', 'p_remise_percent' => 'discount'), 'update' => array('qty_predef' => 'qty_predef', 'remise_percent_predef' => 'remise_percent_predef'),
'disabled' => 'addPredefinedProductButton', 'disabled' => 'addPredefinedProductButton',
'error' => $langs->trans("NoPriceDefinedForThisSupplier") 'error' => $langs->trans("NoPriceDefinedForThisSupplier")
); );
$form->select_produits_fournisseurs($object->socid, '', 'idprodfournprice', '', '', $ajaxoptions); $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions);
if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>'; if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>';
@ -2096,19 +2136,21 @@ else
$doleditor->Create(); $doleditor->Create();
print '</td>'; print '</td>';
print '<td align="right"><input type="text" id="pqty" name="qty" value="1" size="1"></td>'; print '<td align="right"><input type="text" id="qty_predef" name="qty_predef" value="1" size="1"></td>';
print '<td align="right" class="nowrap"><input size="1" id="p_remise_percent" name="remise_percent" type="text" value="'.(GETPOST('remise_percent')?GETPOST('remise_percent'):'0').'"><span class="hideonsmartphone">%</span></td>'; print '<td align="right" class="nowrap"><input size="1" id="remise_percent_predef" name="remise_percent_predef" type="text" value="'.(GETPOST('remise_percent_predef')?GETPOST('remise_percent_predef'):'0').'"><span class="hideonsmartphone">%</span></td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td align="center" valign="middle" colspan="2"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans("Add").'"></td>'; print '<td align="center" valign="middle" colspan="2"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans("Add").'" name="addline_predefined"></td>';
print '</tr>'; print '</tr>';
print '</form>';
} }
} }
print '</table>'; print '</table>';
print '</div>'; print '</form>';
dol_fiche_end();
if ($action != 'presend') if ($action != 'presend')
{ {