<?php
/**
 * invoice_import_cost class
 *
 */
class invoice_import_cost
{
	var $data;
	
	/**
	 * initiated the invoice_import_cost class
	 *
	 * @param object $invoice_import_cost_object
	 */
	function invoice_import_cost( $invoice_import_cost_object ){
		$this->data = $invoice_import_cost_object;
	}

	/**
	 * return array with table data
	 *
	 * @return array
	 */
	function get_smarty_data_array(){
		$array = (array) $this->data;
		$array['edit_link'] = yes_draw_href_image('images/icons/icon_edit.gif',IMAGE_EDIT,xtc_href_link(FILENAME_INVOICES_IMPORT_COSTS_EDIT,'id='.$array['invoice_import_costs_id']),'invoice_import_costs_edit','' ); 
		$array['delete_link'] = yes_draw_href_image_confirm(TEXT_REMOVE_ENTRY,'images/icons/delete.gif',IMAGE_DELETE,xtc_href_link(FILENAME_INVOICES,'id='.$array['invoices_id'].'&action=overview&subaction=delete_import_cost&iicID='.$array['invoice_import_costs_id']),'func_invoice_import_costs_delete','' ); 
		return $array;
	}

	/**
	 * prueft den wert beim editieren einer import-kostenposition
	 *
	 * @param float $submitted_costs
	 * 
	 * @return boolean
	 */
	function check_update_costs_value($import_costs,$submitted_costs){
		$query_raw = sprintf("SELECT SUM(costs) as saved_costs FROM %s WHERE import_costs_id='%s' and invoice_import_costs_id!='%s'",TABLE_INVOICE_IMPORT_COSTS,$this->data->import_costs_id,$this->data->invoice_import_costs_id);
		$query = xtc_db_query($query_raw);
		$result = xtc_db_fetch_array($query);
		if($submitted_costs >= 0 && $submitted_costs <= ($import_costs-(float)$result['saved_costs']) ){
			return true;
		}else{
			return false;
		}
	}
}
