Esempio n. 1
0
        public virtual void VerifyExchangeRateExistsForProject(int?newProjectID)
        {
            if (!PXAccess.FeatureInstalled <FeaturesSet.projectMultiCurrency>())
            {
                return;
            }

            if (!IsCommitmentsEnabled())
            {
                return;
            }

            PMProject project;

            if (ProjectDefaultAttribute.IsProject(Base, newProjectID, out project) && Base.Document.Current != null)
            {
                var curySettings = PMCommitmentAttribute.GetCurrencySettings(Base, newProjectID, Base.Document.Current.CuryID);

                if (!curySettings.UseBaseCurrency && curySettings.ConverionRequired)
                {
                    CM.Extensions.IPXCurrencyService currencyService = ServiceLocator.Current.GetInstance <Func <PXGraph, CM.Extensions.IPXCurrencyService> >()(Base);
                    var rate = currencyService.GetRate(curySettings.FromCuryID, curySettings.ToCuryID, curySettings.RateTypeID, Base.Document.Current.OrderDate.GetValueOrDefault(DateTime.Now));

                    if (rate == null)
                    {
                        var ex = new PXSetPropertyException(Messages.ConversionRateNotDefinedForCommitment, curySettings.FromCuryID, curySettings.ToCuryID, curySettings.RateTypeID, Base.Document.Current.OrderDate.GetValueOrDefault(DateTime.Now));
                        ex.ErrorValue = project.ContractCD;

                        throw ex;
                    }
                }
            }
        }
        public static void Sync(PXCache sender, object data)
        {
            PMCommitmentAttribute commitmentAttribute = null;

            foreach (PXEventSubscriberAttribute attr in sender.GetAttributesReadonly("commitmentID"))
            {
                if (attr is PMCommitmentAttribute)
                {
                    commitmentAttribute = (PMCommitmentAttribute)attr;
                    break;
                }
            }

            if (commitmentAttribute != null)
            {
                commitmentAttribute.SyncCommitment(sender, data, true);
            }
        }
        public static void AddToInvoiced(PXCache sender, PMCommitment container)
        {
            PMCommitmentAttribute commitmentAttribute = null;

            foreach (PXEventSubscriberAttribute attr in sender.GetAttributesReadonly("commitmentID"))
            {
                if (attr is PMCommitmentAttribute)
                {
                    commitmentAttribute = (PMCommitmentAttribute)attr;
                    break;
                }
            }

            if (commitmentAttribute != null)
            {
                commitmentAttribute.AddInvoiced(sender, container);
            }
            else
            {
                AddInvoicedBase(sender, container);
            }
        }
        public virtual void ProcessSOCommitments(PMProject project)
        {
            foreach (PXResult <SOLine, SOOrder> res in solines.Select(project.ContractID))
            {
                SOLine  soline = (SOLine)res;
                SOOrder order  = (SOOrder)res;
                PXParentAttribute.SetParent(solines.Cache, soline, typeof(SOOrder), order);

                PMCommitmentAttribute.Sync(solines.Cache, soline);
            }

            foreach (ARTran tran in artran.Select(project.ContractID))
            {
                SOLine soline = new SOLine();
                soline.OrderType = tran.SOOrderType;
                soline.OrderNbr  = tran.SOOrderNbr;
                soline.LineNbr   = tran.SOOrderLineNbr;

                soline = solines.Locate(soline);

                if (soline != null && soline.CommitmentID != null)
                {
                    decimal sign = (tran.DrCr == DrCr.Credit) ? Decimal.One : Decimal.MinusOne;

                    PMCommitment container = new PMCommitment();
                    container.CommitmentID   = soline.CommitmentID;
                    container.UOM            = tran.UOM;
                    container.InventoryID    = tran.InventoryID;
                    container.CostCodeID     = tran.CostCodeID.GetValueOrDefault(CostCodeAttribute.GetDefaultCostCode());
                    container.InvoicedAmount = sign * tran.TranAmt.GetValueOrDefault();
                    container.InvoicedQty    = sign * tran.Qty.GetValueOrDefault();

                    PMCommitmentAttribute.AddToInvoiced(solines.Cache, container);
                }
            }
        }
        public virtual void ProcessPOCommitments(PMProject project)
        {
            foreach (PXResult <POLine, POOrder> res in polines.Select(project.ContractID))
            {
                POLine  poline = (POLine)res;
                POOrder order  = (POOrder)res;
                PXParentAttribute.SetParent(polines.Cache, poline, typeof(POOrder), order);

                PMCommitmentAttribute.Sync(polines.Cache, poline);
            }

            foreach (APTran tran in aptran.Select(project.ContractID))
            {
                POLine poline = new POLine();
                poline.OrderType = tran.POOrderType;
                poline.OrderNbr  = tran.PONbr;
                poline.LineNbr   = tran.POLineNbr;

                poline = polines.Locate(poline);

                if (poline != null && poline.CommitmentID != null)
                {
                    decimal sign = (tran.DrCr == DrCr.Debit) ? Decimal.One : Decimal.MinusOne;

                    PMCommitment container = new PMCommitment();
                    container.CommitmentID   = poline.CommitmentID;
                    container.UOM            = tran.UOM;
                    container.InventoryID    = tran.InventoryID;
                    container.CostCodeID     = tran.CostCodeID.GetValueOrDefault(CostCodeAttribute.GetDefaultCostCode());
                    container.InvoicedAmount = sign * tran.LineAmt.GetValueOrDefault();
                    container.InvoicedQty    = sign * tran.Qty.GetValueOrDefault();

                    PMCommitmentAttribute.AddToInvoiced(polines.Cache, container);
                }
            }
        }