2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
38 require_once('modules/Reports/Report.php');
39 require_once('include/generic/LayoutManager.php');
40 require_once('include/generic/SugarWidgets/SugarWidgetFieldrelate.php');
42 class Bug45716Helper {
43 public $all_fields = array (
46 'name' => 'account_id',
47 'vname' => 'LBL_ACCOUNT_ID',
51 'module' => 'Opportunities',
52 'real_table' => 'opportunities',
54 'self:account_id_c' =>
57 'source' => 'custom_fields',
58 'name' => 'account_id_c',
59 'vname' => 'LBL_LIST_RELATED_TO',
65 'importable' => 'true',
66 'duplicate_merge' => 'disabled',
67 'duplicate_merge_dom_value' => '0',
69 'reportable' => false,
70 'unified_search' => false,
71 'calculated' => false,
74 'id' => 'Opportunitiesaccount_id_c',
75 'custom_module' => 'Opportunities',
76 'module' => 'Opportunities',
77 'real_table' => 'opportunities_cstm',
79 'self:account_link_c' =>
84 'name' => 'account_link_c',
85 'vname' => 'LBL_ACCOUNT_LINK',
91 'importable' => 'true',
92 'duplicate_merge' => 'disabled',
93 'duplicate_merge_dom_value' => '0',
96 'unified_search' => false,
97 'calculated' => false,
100 'id_name' => 'account_id_c',
101 'ext2' => 'Accounts',
102 'module' => 'Opportunities',
104 'quicksearch' => 'enabled',
105 'studio' => 'visible',
106 'id' => 'Opportunitiesaccount_link_c',
107 'custom_module' => 'Opportunities',
108 'real_table' => 'opportunities_cstm',
109 'secondary_table' => 'accounts',
111 'self:account_name' =>
113 'name' => 'account_name',
115 'id_name' => 'account_id',
116 'vname' => 'LBL_ACCOUNT_NAME',
118 'table' => 'accounts',
119 'join_name' => 'accounts',
121 'module' => 'Opportunities',
122 'dbType' => 'varchar',
123 'link' => 'accounts',
125 'source' => 'non-db',
126 'unified_search' => true,
128 'importable' => 'required',
129 'real_table' => 'opportunities',
133 'name' => 'accounts',
135 'relationship' => 'accounts_opportunities',
136 'source' => 'non-db',
137 'link_type' => 'one',
138 'module' => 'Opportunities',
139 'bean_name' => 'Account',
140 'vname' => 'LBL_ACCOUNTS',
141 'real_table' => 'opportunities',
146 'vname' => 'LBL_AMOUNT',
147 'type' => 'currency',
148 'dbType' => 'double',
149 'comment' => 'Unconverted amount of the opportunity',
150 'importable' => 'required',
151 'duplicate_merge' => '1',
153 'options' => 'numeric_range_search_dom',
154 'enable_range_search' => true,
155 'module' => 'Opportunities',
156 'real_table' => 'opportunities',
158 'self:amount_usdollar' =>
160 'name' => 'amount_usdollar',
161 'vname' => 'LBL_AMOUNT_USDOLLAR',
162 'type' => 'currency',
164 'dbType' => 'double',
165 'disable_num_format' => true,
166 'duplicate_merge' => '0',
168 'comment' => 'Formatted amount of the opportunity',
169 'module' => 'Opportunities',
170 'real_table' => 'opportunities',
172 'self:assigned_user_id' =>
174 'name' => 'assigned_user_id',
175 'rname' => 'user_name',
176 'id_name' => 'assigned_user_id',
177 'vname' => 'LBL_ASSIGNED_TO_ID',
178 'group' => 'assigned_user_name',
181 'module' => 'Opportunities',
182 'reportable' => true,
186 'comment' => 'User ID assigned to record',
187 'duplicate_merge' => 'disabled',
188 'real_table' => 'opportunities',
190 'self:assigned_user_link' =>
192 'name' => 'assigned_user_link',
194 'relationship' => 'opportunities_assigned_user',
195 'vname' => 'LBL_ASSIGNED_TO_USER',
196 'link_type' => 'one',
197 'module' => 'Opportunities',
198 'bean_name' => 'User',
199 'source' => 'non-db',
200 'duplicate_merge' => 'enabled',
201 'rname' => 'user_name',
202 'id_name' => 'assigned_user_id',
204 'real_table' => 'opportunities',
206 'self:assigned_user_name' =>
208 'name' => 'assigned_user_name',
209 'link' => 'assigned_user_link',
210 'vname' => 'LBL_ASSIGNED_TO_NAME',
211 'rname' => 'user_name',
213 'reportable' => false,
214 'source' => 'non-db',
216 'id_name' => 'assigned_user_id',
217 'module' => 'Opportunities',
218 'duplicate_merge' => 'disabled',
219 'real_table' => 'opportunities',
225 'relationship' => 'opportunity_calls',
226 'source' => 'non-db',
227 'vname' => 'LBL_CALLS',
228 'module' => 'Opportunities',
229 'real_table' => 'opportunities',
231 'self:campaign_id' =>
233 'name' => 'campaign_id',
234 'comment' => 'Campaign that generated lead',
235 'vname' => 'LBL_CAMPAIGN_ID',
239 'table' => 'campaigns',
241 'module' => 'Opportunities',
242 'reportable' => false,
243 'massupdate' => false,
244 'duplicate_merge' => 'disabled',
245 'real_table' => 'opportunities',
247 'self:campaign_link' =>
249 'name' => 'campaign_link',
251 'relationship' => 'opportunities_campaign',
252 'vname' => 'LBL_CAMPAIGNS',
253 'link_type' => 'one',
254 'module' => 'Opportunities',
255 'bean_name' => 'Campaign',
256 'source' => 'non-db',
257 'reportable' => false,
258 'real_table' => 'opportunities',
260 'self:campaign_name' =>
262 'name' => 'campaign_name',
264 'id_name' => 'campaign_id',
265 'vname' => 'LBL_CAMPAIGN',
267 'link' => 'campaign_opportunities',
269 'table' => 'campaigns',
270 'module' => 'Opportunities',
271 'source' => 'non-db',
272 'real_table' => 'opportunities',
274 'self:campaign_opportunities' =>
276 'name' => 'campaign_opportunities',
278 'vname' => 'LBL_CAMPAIGN_OPPORTUNITY',
279 'relationship' => 'campaign_opportunities',
280 'source' => 'non-db',
281 'module' => 'Opportunities',
282 'real_table' => 'opportunities',
286 'name' => 'campaigns',
288 'relationship' => 'opportunities_campaign',
289 'module' => 'Opportunities',
290 'bean_name' => 'CampaignLog',
291 'source' => 'non-db',
292 'vname' => 'LBL_CAMPAIGNS',
293 'reportable' => false,
294 'real_table' => 'opportunities',
298 'name' => 'contacts',
300 'relationship' => 'opportunities_contacts',
301 'source' => 'non-db',
302 'module' => 'Opportunities',
303 'bean_name' => 'Contact',
309 'options' => 'opportunity_relationship_type_dom',
312 'vname' => 'LBL_CONTACTS',
313 'real_table' => 'opportunities',
317 'name' => 'contracts',
319 'vname' => 'LBL_CONTRACTS',
320 'relationship' => 'contracts_opportunities',
321 'source' => 'non-db',
322 'module' => 'Opportunities',
323 'real_table' => 'opportunities',
327 'name' => 'created_by',
328 'rname' => 'user_name',
329 'id_name' => 'modified_user_id',
330 'vname' => 'LBL_CREATED',
331 'type' => 'assigned_user_name',
335 'group' => 'created_by_name',
336 'comment' => 'User who created record',
337 'module' => 'Opportunities',
338 'real_table' => 'opportunities',
340 'self:created_by_link' =>
342 'name' => 'created_by_link',
344 'relationship' => 'opportunities_created_by',
345 'vname' => 'LBL_CREATED_USER',
346 'link_type' => 'one',
347 'module' => 'Opportunities',
348 'bean_name' => 'User',
349 'source' => 'non-db',
350 'real_table' => 'opportunities',
352 'self:created_by_name' =>
354 'name' => 'created_by_name',
355 'vname' => 'LBL_CREATED',
357 'reportable' => false,
358 'link' => 'created_by_link',
359 'rname' => 'user_name',
360 'source' => 'non-db',
362 'id_name' => 'created_by',
363 'module' => 'Opportunities',
364 'duplicate_merge' => 'disabled',
365 'importable' => 'false',
366 'real_table' => 'opportunities',
370 'name' => 'currencies',
372 'relationship' => 'opportunity_currencies',
373 'source' => 'non-db',
374 'vname' => 'LBL_CURRENCIES',
375 'module' => 'Opportunities',
376 'real_table' => 'opportunities',
378 'self:currency_id' =>
380 'name' => 'currency_id',
382 'group' => 'currency_id',
383 'vname' => 'LBL_CURRENCY',
386 'name' => 'getCurrencyDropDown',
389 'reportable' => false,
390 'comment' => 'Currency used for display purposes',
391 'module' => 'Opportunities',
392 'real_table' => 'opportunities',
394 'self:currency_name' =>
396 'name' => 'currency_name',
398 'id_name' => 'currency_id',
399 'vname' => 'LBL_CURRENCY_NAME',
402 'table' => 'currencies',
403 'module' => 'Opportunities',
404 'source' => 'non-db',
407 'name' => 'getCurrencyNameDropDown',
411 'duplicate_merge' => 'disabled',
412 'real_table' => 'opportunities',
414 'self:currency_symbol' =>
416 'name' => 'currency_symbol',
418 'id_name' => 'currency_id',
419 'vname' => 'LBL_CURRENCY_SYMBOL',
422 'table' => 'currencies',
423 'module' => 'Opportunities',
424 'source' => 'non-db',
427 'name' => 'getCurrencySymbolDropDown',
431 'duplicate_merge' => 'disabled',
432 'real_table' => 'opportunities',
434 'self:currency_target_c' =>
437 'source' => 'custom_fields',
438 'name' => 'currency_target_c',
439 'vname' => 'LBL_CURRENCY_TARGET',
440 'type' => 'currency',
445 'importable' => 'false',
446 'duplicate_merge' => 'disabled',
447 'duplicate_merge_dom_value' => '0',
449 'reportable' => true,
450 'unified_search' => false,
451 'calculated' => false,
454 'enable_range_search' => false,
455 'id' => 'Opportunitiescurrency_target_c',
456 'custom_module' => 'Opportunities',
457 'module' => 'Opportunities',
458 'real_table' => 'opportunities_cstm',
460 'self:date_closed' =>
462 'name' => 'date_closed',
463 'vname' => 'LBL_DATE_CLOSED',
466 'comment' => 'Expected or actual date the oppportunity will close',
467 'importable' => 'required',
469 'enable_range_search' => true,
470 'options' => 'date_range_search_dom',
471 'module' => 'Opportunities',
472 'real_table' => 'opportunities',
474 'self:date_entered' =>
476 'name' => 'date_entered',
477 'vname' => 'LBL_DATE_ENTERED',
478 'type' => 'datetime',
479 'group' => 'created_by_name',
480 'comment' => 'Date record created',
481 'enable_range_search' => true,
482 'options' => 'date_range_search_dom',
483 'module' => 'Opportunities',
484 'real_table' => 'opportunities',
486 'self:date_modified' =>
488 'name' => 'date_modified',
489 'vname' => 'LBL_DATE_MODIFIED',
490 'type' => 'datetime',
491 'group' => 'modified_by_name',
492 'comment' => 'Date record last modified',
493 'enable_range_search' => true,
494 'options' => 'date_range_search_dom',
495 'module' => 'Opportunities',
496 'real_table' => 'opportunities',
501 'vname' => 'LBL_DELETED',
504 'reportable' => false,
505 'comment' => 'Record deletion indicator',
506 'module' => 'Opportunities',
507 'real_table' => 'opportunities',
509 'self:description' =>
511 'name' => 'description',
512 'vname' => 'LBL_DESCRIPTION',
514 'comment' => 'Full text of the note',
517 'module' => 'Opportunities',
518 'real_table' => 'opportunities',
522 'name' => 'documents',
524 'relationship' => 'documents_opportunities',
525 'source' => 'non-db',
526 'vname' => 'LBL_DOCUMENTS_SUBPANEL_TITLE',
527 'module' => 'Opportunities',
528 'real_table' => 'opportunities',
534 'relationship' => 'emails_opportunities_rel',
535 'source' => 'non-db',
536 'vname' => 'LBL_EMAILS',
537 'module' => 'Opportunities',
538 'real_table' => 'opportunities',
546 'reportable' => true,
547 'comment' => 'Unique identifier',
548 'module' => 'Opportunities',
549 'real_table' => 'opportunities',
551 'self:lead_source' =>
553 'name' => 'lead_source',
554 'vname' => 'LBL_LEAD_SOURCE',
556 'options' => 'lead_source_dom',
558 'comment' => 'Source of the opportunity',
559 'merge_filter' => 'enabled',
560 'module' => 'Opportunities',
561 'real_table' => 'opportunities',
567 'relationship' => 'opportunity_leads',
568 'source' => 'non-db',
569 'vname' => 'LBL_LEADS',
570 'module' => 'Opportunities',
571 'real_table' => 'opportunities',
575 'name' => 'meetings',
577 'relationship' => 'opportunity_meetings',
578 'source' => 'non-db',
579 'vname' => 'LBL_MEETINGS',
580 'module' => 'Opportunities',
581 'real_table' => 'opportunities',
583 'self:modified_by_name' =>
585 'name' => 'modified_by_name',
586 'vname' => 'LBL_MODIFIED_NAME',
588 'reportable' => false,
589 'source' => 'non-db',
590 'rname' => 'user_name',
592 'id_name' => 'modified_user_id',
593 'module' => 'Opportunities',
594 'link' => 'modified_user_link',
595 'duplicate_merge' => 'disabled',
596 'real_table' => 'opportunities',
598 'self:modified_user_id' =>
600 'name' => 'modified_user_id',
601 'rname' => 'user_name',
602 'id_name' => 'modified_user_id',
603 'vname' => 'LBL_MODIFIED',
604 'type' => 'assigned_user_name',
607 'group' => 'modified_by_name',
609 'reportable' => true,
610 'comment' => 'User who last modified record',
611 'module' => 'Opportunities',
612 'real_table' => 'opportunities',
614 'self:modified_user_link' =>
616 'name' => 'modified_user_link',
618 'relationship' => 'opportunities_modified_user',
619 'vname' => 'LBL_MODIFIED_USER',
620 'link_type' => 'one',
621 'module' => 'Opportunities',
622 'bean_name' => 'User',
623 'source' => 'non-db',
624 'real_table' => 'opportunities',
629 'vname' => 'LBL_OPPORTUNITY_NAME',
631 'dbType' => 'varchar',
633 'unified_search' => true,
634 'comment' => 'Name of the opportunity',
635 'merge_filter' => 'selected',
636 'importable' => 'required',
638 'module' => 'Opportunities',
639 'real_table' => 'opportunities',
643 'name' => 'next_step',
644 'vname' => 'LBL_NEXT_STEP',
647 'comment' => 'The next step in the sales process',
648 'merge_filter' => 'enabled',
649 'module' => 'Opportunities',
650 'real_table' => 'opportunities',
656 'relationship' => 'opportunity_notes',
657 'source' => 'non-db',
658 'vname' => 'LBL_NOTES',
659 'module' => 'Opportunities',
660 'real_table' => 'opportunities',
662 'self:opportunity_type' =>
664 'name' => 'opportunity_type',
665 'vname' => 'LBL_TYPE',
667 'options' => 'opportunity_type_dom',
670 'comment' => 'Type of opportunity (ex: Existing, New)',
671 'merge_filter' => 'enabled',
672 'module' => 'Opportunities',
673 'real_table' => 'opportunities',
675 'self:probability' =>
677 'name' => 'probability',
678 'vname' => 'LBL_PROBABILITY',
680 'dbType' => 'double',
682 'comment' => 'The probability of closure',
689 'merge_filter' => 'enabled',
690 'module' => 'Opportunities',
691 'real_table' => 'opportunities',
697 'relationship' => 'projects_opportunities',
698 'source' => 'non-db',
699 'vname' => 'LBL_PROJECTS',
700 'module' => 'Opportunities',
701 'real_table' => 'opportunities',
707 'relationship' => 'quotes_opportunities',
708 'source' => 'non-db',
709 'vname' => 'LBL_QUOTES',
710 'module' => 'Opportunities',
711 'real_table' => 'opportunities',
713 'self:sales_stage' =>
715 'name' => 'sales_stage',
716 'vname' => 'LBL_SALES_STAGE',
718 'options' => 'sales_stage_dom',
721 'comment' => 'Indication of progression towards closure',
722 'merge_filter' => 'enabled',
723 'importable' => 'required',
725 'module' => 'Opportunities',
726 'real_table' => 'opportunities',
732 'relationship' => 'opportunity_tasks',
733 'source' => 'non-db',
734 'vname' => 'LBL_TASKS',
735 'module' => 'Opportunities',
736 'real_table' => 'opportunities',
740 'name' => 'team_count',
741 'rname' => 'team_count',
742 'id_name' => 'team_id',
743 'vname' => 'LBL_TEAMS',
744 'join_name' => 'ts1',
747 'required' => 'true',
749 'module' => 'Opportunities',
750 'link' => 'team_count_link',
751 'massupdate' => false,
753 'source' => 'non-db',
754 'importable' => 'false',
755 'reportable' => false,
756 'duplicate_merge' => 'disabled',
759 'real_table' => 'opportunities',
761 'self:team_count_link' =>
763 'name' => 'team_count_link',
765 'relationship' => 'opportunities_team_count_relationship',
766 'link_type' => 'one',
767 'module' => 'Opportunities',
768 'bean_name' => 'TeamSet',
769 'source' => 'non-db',
770 'duplicate_merge' => 'disabled',
771 'reportable' => false,
773 'real_table' => 'opportunities',
778 'vname' => 'LBL_TEAM_ID',
779 'group' => 'team_name',
780 'reportable' => false,
782 'type' => 'team_list',
784 'comment' => 'Team ID for the account',
785 'module' => 'Opportunities',
786 'real_table' => 'opportunities',
790 'name' => 'team_link',
792 'relationship' => 'opportunities_team',
793 'vname' => 'LBL_TEAMS_LINK',
794 'link_type' => 'one',
795 'module' => 'Opportunities',
796 'bean_name' => 'Team',
797 'source' => 'non-db',
798 'duplicate_merge' => 'disabled',
800 'real_table' => 'opportunities',
804 'name' => 'team_name',
805 'db_concat_fields' =>
810 'sort_on' => 'tj.name',
813 'id_name' => 'team_id',
814 'vname' => 'LBL_TEAMS',
816 'required' => 'true',
819 'module' => 'Opportunities',
820 'link' => 'team_link',
821 'massupdate' => false,
822 'dbType' => 'varchar',
823 'source' => 'non-db',
825 'custom_type' => 'teamset',
826 'real_table' => 'opportunities',
828 'self:team_set_id' =>
830 'name' => 'team_set_id',
832 'id_name' => 'team_set_id',
833 'vname' => 'LBL_TEAM_SET_ID',
834 'type' => 'team_set_id',
838 'module' => 'Opportunities',
839 'real_table' => 'opportunities',
845 'relationship' => 'opportunities_teams',
846 'bean_filter_field' => 'team_set_id',
847 'rhs_key_override' => true,
848 'source' => 'non-db',
849 'vname' => 'LBL_TEAMS',
850 'link_class' => 'TeamSetLink',
851 'link_file' => 'modules/Teams/TeamSetLink.php',
853 'reportable' => false,
854 'module' => 'Opportunities',
855 'real_table' => 'opportunities',
857 ); // END: all_fields
862 public $selected_loaded_custom_links = array (
863 'opportunities_cstm' =>
865 'join_table_alias' => 'opportunities_cstm',
866 'base_table' => 'opportunities',
867 'real_table' => 'opportunities_cstm',
869 'accounts_account_link_c' =>
871 'join_table_alias' => 'accounts1',
872 'base_table' => 'accounts',
873 'join_id' => 'opportunities_cstm.account_id_c',
875 ); // END: selected_loaded_custom_links
879 function getAttribute( $dontcare ) {
884 class Bug45716Test extends Sugar_PHPUnit_Framework_TestCase
886 public function setUp() {
889 $GLOBALS['action'] = 'index';
890 $GLOBALS['module'] = 'Reports';
891 $GLOBALS['app_strings'] = return_application_language('en_us');
892 $GLOBALS['app_list_strings'] = return_app_list_strings_language('en_us');
893 $GLOBALS['mod_strings'] = return_module_language('en_us','Reports');
894 $GLOBALS['db'] = DBManagerFactory::getInstance();
895 $GLOBALS['current_user'] = new User();
896 $GLOBALS['current_user']->retrieve('1');
899 public function tearDown() {
900 unset($GLOBALS['module']);
901 unset($GLOBALS['action']);
902 unset($GLOBALS['mod_strings']);
903 unset($GLOBALS['current_user']);
907 public function testCustomRelatedLink()
909 $layout_def = array (
910 'name' => 'account_id_c',
911 'label' => 'Account Link',
912 'table_key' => 'self',
913 'table_alias' => 'opportunities_cstm',
914 'column_key' => 'self:account_link_c',
918 'PRIMARYID' => '10765534-ff52-52ec-5840-4f16faec901f',
919 'OPPORTUNITIES_NAME' => 'Trait Institute Inc - 1000 units',
920 'OPPORTUNITIES_AMOUNT_UBC8F31' => '52183382.29',
921 'OPPORTUNITIES_AMOUNT' => '52183382.29',
922 'OPPORTUNITIES_AMOUNT_C9AC638' => '-99',
923 'OPPORTUNITIES_CSTM_ACCE36316' => '13ce632e-605e-93ac-c209-4f16fa14e616',
924 'ACCOUNTS1_NAME' => 'OTC Holdings',
927 $fakeLayoutManager = new Bug45716Helper();
928 $sugarWidget = new SugarWidgetFieldrelate($fakeLayoutManager);
930 $output = $sugarWidget->displayList($layout_def);
932 $this->assertContains('record=13ce',$output, 'Missing the id in the output url');