/*
* MpBizDocStates.java
*
* Created on 10 de Outubro de 2006, 17:45
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.m16e.mpbiz.common.bizclasses;
import com.m16e.mpbiz.tables.DbTabEstado;
import com.m16e.tools.Tuple;
import java.util.ArrayList;
import org.apache.log4j.Logger;
////////////////////////////////////////////////////////////
/**
*
* @author carlos
*/
public class MpBizDocStates
{
static Logger logger = Logger.getLogger( MpBizDocStates.class );
public static enum DocStateType
{
AUTHORIZATION( 0, "auhorization" ),
AVAILABILITY( 1, "availability" ),
TRACKING( 2, "tracking" ),
DELIVERY( 3, "delivery" ),
PRINTING( 4, "printing" ),
SYNC_B2B( 5, "sync-b2b" );
private final int code;
private final String typeName;
DocStateType( int code, String name )
{
this.code = code;
this.typeName = name;
}
public int getCode() { return code; }
public String getName() { return typeName; }
}
public static enum DocStateSyncB2B
{
OUT_OF_SYNC( 0, "out-of-sync" ),
SYNCED( 1, "synced" );
private final int code;
private final String typeName;
DocStateSyncB2B( int code, String name )
{
this.code = code;
this.typeName = name;
}
public int getCode() { return code; }
public String getName() { return typeName; }
}
public static enum DocStatePrinting
{
PENDING( 0, "pending"),
PRINTED( 1, "printed" ),
REPRINTED( 2, "reprinted" );
private final int code;
private final String typeName;
DocStatePrinting( int code, String name )
{
this.code = code;
this.typeName = name;
}
public int getCode() { return code; }
public String getName() { return typeName; }
}
public static enum DocStateAuthorization
{
PENDING( 0, "pending" ),
AUTHORIZED( 1, "authorized" ),
REFUSED( 2, "refused" );
private final int code;
private final String typeName;
DocStateAuthorization( int code, String name )
{
this.code = code;
this.typeName = name;
}
public int getCode() { return code; }
public String getName() { return typeName; }
}
public static enum DocStateAvailability
{
PENDING_INFO( 0, "pending-info" ),
PARCIALLY_AVAILABLE( 1, "partially-available" ),
PENDING( 2, "pending" ),
DISCONTINUED( 996, "discontinued" ),
NOT_IN_STOCK( 997, "not-in-stock" ),
OUT_OF_STOCK( 998, "out-of-stock" ),
AVAILABLE( 999, "available" );
private final int code;
private final String typeName;
DocStateAvailability( int code, String name )
{
this.code = code;
this.typeName = name;
}
public int getCode() { return code; }
public String getName() { return typeName; }
}
public static enum DocStateTracking
{
PENDING_PROCESSING( 0, "pending-delivery"),
PENDING_EVOLUTION( 1, "pending-evolution" ),
PENDING_EVOLUTION_PART( 2, "pending-evolution-part" ),
MERCHANDIZE_RECEIVED( 3, "merchandise-received" ),
APPROVED( 4, "approved" ),
FULL_FILLED( 990, "full-filled" ),
PARTIALLY_SHIPPED( 991, "partially-shipped" ),
SHIPPED( 992, "shipped" ),
INVOICE_SENT( 993, "invoice-sent" ),
REFUSED( 995, "refused" ),
CLOSED( 999, "closed" );
private final int code;
private final String typeName;
DocStateTracking( int code, String name )
{
this.code = code;
this.typeName = name;
}
public int getCode() { return code; }
public String getName() { return typeName; }
static public DocStateTracking getByCode( int code )
{
for( DocStateTracking dst : values() )
{
if( dst.getCode() == code )
return dst;
}
return null;
}
}
public static enum DocStateDelivery
{
PENDING_DELIVERY( 0, "pending-delivery" ),
DELIVERING( 1, "delivering" ), // guias
PARCIALLY_DELIVERED( 2, "parcially-delivered" ),
DELIVERED( 999, "delivered" );
private final int code;
private final String typeName;
DocStateDelivery( int code, String name )
{
this.code = code;
this.typeName = name;
}
public int getCode() { return code; }
public String getName() { return typeName; }
}
java.util.List<DbTabEstado> docStates = null;
private static MpBizDocStates onlyInstance = new MpBizDocStates();
////////////////////////////////////////////////////////////
/** Creates a new instance of MpBizDocStates */
public MpBizDocStates()
{
refresh();
}
////////////////////////////////////////////////////////////
public static MpBizDocStates getInstance() { return onlyInstance; }
// ////////////////////////////////////////////////////////////
// public boolean isValid(
// int tipoEntId, int tipoDocId, DocStateType type, int estadoId )
// {
// return isValid( tipoEntId, tipoDocId, type.getCode(), estadoId );
// }
//
////////////////////////////////////////////////////////////
public boolean isValid(
int tipoEntId, int tipoDocId, int type, int estadoId )
{
for( DbTabEstado bean : docStates )
{
if( bean.getTipoEntId() == tipoEntId &&
bean.getTipoDocId() == tipoDocId &&
bean.getTipoEstadoId() == type &&
bean.getEstadoId() == estadoId )
{
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////
public void refresh()
{
docStates = new ArrayList<DbTabEstado>();
try
{
MpBizDocStateTypes.getInstance().refreshData();
DbTabEstado dbTabEstado = new DbTabEstado();
java.util.List<Tuple> lstDocStates =
dbTabEstado.select( "", dbTabEstado.getPKeyOrder() );
for( Tuple t : lstDocStates )
{
DbTabEstado bean = new DbTabEstado();
bean.setTuple( t );
docStates.add( bean );
}
}
catch( Exception e )
{
logger.error( e.getMessage(), e );
throw new IllegalArgumentException( e.getLocalizedMessage() );
}
}
////////////////////////////////////////////////////////////
public java.util.List<DbTabEstado> getDocStates( int tipoEntId, int tipoDocId )
{
java.util.List<DbTabEstado> lstStates = new ArrayList<DbTabEstado>();
for( DbTabEstado bean : docStates )
{
if( bean.getTipoEntId() == tipoEntId &&
bean.getTipoDocId() == tipoDocId )
{
lstStates.add( bean );
}
}
return lstStates;
}
////////////////////////////////////////////////////////////
public java.util.List<DbTabEstado> getDocStates(
int tipoEntId, int tipoDocId, int tipoEstadoId )
{
java.util.List<DbTabEstado> lstStates = new ArrayList<DbTabEstado>();
for( DbTabEstado bean : docStates )
{
if( bean.getTipoEntId() == tipoEntId &&
bean.getTipoDocId() == tipoDocId &&
bean.getTipoEstadoId() == tipoEstadoId )
{
lstStates.add( bean );
}
}
return lstStates;
}
////////////////////////////////////////////////////////////
public DbTabEstado getDocState(
int tipoEntId, int tipoDocId, int type, int estadoId )
{
DbTabEstado ds = null;
for( DbTabEstado bean : docStates )
{
if( bean.getTipoEntId() == tipoEntId &&
bean.getTipoDocId() == tipoDocId &&
bean.getTipoEstadoId() == type &&
bean.getEstadoId() == estadoId )
{
return bean;
}
}
return null;
}
}
|