empresatpv.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Tomeu BorrĂ¡s 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 <Qt>
00022 #include <QObject>
00023 #include <qnamespace.h>
00024 #include <QFile>
00025 #include <QTextStream>
00026 #include <QDomDocument>
00027 
00028 #include "stdio.h"
00029 #include "plugins.h"
00030 
00031 #include "bulmatpv.h"
00032 
00033 
00039 EmpresaTPV::EmpresaTPV(BulmaTPV *bges) : EmpresaBase(), Input(this) {
00040     _depura("EmpresaTPV::EmpresaTPV", 0);
00041     m_bulmaTPV = bges;
00042     _depura("END EmpresaTPV::EmpresaTPV", 0);
00043 }
00044 
00045 
00047 
00049 EmpresaTPV::~EmpresaTPV() {
00050     _depura("EmpresaTPV::~EmpresaTPV", 0);
00051 
00052     while (!m_listaTickets.isEmpty())
00053         delete m_listaTickets.takeFirst();
00054 
00056     guardaConf();
00057 
00058     _depura("END EmpresaTPV::~EmpresaTPV", 0);
00059 }
00060 
00061 
00070 void EmpresaTPV::createMainWindows(Splash *splash) {
00071     _depura("EmpresaTPV::createMainWindows", 0);
00074     splash->mensaje(QApplication::translate("EmpresaTPV", "Inicializando listado de articulos"));
00075     splash->setBarraProgreso(30);
00076     m_progressbar->setValue(30);
00077 
00078     
00080         m_ticketActual = newTicket();
00081         if (!m_ticketActual)
00082         _depura("error en el sistema, reservando memoria.", 0);
00083         m_listaTickets.append(m_ticketActual);
00084 
00085 
00086 
00088     int res = g_plugins->lanza("EmpresaTPV_createMainWindows_Post", this);
00089     if (res != 0) {
00090         return;
00091     } // end if
00092 
00093     cargaConf();
00094 
00096     m_bulmaTPV->statusBar()->showMessage(nameDB(), 2000);
00097     m_bulmaTPV->setWindowTitle(QApplication::translate("EmpresaTPV", "Terminal Punto de Venta GPL") + " :: " + nameDB());
00098 
00099     _depura("END EmpresaTPV::createMainWindows", 0);
00100 }
00101 
00102 
00103 void EmpresaTPV::z() {
00104         begin();
00105         QString query = "INSERT INTO z (idalmacen) VALUES(" +confpr->valor(CONF_IDALMACEN_DEFECTO)+ ")";
00106         ejecuta(query);
00107         query = "SELECT max(idz) AS id FROM z";
00108         cursor2 *cur = cargacursor(query);
00109         QString idz = cur->valor("id");
00110         delete cur;
00111         query = "UPDATE albaran set idz = " + idz + " WHERE idz IS NULL AND ticketalbaran = TRUE";
00112         ejecuta(query);
00113         query = "SELECT count(idz) AS numtickets, sum(totalalbaran) as total FROM albaran WHERE idz = " +idz;
00114         cur = cargacursor(query);
00115         QString numtickets = cur->valor("numtickets");
00116         QString total = cur->valor("total");
00117         if (total == "" ) total = "0";
00118         query = "UPDATE z SET totalz = " + total + ", numtickets = " + numtickets + " WHERE idz =" + idz;
00119         ejecuta(query);
00120         commit();
00121         delete cur;
00122 
00123 
00124 // ========================================
00125 
00126     QFile file( confpr->valor(CONF_TICKET_PRINTER_FILE) );
00127     if ( !file.open(QIODevice::WriteOnly | QIODevice::Unbuffered)) {
00128         _depura("Error en la Impresion de ticket", 2);
00129     } // end if
00130     file.write (QString("Informe Z\n").toAscii());
00131     file.write (QString("=========\n").toAscii());
00132     file.write (QString("Empresa S.L\n").toAscii());
00133     file.write (QString("====================================\n").toAscii());
00134     file.write(QString("Direccion\n").toAscii());
00135     file.write(QString("CP: 07000 Palma de Mallorca\n").toAscii());
00136     file.write(QString("Tel: 971 00 00 00\n").toAscii());
00138     file.write ( "\n \n", 3);
00139 
00140 
00142     file.write( QString("Fecha: ").toAscii());
00143     QDate fecha = QDate::currentDate();
00144     QString sfecha = fecha.toString("d-M-yyyy");
00145     file.write( sfecha.toAscii());
00146     QTime hora = QTime::currentTime();
00147     QString stime = " " + hora.toString("HH:mm");
00148     file.write( stime.toAscii());
00149     file.write ( "\n", 1);
00150 
00152     cur = cargacursor("SELECT * FROM almacen WHERE idalmacen=" + confpr->valor(CONF_IDALMACEN_DEFECTO));
00153     if (!cur->eof()) {
00154         file.write( QString("Almacen: ").toAscii());
00155         file.write( cur->valor("nomalmacen").toAscii());
00156         file.write ( "\n", 1);
00157     } // end if
00158     delete cur;
00159 
00160 
00161     file.write ( "\n", 1);
00162     file.write ( "\n", 1);
00163 
00164 // ============================================
00165 
00166 
00167 
00168     file.write (QString("=======================\n").rightJustified(43,' ').toAscii());
00169 
00170 
00171     QString str = "Num tickets " + numtickets.rightJustified(10,' ');
00172     file.write(str.rightJustified(42,' ').toAscii());
00173     file.write ( "\n", 1);
00174 
00175     str = "Total " + total.rightJustified(10,' ');
00176     file.write(str.rightJustified(42,' ').toAscii());
00177     file.write ( "\n", 1);
00178 
00179 
00180 // ============================================
00181 
00182 
00184     file.write ( "\n \n \n \n", 7);
00185 
00188     file.write ("\x1Dh\x40",3);
00189 
00191     file.write ( "\x1DH\x02",3);
00192 
00194     file.write ( "\x1D",1);
00195     file.write ( "f\x01",2);
00196 
00198     file.write ( "\x1D\x77\x01",3);
00200     file.write ( "\x1Dk\x04",3);
00201     file.write (QString("ZZZ").toAscii());
00202     file.write (" ", 1);
00203     file.write (idz.toAscii());
00204     file.write ("\x00", 1);
00205 
00207     file.write ( "\n \n \n \n \n", 9);
00208 
00209 
00211     file.write ("\x1D\x56\x01", 3);
00212     file.close();
00213 
00214 // ========================================
00215 }
00216 
00217 
00218 
00219 void EmpresaTPV::x() {
00220         QString query = "SELECT count(idalbaran) AS numtickets, sum(totalalbaran) as total FROM albaran WHERE idz IS NULL AND ticketalbaran = TRUE";
00221         cursor2 *cur = cargacursor(query);
00222         QString numtickets = cur->valor("numtickets");
00223         QString total = cur->valor("total");
00224         if (total == "" ) total = "0";
00225         delete cur;
00226 
00227 
00228 // ========================================
00229 
00230     QFile file( confpr->valor(CONF_TICKET_PRINTER_FILE) );
00231     if ( !file.open(QIODevice::WriteOnly | QIODevice::Unbuffered)) {
00232         _depura("Error en la Impresion de ticket", 2);
00233     } // end if
00234     file.write (QString("Informe X\n").toAscii());
00235     file.write (QString("=========\n").toAscii());
00236     file.write (QString("Empresa S.L.\n").toAscii());
00237     file.write (QString("====================================\n").toAscii());
00238     file.write(QString("Direccion\n").toAscii());
00239     file.write(QString("CP: 07000 Palma de Mallorca\n").toAscii());
00240     file.write(QString("Tel: 971 00 00 00\n").toAscii());
00242     file.write ( "\n \n", 3);
00243 
00244 
00246     file.write( QString("Fecha: ").toAscii());
00247     QDate fecha = QDate::currentDate();
00248     QString sfecha = fecha.toString("d-M-yyyy");
00249     file.write( sfecha.toAscii());
00250     QTime hora = QTime::currentTime();
00251     QString stime = " " + hora.toString("HH:mm");
00252     file.write( stime.toAscii());
00253     file.write ( "\n", 1);
00254 
00256     cur = cargacursor("SELECT * FROM almacen WHERE idalmacen=" + confpr->valor(CONF_IDALMACEN_DEFECTO));
00257     if (!cur->eof()) {
00258         file.write( QString("Almacen: ").toAscii());
00259         file.write( cur->valor("nomalmacen").toAscii());
00260         file.write ( "\n", 1);
00261     } // end if
00262     delete cur;
00263 
00264 
00265     file.write ( "\n", 1);
00266     file.write ( "\n", 1);
00267 
00268 // ============================================
00269 
00270 
00271 
00272     file.write (QString("=======================\n").rightJustified(43,' ').toAscii());
00273 
00274 
00275     QString str = "Num tickets " + numtickets.rightJustified(10,' ');
00276     file.write(str.rightJustified(42,' ').toAscii());
00277     file.write ( "\n", 1);
00278 
00279     str = "Total " + total.rightJustified(10,' ');
00280     file.write(str.rightJustified(42,' ').toAscii());
00281     file.write ( "\n", 1);
00282 
00283 
00284 // ============================================
00285 
00286 
00288     file.write ( "\n \n \n \n", 7);
00289 
00291     file.write ( "\n \n \n \n \n", 9);
00292 
00293 
00295     file.write ("\x1D\x56\x01", 3);
00296     file.close();
00297 
00298 // ========================================
00299 }
00300 
00301 
00302 
00303 
00304 
00306 
00308 void EmpresaTPV::guardaConf() {
00309     _depura("EmpresaTPV::guardaConf", 0);
00310     /*
00311         QFile file(confpr->valor(CONF_DIR_USER) + "bulmafact_" + nameDB() + ".cfn");
00313         if (file.open(QIODevice::WriteOnly)) {
00314             QTextStream stream(&file);
00315             stream << "<CONFIG>\n";
00316             stream << "\t<PRINCIPAL>\n";
00317             stream << "\t\t\t<X>" + QString::number(m_bulmafact->x()) + "</X>\n";
00318             stream << "\t\t\t<Y>" + QString::number(m_bulmafact->y()) + "</Y>\n";
00319             stream << "\t\t\t<WIDTH>" + QString::number(m_bulmafact->width()) + "</WIDTH>\n";
00320             stream << "\t\t\t<HEIGHT>" + QString::number(m_bulmafact->height()) + "</HEIGHT>\n";
00321             stream << "\t\t\t<INDEXADOR>" + (m_bulmafact->actionIndexador->isChecked() ? QString("TRUE") : QString("FALSE")) + "</INDEXADOR>\n";
00322             stream << "\t</PRINCIPAL>\n";
00323 
00324 
00325             for (int i = 0; i < m_listventanas->numVentanas(); i++) {
00326             QObject *obj = m_listventanas->ventana(i);
00327                     QWidget *wid = (QWidget *) obj;
00328             stream << "\t<VENTANA>\n";
00329             stream << "\t\t<VNAME>" + obj->objectName() + "</VNAME>\n";
00330             stream << "\t\t<VX>" + QString::number(wid->parentWidget()->x()) + "</VX>\n";
00331             stream << "\t\t<VY>" + QString::number(wid->parentWidget()->y()) + "</VY>\n";
00332             stream << "\t\t<VWIDTH>" + QString::number(wid->width()) + "</VWIDTH>\n";
00333             stream << "\t\t<VHEIGHT>" + QString::number(wid->height()) + "</VHEIGHT>\n";
00334             stream << "\t\t<VVISIBLE>" + (wid->isVisible() ? QString("TRUE") : QString("FALSE")) + "</VVISIBLE>\n";
00335             stream << "\t\t<VMAXIMIZED>" + (wid->isMaximized() ? QString("TRUE") : QString("FALSE")) + "</VMAXIMIZED>\n";
00336             stream << "\t\t<VACTIVEWINDOW>" + (m_bulmafact->workspace()->activeWindow() == wid ? QString("TRUE") : QString("FALSE")) + "</VACTIVEWINDOW>";
00337             stream << "\t</VENTANA>\n";
00338         } // end for
00339 
00340             stream << "</CONFIG>\n";
00341             file.close();
00342         } // end if
00343     */
00344     _depura("END EmpresaTPV::guardaConf", 0);
00345 }
00346 
00347 
00349 
00352 void EmpresaTPV::cargaConf() {
00353     _depura("EmpresaTPV::cargaConf", 0);
00354     /*
00355         QFile file(confpr->valor(CONF_DIR_USER) + "bulmafact_" + nameDB() + ".cfn");
00356         QDomDocument doc("mydocument");
00357         if (!file.open(QIODevice::ReadOnly))
00358             return;
00359         if (!doc.setContent(&file)) {
00360             file.close();
00361             return;
00362         }
00363         file.close();
00364 
00365         // print out the element names of all elements that are direct children
00366         // of the outermost element.
00367         QDomElement docElem = doc.documentElement();
00368         QDomElement principal = docElem.firstChildElement("PRINCIPAL");
00370         QString nx = principal.firstChildElement("X").toElement().text();
00371 
00373         QString ny = principal.firstChildElement("Y").toElement().text();
00374 
00376         QString nwidth = principal.firstChildElement("WIDTH").toElement().text();
00377 
00379         QString nheight = principal.firstChildElement("HEIGHT").toElement().text();
00380 
00382         m_bulmafact->setGeometry(nx.toInt(), ny.toInt(), nwidth.toInt(), nheight.toInt());
00383 
00385         QString indexador = principal.firstChildElement("INDEXADOR").toElement().text();
00386         if (indexador == "TRUE") {
00387         s_indexadorCambiaEstado(TRUE);
00388         m_bulmafact->actionIndexador->setChecked(TRUE);
00389         } else {
00390         s_indexadorCambiaEstado(FALSE);
00391         m_bulmafact->actionIndexador->setChecked(FALSE);
00392         } // end if
00393 
00395        QWidget *activewindow = NULL;
00396        QDomNodeList nodos = docElem.elementsByTagName("VENTANA");
00397             for (int i = 0; i < nodos.count(); i++) {
00398                 QDomNode ventana = nodos.item(i);
00399                 QDomElement e1 = ventana.toElement(); /// try to convert the node to an element.
00400                 if( !e1.isNull() ) { /// the node was really an element.
00401                  QString vname = e1.firstChildElement("VNAME").toElement().text();
00402                 for (int j = 0; j < m_listventanas->numVentanas(); j++) {
00403                     QObject *obj = m_listventanas->ventana(j);
00404                     QWidget *wid = (QWidget *) obj;
00405                     if (obj->objectName() == vname) {
00406                         QString vx = e1.firstChildElement("VX").toElement().text();
00407                         QString vy = e1.firstChildElement("VY").toElement().text();
00408                         QString vwidth = e1.firstChildElement("VWIDTH").toElement().text();
00409                         QString vheight = e1.firstChildElement("VHEIGHT").toElement().text();
00410                         QString vvisible = e1.firstChildElement("VVISIBLE").toElement().text();
00411                         QString vmaximized = e1.firstChildElement("VMAXIMIZED").toElement().text();
00412                         QString vactivewindow = e1.firstChildElement("VACTIVEWINDOW").toElement().text();
00414                         wid->resize(vwidth.toInt(), vheight.toInt());
00415                         wid->parentWidget()->move(vx.toInt(), vy.toInt());
00416                         if ( vvisible == "TRUE") {
00417                             wid->showNormal();
00418                         } // end if
00419                         if ( vmaximized == "TRUE") {
00420                             wid->showMaximized();
00421                         }
00422                         if ( vactivewindow == "TRUE") {
00423                             activewindow = wid;
00424                         }
00425                     } // end if
00426                 } // end for
00427                 } // end if
00428             } // end for
00430         if (activewindow)
00431             m_bulmafact->workspace()->setActiveWindow(activewindow);
00432     */
00433     _depura("END EmpresaTPV::cargaConf", 0);
00434 }
00435 
00436 
00437 
00438 Ticket *EmpresaTPV::newTicket() {
00439     _depura("EmpresaTPV::newTicket", 0);
00441     Ticket *bud;
00442     if (g_plugins->lanza("EmpresaTPV_newTicket", this, (void **)&bud))
00443         return bud;
00444     bud = new Ticket(this, NULL);
00445     _depura("END EmpresaTPV::newTicket", 0);
00446     return bud;
00447 }
00448 
00449 void EmpresaTPV::cobrar() {
00450     QString idtrabajador = m_ticketActual->DBvalue("idtrabajador");
00451     m_ticketActual->guardar();
00452     m_ticketActual->imprimir();
00453     m_listaTickets.removeAt(m_listaTickets.indexOf(m_ticketActual));
00454     m_ticketActual = NULL;
00455 
00456 
00457     Ticket *ticket = NULL;
00458     Ticket *ticketv = NULL;
00459 
00461     for (int i = 0; i < m_listaTickets.size(); ++i) {
00462         ticket = m_listaTickets.at(i);
00463 
00464         if ( "" == ticket->DBvalue("nomticket") && idtrabajador == ticket->DBvalue("idtrabajador")) {
00465             setTicketActual(ticket);
00466             ticket->pintar();
00467             ticketv = ticket;
00468         }// end if
00469     }// end for
00470 
00472     if (!ticketv) {
00473         Ticket *tick = newTicket();
00474         tick->setDBvalue("idtrabajador", idtrabajador);
00475         setTicketActual(tick);
00476         m_listaTickets.append(tick);
00477         tick->pintar();
00478     }// end if
00479 
00480 }
00481 
00482 
00483 

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