public override INItemPlan DefaultValues(PXCache sender, INItemPlan plan_Row, object origRow) { ARTran tran = (ARTran)origRow; if (tran.Released == true || tran.SOShipmentNbr != null || tran.SOOrderNbr != null || tran.LineType != SOLineType.Inventory || tran.InvtMult == 0) { return(null); } PXCache cache = sender.Graph.Caches[BqlCommand.GetItemType(_ParentNoteID)]; bool? hold = (bool?)cache.GetValue(cache.Current, _ParentHoldEntry.Name) | (bool?)cache.GetValue <ARInvoice.creditHold>(cache.Current); plan_Row.BAccountID = tran.CustomerID; plan_Row.PlanType = (hold == true) ? INPlanConstants.Plan69 : INPlanConstants.Plan62; plan_Row.InventoryID = tran.InventoryID; plan_Row.SubItemID = tran.SubItemID; plan_Row.SiteID = tran.SiteID; plan_Row.LocationID = tran.LocationID; plan_Row.LotSerialNbr = tran.LotSerialNbr; plan_Row.Reverse = (tran.InvtMult > 0) ^ (tran.BaseQty < 0m); plan_Row.PlanDate = (DateTime?)cache.GetValue <ARRegister.docDate>(cache.Current); plan_Row.PlanQty = Math.Abs(tran.BaseQty ?? 0m); plan_Row.RefNoteID = (Guid?)cache.GetValue(cache.Current, _ParentNoteID.Name); plan_Row.Hold = hold; return(plan_Row); }
protected virtual void InsertARTran(ARInvoiceEntry arGraph, EPExpenseClaimDetails row, bool copyNotes, bool copyFiles) { ARTran tran = (ARTran)arGraph.Transactions.Cache.CreateInstance(); tran.InventoryID = row.InventoryID; tran.TranDesc = row.TranDesc; tran.TranCost = row.ExtCost; tran.Qty = row.Qty; tran.UOM = row.UOM; tran.CuryTranAmt = row.CuryTranAmt; tran.AccountID = row.SalesAccountID; tran.SubID = row.SalesSubID; tran.Date = row.ExpenseDate; tran = arGraph.Transactions.Insert(tran); if (copyNotes) { string note = PXNoteAttribute.GetNote(Caches[typeof(EPExpenseClaimDetails)], row); if (note != null) { PXNoteAttribute.SetNote(arGraph.Transactions.Cache, tran, note); } } if (copyFiles) { Guid[] files = PXNoteAttribute.GetFileNotes(Caches[typeof(EPExpenseClaimDetails)], row); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(arGraph.Transactions.Cache, tran, files); } } }
protected virtual void ARTran_InventoryID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { if (!e.ExternalCall) { e.Cancel = true; } ARTran tran = (ARTran)e.Row; if (tran == null) { return; } if (Base.Document.Current == null) { return; } if (e.NewValue == null) { return; } string value = Rutrots.Current?.RUTROTType; InventoryItem item = (InventoryItem)Base.InventoryItem.Select((int)e.NewValue); InventoryItemRUTROT itemRR = RUTROTHelper.GetExtensionNullable <InventoryItem, InventoryItemRUTROT>(item); if (!RUTROTHelper.IsItemMatchRUTROTType(value, item, itemRR, itemRR?.IsRUTROTDeductible == true)) { sender.RaiseExceptionHandling <ARTran.inventoryID>(tran, item.InventoryCD, new PXSetPropertyException <ARTran.inventoryID>(RUTROTMessages.LineDoesNotMatchDoc)); e.NewValue = item.InventoryCD; throw new PXSetPropertyException <ARTran.inventoryID>(RUTROTMessages.LineDoesNotMatchDoc); } }
protected override void Master_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Insert || (e.Operation & PXDBOperation.Command) == PXDBOperation.Update) { ARTran row = (ARTran)e.Row; if (Math.Abs((decimal)row.BaseQty) >= 0.0000005m && (row.UnassignedQty >= 0.0000005m || row.UnassignedQty <= -0.0000005m)) { if (sender.RaiseExceptionHandling <ARTran.qty>(row, row.Qty, new PXSetPropertyException(Messages.BinLotSerialNotAssigned))) { throw new PXRowPersistingException(typeof(ARTran.qty).Name, row.Qty, Messages.BinLotSerialNotAssigned); } } try { returnRecords = null; if (!MemoAvailabilityCheckQty(sender, row)) { RaiseAvailabilityException(sender, row, typeof(ARTran.qty), Messages.InvoiceCheck_DecreaseQty, true, sender.GetValueExt <ARTran.origInvoiceNbr>(row), sender.GetValueExt <ARTran.inventoryID>(row), returnRecords == null ? string.Empty : string.Join(", ", returnRecords.Select(x => x.DocumentNbr))); } } finally { returnRecords = null; } OrderAvailabilityCheck(sender, row, onPersist: true); } base.Master_RowPersisting(sender, e); }
public static void ClearInvoiceDetailsBalance(this ARTran tran) { tran.CuryCashDiscBal = 0m; tran.CashDiscBal = 0m; tran.CuryRetainedTaxableAmt = 0m; tran.RetainedTaxableAmt = 0m; tran.CuryRetainedTaxAmt = 0m; tran.RetainedTaxAmt = 0m; tran.CuryRetainageBal = 0m; tran.RetainageBal = 0m; tran.CuryOrigRetainageAmt = 0m; tran.OrigRetainageAmt = 0m; tran.CuryOrigTranAmt = 0m; tran.OrigTranAmt = 0m; tran.CuryTranBal = 0m; tran.TranBal = 0m; tran.CuryOrigTaxableAmt = 0m; tran.OrigTaxableAmt = 0m; tran.CuryOrigTaxAmt = 0m; tran.OrigTaxAmt = 0m; }
protected virtual void ARTran_ManualDisc_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e, PXFieldUpdated del) { // Event handler body before the base BLC event handler collection if (del != null) { del(sender, e); } // Event handler body after the base BLC event handler collection if (e.Row != null) { ARTran row = (ARTran)e.Row; if (row != null) { if (!(bool)row.ManualDisc) { ARTranExt rowext = PXCache <ARTran> .GetExtension <ARTranExt>(row); if (rowext != null) { rowext.UsrDiscountReasonID = null; } } } } }
public virtual void ARTran_IsRUTROTDeductible_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { ARTran tran = (ARTran)e.Row; if (tran == null) { return; } if (Base.Document.Current == null) { return; } if (e.NewValue == null || (bool)e.NewValue == false) { return; } string value = Rutrots.Current?.RUTROTType; InventoryItem item = (InventoryItem)Base.InventoryItem.Select(tran.InventoryID); InventoryItemRUTROT itemRR = RUTROTHelper.GetExtensionNullable <InventoryItem, InventoryItemRUTROT>(item); if (!RUTROTHelper.IsItemMatchRUTROTType(value, item, itemRR, (bool)e.NewValue)) { sender.RaiseExceptionHandling <ARTranRUTROT.isRUTROTDeductible>(tran, false, new PXSetPropertyException <ARTranRUTROT.isRUTROTDeductible>(RUTROTMessages.LineDoesNotMatchDoc)); e.NewValue = false; throw new PXSetPropertyException <ARTranRUTROT.isRUTROTDeductible>(RUTROTMessages.LineDoesNotMatchDoc); } }
protected virtual void InsertARTran(ARInvoiceEntry arGraph, EPExpenseClaimDetails row, decimal signOperation) { CurrencyInfo curyInfo = PXSelect <CurrencyInfo> .Search <CurrencyInfo.curyInfoID>(arGraph, row.CuryInfoID); decimal curyamount; if (arGraph.currencyinfo.Current != null && curyInfo != null && arGraph.currencyinfo.Current.CuryID == curyInfo.CuryID) { curyamount = row.CuryTranAmt.GetValueOrDefault(0); } else { CM.PXCurrencyAttribute.CuryConvCury(arGraph.Document.Cache, arGraph.currencyinfo, row.TranAmt.GetValueOrDefault(), out curyamount); } ARTran tran = arGraph.Transactions.Insert(); tran.InventoryID = row.InventoryID; tran.TranDesc = row.TranDesc; tran.Qty = row.Qty * signOperation; tran.UOM = row.UOM; tran.AccountID = row.SalesAccountID; tran.SubID = row.SalesSubID; tran.Date = row.ExpenseDate; tran.CuryTranAmt = curyamount * signOperation; tran.CuryUnitPrice = (curyamount / (row.Qty.GetValueOrDefault(1m) != 0m ? row.Qty.GetValueOrDefault(1m) : 1m)) * signOperation; tran.CuryExtPrice = curyamount * signOperation; tran = arGraph.Transactions.Update(tran); PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(EPExpenseClaimDetails)], row, arGraph.Transactions.Cache, tran, Setup.Current.GetCopyNoteSettings <PXModule.ar>()); }
public virtual IAddressBase GetFromAddress(ARInvoice invoice, ARTran tran, GetFromAddressLineDelegate del) { int?SOID = GetSOIDRelated(tran); if (SOID != null && tran.SiteID == null) { IAddressBase returnAddress = null; returnAddress = PXSelectJoin <FSAddress, InnerJoin < FSBranchLocation, On <FSBranchLocation.branchLocationAddressID, Equal <FSAddress.addressID> >, InnerJoin <FSServiceOrder, On <FSServiceOrder.branchLocationID, Equal <FSBranchLocation.branchLocationID> > > >, Where < FSServiceOrder.sOID, Equal <Required <FSServiceOrder.sOID> > > > .Select(Base, SOID) .RowCast <FSAddress>() .FirstOrDefault(); return(returnAddress); } return(del(invoice, tran)); }
protected virtual PMBudgetAccum GetTargetBudget(int?accountGroupID, ARTran line) { PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(Base, accountGroupID); PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(Base, line.ProjectID); bool isExisting; BudgetService budgetService = new BudgetService(Base); PX.Objects.PM.Lite.PMBudget budget = budgetService.SelectProjectBalance(ag, project, line.TaskID, line.InventoryID, line.CostCodeID, out isExisting); PMBudgetAccum target = new PMBudgetAccum(); target.Type = budget.Type; target.ProjectID = budget.ProjectID; target.ProjectTaskID = budget.TaskID; target.AccountGroupID = budget.AccountGroupID; target.InventoryID = budget.InventoryID; target.CostCodeID = budget.CostCodeID; target.UOM = budget.UOM; target.Description = budget.Description; target.CuryInfoID = project.CuryInfoID; return(target); }
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 EnsureCanCancel(ARInvoice doc, bool isCorrection) { if (doc.DocType != ARDocType.Invoice) { throw new PXException(Messages.CantCancelDocType, doc.DocType); } if (doc.InstallmentCntr > 0) { throw new PXException(Messages.CantCancelMultipleInstallmentsInvoice); } var arAdjustGroups = PXSelectGroupBy <ARAdjust, Where <ARAdjust.adjdDocType, Equal <Current <ARInvoice.docType> >, And <ARAdjust.adjdRefNbr, Equal <Current <ARInvoice.refNbr> > > >, Aggregate < GroupBy <ARAdjust.adjgDocType, GroupBy <ARAdjust.adjgRefNbr, GroupBy <ARAdjust.released, Sum <ARAdjust.curyAdjdAmt> > > > > > .SelectMultiBound(Base, new[] { doc }) .RowCast <ARAdjust>().ToList(); if (arAdjustGroups.Any(a => a.Released == false)) { throw new PXException(Messages.CantCancelInvoiceWithUnreleasedApplications); } var nonReversedCreditMemo = arAdjustGroups.FirstOrDefault(a => a.CuryAdjdAmt != 0m && a.AdjgDocType == ARDocType.CreditMemo); if (nonReversedCreditMemo != null) { throw new PXException(Messages.CantCancelInvoiceWithCM, nonReversedCreditMemo.AdjdRefNbr, nonReversedCreditMemo.AdjgRefNbr); } var nonReversedApplication = arAdjustGroups.FirstOrDefault(a => a.CuryAdjdAmt != 0m); if (nonReversedApplication != null) { throw new PXException(Messages.CantCancelInvoiceWithPayment, nonReversedApplication.AdjdRefNbr, nonReversedApplication.AdjgRefNbr); } ARTran directSale = PXSelectReadonly <ARTran, Where <ARTran.tranType, Equal <Current <ARInvoice.docType> >, And <ARTran.refNbr, Equal <Current <ARInvoice.refNbr> >, And <ARTran.invtMult, NotEqual <short0>, And <ARTran.lineType, Equal <SOLineType.inventory> > > > > > .SelectSingleBound(Base, new[] { doc }); if (directSale != null) { throw new PXException(Messages.CantCancelInvoiceWithDirectStockSales, doc.RefNbr); } SOOrderShipment notRequireShipment = PXSelectReadonly <SOOrderShipment, Where <SOOrderShipment.invoiceType, Equal <Current <ARInvoice.docType> >, And <SOOrderShipment.invoiceNbr, Equal <Current <ARInvoice.refNbr> >, And <SOOrderShipment.shipmentNbr, Equal <Constants.noShipmentNbr> > > > > .SelectSingleBound(Base, new[] { doc }); if (notRequireShipment != null) { throw new PXException(Messages.CantCancelInvoiceWithOrdersNotRequiringShipments, doc.RefNbr); } }
public Record(ARTran artran, SOLine soline, InventoryItem item, SOSalesPerTran salesPerTran) { this.ARTran = artran; this.SOLine = soline; this.Item = item; this.SalesPerTran = salesPerTran; this.Transactions = new Dictionary <int, INTransaction>(); }
public static void RecoverInvoiceDetailsBalance(this ARTran tran) { tran.CuryRetainageBal = tran.CuryOrigRetainageAmt; tran.RetainageBal = tran.OrigRetainageAmt; tran.CuryTranBal = tran.CuryOrigTranAmt; tran.TranBal = tran.OrigTranAmt; }
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 virtual PXResult <SOLine, SOOrderType> GetLinkedSOLine(ARTran row) { return((PXResult <SOLine, SOOrderType>) PXSelectReadonly2 <SOLine, LeftJoin <SOOrderType, On <SOOrderType.orderType, Equal <SOLine.orderType> > >, Where <SOLine.orderType, Equal <Current <ARTran.sOOrderType> >, And <SOLine.orderNbr, Equal <Current <ARTran.sOOrderNbr> >, And <SOLine.lineNbr, Equal <Current <ARTran.sOOrderLineNbr> > > > > > .SelectSingleBound(_Graph, new[] { row })); }
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; } } } }
private void ValidateTransaction(ARTran transaction) { var documentHasExpiredCompliance = service.ValidateRelatedField <ARTran, ComplianceDocument.revenueTaskID, ARTran.taskID>(transaction, transaction.TaskID); service.ValidateRelatedRow <ARTran, ArTranExt.hasExpiredComplianceDocuments>(transaction, documentHasExpiredCompliance); }
public decimal GetQuantityInBaseUOMs(ARTran tran) { return(INUnitAttribute.ConvertToBase( this.Caches[typeof(ARTran)], tran.InventoryID, tran.UOM, (tran.Qty ?? 0), INPrecision.QUANTITY)); }
public virtual void ARTran_LocationID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { ARTran row = (ARTran)e.Row; if (row != null && (row.InvtMult == 0 || row.LineType != SOLineType.Inventory)) { e.Cancel = true; } }
public BillingData(ARTran tran, PMBillingRule rule, PMTran pmTran, string subCD, string note, Guid[] files) { this.Tran = tran; this.Rule = rule; this.PMTran = pmTran; this.SubCD = subCD; this.Note = note; this.Files = files; }
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 override ARTranAsSplit Convert(ARTran item) { using (new InvtMultScope <ARTran>(item)) { ARTranAsSplit ret = ARTranAsSplit.FromARTran(item); //baseqty will be overriden in all cases but AvailabilityFetch ret.BaseQty = item.BaseQty - item.UnassignedQty; return(ret); } }
protected virtual void ARTran_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { ARTran row = (ARTran)e.Row; ARTran oldRow = (ARTran)e.OldRow; if (row != null) { SyncBudgets(row, oldRow); } }
public virtual void ProcessARTranInventory(ARTran n, ARInvoice ardoc, JournalEntry je) { if (Base.IsIntegrityCheck) { return; } bool tranCostSet = HandleARTranCost(n, ardoc, je); HandleARTranCostOrig(n, tranCostSet); }
public override void UpdateParent(PXCache sender, ARTran Row, ARTranAsSplit Det, ARTranAsSplit OldDet, out decimal BaseQty) { ARTran oldRow = (ARTran)sender.CreateCopy(Row); base.UpdateParent(sender, Row, Det, OldDet, out BaseQty); if (!sender.ObjectsEqual <ARTran.subItemID, ARTran.locationID, ARTran.lotSerialNbr, ARTran.expireDate>(oldRow, Row)) { ARTranPlanIDAttribute.RaiseRowUpdated(sender, Row, oldRow); } }
protected virtual void DRSchedule_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { DRSchedule row = e.Row as DRSchedule; if (row != null) { row.DocumentType = DRScheduleDocumentType.BuildDocumentType(row.Module, row.DocType); if (row.Module == BatchModule.AR) { row.BAccountType = CR.BAccountType.CustomerType; ARTran tran = PXSelect <ARTran, Where <ARTran.tranType, Equal <Current <DRSchedule.docType> >, And <ARTran.refNbr, Equal <Current <DRSchedule.refNbr> >, And <ARTran.lineNbr, Equal <Current <DRSchedule.lineNbr> > > > > > .Select(this); if (tran != null) { row.OrigLineAmt = tran.TranAmt; } } else { row.BAccountType = CR.BAccountType.VendorType; APTran tran = PXSelect <APTran, Where <APTran.tranType, Equal <Current <DRSchedule.docType> >, And <APTran.refNbr, Equal <Current <DRSchedule.refNbr> >, And <APTran.lineNbr, Equal <Current <DRSchedule.lineNbr> > > > > > .Select(this); if (tran != null) { row.OrigLineAmt = tran.TranAmt; } } release.SetVisible(row.IsCustom == true); release.SetEnabled(row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.documentType>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.finPeriodID>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.refNbr>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.lineNbr>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.docDate>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.bAccountID>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.bAccountLocID>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.projectID>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetEnabled <DRSchedule.taskID>(sender, row, row.IsCustom == true); PXUIFieldAttribute.SetVisible <DRSchedule.origLineAmt>(sender, row, row.IsCustom != true); Components.Cache.AllowInsert = row.IsDraft == true; Components.Cache.AllowUpdate = row.IsDraft == true; Components.Cache.AllowDelete = row.IsDraft == true; } }
/// <summary> /// Checks if deferral code has been changed or removed from the line. /// If so, ensures the removal of any associated deferral schedules. /// </summary> public static void DeleteAssociatedScheduleIfDeferralCodeChanged( PXCache cache, ARTran documentLine) { // Obtain the document line last saved into the database // to check if the new line's deferral code differs from it. // - ARTran oldLine = GetOriginal <ARTran>(cache, documentLine); DeleteAssociatedScheduleIfDeferralCodeChanged(cache.Graph, documentLine, oldLine); }
public virtual bool HasStockComponents(ARTran n) { return(n.IsTranCostFinal == true || (PXSelect <SOShipLineSplit, Where <SOShipLineSplit.shipmentNbr, Equal <Current <ARTran.sOShipmentNbr> >, And <SOShipLineSplit.lineNbr, Equal <Current <ARTran.sOShipmentLineNbr> >, And <SOShipLineSplit.isStockItem, Equal <True> > > > > .SelectSingleBound(Base, new object[] { n }).Count() == 0 && PXSelect <SOLineSplit, Where <SOLineSplit.orderType, Equal <Current <ARTran.sOOrderType> >, And <SOLineSplit.orderNbr, Equal <Current <ARTran.sOOrderNbr> >, And <SOLineSplit.lineNbr, Equal <Current <ARTran.sOOrderLineNbr> >, And <SOLineSplit.isStockItem, Equal <True> > > > > > .SelectSingleBound(Base, new object[] { n }).Count() == 0)); }
protected virtual void ARTran_RowInserting(PXCache sender, PXRowInsertingEventArgs e) { if (e.Row == null) { return; } ARTran row = e.Row as ARTran; ARTranRUTROT rowRR = RUTROTHelper.GetExtensionNullable <ARTran, ARTranRUTROT>(row); rowRR.CuryRUTROTTaxAmountDeductible = decimal.Zero; }
protected override void RecalculateDiscounts(PXCache sender, ARTran line) { if (line.InventoryID != null && line.Qty != null && line.CuryLineAmt != null && line.IsFree != true) { DateTime? docDate = Document.Current.DocDate; int? customerLocationID = Document.Current.CustomerLocationID; SOLine soline = PXSelect<SOLine, Where<SOLine.orderType, Equal<Required<SOLine.orderType>>, And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>, And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>.Select(this, line.SOOrderType, line.SOOrderNbr, line.SOOrderLineNbr); if (soline != null) { docDate = soline.OrderDate; } DiscountEngine<ARTran>.SetDiscounts<SOInvoiceDiscountDetail>(sender, Transactions, line, DiscountDetails, customerLocationID, Document.Current.CuryID, docDate.Value, Document.Current.SkipDiscounts, false, recalcdiscountsfilter.Current); foreach (SOInvoiceDiscountDetail discountDetail in DiscountDetails.Select()) { if (discountDetail.OrderType == null) discountDetail.OrderType = line.SOOrderType ?? Messages.NoOrder; if (discountDetail.OrderNbr == null) discountDetail.OrderNbr = line.SOOrderNbr ?? Messages.NoOrderType; } RecalculateTotalDiscount(); } }
public virtual void InvoiceOrder(DateTime invoiceDate, PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order, PXResultset<SOShipLine, SOLine> details, Customer customer, DocumentList<ARInvoice, SOInvoice> list) { ARInvoice newdoc; SOOrder soOrder = order; SOOrderType ordertype = order; decimal ApprovedBalance = 0; decimal PrevDocBal = 0; PXRowUpdated ApprovedBalanceCollector = delegate(PXCache sender, PXRowUpdatedEventArgs e) { ARInvoice ARDoc = (ARInvoice)e.Row; if ((decimal)ARDoc.DocBal > (decimal)ARDoc.ApprovedCreditAmt) { if ((bool)((SOOrder)order).ApprovedCredit && (decimal)ARDoc.DocBal > PrevDocBal) { ApprovedBalance += (decimal)ARDoc.DocBal - PrevDocBal; ARDoc.ApprovedCreditAmt = ApprovedBalance; } ARDoc.ApprovedCredit = (ApprovedBalance == (decimal)ARDoc.DocBal ? true : false); PrevDocBal = (decimal)ARDoc.DocBal; } }; this.RowUpdated.AddHandler(typeof(ARInvoice), ApprovedBalanceCollector); if (list != null) { bool iscc = false; DateTime? orderInvoiceDate = (sosetup.Current.UseShipDateForInvoiceDate == true ? ((SOOrderShipment)order).ShipDate : soOrder.InvoiceDate); if (soOrder.BillSeparately == false) { iscc = PXSelectReadonly<CCProcTran, Where<CCProcTran.origDocType, Equal<Required<CCProcTran.origDocType>>, And<CCProcTran.origRefNbr, Equal<Required<CCProcTran.origRefNbr>>, And<CCProcTran.refNbr, IsNull>>>>.Select(this, soOrder.OrderType, soOrder.OrderNbr).Count > 0; } if (soOrder.PaymentCntr == 0 && soOrder.BillSeparately == false && iscc == false) { if(soOrder.PaymentMethodID == null && soOrder.CashAccountID == null) newdoc = list.Find<ARInvoice.docType, ARInvoice.docDate, ARInvoice.branchID, ARInvoice.customerID, ARInvoice.customerLocationID, SOInvoice.billAddressID, SOInvoice.billContactID, SOInvoice.extRefNbr, ARInvoice.curyID, ARInvoice.termsID, ARInvoice.hidden>(((SOOrderType)order).ARDocType, orderInvoiceDate ?? invoiceDate, soOrder.BranchID, soOrder.CustomerID, soOrder.CustomerLocationID, soOrder.BillAddressID, soOrder.BillContactID, soOrder.ExtRefNbr, soOrder.CuryID, soOrder.TermsID, false) ?? (ARInvoice)new ARInvoice(); else if (soOrder.CashAccountID == null) newdoc = list.Find<ARInvoice.docType, ARInvoice.docDate, ARInvoice.branchID, ARInvoice.customerID, ARInvoice.customerLocationID, SOInvoice.billAddressID, SOInvoice.billContactID, SOInvoice.pMInstanceID, SOInvoice.extRefNbr, ARInvoice.curyID, ARInvoice.termsID, ARInvoice.hidden>(((SOOrderType)order).ARDocType, orderInvoiceDate ?? invoiceDate, soOrder.BranchID, soOrder.CustomerID, soOrder.CustomerLocationID, soOrder.BillAddressID, soOrder.BillContactID, soOrder.PMInstanceID, soOrder.ExtRefNbr, soOrder.CuryID, soOrder.TermsID, false) ?? (ARInvoice)new ARInvoice(); else newdoc = list.Find<ARInvoice.docType, ARInvoice.docDate, ARInvoice.branchID, ARInvoice.customerID, ARInvoice.customerLocationID, SOInvoice.billAddressID, SOInvoice.billContactID, SOInvoice.pMInstanceID, SOInvoice.cashAccountID, SOInvoice.extRefNbr, ARInvoice.curyID, ARInvoice.termsID, ARInvoice.hidden>(((SOOrderType)order).ARDocType, orderInvoiceDate ?? invoiceDate, soOrder.BranchID, soOrder.CustomerID, soOrder.CustomerLocationID, soOrder.BillAddressID, soOrder.BillContactID, soOrder.PMInstanceID, soOrder.CashAccountID, soOrder.ExtRefNbr, soOrder.CuryID, soOrder.TermsID, false) ?? (ARInvoice)new ARInvoice(); } else { newdoc = list.Find<ARInvoice.hidden, ARInvoice.hiddenOrderType, ARInvoice.hiddenOrderNbr>(true, soOrder.OrderType, soOrder.OrderNbr); if (newdoc == null) { newdoc = new ARInvoice(); newdoc.HiddenOrderType = soOrder.OrderType; newdoc.HiddenOrderNbr = soOrder.OrderNbr; newdoc.Hidden = true; } } if (newdoc.RefNbr != null) { Document.Current = this.Document.Search<ARInvoice.refNbr>(newdoc.RefNbr, newdoc.DocType); } else { this.Clear(); string docType = ((SOOrderType)order).ARDocType; if (((SOOrderShipment)order).Operation == ((SOOrderType)order).DefaultOperation) { newdoc.DocType = docType; } else { //for RMA switch document type if previous shipment was not invoiced previously in the current run, i.e. list.Find() returned null newdoc.DocType = docType == ARDocType.Invoice ? ARDocType.CreditMemo : docType == ARDocType.DebitMemo ? ARDocType.CreditMemo : docType == ARDocType.CreditMemo ? ARDocType.Invoice : docType == ARDocType.CashSale ? ARDocType.CashReturn : docType == ARDocType.CashReturn ? ARDocType.CashSale : null; } newdoc.DocDate = orderInvoiceDate ?? invoiceDate; if (string.IsNullOrEmpty(soOrder.FinPeriodID) == false) { newdoc.FinPeriodID = soOrder.FinPeriodID; } if (soOrder.InvoiceNbr != null) { newdoc.RefNbr = soOrder.InvoiceNbr; newdoc.RefNoteID = soOrder.NoteID; } if (((SOOrderType)order).UserInvoiceNumbering == true && string.IsNullOrEmpty(newdoc.RefNbr)) { throw new PXException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName<SOOrder.invoiceNbr>(soorder.Cache)); } AutoNumberAttribute.SetNumberingId<ARInvoice.refNbr>(Document.Cache, ((SOOrderType)order).ARDocType, ((SOOrderType)order).InvoiceNumberingID); newdoc = (ARInvoice)Document.Cache.CreateCopy(this.Document.Insert(newdoc)); newdoc.BranchID = soOrder.BranchID; newdoc.CustomerID = ((SOOrder)order).CustomerID; newdoc.CustomerLocationID = ((SOOrder)order).CustomerLocationID; newdoc.TermsID = ((SOOrder)order).TermsID; newdoc.DiscDate = ((SOOrder)order).DiscDate; newdoc.DueDate = ((SOOrder)order).DueDate; newdoc.TaxZoneID = ((SOOrder)order).TaxZoneID; newdoc.AvalaraCustomerUsageType = ((SOOrder)order).AvalaraCustomerUsageType; newdoc.SalesPersonID = ((SOOrder)order).SalesPersonID; newdoc.DocDesc = ((SOOrder)order).OrderDesc; newdoc.InvoiceNbr = ((SOOrder)order).CustomerOrderNbr; newdoc.CuryID = ((SOOrder)order).CuryID; newdoc.ProjectID = ((SOOrder)order).ProjectID ?? PM.ProjectDefaultAttribute.NonProject(this); newdoc.Hold = ordertype.InvoiceHoldEntry; if (((SOOrderType)order).MarkInvoicePrinted == true) { newdoc.Printed = true; } if (((SOOrderType)order).MarkInvoiceEmailed == true) { newdoc.Emailed = true; } if (soOrder.PMInstanceID != null || string.IsNullOrEmpty(soOrder.PaymentMethodID) == false) { newdoc.PMInstanceID = soOrder.PMInstanceID; newdoc.PaymentMethodID = soOrder.PaymentMethodID; newdoc.CashAccountID = soOrder.CashAccountID; } newdoc = this.Document.Update(newdoc); if (soOrder.PMInstanceID != null || string.IsNullOrEmpty(soOrder.PaymentMethodID) == false) { SODocument.Current.PMInstanceID = soOrder.PMInstanceID; SODocument.Current.PaymentMethodID = soOrder.PaymentMethodID; SODocument.Current.CashAccountID = soOrder.CashAccountID; if(SODocument.Current.CashAccountID == null) SODocument.Cache.SetDefaultExt<SOInvoice.cashAccountID>(SODocument.Current); SODocument.Current.ExtRefNbr = soOrder.ExtRefNbr; //clear error in case invoice currency different from default cash account for customer SODocument.Cache.RaiseExceptionHandling<SOInvoice.cashAccountID>(SODocument.Current, null, null); } foreach (CurrencyInfo info in this.currencyinfo.Select()) { if (((SOOrder)order).InvoiceDate != null) { PXCache<CurrencyInfo>.RestoreCopy(info, (CurrencyInfo)order); info.CuryInfoID = newdoc.CuryInfoID; } } AddressAttribute.CopyRecord<ARInvoice.billAddressID>(this.Document.Cache, newdoc, (SOAddress)order, true); ContactAttribute.CopyRecord<ARInvoice.billContactID>(this.Document.Cache, newdoc, (SOContact)order, true); } } else { newdoc = (ARInvoice)Document.Cache.CreateCopy(Document.Current); if (Transactions.SelectSingle() == null) { newdoc.CustomerID = ((SOOrder)order).CustomerID; newdoc.ProjectID = ((SOOrder)order).ProjectID; newdoc.CustomerLocationID = ((SOOrder)order).CustomerLocationID; newdoc.SalesPersonID = ((SOOrder)order).SalesPersonID; newdoc.TaxZoneID = ((SOOrder)order).TaxZoneID; newdoc.AvalaraCustomerUsageType = ((SOOrder)order).AvalaraCustomerUsageType; newdoc.DocDesc = ((SOOrder)order).OrderDesc; newdoc.InvoiceNbr = ((SOOrder)order).CustomerOrderNbr; newdoc.TermsID = ((SOOrder)order).TermsID; foreach (CurrencyInfo info in this.currencyinfo.Select()) { PXCache<CurrencyInfo>.RestoreCopy(info, (CurrencyInfo)order); info.CuryInfoID = newdoc.CuryInfoID; newdoc.CuryID = info.CuryID; } } newdoc = this.Document.Update(newdoc); AddressAttribute.CopyRecord<ARInvoice.billAddressID>(this.Document.Cache, newdoc, (SOAddress)order, true); ContactAttribute.CopyRecord<ARInvoice.billContactID>(this.Document.Cache, newdoc, (SOContact)order, true); } PXSelectBase<SOInvoiceDiscountDetail> selectInvoiceDiscounts = new PXSelect<SOInvoiceDiscountDetail, Where<SOInvoiceDiscountDetail.tranType, Equal<Current<SOInvoice.docType>>, And<SOInvoiceDiscountDetail.refNbr, Equal<Current<SOInvoice.refNbr>>, And<SOInvoiceDiscountDetail.orderType, Equal<Required<SOInvoiceDiscountDetail.orderType>>, And<SOInvoiceDiscountDetail.orderNbr, Equal<Required<SOInvoiceDiscountDetail.orderNbr>>>>>>>(this); foreach (SOInvoiceDiscountDetail detail in selectInvoiceDiscounts.Select(((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { DiscountDetails.Delete(detail); } TaxAttribute.SetTaxCalc<ARTran.taxCategoryID>(this.Transactions.Cache, null, TaxCalc.ManualCalc); if (details != null) { foreach (SOShipLine shipline in details) { this.Caches[typeof(SOShipLine)].Insert(shipline); } } DateTime? origInvoiceDate = null; foreach (PXResult<SOShipLine, SOLine, SOOrderTypeOperation, ARTran> res in PXSelectJoin<SOShipLine, InnerJoin<SOLine, On<SOLine.orderType, Equal<SOShipLine.origOrderType>, And<SOLine.orderNbr, Equal<SOShipLine.origOrderNbr>, And<SOLine.lineNbr, Equal<SOShipLine.origLineNbr>>>>, InnerJoin<SOOrderTypeOperation, On<SOOrderTypeOperation.orderType, Equal<SOLine.orderType>, And<SOOrderTypeOperation.operation, Equal<SOLine.operation>>>, LeftJoin<ARTran, On<ARTran.sOShipmentNbr, Equal<SOShipLine.shipmentNbr>, And<ARTran.sOShipmentType, Equal<SOShipLine.shipmentType>, And<ARTran.sOShipmentLineNbr, Equal<SOShipLine.lineNbr>, And<ARTran.sOOrderType, Equal<SOShipLine.origOrderType>, And<ARTran.sOOrderNbr, Equal<SOShipLine.origOrderNbr>, And<ARTran.sOOrderLineNbr, Equal<SOShipLine.origLineNbr>>>>>>>>>>, Where<SOShipLine.shipmentNbr, Equal<Required<SOShipLine.shipmentNbr>>, And<SOShipLine.origOrderType, Equal<Required<SOShipLine.origOrderType>>, And<SOShipLine.origOrderNbr, Equal<Required<SOShipLine.origOrderNbr>>, And<ARTran.refNbr, IsNull>>>>>.Select(this, ((SOOrderShipment)order).ShipmentNbr, ((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { SOLine orderline = (SOLine)res; SOShipLine shipline = (SOShipLine)res; if (Math.Abs((decimal)shipline.BaseShippedQty) < 0.0000005m) { continue; } if (origInvoiceDate == null && orderline.InvoiceDate != null) origInvoiceDate = orderline.InvoiceDate; ARTran newtran = new ARTran(); newtran.BranchID = orderline.BranchID; newtran.AccountID = orderline.SalesAcctID; newtran.SubID = orderline.SalesSubID; newtran.SOOrderType = shipline.OrigOrderType; newtran.SOOrderNbr = shipline.OrigOrderNbr; newtran.SOOrderLineNbr = shipline.OrigLineNbr; newtran.SOShipmentNbr = shipline.ShipmentNbr; newtran.SOShipmentType = shipline.ShipmentType; newtran.SOShipmentLineNbr = shipline.LineNbr; newtran.LineType = orderline.LineType; newtran.InventoryID = shipline.InventoryID; newtran.SiteID = orderline.SiteID; newtran.UOM = shipline.UOM; newtran.Qty = shipline.ShippedQty; newtran.BaseQty = shipline.BaseShippedQty; newtran.Commissionable = orderline.Commissionable; newtran.GroupDiscountRate = orderline.GroupDiscountRate; decimal shippedQtyInBaseUnits = INUnitAttribute.ConvertToBase(Transactions.Cache, newtran.InventoryID, shipline.UOM, shipline.ShippedQty.Value, INPrecision.QUANTITY); decimal shippedQtyInOrderUnits = INUnitAttribute.ConvertFromBase(Transactions.Cache, newtran.InventoryID, orderline.UOM, shippedQtyInBaseUnits, INPrecision.QUANTITY); if (shippedQtyInOrderUnits != orderline.OrderQty || shipline.UOM != orderline.UOM) { decimal curyUnitPriceInBaseUnits = INUnitAttribute.ConvertFromBase(Transactions.Cache, newtran.InventoryID, orderline.UOM, orderline.CuryUnitPrice.Value, INPrecision.UNITCOST); decimal curyUnitPriceInShippedUnits = INUnitAttribute.ConvertToBase(Transactions.Cache, newtran.InventoryID, shipline.UOM, curyUnitPriceInBaseUnits, INPrecision.UNITCOST); if (arsetup.Current.LineDiscountTarget == LineDiscountTargetType.SalesPrice) { decimal? salesPriceAfterDiscount = curyUnitPriceInShippedUnits * (1m - orderline.DiscPct / 100m); newtran.CuryTranAmt = shipline.ShippedQty * PXCurrencyAttribute.Round(Transactions.Cache, newtran, salesPriceAfterDiscount ?? 0, CMPrecision.TRANCURY); } else { decimal? curyTranAmt = shipline.ShippedQty * curyUnitPriceInShippedUnits * (1m - orderline.DiscPct / 100m); newtran.CuryTranAmt = PXCurrencyAttribute.Round(Transactions.Cache, newtran, curyTranAmt ?? 0, CMPrecision.TRANCURY); } newtran.CuryUnitPrice = curyUnitPriceInShippedUnits; newtran.CuryDiscAmt = (shipline.ShippedQty * curyUnitPriceInShippedUnits) - newtran.CuryTranAmt; } else { newtran.CuryUnitPrice = orderline.CuryUnitPrice; newtran.CuryTranAmt = orderline.CuryLineAmt; newtran.CuryDiscAmt = orderline.CuryDiscAmt; } if (newdoc.DocType == ((SOOrderType)order).ARDocType && ((SOOrderType)order).DefaultOperation != ((SOOrderTypeOperation)res).Operation) { //keep BaseQty positive for PXFormula newtran.Qty = -newtran.Qty; newtran.CuryDiscAmt = -newtran.CuryDiscAmt; newtran.CuryTranAmt = -newtran.CuryTranAmt; } newtran.ProjectID = orderline.ProjectID; newtran.TaskID = orderline.TaskID; newtran.TranDesc = orderline.TranDesc; newtran.SalesPersonID = orderline.SalesPersonID; newtran.TaxCategoryID = orderline.TaxCategoryID; newtran.DiscPct = orderline.DiscPct; newtran.ManualDisc = orderline.ManualDisc == true || orderline.IsFree == true; newtran.FreezeManualDisc = true; newtran.DiscountID = orderline.DiscountID; newtran.DiscountSequenceID = orderline.DiscountSequenceID; newtran.DetDiscIDC1 = orderline.DetDiscIDC1; newtran.DetDiscIDC2 = orderline.DetDiscIDC2; newtran.DetDiscSeqIDC1 = orderline.DetDiscSeqIDC1; newtran.DetDiscSeqIDC2 = orderline.DetDiscSeqIDC2; newtran.DetDiscApp = orderline.DetDiscApp; newtran.DocDiscIDC1 = orderline.DocDiscIDC1; newtran.DocDiscIDC2 = orderline.DocDiscIDC2; newtran.DocDiscSeqIDC1 = orderline.DocDiscSeqIDC1; newtran.DocDiscSeqIDC2 = orderline.DocDiscSeqIDC2; foreach (ARTran existing in Transactions.Cache.Inserted) { if (Transactions.Cache.ObjectsEqual<ARTran.sOShipmentNbr, ARTran.sOShipmentType, ARTran.sOShipmentLineNbr, ARTran.sOOrderType, ARTran.sOOrderNbr, ARTran.sOOrderLineNbr>(newtran, existing)) { Transactions.Cache.RestoreCopy(newtran, existing); break; } } if (newtran.LineNbr == null) { newtran = this.Transactions.Insert(newtran); if (((SOOrderType)order).CopyLineNotesToInvoice == true) { if (((SOOrderType)order).CopyLineNotesToInvoiceOnlyNS == false || orderline.LineType == SOLineType.NonInventory) { PXNoteAttribute.SetNote(Caches[typeof(ARTran)], newtran, PXNoteAttribute.GetNote(Caches[typeof(SOLine)], orderline)); } } if (((SOOrderType)order).CopyLineFilesToInvoice == true) { if (((SOOrderType)order).CopyLineFilesToInvoiceOnlyNS == false || orderline.LineType == SOLineType.NonInventory) { PXNoteAttribute.SetFileNotes(Caches[typeof(ARTran)], newtran, PXNoteAttribute.GetFileNotes(Caches[typeof(SOLine)], orderline)); } } } else { newtran = this.Transactions.Update(newtran); TaxAttribute.Calculate<ARTran.taxCategoryID>(Transactions.Cache, new PXRowUpdatedEventArgs(newtran, null, true)); } } PXSelectBase<ARTran> cmd = new PXSelect<ARTran, Where<ARTran.tranType, Equal<Current<ARInvoice.docType>>, And<ARTran.refNbr, Equal<Current<ARInvoice.refNbr>>, And<ARTran.sOOrderType, Equal<Current<SOMiscLine2.orderType>>, And<ARTran.sOOrderNbr, Equal<Current<SOMiscLine2.orderNbr>>, And<ARTran.sOOrderLineNbr, Equal<Current<SOMiscLine2.lineNbr>>>>>>>>(this); foreach (SOMiscLine2 orderline in PXSelect<SOMiscLine2, Where<SOMiscLine2.orderType, Equal<Required<SOMiscLine2.orderType>>, And<SOMiscLine2.orderNbr, Equal<Required<SOMiscLine2.orderNbr>>, And<Where<SOMiscLine2.curyUnbilledAmt, Greater<decimal0>, Or<SOMiscLine2.curyLineAmt, LessEqual<decimal0>>>>>>>.Select(this, ((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { if (cmd.View.SelectSingleBound(new object[] { Document.Current, orderline }) == null) { ARTran newtran = new ARTran(); newtran.BranchID = orderline.BranchID; newtran.AccountID = orderline.SalesAcctID; newtran.SubID = orderline.SalesSubID; newtran.SOOrderType = orderline.OrderType; newtran.SOOrderNbr = orderline.OrderNbr; newtran.SOOrderLineNbr = orderline.LineNbr; newtran.SOShipmentNbr = ((SOOrderShipment)order).ShipmentNbr; newtran.SOShipmentType = ((SOOrderShipment)order).ShipmentType; newtran.SOShipmentLineNbr = null; newtran.LineType = SOLineType.MiscCharge; newtran.InventoryID = orderline.InventoryID; newtran.TaskID = orderline.TaskID; newtran.SalesPersonID = orderline.SalesPersonID; newtran.Commissionable = orderline.Commissionable; newtran.UOM = orderline.UOM; newtran.Qty = orderline.UnbilledQty; newtran.BaseQty = orderline.BaseUnbilledQty; newtran.CuryUnitPrice = orderline.CuryUnitPrice; newtran.CuryDiscAmt = orderline.CuryDiscAmt; newtran.CuryTranAmt = orderline.CuryUnbilledAmt; newtran.TranDesc = orderline.TranDesc; newtran.TaxCategoryID = orderline.TaxCategoryID; newtran.DiscPct = orderline.DiscPct; newtran.ManualDisc = orderline.ManualDisc == true || orderline.IsFree == true; newtran.FreezeManualDisc = true; newtran.DiscountID = orderline.DiscountID; newtran.DiscountSequenceID = orderline.DiscountSequenceID; newtran.DetDiscIDC1 = orderline.DetDiscIDC1; newtran.DetDiscIDC2 = orderline.DetDiscIDC2; newtran.DetDiscSeqIDC1 = orderline.DetDiscSeqIDC1; newtran.DetDiscSeqIDC2 = orderline.DetDiscSeqIDC2; newtran.DetDiscApp = orderline.DetDiscApp; newtran.DocDiscIDC1 = orderline.DocDiscIDC1; newtran.DocDiscIDC2 = orderline.DocDiscIDC2; newtran.DocDiscSeqIDC1 = orderline.DocDiscSeqIDC1; newtran.DocDiscSeqIDC2 = orderline.DocDiscSeqIDC2; newtran = this.Transactions.Insert(newtran); if (((SOOrderType)order).CopyLineNotesToInvoice == true) { PXNoteAttribute.SetNote(Caches[typeof(ARTran)], newtran, PXNoteAttribute.GetNote(Caches[typeof(SOMiscLine2)], orderline)); } if (((SOOrderType)order).CopyLineFilesToInvoice == true) { PXNoteAttribute.SetFileNotes(Caches[typeof(ARTran)], newtran, PXNoteAttribute.GetFileNotes(Caches[typeof(SOMiscLine2)], orderline)); } } } SODocument.Current = (SOInvoice)SODocument.Select() ?? (SOInvoice)SODocument.Cache.Insert(); SODocument.Current.BillAddressID = soOrder.BillAddressID; SODocument.Current.BillContactID = soOrder.BillContactID; SODocument.Current.ShipAddressID = soOrder.ShipAddressID; SODocument.Current.ShipContactID = soOrder.ShipContactID; SODocument.Current.IsCCCaptured = soOrder.IsCCCaptured; SODocument.Current.IsCCCaptureFailed = soOrder.IsCCCaptureFailed; SODocument.Current.PaymentProjectID = PM.ProjectDefaultAttribute.NonProject(this); if (soOrder.IsCCCaptured == true) { SODocument.Current.CuryCCCapturedAmt = soOrder.CuryCCCapturedAmt; SODocument.Current.CCCapturedAmt = soOrder.CCCapturedAmt; } SODocument.Current.RefTranExtNbr = soOrder.RefTranExtNbr; SOOrderShipment shipment = PXCache<SOOrderShipment>.CreateCopy((SOOrderShipment)order); shipment.InvoiceType = SODocument.Current.DocType; shipment.InvoiceNbr = SODocument.Current.RefNbr; shipmentlist.Cache.Update(shipment); FillFreightDetails((SOOrder)order, shipment); /*In case Discounts were not recalculated add prorated Doc discounts */ if (ordertype.RecalculateDiscOnPartialShipment != true) { //add prorated document discount details from invoice: PXSelectBase<SOOrderDiscountDetail> selectOrderDocGroupDiscounts = new PXSelect<SOOrderDiscountDetail, Where<SOOrderDiscountDetail.orderType, Equal<Required<SOOrderDiscountDetail.orderType>>, And<SOOrderDiscountDetail.orderNbr, Equal<Required<SOOrderDiscountDetail.orderNbr>>>>>(this); decimal? rate = 1m; if (soOrder.LineTotal > 0m) rate = shipment.LineTotal / soOrder.LineTotal; foreach (SOOrderDiscountDetail docGroupDisc in selectOrderDocGroupDiscounts.Select(((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { SOInvoiceDiscountDetail dd = new SOInvoiceDiscountDetail(); dd.Type = docGroupDisc.Type; dd.DiscountID = docGroupDisc.DiscountID; dd.DiscountSequenceID = docGroupDisc.DiscountSequenceID; dd.OrderType = docGroupDisc.OrderType; dd.OrderNbr = docGroupDisc.OrderNbr; dd.TranType = newdoc.DocType; dd.RefNbr = newdoc.RefNbr; dd.DiscountPct = docGroupDisc.DiscountPct; dd.FreeItemID = docGroupDisc.FreeItemID; dd.FreeItemQty = docGroupDisc.FreeItemQty; if (docGroupDisc.Type == DiscountType.Group) { SOOrderEntry soOrderQ = (SOOrderEntry)PXGraph.CreateInstance(typeof(SOOrderEntry)); soOrderQ.Document.Current = order; Dictionary<DiscountSequenceKey, DiscountEngine<SOLine>.DiscountDetailToLineCorrelation<SOOrderDiscountDetail>> grLinesOrderCorrelation = DiscountEngine<SOLine>.CollectGroupDiscountToLineCorrelation(soOrderQ.Transactions.Cache, soOrderQ.Transactions, soOrderQ.DiscountDetails, soOrder.CustomerLocationID, (DateTime)soOrder.OrderDate, false); foreach (KeyValuePair<DiscountSequenceKey, DiscountEngine<SOLine>.DiscountDetailToLineCorrelation<SOOrderDiscountDetail>> dsGroup in grLinesOrderCorrelation) { if (dsGroup.Key.DiscountID == docGroupDisc.DiscountID && dsGroup.Key.DiscountSequenceID == docGroupDisc.DiscountSequenceID) { decimal invoicedGroupAmt = 0m; foreach (SOLine soLine in dsGroup.Value.listOfApplicableLines) { foreach (ARTran tran in Transactions.Select()) { if (soLine.LineNbr == tran.SOOrderLineNbr) invoicedGroupAmt += (tran.CuryLineAmt ?? 0m); } } rate = (invoicedGroupAmt / (decimal)dsGroup.Value.discountDetailLine.CuryDiscountableAmt); } } } SOInvoiceDiscountDetail located = DiscountDetails.Locate(dd); if (located != null) { located.DiscountAmt += docGroupDisc.DiscountAmt * rate; located.CuryDiscountAmt += docGroupDisc.CuryDiscountAmt * rate; located.DiscountableAmt += docGroupDisc.DiscountableAmt * rate; located.CuryDiscountableAmt += docGroupDisc.CuryDiscountableAmt * rate; located.DiscountableQty += docGroupDisc.DiscountableQty * rate; DiscountDetails.Update(located); } else { dd.DiscountAmt = docGroupDisc.DiscountAmt * rate; dd.CuryDiscountAmt = docGroupDisc.CuryDiscountAmt * rate; dd.DiscountableAmt = docGroupDisc.DiscountableAmt * rate; dd.CuryDiscountableAmt = docGroupDisc.CuryDiscountableAmt * rate; dd.DiscountableQty = docGroupDisc.DiscountableQty * rate; DiscountDetails.Insert(dd); } } } else { //Recalculate all discounts foreach (ARTran tran in Transactions.Select()) { RecalculateDiscounts(this.Transactions.Cache, tran); } } RecalculateTotalDiscount(); foreach (PXResult<SOTaxTran, Tax> res in PXSelectJoin<SOTaxTran, InnerJoin<Tax, On<SOTaxTran.taxID, Equal<Tax.taxID>>>, Where<SOTaxTran.orderType, Equal<Required<SOTaxTran.orderType>>, And<SOTaxTran.orderNbr, Equal<Required<SOTaxTran.orderNbr>>>>>.Select(this, ((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { SOTaxTran tax = (SOTaxTran)res; ARTaxTran newtax = new ARTaxTran(); newtax.Module = BatchModule.AR; Taxes.Cache.SetDefaultExt<ARTaxTran.origTranType>(newtax); Taxes.Cache.SetDefaultExt<ARTaxTran.origRefNbr>(newtax); Taxes.Cache.SetDefaultExt<ARTaxTran.lineRefNbr>(newtax); newtax.TranType = Document.Current.DocType; newtax.RefNbr = Document.Current.RefNbr; newtax.TaxID = tax.TaxID; newtax.TaxRate = 0m; this.Taxes.Delete(newtax); newtax = this.Taxes.Insert(newtax); } decimal? CuryApplAmt = 0m; bool Calculated = false; foreach (SOAdjust soadj in PXSelectJoin<SOAdjust, InnerJoin<AR.ARPayment, On<AR.ARPayment.docType, Equal<SOAdjust.adjgDocType>, And<AR.ARPayment.refNbr, Equal<SOAdjust.adjgRefNbr>>>>, Where<SOAdjust.adjdOrderType, Equal<Required<SOAdjust.adjdOrderType>>, And<SOAdjust.adjdOrderNbr, Equal<Required<SOAdjust.adjdOrderNbr>>, And<AR.ARPayment.openDoc, Equal<True>>>>>.Select(this, ((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { ARAdjust prev_adj = null; bool found = false; foreach (ARAdjust adj in Adjustments.Select()) { if (Calculated) { CuryApplAmt -= adj.CuryAdjdAmt; } if (string.Equals(adj.AdjgDocType, soadj.AdjgDocType) && string.Equals(adj.AdjgRefNbr, soadj.AdjgRefNbr)) { if (soadj.CuryAdjdAmt > 0m) { ARAdjust copy = PXCache<ARAdjust>.CreateCopy(adj); copy.CuryAdjdAmt += (soadj.CuryAdjdAmt > adj.CuryDocBal) ? adj.CuryDocBal : soadj.CuryAdjdAmt; copy.AdjdOrderType = soadj.AdjdOrderType; copy.AdjdOrderNbr = soadj.AdjdOrderNbr; prev_adj = Adjustments.Update(copy); } found = true; if (Calculated) { CuryApplAmt += adj.CuryAdjdAmt; break; } } CuryApplAmt += adj.CuryAdjdAmt; } //if soadjust is not available in adjustments mark as billed if (!found) { /* soadj.Billed = true; soadjustments.Cache.SetStatus(soadj, PXEntryStatus.Updated); */ } Calculated = true; if (!IsExternalTax) { if (CuryApplAmt > Document.Current.CuryDocBal - Document.Current.CuryOrigDiscAmt && prev_adj != null) { prev_adj = PXCache<ARAdjust>.CreateCopy(prev_adj); if (prev_adj.CuryAdjdAmt > (CuryApplAmt - (Document.Current.CuryDocBal - Document.Current.CuryOrigDiscAmt))) { prev_adj.CuryAdjdAmt -= (CuryApplAmt - (Document.Current.CuryDocBal - Document.Current.CuryOrigDiscAmt)); CuryApplAmt = Document.Current.CuryDocBal - Document.Current.CuryOrigDiscAmt; } else { CuryApplAmt -= prev_adj.CuryAdjdAmt; prev_adj.CuryAdjdAmt = 0m; } prev_adj = Adjustments.Update(prev_adj); } } } newdoc = (ARInvoice)Document.Cache.CreateCopy(Document.Current); newdoc.OrigDocDate = origInvoiceDate; SOInvoice socopy = (SOInvoice)SODocument.Cache.CreateCopy(SODocument.Current); PXFormulaAttribute.CalcAggregate<ARAdjust.curyAdjdAmt>(Adjustments.Cache, SODocument.Current, false); Document.Cache.RaiseFieldUpdated<SOInvoice.curyPaymentTotal>(SODocument.Current, null); PXDBCurrencyAttribute.CalcBaseValues<SOInvoice.curyPaymentTotal>(SODocument.Cache, SODocument.Current); SODocument.Cache.RaiseRowUpdated(SODocument.Current, socopy); List<string> ordersdistinct = new List<string>(); foreach (SOOrderShipment shipments in PXSelect<SOOrderShipment, Where<SOOrderShipment.invoiceType, Equal<Current<ARInvoice.docType>>, And<SOOrderShipment.invoiceNbr, Equal<Current<ARInvoice.refNbr>>>>>.Select(this)) { string key = string.Format("{0}|{1}", shipments.OrderType, shipments.OrderNbr); if (!ordersdistinct.Contains(key)) { ordersdistinct.Add(key); } if (ordersdistinct.Count > 1) { newdoc.InvoiceNbr = null; newdoc.SalesPersonID = null; newdoc.DocDesc = null; break; } #region Update FreeItemQty for DiscountDetails based on shipments PXSelectBase<SOShipmentDiscountDetail> selectShipmentDiscounts = new PXSelect<SOShipmentDiscountDetail, Where<SOShipmentDiscountDetail.orderType, Equal<Required<SOShipmentDiscountDetail.orderType>>, And<SOShipmentDiscountDetail.orderNbr, Equal<Required<SOShipmentDiscountDetail.orderNbr>>, And<SOShipmentDiscountDetail.shipmentNbr, Equal<Required<SOShipmentDiscountDetail.shipmentNbr>>>>>>(this); foreach (SOShipmentDiscountDetail sdd in selectShipmentDiscounts.Select(shipments.OrderType, shipments.OrderNbr, shipments.ShipmentNbr)) { SOInvoiceDiscountDetail idd = PXSelect<SOInvoiceDiscountDetail, Where<SOInvoiceDiscountDetail.tranType, Equal<Current<ARInvoice.docType>>, And<SOInvoiceDiscountDetail.refNbr, Equal<Current<ARInvoice.refNbr>>, And<SOInvoiceDiscountDetail.orderType, Equal<Required<SOInvoiceDiscountDetail.orderType>>, And<SOInvoiceDiscountDetail.orderNbr, Equal<Required<SOInvoiceDiscountDetail.orderNbr>>, And<SOInvoiceDiscountDetail.discountID, Equal<Required<SOInvoiceDiscountDetail.discountID>>, And<SOInvoiceDiscountDetail.discountSequenceID, Equal<Required<SOInvoiceDiscountDetail.discountSequenceID>>>>>>>>>.Select(this, shipments.OrderType, shipments.OrderNbr, sdd.DiscountID, sdd.DiscountSequenceID); if (idd != null) { if (idd.FreeItemID == null) { idd.FreeItemID = sdd.FreeItemID; idd.FreeItemQty = sdd.FreeItemQty; } else idd.FreeItemQty = sdd.FreeItemQty; DiscountDetails.Update(idd); } else { idd = new SOInvoiceDiscountDetail(); idd.Type = DiscountType.Line; idd.TranType = newdoc.DocType; idd.RefNbr = newdoc.RefNbr; idd.OrderType = sdd.OrderType; idd.OrderNbr = sdd.OrderNbr; idd.DiscountID = sdd.DiscountID; idd.DiscountSequenceID = sdd.DiscountSequenceID; idd.FreeItemID = sdd.FreeItemID; idd.FreeItemQty = sdd.FreeItemQty; DiscountDetails.Insert(idd); } } #endregion } this.Document.Update(newdoc); if (list != null) { if (Transactions.Search<ARTran.sOOrderType, ARTran.sOOrderNbr, ARTran.sOShipmentType, ARTran.sOShipmentNbr>(shipment.OrderType, shipment.OrderNbr, shipment.ShipmentType, shipment.ShipmentNbr).Count > 0) { try { this.Document.Current.ApplyPaymentWhenTaxAvailable = true; this.Save.Press(); } finally { this.Document.Current.ApplyPaymentWhenTaxAvailable = false; } if (list.Find(this.Document.Current) == null) { list.Add(this.Document.Current, this.SODocument.Current); } } else { this.Clear(); } } this.RowUpdated.RemoveHandler(typeof(ARInvoice), ApprovedBalanceCollector); }
private void DefaultDiscountAccountAndSubAccount(ARTran tran) { ARTran firstTranWithOrderType = PXSelect<ARTran, Where<ARTran.tranType, Equal<Current<SOInvoice.docType>>, And<ARTran.refNbr, Equal<Current<SOInvoice.refNbr>>, And<ARTran.sOOrderType, IsNotNull>>>>.Select(this); if (firstTranWithOrderType != null) { SOOrderType type = PXSelect<SOOrderType, Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.Select(this, firstTranWithOrderType.SOOrderType); if (type != null) { Location customerloc = location.Current; Location companyloc = (Location)PXSelectJoin<Location, InnerJoin<BAccountR, On<Location.bAccountID, Equal<BAccountR.bAccountID>, And<Location.locationID, Equal<BAccountR.defLocationID>>>, InnerJoin<Branch, On<Branch.bAccountID, Equal<BAccountR.bAccountID>>>>,Where<Branch.branchID, Equal<Current<ARRegister.branchID>>>>.Select(this); switch (type.DiscAcctDefault) { case SODiscAcctSubDefault.OrderType: tran.AccountID = (int?)GetValue<SOOrderType.discountAcctID>(type); break; case SODiscAcctSubDefault.MaskLocation: tran.AccountID = (int?)GetValue<Location.cDiscountAcctID>(customerloc); break; } if (tran.AccountID == null) { tran.AccountID = type.DiscountAcctID; } Discount.Cache.RaiseFieldUpdated<ARTran.accountID>(tran, null); if (tran.AccountID != null) { object ordertype_SubID = GetValue<SOOrderType.discountSubID>(type); object customer_Location = GetValue<Location.cDiscountSubID>(customerloc); object company_Location = GetValue<Location.cMPDiscountSubID>(companyloc); object value = SODiscSubAccountMaskAttribute.MakeSub<SOOrderType.discSubMask>(this, type.DiscSubMask, new object[] { ordertype_SubID, customer_Location, company_Location }, new Type[] { typeof(SOOrderType.discountSubID), typeof(Location.cDiscountSubID), typeof(Location.cMPDiscountSubID) }); Discount.Cache.RaiseFieldUpdating<ARTran.subID>(tran, ref value); tran.SubID = (int?)value; } } } }
private void AddFreightTransaction(SOFreightDetail fd) { ARTran freight = new ARTran(); freight.TranDesc = PXMessages.LocalizeFormatNoPrefix(Messages.FreightDescr, fd.ShipVia); freight.SOShipmentNbr = fd.ShipmentNbr; freight.SOShipmentType = fd.ShipmentType ?? SOShipmentType.Issue; freight.SOOrderType = fd.OrderType; freight.SOOrderNbr = fd.OrderNbr; freight.LineType = SOLineType.Freight; freight.CuryTranAmt = fd.CuryTotalFreightAmt; freight.TaxCategoryID = fd.TaxCategoryID; freight.AccountID = fd.AccountID; freight.SubID = fd.SubID; freight.ProjectID = fd.ProjectID; if (fd.TaskID != null) freight.TaskID = fd.TaskID; freight = (ARTran)Freight.Cache.Insert(freight); if (freight.TaskID == null && !PM.ProjectDefaultAttribute.IsNonProject(this, freight.ProjectID)) { Account ac = PXSelect<Account, Where<Account.accountID, Equal<Required<Account.accountID>>>>.Select(this, freight.AccountID); throw new PXException(Messages.TaskWasNotAssigned, ac.AccountCD); } }