From e672783adba4afa3d598bd267a0f113ef0ec1df3 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 22 Aug 2013 11:39:55 +0200 Subject: [PATCH 1/9] add ability to modify margin rate on line edit if authorized --- htdocs/core/tpl/objectline_edit.tpl.php | 117 ++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 6 deletions(-) diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 328964bc0df..a7a744be7ee 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -28,7 +28,7 @@ ?> -
id; ?>" method="POST"> +id; ?>" method="POST"> @@ -133,11 +133,25 @@ if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { margin->enabled)) { ?> - - - - - + + + + + rights->margins->creer) { + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + { + $margin_rate = (isset($_POST["marginRate"])?$_POST["marginRate"]:(($line->pa_ht == 0)?'':price($line->marge_tx))); + echo '%'; + $coldisplay++; + } + if (! empty($conf->global->DISPLAY_MARK_RATES)) + { + $mark_rate = (isset($_POST["markRate"])?$_POST["markRate"]:price($line->marque_tx)); + echo '%'; + $coldisplay++; + } + } + } ?> ">
@@ -386,5 +400,96 @@ $(document).ready(function() { }, 'json'); }); + var npRate = null; +global->DISPLAY_MARGIN_RATES)) { ?> + npRate = "marginRate"; + global->DISPLAY_MARK_RATES)) { ?> + npRate = "markRate"; + + +$("form#editproduct").submit(function(e) { + if (npRate) return checkEditLine(e, npRate); + else return true; +}); +if (npRate == 'marginRate') { + $("input[name='marginRate']:first").blur(function(e) { + return checkEditLine(e, npRate); + }); +} +else { + if (npRate == 'markRate') { + $("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('trans("rateMustBeNumeric"); ?>'); + e.stopPropagation(); + setTimeout(function () { rate.focus() }, 50); + return false; + } + if (npRate == "markRate" && rate.val() >= 100) + { + alert('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(formatFloat(price)); + + return true; +} +function roundFloat(num) { + var main_max_dec_shown = global->MAIN_MAX_DECIMALS_SHOWN; ?>; + var main_rounding = global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>; + + var amount = num.toString().replace(',','.'); // should be useless + var nbdec = 0; + var rounding = main_rounding; + var pos = amount.indexOf('.'); + var decpart = ''; + if (pos >= 0) + decpart = amount.substr(pos+1).replace('/0+$/i',''); // Supprime les 0 de fin de partie decimale + nbdec = decpart.length; + if (nbdec > rounding) + rounding = nbdec; + // Si on depasse max + if (rounding > main_max_dec_shown) + { + rounding = main_max_dec_shown; + } + //amount = parseFloat(amount) + (1 / Math.pow(100, rounding)); // to avoid floating-point errors + return parseFloat(amount).toFixed(rounding); +} + +function formatFloat(num) { + return roundFloat(num).replace('.', ','); +} + From f37c24f8ff74a5bccb86955c0acc19ea631219de Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 22 Aug 2013 11:45:27 +0200 Subject: [PATCH 2/9] allow to modify margin rate or mark rate but not both --- htdocs/core/tpl/objectline_edit.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index a7a744be7ee..ac05f71b901 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -144,7 +144,7 @@ if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { echo '%'; $coldisplay++; } - if (! empty($conf->global->DISPLAY_MARK_RATES)) + elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { $mark_rate = (isset($_POST["markRate"])?$_POST["markRate"]:price($line->marque_tx)); echo '%'; From 4df216afbce9450e561ae7d7a38712a50b2cd5a3 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 22 Aug 2013 12:13:14 +0200 Subject: [PATCH 3/9] add ability to define margin when adding line with new experimental form --- htdocs/core/tpl/objectline_add.tpl.php | 186 ++++++++++++++++++++----- 1 file changed, 149 insertions(+), 37 deletions(-) diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php index 5f4c83a1a71..6e1c3c687f9 100644 --- a/htdocs/core/tpl/objectline_add.tpl.php +++ b/htdocs/core/tpl/objectline_add.tpl.php @@ -41,17 +41,31 @@ if (! empty($conf->margin->enabled)) { ?> trans('BuyingPrice'); ?> global->DISPLAY_MARGIN_RATES)) { - $colspan++; - $colspan2++; - } - if (! empty($conf->global->DISPLAY_MARK_RATES)) { - $colspan++; - $colspan2++; - } - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { - $colspan2++; - } + if ($user->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++; + $colspan2++; + } + if (! empty($conf->global->DISPLAY_MARK_RATES)) { + $colspan++; + $colspan2++; + } + } + if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { + $colspan2++; + } } ?>   @@ -164,21 +178,35 @@ if (! empty($conf->margin->enabled)) { % -margin->enabled)) { -?> - - - - -global->DISPLAY_MARGIN_RATES)) - $colspan++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) - $colspan++; -} -?> + margin->enabled)) { + ?> + + + + + rights->margins->creer) + { + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { + echo '%'; + } + elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { + echo '%'; + } + } + else + { + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { + $colspan++; + } + if (! empty($conf->global->DISPLAY_MARK_RATES)) { + $colspan++; + } + } + } + ?> @@ -188,12 +216,7 @@ if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 12; else $colspan = 11; -if (! empty($conf->margin->enabled)) { - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) - $colspan++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) - $colspan++; -} + ?> > @@ -491,11 +514,7 @@ $(document).ready(function() { }); -}); - - margin->enabled)) { ?> - + var npRate = null; +global->DISPLAY_MARGIN_RATES)) { ?> + npRate = "np_marginRate"; + global->DISPLAY_MARK_RATES)) { ?> + npRate = "np_markRate"; + + +$("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); + }); +} +else { + if (npRate == 'np_markRate') { + $("input[name='np_markRate']:first").blur(function(e) { + return checkFreeLine(e, npRate); + }); + } +} + +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('trans("rateMustBeNumeric"); ?>'); + e.stopPropagation(); + setTimeout(function () { rate.focus() }, 50); + return false; + } + if (npRate == "np_markRate" && rate.val() >= 100) + { + alert('trans("markRateShouldBeLesserThan100"); ?>'); + e.stopPropagation(); + setTimeout(function () { rate.focus() }, 50); + return false; + } + + var np_price = 0; + if (remise.val().replace(',','.') != 100) + { + if (npRate == "np_marginRate") + np_price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100)); + else { + if (npRate == "np_markRate") + 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)); + update_price('price_ht', 'price_ttc'); + + return true; +} +function roundFloat(num) { + var main_max_dec_shown = global->MAIN_MAX_DECIMALS_SHOWN; ?>; + var main_rounding = global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>; + + var amount = num.toString().replace(',','.'); // should be useless + var nbdec = 0; + var rounding = main_rounding; + var pos = amount.indexOf('.'); + var decpart = ''; + if (pos >= 0) + decpart = amount.substr(pos+1).replace('/0+$/i',''); // Supprime les 0 de fin de partie decimale + nbdec = decpart.length; + if (nbdec > rounding) + rounding = nbdec; + // Si on depasse max + if (rounding > main_max_dec_shown) + { + rounding = main_max_dec_shown; + } + //amount = parseFloat(amount) + (1 / Math.pow(100, rounding)); // to avoid floating-point errors + return parseFloat(amount).toFixed(rounding); +} + +function formatFloat(num) { + return roundFloat(num).replace('.', ','); +} +}); + + From aeb072b1eb95e8fb3d50d36c022dd39990beafa7 Mon Sep 17 00:00:00 2001 From: Florian Henry Date: Thu, 22 Aug 2013 15:11:11 +0200 Subject: [PATCH 4/9] Fix: Link "Show all supplier invoice" on suplier card not working --- ChangeLog | 1 + htdocs/fourn/fiche.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b8aa6195d61..bd9ef6e6699 100644 --- a/ChangeLog +++ b/ChangeLog @@ -108,6 +108,7 @@ Fix: update extrafield do not display immediatly after update Fix: Fix bug with canvas thirdparty Fix: [ bug #1037 ] Consumption> Supplier invoices related Fix: User group name do not display in card (view or edit mode) +Fix: Link "Show all supplier invoice" on suplier card not working ***** ChangeLog for 3.4 compared to 3.3.* ***** diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php index c1bb8ede5a2..f813d720569 100644 --- a/htdocs/fourn/fiche.php +++ b/htdocs/fourn/fiche.php @@ -396,7 +396,7 @@ if ($object->fetch($id)) print ''; print ''; - print ''; + print '
'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans('AllBills').' ('.$num.')
'; print ''; print '
'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans('AllBills').' ('.$num.')'.img_picto($langs->trans("Statistics"),'stats').'
'; print ''; From 26b8f29682d4b1bc5f2ba0dde79ca416329a72df Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 22 Aug 2013 10:45:42 +0200 Subject: [PATCH 5/9] fix display of buying price on line edit when no supplier price is defined --- htdocs/fourn/ajax/getSupplierPrices.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/ajax/getSupplierPrices.php b/htdocs/fourn/ajax/getSupplierPrices.php index 029f135a653..b19ddb2996f 100644 --- a/htdocs/fourn/ajax/getSupplierPrices.php +++ b/htdocs/fourn/ajax/getSupplierPrices.php @@ -114,8 +114,8 @@ if (! empty($idprod)) $db->free($result); } } - - echo json_encode($prices); } +echo json_encode($prices); + ?> From 10ced7431e69f44d5f683dadea2f77087cc5fc0c Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 22 Aug 2013 10:49:13 +0200 Subject: [PATCH 6/9] update changelog --- ChangeLog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index bd9ef6e6699..8108bc76e39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -101,6 +101,9 @@ parameter. All methods addline in this case were modified to remove this paramet ***** ChangeLog for 3.4.1 compared to 3.4.0 ***** +Fix: Display buying price on line edit when no supplier price is defined +Fix: Retrieving of margin info when invoice created automatically from order +Fix: Reordering supplier products in list by supplier or supplier ref was crashing Fix: [ bug #1029 ] Tulip numbering mask Fix: Supplier invoice and supplier order are not displayed into object link into agenda event card Fix: [ bug #1033 ] SUPPLIER REF disappeared From 0c249c212767737776a21eb7df7e560656f696d6 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Fri, 23 Aug 2013 10:46:53 +0200 Subject: [PATCH 7/9] Update export.class.php bug fix --- htdocs/exports/class/export.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index a5a4abcd440..fb16e5cbadf 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -755,7 +755,7 @@ class Export global $conf, $langs; $sql = "SELECT em.rowid, em.field, em.label, em.type, em.filter"; - $sql.= " FROM ".MAIN_DB_PREFIX."export_model"; + $sql.= " FROM ".MAIN_DB_PREFIX."export_model as em"; $sql.= " ORDER BY rowid"; $result = $this->db->query($sql); From 24b28d65e464b2be533cbdecd0650f58930424c2 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Fri, 23 Aug 2013 10:57:29 +0200 Subject: [PATCH 8/9] fix margin reports bugs (wrong group by + jquery syntax error) Conflicts: htdocs/margin/customerMargins.php htdocs/margin/productMargins.php --- htdocs/margin/agentMargins.php | 2 +- htdocs/margin/customerMargins.php | 4 ++-- htdocs/margin/productMargins.php | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index bb12125a345..459537e1506 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -160,7 +160,7 @@ if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPr if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname, f.type"; else - $sql.= " GROUP BY u.rowid, s.nom, s.rowid, s.code_client, s.client, u.login, u.lastname, u.firstname, f.type "; + $sql.= " GROUP BY u.rowid"; $sql.= " ORDER BY $sortfield $sortorder "; // TODO: calculate total to display then restore pagination //$sql.= $db->plimit($conf->liste_limit +1, $offset); diff --git a/htdocs/margin/customerMargins.php b/htdocs/margin/customerMargins.php index 67bf8cef506..484f86ad9e0 100644 --- a/htdocs/margin/customerMargins.php +++ b/htdocs/margin/customerMargins.php @@ -178,7 +178,7 @@ if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPr if ($client) $sql.= " GROUP BY f.rowid, s.rowid, s.nom, s.code_client, s.client, f.facnumber, f.total, f.datef, f.paye, f.fk_statut, f.type "; else - $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.facnumber, f.total, f.datef, f.paye, f.fk_statut, f.rowid, f.type "; + $sql.= " GROUP BY s.rowid"; $sql.= " ORDER BY $sortfield $sortorder "; // TODO: calculate total to display then restore pagination //$sql.= $db->plimit($conf->liste_limit +1, $offset); @@ -293,7 +293,7 @@ $db->close();