protected function _getSqlBase() { $idPedido = Zend_Controller_Front::getInstance()->getRequest()->getParam('id_pedido'); $idCliente = Zend_Controller_Front::getInstance()->getRequest()->getParam('id_cliente'); if ($this->_idClienteCon) { $idCliente = $this->_idClienteCon; } if (!$idCliente) { if ($idPedido) { $_pedido = new Vendas_DataView_Pedido_MapperView(); $_pedido->setId($idPedido)->retrieve(); $idCliente = $_pedido->getIdClienteCon(true)->toPhp(); if ($idCliente) { $idCliente = $_pedido->getIdCliente(true)->toPhp(); } } if (!$idCliente) { $idCliente = 0; } } $hoje = ZendT_Type_Date::nowDate()->getValueToDb(); $sql = parent::_getSqlBase(); $sql .= " LEFT JOIN " . Ca_DataView_Contrato_MapperView::$table . " contrato ON ('" . $hoje . "' BETWEEN contrato.dt_vig_ini AND contrato.dt_vig_fim AND contrato.status = 'A' AND contrato.id_cliente = " . $idCliente . ") "; $sql .= " LEFT JOIN " . Ca_DataView_RegraContrato_MapperView::$table . " regra_contrato ON (regra_contrato.id_produto = cv_produto.id AND regra_contrato.status = 'A' AND regra_contrato.tipo IN ('PA','PD') ) "; return $sql; }
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); } }
public function diaAction() { $this->_disableRender(true, false); $_mapper = $this->getMapper(); $_mapper->setDtExibe(ZendT_Type_Date::nowDate()); $recordset = $_mapper->recordset($_mapper->getWhere(), false, false, 'sigla_filial'); $data = array(); while ($row = $recordset->getRow()) { $data[] = $row; } $this->view->data = $data; }
public function processLanc() { $_lancamentos = new Financeiro_DataView_Lancamento_MapperView(); $_where = new ZendT_Db_Where(); $_where->addFilter('fc_lancamento.dt_lanc', ZendT_Type_Date::nowDate(), '<='); if (Auth_Session_User::getInstance()->getIdEmpresa()) { $_where->addFilter('fc_lancamento.id_empresa', Auth_Session_User::getInstance()->getIdEmpresa()); } $_where->addFilter('fc_lancamento.vlr_saldo', '', '=', '', true); $_lancamentos->findAll($_where); while ($_lancamentos->fetch()) { $_lancamentos->update(); } }
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(); } } } } }
protected function _consultorias($dtIni = '', $dtFim = '', $placa = '') { if (!$dtIni) { $dtIni = ZendT_Type_Date::nowDate()->addDay(-3)->getValueToDb(); } if (!$dtFim) { $dtFim = ZendT_Type_Date::nowDate()->getValueToDb(); } $params = array(); $params['header']['Authorization'] = 'bearer ' . $this->_token; $params['get']['Placa'] = $placa; $params['get']['DataInicio'] = $dtIni; $params['get']['DataFim'] = $dtFim; #echo print_r($params); #echo "\n <br>"; $result = $this->_request('https://servicos.vistoriasp.com.br/ECVCommunicationService/api/vistoria/consultaVistoria', $params, Zend_Http_Client::GET); #print_r($result); return $result; }
/** * Salva o arquivo no diretório e na tabela (inclui / altera) * * @param ZendT_File $file - arquivo * @param array $configs - configurações de propriedades do arquivo * @param array $param - propriedades do arquivo * @return integer - id do arquivo salvo */ private function _saveFile($file, $configs, &$param) { $_propDocto = $this->_getPropDocto($param->propName); $param->fileName = $file->getName(); $fileContent = $file->getContent(); $fileType = $file->getContentType(); $hashCode = md5($fileContent); $fileName = $this->_formatFileName($hashCode, $param->fileName); $propName = $param->propName; $dtExpira = ''; $_arquivo = new Ged_DataView_Arquivo_MapperView(); $_arquivo->setHashcode($hashCode); $path = $this->getFilePath($configs['bkpProp'], $propName, $fileName); $_arquivo->setPathArq($path['path']); if (!$_arquivo->exists()) { #$_arquivo->setPathArq($path['path']); } else { $_arquivo_aux = clone $_arquivo; $dtExpira = $_arquivo_aux->retrieve()->getDtExpira()->toPhp(); } if ($configs['lifeTime'] && !$dtExpira) { $dtExpira = ZendT_Type_Date::nowDate()->addDay($configs['lifeTime']); $_arquivo->setDtExpira($dtExpira); } $_arquivo->setConteudoName($param->fileName); $_arquivo->setIdPropDocto($_propDocto->getId()); $_arquivo->setConteudoType($fileType); if ($configs['bkpProp'] == 2 && $param->fileId) { $_arquivo->setId($param->fileId); $_arquivo_aux = new Ged_DataView_Arquivo_MapperView(); $_arquivo_aux->setId($_arquivo->getId()); if ($_arquivo_aux->exists()) { $_arquivo_aux->retrieve(); if ($_arquivo_aux->getHashCode()->toPhp() != $_arquivo->getHashcode()->toPhp()) { $this->remove($_arquivo->getId(), false); $_arquivo->update(); //$path_aux = $this->_getArquivoPath($_arquivo->getId()->toPhp()); } } } $idArquivo = $_arquivo->save(true); //echo "Path: " . $path['full'] . "\n"; if (!file_exists($path['full'])) { if (!file_exists($path['pathBase'])) { //mkdir($path['pathBase'], null, true); $this->mkdirRecursive($path['pathBase']); } $result = file_put_contents($path['full'], $file->getContent()); if (!$result) { throw new ZendT_Exception('Erro ao armazenar o arquivo no servidor "' . $path['full'] . '". Erro: "' . $php_errormsg . '" '); } if (!$result) { throw new ZendT_Exception('Não foi possível salvar o arquivo "' . $path['full'] . '"'); } else { if ($this->_config['linux']) { $this->_execCmd("chmod 777 {$path['full']} -R"); } } } if ($param->parentId) { $_docto = new Ged_DataView_Docto_MapperView(); $_docto->setIdPropRelac($param->parentId); $_docto->setDescricao($param->desc); $_docto->setDhInclusao("SYSDATE"); $_docto->setIdArquivo($idArquivo); $_docto->setIdTipoDocto($param->typeId); $_docto->setIdUsuIncl($param->userId); $idDocto = $_docto->save(); } return $idArquivo; }