Results 1 to 9 of 9

Thread: Calculated fields in 6.3

  1. #1
    prusanoff is offline Sugar Community Member
    Join Date
    Jan 2012
    Location
    San Francisco
    Posts
    15

    Arrow Calculated fields in 6.3

    Hello I have followed the instuctions on http://developers.sugarcrm.com/tutor...AgingField.pdf to precalculate certin feilds. i am running V 6.3.1. after following the instuctions to a tee when i do a quik repair the repair modual stops at 'Rebuilding Relationships'. I am a beginner at programing and at sugar so i am gusing this old method will only work for sugar 5. can any one shed some light on this please. Below is my code

    In : /custom/Extension/modules/Accounts/Ext/Vardefs
    Code:
    <?php
     // created: 2012-01-20 11:53:18
    /* $dictionary['Account']['fields']['gross_revenue_c'] = array (
    	'name' => 'gross_revenue_c',
    	'vname' => 'LBL_GROSS_REVENUE',
    	'type' => 'decimal',
    	'function' => array('name'=>'getGrossProfit', 'returns'=>'html', 'include'=>'custom/CustomCode.php'),
    	'len' => '18',
    	'comment' => 'Automaticly calculated value for gross revenue'
    */
     ?>
    In : /custom/Extension/modules/Accounts/Ext/Language

    Code:
    <?php
    $mod_strings['LBL_GROSS_REVENUE'] = 'Gross Revenue';
    ?>
    In :

    Code:
    <?php  
    
    class getgross   /* trying to precalculate gross revenue */
    
     function getGrossProfit($bean, $field, $value, $view){   
        $total_charge_amount_c = ($bean->total_charge_amount_c ); 
        $cost_of_flight_c = ( $bean->cost_of_flight_c ); 
        $miscellaneous_cost_c = ($bean->miscellaneous_cost_c ); 
        $merchant_cost_c = ($bean->merchant_cost_c ); 
        $miles_c = ($bean->miles_c ); 
        $price_per_mile_c = ( $bean->price_per_mile_c); 
    	$gross_revenue_c = ( $bean->gross_revenue_c); 
    	 
     
    $gross_revenue_c = $total_charge_amount_c;
    $gross_revenue_c -= ($cost_of_flight_c == null ) ? ($miles * $price_per_mile_c ) : $cost_of_flight_c;
    $gross_revenue_c -=  $merchant_cost_c - $miscellaneous_cost_c ;  
    
    if($view == 'EditView' || $view == 'MassUpdate') { //If this is EditView Or MassUpdate Include a field box
    $gross_revenue_c = '<input type=text name=Gross Revenue value={$gross_revenue_c} disabled>\n';
    }
    
    return $gross_revenue_c;
    
    } 
    ?>

  2. #2
    jmertic is offline Sugar Community Manager
    Join Date
    Dec 2007
    Posts
    2,224

    Default Re: Calculated fields in 6.3

    You could do this really easily in Sugar Logic by adding a new calculated field with this formula:

    PHP Code:
    subtract($total_charge_amount_c,if(equal($cost_of_flight_c,null),multiply($miles_c,$price_per_mile_c),$cost_of_flight_c),$merchant_cost_c,$miscellaneous_cost_c
    John Mertic
    Sugar Community Manager

  3. #3
    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: Calculated fields in 6.3

    For my experience I say that maybe the issue could be because the file which has the custom function needs to be under include folder. It can't be in any folder as custom/ in your case.
    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

  4. #4
    prusanoff is offline Sugar Community Member
    Join Date
    Jan 2012
    Location
    San Francisco
    Posts
    15

    Default Re: Calculated fields in 6.3

    Quote Originally Posted by jmertic View Post
    You could do this really easily in Sugar Logic by adding a new calculated field with this formula:

    PHP Code:
    subtract($total_charge_amount_c,if(equal($cost_of_flight_c,null),multiply($miles_c,$price_per_mile_c),$cost_of_flight_c),$merchant_cost_c,$miscellaneous_cost_c
    Hi John

    Thank you for the help full hint. the code looks great but were do i put ? Please help!

  5. #5
    jmertic is offline Sugar Community Manager
    Join Date
    Dec 2007
    Posts
    2,224

    Default Re: Calculated fields in 6.3

    Quote Originally Posted by prusanoff View Post
    Hi John

    Thank you for the help full hint. the code looks great but were do i put ? Please help!
    This is added to the field in Studio, where you see 'Calculated Field'. This feature is only for PRO and above.
    John Mertic
    Sugar Community Manager

  6. #6
    prusanoff is offline Sugar Community Member
    Join Date
    Jan 2012
    Location
    San Francisco
    Posts
    15

    Default Re: Calculated fields in 6.3

    Yes i have heard of that in being in pro but i only have the community edition

  7. #7
    vipernet is offline Junior Member
    Join Date
    Jun 2010
    Posts
    4

    Default Re: Calculated fields in 6.3

    Any news?
    I'm wondering on how to be able in 6.2CE to sum a list of amounts in a Subtotal printed in a field.
    Am i only loosing time due to the CE/PRO limits?
    thank you all

    vc

  8. #8
    prusanoff is offline Sugar Community Member
    Join Date
    Jan 2012
    Location
    San Francisco
    Posts
    15

    Default Re: Calculated fields in 6.3

    Quote Originally Posted by jmertic View Post
    PHP Code:
    subtract($total_charge_amount_c,if(equal($cost_of_flight_c,null),multiply($miles_c,$price_per_mile_c),$cost_of_flight_c),$merchant_cost_c,$miscellaneous_cost_c
    Can i add this to the vardef.php ?????

  9. #9
    andywest is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    41

    Default Re: Calculated fields in 6.3

    I made a post about calculated fields last month i think, im sure if you search my posts you will find it. I attached a zip whch might help you

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. v6.1 calculated fields
    By Meyer in forum Help
    Replies: 2
    Last Post: 2011-04-08, 05:35 AM
  2. calculated fields
    By Meyer in forum Help
    Replies: 0
    Last Post: 2010-12-07, 01:53 PM
  3. Calculated Fields
    By alexbloom in forum Help
    Replies: 8
    Last Post: 2010-01-19, 07:31 PM
  4. Calculated Fields
    By cbeagle in forum Developer Help
    Replies: 7
    Last Post: 2009-10-15, 08:33 AM
  5. Creating Fields - calculated fields and 'related' field
    By gipps in forum General Discussion
    Replies: 0
    Last Post: 2007-07-21, 10:17 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
  •