diff -r e6b80a8b200a .hgtags
--- a/.hgtags	Mon May 14 13:06:13 2012 +0300
+++ b/.hgtags	Fri Sep 13 19:21:02 2013 +0300
@@ -126,3 +126,28 @@
 cf6e2fd498cc6d0855ea2bbcfff2e183f9d31010 201106074
 2b17a3a1993cc8f2c3bac65f033905cd308f0783 201106078
 ed45dcbf04c37ab18c1c9f6bc6623b80c5255041 201106082
+e6b80a8b200ab51b4a2359cee26b1a366634165e 201106089
+83a66e2551a7279ac6c0e299d0e1ff202ef931ba 201106090
+77931b9db1f86c100edf5b1dad8ed3f2cda9aa18 201106104
+bd0e7852592a114e2f0dea964a64359cd3e1e33a 201106111
+0f1d47f300006ba008a21a56c3a889a672745725 201106119
+39b755f77320f96e75e86f2449e1bc4c50ba9e57 201106123
+d67390afea81cdc5d1c8bd9e896d419209afe254 201106129
+2ec1d3c3667496abf167e432c4948c0406281d73 201106137
+2ec1d3c3667496abf167e432c4948c0406281d73 201106137
+34389bec9ed70d6230419ae66d0b30f8b513c156 201106137
+1fe72a04d45dcae9dc71735ae720a32978029017 201106138
+53faee6ec7e414ac8b827625944e7b3a687d7d0e 201106160
+af364a380617ffdea16442d15b16ec385fbc065a 201106173
+ccc8f58116f7e7cee2340bd233755eebe003f40c 201106188
+ccc8f58116f7e7cee2340bd233755eebe003f40c 201106188
+e8cdfea2e66d5889b3e481b0f5719a099685ec79 201106188
+04d10a4ca1b098dd7517860b08e7d503a45414fc 201106190
+9040b5d18b24aa33a912cb4d960b8ff5e285b246 201106210
+7125cae5cda2154d1913f67f972e3abdc20c4246 201106216
+bb648aea5939eaa17c5fce6e9a7cabef592c2530 201106219
+4bd46a30ffdeffa0bdf6f8333dc0f2d876027036 201106227
+4bd46a30ffdeffa0bdf6f8333dc0f2d876027036 201106227
+f0bf3b6743d00e199f2b14138cff56b19fc78cc4 201106227
+62f5e566c1404b8a9bcbbb02e520d837778808f8 201106265
+798b1b502b86d9bad6b134d209011b8ea882637c 201106266
diff -r e6b80a8b200a Ecr.iml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ecr.iml	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="web" name="Web">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/webapps/ecrPrint/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/webapps/ecrPrint" relative="/" />
+        </webroots>
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module" module-name="Utils" />
+    <orderEntry type="library" name="rest_v2_lib" level="application" />
+  </component>
+</module>
+
diff -r e6b80a8b200a conf/ecr/cashprn.Generic.properties
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/ecr/cashprn.Generic.properties	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,39 @@
+#Consideratii generale despre casa de marcat
+# Din cate vad lucreaza cu coduri, asta inseamna ca memoreaza cod-produs. -ESTE O PRESUPUNERE DAR ASA FAC ALTE CASE - DECI PROBABIL - NU IGNORATI !! -
+# Daca se schimba codul la un produs, sau meniul in intregime , vor aparea erori si de accea trebuie golita memoria cod-produs
+# A se consulta servisantul casei pentru codul care face aceasta golire
+# Aceasta golire este recomandata a se face la inchiderea de zi, in fiecare zi !!
+
+# DIN DOCUMENTATIA PE CARE O AM ACEASTA CASA DE MARCAT SUPORTA UN SINGUR TIP DE PLATA ( cash )
+# TREBUIE REZOLVATE DIN SOFT CELELALTE SITUATII ( card - nu se completeaza cod casa marcat la Tipuri de plata ) - se alege tipul de plata corespunzator care poate fi doar unul pe nota
+
+#portul pe care ruleaza casa de marcat (1 = COM1 etc)
+ecrPort=1
+
+#se construieste un fisier bat care executa apoi comenzile una cate una
+ecrItemsFile=bonfiscal.bat
+
+#comanda de executie a unei linii . apare la inceputul fiecarei linii in bat ; se va modifica cu cale absoluta daca este necesar
+cashPrnCommand=cashprn
+
+# comanda care lanseaza bat-ul
+ecrExeFile=cmd bonfiscal.bat
+
+# directorul relativ la directorul curent unde exista driverul si unde se genereaza fisierul de bonuri
+ecrDirectory=cashprn
+
+# pozitia punctului zecimal - presupun ca 3 dar poate fi si 2
+decimalPointPosition=3
+
+# prefixul care se adauga inaintea comenzii - pt exe-uri este necesar rundll32
+#ecrSystemPrefix=rundll32 SHELL32.DLL,ShellExec_RunDLL
+# daca dorim sa fie gol, obligatoriu punem un spatiu dupa egal .
+ecrSystemPrefix= 
+
+# teoretic in aceste fisiere ajunge raspunsul driverului, respectiv eroarea
+ecrErrFile=ecr.err
+ecrLogFile=answer.txt
+
+# din motive istorice trebuie pastrate acestea
+ecrMinGrp=1
+ecrMaxGrp=8
diff -r e6b80a8b200a conf/ecr/datecs.Fprint.properties
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/ecr/datecs.Fprint.properties	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,10 @@
+ecrExeFile=fprint.exe items.txt
+ecrItemsFile=items.txt
+ecrErrFile=ecr.err
+ecrLogFile=answer.txt
+ecrDirectory=fprint
+ecrSystemPrefix=rundll32 SHELL32.DLL,ShellExec_RunDLL
+ecrDecimalPlaces=2
+ecrMinGrp=1
+ecrMaxGrp=8
+#expectedReply=
diff -r e6b80a8b200a conf/ecr/optima.Generic.properties
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/ecr/optima.Generic.properties	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,18 @@
+ecrExeFile= 
+fileNameTemplate=Online_%%nrbon%%.txt
+ecrItemsFile=Online.txt
+ecrErrFile=erori.txt
+ecrLogFile=erori.txt
+ecrDirectory=optima
+ecrSystemPrefix= 
+ecrDecimalPlaces=2
+ecrMinGrp=1
+ecrMaxGrp=99
+
+bonNumbering=true
+#expectedReply=
+
+nonfiscalReceiptLocation=optima/nota.txt
+
+nonfiscalReceiptDestinationMask=optima/Online_nf_%%nrbon%%.txt
+
diff -r e6b80a8b200a conf/ecr/xkube.Generic.properties
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/ecr/xkube.Generic.properties	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,18 @@
+ecrExeFile= 
+fileNameTemplate=Online_%%nrbon%%.txt
+ecrItemsFile=Online.txt
+ecrErrFile=erori.txt
+ecrLogFile=erori.txt
+ecrDirectory=xkube
+ecrSystemPrefix= 
+ecrDecimalPlaces=2
+ecrMinGrp=1
+ecrMaxGrp=99
+
+bonNumbering=true
+#expectedReply=
+
+nonfiscalReceiptLocation=xkube/nota.txt
+
+nonfiscalReceiptDestinationMask=xkube/Online_nf_%%nrbon%%.txt
+
diff -r e6b80a8b200a publish.txt
--- a/publish.txt	Mon May 14 13:06:13 2012 +0300
+++ b/publish.txt	Fri Sep 13 19:21:02 2013 +0300
@@ -16,3 +16,7 @@
 deploy/conf/ecr/mercury.Generic.properties=conf/ecr/mercury.Generic.properties
 deploy/conf/ecr/chd.Generic.properties=conf/ecr/chd.Generic.properties
 deploy/conf/ecr/rompos.Generic.properties=conf/ecr/rompos.Generic.properties
+deploy/conf/ecr/cashprn.Generic.properties=conf/ecr/cashprn.Generic.properties
+deploy/conf/ecr/xkube.Generic.properties=conf/ecr/xkube.Generic.properties
+deploy/conf/ecr/optima.Generic.properties=conf/ecr/optima.Generic.properties
+deploy/conf/ecr/datecs.Fprint.properties=conf/ecr/datecs.Fprint.properties
diff -r e6b80a8b200a src/ro/atreides/ecr/AbstractCashRegister.java
--- a/src/ro/atreides/ecr/AbstractCashRegister.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/AbstractCashRegister.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,13 +1,17 @@
 package ro.atreides.ecr;
 
 import org.mortbay.jetty.Server;
-import ro.atreides.utils.CashRegisterInterface;
+import org.xml.sax.SAXException;
 import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
 import ro.atreides.utils.tricky.NonPrintedBonInterface;
 import ro.atreides.utils.gui.Validators;
 import ro.atreides.utils.web.WebServerInterface;
 
+import java.io.IOException;
+import java.util.Hashtable;
 import java.util.Properties;
+import java.util.Vector;
 
 /**
  * @author valy
@@ -21,7 +25,7 @@
     public int onlineDecimalPlaces, ecrMinGrp, ecrMaxGrp, webServerPort;
 
     public String ecrExeFile, onlineItemsFile, onlineErrFile, onlineLogFile, onlineDirectory,
-            systemPrefix, expectedReply;
+            systemPrefix, expectedReply, fileNameTemplate, nonfiscalReceiptLocation;
 
     public boolean bonNumbering;
 
@@ -31,6 +35,20 @@
 
     protected NonPrintedBonInterface inter;
 
+    protected boolean forceF = false;
+
+    protected boolean multipleTipPlataSupported = true;
+
+    protected Hashtable<String,String> paymentTypes;
+
+    public boolean isForceF() {
+        return forceF;
+    }
+
+    public void setForceF(boolean forceF) {
+        this.forceF = forceF;
+    }
+
     public void setLicenseRequired(boolean licenseRequired) {
         this.licenseRequired = licenseRequired;
     }
@@ -58,6 +76,23 @@
         expectedReply = conf.getProperty("expectedReply");
 
         webServerPort = Integer.parseInt(conf.getProperty("webServerPort", "8080"));
+
+        fileNameTemplate= conf.getProperty("fileNameTemplate");
+
+        nonfiscalReceiptLocation = conf.getProperty("nonfiscalReceiptLocation");
+
+
+        paymentTypes = new Hashtable();
+        String paymentTypesString = conf.getProperty("paymentTypes", "Cash");
+        Vector types = Utils.splitString(paymentTypesString, ',');
+        for (int i = 0; i < types.size(); i++) {
+            String type =  (String)types.elementAt(i);
+            String value = conf.getProperty("paymentType_" + type, "");
+            type = type.toUpperCase();
+            paymentTypes.put(type, value);
+        }
+
+        Logger.logInfo(this, "table = "+paymentTypes);
     }
 
     public AbstractCashRegister() {
@@ -72,12 +107,23 @@
         if(Validators.correctString(ecrExeFile))
             command = systemPrefix + " " + ecrExeFile;
         this.pt = new EcrPrintingThread(onlineDirectory, command, onlineItemsFile, onlineLogFile, onlineErrFile,
-                bonNumbering, expectedReply );
+                bonNumbering, expectedReply, fileNameTemplate );
         this.pt.setName("EcrPrintingThread");
         this.pt.start();
+
+
+        if(nonfiscalReceiptLocation != null) {
+            new NonFiscalReceiptPrintingThread(nonfiscalReceiptLocation, this);
+        }
+
+
         return true;
     }
 
+    public void printNonFiscalBon(String inputFile) {
+
+    }
+
     public String getDepartament(EcrSale newsaleentry) {
         return newsaleentry.getDepartament();
     }
@@ -133,11 +179,41 @@
     public void stopECR(){
     }
 
-    public void startECR(){
+    public void startECR() {
         
     }
 
-    public abstract void processXml(String fileName);
+    public void processXml(String fileName) {
+        try {
+            GenericXmlHandler handler = new GenericXmlHandler(getXmlHandlerInterface());
+            Utils.importXml(handler, fileName);
+
+            Vector<EcrSale> sales = handler.getSales();
+            Vector<EcrPlata> plati = handler.getPlati();
+            Vector<String> comments = handler.getComments();
+            float total = handler.getTotalSales();
+
+            String idBon = handler.getIdBon();
+            int idOrder = handler.getIdOrder();
+
+            printBonFiscal(sales, total, plati, null, comments, idBon, idOrder );
+
+        } catch (IOException e) {
+            Logger.logException(this, e);
+        } catch (SAXException e) {
+            Logger.logException(this, e);
+        } finally {
+        }
+    }
+
+    protected GenericXmlHandlerInterface getXmlHandlerInterface() {
+        return new GenericXmlHandlerInterface() {
+            @Override
+            public String getEcrPaymentCode(String paymentName) {
+                return paymentTypes.get(paymentName);
+            }
+        };
+    }
 
 
     public int getNoOfBonsToPrint() {
@@ -148,11 +224,19 @@
         
     }
 
+    public void setMultipleTipPlataSupported(boolean multipleTipPlataSupported) {
+        this.multipleTipPlataSupported = multipleTipPlataSupported;
+    }
+
     public boolean multiplePaymentTypesSupported() {
-        return true;
+        return multipleTipPlataSupported;
     }
 
     public void deleteBonByIdentifier(String identifier) {
 
     }
+
+    public boolean ecrConnectedAtStartup() {
+        return true;
+    }
 }
\ No newline at end of file
diff -r e6b80a8b200a src/ro/atreides/ecr/CashRegisterInterface.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/CashRegisterInterface.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,48 @@
+package ro.atreides.ecr;
+
+import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.EcrSale;
+import ro.atreides.utils.plati.TipPlata;
+import ro.atreides.utils.tricky.NonPrintedBonInterface;
+
+import java.util.Vector;
+
+/**
+ * @author valy
+ */
+public interface CashRegisterInterface {
+
+    /**
+     * @param sales
+     * @param total
+     * @param plati - null or empty if default ( cash )
+     */
+    public abstract void printBonFiscal(Vector<EcrSale> sales, float total, Vector<EcrPlata> plati, TipPlata cashDefault, Vector<String> comments, String orderIdentifier, int idOrder);
+
+    public abstract void printX() ;
+
+    public abstract void printZ() ;
+
+    public abstract void processBonFiscal(String file, String idBon, int idOrder);
+
+    public void introduNumerar(float numerar);
+
+    public boolean numerarInputReady();
+
+    public void forceTotal();
+
+    public int getNoOfBonsToPrint();
+
+    public void deleteNonPrintedBons();
+
+    public void setInter(NonPrintedBonInterface inter) ;
+
+    public boolean multiplePaymentTypesSupported();
+
+    public void deleteBonByIdentifier(String identifier);
+
+    public boolean isForceF();
+
+    public void setForceF(boolean forceF);
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/DummyCashRegister.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/DummyCashRegister.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,69 @@
+package ro.atreides.ecr;
+
+import ro.atreides.utils.plati.TipPlata;
+import ro.atreides.utils.tricky.NonPrintedBonInterface;
+
+import java.util.Vector;
+
+
+/**
+ * @author valy
+ */
+public class DummyCashRegister implements CashRegisterInterface {
+
+    public void printBonFiscal(Vector sales, float total, Vector plati,  TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
+        System.out.println("dummy : print bon fiscal");
+    }
+
+    public void printX() {
+    }
+
+    public void printZ() {
+    }
+
+
+    public void processBonFiscal(String file, String idBon, int idOrder) {
+        System.out.println("dummy: process bon fiscal");
+    }
+
+    public void introduNumerar(float numerar) {
+    }
+
+
+    public boolean numerarInputReady() {
+        return false;
+    }
+
+
+    public void forceTotal() {
+    }
+
+
+    public int getNoOfBonsToPrint() {
+        return 0;
+    }
+
+
+    public void deleteNonPrintedBons() {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void setInter(NonPrintedBonInterface inter) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+
+    public boolean multiplePaymentTypesSupported() {
+        return true;
+    }
+
+    public void deleteBonByIdentifier(String identifier) {
+    }
+
+    public boolean isForceF() {
+        return false;
+    }
+
+    public void setForceF(boolean forceF) {
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrDb.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/EcrDb.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,38 @@
+package ro.atreides.ecr;
+
+import java.sql.SQLException;
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 1/23/13
+ * Time: 7:24 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class EcrDb {
+    /*extends
+} DerbyPersistentFileManager {
+
+    public EcrDb(String dbName) throws Exception {
+        super(dbName, "eceredebe");
+    }
+
+
+
+    @Override
+    protected void createTables() throws SQLException {
+
+        //table bons : int id, orderIdentifier, source
+        //table products :
+
+        String bons = "create table ecr_bons();";
+        String bonItems = "create table ecr_bonitems();";
+
+        Vector<String> tableScript = new Vector<String>();
+
+        for (String s : tableScript) {
+            SqlUtils.executeUpdate(s, connection);
+        }
+    }*/
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrDialogUtils.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/EcrDialogUtils.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,124 @@
+package ro.atreides.ecr;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: andreic
+ * Date: Jul 23, 2009
+ * Time: 1:05:07 PM
+ */
+public class EcrDialogUtils {
+
+    public static JDialog getDialog(Component parent, Component panel, String title){
+        JDialog dialog = buildDialog(parent);
+        dialog.setTitle(title);
+        initDefaultDialog(dialog, panel, parent);
+        return dialog;
+    }
+
+    private static JDialog buildDialog(Component parent){
+        JDialog dialog = null;
+        if(parent != null){ // modal
+            dialog = new JDialog((JFrame)parent, true);
+        } else {
+            JFrame frame = null;
+            dialog = new JDialog(frame, true);
+        }
+
+        dialog.setModal(true);
+        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+        return dialog;
+    }
+
+    public static JDialog getDialog(Component panel, String title){
+        return getDialog(null, panel, title);
+    }
+
+    private static void initDefaultDialog(JDialog result, Component panel, Component parent){
+        result.setLayout(new GridBagLayout());
+        GridBagConstraints c = new GridBagConstraints();
+        c.fill = GridBagConstraints.BOTH;
+        c.insets = new Insets(2, 2, 2, 2);
+        c.weightx = 1;
+        c.weighty = 1;
+        c.gridheight = 1;
+        c.gridwidth = 1;
+        c.anchor = GridBagConstraints.CENTER;
+        c.gridy = 0;
+        c.gridx = 0;
+
+        result.add(panel, c);
+        result.pack();
+        result.setLocationRelativeTo( parent );
+    }
+
+
+    public static String choiseDialog(Component parent, Component p, String title, String[] buttons){
+        final String[] result = new String[1];
+
+        JPanel panel = new JPanel(new GridBagLayout());
+        final JDialog dialog = getDialog(parent, panel, title);
+
+        GridBagConstraints c = new GridBagConstraints();
+        c.fill = GridBagConstraints.BOTH;
+        c.anchor = GridBagConstraints.CENTER;
+        c.insets = new Insets(3,3,3,3);
+        c.weightx = 1;
+        c.weighty = 1;
+
+        c.gridx = 0;
+        c.gridy = 0;
+        panel.add( p, c );
+
+        c.gridy++;
+        c.weighty = 0;
+        CallBack callback = new CallBack() {
+            @Override
+            public void call(String name) {
+                result[0] = name;
+                dialog.dispose();
+            }
+        };
+        panel.add( buildButtonsPanel(buttons, callback), c );
+
+        dialog.pack();
+        dialog.setLocationRelativeTo(parent);
+        dialog.setResizable(false);
+        dialog.setVisible(true);
+
+        return result[0];
+    }
+
+    private static JPanel buildButtonsPanel(String[] buttons, final CallBack callback){
+        JPanel result = new JPanel(new GridBagLayout());
+        GridBagConstraints c = new GridBagConstraints();
+        c.fill = GridBagConstraints.NONE;
+        c.anchor = GridBagConstraints.CENTER;
+        c.insets = new Insets(2,2,2,2);
+        c.weightx = 1;
+        c.weighty = 1;
+
+        c.gridx = 0;
+        c.gridy = 0;
+        ActionListener listener = new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                callback.call(e.getActionCommand());
+            }
+        };
+        for (int i = 0; i < buttons.length; i++) {
+            JButton button = new JButton(buttons[i]);
+            button.addActionListener(listener);
+            result.add( button, c );
+            c.gridx++;
+        }
+        return result;
+    }
+
+    private abstract static class CallBack {
+        public abstract void call(String name);
+    }
+}
\ No newline at end of file
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrFactory.java
--- a/src/ro/atreides/ecr/EcrFactory.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/EcrFactory.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,6 +1,7 @@
 package ro.atreides.ecr;
 
 import ro.atreides.utils.Logger;
+import ro.atreides.utils.web.WebServerInterface;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -9,10 +10,15 @@
 
 public class EcrFactory {
 
+    public static Properties launcherProperties = null;
+
     private static String [] availableModels = new String [] {
             "datecs.Generic",
             "aclas.Generic",
+            "incotex.Generic",
+            "webxml.Generic",
             "datecs.NativeDP50",
+            "datecs.Fprint",
             "client.Generic",
             "sapel.Generic",
             "total.Generic",
@@ -29,19 +35,20 @@
             "carat.Prima",
             "mercury.Generic",
             "chd.Generic",
-            "rompos.Generic"};
+            "rompos.Generic",
+            "cashprn.Generic",
+            "xkube.Generic",
+            "optima.Generic"};
 
     /**
      *  posibil sa returneze null
      * @param ecrType
      */
-    public static AbstractCashRegister buildEcr(String ecrType, boolean licenceRequired) throws RuntimeException {
+    public static AbstractCashRegister buildEcr(String ecrType, boolean licenceRequired, WebServerInterface webServerInterface) throws RuntimeException {
 
         if(ecrType == null)
             return null;
 
-        String driverClass = "conf" + File.separator + "ecr" + File.separator + ecrType + ".properties";
-
         String realType = null;
         String allTypesString = "";
         for (int i = 0; i < availableModels.length; i++) {
@@ -56,20 +63,32 @@
             Logger.logException("EcrFactory", ex);
         }
 
+        if(launcherProperties == null) {
+            String driverClass = "conf" + File.separator + "ecr" + File.separator + ecrType + ".properties";
+
+            try {
+
+                Properties conf = new Properties();
+                conf.load(new FileInputStream( driverClass ));
+                launcherProperties = conf;
+
+            } catch (IOException e) {
+                RuntimeException ex = new RuntimeException("Fisierul " + driverClass + " este necesar. Contactati suportul tehnic");
+                Logger.logException("EcrFactory", ex);
+            }
+        }
+
         String packageName = "ro.atreides.ecr";
 
         AbstractCashRegister result = null;
         try {
             result = (AbstractCashRegister)Class.forName(packageName + "." + realType).newInstance();
-            Properties conf = new Properties();
-            conf.load(new FileInputStream( driverClass ));
-            result.buildConfiguration(conf);
+
+            result.buildConfiguration(launcherProperties);
             result.setLicenseRequired(licenceRequired);
+            result.setWebserver(webServerInterface);
             result.finishInitialize();
 
-        } catch (IOException e) {
-            RuntimeException ex = new RuntimeException("Fisierul " + driverClass + " este necesar. Contactati suportul tehnic");
-            Logger.logException("EcrFactory", ex);
         } catch (ClassNotFoundException e) {
             Logger.logException("EcrFactory", e);
         } catch (InstantiationException e) {
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrInterface.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/EcrInterface.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,54 @@
+package ro.atreides.ecr;
+
+import ro.atreides.ecr.datecs.nativeImpl.Product;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: andreic
+ * Date: Jun 30, 2009
+ * Time: 6:03:55 PM
+ */
+public interface EcrInterface {
+    public static final int RETRY = 0;
+    public static final int ANULARE = 1;
+    public static final int IGNORE = 2;
+
+    /**
+     * Ecr was not detected
+     * @return
+     * <li><code>RETRY</code> - to continue retrying
+     * <li><code>IGNORE</code> - to stop detecting and close ecr
+     */
+    public int ecrNotPresent();
+
+    /**
+     * Called when ecr refuses to print product.
+     * <p>
+     * <br>There are only 2 possible causes for this, in that order:
+     * <br>1) ecr register is full, perform Z (in this case make sure to return <code>RETRY</code>).
+     * <br>if not then its guaranted to be the second:
+     * <br>2) product is not well formatted, or order in wich it's printed is wrong
+     *
+     * @param p product
+     * @return
+     * <li><code>RETRY</code> - to retry again (should be called in case 1, in case 2 it will not help)
+     * <li><code>IGNORE</code> - to ignore printing current product, print the next one
+     * <li><code>ANULARE</code> - anuleaza tot bonul
+     */
+    public int failedPrint(Product p);
+
+    /**
+     * Ecr was not detected
+     * @return
+     * <li><code>RETRY</code> - to continue retrying
+     * <li><code>IGNORE</code> - to stop detecting and close ecr
+     */
+    public int ecrRemoved();
+
+    
+    public void ecrConnected();
+
+    public boolean isErrorNotifications() ;
+
+    public void setErrorNotifications(boolean errorNotifications) ;
+}
\ No newline at end of file
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrInterfaceImpl.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/EcrInterfaceImpl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,109 @@
+package ro.atreides.ecr;
+
+import ro.atreides.ecr.datecs.nativeImpl.Product;
+import ro.atreides.utils.gui.GuiUtils;
+import ro.atreides.utils.Logger;
+
+import javax.swing.*;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: andreic
+ * Date: Jul 3, 2009
+ * Time: 6:26:31 PM
+ */
+public class EcrInterfaceImpl implements EcrInterface {
+
+    private boolean errorNotifications;
+
+    public boolean isErrorNotifications() {
+        return errorNotifications;
+    }
+
+    public void setErrorNotifications(boolean errorNotifications) {
+        this.errorNotifications = errorNotifications;
+    }
+
+    public int ecrNotPresent() {
+        try {
+            EcrLogic.getInstance().ecrConnected(false);
+        } catch (NullPointerException e){
+            Logger.logException( this, e );
+        }
+
+        if(errorNotifications) {
+            return ecrNotPresent("<html><font color=red size=5>Casa nu a fost detectata!</font>" +
+                    "<br>Verificati:" +
+                    "<font color=blue><br>1) Casa este conectata la calculator" +
+                    "<br>2) Casa este in modul vanzare" +
+                    "<br>3) Scoateti Z (golire)</font></html>");
+        } else return RETRY;
+    }
+
+    public int failedPrint(Product p) {
+        if(errorNotifications) {
+            JLabel message = new JLabel("<html><font color=red size=4>Produsul </font><font color=blue>"+p+"</font>" +
+                    "<font color=red size=4> nu a fost tiparit.</font>" +
+                    "<br>Cauze posibile:" +
+                    "<br>1) format incorect" +
+                    "<br>2) Z nu a fost scos</html>");
+
+            String[] buttons = {"Retipareste produs", "Continua fara acest produs", "Anuleaza intregul bon"};
+
+            String result = EcrDialogUtils.choiseDialog(GuiUtils.currentFrame, message, "Atentie", buttons);
+
+            if(result == null){
+                return RETRY;
+            } else if(result.equals(buttons[0])){
+                return RETRY;
+            } else if(result.equals(buttons[1])){
+                return IGNORE;
+            } else if(result.equals(buttons[2])){
+                return ANULARE;
+            } else {
+                return RETRY;
+            }
+        } else return RETRY;
+    }
+
+    public int ecrRemoved() {
+        try {
+            EcrLogic.getInstance().ecrConnected(false);
+        } catch (NullPointerException e){
+            Logger.logException( this, e );
+        }
+
+        if(errorNotifications) {
+
+            return ecrNotPresent("<html><font color=red size=5>Casa este deconectata!</font>" +
+                    "<br>Verificati:" +
+                    "<font color=blue><br>1) Casa este conectata la calculator" +
+                    "<br>2) Casa este in modul vanzare" +
+                    "<br>3) Scoateti Z (golire)</font></html>");
+        } else return RETRY;
+    }
+
+    private int ecrNotPresent(String comment){
+        try {
+            EcrLogic.getInstance().ecrConnected(false);
+        } catch (NullPointerException e){
+            Logger.logException( this, e );
+        }
+
+        if(errorNotifications) {
+
+            JLabel message = new JLabel(comment);
+            String[] buttons = {"Incearca din nou"};
+            EcrDialogUtils.choiseDialog(GuiUtils.currentFrame, message, "Atentie", buttons);
+            return RETRY;
+        } else return RETRY;
+    }
+
+    public void ecrConnected() {
+        try {
+            EcrLogic.getInstance().ecrConnected(true);
+        } catch (NullPointerException e){
+            Logger.logException( this, e );
+        }
+    }
+}
\ No newline at end of file
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrLogic.java
--- a/src/ro/atreides/ecr/EcrLogic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/EcrLogic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,6 +1,7 @@
 package ro.atreides.ecr;
 
 import ro.atreides.utils.Utils;
+import ro.atreides.utils.web.WebServerInterface;
 
 public class EcrLogic {
 
@@ -12,16 +13,16 @@
 
     public static final String ECR_NOT_CONNECTED = "CASA DE MARCAT DECONECTATA";
 
-    private EcrLogic(String ecrType, boolean licenceRequired) {
-        ecr = EcrFactory.buildEcr(ecrType, licenceRequired);
+    private EcrLogic(String ecrType, boolean licenceRequired, WebServerInterface webserver) {
+        ecr = EcrFactory.buildEcr(ecrType, licenceRequired, webserver);
         if(ecr != null) {
             ecr.start();
         }
     }
 
-    public static synchronized EcrLogic getInstance(String [] args, boolean licenseRequired) {
+    public static synchronized EcrLogic getInstance(String [] args, boolean licenseRequired, WebServerInterface webserver) {
         String ecrType = Utils.getCmdlineValue("-ecrType", args, null);
-        instance = new EcrLogic(ecrType, licenseRequired);
+        instance = new EcrLogic(ecrType, licenseRequired, webserver);
         return instance;
     }
 
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrMain.java
--- a/src/ro/atreides/ecr/EcrMain.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/EcrMain.java	Fri Sep 13 19:21:02 2013 +0300
@@ -23,7 +23,7 @@
         Logger.getInstance(Logger.DEBUG, "ecr.log");
 
         String file = Utils.getCmdlineValue("-file", args, "");
-        EcrLogic reader = EcrLogic.getInstance(args, true);
+        EcrLogic reader = EcrLogic.getInstance(args, true, null);
 
         AbstractCashRegister cashRegister = reader.getEcr();
 
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrPrintingThread.java
--- a/src/ro/atreides/ecr/EcrPrintingThread.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/EcrPrintingThread.java	Fri Sep 13 19:21:02 2013 +0300
@@ -3,6 +3,7 @@
 import ro.atreides.utils.FileUtils;
 import ro.deversoft.utils.noarch.Formatters;
 import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
 import ro.atreides.utils.gui.GuiUtils;
 import ro.atreides.utils.gui.Validators;
 import ro.atreides.utils.gui.dialogs.DialogUtils;
@@ -34,11 +35,13 @@
 
     private String okAnswer;
 
+    private String fileNameTemplate;
+
 //    public EcrPrintingThread() {
 //    }
 
     public EcrPrintingThread(String directory, String exec, String itemsFile, String onlineLogFile, String onlineErrFile,
-                             boolean bonNumbering, String okAnswer) {
+                             boolean bonNumbering, String okAnswer, String fileNameTemplate) {
         this.dir = new File(directory);
         this.exec = exec;
         this.itemsFile = itemsFile;
@@ -46,6 +49,7 @@
         this.err = onlineErrFile;
         this.bonNumbering = bonNumbering;
         this.okAnswer = okAnswer;
+        this.fileNameTemplate = fileNameTemplate;
         try {
             File dir = new File(directory);
             if(!dir.exists())
@@ -103,7 +107,12 @@
                 }
                 String outFile = this.itemsFile;
                 if(bonNumbering) {
-                    outFile = nrBon + this.itemsFile;
+                    if(fileNameTemplate != null) {
+                        String fileSystemFriendly = Utils.getStringMaxSize(5, nrBon +"", '0', true);
+                        outFile = fileNameTemplate.replaceAll("%%nrbon%%", fileSystemFriendly);
+                    } else {
+                        outFile = nrBon + this.itemsFile;
+                    }
                 }
 
                 File itemsFile = new File(directory.getAbsolutePath() + File.separator + outFile);
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrSale.java
--- a/src/ro/atreides/ecr/EcrSale.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/EcrSale.java	Fri Sep 13 19:21:02 2013 +0300
@@ -17,6 +17,16 @@
     private String departament, codTva;
     private int grupa;
 
+    private float returPending;
+
+    public float getReturPending() {
+        return returPending;
+    }
+
+    public void setReturPending(float returPending) {
+        this.returPending = returPending;
+    }
+
     public static final long serialVersionUID = -8871460794490181402L;
 
 
@@ -32,6 +42,8 @@
         this.ppuOriginal = ppuOriginal;
         this.discount = discount;
         this.cotaTva = cotaTva;
+
+        this.setReturPending(Math.abs(ppuDupaDiscount * quantity));
     }
 
     public float getCotaTva() {
diff -r e6b80a8b200a src/ro/atreides/ecr/EcrUtils.java
--- a/src/ro/atreides/ecr/EcrUtils.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/EcrUtils.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,9 +1,15 @@
 package ro.atreides.ecr;
 
+import ro.atreides.utils.Constants;
 import ro.atreides.utils.FloatUtils;
 import ro.atreides.utils.Logger;
+import ro.atreides.utils.plati.Plata;
 
 import java.security.MessageDigest;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Vector;
 
 /**
  * Created by IntelliJ IDEA.
@@ -76,4 +82,39 @@
         }
         return false;
     }
+
+    public static EcrPlata getEcrPlata(Plata p) {
+
+        EcrPlata plata = new EcrPlata();
+        plata.setEcrMapping(p.getEcrMapping());
+        plata.setSuma(FloatUtils.roundFloat(p.getSuma(), Constants.DECIMAL_SCALE));
+        plata.setTipPlata(p.getTipPlata());
+
+        return plata;
+    }
+
+    /**
+     * Converteste dintro clasa in alta
+     */
+    public static Vector<EcrPlata> getEcrPlati(Vector<Plata> plati) {
+        Vector result = new Vector();
+        for (Iterator iter = plati.iterator(); iter.hasNext();) {
+            Plata p = (Plata) iter.next();
+            EcrPlata plata = getEcrPlata(p);
+            result.add(plata);
+        }
+
+        Collections.sort(result, new Comparator() {
+
+            public int compare(Object o1, Object o2) {
+                EcrPlata p1 = (EcrPlata) o1;
+                EcrPlata p2 = (EcrPlata) o2;
+                if (p1.isDefault()) return 1;
+                if (p2.isDefault()) return -1;
+                return p1.getTipPlata().compareToIgnoreCase(p2.getTipPlata());
+            }
+        });
+
+        return result;
+    }
 }
diff -r e6b80a8b200a src/ro/atreides/ecr/GenericXmlHandler.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/GenericXmlHandler.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,155 @@
+package ro.atreides.ecr;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+import ro.atreides.utils.Constants;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 7/24/13
+ * Time: 9:34 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class GenericXmlHandler extends DefaultHandler {
+
+    private Vector<EcrSale> sales = new Vector<EcrSale>();
+    private Vector<EcrPlata> plati = new Vector<EcrPlata>();
+    private Vector<String> comments = new Vector<String>();
+
+    private String idBon = "";
+    private int idOrder = Constants.NULL_VALUE;
+
+    private float totalSales = 0;
+    private float totalPlati = 0;
+
+    private GenericXmlHandlerInterface inter;
+
+    public GenericXmlHandler(GenericXmlHandlerInterface inter) {
+        this.inter = inter;
+    }
+
+    public void startElement(String uri, String qName, String localName, Attributes attributes) throws SAXException {
+
+        if(qName.equalsIgnoreCase("product")) {
+
+            String product = attributes.getValue("label");
+            String priceS = attributes.getValue("price");
+            String priceOriginalS = attributes.getValue("priceOriginal");
+            String qS = attributes.getValue("quantity");
+
+            String vatCode = attributes.getValue("vat");
+            String vatRateS = attributes.getValue("vatRate");
+
+            int cod = Integer.parseInt(attributes.getValue("productCode"));
+            String dept= attributes.getValue("department");
+            int grupa = Integer.parseInt(attributes.getValue("group"));
+
+            float q = Float.parseFloat(qS);
+
+            float vatRate = Float.parseFloat(vatRateS);
+
+            float ppuDupaDiscount = Float.parseFloat(priceS);
+            float ppuOriginal = Float.parseFloat(priceOriginalS);
+            float discount = ppuOriginal-ppuDupaDiscount;
+
+            EcrSale sale = new EcrSale(product, q, ppuDupaDiscount, ppuOriginal,discount, cod, dept, grupa, vatCode, vatRate );
+
+            sales.add(sale);
+
+        } else if(qName.equalsIgnoreCase("ad")){
+
+            String text = attributes.getValue("text");
+            if(text==null || text.length() == 0)
+                text = " ";
+
+            comments.add(text);
+
+        } else if(qName.equalsIgnoreCase("discount")){
+            attributes.getValue("percent");
+
+            //todo nu prea sunt folosite la modul general
+
+        } else if(qName.equalsIgnoreCase("adaos")){
+            attributes.getValue("percent");
+
+            //todo nu prea sunt folosite la modul general
+
+        } else if(qName.equalsIgnoreCase("payment")){
+
+            String type = attributes.getValue("type");
+            type = type.toUpperCase();
+            String codCasa = (String) inter.getEcrPaymentCode(type);
+            String valueS = attributes.getValue("amount");
+
+            float value = Float.parseFloat(valueS);
+
+            EcrPlata plata = new EcrPlata();
+            plata.setEcrMapping(codCasa);
+            plata.setSuma(value);
+            plata.setTipPlata(type);
+
+            plati.add(plata);
+
+        } else if(qName.equalsIgnoreCase("receipt")){
+
+            idBon = attributes.getValue("bonId");
+            idOrder = Integer.parseInt(attributes.getValue("idOrder"));
+
+            totalSales = 0;
+            totalPlati = 0;
+
+            sales.clear();
+            plati.clear();
+            comments.clear();
+
+        }
+    }
+
+    @Override
+    public void endElement(String uri, String localName, String qName) throws SAXException {
+
+        if(qName.equalsIgnoreCase("receipt")) {
+
+            if(totalPlati < totalSales) {
+
+            }
+
+            idBon = "";
+            idOrder = Constants.NULL_VALUE;
+        }
+    }
+
+
+    public int getIdOrder() {
+        return idOrder;
+    }
+
+    public Vector<String> getComments() {
+        return comments;
+    }
+
+    public String getIdBon() {
+        return idBon;
+    }
+
+    public Vector<EcrPlata> getPlati() {
+        return plati;
+    }
+
+    public float getTotalPlati() {
+        return totalPlati;
+    }
+
+    public Vector<EcrSale> getSales() {
+        return sales;
+    }
+
+    public float getTotalSales() {
+        return totalSales;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/GenericXmlHandlerInterface.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/GenericXmlHandlerInterface.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,16 @@
+package ro.atreides.ecr;
+
+import java.util.Hashtable;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 7/24/13
+ * Time: 2:31 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface GenericXmlHandlerInterface {
+
+    public String getEcrPaymentCode(String paymentName);
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/NonFiscalReceiptPrintingThread.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/NonFiscalReceiptPrintingThread.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,51 @@
+package ro.atreides.ecr;
+
+import ro.atreides.utils.FileUtils;
+import ro.atreides.utils.Logger;
+
+import java.io.File;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 11/28/12
+ * Time: 11:46 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class NonFiscalReceiptPrintingThread extends Thread {
+
+    private String nonfiscalReceiptLocation;
+
+    private long sleep = 100;
+
+//    private EcrPrintingThread pt;
+
+    private AbstractCashRegister ecr;
+
+    public NonFiscalReceiptPrintingThread(String nonfiscalReceiptLocation, AbstractCashRegister ecr) {
+        this.nonfiscalReceiptLocation = nonfiscalReceiptLocation;
+//        this.pt = pt;
+
+        this.ecr = ecr;
+
+        setName("NonFiscalReceiptPrintingThread");
+        start();
+    }
+
+    public void run() {
+        while(true) {
+            try {
+                File f = new File(nonfiscalReceiptLocation);
+                if(f.exists()) {
+                    ecr.printNonFiscalBon(nonfiscalReceiptLocation);
+                }
+                try {
+                    Thread.sleep(sleep);
+                } catch (InterruptedException e) {
+                }
+            } catch (Throwable th) {
+                th.printStackTrace();
+            }
+        }
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/SerialDriverInterfaceImpl.java
--- a/src/ro/atreides/ecr/SerialDriverInterfaceImpl.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/SerialDriverInterfaceImpl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,6 +1,5 @@
 package ro.atreides.ecr;
 
-import ro.atreides.ecr.datecs.nativeImpl.EcrDialogUtils;
 import ro.atreides.utils.gui.GuiUtils;
 import ro.atreides.utils.Logger;
 
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/AclasDefaultImpl.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/AclasDefaultImpl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,170 @@
+package ro.atreides.ecr.aclas;
+
+import gnu.io.CommPortIdentifier;
+import gnu.io.PortInUseException;
+import gnu.io.SerialPort;
+import gnu.io.UnsupportedCommOperationException;
+import ro.atreides.ecr.EcrLogic;
+import ro.atreides.ecr.aclas.noarch.AclasImpl;
+import ro.atreides.ecr.aclas.noarch.AclasPersistentList;
+import ro.atreides.ecr.datecs.nativeImpl.PortSettings;
+import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
+import ro.atreides.utils.gui.GuiUtils;
+import ro.atreides.utils.gui.Validators;
+import ro.atreides.utils.gui.dialogs.DialogUtils;
+import ro.atreides.utils.multilang.LangRoAll;
+import ro.atreides.utils.tricky.NonPrintedBonInterface;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 8/27/13
+ * Time: 3:01 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class AclasDefaultImpl extends AclasImpl {
+
+    private Socket socket;
+    private SerialPort serialPort;
+
+    public AclasDefaultImpl(String port) {
+        super(port);
+    }
+
+    @Override
+    protected void logException(Exception e) {
+        Logger.logException(this, e);
+    }
+
+    @Override
+    protected void logError(AclasImpl thiis, Object th) {
+        Logger.logError(this, th.toString());
+    }
+
+    @Override
+    protected AclasPersistentList getPersistentList() {
+        return new AclasPersistentListDefaultImpl(0);
+    }
+
+    @Override
+    protected void ecrConnected(boolean status) {
+        EcrLogic.getInstance().ecrConnected(status);
+    }
+
+    @Override
+    protected boolean connectSerial() throws IOException {
+        try {
+            int speed = 9600, dataBits = 8, stopBits = 1,parity = 0;
+
+            serialPort = null;
+
+            boolean portFound = false;
+            CommPortIdentifier portId = null;
+            Enumeration portList;
+
+            portList = CommPortIdentifier.getPortIdentifiers();
+            while (portList.hasMoreElements()) {
+                portId = (CommPortIdentifier) portList.nextElement();
+                if (portId.getName().equalsIgnoreCase(portName)) {
+                    portFound = true;
+                    break;
+                }
+            }
+            if (!portFound) {
+                DialogUtils.errorDialog(GuiUtils.currentFrame, driverName + ": port incorect : \"" + portName + "\"." +
+                        " Corectati si reporniti !!", LangRoAll.nuPotContinua);
+                return false;
+            }
+
+
+            PortSettings settings = new PortSettings();
+            settings.setName(portName);
+            settings.setSpeed(speed);
+            settings.setDataBits(dataBits);
+            settings.setStopBits(stopBits);
+            settings.setPariry(parity);
+
+            serialPort = (SerialPort) portId.open(driverName, 2000);
+
+            inS = serialPort.getInputStream();
+            outS = serialPort.getOutputStream();
+
+            serialPort.setSerialPortParams( settings.getSpeed(), settings.getDataBits(), settings.getStopBits(), settings.getPariry());
+
+            return true;
+        } catch (PortInUseException e) {
+            DialogUtils.errorDialog(GuiUtils.currentFrame, driverName + ": port ocupat : \"" + portName + "\" ." +
+                    "<br> Verificati ce aplicatii folosesc portul, SAU incercati mai tarziu, SAU restart", LangRoAll.nuPotContinua);
+        } catch (UnsupportedCommOperationException e) {
+            Logger.logException(this, e);
+        }
+
+        return false;
+    }
+
+    @Override
+    protected boolean connectTCP() {
+        try {
+            Vector<String> items = Utils.splitString(portName, '=');
+            if(items.size() < 3 || !Validators.correctString(items.get(1)) || !Validators.correctInteger(items.get(2))) {
+                Logger.logError(this, "Configurare incorecta . Eroare fatala!!");
+                Utils.systemExit();
+            }
+
+            String ip = items.get(1);
+            int port = Integer.parseInt(items.get(2));
+
+            socket = new Socket();
+            SocketAddress sa = new InetSocketAddress(ip, port);
+
+            socket.connect(sa);
+
+            inS = socket.getInputStream();
+            outS = socket.getOutputStream();
+
+            return true;
+        } catch (IOException e) {
+            Logger.logException(this, e);
+            return false;
+        }
+    }
+
+    @Override
+    protected void closeSocket() {
+        if(socket!=null) {
+            try {
+                socket.close();
+            } catch (IOException e) {
+            }
+        }
+    }
+
+    @Override
+    protected void closeSerialPort() {
+        if(serialPort != null) {
+            try {
+                serialPort.close();
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    @Override
+    protected void errorDialog(String message, String title) {
+        DialogUtils.errorDialog(GuiUtils.currentFrame, message, title);
+    }
+
+    public void deleteNonPrintedBons(NonPrintedBonInterface inter) {
+        outQueue.clear();
+    }
+
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/AclasLogger.java
--- a/src/ro/atreides/ecr/aclas/AclasLogger.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/aclas/AclasLogger.java	Fri Sep 13 19:21:02 2013 +0300
@@ -2,7 +2,6 @@
 
 import ro.atreides.ecr.EcrLogger;
 import ro.atreides.ecr.SerialUtils;
-import ro.atreides.ecr.optimus.nativeImpl.Logger;
 import ro.deversoft.utils.noarch.Formatters;
 import ro.atreides.utils.FileUtils;
 import ro.atreides.utils.ZipUtils;
@@ -21,7 +20,7 @@
  * Time: 12:17:15 AM
  */
 
-public class AclasLogger extends EcrLogger {
+class AclasLogger extends EcrLogger {
     private String dir;
     private Date date;
     private StringBuffer buffer = new StringBuffer();
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/AclasPersistentListDefaultImpl.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/AclasPersistentListDefaultImpl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,30 @@
+package ro.atreides.ecr.aclas;
+
+import ro.atreides.ecr.aclas.noarch.AclasPersistentList;
+import ro.atreides.ecr.aclas.noarch.Bon;
+import ro.atreides.utils.FileUtils;
+
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 8/27/13
+ * Time: 2:57 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class AclasPersistentListDefaultImpl extends AclasPersistentList {
+
+    public AclasPersistentListDefaultImpl(int id) {
+        super(id);
+    }
+
+    protected void setProductsFor(Vector<Bon> products, String file){
+        FileUtils.writeObjectTo(products, file, "AclasPersistentList");
+    }
+
+    protected Vector<Bon> getProductsFor(String file){
+        Object list = FileUtils.readObjectFrom(file, "AclasPersistentList");
+        return (Vector) list;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/Generic.java
--- a/src/ro/atreides/ecr/aclas/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/aclas/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,12 +1,22 @@
 package ro.atreides.ecr.aclas;
 
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 import ro.atreides.ecr.AbstractCashRegister;
 import ro.atreides.ecr.EcrSale;
 import ro.atreides.ecr.EcrPlata;
-import ro.atreides.ecr.aclas.messages.*;
+import ro.atreides.ecr.aclas.noarch.AclasXmlHandler;
+import ro.atreides.ecr.aclas.noarch.Bon;
+import ro.atreides.ecr.aclas.noarch.messages.*;
+import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
+import ro.atreides.utils.gui.Validators;
 import ro.atreides.utils.plati.TipPlata;
 import ro.atreides.utils.multilang.LangRoAll;
 
+import java.io.IOException;
+import java.util.Hashtable;
 import java.util.Vector;
 import java.util.Properties;
 
@@ -16,12 +26,14 @@
  */
 public class Generic extends AbstractCashRegister {
 
-    AclasImpl driver;
+    AclasDefaultImpl driver;
 
     private boolean discountGlobal, errorNotifications, discountLaProdus;
 
     private String port;
 
+    private String defaultPayment = "";
+
     public void buildConfiguration(Properties conf) {
         super.buildConfiguration(conf);
 
@@ -29,13 +41,30 @@
         discountLaProdus = Boolean.parseBoolean(conf.getProperty("discountLaProdus", "false"));
         errorNotifications = Boolean.parseBoolean(conf.getProperty("errorNotifications", "true"));
 
-        port = conf.getProperty("ecrPort", "/dev/ttyUSB0");
 
+        defaultPayment = conf.getProperty("defaultPayment", "").toUpperCase();
+
+        Logger.logInfo(this, "table = " + paymentTypes + " defaultPayment : " + defaultPayment);
+
+        port = conf.getProperty("ecrPort", "/dev/ttyS0");
     }
 
 
+    @Override
     public void processXml(String fileName) {
-        //todo later
+        try {
+            AclasXmlHandler xmlHandler = new AclasXmlHandler(paymentTypes, defaultPayment);
+            Utils.importXml(xmlHandler, fileName);
+            processBon( xmlHandler.getReceipt() );
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (SAXException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void processBon(Bon b) {
+        driver.addBon(b);
     }
 
     private AclasMessageDiscount calculeazaProcentDiscount(float valoareOriginala, float discount, boolean discountGlobal) {
@@ -74,7 +103,7 @@
             }
 
             AclasMessageSaleProduct produs = new AclasMessageSaleProduct(price, sale.getQuantity(),
-                    sale.getProduct(), "", sale.getDepartament()); // todo support barcode
+                    sale.getProduct(), "", sale.getDepartament()); // todo use barcode for ID orders, sau alte NUMERE !!
             b.addProduct(produs);
 
             if(discountLaProdus) {
@@ -93,7 +122,6 @@
             }
         }
 
-
         float totalPlatit = 0;
         for(Object o : plati) {
             EcrPlata plata = (EcrPlata)o;
@@ -108,6 +136,8 @@
             b.addProduct(payment);
         }
 
+
+
         AclasMessageOpenDrawer drawer = new AclasMessageOpenDrawer();
         b.addProduct(drawer);
 
@@ -116,7 +146,6 @@
 
     public void printX() {
         Bon b = new Bon();
-//        b.addProduct(new AclasMessageAllVoid());
         b.addProduct(new AclasMessageXReport());
         driver.addBon(b);
     }
@@ -151,7 +180,7 @@
 
 
     public void startECR() {
-        driver = new AclasImpl(port);
+        driver = new AclasDefaultImpl(port);
         driver.setName("AclasImpl");
         driver.start();
     }
@@ -171,8 +200,9 @@
     public void forceTotal() {
     }
 
+    @Override
+    public boolean ecrConnectedAtStartup() {
+        return false;
+    }
 
-    public boolean multiplePaymentTypesSupported() {
-        return true;
-    }
 }
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/AclasImpl.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/AclasImpl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,446 @@
+package ro.atreides.ecr.aclas.noarch;
+
+import ro.atreides.ecr.aclas.noarch.messages.*;
+
+import java.util.Hashtable;
+import java.util.Vector;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 9:32:19 AM
+ */
+public abstract class AclasImpl extends Thread {
+
+    protected InputStream inS;
+    protected OutputStream outS;
+
+    protected String portName ;
+
+    private int sequence=0;
+
+    private Hashtable<Integer, AclasMessage> sentMessages = new Hashtable<Integer, AclasMessage>();
+
+    public static final String driverName = "aclas";
+
+    protected boolean mustRun = true ;
+
+    protected AclasPersistentList outQueue ;
+
+    private boolean connected;
+
+    protected AclasImpl(String port) {
+        this.portName = port;
+        outQueue = getPersistentList();
+    }
+
+    public boolean isConnected() {
+        return connected;
+    }
+
+    protected void setConnected(boolean connected) {
+        this.connected = connected;
+    }
+
+    public void addBon(Bon b) {
+        outQueue.addBon(b);
+    }
+
+    public void setMustRun(boolean mustRun) {
+        this.mustRun = mustRun;
+        this.connected = false;
+    }
+
+    private int getNextSeq() {
+        sequence ++;
+        if(sequence > 255)
+            sequence = 0;
+        return sequence;
+    }
+
+    private int getCurrentSeq() {
+        return sequence;
+    }
+
+    private void clearSeq() {
+        sequence = 0;
+    }
+
+    protected abstract AclasPersistentList getPersistentList() ;
+
+    protected abstract boolean connectSerial() throws IOException ;
+
+    protected abstract boolean connectTCP() ;
+
+    protected abstract void closeSerialPort() ;
+
+    protected abstract void closeSocket() ;
+
+    protected abstract void logException(Exception e) ;
+
+    protected abstract void logError(AclasImpl thiis, Object th);
+
+    protected abstract void ecrConnected(boolean status);
+
+    protected abstract void errorDialog(String message, String title);
+
+    public void run() {
+
+        if(AclasUtils.correctString(portName)) {
+            while(mustRun) {
+                try {
+
+                    try { Thread.sleep(500); } catch (InterruptedException e) { }
+
+                    if(portName.startsWith("tcp")) {
+                        if(!connectTCP())
+                            continue;
+                    } else {
+                        if(!connectSerial())
+                            continue;
+                    }
+
+                    tryToConnect();
+
+                    try { Thread.sleep(4500); } catch (InterruptedException e) { }
+
+                } catch(Exception e) {
+                    logException(e);
+                } catch ( Throwable th) {
+                    logError(this, th);
+                } finally {
+                    closeSocket();
+                    closeSerialPort();
+                }
+
+            }
+        } else {
+            errorDialog(driverName + ": port nedefinit. Corectati si reporniti !!", "Nu pot continua!");
+        }
+    }
+
+    private void tryToConnect() throws IOException {
+        int maxRetriesForConnect = 3;
+        connected = false;
+
+        while(maxRetriesForConnect > 0 && !connected && mustRun) {
+
+            AclasMessageCheckHardware checkH = new AclasMessageCheckHardware();
+            checkH.setPacketNo(getNextSeq());
+            sentMessages.put(checkH.getPacketNo(), checkH);
+            AClasMessageResponse checkHResp = null;
+
+            try {
+                checkHResp = write(checkH, outS, inS);
+            } catch (IOException e) {
+                logException(e);
+            }
+
+            if(checkHResp == null || checkHResp.isError()) {
+                ecrConnected(false);
+
+                emptyInputBuffer(5000);
+                maxRetriesForConnect --;
+
+
+                continue;
+            }
+
+            connected = true;
+        }
+
+        if(connected) {
+            ecrConnected(true);
+            sendBonIfAny();
+        } else {
+            errorDialog("Casa de marcat nefunctionala!!", "Verificati hartia, apoi efectuati Z, apoi Contactati suportul tehnic!!!");
+            return;
+        }
+    }
+
+    private boolean tryLogin() {
+        AclasMessage loginQuery = new AclasMessageClerkLogin();
+        loginQuery.setPacketNo(getNextSeq());
+        sentMessages.put(loginQuery.getPacketNo(), loginQuery);
+        AClasMessageResponse loginResp = null;
+
+        try {
+            loginResp = write(loginQuery, outS, inS);
+        } catch (IOException e) {
+            logException(e);
+        }
+
+        if(loginResp!=null) {
+            if(loginResp.isError()) {
+                //todo trateaza eroarea ! anunta userul ca nu e bine setat loginul in casa !!
+                System.out.println("eroare la login !");
+                return false;
+            } else return true;
+        } else {
+            //am avut un timeout !
+            return false;
+        }
+    }
+
+    private boolean voidPrevious() {
+        AclasMessageAllVoid allVoid = new AclasMessageAllVoid();
+        allVoid.setPacketNo(getNextSeq());
+        sentMessages.put(allVoid.getPacketNo(), allVoid);
+        AClasMessageResponse allVoidResp = null;
+
+        try {
+            allVoidResp = write(allVoid, outS, inS);
+        } catch (IOException e) {
+            logException(e);
+        }
+
+        if(allVoidResp == null || allVoidResp.isError()) {
+            return false;
+        }
+        return true;
+    }
+
+    private AclasMessageResponseCheckSoftware checkSoftwareStatus() {
+        //todo verificam daca casa este in mijlocul unui bon, sau daca are nevoie de ceva sa-i facem
+        AclasMessageCheckSoftware checkS = new AclasMessageCheckSoftware();
+        checkS.setPacketNo(getNextSeq());
+        sentMessages.put(checkS.getPacketNo(), checkS);
+        AclasMessageResponseCheckSoftware checkSResp = null;
+
+        try {
+            checkSResp = (AclasMessageResponseCheckSoftware)write(checkS, outS, inS);
+        } catch (IOException e) {
+            logException(e);
+        }
+
+        return checkSResp;
+    }
+
+    private boolean sendProduct(AclasMessage query) {
+        query.setPacketNo(getNextSeq());
+        sentMessages.put(query.getPacketNo(), query);
+        AClasMessageResponse resp = null;
+
+        try {
+            resp = write(query, outS, inS);
+        } catch (IOException e) {
+            logException(e);
+        }
+
+        if(resp == null || resp.isError()) {
+            return false;
+        }
+
+        return true;
+    }
+
+    private void sendBonIfAny() {
+
+        int maxErrorCountForProduct = 1;
+
+        while(mustRun && connected) {
+
+            if(outQueue.size() > 0) {
+
+                Bon bon = outQueue.get();
+                sentMessages.clear();
+
+                AclasMessageResponseCheckSoftware checkSoftware = checkSoftwareStatus();
+                if(checkSoftware==null) {
+                    return ;
+                }
+
+                if(checkSoftware.isReceiptOpen()) {
+                    voidPrevious();
+                    System.out.println("anulat bon nefinalizat INAINTE");
+                }
+
+                boolean loginOK = tryLogin();
+                if(!loginOK) return ;
+
+                boolean removeFromQueue = true;
+
+                boolean bonAnulat = false;
+
+                AclasMessage firstProduct = null;
+
+                Vector<AclasMessage> products = bon.get();
+                for (AclasMessage query : products) {
+
+                    if(firstProduct == null)
+                        firstProduct = query;
+
+                    if(query.getErrorCount() < maxErrorCountForProduct) {
+
+                        boolean productOK = sendProduct(query);
+                        if(!productOK) {
+                            //todo : pentru fiecare produs ar trebui sa stiu daca a fost tiparit corect sau nu ;
+                            //todo daca a dat eroare trebuie sa stiu ce eroare a dat, ca sa pot scrie la feedback !
+                            query.increaseErrorCount();
+                            removeFromQueue = false ;
+                            break;
+                        }
+                    } else {
+                        errorDialog("Produs Netiparit : '" + query.toString() + "' pe casa fiscala. Prea multe erori !", "Atentie");
+                        errorDialog("INTREGUL BON fiscal a fost anulat !!", "Atentie");
+                        bonAnulat = true;
+                        break;
+                    }
+
+                    try {
+                        Thread.sleep(50);
+                    } catch (InterruptedException e) {
+                    }
+                }
+
+                System.out.println("VERIFICARE DUPA BON");
+
+                checkSoftware = checkSoftwareStatus();
+                if(checkSoftware==null) {
+                    return ;
+                }
+
+                if(checkSoftware.isReceiptOpen()) {
+                    boolean voidOK = voidPrevious();
+                    System.out.println("anulare bon nefinalizat DUPA");
+                    if(firstProduct!=null) {
+                        firstProduct.increaseErrorCount();
+                    }
+                } else {
+                    //tiparit OK
+                    if(!bonAnulat) {
+                        int idBon = Integer.parseInt(checkSoftware.getNrBonFiscalCurent());//todo fa ceva cu asta
+                        System.out.println("IDBON : " + idBon);
+                    }
+                }
+
+                if(!removeFromQueue) {
+                    return ;
+                }
+
+                outQueue.remove(bon);
+            } else {
+                try { Thread.sleep(100); } catch (InterruptedException e) { }
+            }
+        }
+
+    }
+
+    private AClasMessageResponse write(AclasMessage toWrite, OutputStream outS, InputStream inS) throws IOException {
+        byte [] stream = toWrite.getBytes();
+        //todo
+//        System.out.println(Formatters.FULL_TIMESTAMP.format(new Date()) + " Class: " + toWrite.getClass().getName() + " Write: " + TextUtils.getHexString(stream, true) + "||");
+//        System.out.flush();
+        outS.write(stream);
+        outS.flush();
+        AClasMessageResponse mess = getReponse(inS, 5000);
+        return mess;
+    }
+
+    private void emptyInputBuffer(long readTimeout) throws IOException {
+        int toRead = 0;
+        long start = System.currentTimeMillis();
+        while ( toRead > 0 && System.currentTimeMillis() < start + readTimeout) {
+            try { Thread.sleep(100); } catch (InterruptedException e) { }
+            inS.read();
+            toRead = inS.available();
+        }
+    }
+
+    private AClasMessageResponse getReponse(InputStream inS, long readTimeout) throws IOException {
+
+        long start = System.currentTimeMillis();
+
+        int toRead = 0;
+        while ( toRead <= 0 && System.currentTimeMillis() < start + readTimeout) {
+            try { Thread.sleep(100); } catch (InterruptedException e) { }
+            toRead = inS.available();
+        }
+
+        if(toRead <= 0)
+            return null;
+
+        //avem ceva
+        int ch = 0;
+        while(ch != 0xC0 && toRead > 0 ) {
+            //skip pana la inceputul unui pachet
+            ch = inS.read();
+            toRead = inS.available();
+        }
+
+        int i = 0;
+        boolean packetfound = false;
+        byte [] buffer = new byte[65535];
+        if(ch == 0xC0) {
+            //avem un inceput de pachet
+            buffer[0] = (byte)ch;
+
+            //citim pana la sf pachetului
+            ch = 0;
+            long endOfPacketTimeout = 10 * readTimeout;
+            start = System.currentTimeMillis();
+            i++;
+
+            while(System.currentTimeMillis() < start + endOfPacketTimeout) {
+                toRead = inS.available();
+                if(toRead > 0) {
+                    ch = inS.read();
+//                    System.out.println("Am citit : " + (char) ch);
+                    buffer[i] = (byte)ch;
+                    i++;
+                    if(ch == 0xC0) {
+                        packetfound = true;
+                        break;
+                    }
+                } else {
+                    try { Thread.sleep(100); } catch (InterruptedException e) { }
+                }
+            }
+        }
+
+        byte [] buffer2 = new byte[i];
+
+        System.arraycopy(buffer, 0, buffer2, 0, buffer2.length);
+        //todo
+//        System.out.println(Formatters.FULL_TIMESTAMP.format(new Date()) + " Read: " + TextUtils.getHexString(buffer2, true) + "||");
+        System.out.flush();
+
+
+        int responseSequence = buffer2[1];
+
+        AclasMessage originalMessage = sentMessages.get(responseSequence);
+
+        if(originalMessage==null) {
+            logError(this, "Message not found for sequence : " + responseSequence);
+            return null;
+        }
+
+        if(responseSequence != originalMessage.getPacketNo()) {
+            logError(this, "Secventa gresita : Original message seqence : " + originalMessage.getPacketNo() + " responseSequence : " + responseSequence);
+            return null;
+        }
+
+        if(originalMessage != null) {
+            if(originalMessage instanceof AclasMessageCheckHardware) {
+
+                return new AclasMessageResponseCheckHardware(buffer2);
+
+            } else if (originalMessage instanceof AclasMessageCheckSoftware) {
+
+                return new AclasMessageResponseCheckSoftware(buffer2);
+
+            }
+        }
+        return new AClasMessageResponse(buffer2);
+    }
+
+    public final int getNoOfBonsToPrint() {
+        return outQueue.size();
+    }
+
+
+}
+
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/AclasPersistentList.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/AclasPersistentList.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,92 @@
+package ro.atreides.ecr.aclas.noarch;
+
+import java.io.*;
+import java.util.Vector;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: valycozma
+ * Date: Jun 21, 2013
+ * Time: 1:58:50 PM
+ */
+public abstract class AclasPersistentList {
+
+    public String filename;
+    private Vector<Bon> products;
+
+    public AclasPersistentList(){
+        this(0);
+    }
+
+    public AclasPersistentList(int id){
+        filename = "_ecr_aclas_persistent_products_list_" + id ;
+
+        if(!new File(filename).exists()) {
+            products = new Vector<Bon>();
+            setProductsFor(products, filename);
+        } else {
+            products = getProductsFor(filename);
+        }
+    }
+
+    public synchronized void addBon(Bon bon) {
+        if(bon != null) {
+            products.add(bon);
+            setProductsFor(products, filename);
+        }
+    }
+
+    public synchronized void remove(Bon bon){
+        products.remove(bon);
+        setProductsFor(products, filename);
+    }
+
+    public synchronized Bon get(){
+        return products.get(0);
+    }
+
+    public synchronized int size(){
+        return products.size();
+    }
+
+    public synchronized void clear(){
+        products.clear();
+        setProductsFor(products, filename);
+    }
+
+    protected abstract Vector<Bon> getProductsFor(String file);
+
+    protected abstract void setProductsFor(Vector<Bon> products, String file);
+
+
+    //    public synchronized void removeByIdentifier(String identifier) {
+//        System.out.println("Searching for identifier " + identifier);
+//        for (Object product : products) {
+//            Bon b = (Bon)product;
+//            if(b.getOrderIdentifier().equals(identifier)) {
+//                System.out.println("gasit idenfier : " + identifier + " si sters!");
+//                products.remove(b);
+//                break;
+//            }
+//        }
+//        setProductsFor(products, filename);
+//    }
+//
+//    public synchronized void deleteNonPrintedBons(NonPrintedBonInterface inter) {
+//        Vector toRemove = new Vector();
+//        for (int i = 0; i < products.size(); i++) {
+//            Bon bon1 = (Bon)products.get(i);
+//            if(bon1.getIdOrder() > 0) {
+//                if(inter.processNonPrintedBon(bon1.getIdOrder())) {
+//                    toRemove.add(bon1);
+//                }
+//            }
+//        }
+//        for (int i = 0; i < toRemove.size(); i++) {
+//            Bon bon1 = (Bon) toRemove.elementAt(i);
+//            products.remove(bon1);
+//        }
+//        setProductsFor(products, filename);
+//    }
+
+}
\ No newline at end of file
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/AclasUtils.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/AclasUtils.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,99 @@
+package ro.atreides.ecr.aclas.noarch;
+
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 8/27/13
+ * Time: 3:23 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class AclasUtils {
+
+    public static boolean correctString(String toCheck) {
+        if(toCheck ==null || toCheck.trim().equals(""))
+            return false;
+        return true;
+    }
+
+    public static boolean correctInteger(String toCheck) {
+        if(correctString(toCheck)) {
+            try {
+                Integer.parseInt(toCheck);
+                return true;
+            } catch (NumberFormatException e) {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+
+    public static boolean correctFloat(String toCheck) {
+        if(correctString(toCheck)) {
+            try {
+                Float.parseFloat(toCheck);
+                return true;
+            } catch (NumberFormatException e) {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * trunchiaza un string la totalDigits ; daca fillChar != null, se apendeaza acest caracter pana se ajunge la totalDigits
+     * @param totalDigits
+     * @param toConvert
+     * @param fillChar
+     */
+    public static String getStringMaxSize(int totalDigits, String toConvert, Character fillChar, boolean before) {
+//        System.out.println("toConvert: \"" + toConvert + "\"" + " totalDigits " + totalDigits + " before : " + before);
+        if(toConvert == null)
+            toConvert = "";
+
+        if(toConvert.length() > totalDigits)
+            return toConvert.substring(0, totalDigits);
+        else if(toConvert.length() < totalDigits) {
+            String result = toConvert;
+            if(fillChar != null)
+                for(int i = toConvert.length() ; i < totalDigits ; i++) {
+                    if(before) {
+                        result = fillChar.charValue() + result;
+                    } else {
+                        result += fillChar.charValue();
+                    }
+                }
+            return result;
+        } else return toConvert;
+    }
+
+    public static long convertToLong(float toConvert, int scale) {
+        return Math.round( Math.pow(10, scale) * toConvert);
+    }
+
+    public static String getHexString(byte [] bytes, boolean spaced) {
+        StringBuffer buf = new StringBuffer();
+        for(int i = 0 ; i < bytes.length ; i++ ) {
+            short b = bytes[i];
+            if( b < 0 ) b+= 256;
+            buf.append(Integer.toHexString(b));
+            if(spaced)
+                buf.append(' ');
+        }
+        return buf.toString().toUpperCase();
+    }
+
+    public static Vector splitString(String toSplit, char separator) {
+        StringTokenizer token = new StringTokenizer(toSplit, "" + separator);
+        Vector result = new Vector();
+        while(token.hasMoreTokens()) {
+            String s = token.nextToken();
+            result.add(s);
+        }
+        return result;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/AclasXmlHandler.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/AclasXmlHandler.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,146 @@
+package ro.atreides.ecr.aclas.noarch;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+import ro.atreides.ecr.aclas.noarch.messages.*;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 8/27/13
+ * Time: 3:28 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class AclasXmlHandler extends DefaultHandler {
+
+    Bon b = null;
+
+    double totalSales;
+    double totalPlati;
+
+    protected Hashtable<String,String> paymentTypes;
+
+    protected Vector<AclasMessageFooterMessage> comments = new Vector<AclasMessageFooterMessage>();
+
+    private String defaultPayment;
+
+    public AclasXmlHandler(Hashtable<String, String> paymentTypes, String defaultPayment) {
+        this.paymentTypes = paymentTypes;
+        this.defaultPayment = defaultPayment;
+    }
+
+    public Bon getReceipt() {
+        return b;
+    }
+
+    private void addCommentsIfAny() {
+        if(comments.size() > 0) {
+//            b.addProduct(new AclasMessageSubtotal());
+            for (AclasMessageFooterMessage comment : comments) {
+                b.addProduct(comment);
+            }
+        }
+    }
+
+    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+
+        if(qName.equalsIgnoreCase("product")){
+            String name = attributes.getValue("label");
+            float price = Float.parseFloat( attributes.getValue("price") );
+            float priceOriginal = price;
+            String priceOrigS = attributes.getValue("priceOriginal");
+            if(AclasUtils.correctFloat(priceOrigS)) {
+                priceOriginal = Float.parseFloat(  priceOrigS );
+            }
+            float quantity = Float.parseFloat( attributes.getValue("quantity") );
+            String department = attributes.getValue( "department" );
+
+            AclasMessageSaleProduct produs = new AclasMessageSaleProduct(priceOriginal, quantity,
+                    name, "", department); // todo support barcode(?)
+            b.addProduct(produs);
+
+            totalSales += quantity * price;
+
+            if(price!=priceOriginal) {
+                boolean isMajorare = price>priceOriginal;
+                if(isMajorare) {
+                    float percent = (price-priceOriginal)/priceOriginal * 100;
+                    AclasMessageDiscount discount = new AclasMessageDiscount(false, percent, "MAJORARE", isMajorare );
+                    b.addProduct(discount);
+                } else {
+                    float percent = (priceOriginal-price)/priceOriginal * 100;
+                    AclasMessageDiscount discount = new AclasMessageDiscount(false, percent, "DISCOUNT", isMajorare );
+                    b.addProduct(discount);
+                }
+            }
+
+        } else if(qName.equalsIgnoreCase("payment")){
+
+//            addCommentsIfAny();
+
+            float amount = Float.parseFloat( attributes.getValue("amount") );
+
+            String type = attributes.getValue("type");
+            type = type.toUpperCase();
+            String codCasa = paymentTypes.get(type);
+
+            AclasMessagePayment payment = new AclasMessagePayment(codCasa, amount);
+            b.addProduct(payment);
+
+            totalPlati += amount;
+
+        } else if(qName.equalsIgnoreCase("ad")){
+
+            String text = attributes.getValue("text");
+            if(AclasUtils.correctString(text) && comments.size() < 2){
+//                AclasMessageDiscount discount = new AclasMessageDiscount(true, (float)0.001, text, false );
+//                comments.add(discount);
+
+                AclasMessageFooterMessage footer = new AclasMessageFooterMessage(comments.size() + 1, text);
+                comments.add(footer);
+            }
+
+        } else if(qName.equalsIgnoreCase("discount")){
+
+            float percent = Float.parseFloat( attributes.getValue("percent") );
+            AclasMessageDiscount discount = new AclasMessageDiscount(false, percent, "DISCOUNT", false );
+            b.addProduct(discount);
+
+        } else if(qName.equalsIgnoreCase("adaos")){
+
+            float percent = Float.parseFloat( attributes.getValue("percent") );
+            AclasMessageDiscount adaos = new AclasMessageDiscount(false, percent, "ADAOS", false );
+            b.addProduct(adaos);
+
+        } else if(qName.equalsIgnoreCase("receipt")){
+            String idBon = attributes.getValue("bonId");//todo ce fac cu asta ??
+            String idOrderS = attributes.getValue("idOrder");
+            int idOrder = Integer.parseInt(idOrderS);
+
+            b = new Bon(idOrder);
+            totalSales = 0;
+            totalPlati = 0;
+        }
+    }
+
+    public void endElement(String uri, String localName, String qName) throws SAXException {
+        if(qName.equalsIgnoreCase("receipt")){
+            if(totalPlati < totalSales) {
+                String cod = paymentTypes.get(defaultPayment);
+                if(cod != null) {
+                    b.addProduct(new AclasMessagePayment(cod, (float)(totalSales-totalPlati)));
+                }
+            }
+            AclasMessageOpenDrawer drawer = new AclasMessageOpenDrawer();
+
+            b.addProduct(drawer);
+
+            comments.clear();
+        }
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/Bon.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/Bon.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,57 @@
+package ro.atreides.ecr.aclas.noarch;
+
+import java.io.Serializable;
+import java.util.Vector;
+
+public class Bon implements Serializable{
+
+    private Vector produse = new Vector();
+
+    private String feedbackFile ;
+
+    private String feedbackUrl ;
+
+    private int idOrder;
+
+    public Bon(int idOrder){
+        this.idOrder = idOrder;
+    }
+
+    public Bon(){
+    }
+
+    public void addProduct(Object p){
+        if(p != null)
+            produse.add(p);
+    }
+
+    public Vector get(){
+        return produse;
+    }
+
+    public String toString() {
+        StringBuffer buffer = new StringBuffer("Bon {");
+        for (int i = 0; i < produse.size(); i++) {
+            buffer.append("\n\t" + produse.get(i));
+        }
+//        buffer.append("\n\tadaos all: " + adaosTotal + "%");
+        buffer.append("\n}");
+        return buffer.toString();
+    }
+
+    public String getFeedbackUrl() {
+        return feedbackUrl;
+    }
+
+    public void setFeedbackUrl(String feedbackUrl) {
+        this.feedbackUrl = feedbackUrl;
+    }
+
+    public String getFeedbackFile() {
+        return feedbackFile;
+    }
+
+    public void setFeedbackFile(String feedbackFile) {
+        this.feedbackFile = feedbackFile;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/Types.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/Types.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,17 @@
+package ro.atreides.ecr.aclas.noarch;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: andrei
+ * Date: May 4, 2010
+ * Time: 1:48:14 PM
+ */
+public enum Types {
+    NACK,
+    ACK,
+    ERROR,
+    END,
+    ENQUIRE,
+    PACKED,
+    NOTHING
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AClasMessageResponse.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AClasMessageResponse.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,60 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import ro.atreides.ecr.aclas.noarch.AclasUtils;
+
+/**
+ * Date: Nov 21, 2011
+ * Time: 8:29:33 PM
+ */
+public class AClasMessageResponse {
+
+    private int packetNo;
+
+    protected boolean error = false;
+
+    private String errorCodeHex = "";
+    private String errorCodeDecimal = "";
+
+    protected byte [] data ;
+
+    public AClasMessageResponse(byte  [] buffer ) {
+        packetNo = buffer[1];
+
+        int b4 = buffer[4];
+
+        error = b4 != 0x4f;
+
+        if(error) {
+            byte [] buffer2 = new byte[4];
+            System.arraycopy(buffer, 4, buffer2, 0, buffer2.length);
+            errorCodeDecimal = "" + new String(buffer2);
+            errorCodeHex = AclasUtils.getHexString(buffer2, true);
+
+            System.out.println("ERROR : '" + new String(buffer2) + "'");
+
+        } else if(buffer.length > 8) {
+            data = new byte[buffer.length - 6];
+            //57 bytes
+            System.arraycopy(buffer, 4, data, 0, data.length);
+
+            System.out.println(" RESPONSE DATA : " + AclasUtils.getHexString(data, true) + "||");
+        }
+    }
+
+
+    public String getErrorCodeDecimal() {
+        return errorCodeDecimal;
+    }
+
+    public String getErrorCodeHex() {
+        return errorCodeHex;
+    }
+
+    public boolean isError() {
+        return error;
+    }
+
+    public int getPacketNo() {
+        return packetNo;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessage.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessage.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,81 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import java.io.Serializable;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 9:32:45 AM
+ */
+public class AclasMessage implements Serializable {
+
+    protected String command;
+
+    protected int packetNo;
+
+    protected byte [] data;
+
+    private int errorCount = 0;
+
+    public void increaseErrorCount() {
+        errorCount ++;
+    }
+
+    public int getErrorCount() {
+        return errorCount;
+    }
+
+    public int getPacketNo() {
+        return packetNo;
+    }
+
+    public void setPacketNo(int packetNo) {
+        this.packetNo = packetNo;
+    }
+
+
+    public byte[] getData() {
+        return data;
+    }
+
+    public void setData(byte[] data) {
+        this.data = data;
+    }
+
+    public byte [] getBytes() {
+
+        int size = 10;
+        if(data != null) {
+            size += data.length;
+        }
+        byte [] result = new byte[size];
+
+
+        result[0] = (byte)0xC0;
+
+        result[1] = (byte)packetNo;
+
+        result[2] = (byte)0xAA; //170 in baza 10 ; 1010 1010 in baza 2 ; 10 10
+        result[3] = 0x55;
+
+        byte [] cmdBytes = command.getBytes();
+        System.arraycopy(cmdBytes, 0, result, 4, 2);
+
+        if(data != null)
+            System.arraycopy(data, 0, result, 6, data.length);
+
+        result[size - 3] = (byte)0xC0;
+        result[size - 2] = (byte)0xC0;
+        result[size - 1] = (byte)0xC0;
+
+        long checksum = 0;
+        for( int i = 0 ; i < size ; i++ ) {
+            checksum += result[i];
+        }
+        byte b = (byte)(checksum % 256);
+        result[size - 4] = (byte)(b ^ (byte)0xff);
+
+        return result;
+    }
+
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageAllVoid.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageAllVoid.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,14 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageAllVoid extends AclasMessage {
+
+    public AclasMessageAllVoid() {
+        command = "78";
+        //data is null
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageCheckHardware.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageCheckHardware.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,14 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageCheckHardware extends AclasMessage {
+
+    public AclasMessageCheckHardware() {
+        command = "85";
+        //data is null
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageCheckSoftware.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageCheckSoftware.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,13 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageCheckSoftware extends AclasMessage {
+
+    public AclasMessageCheckSoftware() {
+        command = "86";
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageClerkLogin.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageClerkLogin.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,20 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageClerkLogin extends AclasMessage {
+
+    //todo : ar fi interesant de setat cum trebuie astea, sa se faca rapoarte pe casa in functie de useri
+    public AclasMessageClerkLogin() {
+        command = "70";
+
+        data = new byte[4];
+        data[0] = (byte)'1';
+        data[1] = (byte)'0';
+        data[2] = (byte)'0';
+        data[3] = (byte)'0';
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageDiscount.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageDiscount.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,28 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import ro.atreides.ecr.aclas.noarch.AclasUtils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageDiscount extends AclasMessage {
+
+    public AclasMessageDiscount(boolean laSubtotal, float procent, String nume, boolean majorare) {
+        if(majorare)
+            command = "77";
+        else
+            command = "76";
+
+        String s = laSubtotal ? "1" : "0";
+
+        long x = AclasUtils.convertToLong(procent, 2);
+        String qS = AclasUtils.getStringMaxSize(4, "" + x, '0', true);
+        s += qS;
+
+        qS = AclasUtils.getStringMaxSize(32, nume, ' ', false);
+        s += qS;
+
+        data = s.getBytes();
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageDrawerCashEntry.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageDrawerCashEntry.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,46 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import ro.atreides.ecr.aclas.noarch.AclasUtils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageDrawerCashEntry extends AclasMessage {
+
+    public AclasMessageDrawerCashEntry(float suma) {
+        command = "83";
+
+        long x = AclasUtils.convertToLong(suma, 2);
+        String s = AclasUtils.getStringMaxSize(10, x + "", '0', true);
+        data = s.getBytes();
+    }
+
+    public static byte [] getTestMessage() {
+        byte [] test = new byte[20];
+
+        test[0] = (byte)0xC0;
+        test[1] = 0x28;
+        test[2] = (byte)0xAA;
+        test[3] = 0x55;
+        test[4] = 0x38;
+        test[5] = 0x33;
+        test[6] = 0x30;
+        test[7] = 0x30;
+        test[8] = 0x30;
+        test[9] = 0x30;
+        test[10] = 0x30;
+        test[11] = 0x35;
+        test[12] = 0x30;
+        test[13] = 0x30;
+        test[14] = 0x30;
+        test[15] = 0x30;
+        test[16] = (byte)0x88;
+        test[17] = (byte)0xC0;
+        test[18] = (byte)0xC0;
+        test[19] = (byte)0xC0;
+
+        return test;
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageDrawerCashPaid.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageDrawerCashPaid.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,46 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import ro.atreides.ecr.aclas.noarch.AclasUtils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageDrawerCashPaid extends AclasMessage {
+
+    public AclasMessageDrawerCashPaid(float suma) {
+        command = "84";
+
+        long x = AclasUtils.convertToLong(suma, 2);
+        String s = AclasUtils.getStringMaxSize(10, x + "", '0', true);
+        data = s.getBytes();
+    }
+
+    public static byte [] getTestMessage() {
+        byte [] test = new byte[20];
+
+        test[0] = (byte)0xC0;
+        test[1] = 0x28;
+        test[2] = (byte)0xAA;
+        test[3] = 0x55;
+        test[4] = 0x38;
+        test[5] = 0x33;
+        test[6] = 0x30;
+        test[7] = 0x30;
+        test[8] = 0x30;
+        test[9] = 0x30;
+        test[10] = 0x30;
+        test[11] = 0x35;
+        test[12] = 0x30;
+        test[13] = 0x30;
+        test[14] = 0x30;
+        test[15] = 0x30;
+        test[16] = (byte)0x88;
+        test[17] = (byte)0xC0;
+        test[18] = (byte)0xC0;
+        test[19] = (byte)0xC0;
+
+        return test;
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageFooter.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageFooter.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,24 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import ro.atreides.ecr.aclas.noarch.AclasUtils;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 6/20/13
+ * Time: 10:24 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class AclasMessageFooter extends AclasMessage {
+
+    public AclasMessageFooter(String line) {
+        command = "04";
+
+        String s = "1";//first line ; todo for second line
+
+        s += AclasUtils.getStringMaxSize(32, line, null, false);
+
+        data = s.getBytes();
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageFooterMessage.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageFooterMessage.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,18 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import ro.atreides.ecr.aclas.noarch.AclasUtils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageFooterMessage extends AclasMessage {
+
+    public AclasMessageFooterMessage(int lineNr, String line1) {
+        command = "04";
+
+        String s = "" + lineNr;
+        s += AclasUtils.getStringMaxSize(32, line1, ' ', false);
+        data = s.getBytes();
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageOpenDrawer.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageOpenDrawer.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,14 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageOpenDrawer extends AclasMessage {
+
+    public AclasMessageOpenDrawer() {
+        command = "88";
+        //data is null
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessagePaperFeed.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessagePaperFeed.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,16 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessagePaperFeed extends AclasMessage {
+
+    public AclasMessagePaperFeed() {
+        command = "82";
+
+        data = new byte[1];
+        data[0] = 0;
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessagePayment.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessagePayment.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,27 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import ro.atreides.ecr.aclas.noarch.AclasUtils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessagePayment extends AclasMessage {
+
+    public AclasMessagePayment(String tipPlata, float suma) {
+        command = "81";
+
+        String s = "";
+
+        s += AclasUtils.getStringMaxSize(1, tipPlata, '0', true);
+
+        long x = AclasUtils.convertToLong(suma, 2);
+        String qS = AclasUtils.getStringMaxSize(11, x+"", '0', true);
+
+        s += qS;
+
+        data = s.getBytes();
+    }
+
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageResponseCheckHardware.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageResponseCheckHardware.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,32 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 6/20/13
+ * Time: 2:02 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class AclasMessageResponseCheckHardware extends AClasMessageResponse {
+
+    public AclasMessageResponseCheckHardware(byte[] buffer) {
+        super(buffer);
+        if(!error) {
+            //todo fill in rest of the fields
+            //4F 30
+            // 20 20 20 20 20 20 20 20 20 20 20 20 ( 12 bucati )
+            //31 32 33 34 35 36 37 38 39 30 (1 ,2,3...9,0) - nefolosite
+
+            //31 = m = 1:training mode
+
+            //4F 30 20 20 20 20 20 20 20 20 20 20 20 20
+
+            /*
+            2013-06-20 15:10:06.608 Read: C0 1 AA 55 4F 30 20 20 20 20 20 20 20 20 20 20 20 20 31 32 33 34 35 36 37 38 39 30 31 32 33 31 32 33 34 35 36 37 38 39 30 31 32 31 30 31 30 30 31 30 30 30 30 31 38 33 30 30 36 2E 38 34 31 30 30 30 30 30 1D C0 ||
+ DATA : 4F 30 20 20 20 20 20 20 20 20 20 20 20 20 31 32 33 34 35 36 37 38 39 30 31 32 33 31 32 33 34 35 36 37 38 39 30 31 32 31 30 31 30 30 31 30 30 30 30 31 38 33 30 30 36 2E 38 34 31 30 30 30 30 30 ||
+             */
+
+            //nu ma prind ce e cu astea ca nu-s ca in manual
+        }
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageResponseCheckSoftware.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageResponseCheckSoftware.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,74 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 6/20/13
+ * Time: 2:02 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class AclasMessageResponseCheckSoftware extends AClasMessageResponse {
+
+    public AclasMessageResponseCheckSoftware(byte[] buffer) {
+        super(buffer);
+        if(!error) {
+
+            /*
+            2013-06-20 15:21:51.560 Read: C0 2 AA 55 4F 30 32 30 30 36 32 30 31 33 31 34 32 30 33 38 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 39 35 31 2E 30 31 36 30 30 30 30 30 30 31 C7 C0 ||
+ RESPONSE DATA :
+
+ 4F 30 = O0 [0-2)
+ 32 30 = dd = 20 [2-4)
+ 30 36 = mm = 06 [4-6)
+ 32 30 31 33 = yyyy = 2013 [8-10)
+ 31 34 = hh 14 [10-12)
+ 32 30 = mm 20 [12-14)
+ 33 38 = ss 38 [14-16)
+ 30 30 30 30 32 30 = 6 cifre = nr bon fiscal = 000020 [16-22)
+ 30 30 30 30 30 30 = rrrrrr = not used [22-28)
+ 30 30 30 30 30 30 30 30 30 30 = current subtotal = 10 digiti [28-38)
+ 30 = receipt is not closed if 1 [38]
+ 30 = payment started if 1 [39]
+ 30 = 1 means service mode [40]
+ 30 = 1 means superuser mode [41]
+ 31 = 1 means programming is not allowed unless printing Z report [42]
+ 30 39 35 = print buffer left ? = 95 linii [43-46)
+ 31 2E 30 31 36 = versiunea de soft = 1.0.16 [46-51)
+ 30 = 1 mean RAM checksum error [51]
+ 30 30 = Service Count [52-53]
+ 30 30 = Reset Count [54-55]
+ 30 31 = Change tax rate count [56-57]
+
+             */
+
+            System.out.println("Nr bon fiscal curent : " + getNrBonFiscalCurent());//ok
+            System.out.println("Receipt is open : " + isReceiptOpen());//probabil e ok
+            System.out.println("Schimbari taxa : " + getSchimbariTaxa());//ok
+            System.out.println("Current subtotal : " + getSubtotal());//probabil e ok
+        }
+    }
+
+    public String getNrBonFiscalCurent() {
+        return computeFromDigits(16, 21);
+    }
+
+    private String computeFromDigits(int start, int stop) {
+        String s1 = "";
+        for(int i = start ; i <= stop ; i++) {
+            s1 += (char)data[i];
+        }
+        return s1;
+    }
+
+    public boolean isReceiptOpen() {
+        return (char)data[38] == '1';
+    }
+
+    public String getSchimbariTaxa() {
+        return computeFromDigits(56,57);
+    }
+
+    public String getSubtotal() {
+        return computeFromDigits(28,37);
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageSaleProduct.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageSaleProduct.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,48 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+import ro.atreides.ecr.aclas.noarch.AclasUtils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageSaleProduct extends AclasMessage {
+
+    private String productName;
+
+    public AclasMessageSaleProduct(float price, float quantity, String numePRodus, String codBare, String departament) {
+        command = "73";
+
+        this.productName = numePRodus;
+
+        String s = "";
+
+        long x = AclasUtils.convertToLong(quantity, 3);
+        String qS = AclasUtils.getStringMaxSize(9, x+"", '0', true);
+
+        s += qS;
+
+        x = AclasUtils.convertToLong(price, 2);
+        qS = AclasUtils.getStringMaxSize(10, "" + x, '0', true);
+
+        s += qS;
+
+        s += AclasUtils.getStringMaxSize(1, departament, '1', true);
+
+        qS = AclasUtils.getStringMaxSize(24, numePRodus, ' ', false);
+
+        s += qS;
+
+        qS = AclasUtils.getStringMaxSize(13, codBare, '0', false);
+
+        s += qS;
+
+        data = s.getBytes();
+    }
+
+    public String toString() {
+        return productName;
+    }
+    
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageSubtotal.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageSubtotal.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,14 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageSubtotal extends AclasMessage {
+
+    public AclasMessageSubtotal() {
+        command = "";
+        //data is null
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageTotalDue.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageTotalDue.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,14 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageTotalDue extends AclasMessage {
+
+    public AclasMessageTotalDue() {
+        command = "79";
+        //data is null
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageXReport.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageXReport.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,14 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageXReport extends AclasMessage {
+
+    public AclasMessageXReport() {
+        command = "63";
+        //data is null
+    }
+    
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageZReport.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/noarch/messages/AclasMessageZReport.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,14 @@
+package ro.atreides.ecr.aclas.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class AclasMessageZReport extends AclasMessage {
+
+    public AclasMessageZReport() {
+        command = "64";
+        //data is null
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/todelete/AclasSerialReader.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/todelete/AclasSerialReader.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,103 @@
+package ro.atreides.ecr.aclas.todelete;
+
+import ro.atreides.ecr.SerialReaderImplSingleThread;
+import ro.atreides.ecr.optimus.nativeImpl.MessageFactory;
+import ro.atreides.ecr.optimus.nativeImpl.Message;
+import ro.atreides.ecr.optimus.nativeImpl.Reader;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import gnu.io.SerialPort;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: andrei
+ * Date: Apr 29, 2010
+ * Time: 4:42:51 PM
+ */
+
+class AclasSerialReader extends SerialReaderImplSingleThread {
+    private static final int IDLE = 0;
+    private static final int SEARCHING_END = 1;
+    private static final int SEARCHING_CRC1 = 2;
+    private static final int SEARCHING_CRC2 = 3;
+    private static final int SEARCHING_CRC3 = 4;
+    private static final int SEARCHING_CRC4 = 5;
+
+    int state = IDLE;
+    private byte[] buffer = new byte[1024];
+    private int index = 0;
+
+    public AclasSerialReader(final InputStream input, final SerialPort serial) {
+        super(input, serial);
+    }
+
+    @Override
+    protected void dataArrived(byte[] data, int offset, int len) {
+        for (int i = offset; i < len; i++) {
+            byte b = data[i];
+
+            switch (state){
+                case IDLE:
+                    switch (b){
+                        case MessageFactory.ACK:
+                            addMessage(MessageFactory.buildAck());
+                            break;
+                        case MessageFactory.NAK:
+                            addMessage(MessageFactory.buildNack());
+                            break;
+                        case MessageFactory.EOT:
+                            addMessage(MessageFactory.buildTransmisionEnd());
+                            break;
+                        case MessageFactory.ERROR:
+                            addMessage(MessageFactory.buildError());
+                            break;
+                        case MessageFactory.ENQ:
+                            addMessage(MessageFactory.buildEnquire());
+                            break;
+                        case MessageFactory.STX:
+                            buffer[index++] = b;
+                            state = SEARCHING_END;
+                            break;
+                    }
+                    break;
+                case SEARCHING_END:
+                    buffer[index++] = b;
+                    if(b == MessageFactory.ETX){
+                        state = SEARCHING_CRC1;
+                    }
+                    break;
+                case SEARCHING_CRC1:
+                    buffer[index++] = b;
+                    state = SEARCHING_CRC2;
+                    break;
+                case SEARCHING_CRC2:
+                    buffer[index++] = b;
+                    state = SEARCHING_CRC3;
+                    break;
+                case SEARCHING_CRC3:
+                    buffer[index++] = b;
+                    state = SEARCHING_CRC4;
+                    break;
+                case SEARCHING_CRC4:
+                    buffer[index++] = b;
+                    byte[] tmp = new byte[index];
+                    System.arraycopy(buffer, 0, tmp, 0, index);
+                    addMessage(MessageFactory.buildPacked(tmp));
+                    state = IDLE;
+                    index = 0;
+                    break;
+            }
+
+        }
+    }
+
+    public Message read(int timeout) throws IOException {
+        Message m = (Message) super.read(timeout);
+        if(m == null){
+            m = new Message();
+        }
+        return m;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/aclas/todelete/DriverInterfaceAclas.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/aclas/todelete/DriverInterfaceAclas.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,40 @@
+package ro.atreides.ecr.aclas.todelete;
+
+import ro.atreides.ecr.SerialDriverInterfaceImpl;
+import ro.atreides.ecr.aclas.noarch.Bon;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: andrei
+ * Date: May 5, 2010
+ * Time: 5:04:30 PM
+ */
+
+class DriverInterfaceAclas extends SerialDriverInterfaceImpl {
+    final int maxretryes = 2;
+    int retyes;
+    Bon last;
+
+//    public int raportZ(Bon b){
+//        if(last == b){
+//            if(retyes <= 0){
+//                return IGNORE;
+//            }
+//        } else {
+//            retyes = maxretryes;
+//        }
+//
+//        JLabel message = new JLabel("<html><font color=red size=5>Emiteti Raport Zilnic Z din casa de marcat!" +
+//                "</font><font color=green size=4><br>Apasati: '3' 'S.TOTAL' parola 'OK' 'OK' (raport casa)<br>" +
+//                " asteptati...</tr><br>Apasati: '1' 'S.TOTAL' (revenire mod vanzare)</font>");
+//
+//        String[] buttons = {"am facut"};
+//
+//        EcrDialogUtils.choiseDialog(GuiUtils.currentFrame, message, "Atentie", buttons);
+//
+//        last = b;
+//        retyes--;
+//        return RETRY;
+//    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/activa/Generic.java
--- a/src/ro/atreides/ecr/activa/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/activa/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -20,9 +20,6 @@
         super();
     }
 
-    public void processXml(String fileName) {
-    }
-
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
 
         //FIXME : tipuri plata
diff -r e6b80a8b200a src/ro/atreides/ecr/carat/Prima.java
--- a/src/ro/atreides/ecr/carat/Prima.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/carat/Prima.java	Fri Sep 13 19:21:02 2013 +0300
@@ -25,9 +25,6 @@
 public class Prima extends AbstractCashRegister {
 
 
-    public void processXml(String fileName) {
-    }
-
     public void forceTotal() {
     }
 
diff -r e6b80a8b200a src/ro/atreides/ecr/cashprn/Generic.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/cashprn/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,128 @@
+package ro.atreides.ecr.cashprn;
+
+import ro.atreides.ecr.AbstractCashRegister;
+import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.EcrSale;
+import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
+import ro.atreides.utils.gui.Validators;
+import ro.atreides.utils.plati.TipPlata;
+
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 6/12/12
+ * Time: 5:19 PM
+ * To change this template use File | Settings | File Templates.
+ *
+ * driverul asta e un .exe care nu prea stie sa citeasca .txt
+
+ ce trebuie sa-i dau de ex sa scoata un bon din cmd.exe
+
+ CASHPRN 2;1;1;10003933-Cristin
+ CASHPRN 1;1;1;418;2;Ardei;2;1;0;3;1;1
+ CASHPRN 1;1;1;473;1;Calsberg 500;1;6.5;0;3;1;1
+ CASHPRN 1;1;1;40;2;Cartofi la s;1;5;0;3;1;1
+ CASHPRN 1;1;1;232;2;Ficatei capa;1;11;0;3;1;1
+ CASHPRN 1;1;1;112;2;Meniul zilei;2;16;0;3;1;1
+ CASHPRN 1;1;1;30;1;Pepsi;1;5;0;3;1;1
+ CASHPRN 1;1;1;265;2;Smantana;1;2.5;0;3;1;1
+ CASHPRN 0;1;1
+
+
+ Syntax: CASHPRN
+ opcode;port;cashNo;cod;dep;name$;qty;price;rabat;touchDataProvider;sg;tg
+ CASHPRN opcode;port;cashNo;message
+ CASHPRN opcode;port;cashNo
+
+ opcode = 1 for Data, = 2 for message(max 16 chars)
+ opcode = 0 for end transaction
+ port   COM1 or COM2 serial port number
+ cashNo Number of current cash register
+ cod    Articles code
+ dep    Department code
+ name   Articles name(max 12 chars)
+ qty    Articles quantity
+ price  Article single price
+ rabat  (-) for rabat, (+) for additional summ
+ touchDataProvider     Decimal point
+ sg     Stock group
+ tg     Tax group
+
+ Examples: CASHPRN 2;2;1;Peter Norton
+ CASHPRN 1;2;1;133;22;Coca cola;5;2;10;3;1;1
+ CASHPRN 0;2;1
+
+ Copyright ELECTRIC Co, Silistra BG, tel (086) 5-22-27
+
+
+ */
+public class Generic extends AbstractCashRegister {
+
+    private int ecrPort = 1,decimalPointPosition = 2;
+    private String cashPrnCommand = "";
+
+    public Generic() {
+        super();
+    }
+
+    public void buildConfiguration(Properties conf) {
+        super.buildConfiguration(conf);
+
+        ecrPort = Integer.parseInt(conf.getProperty("ecrPort", "1"));
+        cashPrnCommand = conf.getProperty("cashPrnCommand", "cashprn ")+ " ";
+        decimalPointPosition = Integer.parseInt(conf.getProperty("decimalPointPosition", "3"));
+    }
+
+    public void printBonFiscal(Vector<EcrSale> sales, float total, Vector<EcrPlata> plati, TipPlata cashDefault, Vector<String> comments, String orderIdentifier, int idOrder) {
+
+        for (EcrPlata plata : plati) {
+            if(!Validators.correctString(plata.getEcrMapping())) {
+                Logger.logWarning(this, "Tipul de plata : " + plata.getTipPlata() + " nu are setat ecr mapping.");
+                return ;
+            }
+        }
+
+        String items = "";
+
+        for (EcrSale sale : sales) {
+        
+       	    String price = Utils.getString2DecimalsNoTrunc(sale.getPpuDupaDiscount());
+            price = price.replace(".", "");
+
+            String line = cashPrnCommand + "1;" + ecrPort + ";1;" + sale.getCod() + ";" + sale.getDepartament() + ";" +
+                    Utils.getStringMaxSize(12, sale.getProduct(), ' ', false) + ";" + Utils.getString3DecimalsNoTrunc(sale.getQuantity()) + ";"
+                    + price + ";0;" + decimalPointPosition + ";1;" + sale.getCodTva();
+
+            items += line + "\r\n";
+//            CASHPRN 1;1;1;418;2;Ardei;2;1;0;3;1;1
+        }
+
+        for (String comment : comments) {
+            //CASHPRN 2;1;1;10003933-Cristin
+            if(Validators.correctString(comment)) {
+                String line = cashPrnCommand + "2;" + ecrPort +";1;" + Utils.getStringMaxSize(16, comment, ' ',false);
+                items += line + "\r\n";
+            }
+        }
+
+        //CASHPRN 0;1;1
+        String line = cashPrnCommand + "0;" + ecrPort + ";1";
+        items += line + "\r\n";
+
+        Logger.logDebugVerbose(this, "Content bon fiscal : " + items);
+
+        pt.addToQueue(items);
+    }
+
+    public void forceTotal() {
+    }
+
+    @Override
+    public boolean multiplePaymentTypesSupported() {
+        return false;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/chd/Generic.java
--- a/src/ro/atreides/ecr/chd/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/chd/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -30,9 +30,6 @@
         forceTotal = Boolean.parseBoolean(conf.getProperty("forceTotal", "false"));
     }
 
-    public void processXml(String fileName) {
-    }
-
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
 
         String file = "";
diff -r e6b80a8b200a src/ro/atreides/ecr/client/Generic.java
--- a/src/ro/atreides/ecr/client/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/client/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -3,7 +3,7 @@
 import ro.atreides.ecr.AbstractCashRegister;
 import ro.atreides.ecr.EcrPlata;
 import ro.atreides.ecr.EcrSale;
-import ro.atreides.ecr.datecs.nativeImpl.EcrDialogUtils;
+import ro.atreides.ecr.EcrDialogUtils;
 import ro.atreides.utils.*;
 import ro.atreides.utils.gui.Validators;
 import ro.atreides.utils.gui.GuiUtils;
@@ -132,10 +132,13 @@
             String prod = TextUtils.escapeForXML(sale.getProduct());
             text.append("<product label=\"" + prod + "\"" +
                     " price=\"" + Utils.getString2DecimalsNoTrunc(sale.getPpuDupaDiscount()) + "\"" +
+                    " priceOriginal=\"" + Utils.getString2DecimalsNoTrunc(sale.getPpuOriginal()) + "\"" +
                     " quantity=\"" + Utils.getString3DecimalsNoTrunc(sale.getQuantity()) + "\"" +
                     " department=\"" + sale.getDepartament() + "\"" +
                     " group=\"" + sale.getGrupa() + "\"" +
                     " vat=\"" + codTva + "\"" +
+                    " vatRate=\"" + Utils.getString2Decimals(sale.getCotaTva()) + "\"" +
+                    " productCode=\"" + sale.getCod() + "\"" +
                     " />\n");
         }
 
@@ -184,7 +187,7 @@
                     String m = "<html><font color=red size=5>Casa de marcat deconectata !!!</font>" +
                             "<br>Verificati:" +
                             "<font color=blue><br>1) Casa este conectata la calculator" +
-                            "<br>2) Casa este in modul vanzare (OFF 1 1 Total)" +
+                            "<br>2) Casa este in modul vanzare" +
                             "<br>3) Scoateti Z (golire)</font></html>";
 
                     DialogUtils.errorDialog(GuiUtils.currentFrame, m, "Atentie");
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/Fprint.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/datecs/Fprint.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,164 @@
+package ro.atreides.ecr.datecs;
+
+import ro.atreides.ecr.AbstractCashRegister;
+import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.EcrSale;
+import ro.atreides.utils.FloatUtils;
+import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
+import ro.atreides.utils.gui.Validators;
+import ro.atreides.utils.plati.TipPlata;
+
+import java.util.*;
+
+/**
+ * @author valy
+ */
+public class Fprint extends AbstractCashRegister {
+
+    private boolean forceTotal, forceTotalAt2Decimals, discountGlobal;
+
+    public void buildConfiguration(Properties conf) {
+        super.buildConfiguration(conf);
+        forceTotal = Boolean.parseBoolean(conf.getProperty("forceTotal", "false"));
+        forceTotalAt2Decimals = Boolean.parseBoolean(conf.getProperty("forceTotalAt2Decimals", "false"));
+        discountGlobal = Boolean.parseBoolean(conf.getProperty("discountGlobal", "false"));
+    }
+
+    public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
+        String items = "";
+
+        Iterator iter = sales.iterator();
+
+        boolean aDouaZecimala = false;
+
+        float totalFaraReducere = 0;
+        float totalReducere = 0;
+
+        while( iter.hasNext()) {
+            String line = "S,1,______,_,__;";
+            EcrSale newsaleentry = (EcrSale)iter.next();
+            String pNou = newsaleentry.getProduct().toUpperCase();
+            line += Utils.getStringMaxSize(22, pNou, null, false) + ";";//nume produs
+
+            float quantity = newsaleentry.getQuantity();
+
+            float price = (discountGlobal) ? newsaleentry.getPpuOriginal() : newsaleentry.getPpuDupaDiscount();
+
+            line += Utils.getString2DecimalsNoTrunc(price) + ";";//pret unitar : 3333.33
+            line += Utils.getString3DecimalsNoTrunc(quantity) + ";";//cantitate : 33.000
+
+            String dep = getDepartament(newsaleentry);
+            line += dep + ";";//departament
+
+            line += getGrupa(newsaleentry) + ";";//grupa
+            String codTva = newsaleentry.getCodTva();
+            if(Validators.correctString(codTva)) {
+                line += codTva + ";";
+            }
+            line += "0;0;";
+
+            items += line + "\n";
+
+            float value = price * newsaleentry.getQuantity();
+
+            totalFaraReducere += newsaleentry.getPpuOriginal() * newsaleentry.getQuantity();
+            totalReducere += (newsaleentry.getPpuOriginal() - newsaleentry.getPpuDupaDiscount()) * newsaleentry.getQuantity();
+
+            float valueFaraZecimala = FloatUtils.roundFloat(value, 1);
+            if(value != valueFaraZecimala) {
+                Logger.logWarning(this, "2 Zecimale !! " + line);
+                aDouaZecimala = true;
+            }
+
+        }
+
+        if(comments.size() > 0) {
+            items += "P,1,______,_,__;";
+        }
+        for (int i = 0; i < comments.size(); i++) {
+            String o = (String) comments.elementAt(i);
+            o = o.toUpperCase();
+
+            List<String> lines = Utils.splitEqually(o, 16);
+            for (String line : lines) {
+                items += line + ";";
+            }
+
+        }
+        if(comments.size() > 0) {
+            items += ";;;\n";
+        }
+
+
+        if(discountGlobal) {
+            if(totalReducere != 0) {
+                items += "T,1,______,_,__;4;;;;;\n";
+                char command = '1';
+                if(totalReducere < 0) {
+                    command = '0';
+                    totalReducere = -totalReducere;
+                }
+                float procent = totalReducere * 100 / totalFaraReducere;
+
+                items += "C,1,______,_,__;" + command + ";" + Utils.getString2DecimalsNoTrunc(procent) + ";;;;\n";
+            }
+        }
+
+        if(plati == null || plati.size() == 0) {
+            items += "T,1,______,_,__;\n";
+        } else {
+            float totalPlatit = 0;
+            for (Iterator iterator = plati.iterator(); iterator.hasNext();) {
+                EcrPlata plata = (EcrPlata) iterator.next();
+                //todo : am impresia ca aici se face o trunchiere, in loc de o rotunjire cum ar trebui
+                items += "T,1,______,_,__;" + plata.getEcrMapping() + ";" + Utils.getString2DecimalsNoTrunc(plata.getSuma()) + ";;;;\n";
+                totalPlatit += plata.getSuma();
+            }
+            if(forceTotal || totalPlatit < total || ( aDouaZecimala && forceTotalAt2Decimals ) )
+                items += "T,1,______,_,__;\n";
+        }
+
+//        String idBon = Utils.getLocalComputerName() + "_L_" + "numerar";
+//        processBonFiscal(items, idBon, Constants.NULL_VALUE);
+
+        pt.addToQueue(items);
+
+        Logger.logDebugVerbose(this, "Content bon fiscal : " + items);
+    }
+
+    public void introduNumerar(float suma) {
+        String codOp = "";
+        String sumaNoua = "";
+        if(suma > 0) {
+            codOp = "0";
+        } else if(suma < 0) {
+            codOp = "1";
+        } else return;
+        suma = Math.abs(suma);
+        sumaNoua = Utils.getString2DecimalsNoTrunc(suma);
+        String s = "I,1,______,_,__;" + codOp + ";" + sumaNoua + ";;;;\n";
+
+//        String idBon = Utils.getLocalComputerName() + "_L_" + "numerar";
+//        processBonFiscal(s, idBon, Constants.NULL_VALUE);
+
+        pt.addToQueue(s);
+
+        Logger.logDebugVerbose(this, "Content bon fiscal : " + s);
+    }
+
+    public boolean numerarInputReady() {
+        return true;
+    }
+
+    public void forceTotal() {
+        String items = "T,1,______,_,__;\n";
+
+//            String idBon = Utils.getLocalComputerName() + "_L_" + "total";
+//            processBonFiscal(items, idBon, Constants.NULL_VALUE);
+
+        pt.addToQueue(items);
+
+        Logger.logDebugVerbose(this, "Content bon fiscal : " + items);
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/Generic.java
--- a/src/ro/atreides/ecr/datecs/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -22,9 +22,9 @@
     private CasaDeMarkatXmlHandler xmlHandler;
     private MP55Impl casa;
 
-    private boolean forceTotal, forceTotalAt2Decimals, discountGlobal, errorNotifications;
+    private boolean forceTotal, forceTotalAt2Decimals, discountGlobal, errorNotifications, discountLaProdus;
     private Vector ecrLicenseCode = new Vector();
-    private Hashtable paymentTypes;
+
 
     private int ecrId = 0;
 
@@ -54,30 +54,22 @@
         }
 
         discountGlobal = Boolean.parseBoolean(conf.getProperty("discountGlobal", "false"));
+        discountLaProdus = Boolean.parseBoolean(conf.getProperty("discountLaProdus", "false"));
         errorNotifications = Boolean.parseBoolean(conf.getProperty("errorNotifications", "true"));
 
         ecrId = Integer.parseInt(conf.getProperty("ecrId", "0"));
         
-        paymentTypes = new Hashtable();
-        String paymentTypesString = conf.getProperty("paymentTypes", "Cash");
-        Vector types = Utils.splitString(paymentTypesString, ',');
-        for (int i = 0; i < types.size(); i++) {
-            String type =  (String)types.elementAt(i);
-            String value = conf.getProperty("paymentType_" + type, "");
-            type = type.toUpperCase();
-            paymentTypes.put(type, value);
-        }
-        
-        Logger.logInfo(this, "table = "+paymentTypes);
-
         String prop = conf.getProperty("ecrPortFilters", "/dev/ttyS.,/dev/ttyUSB.,COM.");
         filters = Utils.splitString(prop, ',');
 
+        if(discountLaProdus) discountGlobal = false;
+
 
     }
 
-    protected Hashtable getPaymentTypes(){
-        return paymentTypes;
+    @Override
+    public boolean ecrConnectedAtStartup() {
+        return false;
     }
 
     public Generic() {
@@ -128,6 +120,9 @@
     }
 
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
+
+        boolean subtotal = false;
+
         String items = "";
 
         Iterator iter = sales.iterator();
@@ -145,7 +140,11 @@
 
             float quantity = newsaleentry.getQuantity();
 
-            float price = (discountGlobal) ? newsaleentry.getPpuOriginal() : newsaleentry.getPpuDupaDiscount();
+            float discount = 0;
+
+            float price = (discountGlobal || discountLaProdus) ? newsaleentry.getPpuOriginal() : newsaleentry.getPpuDupaDiscount();
+
+            discount = discountLaProdus ? newsaleentry.getDiscount() : 0;
 
             line += Utils.getString2DecimalsNoTrunc(price) + ";";//pret unitar : 3333.33
             line += Utils.getString3DecimalsNoTrunc(quantity) + ";";//cantitate : 33.000
@@ -173,6 +172,23 @@
                 aDouaZecimala = true;
             }
 
+            if(discount != 0) {
+                if(!subtotal) {
+                    items += "T,1,______,_,__;4;;;;;\n";
+                    subtotal = true;
+                }
+                char command = '1';
+                String text = "Discount";
+                if(totalReducere < 0) {
+                    command = '0';
+                    totalReducere = -totalReducere;
+                    text = "Adaos";
+                }
+                float procent = totalReducere * 100 / totalFaraReducere;
+
+                items += "C,1,______,_,__;" + command + ";" + Utils.getString2DecimalsNoTrunc(procent) + ";;;;\n";
+                items += "P,1,______,_,__;" + text + ";;;;;\n";
+            }
         }
 
         if(comments.size() > 0) {
@@ -181,7 +197,11 @@
         for (int i = 0; i < comments.size(); i++) {
             String o = (String) comments.elementAt(i);
             o = o.toUpperCase();
-            items += o + ";";
+
+            List<String> lines = Utils.splitEqually(o, 16);
+            for (String line : lines) {
+                items += line + ";";
+            }
         }
         if(comments.size() > 0) {
             items += ";;;\n";
@@ -192,13 +212,16 @@
             if(totalReducere != 0) {
                 items += "T,1,______,_,__;4;;;;;\n";
                 char command = '1';
+                String text = "Discount";
                 if(totalReducere < 0) {
                     command = '0';
                     totalReducere = -totalReducere;
+                    text = "Adaos";
                 }
                 float procent = totalReducere * 100 / totalFaraReducere;
 
                 items += "C,1,______,_,__;" + command + ";" + Utils.getString2DecimalsNoTrunc(procent) + ";;;;\n";
+                items += "P,1,______,_,__;" + text + ";;;;;\n";
             }
         }
 
@@ -255,7 +278,7 @@
 
     public void finishInitialize() {
         super.finishInitialize();
-        xmlHandler.setPaymentTypes(getPaymentTypes());
+        xmlHandler.setPaymentTypes(paymentTypes);
         startECR();
     }
 
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/nativeImpl/Bon.java
--- a/src/ro/atreides/ecr/datecs/nativeImpl/Bon.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/nativeImpl/Bon.java	Fri Sep 13 19:21:02 2013 +0300
@@ -26,6 +26,13 @@
         this.orderIdentifier = orderIdentifier;
     }
 
+    public Bon(Vector products, String source, int idOrder, String orderIdentifier) {
+        this.products = products;
+        this.source = source;
+        this.idOrder = idOrder;
+        this.orderIdentifier = orderIdentifier;
+    }
+
     public String getOrderIdentifier() {
         return orderIdentifier;
     }
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/nativeImpl/Ecr.java
--- a/src/ro/atreides/ecr/datecs/nativeImpl/Ecr.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/nativeImpl/Ecr.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,5 +1,7 @@
 package ro.atreides.ecr.datecs.nativeImpl;
 
+import ro.atreides.ecr.EcrInterface;
+
 /**
  * Created by IntelliJ IDEA.
  * User: andreic
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/nativeImpl/EcrImpl.java
--- a/src/ro/atreides/ecr/datecs/nativeImpl/EcrImpl.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/nativeImpl/EcrImpl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,5 +1,7 @@
 package ro.atreides.ecr.datecs.nativeImpl;
 
+import ro.atreides.ecr.EcrInterface;
+import ro.atreides.ecr.EcrInterfaceImpl;
 import ro.atreides.utils.Logger;
 import ro.atreides.utils.multilang.LangRoAll;
 import ro.atreides.utils.tricky.NonPrintedBonInterface;
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/nativeImpl/MP55Impl.java
--- a/src/ro/atreides/ecr/datecs/nativeImpl/MP55Impl.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/nativeImpl/MP55Impl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,5 +1,6 @@
 package ro.atreides.ecr.datecs.nativeImpl;
 
+import ro.atreides.ecr.EcrInterface;
 import ro.atreides.utils.Logger;
 import ro.atreides.utils.multilang.LangRoAll;
 
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/nativeImpl/PersistentList.java
--- a/src/ro/atreides/ecr/datecs/nativeImpl/PersistentList.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/nativeImpl/PersistentList.java	Fri Sep 13 19:21:02 2013 +0300
@@ -17,6 +17,7 @@
 
     public PersistentList(int id){
         filename = "_ecr_persistent_products_list_" + ( id==0? "" : id );
+
         products = Utils.getProductsFor(filename);
     }
 
@@ -49,9 +50,11 @@
     }
 
     public synchronized void removeByIdentifier(String identifier) {
+        System.out.println("Searching for identifier " + identifier);
         for (Object product : products) {
             Bon b = (Bon)product;
             if(b.getOrderIdentifier().equals(identifier)) {
+                System.out.println("gasit idenfier : " + identifier + " si sters!");
                 products.remove(b);
                 break;
             }
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/nativeImpl/PortSettings.java
--- a/src/ro/atreides/ecr/datecs/nativeImpl/PortSettings.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/nativeImpl/PortSettings.java	Fri Sep 13 19:21:02 2013 +0300
@@ -73,4 +73,17 @@
     public void setRTS(boolean RTS) {
         this.RTS = RTS;
     }
+
+    @Override
+    public String toString() {
+        return "PortSettings{" +
+                "dataBits=" + dataBits +
+                ", name='" + name + '\'' +
+                ", speed=" + speed +
+                ", portType=" + portType +
+                ", stopBits=" + stopBits +
+                ", pariry=" + pariry +
+                ", RTS=" + RTS +
+                '}';
+    }
 }
\ No newline at end of file
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/nativeImpl/Product.java
--- a/src/ro/atreides/ecr/datecs/nativeImpl/Product.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/nativeImpl/Product.java	Fri Sep 13 19:21:02 2013 +0300
@@ -11,6 +11,9 @@
  * Time: 3:54:16 PM
  */
 public class Product implements Serializable, Cloneable {
+
+    public static final long serialVersionUID = 5315623375743308372L;
+
     private String Name;
     private float Price;
     private int Quantity;
@@ -19,6 +22,16 @@
     private float percent;
     private String source;
 
+    public Product(String name, float price, int quantity, byte[] rawMessage, MessageTypes itemType, float percent, String source) {
+        Name = name;
+        Price = price;
+        Quantity = quantity;
+        this.rawMessage = rawMessage;
+        this.itemType = itemType;
+        this.percent = percent;
+        this.source = source;
+    }
+
     public Product(byte[] message, String itemName, float price, int quantity, String source){
         this.rawMessage = message;
         this.Name = itemName;
diff -r e6b80a8b200a src/ro/atreides/ecr/datecs/nativeImpl/Utils.java
--- a/src/ro/atreides/ecr/datecs/nativeImpl/Utils.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/datecs/nativeImpl/Utils.java	Fri Sep 13 19:21:02 2013 +0300
@@ -319,10 +319,10 @@
     //////////////////////////////////////////////////////////////////////////////////////
 
     public synchronized static List getProductsFor(String file){
-        List result = new Vector();
+        Vector result = new Vector();
         Object list = readObjectFrom(file);
-        if(list instanceof List){
-            result = (List) list;
+        if(list instanceof Vector){
+            result = (Vector) list;
         }
         return result;
     }
@@ -338,9 +338,10 @@
         Object result = null;
         ObjectInput input = null;
         try {
-            input = new ObjectInputStream ( new BufferedInputStream( new FileInputStream( file ) ) );
+            input = new ObjectInputStream ( new FileInputStream( file ) );
             result = input.readObject();
         } catch (Exception e) {
+            e.printStackTrace();
         } finally{
             try {
                 if(input != null){
@@ -599,4 +600,28 @@
                     '}';
         }
     }
+
+    public static final void main(String [] args) {
+
+//        List<Bon> l = getProductsFor("_ecr_persistent_products_list_");
+
+        try {
+            File file = new File("_ecr_persistent_products_list_");
+            ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
+
+            Object obj = in.readObject();
+            in.close();
+
+//            System.out.println("size : " + l.size());
+//
+//            for (Bon o : l) {
+//                System.out.println("products: " + o.getProducts() + ", source: " + o.getSource());
+//            }
+        } catch (IOException e) {
+            Logger.logException("Main", e);
+        } catch (ClassNotFoundException e) {
+            Logger.logException("Main", e);
+        }
+
+    }
 }
\ No newline at end of file
diff -r e6b80a8b200a src/ro/atreides/ecr/elcom/Generic.java
--- a/src/ro/atreides/ecr/elcom/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/elcom/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -3,6 +3,7 @@
 import ro.atreides.ecr.AbstractCashRegister;
 import ro.atreides.ecr.EcrPlata;
 import ro.atreides.ecr.EcrSale;
+import ro.atreides.utils.FloatUtils;
 import ro.atreides.utils.Utils;
 import ro.atreides.utils.gui.Validators;
 import ro.atreides.utils.plati.TipPlata;
@@ -24,14 +25,12 @@
 
     private boolean paymentReplaceDotWithComma = false;
 
+    private boolean discountLaLinie = false;
+
     public Generic() {
         super();
     }
 
-    public void processXml(String fileName) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
     public void buildConfiguration(Properties conf) {
         super.buildConfiguration(conf);
         String um = conf.getProperty("unitateMasura", "1");
@@ -42,6 +41,7 @@
         forceTotal = Boolean.parseBoolean(conf.getProperty("forceTotal", "false"));
         paymentAsFloat = Boolean.parseBoolean(conf.getProperty("paymentAsFloat", "false"));
         paymentReplaceDotWithComma = Boolean.parseBoolean(conf.getProperty("paymentReplaceDotWithComma", "false"));
+        discountLaLinie = Boolean.parseBoolean(conf.getProperty("discountLaLinie", "false"));
     }
 
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
@@ -57,8 +57,13 @@
 		    EcrSale newsaleentry = (EcrSale)iter.next();
 		    String product = newsaleentry.getProduct();
 			float nrPortii = newsaleentry.getQuantity();
-			
-			long p = (long)(printPrice * newsaleentry.getPpuDupaDiscount());
+
+            float orig = newsaleentry.getPpuOriginal();
+            float cuReducere = newsaleentry.getPpuDupaDiscount();
+
+            float pret = discountLaLinie? orig : cuReducere;
+
+			long p = (long)(printPrice * pret);
 
             String codTva = "" + tvaDefault;
             if(Validators.correctString(newsaleentry.getCodTva())) {
@@ -70,20 +75,49 @@
 			
 			items += commandText;
 			items += "\n";
+
+            if(orig != cuReducere && discountLaLinie) {//todo poate sa afisam numele reducerii pe bonul fiscal - daca o cere cineva
+                String tip = "";
+
+                long origL = (long)(printPrice * orig);
+                long cuReducereL = (long)(printPrice * cuReducere);
+                long val = 0;
+
+                if(orig > cuReducere) {
+                    tip = "1";
+                    val = origL - cuReducereL;
+                } else {
+                    tip = "0";
+                    val = cuReducereL - origL;
+                }
+
+                String line = "7;" + tip + ";0;1;0;" + val + ";1";
+                                       //7;1;0;1;0;230;1
+                items += line + "\n";
+            }
 		}
 
+        for (int i = 0; i < comments.size(); i++) {
+            String o = (String) comments.elementAt(i);
+            o = o.toUpperCase();
+            if(!Validators.correctString(o)) o = "*";
+            String line = "1;" + o + ";8;1;1;100;1000;0;1";
+            items += line + "\n";
+        }
+
         if( plati == null || plati.size() == 0 ) {
             items += "3\n";
         } else {
             float totalPlatit = 0;
             for (Iterator iterator = plati.iterator(); iterator.hasNext();) {
                 EcrPlata plata = (EcrPlata) iterator.next();
+
                 float p = plata.getSuma();
                 String s = "";
                 if(paymentAsFloat) {
                     s = Utils.getString2DecimalsNoTrunc(p);
                 } else {
-                    long l = (long)(p * printPrice);
+                    long l = FloatUtils.convertToLong(p, onlineDecimalPlaces);
                     s = l + "";
                 }
 
@@ -93,8 +127,9 @@
                 items += "5;" + s + ";" + plata.getEcrMapping() + ";0;\n";
                 totalPlatit += plata.getSuma();
             }
-            if(totalPlatit < total) {
+            if(!Utils.isValueZero(totalPlatit - total)) {
                 float p = (total - totalPlatit);
+                p = FloatUtils.roundFloat(p, onlineDecimalPlaces);
                 String s = "";
                 if(paymentAsFloat) {
                     s = Utils.getString2DecimalsNoTrunc(p);
diff -r e6b80a8b200a src/ro/atreides/ecr/elcom2/Generic.java
--- a/src/ro/atreides/ecr/elcom2/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/elcom2/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -38,10 +38,6 @@
         paymentReplaceDotWithComma = Boolean.parseBoolean(conf.getProperty("paymentReplaceDotWithComma", "false"));
     }
 
-    public void processXml(String fileName) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
         String items = "";
 
diff -r e6b80a8b200a src/ro/atreides/ecr/elka/Generic.java
--- a/src/ro/atreides/ecr/elka/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/elka/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -23,10 +23,6 @@
         super();
     }
 
-    public void processXml(String fileName) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
         String items = "";
 
diff -r e6b80a8b200a src/ro/atreides/ecr/eltrade/Generic.java
--- a/src/ro/atreides/ecr/eltrade/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/eltrade/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -92,11 +92,6 @@
         pt.addToQueue(cmd);
     }
 
-    public void processXml(String fileName) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-
     public void forceTotal() {
         //To change body of implemented methods use File | Settings | File Templates.
     }
diff -r e6b80a8b200a src/ro/atreides/ecr/euro/Generic.java
--- a/src/ro/atreides/ecr/euro/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/euro/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -28,9 +28,6 @@
         forceTotal = Boolean.parseBoolean(conf.getProperty("forceTotal", "false"));
     }
 
-    public void processXml(String fileName) {
-    }
-
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
         StringBuffer s = new StringBuffer();
 
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/Generic.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,179 @@
+package ro.atreides.ecr.incotex;
+
+import ro.atreides.ecr.AbstractCashRegister;
+import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.EcrSale;
+import ro.atreides.ecr.incotex.noarch.Bon;
+import ro.atreides.ecr.incotex.noarch.messages.*;
+import ro.atreides.utils.plati.TipPlata;
+
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 8:49:15 AM
+ */
+public class Generic extends AbstractCashRegister {
+
+    IncotexImpl driver;
+
+    private boolean discountGlobal, errorNotifications, discountLaProdus;
+
+    private String port;
+
+    public void buildConfiguration(Properties conf) {
+        super.buildConfiguration(conf);
+
+        discountGlobal = Boolean.parseBoolean(conf.getProperty("discountGlobal", "false"));
+        discountLaProdus = Boolean.parseBoolean(conf.getProperty("discountLaProdus", "false"));
+        errorNotifications = Boolean.parseBoolean(conf.getProperty("errorNotifications", "true"));
+
+        port = conf.getProperty("ecrPort", "/dev/ttyS0");
+    }
+
+
+//    private AclasMessageDiscount calculeazaProcentDiscount(float valoareOriginala, float discount, boolean discountGlobal) {
+//
+//        if(discount == 0) return null;
+//
+//        if(valoareOriginala < discount) {
+//            //majorare
+//            float procent = discount * 100 / valoareOriginala;
+//            AclasMessageDiscount disc = new AclasMessageDiscount(discountGlobal, procent, LangRoAll.majorare, true);
+//            return disc;
+//        } else if(valoareOriginala > discount) {
+//            //discount
+//            float procent = discount * 100 / valoareOriginala;
+//            AclasMessageDiscount disc = new AclasMessageDiscount(discountGlobal, procent, LangRoAll.discount, false);
+//            return disc;
+//        } else {
+//            //discount
+//            AclasMessageDiscount disc = new AclasMessageDiscount(discountGlobal, ((float)99.99), LangRoAll.discount, false);//the best we can do
+//            return disc;
+//        }
+//    }
+
+    public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
+        Bon b = new Bon();//todo idorder
+        b.addSale(new IncotexMessageAllVoid());
+
+        IncotexMessage openFiscalReceipt = new IncotexMessageOpenFiscalReceipt();
+        b.addSale(openFiscalReceipt);
+
+        float totalOriginal = 0;
+        float totalDiscount = 0;
+        for (Object o : sales) {
+            EcrSale sale = (EcrSale)o;
+
+            float price = sale.getPpuDupaDiscount();
+            if(discountGlobal || discountLaProdus) {
+                price = sale.getPpuOriginal();
+            }
+
+            IncotexMessageSaleProduct produs = new IncotexMessageSaleProduct(price, sale.getQuantity(),
+                    sale.getProduct(), sale.getCodTva().charAt(0));
+            b.addSale(produs);
+
+//            if(discountLaProdus) {
+//                b.addProduct(calculeazaProcentDiscount(sale.getPpuOriginal(), sale.getDiscount(), false));
+//            } else if(discountGlobal) {
+                totalDiscount += sale.getDiscount() * sale.getQuantity();
+                totalOriginal += sale.getPpuOriginal() * sale.getQuantity();
+//            }
+        }
+
+//        if(discountGlobal && totalDiscount != 0) {
+//            AclasMessageDiscount disc = calculeazaProcentDiscount(totalOriginal, totalDiscount, true);
+//            if(disc != null) {
+//                b.addProduct(new AclasMessageTotalDue());
+//                b.addProduct(disc);
+//            }
+//        }
+
+
+        float totalPlatit = 0;
+        for(Object o : plati) {
+            EcrPlata plata = (EcrPlata)o;
+            IncotexMessagePayment payment = new IncotexMessagePayment(plata.getEcrMapping(), plata.getSuma());
+            b.addSale(payment);
+            totalPlatit += plata.getSuma();
+        }
+
+        //force total
+        if(totalPlatit < total) {
+            IncotexMessagePayment payment = new IncotexMessagePayment(cashDefault.getEcrMapping(), total - totalPlatit);
+            b.addSale(payment);
+        }
+
+        for (Object comment : comments) {
+            String s = (String)comment;
+            b.addSale(new IncotexMessageComment(s));
+        }
+
+        IncotexMessage closeFiscalReceipt = new IncotexMessageCloseFiscalReceipt();
+        b.addSale(closeFiscalReceipt);
+
+
+        driver.addBon(b);
+    }
+
+    public void printX() {
+
+        Bon b = new Bon();
+//        b.addProduct(new AclasMessageAllVoid());
+        b.addSale(new IncotexMessageXReport());
+        driver.addBon(b);
+    }
+
+    public void printZ() {
+        Bon b = new Bon();
+//        b.addProduct(new AclasMessageAllVoid());
+        b.addSale(new IncotexMessageZReport());
+        driver.addBon(b);
+    }
+
+    public void introduNumerar(float suma) {
+        Bon b = new Bon();
+//        b.addProduct(new AclasMessageAllVoid());
+        if(suma == 0) {
+            return;
+        } else {
+            b.addSale(new IncotexMessageDrawerCashEntry(suma));
+        }
+        driver.addBon(b);
+    }
+
+    public boolean numerarInputReady() {
+        return true;
+    }
+
+    @Override
+    public void finishInitialize() {
+        super.finishInitialize();
+        startECR();
+    }
+
+
+    public void startECR() {
+        driver = new IncotexImpl(port);
+        driver.setName("IncotexImpl");
+        driver.start();
+    }
+
+    public void deleteNonPrintedBons() {
+        if(inter != null) {
+            driver.deleteNonPrintedBons(inter);
+        }
+    }
+
+    public int getNoOfBonsToPrint() {
+        if(driver != null)
+            return driver.getNoOfBonsToPrint();
+        else return 0;
+    }
+
+    public void forceTotal() {
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/IncotexImpl.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/IncotexImpl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,164 @@
+package ro.atreides.ecr.incotex;
+
+import gnu.io.CommPortIdentifier;
+import gnu.io.PortInUseException;
+import gnu.io.SerialPort;
+import ro.atreides.ecr.datecs.nativeImpl.PortSettings;
+import ro.atreides.ecr.incotex.noarch.Bon;
+import ro.atreides.ecr.incotex.noarch.IncotexNoarchImpl;
+import ro.atreides.ecr.incotex.noarch.messages.*;
+import ro.deversoft.utils.noarch.Formatters;
+import ro.atreides.utils.Logger;
+import ro.atreides.utils.TextUtils;
+import ro.atreides.utils.Utils;
+import ro.atreides.utils.gui.GuiUtils;
+import ro.atreides.utils.gui.Validators;
+import ro.atreides.utils.gui.dialogs.DialogUtils;
+import ro.atreides.utils.multilang.LangRoAll;
+import ro.atreides.utils.tricky.NonPrintedBonInterface;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Vector;
+
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 9:32:19 AM
+ */
+public class IncotexImpl extends IncotexNoarchImpl {
+
+    private String portName ;
+
+    public IncotexImpl(String port) {
+        this.portName = port;
+    }
+
+    public void run() {
+
+        int speed = 9600, dataBits = 8, stopBits = 1,parity = 0;
+
+        String driverName = "incotex";
+
+        SerialPort serialPort = null;
+
+        if(Validators.correctString(portName)) {
+
+            while(true) {
+
+                boolean portFound = false;
+                CommPortIdentifier portId = null;
+                Enumeration portList;
+
+                String message = "initializing port: " + portName;
+//                screenLogger.log(message);
+
+
+                try {
+
+                    if(portName.startsWith("tcp")) {
+
+                        Vector<String> items = Utils.splitString(portName, '=');
+                        if(items.size() < 3 || !Validators.correctString(items.get(1)) || !Validators.correctInteger(items.get(2))) {
+                            Logger.logError(this, "Configurare incorecta . Eroare fatala!!");
+                            Utils.systemExit();
+                        }
+
+                        String ip = items.get(1);
+                        int port = Integer.parseInt(items.get(2));
+
+                        Socket s = new Socket();
+                        SocketAddress sa = new InetSocketAddress(ip, port);
+
+                        s.connect(sa);
+
+                        inS = s.getInputStream();
+                        outS = s.getOutputStream();
+
+
+                    } else {
+
+
+                        portList = CommPortIdentifier.getPortIdentifiers();
+                        while (portList.hasMoreElements()) {
+                            portId = (CommPortIdentifier) portList.nextElement();
+                            if (portId.getName().equalsIgnoreCase(portName)) {
+                                message = "Found port: " + portName;
+//                        screenLogger.log(message);
+                                portFound = true;
+                                break;
+                            }
+                        }
+                        if (!portFound) {
+                            message = "Port incorect: "+portName;
+                            DialogUtils.errorDialog(GuiUtils.currentFrame, driverName + ": port incorect : \"" + portName + "\"." +
+                                    " Corectati si reporniti !!", LangRoAll.nuPotContinua);
+                            break;
+                        }
+
+
+                        PortSettings settings = new PortSettings();
+                        settings.setName(portName);
+                        settings.setSpeed(speed);
+                        settings.setDataBits(dataBits);
+                        settings.setStopBits(stopBits);
+                        settings.setPariry(parity);
+
+                        message = ">>>>> Opening port: "+portName+"";
+//                    screenLogger.log(message);
+
+                        serialPort = (SerialPort) portId.open(driverName, 2000);
+
+//                        serialPort.setRTS( settings.isRTS() );
+
+                        inS = serialPort.getInputStream();
+                        outS = serialPort.getOutputStream();
+
+                        serialPort.setSerialPortParams( settings.getSpeed(), settings.getDataBits(), settings.getStopBits(), settings.getPariry());
+
+                        message = "Setari port serial DUPA setParams :" +
+                                " baudRate=" + serialPort.getBaudRate() +
+                                " dataBits=" + serialPort.getDataBits() +
+                                " stopBits=" + serialPort.getStopBits() +
+                                " parity=" + serialPort.getParity();
+//                    screenLogger.log(message);
+
+                    }
+
+                    startWork();
+
+
+                } catch (PortInUseException e) {
+                    DialogUtils.errorDialog(GuiUtils.currentFrame, driverName + ": port ocupat : \"" + portName + "\"", LangRoAll.nuPotContinua);
+                } catch(Exception e) {
+                    e.printStackTrace();
+                } catch ( Throwable th) {
+                } finally {
+                    if(serialPort!=null)
+                        serialPort.close();
+                    message = "Am inchis portul: "+portName;
+//                    screenLogger.log(message);
+                }
+
+                try {
+                    Thread.sleep(5000);
+                } catch (InterruptedException e) {
+                }
+            }
+        } else {
+            DialogUtils.errorDialog(GuiUtils.currentFrame, driverName + ": port nedefinit. Corectati si reporniti !!", LangRoAll.nuPotContinua);
+        }
+    }
+
+    public void deleteNonPrintedBons(NonPrintedBonInterface inter) {
+        outQueue.clear();
+    }
+
+}
+
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/Bon.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/Bon.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,60 @@
+package ro.atreides.ecr.incotex.noarch;
+
+import ro.atreides.ecr.incotex.noarch.messages.IncotexMessage;
+
+import java.util.Vector;
+
+public class Bon {
+    private Vector<IncotexMessage> produse = new Vector();
+//    private Vector<IncotexMessage> comentarii = new Vector();
+//    private Vector<IncotexMessage> payments = new Vector();
+    private float adaosTotal;
+
+    public Bon(){
+    }
+
+    public void addSale(IncotexMessage p){
+        if(p != null)
+            produse.add(p);
+    }
+
+    public Vector<IncotexMessage> getSales(){
+        return produse;
+    }
+
+//    public void addComment(String comment){
+//        if(comment != null){
+//            comentarii.add(comment);
+//        }
+//    }
+
+//    public Vector<IncotexMessage> getComments(){
+//        return comentarii;
+//    }
+
+    public float getAdaosTotal() {
+        return adaosTotal;
+    }
+
+    public void setAdaosTotal(float adaosTotal) {
+        this.adaosTotal = adaosTotal;
+    }
+
+//    public void addPayment(IncotexMessage p){
+//        payments.add(p);
+//    }
+
+//    public Vector<IncotexMessage> getPayments() {
+//        return payments;
+//    }
+
+    public String toString() {
+        StringBuffer buffer = new StringBuffer("Bon {");
+        for (int i = 0; i < produse.size(); i++) {
+            buffer.append("\n\t" + produse.get(i));
+        }
+        buffer.append("\n\tadaos all: " + adaosTotal + "%");
+        buffer.append("\n}");
+        return buffer.toString();
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/IncotexNoarchImpl.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/IncotexNoarchImpl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,233 @@
+package ro.atreides.ecr.incotex.noarch;
+
+import ro.atreides.ecr.incotex.noarch.messages.IncotexMessage;
+import ro.atreides.ecr.incotex.noarch.messages.IncotexMessageResponse;
+//import ro.atreides.utils.TextUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Date;
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 6/3/13
+ * Time: 12:45 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class IncotexNoarchImpl extends Thread {
+
+    protected InputStream inS;
+
+    protected OutputStream outS;
+
+    private boolean mustRun = true;
+
+    protected Vector outQueue = new Vector();
+
+    public void addBon(Bon b) {
+        outQueue.add(b);
+    }
+
+    private IncotexMessageResponse write(IncotexMessage toWrite, OutputStream outS, InputStream inS) throws IOException {
+        byte [] stream = toWrite.getBytes();
+//        System.out.println(new Date() + " Write: " + TextUtils.getHexString(stream, true) + "||");
+//        System.out.flush();
+        outS.write(stream);
+        outS.flush();
+        IncotexMessageResponse mess = getReponse(inS, 5000);
+        return mess;
+    }
+
+    private void emptyInputBuffer(long readTimeout) throws IOException {
+        int toRead = 0;
+        long start = System.currentTimeMillis();
+        while ( toRead > 0 && System.currentTimeMillis() < start + readTimeout) {
+            try { Thread.sleep(100); } catch (InterruptedException e) { }
+            inS.read();
+            toRead = inS.available();
+        }
+    }
+
+    private IncotexMessageResponse getReponse(InputStream inS, long readTimeout) throws IOException {
+
+        long start = System.currentTimeMillis();
+
+        int toRead = 0;
+        while ( toRead <= 0 && System.currentTimeMillis() < start + readTimeout) {
+            try { Thread.sleep(100); } catch (InterruptedException e) { }
+            toRead = inS.available();
+        }
+
+        if(toRead <= 0)
+            return new IncotexMessageResponse(IncotexMessageResponse.ERROR_TIMEOUT);
+
+
+        int synMax = 50;
+
+        while(synMax > 0) {
+
+            //avem ceva
+            int ch = inS.read();
+
+            /*
+           while(ch != IncotexMessage.START_PACKET && toRead > 0 ) {
+                   //skip pana la inceputul unui pachet
+                   ch = inS.read();
+                   toRead = inS.available();
+               }
+            */
+
+            if(ch == IncotexMessage.NACK) {
+
+                return new IncotexMessageResponse(IncotexMessageResponse.ERROR_RECEIVED_NACK);
+
+            } else if(ch == IncotexMessage.SYN) {
+
+                try { Thread.sleep(100); } catch (InterruptedException e) { }
+
+                synMax --;
+
+                continue;
+
+            } else if(ch == IncotexMessage.START_PACKET) {
+
+                byte [] buffer = new byte[65535];
+
+                //avem un inceput de pachet
+                buffer[0] = (byte)ch;
+
+                //citim pana la sf pachetului
+                long endOfPacketTimeout = 10 * readTimeout;
+                start = System.currentTimeMillis();
+
+                int i = 1;
+                boolean packetfound = false;
+                while(System.currentTimeMillis() < start + endOfPacketTimeout) {
+                    toRead = inS.available();
+                    if(toRead > 0) {
+                        ch = inS.read();
+//                    System.out.println("Am citit : " + (char) ch);
+                        buffer[i] = (byte)ch;
+                        i++;
+                        if(ch == IncotexMessage.END_PACKET) {
+                            packetfound = true;
+                            break;
+                        }
+                    } else {
+                        try { Thread.sleep(100); } catch (InterruptedException e) { }
+                    }
+                }
+
+                if(!packetfound) {
+                    //todo timeout, primit pachetul pe jumatate
+
+                    return new IncotexMessageResponse(IncotexMessageResponse.ERROR_TIMEOUT);
+
+                } else {
+
+                    byte [] buffer2 = new byte[i];
+                    System.arraycopy(buffer, 0, buffer2, 0, buffer2.length);
+//                    System.out.println(new Date() + " Read: " + TextUtils.getHexString(buffer2, true) + "");
+//                    System.out.flush();
+
+                    return new IncotexMessageResponse(buffer2);
+                }
+            } else {
+                return new IncotexMessageResponse(IncotexMessageResponse.ERROR_STRANGE_CHARS);
+            }
+        }
+
+        return new IncotexMessageResponse(IncotexMessageResponse.ERROR_TIMEOUT);
+    }
+
+    public final int getNoOfBonsToPrint() {
+        return outQueue.size();
+    }
+
+    public void setMustRun(boolean mustRun) {
+        this.mustRun = mustRun;
+    }
+
+    protected void startWork() throws IOException {
+        boolean error = false;
+        final int maxTries = 5;
+        int tries = 0;
+
+        while(mustRun) {
+
+            if(outQueue.size() > 0) {
+
+                Bon bon = (Bon)outQueue.get(0);
+
+                int seq = 1;
+                int respSeq = 1;
+
+                Vector<IncotexMessage> products = bon.getSales();
+                for (IncotexMessage query : products) {
+                    seq ++;
+
+                    query.setPacketNo(seq);
+                    IncotexMessageResponse resp = write(query, outS, inS);
+
+                    if(resp.isNack()) {
+                        System.out.println("incotex: Received NACK !!!");
+                    } else if(resp.isTimeout()) {
+                        System.out.println("incotex: TIMEOUT !!!");
+                    } else {
+                        respSeq = resp.getPacketNo();
+
+                        if(respSeq != seq) {
+                            //a luat-o razna , trebuie anulat tot si luat de la capat
+                            System.out.println("incotex: Secventa gresita message=" + seq + " resp=" + respSeq);
+
+                        } else {
+                            //am primit rasp pozitiv de la casa
+                            System.out.println("incotex: Secventa corecta message=" + seq + " resp=" + respSeq);
+//                                            if(resp.isError()) {
+//                                                System.out.println("error code : " + resp.getErrorCodeDecimal());
+//                                                error = true;
+//                                                break;
+//                                            }
+                        }
+                    }
+
+                    try {
+                        Thread.sleep(50);
+                    } catch (InterruptedException e) {
+                    }
+                }
+
+                if(!error) {
+                    outQueue.remove(0);
+                    tries = 0;
+                } else {
+                    if(tries >= maxTries) {
+                        //todo print error message, ask user
+                        System.out.println("incotex: Eroare fatala - am renuntat");
+                        outQueue.remove(0);
+                    } else {
+                        emptyInputBuffer(5000);
+                        tries ++;
+                    }
+                    error = false;
+                }
+            } else {
+                try {
+                    Thread.sleep(100);
+                } catch (InterruptedException e) {
+                }
+            }
+        }
+    }
+
+    public void setInS(InputStream inS) {
+        this.inS = inS;
+    }
+
+    public void setOutS(OutputStream outS) {
+        this.outS = outS;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/Utils.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/Utils.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,41 @@
+package ro.atreides.ecr.incotex.noarch;
+
+import java.text.DecimalFormat;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 6/3/13
+ * Time: 1:10 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Utils {
+
+    public static final DecimalFormat NUMBER_2DECIMALS_NO_TRUNC = new DecimalFormat("###0.00");
+
+    public static String getString2DecimalsNoTrunc(float number) {
+        String result = NUMBER_2DECIMALS_NO_TRUNC.format(number);
+        return result;
+    }
+
+    public static String getStringMaxSize(int totalDigits, String toConvert, Character fillChar, boolean before) {
+//        System.out.println("toConvert: \"" + toConvert + "\"" + " totalDigits " + totalDigits + " before : " + before);
+        if(toConvert == null)
+            toConvert = "";
+
+        if(toConvert.length() > totalDigits)
+            return toConvert.substring(0, totalDigits);
+        else if(toConvert.length() < totalDigits) {
+            String result = toConvert;
+            if(fillChar != null)
+                for(int i = toConvert.length() ; i < totalDigits ; i++) {
+                    if(before) {
+                        result = fillChar.charValue() + result;
+                    } else {
+                        result += fillChar.charValue();
+                    }
+                }
+            return result;
+        } else return toConvert;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/XmlParser.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/XmlParser.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,132 @@
+package ro.atreides.ecr.incotex.noarch;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+import ro.atreides.ecr.incotex.noarch.messages.*;
+
+import java.util.Hashtable;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 7/19/13
+ * Time: 8:56 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class XmlParser extends DefaultHandler {
+
+    IncotexNoarchImpl driver ;
+
+    Bon currentBon = null;
+
+    Hashtable<String, String> paymentTypesCodes = new Hashtable<String, String>();
+
+    String idBon = "";
+    String idOrder = "";
+
+    float totalSales = 0;
+    float totalPlati = 0;
+
+    boolean demo;
+
+    public XmlParser(IncotexNoarchImpl  driver, boolean isDemo) {
+        this.driver = driver;
+        this.demo = isDemo;
+        paymentTypesCodes.put("CASH", "P");
+        paymentTypesCodes.put("CARD", "N");
+        paymentTypesCodes.put("TICKET", "C");
+    }
+
+    public void startElement(String uri, String qName, String localName, Attributes attributes) throws SAXException {
+
+        if(qName.equalsIgnoreCase("product")) {
+            String product = attributes.getValue("label");
+            String priceS = attributes.getValue("price");
+            String qS = attributes.getValue("quantity");
+
+            String vatCode = attributes.getValue("vat");
+
+            float q = Float.parseFloat(qS);
+            float priceDupaDiscount = Float.parseFloat(priceS);
+
+            //todo reducerile !
+
+            IncotexMessageSaleProduct sale = new IncotexMessageSaleProduct(priceDupaDiscount, q, product, 'A'/*vatCode.charAt(0)*/);//todo sa primim cota numerica tva, si o mapam ca la payments
+            currentBon.addSale(sale);
+
+            totalSales += q * priceDupaDiscount;
+
+
+
+        } else if(qName.equalsIgnoreCase("ad")){
+            String text = attributes.getValue("text");
+            if(text!=null && text.length()>0)
+                text = " ";
+
+            IncotexMessageComment sale = new IncotexMessageComment(text);
+            currentBon.addSale(sale);
+
+        } else if(qName.equalsIgnoreCase("discount")){
+            attributes.getValue("percent");
+
+            //todo
+
+        } else if(qName.equalsIgnoreCase("adaos")){
+            attributes.getValue("percent");
+
+            //todo
+
+        } else if(qName.equalsIgnoreCase("payment")){
+            String type = attributes.getValue("type");
+            type = type.toUpperCase();
+            String codCasa = (String) paymentTypesCodes.get(type);
+            String valueS = attributes.getValue("amount");
+
+            float value = Float.parseFloat(valueS);
+
+            IncotexMessagePayment payment = new IncotexMessagePayment(codCasa, value);
+            currentBon.addSale(payment);
+
+            totalPlati += value;
+
+        } else if(qName.equalsIgnoreCase("receipt")){
+            idBon = attributes.getValue("bonId");
+            idOrder = attributes.getValue("idOrder");
+
+            currentBon = new Bon();
+
+            currentBon.addSale(new IncotexMessageAllVoid());
+
+            currentBon.addSale(new IncotexMessageOpenFiscalReceipt());
+
+            totalSales = 0;
+            totalPlati = 0;
+        }
+    }
+
+    @Override
+    public void endElement(String uri, String localName, String qName) throws SAXException {
+
+        if(qName.equalsIgnoreCase("receipt")) {
+
+            if(totalPlati < totalSales) {
+                currentBon.addSale(new IncotexMessagePaymentCashRest());
+            }
+
+            if(demo) {
+                currentBon.addSale(new IncotexMessageComment(" "));
+                IncotexMessageComment sale = new IncotexMessageComment("Soft by www.DeverSoft.ro");
+                currentBon.addSale(sale);
+                currentBon.addSale(new IncotexMessageComment(" "));
+            }
+
+            currentBon.addSale(new IncotexMessageCloseFiscalReceipt());
+
+            driver.addBon(currentBon);
+
+            idBon = "";
+            idOrder = "";
+        }
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessage.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessage.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,110 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 9:32:45 AM
+ */
+public class IncotexMessage {
+
+    public static final byte START_PACKET = 0x01;
+    public static final byte END_PACKET = 0x03;
+    public static final byte START_BCC = 0x05;
+    public static final byte START_STATUS = 0x04;
+
+    public static final byte NACK = 0x15;
+    public static final byte SYN = 0x16;
+
+    protected byte command;
+
+    protected int packetNo;
+
+    protected byte [] data;
+
+    public int getPacketNo() {
+        return packetNo;
+    }
+
+    public void setPacketNo(int packetNo) {
+        this.packetNo = packetNo + 0x20;
+    }
+
+    public byte[] getData() {
+        return data;
+    }
+
+    public void setData(byte[] data) {
+        this.data = data;
+    }
+
+    public byte [] getBytes() {
+
+        int size = 10;
+        if(data != null) {
+            size += data.length;
+        }
+        byte [] result = new byte[size];
+
+
+        result[0] = START_PACKET;
+
+        result[1] = (byte)(size - 6  + 32 );
+
+        result[2] = (byte)packetNo;
+
+        result[3] = command;
+
+        if(data != null)
+            System.arraycopy(data, 0, result, 4, data.length);
+
+        result[size - 6] = START_BCC;
+
+
+        /*
+Check sum (0000h-FFFFh)
+Length: 4 bytes; value: 30h - 3Fh
+The check sum is formed by the bytes following <01> (without it) to <05> included. Each
+digit is sent as an ASCII code, for instance the check sum 1893h is represented as 31h,
+38h, 39h, 33h.
+         */
+
+        //todo de verificat checksumming-ul
+        long checksum = 0;
+        for( int i = 1 ; i < size - 5 ; i++ ) {
+            checksum += result[i];
+        }
+
+        byte b4 = ( byte ) ( checksum % 16 + 0x30 );
+
+        checksum /= 16;
+        byte b3 = ( byte ) ( checksum % 16 + 0x30);
+
+        checksum /= 16;
+        byte b2 = ( byte ) ( checksum % 16 + 0x30);
+
+        checksum /= 16;
+        byte b1 = ( byte ) ( checksum % 16 + 0x30);//todo daca am 'a' si adaug 30 ce se intampla ?
+
+        result[size - 5 ] = b1;
+        result[size - 4 ] = b2;
+        result[size - 3 ] = b3;
+        result[size - 2 ] = b4;
+
+        result[size - 1] = END_PACKET;
+
+        return result;
+    }
+
+    public static final void main(String [] args) {
+
+        //test de crc !
+        String message = "01 29 34 30 31 2C 30 2C 31 05 30 31 37 3C 03";
+
+        IncotexMessageOpenFiscalReceipt openFiscalReceipt = new IncotexMessageOpenFiscalReceipt();
+        openFiscalReceipt.setPacketNo(0x34);
+        byte [] array = openFiscalReceipt.getBytes();
+
+//        System.out.println(TextUtils.getHexString(array, true ));
+
+        System.out.println("done");
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageAllVoid.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageAllVoid.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,14 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessageAllVoid extends IncotexMessage {
+
+    public IncotexMessageAllVoid() {
+        command = (byte)0x82;//todo de verificat !
+        //data is null
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageCloseFiscalReceipt.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageCloseFiscalReceipt.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,13 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessageCloseFiscalReceipt extends IncotexMessage {
+
+    public IncotexMessageCloseFiscalReceipt() {
+        command = 0x38;
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageComment.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageComment.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,17 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessageComment extends IncotexMessage {
+
+    public IncotexMessageComment(String comment) {
+        command = 0x36;
+
+        String s = comment;
+        data = s.getBytes();
+    }
+
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageDrawerCashEntry.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageDrawerCashEntry.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,18 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+import ro.atreides.ecr.incotex.noarch.Utils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessageDrawerCashEntry extends IncotexMessage {
+
+    public IncotexMessageDrawerCashEntry(float suma) {
+        command = 0x46;
+
+        String s = Utils.getString2DecimalsNoTrunc(suma);
+        data = s.getBytes();
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageOpenFiscalReceipt.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageOpenFiscalReceipt.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,21 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessageOpenFiscalReceipt extends IncotexMessage {
+
+    //todo : ar fi interesant de setat cum trebuie astea, sa se faca rapoarte pe casa in functie de useri
+    public IncotexMessageOpenFiscalReceipt() {
+        command = 0x30;
+
+        data = new byte[5];
+        data[0] = 0x31;
+        data[1] = 0x2c;
+        data[2] = 0x30;
+        data[3] = 0x2c;
+        data[4] = 0x31;
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessagePayment.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessagePayment.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,34 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+import ro.atreides.ecr.incotex.noarch.Utils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessagePayment extends IncotexMessage {
+
+    public IncotexMessagePayment(String tipPlata, float suma) {
+        command = 0x35;
+
+        String s = "";
+
+//        String commentingText = Utils.getStringMaxSize(28, tipPlata, ' ', false);//todo aici ar intra tipul de plata si detalii !
+//        s += commentingText;
+//
+//        s+=(char)0x0a;
+//        //todo text2 dar nu cred ca trb
+
+        s += (char)0x09;
+        s += tipPlata;
+
+//        s += Utils.getStringMaxSize(1, tipPlata, '0', true);
+
+//        long x = FloatUtils.convertToLong(suma, 2);
+//        String qS = Utils.getStringMaxSize(9, x+"", '0', true);//todo testat cu zecimalele and shit
+
+        s += Utils.getString2DecimalsNoTrunc(suma);
+
+        data = s.getBytes();
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessagePaymentCashRest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessagePaymentCashRest.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,16 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessagePaymentCashRest extends IncotexMessage {
+
+    public IncotexMessagePaymentCashRest() {
+        command = 0x35;
+
+        String s = ""+(char)0x09;
+
+        data = s.getBytes();
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageResponse.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageResponse.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,75 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 21, 2011
+ * Time: 8:29:33 PM
+ */
+public class IncotexMessageResponse {
+
+    private int packetNo;
+
+    private int errorCode;
+
+    public static int ERROR_RECEIVED_RESPONSE_PACKAGE = 1;
+    public static int ERROR_RECEIVED_NACK = 2;
+    public static int ERROR_TIMEOUT = 3;
+    public static int ERROR_STRANGE_CHARS = 4;
+
+    public static int ERROR_ALLOK = 8;
+
+    public boolean isNack() {
+        return errorCode == ERROR_RECEIVED_NACK;
+    }
+
+    public boolean isTimeout() {
+        return errorCode == ERROR_TIMEOUT;
+    }
+
+    public IncotexMessageResponse(int errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    public IncotexMessageResponse(byte[] buffer) {
+        this.errorCode = ERROR_RECEIVED_RESPONSE_PACKAGE;
+
+        int size= buffer[1];
+
+        size -= 32;
+
+        packetNo = buffer[2];
+
+        int dataStart = 4;
+        int dataStop = 0;
+        int statusStart = 0;
+        int statusStop = 0;
+
+        for(int i = 3 ; i < size ; i++ ) {
+            if(buffer[i] == IncotexMessage.START_STATUS) {
+                dataStop = i-1;
+                statusStart = i +1;
+                statusStop = statusStart + 6;
+                break;
+            }
+        }
+
+        if(dataStart < dataStop) {
+            //avem ceva in campul de data
+
+            byte [] data = new byte[dataStop - dataStart];
+            System.arraycopy(buffer, dataStart, data, 0, data.length);
+
+            System.out.println("am primit data " + new String(data));
+
+        }
+
+        byte [] status = new byte[6];
+        System.arraycopy(buffer, statusStart, status, 0, status.length);
+
+
+        System.out.println("am primit data " + new String(status));
+    }
+
+    public int getPacketNo() {
+        return packetNo - 0x20;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageSaleProduct.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageSaleProduct.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,36 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+import ro.atreides.ecr.incotex.noarch.Utils;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessageSaleProduct extends IncotexMessage {
+
+    public IncotexMessageSaleProduct(float price, float quantity, String numeProdus, char cotaTva) {
+        command = 0x31;
+
+        String s = "";
+
+//        String commentingText = Utils.getStringMaxSize(28, numeProdus, ' ', false);//todo nu cred ca trebuie !
+//        s += commentingText;
+
+        s+=(char)0x0a;
+        s += Utils.getStringMaxSize(28, numeProdus, ' ', false);
+
+        s += (char)0x09;//todo incorect 0x0a in documentatie
+        s += cotaTva;
+
+        //todo : sign = correction
+
+        s += Utils.getString2DecimalsNoTrunc(price);
+
+        s += "*";
+        s += Utils.getString2DecimalsNoTrunc(quantity);
+
+        data = s.getBytes();
+    }
+
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageXReport.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageXReport.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,16 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessageXReport extends IncotexMessage {
+
+    public IncotexMessageXReport() {
+        command = 0x45;
+        //data is null
+
+        data = "2".getBytes();
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageZReport.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/messages/IncotexMessageZReport.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,16 @@
+package ro.atreides.ecr.incotex.noarch.messages;
+
+/**
+ * Date: Nov 17, 2011
+ * Time: 10:34:36 AM
+ */
+public class IncotexMessageZReport extends IncotexMessage {
+
+    public IncotexMessageZReport() {
+        command = 0x45;
+        //data is null
+
+        data = "0".getBytes();
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/test/IncotexNoarchEcrPlata.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/test/IncotexNoarchEcrPlata.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,37 @@
+package ro.atreides.ecr.incotex.noarch.test;
+
+public class IncotexNoarchEcrPlata {
+    
+    private float suma;
+    
+    private String ecrMapping, tipPlata;
+
+    public String getTipPlata() {
+        return tipPlata;
+    }
+
+    public void setTipPlata(String tipPlata) {
+        this.tipPlata = tipPlata;
+    }
+
+    public float getSuma() {
+        return suma;
+    }
+
+    public void setSuma(float suma) {
+        this.suma = suma;
+    }
+
+    public String getEcrMapping() {
+        return ecrMapping;
+    }
+
+    public void setEcrMapping(String ecrMapping) {
+        this.ecrMapping = ecrMapping;
+    }
+
+    
+    public String toString() {
+        return "Suma : " + suma + " tipPlata : " + ecrMapping;
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/test/IncotexNoarchEcrSale.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/test/IncotexNoarchEcrSale.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,115 @@
+package ro.atreides.ecr.incotex.noarch.test;
+
+import java.io.Serializable;
+
+/**
+ * @author valy
+ */
+public class IncotexNoarchEcrSale implements Serializable {
+
+    private String product;
+    private float quantity;
+    private float ppuDupaDiscount;
+    private float ppuOriginal;
+    private float discount;
+    private float cotaTva;
+    private int cod;
+    private String departament, codTva;
+    private int grupa;
+
+    private float returPending;
+
+    public float getReturPending() {
+        return returPending;
+    }
+
+    public void setReturPending(float returPending) {
+        this.returPending = returPending;
+    }
+
+    public static final long serialVersionUID = -8871460794490181402L;
+
+
+    public IncotexNoarchEcrSale(String product, float quantity, float ppuDupaDiscount, float ppuOriginal, float discount, int cod,
+                                String departament, int grupa, String codTva, float cotaTva) {
+        this.product = product;
+        this.quantity = quantity;
+        this.ppuDupaDiscount = ppuDupaDiscount;
+        this.cod = cod;
+        this.departament = departament;
+        this.grupa = grupa;
+        this.codTva = codTva;
+        this.ppuOriginal = ppuOriginal;
+        this.discount = discount;
+        this.cotaTva = cotaTva;
+
+        this.setReturPending(Math.abs(ppuDupaDiscount * quantity));
+    }
+
+    public float getCotaTva() {
+        return cotaTva;
+    }
+
+    public float getDiscount() {
+        return discount;
+    }
+
+    public void setDiscount(float discount) {
+        this.discount = discount;
+    }
+
+    public float getPpuOriginal() {
+        return ppuOriginal;
+    }
+
+    public void setPpuOriginal(float ppuOriginal) {
+        this.ppuOriginal = ppuOriginal;
+    }
+
+    public int getCod() {
+        return cod;
+    }
+    public void setCod(int cod) {
+        this.cod = cod;
+    }
+    public float getPpuDupaDiscount() {
+        return ppuDupaDiscount;
+    }
+    public void setPpuDupaDiscount(float ppuDupaDiscount) {
+        this.ppuDupaDiscount = ppuDupaDiscount;
+    }
+    public String getProduct() {
+        return product;
+    }
+    public void setProduct(String product) {
+        this.product = product;
+    }
+    public float getQuantity() {
+        return quantity;
+    }
+    public void setQuantity(float quantity) {
+        this.quantity = quantity;
+    }
+
+    public String getDepartament() {
+        return departament;
+    }
+
+    public int getGrupa() {
+        return grupa;
+    }
+
+    public String getCodTva() {
+        return codTva;
+    }
+
+    public void setCodTva(String codTva) {
+        this.codTva = codTva;
+    }
+
+    public String toString() {
+        return "Product : " + product + " quantity : " + quantity + " ppu : " + ppuDupaDiscount + " cod : " + cod +
+            " departament : " + departament + " grupa : " + grupa + " codTva : " + codTva;
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/noarch/test/IncotexTestNoarch.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/noarch/test/IncotexTestNoarch.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,166 @@
+package ro.atreides.ecr.incotex.noarch.test;
+
+import ro.atreides.ecr.incotex.noarch.Bon;
+import ro.atreides.ecr.incotex.noarch.IncotexNoarchImpl;
+import ro.atreides.ecr.incotex.noarch.messages.*;
+
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 6/3/13
+ * Time: 12:58 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class IncotexTestNoarch {
+
+    public static void prepareMessages(IncotexNoarchImpl driver) {
+        if(driver == null)
+            return;
+
+        Vector<IncotexNoarchEcrSale> sales = new Vector<IncotexNoarchEcrSale>();
+        IncotexNoarchEcrSale s1 = new IncotexNoarchEcrSale("test1",(float)0.01,2,3,1,101,"1",1,"A",(float)0.24);
+        sales.add(s1);
+
+        IncotexNoarchEcrSale s2 = new IncotexNoarchEcrSale("test2",(float)0.01,1,2,1,101,"1",1,"A",(float)0.24);
+        sales.add(s2);
+
+        Vector<IncotexNoarchEcrPlata> plati = new Vector<IncotexNoarchEcrPlata>();
+        IncotexNoarchEcrPlata p1 = new IncotexNoarchEcrPlata();
+        p1.setEcrMapping("P");
+        p1.setSuma((float)0.02);
+        p1.setTipPlata("Numerar");
+        plati.add(p1);
+
+        setSale(driver, sales, plati);
+
+//        setSale(driver, sales, plati);
+//
+//        setSale(driver, sales, plati);
+//
+//        setSale(driver, sales, plati);
+
+//        sendPayRest(driver);
+
+//        sendZReport(driver);
+    }
+
+    public static void setSale(IncotexNoarchImpl driver, Vector<IncotexNoarchEcrSale> sales, Vector<IncotexNoarchEcrPlata> plati) {
+
+
+        Bon b = new Bon();
+        b.addSale(new IncotexMessageAllVoid());
+
+        IncotexMessage openFiscalReceipt = new IncotexMessageOpenFiscalReceipt();
+        b.addSale(openFiscalReceipt);
+
+        float totalOriginal = 0;
+        float totalDiscount = 0;
+        float total = 0;
+        for (Object o : sales) {
+            IncotexNoarchEcrSale sale = (IncotexNoarchEcrSale)o;
+
+            float price = sale.getPpuDupaDiscount();
+//            if(discountGlobal || discountLaProdus) {
+//                price = sale.getPpuOriginal();
+//            }
+
+            IncotexMessageSaleProduct produs = new IncotexMessageSaleProduct(price, sale.getQuantity(),
+                    sale.getProduct(), sale.getCodTva().charAt(0));
+            b.addSale(produs);
+
+//            if(discountLaProdus) {
+//                b.addProduct(calculeazaProcentDiscount(sale.getPpuOriginal(), sale.getDiscount(), false));
+//            } else if(discountGlobal) {
+            totalDiscount += sale.getDiscount() * sale.getQuantity();
+            totalOriginal += sale.getPpuOriginal() * sale.getQuantity();
+//            }
+
+            total += sale.getPpuDupaDiscount() *sale.getQuantity();
+        }
+
+//        if(discountGlobal && totalDiscount != 0) {
+//            AclasMessageDiscount disc = calculeazaProcentDiscount(totalOriginal, totalDiscount, true);
+//            if(disc != null) {
+//                b.addProduct(new AclasMessageTotalDue());
+//                b.addProduct(disc);
+//            }
+//        }
+
+
+
+
+        float totalPlatit = 0;
+        for(Object o : plati) {
+            IncotexNoarchEcrPlata plata = (IncotexNoarchEcrPlata)o;
+            IncotexMessagePayment payment = new IncotexMessagePayment(plata.getEcrMapping(), plata.getSuma());
+            b.addSale(payment);
+            totalPlatit += plata.getSuma();
+        }
+
+//        //force total
+        if(totalPlatit < total) {
+            IncotexMessagePaymentCashRest payment = new IncotexMessagePaymentCashRest();
+            b.addSale(payment);
+        }
+
+
+        b.addSale(new IncotexMessageComment(" "));
+        IncotexMessageComment sale = new IncotexMessageComment("Soft by www.DeverSoft.ro");
+        b.addSale(sale);
+        b.addSale(new IncotexMessageComment(" "));
+
+        IncotexMessage closeFiscalReceipt = new IncotexMessageCloseFiscalReceipt();
+        b.addSale(closeFiscalReceipt);
+
+
+        //todo de vazut cum e cu sertarul !
+//        AclasMessageOpenDrawer drawer = new AclasMessageOpenDrawer();
+//        b.addProduct(drawer);
+
+        driver.addBon(b);
+
+    }
+
+    private static void sendCancel(IncotexNoarchImpl impl) {
+        if(impl == null)
+            return;
+
+        Bon b = new Bon();
+        b.addSale(new IncotexMessageAllVoid());
+        impl.addBon(b);
+    }
+
+    public static void sendZReport(IncotexNoarchImpl impl) {
+        if(impl == null)
+            return;
+
+        Bon b = new Bon();
+        b.addSale(new IncotexMessageZReport());
+        impl.addBon(b);
+    }
+
+    public static void sendXReport(IncotexNoarchImpl impl) {
+        if(impl == null)
+            return;
+
+        Bon b = new Bon();
+        b.addSale(new IncotexMessageXReport());
+        impl.addBon(b);
+    }
+
+//    private static void sendPayRest(IncotexNoarchImpl impl) {
+//        if(impl == null)
+//            return;
+//
+//        Bon b = new Bon();
+//        b.addSale(new IncotexMessagePaymentCashRest());
+//
+//        IncotexMessage closeFiscalReceipt = new IncotexMessageCloseFiscalReceipt();
+//        b.addSale(closeFiscalReceipt);
+//
+//        impl.addBon(b);
+//    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/incotex/test/IncotexTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/incotex/test/IncotexTest.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,32 @@
+package ro.atreides.ecr.incotex.test;
+
+import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.EcrSale;
+import ro.atreides.ecr.incotex.noarch.Bon;
+import ro.atreides.ecr.incotex.IncotexImpl;
+import ro.atreides.ecr.incotex.noarch.messages.*;
+import ro.atreides.ecr.incotex.noarch.test.IncotexTestNoarch;
+
+import java.util.Vector;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: valy
+ * Date: 6/3/13
+ * Time: 10:22 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class IncotexTest {
+
+    public static final void main(String [] args) {
+        IncotexImpl driver = new IncotexImpl("/dev/ttyS100");
+        driver.start();
+
+//        sendCancel(driver);
+
+        IncotexTestNoarch.prepareMessages(driver);
+
+
+    }
+
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/mercury/MercuryXmlHandler.java
--- a/src/ro/atreides/ecr/mercury/MercuryXmlHandler.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/mercury/MercuryXmlHandler.java	Fri Sep 13 19:21:02 2013 +0300
@@ -3,6 +3,7 @@
 import org.xml.sax.helpers.DefaultHandler;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
+import ro.atreides.ecr.incotex.noarch.Bon;
 import ro.atreides.ecr.mercury.nativeImpl.requests.FiscalSale;
 import ro.atreides.ecr.mercury.nativeImpl.requests.Payment;
 import ro.atreides.ecr.mercury.nativeImpl.bons.MercuryFiscalReceiptImpl;
diff -r e6b80a8b200a src/ro/atreides/ecr/mercury/nativeImpl/MercuryDriverInterface.java
--- a/src/ro/atreides/ecr/mercury/nativeImpl/MercuryDriverInterface.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/mercury/nativeImpl/MercuryDriverInterface.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,7 +1,7 @@
 package ro.atreides.ecr.mercury.nativeImpl;
 
+import ro.atreides.ecr.EcrDialogUtils;
 import ro.atreides.ecr.SerialDriverInterfaceImpl;
-import ro.atreides.ecr.datecs.nativeImpl.EcrDialogUtils;
 import ro.atreides.utils.gui.GuiUtils;
 import ro.atreides.utils.gui.dialogs.DialogUtils;
 import ro.atreides.utils.multilang.LangRoAll;
diff -r e6b80a8b200a src/ro/atreides/ecr/optima/Generic.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/optima/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,342 @@
+package ro.atreides.ecr.optima;
+
+import ro.atreides.ecr.AbstractCashRegister;
+import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.EcrSale;
+import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
+import ro.atreides.utils.gui.Validators;
+import ro.atreides.utils.plati.TipPlata;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * @author valy
+ */
+public class Generic extends AbstractCashRegister {
+
+    private String tvaDefault = "1";
+
+    private int nonFiscalIndex = 1;
+
+    private String onlineNfDestinationMask;
+
+    public Generic() {
+        super();
+    }
+
+    @Override
+    public void printZ() {
+        String items = "15";
+        pt.addToQueue(items);
+    }
+
+    @Override
+    public void printX() {
+//        String items = "30";
+//        pt.addToQueue(items);
+    }
+
+    @Override
+    public void introduNumerar(float suma) {
+
+//        long printPrice = 1;
+//        for (int i = 0; i < onlineDecimalPlaces; i++) {
+//            printPrice *= 10;
+//        }
+//        long l = 0;
+//
+//        String explicatii = "";
+//        String tip = "";
+//        if(suma < 0) {
+//            l = (long)(-suma * printPrice);
+//            tip = "1";
+//            explicatii = "PLATI";
+//        } else {
+//            explicatii = "SOLD INITIAL";
+//            tip = "2";
+//            l = (long)(suma * printPrice);
+//        }
+//
+//        explicatii = Utils.getStringMaxSize(32, explicatii, null, false);
+//
+//        String items = "25;" + tip + ";" + l + ";" + explicatii;
+//
+//        pt.addToQueue(items);
+    }
+
+    @Override
+    public boolean numerarInputReady() {
+        return false;
+    }
+
+    public void buildConfiguration(Properties conf) {
+        super.buildConfiguration(conf);
+
+        onlineNfDestinationMask = conf.getProperty("nonfiscalReceiptDestinationMask", onlineDirectory + File.separator + "Online_nf_%%nrbon%%.txt");
+    }
+
+    public void printBonFiscal(Vector<EcrSale> sales, float total, Vector<EcrPlata> plati, TipPlata cashDefault, Vector<String> comments, String orderIdentifier, int idOrder) {
+
+        /*
+        2;TEXT ADITIONAL ARTICOL
+        1;ARTICOL 1;1;1;1200;123456
+        7;1;0;1;1200;0;0
+        1;ARTICOL 2;2;2;1100;123400
+        1;ARTICOL 3;3;1;1234;123400
+        7;0;0;1;1234;0;0
+        1;ARTICOL 4;4;2;1234;123400
+        7;1;0;1;0;1100;1
+        1;ARTICOL 5;5;1;1200;123400
+        7;0;0;1;0;1000;1
+        1;ARTICOL6;0;1;1200;123400
+        7;1;1;1;1000;0;0
+        5;1000;2;1;0
+        5;1000;3;1;0
+        5;1000;4;1;0
+        5;1000;5;1;0
+        5;1000;6;1;0
+        5;3000;1;1;0
+        Text aditional
+        Vanzare ARTICOL 1, UM 1, TVA A, pret 12,00, cant. 1,23456
+        Discount procentual la articol -12,00%
+        Vanzare ARTICOL 2, UM 2, TVA B, pret 11,00, cant. 1,234
+        Vanzare ARTICOL 3, UM 3, TVA A, pret 12,34, cant. 1,234
+        Adaos procentual la articol +12,34%
+        Vanzare ARTICOL 4, UM 4, TVA A, pret 12,34, cant. 1,234
+        Discount valoriv la articol -1,00%
+        Vanzare ARTICOL 1, UM 5, TVA A, pret 12,00, cant. 1,234
+        Adaos valoric la articol -10,00%
+        Vanzare ARTICOL 1, UM 0, TVA A, pret 12,00, cant. 1,234
+        Discount procentual la SUBTOTAL  -10,00%
+        Plata partiala de 10,00 cu CEC
+        Plata partiala de 10,00 cu CARD 1
+        Plata partiala de 10,00 cu CARD 2
+        Plata partiala de 10,00 cu BON MASA
+        Plata partiala de 10,00 cu TICHET CADOU
+        Plata partiala de 30,00 cu NUMERAR
+         */
+
+
+        String items = "";
+
+        long priceZeros = 1;
+        for (int i = 0; i < onlineDecimalPlaces; i++) {
+            priceZeros *= 10;
+        }
+
+        Vector<EcrSale> realSales = new Vector<EcrSale>();
+        Vector<EcrSale> returSales = new Vector<EcrSale>();
+
+        boolean bonCuRetur = false;
+        for (EcrSale sale : sales) {
+            if(sale.getQuantity() <0) {
+                returSales.add(sale);
+                bonCuRetur = true;
+            } else {
+                realSales.add(sale);
+            }
+        }
+
+
+        for (EcrSale newsaleentry : realSales) {
+
+            String product = newsaleentry.getProduct();
+            float nrPortii = newsaleentry.getQuantity();
+
+            float orig = newsaleentry.getPpuOriginal();
+            float cuReducere = newsaleentry.getPpuDupaDiscount();
+
+            if(bonCuRetur)
+                orig = cuReducere;
+
+
+            long p = (long)(priceZeros * orig);
+
+            long q = (long)(100000 * nrPortii);
+
+            String codTva = "" + tvaDefault;
+            if(Validators.correctString(newsaleentry.getCodTva())) {
+                codTva = newsaleentry.getCodTva();
+            }
+
+
+            String prodLabel = Utils.getStringMaxSize(18,product, ' ', false);
+
+            String commandText = "1;" + prodLabel + ";1;" + codTva + ";" + p + ";" + q ;
+
+            items += commandText;
+            items += "\n";
+
+            if(orig != cuReducere) {
+                String tip = "";
+
+                long origL = (long)(priceZeros * orig);
+                long cuReducereL = (long)(priceZeros * cuReducere);
+                long val = 0;
+
+                if(orig > cuReducere) {
+                    tip = "1";
+                    val = origL - cuReducereL;
+                } else {
+                    tip = "0";
+                    val = cuReducereL - origL;
+                }
+
+                String line = "7;" + tip + ";0;1;0;" + val + ";1";
+                //7;1;0;1;0;230;1
+                items += line + "\n";
+            }
+
+            float totalReturAcum = 0;
+
+            for (EcrSale returSale : returSales) {
+
+                if(returSale.getReturPending() <= 0)
+                    continue;
+
+                float valoareProdus = newsaleentry.getReturPending();
+
+                float returCurent = returSale.getReturPending();
+
+                if(valoareProdus == returCurent) {
+
+                    //avem un retur egal cu produsul - done
+                    //platim direct cat e fara complicatii
+
+                    returSale.setReturPending(0);
+
+                    totalReturAcum = returCurent;
+
+                    break;
+
+                } else if (valoareProdus > returCurent) {
+
+                    //avem un retur mai mic decat produsul
+                    //adunam mai multe retururi pana se face valoarea produsului
+
+                    float diff = valoareProdus - returCurent;
+
+                    newsaleentry.setReturPending(diff);
+                    returSale.setReturPending(0);
+
+                    totalReturAcum += returCurent;
+
+                } else if(valoareProdus < returCurent) {
+
+                    //avem un retur mai mare decat produsul
+                    //platim produsul, pastram restul de retur pt mai incolo
+
+                    float diff = returCurent - valoareProdus;
+
+                    returSale.setReturPending(diff);
+
+                    totalReturAcum = valoareProdus;
+
+                    break;
+
+                }
+
+            }
+
+            if(totalReturAcum >0) {
+
+                String tip = "";
+                tip = "1";
+
+                long val = (long)(totalReturAcum * priceZeros);
+
+                //urmeaza mecanismul de storno produse prin discount
+                String line = "7;" + tip + ";0;1;0;" + val + ";1";
+
+                items += line + "\n";
+            }
+        }
+
+        for (int i = 0; i < comments.size(); i++) {
+            String o = (String) comments.elementAt(i);
+            o = o.toUpperCase();
+            if(!Validators.correctString(o)) o = "*";
+
+            int chunck = 20;
+
+            int index = 0;
+            while(index < o.length()) {
+                int end = index;
+                if(index + chunck > o.length()) {
+                    end = o.length();
+                } else {
+                    end = index + chunck;
+                }
+                String s = o.substring(index, end);
+
+                s = Utils.getStringMaxSize(32, s, ' ', false);
+                String line = "2;" + s;
+                items += line + "\n";
+
+                index = end;
+            }
+        }
+
+        if( plati == null || plati.size() == 0 ) {
+
+            long totalL = (long)(total * priceZeros);
+            items += "5;" + totalL + ";1;1;0\n";
+
+        } else {
+            float totalPlatit = 0;
+            for (Iterator iterator = plati.iterator(); iterator.hasNext();) {
+                EcrPlata plata = (EcrPlata) iterator.next();
+
+                float p = plata.getSuma();
+                String s = "";
+                long l = (long)(p * priceZeros);
+                s = l + "";
+
+                items += "5;" + s + ";" + plata.getEcrMapping() + ";1;0;\n";
+                totalPlatit += plata.getSuma();
+            }
+            if(totalPlatit < total) {
+                float p = (total - totalPlatit);
+                String s = "";
+                long l = (long)(p * priceZeros);
+                s = l + "";
+
+                items += "5;" + s + ";" + cashDefault.getEcrMapping() + ";1;0;\n";
+            }
+        }
+
+		pt.addToQueue(items);
+    }
+
+    public void forceTotal() {
+    }
+
+    @Override
+    public void printNonFiscalBon(String inputFile) {
+
+        File f = new File(inputFile);
+
+        String outputFile = onlineNfDestinationMask.replaceAll("%%nrbon", "" + nonFiscalIndex);
+        File outF = new File(outputFile);
+
+        int tries = 10;
+        boolean done = false;
+        while(!done && tries >0) {
+            done = f.renameTo(outF);
+            tries --;
+            if(!done)
+                try {
+                    Thread.sleep(300);
+                } catch (InterruptedException e) {
+                }
+        }
+
+        if(!done) {
+            Logger.logError(this, "EROARE LA MUTARE FISIER !");
+        }
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/optimus/TangoDrv.java
--- a/src/ro/atreides/ecr/optimus/TangoDrv.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/optimus/TangoDrv.java	Fri Sep 13 19:21:02 2013 +0300
@@ -108,11 +108,6 @@
         return "" + correctForm;
     }
 
-
-    public void processXml(String fileName) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
     public void forceTotal() {
         //To change body of implemented methods use File | Settings | File Templates.
     }
diff -r e6b80a8b200a src/ro/atreides/ecr/optimus/Test.java
--- a/src/ro/atreides/ecr/optimus/Test.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/optimus/Test.java	Fri Sep 13 19:21:02 2013 +0300
@@ -30,7 +30,7 @@
     public static void testgui(){
         Logger.getInstance(Logger.DEBUGVERBOSE, "protocol.log");
 
-        final EcrLogic logic = EcrLogic.getInstance(new String[]{"-ecrType","optimus.Generic"}, false);
+        final EcrLogic logic = EcrLogic.getInstance(new String[]{"-ecrType","optimus.Generic"}, false, null);
 
         JFrame f = new JFrame("test");
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -67,7 +67,7 @@
 
     public static void testurl() throws Exception {
         Logger.getInstance(Logger.DEBUGVERBOSE, "protocol.log");
-        EcrLogic logic = EcrLogic.getInstance(new String[]{"-ecrType","optimus.Generic"}, false);
+        EcrLogic logic = EcrLogic.getInstance(new String[]{"-ecrType","optimus.Generic"}, false, null);
 
         final Server s = new Server();
         s.addListener(new InetAddrPort(8080));
@@ -97,7 +97,7 @@
 
     public static void test(){
         Logger.getInstance(Logger.DEBUGVERBOSE, "protocol.log");
-        EcrLogic logic = EcrLogic.getInstance(new String[]{"-ecrType","optimus.Generic"}, false);
+        EcrLogic logic = EcrLogic.getInstance(new String[]{"-ecrType","optimus.Generic"}, false, null);
 
         Random r = new Random();
         String[] names = { "Cola", "Pepsi", "Paine", "Cascaval" };
diff -r e6b80a8b200a src/ro/atreides/ecr/optimus/nativeImpl/DriverInterface.java
--- a/src/ro/atreides/ecr/optimus/nativeImpl/DriverInterface.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/optimus/nativeImpl/DriverInterface.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,7 +1,7 @@
 package ro.atreides.ecr.optimus.nativeImpl;
 
+import ro.atreides.ecr.EcrDialogUtils;
 import ro.atreides.ecr.SerialDriverInterfaceImpl;
-import ro.atreides.ecr.datecs.nativeImpl.EcrDialogUtils;
 import ro.atreides.utils.gui.GuiUtils;
 
 import javax.swing.*;
diff -r e6b80a8b200a src/ro/atreides/ecr/optimus/nativeImpl/MG1200Impl.java
--- a/src/ro/atreides/ecr/optimus/nativeImpl/MG1200Impl.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/optimus/nativeImpl/MG1200Impl.java	Fri Sep 13 19:21:02 2013 +0300
@@ -23,8 +23,7 @@
     public MG1200Impl(String id,Vector portFilters) {
         super("driver" + File.separator + "optimus" + id + File.separator);
         super.setFilters(portFilters);
-        logger = new Logger(
-                "driver" + File.separator + "optimus" + id + File.separator + "logs");
+        logger = new Logger("driver" + File.separator + "optimus" + id + File.separator + "logs");
         setDriverInterface(new DriverInterface());
     }
 
diff -r e6b80a8b200a src/ro/atreides/ecr/orgtech/Generic.java
--- a/src/ro/atreides/ecr/orgtech/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/orgtech/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -136,10 +136,6 @@
         }
     }
 
-    public void processXml(String fileName) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
     public void introduNumerar(float suma) {
         String s = "I;1;" + Utils.getString2Decimals(suma) + ";";
         pt.addToQueue(s);
diff -r e6b80a8b200a src/ro/atreides/ecr/partner/Generic.java
--- a/src/ro/atreides/ecr/partner/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/partner/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -30,10 +30,6 @@
         decimalSimbol = conf.getProperty("decimalSimbol", ".");
     }
 
-    public void processXml(String fileName) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
         String items = "";
         
diff -r e6b80a8b200a src/ro/atreides/ecr/rompos/Generic.java
--- a/src/ro/atreides/ecr/rompos/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/rompos/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -37,9 +37,6 @@
         super.buildConfiguration(conf);
     }
 
-    public void processXml(String fileName) {
-    }
-
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
         String productsFile = "";
 
diff -r e6b80a8b200a src/ro/atreides/ecr/sapel/Generic.java
--- a/src/ro/atreides/ecr/sapel/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/sapel/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -13,19 +13,21 @@
 
 public class Generic extends AbstractCashRegister {
 
-    private boolean subtotalRequired;
+    private boolean subtotalRequired, showDecimalSimbol;
+
+    private String decimalSimbol = ".";
 
     public Generic() {
         super();
     }
 
-    public void processXml(String fileName) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
     public void buildConfiguration(Properties conf) {
         super.buildConfiguration(conf);
         subtotalRequired = Boolean.parseBoolean(conf.getProperty("subtotalRequired", "true"));
+
+        showDecimalSimbol = Boolean.parseBoolean(conf.getProperty("showDecimalSimbol", "true"));
+
+        decimalSimbol = conf.getProperty("decimalSimbol", ".");
     }
 
     public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
@@ -67,7 +69,15 @@
         } else {
             for (Iterator iterator = plati.iterator(); iterator.hasNext();) {
                 EcrPlata plata = (EcrPlata) iterator.next();
-                items += plata.getEcrMapping() + "" + Utils.getString2DecimalsNoTrunc(plata.getSuma()) + "\r\n";
+
+                String sumaPlata = Utils.getString2DecimalsNoTrunc(plata.getSuma());
+                if(decimalSimbol.contains(","))
+                    sumaPlata = Utils.switchDecimalSimbols(sumaPlata);
+
+                if(!showDecimalSimbol)
+                    sumaPlata = sumaPlata.replaceAll(decimalSimbol, "");
+
+                items += plata.getEcrMapping() + "" + sumaPlata + "\r\n";
             }
         }
         pt.addToQueue(items);
diff -r e6b80a8b200a src/ro/atreides/ecr/total/Generic.java
--- a/src/ro/atreides/ecr/total/Generic.java	Mon May 14 13:06:13 2012 +0300
+++ b/src/ro/atreides/ecr/total/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -1,14 +1,13 @@
 package ro.atreides.ecr.total;
 
-import ro.atreides.ecr.AbstractCashRegister;
-import ro.atreides.ecr.EcrSale;
-import ro.atreides.ecr.EcrUtils;
-import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.*;
+import ro.atreides.utils.FloatUtils;
 import ro.atreides.utils.plati.TipPlata;
 import ro.atreides.utils.gui.Validators;
 import ro.atreides.utils.Utils;
 
 import java.util.Iterator;
+import java.util.Properties;
 import java.util.Vector;
 
 /**
@@ -16,33 +15,39 @@
  */
 public class Generic extends AbstractCashRegister {
 
+    private boolean discountGlobal;
+
+    public void buildConfiguration(Properties conf) {
+        super.buildConfiguration(conf);
+        discountGlobal = Boolean.parseBoolean(conf.getProperty("discountGlobal", "false"));
+    }
+
     public Generic() {
         super();
     }
 
-    public void processXml(String fileName) {
-    }
+    public void printBonFiscal(Vector<EcrSale> sales, float total, Vector<EcrPlata> plati, TipPlata cashDefault, Vector<String> comments, String orderIdentifier, int idOrder) {
 
-    public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
-        
         //FIXME : tipuri plata
-        
+
         String items = "KARAT\n";
-        
-		Iterator iter = sales.iterator();
-		while( iter.hasNext()) {
-			EcrSale ecrSale = (EcrSale)iter.next();
-            
-			float nrPortii = ecrSale.getQuantity();
-			float ppu = ecrSale.getPpuDupaDiscount();
-			
-			String priceString = EcrUtils.getPrice(8, onlineDecimalPlaces, ppu);
-			String prodName = getString(16, ecrSale.getProduct()).toUpperCase();
-			String portiiString = EcrUtils.getPrice(9, 3, nrPortii);
-			
-			String commandText = "*" + prodName + "        "
-					+ priceString + onlineDecimalPlaces + portiiString
-					+ ecrSale.getCodTva();
+
+        Iterator iter = sales.iterator();
+        while( iter.hasNext()) {
+            EcrSale ecrSale = (EcrSale)iter.next();
+
+            float nrPortii = ecrSale.getQuantity();
+//			float ppu = ecrSale.getPpuDupaDiscount();
+
+            float ppu = (discountGlobal) ? ecrSale.getPpuOriginal() : ecrSale.getPpuDupaDiscount();
+
+            String priceString = EcrUtils.getPrice(8, onlineDecimalPlaces, ppu);
+            String prodName = getString(16, ecrSale.getProduct()).toUpperCase();
+            String portiiString = EcrUtils.getPrice(9, 3, nrPortii);
+
+            String commandText = "*" + prodName + "        "
+                    + priceString + onlineDecimalPlaces + portiiString
+                    + ecrSale.getCodTva();
 
             String dep = "" + ecrSale.getDepartament();
             if(!Validators.correctString(dep)) {
@@ -50,14 +55,45 @@
             } else {
                 commandText += dep + "0";//todo FIXME : daca am dep = 10, atunci rezulta dep = 100
             }
-			items += commandText;
-			items += "\n";
-		}
+            items += commandText;
+            items += "\n";
+
+            /*
+            ;rabat
+-0000060021
+
+Semnul minus semnifica operatiunea rabat
+8 digiti pentru suma (6 digiti nr intreg 2 digiti zecimale)
+2(1 digit pentru zecimale 0=fara;2=cu 2 zecimale) obligatoriu=2
+1 cota de TVA (1=19% ; 0=scutit TVA)
+             */
+
+            if(discountGlobal) {
+
+                String tip = "";
+                float pretOrig = ecrSale.getPpuOriginal();
+                float ppuDupaDiscount = ecrSale.getPpuDupaDiscount();
+                float diff =  pretOrig - ppuDupaDiscount;
+                if(pretOrig > ppuDupaDiscount) {
+                    tip = "-";
+                } else if (pretOrig < ppuDupaDiscount) {
+                    tip = "+";
+                    diff = -diff;
+                } else continue;
+
+                long l = FloatUtils.convertToLong(diff, 2);
+
+                String s = Utils.getStringMaxSize(8, l + "", '0', true);
+
+                String s1 = tip +s + "2" + ecrSale.getCodTva();
+                items += s1 + "\n";
+            }
+        }
 
         if(plati == null || plati.size() == 0) {
             items += "T000001000" +
-                "0" +
-                "ABCDEF\n";
+                    "0" +
+                    "ABCDEF\n";
         } else {
             float totalPlatit = 0;
             for (Iterator iterator = plati.iterator(); iterator.hasNext();) {
@@ -76,18 +112,18 @@
 
             if(totalPlatit < total)
                 items += "T000001000" +
-                "0" +
-                "ABCDEF\n";
+                        "0" +
+                        "ABCDEF\n";
         }
 
         items += "END KARAT\n";
 
         pt.addToQueue(items);
     }
-    
+
     private String getString(int totalDigits, String toConvert) {
         if(toConvert.length() > totalDigits)
-		    return toConvert.substring(0, totalDigits);
+            return toConvert.substring(0, totalDigits);
         else if(toConvert.length() < totalDigits) {
             String result = toConvert;
             for(int i = toConvert.length() ; i < totalDigits ; i++) {
@@ -97,7 +133,6 @@
         } else return toConvert;
     }
 
-
     public void forceTotal() {
         //To change body of implemented methods use File | Settings | File Templates.
     }
diff -r e6b80a8b200a src/ro/atreides/ecr/webxml/Generic.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/webxml/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,162 @@
+package ro.atreides.ecr.webxml;
+
+import org.mortbay.jetty.Server;
+import ro.atreides.ecr.AbstractCashRegister;
+import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.EcrSale;
+import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
+import ro.atreides.utils.plati.TipPlata;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * @author valy
+ */
+public class Generic extends AbstractCashRegister {
+
+    private static Vector<String> xmlElements = new Vector<String>();
+
+    private boolean discountGlobal;
+
+    private static Object lock = new Object();
+
+    public void buildConfiguration(Properties conf) throws RuntimeException {
+        super.buildConfiguration(conf);
+
+        discountGlobal = Boolean.parseBoolean(conf.getProperty("discountGlobal", "false"));
+    }
+
+    public void stopECR() {
+    }
+
+    public void startECR() {
+        try {
+            try {
+                Logger.logInfo(this, "starting webecr servlets");
+                if(webserver != null) {
+                    Server s = (Server)webserver.prepareWebServer(webServerPort);
+                    s.addWebApplication("/webecr","./webapps/webecr/");
+                }
+            } catch (Exception e) {
+                Logger.logException(this, e);
+            }
+
+        } catch (IllegalArgumentException e) {
+            Logger.logException(this, e);
+        } catch (Exception e) {
+            Logger.logException(this, e);
+        }
+    }
+
+    public void processXml(String fileName) {
+    }
+
+    public static String getAndRemoveAllBons() {
+        synchronized (lock) {
+            String allDoc = "<?xml version='1.0' encoding='utf-8'?>\n\n" +
+                    "<document>\n\n";
+
+            for (String xmlElement : xmlElements) {
+                allDoc += xmlElement;
+            }
+
+            allDoc += "\n\n</document>";
+
+            xmlElements.clear();
+
+            return allDoc;
+        }
+    }
+
+    public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
+        synchronized (lock) {
+
+
+            String result = "<receipt bonId=\"" + orderIdentifier + "\" idOrder=\"" + idOrder +"\">\n\n";
+
+            float totalFaraReducere = 0;
+            float totalReducere = 0;
+
+            Iterator iter = sales.iterator();
+            while( iter.hasNext()) {
+                EcrSale sale = (EcrSale)iter.next();
+
+                String name = sale.getProduct();
+                float nrPortii = sale.getQuantity();
+
+                float ppu = sale.getPpuDupaDiscount();
+
+                String line = "<product" +
+                        " label=\"" + name + "\"" +
+                        " price=\"" + Utils.getString2Decimals(ppu) + "\"" +
+                        " quantity=\"" + nrPortii + "\"" +
+                        " vat=\"" + sale.getCodTva() + "\"" +
+                        " priceOriginal=\"" + Utils.getString2DecimalsNoTrunc(sale.getPpuOriginal()) + "\"" +
+                        "/>\n";
+
+                totalFaraReducere += sale.getPpuOriginal() * nrPortii;
+                totalReducere += (sale.getPpuOriginal() - sale.getPpuDupaDiscount()) * nrPortii;
+
+                result+= line;
+
+            }
+
+//        if(discountGlobal) {
+//            if(totalReducere != 0) {
+//                float procent = totalReducere * 100 / totalFaraReducere;
+//                System.out.println("subtotal procent = " + procent);
+//                b.setAdaosTotal(procent);
+//
+//                Logger.logDebug(this, "subtotal procent = " + procent);
+//
+//            }
+//        }
+
+            result += "\n\n";
+
+            for (Object comment : comments) {
+                String com = (String) comment;
+
+                String line = "<ad text=\"" + com + "\"/>\n";
+                result += line;
+            }
+
+            result += "\n\n";
+
+            for (Iterator iterator = plati.iterator(); iterator.hasNext();) {
+                EcrPlata plata = (EcrPlata) iterator.next();
+                String line = "<payment type=\"" + plata.getTipPlata() + "\" amount=\"" + plata.getSuma() + "\"/>\n";
+                result += line;
+            }
+
+            result += "</receipt>\n\n";
+
+            xmlElements.add(result);
+
+        }
+    }
+
+    public void forceTotal() {
+    }
+
+    @Override
+    public void finishInitialize() {
+        super.finishInitialize();
+        startECR();
+    }
+
+    public void deleteNonPrintedBons() {
+        synchronized (lock) {
+            xmlElements.clear();
+        }
+    }
+
+    public int getNoOfBonsToPrint() {
+        synchronized (lock) {
+            return xmlElements.size();
+        }
+    }
+}
\ No newline at end of file
diff -r e6b80a8b200a src/ro/atreides/ecr/webxml/WebXmlGetServlet.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/webxml/WebXmlGetServlet.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,46 @@
+package ro.atreides.ecr.webxml;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: valy
+ * Date: Feb 11, 2011
+ * Time: 6:14:08 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class WebXmlGetServlet extends HttpServlet {
+
+    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+        doGet(req, resp);
+    }
+
+    protected void doGet(final HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+//        System.out.println("query: " + request.getQueryString());
+
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new OutputStreamWriter(response.getOutputStream()));
+        } catch (IllegalStateException e) {
+            out = response.getWriter();
+        }
+
+        response.setContentType("text/html");
+        String content =Generic.getAndRemoveAllBons();
+        sendResponse(content, out);
+        return;
+    }
+
+    private void sendResponse(String s, PrintWriter out) {
+        out.write(s);
+        out.flush();
+    }
+}
diff -r e6b80a8b200a src/ro/atreides/ecr/xkube/Generic.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ro/atreides/ecr/xkube/Generic.java	Fri Sep 13 19:21:02 2013 +0300
@@ -0,0 +1,262 @@
+package ro.atreides.ecr.xkube;
+
+import ro.atreides.ecr.AbstractCashRegister;
+import ro.atreides.ecr.EcrPlata;
+import ro.atreides.ecr.EcrSale;
+import ro.atreides.utils.FileUtils;
+import ro.atreides.utils.Logger;
+import ro.atreides.utils.Utils;
+import ro.atreides.utils.gui.Validators;
+import ro.atreides.utils.plati.TipPlata;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * @author valy
+ */
+public class Generic extends AbstractCashRegister {
+
+    private String tvaDefault = "1";
+
+    private int nonFiscalIndex = 1;
+
+    private String onlineNfDestinationMask;
+
+    public Generic() {
+        super();
+    }
+
+    @Override
+    public void printZ() {
+        String items = "15";
+        pt.addToQueue(items);
+    }
+
+    @Override
+    public void printX() {
+        String items = "30";
+        pt.addToQueue(items);
+    }
+
+    @Override
+    public void introduNumerar(float suma) {
+
+        long printPrice = 1;
+        for (int i = 0; i < onlineDecimalPlaces; i++) {
+            printPrice *= 10;
+        }
+        long l = 0;
+
+        String explicatii = "";
+        String tip = "";
+        if(suma < 0) {
+            l = (long)(-suma * printPrice);
+            tip = "1";
+            explicatii = "PLATI";
+        } else {
+            explicatii = "SOLD INITIAL";
+            tip = "2";
+            l = (long)(suma * printPrice);
+        }
+
+        explicatii = Utils.getStringMaxSize(32, explicatii, null, false);
+
+        String items = "25;" + tip + ";" + l + ";" + explicatii;
+
+        pt.addToQueue(items);
+    }
+
+    @Override
+    public boolean numerarInputReady() {
+        return true;
+    }
+
+    public void buildConfiguration(Properties conf) {
+        super.buildConfiguration(conf);
+
+        onlineNfDestinationMask = conf.getProperty("nonfiscalReceiptDestinationMask", "xkube/Online_nf_%%nrbon%%.txt");
+    }
+
+    public void printBonFiscal(Vector sales, float total, Vector plati, TipPlata cashDefault, Vector comments, String orderIdentifier, int idOrder) {
+
+        /*
+       1;ARTICOL 1;2;1;2;1111;2345;1;1
+       2;1;TEXT ADITIONAL
+       7;0;0;1;1234;0;0
+       1;ARTICOL 2;2;1;2;2222;2345;1;1
+       7;1;0;1;0;2099;1
+       1;ARTICOL 2;2;1;2;3333;2345;1;1
+       7;1;1;1;1221;0;0
+       5;19050;1;1;0
+       12;3;Plata conform document nr. 123456789
+       12;4;Text comercial    Text comercial
+        */
+
+
+        String items = "";
+
+        long printPrice = 1;
+        for (int i = 0; i < onlineDecimalPlaces; i++) {
+            printPrice *= 10;
+        }
+        
+        Iterator iter = sales.iterator();
+		while( iter.hasNext()) {
+		    EcrSale newsaleentry = (EcrSale)iter.next();
+		    String product = newsaleentry.getProduct();
+			float nrPortii = newsaleentry.getQuantity();
+
+            float orig = newsaleentry.getPpuOriginal();
+            float cuReducere = newsaleentry.getPpuDupaDiscount();
+			
+			long p = (long)(printPrice * orig);
+
+            long q = (long)(1000 * nrPortii);
+
+            String codTva = "" + tvaDefault;
+            if(Validators.correctString(newsaleentry.getCodTva())) {
+                codTva = newsaleentry.getCodTva();
+            }
+
+            String prodLabel = Utils.getStringMaxSize(32,product, ' ', false);
+            String deptLabel = Utils.getStringMaxSize(2, newsaleentry.getDepartament(), '0',true);
+
+            String commandText = "1;" + prodLabel + ";1;" + deptLabel + ";" + codTva + ";" + p + ";" + q + ";0;1";
+			
+			items += commandText;
+			items += "\n";
+
+            if(orig != cuReducere) {
+                String tip = "";
+
+                long origL = (long)(printPrice * orig);
+                long cuReducereL = (long)(printPrice * cuReducere);
+                long val = 0;
+
+                if(orig > cuReducere) {
+                    tip = "1";
+                    val = origL - cuReducereL;
+                } else {
+                    tip = "0";
+                    val = cuReducereL - origL;
+                }
+
+                String line = "7;" + tip + ";0;1;0;" + val + ";1";
+                                       //7;1;0;1;0;230;1
+                items += line + "\n";
+            }
+		}
+
+
+
+        if( plati == null || plati.size() == 0 ) {
+
+            long totalL = (long)(total * printPrice);
+            items += "5;" + totalL + ";1;1;0\n";
+
+        } else {
+            float totalPlatit = 0;
+            for (Iterator iterator = plati.iterator(); iterator.hasNext();) {
+                EcrPlata plata = (EcrPlata) iterator.next();
+
+                float p = plata.getSuma();
+                String s = "";
+                long l = (long)(p * printPrice);
+                s = l + "";
+
+                items += "5;" + s + ";" + plata.getEcrMapping() + ";1;0;\n";
+                totalPlatit += plata.getSuma();
+            }
+            if(totalPlatit < total) {
+                float p = (total - totalPlatit);
+                String s = "";
+                long l = (long)(p * printPrice);
+                s = l + "";
+
+                items += "5;" + s + ";" + cashDefault.getEcrMapping() + ";1;0;\n";
+            }
+        }
+
+        for (int i = 0; i < comments.size(); i++) {
+            String o = (String) comments.elementAt(i);
+            o = o.toUpperCase();
+            if(!Validators.correctString(o)) o = "*";
+
+            int chunck = 20;
+
+            int index = 0;
+            while(index < o.length()) {
+                int end = index;
+                if(index + chunck > o.length()) {
+                    end = o.length();
+                } else {
+                    end = index + chunck;
+                }
+                String s = o.substring(index, end);
+
+                s = Utils.getStringMaxSize(20, s, ' ', false);
+                String line = "12;1;" + s + ";";
+                items += line + "\n";
+
+                index = end;
+            }
+        }
+
+		pt.addToQueue(items);
+    }
+
+
+    public void forceTotal() {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+
+    @Override
+    public void printNonFiscalBon(String inputFile) {
+
+        File f = new File(inputFile);
+
+        String outputFile = onlineNfDestinationMask.replaceAll("%%nrbon", "" + nonFiscalIndex);
+        File outF = new File(outputFile);
+
+        int tries = 10;
+        boolean done = false;
+        while(!done && tries >0) {
+            done = f.renameTo(outF);
+            tries --;
+            if(!done)
+                try {
+                    Thread.sleep(300);
+                } catch (InterruptedException e) {
+                }
+        }
+
+        if(!done) {
+            Logger.logError(this, "EROARE LA MUTARE FISIER !");
+        }
+
+
+//        String s = FileUtils.readFileToString(inputFile);
+//
+//        Logger.logDebug(this, "Am citit bon nefiscal \"\n" + s + "\"\n");
+
+//        f.delete();
+//        while(f.exists()) {
+//            Logger.logDebug(this, "Astept stergerea fisierului!");
+//            try {
+//                Thread.sleep(sleep);
+//            } catch (InterruptedException e) {
+//            }
+//            if(f.exists())
+//                f.delete();
+//        }
+//
+//        Logger.logDebug(this, "Fisierul a fost sters!!");
+//
+//        pt.addToQueue(s);
+//        Logger.logDebug(this, "Trimitere terminata!!");
+    }
+}
