<?php

class Transfer_model extends CI_Model {

    public $rules_in=array(
	'sending_type' => array('field' => 'sending_type', 'label' => 'Sending Type','rules' => 'trim|required'),
	'sending_code' => array('field' => 'sending_code', 'label' => 'Sending Code','rules' => 'trim|required|is_unique[sending_money.sending_code]'),
	'sending_date' => array('field' => 'sending_date', 'label' => 'Sending Date','rules' => 'trim|required'),
	'sender_fullname' => array('field' => 'sender_fullname', 'label' => 'Sender Fullname','rules' => 'trim|required'),
	'sender_city' => array('field' => 'sender_city', 'label' => 'Sender City','rules' => 'trim|required'),
	'sender_passport' => array('field' => 'sender_passport', 'label' => 'Sender Passport','rules' => 'trim|required'),
	'passport_exp_date' => array('field' => 'passport_exp_date', 'label' => 'Passport Exp Date','rules' => 'trim|required'),
	'sending_amount' => array('field' => 'sending_amount', 'label' => 'Sending Amount','rules' => 'trim|required'),
	'cost' => array('field' => 'cost', 'label' => 'Cost','rules' => 'trim|required'),
	'total_amount' => array('field' => 'total_amount', 'label' => 'Total Amount','rules' => 'trim|required'),
	'telephone' => array('field' => 'telephone', 'label' => 'Telephone','rules' => 'trim|required'),
	'secret_question' => array('field' => 'secret_question', 'label' => 'Secret Question','rules' => 'trim|required'),
	'secret_answer' => array('field' => 'secret_answer', 'label' => 'Secret Answer','rules' => 'trim|required'),
	'recipent_fullname' => array('field' => 'recipent_fullname', 'label' => 'Recipent Fullname','rules' => 'trim|required'),
	'recipent_phone' => array('field' => 'recipent_phone', 'label' => 'Recipent Phone','rules' => 'trim|required'),
	'recipent_city' => array('field' => 'recipent_city', 'label' => 'Recipent City','rules' => 'trim|required'),
	'recipent_CNI' => array('field' => 'recipent_CNI', 'label' => 'Recipent CNI','rules' => 'trim|required'),
	'agent_id' => array('field' => 'agent_id', 'label' => 'Agent Id','rules' => 'trim|required'));

	
	 public $rules_org=array(
	'sending_type' => array('field' => 'sending_type', 'label' => 'Sending Type','rules' => 'trim|required'),
	'sending_code' => array('field' => 'sending_code', 'label' => 'Sending Code','rules' => 'trim|required|is_unique[sending_money.sending_code]'),
	'sending_date' => array('field' => 'sending_date', 'label' => 'Sending Date','rules' => 'trim|required'),
	'sender_fullname' => array('field' => 'sender_fullname', 'label' => 'Sender Fullname','rules' => 'trim|required'),
	'sending_amount' => array('field' => 'sending_amount', 'label' => 'Sending Amount','rules' => 'trim|required'),
	'cost' => array('field' => 'cost', 'label' => 'Cost','rules' => 'trim|required'),
	'total_amount' => array('field' => 'total_amount', 'label' => 'Total Amount','rules' => 'trim|required'),
	'recipent_fullname' => array('field' => 'recipent_fullname', 'label' => 'Recipent Fullname','rules' => 'trim|required'),
	'recipent_phone' => array('field' => 'recipent_phone', 'label' => 'Recipent Phone','rules' => 'trim|required'),
	'recipent_CNI' => array('field' => 'recipent_CNI', 'label' => 'Recipent CNI','rules' => 'trim|required'),
	'org_address' => array('field' => 'org_address', 'label' => 'Org Address','rules' => 'trim|required'),
	'distribution_number' => array('field' => 'distribution_number', 'label' => 'Distribution Number','rules' => 'trim|required'),
	'name_of_project' => array('field' => 'name_of_project', 'label' => 'Name Of Project','rules' => 'trim|required'),
	'agent_id' => array('field' => 'agent_id', 'label' => 'Agent Id','rules' => 'trim|required'));
	
	
	public function get_all(){
	$query=$this->db->query('SELECT sending_money.*,users.first_name,users.last_name FROM
	sending_money,users WHERE sending_money.agent_id=users.id');
	return $query->result();
	}
	
	public function get_all_invoice(){
	$this->db->select('*');
	$this->db->from('sending_money');
	$this->db->where('trash',"no");
	if(user_type()!="admin"){
	$this->db->where('agent_id',$this->session->userdata("id"));
	}
	$query=  $this->db->get();
	return $query->result();
	}
	
	public function get_by($id){
	  $this->db->select('*');
	  $this->db->from('sending_money');
	  $this->db->where('id',$id);
	  $query=  $this->db->get();
	  return $query->row();
	}

}