示例#1
0
        public int ProcessBillingResult(string batchNo, string fileName)
        {
            List <BillingRejectionViewModel> rejections = ReadBillingResultFile(fileName).ToList();

            foreach (BillingRejectionViewModel rejection in rejections)
            {
                InvoiceHeader invoice = context.InvoiceHeaders.SingleOrDefault(ih => ih.InvoiceNo == rejection.InvoiceNo && !ih.VoidDate.HasValue);
                if (invoice != null)
                {
                    var payments = invoice.PaymentHeaders.Where(ph => !ph.VoidDate.HasValue);
                    foreach (var payment in payments)
                    {
                        payment.VoidDate   = DateTime.Today;
                        payment.VoidReason = "AUTO PAY DECLINED: " + rejection.DeclineCode;
                    }

                    var status = new CustomerStatusHistory();
                    status.Customer         = invoice.Customer;
                    status.Date             = DateTime.Today;
                    status.CustomerStatusID = 4; // billing problem
                    status.Notes            = "AUTO PAY DECLINED OF INVOICE " + invoice.InvoiceNo + ", REJECTION CODE: " + rejection.DeclineCode;
                    status.StartDate        = DateTime.Today;
                    EntityHelper.SetAuditFieldForInsert(status, principal.Identity.Name);
                }
            }

            BillingHeader billing = context.BillingHeaders.SingleOrDefault(b => b.BatchNo == batchNo);

            if (billing != null)
            {
                billing.ResultProcessDate = DateTime.Now;
                foreach (var detail in billing.BillingDetails)
                {
                    var rejection =
                        rejections.SingleOrDefault(reject => reject.InvoiceNo == detail.InvoiceHeader.InvoiceNo);
                    if (rejection != null)
                    {
                        detail.BillingResult = rejection.DeclineCode;
                    }
                }
            }

            context.SaveChanges();

            return(rejections.Count);

            //foreach (var billingDetail in billing.BillingDetails)
            //{
            //    InvoiceHeader invoice = billingDetail.InvoiceHeader;
            //    if (invoice != null)
            //    {
            //        PaymentHeader payment = invoice.PaymentHeaders.SingleOrDefault(ph => !ph.VoidDate.HasValue);
            //        if (payment != null)
            //        {
            //            payment.VoidDate = DateTime.Today;
            //            payment.VoidReason = "AUTO PAY DECLINED: " + rejection.DeclineCode;
            //        }
            //    }
            //}
        }
示例#2
0
 protected void gvwMaster_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "ProcessResult")
     {
         mvwForm.ActiveViewIndex = 1;
         string        batchNo = Convert.ToString(e.CommandArgument);
         BillingHeader billing = BillingService.GetBillingInfo(batchNo);
         lblBatchNo.Text     = billing.BatchNo;
         lblBillingType.Text = billing.BillingType.Description;
         lblProcessDate.Text = billing.ProcessDate.ToString("ddd, dd-MMM-yyyy HH:mm");
         lblFileName.Text    = billing.FileName;
     }
 }
示例#3
0
        private IList <BillingViewModel> CreateBillingInvoices(int branchID, int billingTypeID, IEnumerable <BillingViewModel> billings, DateTime processDate, int processedByEmployeeID, string billingFileName)
        {
            List <BillingViewModel> list = new List <BillingViewModel>();
            string autoNumber            = autoNumberProvider.Generate(branchID, "BL", processDate.Month, processDate.Year);

            BillingHeader billingHeader = new BillingHeader();

            billingHeader.BatchNo       = autoNumber;
            billingHeader.BillingTypeID = billingTypeID;
            billingHeader.BranchID      = branchID;
            billingHeader.UserName      = context.Employees.Single(emp => emp.ID == processedByEmployeeID).UserName;
            billingHeader.ProcessDate   = processDate;
            billingHeader.FileName      = billingFileName;

            foreach (BillingViewModel billing in billings)
            {
                Contract      contract = context.Contracts.SingleOrDefault(c => c.ContractNo == billing.ContractNo);
                Customer      customer = contract.Customer;
                Item          item     = context.Items.SingleOrDefault(it => it.ID == contract.BillingItemID.Value);
                PackageHeader package  = contract.PackageHeader;
                if (contract != null && package != null && customer != null && item != null)
                {
                    var invoiceDetail = new InvoiceDetailViewModel();
                    invoiceDetail.InvoiceID = 0;
                    invoiceDetail.ItemID    = contract.BillingItemID.Value;
                    invoiceDetail.Quantity  = 1;
                    invoiceDetail.UnitName  = item.UnitName1;
                    invoiceDetail.UnitPrice = billing.DuesAmount;
                    invoiceDetail.Discount  = 0;
                    invoiceDetail.IsTaxable = true;

                    var paymentDetail = new PaymentDetailViewModel();
                    paymentDetail.PaymentTypeID    = context.PaymentTypes.SingleOrDefault(p => p.Description == "Credit Card").ID;
                    paymentDetail.CreditCardTypeID = customer.CreditCardTypeID.HasValue ? customer.CreditCardTypeID.Value : context.CreditCardTypes.SingleOrDefault(cc => cc.Description == "Visa").ID;
                    paymentDetail.ApprovalCode     = String.Empty;
                    paymentDetail.Amount           = billing.DuesAmount;
                    paymentDetail.Notes            = "Auto Pay";
                    paymentDetail.PaymentID        = 0;

                    InvoiceHeader invoiceHeader = invoiceProvider.CreateExistingMemberInvoiceForBilling(branchID,
                                                                                                        processDate,
                                                                                                        customer.Barcode,
                                                                                                        processedByEmployeeID,
                                                                                                        "Auto pay " + contract.ContractNo,
                                                                                                        0,
                                                                                                        new List <InvoiceDetailViewModel>()
                    {
                        invoiceDetail
                    },
                                                                                                        new List <PaymentDetailViewModel>()
                    {
                        paymentDetail
                    });


                    var billingDetail = new BillingDetail();
                    billingDetail.Amount        = billing.DuesAmount;
                    billingDetail.Contract      = contract;
                    billingDetail.Customer      = customer;
                    billingDetail.InvoiceHeader = invoiceHeader;
                    billingDetail.PackageHeader = package;
                    billingHeader.BillingDetails.Add(billingDetail);

                    context.Add(billingHeader);

                    billing.Note += "," + invoiceHeader.InvoiceNo;
                    list.Add(billing);
                }

                if (contract.NextDuesDate.HasValue)
                {
                    contract.NextDuesDate = contract.NextDuesDate.Value.AddMonths(contract.DuesInMonth);
                }
            }


            autoNumberProvider.Increment("BL", branchID, processDate.Year);
            context.SaveChanges();

            return(list);
        }