Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 private void FixCounts()
 {
     StoreDBEntities storeDBEntities = new StoreDBEntities();
     System.Collections.Generic.List<Item> list = storeDBEntities.Items.ToList<Item>();
     this.progressBar1.Maximum = list.Count;
     for (int i = 0; i < list.Count; i++)
     {
         try
         {
             this.progressBar1.Value = i;
             long id = list[i].ItemID;
             string name = list[i].Name;
             long purchase = storeDBEntities.InvoiceItems.Where(x => x.Invoice.Sale == false && x.ItemID == id).Sum(x => x.Count);
             long sale = storeDBEntities.InvoiceItems.Where(x => x.Invoice.Sale == true && x.ItemID == id).Sum(x => x.Count);
             Item item = storeDBEntities.Items.First((Item x) => x.ItemID == id);
             item.Available = Convert.ToInt32(purchase - sale);
             DB.Items.ApplyCurrentValues(item);
         }
         catch (InvalidOperationException) { }
     }
     storeDBEntities.SaveChanges();
     this.btnFixItemCounts.Enabled = true;
     this.progressBar1.Value = 0;
     this.T.Abort();
 }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
0
        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, "مبلغ وارد نشده است");
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
 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();
 }
Ejemplo n.º 7
0
 private void MainForm_Load(object sender, System.EventArgs e)
 {
     base.WindowState = FormWindowState.Maximized;
     this.abrMainDate.SelectedDate = (System.DateTime.Now);
     this.ControlDailyCheques();
     this.Font = MainForm.FORM_FONT;
     this.menuStrip1.Font = new System.Drawing.Font(MainForm.FORM_FONT.FontFamily, 10f, System.Drawing.FontStyle.Bold);
     InputLanguage currentInputLanguage = InputLanguage.DefaultInputLanguage;
     for (int i = 0; i < InputLanguage.InstalledInputLanguages.Count; i++)
     {
         if (InputLanguage.InstalledInputLanguages[i].LayoutName == "Persian")
         {
             currentInputLanguage = InputLanguage.InstalledInputLanguages[i];
         }
     }
     InputLanguage.CurrentInputLanguage = currentInputLanguage;
     StoreDBEntities db = new StoreDBEntities();
     var tmpList = db.TempInvoices.ToList();
     for (int i = 0; i < tmpList.Count; i++)
     {
         db.TempInvoices.DeleteObject(tmpList[i]);
     }
     if (tmpList.Count > 0)
     {
         var itemsGrp = tmpList.GroupBy(x => x.TimeStamp).ToList();
         for (int i = 0; i < itemsGrp.Count; i++)
             (new InvoiceSaleForm(itemsGrp[i]){
                 MdiParent = this
             }).Show();
     }
     db.SaveChanges();
         
 }