Example #1
0
 private Detail CreateDetail(Ordering.PurchaseOrderDetail pod)
 {
     return(new Detail()
     {
         PODID = pod.PODID,
         POID = pod.PurchaseOrder.POID,
         ItemID = pod.Item.ItemID,
         PartNum = pod.Item.PartNum,
         Description = pod.Item.Description,
         CategoryID = pod.Category.CatID,
         CategoryName = pod.Category.CatName,
         CategoryNumber = pod.Category.CatNo,
         CategoryActive = pod.Category.Active,
         ParentID = pod.Category.ParentID,
         ParentCategoryName = FindParentCategory(pod).CatName,
         ParentCategoryNumber = FindParentCategory(pod).CatNo,
         ParentCategoryActive = FindParentCategory(pod).Active,
         Quantity = pod.Quantity,
         UnitPrice = pod.UnitPrice,
         Unit = pod.Unit,
         ToInventoryDate = pod.ToInventoryDate,
         IsInventoryControlled = pod.IsInventoryControlled,
         CreatedDate = pod.PurchaseOrder.CreatedDate,
         InventoryItemID = pod.Item.InventoryItemID
     });
 }
Example #2
0
        private Ordering.PurchaseOrderCategory FindParentCategory(Ordering.PurchaseOrderDetail pod)
        {
            Ordering.PurchaseOrderCategory p;

            if (pod.Category.IsParent())
            {
                p = pod.Category;
            }
            else
            {
                p = SelectParentCategories().First(x => x.CatID == pod.Category.ParentID);
            }

            return(p);
        }
Example #3
0
        public Detail Add(int poid, int itemId, int catId, double qty, string unit, double unitPrice)
        {
            var item = Require <Ordering.PurchaseOrderItem>(x => x.ItemID, itemId);

            var pod = new Ordering.PurchaseOrderDetail()
            {
                PurchaseOrder         = Require <Ordering.PurchaseOrder>(x => x.POID, poid),
                Item                  = item,
                Category              = Require <Ordering.PurchaseOrderCategory>(x => x.CatID, catId),
                IsInventoryControlled = item.InventoryItemID.HasValue,
                Quantity              = qty,
                Unit                  = unit,
                UnitPrice             = unitPrice
            };

            DataSession.Insert(pod);

            return(CreateDetail(pod));
        }
Example #4
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);
        }