Announcement

Collapse
No announcement yet.

Formula Calculations - Commissions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Formula Calculations - Commissions

    I am having trouble with a Formula to calculate Commissions under Entity Accounts, am I doing something wrong? Can i limit the calculations to 2 decimal places? USD
    I know its a lot but, just trying to be as detailed as possible.

    Problem # 1 - the Calculation is off by decimal places for the total on field commissions.
    Problem # 2 - the Calculation below if I change filed voice to anything other than 'New" it does not finish the calculation for the other 2 fields 'voice' and 'internet' and just enters a 0 or null value.

    I was able to duplicate all of this in the Demo CRM at http://demo.espocrm.com/advanced/?lang=en_US#

    field mrc should total $241.35 (correct)
    Code:
    ifThen(
       client == 'COMCAST',
       mrc = (( ccblmrc  +ccfflmrc + ccmlmrc + ccimrc + ccvmrc) - (discountinternet + discountvideo + discountvoice))
    );
    
    ifThenElse(
        client == 'COMCAST' && term = '24 Mo',
        commission =
           ifThenElse(
               voice == 'New',
               (ccblmrc + ccfflmrc + ccmlmrc) - discountvoice * 0.5,
               0
           )
           +
           ifThenElse(
               internet == 'New',
               (ccimrc - discountinternet) * 0.5,
               0
           )
           +
           ifThenElse(
               video == 'New',
               (ccvmrc - discountvideo) * 0.5,
               0
           ),
        0
    );
    example test info for fields:
    client = 'COMCAST',
    term = '24 Mo',
    voice = 'New',
    internet = 'New',
    video = 'New',
    ccblmrc = '24.95',
    ccfflmrc = '0',
    ccmlmrc = '134.85',
    ccimrc = '149.95',
    ccvmrc = '81.55',
    discountinternet = '70.00',
    discountvoice = '79.95',
    discountvideo = '0'


    commission field calculated from CRM = $119.85 , should equal $120.675 rounded to $120.68

    https://www.calculatorsoup.com/calcu...9&action=solve
    Last edited by yuri; 07-18-2018, 01:49 PM.

  • #2
    Hi,

    There might be a bug in parser. I will take a look.

    Comment


    • #3
      Hi,

      Try replacing the file application/Espo/Core/Formula/Parser.php with:

      Comment


      • #4
        Using what you provided its now giving me a result of 319.33 - it went up instead of down.

        Comment


        • #5
          Check your formula. I calculated manually and got the same result as formula gave.

          Comment


          • #6
            Total 241.35 / 0.5 = 120.675

            Formula: ifThenElse(client == 'COMCAST' && term = '24 Mo', commission = ifThenElse(voice == 'New', ccblmrc+ccfflmrc+ccmlmrc-discountvoice * 0.5,0) + ifThenElse(internet == 'New', ccimrc-discountinternet * 0.5,0) + ifThenElse(video == 'New', ccvmrc-discountvideo * 0.5,0),0);

            manually checking:
            (ccblmrc = '24.95' + ccfflmrc = '0' + ccmlmrc = '134.85' - discountvoice = '79.95') * 0.5 + (ccimrc = '149.95' - discountinternet = '70.00') * 0.5 + (ccvmrc = '81.55' - discountvideo = '0') * 0.5 =

            (24.95+0.00+134.85-79.95) = 79.85 * 0.5 = 39.925
            (149.95 - 70.00) = 79.95 * 0.5 = 39.975
            (81.55 - 0.00) = 81.55 * 0.5 = 40.75

            39.925 + 39.975 + 40.75 = 120.65


            Should not = 319.33

            Comment


            • #7
              I got 120.65.

              Comment


              • khopper
                khopper commented
                Editing a comment
                is there an attachment size limit? I can send an SWF video file so you can witness....

            • #8
              I formatted your code. Please use formatting to make it readable,

              Code:
              ifThenElse(
                  client == 'COMCAST' && term = '24 Mo',
                  commission = 
                         ifThenElse(
                          voice == 'New',
                          ccblmrc + ccfflmrc + ccmlmrc - discountvoice * 0.5,
                          0
                      )
                        +
                        ifThenElse(
                          internet == 'New',
                          ccimrc - discountinternet * 0.5, 
                          0
                      )
                        +
                        ifThenElse(
                          video == 'New',
                          ccvmrc - discountvideo * 0.5,
                          0
                         )
                    ,
                    0
              );

              Comment


              • #9
                There is a discrepancy between your formula and calculation you provided above.

                Comment


                • khopper
                  khopper commented
                  Editing a comment
                  What is the discrepancy you are mentioning? I am following order of operations PEDMAS.
                  Last edited by khopper; 07-18-2018, 06:17 PM.

              • #10
                Here is a video: https://ufile.io/xzfx1
                using the new Parser.php file and both formulas in the clean readable formats both giving inaccurate calculations.
                Please advise, this form doesn't appear to allow uploads larger than 97kb.

                Comment


                • #11
                  (149.95 - 70.00) = 79.95 * 0.5 = 39.975
                  and

                  ccimrc - discountinternet * 0.5

                  (81.55 - 0.00) = 81.55 * 0.5 = 40.75
                  and

                  ccvmrc - discountvideo * 0.5

                  Comment


                  • #12
                    There is exe file, no video.

                    Comment


                    • khopper
                      khopper commented
                      Editing a comment
                      the EXE is a self executable video. Created using SCREEN2SWF and exported to EXE.
                      If you would prefer I can send as SWF file.
                      Last edited by khopper; 07-18-2018, 07:36 PM.

                  • #13
                    I fixed your code to correspond to calculations you provided:

                    Code:
                    ifThenElse(
                        client == 'COMCAST' && term == '24 Mo',
                        commission =
                            ifThenElse(
                                voice == 'New',
                                (ccblmrc + ccfflmrc + ccmlmrc - discountvoice) * 0.5,
                                0
                            )
                            +
                            ifThenElse(
                                internet == 'New',
                                (ccimrc - discountinternet) * 0.5,
                                0
                            )
                            +
                            ifThenElse(
                                video == 'New',
                                (ccvmrc - discountvideo) * 0.5,
                                0
                            )
                        ,
                        commission = 0
                    );

                    It gives 120.675 !!!
                    Last edited by yuri; 07-18-2018, 07:41 PM.

                    Comment


                    • khopper
                      khopper commented
                      Editing a comment
                      My apologies - I had several variants of the formula and must have grabbed the wrong one.
                      So the Formula code will only work in the clean readable format? I can't have it on one line?

                  • #14
                    It will work in one line. The problem is not in formatting. The problem is in missed parentheses in your code.

                    Comment


                    • khopper
                      khopper commented
                      Editing a comment
                      Thank you for your patience.
                      I should keep the modified Parser.php file correct?

                  • #15
                    Keep Parser.php. It will be added in the next release.

                    Comment

                    Working...
                    X