Fix ident
This commit is contained in:
parent
e7ac01e1bd
commit
b90dbb585a
@ -434,389 +434,388 @@ if ($nolinesbefore) {
|
|||||||
if (is_object($objectline)) {
|
if (is_object($objectline)) {
|
||||||
print $objectline->showOptionals($extrafields, 'edit', array('colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD) ? 0 : 1);
|
print $objectline->showOptionals($extrafields, 'edit', array('colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!empty($conf->service->enabled) || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') // We show date field if required
|
if ((!empty($conf->service->enabled) || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') // We show date field if required
|
||||||
{
|
{
|
||||||
?>
|
print '<tr id="trlinefordates" class="oddeven">'."\n";
|
||||||
|
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print '<td></td>'; }
|
||||||
<tr id="trlinefordates" <?php echo $bcnd[$var]; ?>>
|
print '<td colspan="'.($coldisplay - (empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? 0 : 1)).'">';
|
||||||
<?php if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print '<td></td>'; } ?>
|
$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
|
||||||
<td colspan="<?php echo $coldisplay - (empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? 0 : 1); ?>">
|
$date_end = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
|
||||||
<?php
|
if (!empty($object->element) && $object->element == 'contrat')
|
||||||
$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'));
|
print $langs->trans("DateStartPlanned").' ';
|
||||||
if (!empty($object->element) && $object->element == 'contrat')
|
print $form->selectDate($date_start, "date_start", $usehm, $usehm, 1, "addproduct");
|
||||||
{
|
print ' '.$langs->trans("DateEndPlanned").' ';
|
||||||
print $langs->trans("DateStartPlanned").' ';
|
print $form->selectDate($date_end, "date_end", $usehm, $usehm, 1, "addproduct");
|
||||||
print $form->selectDate($date_start, "date_start", $usehm, $usehm, 1, "addproduct");
|
}
|
||||||
print ' '.$langs->trans("DateEndPlanned").' ';
|
else
|
||||||
print $form->selectDate($date_end, "date_end", $usehm, $usehm, 1, "addproduct");
|
{
|
||||||
|
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 '<script>';
|
||||||
|
if (!$date_start) {
|
||||||
|
if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
|
||||||
|
print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
|
||||||
}
|
}
|
||||||
else
|
if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
|
||||||
{
|
print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
|
||||||
echo $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);
|
|
||||||
echo ' '.$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 '<script>';
|
|
||||||
if (!$date_start) {
|
|
||||||
if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
|
|
||||||
print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
|
|
||||||
}
|
|
||||||
if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
|
|
||||||
print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!$date_end) {
|
}
|
||||||
if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
|
if (!$date_end) {
|
||||||
print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
|
if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
|
||||||
}
|
print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
|
||||||
if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
|
|
||||||
print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
print '</script>';
|
if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
|
||||||
?>
|
print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
|
||||||
</td>
|
}
|
||||||
</tr>
|
}
|
||||||
<?php
|
print '</script>';
|
||||||
|
print '</td>';
|
||||||
|
print '</tr>'."\n";
|
||||||
}
|
}
|
||||||
print "<script>\n";
|
|
||||||
if (!empty($usemargins) && $user->rights->margins->creer)
|
|
||||||
{
|
|
||||||
?>
|
|
||||||
|
|
||||||
/* Some js test when we click on button "Add" */
|
|
||||||
jQuery(document).ready(function() {
|
print "<script>\n";
|
||||||
<?php
|
if (!empty($usemargins) && $user->rights->margins->creer)
|
||||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
|
{
|
||||||
$("input[name='np_marginRate']:first").blur(function(e) {
|
?>
|
||||||
return checkFreeLine(e, "np_marginRate");
|
/* Some js test when we click on button "Add" */
|
||||||
});
|
jQuery(document).ready(function() {
|
||||||
<?php
|
<?php
|
||||||
}
|
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
|
||||||
if (!empty($conf->global->DISPLAY_MARK_RATES)) { ?>
|
$("input[name='np_marginRate']:first").blur(function(e) {
|
||||||
$("input[name='np_markRate']:first").blur(function(e) {
|
return checkFreeLine(e, "np_marginRate");
|
||||||
return checkFreeLine(e, "np_markRate");
|
});
|
||||||
});
|
<?php
|
||||||
<?php
|
}
|
||||||
}
|
if (!empty($conf->global->DISPLAY_MARK_RATES)) { ?>
|
||||||
?>
|
$("input[name='np_markRate']:first").blur(function(e) {
|
||||||
|
return checkFreeLine(e, "np_markRate");
|
||||||
});
|
});
|
||||||
|
|
||||||
/* TODO This does not work for number with thousand separator that is , */
|
|
||||||
function checkFreeLine(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 dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
|
|
||||||
e.stopPropagation();
|
|
||||||
setTimeout(function () { rate.focus() }, 50);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (npRate == "np_markRate" && rate.val() >= 100)
|
|
||||||
{
|
|
||||||
alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
|
|
||||||
e.stopPropagation();
|
|
||||||
setTimeout(function () { rate.focus() }, 50);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var price = 0;
|
|
||||||
remisejs=price2numjs(remise.val());
|
|
||||||
|
|
||||||
if (remisejs != 100) // If a discount not 100 or no discount
|
|
||||||
{
|
|
||||||
if (remisejs == '') remisejs=0;
|
|
||||||
|
|
||||||
bpjs=price2numjs(buying_price.val());
|
|
||||||
ratejs=price2numjs(rate.val());
|
|
||||||
|
|
||||||
if (npRate == "np_marginRate")
|
|
||||||
price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
|
|
||||||
else if (npRate == "np_markRate")
|
|
||||||
price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
|
|
||||||
}
|
|
||||||
$("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
});
|
||||||
|
|
||||||
/* JQuery for product free or predefined select */
|
/* TODO This does not work for number with thousand separator that is , */
|
||||||
jQuery(document).ready(function() {
|
function checkFreeLine(e, npRate)
|
||||||
jQuery("#price_ht").keyup(function(event) {
|
{
|
||||||
// console.log(event.which); // discard event tag and arrows
|
var buying_price = $("input[name='buying_price']:first");
|
||||||
if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
|
var remise = $("input[name='remise_percent']:first");
|
||||||
jQuery("#price_ttc").val('');
|
|
||||||
jQuery("#multicurrency_subprice").val('');
|
var rate = $("input[name='"+npRate+"']:first");
|
||||||
}
|
if (rate.val() == '')
|
||||||
});
|
return true;
|
||||||
jQuery("#price_ttc").keyup(function(event) {
|
|
||||||
// console.log(event.which); // discard event tag and arrows
|
if (! $.isNumeric(rate.val().replace(',','.')))
|
||||||
if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
|
{
|
||||||
jQuery("#price_ht").val('');
|
alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
|
||||||
jQuery("#multicurrency_subprice").val('');
|
e.stopPropagation();
|
||||||
}
|
setTimeout(function () { rate.focus() }, 50);
|
||||||
});
|
return false;
|
||||||
jQuery("#multicurrency_subprice").keyup(function(event) {
|
}
|
||||||
// console.log(event.which); // discard event tag and arrows
|
if (npRate == "np_markRate" && rate.val() >= 100)
|
||||||
if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
|
{
|
||||||
jQuery("#price_ht").val('');
|
alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
|
||||||
jQuery("#price_ttc").val('');
|
e.stopPropagation();
|
||||||
}
|
setTimeout(function () { rate.focus() }, 50);
|
||||||
});
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var price = 0;
|
||||||
|
remisejs=price2numjs(remise.val());
|
||||||
|
|
||||||
|
if (remisejs != 100) // If a discount not 100 or no discount
|
||||||
|
{
|
||||||
|
if (remisejs == '') remisejs=0;
|
||||||
|
|
||||||
|
bpjs=price2numjs(buying_price.val());
|
||||||
|
ratejs=price2numjs(rate.val());
|
||||||
|
|
||||||
|
if (npRate == "np_marginRate")
|
||||||
|
price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
|
||||||
|
else if (npRate == "np_markRate")
|
||||||
|
price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
|
||||||
|
}
|
||||||
|
$("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
/* JQuery for product free or predefined select */
|
||||||
|
jQuery(document).ready(function() {
|
||||||
|
jQuery("#price_ht").keyup(function(event) {
|
||||||
|
// console.log(event.which); // discard event tag and arrows
|
||||||
|
if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
|
||||||
|
jQuery("#price_ttc").val('');
|
||||||
|
jQuery("#multicurrency_subprice").val('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
jQuery("#price_ttc").keyup(function(event) {
|
||||||
|
// console.log(event.which); // discard event tag and arrows
|
||||||
|
if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
|
||||||
|
jQuery("#price_ht").val('');
|
||||||
|
jQuery("#multicurrency_subprice").val('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
jQuery("#multicurrency_subprice").keyup(function(event) {
|
||||||
|
// console.log(event.which); // discard event tag and arrows
|
||||||
|
if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
|
||||||
|
jQuery("#price_ht").val('');
|
||||||
|
jQuery("#price_ttc").val('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#prod_entry_mode_free").on( "click", function() {
|
||||||
|
setforfree();
|
||||||
|
});
|
||||||
|
$("#select_type").change(function()
|
||||||
|
{
|
||||||
|
setforfree();
|
||||||
|
if (jQuery('#select_type').val() >= 0)
|
||||||
|
{
|
||||||
|
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */
|
||||||
|
jQuery('#dp_desc').focus();
|
||||||
|
/* focus if CKEDITOR */
|
||||||
|
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
|
||||||
|
{
|
||||||
|
var editor = CKEDITOR.instances['dp_desc'];
|
||||||
|
if (editor) { editor.focus(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("Hide/show date according to product type");
|
||||||
|
if (jQuery('#select_type').val() == '0')
|
||||||
|
{
|
||||||
|
jQuery('#trlinefordates').hide();
|
||||||
|
jQuery('.divlinefordates').hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jQuery('#trlinefordates').show();
|
||||||
|
jQuery('.divlinefordates').show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#prod_entry_mode_predef").on( "click", function() {
|
||||||
|
console.log("click prod_entry_mode_predef");
|
||||||
|
setforpredef();
|
||||||
|
jQuery('#trlinefordates').show();
|
||||||
|
});
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if (!$freelines) { ?>
|
||||||
|
$("#prod_entry_mode_predef").click();
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
|
||||||
$("#prod_entry_mode_free").on( "click", function() {
|
|
||||||
setforfree();
|
|
||||||
});
|
|
||||||
$("#select_type").change(function()
|
|
||||||
{
|
|
||||||
setforfree();
|
|
||||||
if (jQuery('#select_type').val() >= 0)
|
|
||||||
{
|
|
||||||
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */
|
|
||||||
jQuery('#dp_desc').focus();
|
|
||||||
/* focus if CKEDITOR */
|
|
||||||
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
|
|
||||||
{
|
|
||||||
var editor = CKEDITOR.instances['dp_desc'];
|
|
||||||
if (editor) { editor.focus(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log("Hide/show date according to product type");
|
|
||||||
if (jQuery('#select_type').val() == '0')
|
|
||||||
{
|
|
||||||
jQuery('#trlinefordates').hide();
|
|
||||||
jQuery('.divlinefordates').hide();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
jQuery('#trlinefordates').show();
|
jQuery('#trlinefordates').show();
|
||||||
jQuery('.divlinefordates').show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#prod_entry_mode_predef").on( "click", function() {
|
|
||||||
console.log("click prod_entry_mode_predef");
|
|
||||||
setforpredef();
|
|
||||||
jQuery('#trlinefordates').show();
|
|
||||||
});
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (!$freelines) { ?>
|
if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier))
|
||||||
$("#prod_entry_mode_predef").click();
|
{
|
||||||
|
?>
|
||||||
|
// Get the HT price for the product and display it
|
||||||
|
$.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
|
||||||
|
{ 'id': $(this).val(), 'socid' : <?php print $object->socid; ?> },
|
||||||
|
function(data) { jQuery("#price_ht").val(data.price_ht); },
|
||||||
|
'json'
|
||||||
|
);
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
if (!empty($usemargins) && $user->rights->margins->creer)
|
||||||
|
{
|
||||||
|
$langs->load('stocks');
|
||||||
|
?>
|
||||||
|
|
||||||
|
/* 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('<?php echo DOL_URL_ROOT; ?>/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 = '<?php
|
||||||
|
if (isset($conf->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 += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
|
||||||
|
});
|
||||||
|
options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
|
||||||
|
|
||||||
|
console.log("finally selected defaultkey="+defaultkey+" defaultprice="+defaultprice);
|
||||||
|
|
||||||
|
$("#fournprice_predef").html(options).show();
|
||||||
|
if (defaultkey != '')
|
||||||
|
{
|
||||||
|
$("#fournprice_predef").val(defaultkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* At loading, no product are yet selected, so we hide field of buying_price */
|
||||||
|
$("#buying_price").hide();
|
||||||
|
|
||||||
|
/* Define default price at loading */
|
||||||
|
var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
|
||||||
|
$("#buying_price").val(defaultprice);
|
||||||
|
|
||||||
|
$("#fournprice_predef").change(function() {
|
||||||
|
console.log("change on fournprice_predef");
|
||||||
|
/* Hide field buying_price according to choice into list (if 'inputprice' or not) */
|
||||||
|
var linevalue=$(this).find('option:selected').val();
|
||||||
|
var pricevalue = $(this).find('option:selected').attr("price");
|
||||||
|
if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
|
||||||
|
$("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
|
||||||
|
}
|
||||||
|
if (linevalue == 'inputprice') {
|
||||||
|
$('#buying_price').show();
|
||||||
|
}
|
||||||
|
if (linevalue == 'pmpprice') {
|
||||||
|
$("#buying_price").val(pricevalue);
|
||||||
|
$('#buying_price').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'json');
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
/* When changing predefined product, we reload list of supplier prices required for margin combo */
|
/* To process customer price per quantity */
|
||||||
$("#idprod, #idprodfournprice").change(function()
|
var pbq = parseInt($('option:selected', this).attr('data-pbq'));
|
||||||
|
var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
|
||||||
|
var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
|
||||||
|
|
||||||
|
if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && typeof pbq !== "undefined")
|
||||||
{
|
{
|
||||||
console.log("#idprod, #idprodfournprice change triggered this.val = "+$(this).val());
|
console.log("We choose a price by quanty price_by_qty id = "+pbq+" price_by_qty qty = "+pbqqty+" price_by_qty percent = "+pbqpercent);
|
||||||
|
jQuery("#pbq").val(pbq);
|
||||||
setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva
|
if (jQuery("#qty").val() < pbqqty)
|
||||||
|
|
||||||
jQuery('#trlinefordates').show();
|
|
||||||
|
|
||||||
<?php
|
|
||||||
if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier))
|
|
||||||
{
|
{
|
||||||
?>
|
jQuery("#qty").val(pbqqty);
|
||||||
// Get the HT price for the product and display it
|
|
||||||
$.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
|
|
||||||
{ 'id': $(this).val(), 'socid' : <?php print $object->socid; ?> },
|
|
||||||
function(data) { jQuery("#price_ht").val(data.price_ht); },
|
|
||||||
'json'
|
|
||||||
);
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
if (!empty($usemargins) && $user->rights->margins->creer)
|
if (jQuery("#remise_percent").val() < pbqpercent)
|
||||||
{
|
{
|
||||||
$langs->load('stocks');
|
jQuery("#remise_percent").val(pbqpercent);
|
||||||
?>
|
|
||||||
|
|
||||||
/* 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('<?php echo DOL_URL_ROOT; ?>/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 = '<?php
|
|
||||||
if (isset($conf->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 += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
|
|
||||||
});
|
|
||||||
options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
|
|
||||||
|
|
||||||
console.log("finally selected defaultkey="+defaultkey+" defaultprice="+defaultprice);
|
|
||||||
|
|
||||||
$("#fournprice_predef").html(options).show();
|
|
||||||
if (defaultkey != '')
|
|
||||||
{
|
|
||||||
$("#fournprice_predef").val(defaultkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* At loading, no product are yet selected, so we hide field of buying_price */
|
|
||||||
$("#buying_price").hide();
|
|
||||||
|
|
||||||
/* Define default price at loading */
|
|
||||||
var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
|
|
||||||
$("#buying_price").val(defaultprice);
|
|
||||||
|
|
||||||
$("#fournprice_predef").change(function() {
|
|
||||||
console.log("change on fournprice_predef");
|
|
||||||
/* Hide field buying_price according to choice into list (if 'inputprice' or not) */
|
|
||||||
var linevalue=$(this).find('option:selected').val();
|
|
||||||
var pricevalue = $(this).find('option:selected').attr("price");
|
|
||||||
if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
|
|
||||||
$("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
|
|
||||||
}
|
|
||||||
if (linevalue == 'inputprice') {
|
|
||||||
$('#buying_price').show();
|
|
||||||
}
|
|
||||||
if (linevalue == 'pmpprice') {
|
|
||||||
$("#buying_price").val(pricevalue);
|
|
||||||
$('#buying_price').hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'json');
|
|
||||||
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|
||||||
/* To process customer price per quantity */
|
|
||||||
var pbq = parseInt($('option:selected', this).attr('data-pbq'));
|
|
||||||
var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
|
|
||||||
var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
|
|
||||||
|
|
||||||
if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && typeof pbq !== "undefined")
|
|
||||||
{
|
|
||||||
console.log("We choose a price by quanty price_by_qty id = "+pbq+" price_by_qty qty = "+pbqqty+" price_by_qty percent = "+pbqpercent);
|
|
||||||
jQuery("#pbq").val(pbq);
|
|
||||||
if (jQuery("#qty").val() < pbqqty)
|
|
||||||
{
|
|
||||||
jQuery("#qty").val(pbqqty);
|
|
||||||
}
|
|
||||||
if (jQuery("#remise_percent").val() < pbqpercent)
|
|
||||||
{
|
|
||||||
jQuery("#remise_percent").val(pbqpercent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
jQuery("#pbq").val('');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To set focus */
|
|
||||||
if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
|
|
||||||
{
|
|
||||||
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */
|
|
||||||
jQuery('#dp_desc').focus();
|
|
||||||
/* focus if CKEDITOR */
|
|
||||||
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
|
|
||||||
{
|
|
||||||
var editor = CKEDITOR.instances['dp_desc'];
|
|
||||||
if (editor) { editor.focus(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
<?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef ?>
|
|
||||||
setforpredef();
|
|
||||||
<?php } ?>
|
|
||||||
});
|
|
||||||
|
|
||||||
/* Function to set fields from choice */
|
|
||||||
function setforfree() {
|
|
||||||
console.log("Call setforfree. We show most fields");
|
|
||||||
jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
|
|
||||||
jQuery("#prod_entry_mode_free").prop('checked',true).change();
|
|
||||||
jQuery("#prod_entry_mode_predef").prop('checked',false).change();
|
|
||||||
jQuery("#search_idprod, #idprod, #search_idprodfournprice, #buying_price").val('');
|
|
||||||
jQuery("#price_ht, #multicurrency_price_ht, #price_ttc, #price_ttc, #fourn_ref, #tva_tx, #buying_price, #title_vat, #title_up_ht, #title_up_ht_currency, #title_up_ttc, #title_up_ttc_currency").show();
|
|
||||||
jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show();
|
|
||||||
jQuery("#fournprice_predef").hide();
|
|
||||||
}
|
}
|
||||||
function setforpredef() {
|
else
|
||||||
console.log("Call setforpredef. We hide some fields and show dates");
|
{
|
||||||
jQuery("#select_type").val(-1);
|
jQuery("#pbq").val('');
|
||||||
jQuery("#prod_entry_mode_free").prop('checked',false).change();
|
|
||||||
jQuery("#prod_entry_mode_predef").prop('checked',true).change();
|
|
||||||
<?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT)) { ?>
|
|
||||||
jQuery("#price_ht").val('').show();
|
|
||||||
jQuery("#multicurrency_price_ht").val('').show();
|
|
||||||
<?php } else { ?>
|
|
||||||
jQuery("#price_ht").val('').hide();
|
|
||||||
jQuery("#multicurrency_price_ht").val('').hide();
|
|
||||||
<?php } ?>
|
|
||||||
jQuery("#price_ht").val('');
|
|
||||||
jQuery("#price_ttc, #fourn_ref, #tva_tx, #title_vat, #title_up_ht_currency, #title_up_ttc, #title_up_ttc_currency").hide();
|
|
||||||
jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").hide();
|
|
||||||
jQuery("#buying_price").show();
|
|
||||||
jQuery('#trlinefordates, .divlinefordates').show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
/* To set focus */
|
||||||
|
if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
|
||||||
|
{
|
||||||
|
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */
|
||||||
|
jQuery('#dp_desc').focus();
|
||||||
|
/* focus if CKEDITOR */
|
||||||
|
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
|
||||||
|
{
|
||||||
|
var editor = CKEDITOR.instances['dp_desc'];
|
||||||
|
if (editor) { editor.focus(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
<?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef ?>
|
||||||
|
setforpredef();
|
||||||
|
<?php } ?>
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Function to set fields from choice */
|
||||||
|
function setforfree() {
|
||||||
|
console.log("Call setforfree. We show most fields");
|
||||||
|
jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
|
||||||
|
jQuery("#prod_entry_mode_free").prop('checked',true).change();
|
||||||
|
jQuery("#prod_entry_mode_predef").prop('checked',false).change();
|
||||||
|
jQuery("#search_idprod, #idprod, #search_idprodfournprice, #buying_price").val('');
|
||||||
|
jQuery("#price_ht, #multicurrency_price_ht, #price_ttc, #price_ttc, #fourn_ref, #tva_tx, #buying_price, #title_vat, #title_up_ht, #title_up_ht_currency, #title_up_ttc, #title_up_ttc_currency").show();
|
||||||
|
jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show();
|
||||||
|
jQuery("#fournprice_predef").hide();
|
||||||
|
}
|
||||||
|
function setforpredef() {
|
||||||
|
console.log("Call setforpredef. We hide some fields and show dates");
|
||||||
|
jQuery("#select_type").val(-1);
|
||||||
|
jQuery("#prod_entry_mode_free").prop('checked',false).change();
|
||||||
|
jQuery("#prod_entry_mode_predef").prop('checked',true).change();
|
||||||
|
<?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT)) { ?>
|
||||||
|
jQuery("#price_ht").val('').show();
|
||||||
|
jQuery("#multicurrency_price_ht").val('').show();
|
||||||
|
<?php } else { ?>
|
||||||
|
jQuery("#price_ht").val('').hide();
|
||||||
|
jQuery("#multicurrency_price_ht").val('').hide();
|
||||||
|
<?php } ?>
|
||||||
|
jQuery("#price_ht").val('');
|
||||||
|
jQuery("#price_ttc, #fourn_ref, #tva_tx, #title_vat, #title_up_ht_currency, #title_up_ttc, #title_up_ttc_currency").hide();
|
||||||
|
jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").hide();
|
||||||
|
jQuery("#buying_price").show();
|
||||||
|
jQuery('#trlinefordates, .divlinefordates').show();
|
||||||
|
}
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
print '</script>';
|
||||||
|
|
||||||
print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n";
|
print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user