Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Duplicando Registro ao Salvar e erro não encontrado. Boa noite galera. Tenho um form que ao Salvar o registro ele simplesmente duplica e cria um novo. Também ocorre um erro após alvar nesta linha: Notice: Undefined index: ComprasSub_list_quant in C:xampphtdocsadiantiourorioappcontrolourorioComprasForm.php on line 399 Segue o código, obrigado. ...
CM
Duplicando Registro ao Salvar e erro não encontrado.  
Boa noite galera.

Tenho um form que ao Salvar o registro ele simplesmente duplica e cria um novo.

Também ocorre um erro após alvar nesta linha: Notice: Undefined index: ComprasSub_list_quant in C:xampphtdocsadiantiourorioappcontrolourorioComprasForm.php on line 399


Segue o código, obrigado.

  1. <?php
  1. <?php
  2. /**
  3.  * ComprasForm Master/Detail
  4.  * @author  <your name here>
  5.  */
  6. class ComprasFormNew extends TPage
  7. {
  8.     protected $form// form
  9.     protected $detail_list;
  10.     
  11.     /**
  12.      * Page constructor
  13.      */
  14.     public function __construct()
  15.     {
  16.         parent::__construct();
  17.         
  18.         
  19.         // creates the form
  20.         $this->form = new BootstrapFormBuilder('form_Compras');
  21.         $this->form->setFormTitle('Compras');
  22.         
  23.         // master fields
  24.         $id_compra = new THidden('id_compra');
  25.         $data_compra = new TDate('data_compra');
  26.         $tipo_compra_id = new TDBCombo('tipo_compra_id''ourorio''ComprasTipo''id_tipo_compra''descricao','descricao');
  27.         $tipo_compra_txt = new TEntry('tipo_compra_txt');
  28.         $kilate_id = new TDBCombo('kilate_id''ourorio''ComprasKilate''id_kilate''descricao_kilate','descricao_kilate');
  29.         $kilate_txt = new TEntry('kilate_txt');
  30.   
  31.         $criteria = new TCriteria;
  32.         $criteria->setProperty('order''nome_cliente');
  33.         $cliente_id = new  ">TDBSeekButton('cliente_id''ourorio''form_Compras''Clientes''nome_cliente''cliente_id''cliente_txt'$criteria);
  34.         $cliente_txt = new TEntry('cliente_txt');
  35.         $cliente_txt->setEditable(FALSE);
  36.        
  37.         $cliente_cep = new THidden('cliente_cep');
  38.         $cliente_endereco_tipo = new THidden('cliente_endereco_tipo');
  39.         $cliente_endereco = new THidden('cliente_endereco');
  40.         $cliente_endereco_numero = new THidden('cliente_endereco_numero');
  41.         $cliente_bairro = new THidden('cliente_bairro');
  42.         $cliente_cidade = new THidden('cliente_cidade');
  43.         $cliente_estado = new THidden('cliente_estado');
  44.         $cliente_telefone = new THidden('cliente_telefone');
  45.         $cliente_nascimento = new THidden('cliente_nascimento');
  46.         $cliente_identidade = new THidden('cliente_identidade');
  47.         $cliente_email = new THidden('cliente_email');
  48.         $cliente_cpf = new THidden('cliente_cpf');
  49.        
  50.         $anexo_nf_joia_cliente = new TFile('anexo_nf_joia_cliente');
  51.         $vendedor_txt = new THidden('vendedor_txt');
  52.         $loja_id = new TEntry('loja_id');
  53.         $loja_id = new THidden('loja_id');
  54.         $loja_txt = new TEntry('loja_txt');
  55.         $loja_txt = new THidden('loja_txt');
  56.         $finalizada = new TEntry('finalizada');
  57.         $movimento_fechado = new TEntry('movimento_fechado');
  58.         $movimento_fechado_em = new TDate('movimento_fechado_em');
  59.         
  60.         //Campos Obrigatórios
  61.         $cliente_id->addValidation('Cliente', new TRequiredValidator);
  62.         $tipo_compra_id->addValidation('Tipo de Compra', new TRequiredValidator);
  63.         $kilate_id->addValidation('Kilate', new TRequiredValidator);
  64.         
  65.         // define ação de saída do campo
  66.         $cliente_id->setExitAction(new TAction(array($this'onExitCliente')));
  67.         
  68.         // máscara Master
  69.         $data_compra ->setDatabaseMask('yyyy-mm-dd');
  70.         $data_compra ->setMask('dd/mm/yyyy');
  71.         $data_compra->setValue(date("Y-m-d"));
  72.         $loja_id->setValue(TSession::getValue('userunitid')) ; //id da unidade
  73.         $loja_id->setEditable(FALSE);
  74.         $loja_txt->setValue(TSession::getValue('userunitname')); //nome da unidade
  75.         $loja_txt->setEditable(FALSE);
  76.         $vendedor_txt->setEditable(FALSE);
  77.         $vendedor_txt->setValue(TSession::getValue('username')); //nome do usuário
  78.         // detail fields
  79.         $detail_uniqid = new THidden('detail_uniqid');
  80.         $detail_id_automatico = new THidden('detail_id_automatico');
  81.         $detail_quantidade = new TEntry('detail_quantidade');
  82.         $detail_unidade = new TEntry('detail_unidade');
  83.         $detail_descricao = new TEntry('detail_descricao');
  84.         $detail_valor_unit = new TEntry('detail_valor_unit');
  85.         $detail_subtotal = new TEntry('detail_subtotal');
  86.         $detail_tipo_compra_id = new TDBCombo('detail_tipo_compra_id''ourorio''ComprasTipo''id_tipo_compra''descricao','descricao');
  87.         $detail_kilate_id = new TDBCombo('detail_kilate_id''ourorio''ComprasKilate''id_kilate''descricao_kilate','descricao_kilate');
  88.   
  89.         
  90.         // mascara detalhes
  91.         $detail_descricao->forceUpperCase();
  92.         $detail_unidade->setValue('GR');
  93.         $detail_valor_unit->setNumericMask(2',''.'true);
  94.         $detail_subtotal->setNumericMask(2',''.'true);
  95.         if (!empty($id_compra))
  96.         {
  97.             $id_compra->setEditable(FALSE);
  98.         }
  99.         
  100.         // master fields
  101.         $row $this->form->addFields( [new TLabel('Data')], [$data_compra] ,
  102.                                        [new TLabel('ID')], [$cliente_id],
  103.                                        [new TLabel('Cliente')], [$cliente_txt]);
  104.         $row->layout = ['col-1','col-2','col-sm-1','col-2','col-sm-1','col-sm-5'];
  105.         
  106.         
  107.         $row $this->form->addFields( [new TLabel('Anexo N.F. Joia')], [$anexo_nf_joia_cliente],
  108.                                        [new TLabel('Tipo')], [$tipo_compra_id],
  109.                                        [new TLabel('Kilate')], [$kilate_id]);
  110.         $row->layout = ['col-sm-1''col-sm-3','col-sm-1''col-sm-3','col-sm-1''col-sm-3'];
  111.         
  112.                                         
  113.         $row $this->form->addFields([new THidden('CEP')], [$cliente_cep],
  114.                                       [new THidden('Tipo')], [$cliente_endereco_tipo],
  115.                                       [new THidden('Endereço')], [$cliente_endereco],
  116.                                       [new THidden('Numero')], [$cliente_endereco_numero],
  117.                                       [new THidden('Bairro')], [$cliente_bairro],
  118.                                       [new THidden('Cidade')], [$cliente_cidade],
  119.                                       [new THidden('Estado')], [$cliente_estado],
  120.                                       [new THidden('Telefone')], [$cliente_telefone],
  121.                                       [new THidden('Nasc')], [$cliente_nascimento],
  122.                                       [new THidden('Identidade')], [$cliente_identidade],
  123.                                       [new THidden('Email')], [$cliente_email],
  124.                                       [new THidden('CPF')], [$cliente_cpf],
  125.                                       );
  126.         $row->layout = ['col-sm-1','col-sm-2','col-sm-1','col-sm-2','col-sm-1','col-sm-2','col-sm-1','col-sm-4','col-sm-1','col-sm-2','col-sm-1''col-sm-2''col-sm-1','col-sm-2''col-sm-1','col-sm-2''col-sm-1','col-sm-2''col-sm-1','col-sm-2''col-sm-1','col-sm-2''col-sm-1','col-sm-2'];
  127.         
  128.         $row $this->form->addFields([new THidden('Vendedor')], [$vendedor_txt] ,
  129.                                       [new THidden('ID')], [$loja_id] ,
  130.                                       [new THidden('Loja')], [$loja_txt]);
  131.         $row->layout = ['col-sm-1''col-sm-3','col-sm-1''col-sm-3','col-sm-1','col-sm-3'];
  132.         
  133.         // detail fields
  134.         $this->form->addContent( ['<h4>Item(s) da Compra</h4><hr>'] );
  135.         $this->form->addFields( [$detail_uniqid] );
  136.         $this->form->addFields( [$detail_id_automatico] );
  137.         
  138.         $row $this->form->addFields( [new TLabel('quantidade')], [$detail_quantidade],
  139.                                        [new TLabel('Produto')], [$detail_descricao],
  140.                                        [new TLabel('Valor')], [$detail_valor_unit] );
  141.         $row->layout = ['col-sm-1''col-sm-2','col-sm-1','col-sm-5','col-sm-1','col-sm-2'];
  142.         
  143.         $row $this->form->addFields( [new TLabel('Unidade')], [$detail_unidade],
  144.                                        [new TLabel('Tipo')], [$detail_tipo_compra_id],
  145.                                        [new TLabel('Kilate')], [$detail_kilate_id],
  146.                                        [new TLabel('Subtotal')], [$detail_subtotal] ,
  147.                                        );
  148.         $row->layout = ['col-sm-1''col-sm-2','col-sm-1','col-sm-2','col-sm-1','col-sm-2','col-sm-1','col-sm-2'];
  149.         $add TButton::create('add', [$this'onDetailAdd'], 'Register''fa:plus-circle green');
  150.         $add->getAction()->setParameter('static','1');
  151.         $this->form->addFields( [], [$add] );
  152.         
  153.         $this->detail_list = new BootstrapDatagridWrapper(new TDataGrid);
  154.         $this->detail_list->setId('ComprasSub_list');
  155.         $this->detail_list->generateHiddenFields();
  156.         $this->detail_list->style "min-width: 700px; width:100%;margin-bottom: 10px";
  157.         
  158.         // items
  159.         $this->detail_list->addColumn( new TDataGridColumn('uniqid''Uniqid''center') )->setVisibility(false);
  160.         $this->detail_list->addColumn( new TDataGridColumn('id_automatico''Id''center') )->setVisibility(false);
  161.         $this->detail_list->addColumn( new TDataGridColumn('quant''Quant''left'100) );
  162.         $this->detail_list->addColumn( new TDataGridColumn('descricao''Descricao''left'100) );
  163.         $this->detail_list->addColumn( new TDataGridColumn('unidade''Unidade''left'100) );
  164.         $this->detail_list->addColumn( new TDataGridColumn('valor_unit''Valor Unit''left'100) );
  165.         $this->detail_list->addColumn( new TDataGridColumn('subtotal''Subtotal''left'100) );
  166.         $this->detail_list->addColumn( new TDataGridColumn('tipo_compra_id''Tipo Compra Id''left'100) );
  167.         $this->detail_list->addColumn( new TDataGridColumn('tipo_compra_txt''Tipo Compra Txt''left'100) );
  168.         $this->detail_list->addColumn( new TDataGridColumn('kilate_id''Kilate Id''left'100) );
  169.         $this->detail_list->addColumn( new TDataGridColumn('kilate_txt''Kilate Txt''left'100) );
  170.         // detail actions
  171.         $action1 = new TDataGridAction([$this'onDetailEdit'] );
  172.         $action1->setFields( ['uniqid''*'] );
  173.         
  174.         $action2 = new TDataGridAction([$this'onDetailDelete']);
  175.         $action2->setField('uniqid');
  176.         
  177.         // add the actions to the datagrid
  178.         $this->detail_list->addAction($action1_t('Edit'), 'fa:edit blue');
  179.         $this->detail_list->addAction($action2_t('Delete'), 'far:trash-alt red');
  180.         
  181.         $this->detail_list->createModel();
  182.         
  183.         $panel = new TPanelGroup;
  184.         $panel->add($this->detail_list);
  185.         $panel->getBody()->style 'overflow-x:auto';
  186.         $this->form->addContent( [$panel] );
  187.         
  188.         $btn_gravar $this->form->addAction'SALVAR',  new TAction([$this'onSave'], ['static'=>'1']), 'fa:save white');
  189.         $btn_gravar->class 'btn btn-sm btn-primary';
  190.         
  191.         $btn_limpar $this->form->addAction'LIMPAR', new TAction([$this'onClear']), 'fa:eraser white');
  192.         $btn_limpar->class 'btn btn-sm btn-danger';
  193.         
  194.         $btn_voltar $this->form->addAction('VOLTAR',new TAction(array('ComprasList','onReload')),'far:arrow-alt-circle-left white');
  195.         $btn_voltar->class 'btn btn-sm btn-warning';
  196.         
  197.         //BOTÃO PARA GERAR PDF
  198.         $btn_print $this->form->addAction('RECIBO COMPRA', new TAction(array($this'OnPDF')),'far:arrow-alt-circle-left white');
  199.         $btn_print->class 'btn btn-sm btn-secondary';
  200.         
  201.         // create the page container
  202.         $container = new TVBox;
  203.         $container->style 'width: 100%';
  204.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  205.         $container->add($this->form);
  206.         parent::add($container);
  207.     }
  208.     
  209.     
  210.     /**
  211.      * Clear form
  212.      * @param $param URL parameters
  213.      */
  214.     public function onClear($param)
  215.     {
  216.         $this->form->clear(TRUE);
  217.     }
  218.     
  219.     /**
  220.      * Add detail item
  221.      * @param $param URL parameters
  222.      */
  223.     public function onDetailAdd$param )
  224.     {
  225.         try
  226.         {
  227.             $this->form->validate();
  228.             $data $this->form->getData();
  229.             
  230.             /** validation sample
  231.             if (empty($data->fieldX))
  232.             {
  233.                 throw new Exception('The field fieldX is required');
  234.             }
  235.             **/
  236.             
  237.             $uniqid = !empty($data->detail_uniqid) ? $data->detail_uniqid uniqid();
  238.             
  239.             $grid_data = [];
  240.             $grid_data['uniqid'] = $uniqid;
  241.             $grid_data['id_automatico'] = $data->detail_id_automatico;
  242.             $grid_data['quant'] = $data->detail_quant;
  243.             $grid_data['descricao'] = $data->detail_descricao;
  244.             $grid_data['unidade'] = $data->detail_unidade;
  245.             $grid_data['valor_unit'] = $data->detail_valor_unit;
  246.             $grid_data['subtotal'] = $data->detail_subtotal;
  247.             $grid_data['tipo_compra_id'] = $data->detail_tipo_compra_id;
  248.             $grid_data['tipo_compra_txt'] = $data->detail_tipo_compra_txt;
  249.             $grid_data['kilate_id'] = $data->detail_kilate_id;
  250.             $grid_data['kilate_txt'] = $data->detail_kilate_txt;
  251.             
  252.             // insert row dynamically
  253.             $row $this->detail_list->addItem( (object) $grid_data );
  254.             $row->id $uniqid;
  255.             
  256.             TDataGrid::replaceRowById('ComprasSub_list'$uniqid$row);
  257.             
  258.             // clear detail form fields
  259.             $data->detail_uniqid '';
  260.             $data->detail_id_automatico '';
  261.             $data->detail_quant '';
  262.             $data->detail_descricao '';
  263.             $data->detail_unidade '';
  264.             $data->detail_valor_unit '';
  265.             $data->detail_subtotal '';
  266.             $data->detail_tipo_compra_id '';
  267.             $data->detail_tipo_compra_txt '';
  268.             $data->detail_kilate_id '';
  269.             $data->detail_kilate_txt '';
  270.             
  271.             // send data, do not fire change/exit events
  272.             TForm::sendData'form_Compras'$datafalsefalse );
  273.         }
  274.         catch (Exception $e)
  275.         {
  276.             $this->form->setData$this->form->getData());
  277.             new TMessage('error'$e->getMessage());
  278.         }
  279.     }
  280.     
  281.     /**
  282.      * Edit detail item
  283.      * @param $param URL parameters
  284.      */
  285.     public static function onDetailEdit$param )
  286.     {
  287.         $data = new stdClass;
  288.         $data->detail_uniqid $param['uniqid'];
  289.         $data->detail_id_automatico $param['id_automatico'];
  290.         $data->detail_quant $param['quant'];
  291.         $data->detail_descricao $param['descricao'];
  292.         $data->detail_unidade $param['unidade'];
  293.         $data->detail_valor_unit $param['valor_unit'];
  294.         $data->detail_subtotal $param['subtotal'];
  295.         $data->detail_tipo_compra_id $param['tipo_compra_id'];
  296.         $data->detail_tipo_compra_txt $param['tipo_compra_txt'];
  297.         $data->detail_kilate_id $param['kilate_id'];
  298.         $data->detail_kilate_txt $param['kilate_txt'];
  299.         
  300.         // send data, do not fire change/exit events
  301.         TForm::sendData'form_Compras'$datafalsefalse );
  302.     }
  303.     
  304.     /**
  305.      * Delete detail item
  306.      * @param $param URL parameters
  307.      */
  308.     public static function onDetailDelete$param )
  309.     {
  310.         // clear detail form fields
  311.         $data = new stdClass;
  312.         $data->detail_uniqid '';
  313.         $data->detail_id_automatico '';
  314.         $data->detail_quant '';
  315.         $data->detail_descricao '';
  316.         $data->detail_unidade '';
  317.         $data->detail_valor_unit '';
  318.         $data->detail_subtotal '';
  319.         $data->detail_tipo_compra_id '';
  320.         $data->detail_tipo_compra_txt '';
  321.         $data->detail_kilate_id '';
  322.         $data->detail_kilate_txt '';
  323.         
  324.         // send data, do not fire change/exit events
  325.         TForm::sendData'form_Compras'$datafalsefalse );
  326.         
  327.         // remove row
  328.         TDataGrid::removeRowById('ComprasSub_list'$param['uniqid']);
  329.     }
  330.     
  331.     /**
  332.      * Load Master/Detail data from database to form
  333.      */
  334.     public function onEdit($param)
  335.     {
  336.         try
  337.         {
  338.             TTransaction::open('ourorio');
  339.             
  340.             if (isset($param['key']))
  341.             {
  342.                 $key $param['key'];
  343.                 
  344.                 $object = new Compras($key);
  345.                 $items  ComprasSub::where('compra_id''='$key)->load();
  346.                 
  347.                 foreach( $items as $item )
  348.                 {
  349.                     $item->uniqid uniqid();
  350.                     $row $this->detail_list->addItem$item );
  351.                     $row->id $item->uniqid;
  352.                 }
  353.                 $this->form->setData($object);
  354.                 TTransaction::close();
  355.             }
  356.             else
  357.             {
  358.                 $this->form->clear(TRUE);
  359.             }
  360.         }
  361.         catch (Exception $e// in case of exception
  362.         {
  363.             new TMessage('error'$e->getMessage());
  364.             TTransaction::rollback();
  365.         }
  366.     }
  367.     
  368.     /**
  369.      * Save the Master/Detail data from form to database
  370.      */
  371.     public function onSave($param)
  372.     {
  373.         try
  374.         {
  375.             // open a transaction with database
  376.             TTransaction::open('ourorio');
  377.             
  378.             $data $this->form->getData();
  379.             $this->form->validate();
  380.             
  381.             $master = new Compras;
  382.             $master->fromArray( (array) $data);
  383.             $master->store();
  384.             
  385.             ComprasSub::where('compra_id''='$master->id_compra)->delete();
  386.             
  387.             if( $param['ComprasSub_list_quant'] )
  388.             {
  389.                 foreach( $param['ComprasSub_list_quant'] as $key => $item_id )
  390.                 {
  391.                     $detail = new ComprasSub;
  392.                     $detail->quant  $param['ComprasSub_list_quant'][$key];
  393.                     $detail->descricao  $param['ComprasSub_list_descricao'][$key];
  394.                     $detail->unidade  $param['ComprasSub_list_unidade'][$key];
  395.                     $detail->valor_unit  $param['ComprasSub_list_valor_unit'][$key];
  396.                     $detail->subtotal  $param['ComprasSub_list_subtotal'][$key];
  397.                     $detail->tipo_compra_id  $param['ComprasSub_list_tipo_compra_id'][$key];
  398.                     $detail->tipo_compra_txt  $param['ComprasSub_list_tipo_compra_txt'][$key];
  399.                     $detail->kilate_id  $param['ComprasSub_list_kilate_id'][$key];
  400.                     $detail->kilate_txt  $param['ComprasSub_list_kilate_txt'][$key];
  401.                     $detail->compra_id $master->id_compra;
  402.                     $detail->store();
  403.                 }
  404.             }
  405.             TTransaction::close(); // close the transaction
  406.             
  407.             TForm::sendData('form_Compras', (object) ['id' => $master->id_compra]);
  408.             
  409.             TToast::show('success''Compra Registrada com Sucesso!''top left''far:check-circle' );
  410.             //AdiantiCoreApplication::loadPage( 'ComprasList' );
  411.             //exit;
  412.         }
  413.         catch (Exception $e// in case of exception
  414.         {
  415.             new TMessage('error'$e->getMessage());
  416.             $this->form->setData$this->form->getData() ); // keep form data
  417.             TTransaction::rollback();
  418.         }
  419.     }
  420.     
  421.     public function OnPDF($param)
  422.     {
  423.     $data $this->form->getData();
  424.     
  425.     $data_compra2 TDate::date2br($data->data_compra);
  426.     
  427.     $pdf = new TPDFDesigner;
  428.     $pdf->fromXml('app/reports/recibo_compra_cliente.pdf.xml');
  429.     
  430.     $pdf->replace('{id_compra}',$data->id_compra);
  431.     $pdf->replace('{data_compra}',$data->data_compra);
  432.   
  433.  
  434.     $pdf->replace('{cliente_txt}',utf8_decode($data->cliente_txt));
  435.     $pdf->replace('{endereco_tipo}',utf8_decode($data->cliente_endereco_tipo), 00'L');
  436.     $pdf->replace('{endereco_numero}',utf8_decode($data->cliente_endereco_numero), 00'L');
  437.     $pdf->replace('{endereco}',utf8_decode($data->cliente_endereco), 00'L');
  438.     $pdf->replace('{bairro}',utf8_decode($data->cliente_bairro), 00'L');
  439.   
  440.     $pdf->replace('{cpf}',utf8_decode($data->cliente_cpf), 00'L');
  441.     $pdf->replace('{identidade}',utf8_decode($data->cliente_identidade), 00'L');
  442.     $pdf->replace('{telefone}',utf8_decode($data->cliente_telefone), 00'L');
  443.     $pdf->replace('{nascimento}',utf8_decode($data->cliente_nascimento), 00'L');
  444.     $pdf->replace('{cidade}',utf8_decode($data->cliente_cidade), 00'L');
  445.     $pdf->replace('{estado}',utf8_decode($data->cliente_estado), 00'L');
  446.     $pdf->replace('{email}',utf8_decode($data->cliente_email), 00'L');
  447.    
  448.     $pdf->replace('{vendedor_txt}',utf8_decode($data->vendedor_txt));
  449.     $pdf->replace('{loja_txt}',utf8_decode($data->loja_txt));
  450.     
  451.     $pdf->generate();
  452.     //CABEÇALHO DETALHES                        
  453.     $pdf->SetFont('Arial','B',10);
  454.     $pdf->SetX(18); 
  455.     $pdf->SetFillColor(200200200);            
  456.     //$pdf->Cell(48, 22,'ITEM', 1, 0,'C', TRUE);
  457.     $pdf->Cell(5022utf8_decode('QUANT'), 10,'C'TRUE);                 
  458.     $pdf->Cell(30022utf8_decode('PRODUTO'), 10,'L'TRUE);
  459.     $pdf->Cell(3022utf8_decode('UND'), 10,'C'TRUE);
  460.     $pdf->Cell(7022utf8_decode('VALOR UNT'), 11,'R'TRUE);
  461.     $pdf->Cell(7022utf8_decode('SUBTOTAL'), 11,'R'TRUE);
  462.     
  463.     // Itens do Pedido
  464.    
  465.    
  466.                 
  467.     // inicio do rodapé
  468.     $pdf->SetY(-12);
  469.     $pdf->SetFont('Arial'''8);
  470.     $pdf->setFontColorRGB'#000000' );
  471.     $pdf->Cell(59010utf8_decode('Pág. ').$pdf->PageNo().' de {nb}',0,0,'R');
  472.     $pdf->SetY(-12);
  473.     $pdf->Cell(13010utf8_decode('Sistema Gestor OuroRio © 2021 '),0,0,'R');
  474.     $pdf->SetY(-12);
  475.     $pdf->Cell(340,10,utf8_decode("Impresso em ".date("d/m/Y H:i:s"."")),0,1,'R');
  476.     $pdf->SetY(-12);
  477.     $pdf->Cell(420,10,utf8_decode(" Por ".TSession::getValue('username')),0,1,'R'); //nome do usuário 
  478.     // fim do rodapé
  479.     
  480.    
  481.     
  482.     $file 'app/output/' .time(). '-Recibo.pdf';
  483.     if (!file_exists($file) OR is_writable($file))
  484.     {
  485.     $pdf->save($file);
  486.     //parent::openFile($file);
  487.     
  488.     $window TWindow::create('Ouro Rio'0.80.8);
  489.                 $object = new TElement('object');
  490.                 $object->data  $file;
  491.                 $object->type  'application/pdf';
  492.                 $object->style "width: 100%; height:calc(100% - 10px)";
  493.                 $window->add($object);
  494.                 $window->show();
  495.                 
  496.     }
  497.     else
  498.     {
  499.     throw new Exception(_t('Permission denied') . ': ' $file);
  500.     } 
  501.     
  502.     TToast::show('success','RECIBO GERADO COM SUCESSO!''top left''fas fa-check');
  503.     
  504.     TTransaction::close();
  505.     AdiantiCoreApplication::loadPage'ComprasList' );
  506.     exit;
  507.     
  508.     }
  509.     
  510.     
  511.     // CÓDIGO PARA PASSAR VALORES DO CLIENTE AOS CAMPOS
  512.     public static function onExitCliente($param)
  513.     {
  514.         $cliente_id $param['cliente_id']; // get the product code
  515.         try
  516.         {
  517.             TTransaction::open('ourorio');
  518.             $cliente = new Clientes($cliente_id); // reads the product
  519.             
  520.             $obj = new StdClass;
  521.             //$obj->detail_valor_unit  = number_format($produto->valor_unit, 2, ',', '.');
  522.             //$obj->detail_quantidade = 1;
  523.             //$obj->detail_valor_total = number_format($produto->valor_unit, 2, ',', '.');
  524.             $obj->cliente_cep = ($cliente->cep);
  525.             $obj->cliente_endereco_tipo = ($cliente->endereco_tipo);
  526.             $obj->cliente_endereco = ($cliente->endereco);
  527.             $obj->cliente_endereco_numero = ($cliente->endereco_numero);
  528.             $obj->cliente_bairro = ($cliente->bairro);
  529.             $obj->cliente_cidade = ($cliente->cidade);
  530.             $obj->cliente_estado = ($cliente->estado);
  531.             $obj->cliente_telefone = ($cliente->telefone);
  532.             $obj->cliente_nascimento = ($cliente->data_nascimento);
  533.             $obj->cliente_identidade = ($cliente->identidade);
  534.             $obj->cliente_email = ($cliente->email);
  535.             $obj->cliente_cpf = ($cliente->cpf);
  536.           
  537.             
  538.             TScript::create('setTimeout(function() { $("input[name=\'detail_quantidade\']").focus() }, 500);');
  539.             
  540.             TTransaction::close();
  541.             TForm::sendData('form_Compras'$obj);
  542.         }
  543.         catch (Exception $e)
  544.         {
  545.             new TMessage('error'$e->getMessage());
  546.             $this->form->setData$this->form->getData() ); // keep form data
  547.             TTransaction::rollback();
  548.         }
  549.     }
  550.     
  551. }
  552. ?>

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


Meu negócio pronto Quero me inscrever agora!

Comentários (2)


NR

Você está criando o campo "id_compra", mas não está adicionando ao formulário. Dessa forma, ao salvar, esse valor vai como null e acaba sendo gravado como um novo registro.
  1. <?php
  2. $id_compra = new THidden('id_compra');
  3. // $id_compra precisa ser passado em addFields...
  4. ?>
CM

Bom dia Nataniel.
Obrigado por sua dica. Resolveu.
Mas no meu tópico ficou a outra dúvida de erro nesta linha:

Notice: Undefined index: ComprasSub_list_quant in C:xampphtdocsadiantiourorioappcontrolourorioComprasForm.php on line 399

Que aqui neste post está na linha 391