calculate vat
-
Hi,
Is it possible to do the following with the calculated fields form? See link.
Thanks!
The page I need help with: [log in to see the link]
-
Hello @sdevad,
Yes, the form you sent me as reference can be implemented with our plugin.
Best regards.
Hi @codepeople!
I have tried some different approaches. Can you please guide me a bit?
Hello @sdevad
It is only mathematics.
For example, si the value in the fieldname1 is the percentage, and the the fieldname2 is “Inklusive moms”
Using mathematics:
fieldname2 = x * (1+fieldname1/100)
so x = fieldname2/(1+fieldname1/100)So, the fieldname3 (Exklusive moms) would be the x and its equation :
fieldname2/(1+fieldname1/100)For the fieldname4 (Momssumma), you can simply substract the values:
fieldname2-fieldname3But what to do if all calculated fields are editable? evidently the equations are more complex, and you need identify the field that was edited:
– Insert a HTML Content field in the form with a piece of code similar to the following one as its content to identify the edited field:
<script> var field_edited = 0; jQuery(document).on('keydown', '[id*="fieldname2_"]', function(){field_edited = 2;}); jQuery(document).on('keydown', '[id*="fieldname3_"]', function(){field_edited = 3;}); jQuery(document).on('keydown', '[id*="fieldname4_"]', function(){field_edited = 4;}); </script>and now in the equations you should check the value of the field_edited variable to know mathematical operation to apply. For example, the equation associated to the fieldname3
(function(){ if(field_edited == 2) return fieldname2/(1+fieldname1/100); if(field_edited == 3) return __ME__; if(field_edited == 4) return fieldname4/(fieldname1/100); })()Pay attention to the use of the __ME__ constant, it represent the current value of the field. So, if the edited field is me, I return my value.
Now, you simply should implement the equations associated to the other two calculated fields based on the value of the global variable: field_edited
If you need additional help implementing your equations, I can offer you a custom coding service from my private website:
https://cff.dwbooster.com/customization
Best regards.
Hi @codepeople,
Can you please be more specific.
See questions below.
1. For the radio buttons (25%,12%,6%)
Should I use: Radiobuttons?
Settings: I don’t need to change anything here
2. For the inkl. moms
Should I use a number field?
Settings: I don’t need to change anything here
3. For the exkl. moms
Should I use a number field?
Settings: I don’t need to change anything here
4. For the momssumma
Should I used calculated fields?
Settings: fieldname2/(1+fieldname4/100)
fieldname2-fieldname3 (depending on which number the fields have then)5. Additional
Should I use html content field?
Settings: <script>
var field_edited = 0;
jQuery(document).on(‘keydown’, ‘[id*=”fieldname2_”]’, function(){field_edited = 2;});
jQuery(document).on(‘keydown’, ‘[id*=”fieldname3_”]’, function(){field_edited = 3;});
jQuery(document).on(‘keydown’, ‘[id*=”fieldname4_”]’, function(){field_edited = 4;});
</script>
6. Additional script
Where should I put this code?
(function(){
if(field_edited == 2) return fieldname2/(1+fieldname1/100);
if(field_edited == 3) return __ME__;
if(field_edited == 4) return fieldname4/(fieldname1/100);
})()-
This reply was modified 7 years, 6 months ago by
sdevad.
Hello @sdevad,
As you can understand, I cannot implement all the users’ projects for free as part of the support service, and you are requesting a step by step description of your project’s implementation, that is the same that to request the project’s development.
If you need that I implement your project, please, contact me through my private website:
https://cff.dwbooster.com/customization
Best regards.
Hi @codepeople
But instead of getting my information that I don’t understand you could have get me information that I could use?
It’s not step by step. It’s just two questions if you read my questions.
Hello @sdevad,
In the form inserted in the webpage you sent me as reference, you can enter a value in any of the input fields and the other fields are updated based on the entered value, so, the three input fields are calculated fields but editable (that means, the checkbox that converts the calculated fields as read-only should be unticked)
As the three fields are calculated but editable, you should identify which of them has been edited manually (with the keydown event in the piece of code entered through the content of the HTML Content field), and which fields change their values as result of the equations.
Furthermore, based on the field that has been modified by the action of the user is the mathematical operation that should apply in every case.
Best regards.
-
This reply was modified 7 years, 6 months ago by
The topic ‘calculate vat’ is closed to new replies.