private void butOK_Click(object sender, System.EventArgs e) { bool isDiscountPlanAdj = (Defs.GetValue(DefCat.AdjTypes, _adjustmentCur.AdjType) == "dp"); if (textAdjDate.errorProvider1.GetError(textAdjDate) != "" || textProcDate.errorProvider1.GetError(textProcDate) != "" || textAmount.errorProvider1.GetError(textAmount) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return; } if (PIn.Date(textAdjDate.Text).Date > DateTime.Today.Date && !PrefC.GetBool(PrefName.FutureTransDatesAllowed)) { MsgBox.Show(this, "Adjustment date can not be in the future."); return; } if (textAmount.Text == "") { MessageBox.Show(Lan.g(this, "Please enter an amount.")); return; } if (!isDiscountPlanAdj && listTypeNeg.SelectedIndex == -1 && listTypePos.SelectedIndex == -1) { MsgBox.Show(this, "Please select a type first."); return; } if (IsNew && AvaTax.IsEnabled() && listTypePos.SelectedIndex > -1 && (_listAdjPosCats[listTypePos.SelectedIndex].DefNum == AvaTax.SalesTaxAdjType || _listAdjPosCats[listTypePos.SelectedIndex].DefNum == AvaTax.SalesTaxReturnAdjType) && !Security.IsAuthorized(Permissions.SalesTaxAdjEdit)) { return; } if (PrefC.GetInt(PrefName.RigorousAdjustments) == 0 && _adjustmentCur.ProcNum == 0) { MsgBox.Show(this, "You must attach a procedure to the adjustment."); return; } if (_adjRemAmt < 0) { if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "Remaining amount is negative. Continue?", "Overpaid Procedure Warning")) { return; } } bool changeAdjSplit = false; List <PaySplit> listPaySplitsForAdjust = new List <PaySplit>(); if (IsNew) { //prevents backdating of initial adjustment if (!Security.IsAuthorized(Permissions.AdjustmentCreate, PIn.Date(textAdjDate.Text), true)) //Give message later. { if (!_checkZeroAmount) //Let user create as long as Amount is zero and has edit zero permissions. This was checked on load. { MessageBox.Show(Lans.g("Security", "Not authorized for") + "\r\n" + GroupPermissions.GetDesc(Permissions.AdjustmentCreate)); return; } } } else { //Editing an old entry will already be blocked if the date was too old, and user will not be able to click OK button //This catches it if user changed the date to be older. if (!Security.IsAuthorized(Permissions.AdjustmentEdit, PIn.Date(textAdjDate.Text))) { return; } if (_adjustmentCur.ProvNum != comboProv.GetSelectedProvNum()) { listPaySplitsForAdjust = PaySplits.GetForAdjustments(new List <long>() { _adjustmentCur.AdjNum }); foreach (PaySplit paySplit in listPaySplitsForAdjust) { if (!Security.IsAuthorized(Permissions.PaymentEdit, Payments.GetPayment(paySplit.PayNum).PayDate)) { return; } if (comboProv.GetSelectedProvNum() != paySplit.ProvNum && PrefC.GetInt(PrefName.RigorousAccounting) == (int)RigorousAdjustments.EnforceFully) { changeAdjSplit = true; break; } } if (changeAdjSplit && !MsgBox.Show(this, MsgBoxButtons.OKCancel, "The provider for the associated payment splits will be changed to match the provider on the " + "adjustment.")) { return; } } } //DateEntry not allowed to change DateTime datePreviousChange = _adjustmentCur.SecDateTEdit; _adjustmentCur.AdjDate = PIn.Date(textAdjDate.Text); _adjustmentCur.ProcDate = PIn.Date(textProcDate.Text); _adjustmentCur.ProvNum = comboProv.GetSelectedProvNum(); _adjustmentCur.ClinicNum = comboClinic.SelectedClinicNum; if (listTypePos.SelectedIndex != -1) { _adjustmentCur.AdjType = _listAdjPosCats[listTypePos.SelectedIndex].DefNum; _adjustmentCur.AdjAmt = PIn.Double(textAmount.Text); } if (listTypeNeg.SelectedIndex != -1) { _adjustmentCur.AdjType = _listAdjNegCats[listTypeNeg.SelectedIndex].DefNum; _adjustmentCur.AdjAmt = -PIn.Double(textAmount.Text); } if (isDiscountPlanAdj) { //AdjustmentCur.AdjType is already set to a "discount plan" adj type. _adjustmentCur.AdjAmt = -PIn.Double(textAmount.Text); } if (_checkZeroAmount && _adjustmentCur.AdjAmt != 0) { MsgBox.Show(this, "Amount has to be 0.00 due to security permission."); return; } _adjustmentCur.AdjNote = textNote.Text; try{ if (IsNew) { Adjustments.Insert(_adjustmentCur); SecurityLogs.MakeLogEntry(Permissions.AdjustmentCreate, _adjustmentCur.PatNum, _patCur.GetNameLF() + ", " + _adjustmentCur.AdjAmt.ToString("c")); TsiTransLogs.CheckAndInsertLogsIfAdjTypeExcluded(_adjustmentCur, _isTsiAdj); } else { Adjustments.Update(_adjustmentCur); SecurityLogs.MakeLogEntry(Permissions.AdjustmentEdit, _adjustmentCur.PatNum, _patCur.GetNameLF() + ", " + _adjustmentCur.AdjAmt.ToString("c"), 0 , datePreviousChange); } } catch (Exception ex) { //even though it doesn't currently throw any exceptions MessageBox.Show(ex.Message); return; } if (changeAdjSplit) { PaySplits.UpdateProvForAdjust(_adjustmentCur, listPaySplitsForAdjust); } DialogResult = DialogResult.OK; }
private void butRefresh_Click(object sender, EventArgs e) { _listTsiTransLogsAll = TsiTransLogs.GetAll(); FillGrid(); }
///<summary>Return a list of filtered indexes relative to the index in _listTsiTransLogsAll. ///We use indexes to conserve memory.</summary> private List <int> GetListIndexesFiltered() { List <int> retval = new List <int>(); #region Validate Filters ValidateChildren(ValidationConstraints.Enabled | ValidationConstraints.Visible | ValidationConstraints.Selectable); if (!datePicker.IsValid) { MsgBox.Show(this, "Please fix data entry errors first."); return(retval); //return empty list, filter inputs cannot be applied since there are errors } #endregion Validate Filters #region Get Filter Data DateTime dateStart = datePicker.GetDateTimeFrom(); DateTime dateEnd = datePicker.GetDateTimeTo(); dateEnd = (dateEnd == DateTime.MinValue?DateTime.Today:dateEnd); List <TsiTransType> listSelectedTransTypes = new List <TsiTransType>(); if (!comboBoxMultiTransTypes.SelectedIndices.Contains(0)) { listSelectedTransTypes = comboBoxMultiTransTypes.ListSelectedIndices.Select(x => _listTransTypes[x - 1]).ToList(); } List <string> listSelectedAcctStatuses = new List <string>(); if (!comboBoxMultiAcctStatuses.SelectedIndices.Contains(0)) { listSelectedAcctStatuses = comboBoxMultiAcctStatuses.ListSelectedIndices.Select(x => _listAcctStatuses[x - 1]).ToList(); } List <long> listSuspendedGuarNums = TsiTransLogs.GetSuspendedGuarNums(); List <long> listActiveCollGuarNums = Patients.GetListCollectionGuarNums(/*false*/); Dictionary <long, long> dictLogClinic = new Dictionary <long, long>(); if (PrefC.HasClinicsEnabled) { Patient patCur; dictLogClinic = _listTsiTransLogsAll.ToDictionary(x => x.TsiTransLogNum , x => (x.ClinicNum > 0?x.ClinicNum:(_dictPatLims.TryGetValue(x.PatNum, out patCur)?patCur.ClinicNum:0)) ); } List <string> listClientIDs = new List <string>(); if (!comboBoxMultiClientIDs.SelectedIndices.Contains(0)) { listClientIDs = comboBoxMultiClientIDs.ListSelectedIndices.Select(x => _listClientIDs[x - 1]).ToList(); } #endregion Get Filter Data #region Apply Filter Data for (int i = 0; i < _listTsiTransLogsAll.Count; i++) { TsiTransLog logCur = _listTsiTransLogsAll[i]; if (logCur.TransDateTime.Date <= dateEnd && logCur.TransDateTime.Date >= dateStart && (_listSelectedFamPatNums.Count == 0 || _listSelectedFamPatNums.Contains(logCur.PatNum)) && (comboClinics.ListSelectedClinicNums.Count == 0 || (dictLogClinic.ContainsKey(logCur.TsiTransLogNum) && comboClinics.ListSelectedClinicNums.Contains(dictLogClinic[logCur.TsiTransLogNum]))) && (listClientIDs.Count == 0 || listClientIDs.Contains(logCur.ClientId)) && (listSelectedTransTypes.Count == 0 || listSelectedTransTypes.Contains(logCur.TransType)) && (listSelectedAcctStatuses.Count == 0 || (listSelectedAcctStatuses.Contains("Active") && listActiveCollGuarNums.Contains(logCur.PatNum)) || (listSelectedAcctStatuses.Contains("Suspended") && listSuspendedGuarNums.Contains(logCur.PatNum)) || (listSelectedAcctStatuses.Contains("Inactive") && !listActiveCollGuarNums.Concat(listSuspendedGuarNums).Contains(logCur.PatNum)))) { retval.Add(i); } } #endregion Apply Filter Data return(retval); }
private void FormTsiHistory_Load(object sender, EventArgs e) { SetFilterControlsAndAction(() => FillGrid(), datePicker, checkShowPatNums); #region Fill Clinics _listClinics = new List <Clinic>(); if (PrefC.HasClinicsEnabled) { _listClinics.AddRange( Clinics.GetForUserod(Security.CurUser, true).OrderBy(x => x.ClinicNum != 0).ThenBy(x => x.ItemOrder) ); } else //clinics disabled { _listClinics.Add(Clinics.GetPracticeAsClinicZero(Lan.g(this, "Unassigned"))); } #endregion Fill Clinics #region Fill Client IDs comboBoxMultiClientIDs.Items.Add(Lan.g(this, "All")); comboBoxMultiClientIDs.SetSelected(0, true); _listClientIDs = new List <string>(); long progNum = Programs.GetProgramNum(ProgramName.Transworld); if (progNum > 0) { _listClientIDs = ProgramProperties.GetWhere(x => x.ProgramNum == progNum && x.PropertyDesc.In("ClientIdAccelerator", "ClientIdCollection")) .Select(x => x.PropertyValue).Distinct().ToList(); } _listClientIDs.ForEach(x => comboBoxMultiClientIDs.Items.Add(x)); #endregion Fill Client IDs #region Fill Trans Types _listTransTypes = Enum.GetValues(typeof(TsiTransType)).OfType <TsiTransType>().ToList(); comboBoxMultiTransTypes.Items.Add(Lan.g(this, "All")); comboBoxMultiTransTypes.SetSelected(0, true); _listTransTypes.ForEach(x => comboBoxMultiTransTypes.Items.Add(x.GetDescription())); #endregion Fill Trans Types #region Fill Account Statuses _listAcctStatuses = new[] { "Active", "Suspended", "Inactive" }.ToList(); comboBoxMultiAcctStatuses.Items.Add(Lan.g(this, "All")); comboBoxMultiAcctStatuses.SetSelected(0, true); _listAcctStatuses.ForEach(x => comboBoxMultiAcctStatuses.Items.Add(x)); #endregion Fill Account Statuses #region Get Selected Family PatNums _listSelectedFamPatNums = new List <long>(); if (FormOpenDental.CurPatNum > 0) { Family fam = Patients.GetFamily(FormOpenDental.CurPatNum); textPatient.Text = fam.GetNameInFamLF(FormOpenDental.CurPatNum); _listSelectedFamPatNums = fam.ListPats.Select(x => x.PatNum).ToList(); } #endregion Get Selected Family PatNums #region Get All TsiTransLogs _listTsiTransLogsAll = TsiTransLogs.GetAll(); #endregion Get All TsiTransLogs #region Add ClientIDs No Longer In Use List <string> listLogClientIDs = _listTsiTransLogsAll.Select(x => x.ClientId).Distinct().Where(x => !_listClientIDs.Contains(x)).ToList(); foreach (string clientIDCur in listLogClientIDs) { _listClientIDs.Add(clientIDCur); comboBoxMultiClientIDs.Items.Add(clientIDCur + " (no longer used)"); } #endregion Add ClientIDs No Longer In Use _dictPatLims = Patients.GetLimForPats(_listTsiTransLogsAll.Select(x => x.PatNum).Distinct().ToList() /*,true*/).ToDictionary(x => x.PatNum); datePicker.SetDateTimeFrom(DateTime.Today.AddDays(-1)); //Set start to yesterday datePicker.SetDateTimeTo(DateTime.Today); //Set stop date to today to limit the number of messages that load immediately _selectedLog = null; FillGrid(); }
private void butOK_Click(object sender, EventArgs e) { if (_listGridEntries.FindAll(x => x.Adj != null).Count == 0) //no adjustments have been added. Attempt to add adjustments with the current info. //get the list of selected procedures to add adjustments to (if there are any). Will make one for unattached if none exist. { List <MultiAdjEntry> listSelectedEntries = new List <MultiAdjEntry>(); for (int i = 0; i < gridMain.SelectedIndices.Count(); i++) { listSelectedEntries.Add((MultiAdjEntry)(gridMain.ListGridRows[gridMain.SelectedIndices[i]].Tag)); } if (!IsValid(listSelectedEntries.Count)) { return; } AddAdjustments(listSelectedEntries); FillGrid(); //In case they get stopped at the msgBox below, they should see the new adjustments added. } //now we should be guaranteed to have adjustments bool hasNegAmt = false; foreach (MultiAdjEntry mae in _listGridEntries) { if (mae.Adj == null || mae.Proc == null) { continue; //Procedures or unattached adjustments } decimal remAfter = (decimal)mae.AmtRemBefore + (decimal)mae.Adj.AdjAmt; if (remAfter.IsLessThanZero()) { hasNegAmt = true; break; } } if (hasNegAmt && !MsgBox.Show(this, MsgBoxButtons.OKCancel, "Remaining amount on a procedure is negative. Continue?", "Overpaid Procedure Warning")) { return; } if (!Security.IsAuthorized(Permissions.AdjustmentCreate, true)) //User does not have full edit permission. //Therefore the user only has the ability to edit $0 adjustments (see Load()). { foreach (MultiAdjEntry row in _listGridEntries) { if (row.Adj == null) //skip over Procedure rows { continue; } if (!row.Adj.AdjAmt.IsZero()) { MsgBox.Show(this, "Amount has to be 0.00 due to security permission."); return; } } } List <string> listAdjustmentAmounts = new List <string>(); foreach (MultiAdjEntry row in _listGridEntries) { if (row.Adj == null) //skip over Procedure rows { continue; } Adjustments.Insert(row.Adj); TsiTransLogs.CheckAndInsertLogsIfAdjTypeExcluded(row.Adj); listAdjustmentAmounts.Add(row.Adj.AdjAmt.ToString("c")); } if (listAdjustmentAmounts.Count > 0) { string log = Lan.g(this, "Adjustment(s) created from Multiple Adjustments window:") + " "; SecurityLogs.MakeLogEntry(Permissions.AdjustmentCreate, _patCur.PatNum, log + string.Join(",", listAdjustmentAmounts)); } DialogResult = DialogResult.OK; }