// Path: src/java/is/idega/idegaweb/egov/accounting/business/AccountingConstants.java
// public class AccountingConstants {
// 
// 	public static final String IW_BUNDLE_IDENTIFIER = "is.idega.idegaweb.egov.accounting";
// 
// 	public static final String ACCOUNTING_SYSTEM_NAVISION = "NAVISION";
// 	public static final String ACCOUNTING_SYSTEM_NAVISION_XML = "NAVISIONXML";
// 	public static final String ACCOUNTING_SYSTEM_SFS = "SFS";
// 
// 	public static final String PROPERTY_ACCOUNTING_SYSTEM = "egov.external.accounting.system";
// 	public static final String PROPERTY_ACCOUNTING_FETCHER_SHOW_INPUTS = "egov.accounting.show.all.inputs";
// 	public static final String PROPERTY_ACCOUNTING_SHOW_AGRESSO_VIEW = "egov.accounting.show.agresso.view";
// 	
// 	public static final String SESSION_PRODUCT_MAP = "accounting_product_map";
// 	public static final String SESSION_PAYMENT_METHOD_MAP = "accounting_payment_method_map";
// 
// }
// 
// Path: src/java/is/idega/idegaweb/egov/accounting/data/AccountingFiles.java
// public interface AccountingFiles extends IDOEntity {
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#getCaseCode
// 	 */
// 	public CaseCode getCaseCode();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#getFile
// 	 */
// 	public ICFile getFile();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#getCreatedDate
// 	 */
// 	public Timestamp getCreatedDate();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#getMonth
// 	 */
// 	public Date getMonth();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#setCaseCode
// 	 */
// 	public void setCaseCode(CaseCode code);
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#setFile
// 	 */
// 	public void setFile(ICFile file);
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#setCreatedDate
// 	 */
// 	public void setCreatedDate(Timestamp createdDate);
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#setMonth
// 	 */
// 	public void setMonth(Date month);
// }


import is.idega.idegaweb.egov.accounting.business.AccountingConstants;
import is.idega.idegaweb.egov.accounting.data.AccountingFiles;
import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Iterator;
import com.idega.business.IBORuntimeException;
import com.idega.core.file.data.ICFile;
import com.idega.presentation.IWContext;
import com.idega.presentation.Layer;
import com.idega.presentation.Table2;
import com.idega.presentation.TableCell2;
import com.idega.presentation.TableRow;
import com.idega.presentation.TableRowGroup;
import com.idega.presentation.text.Link;
import com.idega.presentation.text.Text;
import com.idega.presentation.ui.DateInput;
import com.idega.presentation.ui.Form;
import com.idega.presentation.ui.Label;
import com.idega.presentation.ui.SubmitButton;
import com.idega.util.IWTimestamp;
import com.idega.util.PresentationUtil;
/*
 * $Id$ Created on 7.8.2006
 * 
 * Copyright (C) 2006 Idega Software hf. All Rights Reserved.
 * 
 * This software is the proprietary information of Idega hf. Use is subject to
 * license terms.
 */
package is.idega.idegaweb.egov.accounting.presentation;




public class AccountingEntryFetcher extends AccountingBlock {

	private final static String PARAMETER_DATE_FROM = "prm_date_from";
	private final static String PARAMETER_DATE_TO = "prm_date_to";
	private static final String PARAMETER_ACCOUNTING_FILE_PK = "prm_accounting_file_pk";

	private String caseCode = null;

	private void parse(IWContext iwc) throws RemoteException {
		if (iwc.isParameterSet(PARAMETER_DATE_FROM)) {
			
			IWTimestamp month = new IWTimestamp(iwc.getParameter(PARAMETER_DATE_FROM));
			if (iwc.isParameterSet(PARAMETER_DATE_TO)) {
				IWTimestamp to = new IWTimestamp(iwc.getParameter(PARAMETER_DATE_TO));
				
				getAccountingKeyBusiness(iwc).createAccountingFile(this.caseCode, month.getDate(), to.getDate());
			}
			else {
				getAccountingKeyBusiness(iwc).createAccountingFile(this.caseCode, month.getDate());
			}
		}
		
		if (iwc.isParameterSet(PARAMETER_ACCOUNTING_FILE_PK)) {
			getAccountingKeyBusiness(iwc).removeAccountingFile(iwc.getParameter(PARAMETER_ACCOUNTING_FILE_PK));
		}
	}

	protected void present(IWContext iwc) {
		try {
			parse(iwc);
			PresentationUtil.addStyleSheetToHeader(iwc, iwc.getIWMainApplication().getBundle("is.idega.idegaweb.egov.application").getVirtualPathWithFileNameString("style/application.css"));
	
			if (this.caseCode == null) {
				add(new Text("Please set the case code"));
				return;
			}
			
// Path: src/java/is/idega/idegaweb/egov/accounting/business/AccountingConstants.java
// public class AccountingConstants {
// 
// 	public static final String IW_BUNDLE_IDENTIFIER = "is.idega.idegaweb.egov.accounting";
// 
// 	public static final String ACCOUNTING_SYSTEM_NAVISION = "NAVISION";
// 	public static final String ACCOUNTING_SYSTEM_NAVISION_XML = "NAVISIONXML";
// 	public static final String ACCOUNTING_SYSTEM_SFS = "SFS";
// 
// 	public static final String PROPERTY_ACCOUNTING_SYSTEM = "egov.external.accounting.system";
// 	public static final String PROPERTY_ACCOUNTING_FETCHER_SHOW_INPUTS = "egov.accounting.show.all.inputs";
// 	public static final String PROPERTY_ACCOUNTING_SHOW_AGRESSO_VIEW = "egov.accounting.show.agresso.view";
// 	
// 	public static final String SESSION_PRODUCT_MAP = "accounting_product_map";
// 	public static final String SESSION_PAYMENT_METHOD_MAP = "accounting_payment_method_map";
// 
// }
// 
// Path: src/java/is/idega/idegaweb/egov/accounting/data/AccountingFiles.java
// public interface AccountingFiles extends IDOEntity {
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#getCaseCode
// 	 */
// 	public CaseCode getCaseCode();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#getFile
// 	 */
// 	public ICFile getFile();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#getCreatedDate
// 	 */
// 	public Timestamp getCreatedDate();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#getMonth
// 	 */
// 	public Date getMonth();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#setCaseCode
// 	 */
// 	public void setCaseCode(CaseCode code);
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#setFile
// 	 */
// 	public void setFile(ICFile file);
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#setCreatedDate
// 	 */
// 	public void setCreatedDate(Timestamp createdDate);
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.accounting.data.AccountingFilesBMPBean#setMonth
// 	 */
// 	public void setMonth(Date month);
// }


// Path: src/java/is/idega/idegaweb/egov/accounting/presentation/AccountingEntryFetcher.java
import is.idega.idegaweb.egov.accounting.business.AccountingConstants;
import is.idega.idegaweb.egov.accounting.data.AccountingFiles;
import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Iterator;
import com.idega.business.IBORuntimeException;
import com.idega.core.file.data.ICFile;
import com.idega.presentation.IWContext;
import com.idega.presentation.Layer;
import com.idega.presentation.Table2;
import com.idega.presentation.TableCell2;
import com.idega.presentation.TableRow;
import com.idega.presentation.TableRowGroup;
import com.idega.presentation.text.Link;
import com.idega.presentation.text.Text;
import com.idega.presentation.ui.DateInput;
import com.idega.presentation.ui.Form;
import com.idega.presentation.ui.Label;
import com.idega.presentation.ui.SubmitButton;
import com.idega.util.IWTimestamp;
import com.idega.util.PresentationUtil;

/*
 * $Id$ Created on 7.8.2006
 * 
 * Copyright (C) 2006 Idega Software hf. All Rights Reserved.
 * 
 * This software is the proprietary information of Idega hf. Use is subject to
 * license terms.
 */
package is.idega.idegaweb.egov.accounting.presentation;




public class AccountingEntryFetcher extends AccountingBlock {

	private final static String PARAMETER_DATE_FROM = "prm_date_from";
	private final static String PARAMETER_DATE_TO = "prm_date_to";
	private static final String PARAMETER_ACCOUNTING_FILE_PK = "prm_accounting_file_pk";

	private String caseCode = null;

	private void parse(IWContext iwc) throws RemoteException {
		if (iwc.isParameterSet(PARAMETER_DATE_FROM)) {
			
			IWTimestamp month = new IWTimestamp(iwc.getParameter(PARAMETER_DATE_FROM));
			if (iwc.isParameterSet(PARAMETER_DATE_TO)) {
				IWTimestamp to = new IWTimestamp(iwc.getParameter(PARAMETER_DATE_TO));
				
				getAccountingKeyBusiness(iwc).createAccountingFile(this.caseCode, month.getDate(), to.getDate());
			}
			else {
				getAccountingKeyBusiness(iwc).createAccountingFile(this.caseCode, month.getDate());
			}
		}
		
		if (iwc.isParameterSet(PARAMETER_ACCOUNTING_FILE_PK)) {
			getAccountingKeyBusiness(iwc).removeAccountingFile(iwc.getParameter(PARAMETER_ACCOUNTING_FILE_PK));
		}
	}

	protected void present(IWContext iwc) {
		try {
			parse(iwc);
			PresentationUtil.addStyleSheetToHeader(iwc, iwc.getIWMainApplication().getBundle("is.idega.idegaweb.egov.application").getVirtualPathWithFileNameString("style/application.css"));
	
			if (this.caseCode == null) {
				add(new Text("Please set the case code"));
				return;
			}
			
			boolean showFullInputs = iwc.getApplicationSettings().getBoolean(AccountingConstants.PROPERTY_ACCOUNTING_FETCHER_SHOW_INPUTS, false);