Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
ldestailleur 2025-10-01 19:57:33 +02:00
commit fcb55feb50
19 changed files with 1085 additions and 20 deletions

View file

@ -328,6 +328,11 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' &&
$moduleobject = strtolower($moduleobject);
$moduledirforclass = getModuleDirForApiClass($moduleobject);
// this works, but is only necessary because I don't know how to get getModuleDirForApiClass to answer correctly with comm/mailing
if ($moduleobject == 'mailings') {
$moduledirforclass = 'comm/mailing';
}
// Load a dedicated API file
dol_syslog("Load a dedicated API file moduleobject=".$moduleobject." moduledirforclass=".$moduledirforclass);

View file

@ -69,6 +69,8 @@ class Categorie extends CommonObject
const TYPE_INVOICE = 'invoice';
const TYPE_SUPPLIER_ORDER = 'supplier_order';
const TYPE_SUPPLIER_INVOICE = 'supplier_invoice';
const TYPE_SUPPLIER_PROPOSAL = 'supplier_proposal';
const TYPE_PROPOSAL = 'propal';
/**
@ -99,7 +101,9 @@ class Categorie extends CommonObject
'order' => 16,
'invoice' => 17,
'supplier_order' => 20,
'supplier_invoice' => 21
'supplier_invoice' => 21,
'supplier_proposal' => 22,
'propal' => 23
);
/**

View file

@ -0,0 +1,689 @@
<?php
/* Copyright (C) 2025 Cloned from htdocs/comm/propal/class/api_proposals.class.php then modified
* Copyright (C) 2025 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
*
* 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 <https://www.gnu.org/licenses/>.
*/
use Luracast\Restler\RestException;
require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
/**
* API class for mass mailings
*
* @since 23.0.0 Initial implementation
*
* @access protected
* @class DolibarrApiAccess {@requires user,external}
*/
class Mailings extends DolibarrApi
{
/**
* @var string[] Mandatory fields, checked when create and update object
*/
public static $FIELDS = array(
'title',
'sujet',
'body'
);
/**
* @var Mailing {@type Mailing}
*/
public $mailing;
/**
* Constructor
*/
public function __construct()
{
global $db;
$this->db = $db;
$this->mailing = new Mailing($this->db);
}
/**
* Get a mass mailing
*
* Return an array with mass mailing information
*
* @since 23.0.0 Initial implementation
*
* @param int $id ID of mass mailing
* @return Object Object with cleaned properties
*
* @throws RestException
*/
public function get($id)
{
return $this->_fetch($id);
}
/**
* Get properties of an mailing object
*
* Return an array with mailing information
*
* @param int $id ID of mailing object
* @return Object Object with cleaned properties
*
* @throws RestException
*/
private function _fetch($id)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'read')) {
throw new RestException(403);
}
$result = $this->mailing->fetch($id);
if ($result < 0) {
throw new RestException(404, 'Mass mailing not found, id='.$id);
}
if (!DolibarrApi::_checkAccessToResource('mailing', $this->mailing->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->mailing->fetchObjectLinked();
return $this->_cleanObjectDatas($this->mailing);
}
/**
* List mass mailings
*
* Get a list of mass mailings
*
* @since 23.0.0 Initial implementation
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'2016-01-01')"
* @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
* @param bool $pagination_data If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0*
* @param int $loadlinkedobjects Load also linked object
* @return array Array of order objects
* @phan-return Mailing[]|array{data:Mailing[],pagination:array{total:int,page:int,page_count:int,limit:int}}
* @phpstan-return Mailing[]|array{data:Mailing[],pagination:array{total:int,page:int,page_count:int,limit:int}}
*
* @throws RestException
*/
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '', $pagination_data = false, $loadlinkedobjects = 0)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'read')) {
throw new RestException(403);
}
$obj_ret = array();
$sql = "SELECT t.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing AS t";
$sql .= ' WHERE t.entity IN ('.getEntity('mailing').')';
// Add sql filters
if ($sqlfilters) {
$errormessage = '';
$sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
if ($errormessage) {
throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
}
}
//this query will return total mass mailings with the filters given
$sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
$sql .= $this->db->plimit($limit + 1, $offset);
}
dol_syslog("API Rest request mass mailing");
$result = $this->db->query($sql);
if ($result) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
$i = 0;
while ($i < $min) {
$obj = $this->db->fetch_object($result);
$mailing_static = new Mailing($this->db);
if ($mailing_static->fetch($obj->rowid) > 0) {
if ($loadlinkedobjects) {
// retrieve linked objects
$mailing_static->fetchObjectLinked();
}
$obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($mailing_static), $properties);
}
$i++;
}
} else {
throw new RestException(503, 'Error when retrieve list of mass mailings : '.$this->db->lasterror());
}
//if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
if ($pagination_data) {
$totalsResult = $this->db->query($sqlTotals);
$total = $this->db->fetch_object($totalsResult)->total;
$tmp = $obj_ret;
$obj_ret = [];
$obj_ret['data'] = $tmp;
$obj_ret['pagination'] = [
'total' => (int) $total,
'page' => $page, //count starts from 0
'page_count' => ceil((int) $total / $limit),
'limit' => $limit
];
}
return $obj_ret;
}
/**
* Clone a mass mailing
*
* @since 23.0.0 Initial implementation
*
* @param int $id Id of object to clone
* @param int $cloneContent 1=Clone content (default), 0=Forget content
* @param int $cloneRecipients 1=Clone recipients (default), 0=Forget recipients
* @param int $notrigger 1=Disable triggers, 0=Active triggers if any (default)
* @return Object Object with cleaned properties
*
* @throws RestException 403
* @throws RestException 404
* @throws RestException 500 System error
*/
public function clone($id, $cloneContent = 1, $cloneRecipients = 1, $notrigger = 0)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'write')) {
throw new RestException(403, "Insufficient rights");
}
$result = $this->mailing->fetch($id);
if ($result < 0) {
throw new RestException(404, 'Mass mailing to clone not found, id='.$id);
}
$cloningResult = $this->mailing->createFromClone(DolibarrApiAccess::$user, ((int) $id), ((int) $cloneContent), ((int) $cloneRecipients), ((int) $notrigger));
if ($cloningResult < 0) {
throw new RestException(500, "Error cloning mass mailing", array_merge(array($this->mailing->error), $this->mailing->errors));
}
if ($cloningResult > 0) {
return $this->get($cloningResult);
} else {
throw new RestException(500, $this->mailing->error);
}
}
/**
* Create a mass mailing
*
* @since 23.0.0 Initial implementation
*
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return int ID of mass mailing
*
* @throws RestException
*/
public function post($request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'write')) {
throw new RestException(403, "Insufficiant rights");
}
// Check mandatory fields
$result = $this->_validate($request_data);
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$this->mailing->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$this->mailing->$field = $this->_checkValForAPI($field, $value, $this->mailing);
}
if ($this->mailing->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating mass mailing", array_merge(array($this->mailing->error), $this->mailing->errors));
}
return ((int) $this->mailing->id);
}
/**
* Update a mass mailing general fields (won't change lines of mass mailing)
*
* @since 23.0.0 Initial implementation
*
* @param int $id Id of mass mailing to update
* @param array $request_data Datas
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return Object Object with cleaned properties
*
* @throws RestException
*/
public function put($id, $request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'write')) {
throw new RestException(403);
}
$result = $this->mailing->fetch($id);
if ($result < 0) {
throw new RestException(404, 'Mass mailing not found, id='.$id);
}
if (!DolibarrApi::_checkAccessToResource('mailing', $this->mailing->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
foreach ($request_data as $field => $value) {
if ($field == 'id') {
continue;
}
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$this->mailing->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->mailing->array_options[$index] = $this->_checkValForAPI($field, $val, $this->mailing);
}
continue;
}
$this->mailing->$field = $this->_checkValForAPI($field, $value, $this->mailing);
}
if ($this->mailing->update(DolibarrApiAccess::$user) > 0) {
return $this->get($id);
} else {
throw new RestException(500, $this->mailing->error);
}
}
/**
* Delete a mass mailing
*
* @since 23.0.0 Initial implementation
*
* @param int $id Mass mailing ID
* @return array
* @phan-return array{success:array{code:int,message:string}}
* @phpstan-return array{success:array{code:int,message:string}}
*
* @throws RestException 403
* @throws RestException 404
* @throws RestException 500 System error
*/
public function delete($id)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'delete')) {
throw new RestException(403);
}
$result = $this->mailing->fetch($id);
if ($result < 0) {
throw new RestException(404, 'Mass mailing not found, id='.$id);
}
if (!DolibarrApi::_checkAccessToResource('mailing', $this->mailing->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if (!$this->mailing->delete(DolibarrApiAccess::$user)) {
throw new RestException(500, 'Error when delete Mass mailing : '.$this->mailing->error);
}
return array(
'success' => array(
'code' => 200,
'message' => 'Mass mailing with id='.$id.' deleted'
)
);
}
/**
* Delete targets of a mass mailing
*
* @since 23.0.0 Initial implementation
*
* @param int $id Mass mailing ID
* @return array
* @phan-return array{success:array{code:int,message:string}}
* @phpstan-return array{success:array{code:int,message:string}}
*
* @url DELETE {id}/deleteTargets
*
* @throws RestException 403
* @throws RestException 404
* @throws RestException 500 System error
*/
public function deleteTargets($id)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'delete')) {
throw new RestException(403);
}
$result = $this->mailing->fetch($id);
if ($result < 0) {
throw new RestException(404, 'Mass mailing not found, id='.$id);
}
if (!DolibarrApi::_checkAccessToResource('mailing', $this->mailing->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$count = $this->mailing->countNbOfTargets('all');
if (!$this->mailing->delete_targets()) {
throw new RestException(500, 'Error when delete targets of Mass mailing : '.$this->mailing->error);
}
return array(
'success' => array(
'code' => 200,
'message' => 'Target recipients ('.$count.') of Mass mailing with id='.$id.' deleted'
)
);
}
/**
* reset target status of a mass mailing
*
* @since 23.0.0 Initial implementation
*
* @param int $id Mass mailing ID
* @return array
* @phan-return array{success:array{code:int,message:string}}
* @phpstan-return array{success:array{code:int,message:string}}
*
* @url PUT {id}/resetTargetsStatus
*
* @throws RestException 403
* @throws RestException 404
* @throws RestException 500 System error
*/
public function resetTargetsStatus($id)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'write')) {
throw new RestException(403);
}
$result = $this->mailing->fetch($id);
if ($result < 0) {
throw new RestException(404, 'Mass mailing not found, id='.$id);
}
if (!DolibarrApi::_checkAccessToResource('mailing', $this->mailing->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$count = $this->mailing->countNbOfTargets('all');
if (!$this->mailing->reset_targets_status(DolibarrApiAccess::$user)) {
throw new RestException(500, 'Error when reset targets status of Mass mailing : '.$this->mailing->error);
}
return array(
'success' => array(
'code' => 200,
'message' => 'Resetting status of '.$count.' target recipients in Mass mailing with id='.$id
)
);
}
/**
* Set a mass mailing to draft
*
* @since 23.0.0 Initial implementation
*
* @param int $id Mass mailing ID
* @return Object Object with cleaned properties
*
* @url PUT {id}/settodraft
*
* @throws RestException 304
* @throws RestException 403
* @throws RestException 404
* @throws RestException 500 System error
*/
public function settodraft($id)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'write')) {
throw new RestException(403);
}
$result = $this->mailing->fetch($id);
if ($result < 0) {
throw new RestException(404, 'Mass mailing not found, id='.$id);
}
if (!DolibarrApi::_checkAccessToResource('mailing', $this->mailing->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->mailing->setDraft(DolibarrApiAccess::$user);
if ($result == 0) {
throw new RestException(304, 'Nothing done. May be object is already draft');
}
if ($result < 0) {
throw new RestException(500, 'Error : '.$this->mailing->error);
}
$this->mailing->fetchObjectLinked();
return $this->_cleanObjectDatas($this->mailing);
}
/**
* Validate a mass mailing
*
* If you get a bad value for param notrigger check that ou provide this in body
* {
* "notrigger": 0
* }
*
* @since 23.0.0 Initial implementation
*
* @param int $id Mass mailing ID
* @return Object Object with cleaned properties
*
* @url PUT {id}/validate
*
* @throws RestException 304
* @throws RestException 403
* @throws RestException 404
* @throws RestException 500 System error
*/
public function validate($id)
{
if (!DolibarrApiAccess::$user->hasRight('mailing', 'write')) {
throw new RestException(403);
}
$result = $this->mailing->fetch($id);
if ($result < 0) {
throw new RestException(404, 'Mass mailing not found, id='.$id);
}
if (!DolibarrApi::_checkAccessToResource('mailing', $this->mailing->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->mailing->valid(DolibarrApiAccess::$user);
if ($result == 0) {
throw new RestException(304, 'Error nothing done. May be object is already validated');
}
if ($result < 0) {
throw new RestException(500, 'Error when validating Mass mailing: '.$this->mailing->error);
}
$this->mailing->fetchObjectLinked();
return $this->_cleanObjectDatas($this->mailing);
}
/**
* Validate fields before create or update object
*
* @param ?array<string,string> $data Array with data to verify
* @return array<string,string>
*
* @throws RestException
*/
private function _validate($data)
{
if ($data === null) {
$data = array();
}
$mailing = array();
foreach (Mailings::$FIELDS as $field) {
if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
}
$mailing[$field] = $data[$field];
}
return $mailing;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
*
* @param Object $object Object to clean
* @return Object Object with cleaned properties
*/
protected function _cleanObjectDatas($object)
{
// phpcs:enable
$object = parent::_cleanObjectDatas($object);
unset($object->actionmsg);
unset($object->actionmsg2);
unset($object->actiontypecode);
unset($object->alreadypaid);
unset($object->barcode_type_code);
unset($object->barcode_type_coder);
unset($object->barcode_type_label);
unset($object->barcode_type);
unset($object->canvas);
unset($object->civility_code);
unset($object->civility_id);
unset($object->comments);
unset($object->cond_reglement_id);
unset($object->cond_reglement_supplier_id);
unset($object->contact_id);
unset($object->contact);
unset($object->contacts_ids_internal);
unset($object->contacts_ids);
unset($object->context);
unset($object->country_code);
unset($object->country_id);
unset($object->country);
unset($object->db);
unset($object->demand_reason_id);
unset($object->deposit_percent);
unset($object->element_for_permission);
unset($object->element);
unset($object->error);
unset($object->errorhidden);
unset($object->errors);
unset($object->fields);
unset($object->firstname);
unset($object->fk_account);
unset($object->fk_bank);
unset($object->fk_delivery_address);
unset($object->fk_element);
unset($object->fk_multicurrency);
unset($object->fk_project);
unset($object->fk_projet);
unset($object->import_key);
unset($object->isextrafieldmanaged);
unset($object->ismultientitymanaged);
unset($object->labelStatus);
unset($object->labelStatusShort);
unset($object->last_main_doc);
unset($object->lastname);
unset($object->lines);
unset($object->linked_objects);
unset($object->linkedObjects);
unset($object->linkedObjectsIds);
unset($object->mode_reglement_id);
unset($object->model_pdf);
unset($object->module);
unset($object->multicurrency_code);
unset($object->multicurrency_total_ht);
unset($object->multicurrency_total_localtax1);
unset($object->multicurrency_total_localtax2);
unset($object->multicurrency_total_ttc);
unset($object->multicurrency_total_tva);
unset($object->multicurrency_tx);
unset($object->name);
unset($object->nb);
unset($object->nbphoto);
unset($object->newref);
unset($object->next_prev_filter);
unset($object->note);
unset($object->oldcopy);
unset($object->oldref);
unset($object->origin_id);
unset($object->origin_object);
unset($object->origin_type);
unset($object->origin);
unset($object->output);
unset($object->product);
unset($object->project);
unset($object->ref_ext);
unset($object->ref_next);
unset($object->ref_previous);
unset($object->ref);
unset($object->region_code);
unset($object->region_id);
unset($object->region);
unset($object->restrictiononfksoc);
unset($object->retained_warranty_fk_cond_reglement);
unset($object->sendtoid);
unset($object->shipping_method_id);
unset($object->shipping_method);
unset($object->showphoto_on_popup);
unset($object->specimen);
unset($object->state_code);
unset($object->state_id);
unset($object->state);
unset($object->table_element_line);
unset($object->table_element);
unset($object->thirdparty);
unset($object->total_ht);
unset($object->total_localtax1);
unset($object->total_localtax2);
unset($object->total_ttc);
unset($object->total_tva);
unset($object->totalpaid_multicurrency);
unset($object->totalpaid);
unset($object->tpl);
unset($object->transport_mode_id);
unset($object->user);
unset($object->warehouse_id);
return $object;
}
}

View file

@ -361,15 +361,26 @@ class Mailing extends CommonObject
*/
public function fetch($rowid, $ref = '')
{
$sql = "SELECT m.rowid, m.messtype, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe";
$sql = "SELECT m.rowid, m.messtype, m.titre as title, m.entity, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe";
$sql .= ", m.note_public, m.note_private";
$sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
$sql .= ", m.statut as status, m.nbemail";
$sql .= ", m.fk_user_creat, m.fk_user_valid";
$sql .= ", m.tms as date_modification";
$sql .= ", m.date_creat";
$sql .= ", m.date_valid";
$sql .= ", m.date_envoi";
$sql .= ", m.extraparams";
$sql .= ", m.tag";
$sql .= ", m.name_from";
$sql .= ", m.fk_user_modif";
$sql .= ", m.fk_user_appro";
$sql .= ", m.date_appro";
$sql .= ", m.cible";
$sql .= ", m.joined_file1";
$sql .= ", m.joined_file2";
$sql .= ", m.joined_file3";
$sql .= ", m.joined_file4";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
$sql .= " WHERE entity IN (".getEntity('mailing').")";
if ($ref) {
@ -385,6 +396,7 @@ class Mailing extends CommonObject
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
$this->entity = $obj->entity;
$this->ref = $obj->rowid;
$this->title = $obj->title;
$this->messtype = $obj->messtype;
@ -417,9 +429,21 @@ class Mailing extends CommonObject
$this->date_creation = $this->db->jdate($obj->date_creat);
$this->date_validation = $this->db->jdate($obj->date_valid);
$this->date_envoi = $this->db->jdate($obj->date_envoi);
$this->date_modification = $this->db->jdate($obj->date_modification); // tms
$this->extraparams = (array) json_decode($obj->extraparams, true);
$this->tag = $obj->tag;
$this->name_from = $obj->name_from;
$this->fk_user_modif = $obj->fk_user_modif;
$this->fk_user_appro = $obj->fk_user_appro;
$this->date_appro = $obj->date_appro;
$this->cible = $obj->cible;
$this->joined_file1 = $obj->joined_file1;
$this->joined_file2 = $obj->joined_file2;
$this->joined_file3 = $obj->joined_file3;
$this->joined_file4 = $obj->joined_file4;
if ($this->messtype == 'sms') {
$this->picto = 'phone';
}
@ -443,9 +467,10 @@ class Mailing extends CommonObject
* @param int $fromid Id of object to clone
* @param int $option1 1=Clone content, 0=Forget content
* @param int $option2 1=Clone recipients
* @param int $notrigger Disable triggers
* @return int New id of clone
*/
public function createFromClone(User $user, $fromid, $option1, $option2)
public function createFromClone(User $user, $fromid, $option1, $option2, $notrigger = 0)
{
global $langs;
@ -488,7 +513,7 @@ class Mailing extends CommonObject
// Create clone
$object->context['createfromclone'] = 'createfromclone';
$result = $object->create($user);
$result = $object->create($user, $notrigger);
// Other options
if ($result < 0) {
@ -577,6 +602,28 @@ class Mailing extends CommonObject
}
}
/**
* SetDraft emailing
*
* @param User $user Object user that makes it draft
* @return int Return integer <0 if KO, >0 if OK
*/
public function setDraft($user)
{
$now = dol_now();
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
$sql .= " SET statut = 0, fk_user_modif=".$user->id;
$sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog("Mailing::valid", LOG_DEBUG);
if ($this->db->query($sql)) {
return 1;
} else {
$this->error = $this->db->lasterror();
return -1;
}
}
/**
* Delete emailing
@ -726,7 +773,7 @@ class Mailing extends CommonObject
/**
* Count number of target with status
*
* @param string $mode Mode ('alreadysent' = Sent success or error, 'alreadysentok' = Sent success, 'alreadysentko' = Sent error)
* @param string $mode Mode ('alreadysent' = Sent success or error, 'alreadysentok' = Sent success, 'alreadysentko' = Sent error, 'all' = Just return all no matter status)
* @return int Nb of target with status
*/
public function countNbOfTargets($mode)
@ -739,6 +786,8 @@ class Mailing extends CommonObject
$sql .= " AND statut > 0";
} elseif ($mode == 'alreadysentko') {
$sql .= " AND statut = -1";
} elseif ($mode == 'all') {
// just want to return all possible recipients
} else {
$this->error = 'BadValueForParameterMode';
return -2;

View file

@ -43,6 +43,7 @@
// Load Dolibarr environment
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formpropal.class.php';
@ -475,6 +476,8 @@ if (empty($reshook)) {
} elseif ($action == 'set_incoterms' && isModEnabled('incoterm') && $usercancreate) {
// Set incoterm
$result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
} elseif ($action == 'settags' && isModEnabled('category') && $usercancreate) { // Set tags
$result = $object->setCategories(GETPOST('categories', 'array'));
} elseif ($action == 'add' && $usercancreate) {
// Create proposal
$object->socid = $socid;
@ -751,6 +754,12 @@ if (empty($reshook)) {
setEventMessages($langs->trans("ErrorFailedToAddUserAsContact"), null, 'errors');
}
}
if (isModEnabled('category')) {
$categories = GETPOST('categories', 'array');
if (method_exists($object, 'setCategories')) {
$object->setCategories($categories);
}
}
if (!$error) {
$db->commit();
@ -2524,7 +2533,12 @@ if ($action == 'create') {
print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms) ? $soc->location_incoterms : ''));
print '</td></tr>';
}
if (isModEnabled('category')) {
// Categories
print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
print $form->selectCategories(Categorie::TYPE_PROPOSAL, 'categories', $object);
print "</td></tr>";
}
// Template to use by default
print '<tr class="field_model">';
print '<td class="titlefieldcreate">' . $langs->trans("DefaultModel") . '</td>';
@ -3311,6 +3325,33 @@ if ($action == 'create') {
print '</td></tr>';
}
// Categories
if (isModEnabled('category')) {
print '<tr><td>';
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans("Categories");
print '<td><td class="right">';
if ($usercancreate) {
print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id.'&action=edittags&token='.newToken().'">'.img_edit().'</a>';
} else {
print '&nbsp;';
}
print '</td></tr></table>';
print '</td>';
print '<td>';
if ($action == 'edittags') {
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
print '<input type="hidden" name="action" value="settags">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print $form->selectCategories(Categorie::TYPE_PROPOSAL, 'categories', $object);
print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
print '</form>';
} else {
print $form->showCategories($object->id, Categorie::TYPE_PROPOSAL, 1);
}
print "</td></tr>";
}
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';

View file

@ -4089,4 +4089,20 @@ class Propal extends CommonObject
$return .= '</div>';
return $return;
}
/**
* Sets object to supplied categories.
*
* Deletes object from existing categories not supplied.
* Adds it to non existing supplied categories.
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
* @return int<-1,1> Return integer <0 if KO, >0 if OK
*/
public function setCategories($categories)
{
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
return parent::setCategoriesCommon($categories, Categorie::TYPE_PROPOSAL);
}
}

View file

@ -108,6 +108,13 @@ $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'a
$search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
$search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
$search_login = GETPOST('search_login', 'alpha');
$searchCategoryPropalList = GETPOST('search_category_propal_list', 'array:int');
$searchCategoryPropalOperator = 0;
if (GETPOSTISSET('formfilteraction')) {
$searchCategoryPropalOperator = GETPOSTINT('search_category_propal_operator');
} elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
$searchCategoryPropalOperator = getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT');
}
$search_product_category = GETPOSTINT('search_product_category');
$search_town = GETPOST('search_town', 'alpha');
$search_zip = GETPOST('search_zip', 'alpha');
@ -366,6 +373,7 @@ if (empty($reshook)) {
$search_multicurrency_montant_ttc = '';
$search_login = '';
$search_product_category = 0;
$searchCategoryPropalList = array();
$search_town = '';
$search_zip = "";
$search_state = "";
@ -765,6 +773,7 @@ if ($search_import_key) {
$sql .= natural_search("s.import_key", $search_import_key);
}
// Search on user
$param = '';
if ($search_user > 0) {
$sql .= " AND EXISTS (";
$sql .= " SELECT ec.fk_c_type_contact, ec.element_id, ec.fk_socpeople";
@ -773,6 +782,12 @@ if ($search_user > 0) {
$sql .= " ON ec.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal'";
$sql .= " WHERE ec.element_id = p.rowid AND ec.fk_socpeople = ".((int) $search_user).")";
}
if ($searchCategoryPropalOperator == 1) {
$param .= "&search_category_propal_operator=".urlencode((string) ($searchCategoryPropalOperator));
}
foreach ($searchCategoryPropalList as $searchCategoryPropal) {
$param .= "&search_category_propal_list[]=".urlencode($searchCategoryPropal);
}
// Search on sale representative
if ($search_sale && $search_sale != '-1') {
if ($search_sale == -2) {
@ -781,6 +796,34 @@ if ($search_sale && $search_sale != '-1') {
$sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
}
}
// Search for tag/category ($searchCategoryPropalList is an array of ID)
if (!empty($searchCategoryPropalList)) {
$searchCategoryPropalSqlList = array();
$listofcategoryid = '';
foreach ($searchCategoryPropalList as $searchCategoryPropal) {
if (intval($searchCategoryPropal) == -2) {
$searchCategoryPropalSqlList[] = "NOT EXISTS (SELECT ck.fk_propal FROM ".MAIN_DB_PREFIX."categorie_propal as ck WHERE p.rowid = ck.fk_propal)";
} elseif (intval($searchCategoryPropal) > 0) {
if ($searchCategoryPropalOperator == 0) {
$searchCategoryPropalSqlList[] = " EXISTS (SELECT ck.fk_propal FROM ".MAIN_DB_PREFIX."categorie_propal as ck WHERE p.rowid = ck.fk_propal AND ck.fk_categorie = ".((int) $searchCategoryPropal).")";
} else {
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryPropal);
}
}
}
if ($listofcategoryid) {
$searchCategoryPropalSqlList[] = " EXISTS (SELECT ck.fk_propal FROM ".MAIN_DB_PREFIX."categorie_propal as ck WHERE p.rowid = ck.fk_propal AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
}
if ($searchCategoryPropalOperator == 1) {
if (!empty($searchCategoryPropalSqlList)) {
$sql .= " AND (".implode(' OR ', $searchCategoryPropalSqlList).")";
}
} else {
if (!empty($searchCategoryPropalSqlList)) {
$sql .= " AND (".implode(' AND ', $searchCategoryPropalSqlList).")";
}
}
}
// Search for tag/category ($searchCategoryCustomerList is an array of ID)
$searchCategoryCustomerOperator = GETPOSTINT('search_category_customer_operator');
$searchCategoryCustomerList = ($search_categ_cus !== '-1' ? explode(',', (string) $search_categ_cus) : array());
@ -1117,6 +1160,9 @@ $arrayofmassactions = array(
if ($permissiontosendbymail) {
$arrayofmassactions['presend'] = img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail");
}
if (isModEnabled('category') && $user->hasRight('propal', 'lire')) {
$arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
}
if ($permissiontovalidate) {
$arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
}
@ -1188,7 +1234,11 @@ if ($search_all) {
$i = 0;
$moreforfilter = '';
if (isModEnabled('category') && $user->hasRight('categorie', 'read')) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
$formcategory = new FormCategory($db);
$moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PROPOSAL, $searchCategoryPropalList, 'minwidth300', $searchCategoryPropalOperator ? $searchCategoryPropalOperator : 0);
}
// If the user can view prospects other than his'
if ($user->hasRight('user', 'user', 'lire')) {
$langs->load("commercial");

View file

@ -55,6 +55,7 @@ $hookmanager->initHooks(array('propalstats', 'globalcard'));
$object_status = GETPOST('object_status', 'intcomma');
$typent_id = GETPOSTINT('typent_id');
$categ_id = GETPOSTINT('categ_id');
$select_categ_propal_id=GETPOST('select_categ_propal_id', 'array');
$userid = GETPOSTINT('userid');
$socid = GETPOSTINT('socid');
@ -127,7 +128,18 @@ if ($object_status != '' && $object_status >= 0) {
// Build graphic number of object
$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
// $data = array(array('Lib',val1,val2,val3),...)
if ($mode == 'customer') {
if (is_array($select_categ_propal_id) && !empty($select_categ_propal_id)) {
$stats->from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_propal as cat ON (p.rowid = cat.fk_propal)';
$stats->where .= ' AND cat.fk_categorie IN ('.$db->sanitize(implode(',', $select_categ_propal_id)).')';
}
}
if ($mode == 'supplier') {
if (is_array($select_categ_propal_id) && !empty($select_categ_propal_id)) {
$stats->from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_supplier_proposal as cat ON (p.rowid = cat.fk_supplier_proposal)';
$stats->where .= ' AND cat.fk_categorie IN ('.$db->sanitize(implode(',', $select_categ_propal_id)).')';
}
}
if (!$user->hasRight('societe', 'client', 'voir')) {
$filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
@ -297,6 +309,25 @@ print '<tr><td>'.$cat_label.'</td><td>';
print img_picto('', 'category', 'class="pictofixedwidth"');
print $formother->select_categories($cat_type, $categ_id, 'categ_id', 0, 1, 'widthcentpercentminusx maxwidth300');
print '</td></tr>';
if (isModEnabled('category')) {
$cat_type = '';
$cat_label = '';
if ($mode == 'customer') {
$cat_type = Categorie::TYPE_PROPOSAL;
$cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Proposals"));
}
if ($mode == 'supplier') {
$cat_type = Categorie::TYPE_SUPPLIER_PROPOSAL;
$cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("SupplierProposals"));
}
print '<tr><td>'.$cat_label.'</td><td>';
$cate_arbo = $form->select_all_categories($cat_type, '', 'parent', 0, 0, 1);
print img_picto('', 'category', 'class="pictofixedwidth"');
print $form->multiselectarray('select_categ_propal_id', $cate_arbo, GETPOST('select_categ_propal_id', 'array'), 0, 0, 'widthcentpercentminusx maxwidth300');
//print $formother->select_categories($cat_type, $categ_id, 'categ_id', true);
print '</td></tr>';
}
// User
print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
print img_picto('', 'user', 'class="pictofixedwidth"');

View file

@ -2107,6 +2107,9 @@ function dolGetElementUrl($objectid, $objecttype, $withpicto = 0, $option = '')
$classpath = 'commande/class';
$module = 'commande';
$myobject = 'commande';
} elseif ($objecttype == 'mailing') {
$langs->load('mailing');
$classpath = 'comm/mailing/class';
} elseif ($objecttype == 'propal') {
$langs->load('propal');
$classpath = 'comm/propal/class';
@ -2656,6 +2659,8 @@ function getModuleDirForApiClass($moduleobject)
$moduledirforclass = 'comm/propal';
} elseif ($moduleobject == 'agenda' || $moduleobject == 'agendaevents') {
$moduledirforclass = 'comm/action';
} elseif ($moduleobject == 'mailing') {
$moduledirforclass = 'comm/mailing';
} elseif ($moduleobject == 'adherent' || $moduleobject == 'members' || $moduleobject == 'memberstypes' || $moduleobject == 'subscriptions') {
$moduledirforclass = 'adherents';
} elseif ($moduleobject == 'don' || $moduleobject == 'donations') {

View file

@ -98,14 +98,22 @@ class modSalaries extends DolibarrModules
$r++;
$this->rights[$r][0] = 511;
$this->rights[$r][1] = 'Read employee salaries and payments (yours and your subordinates)';
$this->rights[$r][1] = 'Read employee salaries and payments (yours only)';
$this->rights[$r][2] = 'r';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'read';
$this->rights[$r][5] = '';
$r++;
$this->rights[$r][0] = 512;
$this->rights[$r][0] = 511;
$this->rights[$r][1] = 'Read employee salaries and payments (yours and your subordinates)';
$this->rights[$r][2] = 'r';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'readchild';
$this->rights[$r][5] = '';
$r++;
$this->rights[$r][0] = 513;
$this->rights[$r][1] = 'Create/modify payments of empoyee salaries';
$this->rights[$r][2] = 'w';
$this->rights[$r][3] = 0;

View file

@ -0,0 +1,21 @@
-- 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 <https://www.gnu.org/licenses/>.
--
-- ============================================================================
create table llx_categorie_propal
(
fk_categorie integer NOT NULL,
fk_propal integer NOT NULL,
import_key varchar(14)
)ENGINE=innodb;

View file

@ -0,0 +1,26 @@
-- ============================================================================
-- Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
-- Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2022 Solution Libre SAS <contact@solution-libre.fr>
--
-- 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 <https://www.gnu.org/licenses/>.
--
-- ============================================================================
create table llx_categorie_supplier_proposal
(
fk_categorie integer NOT NULL,
fk_supplier_proposal integer NOT NULL,
import_key varchar(14)
)ENGINE=innodb;

View file

@ -920,8 +920,9 @@ Permission402=Créer/modifier les avoirs
Permission403=Valider les avoirs
Permission404=Supprimer les avoirs
Permission431=Utilisez la barre de débogage
Permission511=Lire les salaires et leur paiement (les vôtres et ceux de vos subordonnées)
Permission512=Créer/modifier les salaires et leur paiement
Permission511=Lire les salaires et leur paiement (les vôtres seulement)
Permission512=Lire les salaires et leur paiement (les vôtres et ceux de vos subordonnées)
Permission513=Créer/modifier les salaires et leur paiement
Permission514=Supprimer les salaires et leur paiement
Permission517=Lire les salaires et leur paiement de tout le monde
Permission519=Exporter les salaires

View file

@ -361,9 +361,13 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account ba ON (ba.rowid = s.fk_accoun
$sql .= " ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.rowid = s.fk_user";
$sql .= " AND s.entity IN (".getEntity('salaries').")";
if (!$user->hasRight('salaries', 'readchild')) {
$sql .= " AND s.fk_user = ".(int) $user->id;
}
if (!$user->hasRight('salaries', 'readall')) {
$sql .= " AND s.fk_user IN (".$db->sanitize(implode(',', $childids)).")";
}
//print $sql;
// Search criteria

View file

@ -255,8 +255,11 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.ro
$sql .= " ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.rowid = sal.fk_user";
$sql .= " AND s.entity IN (".getEntity('payment_salaries').")";
if (!$user->hasRight('salaries', 'readchild')) {
$sql .= " AND s.fk_user = ".(int) $user->id;
}
if (!$user->hasRight('salaries', 'readall')) {
$sql .= " AND sal.fk_user IN (".$db->sanitize(implode(',', $childids)).")";
$sql .= " AND s.fk_user IN (".$db->sanitize(implode(',', $childids)).")";
}
// Search criteria

View file

@ -85,6 +85,9 @@ dol_mkdir($dir);
$useridtofilter = $userid; // Filter from parameters
if (!$user->hasRight('salaries', 'readchild') && empty($useridtofilter)) {
$useridtofilter = $user->id;
}
if (!$user->hasRight('salaries', 'readall') && empty($useridtofilter)) {
$useridtofilter = $user->getAllChildIds(1);
}
@ -216,14 +219,19 @@ print '<div class="fichecenter"><div class="fichethirdleft">';
// Show filter box
print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
// User
print '<tr><td>'.$langs->trans("Employee").'</td><td>';
print img_picto('', 'user', 'class="pictofixedwidth"');
print $form->select_dolusers(($userid ? $userid : -1), 'userid', 1, null, 0, !$user->hasRight('salaries', 'readall') ? 'hierarchyme' : '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
if (!$user->hasRight('salaries', 'readchild') && empty($useridtofilter)) {
print img_picto('', 'user', 'class="pictofixedwidth"');
print $form->select_dolusers(($userid ? $userid : -1), 'userid', 1, null, 0, !$user->hasRight('salaries', 'readall') ? 'hierarchyme' : '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
} else {
print $user->getNomUrl(1);
}
print '</td></tr>';
// Year
print '<tr><td>'.$langs->trans("Year").'</td><td>';
if (!in_array($year, $arrayyears)) {
@ -236,7 +244,6 @@ print '<tr><td align="center" colspan="2"><input type="submit" name="submit" cla
print '</table>';
print '</form>';
print '<br><br>';
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre" height="24">';

View file

@ -38,6 +38,7 @@
// Load Dolibarr environment
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
@ -489,6 +490,12 @@ if (empty($reshook)) {
}
if ($id > 0) {
if (isModEnabled('category')) {
$categories = GETPOST('categories', 'array');
if (method_exists($object, 'setCategories')) {
$object->setCategories($categories);
}
}
if (!$error) {
$db->commit();
@ -553,6 +560,8 @@ if (empty($reshook)) {
$object->cloture($user, GETPOSTINT('statut'), GETPOST('note', 'restricthtml'));
}
}
} elseif ($action == 'settags' && isModEnabled('category') && $usercancreate) { // Set tags
$result = $object->setCategories(GETPOST('categories', 'array'));
}
// Actions when printing a doc from card
@ -1455,6 +1464,12 @@ if ($action == 'create') {
print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
print '</td></tr>';
}
// Categories
if (isModEnabled('category')) {
print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
print $form->selectCategories(Categorie::TYPE_SUPPLIER_PROPOSAL, 'categories', $object);
print "</td></tr>";
}
// Other attributes
$parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
@ -1825,7 +1840,32 @@ if ($action == 'create') {
print '</td>';
print '</tr>';
}
// Categories
if (isModEnabled('category')) {
print '<tr><td>';
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans("Categories");
print '<td><td class="right">';
if ($usercancreate) {
print '<a class="editfielda" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$object->id.'&action=edittags&token='.newToken().'">'.img_edit().'</a>';
} else {
print '&nbsp;';
}
print '</td></tr></table>';
print '</td>';
print '<td>';
if ($action == 'edittags') {
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
print '<input type="hidden" name="action" value="settags">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print $form->selectCategories(Categorie::TYPE_SUPPLIER_PROPOSAL, 'categories', $object);
print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
print '</form>';
} else {
print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER_PROPOSAL, 1);
}
print "</td></tr>";
}
// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';

View file

@ -2901,6 +2901,22 @@ class SupplierProposal extends CommonObject
$return .= '</div>';
return $return;
}
/**
* Sets object to supplied categories.
*
* Deletes object from existing categories not supplied.
* Adds it to non existing supplied categories.
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
* @return int<-1,1> Return integer <0 if KO, >0 if OK
*/
public function setCategories($categories)
{
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_PROPOSAL);
}
}

View file

@ -107,6 +107,13 @@ $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc',
$search_project_ref = GETPOST('search_project_ref', 'alpha');
$search_status = GETPOST('search_status', 'intcomma');
$search_product_category = GETPOST('search_product_category', 'int');
$searchCategorySupplierPropalList = GETPOST('search_category_supplier_proposal_list', 'array:int');
$searchCategorySupplierPropalOperator = 0;
if (GETPOSTISSET('formfilteraction')) {
$searchCategorySupplierPropalOperator = GETPOSTINT('search_category_supplier_proposal_operator');
} elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
$searchCategorySupplierPropalOperator = getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT');
}
$search_all = trim(GETPOST('search_all', 'alphanohtml'));
$object_statut = GETPOST('supplier_proposal_statut', 'intcomma');
@ -221,7 +228,7 @@ $result = restrictedArea($user, $module, $objectid, $dbtable);
$permissiontoread = $user->hasRight('supplier_proposal', 'lire');
$permissiontodelete = $user->hasRight('supplier_proposal', 'supprimer');
$permissiontoadd = $user->hasRight('supplier_proposal', 'creer');
/*
* Actions
@ -264,6 +271,7 @@ if (empty($reshook)) {
$search_project_ref = '';
$search_login = '';
$search_product_category = '';
$searchCategorySupplierPropalList = array();
$search_town = '';
$search_zip = "";
$search_state = "";
@ -462,6 +470,34 @@ if ($search_sale && $search_sale != '-1') {
$sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = sp.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
}
}
// Search for tag/category ($searchCategorySupplierInvoiceList is an array of ID)
if (!empty($searchCategorySupplierPropalList)) {
$searchCategorySupplierPropalSqlList = array();
$listofcategoryid = '';
foreach ($searchCategorySupplierPropalList as $searchCategorySupplierPropal) {
if (intval($searchCategorySupplierPropal) == -2) {
$searchCategorySupplierPropalSqlList[] = "NOT EXISTS (SELECT ck.fk_supplier_proposal FROM ".MAIN_DB_PREFIX."categorie_supplier_proposal as ck WHERE sp.rowid = ck.fk_supplier_proposal)";
} elseif (intval($searchCategorySupplierPropal) > 0) {
if ($searchCategorySupplierPropalOperator == 0) {
$searchCategorySupplierPropalSqlList[] = " EXISTS (SELECT ck.fk_supplier_proposal FROM ".MAIN_DB_PREFIX."categorie_supplier_proposal as ck WHERE sp.rowid = ck.fk_supplier_proposal AND ck.fk_categorie = ".((int) $searchCategorySupplierPropal).")";
} else {
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplierPropal);
}
}
}
if ($listofcategoryid) {
$searchCategorySupplierPropalSqlList[] = " EXISTS (SELECT ck.fk_supplier_proposal FROM ".MAIN_DB_PREFIX."categorie_supplier_proposal as ck WHERE sp.rowid = ck.fk_supplier_proposal AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
}
if ($searchCategorySupplierPropalOperator == 1) {
if (!empty($searchCategorySupplierPropalSqlList)) {
$sql .= " AND (".implode(' OR ', $searchCategorySupplierPropalSqlList).")";
}
} else {
if (!empty($searchCategorySupplierPropalSqlList)) {
$sql .= " AND (".implode(' AND ', $searchCategorySupplierPropalSqlList).")";
}
}
}
// Search for tag/category ($searchCategoryProductList is an array of ID)
$searchCategoryProductOperator = GETPOSTINT('search_category_product_operator');
$searchCategoryProductList = array($search_product_category);
@ -631,6 +667,12 @@ if ($resql) {
if ($search_login) {
$param .= '&search_login='.urlencode($search_login);
}
if ($searchCategorySupplierPropalOperator == 1) {
$param .= "&search_category_supplier_propal_operator=".urlencode((string) ($searchCategorySupplierPropalOperator));
}
foreach ($searchCategorySupplierPropalList as $searchCategorySupplierPropal) {
$param .= "&search_category_supplier_invoice_list[]=".urlencode($searchCategorySupplierPropal);
}
if ($search_town) {
$param .= '&search_town='.urlencode($search_town);
}
@ -661,6 +703,9 @@ if ($resql) {
'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
);
if (isModEnabled('category') && $user->hasRight('supplier_proposal', 'lire')) {
$arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
}
if ($user->hasRight('supplier_proposal', 'supprimer')) {
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
}
@ -709,7 +754,11 @@ if ($resql) {
$i = 0;
$moreforfilter = '';
if (isModEnabled('category') && $user->hasRight('categorie', 'read')) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
$formcategory = new FormCategory($db);
$moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_SUPPLIER_PROPOSAL, $searchCategorySupplierPropalList, 'minwidth300', $searchCategorySupplierPropalOperator ? $searchCategorySupplierPropalOperator : 0);
}
// If the user can view prospects other than his'
if ($user->hasRight('user', 'user', 'lire')) {
$langs->load("commercial");