File: shipmentCluster.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 (245 lines) | stat: -rw-r--r-- 7,158 bytes parent folder | download
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
/*
 * 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 "shipmentcluster.h"

#include <QMessageBox>

ShipmentCluster::ShipmentCluster(QWidget* pParent, const char* pName) :
    VirtualCluster(pParent, pName)
{
    addNumberWidget(new ShipmentClusterLineEdit(this, pName));
}

// should limitToOrder and removeOrderLimit be at the lineedit level?
void ShipmentCluster::limitToOrder(const int head_id)
{
  if (head_id > 0)
  {
    switch (static_cast<ShipmentClusterLineEdit*>(_number)->type())
    {
      case ShipmentClusterLineEdit::SalesOrder:
        setExtraClause(QString("   ((shiphead_order_id=%1)"
                               "AND (shiphead_order_type='SO')) ").arg(head_id));
        break;
      case ShipmentClusterLineEdit::TransferOrder:
        setExtraClause(QString("   ((shiphead_order_id=%1)"
                               "AND (shiphead_order_type='TO')) ").arg(head_id));
        break;
      case ShipmentClusterLineEdit::All:
      default:
        setExtraClause(QString(" (shiphead_order_id=%1) ").arg(head_id));
        break;
    }
    switch (static_cast<ShipmentClusterLineEdit*>(_number)->status())
    {
      case ShipmentClusterLineEdit::Shipped:
        if (!extraClause().isEmpty())
          setExtraClause(extraClause().append(" AND "));
        setExtraClause(extraClause().append(" (shiphead_shipped = true) "));
        break;
      case ShipmentClusterLineEdit::Unshipped:
        if (!extraClause().isEmpty())
          setExtraClause(extraClause().append(" AND "));
        setExtraClause(extraClause().append(" (shiphead_shipped = false) "));
        break;
      case ShipmentClusterLineEdit::AllStatus:
      default:
        // do nothing;
        break;
    }
  }
//  else
//    removeOrderLimit();
}

void ShipmentCluster::setId(const int pid, const QString&)
{
//  removeOrderLimit();
  static_cast<ShipmentClusterLineEdit*>(_number)->setId(pid);
}

void ShipmentCluster::removeOrderLimit()
{
  ShipmentClusterLineEdit::ShipmentType type = static_cast<ShipmentClusterLineEdit*>(_number)->type();
  clearExtraClause();
  setType(type);

  ShipmentClusterLineEdit::ShipmentStatus status = static_cast<ShipmentClusterLineEdit*>(_number)->status();
  clearExtraClause();
  setStatus(status);
}

void ShipmentClusterLineEdit::setId(const int pid)
{
  //setType(All);
  VirtualClusterLineEdit::setId(pid);
}

ShipmentClusterLineEdit::ShipmentType ShipmentCluster::type()
{
  return (static_cast<ShipmentClusterLineEdit*>(_number))->type();
}

void ShipmentCluster::setType(QString ptype)
{
  return (static_cast<ShipmentClusterLineEdit*>(_number))->setType(ptype);
}

void ShipmentCluster::setType(ShipmentClusterLineEdit::ShipmentType ptype)
{
  return (static_cast<ShipmentClusterLineEdit*>(_number))->setType(ptype);
}

ShipmentClusterLineEdit::ShipmentStatus ShipmentCluster::status()
{
  return (static_cast<ShipmentClusterLineEdit*>(_number))->status();
}

void ShipmentCluster::setStatus(QString pstatus)
{
  return (static_cast<ShipmentClusterLineEdit*>(_number))->setStatus(pstatus);
}

void ShipmentCluster::setStatus(ShipmentClusterLineEdit::ShipmentStatus pstatus)
{
  return (static_cast<ShipmentClusterLineEdit*>(_number))->setStatus(pstatus);
}

ShipmentClusterLineEdit::ShipmentClusterLineEdit(QWidget* pParent, const char* pName) :
    VirtualClusterLineEdit(pParent, "shiphead", "shiphead_id", "shiphead_number",
                           "formatdate(shiphead_shipdate)", "shiphead_tracknum", 0, pName)
{
    _type = All;
    _status = AllStatus;
    setStrict(false);
    setType(SalesOrder);
    setStatus(Shipped);
    setTitles(tr("Shipment"), tr("Shipments"));
}

ShipmentClusterLineEdit::ShipmentType ShipmentClusterLineEdit::type()
{
  return _type;
}

void ShipmentClusterLineEdit::setType(ShipmentType ptype)
{
  if (ptype != _type)
  {
    switch (ptype)
    {
      case All:
        clearExtraClause();
        break;
      case SalesOrder:
        setExtraClause(" (shiphead_order_type='SO') ");
        break;
      case TransferOrder:
        setExtraClause(" (shiphead_order_type='TO') ");
        break;
      default:
        QMessageBox::critical(this, tr("Invalid Shipment Type"),
                              tr("<p>ShipmentClusterLineEdit::setType received "
                                 "an invalid ShipmentType %1").arg(ptype));
        return;
        break;
    }
  }
  _type = ptype;
}

void ShipmentClusterLineEdit::setType(QString ptype)
{
  if (ptype == "SO")
    setType(SalesOrder);
  else if (ptype == "TO")
    setType(TransferOrder);
  else
  {
    QMessageBox::critical(this, tr("Invalid Shipment Type"),
                          tr("ShipmentClusterLineEdit::setType received "
                             "an invalid ShipmentType %1").arg(ptype));
    setType(All);
  }
}

ShipmentClusterLineEdit::ShipmentStatus ShipmentClusterLineEdit::status()
{
  return _status;
}

void ShipmentClusterLineEdit::setStatus(ShipmentStatus pstatus)
{
  if (pstatus != _status)
  {
    switch (pstatus)
    {
      case AllStatus:
        clearExtraClause();
        break;
      case Shipped:
        setExtraClause(" (shiphead_shipped = true) ");
        break;
      case Unshipped:
        setExtraClause(" (shiphead_shipped = false) ");
        break;
      default:
        QMessageBox::critical(this, tr("Invalid Shipment Status"),
                              tr("<p>ShipmentClusterLineEdit::setStatus received "
                                 "an invalid ShipmentStatus %1").arg(pstatus));
        return;
        break;
    }
  }
  _status = pstatus;
}

void ShipmentClusterLineEdit::setStatus(QString pstatus)
{
  if (pstatus == "Shipped")
    setStatus(Shipped);
  else if (pstatus == "Unshipped")
    setStatus(Unshipped);
  else
  {
    QMessageBox::critical(this, tr("Invalid Shipment Status"),
                          tr("ShipmentClusterLineEdit::setStatus received "
                             "an invalid ShipmentStatus %1").arg(pstatus));
    setStatus(AllStatus);
  }
}

VirtualList* ShipmentClusterLineEdit::listFactory()
{
  return new ShipmentList(this);
}

VirtualSearch* ShipmentClusterLineEdit::searchFactory()
{
  return new ShipmentSearch(this);
}

ShipmentList::ShipmentList(QWidget* pParent, Qt::WindowFlags pFlags) :
  VirtualList(pParent, pFlags)
{
  _listTab->headerItem()->setText(1, tr("Shipped Date"));
  _listTab->headerItem()->setText(2, tr("Tracking Number"));
}

ShipmentSearch::ShipmentSearch(QWidget* pParent, Qt::WindowFlags pFlags) :
  VirtualSearch(pParent, pFlags)
{
  _listTab->headerItem()->setText(1, tr("Shipped Date"));
  _listTab->headerItem()->setText(2, tr("Tracking Number"));

  _searchName->setText(tr("Search through Shipped Date"));
  _searchDescrip->setText(tr("Search through Tracking Number"));
}