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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
/*
* 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 "standardJournal.h"
#include <QVariant>
#include <QMessageBox>
#include "standardJournalItem.h"
standardJournal::standardJournal(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
: XDialog(parent, name, modal, fl)
{
setupUi(this);
_stdjrnlid = -1;
connect(_save, SIGNAL(clicked()), this, SLOT(sSave()));
connect(_new, SIGNAL(clicked()), this, SLOT(sNew()));
connect(_edit, SIGNAL(clicked()), this, SLOT(sEdit()));
connect(_view, SIGNAL(clicked()), this, SLOT(sView()));
connect(_delete, SIGNAL(clicked()), this, SLOT(sDelete()));
connect(_stdjrnlitem, SIGNAL(valid(bool)), _view, SLOT(setEnabled(bool)));
connect(_name, SIGNAL(editingFinished()), this, SLOT(sCheck()));
connect(_close, SIGNAL(clicked()), this, SLOT(reject()));
connect(this, SIGNAL(rejected()), this, SLOT(sReject()));
_stdjrnlitem->addColumn(tr("Account"), 200, Qt::AlignLeft, true, "account" );
_stdjrnlitem->addColumn(tr("Notes"), -1, Qt::AlignLeft, true, "note" );
_stdjrnlitem->addColumn(tr("Debit"), _priceColumn, Qt::AlignRight, true, "debit" );
_stdjrnlitem->addColumn(tr("Credit"), _priceColumn, Qt::AlignRight, true, "credit" );
_debits->setValidator(omfgThis->moneyVal());
_credits->setValidator(omfgThis->moneyVal());
}
standardJournal::~standardJournal()
{
destroy();
// no need to delete child widgets, Qt does it all for us
}
void standardJournal::languageChange()
{
retranslateUi(this);
}
void standardJournal::sReject()
{
XSqlQuery standardReject;
if (_mode == cNew)
{
standardReject.prepare( "DELETE FROM stdjrnlitem "
"WHERE (stdjrnlitem_stdjrnl_id=:stdjrnl_id);" );
standardReject.bindValue(":stdjrnl_id", _stdjrnlid);
standardReject.exec();
}
}
enum SetResponse standardJournal::set(const ParameterList &pParams)
{
XSqlQuery standardet;
XDialog::set(pParams);
QVariant param;
bool valid;
param = pParams.value("stdjrnl_id", &valid);
if (valid)
{
_stdjrnlid = param.toInt();
populate();
}
param = pParams.value("mode", &valid);
if (valid)
{
if (param.toString() == "new")
{
_mode = cNew;
standardet.exec("SELECT NEXTVAL('stdjrnl_stdjrnl_id_seq') AS _stdjrnl_id");
if (standardet.first())
_stdjrnlid = standardet.value("_stdjrnl_id").toInt();
connect(_stdjrnlitem, SIGNAL(valid(bool)), _edit, SLOT(setEnabled(bool)));
connect(_stdjrnlitem, SIGNAL(valid(bool)), _delete, SLOT(setEnabled(bool)));
connect(_stdjrnlitem, SIGNAL(itemSelected(int)), _edit, SLOT(animateClick()));
}
else if (param.toString() == "edit")
{
_mode = cEdit;
connect(_stdjrnlitem, SIGNAL(valid(bool)), _edit, SLOT(setEnabled(bool)));
connect(_stdjrnlitem, SIGNAL(valid(bool)), _delete, SLOT(setEnabled(bool)));
connect(_stdjrnlitem, SIGNAL(itemSelected(int)), _edit, SLOT(animateClick()));
}
else if (param.toString() == "view")
{
_mode = cView;
connect(_stdjrnlitem, SIGNAL(itemSelected(int)), _view, SLOT(animateClick()));
_new->setEnabled(false);
_name->setEnabled(false);
_descrip->setEnabled(false);
_notes->setEnabled(false);
_close->setText(tr("&Close"));
_save->hide();
}
}
return NoError;
}
void standardJournal::sSave()
{
XSqlQuery standardSave;
if (_name->text().length() == 0)
{
QMessageBox::warning( this, tr("Cannot Save Standard Journal"),
tr("You must enter a valid Name.") );
return;
}
standardSave.prepare( "SELECT stdjrnl_id"
" FROM stdjrnl "
" WHERE((UPPER(stdjrnl_name)=UPPER(:stdjrnl_name))"
" AND (stdjrnl_id != :stdjrnl_id));" );
standardSave.bindValue(":stdjrnl_name", _name->text());
standardSave.bindValue(":stdjrnl_id", _stdjrnlid);
standardSave.exec();
if (standardSave.first())
{
QMessageBox::warning( this, tr("Cannot Save Standard Journal"),
tr("The Name you have entered for this Standard Journal already exists. "
"Please enter in a different Name for this Standard Journal."));
_name->setFocus();
return;
}
if (_mode == cNew)
standardSave.prepare( "INSERT INTO stdjrnl "
"(stdjrnl_id, stdjrnl_name, stdjrnl_descrip, stdjrnl_notes) "
"VALUES "
"(:stdjrnl_id, :stdjrnl_name, :stdjrnl_descrip, :stdjrnl_notes);" );
else if (_mode == cEdit)
standardSave.prepare( "UPDATE stdjrnl "
" SET stdjrnl_name=:stdjrnl_name, stdjrnl_descrip=:stdjrnl_descrip, stdjrnl_notes=:stdjrnl_notes "
" WHERE (stdjrnl_id=:stdjrnl_id);" );
standardSave.bindValue(":stdjrnl_id", _stdjrnlid);
standardSave.bindValue(":stdjrnl_name", _name->text());
standardSave.bindValue(":stdjrnl_descrip", _descrip->text());
standardSave.bindValue(":stdjrnl_notes", _notes->toPlainText());
standardSave.exec();
done(_stdjrnlid);
}
void standardJournal::sCheck()
{
XSqlQuery standardCheck;
_name->setText(_name->text().trimmed());
if ((_mode == cNew) && (_name->text().length()))
{
standardCheck.prepare( "SELECT stdjrnl_id"
" FROM stdjrnl"
" WHERE((UPPER(stdjrnl_name)=UPPER(:stdjrnl_name))"
" AND (stdjrnl_id != :stdjrnl_id));" );
standardCheck.bindValue(":stdjrnl_name", _name->text());
standardCheck.bindValue(":stdjrnl_id", _stdjrnlid);
standardCheck.exec();
if (standardCheck.first())
{
_stdjrnlid = standardCheck.value("stdjrnl_id").toInt();
_mode = cEdit;
populate();
_name->setEnabled(false);
}
}
}
void standardJournal::sNew()
{
ParameterList params;
params.append("mode", "new");
params.append("stdjrnl_id", _stdjrnlid);
standardJournalItem newdlg(this, "", true);
newdlg.set(params);
if (newdlg.exec() != XDialog::Rejected)
sFillList();
}
void standardJournal::sEdit()
{
ParameterList params;
params.append("mode", "edit");
params.append("stdjrnlitem_id", _stdjrnlitem->id());
standardJournalItem newdlg(this, "", true);
newdlg.set(params);
if (newdlg.exec() != XDialog::Rejected)
sFillList();
}
void standardJournal::sView()
{
ParameterList params;
params.append("mode", "view");
params.append("stdjrnlitem_id", _stdjrnlitem->id());
standardJournalItem newdlg(this, "", true);
newdlg.set(params);
newdlg.exec();
}
void standardJournal::sDelete()
{
XSqlQuery standardDelete;
standardDelete.prepare( "DELETE FROM stdjrnlitem "
"WHERE (stdjrnlitem_id=:stdjrnlitem_id);" );
standardDelete.bindValue(":stdjrnlitem_id", _stdjrnlitem->id());
standardDelete.exec();
sFillList();
}
void standardJournal::sFillList()
{
XSqlQuery standardFillList;
standardFillList.prepare( "SELECT stdjrnlitem_id,"
" CASE WHEN(accnt_id IS NOT NULL) THEN (formatGLAccount(accnt_id) || '-' || accnt_descrip)"
" ELSE 'ERROR - NO ACCOUNT SPECIFIED'"
" END AS account,"
" firstLine(stdjrnlitem_notes) AS note,"
" CASE WHEN (stdjrnlitem_amount < 0) THEN (stdjrnlitem_amount * -1)"
" ELSE NULL"
" END AS debit,"
" CASE WHEN (stdjrnlitem_amount > 0) THEN (stdjrnlitem_amount)"
" ELSE NULL"
" END AS credit,"
" 'curr' AS debit_xtnumericrole,"
" 'curr' AS credit_xtnumericrole,"
" '' AS debit_xtnullrole,"
" '' AS credit_xtnullrole "
" FROM stdjrnlitem LEFT OUTER JOIN accnt ON (stdjrnlitem_accnt_id=accnt_id)"
" WHERE (stdjrnlitem_stdjrnl_id=:stdjrnl_id) "
" ORDER BY accnt_number, accnt_profit, accnt_sub;" );
standardFillList.bindValue(":stdjrnl_id", _stdjrnlid);
standardFillList.exec();
_stdjrnlitem->populate(standardFillList);
standardFillList.prepare( "SELECT SUM( CASE WHEN (stdjrnlitem_amount < 0) THEN (stdjrnlitem_amount * -1)"
" ELSE 0"
" END ) AS debit,"
" SUM( CASE WHEN (stdjrnlitem_amount > 0) THEN stdjrnlitem_amount"
" ELSE 0"
" END ) AS credit,"
" (SUM(stdjrnlitem_amount) <> 0) AS oob "
"FROM stdjrnlitem "
"WHERE (stdjrnlitem_stdjrnl_id=:stdjrnl_id);" );
standardFillList.bindValue(":stdjrnl_id", _stdjrnlid);
standardFillList.exec();
if (standardFillList.first())
{
_debits->setDouble(standardFillList.value("debit").toDouble());
_credits->setDouble(standardFillList.value("credit").toDouble());
QString stylesheet;
if (standardFillList.value("oob").toBool())
stylesheet = QString("* { color: %1; }").arg(namedColor("error").name());
_debits->setStyleSheet(stylesheet);
_credits->setStyleSheet(stylesheet);
}
else
systemError(this, tr("A System Error occurred at %1::%2.")
.arg(__FILE__)
.arg(__LINE__) );
}
void standardJournal::populate()
{
XSqlQuery standardpopulate;
standardpopulate.prepare( "SELECT stdjrnl_name, stdjrnl_descrip, stdjrnl_notes "
"FROM stdjrnl "
"WHERE (stdjrnl_id=:stdjrnl_id);" );
standardpopulate.bindValue(":stdjrnl_id", _stdjrnlid);
standardpopulate.exec();
if (standardpopulate.first())
{
_name->setText(standardpopulate.value("stdjrnl_name").toString());
_descrip->setText(standardpopulate.value("stdjrnl_descrip").toString());
_notes->setText(standardpopulate.value("stdjrnl_notes").toString());
sFillList();
}
else
systemError(this, tr("A System Error occurred at %1::%2.")
.arg(__FILE__)
.arg(__LINE__) );
}
|