/// <summary>The RowUpdated event handler for the <see cref="Discount" /> mapped cache extension.</summary> /// <param name="e">Parameters of the event.</param> protected virtual void _(Events.RowUpdated <Discount> e) { if (!DiscountEngineGraph.IsInternalDiscountEngineCall && e.Row != null) { if (!Discounts.Cache.ObjectsEqual <Discount.skipDiscount>(e.Row, e.OldRow)) { DiscountEngineGraph.UpdateDocumentDiscount(Details.Cache, Details, Discounts, Documents.Current.BranchID, Documents.Current.LocationID ?? 0, Documents.Current.DocumentDate, e.Row.Type != DiscountType.Document, DiscountEngine.DefaultARDiscountCalculationParameters); RefreshTotalsAndFreeItems(Discounts.Cache); (Discounts.Cache as PXModelExtension <Discount>)?.UpdateExtensionMapping(e.Row); } if (!Discounts.Cache.ObjectsEqual <Discount.discountID>(e.Row, e.OldRow) || !Discounts.Cache.ObjectsEqual <Discount.discountSequenceID>(e.Row, e.OldRow)) { e.Row.IsManual = true; DiscountEngineGraph.InsertManualDocGroupDiscount(Details.Cache, Details, Discounts, e.Row, e.Row.DiscountID, Discounts.Cache.ObjectsEqual <Discount.discountID>(e.Row, e.OldRow) ? e.Row.DiscountSequenceID : null, Documents.Current.BranchID, Documents.Current.LocationID ?? 0, Documents.Current.DocumentDate, DiscountEngine.DefaultARDiscountCalculationParameters); RefreshTotalsAndFreeItems(Discounts.Cache); (Discounts.Cache as PXModelExtension <Discount>)?.UpdateExtensionMapping(e.Row); } if (DiscountEngineGraph.SetExternalManualDocDiscount(Details.Cache, Details, Discounts, e.Row, e.OldRow, DiscountEngine.DefaultARDiscountCalculationParameters)) { RefreshTotalsAndFreeItems(Discounts.Cache); (Discounts.Cache as PXModelExtension <Discount>)?.UpdateExtensionMapping(e.Row); } } }
/// <summary>The RowUpdated event handler for the <see cref="Detail" /> mapped cache extension. When the value of any field of <see cref="Detail"/> is changed, the discount is recalulated for the current line.</summary> /// <param name="e">Parameters of the event.</param> protected virtual void _(Events.RowUpdated <Detail> e) { if (!Details.Cache.ObjectsEqual <Detail.branchID>(e.Row, e.OldRow) && !Details.Cache.ObjectsEqual <Detail.inventoryID>(e.Row, e.OldRow) || !Details.Cache.ObjectsEqual <Detail.siteID>(e.Row, e.OldRow) || !Details.Cache.ObjectsEqual <Detail.quantity>(e.Row, e.OldRow) || !Details.Cache.ObjectsEqual <Detail.curyUnitPrice>(e.Row, e.OldRow) || !Details.Cache.ObjectsEqual <Detail.curyExtPrice>(e.Row, e.OldRow) || !Details.Cache.ObjectsEqual <Detail.curyDiscAmt>(e.Row, e.OldRow) || !Details.Cache.ObjectsEqual <Detail.discPct>(e.Row, e.OldRow) || !Details.Cache.ObjectsEqual <Detail.manualDisc>(e.Row, e.OldRow) || !Details.Cache.ObjectsEqual <Detail.discountID>(e.Row, e.OldRow)) { if (e.Row.ManualDisc != true) { if (e.OldRow.ManualDisc == true) //Manual Discount Unckecked { if (e.Row.IsFree == true) { ResetQtyOnFreeItem(e.Cache.Graph, e.Row); } } if (e.Row.IsFree == true) { DiscountEngineGraph.ClearDiscount(e.Cache, e.Row); } } RecalculateDiscounts(e.Cache, e.Row, e.Row); } }
/// <summary>The RowDeleted event handler for the <see cref="Discount" /> mapped cache extension.</summary> /// <param name="e">Parameters of the event.</param> protected virtual void _(Events.RowDeleted <Discount> e) { if (!DiscountEngineGraph.IsInternalDiscountEngineCall && e.Row != null) { DiscountEngineGraph.UpdateDocumentDiscount(Details.Cache, Details, Discounts, Documents.Current.BranchID, Documents.Current.LocationID ?? 0, Documents.Current.DocumentDate, (e.Row.Type != null && e.Row.Type != DiscountType.Document && e.Row.Type != DiscountType.ExternalDocument), DiscountEngine.DefaultARDiscountCalculationParameters); (Discounts.Cache as PXModelExtension <Discount>)?.UpdateExtensionMapping(e.Row); } RefreshTotalsAndFreeItems(Discounts.Cache); }
/// <summary>Recalculates discounts for the specified detail line.</summary> /// <param name="sender">A cache object.</param> /// <param name="line">The line for which the discounts should be recalculated.</param> protected virtual void RecalculateDiscounts(PXCache sender, Detail line, object source) { if (line.InventoryID != null && line.Quantity != null && line.CuryLineAmount != null && line.IsFree != true) { Document doc = Documents.Current; DiscountEngineGraph.SetDiscounts(Details.Cache, Details, line, Discounts, doc.BranchID ?? 0, doc.LocationID ?? 0, doc.CuryID, doc.DocumentDate ?? Base.Accessinfo.BusinessDate, null, DiscountEngine.DefaultARDiscountCalculationParameters); RecalculateTotalDiscount(); RefreshFreeItemLines(sender); RecalculateDetailsDiscount(Details.Cache); } }
/// <summary>The FieldUpdated event handler for the <see cref="Detail.DiscountID" /> field. When the DiscountID field value is changed, the discount is recalculated for the current line.</summary> /// <param name="e">Parameters of the event.</param> protected virtual void _(Events.FieldUpdated <Detail, Detail.discountID> e) { var doc = Documents.Current; if (e.ExternalCall && e.Row != null) { DiscountEngineGraph.UpdateManualLineDiscount(Details.Cache, Details, e.Row, Discounts, doc.BranchID, doc.LocationID ?? 0, doc.DocumentDate ?? (new PXGraph()).Accessinfo.BusinessDate, DiscountEngine.DefaultARDiscountCalculationParameters); Details.Cache.RaiseFieldUpdated <Detail.curyDiscAmt>(e.Row, 0); } }
/// <summary>The RowUpdated event handler for the <see cref="Document" /> mapped cache extension.</summary> /// <param name="e">Parameters of the event.</param> protected virtual void _(Events.RowUpdated <Document> e) { if (e.Row == null) { return; } if (e.ExternalCall && (!Documents.Cache.ObjectsEqual <Document.documentDate>(e.OldRow, e.Row))) { DiscountEngineGraph.AutoRecalculatePricesAndDiscounts(Details.Cache, Details, null, Discounts, e.Row.LocationID ?? 0, e.Row.DocumentDate ?? (new PXGraph()).Accessinfo.BusinessDate, DiscountEngine.DefaultARDiscountCalculationParameters); } if (e.ExternalCall && Documents.Cache.GetStatus(e.Row) != PXEntryStatus.Deleted && !Documents.Cache.ObjectsEqual <Document.curyDiscTot>(e.OldRow, e.Row)) { var current = Documents.Current; DiscountEngineGraph.CalculateDocumentDiscountRate(Details.Cache, Details, null, null, Discounts, current.CuryLineTotal ?? 0m, current.CuryDiscTot ?? 0m); } if (e.Row.CustomerID != null && e.Row.CuryDiscTot != null && e.Row.CuryDiscTot > 0 && e.Row.CuryLineTotal != null && e.Row.CuryMiscTot != null && (e.Row.CuryLineTotal > 0 || e.Row.CuryMiscTot > 0)) { decimal discountLimit = DiscountEngineGraph.GetDiscountLimit(Documents.Cache, e.Row.CustomerID); if (((e.Row.CuryLineTotal + e.Row.CuryMiscTot) / 100 * discountLimit) < e.Row.CuryDiscTot) { PXUIFieldAttribute.SetWarning <Document.curyDiscTot>(Documents.Cache, e.Row, string.Format(Messages.DocDiscountExceedLimit, discountLimit)); } } if (!Documents.Cache.ObjectsEqual <Document.locationID>(e.OldRow, e.Row) || !Documents.Cache.ObjectsEqual <Document.documentDate>(e.OldRow, e.Row)) { RecalcDiscountsParamFilter recalcFilter = new RecalcDiscountsParamFilter { OverrideManualDiscounts = false, OverrideManualPrices = false, RecalcDiscounts = true, RecalcUnitPrices = true, RecalcTarget = RecalcDiscountsParamFilter.AllLines }; DiscountEngineGraph.RecalculatePricesAndDiscounts(Details.Cache, Details, null, Discounts, e.Row.LocationID ?? 0, e.Row.DocumentDate ?? (new PXGraph()).Accessinfo.BusinessDate, recalcFilter, DiscountEngine.DefaultARDiscountCalculationParameters); RecalculateTotalDiscount(); } }
/// <summary>The RowInserted event handler for the <see cref="Discount" /> mapped cache extension.</summary> /// <param name="e">Parameters of the event.</param> protected virtual void _(Events.RowInserted <Discount> e) { if (!DiscountEngineGraph.IsInternalDiscountEngineCall && e.Row != null) { if (e.Row.DiscountID != null) { DiscountEngineGraph.InsertManualDocGroupDiscount(Details.Cache, Details, Discounts, e.Row, e.Row.DiscountID, null, Documents.Current.BranchID, Documents.Current.LocationID ?? 0, Documents.Current.DocumentDate, DiscountEngine.DefaultARDiscountCalculationParameters); RefreshTotalsAndFreeItems(Discounts.Cache); (Discounts.Cache as PXModelExtension <Discount>)?.UpdateExtensionMapping(e.Row); } if (DiscountEngineGraph.SetExternalManualDocDiscount(Details.Cache, Details, Discounts, e.Row, null, DiscountEngine.DefaultARDiscountCalculationParameters)) { RefreshTotalsAndFreeItems(Discounts.Cache); (Discounts.Cache as PXModelExtension <Discount>)?.UpdateExtensionMapping(e.Row); } } }
/// <summary>The RowDeleted event handler for the <see cref="Detail" /> mapped cache extension. When a <see cref="Detail"/> line is deleted, the discount is recalulated.</summary> /// <param name="e">Parameters of the event.</param> protected virtual void _(Events.RowDeleted <Detail> e) { bool autoFreeItem = e.Row.ManualDisc != true && e.Row.IsFree == true; if (autoFreeItem) { return; } var documentCache = Documents.Cache; if (documentCache.Current != null && documentCache.GetStatus(documentCache.Current) != PXEntryStatus.Deleted) { var doc = Documents.Current; DiscountEngineGraph.RecalculateGroupAndDocumentDiscounts(Details.Cache, Details, null, Discounts, doc.BranchID, doc.LocationID ?? 0, doc.DocumentDate ?? (new PXGraph()).Accessinfo.BusinessDate, DiscountEngine.DefaultARDiscountCalculationParameters); RecalculateTotalDiscount(); RefreshFreeItemLines(Details.Cache); } }
/// <summary>Adds the discount to the specified document.</summary> public virtual void AddDiscount(PXCache sender, Document row) { if (GetDetailMapping().FreezeManualDisc == typeof(Detail.freezeManualDisc)) { return; } Detail discount = Details.Select(); if (discount == null) { discount = (Detail)Details.Cache.CreateInstance(); discount.FreezeManualDisc = true; discount = (Detail)Details.Cache.Insert(discount); } Detail old_row = (Detail)Details.Cache.CreateCopy(discount); discount.CuryLineAmount = row.CuryDiscTot; discount.TaxCategoryID = null; DefaultDiscountAccountAndSubAccount(discount); if (Details.Cache.GetStatus(discount) == PXEntryStatus.Notchanged) { Details.Cache.SetStatus(discount, PXEntryStatus.Updated); } discount.ManualDisc = true; //escape SOManualDiscMode.RowUpdated Details.Cache.RaiseRowUpdated(discount, old_row); decimal auotDocDisc = DiscountEngineGraph.GetTotalGroupAndDocumentDiscount(Discounts); if (auotDocDisc == discount.CuryLineAmount) { discount.ManualDisc = false; } }
private void RecalculateTotalDiscount() { if (Documents.Current != null) { Document old_row = (Document)Documents.Cache.CreateCopy(Documents.Current); Documents.Cache.SetValueExt <Document.curyDiscTot>(Documents.Current, DiscountEngineGraph.GetTotalGroupAndDocumentDiscount(Discounts)); Documents.Cache.RaiseRowUpdated(Documents.Current, old_row); } }
/// <summary>The RowSelected event handler for the <see cref="Discount" /> mapped cache extension.</summary> /// <param name="e">Parameters of the event.</param> protected virtual void _(Events.RowSelected <Discount> e) { if (e.Row != null) { PXUIFieldAttribute.SetEnabled <Discount.skipDiscount>(Discounts.Cache, e.Row, e.Row.DiscountID != null && e.Row.Type != DiscountType.ExternalDocument); PXUIFieldAttribute.SetEnabled <Discount.discountID>(Discounts.Cache, e.Row, e.Row.Type != DiscountType.ExternalDocument); PXUIFieldAttribute.SetEnabled <Discount.discountSequenceID>(Discounts.Cache, e.Row, e.Row.Type != DiscountType.ExternalDocument); PXUIFieldAttribute.SetEnabled <Discount.curyDiscountAmt>(Discounts.Cache, e.Row, e.Row.Type == DiscountType.ExternalDocument || e.Row.Type == DiscountType.Document); PXUIFieldAttribute.SetEnabled <Discount.discountPct>(Discounts.Cache, e.Row, e.Row.Type == DiscountType.ExternalDocument || e.Row.Type == DiscountType.Document); } PXDefaultAttribute.SetPersistingCheck <Discount.discountID>(Discounts.Cache, e.Row, PXPersistingCheck.Nothing); if (Documents.Current != null) { Documents.Cache.SetValueExt <Document.curyDocDisc>(Documents.Current, DiscountEngineGraph.GetTotalGroupAndDocumentDiscount(Discounts, true)); } }