public virtual bool IsApplicable(PXGraph graph, LandedCostCode aCode, POReceiptLine aLine) { bool transferinsidewarehouse = false; if (aLine.ReceiptType == POReceiptType.TransferReceipt) { INTran ortran = INTran.PK.Find(graph, aLine.OrigDocType, aLine.OrigRefNbr, aLine.OrigLineNbr); transferinsidewarehouse = (ortran == null || ortran.SiteID == aLine.SiteID); } if (transferinsidewarehouse == false) { HasApplicableTransfers = true; } //Memo - in this release, non-stock Items are not applicable for the landed cost. Review later. return(!transferinsidewarehouse && (aCode.AllocationMethod != LandedCostAllocationMethod.None && (aLine.LineType == POLineType.GoodsForInventory || aLine.LineType == POLineType.GoodsForReplenishment || aLine.LineType == POLineType.GoodsForSalesOrder || aLine.LineType == POLineType.GoodsForDropShip || aLine.LineType == POLineType.NonStock || aLine.LineType == POLineType.NonStockForDropShip || aLine.LineType == POLineType.NonStockForSalesOrder || aLine.LineType == POLineType.GoodsForServiceOrder || aLine.LineType == POLineType.NonStockForServiceOrder || aLine.LineType == POLineType.GoodsForManufacturing || aLine.LineType == POLineType.NonStockForManufacturing))); }
public virtual bool IsApplicable(PXGraph graph, LandedCostCode aCode, POReceiptLine aLine) { bool transferinsidewarehouse = false; if (aLine.ReceiptType == POReceiptType.TransferReceipt) { INTran ortran = PXSelectReadonly <INTran, Where <INTran.tranType, Equal <Required <INTran.origTranType> >, And <INTran.refNbr, Equal <Required <INTran.origRefNbr> > > > > .SelectWindowed(graph, 0, 1, aLine.OrigTranType, aLine.OrigRefNbr, aLine.OrigLineNbr); transferinsidewarehouse = (ortran == null || ortran.SiteID == aLine.SiteID); } if (transferinsidewarehouse == false) { HasApplicableTransfers = true; } //Memo - in this release, non-stock Items are not applicable for the landed cost. Review later. return(!transferinsidewarehouse && (aCode.AllocationMethod != LandedCostAllocationMethod.None && (aLine.LineType == POLineType.GoodsForInventory || aLine.LineType == POLineType.GoodsForReplenishment || aLine.LineType == POLineType.GoodsForSalesOrder || aLine.LineType == POLineType.GoodsForDropShip || aLine.LineType == POLineType.NonStock || aLine.LineType == POLineType.NonStockForDropShip || aLine.LineType == POLineType.NonStockForSalesOrder))); }
protected override decimal?GetCartQty(INTran line) { if (line == null) { return(null); } INRegisterCartLine docCartLine = RegisterCartLines.Search <INRegisterCartLine.lineNbr>(line.LineNbr); return(docCartLine?.Qty); }
public void Add(PXResult <ARTran, InventoryItem, SOLine, INTran, INTranSplit, INLotSerialStatus, SOSalesPerTran> res) { InventoryItem invItem = res; INTranSplit split = res; INTran tran = res; SOLine line = res; ARTran artran = res; INLotSerialStatus lotStatus = res; SOSalesPerTran sptran = res; Record item = null; if (!records.TryGetValue(artran, out item)) { item = new Record(artran, line, invItem, sptran); if (tran.LineNbr != null) { INTransaction intran = new INTransaction(tran); intran.Splits.Add(new Tuple <INTranSplit, bool>(split, string.IsNullOrEmpty(lotStatus.LotSerialNbr))); item.Transactions.Add(tran.LineNbr.Value, intran); } records.Add(artran, item); } else { if (tran.LineNbr != null) { INTransaction intran = null; if (!item.Transactions.TryGetValue(tran.LineNbr.Value, out intran)) { intran = new INTransaction(tran); item.Transactions.Add(tran.LineNbr.Value, intran); } intran.Splits.Add(new Tuple <INTranSplit, bool>(split, string.IsNullOrEmpty(lotStatus.LotSerialNbr))); } } }
public virtual void CreateAdjustmentTran(List <AllocationServiceBase.POReceiptLineAdjustment> pOLinesToProcess, string ReasonCode) { foreach (AllocationServiceBase.POReceiptLineAdjustment poreceiptline in pOLinesToProcess) { INTran intran = new INTran(); INTran origtran = PurchasePriceVarianceAllocationService.Instance.GetOriginalInTran(_inGraph, poreceiptline.ReceiptLine.ReceiptNbr, poreceiptline.ReceiptLine.LineNbr); bool isDropShip = (poreceiptline.ReceiptLine.LineType == POLineType.GoodsForDropShip || poreceiptline.ReceiptLine.LineType == POLineType.NonStockForDropShip); if (!isDropShip && origtran == null) { throw new PXException(AP.Messages.CannotFindINReceipt, poreceiptline.ReceiptLine.ReceiptNbr); } //Drop-Ships are considered non-stocks if (poreceiptline.ReceiptLine.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.ReceiptLine.InventoryID; intran.SubItemID = poreceiptline.ReceiptLine.SubItemID; intran.SiteID = poreceiptline.ReceiptLine.SiteID; intran.BAccountID = poreceiptline.ReceiptLine.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.ReceiptLine.LocationID ?? origtran.LocationID; } intran.LotSerialNbr = poreceiptline.ReceiptLine.LotSerialNbr; intran.POReceiptType = poreceiptline.ReceiptLine.ReceiptType; intran.POReceiptNbr = poreceiptline.ReceiptLine.ReceiptNbr; intran.POReceiptLineNbr = poreceiptline.ReceiptLine.LineNbr; //tran.Qty = poreceiptline.ReceiptQty; intran.TranDesc = poreceiptline.ReceiptLine.TranDesc; //tran.UnitCost = PXDBPriceCostAttribute.Round(inGraph.transactions.Cache, (decimal)(poreceiptline.ExtCost / poreceiptline.ReceiptQty)); intran.TranCost = poreceiptline.QtyToAssign; 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; //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.ReceiptLine.POAccrualAcctID; intran.SubID = poreceiptline.ReceiptLine.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.ReceiptLine, reasonCode); intran.COGSAcctID = acctID; intran.COGSSubID = subID; intran = _inGraph.transactions.Insert(intran); } }
public INTransaction(INTran tran) { this.Transaction = tran; this.Splits = new List <Tuple <INTranSplit, bool> >(); }
private void UpdateCosts() { if (IsSMRelated() == true) { Dictionary <int?, decimal?> appointmentIDs = new Dictionary <int?, decimal?>(); var appointmentSet = PXSelectJoin <FSAppointmentDet, InnerJoin <FSAppointment, On <FSAppointment.appointmentID, Equal <FSAppointmentDet.appointmentID> >, InnerJoin <FSPostDet, On <FSPostDet.postDetID, Equal <FSAppointmentDet.postID> >, LeftJoin <INTran, On <INTran.sOOrderType, Equal <FSPostDet.sOOrderType>, And <INTran.sOOrderNbr, Equal <FSPostDet.sOOrderNbr>, And <INTran.sOOrderLineNbr, Equal <FSPostDet.sOLineNbr> > > > > > >, Where < FSPostDet.sOOrderType, Equal <Required <FSPostDet.sOOrderType> >, And < FSPostDet.sOOrderNbr, Equal <Required <FSPostDet.sOOrderNbr> > > > > .Select(Base, Base.inregister.Current.SOOrderType, Base.inregister.Current.SOOrderNbr); using (PXTransactionScope ts = new PXTransactionScope()) { foreach (PXResult <FSAppointmentDet, FSAppointment, FSPostDet, INTran> bqlResult in appointmentSet) { FSAppointmentDet fsAppointmentDetRow = (FSAppointmentDet)bqlResult; FSAppointment fsAppointmentRow = (FSAppointment)bqlResult; INTran inTranRow = (INTran)bqlResult; if (inTranRow.RefNbr != null) { PXUpdate < Set <FSAppointmentDet.unitCost, Required <FSAppointmentDet.unitCost>, Set <FSAppointmentDet.curyUnitCost, Required <FSAppointmentDet.curyUnitCost>, Set <FSAppointmentDet.extCost, Required <FSAppointmentDet.extCost>, Set <FSAppointmentDet.curyExtCost, Required <FSAppointmentDet.curyExtCost> > > > >, FSAppointmentDet, Where < FSAppointmentDet.appDetID, Equal <Required <FSAppointmentDet.appDetID> > > > .Update( Base, inTranRow.UnitCost, inTranRow.UnitCost, inTranRow.TranCost, inTranRow.TranCost, fsAppointmentDetRow.AppDetID); } decimal?costTotal = 0.0m; if (appointmentIDs.ContainsKey(fsAppointmentDetRow.AppointmentID) == false) { appointmentIDs.Add(fsAppointmentDetRow.AppointmentID, inTranRow.TranCost ?? fsAppointmentDetRow.ExtCost); } else if (appointmentIDs.TryGetValue(fsAppointmentDetRow.AppointmentID, out costTotal)) { costTotal += inTranRow.TranCost ?? fsAppointmentDetRow.ExtCost; appointmentIDs.Remove(fsAppointmentDetRow.AppointmentID); appointmentIDs.Add(fsAppointmentDetRow.AppointmentID, costTotal); } } foreach (KeyValuePair <int?, decimal?> pair in appointmentIDs.ToList()) { PXUpdate < Set <FSAppointment.costTotal, Required <FSAppointment.costTotal>, Set <FSAppointment.curyCostTotal, Required <FSAppointment.curyCostTotal> > >, FSAppointment, Where < FSAppointment.appointmentID, Equal <Required <FSAppointment.appointmentID> > > > .Update( new PXGraph(), pair.Value, pair.Value, pair.Key); } ts.Complete(); } } }
protected virtual INTran[] CreateTransactions(POLandedCostDoc doc, POLandedCostDetail landedCostDetail, IEnumerable <LandedCostAllocationService.POLandedCostReceiptLineAdjustment> pOLinesToProcess) { var result = new List <INTran>(); var landedCostCode = GetLandedCostCode(landedCostDetail.LandedCostCodeID); var reasonCode = landedCostCode.ReasonCode; foreach (LandedCostAllocationService.POLandedCostReceiptLineAdjustment poreceiptline in pOLinesToProcess) { INTran intran = new INTran(); INTran origtran = LandedCostAllocationService.Instance.GetOriginalInTran(_pxGraph, poreceiptline.ReceiptLine.ReceiptNbr, poreceiptline.ReceiptLine.LineNbr); bool isDropShip = (poreceiptline.ReceiptLine.LineType == POLineType.GoodsForDropShip || poreceiptline.ReceiptLine.LineType == POLineType.NonStockForDropShip); if (!isDropShip && origtran == null) { throw new PXException(AP.Messages.CannotFindINReceipt, poreceiptline.ReceiptLine.ReceiptNbr); } //Drop-Ships are considered non-stocks if (poreceiptline.ReceiptLine.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.ReceiptLine.InventoryID; intran.SubItemID = poreceiptline.ReceiptLine.SubItemID; intran.SiteID = poreceiptline.ReceiptLine.SiteID; intran.BAccountID = doc.VendorID; intran.BranchID = landedCostDetail.BranchID; if (isDropShip && intran.SiteID != null) { INSite invSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <POReceiptLine.siteID> > > > .Select(_pxGraph, intran.SiteID); if (invSite.DropShipLocationID == null) { throw new PXException(SO.Messages.NoDropShipLocation, invSite.SiteCD); } intran.LocationID = invSite.DropShipLocationID; } else { intran.LocationID = poreceiptline.ReceiptLine.LocationID ?? origtran.LocationID; } intran.LotSerialNbr = poreceiptline.ReceiptLine.LotSerialNbr; intran.POReceiptType = poreceiptline.ReceiptLine.ReceiptType; intran.POReceiptNbr = poreceiptline.ReceiptLine.ReceiptNbr; intran.POReceiptLineNbr = poreceiptline.ReceiptLine.LineNbr; //tran.Qty = poreceiptline.ReceiptQty; intran.TranDesc = landedCostDetail.Descr; //tran.UnitCost = PXDBPriceCostAttribute.Round(inGraph.transactions.Cache, (decimal)(poreceiptline.ExtCost / poreceiptline.ReceiptQty)); intran.TranCost = poreceiptline.QtyToAssign; 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; intran.AcctID = landedCostDetail.LCAccrualAcct; intran.SubID = landedCostDetail.LCAccrualSub; GetLCVarianceAccountSub(ref acctID, ref subID, poreceiptline.ReceiptLine); intran.COGSAcctID = acctID; intran.COGSSubID = subID; result.Add(intran); } return(result.ToArray()); }
/// <summary> /// Creates an Issue document using the parameters <c>fsAppointmentRow</c>, <c>fsServiceOrderRow</c>, <c>fsServiceOrderTypeRow</c> and its posting information. /// </summary> protected virtual void CreateDocumentIssue(INIssueEntry graphINIssueEntry, SharedClasses.AppointmentInventoryItemInfo appointmentInventoryItemInfoRow, FSAppointmentDet fsAppointmentInventoryItemRow, DateTime?documentDate, string documentPeriod, FSPostBatch fsPostBatchRow, ref string inRefNbr, ref string inDocType) { if (appointmentInventoryItemInfoRow != null) { INRegister inRegisterRow; #region IN Issue Header if (string.IsNullOrEmpty(inRefNbr)) { inRegisterRow = new INRegister(); inRegisterRow.DocType = INDocType.Issue; inRegisterRow.TranDate = documentDate; inRegisterRow.FinPeriodID = documentPeriod; inRegisterRow.TranDesc = appointmentInventoryItemInfoRow.FSAppointmentRow.DocDesc; inRegisterRow.Hold = false; inRegisterRow = graphINIssueEntry.issue.Current = graphINIssueEntry.issue.Insert(inRegisterRow); inRegisterRow = graphINIssueEntry.issue.Update(inRegisterRow); } else { inRegisterRow = graphINIssueEntry.issue.Current = graphINIssueEntry.issue.Search <INRegister.refNbr>(inRefNbr); } #endregion INTran inTranRow; inTranRow = new INTran(); inTranRow.TranType = INTranType.Issue; inTranRow = graphINIssueEntry.transactions.Current = graphINIssueEntry.transactions.Insert(inTranRow); graphINIssueEntry.transactions.Cache.SetValueExt <INTran.inventoryID>(inTranRow, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.InventoryID); if (PXAccess.FeatureInstalled <FeaturesSet.subItem>()) { graphINIssueEntry.transactions.Cache.SetValueExt <INTran.subItemID>(inTranRow, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.SubItemID); } graphINIssueEntry.transactions.Cache.SetValueExt <INTran.siteID>(inTranRow, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.SiteID); graphINIssueEntry.transactions.Cache.SetValueExt <INTran.qty>(inTranRow, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.Qty); graphINIssueEntry.transactions.Cache.SetValueExt <INTran.unitPrice>(inTranRow, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.UnitPrice); graphINIssueEntry.transactions.Cache.SetValueExt <INTran.tranAmt>(inTranRow, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.TranAmt); graphINIssueEntry.transactions.Cache.SetValueExt <INTran.projectID>(inTranRow, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.ProjectID); graphINIssueEntry.transactions.Cache.SetValueExt <INTran.taskID>(inTranRow, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.ProjectTaskID); FSxINTran fsxINTranRow = graphINIssueEntry.transactions.Cache.GetExtension <FSxINTran>(graphINIssueEntry.transactions.Current); fsxINTranRow.Source = ID.Billing_By.APPOINTMENT; fsxINTranRow.SOID = appointmentInventoryItemInfoRow.FSAppointmentRow.SOID; fsxINTranRow.BillCustomerID = appointmentInventoryItemInfoRow.FSServiceOrderRow.BillCustomerID; fsxINTranRow.CustomerLocationID = appointmentInventoryItemInfoRow.FSServiceOrderRow.BillLocationID; fsxINTranRow.AppointmentID = appointmentInventoryItemInfoRow.FSAppointmentRow.AppointmentID; fsxINTranRow.AppointmentDate = new DateTime(appointmentInventoryItemInfoRow.FSAppointmentRow.ActualDateTimeBegin.Value.Year, appointmentInventoryItemInfoRow.FSAppointmentRow.ActualDateTimeBegin.Value.Month, appointmentInventoryItemInfoRow.FSAppointmentRow.ActualDateTimeBegin.Value.Day, 0, 0, 0); fsxINTranRow.AppDetID = (int)appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.AppDetID; inTranRow = graphINIssueEntry.transactions.Update(inTranRow); graphINIssueEntry.Save.Press(); if (string.IsNullOrEmpty(inRefNbr)) { inRefNbr = graphINIssueEntry.issue.Current.RefNbr; inDocType = graphINIssueEntry.issue.Current.DocType; } UpdateIssuePostInfo(graphINIssueEntry, graphUpdatePostBatchMaint, graphPostInfoEntry, fsAppointmentInventoryItemRow, appointmentInventoryItemInfoRow, fsPostBatchRow); } else { throw new PXException(TX.Error.NOTHING_TO_BE_POSTED); } }
public virtual void PostShippedNotInvoiced(INTran intran, ARTran n, ARInvoice ardoc, JournalEntry je) { if (intran.UpdateShippedNotInvoiced != true) { return; } if (intran.Released != true) { throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(AR.Messages.ShippedNotInvoicedINtranNotReleased, intran.RefNbr)); } var trancosts = PXSelect <INTranCost, Where <INTranCost.costDocType, Equal <Required <INTranCost.costDocType> >, And <INTranCost.costRefNbr, Equal <Required <INTranCost.costRefNbr> >, And <INTranCost.lineNbr, Equal <Required <INTranCost.lineNbr> > > > > > .Select(Base, intran.DocType, intran.RefNbr, intran.LineNbr); foreach (INTranCost trancost in trancosts) { var itemPostClassRes = (PXResult <InventoryItem, INPostClass>) PXSelectJoin <InventoryItem, LeftJoin <INPostClass, On <INPostClass.postClassID, Equal <InventoryItem.postClassID> > >, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, intran.InventoryID); ReasonCode reasoncode = INTran.FK.ReasonCode.FindParent(Base, intran); INSite site = INSite.PK.Find(Base, intran.SiteID); if (trancost != null && trancost.COGSAcctID != null && intran != null) { //Credit shipped-not-invoiced account GLTran tranFromIN = new GLTran(); tranFromIN.SummPost = Base.SummPost; tranFromIN.BranchID = intran.BranchID; tranFromIN.TranType = trancost.TranType; tranFromIN.TranClass = GLTran.tranClass.ShippedNotInvoiced; tranFromIN.AccountID = intran.COGSAcctID ?? INReleaseProcess.GetAccountDefaults <INPostClass.cOGSAcctID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes, intran); tranFromIN.SubID = intran.COGSSubID ?? INReleaseProcess.GetAccountDefaults <INPostClass.cOGSSubID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes, intran); tranFromIN.CuryDebitAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.DebitAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.CuryCreditAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.CreditAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.RefNbr = trancost.RefNbr; tranFromIN.InventoryID = trancost.InventoryID; tranFromIN.Qty = (trancost.InvtMult == (short)1) ? trancost.Qty : -trancost.Qty; tranFromIN.UOM = intran.UOM; tranFromIN.TranDesc = intran.TranDesc; tranFromIN.TranDate = n.TranDate; bool isNonProject = trancost.InvtMult == (short)0; tranFromIN.ProjectID = isNonProject ? PM.ProjectDefaultAttribute.NonProject() : intran.ProjectID; tranFromIN.TaskID = isNonProject ? null : intran.TaskID; tranFromIN.CostCodeID = tranFromIN.CostCodeID; tranFromIN.Released = true; Base.InsertInvoiceDetailsINTranCostTransaction(je, tranFromIN, new GLTranInsertionContext { ARRegisterRecord = ardoc, ARTranRecord = n, INTranRecord = intran, INTranCostRecord = trancost }); //Debit COGS account tranFromIN = new GLTran(); tranFromIN.SummPost = Base.SummPost; tranFromIN.BranchID = n.BranchID; if (reasoncode?.Usage == ReasonCodeUsages.Issue) { tranFromIN.AccountID = reasoncode.AccountID; tranFromIN.SubID = INReleaseProcess.GetReasonCodeSubID(Base, reasoncode, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); } else { tranFromIN.AccountID = INReleaseProcess.GetAccountDefaults <INPostClass.cOGSAcctID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); if (((INPostClass)itemPostClassRes) != null && ((INPostClass)itemPostClassRes).COGSSubFromSales != true) //we cannot use intran here to retrive cogs/sales sub { tranFromIN.SubID = INReleaseProcess.GetAccountDefaults <INPostClass.cOGSSubID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); } else { tranFromIN.SubID = n.SubID; } } tranFromIN.CuryDebitAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.DebitAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.CuryCreditAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.CreditAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.TranType = trancost.TranType; tranFromIN.TranClass = GLTran.tranClass.ShippedNotInvoiced; tranFromIN.RefNbr = trancost.RefNbr; tranFromIN.InventoryID = trancost.InventoryID; tranFromIN.Qty = (trancost.InvtMult == (short)1) ? -trancost.Qty : trancost.Qty; tranFromIN.UOM = intran.UOM; tranFromIN.TranDesc = intran.TranDesc; tranFromIN.TranDate = n.TranDate; tranFromIN.ProjectID = (trancost.InvtMult == (short)1) ? PM.ProjectDefaultAttribute.NonProject() : intran.ProjectID; tranFromIN.TaskID = (trancost.InvtMult == (short)1) ? null : intran.TaskID; tranFromIN.CostCodeID = intran.CostCodeID; tranFromIN.Released = true; tranFromIN.TranLineNbr = (tranFromIN.SummPost == true) ? null : intran.LineNbr; Base.InsertInvoiceDetailsINTranCostTransaction(je, tranFromIN, new GLTranInsertionContext { ARRegisterRecord = ardoc, ARTranRecord = n, INTranRecord = intran, INTranCostRecord = trancost }); } } }
protected void ReceiptDetails_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity) { var lineNbr = targetEntity.Fields.SingleOrDefault(f => f.Name == "OrigLineNbr") as EntityValueField; var receiptQty = targetEntity.Fields.SingleOrDefault(f => f.Name == "Quantity") as EntityValueField; var location = targetEntity.Fields.SingleOrDefault(f => f.Name == "Location") as EntityValueField; var allocations = (targetEntity.Fields.SingleOrDefault(f => string.Equals(f.Name, "Allocations")) as EntityListField).Value ?? new EntityImpl[0]; var hasAllocations = allocations.Any(a => a.Fields != null && a.Fields.Length > 0); var receiptEntry = (INReceiptEntry)graph; string transferNbr = receiptEntry.receipt.Current.TransferNbr; var detailsCache = receiptEntry.transactions.Cache; if (lineNbr == null || transferNbr == null) { detailsCache.Current = detailsCache.Insert(); return; } INTran newtran = null; decimal newtranqty = Decimal.Parse(receiptQty.Value); decimal newtrancost = 0m; receiptEntry.ParseSubItemSegKeys(); using (new PXReadBranchRestrictedScope()) { foreach (PXResult <INTransitLine, INLocationStatus2, INTransitLineLotSerialStatus, INSite, InventoryItem, INTran> res in PXSelectJoin <INTransitLine, InnerJoin <INLocationStatus2, On <INLocationStatus2.locationID, Equal <INTransitLine.costSiteID> >, LeftJoin <INTransitLineLotSerialStatus, On <INTransitLine.transferNbr, Equal <INTransitLineLotSerialStatus.transferNbr>, And <INTransitLine.transferLineNbr, Equal <INTransitLineLotSerialStatus.transferLineNbr> > >, InnerJoin <INSite, On <INSite.siteID, Equal <INTransitLine.toSiteID> >, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <INLocationStatus2.inventoryID> >, InnerJoin <INTran, On <INTran.docType, Equal <INDocType.transfer>, And <INTran.refNbr, Equal <INTransitLine.transferNbr>, And <INTran.lineNbr, Equal <INTransitLine.transferLineNbr>, And <INTran.invtMult, Equal <shortMinus1> > > > > > > > > >, Where <INTransitLine.transferNbr, Equal <Required <INTransitLine.transferNbr> >, And <INTransitLine.transferLineNbr, Equal <Required <INTransitLine.transferLineNbr> > > >, OrderBy <Asc <INTransitLine.transferNbr, Asc <INTransitLine.transferLineNbr> > > > .Select(receiptEntry, transferNbr, lineNbr.Value)) { INTransitLine transitline = res; INLocationStatus2 stat = res; INTransitLineLotSerialStatus lotstat = res; INSite site = res; InventoryItem item = res; INTran tran = res; if (stat.QtyOnHand == 0m || (lotstat != null && lotstat.QtyOnHand == 0m)) { continue; } if (newtran == null) { if (!object.Equals(receiptEntry.receipt.Current.BranchID, site.BranchID)) { INRegister copy = PXCache <INRegister> .CreateCopy(receiptEntry.receipt.Current); copy.BranchID = site.BranchID; receiptEntry.receipt.Update(copy); } newtran = PXCache <INTran> .CreateCopy(tran); newtran.OrigBranchID = newtran.BranchID; newtran.OrigTranType = newtran.TranType; newtran.OrigRefNbr = transitline.TransferNbr; newtran.OrigLineNbr = transitline.TransferLineNbr; newtran.BranchID = site.BranchID; newtran.DocType = receiptEntry.receipt.Current.DocType; newtran.RefNbr = receiptEntry.receipt.Current.RefNbr; newtran.LineNbr = (int)PXLineNbrAttribute.NewLineNbr <INTran.lineNbr>(receiptEntry.transactions.Cache, receiptEntry.receipt.Current); newtran.InvtMult = (short)1; newtran.SiteID = transitline.ToSiteID; newtran.LocationID = transitline.ToLocationID; newtran.ToSiteID = null; newtran.ToLocationID = null; newtran.BaseQty = 0m; newtran.Qty = 0m; newtran.UnitCost = 0m; newtran.Released = false; newtran.InvtAcctID = null; newtran.InvtSubID = null; newtran.ReasonCode = null; newtran.ARDocType = null; newtran.ARRefNbr = null; newtran.ARLineNbr = null; newtran.ProjectID = null; newtran.TaskID = null; newtran.CostCodeID = null; newtran.TranCost = 0m; receiptEntry.splits.Current = null; newtran = receiptEntry.transactions.Insert(newtran); receiptEntry.transactions.Current = newtran; if (receiptEntry.splits.Current != null) { receiptEntry.splits.Delete(receiptEntry.splits.Current); } } if (hasAllocations) { newtranqty = 0m; foreach (var allocation in allocations) { var newsplitqty = allocation.Fields.SingleOrDefault(f => f.Name == "Quantity") as EntityValueField; var newsplitlocation = allocation.Fields.SingleOrDefault(f => f.Name == "Location") as EntityValueField; INTranSplit newsplit = this.addReceiptSplitLine(receiptEntry, stat, lotstat, transitline, newtran, item, Decimal.Parse(newsplitqty.Value), newsplitlocation.Value); newtrancost += newsplit.BaseQty.Value * newsplit.UnitCost.Value; newtranqty += newsplit.BaseQty.Value; } break; } else { INTranSplit newsplit = this.addReceiptSplitLine(receiptEntry, stat, lotstat, transitline, tran, item, newtranqty, null); newtrancost += newsplit.BaseQty.Value * newsplit.UnitCost.Value; newtranqty += newsplit.BaseQty.Value; } } receiptEntry.UpdateTranCostQty(newtran, newtranqty, newtrancost); } }
private INTranSplit addReceiptSplitLine(INReceiptEntry receiptEntry, INLocationStatus2 stat, INTransitLineLotSerialStatus lotstat, INTransitLine transitline, INTran tran, InventoryItem item, Decimal qty, string location) { INTranSplit newsplit; decimal newsplitqty; if (lotstat.QtyOnHand == null) { newsplit = new INTranSplit(); newsplit.InventoryID = stat.InventoryID; newsplit.IsStockItem = true; newsplit.FromSiteID = transitline.SiteID; newsplit.SubItemID = stat.SubItemID; newsplit.LotSerialNbr = null; newsplitqty = qty; } else { newsplit = new INTranSplit(); newsplit.InventoryID = lotstat.InventoryID; newsplit.IsStockItem = true; newsplit.FromSiteID = lotstat.FromSiteID; newsplit.SubItemID = lotstat.SubItemID; newsplit.LotSerialNbr = lotstat.LotSerialNbr; newsplitqty = qty; } newsplit.DocType = receiptEntry.receipt.Current.DocType; newsplit.RefNbr = receiptEntry.receipt.Current.RefNbr; newsplit.LineNbr = tran.LineNbr; newsplit.SplitLineNbr = (int)PXLineNbrAttribute.NewLineNbr <INTranSplit.splitLineNbr>(receiptEntry.splits.Cache, receiptEntry.receipt.Current); newsplit.UnitCost = 0m; newsplit.InvtMult = (short)1; newsplit.SiteID = transitline.ToSiteID; newsplit.PlanID = null; newsplit.Released = false; newsplit.ProjectID = null; newsplit.TaskID = null; if (location == null) { newsplit.LocationID = lotstat.ToLocationID ?? transitline.ToLocationID; } else { receiptEntry.splits.SetValueExt <INTranSplit.locationID>(newsplit, location); } newsplit = receiptEntry.splits.Insert(newsplit); newsplit.MaxTransferBaseQty = newsplitqty; newsplit.BaseQty = newsplitqty; newsplit.Qty = newsplit.BaseQty.Value; receiptEntry.UpdateCostSubItemID(newsplit, item); receiptEntry.SetCostAttributes(tran, newsplit, item, tran.OrigRefNbr); newsplit.UnitCost = PXCurrencyAttribute.BaseRound(receiptEntry, newsplit.UnitCost); receiptEntry.splits.Update(newsplit); return(newsplit); }
public virtual void CreateInvoice(PXGraph graphProcess, List <DocLineExt> docLines, List <DocLineExt> docLinesGrouped, short invtMult, DateTime?invoiceDate, string invoiceFinPeriodID, OnDocumentHeaderInsertedDelegate onDocumentHeaderInserted, OnTransactionInsertedDelegate onTransactionInserted, PXQuickProcess.ActionFlow quickProcessFlow) { if (docLinesGrouped.Count == 0) { return; } bool?initialHold = false; FSServiceOrder fsServiceOrderRow = docLinesGrouped[0].fsServiceOrder; FSSrvOrdType fsSrvOrdTypeRow = docLinesGrouped[0].fsSrvOrdType; FSPostDoc fsPostDocRow = docLinesGrouped[0].fsPostDoc; FSAppointment fsAppointmentRow = docLinesGrouped[0].fsAppointment; Base.FieldDefaulting.AddHandler <INRegister.branchID>((sender, e) => { e.NewValue = fsServiceOrderRow.BranchID; e.Cancel = true; }); INRegister inRegisterRow = new INRegister(); inRegisterRow.DocType = INDocType.Issue; AutoNumberHelper.CheckAutoNumbering(Base, Base.insetup.SelectSingle().IssueNumberingID); inRegisterRow.TranDate = invoiceDate; inRegisterRow.FinPeriodID = invoiceFinPeriodID; inRegisterRow.TranDesc = fsAppointmentRow != null ? fsAppointmentRow.DocDesc : fsServiceOrderRow.DocDesc; inRegisterRow = PXCache <INRegister> .CreateCopy(Base.issue.Insert(inRegisterRow)); initialHold = inRegisterRow.Hold; inRegisterRow.NoteID = null; PXNoteAttribute.GetNoteIDNow(Base.issue.Cache, inRegisterRow); Base.issue.Cache.SetValueExtIfDifferent <INRegister.hold>(inRegisterRow, true); inRegisterRow = Base.issue.Update(inRegisterRow); if (onDocumentHeaderInserted != null) { onDocumentHeaderInserted(Base, inRegisterRow); } IDocLine docLine = null; INTran inTranRow = null; FSxINTran fsxINTranRow = null; PMTask pmTaskRow = null; List <GroupDocLineExt> singleLines = docLines.Where(x => x.docLine.LineType == ID.LineType_ALL.INVENTORY_ITEM).GroupBy( x => new { x.docLine.DocID, x.docLine.LineID }, (key, group) => new GroupDocLineExt(key.DocID, key.LineID, group.ToList())).ToList(); foreach (GroupDocLineExt singleLine in singleLines) { DocLineExt docLineExt = singleLine.Group.First(); docLine = docLineExt.docLine; fsPostDocRow = docLineExt.fsPostDoc; fsServiceOrderRow = docLineExt.fsServiceOrder; fsSrvOrdTypeRow = docLineExt.fsSrvOrdType; fsAppointmentRow = docLineExt.fsAppointment; inTranRow = new INTran(); inTranRow.BranchID = docLine.BranchID; inTranRow.TranType = INTranType.Issue; inTranRow = PXCache <INTran> .CreateCopy(Base.transactions.Insert(inTranRow)); inTranRow.InventoryID = docLine.InventoryID; inTranRow.UOM = docLine.UOM; pmTaskRow = docLineExt.pmTask; if (pmTaskRow != null && pmTaskRow.Status == ProjectTaskStatus.Completed) { throw new PXException(TX.Error.POSTING_PMTASK_ALREADY_COMPLETED, fsServiceOrderRow.RefNbr, docLine.LineRef, pmTaskRow.TaskCD); } if (docLine.ProjectID != null && docLine.ProjectTaskID != null) { inTranRow.ProjectID = docLine.ProjectID; inTranRow.TaskID = docLine.ProjectTaskID; } inTranRow.SiteID = docLine.SiteID; inTranRow.LocationID = docLine.SiteLocationID; inTranRow.TranDesc = docLine.TranDesc; inTranRow.CostCodeID = docLine.CostCodeID; inTranRow.ReasonCode = fsSrvOrdTypeRow.ReasonCode; inTranRow = PXCache <INTran> .CreateCopy(Base.transactions.Update(inTranRow)); INTranSplit currentSplit = Base.splits.Select(); if (fsAppointmentRow == null) { bool qtyAssigned = false; if (currentSplit != null && singleLine.Group != null && singleLine.Group.Count > 0) { Base.splits.Delete(currentSplit); } foreach (DocLineExt splitLine in singleLine.Group) { if (splitLine.fsSODetSplit.SplitLineNbr != null && splitLine.fsSODetSplit.Completed == false) { INTranSplit split = new INTranSplit(); split = Base.splits.Insert(split); INTranSplit copySplit = (INTranSplit)Base.splits.Cache.CreateCopy(split); copySplit.SiteID = splitLine.fsSODetSplit.SiteID != null ? splitLine.fsSODetSplit.SiteID : copySplit.SiteID; copySplit.LocationID = splitLine.fsSODetSplit.LocationID != null ? splitLine.fsSODetSplit.LocationID : copySplit.LocationID; copySplit.LotSerialNbr = splitLine.fsSODetSplit.LotSerialNbr; copySplit.Qty = splitLine.fsSODetSplit.Qty; split = Base.splits.Update(copySplit); qtyAssigned = true; } } inTranRow = (INTran)Base.transactions.Cache.CreateCopy(Base.transactions.Current); if (qtyAssigned == false) { inTranRow.Qty = docLine.GetQty(FieldType.BillableField); } else if (inTranRow.Qty != docLine.GetQty(FieldType.BillableField)) { throw new PXException(TX.Error.QTY_POSTED_ERROR); } } else { bool qtyAssigned = false; if (string.IsNullOrEmpty(docLine.LotSerialNbr) == false) { if (currentSplit != null) { Base.splits.Delete(currentSplit); } INTranSplit split = new INTranSplit(); split = Base.splits.Insert(split); INTranSplit copySplit = (INTranSplit)Base.splits.Cache.CreateCopy(split); copySplit.SiteID = docLine.SiteID; copySplit.LocationID = docLine.SiteLocationID != null ? docLine.SiteLocationID : copySplit.LocationID; copySplit.LotSerialNbr = docLine.LotSerialNbr != null ? docLine.LotSerialNbr : copySplit.LotSerialNbr; copySplit.Qty = docLine.GetQty(FieldType.BillableField); split = Base.splits.Update(copySplit); qtyAssigned = true; } inTranRow = (INTran)Base.transactions.Cache.CreateCopy(Base.transactions.Current); if (qtyAssigned == false) { inTranRow.Qty = docLine.GetQty(FieldType.BillableField); } else if (inTranRow.Qty != docLine.GetQty(FieldType.BillableField)) { throw new PXException(TX.Error.QTY_POSTED_ERROR); } } inTranRow.UnitPrice = docLine.CuryUnitPrice * invtMult; inTranRow.TranAmt = docLine.GetTranAmt(FieldType.BillableField) * invtMult; fsxINTranRow = Base.transactions.Cache.GetExtension <FSxINTran>(inTranRow); fsxINTranRow.Source = docLine.BillingBy; fsxINTranRow.SOID = fsServiceOrderRow.SOID; fsxINTranRow.BillCustomerID = fsServiceOrderRow.CustomerID; fsxINTranRow.CustomerLocationID = fsServiceOrderRow.LocationID; fsxINTranRow.SODetID = docLine.PostSODetID; fsxINTranRow.AppointmentID = docLine.PostAppointmentID; fsxINTranRow.AppointmentDate = fsAppointmentRow?.ExecutionDate; fsxINTranRow.AppDetID = docLine.PostAppDetID; SharedFunctions.CopyNotesAndFiles(Base.transactions.Cache, inTranRow, docLine, fsSrvOrdTypeRow); fsPostDocRow.INDocLineRef = inTranRow = Base.transactions.Update(inTranRow); if (onTransactionInserted != null) { onTransactionInserted(Base, inTranRow); } } inRegisterRow = Base.issue.Update(inRegisterRow); if (Base.insetup.Current?.RequireControlTotal == true) { Base.issue.Cache.SetValueExtIfDifferent <INRegister.controlQty>(inRegisterRow, inRegisterRow.TotalQty); Base.issue.Cache.SetValueExtIfDifferent <INRegister.controlAmount>(inRegisterRow, inRegisterRow.TotalAmount); } if (initialHold != true) { Base.issue.Cache.SetValueExtIfDifferent <INRegister.hold>(inRegisterRow, false); } inRegisterRow = Base.issue.Update(inRegisterRow); }
protected static void CreateCostAjustment(INAdjustmentEntry inGraph, LandedCostCode aLCCode, LandedCostTran aTran, List <LandedCostUtils.INCostAdjustmentInfo> aAllocatedLines) { inGraph.Clear(); inGraph.insetup.Current.RequireControlTotal = false; inGraph.insetup.Current.HoldEntry = false; INRegister newdoc = new INRegister(); newdoc.DocType = INDocType.Adjustment; newdoc.OrigModule = BatchModule.PO; newdoc.SiteID = null; newdoc.TranDate = aTran.InvoiceDate; inGraph.adjustment.Insert(newdoc); //Find IN Receipt (released??) for the LCTran's POReceipt foreach (LandedCostUtils.INCostAdjustmentInfo it in aAllocatedLines) { PXResult <INRegister, INTran> res = (PXResult <INRegister, INTran>) PXSelectJoin <INRegister, InnerJoin <INTran, On <INTran.docType, Equal <INRegister.docType>, And <INTran.refNbr, Equal <INRegister.refNbr> > > >, Where <INRegister.docType, NotEqual <INDocType.adjustment>, And <INTran.pOReceiptNbr, Equal <Required <INTran.pOReceiptNbr> > > > > .SelectWindowed(inGraph, 0, 1, it.POReceiptNbr); INRegister inReceipt = new INRegister(); if (res == null || (inReceipt = res).Released != true) { throw new PXException(Messages.INReceiptMustBeReleasedBeforeLCProcessing, inReceipt.RefNbr, aTran.POReceiptNbr); } INTran origtran = res; INTran tran = new INTran(); if (it.IsStockItem) { tran.TranType = INTranType.ReceiptCostAdjustment; } else { //Landed cost 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 tran.TranType = INTranType.Adjustment; tran.InvtMult = 0; } tran.InventoryID = it.InventoryID; tran.SubItemID = it.SubItemID; tran.SiteID = it.SiteID; tran.BAccountID = aTran.VendorID; tran.LocationID = it.LocationID ?? origtran.LocationID; tran.LotSerialNbr = it.LotSerialNbr; tran.POReceiptNbr = it.POReceiptNbr; tran.POReceiptLineNbr = it.POReceiptLineNbr; tran.ARDocType = (origtran.DocType == INDocType.Issue) ? origtran.ARDocType : null; tran.ARRefNbr = (origtran.DocType == INDocType.Issue) ? origtran.ARRefNbr : null; tran.ARLineNbr = (origtran.DocType == INDocType.Issue) ? origtran.ARLineNbr : null; //tran.Qty = it.ReceiptQty; tran.TranDesc = aTran.Descr; //tran.UnitCost = PXDBPriceCostAttribute.Round(inGraph.transactions.Cache, (decimal)(it.ExtCost / it.ReceiptQty)); tran.TranCost = it.AdjustmentAmount; tran.ReasonCode = aLCCode.ReasonCode; tran.OrigTranType = inReceipt.DocType; tran.OrigRefNbr = inReceipt.RefNbr; tran.AcctID = aLCCode.LCAccrualAcct; tran.SubID = aLCCode.LCAccrualSub; int?acctID = null; int?subID = null; GetLCVarianceAccountSub(ref acctID, ref subID, inGraph, it); tran.COGSAcctID = acctID; tran.COGSSubID = subID; tran = inGraph.transactions.Insert(tran); } }