Exemple #1
0
        private void butOK_Click(object sender, System.EventArgs e)
        {
            if (textDate.Text == "")
            {
                MsgBox.Show(this, "Please enter a date first.");
                return;
            }
            if (PIn.Date(textDate.Text).Date > DateTime.Today.Date && !PrefC.GetBool(PrefName.FutureTransDatesAllowed) &&
                !PrefC.GetBool(PrefName.AllowFutureInsPayments))
            {
                MsgBox.Show(this, "Payments cannot be for a date in the future.");
                return;                 //probably not necesasary since this is an old form, but just in case we use it again
            }
            if (textDate.errorProvider1.GetError(textDate) != "")
            {
                MsgBox.Show(this, "Please fix data entry errors first.");
                return;
            }
            if (gridMain.SelectedIndices.Length == 0)
            {
                MessageBox.Show(Lan.g(this, "At least one item must be selected, or use the delete button."));
                return;
            }
            if (IsNew)
            {
                //prevents backdating of initial check
                if (!Security.IsAuthorized(Permissions.InsPayCreate, PIn.Date(textDate.Text)))
                {
                    return;
                }
                //prevents attaching claimprocs with a date that is older than allowed by security.
            }
            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.InsPayEdit, PIn.Date(textDate.Text)))
                {
                    return;
                }
            }
            if (comboClinic.SelectedIndex == 0)
            {
                ClaimPaymentCur.ClinicNum = 0;
            }
            else
            {
                ClaimPaymentCur.ClinicNum = _listClinics[comboClinic.SelectedIndex - 1].ClinicNum;
            }
            ClaimPaymentCur.CheckAmt    = PIn.Double(textAmount.Text);
            ClaimPaymentCur.CheckDate   = PIn.Date(textDate.Text);
            ClaimPaymentCur.CheckNum    = textCheckNum.Text;
            ClaimPaymentCur.BankBranch  = textBankBranch.Text;
            ClaimPaymentCur.CarrierName = textCarrierName.Text;
            ClaimPaymentCur.Note        = textNote.Text;
            try{
                ClaimPayments.Update(ClaimPaymentCur);                //error thrown if trying to change amount and already attached to a deposit.
            }
            catch (ApplicationException ex) {
                MessageBox.Show(ex.Message);
                return;
            }
            //this could be optimized to only save changes.
            //Would require a starting list to compare to.
            //But this isn't bad, since changes all saved at the very end
            List <int> selectedRows = new List <int>();

            for (int i = 0; i < gridMain.SelectedIndices.Length; i++)
            {
                selectedRows.Add(gridMain.SelectedIndices[i]);
            }
            for (int i = 0; i < splits.Count; i++)
            {
                if (selectedRows.Contains(i))                //row is selected
                {
                    ClaimProcs.SetForClaimOld(splits[i].ClaimNum, ClaimPaymentCur.ClaimPaymentNum, ClaimPaymentCur.CheckDate, true);
                    //Audit trail isn't perfect, since it doesn't make an entry if you remove a claim from a payment.
                    //And it always makes more audit trail entries when you click OK, even if you didn't actually attach new claims.
                    //But since this will cover the vast majority if situations.
                    if (IsNew)
                    {
                        SecurityLogs.MakeLogEntry(Permissions.InsPayCreate, splits[i].PatNum,
                                                  Patients.GetLim(splits[i].PatNum).GetNameLF() + ", "
                                                  + Lan.g(this, "Total Amt: ") + ClaimPaymentCur.CheckAmt.ToString("c") + ", "
                                                  + Lan.g(this, "Claim Split: ") + splits[i].InsPayAmt.ToString("c"));
                    }
                    else
                    {
                        SecurityLogs.MakeLogEntry(Permissions.InsPayEdit, splits[i].PatNum,
                                                  Patients.GetLim(splits[i].PatNum).GetNameLF() + ", "
                                                  + Lan.g(this, "Total Amt: ") + ClaimPaymentCur.CheckAmt.ToString("c") + ", "
                                                  + Lan.g(this, "Claim Split: ") + splits[i].InsPayAmt.ToString("c"));
                    }
                }
                else                 //row not selected
                                     //If user had not been attaching their inspayments to checks, then this will cause such payments to annoyingly have their
                                     //date changed to the current date.  This prompts them to call us.  Then, we tell them to attach to checks.
                {
                    ClaimProcs.SetForClaimOld(splits[i].ClaimNum, ClaimPaymentCur.ClaimPaymentNum, ClaimPaymentCur.CheckDate, false);
                }
            }
            DialogResult = DialogResult.OK;
        }