Esempio n. 1
0
        public ActionResult Edit(int?i)
        {
            if (Session["UserID"] != null && Session["UserType"].ToString().ToLower() == "admin")
            {
                if (i == null)
                {
                    return(RedirectToAction("Index", "Order"));
                }
                List <DAL.User>         users         = uRepo.GetCurrent();
                List <DAL.Order>        orders        = oRepo.GetCurrent();
                List <DAL.Meal>         meals         = mRepo.GetCurrent();
                List <DAL.OrderProduct> orderProducts = opRepo.GetCurrent();

                DAL.Order  o  = oRepo.GetByID((int)i);
                OrderModel om = new OrderModel();

                if (o.Date != null)
                {
                    om.Date = (DateTime)o.Date;
                }
                else
                {
                    om.Date = new DateTime();
                }

                om.EstimatedTime = o.EstimatedTime;
                om.ID            = o.ID;
                om.QRCodePath    = o.QRCodePath;
                om.TotalPrice    = o.TotalPrice;
                om.Voucher       = null;

                UserModel um = new UserModel();
                if (o.UserID != null)
                {
                    var usr = uRepo.GetByID((int)o.UserID);
                    if (usr.DOB != null)
                    {
                        um.DOB = (DateTime)usr.DOB;
                    }
                    else
                    {
                        um.DOB = new DateTime();
                    }

                    um.ID       = usr.ID;
                    um.Mail     = usr.Mail;
                    um.Name     = usr.Name;
                    um.NrOrders = usr.NrOrders;
                    um.Type     = usr.Type;
                }

                om.User          = um;
                om.EstimatedTime = o.EstimatedTime;

                return(View(om));
            }
            return(RedirectToAction("Login", "Home", new { area = "" }));
        }
 public void Test_GetOrderDetails()
 {
     Order order = new Order()
     {
         OrderID = 11063
     };
     OrderDetails orderDetails = nwOrders.GetOrderDetails(order);
     Assert.IsTrue(!String.IsNullOrEmpty(orderDetails.ProductName));
 }
 public void Test_DeleteOrder_FromComplete()
 {
     Order order = new Order()
     {
         CustomerID = "ALFKI",
         EmployeeID = 1,
         Freight = 1,
         OrderDate = DateTime.Now,
         RequiredDate = DateTime.Now,
         ShipAddress = "address",
         ShipCity = "city",
         ShipCountry = "country",
         ShipName = "name",
         ShippedDate = DateTime.Now,
         ShipPostalCode = "223710",
         ShipRegion = "Region",
         ShipVia = 1
     };
     Assert.IsFalse(nwOrders.DeleteOrder(order));
 }
Esempio n. 4
0
        public ActionResult Edit(OrderModel om)
        {
            if (Session["UserID"] != null && Session["UserType"].ToString().ToLower() == "admin")
            {
                if (om == null)
                {
                    return(RedirectToAction("Index", "Order"));
                }

                DAL.Order ord = new DAL.Order();
                ord = oRepo.GetByID(om.ID);
                if (om.Date != null)
                {
                    ord.Date = om.Date;
                }
                oRepo.Update(ord);

                return(RedirectToAction("Index", "Order"));
            }
            return(RedirectToAction("Login", "Home", new { area = "" }));
        }
Esempio n. 5
0
 public AddVAT(DAL.Order order)
 {
     InitializeComponent();
     this.numericUpDown1.Controls[0].Visible = false;
     this.Order = order;
 }
        public async Task SeedAsync()
        {
            await _context.Database.MigrateAsync().ConfigureAwait(false);

            if (!await _context.Users.AnyAsync())
            {
                _logger.LogInformation("Generating inbuilt accounts");

                const string adminRoleName = "administrator";
                const string userRoleName  = "user";

                const string customerRoleName    = "customer";
                const string dealerRoleName      = "dealer";
                const string distributorRoleName = "distributor";


                await EnsureRoleAsync(adminRoleName, "Default administrator", ApplicationPermissions.GetAllPermissionValues());
                await EnsureRoleAsync(userRoleName, "Default user", new string[] { });
                await EnsureRoleAsync(customerRoleName, "Customer", new string[] { });
                await EnsureRoleAsync(dealerRoleName, "Dealer", new string[] { });
                await EnsureRoleAsync(distributorRoleName, "Distributor", new string[] { });

                await CreateUserAsync("admin", "Test$123", "Inbuilt Administrator", "*****@*****.**", "+1 (123) 000-0000", new string[] { adminRoleName });
                await CreateUserAsync("user", "Test$123", "Inbuilt Standard User", "*****@*****.**", "+1 (123) 000-0001", new string[] { userRoleName });

                await CreateUserAsync("customer", "Test$123", " Automotive Customer", "*****@*****.**", "+1 (123) 000-0001", new string[] { customerRoleName });
                await CreateUserAsync("jmlexus", "Test$123", "Dealer", "*****@*****.**", "+1 (123) 000-0001", new string[] { dealerRoleName });
                await CreateUserAsync("jmfamily", "Test$123", "Distributor", "*****@*****.**", "+1 (123) 000-0001", new string[] { distributorRoleName });


                _logger.LogInformation("Inbuilt account generation completed");
            }



            if (!await _context.Customers.AnyAsync() && !await _context.ProductCategories.AnyAsync())
            {
                _logger.LogInformation("Seeding initial data");

                Customer cust_1 = new Customer
                {
                    Name         = "Ebenezer Monney",
                    Email        = "*****@*****.**",
                    Gender       = Gender.Male,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };

                Customer cust_2 = new Customer
                {
                    Name         = "Itachi Uchiha",
                    Email        = "*****@*****.**",
                    PhoneNumber  = "+81123456789",
                    Address      = "Some fictional Address, Street 123, Konoha",
                    City         = "Konoha",
                    Gender       = Gender.Male,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };

                Customer cust_3 = new Customer
                {
                    Name         = "John Doe",
                    Email        = "*****@*****.**",
                    PhoneNumber  = "+18585858",
                    Address      = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio.
                    Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet",
                    City         = "Lorem Ipsum",
                    Gender       = Gender.Male,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };

                Customer cust_4 = new Customer
                {
                    Name         = "Jane Doe",
                    Email        = "*****@*****.**",
                    PhoneNumber  = "+18585858",
                    Address      = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio.
                    Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet",
                    City         = "Lorem Ipsum",
                    Gender       = Gender.Male,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };



                ProductCategory prodCat_1 = new ProductCategory
                {
                    Name         = "None",
                    Description  = "Default category. Products that have not been assigned a category",
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };



                Product prod_1 = new Product
                {
                    Name            = "BMW M6",
                    Description     = "Yet another masterpiece from the world's best car manufacturer",
                    BuyingPrice     = 109775,
                    SellingPrice    = 114234,
                    UnitsInStock    = 12,
                    IsActive        = true,
                    ProductCategory = prodCat_1,
                    DateCreated     = DateTime.UtcNow,
                    DateModified    = DateTime.UtcNow
                };

                Product prod_2 = new Product
                {
                    Name            = "Nissan Patrol",
                    Description     = "A true man's choice",
                    BuyingPrice     = 78990,
                    SellingPrice    = 86990,
                    UnitsInStock    = 4,
                    IsActive        = true,
                    ProductCategory = prodCat_1,
                    DateCreated     = DateTime.UtcNow,
                    DateModified    = DateTime.UtcNow
                };



                Order ordr_1 = new Order
                {
                    Discount     = 500,
                    Cashier      = await _context.Users.FirstAsync(),
                    Customer     = cust_1,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow,
                    OrderDetails = new List <OrderDetail>()
                    {
                        new OrderDetail()
                        {
                            UnitPrice = prod_1.SellingPrice, Quantity = 1, Product = prod_1
                        },
                        new OrderDetail()
                        {
                            UnitPrice = prod_2.SellingPrice, Quantity = 1, Product = prod_2
                        },
                    }
                };

                Order ordr_2 = new Order
                {
                    Cashier      = await _context.Users.FirstAsync(),
                    Customer     = cust_2,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow,
                    OrderDetails = new List <OrderDetail>()
                    {
                        new OrderDetail()
                        {
                            UnitPrice = prod_2.SellingPrice, Quantity = 1, Product = prod_2
                        },
                    }
                };


                _context.Customers.Add(cust_1);
                _context.Customers.Add(cust_2);
                _context.Customers.Add(cust_3);
                _context.Customers.Add(cust_4);

                _context.Products.Add(prod_1);
                _context.Products.Add(prod_2);

                _context.Orders.Add(ordr_1);
                _context.Orders.Add(ordr_2);

                await _context.SaveChangesAsync();

                _logger.LogInformation("Seeding initial data completed");
            }
        }
Esempio n. 7
0
        public async Task SeedAsync()
        {
            await _context.Database.MigrateAsync().ConfigureAwait(false);

            if (!await _context.Users.AnyAsync())
            {
                _logger.LogInformation("Generating inbuilt accounts");

                const string adminRoleName = "administrator";
                const string userRoleName  = "user";

                await EnsureRoleAsync(adminRoleName, "Default administrator", ApplicationPermissions.GetAllPermissionValues());
                await EnsureRoleAsync(userRoleName, "Default user", new string[] { });

                await CreateUserAsync("admin", "tempP@ss123", "Inbuilt Administrator", "*****@*****.**", "+1 (123) 000-0000", new string[] { adminRoleName });
                await CreateUserAsync("user", "tempP@ss123", "Inbuilt Standard User", "*****@*****.**", "+1 (123) 000-0001", new string[] { userRoleName });

                _logger.LogInformation("Inbuilt account generation completed");
            }



            if (!await _context.Customers.AnyAsync()) // && !await _context.ProductCategories.AnyAsync())
            {
                _logger.LogInformation("Seeding initial data");

                var cust_1 = new Customer
                {
                    Name                = "Monney",
                    Vorname             = "Ebenezer",
                    Street              = "Street str.",
                    Hausnummer          = "123",
                    PLZ                 = "54365",
                    Ort                 = "Leverkusen",
                    Telefon             = "0179 299 9981",
                    Email               = "*****@*****.**",
                    Automodell          = "MB C-Kl. 200d",
                    Kennzeichen         = "K-AJ 7777",
                    Lagerplatz          = "F18",
                    Sommer              = false,
                    Winter              = true,
                    Reifensize          = "205 55 R16 91V",
                    Reifenmarke         = "Hankook Cept Evo 2",
                    Profiltiefe         = "1xkaputt, 3xdurch",
                    Dot                 = "3215",
                    Felgeninfo          = "Orig. 5x112, 66,6,",
                    Schraubensize       = "12x 1,5mm",
                    Damagestate         = "Gebraucht",
                    Notizenempfehlungen = "Felgenreparatur, Neu Reifen kaufen.",
                    History             = "Kunde seit 20.07.2017, Ersteinlagerung 20.07.2018 Sommer, W-einl. 01.11.2018, Sommereinlg. 01.04.2018.",
                    Gender              = Gender.Male,
                    CreatedDate         = DateTime.UtcNow,
                    UpdatedDate         = DateTime.UtcNow
                };
                var cust_2 = new Customer
                {
                    Name                = "Itachi",
                    Vorname             = "Uchiha",
                    Street              = "Montanusstr.",
                    Hausnummer          = "123",
                    PLZ                 = "44666",
                    Ort                 = "Köln",
                    Telefon             = "0179 299 9981",
                    Email               = "*****@*****.**",
                    Automodell          = "MB C-Kl. 200d",
                    Kennzeichen         = "K-AJ 7777",
                    Lagerplatz          = "B18",
                    Sommer              = false,
                    Winter              = true,
                    Reifensize          = "205 55 R16 91V",
                    Reifenmarke         = "Hankook Cept Evo 2",
                    Profiltiefe         = "1xkaputt, 3xdurch",
                    Dot                 = "3215",
                    Felgeninfo          = "Orig. 5x112, 66,6,",
                    Schraubensize       = "12x 1,5mm",
                    Damagestate         = "Gebraucht",
                    Notizenempfehlungen = "Felgenreparatur, Neu Reifen kaufen.",
                    History             = "Kunde seit 20.07.2017, Ersteinlagerung 20.07.2018 Sommer, W-einl. 01.11.2018, Sommereinlg. 01.04.2018.",
                    Gender              = Gender.Male,
                    CreatedDate         = DateTime.UtcNow,
                    UpdatedDate         = DateTime.UtcNow
                };
                var cust_3 = new Customer
                {
                    Name                = "Doe",
                    Vorname             = "John ",
                    Street              = "Kndndnde.",
                    Hausnummer          = "123",
                    PLZ                 = "44666",
                    Ort                 = "Düsseldorf",
                    Telefon             = "0179 299 9981",
                    Email               = "*****@*****.**",
                    Automodell          = "MB C-Kl. 200d",
                    Kennzeichen         = "K-AJ 7777",
                    Lagerplatz          = "A18",
                    Sommer              = false,
                    Winter              = true,
                    Reifensize          = "205 55 R16 91V",
                    Reifenmarke         = "Hankook Cept Evo 2",
                    Profiltiefe         = "1xkaputt, 3xdurch",
                    Dot                 = "3215",
                    Felgeninfo          = "Orig. 5x112, 66,6,",
                    Schraubensize       = "12x 1,5mm",
                    Damagestate         = "Gebraucht",
                    Notizenempfehlungen = "Felgenreparatur, Neu Reifen kaufen.",
                    History             = "Kunde seit 20.07.2017, Ersteinlagerung 20.07.2018 Sommer, W-einl. 01.11.2018, Sommereinlg. 01.04.2018.",
                    Gender              = Gender.Male,
                    CreatedDate         = DateTime.UtcNow,
                    UpdatedDate         = DateTime.UtcNow
                };

                ProductCategory prodCat_1 = new ProductCategory
                {
                    Name         = "None",
                    Description  = "Default category. Products that have not been assigned a category",
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };

                Product prod_1 = new Product
                {
                    Name            = "BMW M6",
                    Description     = "Yet another masterpiece from the world's best car manufacturer",
                    BuyingPrice     = 109775,
                    SellingPrice    = 114234,
                    UnitsInStock    = 12,
                    IsActive        = true,
                    ProductCategory = prodCat_1,
                    DateCreated     = DateTime.UtcNow,
                    DateModified    = DateTime.UtcNow
                };
                Product prod_2 = new Product
                {
                    Name            = "Nissan Patrol",
                    Description     = "A true man's choice",
                    BuyingPrice     = 78990,
                    SellingPrice    = 86990,
                    UnitsInStock    = 4,
                    IsActive        = true,
                    ProductCategory = prodCat_1,
                    DateCreated     = DateTime.UtcNow,
                    DateModified    = DateTime.UtcNow
                };


                Order ordr_1 = new Order
                {
                    Discount     = 500,
                    Cashier      = await _context.Users.FirstAsync(),
                    Customer     = cust_1,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow,
                    OrderDetails = new List <OrderDetail>()
                    {
                        new OrderDetail()
                        {
                            UnitPrice = prod_1.SellingPrice, Quantity = 1, Product = prod_1
                        },
                        new OrderDetail()
                        {
                            UnitPrice = prod_2.SellingPrice, Quantity = 1, Product = prod_2
                        },
                    }
                };
                Order ordr_2 = new Order
                {
                    Cashier      = await _context.Users.FirstAsync(),
                    Customer     = cust_2,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow,
                    OrderDetails = new List <OrderDetail>()
                    {
                        new OrderDetail()
                        {
                            UnitPrice = prod_2.SellingPrice, Quantity = 1, Product = prod_2
                        },
                    }
                };


                _context.Customers.Add(cust_1);
                _context.Customers.Add(cust_2);
                _context.Customers.Add(cust_3);

                _context.Products.Add(prod_1);
                _context.Products.Add(prod_2);

                _context.Orders.Add(ordr_1);
                _context.Orders.Add(ordr_2);

                await _context.SaveChangesAsync();

                _logger.LogInformation("Seeding initial data completed");
            }
        }
        public IssueDoc CreateIssueFromPicklist(PickListDetail picklistDetail,Order order,DateTime convertedEthDate,Issue stvLog,User user)
        {
            ReceivePallet receivePallet = new ReceivePallet();
            receivePallet.LoadByPrimaryKey(picklistDetail.ReceivePalletID);

            ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.LoadByPrimaryKey(receivePallet.ReceiveID);

            IssueDoc issueDoc = new IssueDoc();
            issueDoc.AddNew();
            issueDoc.BatchNo = picklistDetail.BatchNumber;
            if(!picklistDetail.IsColumnNull("Cost"))
            issueDoc.Cost = picklistDetail.Cost;
            issueDoc.Date = convertedEthDate;
            issueDoc.EurDate = DateTimeHelper.ServerDateTime;
            issueDoc.StoreId = picklistDetail.StoreID;
            issueDoc.STVID = stvLog.ID;
            issueDoc.IsTransfer = true;
            issueDoc.IssuedBy = user.FullName;
            issueDoc.ItemID = picklistDetail.ItemID;
            issueDoc.NoOfPack = picklistDetail.Packs;
            issueDoc.QtyPerPack = picklistDetail.QtyPerPack;
            issueDoc.Quantity = picklistDetail.QuantityInBU;
            issueDoc.OrderID = order.ID;
            issueDoc.UnitID = receiveDoc.UnitID;
            issueDoc.ManufacturerID = receiveDoc.ManufacturerId;
            issueDoc.SetColumn("UnitCost" ,receiveDoc.GetColumn("Cost"));
            issueDoc.SetColumn("SellingPrice"  ,receiveDoc.GetColumn("SellingPrice"));
            issueDoc.SetColumn("Margin", receiveDoc.GetColumn("Margin"));
            issueDoc.SetColumn("PhysicalStoreID", receiveDoc.GetColumn("PhysicalStoreID"));
            issueDoc.PLDetailID = picklistDetail.ID;
            issueDoc.RecievDocID = picklistDetail.ReceiveDocID;
            issueDoc.SetColumn("InventoryPeriodID", receiveDoc.GetColumn("InventoryPeriodID"));
            // This is a deprecated field
            issueDoc.RecomendedQty = 0;// picklistDetail.Packs;
            issueDoc.RefNo = stvLog.IDPrinted.ToString();
            issueDoc.DispatchConfirmed = false;
            issueDoc.Save();

            //substract from QuantityLeft
            receiveDoc.QuantityLeft -= picklistDetail.QuantityInBU;
            if(receiveDoc.QuantityLeft < 0)
            {
                receiveDoc.QuantityLeft = 0;
            }
            receiveDoc.Save();

            receivePallet.Balance -= picklistDetail.QuantityInBU;
            if(receivePallet.Balance < 0)
            {
                receivePallet.Balance=0;
            }

            receivePallet.ReservedStock -= picklistDetail.Packs;
            if(receivePallet.ReservedStock < 0)
            {
                receivePallet.ReservedStock = 0;
            }
            receivePallet.Save();

            return issueDoc;
        }
Esempio n. 9
0
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.PaymentType = null;
		}
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.SystemUser = null;
		}
Esempio n. 11
0
 partial void UpdateOrder(Order instance);
        private bool saveData()
        {
            calculateTotal();
            if (validator1.Validate() && ValidateData())
            {
                if (cbxCustomer.SelectedValue == null || cbxCustomer.SelectedIndex <= 0)
                {
                    MessageBox.Show("Bạn cần có một khách hàng cho phiếu này!");
                    return false;
                }
                DialogResult dialogResult = Preview();
                if (dialogResult == DialogResult.OK)
                {
                    XKNumber = PrintPreview.XKNumber;
                    BHNumber = PrintPreview.BHNumber;
                    double discount = 0;
                    Double.TryParse(txtDiscount.WorkingText, out discount);
                    DateTime createdDate = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate();

                    double vat = 0;
                    Double.TryParse(txtVAT.WorkingText, out vat);
                    int userId = 0;
                    if (Global.CurrentUser != null)
                    {
                        userId = Global.CurrentUser.Id;
                    }
                    else
                    {
                        MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    if (order != null)//update
                    {
                        #region Update

                        order.CustId = (int)cbxCustomer.SelectedValue;
                        order.Discount = discount;
                        order.Note = txtNote.Text;
                        order.VAT = vat;
                        order.OrderCode = txtOrderCode.Text;
                        order.Reason = txtReason.Text;
                        order.WareHouse = txtWare.Text;
                        order.Total = totalWithTax;
                        order.UpdatedDate = createdDate;

                        #region Update Order Detail

                        string msg = "";
                        int error = 0, amount_change = 0;
                        ProductLog pl, newpl;
                        OrderDetail prd;

                        // Check old data

                        OrderDetailService orderDetailService = new OrderDetailService();
                        List<OrderDetail> deleted_details = old_orderDetails.Where(x => !orderDetails.Select(y => y.ProductId.ToString() + '_' +
                            y.AttributeId.ToString() + '_' + y.UnitId.ToString()).Contains(x.ProductId.ToString() + '_' +
                            x.AttributeId.ToString() + '_' + x.UnitId.ToString())).ToList();
                        List<OrderDetail> updated_details = old_orderDetails.Where(x => orderDetails.Select(y => y.ProductId.ToString() + '_' +
                            y.AttributeId.ToString() + '_' + y.UnitId.ToString()).Contains(x.ProductId.ToString() + '_' +
                            x.AttributeId.ToString() + '_' + x.UnitId.ToString())).ToList();
                        List<OrderDetail> new_details = orderDetails.Where(x => !old_orderDetails.Select(y => y.ProductId.ToString() + '_' +
                            y.AttributeId.ToString() + '_' + y.UnitId.ToString()).Contains(x.ProductId.ToString() + '_' +
                            x.AttributeId.ToString() + '_' + x.UnitId.ToString())).ToList();
                        foreach (OrderDetail item in updated_details)
                        {
                            pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            prd = orderDetails.Where(x => x.ProductId == item.ProductId && x.AttributeId == item.AttributeId &&
                                x.UnitId == item.UnitId).FirstOrDefault();
                            amount_change = Convert.ToInt32(prd.NumberUnit - item.NumberUnit);
                            if (amount_change > 0 && pl.AfterNumber - amount_change < 0) // Tang nguyen lieu
                            {
                                if (error == 0)
                                {
                                    msg += "Những sản phẩm sau đã bị SỬA nhưng không đảm bảo dữ liệu trong kho:\n";
                                    error = 1;
                                }
                                msg += "- " + productLogService.GetNameOfProductLog(pl) + " : " + amount_change.ToString() + "\n";
                            }
                        }
                        foreach (OrderDetail item in new_details)
                        {
                            pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            if (pl.AfterNumber - item.NumberUnit < 0)
                            {
                                if (error < 2)
                                {
                                    msg += "Những sản phẩm sau không đủ số lượng để tạo phiếu bán hàng:\n";
                                    error = 2;
                                }
                                msg += "- " + productLogService.GetNameOfProductLog(pl) + " còn : " + pl.AfterNumber + "\n";
                            }
                        }

                        if (error > 0)
                        {
                            MessageBox.Show(msg, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }

                        foreach (OrderDetail item in deleted_details)
                        {
                            pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            newpl = new ProductLog()
                            {
                                ProductId = item.ProductId,
                                AttributeId = item.AttributeId,
                                UnitId = item.UnitId,
                                BeforeNumber = pl.AfterNumber,
                                Amount = item.NumberUnit,
                                AfterNumber = pl.AfterNumber + item.NumberUnit,
                                RecordCode = order.OrderCode,
                                Status = BHConstant.ACTIVE_STATUS,
                                Direction = BHConstant.DIRECTION_IN,
                                UpdatedDate = createdDate
                            };
                            productLogService.AddProductLog(newpl);
                        }
                        foreach (OrderDetail od in orderDetails)
                        {
                            od.OrderId = order.Id;
                            if (od.ProductId > 0 && od.AttributeId > 0 && od.UnitId > 0)
                            {
                                totalCommission += od.Commission;
                                OrderDetail tmp_ode = old_orderDetails.Where(x => x.ProductId == od.ProductId &&
                                    x.AttributeId == od.AttributeId && x.UnitId == od.UnitId && x.OrderId == order.Id).FirstOrDefault();
                                if (tmp_ode != null)
                                {
                                    double amount = tmp_ode.NumberUnit - od.NumberUnit;
                                    bool ret = orderDetailService.UpdateOrderDetail(od);
                                    //Save in Production Log
                                    if (amount != 0)
                                    {
                                        pl = productLogService.GetProductLog(od.ProductId, od.AttributeId, od.UnitId);
                                        newpl = new ProductLog()
                                        {
                                            ProductId = od.ProductId,
                                            AttributeId = od.AttributeId,
                                            UnitId = od.UnitId,
                                            BeforeNumber = pl.AfterNumber,
                                            Amount = Math.Abs(amount),
                                            AfterNumber = pl.AfterNumber + amount,
                                            RecordCode = order.OrderCode,
                                            Status = BHConstant.ACTIVE_STATUS,
                                            Direction = amount > 0 ? BHConstant.DIRECTION_IN : BHConstant.DIRECTION_OUT,
                                            UpdatedDate = createdDate
                                        };
                                        productLogService.AddProductLog(newpl);
                                    }
                                }
                                else
                                {
                                    bool ret = (od.Id != null && od.Id > 0) ? orderDetailService.UpdateOrderDetail(od) 
                                        : orderDetailService.AddOrderDetail(od);
                                    //Save in Production Log
                                    pl = productLogService.GetProductLog(od.ProductId, od.AttributeId, od.UnitId);
                                    newpl = new ProductLog()
                                    {
                                        ProductId = od.ProductId,
                                        AttributeId = od.AttributeId,
                                        UnitId = od.UnitId,
                                        BeforeNumber = pl.AfterNumber,
                                        Amount = od.NumberUnit,
                                        AfterNumber = pl.AfterNumber - od.NumberUnit,
                                        RecordCode = order.OrderCode,
                                        Status = BHConstant.ACTIVE_STATUS,
                                        Direction = BHConstant.DIRECTION_OUT,
                                        UpdatedDate = createdDate
                                    };
                                    productLogService.AddProductLog(newpl);
                                }
                            }
                        }

                        OrderService orderService = new OrderService();
                        bool result = orderService.UpdateOrder(order);

                        #endregion

                        #region KH & NV

                        CustomerLogService cls = new CustomerLogService();
                        CustomerLog newest = cls.GetCustomerLog(order.OrderCode);
                        if (newest != null)
                        {
                            newest.Amount = totalWithTax;
                            cls.UpdateCustomerLog(newest);
                        }

                        int salerId = (int)order.Customer.SalerId;
                        if (salerId > 0)
                        {
                            EmployeeLogService els = new EmployeeLogService();
                            EmployeeLog order_el = els.SelectEmployeeLogByWhere(x => x.RecordCode == order.OrderCode).FirstOrDefault();
                            if (order_el != null)
                            {
                                order_el.Amount = totalCommission;
                                els.UpdateEmployeeLog(order_el);
                            }
                        }

                        #endregion

                        if (result)
                        {
                            MessageBox.Show("Phiếu bán hàng đã được cập nhật thành công");
                            this.Close();
                            return true;
                        }
                        else
                        {
                            MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }

                        #endregion
                    }
                    else//add new
                    {
                        #region Create New

                        ProductLog pl, newpl;
                        string msg = "";
                        int error = 0;
                        foreach (OrderDetail item in orderDetails)
                        {
                            pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            if (pl.AfterNumber - item.NumberUnit < 0)
                            {
                                if (error == 0)
                                {
                                    msg += "Những sản phẩm sau không đủ số lượng để tạo phiếu bán hàng:\n";
                                    error = 1;
                                }
                                msg += "- " + productLogService.GetNameOfProductLog(pl) + " còn : " + pl.AfterNumber + "\n";
                            }
                        }

                        if (error > 0)
                        {
                            MessageBox.Show(msg, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }

                        SeedService ss = new SeedService();
                        order = new Order
                        {
                            CustId = cbxCustomer.SelectedValue != null ? (int)cbxCustomer.SelectedValue : 0,
                            Discount = discount,
                            Note = txtNote.Text,
                            VAT = vat,
                            OrderCode = ss.AddSeedID(BHConstant.PREFIX_FOR_ORDER),
                            CreatedDate = createdDate,
                            UserId = userId,
                            Reason = txtReason.Text,
                            WareHouse = txtWare.Text,
                            Total = totalWithTax
                        };
                        OrderService orderService = new OrderService();
                        bool result = orderService.AddOrder(order);
                        long newOrderId = -1;
                        try
                        {
                            newOrderId = order.Id;// BaoHienRepository.GetMaxId<Order>();
                        }
                        catch
                        {
                            MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }

                        #region New Order Detail

                        OrderDetailService orderDetailService = new OrderDetailService();
                        foreach (OrderDetail od in orderDetails)
                        {
                            if (od.ProductId > 0 && od.AttributeId > 0 && od.UnitId > 0)
                            {
                                od.OrderId = (int)newOrderId;
                                bool ret = orderDetailService.AddOrderDetail(od);
                                totalCommission += od.Commission;

                                //Save in Production Log
                                pl = productLogService.GetProductLog(od.ProductId, od.AttributeId, od.UnitId);
                                newpl = new ProductLog()
                                {
                                    ProductId = od.ProductId,
                                    AttributeId = od.AttributeId,
                                    UnitId = od.UnitId,
                                    BeforeNumber = pl.AfterNumber,
                                    Amount = od.NumberUnit,
                                    AfterNumber = pl.AfterNumber - od.NumberUnit,
                                    RecordCode = order.OrderCode,
                                    Status = BHConstant.ACTIVE_STATUS,
                                    Direction = BHConstant.DIRECTION_OUT,
                                    UpdatedDate = createdDate
                                };
                                productLogService.AddProductLog(newpl);
                            }
                        }

                        #endregion

                        #region KH & NV

                        CustomerLogService cls = new CustomerLogService();
                        CustomerLog cl = new CustomerLog
                        {
                            CustomerId = order.CustId,
                            RecordCode = order.OrderCode,
                            Amount = totalWithTax,
                            Direction = BHConstant.DIRECTION_OUT,
                            CreatedDate = createdDate
                        };
                        result = cls.AddCustomerLog(cl);

                        int salerId = (int)order.Customer.SalerId;
                        if (salerId > 0)
                        {
                            EmployeeLogService els = new EmployeeLogService();
                            EmployeeLog newel = new EmployeeLog
                            {
                                EmployeeId = salerId,
                                RecordCode = order.OrderCode,
                                Amount = totalCommission,
                                CreatedDate = createdDate
                            };
                            result = els.AddEmployeeLog(newel);
                        }

                        #endregion

                        if (result)
                        {
                            MessageBox.Show("Phiếu bán hàng đã được tạo thành công");
                            this.Close();
                            return true;
                        }
                        else
                        {
                            MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                        #endregion
                    }
                }
                return false;
            }
            else
            {
                MessageBox.Show("Vui lòng kiểm tra các thông tin cần thiết!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
        }
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Customer = null;
		}
Esempio n. 14
0
 public Host FindHost(Order order)
 {
     throw new NotImplementedException();
 }
 private void btnPrint_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("In phiếu bán hàng mà không có bất kì sự thay đổi nào hết ?", "Xác nhận", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.OK)
     {
         order = old_order;
         //orderDetails = new BindingList<OrderDetail>(old_orderDetails);
         PrintDialog pd = new PrintDialog();
         pd.PrinterSettings = new PrinterSettings();
         if (DialogResult.OK == pd.ShowDialog(this))
         {
             this.Cursor = Cursors.AppStarting;
             Print(pd.PrinterSettings.PrinterName);
         }
     }
 }
Esempio n. 16
0
 public GuestRequest FindGuestRequest(Order order)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
 public bool UpdateOrder(Order order)
 {
     throw new NotImplementedException();
 }
        public Issue CreateSTVLog(int? stvLogID, bool convertDNtoSTV, PickList pickList, Order order, int? supplierId, int activityId, bool hasInsurance, int userId)
        {
            int paymentTypeID = order.PaymentTypeID;
            Issue stvLog = new Issue();
            stvLog.AddNew();
            stvLog.PrintedDate = DateTimeHelper.ServerDateTime;
            stvLog.RefNo = order.RefNo;
            stvLog.PickListID = pickList.ID;
            if(supplierId != null)
            {
                stvLog.SupplierID = supplierId.Value;
            }
            stvLog.UserID = userId;
            stvLog.StoreID = activityId;
             stvLog.IsDeliveryNote = (paymentTypeID == PaymentType.Constants.DELIVERY_NOTE);
            stvLog.HasInsurance = hasInsurance;
            stvLog.FiscalYearID = FiscalYear.Current.ID;

            var activity = new Activity();
            activity.LoadByPrimaryKey(activityId);
            stvLog.AccountID = activity.AccountID;

            if (paymentTypeID == PaymentType.Constants.DELIVERY_NOTE)
            {
                stvLog.DocumentTypeID = DocumentType.documentTypes.DeliveryNote.DocumentTypeID;
            }
            else if (paymentTypeID == PaymentType.Constants.CASH)
            {
                stvLog.DocumentTypeID = DocumentType.documentTypes.Cash.DocumentTypeID;
            }
            else if (paymentTypeID == PaymentType.Constants.CREDIT)
            {
                stvLog.DocumentTypeID = DocumentType.documentTypes.Credit.DocumentTypeID;
            }
            else if (paymentTypeID == PaymentType.Constants.STV)
            {
                stvLog.DocumentTypeID = DocumentType.documentTypes.STV.DocumentTypeID;
            }
            else if(paymentTypeID == PaymentType.Constants.ERROR_CORRECTION)
            {
                stvLog.DocumentTypeID = DocumentType.documentTypes.ErrorCorrection.DocumentTypeID;
            }
            else if(paymentTypeID == PaymentType.Constants.INVENTORY)
            {
                stvLog.DocumentTypeID = DocumentType.documentTypes.EndingBalance.DocumentTypeID;
            }
            else if (paymentTypeID == PaymentType.Constants.DISPOSAL) // This should probably have a disposal document type, but for now, STV
            {
                stvLog.DocumentTypeID = DocumentType.documentTypes.STV.DocumentTypeID;
            }
            stvLog.IDPrinted = DocumentType.GetNextSequenceNo(stvLog.DocumentTypeID, stvLog.AccountID, stvLog.FiscalYearID);

            if (!order.IsColumnNull("RequestedBy"))
            {
                stvLog.ReceivingUnitID = order.RequestedBy;
            }
            if (stvLogID.HasValue)
            {
                stvLog.IsReprintOf = stvLogID.Value;
                //this means the STV is from replaced
                Issue s = new Issue();
                s.LoadByPrimaryKey(stvLogID.Value);

                stvLog.IsDeliveryNote = false;
                if (!s.IsColumnNull("IsDeliveryNote") && s.IsDeliveryNote && !convertDNtoSTV)
                {
                    stvLog.IsDeliveryNote = true;
                }
            }
            stvLog.Save();
            return stvLog;
        }
 /// <summary>
 /// Create a new Order object.
 /// </summary>
 /// <param name="orderId">Initial value of the OrderId property.</param>
 /// <param name="orderCode">Initial value of the OrderCode property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 /// <param name="createBy">Initial value of the CreateBy property.</param>
 /// <param name="custId">Initial value of the CustId property.</param>
 /// <param name="total">Initial value of the Total property.</param>
 /// <param name="vAT">Initial value of the VAT property.</param>
 public static Order CreateOrder(global::System.Int32 orderId, global::System.String orderCode, global::System.DateTime createdDate, global::System.Int32 createBy, global::System.Int32 custId, global::System.Double total, global::System.Double vAT)
 {
     Order order = new Order();
     order.OrderId = orderId;
     order.OrderCode = orderCode;
     order.CreatedDate = createdDate;
     order.CreateBy = createBy;
     order.CustId = custId;
     order.Total = total;
     order.VAT = vAT;
     return order;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrders(Order order)
 {
     base.AddObject("Orders", order);
 }
 public void loadDataForEditOrder(int orderId)
 {
     if (!Global.isAdmin())
     {
         disableForm();
     }
     cbxCustomer.Enabled = false; // Don't allow change Customer
     isUpdating = true;
     OrderService orderService = new OrderService();
     order = orderService.GetOrder(orderId);
     old_order = order;
     if (order != null)
     {
         if (orderDetails == null)
         {
             OrderDetailService orderDetailService = new OrderDetailService();
             orderDetails = new BindingList<OrderDetail>(orderDetailService.SelectOrderDetailByWhere(o => o.OrderId == order.Id));
             old_orderDetails = new List<OrderDetail>();
             foreach (OrderDetail od in orderDetails)
             {
                 old_orderDetails.Add(new OrderDetail
                     {
                         AttributeId = od.AttributeId,
                         ProductId = od.ProductId,
                         UnitId = od.UnitId,
                         OrderId = od.OrderId,
                         NumberUnit = od.NumberUnit
                     });
             }
         }
     }            
 }
Esempio n. 22
0
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.DeliveryType = this;
		}
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Customer = this;
		}
Esempio n. 24
0
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.OrderStatuse = this;
		}
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.SystemUser = this;
		}
Esempio n. 26
0
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.OrderStatuse = null;
		}
Esempio n. 27
0
 partial void InsertOrder(Order instance);
Esempio n. 28
0
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.PaymentType = this;
		}
Esempio n. 29
0
 partial void DeleteOrder(Order instance);
Esempio n. 30
0
 public void addOrder(Order order)
 {
     order.OrderKey = Configuration.OrderKey++;
     DS.DataSource.OrderList.Add(order.Copy());
 }