IU
Formulário Mestre/Detalhe
Olá Pessoal,
Estou recebendo esta mensagem quando tento salvar um registro no Formulário Mestre/Detalhe
Alguém sabe me dizer o problema ?
Agradeço a ajuda
Abaixo segue o código todo do CarregamentoForm.class.php
Estou recebendo esta mensagem quando tento salvar um registro no Formulário Mestre/Detalhe
Alguém sabe me dizer o problema ?
Agradeço a ajuda
Abaixo segue o código todo do CarregamentoForm.class.php
- <?php
- /**
- * CarregamentoForm Master/Detail
- * @author <your name here>
- */
- class CarregamentoForm extends TPage
- {
- protected $form; // form
- protected $table_details;
- protected $detail_row;
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct($param)
- {
- parent::__construct($param);
- // creates the form
- $this->form = new TForm('form_Carregamento');
- $this->form->class = 'tform'; // CSS class
- $table_master = new TTable;
- $table_master->width = '100%';
- $table_master->addRowSet( new TLabel('Carregamento'), '', '')->class = 'tformtitle';
- // add a table inside form
- $table_general = new TTable;
- $table_general->width = '100%';
- $frame_general = new TFrame;
- $frame_general->class = 'tframe tframe-custom';
- $frame_general->setLegend('Carregamento');
- $frame_general->style = 'background:whiteSmoke';
- $frame_general->add($table_general);
- $frame_details = new TFrame;
- $frame_details->class = 'tframe tframe-custom';
- $frame_details->style = 'background:whiteSmoke';
- $frame_details->setLegend('CarregamentoImportacao');
- $table_master->addRow()->addCell( $frame_general )->colspan=2;
- $row = $table_master->addRow();
- $row->addCell( $frame_details );
- $this->form->add($table_master);
- // master fields
- $carregamento_id = new TEntry('carregamento_id');
- $dt_saida_porto = new TDate('dt_saida_porto');
- $dt_previsao = new TDate('dt_previsao');
- $transportadora = new TCombo('transportadora');
- $transportadorai = array();
- $transportadorai['I'] = 'ITRI';
- $transportadorai['R'] = 'RODOTECH';
- $transportadora->addItems($transportadorai);
- $modal = new TCombo('modal');
- $modali = array();
- $modali['M'] = 'MULTIMODAL';
- $modali['R'] = 'RODOVIÁRIO';
- $modal->addItems($modali);
- $status = new TCombo('status');
- $statusi = array();
- $statusi['S'] = 'SIM';
- $statusi['N'] = 'NÃO';
- $status->addItems($statusi);
- $motorista_id = new TDBCombo('motorista_id', 'itisu420_sistema2', 'Motorista', 'motorista_id', '{motorista_nome} - {cnh_validade}');
- $cavalo_id = new TDBCombo('cavalo_id', 'itisu420_sistema2', 'Cavalo', 'cavalo_id', '{cavalo} - {cor} - {ano}');
- $carreta_id = new TDBCombo('carreta_id', 'itisu420_sistema2', 'Carreta', 'carreta_id', '{carreta} - {cor} - {ano}');
- // máscaras
- $dt_saida_porto->setMask('dd/mm/yyyy');
- $dt_previsao->setMask('dd/mm/yyyy');
- $transportadora->enableSearch();
- $modal->enableSearch();
- $status->enableSearch();
- $motorista_id->enableSearch();
- $cavalo_id->enableSearch();
- $carreta_id->enableSearch();
- // sizes
- $carregamento_id->setSize('200');
- $dt_saida_porto->setSize('200');
- $dt_previsao->setSize('200');
- $transportadora->setSize('200');
- $modal->setSize('200');
- $status->setSize('200');
- $motorista_id->setSize('300');
- $cavalo_id->setSize('300');
- $carreta_id->setSize('300');
- if (!empty($carregamento_id))
- {
- $carregamento_id->setEditable(FALSE);
- }
- // add form fields to be handled by form
- $this->form->addField($carregamento_id);
- $this->form->addField($dt_saida_porto);
- $this->form->addField($dt_previsao);
- $this->form->addField($transportadora);
- $this->form->addField($modal);
- $this->form->addField($status);
- $this->form->addField($motorista_id);
- $this->form->addField($cavalo_id);
- $this->form->addField($carreta_id);
- // add form fields to the screen
- $table_general->addRowSet( new TLabel('Carregamento Id'), $carregamento_id );
- $table_general->addRowSet( new TLabel('Dt Saida Porto'), $dt_saida_porto );
- $table_general->addRowSet( new TLabel('Dt Previsao'), $dt_previsao );
- $table_general->addRowSet( new TLabel('Transportadora'), $transportadora );
- $table_general->addRowSet( new TLabel('Modal'), $modal );
- $table_general->addRowSet( new TLabel('Status'), $status );
- $table_general->addRowSet( new TLabel('Motorista Id'), $motorista_id );
- $table_general->addRowSet( new TLabel('Cavalo Id'), $cavalo_id );
- $table_general->addRowSet( new TLabel('Carreta Id'), $carreta_id );
- // detail
- $this->table_details = new TTable;
- $this->table_details-> width = '100%';
- $frame_details->add($this->table_details);
- $this->table_details->addSection('thead');
- $row = $this->table_details->addRow();
- // detail header
- $row->addCell( new TLabel('Importacao Id') );
- // create an action button (save)
- $save_button=new TButton('save');
- $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
- $save_button->setImage('fa:circle red fa-lg');//('ico_save.png');
- // create an new button (edit with no parameters)
- $new_button=new TButton('new');
- $new_button->setAction(new TAction(array($this, 'onClear')), _t('New'));
- $new_button->setImage('fa:file fa-lg');//('ico_new.png');
- // define form fields
- $this->form->addField($save_button);
- $this->form->addField($new_button);
- $table_master->addRowSet( array($save_button, $new_button), '', '')->class = 'tformaction'; // CSS class
- $this->detail_row = 0;
- // create the page container
- $container = new TVBox;
- $container->style = 'width: 100%';
- //$container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Executed whenever the user clicks at the edit button da datagrid
- */
- function onEdit($param)
- {
- try
- {
- TTransaction::open('itisu420_sistema2');
- if (isset($param['key']))
- {
- $key = $param['key'];
- $object = new Carregamento($key);
- $object->dt_saida_porto = TDate::date2br($object->dt_saida_porto);
- $object->dt_previsao = TDate::date2br($object->dt_previsao);
- $this->form->setData($object);
- $items = CarregamentoImportacao::where('carregamento_id', '=', $key)->load();
- $this->table_details->addSection('tbody');
- if ($items)
- {
- foreach($items as $item )
- {
- $this->addDetailRow($item);
- }
- // create add button
- $add = new TButton('clone');
- $add->setLabel('Adicionar');
- $add->setImage('fa:plus');
- $add->addFunction('ttable_clone_previous_row(this)');
- // add buttons in table
- $this->table_details->addRowSet([$add]);
- }
- else
- {
- $this->onClear($param);
- }
- TTransaction::close(); // close transaction
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- /**
- * Add detail row
- */
- public function addDetailRow($item)
- {
- $uniqid = mt_rand(1000000, 9999999);
- // create fields
- $importacao_id = new TDBMultiSearch('importacao_id[]', 'itisu420_sistema2', 'Importacao', 'importacao_id', 'conteiner');
- //$importacao_id = new TEntry('importacao_id[]');
- $importacao_id->setMaxSize(1);
- $importacao_id->setMinLength(1);
- // set id's
- $importacao_id->setId('importacao_id_'.$uniqid);
- // set sizes
- $importacao_id->setSize('50%');
- // set mask
- $importacao_id->setMask('{conteiner} ({importacao_id})');
- // set row counter
- $importacao_id->{'data-row'} = $this->detail_row;
- // set value
- if (!empty($item->importacao_id)) { $importacao_id->setValue( $item->importacao_id ); }
- // create delete button
- $del = new TImage('fa:ban red fa-lg');
- $del->onclick = 'ttable_remove_row(this)';
- $row = $this->table_details->addRow();
- // add cells
- $row->addCell($importacao_id);
- $row->addCell( $del );
- $row->{'data-row'} = $this->detail_row;
- // add form field
- $this->form->addField($importacao_id);
- $this->detail_row ++;
- }
- /**
- * Clear form
- */
- public function onClear($param)
- {
- $this->table_details->addSection('tbody');
- $this->addDetailRow( new stdClass );
- // create add button
- $add = new TButton('clone');
- $add->setLabel('Adicionar');
- $add->setImage('fa:plus');
- $add->addFunction('ttable_clone_previous_row(this)');
- // add buttons in table
- $this->table_details->addRowSet([$add]);
- }
- /**
- * Save the Carregamento and the CarregamentoImportacao's
- */
- public static function onSave($param)
- {
- try
- {
- TTransaction::open('itisu420_sistema2');
- $id = (int) $param['carregamento_id'];
- $master = new Carregamento;
- $master->fromArray( $param);
- $master->dt_saida_porto = TDate::date2us($master->dt_saida_porto);
- $master->dt_previsao = TDate::date2us($master->dt_previsao);
- $master->store(); // save master object
- // delete details
- CarregamentoImportacao::where('carregamento_id', '=', $master->carregamento_id)->delete();
- if( !empty($param['importacao_id']) AND is_array($param['importacao_id']) )
- {
- foreach( $param['importacao_id'] as $row => $importacao_id)
- {
- if (!empty($importacao_id))
- {
- $detail = new CarregamentoImportacao;
- $detail->carregamento_id = $master->carregamento_id;
- $detail->importacao_id = $param['importacao_id'][$row];
- $detail->store();
- }
- }
- }
- $data = new stdClass;
- $data->carregamento_id = $master->carregamento_id;
- $master->dt_saida_porto = TDate::date2br($master->dt_saida_porto);
- $master->dt_previsao = TDate::date2br($master->dt_previsao);
- TForm::sendData('form_Carregamento', $data);
- TTransaction::close(); // close the transaction
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }
Em anexo está a mensagem de erro.
Erro do banco de dados. Você chegou a exibir os sqls que estão sendo gerados para analisar?
Oi Nataniel, Vou verificar
com o sql_dump já consigo ver onde se encontra o problema ?
Segue var_dump:
Me refiro ao retorno do sql: