Exemplo n.º 1
0
        private void getFacturenByKlant()
        {
            lblName.Text = opdracht.klantnaam + "(" + opdracht.klant.klant_id_full + ")";
            foreach (opdracht opdr in FactuurManagement.getTeFacturerenOpdrachtenVanKlant(opdracht.vanaf_datum, opdracht.klant))
            {
                //facturenGridView.Rows.Add(false, opdr.opdracht_id, opdr.ritomschrijving, opdr.voorschot, opdr.vanaf_datum.Day + "-" + opdr.vanaf_datum.Month+"-"+opdr.vanaf_datum.Year, opdr.tot_datum.Day+"-"+opdr.tot_datum.Month+"-"+opdr.tot_datum.Year, opdr.offerte_totaal);
                string tempfactuurnummer = "";
                try {
                    tempfactuurnummer += opdr.FactuurNummering.FactuurNr + "-" + opdr.FactuurNummering.FactuurJaar;
                }
                catch { }
                facturenGridView.Rows.Add(false, opdr.opdracht_id, tempfactuurnummer, opdr.ritomschrijving, opdr.voorschot, opdr.vanaf_datum.ToShortDateString(), opdr.tot_datum.ToShortDateString(), opdr.autocarprijs);
                DataGridViewRow row = facturenGridView.Rows[facturenGridView.RowCount - 1];

                if (opdr.FactuurNummering != null)
                {
                    if (opdr.FactuurNummering.FactuurNr == opdracht.FactuurNummering.FactuurNr &&
                        opdr.FactuurNummering.FactuurJaar == opdracht.FactuurNummering.FactuurJaar)
                    {
                        opdracht_factuur of = FactuurManagement.getFactuurVanOpdracht(opdr);
                        if (FactuurManagement.getFactuurDetails(of).Count() == 0)
                        {
                            row.DefaultCellStyle.BackColor = Color.Orange;
                            row.DefaultCellStyle.ForeColor = Color.Black;
                        }
                        row.Cells[0].Value = true;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.Red;
                        row.DefaultCellStyle.ForeColor = Color.White;
                        row.Frozen = true;
                    }
                }
                else
                {
                    opdracht_factuur of = FactuurManagement.getFactuurVanOpdracht(opdr);
                    if (FactuurManagement.getFactuurDetails(of).Count() == 0)
                    {
                        row.DefaultCellStyle.BackColor = Color.Orange;
                        row.DefaultCellStyle.ForeColor = Color.Black;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            String  opdrachtenInhoud = "";
            decimal totalAmount      = 0;

            foreach (DataGridViewRow row in facturenGridView.Rows)
            {
                if ((Boolean)row.Cells[0].Value != false)
                {
                    int opdrachtID = 0;
                    if (!int.TryParse(row.Cells[1].Value.ToString(), out opdrachtID))
                    {
                        continue;
                    }
                    opdracht         op = OpdrachtManagement.getOpdracht(opdrachtID);
                    opdracht_factuur of = FactuurManagement.getFactuurVanOpdracht(op);
                    foreach (opdracht_factuur_detail ofd in FactuurManagement.getFactuurDetails(of))
                    {
                        opdrachtenInhoud += of.opdracht_id + "\t";
                        opdrachtenInhoud += ofd.omschrijving + "\t";
                        opdrachtenInhoud += ofd.bedrag_basis + "\t";
                        opdrachtenInhoud += ofd.btw_percent + "\t";
                        opdrachtenInhoud += ofd.btw_bedrag + "\t";
                        opdrachtenInhoud += ofd.bedrag_inclusief + "\t";
                        opdrachtenInhoud += System.Environment.NewLine;

                        totalAmount += ofd.bedrag_inclusief.Value;
                        FactuurNummering nummer = new FactuurNummering();
                        nummer.bedrijf      = opdracht.FactuurNummering.bedrijf;
                        nummer.FactuurNr    = opdracht.FactuurNummering.FactuurNr;
                        nummer.FactuurJaar  = opdracht.FactuurNummering.FactuurJaar;
                        op.FactuurNummering = nummer;
                        Backend.DataContext.dc.SubmitChanges();
                    }


                    //opdrachtenInhoud += row.Cells[1].Value + "\t" + row.Cells[2].Value + "\t" + row.Cells[4].Value + "\t" + row.Cells[5].Value + "\t€" + row.Cells[6].Value + System.Environment.NewLine;
                    //totalAmount += Convert.ToDouble(row.Cells[6].Value.ToString());
                }
            }

            if (totalAmount > 0)
            {
                locatie adres = KlantManagement.getAdresVanKlant(opdracht.klant.klant_id);

                //Convert date to acceptable format for use in file name
                String datum = DateTime.Today.ToString("yyyy-MM-dd");

                //missing oject to use with various word commands
                object missing = System.Reflection.Missing.Value;

                //the template file you will be using
                object fileToOpen = (object)@"R:\CarGo\opdracht_template.docx";

                //Where the new file will be saved to.
                object fileToSave = (object)@"R:\CarGo\opdrachten\opdracht_" + opdracht.klant.naam + "_" + datum + ".docx";

                //Create new instance of word and create a new document
                Word.Application wordApp = new Word.Application();
                Word.Document    doc     = null;

                //Properties for the new word document
                object readOnly  = false;
                object isVisible = false;

                //Settings the application to invisible, so the user doesn't notice that anything is going on
                wordApp.Visible = false;
                try
                {
                    try
                    {
                        File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true);
                    }
                    catch
                    {
                        MessageBox.Show("Loading the template file failed.", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    readOnly = false;
                    doc      = wordApp.Documents.Open(ref fileToSave, ref missing,
                                                      ref readOnly, ref missing, ref missing, ref missing,
                                                      ref missing, ref missing, ref missing, ref missing,
                                                      ref missing, ref isVisible, ref missing, ref missing,
                                                      ref missing, ref missing);
                }
                catch { }



                PrintManagement.findAndReplace(doc, "factuurdatum", datum);
                PrintManagement.findAndReplace(doc, "factuurnummer", opdracht.FactuurNummering.FactuurNr + " " + opdracht.FactuurNummering.FactuurJaar);
                PrintManagement.findAndReplace(doc, "startOfDocument", opdrachtenInhoud);
                PrintManagement.findAndReplace(doc, "totaal", "Totaal: €" + totalAmount);
                Console.WriteLine(opdrachtenInhoud);

                doc.Save();
                doc.Activate();
                //Making word visible to be able to show the print preview.
                wordApp.Visible = true;
                wordApp.Activate();
                //doc.PrintPreview();
            }
            else
            {
                MessageBox.Show("Onvoldoende gegevens om factuur op te stellen. Kijk Detail Facturatie na", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }
Exemplo n.º 3
0
        private void cbbID_SelectedIndexChanged()
        {
            opdracht opdracht = (opdracht)cbbID.SelectedItem;

            if (opdracht == null)
            {
                MainForm.updateStatus = "Er is geen factuur gekozen.";
            }
            else
            {
                //De opslaan knop op enabled zetten, zodat de gebruiker kan opslaan
                btnOpslaan.Enabled = true;
                enableFields();

                //velden moeten eerst leeggemaakt worden, anders gaan er waarden instaan die er niet mogen instaan (van vorige geselecteerde factuur)
                emptyFields();

                opdracht selectedOpdracht = (opdracht)cbbID.SelectedItem;

                //Kijken of gefactureerd is of niet
                if (selectedOpdracht.factuur_datum == null)
                {
                    lblGefactureerd.Text      = "Niet gefactureerd";
                    lblGefactureerd.ForeColor = Color.Red;
                }
                else
                {
                    lblGefactureerd.Text      = "Gefactureerd";
                    lblGefactureerd.ForeColor = Color.Green;
                }

                cbbKlant.SelectedItem = selectedOpdracht.klant;
                dtVan.Value           = selectedOpdracht.vanaf_datum;
                dtTot.Value           = selectedOpdracht.tot_datum;

                TimeSpan aantaldagen = dtTot.Value - dtVan.Value;
                int      dagen       = aantaldagen.Days + 1;
                txtAantalDagen.Text = dagen.ToString();

                txtVan_uur.Text            = selectedOpdracht.vanaf_uur;
                txtTot_uur.Text            = selectedOpdracht.tot_uur;
                cbbVertrek.SelectedItem    = OpdrachtManagement.getVertrek(selectedOpdracht.opdracht_id);
                cbbBestemming.SelectedItem = OpdrachtManagement.getBestemming(selectedOpdracht.opdracht_id);
                txtTotaalprijs.Text        = selectedOpdracht.offerte_totaal.ToString();

                decimal prijs;
                if (selectedOpdracht.voorschot != null)
                {
                    prijs = (decimal)selectedOpdracht.offerte_totaal - (decimal)selectedOpdracht.voorschot;
                }
                else
                {
                    prijs = (decimal)selectedOpdracht.offerte_totaal;
                }

                txtSaldo.Text     = prijs.ToString();
                txtVoorschot.Text = selectedOpdracht.voorschot.ToString();

                cbBetaald.Checked          = Convert.ToBoolean(selectedOpdracht.factuur_betaald);
                cbBetaaldvoorschot.Checked = Convert.ToBoolean(selectedOpdracht.factuur_betaald_voorschot);
                try
                {
                    dtBetaald.Value = selectedOpdracht.factuur_betalingsdatum.Value;
                }
                catch { } try
                {
                    dtBetaaldvoorschot.Value = selectedOpdracht.factuur_betalingsdatum_voorschot.Value;
                }
                catch { }

                txtBetalingMemo.Text          = selectedOpdracht.factuur_betalingmemo;
                txtBetalingMemovoorschot.Text = selectedOpdracht.factuur_betalingmemo_voorschot;

                Factuurbetaald();
                Voorschotbetaald();

                ////Alle reservaties ophalen en toevoegen aan flpReservaties
                //foreach (reservatie res in OpdrachtManagement.getReservaties(selectedOpdracht.opdracht_id))
                //{
                //    ucReservatie ucReservatie = new ucReservatie();
                //    ucReservatie.Prijs = res.prijs;
                //    ucReservatie.Leverancier = res.leverancier;
                //    ucReservatie.Omschrijving = res.omschrijving;

                //    flpReservaties.Controls.Add(ucReservatie);
                //}

                //factuur informatie ophalen
                opdracht_factuur of = FactuurManagement.getFactuurVanOpdracht(selectedOpdracht);

                if (of == null)
                {
                }
                else
                {
                    txtBedrag_basis.Text     = of.credit_basis.ToString();
                    txtOmschrijving.Text     = of.credit_omschrijving;
                    txtBtw_bedrag.Text       = of.credit_btwbedrag.ToString();
                    cbbBTW.Text              = of.credit_btwpercent.ToString();
                    txtBedrag_inclusief.Text = of.credit_inc.ToString();
                    txtCreditvoorschot.Text  = of.voorschot.ToString();
                    txtTotaal_reis.Text      = of.totaal_reis.ToString();

                    //factuur detail informatie ophalen
                    foreach (opdracht_factuur_detail ofd in FactuurManagement.getFactuurDetails(of))
                    {
                        ucDetailFactuur uc = new ucDetailFactuur();
                        uc.bedrag_basis     = ofd.bedrag_basis;
                        uc.omschrijving     = ofd.omschrijving;
                        uc.bedrag_inclusief = ofd.bedrag_inclusief;
                        uc.btw_bedrag       = ofd.btw_bedrag;
                        uc.btw_percent      = ofd.btw_percent;

                        flpDetail.Controls.Add(uc);
                    }
                }

                if (selectedOpdracht.FactuurNummering != null)
                {
                    if (selectedOpdracht.FactuurNummering.FactuurJaar != null)
                    {
                        _factuurjaar = selectedOpdracht.FactuurNummering.FactuurJaar.Value;
                    }
                    if (selectedOpdracht.FactuurNummering.FactuurNr != null)
                    {
                        _factuurnr = selectedOpdracht.FactuurNummering.FactuurNr.Value;
                    }
                    if (selectedOpdracht.FactuurNummering.bedrijf != null)
                    {
                        txt_eigenaarFactuur.Text = selectedOpdracht.FactuurNummering.bedrijf.naam;
                    }
                }

                if (selectedOpdracht.FactuurNummering1 != null)
                {
                    if (selectedOpdracht.FactuurNummering1.FactuurJaar != null)
                    {
                        _factuurjaarCredit = selectedOpdracht.FactuurNummering1.FactuurJaar.Value;
                    }
                    if (selectedOpdracht.FactuurNummering1.FactuurNr != null)
                    {
                        _factuurnrCredit = selectedOpdracht.FactuurNummering1.FactuurNr.Value;
                    }
                }

                txt_FactuurNr.Enabled         = false;
                txt_factuurjaar.Enabled       = false;
                txt_FactuurNrCredit.Enabled   = false;
                txt_factuurjaarCredit.Enabled = false;

                //Statusbar updaten
                MainForm.updateStatus = "De factuur met ID: " + opdracht.opdracht_id + ", is succesvol geladen.";
            }
        }
Exemplo n.º 4
0
        private void btnPrintCredit_Click(object sender, EventArgs e)
        {
            String  opdrachtenInhoud = "";
            decimal totalAmount      = 0;

            if (cbbID.SelectedItem == null)
            {
                return;
            }

            opdracht op = (opdracht)cbbID.SelectedItem;

            if (op.FactuurNummering1 == null)
            {
                return;
            }
            if (op.FactuurNummering1.FactuurJaar == null || op.FactuurNummering1.FactuurNr == null)
            {
                return;
            }

            opdracht_factuur of = FactuurManagement.getFactuurVanOpdracht(op);

            opdrachtenInhoud += of.opdracht_id + "\t";
            opdrachtenInhoud += of.credit_omschrijving + "\t";
            opdrachtenInhoud += of.credit_basis + "\t";
            opdrachtenInhoud += of.credit_btwpercent + "\t";
            opdrachtenInhoud += of.credit_btwbedrag + "\t";
            opdrachtenInhoud += of.credit_inc + "\t";
            opdrachtenInhoud += System.Environment.NewLine;

            totalAmount += of.credit_inc.Value;



            //opdrachtenInhoud += row.Cells[1].Value + "\t" + row.Cells[2].Value + "\t" + row.Cells[4].Value + "\t" + row.Cells[5].Value + "\t€" + row.Cells[6].Value + System.Environment.NewLine;
            //totalAmount += Convert.ToDouble(row.Cells[6].Value.ToString());


            if (totalAmount > 0)
            {
                locatie adres = KlantManagement.getAdresVanKlant(opdracht.klant.klant_id);

                //Convert date to acceptable format for use in file name
                String datum = DateTime.Today.ToString("yyyy-MM-dd");

                //missing oject to use with various word commands
                object missing = System.Reflection.Missing.Value;

                //the template file you will be using
                //object fileToOpen = (object)@"R:\CarGo\CreditNota_template.docx";
                object fileToOpen = (object)@"R:\CarGo\opdracht_template.docx";

                //Where the new file will be saved to.
                object fileToSave = (object)@"R:\CarGo\opdrachten\Credit_" + opdracht.klant.naam + "_" + datum + ".docx";

                //Create new instance of word and create a new document
                Word.Application wordApp = new Word.Application();
                Word.Document    doc     = null;

                //Properties for the new word document
                object readOnly  = false;
                object isVisible = false;

                //Settings the application to invisible, so the user doesn't notice that anything is going on
                wordApp.Visible = false;
                try
                {
                    try
                    {
                        File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true);
                    }
                    catch
                    {
                        MessageBox.Show("Loading the template file failed.", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    readOnly = false;
                    doc      = wordApp.Documents.Open(ref fileToSave, ref missing,
                                                      ref readOnly, ref missing, ref missing, ref missing,
                                                      ref missing, ref missing, ref missing, ref missing,
                                                      ref missing, ref isVisible, ref missing, ref missing,
                                                      ref missing, ref missing);
                }
                catch { }



                PrintManagement.findAndReplace(doc, "factuurdatum", datum);
                PrintManagement.findAndReplace(doc, "factuurnummer", opdracht.FactuurNummering1.FactuurNr + " " + opdracht.FactuurNummering1.FactuurJaar);
                PrintManagement.findAndReplace(doc, "startOfDocument", opdrachtenInhoud);
                PrintManagement.findAndReplace(doc, "totaal", "Totaal: €" + totalAmount);
                Console.WriteLine(opdrachtenInhoud);

                doc.Save();
                doc.Activate();
                //Making word visible to be able to show the print preview.
                wordApp.Visible = true;
                wordApp.Activate();
                //doc.PrintPreview();
            }
            else
            {
                MessageBox.Show("Credit bedrag moet groter dan 0 zijn.", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }