cuadranteview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.com                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <QMessageBox>
00022 #include <QCloseEvent>
00023 #include <QFile>
00024 #include <QTextStream>
00025 #include <QDrag>
00026 #include <QMenu>
00027 
00028 #include <fstream>
00029 
00030 #include "cuadranteview.h"
00031 #include "cuadrante1view.h"
00032 #include "company.h"
00033 #include "configuracion.h"
00034 #include "plugins.h"
00035 
00036 #include "funcaux.h"
00037 
00038 
00047 CuadranteView::CuadranteView(Company *comp, QWidget *parent)
00048         : FichaBf(comp, parent) {
00049     _depura("CuadranteView::CuadranteView", 0);
00050     setAttribute(Qt::WA_DeleteOnClose);
00051     try {
00052         setupUi(this);
00053 
00055         if (g_plugins->lanza("CuadranteView_CuadranteView", this)) return;
00056 
00057         setTitleName(tr("Almacen"));
00058         setDBTableName("almacen");
00059 
00060         mui_listtrabajadores->setDragEnabled(TRUE);
00061         mui_cuadrante->setAcceptDrops(TRUE);
00062 //      mui_cuadrante->verticalHeader()->hide();
00063 
00064         inicializaTrabajadores();
00065         inicializaCuadrante(QDate::currentDate());
00066 
00067         meteWindow(windowTitle(), this, FALSE);
00068     } catch (...) {
00069         mensajeInfo(tr("Error al crear el almacen"));
00070     } // end try
00071     _depura("END CuadranteView::CuadranteView", 0);
00072 }
00073 
00074 
00077 
00078 
00080 CuadranteView::~CuadranteView() {
00081     _depura("CuadranteView::~CuadranteView", 0);
00082     _depura("END CuadranteView::~CuadranteView", 0);
00083 }
00084 
00085 
00090 void CuadranteView::inicializaTrabajadores() {
00091     _depura("CuadranteView::inicializaTrabajadores", 0);
00092     mui_listtrabajadores->clear();
00093     mui_listtrabajadores->setColumnCount(2);
00094     mui_listtrabajadores->hideColumn(1);
00095     cursor2 *cur = empresaBase()->cargacursor("SELECT * FROM tipotrabajo");
00096     if (cur) {
00097         while (!cur->eof()) {
00098             QTreeWidgetItem *it = new QTreeWidgetItem(mui_listtrabajadores);
00099             it->setText(0, cur->valor("nomtipotrabajo"));
00100             it->setTextColor(0, QColor("#FF0000"));
00101 
00103             cursor2 *curtrab = empresaBase()->cargacursor("SELECT * FROM trabajador WHERE idtipotrabajo = "+cur->valor("idtipotrabajo") + "ORDER BY nomtrabajador, apellidostrabajador");
00104             if (curtrab) {
00105                 while (!curtrab->eof()) {
00106                     QTreeWidgetItem *itt = new QTreeWidgetItem(it);
00107                     itt->setText(0, curtrab->valor("nomtrabajador") + " " + curtrab->valor("apellidostrabajador"));
00108                     itt->setText(1, curtrab->valor("idtrabajador"));
00109                     itt->setTextColor(0, QColor("#000000"));
00110                     curtrab->siguienteregistro();
00111                 } // end while
00112                 delete curtrab;
00113             } // end if
00114 
00115             cur->siguienteregistro();
00116         } // end if
00117         delete cur;
00118     } // end if
00119     _depura("END CuadranteView::inicializaTrabajadores", 0);
00120 }
00121 
00122 
00129 void CuadranteView::inicializaCuadrante(const QDate &dateorig) {
00130     _depura("CuadranteView::inicializaCuadrante", 0);
00131     try {
00132 
00133         mui_cuadrante->clear();
00134 
00135         cursor2 *cur = empresaBase()->cargacursor("SELECT idalmacen, tipoalmacen, nomalmacen FROM almacen ORDER BY tipoalmacen DESC, nomalmacen");
00136         if (!cur) throw -1;
00137 
00138 
00139         mui_cuadrante->setRowCount(cur->numregistros());
00140         mui_cuadrante->setColumnCount(7);
00141 
00142         QStringList headers;
00143         headers << tr("Lunes") << tr("Martes") << tr("Miercoles") << tr("Jueves") << tr("Viernes") << tr("Sabado") << tr("Domingo");
00144         mui_cuadrante->setHorizontalHeaderLabels(headers);
00145 
00146 
00147         int row = 0;
00148         while (!cur->eof()) {
00150             mui_cuadrante->setRowHeight(row, 100);
00151 
00153             QDate date = dateorig.addDays(-dateorig.dayOfWeek() + 1);
00154 
00155             for (int column = 0; column < 7; column ++) {
00156 
00157                 mui_cuadrante->setColumnWidth(column, 250);
00158 
00159                 CuadranteQTextDocument *newItem = new CuadranteQTextDocument(empresaBase(), mui_cuadrante);
00160 
00161                 newItem->setAlmFecha(cur->valor("idalmacen"), date);
00162 
00163                 mui_cuadrante->setCellWidget(row, column, newItem);
00164 
00165                 date = date.addDays(1);
00166             } // end for
00167             cur->siguienteregistro();
00168             row++;
00169         } // end while
00170     } catch (...) {
00171         _depura("Error en la carga del calendario", 2);
00172         return;
00173     }
00174 }
00175 
00176 
00178 
00181 void CuadranteView::on_mui_calendario_clicked(const QDate &date) {
00182     _depura("CuadranteView::on_mui_calendario_clicked", 0, date.toString("dd/MM/yyyy"));
00183     inicializaCuadrante(date);
00184 }
00185 
00186 
00188 
00191 void CuadranteView::on_mui_listtrabajadores_itemDoubleClicked(QTreeWidgetItem *item, int ) {
00192     _depura("elementos dobleclickados", 0);
00193     QString item1 = item->text(1);
00194 
00195     QList<QTableWidgetSelectionRange> selectionranges = mui_cuadrante->selectedRanges();
00196     for (int i = 0; i < selectionranges.size(); ++i) {
00197         for (int x = selectionranges.at(i).topRow(); x <= selectionranges.at(i).bottomRow(); x++) {
00198             for (int y = selectionranges.at(i).leftColumn(); y <= selectionranges.at(i).rightColumn(); y++) {
00199                 CuadranteQTextDocument *newItem = (CuadranteQTextDocument *) mui_cuadrante->cellWidget(x, y);
00200                 newItem->addTrabajador(item1);
00201             } // end for
00202         } // end for
00203     }
00204 }
00205 
00206 
00208 
00210 void CuadranteView::on_mui_editar_clicked() {
00211     _depura ("editar cuadrante", 0);
00212     Cuadrante1View *cuad = new Cuadrante1View(empresaBase(), 0);
00213     empresaBase()->pWorkspace()->addWindow(cuad);
00214     cuad->show();
00215     CuadranteQTextDocument *newItem = (CuadranteQTextDocument *) mui_cuadrante->cellWidget(mui_cuadrante->currentRow(), mui_cuadrante->currentColumn());
00216     newItem->connect (cuad, SIGNAL(save()), newItem, SLOT(refresh()));
00217     cuad->cargar(newItem->idcuadrante());
00218 }
00219 
00220 
00222 
00225 void CuadranteView::on_mui_calendario_customContextMenuRequested ( const QPoint & pos ) {
00226     _depura("CuadranteView::on_mui_calendario_customContextMenuRequested", 0);
00227     QMenu *popup = new QMenu(mui_calendario);
00228 
00229     popup->addSeparator();
00230     QAction *norm = popup->addAction(tr("Normal"));
00231     QAction *fiesta = popup->addAction(tr("Fiesta General"));
00232 
00233     QAction *opcion = popup->exec(mapToGlobal(pos));
00234     if (opcion == norm) {
00235         empresaBase()->begin();
00236         empresaBase()->ejecuta("UPDATE CUADRANTE SET fiestacuadrante = FALSE WHERE fechacuadrante = '"+mui_calendario->selectedDate().toString("dd/MM/yyyy")+"'");
00237         empresaBase()->commit();
00238     } // end if
00239 
00240     if (opcion == fiesta) {
00241         empresaBase()->begin();
00242         empresaBase()->ejecuta("UPDATE CUADRANTE SET fiestacuadrante = TRUE WHERE fechacuadrante = '"+mui_calendario->selectedDate().toString("dd/MM/yyyy")+"'");
00243         empresaBase()->commit();
00244     } // end if
00245 
00246     inicializaCuadrante(mui_calendario->selectedDate());
00247     _depura("END CuadranteView::on_mui_calendario_customContextMenuRequested", 0);
00248 }
00249 
00250 
00252 
00254 void CuadranteView::on_mui_actualizar_clicked() {
00255     _depura("CuadranteView::on_mui_actualizar_clicked", 0);
00256         inicializaTrabajadores();
00257         inicializaCuadrante(QDate::currentDate());
00258     _depura("CuadranteView::on_mui_actualizar_clicked", 0);
00259 }
00260 
00261 
00263 
00265 void CuadranteView::on_mui_limpiar_clicked() {
00266     _depura("CuadranteView::on_mui_limpiar_clicked", 0);
00267     QDate date = mui_calendario->selectedDate().addDays(-mui_calendario->selectedDate().dayOfWeek() + 1);
00268     QDate datefin = date.addDays(6);
00269     QString query = "DELETE FROM horario WHERE idcuadrante IN (SELECT idcuadrante FROM cuadrante WHERE fechacuadrante >= '"+date.toString("dd/MM/yyyy")+"' AND fechacuadrante <='"+datefin.toString("dd/MM/yyyy")+"')";
00270     empresaBase()->ejecuta(query);
00271     query = "DELETE FROM cuadrante WHERE fechacuadrante >= '"+date.toString("dd/MM/yyyy")+"' AND fechacuadrante <='"+datefin.toString("dd/MM/yyyy")+"'";
00272     empresaBase()->ejecuta(query);
00273     on_mui_actualizar_clicked();
00274     _depura("CuadranteView::on_mui_limpiar_clicked", 0);
00275 }
00276 
00277 
00278 
00280 
00282 void CuadranteView::on_mui_duplicar_clicked() {
00283     _depura("CuadranteView::on_mui_limpiar_clicked", 0);
00284     for (QDate date = mui_calendario->selectedDate().addDays(-mui_calendario->selectedDate().dayOfWeek() + 1)
00285     ; date <= mui_calendario->selectedDate().addDays(-mui_calendario->selectedDate().dayOfWeek() + 7)
00286     ; date = date.addDays(1)) {
00287         QDate fechaant = date.addDays(-7);
00288         QString query = "SELECT * FROM cuadrante WHERE fechacuadrante = '"+fechaant.toString("dd/MM/yyyy")+"'";
00289         _depura(query, 2);
00290         cursor2 *cur = empresaBase()->cargacursor(query);
00291         while (!cur->eof()) {
00292                 query = "UPDATE cuadrante SET ";
00293                 query += " comentcuadrante = '"+cur->valor("comentcuadrante")+"'";
00294                 query += ", aperturacuadrante = "+ ((cur->valor("aperturacuadrante")=="")?"NULL":cur->valor("aperturacuadrante"));
00295                 query += ", cierrecuadrante = " + ((cur->valor("cierrecuadrante")=="")?"NULL":cur->valor("cierrecuadrante"));
00296                 query += ", apertura1cuadrante = " + ((cur->valor("apertura1cuadrante")=="")?"NULL":cur->valor("apertura1cuadrante"));
00297                 query += ", cierre1cuadrante = " + ((cur->valor("cierre1cuadrante")=="")?"NULL":cur->valor("cierre1cuadrante"));
00298                 query += ", fiestacuadrante = '" + cur->valor("fiestacuadrante")+"'";
00299                 query += " WHERE fechacuadrante = '" + date.toString("dd/MM/yyyy") + "' AND idalmacen = " +cur->valor("idalmacen");
00300                 empresaBase()->ejecuta(query);
00301 
00302                 cursor2 *cur1 = empresaBase()->cargacursor("SELECT * FROM cuadrante WHERE fechacuadrante = '" + date.toString("dd/MM/yyyy") + "' AND idalmacen = " +cur->valor("idalmacen"));
00303                 QString idcuadrante = cur1->valor("idcuadrante");
00304                 delete cur1;
00305 
00306                 cursor2 *cur2 = empresaBase()->cargacursor("SELECT * FROM horario WHERE idcuadrante=" + cur->valor("idcuadrante"));
00307                 while (!cur2->eof()) {
00308                         query = "INSERT INTO horario (idtrabajador, idcuadrante, horainhorario, horafinhorario) VALUES (";
00309                         query+= cur2->valor("idtrabajador");
00310                         query+= "," + idcuadrante;
00311                         query+= ",'" + cur2->valor("horainhorario") + "'";
00312                         query+= ",'" +cur2->valor("horafinhorario") +"'";
00313                         query+= ")";
00314                         empresaBase()->ejecuta(query);
00315                         cur2->siguienteregistro();
00316                 } // end while
00317                 delete cur2;
00318 
00319                 cur->siguienteregistro();
00320         } // end while
00321         delete cur;
00322 
00323 
00324     } // end for
00325     on_mui_actualizar_clicked();
00326     _depura("CuadranteView::on_mui_limpiar_clicked", 0);
00327 }
00328 
00329 
00331 
00333 void CuadranteView::on_mui_imprimir_clicked() {
00334     _depura("CuadranteView::on_mui_imprimir_clicked", 0);
00335 
00336     QString archivo = confpr->valor(CONF_DIR_OPENREPORTS) + "cuadrante.rml";
00337     QString archivod = confpr->valor(CONF_DIR_USER) + "cuadrante.rml";
00338     QString archivologo = confpr->valor(CONF_DIR_OPENREPORTS) + "logo.jpg";
00339 
00341 #ifdef WINDOWS
00342 
00343     archivo = "copy " + archivo + " " + archivod;
00344 #else
00345 
00346     archivo = "cp " + archivo + " " + archivod;
00347 #endif
00348 
00349     system (archivo.toAscii().constData());
00350 
00352 #ifdef WINDOWS
00353 
00354     archivologo = "copy " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00355 #else
00356 
00357     archivologo = "cp " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00358 #endif
00359 
00360     QFile file;
00361     file.setFileName(archivod);
00362     file.open(QIODevice::ReadOnly);
00363     QTextStream stream(&file);
00364     QString buff = stream.readAll();
00365     file.close();
00366     QString fitxersortidatxt = "";
00367 
00368 
00370     fitxersortidatxt += "<para>Cuadrante</para>\n";
00371     fitxersortidatxt += "<blockTable style=\"tablacontenido\" colWidths=\"4cm, 4cm, 4cm, 4cm, 4cm, 4cm, 4cm\" repeatRows=\"1\">\n";
00372     fitxersortidatxt += "<tr>\n";
00373     fitxersortidatxt += "    <td>Lunes</td>\n";
00374     fitxersortidatxt += "    <td>Martes</td>\n";
00375     fitxersortidatxt += "    <td>Miercoles</td>\n";
00376     fitxersortidatxt += "    <td>Jueves</td>\n";
00377     fitxersortidatxt += "    <td>Viernes</td>\n";
00378     fitxersortidatxt += "    <td>Sabado</td>\n";
00379     fitxersortidatxt += "    <td>Domingo</td>\n";
00380     fitxersortidatxt += "</tr>\n";
00381 
00382 
00383 // ================================================================
00384 
00386 //    QDate date = mui_calendario->selectedDate().addDays(-mui_calendario->selectedDate().dayOfWeek() + 1);
00387 
00388     cursor2 *cur = empresaBase()->cargacursor("SELECT idalmacen FROM almacen");
00389     if (!cur) throw -1;
00390 
00391     mui_cuadrante->setRowCount(cur->numregistros());
00392     mui_cuadrante->setColumnCount(7);
00393 
00394     int row = 0;
00395     while (!cur->eof()) {
00396         fitxersortidatxt += "<tr>\n";
00397         for (int column = 0; column < 7; column ++) {
00398             CuadranteQTextDocument *newItem = (CuadranteQTextDocument *) mui_cuadrante->cellWidget(row, column);
00399             fitxersortidatxt += newItem->impresion();
00400         } // end for
00401         cur->siguienteregistro();
00402         row++;
00403         fitxersortidatxt += "</tr>\n";
00404     } // end while
00405 
00406     fitxersortidatxt += "</blockTable>\n";
00407 
00408     buff.replace("[story]", fitxersortidatxt);
00409 
00410     if (file.open(QIODevice::WriteOnly)) {
00411         QTextStream stream(&file);
00412         stream << buff;
00413         file.close();
00414     } // end if
00415     invocaPDF("cuadrante");
00416     _depura("END CuadranteView::on_mui_imprimir_clicked", 0);
00417 
00418 }
00419 
00420 

Generated on Sat Dec 15 00:01:06 2007 for BulmaGes by  doxygen 1.5.1