diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index 3e42e18e3f3..29570ec379c 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -356,35 +356,36 @@ if ($nolinesbefore) {
">
- multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
+ multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
$coldisplay++;
?>
'."\n";
+ if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print ' | '; }
+ print '';
+ $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
+ $date_end = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
+ if (!empty($object->element) && $object->element == 'contrat')
+ {
+ print $langs->trans("DateStartPlanned").' ';
+ print $form->selectDate($date_start, "date_start", $usehm, $usehm, 1, "addproduct");
+ print ' '.$langs->trans("DateEndPlanned").' ';
+ print $form->selectDate($date_end, "date_end", $usehm, $usehm, 1, "addproduct");
+ }
+ else
+ {
+ print $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
+ print $form->selectDate($date_start, 'date_start', empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, 1, "addproduct", 1, 0);
+ print ' '.$langs->trans('to').' ';
+ print $form->selectDate($date_end, 'date_end', empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, 1, "addproduct", 1, 0);
+ };
+ print '';
+ print ' | ';
+ print '
'."\n";
+}
+
+
+print "';
+ }
?>
-
-
-\n";
+
+ /* When changing predefined product, we reload list of supplier prices required for margin combo */
+ $("#idprod, #idprodfournprice").change(function()
+ {
+ console.log("#idprod, #idprodfournprice change triggered this.val = "+$(this).val());
+
+ setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva
+
+ jQuery('#trlinefordates').show();
+
+ global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier))
+ {
+ ?>
+ // Get the HT price for the product and display it
+ $.post('/product/ajax/products.php?action=fetch',
+ { 'id': $(this).val(), 'socid' : socid; ?> },
+ function(data) { jQuery("#price_ht").val(data.price_ht); },
+ 'json'
+ );
+ rights->margins->creer)
{
+ $langs->load('stocks');
?>
- /* Some js test when we click on button "Add" */
- jQuery(document).ready(function() {
+ /* Code for margin */
+ $("#fournprice_predef").find("option").remove();
+ $("#fournprice_predef").hide();
+ $("#buying_price").val("").show();
+ /* Call post to load content of combo list fournprice_predef */
+ $.post('/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val() }, function(data) {
+ if (data && data.length > 0)
+ {
+ var options = ''; var defaultkey = ''; var defaultprice = ''; var bestpricefound = 0;
+
+ var bestpriceid = 0; var bestpricevalue = 0;
+ var pmppriceid = 0; var pmppricevalue = 0;
+ var costpriceid = 0; var costpricevalue = 0;
+
+ /* setup of margin calculation */
+ var defaultbuyprice = 'global->MARGIN_TYPE))
+ {
+ if ($conf->global->MARGIN_TYPE == '1') print 'bestsupplierprice';
+ if ($conf->global->MARGIN_TYPE == 'pmp') print 'pmp';
+ if ($conf->global->MARGIN_TYPE == 'costprice') print 'costprice';
+ } ?>';
+ console.log("we will set the field for margin. defaultbuyprice="+defaultbuyprice);
+
+ var i = 0;
+ $(data).each(function() {
+ if (this.id != 'pmpprice' && this.id != 'costprice')
+ {
+ i++;
+ this.price = parseFloat(this.price); // to fix when this.price >0
+ // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
+ //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
+ if (bestpricefound == 0 && this.price > 0) { defaultkey = this.id; defaultprice = this.price; bestpriceid = this.id; bestpricevalue = this.price; bestpricefound=1; } // bestpricefound is used to take the first price > 0
+ }
+ if (this.id == 'pmpprice')
+ {
+ // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
+ //console.log("id="+this.id+"-price="+this.price);
+ if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
+ {
+ if (this.price > 0) {
+ defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
+ //console.log("pmppricevalue="+pmppricevalue);
+ }
+ }
+ }
+ if (this.id == 'costprice')
+ {
+ // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
+ //console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
+ if ('costprice' == defaultbuyprice)
+ {
+ if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
+ else if (pmppricevalue > 0) { defaultkey = pmppriceid; defaultprice = pmppricevalue; }
+ }
+ }
+ options += '