dolibarr/htdocs/mrp/class/api_mos.class.php

1145 lines
37 KiB
PHP
Raw Permalink Normal View History

2020-06-17 23:09:30 +00:00
<?php
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2019 Maxime Kohlhaas <maxime@atm-consulting.fr>
2025-02-06 21:16:48 +00:00
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
2020-06-17 23:09:30 +00:00
*
* 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.'/mrp/class/mo.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2020-06-17 23:09:30 +00:00
/**
* \file htdocs/mrp/class/api_mos.class.php
2020-06-17 23:09:30 +00:00
* \ingroup mrp
* \brief File for API management of MO.
*/
/**
* API class for MO
*
* @access protected
* @class DolibarrApiAccess {@requires user,external}
*/
class Mos extends DolibarrApi
{
/**
2025-02-06 21:16:48 +00:00
* @var Mo {@type Mo}
2020-06-17 23:09:30 +00:00
*/
public $mo;
/**
* Constructor
*/
public function __construct()
{
global $db, $conf;
$this->db = $db;
$this->mo = new Mo($this->db);
}
/**
* Get properties of a MO object
*
* Return an array with MO information
2020-06-17 23:09:30 +00:00
*
2023-09-26 16:43:25 +00:00
* @param int $id ID of MO
* @return Object Object with cleaned properties
2020-06-17 23:09:30 +00:00
*
* @url GET {id}
2023-09-26 16:43:25 +00:00
* @throws RestException
2020-06-17 23:09:30 +00:00
*/
public function get($id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('mrp', 'read')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
2020-06-17 23:09:30 +00:00
}
$result = $this->mo->fetch($id);
if (!$result) {
throw new RestException(404, 'MO not found');
}
if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
2020-06-17 23:09:30 +00:00
}
return $this->_cleanObjectDatas($this->mo);
}
/**
* Get categories for a MO
*
* @since 24.0.0 Initial implementation
*
* @param int $id ID of MO
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
*
* @return mixed
*
* @url GET {id}/categories
*
* @throws RestException
*/
public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
{
if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
throw new RestException(403);
}
$categories = new Categorie($this->db);
$result = $categories->getListForItem($id, Categorie::TYPE_MO, $sortfield, $sortorder, $limit, $page);
if ($result < 0) {
throw new RestException(503, 'Error when retrieve category list : ' . implode(',', array_merge(array($categories->error), $categories->errors)));
}
return $result;
}
2020-06-17 23:09:30 +00:00
/**
* List Mos
*
* Get a list of MOs
*
2023-09-26 16:43:25 +00:00
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
2026-05-29 10:16:42 +00:00
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:>:'20160101')"
* @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
2020-06-17 23:09:30 +00:00
* @return array Array of order objects
2025-02-06 21:16:48 +00:00
* @phan-return Mo[]
* @phpstan-return Mo[]
2020-06-17 23:09:30 +00:00
*
* @throws RestException
*/
2023-09-26 16:04:48 +00:00
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '')
2020-06-17 23:09:30 +00:00
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('mrp', 'read')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
2021-04-08 16:51:42 +00:00
}
2020-06-17 23:09:30 +00:00
$obj_ret = array();
2020-09-19 21:30:29 +00:00
$tmpobject = new Mo($this->db);
2020-06-17 23:09:30 +00:00
$socid = DolibarrApiAccess::$user->socid ?: 0;
2020-06-17 23:09:30 +00:00
$restrictonsocid = 0; // Set to 1 if there is a field socid in table of object
// If the internal user must only see his customers, force searching by him
$search_sale = 0;
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight('societe', 'client', 'voir') && !$socid) {
2020-12-11 18:02:13 +00:00
$search_sale = DolibarrApiAccess::$user->id;
}
2020-06-17 23:09:30 +00:00
$sql = "SELECT t.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." AS t";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element."_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
2020-06-17 23:09:30 +00:00
$sql .= " WHERE 1 = 1";
2020-12-11 18:02:13 +00:00
if ($tmpobject->ismultientitymanaged) {
$sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')';
}
if ($restrictonsocid && $socid) {
2021-06-09 13:36:47 +00:00
$sql .= " AND t.fk_soc = ".((int) $socid);
2020-12-11 18:02:13 +00:00
}
// Search on sale representative
if ($search_sale && $search_sale != '-1') {
if ($search_sale == -2) {
$sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
} elseif ($search_sale > 0) {
$sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
}
2020-06-17 23:09:30 +00:00
}
2020-12-11 18:02:13 +00:00
if ($sqlfilters) {
2021-12-20 19:49:32 +00:00
$errormessage = '';
2023-02-25 18:48:33 +00:00
$sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
if ($errormessage) {
throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
2020-06-17 23:09:30 +00:00
}
}
2020-09-19 21:30:29 +00:00
$sql .= $this->db->order($sortfield, $sortorder);
2020-06-17 23:09:30 +00:00
if ($limit) {
2020-12-11 18:02:13 +00:00
if ($page < 0) {
2020-06-17 23:09:30 +00:00
$page = 0;
}
$offset = $limit * $page;
2020-09-19 21:30:29 +00:00
$sql .= $this->db->plimit($limit + 1, $offset);
2020-06-17 23:09:30 +00:00
}
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2020-12-11 18:02:13 +00:00
if ($result) {
2020-06-17 23:09:30 +00:00
$i = 0;
2025-09-28 20:20:44 +00:00
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
while ($i < $min) {
2020-09-19 21:30:29 +00:00
$obj = $this->db->fetch_object($result);
$tmp_object = new Mo($this->db);
2020-06-17 23:09:30 +00:00
if ($tmp_object->fetch($obj->rowid)) {
2023-09-26 16:04:48 +00:00
$obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($tmp_object), $properties);
2020-06-17 23:09:30 +00:00
}
$i++;
}
2020-12-11 18:02:13 +00:00
} else {
2020-06-17 23:09:30 +00:00
throw new RestException(503, 'Error when retrieve MO list');
}
2020-06-17 23:09:30 +00:00
return $obj_ret;
}
/**
* Create MO object
*
* @param array $request_data Request datas
2025-02-06 21:16:48 +00:00
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
2020-06-17 23:09:30 +00:00
* @return int ID of MO
2025-03-24 19:52:13 +00:00
*
* @throws RestException
2020-06-17 23:09:30 +00:00
*/
public function post($request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('mrp', 'write')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
2020-06-17 23:09:30 +00:00
}
// 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->mo->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$this->mo->$field = $this->_checkValForAPI($field, $value, $this->mo);
2020-06-17 23:09:30 +00:00
}
$this->checkRefNumbering();
2025-03-24 19:52:13 +00:00
$result = $this->mo->create(DolibarrApiAccess::$user);
//var_dump($result);exit;
if ($result < 0) {
2020-06-17 23:09:30 +00:00
throw new RestException(500, "Error creating MO", array_merge(array($this->mo->error), $this->mo->errors));
}
2025-03-24 19:52:13 +00:00
2020-06-17 23:09:30 +00:00
return $this->mo->id;
}
/**
* Update MO
*
2024-02-22 00:32:55 +00:00
* @param int $id Id of MO to update
* @param array $request_data Datas
2025-02-06 21:16:48 +00:00
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
2024-02-22 00:32:55 +00:00
* @return Object Updated object
2020-06-17 23:09:30 +00:00
*/
public function put($id, $request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('mrp', 'write')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
2020-06-17 23:09:30 +00:00
}
$result = $this->mo->fetch($id);
if (!$result) {
throw new RestException(404, 'MO not found');
}
if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
2020-06-17 23:09:30 +00:00
}
foreach ($request_data as $field => $value) {
2020-12-11 18:02:13 +00:00
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->mo->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->mo->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->mo);
}
continue;
}
$this->mo->$field = $this->_checkValForAPI($field, $value, $this->mo);
2020-06-17 23:09:30 +00:00
}
$this->checkRefNumbering();
2020-12-11 18:02:13 +00:00
if ($this->mo->update(DolibarrApiAccess::$user) > 0) {
2020-06-17 23:09:30 +00:00
return $this->get($id);
2020-06-20 16:46:49 +00:00
} else {
2020-06-17 23:09:30 +00:00
throw new RestException(500, $this->mo->error);
}
}
/**
* Validate MO
*
* @param int $id MO ID
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return Object Object with cleaned properties
*
* @url POST {id}/validate
*
* @throws RestException 304
* @throws RestException 401
* @throws RestException 404
* @throws RestException 500 System error
*/
public function validate($id, $notrigger = 0)
{
if (!DolibarrApiAccess::$user->hasRight('mrp', 'write')) {
throw new RestException(403);
}
$result = $this->mo->fetch($id);
if (!$result) {
throw new RestException(404, 'MO not found');
}
if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->mo->validate(DolibarrApiAccess::$user, $notrigger);
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 MO: '.$this->mo->error);
}
$result = $this->mo->fetch($id);
return $this->_cleanObjectDatas($this->mo);
}
NEW add method confirmProduced in MOs API (#39324) * FIX commande/stats: do not default "Created by" filter to current user (#39256) The order statistics query is not filtered on the current user on first page load, so the results shown are global. However the "Created by" selector defaulted to the current user (select_dolusers auto-selects $user->id when the passed value is empty), wrongly suggesting the displayed figures were limited to that user. Pass -1 instead of 0 when no user is selected so the combo keeps its empty entry, matching the unfiltered query. The empty option posts -1, which the query turns back into "no user filter", so the round-trip stays consistent after a refresh. * FIX Missing translation for "Weight" * Fix/supplier doc keep project (#39306) * FIX : situation invoice credit note wrong amount in progressive mode When creating a credit note "with same lines" from a situation invoice, the code always subtracts the previous situation invoice's line values before inverting the sign, assuming lines are stored cumulative (INVOICE_USE_SITUATION = 1, legacy mode). In progressive mode (INVOICE_USE_SITUATION = 2), each situation invoice line already stores its own delta amount and percent, so this extra subtraction credits the wrong amount and percent (e.g. 60% / 1272 instead of the correct 20% / 424 on a real cycle). Skip the subtraction in progressive mode so the credit note reuses the source line's own delta values, as expected. * FIX supplier order/proposal loses project after supplier selection On the create form of a supplier order (fourn/commande/card.php) and a supplier price request (supplier_proposal/card.php), the project select was filtered on the supplier third party as soon as one was chosen: the `if ($socid > 0)` branch took precedence over the PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS constant. As a result, a supplier document created from a customer project lost its preselected project when the page reloaded after picking the supplier (the customer project is not linked to the supplier, so it was filtered out). This aligns the behavior with the supplier invoice (fourn/facture/card.php), which gives priority to PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS. The external user restriction now targets $user->socid (the real external-user marker) instead of $socid > 0, which also matched internal users after selecting a supplier. * Fix Standalone reception creation (#39299) Fatal error: Uncaught Error: Call to a member function fetch_optionals() on null * Fix missing include * add method confirmProduced in MOs API which was missing --------- Co-authored-by: atm-corentin <165782689+atm-corentin@users.noreply.github.com> Co-authored-by: Alexandre SPANGARO <alexandre.spangaro@gmail.com> Co-authored-by: Alexandre SPANGARO <aspangaro.dolibarr@gmail.com> Co-authored-by: atm-jonathan <146709163+atm-jonathan@users.noreply.github.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2026-07-30 16:22:44 +00:00
/**
* Close=Confirm Produced MO
*
* @param int $id MO ID
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return Object Object with cleaned properties
*
* @url POST {id}/confirmproduced
*
* @throws RestException 304
* @throws RestException 401
* @throws RestException 404
* @throws RestException 500 System error
*/
public function confirmProduced($id, $notrigger = 0)
{
if (!DolibarrApiAccess::$user->hasRight('mrp', 'write')) {
throw new RestException(403);
}
$result = $this->mo->fetch($id);
if (!$result) {
throw new RestException(404, 'MO not found');
}
if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->mo->setStatut($this->mo::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
if ($result < 0) {
throw new RestException(500, 'Error when setting MO Produced: '.$this->mo->error);
}
$result = $this->mo->fetch($id);
return $this->_cleanObjectDatas($this->mo);
}
2020-06-17 23:09:30 +00:00
/**
* Delete MO
*
* @param int $id MO ID
* @return array
2025-02-06 21:16:48 +00:00
* @phan-return array<string,array{code:int,message:string}>
* @phpstan-return array<string,array{code:int,message:string}>
2020-06-17 23:09:30 +00:00
*/
public function delete($id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('mrp', 'delete')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
2020-06-17 23:09:30 +00:00
}
$result = $this->mo->fetch($id);
if (!$result) {
throw new RestException(404, 'MO not found');
}
if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
2020-06-17 23:09:30 +00:00
}
2020-12-11 18:02:13 +00:00
if (!$this->mo->delete(DolibarrApiAccess::$user)) {
2020-06-17 23:09:30 +00:00
throw new RestException(500, 'Error when deleting MO : '.$this->mo->error);
}
return array(
'success' => array(
'code' => 200,
'message' => 'MO deleted'
)
);
}
/**
2024-05-29 11:58:51 +00:00
* Produce and consume all
2024-05-29 12:07:11 +00:00
*
* - If arraytoconsume and arraytoproduce are both filled, this fill an empty MO with the lines to consume and produce and record the consumption and production.
* - If arraytoconsume and arraytoproduce are not provided, it consumes and produces all existing lines.
*
* Example:
* {
* "inventorylabel": "Produce and consume using API",
* "inventorycode": "PRODUCEAPI-YY-MM-DD",
* "autoclose": 1,
2024-05-29 12:12:09 +00:00
* "arraytoconsume": [
* "objectid": 123, -- ID_of_product
* "qty": "2",
* "fk_warehouse": "789"
* ],
* "arraytoproduce": [
* "objectid": 456, -- ID_of_product
2024-05-29 12:12:19 +00:00
* "qty": "1",
2024-05-29 12:12:09 +00:00
* "fk_warehouse": "789"
* ]
* }
*
2023-09-26 16:43:25 +00:00
* @param int $id ID of state
* @param array $request_data Request datas
2025-02-06 21:16:48 +00:00
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
*
* @url POST {id}/produceandconsumeall
*
* @return int ID of MO
*/
public function produceAndConsumeAll($id, $request_data = null)
{
2021-06-16 10:08:34 +00:00
global $langs;
$error = 0;
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('mrp', 'write')) {
2024-04-07 12:59:25 +00:00
throw new RestException(403, 'Not enough permission');
}
$result = $this->mo->fetch($id);
if (!$result) {
throw new RestException(404, 'MO not found');
}
if ($this->mo->status != Mo::STATUS_VALIDATED && $this->mo->status != Mo::STATUS_INPROGRESS) {
2024-04-07 12:59:25 +00:00
throw new RestException(405, 'Error bad status of MO');
}
// Code for consume and produce...
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
$stockmove = new MouvementStock($this->db);
$labelmovement = '';
$codemovement = '';
$autoclose = 1;
$arraytoconsume = array();
$arraytoproduce = array();
foreach ($request_data as $field => $value) {
if ($field == 'inventorylabel') {
$labelmovement = $value;
}
if ($field == 'inventorycode') {
$codemovement = $value;
}
if ($field == 'autoclose') {
$autoclose = $value;
}
if ($field == 'arraytoconsume') {
$arraytoconsume = $value;
}
if ($field == 'arraytoproduce') {
$arraytoproduce = $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
$stockmove->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
}
if (empty($labelmovement)) {
2023-04-18 18:59:43 +00:00
throw new RestException(500, "Field inventorylabel not provided");
}
if (empty($codemovement)) {
2023-04-18 18:59:43 +00:00
throw new RestException(500, "Field inventorycode not provided");
}
2021-10-12 10:14:03 +00:00
$consumptioncomplete = true;
$productioncomplete = true;
if (!empty($arraytoconsume) && !empty($arraytoproduce)) {
$pos = 0;
2026-01-29 22:30:39 +00:00
$arrayofarrayname = array("arraytoconsume", "arraytoproduce");
foreach ($arrayofarrayname as $arrayname) {
foreach (${$arrayname} as $value) {
$tmpproduct = new Product($this->db);
if (empty($value["objectid"])) {
throw new RestException(500, "Field objectid required in ".$arrayname);
}
$tmpproduct->fetch($value["qty"]);
if (empty($value["qty"])) {
throw new RestException(500, "Field qty required in ".$arrayname);
}
2023-12-27 11:12:20 +00:00
if ($value["qty"] != 0) {
$qtytoprocess = $value["qty"];
if (isset($value["fk_warehouse"])) { // If there is a warehouse to set
if (!($value["fk_warehouse"] > 0)) { // If there is no warehouse set.
$error++;
2021-08-31 18:31:05 +00:00
throw new RestException(500, "Field fk_warehouse must be > 0 in ".$arrayname);
}
if ($tmpproduct->status_batch) {
$error++;
2021-08-31 18:31:05 +00:00
throw new RestException(500, "Product ".$tmpproduct->ref."must be in batch");
}
}
$idstockmove = 0;
if (!$error && $value["fk_warehouse"] > 0) {
// Record consumption to do and stock movement
$id_product_batch = 0;
2021-10-12 10:04:43 +00:00
$stockmove->setOrigin($this->mo->element, $this->mo->id);
if ($arrayname == 'arraytoconsume') {
$moline = new MoLine($this->db);
$moline->fk_mo = $this->mo->id;
$moline->position = $pos;
$moline->fk_product = $value["objectid"];
$moline->fk_warehouse = (int) $value["fk_warehouse"];
$moline->qty = $qtytoprocess;
$moline->batch = (string) $tmpproduct->status_batch;
$moline->role = 'toproduce';
Qual: Fix PhanPluginUnknownObjectMethodCall ("part 1") (#30563) * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add typing hint to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add typing hint in phan config to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjectBlock * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjectBlock * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjects * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Fix: MemberNumRefNumbers getExample does not take any arguments Found thanks to adding the typing for phan! * Qual: Correct forced type for $module * Qual: Ignore phan false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Ignore false positive * Qual: phan/Ignore false positive, replace depr.prop with method * Qual: Fix typing for count by adding is_array check * Qual: replace depr.prop `nom` with method * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Fix depr.prop with getter and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: Improve typing for mymodule template * Make info method arguments match calls * Make PrintingDriver abstract class because we added abstract methods * Add phpdoc typing for phan * Update getExample function signature for compatibility * Update getExample function signature for compatibility * Update getExample function signature for compatibility * Update header wit correct information * Update getExample method signature * Update getExample method signature * Correct reference to class in comment * Force php phan typing for numbering modules * Correct $_GLOBALS to $GLOBALS * Add phpdoc to indicat type of properties * Correct default to null * Improve getNextValue typehint * Improve getNextValue typehint * Qual: Improve ModeleNumRefTakepos typing * Qual: Improve ModeleNumRefRecruitmentJobPosition typing * Fix default for $langs * Do not use non-existing ModeleNumRefTakepos::nom * Allow getNextValue argument to be null * Correct $_GLOBAL into $GLOBALS * Improve typing for ldap functions * Allow null for outputlangs argument * Improve typing for printOriginLine * Improve typing for linkedObject access * Fix PhanTypeMismatchArgumentNullableInternal and optimize * Fix PhanPossiblyUndeclaredVariable by setting default value * Ignore PhanPluginDuplicateExpressionAssignmentOperation - needs PHP7.4 * getToolTip does not accept null, changed to '' * Improve getNextValue typing * Change PrintingDriver back to normal class (instantiated) And add errors for functions that should be overloaded * Adjust pringOriginLine typing to match parent * Fix phpdoc for getNextValue * Fix phan typing * Add/Improve phpdoc typing hints * Qual: Adjustments to match typing * Update typing for unit, use GETPOSTINT * ModeleNumRefTask needs Project * Fix several notices appearing after update from develop * Index for choices is int, use GETPOSTINT * Qual: Ignore empty foreach * Force BOMLine on object line * phan typing to indicate that linked objects are BOM * Type the correct variable name (phan) * Add typing for $langs * Type to CommonNumRefGenerator (no class for availabilities) * Resolve several phan notices after update from dev branch * Extra typing fixes * Move common attributes to parent class (phan) * Add typing to Calendar class * Improve typing hints * Add typing to pdf_eagle_proforma * Qual: Add typing for token in generic_oauthcallback.php * Add typing for objMod * Correct getNextValue function signature (phpstan) * Fix typing (phpstan) * Update version declarations (fix phpstan) * Fix phpstan typing issues * Adjust typing (phpstan) * Qual: Update baseline & conf to detect 25% of PhanPluginUnknownObjectMethodCall
2024-08-17 17:32:52 +00:00
$moline->fk_mrp_production = 0;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = DolibarrApiAccess::$user->id;
$resultmoline = $moline->create(DolibarrApiAccess::$user);
if ($resultmoline <= 0) {
$error++;
throw new RestException(500, $moline->error);
}
2025-02-06 21:16:48 +00:00
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
} else {
$moline = new MoLine($this->db);
$moline->fk_mo = $this->mo->id;
$moline->position = $pos;
$moline->fk_product = $value["objectid"];
$moline->fk_warehouse = $value["fk_warehouse"];
$moline->qty = $qtytoprocess;
$moline->batch = (string) $tmpproduct->status_batch;
$moline->role = 'toconsume';
Qual: Fix PhanPluginUnknownObjectMethodCall ("part 1") (#30563) * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add typing hint to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add typing hint in phan config to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjectBlock * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjectBlock * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjects * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Fix: MemberNumRefNumbers getExample does not take any arguments Found thanks to adding the typing for phan! * Qual: Correct forced type for $module * Qual: Ignore phan false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Ignore false positive * Qual: phan/Ignore false positive, replace depr.prop with method * Qual: Fix typing for count by adding is_array check * Qual: replace depr.prop `nom` with method * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Fix depr.prop with getter and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: Improve typing for mymodule template * Make info method arguments match calls * Make PrintingDriver abstract class because we added abstract methods * Add phpdoc typing for phan * Update getExample function signature for compatibility * Update getExample function signature for compatibility * Update getExample function signature for compatibility * Update header wit correct information * Update getExample method signature * Update getExample method signature * Correct reference to class in comment * Force php phan typing for numbering modules * Correct $_GLOBALS to $GLOBALS * Add phpdoc to indicat type of properties * Correct default to null * Improve getNextValue typehint * Improve getNextValue typehint * Qual: Improve ModeleNumRefTakepos typing * Qual: Improve ModeleNumRefRecruitmentJobPosition typing * Fix default for $langs * Do not use non-existing ModeleNumRefTakepos::nom * Allow getNextValue argument to be null * Correct $_GLOBAL into $GLOBALS * Improve typing for ldap functions * Allow null for outputlangs argument * Improve typing for printOriginLine * Improve typing for linkedObject access * Fix PhanTypeMismatchArgumentNullableInternal and optimize * Fix PhanPossiblyUndeclaredVariable by setting default value * Ignore PhanPluginDuplicateExpressionAssignmentOperation - needs PHP7.4 * getToolTip does not accept null, changed to '' * Improve getNextValue typing * Change PrintingDriver back to normal class (instantiated) And add errors for functions that should be overloaded * Adjust pringOriginLine typing to match parent * Fix phpdoc for getNextValue * Fix phan typing * Add/Improve phpdoc typing hints * Qual: Adjustments to match typing * Update typing for unit, use GETPOSTINT * ModeleNumRefTask needs Project * Fix several notices appearing after update from develop * Index for choices is int, use GETPOSTINT * Qual: Ignore empty foreach * Force BOMLine on object line * phan typing to indicate that linked objects are BOM * Type the correct variable name (phan) * Add typing for $langs * Type to CommonNumRefGenerator (no class for availabilities) * Resolve several phan notices after update from dev branch * Extra typing fixes * Move common attributes to parent class (phan) * Add typing to Calendar class * Improve typing hints * Add typing to pdf_eagle_proforma * Qual: Add typing for token in generic_oauthcallback.php * Add typing for objMod * Correct getNextValue function signature (phpstan) * Fix typing (phpstan) * Update version declarations (fix phpstan) * Fix phpstan typing issues * Adjust typing (phpstan) * Qual: Update baseline & conf to detect 25% of PhanPluginUnknownObjectMethodCall
2024-08-17 17:32:52 +00:00
$moline->fk_mrp_production = 0;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = DolibarrApiAccess::$user->id;
$resultmoline = $moline->create(DolibarrApiAccess::$user);
if ($resultmoline <= 0) {
$error++;
throw new RestException(500, $moline->error);
}
2025-02-06 21:16:48 +00:00
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
}
if ($idstockmove < 0) {
$error++;
throw new RestException(500, $stockmove->error);
}
}
if (!$error) {
// Record consumption done
$moline = new MoLine($this->db);
$moline->fk_mo = $this->mo->id;
$moline->position = $pos;
$moline->fk_product = $value["objectid"];
$moline->fk_warehouse = $value["fk_warehouse"];
$moline->qty = $qtytoprocess;
$moline->batch = (string) $tmpproduct->status_batch;
if ($arrayname == "arraytoconsume") {
$moline->role = 'consumed';
} else {
$moline->role = 'produced';
}
Qual: Fix PhanPluginUnknownObjectMethodCall ("part 1") (#30563) * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add typing hint to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add typing hint in phan config to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint to fix phan notice. * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjectBlock * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjectBlock * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for linkedObjects * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) # Qual: Fix PhanPluginUnknownObjectMethodCall (add typing hints) Add/improve typing hint for PhanPluginUnknownObjectMethodCall * Fix: MemberNumRefNumbers getExample does not take any arguments Found thanks to adding the typing for phan! * Qual: Correct forced type for $module * Qual: Ignore phan false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Ignore false positive * Qual: phan/Ignore false positive, replace depr.prop with method * Qual: Fix typing for count by adding is_array check * Qual: replace depr.prop `nom` with method * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Fix depr.prop with getter and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: phan/Correct module type and ignore false positive * Qual: Improve typing for mymodule template * Make info method arguments match calls * Make PrintingDriver abstract class because we added abstract methods * Add phpdoc typing for phan * Update getExample function signature for compatibility * Update getExample function signature for compatibility * Update getExample function signature for compatibility * Update header wit correct information * Update getExample method signature * Update getExample method signature * Correct reference to class in comment * Force php phan typing for numbering modules * Correct $_GLOBALS to $GLOBALS * Add phpdoc to indicat type of properties * Correct default to null * Improve getNextValue typehint * Improve getNextValue typehint * Qual: Improve ModeleNumRefTakepos typing * Qual: Improve ModeleNumRefRecruitmentJobPosition typing * Fix default for $langs * Do not use non-existing ModeleNumRefTakepos::nom * Allow getNextValue argument to be null * Correct $_GLOBAL into $GLOBALS * Improve typing for ldap functions * Allow null for outputlangs argument * Improve typing for printOriginLine * Improve typing for linkedObject access * Fix PhanTypeMismatchArgumentNullableInternal and optimize * Fix PhanPossiblyUndeclaredVariable by setting default value * Ignore PhanPluginDuplicateExpressionAssignmentOperation - needs PHP7.4 * getToolTip does not accept null, changed to '' * Improve getNextValue typing * Change PrintingDriver back to normal class (instantiated) And add errors for functions that should be overloaded * Adjust pringOriginLine typing to match parent * Fix phpdoc for getNextValue * Fix phan typing * Add/Improve phpdoc typing hints * Qual: Adjustments to match typing * Update typing for unit, use GETPOSTINT * ModeleNumRefTask needs Project * Fix several notices appearing after update from develop * Index for choices is int, use GETPOSTINT * Qual: Ignore empty foreach * Force BOMLine on object line * phan typing to indicate that linked objects are BOM * Type the correct variable name (phan) * Add typing for $langs * Type to CommonNumRefGenerator (no class for availabilities) * Resolve several phan notices after update from dev branch * Extra typing fixes * Move common attributes to parent class (phan) * Add typing to Calendar class * Improve typing hints * Add typing to pdf_eagle_proforma * Qual: Add typing for token in generic_oauthcallback.php * Add typing for objMod * Correct getNextValue function signature (phpstan) * Fix typing (phpstan) * Update version declarations (fix phpstan) * Fix phpstan typing issues * Adjust typing (phpstan) * Qual: Update baseline & conf to detect 25% of PhanPluginUnknownObjectMethodCall
2024-08-17 17:32:52 +00:00
$moline->fk_mrp_production = 0;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = DolibarrApiAccess::$user->id;
$resultmoline = $moline->create(DolibarrApiAccess::$user);
if ($resultmoline <= 0) {
$error++;
throw new RestException(500, $moline->error);
}
$pos++;
}
}
}
}
if (!$error) {
if ($autoclose <= 0) {
$consumptioncomplete = false;
$productioncomplete = false;
}
}
} else {
$pos = 0;
foreach ($this->mo->lines as $line) {
if ($line->role == 'toconsume') {
$tmpproduct = new Product($this->db);
$tmpproduct->fetch($line->fk_product);
if ($line->qty != 0) {
$qtytoprocess = $line->qty;
if (isset($line->fk_warehouse)) { // If there is a warehouse to set
if (!($line->fk_warehouse > 0)) { // If there is no warehouse set.
$langs->load("errors");
$error++;
2026-01-20 15:46:14 +00:00
throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), (string) $tmpproduct->ref));
}
if ($tmpproduct->status_batch) {
$langs->load("errors");
$error++;
2026-01-20 15:46:14 +00:00
throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), (string) $tmpproduct->ref));
}
}
$idstockmove = 0;
if (!$error && $line->fk_warehouse > 0) {
// Record stock movement
$id_product_batch = 0;
2021-10-22 12:27:42 +00:00
$stockmove->origin_type = 'mo';
$stockmove->origin_id = $this->mo->id;
if ($qtytoprocess >= 0) {
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, (int) $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
} else {
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, (int) $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
}
if ($idstockmove < 0) {
$error++;
throw new RestException(500, $stockmove->error);
}
}
if (!$error) {
// Record consumption
$moline = new MoLine($this->db);
$moline->fk_mo = $this->mo->id;
$moline->position = $pos;
$moline->fk_product = $line->fk_product;
$moline->fk_warehouse = $line->fk_warehouse;
$moline->qty = $qtytoprocess;
$moline->batch = (string) $tmpproduct->status_batch;
$moline->role = 'consumed';
$moline->fk_mrp_production = $line->id;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = DolibarrApiAccess::$user->id;
$resultmoline = $moline->create(DolibarrApiAccess::$user);
if ($resultmoline <= 0) {
$error++;
throw new RestException(500, $moline->error);
}
$pos++;
}
}
}
}
$pos = 0;
foreach ($this->mo->lines as $line) {
if ($line->role == 'toproduce') {
$tmpproduct = new Product($this->db);
$tmpproduct->fetch($line->fk_product);
if ($line->qty != 0) {
$qtytoprocess = $line->qty;
if (isset($line->fk_warehouse)) { // If there is a warehouse to set
if (!($line->fk_warehouse > 0)) { // If there is no warehouse set.
$langs->load("errors");
$error++;
2026-01-20 16:39:40 +00:00
throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), (string) $tmpproduct->ref));
}
if ($tmpproduct->status_batch) {
$langs->load("errors");
$error++;
2026-01-20 16:39:40 +00:00
throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), (string) $tmpproduct->ref));
}
}
$idstockmove = 0;
if (!$error && $line->fk_warehouse > 0) {
// Record stock movement
$id_product_batch = 0;
2021-10-22 12:27:42 +00:00
$stockmove->origin_type = 'mo';
$stockmove->origin_id = $this->mo->id;
if ($qtytoprocess >= 0) {
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, (int) $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
} else {
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, (int) $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
}
if ($idstockmove < 0) {
$error++;
throw new RestException(500, $stockmove->error);
}
}
if (!$error) {
// Record consumption
$moline = new MoLine($this->db);
$moline->fk_mo = $this->mo->id;
$moline->position = $pos;
$moline->fk_product = $line->fk_product;
$moline->fk_warehouse = $line->fk_warehouse;
$moline->qty = $qtytoprocess;
$moline->batch = (string) $tmpproduct->status_batch;
$moline->role = 'produced';
$moline->fk_mrp_production = $line->id;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = DolibarrApiAccess::$user->id;
$resultmoline = $moline->create(DolibarrApiAccess::$user);
if ($resultmoline <= 0) {
$error++;
throw new RestException(500, $moline->error);
}
$pos++;
}
}
}
}
if (!$error) {
if ($autoclose > 0) {
foreach ($this->mo->lines as $line) {
if ($line->role == 'toconsume') {
$arrayoflines = $this->mo->fetchLinesLinked('consumed', $line->id);
$alreadyconsumed = 0;
foreach ($arrayoflines as $line2) {
$alreadyconsumed += $line2['qty'];
}
if ($alreadyconsumed < $line->qty) {
$consumptioncomplete = false;
}
}
if ($line->role == 'toproduce') {
$arrayoflines = $this->mo->fetchLinesLinked('produced', $line->id);
$alreadyproduced = 0;
foreach ($arrayoflines as $line2) {
$alreadyproduced += $line2['qty'];
}
if ($alreadyproduced < $line->qty) {
$productioncomplete = false;
}
}
}
} else {
$consumptioncomplete = false;
$productioncomplete = false;
}
}
}
2021-10-12 10:14:03 +00:00
// Update status of MO
2024-03-16 20:43:38 +00:00
dol_syslog("consumptioncomplete = ".json_encode($consumptioncomplete)." productioncomplete = ".json_encode($productioncomplete));
if ($consumptioncomplete && $productioncomplete) {
2023-08-24 11:29:52 +00:00
$result = $this->mo->setStatut(Mo::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
} else {
2023-08-24 11:29:52 +00:00
$result = $this->mo->setStatut(Mo::STATUS_INPROGRESS, 0, '', 'MRP_MO_PRODUCED');
}
if ($result <= 0) {
throw new RestException(500, $this->mo->error);
}
return $this->mo->id;
}
2024-05-29 11:58:51 +00:00
/**
* Produce and consume
*
* Example:
* {
* "inventorylabel": "Produce and consume using API",
* "inventorycode": "PRODUCEAPI-YY-MM-DD",
* "autoclose": 1,
* "arraytoconsume": [
* {
2024-05-29 12:12:09 +00:00
* "objectid": "123", -- rowid of MoLine
2024-05-29 11:58:51 +00:00
* "qty": "2",
* "fk_warehouse": "789" -- "0" or empty, if stock change is disabled.
2024-05-29 11:58:51 +00:00
* }
* ],
* "arraytoproduce": [
* {
2024-05-29 12:12:09 +00:00
* "objectid": "456", -- rowid of MoLine
2024-05-29 11:58:51 +00:00
* "qty": "1",
2024-05-29 12:12:09 +00:00
* "fk_warehouse": "789",
* "pricetoproduce": "12.3" -- optional
2024-05-29 11:58:51 +00:00
* }
* ]
* }
*
* @param int $id ID of state
* @param array $request_data Request datas
2025-02-06 21:16:48 +00:00
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
2024-05-29 11:58:51 +00:00
*
* @url POST {id}/produceandconsume
*
* @return int ID of MO
*/
public function produceAndConsume($id, $request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight("mrp", "write")) {
throw new RestException(403, 'Not enough permission');
}
$result = $this->mo->fetch($id);
if (!$result) {
throw new RestException(404, 'MO not found');
}
if ($this->mo->status != Mo::STATUS_VALIDATED && $this->mo->status != Mo::STATUS_INPROGRESS) {
throw new RestException(405, 'Error bad status of MO');
}
// Code for consume and produce...
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
$stockmove = new MouvementStock($this->db);
$labelmovement = '';
$codemovement = '';
$autoclose = 1;
$arraytoconsume = array();
$arraytoproduce = array();
foreach ($request_data as $field => $value) {
if ($field == 'inventorylabel') {
$labelmovement = $value;
}
if ($field == 'inventorycode') {
$codemovement = $value;
}
if ($field == 'autoclose') {
$autoclose = $value;
}
if ($field == 'arraytoconsume') {
$arraytoconsume = $value;
}
if ($field == 'arraytoproduce') {
$arraytoproduce = $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
2024-05-29 11:58:51 +00:00
$stockmove->context['caller'] = $request_data['caller'];
continue;
}
}
if (empty($labelmovement)) {
throw new RestException(500, "Field inventorylabel not provided");
}
if (empty($codemovement)) {
throw new RestException(500, "Field inventorycode not provided");
}
$this->db->begin();
$pos = 0;
2026-01-29 22:30:39 +00:00
$arrayofarrayname = array("arraytoconsume", "arraytoproduce");
2024-05-29 11:58:51 +00:00
foreach ($arrayofarrayname as $arrayname) {
foreach (${$arrayname} as $value) {
if (empty($value["objectid"])) {
throw new RestException(500, "Field objectid required in " . $arrayname);
}
$molinetoprocess = new MoLine($this->db);
$tmpmolineid = $molinetoprocess->fetch($value["objectid"]);
if ($tmpmolineid <= 0) {
throw new RestException(500, "MoLine with rowid " . $value["objectid"] . " not exist.");
}
$tmpproduct = new Product($this->db);
$tmpproduct->fetch($molinetoprocess->fk_product);
if ($tmpproduct->status_batch) {
throw new RestException(500, "Product " . $tmpproduct->ref . " must be in batch, this API can't handle it currently.");
}
if (empty($value["qty"]) && $value["qty"] != 0) {
throw new RestException(500, "Field qty with lower or higher then 0 required in " . $arrayname);
}
$qtytoprocess = $value["qty"];
2024-07-01 10:52:05 +00:00
$fk_warehousetoprocess = 0;
if ($molinetoprocess->disable_stock_change == false) {
if (isset($value["fk_warehouse"])) { // If there is a warehouse to set
if (!($value["fk_warehouse"] > 0)) { // If there is no warehouse set.
throw new RestException(500, "Field fk_warehouse required in " . $arrayname);
}
2024-05-29 11:58:51 +00:00
}
2024-07-01 10:52:05 +00:00
$fk_warehousetoprocess = (int) $value["fk_warehouse"];
2024-05-29 11:58:51 +00:00
}
$pricetoproduce = 0;
if (isset($value["pricetoproduce"])) { // If there is a price to produce set.
if ($value["pricetoproduce"] > 0) { // Only use prices grater then 0.
$pricetoproduce = $value["pricetoproduce"];
}
}
$idstockmove = 0;
if ($molinetoprocess->disable_stock_change == false) {
// Record stock movement
$id_product_batch = 0;
$stockmove->origin_type = 'mo';
$stockmove->origin_id = $this->mo->id;
if ($arrayname == "arraytoconsume") {
if ($qtytoprocess >= 0) {
2025-02-06 21:16:48 +00:00
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
} else {
2025-02-06 21:16:48 +00:00
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
}
2024-05-29 11:58:51 +00:00
} else {
if ($qtytoprocess >= 0) {
2025-02-06 21:16:48 +00:00
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, $pricetoproduce, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
} else {
2025-02-06 21:16:48 +00:00
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
}
2024-05-29 11:58:51 +00:00
}
if ($idstockmove <= 0) {
throw new RestException(500, $stockmove->error);
2024-05-29 11:58:51 +00:00
}
}
// Record consumption
$moline = new MoLine($this->db);
$moline->fk_mo = $this->mo->id;
$moline->position = $pos;
$moline->fk_product = $tmpproduct->id;
$moline->fk_warehouse = $idstockmove > 0 ? $fk_warehousetoprocess : null;
2024-05-29 11:58:51 +00:00
$moline->qty = $qtytoprocess;
$moline->batch = '';
$moline->fk_mrp_production = $molinetoprocess->id;
$moline->fk_stock_movement = $idstockmove > 0 ? $idstockmove : null;
2024-05-29 11:58:51 +00:00
$moline->fk_user_creat = DolibarrApiAccess::$user->id;
if ($arrayname == "arraytoconsume") {
$moline->role = 'consumed';
} else {
$moline->role = 'produced';
}
$resultmoline = $moline->create(DolibarrApiAccess::$user);
if ($resultmoline <= 0) {
throw new RestException(500, $moline->error);
}
2024-05-31 12:59:16 +00:00
$pos++;
2024-05-29 11:58:51 +00:00
}
}
$consumptioncomplete = true;
$productioncomplete = true;
if ($autoclose > 0) {
// Refresh Lines after consumptions.
$this->mo->fetchLines();
foreach ($this->mo->lines as $line) {
if ($line->role == 'toconsume') {
$arrayoflines = $this->mo->fetchLinesLinked('consumed', $line->id);
$alreadyconsumed = 0;
foreach ($arrayoflines as $line2) {
$alreadyconsumed += $line2['qty'];
}
if ($alreadyconsumed < $line->qty) {
$consumptioncomplete = false;
}
}
if ($line->role == 'toproduce') {
$arrayoflines = $this->mo->fetchLinesLinked('produced', $line->id);
$alreadyproduced = 0;
foreach ($arrayoflines as $line2) {
$alreadyproduced += $line2['qty'];
}
if ($alreadyproduced < $line->qty) {
$productioncomplete = false;
}
}
}
} else {
$consumptioncomplete = false;
$productioncomplete = false;
}
// Update status of MO
2024-05-31 12:59:16 +00:00
dol_syslog("consumptioncomplete = " . (string) $consumptioncomplete . " productioncomplete = " . (string) $productioncomplete);
2024-05-29 11:58:51 +00:00
//var_dump("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete);
2024-05-31 13:38:36 +00:00
if ($consumptioncomplete && $productioncomplete) {
2024-05-29 11:58:51 +00:00
$result = $this->mo->setStatut(Mo::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
} else {
$result = $this->mo->setStatut(Mo::STATUS_INPROGRESS, 0, '', 'MRP_MO_PRODUCED');
}
if ($result <= 0) {
throw new RestException(500, $this->mo->error);
}
$this->db->commit();
return $this->mo->id;
}
2020-06-17 23:09:30 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
* @phpstan-template T
2020-06-17 23:09:30 +00:00
*
2023-09-26 16:04:48 +00:00
* @param Object $object Object to clean
* @return Object Object with cleaned properties
* @phpstan-param T $object
* @phpstan-return T
2020-06-17 23:09:30 +00:00
*/
protected function _cleanObjectDatas($object)
{
// phpcs:enable
$object = parent::_cleanObjectDatas($object);
unset($object->rowid);
unset($object->canvas);
unset($object->name);
unset($object->lastname);
unset($object->firstname);
unset($object->civility_id);
unset($object->statut);
unset($object->state);
unset($object->state_id);
unset($object->state_code);
unset($object->region);
unset($object->region_code);
unset($object->country);
unset($object->country_id);
unset($object->country_code);
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
unset($object->barcode_type_coder);
unset($object->total_ht);
unset($object->total_tva);
unset($object->total_localtax1);
unset($object->total_localtax2);
unset($object->total_ttc);
unset($object->fk_account);
unset($object->comments);
unset($object->note);
unset($object->mode_reglement_id);
unset($object->cond_reglement_id);
unset($object->cond_reglement);
unset($object->shipping_method_id);
unset($object->fk_incoterms);
unset($object->label_incoterms);
unset($object->location_incoterms);
// If object has lines, remove $db property
if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
$nboflines = count($object->lines);
2020-12-11 18:02:13 +00:00
for ($i = 0; $i < $nboflines; $i++) {
2020-06-17 23:09:30 +00:00
$this->_cleanObjectDatas($object->lines[$i]);
unset($object->lines[$i]->lines);
unset($object->lines[$i]->note);
}
}
return $object;
}
/**
2025-02-06 21:16:48 +00:00
* Validate fields before creating or updating an object
2020-06-17 23:09:30 +00:00
*
2025-02-06 21:16:48 +00:00
* @param ?array<null|int|float|string> $data Data to validate
* @return array<string,null|int|float|string>
2020-06-17 23:09:30 +00:00
*
* @throws RestException
*/
private function _validate($data)
{
$myobject = array();
foreach ($this->mo->fields as $field => $propfield) {
2025-03-24 19:52:13 +00:00
if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || empty($propfield['notnull']) || $propfield['notnull'] != 1) {
2020-12-11 18:02:13 +00:00
continue; // Not a mandatory field
}
if (!isset($data[$field])) {
2020-06-17 23:09:30 +00:00
throw new RestException(400, "$field field missing");
2020-12-11 18:02:13 +00:00
}
2021-09-12 23:32:20 +00:00
$myobject[$field] = $data[$field];
2020-06-17 23:09:30 +00:00
}
return $myobject;
}
/**
* Validate the ref field and get the next Number if it's necessary.
*
* @return void
*/
2024-01-21 16:37:08 +00:00
private function checkRefNumbering()
{
$ref = substr($this->mo->ref, 1, 4);
if ($this->mo->status > 0 && $ref == 'PROV') {
throw new RestException(400, "Wrong naming scheme '(PROV%)' is only allowed on 'DRAFT' status. For automatic increment use 'auto' on the 'ref' field.");
}
if (strtolower($this->mo->ref) == 'auto') {
if (empty($this->mo->id) && $this->mo->status == 0) {
$this->mo->ref = ''; // 'ref' will auto incremented with '(PROV' + newID + ')'
} else {
$this->mo->fetch_product();
$numref = $this->mo->getNextNumRef($this->mo->product);
$this->mo->ref = $numref;
}
}
}
2020-06-17 23:09:30 +00:00
}