예제 #1
0
        /// <summary>
        /// le taux de marque permet de calculer la marge directement depuis le prix de vente HT. Pvht * Tmq = la marge
        /// </summary>
        public static decimal GetSellingAmount(VATEnum iResultTypePrice, decimal iNetMarkRatePercentage, decimal iBuyingAmount, decimal iShippingAmountTTC, decimal iVariableFeePercentage, decimal iFixedFeeAmount, decimal iVATRate, ConditionEnum iCondition)
        {
            //TVA sur CA
            if (iCondition == ConditionEnum.UNUSED)
            {
                decimal sellingAmountHT = (iBuyingAmount + (iShippingAmountTTC * iVariableFeePercentage / 100) + iFixedFeeAmount) / (1 - iNetMarkRatePercentage / 100 - (1 + iVATRate / 100) * iVariableFeePercentage / 100);

                //retourne le TTC
                if (iResultTypePrice == VATEnum.TTC)
                {
                    return((sellingAmountHT * (1 + (iVATRate / 100))).Round2());
                }
                //Retourne le HT
                else if (iResultTypePrice == VATEnum.HT)
                {
                    return(sellingAmountHT.Round2());
                }
                else
                {
                    throw new NotSupportedException(iResultTypePrice.ToStringWithEnumName());
                }

                //Prht = Paht + Fv + Ff  avec Prht = pvht(1-tmq)
                //Pvht = (Paht + Lvttc*Tfv +FF)/(1 - tmq - (1+TVA)(Tfv))   avec Pvttc = pvht *(1+TVA)
            }

            //Tva sur marge
            else if (iCondition == ConditionEnum.USED)
            {
                decimal sellingPriceHT = (iBuyingAmount + (iShippingAmountTTC - iBuyingAmount * (iVATRate / 100)) * (iVariableFeePercentage / 100) + iFixedFeeAmount) / (1 - iNetMarkRatePercentage / 100 - (1 + iVATRate / 100) * iVariableFeePercentage / 100);

                //retourne le TTC
                if (iResultTypePrice == VATEnum.TTC)
                {
                    return((sellingPriceHT + (sellingPriceHT - iBuyingAmount) * (iVATRate / 100)).Round2());
                }
                //Retourne le HT
                else if (iResultTypePrice == VATEnum.HT)
                {
                    return((sellingPriceHT).Round2());
                }
                else
                {
                    throw new NotSupportedException(iResultTypePrice.ToStringWithEnumName());
                }

                //Prht = Paht + Fv + Ff   avec Pvttc = Pvht + (pvht - paht)*TVA  avec Prht = pvht(1-tmq)
                //pvht = Paht + (Lvttc - Paht*TVA)Tfv + Ff)/(1-Tmq - (1+tva)Tfv)
            }
            else
            {
                throw new NotSupportedException(iCondition.ToStringWithEnumName());
            }
        }
예제 #2
0
        /// <summary>
        /// Retourne une mise en forme du prix avec la devise et le taux de TVA;
        /// </summary>
        public static string ToString(this decimal iPrice, string iCurrency, VATEnum iVATEnum)
        {
            if (iCurrency == null)
            {
                throw new ArgumentNullException("Currency");
            }

            string taxValue = string.Empty;

            if (iVATEnum == VATEnum.TTC)
            {
                taxValue = "TTC";
            }
            else if (iVATEnum == VATEnum.HT)
            {
                taxValue = "HT";
            }
            else if (iVATEnum == VATEnum.EMPTY)
            {
                taxValue = "";
            }
            else
            {
                throw new NotSupportedException();
            }

            string amountString = "0";

            if (iPrice != 0)
            {
                var nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
                nfi.NumberGroupSeparator   = " ";
                nfi.NumberDecimalSeparator = ",";
                amountString = iPrice.ToString("#,#.00", nfi);

                //ajout le 0 avant la virgule si besoin
                if (amountString[0] == ',')
                {
                    amountString = "0" + amountString;
                }
            }

            return("{0} {1} {2}".FormatString(amountString, iCurrency, taxValue).Trim());
        }