Esempio n. 1
0
        public static bool AddSupplyOrder(SupplyOrder supplyOrder)
        {
            Log.Info("Adding new supply order");
            if (!SupplyOrderDb.BeginUpdateOrders())
            {
                return(false);
            }

            if (!SupplyOrderDb.AddSupplyOrder(supplyOrder.Id, supplyOrder.SupplierId,
                                              supplyOrder.Paid, supplyOrder.DateTime, supplyOrder.Note, supplyOrder.UserId,
                                              supplyOrder.Total))
            {
                Log.Debug(supplyOrder);
                return(false);
            }

            foreach (var entry in supplyOrder.OrderEntries)
            {
                if (!SupplyOrderDb.AddSupplyOrderEntry(entry.OrderId, entry.ItemId, entry.Quantity,
                                                       entry.Price))
                {
                    Log.Debug(supplyOrder);
                    return(false);
                }
            }

            return(SupplyOrderDb.FinalizeOrder());
        }
Esempio n. 2
0
        public static IEnumerable <SupplyOrder> GetDueSupplyOrders(int supplierId)
        {
            var reader = SupplyOrderDb.GetDueSupplyOrders(supplierId).CreateDataReader();

            while (reader.Read())
            {
                var id       = int.Parse(reader["SupplyOrder_ID"].ToString());
                var sId      = int.Parse(reader["Supplier_ID"].ToString());
                var sName    = reader["Name"].ToString();
                var entries  = GetSupplyOrderEntries(id);
                var dateTime = DateTime.Parse(reader["DateTime"].ToString());
                var note     = reader["Note"].ToString();
                var uId      = int.Parse(reader["User_ID"].ToString());
                var sPaid    = bool.Parse(reader["Paid"].ToString());

                var newOrder = new SupplyOrder(id, uId)
                {
                    SupplierId   = sId,
                    SupplierName = sName,
                    OrderEntries = entries.ToList(),
                    Note         = note,
                    DateTime     = dateTime,
                    Paid         = sPaid
                };

                yield return(newOrder);
            }
            reader.Close();
        }
Esempio n. 3
0
        public static bool ReverseSupplyOrder(SupplyOrder supplyOrder, int userId)
        {
            Log.Info("Reverse supply orders");
            if (!SupplyOrderDb.BeginUpdateOrders())
            {
                return(false);
            }

            if (!SupplyOrderDb.UpdateSupplyOrder(supplyOrder.Id, true))
            {
                Log.Debug(supplyOrder);
                return(false);
            }

            supplyOrder.Note = "--ReversedOrder (ReferenceOrderId: " + supplyOrder.Id + ")";
            supplyOrder.Id   = GetNextOrderId();
            supplyOrder.Paid = true;

            if (!SupplyOrderDb.ReverseSupplyOrder(supplyOrder.Id, supplyOrder.SupplierId,
                                                  supplyOrder.Paid, DateTime.Now, supplyOrder.Note, userId, supplyOrder.Total))
            {
                Log.Debug(supplyOrder);
                return(false);
            }

            foreach (var entry in supplyOrder.OrderEntries)
            {
                if (!SupplyOrderDb.ReverseSupplyOrderEntry(supplyOrder.Id, entry.ItemId, entry.Quantity,
                                                           entry.Price))
                {
                    Log.Debug(entry);
                    return(false);
                }
            }

            return(SupplyOrderDb.FinalizeOrder());
        }
Esempio n. 4
0
        public static IEnumerable <SupplyOrder> GetSupplyOrders(bool islimited, string orderId = "%", string supplierId = "%",
                                                                string supplierName            = "%", string itemName = "%", string date = "%", string paid = "%")
        {
            int limit = 50000;

            if (islimited)
            {
                limit = 100;
            }
            var reader = SupplyOrderDb.GetSupplyOrders(orderId, supplierId, supplierName, itemName, date, paid, limit).CreateDataReader();

            while (reader.Read())
            {
                var id       = int.Parse(reader["SupplyOrder_ID"].ToString());
                var sId      = int.Parse(reader["Supplier_ID"].ToString());
                var sName    = reader["Name"].ToString();
                var entries  = GetSupplyOrderEntries(id);
                var dateTime = DateTime.Parse(reader["DateTime"].ToString());
                var note     = reader["Note"].ToString();
                var uId      = int.Parse(reader["User_ID"].ToString());
                var sPaid    = bool.Parse(reader["Paid"].ToString());

                var newOrder = new SupplyOrder(id, uId)
                {
                    SupplierId   = sId,
                    SupplierName = sName,
                    OrderEntries = entries.ToList(),
                    Note         = note,
                    DateTime     = dateTime,
                    Paid         = sPaid
                };

                yield return(newOrder);
            }
            reader.Close();
        }