Example #1
0
        ///<summary>Returns current clinic limit minus message usage for current calendar month.</summary>
        public static double GetClinicBalance(long clinicNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetDouble(MethodBase.GetCurrentMethod(), clinicNum));
            }
            double limit = 0;

            if (!PrefC.HasClinicsEnabled)
            {
                if (PrefC.GetDate(PrefName.SmsContractDate).Year > 1880)
                {
                    limit = PrefC.GetDouble(PrefName.SmsMonthlyLimit);
                }
            }
            else
            {
                if (clinicNum == 0 && Clinics.GetCount(true) > 0)               //Sending text for "Unassigned" patient.  Use the first non-hidden clinic. (for now)
                {
                    clinicNum = Clinics.GetFirst(true).ClinicNum;
                }
                Clinic clinicCur = Clinics.GetClinic(clinicNum);
                if (clinicCur != null && clinicCur.SmsContractDate.Year > 1880)
                {
                    limit = clinicCur.SmsMonthlyLimit;
                }
            }
            DateTime dtStart = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            DateTime dtEnd   = dtStart.AddMonths(1);
            string   command = "SELECT SUM(MsgChargeUSD) FROM smstomobile WHERE ClinicNum=" + POut.Long(clinicNum) + " "
                               + "AND DateTimeSent>=" + POut.Date(dtStart) + " AND DateTimeSent<" + POut.Date(dtEnd);

            limit -= PIn.Double(Db.GetScalar(command));
            return(limit);
        }
Example #2
0
        ///<Summary>asOfDate is typically 12/31/...  </Summary>
        public static double NetIncomeThisYear(DateTime asOfDate)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetDouble(MethodBase.GetCurrentMethod(), asOfDate));
            }
            DateTime firstOfYear = new DateTime(asOfDate.Year, 1, 1);
            string   command     = "SELECT SUM(ROUND(CreditAmt,3)), SUM(ROUND(DebitAmt,3)), AcctType "
                                   + "FROM journalentry,account "
                                   + "WHERE journalentry.AccountNum=account.AccountNum "
                                   + "AND DateDisplayed >= " + POut.Date(firstOfYear)
                                   + " AND DateDisplayed <= " + POut.Date(asOfDate)
                                   + " GROUP BY AcctType";
            DataTable table  = Db.GetTable(command);
            double    retVal = 0;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (table.Rows[i][2].ToString() == "3" ||          //income
                    table.Rows[i][2].ToString() == "4")                     //expense
                {
                    retVal += PIn.Double(table.Rows[i][0].ToString());      //add credit
                    retVal -= PIn.Double(table.Rows[i][1].ToString());      //subtract debit
                    //if it's an expense, we are subtracting (income-expense), but the signs cancel.
                }
            }
            return(retVal);
        }
Example #3
0
        ///<summary>Sums all adjustments for a proc then returns that sum.</summary>
        public static double GetTotForProc(long procNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetDouble(MethodBase.GetCurrentMethod(), procNum));
            }
            string command = "SELECT SUM(AdjAmt) FROM adjustment"
                             + " WHERE ProcNum=" + POut.Long(procNum);

            return(PIn.Double(Db.GetScalar(command)));
        }
Example #4
0
        /// <summary>Adds up the total fees for the procedures passed in that have been completed since the last billing day.</summary>
        public static double TotalRecurringCharges(long patNum, string procedures, int billingDay)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetDouble(MethodBase.GetCurrentMethod(), patNum, procedures, billingDay));
            }
            //Find the beginning of the current billing cycle, use that date to total charges between now and then for this cycle only.
            //Include that date only when we are not on the first day of the current billing cycle.
            DateTime startBillingCycle;

            if (DateTime.Today.Day > billingDay)           //if today is 7/13/2015 and billingDay is 26, startBillingCycle will be 6/26/2015
            {
                startBillingCycle = new DateTime(DateTime.Today.Year, DateTime.Today.Month, billingDay);
            }
            else
            {
                //DateTime.Today.AddMonths handles the number of days in the month and leap years
                //Examples: if today was 12/31/2015, AddMonths(-1) would yield 11/30/2015; if today was 3/31/2016, AddMonths(-1) would yield 2/29/2016
                startBillingCycle = DateTime.Today.AddMonths(-1);
                if (billingDay <= DateTime.DaysInMonth(startBillingCycle.Year, startBillingCycle.Month))
                {
                    //This corrects the issue of a billing cycle day after today but this month doesn't have enough days when last month does
                    //Example: if today was 11/30/2015 and the pat's billing cycle day was the 31st, startBillingCycle=Today.AddMonths(-1) would be 10/30/2015.
                    //But this pat's billing cycle day is the 31st and the December has 31 days.  This adjusts the start of the billing cycle to 10/31/2015.
                    //Example 2: if today was 2/29/2016 (leap year) and the pat's billing cycle day was the 30th, startBillingCycle should be 1/30/2016.
                    //Today.AddMonths(-1) would be 1/29/2016, so this adjusts startBillingCycle to 1/30/2016.
                    startBillingCycle = new DateTime(startBillingCycle.Year, startBillingCycle.Month, billingDay);
                }
            }
            string procStr = "'" + POut.String(procedures).Replace(",", "','") + "'";
            string command = "SELECT SUM(pl.ProcFee) "
                             + "FROM procedurelog pl "
                             + "INNER JOIN procedurecode pc ON pl.CodeNum=pc.CodeNum "
                             + "WHERE pl.ProcStatus=2 "
                             + "AND pc.ProcCode IN (" + procStr + ") "
                             + "AND pl.PatNum=" + POut.Long(patNum) + " "
                             + "AND pl.ProcDate<=" + DbHelper.Curdate() + " ";

            //If today is the billingDay or today is the last day of the current month and the billingDay is greater than today
            //i.e. billingDay=31 and today is the 30th which is the last day of the current month, only count procs with date after the 31st of last month
            if (billingDay == DateTime.Today.Day ||
                (billingDay > DateTime.Today.Day &&
                 DateTime.Today.Day == DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month)))
            {
                command += "AND pl.ProcDate>" + POut.Date(startBillingCycle);
            }
            else
            {
                command += "AND pl.ProcDate>=" + POut.Date(startBillingCycle);
            }
            return(PIn.Double(Db.GetScalar(command)));
        }
Example #5
0
        ///<summary>Sums all adjustments for a proc then returns that sum. Pass false to canIncludeTax in order to exclude sales tax from the end amount.
        ///</summary>
        public static double GetTotForProc(long procNum, bool canIncludeTax = true)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetDouble(MethodBase.GetCurrentMethod(), procNum, canIncludeTax));
            }
            string command = "SELECT SUM(AdjAmt) FROM adjustment"
                             + " WHERE ProcNum=" + POut.Long(procNum);

            if (AvaTax.IsEnabled() && !canIncludeTax)
            {
                command += " AND AdjType NOT IN (" + string.Join(",", POut.Long(AvaTax.SalesTaxAdjType), POut.Long(AvaTax.SalesTaxReturnAdjType)) + ")";
            }
            return(PIn.Double(Db.GetScalar(command)));
        }
Example #6
0
        ///<summary></summary>
        public static double GetTotTaxForProc(Procedure proc)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetDouble(MethodBase.GetCurrentMethod(), proc));
            }
            if (!AvaTax.DoSendProcToAvalara(proc))
            {
                return(0);
            }
            string command = "SELECT SUM(AdjAmt) FROM adjustment"
                             + " WHERE ProcNum=" + POut.Long(proc.ProcNum)
                             + " AND AdjType IN (" + string.Join(",", POut.Long(AvaTax.SalesTaxAdjType), POut.Long(AvaTax.SalesTaxReturnAdjType)) + ")";

            return(PIn.Double(Db.GetScalar(command)));
        }
Example #7
0
 ///<summary>Gets the amount used for the specified adjustment (Sums paysplits that have AdjNum passed in).  Pass in PayNum to exclude splits on that payment.</summary>
 public static double GetAmtAllocated(long adjNum, long excludedPayNum, List <PaySplit> listSplits = null)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         return(Meth.GetDouble(MethodBase.GetCurrentMethod(), adjNum, excludedPayNum, listSplits));
     }
     if (listSplits != null)
     {
         return(listSplits.FindAll(x => x.PayNum != excludedPayNum).Sum(x => x.SplitAmt));
     }
     else
     {
         string command = "SELECT SUM(SplitAmt) FROM paysplit WHERE AdjNum=" + POut.Long(adjNum);
         if (excludedPayNum != 0)
         {
             command += " AND PayNum!=" + POut.Long(excludedPayNum);
         }
         return(PIn.Double(Db.GetScalar(command)));
     }
 }