Erro: Campo "REFERENCIA" não existe ou contém valor NULL Boa Noite Pessoal! Alguém já teve algum erro parecido? Essa mensagem aparece assim que eu carrego a minha classe. Já olhei em tudo mas não identifico. Vlw a todos!!...
AF
Erro: Campo "REFERENCIA" não existe ou contém valor NULL  
Boa Noite Pessoal!
Alguém já teve algum erro parecido? Essa mensagem aparece assim que eu carrego a minha classe.
Já olhei em tudo mas não identifico.
Vlw a todos!!

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 (14)


NR

Parece ser um erro na datagrid.

Você está criando alguma ação apontando para o campo referência, mas este campo não existe ou está vazio.
AF

Olá Nataniel!
Bom, realmente, estou criando uma ação apontando para o campo referência, mas criei o campo sim.. Realmente não compreendo o que está ocorrendo..
Segue o código:

 
  1. <?php
  2. $this->form_item = new TForm('form_pos');
  3. $this->form_item->class = 'tform';
  4. $table_item = new TTable;
  5. $table_item-> width = '100%';
  6. $this->form_item->add($table_item);
  7. // create the form fields
  8. $REFERENCIA = new TEntry('REFERENCIA');
  9. $QUANTIDADE = new TEntry('QUANTIDADE');
  10. // add validators
  11. $REFERENCIA->addValidation('produto', new TRequiredValidator);
  12. // define some attributes
  13. $REFERENCIA->style = 'font-size: 17pt; height: 30px';
  14. $QUANTIDADE->style = 'font-size: 17pt; height: 30px';
  15. // define some properties
  16. $REFERENCIA->setSize(100);
  17. $QUANTIDADE->setSize(100);
  18. $row = $table_item->addRow();
  19. $row->class = 'tformtitle'; // CSS class
  20. $cell = $row->addCell( new TLabel('PRÉ-VENDA'));
  21. $cell->colspan = 4;
  22. // create the field labels
  23. $lab_codigo = new TLabel('C&oacute;digo');
  24. $lab_quantidade = new TLabel('Quantidade');
  25. $lab_codigo->setFontSize(17);
  26. $lab_quantidade->setFontSize(17);
  27. $lab_codigo->setFontFace('Trebuchet MS');
  28. $lab_quantidade->setFontFace('Trebuchet MS');
  29. $lab_codigo->setFontColor('red');
  30. $lab_quantidade->setFontColor('red');
  31. // creates the action button
  32. $button1 = new TButton('add');
  33. $button1->setAction(new TAction(array($this, 'onAddItem')), 'Adicionar');
  34. $button1->setImage('ico_add.png');
  35. // add the form fields
  36. $table_item->addRowSet($lab_codigo, $REFERENCIA,$lab_quantidade, array($QUANTIDADE, $button1));
  37. // define the form fields
  38. $this->form_item->setFields(array($REFERENCIA, $QUANTIDADE, $button1));
  39. // creates the customer form and add a table inside it
  40. $this->form_customer = new TForm('form_customer');
  41. $this->form_customer->class = 'tform';
  42. $table_customer = new TTable;
  43. $table_customer-> width = '100%';
  44. $this->form_customer->add($table_customer);
  45. // add a row for the form title
  46. $row = $table_customer->addRow();
  47. $row->class = 'tformtitle'; // CSS class
  48. $cell = $row->addCell( new TLabel('Cliente'));
  49. $cell->colspan = 5;
  50. // create the form fields
  51. $vendedor = new TDBCombo('vendedor', 'sample', 'vendedor', 'id', 'nome');
  52. $customer_name = new TEntry('customer_name');
  53. $this->totalForm = new TEntry('totalForm');
  54. $this->totalForm->style = 'font-size: 17pt; height: 30px; background-color: black;color: white;';
  55. $this->totalForm->setEditable(FALSE);
  56. // define validation and other properties
  57. $vendedor->addValidation('VENDEDOR', new TRequiredValidator);
  58. $customer_name->addValidation('CLIENTE', new TRequiredValidator);
  59. $customer_name->style = 'font-size: 17pt; height: 30px';
  60. //$this->totalForm->setEditable(FALSE);
  61. // create tha form labels
  62. $lab_cus = new TLabel('Vendedor');
  63. $lab_nam = new TLabel('Cliente');
  64. $lab_total = new TLabel('Total');
  65. $lab_cus->setFontSize(17);
  66. $lab_nam->setFontSize(17);
  67. $lab_total->setFontSize(17);
  68. $lab_cus->setFontFace('Trebuchet MS');
  69. $lab_nam->setFontFace('Trebuchet MS');
  70. $lab_total->setFontFace('Trebuchet MS');
  71. $lab_cus->setFontColor('red');
  72. // action button
  73. $button2 = new TButton('save');
  74. $button2->setAction(new TAction(array($this, 'onSave')), 'Finalizar Venda');
  75. // $button2->setImage('ico_save.png');
  76. $button2->class = 'btn btn-success btn-lg';
  77. // add the form fields inside the table
  78. $table_customer->addRowSet( $lab_nam, $customer_name, $lab_total, $this->totalForm, $button2);
  79. $table_customer->addRowSet( $lab_cus, $vendedor);
  80. // define the form fields
  81. $this->form_customer->setFields(array($customer_name, $button2, $vendedor));
  82. // creates the grid for items
  83. $this->cartgrid = new TQuickGrid;
  84. $this->cartgrid->class = 'tdatagrid_table customized-table';
  85. // $this->cartgrid->makeScrollable();
  86. $scroll = new TScroll();
  87. $scroll->setSize('100%','240');
  88. $scroll->add($this->cartgrid);
  89. $this->cartgrid->setHeight( 150 );
  90. parent::include_css('app/resources/custom-table.css');
  91. $this->cartgrid->addQuickColumn('Referência', 'REFERENCIA', 'right', 55);
  92. $this->cartgrid->addQuickColumn('Descrição', 'DESCRICAO', 'left', 240);
  93. $this->cartgrid->addQuickColumn('Preço', 'PRECO', 'right', 100);
  94. $this->cartgrid->addQuickColumn('Qtd', 'QUANTIDADE', 'right', 70);
  95. $this->cartgrid->addQuickColumn('Total', 'total', 'right', 100);
  96. $this->cartgrid->addQuickAction('Delete', new TDataGridAction(array($this, 'onDelete')), 'REFERENCIA', 'ico_delete.png');
  97. $this->form_total = new TForm('form_total');
  98. $this->form_total->class = 'tform';
  99. $table_total = new TTable;
  100. $table_total-> width = '100%';
  101. $this->form_total->add($table_total);
  102. $rowtotal = $table_total->addRow();
  103. $rowtotal->style = "text-align: center;";
  104. $rowtotal->class = 'tformtitle'; // CSS class
  105. $rowtotal->colspan = 7;
  106. $this->label = new TLabel('TOTAL:');
  107. $this->label->setSize('30');
  108. $this->label->setFontColor('red');
  109. $this->label->style="text-align: center";
  110. //$LBL_UNIDADE->colspan = 3;
  111. $celltotal = $rowtotal->addCell($this->label);
  112. $celltotal->colspan = 3;
  113. $this->cartgrid->createModel();
  114. // wrap the page content using vertical box
  115. $vbox = new TVBox;
  116. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  117. $vbox->add($this->form_item);
  118. $vbox->add($scroll);
  119. //$vbox->add(new TLabel('&nbsp;'));
  120. //$vbox->add($this->cartgrid);
  121. $vbox->add(new TLabel('&nbsp;'));
  122. //$vbox->add($this->form_total);
  123. //$vbox->add(new TLabel('&nbsp;'));
  124. $vbox->add($this->form_customer);
  125. parent::add($vbox);
  126. ?>

AF

Verifique as linhas 9 e 120.
Tentei fazer o mais parecido com o do tutor... Mas realmente não dá certo.
Agradeço pela força!
NR

Procure no seu código pelo trecho abaixo, que deve estar na função onReload:
 
  1. <?php
  2. $this->cartgrid->addItem($object);
  3. ?>


Inspecione a variável $object e veja o que retorna. Ela precisa ter o atributo REFERENCIA definido.
AF

Inspecionei a variável $object como me disse, com um var_dump e obtive sucesso, ou seja, a variável REFERENCIA está definida. Veja só o var_dump:
array (size=1)
0 =>
object(Produto)[3]
protected 'data' =>
array (size=13)
'id' => string '1' (length=1)
'DESCRICAO' => string '70122-02 SAPATENIS MASCULINO 37/1' (length=33)
'QUANTIDADE' => int 2
'REFERENCIA' => string '7895570660630' (length=13)
'NFE_id' => string '1' (length=1)
'DTCADASTRO' => string '2016-08-26' (length=10)
'PRECO' => string '59.90' (length=5)
'FOTO' => string 'Produtos/cielo.jpg' (length=18)
'PACOTECOM' => string '1' (length=1)
'qtdTOTAL' => string '1' (length=1)
'REFERENCIASITE' => null
'TAXADESCONTO' => string '10' (length=2)
'total' => string '59,90' (length=5)
protected 'vdata' => null
protected 'attributes' =>
array (size=11)
0 => string 'DESCRICAO' (length=9)
1 => string 'QUANTIDADE' (length=10)
2 => string 'qtdTOTAL' (length=8)
3 => string 'REFERENCIA' (length=10)
4 => string 'NFE_id' (length=6)
5 => string 'DTCADASTRO' (length=10)
6 => string 'PRECO' (length=5)
7 => string 'FOTO' (length=4)
8 => string 'PACOTECOM' (length=9)
9 => string 'REFERENCIASITE' (length=14)
10 => string 'TAXADESCONTO' (length=12)

O mais estranho que acho é que em localhost a apliação funciona normalmente e na web dá este erro.
Outro fator que percebi é que só é mostrado tal erro no momento em que adiciono um novo registro na datagrid.
NR

Poste o código da função onAddItem.
AF

Segue o código da função onAddItem:

 
  1. <?php
  2. public function onAddItem()
  3. {
  4. try
  5. {
  6. $this->form_item->validate(); // validate form data
  7. TTransaction::open('sample');
  8. $items = TSession::getValue('produtos'); // get items from session
  9. $item = $this->form_item->getData();
  10. new TMessage("info","A ref digitada é: $item->REFERENCIA");
  11. //new TMessage("info", $item->QUANTIDADE);
  12. if($item->QUANTIDADE == null || $item->QUANTIDADE == 0){
  13. $item->QUANTIDADE = 1;
  14. }
  15. $criteria = new TCriteria;
  16. $criteria->add(new TFilter('REFERENCIA', '=', $item->REFERENCIA));
  17. $repositoryProdutos = new TRepository('produto');
  18. $produtosCarregados = $repositoryProdutos->load($criteria);
  19. if($produtosCarregados){
  20. foreach($produtosCarregados as $produto){
  21. $i = 1;
  22. $valor = 0;
  23. $aux3 = 0;
  24. if($items!=null){
  25. foreach ($items as $aux2)
  26. {
  27. if($aux2->REFERENCIA ==$item->REFERENCIA){
  28. $aux2->QUANTIDADE += $item->QUANTIDADE;
  29. $aux3 = 1;
  30. }
  31. }
  32. if($aux3 == 0){
  33. $produto->QUANTIDADE = $item->QUANTIDADE;
  34. array_unshift($items , $produto);
  35. //$items[ ] = $produto; // add the item
  36. }
  37. foreach ($items as $o)
  38. {
  39. $i++;
  40. $valor += ($o->PRECO * $item->QUANTIDADE);
  41. }
  42. }
  43. if($items==null){
  44. $i++;
  45. $valor = ($produto->PRECO * $item->QUANTIDADE);
  46. $produto->QUANTIDADE = $item->QUANTIDADE;
  47. //$produto->REFERENCIA = $item->REFERENCIA;
  48. $items[ ] = $produto; // add the item
  49. new TMessage("info","Entrou no null");
  50. }
  51. }
  52. TSession::setValue('produtos', $items); // store back tthe session
  53. $this->form_item->clear(); // clear form
  54. $this->onReload(); // reload data
  55. }
  56. TTransaction::close();
  57. }
  58. catch (Exception $e) // in case of exception
  59. {
  60. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  61. }
  62. }
  63. ?>
AF

Será que pode ser algo relacionado a versão do PHP?
Em localhost tá normal...
NR

Qual a versão do PHP no server?

Mas não parece ser erro relacionado a versão.

Abra a classe TDataGrid.php e procure pelo trecho abaixo na função prepareAction:
 
  1. <?php
  2. if ( !isset( $object->$field ) )
  3. {
  4. // adicione o var_dump pra ver as informacoes do objeto antes de dar o erro
  5. var_dump($object);
  6. throw new Exception(AdiantiCoreTranslator::translate('Field ^1 not exists or contains NULL value', $field));
  7. }
  8. ?>
AF

Nataniel, no server o PHP é o 5.5.14. Em localhost é o 5.5.30.
Muito estranho esse erro.. Em localhost ok, na web nada.
Até mudei para TDataGrid ao invés de TQuickGrid.
Fiz assim:

 
  1. <?php
  2. $referenciaColuna = new TDataGridColumn('REFERENCIA', 'Referência', 'right', 100);
  3. $descricaoColuna = new TDataGridColumn('DESCRICAO', 'Descrição', 'left', 240);
  4. $precoColuna = new TDataGridColumn('PRECO', 'Preço', 'right', 100);
  5. $quantidadeColuna = new TDataGridColumn('QUANTIDADE', 'Qtd.', 'right', 70);
  6. $totalColuna = new TDataGridColumn('total', 'Total', 'right', 100);
  7. $this->cartgrid->addColumn($referenciaColuna);
  8. $this->cartgrid->addColumn($descricaoColuna);
  9. $this->cartgrid->addColumn($precoColuna);
  10. $this->cartgrid->addColumn($quantidadeColuna);
  11. $this->cartgrid->addColumn($totalColuna);
  12. $action1 = new TDataGridAction(array($this, 'onDelete'));
  13. $action1->setLabel('Delete');
  14. $action1->setImage('ico_delete.png');
  15. $action1->setField('REFERENCIA');
  16. $this->cartgrid->addAction($action1);
  17. $this->cartgrid->createModel();
  18. ?>

E o erro persiste.
AF

Se eu comento o setField fica sem erros..Mas eu preciso passar o campo por parâmetro..
NR

Coloque o var_dump que mencionei no post anterior e veja o que retorna
TF

Olá pessoal. Tmb estou com esse erro, alguém consegui responder?
IV

Bom dia, alguém conseguiu resolver este problema??