⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doc.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			CallableStatement cstmt = DB.prepareCall("{? = call GL_Period_Open(?,?,?,?)}");
			//
			cstmt.registerOutParameter(1, Types.INTEGER);   //  C_Period_ID
			cstmt.setInt(2, p_vo.AD_Client_ID);
			cstmt.setTimestamp(3, p_vo.DateAcct);
			cstmt.setString(4, p_vo.DocumentType);
			cstmt.setNull(5, Types.INTEGER);                //  C_AcctSchema_ID
			//
			cstmt.execute();
			p_vo.C_Period_ID = cstmt.getInt(1);
			cstmt.close();
		}
		catch (SQLException e)
		{
			log.error ("getC_Period_ID", e);
		}
		log.debug ("setC_Period_ID - "
			+ p_vo.AD_Client_ID + " - " + p_vo.DateAcct + " - " + p_vo.DocumentType + " => " + p_vo.C_Period_ID);
	}   //  setC_Period_ID

	/**
	 *	Is Period Open
	 *  @return true if period is open
	 */
	public boolean isPeriodOpen()
	{
		setC_Period_ID();
		boolean open = p_vo.C_Period_ID != -1;
		if (open)
			log.debug("isPeriodOpen - " + p_vo.toString());
		else
			log.warn("isPeriodOpen NO - " + p_vo.toString());
		return open;
	}	//	isPeriodOpen

	/*************************************************************************/

	/**	Amount Type - Invoice   */
	public static final int 	AMTTYPE_Gross   = 0;
	public static final int 	AMTTYPE_Net     = 1;
	public static final int 	AMTTYPE_Charge  = 2;
	/** Amount Type - Allocation    */
	public static final int 	AMTTYPE_Invoice = 0;
	public static final int 	AMTTYPE_Allocation = 1;
	public static final int 	AMTTYPE_Discount = 2;
	public static final int 	AMTTYPE_WriteOff = 3;

	/**
	 *	Get the Amount
	 *  (loaded in loadDocumentDetails)
	 *
	 *  @param AmtType see AMTTYPE_*
	 *  @return Amount
	 */
	public BigDecimal getAmount(int AmtType)
	{
		if (AmtType < 0 || AmtType >= p_vo.Amounts.length)
			return null;
		return p_vo.Amounts[AmtType];
	}	//	getAmount

	/**
	 *  Get Amount with index 0
	 *  @return Amount (primary document amount)
	 */
	public BigDecimal getAmount()
	{
		return p_vo.Amounts[0];
	}   //  getAmount

	/*************************************************************************/

	/**	Account Type - Invoice  */
	public static final int 	ACCTTYPE_Charge         = 0;
	public static final int 	ACCTTYPE_C_Receivable   = 1;
	public static final int 	ACCTTYPE_V_Liability    = 2;
	public static final int 	ACCTTYPE_V_Liability_Services    = 3;

	/** Account Type - Payment  */
	public static final int     ACCTTYPE_UnallocatedCash = 10;
	public static final int 	ACCTTYPE_BankInTransit  = 11;
	public static final int     ACCTTYPE_PaymentSelect  = 12;

	/** Account Type - Cash     */
	public static final int     ACCTTYPE_CashAsset = 20;
	public static final int     ACCTTYPE_CashTransfer = 21;
	public static final int     ACCTTYPE_CashExpense = 22;
	public static final int     ACCTTYPE_CashReceipt = 23;
	public static final int     ACCTTYPE_CashDifference = 24;

	/** Account Type - Allocation   */
	public static final int 	ACCTTYPE_DiscountExp = 30;
	public static final int 	ACCTTYPE_DiscountRev = 31;
	public static final int 	ACCTTYPE_WriteOff = 32;

	/** Account Type - Bank Statement   */
	public static final int     ACCTTYPE_BankAsset = 40;
	public static final int     ACCTTYPE_InterestRev = 41;
	public static final int     ACCTTYPE_InterestExp = 42;

	/** Inventory Accounts          */
	public static final int     ACCTTYPE_InvDifferences = 50;
	public static final int     ACCTTYPE_NotInvoicedReceipts = 51;

	/** GL Accounts                 */
	public static final int     ACCTTYPE_PPVOffset = 60;


	/**
	 *	Get the account for Accounting Schema
	 *  @param AcctType see ACCTTYPE_*
	 *  @param as accounting schema
	 *  @return Account
	 */
	public final Account getAccount (int AcctType, AcctSchema as)
	{
		int para_1 = 0;     //  first parameter (second is always AcctSchema)
		String sql = null;

		/**	Account Type - Invoice  */
		if (AcctType == ACCTTYPE_Charge)
		{
			if (getAmount(AMTTYPE_Charge).compareTo(Env.ZERO) == 0)
				return null;
			sql = "SELECT ChargeAcct FROM C_Charge WHERE C_Charge_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_Charge_ID;
		}
		else if (AcctType == ACCTTYPE_V_Liability)
		{
			sql = "SELECT V_Liability_Acct FROM C_BP_Vendor_Acct WHERE C_BPartner_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BPartner_ID;
		}
		else if (AcctType == ACCTTYPE_V_Liability_Services)
		{
			sql = "SELECT V_Liability_Services_Acct FROM C_BP_Vendor_Acct WHERE C_BPartner_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BPartner_ID;
		}
		else if (AcctType == ACCTTYPE_C_Receivable)
		{
			sql = "SELECT C_Receivable_Acct FROM C_BP_Customer_Acct WHERE C_BPartner_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BPartner_ID;
		}

		/** Account Type - Payment  */
		else if (AcctType == ACCTTYPE_UnallocatedCash)
		{
			sql = "SELECT B_UnallocatedCash_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BankAccount_ID;
		}
		else if (AcctType == ACCTTYPE_BankInTransit)
		{
			sql = "SELECT B_InTransit_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BankAccount_ID;
		}
		else if (AcctType == ACCTTYPE_PaymentSelect)
		{
			sql = "SELECT B_PaymentSelect_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BankAccount_ID;
		}
		/** Account Type - Allocation   */
		else if (AcctType == ACCTTYPE_DiscountExp)
		{
			sql = "SELECT a.PayDiscount_Exp_Acct FROM C_BP_Group_Acct a, C_BPartner bp "
				+ "WHERE a.C_BP_Group_ID=bp.C_BP_Group_ID AND bp.C_BPartner_ID=? AND a.C_AcctSchema_ID=?";
			para_1 = p_vo.C_BPartner_ID;
		}
		else if (AcctType == ACCTTYPE_DiscountRev)
		{
			sql = "SELECT PayDiscount_Rev_Acct FROM C_BP_Group_Acct a, C_BPartner bp "
				+ "WHERE a.C_BP_Group_ID=bp.C_BP_Group_ID AND bp.C_BPartner_ID=? AND a.C_AcctSchema_ID=?";
			para_1 = p_vo.C_BPartner_ID;
		}
		else if (AcctType == ACCTTYPE_WriteOff)
		{
			sql = "SELECT WriteOff_Acct FROM C_BP_Group_Acct a, C_BPartner bp "
				+ "WHERE a.C_BP_Group_ID=bp.C_BP_Group_ID AND bp.C_BPartner_ID=? AND a.C_AcctSchema_ID=?";
			para_1 = p_vo.C_BPartner_ID;
		}

		/** Account Type - Bank Statement   */
		else if (AcctType == ACCTTYPE_BankAsset)
		{
			sql = "SELECT B_Asset_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BankAccount_ID;
		}
		else if (AcctType == ACCTTYPE_InterestRev)
		{
			sql = "SELECT B_InterestRev_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BankAccount_ID;
		}
		else if (AcctType == ACCTTYPE_InterestExp)
		{
			sql = "SELECT B_InterestExp_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_BankAccount_ID;
		}

		/** Account Type - Cash     */
		else if (AcctType == ACCTTYPE_CashAsset)
		{
			sql = "SELECT CB_Asset_Acct FROM C_CashBook_Acct WHERE C_CashBook_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_CashBook_ID;
		}
		else if (AcctType == ACCTTYPE_CashTransfer)
		{
			sql = "SELECT CB_CashTransfer_Acct FROM C_CashBook_Acct WHERE C_CashBook_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_CashBook_ID;
		}
		else if (AcctType == ACCTTYPE_CashExpense)
		{
			sql = "SELECT CB_Expense_Acct FROM C_CashBook_Acct WHERE C_CashBook_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_CashBook_ID;
		}
		else if (AcctType == ACCTTYPE_CashReceipt)
		{
			sql = "SELECT CB_Receipt_Acct FROM C_CashBook_Acct WHERE C_CashBook_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_CashBook_ID;
		}
		else if (AcctType == ACCTTYPE_CashDifference)
		{
			sql = "SELECT CB_Differences_Acct FROM C_CashBook_Acct WHERE C_CashBook_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.C_CashBook_ID;
		}

		/** Inventory Accounts          */
		else if (AcctType == ACCTTYPE_InvDifferences)
		{
			sql = "SELECT W_Differences_Acct FROM M_Warehouse_Acct WHERE M_Warehouse_ID=? AND C_AcctSchema_ID=?";
			//  "SELECT W_Inventory_Acct, W_Revaluation_Acct, W_InvActualAdjust_Acct FROM M_Warehouse_Acct WHERE M_Warehouse_ID=? AND C_AcctSchema_ID=?";
			para_1 = p_vo.M_Warehouse_ID;
		}
		else if (AcctType == ACCTTYPE_NotInvoicedReceipts)
		{
			sql = "SELECT NotInvoicedReceipts_Acct FROM C_BP_Group_Acct a, C_BPartner bp "
				+ "WHERE a.C_BP_Group_ID=bp.C_BP_Group_ID AND bp.C_BPartner_ID=? AND a.C_AcctSchema_ID=?";
			para_1 = p_vo.C_BPartner_ID;
		}

		/** GL Accounts                 */
		else if (AcctType == ACCTTYPE_PPVOffset)
		{
			sql = "SELECT PPVOffset_Acct FROM C_AcctSchema_GL WHERE C_AcctSchema_ID=?";
			para_1 = -1;
		}

		else
		{
			log.error ("getAccount - Not found AcctType=" + AcctType);
			return null;
		}
		//  Do we have sql & Parameter
		if (sql == null || para_1 == 0)
		{
			log.error ("getAccount - No Parameter for AcctType=" + AcctType + " - SQL=" + sql);
			return null;
		}

		//  Get Acct
		int Account_ID = 0;
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(sql);
			if (para_1 == -1)   //  GL Accounts
				pstmt.setInt (1, as.getC_AcctSchema_ID());
			else
			{
				pstmt.setInt (1, para_1);
				pstmt.setInt (2, as.getC_AcctSchema_ID());
			}
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
				Account_ID = rs.getInt(1);
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			log.error ("getAccount - AcctType=" + AcctType + " - SQL=" + sql, e);
			return null;
		}
		//	No account
		if (Account_ID == 0)
		{
			log.error ("getAccount - NO account Type="
				+ AcctType + ", Record=" + p_vo.Record_ID);
			return null;
		}

		//	Return Account
		Account acct = Account.getAccount (Account_ID);
		return acct;
	}	//	getAccount

	/*************************************************************************/

	/**
	 *  Save to Disk - set posted flag
	 *  @param con connection
	 *  @return true if saved
	 */
	private final boolean save (Connection con)
	{
		log.debug ("save - " + toString() + "->" + p_vo.Status);

		StringBuffer sql = new StringBuffer("UPDATE ");
		sql.append(getTableName()).append(" SET Posted='").append(p_vo.Status).append("',Processing='N' ")
			.append("WHERE ").append(getTableName()).append("_ID=").append(p_vo.Record_ID);
		int no = 0;
		try
		{
			Statement stmt = con.createStatement();
			no = stmt.executeUpdate(sql.toString());
			stmt.close();
		}
		catch (SQLException e)
		{
			log.error ("save", e);
			no = 0;
		}
		return no == 1;
	}   //  save

	/**
	 *  Get DocLine with ID
	 *  @param Record_ID Record ID
	 *  @return DocLine
	 */
	public DocLine getDocLine (int Record_ID)
	{
		if (p_lines.length == 0 || Record_ID == 0)
			return null;

		for (int i = 0; i < p_lines.length; i++)
		{
			if (p_lines[i].getTrxLine_ID() == Record_ID)
				return p_lines[i];
		}
		return null;
	}   //  getDocLine

	/**
	 *  String Representation
	 *  @return String
	 */
	public String toString()
	{
		if (p_vo == null)
			return "Doc";
		return p_vo.toString();
	}   //  toString

	/*************************************************************************/
	//  To be overwritten by Subclasses

	/**
	 *  Return TableName of Document
	 *  @return Table Name
	 */
	public abstract String getTableName();

	/**
	 *  Get Document Table ID
	 *  @return AD_Table_ID
	 */
	public abstract int getAD_Table_ID();

	/**
	 *  Load Specific Document Details
	 *  @param rs result set
	 *  @return true if loadDocumentType was set
	 */
	protected abstract boolean loadDocumentDetails (ResultSet rs);

	/**
	 *  Get Source Currency Balance - subtracts line (and tax) amounts from total - no rounding
	 *  @return positive amount, if total header is bigger than lines
	 */
	public abstract BigDecimal getBalance();

	/**
	 *  Create Facts (the accounting logic)
	 *  @param as accounting schema
	 *  @return Fact
	 */
	public abstract Fact createFact (AcctSchema as);

}   //  Doc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -