/**
 * 进货单操作控制类
 * StockinAction.java
 * Copyright (C) 2010 SLMS
 * Simple Logistics Management System
 * 
 */
package com.zds.slms.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.zds.slms.domain.Client;
import com.zds.slms.domain.Employee;
import com.zds.slms.domain.Merchandise;
import com.zds.slms.domain.Stockin;
import com.zds.slms.service.IClientService;
import com.zds.slms.service.IEmployeeService;
import com.zds.slms.service.IMerchandiseService;
import com.zds.slms.service.IStockinService;

/**
 * Copyright (C) 2010:SLMS<br/>
 * Project:SLMS<br/>
 * Module ID:<br/>
 * Comments:Simple Logistics Management System<br/>
 * JDK version used:JDK1.6<br/>
 * Package:com.zds.slms.action<br/>
 * Author:chenyongzheng<br/>
 * Create Date:2010-12-3<br/>
 * Modified By:<br/>
 * Modified Date:<br/>
 * Why & What is modified:<br/>
 * Version:0.1<br/>
 */
@SuppressWarnings("serial")
public class StockinAction extends ActionSupport {
	// 进货单业务处理接口
	private IStockinService stockinService;
	private Stockin stockin = new Stockin();
	// 查询结果集
	private List<Stockin> stockins = new ArrayList<Stockin>();
	// 操作结束后跳转的地址
	private String finish_Url;
	// 要删除的进货单ID
	private String[] stockinId;
	// 客户档案业务处理接口
	private IClientService clientService;
	// 员工档案业务处理接口
	private IEmployeeService employeeService;

	// 商品档案业务处理接口
	private IMerchandiseService merchandiseService;
	// 客户档案下拉框数据
	private List<Client> clients = new ArrayList<Client>();
	// 员工档案下拉框数据
	private List<Employee> employees = new ArrayList<Employee>();
	// 商品档案下拉框数据
	private List<Merchandise> merchandises = new ArrayList<Merchandise>();

	/**
	 * 进货单查询
	 * 
	 * @return
	 */

	public String findStockin() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);
		stockins = stockinService.findStockin(stockin);
		return "findStockin";

	}

	/**
	 * 进货单保存
	 * 
	 * @return
	 */
	public String saveStockin() {
		stockinService.saveStockin(stockin);
		finish_Url = "stockinAction!findStockin.action";
		return "finish";
	}

	/**
	 * 进货单删除
	 * 
	 * @return
	 */
	public String deleteStockin() {
		stockinService.deleteStockin(stockinId);
		finish_Url = "stockinAction!findStockin.action";
		return "finish";
	}

	/**
	 * 进货单更新
	 * 
	 * @return
	 */
	public String updateStockin() {
		stockinService.updateStockin(stockin);
		finish_Url = "stockinAction!findStockin.action";
		return "finish";
	}

	/**
	 * 进货单更新前查询
	 * 
	 * @return
	 */
	public String preUpdateStockin() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);
		stockin = stockinService.findStockin(stockin).get(0);
		return "updateStockin";
	}

	/**
	 * 进货单查询前下拉框数据初始化
	 * 
	 * @return
	 */

	public String preFindStockin() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);

		return "preFindStockin";

	}

	/**
	 * 进货单新增前下拉框数据初始化
	 * 
	 * @return
	 */

	public String preSaveStockin() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);

		return "preSaveStockin";

	}

	/**
	 * 商品单价查询
	 * 
	 * @param merchandiseId
	 *            商品ID
	 * @return
	 */

	public String findMerchandisePriceById(String merchandiseId) {
		if (null == merchandiseId || merchandiseId.trim().length() == 0) {
			return "0";
		}
		Merchandise merchandise = new Merchandise();
		merchandise.setId(Integer.parseInt(merchandiseId));
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(merchandise);

		return String.valueOf(merchandises.get(0).getPrice());

	}

	/**
	 * 进货单查询
	 * 
	 * @param code
	 *            进货单编码
	 * @return
	 */

	public int findStockinByCode(String code) {
		stockin = new Stockin();
		stockin.setCode(code);
		stockins = stockinService.findStockin(stockin);
		return stockins.size();

	}

	/**
	 * @return the stockinService
	 */
	public IStockinService getStockinService() {
		return stockinService;
	}

	/**
	 * @param stockinService
	 *            the stockinService to set
	 */
	public void setStockinService(IStockinService stockinService) {
		this.stockinService = stockinService;
	}

	/**
	 * @return the stockin
	 */
	public Stockin getStockin() {
		return stockin;
	}

	/**
	 * @param stockin
	 *            the stockin to set
	 */
	public void setStockin(Stockin stockin) {
		this.stockin = stockin;
	}

	/**
	 * @return the stockins
	 */
	public List<Stockin> getStockins() {
		return stockins;
	}

	/**
	 * @param stockins
	 *            the stockins to set
	 */
	public void setStockins(List<Stockin> stockins) {
		this.stockins = stockins;
	}

	/**
	 * @return the finish_Url
	 */
	public String getFinish_Url() {
		return finish_Url;
	}

	/**
	 * @param finish_Url
	 *            the finish_Url to set
	 */
	public void setFinish_Url(String finish_Url) {
		this.finish_Url = finish_Url;
	}

	/**
	 * @return the stockinId
	 */
	public String[] getStockinId() {
		return stockinId;
	}

	/**
	 * @param stockinId
	 *            the stockinId to set
	 */
	public void setStockinId(String[] stockinId) {
		this.stockinId = stockinId;
	}

	/**
	 * @return the clientService
	 */
	public IClientService getClientService() {
		return clientService;
	}

	/**
	 * @param clientService
	 *            the clientService to set
	 */
	public void setClientService(IClientService clientService) {
		this.clientService = clientService;
	}

	/**
	 * @return the employeeService
	 */
	public IEmployeeService getEmployeeService() {
		return employeeService;
	}

	/**
	 * @param employeeService
	 *            the employeeService to set
	 */
	public void setEmployeeService(IEmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	/**
	 * @return the merchandiseService
	 */
	public IMerchandiseService getMerchandiseService() {
		return merchandiseService;
	}

	/**
	 * @param merchandiseService
	 *            the merchandiseService to set
	 */
	public void setMerchandiseService(IMerchandiseService merchandiseService) {
		this.merchandiseService = merchandiseService;
	}

	/**
	 * @return the clients
	 */
	public List<Client> getClients() {
		return clients;
	}

	/**
	 * @param clients
	 *            the clients to set
	 */
	public void setClients(List<Client> clients) {
		this.clients = clients;
	}

	/**
	 * @return the employees
	 */
	public List<Employee> getEmployees() {
		return employees;
	}

	/**
	 * @param employees
	 *            the employees to set
	 */
	public void setEmployees(List<Employee> employees) {
		this.employees = employees;
	}

	/**
	 * @return the merchandises
	 */
	public List<Merchandise> getMerchandises() {
		return merchandises;
	}

	/**
	 * @param merchandises
	 *            the merchandises to set
	 */
	public void setMerchandises(List<Merchandise> merchandises) {
		this.merchandises = merchandises;
	}

}
