Need help adding line to logic hook that will copy all data to a new module

Sugar OnDemand 9.1.0 Professional

When an opportunity reaches a sales stage of Closed Won, we create an account record in the Accounts module. The below works as intended in that respect, but I want to ensure that all data from the Opportunity record is copied over to the new account record and then deletes the opportunity record. Can you help me achieve this?

<?php

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class CreateAccountHook
{

    function after_save_method($bean, $event, $arguments)
    {
        //check if a fields value has changed
        if(isset($arguments['dataChanges']['sales_stage']) && $bean->sales_stage=='Closed Won')
        {
               $newAcc = BeanFactory::newBean('Accounts');
            $newAcc->name = $bean->name;
            $newAcc->save();
        }
    }
}

?>
Parents
  • Can you provide some context? Why to delete an Opportunity record?

    What is the goal on creating an Account from an Opportunity?

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Thanks for asking. Our process is as such:

    Marketing provides a list of leads that meet our requirements. Our sales staff(users) can then browse those leads and claim(convert) them according to region, etc, which then converts them to a Prospect(Opportunity). When they are a prospect, they are in the sales cycle and once the sales cycle = closed won, that prospect record then becomes a current account. Our goal is to copy all data from that prospect record to a new account record. Hope that helps clarify.

  • By default on converting a Lead the SugarCRM application creates a Contact and an Account and, eventually, an Opportunity.

    So what you just described seems to be a huge change on default process.

    I believe that what you REALLY need is, on converting a Lead, to create an Account with Type "Prospect" and as soon as its Opportunity gets "Closed Won" then update the related Account to Type "Customer" or something like that.

    Does that make sense?

    I would like to emphasize that deleting an Opportunity will mask the sales people productivity.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
Reply
  • By default on converting a Lead the SugarCRM application creates a Contact and an Account and, eventually, an Opportunity.

    So what you just described seems to be a huge change on default process.

    I believe that what you REALLY need is, on converting a Lead, to create an Account with Type "Prospect" and as soon as its Opportunity gets "Closed Won" then update the related Account to Type "Customer" or something like that.

    Does that make sense?

    I would like to emphasize that deleting an Opportunity will mask the sales people productivity.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
Children
No Data