chore: initial commit
This commit is contained in:
530
api/controllers/API_Controller.php
Normal file
530
api/controllers/API_Controller.php
Normal file
@@ -0,0 +1,530 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use \WpOrg\Requests\Requests as RestapiRequests;
|
||||
|
||||
/**
|
||||
* CodeIgniter API Controller
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author Jeevan Lal
|
||||
* @license MIT
|
||||
* @version 1.1.6
|
||||
*/
|
||||
class API_Controller extends CI_Controller
|
||||
{
|
||||
/**
|
||||
* List of allowed HTTP methods
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $allowed_http_methods = ['get', 'delete', 'post', 'put', 'options', 'patch', 'head'];
|
||||
|
||||
/**
|
||||
* The request method is not supported by the following resource
|
||||
* @link http://www.restapitutorial.com/httpstatuscodes.html
|
||||
*/
|
||||
const HTTP_METHOD_NOT_ALLOWED = 405;
|
||||
|
||||
/**
|
||||
* The request cannot be fulfilled due to multiple errors
|
||||
*/
|
||||
const HTTP_BAD_REQUEST = 400;
|
||||
|
||||
/**
|
||||
* Request Timeout
|
||||
*/
|
||||
const HTTP_REQUEST_TIMEOUT = 408;
|
||||
|
||||
/**
|
||||
* The requested resource could not be found
|
||||
*/
|
||||
const HTTP_NOT_FOUND = 404;
|
||||
|
||||
/**
|
||||
* The user is unauthorized to access the requested resource
|
||||
*/
|
||||
const HTTP_UNAUTHORIZED = 401;
|
||||
|
||||
/**
|
||||
* The request has succeeded
|
||||
*/
|
||||
const HTTP_OK = 200;
|
||||
|
||||
/**
|
||||
* HTTP status codes and their respective description
|
||||
*/
|
||||
const HEADER_STATUS_STRINGS = [
|
||||
'405' => 'HTTP/1.1 405 Method Not Allowed',
|
||||
'400' => 'BAD REQUEST',
|
||||
'408' => 'Request Timeout',
|
||||
'404' => 'NOT FOUND',
|
||||
'401' => 'UNAUTHORIZED',
|
||||
'200' => 'OK',
|
||||
];
|
||||
|
||||
/**
|
||||
* API LIMIT TABLE NAME
|
||||
*/
|
||||
protected $API_LIMIT_TABLE_NAME;
|
||||
|
||||
/**
|
||||
* API KEYS TABLE NAME
|
||||
*/
|
||||
protected $API_KEYS_TABLE_NAME;
|
||||
|
||||
/**
|
||||
* RETURN DATA
|
||||
*/
|
||||
protected $return_other_data = [];
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->CI =& get_instance();
|
||||
|
||||
// load api config file
|
||||
$this->CI->load->config('api');
|
||||
|
||||
// set timezone for api limit
|
||||
date_default_timezone_set($this->CI->config->item('api_timezone'));
|
||||
|
||||
// Load Config Items Values
|
||||
$this->API_LIMIT_TABLE_NAME = $this->CI->config->item('api_limit_table_name');
|
||||
$this->API_KEYS_TABLE_NAME = $this->CI->config->item('api_keys_table_name');
|
||||
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
}
|
||||
|
||||
public function _APIConfig($config = [])
|
||||
{
|
||||
// return other data
|
||||
if(isset($config['data']))
|
||||
$this->return_other_data = $config['data'];
|
||||
|
||||
// by default method `GET`
|
||||
if ((isset($config) AND empty($config)) OR empty($config['methods'])) {
|
||||
$this->_allow_methods(['GET']);
|
||||
} else {
|
||||
$this->_allow_methods($config['methods']);
|
||||
}
|
||||
|
||||
// api limit function `_limit_method()`
|
||||
// Use provided limit or default from config
|
||||
if(isset($config['limit'])) {
|
||||
$this->_limit_method($config['limit']);
|
||||
} else {
|
||||
// Apply default limit if configured and not explicitly disabled
|
||||
$default_limit = $this->CI->config->item('api_default_limit');
|
||||
if ($default_limit !== false && !empty($default_limit)) {
|
||||
$this->_limit_method($default_limit);
|
||||
}
|
||||
}
|
||||
|
||||
// api key function `_api_key()`
|
||||
if(isset($config['key']))
|
||||
$this->_api_key($config['key']);
|
||||
|
||||
// IF Require Authentication
|
||||
if(isset($config['requireAuthorization']) AND $config['requireAuthorization'] === true) {
|
||||
$token_data = $this->_isAuthorized();
|
||||
|
||||
// remove api time in user token data
|
||||
unset($token_data->API_TIME);
|
||||
// return token decode data
|
||||
return [ 'token_data' => (array) $token_data ];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow Methods
|
||||
* -------------------------------------
|
||||
* @param: {array} request methods
|
||||
*/
|
||||
public function _allow_methods(array $methods)
|
||||
{
|
||||
$REQUEST_METHOD = $this->CI->input->server('REQUEST_METHOD', TRUE);
|
||||
|
||||
// check request method in `$allowed_http_methods` array()
|
||||
if (in_array(strtolower($REQUEST_METHOD), $this->allowed_http_methods))
|
||||
{
|
||||
// check request method in user define `$methods` array()
|
||||
if (in_array(strtolower($REQUEST_METHOD), $methods) OR in_array(strtoupper($REQUEST_METHOD), $methods))
|
||||
{
|
||||
// allow request method
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// not allow request method
|
||||
$this->_response(['status' => FALSE, 'error' => 'Unknown method'], self::HTTP_METHOD_NOT_ALLOWED);
|
||||
}
|
||||
} else {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Unknown method'], self::HTTP_METHOD_NOT_ALLOWED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit Method
|
||||
* ------------------------
|
||||
* @param: {int} number
|
||||
* @param: {type} ip
|
||||
*
|
||||
* Total Number Limit without Time
|
||||
*
|
||||
* @param: {minute} time/everyday
|
||||
* Total Number Limit with Last {3,4,5...} minute
|
||||
* --------------------------------------------------------
|
||||
*/
|
||||
public function _limit_method(array $data)
|
||||
{
|
||||
// check limit number
|
||||
if (!isset($data[0])) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Limit Number Required'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// check limit type
|
||||
if (!isset($data[1])) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Limit Type Required'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (!isset($this->db)) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Load CodeIgniter Database Library'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// check limit database table exists
|
||||
if (!$this->db->table_exists($this->API_LIMIT_TABLE_NAME)) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Create API Limit Database Table'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$limit_num = $data[0]; // limit number
|
||||
$limit_type = $data[1]; // limit type
|
||||
|
||||
$limit_time = isset($data[2])? $data[2]:''; // time minute
|
||||
|
||||
if ($limit_type == 'ip')
|
||||
{
|
||||
$where_data_ip = [
|
||||
'uri' => $this->CI->uri->uri_string(),
|
||||
'class' => $this->CI->router->fetch_class(),
|
||||
'method' => $this->CI->router->fetch_method(),
|
||||
'ip_address' => $this->CI->input->ip_address(),
|
||||
];
|
||||
|
||||
$limit_query = $this->CI->db->get_where($this->API_LIMIT_TABLE_NAME, $where_data_ip);
|
||||
if ($this->db->affected_rows() >= $limit_num)
|
||||
{
|
||||
// time limit not empty
|
||||
if (isset($limit_time) AND !empty($limit_time))
|
||||
{
|
||||
// if time limit `numeric` numbers
|
||||
if (is_numeric($limit_time))
|
||||
{
|
||||
$limit_timestamp = time() - ($limit_time*60);
|
||||
// echo Date('d/m/Y h:i A', $times);
|
||||
|
||||
$where_data_ip_with_time = [
|
||||
'uri' => $this->CI->uri->uri_string(),
|
||||
'class' => $this->CI->router->fetch_class(),
|
||||
'method' => $this->CI->router->fetch_method(),
|
||||
'ip_address' => $this->CI->input->ip_address(),
|
||||
'time >=' => $limit_timestamp
|
||||
];
|
||||
|
||||
$time_limit_query = $this->CI->db->get_where($this->API_LIMIT_TABLE_NAME, $where_data_ip_with_time);
|
||||
// echo $this->CI->db->last_query();
|
||||
if ($this->db->affected_rows() >= $limit_num)
|
||||
{
|
||||
$this->_response(['status' => FALSE, 'error' => 'This IP Address has reached the time limit for this method'], self::HTTP_REQUEST_TIMEOUT);
|
||||
} else
|
||||
{
|
||||
// insert limit data
|
||||
$this->limit_data_insert();
|
||||
}
|
||||
}
|
||||
|
||||
// if time limit equal to `everyday`
|
||||
if ($limit_time == 'everyday')
|
||||
{
|
||||
$this->CI->load->helper('date');
|
||||
|
||||
$bad_date = mdate('%d-%m-%Y', time());
|
||||
|
||||
$start_date = nice_date($bad_date .' 12:00 AM', 'd-m-Y h:i A'); // {DATE} 12:00 AM
|
||||
$end_date = nice_date($bad_date .' 12:00 PM', 'd-m-Y h:i A'); // {DATE} 12:00 PM
|
||||
|
||||
$start_date_timestamp = strtotime($start_date);
|
||||
$end_date_timestamp = strtotime($end_date);
|
||||
|
||||
$where_data_ip_with_time = [
|
||||
'uri' => $this->CI->uri->uri_string(),
|
||||
'class' => $this->CI->router->fetch_class(),
|
||||
'method' => $this->CI->router->fetch_method(),
|
||||
'ip_address' => $this->CI->input->ip_address(),
|
||||
'time >=' => $start_date_timestamp,
|
||||
'time <=' => $end_date_timestamp,
|
||||
];
|
||||
|
||||
$time_limit_query = $this->CI->db->get_where($this->API_LIMIT_TABLE_NAME, $where_data_ip_with_time);
|
||||
// echo $this->CI->db->last_query();exit;
|
||||
if ($this->db->affected_rows() >= $limit_num)
|
||||
{
|
||||
$this->_response(['status' => FALSE, 'error' => 'This IP Address has reached the time limit for this method'], self::HTTP_REQUEST_TIMEOUT);
|
||||
} else {
|
||||
// insert limit data
|
||||
$this->limit_data_insert();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->_response(['status' => FALSE, 'error' => 'This IP Address has reached limit for this method'], self::HTTP_REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
} else {
|
||||
// insert limit data
|
||||
$this->limit_data_insert();
|
||||
}
|
||||
} else {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Limit Type Invalid'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit Data Insert
|
||||
*/
|
||||
private function limit_data_insert()
|
||||
{
|
||||
$this->CI->load->helper('api_helper');
|
||||
|
||||
$insert_data = [
|
||||
'uri' => $this->CI->uri->uri_string(),
|
||||
'class' => $this->CI->router->fetch_class(),
|
||||
'method' => $this->CI->router->fetch_method(),
|
||||
'ip_address' => $this->CI->input->ip_address(),
|
||||
'time' => time(),
|
||||
];
|
||||
|
||||
insert($this->API_LIMIT_TABLE_NAME, $insert_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* API key
|
||||
*/
|
||||
private function _api_key(array $key)
|
||||
{
|
||||
if (!isset($key[0])) {
|
||||
$api_key_type = 'header';
|
||||
} else {
|
||||
$api_key_type = $key[0];
|
||||
}
|
||||
|
||||
if (!isset($key[1])) {
|
||||
$api_key = 'table';
|
||||
} else {
|
||||
$api_key = $key[1];
|
||||
}
|
||||
|
||||
// api key type `Header`
|
||||
if (strtolower($api_key_type) == 'header')
|
||||
{
|
||||
$api_key_header_name = $this->config->item('api_key_header_name');
|
||||
|
||||
// check api key header name in request headers
|
||||
$is_header = $this->exists_header($api_key_header_name); // return status and header value
|
||||
if (isset($is_header['status']) === TRUE)
|
||||
{
|
||||
$HEADER_VALUE = trim($is_header['value'] ?? '');
|
||||
|
||||
// if api key equal to `table`
|
||||
if ($api_key != "table")
|
||||
{
|
||||
if ($HEADER_VALUE != $api_key) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
} else {
|
||||
if (!isset($this->db)) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Load CodeIgniter Database Library'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// check api key database table exists
|
||||
if (!$this->db->table_exists($this->API_KEYS_TABLE_NAME)) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Create API Key Database Table'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$where_key_data = [
|
||||
'controller' => $this->CI->router->fetch_class(),
|
||||
'api_key' => $HEADER_VALUE,
|
||||
];
|
||||
|
||||
$limit_query = $this->CI->db->get_where($this->API_KEYS_TABLE_NAME, $where_key_data);
|
||||
if (!$this->db->affected_rows() > 0)
|
||||
{
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Set API Key in Request Header'], self::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else if (strtolower($api_key_type) == 'get') // // api key type `get`
|
||||
{
|
||||
// return status and header value `Content-Type`
|
||||
$is_header = $this->exists_header('Content-Type');
|
||||
if (isset($is_header['status']) === TRUE) {
|
||||
if ($is_header['value'] === "application/json")
|
||||
{
|
||||
$stream_clean = $this->CI->security->xss_clean($this->CI->input->raw_input_stream);
|
||||
$_GET = json_decode($stream_clean, true);
|
||||
}
|
||||
}
|
||||
|
||||
$api_key_get_name = $this->config->item('api_key_get_name');
|
||||
|
||||
$get_param_value = $this->CI->input->get($api_key_get_name, TRUE);
|
||||
if (!empty($get_param_value) AND is_string($get_param_value))
|
||||
{
|
||||
// if api key equal to `table`
|
||||
if ($api_key != "table")
|
||||
{
|
||||
if ($get_param_value != $api_key) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
} else {
|
||||
if (!isset($this->db)) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Load CodeIgniter Database Library'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// check api key database table exists
|
||||
if (!$this->db->table_exists($this->API_KEYS_TABLE_NAME)) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Create API Key Database Table'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$where_key_data = [
|
||||
'controller' => $this->CI->router->fetch_class(),
|
||||
'api_key' => $get_param_value,
|
||||
];
|
||||
|
||||
$limit_query = $this->CI->db->get_where($this->API_KEYS_TABLE_NAME, $where_key_data);
|
||||
if (!$this->db->affected_rows() > 0)
|
||||
{
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key GET Parameter Required'], self::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else if (strtolower($api_key_type) == 'post') // // api key type `post`
|
||||
{
|
||||
// return status and header value `Content-Type`
|
||||
$is_header = $this->exists_header('Content-Type');
|
||||
if (isset($is_header['status']) === TRUE) {
|
||||
if ($is_header['value'] === "application/json")
|
||||
{
|
||||
$stream_clean = $this->CI->security->xss_clean($this->CI->input->raw_input_stream);
|
||||
$_POST = json_decode($stream_clean, true);
|
||||
}
|
||||
}
|
||||
|
||||
$api_key_post_name = $this->config->item('api_key_post_name');
|
||||
|
||||
$get_param_value = $this->CI->input->post($api_key_post_name, TRUE);
|
||||
if (!empty($get_param_value) AND is_string($get_param_value))
|
||||
{
|
||||
// if api key equal to `table`
|
||||
if ($api_key != "table")
|
||||
{
|
||||
if ($get_param_value != $api_key) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
} else {
|
||||
if (!isset($this->db)) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Load CodeIgniter Database Library'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// check api key database table exists
|
||||
if (!$this->db->table_exists($this->API_KEYS_TABLE_NAME)) {
|
||||
$this->_response(['status' => FALSE, 'error' => 'Create API Key Database Table'], self::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$where_key_data = [
|
||||
'controller' => $this->CI->router->fetch_class(),
|
||||
'api_key' => $get_param_value,
|
||||
];
|
||||
|
||||
$limit_query = $this->CI->db->get_where($this->API_KEYS_TABLE_NAME, $where_key_data);
|
||||
if (!$this->db->affected_rows() > 0)
|
||||
{
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key POST Parameter Required'], self::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$this->_response(['status' => FALSE, 'error' => 'API Key Parameter Required'], self::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Authorized
|
||||
*/
|
||||
private function _isAuthorized()
|
||||
{
|
||||
// Load Authorization Library
|
||||
$this->CI->load->library('authorization_token');
|
||||
|
||||
// check token is valid
|
||||
$result = $this->authorization_token->validateToken();
|
||||
|
||||
if (isset($result['status']) AND $result['status'] === true)
|
||||
{
|
||||
return $result['data'];
|
||||
} else {
|
||||
$this->_response(['status' => FALSE, 'error' => $result['message']], self::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Request Header Exists
|
||||
* @return ['status' => true, 'value' => value ]
|
||||
*/
|
||||
private function exists_header($header_name)
|
||||
{
|
||||
$headers = apache_request_headers();
|
||||
foreach ($headers as $header => $value) {
|
||||
if ($header === $header_name) {
|
||||
return ['status' => true, 'value' => $value ];
|
||||
}
|
||||
}
|
||||
return ['status' => false, 'value' => null];
|
||||
}
|
||||
|
||||
/**
|
||||
* Private Response Function
|
||||
*/
|
||||
private function _response($data = NULL, $http_code = NULL)
|
||||
{
|
||||
ob_start();
|
||||
header('content-type:application/json; charset=UTF-8');
|
||||
header(self::HEADER_STATUS_STRINGS[$http_code], true, $http_code);
|
||||
if (!is_array($this->return_other_data)) {
|
||||
print_r(json_encode(['status' => false, 'error' => 'Invalid data format']));
|
||||
} else {
|
||||
print_r(json_encode(array_merge($data, $this->return_other_data)));
|
||||
}
|
||||
ob_end_flush();
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Public Response Function
|
||||
*/
|
||||
public function api_return($data = NULL, $http_code = NULL)
|
||||
{
|
||||
ob_start();
|
||||
header('content-type:application/json; charset=UTF-8');
|
||||
header(self::HEADER_STATUS_STRINGS[$http_code], true, $http_code);
|
||||
print_r(json_encode($data));
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
}
|
||||
220
api/controllers/Api.php
Normal file
220
api/controllers/Api.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
use \WpOrg\Requests\Requests as RestapiRequests;
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Api extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('api_model');
|
||||
$this->load->library('app_modules');
|
||||
|
||||
if (!$this->app_modules->is_active('api')) {
|
||||
access_denied("Api");
|
||||
}
|
||||
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
}
|
||||
|
||||
public function api_management()
|
||||
{
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
$data['user_api'] = $this->api_model->get_user();
|
||||
$data['title'] = _l('api_management');
|
||||
$this->load->view('api_management', $data);
|
||||
}
|
||||
|
||||
/* API user statistics */
|
||||
public function user_stats($id = '')
|
||||
{
|
||||
\modules\api\core\Apiinit::ease_of_mind('api');
|
||||
|
||||
if (!is_admin()) {
|
||||
access_denied('User Statistics');
|
||||
}
|
||||
|
||||
$data['title'] = _l('user_statistics');
|
||||
$data['user_id'] = $id;
|
||||
|
||||
if ($id) {
|
||||
$user_api = $this->api_model->get_user($id);
|
||||
$data['user_api'] = $user_api && count($user_api) ? $user_api[0] : null;
|
||||
|
||||
if ($data['user_api']) {
|
||||
$data['quota_summary'] = $this->api_model->get_quota_summary($data['user_api']['token']);
|
||||
$data['quota_stats'] = $this->api_model->get_quota_stats($data['user_api']['token']);
|
||||
$data['top_endpoints'] = $this->api_model->get_top_endpoints($data['user_api']['token']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['api_users'] = $this->api_model->get_user();
|
||||
$this->load->view('user_stats', $data);
|
||||
}
|
||||
|
||||
public function api_guide()
|
||||
{
|
||||
fopen(APP_MODULES_PATH . 'api/views/apidoc/index.html', 'r');
|
||||
}
|
||||
|
||||
/* Add new user or update existing*/
|
||||
public function user()
|
||||
{
|
||||
\modules\api\core\Apiinit::ease_of_mind('api');
|
||||
|
||||
if (!is_admin()) {
|
||||
access_denied('Ticket Priorities');
|
||||
}
|
||||
if ($this->input->post()) {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
if (!$this->input->post('id')) {
|
||||
$id = $this->api_model->add_user($this->input->post());
|
||||
|
||||
if ($id) {
|
||||
set_alert('success', _l('added_successfully', _l('user_api')));
|
||||
}
|
||||
redirect(admin_url('api/api_management'));
|
||||
} else {
|
||||
$data = $this->input->post();
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
$success = $this->api_model->update_user($data, $id);
|
||||
if ($success) {
|
||||
set_alert('success', _l('updated_successfully', _l('user_api')));
|
||||
}
|
||||
redirect(admin_url('api/api_management'));
|
||||
}
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update user quotas */
|
||||
public function update_user_quotas()
|
||||
{
|
||||
\modules\api\core\Apiinit::ease_of_mind('api');
|
||||
|
||||
if (!is_admin()) {
|
||||
access_denied('User Quotas');
|
||||
}
|
||||
|
||||
if ($this->input->post()) {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
$data = $this->input->post();
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
|
||||
// Add timestamp for quota update
|
||||
$data['quota_updated_at'] = date('Y-m-d H:i:s');
|
||||
|
||||
$success = $this->api_model->update_user($data, $id);
|
||||
if ($success) {
|
||||
set_alert('success', _l('quota_updated_successfully'));
|
||||
} else {
|
||||
set_alert('danger', _l('quota_update_failed'));
|
||||
}
|
||||
redirect(admin_url('api/api_management'));
|
||||
}
|
||||
}
|
||||
|
||||
/* Edit user */
|
||||
public function create_user()
|
||||
{
|
||||
\modules\api\core\Apiinit::ease_of_mind('api');
|
||||
|
||||
if (!is_admin()) {
|
||||
access_denied('User');
|
||||
}
|
||||
$data['title'] = _l('new_user_api');
|
||||
$this->load->view('create_user_api', $data);
|
||||
}
|
||||
|
||||
/* Edit user */
|
||||
public function edit_user($id)
|
||||
{
|
||||
\modules\api\core\Apiinit::ease_of_mind('api');
|
||||
|
||||
if (!is_admin()) {
|
||||
access_denied('User');
|
||||
}
|
||||
if (!$id) {
|
||||
redirect(admin_url('api/api_management'));
|
||||
}
|
||||
$user_api = $this->api_model->get_user($id);
|
||||
$data['user_api'] = $user_api && count($user_api) ? $user_api[0] : null;
|
||||
$data['title'] = _l('edit_user_api');
|
||||
$this->load->view('edit_user_api', $data);
|
||||
}
|
||||
|
||||
|
||||
/* Delete user */
|
||||
public function delete_user($id)
|
||||
{
|
||||
\modules\api\core\Apiinit::ease_of_mind('api');
|
||||
|
||||
if (!is_admin()) {
|
||||
access_denied('User');
|
||||
}
|
||||
if (!$id) {
|
||||
redirect(admin_url('api/api_management'));
|
||||
}
|
||||
$response = $this->api_model->delete_user($id);
|
||||
if ($response == true) {
|
||||
set_alert('success', _l('deleted', _l('user_api')));
|
||||
}
|
||||
redirect(admin_url('api/api_management'));
|
||||
}
|
||||
|
||||
/* Get user statistics data via AJAX */
|
||||
public function get_user_stats_data()
|
||||
{
|
||||
if (!$this->input->is_ajax_request()) {
|
||||
show_404();
|
||||
}
|
||||
|
||||
$user_id = $this->input->post('user_id');
|
||||
$days = $this->input->post('days') ?: 30;
|
||||
|
||||
if ($user_id) {
|
||||
$user_api = $this->api_model->get_user($user_id);
|
||||
if ($user_api && count($user_api)) {
|
||||
$api_key = $user_api[0]['token'];
|
||||
$quota_summary = $this->api_model->get_quota_summary($api_key);
|
||||
$quota_stats = $this->api_model->get_quota_stats($api_key, $days);
|
||||
$top_endpoints = $this->api_model->get_top_endpoints($api_key);
|
||||
|
||||
echo json_encode([
|
||||
'quota_summary' => $quota_summary,
|
||||
'quota_stats' => $quota_stats,
|
||||
'top_endpoints' => $top_endpoints
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(['error' => 'User not found']);
|
||||
}
|
||||
|
||||
/* Clean old logs */
|
||||
public function clean_logs()
|
||||
{
|
||||
if (!is_admin()) {
|
||||
access_denied('api_management');
|
||||
}
|
||||
|
||||
$days = $this->input->post('days') ?: 90;
|
||||
|
||||
if ($this->api_model->clean_old_logs($days)) {
|
||||
set_alert('success', _l('logs_cleaned_successfully'));
|
||||
} else {
|
||||
set_alert('danger', _l('log_cleaning_failed'));
|
||||
}
|
||||
|
||||
redirect(admin_url('api/api_management'));
|
||||
}
|
||||
}
|
||||
296
api/controllers/Calendar.php
Normal file
296
api/controllers/Calendar.php
Normal file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
class Calendar extends REST_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/calendar/ Get All Calendar Events
|
||||
* @apiName GetCalendarEvents
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiGroup Calendar Events
|
||||
*
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "eventid": "1",
|
||||
* "title": "Hello",
|
||||
* "description": "test",
|
||||
* "userid": "1",
|
||||
* "start": "2023-12-12 07:00:00",
|
||||
* "end": 2023-12-12 07:00:00,
|
||||
* "public": "1",
|
||||
* "color": "#03a9f4",
|
||||
* "isstartnotified": "0",
|
||||
* "reminder_before": "30",
|
||||
* "reminder_before_type": "minutes"
|
||||
* },
|
||||
* {
|
||||
* "eventid": "2",
|
||||
* "title": "Hello2",
|
||||
* "description": "test2",
|
||||
* "userid": "2",
|
||||
* "start": "2022-12-12 07:00:00",
|
||||
* "end": 2022-12-12 07:00:00,
|
||||
* "public": "0",
|
||||
* "color": "#03a9f4",
|
||||
* "isstartnotified": "0",
|
||||
* "reminder_before": "3",
|
||||
* "reminder_before_type": "hours"
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {get} api/calendar/:id Request Specific Event Information
|
||||
* @apiName GetCalendarEvent
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiGroup Calendar Events
|
||||
*
|
||||
* @apiParam {id} id Event data by id.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "eventid": "1",
|
||||
* "title": "Hello",
|
||||
* "description": "test",
|
||||
* "userid": "1",
|
||||
* "start": "2023-12-12 07:00:00",
|
||||
* "end": 2023-12-12 07:00:00,
|
||||
* "public": "1",
|
||||
* "color": "#03a9f4",
|
||||
* "isstartnotified": "0",
|
||||
* "reminder_before": "30",
|
||||
* "reminder_before_type": "minutes"
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '')
|
||||
{
|
||||
$data = $this->Api_model->get_table('events', $id);
|
||||
|
||||
if ($data) {
|
||||
$this->response($data, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/calendar/ Create a new Calendar Event
|
||||
* @apiName PostCalendarEvent
|
||||
* @apiGroup Calendar Events
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {String} title Required event title.
|
||||
* @apiParam {String} description Optional event description.
|
||||
* @apiParam {Date} start Required event start date.
|
||||
* @apiParam {Date} start Optional event end date.
|
||||
* @apiParam {String} reminder_before_type Required value of reminder before type.
|
||||
* @apiParam {Number} reminder_before Required value of reminder before.
|
||||
* @apiParam {String} color Optional event color.
|
||||
* @apiParam {Number} userid Required user id.
|
||||
* @apiParam {Number} isstartnotified Required isstartnotified status.
|
||||
* @apiParam {Number} public Required public status.
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* 'title' => string 'Hello'
|
||||
* 'start' => date '2023/12/12 07:00'
|
||||
* 'end' => date '2023/12/12 07:00'
|
||||
* 'reminder_before' => number '10'
|
||||
* 'reminder_before_type' => string 'minutes'
|
||||
* 'color' => string 'red'
|
||||
* 'description' => string 'for test'
|
||||
* 'userid' => number '1'
|
||||
* 'public' => number '1' (0/1)
|
||||
* 'isstartnotified' => number '0'
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Data Added Successfully"
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Data Creation Failed"
|
||||
* }
|
||||
*/
|
||||
public function data_post()
|
||||
{
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
$data = $this->input->post();
|
||||
|
||||
if (empty($data['color'])) {
|
||||
$data['color'] = '#28B8DA';
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('title', 'Title', 'trim|required');
|
||||
$this->form_validation->set_rules('description', 'Description', 'trim');
|
||||
$this->form_validation->set_rules('start', 'Start Date', 'trim|required');
|
||||
$this->form_validation->set_rules('end', 'End Date', 'trim');
|
||||
$this->form_validation->set_rules('reminder_before', 'Value', 'numeric|required');
|
||||
$this->form_validation->set_rules('reminder_before_type', 'reminder_type', 'trim|required');
|
||||
$this->form_validation->set_rules('color', 'Event Color', 'trim');
|
||||
$this->form_validation->set_rules('userid', 'Userid', 'numeric|required');
|
||||
$this->form_validation->set_rules('isstartnotified', 'Isstartnotified', 'numeric|required');
|
||||
$this->form_validation->set_rules('public', 'Public', 'numeric|required');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
|
||||
$id = $this->Api_model->event($data);
|
||||
|
||||
if ($id > 0 && !empty($id)) {
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Data Added Successfully',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Add Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/calendar/:id Update a Calendar Event
|
||||
* @apiName UpdateCalendarEvent
|
||||
* @apiGroup Calendar Events
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {id} unique ID for update data.
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "title": "Hello",
|
||||
* "start": "2023/12/12 07:00",
|
||||
* "end": "2023/12/12 07:00",
|
||||
* "reminder_before": "10",
|
||||
* "reminder_before_type": "minutes",
|
||||
* "color": "red",
|
||||
* "description": "for test",
|
||||
* "userid":6,
|
||||
* "public":1,
|
||||
* "isstartnotified":1
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Data Update Successful."
|
||||
* }
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Data Update Fail"
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '')
|
||||
{
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid data or missing Send ID. please provide updated data ID.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$_POST['eventid'] = $id;
|
||||
$update_data = $this->input->post();
|
||||
|
||||
$data = $_POST;
|
||||
$output = $this->Api_model->event($data);
|
||||
|
||||
if ($output > 0 && !empty($output)) {
|
||||
$message = array('status' => TRUE, 'message' => 'Data Update Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Update Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @api {delete} api/calendar/:id Delete a Calendar Event
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName DeleteCalendarEvent
|
||||
* @apiGroup Calendar Events
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {Number} ID ID for data deletion.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Data Deleted Successfully"
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Data Delete Fail"
|
||||
* }
|
||||
*/
|
||||
|
||||
public function data_delete($id = '')
|
||||
{
|
||||
$id = $this->security->xss_clean($id);
|
||||
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('utilities_model');
|
||||
$output = $this->utilities_model->delete_event($id);
|
||||
|
||||
if ($output === TRUE) {
|
||||
$message = array('status' => TRUE, 'message' => 'Delete Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Delete Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
50
api/controllers/Check.php
Normal file
50
api/controllers/Check.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* @OA\Tag(
|
||||
* name="Check",
|
||||
* description="Common API endpoints"
|
||||
* )
|
||||
*/
|
||||
class Check extends REST_Controller
|
||||
{
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/common/data/{type}",
|
||||
* tags={"Common"},
|
||||
* summary="Get common data",
|
||||
* description="Retrieve common system data",
|
||||
* operationId="getCommonData",
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\Parameter(
|
||||
* name="type",
|
||||
* in="path",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* enum={"expense_category", "payment_mode", "tax_data"}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Successful operation"
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=400,
|
||||
* description="Invalid request"
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=404,
|
||||
* description="Not found"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function data_get($type = "")
|
||||
{
|
||||
// Existing implementation
|
||||
}
|
||||
}
|
||||
179
api/controllers/Common.php
Normal file
179
api/controllers/Common.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require __DIR__.'/REST_Controller.php';
|
||||
|
||||
class Common extends REST_Controller {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function data_get($type = "")
|
||||
{
|
||||
$allowed_type = ["expense_category", "payment_mode", "tax_data"];
|
||||
if (empty($type) || !in_array($type, $allowed_type)) {
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Not valid data'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
$data = $this->{$type}();
|
||||
if (empty($data)) {
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/common/expense_category Request Expense category
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetExpense category
|
||||
* @apiGroup Expense Categories
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiSuccess {Array} Expense category information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
*
|
||||
* [
|
||||
* {
|
||||
* "id": "1",
|
||||
* "name": "cloud server",
|
||||
* "description": "AWS server"
|
||||
* },
|
||||
* {
|
||||
* "id": "2",
|
||||
* "name": "website domain",
|
||||
* "description": "domain Managment and configurations"
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
|
||||
public function expense_category()
|
||||
{
|
||||
$this->load->model('expenses_model');
|
||||
return $this->expenses_model->get_category();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/common/payment_mode Request Payment Modes
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetPayment Mode
|
||||
* @apiGroup Payment Modes
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiSuccess {Array} Payment Modes.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "id": "1",
|
||||
* "name": "Bank",
|
||||
* "description": null,
|
||||
* "show_on_pdf": "0",
|
||||
* "invoices_only": "0",
|
||||
* "expenses_only": "0",
|
||||
* "selected_by_default": "1",
|
||||
* "active": "1"
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function payment_mode()
|
||||
{
|
||||
$this->load->model('payment_modes_model');
|
||||
return $this->payment_modes_model->get('', [
|
||||
'invoices_only !=' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/common/tax_data Request Taxes
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetTaxes
|
||||
* @apiGroup Taxes
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiSuccess {Array} Tax information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "id": "4",
|
||||
* "name": "PAYPAL",
|
||||
* "taxrate": "5.00"
|
||||
* },
|
||||
* {
|
||||
* "id": "1",
|
||||
* "name": "CGST",
|
||||
* "taxrate": "9.00"
|
||||
* },
|
||||
* {
|
||||
* "id": "2",
|
||||
* "name": "SGST",
|
||||
* "taxrate": "9.00"
|
||||
* },
|
||||
* {
|
||||
* "id": "3",
|
||||
* "name": "GST",
|
||||
* "taxrate": "18.00"
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
|
||||
public function tax_data()
|
||||
{
|
||||
$this->load->model('taxes_model');
|
||||
return $this->taxes_model->get();
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file Common.php */
|
||||
/* Location: ./application/controllers/Common.php */
|
||||
522
api/controllers/Contacts.php
Normal file
522
api/controllers/Contacts.php
Normal file
@@ -0,0 +1,522 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Contacts extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
$this->load->model('authentication_model');
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/contacts/:customer_id/:contact_id List all Contacts of a Customer
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName GetContact
|
||||
* @apiGroup Contacts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} customer_id Mandatory Customer unique ID
|
||||
* @apiParam {Number} contact_id Optional Contact unique ID <br/><i>Note : if you don't pass Contact id then it will list all contacts of the customer</i>
|
||||
*
|
||||
* @apiSuccess {Object} Contact Contact information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "6",
|
||||
* "userid": "1",
|
||||
* "company": "xyz",
|
||||
* "vat": "",
|
||||
* "phonenumber": "1234567890",
|
||||
* "country": "0",
|
||||
* "city": "",
|
||||
* "zip": "360005",
|
||||
* "state": "",
|
||||
* "address": "",
|
||||
* "website": "",
|
||||
* "datecreated": "2020-08-19 20:07:49",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "billing_street": "",
|
||||
* "billing_city": "",
|
||||
* "billing_state": "",
|
||||
* "billing_zip": "",
|
||||
* "billing_country": "0",
|
||||
* "shipping_street": "",
|
||||
* "shipping_city": "",
|
||||
* "shipping_state": "",
|
||||
* "shipping_zip": "",
|
||||
* "shipping_country": "0",
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "english",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "addedfrom": "1"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status
|
||||
* @apiError {String} message No data were found
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($customer_id = '', $contact_id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
if (empty($contact_id) && !empty($customer_id)) {
|
||||
$data = $this->Api_model->get_table('all_contacts', $customer_id);
|
||||
}
|
||||
if (!empty($contact_id) && !empty($customer_id)) {
|
||||
$data = $this->Api_model->get_table('contacts', $contact_id);
|
||||
}
|
||||
if (empty($contact_id) && empty($customer_id)) {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "contacts", $contact_id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/contacts/search/:keysearch Search Contact Information
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName GetContactSearch
|
||||
* @apiGroup Contacts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords
|
||||
*
|
||||
* @apiSuccess {Object} Contact Contact information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "8",
|
||||
* "userid": "1",
|
||||
* "is_primary": "0",
|
||||
* "firstname": "chirag",
|
||||
* "lastname": "jagani",
|
||||
* "email": "useremail@gmail.com",
|
||||
* "phonenumber": "",
|
||||
* "title": null,
|
||||
* "datecreated": "2020-05-19 20:07:49",
|
||||
* "password": "$2a$08$6DLJFalqvJGVymCwW2ppNe9HOG5YUP04vzthXZjOFFUQknxfG6QHe",
|
||||
* "new_pass_key": null,
|
||||
* "new_pass_key_requested": null,
|
||||
* "email_verified_at": "2020-08-28 21:36:06",
|
||||
* "email_verification_key": null,
|
||||
* "email_verification_sent_at": null,
|
||||
* "last_ip": null,
|
||||
* "last_login": null,
|
||||
* "last_password_change": null,
|
||||
* "active": "1",
|
||||
* "profile_image": null,
|
||||
* "direction": null,
|
||||
* "invoice_emails": "0",
|
||||
* "estimate_emails": "0",
|
||||
* "credit_note_emails": "0",
|
||||
* "contract_emails": "0",
|
||||
* "task_emails": "0",
|
||||
* "project_emails": "0",
|
||||
* "ticket_emails": "0",
|
||||
* "company": "trueline",
|
||||
* "vat": "",
|
||||
* "country": "0",
|
||||
* "city": "",
|
||||
* "zip": "",
|
||||
* "state": "",
|
||||
* "address": "",
|
||||
* "website": "",
|
||||
* "leadid": null,
|
||||
* "billing_street": "",
|
||||
* "billing_city": "",
|
||||
* "billing_state": "",
|
||||
* "billing_zip": "",
|
||||
* "billing_country": "0",
|
||||
* "shipping_street": "",
|
||||
* "shipping_city": "",
|
||||
* "shipping_state": "",
|
||||
* "shipping_zip": "",
|
||||
* "shipping_country": "0",
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "english",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "addedfrom": "1"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status
|
||||
* @apiError {String} message No data were found
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->search('contacts', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "contacts");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/contacts/ Add New Contact
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName PostContact
|
||||
* @apiGroup Contacts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} customer_id Mandatory Customer id.
|
||||
* @apiParam {String} firstname Mandatory First Name
|
||||
* @apiParam {String} lastname Mandatory Last Name
|
||||
* @apiParam {String} email Mandatory E-mail
|
||||
* @apiParam {String} [title] Optional Position
|
||||
* @apiParam {String} [phonenumber] Optional Phone Number
|
||||
* @apiParam {String} [direction = 'rtl'] Optional Direction (rtl or ltr)
|
||||
* @apiParam {String} [password] Optional password (only required if you pass send_set_password_email parameter)
|
||||
* @apiParam {String} [is_primary = 'on'] Optional Primary Contact (set on or don't pass it)
|
||||
* @apiParam {String} [donotsendwelcomeemail] Optional Do Not Send Welcome Email (set on or don't pass it)
|
||||
* @apiParam {String} [send_set_password_email] Optional Send Set Password Email (set on or don't pass it)
|
||||
* @apiParam {Array} [permissions] Optional Permissions for this contact(["1", "2", "3", "4", "5", "6" ])<br/>
|
||||
* [<br/>
|
||||
* "1", // Invoices permission<br/>
|
||||
* "2", // Estimates permission<br/>
|
||||
* "3", // Contracts permission<br/>
|
||||
* "4", // Proposals permission<br/>
|
||||
* "5", // Support permission<br/>
|
||||
* "6" // Projects permission<br/>
|
||||
* ]
|
||||
* @apiParam {String} [invoice_emails = "invoice_emails"] Optional E-Mail Notification for Invoices (set value same as name or don't pass it)
|
||||
* @apiParam {String} [estimate_emails = "estimate_emails"] Optional E-Mail Notification for Estimate (set value same as name or don't pass it)
|
||||
* @apiParam {String} [credit_note_emails = "credit_note_emails"] Optional E-Mail Notification for Credit Note (set value same as name or don't pass it)
|
||||
* @apiParam {String} [project_emails = "project_emails"] Optional E-Mail Notification for Project (set value same as name or don't pass it)
|
||||
* @apiParam {String} [ticket_emails = "ticket_emails"] Optional E-Mail Notification for Tickets (set value same as name or don't pass it)
|
||||
* @apiParam {String} [task_emails = "task_emails"] Optional E-Mail Notification for Task (set value same as name or don't pass it)
|
||||
* @apiParam {String} [contract_emails ="contract_emails"] Optional E-Mail Notification for Contract (set value same as name or don't pass it)
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Contact added successfully.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Contact added successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status
|
||||
* @apiError {String} message Contact add fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Contact add fail"
|
||||
* }
|
||||
*
|
||||
* @apiError {String} email This Email is already exists
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "email":"This Email is already exists"
|
||||
* },
|
||||
* "message": "This Email is already exists"
|
||||
* }
|
||||
*/
|
||||
public function data_post() {
|
||||
$data = $this->input->post();
|
||||
$send_set_password_email = isset($data['send_set_password_email']) ? true : false;
|
||||
if ($send_set_password_email) {
|
||||
unset($data['password']);
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|max_length[255]|is_unique[' . db_prefix() . 'contacts.email]', array('is_unique' => 'This %s is already exists'));
|
||||
if ($send_set_password_email) {
|
||||
$this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[255]');
|
||||
}
|
||||
$this->form_validation->set_rules('customer_id', 'Customer Id', 'trim|required|numeric|callback_client_id_check');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
} else {
|
||||
$customer_id = $data['customer_id'];
|
||||
unset($data['customer_id']);
|
||||
$id = $this->clients_model->add_contact($data, $customer_id);
|
||||
if ($id > 0 && !empty($id)) {
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Contact added successfully.',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Contact add fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/delete/contacts/:id Delete Contact
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName DeleteContact
|
||||
* @apiGroup Contacts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} customer_id unique Customer id
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Contact Deleted Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Contact Deleted Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status
|
||||
* @apiError {String} message Contact Delete Fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Contact Delete Fail"
|
||||
* }
|
||||
*/
|
||||
public function data_delete($customer_id = '') {
|
||||
$id = $this->security->xss_clean($customer_id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Contact ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$is_exist = $this->clients_model->get_contact($id);
|
||||
if (is_object($is_exist)) {
|
||||
$output = $this->clients_model->delete_contact($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Contact Deleted Successfuly.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Contact Delete Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Contact ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/contacts/:id Update Contact Information
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName PutContact
|
||||
* @apiGroup Contacts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Mandatory Customer Contact id.
|
||||
* @apiParam {String} firstname Mandatory First Name
|
||||
* @apiParam {String} lastname Mandatory Last Name
|
||||
* @apiParam {String} email Mandatory E-mail
|
||||
* @apiParam {String} [title] Optional Position
|
||||
* @apiParam {String} [phonenumber] Optional Phone Number
|
||||
* @apiParam {String} [direction = 'rtl'] Optional Direction (rtl or ltr)
|
||||
* @apiParam {String} [password] Optional password (only required if you pass send_set_password_email parameter)
|
||||
* @apiParam {String} [is_primary = 'on'] Optional Primary Contact (set on or don't pass it)
|
||||
* @apiParam {String} [donotsendwelcomeemail] Optional Do Not Send Welcome Email (set on or don't pass it)
|
||||
* @apiParam {String} [send_set_password_email] Optional Send Set Password Email (set on or don't pass it)
|
||||
* @apiParam {Array} [permissions] Optional Permissions for this contact(["1", "2", "3", "4", "5", "6" ])<br/>
|
||||
* [<br/>
|
||||
* "1", // Invoices permission<br/>
|
||||
* "2", // Estimates permission<br/>
|
||||
* "3", // Contracts permission<br/>
|
||||
* "4", // Proposals permission<br/>
|
||||
* "5", // Support permission<br/>
|
||||
* "6" // Projects permission<br/>
|
||||
* ]
|
||||
* @apiParam {String} [invoice_emails = "invoice_emails"] Optional E-Mail Notification for Invoices (set value same as name or don't pass it)
|
||||
* @apiParam {String} [estimate_emails = "estimate_emails"] Optional E-Mail Notification for Estimate (set value same as name or don't pass it)
|
||||
* @apiParam {String} [credit_note_emails = "credit_note_emails"] Optional E-Mail Notification for Credit Note (set value same as name or don't pass it)
|
||||
* @apiParam {String} [project_emails = "project_emails"] Optional E-Mail Notification for Project (set value same as name or don't pass it)
|
||||
* @apiParam {String} [ticket_emails = "ticket_emails"] Optional E-Mail Notification for Tickets (set value same as name or don't pass it)
|
||||
* @apiParam {String} [task_emails = "task_emails"] Optional E-Mail Notification for Task (set value same as name or don't pass it)
|
||||
* @apiParam {String} [contract_emails ="contract_emails"] Optional E-Mail Notification for Contract (set value same as name or don't pass it)
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "firstname":"new first name",
|
||||
* "lastname":"new last name",
|
||||
* "email":"dummy@gmail.com",
|
||||
* "title":"",
|
||||
* "phonenumber":"9909999099",
|
||||
* "direction":"rtl",
|
||||
* "password":"123456",
|
||||
* "is_primary":"on",
|
||||
* "send_set_password_email":"on",
|
||||
* "permissions":["1", "2", "3", "4", "5", "6" ],
|
||||
* "invoice_emails":"invoice_emails",
|
||||
* "estimate_emails":"estimate_emails",
|
||||
* "credit_note_emails":"credit_note_emails",
|
||||
* "project_emails":"project_emails",
|
||||
* "ticket_emails":"ticket_emails",
|
||||
* "task_emails":"task_emails",
|
||||
* "contract_emails":"contract_emails"
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status
|
||||
* @apiSuccess {String} message Contact updated successful
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Contact Updated Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {String} email This Email is already exists
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "email":"This Email is already exists"
|
||||
* },
|
||||
* "message": "This Email is already exists"
|
||||
* }
|
||||
* @apiError {Boolean} status Request status
|
||||
* @apiError {String} message Contact add fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Contact Update fail"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_put($id = '') {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Client ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('authentication_model');
|
||||
$data = $this->input->post();
|
||||
$is_exist = $this->clients_model->get_contact($id);
|
||||
if (!is_object($is_exist)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Contact ID Doesn\'t Not Exist.');
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
}
|
||||
$_current_email = $this->db->where('id', $id)->get(db_prefix() . 'contacts')->row();
|
||||
if ($_current_email->email == $this->input->post('email')) {
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|max_length[255]');
|
||||
} else {
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|max_length[255]|is_unique[' . db_prefix() . 'contacts.email]', array('is_unique' => 'This %s is already exists'));
|
||||
}
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
}
|
||||
$success = $this->clients_model->update_contact($data, $id);
|
||||
$updated = false;
|
||||
if (is_array($success)) {
|
||||
if (isset($success['set_password_email_sent'])) {
|
||||
$message_str = _l('set_password_email_sent_to_client');
|
||||
} elseif (isset($success['set_password_email_sent_and_profile_updated'])) {
|
||||
$updated = true;
|
||||
$message_str = _l('set_password_email_sent_to_client_and_profile_updated');
|
||||
}
|
||||
} else {
|
||||
if ($success == true) {
|
||||
$updated = true;
|
||||
$message_str = "Contact Updated Successfully";
|
||||
}
|
||||
}
|
||||
if ($updated == true) {
|
||||
$message = array('status' => TRUE, 'message' => $message_str);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Client Update Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function client_id_check($customer_id) {
|
||||
$this->form_validation->set_message('client_id_check', 'The {field} is Invalid');
|
||||
if (empty($customer_id)) {
|
||||
return FALSE;
|
||||
}
|
||||
$query = $this->db->get_where(db_prefix() . 'clients', array('userid' => $customer_id));
|
||||
return $query->num_rows() > 0;
|
||||
}
|
||||
}
|
||||
515
api/controllers/Contracts.php
Normal file
515
api/controllers/Contracts.php
Normal file
@@ -0,0 +1,515 @@
|
||||
j<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Contracts extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/contracts/:id Request Contract information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetContract
|
||||
* @apiGroup Contracts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiParam {Number} id Contact unique ID
|
||||
*
|
||||
* @apiSuccess {Object} Contracts information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "1",
|
||||
* "content": "",
|
||||
* "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
|
||||
* "subject": "New Contract",
|
||||
* "client": "9",
|
||||
* "datestart": "2022-11-21",
|
||||
* "dateend": "2027-11-21",
|
||||
* "contract_type": "1",
|
||||
* "project_id": "0",
|
||||
* "addedfrom": "1",
|
||||
* "dateadded": "2022-11-21 12:45:58",
|
||||
* "isexpirynotified": "0",
|
||||
* "contract_value": "13456.00",
|
||||
* "trash": "0",
|
||||
* "not_visible_to_client": "0",
|
||||
* "hash": "31caaa36b9ea1f45a688c7e859d3ae70",
|
||||
* "signed": "0",
|
||||
* "signature": null,
|
||||
* "marked_as_signed": "0",
|
||||
* "acceptance_firstname": null,
|
||||
* "acceptance_lastname": null,
|
||||
* "acceptance_email": null,
|
||||
* "acceptance_date": null,
|
||||
* "acceptance_ip": null,
|
||||
* "short_link": null,
|
||||
* "name": "Development Contracts",
|
||||
* "userid": "9",
|
||||
* "company": "8web",
|
||||
* "vat": "",
|
||||
* "phonenumber": "",
|
||||
* "country": "0",
|
||||
* "city": "",
|
||||
* "zip": "",
|
||||
* "state": "",
|
||||
* "address": "",
|
||||
* "website": "",
|
||||
* "datecreated": "2022-08-11 14:07:26",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "billing_street": "",
|
||||
* "billing_city": "",
|
||||
* "billing_state": "",
|
||||
* "billing_zip": "",
|
||||
* "billing_country": "0",
|
||||
* "shipping_street": "",
|
||||
* "shipping_city": "",
|
||||
* "shipping_state": "",
|
||||
* "shipping_zip": "",
|
||||
* "shipping_country": "0",
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "type_name": "Development Contracts",
|
||||
* "attachments": [],
|
||||
* "customfields": [],
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('contracts', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "contract", $id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/contracts/:id Delete Contract
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName DeleteContract
|
||||
* @apiGroup Contracts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Contract Deleted Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Contract Deleted Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Contract Delete Fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Contract Delete Fail"
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Contract ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('contracts_model');
|
||||
$is_exist = $this->contracts_model->get($id);
|
||||
if (is_object($is_exist)) {
|
||||
$output = $this->contracts_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Contract Deleted Successfully');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Contract Delete Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Contract ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/contracts Add New Contract
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName PostContract
|
||||
* @apiGroup Contracts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} subject Mandatory. Contract subject
|
||||
* @apiParam {Date} datestart Mandatory. Contract start date
|
||||
* @apiParam {Number} client Mandatory. Customer ID
|
||||
* @apiParam {Date} dateend Optional. Contract end date
|
||||
* @apiParam {Number} contract_type Optional. Contract type
|
||||
* @apiParam {Number} contract_value Optional. Contract value
|
||||
* @apiParam {String} description Optional. Contract description
|
||||
* @apiParam {String} content Optional. Contract content
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* [
|
||||
* "subject"=>"Subject of the Contract,
|
||||
* "datestart"=>"2022-11-11",
|
||||
* "client"=>1,
|
||||
* "dateend"=>"2023-11-11",
|
||||
* "contract_type"=>1,
|
||||
* "contract_value"=>12345,
|
||||
* "description"=>"Lorem Ipsum is simply dummy text of the printing and typesetting industry",
|
||||
* "content"=>"It has been the industry's standard dummy text ever since the 1500s"
|
||||
* ]
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Contracts Added Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Contract Added Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Contract add fail
|
||||
* @apiError {String} message The Start date field is required
|
||||
* @apiError {String} message The Subject field is required
|
||||
* @apiError {String} message The Customer ID field is required
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Contract ID Exists"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "newitems[]": "The Start date field is required"
|
||||
* },
|
||||
* "message": "<p>The Start date field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "subtotal": "The Subject field is required"
|
||||
* },
|
||||
* "message": "<p>The Subject field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "total": "The Customer ID is required"
|
||||
* },
|
||||
* "message": "<p>The Customer ID is required</p>\n"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
$data = $this->input->post();
|
||||
|
||||
$this->form_validation->set_rules('id', 'Contract ID', 'trim|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('content', 'Content', 'trim');
|
||||
$this->form_validation->set_rules('description', 'Description', 'trim');
|
||||
$this->form_validation->set_rules('subject', 'Subject', 'trim|required');
|
||||
$this->form_validation->set_rules('client', 'Customer ID', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('contract_value', 'Contract Value', 'numeric');
|
||||
$this->form_validation->set_rules('datestart', 'Start date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('dateend', 'End date', 'trim|max_length[255]');
|
||||
$this->form_validation->set_rules('contract_type', 'Contract type', 'trim|numeric|greater_than[0]');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('contracts_model');
|
||||
$output = $this->contracts_model->add($data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
$this->handle_contract_attachments_array($output);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Contract Added Successfully',
|
||||
'record_id' => $output
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Contract Add Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/contracts Add New Contract
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName PostContract
|
||||
* @apiGroup Contracts
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} subject Mandatory. Contract subject
|
||||
* @apiParam {Date} datestart Mandatory. Contract start date
|
||||
* @apiParam {Number} client Mandatory. Customer ID
|
||||
* @apiParam {Date} dateend Optional. Contract end date
|
||||
* @apiParam {Number} contract_type Optional. Contract type
|
||||
* @apiParam {Number} contract_value Optional. Contract value
|
||||
* @apiParam {String} description Optional. Contract description
|
||||
* @apiParam {String} content Optional. Contract content
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* [
|
||||
* "subject"=>"Subject of the Contract,
|
||||
* "datestart"=>"2022-11-11",
|
||||
* "client"=>1,
|
||||
* "dateend"=>"2023-11-11",
|
||||
* "contract_type"=>1,
|
||||
* "contract_value"=>12345,
|
||||
* "description"=>"Lorem Ipsum is simply dummy text of the printing and typesetting industry",
|
||||
* "content"=>"It has been the industry's standard dummy text ever since the 1500s"
|
||||
* ]
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Contracts Added Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Contract Added Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Contract add fail
|
||||
* @apiError {String} message The Start date field is required
|
||||
* @apiError {String} message The Subject field is required
|
||||
* @apiError {String} message The Customer ID field is required
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Contract ID Exists"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "newitems[]": "The Start date field is required"
|
||||
* },
|
||||
* "message": "<p>The Start date field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "subtotal": "The Subject field is required"
|
||||
* },
|
||||
* "message": "<p>The Subject field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "total": "The Customer ID is required"
|
||||
* },
|
||||
* "message": "<p>The Customer ID is required</p>\n"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_put($id = '') {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$this->load->library('parse_input_stream');
|
||||
$_POST = $this->parse_input_stream->parse_parameters();
|
||||
$_FILES = $this->parse_input_stream->parse_files();
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Lead ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$update_data = $this->input->post();
|
||||
$update_file = isset($update_data['file']) ? $update_data['file'] : null;
|
||||
unset($update_data['file']);
|
||||
|
||||
$this->load->model('contracts_model');
|
||||
$output = $this->contracts_model->update($update_data, $id);
|
||||
if (!empty($update_file) && count($update_file)) {
|
||||
if ($output <= 0 || empty($output)) {
|
||||
$output = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$attachments = $this->contracts_model->get_contract_attachments('', $output);
|
||||
if ($attachments) {
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->contracts_model->delete_contract_attachment($attachment['id']);
|
||||
}
|
||||
}
|
||||
$this->handle_contract_attachments_array($output);
|
||||
$message = array('status' => TRUE, 'message' => 'Contract Update Successfully');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Contract Update Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function validate_contract_number($number, $contractid) {
|
||||
$isedit = 'false';
|
||||
if (!empty($contractid)) {
|
||||
$isedit = 'true';
|
||||
}
|
||||
$this->form_validation->set_message('validate_contract_number', 'The {field} is already in use');
|
||||
$original_number = null;
|
||||
$date = $this->input->post('date');
|
||||
if (!empty($contractid)) {
|
||||
$data = $this->Api_model->get_table('contracts', $contractid);
|
||||
$original_number = $data->number;
|
||||
if (empty($date)) {
|
||||
$date = $data->date;
|
||||
}
|
||||
}
|
||||
$number = trim($number);
|
||||
$number = ltrim($number, '0');
|
||||
if ($isedit == 'true') {
|
||||
if ($number == $original_number) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (total_rows(db_prefix() . 'contracts', ['YEAR(date)' => date('Y', strtotime(to_sql_date($date))), 'number' => $number, ]) > 0) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
function handle_contract_attachments_array($contract_id, $index_name = 'file') {
|
||||
$path = get_upload_path_by_type('contract') . $contract_id . '/';
|
||||
$CI = & get_instance();
|
||||
if (isset($_FILES[$index_name]['name']) && ($_FILES[$index_name]['name'] != '' || is_array($_FILES[$index_name]['name']) && count($_FILES[$index_name]['name']) > 0)) {
|
||||
if (!is_array($_FILES[$index_name]['name'])) {
|
||||
$_FILES[$index_name]['name'] = [$_FILES[$index_name]['name']];
|
||||
$_FILES[$index_name]['type'] = [$_FILES[$index_name]['type']];
|
||||
$_FILES[$index_name]['tmp_name'] = [$_FILES[$index_name]['tmp_name']];
|
||||
$_FILES[$index_name]['error'] = [$_FILES[$index_name]['error']];
|
||||
$_FILES[$index_name]['size'] = [$_FILES[$index_name]['size']];
|
||||
}
|
||||
_file_attachments_index_fix($index_name);
|
||||
for ($i = 0; $i < count($_FILES[$index_name]['name']); $i++) {
|
||||
// Get the temp file path
|
||||
$tmpFilePath = $_FILES[$index_name]['tmp_name'][$i];
|
||||
// Make sure we have a filepath
|
||||
if (!empty($tmpFilePath) && $tmpFilePath != '') {
|
||||
if (_perfex_upload_error($_FILES[$index_name]['error'][$i]) || !_upload_extension_allowed($_FILES[$index_name]['name'][$i])) {
|
||||
continue;
|
||||
}
|
||||
_maybe_create_upload_path($path);
|
||||
$filename = unique_filename($path, $_FILES[$index_name]['name'][$i]);
|
||||
$newFilePath = $path . $filename;
|
||||
// Upload the file into the temp dir
|
||||
if (copy($tmpFilePath, $newFilePath)) {
|
||||
unlink($tmpFilePath);
|
||||
$data = [];
|
||||
$data[] = ['file_name' => $filename, 'filetype' => $_FILES[$index_name]['type'][$i], ];
|
||||
$this->add_attachment_to_database($contract_id, $data, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function add_attachment_to_database($contract_id, $attachment, $external = false) {
|
||||
$this->load->model('contracts_model');
|
||||
$this->load->model('misc_model');
|
||||
$this->misc_model->add_attachment_to_database($contract_id, 'contract', $attachment, $external);
|
||||
|
||||
$contract = $this->contracts_model->get($contract_id);
|
||||
$not_user_ids = [];
|
||||
if ($contract->addedfrom != get_staff_user_id()) {
|
||||
array_push($not_user_ids, $contract->addedfrom);
|
||||
}
|
||||
$notifiedUsers = [];
|
||||
foreach ($not_user_ids as $uid) {
|
||||
$notified = add_notification([
|
||||
'description' => 'not_contract_added_attachment',
|
||||
'touserid' => $uid,
|
||||
'link' => '#contractid=' . $contract_id,
|
||||
'additional_data' => serialize([
|
||||
$contract->subject,
|
||||
]),
|
||||
]);
|
||||
if ($notified) {
|
||||
array_push($notifiedUsers, $uid);
|
||||
}
|
||||
}
|
||||
pusher_trigger_notification($notifiedUsers);
|
||||
}
|
||||
}
|
||||
29
api/controllers/Controller.php
Normal file
29
api/controllers/Controller.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace modules\api\scontrollers;
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
// Load the core Controller
|
||||
require_once APPPATH.'core/Controller.php';
|
||||
|
||||
/**
|
||||
* Base API Controller with Swagger support
|
||||
*/
|
||||
class Controller extends \CI_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function send_error($message, $code = 400)
|
||||
{
|
||||
$this->output
|
||||
->set_status_header($code)
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode([
|
||||
'error' => $message,
|
||||
'code' => $code
|
||||
]));
|
||||
}
|
||||
}
|
||||
687
api/controllers/Credit_notes.php
Normal file
687
api/controllers/Credit_notes.php
Normal file
@@ -0,0 +1,687 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Credit_notes extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/credit_notes/:id Request Credit notes information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetCreditNotes
|
||||
* @apiGroup Credit Notes
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiSuccess {Object} Credit notes information.
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "2",
|
||||
* "clientid": "1",
|
||||
* "deleted_customer_name": null,
|
||||
* "number": "2",
|
||||
* "prefix": "CN-",
|
||||
* "number_format": "1",
|
||||
* "datecreated": "2021-07-30 16:29:46",
|
||||
* "date": "2021-08-02",
|
||||
* "adminnote": "adminnote2",
|
||||
* "terms": "",
|
||||
* "clientnote": "",
|
||||
* "currency": "1",
|
||||
* "subtotal": "1200.00",
|
||||
* "total_tax": "0.00",
|
||||
* "total": "1200.00",
|
||||
* "adjustment": "0.00",
|
||||
* "addedfrom": "1",
|
||||
* "status": "1",
|
||||
* "project_id": "0",
|
||||
* "discount_percent": "0.00",
|
||||
* "discount_total": "0.00",
|
||||
* "discount_type": "",
|
||||
* "billing_street": "Test",
|
||||
* "billing_city": "Test",
|
||||
* "billing_state": "Test",
|
||||
* "billing_zip": "3000",
|
||||
* "billing_country": "102",
|
||||
* "shipping_street": "Test",
|
||||
* "shipping_city": "Test",
|
||||
* "shipping_state": "Test",
|
||||
* "shipping_zip": "3000",
|
||||
* "shipping_country": "102",
|
||||
* "include_shipping": "1",
|
||||
* "show_shipping_on_credit_note": "1",
|
||||
* "show_quantity_as": "1",
|
||||
* "reference_no": "",
|
||||
* "userid": "1",
|
||||
* "company": "Test",
|
||||
* "vat": "",
|
||||
* "phonenumber": "01324568903",
|
||||
* "country": "102",
|
||||
* "city": "Test",
|
||||
* "zip": "3000",
|
||||
* "state": "Test",
|
||||
* "address": "Test",
|
||||
* "website": "",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "credit_note_id": "2",
|
||||
* "customfields": []
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('creditnotes', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "credit_note", $id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/credit_notes/search/:keysearch Search credit notes item information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetCreditNotesSearch
|
||||
* @apiGroup Credit Notes
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords
|
||||
*
|
||||
* @apiSuccess {Object} credit notes Information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "2",
|
||||
* "clientid": "1",
|
||||
* "deleted_customer_name": null,
|
||||
* "number": "2",
|
||||
* "prefix": "CN-",
|
||||
* "number_format": "1",
|
||||
* "datecreated": "2021-07-30 16:29:46",
|
||||
* "date": "2021-08-02",
|
||||
* "adminnote": "adminnote2",
|
||||
* "terms": "",
|
||||
* "clientnote": "",
|
||||
* "currency": "1",
|
||||
* "subtotal": "1200.00",
|
||||
* "total_tax": "0.00",
|
||||
* "total": "1200.00",
|
||||
* "adjustment": "0.00",
|
||||
* "addedfrom": "1",
|
||||
* "status": "1",
|
||||
* "project_id": "0",
|
||||
* "discount_percent": "0.00",
|
||||
* "discount_total": "0.00",
|
||||
* "discount_type": "",
|
||||
* "billing_street": "Test",
|
||||
* "billing_city": "Test",
|
||||
* "billing_state": "Test",
|
||||
* "billing_zip": "3000",
|
||||
* "billing_country": "102",
|
||||
* "shipping_street": "Test",
|
||||
* "shipping_city": "Test",
|
||||
* "shipping_state": "Test",
|
||||
* "shipping_zip": "3000",
|
||||
* "shipping_country": "102",
|
||||
* "include_shipping": "1",
|
||||
* "show_shipping_on_credit_note": "1",
|
||||
* "show_quantity_as": "1",
|
||||
* "reference_no": "",
|
||||
* "userid": "1",
|
||||
* "company": "test",
|
||||
* "vat": "",
|
||||
* "phonenumber": "01324568903",
|
||||
* "country": "102",
|
||||
* "city": "Test",
|
||||
* "zip": "3000",
|
||||
* "state": "Test",
|
||||
* "address": "Test",
|
||||
* "website": "",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "credit_note_id": "2",
|
||||
* "customfields": []
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
$data = $this->Api_model->search('creditnotes', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "credit_note");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/credit_notes/:id Delete Credit Note
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName DeleteCreditNote
|
||||
* @apiGroup Credit Notes
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Credit Note Deleted Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Credit Note Deleted Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Credit Note Delete Fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Credit Note Delete Fail"
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Credit Note ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('credit_notes_model');
|
||||
$is_exist = $this->credit_notes_model->get($id);
|
||||
if (is_object($is_exist)) {
|
||||
$output = $this->credit_notes_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Credit Note Deleted Successfully');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Credit Note Delete Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Credit Note ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/credit_notes Add New Credit Notes
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName PostCredit_notes
|
||||
* @apiGroup Credit Notes
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} clientid Mandatory. Customer id
|
||||
* @apiParam {Date} date Mandatory. Credit Note Date
|
||||
* @apiParam {Number} number Mandatory. Credit Note Number
|
||||
* @apiParam {Number} currency Mandatory. currency field
|
||||
* @apiParam {Array} newitems Mandatory. New Items to be added
|
||||
* @apiParam {String} billing_street Optional. Street Address
|
||||
* @apiParam {String} [billing_city] Optional. City Name for billing
|
||||
* @apiParam {String} [billing_state] Optional. Name of state for billing
|
||||
* @apiParam {Number} [billing_zip] Optional. Zip code
|
||||
* @apiParam {Number} [billing_country] Optional. Country code
|
||||
* @apiParam {String} [shipping_street] Optional. Address of shipping
|
||||
* @apiParam {String} [shipping_city] Optional. City name for shipping
|
||||
* @apiParam {String} [shipping_state] Optional. Name of state for shipping
|
||||
* @apiParam {Number} [shipping_zip] Optional. Zip code for shipping
|
||||
* @apiParam {Number} [shipping_country] Optional. Country code
|
||||
* @apiParam {String} [discount_type] Optional. before_tax / after_tax discount type
|
||||
* @apiParam {String} [Admin Note] Optional. Admin Note
|
||||
* @apiParam {Decimal} subtotal Mandatory. calculation based on item Qty, Rate and Tax
|
||||
* @apiParam {Decimal} total Mandatory. calculation based on subtotal, Discount and
|
||||
* @apiParam {String} [clientnote] Optional. client notes
|
||||
* @apiParam {String} [terms] Optional. Terms
|
||||
*
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* [
|
||||
* "clientid" => 2
|
||||
* "date" => 2021-08-20
|
||||
* "number" => 2
|
||||
* "newitems[0][description]" => item 1 description
|
||||
* "newitems[0][long_description]" => item 1 long description
|
||||
* "newitems[0][qty]" => 1
|
||||
* "newitems[0][rate]" => 1200
|
||||
* "newitems[0][order]" => 1
|
||||
* "newitems[0][unit]" =>
|
||||
* "newitems[0][unit]" =>
|
||||
* "newitems[0][custom_fields][items][1]" => "new condition"
|
||||
* "subtotal" => 1200.00
|
||||
* "total" => 1200.00
|
||||
* "currency" => 1
|
||||
* "custom_fields"[credit_note][1]" => customfield_value
|
||||
* ]
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Credit Note Added Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Credit Note Added Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Credit Note add fail
|
||||
* @apiError {String} newitems[] The Items field is required
|
||||
* @apiError {String} number The Credit Note number is already in use
|
||||
* @apiError {String} subtotal The Sub Total field is required
|
||||
* @apiError {String} total The Total field is required
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Credit Note Add Fail"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "number":"The Credit Note number is already in use"
|
||||
* },
|
||||
* "message": "The Credit Note number is already in use"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "newitems[]": "The Items field is required"
|
||||
* },
|
||||
* "message": "<p>The Items field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "subtotal": "The Sub Total field is required"
|
||||
* },
|
||||
* "message": "<p>The Sub Total field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "total": "The Total field is required"
|
||||
* },
|
||||
* "message": "<p>The Total field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
$data = $this->input->post();
|
||||
|
||||
$this->form_validation->set_rules('clientid', 'Customer', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('project_id', 'Project', 'trim|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('date', 'Credit Note Date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('newitems[]', 'Items', 'required');
|
||||
$this->form_validation->set_rules('subtotal', 'Sub Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('total', 'Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('number', 'Credit Note Number', 'trim|required|numeric|callback_validate_creditnotes_number[0]');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('credit_notes_model');
|
||||
$id = $this->credit_notes_model->add($data);
|
||||
if ($id > 0 && !empty($id)) {
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Credit Note Added Successfully',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Credit Note Add Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function validate_creditnotes_number($number, $credit_notes_id) {
|
||||
$isedit = 'false';
|
||||
if (!empty($credit_notes_id)) {
|
||||
$isedit = 'true';
|
||||
}
|
||||
$this->form_validation->set_message('validate_creditnotes_number', 'The {field} is already in use');
|
||||
$original_number = null;
|
||||
$date = $this->input->post('date');
|
||||
if (!empty($credit_notes_id)) {
|
||||
$data = $this->Api_model->get_table('creditnotes', $credit_notes_id);
|
||||
$original_number = $data->number;
|
||||
if (empty($date)) {
|
||||
$date = $data->date;
|
||||
}
|
||||
}
|
||||
$number = trim($number);
|
||||
$number = ltrim($number, '0');
|
||||
if ($isedit == 'true') {
|
||||
if ($number == $original_number) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (total_rows(db_prefix() . 'creditnotes', ['YEAR(date)' => date('Y', strtotime(to_sql_date($date))), 'number' => $number, ]) > 0) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/credit_notes Update a Credit Note
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName PutCredit_notes
|
||||
* @apiGroup Credit Notes
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} clientid Mandatory. Customer id
|
||||
* @apiParam {Date} date Mandatory. Credit Note Date
|
||||
* @apiParam {Number} number Mandatory. Credit Note Number
|
||||
* @apiParam {Number} currency Mandatory. currency field
|
||||
* @apiParam {Array} newitems Mandatory. New Items to be added
|
||||
* @apiParam {Array} items Mandatory. Existing items with Id
|
||||
* @apiParam {Array} removed_items Optional. Items to be removed
|
||||
* @apiParam {Array} newitems Optional. New Items to be added
|
||||
* @apiParam {String} billing_street Optional. Street Address
|
||||
* @apiParam {String} [billing_city] Optional. City Name for billing
|
||||
* @apiParam {String} [billing_state] Optional. Name of state for billing
|
||||
* @apiParam {Number} [billing_zip] Optional. Zip code
|
||||
* @apiParam {Number} [billing_country] Optional. Country code
|
||||
* @apiParam {String} [shipping_street] Optional. Address of shipping
|
||||
* @apiParam {String} [shipping_city] Optional. City name for shipping
|
||||
* @apiParam {String} [shipping_state] Optional. Name of state for shipping
|
||||
* @apiParam {Number} [shipping_zip] Optional. Zip code for shipping
|
||||
* @apiParam {Number} [shipping_country] Optional. Country code
|
||||
* @apiParam {String} [discount_type] Optional. before_tax / after_tax discount type
|
||||
* @apiParam {String} [Admin Note] Optional. Admin Note
|
||||
* @apiParam {Decimal} subtotal Mandatory. calculation based on item Qty, Rate and Tax
|
||||
* @apiParam {Decimal} total Mandatory. calculation based on subtotal, Discount and
|
||||
* @apiParam {String} [clientnote] Optional. client notes
|
||||
* @apiParam {String} [terms] Optional. Terms
|
||||
*
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "clientid": 1,
|
||||
* "date": "2021-08-20",
|
||||
* "number": 1,
|
||||
* "items":
|
||||
* {
|
||||
* "1":
|
||||
* {
|
||||
* "itemid": "25",
|
||||
* "order": "1",
|
||||
* "description": "item description",
|
||||
* "long_description": "item long description",
|
||||
* "qty": "1",
|
||||
* "unit": "1",
|
||||
* "rate": "10.00",
|
||||
* "custom_fields":
|
||||
* {
|
||||
* "items":
|
||||
* {
|
||||
* "31": "test 12 item 1",
|
||||
* "32": "10",
|
||||
* "33": "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
|
||||
* "34": "Option 1",
|
||||
* "35":
|
||||
* [
|
||||
* "Option 1",
|
||||
* "Option 2"
|
||||
* ],
|
||||
* "36":
|
||||
* [
|
||||
* "Option 1",
|
||||
* "Option 3"
|
||||
* ],
|
||||
* "37": "2021-05-06",
|
||||
* "38": "2021-05-06 00:23:25",
|
||||
* "39": "#ffffff",
|
||||
* "40": "<a href=\"url.com\" target=\"_blank\">Link</a>"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* },
|
||||
* "newitems":
|
||||
* {
|
||||
* "2":
|
||||
* {
|
||||
* "order": "2",
|
||||
* "description": "updated item 2 description",
|
||||
* "long_description": "updated item 2 logn description",
|
||||
* "qty": "1",
|
||||
* "unit": "",
|
||||
* "rate": "100.00",
|
||||
* "custom_fields":
|
||||
* {
|
||||
* "items":
|
||||
* {
|
||||
* "31": "test 12 item 2",
|
||||
* "32": "10",
|
||||
* "33": "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
|
||||
* "34": "Option 1",
|
||||
* "35":
|
||||
* [
|
||||
* "Option 1",
|
||||
* "Option 2"
|
||||
* ],
|
||||
* "36":
|
||||
* [
|
||||
* "Option 1",
|
||||
* "Option 3"
|
||||
* ],
|
||||
* "37": "2021-05-06",
|
||||
* "38": "2021-05-06 00:23:25",
|
||||
* "39": "#ffffff",
|
||||
* "40": "<a href=\"url.com\" target=\"_blank\">Link</a>"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* },
|
||||
* "custom_fields":
|
||||
* {
|
||||
* "credit_note":
|
||||
* {
|
||||
* "93": "test 1254"
|
||||
* }
|
||||
* },
|
||||
* "subtotal": "1200.00",
|
||||
* "total": "1200.00",
|
||||
* "currency": 1
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Credit Note Updated Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Credit Note Updated Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Credit Note Update Fail
|
||||
* @apiError {String} newitems[] The Items field is required
|
||||
* @apiError {String} number The Credit Note number is already in use
|
||||
* @apiError {String} subtotal The Sub Total field is required
|
||||
* @apiError {String} total The Total field is required
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Credit Note Update Fail"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "number":"The Credit Note number is already in use"
|
||||
* },
|
||||
* "message": "The Credit Note number is already in use"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "newitems[]": "The Items field is required"
|
||||
* },
|
||||
* "message": "<p>The Items field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "subtotal": "The Sub Total field is required"
|
||||
* },
|
||||
* "message": "<p>The Sub Total field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "total": "The Total field is required"
|
||||
* },
|
||||
* "message": "<p>The Total field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_put($id = "") {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Credit Note ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->form_validation->set_rules('clientid', 'Customer', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('project_id', 'Project', 'trim|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('date', 'Credit Note Date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('items[]', 'Items', 'required');
|
||||
$this->form_validation->set_rules('subtotal', 'Sub Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('total', 'Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('number', 'Credit Note Number', 'trim|required|numeric|callback_validate_creditnotes_number[' . $id . ']');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
} else {
|
||||
$this->load->model('credit_notes_model');
|
||||
$is_exist = $this->credit_notes_model->get($id);
|
||||
if (!is_object($is_exist)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Credit Note ID Doesn\'t Not Exist.');
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
}
|
||||
if (is_object($is_exist)) {
|
||||
$data = $this->input->post();
|
||||
$data['isedit'] = "";
|
||||
$success = $this->credit_notes_model->update($data, $id);
|
||||
if ($success == true) {
|
||||
$message = array('status' => TRUE, 'message' => "Credit Note Updated Successfully",);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Credit Note Update Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Credit Note ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
767
api/controllers/Custom_fields.php
Normal file
767
api/controllers/Custom_fields.php
Normal file
@@ -0,0 +1,767 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
class Custom_fields extends REST_Controller {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/custom_fields/:FieldBelongsto/:id Request Values of Custom Fields
|
||||
* @apiVersion 0.2.0
|
||||
* @apiName GetCustomFieldswithValue
|
||||
* @apiGroup Custom Fields
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {string=<br/>"Company",<br/>"Leads",<br/>"Customers",<br/>"Contacts",<br/>"Staff",<br/>"Contracts",<br/>"Tasks",<br/>"Expenses",<br/>"Invoice",<br/>"Items",<br/>"Note",<br/>"Estimate",<br/>"Contract",<br/>"Proposal",<br/>"Projects",<br/>"Tickets"} FieldBelongsto Belongs to Mandatory Field Belongs to.
|
||||
*
|
||||
* @apiParam {Number} [id] Optional unique ID.
|
||||
*
|
||||
* @apiSuccess {Object} Custom Custom Fields information with values.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][1]",
|
||||
* "custom_field_id": "1",
|
||||
* "label": "Input 1",
|
||||
* "required": "0",
|
||||
* "type": "input",
|
||||
* "value": "input1 data"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][2]",
|
||||
* "custom_field_id": "2",
|
||||
* "label": "Number 1",
|
||||
* "required": "0",
|
||||
* "type": "number",
|
||||
* "value": "12"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][3]",
|
||||
* "custom_field_id": "3",
|
||||
* "label": "Textarea 1",
|
||||
* "required": "0",
|
||||
* "type": "textarea",
|
||||
* "value": "textarea content"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][4]",
|
||||
* "custom_field_id": "4",
|
||||
* "label": "Select 1",
|
||||
* "required": "0",
|
||||
* "type": "select",
|
||||
* "value": "[\"Option 1\"]",
|
||||
* "options": "[\"Option 1\",\"Option 2\",\"Option 3\"]"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][5]",
|
||||
* "custom_field_id": "5",
|
||||
* "label": "Multiselect 1",
|
||||
* "required": "0",
|
||||
* "type": "multiselect",
|
||||
* "value": "[\"Option 1\",\" Option 2\"]",
|
||||
* "options": "[\"Option 1\",\"Option 2\",\"Option 3\"]"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][6]",
|
||||
* "custom_field_id": "6",
|
||||
* "label": "Checkbox 1",
|
||||
* "required": "0",
|
||||
* "type": "checkbox",
|
||||
* "value": "[\"Option 1\",\" Option 2\"]",
|
||||
* "options": "[\"Option 1\",\"Option 2\",\"Option 3\"]"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][7]",
|
||||
* "custom_field_id": "7",
|
||||
* "label": "Datepicker 1",
|
||||
* "required": "0",
|
||||
* "type": "date_picker",
|
||||
* "value": "2021-05-16"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][8]",
|
||||
* "custom_field_id": "8",
|
||||
* "label": "Datetime Picker 1",
|
||||
* "required": "0",
|
||||
* "type": "date_picker_time",
|
||||
* "value": "2021-05-25 23:06:00"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][9]",
|
||||
* "custom_field_id": "9",
|
||||
* "label": "Colorpicker 1",
|
||||
* "required": "0",
|
||||
* "type": "colorpicker",
|
||||
* "value": "#8f1b1b"
|
||||
* },
|
||||
* {
|
||||
* "field_name": "custom_fields[invoice][10]",
|
||||
* "custom_field_id": "10",
|
||||
* "label": "Hyperlink 1",
|
||||
* "required": "0",
|
||||
* "type": "link",
|
||||
* "value": "<a href=\"https://google.com\" target=\"_blank\">google</a>"
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($type = "", $id = "") {
|
||||
$allowed_type = ["company", "leads", "customers", "contacts", "staff", "contracts", "tasks", "expenses", "invoice", "items", "credit_note", "estimate", "contract", "proposal", "projects", "tickets"];
|
||||
if (empty($type) || !in_array($type, $allowed_type)) {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'Not valid data'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
$fields = get_custom_fields($type);
|
||||
$customfields = [];
|
||||
foreach ($fields as $key => $field) {
|
||||
$customfields[$key] = new stdclass();
|
||||
$customfields[$key]->field_name = 'custom_fields[' . $field['fieldto'] . '][' . $field['id'] . ']';
|
||||
$customfields[$key]->custom_field_id = $field['id'];
|
||||
$customfields[$key]->label = $field['name'];
|
||||
$customfields[$key]->required = $field['required'];
|
||||
$customfields[$key]->type = $field['type'];
|
||||
$customfields[$key]->value = get_custom_field_value($id, $field['id'], $type, false);
|
||||
if (!empty($field['options'])) {
|
||||
$customfields[$key]->value = json_encode(explode(',', $customfields[$key]->value));
|
||||
$customfields[$key]->options = json_encode(explode(',', $field['options']));
|
||||
}
|
||||
}
|
||||
$this->response($customfields, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {POST} N/A Add Custom Fields
|
||||
* @apiVersion 0.2.0
|
||||
* @apiDescription Submit URL for POST request of the custom fields remains the same for each endpoint (ie `api/contacts` for Contacts endpoint, `api/invoices` for Invoices endpoint, etc..)
|
||||
* <br> <h2>In this example, we will use the following form data which corresponds to the following custom field types:</h2>
|
||||
`custom_fields[invoice][1]` = **Input Type**
|
||||
<br> `custom_fields[invoice][2]` = **Number**
|
||||
<br> `custom_fields[invoice][3]` = **Textarea**
|
||||
<br> `custom_fields[invoice][4]` = **Radio**
|
||||
<br> `custom_fields[invoice][5]` = **Checkbox**
|
||||
<br> `custom_fields[invoice][6]` = **Multiselect**
|
||||
<br> `custom_fields[invoice][7]` = **Date**
|
||||
<br> `custom_fields[invoice][8]` = **Datetime**
|
||||
<br> `custom_fields[invoice][9]` = **Color**
|
||||
<br> `custom_fields[invoice][10]` = **Link**
|
||||
* @apiName PostActionExample
|
||||
* @apiGroup Custom Fields
|
||||
*
|
||||
* @apiParam {string/array} custom_fields[customFieldType] Custom Field Key should be same as `field_name` returned from **Search custom field values' information**
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* [
|
||||
* custom_fields[invoice][1] => John Doe
|
||||
* custom_fields[invoice][2] => 10
|
||||
* custom_fields[invoice][3] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
|
||||
* custom_fields[invoice][4] => Option 1
|
||||
* custom_fields[invoice][5][] => Option 1
|
||||
* custom_fields[invoice][5][] => Option 2
|
||||
* custom_fields[invoice][6][] => Option 1
|
||||
* custom_fields[invoice][6][] => Option 3
|
||||
* custom_fields[invoice][7] => 2021-05-06
|
||||
* custom_fields[invoice][8] => 2021-05-06 00:23:25
|
||||
* custom_fields[invoice][9] => #FFFFFF
|
||||
* custom_fields[invoice][10] => <a href="url.com" target="_blank">Link</a>
|
||||
* ]
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* Same as Original request
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* Same as Original request
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {PUT} N/A Update Custom Fields
|
||||
* @apiVersion 0.2.0
|
||||
* @apiDescription Submit URL for PUT request of the custom fields remains the same for each endpoint (ie `api/contacts` for Contacts endpoint, `api/invoices` for Invoices endpoint, etc..)
|
||||
* <br> <h2>In this example, we will use the following form data which corresponds to the following custom field types:</h2>
|
||||
`custom_fields[invoice][1]` = **Input Type**
|
||||
<br> `custom_fields[invoice][2]` = **Number**
|
||||
<br> `custom_fields[invoice][3]` = **Textarea**
|
||||
<br> `custom_fields[invoice][4]` = **Radio**
|
||||
<br> `custom_fields[invoice][5]` = **Checkbox**
|
||||
<br> `custom_fields[invoice][6]` = **Multiselect**
|
||||
<br> `custom_fields[invoice][7]` = **Date**
|
||||
<br> `custom_fields[invoice][8]` = **Datetime**
|
||||
<br> `custom_fields[invoice][9]` = **Color**
|
||||
<br> `custom_fields[invoice][10]` = **Link**
|
||||
* @apiName PutActionExample
|
||||
* @apiGroup Custom Fields
|
||||
*
|
||||
* @apiParam {string/array} custom_fields[customFieldType] Custom Field JSON should be same as below with `field_name` and `custom_field_id` returned from **Search custom field values' information**
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "custom_fields":{
|
||||
"invoice":{
|
||||
"1":"test 12 item 1",
|
||||
"2":"10",
|
||||
"3":"Lorem Ipsum is simply dummy text of the printing and typesetting industry",
|
||||
"4":"Option 1",
|
||||
"5":["Option 1","Option 2"],
|
||||
"6":["Option 1","Option 3"],
|
||||
"7":"2021-05-06",
|
||||
"8":"2021-05-06 00:23:25",
|
||||
"9":"#ffffff",
|
||||
"10":"<a href=\"url.com\" target=\"_blank\">Link</a>"
|
||||
}
|
||||
}
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* Same as Original request
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* Same as Original request
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {GET} N/A Request Custom Fields
|
||||
* @apiVersion 0.2.0
|
||||
* @apiDescription Custom fields' data will be returned combined with other request's information during the initial GET request of each available endpoint (Contacts, Invoices etc) with their respective `label` and `value` key
|
||||
* @apiName GetActionExample
|
||||
* @apiGroup Custom Fields
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
{
|
||||
"id": "1",
|
||||
"sent": "0",
|
||||
"datesend": null,
|
||||
"clientid": "1",
|
||||
"deleted_customer_name": null,
|
||||
"number": "10",
|
||||
"prefix": "INV-",
|
||||
"number_format": "1",
|
||||
"datecreated": "2021-05-14 00:44:52",
|
||||
"date": "2021-08-28",
|
||||
"duedate": "2021-09-27",
|
||||
"currency": "1",
|
||||
"subtotal": "110.00",
|
||||
"total_tax": "0.00",
|
||||
"total": "110.00",
|
||||
"adjustment": "0.00",
|
||||
"addedfrom": "0",
|
||||
"hash": "4222d2f53404324ea73535d3c0f2c3f0",
|
||||
"status": "1",
|
||||
"clientnote": "",
|
||||
"adminnote": "",
|
||||
"last_overdue_reminder": null,
|
||||
"cancel_overdue_reminders": "1",
|
||||
"allowed_payment_modes": "a:2:{i:0;s:1:\"1\";i:1;s:1:\"2\";}",
|
||||
"token": null,
|
||||
"discount_percent": "0.00",
|
||||
"discount_total": "0.00",
|
||||
"discount_type": "",
|
||||
"recurring": "0",
|
||||
"recurring_type": null,
|
||||
"custom_recurring": "0",
|
||||
"cycles": "0",
|
||||
"total_cycles": "0",
|
||||
"is_recurring_from": null,
|
||||
"last_recurring_date": null,
|
||||
"terms": "",
|
||||
"sale_agent": "0",
|
||||
"billing_street": "billing address",
|
||||
"billing_city": "billing city name",
|
||||
"billing_state": "billing state name",
|
||||
"billing_zip": "billing zip code",
|
||||
"billing_country": "0",
|
||||
"shipping_street": "shipping address",
|
||||
"shipping_city": "city name",
|
||||
"shipping_state": "state name",
|
||||
"shipping_zip": "zip code",
|
||||
"shipping_country": "0",
|
||||
"include_shipping": "1",
|
||||
"show_shipping_on_invoice": "1",
|
||||
"show_quantity_as": "1",
|
||||
"project_id": "0",
|
||||
"subscription_id": "0",
|
||||
"short_link": null,
|
||||
"symbol": "$",
|
||||
"name": "USD",
|
||||
"decimal_separator": ".",
|
||||
"thousand_separator": ",",
|
||||
"placement": "before",
|
||||
"isdefault": "1",
|
||||
"currencyid": "1",
|
||||
"currency_name": "USD",
|
||||
"total_left_to_pay": "110.00",
|
||||
"items": [
|
||||
{
|
||||
"id": "1",
|
||||
"rel_id": "1",
|
||||
"rel_type": "invoice",
|
||||
"description": "item description",
|
||||
"long_description": "item long description",
|
||||
"qty": "1.00",
|
||||
"rate": "10.00",
|
||||
"unit": "1",
|
||||
"item_order": "1",
|
||||
"customfields": [
|
||||
{
|
||||
"label": "Input 1",
|
||||
"value": "test 12 item 1"
|
||||
},
|
||||
{
|
||||
"label": "Number 1",
|
||||
"value": "10"
|
||||
},
|
||||
{
|
||||
"label": "Textarea 1",
|
||||
"value": "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
|
||||
},
|
||||
{
|
||||
"label": "Select 1",
|
||||
"value": "Option 1"
|
||||
},
|
||||
{
|
||||
"label": "Multiselect 1",
|
||||
"value": "Option 1, Option 2"
|
||||
},
|
||||
{
|
||||
"label": "Checkbox 1",
|
||||
"value": "Option 1, Option 3"
|
||||
},
|
||||
{
|
||||
"label": "Datepicker 1",
|
||||
"value": "2021-05-06"
|
||||
},
|
||||
{
|
||||
"label": "Datetime Picker 1",
|
||||
"value": "2021-05-06 00:23:25"
|
||||
},
|
||||
{
|
||||
"label": "Colorpicker 1",
|
||||
"value": "#ffffff"
|
||||
},
|
||||
{
|
||||
"label": "Hyperlink 1",
|
||||
"value": "<a>Link</a>"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"rel_id": "1",
|
||||
"rel_type": "invoice",
|
||||
"description": "updated item 2 description",
|
||||
"long_description": "updated item 2 logn description",
|
||||
"qty": "1.00",
|
||||
"rate": "100.00",
|
||||
"unit": "",
|
||||
"item_order": "2",
|
||||
"customfields": [
|
||||
{
|
||||
"label": "Input 1",
|
||||
"value": "test 12 item 2"
|
||||
},
|
||||
{
|
||||
"label": "Number 1",
|
||||
"value": "10"
|
||||
},
|
||||
{
|
||||
"label": "Textarea 1",
|
||||
"value": "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
|
||||
},
|
||||
{
|
||||
"label": "Select 1",
|
||||
"value": "Option 1"
|
||||
},
|
||||
{
|
||||
"label": "Multiselect 1",
|
||||
"value": "Option 1, Option 2"
|
||||
},
|
||||
{
|
||||
"label": "Checkbox 1",
|
||||
"value": "Option 1, Option 3"
|
||||
},
|
||||
{
|
||||
"label": "Datepicker 1",
|
||||
"value": "2021-05-06"
|
||||
},
|
||||
{
|
||||
"label": "Datetime Picker 1",
|
||||
"value": "2021-05-06 00:23:25"
|
||||
},
|
||||
{
|
||||
"label": "Colorpicker 1",
|
||||
"value": "#ffffff"
|
||||
},
|
||||
{
|
||||
"label": "Hyperlink 1",
|
||||
"value": "<a>Link</a>"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"attachments": [],
|
||||
"visible_attachments_to_customer_found": false,
|
||||
"client": {
|
||||
"userid": "1",
|
||||
"company": "updated company",
|
||||
"vat": "",
|
||||
"phonenumber": "",
|
||||
"country": "0",
|
||||
"city": "",
|
||||
"zip": "",
|
||||
"state": "",
|
||||
"address": "",
|
||||
"website": "",
|
||||
"datecreated": "2021-05-14 00:15:06",
|
||||
"active": "1",
|
||||
"leadid": null,
|
||||
"billing_street": "",
|
||||
"billing_city": "",
|
||||
"billing_state": "",
|
||||
"billing_zip": "",
|
||||
"billing_country": "0",
|
||||
"shipping_street": "",
|
||||
"shipping_city": "",
|
||||
"shipping_state": "",
|
||||
"shipping_zip": "",
|
||||
"shipping_country": "0",
|
||||
"longitude": null,
|
||||
"latitude": null,
|
||||
"default_language": "",
|
||||
"default_currency": "0",
|
||||
"show_primary_contact": "0",
|
||||
"stripe_id": null,
|
||||
"registration_confirmed": "1",
|
||||
"addedfrom": "0"
|
||||
},
|
||||
"payments": [],
|
||||
"scheduled_email": null,
|
||||
"customfields": [
|
||||
{
|
||||
"label": "Input 1",
|
||||
"value": "test 12"
|
||||
},
|
||||
{
|
||||
"label": "Number 1",
|
||||
"value": "10"
|
||||
},
|
||||
{
|
||||
"label": "Textarea 1",
|
||||
"value": "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
|
||||
},
|
||||
{
|
||||
"label": "Select 1",
|
||||
"value": "Option 1"
|
||||
},
|
||||
{
|
||||
"label": "Multiselect 1",
|
||||
"value": "Option 1, Option 2"
|
||||
},
|
||||
{
|
||||
"label": "Checkbox 1",
|
||||
"value": "Option 1, Option 3"
|
||||
},
|
||||
{
|
||||
"label": "Datepicker 1",
|
||||
"value": "2021-05-06"
|
||||
},
|
||||
{
|
||||
"label": "Datetime Picker 1",
|
||||
"value": "2021-05-06 00:23:25"
|
||||
},
|
||||
{
|
||||
"label": "Colorpicker 1",
|
||||
"value": "#ffffff"
|
||||
},
|
||||
{
|
||||
"label": "Hyperlink 1",
|
||||
"value": "<a>Link</a>"
|
||||
}
|
||||
]
|
||||
}
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* Same as Original request
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {GET} N/A Search custom field values' information
|
||||
* @apiVersion 0.2.0
|
||||
* @apiDescription Custom fields' data will be returned combined with other request's information during the initial SEARCH request of each available endpoint (Contacts, Invoices etc) with their respective `label` and `value` key
|
||||
* @apiName SearchActionExample
|
||||
* @apiGroup Custom Fields
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
[
|
||||
{
|
||||
"id": "1",
|
||||
"sent": "0",
|
||||
"datesend": null,
|
||||
"clientid": "1",
|
||||
"deleted_customer_name": null,
|
||||
"number": "10",
|
||||
"prefix": "INV-",
|
||||
"number_format": "1",
|
||||
"datecreated": "2021-05-14 00:15:06",
|
||||
"date": "2021-08-28",
|
||||
"duedate": "2021-09-27",
|
||||
"currency": "1",
|
||||
"subtotal": "110.00",
|
||||
"total_tax": "0.00",
|
||||
"total": "110.00",
|
||||
"adjustment": "0.00",
|
||||
"addedfrom": "0",
|
||||
"hash": "4222d2f53404324ea73535d3c0f2c3f0",
|
||||
"status": "1",
|
||||
"clientnote": "",
|
||||
"adminnote": "",
|
||||
"last_overdue_reminder": null,
|
||||
"cancel_overdue_reminders": "1",
|
||||
"allowed_payment_modes": "a:2:{i:0;s:1:\"1\";i:1;s:1:\"2\";}",
|
||||
"token": null,
|
||||
"discount_percent": "0.00",
|
||||
"discount_total": "0.00",
|
||||
"discount_type": "",
|
||||
"recurring": "0",
|
||||
"recurring_type": null,
|
||||
"custom_recurring": "0",
|
||||
"cycles": "0",
|
||||
"total_cycles": "0",
|
||||
"is_recurring_from": null,
|
||||
"last_recurring_date": null,
|
||||
"terms": "",
|
||||
"sale_agent": "0",
|
||||
"billing_street": "",
|
||||
"billing_city": "",
|
||||
"billing_state": "",
|
||||
"billing_zip": "",
|
||||
"billing_country": "0",
|
||||
"shipping_street": "",
|
||||
"shipping_city": "",
|
||||
"shipping_state": "",
|
||||
"shipping_zip": "",
|
||||
"shipping_country": "0",
|
||||
"include_shipping": "1",
|
||||
"show_shipping_on_invoice": "1",
|
||||
"show_quantity_as": "1",
|
||||
"project_id": "0",
|
||||
"subscription_id": "0",
|
||||
"short_link": null,
|
||||
"userid": "1",
|
||||
"company": "updated company",
|
||||
"vat": "",
|
||||
"phonenumber": "",
|
||||
"country": "0",
|
||||
"city": "",
|
||||
"zip": "",
|
||||
"state": "",
|
||||
"address": "",
|
||||
"website": "",
|
||||
"active": "1",
|
||||
"leadid": null,
|
||||
"longitude": null,
|
||||
"latitude": null,
|
||||
"default_language": "",
|
||||
"default_currency": "0",
|
||||
"show_primary_contact": "0",
|
||||
"stripe_id": null,
|
||||
"registration_confirmed": "1",
|
||||
"invoiceid": "1",
|
||||
"customfields": [
|
||||
{
|
||||
"label": "Input 1",
|
||||
"value": "test 12"
|
||||
},
|
||||
{
|
||||
"label": "Number 1",
|
||||
"value": "10"
|
||||
},
|
||||
{
|
||||
"label": "Textarea 1",
|
||||
"value": "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
|
||||
},
|
||||
{
|
||||
"label": "Select 1",
|
||||
"value": "Option 1"
|
||||
},
|
||||
{
|
||||
"label": "Multiselect 1",
|
||||
"value": "Option 1, Option 2"
|
||||
},
|
||||
{
|
||||
"label": "Checkbox 1",
|
||||
"value": "Option 1, Option 3"
|
||||
},
|
||||
{
|
||||
"label": "Datepicker 1",
|
||||
"value": "2021-05-06"
|
||||
},
|
||||
{
|
||||
"label": "Datetime Picker 1",
|
||||
"value": "2021-05-06 00:23:25"
|
||||
},
|
||||
{
|
||||
"label": "Colorpicker 1",
|
||||
"value": "#ffffff"
|
||||
},
|
||||
{
|
||||
"label": "Hyperlink 1",
|
||||
"value": "<a>Link</a>"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"sent": "0",
|
||||
"datesend": null,
|
||||
"clientid": "1",
|
||||
"deleted_customer_name": null,
|
||||
"number": "4",
|
||||
"prefix": "INV-",
|
||||
"number_format": "1",
|
||||
"datecreated": "2021-05-14 00:15:06",
|
||||
"date": "2021-05-28",
|
||||
"duedate": "2021-06-27",
|
||||
"currency": "1",
|
||||
"subtotal": "110.00",
|
||||
"total_tax": "0.00",
|
||||
"total": "110.00",
|
||||
"adjustment": "0.00",
|
||||
"addedfrom": "0",
|
||||
"hash": "630f8cc7ed2e6a70c4113ab24041bdf5",
|
||||
"status": "6",
|
||||
"clientnote": "",
|
||||
"adminnote": "",
|
||||
"last_overdue_reminder": null,
|
||||
"cancel_overdue_reminders": "1",
|
||||
"allowed_payment_modes": "a:2:{i:0;s:1:\"1\";i:1;s:1:\"2\";}",
|
||||
"token": null,
|
||||
"discount_percent": "0.00",
|
||||
"discount_total": "0.00",
|
||||
"discount_type": "",
|
||||
"recurring": "0",
|
||||
"recurring_type": null,
|
||||
"custom_recurring": "0",
|
||||
"cycles": "0",
|
||||
"total_cycles": "0",
|
||||
"is_recurring_from": null,
|
||||
"last_recurring_date": null,
|
||||
"terms": "",
|
||||
"sale_agent": "0",
|
||||
"billing_street": "",
|
||||
"billing_city": "",
|
||||
"billing_state": "",
|
||||
"billing_zip": "",
|
||||
"billing_country": "0",
|
||||
"shipping_street": "",
|
||||
"shipping_city": "",
|
||||
"shipping_state": "",
|
||||
"shipping_zip": "",
|
||||
"shipping_country": "0",
|
||||
"include_shipping": "1",
|
||||
"show_shipping_on_invoice": "1",
|
||||
"show_quantity_as": "1",
|
||||
"project_id": "0",
|
||||
"subscription_id": "0",
|
||||
"short_link": null,
|
||||
"userid": "1",
|
||||
"company": "updated company",
|
||||
"vat": "",
|
||||
"phonenumber": "",
|
||||
"country": "0",
|
||||
"city": "",
|
||||
"zip": "",
|
||||
"state": "",
|
||||
"address": "",
|
||||
"website": "",
|
||||
"active": "1",
|
||||
"leadid": null,
|
||||
"longitude": null,
|
||||
"latitude": null,
|
||||
"default_language": "",
|
||||
"default_currency": "0",
|
||||
"show_primary_contact": "0",
|
||||
"stripe_id": null,
|
||||
"registration_confirmed": "1",
|
||||
"invoiceid": "2",
|
||||
"customfields": [
|
||||
{
|
||||
"label": "Input 1",
|
||||
"value": "test 12"
|
||||
},
|
||||
{
|
||||
"label": "Number 1",
|
||||
"value": "10"
|
||||
},
|
||||
{
|
||||
"label": "Textarea 1",
|
||||
"value": "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
|
||||
},
|
||||
{
|
||||
"label": "Select 1",
|
||||
"value": "Option 1"
|
||||
},
|
||||
{
|
||||
"label": "Multiselect 1",
|
||||
"value": "Option 1, Option 2"
|
||||
},
|
||||
{
|
||||
"label": "Checkbox 1",
|
||||
"value": "Option 1, Option 3"
|
||||
},
|
||||
{
|
||||
"label": "Datepicker 1",
|
||||
"value": "2021-05-06"
|
||||
},
|
||||
{
|
||||
"label": "Datetime Picker 1",
|
||||
"value": "2021-05-06 00:23:25"
|
||||
},
|
||||
{
|
||||
"label": "Colorpicker 1",
|
||||
"value": "#ffffff"
|
||||
},
|
||||
{
|
||||
"label": "Hyperlink 1",
|
||||
"value": "<a>Link</a>"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* Same as Original request
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {DELETE} N/A Delete Custom Fields
|
||||
* @apiVersion 0.2.0
|
||||
* @apiDescription To remove particular custom field value you can use **Update** action and an **empty** value in the custom field.<br /> Note: When you delete any record the corresponding custom field data will be **automatically deleted**.
|
||||
* @apiName DeleteActionExample
|
||||
* @apiGroup Custom Fields
|
||||
*
|
||||
*/
|
||||
}
|
||||
/* End of file Custom_fields.php */
|
||||
/* Location: ./application/controllers/Custom_fields.php */
|
||||
420
api/controllers/Customers.php
Normal file
420
api/controllers/Customers.php
Normal file
@@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Customers extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/customers/:id Request customer information
|
||||
* @apiName GetCustomer
|
||||
* @apiGroup Customers
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id customer unique ID.
|
||||
*
|
||||
* @apiSuccess {Object} customer information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "28",
|
||||
* "name": "Test1",
|
||||
* "description": null,
|
||||
* "status": "1",
|
||||
* "clientid": "11",
|
||||
* "billing_type": "3",
|
||||
* "start_date": "2019-04-19",
|
||||
* "deadline": "2019-08-30",
|
||||
* "customer_created": "2019-07-16",
|
||||
* "date_finished": null,
|
||||
* "progress": "0",
|
||||
* "progress_from_tasks": "1",
|
||||
* "customer_cost": "0.00",
|
||||
* "customer_rate_per_hour": "0.00",
|
||||
* "estimated_hours": "0.00",
|
||||
* "addedfrom": "5",
|
||||
* "rel_type": "customer",
|
||||
* "potential_revenue": "0.00",
|
||||
* "potential_margin": "0.00",
|
||||
* "external": "E",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('clients', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "customers", $id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/customers/search/:keysearch Search Customer Information
|
||||
* @apiName GetCustomerSearch
|
||||
* @apiGroup Customers
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords.
|
||||
*
|
||||
* @apiSuccess {Object} customer information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "28",
|
||||
* "name": "Test1",
|
||||
* "description": null,
|
||||
* "status": "1",
|
||||
* "clientid": "11",
|
||||
* "billing_type": "3",
|
||||
* "start_date": "2019-04-19",
|
||||
* "deadline": "2019-08-30",
|
||||
* "customer_created": "2019-07-16",
|
||||
* "date_finished": null,
|
||||
* "progress": "0",
|
||||
* "progress_from_tasks": "1",
|
||||
* "customer_cost": "0.00",
|
||||
* "customer_rate_per_hour": "0.00",
|
||||
* "estimated_hours": "0.00",
|
||||
* "addedfrom": "5",
|
||||
* "rel_type": "customer",
|
||||
* "potential_revenue": "0.00",
|
||||
* "potential_margin": "0.00",
|
||||
* "external": "E",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->search('customer', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "customers");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/customers Add New Customer
|
||||
* @apiName PostCustomer
|
||||
* @apiGroup Customers
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} company Mandatory Customer company.
|
||||
* @apiParam {String} [vat] Optional Vat.
|
||||
* @apiParam {String} [phonenumber] Optional Customer Phone.
|
||||
* @apiParam {String} [website] Optional Customer Website.
|
||||
* @apiParam {Number[]} [groups_in] Optional Customer groups.
|
||||
* @apiParam {String} [default_language] Optional Customer Default Language.
|
||||
* @apiParam {String} [default_currency] Optional default currency.
|
||||
* @apiParam {String} [address] Optional Customer address.
|
||||
* @apiParam {String} [city] Optional Customer City.
|
||||
* @apiParam {String} [state] Optional Customer state.
|
||||
* @apiParam {String} [zip] Optional Zip Code.
|
||||
* @apiParam {String} [partnership_type] Optional Customer partnership type.
|
||||
* @apiParam {String} [country] Optional country.
|
||||
* @apiParam {String} [billing_street] Optional Billing Address: Street.
|
||||
* @apiParam {String} [billing_city] Optional Billing Address: City.
|
||||
* @apiParam {Number} [billing_state] Optional Billing Address: State.
|
||||
* @apiParam {String} [billing_zip] Optional Billing Address: Zip.
|
||||
* @apiParam {String} [billing_country] Optional Billing Address: Country.
|
||||
* @apiParam {String} [shipping_street] Optional Shipping Address: Street.
|
||||
* @apiParam {String} [shipping_city] Optional Shipping Address: City.
|
||||
* @apiParam {String} [shipping_state] Optional Shipping Address: State.
|
||||
* @apiParam {String} [shipping_zip] Optional Shipping Address: Zip.
|
||||
* @apiParam {String} [shipping_country] Optional Shipping Address: Country.
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* array (size=22)
|
||||
* 'company' => string 'Themesic Interactive' (length=38)
|
||||
* 'vat' => string '123456789' (length=9)
|
||||
* 'phonenumber' => string '123456789' (length=9)
|
||||
* 'website' => string 'AAA.com' (length=7)
|
||||
* 'groups_in' =>
|
||||
* array (size=2)
|
||||
* 0 => string '1' (length=1)
|
||||
* 1 => string '4' (length=1)
|
||||
* 'default_currency' => string '3' (length=1)
|
||||
* 'default_language' => string 'english' (length=7)
|
||||
* 'address' => string '1a The Alexander Suite Silk Point' (length=27)
|
||||
* 'city' => string 'London' (length=14)
|
||||
* 'state' => string 'London' (length=14)
|
||||
* 'zip' => string '700000' (length=6)
|
||||
* 'country' => string '243' (length=3)
|
||||
* 'billing_street' => string '1a The Alexander Suite Silk Point' (length=27)
|
||||
* 'billing_city' => string 'London' (length=14)
|
||||
* 'billing_state' => string 'London' (length=14)
|
||||
* 'billing_zip' => string '700000' (length=6)
|
||||
* 'billing_country' => string '243' (length=3)
|
||||
* 'shipping_street' => string '1a The Alexander Suite Silk Point' (length=27)
|
||||
* 'shipping_city' => string 'London' (length=14)
|
||||
* 'shipping_state' => string 'London' (length=14)
|
||||
* 'shipping_zip' => string '700000' (length=6)
|
||||
* 'shipping_country' => string '243' (length=3)
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Customer add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Customer add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Customer add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Customer add fail."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
// form validation
|
||||
$this->form_validation->set_rules('company', 'Company', 'trim|required|max_length[600]', array('is_unique' => 'This %s already exists please enter another Company'));
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
// form validation error
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$groups_in = $this->Api_model->value($this->input->post('groups_in', TRUE));
|
||||
$insert_data = ['company' => $this->input->post('company', TRUE), 'vat' => $this->Api_model->value($this->input->post('vat', TRUE)), 'phonenumber' => $this->Api_model->value($this->input->post('phonenumber', TRUE)), 'website' => $this->Api_model->value($this->input->post('website', TRUE)), 'default_currency' => $this->Api_model->value($this->input->post('default_currency', TRUE)), 'default_language' => $this->Api_model->value($this->input->post('default_language', TRUE)), 'address' => $this->Api_model->value($this->input->post('address', TRUE)), 'city' => $this->Api_model->value($this->input->post('city', TRUE)), 'state' => $this->Api_model->value($this->input->post('state', TRUE)), 'zip' => $this->Api_model->value($this->input->post('zip', TRUE)), 'country' => $this->Api_model->value($this->input->post('country', TRUE)), 'billing_street' => $this->Api_model->value($this->input->post('billing_street', TRUE)), 'billing_city' => $this->Api_model->value($this->input->post('billing_city', TRUE)), 'billing_state' => $this->Api_model->value($this->input->post('billing_state', TRUE)), 'billing_zip' => $this->Api_model->value($this->input->post('billing_zip', TRUE)), 'billing_country' => $this->Api_model->value($this->input->post('billing_country', TRUE)), 'shipping_street' => $this->Api_model->value($this->input->post('shipping_street', TRUE)), 'shipping_city' => $this->Api_model->value($this->input->post('shipping_city', TRUE)), 'shipping_state' => $this->Api_model->value($this->input->post('shipping_state', TRUE)), 'shipping_zip' => $this->Api_model->value($this->input->post('shipping_zip', TRUE)), 'shipping_country' => $this->Api_model->value($this->input->post('shipping_country', TRUE)) ];
|
||||
if (!empty($this->input->post('custom_fields', TRUE))) {
|
||||
$insert_data['custom_fields'] = $this->Api_model->value($this->input->post('custom_fields', TRUE));
|
||||
}
|
||||
if ($groups_in != '') {
|
||||
$insert_data['groups_in'] = $groups_in;
|
||||
}
|
||||
// insert data
|
||||
$this->load->model('clients_model');
|
||||
$output = $this->clients_model->add($insert_data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Client add successful.',
|
||||
'record_id' => $output // Εδώ επιστρέφουμε το ID της νέας εγγραφής
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Client add fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/delete/customers/:id Delete a Customer
|
||||
* @apiName DeleteCustomer
|
||||
* @apiGroup Customers
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Customer unique ID.
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Customer Delete Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Customer Delete Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Customer Delete Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Customer Delete Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Customer ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
// delete data
|
||||
$this->load->model('clients_model');
|
||||
$output = $this->clients_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Customer Delete Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Customer Delete Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/customers/:id Update a Customer
|
||||
* @apiName PutCustomer
|
||||
* @apiGroup Customers
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} company Mandatory Customer company.
|
||||
* @apiParam {String} [vat] Optional Vat.
|
||||
* @apiParam {String} [phonenumber] Optional Customer Phone.
|
||||
* @apiParam {String} [website] Optional Customer Website.
|
||||
* @apiParam {Number[]} [groups_in] Optional Customer groups.
|
||||
* @apiParam {String} [default_language] Optional Customer Default Language.
|
||||
* @apiParam {String} [default_currency] Optional default currency.
|
||||
* @apiParam {String} [address] Optional Customer address.
|
||||
* @apiParam {String} [city] Optional Customer City.
|
||||
* @apiParam {String} [state] Optional Customer state.
|
||||
* @apiParam {String} [zip] Optional Zip Code.
|
||||
* @apiParam {String} [country] Optional country.
|
||||
* @apiParam {String} [billing_street] Optional Billing Address: Street.
|
||||
* @apiParam {String} [billing_city] Optional Billing Address: City.
|
||||
* @apiParam {Number} [billing_state] Optional Billing Address: State.
|
||||
* @apiParam {String} [billing_zip] Optional Billing Address: Zip.
|
||||
* @apiParam {String} [billing_country] Optional Billing Address: Country.
|
||||
* @apiParam {String} [shipping_street] Optional Shipping Address: Street.
|
||||
* @apiParam {String} [shipping_city] Optional Shipping Address: City.
|
||||
* @apiParam {String} [shipping_state] Optional Shipping Address: State.
|
||||
* @apiParam {String} [shipping_zip] Optional Shipping Address: Zip.
|
||||
* @apiParam {String} [shipping_country] Optional Shipping Address: Country.
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "company": "Công ty A",
|
||||
* "vat": "",
|
||||
* "phonenumber": "0123456789",
|
||||
* "website": "",
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "country": "243",
|
||||
* "city": "TP London",
|
||||
* "zip": "700000",
|
||||
* "state": "Quận 12",
|
||||
* "address": "hẻm 71, số 34\/3 Đường TA 16, Phường Thới An, Quận 12",
|
||||
* "billing_street": "hẻm 71, số 34\/3 Đường TA 16, Phường Thới An, Quận 12",
|
||||
* "billing_city": "TP London",
|
||||
* "billing_state": "Quận 12",
|
||||
* "billing_zip": "700000",
|
||||
* "billing_country": "243",
|
||||
* "shipping_street": "",
|
||||
* "shipping_city": "",
|
||||
* "shipping_state": "",
|
||||
* "shipping_zip": "",
|
||||
* "shipping_country": "0"
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Customer Update Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Customer Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Customer Update Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Customer Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '') {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Customers ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$update_data = $this->input->post();
|
||||
// update data
|
||||
$this->load->model('clients_model');
|
||||
$output = $this->clients_model->update($update_data, $id);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Customers Update Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Customers Update Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
api/controllers/Env_ver.php
Normal file
29
api/controllers/Env_ver.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
class Env_ver extends AdminController {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
show_404();
|
||||
}
|
||||
|
||||
public function activate() {
|
||||
$res = modules\api\core\Apiinit::pre_validate($this->input->post('module_name'), $this->input->post('purchase_key'));
|
||||
if ($res['status']) {
|
||||
$res['original_url'] = $this->input->post('original_url');
|
||||
}
|
||||
echo json_encode($res);
|
||||
}
|
||||
|
||||
public function upgrade_database() {
|
||||
$res = modules\api\core\Apiinit::pre_validate($this->input->post('module_name'), $this->input->post('purchase_key'));
|
||||
if ($res['status']) {
|
||||
$res['original_url'] = $this->input->post('original_url');
|
||||
}
|
||||
echo json_encode($res);
|
||||
}
|
||||
}
|
||||
731
api/controllers/Estimates.php
Normal file
731
api/controllers/Estimates.php
Normal file
@@ -0,0 +1,731 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Estimates extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/estimates/:id Request Estimate information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetEstimate
|
||||
* @apiGroup Estimates
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiParam {Number} id Contact unique ID
|
||||
*
|
||||
* @apiSuccess {Object} Estimates information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "1",
|
||||
* "sent": "0",
|
||||
* "datesend": null,
|
||||
* "clientid": "1",
|
||||
* "deleted_customer_name": null,
|
||||
* "project_id": "0",
|
||||
* "number": "1",
|
||||
* "prefix": "EST-",
|
||||
* "number_format": "1",
|
||||
* "hash": "b12ae9de6471d0cf153d7846f05128af",
|
||||
* "datecreated": "2021-07-31 11:06:49",
|
||||
* "date": "2021-07-31",
|
||||
* "expirydate": "2021-08-07",
|
||||
* "currency": "1",
|
||||
* "subtotal": "1200.00",
|
||||
* "total_tax": "0.00",
|
||||
* "total": "1200.00",
|
||||
* "adjustment": "0.00",
|
||||
* "addedfrom": "1",
|
||||
* "status": "1",
|
||||
* "clientnote": "",
|
||||
* "adminnote": "",
|
||||
* "discount_percent": "0.00",
|
||||
* "discount_total": "0.00",
|
||||
* "discount_type": "",
|
||||
* "invoiceid": null,
|
||||
* "invoiced_date": null,
|
||||
* "terms": "",
|
||||
* "reference_no": "",
|
||||
* "sale_agent": "0",
|
||||
* "billing_street": "Thangadh, Gujarat, India<br />\r\nShipping",
|
||||
* "billing_city": "Thangadh",
|
||||
* "billing_state": "Gujarat",
|
||||
* "billing_zip": "363630",
|
||||
* "billing_country": "102",
|
||||
* "shipping_street": "Thangadh, Gujarat, India<br />\r\nShipping",
|
||||
* "shipping_city": "Thangadh",
|
||||
* "shipping_state": "Gujarat",
|
||||
* "shipping_zip": "363630",
|
||||
* "shipping_country": "102",
|
||||
* "include_shipping": "1",
|
||||
* "show_shipping_on_estimate": "1",
|
||||
* "show_quantity_as": "1",
|
||||
* "pipeline_order": "0",
|
||||
* "is_expiry_notified": "0",
|
||||
* "acceptance_firstname": null,
|
||||
* "acceptance_lastname": null,
|
||||
* "acceptance_email": null,
|
||||
* "acceptance_date": null,
|
||||
* "acceptance_ip": null,
|
||||
* "signature": null,
|
||||
* "short_link": null,
|
||||
* "symbol": "$",
|
||||
* "name": "USD",
|
||||
* "decimal_separator": ".",
|
||||
* "thousand_separator": ",",
|
||||
* "placement": "before",
|
||||
* "isdefault": "1",
|
||||
* "currencyid": "1",
|
||||
* "currency_name": "USD",
|
||||
* "attachments": [],
|
||||
* "visible_attachments_to_customer_found": false,
|
||||
* "items": [
|
||||
* {
|
||||
* "id": "2",
|
||||
* "rel_id": "1",
|
||||
* "rel_type": "estimate",
|
||||
* "description": "test",
|
||||
* "long_description": "test",
|
||||
* "qty": "1.00",
|
||||
* "rate": "1200.00",
|
||||
* "unit": "1",
|
||||
* "item_order": "1"
|
||||
* }
|
||||
* ],
|
||||
* "client": {
|
||||
* "userid": "1",
|
||||
* "company": "test",
|
||||
* "vat": "",
|
||||
* "phonenumber": "01324568903",
|
||||
* "country": "102",
|
||||
* "city": "test",
|
||||
* "zip": "3000",
|
||||
* "state": "Test",
|
||||
* "address": "Test",
|
||||
* "website": "",
|
||||
* "datecreated": "2021-07-30 16:29:46",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "billing_street": "Test",
|
||||
* "billing_city": "Test",
|
||||
* "billing_state": "Test",
|
||||
* "billing_zip": "3000",
|
||||
* "billing_country": "102",
|
||||
* "shipping_street": "Test",
|
||||
* "shipping_city": "Test",
|
||||
* "shipping_state": "Test",
|
||||
* "shipping_zip": "3000",
|
||||
* "shipping_country": "102",
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "addedfrom": "1"
|
||||
* },
|
||||
* "scheduled_email": null,
|
||||
* "customfields": []
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('estimates', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "estimate", $id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/estimates/search/:keysearch Search Estimate information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetEstimateSearch
|
||||
* @apiGroup Estimates
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Estimate Information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "2",
|
||||
* "sent": "0",
|
||||
* "datesend": null,
|
||||
* "clientid": "1",
|
||||
* "deleted_customer_name": null,
|
||||
* "project_id": "0",
|
||||
* "number": "2",
|
||||
* "prefix": "EST-",
|
||||
* "number_format": "1",
|
||||
* "hash": "ac754972999f948ade369c70bb44d696",
|
||||
* "datecreated": "2021-07-30 16:29:46",
|
||||
* "date": "2021-08-01",
|
||||
* "expirydate": "2021-08-08",
|
||||
* "currency": "1",
|
||||
* "subtotal": "1200.00",
|
||||
* "total_tax": "0.00",
|
||||
* "total": "1200.00",
|
||||
* "adjustment": "0.00",
|
||||
* "addedfrom": "1",
|
||||
* "status": "1",
|
||||
* "clientnote": "",
|
||||
* "adminnote": "adminnote",
|
||||
* "discount_percent": "0.00",
|
||||
* "discount_total": "0.00",
|
||||
* "discount_type": "",
|
||||
* "invoiceid": null,
|
||||
* "invoiced_date": null,
|
||||
* "terms": "",
|
||||
* "reference_no": "",
|
||||
* "sale_agent": "0",
|
||||
* "billing_street": "Test",
|
||||
* "billing_city": "Test",
|
||||
* "billing_state": "Test",
|
||||
* "billing_zip": "3000",
|
||||
* "billing_country": "102",
|
||||
* "shipping_street": "Test",
|
||||
* "shipping_city": "Test",
|
||||
* "shipping_state": "Test",
|
||||
* "shipping_zip": "3000",
|
||||
* "shipping_country": "102",
|
||||
* "include_shipping": "1",
|
||||
* "show_shipping_on_estimate": "1",
|
||||
* "show_quantity_as": "1",
|
||||
* "pipeline_order": "0",
|
||||
* "is_expiry_notified": "0",
|
||||
* "acceptance_firstname": null,
|
||||
* "acceptance_lastname": null,
|
||||
* "acceptance_email": null,
|
||||
* "acceptance_date": null,
|
||||
* "acceptance_ip": null,
|
||||
* "signature": null,
|
||||
* "short_link": null,
|
||||
* "userid": "1",
|
||||
* "company": "test",
|
||||
* "vat": "",
|
||||
* "phonenumber": "01324568903",
|
||||
* "country": "102",
|
||||
* "city": "Test",
|
||||
* "zip": "3000",
|
||||
* "state": "Test",
|
||||
* "address": "Test",
|
||||
* "website": "",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "estimateid": "2",
|
||||
* "customfields": []
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No Data Were Found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
$data = $this->Api_model->search('estimates', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "estimate");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/estimates/:id Delete Estimate
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName DeleteEstimate
|
||||
* @apiGroup Estimates
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Estimates Deleted Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Estimate Deleted Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Estimate Delete Fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Estimate Delete Fail"
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Estimate ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('estimates_model');
|
||||
$is_exist = $this->estimates_model->get($id);
|
||||
if (is_object($is_exist)) {
|
||||
$output = $this->estimates_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Estimate Deleted Successfully');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Estimate Delete Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Estimate ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/estimates Add New Estimates
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName PostEstimates
|
||||
* @apiGroup Estimates
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} clientid Mandatory. Customer id
|
||||
* @apiParam {Number} number Mandatory. Estimates Number
|
||||
* @apiParam {Date} date Mandatory. Estimates Date
|
||||
* @apiParam {Date} [duedate] Optional. Expiry Date of Estimates
|
||||
* @apiParam {Number} currency Mandatory. currency field
|
||||
* @apiParam {Array} newitems Mandatory. New Items to be added
|
||||
* @apiParam {Decimal} subtotal Mandatory. calculation based on item Qty, Rate and Tax
|
||||
* @apiParam {Decimal} total Mandatory. calculation based on subtotal, Discount and Adjustment
|
||||
* @apiParam {String} billing_street Optional. Street Address
|
||||
* @apiParam {String} [billing_city] Optional. City Name for billing
|
||||
* @apiParam {String} [billing_state] Optional. Name of state for billing
|
||||
* @apiParam {Number} [billing_zip] Optional. Zip code
|
||||
* @apiParam {Number} [billing_country] Optional. Country code
|
||||
* @apiParam {String} [shipping_street] Optional. Address of shipping
|
||||
* @apiParam {String} [shipping_city] Optional. City name for shipping
|
||||
* @apiParam {String} [shipping_state] Optional. Name of state for shipping
|
||||
* @apiParam {Number} [shipping_zip] Optional. Zip code for shipping
|
||||
* @apiParam {Number} [shipping_country] Optional. Country code
|
||||
* @apiParam {String} [tags] Optional. TAGS comma separated
|
||||
* @apiParam {Number} [status] Optional. Status id (default status is Accepted)
|
||||
* @apiParam {String} [Reference] Optional. Reference name
|
||||
* @apiParam {Number} [sale_agent] Optional. Sale Agent name
|
||||
* @apiParam {String} [adminnote] Optional. notes by admin
|
||||
* @apiParam {String} [clientnote] Optional. client notes
|
||||
* @apiParam {String} [terms] Optional. Terms
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* [
|
||||
* "clientid"=>1,
|
||||
* "number"=>"00001",
|
||||
* "date"=>"2020-09-07",
|
||||
* "currency"=>1,
|
||||
* "newitems[0][description]"=>"item 1 description",
|
||||
* "newitems[0][long_description]"=>"item 1 long description",
|
||||
* "newitems[0][qty]"=>1,
|
||||
* "newitems[0][rate]"=>100,
|
||||
* "newitems[0][order]"=>1,
|
||||
* "newitems[0][taxname][]"=>CGST|9.00,
|
||||
* "newitems[0][taxname][]"=>SGST|9.00,
|
||||
* "newitems[0][unit]"=>"",
|
||||
* "newitems[1][description]"=>"item 2 description",
|
||||
* "newitems[1][long_description]"=>"item 2 long description",
|
||||
* "newitems[1][qty]"=>1,
|
||||
* "newitems[1][rate]"=>100,
|
||||
* "newitems[1][order]"=>1,
|
||||
* "newitems[1][taxname][]"=>CGST|9.00,
|
||||
* "newitems[1][taxname][]"=>SGST|9.00,
|
||||
* "newitems[1][unit]"=>"",
|
||||
* "subtotal"=>236.00,
|
||||
* "total"=>236.00,
|
||||
* "status"=>1,
|
||||
* ....
|
||||
* ]
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Estimates Added Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Estimates Added Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Estimates add fail
|
||||
* @apiError {String} newitems[] The Items field is required
|
||||
* @apiError {String} number The Estimates number is already in use
|
||||
* @apiError {String} subtotal The Sub Total field is required
|
||||
* @apiError {String} total The Total field is required
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Estimates Add Fail"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "number":"The Estimates number is already in use"
|
||||
* },
|
||||
* "message": "The Estimates number is already in use"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "newitems[]": "The Items field is required"
|
||||
* },
|
||||
* "message": "<p>The Items field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "subtotal": "The Sub Total field is required"
|
||||
* },
|
||||
* "message": "<p>The Sub Total field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "total": "The Total field is required"
|
||||
* },
|
||||
* "message": "<p>The Total field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
error_reporting(0);
|
||||
$data = $this->input->post();
|
||||
$this->form_validation->set_rules('clientid', 'Customer', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('project_id', 'Project', 'trim|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('include_shipping', 'Include Shipping', 'trim|numeric|greater_than_equal_to[0]|less_than_equal_to[1]');
|
||||
$this->form_validation->set_rules('show_shipping_on_estimate', 'Show shipping on estimate', 'trim|numeric|greater_than_equal_to[0]|less_than_equal_to[1]');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('status', 'Status', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('date', 'Estimate date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('quantity', 'Quantity', 'trim|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('newitems[]', 'Items', 'required');
|
||||
$this->form_validation->set_rules('subtotal', 'Sub Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('total', 'Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('billing_street', 'Street', 'trim|required|max_length[200]');
|
||||
$this->form_validation->set_rules('number', 'Estimate Number', 'trim|required|numeric|callback_validate_estimate_number[0]');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('estimates_model');
|
||||
$data['expirydate'] = _d(date('Y-m-d', strtotime('+' . get_option('estimate_due_after') . ' DAY', strtotime(date('Y-m-d')))));
|
||||
$id = $this->estimates_model->add($data);
|
||||
if ($id > 0 && !empty($id)) {
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Estimate Added Successfully',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Estimate Add Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function validate_estimate_number($number, $estimateid) {
|
||||
$isedit = 'false';
|
||||
if (!empty($estimateid)) {
|
||||
$isedit = 'true';
|
||||
}
|
||||
$this->form_validation->set_message('validate_estimate_number', 'The {field} is already in use');
|
||||
$original_number = null;
|
||||
$date = $this->input->post('date');
|
||||
if (!empty($estimateid)) {
|
||||
$data = $this->Api_model->get_table('estimates', $estimateid);
|
||||
$original_number = $data->number;
|
||||
if (empty($date)) {
|
||||
$date = $data->date;
|
||||
}
|
||||
}
|
||||
$number = trim($number);
|
||||
$number = ltrim($number, '0');
|
||||
if ($isedit == 'true') {
|
||||
if ($number == $original_number) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (total_rows(db_prefix() . 'estimates', ['YEAR(date)' => date('Y', strtotime(to_sql_date($date))), 'number' => $number, ]) > 0) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/estimates/:id Update a estimate
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName PutEstimate
|
||||
* @apiGroup Estimates
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} clientid Mandatory. Customer.
|
||||
* @apiParam {String} billing_street Mandatory. Street Address
|
||||
* @apiParam {String} [billing_city] Optional. City Name for billing
|
||||
* @apiParam {String} [billing_state] Optional. Name of state for billing
|
||||
* @apiParam {Number} [billing_zip] Optional. Zip code
|
||||
* @apiParam {Number} [billing_country] Optional. Country code
|
||||
* @apiParam {boolean} [include_shipping="no"] Optional. set yes if you want add Shipping Address
|
||||
* @apiParam {boolean} [show_shipping_on_estimate] Optional. Shows shipping details in estimate.
|
||||
* @apiParam {String} [shipping_street] Optional. Address of shipping
|
||||
* @apiParam {String} [shipping_city] Optional. City name for shipping
|
||||
* @apiParam {String} [shipping_state] Optional. Name of state for shipping
|
||||
* @apiParam {Number} [shipping_zip] Optional. Zip code for shipping
|
||||
* @apiParam {Number} [shipping_country] Optional. Country code
|
||||
* @apiParam {Number} number Mandatory. Estimate Number
|
||||
* @apiParam {Date} date Mandatory. Estimate Date
|
||||
* @apiParam {Date} [expirydate] Optional. Expiry Date of Estimate
|
||||
* @apiParam {String} [tags] Optional. TAGS comma separated
|
||||
* @apiParam {Number} currency Mandatory. currency field
|
||||
* @apiParam {Number} status Mandatory. Estimate Status(eg. Draft, Sent)
|
||||
* @apiParam {String} [reference_no] Optional. Reference #
|
||||
* @apiParam {Number} [sale_agent] Optional. Sale Agent name
|
||||
* @apiParam {String} [discount_type] Optional. before_tax / after_tax discount type
|
||||
* @apiParam {String} [adminnote] Optional. notes by admin
|
||||
* @apiParam {Array} [items] Mandatory. Existing items with Id
|
||||
* @apiParam {Array} [removed_items] Optional. Items to be removed
|
||||
* @apiParam {Array} [newitems] Optional. New Items to be added
|
||||
* @apiParam {Decimal} subtotal Mandatory. calculation based on item Qty, Rate and Tax
|
||||
* @apiParam {Decimal} total Mandatory. calculation based on subtotal, Discount and Adjustment
|
||||
* @apiParam {String} [clientnote] Optional. client notes
|
||||
* @apiParam {String} [terms] Optional. Terms
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "clientid": 1,
|
||||
* "billing_street": "new 1 update",
|
||||
* "number": 2,
|
||||
* "status": 2,
|
||||
* "date": "2021-08-19",
|
||||
* "currency": 1,
|
||||
* "items": {
|
||||
* "1": {
|
||||
* "itemid": "24",
|
||||
* "order": "1",
|
||||
* "description": "item description",
|
||||
* "long_description": "item long description",
|
||||
* "qty": "1",
|
||||
* "unit": "1",
|
||||
* "rate": "10.00",
|
||||
* "custom_fields":{
|
||||
* "items":{
|
||||
* "31":"test 12 item 1",
|
||||
* "32":"10",
|
||||
* "33":"Lorem Ipsum is simply dummy text of the printing and typesetting industry",
|
||||
* "34":"Option 1",
|
||||
* "35":["Option 1","Option 2"],
|
||||
* "36":["Option 1","Option 3"],
|
||||
* "37":"2021-05-06",
|
||||
* "38":"2021-05-06 00:23:25",
|
||||
* "39":"#ffffff",
|
||||
* "40":"<a href=\"url.com\" target=\"_blank\">Link</a>"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* },
|
||||
* "newitems": {
|
||||
* "2": {
|
||||
* "order": "2",
|
||||
* "description": "updated item 2 description",
|
||||
* "long_description": "updated item 2 logn description",
|
||||
* "qty": "1",
|
||||
* "unit": "",
|
||||
* "rate": "100.00",
|
||||
* "custom_fields":{
|
||||
* "items":{
|
||||
* "31":"test 12 item 2",
|
||||
* "32":"10",
|
||||
* "33":"Lorem Ipsum is simply dummy text of the printing and typesetting industry",
|
||||
* "34":"Option 1",
|
||||
* "35":["Option 1","Option 2"],
|
||||
* "36":["Option 1","Option 3"],
|
||||
* "37":"2021-05-06",
|
||||
* "38":"2021-05-06 00:23:25",
|
||||
* "39":"#ffffff",
|
||||
* "40":"<a href=\"url.com\" target=\"_blank\">Link</a>"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* },
|
||||
* "custom_fields":{
|
||||
* "estimate":{
|
||||
* "92":"test 1254"
|
||||
* }
|
||||
* },
|
||||
* "subtotal":"110.00",
|
||||
* "total":"110.00"
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Estimate Updated Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Estimate Update Fail"
|
||||
* }
|
||||
*
|
||||
* @apiError {String} number The Estimate number is already in use
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "number":"The Estimate number is already in use"
|
||||
* },
|
||||
* "message": "The Estimate number is already in use"
|
||||
* }
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function data_put($id = "") {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Estimate ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->form_validation->set_rules('clientid', 'Customer', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('project_id', 'Project', 'trim|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('include_shipping', 'Include Shipping', 'trim|numeric|greater_than_equal_to[0]|less_than_equal_to[1]');
|
||||
$this->form_validation->set_rules('show_shipping_on_estimate', 'Show shipping on estimate', 'trim|numeric|greater_than_equal_to[0]|less_than_equal_to[1]');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('status', 'Status', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('date', 'Estimate date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('quantity', 'Quantity', 'trim|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('items[]', 'Items', 'required');
|
||||
$this->form_validation->set_rules('subtotal', 'Sub Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('total', 'Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('billing_street', 'Street', 'trim|required|max_length[200]');
|
||||
$this->form_validation->set_rules('number', 'Estimate Number', 'trim|required|numeric|callback_validate_estimate_number[' . $id . ']');
|
||||
$_POST['shipping_street'] = $_POST['shipping_street']??"";
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
} else {
|
||||
$this->load->model('estimates_model');
|
||||
$is_exist = $this->estimates_model->get($id);
|
||||
if (!is_object($is_exist)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Estimate ID Doesn\'t Not Exist.');
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
}
|
||||
if (is_object($is_exist)) {
|
||||
$data = $this->input->post();
|
||||
$data['isedit'] = "";
|
||||
$success = $this->estimates_model->update($data, $id);
|
||||
if ($success == true) {
|
||||
$message = array('status' => TRUE, 'message' => "Estimate Updated Successfully",);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Estimate Update Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Estimate ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
671
api/controllers/Expenses.php
Normal file
671
api/controllers/Expenses.php
Normal file
@@ -0,0 +1,671 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Expenses extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/expenses/:id Request Expense information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetExpense
|
||||
* @apiGroup Expenses
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {Number} id Expense unique ID.
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiSuccess {Array} Expense Expense information.
|
||||
* @apiSuccessExample Success-Response:
|
||||
* [
|
||||
* {
|
||||
* "id": "1",
|
||||
* "category": "1",
|
||||
* "currency": "1",
|
||||
* "amount": "50.00",
|
||||
* "tax": "0",
|
||||
* "tax2": "0",
|
||||
* "reference_no": "012457893",
|
||||
* "note": "AWS server hosting charges",
|
||||
* "expense_name": "Cloud Hosting",
|
||||
* "clientid": "1",
|
||||
* "project_id": "0",
|
||||
* "billable": "0",
|
||||
* "invoiceid": null,
|
||||
* "paymentmode": "2",
|
||||
* "date": "2021-09-01",
|
||||
* "recurring_type": "month",
|
||||
* "repeat_every": "1",
|
||||
* "recurring": "1",
|
||||
* "cycles": "12",
|
||||
* "total_cycles": "0",
|
||||
* "custom_recurring": "0",
|
||||
* "last_recurring_date": null,
|
||||
* "create_invoice_billable": "0",
|
||||
* "send_invoice_to_customer": "0",
|
||||
* "recurring_from": null,
|
||||
* "dateadded": "2021-09-01 12:26:34",
|
||||
* "addedfrom": "1",
|
||||
* "is_expense_created_in_xero": "0",
|
||||
* "userid": "1",
|
||||
* "company": "Company A",
|
||||
* "vat": "",
|
||||
* "phonenumber": "",
|
||||
* "country": "0",
|
||||
* "city": "",
|
||||
* "zip": "",
|
||||
* "state": "",
|
||||
* "address": "",
|
||||
* "website": "",
|
||||
* "datecreated": "2020-05-25 22:55:49",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "billing_street": "",
|
||||
* "billing_city": "",
|
||||
* "billing_state": "",
|
||||
* "billing_zip": "",
|
||||
* "billing_country": "0",
|
||||
* "shipping_street": "",
|
||||
* "shipping_city": "",
|
||||
* "shipping_state": "",
|
||||
* "shipping_zip": "",
|
||||
* "shipping_country": "0",
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "name": "Hosting Management",
|
||||
* "description": "server space and other settings",
|
||||
* "show_on_pdf": "0",
|
||||
* "invoices_only": "0",
|
||||
* "expenses_only": "0",
|
||||
* "selected_by_default": "0",
|
||||
* "taxrate": null,
|
||||
* "category_name": "Hosting Management",
|
||||
* "payment_mode_name": "Paypal",
|
||||
* "tax_name": null,
|
||||
* "tax_name2": null,
|
||||
* "taxrate2": null,
|
||||
* "expenseid": "1",
|
||||
* "customfields": []
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('expenses', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "expenses", $id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/expenses/search/:keysearch Search Expenses information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetExpenseSearch
|
||||
* @apiGroup Expenses
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords
|
||||
*
|
||||
* @apiSuccess {Array} Expenses Expenses Information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* [
|
||||
* {
|
||||
* "id": "1",
|
||||
* "category": "1",
|
||||
* "currency": "1",
|
||||
* "amount": "50.00",
|
||||
* "tax": "0",
|
||||
* "tax2": "0",
|
||||
* "reference_no": "012457893",
|
||||
* "note": "AWS server hosting charges",
|
||||
* "expense_name": "Cloud Hosting",
|
||||
* "clientid": "1",
|
||||
* "project_id": "0",
|
||||
* "billable": "0",
|
||||
* "invoiceid": null,
|
||||
* "paymentmode": "2",
|
||||
* "date": "2021-09-01",
|
||||
* "recurring_type": "month",
|
||||
* "repeat_every": "1",
|
||||
* "recurring": "1",
|
||||
* "cycles": "12",
|
||||
* "total_cycles": "0",
|
||||
* "custom_recurring": "0",
|
||||
* "last_recurring_date": null,
|
||||
* "create_invoice_billable": "0",
|
||||
* "send_invoice_to_customer": "0",
|
||||
* "recurring_from": null,
|
||||
* "dateadded": "2021-09-01 12:26:34",
|
||||
* "addedfrom": "1",
|
||||
* "is_expense_created_in_xero": "0",
|
||||
* "userid": "1",
|
||||
* "company": "Company A",
|
||||
* "vat": "",
|
||||
* "phonenumber": "",
|
||||
* "country": "0",
|
||||
* "city": "",
|
||||
* "zip": "",
|
||||
* "state": "",
|
||||
* "address": "",
|
||||
* "website": "",
|
||||
* "datecreated": "2020-05-25 22:55:49",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "billing_street": "",
|
||||
* "billing_city": "",
|
||||
* "billing_state": "",
|
||||
* "billing_zip": "",
|
||||
* "billing_country": "0",
|
||||
* "shipping_street": "",
|
||||
* "shipping_city": "",
|
||||
* "shipping_state": "",
|
||||
* "shipping_zip": "",
|
||||
* "shipping_country": "0",
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "name": "Hosting Management",
|
||||
* "description": "server space and other settings",
|
||||
* "show_on_pdf": "0",
|
||||
* "invoices_only": "0",
|
||||
* "expenses_only": "0",
|
||||
* "selected_by_default": "0",
|
||||
* "taxrate": null,
|
||||
* "category_name": "Hosting Management",
|
||||
* "payment_mode_name": "Paypal",
|
||||
* "tax_name": null,
|
||||
* "tax_name2": null,
|
||||
* "taxrate2": null,
|
||||
* "expenseid": "1",
|
||||
* "customfields": []
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError {Boolean} status Request status
|
||||
* @apiError {String} message No data were found
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
$data = $this->Api_model->search('expenses', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "expenses");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/expenses/:id Delete Expense
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName DeleteExpenses
|
||||
* @apiGroup Expenses
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Expense Deleted Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Expense Deleted Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Expense Delete Fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Expense Delete Fail"
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Expense ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('expenses_model');
|
||||
$is_exist = $this->expenses_model->get($id);
|
||||
if (is_object($is_exist)) {
|
||||
$output = $this->expenses_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Expense Deleted Successfully');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Expense Delete Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Expense ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/expenses Add Expense
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName AddExpense
|
||||
* @apiGroup Expenses
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} [expense_name] Optional. Expanse Name
|
||||
* @apiParam {String} [note] Optional. Expanse Note
|
||||
* @apiParam {Number} category Mandatory. Expense Category
|
||||
* @apiParam {Decimal} amount Mandatory. Expense Amount
|
||||
* @apiParam {Date} date Mandatory. Expense Date
|
||||
* @apiParam {Number} clientid Optional. Customer id
|
||||
* @apiParam {Number} currency Mandatory. Currency Field
|
||||
* @apiParam {Number} tax Optional. Tax 1
|
||||
* @apiParam {Number} tax2 Optional. Tax 2
|
||||
* @apiParam {Number} paymentmode Optional. Payment mode
|
||||
* @apiParam {String} [reference_no] Optional. Reference #
|
||||
* @apiParam {String} [recurring] Optional. recurring 1 to 12 or custom
|
||||
* @apiParam {Number} [repeat_every_custom] Optional. if recurring is custom set number gap
|
||||
* @apiParam {String} [repeat_type_custom] Optional. if recurring is custom set gap option day/week/month/year
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "expense_name": "Test51",
|
||||
* "note": "Expanse note",
|
||||
* "category": 300,
|
||||
* "date": "2021-08-20",
|
||||
* "amount": "1200.00",
|
||||
* "billable": 1,
|
||||
* "clientid": 1,
|
||||
* "currency": 1,
|
||||
* "tax": 1,
|
||||
* "tax2": 1,
|
||||
* "paymentmode": 2,
|
||||
* "reference_no": 5874,
|
||||
* "repeat_every": "6-month",
|
||||
* "cycles": 5,
|
||||
* "create_invoice_billable": 0,
|
||||
* "send_invoice_to_customer": 1,
|
||||
* "custom_fields":
|
||||
* {
|
||||
* "expenses":
|
||||
* {
|
||||
* "94": "test 1254"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Expense Added Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Expense Added Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Expense Update Fail
|
||||
* @apiError {String} category The Expense Category is not found.
|
||||
* @apiError {String} date The Expense date field is required.
|
||||
* @apiError {String} amount The Amount field is required.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Expense Add Fail"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "category":"The Expense Category is not found"
|
||||
* },
|
||||
* "message": "The Expense Category is not found"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "date":"The Expense date field is required."
|
||||
* },
|
||||
* "message": "The Expense date field is required."
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "amount":"The Amount field is required."
|
||||
* },
|
||||
* "message": "The Amount field is required."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
$data = $this->input->post();
|
||||
|
||||
$this->form_validation->set_rules('category', 'Expense Category', 'trim|required|max_length[255]|callback_validate_category');
|
||||
$this->form_validation->set_rules('date', 'Expense date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('category', 'Expense Category', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('date', 'Invoice date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('amount', 'Amount', 'trim|required|decimal|greater_than[0]');
|
||||
$data['note'] = $data['note'] ?? "";
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
} else {
|
||||
$this->load->model('expenses_model');
|
||||
$id = $this->expenses_model->add($data);
|
||||
if ($id > 0 && !empty($id)) {
|
||||
$this->handle_expense_attachments_array($id);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Expense added successfully.',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Expense add fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/expenses Update a Expense
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName PutExpense
|
||||
* @apiGroup Expenses
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} [expense_name] Optional. Name
|
||||
* @apiParam {String} [note] Optional. Note
|
||||
* @apiParam {Number} category Mandatory. Expense Category
|
||||
* @apiParam {Decimal} amount Mandatory. Expense Amount
|
||||
* @apiParam {Date} date Mandatory. Expense Date
|
||||
* @apiParam {Number} clientid Optional. Customer id
|
||||
* @apiParam {Number} currency Mandatory. currency field
|
||||
* @apiParam {Number} tax Optional. Tax 1
|
||||
* @apiParam {Number} tax2 Optional. Tax 2
|
||||
* @apiParam {Number} paymentmode Optional. Payment mode
|
||||
* @apiParam {String} [reference_no] Optional. Reference #
|
||||
* @apiParam {String} [recurring] Optional. recurring 1 to 12 or custom
|
||||
* @apiParam {Number} [repeat_every_custom] Optional. if recurring is custom set number gap
|
||||
* @apiParam {String} [repeat_type_custom] Optional. if recurring is custom set gap option day/week/month/year
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "expense_name": "Test51",
|
||||
* "note": "exp note",
|
||||
* "category": 300,
|
||||
* "date": "2021-08-20",
|
||||
* "amount": "1200.00",
|
||||
* "billable": 1,
|
||||
* "clientid": 1,
|
||||
* "currency": 1,
|
||||
* "tax": 1,
|
||||
* "tax2": 1,
|
||||
* "paymentmode": 2,
|
||||
* "reference_no": 5874,
|
||||
* "repeat_every": "6-month",
|
||||
* "cycles": 5,
|
||||
* "create_invoice_billable": 0,
|
||||
* "send_invoice_to_customer": 1,
|
||||
* "custom_fields":
|
||||
* {
|
||||
* "expenses":
|
||||
* {
|
||||
* "94": "test 1254"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Expense Updated Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Expense Updated Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Expense Update Fail
|
||||
* @apiError {String} category The Expense Category is not found.
|
||||
* @apiError {String} date The Expense date field is required.
|
||||
* @apiError {String} amount The Amount field is required.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Expense Update Fail"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "category":"The Expense Category is not found"
|
||||
* },
|
||||
* "message": "The Expense Category is not found"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "date":"The Expense date field is required."
|
||||
* },
|
||||
* "message": "The Expense date field is required."
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "amount":"The Amount field is required."
|
||||
* },
|
||||
* "message": "The Amount field is required."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_put($id = "") {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$this->load->library('parse_input_stream');
|
||||
$_POST = $this->parse_input_stream->parse_parameters();
|
||||
$_FILES = $this->parse_input_stream->parse_files();
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Lead ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('expenses_model');
|
||||
$is_exist = $this->expenses_model->get($id);
|
||||
if (!is_object($is_exist)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Expense ID Doesn\'t Not Exist.');
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
}
|
||||
if (is_object($is_exist)) {
|
||||
$update_data = $this->input->post();
|
||||
$update_file = isset($update_data['file']) ? $update_data['file'] : null;
|
||||
unset($update_data['file']);
|
||||
|
||||
$output = $this->expenses_model->update($update_data, $id);
|
||||
if (!empty($update_file) && count($update_file)) {
|
||||
if ($output <= 0 || empty($output)) {
|
||||
$output = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($output > 0 && !empty($output)) {
|
||||
$this->expenses_model->delete_expense_attachment($output);
|
||||
$this->handle_expense_attachments_array($output);
|
||||
$message = array('status' => TRUE, 'message' => "Expense Updated Successfully",);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Expense Update Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Expense ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function validate_category($value) {
|
||||
$this->form_validation->set_message('validate_category', 'The {field} is not found.');
|
||||
$this->load->model('expenses_model');
|
||||
$is_exist = $this->expenses_model->get_category($value);
|
||||
if ($is_exist) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function handle_expense_attachments_array($expense_id, $index_name = 'file') {
|
||||
$path = get_upload_path_by_type('expense') . $expense_id . '/';
|
||||
$CI = & get_instance();
|
||||
if (isset($_FILES[$index_name]['name']) && ($_FILES[$index_name]['name'] != '' || is_array($_FILES[$index_name]['name']) && count($_FILES[$index_name]['name']) > 0)) {
|
||||
if (!is_array($_FILES[$index_name]['name'])) {
|
||||
$_FILES[$index_name]['name'] = [$_FILES[$index_name]['name']];
|
||||
$_FILES[$index_name]['type'] = [$_FILES[$index_name]['type']];
|
||||
$_FILES[$index_name]['tmp_name'] = [$_FILES[$index_name]['tmp_name']];
|
||||
$_FILES[$index_name]['error'] = [$_FILES[$index_name]['error']];
|
||||
$_FILES[$index_name]['size'] = [$_FILES[$index_name]['size']];
|
||||
}
|
||||
_file_attachments_index_fix($index_name);
|
||||
for ($i = 0; $i < count($_FILES[$index_name]['name']); $i++) {
|
||||
// Get the temp file path
|
||||
$tmpFilePath = $_FILES[$index_name]['tmp_name'][$i];
|
||||
// Make sure we have a filepath
|
||||
if (!empty($tmpFilePath) && $tmpFilePath != '') {
|
||||
if (_perfex_upload_error($_FILES[$index_name]['error'][$i]) || !_upload_extension_allowed($_FILES[$index_name]['name'][$i])) {
|
||||
continue;
|
||||
}
|
||||
_maybe_create_upload_path($path);
|
||||
$filename = unique_filename($path, $_FILES[$index_name]['name'][$i]);
|
||||
$newFilePath = $path . $filename;
|
||||
// Upload the file into the temp dir
|
||||
if (move_uploaded_file($tmpFilePath, $newFilePath)) {
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('expenses_model');
|
||||
$data = [];
|
||||
$data[] = ['file_name' => $filename, 'filetype' => $_FILES[$index_name]['type'][$i], ];
|
||||
$this->add_attachment_to_database($expense_id, $data, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function add_attachment_to_database($expense_id, $attachment, $external = false, $form_activity = false) {
|
||||
$this->misc_model->add_attachment_to_database($expense_id, 'expense', $attachment, $external);
|
||||
|
||||
// No notification when attachment is imported from web to lead form
|
||||
if ($form_activity == false) {
|
||||
$this->load->model('expenses_model');
|
||||
$expense = $this->expenses_model->get($expense_id);
|
||||
$not_user_ids = [];
|
||||
if ($expense->addedfrom != get_staff_user_id()) {
|
||||
array_push($not_user_ids, $expense->addedfrom);
|
||||
}
|
||||
$notifiedUsers = [];
|
||||
foreach ($not_user_ids as $uid) {
|
||||
$notified = add_notification([
|
||||
'description' => 'not_expense_added_attachment',
|
||||
'touserid' => $uid,
|
||||
'link' => '#expenseid=' . $expense_id,
|
||||
'additional_data' => serialize([
|
||||
$expense->expense_name,
|
||||
]),
|
||||
]);
|
||||
if ($notified) {
|
||||
array_push($notifiedUsers, $uid);
|
||||
}
|
||||
}
|
||||
pusher_trigger_notification($notifiedUsers);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* End of file Expenses.php */
|
||||
767
api/controllers/Invoices.php
Normal file
767
api/controllers/Invoices.php
Normal file
@@ -0,0 +1,767 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Invoices extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/invoices/:id Request invoice information
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName GetInvoice
|
||||
* @apiGroup Invoices
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiParam {Number} id Contact unique ID
|
||||
*
|
||||
* @apiSuccess {Object} Invoice Invoice information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "2",
|
||||
* "sent": "0",
|
||||
* "datesend": null,
|
||||
* "clientid": "1",
|
||||
* "deleted_customer_name": null,
|
||||
* "number": "2",
|
||||
* "prefix": "INV-",
|
||||
* "number_format": "1",
|
||||
* "datecreated": "2020-05-26 19:53:11",
|
||||
* "date": "2020-05-26",
|
||||
* "duedate": "2020-06-25",
|
||||
* "currency": "1",
|
||||
* "subtotal": "5.00",
|
||||
* "total_tax": "0.00",
|
||||
* "total": "5.00",
|
||||
* "adjustment": "0.00",
|
||||
* "addedfrom": "0",
|
||||
* "hash": "7bfac86da004df5364407574d4d1dbf2",
|
||||
* "status": "1",
|
||||
* "clientnote": null,
|
||||
* "adminnote": null,
|
||||
* "last_overdue_reminder": null,
|
||||
* "cancel_overdue_reminders": "0",
|
||||
* "allowed_payment_modes": "['1']",
|
||||
* "token": null,
|
||||
* "discount_percent": "0.00",
|
||||
* "discount_total": "0.00",
|
||||
* "discount_type": "",
|
||||
* "recurring": "0",
|
||||
* "recurring_type": null,
|
||||
* "custom_recurring": "0",
|
||||
* "cycles": "0",
|
||||
* "total_cycles": "0",
|
||||
* "is_recurring_from": null,
|
||||
* "last_recurring_date": null,
|
||||
* "terms": null,
|
||||
* "sale_agent": "0",
|
||||
* "billing_street": "",
|
||||
* "billing_city": "",
|
||||
* "billing_state": "",
|
||||
* "billing_zip": "",
|
||||
* "billing_country": null,
|
||||
* "shipping_street": null,
|
||||
* "shipping_city": null,
|
||||
* "shipping_state": null,
|
||||
* "shipping_zip": null,
|
||||
* "shipping_country": null,
|
||||
* "include_shipping": "0",
|
||||
* "show_shipping_on_invoice": "1",
|
||||
* "show_quantity_as": "1",
|
||||
* "project_id": "0",
|
||||
* "subscription_id": "0",
|
||||
* "symbol": "$",
|
||||
* "name": "USD",
|
||||
* "decimal_separator": ".",
|
||||
* "thousand_separator": ",",
|
||||
* "placement": "before",
|
||||
* "isdefault": "1",
|
||||
* "currencyid": "1",
|
||||
* "currency_name": "USD",
|
||||
* "total_left_to_pay": "5.00",
|
||||
* "items": [
|
||||
* {
|
||||
* "id": "2",
|
||||
* "rel_id": "2",
|
||||
* "rel_type": "invoice",
|
||||
* "description": "12MP Dual Camera with cover",
|
||||
* "long_description": "The JBL Cinema SB110 is a hassle-free soundbar",
|
||||
* "qty": "1.00",
|
||||
* "rate": "5.00",
|
||||
* "unit": "",
|
||||
* "item_order": "1"
|
||||
* }
|
||||
* ],
|
||||
* "attachments": [],
|
||||
* "visible_attachments_to_customer_found": false,
|
||||
* "client": {
|
||||
* "userid": "1",
|
||||
* "company": "trueline",
|
||||
* "vat": "",
|
||||
* "phonenumber": "",
|
||||
* "country": "0",
|
||||
* "city": "",
|
||||
* "zip": "",
|
||||
* "state": "",
|
||||
* "address": "",
|
||||
* "website": "",
|
||||
* "datecreated": "2020-05-19 20:07:49",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "billing_street": "",
|
||||
* "billing_city": "",
|
||||
* "billing_state": "",
|
||||
* "billing_zip": "",
|
||||
* "billing_country": "0",
|
||||
* "shipping_street": "",
|
||||
* "shipping_city": "",
|
||||
* "shipping_state": "",
|
||||
* "shipping_zip": "",
|
||||
* "shipping_country": "0",
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "english",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "addedfrom": "1"
|
||||
* },
|
||||
* "payments": [],
|
||||
* "scheduled_email": null
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// Fetch invoices without specifying order
|
||||
$data = $this->Api_model->get_table('invoices', $id);
|
||||
|
||||
// Check if the data store contains any invoices
|
||||
if ($data) {
|
||||
// Sort $data array by 'id' in ascending order
|
||||
usort($data, function($a, $b) {
|
||||
return $a['id'] - $b['id'];
|
||||
});
|
||||
|
||||
// Optionally, apply additional custom data formatting if needed
|
||||
$data = $this->Api_model->get_api_custom_data($data, "invoice", $id);
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit with a not found message
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} api/invoices/search/:keysearch Search invoice information
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName GetInvoiceSearch
|
||||
* @apiGroup Invoices
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Invoice Information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "19",
|
||||
* "sent": "0",
|
||||
* "datesend": null,
|
||||
* "clientid": "3",
|
||||
* "deleted_customer_name": null,
|
||||
* "number": "19",
|
||||
* "prefix": "INV-",
|
||||
* "number_format": "1",
|
||||
* "datecreated": "2020-08-18 21:19:51",
|
||||
* "date": "2020-07-04",
|
||||
* "duedate": "2020-08-03",
|
||||
* "currency": "1",
|
||||
* "subtotal": "20.00",
|
||||
* "total_tax": "1.80",
|
||||
* "total": "21.80",
|
||||
* "adjustment": "0.00",
|
||||
* "addedfrom": "1",
|
||||
* "hash": "809c0e4c9efba2a3bedfdb5871dc6240",
|
||||
* "status": "2",
|
||||
* "clientnote": "",
|
||||
* "adminnote": "",
|
||||
* "last_overdue_reminder": null,
|
||||
* "cancel_overdue_reminders": "0",
|
||||
* "allowed_payment_modes": "['1']",
|
||||
* "token": null,
|
||||
* "discount_percent": "0.00",
|
||||
* "discount_total": "0.00",
|
||||
* "discount_type": "",
|
||||
* "recurring": "0",
|
||||
* "recurring_type": null,
|
||||
* "custom_recurring": "0",
|
||||
* "cycles": "0",
|
||||
* "total_cycles": "0",
|
||||
* "is_recurring_from": null,
|
||||
* "last_recurring_date": null,
|
||||
* "terms": "",
|
||||
* "sale_agent": "0",
|
||||
* "billing_street": "",
|
||||
* "billing_city": "",
|
||||
* "billing_state": "",
|
||||
* "billing_zip": "",
|
||||
* "billing_country": "0",
|
||||
* "shipping_street": "",
|
||||
* "shipping_city": "",
|
||||
* "shipping_state": "",
|
||||
* "shipping_zip": "",
|
||||
* "shipping_country": "0",
|
||||
* "include_shipping": "0",
|
||||
* "show_shipping_on_invoice": "1",
|
||||
* "show_quantity_as": "1",
|
||||
* "project_id": "0",
|
||||
* "subscription_id": "0",
|
||||
* "userid": "3",
|
||||
* "company": "xyz",
|
||||
* "vat": "",
|
||||
* "phonenumber": "",
|
||||
* "country": "0",
|
||||
* "city": "",
|
||||
* "zip": "",
|
||||
* "state": "",
|
||||
* "address": "",
|
||||
* "website": "",
|
||||
* "active": "1",
|
||||
* "leadid": null,
|
||||
* "longitude": null,
|
||||
* "latitude": null,
|
||||
* "default_language": "",
|
||||
* "default_currency": "0",
|
||||
* "show_primary_contact": "0",
|
||||
* "stripe_id": null,
|
||||
* "registration_confirmed": "1",
|
||||
* "invoiceid": "19"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No Data Were Found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
$data = $this->Api_model->search('invoices', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "invoice");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/invoices Add New invoice
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName PostInvoice
|
||||
* @apiGroup Invoices
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} clientid Mandatory. Customer id
|
||||
* @apiParam {Number} number Mandatory. Invoice Number
|
||||
* @apiParam {Date} date Mandatory. Invoice Date
|
||||
* @apiParam {Number} currency Mandatory. currency field
|
||||
* @apiParam {Array} newitems Mandatory. New Items to be added
|
||||
* @apiParam {Decimal} subtotal Mandatory. calculation based on item Qty, Rate and Tax
|
||||
* @apiParam {Decimal} total Mandatory. calculation based on subtotal, Discount and Adjustment
|
||||
* @apiParam {String} billing_street Mandatory. Street Address
|
||||
* @apiParam {Array} allowed_payment_modes Mandatory. Payment modes
|
||||
* @apiParam {String} [billing_city] Optional. City Name for billing
|
||||
* @apiParam {String} [billing_state] Optional. Name of state for billing
|
||||
* @apiParam {Number} [billing_zip] Optional. Zip code
|
||||
* @apiParam {Number} [billing_country] Optional. Country code
|
||||
* @apiParam {boolean} [include_shipping="no"] Optional. set yes if you want add Shipping Address
|
||||
* @apiParam {boolean} [show_shipping_on_invoice] Optional. Shows shipping details in invoice.
|
||||
* @apiParam {String} [shipping_street] Optional. Address of shipping
|
||||
* @apiParam {String} [shipping_city] Optional. City name for shipping
|
||||
* @apiParam {String} [shipping_state] Optional. Name of state for shipping
|
||||
* @apiParam {Number} [shipping_zip] Optional. Zip code for shipping
|
||||
* @apiParam {Number} [shipping_country] Optional. Country code
|
||||
* @apiParam {Date} [duedate] Optional. Due date for Invoice
|
||||
* @apiParam {boolean} [cancel_overdue_reminders] Optional. Prevent sending overdue remainders for invoice
|
||||
* @apiParam {String} [tags] Optional. TAGS comma separated
|
||||
* @apiParam {Number} [sale_agent] Optional. Sale Agent name
|
||||
* @apiParam {String} [recurring] Optional. recurring 1 to 12 or custom
|
||||
* @apiParam {String} [discount_type] Optional. before_tax / after_tax discount type
|
||||
* @apiParam {Number} [repeat_every_custom] Optional. if recurring is custom set number gap
|
||||
* @apiParam {String} [repeat_type_custom] Optional. if recurring is custom set gap option day/week/month/year
|
||||
* @apiParam {Number} [cycles] Optional. number of cycles 0 for infinite
|
||||
* @apiParam {String} [adminnote] Optional. notes by admin
|
||||
* @apiParam {Array} [removed_items] Optional. Items to be removed
|
||||
* @apiParam {String} [clientnote] Optional. client notes
|
||||
* @apiParam {String} [terms] Optional. Terms
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* [
|
||||
* "clientid"=>1,
|
||||
* "number"=>"00001",
|
||||
* "date"=>"2020-09-07",
|
||||
* "currency"=>1,
|
||||
* "newitems[0][description]"=>"item 1 description",
|
||||
* "newitems[0][long_description]"=>"item 1 long description",
|
||||
* "newitems[0][qty]"=>1,
|
||||
* "newitems[0][rate]"=>100,
|
||||
* "newitems[0][order]"=>1,
|
||||
* "newitems[0][taxname][]"=>CGST|9.00,
|
||||
* "newitems[0][taxname][]"=>SGST|9.00,
|
||||
* "newitems[0][unit]"=>"",
|
||||
* "newitems[1][description]"=>"item 2 description",
|
||||
* "newitems[1][long_description]"=>"item 2 long description",
|
||||
* "newitems[1][qty]"=>1,
|
||||
* "newitems[1][rate]"=>100,
|
||||
* "newitems[1][order]"=>1,
|
||||
* "newitems[1][taxname][]"=>CGST|9.00,
|
||||
* "newitems[1][taxname][]"=>SGST|9.00,
|
||||
* "newitems[1][unit]"=>"",
|
||||
* "subtotal"=>236.00,
|
||||
* "total"=>236.00,
|
||||
* "billing_street"=>"billing address",
|
||||
* "allowed_payment_modes[0]"=>1,
|
||||
* "allowed_payment_modes[1]"=>2,
|
||||
* ....
|
||||
* ]
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Invoice Added Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Invoice Added Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Invoice add fail
|
||||
* @apiError {String} newitems[] The Items field is required
|
||||
* @apiError {String} number The Invoice number is already in use
|
||||
* @apiError {String} allowed_payment_modes[] The Allow Payment Mode field is required
|
||||
* @apiError {String} billing_street The Billing Street field is required
|
||||
* @apiError {String} subtotal The Sub Total field is required
|
||||
* @apiError {String} total The Total field is required
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Invoice Add Fail"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "number":"The Invoice number is already in use"
|
||||
* },
|
||||
* "message": "The Invoice number is already in use"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "allowed_payment_modes[]": "The Allow Payment Mode field is required."
|
||||
* },
|
||||
* "message": "<p>The Allow Payment Mode field is required.</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "billing_street": "The Billing Street field is required"
|
||||
* },
|
||||
* "message": "<p>The Billing Street field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "newitems[]": "The Items field is required"
|
||||
* },
|
||||
* "message": "<p>The Items field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "subtotal": "The Sub Total field is required"
|
||||
* },
|
||||
* "message": "<p>The Sub Total field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "total": "The Total field is required"
|
||||
* },
|
||||
* "message": "<p>The Total field is required</p>\n"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
error_reporting(0);
|
||||
$data = $this->input->post();
|
||||
$this->form_validation->set_rules('clientid', 'Customer', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('number', 'Invoice number', 'trim|required|max_length[255]|callback_validate_invoice_number[0]');
|
||||
$this->form_validation->set_rules('date', 'Invoice date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('newitems[]', 'Items', 'required');
|
||||
$this->form_validation->set_rules('allowed_payment_modes[]', 'Allow Payment Mode', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('billing_street', 'Billing Street', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('subtotal', 'Sub Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('total', 'Total', 'trim|required|decimal|greater_than[0]');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('invoices_model');
|
||||
$id = $this->invoices_model->add($data);
|
||||
if ($id > 0 && !empty($id)) {
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Invoice Added Successfully',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Invoice Add Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/invoices/:id Delete invoice
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName DeleteInvoice
|
||||
* @apiGroup Invoices
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Invoice Deleted Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Invoice Deleted Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Invoice Delete Fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Invoice Delete Fail"
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Invoice ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('invoices_model');
|
||||
$is_exist = $this->invoices_model->get($id);
|
||||
if (is_object($is_exist)) {
|
||||
$output = $this->invoices_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Invoice Deleted Successfully');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Invoice Delete Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Invoice ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/invoices/:id Update invoice
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName PutInvoice
|
||||
* @apiGroup Invoices
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} clientid Mandatory Customer id.
|
||||
*
|
||||
* @apiParam {Number} clientid Mandatory. Customer id
|
||||
* @apiParam {Number} number Mandatory. Invoice Number
|
||||
* @apiParam {Date} date Mandatory. Invoice Date
|
||||
* @apiParam {Number} currency Mandatory. currency field
|
||||
* @apiParam {Array} newitems Mandatory. New Items to be added
|
||||
* @apiParam {Decimal} subtotal Mandatory. calculation based on item Qty, Rate and Tax
|
||||
* @apiParam {Decimal} total Mandatory. calculation based on subtotal, Discount and Adjustment
|
||||
* @apiParam {String} billing_street Mandatory. Street Address
|
||||
* @apiParam {Array} allowed_payment_modes Mandatory. Payment modes
|
||||
* @apiParam {String} [billing_city] Optional. City Name for billing
|
||||
* @apiParam {String} [billing_state] Optional. Name of state for billing
|
||||
* @apiParam {Number} [billing_zip] Optional. Zip code
|
||||
* @apiParam {Number} [billing_country] Optional. Country code
|
||||
* @apiParam {boolean} [include_shipping="no"] Optional. set yes if you want add Shipping Address
|
||||
* @apiParam {boolean} [show_shipping_on_invoice] Optional. Shows shipping details in invoice.
|
||||
* @apiParam {String} [shipping_street] Optional. Address of shipping
|
||||
* @apiParam {String} [shipping_city] Optional. City name for shipping
|
||||
* @apiParam {String} [shipping_state] Optional. Name of state for shipping
|
||||
* @apiParam {Number} [shipping_zip] Optional. Zip code for shipping
|
||||
* @apiParam {Number} [shipping_country] Optional. Country code
|
||||
* @apiParam {Date} [duedate] Optional. Due date for Invoice
|
||||
* @apiParam {boolean} [cancel_overdue_reminders] Optional. Prevent sending overdue remainders for invoice
|
||||
* @apiParam {String} [tags] Optional. TAGS comma separated
|
||||
* @apiParam {Number} [sale_agent] Optional. Sale Agent name
|
||||
* @apiParam {String} [recurring] Optional. recurring 1 to 12 or custom
|
||||
* @apiParam {String} [discount_type] Optional. before_tax / after_tax discount type
|
||||
* @apiParam {Number} [repeat_every_custom] Optional. if recurring is custom set number gap
|
||||
* @apiParam {String} [repeat_type_custom] Optional. if recurring is custom set gap option day/week/month/year
|
||||
* @apiParam {Number} [cycles] Optional. number of cycles 0 for infinite
|
||||
* @apiParam {String} [adminnote] Optional. notes by admin
|
||||
* @apiParam {Array} [items] Optional. Existing items with Id
|
||||
* @apiParam {Array} [removed_items] Optional. Items to be removed
|
||||
* @apiParam {String} [clientnote] Optional. client notes
|
||||
* @apiParam {String} [terms] Optional. Terms
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "clientid": "1",
|
||||
* "billing_street": "billing address",
|
||||
* "billing_city": "billing city name",
|
||||
* "billing_state": "billing state name",
|
||||
* "billing_zip": "billing zip code",
|
||||
* "billing_country": "",
|
||||
* "include_shipping": "on",
|
||||
* "show_shipping_on_invoice": "on",
|
||||
* "shipping_street": "shipping address",
|
||||
* "shipping_city": "city name",
|
||||
* "shipping_state": "state name",
|
||||
* "shipping_zip": "zip code",
|
||||
* "shipping_country": "",
|
||||
* "number": "000001",
|
||||
* "date": "2020-08-28",
|
||||
* "duedate": "2020-09-27",
|
||||
* "cancel_overdue_reminders": "on",
|
||||
* "tags": "TAG 1,TAG 2",
|
||||
* "allowed_payment_modes": [
|
||||
* "1","2"
|
||||
* ],
|
||||
* "currency": "1",
|
||||
* "sale_agent": "1",
|
||||
* "recurring": "custom",
|
||||
* "discount_type": "before_tax",
|
||||
* "repeat_every_custom": "7",
|
||||
* "repeat_type_custom": "day",
|
||||
* "cycles": "0",
|
||||
* "adminnote": "TEST",
|
||||
* "show_quantity_as": "1",
|
||||
* "items": {
|
||||
* "1": {
|
||||
* "itemid": "1",
|
||||
* "order": "1",
|
||||
* "description": "item description",
|
||||
* "long_description": "item long description",
|
||||
* "qty": "1",
|
||||
* "unit": "1",
|
||||
* "rate": "10.00"
|
||||
* }
|
||||
* },
|
||||
* "removed_items": [
|
||||
* "2",
|
||||
* "3"
|
||||
* ],
|
||||
* "newitems": {
|
||||
* "2": {
|
||||
* "order": "2",
|
||||
* "description": "item 2 description",
|
||||
* "long_description": "item 2 logn description",
|
||||
* "qty": "1",
|
||||
* "unit": "",
|
||||
* "rate": "100.00"
|
||||
* }
|
||||
* },
|
||||
* "subtotal": "10.00",
|
||||
* "discount_percent": "10",
|
||||
* "discount_total": "1.00",
|
||||
* "adjustment": "1",
|
||||
* "total": "10.00",
|
||||
* "clientnote": "client note",
|
||||
* "terms": "terms"
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Invoice Updated Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Invoice Update Fail"
|
||||
* }
|
||||
*
|
||||
* @apiError {String} number The Invoice number is already in use
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 409 Conflict
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": {
|
||||
* "number":"The Invoice number is already in use"
|
||||
* },
|
||||
* "message": "The Invoice number is already in use"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_put($id = '') {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Invoice ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->form_validation->set_rules('number', 'Invoice number', 'trim|required|max_length[255]|callback_validate_invoice_number[' . $id . ']');
|
||||
$this->form_validation->set_rules('date', 'Invoice date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('items[]', 'Items', 'required');
|
||||
$this->form_validation->set_rules('allowed_payment_modes[]', 'Allow Payment Mode', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('billing_street', 'Billing Street', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('subtotal', 'Sub Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('total', 'Total', 'trim|required|decimal|greater_than[0]');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
} else {
|
||||
$this->load->model('invoices_model');
|
||||
$is_exist = $this->invoices_model->get($id);
|
||||
if (!is_object($is_exist)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invoice ID Doesn\'t Not Exist.');
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
}
|
||||
if (is_object($is_exist)) {
|
||||
$data = $this->input->post();
|
||||
$data['isedit'] = "";
|
||||
$success = $this->invoices_model->update($data, $id);
|
||||
if ($success == true) {
|
||||
$message = array('status' => TRUE, 'message' => "Invoice Updated Successfully",);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Invoice Update Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Invoice ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function validate_invoice_number($number, $invoiceid) {
|
||||
$isedit = 'false';
|
||||
if (!empty($invoiceid)) {
|
||||
$isedit = 'true';
|
||||
}
|
||||
$this->form_validation->set_message('validate_invoice_number', 'The {field} is already in use');
|
||||
$original_number = null;
|
||||
$date = $this->input->post('date');
|
||||
if (!empty($invoiceid)) {
|
||||
$data = $this->Api_model->get_table('invoices', $invoiceid);
|
||||
$original_number = $data->number;
|
||||
if (empty($date)) {
|
||||
$date = $data->date;
|
||||
}
|
||||
}
|
||||
$number = trim($number);
|
||||
$number = ltrim($number, '0');
|
||||
if ($isedit == 'true') {
|
||||
if ($number == $original_number) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (total_rows(db_prefix() . 'invoices', ['YEAR(date)' => date('Y', strtotime(to_sql_date($date))), 'number' => $number, ]) > 0) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
124
api/controllers/Items.php
Normal file
124
api/controllers/Items.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Items extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/items/:id Request Invoice Item's information
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName GetItem
|
||||
* @apiGroup Items
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiSuccess {Object} Item item information.
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "itemid": "1",
|
||||
* "rate": "100.00",
|
||||
* "taxrate": "5.00",
|
||||
* "taxid": "1",
|
||||
* "taxname": "PAYPAL",
|
||||
* "taxrate_2": "9.00",
|
||||
* "taxid_2": "2",
|
||||
* "taxname_2": "CGST",
|
||||
* "description": "JBL Soundbar",
|
||||
* "long_description": "The JBL Cinema SB110 is a hassle-free soundbar",
|
||||
* "group_id": "0",
|
||||
* "group_name": null,
|
||||
* "unit": ""
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('invoice_items', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "items", $id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/items/search/:keysearch Search Invoice Item's information
|
||||
* @apiVersion 0.1.0
|
||||
* @apiName GetItemSearch
|
||||
* @apiGroup Items
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords
|
||||
*
|
||||
* @apiSuccess {Object} Item Item Information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "rate": "100.00",
|
||||
* "id": "1",
|
||||
* "name": "(100.00) JBL Soundbar",
|
||||
* "subtext": "The JBL Cinema SB110 is a hassle-free soundbar..."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status
|
||||
* @apiError {String} message No data were found
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
$data = $this->Api_model->search('invoice_items', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "items");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
178
api/controllers/Key.php
Normal file
178
api/controllers/Key.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* Keys Controller
|
||||
* This is a basic Key Management REST controller to make and delete keys
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Key extends REST_Controller {
|
||||
protected $methods = [
|
||||
'index_put' => ['level' => 10, 'limit' => 10],
|
||||
'index_delete' => ['level' => 10],
|
||||
'level_post' => ['level' => 10],
|
||||
'regenerate_post' => ['level' => 10],
|
||||
];
|
||||
|
||||
/**
|
||||
* Insert a key into the database
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function index_put() {
|
||||
// Build a new key
|
||||
$key = $this->_generate_key();
|
||||
// If no key level provided, provide a generic key
|
||||
$level = $this->put('level') ? $this->put('level') : 1;
|
||||
$ignore_limits = ctype_digit($this->put('ignore_limits')) ? (int)$this->put('ignore_limits') : 1;
|
||||
// Insert the new key
|
||||
if ($this->_insert_key($key, ['level' => $level, 'ignore_limits' => $ignore_limits])) {
|
||||
$this->response(['status' => TRUE, 'key' => $key], REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code
|
||||
|
||||
} else {
|
||||
$this->response(['status' => FALSE, 'message' => 'Could not save the key'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a key from the database to stop it working
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function index_delete() {
|
||||
$key = $this->delete('key');
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key)) {
|
||||
// It doesn't appear the key exists
|
||||
$this->response(['status' => FALSE, 'message' => 'Invalid API key'], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
|
||||
}
|
||||
// Destroy it
|
||||
$this->_delete_key($key);
|
||||
// Respond that the key was destroyed
|
||||
$this->response(['status' => TRUE, 'message' => 'API key was deleted'], REST_Controller::HTTP_NO_CONTENT); // NO_CONTENT (204) being the HTTP response code
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the level
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function level_post() {
|
||||
$key = $this->post('key');
|
||||
$new_level = $this->post('level');
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key)) {
|
||||
// It doesn't appear the key exists
|
||||
$this->response(['status' => FALSE, 'message' => 'Invalid API key'], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
|
||||
}
|
||||
// Update the key level
|
||||
if ($this->_update_key($key, ['level' => $new_level])) {
|
||||
$this->response(['status' => TRUE, 'message' => 'API key was updated'], REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
$this->response(['status' => FALSE, 'message' => 'Could not update the key level'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend a key
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function suspend_post() {
|
||||
$key = $this->post('key');
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key)) {
|
||||
// It doesn't appear the key exists
|
||||
$this->response(['status' => FALSE, 'message' => 'Invalid API key'], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
|
||||
}
|
||||
// Update the key level
|
||||
if ($this->_update_key($key, ['level' => 0])) {
|
||||
$this->response(['status' => TRUE, 'message' => 'Key was suspended'], REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
$this->response(['status' => FALSE, 'message' => 'Could not suspend the user'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate a key
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function regenerate_post() {
|
||||
$old_key = $this->post('key');
|
||||
$key_details = $this->_get_key($old_key);
|
||||
// Does this key exist?
|
||||
if (!$key_details) {
|
||||
// It doesn't appear the key exists
|
||||
$this->response(['status' => FALSE, 'message' => 'Invalid API key'], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
|
||||
}
|
||||
// Build a new key
|
||||
$new_key = $this->_generate_key();
|
||||
// Insert the new key
|
||||
if ($this->_insert_key($new_key, ['level' => $key_details->level, 'ignore_limits' => $key_details->ignore_limits])) {
|
||||
// Suspend old key
|
||||
$this->_update_key($old_key, ['level' => 0]);
|
||||
$this->response(['status' => TRUE, 'key' => $new_key], REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code
|
||||
} else {
|
||||
$this->response(['status' => FALSE, 'message' => 'Could not save the key'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper Methods */
|
||||
private function _generate_key() {
|
||||
do {
|
||||
// Generate a random salt
|
||||
$salt = base_convert(bin2hex($this->security->get_random_bytes(64)), 16, 36);
|
||||
// If an error occurred, then fall back to the previous method
|
||||
if ($salt === FALSE) {
|
||||
$salt = hash('sha256', time() . mt_rand());
|
||||
}
|
||||
$new_key = substr($salt, 0, config_item('rest_key_length'));
|
||||
} while ($this->_key_exists($new_key));
|
||||
return $new_key;
|
||||
}
|
||||
|
||||
/* Private Data Methods */
|
||||
private function _get_key($key) {
|
||||
return $this->rest->db->where(config_item('rest_key_column'), $key)->get(config_item('rest_keys_table'))->row();
|
||||
}
|
||||
|
||||
private function _key_exists($key) {
|
||||
return $this->rest->db->where(config_item('rest_key_column'), $key)->count_all_results(config_item('rest_keys_table')) > 0;
|
||||
}
|
||||
|
||||
private function _insert_key($key, $data) {
|
||||
$data[config_item('rest_key_column') ] = $key;
|
||||
$data['date_created'] = function_exists('now') ? now() : time();
|
||||
return $this->rest->db->set($data)->insert(config_item('rest_keys_table'));
|
||||
}
|
||||
|
||||
private function _update_key($key, $data) {
|
||||
return $this->rest->db->where(config_item('rest_key_column'), $key)->update(config_item('rest_keys_table'), $data);
|
||||
}
|
||||
|
||||
private function _delete_key($key) {
|
||||
return $this->rest->db->where(config_item('rest_key_column'), $key)->delete(config_item('rest_keys_table'));
|
||||
}
|
||||
}
|
||||
502
api/controllers/Leads.php
Normal file
502
api/controllers/Leads.php
Normal file
@@ -0,0 +1,502 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
*/
|
||||
class Leads extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
$this->load->model('Api_model');
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/leads/ Request all Leads
|
||||
* @apiName GetLeads
|
||||
* @apiGroup Leads
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Object} Lead information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "17",
|
||||
* "hash": "c6e938f8b7a40b1bcfd98dc04f6eeee0-60d9c039da373a685fc0f74d4bfae631",
|
||||
* "name": "Lead name",
|
||||
* "contact": "",
|
||||
* "title": "",
|
||||
* "company": "Themesic Interactive",
|
||||
* "description": "",
|
||||
* "country": "243",
|
||||
* "zip": null,
|
||||
* "city": "London",
|
||||
* "zip": "WC13KJ",
|
||||
* "state": "London",
|
||||
* "address": "1a The Alexander Suite Silk Point",
|
||||
* "assigned": "5",
|
||||
* "dateadded": "2019-07-18 08:59:28",
|
||||
* "from_form_id": "0",
|
||||
* "status": "0",
|
||||
* "source": "4",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {get} api/leads/:id Request Lead information
|
||||
* @apiName GetLead
|
||||
* @apiGroup Leads
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Lead unique ID.
|
||||
*
|
||||
* @apiSuccess {Object} Lead information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "17",
|
||||
* "hash": "c6e938f8b7a40b1bcfd98dc04f6eeee0-60d9c039da373a685fc0f74d4bfae631",
|
||||
* "name": "Lead name",
|
||||
* "contact": "",
|
||||
* "title": "",
|
||||
* "company": "Themesic Interactive",
|
||||
* "description": "",
|
||||
* "country": "243",
|
||||
* "zip": null,
|
||||
* "city": "London",
|
||||
* "zip": "WC13KJ",
|
||||
* "state": "London",
|
||||
* "address": "1a The Alexander Suite Silk Point",
|
||||
* "assigned": "5",
|
||||
* "dateadded": "2019-07-18 08:59:28",
|
||||
* "from_form_id": "0",
|
||||
* "status": "0",
|
||||
* "source": "4",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('leads', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "leads", $id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/leads/search/:keysearch Search Lead Information
|
||||
* @apiName GetLeadSearch
|
||||
* @apiGroup Leads
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Lead information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "17",
|
||||
* "hash": "c6e938f8b7a40b1bcfd98dc04f6eeee0-60d9c039da373a685fc0f74d4bfae631",
|
||||
* "name": "Lead name",
|
||||
* "contact": "",
|
||||
* "title": "",
|
||||
* "company": "Themesic Interactive",
|
||||
* "description": "",
|
||||
* "country": "243",
|
||||
* "zip": null,
|
||||
* "city": "London",
|
||||
* "zip": "WC13KJ",
|
||||
* "state": "London",
|
||||
* "address": "1a The Alexander Suite Silk Point",
|
||||
* "assigned": "5",
|
||||
* "dateadded": "2019-07-18 08:59:28",
|
||||
* "from_form_id": "0",
|
||||
* "status": "0",
|
||||
* "source": "4",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
$data = $this->Api_model->search('lead', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "leads");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/leads Add New Lead
|
||||
* @apiName PostLead
|
||||
* @apiGroup Leads
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} source Mandatory Lead source.
|
||||
* @apiParam {String} status Mandatory Lead Status.
|
||||
* @apiParam {String} name Mandatory Lead Name.
|
||||
* @apiParam {String} assigned Mandatory Lead assigned.
|
||||
* @apiParam {String} [client_id] Optional Lead From Customer.
|
||||
* @apiParam {String} [tags] Optional Lead tags.
|
||||
* @apiParam {String} [contact] Optional Lead contact.
|
||||
* @apiParam {String} [title] Optional Position.
|
||||
* @apiParam {String} [email] Optional Lead Email Address.
|
||||
* @apiParam {String} [website] Optional Lead Website.
|
||||
* @apiParam {String} [phonenumber] Optional Lead Phone.
|
||||
* @apiParam {String} [company] Optional Lead company.
|
||||
* @apiParam {String} [address] Optional Lead address.
|
||||
* @apiParam {String} [city] Optional Lead City.
|
||||
* @apiParam {String} [zip] Optional Zip code.
|
||||
* @apiParam {String} [state] Optional Lead state.
|
||||
* @apiParam {String} [country] Optional Lead Country.
|
||||
* @apiParam {String} [default_language] Optional Lead Default Language.
|
||||
* @apiParam {String} [description] Optional Lead description.
|
||||
* @apiParam {String} [custom_contact_date] Optional Lead From Customer.
|
||||
* @apiParam {String} [contacted_today] Optional Lead Contacted Today.
|
||||
* @apiParam {String} [is_public] Optional Lead google sheet id.
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* array (size=20)
|
||||
* 'status' => string '2' (length=1)
|
||||
* 'source' => string '6' (length=1)
|
||||
* 'assigned' => string '1' (length=1)
|
||||
* 'client_id' => string '5' (length=1)
|
||||
* 'tags' => string '' (length=0)
|
||||
* 'name' => string 'Lead Name' (length=9)
|
||||
* 'contact' => string 'Contact A' (length=9)
|
||||
* 'title' => string 'Position A' (length=10)
|
||||
* 'email' => string 'AAA@gmail.com' (length=13)
|
||||
* 'website' => string '' (length=0)
|
||||
* 'phonenumber' => string '123456789' (length=9)
|
||||
* 'company' => string 'Themesic Interactive' (length=20)
|
||||
* 'address' => string '710-712 Cách Mạng Tháng Tám, P. 5, Q. Tân Bình' (length=33)
|
||||
* 'city' => string 'London' (length=6)
|
||||
* 'zip' => string 'WC13KJ' (length=6)
|
||||
* 'state' => string '' (length=0)
|
||||
* 'default_language' => string 'english' (length=10)
|
||||
* 'description' => string 'Description' (length=11)
|
||||
* 'custom_contact_date' => string '' (length=0)
|
||||
* 'is_public' => string 'on' (length=2)
|
||||
* 'contacted_today' => string 'on' (length=2)
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Lead add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Lead add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Lead add fail."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
// form validation
|
||||
$this->form_validation->set_rules('name', 'Lead Name', 'trim|required|max_length[600]', array('is_unique' => 'This %s already exists please enter another Lead Name'));
|
||||
$this->form_validation->set_rules('source', 'Source', 'trim|required', array('is_unique' => 'This %s already exists please enter another Lead source'));
|
||||
$this->form_validation->set_rules('status', 'Status', 'trim|required', array('is_unique' => 'This %s already exists please enter another Status'));
|
||||
$this->form_validation->set_rules('zip', 'Zip Core', 'trim', array('is_unique' => 'This %s already exists please enter another Zip code'));
|
||||
$this->form_validation->set_rules('assigned', 'Assigned', 'trim|required', array('is_unique' => 'This %s already exists please enter another Assigned'));
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
// form validation error
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$insert_data = ['name' => $this->input->post('name', TRUE), 'source' => $this->input->post('source', TRUE), 'status' => $this->input->post('status', TRUE), 'assigned' => $this->input->post('assigned', TRUE), 'tags' => $this->Api_model->value($this->input->post('tags', TRUE)), 'title' => $this->Api_model->value($this->input->post('title', TRUE)), 'email' => $this->Api_model->value($this->input->post('email', TRUE)), 'website' => $this->Api_model->value($this->input->post('website', TRUE)), 'phonenumber' => $this->Api_model->value($this->input->post('phonenumber', TRUE)), 'company' => $this->Api_model->value($this->input->post('company', TRUE)), 'address' => $this->Api_model->value($this->input->post('address', TRUE)), 'city' => $this->Api_model->value($this->input->post('city', TRUE)), 'zip' => $this->input->post('zip', TRUE), 'state' => $this->Api_model->value($this->input->post('state', TRUE)), 'default_language' => $this->Api_model->value($this->input->post('default_language', TRUE)), 'description' => $this->Api_model->value($this->input->post('description', TRUE)), 'custom_contact_date' => $this->Api_model->value($this->input->post('custom_contact_date', TRUE)), 'is_public' => $this->Api_model->value($this->input->post('is_public', TRUE)), 'contacted_today' => $this->Api_model->value($this->input->post('contacted_today', TRUE)) ];
|
||||
if (!empty($this->input->post('custom_fields', TRUE))) {
|
||||
$insert_data['custom_fields'] = $this->Api_model->value($this->input->post('custom_fields', TRUE));
|
||||
}
|
||||
// insert data
|
||||
$this->load->model('leads_model');
|
||||
$output = $this->leads_model->add($insert_data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$this->handle_lead_attachments_array($output);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Lead add successful.',
|
||||
'record_id' => $output // επιστρέφουμε το ID του νέου lead
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Lead add fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/delete/leads/:id Delete a Lead
|
||||
* @apiName DeleteLead
|
||||
* @apiGroup Leads
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id lead unique ID.
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Lead Delete Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Lead Delete Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Lead Delete Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Lead Delete Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Lead ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
// delete data
|
||||
$this->load->model('leads_model');
|
||||
$output = $this->leads_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Lead Delete Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Lead Delete Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/leads/:id Update a lead
|
||||
* @apiName PutLead
|
||||
* @apiGroup Leads
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} source Mandatory Lead source.
|
||||
* @apiParam {String} status Mandatory Lead Status.
|
||||
* @apiParam {String} name Mandatory Lead Name.
|
||||
* @apiParam {String} assigned Mandatory Lead assigned.
|
||||
* @apiParam {String} [client_id] Optional Lead From Customer.
|
||||
* @apiParam {String} [tags] Optional Lead tags.
|
||||
* @apiParam {String} [contact] Optional Lead contact.
|
||||
* @apiParam {String} [title] Optional Position.
|
||||
* @apiParam {String} [email] Optional Lead Email Address.
|
||||
* @apiParam {String} [website] Optional Lead Website.
|
||||
* @apiParam {String} [phonenumber] Optional Lead Phone.
|
||||
* @apiParam {String} [company] Optional Lead company.
|
||||
* @apiParam {String} [address] Optional Lead address.
|
||||
* @apiParam {String} [city] Optional Lead City.
|
||||
* @apiParam {String} [zip] Optional Zip Code.
|
||||
* @apiParam {String} [state] Optional Lead state.
|
||||
* @apiParam {String} [country] Optional Lead Country.
|
||||
* @apiParam {String} [default_language] Optional Lead Default Language.
|
||||
* @apiParam {String} [description] Optional Lead description.
|
||||
* @apiParam {String} [lastcontact] Optional Lead Last Contact.
|
||||
* @apiParam {String} [is_public] Optional Lead google sheet id.
|
||||
*
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "name": "Lead name",
|
||||
* "contact": "contact",
|
||||
* "title": "title",
|
||||
* "company": "C.TY TNHH TM VẬN TẢI & DU LỊCH ĐẠI BẢO AN",
|
||||
* "description": "description",
|
||||
* "tags": "",
|
||||
* "city": "London",
|
||||
* "zip": "WC13KJ",
|
||||
* "state": "London",
|
||||
* "address": "1a The Alexander Suite Silk Point",
|
||||
* "assigned": "5",
|
||||
* "source": "4",
|
||||
* "email": "AA@gmail.com",
|
||||
* "website": "www.themesic.com",
|
||||
* "phonenumber": "123456789",
|
||||
* "is_public": "on",
|
||||
* "default_language": "english",
|
||||
* "client_id": "3",
|
||||
* "lastcontact": "25/07/2019 08:38:04"
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Lead Update Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Lead Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Lead Update Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Lead Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '') {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$this->load->library('parse_input_stream');
|
||||
$_POST = $this->parse_input_stream->parse_parameters();
|
||||
$_FILES = $this->parse_input_stream->parse_files();
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Lead ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$update_data = $this->input->post();
|
||||
$update_file = isset($update_data['file']) ? $update_data['file'] : null;
|
||||
unset($update_data['file']);
|
||||
// update data
|
||||
$this->load->model('leads_model');
|
||||
$output = $this->leads_model->update($update_data, $id);
|
||||
if (!empty($update_file) && count($update_file)) {
|
||||
if ($output <= 0 || empty($output)) {
|
||||
$output = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$attachments = $this->leads_model->get_lead_attachments($output);
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->leads_model->delete_lead_attachment($attachment['id']);
|
||||
}
|
||||
$this->handle_lead_attachments_array($output);
|
||||
$message = array('status' => TRUE, 'message' => 'Lead Update Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Lead Update Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handle_lead_attachments_array($leadid, $index_name = 'file') {
|
||||
$path = get_upload_path_by_type('lead') . $leadid . '/';
|
||||
$CI = & get_instance();
|
||||
if (isset($_FILES[$index_name]['name']) && ($_FILES[$index_name]['name'] != '' || is_array($_FILES[$index_name]['name']) && count($_FILES[$index_name]['name']) > 0)) {
|
||||
if (!is_array($_FILES[$index_name]['name'])) {
|
||||
$_FILES[$index_name]['name'] = [$_FILES[$index_name]['name']];
|
||||
$_FILES[$index_name]['type'] = [$_FILES[$index_name]['type']];
|
||||
$_FILES[$index_name]['tmp_name'] = [$_FILES[$index_name]['tmp_name']];
|
||||
$_FILES[$index_name]['error'] = [$_FILES[$index_name]['error']];
|
||||
$_FILES[$index_name]['size'] = [$_FILES[$index_name]['size']];
|
||||
}
|
||||
_file_attachments_index_fix($index_name);
|
||||
for ($i = 0; $i < count($_FILES[$index_name]['name']); $i++) {
|
||||
// Get the temp file path
|
||||
$tmpFilePath = $_FILES[$index_name]['tmp_name'][$i];
|
||||
// Make sure we have a filepath
|
||||
if (!empty($tmpFilePath) && $tmpFilePath != '') {
|
||||
if (_perfex_upload_error($_FILES[$index_name]['error'][$i]) || !_upload_extension_allowed($_FILES[$index_name]['name'][$i])) {
|
||||
continue;
|
||||
}
|
||||
_maybe_create_upload_path($path);
|
||||
$filename = unique_filename($path, $_FILES[$index_name]['name'][$i]);
|
||||
$newFilePath = $path . $filename;
|
||||
// Upload the file into the temp dir
|
||||
if (copy($tmpFilePath, $newFilePath)) {
|
||||
unlink($tmpFilePath);
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('leads_model');
|
||||
$data = [];
|
||||
$data[] = ['file_name' => $filename, 'filetype' => $_FILES[$index_name]['type'][$i], ];
|
||||
$CI->leads_model->add_attachment_to_database($leadid, $data, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
44
api/controllers/Login.php
Normal file
44
api/controllers/Login.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
require __DIR__ . '/API_Controller.php';
|
||||
|
||||
class Login extends API_Controller {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function login_api() {
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
// API Configuration
|
||||
$this->_apiConfig(['methods' => ['POST'], ]);
|
||||
// you user authentication code will go here, you can compare the user with the database or whatever
|
||||
$payload = ['id' => "Your User's ID", 'other' => "Some other data"];
|
||||
// Load Authorization Library or Load in autoload config file
|
||||
$this->load->library('authorization_token');
|
||||
// generate a token
|
||||
$token = $this->authorization_token->generateToken($payload);
|
||||
// return data
|
||||
$this->api_return(['status' => true, "result" => ['token' => $token, ], ], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* view method
|
||||
*
|
||||
* @link [api/user/view]
|
||||
* @method POST
|
||||
* @return Response|void
|
||||
*/
|
||||
public function view() {
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
// API Configuration [Return Array: User Token Data]
|
||||
$user_data = $this->_apiConfig(['methods' => ['POST'], 'requireAuthorization' => true, ]);
|
||||
// return data
|
||||
$this->api_return(['status' => true, "result" => ['user_data' => $user_data['token_data']], ], 200);
|
||||
}
|
||||
|
||||
public function api_key() {
|
||||
$this->_APIConfig(['methods' => ['POST'], 'key' => ['header', 'Set API Key'], ]);
|
||||
}
|
||||
}
|
||||
326
api/controllers/Milestones.php
Normal file
326
api/controllers/Milestones.php
Normal file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Milestones extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/milestones/:id Request Milestones information
|
||||
* @apiName GetMilestones
|
||||
* @apiGroup Milestones
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Milestones unique ID.
|
||||
*
|
||||
* @apiSuccess {Object} Milestones information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "5",
|
||||
* "name": "MIlestone A",
|
||||
* "description": "",
|
||||
* "description_visible_to_customer": "0",
|
||||
* "due_date": "2019-09-30",
|
||||
* "project_id": "2",
|
||||
* "color": null,
|
||||
* "milestone_order": "1",
|
||||
* "datecreated": "2019-07-19",
|
||||
* "total_tasks": "0",
|
||||
* "total_finished_tasks": "0"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('milestones', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/milestones/search/:keysearch Search Milestones Information
|
||||
* @apiName GetMilestoneSearch
|
||||
* @apiGroup Milestones
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Milestones information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "5",
|
||||
* "name": "MIlestone A",
|
||||
* "description": "",
|
||||
* "description_visible_to_customer": "0",
|
||||
* "due_date": "2019-09-30",
|
||||
* "project_id": "2",
|
||||
* "color": null,
|
||||
* "milestone_order": "1",
|
||||
* "datecreated": "2019-07-19",
|
||||
* "total_tasks": "0",
|
||||
* "total_finished_tasks": "0"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->search('milestones', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/milestones Add New Milestone
|
||||
* @apiName PostMilestone
|
||||
* @apiGroup Milestones
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} project_id Mandatory project id.
|
||||
* @apiParam {String} name Mandatory Milestone Name.
|
||||
* @apiParam {Date} due_date Mandatory Milestone Due date.
|
||||
* @apiParam {String} [description] Optional Milestone Description.
|
||||
* @apiParam {String} [description_visible_to_customer] Show description to customer.
|
||||
* @apiParam {String} [milestone_order] Optional Milestone Order.
|
||||
*
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* array (size=6)
|
||||
* 'project_id' => string '2' (length=1)
|
||||
* 'name' => string 'Milestone A' (length=11)
|
||||
* 'due_date' => string '30/07/2019' (length=10)
|
||||
* 'description' => string 'Description' (length=11)
|
||||
* 'description_visible_to_customer' => string 'on' (length=2)
|
||||
* 'milestone_order' => string '1' (length=1)
|
||||
*
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Milestone add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Milestone add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Milestone add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Milestone add fail."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
// form validation
|
||||
$this->form_validation->set_rules('name', 'Milestone Name', 'trim|required|max_length[600]', array('is_unique' => 'This %s already exists please enter another Milestone Name'));
|
||||
$this->form_validation->set_rules('project_id', 'Project id', 'trim|required', array('is_unique' => 'This %s already exists please enter another Project id'));
|
||||
$this->form_validation->set_rules('due_date', 'Milestone Due Date', 'trim|required', array('is_unique' => 'This %s already exists please enter another Milestone Due Date'));
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
// form validation error
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$insert_data = ['name' => $this->input->post('name', TRUE), 'due_date' => $this->input->post('due_date', TRUE), 'project_id' => $this->input->post('project_id', TRUE), 'description' => $this->Api_model->value($this->input->post('description', TRUE)), 'description_visible_to_customer' => $this->Api_model->value($this->input->post('description_visible_to_customer', TRUE)), 'milestone_order' => $this->Api_model->value($this->input->post('milestone_order', TRUE)) ];
|
||||
// insert data
|
||||
$this->load->model('projects_model');
|
||||
$output = $this->projects_model->add_milestone($insert_data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Milestone add successful.',
|
||||
'record_id' => $output // επιστρέφουμε το ID του νέου milestone
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Milestone add fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/delete/milestones/:id Delete a Milestone
|
||||
* @apiName DeleteMilestone
|
||||
* @apiGroup Milestones
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Milestone unique ID.
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Milestone Delete Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Milestone Delete Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Milestone Delete Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Milestone Delete Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Milestone ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
// delete data
|
||||
$this->load->model('projects_model');
|
||||
$output = $this->projects_model->delete_milestone($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Milestone Delete Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Milestone Delete Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/milestones/:id Update a Milestone
|
||||
* @apiName PutMilestone
|
||||
* @apiGroup Milestones
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} project_id Mandatory project id.
|
||||
* @apiParam {String} name Mandatory Milestone Name.
|
||||
* @apiParam {Date} due_date Mandatory Milestone Due date.
|
||||
* @apiParam {String} [description] Optional Milestone Description.
|
||||
* @apiParam {String} [description_visible_to_customer] Show description to customer.
|
||||
* @apiParam {String} [milestone_order] Optional Milestone Order.
|
||||
*
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "project_id": "1",
|
||||
* "name": "Milestone A",
|
||||
* "due_date": "30/07/2019",
|
||||
* "description": "Description",
|
||||
* "description_visible_to_customer": "on",
|
||||
* "milestone_order": "1"
|
||||
* }
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Milestone Update Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Milestone Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Milestone Update Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Milestone Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '') {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Milestone ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$update_data = $this->input->post();
|
||||
// update data
|
||||
$this->load->model('projects_model');
|
||||
$output = $this->projects_model->update_milestone($update_data, $id);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Milestone Update Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Milestone Update Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
313
api/controllers/Payments.php
Normal file
313
api/controllers/Payments.php
Normal file
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
*/
|
||||
class Payments extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
$this->load->model('payments_model');
|
||||
$this->load->model('Api_model');
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/payments/:id List all Payments
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetPayment
|
||||
* @apiGroup Payments
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} payment_id Optional payment unique ID <br/><i>Note : if you don't pass Payment id then it will list all payments records</i>
|
||||
*
|
||||
* @apiSuccess {Array} Payments List all Payment Records.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "id": "3",
|
||||
* "invoiceid": "7",
|
||||
* "amount": "1000.00",
|
||||
* "paymentmode": "3",
|
||||
* "paymentmethod": "",
|
||||
* "date": "2020-06-08",
|
||||
* "daterecorded": "2020-06-08 20:29:54",
|
||||
* "note": "",
|
||||
* "transactionid": "000355795931",
|
||||
* "invoiceid": "UPI",
|
||||
* "description": "",
|
||||
* "show_on_pdf": "0",
|
||||
* "invoices_only": "0",
|
||||
* "expenses_only": "0",
|
||||
* "selected_by_default": "0",
|
||||
* "active": "1",
|
||||
* "paymentid": "1"
|
||||
* },
|
||||
* {
|
||||
* "id": "4",
|
||||
* "invoiceid": "12",
|
||||
* "amount": "-3.00",
|
||||
* "paymentmode": "4",
|
||||
* "paymentmethod": "",
|
||||
* "date": "2020-07-04",
|
||||
* "daterecorded": "2020-07-04 15:32:59",
|
||||
* "note": "",
|
||||
* "transactionid": "P228210122733439",
|
||||
* "invoiceid": "Stripe",
|
||||
* "description": "",
|
||||
* "show_on_pdf": "0",
|
||||
* "invoices_only": "0",
|
||||
* "expenses_only": "0",
|
||||
* "selected_by_default": "0",
|
||||
* "active": "1",
|
||||
* "paymentid": "2"
|
||||
* },
|
||||
* {
|
||||
* "id": "1",
|
||||
* "invoiceid": "14",
|
||||
* "amount": "8.00",
|
||||
* "paymentmode": "1",
|
||||
* "paymentmethod": "",
|
||||
* "date": "2020-07-04",
|
||||
* "daterecorded": "2020-07-04 15:47:30",
|
||||
* "note": "",
|
||||
* "transactionid": "000360166374",
|
||||
* "invoiceid": "Bank",
|
||||
* "description": null,
|
||||
* "show_on_pdf": "0",
|
||||
* "invoices_only": "0",
|
||||
* "expenses_only": "0",
|
||||
* "selected_by_default": "1",
|
||||
* "active": "1",
|
||||
* "paymentid": "3"
|
||||
* },
|
||||
* {
|
||||
* "id": "2",
|
||||
* "invoiceid": "13",
|
||||
* "amount": "3.00",
|
||||
* "paymentmode": "2",
|
||||
* "paymentmethod": "Credit card",
|
||||
* "date": "2020-07-04",
|
||||
* "daterecorded": "2020-07-04 15:49:56",
|
||||
* "note": "",
|
||||
* "transactionid": "0124875873",
|
||||
* "invoiceid": "paypal",
|
||||
* "description": "",
|
||||
* "show_on_pdf": "0",
|
||||
* "invoices_only": "0",
|
||||
* "expenses_only": "0",
|
||||
* "selected_by_default": "0",
|
||||
* "active": "1",
|
||||
* "paymentid": "4"
|
||||
* }
|
||||
* ]
|
||||
* @apiError {Boolean} paymentmode Request paymentmode.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "paymentmode": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->payment_get($id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['paymentmode' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/payments/search/:keysearch Search Payments Information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetPaymentSearch
|
||||
* @apiGroup Payments
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords
|
||||
*
|
||||
* @apiSuccess {Array} Payments Payments information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "id": "3",
|
||||
* "invoiceid": "14",
|
||||
* "amount": "8.00",
|
||||
* "paymentmode": "2",
|
||||
* "paymentmethod": "",
|
||||
* "date": "2020-07-04",
|
||||
* "daterecorded": "2020-07-04 15:47:30",
|
||||
* "note": "",
|
||||
* "transactionid": "",
|
||||
* ...
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError {Boolean} paymentmode Request paymentmode
|
||||
* @apiError {String} message No data were found
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "paymentmode": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
// If the key parameter doesn't exist return all the
|
||||
$data = $this->Api_model->search('payments', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['paymentmode' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @api {post} api/payments Add New Payment
|
||||
* @apiName PostPayment
|
||||
* @apiGroup Payments
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} invoiceid Mandatory Invoice ID associated with the payment.
|
||||
* @apiParam {String} amount Mandatory Payment amount.
|
||||
* @apiParam {String} paymentmode Mandatory Payment mode (e.g., cash, credit card, etc.).
|
||||
* @apiParam {String} [paymentmethod] Optional Payment method details.
|
||||
* @apiParam {String} [note] Optional Additional payment note.
|
||||
* @apiParam {String} [transactionid] Optional Transaction ID.
|
||||
* @apiParam {String} [custom_fields] Optional Custom fields data.
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* array (size=6)
|
||||
* 'invoiceid' => string '123' (length=3)
|
||||
* 'amount' => string '250.00' (length=6)
|
||||
* 'paymentmode' => string '1' (length=1)
|
||||
* 'paymentmethod' => string 'Visa' (length=4)
|
||||
* 'note' => string 'Payment for Invoice #123' (length=25)
|
||||
* 'transactionid' => string 'TXN123456789' (length=12)
|
||||
* 'custom_fields' => string '{"field1": "value1", "field2": "value2"}' (JSON format)
|
||||
*
|
||||
* @apiSuccess {Boolean} paymentmode Status of the request.
|
||||
* @apiSuccess {String} message Payment add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "paymentmode": true,
|
||||
* "message": "Payment add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} paymentmode Status of the request.
|
||||
* @apiError {String} message Payment add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "paymentmode": false,
|
||||
* "message": "Payment add fail."
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
public function data_post() {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
// form validation
|
||||
$this->form_validation->set_rules('invoiceid', 'Payment Name', 'trim|required|max_length[600]', array('is_unique' => 'This %s already exists please enter another Payment Name'));
|
||||
$this->form_validation->set_rules('amount', 'Source', 'trim|required', array('is_unique' => 'This %s already exists please enter another Payment amount'));
|
||||
$this->form_validation->set_rules('paymentmode', 'Status', 'trim|required', array('is_unique' => 'This %s already exists please enter another Status'));
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
// form validation error
|
||||
$message = array('paymentmode' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$insert_data = [
|
||||
'invoiceid' => $this->input->post('invoiceid', TRUE),
|
||||
'amount' => $this->input->post('amount', TRUE),
|
||||
'paymentmode' => $this->input->post('paymentmode', TRUE),
|
||||
'paymentmethod' => $this->input->post('paymentmethod', TRUE),
|
||||
'date' => date('Y-m-d H:i:s'), // Current date and time
|
||||
'daterecorded' => date('Y-m-d H:i:s'), // Current date and time for recording
|
||||
'note' => $this->input->post('note', TRUE), // Optional note
|
||||
'transactionid' => $this->input->post('transactionid', TRUE)
|
||||
]; if (!empty($this->input->post('custom_fields', TRUE))) {
|
||||
$insert_data['custom_fields'] = $this->Api_model->value($this->input->post('custom_fields', TRUE));
|
||||
}
|
||||
// insert data
|
||||
$this->load->model('payments_model');
|
||||
$output = $this->payments_model->add($insert_data);
|
||||
// το $output πρέπει να είναι το ID του νέου payment
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$this->handle_payment_attachments_array($output);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Payment add successful.',
|
||||
'record_id' => $output // επιστρέφουμε το ID του νέου payment
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('paymentmode' => FALSE, 'message' => 'Payment add fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
453
api/controllers/Playground.php
Normal file
453
api/controllers/Playground.php
Normal file
@@ -0,0 +1,453 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Playground extends CI_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Only load essential helpers and libraries
|
||||
$this->load->helper('url');
|
||||
$this->load->helper('string');
|
||||
$this->load->library('session');
|
||||
|
||||
// Disable any auto-loaded helpers that might cause issues
|
||||
$this->load->library('output');
|
||||
|
||||
// Override any problematic properties that might be accessed by helpers
|
||||
$this->load->library('app_modules');
|
||||
}
|
||||
|
||||
/**
|
||||
* Public playground index page
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'API Playground - Test Perfex CRM API';
|
||||
$data['base_url'] = base_url();
|
||||
$data['api_base_url'] = base_url('api/');
|
||||
|
||||
// Load the sandbox view instead of swagger
|
||||
$this->load->view('playground/swagger', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sandbox playground page
|
||||
*/
|
||||
public function sandbox()
|
||||
{
|
||||
$data['title'] = 'API Sandbox Playground - Test Perfex CRM API';
|
||||
$data['base_url'] = base_url();
|
||||
$data['api_base_url'] = base_url('api/');
|
||||
|
||||
$this->load->view('playground/sandbox', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute API request (public access)
|
||||
*/
|
||||
public function execute_request()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$endpoint = $this->input->post('endpoint');
|
||||
$headers = $this->input->post('headers');
|
||||
$data = $this->input->post('data');
|
||||
|
||||
// Validate inputs
|
||||
if (empty($method) || empty($endpoint)) {
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Method and endpoint are required'
|
||||
]));
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare headers
|
||||
$request_headers = [];
|
||||
if (!empty($headers)) {
|
||||
$header_lines = explode("\n", $headers);
|
||||
foreach ($header_lines as $line) {
|
||||
$line = trim($line ?? '');
|
||||
if (strpos($line, ':') !== false) {
|
||||
list($key, $value) = explode(':', $line, 2);
|
||||
$request_headers[trim($key ?? '')] = trim($value ?? '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add default headers
|
||||
$request_headers['Content-Type'] = 'application/json';
|
||||
$request_headers['Accept'] = 'application/json';
|
||||
|
||||
// Prepare request data
|
||||
$request_data = null;
|
||||
if (!empty($data) && in_array($method, ['POST', 'PUT', 'PATCH'])) {
|
||||
$request_data = $data;
|
||||
}
|
||||
|
||||
// Make the API request
|
||||
$response = $this->make_api_request($method, $endpoint, $request_headers, $request_data);
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($response));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sample requests
|
||||
*/
|
||||
public function get_samples()
|
||||
{
|
||||
// Load comprehensive samples from config file
|
||||
$samples = include(dirname(__DIR__) . '/config/api_samples.php');
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($samples));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make API request using cURL
|
||||
*/
|
||||
private function make_api_request($method, $endpoint, $headers = [], $data = null)
|
||||
{
|
||||
$url = base_url('api/' . ltrim($endpoint, '/'));
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->format_headers($headers));
|
||||
|
||||
if ($data && in_array($method, ['POST', 'PUT', 'PATCH'])) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($error) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'cURL Error: ' . $error,
|
||||
'http_code' => 0
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'response' => $response,
|
||||
'http_code' => $http_code,
|
||||
'url' => $url
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format headers for cURL
|
||||
*/
|
||||
private function format_headers($headers)
|
||||
{
|
||||
$formatted = [];
|
||||
foreach ($headers as $key => $value) {
|
||||
$formatted[] = $key . ': ' . $value;
|
||||
}
|
||||
return $formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API documentation
|
||||
*/
|
||||
public function documentation()
|
||||
{
|
||||
$data['title'] = 'API Documentation';
|
||||
$this->load->view('playground/documentation', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Swagger file
|
||||
*/
|
||||
public function swagger() {
|
||||
echo file_get_contents(dirname(__DIR__) . '/config/swagger.json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get environment configuration
|
||||
*/
|
||||
public function get_environment_config()
|
||||
{
|
||||
$config = [
|
||||
'sandbox' => [
|
||||
'name' => 'Sandbox Environment',
|
||||
'description' => 'Safe testing environment - no production data affected',
|
||||
'base_url' => base_url('api/'),
|
||||
'features' => [
|
||||
'Safe testing',
|
||||
'No production data impact',
|
||||
'Request logging',
|
||||
'Sample data available'
|
||||
]
|
||||
],
|
||||
'production' => [
|
||||
'name' => 'Production Environment',
|
||||
'description' => 'Live production environment - USE WITH EXTREME CAUTION!',
|
||||
'base_url' => base_url('api/'),
|
||||
'features' => [
|
||||
'Live data access',
|
||||
'Real-time operations',
|
||||
'Production impact',
|
||||
'Requires authentication'
|
||||
],
|
||||
'warning' => 'This will affect live production data!'
|
||||
]
|
||||
];
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available endpoints by category
|
||||
*/
|
||||
public function get_endpoints()
|
||||
{
|
||||
$endpoints = [
|
||||
'leads' => [
|
||||
'name' => 'Leads',
|
||||
'description' => 'Manage sales leads and prospects',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/leads', 'description' => 'Get all leads'],
|
||||
['method' => 'POST', 'path' => '/leads', 'description' => 'Create new lead'],
|
||||
['method' => 'GET', 'path' => '/leads/{id}', 'description' => 'Get specific lead'],
|
||||
['method' => 'PUT', 'path' => '/leads/{id}', 'description' => 'Update lead'],
|
||||
['method' => 'DELETE', 'path' => '/leads/{id}', 'description' => 'Delete lead'],
|
||||
['method' => 'GET', 'path' => '/leads/search/{keyword}', 'description' => 'Search leads']
|
||||
]
|
||||
],
|
||||
'projects' => [
|
||||
'name' => 'Projects',
|
||||
'description' => 'Manage projects and project-related data',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/projects', 'description' => 'Get all projects'],
|
||||
['method' => 'POST', 'path' => '/projects', 'description' => 'Create new project'],
|
||||
['method' => 'GET', 'path' => '/projects/{id}', 'description' => 'Get specific project'],
|
||||
['method' => 'PUT', 'path' => '/projects/{id}', 'description' => 'Update project'],
|
||||
['method' => 'DELETE', 'path' => '/projects/{id}', 'description' => 'Delete project']
|
||||
]
|
||||
],
|
||||
'tasks' => [
|
||||
'name' => 'Tasks',
|
||||
'description' => 'Manage project tasks and assignments',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/tasks', 'description' => 'Get all tasks'],
|
||||
['method' => 'POST', 'path' => '/tasks', 'description' => 'Create new task'],
|
||||
['method' => 'GET', 'path' => '/tasks/{id}', 'description' => 'Get specific task'],
|
||||
['method' => 'PUT', 'path' => '/tasks/{id}', 'description' => 'Update task'],
|
||||
['method' => 'DELETE', 'path' => '/tasks/{id}', 'description' => 'Delete task']
|
||||
]
|
||||
],
|
||||
'tickets' => [
|
||||
'name' => 'Support Tickets',
|
||||
'description' => 'Manage customer support tickets',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/tickets', 'description' => 'Get all tickets'],
|
||||
['method' => 'POST', 'path' => '/tickets', 'description' => 'Create new ticket'],
|
||||
['method' => 'GET', 'path' => '/tickets/{id}', 'description' => 'Get specific ticket'],
|
||||
['method' => 'PUT', 'path' => '/tickets/{id}', 'description' => 'Update ticket'],
|
||||
['method' => 'DELETE', 'path' => '/tickets/{id}', 'description' => 'Delete ticket']
|
||||
]
|
||||
],
|
||||
'invoices' => [
|
||||
'name' => 'Invoices',
|
||||
'description' => 'Manage billing and invoicing',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/invoices', 'description' => 'Get all invoices'],
|
||||
['method' => 'POST', 'path' => '/invoices', 'description' => 'Create new invoice'],
|
||||
['method' => 'GET', 'path' => '/invoices/{id}', 'description' => 'Get specific invoice'],
|
||||
['method' => 'PUT', 'path' => '/invoices/{id}', 'description' => 'Update invoice'],
|
||||
['method' => 'DELETE', 'path' => '/invoices/{id}', 'description' => 'Delete invoice'],
|
||||
['method' => 'GET', 'path' => '/invoices/search/{keyword}', 'description' => 'Search invoices']
|
||||
]
|
||||
],
|
||||
'estimates' => [
|
||||
'name' => 'Estimates',
|
||||
'description' => 'Manage project estimates and quotes',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/estimates', 'description' => 'Get all estimates'],
|
||||
['method' => 'POST', 'path' => '/estimates', 'description' => 'Create new estimate'],
|
||||
['method' => 'GET', 'path' => '/estimates/{id}', 'description' => 'Get specific estimate'],
|
||||
['method' => 'PUT', 'path' => '/estimates/{id}', 'description' => 'Update estimate'],
|
||||
['method' => 'DELETE', 'path' => '/estimates/{id}', 'description' => 'Delete estimate'],
|
||||
['method' => 'GET', 'path' => '/estimates/search/{keyword}', 'description' => 'Search estimates']
|
||||
]
|
||||
],
|
||||
'contracts' => [
|
||||
'name' => 'Contracts',
|
||||
'description' => 'Manage client contracts and agreements',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/contracts', 'description' => 'Get all contracts'],
|
||||
['method' => 'POST', 'path' => '/contracts', 'description' => 'Create new contract'],
|
||||
['method' => 'GET', 'path' => '/contracts/{id}', 'description' => 'Get specific contract'],
|
||||
['method' => 'PUT', 'path' => '/contracts/{id}', 'description' => 'Update contract'],
|
||||
['method' => 'DELETE', 'path' => '/contracts/{id}', 'description' => 'Delete contract']
|
||||
]
|
||||
],
|
||||
'credit_notes' => [
|
||||
'name' => 'Credit Notes',
|
||||
'description' => 'Manage credit notes and refunds',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/credit_notes', 'description' => 'Get all credit notes'],
|
||||
['method' => 'POST', 'path' => '/credit_notes', 'description' => 'Create new credit note'],
|
||||
['method' => 'GET', 'path' => '/credit_notes/{id}', 'description' => 'Get specific credit note'],
|
||||
['method' => 'PUT', 'path' => '/credit_notes/{id}', 'description' => 'Update credit note'],
|
||||
['method' => 'DELETE', 'path' => '/credit_notes/{id}', 'description' => 'Delete credit note'],
|
||||
['method' => 'GET', 'path' => '/credit_notes/search/{keyword}', 'description' => 'Search credit notes']
|
||||
]
|
||||
],
|
||||
'expenses' => [
|
||||
'name' => 'Expenses',
|
||||
'description' => 'Manage business expenses and reimbursements',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/expenses', 'description' => 'Get all expenses'],
|
||||
['method' => 'POST', 'path' => '/expenses', 'description' => 'Create new expense'],
|
||||
['method' => 'GET', 'path' => '/expenses/{id}', 'description' => 'Get specific expense'],
|
||||
['method' => 'PUT', 'path' => '/expenses/{id}', 'description' => 'Update expense'],
|
||||
['method' => 'DELETE', 'path' => '/expenses/{id}', 'description' => 'Delete expense'],
|
||||
['method' => 'GET', 'path' => '/expenses/search/{keyword}', 'description' => 'Search expenses']
|
||||
]
|
||||
],
|
||||
'items' => [
|
||||
'name' => 'Items',
|
||||
'description' => 'Manage invoice items and products',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/items', 'description' => 'Get all items'],
|
||||
['method' => 'GET', 'path' => '/items/{id}', 'description' => 'Get specific item'],
|
||||
['method' => 'GET', 'path' => '/items/search/{keyword}', 'description' => 'Search items']
|
||||
]
|
||||
],
|
||||
'contacts' => [
|
||||
'name' => 'Contacts',
|
||||
'description' => 'Manage client contacts and relationships',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/contacts', 'description' => 'Get all contacts'],
|
||||
['method' => 'POST', 'path' => '/contacts', 'description' => 'Create new contact'],
|
||||
['method' => 'GET', 'path' => '/contacts/{customer_id}/{contact_id}', 'description' => 'Get specific contact'],
|
||||
['method' => 'PUT', 'path' => '/contacts/{customer_id}/{contact_id}', 'description' => 'Update contact'],
|
||||
['method' => 'DELETE', 'path' => '/contacts/{customer_id}', 'description' => 'Delete contact'],
|
||||
['method' => 'GET', 'path' => '/contacts/search/{keyword}', 'description' => 'Search contacts']
|
||||
]
|
||||
],
|
||||
'staff' => [
|
||||
'name' => 'Staff',
|
||||
'description' => 'Manage staff members and team information',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/staff', 'description' => 'Get all staff members'],
|
||||
['method' => 'GET', 'path' => '/staff/{id}', 'description' => 'Get specific staff member']
|
||||
]
|
||||
],
|
||||
'payments' => [
|
||||
'name' => 'Payments',
|
||||
'description' => 'Manage invoice payments and transactions',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/payments', 'description' => 'Get all payments'],
|
||||
['method' => 'POST', 'path' => '/payments', 'description' => 'Create new payment'],
|
||||
['method' => 'GET', 'path' => '/payments/{id}', 'description' => 'Get specific payment'],
|
||||
['method' => 'PUT', 'path' => '/payments/{id}', 'description' => 'Update payment'],
|
||||
['method' => 'DELETE', 'path' => '/payments/{id}', 'description' => 'Delete payment']
|
||||
]
|
||||
],
|
||||
'proposals' => [
|
||||
'name' => 'Proposals',
|
||||
'description' => 'Manage project proposals and quotes',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/proposals', 'description' => 'Get all proposals'],
|
||||
['method' => 'POST', 'path' => '/proposals', 'description' => 'Create new proposal'],
|
||||
['method' => 'GET', 'path' => '/proposals/{id}', 'description' => 'Get specific proposal'],
|
||||
['method' => 'PUT', 'path' => '/proposals/{id}', 'description' => 'Update proposal'],
|
||||
['method' => 'DELETE', 'path' => '/proposals/{id}', 'description' => 'Delete proposal']
|
||||
]
|
||||
],
|
||||
'subscriptions' => [
|
||||
'name' => 'Subscriptions',
|
||||
'description' => 'Manage recurring subscriptions and billing',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/subscriptions', 'description' => 'Get all subscriptions'],
|
||||
['method' => 'POST', 'path' => '/subscriptions', 'description' => 'Create new subscription'],
|
||||
['method' => 'GET', 'path' => '/subscriptions/{id}', 'description' => 'Get specific subscription'],
|
||||
['method' => 'PUT', 'path' => '/subscriptions/{id}', 'description' => 'Update subscription'],
|
||||
['method' => 'DELETE', 'path' => '/subscriptions/{id}', 'description' => 'Delete subscription']
|
||||
]
|
||||
],
|
||||
'milestones' => [
|
||||
'name' => 'Milestones',
|
||||
'description' => 'Manage project milestones and deliverables',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/milestones', 'description' => 'Get all milestones'],
|
||||
['method' => 'POST', 'path' => '/milestones', 'description' => 'Create new milestone'],
|
||||
['method' => 'GET', 'path' => '/milestones/{id}', 'description' => 'Get specific milestone'],
|
||||
['method' => 'PUT', 'path' => '/milestones/{id}', 'description' => 'Update milestone'],
|
||||
['method' => 'DELETE', 'path' => '/milestones/{id}', 'description' => 'Delete milestone'],
|
||||
['method' => 'GET', 'path' => '/milestones/search/{keyword}', 'description' => 'Search milestones']
|
||||
]
|
||||
],
|
||||
'timesheets' => [
|
||||
'name' => 'Timesheets',
|
||||
'description' => 'Manage time tracking and work logs',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/timesheets', 'description' => 'Get all timesheets'],
|
||||
['method' => 'POST', 'path' => '/timesheets', 'description' => 'Create new timesheet entry'],
|
||||
['method' => 'GET', 'path' => '/timesheets/{id}', 'description' => 'Get specific timesheet'],
|
||||
['method' => 'PUT', 'path' => '/timesheets/{id}', 'description' => 'Update timesheet'],
|
||||
['method' => 'DELETE', 'path' => '/timesheets/{id}', 'description' => 'Delete timesheet']
|
||||
]
|
||||
],
|
||||
'calendar' => [
|
||||
'name' => 'Calendar',
|
||||
'description' => 'Manage calendar events and scheduling',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/calendar', 'description' => 'Get all calendar events'],
|
||||
['method' => 'POST', 'path' => '/calendar', 'description' => 'Create new calendar event'],
|
||||
['method' => 'GET', 'path' => '/calendar/{id}', 'description' => 'Get specific calendar event'],
|
||||
['method' => 'PUT', 'path' => '/calendar/{id}', 'description' => 'Update calendar event'],
|
||||
['method' => 'DELETE', 'path' => '/calendar/{id}', 'description' => 'Delete calendar event']
|
||||
]
|
||||
],
|
||||
'common' => [
|
||||
'name' => 'Common Data',
|
||||
'description' => 'Access common system data and configurations',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/common/expense_category', 'description' => 'Get expense categories'],
|
||||
['method' => 'GET', 'path' => '/common/payment_mode', 'description' => 'Get payment modes'],
|
||||
['method' => 'GET', 'path' => '/common/tax_data', 'description' => 'Get tax data']
|
||||
]
|
||||
],
|
||||
'custom_fields' => [
|
||||
'name' => 'Custom Fields',
|
||||
'description' => 'Manage custom fields for different modules',
|
||||
'endpoints' => [
|
||||
['method' => 'GET', 'path' => '/custom_fields/{type}', 'description' => 'Get custom fields by type'],
|
||||
['method' => 'GET', 'path' => '/custom_fields/{type}/{id}', 'description' => 'Get specific custom field']
|
||||
]
|
||||
],
|
||||
'authentication' => [
|
||||
'name' => 'Authentication',
|
||||
'description' => 'User authentication and API key management',
|
||||
'endpoints' => [
|
||||
['method' => 'POST', 'path' => '/login/auth', 'description' => 'Authenticate user'],
|
||||
['method' => 'GET', 'path' => '/login/key', 'description' => 'Get API key information']
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($endpoints));
|
||||
}
|
||||
}
|
||||
624
api/controllers/Projects.php
Normal file
624
api/controllers/Projects.php
Normal file
@@ -0,0 +1,624 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__.'/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
*/
|
||||
class Projects extends REST_Controller {
|
||||
function __construct()
|
||||
{
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
$this->load->model('Api_model');
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/projects/:id Request project information
|
||||
* @apiName GetProject
|
||||
* @apiGroup Projects
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id project unique ID.
|
||||
*
|
||||
* @apiSuccess {Object} Project information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "28",
|
||||
* "name": "Test1",
|
||||
* "description": null,
|
||||
* "status": "1",
|
||||
* "clientid": "11",
|
||||
* "billing_type": "3",
|
||||
* "start_date": "2019-04-19",
|
||||
* "deadline": "2019-08-30",
|
||||
* "project_created": "2019-07-16",
|
||||
* "date_finished": null,
|
||||
* "progress": "0",
|
||||
* "progress_from_tasks": "1",
|
||||
* "project_cost": "0.00",
|
||||
* "project_rate_per_hour": "0.00",
|
||||
* "estimated_hours": "0.00",
|
||||
* "addedfrom": "5",
|
||||
* "rel_type": "lead",
|
||||
* "potential_revenue": "0.00",
|
||||
* "potential_margin": "0.00",
|
||||
* "external": "E",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '')
|
||||
{
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('projects', $id);
|
||||
|
||||
// Check if the data store contains
|
||||
if ($data)
|
||||
{
|
||||
$data = $this->Api_model->get_api_custom_data($data, "projects", $id);
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/projects/search/:keysearch Search Project Information
|
||||
* @apiName GetProjectSearch
|
||||
* @apiGroup Projects
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Project information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "28",
|
||||
* "name": "Test1",
|
||||
* "description": null,
|
||||
* "status": "1",
|
||||
* "clientid": "11",
|
||||
* "billing_type": "3",
|
||||
* "start_date": "2019-04-19",
|
||||
* "deadline": "2019-08-30",
|
||||
* "project_created": "2019-07-16",
|
||||
* "date_finished": null,
|
||||
* "progress": "0",
|
||||
* "progress_from_tasks": "1",
|
||||
* "project_cost": "0.00",
|
||||
* "project_rate_per_hour": "0.00",
|
||||
* "estimated_hours": "0.00",
|
||||
* "addedfrom": "5",
|
||||
* "rel_type": "lead",
|
||||
* "potential_revenue": "0.00",
|
||||
* "potential_margin": "0.00",
|
||||
* "external": "E",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '')
|
||||
{
|
||||
$data = $this->Api_model->search('project', $key);
|
||||
|
||||
// Check if the data store contains
|
||||
if ($data)
|
||||
{
|
||||
$data = $this->Api_model->get_api_custom_data($data,"projects");
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/projects Add New Project
|
||||
* @apiName PostProject
|
||||
* @apiGroup Projects
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} name Mandatory Project Name.
|
||||
* @apiParam {string="lead","customer","internal"} rel_type Mandatory Project Related.
|
||||
* @apiParam {Number} clientid Mandatory Related ID.
|
||||
* @apiParam {Number} billing_type Mandatory Billing Type.
|
||||
* @apiParam {Date} start_date Mandatory Project Start Date.
|
||||
* @apiParam {Number} status Mandatory Project Status.
|
||||
* @apiParam {String} [progress_from_tasks] Optional on or off progress from tasks.
|
||||
* @apiParam {String} [project_cost] Optional Project Cost.
|
||||
* @apiParam {String} [progress] Optional project progress.
|
||||
* @apiParam {String} [project_rate_per_hour] Optional project rate per hour.
|
||||
* @apiParam {String} [estimated_hours] Optional Project estimated hours.
|
||||
* @apiParam {Number[]} [project_members] Optional Project members.
|
||||
* @apiParam {Date} [deadline] Optional Project deadline.
|
||||
* @apiParam {String} [tags] Optional Project tags.
|
||||
* @apiParam {String} [description] Optional Project description.
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* array (size=15)
|
||||
* 'name' => string 'Project Name' (length=12)
|
||||
* 'rel_type' => string 'customer' (length=8)
|
||||
* 'clientid' => string '3' (length=1)
|
||||
* 'progress_from_tasks' => string 'on' (length=2)
|
||||
* 'progress' => string '0' (length=1)
|
||||
* 'billing_type' => string '3' (length=1)
|
||||
* 'status' => string '2' (length=1)
|
||||
* 'project_cost' => string '' (length=0)
|
||||
* 'project_rate_per_hour' => string '' (length=0)
|
||||
* 'estimated_hours' => string '' (length=0)
|
||||
* 'project_members' =>
|
||||
* array (size=1)
|
||||
* 0 => string '1' (length=1)
|
||||
* 'start_date' => string '25/07/2019' (length=10)
|
||||
* 'deadline' => string '' (length=0)
|
||||
* 'tags' => string '' (length=0)
|
||||
* 'description' => string '' (length=0)
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Project add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Project add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Project add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Project add fail."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post()
|
||||
{
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
// form validation
|
||||
$this->form_validation->set_rules('name', 'Project Name', 'trim|required|max_length[600]', array('is_unique' => 'This %s already exists please enter another Project Name'));
|
||||
//$this->form_validation->set_rules('rel_type', 'Related', 'trim|required', array('is_unique' => 'This %s already exists please enter another Project Related'));
|
||||
$this->form_validation->set_rules('billing_type', 'Billing Type', 'trim|required', array('is_unique' => 'This %s already exists please enter another Project Billing Type'));
|
||||
$this->form_validation->set_rules('start_date', 'Project Start Date', 'trim|required', array('is_unique' => 'This %s already exists please enter another Project Start Date'));
|
||||
$this->form_validation->set_rules('status', 'Project Status', 'trim|required', array('is_unique' => 'This %s already exists please enter another Project Status'));
|
||||
$related = $this->input->post('rel_type', TRUE);
|
||||
$this->form_validation->set_rules('clientid', ucwords($related), 'trim|required|max_length[11]', array('is_unique' => 'This %s already exists please enter another Project Name'));
|
||||
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
// form validation error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'error' => $this->form_validation->error_array(),
|
||||
'message' => validation_errors()
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
$project_members = $this->Api_model->value($this->input->post('project_members', TRUE));
|
||||
$insert_data = [
|
||||
'name' => $this->input->post('name', TRUE),
|
||||
//'rel_type' => $this->input->post('rel_type', TRUE),
|
||||
'clientid' => $this->input->post('clientid', TRUE),
|
||||
'billing_type' => $this->input->post('billing_type', TRUE),
|
||||
'start_date' => $this->input->post('start_date', TRUE),
|
||||
'status' => $this->input->post('status', TRUE),
|
||||
'project_cost' => $this->Api_model->value($this->input->post('project_cost', TRUE)),
|
||||
'estimated_hours' => $this->Api_model->value($this->input->post('estimated_hours', TRUE)),
|
||||
'progress_from_tasks' => $this->Api_model->value($this->input->post('progress_from_tasks', TRUE)),
|
||||
'progress' => $this->Api_model->value($this->input->post('progress', TRUE)),
|
||||
'project_rate_per_hour' => $this->Api_model->value($this->input->post('project_rate_per_hour', TRUE)),
|
||||
'deadline' => $this->Api_model->value($this->input->post('deadline', TRUE)),
|
||||
'description' => $this->Api_model->value($this->input->post('description', TRUE)),
|
||||
'tags' => $this->Api_model->value($this->input->post('tags', TRUE)),
|
||||
|
||||
'settings' => array( 'available_features' => array( 'project_overview', 'project_milestones', 'project_gantt', 'project_tasks', 'project_estimates', 'project_subscriptions', 'project_invoices', 'project_expenses', 'project_credit_notes', 'project_tickets', 'project_timesheets', 'project_files', 'project_discussions', 'project_notes', 'project_activity'))
|
||||
];
|
||||
if ($project_members != '') {
|
||||
$insert_data['project_members'] = $project_members;
|
||||
}
|
||||
if (!empty($this->input->post('custom_fields', TRUE))) {
|
||||
$insert_data['custom_fields'] = $this->Api_model->value($this->input->post('custom_fields', TRUE));
|
||||
}
|
||||
|
||||
// insert data
|
||||
$this->load->model('projects_model');
|
||||
$output = $this->projects_model->add($insert_data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
handle_project_file_uploads($output);
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Project add successful.',
|
||||
'record_id' => $output // επιστρέφουμε το ID του νέου project
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Project add failed.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/delete/projects/:id Delete a Project
|
||||
* @apiName DeleteProject
|
||||
* @apiGroup Projects
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id project unique ID.
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Project Delete successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Project Delete Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Project Delete Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Project Delete Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '')
|
||||
{
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id))
|
||||
{
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid Project ID'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete data
|
||||
$this->load->model('projects_model');
|
||||
$output = $this->projects_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Project Delete Successful.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Project Delete Fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/projects/:id Update a project
|
||||
* @apiName PutProject
|
||||
* @apiGroup Projects
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} name Mandatory Project Name.
|
||||
* @apiParam {string="lead","customer","internal"} rel_type Mandatory Project Related.
|
||||
* @apiParam {Number} clientid Mandatory Related ID.
|
||||
* @apiParam {Number} billing_type Mandatory Billing Type.
|
||||
* @apiParam {Date} start_date Mandatory Project Start Date.
|
||||
* @apiParam {Number} status Mandatory Project Status.
|
||||
* @apiParam {String} [progress_from_tasks] Optional on or off progress from tasks.
|
||||
* @apiParam {String} [project_cost] Optional Project Cost.
|
||||
* @apiParam {String} [progress] Optional project progress.
|
||||
* @apiParam {String} [project_rate_per_hour] Optional project rate per hour.
|
||||
* @apiParam {String} [estimated_hours] Optional Project estimated hours.
|
||||
* @apiParam {Number[]} [project_members] Optional Project members.
|
||||
* @apiParam {Date} [deadline] Optional Project deadline.
|
||||
* @apiParam {String} [tags] Optional Project tags.
|
||||
* @apiParam {String} [description] Optional Project description.
|
||||
*
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "name": "Test1",
|
||||
* "rel_type": "lead",
|
||||
* "clientid": "9",
|
||||
* "status": "2",
|
||||
* "progress_from_tasks": "on",
|
||||
* "progress": "0.00",
|
||||
* "billing_type": "3",
|
||||
* "project_cost": "0",
|
||||
* "project_rate_per_hour": "0",
|
||||
* "estimated_hours": "0",
|
||||
* "project_members":
|
||||
* {
|
||||
* "0": "5"
|
||||
* }
|
||||
* "start_date": "19/04/2019",
|
||||
* "deadline": "30/08/2019",
|
||||
* "tags": "",
|
||||
* "description": "",
|
||||
* "settings":
|
||||
* {
|
||||
* "available_features":
|
||||
* {
|
||||
* "0": "project_overview",
|
||||
* "1": "project_milestones" ,
|
||||
* "2": "project_gantt" ,
|
||||
* "3": "project_tasks" ,
|
||||
* "4": "project_estimates" ,
|
||||
* "5": "project_credit_notes" ,
|
||||
* "6": "project_invoices" ,
|
||||
* "7": "project_expenses",
|
||||
* "8": "project_subscriptions" ,
|
||||
* "9": "project_activity" ,
|
||||
* "10": "project_tickets" ,
|
||||
* "11": "project_timesheets",
|
||||
* "12": "project_files" ,
|
||||
* "13": "project_discussions" ,
|
||||
* "14": "project_notes"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Project Update Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Project Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Project Update Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Project Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '')
|
||||
{
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$this->load->library('parse_input_stream');
|
||||
$_POST = $this->parse_input_stream->parse_parameters();
|
||||
$_FILES = $this->parse_input_stream->parse_files();
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Lead ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$update_data = $this->input->post();
|
||||
$update_file = isset($update_data['file']) ? $update_data['file'] : null;
|
||||
unset($update_data['file']);
|
||||
// update data
|
||||
$this->load->model('projects_model');
|
||||
$output = $this->projects_model->update($update_data, $id);
|
||||
if (!empty($update_file) && count($update_file)) {
|
||||
if ($output <= 0 || empty($output)) {
|
||||
$output = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($output == true && !empty($output)) {
|
||||
// success
|
||||
$attachments = $this->projects_model->get_files($output);
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->projects_model->remove_file($attachment['id']);
|
||||
}
|
||||
$this->handle_project_attachments_array($output);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Project Update Successful.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Project Update Fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handle_project_attachments_array($project_id)
|
||||
{
|
||||
$hookData = hooks()->apply_filters('before_handle_project_file_uploads', [
|
||||
'project_id' => $project_id,
|
||||
'index_name' => 'file',
|
||||
'handled_externally' => false, // e.g. module upload to s3
|
||||
'handled_externally_successfully' => false,
|
||||
'files' => $_FILES
|
||||
]);
|
||||
|
||||
if ($hookData['handled_externally']) {
|
||||
return $hookData['handled_externally_successfully'];
|
||||
}
|
||||
|
||||
$filesIDS = [];
|
||||
$errors = [];
|
||||
|
||||
if (isset($_FILES['file']['name'])
|
||||
&& ($_FILES['file']['name'] != '' || is_array($_FILES['file']['name']) && count($_FILES['file']['name']) > 0)) {
|
||||
hooks()->do_action('before_upload_project_attachment', $project_id);
|
||||
|
||||
if (!is_array($_FILES['file']['name'])) {
|
||||
$_FILES['file']['name'] = [$_FILES['file']['name']];
|
||||
$_FILES['file']['type'] = [$_FILES['file']['type']];
|
||||
$_FILES['file']['tmp_name'] = [$_FILES['file']['tmp_name']];
|
||||
$_FILES['file']['error'] = [$_FILES['file']['error']];
|
||||
$_FILES['file']['size'] = [$_FILES['file']['size']];
|
||||
}
|
||||
|
||||
$path = get_upload_path_by_type('project') . $project_id . '/';
|
||||
|
||||
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
|
||||
if (_perfex_upload_error($_FILES['file']['error'][$i])) {
|
||||
$errors[$_FILES['file']['name'][$i]] = _perfex_upload_error($_FILES['file']['error'][$i]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the temp file path
|
||||
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
|
||||
// Make sure we have a filepath
|
||||
if (!empty($tmpFilePath) && $tmpFilePath != '') {
|
||||
_maybe_create_upload_path($path);
|
||||
$originalFilename = unique_filename($path, $_FILES['file']['name'][$i]);
|
||||
$filename = app_generate_hash() . '.' . get_file_extension($originalFilename);
|
||||
|
||||
// In case client side validation is bypassed
|
||||
if (!_upload_extension_allowed($filename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newFilePath = $path . $filename;
|
||||
// Upload the file into the company uploads dir
|
||||
if (copy($tmpFilePath, $newFilePath)) {
|
||||
unlink($tmpFilePath);
|
||||
if (is_client_logged_in()) {
|
||||
$contact_id = get_contact_user_id();
|
||||
$staffid = 0;
|
||||
} else {
|
||||
$staffid = get_staff_user_id();
|
||||
$contact_id = 0;
|
||||
}
|
||||
$data = [
|
||||
'project_id' => $project_id,
|
||||
'file_name' => $filename,
|
||||
'original_file_name' => $originalFilename,
|
||||
'filetype' => $_FILES['file']['type'][$i],
|
||||
'dateadded' => date('Y-m-d H:i:s'),
|
||||
'staffid' => $staffid,
|
||||
'contact_id' => $contact_id,
|
||||
'subject' => $originalFilename,
|
||||
];
|
||||
if (is_client_logged_in()) {
|
||||
$data['visible_to_customer'] = 1;
|
||||
} else {
|
||||
$data['visible_to_customer'] = ($this->input->post('visible_to_customer') == 'true' ? 1 : 0);
|
||||
}
|
||||
$this->db->insert(db_prefix() . 'project_files', $data);
|
||||
|
||||
$insert_id = $this->db->insert_id();
|
||||
if ($insert_id) {
|
||||
if (is_image($newFilePath)) {
|
||||
create_img_thumb($path, $filename);
|
||||
}
|
||||
array_push($filesIDS, $insert_id);
|
||||
} else {
|
||||
unlink($newFilePath);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($filesIDS) > 0) {
|
||||
$this->load->model('projects_model');
|
||||
end($filesIDS);
|
||||
$lastFileID = key($filesIDS);
|
||||
$this->projects_model->new_project_file_notification($filesIDS[$lastFileID], $project_id);
|
||||
}
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$message = '';
|
||||
foreach ($errors as $filename => $error_message) {
|
||||
$message .= $filename . ' - ' . $error_message . '<br />';
|
||||
}
|
||||
header('HTTP/1.0 400 Bad error');
|
||||
echo $message;
|
||||
die;
|
||||
}
|
||||
|
||||
if (count($filesIDS) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
556
api/controllers/Proposals.php
Normal file
556
api/controllers/Proposals.php
Normal file
@@ -0,0 +1,556 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Proposals extends REST_Controller {
|
||||
function __construct() {
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/proposals Request Proposal information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetProposal
|
||||
* @apiGroup Proposals
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiParam {Number} id Proposal unique ID
|
||||
*
|
||||
* @apiSuccess {Object} Proposal information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "1",
|
||||
* "subject": "Test Proposal",
|
||||
* "content": "{proposal_items}",
|
||||
* "addedfrom": "1",
|
||||
* "datecreated": "2021-08-01 13:38:08",
|
||||
* "total": "10.00",
|
||||
* "subtotal": "10.00",
|
||||
* "total_tax": "0.00",
|
||||
* "adjustment": "0.00",
|
||||
* "discount_percent": "0.00",
|
||||
* "discount_total": "0.00",
|
||||
* "discount_type": "",
|
||||
* "show_quantity_as": "1",
|
||||
* "currency": "1",
|
||||
* "open_till": "2021-08-08",
|
||||
* "date": "2021-08-01",
|
||||
* "rel_id": "1",
|
||||
* "rel_type": "customer",
|
||||
* "assigned": "0",
|
||||
* "hash": "9fc38e5ad2f8256b1b8430ee41069f75",
|
||||
* "proposal_to": "test",
|
||||
* "country": "102",
|
||||
* "zip": "30000202",
|
||||
* "state": "Test",
|
||||
* "city": "Test",
|
||||
* "address": "Test",
|
||||
* "email": "test@gmail.com",
|
||||
* "phone": "01324568903",
|
||||
* "allow_comments": "1",
|
||||
* "status": "6",
|
||||
* "estimate_id": null,
|
||||
* "invoice_id": null,
|
||||
* "date_converted": null,
|
||||
* "pipeline_order": "0",
|
||||
* "is_expiry_notified": "0",
|
||||
* "acceptance_firstname": null,
|
||||
* "acceptance_lastname": null,
|
||||
* "acceptance_email": null,
|
||||
* "acceptance_date": null,
|
||||
* "acceptance_ip": null,
|
||||
* "signature": null,
|
||||
* "short_link": null,
|
||||
* "symbol": "$",
|
||||
* "name": "USD",
|
||||
* "decimal_separator": ".",
|
||||
* "thousand_separator": ",",
|
||||
* "placement": "before",
|
||||
* "isdefault": "1",
|
||||
* "currencyid": "1",
|
||||
* "currency_name": "USD",
|
||||
* "attachments": [],
|
||||
* "items": [
|
||||
* {
|
||||
* "id": "4",
|
||||
* "rel_id": "1",
|
||||
* "rel_type": "proposal",
|
||||
* "description": "item 1",
|
||||
* "long_description": "item 1 description",
|
||||
* "qty": "1.00",
|
||||
* "rate": "10.00",
|
||||
* "unit": "1",
|
||||
* "item_order": "1"
|
||||
* }
|
||||
* ],
|
||||
* "visible_attachments_to_customer_found": false,
|
||||
* "customfields": [
|
||||
* {
|
||||
* "label": "Custom Field",
|
||||
* "value": "Custom Field value"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '') {
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('proposals', $id);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "proposal", $id);
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/proposals/search/:keysearch Search proposals information
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName GetProposalSearch
|
||||
* @apiGroup Proposals
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Proposals Information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "2",
|
||||
* "subject": "Test 2",
|
||||
* "content": "{proposal_items}",
|
||||
* "addedfrom": "1",
|
||||
* "datecreated": "2021-08-01 13:43:49",
|
||||
* "total": "10.00",
|
||||
* "subtotal": "10.00",
|
||||
* "total_tax": "0.00",
|
||||
* "adjustment": "0.00",
|
||||
* "discount_percent": "0.00",
|
||||
* "discount_total": "0.00",
|
||||
* "discount_type": "",
|
||||
* "show_quantity_as": "1",
|
||||
* "currency": "1",
|
||||
* "open_till": "2021-08-08",
|
||||
* "date": "2021-08-01",
|
||||
* "rel_id": "1",
|
||||
* "rel_type": "customer",
|
||||
* "assigned": "0",
|
||||
* "hash": "6fe6cd0bc66dff03663154660acc1a93",
|
||||
* "proposal_to": "test",
|
||||
* "country": "102",
|
||||
* "zip": "300000",
|
||||
* "state": "test",
|
||||
* "city": "test",
|
||||
* "address": "test",
|
||||
* "email": "test@gmail.com",
|
||||
* "phone": "01324568903",
|
||||
* "allow_comments": "1",
|
||||
* "status": "6",
|
||||
* "estimate_id": null,
|
||||
* "invoice_id": null,
|
||||
* "date_converted": null,
|
||||
* "pipeline_order": "0",
|
||||
* "is_expiry_notified": "0",
|
||||
* "acceptance_firstname": null,
|
||||
* "acceptance_lastname": null,
|
||||
* "acceptance_email": null,
|
||||
* "acceptance_date": null,
|
||||
* "acceptance_ip": null,
|
||||
* "signature": null,
|
||||
* "short_link": null,
|
||||
* "symbol": "$",
|
||||
* "name": "USD",
|
||||
* "decimal_separator": ".",
|
||||
* "thousand_separator": ",",
|
||||
* "placement": "before",
|
||||
* "isdefault": "1",
|
||||
* "customfields": [
|
||||
* {
|
||||
* "label": "Custom Field",
|
||||
* "value": "Custom Field value"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No Data Were Found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '') {
|
||||
$data = $this->Api_model->search('proposals', $key);
|
||||
// Check if the data store contains
|
||||
if ($data) {
|
||||
$data = $this->Api_model->get_api_custom_data($data, "proposal");
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/proposals/:id Delete Proposal
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName DeleteProposal
|
||||
* @apiGroup Proposals
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {Number} id Proposal unique ID.
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Proposals Deleted Successfully
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Proposals Deleted Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Proposals Delete Fail
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Proposal Delete Fail"
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '') {
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Proposal ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('proposals_model');
|
||||
$is_exist = $this->proposals_model->get($id);
|
||||
if (is_object($is_exist)) {
|
||||
$output = $this->proposals_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array('status' => TRUE, 'message' => 'Proposal Deleted Successfully');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Proposal Delete Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Proposal ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/proposals Add New Proposals
|
||||
* @apiName PostProposals
|
||||
* @apiVersion 0.3.0
|
||||
* @apiGroup Proposals
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} subject Mandatory. Proposal Subject Name.
|
||||
* @apiParam {string="lead","customer"} Related Mandatory. Proposal Related.
|
||||
* @apiParam {Number} rel_id Mandatory. Related ID.
|
||||
* @apiParam {string} proposal_to Mandatory. Lead / Customer name.
|
||||
* @apiParam {Date} date Mandatory. Proposal Start Date.
|
||||
* @apiParam {Date} open_till Optional. Proposal Open Till Date.
|
||||
* @apiParam {string} currency Mandatory. currency id.
|
||||
* @apiParam {string} discount_type Optional. Proposal Open Till Date.
|
||||
* @apiParam {string} status Optional. status id.
|
||||
* @apiParam {string} Assigned Optional. Assignee id.
|
||||
* @apiParam {string} Email Mandatory. Email id.
|
||||
* @apiParam {Array} newitems Mandatory. New Items to be added.
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* [
|
||||
* "subject" => proposal subject
|
||||
* "rel_type" => customer
|
||||
* "rel_id" => 1
|
||||
* "proposal_to" => John Doe
|
||||
* "email" => customer@mail.com
|
||||
* "date" => 2021-08-19
|
||||
* "newitems[0][description]" => item 1 description
|
||||
* "newitems[0][long_description]" => item 1 long description
|
||||
* "newitems[0][qty]" => 1
|
||||
* "newitems[0][rate]" => 1200
|
||||
* "newitems[0][order]" => 1
|
||||
* "newitems[0][unit]" => 1
|
||||
* "newitems[0][unit]" => 1
|
||||
* "newitems[0][custom_fields][items][1]" => custom field item
|
||||
* "subtotal" => 1200.00
|
||||
* "total" => 1200.00
|
||||
* "currency" => 1
|
||||
* "date" => 2021-08-19
|
||||
* "status" => 6
|
||||
* "custom_fields"[proposal][1] => test
|
||||
* ....
|
||||
*]
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Proposal add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Proposal add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Proposal add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Proposal add fail."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post() {
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
error_reporting(0);
|
||||
$data = $this->input->post();
|
||||
|
||||
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|max_length[191]');
|
||||
$this->form_validation->set_rules('rel_type', 'Rel Type', 'trim|required|in_list[lead,customer]');
|
||||
$this->form_validation->set_rules('rel_id', 'Rel Id', 'trim|required|greater_than[0]');
|
||||
$this->form_validation->set_rules('proposal_to', 'Proposal to', 'trim|required|max_length[191]');
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|valid_email|required|max_length[150]');
|
||||
$this->form_validation->set_rules('newitems[]', 'Items', 'required');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('date', 'date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('status', 'Status', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('subtotal', 'Sub Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('total', 'Total', 'trim|required|decimal|greater_than[0]');
|
||||
$data['address'] = $data['address']??"";
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('proposals_model');
|
||||
$data['open_till'] = _d(date('Y-m-d', strtotime('+' . get_option('proposal_due_after') . ' DAY', strtotime(date('Y-m-d')))));
|
||||
$id = $this->proposals_model->add($data);
|
||||
if ($id > 0 && !empty($id)) {
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Proposal Added Successfully',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Proposal Add Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/proposal/:id Update a proposal
|
||||
* @apiVersion 0.3.0
|
||||
* @apiName PutProposal
|
||||
* @apiGroup Proposals
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} subject Mandatory. Proposal Subject Name.
|
||||
* @apiParam {string="lead","customer"} Mandatory. Proposal Related.
|
||||
* @apiParam {Number} rel_id Mandatory. Related ID.
|
||||
* @apiParam {string} proposal_to Mandatory. Lead / Customer name.
|
||||
* @apiParam {Date} date Mandatory. Proposal Start Date.
|
||||
* @apiParam {Date} open_till Optional. Proposal Open Till Date.
|
||||
* @apiParam {string} currency Mandatory. currency id.
|
||||
* @apiParam {string} discount_type Optional. Proposal Open Till Date.
|
||||
* @apiParam {string} status Optional. status id.
|
||||
* @apiParam {string} Assigned Optional. Assignee id.
|
||||
* @apiParam {string} Email Mandatory. Email id.
|
||||
* @apiParam {Array} newitems Mandatory. New Items to be added.
|
||||
* @apiParam {Array} items Optional. Existing items with Id
|
||||
* @apiParam {Array} removed_items Optional. Items to be removed
|
||||
*
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "subject": "Test",
|
||||
* "rel_type": "customer",
|
||||
* "rel_id": 1,
|
||||
* "proposal_to": "Trueline 1",
|
||||
* "email": "test@mail.com",
|
||||
* "date": "2021-08-19",
|
||||
* "currency": 1,
|
||||
* "status": 6,
|
||||
* "items": {
|
||||
* "1": {
|
||||
* "itemid": "23",
|
||||
* "order": "1",
|
||||
* "description": "item description",
|
||||
* "long_description": "item long description",
|
||||
* "qty": "1",
|
||||
* "unit": "1",
|
||||
* "rate": "10.00",
|
||||
* "custom_fields":{
|
||||
* "items":{
|
||||
* "31":"test 12 item 1",
|
||||
* "32":"10",
|
||||
* "33":"Lorem Ipsum is simply dummy text of the printing and typesetting industry",*
|
||||
* "34":"Opti*on 1",*
|
||||
* "35":["Option 1","Option 2"],*
|
||||
* "36":["Option 1","Option 3"],
|
||||
* "37":"2021-05-06",
|
||||
* "38":"2021-05-06 00:23:25",
|
||||
* "39":"#ffffff",
|
||||
* "40":"<a href=\"url.com\" target=\"_blank\">Link</a>"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* },
|
||||
* "newitems": {
|
||||
* "2": {
|
||||
* "order": "2",
|
||||
* "description": "updated item 2 description",
|
||||
* "long_description": "updated item 2 logn description",
|
||||
* "qty": "1",
|
||||
* "unit": "",
|
||||
* "rate": "100.00",
|
||||
* "custom_fields":{
|
||||
* "items":{
|
||||
* "31":"test 12 item 2",
|
||||
* "32":"10",
|
||||
* "33":"Lorem Ipsum is simply dummy text of the printing and typesetting industry",
|
||||
* "34":"Option 1",
|
||||
* "35":["Option 1","Option 2"],
|
||||
* "36":["Option 1","Option 3"],
|
||||
* "37":"2021-05-06",
|
||||
* "38":"2021-05-06 00:23:25",
|
||||
* "39":"#ffffff",
|
||||
* "40":"<a href=\"url.com\" target=\"_blank\">Link</a>"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* },
|
||||
* "custom_fields":{
|
||||
* "proposal":{
|
||||
* "91":"test 12"
|
||||
* }
|
||||
* },
|
||||
* "subtotal":"110.00",
|
||||
* "total":"110.00"
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Proposal Updated Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Proposal Update Fail"
|
||||
* }
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function data_put($id = "") {
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Proposal ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|max_length[191]');
|
||||
$this->form_validation->set_rules('rel_type', 'Rel Type', 'trim|required|in_list[lead,customer]');
|
||||
$this->form_validation->set_rules('rel_id', 'Rel Id', 'trim|required|greater_than[0]');
|
||||
$this->form_validation->set_rules('proposal_to', 'Proposal to', 'trim|required|max_length[191]');
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|valid_email|required|max_length[150]');
|
||||
$this->form_validation->set_rules('items[]', 'Items', 'required');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('status', 'Status', 'trim|required|numeric|greater_than[0]');
|
||||
$this->form_validation->set_rules('date', 'date', 'trim|required|max_length[255]');
|
||||
$this->form_validation->set_rules('subtotal', 'Sub Total', 'trim|required|decimal|greater_than[0]');
|
||||
$this->form_validation->set_rules('total', 'Total', 'trim|required|decimal|greater_than[0]');
|
||||
$_POST['address'] = $_POST['address']??"";
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
} else {
|
||||
$this->load->model('proposals_model');
|
||||
$is_exist = $this->proposals_model->get($id);
|
||||
if (!is_object($is_exist)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Proposal ID Doesn\'t Not Exist.');
|
||||
$this->response($message, REST_Controller::HTTP_CONFLICT);
|
||||
}
|
||||
if (is_object($is_exist)) {
|
||||
$data = $this->input->post();
|
||||
$data['isedit'] = "";
|
||||
$success = $this->proposals_model->update($data, $id);
|
||||
if ($success == true) {
|
||||
$message = array('status' => TRUE, 'message' => "Proposal Updated Successfully",);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array('status' => FALSE, 'message' => 'Proposal Update Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Proposal ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2171
api/controllers/REST_Controller.php
Normal file
2171
api/controllers/REST_Controller.php
Normal file
File diff suppressed because it is too large
Load Diff
147
api/controllers/Reporting.php
Normal file
147
api/controllers/Reporting.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Reporting extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('api_metrics_model');
|
||||
$this->load->model('api_model');
|
||||
}
|
||||
|
||||
/**
|
||||
* Main reporting dashboard
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = _l('api_reporting');
|
||||
$data['api_keys'] = $this->api_model->get_all_api_keys();
|
||||
|
||||
// Get default date range (last 30 days)
|
||||
$end_date = date('Y-m-d');
|
||||
$start_date = date('Y-m-d', strtotime('-30 days'));
|
||||
|
||||
$data['start_date'] = $this->input->get('start_date') ?: $start_date;
|
||||
$data['end_date'] = $this->input->get('end_date') ?: $end_date;
|
||||
$data['api_key'] = $this->input->get('api_key') ?: '';
|
||||
|
||||
// Get usage statistics
|
||||
$data['usage_stats'] = $this->api_metrics_model->get_usage_stats(
|
||||
$data['api_key'] ?: null,
|
||||
$data['start_date'],
|
||||
$data['end_date']
|
||||
);
|
||||
|
||||
// Get endpoint statistics
|
||||
$data['endpoint_stats'] = $this->api_metrics_model->get_endpoint_stats(
|
||||
$data['api_key'] ?: null,
|
||||
$data['start_date'],
|
||||
$data['end_date']
|
||||
);
|
||||
|
||||
// Get hourly usage for charts
|
||||
$data['hourly_usage'] = $this->api_metrics_model->get_hourly_usage(
|
||||
$data['api_key'] ?: null,
|
||||
$data['start_date'],
|
||||
$data['end_date']
|
||||
);
|
||||
|
||||
// Get response code distribution
|
||||
$data['response_codes'] = $this->api_metrics_model->get_response_code_distribution(
|
||||
$data['api_key'] ?: null,
|
||||
$data['start_date'],
|
||||
$data['end_date']
|
||||
);
|
||||
|
||||
// Get API key summary
|
||||
$data['api_key_summary'] = $this->api_metrics_model->get_api_key_summary(
|
||||
$data['start_date'],
|
||||
$data['end_date']
|
||||
);
|
||||
|
||||
$this->load->view('api_reporting', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get chart data via AJAX
|
||||
*/
|
||||
public function get_chart_data()
|
||||
{
|
||||
$chart_type = $this->input->get('chart_type');
|
||||
$api_key = $this->input->get('api_key') ?: null;
|
||||
$start_date = $this->input->get('start_date');
|
||||
$end_date = $this->input->get('end_date');
|
||||
|
||||
$data = [];
|
||||
|
||||
switch ($chart_type) {
|
||||
case 'hourly_usage':
|
||||
$data = $this->api_metrics_model->get_hourly_usage($api_key, $start_date, $end_date);
|
||||
break;
|
||||
case 'daily_usage':
|
||||
$data = $this->api_metrics_model->get_daily_usage($api_key, $start_date, $end_date);
|
||||
break;
|
||||
case 'response_codes':
|
||||
$data = $this->api_metrics_model->get_response_code_distribution($api_key, $start_date, $end_date);
|
||||
break;
|
||||
case 'endpoint_stats':
|
||||
$data = $this->api_metrics_model->get_endpoint_stats($api_key, $start_date, $end_date);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Export usage data
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$api_key = $this->input->get('api_key') ?: null;
|
||||
$start_date = $this->input->get('start_date');
|
||||
$end_date = $this->input->get('end_date');
|
||||
$format = $this->input->get('format') ?: 'csv';
|
||||
|
||||
$this->load->library('excel');
|
||||
|
||||
$data = $this->api_metrics_model->get_api_key_summary($start_date, $end_date);
|
||||
|
||||
$excel = new PHPExcel();
|
||||
$excel->getProperties()->setTitle('API Usage Report');
|
||||
|
||||
$sheet = $excel->getActiveSheet();
|
||||
$sheet->setTitle('API Usage Summary');
|
||||
|
||||
// Headers
|
||||
$headers = ['API Key', 'Total Requests', 'Avg Response Time', 'Success Requests', 'Error Requests'];
|
||||
$col = 'A';
|
||||
foreach ($headers as $header) {
|
||||
$sheet->setCellValue($col . '1', $header);
|
||||
$col++;
|
||||
}
|
||||
|
||||
// Data
|
||||
$row = 2;
|
||||
foreach ($data as $item) {
|
||||
$sheet->setCellValue('A' . $row, $item->api_key);
|
||||
$sheet->setCellValue('B' . $row, $item->total_requests);
|
||||
$sheet->setCellValue('C' . $row, round($item->avg_response_time, 4));
|
||||
$sheet->setCellValue('D' . $row, $item->success_requests);
|
||||
$sheet->setCellValue('E' . $row, $item->error_requests);
|
||||
$row++;
|
||||
}
|
||||
|
||||
$filename = 'api_usage_report_' . date('Y-m-d_H-i-s') . '.xlsx';
|
||||
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
header('Cache-Control: max-age=0');
|
||||
|
||||
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
|
||||
$writer->save('php://output');
|
||||
}
|
||||
}
|
||||
477
api/controllers/Staffs.php
Normal file
477
api/controllers/Staffs.php
Normal file
@@ -0,0 +1,477 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__.'/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Staffs extends REST_Controller {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
$this->load->model('Api_model');
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/staffs/:id Request Staff information
|
||||
* @apiName GetStaff
|
||||
* @apiGroup Staffs
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Staff unique ID.
|
||||
*
|
||||
* @apiSuccess {Object} Staff information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "staffid": "8",
|
||||
* "email": "data1.gsts@gmail.com",
|
||||
* "firstname": "Đào Quang Dân",
|
||||
* "lastname": "",
|
||||
* "facebook": "",
|
||||
* "linkedin": "",
|
||||
* "phonenumber": "",
|
||||
* "skype": "",
|
||||
* "password": "$2a$08$ySLokLAM.AqmW9ZjY2YREO0CIrd5K4Td\/Bpfp8d9QJamWNUfreQuK",
|
||||
* "datecreated": "2019-02-25 09:11:31",
|
||||
* "profile_image": "8.png",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError StaffNotFound The id of the Staff was not found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '')
|
||||
{
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('staffs', $id);
|
||||
|
||||
// Check if the data store contains
|
||||
if ($data)
|
||||
{
|
||||
$data = $this->Api_model->get_api_custom_data($data,"staff", $id);
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/staffs/search/:keysearch Search Staff Information
|
||||
* @apiName GetStaffSearch
|
||||
* @apiGroup Staffs
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Staff information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "staffid": "8",
|
||||
* "email": "data1.gsts@gmail.com",
|
||||
* "firstname": "Đào Quang Dân",
|
||||
* "lastname": "",
|
||||
* "facebook": "",
|
||||
* "linkedin": "",
|
||||
* "phonenumber": "",
|
||||
* "skype": "",
|
||||
* "password": "$2a$08$ySLokLAM.AqmW9ZjY2YREO0CIrd5K4Td\/Bpfp8d9QJamWNUfreQuK",
|
||||
* "datecreated": "2019-02-25 09:11:31",
|
||||
* "profile_image": "8.png",
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError StaffNotFound The id of the Staff was not found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '')
|
||||
{
|
||||
$data = $this->Api_model->search('staff', $key);
|
||||
// Check if the data store contains
|
||||
if ($data)
|
||||
{
|
||||
$data = $this->Api_model->get_api_custom_data($data,"staff");
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/staffs Add New Staff
|
||||
* @apiName PostStaffs
|
||||
* @apiGroup Staffs
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} firstname Mandatory Staff Name.
|
||||
* @apiParam {String} email Mandatory Staff Related.
|
||||
* @apiParam {String} password Mandatory Staff password.
|
||||
* @apiParam {Number} [hourly_rate] Optional hourly rate.
|
||||
* @apiParam {String} [phonenumber] Optional Staff phonenumber.
|
||||
* @apiParam {String} [facebook] Optional Staff facebook.
|
||||
* @apiParam {String} [linkedin] Optional Staff linkedin.
|
||||
* @apiParam {String} [skype] Optional Staff skype.
|
||||
* @apiParam {String} [default_language] Optional Staff default language.
|
||||
* @apiParam {String} [email_signature] Optional Staff email signature.
|
||||
* @apiParam {String} [direction] Optional Staff direction.
|
||||
* @apiParam {String} [send_welcome_email] Optional Staff send welcome email.
|
||||
* @apiParam {Number[]} [departments] Optional Staff departments.
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* array (size=15)
|
||||
* 'firstname' => string '4' (length=1)
|
||||
* 'email' => string 'a@gmail.com' (length=11)
|
||||
* 'hourly_rate' => string '0' (length=1)
|
||||
* 'phonenumber' => string '' (length=0)
|
||||
* 'facebook' => string '' (length=0)
|
||||
* 'linkedin' => string '' (length=0)
|
||||
* 'skype' => string '' (length=0)
|
||||
* 'default_language' => string '' (length=0)
|
||||
* 'email_signature' => string '' (length=0)
|
||||
* 'direction' => string '' (length=0)
|
||||
* 'departments' =>
|
||||
* array (size=5)
|
||||
* 0 => string '1' (length=1)
|
||||
* 1 => string '2' (length=1)
|
||||
* 2 => string '3' (length=1)
|
||||
* 3 => string '4' (length=1)
|
||||
* 4 => string '5' (length=1)
|
||||
* 'send_welcome_email' => string 'on' (length=2)
|
||||
* 'fakeusernameremembered' => string '' (length=0)
|
||||
* 'fakepasswordremembered' => string '' (length=0)
|
||||
* 'password' => string '1' (length=1)
|
||||
* 'role' => string '18' (length=2)
|
||||
*
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Staff add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Staff add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Staff add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Staff add fail."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post()
|
||||
{
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
// form validation
|
||||
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|max_length[600]', array('is_unique' => 'This %s already exists please enter another Staff First Name'));
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email', array('is_unique' => 'This %s already exists please enter another Staff Email'));
|
||||
$this->form_validation->set_rules('password', 'Password', 'trim|required', array('is_unique' => 'This %s already exists please enter another Staff password'));
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
// form validation error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'error' => $this->form_validation->error_array(),
|
||||
'message' => validation_errors()
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
$departments = $this->Api_model->value($this->input->post('departments', TRUE));
|
||||
$insert_data = [
|
||||
'firstname' => $this->input->post('firstname', TRUE),
|
||||
'email' => $this->input->post('email', TRUE),
|
||||
'password' => $this->input->post('password', TRUE),
|
||||
'lastname' => '',
|
||||
'hourly_rate' => $this->Api_model->value($this->input->post('hourly_rate', TRUE)),
|
||||
'phonenumber' => $this->Api_model->value($this->input->post('phonenumber', TRUE)),
|
||||
'facebook' => $this->Api_model->value($this->input->post('facebook', TRUE)),
|
||||
'linkedin' => $this->Api_model->value($this->input->post('linkedin', TRUE)),
|
||||
'skype' => $this->Api_model->value($this->input->post('skype', TRUE)),
|
||||
'default_language' => $this->Api_model->value($this->input->post('default_language', TRUE)),
|
||||
'email_signature' => $this->Api_model->value($this->input->post('email_signature', TRUE)),
|
||||
'direction' => $this->Api_model->value($this->input->post('direction', TRUE)),
|
||||
'send_welcome_email' => $this->Api_model->value($this->input->post('send_welcome_email', TRUE)),
|
||||
'role' => '1',
|
||||
'permissions' => array(
|
||||
'bulk_pdf_exporter' => array('view'),
|
||||
'contracts' => array('create','edit','delete'),
|
||||
'credit_notes' => array('create','edit','delete'),
|
||||
'customers' => array('view','create','edit','delete'),
|
||||
'email_templates' => array('view','edit'),
|
||||
'estimates' => array('create','edit','delete'),
|
||||
'expenses' => array('create','edit','delete'),
|
||||
'invoices' => array('create','edit','delete'),
|
||||
'items' => array('view','create','edit','delete'),
|
||||
'knowledge_base' => array('view','create','edit','delete'),
|
||||
'payments' => array('view','create','edit','delete'),
|
||||
'projects' => array('view','create','edit','delete'),
|
||||
'proposals' => array('create','edit','delete'),
|
||||
'contracts' => array('view'),
|
||||
'roles' => array('view','create','edit','delete'),
|
||||
'settings' => array('view','edit'),
|
||||
'staff' => array('view','create','edit','delete'),
|
||||
'subscriptions' => array('create','edit','delete'),
|
||||
'tasks' => array('view','create','edit','delete'),
|
||||
'checklist_templates' => array('create','delete'),
|
||||
'leads' => array('view','delete'),
|
||||
'goals' => array('view','create','edit','delete'),
|
||||
'surveys' => array('view','create','edit','delete'),
|
||||
)
|
||||
];
|
||||
if($departments != ''){
|
||||
$insert_data['departments'] = $departments;
|
||||
}
|
||||
if (!empty($this->input->post('custom_fields', TRUE))) {
|
||||
$insert_data['custom_fields'] = $this->Api_model->value($this->input->post('custom_fields', TRUE));
|
||||
}
|
||||
// insert data
|
||||
$this->load->model('staff_model');
|
||||
$output = $this->staff_model->add($insert_data);
|
||||
if($output > 0 && !empty($output)){
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Staff add successful.',
|
||||
'record_id' => $output // επιστρέφουμε το ID του νέου staff
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Staff add fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @api {delete} api/delete/staffs/:id Delete a Staff
|
||||
* @apiName DeleteStaff
|
||||
* @apiGroup Staffs
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Staff unique ID.
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Staff registration successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Staff Delete."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Not register your accout.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Staff Not Delete."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id)
|
||||
{
|
||||
$id = $this->security->xss_clean($id);
|
||||
if(empty($id) && !is_numeric($id))
|
||||
{
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid Staff ID'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete data
|
||||
$this->load->model('staff_model');
|
||||
$output = $this->staff_model->delete($id, 0);
|
||||
if($output === TRUE){
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Staff Delete Successful.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}else{
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Staff Delete Fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @api {put} api/staffs/:id Update a Staff
|
||||
* @apiName PutStaff
|
||||
* @apiGroup Staffs
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} firstname Mandatory Staff Name.
|
||||
* @apiParam {String} email Mandatory Staff Related.
|
||||
* @apiParam {String} password Mandatory Staff password.
|
||||
* @apiParam {Number} [hourly_rate] Optional hourly rate.
|
||||
* @apiParam {String} [phonenumber] Optional Staff phonenumber.
|
||||
* @apiParam {String} [facebook] Optional Staff facebook.
|
||||
* @apiParam {String} [linkedin] Optional Staff linkedin.
|
||||
* @apiParam {String} [skype] Optional Staff skype.
|
||||
* @apiParam {String} [default_language] Optional Staff default language.
|
||||
* @apiParam {String} [email_signature] Optional Staff email signature.
|
||||
* @apiParam {String} [direction] Optional Staff direction.
|
||||
* @apiParam {Number[]} [departments] Optional Staff departments.
|
||||
*
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "firstname": "firstname",
|
||||
* "email": "aa454@gmail.com",
|
||||
* "hourly_rate": "0.00",
|
||||
* "phonenumber": "",
|
||||
* "facebook": "",
|
||||
* "linkedin": "",
|
||||
* "skype": "",
|
||||
* "default_language": "",
|
||||
* "email_signature": "",
|
||||
* "direction": "",
|
||||
* "departments": {
|
||||
* "0": "1",
|
||||
* "1": "2"
|
||||
* },
|
||||
* "password": "123456"
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Staff Update Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Staff Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Staff Update Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Staff Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id)
|
||||
{
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if(empty($_POST ) || !isset($_POST ))
|
||||
{
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Data Not Acceptable OR Not Provided'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
if(empty($id) && !is_numeric($id))
|
||||
{
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid Staff ID'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$update_data = $this->input->post();
|
||||
$update_data['lastname'] = '';
|
||||
// update data
|
||||
$this->load->model('staff_model');
|
||||
$output = $this->staff_model->update($update_data, $id);
|
||||
|
||||
if($output > 0 && !empty($output)){
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Staff Update Successful.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}else{
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Staff Update Fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
356
api/controllers/Subscriptions.php
Normal file
356
api/controllers/Subscriptions.php
Normal file
@@ -0,0 +1,356 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
class Subscriptions extends REST_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/subscriptions/ Request all Subscriptions
|
||||
* @apiName Request Subscriptions
|
||||
* @apiGroup Subscriptions
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiSuccess {Object} Data Information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* 'name' => varchar 'New subscription'
|
||||
* 'description' => text 'This is a detailed description of subscription'
|
||||
* 'description_in_item' => tinyint '1'
|
||||
* 'clientid' => int '123'
|
||||
* 'date' => date '2024-01-31'
|
||||
* 'terms' => text 'subscription payment is due'
|
||||
* 'currency ' => int '4'
|
||||
* 'tax_id ' => int '456'
|
||||
* 'stripe_tax_id_2' => varchar 'tax-789'
|
||||
* 'stripe_plan_id' => text 'subscription_ABC'
|
||||
* 'stripe_subscription_id' => text 'subscription_ABC'
|
||||
* 'tax_id_2': int '12',
|
||||
* 'stripe_subscription_id' => text 'sub_123456789'
|
||||
* 'next_billing_cycle' => bigint '1643808000'
|
||||
* 'ends_at' => bigint '1646486400'
|
||||
* 'status' => varchar 'active'
|
||||
* 'quantity' => int '5'
|
||||
* 'project_id' => int '789'
|
||||
* 'hash' => varchar 'a1b2c3'
|
||||
* 'created' => datetime '2024-01-31 12:34:56'
|
||||
* 'created_from' => int '1'
|
||||
* 'date_subscribed' => datetime '2024-01-31 10:00:00'
|
||||
* 'in_test_environment' => int '1'
|
||||
* 'last_sent_at' => datetime '2024-01-31 14:45:00'
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError DataNotFound The id of the data was not found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {get} api/subscriptions/:id Request Subscription Information
|
||||
* @apiName Request Subscription Information
|
||||
* @apiGroup Subscriptions
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {id} id Data id ID.
|
||||
*
|
||||
* @apiSuccess {Object} Data Information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* 'name' => varchar 'New subscription'
|
||||
* 'description' => text 'This is a detailed description of subscription'
|
||||
* 'description_in_item' => tinyint '1'
|
||||
* 'clientid' => int '123'
|
||||
* 'date' => date '2024-01-31'
|
||||
* 'terms' => text 'subscription payment is due'
|
||||
* 'currency ' => int '4'
|
||||
* 'tax_id ' => int '456'
|
||||
* 'stripe_tax_id_2' => varchar 'tax-789'
|
||||
* 'stripe_plan_id' => text 'subscription_ABC'
|
||||
* 'stripe_subscription_id' => text 'subscription_ABC'
|
||||
* 'tax_id_2': int '12',
|
||||
* 'stripe_subscription_id' => text 'sub_123456789'
|
||||
* 'next_billing_cycle' => bigint '1643808000'
|
||||
* 'ends_at' => bigint '1646486400'
|
||||
* 'status' => varchar 'active'
|
||||
* 'quantity' => int '5'
|
||||
* 'project_id' => int '789'
|
||||
* 'hash' => varchar 'a1b2c3'
|
||||
* 'created' => datetime '2024-01-31 12:34:56'
|
||||
* 'created_from' => int '1'
|
||||
* 'date_subscribed' => datetime '2024-01-31 10:00:00'
|
||||
* 'in_test_environment' => int '1'
|
||||
* 'last_sent_at' => datetime '2024-01-31 14:45:00'
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError DataNotFound The id of the data was not found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
|
||||
public function data_get($id = '')
|
||||
{
|
||||
$data = $this->Api_model->get_table('subscriptions', $id);
|
||||
|
||||
if ($data) {
|
||||
$this->response($data, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/subscriptions/ Add New Subscription
|
||||
* @apiName AddNewSubscription
|
||||
* @apiGroup Subscriptions
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {String} name New subscription name.
|
||||
* @apiParam {Text} description Detailed description of the subscription.
|
||||
* @apiParam {TinyInt} description_in_item Indicates if the description is included in the item (1 or 0).
|
||||
* @apiParam {Int} clientid Client ID.
|
||||
* @apiParam {Date} date Subscription start date (YYYY-MM-DD).
|
||||
* @apiParam {Text} terms Subscription terms.
|
||||
* @apiParam {Int} currency Currency ID.
|
||||
* @apiParam {Int} tax_id Tax ID.
|
||||
* @apiParam {Varchar} stripe_tax_id_2 Stripe tax ID.
|
||||
* @apiParam {Text} stripe_plan_id Stripe plan ID.
|
||||
* @apiParam {Text} stripe_subscription_id Stripe Subscription ID.
|
||||
* @apiParam {Int} tax_id_2 Second tax ID.
|
||||
* @apiParam {Varchar} stripe_subscription_id Stripe subscription ID.
|
||||
* @apiParam {BigInt} next_billing_cycle Next billing cycle timestamp.
|
||||
* @apiParam {BigInt} ends_at Subscription end timestamp.
|
||||
* @apiParam {Varchar} status Subscription status (e.g., active).
|
||||
* @apiParam {Int} quantity Subscription quantity.
|
||||
* @apiParam {Int} project_id Associated project ID.
|
||||
* @apiParam {Varchar} hash Unique hash identifier.
|
||||
* @apiParam {DateTime} created Creation timestamp (YYYY-MM-DD HH:MM:SS).
|
||||
* @apiParam {Int} created_from ID of the creator.
|
||||
* @apiParam {DateTime} date_subscribed Subscription date (YYYY-MM-DD HH:MM:SS).
|
||||
* @apiParam {Int} in_test_environment Indicates if the subscription is in a test environment (1 or 0).
|
||||
* @apiParam {DateTime} last_sent_at Last sent timestamp (YYYY-MM-DD HH:MM:SS).
|
||||
*
|
||||
* @apiParamExample {multipart/form-data} Request Example:
|
||||
* {
|
||||
* "name": "New subscription",
|
||||
* "description": "This is a detailed description of subscription",
|
||||
* "description_in_item": 1,
|
||||
* "clientid": 123,
|
||||
* "date": "2024-01-31",
|
||||
* "terms": "subscription payment is due",
|
||||
* "currency": 4,
|
||||
* "tax_id": 456,
|
||||
* "stripe_tax_id_2": "tax-789",
|
||||
* "stripe_plan_id": "subscription_ABC",
|
||||
* "stripe_subscription_id": "subscription_ABC",
|
||||
* "tax_id_2": 12,
|
||||
* "stripe_subscription_id": "sub_123456789",
|
||||
* "next_billing_cycle": 1643808000,
|
||||
* "ends_at": 1646486400,
|
||||
* "status": "active",
|
||||
* "quantity": 5,
|
||||
* "project_id": 789,
|
||||
* "hash": "a1b2c3",
|
||||
* "created": "2024-01-31 12:34:56",
|
||||
* "created_from": 1,
|
||||
* "date_subscribed": "2024-01-31 10:00:00",
|
||||
* "in_test_environment": 1,
|
||||
* "last_sent_at": "2024-01-31 14:45:00"
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Success message.
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Data Added Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError DataNotAdded Data could not be added.
|
||||
*
|
||||
* @apiErrorExample {json} Error-Response:
|
||||
* HTTP/1.1 400 Bad Request
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": "Data not Added"
|
||||
* }
|
||||
*/
|
||||
|
||||
public function data_post()
|
||||
{
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
$data = $this->input->post();
|
||||
|
||||
$this->form_validation->set_rules('name', 'Subscription Name', 'trim|required');
|
||||
$this->form_validation->set_rules('quantity', 'Quantity', 'trim|required');
|
||||
$this->form_validation->set_rules('next_billing_cycle', ' Billing Plan', 'required');
|
||||
$this->form_validation->set_rules('currency', 'Currency', 'trim|required');
|
||||
$this->form_validation->set_rules('clientid', 'clientid', 'trim|required');
|
||||
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$id = $this->Api_model->subscription($data);
|
||||
|
||||
if ($id > 0 && !empty($id)) {
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Data Added Successfully',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Add Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/subscriptions/:id Update a Subscription
|
||||
* @apiName Update a Subscription
|
||||
* @apiParam {id} id ID for update data.
|
||||
* @apiGroup Subscriptions
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* 'name' => varchar 'New subscription updated'
|
||||
* 'description' => text 'This is a detailed description of subscription'
|
||||
* 'description_in_item' => tinyint '1'
|
||||
* 'clientid' => int '123'
|
||||
* 'date' => date '2024-01-31'
|
||||
* 'terms' => text 'subscription payment is due'
|
||||
* 'currency ' => int '4'
|
||||
* 'tax_id ' => int '456'
|
||||
* 'stripe_tax_id_2' => varchar 'tax-789'
|
||||
* 'stripe_plan_id' => text 'subscription_ABC'
|
||||
* 'stripe_subscription_id' => text 'subscription_ABC'
|
||||
* "tax_id_2": int '12',
|
||||
* 'stripe_subscription_id' => text 'sub_123456789'
|
||||
* 'next_billing_cycle' => bigint '1643808000'
|
||||
* 'ends_at' => bigint '1646486400'
|
||||
* 'status' => varchar 'active'
|
||||
* 'quantity' => int '5'
|
||||
* 'project_id' => int '789'
|
||||
* 'hash' => varchar 'a1b2c3'
|
||||
* 'created' => datetime '2024-01-31 12:34:56'
|
||||
* 'created_from' => int '1'
|
||||
* 'date_subscribed' => datetime '2024-01-31 10:00:00'
|
||||
* 'in_test_environment' => int '1'
|
||||
* 'last_sent_at' => datetime '2024-01-31 14:45:00'
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Data Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Data Not Acceptable OR Not Provided"
|
||||
* }
|
||||
*
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Data Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '')
|
||||
{
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid data or missing Send ID. please provide updated data ID.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$_POST['id'] = $id;
|
||||
$update_data = $this->input->post();
|
||||
$data = $_POST;
|
||||
$output = $this->Api_model->subscriptions($data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
$message = array('status' => TRUE, 'message' => 'Data Update Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Update Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/subscriptions/:id Delete a Subscription
|
||||
* @apiName Delete a Subscription
|
||||
* @apiGroup Subscriptions
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {id} id ID for data Deletion.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Delete Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError DataNotAdded.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Delete Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '')
|
||||
{
|
||||
$id = $this->security->xss_clean($id);
|
||||
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('api_model');
|
||||
$output = $this->api_model->delete_subscription($id);
|
||||
|
||||
if ($output === TRUE) {
|
||||
$message = array('status' => TRUE, 'message' => 'Delete Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Delete Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
api/controllers/Swagger.php
Normal file
25
api/controllers/Swagger.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Swagger extends CI_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->library('app_modules');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$data['title'] = 'Api Guide';
|
||||
$this->load->view('playground', $data);
|
||||
}
|
||||
|
||||
public function json()
|
||||
{
|
||||
return REST_Controller::get_swagger_file();
|
||||
}
|
||||
}
|
||||
505
api/controllers/Tasks.php
Normal file
505
api/controllers/Tasks.php
Normal file
@@ -0,0 +1,505 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__.'/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Tasks extends REST_Controller {
|
||||
function __construct()
|
||||
{
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/tasks/:id Request Task information
|
||||
* @apiName GetTask
|
||||
* @apiGroup Tasks
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Task unique ID.
|
||||
*
|
||||
* @apiSuccess {Object} Tasks information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "10",
|
||||
* "name": "This is a task",
|
||||
* "description": "",
|
||||
* "priority": "2",
|
||||
* "dateadded": "2019-02-25 12:26:37",
|
||||
* "startdate": "2019-01-02 00:00:00",
|
||||
* "duedate": "2019-01-04 00:00:00",
|
||||
* "datefinished": null,
|
||||
* "addedfrom": "9",
|
||||
* "is_added_from_contact": "0",
|
||||
* "status": "4",
|
||||
* "recurring_type": null,
|
||||
* "repeat_every": "0",
|
||||
* "recurring": "0",
|
||||
* "is_recurring_from": null,
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '')
|
||||
{
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->get_table('tasks', $id);
|
||||
|
||||
// Check if the data store contains
|
||||
if ($data)
|
||||
{
|
||||
$data = $this->Api_model->get_api_custom_data($data, "tasks", $id);
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/tasks/search/:keysearch Search Tasks Information
|
||||
* @apiName GetTaskSearch
|
||||
* @apiGroup Tasks
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search Keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Tasks information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "10",
|
||||
* "name": "This is a task",
|
||||
* "description": "",
|
||||
* "priority": "2",
|
||||
* "dateadded": "2019-02-25 12:26:37",
|
||||
* "startdate": "2019-01-02 00:00:00",
|
||||
* "duedate": "2019-01-04 00:00:00",
|
||||
* "datefinished": null,
|
||||
* "addedfrom": "9",
|
||||
* "is_added_from_contact": "0",
|
||||
* "status": "4",
|
||||
* "recurring_type": null,
|
||||
* "repeat_every": "0",
|
||||
* "recurring": "0",
|
||||
* "is_recurring_from": null,
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message No data were found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '')
|
||||
{
|
||||
// If the id parameter doesn't exist return all the
|
||||
$data = $this->Api_model->search('tasks', $key);
|
||||
|
||||
// Check if the data store contains
|
||||
if ($data)
|
||||
{
|
||||
usort($data, function($a, $b) {
|
||||
return $a['id'] - $b['id'];
|
||||
});
|
||||
$data = $this->Api_model->get_api_custom_data($data,"tasks");
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/tasks Add New Task
|
||||
* @apiName PostTask
|
||||
* @apiGroup Tasks
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} name Mandatory Task Name.
|
||||
* @apiParam {Date} startdate Mandatory Task Start Date.
|
||||
* @apiParam {String} [is_public] Optional Task public.
|
||||
* @apiParam {String} [billable] Optional Task billable.
|
||||
* @apiParam {String} [hourly_rate] Optional Task hourly rate.
|
||||
* @apiParam {String} [milestone] Optional Task milestone.
|
||||
* @apiParam {Date} [duedate] Optional Task deadline.
|
||||
* @apiParam {String} [priority] Optional Task priority.
|
||||
* @apiParam {String} [repeat_every] Optional Task repeat every.
|
||||
* @apiParam {Number} [repeat_every_custom] Optional Task repeat every custom.
|
||||
* @apiParam {String} [repeat_type_custom] Optional Task repeat type custom.
|
||||
* @apiParam {Number} [cycles] Optional cycles.
|
||||
* @apiParam {string="lead","customer","invoice", "project", "quotation", "contract", "annex", "ticket", "expense", "proposal"} rel_type Mandatory Task Related.
|
||||
* @apiParam {Number} rel_id Optional Related ID.
|
||||
* @apiParam {String} [tags] Optional Task tags.
|
||||
* @apiParam {String} [description] Optional Task description.
|
||||
*
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* array (size=15)
|
||||
* 'is_public' => string 'on' (length=2)
|
||||
* 'billable' => string 'on' (length=2)
|
||||
* 'name' => string 'Task 12' (length=7)
|
||||
* 'hourly_rate' => string '0' (length=1)
|
||||
* 'milestone' => string '' (length=0)
|
||||
* 'startdate' => string '17/07/2019' (length=10)
|
||||
* 'duedate' => string '31/07/2019 11:07' (length=16)
|
||||
* 'priority' => string '2' (length=1)
|
||||
* 'repeat_every' => string '' (length=0)
|
||||
* 'repeat_every_custom' => string '1' (length=1)
|
||||
* 'repeat_type_custom' => string 'day' (length=3)
|
||||
* 'rel_type' => string 'customer' (length=8)
|
||||
* 'rel_id' => string '9' (length=1)
|
||||
* 'tags' => string '' (length=0)
|
||||
* 'description' => string '<span>Task Description</span>' (length=29)
|
||||
*
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Task add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Task add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Task add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Task add fail."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post()
|
||||
{
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
// form validation
|
||||
$this->form_validation->set_rules('name', 'Task Name', 'trim|required|max_length[600]', array('is_unique' => 'This %s already exists please enter another Task Name'));
|
||||
$this->form_validation->set_rules('startdate', 'Task Start Date', 'trim|required', array('is_unique' => 'This %s already exists please enter another Task Start Date'));
|
||||
$this->form_validation->set_rules('is_public', 'Publicly available task', 'trim', array('is_unique' => 'Public state can be 1. Skip it completely to set it at non-public'));
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
// form validation error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'error' => $this->form_validation->error_array(),
|
||||
'message' => validation_errors()
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert_data = [
|
||||
'name' => $this->input->post('name', TRUE),
|
||||
'startdate' => $this->input->post('startdate', TRUE),
|
||||
'is_public' => $this->input->post('is_public', TRUE),
|
||||
'billable' => $this->Api_model->value($this->input->post('billable', TRUE)),
|
||||
'hourly_rate' => $this->Api_model->value($this->input->post('hourly_rate', TRUE)),
|
||||
'milestone' => $this->Api_model->value($this->input->post('milestone', TRUE)),
|
||||
'duedate' => $this->Api_model->value($this->input->post('duedate', TRUE)),
|
||||
'priority' => $this->Api_model->value($this->input->post('priority', TRUE)),
|
||||
'repeat_every' => $this->Api_model->value($this->input->post('repeat_every', TRUE)),
|
||||
'repeat_every_custom' => $this->Api_model->value($this->input->post('repeat_every_custom', TRUE)),
|
||||
'repeat_type_custom' => $this->Api_model->value($this->input->post('repeat_type_custom', TRUE)),
|
||||
'cycles' => $this->Api_model->value($this->input->post('cycles', TRUE)),
|
||||
'rel_type' => $this->Api_model->value($this->input->post('rel_type', TRUE)),
|
||||
'rel_id' => $this->Api_model->value($this->input->post('rel_id', TRUE)),
|
||||
'tags' => $this->Api_model->value($this->input->post('tags', TRUE)),
|
||||
'description' => $this->Api_model->value($this->input->post('description', TRUE))
|
||||
];
|
||||
|
||||
if (!empty($this->input->post('custom_fields', TRUE))) {
|
||||
$insert_data['custom_fields'] = $this->Api_model->value($this->input->post('custom_fields', TRUE));
|
||||
}
|
||||
// insert data
|
||||
$this->load->model('tasks_model');
|
||||
$output = $this->tasks_model->add($insert_data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$this->handle_task_attachments_array($output);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Task add successful.',
|
||||
'record_id' => $output // επιστρέφουμε το ID του νέου task
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Task add failed.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/delete/tasks/:id Delete a Task
|
||||
* @apiName DeleteTask
|
||||
* @apiGroup Tasks
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Task unique ID.
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Task Delete Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Task Delete Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Task Delete Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Task Delete Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '')
|
||||
{
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid Task ID'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
// delete data
|
||||
$this->load->model('tasks_model');
|
||||
$output = $this->tasks_model->delete_task($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Task Delete Successful.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Task Delete Fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/tasks/:id Update a task
|
||||
* @apiName PutTask
|
||||
* @apiGroup Tasks
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} name Mandatory Task Name.
|
||||
* @apiParam {Date} startdate Mandatory Task Start Date.
|
||||
* @apiParam {String} [is_public] Optional Task public.
|
||||
* @apiParam {String} [billable] Optional Task billable.
|
||||
* @apiParam {String} [hourly_rate] Optional Task hourly rate.
|
||||
* @apiParam {String} [milestone] Optional Task milestone.
|
||||
* @apiParam {Date} [duedate] Optional Task deadline.
|
||||
* @apiParam {String} [priority] Optional Task priority.
|
||||
* @apiParam {String} [repeat_every] Optional Task repeat every.
|
||||
* @apiParam {Number} [repeat_every_custom] Optional Task repeat every custom.
|
||||
* @apiParam {String} [repeat_type_custom] Optional Task repeat type custom.
|
||||
* @apiParam {Number} [cycles] Optional cycles.
|
||||
* @apiParam {string="lead","customer","invoice", "project", "quotation", "contract", "annex", "ticket", "expense", "proposal"} rel_type Mandatory Task Related.
|
||||
* @apiParam {Number} rel_id Optional Related ID.
|
||||
* @apiParam {String} [tags] Optional Task tags.
|
||||
* @apiParam {String} [description] Optional Task description.
|
||||
*
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "billable": "1",
|
||||
* "is_public": "1",
|
||||
* "name": "Task 1",
|
||||
* "hourly_rate": "0.00",
|
||||
* "milestone": "0",
|
||||
* "startdate": "27/08/2019",
|
||||
* "duedate": null,
|
||||
* "priority": "0",
|
||||
* "repeat_every": "",
|
||||
* "repeat_every_custom": "1",
|
||||
* "repeat_type_custom": "day",
|
||||
* "cycles": "0",
|
||||
* "rel_type": "lead",
|
||||
* "rel_id": "11",
|
||||
* "tags": "",
|
||||
* "description": ""
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {String} status Request status.
|
||||
* @apiSuccess {String} message Task Update Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Task Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {String} status Request status.
|
||||
* @apiError {String} message Task Update Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Task Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '')
|
||||
{
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$this->load->library('parse_input_stream');
|
||||
$_POST = $this->parse_input_stream->parse_parameters();
|
||||
$_FILES = $this->parse_input_stream->parse_files();
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Lead ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$update_data = $this->input->post();
|
||||
$update_file = isset($update_data['file']) ? $update_data['file'] : null;
|
||||
unset($update_data['file']);
|
||||
|
||||
// update data
|
||||
$this->load->model('tasks_model');
|
||||
$output = $this->tasks_model->update($update_data, $id);
|
||||
if (!empty($update_file) && count($update_file)) {
|
||||
if ($output <= 0 || empty($output)) {
|
||||
$output = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$attachments = $this->tasks_model->get_task_attachments($output);
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->tasks_model->remove_task_attachment($attachment['id']);
|
||||
}
|
||||
$this->handle_task_attachments_array($output);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Task Update Successful.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Task Update Fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handle_task_attachments_array($task_id, $index_name = 'file') {
|
||||
$path = get_upload_path_by_type('task') . $task_id . '/';
|
||||
$CI = & get_instance();
|
||||
if (isset($_FILES[$index_name]['name']) && ($_FILES[$index_name]['name'] != '' || is_array($_FILES[$index_name]['name']) && count($_FILES[$index_name]['name']) > 0)) {
|
||||
if (!is_array($_FILES[$index_name]['name'])) {
|
||||
$_FILES[$index_name]['name'] = [$_FILES[$index_name]['name']];
|
||||
$_FILES[$index_name]['type'] = [$_FILES[$index_name]['type']];
|
||||
$_FILES[$index_name]['tmp_name'] = [$_FILES[$index_name]['tmp_name']];
|
||||
$_FILES[$index_name]['error'] = [$_FILES[$index_name]['error']];
|
||||
$_FILES[$index_name]['size'] = [$_FILES[$index_name]['size']];
|
||||
}
|
||||
_file_attachments_index_fix($index_name);
|
||||
for ($i = 0; $i < count($_FILES[$index_name]['name']); $i++) {
|
||||
// Get the temp file path
|
||||
$tmpFilePath = $_FILES[$index_name]['tmp_name'][$i];
|
||||
// Make sure we have a filepath
|
||||
if (!empty($tmpFilePath) && $tmpFilePath != '') {
|
||||
if (_perfex_upload_error($_FILES[$index_name]['error'][$i]) || !_upload_extension_allowed($_FILES[$index_name]['name'][$i])) {
|
||||
continue;
|
||||
}
|
||||
_maybe_create_upload_path($path);
|
||||
$filename = unique_filename($path, $_FILES[$index_name]['name'][$i]);
|
||||
$newFilePath = $path . $filename;
|
||||
// Upload the file into the temp dir
|
||||
if (copy($tmpFilePath, $newFilePath)) {
|
||||
unlink($tmpFilePath);
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('tasks_model');
|
||||
$data = [];
|
||||
$data[] = ['file_name' => $filename, 'filetype' => $_FILES[$index_name]['type'][$i], ];
|
||||
$CI->tasks_model->add_attachment_to_database($task_id, $data, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
502
api/controllers/Tickets.php
Normal file
502
api/controllers/Tickets.php
Normal file
@@ -0,0 +1,502 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require __DIR__.'/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Tickets extends REST_Controller {
|
||||
function __construct()
|
||||
{
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/tickets/:id Request Ticket information
|
||||
* @apiName GetTicket
|
||||
* @apiGroup Tickets
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Ticket unique ID.
|
||||
*
|
||||
* @apiSuccess {Object} Ticket information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "id": "7",
|
||||
* "ticketid": "7",
|
||||
* "adminreplying": "0",
|
||||
* "userid": "0",
|
||||
* "contactid": "0",
|
||||
* "email": null,
|
||||
* "name": "Trung bình",
|
||||
* "department": "1",
|
||||
* "priority": "2",
|
||||
* "status": "1",
|
||||
* "service": "1",
|
||||
* "ticketkey": "8ef33d61bb0f26cd158d56cc18b71c02",
|
||||
* "subject": "Ticket ER",
|
||||
* "message": "Ticket ER",
|
||||
* "admin": "5",
|
||||
* "date": "2019-04-10 03:08:21",
|
||||
* "project_id": "5",
|
||||
* "lastreply": null,
|
||||
* "clientread": "0",
|
||||
* "adminread": "1",
|
||||
* "assigned": "5",
|
||||
* "line_manager": "8",
|
||||
* "milestone": "27",
|
||||
* ...
|
||||
* }
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message The id of the Ticket was not found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '')
|
||||
{
|
||||
// If the id parameter doesn't exist, return all the tickets
|
||||
$data = $this->Api_model->get_table('tickets', $id);
|
||||
|
||||
if ($data && is_object($data)) { $data = [$data]; }
|
||||
|
||||
// Check if the data store contains any tickets
|
||||
if ($data)
|
||||
{
|
||||
// Iterate through each ticket and rename 'ticketid' to 'ID'
|
||||
foreach ($data as &$ticket) {
|
||||
$ticket['id'] = $ticket['ticketid']; // Rename 'ticketid' to 'ID'
|
||||
//unset($ticket['ticketid']); // Unset the original 'ticketid' key
|
||||
}
|
||||
|
||||
// Reorder keys to bring 'ID' as the first element in each ticket object
|
||||
foreach ($data as &$ticket) {
|
||||
$ticket = ['id' => $ticket['id']] + $ticket; // Add 'ID' as the first element
|
||||
}
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the response and exit with a not found message
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/tickets/search/:keysearch Search Ticket Information
|
||||
* @apiName GetTicketSearch
|
||||
* @apiGroup Tickets
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} keysearch Search keywords.
|
||||
*
|
||||
* @apiSuccess {Object} Ticket information.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "ticketid": "7",
|
||||
* "adminreplying": "0",
|
||||
* "userid": "0",
|
||||
* "contactid": "0",
|
||||
* "email": null,
|
||||
* "name": "Trung bình",
|
||||
* "department": "1",
|
||||
* "priority": "2",
|
||||
* "status": "1",
|
||||
* "service": "1",
|
||||
* "ticketkey": "8ef33d61bb0f26cd158d56cc18b71c02",
|
||||
* "subject": "Ticket ER",
|
||||
* "message": "Ticket ER",
|
||||
* "admin": "5",
|
||||
* "date": "2019-04-10 03:08:21",
|
||||
* "project_id": "5",
|
||||
* "lastreply": null,
|
||||
* "clientread": "0",
|
||||
* "adminread": "1",
|
||||
* "assigned": "5",
|
||||
* "line_manager": "8",
|
||||
* "milestone": "27",
|
||||
* ...
|
||||
* }
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message The id of the Ticket was not found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_search_get($key = '')
|
||||
{
|
||||
$data = $this->Api_model->search('ticket', $key);
|
||||
|
||||
// Check if the data store contains
|
||||
if ($data)
|
||||
{
|
||||
$data = $this->Api_model->get_api_custom_data($data,"tickets");
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No data were found'
|
||||
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/tickets Add New Ticket
|
||||
* @apiName PostTicket
|
||||
* @apiGroup Tickets
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} subject Mandatory Ticket name .
|
||||
* @apiParam {String} department Mandatory Ticket Department.
|
||||
* @apiParam {String} contactid Mandatory Ticket Contact.
|
||||
* @apiParam {String} userid Mandatory Ticket user.
|
||||
* @apiParam {String} [project_id] Optional Ticket Project.
|
||||
* @apiParam {String} [message] Optional Ticket message.
|
||||
* @apiParam {String} [service] Optional Ticket Service.
|
||||
* @apiParam {String} [assigned] Optional Assign ticket.
|
||||
* @apiParam {String} [cc] Optional Ticket CC.
|
||||
* @apiParam {String} [priority] Optional Priority.
|
||||
* @apiParam {String} [tags] Optional ticket tags.
|
||||
*
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
* array (size=11)
|
||||
* 'subject' => string 'ticket name' (length=11)
|
||||
* 'contactid' => string '4' (length=1)
|
||||
* 'userid' => string '5' (length=1)
|
||||
* 'department' => string '2' (length=1)
|
||||
* 'cc' => string '' (length=0)
|
||||
* 'tags' => string '' (length=0)
|
||||
* 'assigned' => string '8' (length=1)
|
||||
* 'priority' => string '2' (length=1)
|
||||
* 'service' => string '2' (length=1)
|
||||
* 'project_id' => string '' (length=0)
|
||||
* 'message' => string '' (length=0)
|
||||
*
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Ticket add successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Ticket add successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Ticket add fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Ticket add fail."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public function data_post()
|
||||
{
|
||||
error_reporting(0);
|
||||
// form validation
|
||||
$this->form_validation->set_rules('subject', 'Ticket Name', 'trim|required', array('is_unique' => 'This %s already exists please enter another Ticket Name'));
|
||||
$this->form_validation->set_rules('department', 'Department', 'trim|required', array('is_unique' => 'This %s already exists please enter another Ticket Department'));
|
||||
$this->form_validation->set_rules('contactid', 'Contact', 'trim|required', array('is_unique' => 'This %s already exists please enter another Ticket Contact'));
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
// form validation error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'error' => $this->form_validation->error_array(),
|
||||
'message' => validation_errors()
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert_data = [
|
||||
'subject' => $this->input->post('subject', TRUE),
|
||||
'department' => $this->input->post('department', TRUE),
|
||||
'contactid' => $this->input->post('contactid', TRUE),
|
||||
'userid' => $this->input->post('userid', TRUE),
|
||||
|
||||
'cc' => $this->Api_model->value($this->input->post('cc', TRUE)),
|
||||
'tags' => $this->Api_model->value($this->input->post('tags', TRUE)),
|
||||
'assigned' => $this->Api_model->value($this->input->post('assigned', TRUE)),
|
||||
'priority' => $this->Api_model->value($this->input->post('priority', TRUE)),
|
||||
'service' => $this->Api_model->value($this->input->post('service', TRUE)),
|
||||
'project_id' => $this->Api_model->value($this->input->post('project_id', TRUE)),
|
||||
'message' => $this->Api_model->value($this->input->post('message', TRUE))
|
||||
];
|
||||
if (!empty($this->input->post('custom_fields', TRUE))) {
|
||||
$insert_data['custom_fields'] = $this->Api_model->value($this->input->post('custom_fields', TRUE));
|
||||
}
|
||||
|
||||
// insert data
|
||||
$this->load->model('tickets_model');
|
||||
$output = $this->tickets_model->add($insert_data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$this->handle_ticket_attachments_array($output);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Ticket add successful.',
|
||||
'record_id' => $output // επιστρέφουμε το ID του νέου ticket
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Ticket add fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/delete/tickets/:id Delete a Ticket
|
||||
* @apiName DeleteTicket
|
||||
* @apiGroup Tickets
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {Number} id Ticket unique ID.
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Ticket Delete Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Ticket Delete Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Ticket Delete Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Ticket Delete Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '')
|
||||
{
|
||||
$id = $this->security->xss_clean($id);
|
||||
if (empty($id) && !is_numeric($id))
|
||||
{
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid Ticket ID'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete data
|
||||
$this->load->model('tickets_model');
|
||||
$output = $this->tickets_model->delete($id);
|
||||
if ($output === TRUE) {
|
||||
// success
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Ticket Delete Successful.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Ticket Delete Fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/tickets/:id Update a ticket
|
||||
* @apiName PutTicket
|
||||
* @apiGroup Tickets
|
||||
*
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiParam {String} subject Mandatory Ticket name .
|
||||
* @apiParam {String} department Mandatory Ticket Department.
|
||||
* @apiParam {String} contactid Mandatory Ticket Contact.
|
||||
* @apiParam {String} userid Mandatory Ticket user.
|
||||
* @apiParam {String} priority Mandatory Priority.
|
||||
* @apiParam {String} [project_id] Optional Ticket Project.
|
||||
* @apiParam {String} [message] Optional Ticket message.
|
||||
* @apiParam {String} [service] Optional Ticket Service.
|
||||
* @apiParam {String} [assigned] Optional Assign ticket.
|
||||
* @apiParam {String} [tags] Optional ticket tags.
|
||||
*
|
||||
*
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "subject": "Ticket ER",
|
||||
* "department": "1",
|
||||
* "contactid": "0",
|
||||
* "ticketid": "7",
|
||||
* "userid": "0",
|
||||
* "project_id": "5",
|
||||
* "message": "Ticket ER",
|
||||
* "service": "1",
|
||||
* "assigned": "5",
|
||||
* "priority": "2",
|
||||
* "tags": ""
|
||||
* }
|
||||
*
|
||||
* @apiSuccess {Boolean} status Request status.
|
||||
* @apiSuccess {String} message Ticket Update Successful.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Ticket Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError {Boolean} status Request status.
|
||||
* @apiError {String} message Ticket Update Fail.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Ticket Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '')
|
||||
{
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$this->load->library('parse_input_stream');
|
||||
$_POST = $this->parse_input_stream->parse_parameters();
|
||||
$_FILES = $this->parse_input_stream->parse_files();
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid Lead ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$update_data = $this->input->post();
|
||||
$update_file = isset($update_data['file']) ? $update_data['file'] : null;
|
||||
unset($update_data['file']);
|
||||
// update data
|
||||
$this->load->model('tickets_model');
|
||||
$update_data['ticketid'] = $id;
|
||||
$output = $this->tickets_model->update_single_ticket_settings($update_data);
|
||||
if (!empty($update_file) && count($update_file)) {
|
||||
if ($output <= 0 || empty($output)) {
|
||||
$output = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($output > 0 && !empty($output)) {
|
||||
// success
|
||||
$attachments = $this->tickets_model->get_ticket_attachments($output);
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->tickets_model->delete_ticket_attachment($attachment['id']);
|
||||
}
|
||||
$this->handle_ticket_attachments_array($output);
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Ticket Update Successful.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
// error
|
||||
$message = array(
|
||||
'status' => FALSE,
|
||||
'message' => 'Ticket Update Fail.'
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handle_ticket_attachments_array($ticket_id, $index_name = 'file') {
|
||||
$path = get_upload_path_by_type('ticket') . $ticket_id . '/';
|
||||
$CI = & get_instance();
|
||||
if (isset($_FILES[$index_name]['name']) && ($_FILES[$index_name]['name'] != '' || is_array($_FILES[$index_name]['name']) && count($_FILES[$index_name]['name']) > 0)) {
|
||||
if (!is_array($_FILES[$index_name]['name'])) {
|
||||
$_FILES[$index_name]['name'] = [$_FILES[$index_name]['name']];
|
||||
$_FILES[$index_name]['type'] = [$_FILES[$index_name]['type']];
|
||||
$_FILES[$index_name]['tmp_name'] = [$_FILES[$index_name]['tmp_name']];
|
||||
$_FILES[$index_name]['error'] = [$_FILES[$index_name]['error']];
|
||||
$_FILES[$index_name]['size'] = [$_FILES[$index_name]['size']];
|
||||
}
|
||||
_file_attachments_index_fix($index_name);
|
||||
for ($i = 0; $i < count($_FILES[$index_name]['name']); $i++) {
|
||||
// Get the temp file path
|
||||
$tmpFilePath = $_FILES[$index_name]['tmp_name'][$i];
|
||||
// Make sure we have a filepath
|
||||
if (!empty($tmpFilePath) && $tmpFilePath != '') {
|
||||
if (_perfex_upload_error($_FILES[$index_name]['error'][$i]) || !_upload_extension_allowed($_FILES[$index_name]['name'][$i])) {
|
||||
continue;
|
||||
}
|
||||
_maybe_create_upload_path($path);
|
||||
$filename = unique_filename($path, $_FILES[$index_name]['name'][$i]);
|
||||
$newFilePath = $path . $filename;
|
||||
// Upload the file into the temp dir
|
||||
if (copy($tmpFilePath, $newFilePath)) {
|
||||
unlink($tmpFilePath);
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('tickets_model');
|
||||
$data = [];
|
||||
$data[] = ['file_name' => $filename, 'filetype' => $_FILES[$index_name]['type'][$i], ];
|
||||
$CI->tickets_model->insert_ticket_attachments_to_database($data, $ticket_id, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
255
api/controllers/Timesheets.php
Normal file
255
api/controllers/Timesheets.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
require __DIR__ . '/REST_Controller.php';
|
||||
|
||||
class Timesheets extends REST_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/timesheets/:id Request Timesheet Information
|
||||
* @apiName Request Timesheet Information
|
||||
* @apiGroup Timesheets
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {id} id Data id ID.
|
||||
*
|
||||
* @apiSuccess {Object} Data Information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "task_id": "2",
|
||||
* "start_time": "10:00:00",
|
||||
* "end_time": "12:00:00",
|
||||
* "staff_id ": "2",
|
||||
* "hourly_rate": "5.00",
|
||||
* "note": "testing note",
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError DataNotFound The id of the data was not found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} api/timesheets/ Request all Timesheets
|
||||
* @apiName Request All Timesheets
|
||||
* @apiGroup Timesheets
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
*
|
||||
* @apiSuccess {Object} Data Information
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* "task_id": "2",
|
||||
* "start_time": "10:00:00",
|
||||
* "end_time": "12:00:00",
|
||||
* "staff_id ": "2",
|
||||
* "hourly_rate": "5.00",
|
||||
* "note": "testing note",
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError DataNotFound The id of the data was not found.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "No data were found"
|
||||
* }
|
||||
*/
|
||||
public function data_get($id = '')
|
||||
{
|
||||
$data = $this->Api_model->get_table('taskstimers', $id);
|
||||
|
||||
if ($data) {
|
||||
$this->response($data, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$this->response(['status' => FALSE, 'message' => 'No data were found'], REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/timesheets/ Add New Timesheet
|
||||
* @apiName Add New Timesheet
|
||||
* @apiGroup Timesheets
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParamExample {Multipart Form} Request-Example:
|
||||
*
|
||||
* "task_id": "2",
|
||||
* "start_time": "10:00:00",
|
||||
* "end_time": "12:00:00",
|
||||
* "staff_id ": "2",
|
||||
* "hourly_rate": "5.00",
|
||||
* "note": "testing note",
|
||||
*
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Data Added Successfully"
|
||||
* }
|
||||
*
|
||||
* @apiError DataNotAdded.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "error": "Data not Added"
|
||||
* }
|
||||
*/
|
||||
|
||||
public function data_post()
|
||||
{
|
||||
\modules\api\core\Apiinit::the_da_vinci_code('api');
|
||||
|
||||
$data = $this->input->post();
|
||||
|
||||
$this->form_validation->set_rules('task_id', 'Task', 'trim|required');
|
||||
$this->form_validation->set_rules('start_time', 'Start Time', 'trim|required');
|
||||
$this->form_validation->set_rules('end_time', 'End Time', 'required');
|
||||
$this->form_validation->set_rules('staff_id', 'Staff Member', 'required');
|
||||
$this->form_validation->set_rules('hourly_rate', 'Time (h)', 'required');
|
||||
$this->form_validation->set_rules('note', 'Note', 'required');
|
||||
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$message = array('status' => FALSE, 'error' => $this->form_validation->error_array(), 'message' => validation_errors());
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$id = $this->Api_model->timesheets($data);
|
||||
if ($id > 0 && !empty($id)) {
|
||||
$message = array(
|
||||
'status' => TRUE,
|
||||
'message' => 'Data Added Successfully',
|
||||
'record_id' => $id
|
||||
);
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Add Fail');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {put} api/timesheets/:id Update a Timesheet
|
||||
* @apiName Update a Timesheet
|
||||
* @apiParam {id} id ID for update data.
|
||||
* @apiGroup Timesheets
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParamExample {json} Request-Example:
|
||||
* {
|
||||
* "task_id": "2",
|
||||
* "start_time": "07:00:00",
|
||||
* "end_time": "09:00:00",
|
||||
* "staff_id ": "2",
|
||||
* "hourly_rate": "15.00",
|
||||
* "note": "Timesheets Notes",
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Data Update Successful."
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Data Not Acceptable OR Not Provided"
|
||||
* }
|
||||
*
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Data Update Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_put($id = '')
|
||||
{
|
||||
// JSON data is now automatically parsed in REST_Controller
|
||||
|
||||
if (empty($_POST) || !isset($_POST)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Not Acceptable OR Not Provided');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_ACCEPTABLE);
|
||||
}
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid data or missing Send ID. please provide updated data ID.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$_POST['id'] = $id;
|
||||
$update_data = $this->input->post();
|
||||
$data = $_POST;
|
||||
$output = $this->Api_model->timesheetUpdate($data);
|
||||
if ($output > 0 && !empty($output)) {
|
||||
$message = array('status' => TRUE, 'message' => 'Data Update Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Data Update Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {delete} api/timesheets/:id Delete a Timesheet
|
||||
* @apiName Delete a Timesheet
|
||||
* @apiGroup Timesheets
|
||||
* @apiHeader {String} authtoken Authentication token, generated from admin area
|
||||
* @apiParam {id} id ID for data Deletion.
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "status": true,
|
||||
* "message": "Delete Successful."
|
||||
* }
|
||||
*
|
||||
* @apiError DataNotAdded.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "status": false,
|
||||
* "message": "Delete Fail."
|
||||
* }
|
||||
*/
|
||||
public function data_delete($id = '')
|
||||
{
|
||||
$id = $this->security->xss_clean($id);
|
||||
|
||||
if (empty($id) && !is_numeric($id)) {
|
||||
$message = array('status' => FALSE, 'message' => 'Invalid ID');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
} else {
|
||||
$this->load->model('api_model');
|
||||
$output = $this->api_model->timesheetDelete($id);
|
||||
|
||||
if ($output === TRUE) {
|
||||
$message = array('status' => TRUE, 'message' => 'Delete Successful.');
|
||||
$this->response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = array('status' => FALSE, 'message' => 'Delete Fail.');
|
||||
$this->response($message, REST_Controller::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user