public Decimal CalcAllocationValue(LandedCostCode aCode, POReceiptLine aLine, Decimal aBaseTotal, Decimal aAllocationTotal) { if (_isPPV) { return(aAllocationTotal); } Decimal value = Decimal.Zero; if (IsApplicable(aCode, aLine)) { Decimal baseShare = LandedCostHelper.GetBaseValue(aCode, aLine); value = (baseShare * aAllocationTotal) / aBaseTotal; } return(value); }
public virtual void CreateAdjustmentTran(INAdjustmentEntry inGraph, List <LandedCostHelper.POReceiptLineAdjustment> pOLinesToProcess, LandedCostCode aLCCode, LandedCostTran aTran, string ReasonCode) { foreach (LandedCostHelper.POReceiptLineAdjustment poreceiptline in pOLinesToProcess) { INTran intran = new INTran(); bool isLCTran = aTran != null; INTran origtran = LandedCostHelper.GetOriginalInTran(inGraph, poreceiptline.Item1.ReceiptNbr, poreceiptline.Item1.LineNbr); bool isDropShip = (poreceiptline.Item1.LineType == POLineType.GoodsForDropShip || poreceiptline.Item1.LineType == POLineType.NonStockForDropShip); if (!isDropShip && origtran == null) { throw new PXException(AP.Messages.CannotFindINReceipt, poreceiptline.Item1.ReceiptNbr); } //Drop-Ships are considered non-stocks if (poreceiptline.Item1.IsStockItem()) { intran.TranType = INTranType.ReceiptCostAdjustment; } else { //Landed cost and PPV for non-stock items are handled in special way in the inventory. //They should create a GL Batch, but for convinience and unforminty this functionality is placed into IN module //Review this part when the functionality is implemented in IN module intran.IsCostUnmanaged = true; intran.TranType = INTranType.Adjustment; intran.InvtMult = 0; } intran.InventoryID = poreceiptline.Item1.InventoryID; intran.SubItemID = poreceiptline.Item1.SubItemID; intran.SiteID = poreceiptline.Item1.SiteID; intran.BAccountID = isLCTran ? aTran.VendorID : poreceiptline.Item1.VendorID; intran.BranchID = poreceiptline.BranchID; if (isDropShip && intran.SiteID != null) { INSite invSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <POReceiptLine.siteID> > > > .Select(inGraph, intran.SiteID); if (invSite.DropShipLocationID == null) { throw new PXException(SO.Messages.NoDropShipLocation, invSite.SiteCD); } intran.LocationID = invSite.DropShipLocationID; } else { intran.LocationID = poreceiptline.Item1.LocationID ?? origtran.LocationID; } intran.LotSerialNbr = poreceiptline.Item1.LotSerialNbr; intran.POReceiptType = poreceiptline.Item1.ReceiptType; intran.POReceiptNbr = poreceiptline.Item1.ReceiptNbr; intran.POReceiptLineNbr = poreceiptline.Item1.LineNbr; //tran.Qty = poreceiptline.ReceiptQty; intran.TranDesc = isLCTran ? aTran.Descr : poreceiptline.Item1.TranDesc; //tran.UnitCost = PXDBPriceCostAttribute.Round(inGraph.transactions.Cache, (decimal)(poreceiptline.ExtCost / poreceiptline.ReceiptQty)); intran.TranCost = poreceiptline.Item2; intran.ReasonCode = ReasonCode; if (origtran != null && origtran.DocType == INDocType.Issue) { intran.ARDocType = origtran.ARDocType; intran.ARRefNbr = origtran.ARRefNbr; intran.ARLineNbr = origtran.ARLineNbr; } if (!isDropShip) { intran.OrigTranType = origtran.DocType; intran.OrigRefNbr = origtran.RefNbr; } int?acctID = null; int?subID = null; if (isLCTran) { intran.AcctID = aLCCode.LCAccrualAcct; intran.SubID = aLCCode.LCAccrualSub; GetLCVarianceAccountSub(ref acctID, ref subID, inGraph, poreceiptline.Item1); } else { //Set AcctID and SubID = POAccrual Acct/Sub from orig. INTran if (origtran != null) { intran.AcctID = origtran.AcctID; intran.SubID = origtran.SubID; } else if (isDropShip) { intran.AcctID = poreceiptline.Item1.POAccrualAcctID; intran.SubID = poreceiptline.Item1.POAccrualSubID; } ReasonCode reasonCode = PXSelect <ReasonCode, Where <ReasonCode.reasonCodeID, Equal <Required <ReasonCode.reasonCodeID> > > > .Select(inGraph, ReasonCode); if (reasonCode == null) { throw new PXException(AP.Messages.ReasonCodeCannotNotFound, ReasonCode); } AP.APReleaseProcess.GetPPVAccountSub(ref acctID, ref subID, inGraph, poreceiptline.Item1, reasonCode); } intran.COGSAcctID = acctID; intran.COGSSubID = subID; intran = inGraph.transactions.Insert(intran); } }
public virtual void ReleaseLCTrans(IEnumerable <LandedCostTran> aTranSet, DocumentList <INRegister> aINCreated, DocumentList <APInvoice> aAPCreated) { Dictionary <int, APInvoiceEntry> apGraphs = new Dictionary <int, APInvoiceEntry>(); Dictionary <int, INAdjustmentEntry> inGraphs = new Dictionary <int, INAdjustmentEntry>(); Dictionary <int, int> combinations = new Dictionary <int, int>(); List <APRegister> forReleaseAP = new List <APRegister>(); List <INRegister> forReleaseIN = new List <INRegister>(); DocumentList <APInvoice> apDocuments = new DocumentList <APInvoice>(this); POSetup poSetupR = this.poSetup.Select(); bool autoReleaseIN = poSetupR.AutoReleaseLCIN.Value; bool autoReleaseAP = poSetupR.AutoReleaseAP.Value; bool noApplicableItems = false; bool noApplicableTransfers = false; foreach (LandedCostTran iTran in aTranSet) { LandedCostCode lcCode = PXSelect <LandedCostCode, Where <LandedCostCode.landedCostCodeID, Equal <Required <LandedCostCode.landedCostCodeID> > > > .Select(this, iTran.LandedCostCodeID); if ((string.IsNullOrEmpty(iTran.APDocType) || string.IsNullOrEmpty(iTran.APRefNbr)) && iTran.PostponeAP == false) { APInvoiceEntry apGraph = null; foreach (KeyValuePair <int, APInvoiceEntry> iGraph in apGraphs) { APInvoice apDoc = iGraph.Value.Document.Current; string terms = String.IsNullOrEmpty(iTran.TermsID) ? lcCode.TermsID : iTran.TermsID; if (apDoc.VendorID == iTran.VendorID && apDoc.VendorLocationID == iTran.VendorLocationID && apDoc.InvoiceNbr == iTran.InvoiceNbr && apDoc.CuryID == iTran.CuryID && apDoc.DocDate == iTran.InvoiceDate && apDoc.TermsID == terms && (apDoc.DocType == AP.APDocType.Invoice && iTran.CuryLCAmount > Decimal.Zero)) { combinations.Add(iTran.LCTranID.Value, iGraph.Key); apGraph = iGraph.Value; } } if (apGraph == null) { apGraph = PXGraph.CreateInstance <APInvoiceEntry>(); if (autoReleaseAP) { apGraph.APSetup.Current.RequireControlTotal = false; apGraph.APSetup.Current.RequireControlTaxTotal = false; apGraph.APSetup.Current.HoldEntry = false; } apGraphs[iTran.LCTranID.Value] = apGraph; } apGraph.InvoiceLandedCost(iTran, null, false); apDocuments.Add(apGraph.Document.Current); } if (lcCode.AllocationMethod != LandedCostAllocationMethod.None) { List <POReceiptLine> receiptLines = new List <POReceiptLine>(); List <LandedCostTranSplit> lcTranSplits = new List <LandedCostTranSplit>(); GetReceiptLinesToAllocate(receiptLines, lcTranSplits, iTran); var lch = new LandedCostHelper(this, false); List <LandedCostHelper.POReceiptLineAdjustment> result = lch.AllocateLCOverRCTLines(receiptLines, lcCode, iTran, lcTranSplits); if (result.Count > 0) { if (result.Count == 1 && !result[0].Item1.InventoryID.HasValue) { noApplicableTransfers = !lch.HasApplicableTransfers; noApplicableItems = true; //Skip Cost adjustment creation; } else { INAdjustmentEntry inGraph = PXGraph.CreateInstance <INAdjustmentEntry>(); if (autoReleaseIN) { inGraph.insetup.Current.RequireControlTotal = false; inGraph.insetup.Current.HoldEntry = false; } CreateCostAjustment(inGraph, lcCode, iTran, result); inGraphs[iTran.LCTranID.Value] = inGraph; } } } } using (PXConnectionScope cs = new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { foreach (LandedCostTran iTran in aTranSet) { bool needUpdate = false; LandedCostTran tran = this.landedCostTrans.Select(iTran.LCTranID); if (apGraphs.ContainsKey(tran.LCTranID.Value)) { APInvoiceEntry apGraph = apGraphs[iTran.LCTranID.Value]; apGraph.Save.Press(); tran.APDocType = apGraph.Document.Current.DocType; tran.APRefNbr = apGraph.Document.Current.RefNbr; if (!tran.APCuryInfoID.HasValue) { tran.APCuryInfoID = apGraph.Document.Current.CuryInfoID; } tran.Processed = true; if (apGraph.Document.Current.Hold != true) { forReleaseAP.Add(apGraph.Document.Current); } if (aAPCreated != null) { aAPCreated.Add(apGraph.Document.Current); } needUpdate = true; } else if (combinations.ContainsKey(tran.LCTranID.Value)) { //Its already saved at this point APInvoiceEntry apGraph = apGraphs[combinations[tran.LCTranID.Value]]; tran.APDocType = apGraph.Document.Current.DocType; tran.APRefNbr = apGraph.Document.Current.RefNbr; if (!tran.APCuryInfoID.HasValue) { tran.APCuryInfoID = apGraph.Document.Current.CuryInfoID; } tran.Processed = true; needUpdate = true; } if (inGraphs.ContainsKey(tran.LCTranID.Value)) { INAdjustmentEntry inGraph = inGraphs[iTran.LCTranID.Value]; inGraph.Save.Press(); tran.INDocType = inGraph.adjustment.Current.DocType; tran.INRefNbr = inGraph.adjustment.Current.RefNbr; tran.Processed = true; forReleaseIN.Add(inGraph.adjustment.Current); if (aINCreated != null) { aINCreated.Add(inGraph.adjustment.Current); } needUpdate = true; } if (!needUpdate && tran.PostponeAP == true) { LandedCostCode lcCode = PXSelect <LandedCostCode, Where <LandedCostCode.landedCostCodeID, Equal <Required <LandedCostCode.landedCostCodeID> > > > .Select(this, iTran.LandedCostCodeID); if (lcCode.AllocationMethod == LandedCostAllocationMethod.None) { tran.Processed = true; needUpdate = true; //This combination needs no processing here but must be updated } } if (needUpdate) { LandedCostTran copy = (LandedCostTran)this.landedCostTrans.Cache.CreateCopy(tran); tran = this.landedCostTrans.Update(copy); } } this.Actions.PressSave(); ts.Complete(); } } if (noApplicableTransfers == true) { throw new NoApplicableSourceException(Messages.LandedCostCannotBeDistributed); } if (noApplicableItems == true) { throw new NoApplicableSourceException(Messages.LandedCostAmountRemainderCannotBeDistributedMultyLines); } if (autoReleaseAP) { if (forReleaseAP.Count > 0) { APDocumentRelease.ReleaseDoc(forReleaseAP, true); } } if (autoReleaseIN) { if (forReleaseIN.Count > 0) { INDocumentRelease.ReleaseDoc(forReleaseIN, false); } } }