<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class OBDatabase {

	private $db = null;

	function __construct(&$dbConn)
	{
		$this->db = $dbConn;
	}

	public function updateDatabase($data)
	{
		$cId = $data["id"];
		$countryCode = $data["countryCode"];

		// $CI->db->field_exists($field_name, $table_name);
		// $CI->db->table_exists($table_name);
		if ($countryCode && !in_array($countryCode,array("IN","NG")))
		{
			$this->db->query('UPDATE `ob_accountgroup` SET name="Cash And Cash Equivalents" WHERE groupCode="CH" AND cId="' . $cId . '"; -- name="Cash-in-hand";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Owner\'s Equity" WHERE groupCode="CP" AND cId="' . $cId . '"; -- name="Capital Account";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Retained Earnings" WHERE groupCode="RS" AND cId="' . $cId . '"; -- name="Reserves & Surplus";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Accounts Receivable" WHERE groupCode="SD" AND cId="' . $cId . '"; -- name="Sundry Debtors";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Accounts Payable" WHERE groupCode="SC" AND cId="' . $cId . '"; -- name="Sundry Creditors";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Direct Costs" WHERE groupCode="ED" AND cId="' . $cId . '"; -- name="Direct Expenses";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Expenses" WHERE groupCode="EI" AND cId="' . $cId . '"; -- name="Indirect Expenses";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Income" WHERE groupCode="ID" AND cId="' . $cId . '"; -- name="Direct Income";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Other Income" WHERE groupCode="II" AND cId="' . $cId . '"; -- name="Indirect Income";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Inventory" WHERE groupCode="SH" AND cId="' . $cId . '"; -- name="Stock-in-hand";');
			$this->db->query('UPDATE `ob_accountgroup` SET name="Cost of Sales" WHERE groupCode="PU" AND cId="' . $cId . '"; -- name="Purchase";');

			// $this->db->query('UPDATE `ob_account` SET name="Cost of Goods Sold" WHERE accCode="PU" AND cId="' . $cId . '"; -- name="Purchase"');
			$this->db->query('UPDATE `ob_account` SET name="Accounts Receivable" WHERE accCode="AR" AND cId="' . $cId . '"; -- name="Sundry Debtors"');
			$this->db->query('UPDATE `ob_account` SET name="Accounts Payable" WHERE accCode="AP" AND cId="' . $cId . '"; -- name="Sundry Creditors"');
			if ($countryCode!="IN")
			{
				$this->db->query('UPDATE `ob_account` SET name="Retained Earnings" WHERE accCode="PL" AND cId="' . $cId . '"; -- name="Profit and Loss"');
			}
		}
	}
}

