Browse files

:N, Sum act values

  • Loading branch information...
1 parent befebcb commit b4ed4daa2a11a86269929db2fc1f00655d01a269 @nycholas committed Aug 9, 2010
View
12 src/modules/admin/couponform.cpp
@@ -113,6 +113,7 @@ void CouponForm::saveAction(void) {
"The coupon \"%1\" was added successfully.")).arg(
couponModel->getName()), 0);
}
+ couponModel->setId(0);
updateModels();
updateForms();
close();
@@ -134,6 +135,7 @@ void CouponForm::saveAndContinueSavingAction(void) {
"The coupon \"%1\" was added successfully.")).arg(
couponModel->getName()));
}
+ couponModel->setId(0);
updateModels();
updateForms();
}
@@ -169,7 +171,7 @@ void CouponForm::removeAction(void) {
sendStatus(
QString(qApp->tr("Successfully deleted %1 coupon.")).arg("1"),
0);
-
+ couponModel->setId(0);
updateModels();
updateForms();
close();
@@ -200,7 +202,7 @@ void CouponForm::updateWidgets(void) {
}
void CouponForm::updateModels(void) {
- couponModel = new CouponModel(0, this);
+ couponModel = new CouponModel(couponModel->getId(), this);
int begin = couponModel->begin();
int sizeAll = couponModel->count();
@@ -539,6 +541,9 @@ void CouponForm::actUpdateWidgets(void) {
}
actTableView->setTabKeyNavigation(true);
actStatusLabel->hide();
+
+ double values = ActCouponModel::sumActValue(couponModel->getId());
+ sumValuesNumberLabel->setText(QString("%1").arg(values));
}
void CouponForm::actUpdateModels(void) {
@@ -720,6 +725,9 @@ void CouponForm::actCouponUpdateWidgets(void) {
clearPushButton->setEnabled(false);
}
actCouponTableView->setTabKeyNavigation(true);
+
+ double values = ActCouponModel::sumActValue(couponModel->getId());
+ sumValuesNumberLabel->setText(QString("%1").arg(values));
}
void CouponForm::actCouponUpdateModels(void) {
View
8 src/modules/admin/couponform.h
@@ -146,10 +146,10 @@ public slots:
act_id = 0,
act_name = 1,
act_description = 2,
- act_value = 2,
- act_dateJoined = 3,
- act_dateChanged = 4,
- act_isActive = 5
+ act_value = 3,
+ act_dateJoined = 4,
+ act_dateChanged = 5,
+ act_isActive = 6
};
enum {
View
19 src/modules/admin/models/actcouponmodel.cpp
@@ -172,6 +172,25 @@ bool ActCouponModel::remove(void) {
return query.exec();
}
+double ActCouponModel::sumActValue(int idCoupon) {
+ QSqlQuery query;
+ query.prepare("SELECT SUM(ara.value) AS admin_register_coupon_value "
+ "FROM admin_register_act_coupon AS arac, "
+ "admin_register_act AS ara "
+ "WHERE arac.admin_register_coupon_id = :admin_register_coupon_id AND "
+ "ara.id = arac.admin_register_act_id");
+ query.bindValue(":admin_register_coupon_id", idCoupon);
+ if (!query.exec())
+ return 0.0;
+ qDebug() << "Query:" << query.lastQuery();
+ int valueCol = query.record().indexOf("admin_register_coupon_value");
+ double values = 0.0;
+ if (query.next()) {
+ values += query.value(valueCol).toDouble();
+ }
+ return values;
+}
+
int ActCouponModel::getId(void) {
return _id;
}
View
2 src/modules/admin/models/actcouponmodel.h
@@ -74,6 +74,8 @@ Q_OBJECT
bool status(void);
bool remove(void);
+ static double sumActValue(int idCoupon);
+
int getId(void);
void setId(int id);
int getActId(void);
View
3 src/modules/admin/models/couponmodel.cpp
@@ -47,7 +47,8 @@ void CouponModel::paginator(void) {
int CouponModel::count(void) {
QSqlQuery query;
QString f = _f.isEmpty() ? "1=1" : _f;
- query.prepare(QString("SELECT count(id) FROM admin_register_coupon WHERE %1").arg(f));
+ query.prepare(QString(
+ "SELECT count(id) FROM admin_register_coupon WHERE %1").arg(f));
if (!query.exec())
return 0;
int count = 0;

0 comments on commit b4ed4da

Please sign in to comment.