0

Hello I hope you can help me. I am trying to use sub-blocks with the following array that you come from 2 mysql queries.

$data[$i]= array(
"ref"=>$row['ref'], 
"label"=>$row['label'],
"unidad"=>$row['cu_label'], 
"rawdata" => array(
  "fecha"=>$ro['fecha'],
  "stock_total"=>$ro['stock_total'],
  "venta_unit"=>$ro['venta_unit'],
  "venta_total"=>$ro['venta_total']
   )
); 

$TBS->MergeBlock('p', $data);

In the xlsx template I am calling like this

 [p;block=begin;sub1=rawdata]
   [p.ref]
   [p.label]
   [p.unidad]
    [p_sub1.fecha;block=tbs:row]
    [p_sub1.stock_total;block=tbs:row]
    [p_sub1.venta_unit;block=tbs:row]
    [p_sub1.venta_total;block=tbs:row]
 [p;block=end]

but for the sud-block rawdata it gives me error item 'date' is not an existing key in the array.

any idea how i can solve. thanks

  • Are you sure the error message is _« item 'date' is not an existing key in the array »_, since there is no 'date' in your code snippet ? – Skrol29 Jan 21 '21 at 17:44
  • if there is a value for the sub-array. if I put this way [p_sub1.val;block=tbs:row] it shows me everything in the same column – aitorxs Jan 21 '21 at 21:44

1 Answers1

1

I can see several mistakes :

1)

The data for the sub-block should be a "recordset", that is an array of array.

In your snippet, you should replace:

"rawdata" => array(
  "fecha"=>$ro['fecha'],
  "stock_total"=>$ro['stock_total'],
  "venta_unit"=>$ro['venta_unit'],
  "venta_total"=>$ro['venta_total']
   )

with:

"rawdata" => array(
  array(
    "fecha"=>$ro['fecha'],
    "stock_total"=>$ro['stock_total'],
    "venta_unit"=>$ro['venta_unit'],
    "venta_total"=>$ro['venta_total'],
  ),
 ),

Thus the data structure is correct, but the sub block always have only one record. This is maybe not what you expect.

2)

The sub-block definition in the XLSX will not display 4 rows.

With OpenTBS, when you repeat "block=…" that produces alternative sections.

In order to have a sub-block defined on 4 rows you should write :

 [p;block=begin;sub1=rawdata]
   [p.ref]
   [p.label]
   [p.unidad]
    [p_sub1.fecha;block=4*tbs:row] (this will define a block over 4 rows, including this one)
    [p_sub1.stock_total]
    [p_sub1.venta_unit]
    [p_sub1.venta_total] (the last row of block 'p_sub1')
 [p;block=end]

With XML templates such as Ms Officve or LibreOffice, it is not advised to define a block with the explict syntax (block=beginblock=end). This is because you cannot imaging where the XLM entities bounds are actually positioned.

And you need luck in order to have a valid XML result. If you put a different color on each of you row in the template, then watch the color in the result. You’ll see that block=begin has broken some rows in the middle.

The good practice with OpenTBS is to define block bounds with the relative syntax, such as block=tbs:row.

I suggest you template should be :

 [p;block=8*tbs:row;sub1=rawdata] (8 rows including the sub-block)
   [p.ref]
   [p.label]
   [p.unidad]
    [p_sub1.fecha;block=4*tbs:row] (this will define a block over 4 rows, including this one)
    [p_sub1.stock_total]
    [p_sub1.venta_unit]
    [p_sub1.venta_total] (the last row of block 'p_sub1')
Skrol29
  • 5,402
  • 1
  • 20
  • 25