Results 1 to 3 of 3

Thread: How do you create a Custom Quote Number???

  1. #1
    CONN3CTED is offline Junior Member
    Join Date
    Mar 2008
    Posts
    1

    Default How do you create a Custom Quote Number???

    Hi All,
    I am new to Sugar and have been trying to find out how to create a custom quote number with no luck finding any answers??

    What I would like, is for my quote numbers to be in a format like "CN_OppName_Increment"
    The default appears to be "Account_Increment"

    Can anyone guide me to the best way to achieve this?

    Thanks in advance
    Glenn

  2. #2
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: How do you create a Custom Quote Number???

    A simple hook can achieve this. Here's some inspiration: In this case, I had to derive the Opportunity number from the year and add a auto increasing number to it. And, it has to be a string, because of the "-" character in the number.

    PHP Code:
    $hook_array['before_save'][] = array(0"_insert_quotenr"'custom/modules/Opportunities/_insert_quotenr.php''_insert_quotenr''generateQuoteNr'); 
    PHP Code:
    class _insert_quotenr {

      function 
    generateQuoteNr(& $bean$event$arguments) {
        
    print_r($_REQUEST);
        if (empty (
    $bean->name)) {
          if (
    $_REQUEST['relate_to'] == "Project" AND !empty ($_REQUEST['relate_id'])) {

            require_once 
    'modules/Project/Project.php';
            
    $Project = new Project();
            
    $Project->retrieve($_REQUEST['relate_id']);
          
    //  print_r($bean);exit;
            // Fill in the Project
            
    $bean->account_id $Project->account_id_c;

            
    // Fill in the Account
            
    $bean->project_id_c $_REQUEST['relate_id'];

            
    // We need a new quote nr
            
    $query "SELECT SUBSTRING(name, 9, 4) AS name FROM opportunities WHERE name LIKE ('" .$Project->name"%') ORDER BY name DESC";
            
    //echo $query; exit;
            
    $result $bean->db->query($query);
            
    $row $bean->db->fetchByAssoc($result);
            if (empty (
    $row['name'])) {
              
    //We have a new year
              
    $projnr $Project->name "-01";
            } else {
              
    ///We have an existing year
              
    $nr sprintf("%02d"$row['name'] + 1);
              
    $projnr $Project->name "-" $nr;
            }
            echo 
    $projnr;
            
    $bean->name $projnr;
          } else {
            die(
    "foobar");
          }
        }
      }

    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  3. #3
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: How do you create a Custom Quote Number???

    *pasting a PM for general benefit*

    Quote Originally Posted by user
    Sorry to private message you but I've got a real problem. I did something similar to what you have here:
    http://www.sugarcrm.com/forums/showthread.php?t=33820

    And it worked saving a derived name into the name field. So I thought I'd try it with some other modules and was unsuccessful. I thought it was just something about those modules. Now I've gone back to implement what was working on a new system with the 5.0f patch installed and it fails. It want's something in the name field first. If I put in anything then my code executes and a new name is created. But I know it was entering the derived name into the name field prior to saving. I am using the before_save event

    Have you upgraded to the f patch and noticed if there is a problem with this?

    Thanks so much for your time.
    Hi user,

    I believe the problem you're having is that the name field is required, and you need to fill in that field to create the record. For this to work, the name field must be read-only, like so:

    PHP Code:
    array (
            
    'name' => 'name',
            
    'type' => 'readonly'//this piece disables the input of the field
          
    ), 
    This is to go in editviewdefs.php in ./custom/modules/<module>/metadata/. If that file doesn't exist yet, copy it from ./modules/<module>/metadata and add this 1 line of code.

    Hope this helps. I'm off to the Caribbean now, so please don't hesitate to ask others the next 3 weeks .

    Good luck!
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. upgraded to 4.5.1e, received "Metadata for table tracker does not exist"
    By sfgeorge in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2007-09-03, 02:24 PM
  2. Replies: 3
    Last Post: 2007-02-05, 09:43 PM
  3. Trying To Create Custom Text Fields - BUG?
    By JustinK101 in forum Help
    Replies: 1
    Last Post: 2006-09-14, 05:35 PM
  4. Asterisk Patch 1.1.0 Crash on logon
    By skyracer in forum Help
    Replies: 6
    Last Post: 2006-07-08, 06:30 AM
  5. Replies: 7
    Last Post: 2006-06-06, 07:56 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
  •