private TimeZoneInfo.AdjustmentRule Initialize(DefinitionParameters parameter)
            {
                DaylightShift row  = null;
                var           id   = parameter.Id;
                var           year = parameter.Year;

                using (new PXConnectionScope())
                    using (PXDataRecord rec = PXDatabase.SelectSingle <DaylightShift>
                                              (
                               new PXDataField(typeof(DaylightShift.fromDate).Name),
                               new PXDataField(typeof(DaylightShift.toDate).Name),
                               new PXDataField(typeof(DaylightShift.shift).Name),
                               new PXDataFieldValue(typeof(DaylightShift.isActive).Name, PXDbType.Bit, 1),
                               new PXDataFieldValue(typeof(DaylightShift.year).Name, PXDbType.Int, year),
                               new PXDataFieldValue(typeof(DaylightShift.timeZone).Name, PXDbType.VarChar, id)
                                              ))
                    {
                        if (rec != null)
                        {
                            row          = new DaylightShift();
                            row.IsActive = true;
                            row.Year     = year;
                            row.TimeZone = id;
                            row.FromDate = rec.GetDateTime(0);
                            row.ToDate   = rec.GetDateTime(1);
                            row.Shift    = rec.GetInt32(2);
                        }
                    }

                if (row == null || string.IsNullOrEmpty(row.TimeZone))
                {
                    return(_systemProvider.FindTimeRegionByTimeZone(id).With(_ => _.GetAdjustmentRule(year)));
                }

                var start     = new DateTime(year, 1, 1);
                var end       = new DateTime(year, 12, 31);
                var delta     = TimeSpan.FromMinutes(row.Shift ?? 0);
                var tranStart = GetTransitionTime((DateTime)row.FromDate);
                var tranEnd   = GetTransitionTime((DateTime)row.ToDate);

                return(TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(start, end, delta, tranStart, tranEnd));
            }
Ejemplo n.º 2
0
            public void Prefetch(PXDatabaseUSProvider provider)
            {
                PXDataRecord record = PXDatabase.SelectSingle <USSetup>(new PXDataField <USSetup.enableInAP>(), new PXDataField <USSetup.simpleNumberingID>());

                if (record == null)
                {
                    _featureActive = false;
                }
                else
                {
                    if (record.GetBoolean(0) ?? false)
                    {
                        _featureActive = true;
                    }
                    else
                    {
                        _featureActive = false;
                    }
                }
            }
Ejemplo n.º 3
0
        protected virtual void _(Events.RowPersisted <ARInvoice> e)
        {
            bool insert = e.Operation == PXDBOperation.Insert;
            bool delete = e.Operation == PXDBOperation.Delete;

            if ((insert || delete) && e.TranStatus == PXTranStatus.Open &&
                (e.Row.IsCorrection == true || e.Row.IsCancellation == true) && e.Row.OrigDocType != null && e.Row.OrigRefNbr != null &&
                !this.CancellationInvoiceCreationOnRelease)
            {
                bool updatedOriginal = PXDatabase.Update <ARRegister>(
                    new PXDataFieldAssign <ARRegister.isUnderCorrection>(PXDbType.Bit, insert),
                    new PXDataFieldRestrict <ARRegister.docType>(PXDbType.Char, e.Row.OrigDocType),
                    new PXDataFieldRestrict <ARRegister.refNbr>(PXDbType.NVarChar, e.Row.OrigRefNbr),
                    new PXDataFieldRestrict <ARRegister.isUnderCorrection>(PXDbType.Bit, !insert));
                if (!updatedOriginal)
                {
                    throw new PXLockViolationException(typeof(ARInvoice), PXDBOperation.Update, new[] { e.Row.OrigDocType, e.Row.OrigRefNbr });
                }
            }
        }
        protected IEnumerable clearLog(PXAdapter adapter)
        {
            EMailAccountSyncFilter filter  = Filter.Current;
            EMailSyncAccount       account = SelectedItems.Current;

            if (filter == null || account == null)
            {
                return(adapter.Get());
            }


            PXDatabase.Delete <EMailSyncLog>(
                new PXDataFieldRestrict <EMailSyncLog.address>(account.Address),
                new PXDataFieldRestrict <EMailSyncLog.serverID>(account.ServerID));

            OperationLog.View.RequestRefresh();
            OperationLog.View.Clear();

            return(adapter.Get());
        }
            public void Prefetch()
            {
                attributes.Clear();

                foreach (PXDataRecord rec in PXDatabase.SelectMulti <CSAttributeGroup>(
                             new PXDataField <CSAttributeGroup.attributeID>(),
                             new PXDataField <CSAttributeGroup.entityType>(),
                             new PXDataField <CSAttributeGroup.entityClassID>()))
                {
                    if (rec.GetString(1) == KCConstants.InventoryItemEntityType)
                    {
                        AttributeDTO attribute = new AttributeDTO
                        {
                            AttributeId = rec.GetString(0),
                            ItemClassId = int.Parse(rec.GetString(2))
                        };
                        attributes.Add(attribute);
                    }
                }
            }
    /// <summary>
    /// The tlbPath callback event handler.
    /// </summary>
    protected void tlbPath_CallBack(object sender, PXCallBackEventArgs e)
    {
        if (e.Command.Name == "AddFav" && PXSiteMap.CurrentNode != null)
        {
            Guid nodeID = PXSiteMap.CurrentNode.NodeID;
            if (!IsInFavorites(nodeID))
            {
                AddFavorite(screenTitle, nodeID);
            }
            else
            {
                PXDatabase.Delete <Favorite>(
                    new PXDataFieldRestrict("UserID", PXAccess.GetUserID()),
                    new PXDataFieldRestrict("SiteMapID", nodeID)
                    );
            }
            PXContext.Session.FavoritesExists["FavoritesExists"] = null;
            PXSiteMap.FavoritesProvider.Clear();

            // check if favorites exists
            using (PXDataRecord exist = PXDatabase.SelectSingle <Favorite>(
                       new PXDataField("UserID"), new PXDataFieldValue("UserID", PXAccess.GetUserID())))
            {
                e.Result = (exist == null) ? "0" : "1";
            }
        }
        else if (e.Command.Name == "ClearFilter")
        {
            var ds = PXPage.GetDefaultDataSource(this.Page);
            if (ds != null)
            {
                var action = ds.DataGraph.Actions[clearFilterCommand];
                if (action != null)
                {
                    action.Press();
                }
            }
            PXCallbackManager.RegisterJavaScript(
                "if (window['__px_alls'] && __px_alls(this) && __px_alls(this)['tlbPath'])__px_alls(this)['tlbPath'].items['clearFilter'].setVisible(false);");
        }
    }
        protected IEnumerable resetWarning(PXAdapter adapter)
        {
            EMailAccountSyncFilter filter  = Filter.Current;
            EMailSyncAccount       account = SelectedItems.Current;

            if (filter == null || account == null)
            {
                return(adapter.Get());
            }


            PXDatabase.Update <EMailSyncAccount>(
                new PXDataFieldAssign <EMailSyncAccount.hasErrors>(false),
                new PXDataFieldRestrict <EMailSyncAccount.serverID>(account.ServerID),
                new PXDataFieldRestrict <EMailSyncAccount.employeeID>(account.EmployeeID));

            SelectedItems.View.RequestRefresh();
            SelectedItems.View.Clear();

            return(adapter.Get());
        }
Ejemplo n.º 8
0
            public void Prefetch()
            {
                EntitiesInUse.Clear();

                using (new PXConnectionScope())
                {
                    PXDataField[] fields = GetCacheKeys <Table>().Select(key => new PXDataField(key)).ToArray();

                    foreach (PXDataRecord record in PXDatabase.SelectMulti <Table>(fields))
                    {
                        var keys = new object[record.FieldCount];

                        for (var i = 0; i < keys.Length; i++)
                        {
                            keys[i] = record.GetValue(i);
                        }

                        EntitiesInUse.Add(GetHash <Table>(keys));
                    }
                }
            }
        public override void Persist()
        {
            using (var ts = new PXTransactionScope())
            {
                foreach (INSite record in site.Cache.Deleted)
                {
                    PXDatabase.Delete <INSiteStatus>(
                        new PXDataFieldRestrict <INSiteStatus.siteID>(PXDbType.Int, 4, record.SiteID, PXComp.EQ),
                        new PXDataFieldRestrict <INSiteStatus.qtyOnHand>(PXDbType.Decimal, 8, 0m, PXComp.EQ),
                        new PXDataFieldRestrict <INSiteStatus.qtyAvail>(PXDbType.Decimal, 8, 0m, PXComp.EQ));

                    PXDatabase.Delete <INLocationStatus>(
                        new PXDataFieldRestrict <INLocationStatus.siteID>(PXDbType.Int, 4, record.SiteID, PXComp.EQ),
                        new PXDataFieldRestrict <INLocationStatus.qtyOnHand>(PXDbType.Decimal, 8, 0m, PXComp.EQ),
                        new PXDataFieldRestrict <INLocationStatus.qtyAvail>(PXDbType.Decimal, 8, 0m, PXComp.EQ));

                    PXDatabase.Delete <INLotSerialStatus>(
                        new PXDataFieldRestrict <INLotSerialStatus.siteID>(PXDbType.Int, 4, record.SiteID, PXComp.EQ),
                        new PXDataFieldRestrict <INLotSerialStatus.qtyOnHand>(PXDbType.Decimal, 8, 0m, PXComp.EQ),
                        new PXDataFieldRestrict <INLotSerialStatus.qtyAvail>(PXDbType.Decimal, 8, 0m, PXComp.EQ));

                    InventoryItem item =
                        PXSelectJoin <InventoryItem,
                                      InnerJoin <INSiteStatus, On <INSiteStatus.inventoryID, Equal <InventoryItem.inventoryID> > >,
                                      Where <INSiteStatus.siteID, Equal <Required <INSiteStatus.siteID> > > >
                        .SelectWindowed(this, 0, 1, record.SiteID);

                    if (item?.InventoryCD != null)
                    {
                        throw new PXRowPersistingException(typeof(INSite.siteCD).Name, record, Messages.SiteUsageDeleted, item.InventoryCD.TrimEnd());
                    }
                }

                ts.Complete();
            }

            base.Persist();
            location.Cache.Clear();
        }
Ejemplo n.º 10
0
        public virtual void CompleteSOLinesAndSplits(ARRegister ardoc, List <PXResult <SOOrderShipment, SOOrder> > orderShipments)
        {
            if (ardoc.IsCancellation == true || ardoc.IsCorrection == true)
            {
                return;
            }

            foreach (PXResult <SOOrderShipment, SOOrder> orderShipment in orderShipments)
            {
                SOOrder     order     = orderShipment;
                SOOrderType orderType = SOOrderType.PK.Find(this, order.OrderType);
                if (orderType.RequireShipping == false)
                {
                    PXDatabase.Update <SOLine>(
                        new PXDataFieldAssign <SOLine.completed>(true),
                        new PXDataFieldRestrict <SOLine.completed>(false),
                        new PXDataFieldRestrict <SOLine.orderType>(PXDbType.VarChar, 2, order.OrderType, PXComp.EQ),
                        new PXDataFieldRestrict <SOLine.orderNbr>(PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ));
                    PXDatabase.Update <SOLineSplit>(
                        new PXDataFieldAssign <SOLineSplit.completed>(true),
                        new PXDataFieldRestrict <SOLineSplit.completed>(false),
                        new PXDataFieldRestrict <SOLineSplit.orderType>(PXDbType.VarChar, 2, order.OrderType, PXComp.EQ),
                        new PXDataFieldRestrict <SOLineSplit.orderNbr>(PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ));
                }
            }
            PXUpdateJoin <
                Set <SOLine.completed, True>,
                SOLine,
                InnerJoin <ARTran, On <ARTran.sOOrderType, Equal <SOLine.orderType>,
                                       And <ARTran.sOOrderNbr, Equal <SOLine.orderNbr>,
                                            And <ARTran.sOOrderLineNbr, Equal <SOLine.lineNbr> > > > >,
                Where <SOLine.lineType, Equal <SOLineType.miscCharge>,
                       And <SOLine.completed, Equal <False>,
                            And <ARTran.tranType, Equal <Required <ARTran.tranType> >,
                                 And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > > >
            .Update(this,
                    ardoc.DocType,
                    ardoc.RefNbr);
        }
Ejemplo n.º 11
0
        protected virtual void _(Events.RowPersisted <ARInvoice> e)
        {
            if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Delete)
            {
                List <PXDataFieldParam> commands = new List <PXDataFieldParam>();

                commands.Add(new PXDataFieldRestrict <PMTran.aRTranType>(PXDbType.Char, 3, e.Row.DocType, PXComp.EQ));
                commands.Add(new PXDataFieldRestrict <PMTran.aRRefNbr>(PXDbType.NChar, 15, e.Row.RefNbr, PXComp.EQ));
                commands.Add(new PXDataFieldAssign(typeof(PMTran.aRTranType).Name, PXDbType.Char, null));
                commands.Add(new PXDataFieldAssign(typeof(PMTran.aRRefNbr).Name, PXDbType.Char, null));
                commands.Add(new PXDataFieldAssign(typeof(PMTran.refLineNbr).Name, PXDbType.Int, null));
                if (e.Row.ProformaExists != true)
                {
                    commands.Add(new PXDataFieldAssign(typeof(PMTran.billed).Name, PXDbType.Bit, false));
                    commands.Add(new PXDataFieldAssign(typeof(PMTran.billedDate).Name, PXDbType.DateTime, null));
                    commands.Add(new PXDataFieldAssign(typeof(PMTran.invoicedQty).Name, PXDbType.Decimal, 0m));
                    commands.Add(new PXDataFieldAssign(typeof(PMTran.invoicedAmount).Name, PXDbType.Decimal, 0m));
                }
                // Acuminator disable once PX1043 SavingChangesInEventHandlers [Reseting the links on document delete - for a large document there can be thousands of records causing timeout on delete if done through PXCache.delete]
                PXDatabase.Update <PMTran>(commands.ToArray());
            }
        }
Ejemplo n.º 12
0
        protected virtual IEnumerable PrepareImport(PXAdapter adapter)
        {
            PXLongOperation.StartOperation(this, () =>
            {
                try
                {
                    // Clear Data
                    PXDatabase.Delete <LUMP3PLImportProcess>(
                        new PXDataFieldRestrict <LUMP3PLImportProcess.createdByID>(Accessinfo.UserID));
                    this.ImportDataList.Cache.Clear();

                    // Load FTP File
                    FTP_Config config   = GetConfig();
                    FTPHelper helper    = new FTPHelper(config);
                    var ftpFileContents = helper.LoadFileStringFromFTP();
                    foreach (var item in ftpFileContents)
                    {
                        var line               = item.Value.Split(';');
                        var model              = this.ImportDataList.Insert((LUMP3PLImportProcess)this.ImportDataList.Cache.CreateInstance());
                        model.WarehouseOrder   = line[0];
                        model.CustomerOrderRef = line[1];
                        model.OrderStatus      = line[2];
                        model.UnitsSent        = int.Parse(string.IsNullOrEmpty(line[3]) ? "0" : line[3]);
                        model.Carrier          = line[4];
                        model.TrackingNumber   = line[5];
                        model.FreightCost      = decimal.Parse(string.IsNullOrEmpty(line[6]) ? "0" : line[6]);
                        model.FreightCurrency  = line[7];
                        model.FtpFileName      = item.Key;
                    }
                    this.Actions.PressSave();
                }
                catch (Exception e)
                {
                    throw new PXOperationCompletedWithErrorException(e.Message, e);
                }
            });
            return(adapter.Get());
        }
Ejemplo n.º 13
0
        public bool PersistGrams(DuplicateDocument document, bool requireRecreate = false)
        {
            if (graph.Caches[document.GetType()].GetStatus(document) == PXEntryStatus.Deleted)
            {
                PXDatabase.Delete <CRGrams>(new PXDataFieldRestrict <CRGrams.entityID>(PXDbType.Int, 4, document.ContactID, PXComp.EQ));

                return(false);
            }

            if (!requireRecreate && GrammSourceUpdated(document))
            {
                return(false);
            }

            PXDatabase.Delete <CRGrams>(new PXDataFieldRestrict <CRGrams.entityID>(PXDbType.Int, 4, document.ContactID, PXComp.EQ));

            foreach (CRGrams gram in DoCreateGramms(document))
            {
                PXDatabase.Insert <CRGrams>(
                    new PXDataFieldAssign(typeof(CRGrams.entityID).Name, PXDbType.Int, 4, document.ContactID),
                    new PXDataFieldAssign(typeof(CRGrams.fieldName).Name, PXDbType.NVarChar, 60, gram.FieldName),
                    new PXDataFieldAssign(typeof(CRGrams.fieldValue).Name, PXDbType.NVarChar, 60, gram.FieldValue),
                    new PXDataFieldAssign(typeof(CRGrams.score).Name, PXDbType.Decimal, 8, gram.Score),
                    new PXDataFieldAssign(typeof(CRGrams.validationType).Name, PXDbType.NVarChar, 2, gram.ValidationType)
                    );
            }

            document.DuplicateStatus         = DuplicateStatusAttribute.NotValidated;
            document.GrammValidationDateTime = PXTimeZoneInfo.Now;

            PXDatabase.Update <Contact>(
                new PXDataFieldAssign <Contact.duplicateStatus>(PXDbType.NVarChar, document.DuplicateStatus),
                new PXDataFieldAssign <Contact.grammValidationDateTime>(PXDbType.DateTime, PXTimeZoneInfo.ConvertTimeToUtc(document.GrammValidationDateTime.Value, LocaleInfo.GetTimeZone())),
                new PXDataFieldRestrict <Contact.contactID>(PXDbType.Int, document.ContactID)
                );

            return(true);
        }
Ejemplo n.º 14
0
        public static bool IsEntityInUse <Table>(params object[] keys)
            where Table : IBqlTable
        {
            if (Attribute.IsDefined(typeof(Table), typeof(EntityInUseDBSlotOnAttribute)))
            {
                var slot = PXDatabase.GetSlot <EntityInUseDefinition <Table> >(typeof(EntityInUseDefinition <Table>).FullName, typeof(Table));
                return(keys.Length != 0
                                        ? slot.EntitiesInUse.Contains(GetHash <Table>(keys))
                                        : slot.EntitiesInUse.Any());
            }
            else
            {
                KeysCollection cacheKeys = GetCacheKeys <Table>();

                if (keys.Length != 0 && cacheKeys.Count() != keys.Length)
                {
                    throw new PXArgumentException(nameof(keys));
                }

                var fields = new PXDataField[cacheKeys.Count * (keys.Length != 0 ? 2 : 1)];

                for (int i = 0; i < cacheKeys.Count; i++)
                {
                    string cacheKey = cacheKeys[i];
                    fields[i] = new PXDataField(cacheKey);

                    if (keys.Length != 0)
                    {
                        fields[cacheKeys.Count + i] = new PXDataFieldValue(cacheKey, keys[i]);
                    }
                }

                using (PXDataRecord record = PXDatabase.SelectSingle <Table>(fields))
                {
                    return(record != null);
                }
            }
        }
Ejemplo n.º 15
0
            public void Prefetch()
            {
                Func <CSAttributeDetail, bool> func = null;

                MultiSelectAttributes = PXDatabase.SelectMulti <CSAttribute>(new PXDataField[] { new PXDataField <CSAttribute.attributeID>(), new PXDataField <CSAttribute.controlType>() }).Where((PXDataRecord r) => {
                    int?num = r.GetInt32(1);
                    return(num.GetValueOrDefault() == 6 & num.HasValue);
                }).Select((PXDataRecord r) => r.GetString(0)).ToList();
                List <CSAttributeDetail> list = (
                    from r in PXDatabase.SelectMulti <CSAttributeDetail>(new PXDataField[] { new PXDataField <CSAttributeDetail.attributeID>(), new PXDataField <CSAttributeDetail.valueID>(), new PXDataField <CSAttributeDetail.sortOrder>() })
                    where MultiSelectAttributes.Contains(r.GetString(0))
                    select new CSAttributeDetail()
                {
                    AttributeID = r.GetString(0),
                    ValueID = r.GetString(1),
                    SortOrder = r.GetInt16(2)
                }).ToList();

                AllValues = new Dictionary <string, Dictionary <string, short> >();
                foreach (string multiSelectAttribute in MultiSelectAttributes)
                {
                    Dictionary <string, short>     strs = new Dictionary <string, short>();
                    List <CSAttributeDetail>       cSAttributeDetails = list;
                    Func <CSAttributeDetail, bool> func1 = func;
                    if (func1 == null)
                    {
                        Func <CSAttributeDetail, bool> attributeID = (CSAttributeDetail a) => a.AttributeID == multiSelectAttribute;
                        Func <CSAttributeDetail, bool> func2       = attributeID;
                        func  = attributeID;
                        func1 = func2;
                    }
                    foreach (CSAttributeDetail cSAttributeDetail in cSAttributeDetails.Where(func1))
                    {
                        strs[cSAttributeDetail.ValueID] = cSAttributeDetail.SortOrder.GetValueOrDefault();
                    }
                    AllValues[multiSelectAttribute] = strs;
                }
            }
Ejemplo n.º 16
0
        protected virtual void INPIDetail_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e)
        {
            INPIDetail d = (INPIDetail)e.NewRow;
            INPIDetail o = (INPIDetail)e.Row;

            if (d == null || o == null)
            {
                return;
            }

            using (PXTransactionScope sc = new PXTransactionScope())
            {
                if (!PXDatabase.Update <INPIDetail>(
                        new PXDataFieldAssign(typeof(INPIDetail.status).Name, PXDbType.VarChar, d.Status),
                        new PXDataFieldAssign(typeof(INPIDetail.physicalQty).Name, PXDbType.Decimal, d.PhysicalQty),
                        new PXDataFieldAssign(typeof(INPIDetail.varQty).Name, PXDbType.Decimal, d.VarQty),
                        new PXDataFieldRestrict(typeof(INPIDetail.pIID).Name, PXDbType.VarChar, d.PIID),
                        new PXDataFieldRestrict(typeof(INPIDetail.lineNbr).Name, PXDbType.Int, d.LineNbr),
                        new PXDataFieldRestrict(typeof(INPIDetail.Tstamp).Name, PXDbType.Timestamp, 8, this.TimeStamp, PXComp.LE)))
                {
                    throw new PXException(ErrorMessages.RecordUpdatedByAnotherProcess, typeof(INPIDetail).Name);
                }

                PXDatabase.Update <INPIHeader>(
                    new PXDataFieldAssign(typeof(INPIHeader.totalPhysicalQty).Name, PXDbType.Decimal, (d.PhysicalQty ?? 0) - (o.PhysicalQty ?? 0))
                {
                    Behavior = PXDataFieldAssign.AssignBehavior.Summarize
                },
                    new PXDataFieldAssign(typeof(INPIHeader.totalVarQty).Name, PXDbType.Decimal, (d.VarQty ?? 0) - (o.VarQty ?? 0))
                {
                    Behavior = PXDataFieldAssign.AssignBehavior.Summarize
                },
                    new PXDataFieldRestrict(typeof(INPIHeader.pIID).Name, PXDbType.VarChar, d.PIID));

                sc.Complete();
            }
        }
Ejemplo n.º 17
0
    /// <summary>
    /// Append node with specified tutle to favorites.
    /// </summary>
    private void AddFavorite(string title, Guid?siteId)
    {
        if (String.IsNullOrEmpty(title) && siteId == null)
        {
            return;
        }

        Guid   folderID = PXSiteMap.RootNode.NodeID;
        string neutralTitle;

        using (PXDataRecord record = PXDatabase.SelectSingle <PX.SM.SiteMap>(new PXDataField("Title"),
                                                                             new PXDataFieldValue("NodeID", siteId)))
        {
            neutralTitle = record.GetString(0);
        }

        if (!string.IsNullOrEmpty(neutralTitle))
        {
            using (PXDataRecord rec_id = PXDatabase.SelectSingle <Favorite>(
                       new PXDataField("Max(Position)+1"),
                       new PXDataFieldValue("UserID", PXAccess.GetUserID())))
            {
                int pos = 1;
                if (rec_id != null)
                {
                    pos = rec_id.GetInt32(0) ?? 1;
                }
                PXDatabase.Insert <Favorite>(
                    new PXDataFieldAssign("UserID", PXAccess.GetUserID()),
                    new PXDataFieldAssign("NodeID", Guid.NewGuid()),
                    new PXDataFieldAssign("Title", neutralTitle),
                    new PXDataFieldAssign("ParentID", folderID),
                    new PXDataFieldAssign("Position", pos),
                    new PXDataFieldAssign("SiteMapID", siteId));
            }
        }
    }
Ejemplo n.º 18
0
        protected virtual IEnumerable LoadData(PXAdapter adapter)
        {
            var filter     = this.Filter.Current;
            var sourceData = SelectFrom <vPACAdjCost> .Where <vPACAdjCost.finPeriodID.IsEqual <P.AsString> > .View.Select(this, filter.FinPeriod).RowCast <vPACAdjCost>().ToList().Where(x => x.FinPeriodID == filter.FinPeriod);

            // Delete temp table data
            PXDatabase.Delete <LUMPacAdjCost>();
            this.ImportPACList.Cache.Clear();

            foreach (var item in sourceData)
            {
                var data = this.ImportPACList.Insert((LUMPacAdjCost)this.ImportPACList.Cache.CreateInstance());
                data.FinPeriodID    = item.FinPeriodID;
                data.Finptdcogs     = item.Finptdcogs;
                data.FinPtdQtySales = item.FinPtdQtySales;
                data.PACUnitCost    = item.PACUnitCost;
                data.InventoryID    = item.InventoryID;
                data.Paccogs        = item.Paccogs;
                data.Siteid         = item.Siteid;
                data.Cogsadj        = item.Cogsadj;
            }
            this.Actions.PressSave();
            return(adapter.Get());
        }
Ejemplo n.º 19
0
        public IEnumerable requestValidation(PXAdapter adapter)
        {
            foreach (FeaturesSet feature in adapter.Get())
            {
                if (feature.Status == 3)
                {
                    FeaturesSet update = PXCache <FeaturesSet> .CreateCopy(feature);

                    update.Status = 0;
                    update        = this.Features.Update(update);
                    this.Features.Delete(feature);

                    if (update.Status != 1)
                    {
                        this.Features.Delete(new FeaturesSet()
                        {
                            Status = 1
                        });
                    }


                    this.Persist();
                    yield return(update);
                }
                else
                {
                    yield return(feature);
                }
            }

            PXDatabase.ResetSlots();
            PXPageCacheUtils.InvalidateCachedPages();
            this.Clear();

            throw new PXRedirectToUrlException(@"~\Main.aspx$target=_top", PXBaseRedirectException.WindowMode.Same, Messages.RefreshSettings);
        }
Ejemplo n.º 20
0
        public static void ReleasePayments(List <APPayment> list, string Action)
        {
            APReleaseChecks releaseChecksGraph = CreateInstance <APReleaseChecks>();
            APPaymentEntry  pe        = CreateInstance <APPaymentEntry>();
            CABatchEntry    be        = CreateInstance <CABatchEntry>();
            bool            failed    = false;
            bool            successed = false;

            List <APRegister> docs = new List <APRegister>(list.Count);

            foreach (APPayment payment in list)
            {
                if (payment.Passed == true)
                {
                    releaseChecksGraph.TimeStamp = pe.TimeStamp = payment.tstamp;
                }

                switch (Action)
                {
                case ReleaseChecksFilter.action.ReleaseChecks:
                    payment.Printed = true;
                    break;

                case ReleaseChecksFilter.action.ReprintChecks:
                case ReleaseChecksFilter.action.VoidAndReprintChecks:
                    payment.ExtRefNbr = null;
                    payment.Printed   = false;
                    break;

                default:
                    continue;
                }

                PXProcessing <APPayment> .SetCurrentItem(payment);

                if (Action == ReleaseChecksFilter.action.ReleaseChecks)
                {
                    try
                    {
                        pe.Document.Current = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        if (pe.Document.Current?.ExtRefNbr != payment.ExtRefNbr)
                        {
                            APPayment payment_copy = PXCache <APPayment> .CreateCopy(pe.Document.Current);

                            payment_copy.ExtRefNbr = payment.ExtRefNbr;
                            pe.Document.Update(payment_copy);
                        }

                        if (PaymentRefAttribute.PaymentRefMustBeUnique(pe.paymenttype.Current) && string.IsNullOrEmpty(payment.ExtRefNbr))
                        {
                            throw new PXException(ErrorMessages.FieldIsEmpty, typeof(APPayment.extRefNbr).Name);
                        }

                        payment.IsReleaseCheckProcess = true;

                        APPrintChecks.AssignNumbersWithNoAdditionalProcessing(pe, payment);
                        pe.Save.Press();

                        object[] persisted = PXTimeStampScope.GetPersisted(pe.Document.Cache, pe.Document.Current);
                        if (persisted == null || persisted.Length == 0)
                        {
                            //preserve timestamp which will be @@dbts after last record committed to db on previous Persist().
                            //otherwise another process updated APAdjust.
                            docs.Add(payment);
                        }
                        else
                        {
                            if (payment.Passed == true)
                            {
                                pe.Document.Current.Passed = true;
                            }
                            docs.Add(pe.Document.Current);
                        }
                        successed = true;
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);

                        docs.Add(null);
                        failed = true;
                    }
                }

                if (Action == ReleaseChecksFilter.action.ReprintChecks || Action == ReleaseChecksFilter.action.VoidAndReprintChecks)
                {
                    try
                    {
                        payment.IsPrintingProcess = true;
                        using (PXTransactionScope transactionScope = new PXTransactionScope())
                        {
                            #region Update CABatch if ReprintChecks
                            CABatch caBatch = PXSelectJoin <CABatch,
                                                            InnerJoin <CABatchDetail, On <CABatch.batchNbr, Equal <CABatchDetail.batchNbr> > >,
                                                            Where <CABatchDetail.origModule, Equal <Required <APPayment.origModule> >,
                                                                   And <CABatchDetail.origDocType, Equal <Required <APPayment.docType> >,
                                                                        And <CABatchDetail.origRefNbr, Equal <Required <APPayment.refNbr> > > > > > .
                                              Select(be, payment.OrigModule, payment.DocType, payment.RefNbr);

                            if (caBatch != null)
                            {
                                be.Document.Current = caBatch;
                                int           DetailCount = be.Details.Select().Count;                       // load
                                CABatchDetail detail      = be.Details.Locate(new CABatchDetail()
                                {
                                    BatchNbr    = be.Document.Current.BatchNbr,
                                    OrigModule  = payment.OrigModule,
                                    OrigDocType = payment.DocType,
                                    OrigRefNbr  = payment.RefNbr,
                                    OrigLineNbr = CABatchDetail.origLineNbr.DefaultValue,
                                });
                                if (detail != null)
                                {
                                    // payment.Status is recalculated in CABatchEntry.Delete
                                    if (DetailCount == 1)
                                    {
                                        be.Document.Delete(be.Document.Current);                                         // Details will delete by PXParent
                                    }
                                    else
                                    {
                                        be.Details.Delete(detail);                                          // recalculated batch totals
                                    }
                                }
                                be.Save.Press();
                            }
                            else
                            {
                                PXCache cacheAPPayment = releaseChecksGraph.APPaymentList.Cache;

                                cacheAPPayment.SetValueExt <APPayment.printed>(payment, false);
                                cacheAPPayment.SetValueExt <APPayment.hold>(payment, false);
                                cacheAPPayment.SetValueExt <APPayment.extRefNbr>(payment, null);
                                // APPayment.Status is recalculated by SetStatusCheckAttribute
                                cacheAPPayment.MarkUpdated(payment);

                                cacheAPPayment.PersistUpdated(payment);
                                cacheAPPayment.Persisted(false);
                            }
                            #endregion
                            // TODO: Need to rework. Use legal CRUD methods of caches!
                            releaseChecksGraph.TimeStamp = PXDatabase.SelectTimeStamp();

                            // delete check numbers only if Reprint (not Void and Reprint)
                            PaymentMethod pm = pe.paymenttype.Select(payment.PaymentMethodID);
                            if (pm.APPrintChecks == true && Action == ReleaseChecksFilter.action.ReprintChecks)
                            {
                                APPayment doc = payment;
                                new HashSet <string>(pe.Adjustments_Raw.Select(doc.DocType, doc.RefNbr)
                                                     .RowCast <APAdjust>()
                                                     .Select(adj => adj.StubNbr))
                                .ForEach(nbr => PaymentRefAttribute.DeleteCheck((int)doc.CashAccountID, doc.PaymentMethodID, nbr));

                                // sync PaymentMethodAccount.APLastRefNbr with actual last CashAccountCheck number
                                PaymentMethodAccount det = releaseChecksGraph.cashaccountdetail.SelectSingle(payment.CashAccountID, payment.PaymentMethodID);
                                PaymentRefAttribute.LastCashAccountCheckSelect.Clear(releaseChecksGraph);
                                CashAccountCheck cacheck = PaymentRefAttribute.LastCashAccountCheckSelect.SelectSingleBound(releaseChecksGraph, new object[] { det });
                                det.APLastRefNbr = cacheck?.CheckNbr;
                                releaseChecksGraph.cashaccountdetail.Cache.PersistUpdated(det);
                                releaseChecksGraph.cashaccountdetail.Cache.Persisted(false);
                            }
                            // END TODO
                            if (string.IsNullOrEmpty(payment.ExtRefNbr))
                            {
                                //try to get next number
                                releaseChecksGraph.APPaymentList.Cache.SetDefaultExt <APPayment.extRefNbr>(payment);
                            }
                            transactionScope.Complete();
                        }
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);
                    }
                    docs.Add(null);
                }
            }
            if (successed)
            {
                APDocumentRelease.ReleaseDoc(docs, true);
            }

            if (failed)
            {
                throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased);
            }
        }
        public virtual IEnumerable <Data.EP.ActivityService.IActivityType> GetActivityTypes()
        {
            ActivityTypeDeinition def = PXDatabase.GetSlot <ActivityTypeDeinition>(typeof(EPActivityType).Name, typeof(EPActivityType));

            return(def.List);
        }
Ejemplo n.º 22
0
 private static ItemCategoriesDefinition GetSlot()
 {
     //Returns or initializes a new instance of ItemCategoriesDefinition. System will automatically invalidate and Prefetch again if INCategory or INItemCategory tables are updated.
     return(PXDatabase.GetSlot <ItemCategoriesDefinition>("ItemCategories", typeof(INCategory), typeof(INItemCategory)));
 }
 protected override void ResetSlot(string slotName)
 {
     PXDatabase.ResetSlot <WizardDefinition>(slotName + Thread.CurrentThread.CurrentUICulture.Name, Tables);
 }
 protected override Definition GetSlot(string slotName)
 {
     return(PXDatabase.GetSlot <WizardDefinition, PXWizardSiteMapProvider>(slotName + Thread.CurrentThread.CurrentUICulture.Name, this, Tables));
 }
Ejemplo n.º 25
0
 public override void ClearDependencies()
 {
     PXDatabase.SelectTimeStamp();
     PXPageCacheUtils.InvalidateCachedPages();
 }
Ejemplo n.º 26
0
        public override void UpdateDatabase()
        {
            ProjectList graph = PXGraph.CreateInstance <ProjectList>();

            try
            {
                SOThrottleConstants records = PXSelectReadonly <SOThrottleConstants> .Select(graph);

                if (records != null)
                {
                    PXDatabase.Delete <SOThrottleConstants>();
                }
                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiListOrders),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID)
                    );

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiListOrdersByNextToken),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetOrder),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetListOrderItems),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("10000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiSubmitFeed),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("20000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetFeedSubmissionResult),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("20000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiRequestReport),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("10000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetRequestReportList),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.getGeneratedReportID),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetReport),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("20000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiFeedResultWaiting),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("20000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));
            }
            catch (Exception ex)
            {
                PXTrace.WriteInformation(ex.Message);
            }
        }
Ejemplo n.º 27
0
        public static bool IsExchange(int emailAccountID)
        {
            Definition def = PXDatabase.GetSlot <Definition>("EmailExchangeAccounts", typeof(EMailAccount));

            return(def.Exchanges != null && def.Exchanges.Contains(emailAccountID));
        }
        public override POOrder CalculateExternalTax(POOrder order)
        {
            var  toAddress    = GetToAddress(order);
            bool isNonTaxable = IsNonTaxable(toAddress);

            if (isNonTaxable)
            {
                order.IsTaxValid         = true;
                order.IsUnbilledTaxValid = true;
                ApplyTax(order, GetTaxResult.Empty, GetTaxResult.Empty);

                return(order);
            }

            var service = TaxProviderFactory(Base, order.TaxZoneID);

            GetTaxRequest getRequest         = null;
            GetTaxRequest getRequestUnbilled = null;

            bool isValidByDefault = true;

            if (order.IsTaxValid != true)
            {
                getRequest = BuildGetTaxRequest(order);

                if (getRequest.CartItems.Count > 0)
                {
                    isValidByDefault = false;
                }
                else
                {
                    getRequest = null;
                }
            }

            if (order.IsUnbilledTaxValid != true)
            {
                getRequestUnbilled = BuildGetTaxRequestUnbilled(order);
                if (getRequestUnbilled.CartItems.Count > 0)
                {
                    isValidByDefault = false;
                }
                else
                {
                    getRequestUnbilled = null;
                }
            }

            if (isValidByDefault)
            {
                PXDatabase.Update <POOrder>(
                    new PXDataFieldAssign(nameof(POOrder.IsTaxValid), true),
                    new PXDataFieldAssign(nameof(POOrder.IsUnbilledTaxValid), true),
                    new PXDataFieldRestrict(nameof(POOrder.OrderType), PXDbType.VarChar, 2, order.OrderType, PXComp.EQ),
                    new PXDataFieldRestrict(nameof(POOrder.OrderNbr), PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ)
                    );
                order.IsTaxValid         = true;
                order.IsUnbilledTaxValid = true;
                PXTimeStampScope.PutPersisted(Base.Document.Cache, order, PXDatabase.SelectTimeStamp());
                return(order);
            }

            GetTaxResult result         = null;
            GetTaxResult resultUnbilled = null;

            bool getTaxFailed = false;

            if (getRequest != null)
            {
                result = service.GetTax(getRequest);
                if (!result.IsSuccess)
                {
                    getTaxFailed = true;
                }
            }
            if (getRequestUnbilled != null)
            {
                resultUnbilled = service.GetTax(getRequestUnbilled);
                if (!resultUnbilled.IsSuccess)
                {
                    getTaxFailed = true;
                }
            }

            if (!getTaxFailed)
            {
                try
                {
                    ApplyTax(order, result, resultUnbilled);
                    PXDatabase.Update <POOrder>(
                        new PXDataFieldAssign(nameof(POOrder.IsTaxValid), true),
                        new PXDataFieldAssign(nameof(POOrder.IsUnbilledTaxValid), true),
                        new PXDataFieldRestrict(nameof(POOrder.OrderType), PXDbType.VarChar, 2, order.OrderType, PXComp.EQ),
                        new PXDataFieldRestrict(nameof(POOrder.OrderNbr), PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ)
                        );
                    order.IsTaxValid         = true;
                    order.IsUnbilledTaxValid = true;
                    PXTimeStampScope.PutPersisted(Base.Document.Cache, order, PXDatabase.SelectTimeStamp());
                }
                catch (PXOuterException ex)
                {
                    string msg = TX.Messages.FailedToApplyTaxes;
                    foreach (string err in ex.InnerMessages)
                    {
                        msg += Environment.NewLine + err;
                    }

                    throw new PXException(ex, msg);
                }
                catch (Exception ex)
                {
                    string msg = TX.Messages.FailedToApplyTaxes;
                    msg += Environment.NewLine + ex.Message;

                    throw new PXException(ex, msg);
                }
            }
            else
            {
                ResultBase taxResult = result ?? resultUnbilled;
                if (taxResult != null)
                {
                    LogMessages(taxResult);
                }

                throw new PXException(TX.Messages.FailedToGetTaxes);
            }

            return(order);
        }
 public static bool IsEnabled()
 {
     return(PXDatabase.GetSlot <EntityRestrictionDefinition>(typeof(EntityRestrictionDefinition).Name, typeof(PreferencesSecurity)).Enabled);
 }
Ejemplo n.º 30
0
        private static void Validate(CATranEntryLight te, CashAccount tlist)
        {
            using (new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    Account account = PXSelect <Account, Where <Account.isCashAccount, Equal <False>,
                                                                And <Account.accountID, Equal <Required <Account.accountID> > > > > .Select(te, tlist.AccountID);

                    if (account != null)
                    {
                        account.IsCashAccount = true;
                        te.account.Update(account);
                        te.account.Cache.Persist(PXDBOperation.Update);
                        te.account.Cache.Persisted(false);
                    }
                    ts.Complete(te);
                }
            }
            te.Clear();

            if (tlist.Reconcile != true)
            {
                te.Clear();
                using (new PXConnectionScope())
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        PXCache adjcache = te.Caches[typeof(CATran)];
                        foreach (CATran catran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> > > > .Select(te, tlist.CashAccountID))
                        {
                            if (tlist.Reconcile != true && (catran.Cleared != true || catran.TranDate == null))
                            {
                                catran.Cleared   = true;
                                catran.ClearDate = catran.TranDate;
                            }
                            te.catrancache.Update(catran);
                        }
                        te.catrancache.Persist(PXDBOperation.Update);
                        ts.Complete(te);
                    }
                    te.catrancache.Persisted(false);
                }
            }

            te.Clear();

            using (new PXConnectionScope())
            {
                PXCache adjcache = te.Caches[typeof(CAAdj)];

                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (PXResult <CAAdj, CATran> res in PXSelectJoin <CAAdj, LeftJoin <CATran, On <CATran.tranID, Equal <CAAdj.tranID> >,
                                                                                            LeftJoin <GLTranDoc, On <GLTranDoc.refNbr, Equal <CAAdj.adjRefNbr>, And <GLTranDoc.tranType, Equal <CAAdj.adjTranType>, And <GLTranDoc.tranModule, Equal <BatchModule.moduleCA> > > > > >,
                                                                           Where <CAAdj.cashAccountID, Equal <Required <CAAdj.cashAccountID> >, And <CATran.tranID, IsNull, And <GLTranDoc.refNbr, IsNull> > > > .Select(te, tlist.CashAccountID))
                    {
                        CAAdj caadj = (CAAdj)res;

                        GLTran gltran = PXSelectJoin <GLTran, InnerJoin <CashAccount,
                                                                         On <CashAccount.accountID, Equal <GLTran.accountID>,
                                                                             And <CashAccount.subID, Equal <GLTran.subID>,
                                                                                  And <CashAccount.branchID, Equal <GLTran.branchID> > > > >,
                                                      Where <GLTran.cATranID, Equal <Required <CAAdj.tranID> >,
                                                             And <CashAccount.cashAccountID, Equal <Required <CAAdj.cashAccountID> > > > > .Select(te, caadj.TranID, caadj.CashAccountID);

                        adjcache.SetValue <CAAdj.tranID>(caadj, null);
                        adjcache.SetValue <CAAdj.cleared>(caadj, false);

                        CATran catran = AdjCashTranIDAttribute.DefaultValues <CAAdj.tranID>(adjcache, caadj);
                        catran.BatchNbr = gltran?.BatchNbr;

                        long?id = null;

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            te.SelectTimeStamp();

                            adjcache.SetValue <CAAdj.tranID>(caadj, id);
                            adjcache.Update(caadj);
                        }

                        if (id.HasValue && gltran?.TranID != null)
                        {
                            gltran.CATranID = id;
                            te.gltrancache.Update(gltran);
                            te.gltrancache.Persist(PXDBOperation.Update);
                        }
                    }

                    adjcache.Persist(PXDBOperation.Update);

                    ts.Complete(te);
                }

                adjcache.Persisted(false);
                te.catrancache.Persisted(false);
                te.gltrancache.Persisted(false);
            }

            te.Clear();

            using (new PXConnectionScope())
            {
                PXCache transfercache = te.Caches[typeof(CATransfer)];

                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (PXResult <CATransfer, CATran> res in PXSelectJoin <CATransfer, LeftJoin <CATran, On <CATran.tranID, Equal <CATransfer.tranIDIn> > >, Where <CATransfer.inAccountID, Equal <Required <CATransfer.inAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID))
                    {
                        CATransfer catransfer = (CATransfer)res;

                        transfercache.SetValue <CATransfer.tranIDIn>(catransfer, null);
                        transfercache.SetValue <CATransfer.clearedIn>(catransfer, false);
                        if (transfercache.GetValue <CATransfer.clearedOut>(catransfer) == null)
                        {
                            transfercache.SetValue <CATransfer.clearedOut>(catransfer, false);
                        }

                        CATran catran = TransferCashTranIDAttribute.DefaultValues <CATransfer.tranIDIn>(transfercache, catransfer);

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            transfercache.SetValue <CATransfer.tranIDIn>(catransfer, id);
                            transfercache.Update(catransfer);
                        }
                    }

                    foreach (PXResult <CATransfer, CATran> res in PXSelectJoin <CATransfer, LeftJoin <CATran, On <CATran.tranID, Equal <CATransfer.tranIDOut> > >, Where <CATransfer.outAccountID, Equal <Required <CATransfer.outAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID))
                    {
                        CATransfer catransfer = (CATransfer)res;

                        transfercache.SetValue <CATransfer.tranIDOut>(catransfer, null);
                        transfercache.SetValue <CATransfer.clearedOut>(catransfer, false);
                        if (transfercache.GetValue <CATransfer.clearedIn>(catransfer) == null)
                        {
                            transfercache.SetValue <CATransfer.clearedIn>(catransfer, false);
                        }

                        CATran catran = TransferCashTranIDAttribute.DefaultValues <CATransfer.tranIDOut>(transfercache, catransfer);

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            transfercache.SetValue <CATransfer.tranIDOut>(catransfer, id);
                            transfercache.Update(catransfer);
                        }
                    }

                    transfercache.Persist(PXDBOperation.Update);

                    ts.Complete(te);
                }

                transfercache.Persisted(false);
                te.catrancache.Persisted(false);
            }

            te.Clear();

            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.module>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.batchNbr>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.ledgerID>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.finPeriodID>(te.Caches[typeof(GLTran)], null, false);

            using (new PXConnectionScope())
            {
                const int rowsPerCycle = 10000;
                bool      noMoreTran   = false;
                int?      lastGLTranIDOnPreviousStep = null;
                int       previousCountRows          = 0;

                while (!noMoreTran)
                {
                    noMoreTran = true;
                    int countRows    = 0;
                    int?lastGLTranID = null;
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        foreach (PXResult <GLTran, Ledger, Batch> res in PXSelectJoin <GLTran, InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLTran.ledgerID> >,
                                                                                                          InnerJoin <Batch, On <Batch.module, Equal <GLTran.module>, And <Batch.batchNbr, Equal <GLTran.batchNbr>,
                                                                                                                                                                          And <Batch.scheduled, Equal <False>, And <Batch.voided, NotEqual <True> > > > > > >,
                                                                                       Where <GLTran.accountID, Equal <Required <GLTran.accountID> >,
                                                                                              And <GLTran.subID, Equal <Required <GLTran.subID> >,
                                                                                                   And <GLTran.branchID, Equal <Required <GLTran.branchID> >,
                                                                                                        And <Ledger.balanceType, Equal <LedgerBalanceType.actual>,
                                                                                                             //ignoring CM because DefaultValues always return null for CM
                                                                                                             And <GLTran.module, NotEqual <BatchModule.moduleCM>,
                                                                                                                  And <GLTran.cATranID, IsNull> > > > > >, OrderBy <Asc <GLTran.tranID> > > .SelectWindowed(te, 0, rowsPerCycle, tlist.AccountID, tlist.SubID, tlist.BranchID))
                        {
                            GLTran gltran = (GLTran)res;
                            lastGLTranID = gltran.TranID;
                            noMoreTran   = false;
                            countRows++;
                            CATran catran = GLCashTranIDAttribute.DefaultValues <GLTran.cATranID>(te.gltrancache, gltran);
                            if (catran != null)
                            {
                                long id;
                                bool newCATRan = false;
                                if (te.catrancache.Locate(catran) == null)
                                {
                                    catran    = (CATran)te.catrancache.Insert(catran);
                                    newCATRan = true;
                                    te.catrancache.PersistInserted(catran);
                                    id = Convert.ToInt64(PXDatabase.SelectIdentity());
                                }
                                else
                                {
                                    catran = (CATran)te.catrancache.Update(catran);
                                    te.catrancache.PersistUpdated(catran);
                                    id = catran.TranID.Value;
                                }

                                gltran.CATranID = id;
                                te.gltrancache.Update(gltran);

                                if (catran.OrigModule != GLTranType.GLEntry)
                                {
                                    switch (catran.OrigModule)
                                    {
                                    case BatchModule.AR:
                                        ARPayment arPayment = PXSelect <ARPayment, Where <ARPayment.docType, Equal <Required <ARPayment.docType> >,
                                                                                          And <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> > > > > .Select(te, catran.OrigTranType, catran.OrigRefNbr);

                                        if (arPayment != null && (arPayment.CATranID == null || newCATRan))
                                        {
                                            arPayment.CATranID = id;
                                            arPayment          = (ARPayment)te.Caches[typeof(ARPayment)].Update(arPayment);
                                            te.Caches[typeof(ARPayment)].PersistUpdated(arPayment);
                                        }
                                        break;

                                    case BatchModule.AP:
                                        APPayment apPayment = PXSelect <APPayment, Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                                                          And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > > .Select(te, catran.OrigTranType, catran.OrigRefNbr);

                                        if (apPayment != null && (apPayment.CATranID == null || newCATRan))
                                        {
                                            apPayment.CATranID = id;
                                            apPayment          = (APPayment)te.Caches[typeof(APPayment)].Update(apPayment);
                                            te.Caches[typeof(APPayment)].PersistUpdated(apPayment);
                                        }
                                        break;
                                    }
                                }
                            }
                        }

                        if (!noMoreTran && countRows == previousCountRows && lastGLTranID == lastGLTranIDOnPreviousStep)
                        {
                            throw new PXException(Messages.ProcessCannotBeCompleted);
                        }

                        previousCountRows          = countRows;
                        lastGLTranIDOnPreviousStep = lastGLTranID;

                        te.gltrancache.ClearQueryCache();
                        te.gltrancache.Persist(PXDBOperation.Update);
                        te.gltrancache.Clear();
                        te.catrancache.Clear();
                        te.catrancache.ClearQueryCache();
                        te.dailycache.Clear();
                        te.Caches[typeof(APPayment)].Clear();
                        te.Caches[typeof(ARPayment)].Clear();
                        ts.Complete(te);
                    }
                }

                PXDatabase.Delete <CADailySummary>(
                    new PXDataFieldRestrict("CashAccountID", PXDbType.Int, 4, tlist.CashAccountID, PXComp.EQ));

                foreach (CATran tran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> > > > .Select(te, tlist.CashAccountID))
                {
                    CADailyAccumulatorAttribute.RowInserted <CATran.tranDate>(te.catrancache, tran);
                }

                te.dailycache.Persist(PXDBOperation.Insert);
                te.dailycache.Persist(PXDBOperation.Update);


                te.gltrancache.Persisted(false);
                te.catrancache.Persisted(false);
                te.dailycache.Persisted(false);
            }
        }