<?php
function xtc_get_order_html_for_pdf($order,$smarty,$template){
	$smarty->assign('address_label_customer',xtc_address_format($order->customer['format_id'], $order->customer, 1, '', '<br>'));
	$smarty->assign('address_label_shipping',xtc_address_format($order->delivery['format_id'], $order->delivery, 1, '', '<br>'));
	$smarty->assign('address_label_payment',xtc_address_format($order->billing['format_id'], $order->billing, 1, '', '<br>'));
	$smarty->assign('csID',$order->customer['csID']);
	$smarty->assign('cID',$order->customer['ID']);

	$ebay_seller = xtc_get_orders_ebay_seller($order->info['id']);
	if($ebay_seller != ''){
		$smarty->assign('EBAY_SELLER_DATA',xtc_get_ebay_seller_data($ebay_seller));
		$smarty->assign('EBAY_ID',$order->info['ebay_id']);
	}
		
	if( $order->info['orders_status'] == ORDERS_STATUS_STORNIERT) {
		$smarty->assign('IS_STORNO','1');
	}
		
	// get products data
	if( $order->info['is_parent'] == 'n') {
		$order_query=xtc_db_query("SELECT
						products_id,
						orders_products_id,
						products_model,
						products_name,
						allow_tax,
						products_tax,
						final_price,
						products_quantity
						FROM ".TABLE_ORDERS_PRODUCTS."
						WHERE orders_id='".$order->info['id']."'");
	}else{
		$order_query=xtc_db_query("SELECT
						op.products_id,
						op.orders_products_id,
						op.products_model,
						op.products_name,
						op.allow_tax,
						op.products_tax,
						op.final_price,
						op.products_quantity
						FROM ".TABLE_ORDERS_PRODUCTS." op, orders o 
						WHERE o.parent_orders_id='".$order->info['id']."' && op.orders_id=o.orders_id");
	}
	$order_data=array();
	$sum_netto = 0;
	while ($order_data_values = xtc_db_fetch_array($order_query)) {
		$attributes_query=xtc_db_query("SELECT
						products_options,
						products_options_values,
						price_prefix,
						options_values_price
						FROM ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES."
						WHERE orders_products_id='".$order_data_values['orders_products_id']."'");
		$attributes_data='';
		$attributes_model='';
		while ($attributes_data_values = xtc_db_fetch_array($attributes_query)) {
			$attributes_data .='<br>'.$attributes_data_values['products_options'].':'.$attributes_data_values['products_options_values'];	
			$attributes_model .='<br>'.xtc_get_attributes_model($order_data_values['products_id'],$attributes_data_values['products_options_values']);
		}
		
		$tax = xtc_display_tax_value($order_data_values['products_tax']).'%';
		$price_notax = format_price($order_data_values['final_price']/$order_data_values['products_quantity'], 1, $order->info['currency'], $order_data_values['allow_tax'], $order_data_values['products_tax']);
		$item_price  = format_price($order_data_values['final_price']/$order_data_values['products_quantity'], 1, $order->info['currency'], 0, 0);
		
		$order_data[]=array(
			'PRODUCTS_MODEL' => $order_data_values['products_model'],
			'PRODUCTS_NAME' => $order_data_values['products_name'],
			'PRODUCTS_ATTRIBUTES' => $attributes_data,
			'PRODUCTS_ATTRIBUTES_MODEL' => $attributes_model,
			'PRODUCTS_PRICE' => xtc_format_price_order($order_data_values['final_price'],1,$order->info['currency']),
			'PRODUCTS_PRICE_NOTAX' => $price_notax,
			'PRODUCTS_ITEM_PRICE' => $item_price,
			'PRODUCTS_TAX' => $tax,
			'PRODUCTS_QTY' => $order_data_values['products_quantity']);
		
		if($order_data_values['allow_tax'] == '1' and $order_data_values['products_tax'] > 0){
			$sum_netto += format_price($order_data_values['final_price'], 0, $order->info['currency'], $order_data_values['allow_tax'], $order_data_values['products_tax']);
		}
	}
	
	// ZEIGE ZWISCHENSUMME NETTOSUMME WENN INCL STEUER
	if($sum_netto > 0){
		$smarty->assign('NETTOSUM',number_format(xtc_round($sum_netto,PRICE_PRECISION),2,',','').' '.$order->info['currency']);
	}
	
	// get order_total data
	$oder_total_query=xtc_db_query("SELECT
			title,
			text,
			class,
			value,
			sort_order
					FROM ".TABLE_ORDERS_TOTAL."
					WHERE orders_id='".$order->info['id']."'
					ORDER BY sort_order ASC");
	
	$order_total=array();
	
	$notax = 0;
	while ($oder_total_values = xtc_db_fetch_array($oder_total_query)) {
	
		$order_total[]=array(
			'TITLE' => $oder_total_values['title'],
			'CLASS'=> $oder_total_values['class'],
			'VALUE'=> $oder_total_values['value'],
			'TEXT' => $oder_total_values['text']);
		
		if ($oder_total_values['class']='ot_total'){ 
			$total=$oder_total_values['value'];
		}
		if($oder_total_values['class']=='ot_subtotal_no_tax'){
			$notax = 1; // RE OHNE MWST
		}
	}
	$smarty->assign('NOTAX', $notax);
	
	// assign language to template for caching
	$smarty->assign('STORE', nl2br(STORE_NAME_ADDRESS));
	$smarty->assign('STORE_WRAP', STORE_WRAP);
	$smarty->assign('BANK', MODULE_PAYMENT_MONEYORDER_PAYTO);
	
	$smarty->assign('language', $_SESSION['language']);
	$smarty->assign('logo_path',HTTP_SERVER.'templates/'.CURRENT_TEMPLATE.'/img/');
	
	$o_ebayid = '';
	if($order->info['is_parent'] == 'y'){
		$all_ebay_query = xtc_db_query("SELECT ebay_id FROM orders WHERE parent_orders_id='".$order->info['id']."'");
		while($all_ebay = xtc_db_fetch_array($all_ebay_query)){
			$o_ebayid .= $all_ebay['ebay_id'].', ';
		}
		$o_ebayid = substr($o_ebayid,0,(strlen($o_ebayid)-2));
	}else{
		$o_ebayid .= $order->info['ebay_id'];
	}
	$smarty->assign('oID',$order->info['id']);
	
	if ($order->info['payment_method']!='' && $order->info['payment_method']!='no_payment') {
		if(is_file(DIR_FS_CATALOG.'lang/'.$_SESSION['language'].'/modules/payment/'.$order->info['payment_method'].'.php')){
			include(DIR_FS_CATALOG.'lang/'.$_SESSION['language'].'/modules/payment/'.$order->info['payment_method'].'.php');
			$payment_method=constant(strtoupper('MODULE_PAYMENT_'.$order->info['payment_method'].'_TEXT_TITLE'));
		}else{
			$payment_method=$order->info['payment_method'];
		}
		$smarty->assign('PAYMENT_METHOD',$payment_method);
	}
	$smarty->assign('DATE',xtc_date_long($order->info['date_purchased']));
	if($order->info['date_shipping'] > 0)
		$smarty->assign('DATE_SHIPPING',xtc_date_long($order->info['date_shipping']));
	if($order->info['date_payment'] > 0)
		$smarty->assign('DATE_PAYMENT',xtc_date_long($order->info['date_payment']));
	$smarty->assign('order_data', $order_data);
	$smarty->assign('order_total', $order_total);
	$pdf_html=$smarty->fetch($template);
	return $pdf_html;
}
?>
