Exemple #1
0
 private List <int> GetLignesNum()
 {
     try
     {
         return((from ListViewItem item in listViewLignes.CheckedItems select int.Parse(item.SubItems[0].Text)).ToList());
     }
     catch (Exception ex)
     {
         Messages.Error("Error getting ligne numbers: " + ex.Message);
         ErrorLog.LogError("Error getting ligne numbers", ex);
         return(null);
     }
 }
Exemple #2
0
        private void LoadNewAvoir()
        {
            try
            {
                var detail = new DetailsDossier();

                //Set référence
                _numAvoir            = detail.GetLastAvoirId(dateAvoir.Value);
                textBoxRefAvoir.Text = _numAvoir.ToString("D");

                if (_numGroupe.Count != 0)
                {
                    // _montant = detail.GetGroupeInfo(_numGroupe).MNT_HT ?? 0;

                    // var factures = detail.GetFactures(_numGroupe);
                    var factures = new List <FACTURE>();

                    //Get factures of each groupe then put them all in one list
                    _numGroupe.ForEach(g =>
                    {
                        var groupeFactures = detail.GetFactures(g);
                        //add each groupe factures to the global list
                        groupeFactures.ForEach(factures.Add);
                    });

                    PopulateFacutresListView(factures);
                    foreach (ListViewItem item in listViewFactures.Items)
                    {
                        item.Checked = true;
                    }
                    textBoxMontantAv.Text = string.Format("{0:#,##0.00}", _montant);
                    textBoxCreance.Text   = string.Format("{0:#,##0.00}", _reste);
                }
                //set totals values
                decimal t, m;
                TotalFactures(out t, out m);

                //disable facture item check
                listViewFactures.ItemCheck += listViewFactures_ItemCheck;
                _designation = textBoxDesc.Text;
                Calculation();
                CheckType();
            }
            catch (Exception e)
            {
                Messages.Error("Error Creating avoir :" + e.Message);
                ErrorLog.LogError("Error Creating avoir", e);
                Close();
            }
        }
Exemple #3
0
        static void Main()
        {
            //authentificate

            if (!Authentif())
            {
                Messages.Error("Vous n'êtes pas autorisé à utiliser l'application. Merci de contacter votre administrateur.");
                return;
            }


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
Exemple #4
0
        private void gridView_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                //REJETE
                if (e.KeyCode == Keys.F1)
                {
                    var rows = gridView.GetSelectedRows();
                    if (!SetEtat(GetSelectedGroups(rows), 1))
                    {
                        return;
                    }
                    RefreshTable();
                    gridView.SelectRow(rows[0]);
                    Alert("Dossier marqué comme rejeté", 1);
                }

                //RECU
                if (e.KeyCode == Keys.F2)
                {
                    var rows = gridView.GetSelectedRows();
                    if (!SetEtat(GetSelectedGroups(rows), 2))
                    {
                        return;
                    }
                    RefreshTable();
                    gridView.SelectRow(rows[0]);
                    Alert("Dossier(s) marqué(s)  comme reçu(s)", 1);
                }

                //EN INSTANCE
                if (e.KeyCode == Keys.F3)
                {
                    var rows = gridView.GetSelectedRows();
                    if (!SetEtat(GetSelectedGroups(rows), 0))
                    {
                        return;
                    }
                    RefreshTable();
                    gridView.SelectRow(rows[0]);
                    Alert("Dossier(s) marqué(s) en instance", 1);
                }
            }
            catch (Exception ex)
            {
                Messages.Error(ex.Message);
            }
        }
Exemple #5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                dateTimePicker.MinDate = dateTimePicker.Value = new DateTime(DateTime.Now.Year, 1, 1);

                // This line of code is generated by Data Source Configuration Wizard
                dossiersPromotionTableAdapter1.Fill(bordereauDataSet2.DossiersPromotion, dateTimePicker.MinDate);
                gridView.CustomFilterDialog += (snd, ev) => { ev.Handled = true; };
            }
            catch (Exception ex)
            {
                Messages.Error("Erreur connexion au serveur: " + ex.Message);
                Close();
            }
        }
Exemple #6
0
 List <AF_GET_LIGNES_FACTURE_Result> GetLignes(string ent, int numFact, DateTime date)
 {
     try
     {
         using (var model = new ExpFinanceEntities())
         {
             return((from l in model.AF_GET_LIGNES_FACTURE(ent, numFact, date)
                     select l).ToList());
         }
     }
     catch (Exception ex)
     {
         Messages.Error("Erreur: " + ex.Message);
         ErrorLog.LogError("Erreur lignes factures", ex);
         return(null);
     }
 }
Exemple #7
0
 static bool Authentif()
 {
     try
     {
         using (var model = new ExpFinanceEntities())
         {
             return((from u in model.AF_UTILISATEUR
                     where u.Username == Environment.UserDomainName + @"\" + Environment.UserName
                     select u).Any());
         }
     }
     catch (Exception)
     {
         Messages.Error("La connexion à la base de données a échoué. vérifier votre connexion réseau ou contactez votre administrateur");
         return(false);
     }
 }
Exemple #8
0
 private bool InsertCheques(List <CHEQUE> cheques)
 {
     try
     {
         using (var model = new ExpFinanceEntities())
         {
             cheques.ForEach(c => model.CHEQUE.Add(c));
             model.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Messages.Error(@"Erreur insertion cheques: " + e.InnerException.Message);
         ErrorLog.LogError(@"Erreur insertion cheques: ", e);
         return(false);
     }
 }
Exemple #9
0
        private void LoadServerReport()
        {
            try
            {
                var parameters = new[]
                {
                    new ReportParameter("entite", _entite),
                    new ReportParameter("codeClient", _codeClient),
                    new ReportParameter("numFacture", _numFacture.ToString(CultureInfo.InvariantCulture))
                };

                reportViewer.ProcessingMode = ProcessingMode.Remote;
                var uri = new Uri(Settings.Default.reportServerURL);
                reportViewer.ServerReport.ReportServerUrl = uri;

                // Get a reference to the default credentials
                ICredentials credentials = CredentialCache.DefaultCredentials;

                // Get a reference to the report server credentials
                var rsCredentials = reportViewer.ServerReport.ReportServerCredentials;

                // Set the credentials for the server report
                rsCredentials.NetworkCredentials = credentials;


                //I'm really sorry for doing this but i had to :'( :'( :'(
                //may god forgive me
                rsCredentials.NetworkCredentials = new NetworkCredential("erpadmin", "Heavy.all2016@", "GHP");

                reportViewer.ServerReport.ReportPath = Settings.Default.reportDetailsFacture;
                reportViewer.ShowCredentialPrompts   = true;
                reportViewer.ServerReport.SetParameters(parameters);


                reportViewer.ZoomMode = ZoomMode.PageWidth;
                reportViewer.RefreshReport();
            }
            catch (Exception ex)
            {
                Messages.Error("Vérifier la connexion avec le serveur !");
                ErrorLog.LogError("Vérifier la connexion avec le serveur !", ex);
                Close();
            }
        }
Exemple #10
0
        private void LoadFactures(string code)
        {
            try
            {
                //reset ligne storings
                LignesBuffer.Clear();
                _lignesList.Clear();

                var detail = new DetailsDossier();
                var fact   = detail.GetClientFactures(code);
                PopulateFacutresListView(fact);
            }
            catch (Exception e)
            {
                Messages.Error(e.Message);
                ErrorLog.LogError("Load Factures", e);
                throw;
            }
        }
Exemple #11
0
 private void labelInstance_Click(object sender, EventArgs e)
 {
     try
     {
         //EN INSTANCE
         var rows = gridView.GetSelectedRows();
         if (!SetEtat(GetSelectedGroups(rows), 0))
         {
             return;
         }
         RefreshTable();
         gridView.SelectRow(rows[0]);
         Alert("Dossier(s) marqué(s) en instance", 1);
     }
     catch (Exception ex)
     {
         Messages.Error(ex.Message);
     }
 }
Exemple #12
0
 private void labelRejet_Click(object sender, EventArgs e)
 {
     try
     {
         //REJETE
         var rows = gridView.GetSelectedRows();
         if (!SetEtat(GetSelectedGroups(rows), 1))
         {
             return;
         }
         RefreshTable();
         gridView.SelectRow(rows[0]);
         Alert("Dossier marqué comme rejeté", 1);
     }
     catch (Exception ex)
     {
         Messages.Error(ex.Message);
     }
 }
Exemple #13
0
        private void InsertCheque(EditAvoirForm f)
        {
            try
            {
                var cheque = new CHEQUE
                {
                    numCheque   = textBoxRef.Text,
                    description = textBoxDesc.Text,
                    codeBank    = (int)comboBoxBank.SelectedValue,
                    date        = dateTimePicker.Value.Date,
                    nom         = textBoxNom.Text,
                    montant     = decimal.Parse(textBoxMontant.Text)
                };
                f.ChequesBuffer = cheque;
            }

            catch (Exception ex)
            {
                Messages.Error(ex.Message);
            }
        }
Exemple #14
0
 void RefreshTable()
 {
     try
     {
         Cursor.Current = Cursors.WaitCursor;
         // This line of code is generated by Data Source Configuration Wizard
         var selected = gridView.GetSelectedRows();
         var focused  = gridView.FocusedRowHandle;
         dossiersPromotionTableAdapter1.Fill(bordereauDataSet2.DossiersPromotion, dateTimePicker.Value);
         if (selected.Count() > 0)
         {
             gridView.SelectRows(selected.First(), selected.Last());
         }
         gridView.FocusedRowHandle = focused;
         Cursor.Current            = Cursors.Default;
     }
     catch (Exception e)
     {
         Messages.Error("Erreur lecture de données.");
         ErrorLog.LogError("refresh table", e);
     }
 }
Exemple #15
0
 private void AvoirForm_Load(object sender, EventArgs e)
 {
     try
     {
         // TODO: This line of code loads data into the 'clientDataSet.Client' table. You can move, or remove it, as needed.
         clientTableAdapter.Fill(clientDataSet.AF_CLIENT, Settings.Default.entite);
         var detail = new DetailsDossier();
         //Set référence
         _numAvoir            = detail.GetLastAvoirId(dateAvoir.Value);
         textBoxRefAvoir.Text = _numAvoir.ToString("D");
         dateExercice.Value   = dateExercice.Maximum = DateTime.Now.Year - 1;
         Calculation();
         CheckType();
         PopulateComboxBoxPalierEf();
         PopulateComboboxPromotion();
     }
     catch (Exception ex)
     {
         Messages.Error(ex.Message);
         ErrorLog.LogError("Load", ex);
         Close();
     }
 }
Exemple #16
0
        private void LoadReport()
        {
            try
            {
                var parameters = new[]
                {
                    new ReportParameter("entite", _entite),
                    new ReportParameter("codeClient", _codeClient),
                    new ReportParameter("numFacture", _numFacture.ToString(CultureInfo.InvariantCulture))
                };
                reportViewer.ProcessingMode = ProcessingMode.Local;


                reportViewer.ZoomMode = ZoomMode.PageWidth;
                reportViewer.LocalReport.SetParameters(parameters);
                reportViewer.RefreshReport();
            }
            catch (Exception)
            {
                Messages.Error("Vérifier la connexion avec le serveur !");
                Close();
            }
        }
Exemple #17
0
        private bool InsertCheques(List <CHEQUE> cheques)
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    //remove old entries

                    // ReSharper disable once AccessToDisposedClosure
                    (from c in model.CHEQUE where c.numAvoir == _numAvoir select c).ForEach(c => model.CHEQUE.Remove(c));

                    //insert new entries
                    cheques.ForEach(c => model.CHEQUE.Add(c));
                    model.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                Messages.Error("Erreur insertion chèques:" + ex.Message);
                ErrorLog.LogError("Erreur insertion chèques", ex);
                return(false);
            }
        }
Exemple #18
0
        private bool InsertAvoir(AVOIR_FINANCIER avoir)
        {
            try
            {
                decimal mntAv;
                decimal.TryParse(textBoxMontantAv.Text, out mntAv);

                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();

                    //Set référence
                    _numAvoir            = detail.GetLastAvoirId(dateAvoir.Value);
                    textBoxRefAvoir.Text = _numAvoir.ToString("D");
                    int codePromo;
                    int.TryParse(comboBoxPromotions.SelectedValue?.ToString(), out codePromo);

                    avoir.numAvoir          = _numAvoir;
                    avoir.montant           = mntAv;
                    avoir.dateAvoir         = dateAvoir.Value.Date;
                    avoir.designation       = textBoxDesc.Text;
                    avoir.montantCheque     = _cheque;
                    avoir.montantCreance    = _creance;
                    avoir.Observation       = _observation;
                    avoir.typeAvoir         = (byte)_typeAvoir;
                    avoir.numAvoirComptable = codePromo;

                    var op = new AF_OPS_LOG
                    {
                        instant   = DateTime.Now,
                        username  = Environment.UserName,
                        numavoir  = _numAvoir,
                        Operation = "Avoir inséré"
                    };

                    model.AF_OPS_LOG.Add(op);
                    //int nac;
                    //if (int.TryParse(textBoxNAC.Text, out nac))
                    //{
                    //    avoir.numAvoirComptable = nac;
                    //}

                    var libre = _isFacture ? (byte)1 : (byte)2;

                    //insert the related group
                    var avoirGroupe = new AF_AVOIR_GROUPE
                    {
                        numAvoir = avoir.numAvoir,
                        IDG      = _numGroupe,
                        Libre    = libre
                    };

                    model.AF_AVOIR_GROUPE.Add(avoirGroupe);


                    //Insert in the etat table
                    var etat = new AF_ETAT_AVOIR
                    {
                        numDossier = _nDossier,
                        numAvoir   = avoir.numAvoir,
                        IDG        = _numGroupe,
                        Etat       = 3,
                        dateHeure  = DateTime.Now
                    };

                    model.AF_ETAT_AVOIR.Add(etat);

                    model.AVOIR_FINANCIER.Add(avoir);
                    model.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error(@"Erreur insertion avoir financier: ");
                ErrorLog.LogError(@"Erreur insertion avoir financier: ", e);
                return(false);
            }
        }
Exemple #19
0
        private bool SetEtat(IEnumerable <int> idg, byte state)
        {
            try
            {
                if (idg == null)
                {
                    return(false);
                }
                idg = idg.ToList();
                if (!idg.Any())
                {
                    return(false);
                }

                using (var model = new ExpFinanceEntities())
                {
                    //If reject treat only one entry
                    if (state == 1)
                    {
                        var g = idg.LastOrDefault();

                        var oldState = (from e in model.AF_ETAT_AVOIR
                                        where e.IDG == g
                                        orderby e.dateHeure descending
                                        select e.Etat).FirstOrDefault();

                        //return if already rejected or if validated
                        if (oldState == state || oldState == 3)
                        {
                            Cursor.Current = Cursors.Default;
                            return(false);
                        }

                        var obs = Prompt.ShowDialog("Motif de rejet", "Observation");

                        var etat = new AF_ETAT_AVOIR
                        {
                            IDG         = g,
                            Etat        = state,
                            dateHeure   = DateTime.Now,
                            observation = obs
                        };

                        var op = new AF_OPS_LOG
                        {
                            instant   = DateTime.Now,
                            Operation = $"Etat mis à {state}",
                            username  = Environment.UserName,
                            idg       = g
                        };

                        model.AF_OPS_LOG.Add(op);
                        model.AF_ETAT_AVOIR.Add(etat);
                        model.SaveChanges();
                        return(true);
                    }

                    Cursor.Current = Cursors.WaitCursor;
                    foreach (int g in idg)
                    {
                        //Check the last state
                        var oldState = (from e in model.AF_ETAT_AVOIR
                                        where e.IDG == g
                                        orderby e.dateHeure descending
                                        select e.Etat).FirstOrDefault();

                        if (oldState == state)
                        {
                            continue;
                        }
                        //return if validated
                        if (oldState == 3)
                        {
                            Cursor.Current = Cursors.Default;
                            return(false);
                        }

                        var etat = new AF_ETAT_AVOIR
                        {
                            IDG       = g,
                            Etat      = state,
                            dateHeure = DateTime.Now
                        };

                        var op = new AF_OPS_LOG
                        {
                            instant   = DateTime.Now,
                            Operation = $"Etat mis à {state}",
                            username  = Environment.UserName,
                            idg       = g
                        };

                        model.AF_OPS_LOG.Add(op);
                        model.AF_ETAT_AVOIR.Add(etat);
                    }

                    model.SaveChanges();
                    Cursor.Current = Cursors.Default;
                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error("Error edit etat: " + e.Message);
                return(false);
            }
        }
Exemple #20
0
        private void printingWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ErrorLog.LogMessage("Begin Printing Work...");

                var reportViewer = new ReportViewer {
                    ProcessingMode = ProcessingMode.Remote
                };
                var uri = new Uri(Settings.Default.reportServerURL);
                reportViewer.ServerReport.ReportServerUrl = uri;


                ErrorLog.LogMessage($"Server registred {Settings.Default.reportServerURL}");

                // Get a reference to the default credentials
                ICredentials credentials = CredentialCache.DefaultCredentials;

                // Get a reference to the report server credentials
                var rsCredentials = reportViewer.ServerReport.ReportServerCredentials;

                // Set the credentials for the server report
                rsCredentials.NetworkCredentials = credentials;


                //I'm really sorry for doing this but i had to :'( :'( :'(
                //may god forgive me
                rsCredentials.NetworkCredentials = new NetworkCredential("erpadmin", "Heavy.all2016@", "GHP");
                reportViewer.ZoomMode            = ZoomMode.PageWidth;


                var from = (int)numericFrom.Value;
                var to   = (int)numericTo.Value;

                var documents = new PrintDocument[1000];
                var i         = 0;
                ErrorLog.LogMessage($"Begin Rendering");
                for (var avoir = from; avoir <= to; avoir++)
                {
                    switch (_viewModel.GetTypeAvoir(avoir))
                    {
                    case 0:
                        reportViewer.ServerReport.ReportPath = "/ExpFinance/AvoirFinancier";
                        break;

                    case 1:
                        reportViewer.ServerReport.ReportPath = "/ExpFinance/AvoirFinancier_libre";
                        break;

                    case 2:
                        reportViewer.ServerReport.ReportPath = "/ExpFinance/AvoirFinancier_ant";
                        break;

                    case 3:
                        reportViewer.ServerReport.ReportPath = "/ExpFinance/AvoirFinancier_EF";
                        break;
                    }

                    ErrorLog.LogMessage($"Printing From {reportViewer.ServerReport.ReportPath}");
                    _numAvoir   = avoir;
                    _codeClient = _viewModel.GetCodeClient(avoir);
                    _montant    = _viewModel.GetAvoirFinancier(avoir).montant.ToString("N2");


                    if (string.IsNullOrEmpty(_codeClient))
                    {
                        continue;
                    }
                    var parameters = new[]
                    {
                        new ReportParameter("client", _codeClient),
                        new ReportParameter("numAvoir", _numAvoir.ToString()),

                        // new ReportParameter("montant", _montant)
                    };

                    //_reportViewer.ShowCredentialPrompts = true;
                    reportViewer.ServerReport.SetParameters(parameters);
                    reportViewer.RefreshReport();

                    var printabledocument = new ReportPrintDocument(reportViewer.ServerReport)
                    {
                        PrinterSettings =
                        {
                            FromPage    = 1,
                            ToPage      = 1,
                            MinimumPage = 1,
                            MaximumPage = 1
                        }
                    };

                    documents[i] = printabledocument;
                    var progress = (decimal)(avoir - from + 1) / (decimal)(to - from + 1) * 100;
                    printingWorker.ReportProgress((int)progress);
                    i++;
                }

                ErrorLog.LogMessage("All pages done");
                var printingDocuments = new MultiPrintDocument(documents)
                {
                    PrinterSettings = { Copies = (short)numericCopies.Value }
                };


                //set printing settings
                if (string.IsNullOrEmpty(_printerName))
                {
                    var printerDialog = new PrintDialog();
                    var result        = printerDialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        _printerName = printerDialog.PrinterSettings.PrinterName;
                        printingDocuments.PrinterSettings.PrinterName = _printerName;
                    }
                }
                else
                {
                    printingDocuments.PrinterSettings.PrinterName = _printerName;
                }

                ErrorLog.LogMessage("Begin Printing");

                printingDocuments.Print();
            }
            catch (Exception ex)
            {
                Messages.Error("Une erreur s'est produite !");
                ErrorLog.LogError($"Impression de {Settings.Default.reportServerURL}", ex);
            }
        }
Exemple #21
0
        private bool InsertFacturesEf(List <string> listeCode)
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();

                    //Get the liste of facture
                    var liste = detail.GetListeFacturesClientAll(listeCode);



                    //Creating Groupe Details
                    var     entite = liste.Select(f => f.entite).FirstOrDefault();
                    var     codeClient = liste.Select(f => f.code_clien).FirstOrDefault();
                    decimal?mntHt = 0, mntRz = 0, mntTtc = 0, mntTva = 0, marge = 0;

                    //calculating totales in factures
                    liste.ForEach(f =>
                    {
                        mntHt  += f.total_HT; //this is HTR !!
                        mntRz  += f.T_remise;
                        mntTtc += f.total_TTC;
                        mntTva += f.total_TVA;
                        marge  += f.Marge;
                    });


                    //Escompte Financier without factures
                    if (liste.Count == 0)
                    {
                        codeClient = comboBoxClient.SelectedValue.ToString();
                        entite     = Settings.Default.entite;
                    }

                    var margeRest = marge - _montant;

                    var etat = 5;

                    var newGroupe = new AF_EF_GROUPE_FACTURE
                    {
                        ENTITE       = entite,
                        CODE_CLIENT  = codeClient,
                        MNT_HT       = mntHt,
                        MNT_RZ       = mntRz,
                        MNT_TVA      = mntTva,
                        MNT_TTC      = mntTtc,
                        MARGE        = marge,
                        MARGE_REST   = margeRest,
                        ETAT         = etat,
                        DATE_DOSSIER = DateTime.Today,
                        ID_LIGNE     = _codePromo, //we store promotion here
                        NB_CADEAU    = _codePalier //we store wich palier here
                    };

                    model.AF_EF_GROUPE_FACTURE.Add(newGroupe);
                    model.SaveChanges();
                    _numGroupe = newGroupe.ID_GROUPE_FACT;

                    liste.ForEach(facture =>
                    {
                        var newFacture = new AF_EF_FACTURE
                        {
                            NUM_FACT       = facture.num_trans,
                            CODE_CLIENT    = facture.code_clien,
                            DATE_FACT      = facture.date_trans ?? default(DateTime),
                            ENTITE         = facture.entite,
                            MARGE          = facture.Marge,
                            MNT_HT_RZ      = facture.total_HT - facture.T_remise,
                            MNT_TTC        = facture.total_TTC,
                            MNT_RZ         = facture.T_remise,
                            MNT_TVA        = facture.total_TVA,
                            ID_GROUPE_FACT = newGroupe.ID_GROUPE_FACT
                        };

                        model.AF_EF_FACTURE.Add(newFacture);

                        //Insert lines if there is


                        if (_lignesList.Count > 0 && _lignesList.ContainsKey((int)newFacture.NUM_FACT))
                        {
                            var lignes = _lignesList[(int)newFacture.NUM_FACT];

                            lignes.ForEach(ligne =>
                            {
                                var newLigne = new AF_EF_LIGNE_FACTURE
                                {
                                    NUM_FACT  = newFacture.NUM_FACT,
                                    DATE_FACT = newFacture.DATE_FACT,
                                    ENTITE    = newFacture.ENTITE,
                                    NUM_LIGNE = ligne
                                };

                                model.AF_EF_LIGNE_FACTURE.Add(newLigne);
                            });
                        }
                    });

                    model.SaveChanges();
                    _numGroupe = newGroupe.ID_GROUPE_FACT;
                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error($@"Erreur insertion factures: \n {e.Message}
                                 \n {e.InnerException?.Message}
                                   \n {e.InnerException?.InnerException?.Message}");

                _numGroupe = 0;
                ErrorLog.LogError("Erreur insertion factures", e);
                return(false);
            }
        }
Exemple #22
0
        private bool InsertFactures(List <string> listeCode)
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    //EXERCICE ANTERIEUR
                    if (!_isFacture)
                    {
                        var ent = Settings.Default.entite;
                        var cli = comboBoxClient.SelectedValue.ToString();
                        //store the date just to keep the date
                        var year = new DateTime((int)dateExercice.Value, 1, 1);

                        var newGroupeCvn = new AF_GROUPE_FACTURE
                        {
                            ENTITE       = ent,
                            CODE_CLIENT  = cli,
                            MNT_HT       = _total,
                            DATE_CADEAU  = year,
                            DATE_DOSSIER = DateTime.Today,
                        };

                        model.AF_GROUPE_FACTURE.Add(newGroupeCvn);
                        model.SaveChanges();
                        _numGroupe = newGroupeCvn.ID_GROUPE_FACT;
                        return(true);
                    }


                    var detail = new DetailsDossier();

                    //Get the liste of facture
                    var liste = detail.GetListeFacturesClient(listeCode);

                    //Creating Groupe Details
                    var     entite = liste.Select(f => f.entite).First();
                    var     codeClient = liste.Select(f => f.code_clien).First();
                    decimal?mntHt = 0, mntRz = 0, mntTtc = 0, mntTva = 0, marge = 0;

                    //calculating totales in factures
                    liste.ForEach(f =>
                    {
                        mntHt  += f.total_HT; //this is HTR !!
                        mntRz  += f.T_remise;
                        mntTtc += f.total_TTC;
                        mntTva += f.total_TVA;
                        marge  += f.Marge;
                    });

                    var margeRest = marge - _montant;

                    var etat = 5;

                    var newGroupe = new AF_GROUPE_FACTURE
                    {
                        ENTITE       = entite,
                        CODE_CLIENT  = codeClient,
                        MNT_HT       = mntHt,
                        MNT_RZ       = mntRz, MNT_TVA = mntTva,
                        MNT_TTC      = mntTtc,
                        MARGE        = marge,
                        MARGE_REST   = margeRest,
                        ETAT         = etat,
                        DATE_DOSSIER = DateTime.Today,
                    };

                    model.AF_GROUPE_FACTURE.Add(newGroupe);
                    model.SaveChanges();
                    _numGroupe = newGroupe.ID_GROUPE_FACT;

                    liste.ForEach(facture =>
                    {
                        var newFacture = new AF_FACTURE
                        {
                            NUM_FACT       = facture.num_trans,
                            CODE_CLIENT    = facture.code_clien,
                            DATE_FACT      = facture.date_trans ?? default(DateTime),
                            ENTITE         = facture.entite,
                            MARGE          = facture.Marge,
                            MNT_HT_RZ      = facture.total_HT - facture.T_remise,
                            MNT_TTC        = facture.total_TTC,
                            MNT_RZ         = facture.T_remise,
                            MNT_TVA        = facture.total_TVA,
                            ID_GROUPE_FACT = newGroupe.ID_GROUPE_FACT
                        };

                        model.AF_FACTURE.Add(newFacture);

                        //Insert lines if there is


                        if (_lignesList.Count > 0 && _lignesList.ContainsKey((int)newFacture.NUM_FACT))
                        {
                            var lignes = _lignesList[(int)newFacture.NUM_FACT];

                            lignes.ForEach(ligne =>
                            {
                                var newLigne = new AF_LIGNE_FACTURE
                                {
                                    NUM_FACT  = newFacture.NUM_FACT,
                                    DATE_FACT = newFacture.DATE_FACT,
                                    ENTITE    = newFacture.ENTITE,
                                    NUM_LIGNE = ligne
                                };

                                model.AF_LIGNE_FACTURE.Add(newLigne);
                            });
                        }
                    });

                    model.SaveChanges();
                    _numGroupe = newGroupe.ID_GROUPE_FACT;
                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error(@"Erreur insertion factures: " + e.Message);
                ErrorLog.LogError(@"Erreur insertion factures: ", e);
                _numGroupe = 0;
                return(false);
            }
        }
Exemple #23
0
        private void LoadAvoir(AVOIR_FINANCIER avoir)
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();
                    //Set références
                    _numAvoir            = avoir.numAvoir;
                    textBoxRefAvoir.Text = _numAvoir.ToString("D");
                    _montant             = avoir.montant;
                    _cheque                 = avoir.montantCheque;
                    _creance                = avoir.montantCreance;
                    _observation            = avoir.Observation;
                    textBoxDesc.Text        = avoir.designation;
                    textBoxObservation.Text = avoir.Observation;
                    dateAvoir.Value         = avoir.dateAvoir;

                    //Get cheques
                    _chequesList = (from c in model.CHEQUE where c.numAvoir == avoir.numAvoir select c).ToList();
                    RebindListBoxCheque();
                    TotalCheque();

                    //Set type
                    switch (avoir.typeAvoir)
                    {
                    case 1:
                        _isCheque  = true;
                        _isCreance = false;
                        break;

                    case 2:
                        _isCreance = true;
                        _isCheque  = false;
                        break;

                    case 3:
                        _isCheque = _isCreance = true;
                        break;

                    default:
                        _isCheque = _isCreance = false;
                        break;
                    }


                    //Get Groupe Factures related to the avoir
                    _numGroupe = (from afg in model.AF_AVOIR_GROUPE
                                  where afg.numAvoir == _numAvoir
                                  select afg.IDG).ToList();


                    // ReSharper disable once ConstantNullCoalescingCondition
                    if (_numGroupe.Count == 0)
                    {
                        throw new NullReferenceException("Les groupse factures liés à cette avoir n'existe plus !");
                    }

                    // var factures = detail.GetFactures(_numGroupe);
                    var factures = new List <FACTURE>();

                    //Get factures of each groupe then put them all in one list
                    _numGroupe.ForEach(g =>
                    {
                        var groupeFactures = detail.GetFactures(g);
                        //add each groupe factures to the global list
                        groupeFactures.ForEach(factures.Add);
                    });

                    PopulateFacutresListView(factures);

                    //disable facture item check
                    listViewFactures.ItemCheck -= listViewFactures_ItemCheck;
                    foreach (ListViewItem item in listViewFactures.Items)
                    {
                        item.Checked = true;
                    }



                    //set totals values
                    decimal t, m;
                    TotalFactures(out t, out m);

                    //set reste
                    _reste = _montant - (_creance + _cheque);

                    textBoxMontantAv.Text = $"{_montant:#,##0.00}";
                    textBoxCreance.Text   = $"{_creance:#,##0.00}";

                    //enable facture item check
                    listViewFactures.ItemCheck += listViewFactures_ItemCheck;

                    CheckType();
                }
            }
            catch (Exception e)
            {
                Messages.Error("Error Loading avoir :" + e.Message);
                ErrorLog.LogError("Error Loading avoir", e);
                Close();
            }
        }
Exemple #24
0
        private bool InsertAvoir(AVOIR_FINANCIER avoir)
        {
            try
            {
                decimal mntAv;
                decimal.TryParse(textBoxMontantAv.Text, out mntAv);

                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();


                    //Set référence (if new avoir get the new num according to the year)
                    if (_avoir == null)
                    {
                        _numAvoir = detail.GetLastAvoirId(dateAvoir.Value);
                    }

                    avoir.numAvoir       = _numAvoir;
                    avoir.montant        = mntAv;
                    avoir.dateAvoir      = dateAvoir.Value.Date;
                    avoir.designation    = _designation;
                    avoir.montantCheque  = _cheque;
                    avoir.montantCreance = _creance;
                    avoir.Observation    = _observation;
                    avoir.typeAvoir      = (byte)_typeAvoir;
                    model.AVOIR_FINANCIER.AddOrUpdate(avoir);


                    var op = new AF_OPS_LOG
                    {
                        instant   = DateTime.Now,
                        username  = Environment.UserName,
                        numavoir  = _numAvoir,
                        Operation = "Avoir inséré"
                    };

                    model.AF_OPS_LOG.Add(op);


                    //insert the related groups
                    foreach (int g in _numGroupe)
                    {
                        var avoirGroupe = new AF_AVOIR_GROUPE
                        {
                            numAvoir = avoir.numAvoir,
                            IDG      = g,
                            Libre    = 0
                        };

                        model.AF_AVOIR_GROUPE.Add(avoirGroupe);
                    }

                    //Insert in the etat table
                    foreach (int g in _numGroupe)
                    {
                        var etat = new AF_ETAT_AVOIR
                        {
                            numDossier = detail.GetGroupeInfo(g).NDOSSIER,
                            numAvoir   = avoir.numAvoir,
                            IDG        = g,
                            Etat       = 3,
                            dateHeure  = DateTime.Now
                        };

                        model.AF_ETAT_AVOIR.Add(etat);
                    }


                    model.SaveChanges();
                    return(true);
                }
            }

            catch (Exception ex)
            {
                Messages.Error("Erreur insertion avoir:" + ex.Message);
                ErrorLog.LogError("Erreur insertion avoir", ex);
                return(false);
            }
        }
Exemple #25
0
        private bool InsertAnte()
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();

                    var tempdata = (from temp in model.AF_TEMP_DATA_ANT
                                    where temp.entite == _entite
                                    select temp);


                    foreach (var temp in tempdata)
                    {
                        //EXERCICE ANTERIEUR
                        ErrorLog.LogMessage($"treating avoir{temp.numAvoir}");
                        var year     = temp.Exercice;
                        var factures = temp.factures.Split('-').ToList();


                        //Get the liste of facture
                        var liste = detail.GetListeFacturesClientAllYears(factures, year.Value.Year);

                        if (liste.Count == 0 || liste.All(f => f == null))
                        {
                            ErrorLog.LogMessage($"No factures in avoir{temp.numAvoir}");
                        }
                        //Creating Groupe Details
                        //var entite = liste.Where(f=>f!=null).Select(f => f.entite).First();
                        //var codeClient = liste.Where(f => f != null).Select(f => f.code_clien).First();
                        decimal?mntHt = 0, mntRz = 0, mntTtc = 0, mntTva = 0, marge = 0;

                        if (liste.Count != 0 || liste.All(f => f != null))
                        {
                            //calculating totales in factures
                            liste.ForEach(f =>
                            {
                                mntHt  += f?.total_HT; //this is HTR !!
                                mntRz  += f?.T_remise;
                                mntTtc += f?.total_TTC;
                                mntTva += f?.total_TVA;
                                marge  += f?.Marge;
                            });
                        }

                        var newGroupeCvn = new AF_TEMP_GROUPE_FACTURE
                        {
                            ID_GROUPE_FACT = temp.idgroupe ?? 0,
                            DATE_CADEAU    = year,
                            DATE_DOSSIER   = DateTime.Today,
                            ENTITE         = _entite,
                            CODE_CLIENT    = temp.codeClient,
                            //MNT_HT = temp.CA, //this info is given by entite (we switch to avoid to insert les avoirs clients)
                            MNT_HT         = mntHt,
                            MNT_RZ         = mntRz,
                            MNT_TVA        = mntTva,
                            MNT_TTC        = mntTtc,
                            MONTANT_CHEQUE = mntHt,//this by the db
                            MARGE          = marge,
                            ETAT           = 20,
                        };

                        model.AF_TEMP_GROUPE_FACTURE.Add(newGroupeCvn);


                        if (liste.Count != 0 || liste.All(f => f != null))
                        {
                            liste.ForEach(facture =>
                            {
                                if (facture != null)
                                {
                                    var newFacture = new AF_TEMP_FACTURE
                                    {
                                        NUM_FACT       = facture.num_trans,
                                        CODE_CLIENT    = facture.code_clien,
                                        DATE_FACT      = facture.date_trans ?? default(DateTime),
                                        ENTITE         = facture.entite,
                                        MARGE          = facture.Marge,
                                        MNT_HT_RZ      = facture.total_HT - facture.T_remise,
                                        MNT_TTC        = facture.total_TTC,
                                        MNT_RZ         = facture.T_remise,
                                        MNT_TVA        = facture.total_TVA,
                                        ID_GROUPE_FACT = temp.idgroupe ?? 0,
                                    };

                                    model.AF_TEMP_FACTURE.Add(newFacture);
                                }
                            });
                        }

                        //model.SaveChanges();
                        //_numGroupe = newGroupeCvn.ID_GROUPE_FACT;



                        //Insert AVOIR


                        _numAvoir = temp.numAvoir;


                        var avoir = new AF_TEMP_AVOIR_FINANCIER
                        {
                            numAvoir          = _numAvoir,
                            montant           = temp.Montant ?? 0,
                            dateAvoir         = temp.dateAvoir ?? DateTime.Now,
                            designation       = "REMISE FINANCIERE",
                            montantCheque     = temp.cheque ?? 0,
                            montantCreance    = temp.creance ?? 0,
                            Observation       = "",
                            typeAvoir         = byte.Parse(temp.typeAvoir),
                            numAvoirComptable = 20,
                        };


                        var libre = (byte)2;

                        //insert the related group
                        var avoirGroupe = new AF_TEMP_AVOIR_GROUPE
                        {
                            numAvoir = avoir.numAvoir,
                            IDG      = temp.idgroupe ?? 0,
                            Libre    = libre
                        };

                        model.AF_TEMP_AVOIR_GROUPE.Add(avoirGroupe);


                        //Insert in the etat table
                        var etat = new AF_TEMP_ETAT_AVOIR
                        {
                            numDossier = temp.refAvoir,
                            numAvoir   = avoir.numAvoir,
                            IDG        = temp.idgroupe ?? 0,
                            Etat       = 3,
                            dateHeure  = DateTime.Today
                        };

                        model.AF_TEMP_ETAT_AVOIR.Add(etat);

                        model.AF_TEMP_AVOIR_FINANCIER.Add(avoir);

                        //model.SaveChanges();
                    }
                    model.SaveChanges();

                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error(@"Erreur insertion factures: " + e.Message);
                ErrorLog.LogError(@"Erreur insertion factures: ", e);
                return(false);
            }
        }
Exemple #26
0
        void SetDetails(int row)
        {
            try
            {
                //getting details
                var details = new DetailsDossier();
                var idg     = TableGetID_GF(row);
                if (idg == 0)
                {
                    return;
                }

                var groupe = details.GetGroupeInfo(idg);

                if (groupe == null)
                {
                    return;
                }

                var promotion = details.GetPromoInfo(groupe.ID_LIGNE ?? 0);

                //getting invoices nums
                var factures      = details.GetFactures(idg);
                var listeFactures = "";
                factures.ForEach(x => listeFactures += x.NUM_FACT + @" | ");
                listeFactures = listeFactures.Remove(listeFactures.Length - 2);
                tableFactures.Controls.Clear();
                int i = 0, l = 0;
                factures.ForEach(f =>
                {
                    if (i > 5)
                    {
                        i = 0;
                        l++;
                    }
                    var linkFacture = new LinkLabel {
                        Text = ((int)f.NUM_FACT).ToString("D"), LinkColor = Color.DimGray, Font = new Font("Segoe UI Semibold", 8.5F, FontStyle.Bold, GraphicsUnit.Point, ((0)))
                    };
                    linkFacture.Click += (sender, args) => ViewFacture(f.NUM_FACT, f.CODE_CLIENT, f.ENTITE);
                    tableFactures.Controls.Add(linkFacture, i, l);
                    i++;
                });


                //Setting details to the view
                textBoxPromotion.Text = promotion.NOM_PROMOTION;
                NomClient             = textBoxClient.Text = TableGetClientName(row);
                textBoxFactures.Text  = listeFactures;
                textBoxDateD.Text     = groupe.DATE_DOSSIER != null?groupe.DATE_DOSSIER.Value.ToShortDateString() : default(string);


                decimal txRest = 0;
                decimal.TryParse(groupe.REF_RISTOURNE, out txRest);
                if (groupe.MONTANT_RISTOURNE > 0)
                {
                    decimal.TryParse(groupe.REF_RISTOURNE, out txRest);
                }
                else
                {
                    txRest = groupe.TX_REST ?? 0;
                }

                textBoxNumDossier.Text = groupe.NDOSSIER;
                textBoxMarge.Text      = string.Format("{0:#,##0.00 Da}", groupe.MARGE);
                textBoxMarge.Text     += @" ( " + string.Format("{0:P2}", groupe.MARGE / groupe.MNT_TTC) + @" )";
                textBoxMargeRest.Text  = string.Format("{0:#,##0.00 Da}", groupe.MARGE_REST - groupe.MONTANT_RISTOURNE ?? 0);
                textBoxMargeRest.Text += @" ( " + string.Format("{0:P2}", txRest / 100) + @" )";
                textBoxTypePromo.Text  = groupe.TYPE_PROMOTION;
            }
            catch (Exception ex)
            {
                Messages.Error("Erreur lecture de données");
                ErrorLog.LogError("set details", ex);
                Close();
            }
        }
Exemple #27
0
        private bool InsertAvoir2016()
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();

                    var tempdata = (from temp in model.AF_TEMP_DATA
                                    where temp.entite == _entite
                                    select temp);

                    foreach (var temp in tempdata)
                    {
                        //EXERCICE 2016
                        var factures = temp.factures.Split('-').ToList();
                        ErrorLog.LogMessage($"treating avoir{temp.numAvoir}");


                        //Get the liste of facture
                        var liste = detail.GetListeFacturesClientAll(factures);
                        if (liste.Count == 0 || liste.All(f => f == null))
                        {
                            ErrorLog.LogMessage($"No factures in avoir{temp.numAvoir}");
                        }
                        //Creating Groupe Details
                        //var entite = liste.Where(f => f != null).Select(f => f.entite).First();
                        //var codeClient = liste.Where(f => f != null).Select(f => f.code_clien).First();
                        decimal?mntHt = 0, mntRz = 0, mntTtc = 0, mntTva = 0, marge = 0;

                        //calculating totales in factures
                        if (liste.Count != 0 || liste.All(f => f != null))
                        {
                            //calculating totales in factures
                            liste.ForEach(f =>
                            {
                                mntHt  += f?.total_HT; //this is HTR !!
                                mntRz  += f?.T_remise;
                                mntTtc += f?.total_TTC;
                                mntTva += f?.total_TVA;
                                marge  += f?.Marge;
                            });
                        }


                        var newGroupeCvn = new AF_TEMP_GROUPE_FACTURE
                        {
                            ID_GROUPE_FACT = temp.idgroupe ?? 0,
                            DATE_DOSSIER   = DateTime.Today,
                            ENTITE         = _entite,
                            CODE_CLIENT    = temp.codeClient,
                            MNT_HT         = mntHt,
                            MNT_RZ         = mntRz,
                            MNT_TVA        = mntTva,
                            MNT_TTC        = mntTtc,
                            MARGE          = marge,
                            ETAT           = 10,
                        };

                        model.AF_TEMP_GROUPE_FACTURE.Add(newGroupeCvn);

                        if (liste.Count != 0 || liste.All(f => f != null))
                        {
                            liste.ForEach(facture =>
                            {
                                if (facture != null)
                                {
                                    var newFacture = new AF_TEMP_FACTURE
                                    {
                                        NUM_FACT       = facture.num_trans,
                                        CODE_CLIENT    = facture.code_clien,
                                        DATE_FACT      = facture.date_trans ?? default(DateTime),
                                        ENTITE         = facture.entite,
                                        MARGE          = facture.Marge,
                                        MNT_HT_RZ      = facture.total_HT - facture.T_remise,
                                        MNT_TTC        = facture.total_TTC,
                                        MNT_RZ         = facture.T_remise,
                                        MNT_TVA        = facture.total_TVA,
                                        ID_GROUPE_FACT = temp.idgroupe ?? 0,
                                    };

                                    model.AF_TEMP_FACTURE.Add(newFacture);
                                }
                            });
                        }

                        //Insert AVOIR


                        _numAvoir = temp.numAvoir;


                        var avoir = new AF_TEMP_AVOIR_FINANCIER
                        {
                            numAvoir          = _numAvoir,
                            montant           = temp.Montant ?? 0,
                            dateAvoir         = temp.dateAvoir,
                            designation       = "REMISE FINANCIERE",
                            montantCheque     = temp.cheque ?? 0,
                            montantCreance    = temp.creance ?? 0,
                            Observation       = "",
                            typeAvoir         = byte.Parse(temp.typeAvoir),
                            numAvoirComptable = 10,
                        };


                        var libre = (byte)1;

                        //insert the related group
                        var avoirGroupe = new AF_TEMP_AVOIR_GROUPE
                        {
                            numAvoir = avoir.numAvoir,
                            IDG      = temp.idgroupe ?? 0,
                            Libre    = libre
                        };

                        model.AF_TEMP_AVOIR_GROUPE.Add(avoirGroupe);


                        //Insert in the etat table
                        var etat = new AF_TEMP_ETAT_AVOIR
                        {
                            numDossier = temp.refAvoir,
                            numAvoir   = avoir.numAvoir,
                            IDG        = temp.idgroupe ?? 0,
                            Etat       = 3,
                            dateHeure  = DateTime.Today
                        };

                        model.AF_TEMP_ETAT_AVOIR.Add(etat);

                        model.AF_TEMP_AVOIR_FINANCIER.Add(avoir);
                    }

                    model.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error(@"Erreur insertion factures: " + e.Message);
                ErrorLog.LogError(@"Erreur insertion factures: ", e);
                return(false);
            }

            //catch (DbEntityValidationException e)
            //{
            //    foreach (var eve in e.EntityValidationErrors)
            //    {
            //        ErrorLog.LogError($"Entity of type \"{ eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors:");
            //        foreach (var ve in eve.ValidationErrors)
            //        {
            //            ErrorLog.LogError($"- Property: \"{ ve.PropertyName}\", Error: \"{ve.ErrorMessage}\"");
            //        }
            //    }
            //    throw;
            //}
        }