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
|
/*
* 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 "employees.h"
#include <QAction>
#include <QMenu>
#include <QMessageBox>
#include <QSqlError>
#include <QVariant>
#include "employee.h"
#include "errorReporter.h"
#include "storedProcErrorLookup.h"
#include "parameterwidget.h"
employees::employees(QWidget* parent, const char*, Qt::WindowFlags fl)
: display(parent, "employees", fl)
{
setWindowTitle(tr("Employees"));
setReportName("EmployeeList");
setMetaSQLOptions("employees", "detail");
setParameterWidgetVisible(true);
setNewVisible(true);
setSearchVisible(true);
setQueryOnStartEnabled(true);
QString qryEmpGrp = QString( "SELECT empgrp_id, empgrp_name FROM empgrp;");
parameterWidget()->appendComboBox(tr("Employee Group"), "emp_group", qryEmpGrp);
parameterWidget()->append(tr("Show Active Only"), "activeOnly", ParameterWidget::Exists);
if (_metrics->boolean("MultiWhs"))
parameterWidget()->append(tr("Site"), "warehous_id", ParameterWidget::Site);
parameterWidget()->applyDefaultFilterSet();
connect(omfgThis, SIGNAL(employeeUpdated(int)), this, SLOT(sFillList()));
list()->addColumn(tr("Site"), _whsColumn, Qt::AlignLeft, true, "warehous_code");
list()->addColumn(tr("Active"), _ynColumn, Qt::AlignLeft, true, "emp_active");
list()->addColumn(tr("Code"), _itemColumn, Qt::AlignLeft, true, "emp_code");
list()->addColumn(tr("Number"), -1, Qt::AlignLeft, true, "emp_number");
list()->addColumn(tr("First"), _itemColumn, Qt::AlignLeft, true, "cntct_first_name");
list()->addColumn(tr("Last"), _itemColumn, Qt::AlignLeft, true, "cntct_last_name");
setupCharacteristics("EMP");
parameterWidget()->applyDefaultFilterSet();
connect(list(), SIGNAL(itemSelected(int)), this, SLOT(sOpen()));
if (!_privileges->check("MaintainEmployees"))
newAction()->setEnabled(false);
}
void employees::sNew()
{
ParameterList params;
params.append("mode", "new");
employee* newdlg = new employee();
newdlg->set(params);
omfgThis->handleNewWindow(newdlg);
}
void employees::sView()
{
ParameterList params;
params.append("mode", "view");
params.append("emp_id", list()->id());
employee* newdlg = new employee();
newdlg->set(params);
omfgThis->handleNewWindow(newdlg);
}
void employees::sDelete()
{
if (QMessageBox::question(this, tr("Delete?"),
tr("Are you sure you want to delete this Employee?"),
QMessageBox::Yes,
QMessageBox::No | QMessageBox::Default) == QMessageBox::No)
return;
XSqlQuery delq;
delq.prepare("DELETE FROM charass WHERE charass_target_type = 'EMP' AND charass_target_id = :emp_id;"
"DELETE FROM empgrpitem WHERE empgrpitem_emp_id = :emp_id;"
"DELETE FROM emp WHERE emp_id = :emp_id;");
delq.bindValue(":emp_id", list()->id());
delq.exec();
if (ErrorReporter::error(QtCriticalMsg, this, tr("Error deleting Employee"),
delq, __FILE__, __LINE__))
return;
sFillList();
}
void employees::sEdit()
{
ParameterList params;
params.append("mode", "edit");
params.append("emp_id", list()->id());
employee* newdlg = new employee();
newdlg->set(params);
omfgThis->handleNewWindow(newdlg);
}
void employees::sPopulateMenu(QMenu *pMenu, QTreeWidgetItem *, int)
{
QAction *menuItem;
bool editPriv =
(_privileges->check("MaintainEmployees"));
bool viewPriv =
(_privileges->check("ViewEmployees"));
menuItem = pMenu->addAction(tr("Edit..."), this, SLOT(sEdit()));
menuItem->setEnabled(editPriv);
menuItem = pMenu->addAction(tr("View..."), this, SLOT(sView()));
menuItem->setEnabled(viewPriv);
menuItem = pMenu->addAction(tr("Delete"), this, SLOT(sDelete()));
menuItem->setEnabled(editPriv);
}
void employees::sOpen()
{
bool editPriv =
(_privileges->check("MaintainEmployees"));
bool viewPriv =
(_privileges->check("ViewEmployees"));
if (editPriv)
sEdit();
else if (viewPriv)
sView();
}
|