package sn.unitech.stock.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import sn.unitech.common.dao.ReadProperties;
import sn.unitech.stock.entity.SysActivite;
import sn.unitech.stock.entity.SysGroupProd;
import sn.unitech.stock.entity.SysSousUnite;
import sn.unitech.stock.entity.SysSousUniteId;
import sn.unitech.stock.entity.SysTypUnite;
import sn.unitech.stock.entity.SysUnite;
import sn.unitech.stock.metier.SysUniteM;
import sn.unitech.stock.metier.iface.ISysUniteM;
import sn.unitech.stock.modal.Resultat;
@ManagedBean
@ViewScoped
public class SysUniteBean implements Serializable{
private ReadProperties readProperties=ReadProperties.getReadProperties();
ISysUniteM<SysUnite> sysUniteM=new SysUniteM();
private SysUnite sysUnite=new SysUnite();
private AllRefs allRefs=new AllRefs() ;
private CMessages cmessages =new CMessages();
private CItems citems=new CItems();
private Cproperties cproperties = citems;
public SysUniteBean(){
}
ParamsUser getParamsUser(){ //alias
return ((ParamsUser)ToolsBean.getToolsBean().getAttribute(ToolsBean.idParamUser));
}
public void saveUnite(ActionEvent a){
this.sysUnite.setIdUnite(this.sysUniteM.getCleUnite(this.cproperties.idContenants,this.cproperties.idContenu,this.cproperties.idSousUnite));
this.sysUnite.setLibelle(this.sysUnite.getIdUnite().replace("_", " "));
SysSousUnite sysSousUnite = new SysSousUnite();
sysSousUnite.setId(new SysSousUniteId(this.cproperties.idSousUnite,this.sysUnite.getIdUnite()));
sysSousUnite.setRapport(this.cproperties.idContenu);
sysSousUnite.setOrdre(1);
Resultat resultat;
resultat=this.sysUniteM.saveUnite(sysUnite,sysSousUnite,this.cproperties.idActivite);
if(resultat.isSucceed()){
this.setSysUnite(new SysUnite());
this.cproperties.setIdContenu(1);
this.cmessages.setSaveMessage(resultat.getMessage());
}else this.cmessages.setSaveMessage(resultat.getMessage());
}
public class AllRefs implements Serializable{
}
public class CMessages implements Serializable{
public String saveMessage;
public String getSaveMessage() {
return saveMessage;
}
public void setSaveMessage(String saveMessage) {
this.saveMessage = saveMessage;
}
}
public class Cproperties implements Serializable{
public Integer idContenu;
public String idContenants;
public String idSousUnite;
String idActivite;
boolean showActivite;
public Integer getIdContenu() {
return idContenu;
}
public void setIdContenu(Integer idContenu) {
this.idContenu = idContenu;
}
public String getIdContenants() {
return idContenants;
}
public void setIdContenants(String idContenants) {
this.idContenants = idContenants;
}
public String getIdSousUnite() {
return idSousUnite;
}
public void setIdSousUnite(String idSousUnite) {
this.idSousUnite = idSousUnite;
}
public String getIdActivite() {
return idActivite;
}
public void setIdActivite(String idActivite) {
this.idActivite = idActivite;
}
public boolean isShowActivite() {
return showActivite;
}
public void setShowActivite(boolean showActivite) {
this.showActivite = showActivite;
}
}
public class CItems extends Cproperties implements Serializable{
Map<String,String> itemsContenants;
Map<String,String> itemsUnitesInternational;
DataModel<SysUnite> dataListUnite=new ListDataModel<SysUnite>(new ArrayList<SysUnite>());
Map<String,String> itemsAllActivite;
public CItems(){
Map map=ToolsBean.getToolsBean().defaultParametter();
map.put(1,"True");
this.itemsUnitesInternational=sysUniteM.findAllUnite(readProperties.read("Unite.jpqlUnitInter"),map);
itemsAllActivite=sysUniteM.findAllActivite(readProperties.read("Unite.jpqlActivite"),ToolsBean.getToolsBean().defaultParametter());
this.showActivite=itemsAllActivite.size()>1;
this.setIdActivite(itemsAllActivite.values().iterator().next());
}
public Map<String,String> getItemsContenants() {
this.itemsContenants= sysUniteM.findAllContenants(readProperties.read("Unite.jpqlContenant"));
return this.itemsContenants;
}
public void setItemsContenants(Map<String,String> itemsContenants) {
this.itemsContenants = itemsContenants;
}
public Map<String, String> getItemsUnitesInternational() {
return itemsUnitesInternational;
}
public void setItemsUnitesInternational(
Map<String, String> itemsUnitesInternational) {
this.itemsUnitesInternational = itemsUnitesInternational;
}
public DataModel<SysUnite> getDataListUnite() {
Map param=new HashMap<Integer,String>();
param.put(0,getParamsUser().adherent.getIdAdherent());
this.dataListUnite.setWrappedData((List<SysUnite>) sysUniteM.listUnite(readProperties.read("Unite.jpqlAllUnite"), param));
return dataListUnite;
}
public void setDataListUnite(DataModel<SysUnite> dataListUnite) {
this.dataListUnite = dataListUnite;
}
public Map<String, String> getItemsAllActivite() {
return itemsAllActivite;
}
public void setItemsAllActivite(Map<String, String> itemsAllActivite) {
this.itemsAllActivite = itemsAllActivite;
}
}
public SysUnite getSysUnite() {
return sysUnite;
}
public void setSysUnite(SysUnite sysUnite) {
this.sysUnite = sysUnite;
}
public AllRefs getAllRefs() {
return allRefs;
}
public void setAllRefs(AllRefs allRefs) {
this.allRefs = allRefs;
}
public CMessages getCmessages() {
return cmessages;
}
public void setCmessages(CMessages cmessages) {
this.cmessages = cmessages;
}
public CItems getCitems() {
return citems;
}
public void setCitems(CItems citems) {
this.citems = citems;
}
public Cproperties getCproperties() {
return cproperties;
}
public void setCproperties(Cproperties cproperties) {
this.cproperties = cproperties;
}
}