Example #1
0
        public ActionResult Create(CreateBillViewModel model)
        {
            ViewBag.Parent = "Quản lý giao hàng";
            ViewBag.Child  = "Lập hóa đơn";
            isAdminLogged();
            var bill = new Bill();

            bill.idDeliveryOrder = model.idDeliveryOrder;
            bill.idDistributor   = model.idDistributor;
            bill.idStaff         = model.idStaff;
            bill.purchase        = model.purchase;
            bill.description     = model.description;
            bill.createdDate     = model.createdDate;
            var delivery = _dOrderService.SearchById(bill.idDeliveryOrder.Value);
            var order    = _orderService.GetOrder(delivery.idOrder.Value);

            // TH thanh toán giao hàng
            // nếu hình thức thanh toán của đơn hàng là qua thẻ thì ko cần lập hóa đơn (paymenttype = true)
            if (order.PaymentType == true)
            {
                ViewBag.types = 1;
                ViewBag.msg   = "Đã thanh toán qua thẻ, không cần lập hóa đơn thanh toán giao hàng";
            }
            else
            {
                // TH thanh toán bằng tiền mặt
                var bills = delivery.Bills;
                // TH Đơn đã có hóa đơn rồi
                if (bills.FirstOrDefault() != null)
                {
                    ViewBag.types = 1;
                    ViewBag.msg   = "Đơn hàng này đã lập hóa đơn thanh toán rồi, vui lòng thanh toán công nợ nếu có!";
                }
                else
                {
                    // TH đơn chưa có hóa đơn
                    decimal tienthieu = delivery.totalPurchase.Value - bill.purchase.Value;
                    if (tienthieu < 0)
                    {
                        ViewBag.types = 1;
                        ViewBag.msg   = "Lập thất bại, tiền đơn hàng chỉ có " + string.Format("{0:0,0}", delivery.totalPurchase.Value) + " VNĐ.";
                    }
                    else
                    {
                        // TH thu tiền ít hơn tổng tiền đơn hàng, thì tăng thêm công nợ
                        if (tienthieu > 0)
                        {
                            var dis = order.Distributor;
                            dis.debt += tienthieu;
                            _distributoriervice.UpdateDebt(bill.idDistributor.Value, dis.debt.Value);
                        }
                        _billService.AddBill(bill);
                    }
                }
            }
            ViewBag.types = 2;
            ViewBag.msg   = "Lập hoá đơn thành công, bạn đã thanh toán " + string.Format("{0:0,0}", delivery.totalPurchase.Value) + " VNĐ.";
            return(View(model));
        }
        public ActionResult Print_Bill(/*List<int>codes*/)
        {
            CreateBillViewModel model = new CreateBillViewModel();

            model.AllProduct   = DbContext.Store.ToList();
            model.BillsProduct = s();
            GetPartial();
            return(View(model));
        }
        public ActionResult Create()
        {
            var userGuid = new Guid(User.Identity.GetUserId());
            var vm       = new CreateBillViewModel
            {
                UserId = userGuid,
                Icon   = "fa-500px"
            };

            return(View(vm));
        }
        public ActionResult Create_bill()
        {
            if (User.Identity.IsAuthenticated)
            {
                CreateBillViewModel model = new CreateBillViewModel();

                model.AllProduct   = DbContext.Store.ToList();
                model.BillsProduct = s();
                GetPartial();
                return(View(model));
            }
            else
            {
                return(Redirect("/Identity/Account/Login"));
            }
        }
Example #5
0
        private async void ExecuteAddBill()
        {
            var reciept = RecieptSearchViewModel.SelectedReciept;

            if (reciept == null)
            {
                NotificationService.Warning("No reciept selected!", "You need to select a reciept to edit");
                return;
            }
            CreateBillViewModelContext = new CreateBillViewModel(reciept, HotelRepository,
                                                                 NotificationService);
            var queryView = new CreateBillView
            {
                DataContext = CreateBillViewModelContext
            };
            await DialogHost.Show(queryView);
        }
Example #6
0
        // GET: PatientsBill/Create
        public ActionResult Create(int?Appointment_id, int?Patient_id)
        {
            CreateBillViewModel model = new CreateBillViewModel();

            Session["QueryVal"] = Appointment_id;
            if (Patient_id != null)
            {
                model.PatientAppointmentDate = (from p in db.tblPatientAppointments
                                                where p.patient_id == Patient_id
                                                select new SelectListItem
                {
                    Text = p.AppointmentDate,
                    Value = p.ID.ToString()
                }).ToList();
            }
            return(View(model));
        }
Example #7
0
        // GET: Bill/Create
        public ActionResult Create(int idDelivery)
        {
            ViewBag.Parent = "Quản lý giao hàng";
            ViewBag.Child  = "Lập hóa đơn";
            isAdminLogged();
            CreateBillViewModel model = new CreateBillViewModel();
            var   user   = Session["admin"] as Account;
            Staff staff  = _staffService.GetByAccount(user.UserName);
            var   dOrder = _dOrderService.SearchById(idDelivery);

            model.idStaff         = staff.idStaff;
            model.idDeliveryOrder = idDelivery;
            model.createdDate     = DateTime.Now;
            model.idDistributor   = dOrder.idDistributor;
            model.nameDistributor = dOrder.Distributor.name;
            model.idDeliveryOrder = dOrder.idDeliveryOrder;
            return(View(model));
        }
        public ActionResult Create(CreateBillViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var userGuid = new Guid(User.Identity.GetUserId());

            model.UserId = userGuid;

            var newbill = Mapper.Map <CreateBillViewModel, Bill>(model);

            newbill.BackgroundColor = newbill.BackgroundColor.Replace("#", "");
            newbill.ForeColor       = newbill.ForeColor.Replace("#", "");

            db.Bills.Add(newbill);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #9
0
        public ActionResult CreateBill(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var saleOrder = _db.SaleOrders.Find(id);

            if (saleOrder == null || saleOrder.Status == SaleOrder.SaleOrderStatus.Cancel)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var viewModel = new CreateBillViewModel
            {
                SaleOrder = saleOrder,
                Bill      = new Bill()
            };

            return(View(viewModel));
        }
Example #10
0
        public ActionResult Create(string nameValueInsert, string nameValueSubmit, CreateBillViewModel model, int?Patient_id)
        {
            var button = nameValueInsert ?? nameValueSubmit;

            if (button == "Insert")
            {
                if (Session["templist"] == null)
                {
                    List <PatientViewModel> lst = new List <PatientViewModel>();

                    lst.Add(new PatientViewModel()
                    {
                        PatientAppointmentID = Int32.Parse(Request.Form["PatientAppointmentID"]),
                        // BillNo = Request.Form["BillNo"],
                        Amount      = double.Parse(Request.Form["Amount"]),
                        Description = Request.Form["Description"]
                    });
                    Session["templist"] = lst;
                }
                else
                {
                    List <PatientViewModel> lst = (List <PatientViewModel>)Session["templist"];

                    lst.Add(new PatientViewModel()
                    {
                        PatientAppointmentID = Int32.Parse(Request.Form["PatientAppointmentID"]),
                        // BillNo = Request.Form["BillNo"],
                        Amount      = double.Parse(Request.Form["Amount"]),
                        Description = Request.Form["Description"]
                    });
                    Session["templist"] = lst;
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    string     username = "";
                    HttpCookie cookie   = HttpContext.Request.Cookies["AdminCookies"];
                    if (cookie != null)
                    {
                        username = Convert.ToString(cookie.Values["UserName"]);
                    }
                    tblPatientBill patientbill = new tblPatientBill();
                    patientbill.PatientAppointmentID = model.PatientAppointmentID;
                    //  patientbill.BillNo = model.ID;
                    patientbill.Amount      = model.AmountTotal;
                    patientbill.Description = model.Note;
                    patientbill.Discount    = model.Discount;
                    patientbill.CreatedAt   = model.CreatedAt;
                    patientbill.CreatedBy   = username;
                    patientbill.is_active   = true;
                    db.tblPatientBills.Add(patientbill);
                    db.SaveChanges();

                    int PatientBill_ID          = Convert.ToInt32(patientbill.ID);
                    List <PatientViewModel> lst = (List <PatientViewModel>)Session["templist"];
                    if (lst != null)
                    {
                        tblPatientBillDetail billdetail = new tblPatientBillDetail();
                        foreach (var item in lst)
                        {
                            billdetail.PatientBillID = PatientBill_ID;
                            billdetail.Amount        = item.Amount;
                            billdetail.CreatedAt     = DateTime.UtcNow;
                            billdetail.CreatedBy     = username;
                            billdetail.Description   = item.Description;
                            billdetail.is_active     = true;
                            db.tblPatientBillDetails.Add(billdetail);
                            db.SaveChanges();
                        }
                        Session.Clear();
                    }
                    return(RedirectToAction("Print", new { Billid = @PatientBill_ID }));
                }
            }
            model.PatientAppointmentDate = (from p in db.tblPatientAppointments
                                            where p.patient_id == Patient_id
                                            select new SelectListItem
            {
                Text = p.AppointmentDate,
                Value = p.ID.ToString()
            }).ToList();
            return(View(model));
        }