/// <summary>
        /// Get amounts
        /// </summary>
        /// <returns>array of amounts</returns>
        public MCommissionAmt[] GetAmts()
        {
            String sql = "SELECT * FROM C_CommissionAmt WHERE C_CommissionRun_ID=@crunid";
            List <MCommissionAmt> list = new List <MCommissionAmt>();

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@crunid", GetC_CommissionRun_ID());

                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, Get_TrxName());
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        list.Add(new MCommissionAmt(GetCtx(), dr, Get_TrxName()));
                    }
                }
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, sql, e);
            }

            //	Convert
            MCommissionAmt[] retValue = new MCommissionAmt[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Example #2
0
        /// <summary>
        /// Update Amt Header
        /// </summary>
        private void UpdateAmtHeader()
        {
            MCommissionAmt amt = new MCommissionAmt(GetCtx(), GetC_CommissionAmt_ID(), Get_TrxName());

            amt.CalculateCommission();
            amt.Save();
        }
Example #3
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="camt">commission amt</param>
 /// <param name="C_Currency_ID">currency</param>
 /// <param name="amt">amount</param>
 /// <param name="qty">quantity</param>
 public MCommissionDetail(MCommissionAmt camt, int C_Currency_ID, Decimal amt, Decimal qty)
     : this(camt.GetCtx(), 0, camt.Get_TrxName())
 {
     SetClientOrg(camt);
     SetC_CommissionAmt_ID(camt.GetC_CommissionAmt_ID());
     SetC_Currency_ID(C_Currency_ID);
     SetActualAmt(amt);
     SetActualQty(qty);
     SetConvertedAmt(Env.ZERO);
 }
        /// <summary>
        /// Update From Amt
        /// </summary>
        public void UpdateFromAmt()
        {
            MCommissionAmt[] amts       = GetAmts();
            Decimal          grandTotal = Env.ZERO;

            for (int i = 0; i < amts.Length; i++)
            {
                MCommissionAmt amt = amts[i];
                grandTotal = Decimal.Add(grandTotal, amt.GetCommissionAmt());
            }
            SetGrandTotal(grandTotal);
        }
        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);
            }
        }