/// <summary>
        /// Calculate Commission
        /// </summary>
        public void CalculateCommission()
        {
            MCommissionDetail[] details      = GetDetails();
            Decimal             convertedAmt = Env.ZERO;
            Decimal             actualQty    = Env.ZERO;

            for (int i = 0; i < details.Length; i++)
            {
                MCommissionDetail detail = details[i];
                Decimal           amt1   = detail.GetConvertedAmt();
                //if (amt1 == null)
                //    amt1 = Env.ZERO;
                convertedAmt = Decimal.Add(convertedAmt, amt1);
                actualQty    = Decimal.Add(actualQty, detail.GetActualQty());
            }
            SetConvertedAmt(convertedAmt);
            SetActualQty(actualQty);
            //
            MCommissionLine cl = new MCommissionLine(GetCtx(), GetC_CommissionLine_ID(), Get_TrxName());
            //	Qty
            Decimal qty = Decimal.Subtract(GetActualQty(), cl.GetQtySubtract());

            if (cl.IsPositiveOnly() && Env.Signum(qty) < 0)
            {
                qty = Env.ZERO;
            }
            qty = Decimal.Multiply(qty, cl.GetQtyMultiplier());
            //	Amt
            Decimal amt = Decimal.Subtract(GetConvertedAmt(), cl.GetAmtSubtract());

            if (cl.IsPositiveOnly() && Env.Signum(amt) < 0)
            {
                amt = Env.ZERO;
            }
            amt = Decimal.Multiply(amt, cl.GetAmtMultiplier());
            //
            SetCommissionAmt(Decimal.Add(amt, qty));
        }
        public void CalculatecommissionwithNewLogic()
        {
            MCommissionDetail[] details = GetDetails();
            if (details.Length > 0)
            {
                Decimal convertedAmt       = Env.ZERO;
                Decimal actualQty          = Env.ZERO;
                Decimal commCalcAmt        = Env.ZERO;
                Decimal TotalCommissionAmt = Env.ZERO;
                for (int i = 0; i < details.Length; i++)
                {
                    MCommissionDetail detail = details[i];
                    convertedAmt = Decimal.Add(convertedAmt, detail.GetConvertedAmt());
                    actualQty    = Decimal.Add(actualQty, detail.GetActualQty());
                    MCommissionAmt  camt = new MCommissionAmt(GetCtx(), detail.GetC_CommissionAmt_ID(), Get_TrxName());
                    MCommissionLine line = new MCommissionLine(GetCtx(), camt.GetC_CommissionLine_ID(), Get_TrxName());

                    SetConvertedAmt(convertedAmt);
                    SetActualQty(actualQty);

                    if (line.GetC_CommissionType() == "A")
                    {
                        if (line.IsPositiveOnly() && Env.Signum(detail.GetConvertedAmt()) < 0)
                        {
                            commCalcAmt = Env.ZERO;
                        }

                        if (detail.GetConvertedAmt() >= line.GetC_TargetAmount())
                        {
                            commCalcAmt = CalculateCommisionAmt(detail.GetConvertedAmt(), line.GetC_TargetPercentage());
                        }
                        else if (detail.GetConvertedAmt() < line.GetC_TargetAmount() && detail.GetConvertedAmt() >= line.GetC_ThresholdAmount())
                        {
                            commCalcAmt = CalculateCommisionAmt(detail.GetConvertedAmt(), line.GetC_ThresholdPercentage());
                        }
                        else
                        {
                            commCalcAmt = 0;
                        }
                    }
                    else if (line.GetC_CommissionType() == "Q")
                    {
                        if (line.IsPositiveOnly() && Env.Signum(detail.GetActualQty()) < 0)
                        {
                            actualQty = Env.ZERO;
                        }

                        if (detail.GetActualQty() >= line.GetC_TargetQuantity())
                        {
                            commCalcAmt = CalculateCommisionAmt(detail.GetConvertedAmt(), line.GetC_TargetPercentage());
                        }
                        else if (detail.GetActualQty() < line.GetC_TargetQuantity() && detail.GetActualQty() >= line.GetC_ThresholdQuantity())
                        {
                            commCalcAmt = CalculateCommisionAmt(detail.GetConvertedAmt(), line.GetC_ThresholdPercentage());
                        }
                        else
                        {
                            commCalcAmt = 0;
                        }
                    }
                    TotalCommissionAmt = TotalCommissionAmt + commCalcAmt;
                }
                SetCommissionAmt(TotalCommissionAmt);
            }
        }