public virtual IDictionary <POLandedCostDetail, INAdjustmentWrapper> CreateLandedCostAdjustments(POLandedCostDoc doc, IEnumerable <LandedCostAllocationService.POLandedCostReceiptLineAdjustment> adjustments)
        {
            var result = new Dictionary <POLandedCostDetail, INAdjustmentWrapper>();

            var adjustmentsGroups = adjustments.Where(t => t.LandedCostDetail != null).GroupBy(t => t.LandedCostDetail);

            foreach (var adjustmentsGroup in adjustmentsGroups)
            {
                var landedCostCode = GetLandedCostCode(adjustmentsGroup.Key.LandedCostCodeID);

                if (landedCostCode.AllocationMethod == LandedCostAllocationMethod.None)
                {
                    continue;
                }

                var inTransctions = CreateTransactions(doc, adjustmentsGroup.Key, adjustmentsGroup.AsEnumerable());

                var newDoc = new INRegister
                {
                    DocType     = INDocType.Adjustment,
                    OrigModule  = BatchModule.PO,
                    SiteID      = null,
                    TranDate    = doc.DocDate,
                    FinPeriodID = doc.FinPeriodID,
                    BranchID    = doc.BranchID,
                    Hold        = false
                };

                var resultItem = new INAdjustmentWrapper(newDoc, inTransctions);

                result.Add(adjustmentsGroup.Key, resultItem);
            }

            return(result);
        }
Exemple #2
0
        protected virtual INIssueEntry InitIssueEntry()
        {
            var issueEntry = PXGraph.CreateInstance <INIssueEntry>();

            issueEntry.FieldVerifying.AddHandler <INTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            issueEntry.FieldVerifying.AddHandler <INTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            issueEntry.FieldVerifying.AddHandler <INTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            issueEntry.RowPersisting.AddHandler <INRegister>((PXCache sender, PXRowPersistingEventArgs e) =>
            {
                if (e.Operation.Command() == PXDBOperation.Delete)
                {
                    return;
                }

                INRegister document = (INRegister)e.Row;

                PXResultset <INTran> trans =
                    PXSelectJoin <INTran,
                                  InnerJoin <INSite, On <INTran.FK.Site> >,
                                  Where <INTran.docType, Equal <Required <INRegister.docType> >,
                                         And <INTran.refNbr, Equal <Required <INRegister.refNbr> > > > >
                    .Select(sender.Graph, document.DocType, document.RefNbr);

                _finPeriodUtils.ValidateFinPeriod(
                    trans.Cast <PXResult <INTran, INSite> >(),
                    row => ((INTran)row).FinPeriodID,
                    row => new[]
                {
                    ((INTran)row).BranchID,
                    ((INSite)row).BranchID,
                },
                    typeof(OrganizationFinPeriod.iNClosed));
            });
            return(issueEntry);
        }
        public virtual void ReleaseDocProc(JournalEntry je, INRegister doc, ReleaseDocProcDelegate del)
        {
            ValidatePostBatchStatus(PXDBOperation.Update, ID.Batch_PostTo.IN, doc.DocType, doc.RefNbr);

            if (del != null)
            {
                del(je, doc);
            }
        }
        public virtual FSCreatedDoc PressSave(int batchID, List <DocLineExt> docLines, BeforeSaveDelegate beforeSave)
        {
            if (Base.issue.Current == null)
            {
                throw new SharedClasses.TransactionScopeException();
            }

            if (beforeSave != null)
            {
                beforeSave(Base);
            }

            Base.Save.Press();

            INRegister inRegisterRow = Base.issue.Current != null ? Base.issue.Current : Base.issue.Select();

            if (docLines != null && docLines.Count > 0)
            {
                FSSrvOrdType fsSrvOrdTypeRow = docLines[0].fsSrvOrdType;

                if (fsSrvOrdTypeRow != null && fsSrvOrdTypeRow.ReleaseIssueOnInvoice == true)
                {
                    if (inRegisterRow.Hold == true)
                    {
                        Base.issue.Cache.SetValueExtIfDifferent <INRegister.hold>(inRegisterRow, false);

                        inRegisterRow = Base.issue.Update(inRegisterRow);
                    }

                    Base.release.Press();
                }
            }

            string docType = Base.issue.Current.DocType;
            string refNbr  = Base.issue.Current.RefNbr;

            var fsCreatedDocRow = new FSCreatedDoc()
            {
                BatchID        = batchID,
                PostTo         = ID.Batch_PostTo.IN,
                CreatedDocType = inRegisterRow.DocType,
                CreatedRefNbr  = inRegisterRow.RefNbr
            };

            return(fsCreatedDocRow);
        }
Exemple #5
0
        protected virtual void CreateCostAjustment(INAdjustmentEntry inGraph, LandedCostCode aLCCode, LandedCostTran aTran, List <LandedCostHelper.POReceiptLineAdjustment> aAllocatedLines)
        {
            inGraph.Clear();

            inGraph.FieldVerifying.AddHandler <INTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            inGraph.FieldVerifying.AddHandler <INTran.origRefNbr>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });

            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);

            CreateAdjustmentTran(inGraph, aAllocatedLines, aLCCode, aTran, aLCCode.ReasonCode);
        }
Exemple #6
0
        public virtual void _(Events.RowPersisting <INRegister> e)
        {
            INRegister row = e.Row;

            if (new LumLibrary().GetJournalEnhance)
            {
                if (!string.IsNullOrEmpty(row.SOShipmentNbr) && !string.IsNullOrEmpty(row.SOShipmentType))
                {
                    var CustomerID = SelectFrom <SOShipment>
                                     .Where <SOShipment.shipmentNbr.IsEqual <P.AsString>
                                             .And <SOShipment.shipmentType.IsEqual <P.AsString> > >
                                     .View.Select(Base, row.SOShipmentNbr, row.SOShipmentType)?.TopFirst?.CustomerID;

                    var CustomerName = SelectFrom <Customer>
                                       .Where <Customer.bAccountID.IsEqual <P.AsInt> >
                                       .View.Select(Base, CustomerID)?.TopFirst?.AcctName;

                    row.TranDesc = $"{row.SOShipmentNbr} {CustomerName}";
                }
            }
        }
        /// <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);
            }
        }
Exemple #8
0
 public INAdjustmentWrapper(INRegister doc, ICollection <INTran> transactions)
 {
     Document     = doc;
     Transactions = transactions;
 }
Exemple #9
0
        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);
            }
        }
        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);
            }
        }