Exemple #1
0
 protected function _afterSave()
 {
     parent::_afterSave();
     $oldHierarquia = $this->getHierarquia(true)->toPhp();
     $idResp = $this->getIdPessoaResp(true)->toPhp();
     if ($idResp) {
         $_mapper = new Ca_Model_Pessoa_Mapper();
         $_mapper->setId($idResp)->retrieve();
         $hirarquia = $_mapper->getHierarquia(true)->toPhp() . '.' . $this->getId()->toPhp();
     } else {
         $hirarquia = $this->getId()->toPhp();
     }
     $hierarquiaComp = substr($hirarquia, 0, strlen($oldHierarquia));
     if ($hierarquiaComp && $oldHierarquia == $hierarquiaComp && $hierarquiaComp != $this->getId()->toPhp()) {
         //throw new ZendT_Exception_Alert(_i18n('Não é possível associar a empresa responvável para este registro, devido a infringir a hierarquia!'));
     }
     if ($oldHierarquia != $hirarquia) {
         $data = array();
         $data['hierarquia'] = $hirarquia;
         $this->getModel()->getAdapter()->update($this->getModel()->getName(), $data, 'id = ' . $this->getId()->toPhp());
     }
     $this->setHierarquia($hirarquia);
     if ($this->_action == 'update' && $oldHierarquia && $oldHierarquia != $hirarquia) {
         $_where = new ZendT_Db_Where();
         $_where->addFilter($this->getModel()->getName() . '.hierarquia', $oldHierarquia, '?%');
         $_where->addFilter($this->getModel()->getName() . '.id', $this->getId(), '!=');
         $_mapper = new Ca_DataView_Pessoa_MapperView();
         $_mapper->findAll($_where, '*');
         while ($_mapper->fetch()) {
             $_mapper->update();
         }
     }
 }
Exemple #2
0
 public function _beforeSave()
 {
     parent::_beforeSave();
     if ($this->_action != 'delete') {
         if ($this->getIdEmpresa(true)->toPhp() == '') {
             $this->setIdEmpresa(Auth_Session_User::getInstance()->getIdEmpresa());
         }
         if ($this->getIdCliente(true)->toPhp() == '') {
             $_pessoa = new Ca_DataView_Pessoa_MapperView();
             $_pessoa->setNome(_i18n('CONSUMIDOR'));
             $_pessoa->retrieve();
             $this->setIdCliente($_pessoa->getId());
         }
         if ($this->getIdClienteCon(true)->toPhp() == '') {
             $this->setIdClienteCon($this->getIdCliente());
         }
         if ($this->getIdUsuInc(true)->toPhp() == '') {
             $this->setIdUsuInc(Auth_Session_User::getInstance()->getId());
         }
         if ($this->getTipo(true)->toPhp() == '') {
             $this->setTipo('V');
         }
         if ($this->getStatus(true)->toPhp() == '') {
             $this->setStatus('A');
         }
         if ($this->getStatusEdi(true)->toPhp() == '') {
             $this->setStatusEdi('N');
         }
         if ($this->getDtEmis(true)->toPhp() == '') {
             $this->setDtEmis(ZendT_Type_Date::nowDate());
         }
         if ($this->getDhInc(true)->toPhp() == '') {
             $this->setDhInc(ZendT_Type_Date::nowDateTime());
         }
         $this->setIdUsuAlt(Auth_Session_User::getInstance()->getId());
         if ($this->getIdFuncionario(true)->toPhp() == '') {
             $_pessoa = new Ca_DataView_Pessoa_MapperView();
             $_pessoa->setEmail(Auth_Session_User::getInstance()->getLogin());
             $_pessoa->retrieve();
             $this->setIdFuncionario($_pessoa->getId());
         }
         if ($this->_action == 'update') {
             /*if ($this->getStatus()->toPhp() == 'A') {
                   $this->_pagamento = new Vendas_DataView_Pagamento_MapperView();
                   $this->_saldoPagto = $this->_pagamento->getSaldoPagar($this->getId());
                   if ($this->_saldoPagto == 0) {
                       $this->setStatus('P'); // pago
                   }
               }*/
         }
     }
     if ($this->_action == 'insert' && !$this->getNumero(true)->toPhp()) {
         $_numeracao = new Ca_Model_Numeracao_Mapper();
         $numero = $_numeracao->proximo(self::$table . '.numero', $this->getIdEmpresa()->toPhp());
         $this->setNumero($numero);
     }
 }
Exemple #3
0
 public function _beforeSave()
 {
     parent::_beforeSave();
     if ($this->_action == 'insert' && !$this->getNumero(true)->toPhp()) {
         $_numeracao = new Ca_Model_Numeracao_Mapper();
         $numero = $_numeracao->proximo(self::$table . '.numero', $this->getIdEmpresa(true)->toPhp());
         $this->setNumero($numero);
     }
     if ($this->getIdEmpresa(true)->toPhp() == '') {
         $this->setIdEmpresa(Auth_Session_User::getInstance()->getIdEmpresa());
     }
     if ($this->getIdCliente(true)->toPhp() == '') {
         $_pessoa = new Ca_DataView_Pessoa_MapperView();
         $_pessoa->setNome(_i18n('CONSUMIDOR'));
         $_pessoa->retrieve();
         $this->setIdCliente($_pessoa->getId());
     }
 }
Exemple #4
0
 protected function _cliente($data)
 {
     $this->_pessoa->newRow();
     $this->_pessoa->setCodigo($data->cnpjCliente);
     $this->_pessoa->setIdEmpresa(Auth_Session_User::getInstance()->getIdEmpresa());
     if (!$this->_pessoa->exists()) {
         $this->_pessoa->setNome($data->razaoSocialCliente)->setPapelCliente('1')->insert();
     }
     return $this->_pessoa->getId();
 }