예제 #1
0
        public virtual FLXProject CreateProject(CROpportunityProducts opporProd)
        {
            CROpportunity current    = this.Base.Opportunity.Current;
            FLXProject    flxProject = new FLXProject();
            PXFieldState  valueExt1  = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeSALESREP") as PXFieldState;
            PXFieldState  valueExt2  = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeSALESPERSO") as PXFieldState;
            PXFieldState  valueExt3  = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeINDUSTRY") as PXFieldState;
            PXFieldState  valueExt4  = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeAPPLICATIO") as PXFieldState;
            PXFieldState  valueExt5  = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeDESIGNINPA") as PXFieldState;
            PXFieldState  valueExt6  = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeCM") as PXFieldState;
            PXFieldState  valueExt7  = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeDISTRY") as PXFieldState;
            PXFieldState  valueExt8  = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeENDCUSTOME") as PXFieldState;

            if (valueExt1.Value != null)
            {
                flxProject.SalesRepID = new int?((int)PXSelectorAttribute.GetField(this.Base.bAccountBasic.Cache, (object)this.Base.BAccounts, "acctCD", valueExt1.Value, "bAccountID"));
            }
            if (valueExt2.Value != null)
            {
                flxProject.SalespersonID = new int?((int)PXSelectorAttribute.GetField(this.SalesPersonView.Cache, (object)this.SalesPersonView, "salesPersonCD", valueExt2.Value, "SalesPersonID"));
            }
            if (valueExt6.Value != null)
            {
                flxProject.CM = new int?((int)PXSelectorAttribute.GetField(this.Base.bAccountBasic.Cache, (object)this.Base.BAccounts, "acctCD", valueExt6.Value, "bAccountID"));
            }
            if (valueExt7.Value != null)
            {
                flxProject.Distributor = new int?((int)PXSelectorAttribute.GetField(this.Base.bAccountBasic.Cache, (object)this.Base.BAccounts, "acctCD", valueExt7.Value, "bAccountID"));
            }
            flxProject.Industry      = valueExt3.Value == null ? (string)null : valueExt3.Value.ToString();
            flxProject.Application   = valueExt4.Value == null ? (string)null : valueExt4.Value.ToString();
            flxProject.CountryID     = valueExt5.Value == null ? (string)null : OpportunityMaint_Extension.GetAddressCountry((PXGraph)this.Base, (string)valueExt5.Value);
            flxProject.EndCustomerID = new int?((int)PXSelectorAttribute.GetField(this.Base.bAccountBasic.Cache, (object)this.Base.BAccounts, "acctCD", valueExt8.Value, "bAccountID"));
            flxProject.OpportunityID = current.OpportunityID;
            flxProject.CustomerID    = current.BAccountID;
            flxProject.OpporLineNbr  = opporProd.LineNbr;
            flxProject.EAU           = opporProd.Qty;
            flxProject.VendorID      = opporProd.VendorID;
            flxProject.Descr         = opporProd.Descr;
            switch (OpportunityMaint_Extension.GetItemType((PXGraph)this.Base, opporProd.InventoryID))
            {
            case "F":
            case "M":
            case "A":
                flxProject.StockItem = opporProd.InventoryID;
                break;

            default:
                flxProject.NonStockItem = opporProd.InventoryID;
                break;
            }
            return(flxProject);
        }
예제 #2
0
        public virtual FLXCommissionTable CreateComisionTable(
            CROpportunityProducts opporProd)
        {
            FLXCommissionTable flxCommissionTable = new FLXCommissionTable();
            CROpportunity      current            = this.Base.Opportunity.Current;
            PXFieldState       valueExt           = this.Base.Opportunity.Cache.GetValueExt((object)current, "AttributeENDCUSTOME") as PXFieldState;

            flxCommissionTable.EndCustomerID = new int?((int)PXSelectorAttribute.GetField(this.Base.bAccountBasic.Cache, (object)this.Base.BAccounts, "acctCD", valueExt.Value, "bAccountID"));
            flxCommissionTable.CustomerID    = current.BAccountID;
            flxCommissionTable.OpportunityID = current.OpportunityID;
            flxCommissionTable.OpporLineNbr  = opporProd.LineNbr;
            flxCommissionTable.NonStock      = opporProd.InventoryID;
            return(flxCommissionTable);
        }
        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);
        }
예제 #4
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);
        }