Ejemplo n.º 1
0
        public String insert(BillingDetail p, String userId)
        {
            String re = "", sql = "";

            p.active = "1";
            //p.ssdata_id = "";
            chkNull(p);
            sql = "Insert Into " + blld.table + "(" + blld.expenses_draw_detail_id + "," + blld.billing_id + "," + blld.item_name_t + "," +
                  blld.active + "," + blld.remark + ", " + blld.item_id + ", " +
                  blld.date_create + ", " + blld.date_modi + ", " + blld.date_cancel + ", " +
                  blld.user_create + ", " + blld.user_modi + ", " + blld.user_cancel + "," +
                  blld.amount_draw + "," + blld.amount_income + " " +
                  ") " +
                  "Values ('" + p.expenses_draw_detail_id + "','" + p.billing_id + "','" + p.item_name_t.Replace("'", "''") + "'," +
                  "'" + p.active + "','" + p.remark + "','" + p.item_id + "', " +
                  "now(),'" + p.date_modi + "','" + p.date_cancel + "', " +
                  "'" + userId + "','" + p.user_modi + "','" + p.user_cancel + "'," +
                  "'" + p.amount_draw + "','" + p.amount_income + "' " +
                  ")";

            try
            {
                re = conn.ExecuteNonQuery(conn.conn, sql);
            }
            catch (Exception ex)
            {
                sql = ex.Message + " " + ex.InnerException;
            }
            return(re);
        }
Ejemplo n.º 2
0
        public BillingDetail setBillingDetail(DataTable dt)
        {
            BillingDetail bill1 = new BillingDetail();

            if (dt.Rows.Count > 0)
            {
                bill1.billing_id              = dt.Rows[0][blld.billing_id].ToString();
                bill1.billing_detail_id       = dt.Rows[0][blld.billing_detail_id].ToString();
                bill1.expenses_draw_detail_id = dt.Rows[0][blld.expenses_draw_detail_id].ToString();
                bill1.item_id       = dt.Rows[0][blld.item_id].ToString();
                bill1.item_name_t   = dt.Rows[0][blld.item_name_t].ToString();
                bill1.active        = dt.Rows[0][blld.active].ToString();
                bill1.date_cancel   = dt.Rows[0][blld.date_cancel].ToString();
                bill1.date_create   = dt.Rows[0][blld.date_create].ToString();
                bill1.date_modi     = dt.Rows[0][blld.date_modi].ToString();
                bill1.user_cancel   = dt.Rows[0][blld.user_cancel].ToString();
                bill1.user_create   = dt.Rows[0][blld.user_create].ToString();
                bill1.user_modi     = dt.Rows[0][blld.user_modi].ToString();
                bill1.item_name_t   = dt.Rows[0][blld.item_name_t].ToString();
                bill1.remark        = dt.Rows[0][blld.remark].ToString();
                bill1.amount_draw   = dt.Rows[0][blld.amount_draw].ToString();
                bill1.amount_income = dt.Rows[0][blld.amount_income].ToString();
            }

            return(bill1);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage UpdateBillingItem([FromBody] string billDetails, string token)
        {
            if (con.CheckIfTokenValid(token) != 10001 && con.IsUserInternal(token) == 1)
            {
                return(new HttpResponseMessage(HttpStatusCode.Unauthorized));
            }
            try
            {
                BillingDetail UpdateBill = JsonConvert.DeserializeObject <BillingDetail>(billDetails);
                BillingDetail OldBill    = con.BillingDetails.SingleOrDefault(i => i.BillID == UpdateBill.BillID);

                OldBill.BillDate       = UpdateBill.BillDate;
                OldBill.CompletionDate = UpdateBill.CompletionDate;
                OldBill.BillMethod     = UpdateBill.BillMethod;
                OldBill.BillReason     = UpdateBill.BillReason;
                OldBill.BillDuration   = UpdateBill.BillDuration;
                OldBill.DirectContact  = UpdateBill.DirectContact;
                OldBill.Postage        = UpdateBill.Postage;
                OldBill.Courier        = UpdateBill.Courier;
                OldBill.Billable       = UpdateBill.Billable;
                OldBill.Comments       = UpdateBill.Comments;
                OldBill.ClientID       = UpdateBill.ClientID;
                con.SubmitChanges();
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                ExceptionLog.LogException(ex);
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(ex))
                });
            }
        }
Ejemplo n.º 4
0
        public String update(BillingDetail p, String userId)
        {
            String re = "", sql = "";

            chkNull(p);
            sql = "Update " + blld.table + " Set " +
                  " " + blld.expenses_draw_detail_id + "='" + p.expenses_draw_detail_id + "' " +
                  "," + blld.item_name_t + "='" + p.item_name_t.Replace("'", "''") + "' " +
                  "," + blld.billing_id + "='" + p.billing_id.Replace("'", "''") + "' " +
                  "," + blld.remark + "='" + p.remark.Replace("'", "''") + "' " +
                  "," + blld.date_modi + "=now() " +
                  "," + blld.user_modi + "='" + userId.Replace("'", "''") + "' " +
                  "," + blld.item_id + "='" + p.item_id.Replace("'", "''") + "' " +
                  "," + blld.amount_draw + "='" + p.amount_draw.Replace("'", "''") + "' " +
                  "," + blld.amount_income + "='" + p.amount_income.Replace("'", "''") + "' " +
                  "Where " + blld.pkField + "='" + p.billing_detail_id + "'"
            ;

            try
            {
                re = conn.ExecuteNonQuery(conn.conn, sql);
            }
            catch (Exception ex)
            {
                sql = ex.Message + " " + ex.InnerException;
            }
            return(re);
        }
Ejemplo n.º 5
0
        private void chkNull(BillingDetail p)
        {
            int     chk  = 0;
            Decimal chk1 = 0;

            p.date_modi   = p.date_modi == null ? "" : p.date_modi;
            p.date_cancel = p.date_cancel == null ? "" : p.date_cancel;
            p.user_create = p.user_create == null ? "" : p.user_create;
            p.user_modi   = p.user_modi == null ? "" : p.user_modi;
            p.user_cancel = p.user_cancel == null ? "" : p.user_cancel;

            p.expenses_draw_detail_id = p.expenses_draw_detail_id == null ? "" : p.expenses_draw_detail_id;
            //p.billing_detail_id = p.billing_detail_id == null ? "" : p.billing_detail_id;
            p.item_name_t = p.item_name_t == null ? "" : p.item_name_t;
            p.remark      = p.remark == null ? "" : p.remark;
            //p.item_name_t = p.item_name_t == null ? "" : p.item_name_t;
            //p.remark = p.remark == null ? "" : p.remark;

            p.item_id = int.TryParse(p.item_id, out chk) ? chk.ToString() : "0";
            p.expenses_draw_detail_id = int.TryParse(p.expenses_draw_detail_id, out chk) ? chk.ToString() : "0";
            p.billing_id = int.TryParse(p.billing_id, out chk) ? chk.ToString() : "0";
            p.item_id    = int.TryParse(p.item_id, out chk) ? chk.ToString() : "0";

            p.amount_draw   = Decimal.TryParse(p.amount_draw, out chk1) ? chk1.ToString() : "0";
            p.amount_income = Decimal.TryParse(p.amount_income, out chk1) ? chk1.ToString() : "0";
        }
Ejemplo n.º 6
0
        private void setRowGrfPay(String blldid)
        {
            if (blldid == null)
            {
                return;
            }
            if (blldid.Equals(""))
            {
                return;
            }
            BillingDetail blld = new BillingDetail();
            Billing       bll  = new Billing();

            blld = xC.accDB.blldDB.selectByPk1(blldid);
            bll  = xC.accDB.bllDB.selectByPk1(blld.billing_id);
            Row rowB = grfPay.Rows.Add();

            rowB[0]             = grfPay.Rows.Count - 1;
            rowB[colPdID]       = "";
            rowB[colPdJobNo]    = bll.job_code;
            rowB[colPdJobId]    = bll.job_id;
            rowB[colPdBillDoc]  = blld.item_name_t;
            rowB[colPdItmNameT] = blld.item_name_t;
            rowB[colPdItmId]    = blld.item_id;
            rowB[colPdAmtE]     = blld.amount_draw;
            rowB[colPdBillDoc]  = bll.billing_code;
            rowB[colPdAmtI]     = blld.amount_income;
            rowB[colPdBlldId]   = blld.billing_detail_id;
            rowB[colPdBllId]    = blld.billing_id;
            calAmt();
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> OrderList(OrderModel orderModel)
        {
            if (orderModel != null)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        if (HttpContext.User.Identity.IsAuthenticated)
                        {
                            AppUser appUser = await _baselDb.AppUsers
                                              .Where(x => x.UserName == HttpContext.User.Identity.Name)
                                              .Include(x => x.BillingDetail)
                                              .SingleOrDefaultAsync();

                            if (appUser.BillingDetail == null)
                            {
                                BillingDetail billingDetail = new BillingDetail()
                                {
                                    Apartment     = orderModel.Apartment,
                                    StreetAddress = orderModel.StreetAddress,
                                    Town          = orderModel.Town
                                };
                                appUser.BillingDetail = billingDetail;
                            }
                            else
                            {
                                appUser.BillingDetail.Apartment     = orderModel.Apartment;
                                appUser.BillingDetail.StreetAddress = orderModel.StreetAddress;
                                appUser.BillingDetail.Town          = orderModel.Town;
                            }

                            HttpContext.Session.SetString("userTotalPrice", orderModel.TotalPrice.ToString());

                            appUser.Name     = orderModel.Name;
                            appUser.Lastname = orderModel.LastName;

                            await _userManager.UpdateAsync(appUser);

                            return(Redirect("https://localhost:44394/Index/?" + "userName="******"&userLastName=" + orderModel.LastName +
                                            "&userTotalPrice=" + orderModel.TotalPrice + "&userId=" + appUser.Id));
                        }

                        return(RedirectToAction("Index", "Home"));
                    }
                    catch (Exception exp)
                    {
                    }
                }
            }
            return(RedirectToAction("ProductList"));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PlaceOrder(CheckoutFormViewModel model, string stripeToken)
        {
            if (!ModelState.IsValid)
            {
                //var errors = ModelState.Values.SelectMany(v => v.Errors).ToList();
                return(RedirectToAction("Checkout"));
            }

            var billingDetail = new BillingDetail
            {
                FirstName     = model.FirstName,
                LastName      = model.LastName,
                Address       = await BuildAddressModel(model.Address),
                Email         = model.Email,
                Phone         = model.Phone,
                IsResidential = model.IsResidential,
                CompanyName   = model.CompanyName,
                OrderNotes    = model.OrderNotes
            };

            var user = await _userService.GetCurrentUserAsync();

            bool    isCustomer = User.IsCustomer() || User.IsAdmin();
            decimal subTotal   = 0;
            decimal total      = 0;

            var cartItems = await _cartService.GetAllAsync(user.Id);

            if (cartItems != null)
            {
                subTotal = _cartService.GetCartTotalCost(isCustomer, cartItems);
            }

            // need calculate total with shipping
            // For now skip it.
            total = subTotal;

            //need to check if shiptodifferentaddress is true, if so, use the ShippingFormViewModel property. SKIP this

            bool success = await _orderService.ProcessOrderAsync(total, stripeToken, billingDetail, cartItems, user);

            if (success)
            {
                //await emailService.SendEmailAsync(model.Email, "Your Order Confirmation", "Please login to your account to view your orders");

                await _cartService.ClearCartAsync(user.Id);

                return(View("Success"));
            }

            return(View("Error"));
        }
Ejemplo n.º 9
0
        public BillingDetail selectByPk1(String copId)
        {
            BillingDetail cop1 = new BillingDetail();
            DataTable     dt   = new DataTable();
            String        sql  = "select blld.* " +
                                 "From " + blld.table + " blld " +
                                 //"Left Join t_ssdata_visit ssv On ssv.ssdata_visit_id = bd.ssdata_visit_id " +
                                 "Where blld." + blld.pkField + " ='" + copId + "' ";

            dt   = conn.selectData(conn.conn, sql);
            cop1 = setBillingDetail(dt);
            return(cop1);
        }
Ejemplo n.º 10
0
        public String insertBillingDetail(BillingDetail p, String userId)
        {
            String re = "";

            if (p.billing_detail_id.Equals(""))
            {
                re = insert(p, userId);
            }
            else
            {
                re = update(p, userId);
            }
            return(re);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the billing details for a server.
        /// </summary>
        /// <param name="server">The server</param>
        /// <returns>The billing details</returns>
        public async Task <BillingDetail> GetBillingDetailsFor(Server server, CancellationToken cancellationToken)
        {
            BillingDetail billingDetails = null;
            var           uri            = string.Format(Constants.ServiceUris.Billing.GetGroupBillingDetails, Configuration.BaseUri, authentication.AccountAlias, server.GroupId);
            var           groupDetails   = await GetGroupBillingDetailsByLink(uri, cancellationToken).ConfigureAwait(false);

            if (groupDetails.Groups.ContainsKey(server.GroupId))
            {
                var parentGroupDetails = groupDetails.Groups[server.GroupId];
                if (parentGroupDetails.Servers.ContainsKey(server.Id))
                {
                    billingDetails = parentGroupDetails.Servers[server.Id];
                }
            }

            return(billingDetails);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> AccountAddressUpdate(OrderModel orderModel)
        {
            if (orderModel != null)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        AppUser appUser = await _baselDb.AppUsers
                                          .Where(z => z.UserName == HttpContext.User.Identity.Name)
                                          .Include(z => z.BillingDetail)
                                          .SingleOrDefaultAsync();

                        appUser.Name     = orderModel.Name;
                        appUser.Lastname = orderModel.LastName;

                        if (appUser.BillingDetail != null)
                        {
                            appUser.BillingDetail.Apartment     = orderModel.Apartment;
                            appUser.BillingDetail.StreetAddress = orderModel.StreetAddress;
                            appUser.BillingDetail.Town          = orderModel.Town;
                        }
                        else
                        {
                            BillingDetail billingDetail = new BillingDetail()
                            {
                                Town          = orderModel.Town,
                                StreetAddress = orderModel.StreetAddress,
                                Apartment     = orderModel.Apartment
                            };

                            appUser.BillingDetail = billingDetail;
                        }

                        await _baselDb.SaveChangesAsync();

                        return(RedirectToAction("AccountAddress"));
                    }
                    catch (Exception)
                    {
                    }
                }
                return(View(orderModel));
            }
            return(RedirectToAction("AccountAddress"));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the data center overview, which contains composite information from several different areas such as billing, compute limits recent activities etc.
        /// </summary>
        /// <param name="dataCenterId">The id of the data center</param>
        /// <returns>A detailed overview of the data center</returns>
        public async Task <DataCenterOverview> GetDataCenterOverview(string dataCenterId, CancellationToken cancellationToken)
        {
            var dataCenter = await GetDataCenter(dataCenterId, true, cancellationToken).ConfigureAwait(false);

            if (dataCenter != null)
            {
                var tasks = new List <Task>();

                BillingDetail          billingTotals   = null;
                ComputeLimits          computeLimits   = null;
                DefaultSettings        defaultSettings = null;
                NetworkLimits          networkLimits   = null;
                IEnumerable <Activity> recentActivity  = null;

                tasks.Add(Task.Run(async() => billingTotals   = await billingService.GetBillingDetailsFor(dataCenter).ConfigureAwait(false)));
                tasks.Add(Task.Run(async() => computeLimits   = await dataCenter.GetComputeLimits(cancellationToken).ConfigureAwait(false)));
                tasks.Add(Task.Run(async() => defaultSettings = await dataCenter.GetDefaultSettings(cancellationToken).ConfigureAwait(false)));
                tasks.Add(Task.Run(async() => networkLimits   = await dataCenter.GetNetworkLimits(cancellationToken).ConfigureAwait(false)));
                tasks.Add(Task.Run(async() => recentActivity  = await accountService.GetRecentActivityFor(dataCenter, cancellationToken).ConfigureAwait(false)));

                await Task.WhenAll(tasks).ConfigureAwait(false);


                var dataCenterOverview = new DataCenterOverview()
                {
                    DataCenter      = dataCenter,
                    BillingTotals   = billingTotals,
                    ComputeLimits   = computeLimits,
                    DefaultSettings = defaultSettings,
                    NetworkLimits   = networkLimits,
                    RecentActivity  = recentActivity
                };

                return(dataCenterOverview);
            }

            return(null);
        }
Ejemplo n.º 14
0
        public ActionResult checkout(BookingDetail bkd)
        {
            List <Bookcar> li = TempData["Bookcar"] as List <Bookcar>;

            // TempData.Keep("Bookcar");

            BillingDetail bd = new BillingDetail();

            bd.BillDate    = System.DateTime.Now;
            bd.TotalAmount = Convert.ToDouble(TempData["bill"]);
            bd.Customer_Id = Convert.ToInt32(Session["Customer_Id"].ToString());
            db.BillingDetails.Add(bd);
            db.SaveChanges();

            foreach (var item in li)
            {
                BookingDetail bdetail = new BookingDetail();
                bdetail.CarId     = item.carid;
                bdetail.Billid    = bd.Billid;
                bdetail.Prize     = item.bill;
                bdetail.StartDate = item.StartDate;
                bdetail.EndDate   = item.EndDate;
                bdetail.PickupLoc = item.PickupLoc;

                db.BookingDetails.Add(bdetail);
                db.SaveChanges();
            }
            TempData.Remove("bill");
            TempData.Remove("Bookcar");

            TempData["msg"] = "Transaction completed.....";

            TempData.Keep();
            return(RedirectToAction("Index", "User"));
            // return RedirectToAction("User","Index");
            //return View("viewcar");
        }
Ejemplo n.º 15
0
        public HttpResponseMessage AddBillingItem([FromBody] string billDetails, string token)
        {
            if (con.CheckIfTokenValid(token) != 10001 && con.IsUserInternal(token) == 1)
            {
                return(new HttpResponseMessage(HttpStatusCode.Unauthorized));
            }
            try
            {
                BillingDetail bill   = JsonConvert.DeserializeObject <BillingDetail>(billDetails);
                int           UserID = con.GetUserIDSession(token).SingleOrDefault().UserID;
                bill.AssignedTo = UserID;
                bill.BilledBy   = UserID;
                bill.DateAdded  = DateTime.Now;

                con.BillingDetails.InsertOnSubmit(bill);
                con.SubmitChanges();
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                ExceptionLog.LogException(ex);
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
Ejemplo n.º 16
0
        private void initConfig()
        {
            blld                         = new BillingDetail();
            blld.billing_id              = "billing_id";
            blld.billing_detail_id       = "billing_detail_id";
            blld.expenses_draw_detail_id = "expenses_draw_detail_id";
            blld.item_id                 = "item_id";
            blld.item_name_t             = "item_name_t";
            blld.amount_draw             = "amount_draw";
            blld.active                  = "active";
            blld.remark                  = "remark";
            blld.date_create             = "date_create";
            blld.date_modi               = "date_modi";
            blld.date_cancel             = "date_cancel";
            blld.user_create             = "user_create";
            blld.user_modi               = "user_modi";
            blld.user_cancel             = "user_cancel";
            blld.amount_income           = "amount_income";

            blld.table   = "t_billing_detail";
            blld.pkField = "billing_detail_id";

            lexpn = new List <BillingDetail>();
        }
Ejemplo n.º 17
0
        private void BtnBSave_Click(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            if (MessageBox.Show("ต้องการ บันทึกช้อมูล ", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK)
            {
                setBilling();
                String re = xC.accDB.bllDB.insertBilling(bll, xC.userId);
                int    chk = 0, chkD = 0;
                if (int.TryParse(re, out chk))
                {
                    txtBllId.Value = re;
                    foreach (Row rowB in grfBill.Rows)
                    {
                        if (rowB[colBitmId] == null)
                        {
                            continue;
                        }
                        BillingDetail blld = new BillingDetail();
                        blld.billing_id              = re;
                        blld.billing_detail_id       = "";
                        blld.expenses_draw_detail_id = rowB[colBexpnddId] != null ? rowB[colBexpnddId].ToString() : "";
                        blld.item_id       = rowB[colBitmId].ToString();
                        blld.item_name_t   = rowB[colBItmNameT].ToString();
                        blld.amount_draw   = rowB[colBExpn] != null ? rowB[colBExpn].ToString() : "0";
                        blld.active        = "";
                        blld.remark        = "";
                        blld.date_create   = "";
                        blld.date_modi     = "";
                        blld.date_cancel   = "";
                        blld.user_create   = "";
                        blld.user_modi     = "";
                        blld.user_cancel   = "";
                        blld.amount_income = rowB[colBimcome] != null ? rowB[colBimcome].ToString() : "0";
                        String re1 = "";
                        re1 = xC.accDB.blldDB.insertBillingDetail(blld, xC.userId);
                        if (int.TryParse(re1, out chk))
                        {
                            chkD++;

                            Debtor dtr = new Debtor();
                            dtr.debtor_id = "";
                            dtr.cus_id    = cus.cust_id;
                            if (!blld.amount_income.Equals("0"))
                            {
                                dtr.amount = blld.amount_income;
                            }
                            else if (!blld.amount_draw.Equals("0"))
                            {
                                dtr.amount = blld.amount_draw;
                            }
                            else
                            {
                                dtr.amount = "0";
                            }

                            dtr.billing_detail_id = re1;
                            dtr.payment_detail_id = "";
                            dtr.job_id            = jim.job_import_id;
                            dtr.remark            = "";
                            dtr.status_debtor     = "1";
                            dtr.comp_id           = cop.comp_id;
                            xC.accDB.dtrDB.insertDebtor(dtr, xC.userId);
                        }
                    }
                    if (chkD == (grfBill.Rows.Count - 1))
                    {
                        txtBllCode.Value = bll.billing_code;
                        Row row = grfCover.Rows.Add();
                        row[colVBllDoc] = bll.billing_code;
                        row[colVJobNo]  = bll.job_code;
                        row[colVAmt]    = bll.amount;
                        row[colVbllId]  = txtBllId.Value;

                        btnBSave.Image = Resources.accept_database24;
                    }
                }
                else
                {
                    btnBSave.Image = Resources.accept_database24;
                }
            }
        }
Ejemplo n.º 18
0
        // Working on this
        public async Task <bool> ProcessOrderAsync(decimal total, string stripeToken, BillingDetail billingDetail, List <CartItem> cartItems, AppUser user)
        {
            // Process payment - Stripe
            string clientSecret = CreateStripePaymentIntent(total);

            // if charge succeeded
            if (true)
            {
                var order = new Order
                {
                    Total         = total,
                    Placed        = DateTime.UtcNow,
                    BillingDetail = billingDetail,
                    User          = user,
                    //StripeChargeId = charge.Id
                };

                var orderDetails = cartItems.Select(item => new OrderDetail
                {
                    ProductId       = item.ProductId,
                    ProductName     = item.Name,
                    ProductQuantity = item.Quantity,
                    ProductCost     = item.Price.Cost,
                    Order           = order
                }).ToList();

                (bool success, int orderId) = await AddOrderAsync(order, orderDetails);

                return(success);
            }
        }
Ejemplo n.º 19
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);
        }