Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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. ...
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.

  1. <?php
  2. /**
  3.  * ReceitaForm Master/Detail
  4.  * @author  Alexandre M. Roberto
  5.  */
  6. class ReceitaForm extends TPage
  7. {
  8.     protected $form// form
  9.     protected $detail_list;
  10.     // trait with saveFile, saveFiles, ...
  11.     use Adianti\Base\AdiantiFileSaveTrait;
  12.         
  13.     /**
  14.      * Page constructor
  15.      */
  16.     public function __construct()
  17.     {
  18.         parent::__construct();     
  19.         
  20.         // creates the form
  21.         $this->form = new BootstrapFormBuilder('form_Receita');
  22.         $this->form->setFormTitle('Formulário de Receita da Paróquia/Comunidade');
  23.         $this->form->setClientValidation(true); 
  24.         
  25.         // master fields
  26.         $id = new TEntry('id');
  27.         $dt_receita = new TDate('dt_receita');
  28.         $refmes = new TCombo('refmes');
  29.         $refano = new TCombo('refano');
  30.         $contribuicoes = new TEntry('contribuicoes');
  31.         $ofertas = new TEntry('ofertas');
  32.         $doacoes = new TEntry('doacoes');
  33.         $promocoes = new TEntry('promocoes');
  34.         $patrimonial = new TEntry('patrimonial');
  35.         $outros = new TEntry('outros');
  36.         $tot_receitas = new TEntry('tot_receitas');
  37.         $dizimo = new TEntry('dizimo');
  38.         $parcelado = new TEntry('parcelado');
  39.         $parcelado->style "background-color: #DFE54A";
  40.         $ofertas_a_repassar = new TEntry('ofertas_a_repassar');
  41.         $comprovantes = new TMultiFile('comprovantes');
  42.         $comprovantes->setAllowedExtensions( ['gif''png''jpg''jpeg''pdf'] );
  43.         $comprovantes->enableFileHandling();
  44.         $comprovantes->enableImageGallery();
  45.         $comprovantes->enablePopover('Preview''<img style="max-width:300px" src="download.php?file={file_name}">');
  46.                         
  47.         $dep_dizimo = new TDate('dep_dizimo');
  48.         $dep_ofertas_a_repassar = new TDate('dep_ofertas_a_repassar');
  49.         $observacoes = new TText('observacoes');
  50.         
  51.         $dt_receita->setMask('dd/mm/yyyy');
  52.         $dt_receita->setDatabaseMask('yyyy-mm-dd');
  53.         $dt_receita->setValuedate('Y-m-d') );
  54.         $contribuicoes->setNumericMask(2',''.'true);
  55.         $ofertas->setNumericMask(2',''.'true);
  56.         $doacoes->setNumericMask(2',''.'true);
  57.         $promocoes->setNumericMask(2',''.'true);
  58.         $patrimonial->setNumericMask(2',''.'true);
  59.         $outros->setNumericMask(2',''.'true);
  60.         $tot_receitas->setNumericMask(2',''.'true);
  61.         $dizimo->setNumericMask(2',''.'true);
  62.         $ofertas_a_repassar->setNumericMask(2',''.'true);
  63.         $parcelado->setNumericMask(2',''.'true);            
  64.                                                
  65.         $current = (int) date('Y');
  66.         $refmes->addItems( ['01' => 'Janeiro',
  67.                          '02' => 'Fevereiro',
  68.                          '03' => 'Março',
  69.                          '04' => 'Abril',
  70.                          '05' => 'Maio',
  71.                          '06' => 'Junho',
  72.                          '07' => 'Julho',
  73.                          '08' => 'Agosto'
  74.                          '09' => 'Setembro'
  75.                          '10' => 'Outubro'
  76.                          '11' => 'Novembro'
  77.                          '12' => 'Dezembro'] );
  78.         $refano->addItems( [ ($current -5) => ($current -5), ($current -4) => ($current -4), ($current -3) => ($current -3), ($current -2) => ($current -2), ($current -1) => ($current -1), $current => $current ] );        
  79.         $id->setSize('100%');
  80.         $dt_receita->setSize('100%');
  81.         $refmes->setSize('100%');
  82.         $refano->setSize('100%');
  83.         $contribuicoes->setSize('100%');
  84.         $ofertas->setSize('100%');
  85.         $doacoes->setSize('100%');
  86.         $promocoes->setSize('100%');
  87.         $patrimonial->setSize('100%');
  88.         $outros->setSize('100%');
  89.         $tot_receitas->setSize('100%');
  90.         $tot_receitas->setEditable(FALSE);
  91.         $dizimo->setSize('100%');
  92.         $parcelado->setSize('100%');
  93.         $parcelado->style = ("background-color: #ffff99; text-align: right;");
  94.         $dizimo->setEditable(FALSE);
  95.         $ofertas_a_repassar->setSize('100%');
  96.         $ofertas_a_repassar->setEditable(FALSE);
  97.         $contribuicoes->setValue(0);
  98.         $ofertas->setValue(0);
  99.         $doacoes->setValue(0);
  100.         $promocoes->setValue(0);
  101.         $patrimonial->setValue(0);
  102.         $outros->setValue(0);
  103.         $parcelado->setValue(0);
  104.  
  105.         $comprovantes->setSize('100%');
  106.         $dep_dizimo->setSize('100%');
  107.         $dep_dizimo->setMask('dd/mm/yyyy');
  108.         $dep_dizimo->setDatabaseMask('yyyy-mm-dd');
  109.         $dep_ofertas_a_repassar->setMask('dd/mm/yyyy');
  110.         $dep_ofertas_a_repassar->setDatabaseMask('yyyy-mm-dd');
  111.         $dep_ofertas_a_repassar->setSize('100%');        
  112.         $observacoes->setSize('100%');                
  113.         // detail fields
  114.         $detail_uniqid = new THidden('detail_uniqid');
  115.         $detail_id = new THidden('detail_id');
  116.         
  117.         $detail_dt_oferta = new TDate('detail_dt_oferta');
  118.         $detail_dt_oferta->setMask('dd/mm/yyyy');
  119.         $detail_dt_oferta->setDatabaseMask('yyyy-mm-dd');       
  120.         $detail_plano_id = new TDBCombo('detail_plano_id''sinodo''Plano''id''{favorecido} ({oferta_tipo->nome})');
  121.         $detail_plano_id->setEditable(FALSE);
  122.         $detail_plano_id->setSize('100%');
  123.         
  124.         $detail_valor = new TNumeric('detail_valor'2',''.'true);         
  125.         $refmes->addValidation('Mês', new TRequiredValidator);
  126.         $refano->addValidation('Ano', new TRequiredValidator);
  127.         
  128.         $detail_deposito = new TDate('detail_deposito');
  129.         $detail_deposito->setMask('dd/mm/yyyy');
  130.         $detail_deposito->setDatabaseMask('yyyy-mm-dd');
  131.          
  132.                 
  133.         // exit action
  134.         $detail_dt_oferta->setExitAction(new TAction([$this,'onExitDate']));
  135.         if (!empty($id))
  136.         {
  137.             $id->setEditable(FALSE);
  138.         }
  139.         
  140.         // master fields
  141.         $row $this->form->addFields( [ new TLabel('Id'),         $id ],
  142.                                        [ new TLabel('Data'),       $dt_receita ],
  143.                                        [ new TLabel('Mês'),        $refmes ],
  144.                                        [ new TLabel('Ano'),        $refano ] );
  145.         $row->layout = ['col-sm-3''col-sm-3''col-sm-3''col-sm-3' ];
  146.         $row $this->form->addFields( [ new TLabel('Contribuições'),  $contribuicoes ],
  147.                                        [ new TLabel('Ofertas'),        $ofertas ],
  148.                                        [ new TLabel('Doações'),        $doacoes ],
  149.                                        [ new TLabel('Promoções'),      $promocoes ]);
  150.         $row->layout = ['col-sm-3''col-sm-3''col-sm-3''col-sm-3' ];
  151.         $row $this->form->addFields( [ new TLabel('Renda Patrimonial'), $patrimonial ],
  152.                                        [ new TLabel('Outras Receitas'),         $outros ],
  153.                                        [ new TLabel('Total Receitas'), $tot_receitas ],
  154.                                        [ new TLabel('Dizimo (10%)'), $dizimo ]);
  155.         $row->layout = ['col-sm-3''col-sm-3','col-sm-3''col-sm-3' ];
  156.         
  157.         $row $this->form->addFields( [ new TLabel('Data do Depósito Dízimo (10%)'),       $dep_dizimo ],
  158.                                        [ new TLabel('<b>Dízimo em atrazo / parcelado</b>'), $parcelado ] );
  159.         $row->layout = ['col-sm-3''col-sm-3' ];
  160.         
  161.         $label4 = new TLabel('Comprovantes''#5A73DB'12'');
  162.         $label4->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%; padding-top: 25px;';
  163.         $this->form->addContent( [$label4] );
  164.                 
  165.         $row $this->form->addFields( [ $comprovantes ]);
  166.         $row->layout = ['col-sm-12' ];
  167.         
  168.         $contribuicoes->setExitAction(new TAction(array($this'onUpdateTotal')));
  169.         $ofertas->setExitAction(new TAction(array($this'onUpdateTotal')));
  170.         $doacoes->setExitAction(new TAction(array($this'onUpdateTotal')));
  171.         $patrimonial->setExitAction(new TAction(array($this'onUpdateTotal')));
  172.         $promocoes->setExitAction(new TAction(array($this'onUpdateTotal')));
  173.         $outros->setExitAction(new TAction(array($this'onUpdateTotal')));
  174.         $parcelado->setExitAction(new TAction(array($this'onUpdateTotal')));
  175.         
  176.         // detail fields
  177.         $label4 = new TLabel('Ofertas a Repassar''#5A73DB'12'');
  178.         $label4->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%; padding-top: 25px;';
  179.         $this->form->addContent( [$label4] );
  180.         $this->form->addFields( [$detail_uniqid] );
  181.         $this->form->addFields( [$detail_id] );
  182.         
  183.         $row $this->form->addFields( [ new TLabel('Data Oferta'),    $detail_dt_oferta ],
  184.                                        [ new TLabel('Favorecido'),     $detail_plano_id ],
  185.                                        [ new TLabel('Data Depósito'),  $detail_deposito ],
  186.                                        [ new TLabel('Valor'),          $detail_valor ]);
  187.         $row->layout = ['col-sm-2''col-sm-6''col-sm-2''col-sm-2'];
  188.         $add TButton::create('add', [$this'onDetailAdd'], _t('Register'), 'fa:plus-circle green');
  189.         $add->getAction()->setParameter('static','1');
  190.         $this->form->addFields( [], [$add] );
  191.         
  192.         $this->detail_list = new BootstrapDatagridWrapper(new TDataGrid);
  193.         $this->detail_list->setId('Oferta_list');
  194.         $this->detail_list->setHeight(150);
  195.         $this->detail_list->makeScrollable();
  196.         $this->detail_list->generateHiddenFields();
  197.         $this->detail_list->style "min-width: 700px; width:100%;margin-bottom: 10px";
  198.         
  199.         // items
  200.         $col_uniq       = new TDataGridColumn'uniqid''Uniqid''center''10%');
  201.         $col_id         = new TDataGridColumn'id''ID''center''10%');
  202.         $col_dt_oferta  = new TDataGridColumn'dt_oferta''Data''center''20%');
  203.         $col_plano_id   = new TDataGridColumn'plano_id''Favorecido''left''40%');
  204.         $col_deposito   = new TDataGridColumn'deposito''Depósito''center''10%');
  205.         $col_valor      = new TDataGridColumn'valor''Valor''right''20%');
  206.         
  207.         $this->detail_list->addColumn$col_uniq );
  208.         $this->detail_list->addColumn$col_id );
  209.         $this->detail_list->addColumn$col_dt_oferta );
  210.         $this->detail_list->addColumn$col_plano_id );
  211.         $this->detail_list->addColumn$col_deposito );
  212.         $this->detail_list->addColumn$col_valor );
  213.         
  214.         $col_id->setVisibility(false);
  215.         $col_uniq->setVisibility(false);             
  216.         
  217.         $col_dt_oferta->setTransformer( function($value$object$row) {
  218.             if ($value)
  219.             {
  220.                 try
  221.                 {
  222.                     $date = new DateTime($value);
  223.                     return $date->format('d/m/Y');
  224.                 }
  225.                 catch (Exception $e)
  226.                 {
  227.                     return $value;
  228.                 }
  229.             }
  230.             return $value;
  231.         });
  232.         
  233.         $col_plano_id->setTransformer(function($value) {
  234.             TTransaction::open('sinodo');
  235.             $plano = new Plano($value);
  236.             $favorecido $plano->favorecido;
  237.             $oferta_tipo $plano->oferta_tipo->nome;
  238.             
  239.             TTransaction::close();
  240.             return $favorecido ' (' $oferta_tipo ')';
  241.         });
  242.         
  243.         $format_value = function($value) {
  244.             if (is_numeric($value)) {
  245.                 return 'R$ '.number_format($value2',''.');
  246.             }
  247.             return $value;
  248.         };     
  249.        
  250.         $col_valor->setTransformer$format_value ); 
  251.         $col_valor->enableTotal('sum''R$'2',''.');
  252.         // define the transformer method over image
  253.         $col_deposito->setTransformer( function($value$object$row) {
  254.             if ($value)
  255.             {
  256.                 try
  257.                 {
  258.                     $date = new DateTime($value);
  259.                     return $date->format('d/m/Y');
  260.                 }
  261.                 catch (Exception $e)
  262.                 {
  263.                     return $value;
  264.                 }
  265.             }
  266.             return $value;
  267.         });
  268.                
  269.         // detail actions
  270.         $action1 = new TDataGridAction([$this'onDetailEdit'] );
  271.         $action1->setFields( ['uniqid''*'] );
  272.         
  273.         $action2 = new TDataGridAction([$this'onDetailDelete']);
  274.         $action2->setField('uniqid');
  275.         
  276.         // add the actions to the datagrid
  277.         $this->detail_list->addAction($action1_t('Edit'), 'fa:edit blue');
  278.         $this->detail_list->addAction($action2_t('Delete'), 'fa:trash-alt red');
  279.         
  280.  
  281.         $panel = new TPanelGroup;
  282.         $panel->add($this->detail_list);
  283.         $panel->getBody()->style 'overflow-x:auto';
  284.         $this->form->addContent( [$panel] );
  285.         $label4 = new TLabel('Obervações''#5A73DB'12'');
  286.         $label4->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%; padding-top: 25px;';
  287.         $this->form->addContent( [$label4] );
  288.         
  289.         $row $this->form->addFields( [ new TLabel(''),       $observacoes ] );
  290.         $row->layout = ['col-sm-12' ];
  291.         
  292.         $this->detail_list->createModel();
  293.                        
  294.         $this->form->addAction'Save',  new TAction([$this'onSave'], ['static'=>'1']), 'fa:save green');
  295.         $this->form->addAction'Clear', new TAction([$this'onClear']), 'fa:eraser red');
  296.         $this->form->addActionLink(_t('Back'),new TAction(array('ReceitaList','onReload')),'far:arrow-alt-circle-left blue');
  297.         
  298.         // create the page container
  299.         $container = new TVBox;
  300.         $container->style 'width: 100%';
  301.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  302.         $container->add($this->form);
  303.         parent::add($container);
  304.     }
  305.     
  306.     public function formatDate($date$object)
  307.     {
  308.         $dt = new DateTime($date);
  309.         return $dt->format('d/m/Y');
  310.     }
  311.     
  312.     public static function onExitDate($params)
  313.     {
  314.         if( !empty($params['detail_dt_oferta']) )
  315.         {
  316.             try
  317.             {
  318.                 TTransaction::open('sinodo');
  319.                 
  320.                 $criteria = new TCriteria;
  321.                 $dt_oferta TDate::date2us$params['detail_dt_oferta']);                
  322.                 $criteria->add( new TFilter'dt_oferta''=' $dt_oferta ));
  323.                 $criteria->add( new TFilter'oferta_tipo_id''!=''3' ));
  324.                 $repository = new TRepository('Plano');
  325.                 $planos $repository->load$criteria );
  326.                                                                
  327.                 if ($planos)
  328.                 {
  329.                     foreach ($planos as $plano)
  330.                     {                      
  331.                         TForm::sendData('form_Receita', (object) ['detail_plano_id' => $plano->id ]);
  332.                     }
  333.                 }
  334.                 else
  335.                 {
  336.                     new TMessage('info''Verifique se existe oferta a repassar nesta data e tente novamente!');
  337.                 }                            
  338.             }
  339.             catch (Exception $e)
  340.             {
  341.                 new TMessage('error'$e->getMessage());
  342.                 TTransaction::rollback();
  343.             }
  344.         }
  345.     } 
  346.     
  347.     /**
  348.      * Clear form
  349.      * @param $param URL parameters
  350.      */
  351.     public function onClear($param)
  352.     {
  353.         $this->form->clear(TRUE);
  354.     }
  355.     
  356.     /**
  357.      * Add detail item
  358.      * @param $param URL parameters
  359.      */
  360.     public function onDetailAdd$param )
  361.     {
  362.         try
  363.         {
  364.             $this->form->validate();
  365.             $data $this->form->getData();
  366.             
  367.             // validation sample
  368.             if (empty($data->detail_deposito))
  369.             {
  370.                 throw new Exception('Informe a data do depósito!');
  371.             }
  372.             
  373.             $uniqid = !empty($data->detail_uniqid) ? $data->detail_uniqid uniqid();
  374.             
  375.             $grid_data = [];
  376.             $grid_data['uniqid'] = $uniqid;
  377.             $grid_data['id'] = $data->detail_id;
  378.             $grid_data['dt_oferta'] = $data->detail_dt_oferta;
  379.             $grid_data['plano_id'] = $data->detail_plano_id;
  380.             $grid_data['deposito'] = $data->detail_deposito;
  381.             $grid_data['valor'] = $data->detail_valor;
  382.             
  383.             // insert row dynamically
  384.             $row $this->detail_list->addItem( (object) $grid_data );
  385.             $row->id $uniqid;
  386.             
  387.             TDataGrid::replaceRowById('Oferta_list'$uniqid$row);
  388.             
  389.             $data = new stdClass;
  390.             
  391.             // clear detail form fields
  392.             $data->detail_uniqid '';
  393.             $data->detail_id '';
  394.             $data->detail_dt_oferta '';
  395.             $data->detail_plano_id '';
  396.             $data->detail_deposito '';
  397.             $data->detail_valor '';
  398.             
  399.             // send data, do not fire change/exit events
  400.             TForm::sendData'form_Receita'$datafalsefalse );
  401.         }
  402.         catch (Exception $e)
  403.         {
  404.             $this->form->setData$this->form->getData());
  405.             new TMessage('error'$e->getMessage());
  406.         }
  407.     }
  408.     
  409.     /**
  410.      * Edit detail item
  411.      * @param $param URL parameters
  412.      */
  413.     public static function onDetailEdit$param )
  414.     {
  415.         $data = new stdClass;
  416.         $data->detail_uniqid     $param['uniqid'];
  417.         $data->detail_id         $param['id'];
  418.         $data->detail_dt_oferta  TDate::date2br($param['dt_oferta']);
  419.         $data->detail_plano_id   $param['plano_id'];
  420.         $data->detail_deposito   TDate::date2br($param['deposito']);
  421.         $data->detail_valor      number_format($param['valor'], 2',','.');
  422.            
  423.         // send data, do not fire change/exit events
  424.         TForm::sendData'form_Receita'$datafalsefalse );
  425.     }
  426.     
  427.     /**
  428.      * Delete detail item
  429.      * @param $param URL parameters
  430.      */
  431.     public static function onDetailDelete$param )
  432.     {
  433.         // clear detail form fields
  434.         $data = new stdClass;
  435.         $data->detail_uniqid '';
  436.         $data->detail_id '';
  437.         $data->detail_dt_oferta '';
  438.         $data->detail_plano_id '';
  439.         $data->detail_deposito '';
  440.         $data->detail_valor '';
  441.         
  442.         // send data, do not fire change/exit events
  443.         TForm::sendData'form_Receita'$datafalsefalse );
  444.         
  445.         // remove row
  446.         TDataGrid::removeRowById('Oferta_list'$param['uniqid']);
  447.     }
  448.     
  449.     /**
  450.      * Load Master/Detail data from database to form
  451.      */
  452.     public function onEdit($param)
  453.     {
  454.         try
  455.         {
  456.             TTransaction::open('sinodo');
  457.             
  458.             if (isset($param['key']))
  459.             {
  460.                 $key $param['key'];
  461.                 
  462.                 $object = new Receita($key);
  463.                 $object->comprovantes ReceitaImagem::where('receita_id''='$param['key'])->getIndexedArray('imagem');
  464.                 $items  Oferta::where('receita_id''='$key)->load();
  465.                 
  466.                 foreach( $items as $item )
  467.                 {
  468.                     $item->uniqid uniqid();
  469.                     $row $this->detail_list->addItem$item );
  470.                     $row->id $item->uniqid;
  471.                 }
  472.                 $this->form->setData($object);
  473.                 TTransaction::close();
  474.             }
  475.             else
  476.             {
  477.                 $this->form->clear(TRUE);
  478.             }
  479.         }
  480.         catch (Exception $e// in case of exception
  481.         {
  482.             new TMessage('error'$e->getMessage());
  483.             TTransaction::rollback();
  484.         }
  485.     }
  486.     
  487.     /**
  488.     * Update the total based on the sale price, amount
  489.     */
  490.     public static function onUpdateTotal($param)
  491.     {
  492.         $contribuicoes = (double) str_replace(['.'','], ['''.'], $param['contribuicoes']);
  493.         $ofertas =       (double) str_replace(['.'','], ['''.'], $param['ofertas']);
  494.         $doacoes =       (double) str_replace(['.'','], ['''.'], $param['doacoes']);
  495.         $patrimonial =   (double) str_replace(['.'','], ['''.'], $param['patrimonial']);
  496.         $promocoes =     (double) str_replace(['.'','], ['''.'], $param['promocoes']);
  497.         $outros =        (double) str_replace(['.'','], ['''.'], $param['outros']);
  498.         
  499.         $obj = new StdClass;
  500.         $obj->tot_receitas number_format(($contribuicoes $ofertas $doacoes $patrimonial $promocoes $outros), 2',''.');
  501.         $obj->dizimo number_format((($contribuicoes $ofertas $doacoes $patrimonial $promocoes $outros) * 0.10), 2',''.');
  502.         TForm::sendData('form_Receita'$obj);
  503.     }
  504.     /**
  505.      * Save the Master/Detail data from form to database
  506.      */
  507.     public function onSave($param)
  508.     {
  509.         try
  510.         {
  511.             // open a transaction with database
  512.             TTransaction::open('sinodo');
  513.             
  514.             $data $this->form->getData();
  515.             $this->form->validate();            
  516.             $master = new Receita;
  517.             $master->fromArray( (array) $data);               
  518.             $master->contribuicoes str_replace(['.'','], ['''.'], $param['contribuicoes']);
  519.             $master->ofertas str_replace(['.'','], ['''.'], $param['ofertas']);
  520.             $master->doacoes str_replace(['.'','], ['''.'], $param['doacoes']);
  521.             $master->patrimonial str_replace(['.'','], ['''.'], $param['patrimonial']);
  522.             $master->promocoes str_replace(['.'','], ['''.'], $param['promocoes']);
  523.             $master->outros str_replace(['.'','], ['''.'], $param['outros']);
  524.             $master->tot_receitas str_replace(['.'','], ['''.'], $param['tot_receitas']);
  525.             $master->dizimo str_replace(['.'','], ['''.'], $param['dizimo']); 
  526.             $master->parcelado str_replace(['.'','], ['''.'], $param['parcelado']);          
  527.             $master->system_user_id TSession::getValue('userid');
  528.             $master->system_unit_id TSession::getValue('userunitid');
  529.             $master->mes TDateTime::convertToMask($master->dep_dizimo'yyyy-mm-dd''mm');
  530.             $master->ano TDateTime::convertToMask($master->dep_dizimo'yyyy-mm-dd''yyyy');
  531.             $master->dep_confirmado 'N';
  532.             $master->store();
  533.                         
  534.             $this->saveFiles($master$data'comprovantes''files/images''ReceitaImagem''imagem''receita_id');
  535.            
  536.             
  537.             Oferta::where('receita_id''='$master->id)->delete();
  538.                                   
  539.             if( $param['Oferta_list_dt_oferta'] )
  540.             {
  541.                 $total 0;
  542.                 foreach( $param['Oferta_list_dt_oferta'] as $key => $item_id )
  543.                 {
  544.                     $detail = new Oferta;
  545.                     $detail->dt_oferta  $param['Oferta_list_dt_oferta'][$key];
  546.                     $detail->plano_id   $param['Oferta_list_plano_id'][$key];
  547.                     $detail->valor      $param['Oferta_list_valor'][$key];
  548.                     $detail->deposito   $param['Oferta_list_deposito'][$key];
  549.                     $detail->mes TDateTime::convertToMask($detail->deposito'yyyy-mm-dd''mm');
  550.                     $detail->ano TDateTime::convertToMask($detail->deposito'yyyy-mm-dd''yyyy');
  551.                     $detail->receita_id $master->id;
  552.                     $detail->system_unit_id = (int)TSession::getValue('userunitid');
  553.                     $detail->store();                 
  554.                     $total += $detail->valor;                                          
  555.                 }
  556.             }
  557.             $master->ofertas_a_repassar $total;
  558.             $master->total_deposito $master->dizimo $master->ofertas_a_repassar $master->parcelado;
  559.             $master->store(); // stores the object
  560.             
  561.             TForm::sendData('form_Receita', (object) ['id' => $master->id]);
  562.                        
  563.             $this->form->setData($data); // fill form data
  564.           
  565.             TTransaction::close(); // close the transaction
  566.             
  567.             new TMessage('info'AdiantiCoreTranslator::translate('Record saved').'!' '<br> O Sínodo agradece por Informar!');
  568.         }
  569.         catch (Exception $e// in case of exception
  570.         {
  571.             if($e->getCode() ==23000){ 
  572.             new TMessage('error''Erro: ' 'Já existe receita informada para este mês/ano! <br> Verifique e tente novamente.'); 
  573.            }else{ 
  574.             new TMessage('error'$e->getMessage());
  575.             $this->form->setData$this->form->getData() ); // keep form data
  576.            }
  577.             TTransaction::rollback();
  578.         }
  579.     }      
  580. }

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (5)


MG

Você está inicializando a variável
$total
dentro do
if( $param['Oferta_list_dt_oferta'] )
.
Teste inicializar antes, pois se o
if
for falso, a linha a seguir onte vc exibe o $total não exibe ainda.
Veja se funciona?
AR

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.

AR

Consegui resolver, fiz uma alteração na linha 563 para:

if( !empty($param['Oferta_list_dt_oferta'] ))

Resolveu aqui, muito obrigado
MG

Excelente! Bom trabalho.
RF

Obrigadão, salvou, consegui aqui também utilizando esse if.