By: David
Date: 2012-06-09
Time: 20:07
|
Help with sub blocks
I am trying to print a variety of items related to a year ending date.
This is our data:
$year_ending_array Array ( [0] => 2012-05 [1] => 2011-05 [2] => 2010-05 )
$adjusted_gross_sales_display Array ( [2012-05] => -296,669.00 [2011-05] => 467,987.00 [2010-05] => 68,801.00 )
$adjusted_cogs_display Array ( [2012-05] => -198,766.00 [2011-05] => 341,345.00 [2010-05] => 6,912.00 ) |
This is the template I tried to use:
Date [onshow..now;frm='yyyy-mm-dd']
Year Ending: [annualincome.val;block=w:p;frm='mmmm, yyyy']
(Note: there is a table here, but it is cut and pasted from word)
Position Amount
Gross Sales [sb.val;block=w:tr;p1=annualincome.val]
Cost of Goods Sold [sb.$;block=w:tr;p1=annualincome.val]
blah |
but all I get back is the years and the header row of the table
Date 2012-06-09
Year Ending: May, 2012
Year Ending: May, 2011
Year Ending: May, 2010
Position Amount
blah |
The php code that I am using is:
$TBS->LoadTemplate(SMARTY_PRIVATE_DIR.'templates/'.'test.docx');
//Print Testin output
//print 'year ending array' ;print_r($year_ending_array) ;
//print '$adjusted_gross_sales_display' ; print_r($adjusted_gross_sales_display) ;
//print '$adjusted_cogs_display' ; print_r ($adjusted_cogs_display);
// Merge data
$TBS->MergeBlock('annualincome', $year_ending_array);
$TBS->MergeBlock('sb1', $adjusted_gross_sales_display );
$TBS->MergeBlock('sb','array','adjusted_gross_sales_display[%p1%]');
$TBS->Show(OPENTBS_DOWNLOAD, $file_name);
|
I think that I am just not understanding sub-blocks. Can I not pick values out of an array based on the value of the first array that I am cycling through?
|
By: Skrol29
Date: 2012-06-09
Time: 22:39
|
Re: Help with sub blocks
Hi David,
I've moved your post to the MS Office category because it is somehow related with DOCX.
The first thing is that your sub-blocks should be embedded in the main block.
That is not the case is your snipped because Ms Word tables are not embedded in paragraphs. Tables take the place of a paragraph.
Thus, in order to embed your sub-blocks, you have to replace "block=w:p" with "block=w:p+w:tbl".
The second thing is that parameter "p1" assumes to have a value. That's why it is usually a TBS field which is merged before p1 is evaluated.
For this, replace "p1=annualincome.val" with "p1=[annualincome.val]".
|
By: David
Date: 2012-06-09
Time: 23:37
|
Re: Help with sub blocks
Skrol,
Thanks very much for the help. I now get the entire table but still can't get just the one year's Gross Sales to show up.
So, I now get results that look like:
Year Ending: May, 2012
Position Amount
Gross Sales -296,669.00
Gross Sales 467,987.00
Gross Sales 68,801.00
Year Ending: May, 2011
Position Amount
Gross Sales -296,669.00
Gross Sales 467,987.00
Gross Sales 68,801.00
Year Ending: May, 2010
Position Amount
Gross Sales -296,669.00
Gross Sales 467,987.00
Gross Sales 68,801.00
|
whether I use [sb.val;block=w:tr;p1=[annualincome.$]] or [sb.val;block=w:tr;p1=[annualincome.val]] in the sub block.
What I am trying to get is:
Year Ending: May, 2012
Position Amount
Gross Sales -296,669.00
Year Ending: May, 2011
Position Amount
Gross Sales 467,987.00
Year Ending: May, 2010
Position Amount
Gross Sales 68,801.00 |
Then I'll start adding other rows with different data related to each year.
|
By: Skrol29
Date: 2012-06-11
Time: 01:23
|
Re: Help with sub blocks
It should work if you avoid the line
$TBS->MergeBlock('sb1', $adjusted_gross_sales_display );
|
And, by the way, I cannot see any "sb1" block in your snippet.
|
By: David
Date: 2012-06-11
Time: 20:33
|
Re: Help with sub blocks
That did not work for me. However, I have come up with a workaround that seems to do what I want. I am posting it here in the hope that it will be helpful to someone.
I noticed that in the example both the block and sub-block were contained in the same array so I used a loop to combine the header ($year_ending_array) and detail ($adjusted_gross_sales_display) arrays. The code now looks like this:
foreach ($year_ending_array as $value){
$financialsbyyear[$value]['agsd']=$adjusted_gross_sales_display[$value] ;
}
$TBS->VarRef['financialsbyyear']= $financialsbyyear;
$TBS->MergeBlock('asb',$financialsbyyear);
//print_r ($financialsbyyear);
// Merge data
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
$TBS->MergeBlock('tfc', $total_fair_compensation);
$TBS->MergeBlock('osa', $year_ending_array);
// $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW);
$TBS->Show(OPENTBS_DOWNLOAD, $file_name); |
and the template looks like this:
Year Ending: [asb.$;block=w:p+w:tbl;frm='mmmm, yyyy']
Position Amount
Gross Sales [asb.agsd;block=w:tr;p1=[asb.$]]
|
For what it is worth I am using this to replace a looped structure in smarty that looks like this:
{foreach from=$year_ending_array item=year}
<p>
<table border="1">
<tr>
<td width="216"> </td>
<td width="216">Year Ended {$year|date_format:"%m/%y"}</td>
</tr>
<tr><td width="216">Gross Sales</td><td width="216">{$adjusted_gross_sales_display[$year]}</td></tr>
<tr><td width="216">Less COGS</td><td width="216">{$adjusted_cogs_display[$year]}</td></tr>
<tr>
<td width="216">Less Overhead Expenses</td>
<td width="216">{$adjusted_overhead_expenses_display[$year]}</td>
... more table rows ...
</table>
</p>
{/foreach}
|
|
|
Posting in progress.
Please wait...
|