/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.delegate.contract;
import beans.contract.entity.ServicePriceDetails;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.filtered.DirectoryService;
import clips.delegate.directory.filtered.DirectoryServiceItem;
import cli_fmw.main.ClipsException;
import cli_fmw.delegate.lists.DataChunk;
import cli_fmw.delegate.lists.Mappable;
import clips.delegate.directory.simple.receptionType.DirectoryReceptionType;
import clips.delegate.directory.simple.receptionType.DirectoryReceptionTypeItem;
import framework.utils.Pair;
/**
*
* @author axe
*/
public class ServisePriceData extends DataChunk<ServicePriceDetails>
implements Mappable<Pair<DirectoryServiceItem, DirectoryReceptionTypeItem>> {
/**комбинированный ключ ID услуги, ID типа приема*/
private Pair<DirectoryServiceItem, DirectoryReceptionTypeItem> key = new Pair<DirectoryServiceItem, DirectoryReceptionTypeItem>();
public ServisePriceData(Pair<DirectoryServiceItem, DirectoryReceptionTypeItem> pair) throws ClipsException {
super(new ServicePriceDetails());
getDetails().serviceID = pair.first.getID();
getDetails().receptionTypeID = pair.second.getID();
getDetails().money = -1;
getDetails().price = -1;
}
public ServisePriceData(ServicePriceDetails details) throws ClipsException {
super(details);
}
public DirectoryServiceItem getService() throws ClipsException {
DirectoryService services = DirectoryLocator.getDirectory(DirectoryService.class);
return services.getItemFromID(getDetails().serviceID);
}
@Deprecated
public void setService(DirectoryServiceItem service) throws ClipsException {
getDetails().serviceID = service.getID();
fireContentStateEvent();
}
public DirectoryReceptionTypeItem getReceptionType() throws ClipsException {
DirectoryReceptionType dirRecType = DirectoryLocator.getDirectory(DirectoryReceptionType.class);
return dirRecType.getItemFromID(getDetails().receptionTypeID);
}
//сумма денег оплачиваемая за услугу страховой команией
public int getMoney() throws ClipsException {
return getDetails().money;
}
//сумма денег оплачиваемая за услугу страховой команией
public void setMoney(int money) throws ClipsException {
getDetails().money = money;
fireContentStateEvent();
}
//договорная стоимость услуги
public int getPrice() throws ClipsException {
return getDetails().price;
}
//договорная стоимость услуги
public void setPrice(int price) throws ClipsException {
getDetails().price = price;
fireContentStateEvent();
}
/**
* стоимость услуги, не оплачиваемая по договору (без учета скидки)
* @return
* @throws ClipsException
*/
public int getLack() throws ClipsException {
int lack = getPrice() - getMoney();
if(lack >=0) {
return lack;
}
return 0;
}
@Override
public Pair<DirectoryServiceItem, DirectoryReceptionTypeItem> getKey() {
try {
key.first = getService();
key.second = getReceptionType();
return key;
} catch (ClipsException ex) {
ex.printStackTrace();
return null;
}
}
}