コード例 #1
0
ファイル: SoaController.cs プロジェクト: murugan-project/ims
        public ActionResult Edit(SoaModel model)
        {
            try
            {
                var invoiceList = Uow.Invoices.GetAll()
                                  .Where(i => i.Policy.ClientId == model.ClientId)
                                  .Where(i => i.Policy.InsuranceProviderId == model.InsuranceProviderId)
                                  .Where(i => i.Status.Name.ToLower() == "unpaid")
                                  .Where(i => i.IssueDate < model.IssueDate)
                                  .ToList();

                var tmpEntity = Uow.Soas.GetById(model.Id);

                // amount can only be recomputed if unpaid
                model.StatusName = AttributeProviderSvc.GetSoaStatusNameFromId(model.StatusId);

                if (model.StatusName.ToLower() == "unpaid")
                {
                    model.TotalAmountDue = invoiceList.Select(i => i.TotalAmountDue).Sum();
                }
                else
                {
                    model.TotalAmountDue = tmpEntity.TotalAmountDue;
                }

                Uow.Soas.Detach(tmpEntity);

                var entity = AutoMapper.Mapper.Map <Soa>(model);

                // EDWIN
                entity.StartDate = tmpEntity.StartDate;
                // EDWIN END

                Uow.Soas.Update(entity);

                LogEdit(entity);

                // if SOA is marked as paid, mark corresponding invoices as paid as well
                if (model.StatusName.ToLower() == "paid")
                {
                    foreach (var invoice in invoiceList)
                    {
                        invoice.StatusId = AttributeProviderSvc.GetInvoiceStatusIdFromName("paid");
                        invoice.PaidDate = DateTime.Now;
                        Uow.Invoices.Update(invoice);
                        LogInvoiceEdit(invoice);
                    }
                }

                Uow.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", new { error = "Something went wrong!" }));
            }
        }
コード例 #2
0
        // POST: api/SoaApi
        public HttpResponseMessage Post([FromBody] SoaModel model)
        {
            try
            {
                var prevSoa = Uow.Soas.GetAll()
                              .Where(s => s.ClientId == model.ClientId &&
                                     s.InsuranceProviderId == model.InsuranceProviderId &&
                                     s.Status.Name.ToLower() == "unpaid")
                              .FirstOrDefault();
                if (prevSoa != null)
                {
                    prevSoa.StatusId = AttributeProviderSvc.GetSoaStatusIdFromName("closed");
                    Uow.Soas.Update(prevSoa);
                    //Uow.SaveChanges();
                    LogEdit(prevSoa);
                }

                // To include time in Issue Date for checking against Invoice list
                DateTime dateTimeNow = DateTime.Now;
                if ((model.IssueDate.Year == dateTimeNow.Year) &&
                    (model.IssueDate.Month == dateTimeNow.Month) &&
                    (model.IssueDate.Day == dateTimeNow.Day))
                {
                    model.IssueDate = dateTimeNow;
                }

                // EDWIN
                var list = Uow.Invoices.GetAll()
                           .Where(i => i.Policy.ClientId == model.ClientId &&
                                  i.Policy.InsuranceProviderId == model.InsuranceProviderId &&
                                  i.Status.Name.ToLower() == "unpaid" &&
                                  i.IssueDate < model.IssueDate)
                           .OrderBy(i => i.IssueDate)
                           .Select(i => new { TotalAmountDue = i.TotalAmountDue, InvoiceIssueDate = i.IssueDate })
                           .ToList();
                model.TotalAmountDue = list.Sum(i => i.TotalAmountDue);

                if (model.TotalAmountDue <= 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, new { errorMessage = "Unable to create SOA record; Invoice not yet approved or sent to client" }));
                }
                // EDWIN END

                model.StatusId = AttributeProviderSvc.GetSoaStatusIdFromName("unpaid");

                var entity = AutoMapper.Mapper.Map <Soa>(model);
                // EDWIN
                var firstInvoice = list.FirstOrDefault();
                if (firstInvoice != null)
                {
                    entity.StartDate = firstInvoice.InvoiceIssueDate;
                }
                else
                {
                    entity.StartDate = DateTime.Now;
                }
                // EDWIN END

                Uow.Soas.Add(entity);
                Uow.SaveChanges();

                LogAdd(entity);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
コード例 #3
0
ファイル: SoaController.cs プロジェクト: murugan-project/ims
        private SoaModel PrepareViewModel(SoaModel vm)
        {
            // EDWIN
            var soaEntity = Uow.Soas.GetAll()
                            .Where(s => s.Id == vm.Id)
                            .Include(s => s.Status)
                            .FirstOrDefault();
            List <SoaTableEntry> entriesAll;
            DateTime             startDate = soaEntity.StartDate.AddMinutes(-1);

            // EDWIN END
            if (soaEntity.Status.Name.ToLower() == "paid")
            {
                entriesAll = Uow.Invoices.GetAll()
                             .Where(i => i.Policy.ClientId == vm.ClientId)
                             .Where(i => i.Policy.InsuranceProviderId == vm.InsuranceProviderId)
                             .Where(i => i.Status.Name.ToLower() == "paid")
                             .Where(i => i.IssueDate >= startDate && i.IssueDate < soaEntity.IssueDate)
                             .ProjectTo <SoaTableEntry>()
                             .ToList();
            }
            else
            {
                entriesAll = Uow.Invoices.GetAll()
                             .Where(i => i.Policy.ClientId == vm.ClientId)
                             .Where(i => i.Policy.InsuranceProviderId == vm.InsuranceProviderId)
                             .Where(i => i.Status.Name.ToLower() == "unpaid")
                             .Where(i => i.IssueDate >= startDate && i.IssueDate < soaEntity.IssueDate)
                             .ProjectTo <SoaTableEntry>()
                             .ToList();
            }
            foreach (var entry in entriesAll)
            {
                entry.Ewt       = entry.Total * 0.02M;
                entry.AmountDue = entry.Total + entry.Ewt;
            }

            var policyTypeList = Uow.PolicyTypes.GetAll().ToList();
            var soaGroupList   = new List <SoaGroupedByType>();

            foreach (var policyType in policyTypeList)
            {
                var entriesPerType = entriesAll
                                     .Where(sEntry => sEntry.PolicyTypeId == policyType.Id)
                                     .ToList();
                soaGroupList.Add(new SoaGroupedByType
                {
                    PolicyTypeName  = policyType.Name,
                    SoaTableEntries = entriesPerType,
                    PremiumSum      = entriesPerType.Select(e => e.Premium).Sum(),
                    TaxSum          = entriesPerType.Select(e => e.Tax).Sum(),
                    TotalSum        = entriesPerType.Select(e => e.Total).Sum(),
                    EwtSum          = entriesPerType.Select(e => e.Ewt).Sum(),
                    AmountDueSum    = entriesPerType.Select(e => e.AmountDue).Sum()
                });
            }

            vm.SoaGroups             = soaGroupList;
            vm.TotalAmountDueWithEwt = entriesAll.Select(a => a.AmountDue).Sum();
            if (vm.IsOrganization)
            {
                vm.ClientName = vm.OrganizationName;
            }

            return(vm);
        }
コード例 #4
0
ファイル: SoaController.cs プロジェクト: murugan-project/ims
        public ActionResult Create(SoaModel model)
        {
            try
            {
                var prevSoa = Uow.Soas.GetAll()
                              .Where(s => s.ClientId == model.ClientId &&
                                     s.InsuranceProviderId == model.InsuranceProviderId &&
                                     s.Status.Name.ToLower() == "unpaid")
                              .FirstOrDefault();
                if (prevSoa != null)
                {
                    prevSoa.StatusId = AttributeProviderSvc.GetSoaStatusIdFromName("closed");
                    Uow.Soas.Update(prevSoa);
                    Uow.SaveChanges();
                    LogEdit(prevSoa);
                }

                // To include time in Issue Date for checking against Invoice list
                DateTime dateTimeNow = DateTime.Now;
                if ((model.IssueDate.Year == dateTimeNow.Year) &&
                    (model.IssueDate.Month == dateTimeNow.Month) &&
                    (model.IssueDate.Day == dateTimeNow.Day))
                {
                    model.IssueDate = dateTimeNow;
                }

                // EDWIN
                var list = Uow.Invoices.GetAll()
                           .Where(i => i.Policy.ClientId == model.ClientId &&
                                  i.Policy.InsuranceProviderId == model.InsuranceProviderId &&
                                  i.Status.Name.ToLower() == "unpaid" &&
                                  i.IssueDate < model.IssueDate)
                           .OrderBy(i => i.IssueDate)
                           .Select(i => new { TotalAmountDue = i.TotalAmountDue, InvoiceIssueDate = i.IssueDate })
                           .ToList();
                model.TotalAmountDue = list.Sum(i => i.TotalAmountDue);
                // EDWIN END

                model.StatusId = AttributeProviderSvc.GetSoaStatusIdFromName("unpaid");

                var entity = AutoMapper.Mapper.Map <Soa>(model);
                // EDWIN
                var firstInvoice = list.FirstOrDefault();
                if (firstInvoice != null)
                {
                    entity.StartDate = firstInvoice.InvoiceIssueDate;
                }
                else
                {
                    entity.StartDate = DateTime.Now;
                }
                // EDWIN END

                Uow.Soas.Add(entity);
                Uow.SaveChanges();

                LogAdd(entity);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", new { error = ex.Message }));
            }
        }