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

require_once APPPATH . 'processors/Transaction_processor.php';

class Purord_processor extends Transaction_processor
{
/*
	public function __construct()
	{
		parent::__construct();
		// $this->ci =& get_instance();
	}
*/
	public function init_save(&$postData)
	{
		parent::init_save($postData);

		$ci =& get_instance();

		if ($this->params->isFranchise)
		{
			$this->flags->isFrPo = true;

			$data['tType'] = SALORD;

			$contact = $ci->TransModel->get_branch_address($this->params->bId);

			$data['bId'] = $this->params->bId = !empty($contact['bId']) ? $contact['bId'] : get_company('mainbId');

			$ci->load->model('contactsModel');

			$rate_sheets = $ci->contactsModel->get_rate_sheets(array(
				'id' => $contact['conId'],
				'csType' => $contact['csType']
			), array(
				'soConvert' => $this->params->bId,
				'is_default' => 1
			));


			if (empty($data["dstStateId"]))
			{
				$data['dstStateId'] 	= $contact['shippingAddr']['stateId'];
				$data['dstStateCode'] 	= $contact['shippingAddr']['stateCode'];
			}

			$data = array_merge($data, $contact);

			// Swap
			$tmp = array(
				"conStateCode" => $data["conStateCode"],
				"conStateId" => $data["conStateId"],
				"dstStateCode" => $data["dstStateCode"],
				"dstStateId" => $data["dstStateId"],
				"conTaxNo" => $data["conTaxNo"]
			);

			$data["conStateCode"] = $tmp["dstStateCode"];
			$data["conStateId"] = $tmp["dstStateId"];
			$data["dstStateCode"] = $tmp["conStateCode"];
			$data["dstStateId"] = $tmp["conStateId"];

		    $data["conTaxNo"] = $contact["taxNo"];
		}
	}

/*
	public function addValidator(&$transData)
	{
		parent::addValidator(new TransValidator($transData));
		// parent::addValidator(new SalinvValidator());
		// parent::addValidator(new SalinvValidator());
	}

	public function process_before_save(&$transData, &$postData)
	{
		parent::process_before_save($transData, $postData);

		
	}

	public function process_after_save(&$retData, &$postData)
	{
		parent::process_after_save($transData, $postData);
	}

	public function process_related_transaction($newtType, $newTransId, $tType, $transId, &$newTransData, &$postData)
	{
		parent::process_related_transaction($newtType, $newTransId, $tType, $transId, $newTransData, $postData);
	}
*/
}
