diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index 8e664a89c3c..64769fa704f 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -18,21 +18,32 @@
* along with this program. If not, see .
*
* Need to have following variables defined:
+ * $object (invoice, order, ...)
* $conf
* $langs
* $dateSelector
- * $this (invoice, order, ...)
- * $inputalsopricewithtax
* $forceall (0 by default, 1 for supplier invoices/orders)
* $senderissupplier (0 by default, 1 for supplier invoices/orders)
+ * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
*/
-global $dateSelector, $forceall, $senderissupplier;
$usemargins=0;
if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1;
+
+global $dateSelector, $forceall, $senderissupplier, $inputalsopricewithtax;
+if (empty($dateSelector)) $dateSelector=0;
if (empty($forceall)) $forceall=0;
if (empty($senderissupplier)) $senderissupplier=0;
+if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
+
+
+// Define colspan for button Add
+$colspan = 3; // Col total ht + col edit + col delete
+if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc
+if (in_array($object->element,array('propal','facture','invoice','commande','order'))) $colspan++; // With this, there is a column move
+if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
+if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
?>
@@ -49,7 +60,6 @@ if (empty($senderissupplier)) $senderissupplier=0;
trans('Qty'); ?>
trans('ReductionShort'); ?>
@@ -62,22 +72,8 @@ if (empty($senderissupplier)) $senderissupplier=0;
?>
rights->margins->creer)
- {
- if(! empty($conf->global->DISPLAY_MARGIN_RATES))
- {
- echo ''.$langs->trans('MarginRate').' ';
- }
- if(! empty($conf->global->DISPLAY_MARK_RATES))
- {
- echo ''.$langs->trans('MarkRate').' ';
- }
- }
- else
- {
- if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
- if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
- }
+ if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARGIN_RATES)) echo ''.$langs->trans('MarginRate').' ';
+ if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARK_RATES)) echo ''.$langs->trans('MarkRate').' ';
}
?>
@@ -98,20 +94,30 @@ else {
// Free line
echo '';
// Show radio free line
- if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) echo ' ';
+ if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
+ {
+ echo ' product->enabled) || empty($conf->service->enabled)))?' checked="true"':'') );
+ echo (GETPOST('prod_entry_mode')=='free' ? ' checked="true"' : '');
+ echo '> ';
+ }
else echo ' ';
// Show type selector
- if (empty($conf->product->enabled) && empty($conf->service->enabled))
+/* if (empty($conf->product->enabled) && empty($conf->service->enabled))
{
// If module product and service disabled, by default this is a product except for contracts it is a service
print ' ';
}
- else {
- if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' ';
+ else {*/
+ echo $langs->trans("FreeLineOfType");
+ /*
+ if (empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans("Type");
+ else if (! empty($forceall) || (! empty($conf->product->enabled) && ! empty($conf->service->enabled))) echo $langs->trans("FreeLineOfType");
else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '.$langs->trans("Service");
- else if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '.$langs->trans("Product");
- echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,1,$forceall);
- }
+ else if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '.$langs->trans("Product");*/
+ echo ' ';
+ echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,1,1);
+// }
echo ' ';
// Predefined product/service
@@ -200,8 +206,8 @@ else {
">
remise_client); ?>" name="remise_percent">%
+
@@ -214,32 +220,25 @@ else {
">
rights->margins->creer)
{
- if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
+ if (! empty($conf->global->DISPLAY_MARGIN_RATES))
+ {
echo '% ';
- $colspan++;
$coldisplay++;
}
- if (! empty($conf->global->DISPLAY_MARK_RATES)) {
+ if (! empty($conf->global->DISPLAY_MARK_RATES))
+ {
echo '% ';
- $colspan++;
$coldisplay++;
}
}
else
{
- if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
- $colspan++;
- $coldisplay++;
- }
- if (! empty($conf->global->DISPLAY_MARK_RATES)) {
- $colspan++;
- $coldisplay++;
- }
+ if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $coldisplay++;
+ if (! empty($conf->global->DISPLAY_MARK_RATES)) $coldisplay++;
}
}
?>
@@ -491,6 +490,7 @@ function setforfree() {
jQuery("#prod_entry_mode_free").attr('checked',true);
jQuery("#prod_entry_mode_predef").attr('checked',false);
jQuery("#price_ht").show();
+ jQuery("#price_ttc").show(); // May no exists
jQuery("#tva_tx").show();
jQuery("#buying_price").val('').show();
jQuery("#fournprice_predef").hide();
@@ -503,6 +503,7 @@ function setforpredef() {
jQuery("#prod_entry_mode_free").attr('checked',false);
jQuery("#prod_entry_mode_predef").attr('checked',true);
jQuery("#price_ht").hide();
+ jQuery("#price_ttc").hide(); // May no exists
jQuery("#tva_tx").hide();
jQuery("#buying_price").show();
jQuery("#title_vat").hide();
diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php
index c9e8ded2e9e..94ad11c991c 100644
--- a/htdocs/core/tpl/objectline_edit.tpl.php
+++ b/htdocs/core/tpl/objectline_edit.tpl.php
@@ -93,7 +93,7 @@ $coldisplay=-1; // We remove first td
$nbrows=ROWS_2;
if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
$enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
- $doleditor=new DolEditor('product_desc',$line->description,'',164,'dolibarr_details','',false,true,$enable,$nbrows,70);
+ $doleditor=new DolEditor('product_desc',$line->description,'',164,'dolibarr_details','',false,true,$enable,$nbrows,'98%');
$doleditor->Create();
?>
diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index 5fd66e90f55..a787930471a 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -515,34 +515,6 @@ elseif ($action == 'update_line' && $user->rights->fournisseur->facture->creer)
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')
- || (GETPOST('dp_desc') && ! GETPOST('addline_libre') && ! GETPOST('idprod', 'int')>0) // we push enter onto qty field
- )
- {
- $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')
- || (! GETPOST('dp_desc') && ! GETPOST('addline_predefined') && GETPOST('idprod', 'int')>0) // we push enter onto qty field
- )
- {
- $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);
if ($ret < 0)
{
@@ -551,19 +523,65 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
}
$ret=$object->fetch_thirdparty();
- if (GETPOST('addline_predefined') || GETPOST('search_idprodfournprice') || GETPOST('idprodfournprice')) // With combolist idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
+ $langs->load('errors');
+ $error=0;
+
+ // Set if we used free entry or predefined product
+ $predef='';
+ $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
+ if (GETPOST('prod_entry_mode') == 'free')
+ {
+ $idprod=0;
+ $price_ht = GETPOST('price_ht');
+ $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
+ }
+ else
+ {
+ $idprod=GETPOST('idprod', 'int');
+ $price_ht = '';
+ $tva_tx = '';
+ }
+
+ $qty = GETPOST('qty'.$predef);
+ $remise_percent=GETPOST('remise_percent'.$predef);
+
+ if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0)
+ {
+ setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors');
+ $error++;
+ }
+ if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('idprodfournprice') && GETPOST('type') < 0)
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
+ $error++;
+ }
+ if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht')==='' && GETPOST('price_ttc')==='') // Unit price can be 0 but not ''
+ {
+ setEventMessage($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), 'errors');
+ $error++;
+ }
+ if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('dp_desc'))
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
+ $error++;
+ }
+ if (! GETPOST('qty'))
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
+ $error++;
+ }
+
+ if (GETPOST('prod_entry_mode') != 'free') // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
{
$idprod=0;
$productsupplier=new ProductFournisseur($db);
- if (GETPOST('idprodfournprice') == '')
- {
- $idprod=-1;
- }
+ if (GETPOST('idprodfournprice') == -1 || GETPOST('idprodfournprice') == '') $idprod=-2; // Same behaviour than with combolist. When not select idprodfournprice is now -2 (to avoid conflict with next action that may return -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
- }
+ {
+ $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)
{
@@ -584,7 +602,7 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
$result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1tx, $localtax2tx, $qty, $idprod, $remise_percent, '', '', 0, $npr);
}
- if ($idprod == 0)
+ if ($idprod == -2 || $idprod == 0)
{
// Product not selected
$error++;
@@ -599,39 +617,37 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
$mesg=''.$langs->trans("ErrorQtyTooLowForThisSupplier").'
';
}
}
- else
- {
- $npr = preg_match('/\*/', $_POST['tauxtva']) ? 1 : 0 ;
- $tauxtva = str_replace('*','',$_POST["tauxtva"]);
- $tauxtva = price2num($tauxtva);
- $localtax1tx= get_localtax($tauxtva, 1, $mysoc,$object->thirdparty);
- $localtax2tx= get_localtax($tauxtva, 2, $mysoc,$object->thirdparty);
+ else if( GETPOST('price_ht')!=='' || GETPOST('price_ttc')!=='' )
+ {
+ $pu_ht = price2num($price_ht, 'MU');
+ $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
+ $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
+ $tva_tx = str_replace('*', '', $tva_tx);
+ $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
+ $desc = $product_desc;
+ $type = GETPOST('type');
- if (! $product_desc)
- {
- $error++;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")).'
';
+ $tva_tx = price2num($tva_tx); // When vat is text input field
+
+ // Local Taxes
+ $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
+ $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
+
+ if (!empty($_POST['price_ht']))
+ {
+ $ht = price2num($_POST['price_ht']);
+ $price_base_type = 'HT';
+
+ //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, $tva_tx, $localtax1tx, $localtax2tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type);
}
else
- {
- $type = $_POST["type"];
-
- if (! empty($_POST['amount']))
- {
- $ht = price2num($_POST['amount']);
- $price_base_type = 'HT';
-
- //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);
- }
- else
- {
- $ttc = price2num($_POST['amountttc']);
- $ht = $ttc / (1 + ($tauxtva / 100));
- $price_base_type = 'HT';
- //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);
- }
+ {
+ $ttc = price2num($_POST['price_ttc']);
+ $ht = $ttc / (1 + ($tva_tx / 100));
+ $price_base_type = 'HT';
+ //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, $tva_tx,$localtax1tx, $localtax2tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type);
}
}
@@ -657,22 +673,35 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
}
}
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['remise_percent']);
- unset($_POST['dp_desc']);
- unset($_POST['pu']);
- unset($_POST['tva_tx']);
- unset($_POST['label']);
- unset($localtax1_tx);
- unset($localtax2_tx);
+ unset($_POST ['prod_entry_mode']);
- 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']);
+ unset($_POST['qty']);
+ unset($_POST['type']);
+ unset($_POST['remise_percent']);
+ unset($_POST['pu']);
+ unset($_POST['price_ht']);
+ unset($_POST['price_ttc']);
+ unset($_POST['tva_tx']);
+ unset($_POST['label']);
+ unset($localtax1_tx);
+ unset($localtax2_tx);
+ unset($_POST['np_marginRate']);
+ unset($_POST['np_markRate']);
+ unset($_POST['dp_desc']);
+ unset($_POST['idprodfournprice']);
+
+ unset($_POST['date_starthour']);
+ unset($_POST['date_startmin']);
+ unset($_POST['date_startsec']);
+ unset($_POST['date_startday']);
+ unset($_POST['date_startmonth']);
+ unset($_POST['date_startyear']);
+ unset($_POST['date_endhour']);
+ unset($_POST['date_endmin']);
+ unset($_POST['date_endsec']);
+ unset($_POST['date_endday']);
+ unset($_POST['date_endmonth']);
+ unset($_POST['date_endyear']);
}
else if (empty($mesg))
{
@@ -2021,13 +2050,10 @@ else
}
- /*
- * Form to add new line
- */
-
+ // Form to add new line
if ($object->statut == 0 && $action != 'edit_line')
{
- print '';
+ /*print ' ';
print '';
print ' '; // ancre
print $langs->trans('AddNewLine').' - '.$langs->trans("FreeZone").' ';
@@ -2040,9 +2066,26 @@ else
print ' ';
print ' ';
print ' ';
- print ' ';
+ print '';*/
+
+ global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
+ $forceall=1; $senderissupplier=1; $dateSelector=0; $inputalsopricewithtax=1;
+ if ($object->statut == 0 && $user->rights->propal->creer)
+ {
+ if ($action != 'editline')
+ {
+ $var = true;
+
+ // Add free products/services
+ $object->formAddObjectLine(1, $mysoc, $soc);
+
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+ }
+ }
// Add free products/services form
+ /*
$var=true;
print '';
print '';
@@ -2141,7 +2184,7 @@ else
print ' ';
print ' ';
print ' ';
- }
+ }*/
}
print '';