Add API "close" for proposals
Standardize code
This commit is contained in:
parent
347883b7be
commit
d40dda83cf
@ -612,14 +612,15 @@ if (empty($reshook))
|
|||||||
// Close proposal
|
// Close proposal
|
||||||
else if ($action == 'setstatut' && $user->rights->propal->cloturer && ! GETPOST('cancel','alpha'))
|
else if ($action == 'setstatut' && $user->rights->propal->cloturer && ! GETPOST('cancel','alpha'))
|
||||||
{
|
{
|
||||||
if (! GETPOST('statut')) {
|
if (! GETPOST('statut','int')) {
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors');
|
||||||
$action = 'statut';
|
$action = 'statut';
|
||||||
} else {
|
} else {
|
||||||
// prevent browser refresh from closing proposal several times
|
// prevent browser refresh from closing proposal several times
|
||||||
if ($object->statut == Propal::STATUS_VALIDATED)
|
if ($object->statut == Propal::STATUS_VALIDATED)
|
||||||
{
|
{
|
||||||
$result=$object->cloture($user, GETPOST('statut','int'), GETPOST('note_private','alpha'));
|
$newprivatenote = dol_concatdesc($object->note_private, GETPOST('note_private','alpha'));
|
||||||
|
$result=$object->cloture($user, GETPOST('statut','int'), $newprivatenote);
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
|
|||||||
@ -90,7 +90,7 @@ class Proposals extends DolibarrApi
|
|||||||
* @param string $sortorder Sort order
|
* @param string $sortorder Sort order
|
||||||
* @param int $limit Limit for list
|
* @param int $limit Limit for list
|
||||||
* @param int $page Page number
|
* @param int $page Page number
|
||||||
* @param string $thirdparty_ids Thirdparty ids to filter commercial proposal of. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i}
|
* @param string $thirdparty_ids Thirdparty ids to filter commercial proposal of. Example: '1' or '1,2,3' {@pattern /^2|3$/i}
|
||||||
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
|
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
|
||||||
* @return array Array of order objects
|
* @return array Array of order objects
|
||||||
*/
|
*/
|
||||||
@ -507,6 +507,48 @@ class Proposals extends DolibarrApi
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close (Accept or refuse) a quote / commercial proposal
|
||||||
|
*
|
||||||
|
* @param int $id Commercial proposal ID
|
||||||
|
* @param int $status Must be 2 (accepted) or 3 (refused) {@min 2}{@max 3}
|
||||||
|
* @param string $note_private Add this mention to the private note
|
||||||
|
* @param int $notrigger Disabled triggers
|
||||||
|
*
|
||||||
|
* @url POST {id}/close
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function close($id, $status, $note_private='', $notrigger=0)
|
||||||
|
{
|
||||||
|
if(! DolibarrApiAccess::$user->rights->propal->creer) {
|
||||||
|
throw new RestException(401);
|
||||||
|
}
|
||||||
|
$result = $this->propal->fetch($id);
|
||||||
|
if( ! $result ) {
|
||||||
|
throw new RestException(404, 'Commercial Proposal not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) {
|
||||||
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->propal->cloture(DolibarrApiAccess::$user, $status, $note_private, $notrigger);
|
||||||
|
if ($result == 0) {
|
||||||
|
throw new RestException(500, 'Error nothing done. May be object is already closed');
|
||||||
|
}
|
||||||
|
if ($result < 0) {
|
||||||
|
throw new RestException(500, 'Error when closing Commercial Proposal: '.$this->propal->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'success' => array(
|
||||||
|
'code' => 200,
|
||||||
|
'message' => 'Commercial Proposal closed (Ref='.$this->propal->ref.')'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate fields before create or update object
|
* Validate fields before create or update object
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1505,48 +1505,6 @@ class Propal extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update value of extrafields on the proposal
|
|
||||||
*
|
|
||||||
* @param User $user Object user that modify
|
|
||||||
* @return int <0 if ko, >0 if ok
|
|
||||||
*/
|
|
||||||
function update_extrafields($user)
|
|
||||||
{
|
|
||||||
global $conf, $hookmanager;
|
|
||||||
|
|
||||||
$action='update';
|
|
||||||
$error = 0;
|
|
||||||
|
|
||||||
// Actions on extra fields (by external module or standard code)
|
|
||||||
// TODO le hook fait double emploi avec le trigger !!
|
|
||||||
$hookmanager->initHooks(array('propaldao'));
|
|
||||||
$parameters=array('id'=>$this->id);
|
|
||||||
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
||||||
if (empty($reshook))
|
|
||||||
{
|
|
||||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
|
||||||
{
|
|
||||||
$result=$this->insertExtraFields();
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ($reshook < 0) $error++;
|
|
||||||
|
|
||||||
if (!$error)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set status to validated
|
* Set status to validated
|
||||||
*
|
*
|
||||||
@ -2258,7 +2216,7 @@ class Propal extends CommonObject
|
|||||||
* @param User $user Object user that close
|
* @param User $user Object user that close
|
||||||
* @param int $statut Statut
|
* @param int $statut Statut
|
||||||
* @param string $note Comment
|
* @param string $note Comment
|
||||||
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function cloture($user, $statut, $note, $notrigger=0)
|
function cloture($user, $statut, $note, $notrigger=0)
|
||||||
@ -2297,7 +2255,7 @@ class Propal extends CommonObject
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($statut == self::STATUS_BILLED)
|
if ($statut == self::STATUS_BILLED) // Why this ?
|
||||||
{
|
{
|
||||||
$trigger_name='PROPAL_CLASSIFY_BILLED';
|
$trigger_name='PROPAL_CLASSIFY_BILLED';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1077,11 +1077,12 @@ class Commande extends CommonOrder
|
|||||||
* Load an object from a proposal and create a new order into database
|
* Load an object from a proposal and create a new order into database
|
||||||
*
|
*
|
||||||
* @param Object $object Object source
|
* @param Object $object Object source
|
||||||
|
* @param User $user User making creation
|
||||||
* @return int <0 if KO, 0 if nothing done, 1 if OK
|
* @return int <0 if KO, 0 if nothing done, 1 if OK
|
||||||
*/
|
*/
|
||||||
function createFromProposal($object)
|
function createFromProposal($object, User $user)
|
||||||
{
|
{
|
||||||
global $conf,$user,$hookmanager;
|
global $conf, $hookmanager;
|
||||||
|
|
||||||
dol_include_once('/core/class/extrafields.class.php');
|
dol_include_once('/core/class/extrafields.class.php');
|
||||||
|
|
||||||
@ -3048,48 +3049,6 @@ class Commande extends CommonOrder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update value of extrafields on order
|
|
||||||
*
|
|
||||||
* @param User $user Object user that modify
|
|
||||||
* @return int <0 if ko, >0 if ok
|
|
||||||
*/
|
|
||||||
function update_extrafields($user)
|
|
||||||
{
|
|
||||||
global $hookmanager, $conf;
|
|
||||||
|
|
||||||
$action='create';
|
|
||||||
$error = 0;
|
|
||||||
|
|
||||||
// Actions on extra fields (by external module or standard code)
|
|
||||||
// TODO le hook fait double emploi avec le trigger !!
|
|
||||||
$hookmanager->initHooks(array('orderdao'));
|
|
||||||
$parameters=array('id'=>$this->id);
|
|
||||||
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
||||||
if (empty($reshook))
|
|
||||||
{
|
|
||||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
|
||||||
{
|
|
||||||
$result=$this->insertExtraFields();
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ($reshook < 0) $error++;
|
|
||||||
|
|
||||||
if (!$error)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the customer order
|
* Delete the customer order
|
||||||
*
|
*
|
||||||
|
|||||||
@ -747,7 +747,7 @@ class Facture extends CommonInvoice
|
|||||||
* @param int $invertdetail Reverse sign of amounts for lines
|
* @param int $invertdetail Reverse sign of amounts for lines
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function createFromCurrent($user,$invertdetail=0)
|
function createFromCurrent(User $user, $invertdetail=0)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
@ -948,11 +948,12 @@ class Facture extends CommonInvoice
|
|||||||
* Load an object from an order and create a new invoice into database
|
* Load an object from an order and create a new invoice into database
|
||||||
*
|
*
|
||||||
* @param Object $object Object source
|
* @param Object $object Object source
|
||||||
|
* @param User $user Object user
|
||||||
* @return int <0 if KO, 0 if nothing done, 1 if OK
|
* @return int <0 if KO, 0 if nothing done, 1 if OK
|
||||||
*/
|
*/
|
||||||
function createFromOrder($object)
|
function createFromOrder($object, User $user)
|
||||||
{
|
{
|
||||||
global $user,$hookmanager;
|
global $hookmanager;
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
|
|||||||
@ -65,7 +65,7 @@ class InterfaceWorkflowManager extends DolibarrTriggers
|
|||||||
$newobject->context['origin'] = $object->element;
|
$newobject->context['origin'] = $object->element;
|
||||||
$newobject->context['origin_id'] = $object->id;
|
$newobject->context['origin_id'] = $object->id;
|
||||||
|
|
||||||
$ret=$newobject->createFromProposal($object);
|
$ret=$newobject->createFromProposal($object, $user);
|
||||||
if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
|
if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ class InterfaceWorkflowManager extends DolibarrTriggers
|
|||||||
$newobject->context['origin'] = $object->element;
|
$newobject->context['origin'] = $object->element;
|
||||||
$newobject->context['origin_id'] = $object->id;
|
$newobject->context['origin_id'] = $object->id;
|
||||||
|
|
||||||
$ret=$newobject->createFromOrder($object);
|
$ret=$newobject->createFromOrder($object, $user);
|
||||||
if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
|
if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1304,44 +1304,6 @@ class SupplierProposal extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update value of extrafields on the proposal
|
|
||||||
*
|
|
||||||
* @param User $user Object user that modify
|
|
||||||
* @return int <0 if ko, >0 if ok
|
|
||||||
*/
|
|
||||||
function update_extrafields($user)
|
|
||||||
{
|
|
||||||
$action='update';
|
|
||||||
|
|
||||||
// Actions on extra fields (by external module or standard code)
|
|
||||||
$hookmanager->initHooks(array('supplier_proposaldao'));
|
|
||||||
$parameters=array('id'=>$this->id);
|
|
||||||
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
||||||
if (empty($reshook))
|
|
||||||
{
|
|
||||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
|
||||||
{
|
|
||||||
$result=$this->insertExtraFields();
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ($reshook < 0) $error++;
|
|
||||||
|
|
||||||
if (!$error)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set status to validated
|
* Set status to validated
|
||||||
*
|
*
|
||||||
|
|||||||
@ -700,7 +700,7 @@ function createInvoiceFromOrder($authentication,$id_order='', $ref_order='', $re
|
|||||||
{
|
{
|
||||||
|
|
||||||
$newobject=new Facture($db);
|
$newobject=new Facture($db);
|
||||||
$result = $newobject->createFromOrder($order);
|
$result = $newobject->createFromOrder($order, $fuser);
|
||||||
|
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user