private bool IsVehicleIdVIP(CDatM1 m1, ref bool isVIP, long cpmArticleDef = GlobalDefs.DEF_UNDEFINED_VALUE)
        {
            trace.Write(TraceLevel.Info, ">>IsVehicleIdVIP");
            bool fnResult = true;

            try
            {
                isVIP = false;

                COPSPlate strPlate    = m1.GetInVehicleID();
                COPSDate  odDate      = m1.GetInDate().Copy();
                long      lGroup      = m1.GetInGroup();
                long      lArticleDef = GlobalDefs.DEF_UNDEFINED_VALUE;

                tariffCalculator.FillTree();
                bool isVehicleIdVIP = database.IsVehicleIdVIP(tariffCalculator.GetTree(), ref strPlate, odDate, lGroup, ref lArticleDef, ref isVIP);
                if (!isVehicleIdVIP)
                {
                    throw new InvalidOperationException("Error getting last operation group");
                }

                if (isVIP && lArticleDef != GlobalDefs.DEF_UNDEFINED_VALUE)
                {
                    m1.SetInArticleDef((int)lArticleDef);
                }
                else if (isVIP && lArticleDef == GlobalDefs.DEF_UNDEFINED_VALUE)
                {
                    isVIP = isVIP && lArticleDef == cpmArticleDef;
                }

                m1.SetOutIsVIP(isVIP);
            }
            catch (Exception error)
            {
                trace.Write(TraceLevel.Error, error.ToLogString());
                fnResult = false;
            }


            trace.Write(TraceLevel.Info, "<<IsVehicleIdVIP");
            return(fnResult);
        }
        private bool ComputeAmpliation(CDatM1 pM1, ref bool pExistCurrentOperationInOtherGroup)
        {
            trace.Write(TraceLevel.Debug, "ComputeAmpliation");
            bool fnResult = true;

            try
            {
                bool      bM1Plus      = false;
                int       nMaxQuantity = 0;
                COPSPlate strPlate;
                COPSDate  oDate;
                long      lCurrentArticleDef;
                long      lCurrentGroup;
                long      lAmpArticleDef = GlobalDefs.DEF_UNDEFINED_VALUE;
                long      lAmpGroup      = GlobalDefs.DEF_UNDEFINED_VALUE;
                bool      bIsVIP         = false;
                bool      bIsResident    = false;

                pExistCurrentOperationInOtherGroup = false;

                lCurrentArticleDef = pM1.GetInArticleDef();
                lCurrentGroup      = pM1.GetInGroup();
                strPlate           = pM1.GetInVehicleID();
                oDate = pM1.GetInDate().Copy();


                if (!database.GetVehicleLastOperationInfo(strPlate, oDate, ref lAmpArticleDef, ref lAmpGroup))
                {
                    throw new InvalidOperationException("Error getting last operation group");
                }

                if ((lAmpGroup != lCurrentGroup && lAmpGroup != GlobalDefs.DEF_UNDEFINED_VALUE) ||
                    (lAmpArticleDef != lCurrentArticleDef && lAmpArticleDef != GlobalDefs.DEF_UNDEFINED_VALUE)
                    )
                {
                    if (lAmpGroup != GlobalDefs.DEF_UNDEFINED_VALUE)
                    {
                        pM1.SetInGroup((int)lAmpGroup);
                    }

                    if (lAmpArticleDef != GlobalDefs.DEF_UNDEFINED_VALUE)
                    {
                        pM1.SetInArticleDef((int)lAmpArticleDef);
                    }

                    nMaxQuantity = (int)pM1.GetOutIntAcumul();

                    if (!tariffCalculator.GetM1(pM1, bM1Plus, nMaxQuantity))
                    {
                        throw new InvalidOperationException("Error computing Ampliation M1");
                    }

                    if (pM1.GetOutRealAccumulateMoney() > 0 && pM1.GetOutResult() > 0 && pM1.GetOutPostPay() == 0)
                    {
                        pExistCurrentOperationInOtherGroup = true;

                        if (!IsVehicleIdVIP(pM1, ref bIsVIP, pM1.GetInArticleDef()))
                        {
                            trace.Write(TraceLevel.Info, "ERROR : IsVehicleIdVIP");
                        }

                        if (!bIsVIP)
                        {
                            if (!IsVehicleIdResident(pM1, ref bIsResident, pM1.GetInArticleDef()))
                            {
                                trace.Write(TraceLevel.Info, "ERROR : IsVehicleIdResident");
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                trace.Write(TraceLevel.Error, error.ToLogString());
                fnResult = false;
            }

            return(fnResult);
        }