Package clips.delegate.service.discount

Source Code of clips.delegate.service.discount.DiscountCardLocal

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package clips.delegate.service.discount;

import beans.discount.card.DiscountCardBean;
import beans.discount.entity.DiscountCardDetails;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import beans.discount.card.DiscountCardBeanRemote;
import cli_fmw.delegate.AuditListener;
import clips.delegate.client.ClientLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.utils.TimeLocal;
import cli_fmw.main.DirectoryItemReplacedException;
import clips.delegate.DEC.DECClient;
import clips.delegate.directory.ro.DirectoryCollaborator;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import clips.delegate.directory.simple.discountCard.DirectoryDiscountCardType;
import clips.delegate.directory.simple.discountCard.DirectoryDiscountCardTypeItem;
import clips.login.UserInfo;
import framework.utils.DateTimeUtils;
import java.util.Date;

/**
* Дисконтная карта.
* Используется только для чтения. Все модификации карты осуществляются на уровне СП
* уже нет. Введена возможность редактировать вручную (приналичии прав)
* @author Axe
*/
public class DiscountCardLocal extends
    DelegateLine2<DiscountCardBeanRemote, DiscountCardDetails> {
   
    private DECClient client = new DECClient(this, "иформацию о владельце", getAuditListener());

    public DiscountCardLocal(ClientLocal c) throws ClipsException {
        super(c.getAuditListener());
        client.initBy(c);
        getDetails().collaboratorID = UserInfo.get().getCollaborator().getID();
        getDetails().created = DateTimeUtils.getDateOnly(TimeLocal.getCurrentTime().getTime());

    }
   
    /**
     * Создает новый объект - дисконтную карту на основе ее ID
   * @param id ID дисконтной карты
   * @throws ClipsException
     */
    public DiscountCardLocal(int id, AuditListener al) throws ClipsException {
        super(id, al);
    }
   
    public DiscountCardLocal(DiscountCardDetails details, AuditListener al) throws ClipsException {
        super(details, al);
    }

    @Override
    protected DiscountCardDetails getNewDetails() {
        return new DiscountCardDetails();
    }
       
   
    /**
     * перенесено на серверную часть см класс ServiceContractPriceData
     * Возвращает дисконт для данной услуге по данной дисконтной карте
     * @param service услуга
     * @return процент
     * @throws cli_fmw.delegate.exception.ClipsException
     */
    /*@Deprecated
    public int getDiscountValue(DirectoryServiceItem service) throws ClipsException {
        DiscountLocal discounts = new DiscountLocal();
        Discounts cardDiscounts = discounts.getDiscounts(getCardType());
       
        DirectoryDiscountLevel levels = (DirectoryDiscountLevel)
                DirectoryLocator.getDirectory(DirectoryDiscountLevel.class, true);
        int money = getMoney();
        Selector ii = levels.getItems();
        DirectoryDiscountLevelItem thisLevel = null;
        for(int i=0; i<ii.size(); i++) {
            DirectoryDiscountLevelItem lvl = (DirectoryDiscountLevelItem) ii.get(i);
            if(lvl.getLevel() > money) {
                break;
            }
            thisLevel = lvl;
        }
       
        if(thisLevel == null) {
            return 0;
        }
        return cardDiscounts.getValue(thisLevel, service.getServiceClass());
    }*/
   
    /**
     * Возвращает код карты
     * @return
     * @throws ClipsException
     */
    public String getCode() throws ClipsException {
        return getDetails().code;
    }
   
    public void setCode(String code) throws ClipsException {
        getDetails().code = code;
        fireContentStateEvent();
    }

    /**
     * Возвращает сотрудника, выдавшего карту
     * @return
     * @throws ClipsException
     */
    public DirectoryCollaboratorItem getCollaborator() throws ClipsException {
        DirectoryCollaborator collabs = (DirectoryCollaborator)
                DirectoryLocator.getDirectory(DirectoryCollaborator.class, false);
        return collabs.getItemFromID(getDetails().collaboratorID);
    }
   
    /**
     * Возвращает сотрудника, заблокировавшего карту или НУЛЛ, если карта не заблокирована
     * @return
     * @throws ClipsException
     */
    public DirectoryCollaboratorItem getBlocker() throws ClipsException {
        if (getDetails().collaboratorBlockerID == 0) {
            return null;
        }
        DirectoryCollaborator collabs = (DirectoryCollaborator)
                DirectoryLocator.getDirectory(DirectoryCollaborator.class, false);
        return collabs.getItemFromID(getDetails().collaboratorBlockerID);
    }

    /**
     * Возвращает срок выдачи карты JOKE
     * @return
     * @throws ClipsException
     */
    public Date getCreatedDate() throws ClipsException {
        return getDetails().created;
    }

    /**
     * Возвращает срок блокирования карты //шутко
     * @return
     */
    public Date getExpiredDate() throws ClipsException {
        return getDetails().expired;
    }
   
    /**
     *
     * @return
     * @throws cli_fmw.delegate.exception.ClipsException
     */
    public boolean isExpired() throws ClipsException {
        Date expired = getExpiredDate();
        if (expired == null) {
            return false;
        }
        return TimeLocal.getCurrentTime().getTime().after(expired);
    }

    /**
     * Возвращает, когда в последний раз была использована карта
     * @return
     */
    public Date getLastUsed() throws ClipsException {
        return getDetails().lastUsed;
   
   
    /**
     * Возвращает количество денег на карте
     * @return
     */
    public int getMoney() throws ClipsException {
       return getDetails().money;
    }

   
    public ClientLocal getClient() throws ClipsException{
        return new ClientLocal(getDetails().clientID, getAuditListener());
    }
   
    @Deprecated
    public String getReasonExtraDescription() throws ClipsException {
        return null;
    }
   
    public DirectoryDiscountCardTypeItem getCardType() throws ClipsException {
        DirectoryDiscountCardType directory = DirectoryLocator.getDirectory(DirectoryDiscountCardType.class);
        try {
            return directory.getItemFromID(getDetails().typeID);
        } catch (DirectoryItemReplacedException ex) {
            reload();
            return directory.getItemFromID(getDetails().typeID);
        }
    }


    public void setCollaborator(DirectoryCollaboratorItem collaborator) throws ClipsException {
        getDetails().collaboratorID = collaborator.getID();
        fireContentStateEvent();
    }
   
    /**
     * Можно выставить нулл
     * @param blocker
     * @throws cli_fmw.main.ClipsException
     */
    public void setBlocker(DirectoryCollaboratorItem blocker) throws ClipsException {
        if (blocker == null){
            getDetails().collaboratorBlockerID = 0;
        }else{
            getDetails().collaboratorBlockerID = blocker.getID();
        }
        fireContentStateEvent();
    }

    public void setCreatedDate(Date date) throws ClipsException {
        getDetails().created = date;
        fireContentStateEvent();
    }

    public void setExpiredDate(Date date) throws ClipsException {
        getDetails().expired = date;
        fireContentStateEvent();
    }
   
    public void setLastUsed(Date date) throws ClipsException {
        getDetails().lastUsed = date;
        fireContentStateEvent();
   
   
    public void setMoney(int money) throws ClipsException {
       getDetails().money = money;
        fireContentStateEvent();
    }

    public void setClient(ClientLocal client) throws ClipsException{
        getDetails().clientID = client.getID();
        fireContentStateEvent();
    }
   
    @Deprecated
    public void setReasonExtraDescription(String description) throws ClipsException {
    }
   
    public void setCardType(DirectoryDiscountCardTypeItem type) throws ClipsException {
        getDetails().typeID = type.getID();
        fireContentStateEvent();
    }
   
   
    @Override
    protected String getBeanName() {
        return DiscountCardBean.class.getSimpleName();
    }

    @Override
    public String toString() {
        try {
            return getClient() == null? "№"+this.getCode() :
                this.getClient().getFIO()+" ["+ getCardType().getTitle()+"]";
        } catch (ClipsException ex) {
            ex.printStackTrace();
            return "Не удлалось загрузить данные о дисонтной катре";
        }
    }
   
   
}
TOP

Related Classes of clips.delegate.service.discount.DiscountCardLocal

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.