#include "frenchTax.h"

#include <common/icore.h>
#include <common/settings.h>
#include <common/commandlineparser.h>
#include <common/constants.h>
#include <common/databasemanager.h>
#include <common/position.h>
#include <QtGui>
#include <QtCore>
#include <QtSql>


using namespace Common;
using namespace Constants;
static inline QString htmlPath(){return Common::ICore::instance()->settings()->applicationResourcesPath()+"/html";}
static inline Common::Settings *settings(){return Common::ICore::instance()->settings();}
frenchTax::frenchTax(){
  setupUi(this);
  Position *position = new Position;
  position->centralPosition(this,width(),height());
  setAttribute(Qt::WA_DeleteOnClose);
  m_db = QSqlDatabase::database(Constants::DB_ACCOUNTANCY);
  enumMapping();
  dateEdit->setDisplayFormat("yyyy");
  dateEdit->setToolTip(trUtf8("Année."));
  dateEdit->setDate(QDate::currentDate());
  m_beginYear = "";
  m_endYear = "";
  comboBox_2->setEditable(false);
  comboBox_2->setInsertPolicy(QComboBox::NoInsert);
  QStringList loginList;
  QSqlQuery queryUser(m_db);
            if(!queryUser.exec("SELECT login FROM utilisateurs")){
                messNoQuery(queryUser,__LINE__);
                emit close();
                return;
            }
            while(queryUser.next()){
                QString loginStr = queryUser.value(0).toString();
                loginList << loginStr;
            }
  //prefered user
  QString prefUser = Common::ICore::instance()->settings()->value(S_UTILISATEUR_CHOISI).toString();
  if(!loginList.isEmpty()){
      loginList.prepend(prefUser);
      }
  else{
      loginList << prefUser;
      }
  loginList.removeDuplicates();
  comboBox_2->addItems(loginList);
  m_textDoc = new QTextDocument;
  buildMapping();
  connect(pushButton  ,SIGNAL(pressed()),    this,SLOT(close()));
  connect(pushButton_2,SIGNAL(pressed()),    this,SLOT(print()));
  connect(pushButton_3,SIGNAL(pressed()),    this,SLOT(pdf()));
  connect(comboBox_2,  SIGNAL(highlighted(int)),this,SLOT(buildMapping()));
  connect(comboBox_2,  SIGNAL(activated(int)),this,SLOT(buildMapping()));
  connect(dateEdit,SIGNAL(dateChanged(const QDate &)),this, SLOT(buildMapping()));
}

frenchTax::~frenchTax(){}

void frenchTax::buildMapping(){
  m_sumsMap.clear();
  m_itemMap.clear();
  m_lettersMap.clear();
  QDate year = dateEdit->date();
  QString yearStr = year.toString("yyyy");
  qDebug() << yearStr;
  m_beginYear = yearStr+"-01-01";
  m_endYear = yearStr+"-12-31";
  QString user = comboBox_2->currentText();//login
  qDebug() << "user ="+user;
  QSqlQuery queryId(m_db);
  QString reqUser = QString("SELECT id_usr FROM utilisateurs WHERE login = '%1'").arg(user);
          if(!queryId.exec(reqUser)){
              messNoQuery(queryId,__LINE__);
              return;
          }
          qDebug() << queryId.lastQuery();
  QString userId;
  QStringList listUserId;
          while(queryId.next()){
              userId = queryId.value(0).toString();
              listUserId << userId;
          }
          if(listUserId.size() > 1){
              QMessageBox::critical(0,trUtf8("Critical"),
                                    trUtf8("Error = ")+"\n"__FILE__+QString::number(__LINE__),QMessageBox::Ok);
          }
          qDebug() << userId;
  //AA,1,AA_recettesEncaissees
  double totalRecettes = 0.00;
  QSqlQuery queryRecettes(m_db);
  QString reqRecettes = QString( "SELECT esp,chq,cb,autre FROM honoraires "
                        "WHERE id_usr = '%1' AND DATE BETWEEN '%2' AND '%3'").arg(userId,m_beginYear,m_endYear);
          if(!queryRecettes.exec(reqRecettes)){
              messNoQuery(queryRecettes,__LINE__);
              return;
          }
          qDebug() << queryRecettes.lastQuery();
          while(queryRecettes.next()){
              double esp   = queryRecettes.value(0).toDouble();
              double chq   = queryRecettes.value(1).toDouble();
              double cb    = queryRecettes.value(2).toDouble();
              double autre = queryRecettes.value(3).toDouble();
              double total = esp+chq+cb+autre;
              totalRecettes += total;
              qDebug() << "total recettes ="+QString::number(totalRecettes);
          }
  m_lettersMap.insert(AA_recettesEncaissees,"AA");
  m_itemMap.insert(AA_recettesEncaissees,trUtf8("Recettes encaissées"));
  m_sumsMap.insert(AA_recettesEncaissees,QString::number(totalRecettes));
  /*negatives sums : fillMap(int & typeEnum ,
                           QString & letterType,
                           QString & explanation,
                           QString & idMvtDispo,
                           QString & userId )*/
  //AB,2,AB_deboursPourClients
  double ABSum = fillMap(AB_deboursPourClients, "AB","Débours payé pour le compte des clients","38",userId);
  //AC,3,AC_honorairesRetrocedes
  double ACSum = fillMap(AC_honorairesRetrocedes,"AC","Honoraires rétrocédés","21",userId);
  //AD,4,AD_montantNetRecettes
  //AD=AA-AB-AC
  double ADSum = totalRecettes - ABSum - ACSum;
  m_lettersMap.insert(AD_montantNetRecettes,"AD");
  m_itemMap.insert(AD_montantNetRecettes,trUtf8("Montant net des recettes"));
  m_sumsMap.insert(AD_montantNetRecettes,QString::number(ADSum));
  //AE,5,AE_produitsFinanciers
  double AESum = fillMap(AE_produitsFinanciers,"AE","Produits financiers","3",userId);
  //AF,6,AF_gainsDivers
  double AFSum = fillMap(AF_gainsDivers,"AF","Gains divers","2",userId);
  //AG,7,AG_totalRecettes
  double AGSum = ADSum + AESum + AFSum;//Total Recettes
  m_lettersMap.insert(AG_totalRecettes,"AG");
  m_itemMap.insert(AG_totalRecettes,trUtf8("Total(lignes 4 à 6)"));
  m_sumsMap.insert(AG_totalRecettes,QString::number(AGSum));
  // end of RECETTES-------------------------------------------
  //beginning of DEPENSES
  //BA,8,BA_achats
  double BASum = fillMap(BA_achats,"BA","Achats","6",userId);
  //BB,9,BB_salairesNetPersonnels
  double BBSum = fillMap(BB_salairesNetPersonnels,"BB","Salaires nets et avantages en nature","8",userId);
  //BC,10,BC_chargesSurSalairesPersonnels
  double BCSum = fillMap(BC_chargesSurSalairesPersonnels,"BC",
                         "Charges sociales sur salaires(parts patronale et ouvrière","9",userId);
  //BD,11,BD_TVA
  double BDSum = fillMap(BD_TVA,"BD","Taxe sur la valeur ajoutée","11",userId);
  //BE,BE_taxeProfessionnelle,12
  double BESum = fillMap(BE_taxeProfessionnelle,"BE","Taxe professionnelle","12",userId);
  //BS,BS_autresImpots,13
  double BSSum = fillMap(BS_autresImpots,"BS","Autres impôts","13",userId);
  //BF,BF_loyersEtChargesLocatives,14
  double BFSum = fillMap(BF_loyersEtChargesLocatives,"BF","Loyer et charges locatives","15",userId);
  //BG,BG_locationMateriels,15
  double BGSum = fillMap(BG_locationMateriels,"BG",
          "Location de matériel et de mobilier dont redevance au titre d'un contrat de collaboration","16",userId);
  //BH,
      //BH_entretienReparations,16
      double BH16 = fillMap(BH_entretienReparations,"BH","Entretien et réparations","17",userId);
      //BH_personnelInterimaire,17
      double BH17 = fillMap(BH_personnelInterimaire,"BH","Personnel intérimaire","18",userId);
      //BH_petitOutillage,18
      double BH18 =fillMap(BH_petitOutillage,"BH","Petit outillage","19",userId);
      //BH_chauffageEauGazElectricite,19
      double BH19 = fillMap(BH_chauffageEauGazElectricite,"BH","Chauffage,eau,gaz,électricité","20",userId);
      //BH_honorairesNonRetrocedes,20
      double BH20 = fillMap(BH_honorairesNonRetrocedes,"BH",
                                             "Honoraires ne constituant pas des rétrocessions","22",userId);
      //BH_assurances,21
      double BH21 = fillMap(BH_assurances,"BH","Primes d'assurances","23",userId);
      //BH_totalTravauxFournitureServicesExterieurs
      double BHSum = BH16 + BH17 + BH18 + BH19 + BH20 + BH21;
      m_lettersMap.insert(BH_totalTravauxFournitureServicesExterieurs,"BH");
      m_itemMap.insert(BH_totalTravauxFournitureServicesExterieurs,
                     trUtf8("TOTAL:travaux,fournitures et services extérieurs."));
      m_sumsMap.insert(BH_totalTravauxFournitureServicesExterieurs,QString::number(BHSum));
  //BJ,
      //BJ_fraisVehiculesAuto,22
      double BJSumAuto = fillMap(BJ_fraisVehiculesAuto,"BJ","Frais de véhicules auto","25",userId);
      //BJ_fraisVehiculesMoto,22
      double BJSumMoto = fillMap(BJ_fraisVehiculesMoto,"BJ","Frais de véhicules auto","26",userId);
      //BJ_fraisDeplacementsAutres,23
      double BJSumAutresDeplacements = fillMap(BJ_fraisDeplacementsAutres,"BJ",
                                               "Autres frais de déplacements(voyages...)","27",userId);
      //BJ_totalFraisDeplacements
      double BJSum = BJSumAuto + BJSumMoto + BJSumAutresDeplacements;
      m_lettersMap.insert(BJ_totalFraisDeplacements,"BJ");
      m_itemMap.insert(BJ_totalFraisDeplacements,trUtf8("TOTAL:transports et déplacements"));
      m_sumsMap.insert(BJ_totalFraisDeplacements,QString::number(BJSum));
  //BK_chargesSocialePersonnelles,24
      double BKSum = fillMap(BK_chargesSocialePersonnelles,"BK","Charges sociales personnelles","28",userId);
  //BL
      //BL_fraisCongres,
      double BLCongres = fillMap(BL_fraisCongres,"BL","Congrès","31",userId);
      //BL_fraisReceptionRepresentations,
      double BLRepresentation = fillMap(BL_fraisReceptionRepresentations,"BL",
                                       "Réceptions et représentations, cadeaux","32",userId);

      //BL_fraisReceptionRepresentationsCongres,25
      double BLSum = BLCongres + BLRepresentation;
      qDebug() << __FILE__ << QString::number(__LINE__) << " " << "QString::number(BLSum) = " << QString::number(BLSum);
      m_lettersMap.insert(BL_fraisReceptionRepresentationsCongres,"BL");
      m_itemMap.insert(BL_fraisReceptionRepresentationsCongres,
                     trUtf8("Frais de réception,de représentation et de congrès"));
      m_sumsMap.insert(BL_fraisReceptionRepresentationsCongres,QString::number(BLSum));
  //BM
      //BM_bureauDocPTT,
      double BM1 = fillMap(BM_bureauDocPTT,"BM","Fournitures de bureau, documentation, PTT","33",userId);
      //BM_fraisActesContentieux,
      double BM2 = fillMap(BM_fraisActesContentieux,"BM","Frais d'actes et de contentieux","33",userId);
      //BM_CotisationsSyndicalesProfessionnelles,
      double BM3 = fillMap(BM_CotisationsSyndicalesProfessionnelles,"BM","Cotisations syndicales et professionnelles","33",userId);
      //BM_autresFraisGestion,
      double BM4 = fillMap(BM_autresFraisGestion,"BM","Autres frais divers de gestion","33",userId);
      //BM_totalFraisDiversGestion
      double BMSum = BM1 + BM2 + BM3 + BM4;
      m_lettersMap.insert(BM_totalFraisDiversGestion,"BM");
      m_itemMap.insert(BM_totalFraisDiversGestion,
                     trUtf8("TOTAL:frais divers de gestion"));
      m_sumsMap.insert(BM_totalFraisDiversGestion,QString::number(BMSum));
  //BN_fraisFinanciers,30
    double BNSum = fillMap(BN_fraisFinanciers,"BN","Frais financiers","36",userId);
  //BP_pertesDiverses,31
    double BPSum = fillMap(BP_pertesDiverses,"BP","Pertes diverses","37",userId);
  //BR_TotalDepenses,32
    double BRSum = BASum + BBSum + BCSum + BDSum + BESum + BSSum +
                   BFSum + BGSum + BHSum + BJSum + BKSum + BLSum +BMSum + BNSum + BPSum ;
    m_lettersMap.insert(BR_TotalDepenses,"BR");
    m_itemMap.insert(BR_TotalDepenses,trUtf8("Total(lignes 8 à 31)"));
    m_sumsMap.insert(BR_TotalDepenses,QString::number(BRSum));

    fillTableWidget();

}

void frenchTax::messNoQuery(QSqlQuery & query , const int line){
  QString error = query.lastError().text()+"\n"+QString::number(line)+__FILE__;
  QMessageBox::critical(0,trUtf8("Critical"),trUtf8("Error = ")+error,QMessageBox::Ok);
}

double frenchTax::fillMap(const int typeEnum ,
                          const char * letterType,
                          const char * explanation,
                          const char * idMvtDispo,
                          QString & userId ){
  double total = 0.00;
  QSqlQuery query(m_db);
  QString req = "SELECT %1 FROM mouvements WHERE %2 = '%3' AND %4 = '%5' AND DATE BETWEEN '%6' AND '%7'";//requete mouvements
          if(!query.exec(req.arg("montant",
                                 "id_mvt_dispo",
                                 QString(idMvtDispo),
                                 "id_usr",
                                 userId,
                                 m_beginYear,
                                 m_endYear))){
              qDebug() << query.lastQuery();
              messNoQuery(query,__LINE__);
              emit close();
              return 1.00;
          }
          while(query.next()){
              double montant = query.value(0).toDouble();
              total += montant;
          }
  m_lettersMap.insert(typeEnum,letterType);
  m_itemMap.insert(typeEnum,trUtf8(explanation));
  m_sumsMap.insert(typeEnum,QString::number(total));
  return total;
}

void frenchTax::fillTableWidget(){
  QTextCursor curs(m_textDoc);
  int r = 0;
  int c = 3;
  r = m_lettersMap.count();
  tableWidget->setRowCount(r);
  tableWidget->setColumnCount(c);
  for(int i = 1;i < BR_TotalDepenses+1  ; i++){
      QTableWidgetItem *itemLetters = new QTableWidgetItem(m_lettersMap.value(i));
      QTableWidgetItem *itemExpl = new QTableWidgetItem(m_itemMap.value(i));
      QTableWidgetItem *itemSum = new QTableWidgetItem(m_sumsMap.value(i));
      tableWidget->setItem(i-1,0,itemLetters);
      tableWidget->setItem(i-1,1,itemExpl);
      tableWidget->setItem(i-1,2,itemSum);
      QString text = m_lettersMap.value(i)+"   "+m_itemMap.value(i)+"   :   "+m_sumsMap.value(i)+" "+settings()->value(S_TYPE_OF_MONEY).toString()+"\n";
      curs.insertText(text);
      curs.movePosition(QTextCursor::EndOfLine,QTextCursor::MoveAnchor,1);
      curs.movePosition(QTextCursor::NextCharacter,QTextCursor::MoveAnchor,1);
  }

}

void frenchTax::print(){
     QPrinter printer;
     QPrintDialog printdialog(&printer,this);
                printdialog .setWindowTitle(tr("Imprimer"));
                printdialog.exec();
                m_textDoc->print(&printer);
    }

void frenchTax::pdf(){
  QString x = Common::ICore::instance()->settings()->value(Constants::X_2035).toString();
  QString y = Common::ICore::instance()->settings()->value(Constants::Y_2035).toString();
  qDebug() << "x ="+x;
  QStringList listHtml;
  QPixmap image(htmlPath()+"/resources_html/pg-3001.png");
  if(modifFileToNewHtml()){
  QFile fileHtml(htmlPath()+"/pageTroisMod.html");
  if(!fileHtml.open(QIODevice::ReadOnly)){
      qWarning() << "pageTroisMod.html cannot open or not found";
  }
  QTextStream streamHtml(&fileHtml);
  streamHtml.setCodec("UTF-8");
  while(!streamHtml.atEnd()){
      QString line = streamHtml.readLine();
      listHtml << line+"\n";
  }
  QPainter *paint = new QPainter;
  if(paint->begin(&image)){
      qDebug() << "Painting image is possible";
  }
  paint->setPen(QPen(Qt::black));
  paint->setFont(QFont("Helvetica",6,QFont::Normal));

  //paint->setBackground(image);
  QString str;
  foreach(str,listHtml){

      if(str.contains("<DIV")&& !str.contains("relative")){
          if(str.contains("REVENUS 1998")){
              str.replace("REVENUS 1998","REVENUS  "+QDate::currentDate().toString("yyyy"));
          }
          //position top
          //<DIV style="position:absolute;top:717;left:38"><nobr><span class="ft0">27</span></nobr></DIV>:
          //<DIV style="position:absolute;top:439;left:27"><nobr><span class="ft17"><b>D<br>É<br>P<br>E<br>N<br>S<br>E<br>S</b></span></nobr></DIV>
          str.remove("<DIV style=\"position:absolute;top:");
          str.remove("left:");
          str.remove("\"><nobr><span class");
          str.remove("</span></nobr></DIV>");
          str.remove("\"ft");
          str.remove("\n");
          str.replace("&nbsp;"," ");

          //reste 717;38=o">27
          //qDebug() << str;
          if(str.contains("<br>")){
              if(str.contains("TOTAL :")){
                  QString rightStr = str.split("<b>")[1];
                  rightStr.remove("<b>");
                  rightStr.remove("</b>");
                  qDebug() << "rightstr = "+rightStr;

                  QString pos = str.split("=")[0];
                  int y = pos.split(";")[0].toInt();
                  int x = pos.split(";")[1].toInt();

                 QStringList list = rightStr.split("<br>");
                 QString str;
                 foreach(str,list){
                     paint->drawText(QPointF(x,y),str);
                     y+= 9;
                 }
                  continue;
              }
              else{
                  str.remove("<br>");
                  str.replace("<b>","");
                  str.replace("</b>","");
                  QString rightStr = str.split(">")[1];
                  QString pos = str.split("=")[0];
                  int y = pos.split(";")[0].toInt();
                  int x = pos.split(";")[1].toInt();

                 for(QString::iterator it = rightStr.begin();it != rightStr.end() ; it++ ){
                    paint->drawText(QPointF(x,y),QString(*it));
                    y += 11;
                 }
                continue;
              }
          }
          if(str.contains(">")){
              str.replace("<b>","");
              str.replace("</b>","");
              QStringList listUn = str.split(">");
              QString sum = listUn[1];
              //qDebug() << sum;
              QStringList listTwo = listUn[0].split("=");
              QString pos = listTwo[0];
              QStringList listThree = pos.split(";");
              int h = 0;
              int w = 0;
              if(y.contains("-")){
                  qDebug() << "-";
                  h = listThree[0].toInt()-y.toInt();
              }
              else{
                  h = listThree[0].toInt()+y.toInt();
              }
              if(x.contains("-")){
                  w  = listThree[1].toInt()-x.toInt();
              }
              else{
                  w  = listThree[1].toInt()+x.toInt();
              }

          paint->drawText(QPointF(w,h),sum);
          }
      }
  }
  image.save(htmlPath()+"/image.png");
  QTextDocument *doc = new QTextDocument;
  QTextCursor c(doc);
  c.insertImage(QImage(htmlPath()+"/image.png"));

  /*QTextEdit *t = new QTextEdit;
  t->resize(800,600);
  t->setDocument(doc);
  t->show();*/

  QPrinter *p = new QPrinter();
  //p->setOutputFileName (htmlPath()+"/fichier.pdf" );
  //p->setOutputFormat(QPrinter::PdfFormat);
  QPrintDialog printDialog(p,this);
  if(printDialog.exec() == QDialog::Accepted){
      doc->print(p);
  }
  paint->end();
  }
  else{qDebug() << "Erreur __FILE__ "+QString::number(__LINE__);}

}

void frenchTax::enumMapping(){
  m_enumMap.insert(AA_recettesEncaissees ,"AA_recettesEncaissees");
  m_enumMap.insert(      AB_deboursPourClients,"AB_deboursPourClients");
  m_enumMap.insert(      AC_honorairesRetrocedes,"AC_honorairesRetrocedes");
  m_enumMap.insert(      AD_montantNetRecettes,"AD_montantNetRecettes");
  m_enumMap.insert(      AE_produitsFinanciers,"AE_produitsFinanciers");
  m_enumMap.insert(      AF_gainsDivers,"AF_gainsDivers");
  m_enumMap.insert(      AG_totalRecettes,"AG_totalRecettes");
   m_enumMap.insert(     BA_achats,"BA_achats");
  m_enumMap.insert(      BB_salairesNetPersonnels,"BB_salairesNetPersonnels");
  m_enumMap.insert(      BC_chargesSurSalairesPersonnels,"BC_chargesSurSalairesPersonnels");
  m_enumMap.insert(      BD_TVA,"BD_TVA");
   m_enumMap.insert(     BE_taxeProfessionnelle,"BE_taxeProfessionnelle");
    m_enumMap.insert(    BS_autresImpots,"BS_autresImpots");
  m_enumMap.insert(      BF_loyersEtChargesLocatives,"BF_loyersEtChargesLocatives");
  m_enumMap.insert(      BG_locationMateriels,"BG_locationMateriels");
  m_enumMap.insert(      BH_entretienReparations,"BH_entretienReparations");
  m_enumMap.insert(      BH_personnelInterimaire,"BH_personnelInterimaire");
  m_enumMap.insert(      BH_petitOutillage,"BH_petitOutillage");
  m_enumMap.insert(      BH_chauffageEauGazElectricite,"BH_chauffageEauGazElectricite");
  m_enumMap.insert(      BH_honorairesNonRetrocedes,"BH_honorairesNonRetrocedes");
  m_enumMap.insert(      BH_assurances,"BH_assurances");
  m_enumMap.insert(      BH_totalTravauxFournitureServicesExterieurs,"BH_totalTravauxFournitureServicesExterieurs");
  m_enumMap.insert(      BJ_fraisVehiculesAuto,"BJ_fraisVehiculesAuto");
  m_enumMap.insert(      BJ_fraisVehiculesMoto,"BJ_fraisVehiculesMoto");
  m_enumMap.insert(      BJ_fraisDeplacementsAutres,"BJ_fraisDeplacementsAutres");
  m_enumMap.insert(      BJ_totalFraisDeplacements,"BJ_totalFraisDeplacements");
  m_enumMap.insert(      BK_chargesSocialePersonnelles,"BK_chargesSocialePersonnelles");
  m_enumMap.insert(      BL_fraisCongres,"BL_fraisCongres");
  m_enumMap.insert(      BL_fraisReceptionRepresentations,"BL_fraisReceptionRepresentations");
  m_enumMap.insert(      BL_fraisReceptionRepresentationsCongres,"BL_fraisReceptionRepresentationsCongres");
  m_enumMap.insert(      BM_bureauDocPTT,"BM_bureauDocPTT");
  m_enumMap.insert(      BM_fraisActesContentieux,"BM_fraisActesContentieux");
  m_enumMap.insert(      BM_CotisationsSyndicalesProfessionnelles,"BM_CotisationsSyndicalesProfessionnelles");
  m_enumMap.insert(      BM_autresFraisGestion,"BM_autresFraisGestion");
  m_enumMap.insert(      BM_totalFraisDiversGestion,"BM_totalFraisDiversGestion");
  m_enumMap.insert(      BN_fraisFinanciers,"BN_fraisFinanciers");
  m_enumMap.insert(      BP_pertesDiverses,"BP_pertesDiverses");
  m_enumMap.insert(      BR_TotalDepenses,"BR_TotalDepenses");
  m_enumMap.insert(      CA_excedent,"CA_excedent");
  m_enumMap.insert(      CB_plusValuesCourtTerme,"CB_plusValuesCourtTerme");
  m_enumMap.insert(      CC_DiversAReintegrer,"CC_DiversAReintegrer");
  m_enumMap.insert(      CD_beneficeSCM,"CD_beneficeSCM");
  m_enumMap.insert(      CE_totalExcedentReintegre,"CE_totalExcedentReintegre");
  m_enumMap.insert(      CF_insuffisance,"CF_insuffisance");
  m_enumMap.insert(      CG_fraisEtablissement,"CG_fraisEtablissement");
  m_enumMap.insert(      CH_dotationAmortissements,"CH_dotationAmortissements");
  m_enumMap.insert(      CJ_provisionPourDepreciationImmobilisationsNonAmortissable,"CJ_provisionPourDepreciationImmobilisationsNonAmortissable");
  m_enumMap.insert(      CK_moinsValuesCourtTerme,"CK_moinsValuesCourtTerme");
  m_enumMap.insert(      CL_diversADeduire,"CL_diversADeduire");
  m_enumMap.insert(      CM_deficitSCM,"CM_deficitSCM");
  m_enumMap.insert(      CN_totalDeficitReintegre,"CN_totalDeficitReintegre");
  m_enumMap.insert(      CP_benefice,"CP_benefice");
  m_enumMap.insert(      CR_deficit,"CR_deficit");
  m_enumMap.insert(      DA_montantImmobilisationHorsTVAdeductible,"DA_montantImmobilisationHorsTVAdeductible");
  m_enumMap.insert(      DB_montantTVAafferenteRecettes,"DB_montantTVAafferenteRecettes");
  m_enumMap.insert(      DC_montantTVAafferenteDepenses,"DC_montantTVAafferenteDepenses");
  m_enumMap.insert(      DD_montantTVAafferenteRecettes,"DD_montantTVAafferenteRecettes");
  m_enumMap.insert(      DE_montantTVAafferenteDepenses,"DE_montantTVAafferenteDepenses");
}

bool frenchTax::modifFileToNewHtml(){
  QFile fileTrois(htmlPath()+"/pageTrois.html");
  QFile fileTroisMod(htmlPath()+"/pageTroisMod.html");
  if(!fileTrois.open(QIODevice::ReadOnly)){
      qDebug() << "pageTrois not found";
      return false;
  }
    if(!fileTroisMod.open(QIODevice::ReadWrite|QIODevice::Text)){
      qDebug() << "pageTroisMod not found";
      return false;
  }
  QTextStream streamMod(&fileTroisMod);
  QTextStream streamTrois(&fileTrois);
  while(!streamTrois.atEnd()){
      QString line = streamTrois.readLine();
      //qDebug() << line;
      QMapIterator<int,QString> it(m_enumMap);
      while(it.hasNext()){
          it.next();
          if(line.contains(it.value())){
              if(it.value() != "BL_fraisReceptionRepresentations"){
                  line.replace(it.value(),m_sumsMap.value(it.key()));
              }

          }
      }
      streamMod << line+"\n";
  }
  return true;
}
