protected virtual void ARDiscount_Type_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { ARDiscount discount = e.Row as ARDiscount; if (discount == null) { return; } DiscountSequence sequence = PXSelect < DiscountSequence, Where < DiscountSequence.discountID, Equal <Required <DiscountSequence.discountID> > > > .SelectWindowed(this, 0, 1, discount.DiscountID); if (sequence != null) { discount.Type = (string)e.OldValue; sender.RaiseExceptionHandling <ARDiscount.type>(discount, e.OldValue, new PXSetPropertyException(Messages.DiscountTypeCannotChanged)); } else if ( discount.Type == DiscountType.Document && !GetAllowedDiscountTargetsForDocumentDiscountType().Item1.Contains(discount.ApplicableTo)) { sender.SetValueExt <ARDiscount.applicableTo>(discount, DiscountTarget.Customer); } }
protected virtual void ARDiscount_RowDeleting(PXCache sender, PXRowDeletingEventArgs e) { ARDiscount row = e.Row as ARDiscount; if (row != null) { DiscountSequence firstSeq = PXSelect <DiscountSequence, Where <DiscountSequence.discountID, Equal <Required <DiscountSequence.discountID> > > > .SelectWindowed(this, 0, 1, row.DiscountID); if (firstSeq != null) { e.Cancel = true; throw new PXSetPropertyException(Messages.SequenceExists); } } }
public virtual void UpdateDiscount(string discountID, string discountSequenceID, DateTime?filterDate) { using (PXConnectionScope cs = new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { foreach (DiscountSequenceDetail detail in PXSelect <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >, And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.isLast, Equal <False> > > > > .Select(this, discountID, discountSequenceID)) { if (detail.PendingDate != null && detail.PendingDate.Value <= filterDate.Value) { if (!PXDatabase.Update <DiscountSequenceDetail>( new PXDataFieldAssign("IsActive", PXDbType.Bit, detail.IsActive), new PXDataFieldAssign("Amount", PXDbType.Decimal, detail.Amount), new PXDataFieldAssign("AmountTo", PXDbType.Decimal, detail.AmountTo), new PXDataFieldAssign("Quantity", PXDbType.Decimal, detail.Quantity), new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, detail.QuantityTo), new PXDataFieldAssign("Discount", PXDbType.Decimal, detail.Discount), new PXDataFieldAssign("FreeItemQty", PXDbType.Decimal, detail.FreeItemQty), new PXDataFieldAssign("LastDate", PXDbType.DateTime, detail.PendingDate), new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null), new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null), new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null), new PXDataFieldRestrict("DiscountID", PXDbType.NVarChar, detail.DiscountID), new PXDataFieldRestrict("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID), new PXDataFieldRestrict("LineNbr", PXDbType.Int, detail.LineNbr), new PXDataFieldRestrict("IsLast", PXDbType.Bit, 1) )) { PXDatabase.Insert <DiscountSequenceDetail>( new PXDataFieldAssign("DiscountID", PXDbType.NVarChar, detail.DiscountID), new PXDataFieldAssign("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID), new PXDataFieldAssign("LineNbr", PXDbType.Int, detail.LineNbr), new PXDataFieldAssign("IsActive", PXDbType.Bit, detail.IsActive), new PXDataFieldAssign("IsLast", PXDbType.Bit, 1), new PXDataFieldAssign("Amount", PXDbType.Decimal, detail.Amount), new PXDataFieldAssign("AmountTo", PXDbType.Decimal, detail.AmountTo), new PXDataFieldAssign("Quantity", PXDbType.Decimal, detail.Quantity), new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, detail.QuantityTo), new PXDataFieldAssign("Discount", PXDbType.Decimal, detail.Discount), new PXDataFieldAssign("FreeItemQty", PXDbType.Decimal, detail.FreeItemQty), new PXDataFieldAssign("LastDate", PXDbType.DateTime, detail.PendingDate), new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null), new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null), new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null), new PXDataFieldAssign("CreatedByID", PXDbType.UniqueIdentifier, 16, detail.CreatedByID), new PXDataFieldAssign("CreatedByScreenID", PXDbType.Char, 8, detail.CreatedByScreenID), new PXDataFieldAssign("CreatedDateTime", PXDbType.DateTime, 8, detail.CreatedDateTime), new PXDataFieldAssign("LastModifiedByID", PXDbType.UniqueIdentifier, 16, detail.LastModifiedByID), new PXDataFieldAssign("LastModifiedByScreenID", PXDbType.Char, 8, detail.LastModifiedByScreenID), new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, 8, detail.LastModifiedDateTime) ); } PXDatabase.Update <DiscountSequenceDetail>( new PXDataFieldAssign("Amount", PXDbType.DirectExpression, "PendingAmount"), new PXDataFieldAssign("Quantity", PXDbType.DirectExpression, "PendingQuantity"), new PXDataFieldAssign("Discount", PXDbType.DirectExpression, "PendingDiscount"), new PXDataFieldAssign("FreeItemQty", PXDbType.DirectExpression, "PendingFreeItemQty"), new PXDataFieldAssign("LastDate", PXDbType.DirectExpression, "PendingDate"), new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null), new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null), new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null), new PXDataFieldRestrict("DiscountID", PXDbType.NVarChar, detail.DiscountID), new PXDataFieldRestrict("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID), new PXDataFieldRestrict("LineNbr", PXDbType.Int, detail.LineNbr), new PXDataFieldRestrict("IsLast", PXDbType.Bit, 0) ); } } foreach (DiscountSequenceDetail detail in PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >, And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID)) { DiscountSequenceDetail amonextval = PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >, And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.amount, Greater <Required <DiscountSequenceDetail.amount> >, And <DiscountSequenceDetail.isLast, Equal <Required <DiscountSequenceDetail.isLast> >, And <DiscountSequenceDetail.isActive, Equal <True> > > > > >, OrderBy <Asc <DiscountSequenceDetail.amount> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Amount, detail.IsLast); DiscountSequenceDetail qtynextval = PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >, And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.quantity, Greater <Required <DiscountSequenceDetail.quantity> >, And <DiscountSequenceDetail.isLast, Equal <Required <DiscountSequenceDetail.isLast> >, And <DiscountSequenceDetail.isActive, Equal <True> > > > > >, OrderBy <Asc <DiscountSequenceDetail.quantity> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Quantity, detail.IsLast); PXDatabase.Update <DiscountSequenceDetail>( new PXDataFieldAssign("AmountTo", PXDbType.Decimal, (amonextval == null ? null : amonextval.Amount)), new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, (qtynextval == null ? null : qtynextval.Quantity)), new PXDataFieldRestrict("DiscountDetailsID", PXDbType.Int, detail.DiscountDetailsID) ); } DiscountSequence sequence = PXSelect <DiscountSequence, Where <DiscountSequence.discountID, Equal <Required <DiscountSequence.discountID> >, And <DiscountSequence.discountSequenceID, Equal <Required <DiscountSequence.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID); if (sequence != null && sequence.StartDate != null && sequence.PendingFreeItemID != null) { PXDatabase.Update <DiscountSequence>( new PXDataFieldAssign("LastFreeItemID", PXDbType.DirectExpression, "FreeItemID"), new PXDataFieldAssign("FreeItemID", PXDbType.DirectExpression, "PendingFreeItemID"), new PXDataFieldAssign("PendingFreeItemID", PXDbType.Int, null), new PXDataFieldAssign("UpdateDate", PXDbType.DateTime, filterDate.Value), //new PXDataFieldAssign("StartDate", PXDbType.DateTime, null), new PXDataFieldRestrict("DiscountID", PXDbType.VarChar, discountID), new PXDataFieldRestrict("DiscountSequenceID", PXDbType.VarChar, discountSequenceID) ); } else if (sequence != null && sequence.StartDate != null) { PXDatabase.Update <DiscountSequence>( new PXDataFieldAssign("UpdateDate", PXDbType.DateTime, filterDate.Value), new PXDataFieldRestrict("DiscountID", PXDbType.VarChar, discountID), new PXDataFieldRestrict("DiscountSequenceID", PXDbType.VarChar, discountSequenceID) ); } ts.Complete(); } } }
public virtual IEnumerable items() { ItemFilter filter = Filter.Current; if (filter == null) { yield break; } bool found = false; foreach (SelectedItem item in Items.Cache.Inserted) { found = true; yield return(item); } if (found) { yield break; } List <string> added = new List <string>(); foreach (DiscountSequence sequence in PXSelect < DiscountSequence, Where < DiscountSequence.startDate, LessEqual <Current <ItemFilter.pendingDiscountDate> >, And <DiscountSequence.isPromotion, Equal <False>, And <DiscountSequence.isActive, Equal <True> > > > > .Select(this)) { string key = string.Format("{0}.{1}", sequence.DiscountID, sequence.DiscountSequenceID); added.Add(key); SelectedItem item = new SelectedItem(); item.DiscountID = sequence.DiscountID; item.DiscountSequenceID = sequence.DiscountSequenceID; item.Description = sequence.Description; item.DiscountedFor = sequence.DiscountedFor; item.BreakBy = sequence.BreakBy; item.IsPromotion = sequence.IsPromotion; item.IsActive = sequence.IsActive; item.StartDate = sequence.StartDate; item.EndDate = sequence.UpdateDate; yield return(Items.Insert(item)); } foreach (DiscountDetail detail in PXSelectGroupBy < DiscountDetail, Where < DiscountDetail.startDate, LessEqual <Current <ItemFilter.pendingDiscountDate> > >, Aggregate < GroupBy <DiscountDetail.discountID, GroupBy <DiscountDetail.discountSequenceID> > > > .Select(this)) { string key = string.Format("{0}.{1}", detail.DiscountID, detail.DiscountSequenceID); if (!added.Contains(key)) { DiscountSequence sequence = PXSelect < DiscountSequence, Where < DiscountSequence.discountID, Equal <Required <DiscountSequence.discountID> >, And <DiscountSequence.discountSequenceID, Equal <Required <DiscountSequence.discountSequenceID> >, And <DiscountSequence.isActive, Equal <True> > > > > .Select(this, detail.DiscountID, detail.DiscountSequenceID); if (sequence != null && sequence.IsPromotion == false) { SelectedItem item = new SelectedItem(); item.DiscountID = sequence.DiscountID; item.DiscountSequenceID = sequence.DiscountSequenceID; item.Description = sequence.Description; item.DiscountedFor = sequence.DiscountedFor; item.BreakBy = sequence.BreakBy; item.IsPromotion = sequence.IsPromotion; item.IsActive = sequence.IsActive; item.StartDate = sequence.StartDate; item.EndDate = sequence.UpdateDate; yield return(Items.Insert(item)); } } } Items.Cache.IsDirty = false; }