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. $this->form->appendPage('Aluno');
  240. // SEPARAR
  241. $this->form->addFields( [new TFormSeparator(('Dados do Aluno'))] );
  242. $this->form->addFields([new TLabel('Código:')], [$id], [new TLabel(('Matricula:'))], [$matricula]);
  243. $this->form->addFields([new TLabel(('Nome:'))], [$name]);
  244. $this->form->addFields([new TLabel('Gênero:')], [$genero_id], [new TLabel('Nascimento:')], [$nascimento]);
  245. $this->form->addFields([new TLabel('CPF:')], [$cpf], [new TLabel('RG:')], [$rg]);
  246. $this->form->addFields([new TLabel('Tel. Aluno:')], [$telefone], [new TLabel('Cel. Aluno:')], [$celular]);
  247. $this->form->addFields([new TLabel('Data da Matrícula:')], [$data_matricula], [new TLabel('Foto:')], [$photo_path]);
  248. $this->frame = new TElement('div');
  249. $this->frame->id = 'photo_path';
  250. $this->frame->style = 'width:180px;height:auto;min-height:180px;border:1px solid gray;padding:4px;';
  251. // SEPARAR
  252. $this->form->addFields( [new TFormSeparator(('Filiação'))] );
  253. $this->form->addFields([new TLabel('Pai:')], [$nomePai], [new TLabel('Mãe:')], [$nomeMae]);
  254. $this->form->addFields([new TLabel('Cel. Pai:')], [$celPai], [new TLabel('Cel. Mãe:')], [$celMae]);
  255. // SEPARAR
  256. $this->form->addFields( [new TFormSeparator(('Endereço do Aluno'))] );
  257. $this->form->addFields([new TLabel('CEP:')], [$cep], [$btnCep]);
  258. $this->form->addFields([new TLabel('Logradouro:')], [$logradouro], [new TLabel('Número:')], [$numero]);
  259. $this->form->addFields([new TLabel('Complemento:')], [$complemento], [new TLabel('Bairro:')], [$bairro]);
  260. $this->form->addFields([new TLabel('Cidade:')], [$cidade], [new TLabel('Estado:')], [$uf]);
  261. $this->form->appendPage('Responsável Financeiro');
  262. $this->form->addFields([new TLabel('Nome:')], [$nomeResp]);
  263. $this->form->addFields([new TLabel('Gênero:')], [$generoRespId], [new TLabel('Nascimento:')], [$nascimentoResp]);
  264. $this->form->addFields([new TLabel('RG:')], [$rgResp], [new TLabel('CPF:')], [$cpfResp]);
  265. $this->form->addFields([new TLabel('Cel.:')], [$celularResp], [new TLabel('Tel.:')], [$telefoneResp]);
  266. $this->form->addFields([new TLabel('E-mail:')], [$emailResp]);
  267. // SEPARAR
  268. $this->form->addFields( [new TFormSeparator(('Endereço'))] );
  269. $this->form->addFields([new TLabel('CEP:')], [$cepResp], [$btnRespCep]);
  270. $this->form->addFields([new TLabel('Logradouro:')], [$logradouroResp], [new TLabel('Complemento:')], [$complementoResp]);
  271. $this->form->addFields([new TLabel('Número:')], [$numeroResp], [new TLabel('Bairro:')], [$bairroResp]);
  272. $this->form->addFields([new TLabel('Cidade:')], [$cidadeResp], [new TLabel('Estado:')], [$ufResp]);
  273. // SEPARAR
  274. $this->form->addFields( [new TFormSeparator(('Endereço de Trabalho'))] );
  275. $this->form->addFields([new TLabel('Empresa:')], [$empresaResp], [new TLabel('Profissão:')], [$profissao_id]);
  276. $this->form->addFields([new TLabel('End. Prof.:')], [$endProfissional], [new TLabel('Tel. Prof.:')], [$telProfissional]);
  277. // SEPARAR
  278. $this->form->addFields( [new TFormSeparator(('Dados Finánceiro'))] );
  279. $this->form->addFields( [new TLabel('Vencimento:')], [$vencimento], [new TLabel('Desconto em %:')], [$desconto]);
  280. $this->form->appendPage('Ficha Médica');
  281. $this->form->addFields([new TLabel('Tipo Sanguíneo:')], [$tipoSanguineo], [new TLabel('Alergias:')], [$alergia]);
  282. $this->form->addFields([new TLabel('Problemas de saúde?')], [$problemaSaude], [new TLabel('Quem chamar para urgência?')], [$chamarUrgencia]);
  283. // TURMA
  284. $this->form->appendPage('Turmas');
  285. $aluno_id = new TEntry('aluno_id[]');
  286. $barcode = new TEntry('barcode[]');
  287. $periodo_id = new TDBCombo('periodo_id[]','db_guiansoft','SystemPeriodo','id','nome');
  288. $curso_id = new TDBCombo('curso_id[]','db_guiansoft','SystemCurso','id','nome');
  289. $modulo_id = new TDBCombo('modulo_id[]','db_guiansoft','SystemModulo','id','nome');
  290. $turma_id = new TDBCombo('turma_id[]','db_guiansoft','SystemTurma','id','nome');
  291. $situacao_id = new TDBCombo('situacao_id[]','db_guiansoft','SystemSituacaoAlunoTurma','id','nome');
  292. // set exit action for input_exit
  293. $change_action = new TAction(array($this, 'onChangeActionModulo'));
  294. $modulo_id->setChangeAction($change_action);
  295. // DEFINE TAMANHO
  296. $aluno_id->setSize('100%');
  297. $barcode->setSize(120);
  298. $periodo_id->setSize('100%');
  299. $curso_id->setSize('100%');
  300. $modulo_id->setSize('100%');
  301. $turma_id->setSize('100%');
  302. $situacao_id->setSize('100%');
  303. $this->system_aluno_turmas_list = new TFieldList;
  304. $this->system_aluno_turmas_list->addField( '<b>'.('ID').'</b>', $aluno_id);
  305. $this->system_aluno_turmas_list->addField( '<b>'.('Barcode').'</b>', $barcode);
  306. $this->system_aluno_turmas_list->addField( '<b>'.('Período').'</b>', $periodo_id);
  307. $this->system_aluno_turmas_list->addField( '<b>'.('Curso').'</b>', $curso_id);
  308. $this->system_aluno_turmas_list->addField( '<b>'.('Módulo').'</b>', $modulo_id);
  309. $this->system_aluno_turmas_list->addField( '<b>'.('Turma').'</b>', $turma_id);
  310. $this->system_aluno_turmas_list->addField( '<b>'.('Situação').'</b>', $situacao_id);
  311. $this->system_aluno_turmas_list->enableSorting();
  312. $this->form->addField($aluno_id);
  313. $this->form->addField($barcode);
  314. $this->form->addField($periodo_id);
  315. $this->form->addField($curso_id);
  316. $this->form->addField($modulo_id);
  317. $this->form->addField($turma_id);
  318. $this->form->addField($situacao_id);
  319. $this->form->addContent( [new TLabel('Turmas')], [$this->system_aluno_turmas_list] );
  320. // FIM TURMAS
  321. // COBRANÇA
  322. $this->form->appendPage('Cobranças');
  323. $plano_pagamento_id->setExitAction(new TAction(array($this,'onPlanoChange')));
  324. $this->form->addFields( [new TLabel('Periodo:')], [$periodoc_id] );
  325. $this->form->addFields( [new TLabel('Plano de pagamento:')], [$plano_pagamento_id, $plano_pagamento_nome], [new TLabel('Parcelas:')], [$parcela] );
  326. $this->form->addFields( [new TLabel('Valor Total:')], [$valor_boleto], [new TLabel(('Status Pagamento:'))], [$status_pagamento_id] );
  327. $this->form->addFields( [new TFormSeparator(('Parcelas'))] );
  328. // BUSCA PARCELA POR PERIODO E STATUS
  329. $this->form->addFields( [ $lp=new TLabel(('Periodo'))], [$periodos_id], [$ls=new TLabel(('Status Pagamento'))], [$status_pagamentos_id] );
  330. // DEFINE A COR
  331. $lp->setFontColor('red');
  332. $ls->setFontColor('red');
  333. $this->form->addFields( [$vbox1] );
  334. // FORMATA O VALOR DA PARCELA NO DATAGRID, NO PADÃO -> R$ 1.000,99
  335. $format_value = function($value) {
  336. if (is_numeric($value)) {
  337. return 'R$ '.number_format($value, 2, ',', '.');
  338. }
  339. return $value;
  340. };
  341. $column_valor_boleto->setTransformer( $format_value );
  342. // FIM COBRANÇA
  343. // wrap the page content
  344. $container = new TVBox;
  345. $container->style = 'width: 100%';
  346. $container->add(new TXMLBreadCrumb('menu.xml', 'AlunoList'));
  347. $container->add($this->form);
  348. // add the container to the page
  349. parent::add($container);
  350. }
  351. /**
  352. * On complete upload photo_path
  353. */
  354. public static function onComplete($param)
  355. {
  356. new TMessage('info', 'Upload completo: ' . $param['photo_path']);
  357. copy("tmp/{$param['photo_path']}", "files/fotos/alunos/{$param['photo_path']}");
  358. // refresh photo_frame
  359. TScript::create("$('#photo_frame').html('')");
  360. TScript::create("$('#photo_frame').html(\"<img width='180px' height='180px' src='files/fotos/alunos/{$param['photo_path']}'>\");");
  361. }
  362. /*
  363. * Função de busca de Endereço pelo CEP
  364. * - Desenvolvido Felipe Olivaes para ajaxbox.com.br
  365. * - Utilizando WebService de CEP da republicavirtual.com.br
  366. */
  367. public static function onCep($param)
  368. {
  369. $resultado = @file_get_contents('http://republicavirtual.com.br/web_cep.php?cep=' . urlencode($param['cep']) . '&formato=query_string');
  370. if (!$resultado) {
  371. $resultado = "&resultado=0&resultado_txt=erro+ao+buscar+cep";
  372. }
  373. parse_str($resultado, $retorno);
  374. $obj = new StdClass;
  375. $obj->cep = $param['cep'];
  376. $obj->logradouro = strtoupper($retorno['tipo_logradouro'] . ' ' . $retorno['logradouro']);
  377. $obj->bairro = strtoupper($retorno['bairro']);
  378. $obj->cidade = strtoupper($retorno['cidade']);
  379. $obj->uf = strtoupper($retorno['uf']);
  380. TForm::sendData('form_Aluno', $obj);
  381. }
  382. /*
  383. * Função de busca de Endereço pelo CEP
  384. * - Desenvolvido Felipe Olivaes para ajaxbox.com.br
  385. * - Utilizando WebService de CEP da republicavirtual.com.br
  386. */
  387. public static function onRespCep($param)
  388. {
  389. $resultado = @file_get_contents('http://republicavirtual.com.br/web_cep.php?cep=' . urlencode($param['cepResp']) . '&formato=query_string');
  390. if (!$resultado) {
  391. $resultado = "&resultado=0&resultado_txt=erro+ao+buscar+cep";
  392. }
  393. parse_str($resultado, $retorno);
  394. $obj = new StdClass;
  395. $obj->cepResp = $param['cepResp'];
  396. $obj->logradouroResp = strtoupper($retorno['tipo_logradouro'] . ' ' . $retorno['logradouro']);
  397. $obj->bairroResp= strtoupper($retorno['bairro']);
  398. $obj->cidadeResp = strtoupper($retorno['cidade']);
  399. $obj->ufResp = strtoupper($retorno['uf']);
  400. TForm::sendData('form_Aluno', $obj);
  401. }
  402. /**
  403. * Action to be executed when the user changes the modulo_id field
  404. */
  405. public static function onChangeActionModulo($param)
  406. {
  407. TTransaction::open('db_guiansoft');
  408. $criteria = new TCriteria;
  409. $criteria->add(new TFilter('modulo_id', '=', $param['modulo_id']));
  410. $repository = new TRepository('SystemTurma');
  411. $turmas = $repository->load($criteria);
  412. $options = array();
  413. foreach ($turmas as $turma){
  414. $options[$turma->id] = $turma->nome;
  415. }
  416. //TForm::sendData('form_Aluno', $objeto);
  417. TCombo::reload('form_Aluno', 'turma_id[]', $options);
  418. }
  419. /**
  420. * On product change
  421. */
  422. static function onPlanoChange( $params )
  423. {
  424. if( isset($params['plano_pagamento_id']) && $params['plano_pagamento_id'] )
  425. {
  426. try
  427. {
  428. TTransaction::open('db_guiansoft');
  429. $systemplanopagamento = new SystemPlanoPagamento($params['plano_pagamento_id']);
  430. $fill_data = new StdClass;
  431. $fill_data->parcela = $systemplanopagamento->prazo;
  432. $fill_data->valor_boleto = $systemplanopagamento->valor_total;
  433. TForm::sendData('form_Aluno', $fill_data);
  434. TTransaction::close();
  435. }
  436. catch (Exception $e) // in case of exception
  437. {
  438. new TMessage('error', $e->getMessage());
  439. TTransaction::rollback();
  440. }
  441. }
  442. }
  443. /**
  444. * Reload the item list
  445. * @param $param URL parameters
  446. */
  447. public function onReload($param)
  448. {
  449. // read session items
  450. $parcelas = TSession::getValue(__CLASS__ . '_parcelas');
  451. $this->datagrid->clear(); // clear detail list
  452. $data = $this->form->getData();
  453. if ($system_aluno_parcelas)
  454. {
  455. $cont = 1;
  456. foreach ($system_aluno_parcelas as $parcelas_id => $parcelas)
  457. {
  458. $system_aluno_parcela->id = $parcelas['id'];
  459. $system_aluno_parcela->numero_documento = $parcelas['numero_documento'];
  460. $system_aluno_parcela->nomeResp = $parcelas['nomeResp'];
  461. $system_aluno_parcela->parcela = $parcelas['parcela'];
  462. $system_aluno_parcela->vencimento = $parcelas['vencimento'];
  463. $system_aluno_parcela->valor_boleto = $parcelas['valor_boleto'];
  464. $system_aluno_parcela->status_pagamento_id = $parcelas['status_pagamento_id'];
  465. $row = $this->datagrid->addSystemAlunoParcela( $system_aluno_parcela );
  466. $row->onmouseover = '';
  467. $row->onmouseout = '';
  468. }
  469. $this->form->setFields( $this->formFields );
  470. }
  471. $this->loaded = TRUE;
  472. }
  473. /**
  474. * method onEdit
  475. * Edit a record data
  476. */
  477. function onEdit($param)
  478. {
  479. try
  480. {
  481. if (isset($param['id'])){
  482. $id = $param['id']; // OBTÉM O PARÂMETRO $key
  483. TTransaction::open('db_guiansoft'); // ABRE A TRANSAÇÃO
  484. $system_aluno = new SystemAluno($param['id']); // INSTANCIA O ACTIVE RECORD
  485. // load the contacts (composition)
  486. $system_aluno_turmas = $system_aluno->getSystemAlunoTurmas();
  487. $system_aluno_parcelas = $system_aluno->getSystemAlunoParcelas();
  488. if ($system_aluno_parcelas) {
  489. foreach ($system_aluno_parcelas as $system_aluno_parcela) {
  490. $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
  491. $this->datagrid->addItem($system_aluno_parcela); // add the detail inside the datagrid
  492. }
  493. }
  494. // TURMAS
  495. if ($system_aluno_turmas) {
  496. $this->system_aluno_turmas_list->addHeader();
  497. foreach ($system_aluno_turmas as $system_aluno_turma)
  498. {
  499. $system_aluno_turma->system_aluno_turma_id = $system_aluno_turma->id;
  500. $this->system_aluno_turmas_list->addDetail($system_aluno_turma);
  501. }
  502. $this->system_aluno_turmas_list->addCloneAction();
  503. }
  504. else
  505. {
  506. $this->clearSystemAlunoTurmas();
  507. }
  508. $this->form->setData($system_aluno); // PREENCHE O FORM
  509. TTransaction::close(); // FECHA A TRANSAÇÃO
  510. }
  511. else {
  512. $this->onClear($param);
  513. $this->form->clear();
  514. TSession::setValue('$system_aluno_parcelas', null);
  515. $this->onReload( $param );
  516. }
  517. }
  518. catch (Exception $e) // in case of exception
  519. {
  520. new TMessage('error', $e->getMessage());
  521. TTransaction::rollback();
  522. }
  523. }
  524. /**
  525. * Clear Turmas
  526. */
  527. public function clearSystemAlunoTurmas()
  528. {
  529. $this->system_aluno_turmas_list->addHeader();
  530. $this->system_aluno_turmas_list->addDetail( new stdClass );
  531. $this->system_aluno_turmas_list->addCloneAction();
  532. }
  533. /**
  534. * Clear form
  535. */
  536. public function onClear()
  537. {
  538. $this->form->clear();
  539. $this->clearSystemAlunoTurmas();
  540. $this->clearSystemAlunoParcelas();
  541. TSession::setValue(__CLASS__ . '_parcelas', array());
  542. $this->onReload($param);
  543. }
  544. /**
  545. * method onSave
  546. * Executed whenever the user clicks at the save button
  547. */
  548. public static function onSave($param)
  549. {
  550. try
  551. {
  552. // ABRE UMA TRANSAÇÃO COM O BANCO DE DADOS
  553. TTransaction::open('db_guiansoft');
  554. // read the form data and instantiates an Active Record
  555. $system_aluno = new SystemAluno;
  556. $system_aluno->fromArray( $param );
  557. $system_aluno->clearParts();
  558. var_dump($system_aluno);
  559. if( !empty($param['barcode']) AND is_array($param['barcode']) )
  560. {
  561. foreach( $param['barcode'] as $row => $barcode)
  562. {
  563. if ($barcode)
  564. {
  565. $system_aluno_turma = new SystemAlunoTurma;
  566. $system_aluno_turma->barcode = $barcode;
  567. $system_aluno_turma->id = $param['aluno_id'][$row];
  568. $system_aluno_turma->periodo_id = $param['periodo_id'][$row];
  569. $system_aluno_turma->curso_id = $param['curso_id'][$row];
  570. $system_aluno_turma->modulo_id = $param['modulo_id'][$row];
  571. $system_aluno_turma->turma_id = $param['turma_id'][$row];
  572. $system_aluno_turma->situacao_id = $param['situacao_id'][$row];
  573. $system_aluno->addSystemAlunoTurma( $system_aluno_turma );
  574. }
  575. }
  576. }
  577. $system_aluno->store(); // SALAVA O OBJETO
  578. $data = new stdClass;
  579. $data->id = $system_aluno->id;
  580. TForm::sendData('form_aluno', $data);
  581. // shows the success message
  582. new TMessage('info', 'Record saved');
  583. TTransaction::close(); // close the transaction
  584. }
  585. catch (Exception $e) // in case of exception
  586. {
  587. new TMessage('error', $e->getMessage());
  588. // undo all pending operations
  589. TTransaction::rollback();
  590. }
  591. }
  592. /*
  593. * - Função de Gerar parcelas
  594. * - Indev (ajuda ate ajudar) kkkk
  595. */
  596. function onGerarParcelas($param)
  597. {
  598. try {
  599. // ABRE UMA TRANSAÇÃO COM O BANCO DE DADOS
  600. TTransaction::open('db_guiansoft');
  601. // read the form data and instantiates an Active Record
  602. $system_aluno = new SystemAluno($param['id']);
  603. $this->datagrid->clear(); // LIMPA A GRID
  604. $this->form->validate(); // VERIFICA OS CAMPOS OBRIGATORIOS E FAZ A VALIDAÇÃO
  605. $old_parcelas = SystemAlunoParcela::where('aluno_id', '=', $system_aluno->id)->load();
  606. $keep_parcelas = array();
  607. // get session items
  608. $items = TSession::getValue(__CLASS__ . '_parcelas');
  609. if (!is_null($items) && ! empty($items)) {
  610. foreach ($items as $item) {
  611. if (substr($item->id, 0, 1) == 'X') { // new record
  612. $system_aluno_parcela = new SystemAlunoParcela;
  613. // recebe dados informado pelo usuário
  614. $system_aluno_parcela->fromArray($item) ;
  615. $system_aluno_parcela->aluno_id = $system_aluno->id;
  616. $system_aluno_parcela->store(); // salva o objeto
  617. } else {
  618. $system_aluno_parcela = new SystemAlunoParcela($item->id);
  619. echo "ja existe parcelas";
  620. }
  621. $keep_parcelas[] = $system_aluno_parcela->id;
  622. $this->addParcelasAluno($system_aluno,$system_aluno_parcela);;
  623. }
  624. TSession::setValue(__CLASS__ . '_parcelas', null);
  625. }else{
  626. // chama a função que realiza o calculo da divisão e tbm realiza o calculo dos dos vencimentos - retorna um array
  627. $parcelas = GerarParcelas::calcularParcelas($param['valor_boleto'],
  628. $param['parcela'], $param['vencimento'],
  629. $param['nomeResp'], $param['cpfResp'], $param['logradouroResp'],
  630. $param['numeroResp'], $param['bairroResp'], $param['cepResp'],
  631. $param['cidadeResp'], $param['plano_pagamento_nome'], $param['ufResp'],
  632. $param['name'], $param['status_pagamento_id'], null);
  633. foreach ($parcelas as $parcela) {
  634. $this->addParcelasAluno($system_aluno,$parcela); // adciona as parcelas
  635. }
  636. // armazena as parcelas sem uma variavel de sessão
  637. TSession::setValue(__CLASS__ . '_parcelas', $parcelas);
  638. }
  639. if ($old_parcelas) {
  640. foreach ($old_parcelas as $old_item) {
  641. if (!in_array($old_item->id, $keep_parcelas)) {
  642. $old_item->delete();
  643. }
  644. }
  645. }
  646. $parcelas = TSession::getValue(__CLASS__ . '_parcelas');
  647. // laço onde add na grid a divisão - os centavos são adicionados na ultima parcela
  648. foreach ($parcelas as $parcela) {
  649. // adiciona as parcelas na grid
  650. $item = new StdClass;
  651. $item->detail_id = empty($parcela->detail_id) ? 'X' . mt_rand(10000000, 19999999) : $parcela->detail_id;
  652. $item->id = $parcela->id;
  653. $item->nosso_numero = $parcela->nosso_numero;
  654. $item->numero_documento = $parcela->numero_documento;
  655. $item->name = $parcela->name;
  656. $item->nomeResp = $parcela->nomeResp;
  657. $item->cpfResp = $parcela->cpfResp;
  658. $item->cepResp = $parcela->cepResp;
  659. $item->logradouroResp = $parcela->logradouroResp;
  660. $item->numeroResp = $parcela->numeroResp;
  661. $item->bairroResp = $parcela->bairroResp;
  662. $item->cidadeResp = $parcela->cidadeResp;
  663. $item->ufResp = $parcela->ufResp;
  664. $item->parcela = $parcela->parcela;
  665. $item->vencimento = DateTime::createFromFormat('d/m/Y', $parcela->vencimento)->format( 'Y-m-d' );
  666. $item->plano_pagamento_nome = $parcela->plano_pagamento_nome;
  667. $item->valor_boleto = ($parcela->valor_boleto);
  668. $item->status_pagamento_id = $parcela->status_pagamento_id;
  669. $this->datagrid->addItem($item);
  670. }
  671. $data = new stdClass;
  672. TForm::sendData('form_aluno', $data);
  673. $this->form->setData($this->form->getData());
  674. TTransaction::close(); // close the transaction
  675. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  676. } catch (Exception $ex) {
  677. new TMessage('error', 'ma oee ' . $ex->getMessage().' file: '.$ex->getFile().' line: '.$ex->getLine());
  678. TTransaction::rollback();
  679. }
  680. }
  681. private function addParcelasAluno($system_aluno, $parcela){
  682. try {
  683. // abri uma transação com banco de dados 'db_guiansoft'
  684. TTransaction::open('db_guiansoft');
  685. $system_aluno_parcela = new SystemAlunoParcela;
  686. $system_aluno_parcela->nosso_numero = $parcela->nosso_numero;
  687. $system_aluno_parcela->numero_documento = $parcela->numero_documento;
  688. $system_aluno_parcela->aluno_id = $system_aluno->id;
  689. $system_aluno_parcela->name = $parcela->name;
  690. $system_aluno_parcela->nomeResp = $parcela->nomeResp;
  691. $system_aluno_parcela->cpfResp = $parcela->cpfResp;
  692. $system_aluno_parcela->cepResp = $parcela->cepResp;
  693. $system_aluno_parcela->logradouroResp = $parcela->logradouroResp;
  694. $system_aluno_parcela->numeroResp = $parcela->numeroResp;
  695. $system_aluno_parcela->bairroResp = $parcela->bairroResp;
  696. $system_aluno_parcela->cidadeResp = $parcela->cidadeResp;
  697. $system_aluno_parcela->ufResp = $parcela->ufResp;
  698. $system_aluno_parcela->valor_boleto = ($parcela->valor_boleto);
  699. $system_aluno_parcela->parcela = $parcela->parcela;
  700. $system_aluno_parcela->plano_pagamento_nome = $parcela->plano_pagamento_nome;
  701. $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
  702. $system_aluno_parcela->status_pagamento_id = $parcela->status_pagamento_id;
  703. $system_aluno_parcela->store(); // salva o objeto
  704. $system_aluno->addSystemAlunoParcela($system_aluno_parcela); // aqui salva a parecela
  705. $system_aluno->store(); // salva o objeto
  706. TTransaction::close(); // close the transaction
  707. } catch (Exception $ex) {
  708. new TMessage('error', 'ma oee ' . $ex->getMessage().' file: '.$ex->getFile().' line: '.$ex->getLine());
  709. }
  710. }
  711. /**
  712. * Show the page
  713. */
  714. public function show() {
  715. parent::show();
  716. }
  717. function onTeste($param) {
  718. echo '<pre>';
  719. print_r($param);
  720. echo '<pre>';
  721. }
  722. /**
  723. * Remove parcela datagrid session
  724. */
  725. public static function deleteBoleto($param)
  726. {
  727. $parcelas = TSession::getValue('datagrid');
  728. unset($parcelas[ $param['id'] ]);
  729. TSession::setValue('datagrid', $parcelas);
  730. }
  731. }
  732. ?>

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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!