PRICING - Ocupação | Antecipação (fixes bug #5836)

Tempo: 03 horas

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@43707 d1611594-4594-4d17-8e1d-87c2c4800839
master
julio 2015-05-05 19:10:27 +00:00
parent 4880a1cfff
commit 9dc27f02a0
1 changed files with 225 additions and 233 deletions

View File

@ -16,7 +16,6 @@ import org.zkoss.zhtml.Messagebox;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Button;
import org.zkoss.zul.Intbox; import org.zkoss.zul.Intbox;
import org.zkoss.zul.Radio; import org.zkoss.zul.Radio;
@ -47,16 +46,10 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
private Intbox ocupacioninicial; private Intbox ocupacioninicial;
private Intbox ocupacionfinal; private Intbox ocupacionfinal;
private Intbox cantdiasmin; private Intbox cantdiasmin;
private Intbox cantdiasmax;
private Intbox cantasientosmin;
private Intbox cantasientosmax;
private MyTextboxDecimal porcentaje; private MyTextboxDecimal porcentaje;
private MyTextboxDecimal importe;
private List<PricingOcupaAntecipa> lsPricingOcupaAntecipa; private List<PricingOcupaAntecipa> lsPricingOcupaAntecipa;
private Radio rdPoltronas;
private Radio rdOcupacao; private Radio rdOcupacao;
private Boolean hasNoElements; private Boolean hasNoElements;
private Button btnAdicionarOcupaAntecipa;
private List<PricingOcupaAntecipa> argList; private List<PricingOcupaAntecipa> argList;
private Pricing pricing; private Pricing pricing;
@ -64,40 +57,31 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
private ConstraintPorcentagem ct; private ConstraintPorcentagem ct;
private static Logger log = Logger.getLogger(EditarPricingOcupaAntecipaController.class); private static Logger log = Logger.getLogger(EditarPricingOcupaAntecipaController.class);
@Override @Override
public void doAfterCompose(Component comp) throws Exception { public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp); super.doAfterCompose(comp);
/* /*
* Transformar a tabela (valores de exemplo) : * Transformar a tabela (valores de exemplo) :
* *
* Qtd. Dias Qtd. Dias Ocup. Min. Ocup. Máx. Porcentagem * Qtd. Dias Qtd. Dias Ocup. Min. Ocup. Máx. Porcentagem Minimo Máximo
* Minimo Máximo
* *
* 12 * 0% 20% -30% * 12 * 0% 20% -30% 12 * 21% 80% -15% 12 * 81% 90% -10% 8 11 0% 80% -15% 8 11 81% 90% -10% 4 7 0% 90% -10%
* 12 * 21% 80% -15%
* 12 * 81% 90% -10%
* 8 11 0% 80% -15%
* 8 11 81% 90% -10%
* 4 7 0% 90% -10%
* *
* Na forma: * Na forma:
* *
* 12 dias ----> 30% (ocupação de 0% -> 20%) * 12 dias ----> 30% (ocupação de 0% -> 20%) 08 dias ----> 15% (ocupação de 21% -> 80%) 04 dias ----> 10% (ocupação de 81% -> 90%)
* 08 dias ----> 15% (ocupação de 21% -> 80%)
* 04 dias ----> 10% (ocupação de 81% -> 90%)
*
*/ */
argList = (List<PricingOcupaAntecipa>) Executions.getCurrent().getArg().get("clasePricingOcupaAntecipaList"); argList = (List<PricingOcupaAntecipa>) Executions.getCurrent().getArg().get("clasePricingOcupaAntecipaList");
parentPricingOcupaAntecipaList = (MyListbox)Executions.getCurrent().getArg().get("pricingOcupaAntecipaList"); parentPricingOcupaAntecipaList = (MyListbox) Executions.getCurrent().getArg().get("pricingOcupaAntecipaList");
pricing = (Pricing)Executions.getCurrent().getArg().get("pricing"); pricing = (Pricing) Executions.getCurrent().getArg().get("pricing");
pricingOcupaAntecipaList.setItemRenderer(new RenderPricingOcupaAntecipa()); pricingOcupaAntecipaList.setItemRenderer(new RenderPricingOcupaAntecipa());
lsPricingOcupaAntecipa = new ArrayList<PricingOcupaAntecipa>(); lsPricingOcupaAntecipa = new ArrayList<PricingOcupaAntecipa>();
try{ try {
Collections.sort(argList, Collections.reverseOrder(new PricingOcupaAntecipaComparator())); Collections.sort(argList, Collections.reverseOrder(new PricingOcupaAntecipaComparator()));
} catch (Exception e){ } catch (Exception e) {
e.printStackTrace();
Messagebox.show(Labels.getLabel("editarPricingOcupaAntecipaAutomaticoController.MSG.FormatoDados"), Messagebox.show(Labels.getLabel("editarPricingOcupaAntecipaAutomaticoController.MSG.FormatoDados"),
Labels.getLabel("editarPricingController.windowOcupacion.title"), Labels.getLabel("editarPricingController.windowOcupacion.title"),
Messagebox.OK, Messagebox.EXCLAMATION); Messagebox.OK, Messagebox.EXCLAMATION);
@ -107,17 +91,21 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
int diaMin = -1; int diaMin = -1;
for (PricingOcupaAntecipa p : argList){ for (PricingOcupaAntecipa p : argList) {
if (diaMin != p.getCantdiasmin()){ if (p.getCantdiasmin() != null) {
if (diaMin != p.getCantdiasmin()) {
lsPricingOcupaAntecipa.add(p); lsPricingOcupaAntecipa.add(p);
diaMin = p.getCantdiasmin(); diaMin = p.getCantdiasmin();
} }
} else {
lsPricingOcupaAntecipa.add(p);
}
} }
// se TabelaMaior.size mod TabelaMenor.size = 0, então há possibilidade de transformar a maior na menor. // se TabelaMaior.size mod TabelaMenor.size = 0, então há possibilidade de transformar a maior na menor.
if ((lsPricingOcupaAntecipa.size() > 0) && (argList.size() % lsPricingOcupaAntecipa.size() == 0)){ if ((lsPricingOcupaAntecipa.size() > 0) && (argList.size() % lsPricingOcupaAntecipa.size() == 0)) {
for (int j = 0; j < lsPricingOcupaAntecipa.size(); j++){ for (int j = 0; j < lsPricingOcupaAntecipa.size(); j++) {
lsPricingOcupaAntecipa.get(j).setOcupacionfinal(argList.get(j).getOcupacionfinal()); lsPricingOcupaAntecipa.get(j).setOcupacionfinal(argList.get(j).getOcupacionfinal());
lsPricingOcupaAntecipa.get(j).setOcupacioninicial(argList.get(j).getOcupacioninicial()); lsPricingOcupaAntecipa.get(j).setOcupacioninicial(argList.get(j).getOcupacioninicial());
lsPricingOcupaAntecipa.get(j).setCantasientosmax(argList.get(j).getCantasientosmax()); lsPricingOcupaAntecipa.get(j).setCantasientosmax(argList.get(j).getCantasientosmax());
@ -125,7 +113,7 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
} }
pricingOcupaAntecipaList.setData(lsPricingOcupaAntecipa); pricingOcupaAntecipaList.setData(lsPricingOcupaAntecipa);
} else if (lsPricingOcupaAntecipa.size() > 0){ } else if (lsPricingOcupaAntecipa.size() > 0) {
Messagebox.show(Labels.getLabel("editarPricingOcupaAntecipaAutomaticoController.MSG.FormatoDados"), Messagebox.show(Labels.getLabel("editarPricingOcupaAntecipaAutomaticoController.MSG.FormatoDados"),
Labels.getLabel("editarPricingController.windowOcupacion.title"), Labels.getLabel("editarPricingController.windowOcupacion.title"),
Messagebox.OK, Messagebox.EXCLAMATION); Messagebox.OK, Messagebox.EXCLAMATION);
@ -133,9 +121,9 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
} }
} }
private void apagarRegistros() throws BusinessException{ private void apagarRegistros() throws BusinessException {
for (PricingOcupaAntecipa poa : argList){ for (PricingOcupaAntecipa poa : argList) {
if ((poa.getOcupacioninicial() != null && poa.getOcupacioninicial().doubleValue() > 0) || (poa.getCantasientosmin() != null && poa.getCantasientosmin().intValue() > 0)){ if ((poa.getOcupacioninicial() != null && poa.getOcupacioninicial().doubleValue() > 0) || (poa.getCantasientosmin() != null && poa.getCantasientosmin().intValue() > 0)) {
pricingOcupaAntecipaService.borrar(poa); pricingOcupaAntecipaService.borrar(poa);
} }
} }
@ -146,9 +134,9 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
calculaCantDiasMax(); calculaCantDiasMax();
try { try {
apagarRegistros(); apagarRegistros();
for (int i = 0; i < lsPricingOcupaAntecipa.size(); i++){ for (int i = 0; i < lsPricingOcupaAntecipa.size(); i++) {
lsPricingOcupaAntecipa.get(i).setOcupacioninicial(new BigDecimal(0)); lsPricingOcupaAntecipa.get(i).setOcupacioninicial(new BigDecimal(0));
if (lsPricingOcupaAntecipa.get(i).getPricingocupaantecipaId() == null){ if (lsPricingOcupaAntecipa.get(i).getPricingocupaantecipaId() == null) {
pricingOcupaAntecipaService.suscribir(lsPricingOcupaAntecipa.get(i)); pricingOcupaAntecipaService.suscribir(lsPricingOcupaAntecipa.get(i));
} else { } else {
pricingOcupaAntecipaService.actualizacion(lsPricingOcupaAntecipa.get(i)); pricingOcupaAntecipaService.actualizacion(lsPricingOcupaAntecipa.get(i));
@ -156,7 +144,7 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
parentList.add(lsPricingOcupaAntecipa.get(i)); parentList.add(lsPricingOcupaAntecipa.get(i));
for (int j=i+1; j < lsPricingOcupaAntecipa.size(); j++){ for (int j = i + 1; j < lsPricingOcupaAntecipa.size(); j++) {
PricingOcupaAntecipa p = new PricingOcupaAntecipa(); PricingOcupaAntecipa p = new PricingOcupaAntecipa();
p.setPricingocupaantecipaId(lsPricingOcupaAntecipa.get(j).getPricingocupaantecipaId()); p.setPricingocupaantecipaId(lsPricingOcupaAntecipa.get(j).getPricingocupaantecipaId());
p.setCantasientosmax(lsPricingOcupaAntecipa.get(j).getCantasientosmax()); p.setCantasientosmax(lsPricingOcupaAntecipa.get(j).getCantasientosmax());
@ -183,18 +171,22 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
private class PricingOcupaAntecipaComparator implements Comparator<PricingOcupaAntecipa> { private class PricingOcupaAntecipaComparator implements Comparator<PricingOcupaAntecipa> {
public int compare(PricingOcupaAntecipa pricing, PricingOcupaAntecipa outroPricing) { public int compare(PricingOcupaAntecipa pricing, PricingOcupaAntecipa outroPricing) {
return pricing.getCantdiasmin(). if (pricing.getCantdiasmin() != null && outroPricing.getCantdiasmin() != null) {
compareTo(outroPricing.getCantdiasmin()); return pricing.getCantdiasmin().compareTo(outroPricing.getCantdiasmin());
} else if (pricing.getOcupacioninicial() != null && outroPricing.getOcupacioninicial() != null) {
return pricing.getOcupacioninicial().compareTo(outroPricing.getOcupacioninicial());
}
return -1;
} }
} }
private void calculaCantDiasMax(){ private void calculaCantDiasMax() {
Collections.sort(lsPricingOcupaAntecipa, Collections.reverseOrder(new PricingOcupaAntecipaComparator())); Collections.sort(lsPricingOcupaAntecipa, Collections.reverseOrder(new PricingOcupaAntecipaComparator()));
PricingOcupaAntecipa poa; PricingOcupaAntecipa poa;
int cantDiasMinAnterior = lsPricingOcupaAntecipa.get(0).getCantdiasmin(); int cantDiasMinAnterior = lsPricingOcupaAntecipa.get(0).getCantdiasmin();
for (int i = 0; i < lsPricingOcupaAntecipa.size(); i++){ for (int i = 0; i < lsPricingOcupaAntecipa.size(); i++) {
poa = lsPricingOcupaAntecipa.get(i); poa = lsPricingOcupaAntecipa.get(i);
if (i == 0){ if (i == 0) {
poa.setCantdiasmax(CANTDIASMAXDEFAULT); poa.setCantdiasmax(CANTDIASMAXDEFAULT);
} else { } else {
poa.setCantdiasmax(cantDiasMinAnterior - 1); poa.setCantdiasmax(cantDiasMinAnterior - 1);
@ -208,7 +200,7 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
poa.setPricing(pricing); poa.setPricing(pricing);
poa.setCantdiasmin(cantdiasmin.getValue()); poa.setCantdiasmin(cantdiasmin.getValue());
poa.setPorcentaje(porcentaje.getValueDecimal()); poa.setPorcentaje(porcentaje.getValueDecimal());
if (rdOcupacao.isChecked()){ if (rdOcupacao.isChecked()) {
poa.setOcupacioninicial(new BigDecimal(ocupacioninicial.getValue())); poa.setOcupacioninicial(new BigDecimal(ocupacioninicial.getValue()));
poa.setOcupacionfinal(new BigDecimal(ocupacionfinal.getValue())); poa.setOcupacionfinal(new BigDecimal(ocupacionfinal.getValue()));
} else { } else {
@ -282,4 +274,4 @@ public class EditarPricingOcupaAntecipaAutomaticoController extends MyGenericFor
this.hasNoElements = hasNoElements; this.hasNoElements = hasNoElements;
} }
} }