File: salesOrderList.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 (218 lines) | stat: -rw-r--r-- 6,497 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * 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 "salesOrderList.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QLayout>
#include <QPushButton>
#include <QVBoxLayout>

#include <parameter.h>

#include "xtreewidget.h"
#include "warehousegroup.h"
#include "xsqlquery.h"

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

  _soheadid = -1;
  _type = (cSoOpen | cSoClosed | cSoReleased);

  setWindowTitle(tr("Sales Orders"));

  QVBoxLayout *mainLayout = new QVBoxLayout(this);
  QVBoxLayout *warehouseLayout = new QVBoxLayout(0);
  QHBoxLayout *topLayout = new QHBoxLayout(0);
  QVBoxLayout *buttonsLayout = new QVBoxLayout(0);
  QVBoxLayout *listLayout = new QVBoxLayout(0);

  mainLayout->setContentsMargins(5, 5, 5, 5);
  warehouseLayout->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);
  warehouseLayout->setSpacing(0);
  topLayout->setSpacing(7);
  buttonsLayout->setSpacing(5);
  listLayout->setSpacing(0);

  _warehouse = new WarehouseGroup(this, "_warehouse");
  warehouseLayout->addWidget(_warehouse);

  QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Preferred);
  warehouseLayout->addItem(spacer);
  topLayout->addLayout(warehouseLayout);

  QSpacerItem* spacer_2 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
  topLayout->addItem(spacer_2);

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

  _select = new QPushButton(tr("&Select"), this);
  _select->setObjectName("_select");
  _select->setEnabled( false );
  _select->setDefault( true );
  buttonsLayout->addWidget(_select);
  buttonsLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
  topLayout->addLayout(buttonsLayout);
  mainLayout->addLayout(topLayout);

  QLabel *_salesOrdersLit = new QLabel(tr("Sales Orders:"), this);
  _salesOrdersLit->setObjectName("_salesOrdersLit");
  listLayout->addWidget(_salesOrdersLit);

  _so = new XTreeWidget(this);
  _so->setObjectName("_so");
  listLayout->addWidget(_so, 1);
  mainLayout->addLayout(listLayout, 1);

  resize( QSize(490, 390).expandedTo(minimumSizeHint()) );

  connect( _close, SIGNAL( clicked() ), this, SLOT( reject() ) );
  connect( _select, SIGNAL( clicked() ), this, SLOT( sSelect() ) );
  connect( _so, SIGNAL( itemSelected(int) ), _select, SLOT( animateClick() ) );
  connect( _so, SIGNAL( valid(bool) ), _select, SLOT( setEnabled(bool) ) );
  connect( _warehouse, SIGNAL(updated()), this, SLOT( sFillList() ) );

  _so->addColumn(tr("Order #"), _orderColumn, Qt::AlignLeft,  true, "cohead_number");
  _so->addColumn(tr("Customer"),          -1, Qt::AlignLeft,  true, "cust_name");
  _so->addColumn(tr("P/O #"),   _orderColumn, Qt::AlignLeft,  true, "cohead_custponumber");
  _so->addColumn(tr("Ordered"),  _dateColumn, Qt::AlignCenter,true, "cohead_orderdate");
  _so->addColumn(tr("Scheduled"),_dateColumn, Qt::AlignCenter,true, "duedate");

  setTabOrder(_warehouse, _so);
  setTabOrder(_so, _select);
  setTabOrder(_select, _close);
  setTabOrder(_close, _warehouse);
  _warehouse->setFocus();
}

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

  param = pParams.value("sohead_id", &valid);
  if (valid)
    _soheadid = param.toInt();

  param = pParams.value("soType", &valid);
  if (valid)
    _type = param.toInt();

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

  param = pParams.value("warehous_id", &valid);
  if (valid)
    _warehouse->setId(param.toInt());
  
  sFillList();
}

void salesOrderList::sSelect()
{
  done(_so->id());
}

void salesOrderList::sFillList()
{
  QString sql;


  if (_type == cSoAtShipping)
  {
    sql = "SELECT DISTINCT cohead_id, cohead_number, cust_name, cohead_custponumber,"
          "                cohead_orderdate,"
          "                getSoSchedDate(cohead_id) AS duedate "
          "FROM shiphead, shipitem, cohead, coitem, itemsite, custinfo "
          "WHERE ((cohead_cust_id=cust_id)"
          " AND (coitem_cohead_id=cohead_id)"
          " AND (coitem_itemsite_id=itemsite_id)"
          " AND (shipitem_orderitem_id=coitem_id)"
          " AND (shipitem_shiphead_id=shiphead_id)"
          " AND (shiphead_order_type='SO')"
          " AND (NOT shiphead_shipped)";

    if (_warehouse->isSelected())
      sql += " AND (itemsite_warehous_id=:warehous_id)";

  sql += ") "
         "ORDER BY cohead_number;";
  }
  else
  {
    bool statusCheck = false;

    sql = "SELECT DISTINCT cohead_id, cohead_number, cust_name, cohead_custponumber,"
          "                cohead_orderdate,"
          "                getSoSchedDate(cohead_id) AS duedate "
          "FROM cohead, coitem, itemsite, custinfo "
          "WHERE ((cohead_cust_id=cust_id)"
          " AND (coitem_status <> 'X')"
          " AND (coitem_cohead_id=cohead_id)"
          " AND (coitem_itemsite_id=itemsite_id)";

    if (_warehouse->isSelected())
      sql += " AND (itemsite_warehous_id=:warehous_id)";

    sql += "AND (";

    if (_type & cSoOpen)
    {
      sql += "(coitem_status='O')";
      statusCheck = true;
    }

    if (_type & cSoClosed)
    {
      if (statusCheck)
        sql += " OR ";
      sql += "(coitem_status='C')";
      statusCheck = true;
    }

    if (_type & cSoReleased)
    {
      if (statusCheck)
        sql += " AND ";
      sql += "(cohead_holdtype='N')";
      statusCheck = true;
    }

    if (_type & cSoCustomer)
    {
      if (statusCheck)
        sql += " AND ";
      sql += "(cohead_cust_id=:cust_id)";
    }

    sql += ")) "
           "ORDER BY cohead_number;";
  }

  XSqlQuery q;
  q.prepare(sql);
  _warehouse->bindValue(q);
  q.bindValue(":cust_id", _custid);
  q.exec();
  _so->populate(q, _soheadid);
}