conditional block display with TBS in DOCX tables

199 Views Asked by At

I am processing DOCX files for invoices with TBS. A first TBS block contains all the taxable items, one per line, followed by lines for subtotal and tax. A second TBS block contains all the non-taxable items, followed by one line for grand total.

I would like to leave out the first block, the subtotal and the tax amount if there are no taxable items. I also would like to leave the second block out if there are no non-taxable items.

This is the basic structure:

[ItemListTx;block=begin]
  [ItemListTx.s]  [ItemListTx.a]
[ItemListTx;block=end]
subtotal          [abk.tt]
tax               [abk.tx]

[ItemListEx;block=begin;enlarge=tbs:p]
  [ItemListTx.s]  [ItemListTx.a]
[ItemListEx;block=end;enlarge=tbs:p]

total             [abk.ttlx]

I wrapped the first five lines into a guarding block with a condition under which to display it:

[onshow;block=begin;enlarge=tbs:p;when 0=1]
...
[onshow;block=end;enlarge=tbs:p]

I did the same for the second block. This works OK. Note that the wrapper block statements are on different lines.

I am still a bit unhappy with the condition though. Is there any other way than setting a flag on the PHP side? It seems to me the second block should do without a wrapper, too.

Note: For editing reasons each item line is a table in itself, really.

1

There are 1 best solutions below

1
Skrol29 On

Here is how it can easily be done:

| [ItemListTx.s;block=tbs:row;bmagnet=3*tbs:row] | [ItemListTx.a] |
| Subtotal:                                      | [abk.tt]       |
| Tax:                                           | [abk.tx]       |

| [ItemListEx.s;block=tbs:row;bmagnet=3*tbs:row] | [ItemListEx.a] |

| Total:                                         | [abk.ttlx]     |

Explanations:

  • Parameter bmagnet enabled you to define the block to delete when the data to merge with MergeBlock() are empty.
  • 3*tbs:row means 3 successive table rows.
  • With OpenTBS it is not recommended to use explicit blocks (block=begin/block=end) because we cannot be sure where they is placed in the inner XML. It is better to use relatives blocks (such as block=tbs:p).