Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 3.14 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void PromotionController::selectPromotion( QDate bDate, QDate eDate)
  2. {
  3.     QSqlQueryModel qPromotion;
  4.  
  5.     m_dateBegin = bDate;
  6.     m_dateEnd = eDate;
  7.  
  8.     QString strDate;
  9.  
  10.     if(m_resultDate )
  11.         strDate = QString(" and datebegin between '%1' and '%2' and dateend between '%1' and '%2' ").arg(m_dateBegin.toString(FMT_DATE_DB)).arg(m_dateEnd.toString(FMT_DATE_DB));
  12.     else
  13.         strDate = QString("");
  14.  
  15.     qPromotion.setQuery(QString("select * from dsm_promotion where removed = false %1 order by id").arg(strDate));
  16.  
  17.     m_promotionListModel->setQuery(qPromotion.query().lastQuery());
  18.     m_promotionListModel->setHeaderData(0, Qt::Horizontal, QString::fromUtf8("Descrição"));
  19.     m_promotionListModel->setHeaderData(1, Qt::Horizontal, QString::fromUtf8("Data Inicial"));
  20.     m_promotionListModel->setHeaderData(2, Qt::Horizontal, QString::fromUtf8("Data Final"));
  21.     m_promotionListModel->setHeaderData(3, Qt::Horizontal, QString::fromUtf8("Desconto"));
  22.  
  23.     QString strPromotionName;
  24.     QString strDateBegin;
  25.     QString strDateEnd;
  26.  
  27.     for(int i = 0 ; i < m_promotionListModel->rowCount() ; i++)
  28.     {
  29.         QString strItem;
  30.         double discountItem = 0;
  31.  
  32.         m_promotionItemModel->setQuery(QString("select * from dsm_promotion_item where promotionid = %1 and removed = false order by id").arg(m_promotionListModel->record(i).value("id").toInt()));
  33.  
  34.         strDateBegin = m_promotionListModel->record(i).value("datebegin").toDate().toString(FMT_DATE);
  35.         strDateEnd = m_promotionListModel->record(i).value("dateend").toDate().toString(FMT_DATE);
  36.  
  37.         if(strDateBegin.contains("1960"))
  38.             strDateBegin = "*";
  39.  
  40.         if(strDateEnd.contains("3000"))
  41.             strDateEnd = "*";
  42.  
  43.  
  44.         QString strPromotionDescription;
  45.  
  46.         strPromotionDescription = QString("%1").arg(m_promotionListModel->record(i).value("description").toString());
  47.  
  48.         for(int x = 0 ; x < m_promotionItemModel->rowCount() ; x++)
  49.         {
  50.             if(discountItem < m_promotionItemModel->record(x).value("discount").toDouble())
  51.                 discountItem = m_promotionItemModel->record(x).value("discount").toDouble();
  52.  
  53.             if(strPromotionDescription.isEmpty())
  54.                 strPromotionDescription = QString("%1").arg(QString::fromUtf8("Promoção %1 (%2%)").arg(i).arg(discountItem));
  55.  
  56.             strItem += QString("    %1\t%2\t%3\t%4\t%5\n").arg(getDescriptionDestiny(m_promotionItemModel->record(x).value("destinyid").toInt(),m_promotionItemModel->record(x).value("type").toInt(),m_promotionItemModel->record(x).value("loteid").toInt(),m_promotionItemModel->record(x).value("loteselected").toBool())).arg(" ").arg(" ").arg(" ").arg(strPromotionDescription);
  57.         }
  58.  
  59.         strPromotionName += QString("\n%1\t%2\t%3\t%4\t%5\n")
  60.                 .arg(strPromotionDescription)
  61.                 .arg(strDateBegin)
  62.                 .arg(strDateEnd)
  63.                 .arg(DSMMoney::MoneyHumanForm3(discountItem) + "%")
  64.                 .arg(m_promotionListModel->record(i).value("id").toInt());
  65.  
  66.         strPromotionName += QString("%1\n").arg(strItem);
  67.     }
  68.  
  69.     m_strPromotion = strPromotionName;
  70. }