2
0
forked from Wavyzz/dolibarr

NEW Add API to activate/unactivate a contract

This commit is contained in:
Laurent Destailleur
2017-11-14 17:51:04 +01:00
parent e37252d83a
commit 451d3ed8ed
3 changed files with 82 additions and 2 deletions

View File

@@ -346,6 +346,83 @@ class Contracts extends DolibarrApi
return false; return false;
} }
/**
* Activate a service line of a given contract
*
* @param int $id Id of contract to activate
* @param int $lineid Id of line to activate
* @param string $datestart {@from body} Date start {@type timestamp}
* @param string $datend {@from body} Date end {@type timestamp}
* @param string $comment {@from body} Comment
*
* @url PUT {id}/lines/{lineid}/activate
*
* @return object
*/
function activateLine($id, $lineid, $datestart, $dateend = NULL, $comment = 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);
}
$updateRes = $this->contract->active_line(DolibarrApiAccess::$user, $lineid, $datestart, $dateend, $comment);
if ($updateRes > 0) {
$result = $this->get($id);
unset($result->line);
return $this->_cleanObjectDatas($result);
}
return false;
}
/**
* Unactivate a service line of a given contract
*
* @param int $id Id of contract to activate
* @param int $lineid Id of line to activate
* @param string $datestart {@from body} Date start {@type timestamp}
* @param string $comment {@from body} Comment
*
* @url PUT {id}/lines/{lineid}/unactivate
*
* @return object
*/
function unactivateLine($id, $lineid, $datestart, $comment = 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->close_line(DolibarrApiAccess::$user, $lineid, $datestart, $comment);
if ($updateRes > 0) {
$result = $this->get($id);
unset($result->line);
return $this->_cleanObjectDatas($result);
}
return false;
}
/** /**
* Delete a line to given contract * Delete a line to given contract
* *

View File

@@ -615,7 +615,10 @@ class FormFile
$modelselected=$arraykeys[0]; $modelselected=$arraykeys[0];
} }
$out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100'); $out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
$out.= ajax_combobox('model'); if ($conf->use_javascript_ajax)
{
$out.= ajax_combobox('model');
}
} }
else else
{ {

View File

@@ -5850,7 +5850,7 @@ function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
// If inline message with no format, we add it. // If inline message with no format, we add it.
if ((empty($conf->use_javascript_ajax) || ! empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) || $keepembedded) && ! preg_match('/<div class=".*">/i',$out)) if ((empty($conf->use_javascript_ajax) || ! empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) || $keepembedded) && ! preg_match('/<div class=".*">/i',$out))
{ {
$divstart='<div class="'.$style.'">'; $divstart='<div class="'.$style.' clearboth">';
$divend='</div>'; $divend='</div>';
} }