Skip to content

Commit

Permalink
[Delivers #70404626] Se adapto el reporte y corrigieron valores de la…
Browse files Browse the repository at this point in the history
…s columnas
  • Loading branch information
Omar Otoniel committed Apr 30, 2014
1 parent 582d6a8 commit 4d8d276
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 11 deletions.
22 changes: 22 additions & 0 deletions src/main/java/mx/edu/um/mateo/colportor/dao/DocumentoDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,28 @@ public Map<String, Object> obtieneTodosDiezmos(Map<String,Object> params){
sql.createCriteria("temporadaColportor").createCriteria("colportor").add(Restrictions.eq("id", (Long)params.get("colportor")));
sql.addOrder(Order.asc("fecha"));

params.put(Constantes.DOCUMENTOCOLPORTOR_LIST, sql.list());
return params;
}
/**
* Regresa todos los diezmos acumulados por colportor y por mes
* @param params
* @return
*/
public Map<String, Object> obtieneTodosDiezmosAcumulados(Map<String,Object> params){
log.debug("obtieneTodosDiezmosAcumulados");
Criteria sql = currentSession().createCriteria(Documento.class);
sql.add(Restrictions.eq("tipoDeDocumento", "Diezmo"));
sql.createAlias("temporadaColportor", "tClp");
sql.createAlias("tClp.colportor", "clp");


sql.setProjection(Projections.projectionList()
.add(Projections.groupProperty("clp.clave"))
.add(Projections.groupProperty("fecha"))
.add(Projections.sum("importe")));
sql.addOrder(Order.asc("fecha"));

params.put(Constantes.DOCUMENTOCOLPORTOR_LIST, sql.list());
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public Map<String, Object> listaInformes(Map<String, Object> params){
StringBuilder query = new StringBuilder();
query.append("select im.colportor_id, coalesce(sum(horas_trabajadas),0) as horasTrabajadas, coalesce(sum(total_pedidos),0.0) as pedidos, coalesce(sum(libros_ventas),0.0) as ventas, ");
query.append("coalesce(sum(literatura_gratis),0) as literaturaGratis, coalesce(sum(oraciones_ofrecidas),0) as oraciones, coalesce(sum(casas_visitadas),0) as casasVisitadas, ");
query.append("coalesce(sum(estudios_biblicos),0) as estudiosBiblicos, coalesce(sum(bautizados),0) as bautizados, coalesce(sum(diezmo),0.0) as diezmos ");
query.append("coalesce(sum(estudios_biblicos),0) as estudiosBiblicos, coalesce(sum(bautizados),0) as bautizados, coalesce(sum(diezmo),0.0) as diezmos, ");
query.append("coalesce(sum(libros_vendidos),0) as librosVendidos ");
query.append("from ");
query.append("( ");
query.append("select * ");
Expand Down Expand Up @@ -241,6 +242,7 @@ public Map<String, Object> listaInformes(Map<String, Object> params){
sql.addScalar("estudiosBiblicos", StandardBasicTypes.INTEGER);
sql.addScalar("bautizados", StandardBasicTypes.INTEGER);
sql.addScalar("diezmos", StandardBasicTypes.BIG_DECIMAL);
sql.addScalar("librosVendidos", StandardBasicTypes.INTEGER);

Object [] objs = null;
List <Object[]>lista = sql.list();
Expand Down Expand Up @@ -309,6 +311,13 @@ public Map<String, Object> listaInformes(Map<String, Object> params){
}catch(NullPointerException e){
detalle.setDiezmo(BigDecimal.ZERO);
}
System.out.println(objs[10]);
try{
detalle.setLiteraturaVendida((Integer)objs[10]);
}catch(NullPointerException e){
detalle.setLiteraturaVendida(0);
}

detalles.add(detalle);
}
params.put(Constantes.INFORMEMENSUAL_DETALLE_LIST, detalles);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/mx/edu/um/mateo/colportor/model/Documento.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public class Documento implements Serializable{

public Documento(){
}

public Documento(BigDecimal importe){
this.importe = importe;
}

public Documento(String tipoDeDocumento, String folio, Date fecha, BigDecimal importe, String observaciones, TemporadaColportor temporadaColportor) {
this.tipoDeDocumento = tipoDeDocumento;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,11 @@ public void importaInformes(File file, Usuario user) throws NullPointerException
String clave = null;
String fecha = null;
String numLibros = null;
String descripcion = null;
BigDecimal compras = null;
BigDecimal boletin = null;
BigDecimal ventas = null;
BigDecimal pedidos = null;
Integer gratis = null;

Colportor clp = null;
Expand All @@ -433,6 +435,7 @@ public void importaInformes(File file, Usuario user) throws NullPointerException
sw =false; //Si no se leyo colportor alguno, entonces no se leen las demas celdas
nuevo = false; //Para saber cuando crear un nuevo encabezado de informe
gratis = 0;
pedidos = BigDecimal.ZERO;

for (int c = 0; c < cols; c++) {
cell = row.getCell(c);
Expand Down Expand Up @@ -475,6 +478,12 @@ public void importaInformes(File file, Usuario user) throws NullPointerException
}
break;
}
case 6:{
log.debug("Descripcion {}",cell.getStringCellValue());
descripcion = cell.getStringCellValue();

break;
}
case 8:{
try{
log.debug("Libros {}",cell.getStringCellValue());
Expand Down Expand Up @@ -505,15 +514,22 @@ public void importaInformes(File file, Usuario user) throws NullPointerException
break;
}
case 11:{

try{
log.debug("boletin {}",cell.getStringCellValue());
boletin = new BigDecimal(cell.getStringCellValue());
}catch(Exception e){
log.debug("Leyendo boletin {}", String.valueOf(cell.getNumericCellValue()));
boletin = new BigDecimal(String.valueOf(cell.getNumericCellValue()));
}
ventas = boletin.plus();
ventas = boletin.multiply(BigDecimal.valueOf(2.0)); //Las ventas son el doble del boletin
ventas = ventas.abs();

//Si es una revista y tiene un costo,
if(descripcion.startsWith("REVISTA") && ventas.compareTo(BigDecimal.ZERO) > 0){
//entonces se acumula en pedidos
pedidos = pedidos.add(ventas);
}
break;
}

Expand All @@ -524,9 +540,9 @@ public void importaInformes(File file, Usuario user) throws NullPointerException
//Insertar boletin
if(sw){

if(boletin.compareTo(BigDecimal.ZERO) == 0){
continue; //No hacemos nada
}
// if(boletin.compareTo(BigDecimal.ZERO) == 0){
// continue; //No hacemos nada
// }

//Obtener el informe
informe = infDao.obtiene(clp,gcFecha.getTime());
Expand All @@ -535,7 +551,7 @@ public void importaInformes(File file, Usuario user) throws NullPointerException
detalle.setInformeMensual(informe);
detalle.setFecha(gcFecha.getTime());
detalle.setLiteraturaVendida(Integer.parseInt(numLibros));
detalle.setTotalPedidos(BigDecimal.ZERO);
detalle.setTotalPedidos(pedidos);
detalle.setTotalVentas(ventas);
detalle.setLiteraturaGratis((gratis != null)?gratis:0);
detalle.setCapturo(user);
Expand All @@ -556,7 +572,7 @@ public void importaInformes(File file, Usuario user) throws NullPointerException
detalle.setInformeMensual(informe);
detalle.setFecha(gcFecha.getTime());
detalle.setLiteraturaVendida(Integer.parseInt(numLibros));
detalle.setTotalPedidos(BigDecimal.ZERO);
detalle.setTotalPedidos(pedidos);
detalle.setTotalVentas(ventas);
detalle.setLiteraturaGratis((gratis != null)?gratis:0);
detalle.setCapturo(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public Map<String, Object> lista(Map<String, Object> params) {
totales.setCasasVisitadas(totales.getCasasVisitadas()+imd.getCasasVisitadas());
totales.setContactosEstudiosBiblicos(totales.getContactosEstudiosBiblicos()+imd.getContactosEstudiosBiblicos());
totales.setBautizados(totales.getBautizados()+imd.getBautizados());
totales.setDiezmo(totales.getDiezmo().add(totalDiezmos));
}
tmp = new InformeMensualDetalle();
tmp.setInformeMensual(new InformeMensual("@"));//para identificar este tipo de registros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package mx.edu.um.mateo.colportor.service.impl;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -359,6 +361,23 @@ public Map<String, Object> informeMensualAsociado(Map<String, Object> params) th
params = infMensualDetalleDao.listaInformes(params);
List <InformeMensualDetalle> detalles = (List <InformeMensualDetalle>)params.get(Constantes.INFORMEMENSUAL_DETALLE_LIST);

Map <String, Documento> mDiezmos = new TreeMap<>();
params = docDao.obtieneTodosDiezmosAcumulados(params);

log.debug("Primer diezmo {}", ((List<Documento>)params.get(Constantes.DOCUMENTOCOLPORTOR_LIST)).get(0));

for(Object [] doc : (List<Object[]>)params.get(Constantes.DOCUMENTOCOLPORTOR_LIST)){
log.debug("doc {}",doc);

if(mDiezmos.containsKey(doc[0])){
//acumulando
mDiezmos.get(doc[0]).setImporte(mDiezmos.get(doc[0]).getImporte().add((BigDecimal)doc[2]));
}
else{
mDiezmos.put((String)doc[0], new Documento((BigDecimal)doc[2]));
}
}

InformeMensualDetalle tmpDetalle = null;
Map <String, InformeMensualDetalle> mDetalles = new TreeMap<>();

Expand All @@ -377,8 +396,34 @@ public Map<String, Object> informeMensualAsociado(Map<String, Object> params) th
for(InformeMensualDetalle det : detalles){
det.getInformeMensual().setColportor(clpDao.obtiene(det.getInformeMensual().getColportor().getId()));

if(mDiezmos.containsKey(det.getInformeMensual().getColportor().getClave())){
det.setDiezmo(mDiezmos.get(det.getInformeMensual().getColportor().getClave()).getImporte());
}

//Realizar aproximaciones de los valores de horas trabajadas
BigDecimal rango = BigDecimal.ZERO;
//este valor temporalmente es fijo, posteriormente debe cambiarse por la lectura de los rangos
switch(gcFecha.get(Calendar.YEAR)){
case 2014: {rango = new BigDecimal("5625.00"); break;}
default: {break;}
}

if(det.getTotalVentas().compareTo(rango) > 0){
det.setHrsTrabajadas(40.0*13.0/3.0);
}
else{
//regla de tres para obtener hrs proporcionales
BigDecimal tmp = new BigDecimal(40.0*13.0/3.0);
MathContext mc = new MathContext(4, RoundingMode.HALF_EVEN);
det.setHrsTrabajadas(((det.getTotalVentas().multiply(tmp, mc)).divide(rango, mc)).doubleValue());
}

det.setCasasVisitadas(new Double(det.getHrsTrabajadas()*2.0).intValue());
det.setOracionesOfrecidas(new Double(det.getCasasVisitadas() * 0.1).intValue());
det.setContactosEstudiosBiblicos(new Double(det.getOracionesOfrecidas() * 0.1).intValue());

totalDetalle.setBautizados(totalDetalle.getBautizados()+det.getBautizados());
totalDetalle.setCasasVisitadas(totalDetalle.getCasasVisitadas()+det.getBautizados());
totalDetalle.setCasasVisitadas(totalDetalle.getCasasVisitadas()+det.getCasasVisitadas());
totalDetalle.setContactosEstudiosBiblicos(totalDetalle.getContactosEstudiosBiblicos()+det.getContactosEstudiosBiblicos());
totalDetalle.setDiezmo(totalDetalle.getDiezmo().add(det.getDiezmo()));
totalDetalle.setHrsTrabajadas(totalDetalle.getHrsTrabajadas()+det.getHrsTrabajadas());
Expand All @@ -392,7 +437,7 @@ public Map<String, Object> informeMensualAsociado(Map<String, Object> params) th
tmpDetalle = new InformeMensualDetalle();
tmpDetalle.setInformeMensual(det.getInformeMensual());
tmpDetalle.setBautizados(det.getBautizados());
tmpDetalle.setCasasVisitadas(det.getBautizados());
tmpDetalle.setCasasVisitadas(det.getCasasVisitadas());
tmpDetalle.setContactosEstudiosBiblicos(det.getContactosEstudiosBiblicos());
tmpDetalle.setDiezmo(det.getDiezmo());
tmpDetalle.setHrsTrabajadas(det.getHrsTrabajadas());
Expand All @@ -406,7 +451,7 @@ public Map<String, Object> informeMensualAsociado(Map<String, Object> params) th
else{
tmpDetalle = mDetalles.get(det.getInformeMensual().getColportor().getClave());
tmpDetalle.setBautizados(tmpDetalle.getBautizados()+det.getBautizados());
tmpDetalle.setCasasVisitadas(tmpDetalle.getCasasVisitadas()+det.getBautizados());
tmpDetalle.setCasasVisitadas(tmpDetalle.getCasasVisitadas()+det.getCasasVisitadas());
tmpDetalle.setContactosEstudiosBiblicos(tmpDetalle.getContactosEstudiosBiblicos()+det.getContactosEstudiosBiblicos());
tmpDetalle.setDiezmo(tmpDetalle.getDiezmo().add(det.getDiezmo()));
tmpDetalle.setHrsTrabajadas(tmpDetalle.getHrsTrabajadas()+det.getHrsTrabajadas());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>

<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -51,7 +52,7 @@
<tr>
<td>
<span class="label label-success">
<b><s:message code="hrsTrabajadas.label" /> </b><fmt:formatNumber type="number" value="${informeMensualAsociadoTotales.hrsTrabajadas}"/>
<b><s:message code="hrsTrabajadas.label" /> </b><fmt:formatNumber maxFractionDigits="0" type="number" value="${informeMensualAsociadoTotales.hrsTrabajadas}" />
</span>
</td>
<td>
Expand Down

0 comments on commit 4d8d276

Please sign in to comment.