Exemple #1
0
        public JsonResult FindTransactionsDeath(SearchViewModel model)
        {
            var result    = new List <ApprovalDeathModel>();
            int?conceptId = ConceptService.GetConceptByCode(((int)PaymentConceptEnum.Muerte).ToString()).ConceptId;

            var allowReversar = this.PermissionService.IsFunctionalityAllowed("GestionarAprobaciones.Reversar");
            var allowAprobar  = this.PermissionService.IsFunctionalityAllowed("GestionarAprobaciones.Aprobar");
            var allowRechazar = this.PermissionService.IsFunctionalityAllowed("GestionarAprobaciones.Rechazar");
            var allowCancelar = this.PermissionService.IsFunctionalityAllowed("GestionarAprobaciones.Cancelar");
            var allowEditar   = this.PermissionService.IsFunctionalityAllowed("GestionarAprobaciones.Editar");

            var payments = PaymentService.FindPaymentsToApprove(model.EBTNumber, model.CaseNumber, model.EntityName,
                                                                model.SocialSecurityNumber, model.BirthDate, model.FilingDate, model.RegionId, model.DispensaryId,
                                                                model.From, model.To, model.StatusId, conceptId).Where(p => p.Transaction.IsNull());
            var groupsCaseIds = payments.DistinctBy(p => p.CaseId);

            foreach (var parent in groupsCaseIds)
            {
                if (parent.CaseId == null)
                {
                    continue;
                }
                var casedetail    = CaseService.FindCaseDetailByIdAndKey(parent.CaseId.Value, parent.CaseKey);
                var lesionado     = EntityService.GetById(casedetail.EntityId.Value);
                var groupPayments = payments.Where(x => x.CaseId != null && x.CaseId.Value == casedetail.CaseId);
                var transaction   = TransactionService.FindTransactionById(parent.TransactionId.Value);

                if (casedetail.CaseId == null)
                {
                    continue;
                }
                var approvalDeath = new ApprovalDeathModel
                {
                    CaseId        = casedetail.CaseId.Value,
                    CaseDetailId  = casedetail.CaseDetailId,
                    CaseNumber    = casedetail.CaseNumber,
                    Lesionado     = lesionado != null ? lesionado.FullName : string.Empty,
                    Ssn           = lesionado != null ? lesionado.SSN : string.Empty,
                    FechaDecision = transaction != null && transaction.DecisionDate != null?
                                    transaction.DecisionDate.ToShortDateString() : string.Empty,
                                        FechaDefuncion = lesionado != null && lesionado.DeceaseDate != null?
                                                         lesionado.DeceaseDate.ToShortDateString() : string.Empty,
                                                             AllowAprobar  = true,
                                                             AllowCancelar = true,
                                                             AllowEditar   = true,
                                                             AllowRechazar = true,
                                                             AllowReversar = true
                };

                foreach (var child in groupPayments)
                {
                    if (child.CaseId == null)
                    {
                        continue;
                    }
                    if (child.CaseDetailId == null)
                    {
                        continue;
                    }
                    if (child.StatusId == null)
                    {
                        continue;
                    }
                    if (child.Amount != null)
                    {
                        var payment = PaymentService.FindPaymentById(child.PaymentId);
                        var entidad = EntityService.GetById(payment.CaseDetail.EntityId.Value);
                        var rel     = RelationshipTypeService.GetRelationshipTypes().
                                      Where(m => m.RelationshipCategoryId == child.CaseDetail.RelationshipTypeId).FirstOrDefault();
                        approvalDeath.Beneficiarios.Add(new ApprovalDeathBeneficiariesModel
                        {
                            CaseId       = child.CaseId.Value,
                            CaseDetailId = child.CaseDetailId.Value,
                            CaseNumber   = string.Format("{0} {1}", child.CaseNumber, child.CaseDetail != null ?
                                                         child.CaseDetail.CaseKey : string.Empty),
                            TransactionId         = child.TransactionId != null ? child.TransactionId.Value : 0,
                            Beneficiario          = entidad.FullName,
                            Ssn                   = entidad.SSN,
                            FechaNacimiento       = entidad.BirthDate.ToShortDateString(),
                            Relacion              = rel.RelationshipType1,
                            Estudiante            = entidad.IsStudying != null && entidad.IsStudying.Value ? "Si" : "No",
                            Tutor                 = string.Empty,
                            PagoInicial           = child.Amount.Value.ToCurrency(),
                            Reserva               = child.CaseDetail.Reserve.ToCurrency(),
                            Mensualidad           = child.CaseDetail.MonthlyInstallment.ToCurrency(),
                            MensualidadesVencidas = (child.Amount / child.CaseDetail.MonthlyInstallment).ToString(),
                            TotalAPagar           = child.Amount.ToCurrency(),
                            Estatus               = child.Status.Status1,
                            EstatusId             = child.StatusId.Value
                        });
                    }
                }
                result.Add(approvalDeath);
            }
            return(JsonDataTable(result));
        }
        //Process client side data and updates demographic data in the database.
        public JsonResult Edit(DemographicViewModel demographic)
        {
            if (demographic.CaseDetail != null)
            {
                var caseDetail = CaseService.FindCaseDetailById(demographic.CaseDetailId);
                if (caseDetail != null)
                {
                    if (caseDetail.CaseKey != "00")
                    {
                        var relationship = RelationshipTypeService.GetRelationshipTypes()
                                           .Where(x => x.RelationshipType1 == demographic.Relationship &&
                                                  x.WidowCertification == demographic.CaseDetail.Entity.HasWidowCertification)
                                           .FirstOrDefault();

                        caseDetail.RelationshipType   = relationship;
                        caseDetail.RelationshipTypeId = relationship.RelationshipTypeId;
                    }

                    #region Entity Information
                    Entity entity = new Entity();
                    if (!demographic.InsertNewEntity)
                    {
                        entity = EntityService.GetById(Convert.ToInt32(caseDetail.EntityId_Sic));
                    }

                    entity.FirstName  = demographic.CaseDetail.Entity.FirstName.Trim();
                    entity.MiddleName = demographic.CaseDetail.Entity.MiddleName != null?demographic.CaseDetail.Entity.MiddleName.Trim() : null;

                    entity.LastName       = demographic.CaseDetail.Entity.LastName.Trim();
                    entity.SecondLastName = demographic.CaseDetail.Entity.SecondLastName != null?demographic.CaseDetail.Entity.SecondLastName.Trim() : null;

                    entity.FullName = string.Concat(
                        entity.FirstName + " ",
                        entity.MiddleName.IsNullOrEmpty() ? String.Empty : entity.MiddleName + " ",
                        entity.LastName + "  ",
                        entity.SecondLastName.IsNullOrEmpty() ? String.Empty : entity.SecondLastName + " ");

                    entity.CaseNumber             = demographic.CaseDetail.CaseNumber;
                    entity.CaseKey                = demographic.CaseDetail.CaseKey;
                    entity.SSN                    = demographic.CaseDetail.Entity.SSN;
                    entity.IDNumber               = demographic.CaseDetail.Entity.IDNumber;
                    entity.BirthDate              = demographic.CaseDetail.Entity.BirthDate;
                    entity.DeceaseDate            = demographic.CaseDetail.Entity.DeceaseDate;
                    entity.MarriageDate           = demographic.CaseDetail.Entity.MarriageDate;
                    entity.CivilStatusId          = demographic.CaseDetail.Entity.CivilStatusId;
                    entity.IsStudying             = demographic.CaseDetail.Entity.IsStudying;
                    entity.SchoolStartDate        = demographic.CaseDetail.Entity.SchoolStartDate;
                    entity.SchoolEndDate          = demographic.CaseDetail.Entity.SchoolEndDate;
                    entity.HasDisability          = demographic.CaseDetail.Entity.HasDisability;
                    entity.OccupationId           = demographic.CaseDetail.Entity.OccupationId;
                    entity.MonthlyIncome          = demographic.CaseDetail.Entity.MonthlyIncome;
                    entity.IsRehabilitated        = demographic.CaseDetail.Entity.IsRehabilitated;
                    entity.IsWorking              = demographic.CaseDetail.Entity.IsWorking;
                    entity.IsEmancipated          = demographic.CaseDetail.Entity.IsEmancipated;
                    entity.HasWidowCertification  = demographic.CaseDetail.Entity.HasWidowCertification;
                    entity.WidowCertificationDate = demographic.CaseDetail.Entity.WidowCertificationDate;
                    entity.ModifiedReasonId       = demographic.CaseDetail.Entity.ModifiedReasonId;
                    entity.OtherModifiedReason    = demographic.CaseDetail.Entity.OtherModifiedReason;
                    entity.Comments               = demographic.CaseDetail.Entity.Comments;
                    entity.Email                  = demographic.CaseDetail.Entity.Email;
                    entity.HomePhoneNumber        = demographic.CaseDetail.Entity.HomePhoneNumber;
                    entity.CellPhoneNumber        = demographic.CaseDetail.Entity.CellPhoneNumber;
                    entity.WorkPhoneNumber        = demographic.CaseDetail.Entity.WorkPhoneNumber;
                    entity.FaxPhoneNumber         = demographic.CaseDetail.Entity.FaxPhoneNumber;
                    entity.OtherPhoneNumber       = demographic.CaseDetail.Entity.OtherPhoneNumber;

                    entity.ModifiedBy       = WebHelper.GetUserName();
                    entity.ModifiedDateTime = DateTime.Now;
                    #endregion

                    #region Address Information
                    if (demographic.PostalAddress != null)
                    {
                        Address PostalAddress = demographic.PostalAddress;

                        //Verificar una manera de traer toda la informaicon de coutry / state a traves de ciudad.
                        var    city  = LocationService.GetAllCities().Where(x => x.CityId == demographic.PostalAddress.CityId).FirstOrDefault();
                        string state = "";
                        if (demographic.PostalAddress.StateId != null)
                        {
                            var state1 = LocationService.GetAllStates().Where(x => x.StateId == demographic.PostalAddress.StateId).FirstOrDefault();
                            state = state1.State1;
                        }
                        var country = LocationService.GetAllCountries().Where(x => x.CountryId == demographic.PostalAddress.CountryId).FirstOrDefault();

                        PostalAddress.FullAddress =
                            demographic.PostalAddress.Line1
                            + (demographic.PostalAddress.Line2.IsNullOrEmpty() ? "" : " " + demographic.PostalAddress.Line2.Trim())
                            + (demographic.PostalAddress.CityId == null ? "" : city.City1 != "Otro" ? " " + city.City1 : " " + demographic.PostalAddress.OtherCity)
                            + (demographic.PostalAddress.StateId == null ? "" : ", " + state)
                            + (demographic.PostalAddress.CountryId == null ? "" : ", " + country.Country1)
                            + (demographic.PostalAddress.ZipCode == null ? "" : " " + demographic.PostalAddress.ZipCode)
                            + (demographic.PostalAddress.ZipCodeExt == null ? "" : "-" + demographic.PostalAddress.ZipCodeExt);
                        PostalAddress.AddressTypeId    = AddressTypeService.GetAddressTypes().Where(x => x.AddressType1 == "Postal").Select(x => x.AddressTypeId).FirstOrDefault();
                        PostalAddress.SourceId         = 8;
                        PostalAddress.ModifiedBy       = WebHelper.GetUserName();
                        PostalAddress.ModifiedDateTime = DateTime.Now;

                        if (!demographic.HasAddress)
                        {
                            PostalAddress.CreatedBy       = WebHelper.GetUserName();
                            PostalAddress.CreatedDateTime = DateTime.Now;
                            entity.Addresses.Add(PostalAddress);
                        }
                        else
                        {
                            foreach (var a in demographic.CaseDetail.Entity.Addresses)
                            {
                                if (a.AddressType.AddressType1 == "Postal" && a.AddressId == demographic.PostalAddress.AddressId)
                                {
                                    a.Line1       = demographic.PostalAddress.Line1;
                                    a.Line2       = demographic.PostalAddress.Line2;
                                    a.CityId      = demographic.PostalAddress.CityId;
                                    a.OtherCity   = demographic.PostalAddress.OtherCity;
                                    a.StateId     = demographic.PostalAddress.StateId;
                                    a.CountryId   = demographic.PostalAddress.CountryId;
                                    a.ZipCode     = demographic.PostalAddress.ZipCode;
                                    a.ZipCodeExt  = demographic.PostalAddress.ZipCodeExt;
                                    a.FullAddress = demographic.PostalAddress.FullAddress;
                                    a.EntityId    = demographic.PostalAddress.EntityId;
                                }
                            }
                        }
                    }
                    #endregion

                    //#region Phone Information

                    //#endregion

                    if (demographic.InsertNewEntity)
                    {
                        entity.SourceId        = 8; //SourceId = Entity Sic Source
                        entity.CreatedBy       = WebHelper.GetUserName();
                        entity.CreatedDateTime = DateTime.Now;
                        try
                        {
                            EntityService.CreateEntity(entity);
                        }
                        catch
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        try
                        {
                            EntityService.ModifyEntity(entity);
                        }
                        catch
                        {
                            throw new Exception();
                        }
                    }

                    caseDetail.Entity       = entity;
                    caseDetail.EntitySic    = entity;
                    caseDetail.EntityId     = entity.EntityId;
                    caseDetail.EntityId_Sic = entity.EntityId;

                    try
                    {
                        CaseService.UpdateCaseDetail(caseDetail);
                    }
                    catch
                    {
                        EntityService.Delete(entity.EntityId);
                        throw new Exception();
                    }

                    return(Json(new { Data = demographic.CaseDetail }));
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                throw new Exception();
            }
        }