Logo Search packages:      
Sourcecode: lemonpos-kde4 version File versions  Download package

void lemonView::printTicket ( TicketInfo  ticket  )  [private, slot]

Slot used to print the ticket, show a frame message and wait a few seconds...

Definition at line 1388 of file lemonview.cpp.

Referenced by finishCurrentTransaction().

{
  //TRanslateable strings:
  QString salesperson    = i18n("Salesperson: %1", loggedUserName);
  QString hQty           = i18n("Qty");
  QString hProduct       = i18n("Product");
  QString hPrice         = i18n("Price");
  QString hDisc          = i18n("Special");
  QString hTotal         = i18n("Total");
  QString hClientDisc    = i18n("Your discount: %1", discMoney);
  QString hClientBuyPoints  = i18n("Your points this buy: %1", buyPoints);
  QString hClientPoints  = i18n("Your total points: %1", clientInfo.points);
  QString hTicket  = i18n("Ticket # %1", ticket.number);
  QString terminal = i18n("Terminal #%1", Settings::editTerminalNumber());
  //HTML Ticket
  QStringList ticketHtml;
  double tDisc = 0.0;
  //Ticket header
  ticketHtml.append(QString("<html><body><b>%1 - %2</b> [%3]<br>Ticket #%4 %5 %6<br>")
      .arg(Settings::editStoreName())
      .arg(Settings::editBranchName())
      .arg(Settings::editBranchNumber())
      .arg(ticket.number)
      .arg(salesperson)
      .arg(terminal));
  //Ticket Table header
  ticketHtml.append(QString("<table border=0><tr><th>%1</th><th>%2</th><th>%3</th><th>%4</th><th>%5</th></tr>")
      .arg(hQty).arg(hProduct).arg(hPrice).arg(hDisc).arg(hTotal));

  //TEXT Ticket
  QStringList itemsForPrint;
  QString line;
  line = QString("%1,  [#%2]").arg(Settings::editStoreName()).arg(Settings::editBranchNumber());
  itemsForPrint.append(line);
  line = QString("%2  %1")
     .arg(terminal)
     .arg(Settings::editBranchName());
  itemsForPrint.append(line);
  line = QString("%1  %2").arg(hTicket).arg(salesperson);
  itemsForPrint.append(line);
  line = KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), KLocale::LongDate);
  itemsForPrint.append(line);
  itemsForPrint.append("          ");
  hQty.truncate(6);
  hProduct.truncate(14);
  hPrice.truncate(7);
  hTotal.truncate(6);
  //qDebug()<< "Strings:"<< hQty;qDebug()<< ", "<< hProduct<<", "<<hPrice<<", "<<hTotal;
  itemsForPrint.append(hQty +"  "+ hProduct +"      "+ hPrice+ " "+ hTotal);
  itemsForPrint.append("------  --------------  -------  -------");
  for (int row=0; row<ui_mainview.tableWidget->rowCount(); ++row)
  {
    QTableWidgetItem *item;
    item = ui_mainview.tableWidget->item(row, colCode);
    qulonglong code = item->data(Qt::DisplayRole).toULongLong();
    ProductInfo info = productsHash.value(code);
    item = ui_mainview.tableWidget->item(row, colDesc);//desc
    QString  idesc =  item->data(Qt::DisplayRole).toString();
    item = ui_mainview.tableWidget->item(row, colPrice);//price
    QString iprice =  item->data(Qt::DisplayRole).toString();
    item = ui_mainview.tableWidget->item(row, colQty);//qty
    QString iqty =  item->data(Qt::DisplayRole).toString();
    iqty = iqty+" "+info.unitStr;
    item = ui_mainview.tableWidget->item(row, colDisc);//discount
    QString idiscount =  item->data(Qt::DisplayRole).toString();
    bool hasDiscount = false;
    //qDebug()<<"Total discount:"<<tDisc;
    if (item->data(Qt::DisplayRole).toDouble() > 0) {
      hasDiscount = true;
      tDisc = tDisc + item->data(Qt::DisplayRole).toDouble();
//       qDebug()<<"Has discount, new tDisc:"<<tDisc;
    }
    item = ui_mainview.tableWidget->item(row, colDue);//due
    QString idue =  item->data(Qt::DisplayRole).toString();

    //HTML Ticket
    ticketHtml.append(QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td></tr>")
        .arg(iqty).arg(idesc).arg(iprice).arg(idiscount).arg(idue));
    //TEXT TICKET
    //adjusting length
    if (idesc.length()>14) idesc.truncate(14); //idesc = idesc.insert(19, '\n');
    else {
      while (idesc.length()<14) idesc = idesc.insert(idesc.length(), ' ');
    }
    //FIXME: Falta ajustar iqty, iprice, idiscount
    while (iqty.length()<6) iqty = iqty.insert(iqty.length(), ' ');
    while (iprice.length()<7) iprice = iprice.insert(iprice.length(), ' ');
//     while (idiscount.length()<4) idiscount = idiscount.insert(idiscount.length(), ' ');

    line = QString("%1  %2  %3  %4").
        arg(iqty).
        arg(idesc).
        arg(iprice).
        arg(idue);
    itemsForPrint.append(line);
    if (hasDiscount) itemsForPrint.append(i18n("        * %1 *     -%2", hDisc, idiscount));
  }//for each item
  //HTML Ticket
  QString harticles = i18np("%1 article.", "%1 articles.", ticket.itemcount);
  QString htotal    = i18n("A total of");
  ticketHtml.append(QString("</table><br><br><b>%1</b> %2 <b>%3</b>")
      .arg(harticles).arg(htotal).arg(KGlobal::locale()->formatMoney(ticket.total)));
  ticketHtml.append(i18n("<br>Paid with %1, your change is <b>%2</b><br>",
                    KGlobal::locale()->formatMoney(ticket.paidwith),
                                    KGlobal::locale()->formatMoney(ticket.change)));
  ticketHtml.append(Settings::editTicketMessage());
  //Text Ticket
  itemsForPrint.append("  ");
  line = QString("%1  %2 %3").arg(harticles).arg(htotal).arg(ticket.total);
  itemsForPrint.append(line);
  if (tDisc > 0) {
    line = i18n("You saved $%1", tDisc);
    itemsForPrint.append(line);
  }
  if (clientInfo.discount>0) itemsForPrint.append(hClientDisc);
  if (buyPoints>0) itemsForPrint.append(hClientBuyPoints);
  if (clientInfo.points>0) itemsForPrint.append(hClientPoints);
  itemsForPrint.append(" ");
  line = i18n("Paid with %1, your change is %2",
              ticket.paidwith, KGlobal::locale()->formatMoney(ticket.change));
  itemsForPrint.append(line);
  itemsForPrint.append(" ");
  if (ticket.paidWithCard) {
    ticketHtml.append(i18n("<br>Card # %1<br>Authorisation # %2",ticket.cardnum, ticket.cardAuthNum));
    line = QString("Card Number:%1 \nAuthorisation #:%2").arg(ticket.cardnum).arg(ticket.cardAuthNum);
    itemsForPrint.append(line);
    itemsForPrint.append(" ");
  }
  line = QString(Settings::editTicketMessage());
  itemsForPrint.append(line);
  ticketHtml.append("</body></html>");

  //Printing...
  qDebug()<< itemsForPrint.join("\n");

  //This is a test... fix it later.
  if (Settings::printTicket()) {
    QFile file("/dev/lp0");
    if (file.open(QIODevice::ReadWrite)) {
      qDebug()<<"Printing ticket...";
      QTextStream out(&file);
      out << "\x1b\x4b\x30";              // Feed back x30 dot lines
      out << "\x1b\x4b\x20";              // Feed back x20 dot lines
      out << itemsForPrint.join("\n");    // Print data

      out << "\x1b\x64\x06";              // Feed 6 lines
      file.close();
    } else qDebug()<<"ERROR: Could not open printer...";
  }

  //Using SP500 for now...
//   StarPrinter *printer = new StarPrinter();
//   printer->openPrinterPort();
//   printer->setCharacterSet_toLatinamerican();
//   if (printer->isPortOpen()) {
//     qDebug()<<"Printer port opened, printing ticket...";
//     printer->writeToPort(itemsForPrint.join("\n"));
//     printer->closePrinterPort();
//   } else { qDebug()<<"Could not open port, lastError:"<<printer->lastError(); }
//   delete printer;

  if (Settings::showDialogOnPrinting())
  {
    TicketPopup *popup = new TicketPopup(this, ticketHtml.join(" "), DesktopIcon("printer", 48), 3000);
    QApplication::beep();
    popup->popup();
  }
  //Start Again a new transaction and clear all used widgets..
  QTimer::singleShot(1000, this, SLOT(startAgain()));

}


Generated by  Doxygen 1.6.0   Back to index