AR
erros Undefined Index e Undefined Variable
Tenho um formulário que começou a apresentar erros:
Notice: Undefined index: Oferta_list_dt_oferta on line 563
Notice: Undefined variable: total on line 581
Não estou conseguindo identificar o que está ocorrendo.
está salvando e também somando e enviando a soma dos detalhes normalmente más apresentam o erros na tela após o salvamento.
Notice: Undefined index: Oferta_list_dt_oferta on line 563
Notice: Undefined variable: total on line 581
Não estou conseguindo identificar o que está ocorrendo.
está salvando e também somando e enviando a soma dos detalhes normalmente más apresentam o erros na tela após o salvamento.
- <?php
- /**
- * ReceitaForm Master/Detail
- * @author Alexandre M. Roberto
- */
- class ReceitaForm extends TPage
- {
- protected $form; // form
- protected $detail_list;
- // trait with saveFile, saveFiles, ...
- use Adianti\Base\AdiantiFileSaveTrait;
- /**
- * Page constructor
- */
- public function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Receita');
- $this->form->setFormTitle('Formulário de Receita da Paróquia/Comunidade');
- $this->form->setClientValidation(true);
- // master fields
- $id = new TEntry('id');
- $dt_receita = new TDate('dt_receita');
- $refmes = new TCombo('refmes');
- $refano = new TCombo('refano');
- $contribuicoes = new TEntry('contribuicoes');
- $ofertas = new TEntry('ofertas');
- $doacoes = new TEntry('doacoes');
- $promocoes = new TEntry('promocoes');
- $patrimonial = new TEntry('patrimonial');
- $outros = new TEntry('outros');
- $tot_receitas = new TEntry('tot_receitas');
- $dizimo = new TEntry('dizimo');
- $parcelado = new TEntry('parcelado');
- $parcelado->style = "background-color: #DFE54A";
- $ofertas_a_repassar = new TEntry('ofertas_a_repassar');
- $comprovantes = new TMultiFile('comprovantes');
- $comprovantes->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg', 'pdf'] );
- $comprovantes->enableFileHandling();
- $comprovantes->enableImageGallery();
- $comprovantes->enablePopover('Preview', '<img style="max-width:300px" src="download.php?file={file_name}">');
- $dep_dizimo = new TDate('dep_dizimo');
- $dep_ofertas_a_repassar = new TDate('dep_ofertas_a_repassar');
- $observacoes = new TText('observacoes');
- $dt_receita->setMask('dd/mm/yyyy');
- $dt_receita->setDatabaseMask('yyyy-mm-dd');
- $dt_receita->setValue( date('Y-m-d') );
- $contribuicoes->setNumericMask(2, ',', '.', true);
- $ofertas->setNumericMask(2, ',', '.', true);
- $doacoes->setNumericMask(2, ',', '.', true);
- $promocoes->setNumericMask(2, ',', '.', true);
- $patrimonial->setNumericMask(2, ',', '.', true);
- $outros->setNumericMask(2, ',', '.', true);
- $tot_receitas->setNumericMask(2, ',', '.', true);
- $dizimo->setNumericMask(2, ',', '.', true);
- $ofertas_a_repassar->setNumericMask(2, ',', '.', true);
- $parcelado->setNumericMask(2, ',', '.', true);
- $current = (int) date('Y');
- $refmes->addItems( ['01' => 'Janeiro',
- '02' => 'Fevereiro',
- '03' => 'Março',
- '04' => 'Abril',
- '05' => 'Maio',
- '06' => 'Junho',
- '07' => 'Julho',
- '08' => 'Agosto',
- '09' => 'Setembro',
- '10' => 'Outubro',
- '11' => 'Novembro',
- '12' => 'Dezembro'] );
- $refano->addItems( [ ($current -5) => ($current -5), ($current -4) => ($current -4), ($current -3) => ($current -3), ($current -2) => ($current -2), ($current -1) => ($current -1), $current => $current ] );
- $id->setSize('100%');
- $dt_receita->setSize('100%');
- $refmes->setSize('100%');
- $refano->setSize('100%');
- $contribuicoes->setSize('100%');
- $ofertas->setSize('100%');
- $doacoes->setSize('100%');
- $promocoes->setSize('100%');
- $patrimonial->setSize('100%');
- $outros->setSize('100%');
- $tot_receitas->setSize('100%');
- $tot_receitas->setEditable(FALSE);
- $dizimo->setSize('100%');
- $parcelado->setSize('100%');
- $parcelado->style = ("background-color: #ffff99; text-align: right;");
- $dizimo->setEditable(FALSE);
- $ofertas_a_repassar->setSize('100%');
- $ofertas_a_repassar->setEditable(FALSE);
- $contribuicoes->setValue(0);
- $ofertas->setValue(0);
- $doacoes->setValue(0);
- $promocoes->setValue(0);
- $patrimonial->setValue(0);
- $outros->setValue(0);
- $parcelado->setValue(0);
- $comprovantes->setSize('100%');
- $dep_dizimo->setSize('100%');
- $dep_dizimo->setMask('dd/mm/yyyy');
- $dep_dizimo->setDatabaseMask('yyyy-mm-dd');
- $dep_ofertas_a_repassar->setMask('dd/mm/yyyy');
- $dep_ofertas_a_repassar->setDatabaseMask('yyyy-mm-dd');
- $dep_ofertas_a_repassar->setSize('100%');
- $observacoes->setSize('100%');
- // detail fields
- $detail_uniqid = new THidden('detail_uniqid');
- $detail_id = new THidden('detail_id');
- $detail_dt_oferta = new TDate('detail_dt_oferta');
- $detail_dt_oferta->setMask('dd/mm/yyyy');
- $detail_dt_oferta->setDatabaseMask('yyyy-mm-dd');
- $detail_plano_id = new TDBCombo('detail_plano_id', 'sinodo', 'Plano', 'id', '{favorecido} ({oferta_tipo->nome})');
- $detail_plano_id->setEditable(FALSE);
- $detail_plano_id->setSize('100%');
- $detail_valor = new TNumeric('detail_valor', 2, ',', '.', true);
- $refmes->addValidation('Mês', new TRequiredValidator);
- $refano->addValidation('Ano', new TRequiredValidator);
- $detail_deposito = new TDate('detail_deposito');
- $detail_deposito->setMask('dd/mm/yyyy');
- $detail_deposito->setDatabaseMask('yyyy-mm-dd');
- // exit action
- $detail_dt_oferta->setExitAction(new TAction([$this,'onExitDate']));
- if (!empty($id))
- {
- $id->setEditable(FALSE);
- }
- // master fields
- $row = $this->form->addFields( [ new TLabel('Id'), $id ],
- [ new TLabel('Data'), $dt_receita ],
- [ new TLabel('Mês'), $refmes ],
- [ new TLabel('Ano'), $refano ] );
- $row->layout = ['col-sm-3', 'col-sm-3', 'col-sm-3', 'col-sm-3' ];
- $row = $this->form->addFields( [ new TLabel('Contribuições'), $contribuicoes ],
- [ new TLabel('Ofertas'), $ofertas ],
- [ new TLabel('Doações'), $doacoes ],
- [ new TLabel('Promoções'), $promocoes ]);
- $row->layout = ['col-sm-3', 'col-sm-3', 'col-sm-3', 'col-sm-3' ];
- $row = $this->form->addFields( [ new TLabel('Renda Patrimonial'), $patrimonial ],
- [ new TLabel('Outras Receitas'), $outros ],
- [ new TLabel('Total Receitas'), $tot_receitas ],
- [ new TLabel('Dizimo (10%)'), $dizimo ]);
- $row->layout = ['col-sm-3', 'col-sm-3','col-sm-3', 'col-sm-3' ];
- $row = $this->form->addFields( [ new TLabel('Data do Depósito Dízimo (10%)'), $dep_dizimo ],
- [ new TLabel('<b>Dízimo em atrazo / parcelado</b>'), $parcelado ] );
- $row->layout = ['col-sm-3', 'col-sm-3' ];
- $label4 = new TLabel('Comprovantes', '#5A73DB', 12, '');
- $label4->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%; padding-top: 25px;';
- $this->form->addContent( [$label4] );
- $row = $this->form->addFields( [ $comprovantes ]);
- $row->layout = ['col-sm-12' ];
- $contribuicoes->setExitAction(new TAction(array($this, 'onUpdateTotal')));
- $ofertas->setExitAction(new TAction(array($this, 'onUpdateTotal')));
- $doacoes->setExitAction(new TAction(array($this, 'onUpdateTotal')));
- $patrimonial->setExitAction(new TAction(array($this, 'onUpdateTotal')));
- $promocoes->setExitAction(new TAction(array($this, 'onUpdateTotal')));
- $outros->setExitAction(new TAction(array($this, 'onUpdateTotal')));
- $parcelado->setExitAction(new TAction(array($this, 'onUpdateTotal')));
- // detail fields
- $label4 = new TLabel('Ofertas a Repassar', '#5A73DB', 12, '');
- $label4->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%; padding-top: 25px;';
- $this->form->addContent( [$label4] );
- $this->form->addFields( [$detail_uniqid] );
- $this->form->addFields( [$detail_id] );
- $row = $this->form->addFields( [ new TLabel('Data Oferta'), $detail_dt_oferta ],
- [ new TLabel('Favorecido'), $detail_plano_id ],
- [ new TLabel('Data Depósito'), $detail_deposito ],
- [ new TLabel('Valor'), $detail_valor ]);
- $row->layout = ['col-sm-2', 'col-sm-6', 'col-sm-2', 'col-sm-2'];
- $add = TButton::create('add', [$this, 'onDetailAdd'], _t('Register'), 'fa:plus-circle green');
- $add->getAction()->setParameter('static','1');
- $this->form->addFields( [], [$add] );
- $this->detail_list = new BootstrapDatagridWrapper(new TDataGrid);
- $this->detail_list->setId('Oferta_list');
- $this->detail_list->setHeight(150);
- $this->detail_list->makeScrollable();
- $this->detail_list->generateHiddenFields();
- $this->detail_list->style = "min-width: 700px; width:100%;margin-bottom: 10px";
- // items
- $col_uniq = new TDataGridColumn( 'uniqid', 'Uniqid', 'center', '10%');
- $col_id = new TDataGridColumn( 'id', 'ID', 'center', '10%');
- $col_dt_oferta = new TDataGridColumn( 'dt_oferta', 'Data', 'center', '20%');
- $col_plano_id = new TDataGridColumn( 'plano_id', 'Favorecido', 'left', '40%');
- $col_deposito = new TDataGridColumn( 'deposito', 'Depósito', 'center', '10%');
- $col_valor = new TDataGridColumn( 'valor', 'Valor', 'right', '20%');
- $this->detail_list->addColumn( $col_uniq );
- $this->detail_list->addColumn( $col_id );
- $this->detail_list->addColumn( $col_dt_oferta );
- $this->detail_list->addColumn( $col_plano_id );
- $this->detail_list->addColumn( $col_deposito );
- $this->detail_list->addColumn( $col_valor );
- $col_id->setVisibility(false);
- $col_uniq->setVisibility(false);
- $col_dt_oferta->setTransformer( function($value, $object, $row) {
- if ($value)
- {
- try
- {
- $date = new DateTime($value);
- return $date->format('d/m/Y');
- }
- catch (Exception $e)
- {
- return $value;
- }
- }
- return $value;
- });
- $col_plano_id->setTransformer(function($value) {
- TTransaction::open('sinodo');
- $plano = new Plano($value);
- $favorecido = $plano->favorecido;
- $oferta_tipo = $plano->oferta_tipo->nome;
- TTransaction::close();
- return $favorecido . ' (' . $oferta_tipo . ')';
- });
- $format_value = function($value) {
- if (is_numeric($value)) {
- return 'R$ '.number_format($value, 2, ',', '.');
- }
- return $value;
- };
- $col_valor->setTransformer( $format_value );
- $col_valor->enableTotal('sum', 'R$', 2, ',', '.');
- // define the transformer method over image
- $col_deposito->setTransformer( function($value, $object, $row) {
- if ($value)
- {
- try
- {
- $date = new DateTime($value);
- return $date->format('d/m/Y');
- }
- catch (Exception $e)
- {
- return $value;
- }
- }
- return $value;
- });
- // detail actions
- $action1 = new TDataGridAction([$this, 'onDetailEdit'] );
- $action1->setFields( ['uniqid', '*'] );
- $action2 = new TDataGridAction([$this, 'onDetailDelete']);
- $action2->setField('uniqid');
- // add the actions to the datagrid
- $this->detail_list->addAction($action1, _t('Edit'), 'fa:edit blue');
- $this->detail_list->addAction($action2, _t('Delete'), 'fa:trash-alt red');
- $panel = new TPanelGroup;
- $panel->add($this->detail_list);
- $panel->getBody()->style = 'overflow-x:auto';
- $this->form->addContent( [$panel] );
- $label4 = new TLabel('Obervações', '#5A73DB', 12, '');
- $label4->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%; padding-top: 25px;';
- $this->form->addContent( [$label4] );
- $row = $this->form->addFields( [ new TLabel(''), $observacoes ] );
- $row->layout = ['col-sm-12' ];
- $this->detail_list->createModel();
- $this->form->addAction( 'Save', new TAction([$this, 'onSave'], ['static'=>'1']), 'fa:save green');
- $this->form->addAction( 'Clear', new TAction([$this, 'onClear']), 'fa:eraser red');
- $this->form->addActionLink(_t('Back'),new TAction(array('ReceitaList','onReload')),'far:arrow-alt-circle-left blue');
- // 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);
- }
- public function formatDate($date, $object)
- {
- $dt = new DateTime($date);
- return $dt->format('d/m/Y');
- }
- public static function onExitDate($params)
- {
- if( !empty($params['detail_dt_oferta']) )
- {
- try
- {
- TTransaction::open('sinodo');
- $criteria = new TCriteria;
- $dt_oferta = TDate::date2us( $params['detail_dt_oferta']);
- $criteria->add( new TFilter( 'dt_oferta', '=' , $dt_oferta ));
- $criteria->add( new TFilter( 'oferta_tipo_id', '!=', '3' ));
- $repository = new TRepository('Plano');
- $planos = $repository->load( $criteria );
- if ($planos)
- {
- foreach ($planos as $plano)
- {
- TForm::sendData('form_Receita', (object) ['detail_plano_id' => $plano->id ]);
- }
- }
- else
- {
- new TMessage('info', 'Verifique se existe oferta a repassar nesta data e tente novamente!');
- }
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }
- /**
- * Clear form
- * @param $param URL parameters
- */
- public function onClear($param)
- {
- $this->form->clear(TRUE);
- }
- /**
- * Add detail item
- * @param $param URL parameters
- */
- public function onDetailAdd( $param )
- {
- try
- {
- $this->form->validate();
- $data = $this->form->getData();
- // validation sample
- if (empty($data->detail_deposito))
- {
- throw new Exception('Informe a data do depósito!');
- }
- $uniqid = !empty($data->detail_uniqid) ? $data->detail_uniqid : uniqid();
- $grid_data = [];
- $grid_data['uniqid'] = $uniqid;
- $grid_data['id'] = $data->detail_id;
- $grid_data['dt_oferta'] = $data->detail_dt_oferta;
- $grid_data['plano_id'] = $data->detail_plano_id;
- $grid_data['deposito'] = $data->detail_deposito;
- $grid_data['valor'] = $data->detail_valor;
- // insert row dynamically
- $row = $this->detail_list->addItem( (object) $grid_data );
- $row->id = $uniqid;
- TDataGrid::replaceRowById('Oferta_list', $uniqid, $row);
- $data = new stdClass;
- // clear detail form fields
- $data->detail_uniqid = '';
- $data->detail_id = '';
- $data->detail_dt_oferta = '';
- $data->detail_plano_id = '';
- $data->detail_deposito = '';
- $data->detail_valor = '';
- // send data, do not fire change/exit events
- TForm::sendData( 'form_Receita', $data, false, false );
- }
- catch (Exception $e)
- {
- $this->form->setData( $this->form->getData());
- new TMessage('error', $e->getMessage());
- }
- }
- /**
- * Edit detail item
- * @param $param URL parameters
- */
- public static function onDetailEdit( $param )
- {
- $data = new stdClass;
- $data->detail_uniqid = $param['uniqid'];
- $data->detail_id = $param['id'];
- $data->detail_dt_oferta = TDate::date2br($param['dt_oferta']);
- $data->detail_plano_id = $param['plano_id'];
- $data->detail_deposito = TDate::date2br($param['deposito']);
- $data->detail_valor = number_format($param['valor'], 2, ',','.');
- // send data, do not fire change/exit events
- TForm::sendData( 'form_Receita', $data, false, false );
- }
- /**
- * Delete detail item
- * @param $param URL parameters
- */
- public static function onDetailDelete( $param )
- {
- // clear detail form fields
- $data = new stdClass;
- $data->detail_uniqid = '';
- $data->detail_id = '';
- $data->detail_dt_oferta = '';
- $data->detail_plano_id = '';
- $data->detail_deposito = '';
- $data->detail_valor = '';
- // send data, do not fire change/exit events
- TForm::sendData( 'form_Receita', $data, false, false );
- // remove row
- TDataGrid::removeRowById('Oferta_list', $param['uniqid']);
- }
- /**
- * Load Master/Detail data from database to form
- */
- public function onEdit($param)
- {
- try
- {
- TTransaction::open('sinodo');
- if (isset($param['key']))
- {
- $key = $param['key'];
- $object = new Receita($key);
- $object->comprovantes = ReceitaImagem::where('receita_id', '=', $param['key'])->getIndexedArray('imagem');
- $items = Oferta::where('receita_id', '=', $key)->load();
- foreach( $items as $item )
- {
- $item->uniqid = uniqid();
- $row = $this->detail_list->addItem( $item );
- $row->id = $item->uniqid;
- }
- $this->form->setData($object);
- TTransaction::close();
- }
- else
- {
- $this->form->clear(TRUE);
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- /**
- * Update the total based on the sale price, amount
- */
- public static function onUpdateTotal($param)
- {
- $contribuicoes = (double) str_replace(['.', ','], ['', '.'], $param['contribuicoes']);
- $ofertas = (double) str_replace(['.', ','], ['', '.'], $param['ofertas']);
- $doacoes = (double) str_replace(['.', ','], ['', '.'], $param['doacoes']);
- $patrimonial = (double) str_replace(['.', ','], ['', '.'], $param['patrimonial']);
- $promocoes = (double) str_replace(['.', ','], ['', '.'], $param['promocoes']);
- $outros = (double) str_replace(['.', ','], ['', '.'], $param['outros']);
- $obj = new StdClass;
- $obj->tot_receitas = number_format(($contribuicoes + $ofertas + $doacoes + $patrimonial + $promocoes + $outros), 2, ',', '.');
- $obj->dizimo = number_format((($contribuicoes + $ofertas + $doacoes + $patrimonial + $promocoes + $outros) * 0.10), 2, ',', '.');
- TForm::sendData('form_Receita', $obj);
- }
- /**
- * Save the Master/Detail data from form to database
- */
- public function onSave($param)
- {
- try
- {
- // open a transaction with database
- TTransaction::open('sinodo');
- $data = $this->form->getData();
- $this->form->validate();
- $master = new Receita;
- $master->fromArray( (array) $data);
- $master->contribuicoes = str_replace(['.', ','], ['', '.'], $param['contribuicoes']);
- $master->ofertas = str_replace(['.', ','], ['', '.'], $param['ofertas']);
- $master->doacoes = str_replace(['.', ','], ['', '.'], $param['doacoes']);
- $master->patrimonial = str_replace(['.', ','], ['', '.'], $param['patrimonial']);
- $master->promocoes = str_replace(['.', ','], ['', '.'], $param['promocoes']);
- $master->outros = str_replace(['.', ','], ['', '.'], $param['outros']);
- $master->tot_receitas = str_replace(['.', ','], ['', '.'], $param['tot_receitas']);
- $master->dizimo = str_replace(['.', ','], ['', '.'], $param['dizimo']);
- $master->parcelado = str_replace(['.', ','], ['', '.'], $param['parcelado']);
- $master->system_user_id = TSession::getValue('userid');
- $master->system_unit_id = TSession::getValue('userunitid');
- $master->mes = TDateTime::convertToMask($master->dep_dizimo, 'yyyy-mm-dd', 'mm');
- $master->ano = TDateTime::convertToMask($master->dep_dizimo, 'yyyy-mm-dd', 'yyyy');
- $master->dep_confirmado = 'N';
- $master->store();
- $this->saveFiles($master, $data, 'comprovantes', 'files/images', 'ReceitaImagem', 'imagem', 'receita_id');
- Oferta::where('receita_id', '=', $master->id)->delete();
- if( $param['Oferta_list_dt_oferta'] )
- {
- $total = 0;
- foreach( $param['Oferta_list_dt_oferta'] as $key => $item_id )
- {
- $detail = new Oferta;
- $detail->dt_oferta = $param['Oferta_list_dt_oferta'][$key];
- $detail->plano_id = $param['Oferta_list_plano_id'][$key];
- $detail->valor = $param['Oferta_list_valor'][$key];
- $detail->deposito = $param['Oferta_list_deposito'][$key];
- $detail->mes = TDateTime::convertToMask($detail->deposito, 'yyyy-mm-dd', 'mm');
- $detail->ano = TDateTime::convertToMask($detail->deposito, 'yyyy-mm-dd', 'yyyy');
- $detail->receita_id = $master->id;
- $detail->system_unit_id = (int)TSession::getValue('userunitid');
- $detail->store();
- $total += $detail->valor;
- }
- }
- $master->ofertas_a_repassar = $total;
- $master->total_deposito = $master->dizimo + $master->ofertas_a_repassar + $master->parcelado;
- $master->store(); // stores the object
- TForm::sendData('form_Receita', (object) ['id' => $master->id]);
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
- new TMessage('info', AdiantiCoreTranslator::translate('Record saved').'!' . '<br> O Sínodo agradece por Informar!');
- }
- catch (Exception $e) // in case of exception
- {
- if($e->getCode() ==23000){
- new TMessage('error', 'Erro: ' . 'Já existe receita informada para este mês/ano! <br> Verifique e tente novamente.');
- }else{
- new TMessage('error', $e->getMessage());
- $this->form->setData( $this->form->getData() ); // keep form data
- }
- TTransaction::rollback();
- }
- }
- }
Você está inicializando a variável
Teste inicializar antes, pois se o
Veja se funciona?
Olá Marcelo,
Obrigado pela Dica. o erro da variável $total foi resolvido com sua sugestão.
Más continua ainda o erro Notice: Undefined index: Oferta_list_dt_oferta na linha 563.
Consegui resolver, fiz uma alteração na linha 563 para:
if( !empty($param['Oferta_list_dt_oferta'] ))
Resolveu aqui, muito obrigado
Excelente! Bom trabalho.
Obrigadão, salvou, consegui aqui também utilizando esse if.