Beispiel #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public VATMaint()
        {
            _oAuthApplication = PXSelectReadonly <HMRCOAuthApplication,
                                                  Where <HMRCOAuthApplication.applicationName, Equal <Required <HMRCOAuthApplication.applicationName> > > >
                                .SelectSingleBound(this, null, _applicationName);

            if (_oAuthApplication != null)
            {
                if (!String.IsNullOrEmpty(_oAuthApplication.UsrServerUrl))
                {
                    urlSite = _oAuthApplication.UsrServerUrl;
                }

                _oAuthToken = PXSelectReadonly <OAuthToken, Where <OAuthToken.applicationID, Equal <Required <OAuthToken.applicationID> > > >
                              .SelectSingleBound(this, null, _oAuthApplication.ApplicationID);
            }
            VATProvider = new VATApi(urlSite, _oAuthApplication, _oAuthToken, vrn, UpdateOAuthToken);
            SetVRN(Period_Header.Current);

            signInHMRC.SetEnabled(_oAuthToken == null);
            sendVATreturn.SetEnabled(false);
            checkVATReturn.SetEnabled(false);
            PXUIFieldAttribute.SetEnabled <VATPeriodFilter.periodKey>(Period_Header.Cache, null, _oAuthToken != null);
            PXUIFieldAttribute.SetVisibility <TaxReportLine.lineNbr>(Period_Details.Cache, null, PXUIVisibility.Invisible);
            PXUIFieldAttribute.SetVisibility <TaxReportLine.lineNbr>(Period_Details.Cache, null, PXUIVisibility.Invisible);
        }
        protected virtual void Segment_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            Segment row = e.Row as Segment;

            if (row == null)
            {
                return;
            }

            if (sender.GetStatus(row) == PXEntryStatus.Inserted)
            {
                sender.RaiseExceptionHandling <Segment.segmentID>(row, row.SegmentID,
                                                                  new PXSetPropertyException(Messages.SegmentedKeyAddingNewSegmentRequiresUpdating, PXErrorLevel.RowWarning));
            }

            if (row.ParentDimensionID != null)
            {
                Segment parent = row;
                if (row.Inherited != true)
                {
                    parent = PXSelectReadonly <Segment, Where <Segment.dimensionID, Equal <Current <Segment.parentDimensionID> >,
                                                               And <Segment.segmentID, Equal <Current <Segment.segmentID> > > > > .SelectSingleBound(this, new object[] { row });
                }
                PXUIFieldAttribute.SetEnabled(sender, row, false);
                PXUIFieldAttribute.SetEnabled <Segment.descr>(sender, row, true);
                PXUIFieldAttribute.SetEnabled <Segment.editMask>(sender, row, true);
                PXUIFieldAttribute.SetEnabled <Segment.autoNumber>(sender, row, true);
                PXUIFieldAttribute.SetEnabled <Segment.validate>(sender, row, parent != null && parent.Validate != true);
            }
        }
Beispiel #3
0
        protected virtual void SOCreateFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            SOCreateFilter filter = Filter.Current;

            FixedDemand.SetProcessDelegate(list => SOCreateProc(list, filter.PurchDate));

            TimeSpan        span;
            Exception       message;
            PXLongRunStatus status = PXLongOperation.GetStatus(this.UID, out span, out message);

            PXUIFieldAttribute.SetVisible <SOLine.orderNbr>(Caches[typeof(SOLine)], null, (status == PXLongRunStatus.Completed || status == PXLongRunStatus.Aborted));

            if (PXAccess.FeatureInstalled <FeaturesSet.warehouse>())
            {
                INSite toxicsite = PXSelectReadonly <INSite,
                                                     Where <INSite.siteID, Equal <Current <SOCreateFilter.siteID> >,
                                                            And <INSite.active, Equal <True>,
                                                                 And <Where <INSite.addressID, IsNull, Or <INSite.contactID, IsNull> > > > > > .SelectSingleBound(this, new object[] { e.Row });

                if (toxicsite != null)
                {
                    throw new PXSetupNotEnteredException <INSite, INSite.siteCD>(Messages.WarehouseWithoutAddressAndContact, toxicsite.SiteCD, toxicsite.SiteCD);
                }
            }
        }
Beispiel #4
0
        public virtual void EnsureCanCancel(ARInvoice doc, bool isCorrection)
        {
            if (doc.DocType != ARDocType.Invoice)
            {
                throw new PXException(Messages.CantCancelDocType, doc.DocType);
            }

            if (doc.InstallmentCntr > 0)
            {
                throw new PXException(Messages.CantCancelMultipleInstallmentsInvoice);
            }

            var arAdjustGroups = PXSelectGroupBy <ARAdjust,
                                                  Where <ARAdjust.adjdDocType, Equal <Current <ARInvoice.docType> >, And <ARAdjust.adjdRefNbr, Equal <Current <ARInvoice.refNbr> > > >,
                                                  Aggregate <
                                                      GroupBy <ARAdjust.adjgDocType, GroupBy <ARAdjust.adjgRefNbr, GroupBy <ARAdjust.released,
                                                                                                                            Sum <ARAdjust.curyAdjdAmt> > > > > >
                                 .SelectMultiBound(Base, new[] { doc })
                                 .RowCast <ARAdjust>().ToList();

            if (arAdjustGroups.Any(a => a.Released == false))
            {
                throw new PXException(Messages.CantCancelInvoiceWithUnreleasedApplications);
            }

            var nonReversedCreditMemo = arAdjustGroups.FirstOrDefault(a => a.CuryAdjdAmt != 0m && a.AdjgDocType == ARDocType.CreditMemo);

            if (nonReversedCreditMemo != null)
            {
                throw new PXException(Messages.CantCancelInvoiceWithCM, nonReversedCreditMemo.AdjdRefNbr, nonReversedCreditMemo.AdjgRefNbr);
            }

            var nonReversedApplication = arAdjustGroups.FirstOrDefault(a => a.CuryAdjdAmt != 0m);

            if (nonReversedApplication != null)
            {
                throw new PXException(Messages.CantCancelInvoiceWithPayment, nonReversedApplication.AdjdRefNbr, nonReversedApplication.AdjgRefNbr);
            }

            ARTran directSale = PXSelectReadonly <ARTran,
                                                  Where <ARTran.tranType, Equal <Current <ARInvoice.docType> >, And <ARTran.refNbr, Equal <Current <ARInvoice.refNbr> >,
                                                                                                                     And <ARTran.invtMult, NotEqual <short0>, And <ARTran.lineType, Equal <SOLineType.inventory> > > > > >
                                .SelectSingleBound(Base, new[] { doc });

            if (directSale != null)
            {
                throw new PXException(Messages.CantCancelInvoiceWithDirectStockSales, doc.RefNbr);
            }

            SOOrderShipment notRequireShipment = PXSelectReadonly <SOOrderShipment,
                                                                   Where <SOOrderShipment.invoiceType, Equal <Current <ARInvoice.docType> >, And <SOOrderShipment.invoiceNbr, Equal <Current <ARInvoice.refNbr> >,
                                                                                                                                                  And <SOOrderShipment.shipmentNbr, Equal <Constants.noShipmentNbr> > > > >
                                                 .SelectSingleBound(Base, new[] { doc });

            if (notRequireShipment != null)
            {
                throw new PXException(Messages.CantCancelInvoiceWithOrdersNotRequiringShipments, doc.RefNbr);
            }
        }
Beispiel #5
0
        public static bool RelatedForBranchReleasedTransactionExists(PXGraph graph, int?branchID)
        {
            GLTran tran = PXSelectReadonly <GLTran,
                                            Where <GLTran.branchID, Equal <Required <GLTran.branchID> >,
                                                   And <GLTran.released, Equal <True> > > >
                          .SelectSingleBound(graph, null, branchID);

            return(tran != null);
        }
Beispiel #6
0
 public static GLHistory GetRelatedToBranchGLHistory(PXGraph graph, int?[] branchIDs)
 {
     if (branchIDs == null || branchIDs.IsEmpty())
     {
         return(null);
     }
     return(PXSelectReadonly <GLHistory,
                              Where <GLHistory.branchID, In <Required <GLHistory.branchID> > > >
            .SelectSingleBound(graph, null, branchIDs));
 }
Beispiel #7
0
        public override void Persist()
        {
            OrganizationLedgerLinkMaint linkMaint = GetExtension <OrganizationLedgerLinkMaint>();

            foreach (Ledger ledger in LedgerRecords.Cache.Deleted)
            {
                CanBeLedgerDeleted(ledger);
            }

            foreach (Ledger ledger in LedgerRecords.Cache.Updated)
            {
                string origBalanceType = LedgerRecords.Cache.GetValueOriginal <Ledger.balanceType>(ledger) as string;

                if (origBalanceType != ledger.BalanceType)
                {
                    GLTran existingReleasedTran = PXSelectReadonly <GLTran,
                                                                    Where <GLTran.ledgerID, Equal <Required <GLTran.ledgerID> >,
                                                                           And <GLTran.released, Equal <True> > > >
                                                  .SelectSingleBound(this, null, ledger.LedgerID);

                    if (existingReleasedTran != null)
                    {
                        throw new PXException(Messages.TheTypeOfTheLedgerCannotBeChangedBecauseAtLeastOneReleasedGLTransactionExists, ledger.LedgerCD);
                    }

                    if (ledger.BalanceType == LedgerBalanceType.Actual)
                    {
                        CanBeLedgerSetAsActual(ledger, linkMaint);
                    }

                    if (origBalanceType == LedgerBalanceType.Actual)
                    {
                        SetActualLedgerIDNullInRelatedCompanies(ledger, linkMaint);
                    }
                }
            }

            Organization[] organizations = OrganizationView.Cache.Updated.Cast <Organization>()
                                           .Select(PXCache <Organization> .CreateCopy).ToArray();

            using (var tranScope = new PXTransactionScope())
            {
                base.Persist();

                OrganizationView.Cache.Clear();

                linkMaint.OnPersist(organizations);

                tranScope.Complete();
            }
        }
Beispiel #8
0
        public virtual void CheckRelatedGLTranDoesNotExist(int?[] branchIDs)
        {
            if (branchIDs == null || branchIDs.IsEmpty())
            {
                return;
            }

            GLTran tran = PXSelectReadonly <GLTran,
                                            Where <GLTran.branchID, In <Required <GLTran.branchID> > > >
                          .SelectSingleBound(Graph, null, branchIDs);

            if (tran != null)
            {
                Branch branch = BranchMaint.FindBranchByID(Graph, tran.BranchID);

                throw new PXException(Messages.TheBranchOrBranchesCannotBeDeletedBecauseTheRelatedTransactionHasBeenPosted,
                                      branch.BranchCD.Trim(),
                                      tran.ToString());
            }
        }
        protected virtual void CanBeLedgerDeleted(Ledger ledger)
        {
            CheckLinksToOrganizationsOnDelete(ledger);

            Batch existingBatch = PXSelectReadonly <Batch,
                                                    Where <Batch.ledgerID, Equal <Required <Batch.ledgerID> > > >
                                  .SelectSingleBound(this, null, ledger.LedgerID);

            if (existingBatch != null)
            {
                throw new PXException(Messages.TheLedgerCannotBeDeletedBecauseAtLeastOneGeneralLedgerBatchExists, ledger.LedgerCD);
            }

            GLTran existingTran = PXSelectReadonly <GLTran,
                                                    Where <GLTran.ledgerID, Equal <Required <GLTran.ledgerID> > > >
                                  .SelectSingleBound(this, null, ledger.LedgerID);

            if (existingTran != null)
            {
                throw new PXException(Messages.TheLedgerCannotBeDeletedBecauseAtLeastOneGeneralLedgerTransactionHasBeenReleased, ledger.LedgerCD);
            }
        }
        protected static void Approve(List <EPOwned> items, bool approve)
        {
            EntityHelper helper = new EntityHelper(new PXGraph());
            var          graphs = new Dictionary <Type, PXGraph>();

            bool errorOccured = false;

            foreach (EPOwned item in items)
            {
                try
                {
                    PXProcessing <EPApproval> .SetCurrentItem(item);

                    if (item.RefNoteID == null)
                    {
                        throw new PXException(Messages.ApprovalRefNoteIDNull);
                    }
                    object row = helper.GetEntityRow(item.RefNoteID.Value, true);

                    if (row == null)
                    {
                        throw new PXException(Messages.ApprovalRecordNotFound);
                    }

                    Type    cahceType = row.GetType();
                    Type    graphType = helper.GetPrimaryGraphType(row, false);
                    PXGraph graph;
                    if (!graphs.TryGetValue(graphType, out graph))
                    {
                        graphs.Add(graphType, graph = PXGraph.CreateInstance(graphType));
                    }

                    EPApproval approval = PXSelectReadonly <EPApproval,
                                                            Where <EPApproval.approvalID, Equal <Current <EPOwned.approvalID> > > >
                                          .SelectSingleBound(graph, new object[] { item });

                    if (approval.Status == EPApprovalStatus.Pending)
                    {
                        graph.Clear();
                        graph.Caches[cahceType].Current = row;
                        graph.Caches[cahceType].SetStatus(row, PXEntryStatus.Notchanged);
                        PXAutomation.GetView(graph);
                        string approved = typeof(EPExpenseClaim.approved).Name;
                        if (graph.AutomationView != null)
                        {
                            PXAutomation.GetStep(graph,
                                                 new object[] { graph.Views[graph.AutomationView].Cache.Current },
                                                 BqlCommand.CreateInstance(
                                                     typeof(Select <>),
                                                     graph.Views[graph.AutomationView].Cache.GetItemType())
                                                 );
                        }
                        string actionName = approve ? nameof(Approve) : nameof(Reject);
                        if (graph.Actions.Contains(actionName))
                        {
                            graph.Actions[actionName].Press();
                        }
                        else if (graph.AutomationView != null)
                        {
                            PXView     view    = graph.Views[graph.AutomationView];
                            BqlCommand select  = view.BqlSelect;
                            PXAdapter  adapter = new PXAdapter(new PXView.Dummy(graph, select, new List <object> {
                                row
                            }));
                            adapter.Menu = actionName;
                            if (graph.Actions.Contains("Action"))
                            {
                                if (!CheckRights(graphType, cahceType))
                                {
                                    throw new PXException(Messages.DontHaveAppoveRights);
                                }
                                foreach (var i in graph.Actions["Action"].Press(adapter))
                                {
                                    ;
                                }
                            }
                            else
                            {
                                throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.AutomationNotConfigured, graph));
                            }
                            //PXAutomation.ApplyAction(graph, graph.Actions["Action"], "Approve", row, out rollback);
                        }
                        else if (graph.Caches[cahceType].Fields.Contains(approved))
                        {
                            object upd = graph.Caches[cahceType].CreateCopy(row);
                            graph.Caches[cahceType].SetValue(upd, approved, true);
                            graph.Caches[cahceType].Update(upd);
                        }
                        graph.Persist();
                    }
                    PXProcessing <EPApproval> .SetInfo(ActionsMessages.RecordProcessed);
                }
                catch (Exception ex)
                {
                    errorOccured = true;
                    PXProcessing <EPApproval> .SetError(ex);
                }
            }
            if (errorOccured)
            {
                throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
            }
        }
        protected virtual void EMailSyncAccount_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
        {
            var row = e.Row as EMailSyncAccount;

            if (row == null)
            {
                return;
            }

            if (row.EmployeeID != null && row.Address == null && row.IsVitrual == false)
            {
                foreach (PXResult <EPEmployee, Contact> result in PXSelectJoin <EPEmployee,
                                                                                InnerJoin <Contact,
                                                                                           On <EPEmployee.defContactID, Equal <Contact.contactID>, And <EPEmployee.parentBAccountID, Equal <Contact.bAccountID> > > >,
                                                                                Where <EPEmployee.bAccountID, Equal <Required <EPEmployee.bAccountID> > > > .Select(Base, row.EmployeeID))
                {
                    row.EmployeeCD = ((EPEmployee)result).AcctName;
                    row.OwnerID    = ((EPEmployee)result).UserID;
                    row.Address    = ((Contact)result).EMail;
                }
            }



            // Inserting a new record when SyncAccount is updated

            if (!(row.SyncAccount ?? false))
            {
                return;
            }

            if (row.EmailAccountID != null)
            {
                return;
            }
            EMailAccount account = null;

            UserPreferences prefs = null;

            if (row.OwnerID != null)
            {
                prefs = Base.UserSettings.Search <UserPreferences.userID>(row.OwnerID);
                if (prefs == null)
                {
                    prefs        = new UserPreferences();
                    prefs.UserID = row.OwnerID;
                    prefs        = Base.UserSettings.Insert(prefs);
                }
            }

            using (new PXReadDeletedScope())
            {
                account = PXSelectReadonly <EMailAccount, Where <EMailAccount.address, Equal <Required <EMailAccount.address> >,
                                                                 And <EMailAccount.emailAccountType, Equal <EmailAccountTypesAttribute.exchange> > > > .SelectSingleBound(Base, null, row.Address);

                if (account == null)
                {
                    account                      = new EMailAccount();
                    account.Description          = row.EmployeeCD;
                    account.Address              = row.Address;
                    account.EmailAccountType     = EmailAccountTypesAttribute.Exchange;
                    account.IncomingHostProtocol = IncomingMailProtocolsAttribute._EXCHANGE;
                    account.IncomingProcessing   = true;
                    account.ForbidRouting        = true;
                    account.CreateActivity       = true;
                    account.DefaultOwnerID       = row.OwnerID;

                    account = Base.EmailAccounts.Insert(account);
                }
                else
                {
                    account.DeletedDatabaseRecord = false;
                    Base.EmailAccounts.Update(account);
                }
            }
            row.EmailAccountID = account.EmailAccountID;


            if (prefs != null && Base.EmailAccounts.Cache.GetStatus(account) == PXEntryStatus.Inserted)
            {
                prefs.DefaultEMailAccountID = account.EmailAccountID;
                prefs = Base.UserSettings.Update(prefs) as UserPreferences;
            }
        }
        protected virtual void Contact_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            Contact row = e.Row as Contact;

            if (row == null)
            {
                return;
            }

            var isNotInserted = sender.GetStatus(row) != PXEntryStatus.Inserted;

            Contact.AllowDelete = row.ContactType == ContactTypesAttribute.Person;
            PXUIFieldAttribute.SetEnabled <Contact.isActive>(Contact.Cache, row, row.ContactType == ContactTypesAttribute.Person);
            PXUIFieldAttribute.SetEnabled <Contact.classID>(Contact.Cache, row, row.ContactType == ContactTypesAttribute.Person);
            PXUIFieldAttribute.SetEnabled <Contact.isAddressSameAsMain>(Contact.Cache, row, row.ContactType == ContactTypesAttribute.Person);

            copyBAccountContactInfo.SetEnabled(row.ContactType == ContactTypesAttribute.Person);
            Answers.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            Answers.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Answers.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Activities.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            Activities.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Activities.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Relations.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Relations.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Relations.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Opportunities.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Opportunities.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Opportunities.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Cases.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Cases.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Cases.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Members.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Members.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Members.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Subscriptions.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Subscriptions.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Subscriptions.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            NWatchers.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            NWatchers.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            NWatchers.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            User.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            User.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            User.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;
            User.Cache.AllowSelect = row.ContactType == ContactTypesAttribute.Person;
            User.Cache.ClearQueryCache();

            Roles.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            Roles.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Roles.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;
            Roles.Cache.AllowSelect = row.ContactType == ContactTypesAttribute.Person;
            Roles.Cache.ClearQueryCache();

            UserRoles.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            UserRoles.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            UserRoles.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;
            UserRoles.Cache.AllowSelect = row.ContactType == ContactTypesAttribute.Person;
            UserRoles.Cache.ClearQueryCache();

            var bAccount = row.BAccountID.
                           With <int?, BAccount>(_ => (BAccount)PXSelect <BAccount,
                                                                          Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .
                                                 Select(this, _));
            var isCustomerOrProspect = bAccount == null ||
                                       bAccount.Type == BAccountType.CustomerType ||
                                       bAccount.Type == BAccountType.ProspectType ||
                                       bAccount.Type == BAccountType.CombinedType;

            addOpportunity.SetEnabled(isNotInserted && isCustomerOrProspect);
            addCase.SetEnabled(isNotInserted && isCustomerOrProspect);

            PXUIFieldAttribute.SetEnabled <Contact.contactID>(sender, row, true);
            PXUIFieldAttribute.SetEnabled <Contact.bAccountID>(sender, row, row.ContactType == ContactTypesAttribute.Person);

            CRContactClass contactClass = row.ClassID.
                                          With(_ => (CRContactClass)PXSelectReadonly <CRContactClass,
                                                                                      Where <CRContactClass.classID, Equal <Required <CRContactClass.classID> > > > .
                                               SelectSingleBound(this, null, _));

            if (contactClass != null)
            {
                Activities.DefaultEMailAccountId = contactClass.DefaultEMailAccountID;
            }

            bool isUserInserted = row.UserID == null || User.Cache.GetStatus(User.Current) == PXEntryStatus.Inserted;
            bool hasLoginType   = isUserInserted && User.Current != null && User.Current.LoginTypeID != null;

            PXUIFieldAttribute.SetEnabled <Users.loginTypeID>(User.Cache, User.Current, isUserInserted && row.IsActive == true);
            PXUIFieldAttribute.SetEnabled <Users.username>(User.Cache, User.Current, this.IsContractBasedAPI || hasLoginType);
            PXUIFieldAttribute.SetEnabled <Users.generatePassword>(User.Cache, User.Current, this.IsContractBasedAPI || hasLoginType);
            PXUIFieldAttribute.SetEnabled <Users.password>(User.Cache, User.Current, this.IsContractBasedAPI || (hasLoginType && User.Current.GeneratePassword != true));

            var employeeHasUserAttached = row.ContactType == ContactTypesAttribute.Employee && User.Current != null;

            PXDefaultAttribute.SetPersistingCheck <Contact.eMail>(sender, row,
                                                                  employeeHasUserAttached || (hasLoginType && User.Current.Username != null)
                ? PXPersistingCheck.NullOrBlank
                : PXPersistingCheck.Nothing);
            PXUIFieldAttribute.SetRequired <Contact.eMail>(sender, employeeHasUserAttached || (hasLoginType && User.Current.Username != null));

            User.Current = (Users)User.View.SelectSingleBound(new[] { e.Row });

            if (row.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated || row.DuplicateFound == true)
            {
                sender.RaiseExceptionHandling <Contact.duplicateStatus>(row,
                                                                        null, new PXSetPropertyException(Messages.ContactHavePossibleDuplicates, PXErrorLevel.Warning, row.ContactID));
            }
        }
Beispiel #13
0
        protected virtual void EPExpenseClaimDetails_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            EPExpenseClaimDetails row = (EPExpenseClaimDetails)e.Row;

            if (row != null)
            {
                EPExpenseClaim claim = (EPExpenseClaim)PXSelect <EPExpenseClaim, Where <EPExpenseClaim.refNbr, Equal <Required <EPExpenseClaimDetails.refNbr> > > > .SelectSingleBound(this, new object[] { null }, row.RefNbr);

                bool enabledApprovalReceipt   = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null;
                bool enabledEditReceipt       = row.Hold == true || !enabledApprovalReceipt;
                bool enabledRefNbr            = true;
                bool enabledEmployeeAndBranch = enabledEditReceipt && !(row.ClaimCuryInfoID == null && cache.AllowUpdate && !string.IsNullOrEmpty(row.RefNbr));
                bool enabledFinancialDetails  = (row.Rejected != true) && (row.Released != true);

                if (claim != null)
                {
                    bool enabledEditClaim = (row.HoldClaim == true);
                    enabledEditReceipt = enabledEditReceipt && enabledEditClaim;
                    EPExpenseClaimDetails receiptnBase = (EPExpenseClaimDetails)PXSelectReadonly <EPExpenseClaimDetails, Where <EPExpenseClaimDetails.claimDetailID, Equal <Required <EPExpenseClaimDetails.claimDetailID> > > > .SelectSingleBound(this, new object[] { null }, row.ClaimDetailID);

                    enabledRefNbr            = (receiptnBase?.RefNbr == null);
                    enabledEmployeeAndBranch = false;
                    enabledFinancialDetails  = enabledFinancialDetails && enabledEditClaim;
                }

                Approval.AllowSelect = enabledApprovalReceipt;
                Delete.SetEnabled(enabledEditReceipt && claim == null);
                PXUIFieldAttribute.SetEnabled(cache, row, enabledEditReceipt);
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.claimDetailID>(cache, row, true);
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.refNbr>(cache, row, enabledRefNbr);
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.employeeID>(cache, row, enabledEmployeeAndBranch);
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.branchID>(cache, row, enabledEmployeeAndBranch);
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.expenseAccountID>(cache, row, enabledFinancialDetails);
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.expenseSubID>(cache, row, enabledFinancialDetails);
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.salesAccountID>(cache, row, enabledFinancialDetails && (row.Billable == true));
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.salesSubID>(cache, row, enabledFinancialDetails && (row.Billable == true));
                PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxCategoryID>(cache, row, enabledFinancialDetails);
                action.SetEnabled("Submit", cache.GetStatus(row) != PXEntryStatus.Inserted && row.Hold == true);

                if (row.ContractID != null && (bool)row.Billable && row.TaskID != null)
                {
                    PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(this, row.TaskID);

                    if (task != null && !(bool)task.VisibleInAP)
                    {
                        cache.RaiseExceptionHandling <EPExpenseClaimDetails.taskID>(e.Row, task.TaskCD, new PXSetPropertyException(PM.Messages.TaskInvisibleInModule, task.TaskCD, GL.BatchModule.AP));
                    }
                }

                CurrencyInfo info = (CurrencyInfo)PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Current <EPExpenseClaimDetails.curyInfoID> > > > .SelectSingleBound(this, new object[] { row });

                if (info != null && info.CuryRateTypeID != null && info.CuryEffDate != null && row.ExpenseDate != null && info.CuryEffDate < row.ExpenseDate)
                {
                    CurrencyRateType ratetype = (CurrencyRateType)PXSelectorAttribute.Select <CurrencyInfo.curyRateTypeID>(currencyinfo.Cache, info);
                    if (ratetype != null && ratetype.RateEffDays > 0 &&
                        ((TimeSpan)(row.ExpenseDate - info.CuryEffDate)).Days > ratetype.RateEffDays)
                    {
                        PXRateIsNotDefinedForThisDateException exc = new PXRateIsNotDefinedForThisDateException(info.CuryRateTypeID, info.BaseCuryID, info.CuryID, (DateTime)row.ExpenseDate);
                        cache.RaiseExceptionHandling <EPExpenseClaimDetails.expenseDate>(e.Row, ((EPExpenseClaimDetails)e.Row).ExpenseDate, exc);
                    }
                }
                string message = PXUIFieldAttribute.GetError <CurrencyInfo.curyID>(currencyinfo.Cache, info);
                if (string.IsNullOrEmpty(message) && info != null && info.CuryRate == null)
                {
                    message = CM.Messages.RateNotFound;
                }
                if (string.IsNullOrEmpty(message))
                {
                    cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyID>(e.Row, null, null);
                }
                else
                {
                    cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyID>(e.Row, null, new PXSetPropertyException(message, PXErrorLevel.Warning));
                }
            }
        }