示例#1
0
 public function converttoaccount()
 {
     $company = $this->_uses['Lead'];
     if (isset($this->_data['Lead']) && isset($this->_data['Lead'][$company->idField])) {
         $id = $this->_data['Lead'][$company->idField];
         $data = $this->_data['Lead'];
     } elseif (isset($this->_data[$company->idField])) {
         $id = $this->_data[$company->idField];
     } else {
         $flash = Flash::Instance();
         $flash->addError('Select a Lead to convert');
         sendTo('leads', 'index', array('contacts'));
     }
     $company->load($id);
     if (!$company->isLoaded()) {
         $flash = Flash::instance();
         $flash->addError('You do not have permission to edit this lead.');
         sendTo($this->name, 'index', $this->_modules);
         return;
     }
     $pl = new PreferencePageList('recently_viewed_leads' . EGS_COMPANY_ID);
     $pl->removePage(new Page(array('module' => 'contacts', 'controller' => 'leads', 'action' => 'view', 'id' => $company->id), 'company', $company->name));
     $pl->save();
     $pl = new PreferencePageList('recently_viewed_companies' . EGS_COMPANY_ID);
     $pl->addPage(new Page(array('module' => 'contacts', 'controller' => 'companys', 'action' => 'view', 'id' => $company->id), 'company', $company->name));
     $pl->save();
     $system_prefs = SystemPreferences::instance();
     $autoGenerate = $system_prefs->getPreferenceValue('auto-account-numbering', 'contacts');
     if (!(empty($autoGenerate) || $autoGenerate === 'off')) {
         $company->update($id, array('is_lead', 'accountnumber'), array('false', $company->createAccountNumber()));
         sendTo('companys', 'view', array('contacts'), array('id' => $company->id));
     } else {
         if (isset($data['accountnumber'])) {
             $company->update($id, array('is_lead', 'accountnumber'), array('false', $data['accountnumber']));
             sendTo('companys', 'view', array('contacts'), array('id' => $company->id));
         } else {
             parent::_new();
         }
     }
 }
示例#2
0
 public function delete()
 {
     $flash = Flash::Instance();
     $errors = array();
     $company = $this->_templateobject;
     $company->load($this->_data['id']);
     if (!$company->isLoaded()) {
         $flash->addError('You do not have permission to delete this contact.');
         sendTo($this->name, 'view', $this->_modules, array($company->idField => $company->{$company->idField}));
         return;
     }
     $pl = new PreferencePageList('recently_viewed_companies' . EGS_COMPANY_ID);
     $pl->removePage(new Page(array('module' => 'contacts', 'controller' => $this->name, 'action' => 'view', $company->idField => $company->{$company->idField}), 'company', $company->getIdentifierValue()));
     $pl->save();
     if (!$company->delete(null, $errors)) {
         exit;
         $errors[] = 'Error deleting ' . $company->getIdentifierValue();
         $flash->addErrors($errors);
         sendTo($this->name, 'view', $this->_modules, array($company->idField => $company->{$company->idField}));
     }
     exit;
     $flash->addMessage($company->getIdentifierValue() . ' deleted successfully');
     sendTo($this->name, 'index', $this->_modules);
 }