1 Conceptual Map of Scripts



 

2 Script Structure

Menu path:
System / Scripts / Scripts
Mobile / Scripts / Scripts
Mobile CRM / System / Scripts / Scripts
Mobile / System / Scripts / Scripts
Sistema / Scripts / Scripts

The APPS system takes advantage of JavaScript to customize application actions and forms. At various points, each installation will require its own customizations, so as to be able to perform actions online with the application. These points may include loading, assignment validation, document editing, new customer registration, document line editing, payment verification, or printing. The apps_scripts table contains all Java programs synchronized to the device, which are interpreted by the application.

apps_sys_scripts
Label Description
Code Script code

  • Values:
    • ticketh.print: ticketh.print.
    • apps_pos_ticketh_open.edit: apps_pos_ticketh_open.edit.
    • apps_pos_ticketh_open.save: apps_pos_ticketh_open.save.
    • ticketh.validate: ticketh.validate.
    • ticketh.close: ticketh.close.
    • apps_customers_new.commit: apps_customers_new.commit.
    • apps_customers_new.edit: apps_customers_new.edit.
    • ticketl.validate: ticketl.validate.
    • apps_pos_ticketl_open.edit: apps_pos_ticketl_open.edit.
    • apps_pos_ticketl_open.save: apps_pos_ticketl_open.save.
    • main: main.
    • apps_sfa_task_assign.save: apps_sfa_task_assign.save.
    • apps_sfa_task_assign.commit: apps_sfa_task_assign.commit.
    • apps_sfa_task_assign.validate: apps_sfa_task_assign.validate.
    • apps_sfa_task_assign.edit: .
    • apps_pos_moveh.commit: apps_pos_moveh.commit.
    • apps_pos_cash.print: apps_pos_cash.print.
    • apps_pos_movement.print: apps_pos_movement.print.
    • apps_pos_moveh.validate: .
    • apps_pos_moveh.edit: apps_pos_moveh.edit.
    • apps_pos_moveh.save: apps_pos_moveh.save.
    • apps_pos_movel.edit: apps_pos_movel.edit.
    • assign_from_action.validate: assign_from_action.validate.
Description Script information
Script Script

Status Status

  • Default: A
  • Case: Upshift
  • Values:
    • A: Valid.
    • B: Drop.
Creator User who first entered/created the record

  • Default: USER
Registration date Log entry date

  • Default: CURRENT
Updater Last user to modify the record

  • Default: USER
Update date Date of most recent registry modification

  • Default: CURRENT
 

3 POS Scripts

 

3.1 apps_pos_ticketh_open.edit

The script with the code apps_pos_ticketh_open.edit is executed when the document header data is edited. There is a set of functions intrinsic to the script which are accepted for use:

Example
Copy
/**
* Get the source bean of this edit form
*/
SQLBean      ticketl     = caller.getBean();
 
/**
* From Constants...
*/
    public static final String            COLUMN_TICKETL_TERMID      = "terminal_id";
    public static final String            COLUMN_TICKETL_SERIE       = "serie";
    public static final String            COLUMN_TICKETL_NUMERO      = "numero";
    public static final String            COLUMN_TICKETL_SEQNO       = "seqno";
    public static final String            COLUMN_TICKETL_INDGEN      = "indgen";
    public static final String            COLUMN_TICKETL_CODEAN      = "codean";
    public static final String            COLUMN_TICKETL_CANTID1     = "cantid_1";
    public static final String            COLUMN_TICKETL_CANTID2     = "cantid_2";
    public static final String            COLUMN_TICKETL_PRICE       = "precio";
    public static final String            COLUMN_TICKETL_DISCOUNT    = "descuen";
    public static final String            COLUMN_TICKETL_IMPNET      = "impnet";
    public static final String            COLUMN_TICKETL_LINORI      = "linori";
    public static final String            COLUMN_TICKETL_LINPRO      = "linpro";
    public static final String            COLUMN_TICKETL_LINPACK     = "linpack";
    public static final String            COLUMN_TICKETL_IMPPRO      = "imppro";
 
/**
* Access values from Bean
*/
 
String       m_terminal_id      = ticketl.getString(Constants.COLUMN_TICKETL_TERMID);
String       m_serie            = ticketl.getString(Constants.COLUMN_TICKETL_SERIE);
String       m_numero           = ticketl.getString(Constants.COLUMN_TICKETL_NUMERO);
 
/**
* Get the field from the form
*/
SQLEditField ed_cantid_1 = caller.get(Constants.COLUMN_TICKETL_CANTID1);

Example: The document lines contain the field 'Delivery Date'. This value only has to be reported when the document type is 'SALP' Order Proposal. Also, the system remembers the last date entered and uses it by default in the next insertion.

Copy
import java.text.*;
 
// Get the source bean of this edit form
SQLBean      ticketl     = caller.getBean();
 
 
// Obtain PK to get info from header
String       m_terminal_id      = ticketl.getString(Constants.COLUMN_TICKETL_TERMID);
String       m_serie            = ticketl.getString(Constants.COLUMN_TICKETL_SERIE);
String       m_numero           = ticketl.getString(Constants.COLUMN_TICKETL_NUMERO);
 
 
// Info from header
String m_tipdoc ="";
Cursor cur_ticketh = context.getContentResolver().query(
    Constants.TABLE_TICKETH_OPEN,
    new String[] { "*" },
    Constants.TABLE_TICKET_NUMBER_MATCH,
    new String[] {m_terminal_id,m_serie,m_numero},
    null 
    );
 
    if (cur_ticketh.moveToNext()) {
        m_tipdoc = cur_ticketh.getString(cur_ticketh.getColumnIndexOrThrow(Constants.COLUMN_TICKETH_TIPDOC));           
    }
 
cur_ticketh.close();
 
 
// Get the last delivery date line (type 'fecent')
String m_last_fecent = null;
SimpleDateFormat sdf = new SimpleDateFormat("E, dd-MM-yyyy");
 
 
Cursor cur_ticketl = context.getContentResolver().query(
    Constants.TABLE_TICKETL_OPEN,
    new String[] { "*" },
    Constants.TABLE_TICKET_NUMBER_MATCH,
    new String[] {m_terminal_id,m_serie,m_numero},
    " seqno DESC " 
    );
 
if (cur_ticketl.moveToNext()) {
    if(cur_ticketl.isFirst())
        m_last_fecent =  SQLBean.getColumnUserValue(ticketl, "fecent", cur_ticketl);
 
}
cur_ticketl.close();
 
 
if(m_tipdoc.equals("SALP")){
 
    try{
        SQLEditField ed_fecent   = caller.get("fecent");
        SQLEditField ed_cantid_2 = caller.get(Constants.COLUMN_TICKETL_CANTID2);
 
        ed_fecent.setVisible(true);
        if(m_last_fecent != null && caller.isInsert())
            ed_fecent.setValue(m_last_fecent);
 
        ed_cantid_2.setVisible(false);
 
 
    }catch (Exception ex) {
        // Price editor doesn't have cantid_2 or fecent 
        System.err.println("Non edit on form");
    }
 
}else{
   try{
        SQLEditField ed_fecent   = caller.get("fecent");
        SQLEditField ed_cantid_2 = caller.get(Constants.COLUMN_TICKETL_CANTID2);
 
        ticketl.setColumnRequired("fecent", false);  
        ed_fecent.setVisible(false);
 
 
        ed_fecent.setValue(sdf.format(new Date()));
        ed_cantid_2.setVisible(false);
 
    }catch (Exception ex) {
        // Price editor doesn't have cantid_2 or fecent 
        System.err.println("Non edit on form");
 
    }  
}
For the document type SALE (Direct Sale), the fields 'quantity 2' and 'Delivery Date' do not appear in the form.
For the document type SALP (Order Proposal), the fields 'quantity 2' and 'Delivery Date' appear in the form.
For the document type DEV (Refund), the field 'Delivery Date' does not appear.
 

3.2 apps_pos_ticketh_open.save

The script with the apps_pos_ticketh_open.save code is executed by pressing 'OK' in the receipt header data editor. The program must return a [true/false] boolean value. There is a set of functions intrinsic to the script which are accepted for use:

Example
Copy
/**
    * Get the source bean of this edit form
    */
    SQLBean      ticketh     = caller.getBean();
     
    /**
    * Get the data in tipdoc (document type) via the bean (note that it is not in the form!)
    */
    String       m_tipdoc      = ticketh.getString(Constants.COLUMN_TICKETH_TIPDOC);
    Int          m_numero      = ticketh.getInt(Constants.COLUMN_TICKETH_NUMERO);
     
    /**
    * Get the field from the form
    */
    SQLEditField ed_user_coment = caller.get(Constants.COLUMN_TICKETH_COMENT);

Example: validate the data entered by the user.

Copy
// ******************************************************
//
// [apps_pos_ticketh_open.save]
//
// bshell  (BshUtils)
// context (CartActivity)
// caller  (SQLEditForm)
// returns  boolean
//
// Event launched from the OK button in the Document Header Editor
//
// For SALF (Venta Factura) document types, 
// a customer with a price rate code is required.
//
//
// ******************************************************
    // Get the source bean of this edit form
    SQLBean      ticketh     = caller.getBean();
 
    // Get the data in tipdoc via the bean (note that it is not in the form!)
    String      m_tipdoc     = ticketh.getString(Constants.COLUMN_TICKETH_TIPDOC);
 
 
    if(m_tipdoc.equals("SALF")){
 
         EditText ed_codcli    = caller.get(Constants.COLUMN_TICKETH_CODCLI).getEditText();
         String   m_codcli     = ed_codcli.getText().toString();
 
         if(m_codcli.length() != 0){
            boolean m_has_tarpre = false;
 
             Cursor stop = context.getContentResolver().query(
                 Constants.tableUri(Constants.tableOf(Constants.TABLE_CUSTOMERS)),
 
                 new String[] { "*" },
                 "rate_code IS NOT NULL AND "+ Constants.COLUMN_CUSTOMERS_CUSTOMER_CODE +" = ?",
                 new String[] {m_codcli},
                 null
             );
 
             while (stop.moveToNext()) {
                 m_has_tarpre = true;
             }
             stop.close();
 
            if(!m_has_tarpre){
                ed_codcli.setError("Seleccionar cliente con tarifa");
                return false;
            }    
         }        
    }
 
return true;

Validation of the document header

For the document type VENP (Sale Order), selection of customers without a rate assigned. The script resets the customer value and reports the error on screen.
 

3.3 apps_pos_ticketl_open.edit

The script with the apps_pos_ticketl_open.edit code will execute when the receipt line data has been edited. There is a set of functions intrinsic to the script which can be used:

Example
Copy
/**
* Get the source bean of this edit form
*/
SQLBean      ticketl     = caller.getBean();
 
/**
* From Constants...
*/
    public static final String            COLUMN_TICKETL_TERMID      = "terminal_id";
    public static final String            COLUMN_TICKETL_SERIE       = "serie";
    public static final String            COLUMN_TICKETL_NUMERO      = "numero";
    public static final String            COLUMN_TICKETL_SEQNO       = "seqno";
    public static final String            COLUMN_TICKETL_INDGEN      = "indgen";
    public static final String            COLUMN_TICKETL_CODEAN      = "codean";
    public static final String            COLUMN_TICKETL_CANTID1     = "cantid_1";
    public static final String            COLUMN_TICKETL_CANTID2     = "cantid_2";
    public static final String            COLUMN_TICKETL_PRICE       = "precio";
    public static final String            COLUMN_TICKETL_DISCOUNT    = "descuen";
    public static final String            COLUMN_TICKETL_IMPNET      = "impnet";
    public static final String            COLUMN_TICKETL_LINORI      = "linori";
    public static final String            COLUMN_TICKETL_LINPRO      = "linpro";
    public static final String            COLUMN_TICKETL_LINPACK     = "linpack";
    public static final String            COLUMN_TICKETL_IMPPRO      = "imppro";
 
/**
* Access values from Bean
*/
 
String       m_terminal_id      = ticketl.getString(Constants.COLUMN_TICKETL_TERMID);
String       m_serie            = ticketl.getString(Constants.COLUMN_TICKETL_SERIE);
String       m_numero           = ticketl.getString(Constants.COLUMN_TICKETL_NUMERO);
 
/**
* Get the field from the form
*/
SQLEditField ed_cantid_1 = caller.get(Constants.COLUMN_TICKETL_CANTID1);

Example: In the document lines, there is a 'Delivery Date' field. This value should only be reported for document type 'SALP' (Order Proposal). The system remembers the last date entered for the next insertion.

Copy
import java.text.*;
 
// Get the source bean of this edit form
SQLBean      ticketl     = caller.getBean();
 
 
// Obtain PK to get info from header
String       m_terminal_id      = ticketl.getString(Constants.COLUMN_TICKETL_TERMID);
String       m_serie            = ticketl.getString(Constants.COLUMN_TICKETL_SERIE);
String       m_numero           = ticketl.getString(Constants.COLUMN_TICKETL_NUMERO);
 
 
// Info from header
String m_tipdoc ="";
Cursor cur_ticketh = context.getContentResolver().query(
    Constants.TABLE_TICKETH_OPEN,
    new String[] { "*" },
    Constants.TABLE_TICKET_NUMBER_MATCH,
    new String[] {m_terminal_id,m_serie,m_numero},
    null 
    );
 
    if (cur_ticketh.moveToNext()) {
        m_tipdoc = cur_ticketh.getString(cur_ticketh.getColumnIndexOrThrow(Constants.COLUMN_TICKETH_TIPDOC));           
    }
 
cur_ticketh.close();
 
 
// Get the last delivery date line (fecent)
String m_last_fecent = null;
SimpleDateFormat sdf = new SimpleDateFormat("E, dd-MM-yyyy");
 
 
Cursor cur_ticketl = context.getContentResolver().query(
    Constants.TABLE_TICKETL_OPEN,
    new String[] { "*" },
    Constants.TABLE_TICKET_NUMBER_MATCH,
    new String[] {m_terminal_id,m_serie,m_numero},
    " seqno DESC " 
    );
 
if (cur_ticketl.moveToNext()) {
    if(cur_ticketl.isFirst())
        m_last_fecent =  SQLBean.getColumnUserValue(ticketl, "fecent", cur_ticketl);
 
}
cur_ticketl.close();
 
 
if(m_tipdoc.equals("SALP")){
 
    try{
        SQLEditField ed_fecent   = caller.get("fecent");
        SQLEditField ed_cantid_2 = caller.get(Constants.COLUMN_TICKETL_CANTID2);
 
        ed_fecent.setVisible(true);
        if(m_last_fecent != null && caller.isInsert())
            ed_fecent.setValue(m_last_fecent);
 
        ed_cantid_2.setVisible(false);
 
 
    }catch (Exception ex) {
        // Price editor doesn't have cantid_2 or fecent 
        System.err.println("Non edit on form");
    }
 
}else{
   try{
        SQLEditField ed_fecent   = caller.get("fecent");
        SQLEditField ed_cantid_2 = caller.get(Constants.COLUMN_TICKETL_CANTID2);
 
        ticketl.setColumnRequired("fecent", false);  
        ed_fecent.setVisible(false);
 
 
        ed_fecent.setValue(sdf.format(new Date()));
        ed_cantid_2.setVisible(false);
 
    }catch (Exception ex) {
        // Price editor doesn't have cantid_2 or fecent 
        System.err.println("Non edit on form");
 
    }  
}

Document Line Editor

For the document type SALP (Order Proposal), the fields 'quantity 2' and 'Delivery Date' appear in the form. For the document type SALE (Direct Sale), the fields 'quantity 2' and 'Delivery Date' do not appear in the form.
 

3.4 apps_pos_ticketl_open.save

The script with the apps_pos_ticketl_open.save code will be executed by pressing the OK button in the document line editor. The program must return a [true/false] boolean value. There is a set of functions intrinsic to the script which can be used:

Example
Copy
/**
* Get the source bean of this edit form
*/
SQLBean      ticketl     = caller.getBean();
 
/**
* Get the data in tipdoc via the bean (note that it is not in the form!)
*/
String       m_terminal_id      = ticketl.getString(Constants.COLUMN_TICKETL_TERMID);
String       m_serie            = ticketl.getString(Constants.COLUMN_TICKETL_SERIE);
String       m_numero           = ticketl.getString(Constants.COLUMN_TICKETL_NUMERO);
 
/**
* Get the field from the form
*/
SQLEditField ed_cantid_1 = caller.get(COLUMN_TICKETL_CANTID1);

Example: For 'SALE' (Direct Sale) documents, if the document belongs to the 'T-Shirts and Tops' family, the minimum quantity must be 10 units.

Copy
// ---------------------------------------------------------------------
// Arguments
//
// bshell  (BshUtils)
// context (CartActivity)
// caller  (SQLEditField)
// returns  void
// 
// This code is executed upon editing a document line's data.
// A minimum of 10 units for items in the Swimsuit family 
// must be reported in 'VENP' (Sale Order) type documents.
// ---------------------------------------------------------------------
// Get the source bean of this edit form
SQLBean      ticketl     = caller.getBean();
 
// Obtain PK to get info from header
String       m_terminal_id      = ticketl.getString(Constants.COLUMN_TICKETL_TERMID);
String       m_serie            = ticketl.getString(Constants.COLUMN_TICKETL_SERIE);
String       m_numero           = ticketl.getString(Constants.COLUMN_TICKETL_NUMERO);
 
 
// Info from header
String m_tipdoc ="";
Cursor cur_ticketh = context.getContentResolver().query(
    Constants.TABLE_TICKETH_OPEN,
    new String[] { "*" },
    Constants.TABLE_TICKET_NUMBER_MATCH,
    new String[] {m_terminal_id,m_serie,m_numero},
    null 
    );
 
    if (cur_ticketh.moveToNext()) {
        m_tipdoc = cur_ticketh.getString(cur_ticketh.getColumnIndexOrThrow(Constants.COLUMN_TICKETH_TIPDOC));           
    }
 
cur_ticketh.close();
 
if(m_tipdoc.equals("SALE")){
 
 
    String codean  =   ticketl.getString(Constants.COLUMN_TICKETL_CODEAN);
    String codart  =   "";
    String codfam  =   "";
 
    // Via Codean we get the item family.
 
    Cursor cur = context.getContentResolver().query(
        Constants.tableUri(Constants.tableOf(Constants.TABLE_POS_EANS),
        new String[] { "*" },
        Constants.COLUMN_EANS_CODEAN +" = ?",
        new String[] {codean},
        null
    );
 
    while (cur.moveToNext()) {
        //codart = (cur.getString(cur.getColumnIndexOrThrow("codart")));
        codart = (cur.getString(cur.getColumnIndexOrThrow(Constants.COLUMN_EANS_ITEM_CODE)));
    }
 
    cur.close();
 
    if(codart.length() != 0){
 
        // We get the Family
        Cursor cur_art = context.getContentResolver().query(
            Constants.tableUri(Constants.tableOf(Constants.TABLE_POS_ITEMS)),
            new String[] { "*" },
            "item_code = ?",
            Constants.COLUMN_ITEMS_ITEM_CODE + " = ?",
            new String[] {codart},
            null
        );
 
        while (cur_art.moveToNext()) {
            //codfam = (cur_art.getString(cur_art.getColumnIndexOrThrow("codfam")));  
            codfam = (cur_art.getString(cur_art.getColumnIndexOrThrow(Constants.COLUMN_ITEMS_FAMILY_CODE)));            
        }
 
        cur_art.close();
 
        // CAMISETAS & TOPS
        if(codfam.equals("0203")){
 
            try{     
//SQLEditField ed_cantid_1   = caller.get("cantid_1");
                SQLEditField ed_cantid_1   = caller.get(Constants.COLUMN_TICKETL_CANTID1);
                Integer m_cantid_1 =   Integer.valueOf(ed_cantid_1.getValue()); 
 
                if(m_cantid_1 < 10){
                    ed_cantid_1.setError("Minimum 10 units (Family)");
                    return false;
                }
            }catch (Exception ex) {
            // Price or discount editor doesn't have cantid_2 or fecent 
                System.err.println("Non edit on form");
            }
        }        
    }       
}
 
return true;

Document Line Validator

For the document type SALE (Venta directa), when the quantity of items in the T-Shirts and Tops family is below 10.
Quantity Error Message.
 

3.5 apps_customers_new.edit

The script with the apps_clientes_new.edit code will be executed before the customer registration editor is shown. There is a set of functions intrinsic to the script which can be used:

Example
Copy
/**
* Get the source bean of this edit form
*/
SQLBean      new_customer     = caller.getBean();
 
/**
* From Constants
*/
    public static final String            COLUMN_CUSTOMERS_NEW_TERMID           = "terminal_id";
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_CODE    = "customer_code";    
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_NAME    = "customer_name";
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_CIF       = "customer_cif";
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_DIRECC  = "customer_direcc";
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_POBLAC  = "customer_poblac";    
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_CODPOS  = "customer_codpos";
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_PHONE1  = "customer_phone1";
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_PHONE2  = "customer_phone2";
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_EMAIL   = "customer_email";
    public static final String            COLUMN_CUSTOMERS_NEW_CUSTOMER_STATE   = "customer_state";
 
 
SQLEditField ed_telef1   = caller.get(Constants.COLUMN_GCLIENTE_NEW_TELEF1);

Example: The New Customers table contains a field (telef1 'Mobile Phone') which is not required. Here it is converted to required.

Copy
// ---------------------------------------------------------------------
// Arguments
//
// bshell  (BshUtils)
// context (CartActivity)
// caller  (SQLEditField)
// returns  void
//
// The field telef1 is required.
// ---------------------------------------------------------------------
 
caller.getBean().setColumnRequired(Constants.COLUMN_CUSTOMERS_NEW_CUSTOMER_PHONE1, true);

Document Line Validator

The Mobile field is required, ordered by the script.
 

3.6 apps_customers_new.commit

The script with the apps_clientes_new.commit code will be executed by pressing OK in the customer registration editor. The program must return a [true/false] boolean value. There is a set of functions intrinsic to the script which can be used:

Example
Copy
/**
* Get the source bean of this edit form
*/
SQLBean      new_customer     = caller.getBean();
 
/**
* From Constants
*/
public static final String          COLUMN_GCLIENTE_NEW_TERMID  = "terminal_id";
public static final String          COLUMN_GCLIENTE_NEW_CODCLI  = "codcli"; 
public static final String          COLUMN_GCLIENTE_NEW_NAME    = "nombre";
public static final String          COLUMN_GCLIENTE_NEW_CIF     = "cif";
public static final String          COLUMN_GCLIENTE_NEW_DIRECC  = "direcc";
public static final String          COLUMN_GCLIENTE_NEW_POBLAC  = "poblac"; 
public static final String          COLUMN_GCLIENTE_NEW_CODPOS  = "codpos";
public static final String          COLUMN_GCLIENTE_NEW_TELEF1  = "telef1";
public static final String          COLUMN_GCLIENTE_NEW_TELEF2  = "telef2";
public static final String          COLUMN_GCLIENTE_NEW_EMAIL   = "email";
public static final String          COLUMN_GCLIENTE_NEW_ESTADO  = "estado";
 
 
SQLEditField ed_telef1   = caller.get(Constants.COLUMN_GCLIENTE_NEW_TELEF1);
 
ed_telef1.setError("Error message");

Example: This script contains the validation of the CIF, mobile, postal code, and email fields.

*Validation of CIF (VAT ID number) and NIE (national ID number).

*Validation of mobile phone (only numerical values permitted).

*Validation of postal code (only numerical values permitted).

*Validation of email address (must contain @ and a period).

Copy
// ---------------------------------------------------------------------
// Arguments
//
// bshell  (BshUtils)
// context (CartActivity)
// caller  (SQLEditField)
// returns  void
//
// Event launched by the OK button in Customer Registration
//
// Verification of the CIF and email address in new customer registration
// [apps_clientes_new.commit]
// ---------------------------------------------------------------------
 
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import android.widget.Toast;
 
 
/**
* Example to perform a REMOTE QUERY
*/
//
//import deister.android.apps.util.SystemUtils;
//
//  String  m_cif   = "";
//  boolean m_found = false;
//
//    // CIF Validation
//    EditText ed_cif  = caller.get("cif").getEditText();
//    m_cif            = ed_cif.getText().toString();
//
//  if(SystemUtils.isNetworkEnabled(context)){
//
//      String statement = "SELECT * FROM apps_clientes WHERE cif = '"+ m_cif +"';";
//
//      Cursor c = caller.remoteQuery(sentencia);
//      if (c != null) {
//          if (c.moveToNext()) {
//              m_found = true;
//          }
//              c.close();
//
//          }
//      }
//
//      if(m_found){
//          ed_cif.setError("CIF Duplicado!!!");
//          return false;
//      }
//  }
 
 
    private final static String   VALORES_PRIMER_CHAR   = "KLTXYZ";
 
    private final static String   LETRA_SOCIEDAD_NUM    = "KLMNPQRSW";
 
    private final static String   LETRA_CONTROL_CIF     = "0123456789";
 
    private final static String   VALORES_CIF           = "ABCDEFGHJKLMNPQRSUVW";
 
    private final static String   NIF_STRING_ASOCIATION = "TRWAGMYFPDXBNJZSQVHLCKE";
 
    private final static String   LETRAS                = "ABCDEFGHIJKLMN?OPQRSTUVWXYZ";
 
 
    /**
     * Check if a string can be converted to integer
     *
     * @param cadena
     * @return
     */
    private static boolean __isNumeric(String cadena)
    {
        try {
            Integer.parseInt(cadena);
            return true;
         } catch (NumberFormatException nfe){
            return false;
         }
    }
 
    /**
    *
    * Validate an email address
    *
    * @param   email
    * @return  true/false.
    */
     private boolean __isValidEmailAddress(String emailAddress)
     {
         String  expression="^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
         CharSequence inputStr = emailAddress;
         Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);
         Matcher matcher = pattern.matcher(inputStr);
         return matcher.matches();
 
     }
 
    /**
    *
    * Return the letter of a DNI (national ID document)
    *
    * @param dni
    * @return
    */
    private static  String __letraDNI(int dni)
    {
        return String.valueOf(NIF_STRING_ASOCIATION.charAt(dni % 23));
    }
 
    /**
     * Validate a CIF
     * @param cif
     * @return
     */
    public static String __isCifValido(String cif)
    {
 
        String m_error_msg = "";
 
        try {
            String vCif = cif.trim();
 
            int m_suma  = 0;
            int m_count = 0;
            int m_temp  = 0;
            int m_cod_control = 0;
 
            String m_first_letter;
            String m_last_letter;
 
            // Check the CIF length is correct.
            if (!(vCif.length() == 9))
                return "The CIF must be 9 characters long";
 
            // If a character which is not a letter or number is found, the CIF
            // is not valid.
            if (vCif.matches("[^A-Za-z0-9]"))
                return "The CIF can only contain letters and numbers";
 
            // Change the string to uppercase.
            vCif = vCif.toUpperCase();
 
            // Get the first letter (company type identifier) and last letter (control identifier)
            // of the CIF.
            m_first_letter = vCif.substring(0, 1);
 
            // Get the last letter of the CIF to check its validity. 
            m_last_letter = vCif.substring(8, 9);
 
            // Check if the first letter is valid.
            if (VALORES_CIF.indexOf(m_first_letter) < 0)
                return "CIF INCORRECTO";
 
            // Get the control code.
            // Add together even integers
            m_suma = m_suma + Integer.parseInt(vCif.substring(2, 3)) + Integer.parseInt(vCif.substring(4, 5))
                    + Integer.parseInt(vCif.substring(6, 7));
 
            // Now multiply each odd integer by two and add
            // the resulting numbers together.
            for (m_count = 1; m_count < 8; m_count = m_count + 2) {
                // Multiply by 2
                m_temp = (Integer.parseInt(vCif.substring(m_count, m_count + 1)) * 2);
 
                // Add the digits together.
                // Difference in handling single-digit numbers, for example: 8 = 8
                // and multi-digit numbers, for example: 16 -> 6 + 1 = 7
                if (m_temp < 10)
                    m_suma = m_suma + m_temp;
                else {
                    m_suma = m_suma + (Integer.parseInt(String.valueOf(m_temp).substring(0, 1)))
                            + (Integer.parseInt(String.valueOf(m_temp).substring(1, 2)));
                }
            }
 
            // Get sum units and subtract them from 10 to get the
            // control digit.
            m_cod_control = ((10 - (m_suma % 10)) % 10);
 
            // If the letter is K, L, M, N, P, Q or S, then 64 is added to the
            // control code, and
            // we get its ASCII to check if it coincides with the last letter of the CIF.
            if (LETRA_SOCIEDAD_NUM.indexOf(m_first_letter) >= 0) {
                byte[] ascii = new byte[1];
 
                // Get the associated ASCII code by adding 64 
                // to the control code.
                if (m_cod_control == 0)
                    m_cod_control = 10;
                m_cod_control = m_cod_control + 64;
                ascii[0] = (Integer.valueOf(m_cod_control)).byteValue();
 
                // The last digit must coincide with
                // the control digit obtained
                if((m_last_letter.equals(new String(ascii)))){
                    m_error_msg = "";
                }else{
                    m_error_msg = "The last letter must be ["+new String(ascii)+"]";
                }
                //resul = (lastLetter.equals(new String(ascii)));
             }else{
                // For other first letters in CIFs, the corresponding last digit
                // must be numerical,
                // and must coincide with the control code.
                if(m_cod_control == LETRA_CONTROL_CIF.indexOf(m_last_letter)){
                    m_error_msg = "";
                }else{
                    m_error_msg = "The last digit must be ["+m_cod_control+"]";
                }
 
             }
        } catch (Exception e) {
            // If an error has occurred, this is because an exception has been thrown while parsing.
            m_error_msg = "Error in checking CIF";
        }
        return m_error_msg;
    }
 
 
    public static String __NIEValida(String cadena) {
 
        int m_long = 0;
        String m_correct = "";
        String m_nif;
        String m_first_char;
        String m_second_char;
        String m_tirth_char;
 
 
        // Validates the length of the string.
        m_long = cadena.length();
        if (m_long == 0) {
                return "No NIE has been reported";
        } else if (!(m_long == 11 || m_long == 9)) {
                return "The NIE must be either 9 or 11 characters long";
        }
 
        m_first_char = cadena.substring(0, 1).toUpperCase();
 
        if (m_long == 11) {
            m_second_char = cadena.substring(1, 2).toUpperCase();
            m_tirth_char = cadena.substring(2, 4).toUpperCase();
            m_nif = cadena.substring(2, 11).toUpperCase();
 
            if (VALORES_PRIMER_CHAR.indexOf(m_first_char) == -1)
                m_correct = "The first character of the NIE is not valid";
            else if (LETRAS.indexOf(m_second_char) == -1)
                m_correct = "the second letter of the NIE is not valid";
            else if (m_tirth_char.equals("00"))
                m_correct = "The third and fourth characters cannot consist of 00";
            else
                m_correct = __isCifValido(m_nif);
        }
 
        if (m_long == 9) {
            if (m_first_char.equals("X")) {
                m_nif = "0" + cadena.substring(1, 9).toUpperCase();
                m_correct = __NumeroNif(m_nif);
            } else if (m_first_char.equals("Y")) {
                m_nif = "1" + cadena.substring(1, 9).toUpperCase();
                m_correct = __NumeroNif(m_nif);
            } else if (m_first_char.equals("Z")) {
                m_nif = "2" + cadena.substring(1, 9).toUpperCase();
                m_correct = __NumeroNif(m_nif);
            } else {
                m_correct = "ERROR";
            }
        }
        return m_correct;
    }
 
   private static String __NumeroNif(String numero)
   {
       // All in uppercase
       numero = numero.toUpperCase();
       String out = "";
       String valoresNIE = "XYZ";
       boolean m_pais_exist = false;
 
       // Basic checking of the string entered by the user
       if (numero.length() != 9 && numero.length() != 11){
           return "The NIF does not have a valid number of characters (9 or 11)";
       }
       if(numero.length() == 9){
 
          String the_dni      = numero.substring(0,8);
          String the_let      = numero.substring(8);
          String the_let_cif  = numero.substring(0,1);
          String the_cif_comp = numero;
 
          if(__isNumeric(the_dni)){
               String the_correct_let = __letraDNI(Integer.valueOf(the_dni));
               if(the_let.equals(the_correct_let)){
                   return out;
               }else{
                   out = "Incorrect letter. The correct value is: [" + the_correct_let + "]";
               }
          }else if((valoresNIE.indexOf(the_let_cif) != -1)){
                // return "enter NIE";
               out = __NIEValida(the_cif_comp);
          }else{
                 out = __isCifValido(the_cif_comp);
              //out = "DNI or CIF not numerical, contains letters";
          }
       }
       if(numero.length() == 11){
          String codnac = numero.substring(0,2);
 
          if(__isNumeric(codnac)){
                return "The first two digits must correspond to the country";
          }
 
         // Cursor m_nac = context.getContentResolver().query(
         // Constants.tableUri("ctiponac"),
         // new String[] { "*" },
         // "coda2 = ?",
         // new String[] {codnac},
         // null
         // );
 
         // if(m_nac.moveToNext()) {
         // m_pais_exist = true;
         // }
         // m_nac.close();
         // if(!m_pais_exist){
         //      out = "Incorrect country code";
         // }
       }
       return out;
   }
 
    // CIF Validation
    EditText ed_cif  = caller.get(Constants.COLUMN_CUSTOMERS_NEW_CUSTOMER_CIF).getEditText();
    m_cif            = ed_cif.getText().toString();
 
    ed_cif.setText(m_cif.toUpperCase());
    String   cif_error = __NumeroNif(m_cif.toUpperCase());
 
    if(cif_error.length() != 0){
        ed_cif.setError(cif_error);
        return false;
    }
 
 
    // Mobile Number Validation
    EditText ed_tel    = caller.get(Constants.COLUMN_CUSTOMERS_NEW_CUSTOMER_PHONE1).getEditText();
    String   telef1    = ed_tel.getText().toString();
 
    if(telef1.length() != 0){
        if(!__isNumeric(telef1)){
            ed_tel.setError("Numerical value!!!");
            return false;
        }
    }
 
    // Postal Code Validation
    EditText ed_cp    = caller.get(Constants.COLUMN_CUSTOMERS_NEW_CUSTOMER_CODPOS).getEditText();
    String   codpos   = ed_cp.getText().toString();
 
    if(codpos.length() != 0){
        if(!__isNumeric(codpos)){
            ed_cp.setError("Numerical value!!!");
            return false;
        }
    }
 
    //Email validation
    EditText ed_email = caller.get(Constants.COLUMN_CUSTOMERS_NEW_CUSTOMER_EMAIL).getEditText();
    String email = ed_email.getText().toString();
    if(email.length() != 0)
    {
        if (!__isValidEmailAddress(email)) {
            ed_email.setError("Incorrect Email Address");
            return false;
        }
    }
 
return true;

Document Line Validator

CIF Validator (Incorrect information). CIF Validator (Correct letter information). Postal code validator. Email address validator.
 

3.7 ticketh.validate

The script with the ticketh.validate code will be executed by pressing the 'Close' or 'Process' button on the main Transactions screen. The program must return a [true/false] boolean value. There is a set of functions intrinsic to the script which can be used:

Example
Copy
/**
* From Constants
*/
    public static final String  COLUMN_TICKETH_HOSTID       = "hardware_id";    // Android phone number or hardware number
    public static final String  COLUMN_TICKETH_TERMID       = "terminal_id";    // As defined in apps_config
    public static final String  COLUMN_TICKETH_POS_USER     = "apps_user";
    public static final String  COLUMN_TICKETH_SERIE        = "serie";
    public static final String  COLUMN_TICKETH_NUMERO       = "numero";     // Sequential #ticket number
    public static final String  COLUMN_TICKETH_NUMFAC       = "numfac";     // Invoice number
    public static final String  COLUMN_TICKETH_TIPDOC       = "tipdoc";     // Type of document
    public static final String  COLUMN_TICKETH_ESTADO       = "estado";     // Marks if a document is canceled
    public static final String  COLUMN_TICKETH_DATE_I       = "fecini";     // Document start date
    public static final String  COLUMN_TICKETH_DATE_E       = "fecfin";     // Document end date
    public static final String  COLUMN_TICKETH_COMENT       = "coment";     // Server notes (for up-down documents)
    public static final String  COLUMN_TICKETH_CODCLI       = "codcli";     // Customer code
    public static final String  COLUMN_TICKETH_CODALM       = "codalm";     // Store code
    public static final String  COLUMN_TICKETH_DOCORI       = "docori";     // Source document
 
/**
* Get the source bean of this edit form
*/
SQLBean      ticketh     = caller;
 
// Obtain PK to get info from header
String       m_terminal_id      = ticketh.getString(Constants.COLUMN_TICKETH_TERMID);
String       m_serie            = ticketh.getString(Constants.COLUMN_TICKETH_SERIE);
String       m_numero           = ticketh.getString(Constants.COLUMN_TICKETH_NUMERO);
 
 
// Info from header
// Get the data in tipdoc via the bean (note that it is not in the form!)
String       m_tipdoc      = ticketh.getString(Constants.COLUMN_TICKETH_TIPDOC);

Example: The system checks that for the SALP 'Order Proposal' document type, in the document lines of the 'Skirts' family, the minimum quantity is 10.

Copy
// ---------------------------------------------------------------------
// Arguments
//
// bshell  (BshUtils)
// context (CartActivity)
// caller  (SQLEditForm)
// returns  void
//
// This code is executed when pressing the Close or Process button
// on the main Transactions screen.
// A minimum of 10 units must be reported for items
// in the Swimsuits family, in SALP 'Order Proposal' documents.
// ---------------------------------------------------------------------
 
import android.net.Uri;
import android.text.Html;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Gravity;
import android.widget.Toast;
 
import deister.android.apps.R;
 
 
// Get the source bean of this edit form
SQLBean      ticketh     = caller;
 
// Obtain PK to get info from header
String       m_terminal_id      = ticketh.getString(Constants.COLUMN_TICKETH_TERMID);
String       m_serie            = ticketh.getString(Constants.COLUMN_TICKETH_SERIE);
String       m_numero           = ticketh.getString(Constants.COLUMN_TICKETH_NUMERO);
 
 
// Info from header
// Get the data in tipdoc via the bean (note that it is not in the form!)
String       m_tipdoc      = ticketh.getString(Constants.COLUMN_TICKETH_TIPDOC);
 
 
if(m_tipdoc.equals("SALP")){
 
    Cursor cur_ticketl = context.getContentResolver().query(
        Uri.parse(Constants.TABLE_TICKETL_OPEN  +
        " JOIN " + Constants.tableOf(Constants.TABLE_POS_EANS) + " ON " +
        Constants.tableOf(Constants.TABLE_TICKETL_OPEN ) + "." + Constants.COLUMN_TICKETL_CODEAN + " = " + Constants.tableOf(Constants.TABLE_POS_EANS) + "." + Constants.COLUMN_EANS_CODEAN +
        " JOIN " + Constants.tableOf(Constants.TABLE_POS_ITEMS) + " ON " +
        Constants.tableOf(Constants.TABLE_POS_ITEMS ) + "." + Constants.COLUMN_ITEMS_ITEM_CODE + " = " + Constants.tableOf(Constants.TABLE_POS_EANS) + "." + Constants.COLUMN_EANS_ITEM_CODE +
        " "),
        new String[] {
            Constants.tableOf(Constants.TABLE_TICKETL_OPEN ) + "." + Constants.COLUMN_TICKETL_CODEAN  + ", " +
            Constants.tableOf(Constants.TABLE_TICKETL_OPEN ) + "." + Constants.COLUMN_TICKETL_CANTID1 + ", " +
            Constants.tableOf(Constants.TABLE_POS_ITEMS )     + "." + Constants.COLUMN_ITEMS_ITEM_CODE  + ", " +
            Constants.tableOf(Constants.TABLE_POS_ITEMS )     + "." + Constants.COLUMN_ITEMS_FAMILY_CODE
            },
        Constants.TABLE_TICKET_NUMBER_MATCH,
        new String[] {m_terminal_id,m_serie,m_numero},
        null
    );
 
    while (cur_ticketl.moveToNext()) {
        int m_cantid = (cur_ticketl.getInt(cur_ticketl.getColumnIndexOrThrow(Constants.COLUMN_TICKETL_CANTID1)));
        String m_codfam = (cur_ticketl.getString(cur_ticketl.getColumnIndexOrThrow(Constants.COLUMN_ITEMS_FAMILY_CODE)));
 
        System.err.println("xxxx CODFAM: "+ m_codfam);
        // Faldas
        if(m_codfam.equals("0206")){
            if(m_cantid < 10){
                String m_nomart = (cur_ticketl.getString(cur_ticketl.getColumnIndexOrThrow(Constants.COLUMN_ITEMS_ITEM_CODE)));
 
                AlertDialog alertDialog = new AlertDialog.Builder(context).create();
                alertDialog.setIcon(R.drawable.alert_warning);
                alertDialog.setTitle(Html.fromHtml("<font color='#FF0000'><b>Alert!!!</b></font>"));
                alertDialog.setMessage(Html.fromHtml("<b>"+ m_nomart + "<b/><br/><br/> Minimun 10 units (Family)"));
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                   }
                });
 
                alertDialog.show();
 
                cur_ticketl.close();
                return false;
            }
        }
    }
 
    cur_ticketl.close();
}
 
return true;

Document Validator

Item in the 'Skirts' family with a quantity below 10 units.
 

3.8 ticketh.close

The script with the ticketh.close code will be executed when the receipt/document payments are entered, or when the 'Menu' button to access the receipt closing menu is pressed. The program must return a [true/false] boolean. There is a set of functions intrinsic to the script which can be used:

Example
Copy
**
* From Constants
*/
 
    public static final Uri      TABLE_TICKETH_OPEN       = Uri.parse(CONTENT_URI +  "apps_pos_ticketh_open");
    public static final Uri      TABLE_TICKETH_CLOSE      = Uri.parse(CONTENT_URI +  "apps_pos_ticketh_close");
    public static final Uri      TABLE_TICKETH_REQUEST    = Uri.parse(CONTENT_URI +  "apps_pos_ticketh_request");
    public static final String   SCRIPT_TICKETH_PROCESS   = "apps_pos_ticketh_request_call";
 
    public static final String   COLUMN_TICKETH_HOSTID    = "hardware_id";    // Android phone number or hardware number
    public static final String   COLUMN_TICKETH_TERMID    = "terminal_id";    // As defined in apps_config
    public static final String   COLUMN_TICKETH_POS_USER  = "apps_user";
    public static final String   COLUMN_TICKETH_SERIE     = "serie";
    public static final String   COLUMN_TICKETH_NUMERO    = "numero";         // Sequential #ticket number
    public static final String   COLUMN_TICKETH_NUMFAC    = "numfac";         // Invoice number
    public static final String   COLUMN_TICKETH_TIPDOC    = "tipdoc";         // Type of document
    public static final String   COLUMN_TICKETH_ESTADO    = "estado";         // Marks if a document is canceled
    public static final String   COLUMN_TICKETH_DATE_I    = "fecini";         // Document start date
    public static final String   COLUMN_TICKETH_DATE_E    = "fecfin";         // Document end date
    public static final String   COLUMN_TICKETH_COMENT    = "coment";         // Server notes (for up-down documents)
    public static final String   COLUMN_TICKETH_CODCLI    = "codcli";         // Customer code
    public static final String   COLUMN_TICKETH_CODALM    = "codalm";         // Store code
    public static final String   COLUMN_TICKETH_DOCORI    = "docori";         // Source document
 
 
/**
* Get the source bean of this edit form
*/
SQLBean      ticketh     = caller;
 
// Obtain PK to get info from header
String       m_terminal_id      = ticketh.getString(Constants.COLUMN_TICKETH_TERMID);
String       m_serie            = ticketh.getString(Constants.COLUMN_TICKETH_SERIE);
String       m_numero           = ticketh.getString(Constants.COLUMN_TICKETH_NUMERO);
 
 
// Info from header
// Get the data in tipdoc via the bean (note that it is not in the form!)
String       m_tipdoc      = ticketh.getString(Constants.COLUMN_TICKETH_TIPDOC);

Example: For SALE (Direct Sale) documents, multiple payments are not permitted.

Copy
// ---------------------------------------------------------------------
 
import android.widget.Toast;
 
/**
* Get the source bean of this edit form
*/
SQLBean      ticketh     = caller;
 
// Obtain PK to get info from header
String       m_terminal_id      = ticketh.getString(Constants.COLUMN_TICKETH_TERMID);
String       m_serie            = ticketh.getString(Constants.COLUMN_TICKETH_SERIE);
String       m_numero           = ticketh.getString(Constants.COLUMN_TICKETH_NUMERO);
 
 
// Info from header
// Get the data in tipdoc via the bean (note that it is not in the form!)
String       m_tipdoc      = ticketh.getString(Constants.COLUMN_TICKETH_TIPDOC);
 
 
 
/******************************************************
* PAYMENTS
*******************************************************/
if(m_tipdoc.equals("SALE")){
     Cursor c = context.getContentResolver().query(
         Constants.tableUri(Constants.tableOf(Constants.TABLE_TICKETC_OPEN)),
         new String[] { "*" },
         null,
         null,
         null
     );
 
    boolean first = false;
    boolean m_multy_payments = false;
 
    while (c.moveToNext()){
        if (!first)   first = true;
        else{
            m_multy_payments = true;
            //while.exit;
            break;
        }
    }
    c.close();
 
 
    if(m_multy_payments){
        Toast.makeText(context, "Pagos Múltiples no permitidos", Toast.LENGTH_LONG).show();
        return false;
    }
}
 
return true;

Payment Validator

For VENP (Sale Order) documents, multiple payments are not permitted.
 

3.9 ticketh.print

The script with the ticketh.print code will be executed when the 'Print' button is pressed, allowing receipt printing to be configured and defined. There is a set of functions intrinsic to the script which can be used:

Example
Copy
caller = CartPrintFormat.java
 
   /******************************************************
    * Instruction to clear buffers and define new buffers.
    *******************************************************/
    buffers.clear();
 
    /**
    * double    getTotal()          
    * double    getReturn()
    * SQLBean   getTicketh()
    * SQLBean   getTicketl()
    * SQLBean   getTicketc()
    * SQLBean   getTicketd()    
    * double    getPayment()
        * int       getGiftMode()       
    * String    getTerminal_id()    
    * String    getTicketSerie()            
    * int       getTicketNumber()
    * String    getTicketNumfac()
        * int       getSeqnoToPrint()
    * boolean   isTicketdInvoice()  
    * void      print(String text)
    * int       getNumberOfCopies() 
    * void      println(String text)
    * SQLBean   getBean(String table)
    * void      setGiftMode(int gift_mode)
        * void      setSeqnoToPrint(int segno)      
    * String    rpad(String text, int size)
    * void      setPrintPCL(String print_command)
    * void      printTable(boolean[] align, String[][] data)
        * void      format(FormaterBuffers formater_buffers, boolean pcl) 
        *
    * PrintFormaterText getPCLFormatter()
    * PrintFormaterText getTextFormatter()
    * PrintFormaterHtml getHtmlFormatter()   
    */

Example: Customize printing (the script defines two types of printing based on the printer model).

Copy
// ******************************************************                                                                                                                                                            
//                                                                                                                                                                                                                   
// [ticketh.print]                                                                                                                                                                                                   
//                                                                                                                                                                                                                   
// Event launched in Print Formatting                                                                                                                                                           
//                                                                                                                                                                                                                   
// * Customized printing                                                                                                                                                                                          
//                                                                                                                                                                                                                   
//                                                                                                                                                                                                                   
// ******************************************************                                                                                                                                                            
 
import android.net.Uri;                                                                                                                                                                                              
import android.util.Base64;                                                                                                                                                                                          
import android.database.Cursor;                                                                                                                                                                                      
import deister.android.apps.Constants;                                                                                                                                                                               
import deister.android.apps.Config;                                                                                                                                                                                  
 
    /******************************************************                                                                                                                                                          
    * HEADER                                                                                                                                                                                                         
    *******************************************************/                                                                                                                                                         
    buffers.clear();                                                                                                                                                                                                 
 
    caller.getHtmlFormatter().open(" "," ");                                                                                                                                                                         
 
    // [0] Normal Print - [1] Gift Mode (No prices) - [2] Gift Mode By Item (One printing for each item)                                                                                                                    
 
    private static int  GIFT_NONE    = 0;                                                                                                                                                                            
    private static int  GIFT_TICKET  = 1;                                                                                                                                                                            
    private static int  GIFT_BY_LINE = 2;                                                                                                                                                                            
 
    int m_gift_mode   = caller.getGiftMode();                                                                                                                                                                        
    int m_seqno       = caller.getSeqnoToPrint();                                                                                                                                                                    
 
    // ESC Comands EPSON TM-T88V                                                                                                                                                                                     
    private final static String ESC_RESET_PRINTER    = Character.toString((char)27) + Character.toString((char)64);                                                                                                  
    private final static String ESC_PRINT_CENTERED   = Character.toString((char)27) + 'a' + Character.toString((char)1);                                                                                             
    private final static String ESC_PRINT_LEFT       = Character.toString((char)27) + 'a' + Character.toString((char)0);                                                                                             
    private final static String ESC_LATIN_CODE_TABLE = Character.toString((char)27) + Character.toString((char)116) +Character.toString((char)16);                                                                   
    private final static String ESC_BREAK_PAPPER     = Character.toString((char)27) + Character.toString((char)105);                                                                                                 
 
    private final static String ESC_OPEN_CASH        = Character.toString((char)27)  +                                                                                                                               
                                                       Character.toString((char)35)  +                                                                                                                               
                                                       Character.toString((char)27)  +                                                                                                                               
                                                       Character.toString((char)61)  +                                                                                                                               
                                                       Character.toString((char)1)   +                                                                                                                               
                                                       Character.toString((char)27)  +                                                                                                                               
                                                       Character.toString((char)61)  +                                                                                                                               
                                                       Character.toString((char)49)  +                                                                                                                               
                                                       Character.toString((char)27)  +                                                                                                                               
                                                       Character.toString((char)112) +                                                                                                                               
                                                       Character.toString((char)48);                                                                                                                                 
    private final static String ESC_DSIZE_WORD       = Character.toString((char)29) + Character.toString((char)33) + Character.toString((char)1);                                                                    
    private final static String ESC_BOLD_WORD        = Character.toString((char)27) + Character.toString((char)69) + Character.toString((char)1);                                                                    
    private final static String ESC_CARAC_ESCAPE     = Character.toString((char)0);                                                                                                                                  
 
    // The logo is omitted                                                                                                                                                                                              
    //caller.setPrintPCL(ESC_RESET_PRINTER + ESC_LATIN_CODE_TABLE + ESC_PRINT_CENTERED + LOGO + ESC_PRINT_LEFT );                                                                                                    
 
    caller.setPrintPCL(ESC_OPEN_CASH);                                                                                                                                                                               
    caller.setPrintPCL(ESC_RESET_PRINTER + ESC_LATIN_CODE_TABLE + ESC_BOLD_WORD + ESC_DSIZE_WORD + ESC_PRINT_CENTERED);                                                                                              
 
    caller.println(" ");                                                                                                                                                                                             
 
    String number = String.valueOf(caller.getTicketNumber());                                                                                                                                                        
    String m_cut = "-----------------------------------------";                                                                                                                                                      
 
    // GET DICTIONARY DATA FOR LANGUAGES                                                                                                                                                               
    Cursor dict = context.getContentResolver().query(
        Constants.tableUri(Constants.tableOf(Constants.TABLE_DICTIONARY)),                                                                                                                                    
        new String[] { "*" },                                                                                                                                                                                        
        Constants.COLUMN_DICTIONARY_LBL_CODE +" LIKE ?",                                                                                                                                                                                           
        new String[] {"print_%"},                                                                                                                                                                                    
        null                                                                                                                                                                                                         
    );                                                                                                                                                                                                               
 
    String print_terminal   = "";                                                                                                                                                                                    
    String print_serie      = "";                                                                                                                                                                                    
    String print_factsimp   = "";                                                                                                                                                                                    
    String print_docori     = "";                                                                                                                                                                                    
    String print_cliente    = "";                                                                                                                                                                                    
    String print_fechafac   = "";                                                                                                                                                                                    
    String print_producto   = "";                                                                                                                                                                                    
    String print_colortalla = "";                                                                                                                                                                                    
    String print_unidades   = "";                                                                                                                                                                                    
    String print_iva        = "";                                                                                                                                                                                    
    String print_baseimp    = "";                                                                                                                                                                                    
    String print_totivainc  = "";                                                                                                                                                                                    
    String print_pagos      = "";                                                                                                                                                                                    
    String print_cabpagos   = "";                                                                                                                                                                                    
    String print_cambio     = "";                                                                                                                                                                                    
    String print_vendedor   = "";                                                                                                                                                                                    
 
 
    while (dict.moveToNext()) {                                                                                                                                                                                      
        dictionary_code  = dict.getString(dict.getColumnIndexOrThrow(Constants.COLUMN_DICTIONARY_LBL_CODE));                                                                                                                                   
        dictionary_desc  = dict.getString(dict.getColumnIndexOrThrow(Constants.COLUMN_DICTIONARY_LBL_DESC));                                                                                                                                   
 
        if(dictionary_code.equals("print_terminal"))   print_terminal   = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_serie"))      print_serie      = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_factsimp"))   print_factsimp   = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_docori"))     print_docori     = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_cliente"))    print_cliente    = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_fechafac"))   print_fechafac   = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_producto"))   print_producto   = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_colortalla")) print_colortalla = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_unidades"))   print_unidades   = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_iva"))        print_iva        = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_baseimp"))    print_baseimp    = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_totivainc"))  print_totivainc  = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_pagos"))      print_pagos      = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_cabpagos"))   print_cabpagos   = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_cambio"))     print_cambio     = dictionary_desc;                                                                                                                           
        if(dictionary_code.equals("print_vendedor"))   print_vendedor   = dictionary_desc;                                                                                                                           
    }                                                                                                                                                                                                                
 
    dict.close();                                                                                                                                                                                                    
 
    Cursor empres = context.getContentResolver().query(
        Constants.tableUri(Constants.tableOf(Constants.TABLE_LOC_STORES)),                                                                                                                                                               
        new String[] { "*" },                                                                                                                                                                                        
        "1 = 1 ",                                                                                                                                                                                                    
        new String[] {},                                                                                                                                                                                             
        null                                                                                                                                                                                                         
    );                                                                                                                                                                                                               
 
    String empresa_store   = "";                                                                                                                                                                                     
    String empresa_nomdlg  = "";                                                                                                                                                                                     
    String empresa_direcc  = "";                                                                                                                                                                                     
    String empresa_codpos  = "";                                                                                                                                                                                     
    String empresa_nomprv  = "";                                                                                                                                                                                     
    String empresa_cif     = "";                                                                                                                                                                                     
    String empresa_telef1  = "";                                                                                                                                                                                     
    String empresa_web     = "";                                                                                                                                                                                     
    String empresa_country = "";                                                                                                                                                                                     
    String empresa_zonimp  = "";                                                                                                                                                                                     
 
    while (empres.moveToNext()) {                                                                                                                                                                                    
        empresa_store   = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_CODE));                                                                                                                              
        empresa_nomdlg  = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_NAME));                                                                                                                              
        empresa_direcc  = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_DIRECC));                                                                                                                            
        empresa_codpos  = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_ZIP));                                                                                                                           
        empresa_nomprv  = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_STATE));                                                                                                                              
        empresa_cif     = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_CIF));                                                                                                                               
        empresa_telef1  = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_TELEF1));                                                                                                                            
        empresa_web     = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_WEB));                                                                                                                               
        empresa_country = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_COUNTRY));                                                                                                                            
        //empresa_zonimp  = empres.getString(empres.getColumnIndexOrThrow(Constants.COLUMN_LOC_STORES_CODE));                                                                                                                            
    }                                                                                                                                                                                                                
    empres.close();                                                                                                                                                                                                  
 
    caller.println(empresa_nomdlg);                                                                                                                                                                                  
 
    // Remove bold and leave as plain text                                                                                                                                                                             
    caller.setPrintPCL(ESC_CARAC_ESCAPE + ESC_RESET_PRINTER + ESC_LATIN_CODE_TABLE + ESC_PRINT_CENTERED);                                                                                                            
 
    // FOR STORES IN PORTUGAL OR CANARY ISLANDS, INDICATE RETAIL BUSINESS                                                                                                                                              
    if (empresa_store.equals("0331") || empresa_store.equals("0332") || empresa_store.equals("0333"))                                                                                                                
        caller.println("Retail Business");                                                                                                                                                                        
 
    String terminal_id = caller.getTicketh().getString(Constants.COLUMN_TICKETH_TERMID);                                                                                                                             
 
    // FOR STORES IN PORTUGAL OR FOR RUMBO S.A. TERMINALS [3020] DO NOT SHOW Mustang Store                                                                                                                                 
    if (empresa_country.equals("ESP") && !empresa_store.equals("0320"))                                                                                                                                              
        caller.println("Mustang Store S.L.");                                                                                                                                                                        
 
    if(empresa_direcc != null)                                                                                                                                                                                       
        caller.println(empresa_direcc);                                                                                                                                                                              
 
    caller.println(empresa_codpos + " " + empresa_nomprv);                                                                                                                                                           
 
    // IF COUNTRY IS NOT SPAIN, REMOVE FIRST TWO DIGITS FROM CIF                                                                                                                                                  
    // FOR RUMBO S.A. STORES, CHANGE CIF MANUALLY                                                                                                                                          
    if (empresa_country.equals("PRT")){                                                                                                                                                                              
        caller.println("CIF:" + empresa_cif);                                                                                                                                                                        
        // caller.println("Certificate Number: 1637"); THE NUMBER DOES NOT NEED TO BE REMOVED HERE                                                                                                                              
    }else{                                                                                                                                                                                                           
        if (empresa_store.equals("0320")){                                                                                                                                                                           
            caller.println("A-30037873");                                                                                                                                                                            
        }else{                                                                                                                                                                                                       
            if(empresa_cif != null)                                                                                                                                                                                  
                caller.println(empresa_cif);                                                                                                                                                                         
        }                                                                                                                                                                                                            
     }                                                                                                                                                                                                               
 
    if(empresa_telef1 != null)                                                                                                                                                                                       
        caller.println("Tfno." + empresa_telef1);                                                                                                                                                                    
 
    caller.println(" ");                                                                                                                                                                                             
    caller.println(" ");                                                                                                                                                                                             
 
    // Configuration for writing on the left                                                                                                                                                                 
    caller.setPrintPCL(ESC_RESET_PRINTER + ESC_LATIN_CODE_TABLE + ESC_PRINT_LEFT );                                                                                                                                  
 
    /******************************************************                                                                                                                                                          
    * BODY                                                                                                                                                                                                           
    ******************************************************/                                                                                                                                                          
 
    String serie       = caller.getTicketh().getString(Constants.COLUMN_TICKETH_SERIE);     // Receipt series                                                                                     
    String codcli      = caller.getTicketh().getString(Constants.COLUMN_TICKETH_CODCLI);    // Customer code                                                                                                     
    String cliente     = caller.getTicketh().getString(Constants.COLUMN_TICKETH_CODCLI);    // Field used to get customer data                                                                         
    String tipdoc      = caller.getTicketh().getString(Constants.COLUMN_TICKETH_TIPDOC);    // Document type code                                                                                      
    String docori      = caller.getTicketh().getString(Constants.COLUMN_TICKETH_DOCORI);    // Source document                                                                                                    
    String numfac      = caller.getTicketh().getString(Constants.COLUMN_TICKETH_NUMFAC);    // Invoice number                                                                                                      
    String sign_hash   = caller.getTicketh().getString(Constants.COLUMN_TICKETH_SIGN_HASH); // HASH (SAF-T) signature                                                                                                   
 
    String dateTime_ini =  SQLBean.getUserDateTimeFormat().format(caller.getTicketh().getTimestamp(Constants.COLUMN_TICKETH_DATE_I));                                                                                
    // String dateTime_ini =  SQLBean.getSystemDateFormat().format(caller.getTicketh().getTimestamp(Constants.COLUMN_TICKETH_DATE_I));                                                                               
 
    // System.err.println("dateTime_ini:" + dateTime_ini);                                                                                                                                                           
    // System.err.println("dateTime_ini2:" + dateTime_ini2);                                                                                                                                                         
 
    // If the customer code is PAsserby... the customer code must be substituted for the equivalent.                                                                                                           
    if(codcli != null){                                                                                                                                                                                              
        // New customer                                                                                                                                                                                            
        if(codcli.startsWith("T")){                                                                                                                                                                                  
            String[] arr = codcli.split("-");                                                                                                                                                                        
            String first = arr[0];                                                                                                                                                                                   
            int    num   = Integer.valueOf(arr[1]);                                                                                                                                                                  
            codcli = first + "-" + String.valueOf(num);                                                                                                                                                              
        }                                                                                                                                                                                                            
    }                                                                                                                                                                                                                
 
    // Get country currency and check if SAF-T certificate is required                                                                                                                                                 
    Cursor p = context.getContentResolver().query(Constants.tableUri("apps_sys_countries"),                                                                                                                          
                                                  new String[] { "*" },                                                                                                                                              
                                                  "country_code = ?",                                                                                                                                                
                                                  new String[] {empresa_country},                                                                                                                                    
                                                  null);                                                                                                                                                             
 
    String country_money = "";                                                                                                                                                                                       
    int country_saft = 0;                                                                                                                                                                                            
 
    while (p.moveToNext()) {                                                                                                                                                                                         
        country_money  = p.getString(p.getColumnIndexOrThrow("currency_money"));                                                                                                                                     
        country_saft   = p.getInt(p.getColumnIndexOrThrow("cert_saft"));                                                                                                                                             
    }                                                                                                                                                                                                                
 
    p.close();                                                                                                                                                                                                       
 
    // Get description of document type                                                                                                                                                      
    String nomdoc = "";                                                                                                                                                                                              
    int request_saft = 0;                                                                                                                                                                                            
 
    Cursor t = context.getContentResolver().query(Constants.tableUri(Constants.tableOf(Constants.TABLE_POS_TICKETD)),                                                                                                                          
                                                  new String[] { "*" },                                                                                                                                              
                                                  Constants.COLUMN_TICKETD_CODIGO +" = ?",                                                                                                                                                      
                                                  new String[] {tipdoc},                                                                                                                                             
                                                  null);                                                                                                                                       
 
    while (t.moveToNext()) {                                                                                                                                                                                         
        nomdoc = t.getString(t.getColumnIndexOrThrow("nomdoc"));                                                                                                                                                     
        request_saft = t.getInt(t.getColumnIndexOrThrow("request_saft"));                                                                                                                                            
    }                                                                                                                                                                                                                
 
    t.close();                                                                                                                                                                                                       
 
    caller.println(nomdoc);                                                                                                                                                                                          
 
    caller.println(print_terminal + "  :" + terminal_id);                                                                                                                                                            
    caller.println(print_serie + "        :" + serie);                                                                                                                                                               
 
    // IF THE DOCUMENT INCLUDES SAF-T, THE DOCUMENT MUST BE SHOWN WITH ITS NUMBER AND                                                                                                                                     
    // INVOICE (NUMFAC) SIMPLIFIED WITH NO JUMPS IN NUMBERING                                                                                                                                                      
    if (country_saft == 1 && request_saft == 1){                                                                                                                                                                     
        caller.println("Número ticket :" + numero); // IF SAF-T, DOCUMENT NUMBER AND INVOICE NUMBER MUST BE SHOWN                                                                                                     
        caller.println(print_factsimp + " :" + numfac);                                                                                                                                                              
    }else{                                                                                                                                                                                                           
        caller.println(print_factsimp + " :" + numero); // IF NOT SAF-T, ONLY DOCUMENT NUMBER AS A SIMPLIFIED INVOICE MUST BE SHOWN                                                                                               
    }                                                                                                                                                                                                                
 
    // When validating return receipts, original receipts will be shown                                                                                                                                            
    if(docori != null) caller.println(print_docori + " :" + docori);                                                                                                                                                 
 
    // If a sale receipt for the customer is not generated, this field will not appear                                                                                                                                        
    if (codcli != null ) caller.println(print_cliente + " :" + codcli);                                                                                                                                              
 
    caller.println(" ");                                                                                                                                                                                             
 
    /** CUSTOMER DATA FOR SALE OR RETURN DOCUMENTS                                                                                                                                           
        The customer may be recently registered (apps_customers_new), or may already have been sent to the                                                                                                          
        apps_clientes table                                                                                                                                                                                     
    **/                                                                                                                                                                                                              
    if (codcli != null) {                                                                                                                                                                                            
        Cursor c = context.getContentResolver().query(
        Constants.tableUri(Constants.tableOf(Constants.TABLE_CUSTOMERS_NEW)),                                                                                                                                           
        new String[] { "*" },                                                                                                                                                                                        
        Constants.COLUMN_CUSTOMERS_CUSTOMER_CODE + " = ?",                                                                                                                                                                                         
        new String[] {cliente},                                                                                                                                                                                      
        null                                                                                                                                                                                                         
        );                                                                                                                                                                                                           
 
        String user_name = "";                                                                                                                                                                                       
        String user_address = "";                                                                                                                                                                                    
        String user_postcode = "";                                                                                                                                                                                   
        String user_city = "";                                                                                                                                                                                       
        String user_cif = "";                                                                                                                                                                                        
 
        while (c.moveToNext()) {                                                                                                                                                                                     
            user_name = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_NAME));                                                                                                                                       
            user_address = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_DIRECC));                                                                                                                                  
            user_postcode = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_CODPOS));                                                                                                                                 
            user_city = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_POBLAC));                                                                                                                                     
            user_cif = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_CIF));                                                                                                                                         
 
            caller.println(m_cut);                                                                                                                                                                                   
 
            caller.println(user_name);                                                                                                                                                                               
            if(user_address != null && user_address != "-") caller.println((user_address == null ? "" : user_address));                                                                                              
            if(user_postcode != null && user_postcode != "-" && user_city != null && user_city != "-") caller.println((user_postcode == null ? "" : user_postcode) + " " + (user_city == null ? "" : user_city));    
            caller.println(user_cif);                                                                                                                                                                                
 
            caller.println(m_cut);                                                                                                                                                                                   
        }                                                                                                                                                                                                            
 
        c.close();                                                                                                                                                                                                   
 
        if(user_name == "" || user_name.length() <= 0){                                                                                                                                                              
            Cursor c = context.getContentResolver().query(
            Constants.tableUri(Constants.tableOf(Constants.TABLE_CUSTOMERS)),                                                                                                                                                                    
            new String[] { "*" },                                                                                                                                                                                    
            Constants.COLUMN_CUSTOMERS_CUSTOMER_CODE + " = ?",                                                                                                                                                                                     
            new String[] {cliente},                                                                                                                                                                                  
            null                                                                                                                                                                                                     
            );                                                                                                                                                                                                       
 
            while (c.moveToNext()) {                                                                                                                                                                                 
                user_name = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_NAME));                                                                                                                                   
                user_address = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_DIRECC));                                                                                                                              
                user_postcode = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_CODPOS));                                                                                                                             
                user_city = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_POBLAC));                                                                                                                                 
                user_cif = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_CUSTOMERS_CUSTOMER_CIF));                                                                                                                                     
 
                caller.println(m_cut);                                                                                                                                                                               
 
                caller.println(user_name);                                                                                                                                                                           
                if(user_address != null && user_address != "-") caller.println((user_address == null ? "" : user_address));                                                                                          
                if(user_postcode != null && user_postcode != "-" && user_city != null && user_city != "-") caller.println((user_postcode == null ? "" : user_postcode) + " " + (user_city == null ? "" : user_city));
                caller.println(user_cif);                                                                                                                                                                            
 
                caller.println(m_cut);                                                                                                                                                                               
            }                                                                                                                                                                                                        
 
            c.close();                                                                                                                                                                                               
        }                                                                                                                                                                                                            
    }                                                                                                                                                                                                                
 
    caller.println(print_fechafac + ": " + dateTime_ini.replaceAll("-","/"));                                                                                                                                        
 
    /******************************************************                                                                                                                                                          
    * LINES                                                                                                                                                                                                         
    *******************************************************/                                                                                                                                                         
 
    Cursor l = Constants.getCartItemsCursor(context.getContentResolver(), caller.getTicketl().getUri(), new String[] { terminal_id, serie, String.valueOf(numero) });                                                
 
    int size = 0; // Size of the second line in receipt details                                                                                                                                                  
 
    caller.println(m_cut);                                                                                                                                                                                           
    caller.println(print_producto);                                                                                                                                                                                  
    caller.println(print_colortalla);                                                                                                                                                                                
    caller.println("            " + print_unidades);                                                                                                                                                                 
    caller.println(m_cut);                                                                                                                                                                                           
 
    while (l.moveToNext()) {                                                                                                                                                                                         
 
        int seqno = l.getInt(l.getColumnIndexOrThrow(Constants.COLUMN_TICKETL_SEQNO));                                                                                                                               
 
        if(m_gift_mode == GIFT_BY_LINE && seqno != m_seqno)                                                                                                                                                          
            continue;                                                                                                                                                                                                
 
        String nomart = caller.rpad(l.getString(l.getColumnIndexOrThrow(Constants.COLUMN_ITEMS_ITEM_DESC)), 40);                                                                                                     
        String codean = l.getString(l.getColumnIndexOrThrow("codean"));                                                                                                                                              
        double cantid = l.getDouble(l.getColumnIndexOrThrow("cantid_1"));                                                                                                                                            
        double precio = l.getDouble(l.getColumnIndexOrThrow("precio"));                                                                                                                                              
        double descuento = l.getDouble(l.getColumnIndexOrThrow("descuen"));                                                                                                                                          
        double impnet   = l.getDouble(l.getColumnIndexOrThrow("impnet"));                                                                                                                                            
 
        if(m_gift_mode == GIFT_BY_LINE)                                                                                                                                                                              
            cantid = 1;                                                                                                                                                                                              
 
        if(m_gift_mode != GIFT_NONE){                                                                                                                                                                                
            precio = 0;                                                                                                                                                                                              
            impnet = 0;                                                                                                                                                                                              
        }                                                                                                                                                                                                            
 
        /** ========================================================================================= */                                                                                                             
        /** GET ITEM COLOR AND SIZE DESCRIPTION FROM APPS_POS_EANS TABLE                              */                                                                                                             
        /** ========================================================================================= */                                                                                                             
        String col_tal = ""; // Stores item color and size, separated by a dash                                                                                                                         
        String color = "";   // Stores color description                                                                                                                                                    
        String talla = "";   // Stores size                                                                                                                                                                    
        String cladoc = "";  // Document classification                                                                                                                                                              
        int sizedesc = 0;    // Variable to adjust the size of the color/size descriptions                                                                                                                                     
 
        Cursor c = context.getContentResolver().query(Constants.tableUri(Constants.tableOf(Constants.TABLE_POS_EANS)),                                       
                                                      new String[] { "DISTINCT nomvar" },                                                                                                                            
                                                      Constants.COLUMN_EANS_CODEAN +" = ?",                                                                                                                                                  
                                                      new String[] {codean},                                                                                                                                         
                                                      null);                                                                                                                                                         
 
        while (c.moveToNext()) {                                                                                                                                                                                     
            col_tal = c.getString(c.getColumnIndexOrThrow(Constants.COLUMN_EANS_NOMVAR));                                                                                                                                                
        }                                                                                                                                                                                                            
 
        c.close();                                                                                                                                                                                                   
 
        String[] separator = null;                                                                                                                                                                                   
 
        String the_line1 = nomart;                                                                                                                                                                                   
        String the_line2 = col_tal.trim();                                                                                                                                                                           
        String the_line3 = String.format("%3.0f %1s %5.3f %3.2f %6.2f %3s", new Object[]{cantid,"x", price, discount, netamt, country_money} );                                                                    
 
        // Complete length of 40 with blank spaces on the left                                                                                                                                               
        size = 40 - the_line3.length();                                                                                                                                                                              
        if (size > 0) for(int j = 1 ; j <= size ; j++) the_line3 = " " + the_line3;                                                                                                                                  
 
        caller.println(the_line1);                                                                                                                                                                                   
        caller.println(the_line2);                                                                                                                                                                                   
        caller.println(the_line3);                                                                                                                                                                                   
    }                                                                                                                                                                                                                
    l.close();                                                                                                                                                                                                       
 
    /******************************************************                                                                                                                                                          
    * TAXES                                                                                                                                                                                                     
    *******************************************************/                                                                                                                                                         
    if(m_gift_mode == GIFT_NONE){                                                                                                                                                                                    
 
          double tot_sin_iva = 0;                                                                                                                                                                                      
 
        Cursor impues = Constants.getImpporCursor(context.getContentResolver(), caller.getTicketl().getUri(), new String[] {terminal_id, serie, numero, empresa_zonimp, empresa_zonimp});                            
 
        // Cursor impues = context.getContentResolver().query(Constants.tableUri("apps_pos_ticketl_close " +                                                                                                         
        //                                                                       " JOIN apps_pos_eans ON apps_pos_ticketl_close.codean = apps_pos_eans.codean " +                                                    
        //                                                                       " JOIN apps_pos_items_v ON apps_pos_eans.item_code = apps_pos_items_v.item_code " +                                                 
        //                                                                       " JOIN apps_pos_taxes_operations ON apps_pos_taxes_operations.tax_item = apps_pos_items_v.tax_code " +                              
        //                                                                       " JOIN apps_pos_taxes ON apps_pos_taxes_operations.tax_code = apps_pos_taxes.tax_code "                                             
        //                                                                       ),                                                                                                                                  
        //                                                    new String[] {" apps_pos_taxes.tax_imppor, " +                                                                                                         
        //                                                                  " SUM(apps_pos_ticketl_close.impnet / (1 + apps_pos_taxes.tax_imppor * 0.01) * (apps_pos_taxes.tax_imppor * 0.01)) quota, " +            
        //                                                                  " SUM(apps_pos_ticketl_close.impnet / (1 + apps_pos_taxes.tax_imppor * 0.01)) base "},                                                   
        //                                                    " apps_pos_ticketl_close.terminal_id = ? AND " +                                                                                                       
        //                                                    " apps_pos_ticketl_close.serie = ? AND " +                                                                                                             
        //                                                    " apps_pos_ticketl_close.numero = ? AND " +                                                                                                            
        //                                                    " apps_pos_eans.catalog = apps_pos_ticketl_close.terminal_id AND " +                                                                                   
        //                                                    " apps_pos_taxes_operations.tax_company  = ? AND " +                                                                                                   
        //                                                    " apps_pos_taxes_operations.tax_customer = ? AND " +                                                                                                   
        //                                                    caller.getTicketh().getString(Constants.COLUMN_TICKETH_DATE_I) + " BETWEEN apps_pos_taxes.tax_fecini AND apps_pos_taxes.tax_fecfin ) " +               
        //                                                    " GROUP BY (1",                                                                                                                                        
        //                                                    new String[] {terminal_id, serie, numero, empresa_zonimp, empresa_zonimp},                                                                             
        //                                                    null);                                                                                                                                                 
 
        caller.println(" ");                                                                                                                                                                                         
        caller.println(m_cut);                                                                                                                                                                                       
        caller.println(" ");                                                                                                                                                                                         
 
        while (impues.moveToNext()) {                                                                                                                                                                                
 
            double imppor = impues.getDouble(impues.getColumnIndexOrThrow("tax_imppor"));                                                                                                                            
            double quota  = impues.getDouble(impues.getColumnIndexOrThrow("quota"));                                                                                                                                 
            double base   = impues.getDouble(impues.getColumnIndexOrThrow("base"));                                                                                                                                  
 
            tot_sin_iva = tot_sin_iva + base;                                                                                                                                                                        
 
            caller.println(print_iva + " ("+ String.format("%2.2f", new Object[]{imppor}) + "%)   : " + String.format("%7.2f", new Object[]{quota}) + " " + country_money);                                          
            caller.println(String.format("%-15s", new Object[]{print_baseimp}) + ": " + String.format("%7.2f", new Object[]{tot_sin_iva}) + " " + country_money);                                                    
        }                                                                                                                                                                                                            
 
        impues.close();                                                                                                                                                                                              
    }                                                                                                                                                                                                                
 
    caller.println(" ");                                                                                                                                                                                             
 
    // Configuration to write receipt total                                                                                                                                                             
    caller.setPrintPCL(ESC_RESET_PRINTER + ESC_LATIN_CODE_TABLE + ESC_PRINT_CENTERED + ESC_DSIZE_WORD + ESC_BOLD_WORD );                                                                                             
 
    caller.println(print_totivainc + " :" + String.format("%8.2f", new Object[]{ m_gift_mode != GIFT_NONE ? 0.00 : caller.getTotal() }) + " " + country_money);                                                      
 
    // Configuration to write left-aligned                                                                                                                                                                
    caller.setPrintPCL(ESC_CARAC_ESCAPE + ESC_RESET_PRINTER + ESC_LATIN_CODE_TABLE + ESC_PRINT_LEFT );                                                                                                               
 
    caller.println(" ");                                                                                                                                                                                             
 
    if(m_gift_mode == GIFT_NONE){                                                                                                                                                                                    
        /******************************************************                                                                                                                                                      
        * PAYMENTS                                                                                                                                                                                                   
        *******************************************************/                                                                                                                                                     
        caller.println(print_pagos);                                                                                                                                                                                 
        caller.println(m_cut);                                                                                                                                                                                       
        caller.println(print_cabpagos);                                                                                                                                                                              
        caller.println(m_cut);                                                                                                                                                                                       
 
        boolean m_payments = false;                                                                                                                                                                                  
        String line_begin = ""; // Variable to compose new start line for payment details                                                                                                                      
        String line_end   = ""; // Variable to compose new end line for payment details                                                                                                                         
        String pag_line   = ""; // Variable to compose complete line for payment type                                                                                                                            
        int fill = 0;                                                                                                                                                                                                
 
        Cursor e = Constants.getCartCashCursor(context.getContentResolver(), caller.getTicketc().getUri(), new String[] { terminal_id, serie, String.valueOf(numero) });                                             
 
        while (e.moveToNext()) {                                                                                                                                                                                     
            m_payments = true;                                                                                                                                                                                       
 
            line_begin = " " + e.getString(e.getColumnIndexOrThrow("pay_type")) + "      " + e.getString(e.getColumnIndexOrThrow("pay_desc"));                                                                       
            line_end = String.format("%8.2f", new Object[]{e.getFloat(e.getColumnIndexOrThrow("pay_amount"))}) + " " + country_money;                                                                                
            fill = 41 - (line_begin.length() + line_end.length()); // Length of spaces filled in                                                                                                                 
 
            // Fill in the starting string with as many spaces as needed to equal the text                                                                                                          
            for(int j = 1 ; j <= fill ; j++) line_begin = line_begin + " ";                                                                                                                                          
 
            // Compose complete line                                                                                                                                                                               
            pag_line = line_begin + line_end;                                                                                                                                                                        
 
            caller.println(pag_line);                                                                                                                                                                                
        }                                                                                                                                                                                                            
        e.close();                                                                                                                                                                                                   
 
        if(m_payments){                                                                                                                                                                                              
            caller.println(m_cut);                                                                                                                                                                                   
            caller.println(print_cambio + "   :" + String.format("%8.2f", new Object[]{caller.getReturn()})  + " " + country_money);                                                                                 
            caller.println(" ");                                                                                                                                                                                     
        }                                                                                                                                                                                                            
    }                                                                                                                                                                                                                
 
    /** ******************************************************** PRINT BARCODE ********************************************************************* */                                                    
    String ean = terminal_id + serie + numero;                                                                                                                                                                       
    int length = ean.length();                                                                                                                                                                                     
 
    String ESC_ANCHO_BARCODE = "";                                                                                                                                                                                   
 
    if (length > 9){                                                                                                                                                                                               
         ESC_ANCHO_BARCODE = Character.toString((char)29) + Character.toString((char)119)+ Character.toString((char)2);                                                                                              
    } else {                                                                                                                                                                                                         
         ESC_ANCHO_BARCODE  = Character.toString((char)29) + Character.toString((char)119)+ Character.toString((char)3);                                                                                             
    }                                                                                                                                                                                                                
 
    String  ESC_ALTO_BARCODE   = Character.toString((char)29) + Character.toString((char)104)+ Character.toString((char)35);                                                                                         
    String  ESC_PRINT_BARCODE  = Character.toString((char)29) + Character.toString((char)107)+ Character.toString((char)69) + Character.toString((char)longitud);                                                    
 
    caller.setPrintPCL(ESC_RESET_PRINTER + ESC_PRINT_CENTERED + ESC_ALTO_BARCODE);                                                                                                                                   
 
    caller.setPrintPCL(ESC_ANCHO_BARCODE + ESC_PRINT_BARCODE + ean + ESC_CARAC_ESCAPE);                                                                                                                              
 
    caller.setPrintPCL(ESC_RESET_PRINTER + ESC_LATIN_CODE_TABLE + ESC_PRINT_LEFT );                                                                                                                                  
 
    /** ****************************************************************************************************************************************************** */                                                    
 
    caller.println(" ");                                                                                                                                                                                             
 
    // Get employee code from receipt/document                                                                                                                                                            
    // If code is not found, this is because the receipt/document has been closed and reprinted                                                                                                                                               
    String coduser = "";                                                                                                                                                                                             
 
    Cursor e = context.getContentResolver().query(
    Constants.tableUri(Constants.tableOf(Constants.TABLE_TICKETH_OPEN)),                                                                                                                                                                 
    new String[] { "*" },                                                                                                                                                                                            
    Constants.COLUMN_TICKETH_NUMERO + " = ?",                                                                                                                                                                                                    
    new String[] {number},                                                                                                                                                                                           
    null                                                                                                                                                                                                             
    );                                                                                                                                                                                                               
 
    while (e.moveToNext()) {                                                                                                                                                                                         
        coduser = e.getString(e.getColumnIndexOrThrow(Constants.COLUMN_TICKETH_LOGIN));                                                                                                                                                 
    }                                                                                                                                                                                                                
    e.close();                                                                                                                                                                                                       
 
    if (coduser == ""){                                                                                                                                                                                              
        Cursor e = context.getContentResolver().query(
        Constants.tableUri(Constants.tableOf(Constants.TABLE_TICKETH_CLOSE)),                                                                                                                                               
        new String[] { "*" },                                                                                                                                                                                        
        Constants.COLUMN_TICKETH_NUMERO + " = ?",                                                                                                                                                                                                
        new String[] {numero},                                                                                                                                                                                       
        null                                                                                                                                                                                                         
        );                                                                                                                                                                                                           
 
        while (e.moveToNext()) {                                                                                                                                                                                     
            coduser = e.getString(e.getColumnIndexOrThrow(Constants.COLUMN_TICKETH_LOGIN));                                                                                                                                             
        }                                                                                                                                                                                                            
        e.close();                                                                                                                                                                                                   
    }                                                                                                                                                                                                                
 
    // Get name of employee who performed the transaction                                                                                                                                                    
    Cursor v = context.getContentResolver().query(
    Constants.tableUri(Constants.tableOf(Constants.TABLE_SYS_USERS)),                                                                                                                                                            
    new String[] { "*" },                                                                                                                                                                                            
    Constants.COLUMN_USERS_CODE + " = ?",                                                                                                                                                                                                 
    new String[] {coduser},                                                                                                                                                                                          
    null                                                                                                                                                                                                             
    );                                                                                                                                                                                                               
 
    String user = "";                                                                                                                                                                                                
 
    while (v.moveToNext()) {                                                                                                                                                                                         
        user = v.getString(v.getColumnIndexOrThrow(Constants.COLUMN_USERS_NAME));                                                                                                                                                    
        caller.println(print_vendedor + " : " + coduser + " " + user);                                                                                                                                               
    }                                                                                                                                                                                                                
    v.close();                                                                                                                                                                                                       
 
    /******************************************************                                                                                                                                                          
    * HASH SIGNATURE                                                                                                                                                                                                     
    *******************************************************/                                                                                                                                                         
    if (country_saft == 1 && request_saft == 1){                                                                                                                                                                     
 
        // GET DICTIONARY DATA FOR LANGUAGES                                                                                                                                                            
        Cursor saft = context.getContentResolver().query(
            Constants.tableUri(Constants.tableOf(Constants.TABLE_DICTIONARY)),                                                                                                                                                      
            new String[] { "*" },                                                                                                                                                                                    
            Constants.COLUMN_DICTIONARY_LBL_CODE + " LIKE ?",                                                                                                                                                                                       
            new String[] {"saft_footer%"},                                                                                                                                                                           
            null                                                                                                                                                                                                     
        );                                                                                                                                                                                                           
 
        String saft_footer_none_ok  = "";                                                                                                                                                                            
        String saft_footer_ok       = "";                                                                                                                                                                            
 
        while (saft.moveToNext()) {                                                                                                                                                                                  
            dictionary_code  = saft.getString(saft.getColumnIndexOrThrow(Constants.COLUMN_DICTIONARY_LBL_CODE));                                                                                                                               
            dictionary_desc  = saft.getString(saft.getColumnIndexOrThrow(Constants.COLUMN_DICTIONARY_LBL_DESC));                                                                                                                               
 
            if(dictionary_code.equals("saft_footer_none_ok")) saft_footer_none_ok  = dictionary_desc;                                                                                                                
            if(dictionary_code.equals("saft_footer_ok"))      saft_footer_ok       = dictionary_desc;                                                                                                                
        }                                                                                                                                                                                                            
 
        saft.close();                                                                                                                                                                                                
 
        if( sign_hash == null || sign_hash.trim() == "" ) {                                                                                                                                                          
            caller.println(" ");                                                                                                                                                                                     
            caller.println(saft_footer_none_ok);                                                                                                                                                                     
        }else{                                                                                                                                                                                                       
            caller.println(" ");                                                                                                                                                                                     
            String m_saft = sign_hash.substring(0,1) + sign_hash.substring(10,11) + sign_hash.substring(20,21) + sign_hash.substring(30,31);                                                                         
            caller.println(m_saft + " " + saft_footer_ok + " 1637");  // 1637 is AXIONAL's number on the list of certified programs                                                                              
        }                                                                                                                                                                                                            
    }                                                                                                                                                                                                                
 
    // Configure printer to print in centered alignment                                                                                                                                                                   
    caller.setPrintPCL(ESC_RESET_PRINTER + ESC_LATIN_CODE_TABLE + ESC_PRINT_CENTERED );                                                                                                                              
 
    /******************************************************                                                                                                                                                                                
    * CUSTOMIZED FOOTERS                                                                                                                                                                                                                    
    *******************************************************/                                                                                                                                                                               
    Cursor tpvtext = context.getContentResolver().query(Constants.tableUri(" mtn_tpv_text_v "),                                                                                                                                            
                                                       new String[] {" mtn_tpv_text_v.orden, mtn_tpv_text_v.linea "},                                                                                                                      
                                                       " mtn_tpv_text_v.delega = ? AND " + caller.getTicketh().getString(Constants.COLUMN_TICKETH_DATE_I) + " BETWEEN mtn_tpv_text_v.fecini AND mtn_tpv_text_v.fecfin ) " + " ORDER BY (1",
                                                       new String[] {empresa_store},                                                                                                                                                       
                                                       null);                                                                                                                                                                              
    caller.println(" ");                                                                                                                                                                                                                   
    caller.println(" ");                                                                                                                                                                                                                   
 
    int texto_promocional = 0;                                                                                                                                                                                                             
 
    while (tpvtext.moveToNext()) {                                                                                                                                                                                                         
        texto_promocional = 1;                                                                                                                                                                                                             
        foot_text = tpvtext.getString(tpvtext.getColumnIndexOrThrow("linea"));                                                                                                                                                             
        if(foot_text == null){                                                                                                                                                                                                             
            caller.println(" ");                                                                                                                                                                                                           
        }else{                                                                                                                                                                                                                             
            caller.println(foot_text);                                                                                                                                                                                                     
        }                                                                                                                                                                                                                                  
    }                                                                                                                                                                                                                                      
 
    if (texto_promocional == 1){                                                                                                                                                                                                           
        caller.println(" ");                                                                                                                                                                                                               
        caller.println(" ");                                                                                                                                                                                                               
        caller.println(" ");                                                                                                                                                                                                               
        caller.println(" ");                                                                                                                                                                                                               
    } else {                                                                                                                                                                                                                               
        caller.println(" ");                                                                                                                                                                                                               
        caller.println(" ");                                                                                                                                                                                                               
    }                                                                                                                                                                                                                                      
 
    tpvtext.close();                                                                                                                                                                                                                       
 
    caller.setPrintPCL(ESC_RESET_PRINTER + ESC_BREAK_PAPPER + ESC_RESET_PRINTER);

Example Receipts/Documents

Return Client Sale Direct Sale Direct Sale 2
 

3.10 apps_pos_cash.print

The script with the apps_pos_cash.print code will be executed when the 'Print' button is pressed, allowing receipt/document printing to be configured and defined. There is a set of intrinsic functions which can be used:

Example
Copy
caller = PrintFormaterText.java
 
   /******************************************************
    * Instruction to clear buffers and define new buffers.
    *******************************************************/
    buffers.clear();
 
 
 
    /**
    * boolean is_blind()
    * SQLBean getCajah()
    * SQLBean getCajal()
    * String getTerminal_id()
    * String get_login_code_open()
    * String get_login_code_close()
    * String get_login_code_open_name()
    * String get_login_code_close_name()
    * String getDateTime_ini()
    * String getDateTime_fin()
    * ArrayList<String> get_stat_message()
    */

Example: Customize printing

Copy
// ******************************************************
//
// [apps_pos_cajah.print]
//
// Event launched in Print Formatting for a cash count / audit printing job
//
// * Customized printing
//
//
// ******************************************************
import java.sql.Timestamp;
import java.text.*;
import deister.android.apps.Constants;
import deister.android.common.util.StringUtils;
import deister.android.apps.print.PrinterConfig;
import deister.android.apps.print.PrintFormater;
import deister.android.apps.print.PrintColumn;
import deister.android.apps.print.FormaterHolder;
import deister.android.apps.print.FormaterBuffers;
import deister.android.apps.config.DLGConfig;
import android.database.Cursor;
 
// ESC Comands EPSON TM-T88V
private final static String ESC_RESET_PRINTER    = Character.toString((char)27) + Character.toString((char)64);
private final static String ESC_PRINT_CENTERED   = Character.toString((char)27) + 'a' + Character.toString((char)1);
private final static String ESC_PRINT_LEFT       = Character.toString((char)27) + 'a' + Character.toString((char)0);
private final static String ESC_LATIN_CODE_TABLE = Character.toString((char)27) + Character.toString((char)116) +Character.toString((char)16);
private final static String ESC_BREAK_PAPPER     = Character.toString((char)27) + Character.toString((char)105);
 
private final static String ESC_OPEN_CASH        = Character.toString((char)27)  +
                                                   Character.toString((char)35)  +
                                                   Character.toString((char)27)  +
                                                   Character.toString((char)61)  +
                                                   Character.toString((char)1)   +
                                                   Character.toString((char)27)  +
                                                   Character.toString((char)61)  +
                                                   Character.toString((char)49)  +
                                                   Character.toString((char)27)  +
                                                   Character.toString((char)112) +
                                                   Character.toString((char)48);
private final static String ESC_DSIZE_WORD       = Character.toString((char)29) + Character.toString((char)33) + Character.toString((char)1);
private final static String ESC_BOLD_WORD        = Character.toString((char)27) + Character.toString((char)69) + Character.toString((char)1);
private final static String ESC_CARAC_ESCAPE     = Character.toString((char)0);
 
buffers.clear();
 
int page_cols = PrinterConfig.getInstance().getColumns();
 
// Printing here, we write on the underlying buffers for TEXT, HTML, PCL ...
FormaterHolder  print_holder = new FormaterHolder();
 
print_holder.initBuffers(buffers);
print_holder.open("", "");
 
 
print_holder.setColumns(
  new PrintColumn[] {
    new PrintColumn("", "", (page_cols), true /* right */)}
);
 
// ******************************************************
// Variable Definition
// ******************************************************
String m_cut = "------------------------------------";
Long   timestamp = null;
String fecfin = "";
String terminal_id = "";
String login_code = "";
String login_name = "";
Integer open_amount = 0; // Opening amount
Integer is_message = 0;  // Messages exist on cash till line
Integer tot_impteo = 0;  // Total theoretical amount
Integer tot_declar = 0;  // Total declared amount
 
 
Cursor cajah = context.getContentResolver().query(
    Constants.TABLE_CAJAH_CLOSE,
    new String[] { "*" },
    null,
    null,
    null
);
 
while (cajah.moveToNext()) {
    timestamp = cajah.getLong(cajah.getColumnIndexOrThrow(Constants.COLUMN_CAJAH_DATE_C));
    terminal_id = cajah.getString(cajah.getColumnIndexOrThrow(Constants.COLUMN_CAJAH_TERMID));
    login_code = cajah.getString(cajah.getColumnIndexOrThrow(Constants.COLUMN_CAJAH_LOGIN));
    open_amount = cajah.getInt(cajah.getColumnIndexOrThrow(Constants.COLUMN_CAJAH_OPEN_AMOUNT));
}
 
cajah.close();
 
Cursor user = context.getContentResolver().query(
    Constants.TABLE_SYS_USERS_LOGIN_CODES,
    new String[] { "*" },
    "login_code = ?",
    new String[] {login_code},
    null
);
 
while (user.moveToNext()) {
    login_name = user.getString(user.getColumnIndexOrThrow(Constants.COLUMN_SYS_USERS_LOGIN_NAME));
}
 
user.close();
 
fecfin = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Timestamp(timestamp));
 
// ********************************************************************
// Adjust Text
// ********************************************************************
print_holder.getPCL().print(ESC_PRINT_CENTERED + ESC_BOLD_WORD);
 
// ********************************************************************
// Terminal number, closing date, and employee responsible for closing
// ********************************************************************
print_holder.println(" ");
print_holder.println("Terminal: " + terminal_id);
print_holder.println("Fecha de cierre: " + fecfin);
print_holder.println("Empleado: " + login_name);
 
// ********************************************************************
// Adjust Text
// ********************************************************************
print_holder.getPCL().print(ESC_RESET_PRINTER + ESC_PRINT_CENTERED);
 
print_holder.println(" ");
print_holder.println(m_cut);
print_holder.println(" ");
 
// ********************************************************************
// Sales total in euros with cash or card
// ********************************************************************
String m_divisa = DLGConfig.getString(Constants.COLUMN_DELEGATION_CURRENCY_MONEY);
 
Cursor cajal = context.getContentResolver().query(
    Constants.TABLE_CAJAL_CLOSE,
    new String[] { "*" },
    null,
    null,
    null
);
 
while (cajal.moveToNext()) {
    print_holder.println(cajal.getString(cajal.getColumnIndexOrThrow(Constants.COLUMN_CAJAL_TYPE_PAY)) + " " + cajal.getString(cajal.getColumnIndexOrThrow(Constants.COLUMN_CAJAL_AMOUNT)) + " " + m_divisa);
 
    if(cajal.getString(cajal.getColumnIndexOrThrow(Constants.COLUMN_CAJAL_STAT_MSG)) != null){
        is_message++;
    }
 
    // Aggregate the total declared amount and total theoretical amount
    tot_declar += cajal.getInt(cajal.getColumnIndexOrThrow(Constants.COLUMN_CAJAL_AMOUNT));
    tot_impteo += cajal.getInt(cajal.getColumnIndexOrThrow("impteo"));
 
}
 
cajal.close();
 
print_holder.println(" ");
print_holder.println(m_cut);
print_holder.println(" ");
 
if (is_message > 0) {
 
    Cursor cajal_err = context.getContentResolver().query(
        Constants.TABLE_CAJAL_CLOSE,
        new String[] { "*" },
        "status_message IS NOT NULL",
        null,
        null
    );
 
    while (cajal_err.moveToNext()) {
 
            print_holder.println(cajal_err.getString(cajal_err.getColumnIndexOrThrow(Constants.COLUMN_CAJAL_TYPE_PAY)) + ": " + cajal_err.getString(cajal_err.getColumnIndexOrThrow(Constants.COLUMN_CAJAL_STAT_MSG)));
    }
 
    cajal_err.close();
 
    print_holder.println(" ");
    print_holder.println(m_cut);
    print_holder.println(" ");
 
}
 
if ((tot_declar > 0) && (tot_impteo == 0)) {
 
    print_holder.println("BLIND AUDIT");
    print_holder.println("IMPOSSIBLE TO VERIFY");
 
    print_holder.println(" ");
    print_holder.println(m_cut);
    print_holder.println(" ");
 
}
 
// ********************************************************************
// Adjust Text
// ********************************************************************
print_holder.getPCL().print(ESC_RESET_PRINTER + ESC_PRINT_CENTERED + ESC_BOLD_WORD);
 
// ********************************************************************
// Opening and Closing Cash Balance
// ********************************************************************
print_holder.println("Cash balance: " + open_amount);
print_holder.println(" ");
print_holder.println(" ");
print_holder.println(" ");
print_holder.println(" ");
print_holder.println(" ");
 
// ********************************************************************
// CUT PAPER AND PREPARE PRINTER
// ********************************************************************
print_holder.getPCL().print(ESC_RESET_PRINTER + ESC_BREAK_PAPPER + ESC_RESET_PRINTER);
 
print_holder.closeIfNeed();
 
// ********************************************************************
// Return and Reload Buffer
// ********************************************************************
return buffers;