Beispiel #1
0
        public virtual void DoConvert(bool redirect)
        {
            ConversionResult <BAccount> result;

            using (var ts = new PXTransactionScope())
            {
                result = AccountExt.Convert(new AccountConversionOptions
                {
                    HoldCurrentsCallback = ContactExt.HoldCurrents
                });

                var contact = ContactExt.Convert(new ContactConversionOptions
                {
                    GraphWithRelation = result.Graph
                });

                if (AccountExt.Documents.Current.RefContactID == null)
                {
                    throw new PXException(Messages.CannotCreateAccount);
                }

                ts.Complete();
            }

            if (redirect)
            {
                AccountExt.Redirect(result);
            }
        }
        private IEnumerable PayBillWithoutJointPayees(PXAdapter adapter, Func <PXAdapter, IEnumerable> baseMethod)
        {
            try
            {
                return(baseMethod(adapter));
            }
            catch (PXRedirectRequiredException exception)
            {
                if (exception.Graph is APPaymentEntry graph)
                {
                    using (PXTransactionScope scope = new PXTransactionScope())
                    {
                        LinkComplianceDocumentsToCheck(graph);
                        var currentApPayment = graph.Document.Current;
                        TakePaymentsOffHoldIfNeeded(graph);
                        graph.Document.Current = currentApPayment;

                        Base.Caches <ComplianceDocumentReference>().Persist(PXDBOperation.Delete);

                        scope.Complete();
                    }
                }
                throw;
            }
        }
Beispiel #3
0
        public IEnumerable detailsView()
        {
            List <object> result = new List <object>();

            var currentSearchPeriod = ((LumINItemCostFilter)this.Caches[typeof(LumINItemCostFilter)].Current)?.FinPeriodID;

            if (currentSearchPeriod != null)
            {
                var           pars      = new List <PXSPParameter>();
                PXSPParameter period    = new PXSPInParameter("@period", PXDbType.Int, currentSearchPeriod);
                PXSPParameter companyID = new PXSPInParameter("@companyID", PXDbType.Int, PX.Data.Update.PXInstanceHelper.CurrentCompany);
                pars.Add(period);
                pars.Add(companyID);

                using (new PXConnectionScope())
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        PXDatabase.Execute("SP_GenerateLumINItemCostHist", pars.ToArray());
                        ts.Complete();
                    }
                }

                PXView select   = new PXView(this, true, DetailsView.View.BqlSelect);
                int    totalrow = 0;
                int    startrow = PXView.StartRow;
                result          = select.Select(PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startrow, PXView.MaximumRows, ref totalrow);
                PXView.StartRow = 0;
                return(result);
            }

            return(result);
        }
        public virtual void GenerateProc(Schedule s, short Times, DateTime runDate)
        {
            IEnumerable <ScheduleDet> sd = new Scheduler(this).MakeSchedule(s, Times, runDate);
            WZTaskEntry graph            = PXGraph.CreateInstance <WZTaskEntry>();

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (ScheduleDet d in sd)
                {
                    foreach (WZScenario scenario in PXSelect <WZScenario, Where <WZScenario.scheduleID, Equal <Required <Schedule.scheduleID> >, And <WZScenario.scheduled, Equal <True> > > > .
                             Select(this, s.ScheduleID))
                    {
                        scenario.ExecutionDate = d.ScheduledDate;
                        graph.Scenario.Current = scenario;
                        if (scenario.Status != WizardScenarioStatusesAttribute._SUSPEND)
                        {
                            graph.activateScenarioWithoutRefresh.Press();
                        }
                    }
                    s.LastRunDate = d.ScheduledDate;
                    Running_Schedule.Cache.Update(s);
                }
                Running_Schedule.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
        }
        public override void Persist()
        {
            var groups = Activity.Cache.Updated.Cast <EPActivityApprove>()
                         .Where(a => a.IsReject == true && a.TimeCardCD != null)
                         .GroupBy(a => a.TimeCardCD)
                         .ToList();

            using (var ts = new PXTransactionScope())
            {
                if (groups.Count > 0)
                {
                    TimeCardMaint maint = PXGraph.CreateInstance <TimeCardMaint>();

                    foreach (var group in groups)
                    {
                        maint.Clear();
                        maint.Document.Current = maint.Document.Search <EPTimeCard.timeCardCD>(group.Key);
                        maint.Actions["Reject"].Press();
                        maint.Persist();
                    }
                }

                base.Persist();

                ts.Complete();
            }
        }
Beispiel #6
0
        protected virtual void EPEquipment_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
        {
            if (e.Row == null || VehicleSelected.Current == null)
            {
                return;
            }

            EPEquipment epEquipmentRow = (EPEquipment)e.Row;

            if (epEquipmentRow.EquipmentID != VehicleSelected.Current.SourceID)
            {
                return;
            }

            if (e.Operation == PXDBOperation.Delete && e.TranStatus == PXTranStatus.Open)
            {
                try
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        VehicleSelected.Delete(VehicleSelected.Current);
                        VehicleSelected.Cache.Persist(PXDBOperation.Delete);
                        ts.Complete();
                    }

                    VehicleSelected.Cache.Persisted(false);
                }
                catch
                {
                    VehicleSelected.Cache.Persisted(true);
                    throw;
                }
            }
        }
Beispiel #7
0
        private void UpdateAcitivtyRemindInfo(object id, UpdateRemindInfo handler)
        {
            EPReminder remindInfo = RemindInfo.Select(id);

            if (remindInfo == null)
            {
                remindInfo = (EPReminder)RemindInfo.Cache.Insert();
                EPActivity activity = PXSelect <EPActivity, Where <EPActivity.taskID, Equal <Required <EPActivity.taskID> > > > .
                                      Select(this, id);

                remindInfo.NoteID = PXNoteAttribute.GetNoteID(Caches[typeof(EPActivity)], activity,
                                                              EntityHelper.GetNoteField(typeof(EPActivity)));
                remindInfo.UserID = PXAccess.GetUserID();
                remindInfo.Date   = PXTimeZoneInfo.Now;
                RemindInfo.Cache.Normalize();
            }
            handler(remindInfo);
            RemindInfo.Update(remindInfo);
            using (var ts = new PXTransactionScope())
            {
                RemindInfo.Cache.Persist(PXDBOperation.Insert);
                RemindInfo.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
            RemindInfo.Cache.Persisted(false);
            ActivityList.Cache.Clear();
            ActivityList.View.Clear();
            ActivityCount.Cache.Clear();
            ActivityCount.View.Clear();
            ReminderList.Cache.Clear();
            ReminderList.View.Clear();
            ReminderListCurrent.View.Clear();
        }
 private void ProcessMessage()
 {
     using (PXTransactionScope sc = new PXTransactionScope())
     {
         try
         {
             PreProcessActivity();
         }
         catch (Exception)
         {
             //Unable to change status - leave message alone.
             return;
         }
         try
         {
             ProcessActivity();
             PostProcessActivity();
         }
         catch (Exception ex)
         {
             PersistException(ex);
         }
         sc.Complete();
     }
 }
Beispiel #9
0
        public virtual void UpdatePersonDisplayNames(string PersonDisplayNameFormat)
        {
            using (var tran = new PXTransactionScope())
            {
                switch (PersonDisplayNameFormat)
                {
                case PersonNameFormatsAttribute.WESTERN:
                    SetContactsWesternOrder();
                    break;

                case PersonNameFormatsAttribute.EASTERN:
                    SetContactsEasternOrder();
                    break;

                case PersonNameFormatsAttribute.LEGACY:
                    SetContactsLegacyOrder();
                    break;

                case PersonNameFormatsAttribute.EASTERN_WITH_TITLE:
                    SetContactsEasternWithTitleOrder();
                    break;
                }

                UpdateBAccounts();

                tran.Complete();
            }

            PXDatabase.ClearCompanyCache();
        }
Beispiel #10
0
        public virtual void DeletePostingBatch(FSContractPostBatch fsPostBatchRow)
        {
            if (fsPostBatchRow.ContractPostBatchID < 0)
            {
                return;
            }

            PostBatchRecords.Current = PostBatchRecords.Search <FSContractPostBatch.contractPostBatchID>(fsPostBatchRow.ContractPostBatchID);

            if (PostBatchRecords.Current == null || PostBatchRecords.Current.ContractPostBatchID != fsPostBatchRow.ContractPostBatchID)
            {
                return;
            }

            using (var ts = new PXTransactionScope())
            {
                PXDatabase.Delete <FSCreatedDoc>(
                    new PXDataFieldRestrict <FSCreatedDoc.batchID>(fsPostBatchRow.ContractPostBatchID));

                PostBatchRecords.Delete(fsPostBatchRow);
                Save.Press();

                ts.Complete();
            }
        }
        protected static void ReleaseActivities(List <EPActivityApprove> activities)
        {
            RegisterEntry registerEntry = (RegisterEntry)PXGraph.CreateInstance(typeof(RegisterEntry));
            bool          activityAdded = false;

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                if (!RecordContractUsage(activities, "Contract-Usage"))
                {
                    throw new PXException(Messages.FailedCreateContractUsageTransactions);
                }

                if (!RecordCostTrans(registerEntry, activities, out activityAdded))
                {
                    throw new PXException(Messages.FailedCreateCostTransactions);
                }

                ts.Complete();
            }

            EPSetup setup = PXSelect <EPSetup> .Select(registerEntry);

            if (activityAdded && setup != null && setup.AutomaticReleasePM == true)
            {
                PX.Objects.PM.RegisterRelease.Release(registerEntry.Document.Current);
            }
        }
        protected void SafetyPersist(PXCache cache, params PXDBOperation[] operations)
        {
            if (operations.Length < 1)
            {
                return;
            }
            bool isAborted = false;

            try
            {
                using (PXTransactionScope tscope = new PXTransactionScope())
                {
                    foreach (PXDBOperation operation in operations)
                    {
                        cache.Persist(operation);
                    }
                    tscope.Complete();
                }
            }
            catch (Exception)
            {
                isAborted = true;
                throw;
            }
            finally
            {
                cache.Persisted(isAborted);
            }
        }
Beispiel #13
0
        public override void Initialize()
        {
            base.Initialize();

            Base.ARDocumentList.SetProcessDelegate(
                delegate(List <BalancedARDocument> list)
            {
                List <ARRegister> newlist = new List <ARRegister>(list.Count);
                foreach (BalancedARDocument doc in list)
                {
                    newlist.Add(doc);
                }

                foreach (ARRegister doc in newlist)
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        ARInvoiceEntry graph = PXGraph.CreateInstance <ARInvoiceEntry>();

                        if (RUTROTHelper.IsNeedBalancing(graph, RUTROTBalanceOn.Release))
                        {
                            BalanceProc(graph, doc);
                        }

                        ARDocumentRelease.ReleaseDoc(new List <ARRegister> {
                            doc
                        }, true);

                        ts.Complete();
                    }
                }
            }
                );
        }
Beispiel #14
0
        private void UpdateAcitivtyRemindInfo(object id, UpdateRemindInfo handler)
        {
            CRReminder remindInfo = RemindInfo.Select(id);

            if (remindInfo == null && id is Guid)
            {
                remindInfo              = (CRReminder)RemindInfo.Cache.Insert();
                remindInfo.RefNoteID    = (Guid)id;
                remindInfo.Owner        = PXAccess.GetUserID();
                remindInfo.ReminderDate = PXTimeZoneInfo.Now;
                RemindInfo.Cache.Normalize();
            }
            handler(remindInfo);
            RemindInfo.Update(remindInfo);
            using (var ts = new PXTransactionScope())
            {
                RemindInfo.Cache.Persist(PXDBOperation.Insert);
                RemindInfo.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
            RemindInfo.Cache.Persisted(false);
            ActivityList.Cache.Clear();
            ActivityList.View.Clear();
            ActivityCount.Cache.Clear();
            ActivityCount.View.Clear();
            ReminderList.Cache.Clear();
            ReminderList.View.Clear();
            ReminderListCurrent.View.Clear();
        }
        public virtual IEnumerable SynGanttSmartsheetProject(PXAdapter adapter)
        {
            this.Base.Actions.PressSave();
            PMProject pmProjectRow = this.Base.Project.Current;

            ProjectEntry projectEntryGraph = PXGraph.CreateInstance <ProjectEntry>();

            SmartsheetClient smartsheetClient = CheckTokenSheetSS(projectEntryGraph, pmProjectRow);

            if (smartsheetClient != null)
            {
                PXLongOperation.StartOperation(this.Base,
                                               () =>
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        projectEntryGraph = this.Base;
                        ProjectEntrySmartsheetExt graphExtended = projectEntryGraph.GetExtension <ProjectEntrySmartsheetExt>();
                        CreateEmployeesAcuUserSS(projectEntryGraph, smartsheetClient);
                        graphExtended.CreateUpdateGanttProject(projectEntryGraph, pmProjectRow, smartsheetClient);
                        ts.Complete();
                    }
                });
            }

            return(adapter.Get());
        }
        public override void Persist()
        {
            if (Header.Cache.IsDirty && Detail.Select().Count == 0 && Header.Current != null)
            {
                throw new PXException(Messages.DimensionIsEmpty);
            }

            var dimension = Header.Current;

            if (dimension == null)
            {
                base.Persist();
            }
            else
            {
                try
                {
                    using (PXTransactionScope tscope = new PXTransactionScope())
                    {
                        if (Header.Cache.GetStatus(dimension) != PXEntryStatus.Deleted)
                        {
                            InsertNumberingValue(Header.Current);
                            CorrectChildDimensions();
                        }

                        var oldLength = (short?)Header.Cache.GetValueOriginal <Dimension.length>(dimension);

                        if (dimension.Length < oldLength)
                        {
                            if (dimension.DimensionID == "SUBACCOUNT")
                            {
                                CheckLongerSubKeysDoNotExist(dimension.Length);

                                PXUpdate <Set <Sub.subCD, Substring <Sub.subCD, int1, CurrentValue <Dimension.length> > >,
                                          Sub>
                                .Update(this);
                            }

                            ValidateDimensionForKeyDuplication(dimension);
                        }

                        PXDimensionAttribute.Clear();
                        base.Persist();
                        Header.Current = dimension;
                        PXDimensionAttribute.Clear();

                        tscope.Complete();
                    }
                }
                catch (PXDatabaseException e)
                {
                    if (e.ErrorCode == PXDbExceptions.DeleteForeignKeyConstraintViolation)
                    {
                        throw new PXException(Messages.SegmentHasValues, e.Keys[1]);
                    }
                    throw;
                }
            }
            PXPageCacheUtils.InvalidateCachedPages();
        }
Beispiel #17
0
        public void Copy(FLXProject project, FLXProjPurchDetails purchDetails)
        {
            using (PXTransactionScope transactionScope = new PXTransactionScope())
            {
                FLXProject copy1 = PXCache <FLXProject> .CreateCopy(project);

                copy1.OrigProjNbr = project.ProjectNbr;
                copy1.NoteID      = new Guid?();
                this.Document.Insert(copy1);
                string projectNbr = this.Document.Current.ProjectNbr;
                if (purchDetails != null)
                {
                    FLXProjPurchDetails copy2 = PXCache <FLXProjPurchDetails> .CreateCopy(purchDetails);

                    copy2.ProjectNbr = projectNbr;
                    copy2.NoteID     = new Guid?();
                    this.ProjPurchDtls.Insert(copy2);
                }
                foreach (FLXProjISOSched flxProjIsoSched1 in this.ProjISOSched.Cache.Inserted)
                {
                    FLXProjISOSched flxProjIsoSched2 = SelectFrom <FLXProjISOSched> .Where <FLXProjISOSched.projectNbr.IsEqual <P.AsString>
                                                                                            .And <FLXProjISOSched.scheduleCD.IsEqual <P.AsString> > > .View.SelectSingleBound((PXGraph)this, (object[])null, (object)copy1.OrigProjNbr, (object)flxProjIsoSched1.ScheduleCD);

                    flxProjIsoSched1.ScheduleDate = flxProjIsoSched2.ScheduleDate;
                    this.ProjISOSched.Update(flxProjIsoSched1);
                }
                transactionScope.Complete();
            }
            PXRedirectHelper.TryRedirect((PXGraph)this, PXRedirectHelper.WindowMode.Same);
        }
        private static void ValidateCADailySummary(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period)
        {
            using (new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    graph.dailycache.Clear();
                    ts.Complete(graph);
                }
            }

            PXDatabase.Delete <CADailySummary>(
                new PXDataFieldRestrict(nameof(CADailySummary.CashAccountID), PXDbType.Int, 4, cashAccount.CashAccountID, PXComp.EQ),
                new PXDataFieldRestrict(nameof(CADailySummary.TranDate), PXDbType.DateTime, 8, period.StartDate, PXComp.GE));

            foreach (CATran tran in PXSelect <CATran,
                                              Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> >,
                                                     And <CATran.tranDate, GreaterEqual <Required <CATran.tranDate> > > > > .Select(graph, cashAccount.CashAccountID, period.StartDate))
            {
                CADailyAccumulatorAttribute.RowInserted <CATran.tranDate>(graph.catrancache, tran);
            }

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

            graph.dailycache.Persisted(false);
        }
 private static void ValidateCleared(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period)
 {
     if (cashAccount.Reconcile != true)
     {
         graph.Clear();
         using (new PXConnectionScope())
         {
             using (PXTransactionScope ts = new PXTransactionScope())
             {
                 foreach (CATran catran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> >,
                                                                    And <CATran.finPeriodID, GreaterEqual <Required <CATran.finPeriodID> > > > > .Select(graph, cashAccount.CashAccountID, period.FinPeriodID))
                 {
                     if (cashAccount.Reconcile != true && (catran.Cleared != true || catran.TranDate == null))
                     {
                         catran.Cleared   = true;
                         catran.ClearDate = catran.TranDate;
                     }
                     graph.catrancache.Update(catran);
                 }
                 graph.catrancache.Persist(PXDBOperation.Update);
                 ts.Complete(graph);
             }
             graph.catrancache.Persisted(false);
         }
     }
 }
        protected void PersistMessages(IEnumerable <CRSMEmail> messages)
        {
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (CRSMEmail item in messages)
                {
                    try
                    {
                        var activityCache = Graph.Caches[item.GetType()];
                        PXDBDefaultAttribute.SetSourceType <CRSMEmail.refNoteID>(activityCache, item, null);
                        activityCache.PersistInserted(item);
                    }
                    catch (Exception e)
                    {
                        if (!MassProcessMode)
                        {
                            throw;
                        }
                        PXTrace.WriteInformation(e);
                    }
                }
                Graph.Caches <CRActivityStatistics>().Persist(PXDBOperation.Insert);
                Graph.Caches <CRActivityStatistics>().Persist(PXDBOperation.Update);

                ts.Complete();
            }
        }
        public override void Persist()
        {
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                BAccount acct = (BAccount)BAccount.Cache.Current;
                if (acct != null && acct.Status == CR.BAccount.status.Inactive)
                {
                    ContactMaint graph = CreateInstance <ContactMaint>();
                    foreach (Contact c in Contacts.Select())
                    {
                        c.IsActive = false;
                        graph.ContactCurrent.Cache.Update(c);
                        graph.Save.Press();
                    }
                }

                base.Persist();
                ts.Complete();
            }

            if (Setup.Current.ValidateAccountDuplicatesOnEntry == true)
            {
                checkForDuplicates.Press();
            }
        }
        public virtual void RevalueInventory(INUpdateStdCostRecord itemsite)
        {
            using (new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    if (je.adjustment.Current == null)
                    {
                        je.adjustment.Cache.Insert();
                    }

                    foreach (
                        PXResult <INCostStatus, InventoryItem, INSite, INPostClass, INItemSite> res in
                        incoststatus.View.SelectMultiBound(new object[] { itemsite }))
                    {
                        INCostStatus layer = res;
                        INSite       site  = res;
                        INTran       tran  = new INTran();

                        if (((INCostStatus)res).LayerType == INLayerType.Oversold)
                        {
                            tran.TranType = INTranType.NegativeCostAdjustment;
                        }
                        else
                        {
                            tran.TranType = INTranType.StandardCostAdjustment;
                        }
                        tran.BranchID   = site.BranchID;
                        tran.InvtAcctID = layer.AccountID;
                        tran.InvtSubID  = layer.SubID;
                        tran.AcctID     = INReleaseProcess.GetAccountDefaults <INPostClass.stdCstRevAcctID>
                                              (je, (InventoryItem)res, (INSite)res, (INPostClass)res);
                        tran.SubID = INReleaseProcess.GetAccountDefaults <INPostClass.stdCstRevSubID>
                                         (je, (InventoryItem)res, (INSite)res, (INPostClass)res);

                        tran.InventoryID = layer.InventoryID;
                        tran.SubItemID   = layer.CostSubItemID;
                        tran.SiteID      = layer.CostSiteID;
                        tran.Qty         = 0m;
                        tran.TranCost    = PXDBCurrencyAttribute.BaseRound(this, (decimal)(layer.QtyOnHand * itemsite.StdCost)) -
                                           layer.TotalCost;

                        je.transactions.Insert(tran);
                    }

                    if (je.transactions.Select().Count == 0)
                    {
                        je.Clear();
                    }
                    else
                    {
                        je.Save.Press();
                        PXProcessing <INUpdateStdCostRecord> .SetInfo(string.Format(Messages.AdjstmentCreated, je.adjustment.Current.RefNbr));
                    }

                    ts.Complete();
                }
            }
        }
Beispiel #23
0
        public virtual void UpdateStdCost(INUpdateStdCostRecord itemsite)
        {
            using (new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    //will be true for non-stock items as well
                    if (itemsite.StdCostOverride == false && itemsite.PendingStdCostReset == false)
                    {
                        PXDatabase.Update <INItemSite>(
                            new PXDataFieldAssign("StdCost", PXDbType.DirectExpression, "PendingStdCost"),
                            new PXDataFieldAssign("StdCostDate", PXDbType.DateTime, itemsite.PendingStdCostDate),
                            new PXDataFieldAssign("PendingStdCost", PXDbType.Decimal, 0m),
                            new PXDataFieldAssign("PendingStdCostDate", PXDbType.DateTime, null),
                            new PXDataFieldAssign("LastStdCost", PXDbType.DirectExpression, "StdCost"),
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, itemsite.InventoryID),
                            new PXDataFieldRestrict("StdCostOverride", PXDbType.Bit, false),
                            new PXDataFieldRestrict("PendingStdCostDate", PXDbType.DateTime, 4, itemsite.PendingStdCostDate, PXComp.LE),
                            new PXDataFieldRestrict("PendingStdCostReset", PXDbType.Bit, false));

                        PXDatabase.Update <InventoryItem>(
                            new PXDataFieldAssign("StdCost", PXDbType.DirectExpression, "PendingStdCost"),
                            new PXDataFieldAssign("StdCostDate", PXDbType.DateTime, itemsite.PendingStdCostDate),
                            new PXDataFieldAssign("PendingStdCost", PXDbType.Decimal, 0m),
                            new PXDataFieldAssign("PendingStdCostDate", PXDbType.DateTime, null),
                            new PXDataFieldAssign("LastStdCost", PXDbType.DirectExpression, "StdCost"),
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, itemsite.InventoryID),
                            new PXDataFieldRestrict("PendingStdCostDate", PXDbType.DateTime, 4, itemsite.PendingStdCostDate, PXComp.LE));
                    }
                    else
                    {
                        var updateParams = new List <PXDataFieldParam>
                        {
                            new PXDataFieldAssign("StdCost", PXDbType.DirectExpression, "PendingStdCost"),
                            new PXDataFieldAssign("StdCostDate", PXDbType.DateTime, itemsite.PendingStdCostDate ?? Accessinfo.BusinessDate),
                            new PXDataFieldAssign("PendingStdCost", PXDbType.Decimal, 0m),
                            new PXDataFieldAssign("PendingStdCostDate", PXDbType.DateTime, null),
                            new PXDataFieldAssign("PendingStdCostReset", PXDbType.Bit, false),
                            new PXDataFieldAssign("LastStdCost", PXDbType.DirectExpression, "StdCost"),
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, itemsite.InventoryID),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, itemsite.SiteID)
                        };

                        // Restriction was added within AC-32883 and looks useless as in this 'else' branch double update is impossible.
                        if (itemsite.PendingStdCostReset == false)
                        {
                            updateParams.Add(new PXDataFieldRestrict("PendingStdCostDate", PXDbType.DateTime, 4, itemsite.PendingStdCostDate, PXComp.LE));
                        }

                        PXDatabase.Update <INItemSite>(updateParams.ToArray());
                    }

                    CreateAdjustments(itemsite,
                                      (layer) => PXDBCurrencyAttribute.BaseRound(this, (decimal)(layer.QtyOnHand * itemsite.PendingStdCost)) - layer.TotalCost);

                    ts.Complete();
                }
            }
        }
Beispiel #24
0
        protected virtual void MarkAs(PXCache cache, CRActivity row, Guid UserID, int status)
        {
            if (IsImport || row.NoteID == null)
            {
                return;
            }

            var noteidType = typeof(TMaster).GetNestedType(typeof(CRActivity.noteID).Name);
            var ownerType  = typeof(TMaster).GetNestedType(typeof(CRActivity.ownerID).Name);

            var select = BqlCommand.Compose(
                typeof(Select <,>), typeof(EPView), typeof(Where <, ,>),
                typeof(EPView.noteID), typeof(Equal <>), typeof(Required <>), noteidType,
                typeof(And <,>), typeof(EPView.userID), typeof(Equal <>), typeof(Required <>), ownerType
                );

            EPView epview = (EPView) new PXView(this, false,
                                                BqlCommand.CreateInstance(select)).SelectSingle(row.NoteID, UserID);

            if (epview == null)
            {
                epview = new EPView
                {
                    NoteID = row.NoteID,
                    UserID = UserID,
                };
            }
            else
            {
                epview = PXCache <EPView> .CreateCopy(epview);
            }

            if (status == EPViewStatusAttribute.VIEWED
                                        ? epview.Status != EPViewStatusAttribute.VIEWED
                                        : epview.Status == EPViewStatusAttribute.VIEWED)
            {
                epview.Status = status;
                EPViews.Update(epview);

                bool isDirty = false;
                foreach (PXCache c in Views.Caches.Where(t => t != typeof(EPView)).Select(t => Caches[t]))
                {
                    isDirty = c.Inserted.ToArray <object>().Any() || c.Updated.ToArray <object>().Any() || c.Deleted.ToArray <object>().Any();
                    if (isDirty)
                    {
                        break;
                    }
                }
                if (!isDirty)
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        Persist();
                        ts.Complete();
                    }
                }
                EPViews.Cache.IsDirty = false;
            }
        }
Beispiel #25
0
        private const bool AutoReleaseDebitAdjustments = true;         //TODO: now (26.10.2017) we can't apply nonreleased debit adjustment

        public static APInvoice CreateAndReleasePPDDebitAdj(APInvoiceEntry ie, APPPDDebitAdjParameters filter, List <PendingPPDDebitAdjApp> list, bool autoReleaseDebitAdjustments)
        {
            APInvoice invDebitAdj;

            try
            {
                ie.Clear(PXClearOption.ClearAll);
                PXUIFieldAttribute.SetError(ie.Document.Cache, null, null, null);

                using (var ts = new PXTransactionScope())
                {
                    invDebitAdj = ie.CreatePPDDebitAdj(filter, list);
                    if (invDebitAdj != null)
                    {
                        if (autoReleaseDebitAdjustments == true)
                        {
                            using (new PXTimeStampScope(null))
                            {
                                APDocumentRelease.ReleaseDoc(new List <APRegister> {
                                    invDebitAdj
                                }, false);
                                APPaymentEntry paymentEntry = PXGraph.CreateInstance <APPaymentEntry>();
                                APPayment      debitAdj     = PXSelect <APPayment,
                                                                        Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                                               And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > >
                                                              .Select(paymentEntry, invDebitAdj.DocType, invDebitAdj.RefNbr)
                                                              .First();

                                paymentEntry.Document.Current = debitAdj;
                                paymentEntry.SelectTimeStamp();
                                CreatePPDApplications(paymentEntry, list, debitAdj);
                                paymentEntry.Persist();
                                APDocumentRelease.ReleaseDoc(new List <APRegister> {
                                    invDebitAdj
                                }, false);                                                                                               // It needs to release applications
                            }
                        }

                        foreach (PendingPPDDebitAdjApp adj in list)
                        {
                            PXProcessing <PendingPPDDebitAdjApp> .SetInfo(adj.Index, ActionsMessages.RecordProcessed);
                        }
                    }
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                foreach (PendingPPDDebitAdjApp adj in list)
                {
                    PXProcessing <PendingPPDDebitAdjApp> .SetError(adj.Index, e);
                }

                invDebitAdj = null;
            }

            return(invDebitAdj);
        }
Beispiel #26
0
        public void OnReleaseComplete(ICADocument doc, OnReleaseCompleteDelegate baseMethod)
        {
            CAAdj cAAdj = doc as CAAdj;

            if (TWNGUIValidation.ActivateTWGUI(Base) == true &&
                cAAdj != null &&
                cAAdj.Released == true &&
                cAAdj.AdjTranType == CATranType.CAAdjustment)
            {
                TWNReleaseProcess rp = PXGraph.CreateInstance <TWNReleaseProcess>();

                PXSelectBase <TWNManualGUIBank> ViewManGUIBank = new SelectFrom <TWNManualGUIBank> .Where <TWNManualGUIBank.adjRefNbr.IsEqual <@P.AsString> > .View(Base);

                foreach (TWNManualGUIBank manualGUIBank in ViewManGUIBank.Cache.Cached)
                {
                    if (PXCache <Tax> .GetExtension <TaxExt>(Tax.PK.Find(Base, manualGUIBank.TaxID)).UsrTWNGUI.Equals(false))
                    {
                        continue;
                    }

                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        rp.CreateGUITrans(new STWNGUITran()
                        {
                            VATCode      = manualGUIBank.VATInCode,
                            GUINbr       = manualGUIBank.GUINbr,
                            GUIStatus    = TWNGUIStatus.Used,
                            BranchID     = Base.CATranCashTrans_Ordered.Current.BranchID,
                            GUIDirection = TWNGUIDirection.Receipt,
                            GUIDate      = manualGUIBank.GUIDate,
                            GUITitle     = (string)PXSelectorAttribute.GetField(ViewManGUIBank.Cache, manualGUIBank,
                                                                                typeof(APRegister.vendorID).Name, manualGUIBank.VendorID,
                                                                                typeof(Vendor.acctName).Name),
                            TaxZoneID     = manualGUIBank.TaxZoneID,
                            TaxCategoryID = manualGUIBank.TaxCategoryID,
                            TaxID         = manualGUIBank.TaxID,
                            TaxNbr        = manualGUIBank.TaxNbr,
                            OurTaxNbr     = manualGUIBank.OurTaxNbr,
                            NetAmount     = manualGUIBank.NetAmt,
                            TaxAmount     = manualGUIBank.TaxAmt,
                            AcctCD        = (string)PXSelectorAttribute.GetField(ViewManGUIBank.Cache, manualGUIBank,
                                                                                 typeof(APRegister.vendorID).Name, manualGUIBank.VendorID,
                                                                                 typeof(Vendor.acctCD).Name),
                            AcctName = (string)PXSelectorAttribute.GetField(ViewManGUIBank.Cache, manualGUIBank,
                                                                            typeof(APRegister.vendorID).Name, manualGUIBank.VendorID,
                                                                            typeof(Vendor.acctName).Name),
                            DeductionCode = manualGUIBank.Deduction,
                            Remark        = manualGUIBank.Remark,
                            OrderNbr      = manualGUIBank.AdjRefNbr
                        });

                        ts.Complete(Base);
                    }
                }
            }

            baseMethod(doc);
        }
        private static void EraseImpl(IEnumerable <SMPersonalDataIndex> entities, GDPREraseOnRestoreProcess graph)
        {
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                graph.ProcessImpl(RemapToPrimary(entities), true, null);

                ts.Complete();
            }
        }
Beispiel #28
0
        private void UpdatePhysicalQty()
        {
            INBarCodeItem item = AddByBarCode.Current;
            INPIHeader    d    = this.PIHeader.Current;

            this.SelectTimeStamp();

            using (PXTransactionScope sc = new PXTransactionScope())
            {
                INPIDetail detail =
                    PXSelectReadonly <INPIDetail,
                                      Where <INPIDetail.pIID, Equal <Current <INPIHeader.pIID> >,
                                             And <INPIDetail.inventoryID, Equal <Current <INBarCodeItem.inventoryID> >,
                                                  And <INPIDetail.subItemID, Equal <Current <INBarCodeItem.subItemID> >,
                                                       And <INPIDetail.locationID, Equal <Current <INBarCodeItem.locationID> >,
                                                            And <Where <INPIDetail.lotSerialNbr, IsNull,
                                                                        Or <INPIDetail.lotSerialNbr, Equal <Current <INBarCodeItem.lotSerialNbr> > > > > > > > > > .SelectWindowed(this, 0, 1);

                if (detail == null)
                {
                    INPIEntry entry = PXGraph.CreateInstance <INPIEntry>();
                    entry.PIHeader.Current = entry.PIHeader.Search <INPIHeader.pIID>(d.PIID);
                    detail = PXCache <INPIDetail> .CreateCopy(entry.PIDetail.Insert(new INPIDetail()));

                    detail.InventoryID = item.InventoryID;
                    detail             = PXCache <INPIDetail> .CreateCopy(entry.PIDetail.Update(detail));

                    detail.SubItemID    = item.SubItemID;
                    detail.LocationID   = item.LocationID;
                    detail.LotSerialNbr = item.LotSerialNbr;
                    detail.PhysicalQty  = item.Qty;
                    detail.ExpireDate   = item.ExpireDate;
                    entry.PIDetail.Update(detail);
                    entry.Save.Press();
                    this.PIHeader.View.RequestRefresh();
                }
                else
                {
                    detail = PXCache <INPIDetail> .CreateCopy(detail);

                    detail.PhysicalQty = detail.PhysicalQty.GetValueOrDefault() + item.Qty.GetValueOrDefault();
                    this.PIDetail.Update(detail);
                }
                sc.Complete();

                item.Description = PXMessages.LocalizeFormatNoPrefixNLA(Messages.PILineUpdated,
                                                                        AddByBarCode.GetValueExt <INBarCodeItem.inventoryID>(item).ToString().Trim(),
                                                                        Setup.Current.UseInventorySubItem == true ? ":" + AddByBarCode.GetValueExt <INBarCodeItem.subItemID>(item) : string.Empty,
                                                                        AddByBarCode.GetValueExt <INBarCodeItem.qty>(item),
                                                                        item.UOM,
                                                                        detail.LineNbr);
            }
            AddByBarCode.Reset(true);
            this.AddByBarCode.View.RequestRefresh();
            this.SelectTimeStamp();
        }
        protected virtual int?GetOrCreatePaymentProfilrByTran(V2.TransactionData tranData, ICCPayment pDoc)
        {
            int?instanceID;

            try
            {
                V2.TranProfile profile = null;
                if (tranData.CustomerId != null && tranData.PaymentId != null)
                {
                    profile = new V2.TranProfile()
                    {
                        CustomerProfileId = tranData.CustomerId, PaymentProfileId = tranData.PaymentId
                    };
                    ICCPaymentProfile cpm = null;
                    try
                    {
                        cpm = PrepeareCpmRecord();
                    }
                    catch (Exception ex)
                    {
                        var v = ex;
                    }
                    cpm.CustomerCCPID = tranData.CustomerId;
                }

                ExternalTransactionState state = GetActiveTransactionState();
                if (profile == null && state.IsPreAuthorized)
                {
                    profile = GetCustomerProfileFromDoc(pDoc);
                }

                if (profile == null)
                {
                    profile = GetOrCreateCustomerProfileByTranId(tranData.TranID);
                }

                instanceID = GetInstanceId(profile);

                using (PXTransactionScope tran = new PXTransactionScope())
                {
                    if (instanceID == PaymentTranExtConstants.NewPaymentProfile)
                    {
                        instanceID = CreatePaymentProfile(profile);
                    }
                    CreateCustomerProcessingCenterRecord(profile);
                    tran.Complete();
                }
            }
            finally
            {
                NewCpm.Cache.Clear();
                NewCpmd.Cache.Clear();
            }
            pDoc.PMInstanceID = instanceID;
            return(instanceID);
        }
Beispiel #30
0
        public virtual void MyPersist()
        {
            serviceOrderIsAlreadyUpdated = false;
            serviceOrderRowPersistedPassedWithStatusAbort = false;
            insertingServiceOrder = false;

            try
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    try
                    {
                        base.Persist(typeof(FSServiceOrder), PXDBOperation.Insert);
                        base.Persist(typeof(FSServiceOrder), PXDBOperation.Update);
                    }
                    catch
                    {
                        Caches[typeof(FSServiceOrder)].Persisted(true);
                        throw;
                    }

                    try
                    {
                        if (RecalculateExternalTaxesSync)
                        {
                            RecalculateExternalTaxes();
                            this.SelectTimeStamp();
                        }

                        base.Persist();

                        if (!RecalculateExternalTaxesSync) //When the calling process is the 'UI' thread.
                        {
                            RecalculateExternalTaxes();
                        }
                    }
                    catch
                    {
                        if (serviceOrderRowPersistedPassedWithStatusAbort == false)
                        {
                            Caches[typeof(FSServiceOrder)].Persisted(true);
                        }

                        throw;
                    }

                    ts.Complete();
                }
            }
            finally
            {
                serviceOrderIsAlreadyUpdated = false;
                serviceOrderRowPersistedPassedWithStatusAbort = false;
                insertingServiceOrder = false;
            }
        }
		public override void Persist()
		{
			CopyFreightNotesAndFilesToARTran();

			foreach (ARTran tran in Transactions.Cache.Deleted)
			{
				ARTran siblings = PXSelect<ARTran, Where<ARTran.sOOrderType, Equal<Required<ARTran.sOOrderType>>,
					And<ARTran.sOOrderNbr, Equal<Required<ARTran.sOOrderNbr>>,
					And<ARTran.sOShipmentType, Equal<Required<ARTran.sOShipmentType>>,
					And<ARTran.sOShipmentNbr, Equal<Required<ARTran.sOShipmentNbr>>,
					And<ARTran.tranType, Equal<Required<ARTran.tranType>>,
					And<ARTran.refNbr, Equal<Required<ARTran.refNbr>>>>>>>>>.SelectWindowed(this, 0, 1,
					tran.SOOrderType, tran.SOOrderNbr, tran.SOShipmentType, tran.SOShipmentNbr, tran.TranType, tran.RefNbr);

				if (siblings != null && siblings.LineType != SOLineType.Freight)
				{
					throw new PXException(Messages.PartialInvoice);
				}
			}

			foreach (ARInvoice invoice in Document.Cache.Deleted)
			{
				foreach (SOInvoice ext in SODocument.Cache.Deleted)
				{
					if (string.Equals(ext.DocType, invoice.DocType) && string.Equals(ext.RefNbr, invoice.RefNbr) && 
						(invoice.IsCCPayment == true ||ext.IsCCPayment == true) && ccProcTran.View.SelectMultiBound( new object[] { invoice, ext }).Count > 0)
					{
						ARPaymentEntry docgraph = PXGraph.CreateInstance<ARPaymentEntry>();
						docgraph.AutoPaymentApp = true;
						docgraph.arsetup.Current.HoldEntry = false;
						docgraph.arsetup.Current.RequireControlTotal = false;

						ARPayment payment = new ARPayment()
						{
							DocType = ARDocType.Payment,
							AdjDate = ext.AdjDate,
							AdjFinPeriodID = ext.AdjFinPeriodID
						};

						payment = PXCache<ARPayment>.CreateCopy(docgraph.Document.Insert(payment));
						payment.CustomerID = invoice.CustomerID;
						payment.CustomerLocationID = invoice.CustomerLocationID;
						payment.ARAccountID = invoice.ARAccountID;
						payment.ARSubID = invoice.ARSubID;

                        payment.PaymentMethodID = ext.PaymentMethodID;
                        payment.PMInstanceID = ext.PMInstanceID;
						payment.CashAccountID = ext.CashAccountID;
						payment.ExtRefNbr = ext.ExtRefNbr ?? string.Format(AR.Messages.ARAutoPaymentRefNbrFormat, payment.DocDate);
						payment.CuryOrigDocAmt = ext.CuryPaymentAmt;

						docgraph.Document.Update(payment);

						using (PXTransactionScope ts = new PXTransactionScope())
						{
							docgraph.Save.Press();

							PXDatabase.Update<CCProcTran>(
								new PXDataFieldAssign("DocType", docgraph.Document.Current.DocType),
								new PXDataFieldAssign("RefNbr", docgraph.Document.Current.RefNbr),
								new PXDataFieldRestrict("DocType", PXDbType.Char, 3, ext.DocType, PXComp.EQ),
								new PXDataFieldRestrict("RefNbr", PXDbType.NVarChar, 15, ext.RefNbr, PXComp.EQ)
								);

							int i = 0;
							bool ccproctranupdated = false;

							foreach (SOOrderShipment order in PXSelect<SOOrderShipment,
								Where<SOOrderShipment.invoiceType, Equal<Required<SOOrderShipment.invoiceType>>,
								And<SOOrderShipment.invoiceNbr, Equal<Required<SOOrderShipment.invoiceNbr>>>>>.Select(docgraph, ext.DocType, ext.RefNbr))
							{
								ccproctranupdated |= PXDatabase.Update<CCProcTran>(
									new PXDataFieldAssign("DocType", docgraph.Document.Current.DocType),
									new PXDataFieldAssign("RefNbr", docgraph.Document.Current.RefNbr),
									new PXDataFieldRestrict("OrigDocType", PXDbType.Char, 3, order.OrderType, PXComp.EQ),
									new PXDataFieldRestrict("OrigRefNbr", PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ),
									new PXDataFieldRestrict("RefNbr", PXDbType.NVarChar, 15, null, PXComp.ISNULL)
									);

								if (ccproctranupdated && i > 0)
								{
									throw new PXException(AR.Messages.ERR_CCMultiplyPreauthCombined);
								}

								i++;
							}

							docgraph.ccProcTran.View.Clear();
							docgraph.Document.Cache.RaiseRowSelected(docgraph.Document.Current);

							PXFieldState voidState;
							if ((voidState = (PXFieldState)docgraph.voidCheck.GetState(Document.Current)) == null || voidState.Enabled == false)
							{
								throw new PXException(AR.Messages.ERR_CCTransactionMustBeVoided);
							}

							List<object> tovoid = new List<object>();
							tovoid.Add(docgraph.Document.Current);

							foreach(object item in docgraph.voidCheck.Press(new PXAdapter(new DummyView(docgraph, docgraph.Document.View.BqlSelect, tovoid)))) { ; }

							base.Persist();

							ts.Complete();
						}

						return;
					}
				}
			}

			foreach (ARAdjust adj in Adjustments.Cache.Inserted)
			{
				if (adj.CuryAdjdAmt == 0m)
				{
					Adjustments.Cache.SetStatus(adj, PXEntryStatus.InsertedDeleted);
				}
			}

			foreach (ARAdjust adj in Adjustments.Cache.Updated)
			{
				if (adj.CuryAdjdAmt == 0m)
				{
					Adjustments.Cache.SetStatus(adj, PXEntryStatus.Deleted);
				}
			}

			foreach (ARInvoice ardoc in Document.Cache.Cached)
			{
				if ((Document.Cache.GetStatus(ardoc) == PXEntryStatus.Inserted || Document.Cache.GetStatus(ardoc) == PXEntryStatus.Updated) && ardoc.DocType == ARDocType.Invoice && ardoc.Released == false && ardoc.ApplyPaymentWhenTaxAvailable != true)
				{
					SOInvoice ext = SODocument.Select(ardoc.DocType, ardoc.RefNbr);

					if (ardoc.CuryDocBal - ardoc.CuryOrigDiscAmt - ext.CuryPaymentTotal - ext.CuryCCCapturedAmt < 0m)
					{
						foreach (PXResult<ARAdjust> res in Adjustments_Raw.View.SelectMultiBound(new object[] { ardoc }))
						{
							ARAdjust adj = res;
							if (Adjustments.Cache.GetStatus(adj) == PXEntryStatus.Notchanged)
							{
								Adjustments.Cache.SetStatus(adj, PXEntryStatus.Updated);
							}
							Adjustments.Cache.RaiseExceptionHandling<ARAdjust.curyAdjdAmt>(adj, adj.CuryAdjdAmt, new PXSetPropertyException(AR.Messages.Application_Amount_Cannot_Exceed_Document_Amount));
							throw new PXException(AR.Messages.Application_Amount_Cannot_Exceed_Document_Amount);
						}
					}
				}
			}

			base.Persist();
		}
		protected void PersistRecord(Package package, object record)
		{
			if (record == null) return;

			var cache = package.Graph.Caches[record.GetType()];
			var status = cache.GetStatus(record);
			try
			{
				using(var ts = new PXTransactionScope())
				{
					switch (status)
					{
						case PXEntryStatus.Updated:
							cache.Persist(record, PXDBOperation.Update);
							break;
						case PXEntryStatus.Inserted:
							cache.Persist(record, PXDBOperation.Insert);
							break;
						case PXEntryStatus.Deleted:
							cache.Persist(record, PXDBOperation.Delete);
							break;
						default:
							throw new InvalidOperationException();
					}
					ts.Complete();
				}
			}
			catch (Exception)
			{
				cache.Remove(record);
				throw;
			}
		}