File: purchaseOrderList.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 (168 lines) | stat: -rw-r--r-- 5,243 bytes parent folder | download | duplicates (4)
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
/*
 * 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 "purchaseOrderList.h"

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

#include <parameter.h>
#include <metasql.h>

#include "xtreewidget.h"

#include "pocluster.h"

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

  _poheadid = -1;
  _type = (cPOUnposted | cPOOpen | cPOClosed);

  setWindowTitle(tr("Purchase Orders"));

  QHBoxLayout *purchaseOrderListLayout = new QHBoxLayout(this);
  QVBoxLayout *tableLayout  = new QVBoxLayout();
  QVBoxLayout *buttonLayout = new QVBoxLayout();
  purchaseOrderListLayout->addLayout(tableLayout);
  purchaseOrderListLayout->addLayout(buttonLayout);

  QHBoxLayout *vendLayout = new QHBoxLayout();
  _vend = new VendorCluster(this, "_vend");
  vendLayout->addWidget(_vend);
  vendLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding,
				      QSizePolicy::Minimum));
  tableLayout->addLayout(vendLayout);

  QLabel *_poheadLit = new QLabel(tr("&Purchase Orders:"), this);
  _poheadLit->setObjectName("_poheadLit");
  tableLayout->addWidget( _poheadLit );

  _pohead = new XTreeWidget(this);
  _pohead->setObjectName("_pohead");
  _poheadLit->setBuddy(_pohead);
  tableLayout->addWidget(_pohead);

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

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

  QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
  buttonLayout->addItem( spacer );

  resize( QSize(550, 350).expandedTo(minimumSizeHint()) );
  //clearWState( WState_Polished );

    // signals and slots connections
  connect(_close,  SIGNAL(clicked()),		this,	SLOT(sClose()	     ));
  connect(_pohead, SIGNAL(itemSelected(int)), _select,	SLOT(animateClick()  ));
  connect(_pohead, SIGNAL(valid(bool)),       _select,	SLOT(setEnabled(bool)));
  connect(_select, SIGNAL(clicked()),		this,	SLOT(sSelect()	     ));
  connect(_vend,   SIGNAL(newId(int)),		this,	SLOT(sFillList()     ));

  _type = 0;

  _pohead->addColumn(tr("Number"),   _orderColumn, Qt::AlignRight, true, "pohead_number");
  _pohead->addColumn(tr("Vendor"),             -1, Qt::AlignLeft,  true, "vend_name");
  _pohead->addColumn(tr("Agent"),     _itemColumn, Qt::AlignCenter,true, "pohead_agent_username");
  _pohead->addColumn(tr("Order Date"),_dateColumn, Qt::AlignLeft,  true, "pohead_orderdate");
  _pohead->addColumn(tr("First Item"),_itemColumn, Qt::AlignLeft,  true, "item_number");

  _pohead->setFocus();
}

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

  param = pParams.value("pohead_id", &valid);
  if (valid)
    _poheadid = param.toInt();
    
  param = pParams.value("poType", &valid);
  if (valid)
    _type = param.toInt();
 
  sFillList();
}

void purchaseOrderList::sSelect()
{
  done(_pohead->id());
}

void purchaseOrderList::sClose()
{
  done(_poheadid);
}

void purchaseOrderList::sFillList()
{
  QString sql( "SELECT pohead_id, pohead_number,"
               "       vend_name, pohead_agent_username,"
	       "       pohead_orderdate,"
	       "       item_number "
               "FROM vendinfo, pohead LEFT OUTER JOIN"
	       "     poitem ON (poitem_pohead_id=pohead_id AND poitem_linenumber=1)"
	       "     LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)"
	       "     LEFT OUTER JOIN item ON (itemsite_item_id=item_id) "
               "WHERE ( (pohead_vend_id=vend_id)"
	       "<? if exists(\"typeList\") ?>"
	       "  AND   (pohead_status IN ("
               "<? foreach(\"typeList\") ?>"
               "  <? if not isfirst(\"typeList\") ?>"
               "    ,"
               "  <? endif ?>"
               "  <? value(\"typeList\") ?>"
               "<? endforeach ?>"
               "                          ))"
	       "<? endif ?>"
	       "<? if exists(\"vend_id\") ?>"
	       "  AND   (pohead_vend_id=<? value(\"vend_id\") ?>)"
	       "<? endif ?>"
	       " ) "
	       "ORDER BY pohead_number DESC;" );
  ParameterList params;
  if (_vend->isValid())
    params.append("vend_id", _vend->id());

  QStringList typeList;
  if (_type & cPOUnposted)
    typeList += "U";

  if (_type & cPOOpen)
    typeList += "O";

  if (_type & cPOClosed)
    typeList += "C";

  if (! typeList.isEmpty())
    params.append("typeList", typeList);

  MetaSQLQuery mql(sql);
  XSqlQuery poheadq = mql.toQuery(params);
  _pohead->populate(poheadq, _poheadid);
}