| Total Complexity | 84 |
| Total Lines | 704 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Salary often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Salary, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class Salary extends CommonObject |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var string ID to identify managed object |
||
| 37 | */ |
||
| 38 | public $element = 'salary'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string Name of table without prefix where object is stored |
||
| 42 | */ |
||
| 43 | public $table_element = 'salary'; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
||
| 47 | */ |
||
| 48 | public $picto = 'payment'; |
||
| 49 | |||
| 50 | public $tms; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var int User ID |
||
| 54 | */ |
||
| 55 | public $fk_user; |
||
| 56 | |||
| 57 | public $datep; |
||
| 58 | public $datev; |
||
| 59 | public $amount; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var int ID |
||
| 63 | */ |
||
| 64 | public $fk_project; |
||
| 65 | |||
| 66 | public $type_payment; |
||
| 67 | public $num_payment; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string salary payments label |
||
| 71 | */ |
||
| 72 | public $label; |
||
| 73 | |||
| 74 | public $datesp; |
||
| 75 | public $dateep; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var int ID |
||
| 79 | */ |
||
| 80 | public $fk_bank; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var int ID |
||
| 84 | */ |
||
| 85 | public $fk_user_author; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var int ID |
||
| 89 | */ |
||
| 90 | public $fk_user_modif; |
||
| 91 | |||
| 92 | const STATUS_UNPAID = 0; |
||
| 93 | const STATUS_PAID = 1; |
||
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * Constructor |
||
| 98 | * |
||
| 99 | * @param DoliDB $db Database handler |
||
| 100 | */ |
||
| 101 | public function __construct($db) |
||
| 102 | { |
||
| 103 | $this->db = $db; |
||
| 104 | $this->element = 'salary'; |
||
| 105 | $this->table_element = 'salary'; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Update database |
||
| 110 | * |
||
| 111 | * @param User $user User that modify |
||
| 112 | * @param int $notrigger 0=no, 1=yes (no update trigger) |
||
| 113 | * @return int <0 if KO, >0 if OK |
||
| 114 | */ |
||
| 115 | public function update($user = null, $notrigger = 0) |
||
| 116 | { |
||
| 117 | global $conf, $langs; |
||
| 118 | |||
| 119 | $error = 0; |
||
| 120 | |||
| 121 | // Clean parameters |
||
| 122 | $this->amount = trim($this->amount); |
||
| 123 | $this->label = trim($this->label); |
||
| 124 | $this->note = trim($this->note); |
||
| 125 | |||
| 126 | // Check parameters |
||
| 127 | if (empty($this->fk_user) || $this->fk_user < 0) |
||
| 128 | { |
||
| 129 | $this->error = 'ErrorBadParameter'; |
||
| 130 | return -1; |
||
| 131 | } |
||
| 132 | |||
| 133 | $this->db->begin(); |
||
| 134 | |||
| 135 | // Update request |
||
| 136 | $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET"; |
||
| 137 | |||
| 138 | $sql .= " tms='".$this->db->idate(dol_now())."',"; |
||
| 139 | $sql .= " fk_user=".$this->fk_user.","; |
||
| 140 | /*$sql .= " datep='".$this->db->idate($this->datep)."',"; |
||
| 141 | $sql .= " datev='".$this->db->idate($this->datev)."',";*/ |
||
| 142 | $sql .= " amount=".price2num($this->amount).","; |
||
| 143 | $sql .= " fk_projet=".((int) $this->fk_project).","; |
||
| 144 | $sql .= " fk_typepayment=".$this->type_payment.","; |
||
| 145 | $sql .= " num_payment='".$this->db->escape($this->num_payment)."',"; |
||
| 146 | $sql .= " label='".$this->db->escape($this->label)."',"; |
||
| 147 | $sql .= " datesp='".$this->db->idate($this->datesp)."',"; |
||
| 148 | $sql .= " dateep='".$this->db->idate($this->dateep)."',"; |
||
| 149 | $sql .= " note='".$this->db->escape($this->note)."',"; |
||
| 150 | $sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").","; |
||
| 151 | $sql .= " fk_user_author=".((int) $this->fk_user_author).","; |
||
| 152 | $sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : 'null'); |
||
| 153 | |||
| 154 | $sql .= " WHERE rowid=".$this->id; |
||
| 155 | |||
| 156 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
||
| 157 | $resql = $this->db->query($sql); |
||
| 158 | if (!$resql) |
||
| 159 | { |
||
| 160 | $this->error = "Error ".$this->db->lasterror(); |
||
| 161 | return -1; |
||
| 162 | } |
||
| 163 | |||
| 164 | // Update extrafield |
||
| 165 | if (!$error) |
||
| 166 | { |
||
| 167 | if (!$error) |
||
| 168 | { |
||
| 169 | $result = $this->insertExtraFields(); |
||
| 170 | if ($result < 0) |
||
| 171 | { |
||
| 172 | $error++; |
||
| 173 | } |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | if (!$notrigger) |
||
| 178 | { |
||
| 179 | // Call trigger |
||
| 180 | $result = $this->call_trigger('salary_MODIFY', $user); |
||
| 181 | if ($result < 0) $error++; |
||
| 182 | // End call triggers |
||
| 183 | } |
||
| 184 | |||
| 185 | if (!$error) |
||
| 186 | { |
||
| 187 | $this->db->commit(); |
||
| 188 | return 1; |
||
| 189 | } |
||
| 190 | else { |
||
| 191 | $this->db->rollback(); |
||
| 192 | return -1; |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | |||
| 197 | /** |
||
| 198 | * Load object in memory from database |
||
| 199 | * |
||
| 200 | * @param int $id id object |
||
| 201 | * @param User $user User that load |
||
| 202 | * @return int <0 if KO, >0 if OK |
||
| 203 | */ |
||
| 204 | public function fetch($id, $user = null) |
||
| 205 | { |
||
| 206 | global $langs; |
||
| 207 | $sql = "SELECT"; |
||
| 208 | $sql .= " s.rowid,"; |
||
| 209 | |||
| 210 | $sql .= " s.tms,"; |
||
| 211 | $sql .= " s.fk_user,"; |
||
| 212 | $sql .= " s.datep,"; |
||
| 213 | $sql .= " s.datev,"; |
||
| 214 | $sql .= " s.amount,"; |
||
| 215 | $sql .= " s.fk_projet as fk_project,"; |
||
| 216 | $sql .= " s.fk_typepayment,"; |
||
| 217 | $sql .= " s.num_payment,"; |
||
| 218 | $sql .= " s.label,"; |
||
| 219 | $sql .= " s.datesp,"; |
||
| 220 | $sql .= " s.dateep,"; |
||
| 221 | $sql .= " s.note,"; |
||
| 222 | $sql .= " s.paye,"; |
||
| 223 | $sql .= " s.fk_bank,"; |
||
| 224 | $sql .= " s.fk_user_author,"; |
||
| 225 | $sql .= " s.fk_user_modif,"; |
||
| 226 | $sql .= " s.fk_account"; |
||
| 227 | /*$sql .= " b.fk_type,"; |
||
| 228 | $sql .= " b.rappro";*/ |
||
| 229 | |||
| 230 | $sql .= " FROM ".MAIN_DB_PREFIX."salary as s"; |
||
| 231 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; |
||
| 232 | $sql .= " WHERE s.rowid = ".$id; |
||
| 233 | |||
| 234 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
||
| 235 | $resql = $this->db->query($sql); |
||
| 236 | if ($resql) |
||
| 237 | { |
||
| 238 | if ($this->db->num_rows($resql)) |
||
| 239 | { |
||
| 240 | $obj = $this->db->fetch_object($resql); |
||
| 241 | |||
| 242 | $this->id = $obj->rowid; |
||
| 243 | $this->ref = $obj->rowid; |
||
| 244 | $this->tms = $this->db->jdate($obj->tms); |
||
| 245 | $this->fk_user = $obj->fk_user; |
||
| 246 | $this->datep = $this->db->jdate($obj->datep); |
||
| 247 | $this->datev = $this->db->jdate($obj->datev); |
||
| 248 | $this->amount = $obj->amount; |
||
| 249 | $this->fk_project = $obj->fk_project; |
||
| 250 | $this->type_payment = $obj->fk_typepayment; |
||
| 251 | $this->num_payment = $obj->num_payment; |
||
| 252 | $this->label = $obj->label; |
||
| 253 | $this->datesp = $this->db->jdate($obj->datesp); |
||
| 254 | $this->dateep = $this->db->jdate($obj->dateep); |
||
| 255 | $this->note = $obj->note; |
||
| 256 | $this->paye = $obj->paye; |
||
| 257 | $this->fk_bank = $obj->fk_bank; |
||
| 258 | $this->fk_user_author = $obj->fk_user_author; |
||
| 259 | $this->fk_user_modif = $obj->fk_user_modif; |
||
| 260 | $this->fk_account = $this->accountid = $obj->fk_account; |
||
| 261 | $this->fk_type = $obj->fk_type; |
||
| 262 | $this->rappro = $obj->rappro; |
||
| 263 | |||
| 264 | // Retreive all extrafield |
||
| 265 | // fetch optionals attributes and labels |
||
| 266 | $this->fetch_optionals(); |
||
| 267 | } |
||
| 268 | $this->db->free($resql); |
||
| 269 | |||
| 270 | return 1; |
||
| 271 | } |
||
| 272 | else { |
||
| 273 | $this->error = "Error ".$this->db->lasterror(); |
||
| 274 | return -1; |
||
| 275 | } |
||
| 276 | } |
||
| 277 | |||
| 278 | |||
| 279 | /** |
||
| 280 | * Delete object in database |
||
| 281 | * |
||
| 282 | * @param User $user User that delete |
||
| 283 | * @return int <0 if KO, >0 if OK |
||
| 284 | */ |
||
| 285 | public function delete($user) |
||
| 286 | { |
||
| 287 | global $conf, $langs; |
||
| 288 | |||
| 289 | $error = 0; |
||
| 290 | |||
| 291 | // Call trigger |
||
| 292 | $result = $this->call_trigger('salary_DELETE', $user); |
||
| 293 | if ($result < 0) return -1; |
||
| 294 | // End call triggers |
||
| 295 | |||
| 296 | // Delete extrafields |
||
| 297 | /*if (!$error) |
||
| 298 | { |
||
| 299 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."salary_extrafields"; |
||
| 300 | $sql .= " WHERE fk_object=".$this->id; |
||
| 301 | |||
| 302 | $resql = $this->db->query($sql); |
||
| 303 | if (!$resql) |
||
| 304 | { |
||
| 305 | $this->errors[] = $this->db->lasterror(); |
||
| 306 | $error++; |
||
| 307 | } |
||
| 308 | }*/ |
||
| 309 | |||
| 310 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."salary"; |
||
| 311 | $sql .= " WHERE rowid=".$this->id; |
||
| 312 | |||
| 313 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
||
| 314 | $resql = $this->db->query($sql); |
||
| 315 | if (!$resql) |
||
| 316 | { |
||
| 317 | $this->error = "Error ".$this->db->lasterror(); |
||
| 318 | return -1; |
||
| 319 | } |
||
| 320 | |||
| 321 | return 1; |
||
| 322 | } |
||
| 323 | |||
| 324 | |||
| 325 | /** |
||
| 326 | * Initialise an instance with random values. |
||
| 327 | * Used to build previews or test instances. |
||
| 328 | * id must be 0 if object instance is a specimen. |
||
| 329 | * |
||
| 330 | * @return void |
||
| 331 | */ |
||
| 332 | public function initAsSpecimen() |
||
| 333 | { |
||
| 334 | $this->id = 0; |
||
| 335 | |||
| 336 | $this->tms = ''; |
||
| 337 | $this->fk_user = ''; |
||
| 338 | $this->datep = ''; |
||
| 339 | $this->datev = ''; |
||
| 340 | $this->amount = ''; |
||
| 341 | $this->label = ''; |
||
| 342 | $this->datesp = ''; |
||
| 343 | $this->dateep = ''; |
||
| 344 | $this->note = ''; |
||
| 345 | $this->fk_bank = ''; |
||
| 346 | $this->fk_user_author = ''; |
||
| 347 | $this->fk_user_modif = ''; |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Create in database |
||
| 352 | * |
||
| 353 | * @param User $user User that create |
||
| 354 | * @return int <0 if KO, >0 if OK |
||
| 355 | */ |
||
| 356 | public function create($user) |
||
| 357 | { |
||
| 358 | global $conf, $langs; |
||
| 359 | |||
| 360 | $error = 0; |
||
| 361 | $now = dol_now(); |
||
| 362 | |||
| 363 | // Clean parameters |
||
| 364 | $this->amount = price2num(trim($this->amount)); |
||
| 365 | $this->label = trim($this->label); |
||
| 366 | $this->note = trim($this->note); |
||
| 367 | $this->fk_bank = trim($this->fk_bank); |
||
| 368 | $this->fk_user_author = trim($this->fk_user_author); |
||
| 369 | $this->fk_user_modif = trim($this->fk_user_modif); |
||
| 370 | $this->accountid = trim($this->accountid); |
||
| 371 | $this->paye = trim($this->paye); |
||
| 372 | |||
| 373 | // Check parameters |
||
| 374 | if (!$this->label) |
||
| 375 | { |
||
| 376 | $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")); |
||
| 377 | return -3; |
||
| 378 | } |
||
| 379 | if ($this->fk_user < 0 || $this->fk_user == '') |
||
| 380 | { |
||
| 381 | $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee")); |
||
| 382 | return -4; |
||
| 383 | } |
||
| 384 | if ($this->amount < 0 || $this->amount == '') |
||
| 385 | { |
||
| 386 | $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); |
||
| 387 | return -5; |
||
| 388 | } |
||
| 389 | /* if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) |
||
| 390 | { |
||
| 391 | $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account")); |
||
| 392 | return -6; |
||
| 393 | } |
||
| 394 | if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) |
||
| 395 | { |
||
| 396 | $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")); |
||
| 397 | return -7; |
||
| 398 | }*/ |
||
| 399 | |||
| 400 | $this->db->begin(); |
||
| 401 | |||
| 402 | // Insert into llx_salary |
||
| 403 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."salary (fk_user"; |
||
| 404 | //$sql .= ", datep"; |
||
| 405 | //$sql .= ", datev"; |
||
| 406 | $sql .= ", amount"; |
||
| 407 | $sql .= ", fk_projet"; |
||
| 408 | $sql .= ", salary"; |
||
| 409 | $sql .= ", fk_typepayment"; |
||
| 410 | $sql .= ", fk_account"; |
||
| 411 | $sql .= ", num_payment"; |
||
| 412 | if ($this->note) $sql .= ", note"; |
||
| 413 | $sql .= ", label"; |
||
| 414 | $sql .= ", datesp"; |
||
| 415 | $sql .= ", dateep"; |
||
| 416 | $sql .= ", fk_user_author"; |
||
| 417 | $sql .= ", datec"; |
||
| 418 | $sql .= ", fk_bank"; |
||
| 419 | $sql .= ", entity"; |
||
| 420 | $sql .= ") "; |
||
| 421 | $sql .= " VALUES ("; |
||
| 422 | $sql .= "'".$this->db->escape($this->fk_user)."'"; |
||
| 423 | //$sql .= ", '".$this->db->idate($this->datep)."'"; |
||
| 424 | //$sql .= ", '".$this->db->idate($this->datev)."'"; |
||
| 425 | $sql .= ", ".$this->amount; |
||
| 426 | $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 0); |
||
| 427 | $sql .= ", ".($this->salary > 0 ? $this->salary : "null"); |
||
|
|
|||
| 428 | $sql .= ", ".($this->type_payment > 0 ? $this->type_payment : 0); |
||
| 429 | $sql .= ", ".($this->accountid > 0 ? $this->accountid : "null"); |
||
| 430 | $sql .= ", '".$this->db->escape($this->num_payment)."'"; |
||
| 431 | if ($this->note) $sql .= ", '".$this->db->escape($this->note)."'"; |
||
| 432 | $sql .= ", '".$this->db->escape($this->label)."'"; |
||
| 433 | $sql .= ", '".$this->db->idate($this->datesp)."'"; |
||
| 434 | $sql .= ", '".$this->db->idate($this->dateep)."'"; |
||
| 435 | $sql .= ", '".$this->db->escape($user->id)."'"; |
||
| 436 | $sql .= ", '".$this->db->idate($now)."'"; |
||
| 437 | $sql .= ", NULL"; |
||
| 438 | $sql .= ", ".$conf->entity; |
||
| 439 | $sql .= ")"; |
||
| 440 | |||
| 441 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
||
| 442 | $result = $this->db->query($sql); |
||
| 443 | if ($result) |
||
| 444 | { |
||
| 445 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."salary"); |
||
| 446 | |||
| 447 | if ($this->id > 0) |
||
| 448 | { |
||
| 449 | // Update extrafield |
||
| 450 | if (!$error) { |
||
| 451 | if (!$error) |
||
| 452 | { |
||
| 453 | $result = $this->insertExtraFields(); |
||
| 454 | if ($result < 0) |
||
| 455 | { |
||
| 456 | $error++; |
||
| 457 | } |
||
| 458 | } |
||
| 459 | } |
||
| 460 | |||
| 461 | // Call trigger |
||
| 462 | $result = $this->call_trigger('salary_CREATE', $user); |
||
| 463 | if ($result < 0) $error++; |
||
| 464 | // End call triggers |
||
| 465 | } |
||
| 466 | else $error++; |
||
| 467 | |||
| 468 | if (!$error) |
||
| 469 | { |
||
| 470 | $this->db->commit(); |
||
| 471 | return $this->id; |
||
| 472 | } |
||
| 473 | else { |
||
| 474 | $this->db->rollback(); |
||
| 475 | return -2; |
||
| 476 | } |
||
| 477 | } |
||
| 478 | else { |
||
| 479 | $this->error = $this->db->error(); |
||
| 480 | $this->db->rollback(); |
||
| 481 | return -1; |
||
| 482 | } |
||
| 483 | } |
||
| 484 | |||
| 485 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 486 | /** |
||
| 487 | * Update link between payment salary and line generate into llx_bank |
||
| 488 | * |
||
| 489 | * @param int $id_bank Id bank account |
||
| 490 | * @return int <0 if KO, >0 if OK |
||
| 491 | */ |
||
| 492 | public function update_fk_bank($id_bank) |
||
| 493 | { |
||
| 494 | // phpcs:enable |
||
| 495 | $sql = 'UPDATE '.MAIN_DB_PREFIX.'salary SET fk_bank = '.$id_bank; |
||
| 496 | $sql .= ' WHERE rowid = '.$this->id; |
||
| 497 | $result = $this->db->query($sql); |
||
| 498 | if ($result) |
||
| 499 | { |
||
| 500 | return 1; |
||
| 501 | } |
||
| 502 | else { |
||
| 503 | dol_print_error($this->db); |
||
| 504 | return -1; |
||
| 505 | } |
||
| 506 | } |
||
| 507 | |||
| 508 | |||
| 509 | /** |
||
| 510 | * Send name clicable (with possibly the picto) |
||
| 511 | * |
||
| 512 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
||
| 513 | * @param string $option link option |
||
| 514 | * @param int $notooltip 1=Disable tooltip |
||
| 515 | * @param string $morecss Add more css on link |
||
| 516 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
||
| 517 | * @return string Chaine with URL |
||
| 518 | */ |
||
| 519 | public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
||
| 520 | { |
||
| 521 | global $db, $conf, $langs, $hookmanager; |
||
| 522 | global $dolibarr_main_authentication, $dolibarr_main_demo; |
||
| 523 | global $menumanager; |
||
| 524 | |||
| 525 | if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips |
||
| 526 | |||
| 527 | $result = ''; |
||
| 528 | |||
| 529 | $label = '<u>'.$langs->trans("Salary").'</u>'; |
||
| 530 | $label .= '<br>'; |
||
| 531 | $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref; |
||
| 532 | |||
| 533 | $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id; |
||
| 534 | |||
| 535 | if ($option != 'nolink') |
||
| 536 | { |
||
| 537 | // Add param to save lastsearch_values or not |
||
| 538 | $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
||
| 539 | if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; |
||
| 540 | if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; |
||
| 541 | } |
||
| 542 | |||
| 543 | $linkclose = ''; |
||
| 544 | if (empty($notooltip)) |
||
| 545 | { |
||
| 546 | if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
||
| 547 | { |
||
| 548 | $label = $langs->trans("ShowMyObject"); |
||
| 549 | $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; |
||
| 550 | } |
||
| 551 | $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; |
||
| 552 | $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; |
||
| 553 | |||
| 554 | /* |
||
| 555 | $hookmanager->initHooks(array('myobjectdao')); |
||
| 556 | $parameters=array('id'=>$this->id); |
||
| 557 | $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
||
| 558 | if ($reshook > 0) $linkclose = $hookmanager->resPrint; |
||
| 559 | */ |
||
| 560 | } |
||
| 561 | else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); |
||
| 562 | |||
| 563 | $linkstart = '<a href="'.$url.'"'; |
||
| 564 | $linkstart .= $linkclose.'>'; |
||
| 565 | $linkend = '</a>'; |
||
| 566 | |||
| 567 | $result .= $linkstart; |
||
| 568 | 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); |
||
| 569 | if ($withpicto != 2) $result .= $this->ref; |
||
| 570 | $result .= $linkend; |
||
| 571 | //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); |
||
| 572 | |||
| 573 | global $action, $hookmanager; |
||
| 574 | $hookmanager->initHooks(array('salarypayment')); |
||
| 575 | $parameters = array('id'=>$this->id, 'getnomurl'=>$result); |
||
| 576 | $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
| 577 | if ($reshook > 0) $result = $hookmanager->resPrint; |
||
| 578 | else $result .= $hookmanager->resPrint; |
||
| 579 | |||
| 580 | return $result; |
||
| 581 | } |
||
| 582 | |||
| 583 | /** |
||
| 584 | * Return amount of payments already done |
||
| 585 | * |
||
| 586 | * @return int Amount of payment already done, <0 if KO |
||
| 587 | */ |
||
| 588 | public function getSommePaiement() |
||
| 589 | { |
||
| 590 | $table = 'payment_salary'; |
||
| 591 | $field = 'fk_salary'; |
||
| 592 | |||
| 593 | $sql = 'SELECT sum(amount) as amount'; |
||
| 594 | $sql .= ' FROM '.MAIN_DB_PREFIX.$table; |
||
| 595 | $sql .= ' WHERE '.$field.' = '.$this->id; |
||
| 596 | |||
| 597 | dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); |
||
| 598 | $resql = $this->db->query($sql); |
||
| 599 | |||
| 600 | if ($resql) { |
||
| 601 | $amount = 0; |
||
| 602 | |||
| 603 | $obj = $this->db->fetch_object($resql); |
||
| 604 | if ($obj) $amount = $obj->amount ? $obj->amount : 0; |
||
| 605 | |||
| 606 | $this->db->free($resql); |
||
| 607 | return $amount; |
||
| 608 | } |
||
| 609 | else { |
||
| 610 | return -1; |
||
| 611 | } |
||
| 612 | } |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Information on record |
||
| 616 | * |
||
| 617 | * @param int $id Id of record |
||
| 618 | * @return void |
||
| 619 | */ |
||
| 620 | public function info($id) |
||
| 621 | { |
||
| 622 | $sql = 'SELECT ps.rowid, ps.datec, ps.fk_user_author'; |
||
| 623 | $sql .= ' FROM '.MAIN_DB_PREFIX.'salary as ps'; |
||
| 624 | $sql .= ' WHERE ps.rowid = '.$id; |
||
| 625 | |||
| 626 | dol_syslog(get_class($this).'::info', LOG_DEBUG); |
||
| 627 | $result = $this->db->query($sql); |
||
| 628 | |||
| 629 | if ($result) |
||
| 630 | { |
||
| 631 | if ($this->db->num_rows($result)) |
||
| 632 | { |
||
| 633 | $obj = $this->db->fetch_object($result); |
||
| 634 | $this->id = $obj->rowid; |
||
| 635 | if ($obj->fk_user_author) |
||
| 636 | { |
||
| 637 | $cuser = new User($this->db); |
||
| 638 | $cuser->fetch($obj->fk_user_author); |
||
| 639 | $this->user_creation = $cuser; |
||
| 640 | } |
||
| 641 | $this->date_creation = $this->db->jdate($obj->datec); |
||
| 642 | } |
||
| 643 | $this->db->free($result); |
||
| 644 | } |
||
| 645 | else { |
||
| 646 | dol_print_error($this->db); |
||
| 647 | } |
||
| 648 | } |
||
| 649 | |||
| 650 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 651 | /** |
||
| 652 | * Tag social contribution as payed completely |
||
| 653 | * |
||
| 654 | * @param User $user Object user making change |
||
| 655 | * @return int <0 if KO, >0 if OK |
||
| 656 | */ |
||
| 657 | public function set_paid($user) |
||
| 658 | { |
||
| 659 | // phpcs:enable |
||
| 660 | $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET"; |
||
| 661 | $sql .= " paye = 1"; |
||
| 662 | $sql .= " WHERE rowid = ".$this->id; |
||
| 663 | $return = $this->db->query($sql); |
||
| 664 | if ($return) return 1; |
||
| 665 | else return -1; |
||
| 666 | } |
||
| 667 | |||
| 668 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 669 | /** |
||
| 670 | * Remove tag payed on social contribution |
||
| 671 | * |
||
| 672 | * @param User $user Object user making change |
||
| 673 | * @return int <0 if KO, >0 if OK |
||
| 674 | */ |
||
| 675 | public function set_unpaid($user) |
||
| 676 | { |
||
| 677 | // phpcs:enable |
||
| 678 | $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET"; |
||
| 679 | $sql .= " paye = 0"; |
||
| 680 | $sql .= " WHERE rowid = ".$this->id; |
||
| 681 | $return = $this->db->query($sql); |
||
| 682 | if ($return) return 1; |
||
| 683 | else return -1; |
||
| 684 | } |
||
| 685 | |||
| 686 | |||
| 687 | /** |
||
| 688 | * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) |
||
| 689 | * |
||
| 690 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
||
| 691 | * @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) |
||
| 692 | * @return string Libelle |
||
| 693 | */ |
||
| 694 | public function getLibStatut($mode = 0, $alreadypaid = -1) |
||
| 697 | } |
||
| 698 | |||
| 699 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 700 | /** |
||
| 701 | * Renvoi le libelle d'un statut donne |
||
| 702 | * |
||
| 703 | * @param int $status Id status |
||
| 704 | * @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 |
||
| 705 | * @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) |
||
| 706 | * @return string Label |
||
| 707 | */ |
||
| 708 | public function LibStatut($status, $mode = 0, $alreadypaid = -1) |
||
| 737 | } |
||
| 738 | } |
||
| 739 |