Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        protected virtual void ARDiscount_Type_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            ARDiscount row = e.Row as ARDiscount;

            if (row != null)
            {
                DiscountSequence sequence = PXSelect <DiscountSequence, Where <DiscountSequence.discountID, Equal <Required <DiscountSequence.discountID> > > > .SelectWindowed(this, 0, 1, row.DiscountID);

                if (sequence != null)
                {
                    row.Type = (string)e.OldValue;
                    sender.RaiseExceptionHandling <ARDiscount.type>(row, e.OldValue, new PXSetPropertyException(Messages.DiscountTypeCannotChanged));
                }
                if (row.Type == DiscountType.Flat)
                {
                    row.IsAutoNumber = true;
                    if (string.IsNullOrEmpty(row.LastNumber))
                    {
                        row.LastNumber = "000000000";
                    }
                }
            }
        }
Exemplo n.º 3
0
        public virtual void UpdateDiscount(string discountID, string discountSequenceID, DateTime?filterDate)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (DiscountDetail detail in PXSelect <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                       And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        if (detail.StartDate != null && detail.StartDate.Value <= filterDate.Value)
                        {
                            PXDatabase.Update <DiscountDetail>(
                                new PXDataFieldAssign("LastAmount", PXDbType.DirectExpression, "Amount"),
                                new PXDataFieldAssign("LastAmountTo", PXDbType.DirectExpression, "AmountTo"),
                                new PXDataFieldAssign("LastQuantity", PXDbType.DirectExpression, "Quantity"),
                                new PXDataFieldAssign("LastQuantityTo", PXDbType.DirectExpression, "QuantityTo"),
                                new PXDataFieldAssign("LastDiscount", PXDbType.DirectExpression, "Discount"),
                                new PXDataFieldAssign("LastFreeItemQty", PXDbType.DirectExpression, "FreeItemQty"),
                                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, "StartDate"),
                                new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null),
                                new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m),
                                new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null),
                                new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, null),
                                new PXDataFieldAssign("StartDate", PXDbType.DateTime, null),
                                new PXDataFieldRestrict("DiscountDetailsID", PXDbType.Int, detail.DiscountDetailsID)
                                );
                        }
                    }
                    foreach (DiscountDetail detail in PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                               And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        DiscountDetail amonextval = PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                             And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> >, And <DiscountDetail.amount, Greater <Required <DiscountDetail.amount> > > > >,
                                                                      OrderBy <Asc <DiscountDetail.amount> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Amount);

                        DiscountDetail qtynextval = PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                             And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> >, And <DiscountDetail.quantity, Greater <Required <DiscountDetail.quantity> > > > >,
                                                                      OrderBy <Asc <DiscountDetail.quantity> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Quantity);

                        PXDatabase.Update <DiscountDetail>(
                            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)
                            );
                    }

                    foreach (DiscountDetail detail in PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                               And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        DiscountDetail amonextval = PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                             And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> >, And <DiscountDetail.lastAmount, Greater <Required <DiscountDetail.lastAmount> > > > >,
                                                                      OrderBy <Asc <DiscountDetail.lastAmount> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Amount);

                        DiscountDetail qtynextval = PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                             And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> >, And <DiscountDetail.lastQuantity, Greater <Required <DiscountDetail.lastQuantity> > > > >,
                                                                      OrderBy <Asc <DiscountDetail.lastQuantity> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Quantity);

                        PXDatabase.Update <DiscountDetail>(
                            new PXDataFieldAssign("LastAmountTo", PXDbType.Decimal, (amonextval == null ? null : amonextval.LastAmount)),
                            new PXDataFieldAssign("LastQuantityTo", PXDbType.Decimal, (qtynextval == null ? null : qtynextval.LastQuantity)),
                            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.StartDate.Value <= filterDate.Value && 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("EndDate", PXDbType.DirectExpression, "StartDate"),
                            //new PXDataFieldAssign("StartDate", PXDbType.DateTime, null),
                            new PXDataFieldRestrict("DiscountID", PXDbType.VarChar, discountID),
                            new PXDataFieldRestrict("DiscountSequenceID", PXDbType.VarChar, discountSequenceID)
                            );
                    }

                    ts.Complete();
                }
            }
        }
Exemplo n.º 4
0
        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>();
            PXSelect <DiscountSequence,
                      Where <DiscountSequence.startDate, LessEqual <Current <ItemFilter.pendingDiscountDate> >,
                             And <DiscountSequence.isPromotion, Equal <boolFalse> > > > s1 = new PXSelect <DiscountSequence, Where <DiscountSequence.startDate, LessEqual <Current <ItemFilter.pendingDiscountDate> >, And <DiscountSequence.isPromotion, Equal <boolFalse> > > >(this);

            foreach (DiscountSequence sequence in s1.Select())
            {
                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.EndDate;

                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> > > > > .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.EndDate;

                        yield return(Items.Insert(item));
                    }
                }
            }

            Items.Cache.IsDirty = false;
        }