/*
 * This class is autogenerated if it does not exists. It may be modified.
 * Copyright: (c) Reinders Posters
 * Modified:  $Date: 2007/08/01 15:01:03 $
 */

package nl.reinders.bm;

import java.math.BigDecimal;
import java.math.RoundingMode;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 * A JPA entity class for license_payment.
 * @version    $Revision: 1.5 $
 * @author     $Author: toeukpap $
 */
@Entity
@Table(name="license_payment")
public class LicensePayment extends nl.reinders.bm.generated.LicensePayment
implements java.io.Serializable
{
	static final long serialVersionUID = 0;
	static final String SOURCECODE_VERSION = "$Revision: 1.5 $";
	static org.apache.log4j.Logger log4j = org.apache.log4j.Logger.getLogger(LicensePayment.class.getName());
	
	// ==============================================================================================
	// CONSTRUCTOR
	
	/**
	 * @param license
	 */
	public LicensePayment()
	{
		super();
	}

	/**
	 * @param license
	 */
	public LicensePayment(License license)
	{
		super();
		setLicense(license);
	}
	
	/**
	 * Use currency's to_euro as default for the to_foreign 
	 */
	public void setLicense(nl.reinders.bm.License value)
	{
		super.setLicense(value);
		
		// if to foreign is not set, but the currency's to euro is set
		if (getToForeign() == null && value != null && value.getCurrency() != null && value.getCurrency().getToEuro() != null)
		{
			// use that to init to foreign
			setToForeign( BigDecimal.ONE.divide( value.getCurrency().getToEuro(), value.getCurrency().getToEuro().scale(), RoundingMode.HALF_UP ));
		}
	}
}
