Search in sources :

Example 16 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project sic by belluccifranco.

the class FacturaController method calcularTotalFacturadoCompra.

@GetMapping("/facturas/total-facturado-compra/criteria")
@ResponseStatus(HttpStatus.OK)
public double calcularTotalFacturadoCompra(@RequestParam Long idEmpresa, @RequestParam(required = false) Long desde, @RequestParam(required = false) Long hasta, @RequestParam(required = false) Long idProveedor, @RequestParam(required = false) Integer nroSerie, @RequestParam(required = false) Integer nroFactura, @RequestParam(required = false) Boolean soloImpagas, @RequestParam(required = false) Boolean soloPagas) {
    Calendar fechaDesde = Calendar.getInstance();
    Calendar fechaHasta = Calendar.getInstance();
    if ((desde != null) && (hasta != null)) {
        fechaDesde.setTimeInMillis(desde);
        fechaHasta.setTimeInMillis(hasta);
    }
    if (soloImpagas == null) {
        soloImpagas = false;
    }
    if (soloPagas == null) {
        soloPagas = false;
    }
    Proveedor proveedor = null;
    if (idProveedor != null) {
        proveedor = proveedorService.getProveedorPorId(idProveedor);
    }
    BusquedaFacturaCompraCriteria criteria = BusquedaFacturaCompraCriteria.builder().empresa(empresaService.getEmpresaPorId(idEmpresa)).buscaPorFecha((desde != null) && (hasta != null)).fechaDesde(fechaDesde.getTime()).fechaHasta(fechaHasta.getTime()).buscaPorProveedor(idProveedor != null).proveedor(proveedor).buscaPorNumeroFactura((nroSerie != null) && (nroFactura != null)).numSerie((nroSerie != null) ? nroSerie : 0).numFactura((nroFactura != null) ? nroFactura : 0).buscarSoloInpagas(soloImpagas).buscaSoloPagadas(soloPagas).cantRegistros(0).build();
    return facturaService.calcularTotalFacturadoCompra(criteria);
}
Also used : BusquedaFacturaCompraCriteria(sic.modelo.BusquedaFacturaCompraCriteria) Calendar(java.util.Calendar) Proveedor(sic.modelo.Proveedor) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 17 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project sic by belluccifranco.

the class FacturaController method buscarFacturaVenta.

@GetMapping("/facturas/venta/busqueda/criteria")
@ResponseStatus(HttpStatus.OK)
public List<FacturaVenta> buscarFacturaVenta(@RequestParam Long idEmpresa, @RequestParam(required = false) Long desde, @RequestParam(required = false) Long hasta, @RequestParam(required = false) Long idCliente, @RequestParam(required = false) Integer nroSerie, @RequestParam(required = false) Integer nroFactura, @RequestParam(required = false) Long idViajante, @RequestParam(required = false) TipoDeComprobante tipoDeComprobante, @RequestParam(required = false) Long idUsuario, @RequestParam(required = false) Long nroPedido, @RequestParam(required = false) Boolean soloImpagas, @RequestParam(required = false) Boolean soloPagas) {
    Calendar fechaDesde = Calendar.getInstance();
    Calendar fechaHasta = Calendar.getInstance();
    if ((desde != null) && (hasta != null)) {
        fechaDesde.setTimeInMillis(desde);
        fechaHasta.setTimeInMillis(hasta);
    }
    soloImpagas = (soloImpagas == null) ? false : soloImpagas;
    soloPagas = (soloPagas == null) ? false : soloPagas;
    if ((soloImpagas == true) && (soloPagas == true)) {
        soloImpagas = false;
        soloPagas = false;
    }
    Cliente cliente = new Cliente();
    if (idCliente != null) {
        cliente = clienteService.getClientePorId(idCliente);
    }
    Usuario usuario = new Usuario();
    if (idUsuario != null) {
        usuario = usuarioService.getUsuarioPorId(idUsuario);
    }
    Usuario viajante = new Usuario();
    if (idViajante != null) {
        viajante = usuarioService.getUsuarioPorId(idViajante);
    }
    BusquedaFacturaVentaCriteria criteria = BusquedaFacturaVentaCriteria.builder().empresa(empresaService.getEmpresaPorId(idEmpresa)).buscaPorFecha((desde != null) && (hasta != null)).fechaDesde(fechaDesde.getTime()).fechaHasta(fechaHasta.getTime()).buscaCliente(idCliente != null).cliente(cliente).buscaUsuario(idUsuario != null).usuario(usuario).buscaViajante(idViajante != null).viajante(viajante).buscaPorNumeroFactura((nroSerie != null) && (nroFactura != null)).numSerie((nroSerie != null) ? nroSerie : 0).numFactura((nroFactura != null) ? nroFactura : 0).buscarPorPedido(nroPedido != null).nroPedido((nroPedido != null) ? nroPedido : 0).buscaPorTipoComprobante(tipoDeComprobante != null).tipoComprobante((tipoDeComprobante != null) ? tipoDeComprobante : null).buscaSoloImpagas(soloImpagas).buscaSoloPagadas(soloPagas).cantRegistros(0).build();
    return facturaService.buscarFacturaVenta(criteria);
}
Also used : BusquedaFacturaVentaCriteria(sic.modelo.BusquedaFacturaVentaCriteria) Usuario(sic.modelo.Usuario) Calendar(java.util.Calendar) Cliente(sic.modelo.Cliente) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 18 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project sic by belluccifranco.

the class FacturaController method calcularGananciaTotal.

@GetMapping("/facturas/ganancia-total/criteria")
@ResponseStatus(HttpStatus.OK)
public double calcularGananciaTotal(@RequestParam Long idEmpresa, @RequestParam(required = false) Long desde, @RequestParam(required = false) Long hasta, @RequestParam(required = false) Long idCliente, @RequestParam(required = false) Integer nroSerie, @RequestParam(required = false) Integer nroFactura, @RequestParam(required = false) Long idViajante, @RequestParam(required = false) TipoDeComprobante tipoDeComprobante, @RequestParam(required = false) Long idUsuario, @RequestParam(required = false) Long nroPedido, @RequestParam(required = false) Boolean soloImpagas, @RequestParam(required = false) Boolean soloPagas) {
    Calendar fechaDesde = Calendar.getInstance();
    Calendar fechaHasta = Calendar.getInstance();
    if ((desde != null) && (hasta != null)) {
        fechaDesde.setTimeInMillis(desde);
        fechaHasta.setTimeInMillis(hasta);
    }
    if ((soloImpagas != null) && (soloPagas != null)) {
        if ((soloImpagas == true) && (soloPagas == true)) {
            soloImpagas = false;
            soloPagas = false;
        }
    }
    Cliente cliente = new Cliente();
    if (idCliente != null) {
        cliente = clienteService.getClientePorId(idCliente);
    }
    Usuario usuario = new Usuario();
    if (idUsuario != null) {
        usuario = usuarioService.getUsuarioPorId(idUsuario);
    }
    Usuario viajante = new Usuario();
    if (idViajante != null) {
        viajante = usuarioService.getUsuarioPorId(idViajante);
    }
    BusquedaFacturaVentaCriteria criteria = BusquedaFacturaVentaCriteria.builder().empresa(empresaService.getEmpresaPorId(idEmpresa)).buscaPorFecha((desde != null) && (hasta != null)).fechaDesde(fechaDesde.getTime()).fechaHasta(fechaHasta.getTime()).buscaCliente(idCliente != null).cliente(cliente).buscaUsuario(idUsuario != null).usuario(usuario).buscaViajante(idViajante != null).viajante(viajante).buscaPorNumeroFactura((nroSerie != null) && (nroFactura != null)).numSerie((nroSerie != null) ? nroSerie : 0).numFactura((nroFactura != null) ? nroFactura : 0).buscarPorPedido(nroPedido != null).nroPedido((nroPedido != null) ? nroPedido : 0).buscaPorTipoComprobante(tipoDeComprobante != null).tipoComprobante((tipoDeComprobante != null) ? tipoDeComprobante : null).buscaSoloImpagas(soloImpagas).buscaSoloPagadas(soloPagas).cantRegistros(0).build();
    return facturaService.calcularGananciaTotal(criteria);
}
Also used : BusquedaFacturaVentaCriteria(sic.modelo.BusquedaFacturaVentaCriteria) Usuario(sic.modelo.Usuario) Calendar(java.util.Calendar) Cliente(sic.modelo.Cliente) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 19 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project sic by belluccifranco.

the class GastoController method getGastosPorCajaYFormaDePago.

@GetMapping("/gastos/busqueda")
@ResponseStatus(HttpStatus.OK)
public List<Gasto> getGastosPorCajaYFormaDePago(@RequestParam long idEmpresa, @RequestParam long idFormaDePago, @RequestParam long desde, @RequestParam long hasta) {
    Date fechaDesde = new Date(desde);
    Date fechaHasta = new Date(hasta);
    return gastoService.getGastosEntreFechasYFormaDePago(idEmpresa, idFormaDePago, fechaDesde, fechaHasta);
}
Also used : Date(java.util.Date) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 20 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class DataValueController method saveDataValue.

// ---------------------------------------------------------------------
// POST
// ---------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void saveDataValue(@RequestParam String de, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String value, @RequestParam(required = false) String comment, @RequestParam(required = false) boolean followUp, HttpServletResponse response) throws WebMessageException {
    boolean strictPeriods = (Boolean) systemSettingManager.getSystemSetting(SettingKey.DATA_IMPORT_STRICT_PERIODS);
    boolean strictCategoryOptionCombos = (Boolean) systemSettingManager.getSystemSetting(SettingKey.DATA_IMPORT_STRICT_CATEGORY_OPTION_COMBOS);
    boolean strictOrgUnits = (Boolean) systemSettingManager.getSystemSetting(SettingKey.DATA_IMPORT_STRICT_ORGANISATION_UNITS);
    boolean requireCategoryOptionCombo = (Boolean) systemSettingManager.getSystemSetting(SettingKey.DATA_IMPORT_REQUIRE_CATEGORY_OPTION_COMBO);
    // ---------------------------------------------------------------------
    // Input validation
    // ---------------------------------------------------------------------
    DataElement dataElement = getAndValidateDataElement(de);
    DataElementCategoryOptionCombo categoryOptionCombo = getAndValidateCategoryOptionCombo(co, requireCategoryOptionCombo);
    DataElementCategoryOptionCombo attributeOptionCombo = getAndValidateAttributeOptionCombo(cc, cp);
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit organisationUnit = getAndValidateOrganisationUnit(ou);
    validateInvalidFuturePeriod(period, dataElement);
    validateAttributeOptionComboWithOrgUnitAndPeriod(attributeOptionCombo, organisationUnit, period);
    String valueValid = ValidationUtils.dataValueIsValid(value, dataElement);
    if (valueValid != null) {
        throw new WebMessageException(WebMessageUtils.conflict("Invalid value: " + value + ", must match data element type: " + dataElement.getValueType()));
    }
    String commentValid = ValidationUtils.commentIsValid(comment);
    if (commentValid != null) {
        throw new WebMessageException(WebMessageUtils.conflict("Invalid comment: " + comment));
    }
    OptionSet optionSet = dataElement.getOptionSet();
    if (!Strings.isNullOrEmpty(value) && optionSet != null && !optionSet.getOptionCodesAsSet().contains(value)) {
        throw new WebMessageException(WebMessageUtils.conflict("Data value is not a valid option of the data element option set: " + dataElement.getUid()));
    }
    if (strictPeriods && !dataElement.getPeriodTypes().contains(period.getPeriodType())) {
        throw new WebMessageException(WebMessageUtils.conflict("Period type of period: " + period.getIsoDate() + " not valid for data element: " + dataElement.getUid()));
    }
    if (strictCategoryOptionCombos && !dataElement.getCategoryOptionCombos().contains(categoryOptionCombo)) {
        throw new WebMessageException(WebMessageUtils.conflict("Category option combo: " + categoryOptionCombo.getUid() + " must be part of category combo of data element: " + dataElement.getUid()));
    }
    if (strictOrgUnits && !organisationUnit.hasDataElement(dataElement)) {
        throw new WebMessageException(WebMessageUtils.conflict("Data element: " + dataElement.getUid() + " must be assigned through data sets to organisation unit: " + organisationUnit.getUid()));
    }
    // ---------------------------------------------------------------------
    // Locking validation
    // ---------------------------------------------------------------------
    validateDataSetNotLocked(dataElement, period, organisationUnit, attributeOptionCombo);
    // ---------------------------------------------------------------------
    // Period validation
    // ---------------------------------------------------------------------
    validateDataInputPeriodForDataElementAndPeriod(dataElement, period);
    // ---------------------------------------------------------------------
    // Assemble and save data value
    // ---------------------------------------------------------------------
    String storedBy = currentUserService.getCurrentUsername();
    Date now = new Date();
    DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
    FileResource fileResource = null;
    if (dataValue == null) {
        if (dataElement.getValueType() == ValueType.FILE_RESOURCE) {
            if (value != null) {
                fileResource = fileResourceService.getFileResource(value);
                if (fileResource == null || fileResource.getDomain() != FileResourceDomain.DATA_VALUE) {
                    throw new WebMessageException(WebMessageUtils.notFound(FileResource.class, value));
                }
                if (fileResource.isAssigned()) {
                    throw new WebMessageException(WebMessageUtils.conflict("File resource already assigned or linked to another data value"));
                }
                fileResource.setAssigned(true);
            } else {
                throw new WebMessageException(WebMessageUtils.conflict("Missing parameter 'value'"));
            }
        }
        dataValue = new DataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo, StringUtils.trimToNull(value), storedBy, now, StringUtils.trimToNull(comment));
        dataValueService.addDataValue(dataValue);
    } else {
        if (value == null && ValueType.TRUE_ONLY.equals(dataElement.getValueType())) {
            if (comment == null) {
                dataValueService.deleteDataValue(dataValue);
                return;
            } else {
                value = "false";
            }
        }
        if (dataElement.isFileType()) {
            fileResourceService.deleteFileResource(dataValue.getValue());
        }
        if (value != null) {
            dataValue.setValue(StringUtils.trimToNull(value));
        }
        if (comment != null) {
            dataValue.setComment(StringUtils.trimToNull(comment));
        }
        if (followUp) {
            dataValue.toggleFollowUp();
        }
        dataValue.setLastUpdated(now);
        dataValue.setStoredBy(storedBy);
        dataValueService.updateDataValue(dataValue);
    }
    if (fileResource != null) {
        fileResourceService.updateFileResource(fileResource);
    }
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) DataValue(org.hisp.dhis.datavalue.DataValue) FileResource(org.hisp.dhis.fileresource.FileResource) Period(org.hisp.dhis.period.Period) OptionSet(org.hisp.dhis.option.OptionSet) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)93 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)69 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)35 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)26 GetMapping (org.springframework.web.bind.annotation.GetMapping)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)16 User (org.hisp.dhis.user.User)14 Date (java.util.Date)13 Configuration (org.hisp.dhis.configuration.Configuration)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Period (org.hisp.dhis.period.Period)11 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 DataSet (org.hisp.dhis.dataset.DataSet)7 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)7 ArrayList (java.util.ArrayList)6 DataApproval (org.hisp.dhis.dataapproval.DataApproval)6 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)6 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)6 Proveedor (sic.modelo.Proveedor)6