Ejemplo n.º 1
0
 private Item CreateItem(Ordering.PurchaseOrderItem item)
 {
     return(new Item()
     {
         ItemID = item.ItemID,
         VendorID = item.Vendor.VendorID,
         VendorName = item.Vendor.VendorName,
         PartNum = item.PartNum,
         Description = item.Description,
         UnitPrice = item.UnitPrice,
         InventoryItemID = item.InventoryItemID,
         Active = item.Active
     });
 }
Ejemplo n.º 2
0
        public Item Add(string partNum, string description, double unitPrice, int vendorId, int?inventoryItemId)
        {
            var item = new Ordering.PurchaseOrderItem()
            {
                Active          = true,
                Description     = description,
                InventoryItemID = inventoryItemId,
                PartNum         = partNum,
                UnitPrice       = unitPrice,
                Vendor          = DataSession.Single <Ordering.Vendor>(vendorId)
            };

            DataSession.Insert(item);

            return(CreateItem(item));
        }
Ejemplo n.º 3
0
        private IList <Ordering.PurchaseOrderDetail> GetDetailsForCopy(Ordering.PurchaseOrder po, Ordering.PurchaseOrder copy, Ordering.Vendor vendor)
        {
            var currentClientId = Context.CurrentUser.ClientID;

            IList <Ordering.PurchaseOrderDetail> details;

            if (po.Client.ClientID == currentClientId || po.Vendor.ClientID == 0)
            {
                // current user is copying own order, or store manager vendor
                details = po.Details.Select(x => new Ordering.PurchaseOrderDetail()
                {
                    Category = x.Category,
                    IsInventoryControlled = x.IsInventoryControlled,
                    Item            = x.Item,
                    PurchaseOrder   = copy,
                    Quantity        = x.Quantity,
                    ToInventoryDate = null,
                    Unit            = x.Unit,
                    UnitPrice       = x.UnitPrice
                }).ToList();
            }
            else
            {
                // current user is copying another user's order

                details = new List <Ordering.PurchaseOrderDetail>();

                // check for items for the current user that have the same description and partnum as the po detail items
                foreach (var d in po.Details)
                {
                    var i = vendor.Items.FirstOrDefault(x =>
                                                        PurchaseOrderItems.CleanString(x.Description) == PurchaseOrderItems.CleanString(d.Item.Description) &&
                                                        PurchaseOrderItems.CleanString(x.PartNum) == PurchaseOrderItems.CleanString(d.Item.PartNum));

                    if (i == null)
                    {
                        // make a copy of the item
                        i = new Ordering.PurchaseOrderItem()
                        {
                            Active          = true,
                            Description     = d.Item.Description,
                            Details         = new List <Ordering.PurchaseOrderDetail>(),
                            InventoryItemID = d.Item.InventoryItemID,
                            PartNum         = d.Item.PartNum,
                            UnitPrice       = d.Item.UnitPrice,
                            Vendor          = vendor
                        };

                        DataSession.Insert(i);

                        vendor.Items.Add(i);
                    }
                    else
                    {
                        i.Active = true; //just in case
                    }

                    var detail = new Ordering.PurchaseOrderDetail()
                    {
                        Category = d.Category,
                        IsInventoryControlled = d.IsInventoryControlled,
                        Item            = i,
                        PurchaseOrder   = copy,
                        Quantity        = d.Quantity,
                        ToInventoryDate = null,
                        Unit            = d.Unit,
                        UnitPrice       = d.UnitPrice
                    };

                    details.Add(detail);
                }
            }

            return(details);
        }