Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Calculate Sum Of 2 Fields

  1. #1
    DanBrown is offline Senior Member
    Join Date
    Jul 2008
    Posts
    95

    Question Calculate Sum Of 2 Fields

    Hi All,

    I want to automatically calculate a sum of 2 fields and this to be automatically entered into a third field.
    the calculation is as follows: Credit Limit - Balance = Credit Available. But obviously i need this in PHP.

    I have seen this done for older versions like version 4.5 and 5.0 but not for 5.1.0b which is what im running.

    many thanks

  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: Calculate Sum Of 2 Fields

    Quote Originally Posted by DanBrown
    Hi All,

    I want to automatically calculate a sum of 2 fields and this to be automatically entered into a third field.
    the calculation is as follows: Credit Limit - Balance = Credit Available. But obviously i need this in PHP.

    I have seen this done for older versions like version 4.5 and 5.0 but not for 5.1.0b which is what im running.

    many thanks
    Hi Dan

    Do you want to calculate it on EditView after changing one of the fields "Credit Limit" and "Credit Available" or when saving a record?

    If your needs is the first one you need a javascript function, otherwise you need a logic_hook before_save.
    Let us know exactly your needs.
    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
    DanBrown is offline Senior Member
    Join Date
    Jul 2008
    Posts
    95

    Default Re: Calculate Sum Of 2 Fields

    its not necessary to do it in editview, but if it will calculate it in the detail view thats good

  4. #4
    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: Calculate Sum Of 2 Fields

    A logic_hook before_save function would be great!
    You can find documentation over it on the sugar wiki.
    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.

  5. #5
    DanBrown is offline Senior Member
    Join Date
    Jul 2008
    Posts
    95

    Default Re: Calculate Sum Of 2 Fields

    Hi andre,

    would i need to do something similar to what youve said in this thread

    http://www.sugarcrm.com/forums/showt...culated+fields

    thanks

  6. #6
    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: Calculate Sum Of 2 Fields

    OK.

    What is the big deal?
    This thread explains what to do...
    Is the big deal the portuguese language?
    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.

  7. #7
    DanBrown is offline Senior Member
    Join Date
    Jul 2008
    Posts
    95

    Default Re: Calculate Sum Of 2 Fields

    There is no big deal im just asking if the information in the thread is still valid and up to date, as i am not a PHP programmer and have no idea where to even begin with a logic_hook.

    By the way there is such a thing as a Google Translator so the language isnt an issue.

    Thanks...

  8. #8
    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: Calculate Sum Of 2 Fields

    You are right.
    This thread explain how to implement.
    If you follow all tips you will be able to implement that.

    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.

  9. #9
    DanBrown is offline Senior Member
    Join Date
    Jul 2008
    Posts
    95

    Default Re: Calculate Sum Of 2 Fields

    Many Thanks Andre

  10. #10
    DanBrown is offline Senior Member
    Join Date
    Jul 2008
    Posts
    95

    Default Re: Calculate Sum Of 2 Fields

    Hi Andre,

    I have one last favour to ask...

    The fields that you enter the numbers into, what type of field do they need to be, textfield, decimal or something else?

    Also i have attempted to create some Logic_hooks. Can you have a quick look and see if they look good to you.

    AccountLogicHook.php...

    PHP Code:
    <?php
    //prevents directly accessing this file from a web browser
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
     
    class 
    AccountLogicHook {
    function 
    calculateField(& $focus$event$arguments){
    $focus->test $focus->alpha $focus->bravo;
      }
    }
    ?>
    logic_hook.php...

    PHP Code:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version. This file will
    // be automatically rebuilt in the future.
    $hook_version 1;
    $hook_array = Array();
    // position, file, function
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1'calculatedField''modules/Accounts/AccountLogicHook.php ','AccountLogicHook''calculateField');
    ?>
    Many Thanks Again!

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Display sum of fields from subpanels
    By warmachine in forum Developer Help
    Replies: 3
    Last Post: 2009-03-12, 10:59 AM
  2. Sum of 2 fields
    By aschaeffer in forum Help
    Replies: 10
    Last Post: 2009-02-23, 02:48 PM
  3. Calculated Sum of 2 fields
    By kinshibuya in forum Help
    Replies: 14
    Last Post: 2008-11-04, 07:32 PM
  4. Replies: 4
    Last Post: 2007-04-03, 02:27 AM
  5. Auto Calculate & Populate Fields
    By coowboy in forum Developer Help
    Replies: 2
    Last Post: 2006-06-26, 11:58 AM

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
  •