Results 1 to 9 of 9

Thread: Logic Hook Calculation Will Only Add Up To 999.99?

  1. #1
    lassociates is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Logic Hook Calculation Will Only Add Up To 999.99?

    I have created a logic hook to calculate fields in the leads table from a post I found by andopes. If the calculation is between -999.99 and 999.99 there is no problem but if the result is 1000.00 then the logic hook inserts NULL in to the table. All of the fields are decimal fields in the database and I am not real sure what is causing this. Any help would be greatly appreciated.

    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    LeadLogicHook {
        function 
    calculate_field(&$focus$event$arguments) {
            
    // andopes comment: for float numbers it is necessary to unformat them to avoid wrong calculation
            
    require_once('modules/Currencies/Currency.php');

            
    $field1 unformat_number($focus->field1);
            
    $field2 unformat_number($focus->field2);
            
    $field3 unformat_number($focus->field3);
            
    $field4 $field1 $field2 $field3;
            
    $focus->field4 format_number($field4);
        }
    }
    ?>

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Logic Hook Calculation Will Only Add Up To 999.99?

    Let us know the file cache/modules/Leads/Leadvardefs.php

    Add the lines:
    PHP Code:
    echo "<LI>field 1 before transformation: '{$focus->field1}'</LI>";
    echo 
    "<LI>field 1 after transformation: '{$field1}'</LI>";
    echo 
    "<LI>field 2 before transformation: '{$focus->field2}'</LI>";
    echo 
    "<LI>field 2 after transformation: '{$field2}'</LI>";
    echo 
    "<LI>field 3 before transformation: '{$focus->field3}'</LI>";
    echo 
    "<LI>field 3 after transformation: '{$field3}'</LI>";
    echo 
    "<LI>field 4 before transformation: '{$field4}'</LI>";
    echo 
    "<LI>field 4 after transformation: '{$focus->field4}'</LI>";
    die(); 

    Just after the line
    PHP Code:
    $focus->field4 format_number($field4); 
    And try again. Let us know the result.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    lassociates is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Re: Logic Hook Calculation Will Only Add Up To 999.99?

    The results:
    Code:
    # field 1 before transformation: '952.00'
    # field 1 after transformation: '952.00'
    # field 2 before transformation: '210.00'
    # field 2 after transformation: '210.00'
    # field 3 before transformation: '1.00'
    # field 3 after transformation: '1.00'
    # field 4 before transformation: '1.00'
    # field 4 after transformation: '1.00'
    # Total Calculation: '1,184.00'
    The exp_total_c field in the database says NULL even though the calculation is correct. I have attached the Leadvardefs.php as there are a bunch of custom fields and that file is getting large.


    Thank you for taking the time to help me on this.
    Jason
    Last edited by lassociates; 2009-07-27 at 11:01 PM.

  4. #4
    lassociates is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Re: Logic Hook Calculation Will Only Add Up To 999.99?

    Any ideas on what might be causing this?

  5. #5
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Logic Hook Calculation Will Only Add Up To 999.99?

    The calculation does not seem OK.
    Let us know the logic_hook function.

    Best regards
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  6. #6
    lassociates is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Re: Logic Hook Calculation Will Only Add Up To 999.99?

    I have attached the files requested, thank you again for taking a look.

    Regards,
    Jason
    Last edited by lassociates; 2009-07-27 at 11:02 PM.

  7. #7
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Logic Hook Calculation Will Only Add Up To 999.99?

    The script seems fine.

    Make sure the field exp_total_c exists on leads_cstm table.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  8. #8
    lassociates is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Re: Logic Hook Calculation Will Only Add Up To 999.99?

    The field does exist in the table and will display the value accurately up to the value of 999.99. Once the value goes above that then the database shows a NULL value.

  9. #9
    lassociates is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Re: Logic Hook Calculation Will Only Add Up To 999.99?

    Ok, here's the problem...

    If you look at the results the calculation does great, the problem is when it gets to 1000.00 it will no longer insert the number into the database. The results tells all, the total says 1,184.00 which cannot be inserted into a decimal field in the database. Strip the , out of the number being inserted into the database and the calculation now works as it should.

    changing:
    PHP Code:
    $focus->field4 format_number($field4); 
    to:
    PHP Code:
    $focus->field4 unformat_number($field4); 
    Seems to fix this calculation.
    Last edited by lassociates; 2009-07-27 at 11:35 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help on my first logic hook.
    By amrutha in forum Developer Help
    Replies: 9
    Last Post: 2009-11-24, 01:29 PM
  2. logic hook
    By atik in forum Developer Help
    Replies: 2
    Last Post: 2009-03-28, 10:47 AM
  3. help with a logic hook
    By souheil in forum Français
    Replies: 12
    Last Post: 2009-03-13, 09:00 AM
  4. Help with a Logic Hook
    By Iggby in forum Developer Help
    Replies: 6
    Last Post: 2009-01-29, 12:01 PM
  5. Logic Hook
    By sacramentojoe in forum Help
    Replies: 15
    Last Post: 2007-07-31, 11:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •