Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Erro SQLSTATE[22007] usando setDatabaseMask Olá, boa noite Galera! Estou com um problema que já foi bastante discutido aqui no fórum mais não estou vendo como resolver. O problema é conversão de data na hora de salvar, estou usando setDatabaseMask mais reporta o erro da imagem anexada. vou colocar meu código aqui e no gist. Obrigado se auguem puder me ajudar! código no gist: https://gist.github.com/Guiansoft/0b7ad67f23740...
JA
Erro SQLSTATE[22007] usando setDatabaseMask  
Olá, boa noite Galera!

Estou com um problema que já foi bastante discutido aqui no fórum mais não estou vendo como resolver.

O problema é conversão de data na hora de salvar, estou usando setDatabaseMask mais reporta o erro da imagem anexada. vou colocar meu código aqui e no gist.

Obrigado se auguem puder me ajudar!
código no gist: https://gist.github.com/Guiansoft/0b7ad67f23740912b0b0756a33553fbf

  1. <?php
  2. /**
  3.  * SystemAlunoForm Registration
  4.  * @author  Jonathas Alves Santos
  5.  */
  6. class AlunoForm extends TPage
  7. {
  8.     private   $frame;
  9.     protected $form// form
  10.     protected $turmas_list;
  11.     protected $formgrid;
  12.     protected $formFields;
  13.     protected $datagrid;
  14.     /**
  15.      * - Class constructor
  16.      * - Creates the page and the registration form
  17.      */
  18.     function __construct()
  19.     {
  20.         parent::__construct();
  21.         // creates the form
  22.         $this->form = new BootstrapFormBuilder('form_Aluno');
  23.         $this->form->setFormTitle(('Aluno'));
  24.         // create the form fields aluno
  25.         $id                          = new TEntry('id');
  26.         $matricula                   = new TEntry('matricula');
  27.         $name                        = new TEntry('name');
  28.         $genero_id                   = new TDBCombo('genero_id','db_guiansoft','SystemGenero','id','nome');
  29.         $nascimento                  = new TDate('nascimento');
  30.         $rg                          = new TEntry('rg');
  31.         $cpf                         = new TEntry('cpf');
  32.         $logradouro                  = new TEntry('logradouro');
  33.         $cep                         = new TEntry('cep');
  34.         $numero                      = new TEntry('numero');
  35.         $bairro                      = new TEntry('bairro');
  36.         $cidade                      = new TEntry('cidade');
  37.         $uf                          = new TEntry('uf');
  38.         $complemento                 = new TEntry('complemento');
  39.         $celular                     = new TEntry('celular');
  40.         $celPai                      = new TEntry('celPai');
  41.         $celMae                      = new TEntry('celMae');
  42.         $telefone                    = new TEntry('telefone');
  43.         $email                       = new TEntry('email');
  44.         $tipoSanguineo               = new TEntry('tipoSanguineo');
  45.         $alergia                     = new TEntry('alergia');
  46.         $problemaSaude               = new TEntry('problemaSaude');
  47.         $chamarUrgencia              = new TEntry('chamarUrgencia');
  48.         $nomePai                     = new TEntry('nomePai');
  49.         $nomeMae                     = new TEntry ('nomeMae');
  50.         $photo_path                  = new TFile('photo_path');
  51.         $data_matricula              = new TDate('data_matricula');
  52.         $data_matricula->setValue(date('Y-m-d'));
  53.         $nomeResp                    = new TEntry('nomeResp');
  54.         $generoRespId                = new TDBCombo('generoRespId','db_guiansoft','SystemGenero','id','nome');
  55.         $nascimentoResp              = new TDate('nascimentoResp');
  56.         $rgResp                      = new TEntry('rgResp');
  57.         $cpfResp                     = new TEntry('cpfResp');
  58.         $logradouroResp              = new TEntry('logradouroResp');
  59.         $cepResp                     = new TEntry('cepResp');
  60.         $numeroResp                  = new TEntry('numeroResp');
  61.         $bairroResp                  = new TEntry('bairroResp');
  62.         $cidadeResp                  = new TEntry('cidadeResp');
  63.         $ufResp                      = new TEntry('ufResp');
  64.         $complementoResp             = new TEntry('complementoResp');
  65.         $celularResp                 = new TEntry('celularResp');
  66.         $telefoneResp                = new TEntry('telefoneResp');
  67.         $emailResp                   = new TEntry('emailResp');
  68.         $empresaResp                 = new TEntry('empresaResp');
  69.         $profissao_id                = new TDBCombo('profissao_id','db_guiansoft','SystemProfissao','id','nome');
  70.         $endProfissional             = new TEntry ('endProfissional');
  71.         $telProfissional             = new TEntry ('telProfissional');
  72.         $vencimento                  = new TDate('vencimento');
  73.         $desconto                    = new TEntry('desconto');
  74.         $periodoc_id                 = new TDBCombo('periodoc_id','db_guiansoft','SystemPeriodo','id','nome');
  75.         $periodos_id                 = new TDBCombo('periodos_id','db_guiansoft','SystemPeriodo','id','nome');
  76.         $plano_pagamento_id          = new  ">TDBSeekButton('plano_pagamento_id''db_guiansoft'$this->form->getName(), 'SystemPlanoPagamento''nome''plano_pagamento_id''plano_pagamento_nome');
  77.         $plano_pagamento_nome        = new TEntry('plano_pagamento_nome');
  78.         $numero_documento            = new TEntry('numero_documento');
  79.         $parcela                     = new TEntry('parcela');
  80.         $valor_boleto                = new TEntry('valor_boleto');
  81.         $status_pagamento_id         = new TDBCombo('status_pagamento_id','db_guiansoft','SystemStatusPagamento','id','nome');
  82.         $status_pagamentos_id        = new TDBCombo('status_pagamentos_id','db_guiansoft','SystemStatusPagamento','id','nome');
  83.         $btnCep                      = new TButton('action1');
  84.         $btnRespCep                  = new TButton('action2');
  85.         $btn $this->form->addAction_t('Save'), new TAction(array($this'onSave')), 'fa:floppy-o');
  86.         $btn->class 'btn btn-sm btn-primary';
  87.         $this->form->addAction_t('Clear'), new TAction(array($this'onEdit')), 'fa:eraser red');
  88.         $this->form->addAction( ('Gerar Parcelas'), new TAction(array($this'onGerarParcelas')), 'fa:hand-o-down');
  89.         $this->form->addAction_t('Back'), new TAction(array('AlunoList','onReload')), 'fa:arrow-circle-o-left blue');
  90.         // complete upload action
  91.         $photo_path->setCompleteAction(new TAction(array($this'onComplete')));
  92.         $photo_path->setAllowedExtensions( ['gif''png''jpg''jpeg'] );
  93.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  94.         $this->datagrid->datatable 'true';
  95.         $this->datagrid->style 'width: 100%';
  96.         $this->datagrid->setHeight(320);
  97.         $hbox1 = new THBox;
  98.         $hbox1->style 'margin: 4px';
  99.         $vbox1 = new TVBox;
  100.         $vbox1->style='width:100%';
  101.         $vbox1->add$hbox1 );
  102.         $vbox1->add($this->datagrid);
  103.         // creates the datagrid columns
  104.         $column_id                   = new TDataGridColumn('id''Código''center');
  105.         $column_numero_documento     = new TDataGridColumn('numero_documento''Num. Documento''center');
  106.         $column_nomeResp             = new TDataGridColumn('nomeResp''Responsável''center');
  107.         $column_parcela              = new TDataGridColumn('parcela''Parcelas''center');
  108.         $column_vencimento           = new TDataGridColumn('vencimento', ('Vencimento'), 'left');
  109.         $column_valor_boleto         = new TDataGridColumn('valor_boleto', ('Valor'), 'left');
  110.         $column_status_pagamento_id  = new TDataGridColumn('status_pagamento_id', ('Status'), 'left');
  111.         // add the columns to the DataGrid
  112.         $this->datagrid->addColumn($column_id);
  113.         $this->datagrid->addColumn($column_numero_documento);
  114.         $this->datagrid->addColumn($column_nomeResp);
  115.         $this->datagrid->addColumn($column_parcela);
  116.         $this->datagrid->addColumn($column_vencimento);
  117.         $this->datagrid->addColumn($column_valor_boleto);
  118.         $this->datagrid->addColumn($column_status_pagamento_id);
  119.         // creates two datagrid actions
  120.         $action1 = new TDataGridAction(array($this'deleteBoleto'));
  121.         $action1->setLabel('Baixa Manual');
  122.         $action1->setImage('fa:download blue');
  123.         $action1->setField('id');
  124.         $action2 = new TDataGridAction(array( 'BoletoView''onGenerate'));
  125.         $action2->setLabel('Imprimir Boleto');
  126.         $action2->setImage('fa:barcode');
  127.         $action2->setFields(['nosso_numero''numero_documento''plano_pagamento_nome''nomeResp''logradouroResp''numeroResp''cpfResp''bairroResp''cepResp''cidadeResp''ufResp''name''parcela''vencimento''valor_boleto']);
  128.         $action3 = new TDataGridAction(array($this'onTeste'));
  129.         $action3->setLabel('Editar');
  130.         $action3->setImage('fa:pencil-square-o blue fa-lg');
  131.         $action3->setField('id');
  132.         $action4 = new TDataGridAction(array($this'deleteBoleto'));
  133.         $action4->setLabel('Delete');
  134.         $action4->setImage('fa:trash-o red fa-lg');
  135.         $action4->setField('id');
  136.         $action_group = new TDataGridActionGroup('Ações''bs:th');
  137.         $action_group->addHeader('Available Options');
  138.         $action_group->addAction($action1);
  139.         $action_group->addAction($action2);
  140.         $action_group->addSeparator();
  141.         $action_group->addHeader('Another Options');
  142.         $action_group->addAction($action3);
  143.         $action_group->addAction($action4);
  144.         // add the actions to the datagrid
  145.         $this->datagrid->addActionGroup($action_group);
  146.         // creates the datagrid model
  147.         $this->datagrid->createModel();
  148.         // define the button action
  149.         $btnCep->setAction(new TAction(array($this'onCep')), 'Busca');
  150.         $btnCep->setImage('fa:map-marker green');
  151.         $btnCep->class 'btn btn-sm btn-primary';
  152.         // define the button action
  153.         $btnRespCep->setAction(new TAction(array($this'onRespCep')), 'Busca');
  154.         $btnRespCep->setImage('fa:map-marker green');
  155.         $btnRespCep->class 'btn btn-sm btn-primary';
  156.         // DEFINE TAMANHO
  157.         $id->setSize('100%');
  158.         $matricula->setSize('100%');
  159.         $name->setSize('100%');
  160.         $genero_id->setSize('100%');
  161.         $nascimento->setSize('100%');
  162.         $rg->setSize('100%');
  163.         $cpf->setSize('100%');
  164.         $logradouro->setSize('100%');
  165.         $numero->setSize('100%');
  166.         $bairro->setSize('100%');
  167.         $cep->setSize('100%');
  168.         $cidade->setSize('100%');
  169.         $uf->setSize('100%');
  170.         $complemento->setSize('100%');
  171.         $celular->setSize('100%');
  172.         $celPai->setSize('100%');
  173.         $celMae->setSize('100%');
  174.         $telefone->setSize('100%');
  175.         $photo_path->setSize('100%');
  176.         $btnCep->setSize('100%');
  177.         $tipoSanguineo->setSize('100%');
  178.         $alergia->setSize('100%');
  179.         $problemaSaude->setSize('100%');
  180.         $chamarUrgencia->setSize('100%');
  181.         $nomePai->setSize('100%');
  182.         $nomeMae->setSize('100%');
  183.         $nomeResp->setSize('100%');
  184.         $generoRespId->setSize('100%');
  185.         $nascimentoResp->setSize('100%');
  186.         $rgResp->setSize('100%');
  187.         $cpfResp->setSize('100%');
  188.         $logradouroResp->setSize('100%');
  189.         $numeroResp->setSize('100%');
  190.         $bairroResp->setSize('100%');
  191.         $cepResp->setSize('100%');
  192.         $cidadeResp->setSize('100%');
  193.         $ufResp->setSize('100%');
  194.         $complementoResp->setSize('100%');
  195.         $celularResp->setSize('100%');
  196.         $telefoneResp->setSize('100%');
  197.         $emailResp->setSize('35%');
  198.         $empresaResp->setSize('100%');
  199.         $profissao_id->setSize('100%');
  200.         $endProfissional->setSize('100%');
  201.         $telProfissional->setSize('100%');
  202.         $data_matricula->setSize('100%');
  203.         $vencimento->setSize('100%');
  204.         $desconto->setSize('100%');
  205.         $periodoc_id->setSize('100%');
  206.         $plano_pagamento_id->setSize('80');
  207.         $plano_pagamento_nome->setSize('calc(100% - 80px)');
  208.         $numero_documento->setSize('100%');
  209.         $parcela->setSize('100%');
  210.         $valor_boleto->setSize('100%');
  211.         $status_pagamento_id->setSize('100%');
  212.         $periodos_id->setSize('100%');
  213.         $status_pagamentos_id->setSize('100%');
  214.         $email->setSize('100%');
  215.         $id->setEditable(false);
  216.         $matricula->setEditable(false);
  217.         $plano_pagamento_nome->setEditable(false);
  218.         // DEFINIÇÃO DE MASCARA
  219.         $cpf->setMask('000.000.000-00');
  220.         $cpfResp->setMask('000.000.000-00');
  221.         $cep->setMask('00000-000');
  222.         $cepResp->setMask('00000-000');
  223.         $celular->setMask('(00)00000-0000');
  224.         $celPai->setMask('(00)00000-0000');
  225.         $celMae->setMask('(00)00000-0000');
  226.         $celularResp->setMask('(00)00000-0000');
  227.         $telefone->setMask('(00)0000-0000');
  228.         $telefoneResp->setMask('(00)0000-0000');
  229.         $nascimento->setMask('dd/mm/yyyy');
  230.         $data_matricula->setMask('dd/mm/yyyy');
  231.         $nascimentoResp->setMask('dd/mm/yyyy');
  232.         $vencimento->setMask('dd/mm/yyyy');
  233.         $nascimento->setDatabaseMask('yyyy-mm-dd');
  234.         $data_matricula->setDatabaseMask('yyyy-mm-dd');
  235.         $nascimentoResp->setDatabaseMask('yyyy-mm-dd');
  236.         $vencimento->setDatabaseMask('yyyy-mm-dd');
  237.         // CAMPOS OBRIGATORIOS
  238.         $email->addValidation('Email', new TEmailValidator);
  239.         
  240.         $this->form->appendPage('Aluno');
  241.         // SEPARAR
  242.         $this->form->addFields( [new TFormSeparator(('Dados do Aluno'))] );
  243.         $this->form->addFields([new TLabel('Código:')], [$id], [new TLabel(('Matricula:'))], [$matricula]);
  244.         $this->form->addFields([new TLabel(('Nome:'))], [$name]);
  245.         $this->form->addFields([new TLabel('Gênero:')], [$genero_id], [new TLabel('Nascimento:')], [$nascimento]);
  246.         $this->form->addFields([new TLabel('CPF:')], [$cpf], [new TLabel('RG:')], [$rg]);
  247.         $this->form->addFields([new TLabel('Tel. Aluno:')], [$telefone], [new TLabel('Cel. Aluno:')], [$celular]);
  248.         $this->form->addFields([new TLabel('Data da Matrícula:')], [$data_matricula], [new TLabel('Foto:')], [$photo_path]);
  249.         $this->frame = new TElement('div');
  250.         $this->frame->id 'photo_path';
  251.         $this->frame->style 'width:180px;height:auto;min-height:180px;border:1px solid gray;padding:4px;';
  252.         // SEPARAR
  253.         $this->form->addFields( [new TFormSeparator(('Filiação'))] );
  254.         $this->form->addFields([new TLabel('Pai:')], [$nomePai], [new TLabel('Mãe:')], [$nomeMae]);
  255.         $this->form->addFields([new TLabel('Cel. Pai:')], [$celPai], [new TLabel('Cel. Mãe:')], [$celMae]);
  256.         // SEPARAR
  257.         $this->form->addFields( [new TFormSeparator(('Endereço do Aluno'))] );
  258.         $this->form->addFields([new TLabel('CEP:')], [$cep], [$btnCep]);
  259.         $this->form->addFields([new TLabel('Logradouro:')], [$logradouro], [new TLabel('Número:')], [$numero]);
  260.         $this->form->addFields([new TLabel('Complemento:')], [$complemento], [new TLabel('Bairro:')], [$bairro]);
  261.         $this->form->addFields([new TLabel('Cidade:')], [$cidade], [new TLabel('Estado:')], [$uf]);
  262.         $this->form->appendPage('Responsável Financeiro');
  263.         $this->form->addFields([new TLabel('Nome:')], [$nomeResp]);
  264.         $this->form->addFields([new TLabel('Gênero:')], [$generoRespId], [new TLabel('Nascimento:')], [$nascimentoResp]);
  265.         $this->form->addFields([new TLabel('RG:')], [$rgResp], [new TLabel('CPF:')], [$cpfResp]);
  266.         $this->form->addFields([new TLabel('Cel.:')], [$celularResp], [new TLabel('Tel.:')], [$telefoneResp]);
  267.         $this->form->addFields([new TLabel('E-mail:')], [$emailResp]);
  268.         // SEPARAR
  269.         $this->form->addFields( [new TFormSeparator(('Endereço'))] );
  270.         $this->form->addFields([new TLabel('CEP:')], [$cepResp], [$btnRespCep]);
  271.         $this->form->addFields([new TLabel('Logradouro:')], [$logradouroResp], [new TLabel('Complemento:')], [$complementoResp]);
  272.         $this->form->addFields([new TLabel('Número:')], [$numeroResp], [new TLabel('Bairro:')], [$bairroResp]);
  273.         $this->form->addFields([new TLabel('Cidade:')], [$cidadeResp], [new TLabel('Estado:')], [$ufResp]);
  274.         // SEPARAR
  275.         $this->form->addFields( [new TFormSeparator(('Endereço de Trabalho'))] );
  276.         $this->form->addFields([new TLabel('Empresa:')], [$empresaResp], [new TLabel('Profissão:')], [$profissao_id]);
  277.         $this->form->addFields([new TLabel('End. Prof.:')], [$endProfissional], [new TLabel('Tel. Prof.:')], [$telProfissional]);
  278.         // SEPARAR
  279.         $this->form->addFields( [new TFormSeparator(('Dados Finánceiro'))] );
  280.         $this->form->addFields( [new TLabel('Vencimento:')], [$vencimento], [new TLabel('Desconto em %:')], [$desconto]);
  281.         $this->form->appendPage('Ficha Médica');
  282.         $this->form->addFields([new TLabel('Tipo Sanguíneo:')], [$tipoSanguineo], [new TLabel('Alergias:')], [$alergia]);
  283.         $this->form->addFields([new TLabel('Problemas de saúde?')], [$problemaSaude], [new TLabel('Quem chamar para urgência?')], [$chamarUrgencia]);
  284.         // TURMA
  285.         $this->form->appendPage('Turmas');
  286.         $aluno_id         = new TEntry('aluno_id[]');
  287.         $barcode          = new TEntry('barcode[]');
  288.         $periodo_id       = new TDBCombo('periodo_id[]','db_guiansoft','SystemPeriodo','id','nome');
  289.         $curso_id         = new TDBCombo('curso_id[]','db_guiansoft','SystemCurso','id','nome');
  290.         $modulo_id        = new TDBCombo('modulo_id[]','db_guiansoft','SystemModulo','id','nome');
  291.         $turma_id         = new TDBCombo('turma_id[]','db_guiansoft','SystemTurma','id','nome');
  292.         $situacao_id      = new TDBCombo('situacao_id[]','db_guiansoft','SystemSituacaoAlunoTurma','id','nome');
  293.         // set exit action for input_exit
  294.         $change_action = new TAction(array($this'onChangeActionModulo'));
  295.         $modulo_id->setChangeAction($change_action);
  296.         
  297.         // DEFINE TAMANHO
  298.         $aluno_id->setSize('100%');
  299.         $barcode->setSize(120);
  300.         $periodo_id->setSize('100%');
  301.         $curso_id->setSize('100%');
  302.         $modulo_id->setSize('100%');
  303.         $turma_id->setSize('100%');
  304.         $situacao_id->setSize('100%');
  305.         $this->system_aluno_turmas_list = new TFieldList;
  306.         $this->system_aluno_turmas_list->addField'<b>'.('ID').'</b>'$aluno_id);
  307.         $this->system_aluno_turmas_list->addField'<b>'.('Barcode').'</b>'$barcode);
  308.         $this->system_aluno_turmas_list->addField'<b>'.('Período').'</b>'$periodo_id);
  309.         $this->system_aluno_turmas_list->addField'<b>'.('Curso').'</b>'$curso_id);
  310.         $this->system_aluno_turmas_list->addField'<b>'.('Módulo').'</b>'$modulo_id);
  311.         $this->system_aluno_turmas_list->addField'<b>'.('Turma').'</b>'$turma_id);
  312.         $this->system_aluno_turmas_list->addField'<b>'.('Situação').'</b>'$situacao_id);
  313.         $this->system_aluno_turmas_list->enableSorting();
  314.         $this->form->addField($aluno_id);
  315.         $this->form->addField($barcode);
  316.         $this->form->addField($periodo_id);
  317.         $this->form->addField($curso_id);
  318.         $this->form->addField($modulo_id);
  319.         $this->form->addField($turma_id);
  320.         $this->form->addField($situacao_id);
  321.         $this->form->addContent( [new TLabel('Turmas')], [$this->system_aluno_turmas_list] );
  322.         // FIM TURMAS
  323.         
  324.         // COBRANÇA
  325.         $this->form->appendPage('Cobranças');
  326.         $plano_pagamento_id->setExitAction(new TAction(array($this,'onPlanoChange')));
  327.         $this->form->addFields( [new TLabel('Periodo:')], [$periodoc_id] );
  328.         $this->form->addFields( [new TLabel('Plano de pagamento:')], [$plano_pagamento_id$plano_pagamento_nome], [new TLabel('Parcelas:')], [$parcela] );
  329.         $this->form->addFields( [new TLabel('Valor Total:')], [$valor_boleto], [new TLabel(('Status Pagamento:'))], [$status_pagamento_id] );
  330.         $this->form->addFields( [new TFormSeparator(('Parcelas'))] );
  331.         // BUSCA PARCELA POR PERIODO E STATUS
  332.         $this->form->addFields( [ $lp=new TLabel(('Periodo'))], [$periodos_id], [$ls=new TLabel(('Status Pagamento'))], [$status_pagamentos_id] );
  333.         // DEFINE A COR
  334.         $lp->setFontColor('red');
  335.         $ls->setFontColor('red');
  336.         $this->form->addFields( [$vbox1] );
  337.         // FORMATA O VALOR DA PARCELA NO DATAGRID, NO PADÃO -> R$ 1.000,99
  338.         $format_value = function($value) {
  339.             if (is_numeric($value)) {
  340.                 return 'R$ '.number_format($value2',''.');
  341.             }
  342.             return $value;
  343.         };
  344.         $column_valor_boleto->setTransformer$format_value );
  345.         // FIM COBRANÇA
  346.         // wrap the page content
  347.         $container = new TVBox;
  348.         $container->style 'width: 100%';
  349.         $container->add(new TXMLBreadCrumb('menu.xml''AlunoList'));
  350.         $container->add($this->form);
  351.         // add the container to the page
  352.         parent::add($container);
  353.     }
  354.     /**
  355.      * On complete upload photo_path
  356.      */
  357.     public static function onComplete($param)
  358.     {
  359.         new TMessage('info''Upload completo: ' $param['photo_path']);
  360.         copy("tmp/{$param['photo_path']}""files/fotos/alunos/{$param['photo_path']}");
  361.         // refresh photo_frame
  362.         TScript::create("$('#photo_frame').html('')");
  363.         TScript::create("$('#photo_frame').html(\"<img width='180px' height='180px' src='files/fotos/alunos/{$param['photo_path']}'>\");");
  364.     }
  365.     /*
  366.     *  Função de busca de Endereço pelo CEP
  367.     *  -   Desenvolvido Felipe Olivaes para ajaxbox.com.br
  368.     *  -   Utilizando WebService de CEP da republicavirtual.com.br
  369.     */
  370.     public static function onCep($param)
  371.     {
  372.         $resultado = @file_get_contents('http://republicavirtual.com.br/web_cep.php?cep=' urlencode($param['cep']) . '&formato=query_string');
  373.         if (!$resultado) {
  374.             $resultado "&resultado=0&resultado_txt=erro+ao+buscar+cep";
  375.         }
  376.         parse_str($resultado$retorno);
  377.         $obj = new StdClass;
  378.         $obj->cep $param['cep'];
  379.         $obj->logradouro strtoupper($retorno['tipo_logradouro'] . ' ' $retorno['logradouro']);
  380.         $obj->bairro strtoupper($retorno['bairro']);
  381.         $obj->cidade strtoupper($retorno['cidade']);
  382.         $obj->uf strtoupper($retorno['uf']);
  383.         TForm::sendData('form_Aluno'$obj);
  384.     }
  385.     /*
  386.     *  Função de busca de Endereço pelo CEP
  387.     *  -   Desenvolvido Felipe Olivaes para ajaxbox.com.br
  388.     *  -   Utilizando WebService de CEP da republicavirtual.com.br
  389.     */
  390.     public static function onRespCep($param)
  391.     {
  392.         $resultado = @file_get_contents('http://republicavirtual.com.br/web_cep.php?cep=' urlencode($param['cepResp']) . '&formato=query_string');
  393.         if (!$resultado) {
  394.             $resultado "&resultado=0&resultado_txt=erro+ao+buscar+cep";
  395.         }
  396.         parse_str($resultado$retorno);
  397.         $obj = new StdClass;
  398.         $obj->cepResp $param['cepResp'];
  399.         $obj->logradouroResp strtoupper($retorno['tipo_logradouro'] . ' ' $retorno['logradouro']);
  400.         $obj->bairroRespstrtoupper($retorno['bairro']);
  401.         $obj->cidadeResp strtoupper($retorno['cidade']);
  402.         $obj->ufResp strtoupper($retorno['uf']);
  403.         TForm::sendData('form_Aluno'$obj);
  404.     }
  405.     /**
  406.      * Action to be executed when the user changes the modulo_id field
  407.      */
  408.     public static function onChangeActionModulo($param)
  409.         {
  410.             TTransaction::open('db_guiansoft');
  411.             $criteria = new TCriteria;
  412.             $criteria->add(new TFilter('modulo_id''='$param['modulo_id']));
  413.             $repository = new TRepository('SystemTurma');
  414.             $turmas $repository->load($criteria);
  415.             $options = array();
  416.             foreach ($turmas as $turma){
  417.             $options[$turma->id] = $turma->nome;
  418.         }
  419.         //TForm::sendData('form_Aluno', $objeto);
  420.         TCombo::reload('form_Aluno''turma_id[]'$options);
  421.     }
  422.     /**
  423.      * On product change
  424.      */
  425.     static function onPlanoChange$params )
  426.     {
  427.         if( isset($params['plano_pagamento_id']) && $params['plano_pagamento_id'] )
  428.         {
  429.             try
  430.             {
  431.                 TTransaction::open('db_guiansoft');
  432.                 $systemplanopagamento = new SystemPlanoPagamento($params['plano_pagamento_id']);
  433.                 $fill_data = new StdClass;
  434.                 $fill_data->parcela $systemplanopagamento->prazo;
  435.                 $fill_data->valor_boleto $systemplanopagamento->valor_total;
  436.                 TForm::sendData('form_Aluno'$fill_data);
  437.                 TTransaction::close();
  438.             }
  439.             catch (Exception $e// in case of exception
  440.             {
  441.                 new TMessage('error'$e->getMessage());
  442.                 TTransaction::rollback();
  443.             }
  444.         }
  445.     }
  446.     /**
  447.      * Reload the item list
  448.     * @param $param URL parameters
  449.     */
  450.     public function onReload($param)
  451.     {
  452.     // read session items
  453.     $parcelas TSession::getValue(__CLASS__ '_parcelas');
  454.     $this->datagrid->clear(); // clear detail list
  455.     $data $this->form->getData();
  456.     if ($system_aluno_parcelas)
  457.     {
  458.         $cont 1;
  459.         foreach ($system_aluno_parcelas as $parcelas_id => $parcelas)
  460.         {
  461.         $system_aluno_parcela->id $parcelas['id'];
  462.         $system_aluno_parcela->numero_documento $parcelas['numero_documento'];
  463.         $system_aluno_parcela->nomeResp $parcelas['nomeResp'];
  464.         $system_aluno_parcela->parcela $parcelas['parcela'];
  465.         $system_aluno_parcela->vencimento $parcelas['vencimento'];
  466.         $system_aluno_parcela->valor_boleto $parcelas['valor_boleto'];
  467.         $system_aluno_parcela->status_pagamento_id $parcelas['status_pagamento_id'];
  468.         $row $this->datagrid->addSystemAlunoParcela$system_aluno_parcela );
  469.         $row->onmouseover '';
  470.         $row->onmouseout  '';
  471.         }
  472.         $this->form->setFields$this->formFields );
  473.     }
  474.     $this->loaded TRUE;
  475.     }
  476.     /**
  477.      * method onEdit
  478.     * Edit a record data
  479.     */
  480.     function onEdit($param)
  481.     {
  482.     try
  483.     {
  484.         if (isset($param['id'])){
  485.         $id $param['id'];  // OBTÉM O PARÂMETRO $key
  486.         TTransaction::open('db_guiansoft'); // ABRE A TRANSAÇÃO
  487.         $system_aluno = new SystemAluno($param['id']); // INSTANCIA O ACTIVE RECORD
  488.         // load the contacts (composition)
  489.         $system_aluno_turmas   $system_aluno->getSystemAlunoTurmas();
  490.         $system_aluno_parcelas $system_aluno->getSystemAlunoParcelas();
  491.         if ($system_aluno_parcelas) {
  492.             foreach ($system_aluno_parcelas as $system_aluno_parcela) {
  493.             $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
  494.             $this->datagrid->addItem($system_aluno_parcela); // add the detail inside the datagrid
  495.             }
  496.         }
  497.         // TURMAS
  498.         if ($system_aluno_turmas) {
  499.             $this->system_aluno_turmas_list->addHeader();
  500.             foreach ($system_aluno_turmas as $system_aluno_turma)
  501.             {
  502.             $system_aluno_turma->system_aluno_turma_id $system_aluno_turma->id;
  503.             $this->system_aluno_turmas_list->addDetail($system_aluno_turma);
  504.             }
  505.             $this->system_aluno_turmas_list->addCloneAction();
  506.         }
  507.         else
  508.         {
  509.             $this->clearSystemAlunoTurmas();
  510.         }
  511.         $this->form->setData($system_aluno); // PREENCHE O FORM
  512.         TTransaction::close(); // FECHA A TRANSAÇÃO
  513.         }
  514.     else {
  515.         $this->onClear($param);
  516.         $this->form->clear();
  517.         TSession::setValue('$system_aluno_parcelas'null);
  518.         $this->onReload$param );
  519.     }
  520.     }
  521.     catch (Exception $e// in case of exception
  522.     {
  523.         new TMessage('error'$e->getMessage());
  524.         TTransaction::rollback();
  525.     }
  526.     }
  527.     /**
  528.      * Clear Turmas
  529.      */
  530.     public function clearSystemAlunoTurmas()
  531.     {
  532.         $this->system_aluno_turmas_list->addHeader();
  533.         $this->system_aluno_turmas_list->addDetail( new stdClass );
  534.         $this->system_aluno_turmas_list->addCloneAction();
  535.     }
  536.     /**
  537.      * Clear form
  538.      */
  539.     public function onClear()
  540.     {
  541.         $this->form->clear();
  542.         $this->clearSystemAlunoTurmas();
  543.         $this->clearSystemAlunoParcelas();
  544.         TSession::setValue(__CLASS__ '_parcelas', array());
  545.         $this->onReload($param);
  546.     }
  547.     /**
  548.      * method onSave
  549.      * Executed whenever the user clicks at the save button
  550.      */
  551.     public static function onSave($param)
  552.     {
  553.         try
  554.         {
  555.             // ABRE UMA TRANSAÇÃO COM O BANCO DE DADOS
  556.             TTransaction::open('db_guiansoft');
  557.             // read the form data and instantiates an Active Record
  558.             $system_aluno = new SystemAluno;
  559.             $system_aluno->fromArray$param );
  560.             $system_aluno->clearParts();
  561.             var_dump($system_aluno);
  562.             if( !empty($param['barcode']) AND is_array($param['barcode']) )
  563.             {
  564.                 foreach( $param['barcode'] as $row => $barcode)
  565.                 {
  566.                     if ($barcode)
  567.                     {
  568.                         $system_aluno_turma = new SystemAlunoTurma;
  569.                         $system_aluno_turma->barcode        $barcode;
  570.                         $system_aluno_turma->id             $param['aluno_id'][$row];
  571.                         $system_aluno_turma->periodo_id     $param['periodo_id'][$row];
  572.                         $system_aluno_turma->curso_id       $param['curso_id'][$row];
  573.                         $system_aluno_turma->modulo_id      $param['modulo_id'][$row];
  574.                         $system_aluno_turma->turma_id       $param['turma_id'][$row];
  575.                         $system_aluno_turma->situacao_id    $param['situacao_id'][$row];
  576.                         $system_aluno->addSystemAlunoTurma$system_aluno_turma );
  577.                     }
  578.                 }
  579.             }
  580.             $system_aluno->store(); // SALAVA O OBJETO
  581.             $data = new stdClass;
  582.             $data->id $system_aluno->id;
  583.             TForm::sendData('form_aluno'$data);
  584.             // shows the success message
  585.             new TMessage('info''Record saved');
  586.             TTransaction::close(); // close the transaction
  587.         }
  588.         catch (Exception $e// in case of exception
  589.         {
  590.             new TMessage('error'$e->getMessage());
  591.             // undo all pending operations
  592.             TTransaction::rollback();
  593.         }
  594.     }
  595.     /*
  596.     * - Função de Gerar parcelas
  597.     * - Indev (ajuda ate ajudar) kkkk
  598.     */
  599.     function onGerarParcelas($param)
  600.     {
  601.     try {
  602.         // ABRE UMA TRANSAÇÃO COM O BANCO DE DADOS
  603.         TTransaction::open('db_guiansoft');
  604.         // read the form data and instantiates an Active Record
  605.         $system_aluno = new SystemAluno($param['id']);
  606.         $this->datagrid->clear(); // LIMPA A GRID
  607.         $this->form->validate(); // VERIFICA OS CAMPOS OBRIGATORIOS E FAZ A VALIDAÇÃO
  608.         $old_parcelas SystemAlunoParcela::where('aluno_id''='$system_aluno->id)->load();
  609.         $keep_parcelas = array();
  610.         // get session items
  611.         $items TSession::getValue(__CLASS__ '_parcelas');
  612.         if (!is_null($items) && ! empty($items)) {
  613.             foreach ($items as $item) {
  614.                 if (substr($item->id01) == 'X') { // new record
  615.                     $system_aluno_parcela = new SystemAlunoParcela;
  616.                             // recebe dados informado pelo usuário
  617.                     $system_aluno_parcela->fromArray($item) ;
  618.                     $system_aluno_parcela->aluno_id     $system_aluno->id;
  619.                     $system_aluno_parcela->store(); // salva o objeto
  620.                 } else {
  621.                     $system_aluno_parcela = new SystemAlunoParcela($item->id);
  622.                                     echo "ja existe parcelas";
  623.                 }
  624.                 $keep_parcelas[] = $system_aluno_parcela->id;
  625.             $this->addParcelasAluno($system_aluno,$system_aluno_parcela);;
  626.             }
  627.             TSession::setValue(__CLASS__ '_parcelas'null);
  628.         }else{
  629.         // chama a função que realiza o calculo da divisão e tbm realiza o calculo dos dos vencimentos - retorna um array
  630.         $parcelas GerarParcelas::calcularParcelas($param['valor_boleto'],
  631.         $param['parcela'], $param['vencimento'],
  632.         $param['nomeResp'], $param['cpfResp'], $param['logradouroResp'],
  633.         $param['numeroResp'], $param['bairroResp'], $param['cepResp'],
  634.         $param['cidadeResp'], $param['plano_pagamento_nome'], $param['ufResp'],
  635.         $param['name'], $param['status_pagamento_id'], null);
  636.     foreach ($parcelas as $parcela) {
  637.     $this->addParcelasAluno($system_aluno,$parcela); // adciona as parcelas
  638.             }
  639.         // armazena as parcelas sem uma variavel de sessão
  640.         TSession::setValue(__CLASS__ '_parcelas'$parcelas);
  641.         }
  642.         if ($old_parcelas) {
  643.             foreach ($old_parcelas as $old_item) {
  644.                 if (!in_array($old_item->id$keep_parcelas)) {
  645.                     $old_item->delete();
  646.                 }
  647.             }
  648.         }
  649.     $parcelas TSession::getValue(__CLASS__ '_parcelas');
  650.         // laço onde add na grid a divisão - os centavos são adicionados na ultima parcela
  651.         foreach ($parcelas as $parcela) {
  652.         // adiciona as parcelas na grid
  653.         $item = new StdClass;
  654.         $item->detail_id = empty($parcela->detail_id) ? 'X' mt_rand(1000000019999999) : $parcela->detail_id;
  655.         $item->id                       $parcela->id;
  656.         $item->nosso_numero             $parcela->nosso_numero;
  657.         $item->numero_documento         $parcela->numero_documento;
  658.         $item->name                     $parcela->name;
  659.         $item->nomeResp                 $parcela->nomeResp;
  660.         $item->cpfResp                  $parcela->cpfResp;
  661.         $item->cepResp                  $parcela->cepResp;
  662.         $item->logradouroResp           $parcela->logradouroResp;
  663.         $item->numeroResp               $parcela->numeroResp;
  664.         $item->bairroResp               $parcela->bairroResp;
  665.         $item->cidadeResp               $parcela->cidadeResp;
  666.         $item->ufResp                   $parcela->ufResp;
  667.         $item->parcela                  $parcela->parcela;
  668.         $item->vencimento               DateTime::createFromFormat('d/m/Y'$parcela->vencimento)->format'Y-m-d' );
  669.         $item->plano_pagamento_nome     $parcela->plano_pagamento_nome;
  670.         $item->valor_boleto             = ($parcela->valor_boleto);
  671.         $item->status_pagamento_id      $parcela->status_pagamento_id;
  672.         $this->datagrid->addItem($item);
  673.         }
  674.         
  675.         $data = new stdClass;
  676.         TForm::sendData('form_aluno'$data);
  677.         $this->form->setData($this->form->getData());
  678.         TTransaction::close(); // close the transaction
  679.         new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  680.     } catch (Exception $ex) {
  681.         new TMessage('error''ma oee ' $ex->getMessage().' file: '.$ex->getFile().' line: '.$ex->getLine());
  682.         TTransaction::rollback();
  683.     }
  684. }
  685. private function addParcelasAluno($system_aluno$parcela){
  686. try {
  687.     // abri uma transação com banco de dados 'db_guiansoft'
  688.     TTransaction::open('db_guiansoft');
  689.     $system_aluno_parcela = new SystemAlunoParcela;
  690.     $system_aluno_parcela->nosso_numero         $parcela->nosso_numero;
  691.     $system_aluno_parcela->numero_documento     $parcela->numero_documento;
  692.     $system_aluno_parcela->aluno_id             $system_aluno->id;
  693.     $system_aluno_parcela->name                 $parcela->name;
  694.     $system_aluno_parcela->nomeResp             $parcela->nomeResp;
  695.     $system_aluno_parcela->cpfResp              $parcela->cpfResp;
  696.     $system_aluno_parcela->cepResp              $parcela->cepResp;
  697.     $system_aluno_parcela->logradouroResp       $parcela->logradouroResp;
  698.     $system_aluno_parcela->numeroResp           $parcela->numeroResp;
  699.     $system_aluno_parcela->bairroResp           $parcela->bairroResp;
  700.     $system_aluno_parcela->cidadeResp           $parcela->cidadeResp;
  701.     $system_aluno_parcela->ufResp               $parcela->ufResp;
  702.     $system_aluno_parcela->valor_boleto         = ($parcela->valor_boleto);
  703.     $system_aluno_parcela->parcela              $parcela->parcela;
  704.     $system_aluno_parcela->plano_pagamento_nome $parcela->plano_pagamento_nome;
  705.     $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
  706.     $system_aluno_parcela->status_pagamento_id  $parcela->status_pagamento_id;
  707.     $system_aluno_parcela->store(); // salva o objeto
  708.     $system_aluno->addSystemAlunoParcela($system_aluno_parcela); // aqui salva a parecela
  709.     $system_aluno->store(); // salva o objeto
  710.     
  711.     TTransaction::close(); // close the transaction
  712. } catch (Exception $ex) {
  713.     new TMessage('error''ma oee ' $ex->getMessage().' file: '.$ex->getFile().' line: '.$ex->getLine());
  714. }
  715. }
  716. /**
  717.      * Show the page
  718.      */
  719.     public function show() {
  720.         parent::show();
  721.     }
  722. function onTeste($param) {
  723.     echo '<pre>';
  724.     print_r($param);
  725.     echo '<pre>';
  726. }
  727.     /**
  728.      * Remove parcela datagrid session
  729.      */
  730.     public static function deleteBoleto($param)
  731.     {
  732.         $parcelas TSession::getValue('datagrid');
  733.         unset($parcelas$param['id'] ]);
  734.         TSession::setValue('datagrid'$parcelas);
  735.     }
  736. }
  737. ?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (3)


NR

A função onSave é static, com isso o construtor não é chamado e não é feita a conversão dos valores e datas. Você vai ter que converter manualmente:
www.adianti.com.br/forum/pt/view_2287?conversao-de-datas-e-valores-m
JA

Olá, Nataniel Rabalioli!

obrigado por responder

Já fiz com esse exemplo que vc indicou e não deu certo tbm.
JA

Olá, Nataniel Rabalioli!

Fiz da forma que vc indicou no link e troquei $id por $key, veja como:

  1. <?php
  2. if (isset($param['key'])){
  3.         $key $param['key'];  // OBTÉM O PARÂMETRO $key
  4.         TTransaction::open('db_guiansoft'); // ABRE A TRANSAÇÃO
  5.         $object = new SystemAluno($key); // INSTANCIA O ACTIVE RECORD
  6. ?>


onde esta key erra id e deu certo!

Obrigado amigo!