<?php

class RecuringInvoice {

	private $CI = null;

	public function __construct()
	{
		$this->CI = &get_instance();
	}

	public function main($action)
	{
		$sendEmail = false;
		if (!empty($action["actConfig"]) && !empty($action["actConfig"]["sendEmail"]))
		{
			$sendEmail = true;
		}

		$transId = 0;
		$trans = null;
		$conIds = array();
		$contacts = array();

		$this->CI->load->model("transModel");
		$this->CI->load->model("contactsModel");

		foreach($action["ref"] as $ref)
		{
			if ($ref["refType"] == "C")
			{
				$conIds[] = $ref["refId"];
				$contacts[$ref["refId"]] = $this->CI->contactsModel->get_details($ref["refId"], array());
			}
			else if ($ref["refType"] == "T")
			{
				$transId = $ref["refId"];
				$trans = $this->CI->transModel->get_trans_item($transId);
			}
		}

		foreach($contacts as $contact)
		{
			$this->process_trans($trans, $contact);
		}
		exit;
	}

	private function process_trans($trans, $contact)
	{
		$contact["contacts"];
		$trans["address"] = $contact["address"];

		print_E($trans);
		print_E($contact);
		exit;
	}
}
