Example #1
0
 public function cancelar($idPedido = false)
 {
     if (!$idPedido) {
         $idPedido = $this->getIdPedido();
     }
     $_lancamento = new Financeiro_DataView_Lancamento_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('item_pedido.id_pedido', $idPedido);
     $_itemLanc = new Vendas_DataView_ItemLanc_MapperView();
     $_itemLanc->findAll($_where, '*');
     while ($_itemLanc->fetch()) {
         $_lancamento->setId($_itemLanc->getIdLancamento())->retrieve()->cancelar();
     }
     $_where = new ZendT_Db_Where();
     $_where->addFilter('pagto_pedido.id_pedido', $idPedido);
     $_pagtoLanc = new Vendas_DataView_PagtoLanc_MapperView();
     $_pagtoLanc->findAll($_where, '*');
     while ($_pagtoLanc->fetch()) {
         $_lancamento->setId($_pagtoLanc->getIdLancamento())->retrieve()->cancelar();
     }
     return true;
 }
Example #2
0
 public function _afterSave()
 {
     parent::_afterSave();
     if (count($this->_others['item_pedido']) > 0 && $this->_others['item_pedido']['id_produto']) {
         $_itemPedido = new Vendas_DataView_ItemPedido_MapperView();
         $_itemPedido->setIdPedido($this->getId())->setIdProduto($this->_others['item_pedido']['id_produto'])->setQtdItem($this->_others['item_pedido']['qtd_item']);
         if (!$_itemPedido->exists()) {
             $_itemPedido->insert();
         }
     }
     if (count($this->_others['pagamento']) > 0 && $this->_others['pagamento']['id_forma_pagto']) {
         $_pagamento = new Vendas_DataView_Pagamento_MapperView();
         $_pagamento->setIdPedido($this->getId())->setIdFormaPagto($this->_others['pagamento']['id_forma_pagto']);
         if (!$_pagamento->exists()) {
             $_pagamento->insert();
         }
     }
     if ($this->getStatus(true)->toPhp() == 'E') {
         $_pagtoLanc = new Vendas_DataView_PagtoLanc_MapperView();
         $_where = new ZendT_Db_Where();
         $_where->addFilter('pagto_pedido.id_pedido', $this->getId());
         $_pagtoLanc->findAll($_where);
         if (!$_pagtoLanc->fetch()) {
             $this->_pagamento->efetivar($this->getId());
         }
     }
     if ($this->getStatus(true)->toPhp() == 'C') {
         $_pagtoLanc = new Vendas_DataView_PagtoLanc_MapperView();
         $_where = new ZendT_Db_Where();
         $_where->addFilter('pagto_pedido.id_pedido', $this->getId());
         $_pagtoLanc->findAll($_where);
         if ($_pagtoLanc->fetch()) {
             $this->_pagamento->cancelar($this->getId());
         }
     }
 }