/// <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 }
private void FillGrid() { RefreshReport(); gridMain.BeginUpdate(); ODGridColumn col = null; if (gridMain.Columns.Count == 0) { col = new ODGridColumn(Lan.g(this, "Patient Name"), _colWidthPatName); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Procedure Date"), _colWidthProcDate); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Procedure Descipion"), 0); //Dynaimc width gridMain.Columns.Add(col); if (PrefC.HasClinicsEnabled) { col = new ODGridColumn(Lan.g(this, "Clinic"), _colWidthClinic); gridMain.Columns.Add(col); } col = new ODGridColumn(Lan.g(this, "Amount"), _colWidthAmount, HorizontalAlignment.Right); gridMain.Columns.Add(col); } gridMain.Rows.Clear(); ODGridRow row; for (int i = 0; i < _myReport.ReportObjects.Count; i++) { if (_myReport.ReportObjects[i].ObjectType != ReportObjectType.QueryObject) { continue; } QueryObject queryObj = (QueryObject)_myReport.ReportObjects[i]; for (int j = 0; j < queryObj.ReportTable.Rows.Count; j++) { row = new ODGridRow(); row.Cells.Add(queryObj.ReportTable.Rows[j][0].ToString()); //Procedure Name row.Cells.Add(PIn.Date(queryObj.ReportTable.Rows[j][1].ToString()).ToShortDateString()); //Procedure Date row.Cells.Add(queryObj.ReportTable.Rows[j][2].ToString()); //Procedure Description if (PrefC.HasClinicsEnabled) { long clinicNum = PIn.Long(queryObj.ReportTable.Rows[j][5].ToString()); if (clinicNum == 0) { row.Cells.Add("Unassigned"); } else { row.Cells.Add(Clinics.GetAbbr(clinicNum)); } } row.Cells.Add(PIn.Double(queryObj.ReportTable.Rows[j][3].ToString()).ToString("c")); //Amount _procTotalAmt += PIn.Decimal(queryObj.ReportTable.Rows[j][3].ToString()); row.Tag = PIn.Long(queryObj.ReportTable.Rows[j][4].ToString()); //Tag set to ProcNum. Used in butNewClaims_Click(). gridMain.Rows.Add(row); } } gridMain.EndUpdate(); }
private void FillGrid() { DataTable table = RpServiceDateView.GetData(PatNum, IsFamily, checkDetailedView.Checked); gridMain.BeginUpdate(); //Columns gridMain.ListGridColumns.Clear(); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "Service Date"), 90)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "Trans Date"), 80)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "Patient"), 150)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "Reference"), 220)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "Charge"), 80, HorizontalAlignment.Right)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "Credit"), 80, HorizontalAlignment.Right)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "Prov"), 80)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "InsBal"), 80, HorizontalAlignment.Right)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "AcctBal"), 80, HorizontalAlignment.Right)); //Rows gridMain.ListGridRows.Clear(); DataRow lastRow = table.Select().LastOrDefault(); foreach (DataRow row in table.Rows) { GridRow newRow = new GridRow(); DateTime serviceDate = PIn.Date(row["Date"].ToString()); DateTime transDate = PIn.Date(row["Trans Date"].ToString()); newRow.Cells.Add((serviceDate.Year < 1880) ? "" : serviceDate.ToShortDateString()); newRow.Cells.Add((transDate.Year < 1880) ? "" : transDate.ToShortDateString()); newRow.Cells.Add(row["Patient"].ToString()); string strReference = row["Reference"].ToString(); newRow.Cells.Add(strReference); bool isUnallocated = strReference.ToLower().Contains("unallocated"); newRow.Cells.Add(isUnallocated ? "" : PIn.Decimal(row["Charge"].ToString()).ToString("f")); newRow.Cells.Add(isUnallocated ? "" : PIn.Decimal(row["Credit"].ToString()).ToString("f")); newRow.Cells.Add(row["Pvdr"].ToString()); decimal insBal = PIn.Decimal(row["InsBal"].ToString()); decimal acctBal = PIn.Decimal(row["AcctBal"].ToString()); bool isTotalsRow = row == lastRow || strReference.ToLower().Contains("Total for Date".ToLower()); bool isProc = row["Type"].ToString().ToLower() == "proc" && checkDetailedView.Checked; //Show insBal and acctBal when not on totals row and detailed is checked and either of the amounts are not zero. bool showDetailedRow = isTotalsRow || isProc || (checkDetailedView.Checked && (Math.Abs(insBal).IsGreaterThanZero() || Math.Abs(acctBal).IsGreaterThanZero())); newRow.Cells.Add(showDetailedRow ? insBal.ToString("f") : ""); newRow.Cells.Add(showDetailedRow ? acctBal.ToString("f") : ""); newRow.Tag = row; if (isTotalsRow) { newRow.Bold = true; } gridMain.ListGridRows.Add(newRow); } gridMain.EndUpdate(); }
private void processReturnToolStripMenuItem_Click(object sender, EventArgs e) { if (!Security.IsAuthorized(Permissions.PaymentCreate)) { return; } if (gridMain.SelectedIndices.Length < 1) { return; } if (IsXWebTransaction(gridMain.SelectedIndices[0])) { long patNum = PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["PatNum"].ToString()); string alias = _tableTrans.Rows[gridMain.SelectedIndices[0]]["Alias"].ToString(); List <CreditCard> listCards = CreditCards.GetCardsByToken(alias, new List <CreditCardSource> { CreditCardSource.XWeb, CreditCardSource.XWebPortalLogin }); if (listCards.Count == 0) { MsgBox.Show(this, "This credit card is no longer stored in the database. Return cannot be processed."); return; } if (listCards.Count > 1) { MsgBox.Show(this, "There is more than one card in the database with this token. Return cannot be processed due to the risk of charging the " + "incorrect card."); return; } FormXWeb FormXW = new FormXWeb(patNum, listCards.FirstOrDefault(), XWebTransactionType.CreditReturnTransaction, createPayment: true); FormXW.LockCardInfo = true; if (FormXW.ShowDialog() == DialogResult.OK) { FillGrid(); } } else { Payment payment = Payments.GetPayment(PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["PaymentNum"].ToString())); PayConnectResponseWeb pcResponseWeb = PayConnectResponseWebs.GetOne(PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["ResponseNum"].ToString())); decimal amt = PIn.Decimal(_tableTrans.Rows[gridMain.SelectedIndices[0]]["Amount"].ToString()); string refNum = _tableTrans.Rows[gridMain.SelectedIndices[0]]["TransactionID"].ToString(); //This is actually PayConnectResponseWeb.RefNumber, it's just stored in the TransactionID column if (!PayConnectL.VoidOrRefundPayConnectPortalTransaction(pcResponseWeb, payment, PayConnectService.transType.RETURN, refNum, amt)) { return; } MsgBox.Show("Return successful."); FillGrid(); } }
private void butOK_Click(object sender, EventArgs e) { if (listTransType.SelectedIndex == 2) //Debit Purchase { if (textCashBackAmt.errorProvider1.GetError(textCashBackAmt) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return; } CashBackAmount = PIn.Decimal(textCashBackAmt.Text); } TransactionType = listTransType.SelectedIndex; SaveToken = checkSaveToken.Checked; DialogResult = DialogResult.OK; }
private void voidPaymentToolStripMenuItem_Click(object sender, EventArgs e) { if (!Security.IsAuthorized(Permissions.PaymentCreate)) { return; } if (gridMain.SelectedIndices.Length < 1 || !MsgBox.Show(this, MsgBoxButtons.YesNo, "Void this payment?")) { return; } try { Cursor = Cursors.WaitCursor; if (IsXWebTransaction(gridMain.SelectedIndices[0])) { long patNum = PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["PatNum"].ToString()); long responseNum = PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["ResponseNum"].ToString()); string payNote = Lan.g(this, "Void XWeb payment made from within Open Dental") + "\r\n" + Lan.g(this, "Amount:") + " " + PIn.Double(_tableTrans.Rows[gridMain.SelectedIndices[0]]["Amount"].ToString()).ToString("f") + "\r\n" + Lan.g(this, "Transaction ID:") + " " + _tableTrans.Rows[gridMain.SelectedIndices[0]]["TransactionID"].ToString() + "\r\n" + Lan.g(this, "Card Number:") + " " + _tableTrans.Rows[gridMain.SelectedIndices[0]]["MaskedAcctNum"].ToString() + "\r\n" + Lan.g(this, "Processed:") + " " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); XWebs.VoidPayment(patNum, payNote, responseNum); } else { Payment payment = Payments.GetPayment(PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["PaymentNum"].ToString())); PayConnectResponseWeb pcResponseWeb = PayConnectResponseWebs.GetOne(PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["ResponseNum"].ToString())); decimal amt = PIn.Decimal(_tableTrans.Rows[gridMain.SelectedIndices[0]]["Amount"].ToString()); string refNum = _tableTrans.Rows[gridMain.SelectedIndices[0]]["TransactionID"].ToString(); //This is actually PayConnectResponseWeb.RefNumber, it's just stored in the TransactionID column if (!PayConnectL.VoidOrRefundPayConnectPortalTransaction(pcResponseWeb, payment, PayConnectService.transType.VOID, refNum, amt)) { Cursor = Cursors.Default; return; } } Cursor = Cursors.Default; MsgBox.Show(this, "Void successful"); FillGrid(); } catch (ODException ex) { Cursor = Cursors.Default; MessageBox.Show(ex.Message); } }
///<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); }
///<summary>When a charge is selected this method highlights all paysplits associated with it.</summary> private void gridCharges_CellClick(object sender, ODGridClickEventArgs e) { //Charge total text set here List <Tuple <long, long, long> > listAddedParents = new List <Tuple <long, long, long> >();//Prov/Clinic/Pat gridSplits.SetSelected(false); decimal chargeTotal = 0; foreach (GridRow row in gridCharges.SelectedGridRows) { AccountEntry accountEntry = (AccountEntry)row.Tag; if (accountEntry.Tag == null) //Parent row { chargeTotal += PIn.Decimal(row.Cells[row.Cells.Count - 1].Text); listAddedParents.Add(Tuple.Create(accountEntry.ProvNum, accountEntry.ClinicNum, accountEntry.PatNum)); continue; } else { for (int j = 0; j < gridSplits.ListGridRows.Count; j++) { PaySplit paySplit = (PaySplit)gridSplits.ListGridRows[j].Tag; if (accountEntry.SplitCollection.Contains(paySplit)) { gridSplits.SetSelected(j, true); } if (accountEntry.GetType() == typeof(PayPlanCharge) && paySplit.PayPlanNum == ((PayPlanCharge)accountEntry.Tag).PayPlanNum) { gridSplits.SetSelected(j, true); } } if (!listAddedParents.Exists(x => x.Item1 == accountEntry.ProvNum && x.Item2 == accountEntry.ClinicNum && x.Item3 == accountEntry.PatNum)) //In case a parent AND child are selected, don't add child amounts if parent was added already { chargeTotal += accountEntry.AmountEnd; } } } textChargeTotal.Text = chargeTotal.ToString("F"); }
///<summary>Processes a PaySimple payment via the PaySimple API.</summary> private PaySimple.ApiResponse ProcessPayment(int expYear, int expMonth) { PaySimple.ApiResponse retVal = null; string refNumber = ""; if (_trantype == PaySimple.TransType.VOID || _trantype == PaySimple.TransType.RETURN) { refNumber = textRefNumber.Text; } string magData = null; if (_parser != null) { magData = _parser.Track2; } string cardNumber = textCardNumber.Text; //if using a stored CC and there is an X-Charge token saved for the CC and the user enters the whole card number to get a PaySimple token //and the number entered doesn't have the same last 4 digits and exp date, then assume it's not the same card and clear out the X-Charge token. if (_creditCardCur != null && //using a saved CC !string.IsNullOrEmpty(_creditCardCur.XChargeToken) && //there is an X-Charge token saved (cardNumber.Right(4) != _creditCardCur.CCNumberMasked.Right(4) || //the card number entered doesn't have the same last 4 digits expYear != _creditCardCur.CCExpiration.Year || //the card exp date entered doesn't have the same year expMonth != _creditCardCur.CCExpiration.Month)) //the card exp date entered doesn't have the same month { if (MsgBox.Show(this, MsgBoxButtons.YesNo, "The card number or expiration date entered does not match the X-Charge card on file. Do you wish " + "to replace the X-Charge card with this one?")) { _creditCardCur.XChargeToken = ""; } else { Cursor = Cursors.Default; return(null); } } //if the user has chosen to store CC tokens and the stored CC has a token and the token is not expired, //then use it instead of the CC number and CC expiration. if (!checkOneTimePayment.Checked && _creditCardCur != null && //if the user selected a saved CC !string.IsNullOrWhiteSpace(_creditCardCur.PaySimpleToken)) //there is a stored token for this card { cardNumber = _creditCardCur.PaySimpleToken; expYear = _creditCardCur.CCExpiration.Year; expMonth = _creditCardCur.CCExpiration.Month; } else if (PIn.Bool(ProgramProperties.GetPropVal(_progCur.ProgramNum, PaySimple.PropertyDescs.PaySimplePreventSavingNewCC, _clinicNum))) { MsgBox.Show(this, "Cannot add a new credit card."); return(null); } try { switch (_trantype) { case PaySimple.TransType.SALE: //If _patCur is null or the PatNum is 0, we will make a one time payment for an UNKNOWN patient. //This is currently only intended for prepaid insurance cards. retVal = PaySimple.MakePayment((_patCur == null ? 0 : _patCur.PatNum), _creditCardCur, PIn.Decimal(textAmount.Text), textCardNumber.Text , new DateTime(expYear, expMonth, 1), checkOneTimePayment.Checked, textZipCode.Text, textSecurityCode.Text, _clinicNum, _carrierName); break; case PaySimple.TransType.AUTH: //Will retreive a new customer id from PaySimple if the patient doesn't exist already. long paySimpleCustomerId = PaySimple.GetCustomerIdForPat(_patCur.PatNum, _patCur.FName, _patCur.LName, _clinicNum); //I have no idea if an insurance can make an auth payment but incase they can I check for it. if (paySimpleCustomerId == 0) //Insurance payment, make a new customer id every time per Nathan on 04/26/2018 { if ((_patCur == null || _patCur.PatNum == 0)) { paySimpleCustomerId = PaySimple.AddCustomer("UNKNOWN", "UNKNOWN", "", _clinicNum); } else { throw new ODException(Lan.g(this, "Invalid PaySimple Customer Id found.")); } } try { retVal = PaySimple.AddCreditCard(paySimpleCustomerId, textCardNumber.Text, new DateTime(expYear, expMonth, 1), textZipCode.Text, _clinicNum); } catch (PaySimpleException ex) { PaySimple.HandlePaySimpleException(ex, paySimpleCustomerId); } break; case PaySimple.TransType.RETURN: if (string.IsNullOrWhiteSpace(textRefNumber.Text)) { throw new ODException(Lan.g(this, "Invalid PaySimple Payment ID.")); } if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "You are about to return a payment. This action is irreversible. Continue?")) { throw new ODException(Lan.g(this, "Payment return was cancelled by user.")); } retVal = PaySimple.ReversePayment(textRefNumber.Text, _clinicNum); break; case PaySimple.TransType.VOID: if (string.IsNullOrWhiteSpace(textRefNumber.Text)) { throw new ODException(Lan.g(this, "Invalid PaySimple Payment ID.")); } if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "You are about to void a payment. This action is irreversible. Continue?")) { throw new ODException(Lan.g(this, "Payment void was cancelled by user.")); } retVal = PaySimple.VoidPayment(textRefNumber.Text, _clinicNum); break; default: throw new Exception("Invalid transmission type: " + _trantype.ToString()); } } catch (PaySimpleException ex) { MessageBox.Show(ex.Message); if (ex.ErrorType == PaySimpleError.CustomerDoesNotExist && MsgBox.Show(this, MsgBoxButtons.OKCancel, "Delete the link to the customer id for this patient?")) { PatientLinks.DeletePatNumTos(ex.CustomerId, PatientLinkType.PaySimple); } return(null); } catch (ODException wex) { MessageBox.Show(wex.Message); //This should have already been Lans.g if applicable. return(null); } catch (Exception ex) { MessageBox.Show(Lan.g(this, "Error:") + " " + ex.Message); return(null); } if (_trantype.In(PaySimple.TransType.SALE, PaySimple.TransType.RETURN, PaySimple.TransType.VOID)) //Only print a receipt if transaction is an approved SALE, RETURN, or VOID //The isSwiped boolean could be incorrectly set if the user swipes a card and then changes the data that was entered to a different card. { retVal.BuildReceiptString(cardNumber, expMonth, expYear, textNameOnCard.Text, _clinicNum, _parser != null); PrintReceipt(retVal.TransactionReceipt); } if (checkOneTimePayment.Checked) //not storing the card token { return(retVal); } UpsertCreditCard(retVal, textCardNumber.Text.Right(4).PadLeft(textCardNumber.Text.Length, 'X'), CreditCardSource.PaySimple, new DateTime(expYear, expMonth, DateTime.DaysInMonth(expYear, expMonth))); return(retVal); }
///<summary>Fills grid based on values in _listEtrans. ///Set isRefreshNeeded to true when we need to reinitialize local dictionarys after in memory list is also updated. Required true for first time running. ///Also allows you to passed in predetermined filter options.</summary> private void FillGrid(bool isRefreshNeeded, List <string> listSelectedStatuses, List <long> listSelectedClinicNums, string carrierName, string checkTraceNum, string amountMin, string amountMax, string controlId) { Cursor = Cursors.WaitCursor; labelControlId.Visible = PrefC.GetBool(PrefName.EraShowControlIdFilter); textControlId.Visible = PrefC.GetBool(PrefName.EraShowControlIdFilter); Action actionCloseProgress = null; if (isRefreshNeeded) { actionCloseProgress = ODProgress.Show(ODEventType.Etrans, typeof(EtransEvent), Lan.g(this, "Gathering data") + "..."); _dictEtrans835s.Clear(); _dictEtransClaims.Clear(); List <Etrans835Attach> listAttached = Etrans835Attaches.GetForEtrans(_listAllEtrans.Select(x => x.EtransNum).ToArray()); Dictionary <long, string> dictEtransMessages = new Dictionary <long, string>(); List <X12ClaimMatch> list835ClaimMatches = new List <X12ClaimMatch>(); Dictionary <long, int> dictClaimMatchCount = new Dictionary <long, int>(); //1:1 with _listEtranss. Stores how many claim matches each 835 has. int batchQueryInterval = 500; //Every 500 rows we get the next 500 message texts to save memory. int rowCur = 0; foreach (Etrans etrans in _listAllEtrans) { if (rowCur % batchQueryInterval == 0) { int range = Math.Min(batchQueryInterval, _listAllEtrans.Count - rowCur); //Either the full batchQueryInterval amount or the remaining amount of etrans. dictEtransMessages = EtransMessageTexts.GetMessageTexts(_listAllEtrans.GetRange(rowCur, range).Select(x => x.EtransMessageTextNum).ToList(), false); } rowCur++; EtransEvent.Fire(ODEventType.Etrans, Lan.g(this, "Processing 835: ") + ": " + rowCur + " out of " + _listAllEtrans.Count); List <Etrans835Attach> listAttachedTo835 = listAttached.FindAll(x => x.EtransNum == etrans.EtransNum); X835 x835 = new X835(etrans, dictEtransMessages[etrans.EtransMessageTextNum], etrans.TranSetId835, listAttachedTo835, true); _dictEtrans835s.Add(etrans.EtransNum, x835); List <X12ClaimMatch> listClaimMatches = x835.GetClaimMatches(); dictClaimMatchCount.Add(etrans.EtransNum, listClaimMatches.Count); list835ClaimMatches.AddRange(listClaimMatches); } #region Set 835 unattached in batch and build _dictEtransClaims and _dictClaimPayCheckNums. EtransEvent.Fire(ODEventType.Etrans, Lan.g(this, "Gathering internal claim matches.")); List <long> listClaimNums = Claims.GetClaimFromX12(list835ClaimMatches); //Can return null. EtransEvent.Fire(ODEventType.Etrans, Lan.g(this, "Building data sets.")); int claimIndexCur = 0; List <long> listMatchedClaimNums = new List <long>(); foreach (Etrans etrans in _listAllEtrans) { X835 x835 = _dictEtrans835s[etrans.EtransNum]; if (listClaimNums != null) { x835.SetClaimNumsForUnattached(listClaimNums.GetRange(claimIndexCur, dictClaimMatchCount[etrans.EtransNum])); } claimIndexCur += dictClaimMatchCount[etrans.EtransNum]; listMatchedClaimNums.AddRange(x835.ListClaimsPaid.FindAll(x => x.ClaimNum != 0).Select(x => x.ClaimNum).ToList()); } List <Claim> listClaims = Claims.GetClaimsFromClaimNums(listMatchedClaimNums.Distinct().ToList()); //The following line includes manually detached and split attaches. _listAllAttaches = Etrans835Attaches.GetForEtransNumOrClaimNums(false, _listAllEtrans.Select(x => x.EtransNum).ToList(), listMatchedClaimNums.ToArray()); _listAllClaimProcs = ClaimProcs.RefreshForClaims(listMatchedClaimNums); foreach (Etrans etrans in _listAllEtrans) { X835 x835 = _dictEtrans835s[etrans.EtransNum]; #region _dictEtransClaims, _dictClaimPayCheckNums _dictEtransClaims.Add(etrans.EtransNum, new List <Claim>()); List <long> listSubClaimNums = x835.ListClaimsPaid.FindAll(x => x.ClaimNum != 0).Select(y => y.ClaimNum).ToList(); List <Claim> listClaimsFor835 = listClaims.FindAll(x => listSubClaimNums.Contains(x.ClaimNum)); foreach (Hx835_Claim claim in x835.ListClaimsPaid) { Claim claimCur = listClaimsFor835.FirstOrDefault(x => x.ClaimNum == claim.ClaimNum); //Can be null. _dictEtransClaims[etrans.EtransNum].Add(claimCur); } #endregion } EtransEvent.Fire(ODEventType.Etrans, Lan.g(this, "Filling Grid.")); #endregion } gridMain.BeginUpdate(); #region Initilize columns gridMain.ListGridColumns.Clear(); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "Patient Name"), 250)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "Carrier Name"), 190)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "Status"), 80)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "Date"), 80, GridSortingStrategy.DateParse)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "Amount"), 80, GridSortingStrategy.AmountParse)); if (PrefC.HasClinicsEnabled) { gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "Clinic"), 70)); } gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "Code"), 37, HorizontalAlignment.Center)); if (PrefC.GetBool(PrefName.EraShowControlIdFilter)) { gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "ControlID"), -1)); } gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableEtrans835s", "Note"), -2)); #endregion gridMain.ListGridRows.Clear(); foreach (Etrans etrans in _listAllEtrans) { X835 x835 = _dictEtrans835s[etrans.EtransNum]; #region Filter: Carrier Name if (carrierName != "" && !x835.PayerName.ToLower().Contains(carrierName.ToLower().Trim())) { continue; } #endregion string status = GetStringStatus(etrans.EtransNum); #region Filter: Status if (!listSelectedStatuses.Contains(status.Replace("*", ""))) //The filter will ignore finalized with detached claims. { continue; } #endregion //List of ClinicNums for the current etrans.ListClaimsPaid from the DB. List <long> listClinicNums = _dictEtransClaims[etrans.EtransNum].Select(x => x == null? 0 :x.ClinicNum).Distinct().ToList(); #region Filter: Clinics if (PrefC.HasClinicsEnabled && !listClinicNums.Exists(x => listSelectedClinicNums.Contains(x))) { continue; //The ClinicNums associated to the 835 do not match any of the selected ClinicNums, so nothing to show in this 835. } #endregion #region Filter: Check and Trace Value if (checkTraceNum != "" && !x835.TransRefNum.ToLower().Contains(checkTraceNum.ToLower().Trim())) //Trace Number does not match { continue; } #endregion #region Filter: Insurance Check Range Min and Max if (amountMin != "" && x835.InsPaid < PIn.Decimal(amountMin) || amountMax != "" && x835.InsPaid > PIn.Decimal(amountMax)) { continue; //Either the InsPaid is below or above our range. } #endregion #region Filter: ControlID if (controlId != "" && !x835.ControlId.ToLower().Contains(controlId.ToLower())) { continue; } #endregion GridRow row = new GridRow(); #region Column: Patient Name List <string> listPatNames = x835.ListClaimsPaid.Select(x => x.PatientName.ToString()).Distinct().ToList(); string patName = (listPatNames.Count > 0 ? listPatNames[0] : ""); if (listPatNames.Count > 1) { patName = "(" + POut.Long(listPatNames.Count) + ")"; } row.Cells.Add(patName); #endregion row.Cells.Add(x835.PayerName); row.Cells.Add(status); //See GetStringStatus(...) for possible values. row.Cells.Add(POut.Date(etrans.DateTimeTrans)); row.Cells.Add(POut.Decimal(x835.InsPaid)); #region Column: Clinic if (PrefC.HasClinicsEnabled) { string clinicAbbr = ""; if (listClinicNums.Count == 1) { if (listClinicNums[0] == 0) { clinicAbbr = Lan.g(this, "Unassigned"); } else { clinicAbbr = Clinics.GetAbbr(listClinicNums[0]); } } else if (listClinicNums.Count > 1) { clinicAbbr = "(" + Lan.g(this, "Multiple") + ")"; } row.Cells.Add(clinicAbbr); } #endregion row.Cells.Add(x835._paymentMethodCode); if (PrefC.GetBool(PrefName.EraShowControlIdFilter)) { row.Cells.Add(x835.ControlId); } row.Cells.Add(etrans.Note); row.Tag = etrans; gridMain.ListGridRows.Add(row); } gridMain.EndUpdate(); actionCloseProgress?.Invoke(); //When this function executes quickly this can fail rarely, fail silently because of WaitCursor. Cursor = Cursors.Default; }
private void CreateIndividual(ReportSimpleGrid report) { //added Procnum to retrieve all codes report.Query = "SELECT procedurelog.ProcDate," + DbHelper.Concat("patient.LName", "', '", "patient.FName", "' '", "patient.MiddleI") + " " + "AS plfname, procedurecode.ProcCode," + "procedurelog.ToothNum,procedurecode.Descript,provider.Abbr," + "procedurelog.ClinicNum," + "procedurelog.ProcFee-IFNULL(SUM(claimproc.WriteOff),0) "; //\"$fee\" " //if no writeoff, then subtract 0 if (DataConnection.DBtype == DatabaseType.MySql) { report.Query += "$fee "; } else //Oracle needs quotes. { report.Query += "\"$fee\" "; } report.Query += "FROM patient,procedurecode,provider,procedurelog " + "LEFT JOIN claimproc ON procedurelog.ProcNum=claimproc.ProcNum " + "AND claimproc.Status='7' " //only CapComplete writeoffs are subtracted here. + "WHERE procedurelog.ProcStatus = '2' " + "AND patient.PatNum=procedurelog.PatNum " + "AND procedurelog.CodeNum=procedurecode.CodeNum " + "AND provider.ProvNum=procedurelog.ProvNum " + whereProv + whereClin + "AND procedurecode.ProcCode LIKE '%" + POut.String(textCode.Text) + "%' " + "AND " + DbHelper.DateColumn("procedurelog.ProcDate") + " >= " + POut.Date(date1.SelectionStart) + " " + "AND " + DbHelper.DateColumn("procedurelog.ProcDate") + " <= " + POut.Date(date2.SelectionStart) + " " + "GROUP BY procedurelog.ProcNum " + "ORDER BY " + DbHelper.DateColumn("procedurelog.ProcDate") + ",plfname,procedurecode.ProcCode,ToothNum"; FormQuery2 = new FormQuery(report); FormQuery2.IsReport = true; DataTable table = report.GetTempTable(); report.TableQ = new DataTable(null); int colI = 7; if (!PrefC.GetBool(PrefName.EasyNoClinics)) { colI = 8; } for (int i = 0; i < colI; i++) //add columns { report.TableQ.Columns.Add(new System.Data.DataColumn()); //blank columns } report.InitializeColumns(); DataRow row; decimal dec = 0; decimal total = 0; for (int i = 0; i < table.Rows.Count; i++) { row = report.TableQ.NewRow(); //create new row called 'row' based on structure of TableQ row[0] = PIn.Date(table.Rows[i][0].ToString()).ToShortDateString(); row[1] = table.Rows[i][1].ToString(); //name row[2] = table.Rows[i][2].ToString(); //adacode row[3] = Tooth.ToInternat(table.Rows[i][3].ToString()); //tooth row[4] = table.Rows[i][4].ToString(); //descript row[5] = table.Rows[i][5].ToString(); //prov if (!PrefC.GetBool(PrefName.EasyNoClinics)) { row[6] = Clinics.GetDesc(PIn.Long(table.Rows[i][6].ToString())); //clinic dec = PIn.Decimal(table.Rows[i][7].ToString()); //fee row[7] = dec.ToString("n"); } else { dec = PIn.Decimal(table.Rows[i][7].ToString()); //fee row[6] = dec.ToString("n"); } total += dec; report.TableQ.Rows.Add(row); } if (!PrefC.GetBool(PrefName.EasyNoClinics)) { report.ColTotal[7] = total; } else { report.ColTotal[6] = total; } FormQuery2.ResetGrid(); report.Title = "Daily Procedures"; report.SubTitle.Add(PrefC.GetString(PrefName.PracticeTitle)); report.SubTitle.Add(date1.SelectionStart.ToString("d") + " - " + date2.SelectionStart.ToString("d")); if (checkAllProv.Checked) { report.SubTitle.Add(Lan.g(this, "All Providers")); } else { string provNames = ""; for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i > 0) { provNames += ", "; } provNames += ProviderC.ListShort[listProv.SelectedIndices[i]].Abbr; } report.SubTitle.Add(provNames); } if (!PrefC.GetBool(PrefName.EasyNoClinics)) { if (checkAllClin.Checked) { report.SubTitle.Add(Lan.g(this, "All Clinics")); } else { string clinNames = ""; for (int i = 0; i < listClin.SelectedIndices.Count; i++) { if (i > 0) { clinNames += ", "; } if (listClin.SelectedIndices[i] == 0) { clinNames += Lan.g(this, "Unassigned"); } else { clinNames += Clinics.List[listClin.SelectedIndices[i] - 1].Description; } } report.SubTitle.Add(clinNames); } } report.SetColumn(this, 0, "Date", 80); report.SetColumn(this, 1, "Patient Name", 130); report.SetColumn(this, 2, "ADA Code", 75); report.SetColumn(this, 3, "Tooth", 45); report.SetColumn(this, 4, "Description", 200); report.SetColumn(this, 5, "Provider", 50); if (!PrefC.GetBool(PrefName.EasyNoClinics)) { report.SetColumn(this, 6, "Clinic", 70); report.SetColumn(this, 7, "Fee", 90, HorizontalAlignment.Right); } else { report.SetColumn(this, 6, "Fee", 90, HorizontalAlignment.Right); } FormQuery2.ShowDialog(); DialogResult = DialogResult.OK; }
private void FillGrid() { if (textDaysOldMin.Text.Trim() == "" || PIn.Double(textDaysOldMin.Text) == 0) { dateMin = DateTime.MinValue; } else { dateMin = DateTimeOD.Today.AddDays(-1 * PIn.Int(textDaysOldMin.Text)); } if (textDaysOldMax.Text.Trim() == "" || PIn.Double(textDaysOldMax.Text) == 0) { dateMax = DateTime.MinValue; } else { dateMax = DateTimeOD.Today.AddDays(-1 * PIn.Int(textDaysOldMax.Text)); } if (comboBoxMultiProv.SelectedIndices[0].ToString() == "0") { isAllProv = true; } else { isAllProv = false; provNumList = new List <long>(); for (int i = 0; i < comboBoxMultiProv.SelectedIndices.Count; i++) { provNumList.Add((long)ProviderC.ListShort[(int)comboBoxMultiProv.SelectedIndices[i] - 1].ProvNum); } } isPreauth = checkPreauth.Checked; Table = Claims.GetOutInsClaims(isAllProv, provNumList, dateMin, dateMax, isPreauth); gridMain.BeginUpdate(); gridMain.Columns.Clear(); ODGridColumn col; col = new ODGridColumn(Lan.g(this, "Carrier"), 180); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Phone"), 103); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Type"), 60); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Patient Name"), 140); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Date of Service"), 93); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Date Sent"), 70); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "Amount"), 85, HorizontalAlignment.Right); gridMain.Columns.Add(col); gridMain.Rows.Clear(); ODGridRow row; string type; total = 0; for (int i = 0; i < Table.Rows.Count; i++) { row = new ODGridRow(); row.Cells.Add(Table.Rows[i]["CarrierName"].ToString()); row.Cells.Add(Table.Rows[i]["Phone"].ToString()); type = Table.Rows[i]["ClaimType"].ToString(); switch (type) { case "P": type = "Primary"; break; case "S": type = "Secondary"; break; case "PreAuth": type = "Preauth"; break; case "Other": type = "Other"; break; case "Cap": type = "Capitation"; break; case "Med": type = "Medical"; //For possible future use. break; default: type = "Error"; //Not allowed to be blank. break; } row.Cells.Add(type); if (PrefC.GetBool(PrefName.ReportsShowPatNum)) { row.Cells.Add(Table.Rows[i]["PatNum"].ToString() + "-" + Table.Rows[i]["LName"].ToString() + ", " + Table.Rows[i]["FName"].ToString() + " " + Table.Rows[i]["MiddleI"].ToString()); } else { row.Cells.Add(Table.Rows[i]["LName"].ToString() + ", " + Table.Rows[i]["FName"].ToString() + " " + Table.Rows[i]["MiddleI"].ToString()); } DateTime dateService = PIn.Date(Table.Rows[i]["DateService"].ToString()); if (dateService.Year < 1880) { row.Cells.Add(""); } else { row.Cells.Add(dateService.ToShortDateString()); } row.Cells.Add(PIn.Date(Table.Rows[i]["DateSent"].ToString()).ToShortDateString()); row.Cells.Add(PIn.Double(Table.Rows[i]["ClaimFee"].ToString()).ToString("c")); gridMain.Rows.Add(row); total += PIn.Decimal(Table.Rows[i]["ClaimFee"].ToString()); } textBox1.Text = total.ToString("c"); gridMain.EndUpdate(); }
private void FillGrid() { int numAccepted = 0; int numRejected = 0; decimal amountAccepted = 0; decimal amountRejected = 0; List <string> claimTrackingNumbers = x277.GetClaimTrackingNumbers(); //bool showInstBillType=false; bool showServiceDateRange = false; for (int i = 0; i < claimTrackingNumbers.Count; i++) { string[] claimInfo = x277.GetClaimInfo(claimTrackingNumbers[i]); //if(claimInfo[5]!="") { //institutional type of bill // showInstBillType=true; //} if (claimInfo[7] != "") //service date end { showServiceDateRange = true; } } gridMain.BeginUpdate(); gridMain.Columns.Clear(); ODGridColumn col; int variableWidth = this.Width - 2 * gridMain.Left - 10; if (showServiceDateRange) { const int serviceDateFromWidth = 86; col = new ODGridColumn(Lan.g(this, "ServDateFrom"), serviceDateFromWidth, HorizontalAlignment.Center); gridMain.Columns.Add(col); variableWidth -= serviceDateFromWidth; const int serviceDateToWidth = 80; col = new ODGridColumn(Lan.g(this, "ServDateTo"), serviceDateToWidth, HorizontalAlignment.Center); gridMain.Columns.Add(col); variableWidth -= serviceDateToWidth; } else { const int serviceDateWidth = 80; col = new ODGridColumn(Lan.g(this, "ServiceDate"), serviceDateWidth, HorizontalAlignment.Center); gridMain.Columns.Add(col); variableWidth -= serviceDateWidth; } const int amountWidth = 80; col = new ODGridColumn(Lan.g(this, "Amount"), amountWidth, HorizontalAlignment.Center); gridMain.Columns.Add(col); variableWidth -= amountWidth; const int statusWidth = 54; col = new ODGridColumn(Lan.g(this, "Status"), statusWidth, HorizontalAlignment.Center); gridMain.Columns.Add(col); variableWidth -= statusWidth; const int lnameWidth = 150; const int fnameWidth = 100; const int claimIdWidth = 100; const int payorControlNumWidth = 126; variableWidth += -lnameWidth - fnameWidth - claimIdWidth - payorControlNumWidth; col = new ODGridColumn(Lan.g(this, "Reason"), variableWidth); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "LName"), lnameWidth); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "FName"), fnameWidth); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "ClaimIdentifier"), claimIdWidth); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g(this, "PayorControlNum"), payorControlNumWidth); gridMain.Columns.Add(col); gridMain.Rows.Clear(); for (int i = 0; i < claimTrackingNumbers.Count; i++) { string[] claimInfo = x277.GetClaimInfo(claimTrackingNumbers[i]); ODGridRow row = new ODGridRow(); row.Cells.Add(new ODGridCell(claimInfo[6])); //service date start if (showServiceDateRange) { row.Cells.Add(new ODGridCell(claimInfo[7])); //service date end } string claimStatus = ""; decimal claimAmount = PIn.Decimal(claimInfo[9]); if (claimInfo[3] == "A") { claimStatus = "Accepted"; numAccepted++; amountAccepted += claimAmount; } else if (claimInfo[3] == "R") { claimStatus = "Rejected"; numRejected++; amountRejected += claimAmount; } row.Cells.Add(new ODGridCell(claimAmount.ToString("F"))); //amount row.Cells.Add(new ODGridCell(claimStatus)); //status row.Cells.Add(new ODGridCell(claimInfo[8])); //reason row.Cells.Add(new ODGridCell(claimInfo[0])); //lname row.Cells.Add(new ODGridCell(claimInfo[1])); //fname row.Cells.Add(new ODGridCell(claimTrackingNumbers[i])); //claim identifier row.Cells.Add(new ODGridCell(claimInfo[4])); //payor control number gridMain.Rows.Add(row); } gridMain.EndUpdate(); textQuantityAccepted.Text = numAccepted.ToString(); textQuantityRejected.Text = numRejected.ToString(); textAmountAccepted.Text = amountAccepted.ToString("F"); textAmountRejected.Text = amountRejected.ToString("F"); }
///<summary>Processes a PayConnect payment via a credit card terminal.</summary> private bool ProcessPaymentTerminal() { PosRequest posRequest = null; try { if (radioSale.Checked) { posRequest = PosRequest.CreateSale(PIn.Decimal(textAmount.Text)); } else if (radioAuthorization.Checked) { posRequest = PosRequest.CreateAuth(PIn.Decimal(textAmount.Text)); } else if (radioVoid.Checked) { posRequest = PosRequest.CreateVoidByReference(textRefNumber.Text); } else if (radioReturn.Checked) { if (textRefNumber.Text == "") { posRequest = PosRequest.CreateRefund(PIn.Decimal(textAmount.Text)); } else { posRequest = PosRequest.CreateRefund(PIn.Decimal(textAmount.Text), textRefNumber.Text); } } else //Shouldn't happen { MsgBox.Show(this, "Please select a transaction type"); return(false); } posRequest.ForceDuplicate = checkForceDuplicate.Checked; } catch (Exception ex) { MessageBox.Show(Lan.g(this, "Error creating request:") + " " + ex.Message); return(false); } bool result = true; ODProgress.ShowAction(() => { _posResponse = DpsPos.ProcessCreditCard(posRequest); }, startingMessage: Lan.g(this, "Processing payment on terminal"), actionException: ex => { this.Invoke(() => { MessageBox.Show(Lan.g(this, "Error processing card:") + " " + ex.Message); result = false; }); }); if (!result) { return(false); } if (_posResponse == null) { MessageBox.Show(Lan.g(this, "Error processing card")); return(false); } if (_posResponse.ResponseCode != "0") //"0" indicates success. May need to check the AuthCode field too to determine if this was a success. { MessageBox.Show(Lan.g(this, "Error message from Pay Connect:") + "\r\n" + _posResponse.ResponseDescription); return(false); } PayConnectService.signatureResponse sigResponse = null; try { Cursor = Cursors.WaitCursor; sigResponse = SendSignature(_posResponse.ReferenceNumber.ToString()); Cursor = Cursors.Default; } catch (Exception ex) { Cursor = Cursors.Default; MessageBox.Show(Lan.g(this, "Card successfully charged. Error processing signature:") + " " + ex.Message); } textCardNumber.Text = _posResponse.CardNumber; textAmount.Text = _posResponse.Amount.ToString("f"); _receiptStr = PayConnectTerminal.BuildReceiptString(posRequest, _posResponse, sigResponse, _clinicNum); PrintReceipt(_receiptStr); return(true); }
///<summary>Processes a PayConnect payment via the PayConnect web service.</summary> private bool ProcessPaymentWebService(int expYear, int expMonth) { string refNumber = ""; if (_trantype == PayConnectService.transType.VOID || _trantype == PayConnectService.transType.RETURN) { refNumber = textRefNumber.Text; } string magData = null; if (_parser != null) { magData = _parser.Track2; } string cardNumber = textCardNumber.Text; //if using a stored CC and there is an X-Charge token saved for the CC and the user enters the whole card number to get a PayConnect token //and the number entered doesn't have the same last 4 digits and exp date, then assume it's not the same card and clear out the X-Charge token. if (_creditCardCur != null && //using a saved CC !string.IsNullOrEmpty(_creditCardCur.XChargeToken) && //there is an X-Charge token saved (cardNumber.Right(4) != _creditCardCur.CCNumberMasked.Right(4) || //the card number entered doesn't have the same last 4 digits expYear != _creditCardCur.CCExpiration.Year || //the card exp date entered doesn't have the same year expMonth != _creditCardCur.CCExpiration.Month)) //the card exp date entered doesn't have the same month { if (MsgBox.Show(this, MsgBoxButtons.YesNo, "The card number or expiration date entered does not match the X-Charge card on file. Do you wish " + "to replace the X-Charge card with this one?")) { _creditCardCur.XChargeToken = ""; } else { Cursor = Cursors.Default; return(false); } } //if the user has chosen to store CC tokens and the stored CC has a token and the token is not expired, //then use it instead of the CC number and CC expiration. if (checkSaveToken.Checked && _creditCardCur != null && //if the user selected a saved CC _creditCardCur.PayConnectToken != "" && //there is a stored token for this card _creditCardCur.PayConnectTokenExp.Date >= DateTime.Today.Date) //the token is not expired { cardNumber = _creditCardCur.PayConnectToken; expYear = _creditCardCur.PayConnectTokenExp.Year; expMonth = _creditCardCur.PayConnectTokenExp.Month; } else if (PIn.Bool(ProgramProperties.GetPropVal(_progCur.ProgramNum, PayConnect.ProgramProperties.PayConnectPreventSavingNewCC, _clinicNum))) { MsgBox.Show(this, "Cannot add a new credit card."); return(false); } string authCode = ""; if (_trantype == PayConnectService.transType.FORCE) { authCode = textRefNumber.Text; } _request = PayConnect.BuildSaleRequest(PIn.Decimal(textAmount.Text), cardNumber, expYear, expMonth, textNameOnCard.Text, textSecurityCode.Text, textZipCode.Text, magData, _trantype, refNumber, checkSaveToken.Checked, authCode, checkForceDuplicate.Checked); _response = PayConnect.ProcessCreditCard(_request, _clinicNum, x => MessageBox.Show(x)); if (_response == null || _response.Status.code != 0) //error in transaction { return(false); } PayConnectService.signatureResponse sigResponse = SendSignature(_response.RefNumber); if ((_trantype.In(PayConnectService.transType.SALE, PayConnectService.transType.RETURN, PayConnectService.transType.VOID)) && _response.Status.code == 0) //Only print a receipt if transaction is an approved SALE, RETURN, or VOID { _receiptStr = PayConnect.BuildReceiptString(_request, _response, sigResponse, _clinicNum); PrintReceipt(_receiptStr); } if (!PrefC.GetBool(PrefName.StoreCCnumbers) && !checkSaveToken.Checked) //not storing the card number or the token { return(true); } //response must be non-null and the status code must be 0=Approved //also, the user must have the pref StoreCCnumbers enabled or they have the checkSaveTokens checked if (_creditCardCur == null) //user selected Add new card from the payment window, save it or its token depending on settings { _creditCardCur = new CreditCard(); _creditCardCur.IsNew = true; _creditCardCur.PatNum = _patCur.PatNum; List <CreditCard> itemOrderCount = CreditCards.Refresh(_patCur.PatNum); _creditCardCur.ItemOrder = itemOrderCount.Count; } _creditCardCur.CCExpiration = new DateTime(expYear, expMonth, DateTime.DaysInMonth(expYear, expMonth)); if (PrefC.GetBool(PrefName.StoreCCnumbers)) { _creditCardCur.CCNumberMasked = textCardNumber.Text; } else { _creditCardCur.CCNumberMasked = textCardNumber.Text.Right(4).PadLeft(textCardNumber.Text.Length, 'X'); } _creditCardCur.Zip = textZipCode.Text; _creditCardCur.PayConnectToken = ""; _creditCardCur.PayConnectTokenExp = DateTime.MinValue; //Store the token and the masked CC number (only last four digits). if (checkSaveToken.Checked && _response.PaymentToken != null) { _creditCardCur.PayConnectToken = _response.PaymentToken.TokenId; _creditCardCur.PayConnectTokenExp = new DateTime(_response.PaymentToken.Expiration.year, _response.PaymentToken.Expiration.month, DateTime.DaysInMonth(_response.PaymentToken.Expiration.year, _response.PaymentToken.Expiration.month)); } _creditCardCur.CCSource = CreditCardSource.PayConnect; if (_creditCardCur.IsNew) { _creditCardCur.ClinicNum = _clinicNum; _creditCardCur.Procedures = PrefC.GetString(PrefName.DefaultCCProcs); CreditCards.Insert(_creditCardCur); } else { if (_creditCardCur.CCSource == CreditCardSource.XServer) //This card has also been added for XCharge. { _creditCardCur.CCSource = CreditCardSource.XServerPayConnect; } CreditCards.Update(_creditCardCur); } return(true); }
private void butOK_Click(object sender, System.EventArgs e) { ReportSimpleGrid report = new ReportSimpleGrid(); report.Query = "SELECT claim.dateservice,claim.claimnum,claim.claimtype,claim.claimstatus," + "CONCAT(CONCAT(CONCAT(CONCAT(patient.LName,', '),patient.FName),' '),patient.MiddleI),carrier.CarrierName,claim.claimfee " + "FROM patient,claim,insplan,carrier " + "WHERE patient.patnum=claim.patnum AND insplan.plannum=claim.plannum " + "AND insplan.CarrierNum=carrier.CarrierNum " + "AND (claim.claimstatus = 'U' OR claim.claimstatus = 'H' OR claim.claimstatus = 'W')"; if (radioRange.Checked == true) { report.Query += " AND claim.dateservice >= '" + date1.SelectionStart.ToString("yyyy-MM-dd") + "' " + "AND claim.dateservice <= '" + date2.SelectionStart.ToString("yyyy-MM-dd") + "'"; } else { report.Query += " AND claim.dateservice = '" + date1.SelectionStart.ToString("yyyy-MM-dd") + "'"; } FormQuery2 = new FormQuery(report); FormQuery2.IsReport = true; DataTable tempT = report.GetTempTable(); report.TableQ = new DataTable(null); //new table no name for (int i = 0; i < 6; i++) //add columns { report.TableQ.Columns.Add(new System.Data.DataColumn()); //blank columns } report.InitializeColumns(); for (int i = 0; i < tempT.Rows.Count; i++) //loop through data rows { DataRow row = report.TableQ.NewRow(); //create new row called 'row' based on structure of TableQ row[0] = (PIn.Date(tempT.Rows[i][0].ToString())).ToShortDateString(); //claim dateservice if (PIn.String(tempT.Rows[i][2].ToString()) == "P") { row[1] = "Primary"; } if (PIn.String(tempT.Rows[i][2].ToString()) == "S") { row[1] = "Secondary"; } if (PIn.String(tempT.Rows[i][2].ToString()) == "PreAuth") { row[1] = "PreAuth"; } if (PIn.String(tempT.Rows[i][2].ToString()) == "Other") { row[1] = "Other"; } if (tempT.Rows[i][3].ToString().Equals("H")) { row[2] = "Holding"; //Claim Status } else if (tempT.Rows[i][3].ToString().Equals("W")) { row[2] = "WaitQ"; //Claim Status, added SPK 7/15/04 } else { row[2] = "Unsent"; //Claim Status } row[3] = tempT.Rows[i][4]; //Patient name row[4] = tempT.Rows[i][5]; //Ins Carrier row[5] = PIn.Double(tempT.Rows[i][6].ToString()).ToString("F"); //claim fee report.ColTotal[5] += PIn.Decimal(tempT.Rows[i][6].ToString()); report.TableQ.Rows.Add(row); } FormQuery2.ResetGrid(); //this is a method in FormQuery2; report.Title = "Claims Not Sent"; report.SubTitle.Add(PrefC.GetString(PrefName.PracticeTitle)); if (radioRange.Checked == true) { report.SubTitle.Add(date1.SelectionStart.ToString("d") + " - " + date2.SelectionStart.ToString("d")); } else { report.SubTitle.Add(date1.SelectionStart.ToString("d")); } report.ColPos[0] = 20; report.ColPos[1] = 145; report.ColPos[2] = 270; report.ColPos[3] = 395; report.ColPos[4] = 520; report.ColPos[5] = 645; report.ColPos[6] = 770; report.ColCaption[0] = "Date"; report.ColCaption[1] = "Type"; report.ColCaption[2] = "Claim Status"; report.ColCaption[3] = "Patient Name"; report.ColCaption[4] = "Insurance Carrier"; report.ColCaption[5] = "Amount"; report.ColAlign[5] = HorizontalAlignment.Right; FormQuery2.ShowDialog(); DialogResult = DialogResult.OK; }
private void butOK_Click(object sender, EventArgs e) { Amount = PIn.Decimal(textAmount.Text); DialogResult = DialogResult.OK; }
///<summary>Processes a PaySimple ACH payment via the PaySimple API.</summary> private PaySimple.ApiResponse ProcessPaymentACH() { PaySimple.ApiResponse retVal = null; string accountNumber = textCheckSaveNumber.Text; //if the user has chosen to store CC tokens and the stored CC has a token and the token is not expired, //then use it instead of the CC number and CC expiration. if (!checkOneTimePaymentACH.Checked && _creditCardCur != null && //if the user selected a saved CC !string.IsNullOrWhiteSpace(_creditCardCur.PaySimpleToken) && //there is a stored token for this card _creditCardCur.CCSource == CreditCardSource.PaySimpleACH) { accountNumber = _creditCardCur.PaySimpleToken; } else if (PIn.Bool(ProgramProperties.GetPropVal(_progCur.ProgramNum, PaySimple.PropertyDescs.PaySimplePreventSavingNewCC, _clinicNum))) { MsgBox.Show(this, "Cannot add a new ACH payment."); return(null); } try { if (_isAddingCard) { retVal = PaySimple.AddACHAccount(_patCur, textRoutingNumber.Text, textCheckSaveNumber.Text, textBankName.Text, radioCheckings.Checked, _clinicNum); } else { retVal = PaySimple.MakePaymentACH(_patCur, _creditCardCur, PIn.Decimal(textAmountACH.Text), textRoutingNumber.Text, textCheckSaveNumber.Text, textBankName.Text, radioCheckings.Checked, checkOneTimePaymentACH.Checked, _clinicNum); try { string result = WebServiceMainHQProxy.GetWebServiceMainHQInstance() .InsertPaySimpleACHId(PayloadHelper.CreatePayload( PayloadHelper.CreatePayloadContent(retVal.RefNumber.ToString(), "PaymentId"), eServiceCode.PaySimple)); PayloadHelper.CheckForError(result); } catch (Exception ex) { FriendlyException.Show("Unable to register for ACH Settled event", ex); } } } catch (PaySimpleException ex) { MessageBox.Show(ex.Message); if (ex.ErrorType == PaySimpleError.CustomerDoesNotExist && MsgBox.Show(this, MsgBoxButtons.OKCancel, "Delete the link to the customer id for this patient?")) { PatientLinks.DeletePatNumTos(ex.CustomerId, PatientLinkType.PaySimple); } return(null); } catch (ODException ex) { MessageBox.Show(ex.Message); //This should have already been Lans.g if applicable. return(null); } catch (Exception ex) { FriendlyException.Show(Lan.g(this, "Error:") + " " + ex.Message, ex); return(null); } if (!_isAddingCard) { retVal.BuildReceiptString(accountNumber, -1, -1, _patCur?.GetNameFL(), _clinicNum, wasSwiped: false, isACH: true); PrintReceipt(retVal.TransactionReceipt); } if (checkOneTimePaymentACH.Checked) //not storing the account token { return(retVal); } UpsertCreditCard(retVal, textCheckSaveNumber.Text.Right(4).PadLeft(textCheckSaveNumber.Text.Length, '*'), CreditCardSource.PaySimpleACH, DateTime.MinValue); return(retVal); }
///<summary>Fills charge grid, and then split grid.</summary> private void FillGridCharges() { //Fill right-hand grid with all the charges, filtered based on checkbox and filters. List <int> listExpandedRows = new List <int>(); for (int i = 0; i < gridCharges.ListGridRows.Count; i++) { if (gridCharges.ListGridRows[i].State.DropDownState == ODGridDropDownState.Down) { listExpandedRows.Add(i); //Keep track of expanded rows } } gridCharges.BeginUpdate(); gridCharges.ListGridColumns.Clear(); gridCharges.ListGridColumns.Add(new GridColumn(Lan.g(this, "Prov"), 100)); gridCharges.ListGridColumns.Add(new GridColumn(Lan.g(this, "Patient"), 100)); if (PrefC.HasClinicsEnabled) { gridCharges.ListGridColumns.Add(new GridColumn(Lan.g(this, "Clinic"), 60)); } gridCharges.ListGridColumns.Add(new GridColumn(Lan.g(this, "Codes"), -200)); //negative so it will dynamically grow when no clinic column is present gridCharges.ListGridColumns.Add(new GridColumn(Lan.g(this, "Amt Orig"), 61, HorizontalAlignment.Right, GridSortingStrategy.AmountParse)); gridCharges.ListGridColumns.Add(new GridColumn(Lan.g(this, "Amt Start"), 61, HorizontalAlignment.Right, GridSortingStrategy.AmountParse)); gridCharges.ListGridColumns.Add(new GridColumn(Lan.g(this, "Amt End"), 61, HorizontalAlignment.Right, GridSortingStrategy.AmountParse)); gridCharges.ListGridRows.Clear(); decimal chargeTotal = 0; //Item1=ProvNum,Item2=ClinicNum,Item3=PatNum List <Tuple <long, long, long> > listAddedProvNums = new List <Tuple <long, long, long> >(); //this needs to be prov/clinic/patnum List <Tuple <long, long, long> > listAddedParents = new List <Tuple <long, long, long> >(); //prov/clinic/pat foreach (AccountEntry entryCharge in _results.ListAccountCharges) { if (Math.Round(entryCharge.AmountStart, 3) == 0) { continue; } if (listAddedProvNums.Any(x => x.Item1 == entryCharge.ProvNum && x.Item2 == entryCharge.ClinicNum && x.Item3 == entryCharge.PatNum)) { continue; } listAddedProvNums.Add(Tuple.Create(entryCharge.ProvNum, entryCharge.ClinicNum, entryCharge.PatNum)); List <AccountEntry> listEntriesForProvAndClinicAndPatient = _results.ListAccountCharges .FindAll(x => x.ProvNum == entryCharge.ProvNum && x.ClinicNum == entryCharge.ClinicNum && x.PatNum == entryCharge.PatNum); List <GridRow> listRows = CreateChargeRows(listEntriesForProvAndClinicAndPatient, listExpandedRows); foreach (GridRow row in listRows) { AccountEntry accountEntry = (AccountEntry)row.Tag; if (accountEntry.Tag == null) //Parent row { chargeTotal += PIn.Decimal(row.Cells[row.Cells.Count - 1].Text); listAddedParents.Add(Tuple.Create(accountEntry.ProvNum, accountEntry.ClinicNum, accountEntry.PatNum)); } else if (!listAddedParents.Exists(x => x.Item1 == accountEntry.ProvNum && x.Item2 == accountEntry.ClinicNum && x.Item3 == accountEntry.PatNum)) //In case a parent AND child are selected, don't add child amounts if parent was added already { chargeTotal += accountEntry.AmountEnd; } gridCharges.ListGridRows.Add(row); } } gridCharges.EndUpdate(); textChargeTotal.Text = chargeTotal.ToString("f"); }
///<summary>Set all fields of this control. This is an alternative to constructing an entirely new instance. ///All uses of this control currently construct as Visible=false so that is the default here.</summary> public void ResetData(DataRow rowApt, DataTable tableApptFields, DataTable tablePatFields, Point location, bool visible = false) { DataRoww = rowApt; TableApptFields = tableApptFields; TablePatFields = tablePatFields; Pattern = PIn.String(DataRoww["Pattern"].ToString()); PatternShowing = ApptSingleDrawing.GetPatternShowing(Pattern); Location = location; Size = ApptSingleDrawing.SetSize(Pattern); //These controls are always drawn as their Shadow bitmap. //They never actually render as a control. //Always set Visible to false here so that parent panel/form doesn't account for them when drawings it's controls. //In the case where it is a draggable control or on the pinboard, then it will be set to Visible=true. Visible = visible; //These are used heavily so deserialize here once to save time when accessing. AptNum = PIn.Long(DataRoww["AptNum"].ToString()); PatNum = PIn.Long(DataRoww["PatNum"].ToString()); AptDateTime = PIn.DateT(DataRoww["AptDateTime"].ToString()); OpNum = PIn.Long(DataRoww["Op"].ToString()); ClinicNum = PIn.Long(DataRoww["ClinicNum"].ToString()); ProvNum = PIn.Long(DataRoww["ProvNum"].ToString()); ProvHyg = PIn.Long(DataRoww["ProvHyg"].ToString()); Confirmed = PIn.Long(DataRoww["Confirmed"].ToString()); IsHygiene = PIn.Bool(DataRoww["IsHygiene"].ToString()); GrossProduction = PIn.Decimal(DataRoww["productionVal"].ToString()); WriteoffPPO = PIn.Decimal(DataRoww["writeoffPPO"].ToString()); AdjustmentTotal = PIn.Decimal(DataRoww["adjustmentTotal"].ToString()); ImageFolder = PIn.String(DataRoww["ImageFolder"].ToString()); PatientName = PIn.String(DataRoww["patientName"].ToString()); AptDate = PIn.String(DataRoww["aptDate"].ToString()); AptDay = PIn.String(DataRoww["aptDay"].ToString()); AptLength = PIn.String(DataRoww["aptLength"].ToString()); AptTime = PIn.String(DataRoww["aptTime"].ToString()); Email = PIn.String(DataRoww["Email"].ToString()); Language = PIn.String(DataRoww["language"].ToString()); ReferralTo = PIn.String(DataRoww["referralTo"].ToString()); ReferralFrom = PIn.String(DataRoww["referralFrom"].ToString()); ApptModNote = PIn.String(DataRoww["apptModNote"].ToString()); FamFinUrgNote = PIn.String(DataRoww["famFinUrgNote"].ToString()); AddrNote = PIn.String(DataRoww["addrNote"].ToString()); Insurance = PIn.String(DataRoww["insurance"].ToString()); ContactMethods = PIn.String(DataRoww["contactMethods"].ToString()); WirelessPhone = PIn.String(DataRoww["wirelessPhone"].ToString()); WkPhone = PIn.String(DataRoww["wkPhone"].ToString()); HmPhone = PIn.String(DataRoww["hmPhone"].ToString()); Age = PIn.String(DataRoww["age"].ToString()); BillingType = PIn.String(DataRoww["billingType"].ToString()); ChartNumber = PIn.String(DataRoww["chartNumber"].ToString()); Note = PIn.String(DataRoww["Note"].ToString()); Procs = PIn.String(DataRoww["procs"].ToString()); Lab = PIn.String(DataRoww["lab"].ToString()); MedUrgNote = PIn.String(DataRoww["MedUrgNote"].ToString()); PreMedFlag = PIn.String(DataRoww["preMedFlag"].ToString()); ConfirmedFromDef = PIn.String(DataRoww["confirmed"].ToString()); Production = PIn.String(DataRoww["production"].ToString()); Provider = PIn.String(DataRoww["provider"].ToString()); ApptStatus aptStatus; if (Enum.TryParse(PIn.String(DataRoww["AptStatus"].ToString()), out aptStatus)) { AptStatus = aptStatus; } else { AptStatus = ApptStatus.None; } ApptPriority priority; if (Enum.TryParse(PIn.String(DataRoww["Priority"].ToString()), out priority)) { Priority = priority; } else { Priority = ApptPriority.Normal; } }
///<summary>Fills grid based on values in _listEtrans. ///Set isRefreshNeeded to true when we need to reinitialize local dictionarys after in memory list is also updated. Required true for first time running. ///Also allows you to passed in predetermined filter options.</summary> private void FillGrid(bool isRefreshNeeded, List <string> listSelectedStatuses, List <long> listSelectedClinicNums, string carrierName, string checkTraceNum, string amountMin, string amountMax) { Action actionCloseProgress = null; if (isRefreshNeeded) { actionCloseProgress = ODProgressOld.ShowProgressStatus("Etrans835", this, Lan.g(this, "Gathering data") + "...", false); _dictEtrans835s.Clear(); _dictEtransClaims.Clear(); _dictClaimPayExists.Clear(); List <Etrans835Attach> listAttached = Etrans835Attaches.GetForEtrans(_listEtranss.Select(x => x.EtransNum).ToArray()); Dictionary <long, string> dictEtransMessages = new Dictionary <long, string>(); List <X12ClaimMatch> list835ClaimMatches = new List <X12ClaimMatch>(); Dictionary <long, int> dictClaimMatchCount = new Dictionary <long, int>(); //1:1 with _listEtranss. Stores how many claim matches each 835 has. int batchQueryInterval = 500; //Every 500 rows we get the next 500 message texts to save memory. int rowCur = 0; foreach (Etrans etrans in _listEtranss) { if (rowCur % batchQueryInterval == 0) { int range = Math.Min(batchQueryInterval, _listEtranss.Count - rowCur); //Either the full batchQueryInterval amount or the remaining amount of etrans. dictEtransMessages = EtransMessageTexts.GetMessageTexts(_listEtranss.GetRange(rowCur, range).Select(x => x.EtransMessageTextNum).ToList(), false); } rowCur++; ODEvent.Fire(new ODEventArgs("Etrans835", Lan.g(this, "Processing 835: ") + ": " + rowCur + " out of " + _listEtranss.Count)); List <Etrans835Attach> listAttachedTo835 = listAttached.FindAll(x => x.EtransNum == etrans.EtransNum); X835 x835 = new X835(etrans, dictEtransMessages[etrans.EtransMessageTextNum], etrans.TranSetId835, listAttachedTo835, true); _dictEtrans835s.Add(etrans.EtransNum, x835); List <X12ClaimMatch> listClaimMatches = x835.GetClaimMatches(); dictClaimMatchCount.Add(etrans.EtransNum, listClaimMatches.Count); list835ClaimMatches.AddRange(listClaimMatches); } #region Set 835 unattached in batch and build _dictEtransClaims and _dictClaimPayCheckNums. ODEvent.Fire(new ODEventArgs("Etrans835", Lan.g(this, "Gathering internal claim matches."))); List <long> listClaimNums = Claims.GetClaimFromX12(list835ClaimMatches); //Can return null. ODEvent.Fire(new ODEventArgs("Etrans835", Lan.g(this, "Building data sets."))); int claimIndexCur = 0; List <long> listMatchedClaimNums = new List <long>(); foreach (Etrans etrans in _listEtranss) { X835 x835 = _dictEtrans835s[etrans.EtransNum]; if (listClaimNums != null) { x835.SetClaimNumsForUnattached(listClaimNums.GetRange(claimIndexCur, dictClaimMatchCount[etrans.EtransNum])); } claimIndexCur += dictClaimMatchCount[etrans.EtransNum]; listMatchedClaimNums.AddRange(x835.ListClaimsPaid.FindAll(x => x.ClaimNum != 0).Select(x => x.ClaimNum).ToList()); } List <Claim> listClaims = Claims.GetClaimsFromClaimNums(listMatchedClaimNums.Distinct().ToList()); _dictClaimPayExists = ClaimPayments.HasClaimPayment(listMatchedClaimNums); //Every claim num is associated to a bool. True when there is an existing claimPayment. foreach (Etrans etrans in _listEtranss) { X835 x835 = _dictEtrans835s[etrans.EtransNum]; #region _dictEtransClaims, _dictClaimPayCheckNums _dictEtransClaims.Add(etrans.EtransNum, new List <Claim>()); List <long> listSubClaimNums = x835.ListClaimsPaid.FindAll(x => x.ClaimNum != 0).Select(y => y.ClaimNum).ToList(); List <Claim> listClaimsFor835 = listClaims.FindAll(x => listSubClaimNums.Contains(x.ClaimNum)); foreach (Hx835_Claim claim in x835.ListClaimsPaid) { Claim claimCur = listClaimsFor835.FirstOrDefault(x => x.ClaimNum == claim.ClaimNum); //Can be null. if (claimCur == null && claim.IsAttachedToClaim && claim.ClaimNum == 0) { claimCur = new Claim(); //Create empty claim since user detached claim manually, will not be considered in GetStringStatus(...). } if (claimCur != null && claim.IsPreauth) //User attached preauth to internal claim, no payment needed to be considered 'Finalized' in GetStringStatus(...). { _dictClaimPayExists[claim.ClaimNum] = true; } _dictEtransClaims[etrans.EtransNum].Add(claimCur); } #endregion } ODEvent.Fire(new ODEventArgs("Etrans835", Lan.g(this, "Filling Grid."))); #endregion } gridMain.BeginUpdate(); #region Initilize columns only once if (gridMain.Columns.Count == 0) { ODGridColumn col; col = new ODGridColumn(Lan.g("TableEtrans835s", "Patient Name"), 250); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g("TableEtrans835s", "Carrier Name"), 190); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g("TableEtrans835s", "Status"), 80); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g("TableEtrans835s", "Date"), 80); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g("TableEtrans835s", "Amount"), 80); gridMain.Columns.Add(col); if (PrefC.HasClinicsEnabled) { col = new ODGridColumn(Lan.g("TableEtrans835s", "Clinic"), 70); gridMain.Columns.Add(col); } col = new ODGridColumn(Lan.g("TableEtrans835s", "Code"), 37, HorizontalAlignment.Center); gridMain.Columns.Add(col); col = new ODGridColumn(Lan.g("TableEtrans835s", "Note"), 0); gridMain.Columns.Add(col); } #endregion gridMain.Rows.Clear(); foreach (Etrans etrans in _listEtranss) { X835 x835 = _dictEtrans835s[etrans.EtransNum]; #region Filter: Carrier Name if (carrierName != "" && !x835.PayerName.ToLower().Contains(carrierName.ToLower())) { continue; } #endregion string status = GetStringStatus(etrans.EtransNum); #region Filter: Status if (!listSelectedStatuses.Contains(status.Replace("*", ""))) //The filter will ignore finalized with detached claims. { continue; } #endregion //List of ClinicNums for the current etrans.ListClaimsPaid from the DB. List <long> listClinicNums = _dictEtransClaims[etrans.EtransNum].Select(x => x == null? 0 :x.ClinicNum).Distinct().ToList(); #region Filter: Clinics if (PrefC.HasClinicsEnabled && !listClinicNums.Exists(x => listSelectedClinicNums.Contains(x))) { continue; //The ClinicNums associated to the 835 do not match any of the selected ClinicNums, so nothing to show in this 835. } #endregion #region Filter: Check and Trace Value if (checkTraceNum != "" && !x835.TransRefNum.Contains(checkTraceNum)) //Trace Number does not match { continue; } #endregion #region Filter: Insurance Check Range Min and Max if (amountMin != "" && x835.InsPaid < PIn.Decimal(amountMin) || amountMax != "" && x835.InsPaid > PIn.Decimal(amountMax)) { continue; //Either the InsPaid is below or above our range. } #endregion ODGridRow row = new ODGridRow(); #region Column: Patient Name List <string> listPatNames = x835.ListClaimsPaid.Select(x => x.PatientName.ToString()).Distinct().ToList(); string patName = (listPatNames.Count > 0 ? listPatNames[0] : ""); if (listPatNames.Count > 1) { patName = "(" + POut.Long(listPatNames.Count) + ")"; } row.Cells.Add(patName); #endregion row.Cells.Add(x835.PayerName); row.Cells.Add(status); //See GetStringStatus(...) for possible values. row.Cells.Add(POut.Date(etrans.DateTimeTrans)); row.Cells.Add(POut.Decimal(x835.InsPaid)); #region Column: Clinic if (PrefC.HasClinicsEnabled) { string clinicAbbr = ""; if (listClinicNums.Count == 1) { if (listClinicNums[0] == 0) { clinicAbbr = Lan.g(this, "Unassigned"); } else { clinicAbbr = Clinics.GetAbbr(listClinicNums[0]); } } else if (listClinicNums.Count > 1) { clinicAbbr = "(" + Lan.g(this, "Multiple") + ")"; } row.Cells.Add(clinicAbbr); } #endregion row.Cells.Add(x835._paymentMethodCode); row.Cells.Add(etrans.Note); row.Tag = etrans; gridMain.Rows.Add(row); } gridMain.EndUpdate(); actionCloseProgress?.Invoke(); }
private void butOK_Click(object sender, System.EventArgs e) { int payPlanVersion = PrefC.GetInt(PrefName.PayPlansVersion); string bDate; string eDate; decimal rcvStart = 0; decimal rcvCharge = 0; decimal rcvPayPlanCredit = 0; decimal rcvProd = 0; decimal rcvPayPlanCharges = 0; decimal rcvAdj = 0; decimal rcvWriteoff = 0; decimal rcvPayment = 0; decimal rcvInsPayment = 0; decimal runningRcv = 0; decimal rcvDaily = 0; decimal[] colTotals = new decimal[11]; string wMonth; string wYear; string wDay = "01"; string wDate; // Get the year / month and instert the 1st of the month for stop point for calculated running balance wYear = date1.SelectionStart.Year.ToString(); wMonth = date1.SelectionStart.Month.ToString(); if (wMonth.Length < 2) { wMonth = "0" + wMonth; } wDate = wYear + "-" + wMonth + "-" + wDay; List <long> listProvNums = new List <long>(); bool hasAllProvs = (listProv.SelectedIndices[0] == 0); if (!hasAllProvs) { for (int i = 0; i < listProv.SelectedIndices.Count; i++) { //Minus 1 due to the 'Practice' option. listProvNums.Add(_listProvs[listProv.SelectedIndices[i] - 1].ProvNum); } } bool isPayPlan2; if (payPlanVersion == 2) { isPayPlan2 = true; } else { isPayPlan2 = false; } ReportComplex report = new ReportComplex(true, isPayPlan2); //Landscape if using PayPlan Version 2 DataTable TableProduction = new DataTable(); //Production DataTable TablePayPlanCredit = new DataTable(); //PayPlanCredits DataTable TableCharge = new DataTable(); //charges(Production-PayPlanCredits) DataTable TablePayPlanCharge = new DataTable(); //PayPlanCharges DataTable TableCapWriteoff = new DataTable(); //capComplete writeoffs DataTable TableInsWriteoff = new DataTable(); //ins writeoffs DataTable TablePay = new DataTable(); //payments - Patient DataTable TableIns = new DataTable(); //payments - Ins, added SPK DataTable TableAdj = new DataTable(); //adjustments // // Main Loop: This will loop twice 1st loop gets running balance to start of month selected // 2nd will break the numbers down by day and calculate the running balances // for (int j = 0; j <= 1; j++) { if (j == 0) { bDate = "0001-01-01"; eDate = wDate; } else { bDate = wDate; eDate = POut.Date(date1.SelectionStart.AddDays(1)).Substring(1, 10); // Needed because all Queries are < end date to get correct Starting AR } TableProduction = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TableProduction"); if (isPayPlan2) { TablePayPlanCredit = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TablePayPlanCredit"); TableCharge = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TableCharge"); TablePayPlanCharge = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TablePayPlanCharge"); } TableCapWriteoff = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TableCapWriteoff"); TableInsWriteoff = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TableInsWriteoff"); TablePay = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TablePay"); TableIns = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TableIns"); TableAdj = RpReceivablesBreakdown.GetRecvBreakdownTable(date1.SelectionStart, listProvNums, radioWriteoffPay.Checked, isPayPlan2, wDate, eDate, bDate, "TableAdj"); //Sum up all the transactions grouped by date. Dictionary <DateTime, decimal> dictPayPlanCharges = TablePayPlanCharge.Select().GroupBy(x => PIn.Date(x["ChargeDate"].ToString())) .ToDictionary(y => y.Key, y => y.ToList().Sum(z => PIn.Decimal(z["Amt"].ToString()))); //1st Loop Calculate running Accounts Receivable upto the 1st of the Month Selected //2nd Loop Calculate the Daily Accounts Receivable upto the Date Selected //Finaly Generate Report showing the breakdown upto the date specified with totals for what is on the report if (j == 0) { for (int k = 0; k < TableCharge.Rows.Count; k++) { rcvCharge += PIn.Decimal(TableCharge.Rows[k][1].ToString()); //Production-PayPlanCredits } rcvPayPlanCharges += dictPayPlanCharges.Sum(x => x.Value); for (int k = 0; k < TableCapWriteoff.Rows.Count; k++) { rcvWriteoff += PIn.Decimal(TableCapWriteoff.Rows[k][1].ToString()); } for (int k = 0; k < TableInsWriteoff.Rows.Count; k++) { rcvWriteoff += PIn.Decimal(TableInsWriteoff.Rows[k][1].ToString()); } for (int k = 0; k < TablePay.Rows.Count; k++) { rcvPayment += PIn.Decimal(TablePay.Rows[k][1].ToString()); } for (int k = 0; k < TableIns.Rows.Count; k++) { rcvInsPayment += PIn.Decimal(TableIns.Rows[k][1].ToString()); } for (int k = 0; k < TableAdj.Rows.Count; k++) { rcvAdj += PIn.Decimal(TableAdj.Rows[k][1].ToString()); } for (int k = 0; k < TableProduction.Rows.Count; k++) { rcvProd += PIn.Decimal(TableProduction.Rows[k][1].ToString()); } for (int k = 0; k < TablePayPlanCredit.Rows.Count; k++) { rcvPayPlanCredit += PIn.Decimal(TablePayPlanCredit.Rows[k][1].ToString()); } TableProduction.Clear(); TablePayPlanCredit.Clear(); TableCharge.Clear(); TablePayPlanCharge.Clear(); TableCapWriteoff.Clear(); TableInsWriteoff.Clear(); TablePay.Clear(); TableIns.Clear(); TableAdj.Clear(); rcvStart = (rcvProd - rcvPayPlanCredit + rcvPayPlanCharges + rcvAdj - rcvWriteoff) - (rcvPayment + rcvInsPayment); } else { rcvCharge = 0; rcvPayPlanCredit = 0; rcvAdj = 0; rcvInsPayment = 0; rcvPayment = 0; rcvProd = 0; rcvPayPlanCharges = 0; rcvWriteoff = 0; rcvDaily = 0; runningRcv = rcvStart; DataTable TableQ = new DataTable(); TableQ.Columns.Add("Date"); TableQ.Columns.Add("Production"); TableQ.Columns.Add("PayPlanCredits"); TableQ.Columns.Add("Charges"); TableQ.Columns.Add("PayPlanCharges"); TableQ.Columns.Add("Adjustments"); TableQ.Columns.Add("Writeoffs"); TableQ.Columns.Add("Payment"); TableQ.Columns.Add("InsPayment"); TableQ.Columns.Add("Daily"); TableQ.Columns.Add("Running"); eDate = POut.Date(date1.SelectionStart).Substring(1, 10); // Reset EndDate to Selected Date DateTime[] dates = new DateTime[(PIn.Date(eDate) - PIn.Date(bDate)).Days + 1]; for (int i = 0; i < dates.Length; i++) //usually 31 days in loop { dates[i] = PIn.Date(bDate).AddDays(i); //create new row called 'row' based on structure of TableQ DataRow row = TableQ.NewRow(); row[0] = dates[i].ToShortDateString(); for (int k = 0; k < TableProduction.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableProduction.Rows[k][0].ToString()))) { rcvProd += PIn.Decimal(TableProduction.Rows[k][1].ToString()); } } for (int k = 0; k < TablePayPlanCredit.Rows.Count; k++) { if (dates[i] == (PIn.Date(TablePayPlanCredit.Rows[k][0].ToString()))) { rcvPayPlanCredit += PIn.Decimal(TablePayPlanCredit.Rows[k][1].ToString()); } } for (int k = 0; k < TableCharge.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableCharge.Rows[k][0].ToString()))) { rcvCharge += PIn.Decimal(TableCharge.Rows[k][1].ToString()); } } decimal rcvPayPlanChargesForDay = 0; if (dictPayPlanCharges.TryGetValue(dates[i], out rcvPayPlanChargesForDay)) { rcvPayPlanCharges += rcvPayPlanChargesForDay; } for (int k = 0; k < TableCapWriteoff.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableCapWriteoff.Rows[k][0].ToString()))) { rcvWriteoff += PIn.Decimal(TableCapWriteoff.Rows[k][1].ToString()); } } for (int k = 0; k < TableAdj.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableAdj.Rows[k][0].ToString()))) { rcvAdj += PIn.Decimal(TableAdj.Rows[k][1].ToString()); } } for (int k = 0; k < TableInsWriteoff.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableInsWriteoff.Rows[k][0].ToString()))) { rcvWriteoff += PIn.Decimal(TableInsWriteoff.Rows[k][1].ToString()); } } for (int k = 0; k < TablePay.Rows.Count; k++) { if (dates[i] == (PIn.Date(TablePay.Rows[k][0].ToString()))) { rcvPayment += PIn.Decimal(TablePay.Rows[k][1].ToString()); } } for (int k = 0; k < TableIns.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableIns.Rows[k][0].ToString()))) { rcvInsPayment += PIn.Decimal(TableIns.Rows[k][1].ToString()); } } //rcvPayPlanCharges and rcvPayPlanCredit will be 0 if not on version 2. rcvDaily = (rcvProd - rcvPayPlanCredit + rcvPayPlanCharges + rcvAdj - rcvWriteoff) - (rcvPayment + rcvInsPayment); runningRcv += (rcvProd - rcvPayPlanCredit + rcvPayPlanCharges + rcvAdj - rcvWriteoff) - (rcvPayment + rcvInsPayment); row["Production"] = rcvProd.ToString("n"); row["PayPlanCredits"] = rcvPayPlanCredit.ToString("n"); row["Charges"] = rcvCharge.ToString("n"); row["PayPlanCharges"] = rcvPayPlanCharges.ToString("n"); row["Adjustments"] = rcvAdj.ToString("n"); row["Writeoffs"] = rcvWriteoff.ToString("n"); row["Payment"] = rcvPayment.ToString("n"); row["InsPayment"] = rcvInsPayment.ToString("n"); row["Daily"] = rcvDaily.ToString("n"); row["Running"] = runningRcv.ToString("n"); colTotals[1] += rcvProd; colTotals[2] += rcvPayPlanCredit; colTotals[3] += rcvCharge; colTotals[4] += rcvPayPlanCharges; colTotals[5] += rcvAdj; colTotals[6] += rcvWriteoff; colTotals[7] += rcvPayment; colTotals[8] += rcvInsPayment; colTotals[9] += rcvDaily; colTotals[10] = runningRcv; TableQ.Rows.Add(row); //adds row to table Q rcvAdj = 0; rcvInsPayment = 0; rcvPayment = 0; rcvProd = 0; rcvPayPlanCharges = 0; rcvWriteoff = 0; rcvCharge = 0; rcvPayPlanCredit = 0; } //Drop the PayPlan columns if not version 2 if (!isPayPlan2) { TableQ.Columns.RemoveAt(2); //PayPlanCredits TableQ.Columns.RemoveAt(2); //Production - PayPlanCredits TableQ.Columns.RemoveAt(2); //PayPlanCharges } ////columnCount will get incremented on the second ColTotal call so we can use it in this way //if(payPlanVersion==2) { // report.ColTotal[1]=PIn.Decimal(colTotals[1].ToString("n")); //prod // report.ColTotal[2]=PIn.Decimal(colTotals[2].ToString("n")); //payplancharges // report.ColTotal[3]=PIn.Decimal(colTotals[3].ToString("n")); //adjustment // report.ColTotal[4]=PIn.Decimal(colTotals[4].ToString("n")); //writeoffs // report.ColTotal[5]=PIn.Decimal(colTotals[5].ToString("n")); //payment // report.ColTotal[6]=PIn.Decimal(colTotals[6].ToString("n")); //inspayment // report.ColTotal[7]=PIn.Decimal(colTotals[7].ToString("n")); //daily // report.ColTotal[8]=PIn.Decimal(colTotals[8].ToString("n")); //running //} //else { // report.ColTotal[1]=PIn.Decimal(colTotals[1].ToString("n")); //prod // report.ColTotal[2]=PIn.Decimal(colTotals[3].ToString("n")); //adjustment // report.ColTotal[3]=PIn.Decimal(colTotals[4].ToString("n")); //writeoffs // report.ColTotal[4]=PIn.Decimal(colTotals[5].ToString("n")); //payment // report.ColTotal[5]=PIn.Decimal(colTotals[6].ToString("n")); //inspayment // report.ColTotal[6]=PIn.Decimal(colTotals[7].ToString("n")); //daily // report.ColTotal[7]=PIn.Decimal(colTotals[8].ToString("n")); //running //} Font font = new Font("Tahoma", 9); Font boldFont = new Font("Tahoma", 9, FontStyle.Bold); Font fontTitle = new Font("Tahoma", 17, FontStyle.Bold); Font fontSubTitle = new Font("Tahoma", 10, FontStyle.Bold); report.ReportName = Lan.g(this, "Receivables Breakdown"); report.AddTitle("Title", Lan.g(this, "Receivables Breakdown"), fontTitle); report.AddSubTitle("PracticeTitle", PrefC.GetString(PrefName.PracticeTitle), fontSubTitle); report.AddSubTitle("Date SubTitle", date1.SelectionStart.ToString("d"), fontSubTitle); string provNames = ""; for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (hasAllProvs) { provNames = "All Providers"; break; } if (i > 0) { provNames += ", "; } provNames += _listProvs[listProv.SelectedIndices[i] - 1].Abbr; } report.AddSubTitle("Provider SubTitle", provNames); int[] summaryGroups1 = { 1 }; QueryObject query = report.AddQuery(TableQ, Lan.g(this, "Date") + ": " + DateTimeOD.Today.ToString("d")); query.AddColumn("Date", 72, FieldValueType.Date); query.AddColumn("Production", 80, FieldValueType.Number); query.GetColumnDetail("Production").ContentAlignment = ContentAlignment.MiddleRight; if (isPayPlan2) { query.AddColumn("PayPlanCredits", 90, FieldValueType.Number); query.GetColumnDetail("PayPlanCredits").ContentAlignment = ContentAlignment.MiddleRight; query.AddColumn("Prod - PPCred", 85, FieldValueType.Number); query.GetColumnDetail("Prod - PPCred").ContentAlignment = ContentAlignment.MiddleRight; query.AddColumn("PayPlanCharges", 100, FieldValueType.Number); query.GetColumnDetail("PayPlanCharges").ContentAlignment = ContentAlignment.MiddleRight; } query.AddColumn("Adjustment", 80, FieldValueType.Number); query.GetColumnDetail("Adjustment").ContentAlignment = ContentAlignment.MiddleRight; query.AddColumn("Writeoff", 80, FieldValueType.Number); query.GetColumnDetail("Writeoff").ContentAlignment = ContentAlignment.MiddleRight; query.AddColumn("Payment", 80, FieldValueType.Number); query.GetColumnDetail("Payment").ContentAlignment = ContentAlignment.MiddleRight; query.AddColumn("InsPayment", 80, FieldValueType.Number); query.GetColumnDetail("InsPayment").ContentAlignment = ContentAlignment.MiddleRight; query.AddColumn("Daily A/R", 100, FieldValueType.Number); query.GetColumnDetail("Daily A/R").ContentAlignment = ContentAlignment.MiddleRight; query.AddColumn("Ending A/R", 100); query.GetColumnDetail("Ending A/R").ContentAlignment = ContentAlignment.MiddleRight; query.GetColumnDetail("Ending A/R").Font = boldFont; if (isPayPlan2) { report.AddFooterText("Desc", "Receivables Calculation: (Production - PayPlanCredits + PayPlanCharges + Adjustments - Writeoffs) " + "- (Payments + Insurance Payments)", font, 0, ContentAlignment.MiddleCenter); } else { report.AddFooterText("Desc", "Receivables Calculation: (Production + Adjustments - Writeoffs) - (Payments + Insurance Payments)", font, 0, ContentAlignment.MiddleCenter); } //report.AddText("EndingAR","Final Ending A/R: "+runningRcv.ToString(),boldFont,0,ContentAlignment.MiddleLeft); report.AddPageNum(font); if (!report.SubmitQueries()) { return; } FormReportComplex FormR = new FormReportComplex(report); FormR.ShowDialog(); DialogResult = DialogResult.OK; } //END If } // END For Loop } //END OK button Clicked
private void butOK_Click(object sender, System.EventArgs e) { long feeSched = FeeSchedC.ListShort[listFeeSched.SelectedIndex].FeeSchedNum; string catName = ""; //string to hold current category name Fees fee = new Fees(); ReportSimpleGrid report = new ReportSimpleGrid(); report.Query = "SELECT procedurecode.ProcCode,fee.Amount,' ',procedurecode.Descript," + "procedurecode.AbbrDesc FROM procedurecode,fee " + "WHERE procedurecode.CodeNum=fee.CodeNum AND fee.FeeSched='" + feeSched.ToString() + "' ORDER BY procedurecode.ProcCode"; FormQuery2 = new FormQuery(report); FormQuery2.IsReport = true; if (radioCode.Checked == true) { FormQuery2.SubmitReportQuery(); report.Title = "Procedure Codes"; report.SubTitle.Add(PrefC.GetString(PrefName.PracticeTitle)); report.SubTitle.Add(FeeScheds.GetDescription(feeSched)); report.SetColumn(this, 0, "Code", 70); report.SetColumn(this, 1, "Fee Amount", 70, HorizontalAlignment.Right); report.SetColumn(this, 2, " ", 80); //otherwise, the amount gets bunched up next to the description. report.SetColumn(this, 3, "Description", 200); report.SetColumn(this, 4, "Abbr Description", 200); FormQuery2.ShowDialog(); DialogResult = DialogResult.OK; } else //categories //report.SubmitTemp();//create TableTemp which is not actually used { ProcedureCode[] ProcList = ProcedureCodes.GetProcList(); report.TableQ = new DataTable(null); for (int i = 0; i < 5; i++) //add columns { report.TableQ.Columns.Add(new System.Data.DataColumn()); //blank columns } report.InitializeColumns(); DataRow row = report.TableQ.NewRow();//add first row by hand to get value for temp row[0] = DefC.GetName(DefCat.ProcCodeCats, ProcList[0].ProcCat); catName = row[0].ToString(); row[1] = ProcList[0].ProcCode; row[2] = ProcList[0].Descript; row[3] = ProcList[0].AbbrDesc; row[4] = ((double)Fees.GetAmount0(ProcList[0].CodeNum, feeSched)).ToString("F"); report.ColTotal[4] += PIn.Decimal(row[4].ToString()); report.TableQ.Rows.Add(row); for (int i = 1; i < ProcList.Length; i++) //loop through data rows { row = report.TableQ.NewRow(); //create new row called 'row' based on structure of TableQ row[0] = DefC.GetName(DefCat.ProcCodeCats, ProcList[i].ProcCat); if (catName == row[0].ToString()) { row[0] = ""; } else { catName = row[0].ToString(); } row[1] = ProcList[i].ProcCode.ToString(); row[2] = ProcList[i].Descript; row[3] = ProcList[i].AbbrDesc.ToString(); row[4] = ((double)Fees.GetAmount0(ProcList[i].CodeNum, feeSched)).ToString("F"); //report.ColTotal[4]+=PIn.PDouble(row[4].ToString()); report.TableQ.Rows.Add(row); } FormQuery2.ResetGrid(); //this is a method in FormQuery2; report.Title = "Procedure Codes"; report.SubTitle.Add(PrefC.GetString(PrefName.PracticeTitle)); report.SubTitle.Add(FeeScheds.GetDescription(feeSched)); report.ColPos[0] = 20; report.ColPos[1] = 120; report.ColPos[2] = 270; report.ColPos[3] = 470; report.ColPos[4] = 620; report.ColPos[5] = 770; report.ColCaption[0] = "Category"; report.ColCaption[1] = "Code"; report.ColCaption[2] = "Description"; report.ColCaption[3] = "Abbr Description"; report.ColCaption[4] = "Fee Amount"; report.ColAlign[4] = HorizontalAlignment.Right; FormQuery2.ShowDialog(); DialogResult = DialogResult.OK; } }
private void butOK_Click(object sender, System.EventArgs e) { string bDate; string eDate; decimal rcvStart = 0; decimal rcvProd = 0; decimal rcvAdj = 0; decimal rcvWriteoff = 0; decimal rcvPayment = 0; decimal rcvInsPayment = 0; decimal runningRcv = 0; decimal rcvDaily = 0; decimal[] ColTotal = new decimal[8]; string wMonth; string wYear; string wDay = "01"; string wDate; // Get the year / month and instert the 1st of the month for stop point for calculated running balance wYear = date1.SelectionStart.Year.ToString(); wMonth = date1.SelectionStart.Month.ToString(); if (wMonth.Length < 2) { wMonth = "0" + wMonth; } wDate = wYear + "-" + wMonth + "-" + wDay; ReportSimpleGrid report = new ReportSimpleGrid(); // // Create temperary tables for sorting data // DataTable TableCharge = new DataTable(); //charges DataTable TableCapWriteoff = new DataTable(); //capComplete writeoffs DataTable TableInsWriteoff = new DataTable(); //ins writeoffs DataTable TablePay = new DataTable(); //payments - Patient DataTable TableIns = new DataTable(); //payments - Ins, added SPK DataTable TableAdj = new DataTable(); //adjustments // // Main Loop: This will loop twice 1st loop gets running balance to start of month selected // 2nd will break the numbers dow by day and calculate the running balances // for (int j = 0; j <= 1; j++) { if (j == 0) { bDate = "0001-01-01"; eDate = wDate; } else { bDate = wDate; eDate = POut.Date(date1.SelectionStart.AddDays(1)).Substring(1, 10); // Needed because all Queries are < end date to get correct Starting AR } string whereProv; //used as the provider portion of the where clauses. //each whereProv needs to be set up separately for each query string whereProvx; //Extended for more than 4 names whereProv = ""; if (listProv.SelectedIndices[0] != 0) { for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i == 0) { whereProv += " AND ("; } else { whereProv += "OR "; } whereProv += "procedurelog.ProvNum = " + POut.Long(ProviderC.ListShort[listProv.SelectedIndices[i] - 1].ProvNum) + " "; } whereProv += ") "; } report.Query = "SELECT procedurelog.ProcDate, " + "SUM(procedurelog.ProcFee*(CASE procedurelog.UnitQty+procedurelog.BaseUnits WHEN 0 THEN 1 ELSE procedurelog.UnitQty+procedurelog.BaseUnits END)) " + "FROM procedurelog " + "WHERE procedurelog.ProcDate >= '" + bDate + "' " + "AND procedurelog.ProcDate < '" + eDate + "' " + "AND procedurelog.ProcStatus = '2' " + whereProv + "GROUP BY procedurelog.ProcDate " + "ORDER BY procedurelog.ProcDate"; TableCharge = report.GetTempTable(); whereProv = ""; if (listProv.SelectedIndices[0] != 0) { for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i == 0) { whereProv += " AND ("; } else { whereProv += "OR "; } whereProv += "claimproc.ProvNum = " + POut.Long(ProviderC.ListShort[listProv.SelectedIndices[i] - 1].ProvNum) + " "; } whereProv += ") "; } if (radioWriteoffPay.Checked) { report.Query = "SELECT DateCP, " + "SUM(WriteOff) FROM claimproc WHERE " + "DateCP >= '" + bDate + "' " + "AND DateCP < '" + eDate + "' " + "AND Status = '7' "//CapComplete + whereProv + " GROUP BY DateCP " + "ORDER BY DateCP"; } else { report.Query = "SELECT ProcDate, " + "SUM(WriteOff) FROM claimproc WHERE " + "ProcDate >= '" + bDate + "' " + "AND ProcDate < '" + eDate + "' " + "AND Status = '7' "//CapComplete + whereProv + " GROUP BY ProcDate " + "ORDER BY ProcDate"; } TableCapWriteoff = report.GetTempTable(); whereProv = ""; if (listProv.SelectedIndices[0] != 0) { for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i == 0) { whereProv += " AND ("; } else { whereProv += "OR "; } whereProv += "ProvNum = " + POut.Long(ProviderC.ListShort[listProv.SelectedIndices[i] - 1].ProvNum) + " "; } whereProv += ") "; } if (radioWriteoffPay.Checked) { report.Query = "SELECT DateCP, " + "SUM(WriteOff) FROM claimproc WHERE " + "DateCP >= '" + bDate + "' " + "AND DateCP < '" + eDate + "' " + "AND Status IN (1,4,5) "//Recieved, supplemental, capclaim. Otherwise, it's only an estimate. 7-CapCompl handled above. + whereProv + " GROUP BY DateCP " + "ORDER BY DateCP"; } else { report.Query = "SELECT ProcDate, " + "SUM(WriteOff) FROM claimproc WHERE " + "ProcDate >= '" + bDate + "' " + "AND ProcDate < '" + eDate + "' " + "AND Status IN (0,1,4,5) " //Notreceived, received, supplemental, capclaim. 7-CapCompl handled above. + whereProv + " GROUP BY ProcDate " + "ORDER BY ProcDate"; } TableInsWriteoff = report.GetTempTable(); whereProv = ""; if (listProv.SelectedIndices[0] != 0) { for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i == 0) { whereProv += " AND ("; } else { whereProv += "OR "; } whereProv += "paysplit.ProvNum = " + POut.Long(ProviderC.ListShort[listProv.SelectedIndices[i] - 1].ProvNum) + " "; } whereProv += ") "; } report.Query = "SELECT paysplit.DatePay,SUM(paysplit.splitamt) FROM paysplit " + "WHERE paysplit.PayPlanNum=0 " + "AND paysplit.DatePay >= '" + bDate + "' " + "AND paysplit.DatePay < '" + eDate + "' " + whereProv + " GROUP BY paysplit.DatePay ORDER BY DatePay"; TablePay = report.GetTempTable(); whereProv = ""; if (listProv.SelectedIndices[0] != 0) { for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i == 0) { whereProv += " AND ("; } else { whereProv += "OR "; } whereProv += "claimproc.ProvNum = " + POut.Long(ProviderC.ListShort[listProv.SelectedIndices[i] - 1].ProvNum) + " "; } whereProv += ") "; } report.Query = "SELECT DateCP,SUM(InsPayamt) " + "FROM claimproc WHERE " + "Status IN (1,4,5,7) "//Received, supplemental, capclaim, capcomplete. + "AND DateCP >= '" + bDate + "' " + "AND DateCP < '" + eDate + "' " + whereProv + " GROUP BY DateCP ORDER BY DateCP"; TableIns = report.GetTempTable(); whereProv = ""; if (listProv.SelectedIndices[0] != 0) { for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i == 0) { whereProv += " AND ("; } else { whereProv += "OR "; } whereProv += "ProvNum = " + POut.Long(ProviderC.ListShort[listProv.SelectedIndices[i] - 1].ProvNum) + " "; } whereProv += ") "; } report.Query = "SELECT adjdate, SUM(adjamt) FROM adjustment WHERE " + "adjdate >= '" + bDate + "' " + "AND adjdate < '" + eDate + "' " + whereProv + " GROUP BY adjdate ORDER BY adjdate"; TableAdj = report.GetTempTable(); //1st Loop Calculate running Accounts Receivable upto the 1st of the Month Selected //2nd Loop Calculate the Daily Accounts Receivable upto the Date Selected //Finaly Generate Report showing the breakdown upto the date specified with totals for what is on the report if (j == 0) { for (int k = 0; k < TableCharge.Rows.Count; k++) { rcvProd += PIn.Decimal(TableCharge.Rows[k][1].ToString()); } for (int k = 0; k < TableCapWriteoff.Rows.Count; k++) { rcvWriteoff += PIn.Decimal(TableCapWriteoff.Rows[k][1].ToString()); } for (int k = 0; k < TableInsWriteoff.Rows.Count; k++) { rcvWriteoff += PIn.Decimal(TableInsWriteoff.Rows[k][1].ToString()); } for (int k = 0; k < TablePay.Rows.Count; k++) { rcvPayment += PIn.Decimal(TablePay.Rows[k][1].ToString()); } for (int k = 0; k < TableIns.Rows.Count; k++) { rcvInsPayment += PIn.Decimal(TableIns.Rows[k][1].ToString()); } for (int k = 0; k < TableAdj.Rows.Count; k++) { rcvAdj += PIn.Decimal(TableAdj.Rows[k][1].ToString()); } TableCharge.Clear(); TableCapWriteoff.Clear(); TableInsWriteoff.Clear(); TablePay.Clear(); TableIns.Clear(); TableAdj.Clear(); rcvStart = (rcvProd + rcvAdj - rcvWriteoff) - (rcvPayment + rcvInsPayment); } else { rcvAdj = 0; rcvInsPayment = 0; rcvPayment = 0; rcvProd = 0; rcvWriteoff = 0; rcvDaily = 0; runningRcv = rcvStart; report.TableQ = new DataTable(null); //new table with 7 columns for (int l = 0; l < 8; l++) //add columns { report.TableQ.Columns.Add(new System.Data.DataColumn()); //blank columns } report.InitializeColumns(); eDate = POut.Date(date1.SelectionStart).Substring(1, 10); // Reset EndDate to Selected Date DateTime[] dates = new DateTime[(PIn.Date(eDate) - PIn.Date(bDate)).Days + 1]; for (int i = 0; i < dates.Length; i++) //usually 31 days in loop { dates[i] = PIn.Date(bDate).AddDays(i); //create new row called 'row' based on structure of TableQ DataRow row = report.TableQ.NewRow(); row[0] = dates[i].ToShortDateString(); for (int k = 0; k < TableCharge.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableCharge.Rows[k][0].ToString()))) { rcvProd += PIn.Decimal(TableCharge.Rows[k][1].ToString()); } } for (int k = 0; k < TableCapWriteoff.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableCapWriteoff.Rows[k][0].ToString()))) { rcvWriteoff += PIn.Decimal(TableCapWriteoff.Rows[k][1].ToString()); } } for (int k = 0; k < TableAdj.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableAdj.Rows[k][0].ToString()))) { rcvAdj += PIn.Decimal(TableAdj.Rows[k][1].ToString()); } } for (int k = 0; k < TableInsWriteoff.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableInsWriteoff.Rows[k][0].ToString()))) { rcvWriteoff += PIn.Decimal(TableInsWriteoff.Rows[k][1].ToString()); } } for (int k = 0; k < TablePay.Rows.Count; k++) { if (dates[i] == (PIn.Date(TablePay.Rows[k][0].ToString()))) { rcvPayment += PIn.Decimal(TablePay.Rows[k][1].ToString()); } } for (int k = 0; k < TableIns.Rows.Count; k++) { if (dates[i] == (PIn.Date(TableIns.Rows[k][0].ToString()))) { rcvInsPayment += PIn.Decimal(TableIns.Rows[k][1].ToString()); } } rcvDaily = (rcvProd + rcvAdj - rcvWriteoff) - (rcvPayment + rcvInsPayment); runningRcv += (rcvProd + rcvAdj - rcvWriteoff) - (rcvPayment + rcvInsPayment); row[1] = rcvProd.ToString("n"); row[2] = rcvAdj.ToString("n"); row[3] = rcvWriteoff.ToString("n"); row[4] = rcvPayment.ToString("n"); row[5] = rcvInsPayment.ToString("n"); row[6] = rcvDaily.ToString("n"); row[7] = runningRcv.ToString("n"); ColTotal[1] += rcvProd; ColTotal[2] += rcvAdj; ColTotal[3] += rcvWriteoff; ColTotal[4] += rcvPayment; ColTotal[5] += rcvInsPayment; ColTotal[6] += rcvDaily; ColTotal[7] = runningRcv; report.TableQ.Rows.Add(row); //adds row to table Q rcvAdj = 0; rcvInsPayment = 0; rcvPayment = 0; rcvProd = 0; rcvWriteoff = 0; } report.ColTotal[1] = PIn.Decimal(ColTotal[1].ToString("n")); report.ColTotal[2] = PIn.Decimal(ColTotal[2].ToString("n")); report.ColTotal[3] = PIn.Decimal(ColTotal[3].ToString("n")); report.ColTotal[4] = PIn.Decimal(ColTotal[4].ToString("n")); report.ColTotal[5] = PIn.Decimal(ColTotal[5].ToString("n")); report.ColTotal[6] = PIn.Decimal(ColTotal[6].ToString("n")); report.ColTotal[7] = PIn.Decimal(ColTotal[7].ToString("n")); FormQuery2 = new FormQuery(report); FormQuery2.IsReport = true; FormQuery2.ResetGrid(); report.Title = "Receivables Breakdown Report"; report.SubTitle.Add(PrefC.GetString(PrefName.PracticeTitle)); whereProv = "Report for: Practice"; whereProvx = ""; if (listProv.SelectedIndices[0] != 0) { int nameCount = 0; whereProv = "Report Includes: "; for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (nameCount < 3) { whereProv += " " + ProviderC.ListShort[listProv.SelectedIndices[i] - 1].GetFormalName() + " /"; } else { whereProvx += " " + ProviderC.ListShort[listProv.SelectedIndices[i] - 1].GetFormalName() + " /"; } nameCount += 1; } whereProv = whereProv.Substring(0, whereProv.Length - 1); if (whereProvx.Length > 0) { whereProvx = whereProvx.Substring(0, whereProvx.Length - 1); } } report.SubTitle.Add(whereProv); report.SubTitle.Add(whereProvx); report.SetColumnPos(this, 0, "Day", 80); report.SetColumnPos(this, 1, "Production", 160, HorizontalAlignment.Right); report.SetColumnPos(this, 2, "Adjustment", 260, HorizontalAlignment.Right); report.SetColumnPos(this, 3, "Writeoff", 360, HorizontalAlignment.Right); report.SetColumnPos(this, 4, "Payment", 470, HorizontalAlignment.Right); report.SetColumnPos(this, 5, "InsPayment", 570, HorizontalAlignment.Right); report.SetColumnPos(this, 6, "Daily A/R", 680, HorizontalAlignment.Right); report.SetColumnPos(this, 7, "Ending A/R", 779, HorizontalAlignment.Right); report.Summary.Add( Lan.g(this, "Receivables Calculation: (Production + Adjustments - Writeoffs) - (Payments + Insurance Payments)")); FormQuery2.ShowDialog(); DialogResult = DialogResult.OK; } //END If } // END For Loop } //END OK button Clicked
private void butOK_Click(object sender, System.EventArgs e) { if (!checkAllProv.Checked && listProv.SelectedIndices.Count == 0) { MsgBox.Show(this, "At least one provider must be selected."); return; } if (!PrefC.GetBool(PrefName.EasyNoClinics)) { if (!checkAllClin.Checked && listClin.SelectedIndices.Count == 0) { MsgBox.Show(this, "At least one clinic must be selected."); return; } } if (listType.SelectedIndices.Count == 0) { MsgBox.Show(this, "At least one type must be selected."); return; } string whereProv = ""; if (!checkAllProv.Checked) { for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i == 0) { whereProv += " AND ("; } else { whereProv += "OR "; } whereProv += "adjustment.ProvNum = " + POut.Long(ProviderC.ListShort[listProv.SelectedIndices[i]].ProvNum) + " "; } whereProv += ") "; } string whereClin = ""; if (!checkAllClin.Checked) { for (int i = 0; i < listClin.SelectedIndices.Count; i++) { if (i == 0) { whereClin += " AND ("; } else { whereClin += "OR "; } if (listClin.SelectedIndices[i] == 0) { whereClin += "adjustment.ClinicNum = 0 "; } else { whereClin += "adjustment.ClinicNum = " + POut.Long(Clinics.List[listClin.SelectedIndices[i] - 1].ClinicNum) + " "; } } whereClin += ") "; } string whereType = "("; for (int i = 0; i < listType.SelectedIndices.Count; i++) { if (i > 0) { whereType += "OR "; } whereType += "adjustment.AdjType = '" + POut.Long(DefC.Short[(int)DefCat.AdjTypes][listType.SelectedIndices[i]].DefNum) + "' "; } whereType += ")"; ReportSimpleGrid report = new ReportSimpleGrid(); report.Query = "SELECT adjustment.AdjDate," + DbHelper.Concat("patient.LName", "', '", "patient.FName", "', '", "patient.MiddleI") + "," + "adjustment.ProvNum,adjustment.ClinicNum," + "definition.ItemName,adjustment.AdjNote,adjustment.AdjAmt FROM " + "adjustment,patient,definition WHERE adjustment.AdjType=definition.DefNum " + "AND patient.PatNum=adjustment.PatNum " + whereProv + whereClin + "AND " + whereType + " " + "AND adjustment.AdjDate >= " + POut.Date(date1.SelectionStart) + " " + "AND adjustment.AdjDate <= " + POut.Date(date2.SelectionStart); report.Query += " ORDER BY adjustment.AdjDate"; FormQuery2 = new FormQuery(report); FormQuery2.IsReport = true; DataTable table = report.GetTempTable(); report.TableQ = new DataTable(null); int colI = 6; if (!PrefC.GetBool(PrefName.EasyNoClinics)) { colI = 7; } for (int i = 0; i < colI; i++) //add columns { report.TableQ.Columns.Add(new System.Data.DataColumn()); //blank columns } report.InitializeColumns(); DataRow row; decimal dec; for (int i = 0; i < table.Rows.Count; i++) { row = report.TableQ.NewRow(); //create new row called 'row' based on structure of TableQ row[0] = PIn.Date(table.Rows[i][0].ToString()).ToShortDateString(); row[1] = table.Rows[i][1].ToString(); //name row[2] = Providers.GetAbbr(PIn.Long(table.Rows[i][2].ToString())); //prov colI = 3; if (!PrefC.GetBool(PrefName.EasyNoClinics)) { row[colI] = Clinics.GetDesc(PIn.Long(table.Rows[i][3].ToString())); //clinic colI++; } row[colI] = table.Rows[i][4].ToString(); //Type colI++; row[colI] = table.Rows[i][5].ToString(); //Note colI++; dec = PIn.Decimal(table.Rows[i][6].ToString()); //Amount row[colI] = dec.ToString("n"); report.ColTotal[colI] += dec; report.TableQ.Rows.Add(row); } FormQuery2.ResetGrid(); report.Title = "Daily Adjustments"; report.SubTitle.Add(PrefC.GetString(PrefName.PracticeTitle)); report.SubTitle.Add(date1.SelectionStart.ToString("d") + " - " + date2.SelectionStart.ToString("d")); if (checkAllProv.Checked) { report.SubTitle.Add(Lan.g(this, "All Providers")); } else { string provNames = ""; for (int i = 0; i < listProv.SelectedIndices.Count; i++) { if (i > 0) { provNames += ", "; } provNames += ProviderC.ListShort[listProv.SelectedIndices[i]].Abbr; } report.SubTitle.Add(provNames); } if (!PrefC.GetBool(PrefName.EasyNoClinics)) { if (checkAllClin.Checked) { report.SubTitle.Add(Lan.g(this, "All Clinics")); } else { string clinNames = ""; for (int i = 0; i < listClin.SelectedIndices.Count; i++) { if (i > 0) { clinNames += ", "; } if (listClin.SelectedIndices[i] == 0) { clinNames += Lan.g(this, "Unassigned"); } else { clinNames += Clinics.List[listClin.SelectedIndices[i] - 1].Description; } } report.SubTitle.Add(clinNames); } } report.SetColumn(this, 0, "Date", 90); report.SetColumn(this, 1, "Patient Name", 130); report.SetColumn(this, 2, "Prov", 60); if (!PrefC.GetBool(PrefName.EasyNoClinics)) { report.SetColumn(this, 3, "Clinic", 70); report.SetColumn(this, 4, "Adjustment Type", 150); report.SetColumn(this, 5, "Note", 150); report.SetColumn(this, 6, "Amount", 75, HorizontalAlignment.Right); } else { report.SetColumn(this, 3, "Adjustment Type", 150); report.SetColumn(this, 4, "Note", 150); report.SetColumn(this, 5, "Amount", 75, HorizontalAlignment.Right); } FormQuery2.ShowDialog(); DialogResult = DialogResult.OK; }