public async Task <AppStatusQuote> Insert(AppStatusQuote appStatusQuote)
        {
            await _unitOfWork.AppStatusQuoteRepository.Add(appStatusQuote);

            await _unitOfWork.SaveChangesAsync();

            return(appStatusQuote);
        }
        public async Task <AppStatusQuote> Update(AppStatusQuote appStatusQuote)
        {
            var appStatusQuoteFind = await GetById(appStatusQuote.Id);

            if (appStatusQuoteFind == null)
            {
                throw new Exception("Documento No existe");
            }

            _unitOfWork.AppStatusQuoteRepository.Update(appStatusQuote);
            await _unitOfWork.SaveChangesAsync();

            return(await GetById(appStatusQuote.Id));
        }
        public async Task <bool> ExisteEnEspera(int appGeneralQuotesId)
        {
            bool result = false;
            var  detail = await _context.AppDetailQuotes.Where(x => x.AppGeneralQuotesId == appGeneralQuotesId).ToListAsync();

            if (detail != null)
            {
                foreach (var item in detail)
                {
                    AppStatusQuote appStatusQuote = await _context.AppStatusQuote.Where(x => x.Id == item.IdEstatus).FirstOrDefaultAsync();

                    if (appStatusQuote.FlagEnEspera == "X")
                    {
                        result = true;
                    }
                }

                return(result);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        public async Task Delete(int id)
        {
            AppStatusQuote entity = await GetById(id);

            _context.AppStatusQuote.Remove(entity);
        }
Esempio n. 5
0
 public void Update(AppStatusQuote entity)
 {
     _context.AppStatusQuote.Update(entity);
 }
Esempio n. 6
0
 public async Task Add(AppStatusQuote entity)
 {
     await _context.AppStatusQuote.AddAsync(entity);
 }
Esempio n. 7
0
        public async Task <ApiResponse <bool> > DeleteGeneralQuotes(AppGeneralQuotesDeleteDto appGeneralQuotesDeleteDto)
        {
            bool resultDto = new bool();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };

            ApiResponse <bool> response = new ApiResponse <bool>(resultDto);

            try
            {
                AppGeneralQuotes appGeneralQuotes = await GetById(appGeneralQuotesDeleteDto.Id);

                if (appGeneralQuotes == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Cotizacion No Existe!!! " + appGeneralQuotesDeleteDto.Cotizacion;
                    response.Meta    = metadata;
                    response.Data    = false;
                    return(response);
                }

                AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(appGeneralQuotes.IdEstatus);

                if (appStatusQuote.FlagModificar == "X")
                {
                    await _cotizacionService.DeleteCotizacion(appGeneralQuotes);

                    var detail = await _unitOfWork.AppDetailQuotesRepository.GetByAppGeneralQuotesId(appGeneralQuotes.Id);

                    if (detail != null && detail.Count > 0)
                    {
                        foreach (var item in detail)
                        {
                            var detailConversion = await _unitOfWork.AppDetailQuotesConversionUnitRepository.GetByAppDetailQuotesId(item.Id);

                            if (detailConversion != null && detailConversion.Count > 0)
                            {
                                foreach (var itemConversion in detailConversion)
                                {
                                    await _unitOfWork.AppDetailQuotesConversionUnitRepository.Delete(itemConversion.Id);

                                    await _unitOfWork.SaveChangesAsync();
                                }
                            }


                            await _unitOfWork.AppDetailQuotesRepository.Delete(item.Id);

                            await _unitOfWork.SaveChangesAsync();
                        }
                    }
                    await Delete(appGeneralQuotesDeleteDto.Id);
                }



                metadata.IsValid = true;
                metadata.Message = $"Cotizacion: {appGeneralQuotesDeleteDto.Cotizacion} Eliminada Satisfactoriamente!!";

                response.Meta = metadata;
                response.Data = resultDto;

                return(response);
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;

                metadata.Message = ex.InnerException.Message;

                response.Meta = metadata;
                response.Data = resultDto;

                return(response);
            }
        }
Esempio n. 8
0
        public async Task <ApiResponse <AppGeneralQuotesGetDto> > UpdateGeneralQuotes(AppGeneralQuotesUpdateDto appGeneralQuotesUpdateDto)
        {
            AppGeneralQuotesGetDto resultDto = new AppGeneralQuotesGetDto();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };

            ApiResponse <AppGeneralQuotesGetDto> response = new ApiResponse <AppGeneralQuotesGetDto>(resultDto);

            try
            {
                AppGeneralQuotes appGeneralQuotes = await GetById(appGeneralQuotesUpdateDto.Id);

                if (appGeneralQuotes == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Cotizacion No Existe!!! " + appGeneralQuotesUpdateDto.Cotizacion;
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }

                MtrCliente cliente = await _mtrClienteService.GetByIdAsync(appGeneralQuotesUpdateDto.IdCliente);

                if (cliente == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Cliente No Existe!!! " + appGeneralQuotesUpdateDto.IdCliente;
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }
                MtrDirecciones direccionEntregarValidate = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesUpdateDto.IdDireccionEntregar);

                if (direccionEntregarValidate == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Direccion Entregar No Existe!!! " + appGeneralQuotesUpdateDto.IdDireccionEntregar;
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }

                MtrContactos mtrContactosValidate = await _unitOfWork.MtrContactosRepository.GetById(appGeneralQuotesUpdateDto.IdContacto);

                if (mtrContactosValidate == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Contacto No Existe!!! ";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }

                MtrCondicionPago condicionPagoValidate = await _unitOfWork.MtrCondicionPagoRepository.GetById(appGeneralQuotesUpdateDto.IdCondPago);

                if (condicionPagoValidate == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Condicion de Pago No Existe!!! ";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }


                MtrTipoMoneda mtrTipoMonedaFind = await _unitOfWork.MtrTipoMonedaRepository.GetById(appGeneralQuotesUpdateDto.IdMtrTipoMoneda);

                if (mtrTipoMonedaFind == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Moneda No Existe!!! ";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }

                if (appGeneralQuotesUpdateDto.OrdenCompra.Length > 16)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Longitud Maxima de Orden de Compra es 16 !!! ";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }


                if (appGeneralQuotesUpdateDto.IdCliente != "000000")
                {
                    appGeneralQuotesUpdateDto.Rif         = cliente.NoRegTribut;
                    appGeneralQuotesUpdateDto.RazonSocial = cliente.Nombre;
                    appGeneralQuotesUpdateDto.Direccion   = cliente.Direccion + " " + cliente.Direccion1;
                }
                appGeneralQuotes.Rif         = appGeneralQuotesUpdateDto.Rif;
                appGeneralQuotes.RazonSocial = appGeneralQuotesUpdateDto.RazonSocial;
                appGeneralQuotes.Direccion   = appGeneralQuotesUpdateDto.Direccion;

                appGeneralQuotes.IdCliente = appGeneralQuotesUpdateDto.IdCliente;

                if (appGeneralQuotesUpdateDto.IdCliente == "000000")
                {
                    appGeneralQuotes.IdMunicipio = appGeneralQuotesUpdateDto.IdMunicipio;
                    var municipio = await _unitOfWork.Winy243Repository.GetById(appGeneralQuotesUpdateDto.IdMunicipio);

                    if (municipio != null)
                    {
                        appGeneralQuotes.DescripcionMunicipio = municipio.DescMunicipio;
                    }
                }
                else
                {
                    var municipio = await _unitOfWork.Winy243Repository.GetByEstadoMunicipio(direccionEntregarValidate.Estado, direccionEntregarValidate.Municipio);

                    if (municipio != null)
                    {
                        appGeneralQuotes.IdMunicipio          = municipio.Recnum;
                        appGeneralQuotes.DescripcionMunicipio = municipio.DescMunicipio;
                    }
                }



                if (appGeneralQuotesUpdateDto.IdCliente != "000000")
                {
                    appGeneralQuotes.IdVendedor = cliente.Vendedor1.Trim();
                }
                else
                {
                    appGeneralQuotes.IdVendedor = appGeneralQuotesUpdateDto.UsuarioActualiza;
                }


                appGeneralQuotes.Observaciones       = appGeneralQuotesUpdateDto.Observaciones;
                appGeneralQuotes.IdCondPago          = appGeneralQuotesUpdateDto.IdCondPago;
                appGeneralQuotes.IdContacto          = appGeneralQuotesUpdateDto.IdContacto;
                appGeneralQuotes.IdDireccionFacturar = (decimal)cliente.IdDireccion;
                appGeneralQuotes.IdDireccionEntregar = appGeneralQuotesUpdateDto.IdDireccionEntregar;
                appGeneralQuotes.OrdenCompra         = appGeneralQuotesUpdateDto.OrdenCompra;
                appGeneralQuotes.UsuarioActualiza    = appGeneralQuotesUpdateDto.UsuarioActualiza;
                appGeneralQuotes.FechaActualiza      = DateTime.Now;
                appGeneralQuotes.Proximo             = 0;
                appGeneralQuotes.IdMtrTipoMoneda     = appGeneralQuotesUpdateDto.IdMtrTipoMoneda;
                if (appGeneralQuotesUpdateDto.FechaPostergada != null)
                {
                    appGeneralQuotes.FechaPostergada = appGeneralQuotesUpdateDto.FechaPostergada;
                }
                if (appGeneralQuotesUpdateDto.ObservacionPostergar != "" && appGeneralQuotesUpdateDto.ObservacionPostergar != null)
                {
                    appGeneralQuotes.ObservacionPostergar = appGeneralQuotesUpdateDto.ObservacionPostergar;
                }
                else
                {
                    appGeneralQuotesUpdateDto.ObservacionPostergar = "";
                }
                appGeneralQuotes.FijarPrecioBs = appGeneralQuotesUpdateDto.FijarPrecioBs;


                AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(appGeneralQuotes.IdEstatus);

                MtrVendedor vendedor = _unitOfWork.MtrVendedorRepository.GetById(appGeneralQuotes.IdVendedor);



                if (appGeneralQuotesUpdateDto.IdCliente != "000000")
                {
                    appGeneralQuotes.SearchText = $"{appGeneralQuotes.Cotizacion}-{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{cliente.Nombre.Trim()}{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{appGeneralQuotes.RazonSocial.Trim()}-{appStatusQuote.Descripcion.Trim()}";
                }
                else
                {
                    appGeneralQuotes.SearchText          = $"{appGeneralQuotes.Cotizacion}-{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{appGeneralQuotes.RazonSocial.Trim()}-{appStatusQuote.Descripcion.Trim()}";
                    appGeneralQuotes.IdDireccionEntregar = 1;
                    appGeneralQuotes.IdDireccionFacturar = 1;
                }



                AppGeneralQuotes AppGeneralQuotesUpdated = await Update(appGeneralQuotes);

                //await _cotizacionService.IntegrarCotizacion(AppGeneralQuotesUpdated.Id);



                if (AppGeneralQuotesUpdated != null)
                {
                    resultDto = _mapper.Map <AppGeneralQuotesGetDto>(AppGeneralQuotesUpdated);

                    MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(resultDto.IdVendedor);
                    if (mtrVendedor != null)
                    {
                        MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor);
                        resultDto.MtrVendedorDto = mtrVendedorDto;
                    }



                    MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(resultDto.IdCliente);
                    if (mtrCliente != null)
                    {
                        MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente);
                        resultDto.MtrClienteDto = mtrClienteDto;
                    }

                    MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(resultDto.IdContacto);

                    if (mtrContactos != null)
                    {
                        MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos);
                        resultDto.MtrContactosDto = mtrContactosDto;
                    }



                    MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(resultDto.IdDireccionEntregar);

                    if (direccionEntregar != null)
                    {
                        MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar);
                        resultDto.MtrDireccionesEntregarDto = direccionEntregarDto;
                    }



                    MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(resultDto.IdDireccionFacturar);

                    if (direccionFacturar != null)
                    {
                        MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar);
                        resultDto.MtrDireccionesFacturarDto = direccionFacturarDto;
                    }

                    MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(resultDto.IdCondPago);

                    if (condicionPago != null)
                    {
                        CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago);
                        resultDto.CondicionPagoDto = condicionPagoDto;
                    }


                    MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(resultDto.IdMtrTipoMoneda);

                    if (mtrTipoMoneda != null)
                    {
                        MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda);
                        resultDto.MtrTipoMonedaDto = mtrTipoMonedaDto;
                    }

                    metadata.IsValid = true;
                    metadata.Message = $"Cotizacion: {resultDto.Cotizacion} Actualizada Satisfactoriamente!!";
                }
                else
                {
                    metadata.IsValid = false;

                    metadata.Message = "Registro No actualizado";
                }


                response.Meta = metadata;
                response.Data = resultDto;

                return(response);
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;

                metadata.Message = ex.InnerException.Message;

                response.Meta = metadata;
                response.Data = resultDto;

                return(response);
            }
        }
Esempio n. 9
0
        public async Task <AppGeneralQuotesGetDto> GetAppGeneralQuotes(AppGeneralQuotesQueryFilter filters)
        {
            filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber;
            filters.PageSize   = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize;


            AppGeneralQuotes quotes = await _unitOfWork.AppGeneralQuotesRepository.GetByCotizacions(filters.Cotizacion);

            if (quotes != null)
            {
                AppGeneralQuotesGetDto appGeneralQuotesGetDto = _mapper.Map <AppGeneralQuotesGetDto>(quotes);

                MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(appGeneralQuotesGetDto.IdVendedor);
                if (mtrVendedor != null)
                {
                    MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor);
                    appGeneralQuotesGetDto.MtrVendedorDto = mtrVendedorDto;
                }



                MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(appGeneralQuotesGetDto.IdCliente);
                if (mtrCliente != null)
                {
                    MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente);
                    appGeneralQuotesGetDto.MtrClienteDto = mtrClienteDto;
                }

                MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(appGeneralQuotesGetDto.IdContacto);

                if (mtrContactos != null)
                {
                    //MtrContactosDto mtrContactosDto = new MtrContactosDto();
                    //mtrContactosDto.IdContacto = mtrContactos.IdContacto;
                    //mtrContactosDto.Cargo = mtrContactos.Email;

                    MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos);
                    appGeneralQuotesGetDto.MtrContactosDto = mtrContactosDto;
                }



                MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesGetDto.IdDireccionEntregar);

                if (direccionEntregar != null)
                {
                    MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar);
                    appGeneralQuotesGetDto.MtrDireccionesEntregarDto = direccionEntregarDto;
                }



                MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesGetDto.IdDireccionFacturar);

                if (direccionFacturar != null)
                {
                    MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar);
                    appGeneralQuotesGetDto.MtrDireccionesFacturarDto = direccionFacturarDto;
                }

                MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(appGeneralQuotesGetDto.IdCondPago);

                if (condicionPago != null)
                {
                    CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago);
                    appGeneralQuotesGetDto.CondicionPagoDto = condicionPagoDto;
                }

                MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(appGeneralQuotesGetDto.IdMtrTipoMoneda);

                if (mtrTipoMoneda != null)
                {
                    MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda);
                    appGeneralQuotesGetDto.MtrTipoMonedaDto = mtrTipoMonedaDto;
                }

                var actualizar = await _unitOfWork.AppGeneralQuotesRepository.VerificarStatus(appGeneralQuotesGetDto.Id);

                if (actualizar)
                {
                    await _unitOfWork.SaveChangesAsync();
                }


                AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(appGeneralQuotesGetDto.IdEstatus);

                if (appStatusQuote != null)
                {
                    AppStatusQuoteGetDto appStatusQuoteDto = _mapper.Map <AppStatusQuoteGetDto>(appStatusQuote);
                    appGeneralQuotesGetDto.AppStatusQuoteGetDto = appStatusQuoteDto;
                }

                appGeneralQuotesGetDto.PorcFlete = await GetFleteByIdDireccionEntrega(appGeneralQuotesGetDto.IdDireccionEntregar);


                var permiteAdicionarDetalle = await _unitOfWork.AppGeneralQuotesRepository.PermiteAdicionarDetalle(appGeneralQuotesGetDto.Id);

                appGeneralQuotesGetDto.PermiteAdicionarDetalle = permiteAdicionarDetalle;

                appGeneralQuotesGetDto.AppGeneralQuotesActionSheetDto = await GetAppGeneralQuotesActionSheetDto(appGeneralQuotesGetDto.Id);

                ApiResponse <List <AppDetailQuotesGetDto> > listDetail = await _appDetailQuotesService.GetListAppDetailQuoteByAppGeneralQuotesId(appGeneralQuotesGetDto.Id);

                if (listDetail != null)
                {
                    appGeneralQuotesGetDto.AppDetailQuotesGetDto = listDetail.Data;
                }



                return(appGeneralQuotesGetDto);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 10
0
        public async Task <PagedList <AppGeneralQuotesGetDto> > GetAllAppGeneralQuotes(AppGeneralQuotesQueryFilter filters)
        {
            filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber;
            filters.PageSize   = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize;


            List <AppGeneralQuotes> quotes = await _unitOfWork.AppGeneralQuotesRepository.GetAll(filters);

            if (quotes.Count > 0)
            {
                List <AppGeneralQuotesGetDto> appGeneralQuotesGetDto = _mapper.Map <List <AppGeneralQuotesGetDto> >(quotes);
                foreach (AppGeneralQuotesGetDto item in appGeneralQuotesGetDto)
                {
                    MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(item.IdVendedor);
                    if (mtrVendedor != null)
                    {
                        MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor);
                        item.MtrVendedorDto = mtrVendedorDto;
                    }



                    MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(item.IdCliente);
                    if (mtrCliente != null)
                    {
                        MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente);
                        item.MtrClienteDto = mtrClienteDto;
                        if (item.IdCliente == "000000")
                        {
                            item.MtrClienteDto.Descripcion = item.IdCliente.Trim() + "-" + item.RazonSocial.Trim() + " RIF: " + item.Rif.ToString();
                        }
                    }

                    MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(item.IdContacto);

                    if (mtrContactos != null)
                    {
                        MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos);
                        item.MtrContactosDto = mtrContactosDto;
                    }



                    MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(item.IdDireccionEntregar);

                    if (direccionEntregar != null)
                    {
                        MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar);
                        item.MtrDireccionesEntregarDto = direccionEntregarDto;
                    }



                    MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(item.IdDireccionFacturar);

                    if (direccionFacturar != null)
                    {
                        MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar);
                        item.MtrDireccionesFacturarDto = direccionFacturarDto;
                    }

                    MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(item.IdCondPago);

                    if (condicionPago != null)
                    {
                        CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago);
                        item.CondicionPagoDto = condicionPagoDto;
                    }

                    MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(item.IdMtrTipoMoneda);

                    if (mtrTipoMoneda != null)
                    {
                        MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda);
                        item.MtrTipoMonedaDto = mtrTipoMonedaDto;
                    }

                    var actualizar = await _unitOfWork.AppGeneralQuotesRepository.VerificarStatus(item.Id);

                    if (actualizar)
                    {
                        await _unitOfWork.SaveChangesAsync();
                    }


                    AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(item.IdEstatus);

                    if (appStatusQuote != null)
                    {
                        AppStatusQuoteGetDto appStatusQuoteDto = _mapper.Map <AppStatusQuoteGetDto>(appStatusQuote);
                        item.AppStatusQuoteGetDto = appStatusQuoteDto;
                    }

                    if (item.IdCliente == "000000")
                    {
                        var municipio = await _unitOfWork.Winy243Repository.GetById(item.IdMunicipio);

                        if (municipio != null)
                        {
                            item.PorcFlete = municipio.PorcFlete;
                            MunicipioGetDto municipioGetDto = _mapper.Map <MunicipioGetDto>(municipio);
                            item.MunicipioGetDto = municipioGetDto;
                        }
                    }
                    else
                    {
                        item.PorcFlete = await GetFleteByIdDireccionEntrega(item.IdDireccionEntregar);

                        var municipio = await _unitOfWork.Winy243Repository.GetByEstadoMunicipio(direccionEntregar.Estado, direccionEntregar.Municipio);

                        if (municipio != null)
                        {
                            item.IdMunicipio          = municipio.Recnum;
                            item.descripcionMunicipio = municipio.DescMunicipio;
                            MunicipioGetDto municipioGetDto = _mapper.Map <MunicipioGetDto>(municipio);
                            item.MunicipioGetDto = municipioGetDto;
                        }
                    }



                    var permiteAdicionarDetalle = await _unitOfWork.AppGeneralQuotesRepository.PermiteAdicionarDetalle(item.Id);

                    item.PermiteAdicionarDetalle = permiteAdicionarDetalle;

                    item.AppGeneralQuotesActionSheetDto = await GetAppGeneralQuotesActionSheetDto(item.Id);


                    ApiResponse <List <AppDetailQuotesGetDto> > listDetail = await _appDetailQuotesService.GetListAppDetailQuoteByAppGeneralQuotesId(item.Id);

                    if (listDetail != null)
                    {
                        item.AppDetailQuotesGetDto = listDetail.Data;
                    }

                    item.FechaString = item.Fecha.ToString("dd/MM/yyyy");
                }

                PagedList <AppGeneralQuotesGetDto> pagedResult = PagedList <AppGeneralQuotesGetDto> .Create(appGeneralQuotesGetDto, filters.PageNumber, filters.PageSize);



                return(pagedResult);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 11
0
        public async Task <AppGeneralQuotesActionSheetDto> GetAppGeneralQuotesActionSheetDto(int AppGeneralQuotesId)
        {
            AppGeneralQuotesActionSheetDto resultDto = new AppGeneralQuotesActionSheetDto();



            resultDto.Cancel = true;



            AppGeneralQuotes generalQuotes = await GetById(AppGeneralQuotesId);

            if (generalQuotes != null)
            {
                resultDto.ExistQuotes = true;

                AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(generalQuotes.IdEstatus);



                if (appStatusQuote.FlagModificar == "X")
                {
                    resultDto.Actualizar = true;
                    resultDto.Eliminar   = true;
                }
                else
                {
                    resultDto.Actualizar = false;
                    resultDto.Eliminar   = false;
                }


                var requiereAprobacion = await _appDetailQuotesService.RequiereAprobacionAppGeneralQuotesId(generalQuotes.Id);

                if (appStatusQuote.PrimeraEstacion == "X")
                {
                    if (requiereAprobacion)
                    {
                        resultDto.EnviarAlCliente = false;
                    }
                    else
                    {
                        resultDto.EnviarAlCliente = true;
                    }
                }
                else
                {
                    resultDto.EnviarAlCliente = false;
                }


                resultDto.EnviarAprobacionPrecio = false;



                var existe = await _unitOfWork.AppDetailQuotesRepository.ExisteEnEspera(AppGeneralQuotesId);

                resultDto.GanarPerder = existe;


                if (!requiereAprobacion)
                {
                    resultDto.Imprimir = true;
                }
            }
            else
            {
                resultDto.ExistQuotes = false;
            }


            return(resultDto);
        }