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
|
/*
* 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 "reschedulePoitem.h"
#include "guiErrorCheck.h"
#include <QMessageBox>
#include <QVariant>
reschedulePoitem::reschedulePoitem(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
: XDialog(parent, name, modal, fl)
{
setupUi(this);
connect(_close, SIGNAL(clicked()), this, SLOT(reject()));
connect(_reschedule, SIGNAL(clicked()), this, SLOT(sReschedule()));
connect(_po, SIGNAL(valid(bool)), _poitem, SLOT(setEnabled(bool)));
connect(_po, SIGNAL(newId(int, QString)), this, SLOT(sPopulatePoitem(int)));
connect(_poitem, SIGNAL(newID(int)), this, SLOT(sPopulate(int)));
connect(_allItems, SIGNAL(clicked()), this, SLOT(sAllItems()));
}
reschedulePoitem::~reschedulePoitem()
{
// no need to delete child widgets, Qt does it all for us
}
void reschedulePoitem::languageChange()
{
retranslateUi(this);
}
enum SetResponse reschedulePoitem::set(const ParameterList &pParams)
{
XSqlQuery rescheduleet;
XDialog::set(pParams);
QVariant param;
bool valid;
param = pParams.value("pohead_id", &valid);
if (valid)
{
_po->setId(param.toInt());
_po->setReadOnly(true);
}
param = pParams.value("poitem_id", &valid);
if (valid)
{
rescheduleet.prepare( "SELECT pohead_id "
"FROM pohead, poitem "
"WHERE ((poitem_pohead_id=pohead_id)"
" AND (pohead_status='O')"
" AND (poitem_id=:poitem_id));" );
rescheduleet.bindValue(":poitem_id", param.toInt());
rescheduleet.exec();
if (rescheduleet.first())
{
_po->setId(rescheduleet.value("pohead_id").toInt());
_po->setReadOnly(true);
_poitem->setId(param.toInt());
_poitem->setEnabled(false);
}
else
{
QMessageBox::critical(this, tr("P/O Not Open"),
tr("The P/O line item you are trying to reschedule does\n"
"not belong to an Open P/O.") );
return UndefinedError;
}
}
return NoError;
}
void reschedulePoitem::sPopulatePoitem(int pPoheadid)
{
XSqlQuery reschedulePopulatePoitem;
reschedulePopulatePoitem.prepare( "SELECT poitem_id,"
" ( poitem_linenumber || '-' ||"
" COALESCE(item_number, poitem_vend_item_number) || ' (' ||"
" COALESCE(item_descrip1, firstLine(poitem_vend_item_descrip)) || ')' ) "
"FROM poitem LEFT OUTER JOIN "
" ( itemsite JOIN item "
" ON (itemsite_item_id=item_id)"
" ) ON (poitem_itemsite_id=itemsite_id) "
"WHERE ( (poitem_status <> 'C')"
" AND (poitem_pohead_id=:pohead_id) ) "
"ORDER BY poitem_linenumber;" );
reschedulePopulatePoitem.bindValue(":pohead_id", pPoheadid);
reschedulePopulatePoitem.exec();
_poitem->populate(reschedulePopulatePoitem);
sPopulate(_poitem->id());
}
void reschedulePoitem::sPopulate(int pPoitemid)
{
XSqlQuery reschedulePopulate;
if (pPoitemid == -1)
{
_current->clear();
_new->clear();
_reschedule->setEnabled(false);
}
else
{
reschedulePopulate.prepare( "SELECT poitem_duedate "
"FROM poitem "
"WHERE (poitem_id=:poitem_id);" );
reschedulePopulate.bindValue(":poitem_id", pPoitemid);
reschedulePopulate.exec();
if (reschedulePopulate.first())
{
_current->setDate(reschedulePopulate.value("poitem_duedate").toDate());
_reschedule->setEnabled(true);
}
}
}
void reschedulePoitem::sAllItems()
{
_poitem->setVisible(!_allItems->isChecked());
_poitemLit->setVisible(!_allItems->isChecked());
_reschedule->setEnabled((_allItems->isChecked() && _po->isValid())
|| (!_allItems->isChecked() && _poitem->isValid()));
}
void reschedulePoitem::sReschedule()
{
XSqlQuery rescheduleReschedule;
QList<GuiErrorCheck> errors;
errors << GuiErrorCheck(!_new->isValid(), _new,
tr("<p>You must enter a reschedule due date before "
"you may save this Purchase Order.") )
<< GuiErrorCheck(!_po->isValid(), _po,
tr("<p>You must select a Purchase Order.") )
;
if (GuiErrorCheck::reportErrors(this, tr("Cannot Reschedule Order"), errors))
return;
if (_allItems->isChecked())
rescheduleReschedule.prepare("SELECT changePoitemDueDate(poitem_id, :dueDate) "
"FROM poitem "
"WHERE ((poitem_pohead_id=:po_id) "
" AND (poitem_status <> 'C'));");
else
rescheduleReschedule.prepare("SELECT changePoitemDueDate(:poitem_id, :dueDate);");
rescheduleReschedule.bindValue(":po_id", _po->id());
rescheduleReschedule.bindValue(":poitem_id", _poitem->id());
rescheduleReschedule.bindValue(":dueDate", _new->date());
rescheduleReschedule.exec();
omfgThis->sPurchaseOrdersUpdated(_po->id(), true);
accept();
}
|