예제 #1
0
        public ActionResult AddComprobante(ComprobanteDTO dto)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (getCurrentUser().IdRol == 4) { return RedirectToAction("Comprobantes", "Admin"); }
            try
            {
                string sTipoComprobante = dto.IdTipoComprobante == 1 ? "Ingreso" : "Egreso";
                int TipoComprobante = 1; //Por defecto tipo de comprobante Ingreso
                if (dto != null)
                {
                    TipoComprobante = dto.IdTipoComprobante;
                    dto.lstMontos = (List<AreaPorComprobanteDTO>)TempData["AreasXMontos"] ?? new List<AreaPorComprobanteDTO>();
                }

                ComprobanteBL objBL = new ComprobanteBL();
                int nDocRepetido = objBL.repeatedNroDocumento(dto.IdEmpresa, dto.IdComprobante, dto.NroDocumento);

                if (dto.IdComprobante == 0)
                {
                    //Si el numero de documento se repite en los ingresos no permitir el registro
                    if (nDocRepetido > 0 && dto.IdTipoComprobante == 1)
                    {
                        switch (nDocRepetido)
                        {
                            case 1:
                                createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_DOCUMENTO_INGRESO_REPETIDO_1);
                                break;
                            case 3:
                                createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_DOCUMENTO_INGRESO_REPETIDO_3);
                                break;
                        }
                    }
                    else if (objBL.add(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("Comprobantes" + sTipoComprobante, "Admin");
                    }
                }
                else if (dto.IdComprobante != 0)
                {
                    //Si el numero de documento se repite en los ingresos no permitir el registro
                    if (nDocRepetido > 0 && dto.IdTipoComprobante == 1)
                    {
                        switch (nDocRepetido)
                        {
                            case 1:
                                createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_DOCUMENTO_INGRESO_REPETIDO_1);
                                break;
                            case 3:
                                createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_DOCUMENTO_INGRESO_REPETIDO_3);
                                break;
                        }
                    }
                    else if (objBL.update(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("Comprobantes" + sTipoComprobante, "Admin");
                    }
                    else
                    {
                        createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                    }

                }
                else
                {
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
                }
            }
            catch (Exception e)
            {
                if (dto.IdComprobante != 0)
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
            }
            TempData["Comprobante"] = dto;
            return RedirectToAction("Comprobante", "Admin", new { id = dto.IdComprobante, idTipoComprobante = dto.IdTipoComprobante });
        }