<?php
$smarty = new yesSmarty();
$smarty->assign('BUTTON_CLOSE',BUTTON_CLOSE);
$imports = new imports;
$invoice = $invoices->get_invoice($_GET['iID']);
$import = $imports->get_import($_GET['impID']);
$smarty->assign('import_number',$import->data->import_number);
$smarty->assign('invoice_number',$invoice->data->invoice_number);
$smarty->assign('currency',$invoice->data->currency);
$smarty->assign('form',xtc_draw_form('invoice_ship_costs', FILENAME_INVOICES_EDIT,'action=add_import_ship_costs_save&id='.$_GET['iID'],'post','onsubmit="return check_add_ship_costs_form();"'));
if(is_array($import->data->ships) and sizeOf($import->data->ships)>0){
	$costs_array = array();
	$open_costs = 0;
	foreach($import->data->ships as $k=>$ship){
		if($ship['import_ships_id'] == $invoice->data->import_ships_id){
			$ship_name = yes_get_ships_name($ship['orderer_ships_id']);
			for($i=0;$i<sizeOf($ship['costs']);$i++){
				$cost = $ship['costs'][$i];
				$saved = $invoices->check_import_ship_costs_id_saved(xtc_db_input($_GET['iID']),$cost['import_ship_costs_id']);
				$costs_array[] = array(
					'import_ship_costs_id'=>$cost['import_ship_costs_id'],
					'import_ships_id'=>$cost['import_ships_id'],
					'import_ships_id'=>$cost['import_ships_id'],
					'ship'=>$ship_name,
					'costs'=>$cost['costs'],
					'costs_expensed'=>$cost['costs_expensed'],
					'costs_text'=>$cost['costs_text'],
					'saved'=>$saved
				);
				if(!$saved)
					$open_costs++;
			}
		}
	}
	$smarty->assign('costs',$costs_array);
	$smarty->assign('open_costs',$open_costs);
}
echo $smarty->fetch(DIR_FS_ADMIN.'templates/invoices_choose_import_ship_costs.html');

include('includes/footer.php');
