<?php
/*
* Generated by CRUDigniter v3.2
* www.crudigniter.com
*/
class Contrat_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
/*
* Get contrat by id
*/
function get_contrat($id)
{
return $this->db->get_where('contrat',array('id'=>$id))->row_array();
}
/*
* Get all contrat count
*/
function get_all_contrat_count()
{
$this->db->from('contrat');
return $this->db->count_all_results();
}
/*
* Get all contrat
*/
function get_all_contrat($params = array())
{
$this->db->select('*,contrat.id as idcontrat,typecontrat.libelle as type, users.nom as name');
$this->db->from('contrat');
$this->db->join('typecontrat', 'typecontrat.id = contrat.typecontrat_id');
$this->db->join('users', 'users.id = contrat.users_id');
$this->db->order_by('contrat.id', 'DESC');
if(isset($params) && !empty($params))
{
$this->db->limit($params['limit'], $params['offset']);
}
return $this->db->get()->result_array();
}
/*
* function to add new contrat
*/
function add_contrat($params)
{
$this->db->insert('contrat',$params);
return $this->db->insert_id();
}
/*
* function to update contrat
*/
function update_contrat($id,$params)
{
$this->db->where('id',$id);
return $this->db->update('contrat',$params);
}
/*
* function to delete contrat
*/
function delete_contrat($id)
{
return $this->db->delete('contrat',array('id'=>$id));
}
function update_solde($url){
$ch = curl_init($url); // such as http://example.com/example.xml
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_USERPWD, 'admintnmzid:GH2019*');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: */*',
'If-Match: *'
));
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$service = json_decode($data);
//print_r($service ->value);
foreach($service ->value as $item)
{
$row=$this->db->query("select * from users where trim(matricule)='".$item->No."'");
if($row->num_rows()>0)
{
$perso=$row->result();
$this->db->where("users_id",$perso[0]->id);
$saved=array("soldeconge"=>$item->Solde_de_conge);
$this->db->update("contrat",$saved);
}
}
}
}