Exemplo n.º 1
0
        private void Edit_StockMovement_Mdi_Load(object sender, EventArgs e)
        {
            EventSink.BarcodeScanned += EventSink_BarcodeScanned;

            if (this.StockMovement != null)
            {
                using (MuhasebeEntities m_Context = new MuhasebeEntities())
                {
                    this.StockMovement = m_Context.StockMovements.Where(q => q.ID == this.StockMovement.ID).FirstOrDefault();

                    this.CreatedAt_Picker.Value   = StockMovement.CreatedAt;
                    this.Account_Box.SelectedText = StockMovement.Account.Name;
                    this.Account_Box.Enabled      = false;

                    if (this.StockMovement.Discount.HasValue)
                    {
                        this.Discount_Num.Value = StockMovement.Discount.Value;
                    }
                    else
                    {
                        this.Discount_Num.Value = 0;
                    }

                    var m_PaymentTypes = m_Context.PaymentTypes.Where(q => q.OwnerID == null || q.OwnerID == Program.User.WorksAtID).ToList();

                    this.PaymentType_Combo.DataSource    = m_PaymentTypes;
                    this.PaymentType_Combo.ValueMember   = "ID";
                    this.PaymentType_Combo.DisplayMember = "Name";

                    this.PaymentType_Combo.Invalidate();

                    this.PaymentType_Combo.SelectedValue = StockMovement.PaymentTypeID;
                    this.PaymentType_Combo.Enabled       = false;

                    PopulateListView();
                }
            }

            if (this.StockMovement != null)
            {
                try
                {
                    var config = new MapperConfiguration(cfg => cfg.CreateMap <StockMovement, StockMovement>());
                    var mapper = config.CreateMapper();

                    this.StockMovement = mapper.Map <StockMovement>(StockMovement);
                }
                catch (Exception ex)
                {
                }
            }
        }
Exemplo n.º 2
0
        private void Buy_Items_Pop_Load(object sender, EventArgs e)
        {
            EventSink.BarcodeScanned += EventSink_BarcodeScanned;

            using (MuhasebeEntities m_Context = new MuhasebeEntities())
            {
                if (this.StockMovement == null)
                {
                    this.StockMovement = new StockMovement();
                }

                var m_PaymentTypes = m_Context.PaymentTypes.Where(q => q.OwnerID == null || q.OwnerID == Program.User.WorksAtID).ToList();

                this.PaymentType_Combo.DataSource    = m_PaymentTypes;
                this.PaymentType_Combo.ValueMember   = "ID";
                this.PaymentType_Combo.DisplayMember = "Name";

                this.PaymentType_Combo.Invalidate();
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
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);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void Save_Button_Click(object sender, EventArgs e)
        {
            if (this.StockMovement.Nodes == null || this.StockMovement.Nodes.Count <= 0)
            {
                MessageBox.Show("Ürün alımı için en az bir adet ürünü listeye eklemelisiniz.", "Hata");
                return;
            }

            int m_AccountID = Convert.ToInt32(this.Account_Box.SelectedValue);

            using (MuhasebeEntities m_Context = new MuhasebeEntities())
            {
                Account       m_Account = m_Context.Accounts.Where(q => q.ID == m_AccountID).FirstOrDefault();
                StockMovement m_Actual  = m_Context.StockMovements.Where(q => q.ID == this.StockMovement.ID).FirstOrDefault();

                if (m_Account != null)
                {
                    var m_Added   = this.StockMovement.Nodes.Except(m_Actual.Nodes, (p, p1) => p.ItemID == p1.ItemID).ToList();
                    var m_Deleted = m_Actual.Nodes.Except(this.StockMovement.Nodes, (p, p1) => p.ItemID == p1.ItemID).ToList();
                    var m_Changed = this.StockMovement.Nodes.Intersect(m_Actual.Nodes, (p, p1) => p.ItemID == p1.ItemID && (p.Amount != p1.Amount || p.BasePrice != p1.BasePrice)).ToList();

                    m_Actual.AccountID     = m_Account.ID;
                    m_Actual.CreatedAt     = CreatedAt_Picker.Value;
                    m_Actual.AuthorID      = Program.User.ID;
                    m_Actual.OwnerID       = Program.User.WorksAtID.Value;
                    m_Actual.PaymentTypeID = Convert.ToInt32(this.PaymentType_Combo.SelectedValue);

                    m_Deleted.All(delegate(StockMovementNode m_Node)
                    {
                        if (Decrese_Stock_Check.Checked)
                        {
                            m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault().Amount -= m_Node.Amount;
                        }

                        StockMovementNode m_ToDelete = m_Actual.Nodes.Where(q => q.ID == m_Node.ID).FirstOrDefault();
                        m_Actual.Nodes.Remove(m_ToDelete);
                        m_Context.Entry(m_ToDelete).State = System.Data.Entity.EntityState.Deleted;

                        return(true);
                    });

                    m_Added.All(delegate(StockMovementNode m_Node)
                    {
                        if (Increase_Stock_Check.Checked)
                        {
                            m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault().Amount += m_Node.Amount;
                        }

                        m_Actual.Nodes.Add(m_Node);

                        return(true);
                    });

                    m_Changed.All(delegate(StockMovementNode m_Node)
                    {
                        //actual node
                        StockMovementNode m_Anode = m_Actual.Nodes.Where(q => q.ID == m_Node.ID).FirstOrDefault();

                        if (m_Node.Amount > m_Anode.Amount && Increase_Stock_Check.Checked)
                        {
                            m_Context.Items.Where(q => q.ID == m_Anode.ItemID).FirstOrDefault().Amount += m_Node.Amount - m_Anode.Amount;
                        }

                        else if (m_Node.Amount < m_Anode.Amount && Decrese_Stock_Check.Checked)
                        {
                            m_Context.Items.Where(q => q.ID == m_Anode.ItemID).FirstOrDefault().Amount -= m_Anode.Amount - m_Node.Amount;
                        }

                        m_Anode.Amount    = m_Node.Amount;
                        m_Anode.BasePrice = m_Node.BasePrice;

                        return(true);
                    });


                    m_Actual.Nodes.All(delegate(StockMovementNode m_Node)
                    {
                        m_Node.Parent     = m_Actual;
                        m_Node.FinalPrice = m_Node.BasePrice * m_Node.Amount;

                        return(true);
                    });

                    m_Actual.Summary = m_Actual.Nodes.Sum(q => q.FinalPrice.Value);

                    if (this.StockMovement.Discount.HasValue)
                    {
                        m_Actual.Discount = this.StockMovement.Discount.Value;
                        m_Actual.Summary -= m_Actual.Discount.Value;
                    }

                    m_Context.SaveChanges();

                    AccountMovement movement = m_Context.AccountMovements.Where(q => q.MovementTypeID == 3 && q.ContractID == m_Actual.ID).FirstOrDefault();

                    if (movement != null)
                    {
                        movement.Value = m_Actual.Summary;
                    }

                    if (m_Actual.PaymentTypeID != 3) //Vadeli olmadığında, gideri doğrultalım
                    {
                        Expenditure m_Expenditure = m_Context.Expenditures.Where(q => q.AccountID == movement.AccountID && q.MovementID == movement.ID).FirstOrDefault();

                        if (m_Expenditure != null)
                        {
                            m_Expenditure.Amount = m_Actual.Summary;
                        }
                    }

                    m_Context.SaveChanges();

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Bu mal alımı için bir cari hesap belirtmelisiniz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }