Example #1
0
File: Accounts.cs Project: mnisl/OD
		///<summary></summary>
		public static void Update(Account acct) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),acct);
				return;
			}
			Crud.AccountCrud.Update(acct);
		}
Example #2
0
File: Accounts.cs Project: mnisl/OD
		///<summary></summary>
		public static long Insert(Account acct) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				acct.AccountNum=Meth.GetLong(MethodBase.GetCurrentMethod(),acct);
				return acct.AccountNum;
			}
			return Crud.AccountCrud.Insert(acct);
		}
Example #3
0
		///<summary></summary>
		public FormJournal(Account accountCur)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			Lan.F(this);
			AccountCur=accountCur;
		}
		///<summary></summary>
		public FormTransactionEdit(long transNum,long accountNum)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			Lan.F(this);
			TransCur=Transactions.GetTrans(transNum);
			AccountOfOrigin=Accounts.GetAccount(accountNum);
			//AccountNumOrigin=accountNumOrigin;
		}
Example #5
0
 ///<summary>Throws exception if account is in use.</summary>
 public static void Delete(Account acct)
 {
     if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
         Meth.GetVoid(MethodBase.GetCurrentMethod(),acct);
         return;
     }
     //check to see if account has any journal entries
     string command="SELECT COUNT(*) FROM journalentry WHERE AccountNum="+POut.Long(acct.AccountNum);
     if(Db.GetCount(command)!="0"){
         throw new ApplicationException(Lans.g("FormAccountEdit",
             "Not allowed to delete an account with existing journal entries."));
     }
     //Check various preference entries
     command="SELECT ValueString FROM preference WHERE PrefName='AccountingDepositAccounts'";
     string result=Db.GetCount(command);
     string[] strArray=result.Split(new char[] {','});
     for(int i=0;i<strArray.Length;i++){
         if(strArray[i]==acct.AccountNum.ToString()){
             throw new ApplicationException(Lans.g("FormAccountEdit","Account is in use in the setup section."));
         }
     }
     command="SELECT ValueString FROM preference WHERE PrefName='AccountingIncomeAccount'";
     result=Db.GetCount(command);
     if(result==acct.AccountNum.ToString()) {
         throw new ApplicationException(Lans.g("FormAccountEdit","Account is in use in the setup section."));
     }
     command="SELECT ValueString FROM preference WHERE PrefName='AccountingCashIncomeAccount'";
     result=Db.GetCount(command);
     if(result==acct.AccountNum.ToString()) {
         throw new ApplicationException(Lans.g("FormAccountEdit","Account is in use in the setup section."));
     }
     //check AccountingAutoPay entries
     for(int i=0;i<AccountingAutoPays.Listt.Count;i++){
         strArray=AccountingAutoPays.Listt[i].PickList.Split(new char[] { ',' });
         for(int s=0;s<strArray.Length;s++){
             if(strArray[s]==acct.AccountNum.ToString()){
                 throw new ApplicationException(Lans.g("FormAccountEdit","Account is in use in the setup section."));
             }
         }
     }
     command="DELETE FROM account WHERE AccountNum = "+POut.Long(acct.AccountNum);
     Db.NonQ(command);
 }
		private void butChange_Click(object sender,EventArgs e) {
			FormAccountPick FormA=new FormAccountPick();
			FormA.ShowDialog();
			if(FormA.DialogResult!=DialogResult.OK) {
				return;
			}
			AccountPicked=FormA.SelectedAccount.Clone();
			textAccount.Text=AccountPicked.Description;
			butChange.Text=Lan.g(this,"Change");
		}
		///<summary>Used when switching simple view (0, 1, or 2 journal entries with identical notes).  This function fills in the correct fields in the simple view, and then deletes any journal entries.  2 journal entries will be recreated upon leaving for compound view by CreateTwoEntries.  This is only called once upon going to simple view.  It's not called repeatedly as a way of refreshing the screen.</summary>
		private void FillSimple(){
			panelSimple.Visible=true;
			panelCompound.Visible=false;
			if(JournalList.Count==0){
				AccountPicked=null;
				textAccount.Text="";
				butChange.Text=Lan.g(this,"Pick");
				textAmount.Text="";
				textMemo.Text="";
			}
			else if(JournalList.Count==1){
				double amt=0;
				//first we assume that the sole entry is for the current account
				if(Accounts.DebitIsPos(AccountOfOrigin.AcctType)) {//this is used for checking account
					if(((JournalEntry)JournalList[0]).DebitAmt>0) {
						amt=((JournalEntry)JournalList[0]).DebitAmt;
					}
					else {//use the credit
						amt=-((JournalEntry)JournalList[0]).CreditAmt;
					}
				}
				else {//false for checking acct
					if(((JournalEntry)JournalList[0]).DebitAmt>0) {
						amt=-((JournalEntry)JournalList[0]).DebitAmt;
					}
					else {
						amt=((JournalEntry)JournalList[0]).CreditAmt;
					}
				}
				//then, if we assumed wrong, change the sign
				if(((JournalEntry)JournalList[0]).AccountNum!=AccountOfOrigin.AccountNum){
					amt=-amt;
				}
				textAmount.Text=amt.ToString("n");
				if(((JournalEntry)JournalList[0]).AccountNum==0){
					AccountPicked=null;
					textAccount.Text="";
					butChange.Text=Lan.g(this,"Pick");
				}
				else if(((JournalEntry)JournalList[0]).AccountNum==AccountOfOrigin.AccountNum){
					AccountPicked=null;
					textAccount.Text="";
					butChange.Text=Lan.g(this,"Pick");
				}
				else{//the sole entry is not for the current account
					AccountPicked=Accounts.GetAccount(((JournalEntry)JournalList[0]).AccountNum);
					textAccount.Text=AccountPicked.Description;
					butChange.Text=Lan.g(this,"Change");
				}
				textMemo.Text=((JournalEntry)JournalList[0]).Memo;
				textCheckNumber.Text=((JournalEntry)JournalList[0]).CheckNumber;
			}
			else{//count=2
				JournalEntry journalCur;
				JournalEntry journalOther;
				if(((JournalEntry)JournalList[0]).AccountNum==AccountOfOrigin.AccountNum){
					//if the first entry is for the account of origin
					journalCur=(JournalEntry)JournalList[0];
					journalOther=(JournalEntry)JournalList[1];
				}
				else{
					journalCur=(JournalEntry)JournalList[1];
					journalOther=(JournalEntry)JournalList[0];
				}
				if(Accounts.DebitIsPos(AccountOfOrigin.AcctType)){//this is used for checking account
					if(journalCur.DebitAmt>0){
						textAmount.Text=journalCur.DebitAmt.ToString("n");
					}
					else{//use the credit
						textAmount.Text=(-journalCur.CreditAmt).ToString("n");
					}
				}
				else{//false for checking acct
					if(journalCur.DebitAmt>0) {
						textAmount.Text=(-journalCur.DebitAmt).ToString("n");
					}
					else {
						textAmount.Text=journalCur.CreditAmt.ToString("n");
					}
				}
				if(journalOther.AccountNum==0){
					AccountPicked=null;
					textAccount.Text="";
					butChange.Text=Lan.g(this,"Pick");
				}
				else{
					AccountPicked=Accounts.GetAccount(journalOther.AccountNum);
					textAccount.Text=AccountPicked.Description;
					butChange.Text=Lan.g(this,"Change");
				}
				textMemo.Text=journalCur.Memo;
				if(journalCur.CheckNumber!=""){
					textCheckNumber.Text=journalCur.CheckNumber;
				}
				if(journalOther.CheckNumber!="") {
					textCheckNumber.Text=journalOther.CheckNumber;
				}
			}
			JournalList=new List<JournalEntry>();
		}
		/*private void comboAccount_SelectedIndexChanged(object sender,EventArgs e) {
			FillAccount();
		}*/

		private void butChange_Click(object sender,EventArgs e) {
			FormAccountPick FormA=new FormAccountPick();
			FormA.ShowDialog();
			if(FormA.DialogResult!=DialogResult.OK){
				return;
			}
			AccountPicked=FormA.SelectedAccount;
			FillAccount();
		}
		private void FormJournalEntryEdit_Load(object sender, System.EventArgs e) {
			if(EntryCur==null){
				MessageBox.Show("Entry cannot be null.");
			}
			AccountPicked=Accounts.GetAccount(EntryCur.AccountNum);//might be null
			/*
			for(int i=0;i<Accounts.ListShort.Length;i++) {
				comboAccount.Items.Add(Accounts.ListShort[i].Description);
				if(Accounts.ListShort[i].AccountNum==EntryCur.AccountNum){
					comboAccount.SelectedIndex=i;
				}
			}
			if(EntryCur.AccountNum !=0 && comboAccount.SelectedIndex==-1){//must be an inactive account
				
			}*/
			FillAccount();
			if(EntryCur.DebitAmt>0){
				textDebit.Text=EntryCur.DebitAmt.ToString("n");
			}
			if(EntryCur.CreditAmt>0) {
				textCredit.Text=EntryCur.CreditAmt.ToString("n");
			}
			textMemo.Text=EntryCur.Memo;
			textCheckNumber.Text=EntryCur.CheckNumber;
			if(EntryCur.ReconcileNum==0){//not attached
				labelReconcile.Visible=false;
				textReconcile.Visible=false;
			}
			else{//attached
				textReconcile.Text=Reconciles.GetOne(EntryCur.ReconcileNum).DateReconcile.ToShortDateString();
				textDebit.ReadOnly=true;
				textCredit.ReadOnly=true;
				butDelete.Enabled=false;
				butChange.Enabled=false;
			}
		}
		private void butOK_Click(object sender, System.EventArgs e) {
			if(gridMain.GetSelectedIndex()==-1){
				MsgBox.Show(this,"Please select an account first.");
				return;
			}
			if(IsQuickBooks) {
				for(int i=0;i<gridMain.SelectedIndices.Length;i++) {
					SelectedAccountsQB.Add((string)(gridMain.Rows[gridMain.SelectedIndices[i]].Tag));
				}
			}
			else {
				SelectedAccount=((Account)gridMain.Rows[gridMain.GetSelectedIndex()].Tag).Clone();
			}
			DialogResult=DialogResult.OK;
		}
		private void gridMain_CellDoubleClick(object sender,ODGridClickEventArgs e) {
			if(IsQuickBooks) {
				SelectedAccountsQB.Add((string)gridMain.Rows[e.Row].Tag);
			}
			else {
				SelectedAccount=((Account)gridMain.Rows[e.Row].Tag).Clone();
			}
			DialogResult=DialogResult.OK;
		}
		private void Add_Click() {
			Account acct=new Account();
			acct.AcctType=AccountType.Asset;
			acct.AccountColor=Color.White;
			FormAccountEdit FormA=new FormAccountEdit(acct);
			FormA.IsNew=true;
			FormA.ShowDialog();
			FillGrid();
		}
		public static string JournalEntryInvalidAccountNum(bool verbose,bool isCheck) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				return Meth.GetString(MethodBase.GetCurrentMethod(),verbose,isCheck);
			}
			string log="";
			command="SELECT COUNT(*) FROM journalentry WHERE AccountNum NOT IN(SELECT AccountNum FROM account)";
			int numFound=PIn.Int(Db.GetCount(command));
			if(isCheck) {
				if(numFound > 0 || verbose) {
					log+=Lans.g("FormDatabaseMaintenance","Transactions found attached to an invalid account")+": "+numFound+"\r\n";
				}
			}
			else {
				if(numFound > 0 || verbose) {
					log+=Lans.g("FormDatabaseMaintenance","Transactions found attached to an invalid account")+": "+numFound+"\r\n";
				}
				if(numFound > 0) {
					//Check to see if there is already an active account called UNKNOWN.
					command="SELECT AccountNum FROM account WHERE Description='UNKNOWN' AND Inactive=0";
					long accountNum=PIn.Long(Db.GetScalar(command));
					if(accountNum==0) {
						//Create a new Account called UNKNOWN.
						Account account=new Account();
						account.Description="UNKNOWN";
						account.Inactive=false;//Just in case.
						account.AcctType=AccountType.Asset;//Default account type.  This DBM check was added to fix orphaned automatic payment journal entries, which should have been associated to an income account.
						accountNum=Accounts.Insert(account);
					}
					//Update the journalentry table.
					command="UPDATE journalentry SET AccountNum="+POut.Long(accountNum)+" WHERE AccountNum NOT IN(SELECT AccountNum FROM account)";
					Db.NonQ(command);
					log+=Lans.g("FormDatabaseMaintenance","   All invalid transactions have been attached to the account called UNKNOWN.")+"\r\n";
					log+=Lans.g("FormDatabaseMaintenance","   They need to be fixed manually.")+"\r\n";
				}
			}
			return log;
		}