private void btnTogglePaid_Click(object sender, System.EventArgs e) { if (this.lstInvoices.SelectedIndices.Count > 0) { long id = long.Parse(this.lstInvoices.Items[this.lstInvoices.SelectedIndices[0]].SubItems[0].Text); Invoice inv = this.db.Invoices.First((Invoice x) => x.InvoiceID == id); if (inv.Sale) { long num = inv.TotalPrice; if (inv.Discount == 0L) { try { DailyTransaction dailyTransaction = this.db.DailyTransactions.First((DailyTransaction x) => x.Description.Contains("اضافه دریافت فاکتور " + (object)id)); num += dailyTransaction.Price; } catch { } } else num -= inv.Discount; if (inv.Customer.ID != -1L) { long accountid = 0; long CustomID = inv.Customer.ID; try { accountid = db.Accounts.First( x => x.DistributorID == CustomID).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = inv.Customer.Name, Description = " ", CustomerID = CustomID, DistributorID = 0, BankAccountID = 0 }; db.Accounts.AddObject(newAcc); db.SaveChanges(); accountid = db.Accounts.OrderByDescending(x => x.Id).First().Id; } Customer customer = this.db.Customers.First((Customer x) => x.ID == inv.Customer.ID); if (inv.Paid) { customer.Debt += num; Document newDoc = new Document { AccountID = accountid, Description = "برگشت وجه فاکتور " + inv.InvoiceID, Value = num, Date = Utilities.getCurrentPersianDate(), SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = true }; db.Documents.AddObject(newDoc); } else { customer.Debt -= num; Document newDoc = new Document { AccountID = accountid, Description = "پرداخت فاکتور " + inv.InvoiceID, Value = num, Date = Utilities.getCurrentPersianDate(), SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = false }; db.Documents.AddObject(newDoc); } db.Customers.ApplyCurrentValues(customer); } } inv.Paid = !inv.Paid; db.Invoices.ApplyCurrentValues(inv); this.db.SaveChanges(); this.lstInvoices.Items[this.lstInvoices.SelectedIndices[0]].SubItems[6].Text = (( this.lstInvoices.Items[this.lstInvoices.SelectedIndices[0]].SubItems[6].Text == "پ شده") ? "پ نشده" : "پ شده"); } }
public static void SaveInvoiceDocument(Invoice Inv) { var db = new StoreDBEntities(); if (Inv.Sale && (Inv.TarafID < 0 || Inv.Paid)) return; long accountid = 0; try { accountid = db.Accounts.AsEnumerable().First(x => x.DistributorID == Inv.TarafID).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = Inv.Distributor.Name, Description = " ", CustomerID = Inv.Sale ? Inv.TarafID : 0, DistributorID = Inv.Sale ? 0 : Inv.TarafID, BankAccountID = 0 }; db.Accounts.AddObject(newAcc); db.SaveChanges(); accountid = db.Accounts.OrderByDescending(x => x.Id).First().Id; //db.AcceptAllChanges(); //db = new StoreDBEntities(); } Document newDocCred = new Document { AccountID = accountid, Description = "فاکتور "+ (Inv.Sale ? "ف" : "خ") +" شماره " + Inv.InvoiceID, Value = Inv.TotalPrice + Inv.Expenses - Inv.Discount, Date = Inv.Date, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = Inv.Sale ? true : false, InvoiceID = Inv.InvoiceID }; db.Documents.AddObject(newDocCred); db.SaveChanges(); }
public static void SaveCashPayDocument(Invoice Inv) { var db = new StoreDBEntities(); long accountid = 0; try { accountid = db.Accounts.AsEnumerable().First(x => x.DistributorID == Inv.TarafID).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = Inv.Distributor.Name, Description = " ", CustomerID = 0, DistributorID = Inv.TarafID, BankAccountID = 0 }; db.Accounts.AddObject(newAcc); db.SaveChanges(); accountid = db.Accounts.OrderByDescending(x => x.Id).First().Id; //db.AcceptAllChanges(); //db = new StoreDBEntities(); } Document newDocDebt = new Document { AccountID = accountid, Description = "پرداخت نقد فاکتور " + Inv.InvoiceID, Value = Inv.TotalPrice + Inv.Expenses - Inv.Discount, Date = Inv.Date, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = true, InvoiceID = Inv.InvoiceID }; db.Documents.AddObject(newDocDebt); db.SaveChanges(); }
private void btnSavePayment_Click(object sender, System.EventArgs e) { if (this.txtPaymentPrice.TextLength > 0) { if (this.cmbPaymentTypes.Text == "موجودی") { int i = 0; while (i < this.lstPayments.Items.Count) { if (this.lstPayments.Items[i].SubItems[1].Text == "موجودی") { if (FarsiMessage.Show("موجودی قبلاً ثبت شده است. مقدار جدید برای موجودی امروز ثبت شود؟", "تکراری", FarsiMessageBoxButtons.YesNo,FarsiMessageBoxIcons.Question) == DialogResult.Yes) { this.dailyTransactionTableAdapter.DeleteByID(long.Parse(this.lstPayments.Items[i].SubItems[0].Text)); this.lstPayments.Items.RemoveAt(i); break; } return; } else { i++; } } } long newID = (long)this.dailyTransactionTableAdapter.InsertQuery(this.abrDateToday.SelectedDateString, long.Parse(this.txtPaymentPrice.Text), true, this.txtPaymentDescription.Text); if (this.cmbBankAccounts.Visible) { this.bankAccountTableAdapter.IncreaseBalance(long.Parse(this.txtPaymentPrice.Text), (long)this.cmbBankAccounts.SelectedValue); } //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ if(cmbPaymentTypes.Text.Contains("واریز به حساب")) { StoreDBEntities DB = new StoreDBEntities(); long bankID = 0; try { bankID = DB.Accounts.First(x => x.BankAccountID == (long)cmbBankAccounts.SelectedValue).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = "بانک " + cmbBankAccounts.Text, Description = " ", CustomerID = 0, DistributorID = 0, BankAccountID = (long)cmbBankAccounts.SelectedValue }; DB.Accounts.AddObject(newAcc); DB.SaveChanges(); bankID = DB.Accounts.OrderByDescending(x => x.Id).First().Id; } Document newBankDoc = new Document { AccountID = bankID, Description = "واریز نقد", Value = long.Parse(txtPaymentPrice.Text), Date = abrDateToday.SelectedDateString, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = true, TransactionID = newID }; DB.Documents.AddObject(newBankDoc); DB.SaveChanges(); } //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ this.txtPaymentPrice.Clear(); this.DateChanged(); this.FixList(); return; } this.errorProvider.SetError(this.lblPaymentPrice, "مبلغ وارد نشده است"); }
private void btnCreateInvoice_Click(object sender, System.EventArgs e) { if (this.total == 0L) { FarsiMessage.Show("مجموع فاکتور صفر است", "", FarsiMessageBoxButtons.OK, FarsiMessageBoxIcons.Stop); return; } string selectedDateString = this.abrInvoiceDate.SelectedDateString; if (this.edit) { List<InvoiceItem> list = editInv.InvoiceItems.ToList<InvoiceItem>(); for (int i = 0; i < list.Count; i++) { long invItemId = list[i].ID; this.db.InvoiceItems.DeleteObject(this.db.InvoiceItems.First((InvoiceItem x) => x.ID == invItemId)); long itemID = list[i].ItemID; Item item = this.db.Items.First((Item x) => x.ItemID == itemID); item.Available += list[i].Count; } this.GenInvoiceID = this.editInv.InvoiceID; Invoice invoice = this.db.Invoices.First((Invoice x) => x.InvoiceID == this.GenInvoiceID); invoice.TarafID = (long)this.cmbCustomers.SelectedValue; invoice.Paid = (this.cmbCustomers.SelectedIndex <= 0 || !this.chkUnPaidInvoice.Checked); invoice.Discount = this.discount; invoice.TotalPrice = this.total; invoice.Expenses = this.expenses; invoice.Description = ""; invoice.Date = this.abrInvoiceDate.SelectedDateString; this.db.Invoices.ApplyCurrentValues(invoice); this.db.SaveChanges(); this.edit = false; } else { Invoice newInv = new Invoice() { Sale = true, TarafID = (long)this.cmbCustomers.SelectedValue, Date = selectedDateString, Paid = this.cmbCustomers.SelectedIndex == 0 || !this.chkUnPaidInvoice.Checked, TotalPrice = this.total, Discount = this.discount, Expenses = this.expenses, Description = "" }; db.Invoices.AddObject(newInv); db.SaveChanges(); GenInvoiceID = newInv.InvoiceID; long accountid = 0; if (cmbCustomers.SelectedIndex > 0) { try { accountid = db.Accounts.First(x => x.CustomerID == (long)cmbCustomers.SelectedValue).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = cmbCustomers.Text, Description = " ", DistributorID = 0, CustomerID = (long)cmbCustomers.SelectedValue, BankAccountID = 0 }; db.Accounts.AddObject(newAcc); db.SaveChanges(); accountid = db.Accounts.OrderByDescending(x => x.Id).First().Id; } try { Document docEdit = db.Documents.First(x => x.InvoiceID == GenInvoiceID && x.Debt_Credit == true); docEdit.Value = total - discount; db.Documents.ApplyCurrentValues(docEdit); } catch { Document newDocDebt = new Document { AccountID = accountid, Description = "فاکتور ف " + GenInvoiceID, Value = total - discount, Date = abrInvoiceDate.SelectedDateString, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = true, InvoiceID = GenInvoiceID }; db.Documents.AddObject(newDocDebt); } try { Document docPayEdit = db.Documents.First(x => x.InvoiceID == GenInvoiceID && x.Debt_Credit == false); if (!this.chkUnPaidInvoice.Checked) { docPayEdit.Value = total - discount; db.Documents.ApplyCurrentValues(docPayEdit); } else db.Documents.DeleteObject(docPayEdit); } catch { if (!this.chkUnPaidInvoice.Checked) { Document newDocPay = new Document { AccountID = accountid, Description = "پرداخت فاکتور فروش " + GenInvoiceID, Value = total - discount, Date = abrInvoiceDate.SelectedDateString, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = false, InvoiceID = GenInvoiceID }; db.Documents.AddObject(newDocPay); } } db.SaveChanges(); } ClearTempItems(); timestamp = Utilities.getCurrentTimeStamp(); lblTimestamp.Text = timestamp.ToString(); } this.daily = this.dailyTransactionTableAdapter.GetData().ToList<StoreDBDataSet.DailyTransactionRow>().FirstOrDefault((StoreDBDataSet.DailyTransactionRow x) => x.Description == "اضافه دریافت فاکتور " + GenInvoiceID); if(daily != null) this.dailyTransactionTableAdapter.DeleteByID(this.daily.ID); // if (numExpenses.Value>0) // this.dailyTransactionTableAdapter.Insert(selectedDateString, this.expenses, false, "اضافه دریافت فاکتور " + this.GenInvoiceID); // else if (this.discount > 0L) // this.dailyTransactionTableAdapter.Insert(selectedDateString, this.discount, true, "تخفیف فاکتور " + this.GenInvoiceID); for (int i = 0; i < this.lstTotal.Items.Count; i++) { long num2 = long.Parse(this.lstTotal.Items[i].SubItems[0].Text); this.invoiceItemTableAdapter.Insert(this.GenInvoiceID, num2, int.Parse(this.lstTotal.Items[i].SubItems[2].Text.Replace(",", "")), int.Parse(this.lstTotal.Items[i].SubItems[3].Text)); //this.itemTableAdapter.GetDataByItemID(num2); this.itemTableAdapter.UpdateAvailable(int.Parse(this.lstTotal.Items[i].SubItems[3].Text), num2); } if (this.cmbCustomers.SelectedIndex > 0) { StoreDBDataSet.CustomerRow customerRow = this.customerTableAdapter.GetData().First((StoreDBDataSet.CustomerRow x) => x.ID == (long)this.cmbCustomers.SelectedValue); this.customerTableAdapter.UpdateByID(customerRow.Name, this.chkUnPaidInvoice.Checked ? (customerRow.Debt + this.total + this.expenses - this.discount) : customerRow.Debt, customerRow.LastPayment, selectedDateString, customerRow.ID); } if (this.chkReportOutput.Checked) { var rep = stiReport1.SaveToString(); this.invoiceItemTableAdapter.FillByInvoiceID(this.storeDBDataSet.InvoiceItem, this.GenInvoiceID); this.itemTableAdapter.Fill(this.storeDBDataSet.Item); this.invoiceTableAdapter.Fill(this.storeDBDataSet.Invoice); this.customerTableAdapter.Fill(this.storeDBDataSet.Customer); this.stiReport1.RegData(this.storeDBDataSet); this.stiReport1.Show(false); stiReport1.LoadFromString(rep); } //this.FillTable(this.itemTableAdapter.GetData()); db = new StoreDBEntities(); this.lstTotal.Items.Clear(); this.lblTotalPrice.Text = ""; this.ComputeTotal(false); this.numDiscount.Value = 0m; this.numExpenses.Value = 0m; this.cmbCustomers.SelectedIndex = 0; this.chkUnPaidInvoice.Checked = false; this.txtItemNameID.Clear(); this.txtItemNameID.Focus(); }
private void btnSaveDebt_Click(object sender, EventArgs e) { string selectedDate = ((MainForm)base.MdiParent).abrMainDate.SelectedDateString; StoreDBEntities storeDBEntities = new StoreDBEntities(); long currDebt = (long)numCurrentDebt.Value; long newDebt = (long)numNewDebt.Value; if (newDebt == currDebt) return; else { long accountid = 0; long CustomID = long.Parse(txtCustomerID.Text); try { accountid = storeDBEntities.Accounts.First( x => x.CustomerID == CustomID).Id; //MessageBox.Show("cust found"+accountid); } catch (InvalidOperationException) { Account newAcc = new Account { Name = txtCustomerName.Text, Description = " ", CustomerID = CustomID, DistributorID = 0, BankAccountID = 0 }; storeDBEntities.Accounts.AddObject(newAcc); storeDBEntities.SaveChanges(); accountid = storeDBEntities.Accounts.OrderByDescending(x => x.Id).First().Id; // MessageBox.Show("cust made"+accountid); } if (newDebt > currDebt) { this.dailyTransactionTableAdapter.Insert( selectedDate, newDebt - currDebt, true, "پرداخت وجه به " + this.txtCustomerName.Text); Document newDoc = new Document() { AccountID = accountid, Description = "وجه دستی", Value = newDebt - currDebt, Date = selectedDate, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = true }; storeDBEntities.Documents.AddObject(newDoc); storeDBEntities.SaveChanges(); // MessageBox.Show("doc + done"+newDoc.Id); } else if (newDebt < currDebt) { this.dailyTransactionTableAdapter.Insert( selectedDate, currDebt - newDebt, false, "پرداخت بدهی توسط " + this.txtCustomerName.Text); this.lstCustomers.SelectedItems[0].SubItems[3].Text = selectedDate; if (newDebt != 0L) { if (FarsiMessage.Show("مبلغ بدهی جدید کاهش یافته است\n\nآیا تمایل دارید برای تغییر وضعیت پرداخت فاکتورهای این مشتری به بخش مدیریت فاکتورها بروید؟", "تسویه ناقص بدهی", FarsiMessageBoxButtons.YesNo, FarsiMessageBoxIcons.Question) == DialogResult.Yes) (new InvoiceManageForm(custID, true)).Show(); } else { List<Invoice> invoices = storeDBEntities.Invoices.Where( (Invoice x) => x.Paid == false && x.TarafID == custID && x.Sale == true).ToList(); for (int i = 0; i < invoices.Count; i++) { invoices[i].Paid = true; storeDBEntities.Invoices.ApplyCurrentValues(invoices[i]); } } Document newDoc = new Document { AccountID = accountid, Description = "پرداخت نقد/با کارت", Value = currDebt - newDebt, Date = selectedDate, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = false }; storeDBEntities.Documents.AddObject(newDoc); Customer cst = storeDBEntities.Customers.AsEnumerable().First( x => x.ID == CustomID); cst.Debt = newDebt; cst.LastPayment = selectedDate; storeDBEntities.Customers.ApplyCurrentValues(cst); storeDBEntities.SaveChanges(); // MessageBox.Show("doc - done"+newDoc.Id); // MessageBox.Show("debt reduced"+CustomID); } } InitializeForm(); }
private void btnCreateSave_Click(object sender, System.EventArgs e) { if (this.edit) { long id = long.Parse(this.lstAccounts.SelectedItems[0].SubItems[0].Text); Account account = this.DB.Accounts.First((Account x) => x.Id == id); account.Name = this.txtName.Text; account.Description = this.txtDescription.Text; account.DistributorID = (this.chkDistributor.Checked ? ((long)this.cmbDistributor.SelectedValue) : 0L); account.CustomerID = (this.chkCustomer.Checked ? ((long)this.cmbCustomer.SelectedValue) : 0L); account.BankAccountID = (this.chkBank.Checked ? ((long)this.cmbBank.SelectedValue) : 0L); } else { long num = 0L; try { num = ( from x in this.DB.Accounts orderby x.Id descending select x).First<Account>().Id; } catch (System.InvalidOperationException) { } Account account2 = new Account{ Name = this.txtName.Text, Description = this.txtDescription.Text, CustomerID = this.chkCustomer.Checked ? ((long)this.cmbCustomer.SelectedValue) : 0L, DistributorID = this.chkDistributor.Checked ? ((long)this.cmbDistributor.SelectedValue) : 0L, BankAccountID = this.chkBank.Checked ? ((long)this.cmbBank.SelectedValue) : 0L}; //account2.Description = this.txtDescription.Text; this.DB.Accounts.AddObject(account2); } this.DB.SaveChanges(); this.ListAccounts(); this.RefreshInputs(); }
public static void SaveDocument(Cheque chq) { var DB = new StoreDBEntities(); long accountid = 0; try { accountid = DB.Accounts.First(x => x.DistributorID == chq.Invoice.TarafID).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = chq.Invoice.Distributor.Name, Description = " ", CustomerID = 0, DistributorID = chq.Invoice.TarafID, BankAccountID = 0 }; DB.Accounts.AddObject(newAcc); DB.SaveChanges(); accountid = DB.Accounts.OrderByDescending(x => x.Id).First().Id; } Document newDoc = new Document { AccountID = accountid, Description = "چک شماره" + chq.CheckNum + " بابت فاکتور خ شماره " + chq.InvoiceID, Value = chq.Price, Date = chq.Invoice.Date, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = true, ChequeID = chq.ID }; DB.Documents.AddObject(newDoc); DB.SaveChanges(); //-------------------------- long bankID = 0; try { bankID = DB.Accounts.First(x => x.BankAccountID == chq.BankAccount.ID).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = "بانک " + chq.BankAccount.BankName, Description = " ", CustomerID = 0, DistributorID = 0, BankAccountID = chq.BankAccount.ID }; DB.Accounts.AddObject(newAcc); DB.SaveChanges(); bankID = DB.Accounts.OrderByDescending(x => x.Id).First().Id; } Document newBankDoc = new Document { AccountID = bankID, Description = "چک شماره" + chq.CheckNum + " در وجه " + chq.Invoice.Distributor.Name, Value = chq.Price, Date = chq.Date, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = false, ChequeID = chq.ID }; DB.Documents.AddObject(newBankDoc); DB.SaveChanges(); }
/// <summary> /// Create a new Account object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="customerID">Initial value of the CustomerID property.</param> /// <param name="distributorID">Initial value of the DistributorID property.</param> /// <param name="bankAccountID">Initial value of the BankAccountID property.</param> public static Account CreateAccount(global::System.Int64 id, global::System.String name, global::System.Int64 customerID, global::System.Int64 distributorID, global::System.Int64 bankAccountID) { Account account = new Account(); account.Id = id; account.Name = name; account.CustomerID = customerID; account.DistributorID = distributorID; account.BankAccountID = bankAccountID; return account; }
/// <summary> /// Deprecated Method for adding a new object to the Accounts EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToAccounts(Account account) { base.AddObject("Accounts", account); }