File: warehouseZone.cpp

package info (click to toggle)
postbooks 4.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 112,660 kB
  • ctags: 22,890
  • sloc: cpp: 310,358; sh: 607; xml: 214; python: 140; awk: 104; makefile: 50
file content (201 lines) | stat: -rw-r--r-- 6,354 bytes parent folder | download | duplicates (2)
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
/*
 * 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 "warehouseZone.h"

#include <QVariant>
#include <QMessageBox>
#include <QSqlError>

#include "errorReporter.h"
#include "guiErrorCheck.h"

warehouseZone::warehouseZone(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(_name, SIGNAL(editingFinished()), this, SLOT(sCheck()));
}

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

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

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

  param = pParams.value("warehous_id", &valid);
  if (valid)
    _warehousid = param.toInt();

  param = pParams.value("whsezone_id", &valid);
  if (valid)
  {
    _whsezoneid = 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;
      _name->setEnabled(false);
      _description->setEnabled(false);
      _close->setText(tr("&Close"));
      _save->hide();
    }
  }

  return NoError;
}

void warehouseZone::sSave()
{
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_name->text().trimmed().isEmpty(), _name,
                          tr("<p>You must enter a valid name before saving "
                             "this Site Zone."))
         ;

  XSqlQuery uniq;
  uniq.prepare("SELECT whsezone_id "
               "FROM whsezone "
               "WHERE ( (whsezone_id<>:whsezone_id)"
               " AND (UPPER(whsezone_name)=UPPER(:whsezone_name)) "
               " AND (whsezone_warehous_id=(:warehouse_id)));" );
  uniq.bindValue(":whsezone_id", _whsezoneid);
  uniq.bindValue(":whsezone_name", _name->text());
  uniq.bindValue(":warehouse_id", _warehousid);
  uniq.exec();
  if (uniq.first())
  {
    errors << GuiErrorCheck(true, _name,
                            tr("<p>The Site Zone information cannot be "
                               "saved as the Site Zone Name that you "
                               "entered conflicts with an existing Site Zone. "
                               "You must uniquely name this Site Zone before "
                               "you may save it." ));
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Checking Site Zone Name"),
                                uniq, __FILE__, __LINE__))
    return;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Site Zone"), errors))
    return;

  XSqlQuery warehouseSave;

  if (_mode == cNew)
  {
    warehouseSave.prepare("SELECT NEXTVAL('whsezone_whsezone_id_seq') AS whsezone_id");
    warehouseSave.exec();
    if (warehouseSave.first())
      _whsezoneid = warehouseSave.value("whsezone_id").toInt();
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Warehouse Site Zone Information"),
                                  warehouseSave, __FILE__, __LINE__))
    {
      return;
    }

    warehouseSave.prepare( "INSERT INTO whsezone "
               "(whsezone_id, whsezone_warehous_id, whsezone_name, whsezone_descrip) "
               "VALUES "
               "(:whsezone_id, :warehous_id, :whsezone_name, :whsezone_descrip);" );
  }
  else if (_mode == cEdit)
    warehouseSave.prepare( "UPDATE whsezone "
               "SET whsezone_warehous_id=:warehous_id,"
               "    whsezone_name=:whsezone_name, whsezone_descrip=:whsezone_descrip "
               "WHERE (whsezone_id=:whsezone_id);" );

  warehouseSave.bindValue(":whsezone_id", _whsezoneid);
  warehouseSave.bindValue(":warehous_id", _warehousid);
  warehouseSave.bindValue(":whsezone_name", _name->text());
  warehouseSave.bindValue(":whsezone_descrip", _description->text());
  warehouseSave.exec();
  if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Warehouse Site Zone Information"),
                                warehouseSave, __FILE__, __LINE__))
  {
    return;
  }

  done(_whsezoneid);
}

void warehouseZone::sCheck()
{
  XSqlQuery warehouseCheck;
  _name->setText(_name->text().trimmed());
  if ( (_mode == cNew) && (_name->text().length()) )
  {
    warehouseCheck.prepare( "SELECT whsezone_id "
               "FROM whsezone "
               "WHERE ( (whsezone_warehous_id=:warehous_id)"
               " AND (UPPER(whsezone_name)=UPPER(:whsezone_name)) );" );
    warehouseCheck.bindValue(":warehous_id", _warehousid);
    warehouseCheck.bindValue(":whsezone_name", _name->text());
    warehouseCheck.exec();
    if (warehouseCheck.first())
    {
      _whsezoneid = warehouseCheck.value("whsezone_id").toInt();
      _mode = cEdit;
      populate();

      _name->setEnabled(false);
    }
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Warehouse Information"),
                                  warehouseCheck, __FILE__, __LINE__))
    {
      return;
    }
  }
}

void warehouseZone::populate()
{
  XSqlQuery warehousepopulate;
  warehousepopulate.prepare( "SELECT whsezone_warehous_id, whsezone_name, whsezone_descrip "
             "FROM whsezone "
             "WHERE (whsezone_id=:whsezone_id);" );
  warehousepopulate.bindValue(":whsezone_id", _whsezoneid);
  warehousepopulate.exec();
  if (warehousepopulate.first())
  {
    _warehousid = warehousepopulate.value("whsezone_warehous_id").toInt();
    _name->setText(warehousepopulate.value("whsezone_name").toString());
    _description->setText(warehousepopulate.value("whsezone_descrip").toString());
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Warehouse Information"),
                                warehousepopulate, __FILE__, __LINE__))
  {
    return;
  }
}