void Trabajadores::trabajadorClicked()
{
    BtCompany *emp1 = ( BtCompany * ) mainCompany();
    BtTicket *ticket = NULL;
    BtTicket *ticketv = NULL;
    bool encontrado = false;

    /// Buscamos cual ha sido el trabajador pulsado.
    BlDbRecordSet *cur = mainCompany() ->loadQuery ( "SELECT * FROM trabajador" );
    while ( !encontrado && !cur->eof() ) {
        if ( ( ( QPushButton * ) sender() ) ->text() == cur->value( "nomtrabajador" ) + " " + cur->value( "apellidostrabajador" )  
	&& ((cur->value("passwordtrabajador") == mui_password->text() || cur->value("passwordtrabajador") == "")) ) {
            encontrado = true;

        } else {
            cur->nextRecord();
        } // end if
    } // end while

    if (encontrado) {
      /// Buscamos el ticket vacio de este trabajador y lo pintamos
      for ( int i = 0; i < emp1->listaTickets() ->size(); ++i ) {
	  ticket = emp1->listaTickets() ->at ( i );

	  if ( ticket->nomTicketDefecto() == ticket->dbValue ( "nomticket" ) && cur->value( "idtrabajador" ) == ticket->dbValue ( "idtrabajador" ) ) {
	      ( ( BtCompany * ) mainCompany() ) ->setTicketActual ( ticket );
	      ticket->pintar();
	      ticketv = ticket;
	  }// end if
      }// end for

      /// Si el trabajador no tiene ticket vacio lo creamos y le ponemos el idtrabajador.
      if ( !ticketv ) {
	  BtTicket * tick = emp1->newBtTicket();
	  tick->setDbValue ( "idtrabajador", cur->value( "idtrabajador" ) );
	  emp1->setTicketActual ( tick );
	  emp1->listaTickets() ->append ( tick );
	  tick->pintar();
      }// end if
      
      /// Segun los privilegios que tenga el camarero le desabilitamos determinados objetos.
      if(cur->value("admintrabajador") == "t") {
	QToolButton *toolz = g_main->findChild<QToolButton *> ( "mui_z" );
	if (toolz) {
	    toolz->setEnabled(true);
	} // end if	

	QToolButton *toolx = g_main->findChild<QToolButton *> ( "mui_x" );
	if (toolx) {
	    toolx->setEnabled(true);
	} // end if	

	QToolButton *toolborraticket = g_main->findChild<QToolButton *> ( "mui_borrarticket" );
	if (toolborraticket) {
	    toolborraticket->setEnabled(true);
	} // end if

      } else {

	QToolButton *toolz = g_main->findChild<QToolButton *> ( "mui_z" );
	if (toolz) {
	    toolz->setEnabled(false);
	} // end if	
	
	QToolButton *toolx = g_main->findChild<QToolButton *> ( "mui_x" );
	if (toolx) {
	    toolx->setEnabled(false);
	} // end if	


	QToolButton *toolborraticket = g_main->findChild<QToolButton *> ( "mui_borrarticket" );
	if (toolborraticket) {
	    toolborraticket->setEnabled(false);
	} // end if
	
      } // end if
      
      delete cur;

      m_validUser = true;
      done ( 0 );
    } // end if
}
Exemple #2
0
void ServerLight::processTicketDataXML(QString data)
{
    BtCompany *emp = (BtCompany *) mainCompany();
    BlDbRecord *rec;
    BtTicket *ticket;
    BtTicket *ticketActual;
    
    fprintf(stdout, "\n==========MENSAJE COMPLETO ===============\n");
    fprintf(stdout, data.toAscii());
    fprintf(stdout, "\n=========================\n");
    
    ticketActual = emp->ticketActual();
  
  
    QString *er = new QString("");
    int *erline;
    int num = 0;
    erline = &num;
  
    QDomDocument doc ( "mydocument" );
    if ( !doc.setContent ( data, true, er, erline ) ) {
      
	//fprintf(stderr, er->toAscii());
	//fprintf(stderr, QString::number(*erline).toAscii());
      
	fprintf(stderr, "Error en documento XML.\n");
        return;
    } // end if


    QDomElement docElem = doc.documentElement();
    QDomElement principal = docElem.firstChildElement ( "TICKET" );
    
    /// Cogemos la coordenada X
    QDomNodeList nodos = principal.elementsByTagName ( "LINEATICKET" );
    
    
    /// Crea un ticket.
    ticket = emp->newBtTicket();
    
    ticket->setDbValue("nomticket", principal.firstChildElement("NOMTICKET").text() );
    ticket->setDbValue("idtrabajador", "1");

	    
    int i = 0;
    while (i < nodos.count() ) {

        QDomNode ventana = nodos.item ( i++ );
		
        QDomElement e1 = ventana.toElement(); /// try to convert the node to an element.
        if ( !e1.isNull() ) { /// the node was really an element.

	    QString idarticulo = e1.firstChildElement("IDARTICULO").text();
	    QString cantarticulo = e1.firstChildElement("CANTARTICULO").text();
	    QString imagen = "";
	    QDomElement modificadores = e1.firstChildElement("MODIFICADORES");
	    if (!modificadores.isNull()) 
	      imagen = modificadores.firstChildElement("IMAGEN").text();
	    
	    
	    /// Inserta lineas.
	    BlDbRecord *linea = ticket->agregarLinea();
	    linea->setDbValue("idarticulo", idarticulo);
	    linea->setDbValue("cantlalbaran", cantarticulo);	    
	    
	    if (imagen != "") {
	      QByteArray bytes1 = QByteArray::fromBase64(imagen.toAscii());
	      QByteArray bytes;
	      QBuffer buffer(&bytes);
	      QImage img;
	      buffer.open(QIODevice::WriteOnly);
	      img.loadFromData(bytes1, "BMP");
	      img.save("/tmp/imagen.bmp","BMP");
	      img.save(&buffer, "PNG");
	      QString text = bytes.toBase64();
	      linea->setDbValue ( "imglalbaran", text );
	    } else {
	      linea->setDbValue ( "imglalbaran", "" );
	    } // end if
	    


	    
	    /// El plugin de IVA incluido tiene que estar instalado.
	    
	    /// Buscamos los parametros en la base de datos.
	    QString query = "SELECT pvparticulo, pvpivaincarticulo, codigocompletoarticulo, nomarticulo, porcentasa_iva FROM articulo LEFT JOIN (SELECT idtipo_iva, porcentasa_iva, fechatasa_iva FROM tasa_iva ) AS t1 ON articulo.idtipo_iva = t1.idtipo_iva WHERE idarticulo = " + idarticulo + " ORDER BY t1.fechatasa_iva LIMIT 1";
  	    
	    BlDbRecordSet *cur = mainCompany() ->loadQuery ( query );

	    if ( !cur->eof() ) {
		linea->setDbValue ( "pvplalbaran", cur->value( "pvparticulo" ) );
		linea->setDbValue ( "pvpivainclalbaran", cur->value( "pvpivaincarticulo" ) );		
		linea->setDbValue ( "codigocompletoarticulo", cur->value( "codigocompletoarticulo" ) );
		linea->setDbValue ( "nomarticulo", cur->value( "nomarticulo" ) );
		linea->setDbValue ( "desclalbaran", cur->value( "nomarticulo" ) );
		linea->setDbValue ( "ivalalbaran", cur->value( "porcentasa_iva") );

	    } // end if
	    delete cur;

        } // end if
    } // end while


    /// Aparca el ticket.
    emp->listaTickets()->prepend(ticket);
    
    /// Hacemos una llamada a plugins para indicar que hay un ticket nuevo y que deben recoger los otros plugins.
    /// En este caso es una llamada extraña pq no se pasa la clase llamante sino que se pasa el ticket generado.
    g_plugins->run("ticket_aparcado_remotamente", ticket);
    
}
Exemple #3
0
void Mesa::abrirMesa() {
    BtCompany * emp = ( BtCompany * ) mainCompany();


    /// Miramos que no haya ningun ticket abierto con el nombre usado
    BtTicket *ticket;
    for ( int i = 0; i < emp->listaTickets() ->size(); ++i ) {
        ticket = emp->listaTickets() ->at ( i );
        if ( m_nombreMesa == ticket->dbValue ( "nomticket" )) {

            /// Quitamos el bloqueo
            emp->ticketActual() ->setDbValue( "bloqueadoticket", "FALSE");
            
            /// Llamamos a plugins para poder hacer lo pertinente
            g_plugins->run("Abrevs_on_mui_aparcar_clicked", this);



            /// Ponemos al trabajador creado el trabajador del ticket actual.
            emp->setTicketActual ( ticket );
            /// Borra el valor del Input.
            emp->pulsaTecla ( Qt::Key_F4, "" );

            /// Llamamos a plugins para poder hacer lo pertinente
            g_plugins->run("Abrevs_on_mui_aparcar_clicked_Post", this);
            
            /// Ponemos el nuevo bloqueo
            ticket->setDbValue("bloqueadoticket", "TRUE");
            
            ticket->pintar();


            g_mesas->on_mui_mesas_clicked();


            return;
        }// end if
    }// end for


    BtTicket *tick;


    tick = emp->newBtTicket();
    tick->setDbValue ( "idtrabajador", emp->ticketActual() ->dbValue ( "idtrabajador" ) );
    emp->setValorBtInput(m_nombreMesa);

    emp->listaTickets() ->insert ( 0, tick );

    /// El nombre del ticket a aparcar lo coge del BtInput.
    tick ->setDbValue ( "nomticket", m_nombreMesa );

    /// Quitamos el bloqueo
    emp->ticketActual() ->setDbValue( "bloqueadoticket", "FALSE");
    
    /// Llamamos a plugins para poder hacer lo pertinente
     g_plugins->run("Abrevs_on_mui_aparcar_clicked", this);



    /// Ponemos al trabajador creado el trabajador del ticket actual.
    emp->setTicketActual ( tick );
    /// Borra el valor del Input.
    emp->pulsaTecla ( Qt::Key_F4, "" );

    /// Llamamos a plugins para poder hacer lo pertinente
    g_plugins->run("Abrevs_on_mui_aparcar_clicked_Post", this);
    
    /// Ponemos el nuevo bloqueo
    tick->setDbValue("bloqueadoticket", "TRUE");
    
    tick->pintar();

    g_mesas->on_mui_mesas_clicked();
}