package com.reallinkbilling.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

import org.apache.struts2.dispatcher.SessionMap;

public class GetGodownDetailsById {

	public static HashMap<String, String> getGodownDetails(
			String godownId,
			SessionMap<String, Object> sessionMap,
			Connection connection) {

		HashMap<String, String> goDownDetails = new HashMap<String, String>();

		String shopId = (String) sessionMap.get("shopId");
		String shopCode = (String) sessionMap.get("shopCode");

		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;

		try {

			String sql = "SELECT "
					+ "godown_code, "
					+ "godown_name, "
					+ "godown_address "
					+ "FROM shop_godown_master "
					+ "WHERE shop_id = ? "
					+ "AND shop_code = ? "
					+ "AND godown_id = ?";

			preparedStatement = connection.prepareStatement(sql);

			preparedStatement.setString(1, shopId);
			preparedStatement.setString(2, shopCode);
			preparedStatement.setString(3, godownId);

			resultSet = preparedStatement.executeQuery();

			if (resultSet.next()) {

				goDownDetails.put(
						"GODOWNCODE",
						resultSet.getString(1)
				);

				goDownDetails.put(
						"GODOWNNAME",
						resultSet.getString(2)
				);

				goDownDetails.put(
						"GODOWNADDRESS",
						resultSet.getString(3)
				);
			}

		} catch (SQLException e) {

			// e.printStackTrace();

		} catch (Exception e) {

			// e.printStackTrace();

		} finally {

			if (resultSet != null) {

				try {

					resultSet.close();
					resultSet = null;

				} catch (SQLException e) {
				}
			}

			if (preparedStatement != null) {

				try {

					preparedStatement.close();
					preparedStatement = null;

				} catch (SQLException e) {
				}
			}
		}

		return goDownDetails;
	}
}