public virtual List <ErrorInfo> GetErrorInfo() { List <ErrorInfo> errorList = new List <ErrorInfo>(); ErrorInfo errorInfo; foreach (ARTran arTranRow in Base.Transactions.Select()) { string errorMessage = SharedFunctions.CheckCacheState(Base.Transactions.Cache, arTranRow, true, true, true); if (string.IsNullOrEmpty(errorMessage) == false) { FSxARTran fsxARTRanRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow); errorInfo = new ErrorInfo() { SOID = fsxARTRanRow.SOID, AppointmentID = fsxARTRanRow.AppointmentID, ErrorMessage = errorMessage + Environment.NewLine }; errorList.Add(errorInfo); } } return(errorList); }
protected int?GetSOIDRelated(ARTran tran) { int?SOID; FSxARTran fsxARTranRow = PXCache <ARTran> .GetExtension <FSxARTran>(tran); SOID = fsxARTranRow?.SOID; if (SOID == null) { var soLine = PXSelect <SOLine, Where <SOLine.orderType, Equal <Required <ARTran.sOOrderType> >, And <SOLine.orderNbr, Equal <Required <ARTran.sOOrderNbr> >, And <SOLine.lineNbr, Equal <Required <ARTran.sOOrderLineNbr> > > > > > .Select(Base, tran.SOOrderType, tran.SOOrderNbr, tran.SOOrderLineNbr) .RowCast <SOLine>() .FirstOrDefault(); if (soLine != null) { FSxSOLine fsxSOLineRow = PXCache <SOLine> .GetExtension <FSxSOLine>(soLine); SOID = fsxSOLineRow?.SOID; } } return(SOID); }
public virtual void FillAppointmentSOFields(PXCache cache, ARTran arTranRow) { if (arTranRow.SOOrderType != null && arTranRow.SOOrderNbr != null && arTranRow.SOOrderLineNbr != null) { PXResult <SOLine, SOOrder, FSServiceOrder, FSAppointment> bqlResult = (PXResult <SOLine, SOOrder, FSServiceOrder, FSAppointment>) PXSelectJoin <SOLine, InnerJoin <SOOrder, On < SOOrder.orderNbr, Equal <SOLine.orderNbr>, And <SOOrder.orderType, Equal <SOLine.orderType> > >, LeftJoin <FSServiceOrder, On < Where2 < Where < FSServiceOrder.refNbr, Equal <FSxSOOrder.soRefNbr>, And <FSServiceOrder.srvOrdType, Equal <FSxSOOrder.srvOrdType> > >, Or <FSServiceOrder.sOID, Equal <FSxSOLine.sOID> > > >, LeftJoin <FSAppointment, On < FSAppointment.appointmentID, Equal <FSxSOLine.appointmentID> > > > >, Where < SOLine.orderType, Equal <Required <SOLine.orderType> >, And <SOLine.orderNbr, Equal <Required <SOLine.orderNbr> >, And <SOLine.lineNbr, Equal <Required <SOLine.lineNbr> > > > > > .Select(cache.Graph, arTranRow.SOOrderType, arTranRow.SOOrderNbr, arTranRow.SOOrderLineNbr); SOLine soLineRow = (SOLine)bqlResult; FSServiceOrder fsServiceOrderRow = (FSServiceOrder)bqlResult; FSAppointment fsAppointmentRow = (FSAppointment)bqlResult; if (soLineRow != null) { FSxARTran fsxARTranRow = cache.GetExtension <FSxARTran>(arTranRow); if (fsServiceOrderRow != null && fsServiceOrderRow.SOID != null) { fsxARTranRow.SOID = fsServiceOrderRow.SOID; fsxARTranRow.BillCustomerID = fsServiceOrderRow.CustomerID; fsxARTranRow.CustomerLocationID = fsServiceOrderRow.LocationID; fsxARTranRow.ServiceOrderDate = fsServiceOrderRow.OrderDate; } if (fsAppointmentRow != null && fsAppointmentRow.AppointmentID != null) { fsxARTranRow.AppointmentID = fsAppointmentRow.AppointmentID; fsxARTranRow.AppointmentDate = fsAppointmentRow.ScheduledDateTimeBegin; } } } }
public SOPrepaymentBySO(ARTran arTranRow, FSxARTran fsxARTran) { SOID = fsxARTran.SOID; unpaidAmount = 0; unpaidAmount += arTranRow.CuryTranAmt ?? 0m; originalAmount = unpaidAmount; fsxARTranList = new List <FSxARTran>(); fsxARTranList.Add(fsxARTran); }
public SOARLineEquipmentComponent(ContractInvoiceLine docLine, SOLine sOLineRow, FSxSOLine fSxSOLineRow) { this.componentID = docLine.ComponentID; this.currentLineRef = sOLineRow.LineNbr; this.equipmentAction = docLine.EquipmentAction; this.sourceLineRef = docLine.LineRef; this.sourceNewTargetEquipmentLineNbr = docLine.NewTargetEquipmentLineNbr; this.fsxSOLineRow = fSxSOLineRow; this.fsxARTranRow = null; }
public SOARLineEquipmentComponent(IDocLine docLine, ARTran arTranRow, FSxARTran fsxARTranRow) { this.componentID = docLine.ComponentID; this.currentLineRef = arTranRow.LineNbr; this.equipmentAction = docLine.EquipmentAction; this.sourceLineRef = docLine.LineRef; this.sourceNewTargetEquipmentLineNbr = docLine.NewTargetEquipmentLineNbr; this.fsxARTranRow = fsxARTranRow; this.fsxSOLineRow = null; }
public void Add(ARTran arTranRow, FSxARTran fsxARTranRow) { if (fsxARTranRow.SOID == null) { return; } SOPrepaymentBySO row = SOPrepaymentList.Find(x => x.SOID.Equals(fsxARTranRow.SOID)); if (row != null) { row.unpaidAmount += arTranRow.CuryTranAmt ?? 0m; row.fsxARTranList.Add(fsxARTranRow); } else { SOPrepaymentBySO newRow = new SOPrepaymentBySO(arTranRow, fsxARTranRow); SOPrepaymentList.Add(newRow); } }
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 = docLines[0].fsServiceOrder; FSSrvOrdType fsSrvOrdTypeRow = docLines[0].fsSrvOrdType; FSPostDoc fsPostDocRow = docLines[0].fsPostDoc; FSAppointment fsAppointmentRow = docLines[0].fsAppointment; Base.FieldDefaulting.AddHandler <ARInvoice.branchID>((sender, e) => { e.NewValue = fsServiceOrderRow.BranchID; e.Cancel = true; }); ARInvoice arInvoiceRow = new ARInvoice(); if (invtMult >= 0) { arInvoiceRow.DocType = ARInvoiceType.Invoice; AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().InvoiceNumberingID); } else { arInvoiceRow.DocType = ARInvoiceType.CreditMemo; AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().CreditAdjNumberingID); } arInvoiceRow.DocDate = invoiceDate; arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow.InvoiceNbr = fsServiceOrderRow.CustPORefNbr; arInvoiceRow = Base.Document.Insert(arInvoiceRow); initialHold = arInvoiceRow.Hold; arInvoiceRow.NoteID = null; PXNoteAttribute.GetNoteIDNow(Base.Document.Cache, arInvoiceRow); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, true); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerID>(arInvoiceRow, fsServiceOrderRow.BillCustomerID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceOrderRow.BillLocationID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyID>(arInvoiceRow, fsServiceOrderRow.CuryID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.taxZoneID>(arInvoiceRow, fsAppointmentRow != null ? fsAppointmentRow.TaxZoneID : fsServiceOrderRow.TaxZoneID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.taxCalcMode>(arInvoiceRow, fsAppointmentRow != null ? fsAppointmentRow.TaxCalcMode : fsServiceOrderRow.TaxCalcMode); string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceOrderRow.BillCustomerID, null); if (termsID != null) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, termsID); } else { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, fsSrvOrdTypeRow.DfltTermIDARSO); } if (fsServiceOrderRow.ProjectID != null) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.projectID>(arInvoiceRow, fsServiceOrderRow.ProjectID); } Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.docDesc>(arInvoiceRow, fsServiceOrderRow.DocDesc); arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow = Base.Document.Update(arInvoiceRow); InvoicingFunctions.SetContactAndAddress(Base, fsServiceOrderRow); if (onDocumentHeaderInserted != null) { onDocumentHeaderInserted(Base, arInvoiceRow); } IDocLine docLine = null; ARTran arTranRow = null; FSxARTran fsxARTranRow = null; PMTask pmTaskRow = null; List <SharedClasses.SOARLineEquipmentComponent> componentList = new List <SharedClasses.SOARLineEquipmentComponent>(); int?acctID; int?pivotAppointmentDetID = -1; foreach (DocLineExt docLineExt in docLines) { docLine = docLineExt.docLine; if (docLineExt.fsAppointment != null) { if (pivotAppointmentDetID != docLineExt.docLine.LineID) { pivotAppointmentDetID = docLineExt.docLine.LineID; } else { continue; } } FSSODetSplit fsSODetSplitRow = docLineExt.fsSODetSplit; fsPostDocRow = docLineExt.fsPostDoc; fsServiceOrderRow = docLineExt.fsServiceOrder; fsSrvOrdTypeRow = docLineExt.fsSrvOrdType; fsAppointmentRow = docLineExt.fsAppointment; arTranRow = new ARTran(); arTranRow = Base.Transactions.Insert(arTranRow); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.branchID>(arTranRow, docLine.BranchID); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.inventoryID>(arTranRow, docLine.InventoryID); 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) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taskID>(arTranRow, docLine.ProjectTaskID); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.uOM>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.UOM : docLine.UOM); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.siteID>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.SiteID : docLine.SiteID); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.locationID>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.LocationID : docLine.SiteLocationID); if (docLine.IsService == true || fsAppointmentRow != null) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, docLine.GetQty(FieldType.BillableField)); } else { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.Qty : docLine.GetQty(FieldType.BillableField)); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.tranDesc>(arTranRow, docLine.TranDesc); fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.salesPersonID>(arTranRow, fsAppointmentRow == null ? fsServiceOrderRow.SalesPersonID : fsAppointmentRow.SalesPersonID); if (docLine.AcctID != null) { acctID = docLine.AcctID; } else { acctID = ServiceOrderCore.Get_TranAcctID_DefaultValue(graphProcess, fsSrvOrdTypeRow.SalesAcctSource, docLine.InventoryID, docLine.SiteID, fsServiceOrderRow); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.accountID>(arTranRow, acctID); if (docLine.SubID != null) { try { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.subID>(arTranRow, docLine.SubID); } catch (PXException) { arTranRow.SubID = null; } } else { InvoicingFunctions.SetCombinedSubID(graphProcess, Base.Transactions.Cache, arTranRow, null, null, fsSrvOrdTypeRow, arTranRow.BranchID, arTranRow.InventoryID, arInvoiceRow.CustomerLocationID, fsServiceOrderRow.BranchLocationID, fsServiceOrderRow.SalesPersonID, docLine.IsService); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.manualPrice>(arTranRow, docLine.ManualPrice); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice * invtMult); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taxCategoryID>(arTranRow, docLine.TaxCategoryID); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.commissionable>(arTranRow, fsAppointmentRow?.Commissionable ?? fsServiceOrderRow.Commissionable ?? false); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.costCodeID>(arTranRow, docLine.CostCodeID); if (docLine.IsBillable == false) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.manualDisc>(arTranRow, true); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyDiscAmt>(arTranRow, docLine.GetQty(FieldType.BillableField) * docLine.CuryUnitPrice * invtMult); } else { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyExtPrice>(arTranRow, ((docLine.CuryBillableExtPrice * invtMult) / docLine.GetQty(FieldType.BillableField)) * arTranRow.Qty); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.discPct>(arTranRow, docLine.DiscPct); } if (fsAppointmentRow != null && !string.IsNullOrEmpty(docLine.LotSerialNbr)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, docLine.LotSerialNbr); } else if (fsSODetSplitRow.SplitLineNbr > 0 && !string.IsNullOrEmpty(fsSODetSplitRow.LotSerialNbr)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, fsSODetSplitRow.LotSerialNbr); } fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow); fsxARTranRow.Source = docLine.BillingBy; fsxARTranRow.SOID = fsServiceOrderRow.SOID; fsxARTranRow.ServiceOrderDate = fsServiceOrderRow.OrderDate; fsxARTranRow.BillCustomerID = fsServiceOrderRow.CustomerID; fsxARTranRow.CustomerLocationID = fsServiceOrderRow.LocationID; fsxARTranRow.SODetID = docLine.PostSODetID; fsxARTranRow.AppointmentID = docLine.PostAppointmentID; fsxARTranRow.AppointmentDate = fsAppointmentRow?.ExecutionDate; fsxARTranRow.AppDetID = docLine.PostAppDetID; fsxARTranRow.Mem_PreviousPostID = docLine.PostID; fsxARTranRow.Mem_TableSource = docLine.SourceTable; SharedFunctions.CopyNotesAndFiles(Base.Transactions.Cache, arTranRow, docLine, fsSrvOrdTypeRow); fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow); if (fsAppointmentRow != null && !string.IsNullOrEmpty(docLine.LotSerialNbr)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, docLine.LotSerialNbr); } else if (fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 && !string.IsNullOrEmpty(fsSODetSplitRow.LotSerialNbr)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, fsSODetSplitRow.LotSerialNbr); } if (PXAccess.FeatureInstalled <FeaturesSet.equipmentManagementModule>()) { if (docLine.EquipmentAction != null) { Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.equipmentAction>(arTranRow, docLine.EquipmentAction); Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.sMEquipmentID>(arTranRow, docLine.SMEquipmentID); Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.equipmentLineRef>(arTranRow, docLine.EquipmentLineRef); fsxARTranRow.Comment = docLine.Comment; if (docLine.EquipmentAction == ID.Equipment_Action.SELLING_TARGET_EQUIPMENT || ((docLine.EquipmentAction == ID.Equipment_Action.CREATING_COMPONENT || docLine.EquipmentAction == ID.Equipment_Action.UPGRADING_COMPONENT || docLine.EquipmentAction == ID.Equipment_Action.NONE) && string.IsNullOrEmpty(docLine.NewTargetEquipmentLineNbr) == false)) { componentList.Add(new SharedClasses.SOARLineEquipmentComponent(docLine, arTranRow, fsxARTranRow)); } else { fsxARTranRow.ComponentID = docLine.ComponentID; } } } if (onTransactionInserted != null) { onTransactionInserted(Base, arTranRow); } } if (componentList.Count > 0) { //Assigning the NewTargetEquipmentLineNbr field value for the component type records foreach (SharedClasses.SOARLineEquipmentComponent currLineModel in componentList.Where(x => x.equipmentAction == ID.Equipment_Action.SELLING_TARGET_EQUIPMENT)) { foreach (SharedClasses.SOARLineEquipmentComponent currLineComponent in componentList.Where(x => (x.equipmentAction == ID.Equipment_Action.CREATING_COMPONENT || x.equipmentAction == ID.Equipment_Action.UPGRADING_COMPONENT || x.equipmentAction == ID.Equipment_Action.NONE))) { if (currLineComponent.sourceNewTargetEquipmentLineNbr == currLineModel.sourceLineRef) { currLineComponent.fsxARTranRow.ComponentID = currLineComponent.componentID; currLineComponent.fsxARTranRow.NewTargetEquipmentLineNbr = currLineModel.currentLineRef; } } } } arInvoiceRow = Base.Document.Update(arInvoiceRow); if (Base.ARSetup.Current.RequireControlTotal == true) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal); } if (initialHold != true || quickProcessFlow != PXQuickProcess.ActionFlow.NoFlow) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, false); } arInvoiceRow = Base.Document.Update(arInvoiceRow); }
public virtual void FillEquipmentFields(PXCache cache, ARTran arTranRow) { if (arTranRow.SOOrderType != null && arTranRow.SOOrderNbr != null && arTranRow.SOOrderLineNbr != null) { PXResult <SOLine, SOOrder, FSServiceOrder, FSAppointment> bqlResult = (PXResult <SOLine, SOOrder, FSServiceOrder, FSAppointment>) PXSelectJoin <SOLine, InnerJoin <SOOrder, On <SOOrder.orderNbr, Equal <SOLine.orderNbr>, And <SOOrder.orderType, Equal <SOLine.orderType> > >, LeftJoin <FSServiceOrder, On < Where2 < Where < FSServiceOrder.refNbr, Equal <FSxSOOrder.soRefNbr>, And <FSServiceOrder.srvOrdType, Equal <FSxSOOrder.srvOrdType> > >, Or <FSServiceOrder.sOID, Equal <FSxSOLine.sOID> > > >, LeftJoin <FSAppointment, On <FSAppointment.appointmentID, Equal <FSxSOLine.appointmentID> > > > >, Where < SOLine.orderType, Equal <Required <SOLine.orderType> >, And < SOLine.orderNbr, Equal <Required <SOLine.orderNbr> >, And < SOLine.lineNbr, Equal <Required <SOLine.lineNbr> > > > > > .Select(cache.Graph, arTranRow.SOOrderType, arTranRow.SOOrderNbr, arTranRow.SOOrderLineNbr); SOLine soLineRow = (SOLine)bqlResult; SOOrder soOrderRow = (SOOrder)bqlResult; FSServiceOrder fsServiceOrderRow = (FSServiceOrder)bqlResult; FSAppointment fsAppointmentRow = (FSAppointment)bqlResult; if (soLineRow != null) { FSxSOOrder fsxSOOrderRow = PXCache <SOOrder> .GetExtension <FSxSOOrder>(soOrderRow); FSxSOLine fsxSOLineRow = PXCache <SOLine> .GetExtension <FSxSOLine>(soLineRow); FSxARTran fsxARTranRow = cache.GetExtension <FSxARTran>(arTranRow); if (fsxSOLineRow.EquipmentAction == ID.Equipment_Action.CREATING_COMPONENT || fsxSOLineRow.EquipmentAction == ID.Equipment_Action.REPLACING_COMPONENT) { fsxARTranRow.SMEquipmentID = fsxSOLineRow.SMEquipmentID; } else { fsxARTranRow.SuspendedSMEquipmentID = fsxSOLineRow.SMEquipmentID; } fsxARTranRow.NewTargetEquipmentLineNbr = fsxSOLineRow.NewTargetEquipmentLineNbr; fsxARTranRow.ComponentID = fsxSOLineRow.ComponentID; if (fsxSOOrderRow.SDEnabled == true || fsServiceOrderRow.SOID != null) { fsxARTranRow.SOID = fsServiceOrderRow.SOID; fsxARTranRow.BillCustomerID = fsServiceOrderRow.BillCustomerID; fsxARTranRow.CustomerLocationID = fsServiceOrderRow.BillLocationID; } if (fsAppointmentRow?.AppointmentID != null) { fsxARTranRow.AppointmentID = fsAppointmentRow.AppointmentID; fsxARTranRow.AppointmentDate = fsAppointmentRow.ScheduledDateTimeBegin; } } } }
public virtual FSContractPostDoc CreateInvoiceByContract(PXGraph graphProcess, DateTime?invoiceDate, string invoiceFinPeriodID, FSContractPostBatch fsContractPostBatchRow, FSServiceContract fsServiceContractRow, FSContractPeriod fsContractPeriodRow, List <ContractInvoiceLine> docLines) { if (docLines.Count == 0) { return(null); } FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graphProcess); ARInvoice arInvoiceRow = new ARInvoice(); arInvoiceRow.DocType = ARInvoiceType.Invoice; arInvoiceRow.DocDate = invoiceDate; arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow.Hold = true; arInvoiceRow = Base.Document.Insert(arInvoiceRow); Base.Document.Cache.SetValueExt <ARInvoice.customerID>(arInvoiceRow, fsServiceContractRow.BillCustomerID); Base.Document.Cache.SetValueExt <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceContractRow.BillLocationID); Base.Document.Cache.SetValueExt <ARInvoice.branchID>(arInvoiceRow, fsServiceContractRow.BranchID); Base.Document.Cache.SetValueExt <ARInvoice.docDesc>(arInvoiceRow, "Contract Standardized Billing: " + fsServiceContractRow.RefNbr + " " + fsServiceContractRow.DocDesc); string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceContractRow.BillCustomerID, null); if (termsID != null) { Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, termsID); } else { Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, fsSetupRow.DfltContractTermIDARSO); } ARTran arTranRow = null; FSxARTran fsxARTranRow = null; int? acctID; foreach (ContractInvoiceLine docLine in docLines) { arTranRow = new ARTran(); arTranRow = Base.Transactions.Insert(arTranRow); Base.Transactions.Cache.SetValueExt <ARTran.inventoryID>(arTranRow, docLine.InventoryID); Base.Transactions.Cache.SetValueExt <ARTran.uOM>(arTranRow, docLine.UOM); Base.Transactions.Cache.SetValueExt <ARTran.salesPersonID>(arTranRow, docLine.SalesPersonID); arTranRow = Base.Transactions.Update(arTranRow); if (docLine.AcctID != null) { acctID = docLine.AcctID; } else { acctID = (int?)ServiceOrderCore.Get_INItemAcctID_DefaultValue( graphProcess, fsSetupRow.ContractSalesAcctSource, docLine.InventoryID, fsServiceContractRow); } Base.Transactions.Cache.SetValueExt <ARTran.accountID>(arTranRow, acctID); if (docLine.SubID != null) { try { Base.Transactions.Cache.SetValueExt <ARTran.subID>(arTranRow, docLine.SubID); } catch (PXException) { arTranRow.SubID = null; } } else { InvoicingFunctions.SetCombinedSubID( graphProcess, Base.Transactions.Cache, arTranRow, null, null, fsSetupRow, arTranRow.BranchID, arTranRow.InventoryID, arInvoiceRow.CustomerLocationID, fsServiceContractRow.BranchLocationID); } Base.Transactions.Cache.SetValueExt <ARTran.qty>(arTranRow, docLine.Qty); Base.Transactions.Cache.SetValueExt <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice); Base.Transactions.Cache.SetValueExt <ARTran.tranDesc>(arTranRow, docLine.TranDescPrefix + arTranRow.TranDesc); arTranRow = Base.Transactions.Update(arTranRow); Base.Transactions.Cache.SetValueExt <ARTran.commissionable>(arTranRow, docLine.Commissionable ?? false); fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow); fsxARTranRow.Source = ID.Billing_By.CONTRACT; fsxARTranRow.ServiceContractID = fsServiceContractRow.ServiceContractID; fsxARTranRow.ContractPeriodID = fsContractPeriodRow.ContractPeriodID; fsxARTranRow.BillCustomerID = fsServiceContractRow.BillCustomerID; fsxARTranRow.CustomerLocationID = fsServiceContractRow.BillLocationID; arTranRow = Base.Transactions.Update(arTranRow); } if (Base.ARSetup.Current.RequireControlTotal == true) { Base.Document.Cache.SetValueExt <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal); } Base.Document.Cache.SetValueExt <ARInvoice.hold>(arInvoiceRow, false); Exception newException = null; try { Base.Save.Press(); } catch (Exception e) { List <ErrorInfo> errorList = this.GetErrorInfo(); var exceptionWithContextMessage = ExceptionHelper.GetExceptionWithContextMessage( PXMessages.Localize(TX.Messages.ERROR_CREATING_INVOICE_IN_POSTING_BATCH), e); newException = InvoicingFunctions.GetErrorInfoInLines(errorList, exceptionWithContextMessage); } if (newException != null) { throw newException; } arInvoiceRow = Base.Document.Current; FSContractPostDoc fsContractCreatedDocRow = new FSContractPostDoc() { ContractPeriodID = fsContractPeriodRow.ContractPeriodID, ContractPostBatchID = fsContractPostBatchRow.ContractPostBatchID, PostDocType = arInvoiceRow.DocType, PostedTO = ID.Batch_PostTo.AR, PostRefNbr = arInvoiceRow.RefNbr, ServiceContractID = fsServiceContractRow.ServiceContractID }; return(fsContractCreatedDocRow); }
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 <ARInvoice.branchID>((sender, e) => { e.NewValue = fsServiceOrderRow.BranchID; e.Cancel = true; }); ARInvoice arInvoiceRow = new ARInvoice(); if (invtMult >= 0) { arInvoiceRow.DocType = ARInvoiceType.Invoice; } else { arInvoiceRow.DocType = ARInvoiceType.CreditMemo; } arInvoiceRow.DocDate = invoiceDate; arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow.InvoiceNbr = fsServiceOrderRow.CustPORefNbr; arInvoiceRow = Base.Document.Insert(arInvoiceRow); initialHold = arInvoiceRow.Hold; arInvoiceRow.NoteID = null; PXNoteAttribute.GetNoteIDNow(Base.Document.Cache, arInvoiceRow); Base.Document.Cache.SetValueExt <ARInvoice.hold>(arInvoiceRow, true); Base.Document.Cache.SetValueExt <ARInvoice.customerID>(arInvoiceRow, fsServiceOrderRow.BillCustomerID); Base.Document.Cache.SetValueExt <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceOrderRow.BillLocationID); Base.Document.Cache.SetValueExt <ARInvoice.curyID>(arInvoiceRow, fsServiceOrderRow.CuryID); Base.Document.Cache.SetValueExt <ARInvoice.taxZoneID>(arInvoiceRow, fsAppointmentRow != null ? fsAppointmentRow.TaxZoneID : fsServiceOrderRow.TaxZoneID); string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceOrderRow.BillCustomerID, null); if (termsID != null) { Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, termsID); } else { Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, fsSrvOrdTypeRow.DfltTermIDARSO); } if (fsServiceOrderRow.ProjectID != null) { Base.Document.Cache.SetValueExt <ARInvoice.projectID>(arInvoiceRow, fsServiceOrderRow.ProjectID); } Base.Document.Cache.SetValueExt <ARInvoice.docDesc>(arInvoiceRow, fsServiceOrderRow.DocDesc); arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow = Base.Document.Update(arInvoiceRow); InvoicingFunctions.SetAddress(Base, fsServiceOrderRow); if (onDocumentHeaderInserted != null) { onDocumentHeaderInserted(Base, arInvoiceRow); } IDocLine docLine = null; ARTran arTranRow = null; FSxARTran fsxARTranRow = null; int? acctID; foreach (DocLineExt docLineExt in docLinesGrouped) { docLine = docLineExt.docLine; fsPostDocRow = docLineExt.fsPostDoc; fsServiceOrderRow = docLineExt.fsServiceOrder; fsSrvOrdTypeRow = docLineExt.fsSrvOrdType; fsAppointmentRow = docLineExt.fsAppointment; arTranRow = new ARTran(); arTranRow = Base.Transactions.Insert(arTranRow); Base.Transactions.Cache.SetValueExt <ARTran.inventoryID>(arTranRow, docLine.InventoryID); Base.Transactions.Cache.SetValueExt <ARTran.uOM>(arTranRow, docLine.UOM); if (docLine.ProjectID != null && docLine.ProjectTaskID != null) { PMTask pmTaskRow = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(graphProcess, docLine.ProjectTaskID); Base.Transactions.Cache.SetValueExt <ARTran.taskID>(arTranRow, pmTaskRow.TaskCD); } Base.Transactions.Cache.SetValueExt <ARTran.qty>(arTranRow, docLine.GetQty(FieldType.BillableField)); Base.Transactions.Cache.SetValueExt <ARTran.tranDesc>(arTranRow, docLine.TranDesc); fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow); Base.Transactions.Cache.SetValueExt <ARTran.salesPersonID>(arTranRow, fsAppointmentRow == null ? fsServiceOrderRow.SalesPersonID : fsAppointmentRow.SalesPersonID); if (docLine.AcctID != null) { acctID = docLine.AcctID; } else { acctID = (int?)ServiceOrderCore.Get_TranAcctID_DefaultValue( graphProcess, fsSrvOrdTypeRow.SalesAcctSource, docLine.InventoryID, fsServiceOrderRow); } Base.Transactions.Cache.SetValueExt <ARTran.accountID>(arTranRow, acctID); if (docLine.SubID != null) { try { Base.Transactions.Cache.SetValueExt <ARTran.subID>(arTranRow, docLine.SubID); } catch (PXException) { arTranRow.SubID = null; } } else { InvoicingFunctions.SetCombinedSubID( graphProcess, Base.Transactions.Cache, arTranRow, null, null, fsSrvOrdTypeRow, arTranRow.BranchID, arTranRow.InventoryID, arInvoiceRow.CustomerLocationID, fsServiceOrderRow.BranchLocationID, fsServiceOrderRow.SalesPersonID, docLine.IsService); } Base.Transactions.Cache.SetValueExt <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice * invtMult); Base.Transactions.Cache.SetValueExt <ARTran.taxCategoryID>(arTranRow, docLine.TaxCategoryID); //Base.Transactions.Cache.SetValueExt<ARTran.curyExtPrice>(arTranRow, docLine.GetTranAmt(FieldType.BillableField) * invtMult); Base.Transactions.Cache.SetValueExt <ARTran.commissionable>(arTranRow, fsAppointmentRow?.Commissionable ?? fsServiceOrderRow.Commissionable ?? false); Base.Transactions.Cache.SetValueExt <ARTran.costCodeID>(arTranRow, docLine.CostCodeID); fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow); fsxARTranRow.Source = docLine.BillingBy; fsxARTranRow.SOID = fsServiceOrderRow.SOID; fsxARTranRow.ServiceOrderDate = fsServiceOrderRow.OrderDate; fsxARTranRow.BillCustomerID = fsServiceOrderRow.BillCustomerID; fsxARTranRow.CustomerLocationID = fsServiceOrderRow.BillLocationID; fsxARTranRow.SODetID = docLine.PostSODetID; fsxARTranRow.AppointmentID = docLine.PostAppointmentID; fsxARTranRow.AppointmentDate = fsAppointmentRow?.ExecutionDate; fsxARTranRow.AppDetID = docLine.PostAppDetID; fsxARTranRow.Mem_PreviousPostID = docLine.PostID; fsxARTranRow.Mem_TableSource = docLine.SourceTable; SharedFunctions.CopyNotesAndFiles(Base.Transactions.Cache, arTranRow, docLine, fsSrvOrdTypeRow); fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow); if (onTransactionInserted != null) { onTransactionInserted(Base, arTranRow); } } arInvoiceRow = Base.Document.Update(arInvoiceRow); if (Base.ARSetup.Current.RequireControlTotal == true) { Base.Document.Cache.SetValueExt <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal); } if (initialHold != true) { Base.Document.Cache.SetValueExt <ARInvoice.hold>(arInvoiceRow, false); } arInvoiceRow = Base.Document.Update(arInvoiceRow); }
public virtual void FillEquipmentFields(PXCache cache, ARTran arTranRow) { if (arTranRow.SOOrderType != null && arTranRow.SOOrderNbr != null && arTranRow.SOOrderLineNbr != null) { PXResult <SOLine, SOOrder, FSServiceOrder, FSAppointment> bqlResult = (PXResult <SOLine, SOOrder, FSServiceOrder, FSAppointment>) PXSelectJoin <SOLine, InnerJoin <SOOrder, On < SOOrder.orderNbr, Equal <SOLine.orderNbr>, And <SOOrder.orderType, Equal <SOLine.orderType> > >, LeftJoin <FSServiceOrder, On < Where2 < Where < FSServiceOrder.refNbr, Equal <FSxSOOrder.soRefNbr>, And <FSServiceOrder.srvOrdType, Equal <FSxSOOrder.srvOrdType> > >, Or <FSServiceOrder.sOID, Equal <FSxSOLine.sOID> > > >, LeftJoin <FSAppointment, On < FSAppointment.appointmentID, Equal <FSxSOLine.appointmentID> > > > >, Where < SOLine.orderType, Equal <Required <SOLine.orderType> >, And < SOLine.orderNbr, Equal <Required <SOLine.orderNbr> >, And < SOLine.lineNbr, Equal <Required <SOLine.lineNbr> > > > > > .Select(cache.Graph, arTranRow.SOOrderType, arTranRow.SOOrderNbr, arTranRow.SOOrderLineNbr); SOLine soLineRow = (SOLine)bqlResult; SOOrder soOrderRow = (SOOrder)bqlResult; FSServiceOrder fsServiceOrderRow = (FSServiceOrder)bqlResult; FSAppointment fsAppointmentRow = (FSAppointment)bqlResult; if (soLineRow != null) { FSxSOOrder fsxSOOrderRow = PXCache <SOOrder> .GetExtension <FSxSOOrder>(soOrderRow); FSxSOLine fsxSOLineRow = PXCache <SOLine> .GetExtension <FSxSOLine>(soLineRow); FSxARTran fsxARTranRow = cache.GetExtension <FSxARTran>(arTranRow); fsxARTranRow.SMEquipmentID = fsxSOLineRow.SMEquipmentID; fsxARTranRow.ComponentID = fsxSOLineRow.ComponentID; fsxARTranRow.EquipmentLineRef = fsxSOLineRow.EquipmentLineRef; fsxARTranRow.EquipmentAction = fsxSOLineRow.EquipmentAction; fsxARTranRow.Comment = fsxSOLineRow.Comment; SOLine soLineRow2 = PXSelect <SOLine, Where < SOLine.orderType, Equal <Required <SOLine.orderType> >, And <SOLine.orderNbr, Equal <Required <SOLine.orderNbr> >, And <SOLine.lineNbr, Equal <Required <SOLine.lineNbr> > > > > > .Select(cache.Graph, arTranRow.SOOrderType, arTranRow.SOOrderNbr, fsxSOLineRow.NewTargetEquipmentLineNbr); if (soLineRow2 != null) { ARTran arTranRow2 = Base.Transactions.Select().Where(x => ((ARTran)x).SOOrderType == arTranRow.SOOrderType && ((ARTran)x).SOOrderNbr == arTranRow.SOOrderNbr && ((ARTran)x).SOOrderLineNbr == soLineRow2.LineNbr).RowCast <ARTran>().FirstOrDefault(); fsxARTranRow.NewTargetEquipmentLineNbr = arTranRow2?.LineNbr; } if (fsxSOOrderRow.SDEnabled == true || fsServiceOrderRow.SOID != null) { fsxARTranRow.SOID = fsServiceOrderRow.SOID; fsxARTranRow.BillCustomerID = fsServiceOrderRow.CustomerID; fsxARTranRow.CustomerLocationID = fsServiceOrderRow.LocationID; } if (fsAppointmentRow?.AppointmentID != null) { fsxARTranRow.AppointmentID = fsAppointmentRow.AppointmentID; fsxARTranRow.AppointmentDate = fsAppointmentRow.ScheduledDateTimeBegin; } } } }
public virtual void UpgradeEquipmentComponents(SMEquipmentMaint graphSMEquipmentMaint, ARRegister arRegisterRow, Dictionary <int?, int?> newEquiments) { var inventoryItemSet = PXSelectJoin <InventoryItem, InnerJoin <ARTran, On <ARTran.inventoryID, Equal <InventoryItem.inventoryID>, And <ARTran.tranType, Equal <ARDocType.invoice> > >, LeftJoin <SOLine, On <SOLine.orderType, Equal <ARTran.sOOrderType>, And <SOLine.orderNbr, Equal <ARTran.sOOrderNbr>, And <SOLine.lineNbr, Equal <ARTran.sOOrderLineNbr> > > > > >, Where < ARTran.tranType, Equal <Required <ARInvoice.docType> >, And <ARTran.refNbr, Equal <Required <ARInvoice.refNbr> >, And <FSxARTran.equipmentAction, Equal <ListField_EquipmentAction.UpgradingComponent>, And <FSxARTran.sMEquipmentID, IsNull, And <FSxARTran.newTargetEquipmentLineNbr, IsNotNull, And <FSxARTran.componentID, IsNotNull, And <FSxARTran.equipmentLineRef, IsNull> > > > > > >, OrderBy < Asc <ARTran.tranType, Asc <ARTran.refNbr, Asc <ARTran.lineNbr> > > > > .Select(Base, arRegisterRow.DocType, arRegisterRow.RefNbr); foreach (PXResult <InventoryItem, ARTran, SOLine> bqlResult in inventoryItemSet) { ARTran arTranRow = (ARTran)bqlResult; SOLine soLineRow = (SOLine)bqlResult; InventoryItem inventoryItemRow = (InventoryItem)bqlResult; FSxARTran fsxARTranRow = PXCache <ARTran> .GetExtension <FSxARTran>(arTranRow); int?smEquipmentID = -1; if (newEquiments.TryGetValue(fsxARTranRow.NewTargetEquipmentLineNbr, out smEquipmentID)) { graphSMEquipmentMaint.EquipmentRecords.Current = graphSMEquipmentMaint.EquipmentRecords.Search <FSEquipment.SMequipmentID>(smEquipmentID); FSEquipmentComponent fsEquipmentComponentRow = graphSMEquipmentMaint.EquipmentWarranties.Select().Where(x => ((FSEquipmentComponent)x).ComponentID == fsxARTranRow.ComponentID).FirstOrDefault(); if (fsEquipmentComponentRow != null) { fsEquipmentComponentRow.SalesOrderNbr = arTranRow.SOOrderNbr; fsEquipmentComponentRow.SalesOrderType = arTranRow.SOOrderType; fsEquipmentComponentRow.LongDescr = arTranRow.TranDesc; fsEquipmentComponentRow.InvoiceRefNbr = arTranRow.RefNbr; fsEquipmentComponentRow.InstallationDate = arTranRow.TranDate != null ? arTranRow.TranDate : arRegisterRow.DocDate; if (fsxARTranRow != null) { if (fsxARTranRow.AppointmentID != null) { fsEquipmentComponentRow.InstAppointmentID = fsxARTranRow.AppointmentID; fsEquipmentComponentRow.InstallationDate = fsxARTranRow.AppointmentDate; } else if (fsxARTranRow.SOID != null) { fsEquipmentComponentRow.InstServiceOrderID = fsxARTranRow.SOID; fsEquipmentComponentRow.InstallationDate = fsxARTranRow.ServiceOrderDate; } fsEquipmentComponentRow.Comment = fsxARTranRow.Comment; } fsEquipmentComponentRow.SerialNumber = arTranRow.LotSerialNbr; fsEquipmentComponentRow = graphSMEquipmentMaint.EquipmentWarranties.Update(fsEquipmentComponentRow); graphSMEquipmentMaint.EquipmentWarranties.SetValueExt <FSEquipmentComponent.inventoryID>(fsEquipmentComponentRow, arTranRow.InventoryID); graphSMEquipmentMaint.EquipmentWarranties.SetValueExt <FSEquipmentComponent.salesDate>(fsEquipmentComponentRow, soLineRow != null && soLineRow.OrderDate != null ? soLineRow.OrderDate : arTranRow.TranDate); graphSMEquipmentMaint.Save.Press(); } } } }
public virtual void Create_Replace_Equipments(SMEquipmentMaint graphSMEquipmentMaint, PXResultset <InventoryItem> inventoryItemSet, ARRegister arRegisterRow, Dictionary <int?, int?> newEquiments, string action) { foreach (PXResult <InventoryItem, ARTran, SOLine> bqlResult in inventoryItemSet) { ARTran arTranRow = (ARTran)bqlResult; //Fetching the cached data record for ARTran that will be updated later arTranRow = PXSelect <ARTran, Where < ARTran.tranType, Equal <Required <ARTran.tranType> >, And <ARTran.refNbr, Equal <Required <ARTran.refNbr> >, And <ARTran.lineNbr, Equal <Required <ARTran.lineNbr> > > > > > .Select(Base, arTranRow.TranType, arTranRow.RefNbr, arTranRow.LineNbr); InventoryItem inventoryItemRow = (InventoryItem)bqlResult; SOLine soLineRow = (SOLine)bqlResult; FSEquipment fsEquipmentRow = null; FSxARTran fsxARTranRow = PXCache <ARTran> .GetExtension <FSxARTran>(arTranRow); FSxEquipmentModel fsxEquipmentModelRow = PXCache <InventoryItem> .GetExtension <FSxEquipmentModel>(inventoryItemRow); for (int i = 0; i < arTranRow.Qty; i++) { SoldInventoryItem soldInventoryItemRow = new SoldInventoryItem(); soldInventoryItemRow.CustomerID = arRegisterRow.CustomerID; soldInventoryItemRow.CustomerLocationID = arRegisterRow.CustomerLocationID; soldInventoryItemRow.InventoryID = inventoryItemRow.InventoryID; soldInventoryItemRow.InventoryCD = inventoryItemRow.InventoryCD; soldInventoryItemRow.InvoiceRefNbr = arTranRow.RefNbr; soldInventoryItemRow.InvoiceLineNbr = arTranRow.LineNbr; soldInventoryItemRow.DocType = arRegisterRow.DocType; soldInventoryItemRow.DocDate = arTranRow.TranDate != null ? arTranRow.TranDate : arRegisterRow.DocDate; if (fsxARTranRow != null) { if (fsxARTranRow.AppointmentID != null) { soldInventoryItemRow.DocDate = fsxARTranRow.AppointmentDate; } else if (fsxARTranRow.SOID != null) { soldInventoryItemRow.DocDate = fsxARTranRow.ServiceOrderDate; } } soldInventoryItemRow.Descr = inventoryItemRow.Descr; soldInventoryItemRow.SiteID = arTranRow.SiteID; soldInventoryItemRow.ItemClassID = inventoryItemRow.ItemClassID; soldInventoryItemRow.SOOrderType = arTranRow.SOOrderType; soldInventoryItemRow.SOOrderNbr = arTranRow.SOOrderNbr; soldInventoryItemRow.SOOrderDate = soLineRow.OrderDate; soldInventoryItemRow.EquipmentTypeID = fsxEquipmentModelRow.EquipmentTypeID; soldInventoryItemRow.LotSerialNumber = arTranRow.LotSerialNbr; fsEquipmentRow = SharedFunctions.CreateSoldEquipment(graphSMEquipmentMaint, soldInventoryItemRow, arTranRow, fsxARTranRow, soLineRow, action, inventoryItemRow); } if (fsEquipmentRow != null) { if (fsxARTranRow.SuspendedSMEquipmentID == null && action == ID.Equipment_Action.REPLACING_TARGET_EQUIPMENT) { fsxARTranRow.SuspendedSMEquipmentID = fsxARTranRow.SMEquipmentID; } fsxARTranRow.SMEquipmentID = fsEquipmentRow.SMEquipmentID; Base.ARTran_TranType_RefNbr.Update(arTranRow); if (action == ID.Equipment_Action.SELLING_TARGET_EQUIPMENT) { int?smEquipmentID = -1; if (newEquiments.TryGetValue(arTranRow.LineNbr, out smEquipmentID) == false) { newEquiments.Add( arTranRow.LineNbr, fsEquipmentRow.SMEquipmentID); } } else if (action == ID.Equipment_Action.REPLACING_TARGET_EQUIPMENT) { if (fsxARTranRow != null) { graphSMEquipmentMaint.EquipmentRecords.Current = graphSMEquipmentMaint.EquipmentRecords.Search <FSEquipment.SMequipmentID>(fsxARTranRow.SuspendedSMEquipmentID); graphSMEquipmentMaint.EquipmentRecords.Current.ReplaceEquipmentID = fsEquipmentRow.SMEquipmentID; graphSMEquipmentMaint.EquipmentRecords.Current.Status = ID.Equipment_Status.DISPOSED; graphSMEquipmentMaint.EquipmentRecords.Current.DisposalDate = soLineRow.OrderDate != null ? soLineRow.OrderDate : arTranRow.TranDate; graphSMEquipmentMaint.EquipmentRecords.Current.DispServiceOrderID = fsxARTranRow.SOID; graphSMEquipmentMaint.EquipmentRecords.Current.DispAppointmentID = fsxARTranRow.AppointmentID; graphSMEquipmentMaint.EquipmentRecords.Cache.SetStatus(graphSMEquipmentMaint.EquipmentRecords.Current, PXEntryStatus.Updated); graphSMEquipmentMaint.Save.Press(); } } } } }
public virtual FSContractPostDoc CreateInvoiceByContract(PXGraph graphProcess, DateTime?invoiceDate, string invoiceFinPeriodID, FSContractPostBatch fsContractPostBatchRow, FSServiceContract fsServiceContractRow, FSContractPeriod fsContractPeriodRow, List <ContractInvoiceLine> docLines) { if (docLines.Count == 0) { return(null); } FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graphProcess); ARInvoice arInvoiceRow = new ARInvoice(); arInvoiceRow.DocType = ARInvoiceType.Invoice; AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().InvoiceNumberingID); arInvoiceRow.DocDate = invoiceDate; arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow.Hold = true; arInvoiceRow = Base.Document.Insert(arInvoiceRow); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerID>(arInvoiceRow, fsServiceContractRow.BillCustomerID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceContractRow.BillLocationID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.branchID>(arInvoiceRow, fsServiceContractRow.BranchID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.docDesc>(arInvoiceRow, (PXMessages.LocalizeFormatNoPrefix(TX.Messages.CONTRACT_WITH_STANDARDIZED_BILLING, fsServiceContractRow.RefNbr, (string.IsNullOrEmpty(fsServiceContractRow.DocDesc) ? string.Empty : fsServiceContractRow.DocDesc)))); string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceContractRow.BillCustomerID, null); if (termsID != null) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, termsID); } else { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, fsSetupRow.DfltContractTermIDARSO); } Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.projectID>(arInvoiceRow, fsServiceContractRow.ProjectID); ARTran arTranRow = null; FSxARTran fsxARTranRow = null; int? acctID; foreach (ContractInvoiceLine docLine in docLines) { arTranRow = new ARTran(); arTranRow = Base.Transactions.Insert(arTranRow); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.inventoryID>(arTranRow, docLine.InventoryID); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.uOM>(arTranRow, docLine.UOM); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.salesPersonID>(arTranRow, docLine.SalesPersonID); arTranRow = Base.Transactions.Update(arTranRow); if (docLine.AcctID != null) { acctID = docLine.AcctID; } else { acctID = (int?)ServiceOrderCore.Get_INItemAcctID_DefaultValue(graphProcess, fsSetupRow.ContractSalesAcctSource, docLine.InventoryID, fsServiceContractRow); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.accountID>(arTranRow, acctID); if (docLine.SubID != null) { try { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.subID>(arTranRow, docLine.SubID); } catch (PXException) { arTranRow.SubID = null; } } else { InvoicingFunctions.SetCombinedSubID(graphProcess, Base.Transactions.Cache, arTranRow, null, null, fsSetupRow, arTranRow.BranchID, arTranRow.InventoryID, arInvoiceRow.CustomerLocationID, fsServiceContractRow.BranchLocationID); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, docLine.Qty); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice); if (docLine.ServiceContractID != null && docLine.ContractRelated == false && (docLine.SODetID != null || docLine.AppDetID != null)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyExtPrice>(arTranRow, docLine.CuryBillableExtPrice); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.discPct>(arTranRow, docLine.DiscPct); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.tranDesc>(arTranRow, docLine.TranDescPrefix + arTranRow.TranDesc); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taskID>(arTranRow, docLine.ProjectTaskID); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.costCodeID>(arTranRow, docLine.CostCodeID); arTranRow = Base.Transactions.Update(arTranRow); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.commissionable>(arTranRow, docLine.Commissionable ?? false); fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow); fsxARTranRow.Source = ID.DocumentSource.INVOICE_FROM_SERVICECONTRACT; fsxARTranRow.ServiceContractID = fsServiceContractRow.ServiceContractID; fsxARTranRow.ContractPeriodID = fsContractPeriodRow.ContractPeriodID; fsxARTranRow.BillCustomerID = fsServiceContractRow.CustomerID; fsxARTranRow.CustomerLocationID = fsServiceContractRow.CustomerLocationID; arTranRow = Base.Transactions.Update(arTranRow); } if (Base.ARSetup.Current.RequireControlTotal == true) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal); } Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, false); Exception newException = null; try { Base.Save.Press(); } catch (Exception e) { List <ErrorInfo> errorList = this.GetErrorInfo(); newException = InvoicingFunctions.GetErrorInfoInLines(errorList, e); } if (newException != null) { throw newException; } arInvoiceRow = Base.Document.Current; FSContractPostDoc fsContractCreatedDocRow = new FSContractPostDoc() { ContractPeriodID = fsContractPeriodRow.ContractPeriodID, ContractPostBatchID = fsContractPostBatchRow.ContractPostBatchID, PostDocType = arInvoiceRow.DocType, PostedTO = ID.Batch_PostTo.AR, PostRefNbr = arInvoiceRow.RefNbr, ServiceContractID = fsServiceContractRow.ServiceContractID }; return(fsContractCreatedDocRow); }
private void Create_Replace_Equipments( SMEquipmentMaint graphSMEquipmentMaint, PXResultset <InventoryItem> inventoryItemSet, ARRegister arRegisterRow, Dictionary <int?, int?> newEquiments, string action) { foreach (PXResult <InventoryItem, ARTran, SOLineSplit, SOLine, SOShipLineSplit> bqlResult in inventoryItemSet) { ARTran arTranRow = (ARTran)bqlResult; InventoryItem inventoryItemRow = (InventoryItem)bqlResult; SOLine soLineRow = (SOLine)bqlResult; SOLineSplit soLineSplitRow = (SOLineSplit)bqlResult; SOShipLineSplit soShipLineSplitRow = (SOShipLineSplit)bqlResult; FSEquipment fsEquipmentRow = null; FSxSOLine fsxSOLineRow = PXCache <SOLine> .GetExtension <FSxSOLine>(soLineRow); FSxARTran fsxARTranRow = PXCache <ARTran> .GetExtension <FSxARTran>(arTranRow); FSxEquipmentModel fsxEquipmentModelRow = PXCache <InventoryItem> .GetExtension <FSxEquipmentModel>(inventoryItemRow); int?iteratorMax = (int?)(soShipLineSplitRow == null || soShipLineSplitRow.Qty == null ? soLineSplitRow.Qty : soShipLineSplitRow.Qty); for (int i = 0; i < iteratorMax; i++) { SoldInventoryItem soldInventoryItemRow = new SoldInventoryItem(); soldInventoryItemRow.CustomerID = arRegisterRow.CustomerID; soldInventoryItemRow.CustomerLocationID = arRegisterRow.CustomerLocationID; soldInventoryItemRow.InventoryID = inventoryItemRow.InventoryID; soldInventoryItemRow.InventoryCD = inventoryItemRow.InventoryCD; soldInventoryItemRow.InvoiceRefNbr = arTranRow.RefNbr; soldInventoryItemRow.InvoiceLineNbr = arTranRow.LineNbr; soldInventoryItemRow.DocType = arRegisterRow.DocType; soldInventoryItemRow.DocDate = arTranRow.TranDate != null ? arTranRow.TranDate : arRegisterRow.DocDate; if (fsxSOLineRow != null) { if (fsxSOLineRow.AppointmentID != null) { soldInventoryItemRow.DocDate = fsxSOLineRow.AppointmentDate; } else if (fsxSOLineRow.SOID != null) { soldInventoryItemRow.DocDate = fsxSOLineRow.ServiceOrderDate; } } soldInventoryItemRow.Descr = inventoryItemRow.Descr; soldInventoryItemRow.SiteID = arTranRow.SiteID; soldInventoryItemRow.ItemClassID = inventoryItemRow.ItemClassID; soldInventoryItemRow.SOOrderType = soLineRow.OrderType; soldInventoryItemRow.SOOrderNbr = soLineRow.OrderNbr; soldInventoryItemRow.SOOrderDate = soLineRow.OrderDate; soldInventoryItemRow.EquipmentTypeID = fsxEquipmentModelRow.EquipmentTypeID; if (soLineSplitRow != null) { soldInventoryItemRow.LotSerialNumber = soLineSplitRow.LotSerialNbr; } if (soldInventoryItemRow.LotSerialNumber == null && soShipLineSplitRow != null) { soldInventoryItemRow.LotSerialNumber = soShipLineSplitRow.LotSerialNbr; } fsEquipmentRow = SharedFunctions.CreateSoldEquipment(graphSMEquipmentMaint, soldInventoryItemRow, soLineRow, fsxSOLineRow, action, inventoryItemRow); } if (fsEquipmentRow != null) { fsxARTranRow.SMEquipmentID = fsEquipmentRow.SMEquipmentID; Base.ARTran_TranType_RefNbr.Update(arTranRow); if (action == ID.Equipment_Action.SELLING_TARGET_EQUIPMENT) { int?smEquipmentID = -1; if (newEquiments.TryGetValue(soLineRow.LineNbr, out smEquipmentID) == false) { newEquiments.Add( soLineRow.LineNbr, fsEquipmentRow.SMEquipmentID); } } else if (action == ID.Equipment_Action.REPLACING_TARGET_EQUIPMENT) { if (fsxSOLineRow != null) { graphSMEquipmentMaint.EquipmentRecords.Current = graphSMEquipmentMaint.EquipmentRecords.Search <FSEquipment.SMequipmentID>(fsxSOLineRow.SMEquipmentID); graphSMEquipmentMaint.EquipmentRecords.Current.ReplaceEquipmentID = fsEquipmentRow.SMEquipmentID; graphSMEquipmentMaint.EquipmentRecords.Current.Status = ID.Equipment_Status.DISPOSED; graphSMEquipmentMaint.EquipmentRecords.Current.DisposalDate = soLineRow.OrderDate; graphSMEquipmentMaint.EquipmentRecords.Current.DispServiceOrderID = fsxSOLineRow.SOID; graphSMEquipmentMaint.EquipmentRecords.Current.DispAppointmentID = fsxSOLineRow.AppointmentID; graphSMEquipmentMaint.EquipmentRecords.Cache.SetStatus(graphSMEquipmentMaint.EquipmentRecords.Current, PXEntryStatus.Updated); graphSMEquipmentMaint.Save.Press(); } } } } }
private void ReplaceComponents( SMEquipmentMaint graphSMEquipmentMaint, ARRegister arRegisterRow) { var inventoryItemSet = PXSelectJoin <InventoryItem, InnerJoin <ARTran, On <ARTran.inventoryID, Equal <InventoryItem.inventoryID>, And <ARTran.tranType, Equal <ARDocType.invoice> > >, InnerJoin <SOLineSplit, On <SOLineSplit.orderType, Equal <ARTran.sOOrderType>, And <SOLineSplit.orderNbr, Equal <ARTran.sOOrderNbr>, And <SOLineSplit.lineNbr, Equal <ARTran.sOOrderLineNbr>, And <SOLineSplit.qty, Greater <Zero> > > > >, InnerJoin <SOLine, On <SOLine.orderType, Equal <SOLineSplit.orderType>, And <SOLine.orderNbr, Equal <SOLineSplit.orderNbr>, And <SOLine.lineNbr, Equal <SOLineSplit.lineNbr> > > >, LeftJoin <SOShipLineSplit, On <SOShipLineSplit.origOrderType, Equal <SOLineSplit.orderType>, And <SOShipLineSplit.origOrderNbr, Equal <SOLineSplit.orderNbr>, And <SOShipLineSplit.origLineNbr, Equal <SOLineSplit.lineNbr>, And <SOShipLineSplit.origSplitLineNbr, Equal <SOLineSplit.splitLineNbr> > > > > > > > >, Where < ARTran.tranType, Equal <Required <ARInvoice.docType> >, And <ARTran.refNbr, Equal <Required <ARInvoice.refNbr> >, And <FSxEquipmentModel.eQEnabled, Equal <True>, And <FSxSOLine.equipmentAction, Equal <ListField_EquipmentAction.ReplacingComponent>, And <FSxSOLine.sMEquipmentID, IsNotNull, And <FSxSOLine.newTargetEquipmentLineNbr, IsNull, And <FSxSOLine.equipmentLineRef, IsNotNull, And <SOLineSplit.pOCreate, Equal <False> > > > > > > > >, OrderBy < Asc <ARTran.tranType, Asc <ARTran.refNbr, Asc <ARTran.lineNbr> > > > > .Select(Base, arRegisterRow.DocType, arRegisterRow.RefNbr); foreach (PXResult <InventoryItem, ARTran, SOLineSplit, SOLine, SOShipLineSplit> bqlResult in inventoryItemSet) { ARTran arTranRow = (ARTran)bqlResult; InventoryItem inventoryItemRow = (InventoryItem)bqlResult; SOLine soLineRow = (SOLine)bqlResult; SOLineSplit soLineSplitRow = (SOLineSplit)bqlResult; SOShipLineSplit soShipLineSplitRow = (SOShipLineSplit)bqlResult; FSxSOLine fsxSOLineRow = PXCache <SOLine> .GetExtension <FSxSOLine>(soLineRow); FSxARTran fsxARTranRow = PXCache <ARTran> .GetExtension <FSxARTran>(arTranRow); graphSMEquipmentMaint.EquipmentRecords.Current = graphSMEquipmentMaint.EquipmentRecords.Search <FSEquipment.SMequipmentID>(fsxSOLineRow.SMEquipmentID); FSEquipmentComponent fsEquipmentComponentRow = graphSMEquipmentMaint.EquipmentWarranties.Select().Where(x => ((FSEquipmentComponent)x).LineNbr == fsxSOLineRow.EquipmentLineRef).FirstOrDefault(); FSEquipmentComponent fsNewEquipmentComponentRow = new FSEquipmentComponent(); fsNewEquipmentComponentRow.ComponentID = fsxSOLineRow.ComponentID; fsNewEquipmentComponentRow = graphSMEquipmentMaint.ApplyComponentReplacement(fsEquipmentComponentRow, fsNewEquipmentComponentRow); fsNewEquipmentComponentRow.SalesOrderNbr = soLineRow.OrderNbr; fsNewEquipmentComponentRow.SalesOrderType = soLineRow.OrderType; fsNewEquipmentComponentRow.InvoiceRefNbr = arTranRow.RefNbr; fsNewEquipmentComponentRow.InstallationDate = arTranRow.TranDate != null ? arTranRow.TranDate : arRegisterRow.DocDate; if (fsxSOLineRow != null) { if (fsxSOLineRow.AppointmentID != null) { fsNewEquipmentComponentRow.InstAppointmentID = fsxSOLineRow.AppointmentID; fsNewEquipmentComponentRow.InstallationDate = fsxSOLineRow.AppointmentDate; } else if (fsxSOLineRow.SOID != null) { fsNewEquipmentComponentRow.InstServiceOrderID = fsxSOLineRow.SOID; fsNewEquipmentComponentRow.InstallationDate = fsxSOLineRow.ServiceOrderDate; } fsNewEquipmentComponentRow.Comment = fsxSOLineRow.Comment; } fsNewEquipmentComponentRow.LongDescr = soLineRow.TranDesc; if (soLineSplitRow != null) { fsNewEquipmentComponentRow.SerialNumber = soLineSplitRow.LotSerialNbr; } if (fsNewEquipmentComponentRow.SerialNumber == null && soShipLineSplitRow != null) { fsNewEquipmentComponentRow.SerialNumber = soShipLineSplitRow.LotSerialNbr; } fsNewEquipmentComponentRow = graphSMEquipmentMaint.EquipmentWarranties.Update(fsNewEquipmentComponentRow); graphSMEquipmentMaint.EquipmentWarranties.SetValueExt <FSEquipmentComponent.inventoryID>(fsNewEquipmentComponentRow, soLineRow.InventoryID); graphSMEquipmentMaint.EquipmentWarranties.SetValueExt <FSEquipmentComponent.salesDate>(fsNewEquipmentComponentRow, soLineRow.OrderDate); graphSMEquipmentMaint.Save.Press(); } }