Results 1 to 4 of 4

Thread: Logic Hook won't calculate more than one .php logic file in same module??

  1. #1
    infamousse is offline Senior Member
    Join Date
    Mar 2009
    Posts
    21

    Exclamation Logic Hook won't calculate more than one .php logic file in same module??

    So,

    I am back, apparently I was able to follow your suggestions (andopes) and the math for the custom module is working. Thank You, again.

    Here is the problem I am running into now. I was able to create the logic_hooks.php, and the logic file, in my case I created the following:
    logic_hooks.php and total_monthly_net.php (which is called by logic_hooks.php (or is it defined in?))

    At this point everything is working wonderfully and as you can see the files seem to be working and doing exactly what they are asked to do.

    logic_hooks.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 :: FINANCIALS LOGIC
    $hook_array['before_save'] = Array(); 
    $hook_array['before_save'][] = Array(1, 'total_monthly_net', 'custom/modules/sec2_financials/total_monthly_net.php', 'total_monthly_net_class', 'total_monthly_net_method'); 
    ?>
    total_monthly_net.php
    Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    
    class total_monthly_net_class {
        function total_monthly_net_method(&$focus, $event, $arguments) {
            // andopes comment: for float numbers it is necessary to unformat them to avoid wrong calculation
            require_once('modules/sec2_financials/sec2_financials.php');
    
            $main_net_inc = unformat_number($focus->main_net_inc);
            $co_net_inc = unformat_number($focus->co_net_inc);
            $second_job_c = unformat_number($focus->second_job_c);
    	 $child_support = unformat_number($focus->child_support);
    	 $rental = unformat_number($focus->rental);
    	 $ss_inc = unformat_number($focus->ss_inc);
    	 $pension = unformat_number($focus->pension);
    	 $other_inc = unformat_number($focus->other_inc);
            $total_mon_inc = $main_net_inc + $co_net_inc + $second_job_c + $child_support + $rental + $ss_inc + $pension + $other_inc;
            $focus->total_mon_inc = format_number($total_mon_inc);
        
        } 
    
    }
    ?>


    This is where my problem begins:

    I added a second definition to logic_hooks.php as you can see in the provided file(s). I have also added the math calculation in the second .php file named monthly_obs.php ; however at this point the field that should be auto calculating is doing nothing. No data is stored and I am not getting any errors to otherwise make me believe I am doing something wrong.

    logic_hooks.php (adding a second definition)
    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 :: FINANCIALS LOGIC
    $hook_array['before_save'] = Array(); 
    $hook_array['before_save'][] = Array(1, 'total_monthly_net', 'custom/modules/sec2_financials/total_monthly_net.php', 'total_monthly_net_class', 'total_monthly_net_method'); 
    $hook_array['before_save'][] = Array(1, 'monthly_obs', 'custom/modules/sec2_financials/monthly_obs.php', 'monthly_obs_class', 'monthly_obs_method'); 
    
    
    ?>
    monthly_obs.php (second definition logic)
    Code:
    <?php
    
    class monthly_obs_class {
        function monthly_obs_method(&$focus, $event, $arguments) {
            // andopes comment: for float numbers it is necessary to unformat them to avoid wrong calculation
           
    
            $rents_pay = unformat_number($focus->rents_pay);
            $home_repairs = unformat_number($focus->home_repairs);
            $other_mortg = unformat_number($focus->other_mortg);
    	 $total_monthly_ob = $rents_pay + $home_repairs + $other_mortg;
            $focus->total_monthly_ob = format_number($total_monthly_ob);
        } 
    
    }
    ?>
    What should I be doing at this point. Bare in mind, I will be running multiple math equations in this module so I need to be sure I can define more than 2 or 3 .php files with logic to:
    a) calculate
    b) print/save data in the appropriate field(s)

    Thanks again for any help any of you may be able to provide.

  2. #2
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,813

    Default Re: Logic Hook won't calculate more than one .php logic file in same module??

    Try numbering the second logic_hook reference as 2 instead of having two of them numbered as 1.
    Regards,

    Angel Magaņa
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

  3. #3
    infamousse is offline Senior Member
    Join Date
    Mar 2009
    Posts
    21

    Default Re: Logic Hook won't calculate more than one .php logic file in same module??

    Angel,

    I tried that prior to post (probably should have mentioned it), it doesn't seem to have a positive effect. Any other thoughts?

  4. #4
    infamousse is offline Senior Member
    Join Date
    Mar 2009
    Posts
    21

    Default Re: Logic Hook won't calculate more than one .php logic file in same module??

    OKAY,


    Apparently my problem lied within total_montlhly_ob (which was a CURRENCY field). It seem's that only TEXT FIELDS will work to store calculations. Thanks again. I will put up my final code as a reference marker for anyone else that is struggling with the same issues.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Logic HOok
    By mswathi in forum Developer Help
    Replies: 6
    Last Post: 2009-08-02, 11:29 PM
  2. Logic hook for a new module
    By AditiRao in forum Developer Help
    Replies: 2
    Last Post: 2009-04-14, 06:31 AM
  3. logic hook for a new module?????
    By amrutha in forum Developer Help
    Replies: 3
    Last Post: 2009-04-13, 06:39 AM
  4. logic hook
    By atik in forum Developer Help
    Replies: 2
    Last Post: 2009-03-28, 10:47 AM
  5. Can I do this with a logic hook?
    By daerid in forum Developer Help
    Replies: 2
    Last Post: 2008-04-23, 05:49 PM

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
  •