<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="kotnum">KOT2</entry>
<entry key="sendstatus">No</entry>
</properties>

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="kotnum">KOT3</entry>
<entry key="sendstatus">No</entry>
</properties>

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<label format="2" size="2"></label>
</properties>

INSERT INTO ROLES(ID, NAME, PERMISSIONS) VALUES('0', 'Administrator role', $FILE{/com/posics/pos/templates/Role.Administrator.xml} );

<!-- TICKET COUPON START -->
        #if ($ticket.getTotal() > 3000)
         <line>
         </line>
         <line>
           <text>------------------------------------------------</text>
         </line>
	<line>
	<image>Printer.Ticket.SpecialOffer.Logo</image>
        </line>
	<line>
           <text align ="center" length="48" bold="true" underline="true">DISCOUNT COUPON</text>
        </line>
           #set($y = $ticket.getDate().getYear() + 1900)
           #set($m = $ticket.getDate().getMonth() + 1)
           #set($d = $ticket.getDate().getDate())

           #set($d = $d + 14)
           #if ((($m ==4) || ($m ==6) || ($m ==9) || ($m ==11)) && ($d > 30))
               #set($m = $m + 1)
               #set($d = $d - 30)
           #elseif (($m ==2) && ($d > 28))
               #set($m = $m + 1)
               #set($d = $d - 28)
           #elseif ($d > 31)
               #set($m = $m + 1)
               #set($d = $d - 31)
           #end

           #if($m > 12)
               #set($m = 1)
               #set($y = $y + 1)
           #end
         <line>
           <text align ="center" length="48" bold="true">Expires:$d/$m/$y</text>
         </line>
         <line>
           <text align ="center" length="48">This coupon entitles you to receive </text>
         </line>
	<line>
         </line>
	<line size="3">
           <text align ="center" length="12" >5%</text>
         </line>
        <line size="3">
           <text align ="center" length="12" >DISCOUNT</text>
         </line>
         <line>
         <text align ="center" length="48">when you purchase next time from us.</text>
         </line>
         #if (${ticket.ticketType} == 0)
         <line>
           <text align="center" length="48">Receipt:${ticket.printId()}</text>
         </line>
         #end
         <line>
           <text>------------------------------------------------</text>
         </line>
        #end
<!-- TICKET COUPON END -->


<!-- SEQUENCE NUMBERS - >
#set($seq = 1)
#set($seq = $seq + 1)

<!-- DISCOUNT UNDER SUBTOTAL - >
#set($discamt = 0)

#if(${ticketline.printName()} != "Discount")

#else
#set($discamt = $discamt + ${ticketline.getSubValue()})
#end

#if(${discamt} != 0)
#set($subt = ${ticket.getSubTotal()}-${discamt})

<text align ="right" length="20">${subt}</text>
<text align ="right" length="20">${discamt}</text>

#end

//change refund for remove from discount

String[] cmd={ \"sh\", \"-c\", \"cat /dev/kot2 | nc.openbsd 192.168.1.245 9100\"};
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(cmd);

//DISCOUNT ON TOTAL
// % Discount for the total of the receipt

import com.posics.format.Formats;
import com.posics.pos.ticket.TicketLineInfo;
import com.posics.pos.ticket.TicketProductInfo;
import java.util.Properties;

discountperc = JOptionPane.showInputDialog(null, "Input percentage.....");
double discountrate = Double.parseDouble(discountperc);
discountrate = discountrate/100.00;

total = ticket.getTotal();
if (total > 0.0) {
    sdiscount = Formats.PERCENT.formatValue(discountrate);

    taxes = ticket.getTaxLines();
    for (int i = 0; i < taxes.length; i++) {
        taxline = taxes[i];
        ticket.insertLine(ticket.getLinesCount(),
            new TicketLineInfo(
                "Discount " + sdiscount + " of " + taxline.printSubTotal(),
                taxline.getTaxInfo().getTaxCategoryID(),
                1.0,
                -taxline.getSubTotal() * discountrate,
                taxline.getTaxInfo()));
    }
    sales.setSelectedIndex(ticket.getLinesCount() - 1);
} else {
    java.awt.Toolkit.getDefaultToolkit().beep();
}

//
//Rounding
//

import com.posics.format.Formats;
import com.posics.pos.ticket.TicketLineInfo;
import com.posicso.pos.ticket.TicketProductInfo;
import java.util.Properties;

total = ticket.getTotal();

if (total > 0.0) {
  //rounding m to nearest multiple of n
  m=total;
  n=5.0; //round to the nearest 5cents
  d = Math.floor((m*100.0+n/2.0)/n)*n/100.0-m;
  //round to 2 decimal places
  rounding = Math.round(d * Math.pow(10, (double) 2)) / Math.pow(10,(double) 2);
  //add line if rounding is needed
  if (rounding <= -0.01 || rounding >= 0.01) {
    taxes = ticket.getTaxLines();
    for (int i = 0; i < taxes.length; i++) {
      taxline = taxes[i];
      // if you only want to round down, remove slashes from the next two lines
      //     if (rounding>0) {
      //       rounding = rounding - .05; }
      ticket.insertLine(ticket.getLinesCount(),
        new TicketLineInfo(
        "Rounding adjustment",
        taxline.getTaxInfo().getTaxCategoryID(),
        1.0,
        rounding,
        taxline.getTaxInfo()));
    }
  }
  sales.setSelectedIndex(ticket.getLinesCount() - 1);
 } else {
  java.awt.Toolkit.getDefaultToolkit().beep();
}

////////
ITEMWISE SALES REPORT

<!-- SALE REPORT START -->
        <line>
            <text bold="true">Sales Report</text>
        </line>
        <line>
            <text align ="left" length="18">Name</text>
            <text align ="right" length="6">Units</text>
            <text align ="right" length="12">Cost</text>
            <text align ="right" length="12">Total</text>
        </line>
        <line>
            <text>------------------------------------------------</text>
        </line>

#set($cat = "")
#set($prod = "")
        #foreach ($line in $payments.getProductSalesLines())
	#if ( $cat != ${line.printCategoryName()} )
	#set( $cat = ${line.printCategoryName()} )
	<line></line>
            <line>
            <text align ="left" length="48">${line.printCategoryName()}</text>
            </line>
	#end
        <line>
        	<text align ="left" length="18">${line.printProductName()}</text>
	        <text align ="right" length="6">${line.printProductUnits()}</text>
		<text align ="right" length="12">${line.printCost()}</text>
	        <text align ="right" length="12">${line.printProductPriceTax()}</text>
        </line>
        #end
        <line>
            <text>------------------------------------------------</text>
        </line>
        <line size="1">
            <text align ="left" length="18" bold="true">Total</text>
            <text align ="right" length="6" bold="true">${payments.printProductSalesTotalUnits()}</text>
            <text align ="right" length="12" bold="true">${payments.printProductSalesCost()}</text>
            <text align ="right" length="12" bold="true">${payments.printProductSalesTotal()}</text>
        </line>
<line size="1">
            <text align ="left" length="24" bold="true">Difference</text>
            <text align ="right" length="12" bold="true">${payments.printProductSalesDifference()}</text>
            <text align ="right" length="12" bold="true">${payments.printProductSalesDifferencePct()}%</text>
        </line>


<!-- SALE REPORT END -->


         <!-- CATEGORY SALE REPORT START -->
        <line>
            <text bold="true">Sales Report</text>
        </line>
        <line>
            <text align ="left" length="23">Name</text>
            <text align ="left" length="10">Units</text>
            <text align ="right" length="15">Total</text>
        </line>
        <line>
            <text>------------------------------------------------</text>
        </line>

#set($cat = "")
#set($catTotal = 0)
#set($catUnits = 0)
#set($catNetTotal = 0)
#set($catNetUnits = 0)
#set($flag = 0)
        #foreach ($line in $payments.getProductSalesLines())


        #set($catTotal = $catTotal + ${line.getProductPrice()})
        #set($catUnits = $catUnits + ${line.getProductUnits()})
#if ( $cat != ${line.printCategoryName()} && $flag == 1 )
        <line>
            <text align ="left" length="23">${cat}</text>
            <text align ="left" length="10">${catUnits}</text>
            <text align ="right" length="15">${catTotal}</text>
        </line>
#set($catNetTotal = $catTotal + $catNetTotal)
#set($catNetUnits = $catUnits + $catNetUnits)
#set($catTotal = 0)
#set($catUnits = 0)
#end
#set($flag = 1)
#set($cat = ${line.printCategoryName()} )
#end
        <line>
            <text align ="left" length="23">${cat}</text>
            <text align ="left" length="10">${catUnits}</text>
            <text align ="right" length="15">${catTotal}</text>
        </line>
#set($catNetTotal = $catTotal + $catNetTotal)
#set($catNetUnits = $catUnits + $catNetUnits)
        <line>
            <text>------------------------------------------------</text>
        </line>
        <line size="1">
            <text align ="left" length="23" bold="true">Total</text>
            <text align ="left" length="10" bold="true">${catNetUnits}</text>
            <text align ="right" length="15" bold="true">${catNetTotal}</text>
        </line>
<!-- CATEGORY SALE REPORT END -->


// DISCOUNT/TARIFF ON CUSTOMER CATEGORY
//event.customerchanged

import com.posics.format.Formats;
import com.posics.pos.ticket.TicketLineInfo;
import com.posics.pos.ticket.TicketProductInfo;

customer = ticket.getCustomer();
if (customer != null && customer.getTaxCustCategoryID() != null) {
	tcc = customer.getTaxCustCategoryID();
	if (tcc.equals("485c8198-ad17-4f36-8b63-af97cc4a2319")) {
		  discountrate = 0.05;

		int numlines = ticket.getLinesCount();
		//start for loop
		for (int i = 0 ; i<numlines ; i++) {
			l = ticket.getLine(i);
			l.setSalePrice(l.getPrice() - l.getPrice() * discountrate);
		}

	}else {

		sales.setTariff("Credit", 0);

	}
}


// SET A DEFAULT TARIFF
//event.show

sales.setTariff("TariffAreaName");

//ROUND OFF

total = ticket.getTotal();
if (total > 0.0) {
  m= Math.round(total);
roundoff = total - m;
roundoff = roundoff * -1;
roundoff = Math.floor(roundoff * 100 + 0.5) / 100;

if(roundoff!=0){
taxes = ticket.getTaxLines();
    for (int i = 0; i < taxes.length; i++) {
      taxline = taxes[i];
      ticket.insertLine(ticket.getLinesCount(),
        new TicketLineInfo(
        "RoundOff",
        taxline.getTaxInfo().getTaxCategoryID(),
        1.0,
        roundoff,
        taxline.getTaxInfo()));
    }
ticket.setProperty("RoundOff", Double.toString(roundoff));
}
}


<!-- SALES TICKETS START -->
        <line></line>
	<line>
            <text bold="true">Receipts</text>
        </line>
        <line>
            <text align ="left" length="10">Receipt</text>
            <text align ="left" length="20">Date</text>
            <text align ="right" length="8">Quantity</text>
            <text align ="right" length="10">Amount</text>
        </line>
        <line>
            <text>------------------------------------------------</text>
        </line>
        #foreach ($line in $payments.getSalesTickets())
        <line>
        	<text align ="left" length="10">${line.printTicketId()}</text>
	        <text align ="left" length="20">${line.printTicketDate()}</text>
                <text align ="right" length="8">${line.printQuantity()}</text>
	        <text align ="right" length="10">${line.printAmount()}</text>
        </line>
        #end
        <line>
            <text>------------------------------------------------</text>
        </line>
<!-- SALES TICKETS END -->

<!-- ITEM NOTE -->
<!-- Script.ReceiptNote -->
value = javax.swing.JOptionPane.showInputDialog("Receipt Note", ticket.getProperty("ReceiptNote"));
if (value != null) {
index=sales.getSelectedIndex();
line=ticket.getLine(index);
line.setProductAttSetInstDesc(value);
}

<!-- Printer.KOT1 and Printer.KOT1_Change -->
#if ($ticketline.getProductAttSetInstDesc())
<line>
<text align ="left" length="48">    ${ticketline.getProductAttSetInstDesc()}</text>
</line>
#end




//USER INTPUT DIALOG WITH TOUCH SCREEN KEYBOARD
if(line.getPrice()==0)
{
com.posics.pos.mant.JInputDialog jid = new com.posics.pos.mant.JInputDialog();
jid.setLabel("Price");
Object[] options = { "OK", "Cancel" };  
int result = javax.swing.JOptionPane.showOptionDialog(null, jid, "Please Enter Name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null);
if (result == JOptionPane.OK_OPTION) {
    Double newPrice = new Double(jid.getValue());
    line.setSalePrice(newPrice);
    }
}

//SEND KEY
String [] keys = {"VK_F5"};
//String [] keys = {"VK_ALT","VK_E"};
ticket.sendKey(keys);

//Send Hex Code from print template to Printer
<hex value="1B2121" length="1"/>

//Replate string from print template
#if ($ticketline.productAttSetInstId)
#set($key = ${ticketline.productAttSetInstDesc})  
#set($key = $key.replaceAll("<br/>", "</text></line><line><text>"))  
<line>
<text align="left">$key</text>
</line>
#end
#end
