1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
| #include <iostream>
#include <cstdlib>
#include <string>
#include <locale>
#include <iterator>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <ctime>
using namespace std;
int rec_countA = 0; //compteur adresses clients
int rec_countB = 0; //compteur donnees financieres clients
int affichageDate(string dateFormat);
struct Company // Structure stockant les informations postales du client
{
string societe;
int compta;
int site;
string groupe;
string fjuri;
string nom;
string enseigne;
string adresse1;
string adresse2;
string cpost;
string ville;
string tel;
string fax;
string email;
string siret;
};
vector <Company> companies; // Un tableau dynamique pour stocker les clients
struct Balanceagee // Structure stockant les informations financieres du client
{
string societe;
int compta;
int site;
string piece;
string commande;
string dateEcriture;
string dateEcheance;
float montant;
string commercial;
float soldeDue;
int dateEcrit()
{
affichageDate(dateEcriture);
return 0;
};
int dateEch ()
{
affichageDate(dateEcheance);
return 0;
};
};
vector < Balanceagee > balClient; //Un tableau dynamique pour stocker les pieces comptables
bool fonctionTriAdresseClient(const Company& a,const Company& b) // Tri des adresses pas numero de site
{
return a.site < b.site;
}
bool fonctionTriBalanceAgeeClient(const Balanceagee & a,const Balanceagee & b) //Tri des factures pas numero de site
{
return a.site < b.site;
}
istream & operator >> (istream & company, Company & companies) //Flux fichier adresse envoye dans la structure Company
{
string compta;
string site ;
// Parsage du flux par un separateur et envoi des données dans les champs de la structure
getline(company, companies.societe, ';');
getline(company, compta, ';');
istringstream incompta(compta); // Transpytage du string en int
incompta >> companies.compta;
getline(company, site, ';');
istringstream insite(site); // Transpytage du string en int
insite >> companies.site;
getline(company, companies.groupe, ';');
getline(company, companies.fjuri, ';');
getline(company, companies.nom, ';');
getline(company, companies.enseigne, ';');
getline(company, companies.adresse1, ';');
getline(company, companies.adresse2, ';');
getline(company, companies.cpost, ';');
getline(company, companies.ville, ';');
getline(company, companies.tel, ';');
getline(company, companies.fax, ';');
getline(company, companies.email, ';');
getline(company, companies.siret);
return company;
}
istream & operator >> (istream & balanceAgeeClient, Balanceagee & balClient) /*Flux fichier Balance agee envoye dans la structure Balanceagee */
{
string compta;
string site;
string piece;
string commande;
string montant;
string soldeDue;
// Parsage du flux par un separateur et envoi des données dans les champs de la structure
getline(balanceAgeeClient, balClient.societe, ';');
getline(balanceAgeeClient, compta, ';');
istringstream incompta(compta); // Transpytage du string en int
incompta >> balClient.compta;
getline(balanceAgeeClient, site, ';');
istringstream insite(site); // Transpytage du string en int
insite >> balClient.site;
getline(balanceAgeeClient, balClient.piece, ';');
getline(balanceAgeeClient, balClient.commande, ';');
getline(balanceAgeeClient, balClient.dateEcriture, ';');
getline(balanceAgeeClient, balClient.dateEcheance, ';');
getline(balanceAgeeClient, montant, ';');
replace(montant.begin(),montant.end(),',','.'); //Remplace le ',' en '.'
montant.erase(remove(montant.begin(), montant.end(), ' '), montant.end()); //supprime les espaces
istringstream inmontant (montant); // Transpytage du string en float
inmontant >> balClient.montant ;
getline(balanceAgeeClient, balClient.commercial, ';');
getline(balanceAgeeClient, soldeDue, ';');
replace(soldeDue.begin(),soldeDue.end(),',','.'); //Remplace le ',' en '.'
soldeDue.erase(remove(soldeDue.begin(), soldeDue.end(), ' '), soldeDue.end()); //supprime les espaces
istringstream insoldeDue (soldeDue); // Transpytage du string en float
insoldeDue >> balClient.soldeDue ;
return balanceAgeeClient;
}
ostream & operator << (ostream & flux, Company const & companies) // Affichage des donnees de la structure Company
{
flux
<< companies.societe << " "
<< companies.site << " "
<< companies.compta << " "
<< companies.groupe << " "
<< companies.fjuri << " "
<< companies.nom << " "
<< companies.enseigne << " "
<< companies.adresse1 << " "
<< companies.adresse2 << " "
<< companies.cpost << " "
<< companies.ville << " "
<< companies.tel << " "
<< companies.fax << " "
<< companies.email << " "
<< companies.siret ;
return flux;
}
ostream & operator << (ostream & fluxFinancier, Balanceagee const & balClient) // Affichage des donnees de la structure Balanceagee
{
fluxFinancier
<< balClient.societe << " "
<< balClient.compta << " "
<< balClient.site << " "
<< balClient.piece << " "
<< balClient.commande << " "
<< balClient.dateEcriture << " "
<< balClient.dateEcheance << " "
<< balClient.montant << " "
<< balClient.commercial << " "
<< balClient.soldeDue ;
return fluxFinancier;
}
void traitementsDonneesClients() /*Lecture du fichier csv et envoie des informations dans une structure */
{
string ligne; //Une variable pour stocker les lignes lues
ifstream fichierAdresses ("Adresseclients.csv");
if(fichierAdresses)
{
//L'ouverture s'est bien passée, on peut donc lire
while(getline(fichierAdresses, ligne)) //Tant qu'on n'est pas à la fin, on lit
{
Company company;
istringstream iss(ligne); // Transpytage du flux ligne pour stocker dans la stucture
iss >> company;
companies.push_back(company);
// Tri des adresses pas numero de site
sort(companies.begin(), companies.end(), fonctionTriAdresseClient);
rec_countA++; //compteur
}
}
// Tant quil y a des donnees dans le tableau on les affiche
else
{
cout << "ERREUR: Impossible d'ouvrir le fichier des adresses clients." << endl;
}
fichierAdresses.close(); //On referme le fichier
//On ne peut plus écrire dans le fichier à partir d'ici
string lignef; //Une variable pour stocker les lignes lues
ifstream fichierBalAgeeClient ("balanceagee.csv");
if(fichierBalAgeeClient)
{
//L'ouverture s'est bien passée, on peut donc lire
while(getline(fichierBalAgeeClient, lignef)) //Tant qu'on n'est pas à la fin, on lit
{
Balanceagee balanceAgeeClient;
istringstream iss(lignef); // Transpytage du flux lignef pour stocker dans la stucture
iss >> balanceAgeeClient;
balClient.push_back(balanceAgeeClient);
//Tri des factures pas numero de site
sort(balClient.begin(), balClient.end(),fonctionTriBalanceAgeeClient);
rec_countB++; //compteur
}
}
// Tant quil y a des donnees dans le tableau on les affiche
else
{
cout << "ERREUR: Impossible d'ouvrir le fichier de la Balance agee." << endl;
}
fichierBalAgeeClient.close(); //On referme le fichier
//On ne peut plus écrire dans le fichier à partir d'ici
}
/*void afficherDonneesClient()
{
int nCompta;
cin >> nCompta;
for(int i = 0;i < rec_countA;i++)
{
while(companies[i].compta == nCompta)
{
cout << balClient[i];
if(i == companies.size())
{
cout << "Il n'existe pas de fiche clients sous ce numero" << endl;
}
else
{
for(int j = 0;j < rec_countB;j++)
{
while(balClient[j].compta == nCompta)
{
cout << companies[i];
}
if(i == balClient.size())
{
cout << "Il n'existe pas de donnee financiere pour ce client" << endl;
}
}
}
}
}
}*/
bool affichageDate(string& dateFormat, int& d, int& m, int& y)
//fonction attend la chaîne en format jj / mm / aaaa:
{
struct tm date;
char format[10];
istringstream iss(dateFormat); // Transpytage du flux dateFormat pour stocker dans le flux iss
char delimiter = '/';
if (iss >> d >> delimiter >> m >> delimiter >> y)
{
date.tm_mday = d;
date.tm_mon = m - 1;
date.tm_year = y - 1900;
date.tm_isdst = -1;
date.tm_hour=0;
date.tm_min=0;
date.tm_sec=0;
// normaliser:
time_t time = mktime(&date);
const struct tm *norm = localtime(&time);
/* lactuelle date devrait être :
m = norm->tm_mon + 1;
d = norm->tm_mday;
y = norm->tm_year;
29/02/2013 deviendrait 01/03/2013*/
// Valider si les données normalisées est toujours le même :
return (norm->tm_mday == d &&
norm->tm_mon == m - 1 &&
norm->tm_year == y - 1900);
}
else
{
std::cout << "La date nest pas correcte" << endl;
}
strftime(format, 10, " %d/%m/%Y ", &date);
cout << format;
return 0;
}
void affichageDonneesClients()
{
int n;
for (n = 1; n < rec_countA; n++)
{
cout << companies[n] << endl;
}
int m;
for (m = 1; m < rec_countB; m++)
{
cout << balClient[m] << endl;
}
}
int main()
{
/*afficherDonneesClient();*/
traitementsDonneesClients();
affichageDonneesClients();
return 0;
} |
Partager