Exemplo n.º 1
0
        public void DeleteTest()
        {
            Bill v = new Bill();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.Id    = 27;
                v.Title = "ySr5";
                v.Money = 74;
                context.Set <Bill>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID);

            Assert.IsInstanceOfType(rv.Model, typeof(BillVM));

            BillVM vm = rv.Model as BillVM;

            v         = new Bill();
            v.ID      = vm.Entity.ID;
            vm.Entity = v;
            _controller.Delete(v.ID, null);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(context.Set <Bill>().Count(), 0);
            }
        }
Exemplo n.º 2
0
        public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

            Assert.IsInstanceOfType(rv.Model, typeof(BillVM));

            BillVM vm = rv.Model as BillVM;
            Bill   v  = new Bill();

            v.Id      = 27;
            v.Title   = "ySr5";
            v.Money   = 74;
            vm.Entity = v;
            _controller.Create(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Bill>().FirstOrDefault();

                Assert.AreEqual(data.Id, 27);
                Assert.AreEqual(data.Title, "ySr5");
                Assert.AreEqual(data.Money, 74);
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
Exemplo n.º 3
0
        public JsonResult SaveBill(BillVM B)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (ERP1DataContext dc = new ERP1DataContext())
                {
                    string Day   = DateTime.Now.Day.ToString();
                    string Month = DateTime.Now.Month.ToString();
                    string Year  = DateTime.Now.Year.ToString();
                    Bill   bill  = new Bill {
                        AppointmentID = B.AppointmentID, DoctorID = B.DoctorID, PatientID = B.PatientID, TotalAmount = decimal.Parse(B.TotalAmount), AddedDay = Day, AddedMonth = Month, AddedYear = Year
                    };
                    foreach (var i in B.BillDetails)
                    {
                        //
                        // i.TotalAmount =
                        bill.BillDetails.Add(i);
                    }
                    dc.Bills.InsertOnSubmit(bill);
                    dc.SubmitChanges();
                    status = true;
                    return(new JsonResult {
                        Data = new { status = status }
                    });
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Exemplo n.º 4
0
        public IActionResult AddService(int?id)
        {
            var bill = _context.Bill
                       .FirstOrDefault(m => m.Bill_ID == id);

            var service = _context.Service_Detail.Where(p => p.Bill_ID == id)
                          .Join(_context.Service,
                                sd => sd.Service_ID,
                                s => s.Service_ID,
                                (sd, s) => new
            {
                Service = s
            }).ToList();

            var servicelist = new List <ServiceVM>();

            foreach (var item in service)
            {
                var ser_qty  = _context.Service_Detail.Where(p => p.Bill_ID == id && p.Service_ID == item.Service.Service_ID).FirstOrDefault();
                var ser_item = new ServiceVM
                {
                    Service          = item.Service,
                    Service_Quantity = ser_qty.Service_Quantity,
                };
                servicelist.Add(ser_item);
            }
            BillVM billVM = new BillVM
            {
                Bill       = bill,
                ServiceVMs = servicelist,
            };

            return(View());
        }
Exemplo n.º 5
0
        // GET: Bill
        public ActionResult Index()
        {
            var model = new BillVM();

            Session["LstProduct"] = new List <product>();
            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult AddBill(BillVM modelInput)
        {
            try
            {
                var model = Session["LstProduct"] as List <product>;
                if (model == null || model.Count == 0)
                {
                    return(Json(new { status = false, msg = "Hóa đơn chưa tạo sản phẩm!" }));
                }

                var data = _customerRepository.GetCustomerById(modelInput.cutomer.user_cd);
                if (data == null)
                {
                    return(Json(new { status = false, msg = "Chưa lựa chọn khách hàng" }));
                }

                var billPaymentOut = new bill_payment_out
                {
                    customer_id   = modelInput.cutomer.user_cd,
                    customer_name = modelInput.cutomer.name,
                    price         = model.Sum(x => x.price * x.amount),
                    create_date   = DateTime.Now,
                    create_user   = ""
                };

                var lstdetails = new List <details_bill_payment_out>();
                foreach (var item in model)
                {
                    var details = new details_bill_payment_out
                    {
                        product_id  = item.id,
                        amount      = item.amount,
                        price       = item.price.ToString(),
                        create_date = DateTime.Now,
                        create_user = ""
                    };
                    lstdetails.Add(details);
                }

                IBillPaymentOutRepository repository = new BillPaymentOutRopository();
                var res = repository.Add(billPaymentOut, lstdetails);
                if (res)
                {
                    return(Json(new { status = true }));
                }
                else
                {
                    return(Json(new { status = false, msg = Constant.Msg007 }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { status = false, msg = ex.Message }));
            }
        }
Exemplo n.º 7
0
 public IActionResult UpdateBill([FromBody] BillVM bill)
 {
     try
     {
         _billService.UpdateBill(bill);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
        public ActionResult BillView()
        {
            if (db.Account.Any())
            {
                // BillVM objBill = new BillVM();


                var cus = (from a in db.Account
                           from c in db.Customer
                           from n in db.Service
                           where a.NewspaperId == n.Id && a.CustomerId == c.Id
                           select new
                {
                    Customer = c,
                    Account = a,
                    NewsPaper = n
                }).ToList();            // as IEnumerable<CounterVM>;



                List <BillVM> lstBill = new List <BillVM>();


                foreach (var item in cus)
                {
                    BillVM Bill = new BillVM();
                    Bill.BillNo        = item.Account.BillNo.ToString();
                    Bill.CustomerId    = item.Customer.CustomerId;
                    Bill.fiscalyear    = item.Account.FiscalYear;
                    Bill.CustomerName  = item.Customer.FirstName;
                    Bill.PrintedDate   = item.Account.Nepalidate;
                    Bill.NewspaperName = item.NewsPaper.NewsPaperName;
                    Bill.Address       = item.Customer.Address;
                    Bill.AccountId     = item.Account.Id;
                    lstBill.Add(Bill);
                }

                lstBill[0].BillNos    = new SelectList(db.Account, "BillNo", "BillNo");
                lstBill[0].Newspapers = new SelectList(db.Newspaper, "NewspaperName", "NewspaperName");



                return(View(lstBill));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 9
0
        public void EditTest()
        {
            Bill v = new Bill();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.Id    = 27;
                v.Title = "ySr5";
                v.Money = 74;
                context.Set <Bill>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID);

            Assert.IsInstanceOfType(rv.Model, typeof(BillVM));

            BillVM vm = rv.Model as BillVM;

            v    = new Bill();
            v.ID = vm.Entity.ID;

            v.Id      = 22;
            v.Title   = "1nG";
            v.Money   = 72;
            vm.Entity = v;
            vm.FC     = new Dictionary <string, object>();

            vm.FC.Add("Entity.Id", "");
            vm.FC.Add("Entity.Title", "");
            vm.FC.Add("Entity.Money", "");
            _controller.Edit(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Bill>().FirstOrDefault();

                Assert.AreEqual(data.Id, 22);
                Assert.AreEqual(data.Title, "1nG");
                Assert.AreEqual(data.Money, 72);
                Assert.AreEqual(data.UpdateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10);
            }
        }
Exemplo n.º 10
0
 public ActionResult Edit(BillVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(PartialView(vm));
     }
     else
     {
         vm.DoEdit();
         if (!ModelState.IsValid)
         {
             vm.DoReInit();
             return(PartialView(vm));
         }
         else
         {
             return(FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID));
         }
     }
 }
Exemplo n.º 11
0
 public ActionResult Create(BillVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(PartialView(vm));
     }
     else
     {
         vm.DoAdd();
         if (!ModelState.IsValid)
         {
             vm.DoReInit();
             return(PartialView(vm));
         }
         else
         {
             return(FFResult().CloseDialog().RefreshGrid());
         }
     }
 }
Exemplo n.º 12
0
        public ActionResult AddProduct(BillVM modelProduct)
        {
            var model = Session["LstProduct"] as List <product>;
            var item  = model.FirstOrDefault(x => x.id == modelProduct.product.id);

            if (item != null)
            {
                item.name   = modelProduct.product.name;
                item.amount = modelProduct.product.amount;
                item.price  = modelProduct.product.price;
            }
            else
            {
                model.Add(modelProduct.product.GetEntity());
            }
            return(Json(new
            {
                view = RenderRazorViewToString(ControllerContext, "LstView", model)
            }));

            //return PartialView(model);
        }
        public ActionResult MyBill()
        {
            if (User.Identity.IsAuthenticated)
            {
                var userId    = User.Identity.GetUserId();
                var soldItems = db.Sales.Where(s => s.Product.UserId == userId && s.Payed == true).ToList();

                var myCurrent = db.Bills.Where(b => b.UserId == userId).SingleOrDefault();

                if (myCurrent != null)
                {
                    var    totalPrice = soldItems.Sum(s => s.Price);
                    BillVM billVM     = new BillVM()
                    {
                        LastRec       = myCurrent.LastRec,
                        TotalRec      = myCurrent.TotalRec,
                        Available     = Convert.ToInt32(totalPrice) - myCurrent.TotalRec,
                        Withdrawable  = (Convert.ToInt32(totalPrice) - myCurrent.TotalRec) - 100,
                        TimeOfLastRec = myCurrent.TimeOfLastRec ?? DateTime.Now
                    };

                    return(View(billVM));
                }
                else
                {
                    BillVM billVM = new BillVM()
                    {
                        LastRec      = 0,
                        TotalRec     = 0,
                        Available    = 0,
                        Withdrawable = 0
                    };

                    return(View(billVM));
                }
            }
            return(RedirectToAction("Index", "Manage"));
        }
Exemplo n.º 14
0
        public void AddBill(BillVM billVM)
        {
            var bill = _mapper.Map <Bill>(billVM);

            _billRepository.Insert(bill);
        }
Exemplo n.º 15
0
        // GET: Bills/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var bill = await _context.Bill
                       .FirstOrDefaultAsync(m => m.Bill_ID == id);

            var room = await _context.RoomBooking.Where(p => p.Bill_ID == id)
                       .GroupBy(d => new { d.Room_ID, d.Bill_ID })
                       .Select(m => new { m.Key.Room_ID, m.Key.Bill_ID })
                       .Join(_context.Room,
                             rb => rb.Room_ID,
                             r => r.Room_ID,
                             (rb, r) => new
            {
                Room = r
            }).ToListAsync();

            var roomlist = new List <RoomVM>();

            foreach (var item in room)
            {
                var facility = await _context.Facility.Where(p => p.Fac_ID == item.Room.Fac_ID).FirstOrDefaultAsync();

                var roomtype = await _context.RoomType.Where(p => p.RoomType_ID == item.Room.RoomType_ID).FirstOrDefaultAsync();

                var fL = new List <Facility>();
                var rL = new List <RoomType>();
                fL.Add(facility);
                rL.Add(roomtype);

                var roomvmitem = new RoomVM
                {
                    Room       = item.Room,
                    RoomTypes  = rL,
                    Facilities = fL,
                };
                roomlist.Add(roomvmitem);
            }

            var service = await _context.Service_Detail
                          .Join(_context.Service,
                                sd => sd.Service_ID,
                                s => s.Service_ID,
                                (sd, s) => new
            {
                Service = s
            }).ToListAsync();

            var servicelist = new List <ServiceVM>();

            foreach (var item in service)
            {
                var ser_qty = await _context.Service_Detail.Where(p => p.Bill_ID == id && p.Service_ID == item.Service.Service_ID).FirstOrDefaultAsync();

                var ser_item = new ServiceVM
                {
                    Service          = item.Service,
                    Service_Quantity = ser_qty.Service_Quantity,
                };
                servicelist.Add(ser_item);
            }
            BillVM billVM = new BillVM
            {
                Bill       = bill,
                RoomVMs    = roomlist,
                ServiceVMs = servicelist,
            };



            if (bill == null)
            {
                return(NotFound());
            }

            return(View(billVM));
        }
Exemplo n.º 16
0
        static void ProductAndBill()
        {
            sql.NonQuery("TRUNCATE TABLE Bill");
            sql.NonQuery("TRUNCATE TABLE BillDetail");

            ClearProducts();
            InsertProducts();

            // Insert bill
            var b = new Bill {
                CreatedDate = DateTime.Now
            };
            // Insert and return inserted id
            int billId = sql.NonQuery(
                "INSERT INTO Bill(CreatedDate) OUTPUT INSERTED.Id VALUES (@CreatedDate)", S.Param("@CreatedDate", b.CreatedDate, SqlDbType.DateTime2));

            // Insert build detail
            var bds = new List <BillDetail>
            {
                new BillDetail {
                    BillId = billId, ProductId = 1, Quantity = 5
                },
                new BillDetail {
                    BillId = billId, ProductId = 2, Quantity = 3
                },
                new BillDetail {
                    BillId = billId, ProductId = 3, Quantity = 4
                },
            };

            // Insert bill detail information
            var values  = new List <string>();
            var @params = new List <SqlParameter>();

            for (var i = 0; i < bds.Count; ++i)
            {
                values.Add(string.Format("(@BillId{0}, @ProductId{0}, @Quantity{0})", i));
                @params.Add(S.Param("@BillId" + i, bds[i].BillId));
                @params.Add(S.Param("@ProductId" + i, bds[i].ProductId));
                @params.Add(S.Param("@Quantity" + i, bds[i].Quantity));
            }

            sql.NonQuery(
                "INSERT INTO BillDetail(BillId, ProductId, Quantity) VALUES " + string.Join(", ", values.ToArray()),
                @params.ToArray());

            // using "complex" t-sql
            // actually I don't recommend this way, let put everything in store procedure or view to make your code easier to debug, maintain.
            var bvm = new BillVM {
                Id = billId, Products = new Dictionary <ProductBasicInfo, int>()
            };

            sql.Queries(@"
SELECT bo.CreatedDate as [Date], p.Id as [ProdId], p.Name as [ProdName], bo.Quantity as [Qty]
FROM ProductTbl as p 
JOIN (SELECT bi.Id, bi.CreatedDate, bd.ProductId, bd.Quantity
      FROM Bill as bi
      JOIN BillDetail as bd 
      ON bi.Id = bd.BillId) as bo
ON bo.Id = @Id AND p.Id = bo.ProductId", S.Param("@Id", billId))
            .ForEach(x => {
                bvm.CreatedDate = (DateTime)x["Date"];     // assign multiple time is stupid, right?
                bvm.Products[new ProductBasicInfo {
                                 Id = (int)x["ProdId"], ProductName = (string)x["ProdName"]
                             }] = (int)x["Qty"];
            });

            // show data
            Console.WriteLine("Bill: " + billId);
            Console.WriteLine("Created Date: " + bvm.CreatedDate.ToString());
            Console.WriteLine("Products:");
            Console.WriteLine("============================================");
            Console.WriteLine("Id     |Name                      |Quantity ");
            Console.WriteLine("--------------------------------------------");
            foreach (var item in bvm.Products)
            {
                Console.WriteLine(
                    item.Key.Id.ToString().PadRight(7, ' ') + '|' +
                    item.Key.ProductName.PadRight(26, ' ') + '|' +
                    item.Value.ToString().PadRight(8, ' '));
            }
            Console.WriteLine("============================================");

            Console.ReadLine();
        }
Exemplo n.º 17
0
        public void UpdateBill(BillVM billVM)
        {
            var bill = _mapper.Map <Bill>(billVM);

            _billRepository.Update(bill);
        }