Menu
Welcome, Guest
Username: Password: Remember me

TOPIC: Remove $ from Line Items Field in Subpanel Listview

Remove $ from Line Items Field in Subpanel Listview 3 months 1 week ago #80085

  • michellegoldmandev
  • michellegoldmandev's Avatar
  • Offline
  • Senior Member
  • Posts: 61
  • Thank you received: 1
  • Karma: 1
I added Line Items logic to my Opportunities module (renamed Time Entries) and am using the existing field 'subtotal_amount' field as total hours, which I want to be displayed as a non-currency field (no $) on the module's listviews. I was able to remove the $ from the main module's listview by changing the field type from currency to decimal and set currenty format from true to false in custom\modules\opportunity\listviewdefs.php file.

Time Entry/Opportunity Module Listview
pasteboard.co/I9ckDYn.jpg

However, when the Opportunity module is a subpanel of another module, the $ remains. In this case it is a subpanel of a custom module I created modeling off the Invoice module. I looked at the subpanel.txt and subpanel.php files and it looks like the main subpanel logic should be pulling the values from the parent module.

Time Entry/Opportunity Module Subpanel Listview
pasteboard.co/I9cljoM.jpg


I am looking for a way to remove the $ from the Opportunities subpanel listview. Has anyone been able to successfully do this?

Thank you.

Versions:
SuiteCRM 7.10.7
PHP 7.2
SQL Server 2014
Windows Server 2012 R2
Chrome 71.0.3578.98
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 3 months 1 week ago #80088

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10526
  • Thank you received: 1567
  • Karma: 360
I am not sure about your strategy of changing an existing field (instead of creating a custom one) but changing it's type...

But for that - have you checked the listviewdefs of the list view? How is the data type there?

If you need to override what is happening you can use several techniques, like this one

stackoverflow.com/questions/15278977/sug...code-in-listviewdefs

or this one

www.jsmackin.co.uk/suitecrm/suitecrm-lis...ditional-formatting/

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 3 months 1 week ago #80091

  • michellegoldmandev
  • michellegoldmandev's Avatar
  • Offline
  • Senior Member
  • Posts: 61
  • Thank you received: 1
  • Karma: 1
Thank you for your reply. Where is the listviewdefs of the list view you reference and I will check?

I tried the first link and that does not seem to have an effect on my field. The $ remains.

I have seen the second link you provided and am able to use something like this to place borders around fields in the subpanel listview ** as long as the field type is not decimal. When the field type is decimal, all of my actual values are replaced with $0.00. What I'm not sure how to do in this logic hook is to remove the $ from the total hours field. Could you please provide instruction on how to do that?
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 3 months 1 week ago #80127

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10526
  • Thank you received: 1567
  • Karma: 360
Sorry, I am not very sure of how to guide you in this specifically, so I can only try to be helpful with some generic clarifications.

If you change vardefs, you change data types in the database and in the Beans. If you change Listviewdefs you just change the way that information is presented on screen.

Note that you might need to visit the Quick Repair and Rebuild page AND scroll down to the bottom to see if it offers to sync database with vardefs - you might have these two things inconsistent.

Finally, when overriding a display method in the view, you are all-powerful and can change anything. However, since you normally don't override the entire thing, you typically just to change a bit and then call into the original method in the parent class. You have to find a balance to keep it simple but change what you need.

Going back to logic hook solution, from Jim's blog:

- try examining the Bean. Which data type is it?

- try changing the Bean - as far as I know, it won't affect anything, only the display, in that view. You shouldn't save the Bean, just change it (including data type if necessary) so it displays as you want.

Good luck, and tell us what you find.

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 3 months 1 week ago #80136

  • michellegoldmandev
  • michellegoldmandev's Avatar
  • Offline
  • Senior Member
  • Posts: 61
  • Thank you received: 1
  • Karma: 1
Hi. Thank you again for your responses.

I did do a quick repair and rebuild. Nothing out of sync in database.

Regarding the logic hook, that is precisely what I'm trying to do is just edit how this field appears in the listview for the subpanel. I just don't know the logic to use in SuiteCRM to remove the $ from my field value.



This is the example from the previous article link provided, which shows how to add a border around certain field types (does not work on decimals).
  public function highlightSubtotal(SugarBean $bean, $event, $arguments){
		global $app_strings, $current_user, $sugar_config, $locale, $fields;
		
		 
        $colour = substr(md5($bean->subtotal_amount),0,6);
        $bean->subtotal_amount = "<div style='border: solid  #$colour;'>".$bean->subtotal_amount."</div>";
		$bean->subtotal_amount = "<div style='background-color:  #$colour;'>".$bean->subtotal_amount."</div>";
	}

I'm thinking I should be able to do something like:
$bean->subtotal_amount = $bean->subtotal_amount|replace:'?':'' ;


Can you provide an example of how I would do that?

Thank you!
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 3 months 1 week ago #80228

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10526
  • Thank you received: 1567
  • Karma: 360
I never tried this and I am not sure how to guide you. But the example you give seems right, except that you need to use PHP str_replace

You can also try tinkering with the data type if necessary, to fool the display code into thinking it's a string, for example. It should be all volatile, meaning that if you mess up the bean, it won't have any further consequences apart from that view (unless you make the mistake of trying to save the bean).

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 3 months 1 week ago #80294

  • michellegoldmandev
  • michellegoldmandev's Avatar
  • Offline
  • Senior Member
  • Posts: 61
  • Thank you received: 1
  • Karma: 1
Thank you for the PHP lead. I did some research on the str_replace and was successful. This is the code I used in my logic hook.
<?php
class FormatSubtotalLogicHook
{
    public function formatSubtotal(SugarBean $bean, $event, $arguments){
	
		$subtotal = $bean->subtotal_amount; //Get subtotal current value
		$search = '$'; // create variable that will be searched for in the current subtotal value
		$replace = ''; // create variable to replace the $
		$newsubtotal = str_replace($subtotal, $search, $replace); // Create new variable that replaces the $ 

	}

}

This is where I was able to find the correct syntax and explanations on how to use the PHP str_replace.

PHP String Replace

Thanks again for your help!
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 2 weeks 4 days ago #86584

  • michellegoldmandev
  • michellegoldmandev's Avatar
  • Offline
  • Senior Member
  • Posts: 61
  • Thank you received: 1
  • Karma: 1
Hi there. I saw this post when I was looking to do the same thing. II have the same situation and tried your solution. It worked for a while and then just suddenly stopped working. I've seen this happen before when the changes I make to the custom files has no effect and I have to resort to modifying the SuiteCRM out of the box files (non-upgrade safe). Any help or insight would be much appreciated. Thank you.

Steps to Recreate Solution:
1. I created the logic hook in the custom/extension/modules/module name of subpanel/ext/logichooks directory
<?php
$hook_array['process_record'] = Array();
$hook_array['process_record'][] = Array(1, 'Format Subtotal', 'custom/modules/Opportunities/FormatSubtotalLogicHook.php','FormatSubtotalLogicHook', 'formatSubtotal');
?>

2. Then I created a new php file (referenced in step 1) in custom/modules/module name of subpanel
<?php
class FormatSubtotalLogicHook
{
    public function formatSubtotal(SugarBean $bean, $event, $arguments){
	
		$subtotal = $bean->subtotal_amount; //Get subtotal current value
		$search = '$'; // create variable that will be searched for in the current subtotal value
		$replace = ''; // create variable to replace the $
		$newsubtotal = str_replace($subtotal, $search, $replace); // Create new variable that replaces the $ 

	}

}
Last Edit: 2 weeks 4 days ago by pgr. Reason: add code tags
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 2 weeks 4 days ago #86585

  • michellegoldmandev
  • michellegoldmandev's Avatar
  • Offline
  • Senior Member
  • Posts: 61
  • Thank you received: 1
  • Karma: 1
I am trying to remove the $ from subtotal_amount specifically.
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 2 weeks 4 days ago #86592

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10526
  • Thank you received: 1567
  • Karma: 360
Have you tried a Quick Repair and Rebuild, after that upgrade that made it stop working?

These particular customizations you're showing here should be upgrade-safe, so there's no reason for them to stop working :huh:

You can check in custom/Ext/modules if your hook is getting picked up in the QR&R

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 1 week 3 days ago #86947

  • michellegoldmandev
  • michellegoldmandev's Avatar
  • Offline
  • Senior Member
  • Posts: 61
  • Thank you received: 1
  • Karma: 1
I did do a repair and actually placed another piece of code in that same logic hook that will place colored borders around one of the other fields in this listview and the borders appear. So, it appears it's running. Where do you mean in your reference "You can check in custom/Ext/modules if your hook is getting picked up in the QR&R "?
The administrator has disabled public write access.

Remove $ from Line Items Field in Subpanel Listview 1 week 3 days ago #86971

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10526
  • Thank you received: 1567
  • Karma: 360
During a QR & R, the stuff from

custom/Extension/**/Ext/

is gathered according to the kind of thing it is (a hook, or vardefs, or whatever) and placed in

custom/modules/Ext/**
and
custom/application/Ext/**

So you can inspect those directories to see if SuiteCRM is picking up your stuff.

But the test you did, of making your hook put red borders, obviously proves that the hook is operational.

I think all that you're missing is this: after that command calculating $newsubtotal with the str_replace, put that value into $bean->subtotal_amount

Or simply do it all in one command with
$bean->subtotal_amount = str_replace($bean->subtotal_amount, '$', ''); 

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
Last Edit: 1 week 3 days ago by pgr.
The administrator has disabled public write access.
Time to create page: 0.054 seconds
Powered by Kunena Forum