Esempio n. 1
0
        public static void Update(PXGraph graph, int?vendorID, int?vendorLocationID, string curyID, int?inventoryID, int?subItemID, string uom, decimal curyCost)
        {
            if (curyCost <= 0 || string.IsNullOrEmpty(uom) ||
                vendorID == null ||
                vendorLocationID == null)
            {
                return;
            }

            PXCache cache = graph.Caches[typeof(POVendorInventoryPriceUpdate)];

            foreach (PXResult <InventoryItem, Vendor, Company> r in
                     PXSelectJoin <InventoryItem,
                                   LeftJoin <Vendor,
                                             On <Vendor.bAccountID, Equal <Required <Vendor.bAccountID> > >,
                                             CrossJoin <Company> >,
                                   Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .
                     Select(graph, vendorID, inventoryID))
            {
                InventoryItem item    = r;
                Vendor        vendor  = r;
                Company       company = r;
                if (item.InventoryID == null || vendor.BAccountID == null ||
                    (item.StkItem == true && subItemID == null))
                {
                    continue;
                }
                INSetup setup = new PXSetup <INSetup>(graph).Current;

                int?savedSubItemID = item.StkItem == true ? subItemID : null;

                POVendorInventory existVendorPrice = PXSelectReadonly <POVendorInventory,
                                                                       Where <POVendorInventory.inventoryID, Equal <Required <POVendorInventory.inventoryID> >,
                                                                              And <POVendorInventory.subItemID, Equal <Required <POVendorInventory.subItemID> >,
                                                                                   And <POVendorInventory.purchaseUnit, Equal <Required <POVendorInventory.purchaseUnit> >,
                                                                                        And <POVendorInventory.vendorID, Equal <Required <POVendorInventory.vendorID> >,
                                                                                             And <POVendorInventory.vendorLocationID, Equal <Required <POVendorInventory.vendorLocationID> > > > > > > >
                                                     .SelectWindowed(graph, 0, 1, item.InventoryID, savedSubItemID, uom, vendorID, vendorLocationID);

                string priceCuryID = (existVendorPrice != null ? existVendorPrice.CuryID : vendor.CuryID) ?? company.BaseCuryID;

                POVendorInventoryPriceUpdate vendorPrice = (POVendorInventoryPriceUpdate)cache.CreateInstance();
                vendorPrice.InventoryID      = inventoryID;
                vendorPrice.SubItemID        = savedSubItemID;
                vendorPrice.VendorID         = vendorID;
                vendorPrice.VendorLocationID = vendorLocationID;
                vendorPrice.PurchaseUnit     = uom;
                vendorPrice = (POVendorInventoryPriceUpdate)cache.Insert(vendorPrice);
                if (item.StkItem != true)
                {
                    vendorPrice.SubItemID = savedSubItemID;
                }
                vendorPrice.CuryID = priceCuryID;
                cache.Normalize();
                vendorPrice.Active = true;
                Decimal cost = ConventCury(graph, vendor.CuryRateTypeID, curyID, curyCost, priceCuryID);
                vendorPrice.LastPrice = ConvertUOM(graph, item, uom, cost, item.PurchaseUnit);
            }
        }
            protected override bool PrepareInsert(PXCache sender, object row, PXAccumulatorCollection columns)
            {
                if (!base.PrepareInsert(sender, row, columns))
                {
                    return(false);
                }

                POVendorInventoryPriceUpdate val = (POVendorInventoryPriceUpdate)row;

                columns.Update <POVendorInventoryPriceUpdate.curyID>(val.CuryID, PXDataFieldAssign.AssignBehavior.Replace);
                columns.Update <POVendorInventoryPriceUpdate.lastPrice>(val.LastPrice, PXDataFieldAssign.AssignBehavior.Replace);
                columns.Update <POVendorInventoryPriceUpdate.active>(val.Active, PXDataFieldAssign.AssignBehavior.Replace);
                return(true);
            }
        public static void Update(PXGraph graph, int?vendorID, int?vendorLocationID, string curyID, int?inventoryID, int?subItemID, string uom, decimal curyCost)
        {
            if (curyCost <= 0 || string.IsNullOrEmpty(uom) ||
                vendorID == null ||
                vendorLocationID == null)
            {
                return;
            }

            PXCache cache = graph.Caches[typeof(POVendorInventoryPriceUpdate)];

            foreach (PXResult <InventoryItem, Vendor, Company> r in
                     PXSelectJoin <InventoryItem,
                                   LeftJoinSingleTable <Vendor,
                                                        On <Vendor.bAccountID, Equal <Required <Vendor.bAccountID> > >,
                                                        CrossJoin <Company> >,
                                   Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .
                     Select(graph, vendorID, inventoryID))
            {
                InventoryItem item    = r;
                Vendor        vendor  = r;
                Company       company = r;
                if (item.InventoryID == null || vendor.BAccountID == null ||
                    (item.StkItem == true && subItemID == null))
                {
                    continue;
                }
                INSetup setup = PXSetupOptional <INSetup> .Select(graph);

                int?savedSubItemID = item.StkItem == true ? subItemID : null;

                POVendorInventoryPriceUpdate vendorPrice = (POVendorInventoryPriceUpdate)cache.CreateInstance();
                vendorPrice.InventoryID      = inventoryID;
                vendorPrice.SubItemID        = savedSubItemID;
                vendorPrice.VendorID         = vendorID;
                vendorPrice.VendorLocationID = vendorLocationID;
                vendorPrice.PurchaseUnit     = uom;
                vendorPrice = (POVendorInventoryPriceUpdate)cache.Insert(vendorPrice);
                if (item.StkItem != true)
                {
                    vendorPrice.SubItemID = savedSubItemID;
                }
                vendorPrice.CuryID = curyID;
                cache.Normalize();
                vendorPrice.Active    = true;
                vendorPrice.LastPrice = curyCost;
            }
        }