maia_modificado/.svn/pristine/6d/6debdcfd33895a4b94d2d1102f0...

296 lines
10 KiB
Plaintext
Executable File

package com.fp.frontend.controller.armas.parametros;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.apache.commons.lang.StringUtils;
import com.fp.dto.Request;
import com.fp.dto.Response;
import com.fp.dto.query.DtoQuery;
import com.fp.dto.query.Filter;
import com.fp.dto.query.SubQuery;
import com.fp.dto.save.DtoSave;
import com.fp.frontend.controller.AbstractController;
import com.fp.frontend.helper.MessageHelper;
import com.fp.frontend.utility.MsgControlArmas;
import com.fp.persistence.parmas.fun.TarmCashManagementHistory;
import com.fp.persistence.parmas.fun.TarmInventarioSubidoPorPersona;
/**
* Clase controladora del bean TgeneCatalogDetail.
*
* @author Christian Pazmino.
* @version 2.1
*/
@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class CashManagementHistoryController extends AbstractController<TarmCashManagementHistory> {
// Fecha inicial
private Date fechainicial;
// Fecha final
private Date fechafinal;
public CashManagementHistoryController() throws Exception {
super(TarmCashManagementHistory.class);
}
@PostConstruct
private void postconstruct() {
this.init();
// Inicializa autoconsulta
if(fechainicial!=null && fechafinal!=null){
super.startQuery();
}
}
/**
* Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador.
*/
private void init() {
try {
this.recperpage = 15; // Cambiar al # reg a mirar.
this.lrecord = new ArrayList<>();
this.beanalias = "CASHMANAGEMENTHISTORY";
} catch (Exception e) {
MessageHelper.setMessageError(e);
}
}
@SuppressWarnings("unchecked")
@Override
protected void querydatabase() {
try {
DtoQuery dto = super.getDtoQuery(true);
if(fechainicial!= null && fechafinal!=null){
if(this.fechainicial.getTime() > this.fechafinal.getTime()){
MessageHelper.setMessageInfo(MsgControlArmas.getProperty("msg_error_liqeco_fechaInicioMayorAFechaFin"));
this.lrecord = new ArrayList<>();
return;
}
Filter filtroFecha = new Filter();
SimpleDateFormat formato= new SimpleDateFormat("yyyy-MM-dd");
filtroFecha.setSql("trunc(t.datefrom)>=TO_DATE('" + formato.format(fechainicial)+ "','yyyy-MM-dd')" +" and "+ "trunc(t.datefrom)<=TO_DATE('" + formato.format(fechafinal)+ "','yyyy-MM-dd')");
dto.addFiltro(filtroFecha);
}
dto.setOrderby("t.datefrom");
SubQuery queryPersonDetail = new SubQuery("TcustPersonDetail", "name", "personname",
"i.pk.personcode=(Select max(o.pk.personcode) from TsafeUserDetail o where o.pk.usercode = t.usercode and o.pk.dateto=to_date('2999-12-31', 'YYYY-MM-DD')) and i.pk.dateto=to_date('2999-12-31', 'YYYY-MM-DD')");
dto.addSubQuery(queryPersonDetail);
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla.
Request request = this.callerhelper.getRequest();
request.setQueryTables(mtables);
Response resp = this.callerhelper.executeQuery(request);
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
this.lrecord = new ArrayList<TarmCashManagementHistory>();
MessageHelper.setMessageError(resp);
} else {
this.lrecord = (List<TarmCashManagementHistory>) resp.get(this.beanalias);
for(TarmCashManagementHistory tmp:lrecord){
// path del alfresco arreglado
tmp.getModifiedData().put("pathAlfresco", tmp.getPathreporte().replace("cm:", ""));
// SimpleDateFormat sdfHora=new SimpleDateFormat("HH:mm");
// Fecha y hora separados
Calendar fechaTmpCal = Calendar.getInstance();
fechaTmpCal.setTimeInMillis(tmp.getDatefrom().getTime());
tmp.getModifiedData().put("hora", StringUtils.leftPad(String.valueOf(fechaTmpCal.get(Calendar.HOUR_OF_DAY)),2,'0')+":"+StringUtils.leftPad(String.valueOf(fechaTmpCal.get(Calendar.MINUTE)),2,'0'));
tmp.getModifiedData().put("fecha", fechaTmpCal.get(Calendar.YEAR)+"-"+StringUtils.leftPad(String.valueOf(fechaTmpCal.get(Calendar.MONTH)+1),2,'0')+"-"+StringUtils.leftPad(String.valueOf(fechaTmpCal.get(Calendar.DAY_OF_MONTH)),2,'0'));
}
super.postQuery(this.lrecord);
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
@Override
public void save() {
try {
DtoSave dtosave = super.getDtoSave();
dtosave.setReturnpk(true); // Para que el core devuelva el pk de los registros nuevos.
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
Request request = this.callerhelper.getRequest();
msave.put(this.beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla.
request.setSaveTables(msave);
Response resp = this.callerhelper.executeSave(request);
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
this.postCommit(resp);
MessageHelper.setMessageInfo(resp);
} else {
MessageHelper.setMessageError(resp);
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
public void update(TarmCashManagementHistory bean) throws Exception {
record=bean;
update();
}
/**
*
*/
public static TarmCashManagementHistory findUltimoReporteGenerado() {
try {
CashManagementHistoryController cc = new CashManagementHistoryController();
cc.init();
cc.recperpage = 10;
cc.addFilter("dateto", "2999-12-31");
cc.querydatabase();
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
return cc.lrecord.get(0);
}
return null;
} catch (Throwable e) {
MessageHelper.setMessageError(e);
return null;
}
}
/**
*
*/
public static List<TarmCashManagementHistory> findReportesGeneradosVigentes() {
try {
CashManagementHistoryController cc = new CashManagementHistoryController();
cc.init();
cc.recperpage = 10000;
cc.addFilter("dateto", "2999-12-31");
cc.querydatabase();
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
return cc.lrecord;
}
return null;
} catch (Throwable e) {
MessageHelper.setMessageError(e);
return null;
}
}
/**
*
*/
public static List<TarmCashManagementHistory> findReportesByDate(Date fechainicial, Date fechafinal) {
try {
CashManagementHistoryController cc = new CashManagementHistoryController();
cc.init();
cc.recperpage = 10000;
// cc.addFilter("dateto", "2999-12-31");
cc.querydatabaseByDate(fechainicial, fechafinal);;
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
return cc.lrecord;
}
return null;
} catch (Throwable e) {
MessageHelper.setMessageError(e);
return null;
}
}
@SuppressWarnings("unchecked")
protected void querydatabaseByDate(Date fechainicial, Date fechafinal) {
try {
DtoQuery dto = super.getDtoQuery(true);
if(fechainicial!= null && fechafinal!=null){
if(fechainicial.getTime() > fechafinal.getTime()){
MessageHelper.setMessageInfo(MsgControlArmas.getProperty("msg_error_liqeco_fechaInicioMayorAFechaFin"));
this.lrecord = new ArrayList<>();
return;
}
Filter filtroFecha = new Filter();
SimpleDateFormat formato= new SimpleDateFormat("yyyy-MM-dd");
filtroFecha.setSql("trunc(t.datefrom)>=TO_DATE('" + formato.format(fechainicial)+ "','yyyy-MM-dd')" +" and "+ "trunc(t.datefrom)<=TO_DATE('" + formato.format(fechafinal)+ "','yyyy-MM-dd')");
dto.addFiltro(filtroFecha);
}
dto.setOrderby("t.datefrom");
SubQuery queryPersonDetail = new SubQuery("TcustPersonDetail", "name", "personname",
"i.pk.personcode=(Select max(o.pk.personcode) from TsafeUserDetail o where o.pk.usercode = t.usercode and o.pk.dateto=to_date('2999-12-31', 'YYYY-MM-DD')) and i.pk.dateto=to_date('2999-12-31', 'YYYY-MM-DD')");
dto.addSubQuery(queryPersonDetail);
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla.
Request request = this.callerhelper.getRequest();
request.setQueryTables(mtables);
Response resp = this.callerhelper.executeQuery(request);
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
this.lrecord = new ArrayList<TarmCashManagementHistory>();
MessageHelper.setMessageError(resp);
} else {
this.lrecord = (List<TarmCashManagementHistory>) resp.get(this.beanalias);
for(TarmCashManagementHistory tmp:lrecord){
// path del alfresco arreglado
tmp.getModifiedData().put("pathAlfresco", tmp.getPathreporte().replace("cm:", ""));
// SimpleDateFormat sdfHora=new SimpleDateFormat("HH:mm");
// Fecha y hora separados
Calendar fechaTmpCal = Calendar.getInstance();
fechaTmpCal.setTimeInMillis(tmp.getDatefrom().getTime());
tmp.getModifiedData().put("hora", StringUtils.leftPad(String.valueOf(fechaTmpCal.get(Calendar.HOUR_OF_DAY)),2,'0')+":"+StringUtils.leftPad(String.valueOf(fechaTmpCal.get(Calendar.MINUTE)),2,'0'));
tmp.getModifiedData().put("fecha", fechaTmpCal.get(Calendar.YEAR)+"-"+StringUtils.leftPad(String.valueOf(fechaTmpCal.get(Calendar.MONTH)+1),2,'0')+"-"+StringUtils.leftPad(String.valueOf(fechaTmpCal.get(Calendar.DAY_OF_MONTH)),2,'0'));
}
super.postQuery(this.lrecord);
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
/**
* Limpia los registros anteriores
*/
public void limpiar(){
this.lrecord = new ArrayList<>();
fechainicial= null;
fechafinal= null;
}
public Date getFechainicial() {
return fechainicial;
}
public void setFechainicial(Date fechainicial) {
this.fechainicial = fechainicial;
}
public Date getFechafinal() {
return fechafinal;
}
public void setFechafinal(Date fechafinal) {
this.fechafinal = fechafinal;
}
}