示例#1
0
文件: Edit.php 项目: rtsantos/mais
 /**
  * Carrega os elementos no formulário para serem renderizado
  * @return void
  */
 public function loadElements($action = 'insert')
 {
     parent::loadElements($action);
     $idPedido = Zend_Controller_Front::getInstance()->getRequest()->getParam('id_pedido');
     if ($idPedido) {
         $_mapper = new Vendas_DataView_Pagamento_MapperView();
         $vlrTotal = $_mapper->getSaldoPagar($idPedido);
         $_mapper->setVlrTotal($vlrTotal);
         $vlrTotal = $_mapper->getVlrTotal()->get();
         $perDesc = 0;
         $_mapper->setPerDesc($perDesc);
         $perDesc = $_mapper->getPerDesc()->get();
         $this->getElement('vlr_total')->setValue($vlrTotal);
         $this->getElement('vlr_a_pagar')->setValue($vlrTotal);
         $this->getElement('per_desc')->setValue($perDesc);
         $this->getElement('per_acre')->setValue($perDesc);
     }
 }
示例#2
0
文件: Mapper.php 项目: rtsantos/mais
 public function efetivar($idPedido = false)
 {
     if (!$idPedido) {
         $idPedido = $this->getIdPedido();
     }
     $_pedido = new Vendas_DataView_Pedido_MapperView();
     $_pedido->setId($idPedido)->retrieve();
     $_pagtoLanc = new Vendas_DataView_PagtoLanc_MapperView();
     $_pagamento = new Vendas_DataView_Pagamento_MapperView();
     $_lancamento = new Financeiro_DataView_Lancamento_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('cv_pagto_pedido.id_pedido', $idPedido);
     $rows = $_pagamento->recordset($_where);
     $pago = false;
     $vlrTotal = 0;
     while ($row = $rows->getRow()) {
         if ($row['pago_forma_pagto']->toPhp() == 'S') {
             $pago = true;
         }
         $qtd = $row['qtd_parcela']->toPhp();
         if (!$qtd) {
             $qtd = 1;
         }
         for ($index = 0; $index < $qtd; $index++) {
             $dtVenc = $row['dt_venc_parc'];
             if ($dtVenc->toPhp() == '') {
                 $dtVenc = $row['dt_emis_pedido'];
             }
             if ($dtVenc->toPhp() == '') {
                 $dtVenc = ZendT_Type_Date::nowDate();
             }
             if ($index) {
                 $dtVenc->addMonths($index);
             }
             $vlrParc = $row['vlr_parc'];
             if ($vlrParc->toPhp() == '') {
                 $vlrParc = $row['vlr_a_pagar'];
             }
             if ($vlrParc->toPhp() == '') {
                 $vlrParc = $row['vlr_pago'];
             }
             $_lancamento->newRow()->setTipo('C')->setIdEmpresa($_pedido->getIdEmpresa())->setIdFavorecido($_pedido->getIdEmpresa())->setDescricao('VENDA DE PEDIDO')->setObservacao('PAGAMENTO ' . ($index + 1) . " de " . $qtd . '. PEDIDO: ' . $row['numero_pedido'])->setIdFormaPagto($row['id_forma_pago'])->setPago($row['pago_forma_pagto'])->setDtLanc($dtVenc)->setVlrLanc($vlrParc)->insert();
             $_pagtoLanc->newRow()->setIdPagtoPedido($row['id'])->setIdLancamento($_lancamento->getId())->insert();
             $vlrTotal = $vlrTotal + $vlrParc->toPhp();
         }
     }
     /**
      * Avalia se é preciso gerar débitos para o pedido
      * custos com imposto ou comissões
      */
     $dtPedido = $_pedido->getDtEmis();
     if ($dtPedido->toPhp() == '') {
         $dtPedido = ZendT_Type_Date::nowDate();
     }
     $dtVenc = $dtPedido;
     $_regra = new Ca_DataView_RegraContrato_MapperView();
     $_itemLanc = new Vendas_DataView_ItemLanc_MapperView();
     $_itens = new Vendas_DataView_ItemPedido_MapperView();
     $_itens->setIdPedido($idPedido);
     $_itens->findAll(null, '*');
     while ($_itens->fetch()) {
         $_where = new ZendT_Db_Where();
         $_where->addFilter('ca_regra_contrato.id_produto', $_itens->getIdProduto());
         $_where->addFilter('ca_regra_contrato.status', 'A');
         $_where->addFilter('ca_regra_contrato.tipo', 'CD');
         $_where->addFilter('ca_regra_contrato.favorecido', 'ca_pedido.', '?%');
         $_where->addFilter('contrato.dt_vig_ini', $dtPedido, '<=');
         $_where->addFilter('contrato.dt_vig_fim', $dtPedido, '>=');
         $_where->addFilter('contrato.id_cliente', $_pedido->getIdClienteCon());
         $_where->addFilter('contrato.status', 'A');
         $_regra->findAll($_where, '*');
         while ($_regra->fetch()) {
             $favorecido = $_regra->getFavorecido()->toPhp();
             $favorecido = str_replace('ca_pedido.', '', $favorecido);
             if ($favorecido == 'especifico') {
                 $idFavorecido = $_regra->getIdFavorecido();
             } else {
                 $idFavorecido = $_pedido->getData($favorecido);
             }
             $desc = $_regra->getDescLanc()->toPhp();
             if (!$desc) {
                 $desc = 'PEDIDO DE VENDA: ' . $_pedido->getNumero()->get();
             }
             if (!$idFavorecido) {
                 $idFavorecido = $_regra->getIdFavorecido();
             }
             //$vlrTotal
             if ($_regra->getVlrFixo()->toPhp() > 0) {
                 $vlrLanc = $_regra->getVlrFixo();
             } else {
                 if ($_regra->getVlrPerc()->toPhp() > 0) {
                     $vlrLanc = $vlrTotal * $_regra->getVlrPerc()->toPhp() / 100;
                 } else {
                     $vlrLanc = 0;
                 }
             }
             if ($idFavorecido) {
                 $_lancamento->newRow()->setTipo('D')->setIdContrato($_regra->getIdContrato())->setIdFavorecido($idFavorecido)->setDescricao($desc)->setObservacao('PEDIDO DE VENDA: ' . $_pedido->getNumero()->get())->setPago('N')->setDtLanc($dtVenc)->setVlrLanc($vlrLanc)->insert();
                 $_itemLanc->newRow()->setIdItemPedido($_itens->getId())->setIdLancamento($_lancamento->getId())->insert();
                 if (!$pago) {
                     $_lancamento->newRow()->setTipo('C')->setIdContrato($_regra->getIdContrato())->setIdFavorecido($idFavorecido)->setDescricao($desc)->setObservacao('CUSTEADO PELO CLIENTE')->setPago('S')->setDtLanc($dtVenc)->setVlrLanc($vlrLanc)->insert();
                     $_itemLanc->newRow()->setIdItemPedido($_itens->getId())->setIdLancamento($_lancamento->getId())->insert();
                 }
             }
         }
     }
 }
示例#3
0
文件: Mapper.php 项目: rtsantos/mais
 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());
         }
     }
 }