--- /tmp/dsg/dolibarr/htdocs/compta/sociales/class/github_19.0.3_cchargesociales.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/sociales/class/client_cchargesociales.class.php @@ -37,4 +36,0 @@ - public $db; - - public $id; - @@ -51,4 +46,0 @@ - /** - * @var string Label - * @deprecated - */ @@ -56,6 +47,0 @@ - - /** - * @var string Label - */ - public $label; - @@ -67,2 +53,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -71,3 +56,0 @@ - /** - * @var string module - */ @@ -77,4 +59,0 @@ - /** - * @var array array of errors - */ - public $errors = array(); @@ -98 +77 @@ - * @return int Return integer <0 if KO, Id of created object if OK + * @return int <0 if KO, Id of created object if OK @@ -106,12 +85,12 @@ - // Clean parameters - $this->trimParameters( - array( - 'libelle', - 'deductible', - 'active', - 'code', - 'fk_pays', - 'module', - 'accountancy_code', - ) - ); + // Clean parameters + $this->trimParameters( + array( + 'libelle', + 'deductible', + 'active', + 'code', + 'fk_pays', + 'module', + 'accountancy_code', + ) + ); @@ -123,0 +103 @@ + @@ -130,0 +111,2 @@ + + @@ -131,0 +114 @@ + @@ -138,0 +122,2 @@ + + @@ -182 +167 @@ - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK @@ -190 +175 @@ - $sql .= " t.libelle as label,"; + $sql .= " t.libelle,"; @@ -201 +186 @@ - $sql .= ' WHERE t.id = '.((int) $id); + $sql .= ' WHERE t.id = '.$id; @@ -212,2 +197 @@ - $this->libelle = $obj->label; - $this->label = $obj->label; + $this->libelle = $obj->libelle; @@ -242 +226 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -252,11 +236,11 @@ - $this->trimParameters( - array( - 'libelle', - 'deductible', - 'active', - 'code', - 'fk_pays', - 'module', - 'accountancy_code', - ) - ); + $this->trimParameters( + array( + 'libelle', + 'deductible', + 'active', + 'code', + 'fk_pays', + 'module', + 'accountancy_code', + ) + ); @@ -271,2 +255,2 @@ - $sql .= ' deductible = '.(isset($this->deductible) ? ((int) $this->deductible) : "null").','; - $sql .= ' active = '.(isset($this->active) ? ((int) $this->active) : "null").','; + $sql .= ' deductible = '.(isset($this->deductible) ? $this->deductible : "null").','; + $sql .= ' active = '.(isset($this->active) ? $this->active : "null").','; @@ -274 +258 @@ - $sql .= ' fk_pays = '.((isset($this->fk_pays) && $this->fk_pays > 0) ? ((int) $this->fk_pays) : "null").','; + $sql .= ' fk_pays = '.(isset($this->fk_pays) ? $this->fk_pays : "null").','; @@ -277 +261 @@ - $sql .= ' WHERE id='.((int) $this->id); + $sql .= ' WHERE id='.$this->id; @@ -289,7 +273,7 @@ - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers @@ -316 +300 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -327,9 +311,9 @@ - //if (!$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_DELETE',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers - //} + //if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_DELETE',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + //} @@ -340 +324 @@ - $sql .= ' WHERE id = '.((int) $this->id); + $sql .= ' WHERE id='.$this->id; @@ -369 +353 @@ - /*public function createFromClone(User $user, $fromid) + public function createFromClone(User $user, $fromid) @@ -409 +393 @@ - }*/ + } @@ -417,3 +401,3 @@ - * @param integer $notooltip 1=Disable tooltip - * @param int $maxlen Max length of visible user name - * @param string $morecss Add more css on link + * @param integer $notooltip 1=Disable tooltip + * @param int $maxlen Max length of visible user name + * @param string $morecss Add more css on link @@ -422 +406 @@ - /*public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '') + public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '') @@ -425,14 +409,14 @@ - global $dolibarr_main_authentication, $dolibarr_main_demo; - global $menumanager; - - - $result = ''; - $companylink = ''; - - $label = ''.$langs->trans("MyModule").''; - $label .= '
'; - $label .= ''.$langs->trans('Ref').': '.$this->ref; - - $link = 'trans("MyModule").''; + $label .= '
'; + $label .= ''.$langs->trans('Ref').': '.$this->ref; + + $link = 'trans('Enabled'); - } elseif ($status == 0) { - return $langs->trans('Disabled'); - } - } elseif ($mode == 1) { - if ($status == 1) { - return $langs->trans('Enabled'); - } elseif ($status == 0) { - return $langs->trans('Disabled'); - } - } elseif ($mode == 2) { - if ($status == 1) { - return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); - } elseif ($status == 0) { - return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); - } - } elseif ($mode == 3) { - if ($status == 1) { - return img_picto($langs->trans('Enabled'), 'statut4'); - } elseif ($status == 0) { - return img_picto($langs->trans('Disabled'), 'statut5'); - } - } elseif ($mode == 4) { - if ($status == 1) { - return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); - } elseif ($status == 0) { - return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); - } - } elseif ($mode == 5) { - if ($status == 1) { - return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4'); - } elseif ($status == 0) { - return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5'); - } - } - return ""; + if ($mode == 0) + { + if ($status == 1) return $langs->trans('Enabled'); + elseif ($status == 0) return $langs->trans('Disabled'); + } + elseif ($mode == 1) + { + if ($status == 1) return $langs->trans('Enabled'); + elseif ($status == 0) return $langs->trans('Disabled'); + } + elseif ($mode == 2) + { + if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); + elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); + } + elseif ($mode == 3) + { + if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4'); + elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5'); + } + elseif ($mode == 4) + { + if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); + elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); + } + elseif ($mode == 5) + { + if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4'); + elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5'); + } @@ -527 +501,0 @@ - $this->label = ''; @@ -536,14 +510,15 @@ - /** - * Trim object parameters - * - * @param string[] $parameters array of parameters to trim - * @return void - */ - private function trimParameters($parameters) - { - foreach ($parameters as $parameter) { - if (isset($this->$parameter)) { - $this->$parameter = trim($this->$parameter); - } - } - } + /** + * Trim object parameters + * @param string[] $parameters array of parameters to trim + * + * @return void + */ + private function trimParameters($parameters) + { + if (!is_array($parameters)) return; + foreach ($parameters as $parameter) { + if (isset($this->$parameter)) { + $this->$parameter = trim($this->$parameter); + } + } + } --- /tmp/dsg/dolibarr/htdocs/compta/sociales/class/github_19.0.3_chargesociales.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/sociales/class/client_chargesociales.class.php @@ -4 +4 @@ - * Copyright (C) 2016-2022 Frédéric France + * Copyright (C) 2016-2019 Frédéric France @@ -6 +5,0 @@ - * Copyright (C) 2021 Gauthier VERDOL @@ -36 +35 @@ - /** + /** @@ -41,3 +40,3 @@ - public $table = 'chargesociales'; - - /** + public $table = 'chargesociales'; + + /** @@ -47,0 +47,48 @@ + /** + * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png + */ + public $picto = 'bill'; + + /** + * {@inheritdoc} + */ + protected $table_ref_field = 'ref'; + + /** + * @var integer|string $date_ech + */ + public $date_ech; + + + public $label; + public $type; + public $type_label; + public $amount; + public $paye; + public $periode; + + /** + * @var integer|string date_creation + */ + public $date_creation; + + /** + * @var integer|string $date_modification + */ + public $date_modification; + + /** + * @var integer|string $date_validation + */ + public $date_validation; + + /** + * @deprecated Use label instead + */ + public $lib; + + /** + * @var int account ID + */ + public $fk_account; + @@ -49,68 +96,12 @@ - * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png - */ - public $picto = 'bill'; - - /** - * {@inheritdoc} - */ - protected $table_ref_field = 'ref'; - - /** - * @var integer|string $date_ech - */ - public $date_ech; - - - public $label; - public $type; - public $type_label; - public $amount; - public $paye; - /** - * @deprecated - */ - public $periode; - public $period; - - /** - * @var integer|string date_creation - */ - public $date_creation; - - /** - * @var integer|string $date_modification - */ - public $date_modification; - - /** - * @var integer|string $date_validation - */ - public $date_validation; - - /** - * @deprecated Use label instead - */ - public $lib; - - /** - * @var int account ID - */ - public $fk_account; - - /** - * @var int account ID (identical to fk_account) - */ - public $accountid; - - /** - * @var int payment type (identical to mode_reglement_id in commonobject class) - */ - public $paiementtype; - - public $mode_reglement_id; - public $mode_reglement_code; - public $mode_reglement; - - /** - * @var int ID - */ + * @var int account ID (identical to fk_account) + */ + public $accountid; + + /** + * @var int payment type (identical to mode_reglement_id in commonobject class) + */ + public $paiementtype; + + /** + * @var int ID + */ @@ -118,12 +108,0 @@ - - /** - * @var int ID - */ - public $fk_user; - - /** - * @var double total - */ - public $total; - - public $totalpaid; @@ -136,52 +115,51 @@ - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct(DoliDB $db) - { - $this->db = $db; - } - - /** - * Retrouve et charge une charge sociale - * - * @param int $id Id - * @param string $ref Ref - * @return int Return integer <0 KO >0 OK - */ - public function fetch($id, $ref = '') - { - $sql = "SELECT cs.rowid, cs.date_ech"; - $sql .= ", cs.libelle as label, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode as period, cs.import_key"; - $sql .= ", cs.fk_account, cs.fk_mode_reglement, cs.fk_user, note_public, note_private"; - $sql .= ", c.libelle as type_label"; - $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; - $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id"; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id'; - $sql .= ' WHERE cs.entity IN ('.getEntity('tax').')'; - if ($ref) { - $sql .= " AND cs.ref = '".$this->db->escape($ref)."'"; - } else { - $sql .= " AND cs.rowid = ".((int) $id); - } - - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->date_ech = $this->db->jdate($obj->date_ech); - $this->lib = $obj->label; - $this->label = $obj->label; - $this->type = $obj->fk_type; - $this->type_label = $obj->type_label; - $this->fk_account = $obj->fk_account; - $this->mode_reglement_id = $obj->fk_mode_reglement; - $this->mode_reglement_code = $obj->mode_reglement_code; - $this->mode_reglement = $obj->mode_reglement_libelle; - $this->amount = $obj->amount; + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } + + /** + * Retrouve et charge une charge sociale + * + * @param int $id Id + * @param string $ref Ref + * @return int <0 KO >0 OK + */ + public function fetch($id, $ref = '') + { + $sql = "SELECT cs.rowid, cs.date_ech"; + $sql .= ", cs.libelle as label, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key"; + $sql .= ", cs.fk_account, cs.fk_mode_reglement"; + $sql .= ", c.libelle"; + $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; + $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id"; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id'; + $sql .= ' WHERE cs.entity IN ('.getEntity('tax').')'; + if ($ref) $sql .= " AND cs.rowid = ".$ref; + else $sql .= " AND cs.rowid = ".$id; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->date_ech = $this->db->jdate($obj->date_ech); + $this->lib = $obj->label; + $this->label = $obj->label; + $this->type = $obj->fk_type; + $this->type_label = $obj->libelle; + $this->fk_account = $obj->fk_account; + $this->mode_reglement_id = $obj->fk_mode_reglement; + $this->mode_reglement_code = $obj->mode_reglement_code; + $this->mode_reglement = $obj->mode_reglement_libelle; + $this->amount = $obj->amount; @@ -189,19 +167,19 @@ - $this->fk_user = $obj->fk_user; - $this->note_public = $obj->note_public; - $this->note_private = $obj->note_private; - $this->paye = $obj->paye; - $this->periode = $this->db->jdate($obj->period); - $this->period = $this->db->jdate($obj->period); - $this->import_key = $this->import_key; - - $this->db->free($resql); - - return 1; - } else { - return 0; - } - } else { - $this->error = $this->db->lasterror(); - return -1; - } - } + $this->paye = $obj->paye; + $this->periode = $this->db->jdate($obj->periode); + $this->import_key = $this->import_key; + + $this->db->free($resql); + + return 1; + } + else + { + return 0; + } + } + else + { + $this->error = $this->db->lasterror(); + return -1; + } + } @@ -218,4 +196,6 @@ - // Validation of parameters - if ($newamount == 0 || empty($this->date_ech) || (empty($this->period) && empty($this->periode))) { - return false; - } + // Validation parametres + if (!$newamount > 0 || empty($this->date_ech) || empty($this->periode)) + { + return false; + } + @@ -226,9 +206,9 @@ - /** - * Create a social contribution into database - * - * @param User $user User making creation - * @return int Return integer <0 if KO, id if OK - */ - public function create($user) - { - global $conf; + /** + * Create a social contribution into database + * + * @param User $user User making creation + * @return int <0 if KO, id if OK + */ + public function create($user) + { + global $conf; @@ -237,4 +217,4 @@ - $now = dol_now(); - - // Nettoyage parametres - $newamount = price2num($this->amount, 'MT'); + $now = dol_now(); + + // Nettoyage parametres + $newamount = price2num($this->amount, 'MT'); @@ -243,2 +223,2 @@ - $this->error = "ErrorBadParameter"; - return -2; + $this->error = "ErrorBadParameter"; + return -2; @@ -247,8 +227,8 @@ - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, fk_user, date_creation)"; - $sql .= " VALUES (".((int) $this->type); - $sql .= ", ".($this->fk_account > 0 ? ((int) $this->fk_account) : 'NULL'); - $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "NULL"); - $sql .= ", '".$this->db->escape($this->label ? $this->label : $this->lib)."'"; - $sql .= ", '".$this->db->idate($this->date_ech)."'"; + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, date_creation)"; + $sql .= " VALUES (".$this->type; + $sql .= ", ".($this->fk_account > 0 ? $this->fk_account : 'NULL'); + $sql .= ", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id : "NULL"); + $sql .= ", '".$this->db->escape($this->label ? $this->label : $this->lib)."'"; + $sql .= ", '".$this->db->idate($this->date_ech)."'"; @@ -256,14 +236,13 @@ - $sql .= ", '".price2num($newamount)."'"; - $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 'NULL'); - $sql .= ", ".((int) $conf->entity); - $sql .= ", ".((int) $user->id); - $sql .= ", ".($this->fk_user > 0 ? ((int) $this->fk_user) : 'NULL'); - $sql .= ", '".$this->db->idate($now)."'"; - $sql .= ")"; - - dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales"); - - //dol_syslog("ChargesSociales::create this->id=".$this->id); + $sql .= ", '".price2num($newamount)."'"; + $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 'NULL'); + $sql .= ", ".$conf->entity; + $sql .= ", ".$user->id; + $sql .= ", '".$this->db->idate($now)."'"; + $sql .= ")"; + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales"); + + //dol_syslog("ChargesSociales::create this->id=".$this->id); @@ -271,3 +250 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -278 +255,2 @@ - } else { + } + else { @@ -282,296 +260,267 @@ - } else { - $this->error = $this->db->error(); - $this->db->rollback(); - return -1; - } - } - - - /** - * Delete a social contribution - * - * @param User $user Object user making delete - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete($user) - { - $error = 0; - - $this->db->begin(); - - // Get bank transaction lines for this social contributions - include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - $account = new Account($this->db); - $lines_url = $account->get_url('', $this->id, 'sc'); - - // Delete bank urls - foreach ($lines_url as $line_url) { - if (!$error) { - $accountline = new AccountLine($this->db); - $accountline->fetch($line_url['fk_bank']); - $result = $accountline->delete_urls($user); - if ($result < 0) { - $error++; - } - } - } - - // Delete payments - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge=".((int) $this->id); - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - } - } - - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid=".((int) $this->id); - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - } - } - - if (!$error) { - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; - } - } - - - /** - * Update social or fiscal contribution - * - * @param User $user User that modify - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function update($user, $notrigger = 0) - { - $error = 0; - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; - $sql .= " SET libelle='".$this->db->escape($this->label ? $this->label : $this->lib)."'"; - $sql .= ", date_ech='".$this->db->idate($this->date_ech)."'"; - $sql .= ", periode='".$this->db->idate($this->periode)."'"; - $sql .= ", amount='".price2num($this->amount, 'MT')."'"; - $sql .= ", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) : "NULL"); - $sql .= ", fk_user=".($this->fk_user > 0 ? $this->db->escape($this->fk_user) : "NULL"); - $sql .= ", fk_user_modif=".$user->id; - $sql .= " WHERE rowid=".((int) $this->id); - - dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - - if (!$error) { - if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('SOCIALCONTRIBUTION_MODIFY', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - } - - // Commit or rollback - if ($error) { - foreach ($this->errors as $errmsg) { - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); - } - $this->db->rollback(); - return -1 * $error; - } else { - $this->db->commit(); - return 1; - } - } - - /** - * Calculate amount remaining to pay by year - * - * @param int $year Year - * @return number - */ - public function solde($year = 0) - { - global $conf; - - $sql = "SELECT SUM(f.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f"; - $sql .= " WHERE f.entity = ".$conf->entity; - $sql .= " AND paye = 0"; - - if ($year) { - $sql .= " AND f.datev >= '".((int) $year)."-01-01' AND f.datev <= '".((int) $year)."-12-31' "; - } - - $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result)) { - $obj = $this->db->fetch_object($result); - $this->db->free($result); - return $obj->amount; - } else { - return 0; - } - } else { - print $this->db->error(); - return -1; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Tag social contribution as paid completely - * - * @deprecated - * @see setPaid() - * @param User $user Object user making change - * @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 - * @return int Return integer <0 if KO, >0 if OK - */ - public function setPaid($user) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; - $sql .= " paye = 1"; - $sql .= " WHERE rowid = ".((int) $this->id); - - $return = $this->db->query($sql); - - if ($return) { - $this->paye = 1; - - return 1; - } else { - return -1; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Remove tag paid on social contribution - * - * @deprecated - * @see setUnpaid() - * @param User $user Object user making change - * @return int Return integer <0 if KO, >0 if OK - */ - public function set_unpaid($user) - { - // phpcs:enable - dol_syslog(get_class($this)."::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE); - return $this->setUnpaid($user); - } - - /** - * Remove tag paid on social contribution - * - * @param User $user Object user making change - * @return int Return integer <0 if KO, >0 if OK - */ - public function setUnpaid($user) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; - $sql .= " paye = 0"; - $sql .= " WHERE rowid = ".((int) $this->id); - - $return = $this->db->query($sql); - - if ($return) { - $this->paye = 0; - - return 1; - } else { - return -1; - } - } - - /** - * Retourne le libelle du statut d'une charge (impaye, payee) - * - * @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 recommand to put here amount paid if you have it, 1 otherwise) - * @return string Label - */ - public function getLibStatut($mode = 0, $alreadypaid = -1) - { - return $this->LibStatut($this->paye, $mode, $alreadypaid); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Renvoi le libelle d'un statut donne - * - * @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 recommand 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(); - - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { - global $langs; - //$langs->load("mymodule"); - $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('Unpaid'); - $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('Paid'); - if ($status == self::STATUS_UNPAID && $alreadypaid > 0) { - $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted"); - } - $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('Unpaid'); - $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('Paid'); - if ($status == self::STATUS_UNPAID && $alreadypaid > 0) { - $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted"); - } - } - - $statusType = 'status1'; - if ($status == 0 && $alreadypaid > 0) { - $statusType = 'status3'; - } - if ($status == 1) { - $statusType = 'status6'; - } - - return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); - } - - - /** + } + else + { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } + } + + + /** + * Delete a social contribution + * + * @param User $user Object user making delete + * @return int <0 if KO, >0 if OK + */ + public function delete($user) + { + $error = 0; + + $this->db->begin(); + + // Get bank transaction lines for this social contributions + include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + $account = new Account($this->db); + $lines_url = $account->get_url('', $this->id, 'sc'); + + // Delete bank urls + foreach ($lines_url as $line_url) + { + if (!$error) + { + $accountline = new AccountLine($this->db); + $accountline->fetch($line_url['fk_bank']); + $result = $accountline->delete_urls($user); + if ($result < 0) + { + $error++; + } + } + } + + // Delete payments + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge=".$this->id; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + $this->error = $this->db->lasterror(); + } + } + + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid=".$this->id; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + $this->error = $this->db->lasterror(); + } + } + + if (!$error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * Update social or fiscal contribution + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function update($user, $notrigger = 0) + { + $error = 0; + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; + $sql .= " SET libelle='".$this->db->escape($this->label ? $this->label : $this->lib)."'"; + $sql .= ", date_ech='".$this->db->idate($this->date_ech)."'"; + $sql .= ", periode='".$this->db->idate($this->periode)."'"; + $sql .= ", amount='".price2num($this->amount, 'MT')."'"; + $sql .= ", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) : "NULL"); + $sql .= ", fk_user_modif=".$user->id; + $sql .= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } + + if (!$error) + { + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('SOCIALCHARGES_MODIFY', $user); + if ($result < 0) $error++; + // End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach ($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + $this->db->rollback(); + return -1 * $error; + } + else + { + $this->db->commit(); + return 1; + } + } + + /** + * Calculate amount remaining to pay by year + * + * @param int $year Year + * @return number + */ + public function solde($year = 0) + { + global $conf; + + $sql = "SELECT SUM(f.amount) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f"; + $sql .= " WHERE f.entity = ".$conf->entity; + $sql .= " AND paye = 0"; + + if ($year) { + $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; + } + + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->db->free($result); + return $obj->amount; + } + else + { + return 0; + } + } + else + { + print $this->db->error(); + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Tag social contribution as payed completely + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + public function set_paid($user) + { + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; + $sql .= " paye = 1"; + $sql .= " WHERE rowid = ".$this->id; + $return = $this->db->query($sql); + if ($return) return 1; + else return -1; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Remove tag payed on social contribution + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + public function set_unpaid($user) + { + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; + $sql .= " paye = 0"; + $sql .= " WHERE rowid = ".$this->id; + $return = $this->db->query($sql); + if ($return) return 1; + else return -1; + } + + /** + * Retourne le libelle du statut d'une charge (impaye, payee) + * + * @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 recommand to put here amount payed if you have it, 1 otherwise) + * @return string Label + */ + public function getLibStatut($mode = 0, $alreadypaid = -1) + { + return $this->LibStatut($this->paye, $mode, $alreadypaid); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un statut donne + * + * @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 recommand to put here amount payed 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(); + + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { + global $langs; + //$langs->load("mymodule"); + $this->labelStatus[self::STATUS_UNPAID] = $langs->trans('Unpaid'); + $this->labelStatus[self::STATUS_PAID] = $langs->trans('Paid'); + if ($status == self::STATUS_UNPAID && $alreadypaid > 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted"); + $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans('Unpaid'); + $this->labelStatusShort[self::STATUS_PAID] = $langs->trans('Paid'); + if ($status == self::STATUS_UNPAID && $alreadypaid > 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted"); + } + + $statusType = 'status1'; + if ($status == 0 && $alreadypaid > 0) $statusType = 'status3'; + if ($status == 1) $statusType = 'status6'; + + return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); + } + + + /** @@ -581,2 +530,2 @@ - * @param string $option On what the link point to ('nolink', ...) - * @param int $notooltip 1=Disable tooltip + * @param int $maxlen Max length of label + * @param int $notooltip 1=Disable tooltip @@ -584,123 +533,99 @@ - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @return string String with link - */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $short = 0, $save_lastsearch_value = -1) - { - global $langs, $conf, $user, $form, $hookmanager; - - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } - - $result = ''; - - $url = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$this->id; - - if ($short) { - return $url; - } - - if ($option !== 'nolink') { - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } - } - - if (empty($this->ref)) { - $this->ref = $this->label; - } - - $label = img_picto('', $this->picto, 'class="pictofixedwidth"').''.$langs->trans("SocialContribution").''; - if (isset($this->paye)) { - $label .= ' '.$this->getLibStatut(5); - } - if (!empty($this->ref)) { - $label .= '
'.$langs->trans('Ref').': '.$this->ref; - } - if (!empty($this->label)) { - $label .= '
'.$langs->trans('Label').': '.$this->label; - } - if (!empty($this->type_label)) { - $label .= '
'.$langs->trans('Type').': '.$this->type_label; - } - - $linkclose = ''; - if (empty($notooltip) && $user->hasRight("facture", "read")) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { - $label = $langs->trans("SocialContribution"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip"'; - } - - $linkstart = '
'; - $linkend = ''; - - $result .= $linkstart; - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } - $result .= $linkend; - global $action; - $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } - return $result; - } - - /** - * Return amount of payments already done - * - * @return int Amount of payment already done, <0 if KO - */ - public function getSommePaiement() - { - $table = 'paiementcharge'; - $field = 'fk_charge'; - - $sql = 'SELECT sum(amount) as amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$table; - $sql .= " WHERE ".$field." = ".((int) $this->id); - - dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $amount = 0; - - $obj = $this->db->fetch_object($resql); - if ($obj) { - $amount = $obj->amount ? $obj->amount : 0; - } - - $this->db->free($resql); - return $amount; - } else { - return -1; - } - } - - /** - * Charge les informations d'ordre info dans l'objet entrepot - * - * @param int $id Id of social contribution - * @return int Return integer <0 if KO, >0 if OK - */ - public function info($id) - { - $sql = "SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,"; - $sql .= " e.fk_user_author, e.fk_user_modif, e.fk_user_valid"; + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string String with link + */ + public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $short = 0, $save_lastsearch_value = -1) + { + global $langs, $conf, $user, $form; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + + $result = ''; + + $url = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$this->id; + + if ($short) return $url; + + if ($option !== 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + } + + + if (empty($this->ref)) $this->ref = $this->label; + + $label = ''.$langs->trans("SocialContribution").''; + if (!empty($this->ref)) + $label .= '
'.$langs->trans('Ref').': '.$this->ref; + if (!empty($this->label)) + $label .= '
'.$langs->trans('Label').': '.$this->label; + if (!empty($this->type_label)) + $label .= '
'.$langs->trans('Type').': '.$this->type_label; + + $linkclose = ''; + if (empty($notooltip) && $user->rights->facture->lire) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label = $langs->trans("SocialContribution"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; + } + + $linkstart = ''; + $linkend = ''; + + $result .= $linkstart; + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref); + $result .= $linkend; + + return $result; + } + + /** + * Return amount of payments already done + * + * @return int Amount of payment already done, <0 if KO + */ + public function getSommePaiement() + { + $table = 'paiementcharge'; + $field = 'fk_charge'; + + $sql = 'SELECT sum(amount) as amount'; + $sql .= ' FROM '.MAIN_DB_PREFIX.$table; + $sql .= ' WHERE '.$field.' = '.$this->id; + + dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $amount = 0; + + $obj = $this->db->fetch_object($resql); + if ($obj) $amount = $obj->amount ? $obj->amount : 0; + + $this->db->free($resql); + return $amount; + } + else + { + return -1; + } + } + + /** + * Charge les informations d'ordre info dans l'objet entrepot + * + * @param int $id Id of social contribution + * @return int <0 if KO, >0 if OK + */ + public function info($id) + { + $sql = "SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,"; + $sql .= " e.fk_user_author, e.fk_user_modif, e.fk_user_valid"; @@ -708,95 +633,66 @@ - $sql .= " WHERE e.rowid = ".((int) $id); - - 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); - - $this->id = $obj->rowid; - - $this->user_creation_id = $obj->fk_user_author; - $this->user_modification_id = $obj->fk_user_modif; - $this->user_validation_id = $obj->fk_user_valid; - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = $this->db->jdate($obj->datem); - $this->date_validation = $this->db->jdate($obj->datev); - $this->import_key = $obj->import_key; - } - - $this->db->free($result); - return 1; - } else { - dol_print_error($this->db); - return -1; - } - } - - /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - public function initAsSpecimen() - { - // Initialize parameters - $this->id = 0; - $this->ref = 'SPECIMEN'; - $this->specimen = 1; - $this->paye = 0; - $this->date_creation = dol_now(); - $this->date_ech = $this->date_creation + 3600 * 24 * 30; - $this->periode = $this->date_creation + 3600 * 24 * 30; - $this->period = $this->date_creation + 3600 * 24 * 30; - $this->amount = 100; - $this->label = 'Social contribution label'; - $this->type = 1; - $this->type_label = 'Type of social contribution'; - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $conf, $langs; - - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(0) : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (property_exists($this, 'label')) { - $return .= '  
'.$this->label.'
'; - } - if (!empty($arraydata['project']) && $arraydata['project']->id > 0) { - $return .= '
'.$arraydata['project']->getNomUrl(1).''; - } - if (property_exists($this, 'date_ech')) { - $return .= '
'.$langs->trans("DateEnd").' : '.dol_print_date($this->date_ech, 'day').''; - } - if (property_exists($this, 'amount')) { - $return .= '
'; - $return .= ''.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).''; - } - if (method_exists($this, 'LibStatut')) { - $return .= '
'.$this->getLibStatut(3, $this->alreadypaid).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; - } + $sql .= " WHERE e.rowid = ".$id; + + 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); + + $this->id = $obj->rowid; + + if ($obj->fk_user_author) { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + + if ($obj->fk_user_modif) { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_modif); + $this->user_modification = $muser; + } + + if ($obj->fk_user_valid) { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_validation = $vuser; + } + + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->datem); + $this->date_validation = $this->db->jdate($obj->datev); + $this->import_key = $obj->import_key; + } + + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + public function initAsSpecimen() + { + // Initialize parameters + $this->id = 0; + $this->ref = 'SPECIMEN'; + $this->specimen = 1; + $this->paye = 0; + $this->date = dol_now(); + $this->date_ech = $this->date + 3600 * 24 * 30; + $this->periode = $this->date + 3600 * 24 * 30; + $this->amount = 100; + $this->label = 'Social contribution label'; + $this->type = 1; + $this->type_label = 'Type of social contribution'; + } --- /tmp/dsg/dolibarr/htdocs/compta/sociales/class/github_19.0.3_paymentsocialcontribution.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/sociales/class/client_paymentsocialcontribution.class.php @@ -2,3 +2,2 @@ -/* Copyright (C) 2002 Rodolphe Quiedeville - * Copyright (C) 2004-2007 Laurent Destailleur - * Copyright (C) 2022 Alexandre Spangaro +/* Copyright (C) 2002 Rodolphe Quiedeville + * Copyright (C) 2004-2007 Laurent Destailleur @@ -51,7 +50,2 @@ - * @var string Label - */ - public $label; - - /** - * @var int ID - */ + * @var int ID + */ @@ -65,20 +58,0 @@ - * @var string - */ - public $type_code; - - /** - * @var string - */ - public $type_label; - - /** - * @var int - */ - public $bank_account; - - /** - * @var int - */ - public $bank_line; - - /** @@ -90,6 +64,6 @@ - public $amount; // Total amount of payment - public $amounts = array(); // Array of amounts - - /** - * @var int ID - */ + public $amount; // Total amount of payment + public $amounts = array(); // Array of amounts + + /** + * @var int ID + */ @@ -110,2 +84,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -115,2 +89,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -120,2 +94,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -125,16 +98,0 @@ - * @var int ID - */ - public $chid; - - /** - * @var integer|string datepaye - */ - public $datepaye; - - /** - * @var integer|string paiementtype - */ - public $paiementtype; - - - /** @@ -145 +103 @@ - public function __construct(DoliDB $db) + public function __construct($db) @@ -152,2 +110,2 @@ - * Use this->amounts to have list of lines for the payment - * + * Use this->amounts to have list of lines for the payment + * @@ -155,2 +113,2 @@ - * @param int $closepaidcontrib 1=Also close paid contributions to paid, 0=Do nothing more - * @return int Return integer <0 if KO, id of payment if OK + * @param int $closepaidcontrib 1=Also close payed contributions to paid, 0=Do nothing more + * @return int <0 if KO, id of payment if OK @@ -164 +122 @@ - $now = dol_now(); + $now = dol_now(); @@ -169 +127,2 @@ - if (!$this->datepaye) { + if (!$this->datepaye) + { @@ -175,37 +134,21 @@ - if (isset($this->fk_charge)) { - $this->fk_charge = (int) $this->fk_charge; - } - if (isset($this->amount)) { - $this->amount = trim($this->amount); - } - if (isset($this->fk_typepaiement)) { - $this->fk_typepaiement = (int) $this->fk_typepaiement; - } - if (isset($this->num_payment)) { - $this->num_payment = trim($this->num_payment); - } - if (isset($this->note_private)) { - $this->note_private = trim($this->note_private); - } - if (isset($this->fk_bank)) { - $this->fk_bank = (int) $this->fk_bank; - } - if (isset($this->fk_user_creat)) { - $this->fk_user_creat = (int) $this->fk_user_creat; - } - if (isset($this->fk_user_modif)) { - $this->fk_user_modif = (int) $this->fk_user_modif; - } - - $totalamount = 0; - foreach ($this->amounts as $key => $value) { // How payment is dispatch - $newvalue = price2num($value, 'MT'); - $this->amounts[$key] = $newvalue; - $totalamount += $newvalue; - } - $totalamount = price2num($totalamount); - - // Check parameters - if ($totalamount == 0) { - return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null - } + if (isset($this->fk_charge)) $this->fk_charge = (int) $this->fk_charge; + if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement = (int) $this->fk_typepaiement; + if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); + if (isset($this->note)) $this->note = trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; + + $totalamount = 0; + foreach ($this->amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value, 'MT'); + $this->amounts[$key] = $newvalue; + $totalamount += $newvalue; + } + $totalamount = price2num($totalamount); + + // Check parameters + if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null @@ -216 +159,2 @@ - if ($totalamount != 0) { + if ($totalamount != 0) + { @@ -221,2 +165,2 @@ - $sql .= " ".((float) $totalamount).","; - $sql .= " ".((int) $this->paiementtype).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.","; + $sql .= " ".$totalamount.","; + $sql .= " ".$this->paiementtype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.","; @@ -226 +170,2 @@ - if ($resql) { + if ($resql) + { @@ -230 +175,2 @@ - foreach ($this->amounts as $key => $amount) { + foreach ($this->amounts as $key => $amount) + { @@ -232 +178,2 @@ - if (is_numeric($amount) && $amount != 0) { + if (is_numeric($amount) && $amount <> 0) + { @@ -235,2 +182,3 @@ - // If we want to closed paid invoices - if ($closepaidcontrib) { + // If we want to closed payed invoices + if ($closepaidcontrib) + { @@ -246,4 +194,3 @@ - if ($remaintopay == 0) { - $result = $contrib->setPaid($user); - } else { - dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing."); + if ($remaintopay == 0) + { + $result = $contrib->set_paid($user); @@ -250,0 +198 @@ + else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing."); @@ -254 +202,3 @@ - } else { + } + else + { @@ -260,8 +210,7 @@ - if ($result < 0) { - $error++; - } - - if ($totalamount != 0 && !$error) { - $this->amount = $totalamount; - $this->total = $totalamount; // deprecated - $this->db->commit(); + if ($result < 0) $error++; + + if ($totalamount != 0 && !$error) + { + $this->amount = $totalamount; + $this->total = $totalamount; // deprecated + $this->db->commit(); @@ -269 +218,3 @@ - } else { + } + else + { @@ -280 +231 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -302 +253 @@ - $sql .= " WHERE t.rowid = ".((int) $id); + $sql .= " WHERE t.rowid = ".$id; @@ -307,2 +258,4 @@ - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { @@ -319,0 +273 @@ + $this->num_paiement = $obj->num_payment; @@ -321 +275 @@ - $this->note_private = $obj->note; + $this->note = $obj->note; @@ -335 +289,3 @@ - } else { + } + else + { @@ -347 +303 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -356,24 +312,9 @@ - if (isset($this->fk_charge)) { - $this->fk_charge = (int) $this->fk_charge; - } - if (isset($this->amount)) { - $this->amount = trim($this->amount); - } - if (isset($this->fk_typepaiement)) { - $this->fk_typepaiement = (int) $this->fk_typepaiement; - } - if (isset($this->num_payment)) { - $this->num_payment = trim($this->num_payment); - } - if (isset($this->note_private)) { - $this->note_private = trim($this->note_private); - } - if (isset($this->fk_bank)) { - $this->fk_bank = (int) $this->fk_bank; - } - if (isset($this->fk_user_creat)) { - $this->fk_user_creat = (int) $this->fk_user_creat; - } - if (isset($this->fk_user_modif)) { - $this->fk_user_modif = (int) $this->fk_user_modif; - } + if (isset($this->fk_charge)) $this->fk_charge = (int) $this->fk_charge; + if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement = (int) $this->fk_typepaiement; + if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); + if (isset($this->note)) $this->note = trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; @@ -388 +329,2 @@ - $sql .= " fk_charge=".(isset($this->fk_charge) ? ((int) $this->fk_charge) : "null").","; + + $sql .= " fk_charge=".(isset($this->fk_charge) ? $this->fk_charge : "null").","; @@ -392,3 +334,3 @@ - $sql .= " amount=".(isset($this->amount) ? price2num($this->amount) : "null").","; - $sql .= " fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) : "null").","; - $sql .= " num_paiement=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").","; + $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").","; + $sql .= " fk_typepaiement=".(isset($this->fk_typepaiement) ? $this->fk_typepaiement : "null").","; + $sql .= " num_paiement=".(isset($this->num_paiement) ? "'".$this->db->escape($this->num_paiement)."'" : "null").","; @@ -396,4 +338,6 @@ - $sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").","; - $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) : "null").","; - $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null"); - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").","; + $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").","; + $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").""; + + + $sql .= " WHERE rowid=".$this->id; @@ -405,4 +349 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } @@ -411,2 +352,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -418 +361,3 @@ - } else { + } + else + { @@ -430 +375 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -433,0 +379 @@ + global $conf, $langs; @@ -440,2 +386,3 @@ - if ($this->bank_line > 0) { - $accline = new AccountLine($this->db); + if ($this->bank_line > 0) + { + $accline = new AccountLine($this->db); @@ -443 +390 @@ - $result = $accline->delete($user); + $result = $accline->delete(); @@ -448,3 +395,4 @@ - } - - if (!$error) { + } + + if (!$error) + { @@ -452 +400 @@ - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " WHERE rowid=".$this->id; @@ -456,4 +404 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } @@ -463,2 +408,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -470 +417,3 @@ - } else { + } + else + { @@ -506 +455,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -514 +464,2 @@ - if (!$error) { + if (!$error) + { @@ -517 +468,3 @@ - } else { + } + else + { @@ -525,5 +478,5 @@ - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void @@ -550,15 +503,15 @@ - /** - * Add record into bank for payment with links between this bank record and invoices of payment. - * All payment properties must have been set first like after a call to create(). - * - * @param User $user Object of user making payment - * @param string $mode 'payment_sc' - * @param string $label Label to use in bank record - * @param int $accountid Id of bank account to do link with - * @param string $emetteur_nom Name of transmitter - * @param string $emetteur_banque Name of bank - * @return int Return integer <0 if KO, >0 if OK - */ - public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) - { - global $conf, $langs; + /** + * Add record into bank for payment with links between this bank record and invoices of payment. + * All payment properties must have been set first like after a call to create(). + * + * @param User $user Object of user making payment + * @param string $mode 'payment_sc' + * @param string $label Label to use in bank record + * @param int $accountid Id of bank account to do link with + * @param string $emetteur_nom Name of transmitter + * @param string $emetteur_banque Name of bank + * @return int <0 if KO, >0 if OK + */ + public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) + { + global $conf; @@ -567,96 +520,83 @@ - $this->num_payment = trim($this->num_payment); - - $error = 0; - - if (isModEnabled("banque")) { - include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - - $acc = new Account($this->db); - $acc->fetch($accountid); - - $total = $this->total; - if ($mode == 'payment_sc') { - $total = -$total; - } - - // Insert payment into llx_bank - $bank_line_id = $acc->addline( - $this->datepaye, - $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") - $label, - $total, - $this->num_payment, - '', - $user, - $emetteur_nom, - $emetteur_banque - ); - - // Mise a jour fk_bank dans llx_paiement. - // On connait ainsi le paiement qui a genere l'ecriture bancaire - if ($bank_line_id > 0) { - $result = $this->update_fk_bank($bank_line_id); - if ($result <= 0) { - $error++; - dol_print_error($this->db); - } - - // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction - $url = ''; - if ($mode == 'payment_sc') { - $url = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='; - } - if ($url) { - $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); - if ($result <= 0) { - $error++; - dol_print_error($this->db); - } - } - - // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) - $linkaddedforthirdparty = array(); - foreach ($this->amounts as $key => $value) { - if ($mode == 'payment_sc') { - $socialcontrib = new ChargeSociales($this->db); - $socialcontrib->fetch($key); - $result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ? ' ('.$socialcontrib->lib.')' : ''), 'sc'); - if ($result <= 0) { - dol_print_error($this->db); - } - - if ($socialcontrib->fk_user) { - $fuser = new User($this->db); - $fuser->fetch($socialcontrib->fk_user); - - // Add link 'user' in bank_url between operation and bank transaction - $result = $acc->add_url_line( - $bank_line_id, - $socialcontrib->fk_user, - DOL_URL_ROOT.'/user/card.php?id=', - $fuser->getFullName($langs), - 'user' - ); - - if ($result <= 0) { - $this->error = $acc->error; - $error++; - } - } - } - } - } else { - $this->error = $acc->error; - $error++; - } - } - - if (!$error) { - return 1; - } else { - return -1; - } - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement); + + $error = 0; + + if (!empty($conf->banque->enabled)) + { + include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $acc = new Account($this->db); + $acc->fetch($accountid); + + $total = $this->total; + if ($mode == 'payment_sc') $total = -$total; + + // Insert payment into llx_bank + $bank_line_id = $acc->addline( + $this->datepaye, + $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") + $label, + $total, + $this->num_payment, + '', + $user, + $emetteur_nom, + $emetteur_banque + ); + + // Mise a jour fk_bank dans llx_paiement. + // On connait ainsi le paiement qui a genere l'ecriture bancaire + if ($bank_line_id > 0) + { + $result = $this->update_fk_bank($bank_line_id); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + + // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction + $url = ''; + if ($mode == 'payment_sc') $url = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='; + if ($url) + { + $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + } + + // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) + $linkaddedforthirdparty = array(); + foreach ($this->amounts as $key => $value) + { + if ($mode == 'payment_sc') + { + $socialcontrib = new ChargeSociales($this->db); + $socialcontrib->fetch($key); + $result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ? ' ('.$socialcontrib->lib.')' : ''), 'sc'); + if ($result <= 0) dol_print_error($this->db); + } + } + } + else + { + $this->error = $acc->error; + $error++; + } + } + + if (!$error) + { + return 1; + } + else + { + return -1; + } + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -671,2 +611,2 @@ - // phpcs:enable - $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id); + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id; @@ -676 +616,2 @@ - if ($result) { + if ($result) + { @@ -678 +619,3 @@ - } else { + } + else + { @@ -686,4 +629,4 @@ - * Return the label of the 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 - * @return string Label of status + * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle @@ -696,7 +639,7 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return the 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 - * @return string Label of status + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un statut donne + * + * @param int $status Statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle du statut @@ -706 +649 @@ - // phpcs:enable + // phpcs:enable @@ -761,69 +704,14 @@ - if (empty($this->ref)) { - $this->ref = $this->label; - } - - $label = img_picto('', $this->picto).' '.$langs->trans("SocialContributionPayment").''; - $label .= '
'.$langs->trans('Ref').': '.$this->ref; - if (!empty($this->label)) { - $labeltoshow = $this->label; - $reg = array(); - if (preg_match('/^\((.*)\)$/i', $this->label, $reg)) { - // Label generique car entre parentheses. On l'affiche en le traduisant - if ($reg[1] == 'paiement') { - $reg[1] = 'Payment'; - } - $labeltoshow = $langs->trans($reg[1]); - } - $label .= '
'.$langs->trans('Label').': '.$labeltoshow; - } - if ($this->datep) { - $label .= '
'.$langs->trans('Date').': '.dol_print_date($this->datep, 'day'); - } - - if (!empty($this->id)) { - $link = ''; - $linkend = ''; - - if ($withpicto) { - $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); - } - if ($withpicto && $withpicto != 2) { - $result .= ' '; - } - if ($withpicto != 2) { - $result .= $link.($maxlen ? dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; - } - } - - return $result; - } - - - /** - * Return if object was dispatched into bookkeeping - * - * @return int Return integer <0 if KO, 0=no, 1=yes - */ - public function getVentilExportCompta() - { - $alreadydispatched = 0; - - $type = 'bank'; - - $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->bank_line); - $resql = $this->db->query($sql); - if ($resql) { - $obj = $this->db->fetch_object($resql); - if ($obj) { - $alreadydispatched = $obj->nb; - } - } else { - $this->error = $this->db->lasterror(); - return -1; - } - - if ($alreadydispatched) { - return 1; - } - return 0; - } + if (empty($this->ref)) $this->ref = $this->lib; + $label = $langs->trans("ShowPayment").': '.$this->ref; + + if (!empty($this->id)) { + $link = ''; + $linkend = ''; + + if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); + if ($withpicto && $withpicto != 2) $result .= ' '; + if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; + } + + return $result; + }