示例#1
0
 ///<summary>Inserts one PayPlanCharge into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(PayPlanCharge payPlanCharge,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         payPlanCharge.PayPlanChargeNum=ReplicationServers.GetKey("payplancharge","PayPlanChargeNum");
     }
     string command="INSERT INTO payplancharge (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="PayPlanChargeNum,";
     }
     command+="PayPlanNum,Guarantor,PatNum,ChargeDate,Principal,Interest,Note,ProvNum,ClinicNum) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(payPlanCharge.PayPlanChargeNum)+",";
     }
     command+=
              POut.Long  (payPlanCharge.PayPlanNum)+","
         +    POut.Long  (payPlanCharge.Guarantor)+","
         +    POut.Long  (payPlanCharge.PatNum)+","
         +    POut.Date  (payPlanCharge.ChargeDate)+","
         +"'"+POut.Double(payPlanCharge.Principal)+"',"
         +"'"+POut.Double(payPlanCharge.Interest)+"',"
         +"'"+POut.String(payPlanCharge.Note)+"',"
         +    POut.Long  (payPlanCharge.ProvNum)+","
         +    POut.Long  (payPlanCharge.ClinicNum)+")";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         payPlanCharge.PayPlanChargeNum=Db.NonQ(command,true);
     }
     return payPlanCharge.PayPlanChargeNum;
 }
示例#2
0
 ///<summary>Inserts one PayPlanCharge into the database.  Returns the new priKey.</summary>
 internal static long Insert(PayPlanCharge payPlanCharge)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         payPlanCharge.PayPlanChargeNum=DbHelper.GetNextOracleKey("payplancharge","PayPlanChargeNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(payPlanCharge,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     payPlanCharge.PayPlanChargeNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(payPlanCharge,false);
     }
 }
示例#3
0
 ///<summary></summary>
 public static void InsertOrUpdate(PayPlanCharge charge, bool isNew)
 {
     //if(){
     //	throw new ApplicationException(Lan.g(this,""));
     //}
     if (isNew)
     {
         Insert(charge);
     }
     else
     {
         Update(charge);
     }
 }
示例#4
0
        public static GridRow CreateRowForPayPlanCharge(PayPlanCharge payPlanCharge, int payPlanChargeOrdinal, bool isDynamic = false)
        {
            string descript = "#" + payPlanChargeOrdinal;

            if (payPlanCharge.Note != "")
            {
                descript += " " + payPlanCharge.Note;
                //Don't add a # if it's a recalculated charge because they aren't "true" payplan charges.
                if (payPlanCharge.Note.Trim().ToLower().Contains("recalculated based on"))
                {
                    descript = payPlanCharge.Note;
                }
            }
            GridRow row = new GridRow();                                 //Charge row

            row.Cells.Add(payPlanCharge.ChargeDate.ToShortDateString()); //0 Date
            row.Cells.Add(Providers.GetAbbr(payPlanCharge.ProvNum));     //1 Prov Abbr
            if (payPlanCharge.Principal < 0)                             //adjustment
            {
                row.Cells.Add(descript);                                 //descript -- this has to show since we don't have a type of 'adjustment'. If not, the next debit charge is one off.
                row.Cells.Add("");                                       //principal
                row.Cells.Add("");                                       //interest
                row.Cells.Add("");                                       //due
                row.Cells.Add("");                                       //payment
                if (!isDynamic)
                {
                    row.ColorText = Defs.GetDefByExactName(DefCat.AccountColors, "Adjustment").ItemColor;
                    row.Cells.Add((payPlanCharge.Principal).ToString("n"));                     //adjustment
                }
            }
            else                                                                                 //regular charge
            {
                row.Cells.Add(descript);                                                         //2 Descript
                row.Cells.Add((payPlanCharge.Principal).ToString("n"));                          //3 Principal
                row.Cells.Add(payPlanCharge.Interest.ToString("n"));                             //4 Interest
                row.Cells.Add((payPlanCharge.Principal + payPlanCharge.Interest).ToString("n")); //5 Due
                row.Cells.Add("");                                                               //6 Payment
                if (!isDynamic)                                                                  //Dynamic payment plans do not have pay plan adjustments.
                {
                    row.Cells.Add("");                                                           //7 Adjustment
                }
            }
            row.Cells.Add("");            //8 Balance (filled later)
            if (isDynamic && payPlanCharge.PayPlanChargeNum == 0)
            {
                row.ColorText = System.Drawing.Color.Gray;              //it isn't an actual charge yet, it hasn't come due and been inserted into the database.
            }
            row.Tag = payPlanCharge;
            return(row);
        }
示例#5
0
        ///<summary>Inserts one PayPlanCharge into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(PayPlanCharge payPlanCharge, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                payPlanCharge.PayPlanChargeNum = ReplicationServers.GetKey("payplancharge", "PayPlanChargeNum");
            }
            string command = "INSERT INTO payplancharge (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "PayPlanChargeNum,";
            }
            command += "PayPlanNum,Guarantor,PatNum,ChargeDate,Principal,Interest,Note,ProvNum,ClinicNum,ChargeType,ProcNum,SecDateTEntry,StatementNum,FKey,LinkType) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(payPlanCharge.PayPlanChargeNum) + ",";
            }
            command +=
                POut.Long(payPlanCharge.PayPlanNum) + ","
                + POut.Long(payPlanCharge.Guarantor) + ","
                + POut.Long(payPlanCharge.PatNum) + ","
                + POut.Date(payPlanCharge.ChargeDate) + ","
                + "'" + POut.Double(payPlanCharge.Principal) + "',"
                + "'" + POut.Double(payPlanCharge.Interest) + "',"
                + DbHelper.ParamChar + "paramNote,"
                + POut.Long(payPlanCharge.ProvNum) + ","
                + POut.Long(payPlanCharge.ClinicNum) + ","
                + POut.Int((int)payPlanCharge.ChargeType) + ","
                + POut.Long(payPlanCharge.ProcNum) + ","
                + DbHelper.Now() + ","
                //SecDateTEdit can only be set by MySQL
                + POut.Long(payPlanCharge.StatementNum) + ","
                + POut.Long(payPlanCharge.FKey) + ","
                + POut.Int((int)payPlanCharge.LinkType) + ")";
            if (payPlanCharge.Note == null)
            {
                payPlanCharge.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(payPlanCharge.Note));

            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command, paramNote);
            }
            else
            {
                payPlanCharge.PayPlanChargeNum = Db.NonQ(command, true, "PayPlanChargeNum", "payPlanCharge", paramNote);
            }
            return(payPlanCharge.PayPlanChargeNum);
        }
示例#6
0
 ///<summary>Inserts one PayPlanCharge into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(PayPlanCharge payPlanCharge)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(payPlanCharge, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             payPlanCharge.PayPlanChargeNum = DbHelper.GetNextOracleKey("payplancharge", "PayPlanChargeNum");                  //Cacheless method
         }
         return(InsertNoCache(payPlanCharge, true));
     }
 }
示例#7
0
        ///<summary>Must pass in a list of charges for the guarantor.  The ones for this particular payplan will be returned.</summary>
        public static PayPlanCharge[] GetForPayPlan(int payPlanNum, PayPlanCharge[] ChargeList)
        {
            ArrayList AL = new ArrayList();

            for (int i = 0; i < ChargeList.Length; i++)
            {
                if (ChargeList[i].PayPlanNum == payPlanNum)
                {
                    AL.Add(ChargeList[i]);
                }
            }
            PayPlanCharge[] retVal = new PayPlanCharge[AL.Count];
            AL.CopyTo(retVal);
            return(retVal);
        }
示例#8
0
        ///<summary></summary>
        private static void Update(PayPlanCharge charge)
        {
            string command = "UPDATE payplancharge SET "
                             + "PayPlanChargeNum = '" + POut.PInt(charge.PayPlanChargeNum) + "'"
                             + ",PayPlanNum = '" + POut.PInt(charge.PayPlanNum) + "'"
                             + ",Guarantor = '" + POut.PInt(charge.Guarantor) + "'"
                             + ",PatNum = '" + POut.PInt(charge.PatNum) + "'"
                             + ",ChargeDate = " + POut.PDate(charge.ChargeDate)
                             + ",Principal = '" + POut.PDouble(charge.Principal) + "'"
                             + ",Interest = '" + POut.PDouble(charge.Interest) + "'"
                             + ",Note = '" + POut.PString(charge.Note) + "'"
                             + " WHERE PayPlanChargeNum = '" + POut.PInt(charge.PayPlanChargeNum) + "'";

            General.NonQ(command);
        }
示例#9
0
        public static PayPlanCharge CreateNegativeCreditForAdj(long patNum, long payPlanNum, double negAdjAmt)
        {
            PayPlanCharge txOffset = new PayPlanCharge()
            {
                ChargeDate = DateTime.Now.Date,
                ChargeType = PayPlanChargeType.Credit,              //needs to be saved as a credit to show in Tx Form
                Guarantor  = patNum,
                Note       = "Adjustment",
                PatNum     = patNum,
                PayPlanNum = payPlanNum,
                Principal  = negAdjAmt,
                ProcNum    = 0,
            };

            return(txOffset);
        }
示例#10
0
        ///<summary>Updates one PayPlanCharge in the database.</summary>
        internal static void Update(PayPlanCharge payPlanCharge)
        {
            string command = "UPDATE payplancharge SET "
                             + "PayPlanNum      =  " + POut.Long(payPlanCharge.PayPlanNum) + ", "
                             + "Guarantor       =  " + POut.Long(payPlanCharge.Guarantor) + ", "
                             + "PatNum          =  " + POut.Long(payPlanCharge.PatNum) + ", "
                             + "ChargeDate      =  " + POut.Date(payPlanCharge.ChargeDate) + ", "
                             + "Principal       = '" + POut.Double(payPlanCharge.Principal) + "', "
                             + "Interest        = '" + POut.Double(payPlanCharge.Interest) + "', "
                             + "Note            = '" + POut.String(payPlanCharge.Note) + "', "
                             + "ProvNum         =  " + POut.Long(payPlanCharge.ProvNum) + ", "
                             + "ClinicNum       =  " + POut.Long(payPlanCharge.ClinicNum) + " "
                             + "WHERE PayPlanChargeNum = " + POut.Long(payPlanCharge.PayPlanChargeNum);

            Db.NonQ(command);
        }
示例#11
0
        public static PayPlanCharge CreatePayPlanCharge(DateTime chargeDate, long patNum, long guarantor, long payplanNum, double prinicpal, long provNum
                                                        , long procNum, PayPlanChargeType chargeType)
        {
            PayPlanCharge ppc = new PayPlanCharge()
            {
                PayPlanNum = payplanNum,
                PatNum     = patNum,
                ChargeDate = chargeDate,
                Principal  = prinicpal,
                Guarantor  = guarantor,
                ProvNum    = provNum,
                ProcNum    = procNum,
                ChargeType = chargeType
            };

            PayPlanCharges.Insert(ppc);
            return(ppc);
        }
示例#12
0
        public static PayPlanCharge CreateOne(long payPlanNum, long guarantor, long patNum, DateTime chargeDate, double principal, double interest,
                                              string note = "", long provNum = 0, long clinicNum = 0, PayPlanChargeType chargeType = PayPlanChargeType.Debit, long procNum = 0)
        {
            PayPlanCharge charge = new PayPlanCharge();

            charge.PayPlanNum = payPlanNum;
            charge.Guarantor  = guarantor;
            charge.PatNum     = patNum;
            charge.ChargeDate = chargeDate;
            charge.Principal  = principal;
            charge.Interest   = interest;
            charge.Note       = note;
            charge.ProvNum    = provNum;
            charge.ClinicNum  = clinicNum;
            charge.ChargeType = chargeType;
            charge.ProcNum    = procNum;
            PayPlanCharges.Insert(charge);
            return(charge);
        }
示例#13
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<PayPlanCharge> TableToList(DataTable table){
			List<PayPlanCharge> retVal=new List<PayPlanCharge>();
			PayPlanCharge payPlanCharge;
			for(int i=0;i<table.Rows.Count;i++) {
				payPlanCharge=new PayPlanCharge();
				payPlanCharge.PayPlanChargeNum= PIn.Long  (table.Rows[i]["PayPlanChargeNum"].ToString());
				payPlanCharge.PayPlanNum      = PIn.Long  (table.Rows[i]["PayPlanNum"].ToString());
				payPlanCharge.Guarantor       = PIn.Long  (table.Rows[i]["Guarantor"].ToString());
				payPlanCharge.PatNum          = PIn.Long  (table.Rows[i]["PatNum"].ToString());
				payPlanCharge.ChargeDate      = PIn.Date  (table.Rows[i]["ChargeDate"].ToString());
				payPlanCharge.Principal       = PIn.Double(table.Rows[i]["Principal"].ToString());
				payPlanCharge.Interest        = PIn.Double(table.Rows[i]["Interest"].ToString());
				payPlanCharge.Note            = PIn.String(table.Rows[i]["Note"].ToString());
				payPlanCharge.ProvNum         = PIn.Long  (table.Rows[i]["ProvNum"].ToString());
				payPlanCharge.ClinicNum       = PIn.Long  (table.Rows[i]["ClinicNum"].ToString());
				retVal.Add(payPlanCharge);
			}
			return retVal;
		}
示例#14
0
        public void LedgersTests_ComputeAgingProcLifo_PayPlan3()
        {
            string        suffix              = MethodBase.GetCurrentMethod().Name;
            Patient       pat                 = PatientT.CreatePatient(fName: "Aging_PayPlan3", suffix: suffix);
            Procedure     proc95              = ProcedureT.CreateProcedure(pat, "D0270", ProcStat.C, "", 200, DateTime.Today.AddDays(-95));
            Procedure     proc35              = ProcedureT.CreateProcedure(pat, "D1110", ProcStat.C, "", 100, DateTime.Today.AddDays(-35));
            PayPlan       payPlan             = PayPlanT.CreatePayPlan(pat.PatNum, 100, 50, DateTime.Today.AddDays(-35), proc35.ProvNum);
            Adjustment    adj5                = AdjustmentT.MakeAdjustment(pat.PatNum, -5.50, DateTime.Today.AddDays(-5), proc35.ProcDate, proc35.ProcNum);
            PayPlanCharge ppc5                = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddDays(-5), 100, 0, chargeType: PayPlanChargeType.Credit, procNum: proc35.ProcNum);
            int           payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                CheckAgingProcLifo(pat.PatNum, 50, 44.50, 0, 200, 100, YN.Yes);
                CheckAgingProcLifo(pat.PatNum, 50, 150, 0, 94.50, 100, YN.No);
                CheckAgingProcLifo(pat.PatNum, 50, 150, 0, 94.50, 100, YN.Unknown);          //Unset will behave the same as Off for now, until we change default behavior in future.
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
            }
        }
示例#15
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <PayPlanCharge> TableToList(DataTable table)
        {
            List <PayPlanCharge> retVal = new List <PayPlanCharge>();
            PayPlanCharge        payPlanCharge;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                payPlanCharge = new PayPlanCharge();
                payPlanCharge.PayPlanChargeNum = PIn.Long(table.Rows[i]["PayPlanChargeNum"].ToString());
                payPlanCharge.PayPlanNum       = PIn.Long(table.Rows[i]["PayPlanNum"].ToString());
                payPlanCharge.Guarantor        = PIn.Long(table.Rows[i]["Guarantor"].ToString());
                payPlanCharge.PatNum           = PIn.Long(table.Rows[i]["PatNum"].ToString());
                payPlanCharge.ChargeDate       = PIn.Date(table.Rows[i]["ChargeDate"].ToString());
                payPlanCharge.Principal        = PIn.Double(table.Rows[i]["Principal"].ToString());
                payPlanCharge.Interest         = PIn.Double(table.Rows[i]["Interest"].ToString());
                payPlanCharge.Note             = PIn.String(table.Rows[i]["Note"].ToString());
                payPlanCharge.ProvNum          = PIn.Long(table.Rows[i]["ProvNum"].ToString());
                payPlanCharge.ClinicNum        = PIn.Long(table.Rows[i]["ClinicNum"].ToString());
                retVal.Add(payPlanCharge);
            }
            return(retVal);
        }
示例#16
0
        ///<summary>Inserts one PayPlanCharge into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(PayPlanCharge payPlanCharge, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                payPlanCharge.PayPlanChargeNum = ReplicationServers.GetKey("payplancharge", "PayPlanChargeNum");
            }
            string command = "INSERT INTO payplancharge (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "PayPlanChargeNum,";
            }
            command += "PayPlanNum,Guarantor,PatNum,ChargeDate,Principal,Interest,Note,ProvNum,ClinicNum) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(payPlanCharge.PayPlanChargeNum) + ",";
            }
            command +=
                POut.Long(payPlanCharge.PayPlanNum) + ","
                + POut.Long(payPlanCharge.Guarantor) + ","
                + POut.Long(payPlanCharge.PatNum) + ","
                + POut.Date(payPlanCharge.ChargeDate) + ","
                + "'" + POut.Double(payPlanCharge.Principal) + "',"
                + "'" + POut.Double(payPlanCharge.Interest) + "',"
                + "'" + POut.String(payPlanCharge.Note) + "',"
                + POut.Long(payPlanCharge.ProvNum) + ","
                + POut.Long(payPlanCharge.ClinicNum) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                payPlanCharge.PayPlanChargeNum = Db.NonQ(command, true);
            }
            return(payPlanCharge.PayPlanChargeNum);
        }
示例#17
0
        ///<summary>Gets all PayPlanCharges for a guarantor or patient, ordered by date.</summary>
        public static PayPlanCharge[] Refresh(int patNum)
        {
            string command =
                "SELECT * FROM payplancharge "
                + "WHERE Guarantor='" + POut.PInt(patNum) + "' "
                + "OR PatNum='" + POut.PInt(patNum) + "' "
                + "ORDER BY ChargeDate";
            DataTable table = General.GetTable(command);

            PayPlanCharge[] List = new PayPlanCharge[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                List[i] = new PayPlanCharge();
                List[i].PayPlanChargeNum = PIn.PInt(table.Rows[i][0].ToString());
                List[i].PayPlanNum       = PIn.PInt(table.Rows[i][1].ToString());
                List[i].Guarantor        = PIn.PInt(table.Rows[i][2].ToString());
                List[i].PatNum           = PIn.PInt(table.Rows[i][3].ToString());
                List[i].ChargeDate       = PIn.PDate(table.Rows[i][4].ToString());
                List[i].Principal        = PIn.PDouble(table.Rows[i][5].ToString());
                List[i].Interest         = PIn.PDouble(table.Rows[i][6].ToString());
                List[i].Note             = PIn.PString(table.Rows[i][7].ToString());
            }
            return(List);
        }
示例#18
0
        public static PayPlan CreatePayPlan(long patNum, double totalAmt, double payAmt, DateTime datePayStart, long provNum)
        {
            PayPlan payPlan = new PayPlan();

            payPlan.Guarantor   = patNum;
            payPlan.PatNum      = patNum;
            payPlan.PayAmt      = totalAmt;
            payPlan.PayPlanDate = datePayStart;
            payPlan.PayAmt      = totalAmt;
            PayPlans.Insert(payPlan);
            PayPlanCharge charge = new PayPlanCharge();

            charge.PayPlanNum = payPlan.PayPlanNum;
            charge.PatNum     = patNum;
            charge.ChargeDate = datePayStart;
            charge.Principal  = totalAmt;
            charge.ChargeType = PayPlanChargeType.Credit;
            double sumCharges    = 0;
            int    countPayments = 0;

            while (sumCharges < totalAmt)
            {
                charge            = new PayPlanCharge();
                charge.ChargeDate = datePayStart.AddMonths(countPayments);
                charge.PatNum     = patNum;
                charge.Guarantor  = patNum;
                charge.PayPlanNum = payPlan.PayPlanNum;
                charge.Principal  = Math.Min(payAmt, totalAmt - sumCharges);
                charge.ProvNum    = provNum;
                sumCharges       += charge.Principal;
                charge.ChargeType = PayPlanChargeType.Debit;
                PayPlanCharges.Insert(charge);
                countPayments++;
            }
            return(payPlan);
        }
示例#19
0
		///<summary>Updates one PayPlanCharge in the database.</summary>
		public static void Update(PayPlanCharge payPlanCharge){
			string command="UPDATE payplancharge SET "
				+"PayPlanNum      =  "+POut.Long  (payPlanCharge.PayPlanNum)+", "
				+"Guarantor       =  "+POut.Long  (payPlanCharge.Guarantor)+", "
				+"PatNum          =  "+POut.Long  (payPlanCharge.PatNum)+", "
				+"ChargeDate      =  "+POut.Date  (payPlanCharge.ChargeDate)+", "
				+"Principal       = '"+POut.Double(payPlanCharge.Principal)+"', "
				+"Interest        = '"+POut.Double(payPlanCharge.Interest)+"', "
				+"Note            = '"+POut.String(payPlanCharge.Note)+"', "
				+"ProvNum         =  "+POut.Long  (payPlanCharge.ProvNum)+", "
				+"ClinicNum       =  "+POut.Long  (payPlanCharge.ClinicNum)+" "
				+"WHERE PayPlanChargeNum = "+POut.Long(payPlanCharge.PayPlanChargeNum);
			Db.NonQ(command);
		}
示例#20
0
 ///<summary></summary>
 public FormPayPlanChargeEdit(PayPlanCharge payPlanCharge)
 {
     InitializeComponent();
     PayPlanChargeCur = payPlanCharge.Copy();
     Lan.F(this);
 }
示例#21
0
        public void LedgersTests_ComputeAgingProcLifo_LargeDb()
        {
            Def            defNeg   = DefT.CreateDefinition(DefCat.AdjTypes, "Ortho Revenue", "-");
            Def            defPos   = DefT.CreateDefinition(DefCat.AdjTypes, "Ortho Revenue", "+");
            Def            defPay   = DefT.CreateDefinition(DefCat.PaymentTypes, "Check");
            List <Patient> listPats = new List <Patient>();

            for (int i = 0; i < 1000; i++)
            {
                Patient       pat     = PatientT.CreatePatient(fName: "Schedule Based", lName: "UDP Ortho LargeDb");
                Procedure     proc    = ProcedureT.CreateProcedure(pat, "D8090", ProcStat.C, "", 4000, DateTime.Today.AddMonths(-6).AddDays(-1));
                PayPlan       payPlan = PayPlanT.CreatePayPlan(pat.PatNum, 4000, 166.67, DateTime.Today.AddMonths(-6).AddDays(-1), proc.ProvNum);
                Adjustment    adj6    = AdjustmentT.MakeAdjustment(pat.PatNum, -2800, DateTime.Today.AddMonths(-6).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defNeg.DefNum);
                Payment       pay6    = PaymentT.MakePayment(pat.PatNum, 166.67, DateTime.Today.AddMonths(-6).AddDays(-1), payPlanNum: payPlan.PayPlanNum, provNum: proc.ProvNum, procNum: proc.ProcNum, payType: defPay.DefNum);
                PayPlanCharge ppc6    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-6).AddDays(-1), 1200, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj5    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-5).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                Payment       pay5    = PaymentT.MakePayment(pat.PatNum, 166.67, DateTime.Today.AddMonths(-5).AddDays(-1), payPlanNum: payPlan.PayPlanNum, provNum: proc.ProvNum, procNum: proc.ProcNum, payType: defPay.DefNum);
                PayPlanCharge ppc5    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-5).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj4    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-4).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                PayPlanCharge ppc4    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-4).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj3    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-3).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                PayPlanCharge ppc3    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-3).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj2    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-2).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                PayPlanCharge ppc2    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-2).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj1    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-1).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                PayPlanCharge ppc1    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-1).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                listPats.Add(pat);
            }
            int       payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);
            int       agingProcLifoPrev   = PrefC.GetInt(PrefName.AgingProcLifo);
            Stopwatch swOn    = new Stopwatch();
            Stopwatch swOff   = new Stopwatch();
            Stopwatch swUnset = new Stopwatch();

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                swOn.Start();
                PrefT.UpdateInt(PrefName.AgingProcLifo, (int)YN.Yes);
                Ledgers.ComputeAging(0, DateTime.Today);               //Compute aging for all patients.
                foreach (Patient pat in listPats)
                {
                    PatAssertBalances(pat.PatNum, 166.67, 166.67, 166.67, 333.34, 833.35);
                }
                swOn.Stop();
                swOff.Start();
                PrefT.UpdateInt(PrefName.AgingProcLifo, (int)YN.No);
                Ledgers.ComputeAging(0, DateTime.Today);               //Compute aging for all patients.
                foreach (Patient pat in listPats)
                {
                    PatAssertBalances(pat.PatNum, 166.67, 288.41, 288.41, 89.86, 833.35);
                }
                swOff.Stop();
                swUnset.Start();
                PrefT.UpdateInt(PrefName.AgingProcLifo, (int)YN.Unknown);
                Ledgers.ComputeAging(0, DateTime.Today);               //Compute aging for all patients.
                foreach (Patient pat in listPats)
                {
                    PatAssertBalances(pat.PatNum, 166.67, 288.41, 288.41, 89.86, 833.35);
                }
                swUnset.Stop();
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
                PrefT.UpdateInt(PrefName.AgingProcLifo, agingProcLifoPrev);
            }
            //Fails if swOn run time is at least 10 times as large as the average of the runtimes for swUnset and swOff.
            Assert.IsTrue(swOn.Elapsed.TotalMilliseconds < (swUnset.Elapsed.TotalMilliseconds + swOff.Elapsed.TotalMilliseconds) * 5,
                          "Pref On: " + swOn.Elapsed + "\r\n"
                          + "Pref Off: " + swOff.Elapsed + "\r\n"
                          + "Pref Unset: " + swUnset.Elapsed);
        }
示例#22
0
        private void butAddOrUpdate_Click(object sender, EventArgs e)
        {
            List <PayPlanEntry> listSelectedEntries = new List <PayPlanEntry>();

            for (int i = 0; i < gridMain.SelectedIndices.Count(); i++)          //add all of the currently selected entries to this list.
            {
                listSelectedEntries.Add((PayPlanEntry)(gridMain.Rows[gridMain.SelectedIndices[i]].Tag));
            }
            if (listSelectedEntries.Count <= 1)            //validation (doesn't matter if multiple are selected)
            {
                if (String.IsNullOrEmpty(textAmt.Text) || textAmt.errorProvider1.GetError(textAmt) != "" || PIn.Double(textAmt.Text) == 0)
                {
                    MsgBox.Show(this, "Please enter a valid amount.");
                    return;
                }
                if (textDate.Text != "" && textDate.errorProvider1.GetError(textDate) != "")
                {
                    MsgBox.Show(this, "Please enter a valid date.");
                    return;
                }
            }
            if (textDate.Text == "")
            {
                textDate.Text = DateTime.Today.ToShortDateString();
            }
            if (Security.IsGlobalDateLock(Permissions.PayPlanEdit, PIn.Date(textDate.Text)))
            {
                return;
            }
            if (listSelectedEntries.Count == 0)            //if they have none selected
            //add an unattached charge.
            {
                PayPlanCharge addCharge = new PayPlanCharge()
                {
                    ChargeDate = PIn.Date(textDate.Text),
                    ChargeType = PayPlanChargeType.Credit,
                    Guarantor  = _patCur.PatNum,                 //credits should always appear on the patient of the payment plan.
                    Note       = PIn.String(textNote.Text),
                    PatNum     = _patCur.PatNum,
                    PayPlanNum = _payPlanCur.PayPlanNum,
                    Principal  = PIn.Double(textAmt.Text),
                    ProcNum    = 0,
                    //provider/clinic will be set when the amortization schedule is saved. FormPayPlan.SaveData()
                    //ClinicNum=0,
                    //ProvNum=0,
                };
                ListPayPlanCreditsCur.Add(addCharge);
            }
            else if (listSelectedEntries.Count == 1)            //if they have one selected
            {
                PayPlanEntry selectedEntry = listSelectedEntries[0];
                if (selectedEntry.IsChargeOrd)                  //if it's a charge
                //update the charge selected. get info from text boxes.
                //DO NOT use PayPlanChargeNum. They are not pre-inserted so they will all be 0 if new.
                {
                    PayPlanCharge selectedCharge = ((PayPlanEntry)(gridMain.Rows[gridMain.SelectedIndices[0]].Tag)).Charge;
                    selectedCharge.Principal = PIn.Double(textAmt.Text);
                    selectedCharge.Note      = PIn.String(textNote.Text);
                    if (selectedEntry.ProcStatOrd == ProcStat.TP && selectedEntry.ProcNumOrd != 0)                  //if it's treatment planned, save the date as maxvalue so it will not show up in the ledger.
                    //if it doesn't have a procnum, then we are editing an unattached row.
                    {
                        selectedCharge.ChargeDate = DateTime.MaxValue;
                    }
                    else
                    {
                        selectedCharge.ChargeDate = PIn.Date(textDate.Text);
                    }
                }
                else                   //if it's a procedure
                                       //add a charge for the selected procedure. get info from text boxes.
                {
                    PayPlanCharge addCharge = new PayPlanCharge();
                    if (selectedEntry.ProcStatOrd == ProcStat.TP && selectedEntry.ProcNumOrd != 0)                 //If tp, maxvalue.
                    //if procnum == 0, it's unattached.
                    {
                        addCharge.ChargeDate = DateTime.MaxValue;
                    }
                    else
                    {
                        addCharge.ChargeDate = PIn.Date(textDate.Text);
                    }
                    addCharge.ChargeType = PayPlanChargeType.Credit;
                    addCharge.Guarantor  = _patCur.PatNum;                 //credits should always appear on the patient of the payment plan.
                    addCharge.Note       = PIn.String(textNote.Text);
                    addCharge.PatNum     = _patCur.PatNum;
                    addCharge.PayPlanNum = _payPlanCur.PayPlanNum;
                    addCharge.Principal  = PIn.Double(textAmt.Text);
                    addCharge.ProcNum    = selectedEntry.ProcNumOrd;
                    //provider/clinic will be set when the amortization schedule is saved. FormPayPlan.SaveData()
                    //ClinicNum=0,
                    //ProvNum=0,
                    ListPayPlanCreditsCur.Add(addCharge);
                }
            }
            else if (listSelectedEntries.Count > 1)            //if they have more than one entry selected
            //remove everythig that doesn't have a procnum from the list
            {
                List <PayPlanEntry> listSelectedProcs = listSelectedEntries.Where(x => !x.IsChargeOrd).Where(x => x.Proc != null).ToList();
                if (listSelectedEntries.Count == 0)                //if the list is then empty, there's nothing to do.
                {
                    MsgBox.Show(this, "You must have at least one procedure selected.");
                    return;
                }
                if (!MsgBox.Show(this, MsgBoxButtons.OKCancel,
                                 "Add a payment plan credit for each of the selected procedure's remaining amount?  Selected credits will be ignored."))
                {
                    return;
                }
                //add a charge for every selected procedure for the amount remaining.
                //don't allow adding $0.00 credits.
                foreach (PayPlanEntry entryProcCur in listSelectedProcs)
                {
                    List <PayPlanEntry> listEntriesForProc = _listPayPlanEntries
                                                             .Where(x => x.ProcNumOrd == entryProcCur.ProcNumOrd)
                                                             .Where(x => x.IsChargeOrd == true).ToList();
                    PayPlanCharge addCharge = new PayPlanCharge();
                    if (entryProcCur.ProcStatOrd == ProcStat.TP)                   //If tp, maxvalue.
                    {
                        addCharge.ChargeDate = DateTime.MaxValue;
                    }
                    else
                    {
                        addCharge.ChargeDate = DateTimeOD.Today;
                    }
                    addCharge.ChargeType = PayPlanChargeType.Credit;
                    addCharge.Guarantor  = _patCur.PatNum;                 //credits should always appear on the patient of the payment plan.
                    addCharge.Note       = ProcedureCodes.GetStringProcCode(entryProcCur.Proc.CodeNum) + ": " + Procedures.GetDescription(entryProcCur.Proc);
                    addCharge.PatNum     = _patCur.PatNum;
                    addCharge.PayPlanNum = _payPlanCur.PayPlanNum;
                    addCharge.Principal  = PIn.Double(entryProcCur.RemBefStr);
                    if (listEntriesForProc.Count != 0)
                    {
                        addCharge.Principal = listEntriesForProc.Min(x => PIn.Double(x.RemAftStr));
                    }
                    addCharge.ProcNum = entryProcCur.ProcNumOrd;
                    //provider/clinic will be set when the amortization schedule is saved. FormPayPlan.SaveData()
                    //ClinicNum=0,
                    //ProvNum=0,
                    if (addCharge.Principal > 0)
                    {
                        ListPayPlanCreditsCur.Add(addCharge);
                    }
                }
            }
            textAmt.Text  = "";
            textDate.Text = "";
            textNote.Text = "";
            FillGrid();
            SetTextBoxes();
        }
示例#23
0
 ///<summary>Inserts many PayPlanCharges into the database.  Provides option to use the existing priKey.</summary>
 public static void InsertMany(List <PayPlanCharge> listPayPlanCharges, bool useExistingPK)
 {
     if (!useExistingPK && PrefC.RandomKeys)
     {
         foreach (PayPlanCharge payPlanCharge in listPayPlanCharges)
         {
             Insert(payPlanCharge);
         }
     }
     else
     {
         StringBuilder sbCommands = null;
         int           index      = 0;
         int           countRows  = 0;
         while (index < listPayPlanCharges.Count)
         {
             PayPlanCharge payPlanCharge = listPayPlanCharges[index];
             StringBuilder sbRow         = new StringBuilder("(");
             bool          hasComma      = false;
             if (sbCommands == null)
             {
                 sbCommands = new StringBuilder();
                 sbCommands.Append("INSERT INTO payplancharge (");
                 if (useExistingPK)
                 {
                     sbCommands.Append("PayPlanChargeNum,");
                 }
                 sbCommands.Append("PayPlanNum,Guarantor,PatNum,ChargeDate,Principal,Interest,Note,ProvNum,ClinicNum,ChargeType,ProcNum,SecDateTEntry,StatementNum,FKey,LinkType) VALUES ");
                 countRows = 0;
             }
             else
             {
                 hasComma = true;
             }
             if (useExistingPK)
             {
                 sbRow.Append(POut.Long(payPlanCharge.PayPlanChargeNum)); sbRow.Append(",");
             }
             sbRow.Append(POut.Long(payPlanCharge.PayPlanNum)); sbRow.Append(",");
             sbRow.Append(POut.Long(payPlanCharge.Guarantor)); sbRow.Append(",");
             sbRow.Append(POut.Long(payPlanCharge.PatNum)); sbRow.Append(",");
             sbRow.Append(POut.Date(payPlanCharge.ChargeDate)); sbRow.Append(",");
             sbRow.Append("'" + POut.Double(payPlanCharge.Principal) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.Double(payPlanCharge.Interest) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.String(payPlanCharge.Note) + "'"); sbRow.Append(",");
             sbRow.Append(POut.Long(payPlanCharge.ProvNum)); sbRow.Append(",");
             sbRow.Append(POut.Long(payPlanCharge.ClinicNum)); sbRow.Append(",");
             sbRow.Append(POut.Int((int)payPlanCharge.ChargeType)); sbRow.Append(",");
             sbRow.Append(POut.Long(payPlanCharge.ProcNum)); sbRow.Append(",");
             sbRow.Append(DbHelper.Now()); sbRow.Append(",");
             //SecDateTEdit can only be set by MySQL
             sbRow.Append(POut.Long(payPlanCharge.StatementNum)); sbRow.Append(",");
             sbRow.Append(POut.Long(payPlanCharge.FKey)); sbRow.Append(",");
             sbRow.Append(POut.Int((int)payPlanCharge.LinkType)); sbRow.Append(")");
             if (sbCommands.Length + sbRow.Length + 1 > TableBase.MaxAllowedPacketCount && countRows > 0)
             {
                 Db.NonQ(sbCommands.ToString());
                 sbCommands = null;
             }
             else
             {
                 if (hasComma)
                 {
                     sbCommands.Append(",");
                 }
                 sbCommands.Append(sbRow.ToString());
                 countRows++;
                 if (index == listPayPlanCharges.Count - 1)
                 {
                     Db.NonQ(sbCommands.ToString());
                 }
                 index++;
             }
         }
     }
 }
示例#24
0
 ///<summary>Inserts one PayPlanCharge into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(PayPlanCharge payPlanCharge)
 {
     return(InsertNoCache(payPlanCharge, false));
 }
示例#25
0
        /// <summary>Creates a payplan and payplan charges with credits. Credit amount generated based off the total amount of the procedures in the list.
        /// If credits are not attached,list of procedures must be null and a total amount must be specified.</summary>
        public static PayPlan CreatePayPlanWithCredits(long patNum, double payAmt, DateTime datePayStart, long provNum = 0, List <Procedure> listProcs = null
                                                       , double totalAmt = 0, long guarantorNum = 0, long clinicNum = 0)
        {
            double totalAmount;

            guarantorNum = guarantorNum == 0?patNum:guarantorNum;        //if it's 0, default to the patNum.
            if (listProcs != null)
            {
                totalAmount = listProcs.Sum(x => x.ProcFee);
            }
            else
            {
                totalAmount = totalAmt;
            }
            PayPlan payPlan = CreatePayPlanNoCharges(patNum, totalAmount, datePayStart, guarantorNum);       //create charges later depending on if attached to procs or not.

            if (listProcs != null)
            {
                foreach (Procedure proc in listProcs)
                {
                    PayPlanCharge credit = new PayPlanCharge();
                    credit.PayPlanNum = payPlan.PayPlanNum;
                    credit.PatNum     = patNum;
                    credit.ProcNum    = proc.ProcNum;
                    credit.ProvNum    = proc.ProvNum;
                    credit.Guarantor  = patNum;                 //credits should always appear on the patient of the payment plan.
                    credit.ChargeDate = datePayStart;
                    credit.ClinicNum  = clinicNum;
                    credit.Principal  = proc.ProcFee;
                    credit.ChargeType = PayPlanChargeType.Credit;
                    PayPlanCharges.Insert(credit);                    //attach the credit for the proc amount.
                }
            }
            else              //make one credit for the lump sum.
            {
                PayPlanCharge credit = new PayPlanCharge();
                credit.PayPlanNum = payPlan.PayPlanNum;
                credit.PatNum     = patNum;
                credit.ChargeDate = datePayStart;
                credit.ProvNum    = provNum;
                credit.ClinicNum  = clinicNum;
                credit.Guarantor  = patNum;             //credits should always appear on the patient of the payment plan.
                credit.Principal  = totalAmount;
                credit.ChargeType = PayPlanChargeType.Credit;
                PayPlanCharges.Insert(credit);                //attach the credit for the total amount.
            }
            //make debit charges for the payment plan
            double sumCharges    = 0;
            int    countPayments = 0;

            while (sumCharges < totalAmount)
            {
                PayPlanCharge charge = new PayPlanCharge();
                charge.ChargeDate = datePayStart.AddMonths(countPayments);
                charge.PatNum     = patNum;
                charge.Guarantor  = guarantorNum;
                charge.ClinicNum  = clinicNum;
                charge.PayPlanNum = payPlan.PayPlanNum;
                charge.Principal  = Math.Min(payAmt, totalAmount - sumCharges);
                charge.ProvNum    = provNum;
                sumCharges       += charge.Principal;
                charge.ChargeType = PayPlanChargeType.Debit;
                PayPlanCharges.Insert(charge);
                countPayments++;
            }
            return(payPlan);
        }
示例#26
0
 ///<summary>Returns true if Update(PayPlanCharge,PayPlanCharge) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(PayPlanCharge payPlanCharge, PayPlanCharge oldPayPlanCharge)
 {
     if (payPlanCharge.PayPlanNum != oldPayPlanCharge.PayPlanNum)
     {
         return(true);
     }
     if (payPlanCharge.Guarantor != oldPayPlanCharge.Guarantor)
     {
         return(true);
     }
     if (payPlanCharge.PatNum != oldPayPlanCharge.PatNum)
     {
         return(true);
     }
     if (payPlanCharge.ChargeDate.Date != oldPayPlanCharge.ChargeDate.Date)
     {
         return(true);
     }
     if (payPlanCharge.Principal != oldPayPlanCharge.Principal)
     {
         return(true);
     }
     if (payPlanCharge.Interest != oldPayPlanCharge.Interest)
     {
         return(true);
     }
     if (payPlanCharge.Note != oldPayPlanCharge.Note)
     {
         return(true);
     }
     if (payPlanCharge.ProvNum != oldPayPlanCharge.ProvNum)
     {
         return(true);
     }
     if (payPlanCharge.ClinicNum != oldPayPlanCharge.ClinicNum)
     {
         return(true);
     }
     if (payPlanCharge.ChargeType != oldPayPlanCharge.ChargeType)
     {
         return(true);
     }
     if (payPlanCharge.ProcNum != oldPayPlanCharge.ProcNum)
     {
         return(true);
     }
     //SecDateTEntry not allowed to change
     //SecDateTEdit can only be set by MySQL
     if (payPlanCharge.StatementNum != oldPayPlanCharge.StatementNum)
     {
         return(true);
     }
     if (payPlanCharge.FKey != oldPayPlanCharge.FKey)
     {
         return(true);
     }
     if (payPlanCharge.LinkType != oldPayPlanCharge.LinkType)
     {
         return(true);
     }
     return(false);
 }
示例#27
0
        ///<summary>Updates one PayPlanCharge in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(PayPlanCharge payPlanCharge, PayPlanCharge oldPayPlanCharge)
        {
            string command = "";

            if (payPlanCharge.PayPlanNum != oldPayPlanCharge.PayPlanNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PayPlanNum = " + POut.Long(payPlanCharge.PayPlanNum) + "";
            }
            if (payPlanCharge.Guarantor != oldPayPlanCharge.Guarantor)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Guarantor = " + POut.Long(payPlanCharge.Guarantor) + "";
            }
            if (payPlanCharge.PatNum != oldPayPlanCharge.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(payPlanCharge.PatNum) + "";
            }
            if (payPlanCharge.ChargeDate.Date != oldPayPlanCharge.ChargeDate.Date)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ChargeDate = " + POut.Date(payPlanCharge.ChargeDate) + "";
            }
            if (payPlanCharge.Principal != oldPayPlanCharge.Principal)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Principal = '" + POut.Double(payPlanCharge.Principal) + "'";
            }
            if (payPlanCharge.Interest != oldPayPlanCharge.Interest)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Interest = '" + POut.Double(payPlanCharge.Interest) + "'";
            }
            if (payPlanCharge.Note != oldPayPlanCharge.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = " + DbHelper.ParamChar + "paramNote";
            }
            if (payPlanCharge.ProvNum != oldPayPlanCharge.ProvNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ProvNum = " + POut.Long(payPlanCharge.ProvNum) + "";
            }
            if (payPlanCharge.ClinicNum != oldPayPlanCharge.ClinicNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ClinicNum = " + POut.Long(payPlanCharge.ClinicNum) + "";
            }
            if (payPlanCharge.ChargeType != oldPayPlanCharge.ChargeType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ChargeType = " + POut.Int((int)payPlanCharge.ChargeType) + "";
            }
            if (payPlanCharge.ProcNum != oldPayPlanCharge.ProcNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ProcNum = " + POut.Long(payPlanCharge.ProcNum) + "";
            }
            //SecDateTEntry not allowed to change
            //SecDateTEdit can only be set by MySQL
            if (payPlanCharge.StatementNum != oldPayPlanCharge.StatementNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "StatementNum = " + POut.Long(payPlanCharge.StatementNum) + "";
            }
            if (command == "")
            {
                return(false);
            }
            if (payPlanCharge.Note == null)
            {
                payPlanCharge.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(payPlanCharge.Note));

            command = "UPDATE payplancharge SET " + command
                      + " WHERE PayPlanChargeNum = " + POut.Long(payPlanCharge.PayPlanChargeNum);
            Db.NonQ(command, paramNote);
            return(true);
        }
示例#28
0
 ///<summary>Links charges to credits explicitly based on FKs first, then implicitly based on Date.</summary>
 private void LinkChargesToCredits()
 {
     #region Explicit
     for (int i = 0; i < _listAccountCharges.Count; i++)
     {
         AccountEntry charge = _listAccountCharges[i];
         for (int j = 0; j < _listPaySplits.Count; j++)
         {
             PaySplit paySplit    = _listPaySplits[j];
             decimal  paySplitAmt = (decimal)paySplit.SplitAmt;
             //Procedures that were being paid on through this payment plan should not get removed from this grid, even if they are fully paid off.
             if (charge.GetType() == typeof(Procedure) &&
                 paySplit.ProcNum == charge.PriKey &&
                 (paySplit.PayPlanNum == 0 || paySplit.PayPlanNum != _payPlanCur.PayPlanNum))
             {
                 charge.ListPaySplits.Add(paySplit);
                 charge.AmountEnd   -= paySplitAmt;
                 _accountCredits    -= paySplitAmt;
                 charge.AmountStart -= paySplitAmt;
             }
             else if (charge.GetType() == typeof(PayPlanCharge) && ((PayPlanCharge)charge.Tag).PayPlanNum == paySplit.PayPlanNum && charge.AmountEnd > 0 && paySplit.SplitAmt > 0)
             {
                 charge.AmountEnd -= paySplitAmt;
                 _accountCredits  -= paySplitAmt;
             }
         }
         for (int j = 0; j < _listAdjustments.Count; j++)
         {
             Adjustment adjustment    = _listAdjustments[j];
             decimal    adjustmentAmt = (decimal)adjustment.AdjAmt;
             if (charge.GetType() == typeof(Procedure) && adjustment.ProcNum == charge.PriKey)
             {
                 charge.AmountEnd += adjustmentAmt;
                 if (adjustment.AdjAmt < 0)
                 {
                     _accountCredits += adjustmentAmt;
                 }
                 charge.AmountStart += adjustmentAmt;
                 //If the adjustment is attached to a procedure decrease the procedure's amountoriginal so we know what it was just prior to autosplitting.
             }
         }
         for (int j = 0; j < _listPayPlanCharges.Count; j++)
         {
             PayPlanCharge payPlanCharge = _listPayPlanCharges[j];
             if (charge.GetType() == typeof(Procedure) && payPlanCharge.ProcNum == charge.PriKey)                  //payPlanCharge.ProcNum will only be set for credits.
             {
                 charge.AmountEnd   -= (decimal)payPlanCharge.Principal;
                 charge.AmountStart -= (decimal)payPlanCharge.Principal;
                 _accountCredits    -= (decimal)payPlanCharge.Principal;
             }
         }
         //Credits for the current payment plan don't get linked here, they get linked on the grid (Above)
         //for(int j = 0;j < ListPayPlanCreditsCur.Count;j++) {
         //	PayPlanCharge payPlanCharge=ListPayPlanCreditsCur[j];
         //	if(charge.GetType()==typeof(Procedure) && payPlanCharge.ProcNum == charge.PriKey) {
         //		charge.AmountEnd-=(decimal)payPlanCharge.Principal;
         //		charge.AmountStart-=(decimal)payPlanCharge.Principal;
         //		_accountCredits-=(decimal)payPlanCharge.Principal;
         //	}
         //}
         //
         //claimprocs explicitly linked to the procedures for this patient.
         for (int j = 0; j < _listClaimProcs.Count; j++)
         {
             ClaimProc claimProcCur = _listClaimProcs[j];
             if (charge.GetType() != typeof(Procedure) || claimProcCur.ProcNum != charge.PriKey)
             {
                 continue;
             }
             decimal amt = 0;
             if ((claimProcCur.Status == ClaimProcStatus.Estimate || claimProcCur.Status == ClaimProcStatus.NotReceived))
             {
                 //Estimated Payment
                 amt = (decimal)claimProcCur.InsEstTotal;
                 if (claimProcCur.InsEstTotalOverride != -1)
                 {
                     amt = (decimal)claimProcCur.InsEstTotalOverride;
                 }
                 charge.AmountEnd   -= amt;
                 charge.AmountStart -= amt;
                 //Estimated Writeoff
                 amt = 0;
                 if (claimProcCur.WriteOffEstOverride != -1)
                 {
                     amt = (decimal)claimProcCur.WriteOffEstOverride;
                 }
                 else if (claimProcCur.WriteOffEst != -1)
                 {
                     amt = (decimal)claimProcCur.WriteOffEst;
                 }
                 charge.AmountEnd   -= amt;
                 charge.AmountStart -= amt;
             }
             else if (claimProcCur.Status == ClaimProcStatus.Received || claimProcCur.Status == ClaimProcStatus.Supplemental ||
                      claimProcCur.Status == ClaimProcStatus.CapClaim || claimProcCur.Status == ClaimProcStatus.CapComplete)
             {
                 //actual payment and actual writeoff.
                 amt = (decimal)claimProcCur.InsPayAmt + (decimal)claimProcCur.WriteOff;
                 charge.AmountEnd   -= amt;
                 charge.AmountStart -= amt;
             }
         }
     }
     #endregion Explicit
     //Apply negative charges as if they're credits.
     for (int i = 0; i < _listAccountCharges.Count; i++)
     {
         AccountEntry entryCharge = _listAccountCharges[i];
         if (entryCharge.AmountEnd < 0)
         {
             _accountCredits      -= entryCharge.AmountEnd;
             entryCharge.AmountEnd = 0;
         }
     }
     #region Implicit
     //Now we have a date-sorted list of all the unpaid charges as well as all non-attributed credits.
     //We need to go through each and pay them off in order until all we have left is the most recent unpaid charges.
     for (int i = 0; i < _listAccountCharges.Count && _accountCredits > 0; i++)
     {
         AccountEntry charge = _listAccountCharges[i];
         decimal      amt    = Math.Min(charge.AmountEnd, _accountCredits);
         charge.AmountEnd   -= amt;
         _accountCredits    -= amt;
         charge.AmountStart -= amt;              //Decrease amount original for the charge so we know what it was just prior to when the autosplits were made.
     }
     #endregion Implicit
 }
示例#29
0
		///<summary>Updates one PayPlanCharge in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
		public static bool Update(PayPlanCharge payPlanCharge,PayPlanCharge oldPayPlanCharge){
			string command="";
			if(payPlanCharge.PayPlanNum != oldPayPlanCharge.PayPlanNum) {
				if(command!=""){ command+=",";}
				command+="PayPlanNum = "+POut.Long(payPlanCharge.PayPlanNum)+"";
			}
			if(payPlanCharge.Guarantor != oldPayPlanCharge.Guarantor) {
				if(command!=""){ command+=",";}
				command+="Guarantor = "+POut.Long(payPlanCharge.Guarantor)+"";
			}
			if(payPlanCharge.PatNum != oldPayPlanCharge.PatNum) {
				if(command!=""){ command+=",";}
				command+="PatNum = "+POut.Long(payPlanCharge.PatNum)+"";
			}
			if(payPlanCharge.ChargeDate != oldPayPlanCharge.ChargeDate) {
				if(command!=""){ command+=",";}
				command+="ChargeDate = "+POut.Date(payPlanCharge.ChargeDate)+"";
			}
			if(payPlanCharge.Principal != oldPayPlanCharge.Principal) {
				if(command!=""){ command+=",";}
				command+="Principal = '"+POut.Double(payPlanCharge.Principal)+"'";
			}
			if(payPlanCharge.Interest != oldPayPlanCharge.Interest) {
				if(command!=""){ command+=",";}
				command+="Interest = '"+POut.Double(payPlanCharge.Interest)+"'";
			}
			if(payPlanCharge.Note != oldPayPlanCharge.Note) {
				if(command!=""){ command+=",";}
				command+="Note = '"+POut.String(payPlanCharge.Note)+"'";
			}
			if(payPlanCharge.ProvNum != oldPayPlanCharge.ProvNum) {
				if(command!=""){ command+=",";}
				command+="ProvNum = "+POut.Long(payPlanCharge.ProvNum)+"";
			}
			if(payPlanCharge.ClinicNum != oldPayPlanCharge.ClinicNum) {
				if(command!=""){ command+=",";}
				command+="ClinicNum = "+POut.Long(payPlanCharge.ClinicNum)+"";
			}
			if(command==""){
				return false;
			}
			command="UPDATE payplancharge SET "+command
				+" WHERE PayPlanChargeNum = "+POut.Long(payPlanCharge.PayPlanChargeNum);
			Db.NonQ(command);
			return true;
		}
示例#30
0
        ///<summary>Updates one PayPlanCharge in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
        internal static void Update(PayPlanCharge payPlanCharge, PayPlanCharge oldPayPlanCharge)
        {
            string command = "";

            if (payPlanCharge.PayPlanNum != oldPayPlanCharge.PayPlanNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PayPlanNum = " + POut.Long(payPlanCharge.PayPlanNum) + "";
            }
            if (payPlanCharge.Guarantor != oldPayPlanCharge.Guarantor)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Guarantor = " + POut.Long(payPlanCharge.Guarantor) + "";
            }
            if (payPlanCharge.PatNum != oldPayPlanCharge.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(payPlanCharge.PatNum) + "";
            }
            if (payPlanCharge.ChargeDate != oldPayPlanCharge.ChargeDate)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ChargeDate = " + POut.Date(payPlanCharge.ChargeDate) + "";
            }
            if (payPlanCharge.Principal != oldPayPlanCharge.Principal)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Principal = '" + POut.Double(payPlanCharge.Principal) + "'";
            }
            if (payPlanCharge.Interest != oldPayPlanCharge.Interest)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Interest = '" + POut.Double(payPlanCharge.Interest) + "'";
            }
            if (payPlanCharge.Note != oldPayPlanCharge.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = '" + POut.String(payPlanCharge.Note) + "'";
            }
            if (payPlanCharge.ProvNum != oldPayPlanCharge.ProvNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ProvNum = " + POut.Long(payPlanCharge.ProvNum) + "";
            }
            if (payPlanCharge.ClinicNum != oldPayPlanCharge.ClinicNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ClinicNum = " + POut.Long(payPlanCharge.ClinicNum) + "";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE payplancharge SET " + command
                      + " WHERE PayPlanChargeNum = " + POut.Long(payPlanCharge.PayPlanChargeNum);
            Db.NonQ(command);
        }
示例#31
0
        private void butAddOrUpdate_Click(object sender, EventArgs e)
        {
            List <PayPlanEdit.PayPlanEntry> listSelectedEntries = new List <PayPlanEdit.PayPlanEntry>();

            for (int i = 0; i < gridMain.SelectedIndices.Count(); i++)          //add all of the currently selected entries to this list.
            {
                listSelectedEntries.Add((PayPlanEdit.PayPlanEntry)(gridMain.ListGridRows[gridMain.SelectedIndices[i]].Tag));
            }
            if (listSelectedEntries.Count <= 1)            //validation (doesn't matter if multiple are selected)
            {
                if (string.IsNullOrEmpty(textAmt.Text) || textAmt.errorProvider1.GetError(textAmt) != "" || PIn.Double(textAmt.Text) == 0)
                {
                    MsgBox.Show(this, "Please enter a valid amount.");
                    return;
                }
                if (textDate.Text != "" && textDate.errorProvider1.GetError(textDate) != "")
                {
                    MsgBox.Show(this, "Please enter a valid date.");
                    return;
                }
            }
            if (textDate.Text == "")
            {
                textDate.Text = DateTime.Today.ToShortDateString();
            }
            if (Security.IsGlobalDateLock(Permissions.PayPlanEdit, PIn.Date(textDate.Text)))
            {
                return;
            }
            if (listSelectedEntries.Count == 0)
            {
                if (PrefC.GetInt(PrefName.RigorousAccounting) == (int)RigorousAccounting.EnforceFully)                //if they have none selected
                {
                    MsgBox.Show(this, "All treatment credits (excluding adjustments) must have a procedure.");
                    return;
                }
                //add an unattached charge only if not on enforce fully
                PayPlanCharge addCharge = PayPlanEdit.CreateUnattachedCredit(textDate.Text, _patCur.PatNum, textNote.Text, _payPlanCur.PayPlanNum,
                                                                             PIn.Double(textAmt.Text));
                ListPayPlanCreditsCur.Add(addCharge);
            }
            else if (listSelectedEntries.Count == 1)            //if they have one selected
            {
                PayPlanEdit.PayPlanEntry selectedEntry = listSelectedEntries[0];
                if (selectedEntry.Proc != null && _listPayPlanLinksForProcs.Select(x => x.FKey).Contains(selectedEntry.Proc.ProcNum))
                {
                    MsgBox.Show(this, "This procedure is already linked to a dynamic payment plan.");
                    return;
                }
                if (PrefC.GetInt(PrefName.RigorousAccounting) == (int)RigorousAccounting.EnforceFully)
                {
                    if ((selectedEntry.Proc == null || selectedEntry.Proc.ProcNum == 0) &&
                        !(selectedEntry.Charge != null && selectedEntry.Charge.IsCreditAdjustment))
                    {
                        MsgBox.Show(this, "All treatment credits (excluding adjustments) must have a procedure.");
                        return;
                    }
                }
                PayPlanCharge selectedCharge = new PayPlanCharge();
                if (selectedEntry.IsChargeOrd)
                {
                    //get the charge from the grid.
                    //DO NOT use PayPlanChargeNum. They are not pre-inserted so they will all be 0 if new.
                    selectedCharge = ((PayPlanEdit.PayPlanEntry)(gridMain.ListGridRows[gridMain.SelectedIndices[0]].Tag)).Charge;
                }
                ListPayPlanCreditsCur = PayPlanEdit.CreateOrUpdateChargeForSelectedEntry(selectedEntry, ListPayPlanCreditsCur, PIn.Double(textAmt.Text), textNote.Text, textDate.Text
                                                                                         , _patCur.PatNum, _payPlanCur.PayPlanNum, selectedCharge);
            }
            else if (listSelectedEntries.Count > 1)            //if they have more than one entry selected
            //remove everythig that doesn't have a procnum from the list
            {
                List <PayPlanEdit.PayPlanEntry> listSelectedProcs = listSelectedEntries.Where(x => !x.IsChargeOrd).Where(x => x.Proc != null).ToList();
                if (listSelectedEntries.Count == 0)                //if the list is then empty, there's nothing to do.
                {
                    MsgBox.Show(this, "You must have at least one procedure selected.");
                    return;
                }
                if (!MsgBox.Show(this, MsgBoxButtons.OKCancel,
                                 "Add a payment plan credit for each of the selected procedure's remaining amount?  Selected credits will be ignored."))
                {
                    return;
                }
                List <PayPlanEdit.PayPlanEntry> listValidSelectedProcs =
                    listSelectedProcs.FindAll(x => !_listPayPlanLinksForProcs.Select(y => y.FKey).Contains(x.Proc.ProcNum));
                int countProcsSkipped = listSelectedProcs.Count - listValidSelectedProcs.Count;
                ListPayPlanCreditsCur = PayPlanEdit.CreateCreditsForAllSelectedEntries(listValidSelectedProcs, _listPayPlanEntries, DateTimeOD.Today
                                                                                       , _patCur.PatNum, _payPlanCur.PayPlanNum, ListPayPlanCreditsCur);
                if (countProcsSkipped > 0)
                {
                    MsgBox.Show(this, "Credits were not made for " + countProcsSkipped + " procedure(s) because they are linked to one or more dynamic payment plans.");
                }
            }
            textAmt.Text  = "";
            textDate.Text = "";
            textNote.Text = "";
            FillGrid();
            SetTextBoxes();
        }