File: configurePD.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 (150 lines) | stat: -rw-r--r-- 5,228 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
/*
 * 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 "configurePD.h"

#include <QVariant>
#include <QMessageBox>
#include <QSqlError>
#include "storedProcErrorLookup.h"
#include "guiclient.h"
#include "errorReporter.h"

configurePD::configurePD(QWidget* parent, const char* name, bool /*modal*/, Qt::WindowFlags fl)
    : XAbstractConfigure(parent, fl)
{
  XSqlQuery configureconfigurePD;
  setupUi(this);

  if (name)
    setObjectName(name);

  _inactiveBomItems->setChecked(_metrics->boolean("AllowInactiveBomItems"));
  _exclusive->setChecked(_metrics->boolean("DefaultSoldItemsExclusive"));
  _changeLog->setChecked(_metrics->boolean("ItemChangeLog"));
  _allowDelete->setChecked(_metrics->boolean("AllowBOMItemDelete"));
  _autoItemSearch->setChecked(_metrics->boolean("AutoItemSearch"));

  QString issueMethod = _metrics->value("DefaultWomatlIssueMethod");
  if (issueMethod == "S")
    _issueMethod->setCurrentIndex(0);
  else if (issueMethod == "L")
    _issueMethod->setCurrentIndex(1);
  else if (issueMethod == "M")
    _issueMethod->setCurrentIndex(2);
    
  if(_metrics->value("Application") == "PostBooks")
  {
    _revControl->hide();
    _transforms->hide();
  }
  else
  {
    configureconfigurePD.exec("SELECT * FROM itemtrans LIMIT 1;");
    if (configureconfigurePD.first())
    {
      _transforms->setChecked(true);
      _transforms->setEnabled(false);
    }
    else 
      _transforms->setChecked(_metrics->boolean("Transforms"));

    configureconfigurePD.exec("SELECT * FROM rev LIMIT 1;");
    if (configureconfigurePD.first())
    {
      _revControl->setChecked(true);
      _revControl->setEnabled(false);
    }
    else 
      _revControl->setChecked(_metrics->boolean("RevControl"));
  }
  
  this->setWindowTitle("Products Configuration");

  //adjustSize();
}

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

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

bool configurePD::sSave()
{
  XSqlQuery configureSave;
  emit saving();

  if (!_metrics->boolean("RevControl") && (_revControl->isChecked()))
  {
    if (QMessageBox::warning(this, tr("Enable Revision Control"),
      tr("Enabling revision control will create control records "
         "for products that contain revision number data.  This "
         "change can not be undone.  Do you wish to proceed?"),
        QMessageBox::Yes | QMessageBox::Default,
        QMessageBox::No  | QMessageBox::Escape) == QMessageBox::Yes)
    {
      _metrics->set("RevControl", true);
      
      QString rsql = "SELECT createbomrev(bomhead_item_id,bomhead_revision) AS result "
                     "  FROM bomhead "
                     " WHERE((COALESCE(bomhead_revision,'') <> '') "
                     "   AND (bomhead_rev_id=-1))";
      if (_metrics->value("Application") != "Standard" && _metrics->value("Application") != "PostBooks")
        rsql += " UNION "
                "SELECT createboorev(boohead_item_id,boohead_revision) "
                "  FROM boohead "
                " WHERE((COALESCE(boohead_revision,'') <> '') "
                "   AND (boohead_rev_id=-1));";
      configureSave.exec(rsql);
      if (configureSave.first() && (configureSave.value("result").toInt() < 0))
      {
        ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Period"),
                                 storedProcErrorLookup("CreateRevision",
                                 configureSave.value("result").toInt()),
                                 __FILE__, __LINE__);
        _metrics->set("RevControl", false);
        return false;
      }
      if (configureSave.lastError().type() != QSqlError::NoError)
      {
        QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
          .arg(__FILE__)
          .arg(__LINE__),
          configureSave.lastError().databaseText());
        _metrics->set("RevControl", false);
        return false;
      }
    }
    else
      return false;
  }

  _metrics->set("Transforms", ((_transforms->isChecked()) && (!_transforms->isHidden())));
  _metrics->set("RevControl", ((_revControl->isChecked()) && (!_revControl->isHidden())));
  _metrics->set("AllowInactiveBomItems", _inactiveBomItems->isChecked());
  _metrics->set("DefaultSoldItemsExclusive", _exclusive->isChecked());
  _metrics->set("ItemChangeLog", _changeLog->isChecked());
  _metrics->set("AllowBOMItemDelete", _allowDelete->isChecked());
  _metrics->set("AutoItemSearch", _autoItemSearch->isChecked());
  
  if (_issueMethod->currentIndex() == 0)
    _metrics->set("DefaultWomatlIssueMethod", QString("S"));
  else if (_issueMethod->currentIndex() == 1)
    _metrics->set("DefaultWomatlIssueMethod", QString("L"));
  else if (_issueMethod->currentIndex() == 2)
    _metrics->set("DefaultWomatlIssueMethod", QString("M"));

  return true;
}