Exemple #1
0
        public static opdracht_factuur addFactuurVanOpdracht(opdracht_factuur opdracht_factuur)
        {
            dc.opdracht_factuurs.InsertOnSubmit(opdracht_factuur);
            dc.SubmitChanges();

            return(opdracht_factuur);
        }
Exemple #2
0
        //Detail gegevens van een factuur ophalen (de prijzen waaruit deze bestaat)
        public static IEnumerable <opdracht_factuur_detail> getFactuurDetails(opdracht_factuur of)
        {
            var query = (from ofd in dc.opdracht_factuur_details
                         where ofd.opdracht_factuur == of
                         select ofd);

            return(query);
        }
Exemple #3
0
        public static void deleteDetailsVanFactuur(opdracht_factuur of)
        {
            var query = (from ofd in dc.opdracht_factuur_details
                         where ofd.opdracht_factuur == of
                         select ofd);

            if (query.Any() == true)
            {
                dc.opdracht_factuur_details.DeleteAllOnSubmit(query);
                dc.SubmitChanges();
            }
            else
            {
            }
        }
        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;
                    }
                }
            }
        }
        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);
            }
        }
Exemple #6
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.";
            }
        }
Exemple #7
0
        //Factuur updaten
        private void btnOpslaan_Click(object sender, EventArgs e)
        {
            //Validatie check
            if (Validation.hasValidationErrors(this.Controls))
            {
                return;
            }
            //Huidige opdracht (factuur) selecteren in combbox (voor id uit te halen)
            opdracht oudeOpdracht = (opdracht)cbbID.SelectedItem;



            //dtVan.Value, dtTot.Value
            //De oude opdracht (factuur) updaten en de geupdate opdracht (factuur) terugsturen
            int voorschot;

            if (!int.TryParse(txtVoorschot.Text, out voorschot))
            {
                voorschot = 0;
            }
            opdracht nieuweOpdracht = FactuurManagement.updateFactuur(oudeOpdracht.opdracht_id, (klant)cbbKlant.SelectedItem,
                                                                      dtVan.Value.ToShortDateString(), dtTot.Value.ToShortDateString(), txtVan_uur.Text, txtTot_uur.Text, decimal.Parse(txtSaldo.Text), voorschot,
                                                                      cbBetaald.Checked, txtBetalingMemo.Text, dtBetaald.Value, cbBetaaldvoorschot.Checked, txtBetalingMemovoorschot.Text, dtBetaaldvoorschot.Value);



            //Vertreklocatie toevoegen aan opdracht (factuur)
            locatie vertrek = (locatie)cbbVertrek.SelectedItem;

            OfferteManagement.addLocatieBijOfferte(vertrek, nieuweOpdracht, "vertrek");

            //Bestemming locatie toevoegen aan opdracht (factuur)
            locatie bestemming = (locatie)cbbBestemming.SelectedItem;

            OfferteManagement.addLocatieBijOfferte(bestemming, nieuweOpdracht, "bestemming");

            //Factuur info opslaan
            #region gegevensophaal
            decimal?bedrag_basis;
            if (txtBedrag_basis.Text == string.Empty)
            {
                bedrag_basis = null;
            }
            else
            {
                bedrag_basis = decimal.Parse(txtBedrag_basis.Text);
            }

            decimal?btw_bedrag;
            if (txtBtw_bedrag.Text == string.Empty)
            {
                btw_bedrag = null;
            }
            else
            {
                btw_bedrag = decimal.Parse(txtBtw_bedrag.Text);
            }

            decimal?bedrag_inclusief;
            if (txtBedrag_inclusief.Text == string.Empty)
            {
                bedrag_inclusief = null;
            }
            else
            {
                bedrag_inclusief = decimal.Parse(txtBedrag_inclusief.Text);
            }

            decimal?credit_voorschot;
            if (txtCreditvoorschot.Text == string.Empty)
            {
                credit_voorschot = null;
            }
            else
            {
                credit_voorschot = decimal.Parse(txtCreditvoorschot.Text);
            }

            decimal?totaal_reis;
            if (txtTotaal_reis.Text == string.Empty)
            {
                totaal_reis = null;
            }
            else
            {
                totaal_reis = decimal.Parse(txtTotaal_reis.Text);
            }

            decimal?btw_percent;
            if (cbbBTW.Text == string.Empty)
            {
                btw_percent = null;
            }
            else
            {
                btw_percent = decimal.Parse(cbbBTW.Text);
            }
            #endregion

            opdracht_factuur updatedFactuur = new opdracht_factuur();

            if (FactuurManagement.hasFactuur(nieuweOpdracht) == true)
            {
                //updaten
                updatedFactuur = FactuurManagement.updateFactuurVanOpdracht(nieuweOpdracht, totaal_reis, credit_voorschot,
                                                                            bedrag_basis, btw_bedrag, btw_percent, bedrag_inclusief, txtOmschrijving.Text);
            }

            else
            {
                //aanmaken
                opdracht_factuur of = new opdracht_factuur();
                of.totaal_reis         = totaal_reis;
                of.voorschot           = credit_voorschot;
                of.credit_basis        = bedrag_basis;
                of.credit_btwbedrag    = btw_bedrag;
                of.credit_btwpercent   = btw_percent;
                of.credit_inc          = bedrag_inclusief;
                of.credit_omschrijving = txtOmschrijving.Text;
                of.opdracht            = nieuweOpdracht;

                updatedFactuur = FactuurManagement.addFactuurVanOpdracht(of);
            }

            //Factuur detail
            FactuurManagement.deleteDetailsVanFactuur(updatedFactuur);

            foreach (ucDetailFactuur uc in flpDetail.Controls)
            {
                opdracht_factuur_detail ofd = new opdracht_factuur_detail();
                ofd.bedrag_basis        = uc.bedrag_basis;
                ofd.omschrijving        = uc.omschrijving;
                ofd.btw_percent         = uc.btw_percent;
                ofd.btw_bedrag          = uc.btw_bedrag;
                ofd.bedrag_inclusief    = uc.bedrag_inclusief;
                ofd.opdracht_factuur_id = updatedFactuur.opdracht_factuur_id;

                FactuurManagement.updateDetailsVanFactuur(ofd);
            }
            cbbID_SelectedIndexChanged();
            //frmMain statusbalk updaten
            MainForm.updateStatus = "De factuur met ID: " + oudeOpdracht.opdracht_id + ", is succesvol opgeslaan.";
        }
Exemple #8
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);
            }
        }