//    Posics Saleculator - Billing System.
//    Copyright (C) 2009 Posics
//
//    This file is part of Posics Saleculator.
//


//sales.savePrice(line.getSalePrice(), line.getProductID());

//Stop the line modification of sent products

if (!line.getProperty("sendstatus").equals("No") && !line.getProperty("sendstatus").equals("N/A")){
 oldline = ticket.getLine(index);
 if ((oldline.getProperty("sendstatus").equals("Yes") || oldline.getProperty("sendstatus").equals("Modify"))
     && !oldline.isProductCom()
     && !line.isProductCom()
     && oldline.getProperty("kotnum").equals(line.getProperty("kotnum"))
     && oldline.getProductName().equals(line.getProductName())
     && oldline.getSalePrice() == line.getSalePrice()
     && ((oldline.getProductID() == null && line.getProductID() == null)
         || (oldline.getProductID() != null && oldline.getProductID().equals(line.getProductID())))) {

  if (oldline.getProperty("kotmodifyqty") == null) {
   originalQty = oldline.getMultiply();
  }else{
   originalQty = Double.parseDouble(oldline.getProperty("kotmodifyqty"));
  }

  if (originalQty != line.getMultiply()) {
   line.setProperty("sendstatus", "Modify");
   line.setProperty("kotmodifyqty", String.valueOf(originalQty));
   line.setProperty("kotnum", oldline.getProperty("kotnum"));
  }else{
   line.setProperty("sendstatus", "Yes");
   line.getProperties().remove("kotmodifyqty");
   line.getProperties().remove("kotadjustlabel");
   line.getProperties().remove("kotadjustqty");
  }

  return null;
 }else{
  JOptionPane.showMessageDialog(null, "You can only change quantity for an already sent item.", "Error", JOptionPane.ERROR_MESSAGE);
  return "cancel";
 }

 JOptionPane.showMessageDialog(null, "You cannot modify a sent item.", "Error", JOptionPane.ERROR_MESSAGE);
 return "cancel";
}
