Пример #1
0
        public int ProcessBillingUnpaidInvoice(string fileName)
        {
            // accepted
            List <BillingAcceptedViewModel> acceptedInvoices = ReadBillingUnpaidAcceptedFile(fileName).ToList();
            AutoNumberProvider autoNumberProvider            = new AutoNumberProvider(ctx);

            foreach (BillingAcceptedViewModel acceptedInvoice in acceptedInvoices)
            {
                InvoiceHeader invoice = ctx.InvoiceHeaders.SingleOrDefault(ih => ih.InvoiceNo == acceptedInvoice.InvoiceNo);
                Customer      cust    = invoice.Customer;
                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: " + acceptedInvoice.DeclineCode;
                    }

                    string paymentNo = autoNumberProvider.Generate(invoice.BranchID, "PM", DateTime.Today.Month, DateTime.Today.Year);

                    PaymentHeader h = new PaymentHeader();
                    h.Date      = DateTime.Today;
                    h.InvoiceID = invoice.ID;
                    h.PaymentNo = paymentNo;
                    h.VoidDate  = (DateTime?)null;
                    EntityHelper.SetAuditFieldForInsert(h, HttpContext.Current.User.Identity.Name);

                    PaymentDetail d = new PaymentDetail();
                    d.CreditCardTypeID = cust.CreditCardTypeID;
                    d.PaymentTypeID    = 4; // credit  card
                    d.Amount           = invoice.InvoiceDetails.Sum(inv => (inv.Quantity * inv.UnitPrice) - (inv.Discount / 100 * (inv.Quantity * inv.UnitPrice)));
                    d.ApprovalCode     = acceptedInvoice.VerificationCode;
                    h.PaymentDetails.Add(d);
                    ctx.PaymentHeaders.InsertOnSubmit(h);

                    autoNumberProvider.Increment("PM", invoice.BranchID, DateTime.Today.Year);

                    CustomerStatusHistory status = new CustomerStatusHistory();
                    status.Customer         = invoice.Customer;
                    status.Date             = DateTime.Today;
                    status.CustomerStatusID = 1; // OK
                    status.Notes            = "AUTO PAY ACCEPTED FOR INVOICE " + invoice.InvoiceNo;
                    status.StartDate        = DateTime.Today;
                    EntityHelper.SetAuditFieldForInsert(status, HttpContext.Current.User.Identity.Name);
                }
            }

            ctx.SubmitChanges();

            return(acceptedInvoices.Count);
        }
Пример #2
0
        public void Add(
            DateTime date,
            bool useExistingBarcode,
            string barcode,
            bool isTransfer,
            string firstName,
            string LastName,
            DateTime dateOfBirth,
            int branchID,
            int packageID,
            DateTime?purchaseDate,
            DateTime effectiveDate,
            int billingTypeID,
            int billingCardTypeID,
            int billingBankID,
            string billingCardNo,
            string billingCardHolderName,
            string billingCardHolderID,
            DateTime cardExpiredDate,
            char status,
            int billingItemID,
            decimal duesAmount,
            DateTime?nextDuesDate,
            DateTime expiredDate,
            string homePhone,
            string cellphone,
            string mailingAddress,
            string zipCodeMailingAddress,
            string address,
            string zipCode,
            int areaID,
            int schoolID,
            bool fatherIsExist,
            string fatherName,
            string fatherIDCardNo,
            DateTime?fatherBirthDate,
            string fatherCellPhone,
            string fatherEmail,
            bool motherIsExist,
            string motherName,
            string motherIDCardNo,
            DateTime?motherBirthDate,
            string motherCellPhone,
            string motherEmail,
            string notes,
            string contractType)
        {
            PackageHeader package = ctx.PackageHeaders.SingleOrDefault(pkg => pkg.ID == packageID);

            if (package != null)
            {
                //nextDuesDate = effectiveDate.AddMonths(package.PackageDuesInMonth);
                Customer cust = null;
                if (useExistingBarcode)
                {
                    cust = ctx.Customers.Single(c => c.Barcode == barcode);
                }
                else
                {
                    cust                = new Customer();
                    cust.Barcode        = autoNumberProvider.Generate(branchID, "CU", 0, 0);
                    cust.FirstName      = firstName;
                    cust.LastName       = LastName;
                    cust.DateOfBirth    = dateOfBirth;
                    cust.HomeBranchID   = branchID;
                    cust.HomePhone      = homePhone;
                    cust.CellPhone1     = cellphone;
                    cust.BillingTypeID  = billingTypeID;
                    cust.AreaID         = areaID == 0 ? (int?)null : areaID;
                    cust.SchoolID       = schoolID == 0 ? (int?)null : schoolID;
                    cust.MailingAddress = mailingAddress;
                    cust.MailingZipCode = zipCodeMailingAddress;
                    cust.Address        = address;
                    cust.ZipCode        = zipCode;
                    if (billingTypeID != 1) // auto payment
                    {
                        cust.BankID           = billingBankID;
                        cust.CreditCardTypeID = billingCardTypeID;
                        cust.CardHolderName   = billingCardHolderName;
                        cust.CardHolderID     = billingCardHolderID;
                        cust.CardNo           = billingCardNo;
                        cust.ExpiredDate      = cardExpiredDate;
                    }
                    else
                    {
                        cust.BankID           = (int?)null;
                        cust.CreditCardTypeID = (int?)null;
                        cust.CardHolderName   = null;
                        cust.CardHolderID     = null;
                        cust.CardNo           = null;
                        cust.ExpiredDate      = (DateTime?)null;
                    }
                    EntityHelper.SetAuditFieldForInsert(cust, HttpContext.Current.User.Identity.Name);
                    ctx.Customers.InsertOnSubmit(cust);

                    autoNumberProvider.Increment("CU", branchID, 0);
                }

                Contract contract = new Contract();
                contract.ContractNo    = autoNumberProvider.Generate(branchID, "CO", date.Month, date.Year);
                contract.Date          = date;
                contract.Customer      = cust;
                contract.BranchID      = branchID;
                contract.PackageHeader = package;
                //contract.PurchaseDate = purchaseDate;
                contract.EffectiveDate = effectiveDate;
                contract.BillingItemID = billingItemID == 0 ? (int?)null : billingItemID;
                contract.DuesAmount    = duesAmount;
                contract.NextDuesDate  = nextDuesDate.Value;
                //contract.ExpiredDate = expiredDate;
                contract.ExpiredDate   = effectiveDate.AddMonths(package.PackageDuesInMonth);
                contract.BillingTypeID = billingTypeID;
                contract.Status        = status.ToString();
                contract.Notes         = notes;
                contract.DuesInMonth   = package.PackageDuesInMonth;
                if (isTransfer)
                {
                    contract.ContractType = "T";
                }
                else
                {
                    contract.ContractType = useExistingBarcode ? contractType : null;
                }
                EntityHelper.SetAuditFieldForInsert(contract, HttpContext.Current.User.Identity.Name);
                ctx.Contracts.InsertOnSubmit(contract);


                if (!useExistingBarcode)
                {
                    if (fatherIsExist)
                    {
                        Person person = new Person();
                        person.Connection = "F";
                        person.Name       = fatherName;
                        person.IDCardNo   = fatherIDCardNo;
                        person.Phone1     = fatherCellPhone;
                        person.BirthDate  = fatherBirthDate;
                        person.Email      = fatherEmail;
                        person.Customer   = cust;
                        EntityHelper.SetAuditFieldForInsert(person, HttpContext.Current.User.Identity.Name);
                        ctx.Persons.InsertOnSubmit(person);
                    }

                    if (motherIsExist)
                    {
                        Person person = new Person();
                        person.Connection = "M";
                        person.Name       = motherName;
                        person.IDCardNo   = motherIDCardNo;
                        person.Phone1     = motherCellPhone;
                        person.BirthDate  = motherBirthDate;
                        person.Email      = motherEmail;
                        person.Customer   = cust;
                        EntityHelper.SetAuditFieldForInsert(person, HttpContext.Current.User.Identity.Name);
                        ctx.Persons.InsertOnSubmit(person);
                    }
                }

                autoNumberProvider.Increment("CO", branchID, date.Year);
                ctx.SubmitChanges();
            }
        }
Пример #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>();
            InvoiceProvider         invoiceProvider    = new InvoiceProvider(ctx);
            AutoNumberProvider      autoNumberProvider = new AutoNumberProvider(ctx);
            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      = ctx.Employees.Single(emp => emp.ID == processedByEmployeeID).UserName;
            billingHeader.ProcessDate   = processDate;
            billingHeader.FileName      = billingFileName;

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

                    PaymentDetailViewModel paymentDetail = new PaymentDetailViewModel();
                    paymentDetail.PaymentTypeID    = ctx.PaymentTypes.SingleOrDefault(p => p.Description == "Credit Card").ID;
                    paymentDetail.CreditCardTypeID = customer.CreditCardTypeID.HasValue ? customer.CreditCardTypeID.Value : ctx.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
                    });


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

                    ctx.BillingHeaders.InsertOnSubmit(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);
            ctx.SubmitChanges();

            return(list);
        }