/// <summary>Returns true if ClaimProcAllowCreditsGreaterThanProcFee preference allows the user to add credits greater than the proc fee. Otherwise returns false </summary>
        private bool isClaimProcGreaterThanProcFee()
        {
            ClaimProcCreditsGreaterThanProcFee creditsGreaterPref = (ClaimProcCreditsGreaterThanProcFee)PrefC.GetInt(PrefName.ClaimProcAllowCreditsGreaterThanProcFee);

            if (creditsGreaterPref == ClaimProcCreditsGreaterThanProcFee.Allow)
            {
                return(true);
            }
            List <Procedure>  listProcs                 = Procedures.GetManyProc(ClaimProcsToEdit.Select(x => x.ProcNum).ToList(), false);
            List <ClaimProc>  listClaimProcsForPat      = ClaimProcs.Refresh(PatCur.PatNum);
            List <PaySplit>   listPaySplitForSelectedCP = PaySplits.GetPaySplitsFromProcs(ClaimProcsToEdit.Select(x => x.ProcNum).ToList());
            List <Adjustment> listAdjForSelectedCP      = Adjustments.GetForProcs(ClaimProcsToEdit.Select(x => x.ProcNum).ToList());
            bool          isCreditGreater               = false;
            List <string> listProcDescripts             = new List <string>();

            for (int i = 0; i < ClaimProcsToEdit.Length; i++)
            {
                ClaimProc claimProcCur = ClaimProcsToEdit[i];
                int       insPayIdx    = gridMain.ListGridColumns.GetIndex(Lan.g("TableClaimProc", "Ins Pay"));
                int       writeoffIdx  = gridMain.ListGridColumns.GetIndex(Lan.g("TableClaimProc", "Writeoff"));
                int       feeAcctIdx   = gridMain.ListGridColumns.GetIndex(Lan.g("TableClaimProc", "Fee"));
                decimal   insPayAmt    = (decimal)ClaimProcs.ProcInsPay(listClaimProcsForPat.FindAll(x => x.ClaimProcNum != claimProcCur.ClaimProcNum), claimProcCur.ProcNum)
                                         + PIn.Decimal(gridMain.ListGridRows[i].Cells[insPayIdx].Text);
                decimal writeOff = (decimal)ClaimProcs.ProcWriteoff(listClaimProcsForPat.FindAll(x => x.ClaimProcNum != claimProcCur.ClaimProcNum), claimProcCur.ProcNum)
                                   + PIn.Decimal(gridMain.ListGridRows[i].Cells[writeoffIdx].Text);
                decimal feeAcct   = PIn.Decimal(gridMain.ListGridRows[i].Cells[feeAcctIdx].Text);
                decimal adj       = listAdjForSelectedCP.Where(x => x.ProcNum == claimProcCur.ProcNum).Select(x => (decimal)x.AdjAmt).Sum();
                decimal patPayAmt = listPaySplitForSelectedCP.Where(x => x.ProcNum == claimProcCur.ProcNum).Select(x => (decimal)x.SplitAmt).Sum();
                //Any changes to this calculation should also consider FormClaimProc.IsClaimProcGreaterThanProcFee().
                decimal creditRem = feeAcct - patPayAmt - insPayAmt - writeOff + adj;
                isCreditGreater |= (creditRem.IsLessThanZero());
                if (creditRem.IsLessThanZero())
                {
                    Procedure proc = listProcs.FirstOrDefault(x => x.ProcNum == claimProcCur.ProcNum);
                    listProcDescripts.Add((proc == null ? "" : ProcedureCodes.GetProcCode(proc.CodeNum).ProcCode)
                                          + "\t" + Lan.g(this, "Fee") + ": " + feeAcct.ToString("F")
                                          + "\t" + Lan.g(this, "Credits") + ": " + (Math.Abs(-patPayAmt - insPayAmt - writeOff + adj)).ToString("F")
                                          + "\t" + Lan.g(this, "Remaining") + ": (" + Math.Abs(creditRem).ToString("F") + ")");
                }
            }
            if (!isCreditGreater)
            {
                return(true);
            }
            if (creditsGreaterPref == ClaimProcCreditsGreaterThanProcFee.Block)
            {
                MsgBoxCopyPaste msgBox = new MsgBoxCopyPaste(Lan.g(this, "Remaining amount is negative for the following procedures") + ":\r\n"
                                                             + string.Join("\r\n", listProcDescripts) + "\r\n" + Lan.g(this, "Not allowed to continue."));
                msgBox.Text = Lan.g(this, "Overpaid Procedure Warning");
                msgBox.ShowDialog();
                return(false);
            }
            if (creditsGreaterPref == ClaimProcCreditsGreaterThanProcFee.Warn)
            {
                return(MessageBox.Show(Lan.g(this, "Remaining amount is negative for the following procedures") + ":\r\n"
                                       + string.Join("\r\n", listProcDescripts.Take(10)) + "\r\n" + (listProcDescripts.Count > 10?"...\r\n":"") + Lan.g(this, "Continue?")
                                       , Lan.g(this, "Overpaid Procedure Warning"), MessageBoxButtons.OKCancel) == DialogResult.OK);
            }
            return(true);           //should never get to this line, only possible if another enum value is added to allow, warn, and block
        }
        ///<summary>Returns true if InsPayNoWriteoffMoreThanProc preference is turned on and the sum of write off amount is greater than the proc fee.
        ///Otherwise returns false </summary>
        private bool IsWriteOffGreaterThanProcFee()
        {
            if (!PrefC.GetBool(PrefName.InsPayNoWriteoffMoreThanProc))
            {
                return(false);               //InsPayNoWriteoffMoreThanProc preference is off. No need to check.
            }
            List <ClaimProc>  listClaimProcsForPat  = ClaimProcs.Refresh(PatCur.PatNum);
            List <Adjustment> listAdjustmentsForPat = Adjustments.GetForProcs(ClaimProcsToEdit.Select(x => x.ProcNum).Where(x => x != 0).ToList());
            bool          isWriteoffGreater         = false;
            List <string> listProcDescripts         = new List <string>();

            for (int i = 0; i < ClaimProcsToEdit.Length; i++)
            {
                ClaimProc claimProcCur = ClaimProcsToEdit[i];
                //Fetch all adjustments for the given procedure.
                List <Adjustment> listClaimProcAdjustments = listAdjustmentsForPat.Where(x => x.ProcNum == claimProcCur.ProcNum).ToList();
                int     writeoffIdx = gridMain.ListGridColumns.GetIndex(Lan.g("TableClaimProc", "Writeoff"));
                int     feeAcctIdx  = gridMain.ListGridColumns.GetIndex(Lan.g("TableClaimProc", "Fee"));
                decimal writeOff    = (decimal)ClaimProcs.ProcWriteoff(listClaimProcsForPat.FindAll(x => x.ClaimProcNum != claimProcCur.ClaimProcNum), claimProcCur.ProcNum)
                                      + PIn.Decimal(gridMain.ListGridRows[i].Cells[writeoffIdx].Text);
                decimal feeAcct = PIn.Decimal(gridMain.ListGridRows[i].Cells[feeAcctIdx].Text);
                decimal adjAcct = listClaimProcAdjustments.Sum(x => (decimal)x.AdjAmt);
                //Any changes to this calculation should also consider FormClaimProc.IsWriteOffGreaterThanProc().
                decimal writeoffRem = feeAcct - writeOff + adjAcct;
                isWriteoffGreater |= (writeoffRem.IsLessThanZero() && writeOff.IsGreaterThanZero());
                if (writeoffRem.IsLessThanZero() && writeOff.IsGreaterThanZero())
                {
                    Procedure proc = Procedures.GetProcFromList(ProcList, claimProcCur.ProcNum);                 //will return a new procedure if none found.
                    listProcDescripts.Add((proc == null ? "" : ProcedureCodes.GetProcCode(proc.CodeNum).ProcCode)
                                          + "\t" + Lan.g(this, "Fee") + ": " + feeAcct.ToString("F")
                                          + "\t" + Lan.g(this, "Adjustments") + ": " + adjAcct.ToString("F")
                                          + "\t" + Lan.g(this, "Write-off") + ": " + (Math.Abs(-writeOff)).ToString("F")
                                          + "\t" + Lan.g(this, "Remaining") + ": (" + Math.Abs(writeoffRem).ToString("F") + ")");
                }
            }
            if (isWriteoffGreater)
            {
                MsgBoxCopyPaste msgBox = new MsgBoxCopyPaste(Lan.g(this, "Write-off amount is greater than the adjusted procedure fee for the following "
                                                                   + "procedure(s)") + ":\r\n" + string.Join("\r\n", listProcDescripts) + "\r\n" + Lan.g(this, "Not allowed to continue."));
                msgBox.Text = Lan.g(this, "Excessive Write-off");
                msgBox.ShowDialog();
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        private void FillProcedure()
        {
            if (_adjustmentCur.ProcNum == 0)
            {
                textProcDate2.Text       = "";
                textProcProv.Text        = "";
                textProcTooth.Text       = "";
                textProcDescription.Text = "";
                textProcFee.Text         = "";
                textProcWriteoff.Text    = "";
                textProcInsPaid.Text     = "";
                textProcInsEst.Text      = "";
                textProcAdj.Text         = "";
                textProcPatPaid.Text     = "";
                textProcAdjCur.Text      = "";
                labelProcRemain.Text     = "";
                _adjRemAmt = 0;
                return;
            }
            Procedure         procCur         = Procedures.GetOneProc(_adjustmentCur.ProcNum, false);
            List <ClaimProc>  listClaimProcs  = ClaimProcs.Refresh(procCur.PatNum);
            List <Adjustment> listAdjustments = Adjustments.Refresh(procCur.PatNum)
                                                .Where(x => x.ProcNum == procCur.ProcNum && x.AdjNum != _adjustmentCur.AdjNum).ToList();

            textProcDate.Text        = procCur.ProcDate.ToShortDateString();
            textProcDate2.Text       = procCur.ProcDate.ToShortDateString();
            textProcProv.Text        = Providers.GetAbbr(procCur.ProvNum);
            textProcTooth.Text       = Tooth.ToInternat(procCur.ToothNum);
            textProcDescription.Text = ProcedureCodes.GetProcCode(procCur.CodeNum).Descript;
            double procWO      = -ClaimProcs.ProcWriteoff(listClaimProcs, procCur.ProcNum);
            double procInsPaid = -ClaimProcs.ProcInsPay(listClaimProcs, procCur.ProcNum);
            double procInsEst  = -ClaimProcs.ProcEstNotReceived(listClaimProcs, procCur.ProcNum);
            double procAdj     = listAdjustments.Sum(x => x.AdjAmt);
            double procPatPaid = -PaySplits.GetTotForProc(procCur);

            textProcFee.Text      = procCur.ProcFeeTotal.ToString("F");
            textProcWriteoff.Text = procWO == 0?"":procWO.ToString("F");
            textProcInsPaid.Text  = procInsPaid == 0?"":procInsPaid.ToString("F");
            textProcInsEst.Text   = procInsEst == 0?"":procInsEst.ToString("F");
            textProcAdj.Text      = procAdj == 0?"":procAdj.ToString("F");
            textProcPatPaid.Text  = procPatPaid == 0?"":procPatPaid.ToString("F");
            //Intelligently sum the values above based on statuses instead of blindly adding all of the values together.
            //The remaining amount is typically called the "patient portion" so utilze the centralized method that gets the patient portion.
            decimal patPort    = ClaimProcs.GetPatPortion(procCur, listClaimProcs, listAdjustments);
            double  procAdjCur = 0;

            if (textAmount.errorProvider1.GetError(textAmount) == "")
            {
                if (listTypePos.SelectedIndex > -1)              //pos
                {
                    procAdjCur = PIn.Double(textAmount.Text);
                }
                else if (listTypeNeg.SelectedIndex > -1 || Defs.GetValue(DefCat.AdjTypes, _adjustmentCur.AdjType) == "dp")           //neg or discount plan
                {
                    procAdjCur = -PIn.Double(textAmount.Text);
                }
            }
            textProcAdjCur.Text = procAdjCur == 0?"":procAdjCur.ToString("F");
            //Add the current adjustment amount to the patient portion which will give the newly calculated remaining amount.
            _adjRemAmt           = (decimal)procAdjCur + (decimal)procPatPaid + patPort;
            labelProcRemain.Text = _adjRemAmt.ToString("c");
        }