From 55d01a015ccf74213b5fedb514d700b3df0dc79d Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 4 Jul 2018 14:47:15 +0200 Subject: [PATCH 01/16] Issue 411: Pricing Formulas - Add/edit/delete formulas in admin --- resources/admin.php | 1 + .../admin/classes/domain/PricingFormula.php | 50 ++++++++++++ .../getAdminPricingFormulaUpdateForm.php | 26 ++++++ .../ajax_htmldata/getAdminPricingFormulas.php | 39 +++++++++ .../ajax_processing/deletePricingFormula.php | 14 ++++ .../ajax_processing/updatePricingFormula.php | 16 ++++ resources/install/protected/3.0.0/005-411.sql | 18 +++++ resources/js/admin.js | 79 +++++++++++++++++++ 8 files changed, 243 insertions(+) create mode 100644 resources/admin/classes/domain/PricingFormula.php create mode 100644 resources/ajax_forms/getAdminPricingFormulaUpdateForm.php create mode 100644 resources/ajax_htmldata/getAdminPricingFormulas.php create mode 100644 resources/ajax_processing/deletePricingFormula.php create mode 100644 resources/ajax_processing/updatePricingFormula.php create mode 100644 resources/install/protected/3.0.0/005-411.sql diff --git a/resources/admin.php b/resources/admin.php index 1da3cc38d..b72499cdb 100644 --- a/resources/admin.php +++ b/resources/admin.php @@ -87,6 +87,7 @@ + diff --git a/resources/admin/classes/domain/PricingFormula.php b/resources/admin/classes/domain/PricingFormula.php new file mode 100644 index 000000000..d21654ee0 --- /dev/null +++ b/resources/admin/classes/domain/PricingFormula.php @@ -0,0 +1,50 @@ +. +** +************************************************************************************************************************** +*/ + +class PricingFormula extends DatabaseObject { + + protected function defineRelationships() {} + + public function allAsArray() { + $query = "SELECT * FROM PricingFormula ORDER BY 1"; + $result = $this->db->processQuery($query, 'assoc'); + + $resultArray = array(); + $rowArray = array(); + + if (isset($result['pricingFormulaID'])){ + foreach (array_keys($result) as $attributeName) { + $rowArray[$attributeName] = $result[$attributeName]; + } + array_push($resultArray, $rowArray); + }else{ + foreach ($result as $row) { + foreach (array_keys($this->attributeNames) as $attributeName) { + $rowArray[$attributeName] = $row[$attributeName]; + } + array_push($resultArray, $rowArray); + } + } + + return $resultArray; + } + +} + +?> diff --git a/resources/ajax_forms/getAdminPricingFormulaUpdateForm.php b/resources/ajax_forms/getAdminPricingFormulaUpdateForm.php new file mode 100644 index 000000000..7e29ef74c --- /dev/null +++ b/resources/ajax_forms/getAdminPricingFormulaUpdateForm.php @@ -0,0 +1,26 @@ + $pricingFormulaID))); + } else { + $instance = new PricingFormula(); + } +?> +
+
+ +
+Field $i:
"); +} + +?> + + + +
diff --git a/resources/ajax_htmldata/getAdminPricingFormulas.php b/resources/ajax_htmldata/getAdminPricingFormulas.php new file mode 100644 index 000000000..cfdffb4f5 --- /dev/null +++ b/resources/ajax_htmldata/getAdminPricingFormulas.php @@ -0,0 +1,39 @@ +allAsArray(); + + echo "
"._("Pricing formulas")."
"; + + if (count($instanceArray) > 0){ + ?> + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + } + + ?> +
  
" . $instance['shortName'] . ""._("edit").""._("remove")."
+ "._("add new formula")."
"; + +?> + diff --git a/resources/ajax_processing/deletePricingFormula.php b/resources/ajax_processing/deletePricingFormula.php new file mode 100644 index 000000000..d7337169d --- /dev/null +++ b/resources/ajax_processing/deletePricingFormula.php @@ -0,0 +1,14 @@ + $deleteID))); + + try { + $instance->delete(); + } catch (Exception $e) { + //print out a friendly message... + echo _("Unable to delete. Please make sure no resources are set up with this information."); + } + +?> diff --git a/resources/ajax_processing/updatePricingFormula.php b/resources/ajax_processing/updatePricingFormula.php new file mode 100644 index 000000000..f97d5259d --- /dev/null +++ b/resources/ajax_processing/updatePricingFormula.php @@ -0,0 +1,16 @@ + $_POST['pricingFormulaID']))); +} else { + $instance = new PricingFormula(); +} + +$instance->shortName = $_POST['formulaName']; +for ($i = 1; $i <= 10; $i++) { + $memberName = "field${i}Name"; + $instance->$memberName = $_POST[$memberName] ? $_POST[$memberName] : null; +} +$instance->formula = $_POST['formula']; +$instance->save(); + +?> diff --git a/resources/install/protected/3.0.0/005-411.sql b/resources/install/protected/3.0.0/005-411.sql new file mode 100644 index 000000000..a9f0cacf0 --- /dev/null +++ b/resources/install/protected/3.0.0/005-411.sql @@ -0,0 +1,18 @@ +CREATE TABLE `PricingFormula` ( + `pricingFormulaID` int(11) NOT NULL, + `shortName` varchar(200) default NULL, + `field1Name` varchar(200) default NULL, + `field2Name` varchar(200) default NULL, + `field3Name` varchar(200) default NULL, + `field4Name` varchar(200) default NULL, + `field5Name` varchar(200) default NULL, + `field6Name` varchar(200) default NULL, + `field7Name` varchar(200) default NULL, + `field8Name` varchar(200) default NULL, + `field9Name` varchar(200) default NULL, + `field10Name` varchar(200) default NULL, + `formula` TEXT default NULL +); + +ALTER TABLE `PricingFormula` CHANGE pricingFormulaID pricingFormulaID INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY; + diff --git a/resources/js/admin.js b/resources/js/admin.js index ac4df66c6..352b4ca7d 100644 --- a/resources/js/admin.js +++ b/resources/js/admin.js @@ -53,6 +53,11 @@ $(document).ready(function(){ updateImportConfigTable(); }); + $(".PricingFormulaLink").click(function () { + updatePricingFormulaTable(); + }); + + $(".EbscoKbConfigLink").click(function () { updateEbscoKbConfigTable(); }); @@ -62,6 +67,12 @@ $(document).ready(function(){ submitEbscoKbData(); }); + $("#pricingFormulaConfig").live('submit', function(e){ + e.preventDefault(); + submitPricingFormula(); + }); + + $('.removeData').live('click', function () { deleteData($(this).attr("cn"), $(this).attr("id")); }); @@ -78,6 +89,7 @@ function removeSelectedClassFromNav(){ $(".ImportConfigLink").parent().parent().removeClass('selected'); $(".SubjectsAdminLink").parent().parent().removeClass('selected'); $(".EbscoKbConfigLink").parent().parent().removeClass('selected'); + $(".PricingFormulaLink").parent().parent().removeClass('selected'); } @@ -188,6 +200,27 @@ function updateUserTable(){ } +function updatePricingFormulaTable(){ + removeSelectedClassFromNav(); + $(".PricingFormulaLink").parent().parent().addClass('selected'); + + $.ajax({ + type: "GET", + url: "ajax_htmldata.php", + cache: false, + data: "action=getAdminPricingFormulas", + success: function(html) { + $('#div_AdminContent').html(html); + tb_reinit(); + } + }); + + //make sure error is empty + $('#div_error').html(""); + +} + + function updateAlertTable(){ @@ -530,6 +563,24 @@ function submitEbscoKbData(){ }); } +// Validate fund form +function submitPricingFormula(){ + var form = $('#pricingFormulaConfig'); + $.ajax({ + type: "POST", + url: "ajax_processing.php?action=updatePricingFormula&formulaPricingID=" + $("#formulaPricingID").val(), + cache: false, + data: form.serialize(), + success: function(e) { + updatePricingFormulaTable(); + window.parent.tb_remove(); + }, + error: function(xhr) { + $('#pricingFormulaConfigError').html(xhr.responseText); + } + }); +} + function deleteData(className, deleteID){ @@ -558,6 +609,34 @@ function deleteData(className, deleteID){ } } +function deletePricingFormula(deleteID){ + + if (confirm(_("Do you really want to remove this pricing formula?")) == true) { + + $.ajax({ + type: "GET", + url: "ajax_processing.php", + cache: false, + data: "action=deletePricingFormula&id=" + deleteID, + success: function(html) { + + if (html){ + showError(html); + + // close the div in 3 secs + setTimeout("emptyError();",3000); + }else{ + updatePricingFormulaTable(); + tb_reinit(); + } + + } + }); + + } +} + + function deleteGeneralSubject(className, deleteID){ if (confirm(_("Do you really want to remove this data?")) == true) { From 41d8707df4b75733373f7f7cd37b7492de28d1af Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Thu, 12 Jul 2018 15:24:51 +0200 Subject: [PATCH 02/16] Issue 411: Pricing Formulas - Use formulas in costs --- .../admin/classes/domain/PricingFormula.php | 10 +++ resources/ajax_forms/getCostForm.php | 56 ++++++++++-- .../ajax_forms/getPricingFormulaForm.php | 24 +++++ .../getPaymentFromPricingFormula.php | 23 +++++ resources/ajax_processing/submitCost.php | 10 +++ resources/install/protected/3.0.0/005-411.sql | 12 +++ resources/js/forms/costForm.js | 87 +++++++++++++++++-- 7 files changed, 209 insertions(+), 13 deletions(-) create mode 100644 resources/ajax_forms/getPricingFormulaForm.php create mode 100644 resources/ajax_processing/getPaymentFromPricingFormula.php diff --git a/resources/admin/classes/domain/PricingFormula.php b/resources/admin/classes/domain/PricingFormula.php index d21654ee0..fa07da3c1 100644 --- a/resources/admin/classes/domain/PricingFormula.php +++ b/resources/admin/classes/domain/PricingFormula.php @@ -45,6 +45,16 @@ public function allAsArray() { return $resultArray; } + public function getFieldValues() { + $fieldValues = array(); + for ($i = 1; $i <= 10; $i++) { + $memberName = "field${i}Name"; + if ($this->$memberName) + $fieldValues[$memberName] = $this->$memberName; + } + return $fieldValues; + } + } ?> diff --git a/resources/ajax_forms/getCostForm.php b/resources/ajax_forms/getCostForm.php index d837b0bac..af541d030 100644 --- a/resources/ajax_forms/getCostForm.php +++ b/resources/ajax_forms/getCostForm.php @@ -25,6 +25,10 @@ $costDetailsObj = new CostDetails(); $costDetailsArray = $costDetailsObj->allAsArray(); +// get all pricing formulas +$formulaObj = new PricingFormula(); +$formulaArray = $formulaObj->allAsArray(); + //get payments $sanitizedInstance = array(); $instance = new ResourcePayment(); @@ -41,7 +45,7 @@ // Table geometry is different if enhanced cost history is enabled $baseWidth = 345; -$numCols = 6; +$numCols = 7; if ($enhancedCostFlag){ $baseWidth += 688; $numCols += 8; // year, sub start, sub end, cost details, invoice num @@ -79,7 +83,8 @@ - + + @@ -132,6 +137,17 @@ + + + + + @@ -185,12 +201,10 @@ - + - - @@ -199,6 +213,11 @@
+ + +
test
+ +
@@ -208,7 +227,8 @@ if (count($paymentArray) > 0){ foreach ($paymentArray as $payment){ ?> - + + ' class='changeInput year costHistoryYear' /> @@ -261,6 +281,22 @@ ' style='width:60px;' class='changeInput priceTaxIncluded' /> + + + + + + ' class='changeInput paymentAmount costHistoryPayment' /> @@ -338,7 +374,12 @@
- + + +
+ + + @@ -361,7 +402,6 @@
- diff --git a/resources/ajax_forms/getPricingFormulaForm.php b/resources/ajax_forms/getPricingFormulaForm.php new file mode 100644 index 000000000..8621f4239 --- /dev/null +++ b/resources/ajax_forms/getPricingFormulaForm.php @@ -0,0 +1,24 @@ + $pricingFormulaID))); + if ($resourcePaymentID) { + $rp = new ResourcePayment(new NamedArguments(array('primaryKey' => $resourcePaymentID))); + } +?> +

Formula: formula; ?>

+ +$memberName) { + echo (": $memberValue) + echo (" value='" . $rp->$memberValue . "'"); + echo ('/>
'); + } +} +?> + diff --git a/resources/ajax_processing/getPaymentFromPricingFormula.php b/resources/ajax_processing/getPaymentFromPricingFormula.php new file mode 100644 index 000000000..26501e26e --- /dev/null +++ b/resources/ajax_processing/getPaymentFromPricingFormula.php @@ -0,0 +1,23 @@ + $formulaID))); + #$ra = new ResourceAcquisition(new NamedArguments(array('primaryKey' => $resourceAcquisitionID))); + $formula = $pf->formula; + for ($i = 1; $i <= 10; $i++) { + $name = "field${i}Name"; + if (isset($_GET[$name])) + $formulaValues[$name] = $_GET[$name]; + } + $fieldValues = $pf->getFieldValues(); + foreach ($fieldValues as $dbName => $formulaElementName) { + //echo "replacing $formulaElementName with " . $formulaValues[$dbName] . "\n"; + $formula = str_replace($formulaElementName, $formulaValues[$dbName], $formula); + #$raDbName = str_replace("Name", "Value", $dbName); + #$ra->$raDbName = $formulaValues[$dbName]; + //echo $formula . "\n"; + } + #$ra->save(); + echo eval("return $formula;"); +?> diff --git a/resources/ajax_processing/submitCost.php b/resources/ajax_processing/submitCost.php index ddb9c2e1f..d6d4219dd 100644 --- a/resources/ajax_processing/submitCost.php +++ b/resources/ajax_processing/submitCost.php @@ -22,6 +22,8 @@ $costDetailsArray = array(); $costDetailsArray = explode(':::',$_POST['costDetails']); $costNoteArray = array(); $costNoteArray = explode(':::',$_POST['costNotes']); $invoiceArray = array(); $invoiceArray = explode(':::',$_POST['invoices']); + $formulaIDArray = array(); $formulaIDArray = explode(':::',$_POST['formulaIDS']); + $formulaArray = array(); $formulaArray = explode(':::',$_POST['formulas']); foreach ($orderTypeArray as $key => $value){ if (($value) && ($paymentAmountArray[$key] || $yearArray[$key] || $fundIDArray[$key] || $costNoteArray[$key])){ $resourcePayment = new ResourcePayment(); @@ -41,6 +43,14 @@ $resourcePayment->costDetailsID = $costDetailsArray[$key]; $resourcePayment->costNote = $costNoteArray[$key]; $resourcePayment->invoiceNum = $invoiceArray[$key]; + $resourcePayment->pricingFormulaID = $formulaIDArray[$key]; + $formulaValues = explode(':', $formulaArray[$key]); + $i = 1; + foreach ($formulaValues as $formulaValue) { + $memberName = "field${i}Value"; + $resourcePayment->$memberName = $formulaValue; + $i++; + } try { $resourcePayment->save(); } catch (Exception $e) { diff --git a/resources/install/protected/3.0.0/005-411.sql b/resources/install/protected/3.0.0/005-411.sql index a9f0cacf0..eb6ff3e89 100644 --- a/resources/install/protected/3.0.0/005-411.sql +++ b/resources/install/protected/3.0.0/005-411.sql @@ -16,3 +16,15 @@ CREATE TABLE `PricingFormula` ( ALTER TABLE `PricingFormula` CHANGE pricingFormulaID pricingFormulaID INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY; +ALTER TABLE `ResourcePayment` + ADD COLUMN `pricingFormulaID` varchar(200) default NULL, + ADD COLUMN `field1Value` varchar(200) default NULL, + ADD COLUMN `field2Value` varchar(200) default NULL, + ADD COLUMN `field3Value` varchar(200) default NULL, + ADD COLUMN `field4Value` varchar(200) default NULL, + ADD COLUMN `field5Value` varchar(200) default NULL, + ADD COLUMN `field6Value` varchar(200) default NULL, + ADD COLUMN `field7Value` varchar(200) default NULL, + ADD COLUMN `field8Value` varchar(200) default NULL, + ADD COLUMN `field9Value` varchar(200) default NULL, + ADD COLUMN `field10Value` varchar(200) default NULL; diff --git a/resources/js/forms/costForm.js b/resources/js/forms/costForm.js index d16877e69..b8103364c 100644 --- a/resources/js/forms/costForm.js +++ b/resources/js/forms/costForm.js @@ -24,6 +24,37 @@ $(function(){ submitCostForm(); }); + addShowFormula(); + + $(".paymentTR").each(function() { + var $this = $(this); + var formulaSelect = $this.find(".formulaSelect"); + var formulaID = $this.find("input[name='paymentPricingFormulaID']").val(); + var resourcePaymentID = $this.find("input[name='resourcePaymentID']").val(); + getFormulaForm(formulaID, resourcePaymentID, formulaSelect, true); + }); + + $(".formulaSelect").change(function() { + var formulaID = $(this).val(); + var resourcePaymentID = $(this).parent().find("input[name='resourcePaymentID']").val(); + getFormulaForm(formulaID, resourcePaymentID, $(this)); + }); + + $("#addFormulaButton").live('click', function(e){ + e.preventDefault(); + var values = $(e.currentTarget).parent().find("input[name^='field']").map(function() { return this.name + "=" + this.value }).get().join("&"); + $.ajax({ + type: "GET", + url: "ajax_processing.php", + cache: false, + data: "action=getPaymentFromPricingFormula&pricingFormulaID=" + $(this).parent().find(".formulaID").val() + "&" + values, + success: function(html) { + $(e.currentTarget).parent().parent().parent().prev('tr').prev('tr').find(".paymentAmount").val(html); + $(e.currentTarget).parent().parent().parent().hide(); + } + }); + + }); //the following are all to change the look of the inputs when they're clicked $('.changeDefault').live('focus', function(e) { @@ -111,7 +142,6 @@ $(function(){ }); $(".addPayment").click(function () { - var y = $('.newPaymentTable').find('.year').val(); var ssd = $('.newPaymentTable').find('.susbcriptionStartDate').val(); var sed = $('.newPaymentTable').find('.susbcriptionEndDate').val(); @@ -123,7 +153,6 @@ $(function(){ var detailsID = $('.newPaymentTable').find('.costDetailsID').val(); var pAmount = $('.newPaymentTable').find('.paymentAmount').val(); var cNote = $('.newPaymentTable').find('.costNote').val(); - if(validateTable($('.newPaymentTable tbody tr'))) { //we're going to strip out the $ of the payment amount @@ -144,7 +173,14 @@ $(function(){ replaceInputWithImage.replaceWith("" + _("remove this payment") + ""); duplicateTR.appendTo('.paymentTable'); - $('').appendTo('.paymentTable'); + $('').appendTo('.paymentTable'); + + var duplicateFormulaTR = $('.newFormulaTR').clone(); + + duplicateFormulaTR.removeClass('newFormulaTR'); //remove newPaymentTR class from duplicate + duplicateFormulaTR.addClass('formulaTR'); + duplicateFormulaTR.appendTo('.paymentTable'); + addShowFormula(); //reset the add line values $('.newPaymentTable').find('.year').val(''); @@ -159,6 +195,7 @@ $(function(){ $('.newPaymentTable').find('.costDetailsID').val(''); $('.newPaymentTable').find('.costNote').val(''); $('.newPaymentTable').find('.invoiceNum').val(''); + $('.newPaymentTable').find('.formulaSelect').val(''); var tableDiv=$('.paymentTableDiv')[0]; tableDiv.scrollTop=tableDiv.scrollHeight; return true; @@ -261,6 +298,22 @@ function submitCostForm() $(".paymentTable").find(".invoiceNum").each(function(id) { invoiceList += $(this).val() + ":::"; }); + + formulaIDList = ''; + $(".paymentTable").find(".formulaSelect").each(function(id) { + formulaIDList += $(this).val() + ":::"; + }); + + formulaList = ''; + + $(".formulaTR").each(function() { + var $this = $(this); + var singleFormulaArray = new Array(); + $this.find("input[name^='field']").each(function() { + singleFormulaArray.push($(this).val()); + }); + formulaList += singleFormulaArray.join(':') + ":::"; + }); $('#submitCost').attr("disabled", "disabled"); $.ajax({ type: "POST", @@ -281,7 +334,9 @@ function submitCostForm() orderTypes: orderTypeList, costDetails: detailsList, costNotes: costNoteList, - invoices: invoiceList + invoices: invoiceList, + formulas: formulaList, + formulaIDS: formulaIDList }, success: function(html) { if (html){ @@ -311,7 +366,7 @@ function validateTable(objRows) $(objRows).find('.div_errorPayment').each(function() {$(this).html('');}); //clear existing errors //while(typeof objRows[currentRow] !== "undefined") - for (var currentRow = 0; currentRow < objRows.length; currentRow += 2) + for (var currentRow = 0; currentRow < objRows.length; currentRow += 3) { var y = $(objRows[currentRow]).find('.year').val(); var ssd = $(objRows[currentRow]).find('.subscriptionStartDate').val(); @@ -352,6 +407,28 @@ function validateTable(objRows) return hasNoErrors; } +function addShowFormula() { + $(".showFormula").unbind('click').click(function() { + $(this).parent().parent().next('tr').next('tr').toggle(); + }); +} + +function getFormulaForm(pricingFormulaID, resourcePaymentID, origin, hide = false) { + $.ajax({ + type: "GET", + url: "ajax_forms.php", + cache: false, + data: "action=getPricingFormulaForm&pricingFormulaID=" + pricingFormulaID + "&resourcePaymentID=" + resourcePaymentID, + success: function(html) { + origin.parent().parent().next('tr').next('tr').find(".formulaDiv").html(html); + origin.parent().parent().next('tr').next('tr').show(); + if (hide == true) { + origin.parent().parent().next('tr').next('tr').hide(); + } + } + }); +} + //kill all binds done by jquery live function kill() { From 2ccec2902f4070c4036bee162287c12ee0adecc0 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 18 Jul 2018 11:46:14 +0200 Subject: [PATCH 03/16] Issue 411: Pricing Formulas - Use cost_to_integer and integer_to_cost --- resources/ajax_forms/getPricingFormulaForm.php | 2 +- resources/ajax_processing/submitCost.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/ajax_forms/getPricingFormulaForm.php b/resources/ajax_forms/getPricingFormulaForm.php index 8621f4239..fed357d68 100644 --- a/resources/ajax_forms/getPricingFormulaForm.php +++ b/resources/ajax_forms/getPricingFormulaForm.php @@ -16,7 +16,7 @@ if ($instance->$memberName) { echo (": $memberValue) - echo (" value='" . $rp->$memberValue . "'"); + echo (" value='" . integer_to_cost($rp->$memberValue) . "'"); echo ('/>
'); } } diff --git a/resources/ajax_processing/submitCost.php b/resources/ajax_processing/submitCost.php index d6d4219dd..0fa73009a 100644 --- a/resources/ajax_processing/submitCost.php +++ b/resources/ajax_processing/submitCost.php @@ -48,7 +48,7 @@ $i = 1; foreach ($formulaValues as $formulaValue) { $memberName = "field${i}Value"; - $resourcePayment->$memberName = $formulaValue; + $resourcePayment->$memberName = cost_to_integer($formulaValue); $i++; } try { From 680c86dde7de35684af9bde36c9ccaf5ef678b3e Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 18 Jul 2018 11:51:15 +0200 Subject: [PATCH 04/16] Issue 411: Pricing Formulas - Fix line removal --- resources/js/forms/costForm.js | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/js/forms/costForm.js b/resources/js/forms/costForm.js index b8103364c..52918810f 100644 --- a/resources/js/forms/costForm.js +++ b/resources/js/forms/costForm.js @@ -116,6 +116,7 @@ $(function(){ $(".remove").live('click', function () { $(this).parent().parent().parent().fadeTo(400, 0, function () { $(this).next().remove(); //remove the error line first + $(this).next().remove(); //remove the formula line $(this).remove(); //then remove the row containing the data }); return false; From f0509726886a2a7a89e3a77818f26322803e7922 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 18 Jul 2018 15:49:01 +0200 Subject: [PATCH 05/16] Issue 411: Pricing Formulas - Improve UI, add translations --- .../getAdminPricingFormulaUpdateForm.php | 16 +++++++++++----- resources/ajax_forms/getCostForm.php | 6 +++--- resources/ajax_forms/getPricingFormulaForm.php | 8 +++++--- resources/css/style.css | 8 ++++++++ resources/js/forms/costForm.js | 5 +++-- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/resources/ajax_forms/getAdminPricingFormulaUpdateForm.php b/resources/ajax_forms/getAdminPricingFormulaUpdateForm.php index 7e29ef74c..084681492 100644 --- a/resources/ajax_forms/getAdminPricingFormulaUpdateForm.php +++ b/resources/ajax_forms/getAdminPricingFormulaUpdateForm.php @@ -11,16 +11,22 @@
-
+ +
+
+ + +Field $i:
"); + echo (""); } ?> - - - + + +

+ diff --git a/resources/ajax_forms/getCostForm.php b/resources/ajax_forms/getCostForm.php index af541d030..0b25903fc 100644 --- a/resources/ajax_forms/getCostForm.php +++ b/resources/ajax_forms/getCostForm.php @@ -137,7 +137,7 @@ - + ' style='width:60px;' class='changeInput priceTaxIncluded' /> - + + +$memberName) { - echo (": '); } } ?> +
:formula; ?>
:$memberValue) echo (" value='" . integer_to_cost($rp->$memberValue) . "'"); - echo ('/>
'); + echo ('/>
diff --git a/resources/css/style.css b/resources/css/style.css index b01cbcecd..08e5faa00 100755 --- a/resources/css/style.css +++ b/resources/css/style.css @@ -305,6 +305,10 @@ table.linedDataTable tr { vertical-align:top; } +#pricingFormulaConfig td { + height: 2em; +} + /*--- Prevent Table Cell from Being Too Long ---*/ #fund-short-name { @@ -2238,6 +2242,10 @@ a.smallLink { padding-left: 3px; } +.formulaSelectTD td { + white-space: nowrap; +} + .costHistoryYear { width: 30px; } diff --git a/resources/js/forms/costForm.js b/resources/js/forms/costForm.js index 52918810f..530f0ae85 100644 --- a/resources/js/forms/costForm.js +++ b/resources/js/forms/costForm.js @@ -154,7 +154,7 @@ $(function(){ var detailsID = $('.newPaymentTable').find('.costDetailsID').val(); var pAmount = $('.newPaymentTable').find('.paymentAmount').val(); var cNote = $('.newPaymentTable').find('.costNote').val(); - if(validateTable($('.newPaymentTable tbody tr'))) + if(validateTable($('.newPaymentTable > tbody > tr'))) { //we're going to strip out the $ of the payment amount pAmount = pAmount.replace('$',''); @@ -227,7 +227,7 @@ function submitCostForm() return; } } - if(validateTable($('.paymentTable tbody tr'))) + if(validateTable($('.paymentTable > tbody > tr'))) { purchaseSitesList =''; $(".paymentTable").find(".check_purchaseSite:checked").each(function(id) { @@ -363,6 +363,7 @@ function submitCostForm() function validateTable(objRows) { //var currentRow = 0; +console.log(objRows); var hasNoErrors = true; $(objRows).find('.div_errorPayment').each(function() {$(this).html('');}); //clear existing errors From 6b481530f56503ad673538269e8a25b1ef47a223 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 18 Jul 2018 17:03:22 +0200 Subject: [PATCH 06/16] Issue 411: Pricing Formulas - Prevent formulas with non-mathematical expressions from being executed --- .../getPaymentFromPricingFormula.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/resources/ajax_processing/getPaymentFromPricingFormula.php b/resources/ajax_processing/getPaymentFromPricingFormula.php index 26501e26e..1564cb43f 100644 --- a/resources/ajax_processing/getPaymentFromPricingFormula.php +++ b/resources/ajax_processing/getPaymentFromPricingFormula.php @@ -1,9 +1,7 @@ $formulaID))); - #$ra = new ResourceAcquisition(new NamedArguments(array('primaryKey' => $resourceAcquisitionID))); $formula = $pf->formula; for ($i = 1; $i <= 10; $i++) { $name = "field${i}Name"; @@ -12,12 +10,14 @@ } $fieldValues = $pf->getFieldValues(); foreach ($fieldValues as $dbName => $formulaElementName) { - //echo "replacing $formulaElementName with " . $formulaValues[$dbName] . "\n"; + if (!is_numeric($formulaValues[$dbName])) { + die(); + } $formula = str_replace($formulaElementName, $formulaValues[$dbName], $formula); - #$raDbName = str_replace("Name", "Value", $dbName); - #$ra->$raDbName = $formulaValues[$dbName]; - //echo $formula . "\n"; } - #$ra->save(); - echo eval("return $formula;"); + $formula = preg_replace('/\s+/', '', $formula); + $formulaAfterCheck = preg_replace('~[^0-9.()-+*/]~', '', $formula); + if (strcmp($formula, $formulaAfterCheck) == 0) { + echo eval("return $formulaAfterCheck;"); + } ?> From fc5dadd41f25e45439d2b206fdfa95c4556fcbe8 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Tue, 30 Oct 2018 16:35:50 +0100 Subject: [PATCH 07/16] Issue 411: Pricing Formulas - Display formula with values once saved --- resources/admin/classes/domain/ResourcePayment.php | 10 ++++++++++ resources/ajax_forms/getPricingFormulaForm.php | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/resources/admin/classes/domain/ResourcePayment.php b/resources/admin/classes/domain/ResourcePayment.php index b44a984be..2e35fc999 100644 --- a/resources/admin/classes/domain/ResourcePayment.php +++ b/resources/admin/classes/domain/ResourcePayment.php @@ -44,6 +44,16 @@ public function getPaymentAmountChangeFromPreviousYear(){ } return 'n/a'; } + + public function getFormulaValues() { + $fieldValues = array(); + for ($i = 1; $i <= 10; $i++) { + $memberName = "field${i}Value"; + if ($this->$memberName) + $fieldValues['field' . $i . 'Name'] = $this->$memberName; + } + return $fieldValues; + } } ?> diff --git a/resources/ajax_forms/getPricingFormulaForm.php b/resources/ajax_forms/getPricingFormulaForm.php index cec65af64..df353fdb1 100644 --- a/resources/ajax_forms/getPricingFormulaForm.php +++ b/resources/ajax_forms/getPricingFormulaForm.php @@ -11,6 +11,18 @@ pricingFormulaID) { + $fieldValues = $instance->getFieldValues(); + $formulaValues = $rp->getFormulaValues(); + $formula = $instance->formula; + foreach ($fieldValues as $dbName => $formulaElementName) { + if (!is_numeric($formulaValues[$dbName])) { + next(); + } + $formula = str_replace($formulaElementName, integer_to_cost($formulaValues[$dbName]), $formula); + } + echo ""; +} for ($i = 1; $i <= 10; $i++) { $memberName = "field${i}Name"; $memberValue = "field${i}Value"; From c7721e0bbf48761bc6a16f8d571664efd7f6e0f6 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Tue, 27 Nov 2018 16:29:12 +0100 Subject: [PATCH 08/16] Issue 411: Pricing Formulas - Fix form width --- resources/ajax_htmldata/getAcquisitionsDetails.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/ajax_htmldata/getAcquisitionsDetails.php b/resources/ajax_htmldata/getAcquisitionsDetails.php index d935a194f..ea3dee25a 100644 --- a/resources/ajax_htmldata/getAcquisitionsDetails.php +++ b/resources/ajax_htmldata/getAcquisitionsDetails.php @@ -5,7 +5,7 @@ if ($enhancedCostFlag){ $numCols = 12; $tableWidth = 760; - $formWidth = 1084; + $formWidth = 1300; ?>
:formula; ?>
" . _("With values") . ":" . $formula . "