private void butOK_Click(object sender, System.EventArgs e) { if (textDate.errorProvider1.GetError(textDate) != "" || textAPR.errorProvider1.GetError(textAPR) != "") { MessageBox.Show(Lan.g(this, "Please fix data entry errors first.")); return; } if (PIn.PInt(textAPR.Text) < 2) { if (MessageBox.Show(Lan.g(this, "The APR is much lower than normal. Do you wish to proceed?"), "", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } } //Patients.ResetAging(); //Ledgers.UpdateFinanceCharges(PIn.PDate(textDate.Text)); PatAging[] AgingList = Patients.GetAgingList(); double OverallBalance; for (int i = 0; i < AgingList.Length; i++) { OverallBalance = 0; //this WILL NOT be the same as the patient's total balance if (radio30.Checked) { OverallBalance = AgingList[i].Bal_31_60 + AgingList[i].Bal_61_90 + AgingList[i].BalOver90; } if (radio60.Checked) { OverallBalance = AgingList[i].Bal_61_90 + AgingList[i].BalOver90; } if (radio90.Checked) { OverallBalance = AgingList[i].BalOver90; } if (OverallBalance > 0) { Adjustment AdjustmentCur = new Adjustment(); AdjustmentCur.PatNum = AgingList[i].PatNum; //AdjustmentCur.DateEntry=PIn.PDate(textDate.Text);//automatically handled AdjustmentCur.AdjDate = PIn.PDate(textDate.Text); AdjustmentCur.ProcDate = PIn.PDate(textDate.Text); AdjustmentCur.AdjType = DefB.Short[(int)DefCat.AdjTypes] [(int)ALPosIndices[listAdjType.SelectedIndex]].DefNum; AdjustmentCur.AdjNote = "Finance Charge"; AdjustmentCur.AdjAmt = Math.Round(((PIn.PDouble(textAPR.Text) * .01 / 12) * OverallBalance), 2); AdjustmentCur.ProvNum = AgingList[i].PriProv; Adjustments.InsertOrUpdate(AdjustmentCur, true); } } Prefs.UpdateString("FinanceChargeAPR", textAPR.Text); Prefs.UpdateInt("FinanceChargeAdjustmentType", DefB.Short[(int)DefCat.AdjTypes][(int)ALPosIndices[listAdjType.SelectedIndex]].DefNum); Prefs.UpdateString("FinanceChargeLastRun", POut.PDate(DateTime.Today, false)); DataValid.SetInvalid(InvalidTypes.Prefs); MessageBox.Show(Lan.g(this, "Finance Charges Added.")); DialogResult = DialogResult.OK; }
private void butOK_Click(object sender, System.EventArgs e) { if (textAdjDate.errorProvider1.GetError(textAdjDate) != "" || textProcDate.errorProvider1.GetError(textProcDate) != "" || textAmount.errorProvider1.GetError(textAmount) != "" ) { MsgBox.Show(this, "Please fix data entry errors first."); return; } if (textAmount.Text == "") { MessageBox.Show(Lan.g(this, "Please enter an amount.")); return; } if (listTypeNeg.SelectedIndex == -1 && listTypePos.SelectedIndex == -1) { MsgBox.Show(this, "Please select a type first."); return; } //DateEntry not allowed to change AdjustmentCur.AdjDate = PIn.PDate(textAdjDate.Text); AdjustmentCur.ProcDate = PIn.PDate(textProcDate.Text); if (listProvider.SelectedIndex == -1) { AdjustmentCur.ProvNum = PatCur.PriProv; } else { AdjustmentCur.ProvNum = Providers.List[this.listProvider.SelectedIndex].ProvNum; } if (listTypePos.SelectedIndex != -1) { AdjustmentCur.AdjType = DefB.Short[(int)DefCat.AdjTypes][(int)PosIndex[listTypePos.SelectedIndex]].DefNum; } if (listTypeNeg.SelectedIndex != -1) { AdjustmentCur.AdjType = DefB.Short[(int)DefCat.AdjTypes][(int)NegIndex[listTypeNeg.SelectedIndex]].DefNum; } if (DefB.GetValue(DefCat.AdjTypes, AdjustmentCur.AdjType) == "+") //pos { AdjustmentCur.AdjAmt = PIn.PDouble(textAmount.Text); } else //neg { AdjustmentCur.AdjAmt = -PIn.PDouble(textAmount.Text); } AdjustmentCur.AdjNote = textNote.Text; try{ Adjustments.InsertOrUpdate(AdjustmentCur, IsNew); } catch (Exception ex) { //even though it doesn't currently throw any exceptions MessageBox.Show(ex.Message); return; } if (IsNew) { SecurityLogs.MakeLogEntry(Permissions.AdjustmentCreate, AdjustmentCur.PatNum, Patients.GetLim(AdjustmentCur.PatNum).GetNameLF() + ", " + AdjustmentCur.AdjAmt.ToString("c")); } else { SecurityLogs.MakeLogEntry(Permissions.AdjustmentEdit, AdjustmentCur.PatNum, Patients.GetLim(AdjustmentCur.PatNum).GetNameLF() + ", " + AdjustmentCur.AdjAmt.ToString("c")); } DialogResult = DialogResult.OK; }
private int ReallocateAll() { string command = "SELECT DefNum FROM definition WHERE Category=1 AND ItemName='Reallocation'"; DataTable table = General.GetTable(command); int defnum; if (table.Rows.Count == 0) { Def def = new Def(); def.Category = DefCat.AdjTypes; def.ItemName = "Reallocation"; def.ItemValue = "+"; def.ItemOrder = DefB.Long[(int)DefCat.AdjTypes].Length; Defs.Insert(def); defnum = def.DefNum; DataValid.SetInvalid(InvalidTypes.Defs); } else { defnum = PIn.PInt(table.Rows[0][0].ToString()); } //find all families where someone has a negative balance. command = "SELECT DISTINCT Guarantor FROM patient WHERE EstBalance < 0"; DataTable tableGuarantors = General.GetTable(command); int changed = 0; //bool result; double[] familyBals; DataTable tablePatients; Adjustment adj; Double delta; for (int i = 0; i < tableGuarantors.Rows.Count; i++) { command = "SELECT PatNum,EstBalance FROM patient WHERE Guarantor=" + tableGuarantors.Rows[i][0].ToString(); tablePatients = General.GetTable(command); if (tablePatients.Rows.Count == 1) //impossible to allocate { continue; } familyBals = new double[tablePatients.Rows.Count]; for (int p = 0; p < tablePatients.Rows.Count; p++) { familyBals[p] = PIn.PDouble(tablePatients.Rows[p]["EstBalance"].ToString()); } for (int p = 0; p < familyBals.Length; p++) { if (familyBals[p] < 0) //if a negative bal found { for (int j = 0; j < familyBals.Length; j++) //look for a positive bal to adjust { if (j == p) { continue; //skip same patient } if (familyBals[j] <= 0) { continue; //no neg bal } if (familyBals[j] >= -familyBals[p]) //if sufficient bal to zero out the neg { familyBals[j] += familyBals[p]; //because p is neg familyBals[p] = 0; break; //quit looking for a pos bal to adj. } else //only enough bal to reduce the negative, not eliminate it { familyBals[p] += familyBals[j]; //because p is neg familyBals[j] = 0; } } } } //now, save any changes to db: for (int p = 0; p < familyBals.Length; p++) { if (familyBals[p] == PIn.PDouble(tablePatients.Rows[p]["EstBalance"].ToString())) { continue; //same, so no change to db } adj = new Adjustment(); adj.PatNum = PIn.PInt(tablePatients.Rows[p]["PatNum"].ToString()); adj.AdjDate = DateTime.Today; adj.AdjNote = "Automatic"; adj.AdjType = defnum; adj.ProcDate = DateTime.Today; adj.ProvNum = PrefB.GetInt("PracticeDefaultProv"); delta = familyBals[p] - PIn.PDouble(tablePatients.Rows[p]["EstBalance"].ToString()); //works whether pos or neg adj.AdjAmt = delta; Adjustments.InsertOrUpdate(adj, true); command = "UPDATE patient SET EstBalance=EstBalance+'" + POut.PDouble(delta) + "' WHERE PatNum=" + tablePatients.Rows[p]["PatNum"].ToString(); General.NonQ(command); changed++; } } return(changed); }