예제 #1
0
        private void seçiliİşlemleriPDFyeAktarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.seçiliİşlemleriPDFyeAktarToolStripMenuItem.Enabled = false;

            this.BeginInvoke((MethodInvoker) delegate()
            {
                using (MuhasebeEntities m_Context = new MuhasebeEntities())
                {
                    List <AccountMovement> m_List = new List <AccountMovement>();

                    foreach (ListViewItem m_Item in this.Account_History_View.SelectedItems)
                    {
                        int m_MovementID = Convert.ToInt32(m_Item.Tag);

                        AccountMovement m_Movement = m_Context.AccountMovements.Where(q => q.ID == m_MovementID).FirstOrDefault();
                        m_List.Add(m_Movement);
                    }

                    m_List                   = m_List.OrderBy(q => q.CreatedAt).ToList();
                    Account m_Account        = m_List.FirstOrDefault().Account;
                    AccountSummary m_Summary = m_Account.GetSummary(m_List);

                    string m_Data            = "";
                    string m_SummaryTemplate = "Yukarıdaki işlemler sonucunda firmamız <strong>{0}</strong>";
                    string m_BaseTemplate    = "<tr class=\"movement\">" +
                                               "<td class=\"id\">{0}</td>" +
                                               "<td class=\"mtype\">{1}</td>" +
                                               "<td class=\"date\">{2}</td>" +
                                               "<td class=\"author\">{3}</td>" +
                                               "<td class=\"payment\">{4}</td>" +
                                               "<td class=\"desc\">{5}</td> " +
                                               "<td class=\"price\">{6}</td>" +
                                               "</tr>";

                    m_List.All(delegate(AccountMovement movement)
                    {
                        string m_Description = "";

                        if (movement.MovementTypeID != 3)                                    // ürün tedariğinde yorum yok
                        {
                            if (movement.MovementTypeID == 1 && movement.PaymentTypeID != 3) // Vadeli satış değilse
                            {
                                Income m_Income = m_Context.Incomes.Where(q => q.InvoiceID == movement.ContractID).FirstOrDefault();

                                if (m_Income != null)
                                {
                                    m_Description = m_Income.Description;
                                }
                            }
                            else if (movement.MovementTypeID == 2) // Alacak tahsilatı, gelir
                            {
                                Income m_Income = m_Context.Incomes.Where(q => q.ID == movement.ContractID).FirstOrDefault();

                                if (m_Income != null)
                                {
                                    m_Description = m_Income.Description;
                                }
                            }
                            else if (movement.MovementTypeID == 4) // Borç ödemesi, gider
                            {
                                Expenditure m_Expenditure = m_Context.Expenditures.Where(q => q.ID == movement.ContractID).FirstOrDefault();

                                if (m_Expenditure != null)
                                {
                                    m_Description = m_Expenditure.Description;
                                }
                            }
                        }

                        string m_Formatted = string.Format(m_BaseTemplate, movement.ID, movement.MovementType.Name, movement.CreatedAt.ToString("dd/MM/yyyy"),
                                                           movement.Author.FullName, movement.PaymentType.Name, m_Description, ItemHelper.GetFormattedPrice(movement.Value));

                        m_Data += m_Formatted;

                        if (movement.MovementTypeID == 1 || movement.MovementTypeID == 3) // satılan malları veya alınanları listeleyelim
                        {
                            string m_ExTemplate = "<tr>" +
                                                  "<td colspan=\"7\">" +
                                                  "<div class=\"columns sale\">" +
                                                  "<div class=\"order-code col\">Sipariş Kodu</div>" +
                                                  "<div class=\"name col\">Ürün Adı</div>" +
                                                  "<div class=\"amount col\">Miktar</div>" +
                                                  "<div class=\"base-price col\">Birim</div>" +
                                                  "<div class=\"total-price col\">Toplam</div>" +
                                                  "</div>" +
                                                  "{0}" +
                                                  "</td>" +
                                                  "</tr>";

                            string m_ExItemTemplate = "<div class=\"item\">" +
                                                      "<div class=\"order-code col\">{0}</div>" +
                                                      "<div class=\"name col\">{1}</div>" +
                                                      "<div class=\"amount col\">{2}</div>" +
                                                      "<div class=\"base-price col\">{3}</div>" +
                                                      "<div class=\"total-price col\">{4}</div>" +
                                                      "</div>";

                            if (movement.MovementTypeID == 1) //Mal satışı
                            {
                                Invoice m_Invoice = m_Context.Invoices.Where(q => q.ID == movement.ContractID).FirstOrDefault();

                                if (m_Invoice != null)
                                {
                                    string m_ExItemInfo = "";

                                    m_Invoice.Nodes.All(delegate(InvoiceNode node)
                                    {
                                        string m_OrderCode = node.Item != null ? node.Item.OrderCode : "-";
                                        string m_Name      = node.Item != null ? node.Item.Product.Name : node.Description;
                                        string m_Amount    = node.Item != null ? ItemHelper.GetFormattedAmount(node.Amount.Value, node.Item.UnitType.DecimalPlaces, node.Item.UnitType.Abbreviation)
                                                                            : ItemHelper.GetFormattedAmount(node.Amount.Value, 0, "Adet");
                                        string m_Base  = ItemHelper.GetFormattedPrice(node.BasePrice.Value);
                                        string m_Final = ItemHelper.GetFormattedPrice(node.FinalPrice.Value);

                                        m_ExItemInfo += string.Format(m_ExItemTemplate, m_OrderCode, m_Name, m_Amount, m_Base, m_Final);
                                        return(true);
                                    });

                                    m_ExItemInfo = string.Format(m_ExTemplate, m_ExItemInfo);
                                    m_Data      += m_ExItemInfo;
                                }
                            }
                            else if (movement.MovementTypeID == 3) //Mal alımı
                            {
                                StockMovement m_Stock = m_Context.StockMovements.Where(q => q.ID == movement.ContractID).FirstOrDefault();

                                if (m_Stock != null)
                                {
                                    string m_ExItemInfo = "";

                                    m_Stock.Nodes.All(delegate(StockMovementNode node)
                                    {
                                        string m_OrderCode = node.Item.OrderCode;
                                        string m_Name      = node.Item.Product.Name;
                                        string m_Amount    = ItemHelper.GetFormattedAmount(node.Amount, node.Item.UnitType.DecimalPlaces, node.Item.UnitType.Abbreviation);
                                        string m_Base      = ItemHelper.GetFormattedPrice(node.BasePrice.Value);
                                        string m_Final     = ItemHelper.GetFormattedPrice(node.FinalPrice.Value);

                                        m_ExItemInfo += string.Format(m_ExItemTemplate, m_OrderCode, m_Name, m_Amount, m_Base, m_Final);
                                        return(true);
                                    });

                                    m_ExItemInfo = string.Format(m_ExTemplate, m_ExItemInfo);
                                    m_Data      += m_ExItemInfo;
                                }
                            }
                        }

                        return(true);
                    });

                    if (m_Summary.Net < 0)
                    {
                        m_SummaryTemplate = string.Format(m_SummaryTemplate, string.Format("sizden {0} alacaklıdır.", ItemHelper.GetFormattedPrice(Math.Abs(m_Summary.Net))));
                    }
                    else if (m_Summary.Net > 0)
                    {
                        m_SummaryTemplate = string.Format(m_SummaryTemplate, string.Format("size {0} borçludur.", ItemHelper.GetFormattedPrice(Math.Abs(m_Summary.Net))));
                    }
                    else
                    {
                        this.Net_State_Label.Text = "Herhangi bir alacak/borç bulunmamaktadır.";
                    }

                    this.Save_Dialog.FileName = string.Format("{0} - İşlem Geçmişi.pdf", m_Account.Name);

                    if (this.Save_Dialog.ShowDialog() == DialogResult.OK)
                    {
                        string m_SavePath  = this.Save_Dialog.FileName;
                        string html        = "";
                        string m_LocalPath = Application.StartupPath;
                        string m_IndexPath = Path.Combine(m_LocalPath, "View\\AccountMovementsForm\\index.html");
                        string m_AbsPath   = Path.Combine(m_LocalPath, "View\\AccountMovementsForm\\");

                        using (StreamReader m_Reader = new StreamReader(m_IndexPath, Encoding.UTF8, true))
                        {
                            html = m_Reader.ReadToEnd();
                        }

                        html = html.Replace("{PATH}", m_AbsPath);
                        html = html.Replace("{BASEPATH}", m_LocalPath);
                        html = html.Replace("{COMPANY-NAME}", Program.User.WorksAt.Name);
                        html = html.Replace("{TAXID}", Program.User.WorksAt.TaxID);
                        html = html.Replace("{TAXPLACE}", Program.User.WorksAt.TaxDepartment);
                        html = html.Replace("{ADDRESS}", Program.User.WorksAt.Address);
                        html = html.Replace("{DISTRICT}", Program.User.WorksAt.District);
                        html = html.Replace("{PROVINCE}", Program.User.WorksAt.Province);
                        html = html.Replace("{TELEPHONE}", Program.User.WorksAt.Phone);
                        html = html.Replace("{EMAIL}", Program.User.WorksAt.Email);

                        html = html.Replace("{DATA}", m_Data);
                        html = html.Replace("{SUMMARY}", m_SummaryTemplate);

                        html = html.Replace("{ACCOUNT-NAME}", m_Account.Name);
                        html = html.Replace("{ACCOUNT-TAXOFFICE", m_Account.TaxDepartment);
                        html = html.Replace("{ACCOUNT-TAXID}", m_Account.TaxID);
                        html = html.Replace("{ACCOUNT-ADDRESS}", m_Account.Address);
                        html = html.Replace("{ACCOUNT-CITY}", m_Account.City.Name);
                        html = html.Replace("{ACCOUNT-PROVINCE}", m_Account.Province.Name);
                        html = html.Replace("{ACCOUNT-PHONE}", m_Account.Phone);
                        html = html.Replace("{ACCOUNT-GSM}", m_Account.Gsm);
                        html = html.Replace("{ACCOUNT-EMAIL}", m_Account.Email);

                        try
                        {
                            var pdf = Pdf
                                      .From(html)
                                      .OfSize(PaperSize.A4)
                                      .WithTitle("Title")
                                      .WithMargins(0.8.Centimeters())
                                      .WithoutOutline()
                                      .Portrait()
                                      .Comressed()
                                      .Content();

                            FileStream m_Stream = new FileStream(m_SavePath, FileMode.Create);

                            using (BinaryWriter m_Writer = new BinaryWriter(m_Stream))
                            {
                                m_Writer.Write(pdf, 0, pdf.Length);
                            }

                            m_Stream.Close();
                            m_Stream.Dispose();
                            MessageBox.Show("Pdf dosyası oluşturuldu.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch (Exception ex)
                        {
                            Logger.Enqueue(ex);
                            MessageBox.Show("Oluşan bir hata nedeniyle pdf dosyası yazılamadı. Lütfen tekrar deneyin.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            });

            this.seçiliİşlemleriPDFyeAktarToolStripMenuItem.Enabled = true;
        }
예제 #2
0
        private void EditMovement(AccountMovement movement)
        {
            switch (movement.MovementTypeID)
            {
            case 1:     // Ticari Mat Satışı Yapıldı
            {
                using (MuhasebeEntities m_Context = new MuhasebeEntities())
                {
                    Invoice m_Invoice = m_Context.Invoices.Where(q => q.ID == movement.ContractID).FirstOrDefault();
                    m_Context.Entry(m_Invoice).State = System.Data.Entity.EntityState.Detached;

                    if (m_Invoice != null)
                    {
                        Edit_Sale_Mdi m_Mdi = new Edit_Sale_Mdi();
                        m_Mdi.Invoice = m_Invoice;
                        m_Mdi.ShowDialog();
                    }
                }

                break;
            }

            case 2:     // Alacak tahsilatı yapıldı
            {
                using (MuhasebeEntities m_Context = new MuhasebeEntities())
                {
                    Income m_Income = m_Context.Incomes.Where(q => q.ID == movement.ContractID).FirstOrDefault();
                    m_Context.Entry(m_Income).State = System.Data.Entity.EntityState.Detached;

                    if (m_Income != null)
                    {
                        Edit_Revenue_Pop m_Pop = new Edit_Revenue_Pop();
                        m_Pop.Income = m_Income;
                        m_Pop.ShowDialog();
                    }
                }

                break;
            }

            case 3:     //Ürün Tedariği Yapıldı
            {
                StockMovement m_StockMovement = null;

                using (MuhasebeEntities m_Context = new MuhasebeEntities())
                {
                    m_StockMovement = m_Context.StockMovements.Where(q => q.ID == movement.ContractID).FirstOrDefault();
                    //m_Context.Entry(m_StockMovement).State = System.Data.Entity.EntityState.Detached;
                };

                if (m_StockMovement != null)
                {
                    Edit_StockMovement_Mdi m_Mdi = new Edit_StockMovement_Mdi();
                    m_Mdi.StockMovement = m_StockMovement;
                    m_Mdi.ShowDialog();
                }


                break;
            }

            case 4:     //Borç ödemesi yapıldı
            {
                using (MuhasebeEntities m_Context = new MuhasebeEntities())
                {
                    Expenditure m_Expenditure = m_Context.Expenditures.Where(q => q.ID == movement.ContractID).FirstOrDefault();
                    m_Context.Entry(m_Expenditure).State = System.Data.Entity.EntityState.Detached;

                    if (m_Expenditure != null)
                    {
                        Edit_Expenditure_Pop m_Pop = new Edit_Expenditure_Pop();
                        m_Pop.Expenditure = m_Expenditure;
                        m_Pop.ShowDialog();
                    }
                }

                break;
            }
            }

            this.PopulateAccountHistory(movement.Account);
        }
예제 #3
0
        private void Delete_Movement_Button_Click(object sender, EventArgs e)
        {
            if (this.Account_History_View.SelectedItems.Count > 0)
            {
                int m_MovementID = Convert.ToInt32(this.Account_History_View.SelectedItems[0].Tag);

                using (MuhasebeEntities m_Context = new MuhasebeEntities())
                {
                    AccountMovement m_Movement = m_Context.AccountMovements.Where(q => q.ID == m_MovementID).FirstOrDefault();

                    if (m_Movement != null)
                    {
                        Account m_Account = m_Context.Accounts.Where(q => q.ID == m_Movement.AccountID).FirstOrDefault();

                        switch (m_Movement.MovementTypeID)
                        {
                        case 1:     //Ticari Mal Satışı (Peşin / Vadeli)
                        {
                            string message = "Yaptığınız {0} TL tutarındaki {1} satışa ait tüm gelir bilgileri silinecek, sattığınız ürünlerin adetleri stoğunuza geri eklenecek, onaylıyor musunuz?";

                            Invoice m_Invoice = m_Context.Invoices.Where(q => q.ID == m_Movement.ContractID).FirstOrDefault();

                            if (m_Invoice != null)
                            {
                                message = string.Format(message, m_Invoice.Nodes.Sum(q => q.FinalPrice).Value, m_Movement.PaymentTypeID == 3 ? "vadeli" : "peşin");

                                if (MessageBox.Show(message, "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    if (m_Movement.PaymentTypeID != 3)         // vadeli değil yani ödenmiş ve gelir oluşmuş
                                    {
                                        Income m_Income = m_Context.Incomes.Where(q => q.InvoiceID == m_Invoice.ID).FirstOrDefault();

                                        if (m_Income != null)
                                        {
                                            m_Context.Incomes.Remove(m_Income);
                                        }
                                    }

                                    m_Invoice.Nodes.All(delegate(InvoiceNode node)
                                        {
                                            node.Item.Amount += node.Amount.Value;

                                            return(true);
                                        });

                                    m_Context.InvoiceNodes.RemoveRange(m_Invoice.Nodes);
                                    m_Context.Invoices.Remove(m_Invoice);
                                }
                            }

                            m_Context.AccountMovements.Remove(m_Movement);
                            m_Context.SaveChanges();

                            break;
                        }

                        case 2:     //Vadenin Tahsilatı
                        {
                            string message = "Yaptığınız {0} TL tutarındaki alacak tahsilatı iptal edilecek ve bu işleme ait geliriniz silinecek, onaylıyor musunuz?";

                            Income m_Income = m_Context.Incomes.Where(q => q.ID == m_Movement.ContractID).FirstOrDefault();

                            if (m_Income != null)
                            {
                                message = string.Format(message, m_Income.Amount.Value);

                                if (MessageBox.Show(message, "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    m_Context.Incomes.Remove(m_Income);
                                }
                            }

                            m_Context.AccountMovements.Remove(m_Movement);
                            m_Context.SaveChanges();

                            break;
                        }

                        case 3:     //Ürün Tedariği Yapıldı
                        {
                            string message = "Yaptığınız {0} kalemlik mal tahsilatı iptal edilecek, \nBu işlem ile stoğunuza eklenmiş olan ürünler silinecektir. \nBu işlemden oluşan giderler silinecektir. \n\nOnaylıyor musunuz?";

                            StockMovement m_StockMov = m_Context.StockMovements.Where(q => q.ID == m_Movement.ContractID && q.OwnerID == Program.User.WorksAtID).FirstOrDefault();

                            if (m_StockMov != null)
                            {
                                message = string.Format(message, m_StockMov.Nodes.Count);

                                if (MessageBox.Show(message, "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    m_StockMov.Nodes.All(delegate(StockMovementNode m_Node)
                                        {
                                            m_Node.Item.Amount -= m_Node.Amount;

                                            return(true);
                                        });

                                    if (m_StockMov.PaymentTypeID != 3)
                                    {
                                        Expenditure m_Expenditure = m_Context.Expenditures.Where(q => q.MovementID == m_Movement.ID).FirstOrDefault();

                                        if (m_Expenditure != null)
                                        {
                                            m_Context.Expenditures.Remove(m_Expenditure);
                                        }
                                    }

                                    m_Context.AccountMovements.Remove(m_Movement);
                                    m_Context.SaveChanges();
                                }
                            }

                            break;
                        }

                        case 4:     // Borç ödemesi yapıldı.
                        {
                            string message = "Yaptığınız {0} TL tutarındaki borç ödemesi silinecektir. \nBu işleme ait, gider yönetiminde gözüken gideriniz de silinecektir. \n\nOnaylıyor musunuz?";


                            Expenditure m_Expenditure = m_Context.Expenditures.Where(q => q.ID == m_Movement.ContractID && q.OwnerID == Program.User.WorksAtID).FirstOrDefault();

                            if (m_Expenditure != null)
                            {
                                message = string.Format(message, m_Expenditure.Amount.Value);

                                if (MessageBox.Show(message, "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    m_Context.Expenditures.Remove(m_Expenditure);
                                }
                            }

                            m_Context.AccountMovements.Remove(m_Movement);
                            m_Context.SaveChanges();


                            break;
                        }
                        }

                        PopulateAccountHistory(m_Account);
                    }
                }
            }
        }
예제 #4
0
 void Pop_RevenueEdited(Income income)
 {
     PopulateListView();
 }
예제 #5
0
        private void Delete_Button_Click(object sender, EventArgs e)
        {
            if (this.Revenue_List.SelectedItems.Count > 0)
            {
                ListViewItem m_Selected = this.Revenue_List.SelectedItems[0];

                if (m_Selected.Tag != null)
                {
                    MuhasebeEntities m_Context = new MuhasebeEntities();
                    int    m_ItemID            = Convert.ToInt32(m_Selected.Tag);
                    Income m_Income            = m_Context.Incomes.Where(q => q.ID == m_ItemID).FirstOrDefault();

                    if (m_Income.AuthorID == Program.User.ID || Program.User.Position.ID == 1)
                    {
                        if (m_Income.InvoiceID != null && m_Income.InvoiceID != 0)
                        {
                            AccountMovement m_Movement = m_Context.AccountMovements.Where(q => q.MovementTypeID == 1 && q.ContractID == m_Income.InvoiceID).FirstOrDefault();
                            // peşin satış sonucu oluşan faturayı ve gelirin kendisini, hareketi de siliyoruz

                            if (m_Movement != null)
                            {
                                m_Context.AccountMovements.Remove(m_Movement); // Ticari Mal Satışı yada Alacak tahsilatı olan gelire ait hareketi sil
                            }
                            m_Income.Invoice.Nodes.All(delegate(InvoiceNode node)
                            {
                                if (node.Item != null)
                                {
                                    node.Item.Amount += node.Amount.Value;
                                }

                                return(true);
                            });

                            m_Context.InvoiceNodes.RemoveRange(m_Income.Invoice.Nodes);
                            m_Context.Invoices.Remove(m_Income.Invoice);
                        }
                        else   //Bu gelirin faturası yok, bir vade tahsilatı olabilir?
                        {
                            AccountMovement m_Movement = m_Context.AccountMovements.Where(q => q.MovementTypeID == 2 && q.ContractID == m_Income.ID).FirstOrDefault();

                            if (m_Movement != null)
                            {
                                m_Context.AccountMovements.Remove(m_Movement);
                            }
                        }

                        m_Context.Incomes.Remove(m_Income);
                        m_Context.SaveChanges();
                        m_Selected.Remove();

                        PopulateListView();
                    }
                    else
                    {
                        MessageBox.Show("Bu nesneyi silmek için yetkiniz bulunmamaktadır", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Silme işlemi sırasında bir hata oluştu", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #6
0
 void m_Pop_RevenueAdded(Income income)
 {
     this.PopulateListView();
 }
예제 #7
0
        private void Sale_Button_Click(object sender, EventArgs e)
        {
            int m_PaymentTypeID = Convert.ToInt32(this.Payment_Combo.SelectedValue);

            if (m_PaymentTypeID == 3 && this.Account_Box.SelectedValue == null)
            {
                MessageBox.Show("Vadeli satışı ancak bir cari hesaba yapabilirsiniz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (MuhasebeEntities m_Context = new MuhasebeEntities())
            {
                if (this.Invoice != null && this.Invoice.Nodes.Count > 0)
                {
                    this.Invoice.OwnerID       = Program.User.WorksAtID.Value;
                    this.Invoice.PaymentTypeID = Convert.ToInt32(this.Payment_Combo.SelectedValue);
                    this.Invoice.CreatedAt     = DateTime.Now;
                    this.Invoice.AuthorID      = Program.User.ID;

                    this.Invoice.State = "Complete";

                    decimal m_Total = 0;
                    decimal m_Tax   = 0;

                    this.Invoice.Nodes.All(delegate(InvoiceNode m_Node)
                    {
                        m_Total += m_Node.FinalPrice.Value;
                        m_Tax   += m_Node.FinalPrice.Value * ((decimal)(m_Node.Tax.Value / 100));

                        if (this.Decrease_Stock_Check.Checked && m_Node.Item != null)
                        {
                            m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault().Amount -= m_Node.Amount.Value;
                        }

                        m_Node.Invoice = this.Invoice;
                        m_Node.Item    = null;

                        return(true);
                    });

                    if (this.Invoice.Discount.HasValue)
                    {
                        m_Total = m_Total - this.Invoice.Discount.Value;
                    }

                    m_Context.Invoices.Add(this.Invoice);
                    m_Context.SaveChanges();


                    if (this.Invoice.PaymentTypeID != 3) //Vadeli bir satış değilse gelir olarak geçmişe ekleyelim
                    {
                        Income m_Income = new Income();
                        m_Income.Amount       = m_Total;
                        m_Income.AuthorID     = Program.User.ID;
                        m_Income.CreatedAt    = DateTime.Now;
                        m_Income.Description  = "Ticari mal satışı yapıldı.";
                        m_Income.IncomeTypeID = 1; // Genel
                        m_Income.InvoiceID    = this.Invoice.ID;
                        m_Income.OwnerID      = Program.User.WorksAtID;

                        if (this.Account_Box.SelectedValue != null)
                        {
                            int m_AccountID = Convert.ToInt32(this.Account_Box.SelectedValue);
                            m_Income.AccountID = m_AccountID;
                        }

                        m_Context.Incomes.Add(m_Income);
                    }

                    m_Context.SaveChanges();

                    string toWho       = "bilinmeyen bir müşteriye";
                    string paymentText = "peşin";

                    if (this.Account_Box.SelectedValue != null)
                    {
                        int m_AccountID = Convert.ToInt32(this.Account_Box.SelectedValue);

                        Account m_Account = m_Context.Accounts.Where(q => q.ID == m_AccountID).FirstOrDefault();

                        if (m_Account != null)
                        {
                            toWho = string.Format("{0} adlı hesaba", m_Account.Name);

                            AccountMovement m_Movement = new AccountMovement();
                            m_Movement.AccountID      = m_Account.ID;
                            m_Movement.AuthorID       = Program.User.ID;
                            m_Movement.MovementTypeID = 1; // Kasadan satış
                            m_Movement.ContractID     = this.Invoice.ID;
                            m_Movement.CreatedAt      = DateTime.Now;
                            m_Movement.OwnerID        = Program.User.WorksAtID.Value;
                            m_Movement.PaymentTypeID  = this.Invoice.PaymentTypeID.Value;
                            m_Movement.Value          = m_Total; // m_Income.Amount.Value;

                            this.Invoice.TargetID = m_Account.ID;

                            m_Context.AccountMovements.Add(m_Movement);
                        }
                    }

                    if (this.Invoice.PaymentTypeID == 3)
                    {
                        paymentText = "vadeli";
                    }

                    Event m_Event = new Event();
                    m_Event.AuthorID    = Program.User.ID;
                    m_Event.CategoryID  = 4; // Satış
                    m_Event.CreatedAt   = DateTime.Now;
                    m_Event.Description = string.Format("Kullanıcı {0} {1} TL değerinde {2} satış yaptı.", toWho, m_Total, paymentText);
                    m_Event.OwnerID     = Program.User.WorksAtID;

                    m_Context.Events.Add(m_Event);

                    m_Context.SaveChanges();

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Satılabilecek herhangi bir ürün yok.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }