dolibarr/htdocs/salaries/class/salary.class.php

1050 lines
34 KiB
PHP
Raw Permalink Normal View History

<?php
/* Copyright (C) 2011-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
*
* 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/>.
*/
/**
* \file htdocs/salaries/class/salary.class.php
* \ingroup salaries
* \brief Class for salaries module payment
*/
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
/**
* Class to manage salary payments
*/
class Salary extends CommonObject
{
2021-03-04 19:20:16 +01:00
/**
* @var string ID to identify managed object
*/
public $element = 'salary';
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'salary';
/**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/
public $picto = 'salary';
2021-03-04 19:20:16 +01:00
/**
2024-03-11 22:19:49 +01:00
* @var array<string, array<string>> List of child tables. To test if we can delete object.
*/
2024-03-11 22:19:49 +01:00
protected $childtables = array('payment_salary' => array('name' => 'SalaryPayment', 'fk_element' => 'fk_salary'));
2023-04-03 19:51:40 +02:00
// /**
// * @var array List of child tables. To know object to delete on cascade.
// * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
// * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
// */
//protected $childtablesoncascade = array('mymodule_myobjectdet');
2021-03-04 19:20:16 +01:00
/**
* @var int User ID
*/
public $fk_user;
/**
* @var int|string
*/
2021-03-04 19:20:16 +01:00
public $datep;
/**
* @var int|string
*/
2021-03-04 19:20:16 +01:00
public $datev;
/**
* @var string
*/
public $salary;
/**
* @var float|string
*/
2022-06-15 11:19:14 +02:00
public $amount;
2021-03-04 19:20:16 +01:00
/**
* @var int ID
*/
public $fk_project;
/**
* @var int
*/
public $type_payment; // TODO Rename into type_payment_id
/**
* @var string
*/
public $type_payment_code;
2021-03-04 19:20:16 +01:00
/**
* @var string salary payments label
*/
public $label;
/**
* @var int|string
*/
2021-03-04 19:20:16 +01:00
public $datesp;
/**
* @var int|string
*/
2021-03-04 19:20:16 +01:00
public $dateep;
/**
* @var int ID
*/
public $fk_bank;
2023-02-06 22:28:03 +01:00
/**
* @var int
2024-12-17 21:42:26 +01:00
* @deprecated see $accountid
2023-02-06 22:28:03 +01:00
* @see $accountid
*/
public $fk_account;
/**
* @var int
*/
public $accountid;
2021-03-04 19:20:16 +01:00
/**
* @var int ID
*/
public $fk_user_author;
/**
* @var int ID
*/
public $fk_user_modif;
/**
* @var User
*/
public $user;
2022-06-20 03:56:09 +02:00
/**
* @var int<0,1> 1 if salary paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code)
* @deprecated Use $status and $close_code
2022-06-20 03:56:09 +02:00
*/
public $paye;
const STATUS_UNPAID = 0;
const STATUS_PAID = 1;
/**
2024-12-17 21:42:26 +01:00
* @var float amount remain to pay
*/
public $resteapayer;
public $fields = array(
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'visible' => 1, 'index' => 1, 'comment' => "Reference of object"),
'ref_ext' => array('type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'visible' => 0, 'position' => 11),
'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 12, 'notnull' => 0, 'visible' => 1),
'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'position' => 30),
'datep' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 40, 'comment' => 'Date'),
'datev' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'comment' => 'Date'),
'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Employee', 'enabled' => 1, 'position' => 15, 'notnull' => 1, 'visible' => 1, 'picto' => 'user'),
'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 20),
'salary' => array('type' => 'double(24,8)', 'label' => 'salary', 'enabled' => 1, 'visible' => 0, 'position' => 70),
'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 80),
'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'visible' => 0, 'position' => 90),
'fk_typepayment' => array('type' => 'typepayment', 'label' => 'DefaultPaymentMode', 'enabled' => 1, 'visible' => 1, 'position' => 100, 'comment' => 'Payment type'),
'num_payment' => array('type' => 'string', 'label' => 'Reference', 'enabled' => 1, 'visible' => 0, 'position' => 110, 'comment' => 'Reference'),
'datesp' => array('type' => 'date', 'label' => 'DateStart', 'enabled' => 1, 'visible' => 1, 'position' => 130, 'comment' => 'Date'),
'dateep' => array('type' => 'date', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 140, 'comment' => 'Date'),
'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => 0, 'position' => 150, 'index' => 1),
'note' => array('type' => 'text', 'label' => 'Note', 'enabled' => 1, 'position' => 160, 'visible' => 0,),
'fk_bank' => array('type' => 'integer', 'label' => 'BankId', 'enabled' => 1, 'visible' => 0, 'position' => 170),
'paye' => array('type' => 'smallint(6)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 180),
'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => 0, 'position' => 190),
'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 200, 'visible' => 0,),
'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 220),
);
2021-03-04 19:20:16 +01:00
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
$this->element = 'salary';
$this->table_element = 'salary';
$this->fields['ref_ext']['visible'] = getDolGlobalInt('MAIN_LIST_SHOW_REF_EXT');
2021-03-04 19:20:16 +01:00
}
/**
* Update database
*
* @param User $user User that modify
* @param int $notrigger 0=no, 1=yes (no update trigger)
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
2021-03-04 19:20:16 +01:00
*/
public function update($user = null, $notrigger = 0)
{
$error = 0;
// Clean parameters
$this->amount = trim($this->amount);
$this->label = trim($this->label);
$this->note = trim($this->note);
$this->note_private = trim($this->note_private);
$this->note_public = trim($this->note_public);
2021-03-04 19:20:16 +01:00
// Check parameters
if (empty($this->fk_user) || $this->fk_user < 0) {
$this->error = 'ErrorBadParameter';
return -1;
}
$this->db->begin();
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
$sql .= " tms='".$this->db->idate(dol_now())."',";
2021-06-09 15:36:47 +02:00
$sql .= " fk_user=".((int) $this->fk_user).",";
2021-03-04 19:20:16 +01:00
/*$sql .= " datep='".$this->db->idate($this->datep)."',";
$sql .= " datev='".$this->db->idate($this->datev)."',";*/
$sql .= " amount=".price2num($this->amount).",";
$sql .= " fk_projet=".((int) $this->fk_project).",";
2021-06-09 15:36:47 +02:00
$sql .= " fk_typepayment=".((int) $this->type_payment).",";
2021-03-04 19:20:16 +01:00
$sql .= " label='".$this->db->escape($this->label)."',";
$sql .= " datesp='".$this->db->idate($this->datesp)."',";
$sql .= " dateep='".$this->db->idate($this->dateep)."',";
$sql .= " note='".$this->db->escape($this->note)."',";
$sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").",";
$sql .= " fk_user_author=".((int) $this->fk_user_author).",";
2021-04-28 13:12:01 +02:00
$sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
2021-03-14 12:20:23 +01:00
$sql .= " WHERE rowid=".((int) $this->id);
2021-03-04 19:20:16 +01:00
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
// Update extrafield
if (!$error) {
$result = $this->insertExtraFields();
if ($result < 0) {
$error++;
2021-03-04 19:20:16 +01:00
}
}
if (!$notrigger) {
// Call trigger
2022-04-02 16:08:04 +02:00
$result = $this->call_trigger('SALARY_MODIFY', $user);
2023-12-04 13:53:48 +01:00
if ($result < 0) {
$error++;
}
2021-03-04 19:20:16 +01:00
// End call triggers
}
if (!$error) {
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return -1;
}
}
/**
* Load object in memory from database
*
* @param int $id id object
* @param User $user User that load
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
2021-03-04 19:20:16 +01:00
*/
public function fetch($id, $user = null)
{
$sql = "SELECT";
$sql .= " s.rowid,";
$sql .= " s.tms,";
$sql .= " s.fk_user,";
$sql .= " s.datep,";
$sql .= " s.datev,";
$sql .= " s.amount,";
$sql .= " s.fk_projet as fk_project,";
$sql .= " s.fk_typepayment,";
$sql .= " s.label,";
$sql .= " s.datesp,";
$sql .= " s.dateep,";
$sql .= " s.note as note_private,";
$sql .= " s.note_public,";
$sql .= " s.paye,";
2021-03-04 19:20:16 +01:00
$sql .= " s.fk_bank,";
$sql .= " s.fk_user_author,";
$sql .= " s.fk_user_modif,";
$sql .= " s.fk_account,";
$sql .= " cp.code as type_payment_code";
2021-03-04 19:20:16 +01:00
$sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON s.fk_typepayment = cp.id";
2021-03-14 11:48:39 +01:00
$sql .= " WHERE s.rowid = ".((int) $id);
2021-03-04 19:20:16 +01:00
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2021-03-04 19:20:16 +01:00
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
2022-06-20 03:56:09 +02:00
$this->id = $obj->rowid;
2021-03-04 19:20:16 +01:00
$this->ref = $obj->rowid;
$this->tms = $this->db->jdate($obj->tms);
2022-06-20 03:56:09 +02:00
$this->fk_user = $obj->fk_user;
2021-03-04 19:20:16 +01:00
$this->datep = $this->db->jdate($obj->datep);
$this->datev = $this->db->jdate($obj->datev);
2022-06-20 03:56:09 +02:00
$this->amount = $obj->amount;
$this->fk_project = $obj->fk_project;
$this->type_payment = $obj->fk_typepayment;
$this->type_payment_code = $obj->type_payment_code;
2021-03-04 19:20:16 +01:00
$this->label = $obj->label;
$this->datesp = $this->db->jdate($obj->datesp);
$this->dateep = $this->db->jdate($obj->dateep);
$this->note = $obj->note_private;
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
$this->paye = $obj->paye;
2023-12-14 16:00:05 +01:00
$this->status = $obj->paye;
2022-06-20 03:56:09 +02:00
$this->fk_bank = $obj->fk_bank;
$this->fk_user_author = $obj->fk_user_author;
$this->fk_user_modif = $obj->fk_user_modif;
2023-02-06 22:28:03 +01:00
$this->fk_account = $obj->fk_account;
$this->accountid = $obj->fk_account;
2022-06-20 03:56:09 +02:00
// Retrieve all extrafield
2021-03-04 19:20:16 +01:00
// fetch optionals attributes and labels
$this->fetch_optionals();
}
$this->db->free($resql);
return 1;
} else {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
}
/**
* Delete object in database
*
* @param User $user User that delete
2024-01-12 19:48:18 +01:00
* @param int $notrigger 0=launch triggers after, 1=disable triggers
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
2021-03-04 19:20:16 +01:00
*/
2023-04-03 19:51:40 +02:00
public function delete($user, $notrigger = 0)
2021-03-04 19:20:16 +01:00
{
2023-04-03 19:51:40 +02:00
return $this->deleteCommon($user, $notrigger);
2021-03-04 19:20:16 +01:00
}
/**
* Initialise an instance with random values.
* Used to build previews or test instances.
* id must be 0 if object instance is a specimen.
*
* @return int
2021-03-04 19:20:16 +01:00
*/
public function initAsSpecimen()
{
$this->id = 0;
$this->tms = dol_now();
$this->fk_user = 0;
2021-03-04 19:20:16 +01:00
$this->datep = '';
$this->datev = '';
$this->amount = '';
$this->label = '';
$this->datesp = '';
$this->dateep = '';
$this->note = '';
$this->fk_bank = 0;
$this->fk_user_author = 0;
$this->fk_user_modif = 0;
return 1;
2021-03-04 19:20:16 +01:00
}
/**
* Create in database
*
* @param User $user User that create
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
2021-03-04 19:20:16 +01:00
*/
public function create($user)
{
global $conf, $langs;
$error = 0;
$now = dol_now();
// Clean parameters
$this->amount = price2num(trim($this->amount));
$this->label = trim($this->label);
$this->note = trim($this->note);
$this->fk_bank = (int) $this->fk_bank;
$this->fk_user_author = (int) $this->fk_user_author;
$this->fk_user_modif = (int) $this->fk_user_modif;
$this->accountid = (int) $this->accountid;
$this->paye = (int) $this->paye;
2021-03-04 19:20:16 +01:00
// Check parameters
if (!$this->label) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
return -3;
}
if ($this->fk_user < 0 || $this->fk_user == '') {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
return -4;
}
if ($this->amount == '') {
2021-03-04 19:20:16 +01:00
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
return -5;
}
$this->db->begin();
// Insert into llx_salary
$sql = "INSERT INTO ".MAIN_DB_PREFIX."salary (fk_user";
//$sql .= ", datep";
//$sql .= ", datev";
$sql .= ", amount";
$sql .= ", fk_projet";
$sql .= ", salary";
$sql .= ", fk_typepayment";
$sql .= ", fk_account";
2023-12-04 13:53:48 +01:00
if ($this->note) {
$sql .= ", note";
}
2021-03-04 19:20:16 +01:00
$sql .= ", label";
$sql .= ", datesp";
$sql .= ", dateep";
$sql .= ", fk_user_author";
$sql .= ", datec";
$sql .= ", fk_bank";
$sql .= ", entity";
$sql .= ") ";
$sql .= " VALUES (";
$sql .= "'".((int) $this->fk_user)."'";
2021-03-04 19:20:16 +01:00
//$sql .= ", '".$this->db->idate($this->datep)."'";
//$sql .= ", '".$this->db->idate($this->datev)."'";
2023-12-04 13:53:48 +01:00
$sql .= ", ".((float) $this->amount);
2021-09-03 21:25:17 +02:00
$sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
2023-12-04 13:53:48 +01:00
$sql .= ", ".($this->salary > 0 ? ((float) $this->salary) : "null");
2021-09-03 21:25:17 +02:00
$sql .= ", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
$sql .= ", ".($this->accountid > 0 ? ((int) $this->accountid) : "null");
2023-12-04 13:53:48 +01:00
if ($this->note) {
$sql .= ", '".$this->db->escape($this->note)."'";
}
2021-03-04 19:20:16 +01:00
$sql .= ", '".$this->db->escape($this->label)."'";
$sql .= ", '".$this->db->idate($this->datesp)."'";
$sql .= ", '".$this->db->idate($this->dateep)."'";
$sql .= ", '".((int) $user->id)."'";
2021-03-04 19:20:16 +01:00
$sql .= ", '".$this->db->idate($now)."'";
$sql .= ", NULL";
2021-09-03 21:25:17 +02:00
$sql .= ", ".((int) $conf->entity);
2021-03-04 19:20:16 +01:00
$sql .= ")";
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."salary");
if ($this->id > 0) {
// Update extrafield
if (!$error) {
$result = $this->insertExtraFields();
if ($result < 0) {
$error++;
2021-03-04 19:20:16 +01:00
}
}
// Call trigger
2022-04-02 16:08:04 +02:00
$result = $this->call_trigger('SALARY_CREATE', $user);
2023-12-04 13:53:48 +01:00
if ($result < 0) {
$error++;
}
2021-03-04 19:20:16 +01:00
// End call triggers
2023-12-04 13:53:48 +01:00
} else {
$error++;
}
2021-03-04 19:20:16 +01:00
if (!$error) {
$this->db->commit();
return $this->id;
} else {
$this->db->rollback();
return -2;
}
} else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
}
2023-12-04 13:53:48 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2021-03-04 19:20:16 +01:00
/**
* Update link between payment salary and line generate into llx_bank
*
* @param int $id_bank Id bank account
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
2021-03-04 19:20:16 +01:00
*/
public function update_fk_bank($id_bank)
{
2023-12-04 13:53:48 +01:00
// phpcs:enable
2021-03-30 11:36:50 +02:00
$sql = 'UPDATE '.MAIN_DB_PREFIX.'salary SET fk_bank = '.((int) $id_bank);
2021-08-27 23:36:06 +02:00
$sql .= " WHERE rowid = ".((int) $this->id);
2021-03-04 19:20:16 +01:00
$result = $this->db->query($sql);
if ($result) {
return 1;
} else {
dol_print_error($this->db);
return -1;
}
}
2023-02-04 22:00:47 +01:00
/**
* getTooltipContentArray
* @param array<string,mixed> $params params to construct tooltip data
2023-02-04 22:00:47 +01:00
* @since v18
* @return array{picto?:string,ref?:string,refsupplier?:string,label?:string,date?:string,date_echeance?:string,amountht?:string,total_ht?:string,totaltva?:string,amountlt1?:string,amountlt2?:string,amountrevenustamp?:string,totalttc?:string}|array{optimize:string}
2023-02-04 22:00:47 +01:00
*/
public function getTooltipContentArray($params)
{
2023-12-14 16:00:05 +01:00
global $langs;
2023-02-04 22:00:47 +01:00
$langs->loadLangs(['salaries']);
2023-12-14 16:00:05 +01:00
// Complete datas
if (!empty($params['fromajaxtooltip']) && !isset($this->alreadypaid)) {
// Load the alreadypaid field
$this->alreadypaid = $this->getSommePaiement(0);
}
2023-02-04 22:00:47 +01:00
$datas = [];
2023-12-14 16:00:05 +01:00
2023-02-04 22:00:47 +01:00
$datas['picto'] = '<u>'.$langs->trans("Salary").'</u>';
2023-12-14 16:00:05 +01:00
if (isset($this->status) && isset($this->alreadypaid)) {
$datas['picto'] .= ' '.$this->getLibStatut(5, $this->alreadypaid);
}
2023-02-04 22:00:47 +01:00
$datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
return $datas;
}
2021-03-04 19:20:16 +01:00
/**
* Send name clickable (with possibly the picto)
2021-03-04 19:20:16 +01:00
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @param string $option link option
* @param int $notooltip 1=Disable tooltip
* @param string $morecss Add more css on link
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
* @return string Chaine with URL
*/
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
{
2023-12-14 16:00:05 +01:00
global $conf, $langs, $hookmanager;
2021-03-04 19:20:16 +01:00
2023-12-04 13:53:48 +01:00
if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1;
} // Force disable tooltips
2021-03-04 19:20:16 +01:00
$result = '';
2023-02-06 22:28:03 +01:00
$params = [
'id' => $this->id,
'objecttype' => $this->element,
'option' => $option,
];
$classfortooltip = 'classfortooltip';
$dataparams = '';
if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
$classfortooltip = 'classforajaxtooltip';
2023-04-03 19:51:40 +02:00
$dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
$label = '';
} else {
$label = implode($this->getTooltipContentArray($params));
2021-07-01 19:06:16 +02:00
}
2021-03-04 19:20:16 +01:00
$url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id;
if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2023-09-10 17:41:22 +02:00
if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2023-02-06 22:28:03 +01:00
$add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
2021-03-04 19:20:16 +01:00
}
$linkclose = '';
if (empty($notooltip)) {
2023-11-27 12:08:48 +01:00
if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2021-03-04 19:20:16 +01:00
$label = $langs->trans("ShowMyObject");
2025-01-09 01:41:24 +01:00
$linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
2021-03-04 19:20:16 +01:00
}
2025-01-09 01:41:24 +01:00
$linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
2023-02-04 22:00:47 +01:00
$linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
2021-03-04 19:20:16 +01:00
$linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
2023-02-04 22:00:47 +01:00
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
2023-02-04 22:00:47 +01:00
}
if ($withpicto != 2) {
$result .= $this->ref;
}
2021-03-04 19:20:16 +01:00
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
global $action, $hookmanager;
$hookmanager->initHooks(array('salarypayment'));
2024-03-11 22:19:49 +01:00
$parameters = array('id' => $this->id, 'getnomurl' => &$result);
2021-03-04 19:20:16 +01:00
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2023-12-04 13:53:48 +01:00
if ($reshook > 0) {
$result = $hookmanager->resPrint;
} else {
$result .= $hookmanager->resPrint;
}
2021-03-04 19:20:16 +01:00
return $result;
}
/**
* Return amount of payments already done
*
2023-12-15 10:28:16 +01:00
* @param int $multicurrency Return multicurrency_amount instead of amount. -1=Return both.
* @return float|int|array Amount of payment already done, <0 and set ->error if KO
*/
2023-12-15 10:28:16 +01:00
public function getSommePaiement($multicurrency = 0)
{
$table = 'payment_salary';
$field = 'fk_salary';
2023-04-03 19:51:40 +02:00
$sql = "SELECT sum(amount) as amount";
2023-12-15 10:28:16 +01:00
//sum(multicurrency_amount) as multicurrency_amount // Not yet supported
2023-04-03 19:51:40 +02:00
$sql .= " FROM ".MAIN_DB_PREFIX.$table;
2021-08-28 00:55:51 +02:00
$sql .= " WHERE ".$field." = ".((int) $this->id);
dol_syslog(get_class($this)."::getSommePaiement for salary id=".((int) $this->id), LOG_DEBUG);
2023-12-15 10:28:16 +01:00
$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
$this->db->free($resql);
2023-12-15 10:28:16 +01:00
if ($obj) {
if ($multicurrency < 0) {
//$this->sumpayed = $obj->amount;
//$this->sumpayed_multicurrency = $obj->multicurrency_amount;
//return array('alreadypaid'=>(float) $obj->amount, 'alreadypaid_multicurrency'=>(float) $obj->multicurrency_amount);
return array(); // Not yet supported
} elseif ($multicurrency) {
//$this->sumpayed_multicurrency = $obj->multicurrency_amount;
//return (float) $obj->multicurrency_amount;
return -1; // Not yet supported
} else {
//$this->sumpayed = $obj->amount;
return (float) $obj->amount;
}
} else {
return 0;
}
2021-03-04 19:20:16 +01:00
} else {
2023-12-15 10:28:16 +01:00
$this->error = $this->db->lasterror();
return -1;
}
}
2021-03-04 19:20:16 +01:00
/**
* Information on record
*
* @param int $id Id of record
* @return void
*/
public function info($id)
{
2022-06-28 13:09:53 +02:00
$sql = 'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
2021-03-04 19:20:16 +01:00
$sql .= ' FROM '.MAIN_DB_PREFIX.'salary as ps';
2021-03-14 11:48:39 +01:00
$sql .= ' WHERE ps.rowid = '.((int) $id);
2021-03-04 19:20:16 +01:00
dol_syslog(get_class($this).'::info', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
2021-03-04 19:20:16 +01:00
$this->id = $obj->rowid;
2021-04-26 12:29:17 +02:00
2022-06-28 13:09:53 +02:00
$this->user_creation_id = $obj->fk_user_author;
$this->user_modification_id = $obj->fk_user_modif;
2021-03-04 19:20:16 +01:00
$this->date_creation = $this->db->jdate($obj->datec);
2022-06-28 13:09:53 +02:00
$this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
2021-03-04 19:20:16 +01:00
}
$this->db->free($result);
} else {
dol_print_error($this->db);
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Tag social contribution as paid completely
*
* @deprecated Use setPaid()
* @see setPaid()
* @param User $user Object user making change
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
*/
public function set_paid($user)
{
// phpcs:enable
dol_syslog(get_class($this)."::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
return $this->setPaid($user);
}
/**
* Tag social contribution as paid completely
*
* @param User $user Object user making change
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
*/
public function setPaid($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
$sql .= " paye = 1";
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = ".((int) $this->id);
2023-06-04 01:42:28 +02:00
$return = $this->db->query($sql);
2023-06-04 01:42:28 +02:00
if ($return) {
$this->paye = 1;
return 1;
} else {
return -1;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Remove tag paid on social contribution
*
* @param User $user Object user making change
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
*/
public function set_unpaid($user)
{
// phpcs:enable
$sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
$sql .= " paye = 0";
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = ".((int) $this->id);
2023-06-04 01:42:28 +02:00
$return = $this->db->query($sql);
2023-06-04 01:42:28 +02:00
if ($return) {
$this->paye = 0;
return 1;
} else {
return -1;
}
}
2021-03-04 19:20:16 +01:00
/**
2023-04-08 15:08:55 +02:00
* Return label of current status
2021-03-04 19:20:16 +01:00
*
2023-04-08 15:08:55 +02:00
* @param int $mode 0=label long, 1=labels short, 2=Picto + Label short, 3=Picto, 4=Picto + Label long, 5=Label short + Picto
* @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommend to put here amount paid if you have it, 1 otherwise)
2021-04-18 16:43:09 +02:00
* @return string Label
2021-03-04 19:20:16 +01:00
*/
public function getLibStatut($mode = 0, $alreadypaid = -1)
{
return $this->LibStatut($this->paye, $mode, $alreadypaid);
}
2023-12-04 13:53:48 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
2023-04-08 15:08:55 +02:00
* Return label of a given status
*
* @param int $status Id status
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
* @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommend to put here amount paid if you have it, 1 otherwise)
* @return string Label
*/
public function LibStatut($status, $mode = 0, $alreadypaid = -1)
{
// phpcs:enable
global $langs;
// Load translation files required by the page
$langs->loadLangs(array("customers", "bills"));
// We reinit status array to force to redefine them because label may change according to properties values.
$this->labelStatus = array();
$this->labelStatusShort = array();
2021-03-04 19:20:16 +01:00
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
//$langs->load("mymodule");
2021-10-16 19:37:57 +02:00
$this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
$this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
2023-12-27 12:12:20 +01:00
if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
2023-12-04 13:53:48 +01:00
$this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
}
2021-10-16 19:37:57 +02:00
$this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
$this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
2023-12-27 12:12:20 +01:00
if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
2023-12-04 13:53:48 +01:00
$this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
}
}
$statusType = 'status1';
2023-12-27 12:12:20 +01:00
if ($status == 0 && $alreadypaid != 0) {
2023-12-04 13:53:48 +01:00
$statusType = 'status3';
}
if ($status == 1) {
$statusType = 'status6';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
2023-01-11 15:03:55 +01:00
/**
* Return clickable link of object (with eventually picto)
2023-01-11 15:03:55 +01:00
*
* @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
* @param ?array<string,mixed> $arraydata Array of data
* @return string HTML Code for Kanban thumb.
2023-01-11 15:03:55 +01:00
*/
2023-01-18 22:27:52 +01:00
public function getKanbanView($option = '', $arraydata = null)
2023-01-11 15:03:55 +01:00
{
global $langs;
2023-03-07 22:04:40 +01:00
$selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2023-01-11 15:03:55 +01:00
$return = '<div class="box-flex-item box-flex-grow-zero">';
$return .= '<div class="info-box info-box-sm">';
$return .= '<span class="info-box-icon bg-infobox-action">';
$return .= img_picto('', $this->picto);
$return .= '</span>';
$return .= '<div class="info-box-content">';
2023-05-11 11:03:26 +02:00
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
2023-10-17 15:43:56 +02:00
if ($selected >= 0) {
$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
}
2023-04-03 19:51:40 +02:00
if (!empty($arraydata['user']) && is_object($arraydata['user'])) {
$user = $arraydata['user'];
'@phan-var-force User $user';
$return .= '<br><span class="info-box-label">'.$user->getNomUrl(empty($arraydata['user']->photo) ? 1 : -1, '', 0, 0, 16, 0, '', 'maxwidth100').'</span>';
2023-01-11 15:03:55 +01:00
}
if (property_exists($this, 'amount')) {
2023-04-03 19:51:40 +02:00
$return .= '<br><span class="info-box-label amount">'.price($this->amount).'</span>';
if (property_exists($this, 'type_payment') && !empty($this->type_payment)) {
$return .= ' <span class="info-box-label opacitymedium small">';
if ($langs->trans("PaymentTypeShort".$this->type_payment) != "PaymentTypeShort".$this->type_payment) {
$return .= $langs->trans("PaymentTypeShort".$this->type_payment);
} elseif ($langs->trans("PaymentType".$this->type_payment) != "PaymentType".$this->type_payment) {
$return .= $langs->trans("PaymentType".$this->type_payment);
}
$return .= '</span>';
}
2023-01-11 15:03:55 +01:00
}
if (method_exists($this, 'LibStatut')) {
2024-06-22 15:07:39 +02:00
$return .= '<br><div class="info-box-status">'.$this->getLibStatut(3, isset($this->alreadypaid) ? $this->alreadypaid : $this->totalpaid).'</div>';
2023-01-11 15:03:55 +01:00
}
$return .= '</div>';
$return .= '</div>';
$return .= '</div>';
return $return;
}
2023-12-04 13:53:48 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Create a withdrawal request for a direct debit order or a credit transfer order.
* Use the remain to pay excluding all existing open direct debit requests.
*
* @param User $fuser User asking the direct debit transfer
* @param float $amount Amount we request direct debit for
* @param string $type 'direct-debit' or 'bank-transfer'
* @param string $sourcetype Source ('facture' or 'supplier_invoice')
* @param int $checkduplicateamongall 0=Default (check among open requests only to find if request already exists). 1=Check also among requests completely processed and cancel if at least 1 request exists whatever is its status.
2023-12-06 15:46:39 +01:00
* @return int Return integer <0 if KO, 0 if a request already exists, >0 if OK
*/
public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'salaire', $checkduplicateamongall = 0)
{
// phpcs:enable
global $conf, $mysoc;
$error = 0;
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
if ($this->paye == 0) {
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
$bac = new CompanyBankAccount($this->db);
Qual: Ignore false positive for suspicious param positions (#28693) * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored
2024-03-07 20:16:48 +01:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
$bac->fetch(0, '', $mysoc->id);
$sql = "SELECT count(rowid) as nb";
$sql .= " FROM ".$this->db->prefix()."prelevement_demande";
if ($type == 'salaire') {
$sql .= " WHERE fk_salary = ".((int) $this->id);
} else {
$sql .= " WHERE fk_facture = ".((int) $this->id);
}
$sql .= " AND type = 'ban'"; // To exclude record done for some online payments
if (empty($checkduplicateamongall)) {
$sql .= " AND traite = 0";
}
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj && $obj->nb == 0) { // If no request found yet
$now = dol_now();
$totalpaid = $this->getSommePaiement();
// $totalcreditnotes = $this->getSumCreditNotesUsed();
// $totaldeposits = $this->getSumDepositsUsed();
//print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
// We can also use bcadd to avoid pb with floating points
// For example print 239.2 - 229.3 - 9.9; does not return 0.
//$resteapayer=bcadd($this->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
//$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
// if (empty($amount)) {
// $amount = price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
// }
if (is_numeric($amount) && $amount != 0) {
$sql = 'INSERT INTO '.$this->db->prefix().'prelevement_demande(';
if ($type == 'salaire') {
$sql .= 'fk_salary, ';
} else {
$sql .= 'fk_facture, ';
}
$sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity)';
$sql .= " VALUES (".((int) $this->id);
$sql .= ", ".((float) price2num($amount));
$sql .= ", '".$this->db->idate($now)."'";
$sql .= ", ".((int) $fuser->id);
$sql .= ", '".$this->db->escape($bac->code_banque)."'";
$sql .= ", '".$this->db->escape($bac->code_guichet)."'";
$sql .= ", '".$this->db->escape($bac->number)."'";
$sql .= ", '".$this->db->escape($bac->cle_rib)."'";
$sql .= ", '".$this->db->escape($sourcetype)."'";
$sql .= ", 'ban'";
$sql .= ", ".((int) $conf->entity);
$sql .= ")";
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::demandeprelevement Erreur');
$error++;
}
} else {
$this->error = 'WithdrawRequestErrorNilAmount';
dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount');
$error++;
}
if (!$error) {
// Force payment mode of invoice to withdraw
$payment_mode_id = dol_getIdFromCode($this->db, ($type == 'bank-transfer' ? 'VIR' : 'PRE'), 'c_paiement', 'code', 'id', 1);
if ($payment_mode_id > 0) {
$result = $this->setPaymentMethods($payment_mode_id);
}
}
if ($error) {
return -1;
}
return 1;
} else {
$this->error = "A request already exists";
dol_syslog(get_class($this).'::demandeprelevement Can t create a request to generate a direct debit, a request already exists.');
return 0;
}
} else {
$this->error = $this->db->error();
dol_syslog(get_class($this).'::demandeprelevement Error -2');
return -2;
}
} else {
$this->error = "Status of invoice does not allow this";
dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->status, $this->paye, $this->mode_reglement_id");
return -3;
}
}
2023-12-04 13:53:48 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Remove a direct debit request or a credit transfer request
*
* @param User $fuser User making delete
* @param int $did ID of request to delete
2023-12-06 15:46:39 +01:00
* @return int Return integer <0 if OK, >0 if KO
*/
public function demande_prelevement_delete($fuser, $did)
{
// phpcs:enable
$sql = 'DELETE FROM '.$this->db->prefix().'prelevement_demande';
$sql .= ' WHERE rowid = '.((int) $did);
$sql .= ' AND traite = 0';
if ($this->db->query($sql)) {
return 0;
} else {
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::demande_prelevement_delete Error '.$this->error);
return -1;
}
}
}