Exemple #1
0
        //Graph passed in function must be the one using newly created sub in details - otherwise save will fail (inserted subs will be created in other graph)
        protected static void GetLCVarianceAccountSub(ref int?aAccountID, ref int?aSubID, PXGraph aGraph, POReceiptLine aRow)
        {
            if (aRow.InventoryID.HasValue)
            {
                PXResult <InventoryItem, INPostClass> res = (PXResult <InventoryItem, INPostClass>) PXSelectJoin <InventoryItem,
                                                                                                                  LeftJoin <INPostClass, On <INPostClass.postClassID, Equal <InventoryItem.postClassID> > >,
                                                                                                                  Where <InventoryItem.inventoryID, Equal <Required <POLine.inventoryID> > > > .Select(aGraph, aRow.InventoryID);

                if (res != null)
                {
                    InventoryItem invItem   = (InventoryItem)res;
                    INPostClass   postClass = (INPostClass)res;
                    if ((bool)invItem.StkItem)
                    {
                        if (postClass == null)
                        {
                            throw new PXException(Messages.PostingClassIsNotDefinedForTheItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr);
                        }
                        INSite invSite = null;
                        if (aRow.SiteID != null)
                        {
                            invSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <POReceiptLine.siteID> > > > .Select(aGraph, aRow.SiteID);
                        }
                        if (aRow.LineType == POLineType.GoodsForDropShip)
                        {
                            aAccountID = INReleaseProcess.GetAcctID <INPostClass.cOGSAcctID>(aGraph, postClass.COGSAcctDefault, invItem, invSite, postClass);
                            if (aAccountID == null)
                            {
                                throw new PXException(Messages.COGSAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                            }
                            try
                            {
                                aSubID = INReleaseProcess.GetSubID <INPostClass.cOGSSubID>(aGraph, postClass.COGSAcctDefault, postClass.COGSSubMask, invItem, invSite, postClass);
                            }
                            catch (PXException ex)
                            {
                                if (postClass.COGSSubID == null ||
                                    string.IsNullOrEmpty(postClass.COGSSubMask) ||
                                    invItem.COGSSubID == null || invSite == null || invSite.COGSSubID == null)
                                {
                                    throw new PXException(Messages.COGSSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                                }
                                else
                                {
                                    throw ex;
                                }
                            }
                            if (aSubID == null)
                            {
                                throw new PXException(Messages.COGSSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                            }
                        }
                        else
                        {
                            aAccountID = INReleaseProcess.GetAcctID <INPostClass.lCVarianceAcctID>(aGraph, postClass.LCVarianceAcctDefault, invItem, invSite, postClass);
                            if (aAccountID == null)
                            {
                                throw new PXException(Messages.LCVarianceAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                            }
                            try
                            {
                                aSubID = INReleaseProcess.GetSubID <INPostClass.lCVarianceSubID>(aGraph, postClass.LCVarianceAcctDefault, postClass.LCVarianceSubMask, invItem, invSite, postClass);
                            }
                            catch (PXException ex)
                            {
                                if (postClass.LCVarianceSubID == null ||
                                    string.IsNullOrEmpty(postClass.LCVarianceSubMask) ||
                                    invItem.LCVarianceSubID == null || invSite == null || invSite.LCVarianceSubID == null)
                                {
                                    throw new PXException(Messages.LCVarianceSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                                }
                                else
                                {
                                    throw ex;
                                }
                            }
                            if (aSubID == null)
                            {
                                throw new PXException(Messages.LCVarianceSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                            }
                        }
                    }
                    else
                    {
                        aAccountID = aRow.ExpenseAcctID;
                        aSubID     = aRow.ExpenseSubID;
                    }
                }
                else
                {
                    throw
                        new PXException(Messages.LCInventoryItemInReceiptRowIsNotFound, aRow.InventoryID, aRow.ReceiptNbr, aRow.LineNbr);
                }
            }
            else
            {
                aAccountID = aRow.ExpenseAcctID;
                aSubID     = aRow.ExpenseSubID;
            }
        }
Exemple #2
0
        protected virtual void GetLCVarianceAccountSub(ref int?aAccountID, ref int?aSubID, POReceiptLine receiptLine)
        {
            if (receiptLine.InventoryID.HasValue)
            {
                var invItem = InventoryItem.PK.Find(_pxGraph, receiptLine.InventoryID);
                if (invItem != null)
                {
                    INPostClass postClass = INPostClass.PK.Find(_pxGraph, invItem.PostClassID);

                    if ((bool)invItem.StkItem)
                    {
                        if (postClass == null)
                        {
                            throw new PXException(Messages.PostingClassIsNotDefinedForTheItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr);
                        }
                        INSite invSite = null;
                        if (receiptLine.SiteID != null)
                        {
                            invSite = INSite.PK.Find(_pxGraph, receiptLine.SiteID);
                        }
                        if (receiptLine.LineType == POLineType.GoodsForDropShip)
                        {
                            aAccountID = INReleaseProcess.GetAcctID <INPostClass.cOGSAcctID>(_pxGraph, postClass.COGSAcctDefault, invItem, invSite, postClass);
                            if (aAccountID == null)
                            {
                                throw new PXException(Messages.COGSAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                            }
                            try
                            {
                                aSubID = INReleaseProcess.GetSubID <INPostClass.cOGSSubID>(_pxGraph, postClass.COGSAcctDefault, postClass.COGSSubMask, invItem, invSite, postClass);
                            }
                            catch (PXException ex)
                            {
                                if (postClass.COGSSubID == null ||
                                    string.IsNullOrEmpty(postClass.COGSSubMask) ||
                                    invItem.COGSSubID == null || invSite == null || invSite.COGSSubID == null)
                                {
                                    throw new PXException(Messages.COGSSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                                }
                                else
                                {
                                    throw ex;
                                }
                            }
                            if (aSubID == null)
                            {
                                throw new PXException(Messages.COGSSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                            }
                        }
                        else
                        {
                            aAccountID = INReleaseProcess.GetAcctID <INPostClass.lCVarianceAcctID>(_pxGraph, postClass.LCVarianceAcctDefault, invItem, invSite, postClass);
                            if (aAccountID == null)
                            {
                                throw new PXException(Messages.LCVarianceAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                            }
                            try
                            {
                                aSubID = INReleaseProcess.GetSubID <INPostClass.lCVarianceSubID>(_pxGraph, postClass.LCVarianceAcctDefault, postClass.LCVarianceSubMask, invItem, invSite, postClass);
                            }
                            catch (PXException ex)
                            {
                                if (postClass.LCVarianceSubID == null ||
                                    string.IsNullOrEmpty(postClass.LCVarianceSubMask) ||
                                    invItem.LCVarianceSubID == null || invSite == null || invSite.LCVarianceSubID == null)
                                {
                                    throw new PXException(Messages.LCVarianceSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                                }
                                else
                                {
                                    throw ex;
                                }
                            }
                            if (aSubID == null)
                            {
                                throw new PXException(Messages.LCVarianceSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty);
                            }
                        }
                    }
                    else
                    {
                        aAccountID = receiptLine.ExpenseAcctID;
                        aSubID     = receiptLine.ExpenseSubID;
                    }
                }
                else
                {
                    throw
                        new PXException(Messages.LCInventoryItemInReceiptRowIsNotFound, receiptLine.InventoryID, receiptLine.ReceiptNbr, receiptLine.LineNbr);
                }
            }
            else
            {
                aAccountID = receiptLine.ExpenseAcctID;
                aSubID     = receiptLine.ExpenseSubID;
            }
        }