예제 #1
0
파일: FormPayment.cs 프로젝트: mnisl/OD
		private void butOK_Click(object sender,System.EventArgs e) {
			if(textDate.errorProvider1.GetError(textDate)!=""
				|| textAmount.errorProvider1.GetError(textAmount)!="") {
				MessageBox.Show(Lan.g(this,"Please fix data entry errors first."));
				return;
			}
			if(checkPayTypeNone.Checked) {
				if(PIn.Double(textAmount.Text)!=0) {
					MsgBox.Show(this,"Amount must be zero for a transfer.");
					return;
				}
			}
			else {
				if(textAmount.Text=="") {
					MessageBox.Show(Lan.g(this,"Please enter an amount."));
					return;
				}
				if(PIn.Double(textAmount.Text)==0) {
					MessageBox.Show(Lan.g(this,"Amount must not be zero unless this is a transfer."));
					return;
				}
				if(listPayType.SelectedIndex==-1) {
					MsgBox.Show(this,"A payment type must be selected.");
					return;
				}
			}
			if(IsNew) {
				//prevents backdating of initial payment
				if(!Security.IsAuthorized(Permissions.PaymentCreate,PIn.Date(textDate.Text))) {
					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.PaymentEdit,PIn.Date(textDate.Text))) {
					return;
				}
			}
			bool accountingSynchRequired=false;
			double accountingOldAmt=PaymentCur.PayAmt;
			long accountingNewAcct=-1;//the old acctNum will be retrieved inside the validation code.
			if(textDepositAccount.Visible) {
				accountingNewAcct=-1;//indicates no change
			}
			else if(comboDepositAccount.Visible && comboDepositAccount.Items.Count>0 && comboDepositAccount.SelectedIndex!=-1) {
				accountingNewAcct=DepositAccounts[comboDepositAccount.SelectedIndex];
			}
			else {//neither textbox nor combo visible. Or something's wrong with combobox
				accountingNewAcct=0;
			}
			try {
				accountingSynchRequired=Payments.ValidateLinkedEntries(accountingOldAmt,PIn.Double(textAmount.Text),IsNew,
					PaymentCur.PayNum,accountingNewAcct);
			}
			catch(ApplicationException ex) {
				MessageBox.Show(ex.Message);//not able to alter, so must not allow user to continue.
				return;
			}
			PaymentCur.PayAmt=PIn.Double(textAmount.Text);//handles blank
			PaymentCur.PayDate=PIn.Date(textDate.Text);
			#region Recurring charge logic
			//User chose to have a recurring payment so we need to know if the card has recurring setup and which month to apply the payment to.
			if(IsNew && checkRecurring.Checked && comboCreditCards.SelectedIndex!=creditCards.Count) {
				//Check if a recurring charge is setup for the selected card.
				if(creditCards[comboCreditCards.SelectedIndex].ChargeAmt==0 
					|| creditCards[comboCreditCards.SelectedIndex].DateStart.Year < 1880) 
				{
					MsgBox.Show(this,"The selected credit card has not been setup for recurring charges.");
					return;
				}
				//Check if a stop date was set and if that date falls in on today or in the past.
				if(creditCards[comboCreditCards.SelectedIndex].DateStop.Year > 1880
					&& creditCards[comboCreditCards.SelectedIndex].DateStop<=DateTime.Now) 
				{
					MsgBox.Show(this,"This card is no longer accepting recurring charges based on the stop date.");
					return;
				}
				//Have the user decide what month to apply the recurring charge towards.
				FormCreditRecurringDateChoose formDateChoose=new FormCreditRecurringDateChoose(creditCards[comboCreditCards.SelectedIndex]);
				formDateChoose.ShowDialog();
				if(formDateChoose.DialogResult!=DialogResult.OK) {
					MsgBox.Show(this,"Uncheck the \"Apply to Recurring Charge\" box.");
					return;
				}
				//This will change the PayDate to work better with the recurring charge automation.  User was notified in previous window.
				PaymentCur.PayDate=formDateChoose.PayDate;
			}
			else if(IsNew && checkRecurring.Checked && comboCreditCards.SelectedIndex==creditCards.Count) {
				MsgBox.Show(this,"Cannot apply a recurring charge to a new card.");
				return;
			}
			#endregion
			PaymentCur.CheckNum=textCheckNum.Text;
			PaymentCur.BankBranch=textBankBranch.Text;
			PaymentCur.PayNote=textNote.Text;
			PaymentCur.IsRecurringCC=checkRecurring.Checked;
			if(checkPayTypeNone.Checked) {
				PaymentCur.PayType=0;
			}
			else {
				PaymentCur.PayType=DefC.Short[(int)DefCat.PaymentTypes][listPayType.SelectedIndex].DefNum;
			}
			//PaymentCur.PatNum=PatCur.PatNum;//this is already done before opening this window.
			//PaymentCur.ClinicNum already handled
			if(IsNew && SplitList.Count==0) {
				//The user has no splits and is trying to submit a payment.
				//We need to ask if they want to autosplit the payment to start getting procedures associated to splits.
				if(MsgBox.Show(this,MsgBoxButtons.YesNo,"Would you like to autosplit the payment to outstanding family balances?")) {
					FormPaySplitManage FormPSM=new FormPaySplitManage();
					FormPSM.PaymentAmt=PIn.Double(textAmount.Text);
					FormPSM.FamCur=Patients.GetFamily(PatCur.PatNum);
					FormPSM.PatCur=PatCur;
					FormPSM.PaymentCur=PaymentCur;
					FormPSM.PayDate=PIn.DateT(textDate.Text);
					FormPSM.IsNew=IsNew;
					FormPSM.ListSplitsCur=SplitList;
					if(FormPSM.ShowDialog()==DialogResult.OK) {
						SplitList=FormPSM.ListSplitsCur;
						PaymentCur=FormPSM.PaymentCur;
						if(SplitList.Count==0) {//If they clicked OK without any splits being added, add one split.
							AddOneSplit();
						}
					}
					else {//Cancel
						AddOneSplit();
					}
				}
				else {//Either no allocation required, or user does not want to allocate.  Just add one split.
					AddOneSplit();
				}
			}
			else {//Existing payment and/or has splits.
				if(SplitList.Count==0) {//Existing payment with no splits.
					if(Payments.AllocationRequired(PaymentCur.PayAmt,PaymentCur.PatNum)
						&& MsgBox.Show(this,MsgBoxButtons.YesNo,"Apply part of payment to other family members?")) {
						SplitList=Payments.Allocate(PaymentCur);//PayAmt needs to be set first
					}
					else {//Either no allocation required, or user does not want to allocate.  Just add one split.
						AddOneSplit();
					}
				}
				else {//A new or existing payment with splits.
					if(SplitList.Count==1//if one split
						&& PIn.Double(textAmount.Text) != SplitList[0].SplitAmt)//and amount doesn't match payment
					{
						SplitList[0].SplitAmt=PIn.Double(textAmount.Text);//make amounts match
					}
					if(SplitList.Count==1//if one split
						&& PaymentCur.PayDate != SplitList[0].ProcDate
						&& SplitList[0].ProcNum==0)//not attached to procedure
					{
						if(MsgBox.Show(this,MsgBoxButtons.YesNo,"Change split date to match payment date?")) {
							SplitList[0].ProcDate=PaymentCur.PayDate;
						}
					}
					if(SplitList.Count!=1 && PaymentCur.PayAmt!=PIn.Double(textTotal.Text)) {
						MsgBox.Show(this,"Split totals must equal payment amount.");
						//work on reallocation schemes here later
						return;
					}
				}
			}
			if(SplitList.Count>1) {
				PaymentCur.IsSplit=true;
			}
			else {
				PaymentCur.IsSplit=false;
			}
			try {
				Payments.Update(PaymentCur,true);
			}
			catch(ApplicationException ex) {//this catches bad dates.
				MessageBox.Show(ex.Message);
				return;
			}
			//Set all DatePays the same.
			for(int i=0;i<SplitList.Count;i++) {
				SplitList[i].DatePay=PaymentCur.PayDate;
			}
			PaySplits.UpdateList(SplitListOld,SplitList);
			//Accounting synch is done here.  All validation was done further up
			//If user is trying to change the amount or linked account of an entry that was already copied and linked to accounting section
			if(accountingSynchRequired) {
				Payments.AlterLinkedEntries(accountingOldAmt,PaymentCur.PayAmt,IsNew,
					PaymentCur.PayNum,accountingNewAcct,PaymentCur.PayDate,FamCur.GetNameInFamFL(PaymentCur.PatNum));
			}
			if(IsNew) {
				SecurityLogs.MakeLogEntry(Permissions.PaymentCreate,PaymentCur.PatNum,
					Patients.GetLim(PaymentCur.PatNum).GetNameLF()+", "
					+PaymentCur.PayAmt.ToString("c"));
			}
			else {
				SecurityLogs.MakeLogEntry(Permissions.PaymentEdit,PaymentCur.PatNum,
					Patients.GetLim(PaymentCur.PatNum).GetNameLF()+", "
					+PaymentCur.PayAmt.ToString("c"));
			}
			DialogResult=DialogResult.OK;
		}
예제 #2
0
파일: FormPayment.cs 프로젝트: mnisl/OD
		private void butSplitManage_Click(object sender,EventArgs e) {
			FormPaySplitManage FormPSM=new FormPaySplitManage();
			FormPSM.PaymentAmt=PIn.Double(textAmount.Text);
			FormPSM.FamCur=Patients.GetFamily(PatCur.PatNum);
			FormPSM.PatCur=PatCur;
			FormPSM.PaymentCur=PaymentCur;
			FormPSM.PayDate=PIn.DateT(textDate.Text);
			FormPSM.IsNew=IsNew;
			FormPSM.ListSplitsCur=SplitList;
			FormPSM.ShowDialog();
			if(FormPSM.DialogResult==DialogResult.OK) {
				SplitList=FormPSM.ListSplitsCur;
				PaymentCur=FormPSM.PaymentCur;
				textAmount.Text=POut.Double(PaymentCur.PayAmt);
			}
			FillMain();
		}