• Resolved metesey

    (@metesey)


    Liste (fieldname1)
    A??klama – De?er
    Poz1: 15$
    Poz2: 20$
    Poz3: 40$
    Poz4: 26$
    Poz5: 15.5$

    Listedeki a??klama de?erine g?re bir hesaplamada de?erleri kullanmak istiyorum. Bu mümkün mü?

    Hesaplama (fieldname2)

    (10+20)*IN(‘Poz2’,fieldname1)
    = (10+20)*20 = 600$

    Daha sonra fieldname1 de?erlerini de?i?tirdi?im zaman hesaplama k?sm?n? de?i?tirmem gerekmesin.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @metesey

    The process is more simple. You can enter the numbers only (15, 20, 40, 26, and 15.5) in the choices’ values (note they are used only for calculations, you can configure the field to submit the choices’ texts), and then insert a calculated field in the form and enter the equation:

    (10+20)*fieldname1

    or simply:

    30*fieldname1

    Best regards.

    Plugin Author codepeople

    (@codepeople)

    Hello @metesey

    By the way, the plugin sums by itself the values of the ticked choices in the checkbox field, but if you disabled this feature from the checkbox field’s settings, its value would be an array with the values of the ticked choices, and in this case, you must make the sum explicitly, and the equation needs to be edited as follows:

    30*SUM(fieldname1)

    Best regards.

    Thread Starter metesey

    (@metesey)

    2024 Y?l?nda
    Liste (fieldname1) – Hidden
    A??klama – De?er
    Poz1: 15$
    Poz2: 20$
    Poz3: 40$
    Poz4: 26$
    Poz5: 15.5$

    Tam anlatamad?m galiba. Asl?nda benim istedi?im ücretleri bir listeye girece?im, sonra formülde o a??klamaya kar??l?k gelen de?eri alay?m. Kullan?c?lar bu ücretleri g?rmeyecek ve her y?l güncellenecek.

    Hesaplama-1
    (10+20)*IN(‘Poz2’,fieldname1)
    = (10+20)*20 = 600$

    Hesaplama-2
    (10+10+5)*IN(‘Poz3’,fieldname1)
    = 25*40 = 1000$

    Hesaplama-3
    (10+10)*IN(‘Poz1’,fieldname1)
    = 20*15 = 300$

    ——————————

    2025 Y?l?nda
    Liste (fieldname1) – Hidden
    A??klama – De?er
    Poz1: 20$
    Poz2: 25$
    Poz3: 45$
    Poz4: 31$
    Poz5: 20.5$

    yani y?llar de?i?ti?i zaman listedeki fiyatlar? olu?turaca??m. Hesaplamalar buna g?re güncellenecek.

    Hesaplama-1
    (10+20)*IN(‘Poz2’,fieldname1)
    = (10+20)*25 = 750$

    Hesaplama-2
    (10+10+5)*IN(‘Poz3’,fieldname1)
    = 25*45 = 1125$

    Hesaplama-3
    (10+10)*IN(‘Poz1’,fieldname1)
    = 20*40 = 400$

    Plugin Author codepeople

    (@codepeople)

    Hello @metesey

    In this case, if fieldname1 is a checkbox field with the choices values: Poz1, Poz2, Poz3, Poz4, and Poz5, and you want to implement the equation of the Hesaplama-1 field as follows:

    If the Poz2 choice is ticked in feldname1 the equation’s result would be: (10+20)*20 and zero if not.

    First, I recommend inserting an “HTML Content” field in the form to define the object with choices’ values (it allows you to edit the prices in only one place)


    <script>
    values = {'Poz1': 15, 'Poz2': 20, 'Poz3': 40, 'Poz4': 26, 'Poz5': 15.5};
    </script>

    And edit the equation in the calculated field as follows:

    (10+20)*IF(IN('Poz2', fieldname1|r, values['Poz2']), 0)

    You can follow a similar logic with the other equations.

    Best regards.

    Thread Starter metesey

    (@metesey)

    Te?ekkürler formülü a?a??daki gibi kulland?m. Fiyatlar? tek yerden kontrol etmek i?in.

    HTML ??eri?i
    <script>
    values = {‘Poz1’: 15, ‘Poz2’: 20, ‘Poz3’: 40, ‘Poz4’: 26, ‘Poz5’: 15.5};
    </script>

    Hesaplama

    (10+20)*values[‘Poz2’]

    ?yi ?al??malar dilerim.

    Plugin Author codepeople

    (@codepeople)

    Hello @metesey

    Yes, that’s fine, but if you want to evaluate the equation based on the fieldname1 choice selected you must include it in the equation.

    Best regards.

    Thread Starter metesey

    (@metesey)

    Merhaba son bir soru daha soracakt?m. Ba?ka hesaplamadaki de?eride alabiliyormuyuz.

    ?rne?in

    (10+20)*values[‘Poz2’]

    yerine

    (10+20)*[CP_CALCULATED_FIELDS id=”1″ values[‘Poz2’]]

    veya

    (10+20)*[CP_CALCULATED_FIELDS id=”7″ values[‘Poz2’]]

    gibi.

    ?yi ?al??malar dilerim.

    Plugin Author codepeople

    (@codepeople)

    Hello @metesey

    If you have two forms on the page, you can assign class names to them via their shortcodes:


    [CP_CALCULATED_FIELDS id="1" class="class-a"]
    [CP_CALCULATED_FIELDS id="7" class="class-b"]

    And assuming you want to use the value of the field in form with class-a in the equations of form-b, you can enter an equation similar to the following one:

    (10+20)*getField(fieldname2|n, '.class-a')

    The equation multiplies the (10+20) by the value of the field with name fieldname2 in the form with class class-a.

    Best regards.

    Thread Starter metesey

    (@metesey)

    class=”class-a” kodlar?n? nereden ekliyoruz, k?sa kodlardan m??

    Benim elimde bir fiyat listesi olacak bunu bir hesaplama sayfas?na “HTML ??eri?i” olarak a?a??daki gibi yazmak istiyorum.;

    <script>
    values = {'Poz1': 15, 'Poz2': 20, 'Poz3': 40, 'Poz4': 26, 'Poz5': 15.5};
    </script>

    Bundan sonraki hesaplamalarda ise bu fiyatlar? ?ekip kullanmak istiyorum. Fiyatlar sadece bir hesaplama formunda olacak. Ben bunu de?i?ik hesaplamalarda kullanmak istiyorum.

    ?rne?in:

    getField(fieldname1|n, ‘.class-a’).setChoices(values: [‘Poz2’])*7.85*2

    ama bu class’? nas?l atayaca??m ve values de?erlerini nas??l ?ekece?im onu beceremedim.

    Plugin Author codepeople

    (@codepeople)

    Hello @metesey

    For multiple forms on the page, you cannot use the same “values” variable name on them. The “values” variable in the last form would overwrite others.

    I honestly do not understand why you are making the process so complex. What do you want to implement exactly? Could you please describe the project in English? I think I’m losing something by translating the texts.

    Best regards.

    Thread Starter metesey

    (@metesey)

    Hello.
    Your calculation plugin is very nice and helps me to make flexible calculations. But I still need your help to solve some issues more easily.

    Let me try to explain my project in more detail.

    I want to create a price list to be used in later forms. The prices in this list will be updated every month. If I write these prices in each form, I will have to update all forms when updating prices. However, when I correct the prices only in a list, I want these prices to be updated in all forms (calculations) if possible;

    FORM 1: UNIT PRICES

    fieldname1: “HTML Content” or else

    <script>

    values = {‘Cost1': 15, 'Cost2': 20, 'Cost3': 40, 'Cost4': 26, 'Cost5': 15.5};

    </script>

    FORM 2: BATHROOM COST CALCULATION

    fieldname1: Bathroom field
    fieldname2: Wall height
    fieldname3: fieldname1*Cost2
    fieldname4: (fieldname1+fieldname2)*Cost3
    fieldname5: fieldname3+fieldname4

    FORM 3: KITCHEN COST CALCULATION

    fieldname1: Cabinet length
    fieldname2: Cabinet height
    fieldname3: (fieldname1+fieldname2)*Cost3

    FORM 4: WC COST CALCULATION


    FORM 5: ROOF COST CALCULATION


    Since I make calculations in different forms, how can I write formulas so that when the prices are updated, instead of opening each form and updating the prices in the calculations, I will update the prices on a sheet and with this update, the calculations in all forms will be updated?

    Plugin Author codepeople

    (@codepeople)

    Hello @metesey

    The behavior you describe can be implemented by using the DS fields distributed with the Developer and Platinum plugin versions.

    The DS fields read their values from external data sources like CSV files, databases, other submissions, ACF, etc.

    You can create the prices list in a CSV file (You can even use Google Sheets and publish the Google Sheets document in CSV format) and use it from the forms by using the DS fields.

    Implementing the forms in this way allows you to update the price list in one place. The forms would use the new prices without modifying the forms.

    So, assuming you have a CSV file with the columns: name, value


    name,value
    Cost1,15
    Cost2,20
    Cost3,40
    Cost4,26
    Cost5,15.5

    Now, in the form, you can insert a RecordSet DS field to read the CSV file from its URL. To describe the process I’ll call it fieldname123.

    The equations in “FORM 2: BATHROOM COST CALCULATION” can be implemented as follows:

    fieldname3 equation:


    (function(){
    let prices = fieldname123;
    for( let i in prices ) {
    if(prices[i]['name'] == 'Cost2') return fieldname1*prices[i]['value'];
    }

    })()

    fieldname4 equation:


    (function(){
    let prices = fieldname123;
    for( let i in prices ) {
    if(prices[i]['name'] == 'Cost3') return (fieldname1+fieldname2)*prices[i]['value'];
    }

    })()

    Learn more about the DS fields by reading the following blog post:

    https://cff.dwbooster.com/blog/2019/02/14/ds

    Best regards.

    Thread Starter metesey

    (@metesey)

    Tamam, ilginiz i?in te?ekkür ederim.

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.