diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 52f7a473bed..2d828298b51 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -1079,22 +1079,26 @@ class BookKeeping extends CommonObject
* @param string $mode Mode
* @return number <0 if KO, >0 if OK
*/
- public function updateByMvt($piece_num='', $field='', $value='', $mode='') {
+ public function updateByMvt($piece_num='', $field='', $value='', $mode='')
+ {
+ $error=0;
+
$this->db->begin();
+
$sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element . $mode . " as ab";
$sql .= ' SET ab.' . $field . '=' . (is_numeric($value)?$value:"'".$value."'");
$sql .= ' WHERE ab.piece_num=' . $piece_num ;
$resql = $this->db->query($sql);
if (! $resql) {
- $error ++;
+ $error++;
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
}
if ($error) {
$this->db->rollback();
- return - 1 * $error;
+ return -1 * $error;
} else {
$this->db->commit();
@@ -1521,11 +1525,16 @@ class BookKeeping extends CommonObject
* @param string $piece_num Piece num
* @return void
*/
- public function transformTransaction($direction=0,$piece_num='') {
+ public function transformTransaction($direction=0,$piece_num='')
+ {
+ $error = 0;
+
$this->db->begin();
- if ($direction==0) {
+
+ if ($direction==0)
+ {
$next_piecenum=$this->getNextNumMvt();
- if ($result < 0) {
+ if ($next_piecenum < 0) {
$error++;
}
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element.'(doc_date, doc_type,';
diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php
index 0e3e71c1527..13602160c48 100644
--- a/htdocs/accountancy/customer/lines.php
+++ b/htdocs/accountancy/customer/lines.php
@@ -32,6 +32,8 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
// Langs
$langs->load("bills");
@@ -51,6 +53,9 @@ $search_desc = GETPOST('search_desc', 'alpha');
$search_amount = GETPOST('search_amount', 'alpha');
$search_account = GETPOST('search_account', 'alpha');
$search_vat = GETPOST('search_vat', 'alpha');
+$search_day=GETPOST("search_day","int");
+$search_month=GETPOST("search_month","int");
+$search_year=GETPOST("search_year","int");
$search_country = GETPOST('search_country', 'alpha');
$search_tvaintra = GETPOST('search_tvaintra', 'alpha');
@@ -95,6 +100,9 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x',
$search_amount = '';
$search_account = '';
$search_vat = '';
+ $search_day = '';
+ $search_month = '';
+ $search_year = '';
$search_country = '';
$search_tvaintra = '';
}
@@ -131,6 +139,7 @@ if (is_array($changeaccount) && count($changeaccount) > 0) {
*/
$form = new Form($db);
+$formother = new FormOther($db);
llxHeader('', $langs->trans("CustomersVentilation") . ' - ' . $langs->trans("Dispatched"));
@@ -197,6 +206,19 @@ if (strlen(trim($search_account))) {
if (strlen(trim($search_vat))) {
$sql .= natural_search("fd.tva_tx", $search_vat);
}
+if ($search_month > 0)
+{
+ if ($search_year > 0 && empty($search_day))
+ $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
+ else if ($search_year > 0 && ! empty($search_day))
+ $sql.= " AND f.datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month, $search_day, $search_year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month, $search_day, $search_year))."'";
+ else
+ $sql.= " AND date_format(f.datef, '%m') = '".$db->escape($search_month)."'";
+}
+else if ($search_year > 0)
+{
+ $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
+}
if (strlen(trim($search_country))) {
$sql .= natural_search("co.label", $search_country);
}
@@ -237,6 +259,9 @@ if ($result) {
$param .= "&search_account=" . $search_account;
if ($search_vat)
$param .= "&search_vat=" . $search_vat;
+ if ($search_day) $param.='&search_day='.urlencode($search_day);
+ if ($search_month) $param.='&search_month='.urlencode($search_month);
+ if ($search_year) $param.='&search_year='.urlencode($search_year);
if ($search_country)
$param .= "&search_country=" . $search_country;
if ($search_tvaintra)
@@ -267,7 +292,11 @@ if ($result) {
print '
';
print ' | ';
print ' | ';
- print ' | ';
+ print '';
+ if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '';
+ print '';
+ $formother->select_year($search_year,'search_year',1, 20, 5);
+ print ' | ';
print ' | ';
//print ' | ';
print ' | ';
diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php
index 51f62ecabf6..2d26a2d06d8 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -115,6 +115,7 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x',
$search_amount = '';
$search_account = '';
$search_vat = '';
+ $search_day = '';
$search_month = '';
$search_year = '';
}
diff --git a/htdocs/accountancy/expensereport/lines.php b/htdocs/accountancy/expensereport/lines.php
index 156d80f09e4..750a5bc9f25 100644
--- a/htdocs/accountancy/expensereport/lines.php
+++ b/htdocs/accountancy/expensereport/lines.php
@@ -31,6 +31,8 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
// Langs
$langs->load("compta");
@@ -50,6 +52,9 @@ $search_desc = GETPOST('search_desc', 'alpha');
$search_amount = GETPOST('search_amount', 'alpha');
$search_account = GETPOST('search_account', 'alpha');
$search_vat = GETPOST('search_vat', 'alpha');
+$search_day=GETPOST("search_day","int");
+$search_month=GETPOST("search_month","int");
+$search_year=GETPOST("search_year","int");
// Load variable for pagination
$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
@@ -90,6 +95,9 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x',
$search_amount = '';
$search_account = '';
$search_vat = '';
+ $search_day = '';
+ $search_month = '';
+ $search_year = '';
}
if (is_array($changeaccount) && count($changeaccount) > 0) {
@@ -123,6 +131,9 @@ if (is_array($changeaccount) && count($changeaccount) > 0) {
* View
*/
+$form = new Form($db);
+$formother = new FormOther($db);
+
llxHeader('', $langs->trans("ExpenseReportsVentilation") . ' - ' . $langs->trans("Dispatched"));
print ''."\n";
+ }
print load_fiche_titre($langs->trans("DoPayment"));
print "
\n";
@@ -294,7 +308,12 @@ if ($action == 'create')
if ($sumpaid < $objp->amount)
{
$namef = "amount_".$objp->id;
- print '';
+ $nameRemain = "remain_".$objp->id;
+ if (!empty($conf->use_javascript_ajax))
+ print img_picto("Auto fill",'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'");
+ $remaintopay=$objp->amount - $sumpaid;
+ print '';
+ print '';
}
else
{
diff --git a/htdocs/contrat/class/api_contracts.class.php b/htdocs/contrat/class/api_contracts.class.php
new file mode 100644
index 00000000000..7e92b8d6efe
--- /dev/null
+++ b/htdocs/contrat/class/api_contracts.class.php
@@ -0,0 +1,532 @@
+
+ * Copyright (C) 2016 Laurent Destailleur
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+ use Luracast\Restler\RestException;
+
+ require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
+
+/**
+ * API class for contracts
+ *
+ * @access protected
+ * @class DolibarrApiAccess {@requires user,external}
+ */
+class Contracts extends DolibarrApi
+{
+
+ /**
+ * @var array $FIELDS Mandatory fields, checked when create and update object
+ */
+ static $FIELDS = array(
+ 'socid',
+ 'date_contrat',
+ 'commercial_signature_id',
+ 'commercial_suivi_id'
+ );
+
+ /**
+ * @var Contract $contract {@type Contrat}
+ */
+ public $contract;
+
+ /**
+ * Constructor
+ */
+ function __construct()
+ {
+ global $db, $conf;
+ $this->db = $db;
+ $this->contract = new Contrat($this->db);
+ }
+
+ /**
+ * Get properties of a contrat object
+ *
+ * Return an array with contrat informations
+ *
+ * @param int $id ID of contract
+ * @return array|mixed data without useless information
+ *
+ * @throws RestException
+ */
+ function get($id)
+ {
+ if(! DolibarrApiAccess::$user->rights->contrat->lire) {
+ throw new RestException(401);
+ }
+
+ $result = $this->contract->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Contract not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('contrat',$this->contract->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $this->contract->fetchObjectLinked();
+ return $this->_cleanObjectDatas($this->contract);
+ }
+
+
+
+ /**
+ * List contracts
+ *
+ * Get a list of contracts
+ *
+ * @param string $sortfield Sort field
+ * @param string $sortorder Sort order
+ * @param int $limit Limit for list
+ * @param int $page Page number
+ * @param string $thirdparty_ids Thirdparty ids to filter contracts of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
+ * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
+ * @return array Array of contract objects
+ *
+ * @throws RestException
+ */
+ function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
+ global $db, $conf;
+
+ $obj_ret = array();
+
+ // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
+ $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
+
+ // If the internal user must only see his customers, force searching by him
+ $search_sale = 0;
+ if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
+
+ $sql = "SELECT t.rowid";
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
+ $sql.= " FROM ".MAIN_DB_PREFIX."contrat as t";
+
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
+
+ $sql.= ' WHERE t.entity IN ('.getEntity('contrat').')';
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
+ if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
+ if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
+ // Insert sale filter
+ if ($search_sale > 0)
+ {
+ $sql .= " AND sc.fk_user = ".$search_sale;
+ }
+ // Add sql filters
+ if ($sqlfilters)
+ {
+ if (! DolibarrApi::_checkFilters($sqlfilters))
+ {
+ throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
+ }
+ $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
+ $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
+ }
+
+ $sql.= $db->order($sortfield, $sortorder);
+ if ($limit) {
+ if ($page < 0)
+ {
+ $page = 0;
+ }
+ $offset = $limit * $page;
+
+ $sql.= $db->plimit($limit + 1, $offset);
+ }
+
+ dol_syslog("API Rest request");
+ $result = $db->query($sql);
+
+ if ($result)
+ {
+ $num = $db->num_rows($result);
+ $min = min($num, ($limit <= 0 ? $num : $limit));
+ while ($i < $min)
+ {
+ $obj = $db->fetch_object($result);
+ $contrat_static = new Contrat($db);
+ if($contrat_static->fetch($obj->rowid)) {
+ $obj_ret[] = $this->_cleanObjectDatas($contrat_static);
+ }
+ $i++;
+ }
+ }
+ else {
+ throw new RestException(503, 'Error when retrieve contrat list : '.$db->lasterror());
+ }
+ if( ! count($obj_ret)) {
+ throw new RestException(404, 'No contract found');
+ }
+ return $obj_ret;
+ }
+
+ /**
+ * Create contract object
+ *
+ * @param array $request_data Request data
+ * @return int ID of contrat
+ */
+ function post($request_data = NULL)
+ {
+ if(! DolibarrApiAccess::$user->rights->contrat->creer) {
+ throw new RestException(401, "Insuffisant rights");
+ }
+ // Check mandatory fields
+ $result = $this->_validate($request_data);
+
+ foreach($request_data as $field => $value) {
+ $this->contract->$field = $value;
+ }
+ /*if (isset($request_data["lines"])) {
+ $lines = array();
+ foreach ($request_data["lines"] as $line) {
+ array_push($lines, (object) $line);
+ }
+ $this->contract->lines = $lines;
+ }*/
+ if ($this->contract->create(DolibarrApiAccess::$user) < 0) {
+ throw new RestException(500, "Error creating contract", array_merge(array($this->contract->error), $this->contract->errors));
+ }
+
+ return $this->contract->id;
+ }
+
+ /**
+ * Get lines of an contract
+ *
+ * @param int $id Id of contract
+ *
+ * @url GET {id}/lines
+ *
+ * @return int
+ */
+ function getLines($id) {
+ if(! DolibarrApiAccess::$user->rights->contrat->lire) {
+ throw new RestException(401);
+ }
+
+ $result = $this->contract->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Contract not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('contrat',$this->contract->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+ $this->contract->getLinesArray();
+ $result = array();
+ foreach ($this->contract->lines as $line) {
+ array_push($result,$this->_cleanObjectDatas($line));
+ }
+ return $result;
+ }
+
+ /**
+ * Add a line to given contract
+ *
+ * @param int $id Id of contrat to update
+ * @param array $request_data Contractline data
+ *
+ * @url POST {id}/lines
+ *
+ * @return int
+ */
+ function postLine($id, $request_data = NULL) {
+ if(! DolibarrApiAccess::$user->rights->contrat->creer) {
+ throw new RestException(401);
+ }
+
+ $result = $this->contract->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Contract not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('contrat',$this->contract->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+ $request_data = (object) $request_data;
+ $updateRes = $this->contract->addline(
+ $request_data->desc,
+ $request_data->subprice,
+ $request_data->qty,
+ $request_data->tva_tx,
+ $request_data->localtax1_tx,
+ $request_data->localtax2_tx,
+ $request_data->fk_product,
+ $request_data->remise_percent,
+ $request_data->date_start, // date ouverture = date_start_real
+ $request_data->date_end, // date_cloture = date_end_real
+ $request_data->HT,
+ $request_data->subprice_excl_tax,
+ $request_data->info_bits,
+ $request_data->fk_fournprice,
+ $request_data->pa_ht,
+ $request_data->array_options,
+ $request_data->fk_unit,
+ $request_data->rang
+ );
+
+ if ($updateRes > 0) {
+ return $updateRes;
+
+ }
+ return false;
+ }
+
+ /**
+ * Update a line to given contract
+ *
+ * @param int $id Id of contrat to update
+ * @param int $lineid Id of line to update
+ * @param array $request_data Contractline data
+ *
+ * @url PUT {id}/lines/{lineid}
+ *
+ * @return object
+ */
+ function putLine($id, $lineid, $request_data = NULL) {
+ if(! DolibarrApiAccess::$user->rights->contrat->creer) {
+ throw new RestException(401);
+ }
+
+ $result = $this->contract->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Contrat not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('contrat',$this->contract->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $request_data = (object) $request_data;
+
+ $updateRes = $this->contract->updateline(
+ $lineid,
+ $request_data->desc,
+ $request_data->subprice,
+ $request_data->qty,
+ $request_data->remise_percent,
+ $request_data->date_ouveture_prevue,
+ $request_data->date_fin_validite,
+ $request_data->tva_tx,
+ $request_data->localtax1_tx,
+ $request_data->localtax2_tx,
+ $request_data->date_ouverture,
+ $request_data->date_cloture,
+ 'HT',
+ $request_data->info_bits,
+ $request_data->fk_fourn_price,
+ $request_data->pa_ht,
+ $request_data->array_options,
+ $request_data->fk_unit
+ );
+
+ if ($updateRes > 0) {
+ $result = $this->get($id);
+ unset($result->line);
+ return $this->_cleanObjectDatas($result);
+ }
+
+ return false;
+ }
+
+ /**
+ * Delete a line to given contract
+ *
+ *
+ * @param int $id Id of contract to update
+ * @param int $lineid Id of line to delete
+ *
+ * @url DELETE {id}/lines/{lineid}
+ *
+ * @return int
+ * @throws 401
+ * @throws 404
+ */
+ function deleteLine($id, $lineid) {
+ if(! DolibarrApiAccess::$user->rights->contrat->creer) {
+ throw new RestException(401);
+ }
+
+ $result = $this->contract->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Contrat not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('contrat',$this->contract->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $request_data = (object) $request_data;
+ $updateRes = $this->contract->deleteline($lineid, DolibarrApiAccess::$user);
+ if ($updateRes > 0) {
+ return $this->get($id);
+ }
+ return false;
+ }
+
+ /**
+ * Update contract general fields (won't touch lines of contract)
+ *
+ * @param int $id Id of contrat to update
+ * @param array $request_data Datas
+ *
+ * @return int
+ */
+ function put($id, $request_data = NULL) {
+ if(! DolibarrApiAccess::$user->rights->contrat->creer) {
+ throw new RestException(401);
+ }
+
+ $result = $this->contract->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Contrat not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('contrat',$this->contract->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+ foreach($request_data as $field => $value) {
+ if ($field == 'id') continue;
+ $this->contract->$field = $value;
+ }
+
+ if($this->contract->update(DolibarrApiAccess::$user, 0))
+ return $this->get($id);
+
+ return false;
+ }
+
+ /**
+ * Delete contract
+ *
+ * @param int $id Contract ID
+ *
+ * @return array
+ */
+ function delete($id)
+ {
+ if(! DolibarrApiAccess::$user->rights->contrat->supprimer) {
+ throw new RestException(401);
+ }
+ $result = $this->contract->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Contract not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('contrat',$this->contract->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ if( ! $this->contract->delete(DolibarrApiAccess::$user)) {
+ throw new RestException(500, 'Error when delete contract : '.$this->contract->error);
+ }
+
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'message' => 'Contract deleted'
+ )
+ );
+
+ }
+
+ /**
+ * Validate an contract
+ *
+ * @param int $id Contract ID
+ * @param int $idwarehouse Warehouse ID
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ *
+ * @url POST {id}/validate
+ *
+ * @return array
+ * FIXME An error 403 is returned if the request has an empty body.
+ * Error message: "Forbidden: Content type `text/plain` is not supported."
+ * Workaround: send this in the body
+ * {
+ * "idwarehouse": 0,
+ * "notrigger": 0
+ * }
+ */
+ /*
+ function validate($id, $idwarehouse=0, $notrigger=0)
+ {
+ if(! DolibarrApiAccess::$user->rights->contrat->creer) {
+ throw new RestException(401);
+ }
+ $result = $this->contract->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Contract not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('contrat',$this->contract->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $result = $this->contract->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
+ if ($result == 0) {
+ throw new RestException(500, 'Error nothing done. May be object is already validated');
+ }
+ if ($result < 0) {
+ throw new RestException(500, 'Error when validating Contract: '.$this->contract->error);
+ }
+
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'message' => 'Contract validated (Ref='.$this->contract->ref.')'
+ )
+ );
+ }
+ */
+
+ /**
+ * Clean sensible object datas
+ *
+ * @param object $object Object to clean
+ * @return array Array of cleaned object properties
+ */
+ function _cleanObjectDatas($object) {
+
+ $object = parent::_cleanObjectDatas($object);
+
+ unset($object->address);
+
+ return $object;
+ }
+
+ /**
+ * Validate fields before create or update object
+ *
+ * @param array $data Array with data to verify
+ * @return array
+ * @throws RestException
+ */
+ function _validate($data)
+ {
+ $contrat = array();
+ foreach (Contracts::$FIELDS as $field) {
+ if (!isset($data[$field]))
+ throw new RestException(400, "$field field missing");
+ $contrat[$field] = $data[$field];
+
+ }
+ return $contrat;
+ }
+}
diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php
index 071ae75e5b7..d54c2b521ff 100644
--- a/htdocs/contrat/class/contrat.class.php
+++ b/htdocs/contrat/class/contrat.class.php
@@ -1400,13 +1400,14 @@ class Contrat extends CommonObject
* @param int $pa_ht Buying price HT
* @param array $array_options extrafields array
* @param string $fk_unit Code of the unit to use. Null to use the default one
- * @return int <0 si erreur, >0 si ok
+ * @param string $rang Position
+ * @return int <0 if KO, >0 if OK
*/
- function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0, $fk_unit = null)
+ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0, $fk_unit = null, $rang=0)
{
global $user, $langs, $conf, $mysoc;
- dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type, $pu_ttc, $info_bits");
+ dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type, $pu_ttc, $info_bits, $rang");
if ($this->statut >= 0)
{
@@ -1616,7 +1617,7 @@ class Contrat extends CommonObject
{
global $user, $conf, $langs, $mysoc;
- // Nettoyage parametres
+ // Clean parameters
$qty=trim($qty);
$desc=trim($desc);
$desc=trim($desc);
@@ -1625,6 +1626,7 @@ class Contrat extends CommonObject
$localtax1tx = price2num($localtax1tx);
$localtax2tx = price2num($localtax2tx);
$pa_ht=price2num($pa_ht);
+ if (empty($fk_fournprice)) $fk_fournprice=0;
$subprice = $price;
$remise = 0;
@@ -1701,7 +1703,7 @@ class Contrat extends CommonObject
$sql.= ", total_localtax1='".price2num($total_localtax1)."'";
$sql.= ", total_localtax2='".price2num($total_localtax2)."'";
$sql.= ", total_ttc='". price2num($total_ttc)."'";
- $sql.= ", fk_product_fournisseur_price='".$fk_fournprice."'";
+ $sql.= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : "null");
$sql.= ", buy_price_ht='".price2num($pa_ht)."'";
if ($date_start > 0) { $sql.= ",date_ouverture_prevue='".$this->db->idate($date_start)."'"; }
else { $sql.=",date_ouverture_prevue=null"; }
@@ -1772,7 +1774,7 @@ class Contrat extends CommonObject
* @param User $user User that delete
* @return int >0 if OK, <0 if KO
*/
- function deleteline($idline,$user)
+ function deleteline($idline, User $user)
{
global $conf, $langs;
@@ -2343,7 +2345,17 @@ class Contrat extends CommonObject
}
}
- /**
+ /**
+ * Create an array of order lines
+ *
+ * @return int >0 if OK, <0 if KO
+ */
+ function getLinesArray()
+ {
+ return $this->fetch_lines();
+ }
+
+ /**
* Create a document onto disk according to template module.
*
* @param string $modele Force model to use ('' to not force)
@@ -3033,7 +3045,7 @@ class ContratLigne extends CommonObjectLine
$sql.= " info_bits,";
$sql.= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht";
if ($this->date_ouverture_prevue > 0) { $sql.= ",date_ouverture_prevue"; }
- if ($this->date_fin_validite > 0) { $sql.= ",date_fin_validite"; }
+ if ($this->date_fin_validite > 0) { $sql.= ",date_fin_validite"; }
$sql.= ") VALUES ($this->fk_contrat, '', '" . $this->db->escape($this->description) . "',";
$sql.= ($this->fk_product>0 ? $this->fk_product : "null").",";
$sql.= " '".$this->db->escape($this->qty)."',";
@@ -3051,8 +3063,8 @@ class ContratLigne extends CommonObjectLine
else $sql.= ' null,';
if ($this->pa_ht > 0) $sql.= ' '.price2num($this->pa_ht);
else $sql.= ' null';
- if ($this->date_ouverture_prevue > 0) { $sql.= ",'".$this->db->idate($this->date_ouverture_prevue)."'"; }
- if ($this->date_fin_validite > 0) { $sql.= ",'".$this->db->idate($this->date_fin_validite)."'"; }
+ if ($this->date_ouverture > 0) { $sql.= ",'".$this->db->idate($this->date_ouverture)."'"; }
+ if ($this->date_cloture > 0) { $sql.= ",'".$this->db->idate($this->date_cloture)."'"; }
$sql.= ")";
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php
index e382f5c8198..39487cf6fea 100644
--- a/htdocs/core/class/CMailFile.class.php
+++ b/htdocs/core/class/CMailFile.class.php
@@ -275,7 +275,8 @@ class CMailFile
// comme des injections mail par les serveurs de messagerie.
$this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers);
- $this->message = $this->eol.'This is a message with multiple parts in MIME format.'.$this->eol;
+ //$this->message = $this->eol.'This is a message with multiple parts in MIME format.'.$this->eol;
+ $this->message = 'This is a message with multiple parts in MIME format.'.$this->eol;
$this->message.= $text_body . $files_encoded;
$this->message.= "--" . $this->mixed_boundary . "--" . $this->eol;
}
@@ -961,8 +962,8 @@ class CMailFile
//$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol;
- $out.= "Content-Type: multipart/mixed; boundary=\"".$this->mixed_boundary."\"".$this->eol2;
- $out.= "Content-Transfer-Encoding: 8bit".$this->eol2;
+ $out.= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2;
+ $out.= "Content-Transfer-Encoding: 8bit".$this->eol2; // TODO Seems to be ignored. Header is 7bit once received.
dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out);
return $out;
@@ -1014,23 +1015,23 @@ class CMailFile
if ($this->atleastoneimage)
{
- $out.= "Content-Type: multipart/alternative; boundary=\"".$this->alternative_boundary."\"".$this->eol;
+ $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
$out.= $this->eol;
$out.= "--" . $this->alternative_boundary . $this->eol;
}
// Make RFC821 Compliant, replace bare linefeeds
- $strContent = preg_replace("/(?global->MAIN_FIX_FOR_BUGGED_MTA))
{
- $strContent = preg_replace("/\r\n/si", "\n", $strContent);
+ $strContent = preg_replace("/\r\n/si", "\n", $strContent); // PCRE modifier /s means new lines are common chars
}
$strContentAltText = '';
if ($this->msgishtml)
{
$strContentAltText = html_entity_decode(strip_tags($strContent));
- $strContentAltText = rtrim(wordwrap($strContentAltText, 75, "\r\n"));
+ $strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));
// Check if html header already in message, if not complete the message
$strContent = $this->checkIfHTML($strContent);
@@ -1038,31 +1039,35 @@ class CMailFile
// Make RFC2045 Compliant, split lines
//$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content
- $strContent = rtrim(wordwrap($strContent)); // TODO Using this method creates unexpected line break on text/plain content.
+ // TODO Encode main content into base64 and use the chunk_split, or quoted-printable
+ $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n")); // TODO Using this method creates unexpected line break on text/plain content.
if ($this->msgishtml)
{
if ($this->atleastoneimage)
{
$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
+ //$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
$out.= $this->eol.($strContentAltText?$strContentAltText:strip_tags($strContent)).$this->eol; // Add plain text message
$out.= "--" . $this->alternative_boundary . $this->eol;
- $out.= "Content-Type: multipart/related; boundary=\"".$this->related_boundary."\"".$this->eol;
+ $out.= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol;
$out.= $this->eol;
$out.= "--" . $this->related_boundary . $this->eol;
}
if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part
{
- $out.= "Content-Type: multipart/alternative; boundary=\"".$this->alternative_boundary."\"".$this->eol;
+ $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
$out.= $this->eol;
$out.= "--" . $this->alternative_boundary . $this->eol;
$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
+ //$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
$out.= $this->eol.$strContentAltText.$this->eol;
$out.= "--" . $this->alternative_boundary . $this->eol;
}
$out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
+ //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; // TODO Use base64
$out.= $this->eol.$strContent.$this->eol;
if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part
@@ -1073,6 +1078,7 @@ class CMailFile
else
{
$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
+ //$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
$out.= $this->eol.$strContent.$this->eol;
}
diff --git a/htdocs/core/class/emailsenderprofile.class.php b/htdocs/core/class/emailsenderprofile.class.php
index d2082bfba01..f211a0b1670 100644
--- a/htdocs/core/class/emailsenderprofile.class.php
+++ b/htdocs/core/class/emailsenderprofile.class.php
@@ -273,7 +273,9 @@ class EmailSenderProfile extends CommonObject
$result = '';
$companylink = '';
- $url='';
+ $label=$this->label;
+
+ $url='';
//$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
$linkstart = '';
diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php
index 9fc1739334c..99b799d5d6e 100644
--- a/htdocs/core/db/DoliDB.class.php
+++ b/htdocs/core/db/DoliDB.class.php
@@ -59,7 +59,7 @@ abstract class DoliDB implements Database
public $lastqueryerror;
/** @var string Last error message */
public $lasterror;
- /** @var int Last error number */
+ /** @var string Last error number. For example: 'DB_ERROR_RECORD_ALREADY_EXISTS', '12345', ... */
public $lasterrno;
/** @var bool Status */
@@ -238,16 +238,16 @@ abstract class DoliDB implements Database
else $return.=', ';
$return.=preg_replace('/[^0-9a-z_\.]/i','',$val);
-
+
$tmpsortorder = trim($orders[$i]);
-
+
// Only ASC and DESC values are valid SQL
if (strtoupper($tmpsortorder) === 'ASC') {
$return .= ' ASC';
} elseif (strtoupper($tmpsortorder) === 'DESC') {
$return .= ' DESC';
}
-
+
$i++;
}
return $return;
diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php
index 44a404c6c67..2f59c7e388c 100644
--- a/htdocs/core/lib/files.lib.php
+++ b/htdocs/core/lib/files.lib.php
@@ -47,7 +47,7 @@ function dol_basename($pathfile)
* @param string $filter Regex filter to restrict list. This regex value must be escaped for '/' by doing preg_quote($var,'/'), since this char is used for preg_match function,
* but must not contains the start and end '/'. Filter is checked into basename only.
* @param array $excludefilter Array of Regex for exclude filter (example: array('(\.meta|_preview.*\.png)$','^\.')). Exclude is checked into fullpath.
- * @param string $sortcriteria Sort criteria ("","fullname","relativename","name","date","size")
+ * @param string $sortcriteria Sort criteria ('','fullname','relativename','name','date','size')
* @param string $sortorder Sort order (SORT_ASC, SORT_DESC)
* @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
* @param int $nohook Disable all hooks
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index f56cd2f523d..2626e917460 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -6791,3 +6791,37 @@ function getDictvalue($tablename, $field, $id, $checkentity=false, $rowidfield='
return '';
}
}
+
+/**
+ * Return true if the color is light
+ *
+ * @param string $stringcolor String with hex (FFFFFF) or comma RGB ('255,255,255')
+ * @return int -1 : Error with argument passed |0 : color is dark | 1 : color is light
+ */
+function colorIsLight($stringcolor)
+{
+ $res = -1;
+ if (!empty($stringcolor))
+ {
+ $res = 0;
+ $tmp=explode(',', $stringcolor);
+ if (count($tmp) > 1) // This is a comma RGB ('255','255','255')
+ {
+ $r = $tmp[0];
+ $g = $tmp[1];
+ $b = $tmp[2];
+ }
+ else
+ {
+ $hexr=$stringcolor[0].$stringcolor[1];
+ $hexg=$stringcolor[2].$stringcolor[3];
+ $hexb=$stringcolor[4].$stringcolor[5];
+ $r = hexdec($hexr);
+ $g = hexdec($hexg);
+ $b = hexdec($hexb);
+ }
+ $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
+ if ($bright > 0.6) $res = 1;
+ }
+ return $res;
+}
diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php
index 3d2e2bb359b..7697c4e56a9 100644
--- a/htdocs/core/lib/functions2.lib.php
+++ b/htdocs/core/lib/functions2.lib.php
@@ -1606,7 +1606,8 @@ function getListOfModels($db,$type,$maxfilenamelength=0)
if (! $tmpdir) { unset($listofdir[$key]); continue; }
if (is_dir($tmpdir))
{
- $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0);
+ // all type of template is allowed
+ $tmpfiles=dol_dir_list($tmpdir, 'files', 0, '', '', 'name', SORT_ASC, 0);
if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
}
}
@@ -2153,40 +2154,6 @@ function colorStringToArray($stringcolor,$colorifnotfound=array(88,88,88))
return array(hexdec($reg[1]),hexdec($reg[2]),hexdec($reg[3]));
}
-/**
- * Return true if the color is light
- *
- * @param string $stringcolor String with hex (FFFFFF) or comma RGB ('255,255,255')
- * @return int -1 : Error with argument passed |0 : color is dark | 1 : color is light
- */
-function colorIsLight($stringcolor)
-{
- $res = -1;
- if (!empty($stringcolor))
- {
- $res = 0;
- $tmp=explode(',', $stringcolor);
- if (count($tmp) > 1) // This is a comma RGB ('255','255','255')
- {
- $r = $tmp[0];
- $g = $tmp[1];
- $b = $tmp[2];
- }
- else
- {
- $hexr=$stringcolor[0].$stringcolor[1];
- $hexg=$stringcolor[2].$stringcolor[3];
- $hexb=$stringcolor[4].$stringcolor[5];
- $r = hexdec($hexr);
- $g = hexdec($hexg);
- $b = hexdec($hexb);
- }
- $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
- if ($bright > 0.6) $res = 1;
- }
- return $res;
-}
-
/**
* Applies the Cartesian product algorithm to an array
* Source: http://stackoverflow.com/a/15973172
diff --git a/htdocs/expensereport/class/api_expensereports.class.php b/htdocs/expensereport/class/api_expensereports.class.php
index d1f123b791f..3085c3659be 100644
--- a/htdocs/expensereport/class/api_expensereports.class.php
+++ b/htdocs/expensereport/class/api_expensereports.class.php
@@ -271,7 +271,7 @@ class ExpenseReports extends DolibarrApi
);
if ($updateRes > 0) {
- return $this->get($id)->line->rowid;
+ return $updateRes;
}
return false;
diff --git a/htdocs/modulebuilder/template/class/api_myobject.class.php b/htdocs/modulebuilder/template/class/api_myobject.class.php
index e3e38cefd38..e4a02468557 100644
--- a/htdocs/modulebuilder/template/class/api_myobject.class.php
+++ b/htdocs/modulebuilder/template/class/api_myobject.class.php
@@ -231,7 +231,7 @@ class MyObjectApi extends DolibarrApi
}
if($this->myobject->update($id, DolibarrApiAccess::$user))
- return $this->get ($id);
+ return $this->get($id);
return false;
}
diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php
index c63c4cfbd23..6fcdfde7ca2 100644
--- a/htdocs/projet/class/api_projects.class.php
+++ b/htdocs/projet/class/api_projects.class.php
@@ -342,7 +342,7 @@ class Projects extends DolibarrApi
);
if ($updateRes > 0) {
- return $this->get($id)->line->rowid;
+ return $updateRes;
}
return false;
diff --git a/htdocs/projet/class/api_tasks.class.php b/htdocs/projet/class/api_tasks.class.php
index 168afc2cb0c..f00a536df87 100644
--- a/htdocs/projet/class/api_tasks.class.php
+++ b/htdocs/projet/class/api_tasks.class.php
@@ -20,7 +20,7 @@
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
-
+
/**
* API class for projects
*
@@ -88,12 +88,12 @@ class Tasks extends DolibarrApi
// TODO
// Add class for timespent records and loop and fill $line->lines with records of timespent
}
-
+
return $this->_cleanObjectDatas($this->task);
}
-
-
+
+
/**
* List tasks
*
@@ -110,7 +110,7 @@ class Tasks extends DolibarrApi
global $db, $conf;
$obj_ret = array();
-
+
// case of external user, $thirdparty_ids param is ignored and replaced by user's socid
$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
@@ -134,7 +134,7 @@ class Tasks extends DolibarrApi
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Add sql filters
- if ($sqlfilters)
+ if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
@@ -143,7 +143,7 @@ class Tasks extends DolibarrApi
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
-
+
$sql.= $db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0)
@@ -236,7 +236,7 @@ class Tasks extends DolibarrApi
}
$this->project->getLinesArray(DolibarrApiAccess::$user);
$result = array();
- foreach ($this->project->lines as $line) // $line is a task
+ foreach ($this->project->lines as $line) // $line is a task
{
if ($includetimespent == 1)
{
@@ -252,7 +252,7 @@ class Tasks extends DolibarrApi
return $result;
}
*/
-
+
/**
* Get roles a user is assigned to a task with
*
@@ -265,20 +265,20 @@ class Tasks extends DolibarrApi
*/
function getRoles($id, $userid=0) {
global $db;
-
+
if(! DolibarrApiAccess::$user->rights->projet->lire) {
throw new RestException(401);
}
-
+
$result = $this->task->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Task not found');
}
-
+
if( ! DolibarrApi::_checkAccessToResource('task',$this->task->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
-
+
$usert = DolibarrApiAccess::$user;
if ($userid > 0)
{
@@ -292,8 +292,8 @@ class Tasks extends DolibarrApi
}
return $result;
}
-
-
+
+
/**
* Add a task to given project
*
@@ -348,13 +348,13 @@ class Tasks extends DolibarrApi
);
if ($updateRes > 0) {
- return $this->get($id)->line->rowid;
+ return $updateRes;
}
return false;
}
*/
-
+
/**
* Update a task to given project
*
@@ -412,8 +412,8 @@ class Tasks extends DolibarrApi
}
return false;
}*/
-
-
+
+
/**
* Update task general fields (won't touch time spent of task)
*
@@ -484,7 +484,7 @@ class Tasks extends DolibarrApi
}
-
+
/**
* Add time spent to a task of a project.
* You can test this API with the following input message
@@ -495,15 +495,15 @@ class Tasks extends DolibarrApi
* @param int $duration Duration in seconds (3600 = 1h)
* @param int $user_id User (Use 0 for connected user)
* @param string $note Note
- *
+ *
* @url POST {id}/addtimespent
*
* @return array
*/
function addTimeSpent($id, $date, $duration, $user_id=0, $note='')
{
-
-
+
+
if( ! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401);
}
@@ -511,22 +511,22 @@ class Tasks extends DolibarrApi
if ($result <= 0) {
throw new RestException(404, 'Task not found');
}
-
+
if( ! DolibarrApi::_checkAccessToResource('project', $this->task->fk_project)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
-
+
$uid = $user_id;
if (empty($uid)) $uid = DolibarrApiAccess::$user->id;
- $newdate = dol_stringtotime($date, 1);
+ $newdate = dol_stringtotime($date, 1);
$this->task->timespent_date = $newdate;
$this->task->timespent_datehour = $newdate;
$this->task->timespent_withhour = 1;
$this->task->timespent_duration = $duration;
$this->task->timespent_fk_user = $user_id;
- $this->task->timespent_note = $note;
-
+ $this->task->timespent_note = $note;
+
$result = $this->task->addTimeSpent(DolibarrApiAccess::$user, 0);
if ($result == 0) {
throw new RestException(500, 'Error nothing done. May be object is already validated');
@@ -534,7 +534,7 @@ class Tasks extends DolibarrApi
if ($result < 0) {
throw new RestException(500, 'Error when adding time: '.$this->task->error);
}
-
+
return array(
'success' => array(
'code' => 200,
@@ -542,8 +542,8 @@ class Tasks extends DolibarrApi
)
);
}
-
-
+
+
/**
* Clean sensible object datas
*
@@ -551,9 +551,9 @@ class Tasks extends DolibarrApi
* @return array Array of cleaned object properties
*/
function _cleanObjectDatas($object) {
-
+
$object = parent::_cleanObjectDatas($object);
-
+
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
@@ -575,21 +575,21 @@ class Tasks extends DolibarrApi
unset($object->country);
unset($object->country_id);
unset($object->country_code);
-
+
unset($object->weekWorkLoad);
unset($object->weekWorkLoad);
-
+
//unset($object->lines); // for task we use timespent_lines, but for project we use lines
-
+
unset($object->total_ht);
unset($object->total_tva);
unset($object->total_localtax1);
unset($object->total_localtax2);
unset($object->total_ttc);
-
+
return $object;
}
-
+
/**
* Validate fields before create or update object
*
@@ -608,8 +608,8 @@ class Tasks extends DolibarrApi
}
return $object;
}
-
-
+
+
// TODO
// getSummaryOfTimeSpent
}