public InvoiceWindow(Invoice invoice = null)
        {
            InitializeComponent();

            context = new InvoicesContext();

            CompanyList  = context.GetCompanies();
            ContractList = context.GetContracts();

            if (invoice == null)
            {
                invoice = context.Invoices.Create();
                context.Invoices.Add(invoice);
            }
            else
            {
                invoice = context.GetInvoiceById(invoice.Id);
            }

            if (invoice.Contract != null)
            {
                SelectedSupplier = invoice.Contract.Supplier;
            }

            DataContext = invoice;
        }
Ejemplo n.º 2
0
        public AddendumWindow(Addendum addendum, InvoicesContext context)
        {
            InitializeComponent();

            this.context = context;

            DataContext = addendum;
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            using (var context = new InvoicesContext())
            {
                Database.SetInitializer(new InvoicesInitializer());
                context.Database.Initialize(false);
            }

            InitializeComponent();
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, InvoicesContext context)
        {
            app.UseDeveloperExceptionPage();

            new InvoicesInitializer().Seed(context);
            
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, InvoicesContext context)
        {
            //app.UseDeveloperExceptionPage();

            new InvoicesInitializer().Seed(context);

            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });
        }
        public CompanyWindow(Company company = null)
        {
            InitializeComponent();

            context = new InvoicesContext();

            if (company == null)
            {
                company = context.Companies.Create();
                context.Companies.Add(company);
            }
            else
            {
                company = context.GetCompanyById(company.Id);
            }

            DataContext = company;
        }
Ejemplo n.º 7
0
        public ContractWindow(Contract contract = null)
        {
            InitializeComponent();

            context = new InvoicesContext();

            CompanyList = context.GetCompanies();

            if (contract == null)
            {
                contract = context.Contracts.Create();
                context.Contracts.Add(contract);
            }
            else
            {
                contract = context.GetContractById(contract.Id);
            }

            DataContext = contract;
        }
Ejemplo n.º 8
0
        public void Execute(object parameter)
        {
            int index = this.vm.Invoices.IndexOf(this.vm.SelectedInvoice);

            if (index < 0)
            {
                throw new Exception("nie wybrano elementu");
            }
            else
            {
                using (var db = new InvoicesContext())
                {
                    var obj = db.Invoices.SingleOrDefault(x => x.InvoiceId == this.vm.SelectedInvoice.InvoiceId);
                    db.Positions.RemoveRange(obj.Positions);
                    db.Invoices.Attach(obj);
                    db.Invoices.Remove(obj);
                    db.SaveChanges();

                    this.vm.Invoices = new System.Collections.ObjectModel.ObservableCollection <Invoice>(db.Invoices);
                }
            }
        }
        public void Execute(object parameter)
        {
            string invoiceName;
            int    maxId;

            using (var db = new InvoicesContext())
            {
                if (!db.Invoices.Any())
                {
                    maxId = 0;
                }
                else
                {
                    maxId = db.Invoices.Where(u => u.Created.Year == DateTime.Now.Year).OrderByDescending(u => u.InvoiceId).FirstOrDefault().InvoiceId;
                }
                invoiceName = $"FV_{++maxId}_{DateTime.Now.Year}";
            }

            string fileName = string.Concat(AppDomain.CurrentDomain.BaseDirectory, invoiceName, ".docx");

            var doc = DocX.Create(fileName);

            string docDate     = DateTime.Now.ToString("dd/MM/yyyy").ToString();
            int    paymentDays = 14;
            string paymentType = "przelew";

            doc.InsertParagraph($"Faktura nr {invoiceName.Replace("_", "/")}").Alignment = Alignment.right;
            doc.InsertParagraph($"Data wystawienia {docDate}").Alignment = Alignment.right;
            doc.InsertParagraph($"Termin płatności: {paymentDays.ToString()} dni").Alignment = Alignment.right;
            doc.InsertParagraph($"Metoda płatności: {paymentType}").Alignment = Alignment.right;

            doc.InsertParagraph("Sprzedawca:").Bold();
            doc.InsertParagraph(Properties.Settings.Default.Name);
            doc.InsertParagraph($"{Properties.Settings.Default.Street} {Properties.Settings.Default.Number}");
            doc.InsertParagraph($"{Properties.Settings.Default.PostalCode} {Properties.Settings.Default.City}");
            doc.InsertParagraph($"NIP: {Properties.Settings.Default.NIP}");
            if (!string.IsNullOrEmpty(Properties.Settings.Default.BankAccount))
            {
                doc.InsertParagraph($"Nr rachunku do wpłat: {Properties.Settings.Default.BankAccount}");
            }

            doc.InsertParagraph("Nabywca:").Bold().Alignment              = Alignment.right;
            doc.InsertParagraph(this.vm.Customer.Name).Alignment          = Alignment.right;
            doc.InsertParagraph(this.vm.Customer.Adress).Alignment        = Alignment.right;
            doc.InsertParagraph($"NIP: {this.vm.Customer.Nip}").Alignment = Alignment.right;

            doc.InsertParagraph();
            doc.InsertParagraph();
            Table posTable = doc.AddTable(this.vm.Positions.Count + 1, 8);

            posTable.Rows[0].Cells[0].Paragraphs.First().Append("Lp.");
            posTable.Rows[0].Cells[1].Paragraphs.First().Append("Nazwa");
            posTable.Rows[0].Cells[2].Paragraphs.First().Append("Jedn.");
            posTable.Rows[0].Cells[3].Paragraphs.First().Append("Ilość");
            posTable.Rows[0].Cells[4].Paragraphs.First().Append("Cena netto");
            posTable.Rows[0].Cells[5].Paragraphs.First().Append("Stawka VAT");
            posTable.Rows[0].Cells[6].Paragraphs.First().Append("Wartość netto");
            posTable.Rows[0].Cells[7].Paragraphs.First().Append("Wartość brutto");

            foreach (Position item in this.vm.Positions)
            {
                item.RowIndex = this.vm.Positions.IndexOf(item) + 1;
                posTable.Rows[item.RowIndex].Cells[0].Paragraphs.First().Append($"{item.RowIndex.ToString()}.");
                posTable.Rows[item.RowIndex].Cells[1].Paragraphs.First().Append(item.Name);
                posTable.Rows[item.RowIndex].Cells[2].Paragraphs.First().Append(item.Unit);
                posTable.Rows[item.RowIndex].Cells[3].Paragraphs.First().Append(item.Quantity.ToString("F"));
                posTable.Rows[item.RowIndex].Cells[4].Paragraphs.First().Append(item.PriceNetto.ToString("F"));
                posTable.Rows[item.RowIndex].Cells[5].Paragraphs.First().Append($"{item.Vat.ToString()}%");
                posTable.Rows[item.RowIndex].Cells[6].Paragraphs.First().Append(item.AmountNetto.ToString("F"));
                posTable.Rows[item.RowIndex].Cells[7].Paragraphs.First().Append(item.AmountBrutto.ToString("F"));
            }

            doc.InsertTable(posTable);
            doc.InsertParagraph();
            doc.InsertParagraph();

            double totalAmountBrutto = this.vm.Positions.Sum(x => x.AmountBrutto);
            double totalAmountNetto  = this.vm.Positions.Sum(x => x.AmountNetto);

            doc.InsertParagraph($"Razem netto: {totalAmountNetto.ToString("F")} PLN").Alignment   = Alignment.right;
            doc.InsertParagraph($"Razem brutto: {totalAmountBrutto.ToString("F")} PLN").Alignment = Alignment.right;
            doc.InsertParagraph("Zapłacono: 0,00 PLN").Alignment = Alignment.right;
            doc.InsertParagraph($"Do zapłaty: {totalAmountBrutto.ToString("F")} PLN").Alignment = Alignment.right;

            doc.InsertParagraph();
            doc.InsertParagraph("Uwagi: W tytule przelewu proszę podać nr zamówienia.");

            doc.AddFooters();
            var footerDefault = doc.Footers.Odd;

            footerDefault.InsertParagraph("…..………………...........................                                         ..........................................................").Alignment = Alignment.center;
            footerDefault.InsertParagraph("Osoba upoważniona do obioru                                        Osoba upoważniona do wystawienia").Alignment = Alignment.center;

            doc.Save();

            Process.Start("WINWORD.EXE", "\"" + fileName + "\"");

            using (var db = new InvoicesContext())
            {
                var invoice = new Invoice
                {
                    Name           = invoiceName,
                    Created        = DateTime.Now,
                    SellerName     = Properties.Settings.Default.Name,
                    SellerNip      = Properties.Settings.Default.NIP,
                    CustomerName   = this.vm.Customer.Name,
                    CustomerAdress = this.vm.Customer.Adress,
                    CustomerNip    = this.vm.Customer.Nip,
                    AmountBrutto   = totalAmountBrutto.ToString()
                };

                db.Invoices.Add(invoice);

                foreach (Position item in this.vm.Positions)
                {
                    PositionDB posDB = new PositionDB
                    {
                        RowIndex     = item.RowIndex,
                        Name         = item.Name,
                        Unit         = item.Unit,
                        PriceNetto   = item.PriceNetto,
                        PriceBrutto  = item.PriceBrutto.GetValueOrDefault(),
                        Quantity     = item.Quantity,
                        Vat          = item.Vat,
                        AmountNetto  = item.AmountNetto,
                        AmountBrutto = item.AmountBrutto,
                        Invoices     = invoice
                    };

                    db.Positions.Add(posDB);
                }
                db.SaveChanges();

                this.vm.Invoices = new System.Collections.ObjectModel.ObservableCollection <Invoice>(db.Invoices);
            }

            this.vm.Positions.Clear();
        }
Ejemplo n.º 10
0
 public InvoicesController(InvoicesContext invoicesContext)
 {
     db = invoicesContext;
 }
Ejemplo n.º 11
0
 public InvoicesController(InvoicesContext _context)
 {
     context = _context;
 }
Ejemplo n.º 12
0
 private void RefreshInvoices()
 {
     using (var context = new InvoicesContext())
         dgInvoices.ItemsSource = context.GetInvoices();
 }
Ejemplo n.º 13
0
 private void RefreshContracts()
 {
     using (var context = new InvoicesContext())
         dgContracts.ItemsSource = context.GetContracts();
 }