<?php
$w = "70"; // first column width
$w2 = "15"; // second column width
$content = '
<table style="width: 100%; font-size: 8pt;">
	<tr>		
		<td style="width: ' . $w . '%">
			<b><h1>Dokument KS</h1></b>
		</td>
		<td style="width: ' . $w2 . '%">
			 Numer: 
		</td>
		<td style="text-align: right">
			<b>' . $focus->document_no . '</b>
		</td>
	</tr>
	<tr>		
		<td style="width: ' . $w . '%">
			&nbsp;
		</td>
		<td style="width: ' . $w2 . '%">
			</b>Data wystawienia:</b> 
		</td>
		<td style="text-align: right">
			<b>' . $focus->register_date . '</b>
		</td>
	</tr>
	<tr>		
		<td style="width: ' . $w . '%">
			&nbsp;
		</td>
		<td style="width: ' . $w2 . '%">
			Wystawił: 
		</td>
		<td style="text-align: right">
			<b>' . $user->full_name . '</b>
		</td>
	</tr>
	<tr>		
		<td style="width: ' . $w . '%">
			&nbsp;
		</td>
		<td style="width: ' . $w2 . '%">
			Magazyn: 
		</td>
		<td style="text-align: right">
			<b>' . $focus->stock_name . '</b>
		</td>
	</tr>
	<tr>		
		<td style="width: ' . $w . '%">
			&nbsp;
		</td>
		<td style="width: ' . $w2 . '%">
			Typ: 
		</td>
		<td style="text-align: right">
			<b>' . $app_list_strings['ecmstockdoccorrects_type_dom'][$focus->type] . '</b>
		</td>
	</tr>
</table><br>
';
if ($focus->name && $focus->name != '') {
	$content .= '
		<table style="width: 100%; text-align: center">
			<tr><td>
				<b>' . $focus->name . '</b>
			</td></tr>
		</table>
';
}

$content .= '<br>';

// start items table
$columns = array ();

$columns ['position'] = array (
		'field' => array (
				'position' 
		),
		'label' => 'Lp.',
		'align' => 'center' 
);

$columns ['name'] = array (
		'field' => array (
				'name',
				'product_code' 
		),
		'label' => 'Nazwa<br>Indeks',
		'align' => 'left' 
);
$columns ['qty'] = array (
		'field' => array (
				'quantity',
				'unit_name' 
		),
		'label' => 'Ilość<br>J.m.',
		'align' => 'right' 
);

$columns ['price'] = array (
		'field' => array (
				'price' 
		),
		'label' => 'Cena',
		'align' => 'right' 
);

$columns ['total'] = array (
		'field' => array (
				'total' 
		),
		'label' => 'Wartość',
		'align' => 'right' 
);

// set widths
$totals = array ();

$columns ['position'] ['width'] = '5';
$columns ['name'] ['width'] = '45';
$columns ['qty'] ['width'] = '10';
$columns ['price'] ['width'] = '20';
$columns ['total'] ['width'] = '20';

// rysujemy :)
$content .= '
	<table style="width: 100%; font-size: 7pt; border: 0.5 solid black; border-collapse: collapse"><thead>
		<tr>
';

foreach ( $columns as $col ) {
	$content .= '
		<th style="border: 0.5 solid black; width: ' . $col ['width'] . '%;">' . $col ['label'] . '</th>		
	';
}
$content .= '
	</tr></thead><tbody>
';

foreach ( $positions as $pos ) {
	$content .= '<tr>';
	foreach ( $columns as $col ) {
		$content .= '<td style="border: 0.5 solid black; text-align: ' . $col ['align'] . ';">';
		foreach ( $col ['field'] as $f ) {
				if (! $pos [$f] || $pos [$f] == '')
					$pos [$f] = '-';
				$content .= $pos [$f] . '<br>';
		}
		$content .= '</td>';
	}
	$content .= '</tr>';
}

$content .= '
	</tbody></table>
';
// summary table
// get currency symbol
$c = new Currency ();
$c->retrieve ( $focus->currency_id );
$symbol = $c->symbol;
unset ( $c );
$content .= '
	<br><br>
	<table style="font-size: 9pt; border: 0.5 solid black; border-collapse: collapse; width: 215px; margin-left: 70%">
';

$content .= '
		<tr>
			<td style="border: 0.5 solid black; width: 50%;">
				Suma
			</td>
			<td style="border: 0.5 solid black; text-align: right;">
				' . format_number ( $focus->total) . ' ' . $symbol . '
			</td>
		</tr>
		';
$content .= '
	</table>
	<br><br>
	' . $focus->pdf_text . '			
';

//echo $content; die();








