#include <QtCore>
#include <QtGui>
#include <QtSql>

#include "string.h"

#include "recettedialog.h"
extern QString g_pathabsolu;
extern QString g_nomentre;
extern QString g_guidentre;
recettedialog::recettedialog()
{
m_db1 = QSqlDatabase::database("un");
m_db2 = QSqlDatabase::database("deux");

 m_id = 0;
 m_praticien = "";
 QMessageBox *message2;
 QMessageBox *message3;

setupUi(this);
progressBar->setValue(0);
dateEdit->setDisplayFormat("dd/MM/yyyy");
dateEdit->setDate(QDate::currentDate());
setAttribute(Qt::WA_DeleteOnClose);




    Espece->setCheckable(true);
    Cheque->setCheckable(true);
    cb->setCheckable(true);
    checkBox_4->setCheckable(true);
    checkBox->setCheckable(true);
    checkBox_2->setCheckable(true);

    Espece->setAutoExclusive(true);
    Cheque->setAutoExclusive(true);
    cb->setAutoExclusive(true);
    checkBox_4->setAutoExclusive(true);
    checkBox->setAutoExclusive(true);
    checkBox_2->setAutoExclusive(false);


m_model = new QSqlQueryModel;

QSqlQuery query(m_db1);
query.exec("SELECT DossGUID FROM Verrous");
if(query.next())
{
m_guid = query.value(0).toString();
}
if((g_guidentre == "") == true){
QSqlQuery query8(m_db1);
query8.exec("SELECT * FROM Verrous");
m_nbredos = query8.size();
while(query8.next()){
QString username = query8.value(5).toString();
m_usernames << ""+username+"";
}
if (m_nbredos >1)
{
foreach (m_str,m_usernames){
int j=0;
while (m_str!= m_usernames[j]){
j++;
if (j == m_usernames.size() - 1)
message3->information(0,tr("erreur"),trUtf8("plusieurs dossiers sont ouverts, mais sur plusieurs utilisateurs; vérifiez votre enregistrement"),QMessageBox::Ok);
	break;
}
}
message2->information(0,tr("erreur"),trUtf8("vous avez plusieurs dossiers ouverts,vérifiez que l'enregistrement est le bon"),QMessageBox::Ok);
}
m_model->setQuery("SELECT FchGnrl_NomDos,FchGnrl_Prenom,FchGnrl_IDDos FROM IndexNomPrenom WHERE FchGnrl_IDDos = '"+m_guid+"'",m_db1);
m_model->setHeaderData(0, Qt::Horizontal, tr("Nom"));
m_model->setHeaderData(1, Qt::Horizontal, tr("Prenom"));
m_model->setHeaderData(2, Qt::Horizontal, tr("guid"));
}
else {
    m_model->setQuery("SELECT FchGnrl_NomDos,FchGnrl_Prenom,FchGnrl_IDDos FROM IndexNomPrenom WHERE FchGnrl_IDDos = '"+g_guidentre+"'",m_db1);
m_model->setHeaderData(0, Qt::Horizontal, tr("Nom"));
m_model->setHeaderData(1, Qt::Horizontal, tr("Prenom"));
m_model->setHeaderData(2, Qt::Horizontal, tr("guid"));
    }
    tableView->setModel(m_model);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
tableView->resizeColumnsToContents();
tableView->resizeRowsToContents();
tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
tableView->show();
//liste d'actes
comboBox->setEditable(1);
comboBox->setInsertPolicy(QComboBox::NoInsert);
QFile actes(""+g_pathabsolu+"/actes.ini");

if(!actes.open(QIODevice::ReadOnly | QIODevice::Text))
return;

QTextStream stream(&actes);
while(!stream.atEnd()){
QString ligne = stream.readLine();
ligne.replace(" ","");
m_textes << ""+ligne+"";
}

comboBox->addItems(m_textes);

//choix user preferentiel
QStringList utilisateurlist;
QFile user(""+g_pathabsolu+"/comptabilite.ini");
if(!user.open(QIODevice::ReadOnly))
return;
QTextStream point(&user);
while(!point.atEnd()){
QString utilisateur = point.readLine();
utilisateurlist << ""+utilisateur+"";}
QString utilisateur2 = utilisateurlist[24];
QStringList utilisateurnbre = utilisateur2.split("=",QString::KeepEmptyParts);
QString idprefere = utilisateurnbre.value(1);
idprefere.replace(" ","");
m_id = idprefere.toInt();

QSqlQuery query3(m_db2);
query3.exec("SELECT id_usr,login FROM utilisateurs WHERE id_drtux_usr = "+QString::number(m_id)+"");
if(query3.next())
{
//m_idusr = query3.value(0).toInt();
m_loginpref = query3.value(1).toString();
}

//choix user
comboBox_2->setEditable(1);
comboBox_2->setInsertPolicy(QComboBox::NoInsert);
m_listelogin << ""+m_loginpref+"";

QSqlQuery query4(m_db2);
query4.exec("SELECT login FROM utilisateurs");
while(query4.next()){
m_login = query4.value(0).toString();
m_listelogin << ""+m_login+"";
}
comboBox_2->addItems(m_listelogin);
QStringList valeurc;
QString valeur = utilisateurlist[27];

valeurc = valeur.split("=");

QString valeurduc = "C ="+valeurc[1]+"";
valeurduc.replace(" ","");
std::string valeurducstr = valeurduc.toStdString();
const char *valeurchar = valeurducstr.c_str();
pushButton->setText(QApplication::translate("RecetteDialog", valeurchar, 0, QApplication::UnicodeUTF8));
pushButton->setEnabled(true);
pushButton_2->setEnabled(true);
pushButton_3->setEnabled(true);

connect(pushButton,SIGNAL(pressed()),this,SLOT(enregistrece()));
connect(pushButton_2,SIGNAL(pressed()),this,SLOT(enregistreautreacte()));
connect(pushButton_3,SIGNAL(pressed()),this,SLOT(modifierrecettes()));
connect(pushButton_5,SIGNAL(pressed()),this,SLOT(fermer()));
pushButton_4->hide();
}
/////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//fonction d'enregistrement du C
void recettedialog::enregistrece()
{
    if((checkBox_2->isChecked())==false){
    pushButton->setEnabled(false);}
QString userchoisi = comboBox_2->currentText();
//qDebug() << ""+userchoisi+"";
QSqlQuery query1(m_db2);
query1.exec("SELECT id_usr FROM utilisateurs WHERE login = '"+userchoisi+"'");
if(query1.next())
{
m_idusr = query1.value(0).toInt();
}
//qDebug() << ""+QString::number(m_idusr)+"";
//db1 = QSqlDatabase::database("un");
//db2 = QSqlDatabase::database("deux");
QSqlQueryModel *modele = new QSqlQueryModel;
modele->setQuery("SELECT * FROM honoraires",m_db2);
int count = modele->rowCount();
modele->clear();


m_model = new QSqlQueryModel;
m_model->setQuery("SELECT FchGnrl_NomDos,FchGnrl_Prenom,FchGnrl_IDDos FROM IndexNomPrenom WHERE FchGnrl_IDDos = '"+m_guid+"'",m_db1);
QStringList utilisateurlist;
QFile user(""+g_pathabsolu+"/comptabilite.ini");
if(!user.open(QIODevice::ReadOnly))
return;
QTextStream point(&user);
while(!point.atEnd()){
QString utilisateur = point.readLine();
utilisateurlist << ""+utilisateur+"";}
QString ligneacte = utilisateurlist[27];
QStringList listeactesplit = ligneacte.split("=");
QString acteprefere = listeactesplit[1];
acteprefere.replace(" ","");
double acte = acteprefere.toDouble();
QDate daterecup = dateEdit->date();
m_date = daterecup.toString("yyyy-MM-dd");
//qDebug() << "OK2";
QString prat = comboBox_2->currentText();

QSqlQuery query5(m_db2);
query5.exec("SELECT nom_usr FROM utilisateurs WHERE login = '"+prat+"'");
if (query5.next()) {
m_praticien = query5.value(0).toString();
}

//qDebug() << "OK3";
//QModelIndex index = tableView->QAbstractItemView::currentIndex();
//int row = index.row();
//qDebug() << "OK4";

QString nom = m_model->data(m_model->index(0,0,QModelIndex())).toString();
QString prenom = m_model->data(m_model->index(0,1,QModelIndex())).toString();
//qDebug() << "OK5";
m_nomprenom = nom+","+prenom;
m_guiddrtux = m_model->data(m_model->index(0,2,QModelIndex())).toString();

QSqlQuery query8(m_db1);
query8.exec("SELECT ID_PrimKey FROM Personnes WHERE Login = '"+prat+"'");
if (query8.next()){
m_ida = query8.value(0).toInt();}
//----------------si récupération du guid dans medintux--------------------------
if((g_guidentre == "")==false){
m_guiddrtux = g_guidentre;
QSqlQuery query(m_db1);
query.exec("SELECT FchGnrl_NomDos,FchGnrl_Prenom FROM IndexNomPrenom WHERE FchGnrl_IDDos = '"+g_guidentre+"'");
if(query.next()){
QString nom = query.value(0).toString();
QString prenom = query.value(1).toString();
m_nomprenom = nom+","+prenom;
}
}
if(m_nomprenom.contains("'")){
    m_nomprenom.replace("'","''");
    }
QMessageBox *message;

QSqlQuery query2(m_db2);
QString C = "C//Consultation//N//22//0//0//0//0//0|";
if(Espece->isChecked()==true){
query2.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+C+"',NULL,"+QString::number(acte)+",0,0,0,0,0)");
enregistrement(query2);}
else if(Cheque->isChecked()){
	query2.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+C+"',NULL,0,"+QString::number(acte)+",0,0,0,0)");
enregistrement(query2);}
else if(cb->isChecked()){
	query2.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+C+"',NULL,0,0,"+QString::number(acte)+",0,0,0)");
enregistrement(query2);}
else if(checkBox->isChecked()){
query2.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+C+"',NULL,0,0,0,"+QString::number(acte)+",0,0)");
enregistrement(query2);}
else if(checkBox_4->isChecked()){
	query2.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+C+"',NULL,0,0,0,0,0,"+QString::number(acte)+")");
enregistrement(query2);}
else
	 message->information(0,tr("erreur"),trUtf8("vous avez oublié de choisir le type de paiement"),QMessageBox::Ok);

modele->setQuery("SELECT * FROM honoraires",m_db2);

int newcount = modele->rowCount();
modele->clear();
//QProgressBar *progressbar = new QProgressBar;
if(newcount == count+1)
{
QString labeltexte = "la somme : "+m_executedquery+" a \351t\351 enregistr\351e.";

label_7->setText(""+labeltexte+"");
progressBar->setRange(0,100);
progressBar->show();
QTimeLine *time = new QTimeLine;
time->setFrameRange(0,100);
connect(time, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
emit time->start();
}

else
{QMessageBox::warning(0,tr("erreur"),tr("erreur insertion recette"),QMessageBox::Ok);}
//condition sur la checkBox "plus acte"
//garde ouvert le widget si cette checkBox est cochée puis décoche toutes les checkBox pour le tour suivant
//permet de ne pas décocher à la main

if(checkBox_2->isChecked() == false){
QTimer::singleShot(1000,this,SLOT(fermer()));
}
//remise à zero des checkBox
else
{
checkBox_2->setCheckState(Qt::Unchecked);
if(Espece->isChecked())
    {Espece->setCheckState(Qt::Unchecked);}
else if(Cheque->isChecked())
    {Cheque->setCheckState(Qt::Unchecked);}
else if(cb->isChecked())
    {cb->setCheckState(Qt::Unchecked);}
else if(checkBox_4->isChecked())
    {checkBox_4->setCheckState(Qt::Unchecked);}
else if(checkBox->isChecked())
    {checkBox->setCheckState(Qt::Unchecked);}
else {QMessageBox::warning(0,tr("erreur"),trUtf8("aucune case n'est cochée..."),QMessageBox::Ok);}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//fonction d'enregistrement des autres actes/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
void recettedialog::enregistreautreacte()
{
    if((checkBox_2->isChecked())== false){
    pushButton_2->setEnabled(false);}
QString userchoisi = comboBox_2->currentText();
//qDebug() << ""+userchoisi+"";
QSqlQuery query1(m_db2);
query1.exec("SELECT id_usr FROM utilisateurs WHERE login = '"+userchoisi+"'");
if(query1.next())
{
m_idusr = query1.value(0).toInt();
}
//qDebug() << ""+QString::number(m_idusr)+"";
//db1 = QSqlDatabase::database("un");
//db2 = QSqlDatabase::database("deux");
QSqlQueryModel *modele2 = new QSqlQueryModel;
modele2->setQuery("SELECT * FROM honoraires",m_db2);
int count = modele2->rowCount();
modele2->clear();
///////////somme libre/////////////////////////////////
m_entreelibre = lineEdit->text();
m_sommeentree = lineEdit_2->text().toDouble();

m_model = new QSqlQueryModel;
m_model->setQuery("SELECT FchGnrl_NomDos,FchGnrl_Prenom,FchGnrl_IDDos FROM IndexNomPrenom WHERE FchGnrl_IDDos = '"+m_guid+"'",m_db1);
QString actestring = comboBox->currentText();
//qDebug() << "OK";
QStringList listeacte = actestring.split("=",QString::KeepEmptyParts);
double acte = listeacte.value(1).toDouble();
QString actea = listeacte.value(0);
m_acteautre = actea+"//Autre//N//00//0//0//0//0//0|";
QString actelibre = "libre//Autre//N//00//0//0//0//0//0|";
//qDebug() << "OK1";
QDate daterecup = dateEdit->date();
m_date = daterecup.toString("yyyy-MM-dd");

QString prat = comboBox_2->currentText();
QSqlQuery query7(m_db2);
query7.exec("SELECT nom_usr FROM utilisateurs WHERE login = '"+prat+"'");
if (query7.next()) {
m_praticien = query7.value(0).toString();
}

QString nom = m_model->data(m_model->index(0,0,QModelIndex())).toString();
QString prenom = m_model->data(m_model->index(0,1,QModelIndex())).toString();
//qDebug() << "OK5";
m_nomprenom = nom+","+prenom;
m_guiddrtux = m_model->data(m_model->index(0,2,QModelIndex())).toString();

QSqlQuery query9(m_db1);
query9.exec("SELECT ID_PrimKey FROM Personnes WHERE Login = '"+prat+"'");
if (query9.next()){
m_ida = query9.value(0).toInt();}

QMessageBox *message;
//---------------si récupération du guid dans medintux----------------------------------
if((g_guidentre == "")==false){
m_guiddrtux = g_guidentre;
QSqlQuery query(m_db1);
query.exec("SELECT FchGnrl_NomDos,FchGnrl_Prenom FROM IndexNomPrenom WHERE FchGnrl_IDDos = '"+g_guidentre+"'");
if(query.next()){
QString nom = query.value(0).toString();
QString prenom = query.value(1).toString();
m_nomprenom = nom+","+prenom;
}
}
if(m_nomprenom.contains("'")){
    m_nomprenom.replace("'","''");
    }
if(Espece->isChecked()==true){
if(m_entreelibre == ""){
QSqlQuery query6(m_db2);
   if(m_sommeentree==0)//alors on choisit dans la combobox
{
query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+m_acteautre+"',NULL,'"+QString::number(acte)+"',0,0,0,0,0)");
enregistrement(query6);
}
else{//ou dans la somme libre, ce sera intitulé "libre"
query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,'"+QString::number(m_sommeentree)+"',0,0,0,0,0)");
enregistrement(query6);
}
}
   else {QSqlQuery query6(m_db2);//dénomination libre et somme libre
message_libre();
query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_entreelibre+"',NULL,'"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,'"+QString::number(m_sommeentree)+"',0,0,0,0,0);");
enregistrement(query6);
}
 }
//fin de espece
else if(Cheque->isChecked()){
if(m_entreelibre==""){
QSqlQuery query6(m_db2);
   if(m_sommeentree==0){
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+m_acteautre+"',NULL,0,'"+QString::number(acte)+"',0,0,0,0)");
enregistrement(query6);
}
   else{
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,0,'"+QString::number(m_sommeentree)+"',0,0,0,0)");
enregistrement(query6);
}
}
else {QSqlQuery query6(m_db2);
message_libre();
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_entreelibre+"',NULL,'"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,0,'"+QString::number(m_sommeentree)+"',0,0,0,0)");
enregistrement(query6);
}
}
//fin de cheque
else if(cb->isChecked()){
if(m_entreelibre == ""){
QSqlQuery query6(m_db2);
   if(m_sommeentree==0){
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+m_acteautre+"',NULL,0,0,'"+QString::number(acte)+"',0,0,0)");
enregistrement(query6);
}
   else{
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,0,0,'"+QString::number(m_sommeentree)+"',0,0,0)");
enregistrement(query6);
}
}
else {QSqlQuery query6(m_db2);
message_libre();
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_entreelibre+"',NULL,'"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,0,0,'"+QString::number(m_sommeentree)+"',0,0,0)");
enregistrement(query6);
}
}
//fin de carte bancaire

else if(checkBox->isChecked()){
if(m_entreelibre == ""){
QSqlQuery query6(m_db2);
   if(m_sommeentree == 0){
query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+m_acteautre+"',NULL,0,0,0,'"+QString::number(acte)+"',0,0)");
enregistrement(query6);
}
   else{
query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,0,0,0,'"+QString::number(m_sommeentree)+"',0,0)");
enregistrement(query6);
}
}
else {QSqlQuery query6(m_db2);
message_libre();
query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_entreelibre+"',NULL,'"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,0,0,0,'"+QString::number(m_sommeentree)+"',0,0)");
enregistrement(query6);
}
}
//fin de dispense d'avance des frais
else if(checkBox_4->isChecked()){
if(m_entreelibre == ""){
QSqlQuery query6(m_db2);
   if(m_sommeentree == 0){
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+m_acteautre+"',NULL,0,0,0,0,0,'"+QString::number(acte)+"')");
enregistrement(query6);
}
   else{
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_nomprenom+"','"+m_guiddrtux+"','"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,0,0,0,0,0,'"+QString::number(m_sommeentree)+"'')");
enregistrement(query6);
}
}
else {QSqlQuery query6(m_db2);
message_libre();
	query6.exec("INSERT INTO honoraires (id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du)"
"VALUES ("+QString::number(m_idusr)+","+QString::number(m_ida)+",'"+m_entreelibre+"',NULL,'"+m_praticien+"','"+m_date+"','"+actelibre+"',NULL,0,0,0,0,0,'"+QString::number(m_sommeentree)+"')");
enregistrement(query6);
}
}
//fin de dus
else
	 message->information(0,tr("erreur"),trUtf8("vous avez oublié de choisir le type de paiement"),QMessageBox::Ok);

modele2->setQuery("SELECT * FROM honoraires",m_db2);

int newcount = modele2->rowCount();
modele2->clear();

QMessageBox *message2 = new QMessageBox;
//QProgressBar *progressbar2 = new QProgressBar;
if(newcount == count+1)
{
QString labeltexte = "la somme : "+m_executedquery+" a \351t\351 enregistr\351e.";

label_7->setText(""+labeltexte+"");
progressBar->setRange(0,100);
progressBar->show();
QTimeLine *time = new QTimeLine;
time->setFrameRange(0,100);
connect(time, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
emit time->start();
}

else
{message2->warning(0,tr("erreur"),tr("erreur insertion recette"),QMessageBox::Ok);}


if(checkBox_2->isChecked() == false){
QTimer::singleShot(1000,this,SLOT(fermer()));}
//remise à zero des checkBox
else
{
checkBox_2->setCheckState(Qt::Unchecked);
if(Espece->isChecked())
    {Espece->setCheckState(Qt::Unchecked);}
else if(Cheque->isChecked())
    {Cheque->setCheckState(Qt::Unchecked);}
else if(cb->isChecked())
    {cb->setCheckState(Qt::Unchecked);}
else if(checkBox_4->isChecked())
    {checkBox_4->setCheckState(Qt::Unchecked);}
else if(checkBox->isChecked())
    {checkBox->setCheckState(Qt::Unchecked);}
else {QMessageBox::warning(0,tr("erreur"),trUtf8("aucune case n'est cochée..."),QMessageBox::Ok);}
}

}

QString recettedialog::enregistrement(QSqlQuery &namequery){
QString result;
QString result1;
QString result2;
QString result3;
QString result4;
QString result5;
QString result6;
int id = namequery.lastInsertId().toInt();

QSqlQuery query(m_db2);
query.exec("SELECT id_hono,id_usr,id_drtux_usr,patient,GUID,praticien,date,acte,remarque,esp,chq,cb,daf,autre,du,valide,tracabilite FROM honoraires WHERE id_hono = "+QString::number(id)+"");
while(query.next()){
result1 = query.value(9).toString();
result2 = query.value(10).toString();
result3 = query.value(11).toString();
result4 = query.value(12).toString();
result5 = query.value(13).toString();
result6 = query.value(14).toString();
result = "-"+result1 + "-"+result2 + "-"+result3 + "-"+result4+ "-"+result5 + "-"+result6;
}
result.replace("-0","-");
result.replace("-","");
m_executedquery = result;

//result.replace("0","");

return m_executedquery;
}

void recettedialog::fermer()
{
emit QApplication::closeAllWindows();
}

void recettedialog::fermer2()
{
emit QApplication::closeAllWindows();
}

void recettedialog::modifierrecettes()
{
    pushButton_3->setEnabled(false);
m_modifrecette = new modifierrecette;
m_modifrecette->show();
}

void recettedialog::on_lineEdit_textChanged(){
label_5->setText("<html><body><font size = 6 color = ""red"">somme libre ici</font></body></html>");
label_6->setText("<html><body><font size = 3 color = ""red"">enregistrez par 'autres actes'</font></body></html>");
}

void recettedialog::message_libre(){
QMessageBox::information(0,tr("info"),trUtf8("l'intitulé libre prime sur le nom et le prénom"),QMessageBox::Ok);
}

