File: itemAliasList.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 (203 lines) | stat: -rw-r--r-- 6,622 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
202
203
/*
 * 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 "itemAliasList.h"

#include <QCheckBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QVariant>

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

#include "itemcluster.h"
#include "xtreewidget.h"

QString buildItemLineEditQuery(const QString, const QStringList, const QString, const unsigned int, bool);
QString buildItemLineEditTitle(const unsigned int, const QString);

itemAliasList::itemAliasList(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) :
  QDialog(parent, fl)
{
  setObjectName(name ? name : "itemAliasList");
  setModal(modal);

  setWindowTitle(tr( "Item Aliases"));

  _itemType = ItemLineEdit::cUndefined;

  if ( !name )
   setObjectName( "itemAliasList" );

  QVBoxLayout *_mainLayout = new QVBoxLayout(this);
  QHBoxLayout *_itemLayout = new QHBoxLayout(0);
  QHBoxLayout *_line1Layout = new QHBoxLayout(0);
  QVBoxLayout *_enterLayout = new QVBoxLayout(0);
  QHBoxLayout *_topLayout = new QHBoxLayout( 0);
  QVBoxLayout *_buttonsLayout= new QVBoxLayout(0);
  QVBoxLayout *_listLayout = new QVBoxLayout(0);

  _mainLayout->setContentsMargins(5, 5, 5, 5); 
  _itemLayout->setContentsMargins(0, 0, 0, 0); 
  _line1Layout->setContentsMargins(0, 0, 0, 0); 
  _enterLayout->setContentsMargins(0, 0, 0, 0); 
  _topLayout->setContentsMargins(0, 0, 0, 0); 
  _buttonsLayout->setContentsMargins(0, 0, 0, 0); 
  _listLayout->setContentsMargins(0, 0, 0, 0); 

  _mainLayout->setSpacing(5); 
  _itemLayout->setSpacing(5); 
  _line1Layout->setSpacing(7); 
  _enterLayout->setSpacing(5); 
  _topLayout->setSpacing(7); 
  _buttonsLayout->setSpacing(5); 
  _listLayout->setSpacing(0); 

  QLabel *_aliasLit = new QLabel(tr("&Alias:"), this);
  _aliasLit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  _aliasLit->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
  _itemLayout->addWidget(_aliasLit);

  _alias = new QLineEdit(this);
  _alias->setObjectName("_alias");
  _alias->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  _aliasLit->setBuddy(_alias);
  _itemLayout->addWidget(_alias);
  _line1Layout->addLayout(_itemLayout);

  _showInactive = new QCheckBox(tr("Show &Inactive Items"), this);
  _line1Layout->addWidget(_showInactive);
  _enterLayout->addLayout(_line1Layout);

  QSpacerItem* spacer = new QSpacerItem( 20, 32, QSizePolicy::Minimum, QSizePolicy::Fixed );
  _enterLayout->addItem( spacer );
  _topLayout->addLayout(_enterLayout);

  _close = new QPushButton(tr("&Cancel"), this);
  _buttonsLayout->addWidget(_close);

  _select = new QPushButton(tr("&Select"), this);
  _select->setEnabled( false );
  _select->setAutoDefault( true );
  _select->setDefault( true );
  _buttonsLayout->addWidget(_select);

  _topLayout->addLayout(_buttonsLayout);
  _mainLayout->addLayout(_topLayout);

  QLabel *_itemsLit = new QLabel(tr("&Items:"), this);
  _listLayout->addWidget(_itemsLit);

  _item = new XTreeWidget(this);
  _item->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  _itemsLit->setBuddy(_item);
  _listLayout->addWidget(_item);
  _mainLayout->addLayout(_listLayout);

  connect( _item, SIGNAL( itemSelected(int) ), this, SLOT( sSelect() ) );
  connect( _select, SIGNAL( clicked() ), this, SLOT( sSelect() ) );
  connect( _alias, SIGNAL( editingFinished() ), this, SLOT( sFillList() ) );
  connect( _item, SIGNAL( valid(bool) ), _select, SLOT( setEnabled(bool) ) );
  connect( _close, SIGNAL( clicked() ), this, SLOT( reject() ) );

  _useQuery = false;

  _item->addColumn(tr("Alias Number"),100, Qt::AlignLeft, true, "itemalias_number");
  _item->addColumn(tr("Item Number"), 100, Qt::AlignLeft, true, "item_number");
  _item->addColumn(tr("Description"),  -1, Qt::AlignLeft, true, "item_descrip");
}

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

  param = pParams.value("itemType", &valid);
  if (valid)
  {
    _itemType = param.toUInt();
    setWindowTitle(buildItemLineEditTitle(_itemType, tr("Item Aliases")));
  }
  else
  {
    _itemType = ItemLineEdit::cUndefined;
    setWindowTitle(tr("Item Aliases"));
  }

  param = pParams.value("extraClauses", &valid);
  if (valid)
    _extraClauses = param.toStringList();

  _showInactive->setChecked(false);
  _showInactive->setEnabled(!(_itemType & ItemLineEdit::cActive));

  param = pParams.value("sql", &valid);
  if (valid)
    _sql = param.toString();
}

void itemAliasList::sSelect()
{
  done(_item->altId());
}

void itemAliasList::sFillList()
{
  _item->clear();

  if (_alias->text().trimmed().length() == 0)
    return;

  QString pre( "SELECT item_id, itemalias_id, itemalias_number, item_number, (item_descrip1 || ' ' || item_descrip2) AS item_descrip "
               "FROM (SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2");
  QString post(") AS data, itemalias "
               "WHERE ( (itemalias_item_id=item_id)"
               " AND (UPPER(itemalias_number)~UPPER(:searchString)) )" );

  if(_x_preferences && _x_preferences->boolean("ListNumericItemNumbersFirst"))
    post += " ORDER BY toNumeric(item_number, 999999999999999), item_number";
  else
    post += " ORDER BY item_number";

  QStringList clauses;
  clauses = _extraClauses;
  if ( !(_itemType & ItemLineEdit::cActive) && !_showInactive->isChecked())
    clauses << "(item_active)";

  XSqlQuery alias;
  alias.prepare(buildItemLineEditQuery(pre, clauses, post, _itemType, false));
  alias.bindValue(":searchString", _alias->text().trimmed());
  alias.exec();
  if (alias.first())
  {
    if (_useQuery)
    {
      XSqlQuery item(_sql);
      if (item.first())
      {
          XTreeWidgetItem *last = NULL;
          do
          {
            if (item.findFirst("item_id", alias.value("item_id").toInt()) != -1)
              last = new XTreeWidgetItem( _item, last, alias.value("item_id").toInt(), alias.value("itemalias_id").toInt(),
                                        alias.value("itemalias_number").toString(), alias.value("item_number").toString(), alias.value("item_descrip").toString() );
          }
          while (alias.next());
      }
    }
    else
      _item->populate(alias, true);
  }
}