/**
  *  Constructor
  *	@param ctx context
  *  @param bp BP
  *	@param bpc BP Contact
  *  @param location Location
  */
 public MBPBankAccount(Ctx ctx, MBPartner bp, MUser bpc, MLocation location)
     : this(ctx, 0, bp.Get_TrxName())
 {
     SetIsACH(false);
     //
     SetC_BPartner_ID(bp.GetC_BPartner_ID());
     //
     SetA_Name(bpc.GetName());
     SetA_EMail(bpc.GetEMail());
     //
     SetA_Street(location.GetAddress1());
     SetA_City(location.GetCity());
     SetA_Zip(location.GetPostal());
     SetA_State(location.GetRegionName(true));
     SetA_Country(location.GetCountryName());
 }
Beispiel #2
0
        /**
         *  Make name Unique
         *  @param address address
         */
        private void MakeUnique(MLocation address)
        {
            //	_uniqueName = address.toString();
            //	return;

            if (_uniqueName.Length == 0)
            {
                _uniqueName.Clear();
            }
            _unique++;

            // 0 + Address1
            // to set address1
            if (_uniqueName.Length == 0)
            {
                String xx = address.GetAddress1();
                if (xx != null && xx.Length > 0)
                {
                    _uniqueName.Append(xx);
                }
                // Set address2, address3 and address4 in case of VA077
                if (VAdvantage.Utility.Env.IsModuleInstalled("VA077_"))
                {
                    xx = address.GetAddress2();
                    if (xx != null && xx.Length > 0)
                    {
                        if (_uniqueName.Length > 0)
                        {
                            _uniqueName.Append(" ");
                        }
                        _uniqueName.Append(xx);
                    }
                    xx = address.GetAddress3();
                    if (xx != null && xx.Length > 0)
                    {
                        if (_uniqueName.Length > 0)
                        {
                            _uniqueName.Append(" ");
                        }
                        _uniqueName.Append(xx);
                    }
                    xx = address.GetAddress4();
                    if (xx != null && xx.Length > 0)
                    {
                        if (_uniqueName.Length > 0)
                        {
                            _uniqueName.Append(" ");
                        }
                        _uniqueName.Append(xx);
                    }
                }
                _unique = 0;
            }

            //	0 - City
            // to set address1 and City as Name
            if (_unique == 0 && _uniqueName.Length >= 0)
            {
                String xx = address.GetCity();
                if (xx != null && xx.Length > 0)
                {
                    if (_uniqueName.Length > 0)
                    {
                        _uniqueName.Append(" ");
                    }
                    _uniqueName.Append(xx);
                }
                // Copy region, postal code country name in case of VA077
                if (VAdvantage.Utility.Env.IsModuleInstalled("VA077_"))
                {
                    xx = address.GetRegionName(true);
                    if (xx != null && xx.Length > 0)
                    {
                        if (_uniqueName.Length > 0)
                        {
                            _uniqueName.Append(" ");
                        }
                        _uniqueName.Append(xx);
                    }
                    xx = address.GetPostal();
                    if (xx != null && xx.Length > 0)
                    {
                        if (_uniqueName.Length > 0)
                        {
                            _uniqueName.Append(" ");
                        }
                        _uniqueName.Append(xx);
                    }
                    xx = address.GetCountryName();
                    if (xx != null && xx.Length > 0)
                    {
                        if (_uniqueName.Length > 0)
                        {
                            _uniqueName.Append(" ");
                        }
                        _uniqueName.Append(xx);
                    }
                }
                _unique = 0;
            }

            //	1 + Address1
            if (_unique == 1 || _uniqueName.Length == 0)
            {
                String xx = address.GetAddress1();
                if (xx != null && xx.Length > 0)
                {
                    if (_uniqueName.Length > 0)
                    {
                        _uniqueName.Append(" ");
                    }
                    _uniqueName.Append(xx);
                }
                _unique = 1;
            }
            //	2 + Address2
            if (_unique == 2 || _uniqueName.Length == 0)
            {
                String xx = address.GetAddress2();
                if (xx != null && xx.Length > 0)
                {
                    if (_uniqueName.Length > 0)
                    {
                        _uniqueName.Append(" ");
                    }
                    _uniqueName.Append(xx);
                }
                _unique = 2;
            }
            //	3 - Region
            if (_unique == 3 || _uniqueName.Length == 0)
            {
                String xx = address.GetRegionName(true);
                {
                    if (_uniqueName.Length > 0)
                    {
                        _uniqueName.Append(" ");
                    }
                    _uniqueName.Append(xx);
                }
                _unique = 3;
            }
            // 5 - Country
            if (_unique == 5 || _uniqueName.Length == 0)
            {
                String xx = address.GetCountryName();
                {
                    if (_uniqueName.Length > 0)
                    {
                        _uniqueName.Append(" ");
                    }
                    _uniqueName.Append(xx);
                }
                _unique = 5;
            }
            //	4 - ID
            if (_unique == 4 || _uniqueName.Length == 0)
            {
                int id = Get_ID();
                if (id == 0)
                {
                    id = address.Get_ID();
                }
                _uniqueName.Append("#" + id);
                _unique = 4;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Set Value and Description and Fully Qualified Flag for Combination
        /// </summary>
        public void SetValueDescription()
        {
            StringBuilder combi          = new StringBuilder();
            StringBuilder descr          = new StringBuilder();
            bool          fullyQualified = true;
            //
            MAcctSchema as1 = new MAcctSchema(GetCtx(), GetC_AcctSchema_ID(), Get_TrxName());   //	In Trx!

            MAcctSchemaElement[] elements = MAcctSchemaElement.GetAcctSchemaElements(as1);
            for (int i = 0; i < elements.Length; i++)
            {
                if (i > 0)
                {
                    combi.Append(as1.GetSeparator());
                    descr.Append(as1.GetSeparator());
                }
                MAcctSchemaElement element  = elements[i];
                String             combiStr = "_"; //	not defined
                String             descrStr = "_";

                if (MAcctSchemaElement.ELEMENTTYPE_Organization.Equals(element.GetElementType()))
                {
                    if (GetAD_Org_ID() != 0)
                    {
                        MOrg org = new MOrg(GetCtx(), GetAD_Org_ID(), Get_TrxName());   //	in Trx!
                        combiStr = org.GetValue();
                        descrStr = org.GetName();
                    }
                    else
                    {
                        combiStr       = "*";
                        descrStr       = "*";
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(element.GetElementType()))
                {
                    if (GetAccount_ID() != 0)
                    {
                        if (_accountEV == null)
                        {
                            _accountEV = new MElementValue(GetCtx(), GetAccount_ID(), Get_TrxName());
                        }
                        combiStr = _accountEV.GetValue();
                        descrStr = _accountEV.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Account");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_SubAccount.Equals(element.GetElementType()))
                {
                    if (GetC_SubAcct_ID() != 0)
                    {
                        X_C_SubAcct sa = new X_C_SubAcct(GetCtx(), GetC_SubAcct_ID(), Get_TrxName());
                        combiStr = sa.GetValue();
                        descrStr = sa.GetName();
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(element.GetElementType()))
                {
                    if (GetM_Product_ID() != 0)
                    {
                        X_M_Product product = new X_M_Product(GetCtx(), GetM_Product_ID(), Get_TrxName());
                        combiStr = product.GetValue();
                        descrStr = product.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Product");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_BPartner.Equals(element.GetElementType()))
                {
                    if (GetC_BPartner_ID() != 0)
                    {
                        X_C_BPartner partner = new X_C_BPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName());
                        combiStr = partner.GetValue();
                        descrStr = partner.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Business Partner");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_OrgTrx.Equals(element.GetElementType()))
                {
                    if (GetAD_OrgTrx_ID() != 0)
                    {
                        MOrg org = new MOrg(GetCtx(), GetAD_OrgTrx_ID(), Get_TrxName());        // in Trx!
                        combiStr = org.GetValue();
                        descrStr = org.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Trx Org");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_LocationFrom.Equals(element.GetElementType()))
                {
                    if (GetC_LocFrom_ID() != 0)
                    {
                        MLocation loc = new MLocation(GetCtx(), GetC_LocFrom_ID(), Get_TrxName());      //	in Trx!
                        combiStr = loc.GetPostal();
                        descrStr = loc.GetCity();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Location From");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_LocationTo.Equals(element.GetElementType()))
                {
                    if (GetC_LocTo_ID() != 0)
                    {
                        MLocation loc = new MLocation(GetCtx(), GetC_LocFrom_ID(), Get_TrxName());      //	in Trx!
                        combiStr = loc.GetPostal();
                        descrStr = loc.GetCity();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Location To");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_SalesRegion.Equals(element.GetElementType()))
                {
                    if (GetC_SalesRegion_ID() != 0)
                    {
                        MSalesRegion loc = new MSalesRegion(GetCtx(), GetC_SalesRegion_ID(), Get_TrxName());
                        combiStr = loc.GetValue();
                        descrStr = loc.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: SalesRegion");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(element.GetElementType()))
                {
                    if (GetC_Project_ID() != 0)
                    {
                        X_C_Project project = new X_C_Project(GetCtx(), GetC_Project_ID(), Get_TrxName());
                        combiStr = project.GetValue();
                        descrStr = project.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Project");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Campaign.Equals(element.GetElementType()))
                {
                    if (GetC_Campaign_ID() != 0)
                    {
                        X_C_Campaign campaign = new X_C_Campaign(GetCtx(), GetC_Campaign_ID(), Get_TrxName());
                        combiStr = campaign.GetValue();
                        descrStr = campaign.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Campaign");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Activity.Equals(element.GetElementType()))
                {
                    if (GetC_Activity_ID() != 0)
                    {
                        X_C_Activity act = new X_C_Activity(GetCtx(), GetC_Activity_ID(), Get_TrxName());
                        combiStr = act.GetValue();
                        descrStr = act.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Campaign");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_UserList1.Equals(element.GetElementType()))
                {
                    if (GetUser1_ID() != 0)
                    {
                        MElementValue ev = new MElementValue(GetCtx(), GetUser1_ID(), Get_TrxName());
                        combiStr = ev.GetValue();
                        descrStr = ev.GetName();
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_UserList2.Equals(element.GetElementType()))
                {
                    if (GetUser2_ID() != 0)
                    {
                        MElementValue ev = new MElementValue(GetCtx(), GetUser2_ID(), Get_TrxName());
                        combiStr = ev.GetValue();
                        descrStr = ev.GetName();
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_UserElement1.Equals(element.GetElementType()))
                {
                    if (GetUserElement1_ID() != 0)
                    {
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_UserElement2.Equals(element.GetElementType()))
                {
                    if (GetUserElement2_ID() != 0)
                    {
                    }
                }
                combi.Append(combiStr);
                descr.Append(descrStr);
            }
            //	Set Values
            base.SetCombination(combi.ToString());
            base.SetDescription(descr.ToString());
            if (fullyQualified != IsFullyQualified())
            {
                SetIsFullyQualified(fullyQualified);
                _log.Fine("Combination=" + GetCombination() + " - " + GetDescription() + " - FullyQualified=" + fullyQualified);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Get Tax ID (Detail).
        /// If error return 0 and set error log (TaxNotFound)
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="C_TaxCategory_ID">tax category</param>
        /// <param name="IsSOTrx">Sales Order Trx</param>
        /// <param name="shipDate">ship date (ignored)</param>
        /// <param name="shipFromC_Locction_ID">ship from (ignored)</param>
        /// <param name="shipToC_Location_ID">ship to (ignored)</param>
        /// <param name="billDate">invoice date</param>
        /// <param name="billFromC_Location_ID">invoice from</param>
        /// <param name="billToC_Location_ID">invoice to</param>
        /// <returns>C_Tax_ID</returns>
        protected static int Get(Ctx ctx, int C_TaxCategory_ID, bool IsSOTrx,
                                 DateTime?shipDate, int shipFromC_Locction_ID, int shipToC_Location_ID,
                                 DateTime?billDate, int billFromC_Location_ID, int billToC_Location_ID)
        {
            //	C_TaxCategory contains CommodityCode
            //	API to Tax Vendor comes here

            //if (CLogMgt.IsLevelFinest())
            {
                log.Info("(Detail) - Category=" + C_TaxCategory_ID
                         + ", SOTrx=" + IsSOTrx);
                log.Config("(Detail) - BillFrom=" + billFromC_Location_ID
                           + ", BillTo=" + billToC_Location_ID + ", BillDate=" + billDate);
            }

            MTax[]    taxes = MTax.GetAll(ctx);
            MLocation lFrom = new MLocation(ctx, billFromC_Location_ID, null);
            MLocation lTo   = new MLocation(ctx, billToC_Location_ID, null);

            log.Finer("From=" + lFrom);
            log.Finer("To=" + lTo);

            List <MTax> results = new List <MTax>();

            for (int i = 0; i < taxes.Length; i++)
            {
                MTax tax = taxes[i];
                if (tax.IsTaxExempt() ||
                    !tax.IsActive() ||
                    tax.GetC_TaxCategory_ID() != C_TaxCategory_ID ||
                    tax.GetParent_Tax_ID() != 0)        //	user parent tax
                {
                    continue;
                }
                if (IsSOTrx && MTax.SOPOTYPE_PurchaseTax.Equals(tax.GetSOPOType()))
                {
                    continue;
                }
                if (!IsSOTrx && MTax.SOPOTYPE_SalesTax.Equals(tax.GetSOPOType()))
                {
                    continue;
                }

                // if (CLogMgt.IsLevelFinest())
                {
                    log.Finest(tax.ToString());
                    log.Finest("From Country - " + (tax.GetC_Country_ID() == lFrom.GetC_Country_ID() ||
                                                    tax.GetC_Country_ID() == 0));
                    log.Finest("From Region - " + (tax.GetC_Region_ID() == lFrom.GetC_Region_ID() ||
                                                   tax.GetC_Region_ID() == 0));
                    log.Finest("To Country - " + (tax.GetTo_Country_ID() == lTo.GetC_Country_ID() ||
                                                  tax.GetTo_Country_ID() == 0));
                    log.Finest("To Region - " + (tax.GetTo_Region_ID() == lTo.GetC_Region_ID() ||
                                                 tax.GetTo_Region_ID() == 0));
                    //log.Finest("Date valid - " + (!tax.GetValidFrom().after(billDate)));
                    log.Finest("Date valid - " + (!(tax.GetValidFrom() > (billDate))));
                }

                //	From Country
                if ((tax.GetC_Country_ID() == lFrom.GetC_Country_ID() ||
                     tax.GetC_Country_ID() == 0)
                    //	From Region
                    && (tax.GetC_Region_ID() == lFrom.GetC_Region_ID() ||
                        tax.GetC_Region_ID() == 0)
                    //	To Country
                    && (tax.GetTo_Country_ID() == lTo.GetC_Country_ID() ||
                        tax.GetTo_Country_ID() == 0)
                    //	To Region
                    && (tax.GetTo_Region_ID() == lTo.GetC_Region_ID() ||
                        tax.GetTo_Region_ID() == 0)
                    //	Date
                    //&& !tax.GetValidFrom().after(billDate)
                    && tax.GetValidFrom() > (billDate)
                    )
                {
                    if (!tax.IsPostal())
                    {
                        results.Add(tax);
                        continue;
                    }
                    //
                    MTaxPostal[] postals = tax.GetPostals(false);
                    for (int j = 0; j < postals.Length; j++)
                    {
                        MTaxPostal postal = postals[j];
                        if (postal.IsActive()
                            //	Postal From is mandatory
                            && postal.GetPostal().StartsWith(lFrom.GetPostal())
                            //	Postal To is optional
                            && (postal.GetPostal_To() == null ||
                                postal.GetPostal_To().StartsWith(lTo.GetPostal()))
                            )
                        {
                            results.Add(tax);
                            continue;
                        }
                    } //	for all postals
                }
            }         //	for all taxes

            //	One Result
            if (results.Count == 1)
            {
                return(results[0].GetC_Tax_ID());
            }
            //	Multiple results - different valid from dates
            if (results.Count > 1)
            {
                MTax latest = null;
                for (int i = 0; i < results.Count; i++)
                {
                    MTax tax = results[i];
                    if (latest == null
                        //|| tax.GetValidFrom().after(latest.GetValidFrom()))
                        || tax.GetValidFrom() > (latest.GetValidFrom()))
                    {
                        latest = tax;
                    }
                }
                return(latest.GetC_Tax_ID());
            }

            //	Default Tax
            for (int i = 0; i < taxes.Length; i++)
            {
                MTax tax = taxes[i];
                if (!tax.IsDefault() || !tax.IsActive() ||
                    tax.GetParent_Tax_ID() != 0)        //	user parent tax
                {
                    continue;
                }
                if (IsSOTrx && MTax.SOPOTYPE_PurchaseTax.Equals(tax.GetSOPOType()))
                {
                    continue;
                }
                if (!IsSOTrx && MTax.SOPOTYPE_SalesTax.Equals(tax.GetSOPOType()))
                {
                    continue;
                }
                log.Fine("(default) - " + tax);
                return(tax.GetC_Tax_ID());
            }   //	for all taxes

            log.SaveError("TaxNotFound", "");
            return(0);
        }