Exemple #1
0
        private bool CanDelete(CRCustomerClass row)
        {
            if (row != null)
            {
                BAccount c = PXSelect <BAccount,
                                       Where <BAccount.classID, Equal <Required <BAccount.classID> > > > .
                             SelectWindowed(this, 0, 1, row.CRCustomerClassID);

                if (c != null)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        protected virtual void Contact_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
        {
            Contact cont = (Contact)e.Row;

            if (cont != null && cont.ContactType == ContactTypesAttribute.Employee && cache.ObjectsEqual <Contact.displayName>(e.Row, e.OldRow))
            {
                BAccount emp =
                    PXSelect <BAccount,
                              Where <BAccount.parentBAccountID, Equal <Current <Contact.bAccountID> >,
                                     And <BAccount.defContactID, Equal <Current <CR.Contact.contactID> > > > > .SelectSingleBound(this, new object[] { cont });

                if (emp != null)
                {
                    emp = (BAccount)this.bAccountBasic.Cache.CreateCopy(emp);
                    this.bAccountBasic.Cache.SetValueExt <EPEmployee.acctName>(emp, cont.DisplayName);
                    this.bAccountBasic.Update(emp);
                }
            }
        }
        protected virtual void CRPurgeFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            CRPurgeFilter filter = (CRPurgeFilter)e.Row;

            if (filter == null)
            {
                return;
            }

            PXUIFieldAttribute.SetEnabled <CRPurgeFilter.purgeAgeOfNotConvertedLeads>(sender, filter, filter.PurgeOldNotConvertedLeads == true);
            PXUIFieldAttribute.SetEnabled <CRPurgeFilter.purgePeriodWithoutActivity>(sender, filter, filter.PurgeOldInertContacts == true);

            Items.SetProcessDelegate(delegate(PurgeContactsProcess graph, Contact contact)
            {
                BAccount bacct = PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Current <Contact.bAccountID> > > > .SelectSingleBound(graph, new object[] { contact });
                if (bacct == null || bacct.DefAddressID != contact.DefAddressID)
                {
                    graph.Address.Delete(new Address {
                        AddressID = contact.DefAddressID
                    });
                }

                foreach (CRPMSMEmail activity in graph.Activities.Select(new object[] { contact.ContactID }))
                {
                    if (activity.IsBillable == true || !string.IsNullOrEmpty(activity.TimeCardCD) ||
                        activity.MPStatus == MailStatusListAttribute.InProcess)
                    {
                        throw new PXException(Messages.CannotDeleteActivity);
                    }
                    graph.Activities.Delete(activity);
                }

                // Relations, Marketing List members, Campaign members and Notifications delete by PXParentAttribute

                graph.Items.Delete(contact);
                graph.Actions.PressSave();
            }
                                     );
        }
        public static void ConvertToAccount(Contact contact, AccountsFilter param)
        {
            BusinessAccountMaint accountMaint = CreateInstance <BusinessAccountMaint>();
            object cd = param.BAccountID;

            accountMaint.BAccount.Cache.RaiseFieldUpdating <BAccount.acctCD>(null, ref cd);
            BAccount account = new BAccount
            {
                AcctCD           = (string)cd,
                AcctName         = param.AccountName,
                Type             = BAccountType.ProspectType,
                ClassID          = param.AccountClass,
                ParentBAccountID = contact.ParentBAccountID
            };

            #region Set Contact and Address fields
            CRContactClass cls = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Current <Contact.classID> > > > .SelectSingleBound(accountMaint, new object[] { contact });

            if (cls != null && cls.OwnerToBAccount == true)
            {
                account.WorkgroupID = contact.WorkgroupID;
                account.OwnerID     = contact.OwnerID;
            }

            try
            {
                object newValue = account.OwnerID;
                accountMaint.BAccount.Cache.RaiseFieldVerifying <BAccount.ownerID>(account, ref newValue);
            }
            catch (PXSetPropertyException)
            {
                account.OwnerID = null;
            }

            account = accountMaint.BAccount.Insert(account);

            accountMaint.Answers.CopyAllAttributes(account, contact);

            Contact defContact = PXCache <Contact> .CreateCopy(PXSelect <Contact, Where <Contact.contactID, Equal <Current <BAccount.defContactID> > > > .SelectSingleBound(accountMaint, new object[] { account }));

            var defContactNoteID = defContact.NoteID;
            PXCache <Contact> .RestoreCopy(defContact, contact);

            defContact.ContactType     = ContactTypesAttribute.BAccountProperty;
            defContact.FullName        = account.AcctName;
            defContact.ContactID       = account.DefContactID;
            defContact.BAccountID      = account.BAccountID;
            defContact.DuplicateStatus = DuplicateStatusAttribute.NotValidated;
            defContact.DuplicateFound  = false;
            defContact.WorkgroupID     = null;
            defContact.OwnerID         = null;
            defContact.NoteID          = defContactNoteID;
            defContact = accountMaint.DefContact.Update(defContact);

            Address contactAddress = PXSelect <Address, Where <Address.addressID, Equal <Required <Contact.defAddressID> > > > .Select(accountMaint, contact.DefAddressID);

            if (contactAddress == null)
            {
                throw new PXException(Messages.DefAddressNotExists, contact.DisplayName);
            }
            contactAddress.BAccountID = account.BAccountID;
            accountMaint.AddressCurrent.Cache.Clear();

            defContact.DefAddressID = contactAddress.AddressID;
            defContact = accountMaint.DefContact.Update(defContact);

            contactAddress = accountMaint.AddressCurrent.Update(contactAddress);

            account.DefAddressID = contactAddress.AddressID;
            accountMaint.BAccount.Update(account);

            contact.BAccountID      = account.BAccountID;
            contact.DuplicateStatus = DuplicateStatusAttribute.NotValidated;
            contact.DuplicateFound  = false;
            if (contact.QualificationDate == null)
            {
                contact.QualificationDate = PXTimeZoneInfo.Now;
            }
            accountMaint.Contacts.Cache.SetStatus(contact, PXEntryStatus.Updated);
            CR.Location location = accountMaint.DefLocation.Select();
            location.DefAddressID = contactAddress.AddressID;
            accountMaint.DefLocation.Update(location);

            account.NoteID = PXNoteAttribute.GetNoteID <CRActivity.noteID>(accountMaint.CurrentBAccount.Cache, account);
            foreach (CRPMTimeActivity a in PXSelect <CRPMTimeActivity, Where <CRPMTimeActivity.refNoteID, Equal <Required <Contact.noteID> > > > .Select(accountMaint, contact.NoteID))
            {
                a.BAccountID = account.BAccountID;
                accountMaint.Activities.Cache.Update(a);
            }
            #endregion

            // Copy Note text and Files references
            CRSetup setup = PXSetupOptional <CRSetup> .Select(accountMaint);

            PXNoteAttribute.CopyNoteAndFiles(accountMaint.Contacts.Cache, contact, accountMaint.CurrentBAccount.Cache, account, setup);

            throw new PXRedirectRequiredException(accountMaint, "Business Account");
        }
Exemple #5
0
        protected override bool Process(Package package)
        {
            var account = package.Account;

            if (account.IncomingProcessing != true ||
                account.CreateCase != true)
            {
                return(false);
            }

            var message = package.Message;

            if (!string.IsNullOrEmpty(message.Exception) ||
                message.IsIncome != true ||
                message.RefNoteID != null ||
                message.ClassID == CRActivityClass.EmailRouting)
            {
                return(false);
            }


            var graph = PXGraph.CreateInstance <CRCaseMaint>();

            SetCRSetup(graph);
            SetAccessInfo(graph);
            var copy = package.Graph.Caches[typeof(CRSMEmail)].CreateCopy(message);

            try
            {
                var caseCache = graph.Caches[typeof(CRCase)];
                var @case     = (CRCase)caseCache.Insert();
                @case = graph.Case.Search <CRCase.caseCD>(@case.CaseCD);
                @case = PXCache <CRCase> .CreateCopy(@case);

                //@case.EMail = package.Address;
                @case.Subject = message.Subject;
                if (@case.Subject == null || @case.Subject.Trim().Length == 0)
                {
                    @case.Subject = GetFromString(package.Address, package.Description);
                }
                @case.Description = message.Body;

                if (account.CreateCaseClassID != null)
                {
                    @case.CaseClassID = account.CreateCaseClassID;
                }

                CRCaseClass caseClass = PXSelect <CRCaseClass, Where <CRCaseClass.caseClassID, Equal <Required <CRCaseClass.caseClassID> > > > .SelectSingleBound(graph, null, @case.CaseClassID);

                if (caseClass == null)
                {
                    return(false);
                }

                @case = PXCache <CRCase> .CreateCopy((CRCase)caseCache.Update(@case));

                BAccount baccount = null;
                var      contact  = FindContact(graph, package.Address);
                if (contact != null)
                {
                    @case.ContactID   = contact.ContactID;
                    message.ContactID = contact.ContactID;
                    baccount          = FindAccount(graph, contact);
                }
                else if (caseClass.RequireContact == true)
                {
                    return(false);
                }

                if (baccount == null && contact == null)
                {
                    baccount = FindAccount(graph, package.Address);
                }

                if (baccount != null)
                {
                    PXCache cache = graph.Caches[typeof(BAccount)];
                    graph.EnsureCachePersistence(cache.GetItemType());
                    message.BAccountID = baccount.BAccountID;
                    @case.CustomerID   = baccount.BAccountID;
                }
                else if (caseClass.RequireCustomer == true)
                {
                    return(false);
                }

                message.RefNoteID = PXNoteAttribute.GetNoteID <CRCase.noteID>(graph.Caches[typeof(CRCase)], @case);
                caseCache.Update(@case);
                graph.Activities.Cache.Current = message;
                graph.Save.PressImpl(false);
            }
            catch (Exception e)
            {
                package.Graph.Caches[typeof(CRSMEmail)].RestoreCopy(message, copy);
                throw new PXException(Messages.CreateCaseException, e is PXOuterException ? ("\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages)) : e.Message);
            }
            return(true);
        }
Exemple #6
0
        private static void ProcessValidation(ValidationFilter filter, Contact record)
        {
            BusinessAccountMaint graph = PXGraph.CreateInstance <BusinessAccountMaint>();
            PXView view = graph.BAccount.View;

            int startRow = 0, totalRows = 0;

            BAccount baccount = null;
            Contact  contact  = null;

            if (record.ContactType == ContactTypesAttribute.BAccountProperty && record.BAccountID != null)
            {
                List <object> list_baccount = view.Select(null, null, new object[] { record.BAccountID }, new string[] { typeof(BAccount.bAccountID).Name }, null, null,
                                                          ref startRow, 1, ref totalRows);
                if (list_baccount != null && list_baccount.Count >= 1)
                {
                    baccount = PXResult.Unwrap <BAccount>(list_baccount[0]);
                }
            }
            if (baccount == null || baccount.DefContactID != record.ContactID)
            {
                throw new PXException(Messages.ContactNotFound);
            }

            contact = graph.DefContact.Current = graph.DefContact.SelectWindowed(0, 1);
            contact.DuplicateFound = true;

            PXView viewDuplicates = graph.Duplicates.View;

            if (viewDuplicates == null)
            {
                throw new PXException(Messages.DuplicateViewNotFound);
            }
            viewDuplicates.Clear();
            List <object> duplicates = viewDuplicates.SelectMulti();

            contact = (Contact)graph.DefContact.Cache.CreateCopy(contact);
            contact.DuplicateStatus = DuplicateStatusAttribute.Validated;
            Decimal?score = 0;

            foreach (PXResult <CRDuplicateRecord, Contact, CRLeadContactValidationProcess.Contact2> r in duplicates)
            {
                CRLeadContactValidationProcess.Contact2 duplicate = r;
                CRDuplicateRecord contactScore = r;

                int duplicateWeight = ContactMaint.GetContactWeight(duplicate);
                int currentWeight   = ContactMaint.GetContactWeight(contact);
                if (duplicateWeight > currentWeight ||
                    (duplicateWeight == currentWeight &&
                     duplicate.ContactID < contact.ContactID))
                {
                    contact.DuplicateStatus = DuplicateStatusAttribute.PossibleDuplicated;
                    if (contactScore.Score > score)
                    {
                        score = contactScore.Score;
                    }
                }
            }
            graph.DefContact.Cache.Update(contact);
            graph.DefContact.Cache.RestoreCopy(record, contact);
            graph.Actions.PressSave();
        }
        protected virtual GetTaxRequest BuildGetTaxRequest(CROpportunity order)
        {
            if (order == null)
            {
                throw new PXArgumentException(nameof(order));
            }

            BAccount cust = (BAccount)PXSelect <BAccount,
                                                Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .
                            Select(Base, order.BAccountID);

            Location loc = (Location)PXSelect <Location,
                                               Where <Location.bAccountID, Equal <Required <Location.bAccountID> >, And <Location.locationID, Equal <Required <Location.locationID> > > > > .
                           Select(Base, order.BAccountID, order.LocationID);

            IAddressBase addressFrom = GetFromAddress();
            IAddressBase addressTo   = GetToAddress(order);

            if (addressFrom == null)
            {
                throw new PXException(Messages.FailedGetFromAddressCR);
            }

            if (addressTo == null)
            {
                throw new PXException(Messages.FailedGetToAddressCR);
            }

            GetTaxRequest request = new GetTaxRequest();

            request.CompanyCode        = CompanyCodeFromBranch(order.TaxZoneID, Base.Accessinfo.BranchID);
            request.CurrencyCode       = order.CuryID;
            request.CustomerCode       = cust?.AcctCD;
            request.OriginAddress      = AddressConverter.ConvertTaxAddress(addressFrom);
            request.DestinationAddress = AddressConverter.ConvertTaxAddress(addressTo);
            request.DocCode            = $"CR.{order.OpportunityID}";
            request.DocDate            = order.CloseDate.GetValueOrDefault();
            request.Discount           = order.CuryLineDocDiscountTotal.GetValueOrDefault();

            int mult = 1;

            if (loc != null)
            {
                request.CustomerUsageType = loc.CAvalaraCustomerUsageType;
            }
            if (!string.IsNullOrEmpty(loc?.CAvalaraExemptionNumber))
            {
                request.ExemptionNo = loc.CAvalaraExemptionNumber;
            }

            request.DocType = TaxDocumentType.SalesOrder;

            PXSelectBase <CROpportunityProducts> select = new PXSelectJoin <CROpportunityProducts,
                                                                            LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <CROpportunityProducts.inventoryID> >,
                                                                                      LeftJoin <Account, On <Account.accountID, Equal <InventoryItem.salesAcctID> > > >,
                                                                            Where <CROpportunityProducts.quoteID, Equal <Current <CROpportunity.quoteNoteID> > >,
                                                                            OrderBy <Asc <CROpportunityProducts.lineNbr> > >(Base);

            foreach (PXResult <CROpportunityProducts, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order }))
            {
                CROpportunityProducts tran = (CROpportunityProducts)res;
                InventoryItem         item = (InventoryItem)res;
                Account salesAccount       = (Account)res;

                var line = new TaxCartItem();
                line.Index              = tran.LineNbr ?? 0;
                line.Amount             = mult * tran.CuryAmount.GetValueOrDefault();
                line.Description        = tran.Descr;
                line.DestinationAddress = request.DestinationAddress;
                line.OriginAddress      = request.OriginAddress;
                line.ItemCode           = item.InventoryCD;
                line.Quantity           = Math.Abs(tran.Qty.GetValueOrDefault());
                line.Discounted         = request.Discount > 0;
                line.RevAcct            = salesAccount.AccountCD;
                line.TaxCode            = tran.TaxCategoryID;

                request.CartItems.Add(line);
            }

            return(request);
        }
        protected override bool Process(Package package)
        {
            var account = package.Account;

            if (account.IncomingProcessing != true ||
                account.CreateActivity != true)
            {
                return(false);
            }
            PXGraph graph   = package.Graph;
            var     message = package.Message;

            if (!string.IsNullOrEmpty(message.Exception) || message.RefNoteID != null)
            {
                return(false);
            }

            List <String> addressesList = new List <String>( );

            addressesList.Add(package.Address);
            if (package.Message.IsIncome == false && package.Message.MailTo != null && package.Account.EmailAccountType == EmailAccountTypesAttribute.Exchange)
            {
                addressesList.InsertRange(0, EmailParser.ParseAddresses(message.MailTo).Select(m => m.Address));
            }

            foreach (String address in addressesList)
            {
                PXSelect <Contact,
                          Where <
                              Contact.eMail, Contains <Required <Contact.eMail> >,
                              And <Contact.contactType, Equal <ContactTypesAttribute.person> > > >
                .Clear(package.Graph);

                var contact = (Contact)PXSelect <Contact,
                                                 Where <
                                                     Contact.eMail, Contains <Required <Contact.eMail> >,
                                                     And <Contact.contactType, Equal <ContactTypesAttribute.person> > > >
                              .SelectWindowed(package.Graph, 0, 1, address);

                if (contact != null && contact.ContactID != null)
                {
                    graph.EnsureCachePersistence(typeof(Contact));
                    graph.EnsureCachePersistence(typeof(BAccount));

                    message.ContactID = contact.ContactID;

                    PXSelect <BAccount,
                              Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .
                    Clear(package.Graph);

                    BAccount baCcount = PXSelect <BAccount,
                                                  Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .
                                        Select(package.Graph, contact.BAccountID);

                    if (baCcount != null)
                    {
                        message.BAccountID = baCcount.BAccountID;
                    }

                    return(true);
                }
            }
            return(false);
        }
Exemple #9
0
            private IEnumerable DoCreateGramms(Contact contact)
            {
                string[] types = contact.ContactType == ContactTypesAttribute.BAccountProperty ? AccountTypes : ContactTypes;

                foreach (string validationType in types)
                {
                    PXCache cache  = graph.Caches[contact.GetType()];
                    PXCache lCache = graph.Caches[typeof(Location)];

                    Location defLocation = null;
                    if (contact.BAccountID != null)
                    {
                        BAccount bAccount = PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Required <Contact.bAccountID> > > > .Select(graph, contact.BAccountID);

                        if (bAccount != null && bAccount.DefLocationID != null)
                        {
                            defLocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <Location.bAccountID> >, And <Location.locationID, Equal <Required <BAccount.defLocationID> > > > > .Select(graph, bAccount.BAccountID, bAccount.DefLocationID);
                        }
                    }


                    string type = validationType;                     // TODO: remove duplicate?
                    if (!Definition.TypeRules.ContainsKey(validationType))
                    {
                        continue;
                    }

                    decimal total = 0, totalZero = 0;
                    foreach (var rule in Definition.TypeRules[type])
                    {
                        if (type == ValidationTypesAttribute.Account && defLocation != null)
                        {
                            if (lCache.GetValue(defLocation, rule.MatchingField) == null && cache.GetValue(contact, rule.MatchingField) == null)
                            {
                                totalZero += rule.ScoreWeight.GetValueOrDefault();
                            }
                            else
                            {
                                total += rule.ScoreWeight.GetValueOrDefault();
                            }
                        }
                        else
                        {
                            if (cache.GetValue(contact, rule.MatchingField) == null)
                            {
                                totalZero += rule.ScoreWeight.GetValueOrDefault();
                            }
                            else
                            {
                                total += rule.ScoreWeight.GetValueOrDefault();
                            }
                        }
                    }

                    if (total == 0)
                    {
                        continue;
                    }

                    foreach (CRValidationRules rule in Definition.TypeRules[type])
                    {
                        string  fieldName     = rule.MatchingField;
                        string  transformRule = rule.TransformationRule;
                        Decimal sw            = rule.ScoreWeight ?? 0;
                        if (sw == 0)
                        {
                            continue;
                        }

                        if (sw > 0 && totalZero > 0)
                        {
                            sw += totalZero * (sw / total);
                        }

                        var value = cache.GetValue(contact, fieldName);
                        if (type == ValidationTypesAttribute.Account && value == null)
                        {
                            value = lCache.GetValue(defLocation, fieldName);
                        }

                        if (value == null)
                        {
                            continue;
                        }
                        string stringValue = value.ToString().ToLower();

                        if (transformRule.Equals(TransformationRulesAttribute.SplitWords))
                        {
                            int?     id    = contact.ContactID;
                            string[] words = stringValue.Split();

                            foreach (string word in words)
                            {
                                Decimal score = Decimal.Round(sw / words.Length, 4);
                                if (score <= 0)
                                {
                                    continue;
                                }
                                CRGrams gram = new CRGrams();
                                gram.EntityID       = id;
                                gram.ValidationType = validationType;
                                gram.FieldName      = fieldName;
                                gram.FieldValue     = word;
                                gram.Score          = score;
                                yield return(gram);
                            }
                        }
                        else
                        {
                            if (transformRule.Equals(TransformationRulesAttribute.DomainName))
                            {
                                if (stringValue.Contains('@'))
                                {
                                    stringValue = stringValue.Segment('@', 1);
                                }
                                else
                                {
                                    try
                                    {
                                        stringValue = new UriBuilder(stringValue).Host;
                                        int    index        = stringValue.IndexOf('.');
                                        string firstSegment = index < 0 ? stringValue : stringValue.Substring(0, index);
                                        if (firstSegment.Equals("www"))
                                        {
                                            stringValue = stringValue.Substring(index + 1);
                                        }
                                    }
                                    catch (UriFormatException)
                                    {
                                        //Do nothing
                                    }
                                }
                            }

                            CRGrams gram = new CRGrams();
                            gram.FieldValue     = stringValue;
                            gram.EntityID       = contact.ContactID;
                            gram.ValidationType = validationType;
                            gram.FieldName      = fieldName;
                            gram.Score          = Decimal.Round(sw, 4);

                            yield return(gram);
                        }
                    }
                }
            }
Exemple #10
0
        protected static GetTaxRequest BuildGetTaxRequest(OpportunityMaint rg, CROpportunity order)
        {
            if (order == null)
            {
                throw new PXArgumentException(ErrorMessages.ArgumentNullException);
            }

            BAccount cust = (BAccount)PXSelect <BAccount,
                                                Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .
                            Select(rg, order.BAccountID);

            Location loc = (Location)PXSelect <Location,
                                               Where <Location.bAccountID, Equal <Required <Location.bAccountID> >, And <Location.locationID, Equal <Required <Location.locationID> > > > > .
                           Select(rg, order.BAccountID, order.LocationID);

            IAddressBase addressFrom = GetFromAddress(rg);
            IAddressBase addressTo   = GetToAddress(rg, order);

            if (addressFrom == null)
            {
                throw new PXException(Messages.FailedGetFromAddressSO);
            }

            if (addressTo == null)
            {
                throw new PXException(Messages.FailedGetToAddressSO);
            }

            var avalaraSetup = (TXAvalaraSetup)PXSetupOptional <TXAvalaraSetup> .Select(rg);

            GetTaxRequest request = new GetTaxRequest();

            request.CompanyCode        = AvalaraMaint.CompanyCodeFromBranch(rg, rg.Accessinfo.BranchID);
            request.CurrencyCode       = order.CuryID;
            request.CustomerCode       = cust.AcctCD;
            request.OriginAddress      = AvalaraMaint.FromAddress(addressFrom);
            request.DestinationAddress = AvalaraMaint.FromAddress(addressTo);
            request.DetailLevel        = DetailLevel.Summary;
            request.DocCode            = string.Format("CR.{0}", order.OpportunityID);
            request.DocDate            = order.CloseDate.GetValueOrDefault();

            int mult = 1;

            if (!string.IsNullOrEmpty(loc.CAvalaraCustomerUsageType))
            {
                request.CustomerUsageType = loc.CAvalaraCustomerUsageType;
            }
            if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber))
            {
                request.ExemptionNo = loc.CAvalaraExemptionNumber;
            }

            request.DocType = DocumentType.SalesOrder;

            PXSelectBase <CROpportunityProducts> select = new PXSelectJoin <CROpportunityProducts,
                                                                            LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <CROpportunityProducts.inventoryID> >,
                                                                                      LeftJoin <Account, On <Account.accountID, Equal <InventoryItem.salesAcctID> > > >,
                                                                            Where <CROpportunityProducts.cROpportunityID, Equal <Current <CROpportunity.opportunityID> > >,
                                                                            OrderBy <Asc <CROpportunityProducts.cROpportunityProductID> > >(rg);

            foreach (PXResult <CROpportunityProducts, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order }))
            {
                CROpportunityProducts tran = (CROpportunityProducts)res;
                InventoryItem         item = (InventoryItem)res;
                Account salesAccount       = (Account)res;

                Line line = new Line();
                line.No                 = Convert.ToString(tran.CROpportunityProductID);
                line.Amount             = mult * tran.CuryAmount.GetValueOrDefault();
                line.Description        = tran.TransactionDescription;
                line.DestinationAddress = request.DestinationAddress;
                line.OriginAddress      = request.OriginAddress;
                line.ItemCode           = item.InventoryCD;
                line.Qty                = Math.Abs(Convert.ToDouble(tran.Qty.GetValueOrDefault()));
                line.Discounted         = request.Discount > 0;
                line.TaxIncluded        = avalaraSetup.IsInclusiveTax == true;

                if (avalaraSetup != null && avalaraSetup.SendRevenueAccount == true)
                {
                    line.RevAcct = salesAccount.AccountCD;
                }

                line.TaxCode = tran.TaxCategoryID;

                request.Lines.Add(line);
            }

            return(request);
        }