File: implodeWo.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 (113 lines) | stat: -rw-r--r-- 3,462 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
/*
 * 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 "implodeWo.h"

#include <QVariant>
#include <QMessageBox>
#include <QSqlError>
#include "inputManager.h"
#include "errorReporter.h"

implodeWo::implodeWo(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  : XDialog(parent, name, modal, fl)
{
  setupUi(this);

  connect(_wo, SIGNAL(valid(bool)), _implode, SLOT(setEnabled(bool)));
  connect(_implode, SIGNAL(clicked()), this, SLOT(sImplode()));
  connect(_close, SIGNAL(clicked()), this, SLOT(reject()));

  _captive = true;
  omfgThis->inputManager()->notify(cBCWorkOrder, this, _wo, SLOT(setId(int)));

  _wo->setType(cWoExploded);
}

implodeWo::~implodeWo()
{
  // no need to delete child widgets, Qt does it all for us
}

void implodeWo::languageChange()
{
  retranslateUi(this);
}

enum SetResponse implodeWo::set(const ParameterList &pParams)
{
  XDialog::set(pParams);
  _captive = true;

  QVariant param;
  bool     valid;

  param = pParams.value("wo_id", &valid);
  if (valid)
  {
    _wo->setId(param.toInt());
    _wo->setEnabled(false);
  }

  return NoError;
}

void implodeWo::sImplode()
{
  XSqlQuery implodeImplode;
  implodeImplode.prepare( "SELECT wo_adhoc "
             "FROM wo "
             "WHERE ( (wo_adhoc)"
             " AND (wo_id=:wo_id) );" );
  implodeImplode.bindValue(":wo_id", _wo->id());
  implodeImplode.exec();
  if (implodeImplode.first())
  {
    if ( QMessageBox::warning( this, tr("Adhoc Work Order"),
                               tr( "The Work Order you have selected to Implode is adhoc, meaning\n"
                                   "that its W/O Materials Requirements and/or W/O Operations lists\n"
                                   "have been manually modified.  If you Implode the selected Work Order\n"
                                   "then these modifications will be lost.\n"
                                   "Are you sure that you want to Implode the selected Work Order?"),
                               tr("&Yes"), tr("&No"), QString::null, 0, 1) == 1)
      return;
  }

  implodeImplode.prepare("SELECT implodeWo(:wo_id, true) AS result;");
  implodeImplode.bindValue(":wo_id", _wo->id());
  implodeImplode.exec();
  if (implodeImplode.first() && implodeImplode.value("result").toInt() < 0)
  {
    QString msg;
    if (implodeImplode.value("result").toInt() == -1)
      msg = tr("The Work Order could not be imploded because time clock "
	       "entries exist for it.");
    else
      msg = tr("The Work Order could not be imploded (reason %1).")
	    .arg(implodeImplode.value("result").toString());
    QMessageBox::information(this, tr("Work Order Not Imploded"), msg);
    return;
  }
  else if (implodeImplode.lastError().type() != QSqlError::NoError)
    ErrorReporter::error(QtCriticalMsg, this, tr("Error Imploding Work Order"),
                       implodeImplode, __FILE__, __LINE__);

  omfgThis->sWorkOrdersUpdated(_wo->id(), true);

  if (_captive)
    accept();
  else
  {
    _wo->setId(-1);
    _close->setText("&Close");
    _wo->setFocus();
  }
}