File: subAccntType.cpp

package info (click to toggle)
postbooks 4.9.5-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 103,120 kB
  • sloc: cpp: 288,269; sh: 607; xml: 214; awk: 104; makefile: 49
file content (215 lines) | stat: -rw-r--r-- 7,187 bytes parent folder | download
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
/*
 * 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 "subAccntType.h"

#include <QVariant>
#include <QMessageBox>

subAccntType::subAccntType(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  : XDialog(parent, name, modal, fl)
{
  setupUi(this);

  connect(_save, SIGNAL(clicked()), this, SLOT(sSave()));
  connect(_close, SIGNAL(clicked()), this, SLOT(reject()));
  connect(_code, SIGNAL(editingFinished()), this, SLOT(sCheck()));
}

subAccntType::~subAccntType()
{
  // no need to delete child widgets, Qt does it all for us
}

void subAccntType::languageChange()
{
  retranslateUi(this);
}

enum SetResponse subAccntType::set( const ParameterList & pParams )
{
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("subaccnttype_id", &valid);
  if (valid)
  {
    _subaccnttypeid = param.toInt();
    populate();
  }

  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;

      _code->setEnabled(false);
      _description->setEnabled(false);
      _type->setEnabled(false);
      _close->setText(tr("&Close"));
      _save->hide();
    }
  }

  return NoError;
}

void subAccntType::sSave()
{
  XSqlQuery subSave;
  if (_mode == cEdit)
  {
    subSave.prepare( "SELECT subaccnttype_id "
               "FROM subaccnttype "
               "WHERE ( (subaccnttype_id<>:subaccnttype_id)"
               " AND (subaccnttype_code=:subaccnttype_code) );");
    subSave.bindValue(":subaccnttype_id", _subaccnttypeid);
    subSave.bindValue(":subaccnttype_code", _code->text());
    subSave.exec();
    if (subSave.first())
    {
      QMessageBox::critical( this, tr("Cannot Create Subaccount Type"),
                             tr( "A Subaccount Type with the entered code already exists."
                                 "You may not create a Subaccount Type with this code." ) );
      _code->setFocus();
      return;
    }

    subSave.prepare( "UPDATE subaccnttype "
               "SET subaccnttype_code=:subaccnttype_code,"
               "       subaccnttype_descrip=:subaccnttype_descrip,"
               "       subaccnttype_accnt_type=:subaccnttype_accnt_type "
               "WHERE (subaccnttype_id=:subaccnttype_id);" );
    subSave.bindValue(":subaccnttype_id", _subaccnttypeid);
    subSave.bindValue(":subaccnttype_code", _code->text());
    subSave.bindValue(":subaccnttype_descrip", _description->text());
    if (_type->currentIndex() == 0)
      subSave.bindValue(":subaccnttype_accnt_type", "A");
    else if (_type->currentIndex() == 1)
      subSave.bindValue(":subaccnttype_accnt_type", "L");
    else if (_type->currentIndex() == 2)
      subSave.bindValue(":subaccnttype_accnt_type", "E");
    else if (_type->currentIndex() == 3)
      subSave.bindValue(":subaccnttype_accnt_type", "R");
    else if (_type->currentIndex() == 4)
      subSave.bindValue(":subaccnttype_accnt_type", "Q");
    subSave.exec();
  }
  else if (_mode == cNew)
  {
    subSave.prepare( "SELECT subaccnttype_id "
               "FROM subaccnttype "
               "WHERE (subaccnttype_code=:subaccnttype_code);");
    subSave.bindValue(":subaccnttype_code", _code->text().trimmed());
    subSave.exec();
    if (subSave.first())
    {
      QMessageBox::critical( this, tr("Cannot Create Subaccount Type"),
                             tr( "A Subaccount Type with the entered code already exists.\n"
                                 "You may not create a Subaccount Type with this code." ) );
      _code->setFocus();
      return;
    }

    subSave.exec("SELECT NEXTVAL('subaccnttype_subaccnttype_id_seq') AS subaccnttype_id;");
    if (subSave.first())
      _subaccnttypeid = subSave.value("subaccnttype_id").toInt();
    else
    {
      systemError(this, tr("A System Error occurred at %1::%2.")
                        .arg(__FILE__)
                        .arg(__LINE__) );
      return;
    }

    subSave.prepare( "INSERT INTO subaccnttype "
               "( subaccnttype_id, subaccnttype_code,"
               "  subaccnttype_descrip, subaccnttype_accnt_type ) "
               "VALUES "
               "( :subaccnttype_id, :subaccnttype_code, :subaccnttype_descrip, :subaccnttype_accnt_type );" );
    subSave.bindValue(":subaccnttype_id", _subaccnttypeid);
    subSave.bindValue(":subaccnttype_code", _code->text());
    subSave.bindValue(":subaccnttype_descrip", _description->text());
    if (_type->currentIndex() == 0)
      subSave.bindValue(":subaccnttype_accnt_type", "A");
    else if (_type->currentIndex() == 1)
      subSave.bindValue(":subaccnttype_accnt_type", "L");
    else if (_type->currentIndex() == 2)
      subSave.bindValue(":subaccnttype_accnt_type", "E");
    else if (_type->currentIndex() == 3)
      subSave.bindValue(":subaccnttype_accnt_type", "R");
    else if (_type->currentIndex() == 4)
      subSave.bindValue(":subaccnttype_accnt_type", "Q");
    subSave.exec();
  }

  done(_subaccnttypeid);
}

void subAccntType::sCheck()
{
  XSqlQuery subCheck;
  _code->setText(_code->text().trimmed());
//  if ( (_mode == cNew) && (_code->text().length()) )
  if (_code->text().length())
  {
    subCheck.prepare( "SELECT subaccnttype_id "
               "FROM subaccnttype "
               "WHERE (subaccnttype_code=:subaccnttype_code);" );
    subCheck.bindValue(":subaccnttype_code", _code->text());
    subCheck.exec();
    if (subCheck.first())
    {
      _subaccnttypeid = subCheck.value("subaccnttype_id").toInt();
      _mode = cEdit;
      populate();

//      _code->setEnabled(false);
    }
  }
}

void subAccntType::populate()
{
  XSqlQuery subpopulate;
  subpopulate.prepare( "SELECT subaccnttype_code, subaccnttype_accnt_type, subaccnttype_descrip "
             "FROM subaccnttype "
             "WHERE (subaccnttype_id=:subaccnttype_id);" );
  subpopulate.bindValue(":subaccnttype_id", _subaccnttypeid);
  subpopulate.exec();
  if (subpopulate.first())
  {
    _code->setText(subpopulate.value("subaccnttype_code").toString());
    _description->setText(subpopulate.value("subaccnttype_descrip").toString());
    
    if (subpopulate.value("subaccnttype_accnt_type").toString() == "A")
      _type->setCurrentIndex(0);
    else if (subpopulate.value("subaccnttype_accnt_type").toString() == "L")
      _type->setCurrentIndex(1);
    else if (subpopulate.value("subaccnttype_accnt_type").toString() == "E")
      _type->setCurrentIndex(2);
    else if (subpopulate.value("subaccnttype_accnt_type").toString() == "R")
      _type->setCurrentIndex(3);
    else if (subpopulate.value("subaccnttype_accnt_type").toString() == "Q")
      _type->setCurrentIndex(4);
  }
}