Exemple #1
0
        protected virtual IEnumerable assets()
        {
            DisposalFilter filter = Filter.Current;

            PXSelectBase <FixedAsset> cmd = new PXSelectJoin <FixedAsset,
                                                              InnerJoin <FADetails, On <FixedAsset.assetID, Equal <FADetails.assetID> >,
                                                                         LeftJoin <Account, On <FixedAsset.fAAccountID, Equal <Account.accountID> > > >,
                                                              Where <FADetails.status, NotEqual <FixedAssetStatus.disposed>,
                                                                     And <FADetails.status, NotEqual <FixedAssetStatus.hold>,
                                                                          And <FADetails.status, NotEqual <FixedAssetStatus.suspended> > > > >(this);

            if (filter.BookID != null)
            {
                cmd.Join <InnerJoin <FABookBalance, On <FABookBalance.assetID, Equal <FixedAsset.assetID> > > >();
                cmd.WhereAnd <Where <FABookBalance.bookID, Equal <Current <DisposalFilter.bookID> > > >();
            }

            if (filter.ClassID != null)
            {
                cmd.WhereAnd <Where <FixedAsset.classID, Equal <Current <DisposalFilter.classID> > > >();
            }
            if (PXAccess.FeatureInstalled <FeaturesSet.multipleCalendarsSupport>() || filter.OrgBAccountID != null)
            {
                cmd.WhereAnd <Where <FixedAsset.branchID, Inside <Current <DisposalFilter.orgBAccountID> > > >();
            }
            if (filter.ParentAssetID != null)
            {
                cmd.WhereAnd <Where <FixedAsset.parentAssetID, Equal <Current <DisposalFilter.parentAssetID> > > >();
            }

            int startRow  = PXView.StartRow;
            int totalRows = 0;

            List <PXFilterRow> newFilters = new List <PXFilterRow>();

            foreach (PXFilterRow f in PXView.Filters)
            {
                if (f.DataField.ToLower() == "status")
                {
                    f.DataField = "FADetails__Status";
                }
                newFilters.Add(f);
            }
            List <object> list = cmd.View.Select(PXView.Currents, null, PXView.Searches, PXView.SortColumns, PXView.Descendings, newFilters.ToArray(), ref startRow, PXView.MaximumRows, ref totalRows);

            PXView.StartRow = 0;
            return(list);
        }
        public virtual void VerifyPrepaidContractRelated(PXCache cache, FSBillingCycle fsBillingCycleRow)
        {
            if (fsBillingCycleRow.BillingBy == (string)cache.GetValueOriginal <FSBillingCycle.billingBy>(fsBillingCycleRow))
            {
                return;
            }

            if (Setup.Current != null)
            {
                int count = 0;

                if (Setup.Current.CustomerMultipleBillingOptions == false)
                {
                    count = PXSelectJoin <Customer,
                                          InnerJoin <FSBillingCycle,
                                                     On <FSBillingCycle.billingCycleID, Equal <FSxCustomer.billingCycleID> >,
                                                     InnerJoin <FSServiceOrder,
                                                                On <FSServiceOrder.customerID, Equal <Customer.bAccountID> > > >,
                                          Where <
                                              FSServiceOrder.billContractPeriodID, IsNotNull,
                                              And <
                                                  FSBillingCycle.billingCycleID, Equal <Required <FSBillingCycle.billingCycleID> > > > >
                            .Select(this, fsBillingCycleRow.BillingCycleID).Count;
                }
                else
                {
                    count = PXSelectJoin <FSCustomerBillingSetup,
                                          InnerJoin <FSSrvOrdType,
                                                     On <FSSrvOrdType.srvOrdType, Equal <FSCustomerBillingSetup.srvOrdType> >,
                                                     InnerJoin <FSServiceOrder,
                                                                On <FSServiceOrder.srvOrdType, Equal <FSSrvOrdType.srvOrdType>,
                                                                    And <FSServiceOrder.cBID, Equal <FSCustomerBillingSetup.cBID> > > > >,
                                          Where <
                                              FSServiceOrder.billContractPeriodID, IsNotNull,
                                              And <
                                                  FSCustomerBillingSetup.billingCycleID, Equal <Required <FSCustomerBillingSetup.billingCycleID> > > > >
                            .Select(this, fsBillingCycleRow.BillingCycleID).Count;
                }

                if (count > 0)
                {
                    cache.RaiseExceptionHandling <FSBillingCycle.billingCycleCD>(fsBillingCycleRow,
                                                                                 fsBillingCycleRow.BillingCycleCD,
                                                                                 new PXSetPropertyException(TX.Error.NO_UPDATE_BILLING_CYCLE_SERVICE_CONTRACT_RELATED, PXErrorLevel.Error));
                    throw new PXException(TX.Error.NO_UPDATE_BILLING_CYCLE_SERVICE_CONTRACT_RELATED);
                }
            }
        }
 public IEnumerable <PXResult <TaxTran, APRegister> > GetReportedTaxTransWithAdjdDocumentForAPPayments(string docType, string[] refNbrs, int?taxAgencyID, string taxPeriodID)
 {
     return(PXSelectJoin <TaxTran,
                          InnerJoin <APRegister,
                                     On <TaxTran.adjdDocType, Equal <APRegister.docType>,
                                         And <TaxTran.adjdRefNbr, Equal <APRegister.refNbr> > > >,
                          Where <TaxTran.tranType, Equal <Required <TaxTran.tranType> >,
                                 And <TaxTran.refNbr, In <Required <TaxTran.refNbr> >,
                                      And <TaxTran.vendorID, Equal <Required <TaxTran.vendorID> >,
                                           And <TaxTran.taxPeriodID, Equal <Required <TaxTran.taxPeriodID> >,
                                                And <TaxTran.voided, Equal <False>,
                                                     And <TaxTran.released, Equal <True>,
                                                          And <TaxTran.module, Equal <BatchModule.moduleAP> > > > > > > > >
            .Select(_graph, docType, refNbrs, taxAgencyID, taxPeriodID)
            .Cast <PXResult <TaxTran, APRegister> >());
 }
        protected new virtual IEnumerable Cancel(PXAdapter a)
        {
            if (a.Searches.Length == 1)
            {
                PXResult <SOOrderType> orderType = PXSelectJoin <SOOrderType,
                                                                 LeftJoin <SOOrderTypeOperation,
                                                                           On2 <SOOrderTypeOperation.FK.OrderType, And <SOOrderTypeOperation.operation, Equal <SOOrderType.defaultOperation> > > >,
                                                                 Where <SOOrderType.requireShipping, Equal <boolFalse>, Or <FeatureInstalled <FeaturesSet.inventory> > > > .Search <SOOrderType.orderType>(this, a.Searches[0]);

                if (orderType != null && (!soordertype.View.BqlSelect.Meet(soordertype.Cache, (SOOrderType)orderType) || !soordertype.View.BqlSelect.Meet(operations.Cache, PXResult.Unwrap <SOOrderTypeOperation>(orderType))))
                {
                    a.Searches[0] = null;
                }
            }
            return((new PXCancel <SOOrderType>(this, "Cancel")).Press(a));
        }
Exemple #5
0
        protected virtual IEnumerable items()
        {
            ScheduleProjectionFilter filter = Filter.Current;

            PXSelectBase <DRScheduleDetail> select = new PXSelectJoin <DRScheduleDetail,
                                                                       InnerJoin <DRSchedule, On <DRScheduleDetail.scheduleID, Equal <DRSchedule.scheduleID> >,
                                                                                  InnerJoin <DRDeferredCode, On <DRDeferredCode.deferredCodeID, Equal <DRScheduleDetail.defCode> > > >,
                                                                       Where <DRDeferredCode.method, Equal <DeferredMethodType.cashReceipt> > >(this);

            if (!string.IsNullOrEmpty(filter.DeferredCode))
            {
                select.WhereAnd <Where <DRScheduleDetail.defCode, Equal <Current <ScheduleProjectionFilter.deferredCode> > > >();
            }

            return(select.Select());
        }
Exemple #6
0
        protected virtual void _(Events.FieldVerifying <PMChangeOrderClass, PMChangeOrderClass.isRevenueBudgetEnabled> e)
        {
            if ((bool?)e.NewValue != true)
            {
                var select = new PXSelectJoin <PMChangeOrderBudget,
                                               InnerJoin <PMChangeOrder, On <PMChangeOrderBudget.refNbr, Equal <PMChangeOrder.refNbr> > >,
                                               Where <PMChangeOrderBudget.type, Equal <GL.AccountType.income>,
                                                      And <PMChangeOrder.classID, Equal <Current <PMChangeOrderClass.classID> > > > >(this);

                PMChangeOrderBudget res = select.SelectWindowed(0, 1);
                if (res != null)
                {
                    throw new PXSetPropertyException <PMChangeOrderClass.isRevenueBudgetEnabled>(Messages.ClassContainsRevenueBudget);
                }
            }
        }
 protected IEnumerable preferredVendorItem()
 {
     foreach (var item in PXSelectJoin <POVendorInventory,
                                        InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <POVendorInventory.inventoryID> > >,
                                        Where <POVendorInventory.inventoryID, Equal <Current <INItemSite.inventoryID> >,
                                               And <POVendorInventory.vendorID, Equal <Current <INItemSite.preferredVendorID> >,
                                                    And <POVendorInventory.subItemID, Equal <Current <InventoryItem.defaultSubItemID> >,
                                                         And <POVendorInventory.purchaseUnit, Equal <InventoryItem.purchaseUnit>,
                                                              And <Where <POVendorInventory.vendorLocationID, Equal <Current <INItemSite.preferredVendorLocationID> >,
                                                                          Or <POVendorInventory.vendorLocationID, IsNull> > > > > > >,
                                        OrderBy <Desc <POVendorInventory.vendorLocationID,
                                                       Asc <POVendorInventory.recordID> > > > .SelectSingleBound(this, null))
     {
         yield return(item);
     }
 }
        protected virtual IAddressBase GetToAddress(POOrder order)
        {
            if (order.OrderType.IsIn(POOrderType.RegularOrder, POOrderType.Blanket, POOrderType.StandardBlanket, POOrderType.DropShip))
            {
                return((POShipAddress)PXSelect <POShipAddress, Where <POShipAddress.addressID, Equal <Required <POOrder.shipAddressID> > > > .Select(Base, order.ShipAddressID));
            }

            return
                (PXSelectJoin <Branch,
                               InnerJoin <BAccountR, On <BAccountR.bAccountID, Equal <Branch.bAccountID> >,
                                          InnerJoin <Address, On <Address.addressID, Equal <BAccountR.defAddressID> > > >,
                               Where <Branch.branchID, Equal <Required <Branch.branchID> > > >
                 .Select(Base, order.BranchID)
                 .RowCast <Address>()
                 .FirstOrDefault());
        }
        protected virtual void INKitSpecHdr_KitInventoryID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            INKitSpecHdr row = e.Row as INKitSpecHdr;

            if (row != null)
            {
                INLotSerClass kitLotSerClass = PXSelectJoin <INLotSerClass,
                                                             InnerJoin <InventoryItem, On <InventoryItem.lotSerClassID, Equal <INLotSerClass.lotSerClassID> > >,
                                                             Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, row.KitInventoryID);

                if (kitLotSerClass != null)
                {
                    row.LotSerTrack = kitLotSerClass.LotSerTrack;
                }
            }
        }
Exemple #10
0
    public void SOOrder_OrderType_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        var query = new PXSelectJoin <SOOrderType,
                                      InnerJoin <PX.SM.UsersInRoles,
                                                 On <PX.SM.UsersInRoles.rolename,
                                                     Equal <SOOrderTypeExt.usrUserRole> > >,
                                      Where <PX.SM.UsersInRoles.username,
                                             Equal <Current <AccessInfo.userName> > > >(Base);
        var orderType = query.SelectSingle();

        if (orderType != null)
        {
            e.NewValue = orderType.OrderType;
            e.Cancel   = true;
        }
    }
        protected virtual IAddressBase GetToAddress(POOrder order, POLine line)
        {
            if (order.OrderType.IsIn(POOrderType.RegularOrder, POOrderType.Blanket, POOrderType.StandardBlanket))
            {
                return
                    (PXSelectJoin <Address,
                                   InnerJoin <INSite, On <INSite.FK.Address> >,
                                   Where <INSite.siteID, Equal <Current <POLine.siteID> > > >
                     .SelectSingleBound(Base, new[] { line })
                     .RowCast <Address>()
                     .FirstOrDefault()
                     ?? GetToAddress(order));
            }

            return(GetToAddress(order));
        }
        protected virtual void Users_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            Users user = (Users)e.Row;

            if (user == null)
            {
                return;
            }

            PXResultset <EPAssignmentRoute> res = PXSelectJoin <EPAssignmentRoute, InnerJoin <EPAssignmentMap, On <EPAssignmentRoute.assignmentMapID, Equal <EPAssignmentMap.assignmentMapID> > >, Where <EPAssignmentRoute.ownerID, Equal <Current <Users.pKID> > > > .Select(this, new object[] { user });

            foreach (PXResult <EPAssignmentRoute, EPAssignmentMap> result in res)
            {
                throw new PXSetPropertyException(PX.Objects.EP.Messages.UserParticipateInAssignmentMap, user.Username, ((EPAssignmentMap)result).Name);
            }
        }
        protected virtual void EPPosition_RowDeleting(PXCache cache, PXRowDeletingEventArgs e)
        {
            EPPosition row = e.Row as EPPosition;

            if (row != null)
            {
                EPEmployee p = PXSelectJoin <EPEmployee,
                                             LeftJoin <EPEmployeePosition, On <EPEmployee.bAccountID, Equal <EPEmployeePosition.employeeID> > >,
                                             Where <EPEmployeePosition.positionID, Equal <Required <EPPosition.positionID> > > > .SelectSingleBound(this, null, row.PositionID);

                if (p != null)
                {
                    throw new PXException(Messages.PositionInUseForDelete, p.AcctCD);
                }
            }
        }
Exemple #14
0
        public void Prefetch()
        {
            pagesAnlytics     = new Dictionary <Guid, List <Guid> >();
            pagesAnlyticstext = new Dictionary <Guid, string>();
            foreach (WikiDescriptor _wikiDescriptor in PXSelect <WikiDescriptor> .Select(new PXGraph()))
            {
                foreach (PXResult <WikiPageAnalytic, WikiPage> rec in PXSelectJoin <WikiPageAnalytic,
                                                                                    InnerJoin <WikiPage, On <WikiPage.pageID, Equal <WikiPageAnalytic.pageID> > >,
                                                                                    Where <WikiPage.pageID, Equal <Required <WikiPage.wikiID> > > >
                         .Select(new PXGraph(), _wikiDescriptor.PageID, _wikiDescriptor.PageID))
                {
                    WikiPageAnalytic wra = rec[typeof(WikiPageAnalytic)] as WikiPageAnalytic;
                    WikiPage         wp  = rec[typeof(WikiPage)] as WikiPage;
                    List <Guid>      list;
                    if (!pagesAnlytics.TryGetValue(wra.PageID.Value, out list))
                    {
                        list = new List <Guid>();
                        pagesAnlytics.Add(wra.PageID.Value, list);
                    }
                    if (!(list.IndexOf(wra.NPageID.Value) > -1))
                    {
                        list.Add(wra.NPageID.Value);
                    }
                }

                if (pagesAnlytics.ContainsKey((Guid)_wikiDescriptor.PageID))
                {
                    foreach (Guid scriptid in pagesAnlytics[(Guid)_wikiDescriptor.PageID])
                    {
                        foreach (PXResult <WikiRevision> rec1 in PXSelect <WikiRevision,
                                                                           Where <WikiRevision.pageID, Equal <Required <WikiRevision.pageID> > >,
                                                                           OrderBy <Desc <WikiRevision.pageRevisionID> > > .SelectWindowed(new PXGraph(), 0, 1, scriptid, scriptid))
                        {
                            WikiRevision wrp = rec1[typeof(WikiRevision)] as WikiRevision;
                            if (!pagesAnlyticstext.ContainsKey((Guid)_wikiDescriptor.PageID))
                            {
                                pagesAnlyticstext.Add((Guid)_wikiDescriptor.PageID, wrp.Content);
                            }
                            else
                            {
                                pagesAnlyticstext[(Guid)_wikiDescriptor.PageID] = pagesAnlyticstext[(Guid)_wikiDescriptor.PageID] + wrp.Content;
                            }
                        }
                    }
                }
            }
        }
        protected virtual IEnumerable spdocs()
        {
            List <ARSPCommnDocResult> res = new List <ARSPCommnDocResult>();
            SPDocFilter filter            = Filter.Current;

            if (filter?.CommnPeriod != null)
            {
                PXSelectBase <ARSalesPerTran> sel = new PXSelectJoin <ARSalesPerTran,
                                                                      InnerJoin <ARRegister, On <ARSalesPerTran.docType, Equal <ARRegister.docType>,
                                                                                                 And <ARSalesPerTran.refNbr, Equal <ARRegister.refNbr> > >,
                                                                                 InnerJoinSingleTable <Customer, On <Customer.bAccountID, Equal <ARRegister.customerID>,
                                                                                                                     And <Match <Customer, Current <AccessInfo.userName> > > > > >,
                                                                      Where <ARSalesPerTran.actuallyUsed, Equal <BQLConstants.BitOn> > >(this);

                if (filter.SalesPersonID != null)
                {
                    sel.WhereAnd <Where <ARSalesPerTran.salespersonID, Equal <Current <SPDocFilter.salesPersonID> > > >();
                }
                if (filter.CommnPeriod != null)
                {
                    sel.WhereAnd <Where <ARSalesPerTran.commnPaymntPeriod, Equal <Current <SPDocFilter.commnPeriod> > > >();
                }
                if (filter.CustomerID != null)
                {
                    sel.WhereAnd <Where <ARRegister.customerID, Equal <Current <SPDocFilter.customerID> > > >();
                }
                if (filter.LocationID != null)
                {
                    sel.WhereAnd <Where <ARRegister.customerLocationID, Equal <Current <SPDocFilter.locationID> > > >();
                }

                PXView        view              = sel.View;
                int           startRow          = PXView.StartRow;
                int           totalRows         = 0;
                List <object> windowedSelection = view.Select(PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows);
                PXView.StartRow = 0;

                foreach (PXResult <ARSalesPerTran, ARRegister, Customer> it in windowedSelection)
                {
                    ARSPCommnDocResult m = new ARSPCommnDocResult();
                    Copy(m, ((ARSalesPerTran)it));
                    Copy(m, ((ARRegister)it));
                    res.Add(m);
                }
            }
            return(res);
        }
Exemple #16
0
        public virtual IEnumerable routeDocuments()
        {
            var commandFilter = new PXSelectJoin <FSRouteDocument,
                                                  InnerJoin <FSRoute,
                                                             On <FSRoute.routeID, Equal <FSRouteDocument.routeID> > > >(this);

            var filter = Filter.Current;

            //Filters
            if (filter.FromDate != null)
            {
                commandFilter.WhereAnd <Where <FSRouteDocument.date, GreaterEqual <CurrentValue <RouteDocumentFilter.fromDate> > > >();
            }

            if (filter.ToDate != null)
            {
                commandFilter.WhereAnd <Where <FSRouteDocument.date, LessEqual <CurrentValue <RouteDocumentFilter.toDate> > > >();
            }

            if (filter.RouteID != null)
            {
                commandFilter.WhereAnd <Where <FSRouteDocument.routeID, Equal <CurrentValue <RouteDocumentFilter.routeID> > > >();
            }

            if (filter.StatusOpen == true || filter.StatusInProcess == true || filter.StatusCanceled == true || filter.StatusCompleted == true || filter.StatusClosed == true)
            {
                SetWhereStatus(filter.StatusOpen, filter.StatusInProcess, filter.StatusCanceled, filter.StatusCompleted, filter.StatusClosed, commandFilter);
            }

            int startRow  = PXView.StartRow;
            int totalRows = 0;
            var list      = commandFilter.View.Select(
                PXView.Currents,
                PXView.Parameters,
                PXView.Searches,
                PXView.SortColumns,
                PXView.Descendings,
                PXView.Filters,
                ref startRow,
                PXView.MaximumRows,
                ref totalRows);

            PXView.StartRow = 0;

            return(list);
        }
Exemple #17
0
        protected virtual void _(Events.RowInserted <Document> e)
        {
            var row = e.Row as Document;

            if (row == null)
            {
                return;
            }

            bool oldContactDirty = GetContactCache().IsDirty;
            bool oldAddressDirty = GetAddressCache().IsDirty;

            Contact oldContact = null;
            Address oldAddress = null;

            if (row.ContactID != null)
            {
                oldContact = PXSelect <Contact,
                                       Where <Contact.contactID, Equal <Current <Document.contactID> > > > .Select(Base);

                oldAddress = PXSelectJoin <Address,
                                           LeftJoin <Contact, On <Contact.defAddressID, Equal <Address.addressID> > >,
                                           Where <Contact.contactID, Equal <Current <Document.contactID> > > > .Select(Base);
            }
            else if (row.LocationID != null)
            {
                oldContact = PXSelectJoin <Contact,
                                           LeftJoin <Location, On <Location.locationID, Equal <Current <Document.locationID> > > >,
                                           Where <Contact.contactID, Equal <Location.defContactID> > > .Select(Base);

                oldAddress = PXSelectJoin <Address,
                                           LeftJoin <Contact, On <Contact.defAddressID, Equal <Address.addressID> >,
                                                     LeftJoin <Location, On <Location.locationID, Equal <Current <Document.locationID> > > > >,
                                           Where <Address.addressID, Equal <Location.defAddressID> > > .Select(Base);
            }

            ChangedData forContactInfo = new ChangedData();

            forContactInfo.OldContact = oldContact;
            forContactInfo.OldAddress = oldAddress;

            DefaultRecords(row, forContactInfo, new ChangedData(false));

            GetContactCache().IsDirty = oldContactDirty;
            GetAddressCache().IsDirty = oldAddressDirty;
        }
Exemple #18
0
        public Func <decimal?, decimal> GetRoundDelegateForLedger(int?ledgerID)
        {
            var currency = (Currency)PXSelectJoin <Currency,
                                                   InnerJoin <Ledger,
                                                              On <Currency.curyID, Equal <Ledger.baseCuryID> > >,
                                                   Where
                                                   <Ledger.ledgerID, Equal <Required <Ledger.ledgerID> > > >
                           .Select(this, ledgerID);

            if (currency == null)
            {
                throw new PXException(
                          PXMessages.LocalizeFormat(Messages.CurrencyForLedgerCannotBeFound, ledgerID));
            }

            return(value => Math.Round(value.Value, currency.DecimalPlaces.Value, MidpointRounding.AwayFromZero));
        }
        private PXResultset <CSAnswers, CSAttributeGroup, CSAttributeDetail2> GenerateAttributeList(int attributeNum)
        {
            PXResultset <CSAnswers, CSAttributeGroup, CSAttributeDetail2> list = new PXResultset <CSAnswers, CSAttributeGroup, CSAttributeDetail2>();

            PXSelectBase <CSAttributeGroup> query = new PXSelectJoin <CSAttributeGroup,
                                                                      InnerJoin <CSAttributeDetail2, On <CSAttributeGroupExt.usrCategory, Equal <CSAttributeDetail2.valueID>,
                                                                                                         And <CSAttributeDetail2.attributeID, Equal <Required <INSetupExt.usrCategoryAttribute> >,
                                                                                                              And <CSAttributeDetail2.sortOrder, Equal <Required <CSAttributeDetail2.sortOrder> >,
                                                                                                                   And <CSAttributeDetail2.disabled, Equal <False> > > > > >,
                                                                      Where <CSAttributeGroup.entityClassID, Equal <Required <InventoryItem.itemClassID> >
                                                                             , And <CSAttributeGroup.entityType, Equal <PCBConst.entityTypeIN> >
                                                                             >,
                                                                      OrderBy <Asc <CSAttributeGroup.sortOrder> > >(Base);

            InventoryItem current  = Base.Item.Current;
            INSetupExt    setupExt = Base.insetup.Current.GetExtension <INSetupExt>();

            if (current != null && current.InventoryID != null && setupExt != null) //&& current.InventoryID > 0
            {
                foreach (PXResult <CSAttributeGroup, CSAttributeDetail2> item in query.Select(setupExt.UsrCategoryAttribute, attributeNum, current.ItemClassID))
                {
                    CSAttributeGroup   attribute = item;
                    CSAttributeDetail2 detail    = item;

                    CSAnswers answerCheck = PXSelect <CSAnswers, Where <CSAnswers.refNoteID, Equal <Required <CSAnswers.refNoteID> >,
                                                                        And <CSAnswers.attributeID, Equal <Required <CSAnswers.attributeID> > > > >
                                            .Select(Base, current.NoteID, attribute.AttributeID);

                    if (answerCheck == null)
                    {
                        CSAnswers newAnswer = new CSAnswers();
                        newAnswer.AttributeID = attribute.AttributeID;
                        newAnswer.Value       = string.Empty;
                        newAnswer.Order       = attribute.SortOrder;
                        newAnswer.IsRequired  = attribute.Required;
                        newAnswer.RefNoteID   = current.NoteID;
                        list.Add(new PXResult <CSAnswers, CSAttributeGroup, CSAttributeDetail2>(newAnswer, attribute, detail));
                    }
                    else
                    {
                        list.Add(new PXResult <CSAnswers, CSAttributeGroup, CSAttributeDetail2>(answerCheck, attribute, detail));
                    }
                }
            }
            return(list);
        }
 /// <summary>
 /// Searches for a reference to <paramref name="numberingID"/> in segmented keys.
 /// </summary>
 /// <param name="numberingID">The identifier of the numbering sequence to search for.</param>
 /// <param name="demensionID">The ID of the segmented key in which the reference has been found.</param>
 /// <param name="segmentID">The ID of the segment in which the reference has been found.</param>
 /// <returns>If a segmented key with the reference to the specified <paramref name="numberingID"/> has
 /// been found, the method returns <tt>True</tt>; otherwise, the method returns <tt>False</tt>.</returns>
 public bool IsInUseSegments(string numberingID, out string demensionID, out string segmentID)
 {
     foreach (PXResult <Dimension, Segment> r in PXSelectJoin <Dimension,
                                                               InnerJoin <Segment, On <Segment.dimensionID, Equal <Dimension.dimensionID> > >,
                                                               Where <Dimension.numberingID, Equal <Optional <Numbering.numberingID> >,
                                                                      And <Segment.autoNumber, Equal <Optional <Segment.autoNumber> > > > > .Select(parentGraph, numberingID, true))
     {
         Dimension dim    = r;
         Segment   segrow = r;
         demensionID = segrow.DimensionID;
         segmentID   = segrow.SegmentID.ToString();
         return(true);
     }
     demensionID = null;
     segmentID   = null;
     return(false);
 }
        public bool CheckDoNotExistUnreleasedCAAdjsWithCASplitsWithBranchWithFinPeriodLessOrEqual(int?branchID, string finPeriod)
        {
            var childBranchIds = PXAccess.GetChildBranchIDs(GetBranchByID(branchID).BranchCD);

            var query = new PXSelectJoin <CAAdj,
                                          LeftJoin <CASplit,
                                                    On <CAAdj.adjTranType, Equal <CASplit.adjTranType>,
                                                        And <CAAdj.adjRefNbr, Equal <CASplit.adjRefNbr> > > >,
                                          Where <CAAdj.released, Equal <False>,
                                                 And <CAAdj.finPeriodID, LessEqual <Required <CAAdj.finPeriodID> >,
                                                      And <Where <CAAdj.branchID, In <Required <CAAdj.branchID> >,
                                                                  Or <CASplit.branchID, In <Required <CASplit.branchID> > > > > > > >(_graph);

            var caAdj = query.SelectSingle(finPeriod, childBranchIds, childBranchIds);

            return(caAdj == null);
        }
        public bool CheckDoNotExistUnreleasedARRegistersWithARTransWithBranchWithFinPeriodLessOrEqual(int?branchID, string finPeriod)
        {
            var childBranchIds = PXAccess.GetChildBranchIDs(GetBranchByID(branchID).BranchCD);

            var query = new PXSelectJoin <ARRegister,
                                          LeftJoin <ARTran,
                                                    On <ARRegister.docType, Equal <ARTran.tranType>,
                                                        And <ARRegister.refNbr, Equal <ARTran.refNbr> > > >,
                                          Where <ARRegister.released, Equal <False>,
                                                 And <ARRegister.finPeriodID, LessEqual <Required <ARRegister.finPeriodID> >,
                                                      And <Where <ARRegister.branchID, In <Required <ARRegister.branchID> >,
                                                                  Or <ARTran.branchID, In <Required <ARTran.branchID> > > > > > > >(_graph);

            var arRegister = query.SelectSingle(finPeriod, childBranchIds, childBranchIds);

            return(arRegister == null);
        }
Exemple #23
0
		protected override void ClosePeriodProc(FinPeriod p)
		{
			PXSelectBase select = new PXSelectJoin<ARRegister, 
											LeftJoin<ARAdjust, On<ARAdjust.adjgDocType, Equal<ARRegister.docType>, And<ARAdjust.adjgRefNbr, Equal<ARRegister.refNbr>, And<ARAdjust.released, Equal<False>>>>>,
											Where<ARRegister.voided, Equal<boolFalse>, 
											And<ARRegister.scheduled, Equal<boolFalse>,
											And<Where<ARAdjust.adjgFinPeriodID, IsNull, And<ARRegister.released, Equal<False>, And<ARRegister.finPeriodID, Equal<Required<ARRegister.finPeriodID>>, Or<ARAdjust.adjgFinPeriodID, Equal<Required<ARAdjust.adjgFinPeriodID>>>>>>>>>>(this);
			object doc = select.View.SelectSingle(p.FinPeriodID, p.FinPeriodID);
			if (doc != null)
			{			
				throw new PXException(AP.Messages.PeriodHasUnreleasedDocs);
			}			

			p.ARClosed = true;
			Caches[typeof(FinPeriod)].Update(p);
			Actions.PressSave();
		}
Exemple #24
0
        /// <summary>
        /// Add the Billing Customer info as a recipient(s) in the Email template generated by Appointment.
        /// </summary>
        private static void AddBillingRecipient(AppointmentEntry graphAppointmentEntry, NotificationRecipient recSetup, RecipientList recipients)
        {
            NotificationRecipient recipient = null;

            if (graphAppointmentEntry.ServiceOrderRelated.Current.BillCustomerID != null)
            {
                Customer customerRow = PXSelect <Customer,
                                                 Where <
                                                     Customer.bAccountID, Equal <Required <Customer.bAccountID> > > >
                                       .Select(graphAppointmentEntry, graphAppointmentEntry.ServiceOrderRelated.Current.BillCustomerID);

                if (customerRow == null)
                {
                    return;
                }

                FSxCustomer fsxCustomerRow = PXCache <Customer> .GetExtension <FSxCustomer>(customerRow);

                if (fsxCustomerRow.SendAppNotification == true)
                {
                    Contact contactRow = PXSelectJoin <Contact,
                                                       InnerJoin <Customer,
                                                                  On <Contact.bAccountID, Equal <Customer.bAccountID>,
                                                                      And <Contact.contactID, Equal <Customer.defBillContactID> > > >,
                                                       Where <
                                                           Customer.bAccountID, Equal <Required <Customer.bAccountID> > > >
                                         .Select(graphAppointmentEntry, graphAppointmentEntry.ServiceOrderRelated.Current.BillCustomerID);

                    if (contactRow != null && contactRow.EMail != null)
                    {
                        recipient = new NotificationRecipient()
                        {
                            Active = true,
                            Email  = contactRow.EMail,
                            Hidden = recSetup.Hidden,
                            Format = recSetup.Format
                        };
                    }
                }

                if (recipient != null)
                {
                    recipients.Add(recipient);
                }
            }
        }
Exemple #25
0
        /// <summary>
        /// Add the Employee info defined in the Notification tab defined in the <c>SrvOrdType</c> as a recipient(s) in the Email template generated by Appointment.
        /// </summary>
        private static void AddEmployeeRecipient(PXGraph graph, NotificationRecipient recSetup, RecipientList recipients)
        {
            NotificationRecipient recipient = null;
            bool?appNotification            = false;

            PXResult <Contact, BAccount, EPEmployee> bqlResult =
                (PXResult <Contact, BAccount, EPEmployee>) PXSelectJoin <Contact,
                                                                         InnerJoin <BAccount,
                                                                                    On <Contact.bAccountID, Equal <BAccount.parentBAccountID>,
                                                                                        And <Contact.contactID, Equal <BAccount.defContactID> > >,
                                                                                    InnerJoin <EPEmployee,
                                                                                               On <EPEmployee.bAccountID, Equal <BAccount.bAccountID> > > >,
                                                                         Where <
                                                                             Contact.contactID, Equal <Required <Contact.contactID> >,
                                                                             And <BAccount.type, Equal <Required <BAccount.type> > > > >
                .Select(graph, recSetup.ContactID, BAccountType.EmployeeType);

            Contact    contactRow    = (Contact)bqlResult;
            BAccount   baccountRow   = (BAccount)bqlResult;
            EPEmployee epEmployeeRow = (EPEmployee)bqlResult;

            if (epEmployeeRow != null)
            {
                FSxEPEmployee fsxEpEmployeeRow = PXCache <EPEmployee> .GetExtension <FSxEPEmployee>(epEmployeeRow);

                appNotification = fsxEpEmployeeRow.SendAppNotification;

                if (appNotification == true)
                {
                    if (contactRow != null && contactRow.EMail != null)
                    {
                        recipient = new NotificationRecipient()
                        {
                            Active = true,
                            Email  = contactRow.EMail,
                            Hidden = recSetup.Hidden,
                            Format = recSetup.Format
                        };
                        if (recipient != null)
                        {
                            recipients.Add(recipient);
                        }
                    }
                }
            }
        }
        /// <summary><see cref="InventoryByClassFilter.InventoryID"/> Updated</summary>
        protected virtual void InventoryByClassFilter_InventoryID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            var row = (InventoryByClassFilter)e.Row;

            if (row?.InventoryID != null)
            {
                INItemClass current = PXSelectJoin <INItemClass,
                                                    InnerJoin <InventoryItem, On <INItemClass.itemClassID, Equal <InventoryItem.itemClassID> > >,
                                                    Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > >
                                      .SelectWindowed(this, 0, 1, row.InventoryID);

                _allowToSyncTreeCurrentWithPrimaryViewCurrent  = true;
                _forbidToSyncTreeCurrentWithPrimaryViewCurrent = false;
                _keepInventoryFilter    = true;
                ItemClassFilter.Current = current;
            }
        }
        protected virtual void EPCompanyTreeMember_Active_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            EPCompanyTreeMember row = (EPCompanyTreeMember)e.Row;

            if (row == null)
            {
                return;
            }

            string res = "";

            foreach (EPAssignmentMap map in PXSelectJoin <EPAssignmentMap,
                                                          InnerJoin <EPAssignmentRoute, On <EPAssignmentRoute.assignmentMapID, Equal <EPAssignmentMap.assignmentMapID> > >,
                                                          Where <EPAssignmentRoute.ownerID, Equal <Required <EPAssignmentRoute.ownerID> > > > .
                     Select(this, row.UserID))
            {
                if (map == null)
                {
                    throw new PXException(Objects.EP.Messages.WorkgroupIsInUse);
                }

                string MapType = "";
                if (map.MapType == EPMapType.Assignment)
                {
                    MapType = Objects.EP.Messages.Assignment;
                }
                else
                {
                    MapType = Objects.EP.Messages.Approval;
                }

                EPEmployee Employee = PXSelect <EPEmployee,
                                                Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(this, row.UserID);

                if (Employee != null)
                {
                    res = res + string.Format(Objects.EP.Messages.EmployeeIsInUseAtAssignmentMapPart1, Employee.AcctName, MapType, map.Name) + "\n";
                }
            }

            if (!String.IsNullOrEmpty(res))
            {
                sender.RaiseExceptionHandling <EPCompanyTreeMember.userID>(row, row.UserID, new PXSetPropertyException(res + "\n" + Objects.EP.Messages.EmployeeIsInUseAtAssignmentMapPart2, PXErrorLevel.RowWarning));
            }
        }
Exemple #28
0
        protected virtual void GenerateStatement(ARStatementCycle cycle, DateTime statementDate, bool clearExisting)
        {
            PXSelectBase <Customer> selectCustomer = new PXSelectJoin <Customer,
                                                                       InnerJoin <CustomerMaster, On <CustomerMaster.bAccountID, Equal <Customer.statementCustomerID> > >,
                                                                       Where <CustomerMaster.statementCycleId, Equal <Required <Customer.statementCycleId> > >,
                                                                       OrderBy <Asc <Customer.statementCustomerID> > >(this);

            var statementGraph = CreateInstance <StatementCreateBO>();

            var family = new List <Customer> {
            };

            foreach (Customer customer in selectCustomer.Select(cycle.StatementCycleId))
            {
                if (family.Any() == false || family.First().StatementCustomerID == customer.StatementCustomerID)
                {
                    family.Add(customer);
                }
                else
                {
                    GenerateStatementForCustomerFamily(statementGraph, cycle, family, statementDate, clearExisting);
                    family = new List <Customer> {
                        customer
                    };
                }
            }

            if (family.Any())
            {
                GenerateStatementForCustomerFamily(statementGraph, cycle, family, statementDate, clearExisting);
            }

            Customer leftToProcess = PXSelectReadonly2 <Customer,
                                                        InnerJoin <CustomerMaster, On <CustomerMaster.bAccountID, Equal <Customer.statementCustomerID> > >,
                                                        Where <CustomerMaster.statementCycleId, Equal <Required <Customer.statementCycleId> >,
                                                               And <Where <Customer.statementLastDate, IsNull,
                                                                           Or <Customer.statementLastDate, Less <Required <Customer.statementLastDate> > > > > > > .SelectWindowed(this, 0, 1, cycle.StatementCycleId, statementDate);

            if (leftToProcess == null)
            {
                cycle.LastStmtDate = statementDate;
                this.CyclesList.Update(cycle);
                this.Actions.PressSave();
            }
        }
        public static ItemCost Fetch(PXGraph graph, int?vendorID, int?vendorLocationID, DateTime?docDate, string curyID, int?inventoryID, int?subItemID, int?siteID, string uom, bool onlyVendor)
        {
            PXSelectBase <InventoryItem> vendorCostSelect =
                new PXSelectJoin <InventoryItem,
                                  LeftJoin <INItemCost, On <INItemCost.inventoryID, Equal <InventoryItem.inventoryID> >,
                                            LeftJoin <POVendorInventory, On <
                                                          POVendorInventory.inventoryID, Equal <InventoryItem.inventoryID>,
                                                          And <POVendorInventory.active, Equal <True>,
                                                               And <POVendorInventory.vendorID, Equal <Required <Vendor.bAccountID> >,
                                                                    And <POVendorInventory.curyID, Equal <Required <POVendorInventory.curyID> >,
                                                                         And2 <Where <POVendorInventory.subItemID, Equal <Required <POVendorInventory.subItemID> >,
                                                                                      Or <POVendorInventory.subItemID, Equal <InventoryItem.defaultSubItemID>,
                                                                                          Or <POVendorInventory.subItemID, IsNull,
                                                                                              Or <Where <Required <POVendorInventory.subItemID>, IsNull,
                                                                                                         And <POVendorInventory.subItemID, Equal <True> > > > > > >,
                                                                               And2 <Where <POVendorInventory.purchaseUnit, Equal <Required <POVendorInventory.purchaseUnit> > >,
                                                                                     And <Where <POVendorInventory.vendorLocationID, Equal <Required <POVendorInventory.vendorLocationID> >,
                                                                                                 Or <POVendorInventory.vendorLocationID, IsNull> > > > > > > > > > >,
                                  Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > >,
                                  OrderBy <
                                      Asc <Switch <Case <Where <POVendorInventory.purchaseUnit, Equal <InventoryItem.purchaseUnit> >, True>, False>,
                                           Asc <Switch <Case <Where <POVendorInventory.subItemID, Equal <InventoryItem.defaultSubItemID> >, True>, False>,
                                                Asc <Switch <Case <Where <POVendorInventory.vendorLocationID, IsNull>, True>, False>,
                                                     Asc <InventoryItem.inventoryCD> > > > > >(graph);

            Func <string, PXResult <InventoryItem, INItemCost, POVendorInventory> > selectVendorCostByUOM =
                uomParam => vendorCostSelect
                .Select(vendorID, curyID, subItemID, subItemID, uomParam, vendorLocationID, inventoryID)
                .FirstOrDefault(r => r.GetItem <POVendorInventory>() != null)
                as PXResult <InventoryItem, INItemCost, POVendorInventory>;

            var vendorCostRow = selectVendorCostByUOM(uom);
            var item          = vendorCostRow.GetItem <InventoryItem>();

            Func <POVendorInventory, ItemCost> fetchVendorLastCost =
                vendorPrice => vendorPrice.LastPrice != null && vendorPrice.LastPrice != 0m
                                        ? new ItemCost(item, vendorPrice.PurchaseUnit, curyID, vendorPrice.LastPrice.Value, false)
                                        : null;

            return(fetchVendorLastCost(vendorCostRow.GetItem <POVendorInventory>())
                   ?? fetchVendorLastCost(selectVendorCostByUOM(item.BaseUnit).GetItem <POVendorInventory>())
                   ?? (onlyVendor ? null : FetchStdCost(graph, item, docDate))
                   ?? (onlyVendor ? null : FetchSiteLastCost(graph, item, siteID))
                   ?? new ItemCost(item, vendorCostRow.GetItem <INItemCost>()?.LastCost ?? 0));
        }
Exemple #30
0
        public virtual BqlCommand ComposeBQLCommandForRecords(SchedulesFilter filter)
        {
            if (filter == null)
            {
                return(null);
            }

            PXSelectBase <SchedulesInqResult> select = new PXSelectJoin <SchedulesInqResult,
                                                                         InnerJoin <DRSchedule, On <DRSchedule.scheduleID, Equal <SchedulesInqResult.scheduleID> >,
                                                                                    InnerJoin <DRDeferredCode, On <DRDeferredCode.deferredCodeID, Equal <SchedulesInqResult.defCode> >,
                                                                                               LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <SchedulesInqResult.componentID> > > > >,
                                                                         Where <DRDeferredCode.accountType, Equal <Current <SchedulesFilter.accountType> > > >(this);

            if (!string.IsNullOrEmpty(filter.DeferredCode))
            {
                select.WhereAnd <Where <SchedulesInqResult.defCode, Equal <Current <SchedulesFilter.deferredCode> > > >();
            }

            if (filter.OrgBAccountID != null)
            {
                select.WhereAnd <Where <SchedulesInqResult.branchID, Inside <Current <SchedulesFilter.orgBAccountID> > > >();          //MatchWithOrg
            }

            if (filter.AccountID != null)
            {
                select.WhereAnd <Where <SchedulesInqResult.defAcctID, Equal <Current <SchedulesFilter.accountID> > > >();
            }

            if (filter.SubID != null)
            {
                select.WhereAnd <Where <SchedulesInqResult.defSubID, Equal <Current <SchedulesFilter.subID> > > >();
            }

            if (filter.BAccountID != null)
            {
                select.WhereAnd <Where <SchedulesInqResult.bAccountID, Equal <Current <SchedulesFilter.bAccountID> > > >();
            }

            if (filter.ComponentID != null)
            {
                select.WhereAnd <Where <SchedulesInqResult.componentID, Equal <Current <SchedulesFilter.componentID> > > >();
            }

            return(select.View.BqlSelect);
        }
Exemple #31
0
        protected override void ClosePeriodProc(FinPeriod p)
        {
            PXSelectBase select = new PXSelect <INRegister,
                                                Where <INRegister.finPeriodID, Equal <Required <INRegister.finPeriodID> >,
                                                       And <INRegister.released, Equal <boolFalse> > > >(this);
            INRegister doc = (INRegister)select.View.SelectSingle(p.FinPeriodID);

            if (doc != null)
            {
                throw new PXException(AP.Messages.PeriodHasUnreleasedDocs);
            }

            //MS Landed cost will not be able to create these transactions if the period is closed
            LandedCostTran lcTranFromAP = PXSelectJoin <LandedCostTran,
                                                        InnerJoin <APRegister, On <LandedCostTran.aPDocType, Equal <APRegister.docType>,
                                                                                   And <LandedCostTran.aPRefNbr, Equal <APRegister.refNbr> > > >,
                                                        Where <LandedCostTran.invoiceDate, GreaterEqual <Required <LandedCostTran.invoiceDate> >,
                                                               And <LandedCostTran.invoiceDate, Less <Required <LandedCostTran.invoiceDate> >,
                                                                    And <LandedCostTran.source, Equal <LandedCostTranSource.fromAP>,
                                                                         And <APRegister.released, Equal <True>,
                                                                              And <LandedCostTran.processed, Equal <False> > > > > > > .Select(this, p.StartDate, p.EndDate);

            if (lcTranFromAP != null && lcTranFromAP.LCTranID.HasValue)
            {
                throw new PXException(Messages.PeriodHasINDocsFromAP_LCToBeCreated);
            }

            PO.LandedCostTran lcTranFromPO = PXSelectJoin <LandedCostTran,
                                                           InnerJoin <POReceipt, On <LandedCostTran.pOReceiptNbr, Equal <POReceipt.receiptNbr> > >,
                                                           Where <LandedCostTran.invoiceDate, GreaterEqual <Required <LandedCostTran.invoiceDate> >,
                                                                  And <LandedCostTran.invoiceDate, Less <Required <LandedCostTran.invoiceDate> >,
                                                                       And <LandedCostTran.source, Equal <LandedCostTranSource.fromPO>,
                                                                            And <POReceipt.released, Equal <True>,
                                                                                 And <LandedCostTran.processed, Equal <False> > > > > > > .Select(this, p.StartDate, p.EndDate);

            if (lcTranFromPO != null && lcTranFromPO.LCTranID.HasValue)
            {
                throw new PXException(Messages.PeriodHasINDocsFromPO_LCToBeCreated);
            }

            p.INClosed = true;
            Caches[typeof(FinPeriod)].Update(p);

            Actions.PressSave();
        }
Exemple #32
0
		protected override void ClosePeriodProc(FinPeriod p)
        {
            APRegister prebookedDoc = PXSelect<APRegister, Where<APRegister.voided, Equal<boolFalse>,
                                            And<APRegister.prebooked, Equal<boolTrue>,
                                            And<APRegister.released, Equal<boolFalse>,
                                            And<APRegister.finPeriodID, Equal<Required<APRegister.finPeriodID>>>>>>>.Select(this, p.FinPeriodID);
            if (prebookedDoc != null)
            {
                throw new PXException(Messages.PeriodHasPrebookedDocs);
            }

			PXSelectBase select = new PXSelectJoin<APRegister,
											LeftJoin<APAdjust, On<APAdjust.adjgDocType, Equal<APRegister.docType>, And<APAdjust.adjgRefNbr, Equal<APRegister.refNbr>, And<APAdjust.released, Equal<False>>>>>,
											Where<APRegister.voided, Equal<boolFalse>,
											And<APRegister.scheduled, Equal<boolFalse>,
											And<Where<APAdjust.adjgFinPeriodID, IsNull, And<APRegister.released, Equal<False>, And<APRegister.finPeriodID, Equal<Required<APRegister.finPeriodID>>, Or<APAdjust.adjgFinPeriodID, Equal<Required<APAdjust.adjgFinPeriodID>>>>>>>>>>(this); 
			object doc = select.View.SelectSingle(p.FinPeriodID, p.FinPeriodID);
			if (doc != null)
			{
				throw new PXException(Messages.PeriodHasUnreleasedDocs);
			}

			PO.LandedCostTran lcTran = PXSelectJoin<LandedCostTran,
											InnerJoin<POReceipt, On<LandedCostTran.pOReceiptNbr, Equal<POReceipt.receiptNbr>>>,
											Where<LandedCostTran.source, Equal<LandedCostTranSource.fromPO>,
											And<POReceipt.released, Equal<True>,
											And<LandedCostTran.postponeAP,Equal<False>,
											And<LandedCostTran.processed, Equal<False>,
												And<LandedCostTran.invoiceDate, GreaterEqual<Required<LandedCostTran.invoiceDate>>,				
												And<LandedCostTran.invoiceDate, Less<Required<LandedCostTran.invoiceDate>>>>>>>>>.Select(this, p.StartDate, p.EndDate);
			if (lcTran != null && lcTran.LCTranID.HasValue) 
			{
				throw new PXException(Messages.PeriodHasAPDocsFromPO_LCToBeCreated);
			}
			
			p.APClosed = true;
			Caches[typeof(FinPeriod)].Update(p);

			Actions.PressSave();
		}
Exemple #33
0
		protected virtual IEnumerable GetRecords()
		{
			bool ar = true;
			PXCache cache = this._Graph.Caches[BqlCommand.GetItemType(moduleField)];
			string docType = ARDocType.Invoice;

			if (cache.Current != null )
			{
				docType = (string)cache.GetValue(cache.Current, docTypeField.Name);
				string module = (string)cache.GetValue(cache.Current, moduleField.Name);
				if (module == BatchModule.AP)
					ar = false;
			}

			if (ar)
			{
				PXSelectBase<ARInvoice> select = new 
					PXSelectJoin<ARInvoice, 
					InnerJoin<BAccount, On<BAccount.bAccountID, Equal<ARInvoice.customerID>>>,
					Where<ARInvoice.docType, Equal<Required<ARInvoice.docType>>>>(this._Graph);
				foreach (PXResult<ARInvoice, BAccount> res in select.Select(docType))
				{
					ARInvoice doc = (ARInvoice)res;
					BAccount customer = (BAccount)res;


					string status = null;
					ARDocStatus.ListAttribute x = new ARDocStatus.ListAttribute();
					if (x.ValueLabelDic.ContainsKey(doc.Status))
					{
						status = x.ValueLabelDic[doc.Status];
					}
					

					DRDocumentRecord record = new DRDocumentRecord();
					record.BAccountCD = customer.AcctCD;
					record.RefNbr = doc.RefNbr;
					record.Status = status;
					record.FinPeriodID = doc.FinPeriodID;
					record.DocType = doc.DocType;
					record.DocDate = doc.DocDate;
					record.LocationID = doc.CustomerLocationID;
					record.CuryOrigDocAmt = doc.CuryOrigDocAmt;
					record.CuryID = doc.CuryID;

					yield return record;
				}
			}
			else
			{
				PXSelectBase<APInvoice> select = new
					PXSelectJoin<APInvoice,
					InnerJoin<BAccount, On<BAccount.bAccountID, Equal<APInvoice.vendorID>>>,
					Where<APInvoice.docType, Equal<Required<APInvoice.docType>>>>(this._Graph);
				foreach (PXResult<APInvoice, BAccount> res in select.Select(docType))
				{
					APInvoice doc = (APInvoice)res;
					BAccount customer = (BAccount)res;

					string status = null;
					APDocStatus.ListAttribute x = new APDocStatus.ListAttribute();
					if (x.ValueLabelDic.ContainsKey(doc.Status))
					{
						status = x.ValueLabelDic[doc.Status];
					}

					DRDocumentRecord record = new DRDocumentRecord();
					record.BAccountCD = customer.AcctCD;
					record.RefNbr = doc.RefNbr;
					record.Status = status;
					record.FinPeriodID = doc.FinPeriodID;
					record.DocType = doc.DocType;
					record.DocDate = doc.DocDate;
					record.LocationID = doc.VendorLocationID;
					record.CuryOrigDocAmt = doc.CuryOrigDocAmt;
					record.CuryID = doc.CuryID;

					yield return record;
				}
			}
		}
		protected override void ApplyAvalaraTax(ARInvoice invoice, GetTaxResult result)
		{
			TaxZone taxZone = (TaxZone)taxzone.View.SelectSingleBound(new object[] { invoice });
			AP.Vendor vendor = PXSelect<AP.Vendor, Where<AP.Vendor.bAccountID, Equal<Required<AP.Vendor.bAccountID>>>>.Select(this, taxZone.TaxVendorID);

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

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

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

			bool requireControlTotal = ARSetup.Current.RequireControlTotal == true;

			if (invoice.Hold != true)
				ARSetup.Current.RequireControlTotal = false;

			try
			{

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

					//Insert Tax if not exists - just for the selectors sake
					Tax tx = PXSelect<Tax, Where<Tax.taxID, Equal<Required<Tax.taxID>>>>.Select(this, taxID);
					if (tx == null)
					{
						tx = new Tax();
						tx.TaxID = taxID;
						//tx.Descr = string.Format("Avalara {0} {1}%", taxID, Convert.ToDecimal(result.TaxSummary[i].Rate)*100);
						tx.Descr = string.Format("Avalara {0}", taxID);
						tx.TaxType = CSTaxType.Sales;
						tx.TaxCalcType = CSTaxCalcType.Doc;
						tx.TaxCalcLevel = CSTaxCalcLevel.CalcOnItemAmt;
						tx.TaxApplyTermsDisc = CSTaxTermsDiscount.ToTaxableAmount;
						tx.SalesTaxAcctID = vendor.SalesTaxAcctID;
						tx.SalesTaxSubID = vendor.SalesTaxSubID;
						tx.ExpenseAccountID = vendor.TaxExpenseAcctID;
						tx.ExpenseSubID = vendor.TaxExpenseSubID;
						tx.TaxVendorID = taxZone.TaxVendorID;

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

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

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

						Taxes.Update(existing);
						existingRows.Remove(existing.TaxID.Trim().ToUpperInvariant());
					}
					else
					{
						ARTaxTran tax = new ARTaxTran();
						tax.Module = BatchModule.AR;
						tax.TranType = invoice.DocType;
						tax.RefNbr = invoice.RefNbr;
						tax.TaxID = taxID;
						tax.TaxAmt = Math.Abs(result.TaxSummary[i].Tax);
						tax.CuryTaxAmt = Math.Abs(result.TaxSummary[i].Tax);
						tax.TaxableAmt = Math.Abs(result.TaxSummary[i].Taxable);
						tax.CuryTaxableAmt = Math.Abs(result.TaxSummary[i].Taxable);
						tax.TaxRate = Convert.ToDecimal(result.TaxSummary[i].Rate);
						tax.TaxType = "S";
						tax.TaxBucketID = 0;
						tax.AccountID = vendor.SalesTaxAcctID;
						tax.SubID = vendor.SalesTaxSubID;

						Taxes.Insert(tax);
					}
				}

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

				SOInvoice soInvoice = PXSelect<SOInvoice, Where<SOInvoice.docType, Equal<Required<SOInvoice.docType>>, And<SOInvoice.refNbr, Equal<Required<SOInvoice.refNbr>>>>>.Select(this, invoice.DocType, invoice.RefNbr);

				invoice.CuryTaxTotal = Math.Abs(result.TotalTax);
				Document.Cache.SetValueExt<ARInvoice.isTaxSaved>(invoice, true);
			}
			finally
			{
				ARSetup.Current.RequireControlTotal = requireControlTotal;
			}


			if (invoice.ApplyPaymentWhenTaxAvailable == true)
			{
				PXSelectBase<ARAdjust> select = new PXSelectJoin<ARAdjust,
					InnerJoin<ARPayment, On<ARAdjust.adjgDocType, Equal<ARPayment.docType>, And<ARAdjust.adjgRefNbr, Equal<ARPayment.refNbr>>>>,
					Where<ARAdjust.adjdDocType, Equal<Required<ARInvoice.docType>>,
					And<ARAdjust.adjdRefNbr, Equal<Required<ARInvoice.refNbr>>>>>(this);


				foreach (PXResult<ARAdjust, ARPayment> res in select.Select(invoice.DocType, invoice.RefNbr))
				{
					ARAdjust row = (ARAdjust)res;
					ARPayment payment = (ARPayment)res;

					ARAdjust copy = PXCache<ARAdjust>.CreateCopy(row);
					copy.CuryAdjdAmt = Math.Min(copy.CuryAdjdAmt.GetValueOrDefault(), invoice.CuryDocBal.GetValueOrDefault());
					Adjustments.Update(copy);
				}
			}

		}
		public virtual List<CSBox> GetBoxesByCarrierID(string carrierID)
		{
			List<CSBox> list = new List<CSBox>();
			if (string.IsNullOrEmpty(carrierID))
			{
				foreach (CSBox box in PXSelect<CSBox, Where<CSBox.maxWeight, Greater<decimal0>>>.Select(graph))
				{
					list.Add(box);
				}
			}
			else
			{
				PXSelectBase<CSBox> select = new PXSelectJoin<CSBox,
					InnerJoin<CarrierPackage, On<CSBox.boxID, Equal<CarrierPackage.boxID>>>,
					Where<CarrierPackage.carrierID, Equal<Required<CarrierPackage.carrierID>>,
					And<CSBox.maxWeight, Greater<decimal0>>>, OrderBy<Asc<CSBox.maxWeight>>>(graph);

				foreach (CSBox box in select.Select(carrierID))
				{
					list.Add(box);
				}
			}

			return list;
		}
		public virtual List<INItemBoxEx> GetBoxesByInventoryID(int inventoryID, string carrierID)
		{
			PXSelectBase<INItemBoxEx> select;
			if (string.IsNullOrEmpty(carrierID))
			{
				select = new PXSelect<INItemBoxEx,
					Where<INItemBoxEx.inventoryID, Equal<Required<INItemBoxEx.inventoryID>>>>(graph);
			}
			else
			{
				select = new PXSelectJoin<INItemBoxEx,
					InnerJoin<CarrierPackage, On<INItemBoxEx.boxID, Equal<CarrierPackage.boxID>>>,
					Where<INItemBoxEx.inventoryID, Equal<Required<INItemBox.inventoryID>>,
					And<CarrierPackage.carrierID, Equal<Required<CarrierPackage.carrierID>>>>>(graph);
			}

			List<INItemBoxEx> list = new List<INItemBoxEx>();
			foreach (INItemBoxEx box in select.Select(inventoryID, carrierID))
			{
				list.Add(box);
			}

			if (list.Count == 0 )
			{
				if (string.IsNullOrEmpty(carrierID))
				{
					//there are no explicit boxes setup on the InventoryItem. This means that all system boxes are applicable:
					List<CSBox> allboxes = GetBoxesByCarrierID(carrierID);
					foreach (CSBox csBox in allboxes)
					{
						INItemBoxEx box = new INItemBoxEx();
						box.BoxID = csBox.BoxID;
						box.BaseQty = null;
						box.BoxWeight = csBox.BoxWeight;
						box.CarrierBox = csBox.CarrierBox;
						box.Description = csBox.Description;
						box.InventoryID = inventoryID;
						box.MaxQty = null;
						box.MaxVolume = csBox.MaxVolume;
						box.MaxWeight = csBox.MaxWeight;
						box.Qty = null;
						box.UOM = null;
						list.Add(box);
					}
				}
				else
				{
					//There is no common box between boxes defined for the item and boxess defined for the carrier.
					throw new PXException(Messages.BoxesNotDefined);
				}
			}
			
			return list;
		}
Exemple #37
0
		protected virtual IEnumerable GetRecords()
		{
			bool useOnlyExisting = false;
			PXCache cache = this._Graph.Caches[typeof(DRScheduleDetail)];
			if (cache.Current != null && cache.GetStatus(cache.Current) != PXEntryStatus.Inserted)
			{
				useOnlyExisting = true;
			}


			if (useOnlyExisting)
			{
				PXSelectBase<DRScheduleDetail> select = new PXSelectJoin<DRScheduleDetail,
					LeftJoin<InventoryItem, On<DRScheduleDetail.componentID, Equal<InventoryItem.inventoryID>>>, Where<DRScheduleDetail.scheduleID, Equal<Current<DRScheduleDetail.scheduleID>>>>(this._Graph);

				foreach (PXResult<DRScheduleDetail, InventoryItem> res in select.Select())
				{
					InventoryItem item = (InventoryItem)res;

					if (item.InventoryID != null)
						yield return item;
				}

			}
			else
			{
				foreach (InventoryItem item in PXSelect<InventoryItem>.Select(this._Graph))
				{
					yield return item;
				}
			}

		}