NEW Add api validate and close on contracts
This commit is contained in:
parent
6d6c4bf088
commit
4f6304624a
@ -269,8 +269,8 @@ class Contracts extends DolibarrApi
|
||||
$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->date_start, // date_start = date planned start, date ouverture = date_start_real
|
||||
$request_data->date_end, // date_end = date planned end, date_cloture = date_end_real
|
||||
$request_data->HT,
|
||||
$request_data->subprice_excl_tax,
|
||||
$request_data->info_bits,
|
||||
@ -450,7 +450,6 @@ class Contracts extends DolibarrApi
|
||||
* 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
|
||||
@ -460,12 +459,10 @@ class Contracts extends DolibarrApi
|
||||
* 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)
|
||||
function validate($id, $notrigger=0)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->contrat->creer) {
|
||||
throw new RestException(401);
|
||||
@ -479,7 +476,7 @@ class Contracts extends DolibarrApi
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
$result = $this->contract->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
|
||||
$result = $this->contract->validate(DolibarrApiAccess::$user, '', $notrigger);
|
||||
if ($result == 0) {
|
||||
throw new RestException(500, 'Error nothing done. May be object is already validated');
|
||||
}
|
||||
@ -494,7 +491,54 @@ class Contracts extends DolibarrApi
|
||||
)
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Close all services of a contract
|
||||
*
|
||||
* @param int $id Contract ID
|
||||
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
||||
*
|
||||
* @url POST {id}/close
|
||||
*
|
||||
* @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
|
||||
* {
|
||||
* "notrigger": 0
|
||||
* }
|
||||
*/
|
||||
function close($id, $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->closeAll(DolibarrApiAccess::$user, $notrigger);
|
||||
if ($result == 0) {
|
||||
throw new RestException(500, 'Error nothing done. May be object is already close');
|
||||
}
|
||||
if ($result < 0) {
|
||||
throw new RestException(500, 'Error when closing Contract: '.$this->contract->error);
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => array(
|
||||
'code' => 200,
|
||||
'message' => 'Contract closed (Ref='.$this->contract->ref.'). All services were closed.'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Clean sensible object datas
|
||||
@ -508,6 +552,16 @@ class Contracts extends DolibarrApi
|
||||
|
||||
unset($object->address);
|
||||
|
||||
unset($object->date_ouverture_prevue);
|
||||
unset($object->date_ouverture);
|
||||
unset($object->date_fin_validite);
|
||||
unset($object->date_cloture);
|
||||
unset($object->date_debut_prevue);
|
||||
unset($object->date_debut_reel);
|
||||
unset($object->date_fin_prevue);
|
||||
unset($object->date_fin_reel);
|
||||
unset($object->civility_id);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
@ -298,12 +298,13 @@ class Contrat extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all lines of a contract
|
||||
* Close all lines of a contract
|
||||
*
|
||||
* @param User $user Object User making action
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @param User $user Object User making action
|
||||
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function closeAll($user)
|
||||
function closeAll(User $user, $notrigger=0)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
@ -330,7 +331,7 @@ class Contrat extends CommonObject
|
||||
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
$result=$this->validate($user);
|
||||
$result=$this->validate($user, '', $notrigger);
|
||||
if ($result < 0) $ok=false;
|
||||
}
|
||||
|
||||
@ -355,7 +356,7 @@ class Contrat extends CommonObject
|
||||
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function validate($user, $force_number='', $notrigger=0)
|
||||
function validate(User $user, $force_number='', $notrigger=0)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
global $langs, $conf;
|
||||
@ -741,12 +742,12 @@ class Contrat extends CommonObject
|
||||
$line->fk_unit = $objp->fk_unit;
|
||||
|
||||
$line->ref = $objp->product_ref; // deprecated
|
||||
if (empty($objp->fk_product))
|
||||
if (empty($objp->fk_product))
|
||||
{
|
||||
$line->label = ''; // deprecated
|
||||
$line->libelle = $objp->description; // deprecated
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
$line->label = $objp->product_label; // deprecated
|
||||
$line->libelle = $objp->product_label; // deprecated
|
||||
@ -757,11 +758,15 @@ class Contrat extends CommonObject
|
||||
|
||||
$line->description = $objp->description;
|
||||
|
||||
$line->date_start = $this->db->jdate($objp->date_ouverture_prevue);
|
||||
$line->date_start_real = $this->db->jdate($objp->date_ouverture);
|
||||
$line->date_end = $this->db->jdate($objp->date_fin_validite);
|
||||
$line->date_end_real = $this->db->jdate($objp->date_cloture);
|
||||
// For backward compatibility
|
||||
$line->date_ouverture_prevue = $this->db->jdate($objp->date_ouverture_prevue);
|
||||
$line->date_ouverture = $this->db->jdate($objp->date_ouverture);
|
||||
$line->date_fin_validite = $this->db->jdate($objp->date_fin_validite);
|
||||
$line->date_cloture = $this->db->jdate($objp->date_cloture);
|
||||
// For backward compatibility
|
||||
$line->date_debut_prevue = $this->db->jdate($objp->date_ouverture_prevue);
|
||||
$line->date_debut_reel = $this->db->jdate($objp->date_ouverture);
|
||||
$line->date_fin_prevue = $this->db->jdate($objp->date_fin_validite);
|
||||
@ -2242,10 +2247,10 @@ class Contrat extends CommonObject
|
||||
$line->total_ht=90;
|
||||
$line->total_ttc=107.64; // 90 * 1.196
|
||||
$line->total_tva=17.64;
|
||||
$line->date_ouverture = dol_now() - 200000;
|
||||
$line->date_ouverture_prevue = dol_now() - 500000;
|
||||
$line->date_fin_validite = dol_now() + 500000;
|
||||
$line->date_cloture = dol_now() - 100000;
|
||||
$line->date_start = dol_now() - 500000;
|
||||
$line->date_start_real = dol_now() - 200000;
|
||||
$line->date_end = dol_now() + 500000;
|
||||
$line->date_end_real = dol_now() - 100000;
|
||||
if ($num_prods > 0)
|
||||
{
|
||||
$prodid = mt_rand(1, $num_prods);
|
||||
@ -2458,6 +2463,12 @@ class ContratLigne extends CommonObjectLine
|
||||
var $product_label;
|
||||
|
||||
var $date_commande;
|
||||
|
||||
var $date_start; // date start planned
|
||||
var $date_start_real; // date start real
|
||||
var $date_end; // date end planned
|
||||
var $date_end_real; // date end real
|
||||
// For backward compatibility
|
||||
var $date_ouverture_prevue; // date start planned
|
||||
var $date_ouverture; // date start real
|
||||
var $date_fin_validite; // date end planned
|
||||
@ -2693,10 +2704,17 @@ class ContratLigne extends CommonObjectLine
|
||||
$this->label = $obj->label; // deprecated. We do not use this field. Only ref and label of product, and description of contract line
|
||||
$this->description = $obj->description;
|
||||
$this->date_commande = $this->db->jdate($obj->date_commande);
|
||||
|
||||
$this->date_start = $this->db->jdate($obj->date_ouverture_prevue);
|
||||
$this->date_start_real = $this->db->jdate($obj->date_ouverture);
|
||||
$this->date_end = $this->db->jdate($obj->date_fin_validite);
|
||||
$this->date_end_real = $this->db->jdate($obj->date_cloture);
|
||||
// For backward compatibility
|
||||
$this->date_ouverture_prevue = $this->db->jdate($obj->date_ouverture_prevue);
|
||||
$this->date_ouverture = $this->db->jdate($obj->date_ouverture);
|
||||
$this->date_fin_validite = $this->db->jdate($obj->date_fin_validite);
|
||||
$this->date_cloture = $this->db->jdate($obj->date_cloture);
|
||||
|
||||
$this->tva_tx = $obj->tva_tx;
|
||||
$this->vat_src_code = $obj->vat_src_code;
|
||||
$this->localtax1_tx = $obj->localtax1_tx;
|
||||
@ -2784,6 +2802,12 @@ class ContratLigne extends CommonObjectLine
|
||||
if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
|
||||
if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
|
||||
if (empty($this->remise_percent)) $this->remise_percent = 0;
|
||||
// For backward compatibility
|
||||
if (empty($this->date_start)) $this->date_start=$this->date_ouverture_prevue;
|
||||
if (empty($this->date_start_real)) $this->date_start=$this->date_ouverture;
|
||||
if (empty($this->date_end)) $this->date_start=$this->date_fin_validite;
|
||||
if (empty($this->date_end_real)) $this->date_start=$this->date_cloture;
|
||||
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
|
||||
@ -41,6 +41,7 @@ YouCanEditHtmlSourceckeditor=You can edit HTML source code using the "Source" bu
|
||||
YouCanEditHtmlSource=<br><span class="fa fa-bug"></span> You can include PHP code into this source using tags <strong><?php ?></strong>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.<br><br><span class="fa fa-bug"></span> You can also include content of another Page/Container with the following syntax:<br><strong><?php dolIncludeHtmlContent($websitekey.'/alias_of_container_to_include.php'); ?></strong><br><br><span class="fa fa-download"></span> To include a <strong>link to download</strong> a file stored into the <strong>documents</strong> directory, use the <strong>document.php</strong> wrapper:<br>Example, for a file into documents/ecm (need to be logged), syntax is:<br><strong><a href="/document.php?modulepart=ecm&file=relative_dir/filename.ext"></strong><br>For same file into documents/ecm (open access using the sharing hash key), syntax is:<br><strong><a href="/document.php?modulepart=ecm&file=relative_dir/filename.ext&hashp=publicsharekeyoffile"></strong><br>For a file into documents/media (open directory for public access), syntax is:<br><strong><a href="/document.php?modulepart=medias&file=relative_dir/filename.ext"></strong><br><br><span class="fa fa-picture-o"></span> To include an <strong>image</strong> stored into the <strong>documents</strong> directory, use the <strong>viewimage.php</strong> wrapper:<br>Example, for an image into documents/media (open access), syntax is:<br><strong><a href="/viewimage.php?modulepart=medias&file=relative_dir/filename.ext"></strong><br>
|
||||
ClonePage=Clone page/container
|
||||
CloneSite=Clone site
|
||||
SiteAdded=Web site added
|
||||
ConfirmClonePage=Please enter code/alias of new page and if it is a translation of the cloned page.
|
||||
PageIsANewTranslation=The new page is a translation of the current page ?
|
||||
LanguageMustNotBeSameThanClonedPage=You clone a page as a translation. The language of the new page must be different than language of source page.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user