Example #1
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();
            }
        }
Example #2
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);
            }
        }
Example #3
0
        private bool InsertAvoirEf(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");


                    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;


                    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 = (byte)3;

                    //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: " + e.InnerException.Message);
                ErrorLog.LogError("Erreur insertion avoir financier", e);
                return(false);
            }
        }
Example #4
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);
            }
        }
Example #5
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);
            }
        }
Example #6
0
 private void printingWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     ErrorLog.LogMessage("Work done.");
 }