JA
Apagando registro anterior
Olá, boa noite estou com um problema, quando acrescento um novo registro ou edito ele acaba apagando o registro anterior. A ideia é registrar cada ano que o aluno estudou na instituição como periodo, curso, modulo, turma e situação do aluno na turma.
model
- <?php
- /**
- * SystemAlunoForm Registration
- * @author Jonathas Alves Santos
- */
- class AlunoForm extends TPage
- {
- private $frame;
- protected $form; // form
- protected $turmas_list;
- protected $formgrid;
- protected $formFields;
- protected $datagrid;
- /**
- * - Class constructor
- * - Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Aluno');
- $this->form->setFormTitle(('Aluno'));
- // create the form fields aluno
- $id = new TEntry('id');
- $matricula = new TEntry('matricula');
- $name = new TEntry('name');
- $genero_id = new TDBCombo('genero_id','db_guiansoft','SystemGenero','id','nome');
- $nascimento = new TDate('nascimento');
- $rg = new TEntry('rg');
- $cpf = new TEntry('cpf');
- $logradouro = new TEntry('logradouro');
- $cep = new TEntry('cep');
- $numero = new TEntry('numero');
- $bairro = new TEntry('bairro');
- $cidade = new TEntry('cidade');
- $uf = new TEntry('uf');
- $complemento = new TEntry('complemento');
- $celular = new TEntry('celular');
- $celPai = new TEntry('celPai');
- $celMae = new TEntry('celMae');
- $telefone = new TEntry('telefone');
- $email = new TEntry('email');
- $tipoSanguineo = new TEntry('tipoSanguineo');
- $alergia = new TEntry('alergia');
- $problemaSaude = new TEntry('problemaSaude');
- $chamarUrgencia = new TEntry('chamarUrgencia');
- $nomePai = new TEntry('nomePai');
- $nomeMae = new TEntry ('nomeMae');
- $photo_path = new TFile('photo_path');
- $data_matricula = new TDate('data_matricula');
- $data_matricula->setValue(date('Y-m-d'));
- $nomeResp = new TEntry('nomeResp');
- $generoRespId = new TDBCombo('generoRespId','db_guiansoft','SystemGenero','id','nome');
- $nascimentoResp = new TDate('nascimentoResp');
- $rgResp = new TEntry('rgResp');
- $cpfResp = new TEntry('cpfResp');
- $logradouroResp = new TEntry('logradouroResp');
- $cepResp = new TEntry('cepResp');
- $numeroResp = new TEntry('numeroResp');
- $bairroResp = new TEntry('bairroResp');
- $cidadeResp = new TEntry('cidadeResp');
- $ufResp = new TEntry('ufResp');
- $complementoResp = new TEntry('complementoResp');
- $celularResp = new TEntry('celularResp');
- $telefoneResp = new TEntry('telefoneResp');
- $emailResp = new TEntry('emailResp');
- $empresaResp = new TEntry('empresaResp');
- $profissao_id = new TDBCombo('profissao_id','db_guiansoft','SystemProfissao','id','nome');
- $endProfissional = new TEntry ('endProfissional');
- $telProfissional = new TEntry ('telProfissional');
- $vencimento = new TDate('vencimento');
- $desconto = new TEntry('desconto');
- $periodoc_id = new TDBCombo('periodoc_id','db_guiansoft','SystemPeriodo','id','nome');
- $periodos_id = new TDBCombo('periodos_id','db_guiansoft','SystemPeriodo','id','nome');
- $plano_pagamento_id = new ">TDBSeekButton('plano_pagamento_id', 'db_guiansoft', $this->form->getName(), 'SystemPlanoPagamento', 'nome', 'plano_pagamento_id', 'plano_pagamento_nome');
- $plano_pagamento_nome = new TEntry('plano_pagamento_nome');
- $numero_documento = new TEntry('numero_documento');
- $parcela = new TEntry('parcela');
- $valor_boleto = new TEntry('valor_boleto');
- $status_pagamento_id = new TDBCombo('status_pagamento_id','db_guiansoft','SystemStatusPagamento','id','nome');
- $status_pagamentos_id = new TDBCombo('status_pagamentos_id','db_guiansoft','SystemStatusPagamento','id','nome');
- $btnCep = new TButton('action1');
- $btnRespCep = new TButton('action2');
- $btn = $this->form->addAction( _t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addAction( _t('Clear'), new TAction(array($this, 'onEdit')), 'fa:eraser red');
- $this->form->addAction( ('Gerar Parcelas'), new TAction(array($this, 'onGerarParcelas')), 'fa:hand-o-down');
- $this->form->addAction( _t('Back'), new TAction(array('AlunoList','onReload')), 'fa:arrow-circle-o-left blue');
- // complete upload action
- $photo_path->setCompleteAction(new TAction(array($this, 'onComplete')));
- $photo_path->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->datatable = 'true';
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->setHeight(320);
- $hbox1 = new THBox;
- $hbox1->style = 'margin: 4px';
- $vbox1 = new TVBox;
- $vbox1->style='width:100%';
- $vbox1->add( $hbox1 );
- $vbox1->add($this->datagrid);
- // creates the datagrid columns
- $column_id = new TDataGridColumn('id', 'Código', 'center');
- $column_numero_documento = new TDataGridColumn('numero_documento', 'Num. Documento', 'center');
- $column_nomeResp = new TDataGridColumn('nomeResp', 'Responsável', 'center');
- $column_parcela = new TDataGridColumn('parcela', 'Parcelas', 'center');
- $column_vencimento = new TDataGridColumn('vencimento', ('Vencimento'), 'left');
- $column_valor_boleto = new TDataGridColumn('valor_boleto', ('Valor'), 'left');
- $column_status_pagamento_id = new TDataGridColumn('status_pagamento_id', ('Status'), 'left');
- // add the columns to the DataGrid
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_numero_documento);
- $this->datagrid->addColumn($column_nomeResp);
- $this->datagrid->addColumn($column_parcela);
- $this->datagrid->addColumn($column_vencimento);
- $this->datagrid->addColumn($column_valor_boleto);
- $this->datagrid->addColumn($column_status_pagamento_id);
- // creates two datagrid actions
- $action1 = new TDataGridAction(array($this, 'deleteBoleto'));
- $action1->setLabel('Baixa Manual');
- $action1->setImage('fa:download blue');
- $action1->setField('id');
- $action2 = new TDataGridAction(array( 'BoletoView', 'onGenerate'));
- $action2->setLabel('Imprimir Boleto');
- $action2->setImage('fa:barcode');
- $action2->setFields(['nosso_numero', 'numero_documento', 'plano_pagamento_nome', 'nomeResp', 'logradouroResp', 'numeroResp', 'cpfResp', 'bairroResp', 'cepResp', 'cidadeResp', 'ufResp', 'name', 'parcela', 'vencimento', 'valor_boleto']);
- $action3 = new TDataGridAction(array($this, 'onTeste'));
- $action3->setLabel('Editar');
- $action3->setImage('fa:pencil-square-o blue fa-lg');
- $action3->setField('id');
- $action4 = new TDataGridAction(array($this, 'deleteBoleto'));
- $action4->setLabel('Delete');
- $action4->setImage('fa:trash-o red fa-lg');
- $action4->setField('id');
- $action_group = new TDataGridActionGroup('Ações', 'bs:th');
- $action_group->addHeader('Available Options');
- $action_group->addAction($action1);
- $action_group->addAction($action2);
- $action_group->addSeparator();
- $action_group->addHeader('Another Options');
- $action_group->addAction($action3);
- $action_group->addAction($action4);
- // add the actions to the datagrid
- $this->datagrid->addActionGroup($action_group);
- // creates the datagrid model
- $this->datagrid->createModel();
- // define the button action
- $btnCep->setAction(new TAction(array($this, 'onCep')), 'Busca');
- $btnCep->setImage('fa:map-marker green');
- $btnCep->class = 'btn btn-sm btn-primary';
- // define the button action
- $btnRespCep->setAction(new TAction(array($this, 'onRespCep')), 'Busca');
- $btnRespCep->setImage('fa:map-marker green');
- $btnRespCep->class = 'btn btn-sm btn-primary';
- // DEFINE TAMANHO
- $id->setSize('100%');
- $matricula->setSize('100%');
- $name->setSize('100%');
- $genero_id->setSize('100%');
- $nascimento->setSize('100%');
- $rg->setSize('100%');
- $cpf->setSize('100%');
- $logradouro->setSize('100%');
- $numero->setSize('100%');
- $bairro->setSize('100%');
- $cep->setSize('100%');
- $cidade->setSize('100%');
- $uf->setSize('100%');
- $complemento->setSize('100%');
- $celular->setSize('100%');
- $celPai->setSize('100%');
- $celMae->setSize('100%');
- $telefone->setSize('100%');
- $photo_path->setSize('100%');
- $btnCep->setSize('100%');
- $tipoSanguineo->setSize('100%');
- $alergia->setSize('100%');
- $problemaSaude->setSize('100%');
- $chamarUrgencia->setSize('100%');
- $nomePai->setSize('100%');
- $nomeMae->setSize('100%');
- $nomeResp->setSize('100%');
- $generoRespId->setSize('100%');
- $nascimentoResp->setSize('100%');
- $rgResp->setSize('100%');
- $cpfResp->setSize('100%');
- $logradouroResp->setSize('100%');
- $numeroResp->setSize('100%');
- $bairroResp->setSize('100%');
- $cepResp->setSize('100%');
- $cidadeResp->setSize('100%');
- $ufResp->setSize('100%');
- $complementoResp->setSize('100%');
- $celularResp->setSize('100%');
- $telefoneResp->setSize('100%');
- $emailResp->setSize('35%');
- $empresaResp->setSize('100%');
- $profissao_id->setSize('100%');
- $endProfissional->setSize('100%');
- $telProfissional->setSize('100%');
- $data_matricula->setSize('100%');
- $vencimento->setSize('100%');
- $desconto->setSize('100%');
- $periodoc_id->setSize('100%');
- $plano_pagamento_id->setSize('80');
- $plano_pagamento_nome->setSize('calc(100% - 80px)');
- $numero_documento->setSize('100%');
- $parcela->setSize('100%');
- $valor_boleto->setSize('100%');
- $status_pagamento_id->setSize('100%');
- $periodos_id->setSize('100%');
- $status_pagamentos_id->setSize('100%');
- $email->setSize('100%');
- $id->setEditable(false);
- $matricula->setEditable(false);
- $plano_pagamento_nome->setEditable(false);
- // DEFINIÇÃO DE MASCARA
- $cpf->setMask('000.000.000-00');
- $cpfResp->setMask('000.000.000-00');
- $cep->setMask('00000-000');
- $cepResp->setMask('00000-000');
- $celular->setMask('(00)00000-0000');
- $celPai->setMask('(00)00000-0000');
- $celMae->setMask('(00)00000-0000');
- $celularResp->setMask('(00)00000-0000');
- $telefone->setMask('(00)0000-0000');
- $telefoneResp->setMask('(00)0000-0000');
- //$nascimento->setMask('dd/mm/yyyy');
- //$data_matricula->setMask('dd/mm/yyyy');
- //$nascimentoResp->setMask('dd/mm/yyyy');
- //$vencimento->setMask('dd/mm/yyyy');
- //$nascimento->setDatabaseMask('yyyy-mm-dd');
- //$data_matricula->setDatabaseMask('yyyy-mm-dd');
- //$nascimentoResp->setDatabaseMask('yyyy-mm-dd');
- //$vencimento->setDatabaseMask('yyyy-mm-dd');
- // CAMPOS OBRIGATORIOS
- $email->addValidation('Email', new TEmailValidator);
- $this->form->appendPage('Aluno');
- // SEPARAR
- $this->form->addFields( [new TFormSeparator(('Dados do Aluno'))] );
- $this->form->addFields([new TLabel('Código:')], [$id], [new TLabel(('Matricula:'))], [$matricula]);
- $this->form->addFields([new TLabel(('Nome:'))], [$name]);
- $this->form->addFields([new TLabel('Gênero:')], [$genero_id], [new TLabel('Nascimento:')], [$nascimento]);
- $this->form->addFields([new TLabel('CPF:')], [$cpf], [new TLabel('RG:')], [$rg]);
- $this->form->addFields([new TLabel('Tel. Aluno:')], [$telefone], [new TLabel('Cel. Aluno:')], [$celular]);
- $this->form->addFields([new TLabel('Data da Matrícula:')], [$data_matricula], [new TLabel('Foto:')], [$photo_path]);
- $this->frame = new TElement('div');
- $this->frame->id = 'photo_path';
- $this->frame->style = 'width:180px;height:auto;min-height:180px;border:1px solid gray;padding:4px;';
- // SEPARAR
- $this->form->addFields( [new TFormSeparator(('Filiação'))] );
- $this->form->addFields([new TLabel('Pai:')], [$nomePai], [new TLabel('Mãe:')], [$nomeMae]);
- $this->form->addFields([new TLabel('Cel. Pai:')], [$celPai], [new TLabel('Cel. Mãe:')], [$celMae]);
- // SEPARAR
- $this->form->addFields( [new TFormSeparator(('Endereço do Aluno'))] );
- $this->form->addFields([new TLabel('CEP:')], [$cep], [$btnCep]);
- $this->form->addFields([new TLabel('Logradouro:')], [$logradouro], [new TLabel('Número:')], [$numero]);
- $this->form->addFields([new TLabel('Complemento:')], [$complemento], [new TLabel('Bairro:')], [$bairro]);
- $this->form->addFields([new TLabel('Cidade:')], [$cidade], [new TLabel('Estado:')], [$uf]);
- $this->form->appendPage('Responsável Financeiro');
- $this->form->addFields([new TLabel('Nome:')], [$nomeResp]);
- $this->form->addFields([new TLabel('Gênero:')], [$generoRespId], [new TLabel('Nascimento:')], [$nascimentoResp]);
- $this->form->addFields([new TLabel('RG:')], [$rgResp], [new TLabel('CPF:')], [$cpfResp]);
- $this->form->addFields([new TLabel('Cel.:')], [$celularResp], [new TLabel('Tel.:')], [$telefoneResp]);
- $this->form->addFields([new TLabel('E-mail:')], [$emailResp]);
- // SEPARAR
- $this->form->addFields( [new TFormSeparator(('Endereço'))] );
- $this->form->addFields([new TLabel('CEP:')], [$cepResp], [$btnRespCep]);
- $this->form->addFields([new TLabel('Logradouro:')], [$logradouroResp], [new TLabel('Complemento:')], [$complementoResp]);
- $this->form->addFields([new TLabel('Número:')], [$numeroResp], [new TLabel('Bairro:')], [$bairroResp]);
- $this->form->addFields([new TLabel('Cidade:')], [$cidadeResp], [new TLabel('Estado:')], [$ufResp]);
- // SEPARAR
- $this->form->addFields( [new TFormSeparator(('Endereço de Trabalho'))] );
- $this->form->addFields([new TLabel('Empresa:')], [$empresaResp], [new TLabel('Profissão:')], [$profissao_id]);
- $this->form->addFields([new TLabel('End. Prof.:')], [$endProfissional], [new TLabel('Tel. Prof.:')], [$telProfissional]);
- // SEPARAR
- $this->form->addFields( [new TFormSeparator(('Dados Finánceiro'))] );
- $this->form->addFields( [new TLabel('Vencimento:')], [$vencimento], [new TLabel('Desconto em %:')], [$desconto]);
- $this->form->appendPage('Ficha Médica');
- $this->form->addFields([new TLabel('Tipo Sanguíneo:')], [$tipoSanguineo], [new TLabel('Alergias:')], [$alergia]);
- $this->form->addFields([new TLabel('Problemas de saúde?')], [$problemaSaude], [new TLabel('Quem chamar para urgência?')], [$chamarUrgencia]);
- // TURMA
- $this->form->appendPage('Turmas');
- $aluno_id = new THidden('aluno_id[]');
- $barcode = new TEntry('barcode[]');
- $periodo_id = new TDBCombo('periodo_id[]','db_guiansoft','SystemPeriodo','id','nome');
- $curso_id = new TDBCombo('curso_id[]','db_guiansoft','SystemCurso','id','nome');
- $modulo_id = new TDBCombo('modulo_id[]','db_guiansoft','SystemModulo','id','nome');
- $turma_id = new TDBCombo('turma_id[]','db_guiansoft','SystemTurma','id','nome');
- $situacao_id = new TDBCombo('situacao_id[]','db_guiansoft','SystemSituacaoAlunoTurma','id','nome');
- // set exit action for input_exit
- $change_action = new TAction(array($this, 'onChangeActionModulo'));
- $modulo_id->setChangeAction($change_action);
- // DEFINE TAMANHO
- $aluno_id->setSize('100%');
- $barcode->setSize(120);
- $periodo_id->setSize('100%');
- $curso_id->setSize('100%');
- $modulo_id->setSize('100%');
- $turma_id->setSize('100%');
- $situacao_id->setSize('100%');
- $this->system_aluno_turmas_list = new TFieldList;
- $this->system_aluno_turmas_list->addField( '<b>'.('ID').'</b>', $aluno_id);
- $this->system_aluno_turmas_list->addField( '<b>'.('Barcode').'</b>', $barcode);
- $this->system_aluno_turmas_list->addField( '<b>'.('Período').'</b>', $periodo_id);
- $this->system_aluno_turmas_list->addField( '<b>'.('Curso').'</b>', $curso_id);
- $this->system_aluno_turmas_list->addField( '<b>'.('Módulo').'</b>', $modulo_id);
- $this->system_aluno_turmas_list->addField( '<b>'.('Turma').'</b>', $turma_id);
- $this->system_aluno_turmas_list->addField( '<b>'.('Situação').'</b>', $situacao_id);
- $this->system_aluno_turmas_list->enableSorting();
- $this->form->addField($aluno_id);
- $this->form->addField($barcode);
- $this->form->addField($periodo_id);
- $this->form->addField($curso_id);
- $this->form->addField($modulo_id);
- $this->form->addField($turma_id);
- $this->form->addField($situacao_id);
- $this->form->addContent( [new TLabel('Turmas')], [$this->system_aluno_turmas_list] );
- // FIM TURMAS
- // COBRANÇA
- $this->form->appendPage('Cobranças');
- $plano_pagamento_id->setExitAction(new TAction(array($this,'onPlanoChange')));
- $this->form->addFields( [new TLabel('Periodo:')], [$periodoc_id] );
- $this->form->addFields( [new TLabel('Plano de pagamento:')], [$plano_pagamento_id, $plano_pagamento_nome], [new TLabel('Parcelas:')], [$parcela] );
- $this->form->addFields( [new TLabel('Valor Total:')], [$valor_boleto], [new TLabel(('Status Pagamento:'))], [$status_pagamento_id] );
- $this->form->addFields( [new TFormSeparator(('Parcelas'))] );
- // BUSCA PARCELA POR PERIODO E STATUS
- $this->form->addFields( [ $lp=new TLabel(('Periodo'))], [$periodos_id], [$ls=new TLabel(('Status Pagamento'))], [$status_pagamentos_id] );
- // DEFINE A COR
- $lp->setFontColor('red');
- $ls->setFontColor('red');
- $this->form->addFields( [$vbox1] );
- // FORMATA O VALOR DA PARCELA NO DATAGRID, NO PADÃO -> R$ 1.000,99
- $format_value = function($value) {
- if (is_numeric($value)) {
- return 'R$ '.number_format($value, 2, ',', '.');
- }
- return $value;
- };
- $column_valor_boleto->setTransformer( $format_value );
- // FIM COBRANÇA
- // wrap the page content
- $container = new TVBox;
- $container->style = 'width: 100%';
- $container->add(new TXMLBreadCrumb('menu.xml', 'AlunoList'));
- $container->add($this->form);
- // add the container to the page
- parent::add($container);
- }
- /**
- * On complete upload photo_path
- */
- public static function onComplete($param)
- {
- new TMessage('info', 'Upload completo: ' . $param['photo_path']);
- copy("tmp/{$param['photo_path']}", "files/fotos/alunos/{$param['photo_path']}");
- // refresh photo_frame
- TScript::create("$('#photo_frame').html('')");
- TScript::create("$('#photo_frame').html(\"<img width='180px' height='180px' src='files/fotos/alunos/{$param['photo_path']}'>\");");
- }
- /*
- * Função de busca de Endereço pelo CEP
- * - Desenvolvido Felipe Olivaes para ajaxbox.com.br
- * - Utilizando WebService de CEP da republicavirtual.com.br
- */
- public static function onCep($param)
- {
- $resultado = @file_get_contents('http://republicavirtual.com.br/web_cep.php?cep=' . urlencode($param['cep']) . '&formato=query_string');
- if (!$resultado) {
- $resultado = "&resultado=0&resultado_txt=erro+ao+buscar+cep";
- }
- parse_str($resultado, $retorno);
- $obj = new StdClass;
- $obj->cep = $param['cep'];
- $obj->logradouro = strtoupper($retorno['tipo_logradouro'] . ' ' . $retorno['logradouro']);
- $obj->bairro = strtoupper($retorno['bairro']);
- $obj->cidade = strtoupper($retorno['cidade']);
- $obj->uf = strtoupper($retorno['uf']);
- TForm::sendData('form_Aluno', $obj);
- }
- /*
- * Função de busca de Endereço pelo CEP
- * - Desenvolvido Felipe Olivaes para ajaxbox.com.br
- * - Utilizando WebService de CEP da republicavirtual.com.br
- */
- public static function onRespCep($param)
- {
- $resultado = @file_get_contents('http://republicavirtual.com.br/web_cep.php?cep=' . urlencode($param['cepResp']) . '&formato=query_string');
- if (!$resultado) {
- $resultado = "&resultado=0&resultado_txt=erro+ao+buscar+cep";
- }
- parse_str($resultado, $retorno);
- $obj = new StdClass;
- $obj->cepResp = $param['cepResp'];
- $obj->logradouroResp = strtoupper($retorno['tipo_logradouro'] . ' ' . $retorno['logradouro']);
- $obj->bairroResp= strtoupper($retorno['bairro']);
- $obj->cidadeResp = strtoupper($retorno['cidade']);
- $obj->ufResp = strtoupper($retorno['uf']);
- TForm::sendData('form_Aluno', $obj);
- }
- /**
- * Action to be executed when the user changes the modulo_id field
- */
- public static function onChangeActionModulo($param)
- {
- TTransaction::open('db_guiansoft');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('modulo_id', '=', $param['modulo_id']));
- $repository = new TRepository('SystemTurma');
- $turmas = $repository->load($criteria);
- $options = array();
- foreach ($turmas as $turma){
- $options[$turma->id] = $turma->nome;
- }
- //TForm::sendData('form_Aluno', $objeto);
- TCombo::reload('form_Aluno', 'turma_id[]', $options);
- }
- /**
- * On product change
- */
- static function onPlanoChange( $params )
- {
- if( isset($params['plano_pagamento_id']) && $params['plano_pagamento_id'] )
- {
- try
- {
- TTransaction::open('db_guiansoft');
- $systemplanopagamento = new SystemPlanoPagamento($params['plano_pagamento_id']);
- $fill_data = new StdClass;
- $fill_data->parcela = $systemplanopagamento->prazo;
- $fill_data->valor_boleto = $systemplanopagamento->valor_total;
- TForm::sendData('form_Aluno', $fill_data);
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }
- /**
- * Reload the item list
- * @param $param URL parameters
- */
- public function onReload($param)
- {
- // read session items
- $parcelas = TSession::getValue(__CLASS__ . '_parcelas');
- $this->datagrid->clear(); // clear detail list
- $data = $this->form->getData();
- if ($system_aluno_parcelas)
- {
- $cont = 1;
- foreach ($system_aluno_parcelas as $parcelas_id => $parcelas)
- {
- $system_aluno_parcela->id = $parcelas['id'];
- $system_aluno_parcela->numero_documento = $parcelas['numero_documento'];
- $system_aluno_parcela->nomeResp = $parcelas['nomeResp'];
- $system_aluno_parcela->parcela = $parcelas['parcela'];
- $system_aluno_parcela->vencimento = $parcelas['vencimento'];
- $system_aluno_parcela->valor_boleto = $parcelas['valor_boleto'];
- $system_aluno_parcela->status_pagamento_id = $parcelas['status_pagamento_id'];
- $row = $this->datagrid->addSystemAlunoParcela( $system_aluno_parcela );
- $row->onmouseover = '';
- $row->onmouseout = '';
- }
- $this->form->setFields( $this->formFields );
- }
- $this->loaded = TRUE;
- }
- /**
- * method onEdit
- * Edit a record data
- */
- function onEdit($param)
- {
- try
- {
- if (isset($param['id'])){
- $id = $param['id']; // OBTÉM O PARÂMETRO $key
- TTransaction::open('db_guiansoft'); // ABRE A TRANSAÇÃO
- $system_aluno = new SystemAluno($param['id']); // INSTANCIA O ACTIVE RECORD
- // load the contacts (composition)
- $system_aluno_turmas = $system_aluno->getSystemAlunoTurmas();
- $system_aluno_parcelas = $system_aluno->getSystemAlunoParcelas();
- if ($system_aluno_parcelas) {
- foreach ($system_aluno_parcelas as $system_aluno_parcela) {
- $system_aluno_parcela->vencimento = DateTime::createFromFormat('Y-m-d', $system_aluno_parcela->vencimento)->format( 'd/m/Y' ); // CONVERTE DATA NO FORMATO d/m/Y PARA A GRID
- $this->datagrid->addItem($system_aluno_parcela); // add the detail inside the datagrid
- }
- }
- // TURMAS
- if ($system_aluno_turmas) {
- $this->system_aluno_turmas_list->addHeader();
- foreach ($system_aluno_turmas as $system_aluno_turma)
- {
- $system_aluno_turma->system_aluno_turma_id = $system_aluno_turma->id;
- $this->system_aluno_turmas_list->addDetail($system_aluno_turma);
- }
- $this->system_aluno_turmas_list->addCloneAction();
- }
- else
- {
- $this->clearSystemAlunoTurmas();
- }
- $this->form->setData($system_aluno); // PREENCHE O FORM
- TTransaction::close(); // FECHA A TRANSAÇÃO
- }
- else {
- $this->onClear($param);
- $this->form->clear();
- TSession::setValue('$system_aluno_parcelas', null);
- $this->onReload( $param );
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- /**
- * Clear Turmas
- */
- public function clearSystemAlunoTurmas()
- {
- $this->system_aluno_turmas_list->addHeader();
- $this->system_aluno_turmas_list->addDetail( new stdClass );
- $this->system_aluno_turmas_list->addCloneAction();
- }
- /**
- * Clear form
- */
- public function onClear()
- {
- $this->form->clear();
- $this->clearSystemAlunoTurmas();
- $this->clearSystemAlunoParcelas();
- TSession::setValue(__CLASS__ . '_parcelas', array());
- $this->onReload($param);
- }
- /**
- * method onSave
- * Executed whenever the user clicks at the save button
- */
- public static function onSave($param)
- {
- try
- {
- // ABRE UMA TRANSAÇÃO COM O BANCO DE DADOS
- TTransaction::open('db_guiansoft');
- // read the form data and instantiates an Active Record
- $system_aluno = new SystemAluno;
- $system_aluno->fromArray( $param );
- $system_aluno->clearParts();
- if( !empty($param['barcode']) AND is_array($param['barcode']) )
- {
- foreach( $param['barcode'] as $row => $barcode)
- {
- if ($barcode)
- {
- $system_aluno_turma = new SystemAlunoTurma;
- $system_aluno_turma->barcode = $barcode;
- $system_aluno_turma->id = $param['aluno_id'][$row];
- $system_aluno_turma->periodo_id = $param['periodo_id'][$row];
- $system_aluno_turma->curso_id = $param['curso_id'][$row];
- $system_aluno_turma->modulo_id = $param['modulo_id'][$row];
- $system_aluno_turma->turma_id = $param['turma_id'][$row];
- $system_aluno_turma->situacao_id = $param['situacao_id'][$row];
- $system_aluno->addSystemAlunoTurma( $system_aluno_turma );
- }
- }
- }
- $system_aluno->store(); // SALAVA O OBJETO
- $data = new stdClass;
- $data->id = $system_aluno->id;
- TForm::sendData('form_aluno', $data);
- // shows the success message
- new TMessage('info', 'Record saved');
- TTransaction::close(); // close the transaction
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /*
- * - Função de Gerar parcelas
- * - Indev (ajuda ate ajudar) kkkk
- */
- function onGerarParcelas($param)
- {
- try {
- // ABRE UMA TRANSAÇÃO COM O BANCO DE DADOS
- TTransaction::open('db_guiansoft');
- // read the form data and instantiates an Active Record
- $system_aluno = new SystemAluno($param['id']);
- $this->datagrid->clear(); // LIMPA A GRID
- $this->form->validate(); // VERIFICA OS CAMPOS OBRIGATORIOS E FAZ A VALIDAÇÃO
- $old_parcelas = SystemAlunoParcela::where('aluno_id', '=', $system_aluno->id)->load();
- $keep_parcelas = array();
- // get session items
- $items = TSession::getValue(__CLASS__ . '_parcelas');
- if (!is_null($items) && ! empty($items)) {
- foreach ($items as $item) {
- if (substr($item->id, 0, 1) == 'X') { // new record
- $system_aluno_parcela = new SystemAlunoParcela;
- // recebe dados informado pelo usuário
- $system_aluno_parcela->fromArray($item) ;
- $system_aluno_parcela->aluno_id = $system_aluno->id;
- $system_aluno_parcela->store(); // salva o objeto
- } else {
- $system_aluno_parcela = new SystemAlunoParcela($item->id);
- echo "ja existe parcelas";
- }
- $keep_parcelas[] = $system_aluno_parcela->id;
- $this->addParcelasAluno($system_aluno,$system_aluno_parcela);;
- }
- TSession::setValue(__CLASS__ . '_parcelas', null);
- }else{
- // 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($param['valor_boleto'],
- $param['parcela'], $param['vencimento'],
- $param['nomeResp'], $param['cpfResp'], $param['logradouroResp'],
- $param['numeroResp'], $param['bairroResp'], $param['cepResp'],
- $param['cidadeResp'], $param['plano_pagamento_nome'], $param['ufResp'],
- $param['name'], $param['status_pagamento_id'], null);
- foreach ($parcelas as $parcela) {
- $this->addParcelasAluno($system_aluno,$parcela); // adciona as parcelas
- }
- // armazena as parcelas sem uma variavel de sessão
- TSession::setValue(__CLASS__ . '_parcelas', $parcelas);
- }
- if ($old_parcelas) {
- foreach ($old_parcelas as $old_item) {
- if (!in_array($old_item->id, $keep_parcelas)) {
- $old_item->delete();
- }
- }
- }
- $parcelas = TSession::getValue(__CLASS__ . '_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->nosso_numero = $parcela->nosso_numero;
- $item->numero_documento = $parcela->numero_documento;
- $item->name = $parcela->name;
- $item->nomeResp = $parcela->nomeResp;
- $item->cpfResp = $parcela->cpfResp;
- $item->cepResp = $parcela->cepResp;
- $item->logradouroResp = $parcela->logradouroResp;
- $item->numeroResp = $parcela->numeroResp;
- $item->bairroResp = $parcela->bairroResp;
- $item->cidadeResp = $parcela->cidadeResp;
- $item->ufResp = $parcela->ufResp;
- $item->parcela = $parcela->parcela;
- $item->vencimento = DateTime::createFromFormat('d/m/Y', $parcela->vencimento)->format( 'Y-m-d' );
- $item->plano_pagamento_nome = $parcela->plano_pagamento_nome;
- $item->valor_boleto = ($parcela->valor_boleto);
- $item->status_pagamento_id = $parcela->status_pagamento_id;
- $this->datagrid->addItem($item);
- }
- $data = new stdClass;
- TForm::sendData('form_aluno', $data);
- $this->form->setData($this->form->getData());
- TTransaction::close(); // close the transaction
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- } catch (Exception $ex) {
- new TMessage('error', 'ma oee ' . $ex->getMessage().' file: '.$ex->getFile().' line: '.$ex->getLine());
- TTransaction::rollback();
- }
- }
- private function addParcelasAluno($system_aluno, $parcela){
- try {
- // abri uma transação com banco de dados 'db_guiansoft'
- TTransaction::open('db_guiansoft');
- $system_aluno_parcela = new SystemAlunoParcela;
- $system_aluno_parcela->nosso_numero = $parcela->nosso_numero;
- $system_aluno_parcela->numero_documento = $parcela->numero_documento;
- $system_aluno_parcela->aluno_id = $system_aluno->id;
- $system_aluno_parcela->name = $parcela->name;
- $system_aluno_parcela->nomeResp = $parcela->nomeResp;
- $system_aluno_parcela->cpfResp = $parcela->cpfResp;
- $system_aluno_parcela->cepResp = $parcela->cepResp;
- $system_aluno_parcela->logradouroResp = $parcela->logradouroResp;
- $system_aluno_parcela->numeroResp = $parcela->numeroResp;
- $system_aluno_parcela->bairroResp = $parcela->bairroResp;
- $system_aluno_parcela->cidadeResp = $parcela->cidadeResp;
- $system_aluno_parcela->ufResp = $parcela->ufResp;
- $system_aluno_parcela->valor_boleto = ($parcela->valor_boleto);
- $system_aluno_parcela->parcela = $parcela->parcela;
- $system_aluno_parcela->plano_pagamento_nome = $parcela->plano_pagamento_nome;
- $system_aluno_parcela->vencimento = DateTime::createFromFormat('d/m/Y', $parcela->vencimento)->format( 'Y-m-d' ); // CONVERTE DATA NA HORA DE SALVAR PARA Y-m-d
- $system_aluno_parcela->status_pagamento_id = $parcela->status_pagamento_id;
- $system_aluno_parcela->store(); // salva o objeto
- $system_aluno->addSystemAlunoParcela($system_aluno_parcela); // aqui salva a parecela
- $system_aluno->store(); // salva o objeto
- TTransaction::close(); // close the transaction
- } catch (Exception $ex) {
- new TMessage('error', 'ma oee ' . $ex->getMessage().' file: '.$ex->getFile().' line: '.$ex->getLine());
- }
- }
- /**
- * Show the page
- */
- public function show() {
- parent::show();
- }
- function onTeste($param) {
- echo '<pre>';
- print_r($param);
- echo '<pre>';
- }
- /**
- * Remove parcela datagrid session
- */
- public static function deleteBoleto($param)
- {
- $parcelas = TSession::getValue('datagrid');
- unset($parcelas[ $param['id'] ]);
- TSession::setValue('datagrid', $parcelas);
- }
- }
- ?>
model
- <?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 $system_aluno_parcelas;
- public function __construct($id = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct($id, $callObjectLoad);
- parent::addAttribute('matricula');
- 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();
- $this->system_aluno_parcelas = array();
- }
- /**
- * Composition with Item
- */
- public function addSystemAlunoTurma(SystemAlunoTurma $system_aluno_turma)
- {
- $this->system_aluno_turmas[] = $system_aluno_turma;
- }
- /**
- * Composition with Item
- */
- public function addSystemAlunoParcela(SystemAlunoParcela $system_aluno_parcela)
- {
- $this->system_aluno_parcelas[] = $system_aluno_parcela;
- }
- /**
- * Return Items composition
- */
- public function getSystemAlunoTurmas()
- {
- return $this->system_aluno_turmas;
- }
- /**
- * Return Items composition
- */
- public function getSystemAlunoParcelas()
- {
- return $this->system_aluno_parcelas;
- }
- /**
- * Load the object and the aggregates
- */
- public function load($id)
- {
- $this->system_aluno_turmas = parent::loadComposite('SystemAlunoTurma', 'aluno_id', $id);
- $this->system_aluno_parcelas = parent::loadComposite('SystemAlunoParcela', 'aluno_id', $id);
- // 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();
- parent::saveComposite('SystemAlunoTurma', 'aluno_id', $this->id, $this->system_aluno_turmas);
- parent::saveComposite('SystemAlunoParcela', 'aluno_id', $this->id, $this->system_aluno_parcelas);
- }
- /**
- * Delete the book and its aggregates
- */
- public function delete($id = NULL)
- {
- $id = isset($id) ? $id : $this->{'id'};
- parent::deleteComposite('SystemAlunoTurma', 'aluno_id', $id);
- parent::deleteComposite('SystemAlunoParcela', 'aluno_id', $id);
- // delete the object itself
- parent::delete($id);
- }
- public function get_system_status_pagamento()
- {
- // loads the associated object
- if (empty($this->system_status_pagamentos))
- $this->system_status_pagamentos = new SystemStatusPagamento($this->status_pagamento_id);
- // returns the associated object
- return $this->system_status_pagamentos->nome;
- }
- /**
- * Retorna periodo
- */
- public function get_SystemAluno()
- {
- return SystemAluno::find($this->aluno_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);
- }
- /**
- * Retorna periodo
- */
- public function get_SystemAlunoNota()
- {
- return SystemAlunoNota::find($this->aluno_id);
- }
- }
- ?>
Habilite os logs de sql para facilitar e isolar o problema.
Olá, Nataniel Rabaioli!
São esses logs:
Veja que pelos logs é possível perceber que são feitos vários updates na system_aluno_turma após o insert. Era esse o comportamento desejado?
Achei estranho o trecho abaixo:
aluno_id não seria a coluna de vínculo, ao invés da chave primária na tabela aluno_turma?
Obrigado Nataniel! Deu certo.