File: shiptoCluster.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 (279 lines) | stat: -rw-r--r-- 7,353 bytes parent folder | download | duplicates (3)
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
/*
 * 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 <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QMessageBox>
#include <QHBoxLayout>
#include <QVBoxLayout>

#include <parameter.h>
#include <xsqlquery.h>

#include "shiptocluster.h"

ShiptoEdit::ShiptoEdit(QWidget *pParent, const char *pName) :
   VirtualClusterLineEdit(pParent, "shiptoinfo", "shipto_id", "shipto_num", "shipto_name", "addr_line1", " (false) ", pName, "shipto_active")
{
  setTitles(tr("Ship To Address"), tr("Ship To Addresses"));
  setUiName("shipTo");
  setEditPriv("MaintainShiptos");
  setViewPriv("ViewShiptos");
  setNewPriv("MaintainShiptos");

  _custid = 0;
  setCustid(-1);

  _query = "SELECT shipto_id AS id, shipto_num AS number, shipto_name AS name, "
           "  addr_line1 AS description, "
           "  (addr_city || ', ' || addr_state || '  ' || addr_postalcode) AS csv,"
           "  shipto_active AS active "
           "FROM shiptoinfo "
           "  LEFT OUTER JOIN addr ON (shipto_addr_id=addr_id) "
           "WHERE (true) ";
}

void ShiptoEdit::setId(int pId)
{
  if (pId == _id)
    return;

  VirtualClusterLineEdit::setId(pId);

  if (pId != -1)
  {
      emit nameChanged(_name);
      emit address1Changed(_description);
  }
// Incident #24595
//  else
//  {
//    _custid = -1;
//    _extraClause = " (false) ";
//    emit newCustid(_custid);
//  }
}

void ShiptoEdit::setCustid(int pCustid)
{
  if (pCustid == _custid)
    return;

  clear();
  _custid = pCustid;

  if (_custid != -1)
  {
    _extraClause = QString(" (shipto_cust_id=%1) ").arg(_custid);
    setNewPriv("MaintainShiptos");
  }
  else
  {
    _extraClause = " (false) ";
    setNewPriv("");
  }

  sUpdateMenu();

  emit newCustid(pCustid);
  emit disableList(_custid == -1);
}

void ShiptoEdit::sNew()
{
  if (canOpen())
  {
    if (!_x_privileges->check(_newPriv))
      return;

    ParameterList params;
    params.append("mode", "new");
    params.append("cust_id", _custid);

    QWidget* w = 0;
    if (parentWidget()->window())
    {
      if (parentWidget()->window()->isModal())
        w = _guiClientInterface->openWindow(_uiName, params, parentWidget()->window() , Qt::WindowModal, Qt::Dialog);
      else
        w = _guiClientInterface->openWindow(_uiName, params, parentWidget()->window() , Qt::NonModal, Qt::Window);
    }

    if (w->inherits("QDialog"))
    {
      QDialog* newdlg = qobject_cast<QDialog*>(w);
      int id = newdlg->exec();
      if (id != QDialog::Rejected)
      {
        silentSetId(id);
        emit newId(_id);
        emit valid(_id != -1);
      }
    }
  }
}

void ShiptoEdit::sList()
{
  disconnect(this, SIGNAL(editingFinished()), this, SLOT(sParse()));

  shipToList* newdlg = listFactory();
  if (newdlg)
  {
    ParameterList params;
    params.append("cust_id", _custid);
    newdlg->set(params);

    int id = newdlg->exec();
    setId(id);
  }
  else
    QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
                          .arg(__FILE__)
                          .arg(__LINE__),
                          tr("%1::sList() not yet defined")
                          .arg(metaObject()->className()));

  connect(this, SIGNAL(editingFinished()), this, SLOT(sParse()));
}

void ShiptoEdit::sSearch()
{
  disconnect(this, SIGNAL(editingFinished()), this, SLOT(sParse()));

  shipToSearch* newdlg = searchFactory();
  if (newdlg)
  {
    ParameterList params;
    params.append("cust_id", _custid);
    newdlg->set(params);
    newdlg->setSearchText(text());
    int id = newdlg->exec();
    setId(id);
  }
  else
    QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
                          .arg(__FILE__)
                          .arg(__LINE__),
                          tr("%1::sSearch() not yet defined")
                          .arg(metaObject()->className()));

  connect(this, SIGNAL(editingFinished()), this, SLOT(sParse()));
}

shipToList* ShiptoEdit::listFactory()
{
  return new shipToList(this);
}

shipToSearch* ShiptoEdit::searchFactory()
{
  return new shipToSearch(this);
}

///////////////////////////////

ShiptoCluster::ShiptoCluster(QWidget *pParent, const char *pName) :
    VirtualCluster(pParent, pName)
{
  addNumberWidget(new ShiptoEdit(this, pName));
  setLabel(tr("Ship To#"));
  setNameVisible(true);
  setDescriptionVisible(true);

  setCustid(-1);
}

void ShiptoCluster::setCustid(int pId)
{
  static_cast<ShiptoEdit*>(_number)->setCustid(pId);
}

///////////////////////////////////////////////////////////////////////////////

shipToList::shipToList(QWidget* pParent, Qt::WindowFlags pFlags) :
    VirtualList(pParent, pFlags)
{
  setMinimumWidth(600);

  QLabel* custNumberLit = new QLabel(tr("Customer #:"), this);
  QLabel* custNameLit = new QLabel(tr("Name:"), this);
  QLabel* custAddrLit = new QLabel(tr("Address:"), this);
  _custNumber = new QLabel(this);
  _custName = new QLabel(this);
  _custAddr = new QLabel(this);
  QGridLayout* grid = new QGridLayout(this);
  grid->addWidget(custNumberLit,0,0,1,1,Qt::AlignRight);
  grid->addWidget(custNameLit,1,0,1,1,Qt::AlignRight);
  grid->addWidget(custAddrLit,2,0,1,1,Qt::AlignRight);
  grid->addWidget(_custNumber,0,1,1,1,Qt::AlignLeft);
  grid->addWidget(_custName,1,1,1,1,Qt::AlignLeft);
  grid->addWidget(_custAddr,2,1,1,1,Qt::AlignLeft);
  QVBoxLayout* searchLayout = findChild<QVBoxLayout*>("searchLyt");
  searchLayout->insertLayout(0,grid);

  _listTab->setColumnCount(2);
  _listTab->addColumn(tr("Address"),  75, Qt::AlignLeft,  true, "description");
  _listTab->addColumn(tr("City, State, Zip"),      100, Qt::AlignLeft,  true, "csv");
}

void shipToList::set(const ParameterList &pParams)
{
  QVariant param;
  bool     valid;

  param = pParams.value("cust_id", &valid);
  if (valid)
  {
     XSqlQuery cust;
     cust.prepare("SELECT cust_number, cust_name, addr_line1 "
                  "FROM custinfo "
                  "LEFT OUTER JOIN cntct ON (cust_cntct_id=cntct_id) "
                  "LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id) "
                  "WHERE (cust_id=:cust_id)");
     cust.bindValue(":cust_id", param.toInt());
     cust.exec();
     if (cust.first())
     {
       _custNumber->setText(cust.value("cust_number").toString());
       _custName->setText(cust.value("cust_name").toString());
       _custAddr->setText(cust.value("addr_line1").toString());
     }
  }
}

///////////////////////////

shipToSearch::shipToSearch(QWidget* pParent, Qt::WindowFlags pFlags)
    : VirtualSearch(pParent, pFlags)
{
  setMinimumWidth(600);

  _custid = -1;

  _listTab->setColumnCount(2);
  _listTab->addColumn(tr("Address"),  75, Qt::AlignLeft,  true, "description");
  _listTab->addColumn(tr("City, State, Zip"),      100, Qt::AlignLeft,  true, "csv");
}

void shipToSearch::set(const ParameterList &pParams)
{
  QVariant param;
  bool     valid;

  param = pParams.value("cust_id", &valid);
  if (valid)
    _custid = param.toInt();

}