- void PromotionController::selectPromotion( QDate bDate, QDate eDate)
- {
- QSqlQueryModel qPromotion;
- m_dateBegin = bDate;
- m_dateEnd = eDate;
- QString strDate;
- if(m_resultDate )
- 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));
- else
- strDate = QString("");
- qPromotion.setQuery(QString("select * from dsm_promotion where removed = false %1 order by id").arg(strDate));
- m_promotionListModel->setQuery(qPromotion.query().lastQuery());
- m_promotionListModel->setHeaderData(0, Qt::Horizontal, QString::fromUtf8("Descrição"));
- m_promotionListModel->setHeaderData(1, Qt::Horizontal, QString::fromUtf8("Data Inicial"));
- m_promotionListModel->setHeaderData(2, Qt::Horizontal, QString::fromUtf8("Data Final"));
- m_promotionListModel->setHeaderData(3, Qt::Horizontal, QString::fromUtf8("Desconto"));
- QString strPromotionName;
- QString strDateBegin;
- QString strDateEnd;
- for(int i = 0 ; i < m_promotionListModel->rowCount() ; i++)
- {
- QString strItem;
- double discountItem = 0;
- 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()));
- strDateBegin = m_promotionListModel->record(i).value("datebegin").toDate().toString(FMT_DATE);
- strDateEnd = m_promotionListModel->record(i).value("dateend").toDate().toString(FMT_DATE);
- if(strDateBegin.contains("1960"))
- strDateBegin = "*";
- if(strDateEnd.contains("3000"))
- strDateEnd = "*";
- QString strPromotionDescription;
- strPromotionDescription = QString("%1").arg(m_promotionListModel->record(i).value("description").toString());
- for(int x = 0 ; x < m_promotionItemModel->rowCount() ; x++)
- {
- if(discountItem < m_promotionItemModel->record(x).value("discount").toDouble())
- discountItem = m_promotionItemModel->record(x).value("discount").toDouble();
- if(strPromotionDescription.isEmpty())
- strPromotionDescription = QString("%1").arg(QString::fromUtf8("Promoção %1 (%2%)").arg(i).arg(discountItem));
- 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);
- }
- strPromotionName += QString("\n%1\t%2\t%3\t%4\t%5\n")
- .arg(strPromotionDescription)
- .arg(strDateBegin)
- .arg(strDateEnd)
- .arg(DSMMoney::MoneyHumanForm3(discountItem) + "%")
- .arg(m_promotionListModel->record(i).value("id").toInt());
- strPromotionName += QString("%1\n").arg(strItem);
- }
- m_strPromotion = strPromotionName;
- }