Your warranties manager
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

produititem.cpp 5.8 KiB

vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 9 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include "produititem.h"
  2. #include "ui_produititem.h"
  3. #include "mainwindow.h"
  4. #include <QMessageBox>
  5. #include <QBuffer>
  6. #include <manufacturersmanager.h>
  7. QDataStream &operator <<(QDataStream &out, const ProduitInfo &prod)
  8. {
  9. out << prod.nomProduit << prod.dateAchat << prod.dateFinGarantie << prod.image << prod.indexMagasin << prod.enSAV << prod.factures << prod.garanties;
  10. return out;
  11. }
  12. QDataStream &operator >>(QDataStream &in, ProduitInfo &prod)
  13. {
  14. in >> prod.nomProduit >> prod.dateAchat >> prod.dateFinGarantie >> prod.image >> prod.indexMagasin >> prod.enSAV >> prod.factures >> prod.garanties;
  15. return in;
  16. }
  17. ProduitItem::ProduitItem(QWidget *parent, QString nomProduit, QDate dateAchat, QDate dateFinGarantie, QPixmap image, int magasin,
  18. bool enSAV, QHash<QString, QByteArray> factures, QHash<QString, QByteArray> garanties) :
  19. QWidget(parent),
  20. ui(new Ui::ProduitItem)
  21. {
  22. ui->setupUi(this);
  23. this->nomProduit = nomProduit;
  24. this->dateAchat = dateAchat;
  25. this->dateFinGarantie = dateFinGarantie;
  26. this->indexMagasin = magasin;
  27. this->enSAV = enSAV;
  28. this->factures = factures;
  29. this->garanties = garanties;
  30. ui->nomProduit->setText("<h1>"+nomProduit+"</h1>");
  31. updateDescription();
  32. this->image = image;
  33. this->image.scaled(QSize(128, 128), Qt::KeepAspectRatio);
  34. ui->image->setPixmap(this->image);
  35. ui->btnMoreInfo->setToolTip(tr("Ouvre une fenêtre contenant toutes les informations\nsur votre %1.", "%1 represents the name of the product, as given in the Name field.").arg(nomProduit));
  36. }
  37. void ProduitItem::on_btnMoreInfo_clicked(bool deleteOnCancel)
  38. {
  39. InfosProduitDialog *winInfoProd = new InfosProduitDialog(this, this->parentWidget(), nomProduit, dateAchat, dateFinGarantie, image, indexMagasin, enSAV, factures, garanties);
  40. winInfoProd->setModal(true);
  41. winInfoProd->show();
  42. // Si on annule et que deleteOnCancel est vrai, le signal deleteAsked() sera déclenché.
  43. if(deleteOnCancel)
  44. connect(winInfoProd, SIGNAL(rejected()), SLOT(winInfoProdCanceled()));
  45. }
  46. void ProduitItem::winInfoProdCanceled()
  47. {
  48. emit deleteAsked();
  49. }
  50. // Accesseurs
  51. QPixmap ProduitItem::getImage()
  52. {
  53. return this->image;
  54. }
  55. void ProduitItem::setNomProduit(QString nomProduit)
  56. {
  57. this->nomProduit = nomProduit;
  58. ui->nomProduit->setText("<h1>"+nomProduit+"</h1>");
  59. }
  60. void ProduitItem::setDateAchat(QDate dateAchat)
  61. {
  62. this->dateAchat = dateAchat;
  63. updateDescription();
  64. }
  65. void ProduitItem::setDateFinGarantie(QDate dateFinGarantie)
  66. {
  67. this->dateFinGarantie = dateFinGarantie;
  68. updateDescription();
  69. }
  70. void ProduitItem::setImage(QPixmap image)
  71. {
  72. this->image = image;
  73. ui->image->setPixmap(image);
  74. }
  75. int ProduitItem::getMagasin()
  76. {
  77. return this->indexMagasin;
  78. }
  79. void ProduitItem::setMagasin(int index)
  80. {
  81. this->indexMagasin = index;
  82. }
  83. void ProduitItem::setEnSAV(bool y)
  84. {
  85. this->enSAV = y;
  86. updateDescription();
  87. }
  88. void ProduitItem::setFactures(QHash<QString, QByteArray> factures)
  89. {
  90. this->factures = factures;
  91. }
  92. void ProduitItem::setGaranties(QHash<QString, QByteArray> garanties)
  93. {
  94. this->garanties = garanties;
  95. }
  96. // Permet de mettre à jour le petit texte en-dessous du nom du produit
  97. void ProduitItem::updateDescription()
  98. {
  99. if(dateFinGarantie != QDate(1970, 1, 1))
  100. {
  101. if(QDate::currentDate() < dateFinGarantie)
  102. descriptionListe = tr("Acheté le %1, fin de la garantie le %2", "%1 and %2 are dates").arg(dateAchat.toString(Qt::LocaleDate), dateFinGarantie.toString(Qt::LocaleDate));
  103. else
  104. descriptionListe = tr("Acheté le %1, garantie expirée", "%1 is a date").arg(dateAchat.toString(Qt::LocaleDate));
  105. }
  106. else
  107. descriptionListe = tr("Acheté le %1, garantie à vie", "%1 is a date").arg(dateAchat.toString(Qt::LocaleDate));
  108. if(this->enSAV)
  109. descriptionListe += tr("\nParti en SAV");
  110. ui->infosProduit->setText(descriptionListe);
  111. }
  112. void ProduitItem::openDialog(bool deleteOnCancel)
  113. {
  114. on_btnMoreInfo_clicked(deleteOnCancel);
  115. }
  116. // Pour la sérialisation
  117. ProduitInfo ProduitItem::getProduitInfo()
  118. {
  119. ProduitInfo i;
  120. i.nomProduit = this->nomProduit;
  121. i.dateAchat = this->dateAchat;
  122. i.dateFinGarantie = this->dateFinGarantie;
  123. i.image = this->image;
  124. i.indexMagasin = this->indexMagasin;
  125. i.enSAV = this->enSAV;
  126. i.factures = this->factures;
  127. i.garanties = this->garanties;
  128. return i;
  129. }
  130. QJsonObject ProduitItem::getJSON()
  131. {
  132. // Convert image to base64
  133. QByteArray imageByteArray;
  134. QBuffer buffer(&imageByteArray);
  135. buffer.open(QIODevice::WriteOnly);
  136. this->image.toImage().save(&buffer, "JPEG");
  137. QString imageBase64 = imageByteArray.toBase64();
  138. // Fetch the shop's name
  139. ManufacturersManager manufacturersManager;
  140. QList<QString> manufacturers = manufacturersManager.getManufacturers();
  141. QString shopName = manufacturers[this->indexMagasin];
  142. // Attached documents
  143. QJsonObject jsonAttachedDocuments;
  144. for(int i = 0; i < factures.keys().length(); i++)
  145. {
  146. QString key = factures.keys()[i];
  147. QByteArray facture = factures[key];
  148. jsonAttachedDocuments["fac-" + key] = (QString) facture.toBase64();
  149. }
  150. for(int i = 0; i < garanties.keys().length(); i++)
  151. {
  152. QString key = garanties.keys()[i];
  153. QByteArray garantie = garanties[key];
  154. jsonAttachedDocuments["warr-" + key] = (QString) garantie.toBase64();
  155. }
  156. QJsonObject jsonObject;
  157. jsonObject["name"] = this->nomProduit;
  158. jsonObject["boughtOn"] = (int) ((QDateTime) this->dateAchat).toTime_t();
  159. jsonObject["warrantyEnd"] = (int) ((QDateTime) this->dateFinGarantie).toTime_t();
  160. jsonObject["image"] = imageBase64;
  161. jsonObject["shop"] = shopName;
  162. jsonObject["returnedToManufacturer"] = this->enSAV;
  163. jsonObject["attachedDocuments"] = jsonAttachedDocuments;
  164. return jsonObject;
  165. }
  166. ProduitItem::~ProduitItem()
  167. {
  168. delete ui;
  169. }