<?php
$w = "40"; // first column width
$w2 = "30"; // second column width
$w3= "20";
global $app_list_strings;

$content ='<p style="text-align: center;"><b>'.$labels['LBL_PDF_DOCUMENT_NO'].' '.$focus->document_no.'</b></p>
<table style="width: 100%; font-size: 8pt;">
	<tr>		
		<td style="width: ' . $w . '%">
			<b>'.$labels['LBL_PDF_CONTENT_INVOICE_FOR'].'</b>
		</td>
		<td style="width: ' . $w3 . '%">';
		if($focus->shipping_address_name!=''){ 
			$content.= '<b>DOSTAWA DO</b>';
		}
		$content.= '</td>
		<td style="width: ' . $w2 . '%">
		</td>
		<td style="text-align: right">
	
		</td>
	</tr>
	<tr>		
		<td style="width: ' . $w . '%">
			' . $focus->parent_name . '
		</td>
		<td style="width: ' . $w3 . '%">
			'.$focus->shipping_address_name.'
		</td>
		<td style="width: ' . $w2 . '%">
		</td>
		<td style="text-align: right">
	
		</td>
	</tr>
	<tr>		
		<td style="width: ' . $w . '%">
			' . $focus->parent_address_street . '
		</td>
		<td style="width: ' . $w3 . '%">
			' . $focus->shipping_address_street . '
		</td>
		<td style="width: ' . $w2 . '%"></td>
		<td style="text-align: right">
	
		</td>
	</tr>
	<tr>		
		<td style="width: ' . $w . '%">
			'. $focus->parent_address_postalcode . ' ' . $focus->parent_address_city;
		if (!is_null($focus->parent_address_country) & $focus->parent_address_country!='')
			$content.=', '.$focus->parent_address_country;
	$content.='
		</td>
		<td style="width: ' . $w3 . '%">
			'. $focus->shipping_address_postalcode . ' ' . $focus->shipping_address_city;
	if (!is_null($focus->shipping_address_country) & $focus->shipping_address_country!='')
		$content.=', '.$focus->shipping_address_country;
	$content.='
		</td>
		<td style="width: ' . $w2 . '%">
		
		</td>
		<td style="text-align: right">
		
		</td>
	</tr>';
		$content.='
		<tr>
			<td valign="top" style="width: ' . $w . '%">';
		if (!is_null($focus->parent_nip) && $focus->parent_nip) {
			$content.=$labels['LBL_PDF_CONTENT_NIP'].' '.$focus->parent_nip;
			$nip = true;
		}
		if (!is_null($focus->parent_iln) && $focus->parent_iln) {
			if ($nip) $content.'<br>'; $nip = false;
			$content.='<br>ILN: '.$focus->parent_iln;	
		}	
		$content.='		
			</td>';
		$content.='
			<td valign="top" style="width: ' . $w3 . '%">';
		if (!is_null($focus->shipping_nip) && $focus->shipping_nip) {
			$content.=$labels['LBL_PDF_CONTENT_NIP'].' '.$focus->parent_shipping_nip;
			$nip = true;
		}
		if (!is_null($focus->shipping_iln) && $focus->shipping_iln) {
			if ($nip) $content.'<br>'; $nip = false;
			$content.='ILN: '.$focus->shipping_iln;
		}
		$content.='
			</td>
		<td valign="top" style="width: ' . $w2 . '%"></td>
		<td colspan="0" valign="top" style="text-align: right">
	
		</td>
		</tr>';
$content.='
</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><table width="100%" style="font-size: 7pt;text-align:right;vertical-align:top;">
		<tr><td width="44%" style="text-align: left">'.$labels['LBL_PDF_CONTENT_REGISTER_DATE'].' <b>' . $focus->register_date . ' </b>'.($focus->delivery_date!="" ? '<br>Data dostawy: <b>'.$focus->delivery_date.'</b>': '').''.($focus->ads_text!="" ? '<br>Kod dostawcy: <b>'.$focus->ads_text.'</b>': '');

if ($focus->parent_id == '226a168c-2fef-b92f-0918-6200de91bb31') {
    $content .= '<br>Numer dostawcy: <b>12342</b>';
	$content .= '<br>GLN dostawcy: <b>5909000896239</b><br>';
}

$content .= '</td><td style="text-align: left;" width="20%"><br></td><td rowspan="2" style="text-align: left;vertical-align:top;">';

if($focus->wz_name!=''){
	$content.=$labels['LBL_PDF_CONTENT_PARENT_DOCUMENT_WZ'].':<br>';
}
if($focus->order_no!=''){
	$content.=$labels['LBL_PDF_CONTENT_PARENT_DOCUMENT_NO'].'<br>';
}
if($focus->category!=''){
	$content .=  'Kategoria:<br>';
}
$content.=$labels['LBL_STOCK_NAME'].':<br>';
$content.='</td>
		<td rowspan="2" style="vertical-align:top;">';
if($focus->wz_name!=''){
	$content.='<b>' . $focus->wz_name.'</b><br>';
}
if($focus->order_no!=''){
	$content.='<b>' . $focus->order_no.'</b><br>';
}
if($focus->category!=''){
	$content.='<b>' . $app_list_strings['ecmstockdocouts_category_list'][$focus->category] .'</b><br>';
}
$content.='<b>' . $focus->stock_name.'</b><br>';
$content.='</td></tr></table>';

$content .= '<br>';

// start items table
$columns = array ();
$EcmSysInfo = new EcmSysInfo();
$columns ['position'] = array (
		'field' => array (
				'position' 
		),
		'label' => 'Lp.',
		'align' => 'center' 
);

$columns ['name'] = array (
		'field' => array (
				'name',
				'product_code' 
		),
		'label' => 'Nazwa<br>Indeks',
		'align' => 'left' 
);
if($EcmSysInfo->getDatabaseName()=='preDb_0dcc87940d3655fa574b253df04ca1c3'){
	$columns ['recipient_code'] = array (
			'field' => array (
					'recipient_code',
			),
			'label' => 'Kod odbiorcy',
			'align' => 'left'
	);
}
$columns ['qty'] = array (
		'field' => array (
				'quantity',
				'unit_name' 
		),
		'label' => 'Ilość<br>J.m.',
		'align' => 'right' 
);

if ($focus->parent_id == '226a168c-2fef-b92f-0918-6200de91bb31') {
    $columns ['logistic_1'] = array (
        'field' => array (
            'product_pieces_per_carton',
        ),
        'label' => 'PCB',
        'align' => 'right'
    );
	$columns ['logistic_2'] = array (
        'field' => array (
            'product_cartons'
        ),
        'label' => 'Ilość kartonów',
        'align' => 'right'
    );
}



// set widths
$totals = array ();

$columns ['position'] ['width'] = '5';
$columns ['name'] ['width'] = '55';
if($EcmSysInfo->getDatabaseName()=='preDb_0dcc87940d3655fa574b253df04ca1c3'){

$columns ['recipient_code'] ['width'] = '10';
}
$columns ['qty'] ['width'] = '10';


// 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'] . '%;background-color: #E6E6FA;">' . $col ['label'] . '</th>		
	';
}
$content .= '
	</tr></thead><tbody>
';
$total_qty=0;
foreach ( $positions as $pos ) {
	if ($pos['part_no'] && $pos['part_no']!='.')
		$pos['product_code'].= '<br>'.$pos['part_no'];
	$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>';
	$total_qty+=$pos['quantity'];
}

$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: 7pt; border: 0.5 solid black; border-collapse: collapse; width: 215px; margin-left: 70%">
';

$content .= '
		<tr>
			<td style="border: 0.5 solid black; width: 50%;background-color: #E6E6FA;">
				<b>Razem ilość:</b>
			</td>
			<td style="border: 0.5 solid black; text-align: right;">
				' .$total_qty . '  
			</td>
		</tr>
		';
if ($focus->parent_id == '226a168c-2fef-b92f-0918-6200de91bb31') {
	$total_cartoons = 0;
	foreach ( $positions as $pos ) {
		$total_cartoons += $pos['product_cartons'];
	}
	$content .= '
		<tr>
			<td style="border: 0.5 solid black; width: 50%;background-color: #E6E6FA;">
				<b>Ilość kartonów:</b>
			</td>
			<td style="border: 0.5 solid black; text-align: right;">
				' .$total_cartoons. '  
			</td>
		</tr>
	';
}
$content .= '
	</table>
	<br><p style="font-size: 7pt;">'.$labels['LBL_PDF_CONTENT_ISSUED_BY'].' <b>'.$user->full_name.'</b></p>
	' . $focus->pdf_text . '			
';

//echo $content; die();








