コード例 #1
0
        protected virtual void _(Events.FieldDefaulting <FSSrvOrdType, FSSrvOrdType.appAddressSource> e)
        {
            //The default value for this field cannot be handled in the DAC with the PXDefault attribute
            //because the information is retrieved from FSSetup and it fails when the setup hasn't been configured
            if (e.Row == null)
            {
                return;
            }

            FSSetup fsSetupRow = SetupRecord.Select();

            e.NewValue = ID.Source_Info.BUSINESS_ACCOUNT;
        }
コード例 #2
0
        public override void Initialize()
        {
            try
            {
                var fullName = Base.GetType().Namespace + '.' + Base.GetType().Name;

                //if (Base.GetType().Name == "CustomerMaint") {

                PowerTabAssignment.Current = PowerTabAssignment.Select(fullName);

                if (PowerTabAssignment.Current != null)
                {
                    var paramMap = PowerTabMapping.Select();

                    if (paramMap != null)
                    {
                        var ptParams = new Dictionary <string, string>();

                        foreach (GIMappingLine param in paramMap)
                        {
                            //var cleanName = param.FieldName.Split('.').Last();
                            ptParams.Add(param.ParamName, param.FieldName);
                        }

                        //PowerTabSource.Current = new PTSource();
                        //PowerTabSource.Current.PowerTabUrl = BuildSource("GI", PowerTabAssignment.Current.DesignID, ptParams);

                        // ptParams.Add("CustomerAccountID", "AcctCD");
                        //BuildSource("DB", "DB000031", ptParams);

                        Base.RowSelected.AddHandler(Base.PrimaryView, (cache, args) =>
                        {
                            if (PowerTabSource?.Current == null)
                            {
                                PowerTabSource.Current = new PTSource();
                            }
                            PowerTabAssignment.Current = PowerTabAssignment.Select(fullName);
                            var giName = ((GIDesign)PXSelectorAttribute.SelectAll <GIMapping.designID>(PowerTabAssignment.Cache, PowerTabAssignment.Current).Find(map => ((GIDesign)map).DesignID == PowerTabAssignment.Current.DesignID))?.Name;

                            PowerTabSource.Current.PowerTabUrl = BuildSource("GI", giName, ptParams);
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                PXTrace.WriteError(ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Try to get the appropriate ServiceOrderType from this sources:
        /// a. <c>FSServiceOrder</c>
        /// b. <c>FSWrkProcessRow</c>
        /// c. <c>FSSetup</c>
        /// </summary>
        /// <param name="fsWrkProcessRow"><c>FSWrkProcess</c> row.</param>
        /// <param name="fsServiceOrderRow">FSServiceOrder row.</param>
        private string GetSrvOrdType(FSWrkProcess fsWrkProcessRow, FSServiceOrder fsServiceOrderRow)
        {
            // a) Try to retrieve the ServiceOrderType from the ServiceOrder row
            if (fsWrkProcessRow.SOID != null &&
                fsServiceOrderRow != null &&
                !string.IsNullOrEmpty(fsServiceOrderRow.SrvOrdType))
            {
                return(fsServiceOrderRow.SrvOrdType);
            }

            // b) Try to retrieve the ServiceOrderType from the WrkProcess row
            if (!string.IsNullOrEmpty(fsWrkProcessRow.SrvOrdType) &&
                !string.IsNullOrWhiteSpace(fsWrkProcessRow.SrvOrdType))
            {
                return(fsWrkProcessRow.SrvOrdType);
            }

            // c) Try to retrieve the Default ServiceOrderType from the Setup row
            FSSetup fsSetupRow = PXSetup <FSSetup> .Select(this);

            if (fsSetupRow != null &&
                !string.IsNullOrEmpty(fsSetupRow.DfltSrvOrdType))
            {
                return(fsSetupRow.DfltSrvOrdType);
            }

            return(null);
        }
コード例 #4
0
        protected override Type GetSelect(PXCache sender)
        {
            POSetup posetup = PXSetup <POSetup> .Select(sender.Graph);

            if (posetup.AddServicesFromNormalPOtoPR == true && posetup.AddServicesFromDSPOtoPR != true)
            {
                return(typeof(Select <POLine, Where <POLine.lineType, NotEqual <POLineType.service>,
                                                     Or <POLine.orderType, Equal <POOrderType.regularOrder> > > >));
            }
            else if (posetup.AddServicesFromNormalPOtoPR != true && posetup.AddServicesFromDSPOtoPR == true)
            {
                return(typeof(Select <POLine, Where <POLine.lineType, NotEqual <POLineType.service>,
                                                     Or <POLine.orderType, Equal <POOrderType.dropShip> > > >));
            }
            else if (posetup.AddServicesFromNormalPOtoPR == true && posetup.AddServicesFromDSPOtoPR == true)
            {
                return(typeof(Select <POLine, Where <POLine.lineType, NotEqual <POLineType.service>,
                                                     Or <POLine.orderType, Equal <POOrderType.regularOrder>,
                                                         Or <POLine.orderType, Equal <POOrderType.dropShip> > > > >));
            }
            else
            {
                return(typeof(Select <POLine, Where <POLine.lineType, NotEqual <POLineType.service> > >));
            }
        }
コード例 #5
0
        public static void VerifyFinPeriod <fieldPeriod, fieldClosed>(PXGraph graph, PXCache cache, object row, PXSelectBase <FinPeriod> finperiod)
            where fieldPeriod : class, IBqlField
            where fieldClosed : class, IBqlField
        {
            if (finperiod.Current != null)
            {
                GLSetup glsetup = PXSetup <GLSetup> .Select(graph);

                object isClosed = finperiod.Cache.GetValue <fieldClosed>(finperiod.Current);

                if (finperiod.Current.Active != true || isClosed.Equals(true) && glsetup != null && glsetup.PostClosedPeriods != true)
                {
                    BqlCommand select = BqlCommand.CreateInstance(typeof(Select <FinPeriod,
                                                                                 Where <FinPeriod.active, Equal <True>,
                                                                                        And <FinPeriod.finPeriodID, Greater <Required <FinPeriod.finPeriodID> > > >,
                                                                                 OrderBy <Asc <FinPeriod.finPeriodID> > >))
                                        .WhereAnd(BqlCommand.Compose(typeof(Where <,>), typeof(fieldClosed), typeof(NotEqual <True>)));

                    object    docPeriod = cache.GetValue <fieldPeriod>(row);
                    FinPeriod firstopen = new PXView(graph, false, select).SelectSingle(docPeriod) as FinPeriod;

                    if (firstopen == null)
                    {
                        string userPeriod = Mask.Format("##-####", finperiod.Cache.GetValueExt <FinPeriod.finPeriodID>(finperiod.Current).ToString());
                        throw new PXSetPropertyException(GL.Messages.NoActivePeriodAfter, userPeriod);
                    }

                    cache.SetValue <fieldPeriod>(row, firstopen.FinPeriodID);
                }
            }
        }
コード例 #6
0
        public INPostClassMaint()
        {
            INSetup record = insetup.Select();

            PXUIFieldAttribute.SetVisible <INPostClass.pPVAcctID>(postclass.Cache, null, true);
            PXUIFieldAttribute.SetVisible <INPostClass.pPVSubID>(postclass.Cache, null, true);
            PXUIFieldAttribute.SetVisible <INPostClass.pPVAcctDefault>(postclass.Cache, null, true);
            PXUIFieldAttribute.SetVisible <INPostClass.pPVSubMask>(postclass.Cache, null, true);
        }
        public virtual void FSSrvOrdType_AppAddressSource_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            //The default value for this field cannot be handled in the DAC with the PXDefault attribute
            //because the information is retrieved from FSSetup and it fails when the setup hasn't been configured
            if (e.Row == null)
            {
                return;
            }

            FSSetup fsSetupRow = SetupRecord.Select();

            if (fsSetupRow != null && fsSetupRow.DfltAppAddressSource != null)
            {
                e.NewValue = fsSetupRow.DfltAppAddressSource;
            }
            else
            {
                e.NewValue = ID.Source_Info.BUSINESS_ACCOUNT;
            }
        }
コード例 #8
0
        public virtual void VerifyExpenseRefNbrIsNotEmpty(EPExpenseClaimDetails receipt)
        {
            EPSetup setup = EPSetup.Select();

            if (setup.RequireRefNbrInExpenseReceipts == true)
            {
                if (string.IsNullOrEmpty(receipt.ExpenseRefNbr))
                {
                    var fieldName = typeof(EPExpenseClaimDetails.expenseRefNbr).Name;
                    throw new PXRowPersistingException(fieldName, receipt.ExpenseRefNbr, ErrorMessages.FieldIsEmpty, fieldName);
                }
            }
        }
コード例 #9
0
        protected override bool?GetCreditCheckError(PXCache sender, object Row)
        {
            if (sender.Graph.GetType() == typeof(SO.SOInvoiceEntry) || sender.Graph.GetType().BaseType == typeof(SO.SOInvoiceEntry))
            {
                PX.Objects.SO.SOSetup soSetup = PXSetup <PX.Objects.SO.SOSetup> .Select(sender.Graph);

                return(soSetup?.CreditCheckError);
            }
            else
            {
                ARSetup arSetup = PXSetup <ARSetup> .Select(sender.Graph);

                return(arSetup?.CreditCheckError);
            }
        }
コード例 #10
0
        /// <summary>
        /// Try to get the appropriate ServiceOrderType from this sources:
        /// a. <c>FSServiceOrder</c>
        /// b. <c>FSWrkProcessRow</c>
        /// c. <c>FSSetup</c>
        /// </summary>
        /// <param name="fsWrkProcessRow"><c>FSWrkProcess</c> row.</param>
        /// <param name="fsServiceOrderRow">FSServiceOrder row.</param>
        private static string GetSrvOrdType(PXGraph graph, FSWrkProcess fsWrkProcessRow, FSServiceOrder fsServiceOrderRow)
        {
            // a) Try to retrieve the ServiceOrderType from the ServiceOrder row
            if (fsWrkProcessRow.SOID != null &&
                fsServiceOrderRow != null &&
                !string.IsNullOrEmpty(fsServiceOrderRow.SrvOrdType))
            {
                return(fsServiceOrderRow.SrvOrdType);
            }

            // b) Try to retrieve the ServiceOrderType from the WrkProcess row
            if (!string.IsNullOrEmpty(fsWrkProcessRow.SrvOrdType) &&
                !string.IsNullOrWhiteSpace(fsWrkProcessRow.SrvOrdType))
            {
                return(fsWrkProcessRow.SrvOrdType);
            }

            // c) Try to retrieve the ServiceOrderType from the users preferences
            PX.SM.UserPreferences userPreferencesRow = PXSelect <PX.SM.UserPreferences,
                                                                 Where <
                                                                     PX.SM.UserPreferences.userID, Equal <CurrentValue <AccessInfo.userID> > > >
                                                       .Select(graph);

            if (userPreferencesRow != null)
            {
                FSxUserPreferences fsxUserPreferencesRow = PXCache <PX.SM.UserPreferences> .GetExtension <FSxUserPreferences>(userPreferencesRow);

                if (!string.IsNullOrEmpty(fsxUserPreferencesRow.DfltSrvOrdType))
                {
                    return(fsxUserPreferencesRow.DfltSrvOrdType);
                }
            }


            // d) Try to retrieve the Default ServiceOrderType from the Setup row
            FSSetup fsSetupRow = PXSetup <FSSetup> .Select(graph);

            if (fsSetupRow != null &&
                !string.IsNullOrEmpty(fsSetupRow.DfltSrvOrdType))
            {
                return(fsSetupRow.DfltSrvOrdType);
            }

            return(null);
        }
コード例 #11
0
        protected virtual void FSLicense_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSLicense fsLicenseRow = (FSLicense)e.Row;
            FSSetup   fsSetupRow   = SetupRecord.Select();

            if (string.IsNullOrEmpty(fsSetupRow.LicenseNumberingID))
            {
                LicenseRecords.Cache.RaiseExceptionHandling <FSLicense.refNbr>(
                    fsLicenseRow,
                    fsLicenseRow.RefNbr,
                    new PXSetPropertyException(TX.Error.LICENSE_NEED_NUMBERING_ID, PXErrorLevel.Error));
            }
        }
コード例 #12
0
        protected virtual void _(Events.RowPersisting <FSLicense> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSLicense fsLicenseRow = (FSLicense)e.Row;
            FSSetup   fsSetupRow   = SetupRecord.Select();

            if (string.IsNullOrEmpty(fsSetupRow.LicenseNumberingID))
            {
                LicenseRecords.Cache.RaiseExceptionHandling <FSLicense.refNbr>(
                    fsLicenseRow,
                    fsLicenseRow.RefNbr,
                    new PXSetPropertyException(TX.Error.SPECIFY_LICENSE_NUMBERINGID_IN_X, PXErrorLevel.Error,
                                               DACHelper.GetDisplayName(typeof(FSSetup))));
            }
        }
        public DataIntegrityValidator <TRegister> CheckDocumentTotalsConformToCurrencyPrecision(bool disableCheck = false)
        {
            if (IsSkipCheck(disableCheck))
            {
                return(this);
            }

            Company company = PXSetup <Company> .Select(_graph);

            Currency baseCurrency = PXSelect <
                Currency,
                Where <
                    Currency.curyID, Equal <Required <Currency.curyID> > > >
                                    .Select(_graph, company.BaseCuryID);

            Currency documentCurrency = _doc.CuryID == baseCurrency.CuryID
                                ? baseCurrency
                                : PXSelect <
                Currency,
                Where <
                    Currency.curyID, Equal <Required <Currency.curyID> > > >
                                        .Select(_graph, _doc.CuryID);

            short baseCurrencyDecimalPlaces     = baseCurrency.DecimalPlaces ?? 0;
            short documentCurrencyDecimalPlaces = documentCurrency.DecimalPlaces ?? 0;

            decimal documentBalance         = _doc.DocBal ?? 0m;
            decimal documentBalanceCurrency = _doc.CuryDocBal ?? 0m;

            decimal documentOriginalAmount         = _doc.OrigDocAmt ?? 0m;
            decimal documentOriginalAmountCurrency = _doc.CuryOrigDocAmt ?? 0m;

            if (documentBalance != Math.Round(documentBalance, baseCurrencyDecimalPlaces) ||
                documentOriginalAmount != Math.Round(documentOriginalAmount, baseCurrencyDecimalPlaces) ||
                documentBalanceCurrency != Math.Round(documentBalanceCurrency, documentCurrencyDecimalPlaces) ||
                documentOriginalAmountCurrency != Math.Round(documentOriginalAmountCurrency, documentCurrencyDecimalPlaces))
            {
                _errors.Add(new InconsistencyError <InconsistencyCode.documentTotalsWrongPrecision>(
                                new RecordContextInfo(_docCache, _doc)));
            }

            return(this);
        }
コード例 #14
0
        public virtual void VerifyAndSetFirstOpenedFinPeriod <TFinPeriodField, TBranchField>(PXCache rowCache, object row, PXSelectBase <OrganizationFinPeriod> finPeriodView, Type fieldModuleClosed = null)
            where TFinPeriodField : class, IBqlField
            where TBranchField : class, IBqlField
        {
            OrganizationFinPeriod finPeriod = finPeriodView.Current as OrganizationFinPeriod;

            if (finPeriod != null)
            {
                GLSetup glsetup = PXSetup <GLSetup> .Select(Graph);

                bool isClosed = finPeriod.Status == FinPeriods.TableDefinition.FinPeriod.status.Closed;

                if (fieldModuleClosed != null)
                {
                    isClosed |= (bool?)finPeriodView.Cache.GetValue(finPeriod, fieldModuleClosed.Name) == true;
                }

                if (finPeriod.Status == FinPeriod.status.Inactive ||
                    finPeriod.Status == FinPeriod.status.Locked ||
                    isClosed && glsetup != null && glsetup.RestrictAccessToClosedPeriods == true)
                {
                    string finPeriodID    = (string)rowCache.GetValue <TFinPeriodField>(row);
                    int?   organizationID = PXAccess.GetParentOrganizationID((int?)rowCache.GetValue <TBranchField>(row));

                    OrganizationFinPeriod firstopen = rowCache.Graph.GetService <IFinPeriodRepository>().FindFirstOpenFinPeriod(finPeriodID, organizationID, fieldModuleClosed);

                    if (firstopen == null)
                    {
                        string userPeriod = Mask.Format("##-####", finPeriodView.Cache.GetValueExt <OrganizationFinPeriod.finPeriodID>(finPeriodView.Current).ToString());
                        throw new PXSetPropertyException(GL.Messages.NoActivePeriodAfter, userPeriod);
                    }

                    rowCache.SetValue <TFinPeriodField>(row, firstopen.FinPeriodID);
                }
            }
        }
        protected void ApplyTax(PMQuote quote, GetTaxResult result)
        {
            TaxZone taxZone = null;

            AP.Vendor vendor = null;

            if (result.TaxSummary.Length > 0)
            {
                taxZone = (TaxZone)PXSetup <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <PMQuote.taxZoneID> > > > .Select(Base, quote.TaxZoneID);

                vendor = (VendorMaster)PXSelectReadonly <VendorMaster, Where <VendorMaster.bAccountID, Equal <Required <VendorMaster.bAccountID> > > > .Select(Base, taxZone.TaxVendorID);

                if (vendor == null)
                {
                    throw new PXException(CR.Messages.ExternalTaxVendorNotFound);
                }
            }

            //Clear all existing Tax transactions:
            foreach (PXResult <CRTaxTran, Tax> res in Base.Taxes.View.SelectMultiBound(new object[] { quote }))
            {
                CRTaxTran taxTran = (CRTaxTran)res;
                Base.Taxes.Delete(taxTran);
            }

            Base.Views.Caches.Add(typeof(Tax));

            for (int i = 0; i < result.TaxSummary.Length; i++)
            {
                string taxID = GetTaxID(result.TaxSummary[i]);

                //Insert Tax if not exists - just for the selectors sake
                Tax tx = PXSelect <Tax, Where <Tax.taxID, Equal <Required <Tax.taxID> > > > .Select(Base, taxID);

                if (tx == null)
                {
                    tx                   = new Tax();
                    tx.TaxID             = taxID;
                    tx.Descr             = PXMessages.LocalizeFormatNoPrefixNLA(TX.Messages.ExternalTaxProviderTaxId, taxID);
                    tx.TaxType           = CSTaxType.Sales;
                    tx.TaxCalcType       = CSTaxCalcType.Doc;
                    tx.TaxCalcLevel      = result.TaxSummary[i].TaxCalculationLevel.ToCSTaxCalcLevel();
                    tx.TaxApplyTermsDisc = CSTaxTermsDiscount.ToTaxableAmount;
                    tx.SalesTaxAcctID    = vendor.SalesTaxAcctID;
                    tx.SalesTaxSubID     = vendor.SalesTaxSubID;
                    tx.ExpenseAccountID  = vendor.TaxExpenseAcctID;
                    tx.ExpenseSubID      = vendor.TaxExpenseSubID;
                    tx.TaxVendorID       = taxZone.TaxVendorID;
                    tx.IsExternal        = true;

                    Base.Caches[typeof(Tax)].Insert(tx);
                }

                CRTaxTran tax = new CRTaxTran();
                tax.QuoteID        = quote.QuoteID;
                tax.TaxID          = taxID;
                tax.CuryTaxAmt     = result.TaxSummary[i].TaxAmount;
                tax.CuryTaxableAmt = result.TaxSummary[i].TaxableAmount;
                tax.TaxRate        = Convert.ToDecimal(result.TaxSummary[i].Rate) * 100;

                Base.Taxes.Insert(tax);
            }

            Base.Quote.SetValueExt <PMQuote.curyTaxTotal>(quote, result.TotalTaxAmount);

            decimal?СuryProductsAmount =
                quote.ManualTotalEntry == true
                                ? quote.CuryAmount - quote.CuryDiscTot
                                : quote.CuryLineTotal - quote.CuryDiscTot + quote.CuryTaxTotal;

            Base.Quote.SetValueExt <PMQuote.curyProductsAmount>(quote, СuryProductsAmount ?? 0m);
        }
コード例 #16
0
        protected static void ApplyAvalaraTax(OpportunityMaint rg, CROpportunity order, GetTaxResult result)
        {
            var avalaraSetup = (TXAvalaraSetup)PXSetupOptional <TXAvalaraSetup> .Select(rg);

            TaxZone taxZone = (TaxZone)PXSetup <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <CROpportunity.taxZoneID> > > > .Select(rg, order.TaxZoneID);

            AP.Vendor vendor = PXSelect <AP.Vendor, Where <AP.Vendor.bAccountID, Equal <Required <AP.Vendor.bAccountID> > > > .Select(rg, taxZone.TaxVendorID);

            if (vendor == null)
            {
                throw new PXException("Tax Vendor is required but not found for the External TaxZone.");
            }

            Dictionary <string, CRTaxTran> existingRows = new Dictionary <string, CRTaxTran>();

            foreach (PXResult <CRTaxTran, Tax> res in rg.Taxes.View.SelectMultiBound(new object[] { order }))
            {
                CRTaxTran taxTran = (CRTaxTran)res;
                existingRows.Add(taxTran.TaxID.Trim().ToUpperInvariant(), taxTran);
            }

            rg.Views.Caches.Add(typeof(Tax));

            for (int i = 0; i < result.TaxSummary.Count; i++)
            {
                string taxID = result.TaxSummary[i].TaxName.ToUpperInvariant();

                //Insert Tax if not exists - just for the selectors sake
                Tax tx = PXSelect <Tax, Where <Tax.taxID, Equal <Required <Tax.taxID> > > > .Select(rg, taxID);

                if (tx == null)
                {
                    tx       = new Tax();
                    tx.TaxID = taxID;
                    //tx.Descr = string.Format("Avalara {0} {1}%", taxID, Convert.ToDecimal(result.TaxSummary[i].Rate)*100);
                    tx.Descr             = string.Format("Avalara {0}", taxID);
                    tx.TaxType           = CSTaxType.Sales;
                    tx.TaxCalcType       = CSTaxCalcType.Doc;
                    tx.TaxCalcLevel      = avalaraSetup.IsInclusiveTax == true ? CSTaxCalcLevel.Inclusive : CSTaxCalcLevel.CalcOnItemAmt;
                    tx.TaxApplyTermsDisc = CSTaxTermsDiscount.ToTaxableAmount;
                    tx.SalesTaxAcctID    = vendor.SalesTaxAcctID;
                    tx.SalesTaxSubID     = vendor.SalesTaxSubID;
                    tx.ExpenseAccountID  = vendor.TaxExpenseAcctID;
                    tx.ExpenseSubID      = vendor.TaxExpenseSubID;
                    tx.TaxVendorID       = taxZone.TaxVendorID;

                    rg.Caches[typeof(Tax)].Insert(tx);
                }

                CRTaxTran existing = null;
                existingRows.TryGetValue(taxID, out existing);

                if (existing != null)
                {
                    existing.TaxAmt         = Math.Abs(result.TaxSummary[i].Tax);
                    existing.CuryTaxAmt     = Math.Abs(result.TaxSummary[i].Tax);
                    existing.TaxableAmt     = Math.Abs(result.TaxSummary[i].Taxable);
                    existing.CuryTaxableAmt = Math.Abs(result.TaxSummary[i].Taxable);
                    existing.TaxRate        = Convert.ToDecimal(result.TaxSummary[i].Rate);

                    rg.Taxes.Update(existing);
                    existingRows.Remove(existing.TaxID.Trim().ToUpperInvariant());
                }
                else
                {
                    CRTaxTran tax = new CRTaxTran();
                    tax.OpportunityID  = order.OpportunityID;
                    tax.TaxID          = taxID;
                    tax.TaxAmt         = Math.Abs(result.TaxSummary[i].Tax);
                    tax.CuryTaxAmt     = Math.Abs(result.TaxSummary[i].Tax);
                    tax.TaxableAmt     = Math.Abs(result.TaxSummary[i].Taxable);
                    tax.CuryTaxableAmt = Math.Abs(result.TaxSummary[i].Taxable);
                    tax.TaxRate        = Convert.ToDecimal(result.TaxSummary[i].Rate);

                    rg.Taxes.Insert(tax);
                }
            }

            foreach (CRTaxTran taxTran in existingRows.Values)
            {
                rg.Taxes.Delete(taxTran);
            }

            rg.Opportunity.SetValueExt <CROpportunity.curyTaxTotal>(order, Math.Abs(result.TotalTax));

            try
            {
                rg.SkipAvalaraTaxProcessing = true;
                rg.Save.Press();
            }
            finally
            {
                rg.SkipAvalaraTaxProcessing = false;
            }
        }
コード例 #17
0
ファイル: TaxImport.cs プロジェクト: Vialythen/AcumaticaTest
        private static void Translate(TaxImportProcess graph, TXImportState item, TaxBuilder.Result result, out List <Tax> taxes,
                                      out List <KeyValuePair <Tax, List <TaxRev> > > revisions, out List <TaxZone> zones, out List <TaxZoneDet> zoneDetails, out List <TaxCategoryDet> categoryDetails, out List <TaxZoneZip> zoneZips)
        {
            taxes           = new List <Tax>(result.Taxes.Count);
            revisions       = new List <KeyValuePair <Tax, List <TaxRev> > >(result.Taxes.Count);
            zones           = new List <TaxZone>(result.Zones.Count);
            zoneDetails     = new List <TaxZoneDet>(result.ZoneDetails.Count);
            categoryDetails = new List <TaxCategoryDet>(result.Taxes.Count * 2);
            zoneZips        = new List <TaxZoneZip>(result.ZoneZips.Count);

            TXImportSettings settings = PXSetup <TXImportSettings> .Select(graph);

            if (string.IsNullOrEmpty(settings.TaxableCategoryID))
            {
                throw new PXException(Messages.TaxableCategoryIDIsNotSet);
            }

            foreach (ZoneRecord zr in result.Zones)
            {
                TaxZone taxZone = new TaxZone();
                taxZone.TaxZoneID = zr.ZoneID;
                taxZone.Descr     = zr.Description;

                if (zr.CombinedRate > 0)
                {
                    taxZone.DfltTaxCategoryID = settings.TaxableCategoryID;
                }

                taxZone.IsImported = true;
                zones.Add(taxZone);
            }

            foreach (TaxRecord tr in result.Taxes)
            {
                Tax tax = new Tax();
                tax.TaxID          = tr.TaxID;
                tax.TaxType        = CSTaxType.Sales;
                tax.Descr          = tr.Description;
                tax.IsImported     = true;
                tax.SalesTaxAcctID = item.AccountID;
                tax.SalesTaxSubID  = item.SubID;
                tax.TaxCalcType    = CSTaxCalcType.Doc;
                tax.TaxCalcLevel   = CSTaxCalcLevel.CalcOnItemAmt;
                taxes.Add(tax);

                revisions.Add(new KeyValuePair <Tax, List <TaxRev> >(tax, GetRevisions(tr)));
                categoryDetails.AddRange(GetCategories(graph, settings, tr));
            }

            foreach (ZoneDetailRecord zd in result.ZoneDetails)
            {
                TaxZoneDet zoneDetail = new TaxZoneDet();
                zoneDetail.TaxID      = zd.TaxID;
                zoneDetail.TaxZoneID  = zd.ZoneID;
                zoneDetail.IsImported = true;
                zoneDetails.Add(zoneDetail);
            }

            foreach (IList <ZoneZipPlusRecord> zr in result.ZoneZipPlus.Values)
            {
                foreach (ZoneZipPlusRecord zzp in zr)
                {
                    TaxZoneZip tzzp = new TaxZoneZip();
                    tzzp.TaxZoneID = zzp.ZoneID;
                    tzzp.ZipCode   = zzp.ZipCode;
                    tzzp.ZipMin    = zzp.ZipMin;
                    tzzp.ZipMax    = zzp.ZipMax;

                    zoneZips.Add(tzzp);
                }
            }
        }
コード例 #18
0
        protected virtual bool?GetCreditCheckError(PXCache sender, object Row)
        {
            ARSetup arsetup = PXSetup <ARSetup> .Select(sender.Graph);

            return(arsetup?.CreditCheckError);
        }
        protected virtual void ARSalesPrice_SalesPrice_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            ARSalesPrice row = e.Row as ARSalesPrice;

            if (row != null && MinGrossProfitValidation != MinGrossProfitValidationType.None && row.EffectiveDate != null)
            {
                var r = (PXResult <InventoryItem, INItemCost>)
                        PXSelectJoin <InventoryItem,
                                      LeftJoin <INItemCost, On <INItemCost.inventoryID, Equal <InventoryItem.inventoryID> > >,
                                      Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .SelectWindowed(this, 0, 1, row.InventoryID);

                InventoryItem item = r;
                INItemCost    cost = r;
                if (item != null)
                {
                    decimal newValue = (decimal)e.NewValue;
                    if (row.UOM != item.BaseUnit)
                    {
                        try
                        {
                            newValue = INUnitAttribute.ConvertFromBase(sender, item.InventoryID, row.UOM, newValue, INPrecision.UNITCOST);
                        }
                        catch (PXUnitConversionException)
                        {
                            sender.RaiseExceptionHandling <ARSalesPrice.salesPrice>(row, e.NewValue, new PXSetPropertyException(SO.Messages.FailedToConvertToBaseUnits, PXErrorLevel.Warning));
                            return;
                        }
                    }

                    decimal minPrice = PXPriceCostAttribute.MinPrice(item, cost);
                    if (row.CuryID != Company.Current.BaseCuryID)
                    {
                        ARSetup arsetup = PXSetup <ARSetup> .Select(this);

                        if (string.IsNullOrEmpty(arsetup.DefaultRateTypeID))
                        {
                            throw new PXException(SO.Messages.DefaultRateNotSetup);
                        }

                        minPrice = ConvertAmt(Company.Current.BaseCuryID, row.CuryID, arsetup.DefaultRateTypeID, row.EffectiveDate.Value, minPrice);
                    }


                    if (newValue < minPrice)
                    {
                        switch (MinGrossProfitValidation)
                        {
                        case MinGrossProfitValidationType.Warning:
                            sender.RaiseExceptionHandling <ARSalesPrice.salesPrice>(row, e.NewValue, new PXSetPropertyException(SO.Messages.GrossProfitValidationFailed, PXErrorLevel.Warning));
                            break;

                        case MinGrossProfitValidationType.SetToMin:
                            e.NewValue = minPrice;
                            sender.RaiseExceptionHandling <ARSalesPrice.salesPrice>(row, e.NewValue, new PXSetPropertyException(SO.Messages.GrossProfitValidationFailedAndPriceFixed, PXErrorLevel.Warning));
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
コード例 #20
0
        protected virtual void ApplyTax(CROpportunity order, GetTaxResult result)
        {
            TaxZone taxZone = null;

            AP.Vendor vendor = null;

            if (result.TaxSummary.Length > 0)
            {
                taxZone = (TaxZone)PXSetup <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <CROpportunity.taxZoneID> > > > .Select(Base, order.TaxZoneID);

                vendor = (AP.Vendor) PXSelect <AP.Vendor, Where <AP.Vendor.bAccountID, Equal <Required <AP.Vendor.bAccountID> > > > .Select(Base, taxZone.TaxVendorID);

                if (vendor == null)
                {
                    throw new PXException(Messages.ExternalTaxVendorNotFound);
                }
            }

            //Clear all existing Tax transactions:
            foreach (PXResult <CRTaxTran, Tax> res in Base.Taxes.View.SelectMultiBound(new object[] { order }))
            {
                CRTaxTran taxTran = (CRTaxTran)res;
                Base.Taxes.Delete(taxTran);
            }

            Base.Views.Caches.Add(typeof(Tax));

            for (int i = 0; i < result.TaxSummary.Length; i++)
            {
                string taxID = result.TaxSummary[i].TaxName;
                if (string.IsNullOrEmpty(taxID))
                {
                    taxID = result.TaxSummary[i].JurisCode;
                }

                if (string.IsNullOrEmpty(taxID))
                {
                    PXTrace.WriteInformation(Messages.EmptyValuesFromExternalTaxProvider);
                    continue;
                }

                CreateTax(Base, taxZone, vendor, result.TaxSummary[i], taxID);

                CRTaxTran tax = new CRTaxTran();
                tax.QuoteID        = order.QuoteNoteID;
                tax.TaxID          = taxID;
                tax.CuryTaxAmt     = Math.Abs(result.TaxSummary[i].TaxAmount);
                tax.CuryTaxableAmt = Math.Abs(result.TaxSummary[i].TaxableAmount);
                tax.TaxRate        = Convert.ToDecimal(result.TaxSummary[i].Rate) * 100;

                Base.Taxes.Insert(tax);
            }

            Base.Opportunity.SetValueExt <CROpportunity.curyTaxTotal>(order, Math.Abs(result.TotalTaxAmount));

            decimal?СuryProductsAmount =
                order.ManualTotalEntry == true
                                ? order.CuryAmount - order.CuryDiscTot
                                : order.CuryLineTotal - order.CuryDiscTot + order.CuryTaxTotal;

            CalcCuryProductsAmount(order, ref СuryProductsAmount);

            Base.Opportunity.SetValueExt <CROpportunity.curyProductsAmount>(order, СuryProductsAmount ?? 0m);
        }
コード例 #21
0
 private GLSetup GetGLSetup()
 {
     return(PXSetup <GLSetup> .Select(_graph));
 }
コード例 #22
0
        protected virtual bool?IsMigrationMode(PXCache sender)
        {
            ARSetup arsetup = PXSetup <ARSetup> .Select(sender.Graph);

            return(arsetup?.MigrationMode);
        }
        protected void ApplyTax(FSServiceOrder order, GetTaxResult result)
        {
            TaxZone taxZone = null;

            AP.Vendor vendor = null;

            if (result.TaxSummary.Length > 0)
            {
                taxZone = (TaxZone)PXSetup <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <FSServiceOrder.taxZoneID> > > > .Select(Base, order.TaxZoneID);

                vendor = (AP.Vendor) PXSelect <AP.Vendor, Where <AP.Vendor.bAccountID, Equal <Required <AP.Vendor.bAccountID> > > > .Select(Base, taxZone.TaxVendorID);

                if (vendor == null)
                {
                    throw new PXException(PX.Objects.CR.Messages.ExternalTaxVendorNotFound);
                }
            }

            //Clear all existing Tax transactions:
            foreach (PXResult <FSServiceOrderTaxTran, Tax> res in Base.Taxes.View.SelectMultiBound(new object[] { order }))
            {
                FSServiceOrderTaxTran taxTran = (FSServiceOrderTaxTran)res;
                Base.Taxes.Delete(taxTran);
            }

            Base.Views.Caches.Add(typeof(Tax));

            for (int i = 0; i < result.TaxSummary.Length; i++)
            {
                string taxID = GetTaxID(result.TaxSummary[i]);

                //Insert Tax if not exists - just for the selectors sake
                Tax tx = PXSelect <Tax, Where <Tax.taxID, Equal <Required <Tax.taxID> > > > .Select(Base, taxID);

                if (tx == null)
                {
                    tx                   = new Tax();
                    tx.TaxID             = taxID;
                    tx.Descr             = PXMessages.LocalizeFormatNoPrefixNLA(PX.Objects.TX.Messages.ExternalTaxProviderTaxId, taxID);
                    tx.TaxType           = CSTaxType.Sales;
                    tx.TaxCalcType       = CSTaxCalcType.Doc;
                    tx.TaxCalcLevel      = result.TaxSummary[i].TaxCalculationLevel.ToCSTaxCalcLevel();
                    tx.TaxApplyTermsDisc = CSTaxTermsDiscount.ToTaxableAmount;
                    tx.SalesTaxAcctID    = vendor.SalesTaxAcctID;
                    tx.SalesTaxSubID     = vendor.SalesTaxSubID;
                    tx.ExpenseAccountID  = vendor.TaxExpenseAcctID;
                    tx.ExpenseSubID      = vendor.TaxExpenseSubID;
                    tx.TaxVendorID       = taxZone.TaxVendorID;
                    tx.IsExternal        = true;

                    Base.Caches[typeof(Tax)].Insert(tx);
                }

                FSServiceOrderTaxTran tax = new FSServiceOrderTaxTran();
                tax.EntityType     = ID.PostDoc_EntityType.SERVICE_ORDER;
                tax.EntityID       = order.SOID;
                tax.TaxID          = taxID;
                tax.CuryTaxAmt     = Math.Abs(result.TaxSummary[i].TaxAmount);
                tax.CuryTaxableAmt = Math.Abs(result.TaxSummary[i].TaxableAmount);
                tax.TaxRate        = Convert.ToDecimal(result.TaxSummary[i].Rate) * 100;

                Base.Taxes.Insert(tax);
            }

            Base.CurrentServiceOrder.SetValueExt <FSServiceOrder.curyTaxTotal>(order, Math.Abs(result.TotalTaxAmount));

            decimal?СuryDocTotal = ServiceOrderEntry.GetCuryDocTotal(order.CuryBillableOrderTotal, order.CuryDiscTot, order.CuryTaxTotal, 0);

            Base.CurrentServiceOrder.SetValueExt <FSServiceOrder.curyDocTotal>(order, СuryDocTotal ?? 0m);
        }
コード例 #24
0
        protected static void ApplyAvalaraTax(OpportunityMaint rg, CROpportunity order, GetTaxResult result)
        {
            var avalaraSetup = (TXAvalaraSetup)PXSetupOptional <TXAvalaraSetup> .Select(rg);

            TaxZone taxZone = (TaxZone)PXSetup <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <CROpportunity.taxZoneID> > > > .Select(rg, order.TaxZoneID);

            AP.Vendor vendor = PXSelect <AP.Vendor, Where <AP.Vendor.bAccountID, Equal <Required <AP.Vendor.bAccountID> > > > .Select(rg, taxZone.TaxVendorID);

            if (vendor == null)
            {
                throw new PXException(Messages.ExternalTaxVendorNotFound);
            }

            //Clear all existing Tax transactions:
            foreach (PXResult <CRTaxTran, Tax> res in rg.Taxes.View.SelectMultiBound(new object[] { order }))
            {
                CRTaxTran taxTran = (CRTaxTran)res;
                rg.Taxes.Delete(taxTran);
            }

            rg.Views.Caches.Add(typeof(Tax));

            for (int i = 0; i < result.TaxSummary.Count; i++)
            {
                string taxID = AvalaraMaint.GetTaxID(result.TaxSummary[i]);

                //Insert Tax if not exists - just for the selectors sake
                Tax tx = PXSelect <Tax, Where <Tax.taxID, Equal <Required <Tax.taxID> > > > .Select(rg, taxID);

                if (tx == null)
                {
                    tx       = new Tax();
                    tx.TaxID = taxID;
                    //tx.Descr = string.Format("Avalara {0} {1}%", taxID, Convert.ToDecimal(result.TaxSummary[i].Rate)*100);
                    tx.Descr             = PXMessages.LocalizeFormatNoPrefixNLA(TX.Messages.AvalaraTaxId, taxID);
                    tx.TaxType           = CSTaxType.Sales;
                    tx.TaxCalcType       = CSTaxCalcType.Doc;
                    tx.TaxCalcLevel      = avalaraSetup.IsInclusiveTax == true ? CSTaxCalcLevel.Inclusive : CSTaxCalcLevel.CalcOnItemAmt;
                    tx.TaxApplyTermsDisc = CSTaxTermsDiscount.ToTaxableAmount;
                    tx.SalesTaxAcctID    = vendor.SalesTaxAcctID;
                    tx.SalesTaxSubID     = vendor.SalesTaxSubID;
                    tx.ExpenseAccountID  = vendor.TaxExpenseAcctID;
                    tx.ExpenseSubID      = vendor.TaxExpenseSubID;
                    tx.TaxVendorID       = taxZone.TaxVendorID;
                    tx.IsExternal        = true;

                    rg.Caches[typeof(Tax)].Insert(tx);
                }

                CRTaxTran tax = new CRTaxTran();
                tax.OpportunityID  = order.OpportunityID;
                tax.TaxID          = taxID;
                tax.CuryTaxAmt     = Math.Abs(result.TaxSummary[i].Tax);
                tax.CuryTaxableAmt = Math.Abs(result.TaxSummary[i].Taxable);
                tax.TaxRate        = Convert.ToDecimal(result.TaxSummary[i].Rate) * 100;

                rg.Taxes.Insert(tax);
            }

            rg.Opportunity.SetValueExt <CROpportunity.curyTaxTotal>(order, Math.Abs(result.TotalTax));

            try
            {
                rg.SkipAvalaraTaxProcessing = true;
                rg.Save.Press();
            }
            finally
            {
                rg.SkipAvalaraTaxProcessing = false;
            }
        }