Results 1 to 7 of 7

Thread: date range

  1. #1
    mpatwi is offline Junior Member
    Join Date
    Apr 2008
    Posts
    2

    Default date range

    can you do a date range search in sugarcrm search. from x date to y date retreive all records that match. if not i think that would be an important feature to add i think?

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: date range

    Hi, mpatwi

    it is right possible.

    You have to modify the modules/Opportunities/metadata/SearchFields.php and set a search field for begin date (operator: >) and another one for end date (operator: <)
    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    pblag's Avatar
    pblag is offline Sugar Community Member
    Join Date
    Jul 2006
    Location
    Ukraine (Chernivtsy)
    Posts
    347

    Wink Re: date range

    Hi mpatwi!

    if you want we can do it for you.

    please feel free to contact us.
    Petro Blagodir
    petro@blagodir.ua
    http://www.blagodir.com
    Blagodir Ltd.( SugarCRM - Consultations, Development and Support)

  4. #4
    kenshiro is offline Sugar Community Member
    Join Date
    Mar 2007
    Location
    Macerata - ITALY
    Posts
    421

    Default Re: date range

    Quote Originally Posted by mpatwi
    can you do a date range search in sugarcrm search. from x date to y date retreive all records that match. if not i think that would be an important feature to add i think?
    Hi,
    it's available on the DEMO version of Enhanced Search.
    You'll find also many options for text search and OR / NOT operators.

    Take a look at this thread for more details.

  5. #5
    850039 is offline Member
    Join Date
    Nov 2008
    Posts
    17

    Default Re: date range

    Quote Originally Posted by andopes
    Hi, mpatwi

    it is right possible.

    You have to modify the modules/Opportunities/metadata/SearchFields.php and set a search field for begin date (operator: >) and another one for end date (operator: <)
    Cheers
    Hello, andopes

    This modification does not work. Look into the source code of SearchForm.php and SearchForm2.php, there are no cases for operators '<' and '>':

    PHP Code:
    switch(strtolower($operator)) {
                                case 
    'subquery':
                                    
    $sq $parms['subquery'];
                                    if(
    is_array($sq)){
                                        
    $and_or ' AND ';
                                        if (isset(
    $sq['OR'])){
                                            
    $and_or ' OR ';
                                        }
                                        
    $first true;
                                        foreach(
    $sq as $q){
                                            if(empty(
    $q) || strlen($q)<2) continue;
                                            if(!
    $first){
                                                
    $where .= $and_or;
                                            }
                                            
    $where .= " {$db_field} IN ({$q} '{$field_value}%') ";
                                            
    $first false;
                                        }
                                    }else{
                                      
    $where .= "{$db_field} IN ({$parms['subquery']} '{$field_value}%')";
                                    }

                                    break;

                                case 
    'like':

                                    if(isset(
    $parms['extra_search']) && !empty($parms['extra_search'])){
                                        
    //$where .=  "$parms[extra_search] like '$field_value$like_char' OR (($parms[extra_search]='') AND $db_field like '$field_value$like_char')";
                                        
    if($GLOBALS['db']->dbType == 'mysql') {
                                            
    $where .= "IFNULL($parms[extra_search],$db_field) like '$field_value$like_char'";
                                        }elseif(
    $GLOBALS['db']->dbType == 'mssql'){
                                            
    $where .= "ISNULL($parms[extra_search],$db_field) like '$field_value$like_char'";
                                        }elseif(
    $GLOBALS['db']->dbType == 'oci8'){
                                            
    $where .= "NVL($parms[extra_search],$db_field) like '$field_value$like_char'";
                                        }
                                    }else{
                                        
    $where .=  $db_field " like '".$field_value.$like_char."'";
                                    }
                                    break;
                                case 
    'in':
                                    
    $where .=  $db_field " in (".$field_value.')';
                                    break;
                                case 
    '=':
                                    
    $where .=  $db_field " = '".$field_value ."'";
                                    break;
                                case 
    'db_date':
                                    if(
    preg_match('/^\d{4}.\d{1,2}$/'$field_value) == 0) {
                                      
    $where .=  $db_field " = "$field_value;
                                    } else {
                                      
    // Create correct date_format conversion String
                                      
    if($GLOBALS['db']->dbType == 'oci8') {
                                          
    $where .= db_convert($db_field,'date_format',array("'YYYY-MM'")) . " = '" $field_value "'";
                                      } else {
                                          
    $where .= db_convert($db_field,'date_format',array("'%Y-%m'")) . " = '" $field_value "'";
                                      }
                                    }
                                    break;
                                
    // tyoung bug 15971 - need to add these special cases into the $where query
                                
    case 'custom_enum':
                                    
    $where .= $field_value;
                                    break;
                            } 
    So, do you have any idea how to make it work?

    Thank you
    Last edited by 850039; 2008-11-21 at 01:07 PM.

  6. #6
    850039 is offline Member
    Join Date
    Nov 2008
    Posts
    17

    Default Re: date range

    I solved this problem in next way:
    I made custom class CustomSearchForm which extends standard SearchForm, then I copied method generateSearchWhere and added my own cases. All that I needed to make it work just require my custom class instead of standard class in my view.

  7. #7
    precar is offline Member
    Join Date
    May 2009
    Posts
    7

    Default Re: date range

    Hi,

    I am trying to do the same thing as you. Would you mind giving me more detail on exactly what you did? Which files did you modify/add?


    Thanks a lot,
    Precar

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Date range in own module SugarCE 5.0
    By jacekskowron in forum Developer Help
    Replies: 6
    Last Post: 2008-01-21, 10:54 PM
  2. Setting default date range for Meeting Dashlet
    By leenwebb in forum Developer Help
    Replies: 2
    Last Post: 2007-02-22, 04:20 PM
  3. Date Range for Dashboard
    By LuvDodo in forum General Discussion
    Replies: 4
    Last Post: 2006-03-22, 06:18 PM
  4. HOWTO:Change date range in Dashboard
    By limleechin in forum Help
    Replies: 2
    Last Post: 2005-03-04, 08:19 AM

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
  •