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
|
/*
* 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 "closeWo.h"
#include <QMessageBox>
#include <QSqlError>
#include <QVariant>
#include "inputManager.h"
#include "returnWoMaterialItem.h"
closeWo::closeWo(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
: XDialog(parent, name, modal, fl)
{
setupUi(this);
connect(_closeWo, SIGNAL(clicked()), this, SLOT(sCloseWo()));
_captive = false;
_transDate->setDate(omfgThis->dbDate(), true);
omfgThis->inputManager()->notify(cBCWorkOrder, this, _wo, SLOT(setId(int)));
_wo->setType(cWoOpen | cWoExploded | cWoReleased | cWoIssued);
_postMaterialVariance->setChecked(_metrics->boolean("PostMaterialVariances"));
}
closeWo::~closeWo()
{
// no need to delete child widgets, Qt does it all for us
}
void closeWo::languageChange()
{
retranslateUi(this);
}
enum SetResponse closeWo::set(const ParameterList &pParams)
{
XDialog::set(pParams);
_captive = true;
QVariant param;
bool valid;
param = pParams.value("transDate", &valid);
if (valid)
_transDate->setDate(param.toDate());
param = pParams.value("wo_id", &valid);
if (valid)
{
_wo->setId(param.toInt());
_wo->setReadOnly(true);
}
return NoError;
}
bool closeWo::okToSave()
{
XSqlQuery closeokToSave;
if (!_transDate->isValid())
{
QMessageBox::critical(this, tr("Invalid date"),
tr("You must enter a valid transaction date.") );
_transDate->setFocus();
return false;
}
// Return any tools that have been issued
XSqlQuery tool;
tool.prepare( "SELECT womatl_id"
" FROM womatl "
" JOIN itemsite ON (womatl_itemsite_id = itemsite_id) "
" JOIN item ON ((itemsite_item_id = item_id) AND (item_type = 'T')) "
" WHERE ((womatl_wo_id=:wo_id)"
" AND (womatl_qtyiss > 0 ));");
tool.bindValue(":wo_id", _wo->id());
tool.exec();
if (tool.first())
{
do
{
returnWoMaterialItem newdlg(this);
ParameterList params;
params.append("womatl_id", tool.value("womatl_id").toInt());
if (newdlg.set(params) == NoError)
newdlg.exec();
}
while (tool.next());
}
XSqlQuery type;
type.prepare( "SELECT itemsite_costmethod "
"FROM itemsite,wo "
"WHERE ((wo_id=:wo_id) "
"AND (wo_itemsite_id=itemsite_id)); ");
type.bindValue(":wo_id", _wo->id());
type.exec();
if (type.first())
{
if (type.value("itemsite_costmethod").toString() == "J")
{
if (QMessageBox::critical(this, tr("Job Costed Item"),
tr("<p>Work Orders for item sites with the Job cost "
"method are posted when shipping the Sales Order "
"they are associated with."
"<p>Are you sure you want to close this "
"Work Order?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)
{
_wo->setFocus();
return false;
}
}
closeokToSave.prepare("SELECT wo_qtyrcv, womatl_issuemethod, womatl_qtyiss "
" FROM wo "
" JOIN womatl ON (womatl_wo_id = wo_id) "
" JOIN itemsite ON (womatl_itemsite_id = itemsite_id) "
" JOIN item ON ((itemsite_item_id = item_id) AND (NOT item_type = 'T')) "
" WHERE (wo_id=:wo_id);" );
closeokToSave.bindValue(":wo_id", _wo->id());
closeokToSave.exec();
if (closeokToSave.first())
{
if (closeokToSave.value("wo_qtyrcv").toDouble() == 0.0)
QMessageBox::warning(this, tr("No Production Posted"),
tr("<p>There has not been any Production "
"received from this Work Order. This "
"probably means Production Postings for "
"this Work Order have been overlooked." ));
bool unissuedMaterial = false;
bool unpushedMaterial = false;
do
{
if (! unissuedMaterial &&
(closeokToSave.value("womatl_issuemethod") == "S") &&
(closeokToSave.value("womatl_qtyiss").toDouble() == 0.0) )
{
QMessageBox::warning(this, tr("Unissued Push Items"),
tr("<p>The selected Work Order has Material "
"Requirements that are Push-Issued but "
"have not had any material issued to them. "
"This probably means that required manual "
"material issues have been overlooked."));
unissuedMaterial = true;
}
else if (! unpushedMaterial &&
( (closeokToSave.value("womatl_issuemethod") == "L") ||
(closeokToSave.value("womatl_issuemethod") == "M") ) &&
(closeokToSave.value("womatl_qtyiss").toDouble() == 0.0) )
{
QMessageBox::warning(this, tr("Unissued Pull Items"),
tr("<p>The selected Work Order has Material "
"Requirements that are Pull-Issued but "
"have not had any material issued to them. "
"This probably means that Production was "
"posted for this Work Order through "
"posting Operations. The BOM for this Item "
"should be modified to list Used At "
"selections for each BOM Item." ) );
unpushedMaterial = true;
}
}
while (closeokToSave.next());
}
else if (closeokToSave.lastError().type() != QSqlError::NoError)
{
systemError(this, closeokToSave.lastError().databaseText(), __FILE__, __LINE__);
return false;
}
return true; // this is the only successful case
}
else if (type.lastError().type() != QSqlError::NoError)
{
systemError(this, type.lastError().databaseText(), __FILE__, __LINE__);
return false;
}
else // type not found
{
systemError(this, tr("Cannot close Work Order %1 because the Item does not "
"appear to have an Item Type! Please check the Item "
"definition. You may need to reset the Type and save "
"the Item record.").arg(_wo->woNumber()));
return false;
}
return false;
}
void closeWo::sCloseWo()
{
XSqlQuery closeCloseWo;
if (okToSave() &&
QMessageBox::question(this, tr("Close Work Order"),
tr("<p>Are you sure you want to close this "
"Work Order?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
{
closeCloseWo.prepare("SELECT closeWo(:wo_id, :postMatVar, :date);");
closeCloseWo.bindValue(":wo_id", _wo->id());
closeCloseWo.bindValue(":postMatVar", QVariant(_postMaterialVariance->isChecked()));
closeCloseWo.bindValue(":date", _transDate->date());
closeCloseWo.exec();
if (closeCloseWo.lastError().type() != QSqlError::NoError)
{
systemError(this, closeCloseWo.lastError().databaseText(), __FILE__, __LINE__);
return;
}
omfgThis->sWorkOrdersUpdated(_wo->id(), true);
if (_captive)
close();
else
{
clear();
}
}
}
void closeWo::clear()
{
_wo->setId(-1);
_close->setText(tr("&Close"));
_wo->setFocus();
}
|