Skip to content

Commit

Permalink
adding minimum order calculation instead of multiplication for item p…
Browse files Browse the repository at this point in the history
…rices
  • Loading branch information
apinprastya committed Jun 19, 2019
1 parent ca7a824 commit 66e15e7
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 150 deletions.
1 change: 1 addition & 0 deletions libglobal/global_setting_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace SETTING {
const QString APPLICATION_LANGUAGE = QStringLiteral("application/language");
const QString CASHIER_NAMEBASED = QStringLiteral("application/name_based");
const QString CAPITALIZE = QStringLiteral("application/capitalize");
const QString MULTIPLE_MINIMUM = QStringLiteral("application/multipleminumum");
const QString LOCALE_LANGUAGE = QStringLiteral("application/locale_language");
const QString LOCALE_COUNTRY = QStringLiteral("application/locale_country");
const QString LOCALE_USE_SIGN = QStringLiteral("application/locale_use_sign");
Expand Down
19 changes: 19 additions & 0 deletions libgui/cashier/cashiertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "util.h"
#include "message.h"
#include "global_constant.h"
#include "global_setting_const.h"
#include <cmath>
#include <QLocale>
#include <QDebug>
Expand Down Expand Up @@ -301,7 +302,25 @@ QList<int> CashierTableModel::rowOfBarcode(const QString &barcode)
QList<CashierItem *> CashierTableModel::calculatePrices(const QString &barcode, const QString &name, float count, const QString &unit, int itemFlag, const QString &note)
{
QList<CashierItem*> retVal;
bool useMinimum = Preference::getBool(SETTING::MULTIPLE_MINIMUM, false);
const QVariantList &prices = mPrices[barcode];
if(useMinimum) {
for(int i = prices.count() - 1; i >= 0; i--) {
const QVariantMap &p = prices[i].toMap();
const float &c = p["count"].toFloat();
if(i == 0 || c <= count) {
const double &price = p["price"].toDouble();
const QString &discformula = p["discount_formula"].toString();
double disc = Util::calculateDiscount(discformula, price);
CashierItem *item = new CashierItem(name, barcode, count, price, price * count, discformula, disc, (price - disc) * count, unit);
item->itemFlag = itemFlag;
item->note = note;
retVal << item;
break;
}
}
return retVal;
}
if(prices.size() == 1) {
const double &price = prices[0].toMap()["price"].toDouble();
const QString &discformula = prices[0].toMap()["discount_formula"].toString();
Expand Down
2 changes: 2 additions & 0 deletions libgui/setting/settingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void SettingWidget::setupAppliaction()

ui->groupNameBased->setChecked(Preference::getBool(SETTING::CASHIER_NAMEBASED));
ui->groupCapitalize->setChecked(Preference::getBool(SETTING::CAPITALIZE));
ui->groupUseMinimumOrder->setChecked(Preference::getBool(SETTING::MULTIPLE_MINIMUM));
}

void SettingWidget::setupLocale()
Expand Down Expand Up @@ -239,6 +240,7 @@ void SettingWidget::saveClicked()
Preference::setValue(SETTING::TAX_VALUE, ui->lineSalesTax->text());
Preference::setValue(SETTING::CASHIER_NAMEBASED, ui->groupNameBased->isChecked());
Preference::setValue(SETTING::CAPITALIZE, ui->groupCapitalize->isChecked());
Preference::setValue(SETTING::MULTIPLE_MINIMUM, ui->groupUseMinimumOrder->isChecked());
//locale
Preference::setValue(SETTING::APPLICATION_LANGUAGE, ui->comboApplicationLanguage->currentData());
Preference::setValue(SETTING::LOCALE_COUNTRY, ui->comboLocaleCounty->currentData().toInt());
Expand Down
27 changes: 26 additions & 1 deletion libgui/setting/settingwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<property name="tabBarAutoHide">
<bool>false</bool>
Expand Down Expand Up @@ -257,6 +257,31 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupUseMinimumOrder">
<property name="title">
<string>Use minimum order</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
<item>
<widget class="QLabel" name="label_40">
<property name="text">
<string>Item has multi price will use minimum order instead of multiplier</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
Expand Down
Binary file modified translation/libgui_id.qm
Binary file not shown.
Loading

0 comments on commit 66e15e7

Please sign in to comment.