how to set image size for button suitable size

in my work. i’ve use vaadin to build my own project but in this case i not have solution to fix some problem.

for the button my customer want to have button preview product image and can be click to enlarge size of product

and when i code it that not to easy . the image has size over the button size and overflow. i want someone to help.

this is my code

package com.example.dms.PurchaseOrder;

import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Properties;

import javax.servlet.http.HttpSession;
import javax.swing.ImageIcon;

import com.example.dms.AppFrame;
import com.example.dms.DmsApplication;
import com.example.dms.DmsInsertDuplicate;
import com.example.dms.DmsValidate;
import com.example.dms.Abstract.AbstractEditProfile;
import com.example.dms.Abstract.AbstractForm;
import com.example.dms.ConnectDB.DB;
import com.example.dms.Report.reportInvoiceDetail;
import com.example.dms.Util.BrowserSize;
import com.example.dms.Util.DateUtil;
import com.example.dms.Util.RootPath;
import com.google.gwt.cell.client.TextInputCell.ViewData;
import com.google.gwt.user.client.ui.FocusListener;
import com.google.gwt.user.client.ui.SourcesClickEvents;
import com.google.gwt.user.client.ui.Widget;
import com.sun.mail.handlers.image_gif;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.Container.PropertySetChangeEvent;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.Paintable.RepaintRequestListener;
import com.vaadin.terminal.FileResource;
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.UserError;
import com.vaadin.terminal.Paintable.RepaintRequestEvent;
import com.vaadin.terminal.gwt.client.ui.VEmbedded;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component.Event;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.Window.CloseEvent;
import com.vaadin.ui.Window.Notification;
import com.vaadin.ui.themes.BaseTheme;
import com.vaadin.ui.themes.Reindeer;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.Component.Listener;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.NativeButton;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.PopupDateField;
import com.vaadin.ui.PopupView;
import com.vaadin.ui.Select;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.VerticalSplitPanel;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.CloseListener;

import javax.imageio.ImageIO;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Authenticator;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.*;

public class PurchaseOrderForm extends AbstractForm {
private Window sublock = null;
private TextField txtUsr = null;
private PasswordField txtPwd = null;
private static final ThemeResource view = new ThemeResource(“…/Reindeer/Icons/32/Preview.png”);
private Button btn_view;
private final static String iconSelect = “…/Reindeer/Icons/16/OK.png”;
private DmsValidate tmsV =null;
private String fieldTbl = null;
private String whereCon = null;
private String nameTbl = null;
int numCount = 0;
public int DealerID = 0;
public int sale_id = 0;
private String mode;

private Select selCat;
private Select selPro;
private Select selPat;
private CheckBox cheAuto;
private TextField txtPO;
private TextField txtExp;
private TextField txtRemarkPO;
private TextField txtRemarkItem;
private TextField txtQuan;

// private TextField txtStatus;
private Select selStatus;
private String iconNew = “…/Reindeer/Icons/16/Input.png”;
private String iconsubmit = “…/Reindeer/Icons/16/Input.png”;
private String icondel = “…/Reindeer/Icons/16/Input.png”;

private Window subwinCat = new Window();
private Table tblPro = null;
private Table tblPatt = null;

public Button btnNew = null;
public Button btnSubmit = null;
public Button btnDelPO = null;
public Button btnAdd = null;
public Button btnDel = null;
public Button btnUpdate = null;

// public Link userLink = null;

private DmsInsertDuplicate tmsInsert = new DmsInsertDuplicate();
private Table tblDataTable;
private Table tblData;
private String usrName = "";
private String Dealer = "";
private String EmailPur = "";
private HorizontalLayout hLayL;
private HorizontalLayout hLayR;
private HorizontalLayout hLayA;
private HorizontalLayout hLayD;
private VerticalLayout mainLay = null; 
private HorizontalSplitPanel panel = null;
private VerticalSplitPanel Data = null;
private String eventMode;

private PurchaseOrderClass PurCls;
private PurchaseOrderAction PurAct;

private String usrLog = DmsApplication.getInstance().getUser();
private int usrgroup = DmsApplication.getInstance().getUsergroup();
private Button LinkProfile;
private Label LabelDealer;

Window subwindow;	
Label message;
Button yes;
Button no;
Button temp;
ArrayList<Object> arrID = new ArrayList<Object>();
ArrayList<Object> arrID2 = new ArrayList<Object>();
ArrayList<Object> arrValue = new ArrayList<Object>();
ArrayList<Object> arrValue2 = new ArrayList<Object>();
String usr = "";
String PO_NUMBER="";
ArrayList<String> email;
private Window subwinZoom;

private String[] b;
private BigDecimal getprice;
private BigDecimal chkprice;
private BigDecimal credit; 
private TextField creditTxt; 
private TextField getpriceTxt;  
private TextField chkpriceTxt;  

private int	chkApprove = 0;
private int	chkPartial = 0;

private String emailAddress = "";
public PurchaseOrderForm(){

	creditTxt = new TextField();
	creditTxt.setValue(" 0 "+this.getMenuLabel2("bD"));
	creditTxt.setReadOnly(true);
	getpriceTxt = new TextField();
	getpriceTxt.setValue(" 0 "+this.getMenuLabel2("bD"));
	getpriceTxt.setReadOnly(true);
	chkpriceTxt = new TextField();
	chkpriceTxt.setValue(" 0 "+this.getMenuLabel2("bD"));
	chkpriceTxt.setReadOnly(true);
	
	usr = DmsApplication.getInstance().getUser();
	this.tblDataTable = new Table();
	tmsV = new DmsValidate();
	
	btn_view = new Button("",this,"view");
	btn_view.setIcon(view);
	btn_view.setStyleName(BaseTheme.BUTTON_LINK);
	btn_view.setDescription("");
	btn_view.setEnabled(false);
	
	PurCls = new PurchaseOrderClass();
	PurAct = new PurchaseOrderAction();
	
	PurAct.setObjClass(PurCls);
	PurCls.setCreate_user(usrLog);
	PurCls.setUpdate_user(usrLog);

// System.out.println(“PurCls.getOrder_id()”+PurCls.getOrder_id());
tblPro = new Table();
tblPatt = new Table();

	tblPro.setWidth("750px");
	tblPatt.setWidth("750px");
	
	BrowserSize bs = new BrowserSize();
	double width = bs.getBrowserWidth();
	double height = bs.getBrowserHeight();
	
	mainLay = new VerticalLayout(); 
	mainLay.setWidth("100%");
	mainLay.setMargin(false);
	mainLay.setSpacing(false);
	
	panel = new HorizontalSplitPanel();
	panel.setHeight((height*0.50) + "px");
    panel.setWidth((width) + "px");

// panel.setWidth(“100%”);
panel.setMargin(false);

    Data = new VerticalSplitPanel();
    Data.setSplitPosition(44);
    Data.setLocked(true);


	btnNew = new Button("New",this,"btnNew");
	btnSubmit = new Button("Submit",this,"btnAct");	
	btnAdd = new Button("Add",this,"btnAdd");
	btnDel = new Button("Delete",this,"btnDel");
	btnDelPO = new Button("Delete PO",this,"btnDelPO");
	btnUpdate = new Button("Update",this,"btnUpdate");
	
	btnNew.setWidth("120px");
	btnDelPO.setWidth("120px");
	btnDel.setWidth("75px");
	btnAdd.setWidth("75px");
	btnSubmit.setWidth("120px");
	btnUpdate.setWidth("75px");

	btnNew.setIcon(new ThemeResource(iconNew));	
	btnSubmit.setIcon(new ThemeResource(iconsubmit));
	btnDelPO.setIcon(new ThemeResource(icondel));

	
	Component usr = this.getUserName();
	Component dealer = this.getDealer();
	
	tblData = new Table("");
	
	mode = "insert";
	
	

	
	 hLayL = new HorizontalLayout();
	 hLayL.setMargin(false);
	 hLayL.setSpacing(true);
	 hLayL.addComponent(btnNew);
	 hLayL.addComponent(btnSubmit);
	 hLayL.addComponent(btnDelPO);
	 hLayL.addComponent(btn_view);
	 
	 hLayR = new HorizontalLayout();
	 hLayR.setMargin(false);
	 hLayR.setSpacing(true);
	 hLayR.addComponent(creditTxt);
	 hLayR.addComponent(getpriceTxt);
	 hLayR.addComponent(chkpriceTxt);
	 hLayR.addComponent(usr);
	 hLayR.addComponent(dealer);

			
	HorizontalLayout hLay = new HorizontalLayout();
	hLay.setMargin(true);
	hLay.setSpacing(true);
	hLay.setWidth("100%");
	hLay.addComponent(hLayL);
	hLay.addComponent(btnSubmit);
	hLay.addComponent(btnDelPO);
	hLay.addComponent(hLayR);
	hLay.setComponentAlignment(hLayL, Alignment.MIDDLE_LEFT);
	hLay.setComponentAlignment(hLayR, Alignment.MIDDLE_RIGHT);
	hLay.addComponent(btnDel);

// hLay.addComponent(userLink);

	mainLay.addComponent(hLay);
	mainLay.addComponent(panel);
	mainLay.setComponentAlignment(hLay,Alignment.MIDDLE_LEFT);
	
	//this.tblDataTable.removeAllItems();

	
	selCat = new Select("");
	selCat.setWidth("140px");
	selCat.setNullSelectionAllowed(false);
	selCat.addListener(new Property.ValueChangeListener() {
		public void valueChange(ValueChangeEvent event) {
			// TODO Auto-generated method stub
			
			if(event.getProperty().getValue()!=null){
				getProANDPatt(event.getProperty().getValue().toString());
			}
			
			
			DB db = new DB();
			db.dbConnect();	
			selPro.removeAllItems();
			try {
				String sql = "SELECT * FROM products WHERE category_id = '" +event.getProperty().getValue()+"' AND products.status = '1' order by CONVERT (description USING tis620)";

				ResultSet rs =  db.getResult(sql);
				
				while(rs.next()){
								selPro.addItem(rs.getInt("product_id"));
								selPro.setItemCaption(rs.getInt("product_id"),rs.getString("description").trim());
				}
				selPro.setImmediate(true);
				selPro.setEnabled(true);
				selPro.select(0);
				rs.close();
				db.dbClose();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	});
	
	
	selPro = new Select("");
	selPro.setWidth("140px");
	selPro.setNullSelectionAllowed(false);
	selPro.addListener(new Property.ValueChangeListener() {
		
		String Procode = "";
		
		public void valueChange(ValueChangeEvent event) {
			// TODO Auto-generated method stub
			
			getProCode();
			
			DB db = new DB();
			db.dbConnect();	
			selPat.removeAllItems();
			try {
				String sql = "SELECT\n" +
						"patterns.description,\n" +
						"patterns.pattern_id\n" +
						"FROM\n" +
						"patterns\n" +
						"WHERE\n" +
						"patterns.model_code = '"+ Procode +"' AND patterns.status = '1'\n" +
						"order by CONVERT (description USING tis620)";

// System.out.println("produce select : "+sql);
ResultSet rs = db.getResult(sql);

				while(rs.next()){
							selPat.addItem(rs.getInt("pattern_id"));
							selPat.setItemCaption(rs.getInt("pattern_id"),rs.getString("description").trim());
					}
				selPat.setImmediate(true);
				selPat.setEnabled(true);
				selPat.select(0);
				
				rs.close();
				db.dbClose();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		private void getPhotoView(){
			DB db = new DB();
			db.dbConnect();	
			String PhotoViewPath = "";
			try {
				String sql = "SELECT\n" +
						"IF(photos.photo_path<>'' OR photos.photo_path<>NULL,photos.photo_path,'') AS photo_path\n" +
						"FROM\n" +
						"products\n" +
						"LEFT JOIN photos ON photos.photo_id = products.photo_id\n" +
						"WHERE products.product_id = '"+ selPro.getValue().toString() +"'";

// System.out.println("getPhotoView : "+sql);
ResultSet rs = db.getResult(sql);

				if(rs.next()){
					PhotoViewPath = rs.getString("photo_path");	
				}
			
				
				rs.close();
				db.dbClose();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
			
			
		}

		private void getProCode() {
			// TODO Auto-generated method stub
	
			DB db = new DB();
			db.dbConnect();	
			selPat.removeAllItems();
			try {
				String sql = "SELECT\n" +
						"products.model_code\n" +
						"FROM\n" +
						"products where description = '"+ selPro.getItemCaption(selPro.getValue()) +"'";

// System.out.println("getprocode : "+sql);
ResultSet rs = db.getResult(sql);

				while(rs.next()){
					Procode = rs.getString("model_code");	
					}
			
				
				rs.close();
				db.dbClose();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
	});
	
	selPat = new Select("");
	selPat.setWidth("140px");		
	selCat.setRequired(true);
	selPat.setRequired(true);
	selPro.setRequired(true);
	selPat.setNullSelectionAllowed(false);
	
	cheAuto = new CheckBox("");
	
	txtPO = new TextField("");
	txtPO.setReadOnly(true);
	
	txtQuan = new TextField("");
	txtQuan.addListener(new TextChangeListener() {

		public void textChange(TextChangeEvent event) {
			// TODO Auto-generated method stub
			DecimalFormat df = new DecimalFormat("#,###,###,##0");
			try{
				int count12 = 0;
				String[] a ={};
				String Output ="";
				while(count12 < event.getText().toString().length()){

// System.out.println(event.getText().toString());
a = event.getText().toString().split(“,”);
count12++;
}
for(int i =0;i<a.length;i++){
Output = Output + a[i]
;
}
if(!event.getText().equals(“”)){
if(!tmsV.checkBig(Output)){
txtQuan.setComponentError(new UserError(“Please enter numeric only.”));
tmsV.setNotic(“Warning !!
Please enter numeric only.”, Notification.TYPE_WARNING_MESSAGE);
tmsV.getNotic();
}else{
txtQuan.setComponentError(null);
if(Integer.parseInt(Output)<=0||Integer.parseInt(Output)>9999999){
txtQuan.setComponentError(new UserError(“Please enter number between 1-9,999,999.”));
tmsV.setNotic(“Warning !!
Please enter number between 1-9,999,999.”, Notification.TYPE_WARNING_MESSAGE);
tmsV.getNotic();
}else{
txtQuan.setComponentError(null);
txtQuan.setValue(df.format(Integer.parseInt(Output.toString())));
}
}

				}else{
					txtQuan.setComponentError(null);
				}
			}catch (NumberFormatException e) {
			// TODO: handle exception

			
		}

		}
	});
	txtQuan.setRequired(true);

// txtStatus = new TextField(“”);
// txtStatus.setReadOnly(true);
// txtStatus.setWidth(“80”);
selStatus = new Select();
selStatus.setWidth(“80px”);
selStatus.setNullSelectionAllowed(false);
selStatus.setEnabled(false);
selStatus.addListener(new Property.ValueChangeListener() {

		public void valueChange(ValueChangeEvent event) {
			if(event.getProperty().toString()==null){
				//Do not do anything.
			}else{
				// TODO Auto-generated method stub
				DB conn = new DB();
				conn.dbConnect();
				String sql = "UPDATE orders SET " +
						"current_status = '"+event.getProperty().toString()+"'" +
						",updated_user = '" + PurCls.getUpdate_user()+ "'" +
						",updated_datetime = NOW() " +
						" WHERE order_id = '" + PurCls.getPO_id()+ "'" ;
				conn.executeSQL(sql);

// System.out.println(">>>>> " +sql);
try {
conn.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}
}

		}
	});
	txtExp = new TextField();
	txtExp.setReadOnly(true);
	txtRemarkPO = new TextField();
	txtRemarkPO.setWidth("150px");
	txtRemarkItem = new TextField();
	txtRemarkItem.setWidth("150px");

	
	
}

public Component getUserName(){
	
	
	DB db = new DB();
	db.dbConnect();		
	
	try {
		String sql = "SELECT\n" +
				"users.user_id,\n" +
				"users.login_name,\n" +
				"users.user_group_id,\n" +
				"users.dealer_id,\n" +
				"users.`password`,\n" +
				"users.first_name,\n" +
				"users.last_name,\n" +
				"users.employee_id,\n" +
				"users.date_of_birth,\n" +
				"users.email_address,\n" +
				"users.contact_no,\n" +
				"users.expire_date,\n" +
				"users.`status`,\n" +
				"users.created_user,\n" +
				"users.created_datetime,\n" +
				"users.updated_user,\n" +
				"users.updated_datetime,\n" +
				"IF(dealers.dealer_name<>'' OR dealers.dealer_name<>null,dealers.dealer_name,'') AS dealer_name,\n" +
				"photos.photo_path\n" +
				"FROM\n" +
				"users\n" +
				"LEFT JOIN dealers ON dealers.dealer_id = users.dealer_id\n" +
				"LEFT JOIN photos ON photos.photo_id = users.photo_id\n" +
				"WHERE user_id = '"+usr+"'";

// System.out.println(sql);
ResultSet rs = db.getResult(sql);

		if(rs.next()){
			usrName = rs.getString("first_name")+"  "+rs.getString("last_name");

// POfrm = (PurchaseOrderForm)POfrm.POfrm();
DealerID = rs.getInt(“dealer_id”);

		}
		rs.close();
		db.dbClose();
	} catch (SQLException e) {
		e.printStackTrace();
	}
	
	LinkProfile = new Button(usrName,this,"Profile");
	LinkProfile.setStyleName(BaseTheme.BUTTON_LINK);

	return LinkProfile;
}

public Component getDealer(){
	
	
	DB db = new DB();
	db.dbConnect();		
	
	try {
		String sql = "SELECT\n" +
				"IF(users.email_address<>'' OR users.email_address<>null,users.email_address,'') AS email_address,\n"+
				"IF(dealers.dealer_name<>'' OR dealers.dealer_name<>null,dealers.dealer_name,'') AS dealer_name\n" +
				"FROM\n" +
				"users\n" +
				"LEFT JOIN dealers ON dealers.dealer_id = users.dealer_id\n" +
				"WHERE user_id = '"+usr+"'";

// System.out.println(sql);
ResultSet rs = db.getResult(sql);

		if(rs.next()){
			if(rs.getString("dealer_name").equals("")){
				Dealer = "";
				EmailPur = "";
			}else{
			Dealer = "@ "+rs.getString("dealer_name");
			EmailPur = rs.getString("email_address");
			}
			
		}
		if(usr.equals("1") || usr.equals("2") || usr.equals("3") || usr.equals("9") || usr.equals("10")){
			Dealer = "";
		}
		rs.close();
		db.dbClose();
	} catch (SQLException e) {
		e.printStackTrace();
	}
	
	LabelDealer = new Label(Dealer);

	return LabelDealer;
}

public void Profile(){
	AbstractEditProfile Profile = new AbstractEditProfile(usr);
   	DmsApplication.getInstance().getMainWindow().addWindow(Profile.getsub());
}
/////////////////////////////////////////////////////////////////////////////////////////////view
public void view(Button.ClickEvent event){
	if(PurCls.getOrder_id()==0){
		this.getAlert("alert_error_input");
	}else{
		if (usrgroup == 3){
			reportPurchaseCom PurchaseCom = new reportPurchaseCom(PurCls.getOrder_id());
			 DmsApplication.getInstance().getMainWindow().addWindow(PurchaseCom.getsub());
		}else{
			reportPurchaseShop PurchaseShop = new reportPurchaseShop(PurCls.getOrder_id());
			 DmsApplication.getInstance().getMainWindow().addWindow(PurchaseShop.getsub());
		} 
	}
	
}
@Override
public void addComp() {
	arrValue.clear();
	arrID.clear();
	btnAdd.setEnabled(false);
	btn_view.setEnabled(false);
	chkGroup();
	
	
	GridLayout Grid = new GridLayout(7,3);
	Grid.setMargin(false);
	Grid.setSpacing(false);
	Grid.setWidth(1000, Sizeable.UNITS_PIXELS);
	Grid.setHeight(120, Sizeable.UNITS_PIXELS);
	Grid.setColumnExpandRatio(0, 12);
	Grid.setColumnExpandRatio(1, 12);
	Grid.setColumnExpandRatio(2, 0.1f);
	Grid.setColumnExpandRatio(3, 10);
	Grid.setColumnExpandRatio(4, 3);
	Grid.setColumnExpandRatio(5, 0.1f);
	Grid.setColumnExpandRatio(6, 8);
	
	 hLayA = new HorizontalLayout();
	 hLayA.setMargin(false);
	 hLayA.setSpacing(true);
	 hLayA.addComponent(btnAdd);
	 hLayA.addComponent(btnDel);
	
	FormLayout layOut = new FormLayout();
	layOut.setMargin(true);
	layOut.setSpacing(true);
	layOut.addComponent(txtPO);
	layOut.addComponent(selCat);
	layOut.addComponent(txtQuan);
	Grid.addComponent(layOut, 0, 0, 0, 2);
	Grid.setComponentAlignment(layOut, Alignment.TOP_LEFT);
	
	
	FormLayout layOut2 = new FormLayout();
	layOut2.setMargin(true);
	layOut2.setSpacing(true);
	layOut2.addComponent(txtExp);
	layOut2.addComponent(selPro);
	layOut2.addComponent(hLayA);
	Grid.addComponent(layOut2, 1, 0, 1, 2);
	Grid.setComponentAlignment(layOut2, Alignment.TOP_LEFT);

	
	FormLayout layOut3 = new FormLayout();
	layOut3.setMargin(true);
	layOut3.setSpacing(true);
	layOut3.addComponent(txtRemarkPO);
	layOut3.addComponent(selPat);
	layOut3.addComponent(txtRemarkItem);
	Grid.addComponent(layOut3, 3, 0, 4, 2);
	Grid.setComponentAlignment(layOut3, Alignment.TOP_LEFT);
	
	
	FormLayout layOut4 = new FormLayout();
	layOut4.setMargin(true);
	layOut4.setSpacing(true);
	layOut4.addComponent(btnUpdate);
	layOut4.addComponent(cheAuto);

// layOut4.addComponent(txtStatus);
layOut4.addComponent(selStatus);
Grid.addComponent(layOut4, 6, 0, 6, 2);
Grid.setComponentAlignment(layOut4, Alignment.TOP_LEFT);

	txtPO.setReadOnly(false);
	txtPO.setValue("");
	txtPO.setReadOnly(true);
	txtExp.setReadOnly(false);
	txtExp.setValue("");
	txtExp.setReadOnly(true);
	
	selCat.setEnabled(false);
	selPro.setEnabled(false);
	selPat.setEnabled(false);

// btnAdd.setCaption(“Add”);
btnDelPO.setVisible(false);
btnSubmit.setVisible(false);
btnDel.setVisible(false);
// panel.removeAllComponents();
// panel.setSplitPosition(15);
// this.setEmptyField();
txtQuan.setValue(“”);
VerticalLayout vertLayout = new VerticalLayout();
// FormLayout layOutU = new FormLayout();
// layOutU.setMargin(true);
// layOutU.setSpacing(true);
// layOutU.addComponent(txtRemarkPO);
// FormLayout layOutL = new FormLayout();
// layOutL.setMargin(false);
// layOutL.setSpacing(false);
// layOutL.addComponent(selPat);
// layOutL.addComponent(txtRemarkItem);
// FormLayout layOutR = new FormLayout();
// layOutR.setMargin(false);
// layOutR.setSpacing(false);
// layOutR.addComponent(cheAuto);
// layOutR.addComponent(txtStatus);

// hLayA = new HorizontalLayout();
// hLayA.setMargin(false);
// hLayA.setSpacing(true);
// hLayA.addComponent(btnAdd);
// hLayA.addComponent(btnDel);
// hLayD = new HorizontalLayout();
// hLayD.setMargin(false);
// hLayD.setSpacing(false);
// hLayD.addComponent(layOutL);
// hLayD.addComponent(layOutR);

// FormLayout layOut = new FormLayout();
// layOut.setMargin(true);
// layOut.setSpacing(true);
// FormLayout layOut2 = new FormLayout();
// layOut2.setMargin(true);
// layOut2.setSpacing(true);
// FormLayout layOut3 = new FormLayout();
// layOut3.setMargin(true);
// layOut3.setSpacing(false);
// FormLayout layOut4 = new FormLayout();
// layOut4.setMargin(true);
// layOut4.setSpacing(true);

// layOut.addComponent(txtPO);
// txtPO.setReadOnly(true);
//
// layOut.addComponent(selCat);
// layOut.addComponent(txtQuan);
//
// layOut2.addComponent(txtExp);
// layOut2.addComponent(selPro);
// layOut2.addComponent(hLayA);
//
//
// layOut3.addComponent(layOutU);
// layOut3.addComponent(hLayD);

// layOut4.addComponent(txthid3);
// layOut4.addComponent(cheAuto);
// layOut4.addComponent(txtStatus);
// txtStatus.setReadOnly(true);

	HorizontalLayout hLayout = new HorizontalLayout();
	hLayout.setSpacing(false);
	hLayout.setMargin(false);	
	
	TabSheet tabSheet = new TabSheet();
	
	tabSheet.setWidth("100%");
	tabSheet.setHeight("100%");		
	tabSheet.setStyleName(Reindeer.TABSHEET_BORDERLESS);
	tabSheet.addTab(Grid,this.getMenuLabel2("Order_menu")+" > "+this.getMenuLabel2("Order_menu"));

// hLayout.addComponent(layOut);
// hLayout.addComponent(layOut2);
// hLayout.addComponent(layOut3);
// hLayout.addComponent(layOut4);

	vertLayout.setWidth("100%");
	vertLayout.setMargin(false);
	vertLayout.setSpacing(false);
	
	panel.setFirstComponent(this.tblDataTable);
	
	Data.setFirstComponent(tabSheet);
	Data.setSecondComponent(tblData);		
    
	panel.setSecondComponent(Data);	
	panel.setSplitPosition(23);

// layOut.setSpacing(true);
// layOut.setMargin(true);

	this.setMode("insert");
	viewData(" WHERE order_items.order_id = '' ");
	if (usrgroup == 3){
		viewLeftData("WHERE sales.sale_id = '"+usrLog+"' AND orders.current_status = '2'");
	}else if(usrgroup == 4){
		viewLeftData("WHERE dealers.dealer_id = '"+DealerID+"' AND orders.current_status = '2'");
	}
	else{
		if ( DealerID == 0 ){
			viewLeftData("");
		}else{
		viewLeftData("WHERE dealers.dealer_id = '"+DealerID+"'");
		}
	}
	PurCls.setOrder_id(0);
	
	selectCat();

// selectPro();
// selectPat();
selectStatus();
setLangLabel();

}


private void selectStatus() {
	// TODO Auto-generated method stub
	DB db = new DB();
	db.dbConnect();		
	this.selStatus.removeAllItems();
	try {
		String sql = "SELECT\n" +
				"status.status_id,\n" +
				"status.description\n" +
				"FROM\n" +
				"status\n" +
				"WHERE\n" +
				"status.status_type = 'PO'\n" +
				"order by CONVERT (status.description USING tis620)";
		ResultSet rs =  db.getResult(sql);

// System.out.println("sql : "+sql);
while(rs.next()){
this.selStatus.addItem(rs.getInt(“status_id”));
this.selStatus.setItemCaption(rs.getInt(“status_id”),rs.getString(“description”).trim());
this.selStatus.setImmediate(true);
}
rs.close();
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void viewLeftData(String addSQL) {
	
	this.tblDataTable.removeAllItems();
	
	DateUtil date = new DateUtil();
	date.setDateFormat("yyyy-MM-dd");
	addSQL = (addSQL.equals(""))? " " : addSQL ;
	ArrayList<Object> rs = null;

// System.out.println("g = "+usrgroup);
if(usrgroup == 3){
rs = PurAct.getView1(addSQL + " order by order_id DESC LIMIT 100 ");
}
else{
rs = PurAct.getView(addSQL + " order by order_id DESC LIMIT 100 ");
}

	int i =1;
	if(rs.size() != 0) {
		
		
		IndexedContainer container = new IndexedContainer();
		String PO = this.getMenuLabel2("PO#");
		String POnumber = this.getMenuLabel2("TCE_PO#");
		String PO2 = this.getMenuLabel2("PO_date");
		String PO3 = this.getMenuLabel2("pur_name");
		String PO4 = this.getMenuLabel2("dealer");
		String PO5 = this.getMenuLabel2("lb_expire");
		String stat_lb = this.getMenuLabel2("lb_use_status");
	
		container.addContainerProperty("USER_GROUP_ID", String.class, "");
		container.addContainerProperty(PO, String.class, "");
		container.addContainerProperty(POnumber, String.class, "");
		container.addContainerProperty(PO2, String.class, "");
		container.addContainerProperty(PO3, String.class, "");
		container.addContainerProperty(PO4, String.class, "");
		container.addContainerProperty(PO5, String.class, "");
		container.addContainerProperty(stat_lb, String.class, "");	
		
		 for (Object obj : rs ){
		
	        	PurchaseOrderClass data = (PurchaseOrderClass)obj;
	            Item item = container.addItem(data);

	            item.getItemProperty("USER_GROUP_ID").setValue(data.getOrder_id());
	            item.getItemProperty(PO).setValue(data.getPO());
	            item.getItemProperty(POnumber).setValue(data.getTCEPO());
	            item.getItemProperty(PO2).setValue(date.getCalToStr(data.getDateCreate()));
	            item.getItemProperty(PO3).setValue(data.getPURNAME());
	            item.getItemProperty(PO4).setValue(data.getDEALER());
	            item.getItemProperty(PO5).setValue(data.getExpDate());
	            item.getItemProperty(stat_lb).setValue(data.getStatus2());

	            i++;
		
	    }
	
		this.tblDataTable.setContainerDataSource(container);	
		this.tblDataTable.setSizeUndefined();    
		this.tblDataTable.setWidth("100%");
		this.tblDataTable.setHeight("100%");
		this.tblDataTable.setVisible(true);
		this.tblDataTable.setEnabled(true);			
			
		this.tblDataTable.setSelectable(true);
		this.tblDataTable.setImmediate(true);			
			
		this.tblDataTable.setColumnReorderingAllowed(true);
		this.tblDataTable.setColumnCollapsingAllowed(true);	        

		if(usrgroup == 3){
			this.tblDataTable.setVisibleColumns(new String[] {PO,POnumber,PO2,PO3,PO4,PO5,stat_lb});	
		}
		else if(usrgroup == 4){
			this.tblDataTable.setVisibleColumns(new String[] {PO,POnumber,PO2,PO3,PO5,stat_lb});
		}
		else if(usrgroup == 5){
			
			this.tblDataTable.setVisibleColumns(new String[] {PO,POnumber,PO2,PO3,PO5,stat_lb});
		}
		else{
			this.tblDataTable.setVisibleColumns(new String[] {PO,POnumber,PO2,PO3,PO4,PO5,stat_lb});
		}
		
		this.tblDataTable.addListener(new ItemClickListener() {
			   
				public void itemClick(ItemClickEvent event) {
					
					String a = event.getItem().toString();

		        	b = a.split(" ");
		        	btn_view.setEnabled(true);
		        	
		        	PurCls.setOrder_id(Integer.parseInt(b[0]

));
PurCls.setPO_id(Integer.parseInt(b[0]
));

		        	if(b[9]

.equals(“Draft”)){
PurCls.setCur_status(1);
}
else if(b[9]
.equals(“Submitted”)){
PurCls.setCur_status(2);
}
else if(b[9]
.equals(“Approved”)){
PurCls.setCur_status(3);
}
else if(b[9]
.equals(“Partial”)){
PurCls.setCur_status(4);
}
else if(b[9]
.equals(“Closed”)){
PurCls.setCur_status(5);
}
else if(b[9]
.equals(“Cancel”)){
PurCls.setCur_status(6);
}

// System.out.println(“PurCls.getCur_status()”+PurCls.getCur_status());

		        	PO_EXP();
					cur_status();

// System.out.println(“Status = “+PurCls.getCur_status());
// System.out.println(“Group = “+usrgroup);
txtRemarkItem.setValue(””);
if(usrgroup == 5){
selCat.select(null);
selPro.select(null);
selPro.setEnabled(false);
selPat.select(null);
selPat.setEnabled(false);
txtQuan.setValue(””);
btnAdd.setCaption(“Add”);
mode = “insert”;
}

					if (event.getButton() == com.vaadin.event.MouseEvents.ClickEvent.BUTTON_LEFT) {
						if (PurCls.getCur_status()== 2||PurCls.getCur_status()== 4){
							if (usrgroup == 5){

// System.out.println(1);
selCat.setEnabled(false);
btnSubmit.setVisible(true);
btnDelPO.setVisible(true);
}
else{
// System.out.println(2);
btnDelPO.setVisible(false);
selCat.setEnabled(true);
selCat.select(null);
selCat.setEnabled(false);
selPro.setEnabled(true);
selPro.select(null);
selPro.setEnabled(false);
selPat.setEnabled(true);
selPat.select(null);
selPat.setEnabled(false);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
}
}
else if (PurCls.getCur_status()== 3){
if (usrgroup == 5){
// System.out.println(5);
selCat.setEnabled(false);
btnSubmit.setVisible(true);
btnDelPO.setVisible(true);
}
else{
// System.out.println(6);
btnDelPO.setVisible(false);
selCat.setEnabled(true);
selCat.select(null);
selCat.setEnabled(false);
selPro.setEnabled(true);
selPro.select(null);
selPro.setEnabled(false);
selPat.setEnabled(true);
selPat.select(null);
selPat.setEnabled(false);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
}
}
else{
if (usrgroup == 5){
// System.out.println(3);
selCat.setEnabled(true);
btnSubmit.setVisible(true);
btnDelPO.setVisible(true);
}
else{
// System.out.println(4);
btnDelPO.setVisible(false);
selCat.setEnabled(true);
selCat.select(null);
selCat.setEnabled(false);
selPro.setEnabled(true);
selPro.select(null);
selPro.setEnabled(false);
selPat.setEnabled(true);
selPat.select(null);
selPat.setEnabled(false);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
}
}

// setMode(“update”);
chkApprove();
// System.out.println("approveapproveapprove "+chkApprove);
// System.out.println("partialpartialpartial "+chkPartial);

			           	viewData(" WHERE order_items.order_id" + " = '" +PurCls.getOrder_id()+"'  ");
			           	cur_status();
			           	if (PurCls.getCur_status()== 2||PurCls.getCur_status()== 3||PurCls.getCur_status()== 4){
			           		if (usrgroup == 3 ){
			           			btnNew.setVisible(false);
			           			btnSubmit.setVisible(false);
			           			btnDelPO.setVisible(false);
			           			btnDel.setVisible(false);
			           		}
			           		else if(usrgroup == 5){
			           			btnAdd.setVisible(false);
			           			btnSubmit.setVisible(false);
			           			btnDelPO.setVisible(false);
			           			btnDel.setVisible(false);
			           		}
			           	}
			           	else if (PurCls.getCur_status()== 5){
			           		if (usrgroup == 3 ){
			           			btnNew.setVisible(false);
			           			btnSubmit.setVisible(false);
			           			btnDelPO.setVisible(false);
			           			btnAdd.setVisible(false);
			           			btnDel.setVisible(false);
			           		}
			           		else if(usrgroup == 5){
			           			btnAdd.setVisible(false);
			           			btnSubmit.setVisible(false);
			           			btnDelPO.setVisible(false);
			           			btnDel.setVisible(false);
			           		}	
			           	}
			           	else {
			           		if (usrgroup == 3 ){
			           			btnNew.setVisible(false);
			           			btnSubmit.setVisible(false);
			           			btnDelPO.setVisible(false);
			           			btnAdd.setVisible(false);
			           			btnDel.setVisible(false);
			           		}
			           		else if(usrgroup == 5){
			           			btnAdd.setVisible(true);
			           			btnSubmit.setVisible(true);
			           			btnDelPO.setVisible(true);
			           			btnDel.setVisible(false);
			           		}
			           	}
					}
				}
			});		
	} else {
		rs.clear();
		this.getAlert("search_not_found");
		panel.setSplitPosition(0);
	}   

}

@Override
public void viewData(String addSQL) {
	arrID2.clear();
 	arrValue2.clear();
 		chkApprove = 0;
 		chkPartial = 0;
	tblData.removeAllItems();
	int shownRowsCount = tblData.getVisibleItemIds().size();
	addSQL = (addSQL.equals(""))? " " : addSQL ;
	ArrayList<Object> rs = PurAct.getAll(addSQL + " order by item_no ");
	DecimalFormat df = new DecimalFormat( "#,###,###,##0.00" );
	final DecimalFormat df2 = new DecimalFormat( "#,###,###,##0" );
	int i =1;
	
	if(rs.size() != 0) {
		
		BigDecimal AmountShowFooter = new BigDecimal(0);
		double sumAmount = 0.0;
		double sumAmount2 = 0.0;
		final IndexedContainer container1 = new IndexedContainer();
        
		final String item = this.getMenuLabel2("PO_item");
		final String model = this.getMenuLabel2("PO_model");
		final String pattern = this.getMenuLabel2("PO_pattern");
		final String price = this.getMenuLabel2("PO_price");
		final String qty = this.getMenuLabel2("PO_qty");
		final String unit = this.getMenuLabel2("PO_unit");
		final String amount = this.getMenuLabel2("PO_amount");
		final String approve = this.getMenuLabel2("PO_approve");
        final String amount2 = this.getMenuLabel2("PO_amount2");
        final String status = this.getMenuLabel2("lb_item_status");
        final String remark = this.getMenuLabel2("lb_remark");
      
        
        container1.addContainerProperty("ID", String.class, "");
        container1.addContainerProperty("order_id", String.class, "");
        container1.addContainerProperty(item, String.class, "");	
        container1.addContainerProperty(model, String.class, "");
        container1.addContainerProperty(pattern, String.class, "");
        container1.addContainerProperty(price, String.class, "");
        container1.addContainerProperty(qty, String.class, "");
        container1.addContainerProperty(unit, String.class, "");
        container1.addContainerProperty(amount, String.class, "");
        container1.addContainerProperty(approve, TextField.class, "");
        container1.addContainerProperty(amount2, String.class, "");
        container1.addContainerProperty(status, String.class, "");
        container1.addContainerProperty(remark, String.class, "");
       
       
        for (Object obj : rs ){

        	final PurchaseOrderClass data = (PurchaseOrderClass)obj;
        	final Item item2 = container1.addItem(data);
             Object txtAppID = data.getItem_id();
             final TextField txtApp = new TextField();
        	txtApp.setWidth("50px");
        	txtApp.setData(txtAppID);
        	txtApp.addStyleName("align-right");
        	txtApp.setImmediate(true);

// final TextField txtAmount2 = new TextField();
// txtAmount2.setWidth(“50px”);
// txtAmount2.setReadOnly(true);
// final TextField txtStatus = new TextField();
// final TextField txtremark = new TextField();
// txtremark.setWidth(“110px”);
// txtStatus.setReadOnly(true);

// txtAmount2.setImmediate(true);
// txtStatus.setImmediate(true);
// txtremark.setImmediate(true);

        	arrID2.add(Integer.parseInt(txtApp.getData().toString()));
        	arrValue2.add(data.getPoqty()-data.getAppqty());
        	
        	
        	
        	txtApp.addListener(new TextChangeListener() {
        		int getItemId = 0;
        		int getQuantity = 0;
        		int getProductPrice = 0;
        		int getIndex = 0;
				public void textChange(TextChangeEvent event) {
					
					// TODO Auto-generated method stub
					getItemId = Integer.parseInt(txtApp.getData().toString());

// System.out.println("DataID = "+Integer.parseInt(txtApp.getData().toString()));
// System.out.println("Values = "+event.getText().toString());
CheckQuantity();

					if(!event.getText().toString().equals("")){
						if(tmsV.checkNumeric(event.getText().toString())==true){
							if(Integer.parseInt(event.getText().toString())>getQuantity){
								DmsApplication.getInstance().getMainWindow().showNotification("Approve more than quantity!!!");

								txtApp.setValue(getQuantity);
								item2.getItemProperty(amount2).setValue(getQuantity*getProductPrice);

// txtAmount2.setReadOnly(false);
// txtAmount2.setValue(getQuantity*getProductPrice);
// txtAmount2.setReadOnly(true);
if(!arrID.isEmpty()){

// System.out.println(“arrID.size()arrID.size()arrID.size()”+arrID.size());
boolean chk = check();
if(chk==false){
arrID.add(Integer.parseInt(txtApp.getData().toString()));
arrValue.add(getQuantity);
// System.out.println(“EEEEEEEEEEEEEEEEEEEEEEEEe”);
// System.out.println(arrID);
// System.out.println(arrValue);
}else{
// System.out.println("mai add "+arrID);
// arrValue.add(getQuantity);
// System.out.println(arrValue);
}

								}else{
									arrID.add(Integer.parseInt(txtApp.getData().toString()));
									arrValue.add(getQuantity);

// System.out.println(“DDDDDDDDDDDDDDDDDd”);
// System.out.println(arrID);
// System.out.println(arrValue);
}

							}else{

// txtAmount2.setReadOnly(false);
item2.getItemProperty(amount2).setValue(Integer.parseInt(event.getText().toString())*getProductPrice);
// txtAmount2.setValue(Integer.parseInt(event.getText().toString())*getProductPrice);
// txtAmount2.setReadOnly(true);
if(!arrID.isEmpty()){

// System.out.println(arrID.size());
boolean chk = check();
if(chk==false){
arrID.add(Integer.parseInt(txtApp.getData().toString()));
arrValue.add(Integer.parseInt(event.getText().toString()));

										getIndex = Integer.parseInt(event.getText().toString());

// System.out.println(arrID);
// System.out.println(arrValue);
}else{

// System.out.println("mai add "+arrID);
if(arrID.size()<=1){
arrValue.clear();
// System.out.println(“CCCCCCCCCCCCCCCCCCCCCCCC”);
arrValue.add(Integer.parseInt(event.getText().toString()));
// System.out.println(arrID);
// System.out.println(arrValue);
}else{
// int Index4 = arrValue.indexOf(Integer.parseInt(event.getText().toString()));
// System.out.println("Index 4 "+Index4);
// System.out.println("getIndex "+getIndex);
// System.out.println(arrValue);
// arrValue.remove(getIndex);
// Index4–;
// arrValue.add(Index4,Integer.parseInt(event.getText().toString()));
}

									}

								}else{
									arrID.add(Integer.parseInt(txtApp.getData().toString()));
									arrValue.add(Integer.parseInt(event.getText().toString()));

// System.out.println(arrID);
// System.out.println(arrValue);
}

							}
						}else{
							DmsApplication.getInstance().getMainWindow().showNotification("Please Enter Numberic!!!");
							txtApp.setValue("");

// txtAmount2.setReadOnly(false);
// txtAmount2.setValue(“”);
// txtAmount2.setReadOnly(true);
item2.getItemProperty(amount2).setValue(“”);
if(arrID.size()<=1){
arrID.clear();
arrValue.clear();
// System.out.println(arrID);
// System.out.println(arrValue);
// System.out.println(“AAAAAAAAAAAAAAAAAAAAAAAAa”);
}else{
int Index = arrID.indexOf(Integer.parseInt(txtApp.getData().toString()));
int Index2 = arrValue.indexOf(Integer.parseInt(event.getText().toString()));
arrID.remove(Index);
arrValue.remove(Index2);

								Index--;
								Index2--;

// System.out.println(“BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB”);
// System.out.println(arrID);
// System.out.println(arrValue);
}
}
}else{
txtApp.setValue(“”);
item2.getItemProperty(amount2).setValue(“”);
// txtAmount2.setReadOnly(false);
// txtAmount2.setValue(“”);
// txtAmount2.setReadOnly(true);
if(arrID.size()<=1){
arrID.clear();
arrValue.clear();
// System.out.println(arrID);
// System.out.println(arrValue);
}else{
int Index = arrID.indexOf(Integer.parseInt(txtApp.getData().toString()));
int Index2 = arrValue.indexOf(Integer.parseInt(event.getText().toString()));
arrID.remove(Index);
arrValue.remove(Index2);

							Index--;
							Index2--;

// System.out.println(arrID);
// System.out.println(arrValue);
}
}
}

				public boolean check(){
					System.out.println("arrIDarrIDarrID"+arrID);
					int i =0;
					for ( i = 0; i < arrID.size(); i++)
					  {
					    if (Integer.parseInt(arrID.get(i).toString()) == getItemId) return true ;
					  }
					return false;
				}
				
				public void CheckQuantity(){
					DB db = new DB();
					db.dbConnect();	
					DateUtil date = new DateUtil();
					date.setDateFormat("yyyy-MM-dd");
					
					String sql = 	
							"SELECT "+
							"order_items.item_no, "+
							"order_items.order_id, "+
							"order_items.product_id, "+
							"order_items.pattern_id, "+
							"order_items.po_unit_price, "+
							"order_items.po_qty, "+
							"order_items.app_unit_price, "+
							"order_items.app_qty, "+
							"products.model_code, "+
							"products.description AS product_name, "+
							"products.category_id, "+
							"products.unit, "+
							"products.unit_price, "+
							"patterns.pattern_code, "+
							"patterns.description AS pattern_name, "+
							"categories.description "+
							"FROM "+
							"products "+
							"RIGHT JOIN order_items ON products.product_id = order_items.product_id "+
							"LEFT JOIN patterns ON patterns.pattern_id = order_items.pattern_id "+
							"LEFT JOIN categories ON categories.category_id = products.category_id "+
							"WHERE order_items.order_id" + " = '" +PurCls.getOrder_id()+"' AND order_items.item_no = '"+getItemId+"'";

// System.out.println(“CheckQuantity???”+sql);
ResultSet rs = db.getResult(sql);

					try {				
						
						if(rs.next()){
							getQuantity = rs.getInt("po_qty");

// getProductPrice = rs.getInt(“unit_price”);
getProductPrice = rs.getInt(“po_unit_price”);
}
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}

				}
				
				
        		
			});
        
        	/////////////////////////////////////////////////////////////////////////////////////
        	
            if (PurCls.getCur_status()== 2||PurCls.getCur_status()== 4){
            	if (usrgroup == 3){
            		
            		txtApp.setReadOnly(false);
            		
            	}
            	else{
            		txtApp.setReadOnly(true);
            	}
            }
            else{
            	
            	txtApp.setReadOnly(true);
            }
            
            if(data.getAppqty()!=0){

// txtAmount2.setReadOnly(false);
// txtAmount2.setValue(data.getAppqty()*data.getAppprice());
// txtAmount2.setReadOnly(true);
txtApp.setReadOnly(false);
txtApp.setValue(“”);
txtApp.setValue(data.getPoqty()-data.getAppqty());
txtApp.setReadOnly(true);
if(usrgroup==3){

            		txtApp.setReadOnly(false);

// txtApp.setValue(data.getPoqty());
txtApp.setValue(data.getPoqty()-data.getAppqty());
}

            }else{
            	txtApp.setReadOnly(false);
            	txtApp.setValue("");
            	
            	txtApp.setReadOnly(true);
            	if(usrgroup==3){
            		
            		txtApp.setReadOnly(false);
            		txtApp.setValue(data.getPoqty());
            	}
            }

// System.out.println(“Appqty “+data.getAppqty() +” POqty “+data.getPoqty());
// if(data.getAppqty()<data.getPoqty()){
// if(data.getAppqty()==0){
// txtStatus.setReadOnly(false);
// txtStatus.setValue(””);
// txtStatus.setReadOnly(true);
// }else{
// txtStatus.setReadOnly(false);
// txtStatus.setValue(data.getStatus_name());
// txtStatus.setReadOnly(true);
// }
// }else{
// txtStatus.setReadOnly(false);
// txtStatus.setValue(data.getStatus_name());
// txtStatus.setReadOnly(true);
//
// }
if(data.getPoqty()==data.getAppqty()){
this.tblData.addStyleName(“green”);
}else{
this.tblData.addStyleName(“red”);
}
sumAmount+= data.getAmount();
BigDecimal AmountShow = new BigDecimal(data.getAmount());

            AmountShowFooter = new BigDecimal(sumAmount);
            AmountShowFooter.doubleValue();
            sumAmount2 += data.getAppqty()*data.getAppprice();
        	
           
            
            item2.getItemProperty("ID").setValue(data.getItem_id());
            item2.getItemProperty("order_id").setValue(data.getOrder_id());
            item2.getItemProperty(item).setValue(i);
            item2.getItemProperty(model).setValue(data.getProduct_name() +" ("+ data.getModel_code() +")");
            item2.getItemProperty(pattern).setValue(data.getPattern_name());
            item2.getItemProperty(price).setValue(df.format(data.getPoprice()));
            item2.getItemProperty(qty).setValue(df2.format(data.getPoqty()));
            item2.getItemProperty(unit).setValue(data.getUnit());
            item2.getItemProperty(amount).setValue(df.format(AmountShow.doubleValue()));
            item2.getItemProperty(approve).setValue(txtApp);
            item2.getItemProperty(amount2).setValue(df.format(data.getAppqty()*data.getAppprice()));
            item2.getItemProperty(status).setValue(data.getStatus_name());
            item2.getItemProperty(remark).setValue(data.getRemark_item());

            
            
            i++;  
        }
        
        
        this.tblData.setContainerDataSource(container1);	
        
        this.tblData.setVisible(true);
        this.tblData.setEnabled(true);
        if(i>6){
        	this.tblData.setWidth("92.5%");
        }else{
        	this.tblData.setWidth("91%");
        }
        if(i>6){
			this.tblData.setPageLength(7);
		}else{
			this.tblData.setPageLength(i-1);
		}

// this.tblData.setPageLength(shownRowsCount);
if(usrgroup == 3){
this.tblData.setSelectable(false);
this.tblData.setImmediate(true);
}
else if(usrgroup == 4){
this.tblData.setSelectable(false);
this.tblData.setImmediate(true);
}
else if(usrgroup == 5){
this.tblData.setSelectable(true);
this.tblData.setImmediate(true);
}
else{
this.tblData.setSelectable(false);
this.tblData.setImmediate(true);
}

        this.tblData.setColumnReorderingAllowed(true);
        this.tblData.setColumnCollapsingAllowed(true);	        

// tblDataTable.setColumnCollapsed(getLabel(2), true);
this.tblData.setVisibleColumns(new String {item,model,pattern,price,qty,unit,amount,approve,amount2,status,remark});

        tblData.setColumnWidth(item, 25);
        tblData.setColumnWidth(model, 130);
        tblData.setColumnWidth(pattern, 100);
        tblData.setColumnWidth(price, 55);
        this.tblData.setColumnAlignment(price, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(qty, 55);
        this.tblData.setColumnAlignment(qty, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(unit, 50);
        tblData.setColumnWidth(amount, 90);
        this.tblData.setColumnAlignment(amount, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(approve, 50);
        this.tblData.setColumnAlignment(approve, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(amount2, 90);
        this.tblData.setColumnAlignment(amount2, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(status, 60);
	
        tblData.setFooterVisible(true);
        this.tblData.setColumnFooter(pattern,"<b>"+this.getMenuLabel2("lb_total")+"</b>");
        this.tblData.setColumnFooter(amount, "<b>"+df.format(AmountShowFooter)+"</b>");
        this.tblData.setColumnFooter(amount2, "<b>"+df.format(sumAmount2)+"</b>");
        this.tblData.addListener(new ItemClickListener() {
			   
			public void itemClick(ItemClickEvent event) {
				// TODO Auto-generated method stub
				if (event.getButton() == com.vaadin.event.MouseEvents.ClickEvent.BUTTON_LEFT) {
		        	String a = event.getItem().toString();
		        	
		        	String[] b = a.split(" ");
		        	
		        	PurCls.setItem_id(Integer.parseInt(b[0]

));
PurCls.setOrder_id(Integer.parseInt(b[1]
));
PurCls.setPO_id(Integer.parseInt(b[1]
));
if (PurCls.getCur_status()== 2||PurCls.getCur_status()== 3||PurCls.getCur_status()== 4){
if(usrgroup == 3){
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}
else if(usrgroup == 4){
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}
else if(usrgroup == 5){
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}
else{
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}
}
else if (PurCls.getCur_status()== 5){
if(usrgroup == 3){
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}
else if(usrgroup == 4){
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}
else if(usrgroup == 5){
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}
else{
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}

			        		}
			        else {
			        	
				        	if(usrgroup == 3){
				        		selCat.select(null);
					           	selPro.select(null);
					        	selPat.select(null);
					        	txtQuan.setValue("");
					        	txtQuan.setEnabled(false);
					        	selCat.setEnabled(false);
					        	selPro.setEnabled(false);
					        	selPat.setEnabled(false);	
								}
								else if(usrgroup == 4){
									selCat.select(null);
						           	selPro.select(null);
						        	selPat.select(null);
						        	txtQuan.setValue("");
						        	txtQuan.setEnabled(false);
						        	selCat.setEnabled(false);
						        	selPro.setEnabled(false);
						        	selPat.setEnabled(false);	
						        }
								else if(usrgroup == 5){
									PurAct.getById();
						        	selCat.select(PurCls.getCat_id());
						           	selPro.select(PurCls.getProduct_id());
						        	selPat.select(PurCls.getPattern_id());
						        	txtRemarkItem.setValue(PurCls.getRemark_item());
						        	txtQuan.setEnabled(true);
						        	txtQuan.setValue(df2.format(PurCls.getPoqty()));
						        	selCat.setEnabled(false);
						        	selPro.setEnabled(false);
						        	selPat.setEnabled(false);
						          	setMode("update");
						           	btnDel.setVisible(true);

// btnAdd.setVisible(true);
btnAdd.setCaption(“Edit”);
}
else{
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(“”);
txtQuan.setEnabled(false);
selCat.setEnabled(false);
selPro.setEnabled(false);
selPat.setEnabled(false);
}

			        	}
					}
				}
			});		

	} else{
		IndexedContainer container1 = new IndexedContainer();
        
        String item = this.getMenuLabel2("PO_item");
        String model = this.getMenuLabel2("PO_model");
        String pattern = this.getMenuLabel2("PO_pattern");
        String price = this.getMenuLabel2("PO_price");
        String qty = this.getMenuLabel2("PO_qty");
        String unit = this.getMenuLabel2("PO_unit");
        String amount = this.getMenuLabel2("PO_amount");
        String approve = this.getMenuLabel2("PO_approve");
        String amount2 = this.getMenuLabel2("PO_amount2");
        String status = this.getMenuLabel2("lb_item_status");
        String remark = this.getMenuLabel2("lb_remark");
        
        container1.addContainerProperty("USER_GROUP_ID", String.class, "");
        container1.addContainerProperty(item, String.class, "");	
        container1.addContainerProperty(model, String.class, "");
        container1.addContainerProperty(pattern, String.class, "");
        container1.addContainerProperty(price, String.class, "");
        container1.addContainerProperty(qty, String.class, "");
        container1.addContainerProperty(unit, String.class, "");
        container1.addContainerProperty(amount, String.class, "");
        container1.addContainerProperty(approve, String.class, "");
        container1.addContainerProperty(amount2, String.class, "");
        container1.addContainerProperty(status, String.class, "");
        container1.addContainerProperty(remark, String.class, "");
        
        this.tblData.setContainerDataSource(container1);
        this.tblData.setWidth("95%");
        this.tblData.setVisible(true);
        this.tblData.setEnabled(true);			
		
        this.tblData.setSelectable(true);
        this.tblData.setImmediate(true);			
		
        this.tblData.setColumnReorderingAllowed(true);
        this.tblData.setColumnCollapsingAllowed(true);
        tblData.setFooterVisible(false);
      

        this.tblData.setVisibleColumns(new String[] {item,model,pattern,price,qty,unit,amount,approve,amount2,status,remark});
        tblData.setColumnWidth(item, 25);
        tblData.setColumnWidth(model, 170);
        tblData.setColumnWidth(pattern, 130);
        tblData.setColumnWidth(price, 55);
        this.tblData.setColumnAlignment(price, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(qty, 30);
        this.tblData.setColumnAlignment(qty, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(unit, 50);
        tblData.setColumnWidth(amount, 55);
        this.tblData.setColumnAlignment(amount, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(approve, 55);
        this.tblData.setColumnAlignment(approve, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(amount2, 55);
        this.tblData.setColumnAlignment(amount2, Table.ALIGN_RIGHT);
        tblData.setColumnWidth(status, 50);
        this.tblData.setPageLength(0);
	}

}

public void runningPO(){
	
	PurCls.setDealer_id(DealerID);
	
	Locale currenntLocale = new Locale("en","us");
	final DateFormat dateFormat = new SimpleDateFormat("MMyyyy",currenntLocale);
	final String num = saleRunning();
	final Date Tempdate = new Date();
	
	txtPO.setReadOnly(false);
	txtPO.setValue(DealerID+"-"+dateFormat.format(Tempdate.getTime())+"-"+num);
	txtPO.setReadOnly(true);
	txtExp.setReadOnly(false);
	txtExp.setValue(PurCls.getExpDate());
	txtExp.setReadOnly(true);
	
	PurCls.setPonumber(txtPO.getValue().toString());
	PurAct.insertSaleRunningNo();
	PurAct.insertPO();
	PurAct.selectPO_id();
	this.cur_status();
	
	if (usrgroup == 3){
		viewLeftData("WHERE sales.sale_id = '"+usrLog+"'");
	}else if(usrgroup == 4){
		viewLeftData("WHERE dealers.dealer_id = '"+DealerID+"' AND orders.current_status = '2'");
	}
	else{
		if ( DealerID == 0 ){
			viewLeftData("");
		}else{
		viewLeftData("WHERE dealers.dealer_id = '"+DealerID+"'");
		}
	}
}



@Override
public void setLangLabel() {
	txtPO.setCaption("PO#");
	selCat.setCaption(this.getMenuLabel2("select_Categories"));
	selPro.setCaption(this.getMenuLabel2("select_Product"));
	selPat.setCaption(this.getMenuLabel2("select_Pattern"));
	cheAuto.setCaption(this.getMenuLabel2("check_Auto"));
	txtQuan.setCaption(this.getMenuLabel2("lb_Quantity"));
	txtExp.setCaption(this.getMenuLabel2("lb_expire"));
	tblData.setCaption(this.getMenuLabel2("Data"));
	tblDataTable.setCaption(this.getMenuLabel2("Data"));
	txtRemarkPO.setCaption(this.getMenuLabel2("lb_POre"));
	txtRemarkItem.setCaption(this.getMenuLabel2("lb_itemre"));
	creditTxt.setCaption(this.getMenuLabel2("creditTxt"));
	getpriceTxt.setCaption(this.getMenuLabel2("getpriceTxt"));
	chkpriceTxt.setCaption(this.getMenuLabel2("chkpriceTxt"));
	
	
}

@Override
public void setEmptyField() {
	btnSubmit.setVisible(false);
	btnDelPO.setVisible(false);
	btnDel.setVisible(false);
	selCat.select(null);
	selPro.select(null);
	selPat.select(null);
	cheAuto.setValue(false);
	txtQuan.setValue("");
	txtRemarkPO.setValue("");
	txtRemarkItem.setValue("");
	tblData.removeAllItems();
	tblData.setFooterVisible(false);
	
}

@Override
public void btnNew(ClickEvent event) {
	
	subwindow = new Window("");
	message = new Label("");
	yes = new Button("",this,"btnYes");
	no = new Button("",this,"btnNo");
	temp = new Button("",this,"btnTemp");
	
    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);		
	
    HorizontalLayout area = new HorizontalLayout();
    area.setSpacing(true);
    area.setMargin(true);
    area.addComponent(yes);
    area.setComponentAlignment(yes,Alignment.TOP_LEFT);
    area.addComponent(no);
    area.setComponentAlignment(no,Alignment.TOP_RIGHT);
    area.addComponent(temp);
    area.setComponentAlignment(temp, Alignment.TOP_RIGHT);
    
    layout.addComponent(message);
    layout.addComponent(area);   
    
	subwindow.setCaption(this.getMenuLabel2("confrim_title"));
    subwindow.setWidth("300px");
    // ...and make it modal
    subwindow.setModal(true);

    // Configure the windws layout; by default a VerticalLayout


    // Add some content; a label and a close-button
    message.setCaption(this.getMenuLabel2("create_po"));
   

    yes.setCaption(this.getMenuLabel2("btn_yes"));
    no.setCaption(this.getMenuLabel2("btn_no"));
    temp.setCaption(this.getMenuLabel2("btn_temp"));
    chkGroup();
    DmsApplication.getInstance().getMainWindow().addWindow(subwindow);		
}
	public void btnYes(Button.ClickEvent event) {
		setNextAlert();
		runningPO();
		setEmptyField();
		selCat.setEnabled(true);
		subwindow.getParent().removeWindow(subwindow);
		this.setMode("insert");
	}	
	
	public void btnTemp(Button.ClickEvent event) {

// setNextAlert();
// runningPO();
// setEmptyField();
// selCat.setEnabled(true);
// subwindow.getParent().removeWindow(subwindow);

	}

	public void btnNo(Button.ClickEvent event) {
		subwindow.getParent().removeWindow(subwindow);
	}


@Override
public void btnAct(ClickEvent event) {
	
	subwindow = new Window("");
	message = new Label("");
	yes = new Button("",this,"btnYes3");
	no = new Button("",this,"btnNo3");
	
    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);		
	
    HorizontalLayout area = new HorizontalLayout();
    area.setSpacing(true);
    area.setMargin(true);
    area.addComponent(yes);
    area.setComponentAlignment(yes,Alignment.TOP_LEFT);
    area.addComponent(no);
    area.setComponentAlignment(no,Alignment.TOP_RIGHT);
    
    layout.addComponent(message);
    layout.addComponent(area);   
    
	subwindow.setCaption(this.getMenuLabel2("confrim_title"));
    subwindow.setWidth("300px");
    // ...and make it modal
    subwindow.setModal(true);

    message.setCaption(this.getMenuLabel2("confirm_submit"));

    yes.setCaption(this.getMenuLabel2("btn_yes"));
    no.setCaption(this.getMenuLabel2("btn_no"));

/////////////////////////////////////////////////////////////////////////////////////////////////check

    String DatePO = "";
	Locale currentLocale = new Locale("en","US");
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",currentLocale);
	Date date = new Date();
	
	getprice = null;
	chkprice = null;
	credit = null;
	int chktotalPro = 0;
	int chkquotaPro = 0;

	Date DateNow = new Date();
	DatePO = this.getDatePO();

// System.out.println("DateNow : “+dateFormat.format(DateNow)+” <> DatePO : "+DatePO);

				//////////Check Credit/////////
				getprice = this.getpriceval();
				chkprice = this.chktotalprice();
				getprice = getprice.multiply(new BigDecimal(PurCls.getPoqty()));
				chkprice = chkprice.add(getprice);
				credit = this.getcredit();		
				
				creditTxt.setReadOnly(false);
				getpriceTxt.setReadOnly(false);
				chkpriceTxt.setReadOnly(false);
				
				creditTxt.setValue(credit);
				getpriceTxt.setValue(getprice);
				chkpriceTxt.setValue(chkprice);
				
				creditTxt.setReadOnly(true);
				getpriceTxt.setReadOnly(true);
				chkpriceTxt.setReadOnly(true);

// System.out.println("getprice : “+getprice+” <> chkprice : “+chkprice+” <> credit : "+credit);
int val = chkprice.compareTo(credit);
//////////////////////////////
if(val==-1){
//////////Check Quota///////////
chktotalPro = getTotalQty();
chktotalPro += PurCls.getPoqty();
chkquotaPro = getProQuota();
///////////////////////////////
boolean chk = true;

// DatePO = this.getDatePO();
DatePO = dateFormat.format(DateNow);

					if(chkquotaPro==0){
						 DmsApplication.getInstance().getMainWindow().addWindow(subwindow);
					}else{
						DmsApplication.getInstance().getMainWindow().addWindow(subwindow);
						if(chkquotaPro<chktotalPro){
							Lock();
						}else{
							if(DatePO.equals(dateFormat.format(date))){
								}else{
									DmsApplication.getInstance().getMainWindow().showNotification(this.getMenuLabel2("lb_chk_date"));

						}
					}
					}
					if(chk == false) { 
						btnSubmit.setVisible(true);
						this.getAlert("alert_save");
					} 
				}else{
					Lock();
				}

	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////check
				

    
}
	
	public void btnYes3(Button.ClickEvent event) {

// PurCls.setPonumber(txtPO.getValue().toString());
// PurAct.selectPO_id();
runningSubmit();

		DB conn = new DB();
		conn.dbConnect();
		String sql = "UPDATE orders SET " +
				"`current_status` =  '2'" +
				",tce_order_no = '" + PurCls.getTCEPO()+ "'"+
				",updated_user = '" + PurCls.getUpdate_user()+ "'" +
				",updated_datetime = NOW() " +
				" WHERE order_id = '" + PurCls.getPO_id()+ "'" ;
		conn.executeSQL(sql);
		System.out.println(">>>>> " +sql);
		try {
			conn.dbClose();
		} catch (SQLException e) {
			e.printStackTrace();
		}

// txtStatus.setReadOnly(false);
// txtStatus.setValue(“”);
// txtStatus.setReadOnly(true);
// selStatus.select(null);
txtPO.setReadOnly(false);
txtPO.setValue(“”);
txtPO.setReadOnly(true);
txtExp.setReadOnly(false);
txtExp.setValue(“”);
txtExp.setReadOnly(true);
if (usrgroup == 3){
viewLeftData(“WHERE sales.sale_id = '”+usrLog+“'”);
}
else if(usrgroup == 4){
viewLeftData(“WHERE dealers.dealer_id = '”+DealerID+“’ AND orders.current_status = ‘2’”);
}
else{
if ( DealerID == 0 ){
viewLeftData(“”);
}else{
viewLeftData(“WHERE dealers.dealer_id = '”+DealerID+“'”);
}
}
setEmptyField();
// SendMail();
SendMail2();
subwindow.getParent().removeWindow(subwindow);
}

	public void btnNo3(Button.ClickEvent event) {
		subwindow.getParent().removeWindow(subwindow);
	}	
	
public void btnDelPO(ClickEvent event){
	subwindow = new Window("");
	message = new Label("");
	yes = new Button("",this,"btnYes1");
	no = new Button("",this,"btnNo1");
	
    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);		
	
    HorizontalLayout area = new HorizontalLayout();
    area.setSpacing(true);
    area.setMargin(true);
    area.addComponent(yes);
    area.setComponentAlignment(yes,Alignment.TOP_LEFT);
    area.addComponent(no);
    area.setComponentAlignment(no,Alignment.TOP_RIGHT);
    
    layout.addComponent(message);
    layout.addComponent(area);   
    
    txtQuan.setEnabled(false);
	selCat.setEnabled(false);
	selPro.setEnabled(false);
	selPat.setEnabled(false);
    
    
    
    
	subwindow.setCaption(this.getMenuLabel2("confrim_title"));
    subwindow.setWidth("300px");
    // ...and make it modal
    subwindow.setModal(true);

    message.setCaption(this.getMenuLabel2("confirm_del"));

    yes.setCaption(this.getMenuLabel2("btn_yes"));
    no.setCaption(this.getMenuLabel2("btn_no"));
    
    DmsApplication.getInstance().getMainWindow().addWindow(subwindow);		
}
	
	public void btnYes1(Button.ClickEvent event) {
		PurCls.setTableName("orders");
		PurAct.delData();
		PurCls.setTableName("order_items");
		PurAct.delData();
		this.getAlert("alert_del");
		if (usrgroup == 3){
			viewLeftData("WHERE sales.sale_id = '"+usrLog+"'");
		}
		else if(usrgroup == 4){
			viewLeftData("WHERE dealers.dealer_id = '"+DealerID+"' AND orders.current_status = '2'");
		}
		else{
			if ( DealerID == 0 ){
				viewLeftData("");
			}else{
			viewLeftData("WHERE dealers.dealer_id = '"+DealerID+"'");
			}
		}
		this.viewData("");		
		this.setEmptyField();
		txtPO.setReadOnly(false);
		txtPO.setValue("");
		txtPO.setReadOnly(true);
		txtExp.setReadOnly(false);
		txtExp.setValue("");
		txtExp.setReadOnly(true);
		this.setMode("insert");
		subwindow.getParent().removeWindow(subwindow);
	}	

	public void btnNo1(Button.ClickEvent event) {
		subwindow.getParent().removeWindow(subwindow);
	}	

@Override
public void btnDel(ClickEvent event) {
	subwindow = new Window("");
	message = new Label("");
	yes = new Button("",this,"btnYes2");
	no = new Button("",this,"btnNo2");
	
    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);		
	
    HorizontalLayout area = new HorizontalLayout();
    area.setSpacing(true);
    area.setMargin(true);
    area.addComponent(yes);
    area.setComponentAlignment(yes,Alignment.TOP_LEFT);
    area.addComponent(no);
    area.setComponentAlignment(no,Alignment.TOP_RIGHT);
    
    layout.addComponent(message);
    layout.addComponent(area);   
    
	subwindow.setCaption(this.getMenuLabel2("confrim_title"));
    subwindow.setWidth("300px");
    // ...and make it modal
    subwindow.setModal(true);

    message.setCaption(this.getMenuLabel2("confirm_del"));

    yes.setCaption(this.getMenuLabel2("btn_yes"));
    no.setCaption(this.getMenuLabel2("btn_no"));
    
    DmsApplication.getInstance().getMainWindow().addWindow(subwindow);		
}
	
	public void btnYes2(Button.ClickEvent event) {
		PurAct.delitem();
		this.getAlert("alert_del");
		this.setEmptyField();
		this.viewData(" WHERE order_items.order_id = '"+ PurCls.getOrder_id() +"'");
		
		selCat.setEnabled(true);
		selPro.setEnabled(false);
		selPat.setEnabled(false);
		btnAdd.setCaption("Add");
		this.setMode("insert");
		subwindow.getParent().removeWindow(subwindow);
	}	

	public void btnNo2(Button.ClickEvent event) {
		subwindow.getParent().removeWindow(subwindow);
	}	
	


public void btnAdd(ClickEvent event) {
	String DatePO = "";
	Locale currentLocale = new Locale("en","US");
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",currentLocale);
	Date date = new Date();

// BigDecimal getprice = null;
// BigDecimal chkprice = null;
// BigDecimal credit = null;
// int chktotalPro = 0;
// int chkquotaPro = 0;
if (mode == “insert”) {
if(this.checkValidate() == true){

			int count12 = 0;
			String[] a ={};
			String Output ="";
			while(count12 < txtQuan.getValue().toString().length()){

// System.out.println(txtQuan.getValue().toString());
a = txtQuan.getValue().toString().split(“,”);
count12++;
}
for(int i =0;i<a.length;i++){
Output = Output + a[i]
;
}

		PurCls.setProduct_id(new Integer("" + selPro.getValue()));
		PurCls.setPattern_id(new Integer("" + selPat.getValue()));
		PurCls.setPoqty(new Integer("" + Output));
		PurCls.setRemark_item(txtRemarkItem.getValue().toString());
		PurAct.getPrice();
		PurAct.selectPO_id();

// PurCls.setAmount(PurCls.getPoprice()*PurCls.getPoqty());

			if(this.checkDup() == false){
				//////////Check Credit/////////

// getprice = this.getpriceval();
// chkprice = this.chktotalprice();
//// System.out.println("GETVVALUES_before : “+chkprice+” "+getprice);
// getprice = getprice.multiply(new BigDecimal(PurCls.getPoqty()));
// chkprice = chkprice.add(getprice);
// credit = this.getcredit();
//// System.out.println("GETVVALUES_after : “+chkprice+” “+credit+” "+getprice);
// int val = chkprice.compareTo(credit);
// System.out.println(val);
//////////////////////////////
// if(val==-1){
//////////Check Quota///////////
// chktotalPro = getTotalQty();
// chktotalPro += PurCls.getPoqty();
// chkquotaPro = getProQuota();
// System.out.println("CheckQuota : “+chktotalPro+” “+chkquotaPro);
///////////////////////////////
boolean chk = true;
DatePO = this.getDatePO();
// System.out.println(DatePO+” "+dateFormat.format(date));
// if(chkquotaPro==0){

						if(DatePO.equals(dateFormat.format(date))){
							chk = PurAct.insertData();
						}else{
							DmsApplication.getInstance().getMainWindow().showNotification(this.getMenuLabel2("lb_chk_date"));
							//cound't insert po# is older than date of insert
						}

// }else{
// if(chkquotaPro<chktotalPro){
// Lock();
// }else{
// if(DatePO.equals(dateFormat.format(date))){
// chk = PurAct.insertData();
// }else{
// DmsApplication.getInstance().getMainWindow().showNotification(this.getMenuLabel2(“lb_chk_date”));
// //cound’t insert po# is older than date of insert
// }
// }
// }
// System.out.println(chk);
if(chk == false) {
viewData(" WHERE order_items.order_id = ‘“+ PurCls.getPO_id()+”’ “);
btnSubmit.setVisible(true);
// this.setMode(“update”);
this.getAlert(“alert_save”);
// viewData(”“);
selCat.select(null);
selPro.select(null);
selPat.select(null);
txtQuan.setValue(”“);
txtRemarkItem.setValue(”");
}
// else {
//// PurAct.delData();
// DmsApplication.getInstance().getMainWindow().showNotification(this.getMenuLabel2(“lb_insert_fail”));
// }

// }else{
// Lock();
// }

			} else {
				this.getAlert("alert_insert_dupicate");
			}
		}	
		else{
			//viewData("");
			this.getAlert("alert_error");
		}
	}
	else if (mode == "update") {

// if(this.checkValidate() == true){
int count12 = 0;
String a ={};
String Output =“”;
while(count12 < txtQuan.getValue().toString().length()){
// System.out.println(txtQuan.getValue().toString());
a = txtQuan.getValue().toString().split(“,”);
count12++;
}
for(int i =0;i<a.length;i++){
Output = Output + a[i]
;
}
PurCls.setPoqty(new Integer(“” + Output));
PurCls.setRemark_item(txtRemarkItem.getValue().toString());
// PurAct.getPrice();
// PurAct.selectPO_id();

// getprice = this.getpriceval();
// chkprice = this.chktotalprice();
//// System.out.println("GETVVALUES_before : “+chkprice+” "+getprice);
// getprice = getprice.multiply(new BigDecimal(PurCls.getPoqty()));
// chkprice = chkprice.add(getprice);
// credit = this.getcredit();
// System.out.println("GETVVALUES_after : “+chkprice+” “+credit+” "+getprice);
// int val = chkprice.compareTo(credit);
// System.out.println(val);
// if(val==-1){
//////////Check Quota///////////
// chktotalPro = getTotalQty();
// chktotalPro += PurCls.getPoqty();
// chkquotaPro = getProQuota();
// System.out.println("CheckQuota : “+chktotalPro+” “+chkquotaPro);
///////////////////////////////
boolean chk = true;
DatePO = this.getDatePO();
// System.out.println(DatePO+” "+dateFormat.format(date));
// if(chkquotaPro==0){

					if(DatePO.equals(dateFormat.format(date))){
						chk = PurAct.updateData();
					}else{
						DmsApplication.getInstance().getMainWindow().showNotification(this.getMenuLabel2("lb_chk_date"));
						//cound't insert po# is older than date of insert
					}

// }else{
// if(chkquotaPro<chktotalPro){
// Lock();
// }else{
// if(DatePO.equals(dateFormat.format(date))){
// chk = PurAct.updateData();
// }else{
// DmsApplication.getInstance().getMainWindow().showNotification(this.getMenuLabel2(“lb_chk_date”));
// //cound’t insert po# is older than date of insert
// }
// }
// }
// System.out.println(chk);
if(chk == false) {
viewData(" WHERE order_items.order_id = ‘“+ PurCls.getPO_id()+”’ ");
this.getAlert(“alert_save”);
}

// }else{
// Lock();
// }
}
// }
}

private void Lock() {
	// TODO Auto-generated method stub
	 
	 Button ok;
	 Button cancel;
	 sublock = new Window(this.getMenuLabel2("lb_lock_sub"));
	 sublock.center();
	 sublock.getContent().setSizeUndefined();
	 sublock.setResizable(false);
	 sublock.setModal(true);
	 sublock.setDraggable(false);
     sublock.setClosable(false);
	txtUsr = new TextField();
	txtUsr.isRequired();
	txtPwd = new PasswordField();
	txtPwd.isRequired();
    ok = new Button("",this,"Unlock");
    cancel = new Button();
    cancel.addListener(new ClickListener() {
		
		public void buttonClick(ClickEvent event) {
			// TODO Auto-generated method stub
			sublock.getParent().removeWindow(sublock);
		}
	});
    
    HorizontalLayout horlay = new HorizontalLayout();
    horlay.setMargin(false);
    horlay.setSpacing(true);
    horlay.addComponent(ok);
    horlay.addComponent(cancel);
    
    FormLayout frm = new FormLayout();
    frm.setMargin(true);
    frm.setSpacing(true);
    frm.addComponent(txtUsr); 
    frm.addComponent(txtPwd);  
    frm.addComponent(horlay);
    
    
    txtUsr.setCaption(this.getMenuLabel2("lb_user_owner"));
	txtPwd.setCaption(this.getMenuLabel2("lb_pass_owner"));
    ok.setCaption(this.getMenuLabel2("lb_unlock"));
    cancel.setCaption(this.getMenuLabel2("lb_unlock_cancel"));

    VerticalLayout layout = (VerticalLayout) sublock.getContent();
    layout.setMargin(true);
    layout.setSpacing(false);
    layout.addComponent(frm);  
    
    DmsApplication.getInstance().getMainWindow().addWindow(sublock); 
}

public void Unlock(){
	DB db = new DB();
	db.dbConnect();
	final String sql = "SELECT\n" +
			"users.login_name,\n" +
			"users.`password`\n" +
			"FROM\n" +
			"users\n" +
			"WHERE\n" +
			"users.dealer_id = '"+ DealerID +"' AND users.user_group_id = '4'";

// System.out.println("Login : "+sql);
ResultSet rs = null;
try {
rs = db.getResult(sql);
while (rs.next()) {
if(txtUsr.getValue().toString().equals(rs.getString(“login_name”)) && txtPwd.getValue().toString().equals(rs.getString(“password”))){
sublock.getParent().removeWindow(sublock);
}else{
if(rs.last()==true){
DmsApplication.getInstance().getMainWindow().showNotification(this.getMenuLabel2(“lb_unlock_alert”));
}
}
}
db.rsClose();
db.connClose();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void chkApprove() {
int count=0;
DB db = new DB();
db.dbConnect();	
	String sql1 ="SELECT "+
			"order_items.po_qty,"+
			"products.unit_price, "+
			"order_items.status_id "+
			"FROM products "+
			"RIGHT JOIN order_items ON products.product_id = order_items.product_id "+
			"LEFT JOIN patterns ON patterns.pattern_id = order_items.pattern_id "+
			"LEFT JOIN categories ON categories.category_id = products.category_id "+
			"WHERE order_items.order_id = '"+PurCls.getOrder_id()+"' ";
	ResultSet rs = db.getResult(sql1);

// System.out.println(“sql1 : >>>>>>”+sql1);
try {

				while(rs.next()){
					count++;
					PurCls.setPoqty(rs.getInt("po_qty"));
					PurCls.setPoprice(rs.getInt("unit_price"));
					PurCls.setChkStat(rs.getInt("status_id"));
					
					if(PurCls.getChkStat()==3){
						chkApprove++;
					}else if(PurCls.getChkStat()==4){
						chkPartial++;
					}
					
				}
				if(chkPartial==0&&chkApprove==0){
					btnAdd.setEnabled(true);
				}else{
				if(chkPartial<1){
					btnAdd.setEnabled(false);
				}else{
					btnAdd.setEnabled(true);
				}
				}
				
				if(count==chkApprove){
					DB conn = new DB();
					conn.dbConnect();
					
					String sql = "UPDATE orders SET " +
							" `current_status` = '3' " +
							" WHERE order_id = '" + PurCls.getPO_id() + "'";
					conn.executeSQL(sql);

// System.out.println("UPDATE orders status` = ‘3’ >>>>> " +sql);
try {
conn.dbClose();
this.getAlert(“alert_save”);

					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				
				db.dbClose();
			} catch (SQLException e) {
				e.printStackTrace();
			}	
			
			
}



public void btnApp(ClickEvent event) {

//
//
// System.out.println(“arrID2arrID2arrID2111”+arrID2);
// System.out.println(“txtApp.getValue().toString()1111”+arrValue2);
int status = 0;

if(arrID.size()<1){

for(int i = 0; i<arrID2.size();i++){
		
	DB db = new DB();
	db.dbConnect();	
		String sql1 ="SELECT "+
				"order_items.po_qty,"+
				"products.unit_price, "+
				"order_items.app_qty "+
				"FROM products "+
				"RIGHT JOIN order_items ON products.product_id = order_items.product_id "+
				"LEFT JOIN patterns ON patterns.pattern_id = order_items.pattern_id "+
				"LEFT JOIN categories ON categories.category_id = products.category_id "+
				"WHERE order_items.order_id = '"+PurCls.getOrder_id()+"' AND order_items.item_no = '"+arrID2.get(i)+"'";
		ResultSet rs = db.getResult(sql1);
				System.out.println("sql1 : 11111111111111>>>>>>"+sql1);
				try {				
					
					if(rs.next()){
						PurCls.setPoqty(rs.getInt("po_qty"));
						PurCls.setPoprice(rs.getInt("unit_price"));
						PurCls.setAppqty(rs.getInt("app_qty"));
						System.out.println("arrValue.get(i).toString() "+arrValue2.get(i).toString());
						if(rs.getInt("po_qty")==Integer.parseInt(arrValue2.get(i).toString())){
							status = 3;
						}else{
							status = 4;
						}
						
					}
					db.dbClose();
				} catch (SQLException e) {
					e.printStackTrace();
				}		
		
				
		DB conn = new DB();
		conn.dbConnect();
		
		String sql = "UPDATE order_items SET " +
				" status_id = '"+status+"'"+
				",app_unit_price = '" + PurCls.getPoprice()+ "'" +
				",app_qty = '"+arrValue2.get(i)+"' " +
				" WHERE item_no = '" + arrID2.get(i)+ "' AND (status_id = '4' OR status_id IS NULL)";
		conn.executeSQL(sql);

// System.out.println(“UPDATE order_items SET 11111111111111>>>>> " +sql);
try {
conn.dbClose();
this.getAlert(“alert_save”);
viewData(” WHERE order_items.order_id = ‘“+ PurCls.getPO_id()+”’ ");
} catch (SQLException e) {
e.printStackTrace();
}
}

}else{

for(int i = 0; i<arrID2.size();i++){
	
	DB db = new DB();
	db.dbConnect();	
		String sql1 ="SELECT "+
				"order_items.po_qty,"+
				"products.unit_price, "+
				"order_items.app_qty "+
				"FROM products "+
				"RIGHT JOIN order_items ON products.product_id = order_items.product_id "+
				"LEFT JOIN patterns ON patterns.pattern_id = order_items.pattern_id "+
				"LEFT JOIN categories ON categories.category_id = products.category_id "+
				"WHERE order_items.order_id = '"+PurCls.getOrder_id()+"' AND order_items.item_no = '"+arrID2.get(i)+"'";
		ResultSet rs = db.getResult(sql1);
				System.out.println("sql1 BBBBBBBBBBBBBB: >>>>>>"+sql1);
				try {				
					
					if(rs.next()){
						PurCls.setPoqty(rs.getInt("po_qty"));
						PurCls.setPoprice(rs.getInt("unit_price"));
						PurCls.setAppqty(rs.getInt("app_qty"));
						System.out.println("arrValue.get(i).toString() "+arrValue2.get(i).toString());
						if(rs.getInt("po_qty")==Integer.parseInt(arrValue2.get(i).toString())){
							status = 3;
						}else{
							status = 4;
						}
						
					}
					db.dbClose();
				} catch (SQLException e) {
					e.printStackTrace();
				}		
		
				
		DB conn = new DB();
		conn.dbConnect();

		String sql = "UPDATE order_items SET " +
				" status_id = '"+status+"'"+
				",app_unit_price = '" + PurCls.getPoprice()+ "'" +
				",app_qty = '"+arrValue2.get(i)+"' " +
				" WHERE item_no = '" + arrID2.get(i)+ "' AND (status_id = '4' OR status_id IS NULL)";
		conn.executeSQL(sql);

// System.out.println(“UPDATE order_items SET BBBBBBBBBBBBBBB>>>>> " +sql);
try {
conn.dbClose();
this.getAlert(“alert_save”);
viewData(” WHERE order_items.order_id = ‘“+ PurCls.getPO_id()+”’ ");
} catch (SQLException e) {
e.printStackTrace();
}

}

/////////////////////////////////////////////////////////////////
System.out.println("arrID.size() "+arrID);
System.out.println("arrID.arrValue() "+arrValue);
for(int i = 0; i<arrID.size();i++){

	DB db = new DB();
	db.dbConnect();	
		String sql1 ="SELECT "+
				"order_items.po_qty,"+
				"products.unit_price, "+
				"order_items.app_qty "+
				"FROM products "+
				"RIGHT JOIN order_items ON products.product_id = order_items.product_id "+
				"LEFT JOIN patterns ON patterns.pattern_id = order_items.pattern_id "+
				"LEFT JOIN categories ON categories.category_id = products.category_id "+
				"WHERE order_items.order_id = '"+PurCls.getOrder_id()+"' AND order_items.item_no = '"+arrID.get(i)+"'";
		ResultSet rs = db.getResult(sql1);
				System.out.println("sql1 CCCCCCCCCCC : >>>>>>"+sql1);
				try {				
					
					if(rs.next()){
						PurCls.setPoqty(rs.getInt("po_qty"));
						PurCls.setPoprice(rs.getInt("unit_price"));
						PurCls.setAppqty(rs.getInt("app_qty"));
						System.out.println("arrValue.get(i).toString() "+arrValue.get(i).toString());
						if(rs.getInt("po_qty")==Integer.parseInt(arrValue.get(i).toString())){
							status = 3;
						}else{
							status = 4;
						}
						
					}
					db.dbClose();
				} catch (SQLException e) {
					e.printStackTrace();
				}		
		
				
		DB conn = new DB();
		conn.dbConnect();
		int a = ((Number)PurCls.getAppqty()).intValue();
		int b = ((Number)arrValue.get(i)).intValue();
		System.out.println("a2  "+a+" arrValue2.get(i)"+arrValue.get(i));
		if(a==0){
			PurCls.setSumQty(b);
			System.out.println("AA2 : " +PurCls.getSumQty());
		}else if(PurCls.getPoqty()==PurCls.getAppqty()){
			PurCls.setSumQty(b);
			System.out.println("BB2 : " +PurCls.getSumQty());
		}else{
			int c = a+b;
			PurCls.setSumQty(c);
			System.out.println("CC2 : " +PurCls.getSumQty());
		}
		
		String sql = "UPDATE order_items SET " +
				" status_id = '"+status+"'"+
				",app_unit_price = '" + PurCls.getPoprice()+ "'" +

// “,app_qty = '”+arrValue.get(i)+“’ " +
“,app_qty = '”+PurCls.getSumQty()+”’ " +
" WHERE item_no = ‘" + arrID.get(i)+ "’“;
conn.executeSQL(sql);
// System.out.println(“UPDATE order_items SET CCCCCCCCCCCC>>>>> " +sql);
try {
conn.dbClose();
this.getAlert(“alert_save”);
viewData(” WHERE order_items.order_id = '”+ PurCls.getPO_id()+"’ ");
} catch (SQLException e) {
e.printStackTrace();
}

		/////////////////////////////////////////
		
		
		DB conChk = new DB();
		conChk.dbConnect();
		
		String sqlChk = "UPDATE order_items SET " +
		" status_id = '3' "+
		" WHERE item_no = '" + arrID.get(i)+ "' AND po_qty=app_qty";
		conChk.executeSQL(sqlChk);
		try {
		conChk.dbClose();

// viewData(" WHERE order_items.order_id = ‘“+ PurCls.getPO_id()+”’ ");
} catch (SQLException e) {
e.printStackTrace();
}

}

}
chkApprove();
SendMail2();
}

public void btnUpdate(ClickEvent event) {	
	if(txtRemarkPO.getValue().toString()!=""){
		DB conn = new DB();
		conn.dbConnect();
		
		String sql = "UPDATE orders SET " +
				" remark = '"+txtRemarkPO.getValue().toString()+"'"+
				" WHERE order_id = '" + PurCls.getPO_id() + "'" ;
		conn.executeSQL(sql);

// System.out.println(">>>>> " +sql);
try {
conn.dbClose();
this.getAlert(“alert_save”);

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}else{
		this.getAlert("alert_valid_data");
	}
}

@Override
public Object getForm() {
	// TODO Auto-generated method stub
	return mainLay;
}

@Override
public boolean checkValidate() {
	if(selCat.getValue()== null) return false;
	if(selPro.getValue()== null) return false;
	if(selPat.getValue()== null) return false;
	if(txtQuan.getValue().equals("")) return false;
	return true;
}

@Override
protected String getLabel(int index) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public void setMode(String str) {
	mode = str;
	if(mode.equals("add")) 
	{
		btnNew.setVisible(true);
		btnSubmit.setVisible(true);

	} else if(mode.equals("update")) {
		btnNew.setVisible(true);
		btnSubmit.setVisible(true);
		btnNew.setVisible(true);
	}	
}
public void selectCat(){
	DB db = new DB();
	db.dbConnect();		
	this.selCat.removeAllItems();
	try {
		String sql = "SELECT * FROM categories WHERE categories.`status` = '1' order by CONVERT (categories.description USING tis620)";
		ResultSet rs =  db.getResult(sql);
		
		while(rs.next()){
			this.selCat.addItem(rs.getInt("category_id"));
			this.selCat.setItemCaption(rs.getInt("category_id"),rs.getString("description").trim());
			this.selCat.setImmediate(true);
		}
		rs.close();
		db.dbClose();
	} catch (SQLException e) {
		e.printStackTrace();
	}

}


public void setFieldID(String fieldTBL) { this.fieldTbl = fieldTBL; } //set field name
public void setTableName(String nameTBL) { this.nameTbl = nameTBL; } //set table name
public void setWhereCon(String whereCon) { this.whereCon = whereCon; } //set where condition

protected String getFieldID() { return this.fieldTbl; }
protected String getTableName() { return this.nameTbl;}
protected String getWhereCon() { return this.whereCon; }

public String SaleRunningNo(){
	String docRunNo = "";
	try {
	DB db = new DB();
	db.dbConnect();

	String sql = "SELECT COUNT(" + this.getFieldID() + ") AS numrows FROM " + this.getTableName() +" ";

	sql = (this.getWhereCon().equals("")) ? sql : sql + " " + this.getWhereCon();

	ResultSet rs = db.getResult(sql);

	if(rs.next()){
	numCount = Integer.parseInt(rs.getString("numrows"))+1;
	}

	} catch (SQLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	}
	
	docRunNo = ""+numCount;
	
	return docRunNo;
}

public String saleRunning() {
	Locale currentLocale = new Locale("en","US");
	// final DateFormat dateFormat = new SimpleDateFormat("-yyyy-MM-dd",currentLocale);
	// final Date Tempdate = new Date();

	final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",currentLocale);
	final Date Tempdate = new Date();
	

	int year = Tempdate.getYear()+1900;
	int month = Tempdate.getMonth()+1;
	
	String whereCon = "WHERE YEAR(datetime) = ('"+year+"') AND dealer_id = '" + DealerID +"'"; 

	this.setFieldID("id");
	this.setTableName("po_running");
	this.setWhereCon(whereCon);
	String number ="";
	number = this.SaleRunningNo();
	return number;
	}

public PurchaseOrderForm POfrm(){
	return this;
}

public void cur_status(){
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT "+
						"`status`.description, "+
						"`status`.status_id "+
						"FROM "+
						"`status` "+
						"RIGHT JOIN orders ON `status`.status_id = orders.current_status "+
						"WHERE orders.order_id = '"+ PurCls.getPO_id() +"'";
		ResultSet rs =  db.getResult(sql);

// System.out.println("))>>> "+sql);
if(rs.next()){
PurCls.setCur_status(rs.getInt(“status_id”));
selStatus.setEnabled(true);
selStatus.select(rs.getInt(“status_id”));
// this.txtStatus.setReadOnly(false);
// this.txtStatus.setValue(rs.getString(“description”));
// this.txtStatus.setReadOnly(true);
}
rs.close();
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}
}
public boolean checkDup() {

	String whereCon = "WHERE order_items.order_id = '"+PurCls.getPO_id()+"' AND order_items.product_id = '" + Integer.parseInt(this.selPro.getValue().toString()) + "' AND order_items.pattern_id = '"+ Integer.parseInt(this.selPat.getValue().toString()) + "'";

// if (mode.equals(“update”)) {
// whereCon = whereCon + “AND " + this.PurCls.getIdField() + " <> '”
// + this.UGCls.getUserGroupId() + “'”;
// }

	this.tmsInsert.setFieldID("order_id");
	this.tmsInsert.setTableName("order_items");
	this.tmsInsert.setWhereCon(whereCon);

	if (this.tmsInsert.checkInsertDuplicate() == false) {
		return false;
	} else
		return true;
}

private void setNextAlert() {
	String Expire ="";
	Locale currenntLocale = new Locale("en","us");
	final DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy",currenntLocale);
	Date d = new Date();
	
	DB db = new DB();
	db.dbConnect();
	try{
		String sql = "SELECT * FROM parameters WHERE id = '1'";
		ResultSet rs = db.getResult(sql);
		if(rs.next()){
			Expire = rs.getString("value");
		}
		rs.close();
		db.dbClose();
	} catch (SQLException e) {
		e.printStackTrace();
	}
	
	Calendar NextDate = Calendar.getInstance();
	NextDate.setTime(d);
	NextDate.add(Calendar.DATE,Integer.parseInt(Expire));
	String dd = dateFormat.format(NextDate.getTime());

// System.out.println(“=>”+dd);
PurCls.setExpDate(dd);

	}
public void chkGroup(){
	if (usrgroup == 3){
		btnNew.setVisible(false);
		btnSubmit.setVisible(false);
		btnDelPO.setVisible(false);
		btnDel.setVisible(false);
		selCat.setEnabled(false);
		txtQuan.setReadOnly(true);
		
		btnAdd = new Button("Approved",this,"btnApp");
		
		
		}
	else if (usrgroup == 5){
		btnNew.setVisible(true);
		btnAdd.setEnabled(true);
		}
		else {
			
			btnNew.setVisible(false);
			btnSubmit.setVisible(false);
			btnDelPO.setVisible(false);
			btnDel.setVisible(false);
			btnAdd.setVisible(false);
			txtQuan.setEnabled(false);
			selCat.setEnabled(false);
			selPro.setEnabled(false);
			selPat.setEnabled(false);
			}			
	
}
public void runningSubmit(){
	
	Locale currenntLocale = new Locale("en","us");
	final DateFormat dateFormat = new SimpleDateFormat("MMyyyy",currenntLocale);
	final String num = submitRunning();
	final Date Tempdate = new Date();
	

	PurCls.setTCEPO("Online"+"-"+dateFormat.format(Tempdate.getTime())+"-"+num);
	PurAct.insertTCERunningNo();
	if (usrgroup == 3){
		viewLeftData("WHERE sales.sale_id = '"+usrLog+"'");
	}
	else if(usrgroup == 4){
		viewLeftData("WHERE dealers.dealer_id = '"+DealerID+"' AND orders.current_status = '2'");
	}
	else{
		if ( DealerID == 0 ){
			viewLeftData("");
		}else{
		viewLeftData("WHERE dealers.dealer_id = '"+DealerID+"'");
		}
	}
}

public String submitRunning() {
	Locale currentLocale = new Locale("en","US");
	// final DateFormat dateFormat = new SimpleDateFormat("-yyyy-MM-dd",currentLocale);
	// final Date Tempdate = new Date();

	final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",currentLocale);
	final Date Tempdate = new Date();
	

	int year = Tempdate.getYear()+1900;

	
	String whereCon = "WHERE YEAR(datetime) = ('"+year+"')"; 

	this.setFieldID("id");
	this.setTableName("tce_running");
	this.setWhereCon(whereCon);
	String number ="";
	number = this.SaleRunningNo();
	return number;
	}

public void PO_EXP(){
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT * FROM orders  WHERE order_id = '"+PurCls.getOrder_id()+ "'";			
		ResultSet rs =  db.getResult(sql);

		if(rs.next()){
			txtPO.setReadOnly(false);
        	txtPO.setValue(rs.getString("dealer_order_no"));
        	PO_NUMBER = rs.getString("dealer_order_no");
        	txtPO.setReadOnly(true);
        	txtExp.setReadOnly(false);
        	txtExp.setValue(rs.getString("expire_date"));
        	txtExp.setReadOnly(true);
        	
        	if(rs.getString("remark")==null){
        		txtRemarkPO.setValue("");
        	}else{
        		txtRemarkPO.setValue(rs.getString("remark"));
        	}
		}
		rs.close();
		db.dbClose();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}

private BigDecimal getpriceval() {
	// TODO Auto-generated method stub
	BigDecimal chk = null;
	
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT\n" +
				"products.unit_price\n" +
				"FROM\n" +
				"products\n" +
				"WHERE products.product_id = '"+PurCls.getProduct_id()+"'";

		ResultSet rs =  db.getResult(sql);

// System.out.println("getpricevalue))>>> "+sql);
if(rs.next()){
if(rs.getBigDecimal(“unit_price”)==null){
chk = new BigDecimal(0);
}else{
chk = new BigDecimal(rs.getInt(“unit_price”));
}
}else{
chk = new BigDecimal(0);
}
rs.close();
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}
return chk;
}

public BigDecimal chktotalprice(){
	Locale currentLocale = new Locale("en","US");
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",currentLocale);
	Date date = new Date();
	
	BigDecimal chk = null;
	
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT DISTINCT\n" +
				"IF((\n" +
				"SELECT\n" +
				"SUM(po_unit_price*po_qty) AS total\n" +
				"FROM\n" +
				"order_items\n" +
				"LEFT JOIN orders ON orders.order_id = order_items.order_id\n" +
				"WHERE orders.created_user = '"+usr+"' AND orders.created_datetime LIKE '%"+dateFormat.format(date)+"%'\n" +
				")<>NULL,'0',(\n" +
				"SELECT\n" +
				"SUM(po_unit_price*po_qty) AS total\n" +
				"FROM\n" +
				"order_items\n" +
				"LEFT JOIN orders ON orders.order_id = order_items.order_id\n" +
				"WHERE orders.created_user = '"+usr+"' AND orders.created_datetime LIKE '%"+dateFormat.format(date)+"%'\n" +
				")) AS result\n" +
				"FROM\n" +
				"order_items";

		ResultSet rs =  db.getResult(sql);

// System.out.println("chktotalprice))>>> "+sql);
if(rs.next()){
if(rs.getBigDecimal(“result”)==null){
chk = new BigDecimal(0);
}else{
chk = new BigDecimal(rs.getInt(“result”));
}
}
rs.close();
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}
return chk;
}

public BigDecimal getcredit(){
	
	
	BigDecimal creditchk = null;
	
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT\n" +
						"IF(purchasers.credit<>'' OR purchasers.credit<>NULL,purchasers.credit,0) AS credit\n" +
						"FROM\n" +
						"purchasers\n" +
						"WHERE\n" +
						"purchasers.purchaser_id = '"+usrLog+"'";
		ResultSet rs =  db.getResult(sql);

// System.out.println("getcredit))>>> "+sql);
if(rs.next()){

				creditchk = new BigDecimal(rs.getInt("credit"));
			

		}else{
				creditchk = new BigDecimal(0);
		}
		rs.close();
		db.dbClose();
	} catch (SQLException e) {
		e.printStackTrace();
	}
	return creditchk;
}

public int getTotalQty(){
	Locale currentLocale = new Locale("en","US");
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",currentLocale);
	Date date = new Date();
	
	int chk = 0;
	
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT\n" +
				"SUM(order_items.po_qty) AS totalPro\n" +
				"FROM\n" +
				"order_items\n" +
				"LEFT JOIN orders ON orders.order_id = order_items.order_id\n" +
				"WHERE order_items.product_id = '"+PurCls.getProduct_id()+"' AND orders.created_user = '"+usr+"' AND orders.created_datetime LIKE '%"+dateFormat.format(date)+"%'";

		ResultSet rs =  db.getResult(sql);

// System.out.println("getTotalQty))>>> "+sql);
if(rs.next()){
chk = rs.getInt(“totalPro”);
}else{
chk = 0;
}
rs.close();
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}

	return chk;
}

public int getProQuota(){
	
	int chk = 0;
	
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT\n" +
				"quota.quantity\n" +
				"FROM\n" +
				"quota\n" +
				"WHERE quota.dealer_id = '"+DealerID+"' AND quota.product_id = '"+PurCls.getProduct_id()+"' AND quota.`status` = '1'";
		
		ResultSet rs =  db.getResult(sql);

// System.out.println("getProQaota))>>> "+sql);
if(rs.next()){
chk = rs.getInt(“quantity”);
}else{
chk = 0;
}
rs.close();
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}

	return chk;
}

private String getDatePO() {
	// TODO Auto-generated method stub
	Locale currentLocale = new Locale("en","US");
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",currentLocale);
	
	String chkPO = "";
	
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT\n" +
				"orders.created_datetime\n" +
				"FROM\n" +
				"orders\n" +
				"WHERE orders.order_id = '"+ PurCls.getPO_id() +"'";
		ResultSet rs =  db.getResult(sql);

// System.out.println("getDatePO))>>> "+sql);
if(rs.next()){
chkPO = dateFormat.format(rs.getDate(“created_datetime”).getTime());
}
rs.close();
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}

	return chkPO;
}

public void getProANDPatt(String Cat_id){
	subwinCat = new Window();
	subwinCat.center();
	subwinCat.getContent().setSizeUndefined();
	subwinCat.setResizable(false);
	subwinCat.setModal(true);
	subwinCat.setDraggable(false);   	
	subwinCat.setStyleName(Reindeer.WINDOW_LIGHT);
	
	Label LPro = new Label(this.getMenuLabel2("Product_menu"));
	Label LPatt = new Label(this.getMenuLabel2("lb_Pat"));
	
	FormLayout frm = new FormLayout();
    frm.setMargin(true);
    frm.setSpacing(true);
    //ใส่ Table
    frm.addComponent(LPro);       
    frm.addComponent(tblPro);
    frm.addComponent(LPatt);
    frm.addComponent(tblPatt);

    
    VerticalLayout layout = (VerticalLayout) subwinCat.getContent();
    layout.setMargin(true);
    layout.setSpacing(false);
    layout.addComponent(frm); 
    
    getProTable(Cat_id);
    DmsApplication.getInstance().getMainWindow().addWindow(subwinCat);
    
}

public void getProTable(String id){
	int i =0;
	ArrayList<Object> rs = PurAct.getProductTable(id);
	if(rs.size() != 0) {
		tblPro.removeAllItems();
		
		
		final DecimalFormat df = new DecimalFormat( "#,###,###,##0.00" );
		final DecimalFormat df2 = new DecimalFormat( "#,###,###,##0" );
        IndexedContainer container1 = new IndexedContainer();
        
        String name_c = this.getMenuLabel2("code");
        String name_lb = this.getMenuLabel2("Product_name_lb");
        String unit = this.getMenuLabel2("Product_unit_lb");
        String unit_price = this.getMenuLabel2("Product_price_lb");
        String unit_pack = this.getMenuLabel2("Product_package_lb");
        
        container1.addContainerProperty("ID", String.class, "");
        container1.addContainerProperty(name_c, String.class, "");	
        container1.addContainerProperty(name_lb, String.class, "");	
        container1.addContainerProperty(unit, String.class, "");
        container1.addContainerProperty(unit_price, String.class, "");
        container1.addContainerProperty(unit_pack, String.class, "");
		
        for (Object obj : rs ){
        	PurchaseOrderClass data = (PurchaseOrderClass)obj;
            Item item = container1.addItem(data);
            
            item.getItemProperty("ID").setValue(data.getProduct_id());
            item.getItemProperty(name_c).setValue(data.getModel_code());
            item.getItemProperty(name_lb).setValue(data.getDescription());
            item.getItemProperty(unit).setValue(data.getUnit());
            item.getItemProperty(unit_price).setValue(df.format(data.getPrice()));
            item.getItemProperty(unit_pack).setValue(df2.format(data.getUnitPpack()));
            
            i++;
        }
        tblPro.setContainerDataSource(container1);	
        
        
        tblPatt.removeAllItems();
        IndexedContainer container = new IndexedContainer();
        
        String patt_code = getMenuLabel2("lb_patterns_code");
        String patt_desc = getMenuLabel2("lb_patterns_desc");
        String photo = getMenuLabel2("lb_image");
        String photo2 = getMenuLabel2("lb_image2");
        String Select = getMenuLabel2("lb_select");
        
        container.addContainerProperty(patt_code, String.class, "");	
        container.addContainerProperty(patt_desc, String.class, "");	
        container.addContainerProperty(photo, String.class, "");
        container.addContainerProperty(photo2, String.class, "");
        container.addContainerProperty(Select, Button.class, "");
        tblPatt.setPageLength(0);
        tblPatt.setContainerDataSource(container);
        

        tblPro.setVisible(true);
        tblPro.setEnabled(true);
        if(i>=5){
        	tblPro.setPageLength(5);
        }else{
        	tblPro.setPageLength(i);
        }
		tblPro.setPageLength(i);
        tblPro.setSelectable(true);
		//tblDataTable.setMultiSelect(true);
        tblPro.setImmediate(true);			
		
        tblPro.setColumnReorderingAllowed(true);
        tblPro.setColumnCollapsingAllowed(true);	        

		//tblDataTable.setColumnCollapsed(getLabel(2), true);
        tblPro.setVisibleColumns(new String[] {name_c,name_lb,unit,unit_price,unit_pack});			
		
        
        
        
        tblPro.addListener(new ItemClickListener() {
			public void itemClick(ItemClickEvent event) {
				// TODO Auto-generated method stub
				
				if (event.getButton() == com.vaadin.event.MouseEvents.ClickEvent.BUTTON_LEFT) {
					
		        	String a = event.getItem().toString();
		        	String[] b = a.split(" ");
		        	PurCls.setProduct_id(Integer.parseInt(b[0]

));
selPro.select(Integer.parseInt(b[0]
));
// System.out.println(PurCls.getProduct_id());
// PurAct.getById();

		        	getPattTable(b[1]

);
}
}
});

	} else {
		
		tblPro.removeAllItems();
        IndexedContainer container1 = new IndexedContainer();
        
        String name_c = this.getMenuLabel2("code");
        String name_lb = this.getMenuLabel2("Product_name_lb");
        String unit = this.getMenuLabel2("Product_unit_lb");
        String unit_price = this.getMenuLabel2("Product_price_lb");
        String unit_pack = this.getMenuLabel2("Product_package_lb");
        
       
        container1.addContainerProperty(name_c, String.class, "");	
        container1.addContainerProperty(name_lb, String.class, "");	
        container1.addContainerProperty(unit, String.class, "");
        container1.addContainerProperty(unit_price, String.class, "");
        container1.addContainerProperty(unit_pack, String.class, "");
		
        tblPro.setContainerDataSource(container1);
        tblPro.setPageLength(0);
		rs.clear();
		
		tblPatt.removeAllItems();
        IndexedContainer container = new IndexedContainer();
        
        String patt_code = getMenuLabel2("lb_patterns_code");
        String patt_desc = getMenuLabel2("lb_patterns_desc");
        String photo = getMenuLabel2("lb_image");
        String photo2 = getMenuLabel2("lb_image2");
        String Select = getMenuLabel2("lb_select");
        
        container.addContainerProperty(patt_code, String.class, "");	
        container.addContainerProperty(patt_desc, String.class, "");	
        container.addContainerProperty(photo, String.class, "");
        container.addContainerProperty(photo2, String.class, "");
        container.addContainerProperty(Select, Button.class, "");
        tblPatt.setPageLength(0);
        tblPatt.setContainerDataSource(container);
		this.getAlert("search_not_found");
		
		
	}
}
	
public void  getPattTable(String pro_id){
	tblPatt.removeAllItems();
	int j =0;
	ArrayList<Object> rs2 = PurAct.getPatternTable(pro_id);
	if(rs2.size() != 0) {

        IndexedContainer container = new IndexedContainer();
        
        String patt_code = getMenuLabel2("lb_patterns_code");
        String patt_desc = getMenuLabel2("lb_patterns_desc");
        String photo = getMenuLabel2("lb_image");
        String photo2 = getMenuLabel2("lb_image2");
        String Select = getMenuLabel2("lb_select");
        String photo_path="photo_path";
        
        
        container.addContainerProperty("ID", String.class, "");
        container.addContainerProperty(patt_code, String.class, "");	
        container.addContainerProperty(patt_desc, String.class, "");	

// container.addContainerProperty(photo, String.class, “”);
container.addContainerProperty(photo, Embedded.class, “”);
container.addContainerProperty(photo2, Button.class, “”);
container.addContainerProperty(Select, Button.class, “”);
container.addContainerProperty(photo_path, String.class, “”);

        for (Object obj : rs2 ){
        	final PurchaseOrderClass data2 = (PurchaseOrderClass)obj;
            Item item2 = container.addItem(data2);
            
            final Embedded emPhoto = new Embedded();
            emPhoto.setWidth("100px");
            emPhoto.setHeight("100px");

// Image image = new Image(“”,resource);
// Link link = new Link();
try{

				emPhoto.setSource(new FileResource(new File(data2.getPhoto_path()), DmsApplication.getInstance()));	

//
// emPhoto.addListener(new MouseMotionAdapter(){
//
// public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
// getZoomPicture(emPhoto.getData().toString());
// }
// });
// emPhoto.(new ClickListzener()
// {
// public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
// getZoomPicture(emPhoto.getData().toString());
//
// }
// });
//

            }catch (NullPointerException e) {
				// TODO: handle exception
				emPhoto.setSource(new FileResource(new File(RootPath.getEmptyPhoduct()), DmsApplication.getInstance()));

			}
			
            
        	Object btnID2 = data2.getPhoto_path();
            
            final Button btnView = new Button();

            try{

            FileResource resource = new FileResource(new File(data2.getPhoto_path()),DmsApplication.getInstance());

// resource.setBufferSize();
btnView.setIcon(resource);
// btnView.setIcon(new ThemeResource(“…/Reindeer/Icons/64/61.png”));
// btnView.setSizeUndefined();
// btnView.setSizeFull();
btnView.setStyleName(BaseTheme.BUTTON_LINK);
btnView.setData(btnID2);
btnView.setHeight(“100px”);
btnView.setWidth(“100px”);
btnView.addListener(new ClickListener() {

    			public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {

// System.out.println("btnView.getData().toString() : "+btnView.getData().toString());
getZoomPicture(btnView.getData().toString());

    			}
    		});
            }catch (NullPointerException e) {
            	
            	
            	FileResource resource = new FileResource(new File(RootPath.getEmptyPhoduct()),DmsApplication.getInstance());
            	  btnView.setIcon(resource);

// btnView.setIcon(new ThemeResource(“…/Reindeer/Icons/64/61.png”));
// btnView.setSizeUndefined();
// btnView.setSizeFull();
btnView.setStyleName(BaseTheme.BUTTON_LINK);
btnView.setData(btnID2);
btnView.setHeight(“100px”);
btnView.addListener(new ClickListener() {

  	    			public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {

// System.out.println("btnView.getData().toString() : "+btnView.getData().toString());
getZoomPicture(RootPath.getEmptyPhoduct());

  	    			}
  	    		});
            }
          
            
            
            Object btnID = data2.getPattern_id();
            final Button btnSelect = new Button();
			btnSelect.setIcon(new ThemeResource(iconSelect));
			btnSelect.setStyleName(Reindeer.BUTTON_SMALL);
			btnSelect.setData(btnID);
			btnSelect.setCaption(getMenuLabel2("lb_select"));
			btnSelect.addListener(new ClickListener() {
				
				public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
					//System.out.println(popup.getData());

// System.out.println("BtnSelect : "+btnSelect.getData().toString());
selPat.select(Integer.parseInt(btnSelect.getData().toString()));
(subwinCat.getParent()).removeWindow(subwinCat);
// txtQuan.setVisible(true);
}
});

            item2.getItemProperty("ID").setValue(data2.getPattern_id());
            item2.getItemProperty(patt_code).setValue(data2.getModel_code());
            item2.getItemProperty(patt_desc).setValue(data2.getDescription());

// item2.getItemProperty(photo).setValue(data2.getPhoto_path());
item2.getItemProperty(photo).setValue(emPhoto);
item2.getItemProperty(photo2).setValue(btnView);
item2.getItemProperty(Select).setValue(btnSelect);
item2.getItemProperty(photo_path).setValue(data2.getPhoto_path());

            j++;
        }
        
        
    	
        
        tblPatt.setContainerDataSource(container);

// System.out.println("SetpageLength : "+j);
if(j>=3){
tblPatt.setPageLength(3);
}else{
tblPatt.setPageLength(j);
}

        tblPatt.setSelectable(true);
		//tblDataTable.setMultiSelect(true);
        tblPatt.setImmediate(true);		
        
        tblPatt.setColumnReorderingAllowed(true);
        tblPatt.setColumnCollapsingAllowed(true);	
        
        tblPatt.setColumnAlignment(photo, Table.ALIGN_CENTER);
        tblPatt.setColumnAlignment(photo2, Table.ALIGN_CENTER);
        tblPatt.setColumnAlignment(Select, Table.ALIGN_CENTER);
        tblPatt.setVisibleColumns(new String[] {patt_code,patt_desc,photo,photo2,Select});
        
	}else{
		tblPatt.removeAllItems();
        IndexedContainer container = new IndexedContainer();
        
        String patt_code = getMenuLabel2("lb_patterns_code");
        String patt_desc = getMenuLabel2("lb_patterns_desc");
        String photo = getMenuLabel2("lb_image");
        String photo2 = getMenuLabel2("lb_image2");
        String Select = getMenuLabel2("lb_select");
        
        container.addContainerProperty(patt_code, String.class, "");	
        container.addContainerProperty(patt_desc, String.class, "");	
        container.addContainerProperty(photo, String.class, "");
        container.addContainerProperty(photo2, String.class, "");
        container.addContainerProperty(Select, Button.class, "");
        tblPatt.setPageLength(0);
        tblPatt.setContainerDataSource(container);
		
		DmsApplication.getInstance().getMainWindow().showNotification("Data not found !!", Notification.TYPE_WARNING_MESSAGE);
	}
	

}

public void getZoomPicture(String photo_path){
	subwinZoom = new Window();
	subwinZoom.center();
	subwinZoom.getContent().setSizeUndefined();
	subwinZoom.setResizable(false);
	subwinZoom.setModal(true);
	subwinZoom.setDraggable(false);   	
	subwinZoom.setStyleName(Reindeer.WINDOW_LIGHT);
	
	FormLayout frm = new FormLayout();
    frm.setMargin(true);
    frm.setSpacing(false);
    
    final Embedded emPhoto = new Embedded();
    emPhoto.setWidth("500px");
    emPhoto.setHeight("500px");
   
	emPhoto.setSource(new FileResource(new File(photo_path), DmsApplication.getInstance()));
	
    frm.addComponent(emPhoto);
    VerticalLayout layout = (VerticalLayout) subwinZoom.getContent();
    layout.setMargin(false);
    layout.setSpacing(false);
    layout.addComponent(frm); 
    DmsApplication.getInstance().getMainWindow().addWindow(subwinZoom);
}

public void SendMail(){
	getMailAddress();

// System.out.println(email.size());
for(String a : email){
Properties props = new Properties();
props.setProperty(“mail.smtp.starttls.enable”, “true”);
// props.put(“mail.smtp.starttls.enable”, “true”);
props.put(“mail.smtp.host” , “smtp.gmail.com”);
// props.put(“mail.smtp.socketFactory.port”, “” + 587);
// props.put(“mail.smtp.socketFactory.class”, “javax.net.ssl.SSLsocketFactory”);
props.put(“mail.smtp.auth”, “true”);
props.put(“mail.smtp.port”, “” + 587);

			   Session session  = Session.getDefaultInstance( props , 
					   new javax.mail.Authenticator() {
				   		protected PasswordAuthentication getPasswordAuthentication() {
							return new PasswordAuthentication("admin@hnum.mygbiz.com", "tconnet1234");
						}
			   			}
					   
					   );
			 try{

// System.out.println(session+" “+EmailPur+” “+a);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(EmailPur));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(a));
message.setSubject(this.getMenuLabel2(“mail_header”));
message.setText(this.getMenuLabel2(“mail_context”)+” “+PO_NUMBER+” "+this.getMenuLabel2(“mail_context_con”));
Transport.send(message);

			 }catch(MessagingException e){

// System.out.println(e);
DmsApplication.getInstance().getMainWindow().showNotification(this.getMenuLabel2(“lb_fail_email”));
}
}
}
public void SendMail2(){
getMailSmtp();

final String username = PurCls.getUsername();
final String password = PurCls.getPassword();

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");

// props.put(“mail.smtp.host”, “smtp.gmail.com”);
props.put(“mail.smtp.host”, PurCls.getHost());
props.put(“mail.smtp.port”, PurCls.getPort());

Session session = Session.getInstance(props,
  new javax.mail.Authenticator() {
	protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication(username, password);
	}
  });

try {

	Message message = new MimeMessage(session);
	message.setFrom(new InternetAddress(PurCls.getUsername()));
	message.setRecipients(Message.RecipientType.TO,
		InternetAddress.parse(emailAddress));

// System.out.println(“emailAddress >”+emailAddress);
message.setSubject(“Testing Subject”);
message.setText(“Testing Message”);

	Transport.send(message);

// System.out.println(“Done”);

} catch (MessagingException e) {
	throw new RuntimeException(e);
}
}
public void getMailSmtp(){
	
	DB db = new DB();
	db.dbConnect();			
	try {
		String sql = "SELECT\n" +
				"*\n" +
				"FROM\n" +
				"config_system_email\n" +
				"INNER JOIN config_sent_email ON config_system_email.email_group = config_sent_email.email_group_id\n" +
				"INNER JOIN users ON config_sent_email.user_id = users.user_id\n" +
				"WHERE config_system_email.`status` = '1'";
		
		ResultSet rs =  db.getResult(sql);

System.out.println("getMailSmtp > "+sql);
while(rs.next()){

			PurCls.setUsername(rs.getString("email"));
			PurCls.setPassword(rs.getString("password"));
			PurCls.setHost(rs.getString("smtp_host_id"));
			PurCls.setPort(rs.getString("smtp_port_id"));
			PurCls.setEmailAdd(rs.getString("email_address"));

			emailAddress+=rs.getString("email_address")+",";
		}
		
		System.out.println(PurCls.getUsername()+" "+PurCls.getPassword()+" "+PurCls.getHost()+" "+PurCls.getPort());
		rs.close();
		db.dbClose();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}

private void getMailAddress() {
	email = new ArrayList<String>();

// email.clear();
DB db = new DB();
db.dbConnect();
try {
String sql = “SELECT\n” +
“users.email_address\n” +
“FROM\n” +
“users\n” +
“WHERE user_group_id = ‘3’ OR ( dealer_id = '”+DealerID+“’ AND user_group_id = ‘4’ )”;

		ResultSet rs =  db.getResult(sql);

// System.out.println("getMail))>>> "+sql);
while(rs.next()){
if(rs.getString(“email_address”).length()>0){
email.add(rs.getString(“email_address”));
}
}
rs.close();
db.dbClose();
} catch (SQLException e) {
e.printStackTrace();
}
}

}
12993.png

below has some attach preview image

Absolutely nobody read your listing because it’s too long.
I just read your question ad see the attachment.
I suggest you use
Image
component instead of
Button

thank you i will try my best

You could use css:

background-image: url(…/yourimage.jpg);
background-repeat: no-repeat
background-size: cover;

you could also use background-size: 100% 100%; which causes the image to get stretched.


Refer to this.

thank Marius Reinwald very much . now i use

tr.v-table-row .v-icon {max-width: 100%;}

because button in table only set css

this is my solution

very thanks again Marius Reinwald and Ebrahim Pasbani …