예제 #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));
        }
예제 #2
0
        public IActionResult InsertBill([FromBody] BillVM bill)
        {
            try
            {
                _billService.AddBill(bill);
                return(Ok());
            }

            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
예제 #3
0
        public void TestBlueSky_Add()
        {
            // set-up
            IBill bill = CreateBill();

            // pre-conditions
            Assert.IsNull(Service.GetBill(bill.RecordId));

            // exercise
            Service.AddBill(bill);
            IBill persistedBill = Service.GetBill(bill.RecordId);

            // post-conditions
            Assert.AreEqual(persistedBill, bill);
        }
예제 #4
0
        public void Execute(AddBillCommandContext commandContext)
        {
            string databaseName = commandContext.DatabasePath;

            using (SQLiteConnection conn = new SQLiteConnection(string.Format(@"Data Source={0};", databaseName)))
            {
                conn.Open();

                DateTime createdAt = DateTime.UtcNow;

                SQLiteCommand getNewBillNumberQuery =
                    new SQLiteCommand(
                        string.Format(
                            @"select COUNT(NUMBER) from bills where CreatedAt LIKE @yearMonth + '%' "), conn);
                getNewBillNumberQuery.Parameters.AddWithValue("@yearMonth",
                                                              $"{createdAt.Year:0000}-{createdAt.Month:00}");
                int number = (int)getNewBillNumberQuery.ExecuteScalar() + 1;


                SQLiteCommand command =
                    new SQLiteCommand(
                        string.Format(
                            @"INSERT INTO 'Bills' ('Sum','Number','ClientId','CreatedAt') VALUES (@sum, @number,@clid,@createdat);"), conn);
                command.Parameters.AddWithValue("@sum", commandContext.Sum);
                command.Parameters.AddWithValue("@number", number);
                command.Parameters.AddWithValue("@clid", commandContext.ClientId);
                command.Parameters.AddWithValue("@createdat", createdAt.ToString("s"));
                command.ExecuteNonQuery();

                SQLiteCommand getNewBillIdQuery =
                    new SQLiteCommand(
                        string.Format(
                            @"SELECT Id FROM Bills WHERE Number=@number AND CreatedAt=@createdat), conn);"));
                getNewBillIdQuery.Parameters.AddWithValue("@number", number);
                getNewBillIdQuery.Parameters.AddWithValue("@createdat", createdAt.ToString("s"));
                int id = (int)getNewBillIdQuery.ExecuteScalar();

                _billService.AddBill(id, number, commandContext.Sum, commandContext.ClientId, createdAt);
            }
        }
예제 #5
0
        public IActionResult AddBill([FromBody] BillAddRequest billAddRequest)
        {
            var bill = billService.AddBill(billAddRequest);

            return(CreatedAtAction(nameof(GetBill), new { bill.Id }, bill));
        }
예제 #6
0
 public bool AddProduct(BillModel model)
 {
     return(billService.AddBill(model));
 }