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(); } }
private void PopulateComboboxPromotion() { var detail = new DetailsDossier(); var list = detail.GetListOfPromotions().Select( p => new { CODE = p.CODE_PROMOTION, NOM = p.NOM_PROMOTION }).ToList(); list.Add(new { CODE = 0, NOM = " - N/A" }); comboBoxPromotions.DataSource = list.OrderBy(p => p.NOM).ToList(); comboBoxPromotions.ValueMember = "CODE"; comboBoxPromotions.DisplayMember = "NOM"; }
private void comboBoxPalierEf_SelectedValueChanged(object sender, EventArgs e) { if (!textBoxTauxMontant.Enabled) { return; } var d = new DetailsDossier(); int p; if (!int.TryParse(comboBoxPalierEf.SelectedValue.ToString(), out p)) { return; } decimal t = d.GetTauxPalier(p); _codePalier = p; textBoxTauxMontant.Text = t.ToString("N2"); }
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; } }
private void PopulateComboxBoxPalierEf() { var detail = new DetailsDossier(); var listPalier = detail.GetListPalier() .Select( p => new { val = p.idPalier, display = $"ESCOMPTE FINANCIER ({p.Percentage}%)" }) .ToList(); listPalier.Add(new { val = 0, display = " - AUTRE" }); comboBoxPalierEf.DataSource = listPalier; comboBoxPalierEf.ValueMember = "val"; comboBoxPalierEf.DisplayMember = "display"; }
private void buttonGenerAvoir_Click(object sender, EventArgs e) { if (gridView.FocusedValue == null) { return; } if (gridView.GetSelectedRows().Count() == 0) { return; } var rows = gridView.GetSelectedRows(); var detail = new DetailsDossier(); if (rows.Count() > 1) { var client = TableGetClientName(rows[0]); if (rows.Any(r => TableGetClientName(r) != client)) { Alert("Veuillez sélectionner les dossier d'un seul client !!"); return; } } else { //if it is validated } if (rows.Any(r => detail.GetState(TableGetID_GF(r)) != 2)) { Alert("Seul les dossiers reçus peuvent être traité !!"); return; } var avrf = new AvoirForm(GetSelectedGroups(rows).ToList(), TableGetTotal(rows)); avrf.Closed += AvrfOnClosed; avrf.ShowDialog(); }
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(); } }
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(); } }
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(); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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; //} }