Page 1 of 4 1234 LastLast
Results 1 to 10 of 36

Thread: calculations

  1. #1
    chris.marsden is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    57

    Default calculations

    Hi Guys,

    How do I do this?

    I have 2 custom fields which we will call X & Y. i want X & Y to perfiom this calculation X*Y/100=Z.

    here is the triky part, i want the value of this calculation (Z) to be outpit into another field as a currency format...

    Is this possible?

  2. #2
    ashokinsugar is offline Sugar Community Member
    Join Date
    Apr 2011
    Location
    INDIA
    Posts
    67

    Default Re: calculations

    Hi chris.marsden,

    Its possible, just fetch and write few custom code in save and display.

    If issue just google it you will get some help.

  3. #3
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    403

    Wink Re: calculations

    The best way you can do it is through logic hook.
    This is a tool of sugar that allow the developers to do some actions when you create, modify or delete any record.
    In this link there is an example (in spanish) but you can look for more googling.
    good luck

  4. #4
    chris.marsden is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    57

    Default Re: calculations

    None of the logic hook makes logical sence to me atm lol as it all seems relevant to adding tasks and auto creationg of call logs (this will be very useful however)... will keep reading but all help appriciated with the below:

    basicly what i want it to do is take the value of one custom field called EAC (textfield holding a number) (eg 12000) and multiply by another custom field called uplift (eg 1) (textbox holding a number). then devide to put decimal in correct place then output this as currency.

    Eg 12000 * 1p = £120
    the user will input it a a 1 however not 0.01 which is what it should be written as so i will need to devide by 100 to give correct output.

  5. #5
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    403

    Default Re: calculations

    I'd do the next:
    1. Create in /custom/modules/yourmodule/ the file logic_hooks.php only with this code:
      Code:
      $hook_version = 1;
      $hook_array['before_save'][] = Array(1,"calculations","custom/modules/yourmodule/calculations_Hook.php","calculations_Hook","calculations");
    2. Create in /custom/modules/yourmodule/ the file calculations_Hook.php with this code:


    PHP Code:
    require_once("include/modules/yourmodule/yourmodule.php");
    class 
    calculations_Hook{
        function 
    calculations(&$bean$event$arguments){
            global 
    $current_user;
            
    $oldOpp = new yourmodule.php();
            
    $oldOpp->retrieve($bean->id); 
                    if (empty(
    $bean->fetched_row['id'])){ //if is true is because it is a new record
                         
    $bean->fielddestination =  $bean->EAC $bean->uplift;
                          
    //here I'd do calculations on depending of other field that I create of kind dropdown list
                         //with all kinds of currencies that the user can choose
                           
    if($bean->currency == 'pound') {
                               
    //calculations for currency 'pound'
                           
    }   
                    }
        }


    • This will do the calculations in your module every time a new record of the module is created (not if is modified, only when is created)
    • As you can see at the code, I'd create other field for the currency chosen by the user.

    good luck chris
    Last edited by garciasanchezdaniel; 2011-10-08 at 02:21 PM.

  6. #6
    rafael.q.g@hotmail.com's Avatar
    rafael.q.g@hotmail.com is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Florianópolis - Brazil
    Posts
    782

    Default Re: calculations

    You can create a non-db field which value is camputed based in a php function.
    Take a look at this example: http://developers.sugarcrm.com/tutor...AgingField.pdf

    Then I have sure you easialy will be able to realize that.
    Rafael Queiroz Gonçalves
    Advanced OMG UML Certified Professional
    Sun Certified Enterprise Architect for the Java Platform
    Sun Certified Programmer for the Java 2 Platform
    IBM Certified Advanced Application Developer - Lotus Notes and Domino
    IBM Certified Application Developer - IBM WebSphere Portlet Factory
    Computer Science Mastering / UFSC - PPGCC

  7. #7
    Kupido is offline Sugar Community Member
    Join Date
    Apr 2011
    Posts
    60

    Default Re: calculations

    Hello

    the pdf is not bad, but my problem is the function.

    I need a simple calculation from 6 fields.
    I had field a, b,c,d,e,f and from this fields i want the sum in another field.(after save)

    Is that possible?

  8. #8
    kirstyobrien's Avatar
    kirstyobrien is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Denver, CO
    Posts
    32

    Default Re: calculations

    Couldn't you create a new field "Z" and have the calculation on this field so when there are values in fields X & Y the output appears in field Z?

  9. #9
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    403

    Default Re: calculations

    Quote Originally Posted by Kupido View Post
    Hello

    the pdf is not bad, but my problem is the function.

    I need a simple calculation from 6 fields.
    I had field a, b,c,d,e,f and from this fields i want the sum in another field.(after save)

    Is that possible?
    A simple and easy way to do it is through logic hooks as I have explained in my previous post.

  10. #10
    Kupido is offline Sugar Community Member
    Join Date
    Apr 2011
    Posts
    60

    Default Re: calculations

    Hello garciasanchezdaniel

    thx for your answer.

    But i understand not were you get the variables &$bean, $event, $arguments
    Who can i change this for my "problem"
    Where can get this variables


    thx a lot

Page 1 of 4 1234 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Calculations
    By henryvho in forum General Discussion
    Replies: 3
    Last Post: 2011-03-02, 03:44 PM
  2. Calculations in templates?
    By Systems Navigator in forum Help
    Replies: 12
    Last Post: 2010-10-27, 09:45 AM
  3. Calculations
    By monicaDC in forum Developer Help
    Replies: 11
    Last Post: 2009-05-13, 05:57 AM
  4. Simple Calculations
    By juniovalerio in forum Sales Force Automation
    Replies: 5
    Last Post: 2009-04-16, 08:33 AM
  5. Help with Calculations
    By JackieBM in forum Help
    Replies: 0
    Last Post: 2007-02-21, 06:13 AM

Tags for this Thread

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
  •