protected virtual IAddressBase GetFromAddress(APInvoice invoice, APTran tran)
 {
     return((IAddressBase)
            PXSelectJoin <PORemitAddress,
                          InnerJoin <POOrder, On <PORemitAddress.addressID, Equal <POOrder.remitAddressID> > >,
                          Where <POOrder.orderType, Equal <Current <APTran.pOOrderType> >,
                                 And <POOrder.orderNbr, Equal <Current <APTran.pONbr> > > > >
            .SelectSingleBound(Base, new[] { tran })
            .RowCast <PORemitAddress>()
            .FirstOrDefault()
            ??
            PXSelectJoin <Address,
                          InnerJoin <Location, On <Location.defAddressID, Equal <Address.addressID> >,
                                     InnerJoin <POReceipt, On <POReceipt.vendorLocationID, Equal <Location.locationID> >,
                                                InnerJoin <POReceiptLine, On <
                                                               POReceiptLine.receiptType, Equal <POReceipt.receiptType>,
                                                               And <POReceiptLine.receiptNbr, Equal <POReceipt.receiptNbr> > > > > >,
                          Where <POReceiptLine.receiptType, Equal <Current <APTran.receiptType> >,
                                 And <POReceiptLine.receiptNbr, Equal <Current <APTran.receiptNbr> >,
                                      And <POReceiptLine.lineNbr, Equal <Current <APTran.receiptLineNbr> > > > > >
            .SelectSingleBound(Base, new[] { tran })
            .RowCast <Address>()
            .FirstOrDefault()
            ??
            PXSelectJoin <Address,
                          InnerJoin <Location, On <Location.defAddressID, Equal <Address.addressID> > >,
                          Where <Location.locationID, Equal <Current <APInvoice.vendorLocationID> > > >
            .SelectSingleBound(Base, new[] { invoice })
            .RowCast <Address>()
            .FirstOrDefault());;
 }
        private TaxPeriod GetTaxPeriodForTaxAdjustment(TaxAdjustment taxAdjustment)
        {
            if (taxAdjustment?.BranchID == null || taxAdjustment.VendorID == null || taxAdjustment.DocDate == null)
            {
                return(null);
            }

            TaxPeriod taxPeriod =
                PXSelectJoin <TaxPeriod,
                              InnerJoin <GL.Branch,
                                         On <GL.Branch.organizationID, Equal <TaxPeriod.organizationID> > >,
                              Where <GL.Branch.branchID, Equal <Required <GL.Branch.branchID> >,
                                     And <TaxPeriod.vendorID, Equal <Required <TaxPeriod.vendorID> >,
                                          And <TaxPeriod.startDate, LessEqual <Required <TaxPeriod.startDate> >,
                                               And <TaxPeriod.endDate, Greater <Required <TaxPeriod.endDate> > > > > > >
                .SelectSingleBound(this, currents : null, pars : new object[]
            {
                taxAdjustment.BranchID,
                taxAdjustment.VendorID,
                taxAdjustment.DocDate,
                taxAdjustment.DocDate
            });

            return(taxPeriod);
        }
        public static string GetDimensionAutonumberingNewValue(this PXGraph graph, string dimension)
        {
            Numbering n = (PXResult <Dimension, Numbering>) PXSelectJoin <Dimension,
                                                                          LeftJoin <Numbering, On <Dimension.numberingID, Equal <Numbering.numberingID> > >,
                                                                          Where <Dimension.dimensionID, Equal <Required <Dimension.dimensionID> >,
                                                                                 And <Numbering.userNumbering, NotEqual <True> > > >
                          .SelectSingleBound(graph, null, dimension);

            return(n.With(_ => _.NewSymbol) ?? Messages.New);
        }
 public virtual EPEmployeeCorpCardLink GetFirstCreditCardForEmployeeAlphabeticallySorted(int employeeID)
 {
     return((EPEmployeeCorpCardLink)PXSelectJoin <EPEmployeeCorpCardLink,
                                                  InnerJoin <CACorpCard,
                                                             On <CACorpCard.corpCardID, Equal <EPEmployeeCorpCardLink.corpCardID> > >,
                                                  Where <EPEmployeeCorpCardLink.employeeID, Equal <Required <EPExpenseClaimDetails.employeeID> >,
                                                         And <CACorpCard.isActive, Equal <True> > >,
                                                  OrderBy <Asc <CACorpCard.name> > >
            .SelectSingleBound(this.Base, null, employeeID));
 }
Beispiel #5
0
        public virtual IAddressBase GetToAddress(ARInvoice invoice, ARTran tran)
        {
            if (invoice.OrigModule == BatchModule.SO)
            {
                var soLine =
                    PXSelectJoin <SOAddress,
                                  InnerJoin <SOOrder, On <SOOrder.shipAddressID, Equal <SOAddress.addressID> >,
                                             LeftJoin <SOLine, On <SOLine.orderType, Equal <SOOrder.orderType>,
                                                                   And <SOLine.orderNbr, Equal <SOOrder.orderNbr> > >,
                                                       LeftJoin <Carrier, On <Carrier.carrierID, Equal <SOOrder.shipVia> > > > >,
                                  Where <SOOrder.orderType, Equal <Current <ARTran.sOOrderType> >,
                                         And <SOOrder.orderNbr, Equal <Current <ARTran.sOOrderNbr> >,
                                              And <Where <Current2 <ARTran.sOOrderLineNbr>, IsNull,
                                                          Or <Current2 <ARTran.sOOrderLineNbr>, Equal <SOLine.lineNbr> > > > > > >
                    .SelectSingleBound(Base, new[] { tran }).AsEnumerable()
                    .Cast <PXResult <SOAddress, SOOrder, SOLine, Carrier> >()
                    .FirstOrDefault();

                var dropShipAddress = GetDropShipDestinationAddress(tran, soLine);
                if (dropShipAddress != null)
                {
                    return(dropShipAddress);
                }

                var shipLine =
                    PXSelectJoin <SOAddress,
                                  InnerJoin <SOShipment, On <SOShipment.shipAddressID, Equal <SOAddress.addressID> >,
                                             LeftJoin <SOShipLine, On <SOShipLine.shipmentType, Equal <SOShipment.shipmentType>,
                                                                       And <SOShipLine.shipmentNbr, Equal <SOShipment.shipmentNbr> > >,
                                                       LeftJoin <Carrier, On <Carrier.carrierID, Equal <SOShipment.shipVia> > > > >,
                                  Where <SOShipment.shipmentType, Equal <Current <ARTran.sOShipmentType> >,
                                         And <SOShipment.shipmentNbr, Equal <Current <ARTran.sOShipmentNbr> >,
                                              And <Where <Current2 <ARTran.sOShipmentLineNbr>, IsNull,
                                                          Or <Current2 <ARTran.sOShipmentLineNbr>, Equal <SOShipLine.lineNbr> > > > > > >
                    .SelectSingleBound(Base, new[] { tran }).AsEnumerable()
                    .Cast <PXResult <SOAddress, SOShipment, SOShipLine, Carrier> >()
                    .FirstOrDefault();

                bool isCommonCarrier = shipLine == null
                                        ? ((Carrier)soLine)?.IsCommonCarrier == true
                                        : ((Carrier)shipLine)?.IsCommonCarrier == true;
                if (tran.SiteID != null && isCommonCarrier == false)
                {
                    return(GetFromAddress(invoice, tran));
                }

                return((tran.LineType == SOLineType.Freight || tran.SOShipmentLineNbr != null ? (SOAddress)shipLine : null).With(ValidAddressFrom <SOShipment.shipAddressID>)
                       ?? (tran.LineType == SOLineType.Freight || tran.SOOrderLineNbr != null ? (SOAddress)soLine : null).With(ValidAddressFrom <SOOrder.shipAddressID>)
                       ?? GetToAddress(invoice));
            }

            return(GetToAddress(invoice));
        }
Beispiel #6
0
        public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            base.FieldDefaulting(sender, e);

            FABookPeriod period = PXSelectJoin <FABookPeriod, LeftJoin <FABook, On <FABookPeriod.bookID, Equal <FABook.bookID> > >,
                                                Where <FABookPeriod.startDate, LessEqual <Current <AccessInfo.businessDate> >, And <FABookPeriod.endDate, Greater <Current <AccessInfo.businessDate> >, And <FABook.updateGL, Equal <boolTrue> > > > > .SelectSingleBound(sender.Graph, new object[0]);

            if (period != null)
            {
                e.NewValue = FinPeriodIDFormattingAttribute.FormatForDisplay(period.FinPeriodID);
            }
        }
 public virtual EPExpenseClaimDetails GetLastUsedCreditCardForEmployee(int employeeID)
 {
     return((EPExpenseClaimDetails)PXSelectJoin <EPExpenseClaimDetails,
                                                 InnerJoin <EPEmployeeCorpCardLink,
                                                            On <EPEmployeeCorpCardLink.employeeID, Equal <EPExpenseClaimDetails.employeeID> >,
                                                            InnerJoin <CACorpCard,
                                                                       On <CACorpCard.corpCardID, Equal <EPEmployeeCorpCardLink.corpCardID>,
                                                                           And <CACorpCard.corpCardID, Equal <EPExpenseClaimDetails.corpCardID> > > > >,
                                                 Where <CACorpCard.isActive, Equal <True>,
                                                        And <EPEmployeeCorpCardLink.employeeID, Equal <Required <EPExpenseClaimDetails.employeeID> > > >,
                                                 OrderBy <Desc <EPExpenseClaimDetails.lastModifiedDateTime> > >
            .SelectSingleBound(this.Base, null, employeeID));
 }
        protected virtual string GetDimensionAutonumberingNewValue(PXGraph graph, string dimension)
        {
            Numbering numbering = (PXResult <Dimension, Numbering>) PXSelectJoin <
                Dimension,
                LeftJoin <Numbering,
                          On <Dimension.numberingID, Equal <Numbering.numberingID> > >,
                Where <
                    Dimension.dimensionID, Equal <Required <Dimension.dimensionID> >,
                    And <Numbering.userNumbering, NotEqual <True> > > >
                                  .SelectSingleBound(graph, null, dimension);

            return(numbering?.NewSymbol ?? Messages.New);
        }
 protected bool PostedTransInOtherCuryExists(Account account, string curyID)
 {
     return(PXSelectJoin <GLTran,
                          InnerJoin <CurrencyInfo,
                                     On <GLTran.curyInfoID, Equal <CurrencyInfo.curyInfoID> >,
                                     InnerJoin <Ledger,
                                                On <GLTran.ledgerID, Equal <Ledger.ledgerID> > > >,
                          Where <GLTran.accountID, Equal <Current <Account.accountID> >,
                                 And <CurrencyInfo.curyID, NotEqual <Required <CurrencyInfo.curyID> >,
                                      And <GLTran.posted, Equal <True>,
                                           And <Ledger.balanceType, NotEqual <LedgerBalanceType.report> > > > > >
            .SelectSingleBound(this, new object[] { account }, curyID)
            .Count > 0);
 }
Beispiel #10
0
        private static Tuple <EMailSyncServer, EMailSyncPolicy, PXSyncMailbox> GetConfig(int emailAccountID)
        {
            PXGraph graph = new PXGraph();

            foreach (PXResult <EMailSyncAccount, EMailSyncServer, EMailAccount, EPEmployee, Contact> row in
                     PXSelectJoin <EMailSyncAccount,
                                   InnerJoin <EMailSyncServer, On <EMailSyncServer.accountID, Equal <EMailSyncAccount.serverID> >,
                                              InnerJoin <EMailAccount, On <EMailAccount.emailAccountID, Equal <EMailSyncAccount.emailAccountID> >,
                                                         LeftJoin <EPEmployee, On <EMailSyncAccount.employeeID, Equal <EPEmployee.bAccountID> >,
                                                                   LeftJoin <Contact, On <EPEmployee.defContactID, Equal <Contact.contactID>, And <EPEmployee.parentBAccountID, Equal <Contact.bAccountID> > > > > > >,
                                   Where <EMailSyncAccount.emailAccountID, Equal <Required <EMailSyncAccount.emailAccountID> > >,
                                   OrderBy <Asc <EMailSyncAccount.serverID, Asc <EMailSyncAccount.employeeID> > > > .SelectSingleBound(graph, null, emailAccountID))
            {
                EMailSyncServer  server       = row;
                EMailSyncAccount account      = row;
                Contact          contact      = row;
                EMailAccount     eMailAccount = row;

                if (server == null || account == null || String.IsNullOrEmpty(account.Address))
                {
                    throw new PXException(Messages.EmailExchangeAccountNotFound);
                }
                if (server.IsActive != true)
                {
                    throw new PXException(Messages.EmailExchangeAccountNotEnabled);
                }

                string address = (contact != null ? contact.EMail : null) ?? account.Address;

                PXSyncMailbox mailbox = new PXSyncMailbox(address, account.EmployeeID.Value, emailAccountID, new PXSyncMailboxPreset(null, null), new PXSyncMailboxPreset(null, null), eMailAccount.IncomingProcessing ?? false);

                string          policyName = account.PolicyName ?? server.DefaultPolicyName;
                EMailSyncPolicy policy     = PXSelect <EMailSyncPolicy, Where <EMailSyncPolicy.policyName, Equal <Required <EMailSyncPolicy.policyName> > > > .SelectSingleBound(graph, null, policyName);

                if (policy == null)
                {
                    throw new PXException(Messages.EmailExchangePolicyNotFound, account.Address);
                }

                if (String.IsNullOrEmpty(server.ServerType) || !_exchangers.ContainsKey(server.ServerType))
                {
                    throw new PXException(Messages.EmailExchangeProviderNotFound);
                }

                return(Tuple.Create(server, policy, mailbox));
            }

            throw new PXException(Messages.EmailExchangeAccountNotFound);
        }
Beispiel #11
0
        protected virtual IEnumerable documentList()
        {
            foreach (ARInvoiceExt doc in PXSelect <ARInvoiceExt> .Select(this))
            {
                bool hasUnreleasedDocument = false;

                foreach (PXResult <ARRetainageInvoice, ARTran> res in PXSelectJoin <ARRetainageInvoice,
                                                                                    LeftJoin <ARTran, On <ARRetainageInvoice.paymentsByLinesAllowed, Equal <True>,
                                                                                                          And <ARTran.tranType, Equal <ARRetainageInvoice.docType>,
                                                                                                               And <ARTran.refNbr, Equal <ARRetainageInvoice.refNbr>,
                                                                                                                    And <ARTran.origLineNbr, Equal <Required <ARTran.origLineNbr> > > > > > >,
                                                                                    Where <ARRetainageInvoice.isRetainageDocument, Equal <True>,
                                                                                           And <ARRetainageInvoice.origDocType, Equal <Required <ARInvoice.docType> >,
                                                                                                And <ARRetainageInvoice.origRefNbr, Equal <Required <ARInvoice.refNbr> >,
                                                                                                     And <ARRetainageInvoice.released, NotEqual <True> > > > > >
                         .SelectSingleBound(this, null, doc.ARTranLineNbr, doc.DocType, doc.RefNbr))
                {
                    ARRetainageInvoice invoice = res;
                    ARTran             tran    = res;

                    if (invoice.PaymentsByLinesAllowed != true ||
                        tran.LineNbr != null)
                    {
                        hasUnreleasedDocument = true;
                    }
                }

                if (!hasUnreleasedDocument)
                {
                    ARRetainageFilter filter   = Filter.Current;
                    bool hasProjectTransaction = true;

                    if (doc.PaymentsByLinesAllowed != true &&
                        (filter.ProjectTaskID != null ||
                         filter.AccountGroupID != null ||
                         filter.CostCodeID != null ||
                         filter.InventoryID != null))
                    {
                        ARTran projectTran = SearchProjectTransaction(doc);
                        hasProjectTransaction = projectTran != null;
                    }

                    if (hasProjectTransaction)
                    {
                        yield return(doc);
                    }
                }
            }
        }
 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, 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 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);
                }
            }
        }
        protected virtual IAddressBase GetFromAddress(ARInvoice invoice, ARTran tran)
        {
            if (invoice.OrigModule == BatchModule.SO)
            {
                var soLine =
                    PXSelectJoin <Address,
                                  InnerJoin <INSite, On <INSite.addressID, Equal <Address.addressID> >,
                                             InnerJoin <SOLine, On <SOLine.siteID, Equal <INSite.siteID> > > >,
                                  Where <SOLine.orderType, Equal <Current <ARTran.sOOrderType> >,
                                         And <SOLine.orderNbr, Equal <Current <ARTran.sOOrderNbr> >,
                                              And <SOLine.lineNbr, Equal <Current <ARTran.sOOrderLineNbr> > > > > >
                    .SelectSingleBound(Base, new[] { tran })
                    .Cast <PXResult <Address, INSite, SOLine> >()
                    .FirstOrDefault();

                return(GetDropShipOriginAddress(tran, soLine)
                       ?? PXSelectJoin <Address,
                                        InnerJoin <INSite, On <INSite.addressID, Equal <Address.addressID> >,
                                                   InnerJoin <SOShipLine, On <SOShipLine.siteID, Equal <INSite.siteID>,
                                                                              And <SOShipLine.shipmentType, Equal <Current <ARTran.sOShipmentType> > > > > >,
                                        Where <SOShipLine.shipmentNbr, Equal <Current <ARTran.sOShipmentNbr> >,
                                               And <SOShipLine.lineNbr, Equal <Current <ARTran.sOShipmentLineNbr> > > > >
                       .SelectSingleBound(Base, new[] { tran })
                       .RowCast <Address>()
                       .FirstOrDefault()
                       .With(ValidAddressFrom <INSite.addressID>)
                       ?? (tran.LineType == SOLineType.Freight
                                                ? PXSelectJoin <Address,
                                                                InnerJoin <INSite, On <INSite.addressID, Equal <Address.addressID> >,
                                                                           InnerJoin <SOShipment, On <SOShipment.siteID, Equal <INSite.siteID> > > >,
                                                                Where <SOShipment.shipmentType, Equal <Current <ARTran.sOShipmentType> >,
                                                                       And <SOShipment.shipmentNbr, Equal <Current <ARTran.sOShipmentNbr> > > > >
                           .SelectSingleBound(Base, new[] { tran })
                           .RowCast <Address>()
                           .FirstOrDefault()
                           .With(ValidAddressFrom <INSite.addressID>)
                                                : null)
                       ?? ((Address)soLine).With(ValidAddressFrom <INSite.addressID>)
                       ?? GetFromAddress(invoice));                 // branch address
            }
            return(GetFromAddress(invoice));
        }
        protected virtual IAddressBase GetToAddress(APInvoice invoice, APTran tran)
        {
            var poLine =
                PXSelectJoin <Address,
                              InnerJoin <INSite, On <INSite.addressID, Equal <Address.addressID> >,
                                         InnerJoin <POLine, On <POLine.siteID, Equal <INSite.siteID> > > >,
                              Where <POLine.orderType, Equal <Current <APTran.pOOrderType> >,
                                     And <POLine.orderNbr, Equal <Current <APTran.pONbr> >,
                                          And <POLine.lineNbr, Equal <Current <APTran.pOLineNbr> > > > > >
                .SelectSingleBound(Base, new[] { tran })
                .Cast <PXResult <Address, INSite, POLine> >()
                .FirstOrDefault();

            var poAddress =
                PXSelectJoin <POShipAddress,
                              InnerJoin <POOrder, On <POShipAddress.addressID, Equal <POOrder.shipAddressID> > >,
                              Where <POOrder.orderType, Equal <Current <APTran.pOOrderType> >,
                                     And <POOrder.orderNbr, Equal <Current <APTran.pONbr> > > > >
                .SelectSingleBound(Base, new[] { tran })
                .RowCast <POShipAddress>()
                .FirstOrDefault();

            if (poLine?.GetItem <POLine>()?.OrderType == POOrderType.DropShip)
            {
                return(poAddress);
            }

            return
                (PXSelectJoin <Address,
                               InnerJoin <INSite, On <INSite.addressID, Equal <Address.addressID> >,
                                          InnerJoin <POReceiptLine, On <POReceiptLine.siteID, Equal <INSite.siteID> > > >,
                               Where <POReceiptLine.receiptType, Equal <Current <APTran.receiptType> >,
                                      And <POReceiptLine.receiptNbr, Equal <Current <APTran.receiptNbr> >,
                                           And <POReceiptLine.lineNbr, Equal <Current <APTran.receiptLineNbr> > > > > >
                 .SelectSingleBound(Base, new[] { tran })
                 .RowCast <Address>()
                 .FirstOrDefault()
                 ?? poLine?.GetItem <Address>()
                 ?? poAddress
                 ?? GetToAddress(invoice));
        }
Beispiel #17
0
        public override object Evaluate(PXCache cache, object item, Dictionary <Type, object> pars)
        {
            string         classID = (string)pars[typeof(ClassID)];
            CRContactClass cls     = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Required <CRContactClass.classID> > > > .Select(cache.Graph, classID);

            if (cls == null)
            {
                return(null);
            }

            var rec = (PXResult <Users, Contact, BAccountR>)
                      PXSelectJoin <Users,
                                    InnerJoin <Contact, On <Contact.userID, Equal <Users.pKID> >,
                                               InnerJoin <BAccountR, On <Contact.contactID, Equal <BAccountR.defContactID>, And <Contact.bAccountID, Equal <BAccountR.parentBAccountID> > > > >,
                                    Where <Users.pKID, Equal <Current <AccessInfo.userID> > > > .SelectSingleBound(cache.Graph, null, null);

            BAccountR bAccount = rec;

            return(bAccount != null && !string.IsNullOrEmpty(bAccount.AcctCD) && cls.OwnerIsCreatedUser == true
                                ? bAccount.AcctCD
                                : null);
        }
        private IAddressBase GetDropShipOriginAddress(ARTran tran, SOLine soLine)
        {
            if (soLine != null && tran.SOOrderLineNbr != null)
            {
                Boolean isDropShip    = soLine.POCreate == true && soLine.POSource == INReplenishmentSource.DropShipToOrder;
                Address vendorAddress = isDropShip
                                        ? PXSelectJoin <Address,
                                                        InnerJoin <Location, On <Location.defAddressID, Equal <Address.addressID> >,
                                                                   InnerJoin <PO.POReceipt, On <PO.POReceipt.vendorLocationID, Equal <Location.locationID> > > >,
                                                        Where <PO.POReceipt.receiptNbr, Equal <Current <ARTran.sOShipmentNbr> > > >
                                        .SelectSingleBound(Base, new[] { tran })
                                        .RowCast <Address>()
                                        .FirstOrDefault()
                                        : null;

                if (vendorAddress != null)
                {
                    return(vendorAddress.With(ValidAddressFrom <PO.POReceipt.vendorLocationID>));
                }
            }
            return(null);
        }
        private void FillFromAccount()
        {
            Contact relatedContact = PXSelectJoin <
                Contact,
                InnerJoin <BAccount,
                           On <BAccount.defContactID, Equal <Contact.contactID> > >,
                Where <
                    BAccount.bAccountID, Equal <Current <Document.bAccountID> > > >
                                     .SelectSingleBound(Base, new[] { Documents.Current });

            Address relatedContactAddress = PXSelectJoin <
                Address,
                InnerJoin <BAccount,
                           On <BAccount.defAddressID, Equal <Address.addressID> > >,
                Where <
                    BAccount.bAccountID, Equal <Current <Document.bAccountID> > > >
                                            .SelectSingleBound(Base, new[] { relatedContact });

            DocumentContact docContact = Contacts.Cache.Current as DocumentContact;
            DocumentAddress docAddress = Addresses.SelectSingle(docContact.DefAddressID);

            FillToDocumentContact(Contacts.Cache, docContact, relatedContact);
            FillToDocumentAddress(Addresses.Cache, docAddress, relatedContactAddress);
        }
        private IAddressBase GetDropShipDestinationAddress(ARTran tran, SOLine soLine)
        {
            if (soLine != null && tran.SOOrderLineNbr != null)
            {
                Boolean      isDropShip      = soLine.POCreate == true && soLine.POSource == INReplenishmentSource.DropShipToOrder;
                IAddressBase dropShipAddress = isDropShip
                                        ? PXSelectJoin <PO.POAddress,
                                                        InnerJoin <PO.POOrder, On <PO.POOrder.shipAddressID, Equal <PO.POAddress.addressID> >,
                                                                   InnerJoin <PO.POReceiptLine, On <PO.POReceiptLine.pOType, Equal <PO.POOrder.orderType>,
                                                                                                    And <PO.POReceiptLine.pONbr, Equal <PO.POOrder.orderNbr> > > > >,
                                                        Where <PO.POReceiptLine.receiptNbr, Equal <Current <ARTran.sOShipmentNbr> >,
                                                               And <PO.POReceiptLine.lineNbr, Equal <Current <ARTran.sOShipmentLineNbr> > > > >
                                               .SelectSingleBound(Base, new[] { tran })
                                               .RowCast <PO.POAddress>()
                                               .FirstOrDefault()
                                        : null;

                if (dropShipAddress != null)
                {
                    return(dropShipAddress.With(ValidAddressFrom <PO.POOrder.shipAddressID>));
                }
            }
            return(null);
        }
        protected virtual void HasOpenDocuments(PXCache sender, INLotSerClass row, string oldValue)
        {
            foreach (PXResult <InventoryItem, PX.Objects.SO.Table.SOShipLineSplit> openShipmentSplit in PXSelectJoin <InventoryItem,
                                                                                                                      InnerJoin <PX.Objects.SO.Table.SOShipLineSplit, On <PX.Objects.SO.Table.SOShipLineSplit.inventoryID, Equal <InventoryItem.inventoryID>, And <PX.Objects.SO.Table.SOShipLineSplit.confirmed, Equal <False> > > >,
                                                                                                                      Where <InventoryItem.lotSerClassID, Equal <Required <INLotSerClass.lotSerClassID> > > > .SelectSingleBound(this, null, row.LotSerClassID))
            {
                InventoryItem item = (InventoryItem)openShipmentSplit;
                PX.Objects.SO.Table.SOShipLineSplit shipmentLineSplit = (PX.Objects.SO.Table.SOShipLineSplit)openShipmentSplit;

                throw new PXException(
                          row.LotSerAssign == INLotSerAssign.WhenReceived
                                                ? Messages.LotSerIssueMethodCannotBeChangedShipment
                                                : Messages.LotSerAutoNextNbrCannotBeChangedShipment,
                          shipmentLineSplit.ShipmentNbr,
                          item.InventoryCD);
            }
        }
        public virtual void HandleARTranCostOrig(ARTran n, bool tranCostSet)
        {
            if (n.InventoryID != null && (n.LineType.IsIn(null, SOLineType.MiscCharge) || n.LineType.IsIn(SOLineType.Inventory, SO.SOLineType.NonInventory) && !tranCostSet))
            {
                //TO DO: review this part and add more accurate cost selection conditions (INItemSite?)
                PXResult <IN.InventoryItem, IN.INItemSite> result = (PXResult <IN.InventoryItem, IN.INItemSite>) PXSelectJoin <IN.InventoryItem,
                                                                                                                               LeftJoin <IN.INItemSite, On <IN.INItemSite.inventoryID, Equal <IN.InventoryItem.inventoryID>,
                                                                                                                                                            And <IN.INItemSite.siteID, Equal <Required <IN.INItemSite.siteID> > > > >,
                                                                                                                               Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .SelectSingleBound(Base, null, n.SiteID, n.InventoryID);

                if (result != null)
                {
                    IN.InventoryItem item     = (IN.InventoryItem)result;
                    IN.INItemSite    itemSite = (IN.INItemSite)result;
                    if (item.StkItem == true)
                    {
                        if (itemSite.ValMethod != null)
                        {
                            if (item.ValMethod == IN.INValMethod.Standard)
                            {
                                n.TranCostOrig = n.Qty * itemSite.StdCost;
                            }
                            else
                            {
                                n.TranCostOrig = n.Qty * itemSite.AvgCost;
                            }
                        }
                    }
                    else if (n.SOShipmentType != SOShipmentType.DropShip)
                    {
                        if (n.AccrueCost == true && n.AccruedCost != null)
                        {
                            n.TranCost        = n.AccruedCost;
                            n.TranCostOrig    = n.AccruedCost;
                            n.IsTranCostFinal = true;
                        }
                        else
                        {
                            if (item.KitItem == true && PXAccess.FeatureInstalled <FeaturesSet.kitAssemblies>() && this.SOSetup.Current != null)
                            {
                                switch (this.SOSetup.Current.SalesProfitabilityForNSKits)
                                {
                                case SalesProfitabilityNSKitMethod.NSKitStandardCostOnly:
                                    n.TranCost       += n.BaseQty * item.StdCost;
                                    n.TranCostOrig    = n.TranCost;
                                    n.IsTranCostFinal = true;
                                    break;

                                case SalesProfitabilityNSKitMethod.NSKitStandardAndStockComponentsCost:
                                    n.TranCost       += n.BaseQty * item.StdCost;
                                    n.TranCostOrig    = n.TranCost;
                                    n.IsTranCostFinal = HasStockComponents(n);
                                    break;

                                case SalesProfitabilityNSKitMethod.StockComponentsCostOnly:
                                    n.IsTranCostFinal = HasStockComponents(n);
                                    break;
                                }
                            }
                            else
                            {
                                n.TranCost       += n.BaseQty * item.StdCost;
                                n.TranCostOrig    = n.TranCost;
                                n.IsTranCostFinal = true;
                            }
                        }
                    }
                }
            }
        }
        public static void ProcessPendingVATProc(List <TaxTran> list)
        {
            JournalEntry je = PXGraph.CreateInstance <JournalEntry>();

            PXCache dummycache = je.Caches[typeof(TaxTran)];

            dummycache = je.Caches[typeof(VATTaxTran)];
            je.Views.Caches.Add(typeof(VATTaxTran));

            DocumentList <Batch> created = new DocumentList <Batch>(je);

            foreach (TaxTran taxtran in list)
            {
                PXProcessing <TaxTran> .SetCurrentItem(taxtran);

                if (string.IsNullOrEmpty(taxtran.TaxInvoiceNbr) == true || taxtran.TaxInvoiceDate == null)
                {
                    //PXProcessing<TaxTran>.SetWarning(Messages.CannotProcessW);
                    PXProcessing <TaxTran> .SetError(Messages.CannotProcessW);
                }
                else
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        foreach (PXResult <VATTaxTran, CurrencyInfo, Tax> res  in PXSelectJoin <VATTaxTran, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <VATTaxTran.curyInfoID> >, InnerJoin <Tax, On <Tax.taxID, Equal <VATTaxTran.taxID> > > >, Where <VATTaxTran.module, Equal <Current <TaxTran.module> >, And <VATTaxTran.tranType, Equal <Current <TaxTran.tranType> >, And <VATTaxTran.refNbr, Equal <Current <TaxTran.refNbr> >, And <VATTaxTran.taxID, Equal <Current <TaxTran.taxID> > > > > > > .SelectSingleBound(je, new object[] { taxtran }))
                        {
                            VATTaxTran   n    = (VATTaxTran)res;
                            CurrencyInfo info = (CurrencyInfo)res;
                            Tax          x    = (Tax)res;

                            string strFinPeriodID = FinPeriodSelectorAttribute.PeriodFromDate(taxtran.TaxInvoiceDate);
                            SegregateBatch(je, info.CuryID, taxtran.TaxInvoiceDate, strFinPeriodID, created);

                            n.TaxInvoiceNbr  = taxtran.TaxInvoiceNbr;
                            n.TaxInvoiceDate = taxtran.TaxInvoiceDate;

                            je.Caches[typeof(VATTaxTran)].Update(n);

                            CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info);

                            new_info.CuryInfoID = null;
                            new_info.ModuleCode = "GL";
                            new_info.BaseCalc   = false;
                            new_info            = je.currencyinfo.Insert(new_info) ?? new_info;

                            //reverse original transaction
                            {
                                GLTran tran = new GLTran();
                                tran.AccountID     = n.AccountID;
                                tran.SubID         = n.SubID;
                                tran.CuryDebitAmt  = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? n.CuryTaxAmt : 0m;
                                tran.DebitAmt      = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? n.TaxAmt : 0m;
                                tran.CuryCreditAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? 0m : n.CuryTaxAmt;
                                tran.CreditAmt     = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? 0m : n.TaxAmt;
                                tran.TranType      = n.TranType;
                                tran.TranClass     = "N";
                                tran.RefNbr        = n.RefNbr;
                                tran.TranDesc      = n.TaxInvoiceNbr;
                                tran.TranPeriodID  = strFinPeriodID;
                                tran.FinPeriodID   = strFinPeriodID;
                                tran.TranDate      = n.TaxInvoiceDate;
                                tran.CuryInfoID    = new_info.CuryInfoID;
                                tran.Released      = true;

                                je.GLTranModuleBatNbr.Insert(tran);

                                VATTaxTran newtran = PXCache <VATTaxTran> .CreateCopy(n);

                                newtran.Module         = "GL";
                                newtran.TranType       = (n.TaxType == TaxType.PendingSales) ? TaxAdjustmentType.ReverseOutputVAT : TaxAdjustmentType.ReverseInputVAT;
                                newtran.RefNbr         = newtran.TaxInvoiceNbr;
                                newtran.TranDate       = newtran.TaxInvoiceDate;
                                newtran.CuryTaxableAmt = -ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.CuryTaxableAmt;
                                newtran.TaxableAmt     = -ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.TaxableAmt;
                                newtran.CuryTaxAmt     = -ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.CuryTaxAmt;
                                newtran.TaxAmt         = -ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.TaxAmt;

                                je.Caches[typeof(VATTaxTran)].Insert(newtran);
                            }

                            //reclassify to VAT account
                            {
                                GLTran tran = new GLTran();
                                tran.AccountID     = (n.TaxType == TaxType.PendingSales) ? x.SalesTaxAcctID : x.PurchTaxAcctID;
                                tran.SubID         = (n.TaxType == TaxType.PendingSales) ? x.SalesTaxSubID : x.PurchTaxSubID;
                                tran.CuryDebitAmt  = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? 0m : n.CuryTaxAmt;
                                tran.DebitAmt      = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? 0m : n.TaxAmt;
                                tran.CuryCreditAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? n.CuryTaxAmt : 0m;
                                tran.CreditAmt     = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? n.TaxAmt : 0m;
                                tran.TranType      = n.TranType;
                                tran.TranClass     = "N";
                                tran.RefNbr        = n.RefNbr;
                                tran.TranDesc      = n.TaxInvoiceNbr;
                                tran.TranPeriodID  = strFinPeriodID;
                                tran.FinPeriodID   = strFinPeriodID;
                                tran.TranDate      = n.TaxInvoiceDate;
                                tran.CuryInfoID    = new_info.CuryInfoID;
                                tran.Released      = true;

                                je.GLTranModuleBatNbr.Insert(tran);

                                VATTaxTran newtran = PXCache <VATTaxTran> .CreateCopy(n);

                                newtran.Module         = "GL";
                                newtran.TranType       = (n.TaxType == TaxType.PendingSales) ? TaxAdjustmentType.OutputVAT : TaxAdjustmentType.InputVAT;
                                newtran.TaxType        = (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase;
                                newtran.AccountID      = (n.TaxType == TaxType.PendingSales) ? x.SalesTaxAcctID : x.PurchTaxAcctID;
                                newtran.SubID          = (n.TaxType == TaxType.PendingSales) ? x.SalesTaxSubID : x.PurchTaxSubID;
                                newtran.RefNbr         = newtran.TaxInvoiceNbr;
                                newtran.TranDate       = newtran.TaxInvoiceDate;
                                newtran.CuryTaxableAmt = ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.CuryTaxableAmt;
                                newtran.TaxableAmt     = ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.TaxableAmt;
                                newtran.CuryTaxAmt     = ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.CuryTaxAmt;
                                newtran.TaxAmt         = ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.TaxAmt;

                                je.Caches[typeof(VATTaxTran)].Insert(newtran);
                            }
                        }

                        je.Save.Press();

                        ts.Complete();
                    }
                    PXProcessing <TaxTran> .SetProcessed();
                }
            }
        }
Beispiel #24
0
        protected override void ClosePeriodProc(FinPeriod p)
        {
            PXSelectBase select = new PXSelect <FATran,
                                                Where <FATran.finPeriodID, Equal <Required <FATran.finPeriodID> >,
                                                       And <FATran.released, Equal <False> > > >(this);
            FATran tran = (FATran)select.View.SelectSingle(p.FinPeriodID);

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

            PXResult <FABookBalance, FixedAsset, FABook> res = (PXResult <FABookBalance, FixedAsset, FABook>) PXSelectJoin <FABookBalance,
                                                                                                                            LeftJoin <FixedAsset, On <FixedAsset.assetID, Equal <FABookBalance.assetID> >,
                                                                                                                                      LeftJoin <FABook, On <FABookBalance.bookID, Equal <FABook.bookID> >,
                                                                                                                                                LeftJoin <FADetails, On <FADetails.assetID, Equal <FABookBalance.assetID> > > > >,
                                                                                                                            Where <FABookBalance.deprFromPeriod, LessEqual <Current <FinPeriod.finPeriodID> >,
                                                                                                                                   And <FABookBalance.deprToPeriod, GreaterEqual <Current <FinPeriod.finPeriodID> >,
                                                                                                                                        And <FABookBalance.updateGL, Equal <True>,
                                                                                                                                             And <FixedAsset.suspended, NotEqual <True>,
                                                                                                                                                  And <FADetails.hold, NotEqual <True>,
                                                                                                                                                       And <FABookBalance.initPeriod, IsNotNull,
                                                                                                                                                            And <Where <FABookBalance.currDeprPeriod, IsNull,
                                                                                                                                                                        And <FABookBalance.status, Equal <FixedAssetStatus.active>,
                                                                                                                                                                             Or <FABookBalance.currDeprPeriod, LessEqual <Current <FinPeriod.finPeriodID> > > > > > > > > > > > > .SelectSingleBound(this, new object[] { p });

            if (res != null)
            {
                FixedAsset asset = res;
                FABook     book  = res;
                throw new PXException(Messages.AssetNotDepreciatedInPeriod, asset.AssetCD, book.BookCode, FinPeriodIDAttribute.FormatForError(p.FinPeriodID));
            }

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

            Actions.PressSave();
        }
Beispiel #25
0
        private static void AddTaxesAndApplications(ARInvoiceEntry ie, PendingPPDCreditMemoApp doc, Customer customer, ARInvoice invoice)
        {
            ARTaxTran artaxMax               = null;
            decimal?  TaxTotal               = 0m;
            decimal?  InclusiveTotal         = 0m;
            decimal?  DiscountedTaxableTotal = 0m;
            decimal?  DiscountedPriceTotal   = 0m;
            decimal   CashDiscPercent        = (decimal)(doc.CuryAdjdPPDAmt / doc.InvCuryOrigDocAmt);

            PXResultset <ARTaxTran> taxes = PXSelectJoin <ARTaxTran,
                                                          InnerJoin <Tax, On <Tax.taxID, Equal <ARTaxTran.taxID> > >,
                                                          Where <ARTaxTran.module, Equal <BatchModule.moduleAR>,
                                                                 And <ARTaxTran.tranType, Equal <Required <ARTaxTran.tranType> >,
                                                                      And <ARTaxTran.refNbr, Equal <Required <ARTaxTran.refNbr> > > > > > .Select(ie, doc.AdjdDocType, doc.AdjdRefNbr);

            //add taxes
            foreach (PXResult <ARTaxTran, Tax> res in taxes)
            {
                Tax       tax   = res;
                ARTaxTran artax = PXCache <ARTaxTran> .CreateCopy(res);

                ARTaxTran artaxNew = ie.Taxes.Search <ARTaxTran.taxID>(artax.TaxID);

                if (artaxNew == null)
                {
                    artax.TranType    = null;
                    artax.RefNbr      = null;
                    artax.TaxPeriodID = null;
                    artax.Released    = false;
                    artax.Voided      = false;
                    artax.CuryInfoID  = invoice.CuryInfoID;

                    TaxBaseAttribute.SetTaxCalc <ARTran.taxCategoryID, ARTaxAttribute>(ie.Transactions.Cache, null, TaxCalc.NoCalc);
                    artaxNew = ie.Taxes.Insert(artax);

                    artaxNew.CuryTaxableAmt = 0m;
                    artaxNew.CuryTaxAmt     = 0m;
                    artaxNew.TaxRate        = artax.TaxRate;
                }

                bool isTaxable = CalculateDiscountedTaxes(ie.Taxes.Cache, artax, CashDiscPercent);
                DiscountedPriceTotal += artax.CuryDiscountedPrice;

                decimal?CuryTaxableAmt = artax.CuryTaxableAmt - artax.CuryDiscountedTaxableAmt;
                decimal?CuryTaxAmt     = artax.CuryTaxAmt - artax.CuryDiscountedPrice;

                artaxNew.CuryTaxableAmt += CuryTaxableAmt;
                artaxNew.CuryTaxAmt     += CuryTaxAmt;

                TaxBaseAttribute.SetTaxCalc <ARTran.taxCategoryID, ARTaxAttribute>(ie.Transactions.Cache, null, TaxCalc.ManualCalc);
                ie.Taxes.Update(artaxNew);

                if (isTaxable)
                {
                    DiscountedTaxableTotal += artax.CuryDiscountedTaxableAmt;
                    if (artaxMax == null || artaxNew.CuryTaxableAmt > artaxMax.CuryTaxableAmt)
                    {
                        artaxMax = artaxNew;
                    }
                }

                if (tax.TaxCalcLevel == CSTaxCalcLevel.Inclusive)
                {
                    InclusiveTotal += CuryTaxAmt;
                }
                else
                {
                    TaxTotal += CuryTaxAmt;
                }
            }

            //adjust taxes according to parent ARInvoice
            decimal?DiscountedInvTotal = doc.InvCuryOrigDocAmt - doc.InvCuryOrigDiscAmt;
            decimal?DiscountedDocTotal = DiscountedTaxableTotal + DiscountedPriceTotal;

            if (doc.InvCuryOrigDiscAmt == doc.CuryAdjdPPDAmt &&
                artaxMax != null &&
                doc.InvCuryVatTaxableTotal + doc.InvCuryTaxTotal == doc.InvCuryOrigDocAmt &&
                DiscountedDocTotal != DiscountedInvTotal)
            {
                artaxMax.CuryTaxableAmt += DiscountedDocTotal - DiscountedInvTotal;
                TaxBaseAttribute.SetTaxCalc <ARTran.taxCategoryID, ARTaxAttribute>(ie.Transactions.Cache, null, TaxCalc.ManualCalc);
                ie.Taxes.Update(artaxMax);
            }

            //add document details
            ARTran tranNew = ie.Transactions.Insert();

            tranNew.BranchID = doc.AdjdBranchID;
            using (new PXLocaleScope(customer.LocaleName))
                tranNew.TranDesc = string.Format("{0} {1}, {2} {3}", PXMessages.LocalizeNoPrefix(DocTypes[doc.AdjdDocType]), doc.AdjdRefNbr, PXMessages.LocalizeNoPrefix(Messages.Payment), doc.AdjgRefNbr);
            tranNew.CuryExtPrice         = doc.CuryAdjdPPDAmt - TaxTotal;
            tranNew.CuryTaxableAmt       = tranNew.CuryExtPrice - InclusiveTotal;
            tranNew.CuryTaxAmt           = TaxTotal + InclusiveTotal;
            tranNew.AccountID            = customer.DiscTakenAcctID;
            tranNew.SubID                = customer.DiscTakenSubID;
            tranNew.TaxCategoryID        = null;
            tranNew.IsFree               = true;
            tranNew.ManualDisc           = true;
            tranNew.CuryDiscAmt          = 0m;
            tranNew.DiscPct              = 0m;
            tranNew.GroupDiscountRate    = 1m;
            tranNew.DocumentDiscountRate = 1m;

            if (taxes.Count == 1)
            {
                ARTaxTran artax  = taxes[0];
                ARTran    artran = PXSelectJoin <ARTran,
                                                 InnerJoin <ARTax, On <ARTax.tranType, Equal <ARTran.tranType>,
                                                                       And <ARTax.refNbr, Equal <ARTran.refNbr>,
                                                                            And <ARTax.lineNbr, Equal <ARTran.lineNbr> > > > >,
                                                 Where <ARTax.tranType, Equal <Required <ARTax.tranType> >,
                                                        And <ARTax.refNbr, Equal <Required <ARTax.refNbr> >,
                                                             And <ARTax.taxID, Equal <Required <ARTax.taxID> > > > >,
                                                 OrderBy <Asc <ARTran.lineNbr> > > .SelectSingleBound(ie, null, artax.TranType, artax.RefNbr, artax.TaxID);

                if (artran != null)
                {
                    tranNew.TaxCategoryID = artran.TaxCategoryID;
                }
            }

            ie.Transactions.Update(tranNew);

            //add applications
            ARAdjust adj = new ARAdjust();

            adj.AdjdDocType = doc.AdjdDocType;
            adj.AdjdRefNbr  = doc.AdjdRefNbr;
            adj             = ie.Adjustments_1.Insert(adj);

            adj.CuryAdjgAmt = doc.InvCuryDocBal;
            ie.Adjustments_1.Update(adj);
        }
Beispiel #26
0
        protected virtual void DefaultUnitCost(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            if (adjustment.Current != null && adjustment.Current.OrigModule == INRegister.origModule.PI)
            {
                return;
            }

            object UnitCost = null;

            InventoryItem item = (InventoryItem)PXSelectorAttribute.Select <INTran.inventoryID>(sender, e.Row);

            if (item.ValMethod == INValMethod.Specific && string.IsNullOrEmpty(((INTran)e.Row).LotSerialNbr) == false)
            {
                INCostStatus status = PXSelectJoin <INCostStatus,
                                                    LeftJoin <INLocation, On <INLocation.locationID, Equal <Current <INTran.locationID> > >,
                                                              InnerJoin <INCostSubItemXRef, On <INCostSubItemXRef.costSubItemID, Equal <INCostStatus.costSubItemID> > > >,
                                                    Where <INCostStatus.inventoryID, Equal <Current <INTran.inventoryID> >, And2 <Where <INLocation.isCosted, Equal <boolFalse>, And <INCostStatus.costSiteID, Equal <Current <INTran.siteID> >, Or <INCostStatus.costSiteID, Equal <Current <INTran.locationID> > > > >, And <INCostSubItemXRef.subItemID, Equal <Current <INTran.subItemID> >, And <INCostStatus.lotSerialNbr, Equal <Current <INTran.lotSerialNbr> > > > > > > .SelectSingleBound(this, new object[] { e.Row });

                if (status != null && status.QtyOnHand != 0m)
                {
                    UnitCost = PXDBPriceCostAttribute.Round((decimal)(status.TotalCost / status.QtyOnHand));
                }
            }
            else if (item.ValMethod == INValMethod.FIFO && string.IsNullOrEmpty(((INTran)e.Row).OrigRefNbr) == false)
            {
                INCostStatus status = PXSelectJoin <INCostStatus,
                                                    LeftJoin <INLocation, On <INLocation.locationID, Equal <Current <INTran.locationID> > >,
                                                              InnerJoin <INCostSubItemXRef, On <INCostSubItemXRef.costSubItemID, Equal <INCostStatus.costSubItemID> > > >,
                                                    Where <INCostStatus.inventoryID, Equal <Current <INTran.inventoryID> >, And2 <Where <INLocation.isCosted, Equal <boolFalse>, And <INCostStatus.costSiteID, Equal <Current <INTran.siteID> >, Or <INCostStatus.costSiteID, Equal <Current <INTran.locationID> > > > >, And <INCostSubItemXRef.subItemID, Equal <Current <INTran.subItemID> >, And <INCostStatus.receiptNbr, Equal <Current <INTran.origRefNbr> > > > > > > .SelectSingleBound(this, new object[] { e.Row });

                if (status != null && status.QtyOnHand != 0m)
                {
                    UnitCost = PXDBPriceCostAttribute.Round((decimal)(status.TotalCost / status.QtyOnHand));
                }
            }
            else
            {
                if (item.ValMethod == INValMethod.Average)
                {
                    sender.RaiseFieldDefaulting <INTran.avgCost>(e.Row, out UnitCost);
                }
                if (UnitCost == null || (decimal)UnitCost == 0m)
                {
                    sender.RaiseFieldDefaulting <INTran.unitCost>(e.Row, out UnitCost);
                }
            }


            decimal?qty = (decimal?)sender.GetValue <INTran.qty>(e.Row);

            if (UnitCost != null && ((decimal)UnitCost != 0m || qty < 0m))
            {
                if ((decimal)UnitCost < 0m)
                {
                    sender.RaiseFieldDefaulting <INTran.unitCost>(e.Row, out UnitCost);
                }

                decimal?unitcost = INUnitAttribute.ConvertToBase <INTran.inventoryID>(sender, e.Row, ((INTran)e.Row).UOM, (decimal)UnitCost, INPrecision.UNITCOST);

                //suppress trancost recalculation for cost only adjustments
                if (qty == 0m)
                {
                    sender.SetValue <INTran.unitCost>(e.Row, unitcost);
                }
                else
                {
                    sender.SetValueExt <INTran.unitCost>(e.Row, unitcost);
                }
            }
        }
        public static void ValidateCCPayment(PXGraph graph, List <IExternalTransaction> list, bool isMassProcess)
        {
            bool            failed          = false;
            ARCashSaleEntry arCashSaleGraph = null;
            ARPaymentEntry  arPaymentGraph  = null;
            SOInvoiceEntry  soInvoiceGraph  = null;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i] == null)
                {
                    continue;
                }

                if ((i % 100) == 0)
                {
                    if (arCashSaleGraph != null)
                    {
                        arCashSaleGraph.Clear();
                    }
                    if (arPaymentGraph != null)
                    {
                        arPaymentGraph.Clear();
                    }
                    if (soInvoiceGraph != null)
                    {
                        soInvoiceGraph.Clear();
                    }
                }

                IExternalTransaction tran = list[i];

                var resultSet = PXSelectJoin <Standalone.ARRegister,
                                              LeftJoin <ARPayment,
                                                        On <ARPayment.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                            And <ARPayment.docType, Equal <Standalone.ARRegister.docType> > >,
                                                        LeftJoin <ARInvoice,
                                                                  On <ARInvoice.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                      And <ARInvoice.docType, Equal <Standalone.ARRegister.docType> > >,
                                                                  LeftJoin <SOInvoice,
                                                                            On <SOInvoice.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                                And <SOInvoice.docType, Equal <Standalone.ARRegister.docType> > >,
                                                                            LeftJoin <Standalone.ARCashSale,
                                                                                      On <Standalone.ARCashSale.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                                          And <Standalone.ARCashSale.docType, Equal <Standalone.ARRegister.docType> > > > > > >,
                                              Where <Standalone.ARRegister.refNbr, Equal <Required <Standalone.ARRegister.refNbr> >,
                                                     And <Standalone.ARRegister.docType, Equal <Required <Standalone.ARRegister.docType> > > > >
                                .SelectSingleBound(graph, null, tran.RefNbr, tran.DocType);

                foreach (PXResult <Standalone.ARRegister, ARPayment, ARInvoice, SOInvoice, Standalone.ARCashSale> arDoc in resultSet)
                {
                    if (arDoc == null)
                    {
                        continue;
                    }

                    try
                    {
                        if ((ARInvoice)arDoc is ARInvoice arInvoice &&
                            arInvoice != null && arInvoice.RefNbr != null)
                        {
                            if ((SOInvoice)arDoc is SOInvoice soInvoice &&
                                soInvoice != null && soInvoice.RefNbr != null)
                            {
                                soInvoiceGraph = soInvoiceGraph != null ? soInvoiceGraph : PXGraph.CreateInstance <SOInvoiceEntry>();
                                SOInvoiceEntry.PaymentTransaction ext = soInvoiceGraph.GetExtension <SOInvoiceEntry.PaymentTransaction>();
                                soInvoiceGraph.Document.Current   = arInvoice;
                                soInvoiceGraph.SODocument.Current = soInvoice;
                                if (ext.CanValidate(arInvoice))
                                {
                                    ext.validateCCPayment.Press();
                                }
                            }
                            else if ((Standalone.ARCashSale)arDoc is Standalone.ARCashSale arCashSale &&
                                     arCashSale != null && arCashSale.RefNbr != null)
                            {
                                arCashSaleGraph = arCashSaleGraph != null ? arCashSaleGraph : PXGraph.CreateInstance <ARCashSaleEntry>();
                                ARCashSaleEntry.PaymentTransaction ext = arCashSaleGraph.GetExtension <ARCashSaleEntry.PaymentTransaction>();
                                arCashSaleGraph.Document.Current = arCashSale;
                                if (ext.CanValidate(arCashSaleGraph.Document.Current))
                                {
                                    ext.validateCCPayment.Press();
                                }
                            }
                        }
        protected virtual IEnumerable Cancel(PXAdapter a)
        {
            string organizationCD;
            string yearNumber;

            if (NewCalendarParams.View.Answer == WebDialogResult.None)             // First outer call
            {
                FinYearKey storedYearKey = new FinYearKey
                {
                    OrganizationID = OrgFinYear.Current?.OrganizationID,
                    Year           = OrgFinYear.Current?.Year
                };

                #region Deliberate Technomagic. Copy-pasted fron base PXCancel instead invocation
                Clear();
                SelectTimeStamp();
                #endregion

                StoredYearKey.Cache.Clear();
                StoredYearKey.Insert(storedYearKey);
                StoredYearKey.Cache.IsDirty = false;

                organizationCD = (string)a.Searches.GetSearchValueByPosition(0);
                if (organizationCD == null)
                {
                    yield break;
                }
                yearNumber = (string)a.Searches.GetSearchValueByPosition(1);
            }
            else             // Second call after SmartPanel closing
            {
                object       extValue = NewCalendarParams.Cache.GetValueExt <NewOrganizationCalendarParameters.organizationID>(NewCalendarParams.Current);
                PXFieldState state    = extValue as PXFieldState;
                organizationCD = state != null ? (string)state.Value : (string)extValue;
                yearNumber     = NewCalendarParams.Current.StartYear;
            }

            OrganizationFinYear targetYear = PXSelectJoin <
                OrganizationFinYear,
                InnerJoin <Organization,
                           On <OrganizationFinYear.organizationID, Equal <Organization.organizationID> > >,
                Where <Organization.organizationCD, Equal <Required <Organization.organizationCD> >,
                       And <OrganizationFinYear.year, Equal <Required <OrganizationFinYear.year> > > > >
                                             .SelectSingleBound(this, new object[] { }, organizationCD, yearNumber);

            OrganizationFinYear returnYear = null;
            if (targetYear == null)
            {
                OrganizationFinYear lastYear = LastOrganizationYear.SelectSingle(organizationCD);

                if (lastYear == null)
                {
                    if (NewCalendarParams.AskExtFullyValid((graph, viewName) =>
                    {
                        NewCalendarParams.Current.OrganizationID = PXAccess.GetOrganizationID(organizationCD);
                    },
                                                           DialogAnswerType.Positive))
                    {
                        OrganizationFinYear generatedFinYear;
                        using (PXTransactionScope ts = new PXTransactionScope())
                        {
                            generatedFinYear = GenerateSingleOrganizationFinYear(
                                (int)NewCalendarParams.Current.OrganizationID,
                                NewCalendarParams.Current.StartYear,
                                NewCalendarParams.Current.StartMasterFinPeriodID);
                            Actions.PressSave();
                            ts.Complete();
                        }
                        returnYear = generatedFinYear;
                    }
                    else
                    {
                        OrganizationFinYear storedYear = FinPeriodRepository.FindOrganizationFinYearByID(StoredYearKey.Current?.OrganizationID, StoredYearKey.Current?.Year);
                        returnYear = storedYear;
                    }
                }
                else
                {
                    returnYear = lastYear;
                }
            }
            else
            {
                returnYear = targetYear;
            }

            if (returnYear != null)
            {
                yield return(returnYear);
            }
            yield break;
        }