JA
Erro ao salvar parcelas. acredito que seja store();
Olá, boa tarde!
Preciso de ajuda galera por gentileza!
Estou desenvolvendo um sistema para um curso de inglês, temos a parte de cobrança que geramos 6 parcelas já consigo gerar mais venho tendo problemas para salvar.
Já fiz um print_r($detail); e var_dump($detail); ambos retorna as informações que preciso para salvar eu desconfio que seja o
// stores the object in the database
//$detail->store();
pois quando removo ele a pagina carrega sem erro quando coloco a pagina não carrega.
obs: botão gerar parcela ele gera e salva ao mesmo tempo.
log.txt :
print_r($detail); :
control - AlunoForm.class.php - Acho que o erro está no store
model - SystemAlunoForm.class.php
model - SystemAlunoParcelaForm.class.php
Att,
Jonathas Alves
Preciso de ajuda galera por gentileza!
Estou desenvolvendo um sistema para um curso de inglês, temos a parte de cobrança que geramos 6 parcelas já consigo gerar mais venho tendo problemas para salvar.
Já fiz um print_r($detail); e var_dump($detail); ambos retorna as informações que preciso para salvar eu desconfio que seja o
// stores the object in the database
//$detail->store();
pois quando removo ele a pagina carrega sem erro quando coloco a pagina não carrega.
obs: botão gerar parcela ele gera e salva ao mesmo tempo.
log.txt :
Debug: 2018-04-08 12:47:19 - SELECT * FROM system_aluno_parcela WHERE (aluno_id = '1')
Debug: 2018-04-08 12:47:19 - SELECT * FROM system_aluno_parcela WHERE (id = '919249092')
Debug: 2018-04-08 12:47:19 - SELECT * FROM system_aluno_parcela WHERE (id = '914038784')
Debug: 2018-04-08 12:47:19 - SELECT * FROM system_aluno_parcela WHERE (id = '916542239')
Debug: 2018-04-08 12:47:19 - SELECT * FROM system_aluno_parcela WHERE (id = '914410275')
Debug: 2018-04-08 12:47:19 - SELECT * FROM system_aluno_parcela WHERE (id = '917556450')
Debug: 2018-04-08 12:47:19 - SELECT * FROM system_aluno_parcela WHERE (id = '915868346')
print_r($detail); :
stdClass Object ( [aluno_id] => 1 [numero_document] => 919249092 [name] => GUILHERME SANTA BARBARA SANTOS [plano_pagamento_nome] => KIDS 1 [nomeResp] => JONATHAS ALVES SANTOS [cpfResp] => 035.696.905-39 [numero_parcela] => 1/6 [vencimento] => 09/06/2005 [valor_boleto] => 266.67 [status_pagamento_id] => PENDENTE )
stdClass Object ( [aluno_id] => 1 [numero_document] => 914038784 [name] => GUILHERME SANTA BARBARA SANTOS [plano_pagamento_nome] => KIDS 1 [nomeResp] => JONATHAS ALVES SANTOS [cpfResp] => 035.696.905-39 [numero_parcela] => 2/6 [vencimento] => 09/07/2005 [valor_boleto] => 266.67 [status_pagamento_id] => PENDENTE )
stdClass Object ( [aluno_id] => 1 [numero_document] => 916542239 [name] => GUILHERME SANTA BARBARA SANTOS [plano_pagamento_nome] => KIDS 1 [nomeResp] => JONATHAS ALVES SANTOS [cpfResp] => 035.696.905-39 [numero_parcela] => 3/6 [vencimento] => 09/08/2005 [valor_boleto] => 266.67 [status_pagamento_id] => PENDENTE )
stdClass Object ( [aluno_id] => 1 [numero_document] => 914410275 [name] => GUILHERME SANTA BARBARA SANTOS [plano_pagamento_nome] => KIDS 1 [nomeResp] => JONATHAS ALVES SANTOS [cpfResp] => 035.696.905-39 [numero_parcela] => 4/6 [vencimento] => 09/09/2005 [valor_boleto] => 266.67 [status_pagamento_id] => PENDENTE )
stdClass Object ( [aluno_id] => 1 [numero_document] => 917556450 [name] => GUILHERME SANTA BARBARA SANTOS [plano_pagamento_nome] => KIDS 1 [nomeResp] => JONATHAS ALVES SANTOS [cpfResp] => 035.696.905-39 [numero_parcela] => 5/6 [vencimento] => 09/10/2005 [valor_boleto] => 266.67 [status_pagamento_id] => PENDENTE )
stdClass Object ( [aluno_id] => 1 [numero_document] => 915868346 [name] => GUILHERME SANTA BARBARA SANTOS [plano_pagamento_nome] => KIDS 1 [nomeResp] => JONATHAS ALVES SANTOS [cpfResp] => 035.696.905-39 [numero_parcela] => 6/6 [vencimento] => 09/11/2005 [valor_boleto] => 266.65 [status_pagamento_id] => PENDENTE )
control - AlunoForm.class.php - Acho que o erro está no store
- <?php
- /*
- * Função de Gerar parcelas
- * - Desenvolvido Jonathas Alves Santos
- */
- function onGerarParcelas($param)
- {
- try {
- // abri uma transação com banco de dados 'db_guiansoft'
- TTransaction::open('db_guiansoft');
- // Ativar o log de depuração para operações SQL dentro da transação
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- // read the form data and instantiates an Active Record
- $system_aluno = new SystemAluno;
- $system_aluno->fromArray( $param );
- $system_aluno->clearParts();
- // delete details
- $old_parcelas = SystemAlunoParcela::where('aluno_id', '=', $system_aluno->id)->load();
- $keep_parcelas = array();
- // get session items
- $items = TSession::getValue(__CLASS__ . '_parcelas');
- if ($items) {
- foreach ($items as $item) {
- if (substr($item->id, 0, 1) == 'X') { // new record
- $detail = new SystemAlunoParcela;
- } else {
- $detail = SystemAlunoParcela::find($item->id);
- }
- $detail->aluno_id = $system_aluno->id;
- $detail->numero_document = $item->id;
- $detail->name = $item->name;
- $detail->plano_pagamento_nome = $item->plano_pagamento_nome;
- $detail->nomeResp = $item->nomeResp;
- $detail->cpfResp = $item->cpfResp;
- $detail->numero_parcela = $item->numero_parcela;
- $detail->vencimento = $item->vencimento;
- $detail->valor_boleto = $item->valor_boleto;
- $detail->status_pagamento_id = $item->status_pagamento_id;
- print_r($detail);
- }
- }
- if ($old_parcelas) {
- foreach ($old_parcelas as $old_parcela) {
- if (!in_array($old_parcela->id, $keep_parcelas)) {
- $old_parcela->delete();
- }
- }
- }
- // stores the object in the database
- //$detail->store();
- $this->datagrid->clear(); // limpa a grid
- $this->form->validate(); // verifica os campos obrigatorios e faz a validação
- // recebe dados informado pelo usuário
- $nomeResp = $param['nomeResp'];
- $cpfResp = $param['cpfResp'];
- $logradouroResp = $param['logradouroResp'];
- $numeroResp = $param['numeroResp'];
- $bairroResp = $param['bairroResp'];
- $cepResp = $param['cepResp'];
- $cidadeResp = $param['cidadeResp'];
- $ufResp = $param['ufResp'];
- $name = $param['name'];
- $DataPrimeiraParcela = $param['vencimento'];
- $plano_pagamento_nome = $param['plano_pagamento_nome'];
- $total = ($param['valor_boleto']);
- $prazo = $param['parcela'];
- $status = $param['status_pagamento_id'];
- // chama a função que realiza o calculo da divisão e tbm realiza o calculo dos dos vencimentos - retorna um array
- $parcelas = GerarParcelas::calcularParcelas($total, $prazo, $DataPrimeiraParcela, $nomeResp, $cpfResp, $logradouroResp, $numeroResp, $bairroResp, $cepResp, $cidadeResp, $plano_pagamento_nome, $ufResp, $name, $status, null);
- // armazena as parcelas sem uma variavel de sessão
- TSession::setValue(__CLASS__ . '_parcelas', $parcelas);
- // laço onde add na grid a divisão - os centavos são adicionados na ultima parcela
- foreach ($parcelas as $parcela) {
- // adiciona as parcelas na grid
- $item = new StdClass;
- $item->detail_id = empty($parcela->detail_id) ? 'X' . mt_rand(10000000, 19999999) : $parcela->detail_id;
- $item->id = $parcela->id;
- $item->numero_documento = $parcela->id;
- $item->nomeResp = $parcela->nomeResp;
- $item->cpfResp = $parcela->cpfResp;
- $item->logradouroResp = $parcela->logradouroResp;
- $item->numeroResp = $parcela->numeroResp;
- $item->bairroResp = $parcela->bairroResp;
- $item->cepResp = $parcela->cepResp;
- $item->cidadeResp = $parcela->cidadeResp;
- $item->ufResp = $parcela->ufResp;
- $item->name = $parcela->name;
- $item->parcela = $parcela->numero_parcela;
- $item->plano_pagamento_nome = $parcela->plano_pagamento_nome;
- $item->valor_boleto = ($parcela->valor_boleto);
- $item->vencimento = $parcela->vencimento;
- $item->status_pagamento_id = $parcela->status_pagamento_id;
- $this->datagrid->addItem($item);
- }
- // mantem os dados no form
- TTransaction::close(); // close the transaction
- $data = new stdClass;
- $data->id = $system_aluno->id;
- TForm::sendData('form_aluno', $data);
- $this->onEdit(array('key' => $barcode->id)); // reload form and session items
- $this->form->setData($this->form->getData());
- $this->datagrid->getItems;
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- } catch (Exception $ex) {
- new TMessage('error', 'ma oee ' . $ex->getMessage());
- TTransaction::rollback();
- }
- }
- ?>
model - SystemAlunoForm.class.php
- <?php
- /**
- * SystemUser
- *
- * @version 1.0
- * @package model
- * @subpackage admin
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class SystemAluno extends TRecord
- {
- const TABLENAME = 'system_aluno';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'max'; // {max, serial}
- private $system_aluno_turmas;
- private $details;
- public function __construct($id = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct($id, $callObjectLoad);
- parent::addAttribute('name');
- parent::addAttribute('photo_path');
- parent::addAttribute('nomeResp');
- parent::addAttribute('rg');
- parent::addAttribute('rgResp');
- parent::addAttribute('cpf');
- parent::addAttribute('cpfResp');
- parent::addAttribute('nomePai');
- parent::addAttribute('nomeMae');
- parent::addAttribute('nascimento');
- parent::addAttribute('nascimentoResp');
- parent::addAttribute('genero_id');
- parent::addAttribute('generoRespId');
- parent::addAttribute('cep');
- parent::addAttribute('cepResp');
- parent::addAttribute('logradouro');
- parent::addAttribute('logradouroResp');
- parent::addAttribute('numero');
- parent::addAttribute('numeroResp');
- parent::addAttribute('complemento');
- parent::addAttribute('complementoResp');
- parent::addAttribute('bairro');
- parent::addAttribute('bairroResp');
- parent::addAttribute('cidade');
- parent::addAttribute('cidadeResp');
- parent::addAttribute('uf');
- parent::addAttribute('ufResp');
- parent::addAttribute('celular');
- parent::addAttribute('celPai');
- parent::addAttribute('celMae');
- parent::addAttribute('celularResp');
- parent::addAttribute('telefone');
- parent::addAttribute('telefoneResp');
- parent::addAttribute('emailResp');
- parent::addAttribute('tipoSanguineo');
- parent::addAttribute('alergia');
- parent::addAttribute('problemaSaude');
- parent::addAttribute('chamarUrgencia');
- parent::addAttribute('desconto');
- parent::addAttribute('empresaResp');
- parent::addAttribute('profissao_id');
- parent::addAttribute('endProfissional');
- parent::addAttribute('telProfissional');
- parent::addAttribute('data_matricula');
- parent::addAttribute('login');
- parent::addAttribute('password');
- parent::addAttribute('email');
- parent::addAttribute('frontpage_id');
- parent::addAttribute('system_unit_id');
- parent::addAttribute('active');
- parent::addAttribute('periodo_id');
- parent::addAttribute('vencimento');
- }
- /**
- * Reset aggregates
- */
- public function clearParts()
- {
- $this->system_aluno_turmas = array();
- }
- /**
- * Composition with Item
- */
- public function addSystemAlunoTurma(SystemAlunoTurma $system_aluno_turma)
- {
- $this->system_aluno_turmas[] = $system_aluno_turma;
- }
- /**
- * Return Items composition
- */
- public function getSystemAlunoTurmas()
- {
- return $this->system_aluno_turmas;
- }
- /**
- * Load the object and the aggregates
- */
- public function load($id)
- {
- $system_aluno_turma_rep = new TRepository('SystemAlunoTurma');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('aluno_id', '=', $id));
- // load the Item composition
- $system_aluno_turmas = $system_aluno_turma_rep->load($criteria);
- if ($system_aluno_turmas)
- {
- foreach ($system_aluno_turmas as $system_aluno_turma)
- {
- //$system_aluno_turma = new SystemAlunoTurma($system_aluno_turma-> id);
- $this->addSystemAlunoTurma($system_aluno_turma);
- }
- }
- // load the object itself
- return parent::load($id);
- }
- /**
- * Stores the book and the aggregates (authors, subjects, items)
- */
- public function store()
- {
- // stores the Book
- parent::store();
- // delete the aggregates
- $criteria = new TCriteria;
- $criteria->add(new TFilter('aluno_id', '=', $this->id));
- $repository = new TRepository('SystemAlunoParcela');
- $repository->delete($criteria);
- // store the system_aluno_turmas
- if ($this->details)
- {
- foreach ($this->details as $detail)
- {
- $detail-> aluno_id = $this-> id;
- $detail->store();
- }
- }
- // collect persistent item ids
- if ($this->system_aluno_turmas)
- {
- foreach ($this->system_aluno_turmas as $system_aluno_turma)
- {
- if ($system_aluno_turma->id)
- {
- $system_aluno_turma_ids[] = $system_aluno_turma->id;
- }
- }
- }
- if (!empty($system_aluno_turma_ids))
- {
- // delete all items, except for those that persist
- $criteria->add(new TFilter('id', 'NOT IN', $system_aluno_turma_ids));
- }
- $repository = new TRepository('SystemAlunoTurma');
- $repository->delete($criteria);
- // store the system_aluno_turmas
- if ($this->system_aluno_turmas)
- {
- foreach ($this->system_aluno_turmas as $system_aluno_turma)
- {
- $system_aluno_turma-> aluno_id = $this-> id;
- $system_aluno_turma->store();
- }
- }
- }
- /**
- * Delete the book and its aggregates
- */
- public function delete($id = NULL)
- {
- $id = isset($id) ? $id : $this->{'id'};
- SystemAlunoTurma::where('aluno_id', '=', $id)->delete();
- // delete the object itself
- parent::delete($id);
- }
- /**
- * Retorna periodo
- */
- public function get_SystemStatusPagamento()
- {
- return SystemStatusPagamento::find($this->status_pagamento_id);
- }
- /**
- * Retorna periodo
- */
- public function get_SystemPeriodo()
- {
- return SystemPeriodo::find($this->periodo_id);
- }
- }
- ?>
model - SystemAlunoParcelaForm.class.php
- <?php
- /**
- * System_aluno_turma Active Record
- * @author <Jonathas Alves Santos>
- */
- class SystemAlunoParcela extends TRecord
- {
- const TABLENAME = 'system_aluno_parcela';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'max'; // {max, serial}
- private $system_aluno;
- /**
- * Returns the Item from its numero_documento
- */
- public static function newFromNumeroDocumento($numero_documento)
- {
- $rep = new TRepository('SystemAlunoParcela');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('numero_documento', '=', $numero_documento));
- $objects = $rep->load($criteria);
- if ($objects)
- {
- $detail = $objects[0];
- return $detail;
- }
- }
- }
- ?>
Att,
Jonathas Alves
Jonathas, qual o erro ele apresenta?
Boa boite Marcelo Gomes!
Salva sem apresentar erro, mais não grava nada no banco.
Jonathas, talvez precise do código completo para analisar. Mas vou tentar recriar o seu cenário para ver o que poderia ser.
Este código foi gerado pelo Studio?
olá, boa noite! Marcelo não foi gerado pelo studio.
Onde vc colocou "print", troque por $detail->store().
Pelo que entendi do seu código, o mesmo deveria ser salvo a cada iteração, não é isso?
Foi isso que você fez?
Por que no primeiro print que passou, o "store" estava fora do laço.
Outra dúvida: você sobrescreveu o "store" do TRecord?
Coloquei o store veja o log de erro
veja tbm minha model
e a model da parcelas
</Jonathas>
Jonathas
O erro é claro, o método "store" não existe para o objeto "$detail" no método "onGerar...".
Tem muito conteúdo na tela fica difícil navegar. Revise este objeto. veja se ele está sendo instanciado corretamente.
O método "store" é herdado de um Model estendido de um TRecord.
No momento que chama "store", $detail não é um objeto da Classe: SystemAlunoParcela.
Olá, consegui resolver o problema !
Obrigado!