package core.stlmes.server.sale.service.balance;

import CoreFS.SA06.CoreReturnObject;
import core.stlmes.server.sale.dao.SlmBalanceDetailAllDao;
import core.stlmes.server.sale.dao.SlmBalanceTransMoneyDao;
import core.stlmes.server.sale.dao.SlmOrderHeadTgDao;
import core.stlmes.server.sale.dao.YdmZcBillMDao;
import core.stlmes.server.sale.po.SlmBalanceDetailAllBean;
import core.stlmes.server.sale.po.SlmBalanceTransMoneyBean;
import core.stlmes.server.sale.po.SlmOrderHeadTgBean;
import core.stlmes.server.sale.po.YdmZcBillMBean;
import core.stlmes.server.sale.service.baseservice.BaseBll;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class SlmBalanceTransMgt extends BaseBll
{

	public CoreReturnObject saveTransMoney(java.util.HashMap map, String person)
	{
		CoreReturnObject cro = new CoreReturnObject();
		core.stlmes.server.sale.dao.SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		if (map == null || map.size() == 0) return cro;
		java.util.List<SlmBalanceTransMoneyBean> beanList = new java.util.ArrayList<SlmBalanceTransMoneyBean>();
		SlmBalanceTransMoneyBean bean = new SlmBalanceTransMoneyBean();
		String[] temp = null;

		bean.setAgency_fl(map.get("AGENCY_FL").toString());
		double ticketnum = core.stlmes.server.sale.util.Convert.getDouble(map
				.get("TRANSNUM").toString());
		double ticketmny = core.stlmes.server.sale.util.Convert.getDouble(map
				.get("TRANSMNY").toString());
		bean.setTicketnum(ticketnum);
		bean.setMoney(ticketmny);

		bean.setBuyercode(map.get("CUSTOMER_NO").toString());
		bean.setBuyername(map.get("CUSTOMER_NM").toString());
		bean.setAskplan_id(map.get("BILL_NO").toString());
		bean.setInceptcorpcode(map.get("RECEIV_NM").toString());
		bean.setTrans_type(map.get("TRANS_TYPE").toString());
		// bean.setMotormanname(map.get("CARRIER_UNIT").toString());
		bean.setReceiv_addr(map.get("RECEIV_ADDR").toString());
		bean.setDelvry_addr(map.get("DELVRY_ADDR").toString());

		// bean.setMoney_type(map.get("MONET_TYPE").toString());
		bean.setStatus_cd("0");
		bean.setReg_id(person);
		bean.setReg_dtime(new Date());
		bean.setForecorpcode(map.get("SALE_ORG").toString());
		bean.setForecorpname(map.get("SALE_ORG_DESC").toString());
		bean.setOrd_pk(map.get("ORD_PK").toString());
		bean.setOrd_ln_pk(map.get("ORD_LN_PK").toString());
		bean.setOrd_ln_dly_pk(map.get("ORD_LN_DLY_PK").toString());
		bean.setIndex_seq(map.get("INDEX_SEQ").toString());
		bean.setOrder_no(map.get("ORDER_NO").toString());
		bean.setOrder_seq(map.get("ORDER_SEQ").toString());

		core.stlmes.server.sale.dbhelp.DbTrans trans = new core.stlmes.server.sale.dbhelp.DbTrans();

		try
		{
			String FST_DRAWEE_UNIT = "";
			List<YdmZcBillMBean> list = new YdmZcBillMDao()
					.getYdmZcBillMByBillNo(map.get("BILL_NO").toString());
			if (list == null)
			{
			}
			else
			{
				SlmOrderHeadTgBean odbean = (new SlmOrderHeadTgDao() )
						.getSlmOrderHeadTgByOrdPk(list.get(0).getOrd_pk());
				FST_DRAWEE_UNIT = (odbean == null ) ? "" : odbean
						.getFst_drawee_unit();

			}

			bean.setFst_drawee_unit(FST_DRAWEE_UNIT);
			bean.setMoney_type(MoneyTypeTransmny);
			bean.setMoney(ticketmny);
			bean.setTickettype(GetMnyTypeByAgencyFlAndAddressFroTransMny(map
					.get("AGENCY_FL").toString()));

			SimpleDateFormat tempDate = new SimpleDateFormat("yyyyMM");
			String time = tempDate.format(new Date());
			bean.setInvoice_month(time);
			bean.setInvoice_sts("0");
			bean.setStatus_cd("0");
			bean.setStatus_cd_org("0");
			bean.setTicketstatus("0");

			trans.beginTransaction();
			slmBalanceTransMoneyDao.setTrans(trans);
			slmBalanceTransMoneyDao
					.deleteTransMoneyByAskPlanIdAndOrdPkAndLineAndDelPkAndSeq(
							bean.getAskplan_id(), bean.getOrd_pk(), bean
									.getOrd_ln_pk(), bean.getOrd_ln_dly_pk(),
							bean.getIndex_seq());

			slmBalanceTransMoneyDao.insert(bean);
			trans.commit();

		}
		catch (java.sql.SQLException ex)
		{
			trans.rollback();
			super.setCroErrMsg(cro, ex.getMessage());
		}
		catch (java.lang.Exception ex)
		{
			trans.rollback();
			super.setCroErrMsg(cro, ex.getMessage());
		}

		return cro;

	}

	public CoreReturnObject saveTransMoneyWithBillNoAndTransMny(String billno,
			String transMny, String ticketType, String AGENCY_FL,
			String delvaddr, String ordpk, String ordLnPk, String ordLndPk,
			String indexNo, String person, String weight,String disburasesbill,String TransNo,String stampDutyMoney)
	{
		CoreReturnObject cro = new CoreReturnObject();
		SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = null;
		SlmBalanceTransMoneyBean bean = null;
		core.stlmes.server.sale.dbhelp.DbTrans trans = null;
		trans = new core.stlmes.server.sale.dbhelp.DbTrans();
		bean = new SlmBalanceTransMoneyBean();
		slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		double money = core.stlmes.server.sale.util.Convert.getDouble(transMny);
		// if (money == 0) return cro;
		if (ticketType.equals("无")) return cro;

		String FST_DRAWEE_UNIT = "";
		try
		{
			List<YdmZcBillMBean> list = new YdmZcBillMDao()
					.getYdmZcBillMByBillNo(billno);
			YdmZcBillMBean mbean = null;
			if (list == null)
			{
			}
			else
			{
				mbean = list.get(0);
				SlmOrderHeadTgBean odbean = (new SlmOrderHeadTgDao() )
						.getSlmOrderHeadTgByOrdPk(list.get(0).getOrd_pk());
				FST_DRAWEE_UNIT = (odbean == null ) ? "" : odbean
						.getFst_drawee_unit();
				bean.setAgency_fl(AGENCY_FL);
				bean.setBuyercode(mbean.getStlmt_unit_no());
				bean.setBuyername(mbean.getStlmt_unit_nm());
				bean.setAskplan_id(billno);
				bean.setInceptcorpcode(mbean.getReceiv_nm());
				// bean.setReceiv_addr(delvaddr);
				bean.setDelvry_addr(delvaddr);
				bean.setStatus_cd("0");
				bean.setReg_id(person);
				bean.setReg_dtime(new Date());
				bean.setForecorpcode(mbean.getSale_org());
				bean.setForecorpname(mbean.getSale_org_desc());
				bean.setOrd_pk(ordpk);
				bean.setOrd_ln_pk(ordLnPk);
				bean.setOrd_ln_dly_pk(ordLndPk);
				bean.setIndex_seq(indexNo);
				bean.setFst_drawee_unit(FST_DRAWEE_UNIT);
				bean.setMoney_type(MoneyTypeTransmny);
				bean.setMoney(money);
				bean.setStampDutyMoney(core.stlmes.server.sale.util.Convert.getDouble(stampDutyMoney));
				bean.setTrans_type( ("110501"
						.equals(mbean.getPlan_trans_type()) ) ? "汽运" : "铁运");
				bean.setTickettype(ticketType);

				SimpleDateFormat tempDate = new SimpleDateFormat("yyyyMM");
				String time = tempDate.format(new Date());
				bean.setInvoice_month(time);
				bean.setInvoice_sts("0");
				bean.setStatus_cd("0");
				bean.setStatus_cd_org("0");
				bean.setTicketstatus("0");
				bean.setDisburases_bill(disburasesbill);
				bean.setTrans_no(TransNo);

				trans.beginTransaction();
				slmBalanceTransMoneyDao.setTrans(trans);
				slmBalanceTransMoneyDao
						.deleteTransMoneyByAskPlanIdAndOrdPkAndLineAndDelPkAndSeq(
								bean.getAskplan_id(), bean.getOrd_pk(), bean
										.getOrd_ln_pk(), bean
										.getOrd_ln_dly_pk(), bean
										.getAgency_fl());

				slmBalanceTransMoneyDao.insert(bean);
				trans.commit();

			}
		}
		catch (java.sql.SQLException ex)
		{
			trans.rollback();
			super.setCroErrMsg(cro, ex.getMessage());
		}
		catch (java.lang.Exception ex)
		{
			trans.rollback();
			super.setCroErrMsg(cro, ex.getMessage());
		}

		return cro;

	}

	private String GetMnyTypeByAgencyFlAndAddressFroTransMny(String agencyfl)
	{
		if (agencyfl.equals("0")) return TicketType_Crd;
		else if (agencyfl.equals("1")) return TicketType_Receive;
		else if (agencyfl.equals("2")) return TicketType_Debt;
		else
			return TicketType_Receive;

	}

	public CoreReturnObject deleteTransMoney(String transseq, String person)
	{
		CoreReturnObject cro = new CoreReturnObject();
		core.stlmes.server.sale.dao.SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		try
		{
			slmBalanceTransMoneyDao.delete(transseq);
		}
		catch (java.sql.SQLException ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());
		}

		catch (java.lang.Exception ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());

		}

		return cro;
	}

	public CoreReturnObject editTransMoney(String transeq, String ticketNum,
			String money, String person)
	{
		CoreReturnObject cro = new CoreReturnObject();
		core.stlmes.server.sale.dao.SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		try
		{
			double mny = core.stlmes.server.sale.util.Convert.getDouble(money);
			double ticketnumd = core.stlmes.server.sale.util.Convert
					.getDouble(ticketNum);
			slmBalanceTransMoneyDao.update(transeq, ticketnumd, mny, person);

		}
		catch (java.sql.SQLException ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());
		}

		catch (java.lang.Exception ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());

		}

		return cro;
	}

	public CoreReturnObject affrimTransMnyByAskPlanId(String askplanid,
			String person)
	{
		CoreReturnObject cro = new CoreReturnObject();
		core.stlmes.server.sale.dao.SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		try
		{

			slmBalanceTransMoneyDao.affrimAskPlanIdFroTransMny(askplanid,
					person);

		}
		catch (java.sql.SQLException ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());
		}

		catch (java.lang.Exception ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());

		}

		return cro;
	}

	public CoreReturnObject rollbackInvoiceNo(String invoiceNo, String person)
	{
		CoreReturnObject cro = new CoreReturnObject();
		try
		{
			new SlmBalanceTransMoneyDao().rollbackInvoiceNo(invoiceNo, person);
		}
		catch (java.sql.SQLException ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());
		}

		catch (java.lang.Exception ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());

		}
		return cro;

	}

	public CoreReturnObject saveOutStockMny(String askPlanId, String person)
	{
		CoreReturnObject cro = new CoreReturnObject();
		SlmBalanceDetailAllDao slmBalanceDetailAllDao = new SlmBalanceDetailAllDao();
		SlmBalanceDetailAllBean detail = new SlmBalanceDetailAllBean();
		SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		core.stlmes.server.sale.dbhelp.DbTrans dbtrans = new core.stlmes.server.sale.dbhelp.DbTrans();

		deleteOutStockMnyByAksPlanId(askPlanId, person);
		try
		{
			List<SlmBalanceDetailAllBean> listBal = slmBalanceDetailAllDao
					.getSlmBalanceDetailAllByAskPlanId(askPlanId);
			if (listBal == null) return cro;
			String hsKey = "";
			double mny = 0;
			java.util.Hashtable hs = new java.util.Hashtable();
			List<SlmBalanceDetailAllBean> temp = new java.util.ArrayList<SlmBalanceDetailAllBean>();
			for (SlmBalanceDetailAllBean bean : listBal)
			{
				// 虚拟提单，直接返回
				if (bean.getIspreclose().equals("1")) return cro;
				String key = bean.getAskplan_id() + bean.getOrd_pk()
						+ bean.getOrd_ln_pk() + bean.getOrd_ln_dly_pk()
						+ bean.getTallysheet_no();
				if (hs.containsKey(key))
				{
					temp = ( List<SlmBalanceDetailAllBean>)hs.get(key);
					hs.remove(key);

				}
				else
				{
					temp = new java.util.ArrayList<SlmBalanceDetailAllBean>();
				}
				temp.add(bean);
				hs.put(key, temp);

			}

			java.util.Iterator iter = hs.keySet().iterator();
			SlmBalanceTransMoneyBean slmBalanceTransMoneyBean = null;

			dbtrans.beginTransaction();
			slmBalanceTransMoneyDao.setTrans(dbtrans);
			while (iter.hasNext())
			{
				mny = 0;
				double wgt = 0.0;
				slmBalanceTransMoneyBean = new SlmBalanceTransMoneyBean();
				temp = ( List<SlmBalanceDetailAllBean>)hs.get(iter.next());
				for (SlmBalanceDetailAllBean bean : temp)
				{
					mny = mny + bean.getOutstockmny();
					wgt = wgt + bean.getAct_wgt();

				}

				if (mny == 0) return cro;
				detail = temp.get(0);
				slmBalanceTransMoneyBean.setAskplan_id(askPlanId);
				slmBalanceTransMoneyBean.setTallysheet_no(detail
						.getTallysheet_no());
				slmBalanceTransMoneyBean.setOrd_pk(detail.getOrd_pk());
				slmBalanceTransMoneyBean.setOrd_ln_pk(detail.getOrd_ln_pk());
				slmBalanceTransMoneyBean.setOrd_ln_dly_pk(detail
						.getOrd_ln_dly_pk());

				slmBalanceTransMoneyBean.setOrder_no(detail.getOrd_no());
				slmBalanceTransMoneyBean.setOrder_seq(detail.getOrd_seq());
				slmBalanceTransMoneyBean.setMoney(mny);
				slmBalanceTransMoneyBean.setMoney_type("出库费");
				slmBalanceTransMoneyBean.setStatus_cd("1");
				slmBalanceTransMoneyBean.setTickettype(detail.getMoney_type());
				slmBalanceTransMoneyBean.setBuyercode(detail.getBuyercode());
				slmBalanceTransMoneyBean.setBuyername(detail.getBuyername());
				slmBalanceTransMoneyBean.setForecorpcode(detail
						.getForecorpcode());
				slmBalanceTransMoneyBean.setForecorpname(detail
						.getForecorpname());
				slmBalanceTransMoneyBean.setTrans_type(detail
						.getTrans_type_name());
				slmBalanceTransMoneyBean.setMotormanname(detail
						.getMotormanname_desc());
				slmBalanceTransMoneyBean.setAgency_fl(detail.getAgency_fl());
				slmBalanceTransMoneyBean
						.setDelvry_addr(detail.getDelvry_addr());
				slmBalanceTransMoneyBean
						.setReceiv_addr(detail.getReceiv_addr());
				slmBalanceTransMoneyBean.setReg_id(person);
				slmBalanceTransMoneyBean.setReg_dtime(new Date());
				slmBalanceTransMoneyBean.setInceptcorpcode(detail
						.getRecv_unit());
				slmBalanceTransMoneyBean.setFst_drawee_unit(detail
						.getFst_drawee_unit());
				slmBalanceTransMoneyBean.setWeight(wgt);

				SimpleDateFormat tempDate = new SimpleDateFormat("yyyyMM");
				String time = tempDate.format(new Date());
				slmBalanceTransMoneyBean.setInvoice_month(time);
				slmBalanceTransMoneyBean.setInvoice_sts("0");
				slmBalanceTransMoneyBean.setStatus_cd("0");
				slmBalanceTransMoneyBean.setStatus_cd_org("0");
				slmBalanceTransMoneyBean.setTicketstatus("0");

				slmBalanceTransMoneyDao.insert(slmBalanceTransMoneyBean);

			}
			dbtrans.commit();
			slmBalanceTransMoneyDao.setTrans(null);
		}
		catch (java.sql.SQLException ex)
		{
			super.setCroErrMsg(cro, ex.getMessage());
			dbtrans.rollback();
			slmBalanceTransMoneyDao.setTrans(null);
		}

		catch (java.lang.Exception ex)
		{
			dbtrans.rollback();
			slmBalanceTransMoneyDao.setTrans(null);
			super.setCroErrMsg(cro, ex.getMessage());

		}
		return cro;

	}

	public void SaveOutStockMnyByAlineTicket(java.sql.Connection conn,
			java.util.ArrayList list, String person)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		if (list == null || list.size() == 0) return;
		String[] temp = null;
		String billNO = (( String[])list.get(0) )[0];
		SlmBalanceTransMoneyBean slmBalanceTransMoneyBean = null;
		SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		YdmZcBillMBean mbean = null;
		String FST_DRAWEE_UNIT = "";

		try
		{
			List<YdmZcBillMBean> listb = new YdmZcBillMDao()
					.getYdmZcBillMByBillNo(billNO);

			if (listb == null || listb.size() == 0) return;
			mbean = listb.get(0);
			SlmOrderHeadTgBean odbean = (new SlmOrderHeadTgDao() )
					.getSlmOrderHeadTgByOrdPk(mbean.getOrd_pk());
			FST_DRAWEE_UNIT = (odbean == null ) ? "" : odbean
					.getFst_drawee_unit();
		}
		catch (java.sql.SQLException ex)
		{
		}

		slmBalanceTransMoneyDao.deleteOutStockMnyByBillNo(conn, billNO);

		for (Object obj : list)
		{
			slmBalanceTransMoneyBean = new SlmBalanceTransMoneyBean();
			temp = ( String[])obj;
			// String billNO = temp[0];
			String ORD_PK = temp[1];
			String ORD_LN_PK = temp[2];
			String ORD_LN_DLY_PK = temp[3];
			String AGENCY_FL = temp[4];
			String ORDER_NO = temp[5];
			String ORDER_SEQ = temp[6];
			String DELVRY_ADDR = temp[7];
			String TRANS_TYPE = temp[8];
			String MOTORMANNAME = temp[9];
			String money = temp[10];
			String moneyType = temp[11];
			String weight = temp[12];
			double money1 = core.stlmes.server.sale.util.Convert
					.getDouble(money);
			if (money1 == 0) return;
			double weight1 = core.stlmes.server.sale.util.Convert
					.getDouble(weight);

			slmBalanceTransMoneyBean.setAskplan_id(billNO);
			slmBalanceTransMoneyBean.setTallysheet_no("");
			slmBalanceTransMoneyBean.setOrd_pk(ORD_PK);
			slmBalanceTransMoneyBean.setOrd_ln_pk(ORD_LN_PK);
			slmBalanceTransMoneyBean.setOrd_ln_dly_pk(ORD_LN_DLY_PK);

			slmBalanceTransMoneyBean.setOrder_no(ORDER_NO);
			slmBalanceTransMoneyBean.setOrder_seq(ORDER_SEQ);
			slmBalanceTransMoneyBean.setMoney(money1);
			slmBalanceTransMoneyBean.setMoney_type("出库费");
			slmBalanceTransMoneyBean.setStatus_cd("0");
			slmBalanceTransMoneyBean.setTickettype(moneyType);
			slmBalanceTransMoneyBean.setBuyercode(mbean.getStlmt_unit_no());
			slmBalanceTransMoneyBean.setBuyername(mbean.getStlmt_unit_nm());
			slmBalanceTransMoneyBean.setForecorpcode(mbean.getSale_org());
			slmBalanceTransMoneyBean.setForecorpname(mbean.getSale_org_desc());
			slmBalanceTransMoneyBean.setTrans_type(TRANS_TYPE);
			slmBalanceTransMoneyBean.setMotormanname(MOTORMANNAME);
			slmBalanceTransMoneyBean.setAgency_fl(AGENCY_FL);
			slmBalanceTransMoneyBean.setDelvry_addr(DELVRY_ADDR);
			slmBalanceTransMoneyBean.setReceiv_addr("");
			slmBalanceTransMoneyBean.setReg_id(person);
			slmBalanceTransMoneyBean.setReg_dtime(new Date());
			slmBalanceTransMoneyBean.setInceptcorpcode(mbean.getReceiv_nm());
			slmBalanceTransMoneyBean.setFst_drawee_unit(FST_DRAWEE_UNIT);
			slmBalanceTransMoneyBean.setWeight(weight1);
			SimpleDateFormat tempDate = new SimpleDateFormat("yyyyMM");
			String time = tempDate.format(new Date());
			slmBalanceTransMoneyBean.setInvoice_month(time);
			slmBalanceTransMoneyBean.setInvoice_sts("0");
			slmBalanceTransMoneyBean.setStatus_cd("0");
			slmBalanceTransMoneyBean.setStatus_cd_org("0");
			slmBalanceTransMoneyBean.setTicketstatus("0");
			slmBalanceTransMoneyBean.setStampDutyMoney(0.0);
			slmBalanceTransMoneyDao.insert(conn, slmBalanceTransMoneyBean);

		}

	}

	public CoreReturnObject deleteOutStockMnyByAksPlanId(String askPlanId,
			String person)
	{
		CoreReturnObject cro = new CoreReturnObject();

		SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		core.stlmes.server.sale.dbhelp.DbTrans trans = new core.stlmes.server.sale.dbhelp.DbTrans();

		try
		{
			trans.beginTransaction();
			slmBalanceTransMoneyDao.setTrans(trans);
			List<SlmBalanceTransMoneyBean> list = slmBalanceTransMoneyDao
					.getOutStockMnySlmBalanceTransMoneyByAskPlanId(askPlanId);
			if (list == null) return cro;
			for (SlmBalanceTransMoneyBean bean : list)
			{
				slmBalanceTransMoneyDao.delete(bean.getTrans_pk());

			}
			trans.commit();
			slmBalanceTransMoneyDao.setTrans(null);

		}
		catch (java.sql.SQLException ex)
		{
			trans.rollback();
			slmBalanceTransMoneyDao.setTrans(null);
			super.setCroErrMsg(cro, ex.getMessage());

		}

		catch (java.lang.Exception ex)
		{
			trans.rollback();
			slmBalanceTransMoneyDao.setTrans(null);
			super.setCroErrMsg(cro, ex.getMessage());

		}
		return cro;

	}

	public synchronized CoreReturnObject makeInvoiceTransMoney(
			java.util.ArrayList list, String forecode, String person)
	{
		CoreReturnObject cro = new CoreReturnObject();
		cro = makeInvoice(list, forecode, person, "0");
		return cro;
	}

	public synchronized CoreReturnObject makeInvoiceOutStockMoney(
			java.util.ArrayList list, String forecode, String person)
	{
		CoreReturnObject cro = new CoreReturnObject();
		cro = makeInvoice(list, forecode, person, "1");
		return cro;
	}

	// invoiceType 0 transMny,1 outStockMny
	private synchronized CoreReturnObject makeInvoice(java.util.ArrayList list,
			String forecode, String person, String invoiceType)
	{
		CoreReturnObject cro = new CoreReturnObject();
		core.stlmes.server.sale.dao.SlmBalanceTransMoneyDao slmBalanceTransMoneyDao = new SlmBalanceTransMoneyDao();
		core.stlmes.server.sale.dbhelp.DbTrans trans = new core.stlmes.server.sale.dbhelp.DbTrans();
		String[] temp = null;
		java.util.ArrayList<String> lista = new java.util.ArrayList<String>();
		String invoiceNo = "";
		try
		{
			invoiceNo = slmBalanceTransMoneyDao.getmaxInvoiceNo();
			String buyercode = "";
			java.util.Hashtable hs = new java.util.Hashtable();
			for (Object s : list)
			{
				temp = ( String[])s;
				buyercode = temp[7];
				List<SlmBalanceTransMoneyBean> translist = null;
				if (!hs.containsKey(buyercode.toString()))
				{
					if (invoiceType.equals("0"))
					{
						translist = slmBalanceTransMoneyDao
								.getunInvoiceSlmBalanceTransMoneyByBuyerCode(buyercode);
					}

					if (invoiceType.equals("1"))
					{
						translist = slmBalanceTransMoneyDao
								.getunInvoiceOutStockMnySlmBalanceTransMoneyByBuyerCode(buyercode);
					}
					if (translist != null)
					{
						hs.put(buyercode, translist);
					}
				}

			}

			java.util.Iterator iter = hs.keySet().iterator();
			List<SlmBalanceTransMoneyBean> listmn = null;

			trans.beginTransaction();
			slmBalanceTransMoneyDao.setTrans(trans);
			while (iter.hasNext())
			{
				invoiceNo = this.getNextInvoiceNo(invoiceNo);
				listmn = ( List<SlmBalanceTransMoneyBean>)hs.get(iter.next()
						.toString());
				for (SlmBalanceTransMoneyBean bean : listmn)
				{

					slmBalanceTransMoneyDao.updateInvoiceNo("T" + invoiceNo,
							person, bean.getTrans_pk());
				}

			}
			trans.commit();
			slmBalanceTransMoneyDao.setTrans(null);

		}
		catch (java.sql.SQLException ex)
		{
			trans.rollback();
			slmBalanceTransMoneyDao.setTrans(null);
			super.setCroErrMsg(cro, ex.getMessage());
		}

		catch (java.lang.Exception ex)
		{
			trans.rollback();
			slmBalanceTransMoneyDao.setTrans(null);
			super.setCroErrMsg(cro, ex.getMessage());

		}

		return cro;
	}

	public void updateVirtualBillStatusWhenSecondClosePreBill(String askPlanId)
	{
		CoreReturnObject cro = new CoreReturnObject();
		return;
		// YdmZcLoadvehicleMatDao ydmZcLoadvehicleMatDao = new
		// YdmZcLoadvehicleMatDao();
		// SlmBalanceDetailAllDao slmBalanceDetailAllDao = new
		// SlmBalanceDetailAllDao();
		// SlmBalanceInfoDao slmBalanceInfoDao = new SlmBalanceInfoDao();
		// core.stlmes.server.sale.dbhelp.DbTrans trans = new
		// core.stlmes.server.sale.dbhelp.DbTrans();
		//
		// try
		// {
		// trans.beginTransaction();
		//
		// slmBalanceDetailAllDao.updatePreCloseToClose(askPlanId);
		// slmBalanceInfoDao.updateVirtualAskplanIdToRealClose(askPlanId);
		// trans.commit();
		// // saveOutStockMny(askPlanId, "Sys");
		//
		// }
		// catch (java.sql.SQLException ex)
		// {
		// trans.rollback();
		//
		// // super.setCroErrMsg(cro, ex.getMessage());
		// }
		//
		// catch (java.lang.Exception ex)
		// {
		// trans.rollback();
		//
		// // super.setCroErrMsg(cro, ex.getMessage());
		//
		// }

	}

	private String getNextInvoiceNo(String invoiceNo)
	{
		java.math.BigDecimal bd = new java.math.BigDecimal(invoiceNo);
		java.math.BigDecimal bd1 = new java.math.BigDecimal(1);
		bd = bd.add(bd1);
		return bd.toString();
	}

	private String MoneyTypeOutStock = "出库费";
	private String MoneyTypeDZF = "吊装费";
	private String MoneyTypeTransmny = "运费";
	private String TicketType_Receive = "应收";
	private String TicketType_Debt = "应付";
	private String TicketType_Crd = "报销";
}
