| Total Complexity | 91 |
| Total Lines | 621 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like PaymentDonation 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 PaymentDonation, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class PaymentDonation extends CommonObject |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * @var string ID to identify managed object |
||
| 34 | */ |
||
| 35 | public $element='payment_donation'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string Name of table without prefix where object is stored |
||
| 39 | */ |
||
| 40 | public $table_element='payment_donation'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
||
| 44 | */ |
||
| 45 | public $picto = 'payment'; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var int ID |
||
| 49 | */ |
||
| 50 | public $rowid; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var int ID |
||
| 54 | */ |
||
| 55 | public $fk_donation; |
||
| 56 | |||
| 57 | public $datec=''; |
||
| 58 | public $tms=''; |
||
| 59 | public $datep=''; |
||
| 60 | public $amount; // Total amount of payment |
||
| 61 | public $amounts=array(); // Array of amounts |
||
| 62 | public $typepayment; |
||
| 63 | public $num_payment; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var int ID |
||
| 67 | */ |
||
| 68 | public $fk_bank; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var int ID |
||
| 72 | */ |
||
| 73 | public $fk_user_creat; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var int ID |
||
| 77 | */ |
||
| 78 | public $fk_user_modif; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @deprecated |
||
| 82 | * @see $amount, $amounts |
||
| 83 | */ |
||
| 84 | public $total; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Constructor |
||
| 88 | * |
||
| 89 | * @param DoliDB $db Database handler |
||
| 90 | */ |
||
| 91 | public function __construct($db) |
||
| 92 | { |
||
| 93 | $this->db = $db; |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Create payment of donation into database. |
||
| 98 | * Use this->amounts to have list of lines for the payment |
||
| 99 | * |
||
| 100 | * @param User $user User making payment |
||
| 101 | * @param bool $notrigger false=launch triggers after, true=disable triggers |
||
| 102 | * @return int <0 if KO, id of payment if OK |
||
| 103 | */ |
||
| 104 | public function create($user, $notrigger = false) |
||
| 105 | { |
||
| 106 | global $conf, $langs; |
||
| 107 | |||
| 108 | $error=0; |
||
| 109 | |||
| 110 | $now=dol_now(); |
||
| 111 | |||
| 112 | // Validate parameters |
||
| 113 | if (! $this->datepaid) |
||
|
|
|||
| 114 | { |
||
| 115 | $this->error='ErrorBadValueForParameterCreatePaymentDonation'; |
||
| 116 | return -1; |
||
| 117 | } |
||
| 118 | |||
| 119 | // Clean parameters |
||
| 120 | if (isset($this->fk_donation)) $this->fk_donation=trim($this->fk_donation); |
||
|
1 ignored issue
–
show
|
|||
| 121 | if (isset($this->amount)) $this->amount=trim($this->amount); |
||
| 122 | if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); |
||
| 123 | if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); |
||
| 124 | if (isset($this->note)) $this->note=trim($this->note); |
||
| 125 | if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); |
||
|
1 ignored issue
–
show
|
|||
| 126 | if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); |
||
|
1 ignored issue
–
show
|
|||
| 127 | if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); |
||
| 128 | |||
| 129 | $totalamount = 0; |
||
| 130 | foreach ($this->amounts as $key => $value) // How payment is dispatch |
||
| 131 | { |
||
| 132 | $newvalue = price2num($value, 'MT'); |
||
| 133 | $this->amounts[$key] = $newvalue; |
||
| 134 | $totalamount += $newvalue; |
||
| 135 | } |
||
| 136 | $totalamount = price2num($totalamount); |
||
| 137 | |||
| 138 | // Check parameters |
||
| 139 | if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null |
||
| 140 | |||
| 141 | |||
| 142 | $this->db->begin(); |
||
| 143 | |||
| 144 | if ($totalamount != 0) |
||
| 145 | { |
||
| 146 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_donation (fk_donation, datec, datep, amount,"; |
||
| 147 | $sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; |
||
| 148 | $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',"; |
||
| 149 | $sql.= " '".$this->db->idate($this->datepaid)."',"; |
||
| 150 | $sql.= " ".$totalamount.","; |
||
| 151 | $sql.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.","; |
||
| 152 | $sql.= " 0)"; |
||
| 153 | |||
| 154 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
||
| 155 | $resql=$this->db->query($sql); |
||
| 156 | if ($resql) |
||
| 157 | { |
||
| 158 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_donation"); |
||
| 159 | $this->ref = $this->id; |
||
| 160 | } |
||
| 161 | else |
||
| 162 | { |
||
| 163 | $error++; |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | if (! $error && ! $notrigger) |
||
| 168 | { |
||
| 169 | // Call triggers |
||
| 170 | $result=$this->call_trigger('DONATION_PAYMENT_CREATE', $user); |
||
| 171 | if ($result < 0) { $error++; } |
||
| 172 | // End call triggers |
||
| 173 | } |
||
| 174 | |||
| 175 | if ($totalamount != 0 && ! $error) |
||
| 176 | { |
||
| 177 | $this->amount=$totalamount; |
||
| 178 | $this->total=$totalamount; // deprecated |
||
| 179 | $this->db->commit(); |
||
| 180 | return $this->id; |
||
| 181 | } |
||
| 182 | else |
||
| 183 | { |
||
| 184 | $this->error=$this->db->error(); |
||
| 185 | $this->db->rollback(); |
||
| 186 | return -1; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Load object in memory from database |
||
| 192 | * |
||
| 193 | * @param int $id Id object |
||
| 194 | * @return int <0 if KO, >0 if OK |
||
| 195 | */ |
||
| 196 | public function fetch($id) |
||
| 197 | { |
||
| 198 | global $langs; |
||
| 199 | $sql = "SELECT"; |
||
| 200 | $sql.= " t.rowid,"; |
||
| 201 | $sql.= " t.fk_donation,"; |
||
| 202 | $sql.= " t.datec,"; |
||
| 203 | $sql.= " t.tms,"; |
||
| 204 | $sql.= " t.datep,"; |
||
| 205 | $sql.= " t.amount,"; |
||
| 206 | $sql.= " t.fk_typepayment,"; |
||
| 207 | $sql.= " t.num_payment,"; |
||
| 208 | $sql.= " t.note,"; |
||
| 209 | $sql.= " t.fk_bank,"; |
||
| 210 | $sql.= " t.fk_user_creat,"; |
||
| 211 | $sql.= " t.fk_user_modif,"; |
||
| 212 | $sql.= " pt.code as type_code, pt.libelle as type_libelle,"; |
||
| 213 | $sql.= ' b.fk_account'; |
||
| 214 | $sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as t"; |
||
| 215 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id"; |
||
| 216 | $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; |
||
| 217 | $sql.= " WHERE t.rowid = ".$id; |
||
| 218 | |||
| 219 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
||
| 220 | $resql=$this->db->query($sql); |
||
| 221 | if ($resql) |
||
| 222 | { |
||
| 223 | if ($this->db->num_rows($resql)) |
||
| 224 | { |
||
| 225 | $obj = $this->db->fetch_object($resql); |
||
| 226 | |||
| 227 | $this->id = $obj->rowid; |
||
| 228 | $this->ref = $obj->rowid; |
||
| 229 | |||
| 230 | $this->fk_donation = $obj->fk_donation; |
||
| 231 | $this->datec = $this->db->jdate($obj->datec); |
||
| 232 | $this->tms = $this->db->jdate($obj->tms); |
||
| 233 | $this->datep = $this->db->jdate($obj->datep); |
||
| 234 | $this->amount = $obj->amount; |
||
| 235 | $this->fk_typepayment = $obj->fk_typepayment; |
||
| 236 | $this->num_payment = $obj->num_payment; |
||
| 237 | $this->note = $obj->note; |
||
| 238 | $this->fk_bank = $obj->fk_bank; |
||
| 239 | $this->fk_user_creat = $obj->fk_user_creat; |
||
| 240 | $this->fk_user_modif = $obj->fk_user_modif; |
||
| 241 | |||
| 242 | $this->type_code = $obj->type_code; |
||
| 243 | $this->type_libelle = $obj->type_libelle; |
||
| 244 | |||
| 245 | $this->bank_account = $obj->fk_account; |
||
| 246 | $this->bank_line = $obj->fk_bank; |
||
| 247 | } |
||
| 248 | $this->db->free($resql); |
||
| 249 | |||
| 250 | return 1; |
||
| 251 | } |
||
| 252 | else |
||
| 253 | { |
||
| 254 | $this->error="Error ".$this->db->lasterror(); |
||
| 255 | return -1; |
||
| 256 | } |
||
| 257 | } |
||
| 258 | |||
| 259 | |||
| 260 | /** |
||
| 261 | * Update database |
||
| 262 | * |
||
| 263 | * @param User $user User that modify |
||
| 264 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
||
| 265 | * @return int <0 if KO, >0 if OK |
||
| 266 | */ |
||
| 267 | public function update($user, $notrigger = 0) |
||
| 268 | { |
||
| 269 | global $conf, $langs; |
||
| 270 | $error=0; |
||
| 271 | |||
| 272 | // Clean parameters |
||
| 273 | |||
| 274 | if (isset($this->fk_donation)) $this->fk_donation=trim($this->fk_donation); |
||
|
1 ignored issue
–
show
|
|||
| 275 | if (isset($this->amount)) $this->amount=trim($this->amount); |
||
| 276 | if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); |
||
| 277 | if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); |
||
| 278 | if (isset($this->note)) $this->note=trim($this->note); |
||
| 279 | if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); |
||
|
1 ignored issue
–
show
|
|||
| 280 | if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); |
||
|
1 ignored issue
–
show
|
|||
| 281 | if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); |
||
| 282 | |||
| 283 | // Check parameters |
||
| 284 | // Put here code to add control on parameters values |
||
| 285 | |||
| 286 | // Update request |
||
| 287 | $sql = "UPDATE ".MAIN_DB_PREFIX."payment_donation SET"; |
||
| 288 | $sql.= " fk_donation=".(isset($this->fk_donation)?$this->fk_donation:"null").","; |
||
| 289 | $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; |
||
| 290 | $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; |
||
| 291 | $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; |
||
| 292 | $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; |
||
| 293 | $sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").","; |
||
| 294 | $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").","; |
||
| 295 | $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; |
||
| 296 | $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; |
||
| 297 | $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; |
||
| 298 | $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; |
||
| 299 | $sql.= " WHERE rowid=".$this->id; |
||
| 300 | |||
| 301 | $this->db->begin(); |
||
| 302 | |||
| 303 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
||
| 304 | $resql = $this->db->query($sql); |
||
| 305 | if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
||
| 306 | |||
| 307 | if (! $error) |
||
| 308 | { |
||
| 309 | if (! $notrigger) |
||
| 310 | { |
||
| 311 | if (! $error && ! $notrigger) |
||
| 312 | { |
||
| 313 | // Call triggers |
||
| 314 | $result=$this->call_trigger('DONATION_PAYMENT_MODIFY', $user); |
||
| 315 | if ($result < 0) { $error++; } |
||
| 316 | // End call triggers |
||
| 317 | } |
||
| 318 | } |
||
| 319 | } |
||
| 320 | |||
| 321 | // Commit or rollback |
||
| 322 | if ($error) |
||
| 323 | { |
||
| 324 | foreach($this->errors as $errmsg) |
||
| 325 | { |
||
| 326 | dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
||
| 327 | $this->error.=($this->error?', '.$errmsg:$errmsg); |
||
| 328 | } |
||
| 329 | $this->db->rollback(); |
||
| 330 | return -1*$error; |
||
| 331 | } |
||
| 332 | else |
||
| 333 | { |
||
| 334 | $this->db->commit(); |
||
| 335 | return 1; |
||
| 336 | } |
||
| 337 | } |
||
| 338 | |||
| 339 | |||
| 340 | /** |
||
| 341 | * Delete object in database |
||
| 342 | * |
||
| 343 | * @param User $user User that delete |
||
| 344 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
||
| 345 | * @return int <0 if KO, >0 if OK |
||
| 346 | */ |
||
| 347 | public function delete($user, $notrigger = 0) |
||
| 348 | { |
||
| 349 | global $conf, $langs; |
||
| 350 | $error=0; |
||
| 351 | |||
| 352 | $this->db->begin(); |
||
| 353 | |||
| 354 | if (! $error) |
||
| 355 | { |
||
| 356 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; |
||
| 357 | $sql.= " WHERE type='payment_donation' AND url_id=".$this->id; |
||
| 358 | |||
| 359 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
||
| 360 | $resql = $this->db->query($sql); |
||
| 361 | if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
||
| 362 | } |
||
| 363 | |||
| 364 | if (! $error) |
||
| 365 | { |
||
| 366 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_donation"; |
||
| 367 | $sql.= " WHERE rowid=".$this->id; |
||
| 368 | |||
| 369 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
||
| 370 | $resql = $this->db->query($sql); |
||
| 371 | if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
||
| 372 | } |
||
| 373 | |||
| 374 | if (! $error) |
||
| 375 | { |
||
| 376 | if (! $notrigger) |
||
| 377 | { |
||
| 378 | if (! $error && ! $notrigger) |
||
| 379 | { |
||
| 380 | // Call triggers |
||
| 381 | $result=$this->call_trigger('DONATION_PAYMENT_DELETE', $user); |
||
| 382 | if ($result < 0) { $error++; } |
||
| 383 | // End call triggers |
||
| 384 | } |
||
| 385 | } |
||
| 386 | } |
||
| 387 | |||
| 388 | // Commit or rollback |
||
| 389 | if ($error) |
||
| 390 | { |
||
| 391 | foreach($this->errors as $errmsg) |
||
| 392 | { |
||
| 393 | dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
||
| 394 | $this->error.=($this->error?', '.$errmsg:$errmsg); |
||
| 395 | } |
||
| 396 | $this->db->rollback(); |
||
| 397 | return -1*$error; |
||
| 398 | } |
||
| 399 | else |
||
| 400 | { |
||
| 401 | $this->db->commit(); |
||
| 402 | return 1; |
||
| 403 | } |
||
| 404 | } |
||
| 405 | |||
| 406 | |||
| 407 | |||
| 408 | /** |
||
| 409 | * Load an object from its id and create a new one in database |
||
| 410 | * |
||
| 411 | * @param User $user User making the clone |
||
| 412 | * @param int $fromid Id of object to clone |
||
| 413 | * @return int New id of clone |
||
| 414 | */ |
||
| 415 | public function createFromClone(User $user, $fromid) |
||
| 416 | { |
||
| 417 | $error=0; |
||
| 418 | |||
| 419 | $object=new PaymentDonation($this->db); |
||
| 420 | |||
| 421 | $this->db->begin(); |
||
| 422 | |||
| 423 | // Load source object |
||
| 424 | $object->fetch($fromid); |
||
| 425 | $object->id=0; |
||
| 426 | $object->statut=0; |
||
| 427 | |||
| 428 | // Clear fields |
||
| 429 | // ... |
||
| 430 | |||
| 431 | // Create clone |
||
| 432 | $object->context['createfromclone'] = 'createfromclone'; |
||
| 433 | $result=$object->create($user); |
||
| 434 | |||
| 435 | // Other options |
||
| 436 | if ($result < 0) |
||
| 437 | { |
||
| 438 | $this->error=$object->error; |
||
| 439 | $error++; |
||
| 440 | } |
||
| 441 | |||
| 442 | if (! $error) |
||
| 443 | { |
||
| 444 | |||
| 445 | } |
||
| 446 | |||
| 447 | unset($object->context['createfromclone']); |
||
| 448 | |||
| 449 | // End |
||
| 450 | if (! $error) |
||
| 451 | { |
||
| 452 | $this->db->commit(); |
||
| 453 | return $object->id; |
||
| 454 | } |
||
| 455 | else |
||
| 456 | { |
||
| 457 | $this->db->rollback(); |
||
| 458 | return -1; |
||
| 459 | } |
||
| 460 | } |
||
| 461 | |||
| 462 | |||
| 463 | /** |
||
| 464 | * Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee) |
||
| 465 | * |
||
| 466 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long |
||
| 467 | * @return string Libelle |
||
| 468 | */ |
||
| 469 | public function getLibStatut($mode = 0) |
||
| 472 | } |
||
| 473 | |||
| 474 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 475 | /** |
||
| 476 | * Renvoi le libelle d'un statut donne |
||
| 477 | * |
||
| 478 | * @param int $statut Id statut |
||
| 479 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
||
| 480 | * @return string Libelle du statut |
||
| 481 | */ |
||
| 482 | public function LibStatut($statut, $mode = 0) |
||
| 483 | { |
||
| 484 | // phpcs:enable |
||
| 485 | global $langs; |
||
| 486 | |||
| 487 | return ''; |
||
| 488 | } |
||
| 489 | |||
| 490 | |||
| 491 | /** |
||
| 492 | * Initialise an instance with random values. |
||
| 493 | * Used to build previews or test instances. |
||
| 494 | * id must be 0 if object instance is a specimen. |
||
| 495 | * |
||
| 496 | * @return void |
||
| 497 | */ |
||
| 498 | public function initAsSpecimen() |
||
| 499 | { |
||
| 500 | $this->id=0; |
||
| 501 | |||
| 502 | $this->fk_donation=''; |
||
|
1 ignored issue
–
show
|
|||
| 503 | $this->datec=''; |
||
| 504 | $this->tms=''; |
||
| 505 | $this->datep=''; |
||
| 506 | $this->amount=''; |
||
| 507 | $this->fk_typepayment=''; |
||
| 508 | $this->num_payment=''; |
||
| 509 | $this->note=''; |
||
|
1 ignored issue
–
show
|
|||
| 510 | $this->fk_bank=''; |
||
|
1 ignored issue
–
show
|
|||
| 511 | $this->fk_user_creat=''; |
||
|
1 ignored issue
–
show
|
|||
| 512 | $this->fk_user_modif=''; |
||
|
1 ignored issue
–
show
|
|||
| 513 | } |
||
| 514 | |||
| 515 | |||
| 516 | /** |
||
| 517 | * Add record into bank for payment with links between this bank record and invoices of payment. |
||
| 518 | * All payment properties must have been set first like after a call to create(). |
||
| 519 | * |
||
| 520 | * @param User $user Object of user making payment |
||
| 521 | * @param string $mode 'payment_donation' |
||
| 522 | * @param string $label Label to use in bank record |
||
| 523 | * @param int $accountid Id of bank account to do link with |
||
| 524 | * @param string $emetteur_nom Name of transmitter |
||
| 525 | * @param string $emetteur_banque Name of bank |
||
| 526 | * @return int <0 if KO, >0 if OK |
||
| 527 | */ |
||
| 528 | public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) |
||
| 529 | { |
||
| 530 | global $conf; |
||
| 531 | |||
| 532 | $error=0; |
||
| 533 | |||
| 534 | if (! empty($conf->banque->enabled)) |
||
| 535 | { |
||
| 536 | require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; |
||
| 537 | |||
| 538 | $acc = new Account($this->db); |
||
| 539 | $acc->fetch($accountid); |
||
| 540 | |||
| 541 | $total=$this->total; |
||
|
1 ignored issue
–
show
|
|||
| 542 | if ($mode == 'payment_donation') $amount=$total; |
||
| 543 | |||
| 544 | // Insert payment into llx_bank |
||
| 545 | $bank_line_id = $acc->addline( |
||
| 546 | $this->datepaid, |
||
| 547 | $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") |
||
| 548 | $label, |
||
| 549 | $amount, |
||
| 550 | $this->num_payment, |
||
| 551 | '', |
||
| 552 | $user, |
||
| 553 | $emetteur_nom, |
||
| 554 | $emetteur_banque |
||
| 555 | ); |
||
| 556 | |||
| 557 | // Update fk_bank in llx_paiement. |
||
| 558 | // On connait ainsi le paiement qui a genere l'ecriture bancaire |
||
| 559 | if ($bank_line_id > 0) |
||
| 560 | { |
||
| 561 | $result=$this->update_fk_bank($bank_line_id); |
||
| 562 | if ($result <= 0) |
||
| 563 | { |
||
| 564 | $error++; |
||
| 565 | dol_print_error($this->db); |
||
| 566 | } |
||
| 567 | |||
| 568 | // Add link 'payment', 'payment_supplier', 'payment_donation' in bank_url between payment and bank transaction |
||
| 569 | $url=''; |
||
| 570 | if ($mode == 'payment_donation') $url=DOL_URL_ROOT.'/don/payment/card.php?rowid='; |
||
| 571 | if ($url) |
||
| 572 | { |
||
| 573 | $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); |
||
| 574 | if ($result <= 0) |
||
| 575 | { |
||
| 576 | $error++; |
||
| 577 | dol_print_error($this->db); |
||
| 578 | } |
||
| 579 | } |
||
| 580 | } |
||
| 581 | else |
||
| 582 | { |
||
| 583 | $this->error=$acc->error; |
||
| 584 | $error++; |
||
| 585 | } |
||
| 586 | } |
||
| 587 | |||
| 588 | if (! $error) |
||
| 589 | { |
||
| 590 | return 1; |
||
| 591 | } |
||
| 592 | else |
||
| 593 | { |
||
| 594 | return -1; |
||
| 595 | } |
||
| 596 | } |
||
| 597 | |||
| 598 | |||
| 599 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 600 | /** |
||
| 601 | * Update link between the donation payment and the generated line in llx_bank |
||
| 602 | * |
||
| 603 | * @param int $id_bank Id if bank |
||
| 604 | * @return int >0 if OK, <=0 if KO |
||
| 605 | */ |
||
| 606 | public function update_fk_bank($id_bank) |
||
| 621 | } |
||
| 622 | } |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Return clicable name (with picto eventually) |
||
| 626 | * |
||
| 627 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
||
| 628 | * @param int $maxlen Longueur max libelle |
||
| 629 | * @return string Chaine avec URL |
||
| 630 | */ |
||
| 631 | public function getNomUrl($withpicto = 0, $maxlen = 0) |
||
| 651 | } |
||
| 652 | } |
||
| 653 |