示例#1
0
 public List <int?> GetOrganizationIDsInDetails()
 {
     return(Adjustments
            .Select()
            .SelectMany(row => GetAdjustBranchIDs((Adjust)row))
            .Select(PXAccess.GetParentOrganizationID)
            .Distinct()
            .ToList());
 }
示例#2
0
        protected override void _(Events.RowUpdated <Invoice> e)
        {
            base._(e);

            if (ShouldUpdateAdjustmentsOnDocumentUpdated(e))
            {
                foreach (Adjust2 adjust in AppliedAdjustments.Select())
                {
                    if (!e.Cache.ObjectsEqual <Invoice.branchID>(e.Row, e.OldRow))
                    {
                        AppliedAdjustments.Cache.SetDefaultExt <Adjust2.adjdBranchID>(adjust);
                    }

                    if (!e.Cache.ObjectsEqual <Invoice.headerTranPeriodID>(e.Row, e.OldRow))
                    {
                        FinPeriodIDAttribute.DefaultPeriods <Adjust2.adjgFinPeriodID>(AppliedAdjustments.Cache, adjust);
                        FinPeriodIDAttribute.DefaultPeriods <Adjust2.adjdFinPeriodID>(AppliedAdjustments.Cache, adjust);
                    }

                    (AppliedAdjustments.Cache as PXModelExtension <Adjust2>)?.UpdateExtensionMapping(adjust);

                    AppliedAdjustments.Cache.MarkUpdated(adjust);
                }
            }
        }
        /// <summary>Adds the discount to the specified document.</summary>
        public virtual void AddDiscount(PXCache sender, Document row)
        {
            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 = DiscountEngine.GetTotalGroupAndDocumentDiscount(Discounts);

            if (auotDocDisc == discount.CuryLineAmount)
            {
                discount.ManualDisc = false;
            }
        }
示例#4
0
 public IEnumerable <IExternalTransaction> GetExtTrans()
 {
     if (ExternalTransaction == null)
     {
         yield break;
     }
     foreach (IExternalTransaction tran in ExternalTransaction.Select().RowCast <ExternalTransactionDetail>())
     {
         yield return(tran);
     }
 }
示例#5
0
        public IEnumerable <ICCPaymentTransaction> GetProcTrans()
        {
            if (PaymentTransaction == null)
            {
                yield break;
            }
            IEnumerable <ICCPaymentTransaction> trans = PaymentTransaction.Select().RowCast <PaymentTransactionDetail>().Cast <ICCPaymentTransaction>();

            foreach (ICCPaymentTransaction tran in trans)
            {
                yield return(tran);
            }
        }
        protected virtual void _(Events.RowUpdated <Document> e)
        {
            Document doc = e.Row;

            decimal?total = 0m;

            foreach (SalesPerson sp in Details.Select())
            {
                total += sp.Commision;
            }

            e.Cache.SetValueExt <Document.description>(e.Row, "Total commision calculated = " + total.ToString());
        }
        protected override void _(Events.RowUpdated <Document> e)
        {
            base._(e);

            if (ShouldUpdateOverheadsOnDocumentUpdated(e))
            {
                foreach (DocumentLine overhead in Overheads.Select())
                {
                    Overheads.Cache.SetDefaultExt <DocumentLine.finPeriodID>(overhead);

                    Overheads.Cache.MarkUpdated(overhead);
                }
            }
        }
        /// <summary>Returns the sales price for the specified detail row.</summary>
        /// <param name="row">A detail line.</param>
        /// <param name="sender">A cache object.</param>
        protected virtual decimal GetPrice(PXCache sender, Detail row)
        {
            string           customerPriceClass = ARPriceClass.EmptyPriceClass;
            PriceClassSource source             = PriceClassSource.Select();

            if (!string.IsNullOrEmpty(source?.PriceClassID))
            {
                customerPriceClass = source.PriceClassID;
            }

            Document     doc  = Documents.Current;
            CurrencyInfo info = SelectCurrencyInfo(doc);

            return
                (ARSalesPriceMaint.CalculateSalesPrice(sender, customerPriceClass, doc.BAccountID,
                                                       row.InventoryID, info.GetCM(),
                                                       row.UOM, row.Quantity, doc.DocumentDate ?? sender.Graph.Accessinfo.BusinessDate.Value, row.CuryUnitPrice) ?? 0m);
        }
示例#9
0

        
示例#10
0
 /// <summary>Returns the current currency source.</summary>
 /// <returns>The default implementation returns the <see cref="CurySource" /> data view.</returns>
 /// <example>
 ///   <code title="Example" description="The following code shows sample implementation of the method in the implementation class." lang="CS">
 /// public PXSelect&lt;CRSetup&gt; crCurrency;
 /// protected PXSelectExtension&lt;CurySource&gt; SourceSetup =&gt; new PXSelectExtension&lt;CurySource&gt;(crCurrency);
 ///
 /// protected virtual CurySourceMapping GetSourceSetupMapping()
 /// {
 ///       return new CurySourceMapping(typeof(CRSetup)) {CuryID = typeof(CRSetup.defaultCuryID), CuryRateTypeID = typeof(CRSetup.defaultRateTypeID)};
 ///  }
 ///
 /// protected override CurySource CurrentSourceSelect()
 /// {
 ///        CurySource settings = base.CurrentSourceSelect();
 ///        if (settings == null)
 ///              return SourceSetup.Select();
 ///        if (settings.CuryID == null || settings.CuryRateTypeID == null)
 ///        {
 ///              CurySource setup = SourceSetup.Select();
 ///              settings = (CurySource)CurySource.Cache.CreateCopy(settings);
 ///              settings.CuryID = settings.CuryID ?? setup.CuryID;
 ///              settings.CuryRateTypeID = settings.CuryRateTypeID ?? setup.CuryRateTypeID;
 ///        }
 ///        return settings;
 /// }</code>
 /// </example>
 protected virtual CurySource CurrentSourceSelect()
 {
     return(CurySource.Select());
 }
示例#11
0
        public virtual IEnumerable checkForDuplicates(PXAdapter adapter)
        {
            DuplicateDocument duplicateDocument = DuplicateDocuments.Current ?? DuplicateDocuments.Select();

            if (duplicateDocument == null)
            {
                return(adapter.Get());
            }

            var prevStatus  = duplicateDocument.DuplicateStatus;
            var prevIsDirty = Base.Caches[DuplicateDocuments.Cache.GetMain(duplicateDocument).GetType()].IsDirty;

            if (CheckIsActive())
            {
                duplicateDocument.DuplicateFound = true;
                duplicateDocument = DuplicateDocuments.Update(duplicateDocument);

                Duplicates.View.Clear();
                var result = Duplicates.Select().ToList();

                bool anyFound = result != null && result.Count > 0;
                duplicateDocument.DuplicateFound  = anyFound;
                duplicateDocument.DuplicateStatus = anyFound
                                        ? DuplicateStatusAttribute.PossibleDuplicated
                                        : DuplicateStatusAttribute.Validated;

                duplicateDocument = DuplicateDocuments.Update(duplicateDocument);

                if (duplicateDocument.ContactType?.IsIn(ContactTypesAttribute.Lead, ContactTypesAttribute.Person) == true &&
                    Setup.Current?.ContactEmailUnique == true &&
                    !String.IsNullOrWhiteSpace(duplicateDocument.Email))
                {
                    try
                    {
                        var parsedEmail = EmailParser.ParseAddresses(duplicateDocument.Email).FirstOrDefault();

                        if (result
                            .Select(item => item.GetItem <DuplicateContact>())
                            .Where(item => !String.IsNullOrWhiteSpace(item.EMail) && item.ContactType.IsIn(ContactTypesAttribute.Lead, ContactTypesAttribute.Person))
                            .Any(item => item.EMail.Contains(parsedEmail.Address)))
                        {
                            DuplicateDocuments.Cache.RaiseExceptionHandling <DuplicateDocument.email>(
                                duplicateDocument,
                                duplicateDocument.Email,
                                new PXSetPropertyException(Messages.ContactEmailNotUnique, PXErrorLevel.Warning));
                        }
                    }
                    catch (Exception) { }
                }
            }

            if (duplicateDocument.DuplicateStatus != prevStatus)
            {
                Base.Actions.PressSave();
            }
            else
            {
                Base.Caches[DuplicateDocuments.Cache.GetMain(duplicateDocument).GetType()].IsDirty = prevIsDirty;
            }

            if (duplicateDocument.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated || duplicateDocument.DuplicateFound == true)
            {
                DuplicateDocuments.Cache.RaiseExceptionHandling <DuplicateDocument.duplicateStatus>(duplicateDocument,
                                                                                                    duplicateDocument.DuplicateStatus,
                                                                                                    new PXSetPropertyException(WarningMessage, PXErrorLevel.Warning));
            }
            else
            {
                DuplicateDocuments.Cache.RaiseExceptionHandling <DuplicateDocument.duplicateStatus>(duplicateDocument,
                                                                                                    duplicateDocument.DuplicateStatus,
                                                                                                    null);
            }

            return(adapter.Get());
        }
        private void RefreshFreeItemLines(PXCache sender)
        {
            if (sender.Graph.IsImport && !sender.Graph.IsMobile)
            {
                return;
            }

            Dictionary <int, decimal> groupedByInventory = new Dictionary <int, decimal>();

            //PXSelectBase<Discount> select = new PXSelect<Discount,
            //	Where<Discount.orderType, Equal<Current<CROpportunity.orderType>>,
            //	And<Discount.orderNbr, Equal<Current<CROpportunity.orderNbr>>,
            //	//And<Discount.skipDiscount, NotEqual<boolTrue>>
            //	>>>(_Graph);

            foreach (Discount item in Discounts.Select())
            {
                if (item.FreeItemID != null && item.SkipDiscount != true)
                {
                    if (groupedByInventory.ContainsKey(item.FreeItemID.Value))
                    {
                        groupedByInventory[item.FreeItemID.Value] += item.FreeItemQty ?? 0;
                    }
                    else
                    {
                        groupedByInventory.Add(item.FreeItemID.Value, item.FreeItemQty ?? 0);
                    }
                }
            }

            bool freeItemChanged = false;

            #region Delete Unvalid FreeItems
            foreach (Detail line in Details.Cache.Cached)
            {
                var status = Details.Cache.GetStatus(line);
                if (status == PXEntryStatus.Deleted || status == PXEntryStatus.InsertedDeleted)
                {
                    continue;
                }

                if (line.IsFree != true)
                {
                    continue;
                }

                if (line.ManualDisc == false && line.InventoryID != null)
                {
                    if (groupedByInventory.ContainsKey(line.InventoryID.Value))
                    {
                        if (groupedByInventory[line.InventoryID.Value] == 0)
                        {
                            Details.Cache.Delete(line);
                            freeItemChanged = true;
                        }
                    }
                    else
                    {
                        Details.Cache.Delete(line);
                        freeItemChanged = true;
                    }
                }
            }

            #endregion

            foreach (KeyValuePair <int, decimal> kv in groupedByInventory)
            {
                object source;
                var    freeLine = GetFreeLineByItemID(kv.Key, out source);

                if (freeLine == null)
                {
                    if (kv.Value > 0)
                    {
                        Detail line = new Detail
                        {
                            InventoryID = kv.Key,
                            IsFree      = true,
                            Quantity    = kv.Value
                        };
                        //line.ShipComplete = SOShipComplete.CancelRemainder;
                        //Need to ckeck
                        Details.Cache.Insert(line);


                        freeItemChanged = true;
                    }
                }
                else
                {
                    Detail copy = (Detail)Details.Cache.CreateCopy(freeLine);
                    copy.Quantity = kv.Value;
                    Details.Cache.Update(copy);
                    freeItemChanged = true;
                }
            }

            if (freeItemChanged)
            {
                Details.View.RequestRefresh();
            }
        }