Beispiel #1
0
        /// <summary>
        /// Returns false if application cannot be finalized due to all forms not being
        /// submitted
        /// </summary>
        /// <returns></returns>
        public virtual bool SubmitAndFinalize()
        {
            // There can be no unassigned forms
            foreach (var form in GetOrderedForms())
            {
                if (form.IsRequired && !form.IsAssigned)
                {
                    return(false);
                }
            }
            bool isIncomplete = HasStatus(EApplicationStatus.DeemedIncomplete);

            // There can be no warnings within the review. Also the application cannot be any step past submitted or resubmitted
            if (Review().Count > 0 ||
                (!isIncomplete ? CurrentStatusLog.Status > EApplicationStatus.Submitted : CurrentStatusLog.Status >= EApplicationStatus.Resubmitted))
            {
                return(false);
            }
            foreach (var form in GetOrderedForms())
            {
                if (form is SignatureForm)
                {
                    ((SignatureForm)form).Signatures.ForEach(x => x.IsSignatureFinalized = true);
                }
            }
            StatusHistory.Add(ApplicationStatusLogItem.FactoryCreate(isIncomplete ? EApplicationStatus.Resubmitted : EApplicationStatus.Submitted));
            CanEdit = false;
            return(true);
        }
        public ActionResult ApplicationDeemedSubmittable(int id)
        {
            var application = _context.Applications.FirstOrDefault(x => x.Id == id);

            if (application == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            application.StatusHistory.Add(ApplicationStatusLogItem.FactoryCreate(EApplicationStatus.DeemedSubmittable));
            GenerateInvoice(application, EInvoicePurpose.MapReviewFee);
            _context.SaveChanges();

            return(RedirectToAction("Submitted", new { id = id }));
        }
        public ActionResult CheckInvoice(int id)
        {
            var invoice = _context.Invoices.Where(x => x.Id == id).Include(x => x.PaymentForm).FirstOrDefault();

            if (invoice == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            if (!invoice.Paid)
            {
                var aid         = invoice.PaymentForm.ApplicationId;
                var application = _context.Applications.Where(x => x.Id == aid)
                                  .Include(x => x.StatusHistory)
                                  .Include(x => x.Applicants)
                                  .Include(x => x.ProjectInfo)
                                  .FirstOrDefault();
                var applicant = GetCurrentApplicant();
                if (application == null)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                if (!User.IsInRole(EUserRoles.Admin) && !User.IsInRole(EUserRoles.Bsm))
                {
                    // Ensure that an applicant is looking at their invoice & not somebody else's
                    if (application.Applicants.All(x => x.Id != applicant.Id))
                    {
                        throw new HttpResponseException(HttpStatusCode.BadRequest);
                    }
                }
                // Verify Payment
                var invoiceRead =
                    new ReadInvoiceXml(PaymentGatewaySoapHelper.CallWebService(new ReadInvoiceEnvelope(invoice.InvoiceNo)));

                invoice.Paid = invoiceRead.IsPaid && !invoiceRead.Voided;
                invoice.Void = invoiceRead.Voided;

                if (invoice.Paid)
                {
                    EApplicationStatus status;
                    if (invoice.InvoicePurpose == EInvoicePurpose.InitialPayment)
                    {
                        status = EApplicationStatus.InitialPaymentReceived;
                    }
                    else if (invoice.InvoicePurpose == EInvoicePurpose.IncompleteFee)
                    {
                        status = EApplicationStatus.IncompleteFeeReceived;
                    }
                    else if (invoice.InvoicePurpose == EInvoicePurpose.MapReviewFee)
                    {
                        status = EApplicationStatus.MapReviewFeeReceived;
                    }
                    else
                    {
                        throw new NotSupportedException(EnumHelper <EInvoicePurpose> .GetDisplayValue(invoice.InvoicePurpose));
                    }
                    application.StatusHistory.Add(ApplicationStatusLogItem.FactoryCreate(status));
                }
                _context.SaveChanges();
            }
            return(Json(new { paid = invoice.Paid, voided = invoice.Void, success = invoice.Paid || invoice.Void }));
        }