Ejemplo n.º 1
0
        private void Edit_Movement_Button_Click(object sender, EventArgs e)
        {
            if (this.Account_History_View.SelectedItems.Count == 1)
            {
                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)
                    {
                        EditMovement(m_Movement);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void Save_Btn_Click(object sender, EventArgs e)
        {
            using (MuhasebeEntities m_Context = new MuhasebeEntities()) {
                Expenditure m_Expenditure = new Expenditure();

                m_Expenditure.CreatedAt         = this.CreatedAt_Picker.Value;
                m_Expenditure.ExpenditureTypeID = Convert.ToInt32(this.Expenditure_Combo.SelectedValue);
                m_Expenditure.Amount            = this.Cost_Num.Value;
                m_Expenditure.AuthorID          = Convert.ToInt32(this.Responsible_Combo.SelectedValue);
                m_Expenditure.OwnerID           = Program.User.WorksAtID;
                m_Expenditure.Description       = this.ExpenditureDesc_Text.Text;

                m_Context.Expenditures.Add(m_Expenditure);
                m_Context.SaveChanges();

                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)
                    {
                        m_Expenditure.AccountID = m_Account.ID;

                        AccountMovement m_Movement = new AccountMovement();
                        m_Movement.AccountID      = m_AccountID;
                        m_Movement.AuthorID       = Program.User.ID;
                        m_Movement.MovementTypeID = 4; // Borç ödemesi yapıldı.
                        m_Movement.OwnerID        = Program.User.WorksAtID.Value;
                        m_Movement.PaymentTypeID  = 1; //Peşin haliyle
                        m_Movement.Value          = m_Expenditure.Amount.Value;
                        m_Movement.ContractID     = m_Expenditure.ID;
                        m_Movement.CreatedAt      = this.CreatedAt_Picker.Value;

                        m_Context.AccountMovements.Add(m_Movement);
                        m_Expenditure.MovementID = m_Movement.ID;
                    }
                }

                m_Context.SaveChanges();

                InvokeExpenditureAdded(m_Expenditure);
                this.Close();
            }
        }
Ejemplo n.º 3
0
        private void Delete_Button_Click(object sender, EventArgs e)
        {
            if (this.Expenditure_List.SelectedItems.Count > 0)
            {
                ListViewItem m_Selected = this.Expenditure_List.SelectedItems[0];

                if (m_Selected.Tag != null)
                {
                    using (MuhasebeEntities m_Context = new MuhasebeEntities())
                    {
                        int m_ItemID = Convert.ToInt32(m_Selected.Tag);

                        Expenditure m_Expenditure = m_Context.Expenditures.Where(q => q.ID == m_ItemID).FirstOrDefault();

                        if (m_Expenditure.OwnerID != null && m_Expenditure.OwnerID == Program.User.WorksAtID)
                        {
                            if (m_Expenditure.MovementID.HasValue)
                            {
                                AccountMovement m_Movement = m_Context.AccountMovements.Where(q => q.ID == m_Expenditure.MovementID).FirstOrDefault();

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

                            m_Context.Expenditures.Remove(m_Expenditure);
                            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);
                }
            }
        }
Ejemplo n.º 4
0
        private void Save_Btn_Click(object sender, EventArgs e)
        {
            using (MuhasebeEntities m_Context = new MuhasebeEntities())
            {
                Income m_Income = new Income();
                m_Income.CreatedAt    = this.Revenue_Date_Picker.Value;
                m_Income.Amount       = this.Revenue_Amount_Num.Value;
                m_Income.AuthorID     = Convert.ToInt32(this.Responsible_Combo.SelectedValue);
                m_Income.Description  = this.Description_Box.Text;
                m_Income.IncomeTypeID = Convert.ToInt32(this.Revenue_Type_Combo.SelectedValue);
                m_Income.OwnerID      = Program.User.WorksAtID;

                m_Context.Incomes.Add(m_Income);
                m_Context.SaveChanges();

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

                    AccountMovement m_Movement = new AccountMovement();
                    m_Movement.CreatedAt      = this.Revenue_Date_Picker.Value;
                    m_Movement.AccountID      = m_AccountID;
                    m_Movement.AuthorID       = Program.User.ID;
                    m_Movement.ContractID     = m_Income.ID;
                    m_Movement.MovementTypeID = 2; //Alacak tahsilatı
                    m_Movement.OwnerID        = Program.User.WorksAtID.Value;
                    m_Movement.PaymentTypeID  = 1; //Nakit
                    m_Movement.Value          = m_Income.Amount.Value;

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

                InvokeRevenueAdded(m_Income);
            }

            this.Close();
        }
Ejemplo n.º 5
0
        private void Save_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;
                    }

                    Invoice m_Actual = m_Context.Invoices.Where(q => q.ID == this.Invoice.ID).FirstOrDefault();
                    m_Actual.OwnerID       = this.Invoice.OwnerID;
                    m_Actual.AuthorID      = this.Invoice.AuthorID;
                    m_Actual.CreatedAt     = this.Invoice.CreatedAt;
                    m_Actual.Discount      = this.Invoice.Discount;
                    m_Actual.PaymentTypeID = this.Invoice.PaymentTypeID;
                    m_Actual.State         = this.Invoice.State;
                    m_Actual.TargetID      = this.Invoice.TargetID;

                    var m_Added   = this.Invoice.Nodes.Except(m_Actual.Nodes, (p, p1) => p.ItemID == p1.ItemID).ToList();
                    var m_Deleted = m_Actual.Nodes.Except(this.Invoice.Nodes, (p, p1) => p.ItemID == p1.ItemID).ToList();
                    var m_Changed = m_Actual.Nodes.Intersect(this.Invoice.Nodes, (p, p1) => p.ItemID == p1.ItemID && (p.Amount != p1.Amount || p.BasePrice != p1.BasePrice || p.UseCustomPrice != p1.UseCustomPrice)).ToList();

                    m_Added.All(delegate(InvoiceNode m_Node)
                    {
                        if (Decrease_Stock_Check.Checked && m_Node.ItemID > 0)
                        {
                            m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault().Amount -= m_Node.Amount.Value;
                        }

                        m_Actual.Nodes.Add(m_Node);

                        return(true);
                    });

                    m_Deleted.All(delegate(InvoiceNode m_Node)
                    {
                        if (Increase_Stock_Check.Checked && m_Node.ItemID > 0)
                        {
                            m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault().Amount += m_Node.Amount.Value;
                        }

                        InvoiceNode m_ToDelete = m_Actual.Nodes.Where(q => q.ItemID == m_Node.ItemID).FirstOrDefault();

                        m_Actual.Nodes.Remove(m_ToDelete);
                        m_Context.Entry(m_ToDelete).State = System.Data.Entity.EntityState.Deleted;

                        return(true);
                    });

                    m_Changed.All(delegate(InvoiceNode m_Node)
                    {
                        InvoiceNode m_Knode = this.Invoice.Nodes.Where(q => q.ItemID == m_Node.ItemID).FirstOrDefault();

                        if (m_Knode != null)
                        {
                            if (m_Node.Amount > m_Knode.Amount)
                            {                                                          // Bazıları silinmiş
                                if (m_Node.ItemID > 0 && Increase_Stock_Check.Checked) //Eğer kayıt dışı satış değilse
                                {
                                    m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault().Amount += m_Node.Amount.Value - m_Knode.Amount.Value;
                                }
                            }
                            else if (m_Node.Amount < m_Knode.Amount)
                            {
                                if (m_Node.ItemID > 0 && Decrease_Stock_Check.Checked) // Kayıt dışı satış değisle
                                {
                                    m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault().Amount -= m_Knode.Amount.Value - m_Node.Amount.Value;
                                }
                            }

                            m_Node.Amount         = m_Knode.Amount;
                            m_Node.BasePrice      = m_Knode.BasePrice;
                            m_Node.FinalPrice     = m_Knode.FinalPrice;
                            m_Node.UseCustomPrice = m_Knode.UseCustomPrice;

                            if (m_Node.UseCustomPrice == null)
                            {
                                m_Node.UseCustomPrice = false;
                            }
                        }

                        return(true);
                    });

                    m_Actual.Nodes.All(delegate(InvoiceNode m_Node)
                    {
                        m_Node.Invoice = m_Actual;
                        m_Node.Item    = null;

                        return(true);
                    });

                    if (m_Actual.PaymentTypeID != 3) // Vadeli değil
                    {
                        Income m_Income = m_Context.Incomes.Where(q => q.InvoiceID == m_Actual.ID).FirstOrDefault();
                        m_Income.Amount = m_Total;
                    }

                    AccountMovement m_Movement = m_Context.AccountMovements.Where(q => q.AccountID == m_Actual.TargetID && q.ContractID == m_Actual.ID && q.MovementTypeID == 1).FirstOrDefault();

                    if (m_Movement != null)
                    {
                        m_Movement.Value = m_Total;
                    }

                    m_Context.SaveChanges();

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Satılabilecek herhangi bir ürün yok.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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);
                    }
                }
            }
        }
Ejemplo n.º 9
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);
                }
            }
        }
Ejemplo n.º 10
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();

                if (m_Account != null)
                {
                    this.StockMovement.Nodes.All(delegate(StockMovementNode m_Node)
                    {
                        m_Node.Parent     = this.StockMovement;
                        m_Node.Item       = null;
                        m_Node.FinalPrice = m_Node.BasePrice * m_Node.Amount;

                        return(true);
                    });

                    this.StockMovement.AccountID     = m_Account.ID;
                    this.StockMovement.CreatedAt     = CreatedAt_Picker.Value;
                    this.StockMovement.AuthorID      = Program.User.ID;
                    this.StockMovement.OwnerID       = Program.User.WorksAtID.Value;
                    this.StockMovement.PaymentTypeID = Convert.ToInt32(this.PaymentType_Combo.SelectedValue);
                    this.StockMovement.Summary       = this.StockMovement.Nodes.Sum(q => q.FinalPrice.Value);

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

                    m_Context.StockMovements.Add(this.StockMovement);
                    m_Context.SaveChanges();

                    AccountMovement m_Movement = new AccountMovement();
                    m_Movement.AccountID      = m_Account.ID;
                    m_Movement.AuthorID       = Program.User.ID;
                    m_Movement.ContractID     = this.StockMovement.ID;
                    m_Movement.CreatedAt      = CreatedAt_Picker.Value;
                    m_Movement.MovementTypeID = 3; // Ürün tedariği yapıldı
                    m_Movement.OwnerID        = Program.User.WorksAtID.Value;
                    m_Movement.PaymentTypeID  = this.StockMovement.PaymentTypeID;
                    m_Movement.Value          = this.StockMovement.Summary;

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

                    if (this.StockMovement.PaymentTypeID != 3) //Vadeli değil
                    {
                        Expenditure m_Expenditure = new Expenditure();
                        m_Expenditure.CreatedAt         = CreatedAt_Picker.Value;
                        m_Expenditure.Amount            = this.StockMovement.Summary;
                        m_Expenditure.AuthorID          = Program.User.ID;
                        m_Expenditure.ExpenditureTypeID = 5; //Ürün alım gideri
                        m_Expenditure.OwnerID           = Program.User.WorksAtID;
                        m_Expenditure.AccountID         = this.StockMovement.AccountID;
                        m_Expenditure.Description       = "Yapılan ürün/hizmet alımı karşılığı peşin ödendi.";
                        m_Expenditure.MovementID        = m_Movement.ID;

                        m_Context.Expenditures.Add(m_Expenditure);
                    }

                    if (this.Increase_Stock_Check.Checked) // alınan mallar sonucu stoğu artıralım
                    {
                        this.StockMovement.Nodes.All(delegate(StockMovementNode m_Node)
                        {
                            m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault().Amount += m_Node.Amount;

                            return(true);
                        });
                    }

                    m_Context.SaveChanges();

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Bu mal alımı için bir cari hesap belirtmelisiniz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 11
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);
                }
            }
        }
Ejemplo n.º 12
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);
                }
            }
        }