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
|
/*
* 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 "purgeInvoices.h"
#include <QVariant>
#include <QMessageBox>
#include <QFile>
#include <QProgressDialog>
purgeInvoices::purgeInvoices(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
: XDialog(parent, name, modal, fl)
{
setupUi(this);
// signals and slots connections
connect(_purge, SIGNAL(clicked()), this, SLOT(sPurge()));
connect(_close, SIGNAL(clicked()), this, SLOT(reject()));
}
purgeInvoices::~purgeInvoices()
{
// no need to delete child widgets, Qt does it all for us
}
void purgeInvoices::languageChange()
{
retranslateUi(this);
}
void purgeInvoices::sPurge()
{
XSqlQuery purgePurge;
if (!_cutOffDate->isValid())
{
QMessageBox::warning( this, tr("Enter Cutoff Date"),
tr("You must enter a valid cutoff date before purging Invoice Records.") );
return;
}
if ( QMessageBox::warning( this, tr("Delete Invoice Records"),
tr( "This function will purge Invoices and all of the associated documents including:\n"
"Return Authorizations, Lot/Serial Registrations, Sales Orders, Shipments, and Billing.\n"
"The results of the process are saved in the log file purgeInvoices.log.\n"
"You will not be able to re-print an Invoice if you delete that Invoice's Records.\n"
"\n"
"Are you sure that you want to delete the selected Invoice Records?" ),
tr("Yes"), tr("No"), QString::null, 0, 1) == 0)
{
QString logpath;
QString logname;
QString logtogether;
logpath = "";
logname = "purgeInvoices.log";
logtogether = logpath + logname;
QFile logfile(logtogether);
logfile.remove();
logfile.open(QIODevice::WriteOnly);
int _invoices = 1;
int _kount = 1;
XSqlQuery invoices;
invoices.prepare("SELECT COUNT(*) AS invoice_count "
"FROM invchead "
"WHERE ( (invchead_invcdate <= :cutOffDate) "
" AND (invchead_posted) "
" AND (invchead_recurring_invchead_id!=invchead_id) "
" AND (checkInvoiceSitePrivs(invchead_id)) );");
invoices.bindValue(":cutOffDate", _cutOffDate->date());
invoices.exec();
if (invoices.first())
_invoices = (invoices.value("invoice_count").toInt());
QProgressDialog _progress(tr("Purge Invoices in progress..."), tr("Cancel"), 0, _invoices, this);
_progress.setWindowModality(Qt::WindowModal);
invoices.prepare("SELECT invchead_id, invchead_invcnumber "
"FROM invchead "
"WHERE ( (invchead_invcdate <= :cutOffDate) "
" AND (invchead_posted) "
" AND (NOT invchead_recurring) "
" AND (checkInvoiceSitePrivs(invchead_id)) );");
invoices.bindValue(":cutOffDate", _cutOffDate->date());
invoices.exec();
while (invoices.next())
{
purgePurge.prepare("SELECT purgeInvoiceRecord(:cutOffDate, :invchead_id) AS result;");
purgePurge.bindValue(":cutOffDate", _cutOffDate->date());
purgePurge.bindValue(":invchead_id", invoices.value("invchead_id").toInt());
purgePurge.exec();
if (purgePurge.first())
{
QString logmessage = "Invoice ";
logmessage += invoices.value("invchead_invcnumber").toString();
logmessage += ", result=";
logmessage += purgePurge.value("result").toString();
logfile.write(logmessage.toLatin1());
logfile.write("\n");
}
if (_progress.wasCanceled())
break;
_progress.setValue(_kount);
_kount++;
}
_progress.setValue(_invoices);
// Purge T/O shipments that aren't invoiced
purgePurge.prepare("SELECT purgeShipments(:cutOffDate) AS result;");
purgePurge.bindValue(":cutOffDate", _cutOffDate->date());
purgePurge.exec();
accept();
}
}
|