Beispiel #1
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);
                }
            }
        }
Beispiel #2
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> > >));
            }
        }
        /// <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);
        }
Beispiel #4
0
        public static void Update(PXGraph graph, int?vendorID, int?vendorLocationID, string curyID, int?inventoryID, int?subItemID, string uom, decimal curyCost)
        {
            if (curyCost <= 0 || string.IsNullOrEmpty(uom) ||
                vendorID == null ||
                vendorLocationID == null)
            {
                return;
            }

            PXCache cache = graph.Caches[typeof(POVendorInventoryPriceUpdate)];

            foreach (PXResult <InventoryItem, Vendor, Company> r in
                     PXSelectJoin <InventoryItem,
                                   LeftJoin <Vendor,
                                             On <Vendor.bAccountID, Equal <Required <Vendor.bAccountID> > >,
                                             CrossJoin <Company> >,
                                   Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .
                     Select(graph, vendorID, inventoryID))
            {
                InventoryItem item    = r;
                Vendor        vendor  = r;
                Company       company = r;
                if (item.InventoryID == null || vendor.BAccountID == null ||
                    (item.StkItem == true && subItemID == null))
                {
                    continue;
                }
                INSetup setup = new PXSetup <INSetup>(graph).Current;

                int?savedSubItemID = item.StkItem == true ? subItemID : null;

                POVendorInventory existVendorPrice = PXSelectReadonly <POVendorInventory,
                                                                       Where <POVendorInventory.inventoryID, Equal <Required <POVendorInventory.inventoryID> >,
                                                                              And <POVendorInventory.subItemID, Equal <Required <POVendorInventory.subItemID> >,
                                                                                   And <POVendorInventory.purchaseUnit, Equal <Required <POVendorInventory.purchaseUnit> >,
                                                                                        And <POVendorInventory.vendorID, Equal <Required <POVendorInventory.vendorID> >,
                                                                                             And <POVendorInventory.vendorLocationID, Equal <Required <POVendorInventory.vendorLocationID> > > > > > > >
                                                     .SelectWindowed(graph, 0, 1, item.InventoryID, savedSubItemID, uom, vendorID, vendorLocationID);

                string priceCuryID = (existVendorPrice != null ? existVendorPrice.CuryID : vendor.CuryID) ?? company.BaseCuryID;

                POVendorInventoryPriceUpdate vendorPrice = (POVendorInventoryPriceUpdate)cache.CreateInstance();
                vendorPrice.InventoryID      = inventoryID;
                vendorPrice.SubItemID        = savedSubItemID;
                vendorPrice.VendorID         = vendorID;
                vendorPrice.VendorLocationID = vendorLocationID;
                vendorPrice.PurchaseUnit     = uom;
                vendorPrice = (POVendorInventoryPriceUpdate)cache.Insert(vendorPrice);
                if (item.StkItem != true)
                {
                    vendorPrice.SubItemID = savedSubItemID;
                }
                vendorPrice.CuryID = priceCuryID;
                cache.Normalize();
                vendorPrice.Active = true;
                Decimal cost = ConventCury(graph, vendor.CuryRateTypeID, curyID, curyCost, priceCuryID);
                vendorPrice.LastPrice = ConvertUOM(graph, item, uom, cost, item.PurchaseUnit);
            }
        }
Beispiel #5
0
        public static IFaceApi GetFaceApi(this PXGraph graph)
        {
            var settings = new PXSetup <PreferencesSecurity>(graph);

            var subscriptionId = (string)settings.Cache.GetValue(settings.Current, "UsrFaceApiID");

            var sericeUrl = (string)settings.Cache.GetValue(settings.Current, "UsrFaceApiURL");

            return(new FaceApiClient(new FaceApiOxfordClient(subscriptionId, sericeUrl), new FaceApiStore(graph)));
        }
        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);
            }
        }
Beispiel #7
0
        public RUTROTManager(PXGraph graph, PXSelectBase <RUTROT> rutrot, PXSelectBase <RUTROTDistribution> distribution, PXSelectBase <Doc> document, PXSelectBase <Tran> transactions, PXSelectBase <CurrencyInfo> curyInfo)
        {
            this.Base      = graph;
            Rutrots        = rutrot;
            RRDistribution = distribution;
            Document       = document;
            Transactions   = transactions;
            currencyinfo   = curyInfo;
            ARSetup        = new PXSetup <AR.ARSetup>(graph);

            graph.RowSelected.AddHandler <RUTROTDistribution>(RUTROTDistribution_RowSelected);
            graph.RowInserted.AddHandler <RUTROT>(RUTROT_RowInserted);
            graph.RowUpdated.AddHandler <RUTROT>(RUTROT_RowUpdated);
            graph.RowPersisting.AddHandler <RUTROT>(RUTROT_RowPersisting);
            graph.FieldVerifying.AddHandler <RUTROT.rUTROTType>(RUTROT_RUTROTType_FieldVerifying);
            graph.FieldUpdated.AddHandler <RUTROT.rUTROTType>(RUTROT_RUTROTType_FieldUpdated);
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public override List <ApprovalMap> GetAssignedMaps(SourceAssign doc, PXCache cache)
        {
            PXResultset <SetupApproval> setups = PXSetup <SetupApproval> .SelectMultiBound(cache.Graph, new object[] { doc });

            int count = setups.Count;
            var list  = new List <ApprovalMap>();

            for (int i = 0; i < count; i++)
            {
                SetupApproval setup = (SetupApproval)setups[i];
                IAssignedMap  map   = (IAssignedMap)setup;
                if (map.IsActive == true && map.AssignmentMapID != null)
                {
                    list.Add(new ApprovalMap(map.AssignmentMapID.Value, map.AssignmentNotificationID));
                }
            }
            return(list);
        }
        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);
        }
        public static Decimal ConventCury(PXGraph graph, string curyRateTypeID, string curyID, decimal curyCost, string destinationCuryID)
        {
            if (curyID == destinationCuryID)
            {
                return(curyCost);
            }

            Decimal baseCost   = curyCost;
            string  BaseCuryID = new PXSetup <Company>(graph).Current.BaseCuryID;

            if (curyID != BaseCuryID)
            {
                PXCurrencyAttribute.CuryConvBase(graph.Caches[typeof(CurrencyInfo)], GetCurrencyInfo(graph, curyRateTypeID, curyID), curyCost, out baseCost, true);
            }
            Decimal cost = baseCost;

            if (destinationCuryID != BaseCuryID)
            {
                PXCurrencyAttribute.CuryConvCury(graph.Caches[typeof(CurrencyInfo)], GetCurrencyInfo(graph, curyRateTypeID, destinationCuryID), baseCost, out cost, true);
            }
            return(cost);
        }
        private static CurrencyInfo GetCurrencyInfo(PXGraph graph, string curyRateTypeID, string curyID)
        {
            if (curyID == null)
            {
                curyID = new PXSetup <Company>(graph).Current.BaseCuryID;
            }
            if (curyRateTypeID == null)
            {
                curyRateTypeID = new CMSetupSelect(graph).Current.APRateTypeDflt;
            }

            CurrencyInfo info = new CurrencyInfo();

            info.ModuleCode     = BatchModule.AP;
            info.CuryID         = curyID;
            info.CuryRateTypeID = curyRateTypeID;
            info.CuryInfoID     = null;
            PXCache cache = graph.Caches[typeof(CurrencyInfo)];

            info = (CurrencyInfo)cache.Insert(info);
            cache.Delete(info);
            return(info);
        }
        public virtual object GetExpenseAccountSub(PXCache sender, PXFieldDefaultingEventArgs e, InventoryItem item, int?siteID,
                                                   GetAccountSubUsingPostingClassDelegate GetAccountSubUsingPostingClass,
                                                   GetAccountSubFromItemDelegate GetAccountSubFromItem)
        {
            object expenseAccountSubID = null;

            if (item != null && item.StkItem != true)
            {
                var insetup = (INSetup)PXSetup <INSetup> .SelectWindowed(sender.Graph, 0, 1);

                if (item.NonStockReceipt == true && PXAccess.FeatureInstalled <FeaturesSet.inventory>() && insetup != null && insetup.UpdateGL == true)
                {
                    INPostClass postClass = INPostClass.PK.Find(sender.Graph, item.PostClassID);
                    if (postClass != null)
                    {
                        var site = INSite.PK.Find(sender.Graph, siteID);
                        try
                        {
                            expenseAccountSubID = GetAccountSubUsingPostingClass(item, site, postClass);
                        }
                        catch (PXMaskArgumentException)
                        {
                        }
                    }
                    else
                    {
                        expenseAccountSubID = null;
                    }
                }
                else
                {
                    expenseAccountSubID = GetAccountSubFromItem(item);
                }
            }

            return(expenseAccountSubID);
        }
        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);
                }
            }
        }
 private GLSetup GetGLSetup()
 {
     return(PXSetup <GLSetup> .Select(_graph));
 }
Beispiel #16
0
        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);
                }
            }
        }
        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;
                        }
                    }
                }
            }
        }
Beispiel #18
0
        private static void ClaimDetail(List <EPExpenseClaimDetails> details, bool isApiContext, bool singleOperation)
        {
            ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>();
            PXSetup <EPSetup> epsetup           = new PXSetup <EPSetup>(PXGraph.CreateInstance(typeof(ExpenseClaimDetailEntry)));
            bool enabledApprovalReceipt         = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null;
            bool isError        = false;
            bool notAllApproved = false;
            Dictionary <string, EPExpenseClaim> result = new Dictionary <string, EPExpenseClaim>();

            IEnumerable <Receipts> List;

            if (epsetup.Current.AllowMixedTaxSettingInClaims == true)
            {
                List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy(
                    item => new
                {
                    item.EmployeeID,
                    item.BranchID,
                    item.CustomerID,
                    item.CustomerLocationID,
                    ClaimCuryID = GetClaimCuryID(expenseClaimEntry, item)
                },
                    (key, item) => new Receipts
                {
                    employee         = key.EmployeeID,
                    branch           = key.BranchID,
                    customer         = key.CustomerID,
                    customerLocation = key.CustomerLocationID,
                    claimCuryID      = key.ClaimCuryID,
                    details          = item
                }
                    );
            }
            else
            {
                List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy(
                    item => new
                {
                    item.EmployeeID,
                    item.BranchID,
                    item.CustomerID,
                    item.CustomerLocationID,
                    item.TaxZoneID,
                    item.TaxCalcMode,
                    ClaimCuryID = GetClaimCuryID(expenseClaimEntry, item)
                },
                    (key, item) => new Receipts
                {
                    employee         = key.EmployeeID,
                    branch           = key.BranchID,
                    customer         = key.CustomerID,
                    customerLocation = key.CustomerLocationID,
                    claimCuryID      = key.ClaimCuryID,
                    details          = item
                }
                    );
            }

            string errorMessage = null;

            foreach (Receipts item in List)
            {
                isError        = false;
                notAllApproved = false;
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    expenseClaimEntry.Clear();
                    expenseClaimEntry.SelectTimeStamp();
                    EPExpenseClaim expenseClaim = (EPExpenseClaim)expenseClaimEntry.ExpenseClaim.Cache.CreateInstance();
                    expenseClaim.EmployeeID         = item.employee;
                    expenseClaim.BranchID           = item.branch;
                    expenseClaim.CustomerID         = item.customer;
                    expenseClaim.DocDesc            = EP.Messages.SubmittedReceipt;
                    expenseClaim                    = expenseClaimEntry.ExpenseClaim.Update(expenseClaim);
                    expenseClaim.CuryID             = item.claimCuryID;
                    expenseClaim                    = expenseClaimEntry.ExpenseClaim.Update(expenseClaim);
                    expenseClaim.CustomerLocationID = item.customerLocation;
                    expenseClaim.TaxCalcMode        = item.details.First().TaxCalcMode;
                    expenseClaim.TaxZoneID          = item.details.First().TaxZoneID;

                    foreach (EPExpenseClaimDetails detail in item.details)
                    {
                        PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(detail);

                        if (detail.Approved ?? false)
                        {
                            try
                            {
                                if (detail.IsPaidWithCard)
                                {
                                    EPEmployee employee =
                                        PXSelect <EPEmployee,
                                                  Where <EPEmployee.bAccountID, Equal <Required <EPEmployee.bAccountID> > > >
                                        .Select(expenseClaimEntry, item.employee);

                                    if (employee.AllowOverrideCury != true && detail.CardCuryID != employee.CuryID)
                                    {
                                        errorMessage = PXMessages.Localize(Messages.ClaimCannotBeCreatedForReceiptBecauseCuryCannotBeOverriden);

                                        isError = true;
                                    }
                                }

                                if (!isError && detail.TipAmt != 0 && epsetup.Current.NonTaxableTipItem == null)
                                {
                                    errorMessage = Messages.TipItemIsNotDefined;
                                    isError      = true;
                                }

                                if (!isError)
                                {
                                    expenseClaimEntry.ReceiptEntryExt.SubmitReceiptExt(expenseClaimEntry.ExpenseClaim.Cache,
                                                                                       expenseClaimEntry.ExpenseClaimDetails.Cache, expenseClaimEntry.ExpenseClaim.Current, detail);

                                    expenseClaimEntry.Save.Press();
                                    if (!result.ContainsKey(expenseClaim.RefNbr))
                                    {
                                        result.Add(expenseClaim.RefNbr, expenseClaim);
                                    }
                                    detail.RefNbr = expenseClaim.RefNbr;

                                    PXProcessing <EPExpenseClaimDetails> .SetProcessed();
                                }
                            }
                            catch (Exception ex)
                            {
                                errorMessage = ex.Message;
                                isError      = true;
                            }
                        }
                        else
                        {
                            errorMessage = enabledApprovalReceipt
                                                                ? Messages.ReceiptNotApproved
                                                                : Messages.ReceiptTakenOffHold;

                            notAllApproved = true;
                        }

                        if (errorMessage != null)
                        {
                            PXProcessing <EPExpenseClaimDetails> .SetError(errorMessage);
                        }
                    }
                    if (!isError)
                    {
                        ts.Complete();
                    }
                }
            }

            if (!isError && !notAllApproved)
            {
                if (result.Count == 1 && isApiContext == false)
                {
                    expenseClaimEntry = CreateInstance <ExpenseClaimEntry>();
                    PXRedirectHelper.TryRedirect(expenseClaimEntry, result.First().Value, PXRedirectHelper.WindowMode.InlineWindow);
                }
            }
            else
            {
                PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(null);

                if (singleOperation)
                {
                    throw new PXException(errorMessage);
                }
                else
                {
                    throw new PXException(Messages.ErrorProcessingReceipts);
                }
            }
        }
Beispiel #19
0
        protected override bool isControlTotalRequired(PXCache sender)
        {
            CASetup setup = new PXSetup <CASetup>(sender.Graph).Select();

            return(setup != null && setup.RequireControlTotal == true);
        }
        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);
        }
        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);
        }
        private static void ClaimDetail(List <EPExpenseClaimDetails> details)
        {
            PXSetup <EPSetup> epsetup   = new PXSetup <EPSetup>(PXGraph.CreateInstance(typeof(ExpenseClaimDetailEntry)));
            bool enabledApprovalReceipt = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null;
            bool isError        = false;
            bool notAllApproved = false;
            Dictionary <string, EPExpenseClaim> result = new Dictionary <string, EPExpenseClaim>();

            IEnumerable <Receipts> List;

            if (epsetup.Current.AllowMixedTaxSettingInClaims == true)
            {
                List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy(
                    item => new
                {
                    item.EmployeeID,
                    item.BranchID,
                    item.CustomerID,
                    item.CustomerLocationID,
                },
                    (key, item) => new Receipts
                {
                    employee         = key.EmployeeID,
                    branch           = key.BranchID,
                    customer         = key.CustomerID,
                    customerLocation = key.CustomerLocationID,
                    details          = item
                }
                    );
            }
            else
            {
                List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy(
                    item => new
                {
                    item.EmployeeID,
                    item.BranchID,
                    item.CustomerID,
                    item.CustomerLocationID,
                    item.TaxZoneID,
                    item.TaxCalcMode
                },
                    (key, item) => new Receipts
                {
                    employee         = key.EmployeeID,
                    branch           = key.BranchID,
                    customer         = key.CustomerID,
                    customerLocation = key.CustomerLocationID,
                    details          = item
                }
                    );
            }

            foreach (Receipts item in List)
            {
                isError        = false;
                notAllApproved = false;
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>();
                    expenseClaimEntry.SelectTimeStamp();
                    EPExpenseClaim expenseClaim = (EPExpenseClaim)expenseClaimEntry.ExpenseClaim.Cache.CreateInstance();
                    expenseClaim.EmployeeID         = item.employee;
                    expenseClaim.BranchID           = item.branch;
                    expenseClaim.CustomerID         = item.customer;
                    expenseClaim.DocDesc            = EP.Messages.SubmittedReceipt;
                    expenseClaim                    = expenseClaimEntry.ExpenseClaim.Update(expenseClaim);
                    expenseClaim.CustomerLocationID = item.customerLocation;
                    expenseClaim.TaxCalcMode        = item.details.First().TaxCalcMode;
                    expenseClaim.TaxZoneID          = item.details.First().TaxZoneID;

                    foreach (EPExpenseClaimDetails detail in item.details)
                    {
                        PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(detail);

                        if (detail.Approved ?? false)
                        {
                            try
                            {
                                if (detail.TipAmt != 0 && epsetup.Current.NonTaxableTipItem == null)
                                {
                                    PXProcessing <EPExpenseClaimDetails> .SetError(Messages.TipItemIsNotDefined);

                                    isError = true;
                                }
                                else
                                {
                                    EPClaimReceiptController.SubmitReceipt(expenseClaimEntry.ExpenseClaim.Cache,
                                                                           expenseClaimEntry.ExpenseClaimDetails.Cache, expenseClaimEntry.ExpenseClaim.Current, detail);

                                    PXProcessing <EPExpenseClaimDetails> .SetProcessed();
                                }


                                expenseClaimEntry.Save.Press();
                                if (!result.ContainsKey(expenseClaim.RefNbr))
                                {
                                    result.Add(expenseClaim.RefNbr, expenseClaim);
                                }
                                detail.RefNbr = expenseClaim.RefNbr;
                            }
                            catch (Exception ex)
                            {
                                PXProcessing <EPExpenseClaimDetails> .SetError(ex);

                                isError = true;
                            }
                        }
                        else
                        {
                            PXProcessing.SetError(enabledApprovalReceipt
                                                                ? Messages.ReceiptNotApproved
                                                                : Messages.ReceiptTakenOffHold);
                            notAllApproved = true;
                        }
                    }
                    if (!isError)
                    {
                        ts.Complete();
                    }
                }
            }



            if (!isError && !notAllApproved)
            {
                if (result.Count == 1)
                {
                    ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>();
                    PXRedirectHelper.TryRedirect(expenseClaimEntry, result.First().Value, PXRedirectHelper.WindowMode.InlineWindow);
                }
            }
            else
            {
                PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(null);

                throw new PXException(Messages.ErrorProcessingReceipts);
            }
        }
        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;
            }
        }
        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);
        }
Beispiel #25
0
        public static ItemCost Fetch(PXGraph graph, int?vendorID, int?vendorLocationID, DateTime?docDate, string curyID, int?inventoryID, int?subItemID, int?siteID, string uom, bool onlyVendor)
        {
            InventoryItem     item        = null;
            INItemCost        cost        = null;
            Vendor            vendor      = null;
            POVendorInventory vendorPrice = null;

            foreach (PXResult <InventoryItem, INItemCost, Vendor, POVendorInventory> r in
                     PXSelectJoin <InventoryItem,
                                   LeftJoin <INItemCost, On <INItemCost.inventoryID, Equal <InventoryItem.inventoryID> >,
                                             LeftJoin <Vendor,
                                                       On <Vendor.bAccountID, Equal <Required <Vendor.bAccountID> > >,
                                                       LeftJoin <POVendorInventory,
                                                                 On <POVendorInventory.inventoryID, Equal <InventoryItem.inventoryID>,
                                                                     And <POVendorInventory.active, Equal <boolTrue>,
                                                                          And <POVendorInventory.vendorID, Equal <Vendor.bAccountID>,
                                                                               And2 <Where <POVendorInventory.subItemID, Equal <Required <POVendorInventory.subItemID> >,
                                                                                            Or <POVendorInventory.subItemID, Equal <InventoryItem.defaultSubItemID>,
                                                                                                Or <POVendorInventory.subItemID, IsNull,
                                                                                                    Or <Where <Required <POVendorInventory.subItemID>, IsNull,
                                                                                                               And <POVendorInventory.subItemID, Equal <True> > > > > > >,

                                                                                     And2 <Where <POVendorInventory.purchaseUnit, Equal <Required <POVendorInventory.purchaseUnit> >,
                                                                                                  Or <POVendorInventory.purchaseUnit, Equal <InventoryItem.purchaseUnit> > >,
                                                                                           And <Where <POVendorInventory.vendorLocationID, Equal <Required <POVendorInventory.vendorLocationID> >,
                                                                                                       Or <POVendorInventory.vendorLocationID, IsNull> > > > > > > > > > >,
                                   Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > >,
                                   OrderBy <
                                       Asc <Switch <Case <Where <POVendorInventory.purchaseUnit, Equal <InventoryItem.purchaseUnit> >, boolTrue>, boolFalse>,
                                            Asc <Switch <Case <Where <POVendorInventory.subItemID, Equal <InventoryItem.defaultSubItemID> >, boolTrue>, boolFalse>,
                                                 Asc <Switch <Case <Where <POVendorInventory.vendorLocationID, IsNull>, boolTrue>, boolFalse>,
                                                      Asc <InventoryItem.inventoryCD> > > > > >
                     .Select(graph, vendorID, subItemID, subItemID, uom, vendorLocationID, inventoryID))
            {
                item        = r;
                cost        = r;
                vendor      = r;
                vendorPrice = r;
                if (vendorPrice != null)
                {
                    break;
                }
            }
            if (vendorPrice != null && vendorPrice.VendorID != null)
            {
                Decimal?price =
                    (docDate != null && docDate >= vendorPrice.EffDate && vendorPrice.EffPrice > 0)
                                        ? vendorPrice.EffPrice
                                        : vendorPrice.LastPrice;
                string purchaseUnit = vendorPrice.PurchaseUnit ?? item.PurchaseUnit;

                if (price == 0)
                {
                    price = null;
                }

                if (price != null)
                {
                    Company company = new PXSetup <Company>(graph).Current;
                    if (vendorPrice.CuryID == company.BaseCuryID || vendorPrice.CuryID == null)
                    {
                        return(new ItemCost(item, purchaseUnit, price.Value));
                    }
                    try
                    {
                        Decimal basePrice;
                        PXCurrencyAttribute.CuryConvBase(graph.Caches[typeof(CurrencyInfo)], GetCurrencyInfo(graph, vendor.CuryRateTypeID, vendorPrice.CuryID), price.Value, out basePrice, true);
                        return(new ItemCost(item, purchaseUnit, vendorPrice.CuryID, price.Value, basePrice));
                    }
                    catch
                    {
                        return(new ItemCost(item, purchaseUnit, 0));
                    }
                }
            }

            return
                (FetchHistoryLastCost(graph, vendorID, vendorLocationID, inventoryID, subItemID) ??
                 (onlyVendor ? null : FetchLastCost(graph, item, docDate)) ??
                 (onlyVendor ? null : FetchSiteLastCost(graph, item, cost, siteID)) ??
                 new ItemCost(item, 0));
        }
        protected virtual bool?GetCreditCheckError(PXCache sender, object Row)
        {
            ARSetup arsetup = PXSetup <ARSetup> .Select(sender.Graph);

            return(arsetup?.CreditCheckError);
        }
Beispiel #27
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;
            }
        }
Beispiel #28
0
        private static void ClaimDetail(List <EPExpenseClaimDetails> details)
        {
            PXSetup <EPSetup> epsetup   = new PXSetup <EPSetup>(PXGraph.CreateInstance(typeof(ExpenseClaimDetailEntry)));
            bool enabledApprovalReceipt = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null;
            bool isError        = false;
            bool notAllApproved = false;
            bool emptyClaim     = true;
            var  List           = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy(
                item => new { item.EmployeeID, item.BranchID, item.CustomerID, item.CustomerLocationID }
                , (key, item) => new { employee = key.EmployeeID, branch = key.BranchID, customer = key.CustomerID, customerLocation = key.CustomerLocationID, details = item }
                );

            List <EPExpenseClaim> result = new List <EPExpenseClaim>();

            foreach (var item in List)
            {
                isError        = false;
                notAllApproved = false;
                emptyClaim     = true;
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>();
                    EPExpenseClaim    expenseClaim      = (EPExpenseClaim)expenseClaimEntry.ExpenseClaim.Cache.CreateInstance();
                    expenseClaim.EmployeeID         = item.employee;
                    expenseClaim.BranchID           = item.branch;
                    expenseClaim.CustomerID         = item.customer;
                    expenseClaim.DocDesc            = EP.Messages.SubmittedReceipt;
                    expenseClaim                    = expenseClaimEntry.ExpenseClaim.Update(expenseClaim);
                    expenseClaim.CustomerLocationID = item.customerLocation;

                    foreach (EPExpenseClaimDetails detail in item.details)
                    {
                        PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(detail);

                        if (detail.Approved ?? false)
                        {
                            try
                            {
                                expenseClaimEntry.SubmitDetail(detail);
                                PXProcessing <EPExpenseClaimDetails> .SetProcessed();

                                emptyClaim = false;
                            }
                            catch (Exception ex)
                            {
                                PXProcessing <EPExpenseClaimDetails> .SetError(ex);

                                isError = true;
                            }
                        }
                        else
                        {
                            PXProcessing.SetError(enabledApprovalReceipt
                                ? Messages.ReceiptNotApproved
                                : Messages.ReceiptTakenOffHold);
                            notAllApproved = true;
                        }
                    }

                    if (!emptyClaim)
                    {
                        try
                        {
                            expenseClaimEntry.Actions.PressSave();
                            result.Add(expenseClaim);
                        }
                        catch (Exception ex)
                        {
                            foreach (EPExpenseClaimDetails detail in item.details)
                            {
                                PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(detail);

                                PXProcessing <EPExpenseClaimDetails> .SetError(ex);
                            }
                            isError = true;
                        }
                    }
                    if (!isError)
                    {
                        ts.Complete();
                    }
                }
            }

            if (!isError && !notAllApproved)
            {
                if (result.Count == 1)
                {
                    ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>();
                    PXRedirectHelper.TryRedirect(expenseClaimEntry, result[0], PXRedirectHelper.WindowMode.InlineWindow);
                }
            }
            else
            {
                PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(null);

                throw new PXException(Messages.ErrorProcessingReceipts);
            }
        }
        protected virtual bool?IsMigrationMode(PXCache sender)
        {
            ARSetup arsetup = PXSetup <ARSetup> .Select(sender.Graph);

            return(arsetup?.MigrationMode);
        }