1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*
* This file is part of the xTuple ERP: PostBooks Edition, a free and
* open source Enterprise Resource Planning software suite,
* Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
* It is licensed to you under the Common Public Attribution License
* version 1.0, the full text of which (including xTuple-specific Exhibits)
* is available at www.xtuple.com/CPAL. By using this software, you agree
* to be bound by its terms.
*/
#include "itemtax.h"
#include <QMessageBox>
#include <QVariant>
/*
* Constructs a itemtax as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
itemtax::itemtax(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
: XDialog(parent, name, modal, fl)
{
setupUi(this);
// signals and slots connections
connect(_save, SIGNAL(clicked()), this, SLOT(sSave()));
_itemtaxid = -1;
_itemid = -1;
}
/*
* Destroys the object and frees any allocated resources
*/
itemtax::~itemtax()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void itemtax::languageChange()
{
retranslateUi(this);
}
enum SetResponse itemtax::set(const ParameterList & pParams)
{
XSqlQuery itemtaxet;
XDialog::set(pParams);
QVariant param;
bool valid;
param = pParams.value("item_id", &valid);
if (valid)
_itemid = param.toInt();
param = pParams.value("itemtax_id", &valid);
if (valid)
{
_itemtaxid = param.toInt();
itemtaxet.prepare("SELECT itemtax_item_id,"
" COALESCE(itemtax_taxzone_id,-1) AS taxzone_id,"
" itemtax_taxtype_id"
" FROM itemtax"
" WHERE (itemtax_id=:itemtax_id);");
itemtaxet.bindValue(":itemtax_id", _itemtaxid);
itemtaxet.exec();
if(itemtaxet.first())
{
_itemid = itemtaxet.value("itemtax_item_id").toInt();
_taxzone->setId(itemtaxet.value("taxzone_id").toInt());
_taxtype->setId(itemtaxet.value("itemtax_taxtype_id").toInt());
}
// TODO: catch any possible errors
}
param = pParams.value("mode", &valid);
if(valid)
{
if(param.toString() == "new")
_mode = cNew;
else if(param.toString() == "edit")
_mode = cEdit;
else if(param.toString() == "view")
{
_mode = cView;
_save->hide();
_taxzone->setEnabled(false);
_taxtype->setEnabled(false);
}
}
return NoError;
}
void itemtax::sSave()
{
XSqlQuery itemtaxSave;
itemtaxSave.prepare("SELECT itemtax_id"
" FROM itemtax"
" WHERE ((itemtax_taxzone_id=:taxzone_id)"
" AND (itemtax_item_id=:item_id)"
" AND (itemtax_id != :itemtax_id))");
itemtaxSave.bindValue(":item_id", _itemid);
itemtaxSave.bindValue(":itemtax_id", _itemtaxid);
if(_taxzone->isValid())
itemtaxSave.bindValue(":taxzone_id", _taxzone->id());
itemtaxSave.exec();
if(itemtaxSave.first())
{
QMessageBox::warning(this, tr("Tax Zone Already Exists"),
tr("The Tax Zone you have choosen already exists for this item."));
return;
}
if(cNew == _mode)
itemtaxSave.prepare("INSERT INTO itemtax"
" (itemtax_item_id, itemtax_taxzone_id, itemtax_taxtype_id) "
"VALUES(:item_id, :taxzone_id, :taxtype_id)");
else if(cEdit == _mode)
itemtaxSave.prepare("UPDATE itemtax"
" SET itemtax_taxzone_id=:taxzone_id,"
" itemtax_taxtype_id=:taxtype_id"
" WHERE (itemtax_id=:itemtax_id);");
itemtaxSave.bindValue(":item_id", _itemid);
itemtaxSave.bindValue(":itemtax_id", _itemtaxid);
if(_taxzone->isValid())
itemtaxSave.bindValue(":taxzone_id", _taxzone->id());
itemtaxSave.bindValue(":taxtype_id", _taxtype->id());
itemtaxSave.exec();
accept();
}
|