// script.SendOrder.txt
// Sends an item in a Sale to a remote (Kitchen) Printer
/*
**    Chromis POS  - The New Dynamic Open Source POS
**    Copyright  (c) 2015-2019 Chromis and previous contributing parties (Unicenta & Openbravo)
**    http://www.chromis.co.uk
**
**    This file is part of Chromis POS 
**
**    Chromis POS is free software: you can redistribute it and/or modify
**    it under the terms of the GNU General Public License as published by
**    the Free Software Foundation, either version 3 of the License, or
**    (at your option) any later version.
**
**    Chromis POS is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**    GNU General Public License for more details.
**
**    You should have received a copy of the GNU General Public License
**    along with Chromis POS.  If not, see <http://www.gnu.org/licenses/>
**
**
 */
// **************************************************************************

boolean kitchen = false;
boolean display = false;

if ( ! ticket.getTicketType().toString().equals("REFUND") ) { 
for(int i= 0; i < ticket.getLinesCount(); i++){
	line = ticket.getLine(i);

	if (line.isProductKitchen()  && (line.getProperty("sendstatus") == null)){
		line.setProperty("sendstatus", "No");
	}
	if(line.isProductKitchen() && (line.getProperty("sendstatus").equals("No"))){
		kitchen = true;
	}	
	if (line.isProductDisplay()  && (line.getProperty("sendstatus") == null)){
		line.setProperty("sendstatus", "No");
	}	
	if(line.isProductDisplay() && (line.getProperty("sendstatus").equals("No"))){
		display = true;
	}
}
if (kitchen) {
	sales.printTicket("Printer.TicketKitchen");	
}

if (display) {
	sales.kitchenOrderScreen();	
}

if (kitchen || display){
	javax.swing.JOptionPane.showMessageDialog(null, "Order sent to Remote device");
} else {
	javax.swing.JOptionPane.showMessageDialog(null, "Nothing to Send", "Warning", JOptionPane.WARNING_MESSAGE);
}

for(int i = ticket.getLinesCount()-1; i>= 0 ; i--){
	line = ticket.getLine(i);
	String a = line.getProperty("sendstatus");
	
	if((line.isProductKitchen() || line.isProductDisplay()) && (line.getProperty("sendstatus").equals("No"))){
		line.setProperty("sendstatus", "OK");
	}
}

	sales.doRefresh();

}

  
