Пример #1
0
        /// <summary>
        /// Get Lines
        /// </summary>
        /// <returns>array of lines</returns>
        public MCommissionLine[] GetLines()
        {
            String sql = "SELECT * FROM C_CommissionLine WHERE C_Commission_ID=@comid ORDER BY Line";
            List <MCommissionLine> list = new List <MCommissionLine>();

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@comid", GetC_Commission_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 MCommissionLine(GetCtx(), dr, Get_TrxName()));
                    }
                }
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, sql, e);
            }

            //	Convert
            MCommissionLine[] retValue = new MCommissionLine[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Пример #2
0
        /// <summary>
        /// Copy Lines From other Commission
        /// </summary>
        /// <param name="otherCom">commission</param>
        /// <returns>number of lines copied</returns>
        public int CopyLinesFrom(MCommission otherCom)
        {
            if (otherCom == null)
            {
                return(0);
            }
            MCommissionLine[] fromLines = otherCom.GetLines();
            int count = 0;

            for (int i = 0; i < fromLines.Length; i++)
            {
                MCommissionLine line = new MCommissionLine(GetCtx(), 0, Get_TrxName());
                PO.CopyValues(fromLines[i], line, GetAD_Client_ID(), GetAD_Org_ID());
                line.Set_ValueNoCheck("C_CommissionLine_ID", null);     //	new
                line.SetC_Commission_ID(GetC_Commission_ID());
                if (line.Save())
                {
                    count++;
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - From=" + fromLines.Length + " <> Saved=" + count);
            }
            return(count);
        }
        /// <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);
            }
        }