00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }
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 }
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 }
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 }
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 }
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
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 _depura("END EmpresaTPV::guardaConf", 0);
00345 }
00346
00347
00349
00352 void EmpresaTPV::cargaConf() {
00353 _depura("EmpresaTPV::cargaConf", 0);
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00370
00371
00373
00374
00376
00377
00379
00380
00382
00383
00385
00386
00387
00388
00389
00390
00391
00392
00393
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00430
00431
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 }
00469 }
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 }
00479
00480 }
00481
00482
00483