示例#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);
            }
        }
示例#2
0
        protected virtual void INItemXRef_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            var xRef = (INItemXRef)e.Row;

            if (e.Operation.Command().IsIn(PXDBOperation.Insert, PXDBOperation.Update) &&
                xRef.AlternateType.IsNotIn(INAlternateType.VPN, INAlternateType.CPN))
            {
                xRef.BAccountID = 0;
                sender.Normalize();
            }
        }
        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;
            }
        }
        public override void RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            if (e.Operation == PXDBOperation.Insert)
            {
                originalRefNbr = (string)sender.GetValue(e.Row, _FieldName);

                if (SetRefNbr(sender, e.Row) == false)
                {
                    throw new AutoNumberException();
                }
                else
                {
                    sender.Normalize();
                }
            }
        }
        public override void RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            if (e.TranStatus == PXTranStatus.Aborted && e.Operation == PXDBOperation.Insert)
            {
                if (originalRefNbr != null)
                {
                    sender.SetValue(e.Row, _FieldName, originalRefNbr);
                    sender.Normalize();
                }
            }

            if (e.TranStatus == PXTranStatus.Aborted || e.TranStatus == PXTranStatus.Completed)
            {
                originalRefNbr = null;
            }
        }
示例#6
0
        public virtual void RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
        {
            PXCache cache = sender.Graph.Caches[typeof(CATran)];

            if (e.TranStatus == PXTranStatus.Open)
            {
                object key = sender.GetValue(e.Row, _FieldOrdinal);
            }
            else if (e.TranStatus == PXTranStatus.Aborted)
            {
                object key = sender.GetValue(e.Row, _FieldOrdinal);
                if (_KeyToAbort != null && (long)_KeyToAbort < 0L)
                {
                    sender.SetValue(e.Row, _FieldOrdinal, _KeyToAbort);
                    foreach (CATran data in cache.Inserted)
                    {
                        if (Equals(key, data.TranID))
                        {
                            data.TranID = (long)_KeyToAbort;
                            cache.ResetPersisted(data);
                            break;
                        }
                    }
                }
                else
                {
                    foreach (CATran data in cache.Updated)
                    {
                        if (object.Equals(key, data.TranID))
                        {
                            cache.ResetPersisted(data);
                        }
                    }
                }

                cache.Normalize();
            }
            else
            {
                object key = sender.GetValue(e.Row, _FieldOrdinal);
                foreach (CATran data in cache.Inserted)
                {
                    if (object.Equals(key, data.TranID))
                    {
                        cache.RaiseRowPersisted(data, PXDBOperation.Insert, e.TranStatus, e.Exception);
                        cache.SetStatus(data, PXEntryStatus.Notchanged);
                        PXTimeStampScope.PutPersisted(cache, data, sender.Graph.TimeStamp);
                        cache.ResetPersisted(data);
                    }
                }
                foreach (CATran data in cache.Updated)
                {
                    if (object.Equals(key, data.TranID))
                    {
                        cache.RaiseRowPersisted(data, PXDBOperation.Update, e.TranStatus, e.Exception);
                        cache.SetStatus(data, PXEntryStatus.Notchanged);
                        PXTimeStampScope.PutPersisted(cache, data, sender.Graph.TimeStamp);
                        cache.ResetPersisted(data);
                    }
                }
                foreach (CATran data in cache.Deleted)
                {
                    cache.RaiseRowPersisted(data, PXDBOperation.Delete, e.TranStatus, e.Exception);
                    cache.SetStatus(data, PXEntryStatus.Notchanged);
                    PXTimeStampScope.PutPersisted(cache, data, sender.Graph.TimeStamp);
                    cache.ResetPersisted(data);
                }
                cache.IsDirty = false;
                cache.Normalize();
            }
        }
示例#7
0
        public virtual void RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            object  key   = sender.GetValue(e.Row, _FieldOrdinal);
            PXCache cache = sender.Graph.Caches[typeof(CATran)];
            CATran  info  = null;

            if (key != null)
            {
                //do not read cached record in release processes
                if ((info = PXSelectReadonly <CATran, Where <CATran.tranID, Equal <Required <CATran.tranID> > > > .Select(sender.Graph, key)) != null)
                {
                    CATran cached = (CATran)cache.Locate(info);
                    if (cached != null)
                    {
                        if ((cached.OrigModule != null && info.OrigModule != null && cached.OrigModule != info.OrigModule) ||
                            (cached.OrigRefNbr != null && info.OrigRefNbr != null && cached.OrigRefNbr != info.OrigRefNbr) ||
                            (cached.OrigTranType != null && info.OrigTranType != null && cached.OrigTranType != info.OrigTranType))
                        {
                            // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details)
                            throw new PXException(Messages.CouldNotInsertCATran);
                        }
                        if (cache.GetStatus(cached) == PXEntryStatus.Notchanged)
                        {
                            PXCache <CATran> .RestoreCopy(cached, info);
                        }
                        info = cached;
                    }
                    else
                    {
                        cache.SetStatus(info, PXEntryStatus.Notchanged);
                    }
                }

                if ((long)key < 0L && info == null)
                {
                    info        = new CATran();
                    info.TranID = (long)key;
                    info        = (CATran)cache.Locate(info);
                }

                if (info == null)
                {
                    key = null;
                    sender.SetValue(e.Row, _FieldOrdinal, null);
                }
            }

            if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Delete)
            {
                if (info != null)
                {
                    cache.Delete(info);
                    cache.PersistDeleted(info);
                }
            }
            else if (info == null)
            {
                if (!this.NeedPreventCashTransactionCreation(sender, e.Row))
                {
                    info = DefaultValues(sender, new CATran(), e.Row);

                    if (info != null)
                    {
                        info = (CATran)cache.Insert(info);
                        if (!(info.TranID < 0L))
                        {
                            throw new PXException(Messages.CouldNotInsertCATran);
                        }

                        // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details)
                        sender.SetValue(e.Row, _FieldOrdinal, info.TranID);
                        _KeyToAbort = info.TranID;
                        cache.PersistInserted(info);
                        long id = info.TranID ?? 0;
                        if (id == 0 || id < 0)
                        {
                            throw new PXException(Messages.CATranNotSaved, sender.GetItemType().Name);
                        }
                        sender.SetValue(e.Row, _FieldOrdinal, id);
                        info.TranID = id;
                        cache.Normalize();
                    }
                }
            }
            else if (info.TranID < 0L)
            {
                info = DefaultValues(sender, PXCache <CATran> .CreateCopy(info), e.Row);
                if (info != null)
                {
                    info = (CATran)cache.Update(info);

                    sender.SetValue(e.Row, _FieldOrdinal, info.TranID);
                    _KeyToAbort = info.TranID;
                    cache.PersistInserted(info);
                    long id = info.TranID ?? 0;
                    if (id == 0 || id < 0)
                    {
                        throw new PXException(Messages.CATranNotSaved, sender.GetItemType().Name);
                    }
                    sender.SetValue(e.Row, _FieldOrdinal, id);
                    info.TranID = id;
                    cache.Normalize();
                }
            }
            else
            {
                CATran copy = PXCache <CATran> .CreateCopy(info);

                copy = DefaultValues(sender, copy, e.Row);
                if (copy != null)
                {
                    if ((copy.OrigModule != null && info.OrigModule != null && copy.OrigModule != info.OrigModule) ||
                        (copy.OrigRefNbr != null && info.OrigRefNbr != null && copy.OrigRefNbr != info.OrigRefNbr) ||
                        (copy.OrigTranType != null && info.OrigTranType != null && copy.OrigTranType != info.OrigTranType))
                    {
                        // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details)
                        throw new PXException(Messages.CouldNotInsertCATran);
                    }
                    info = (CATran)cache.Update(copy);
                    //to avoid another process updated DefaultValues will return null for Released docs, except for GLTran
                    cache.PersistUpdated(info);
                }
                //JournalEntry is usually persisted prior to ReleaseGraph to obtain BatchNbr reference, read info should contain set Released flag
                else if (info.Released == false)
                {
                    key = null;
                    sender.SetValue(e.Row, _FieldOrdinal, null);

                    cache.Delete(info);
                }
            }
            foreach (CATran toDelete in cache.Deleted)
            {
                cache.PersistDeleted(toDelete);
            }
        }