Complex classes like BonPrelevement 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 BonPrelevement, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 40 | class BonPrelevement extends CommonObject |
||
| 41 | { |
||
| 42 | public $element='widthdraw'; |
||
| 43 | public $table_element='prelevement_bons'; |
||
| 44 | public $picto = 'payment'; |
||
| 45 | |||
| 46 | var $date_echeance; |
||
| 47 | var $raison_sociale; |
||
| 48 | var $reference_remise; |
||
| 49 | var $emetteur_code_guichet; |
||
| 50 | var $emetteur_numero_compte; |
||
| 51 | var $emetteur_code_banque; |
||
| 52 | var $emetteur_number_key; |
||
| 53 | |||
| 54 | var $emetteur_iban; |
||
| 55 | var $emetteur_bic; |
||
| 56 | var $emetteur_ics; |
||
| 57 | |||
| 58 | var $total; |
||
| 59 | var $_fetched; |
||
| 60 | var $statut; // 0-Wait, 1-Trans, 2-Done |
||
| 61 | var $labelstatut=array(); |
||
| 62 | |||
| 63 | var $invoice_in_error=array(); |
||
| 64 | var $thirdparty_in_error=array(); |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * Constructor |
||
| 69 | * |
||
| 70 | * @param DoliDB $db Database handler |
||
| 71 | * @param string $filename Filename of withdraw receipt |
||
| 72 | */ |
||
| 73 | function __construct($db, $filename='') |
||
| 74 | { |
||
| 75 | global $conf,$langs; |
||
| 76 | |||
| 77 | $error = 0; |
||
| 78 | $this->db = $db; |
||
| 79 | |||
| 80 | $this->filename=$filename; |
||
| 81 | |||
| 82 | $this->date_echeance = time(); |
||
| 83 | $this->raison_sociale = ""; |
||
| 84 | $this->reference_remise = ""; |
||
| 85 | |||
| 86 | $this->emetteur_code_guichet = ""; |
||
| 87 | $this->emetteur_numero_compte = ""; |
||
| 88 | $this->emetteur_code_banque = ""; |
||
| 89 | $this->emetteur_number_key = ""; |
||
| 90 | |||
| 91 | $this->emetteur_iban = ""; |
||
| 92 | $this->emetteur_bic = ""; |
||
| 93 | $this->emetteur_ics = ""; |
||
| 94 | |||
| 95 | $this->factures = array(); |
||
| 96 | |||
| 97 | $this->methodes_trans = array(); |
||
| 98 | |||
| 99 | $this->methodes_trans[0] = "Internet"; |
||
| 100 | |||
| 101 | $this->_fetched = 0; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Add invoice to withdrawal |
||
| 106 | * |
||
| 107 | * @param int $facture_id id invoice to add |
||
| 108 | * @param int $client_id id invoice customer |
||
| 109 | * @param string $client_nom customer name |
||
| 110 | * @param int $amount amount of invoice |
||
| 111 | * @param string $code_banque code of bank withdrawal |
||
| 112 | * @param string $code_guichet code of bank's office |
||
| 113 | * @param string $number bank account number |
||
| 114 | * @param string $number_key number key of account number |
||
| 115 | * @return int >0 if OK, <0 if KO |
||
| 116 | */ |
||
| 117 | function AddFacture($facture_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key) |
||
| 118 | { |
||
| 119 | $result = 0; |
||
| 120 | $line_id = 0; |
||
| 121 | |||
| 122 | $result = $this->addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key); |
||
| 123 | |||
| 124 | if ($result == 0) |
||
| 125 | { |
||
| 126 | if ($line_id > 0) |
||
| 127 | { |
||
| 128 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_facture ("; |
||
| 129 | $sql.= "fk_facture"; |
||
| 130 | $sql.= ",fk_prelevement_lignes"; |
||
| 131 | $sql.= ") VALUES ("; |
||
| 132 | $sql.= $facture_id; |
||
| 133 | $sql.= ", ".$line_id; |
||
| 134 | $sql.= ")"; |
||
| 135 | |||
| 136 | if ($this->db->query($sql)) |
||
| 137 | { |
||
| 138 | $result = 0; |
||
| 139 | } |
||
| 140 | else |
||
| 141 | { |
||
| 142 | $result = -1; |
||
| 143 | dol_syslog(get_class($this)."::AddFacture Erreur $result"); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | else |
||
| 147 | { |
||
| 148 | $result = -2; |
||
| 149 | dol_syslog(get_class($this)."::AddFacture Erreur $result"); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | else |
||
| 153 | { |
||
| 154 | $result = -3; |
||
| 155 | dol_syslog(get_class($this)."::AddFacture Erreur $result"); |
||
| 156 | } |
||
| 157 | |||
| 158 | return $result; |
||
| 159 | |||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Add line to withdrawal |
||
| 164 | * |
||
| 165 | * @param int $line_id id line to add |
||
| 166 | * @param int $client_id id invoice customer |
||
| 167 | * @param string $client_nom customer name |
||
| 168 | * @param int $amount amount of invoice |
||
| 169 | * @param string $code_banque code of bank withdrawal |
||
| 170 | * @param string $code_guichet code of bank's office |
||
| 171 | * @param string $number bank account number |
||
| 172 | * @param string $number_key number key of account number |
||
| 173 | * @return int >0 if OK, <0 if KO |
||
| 174 | */ |
||
| 175 | function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key) |
||
| 176 | { |
||
| 177 | $result = -1; |
||
| 178 | $concat = 0; |
||
| 179 | |||
| 180 | if ($concat == 1) |
||
| 181 | { |
||
| 182 | /* |
||
| 183 | * We aggregate the lines |
||
| 184 | */ |
||
| 185 | $sql = "SELECT rowid"; |
||
| 186 | $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes"; |
||
| 187 | $sql.= " WHERE fk_prelevement_bons = ".$this->id; |
||
| 188 | $sql.= " AND fk_soc =".$client_id; |
||
| 189 | $sql.= " AND code_banque ='".$code_banque."'"; |
||
| 190 | $sql.= " AND code_guichet ='".$code_guichet."'"; |
||
| 191 | $sql.= " AND number ='".$number."'"; |
||
| 192 | |||
| 193 | $resql=$this->db->query($sql); |
||
| 194 | if ($resql) |
||
| 195 | { |
||
| 196 | $num = $this->db->num_rows($resql); |
||
| 197 | } |
||
| 198 | else |
||
| 199 | { |
||
| 200 | $result = -1; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | else |
||
| 204 | { |
||
| 205 | /* |
||
| 206 | * No aggregate |
||
| 207 | */ |
||
| 208 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_lignes ("; |
||
| 209 | $sql.= "fk_prelevement_bons"; |
||
| 210 | $sql.= ", fk_soc"; |
||
| 211 | $sql.= ", client_nom"; |
||
| 212 | $sql.= ", amount"; |
||
| 213 | $sql.= ", code_banque"; |
||
| 214 | $sql.= ", code_guichet"; |
||
| 215 | $sql.= ", number"; |
||
| 216 | $sql.= ", cle_rib"; |
||
| 217 | $sql.= ") VALUES ("; |
||
| 218 | $sql.= $this->id; |
||
| 219 | $sql.= ", ".$client_id; |
||
| 220 | $sql.= ", '".$this->db->escape($client_nom)."'"; |
||
| 221 | $sql.= ", '".price2num($amount)."'"; |
||
| 222 | $sql.= ", '".$code_banque."'"; |
||
| 223 | $sql.= ", '".$code_guichet."'"; |
||
| 224 | $sql.= ", '".$number."'"; |
||
| 225 | $sql.= ", '".$number_key."'"; |
||
| 226 | $sql.= ")"; |
||
| 227 | |||
| 228 | if ($this->db->query($sql)) |
||
| 229 | { |
||
| 230 | $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_lignes"); |
||
| 231 | $result = 0; |
||
| 232 | } |
||
| 233 | else |
||
| 234 | { |
||
| 235 | dol_syslog(get_class($this)."::addline Error -2"); |
||
| 236 | $result = -2; |
||
| 237 | } |
||
| 238 | |||
| 239 | } |
||
| 240 | |||
| 241 | return $result; |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Return error string |
||
| 246 | * |
||
| 247 | * @param int $error Id of error |
||
| 248 | * @return string Error string |
||
| 249 | */ |
||
| 250 | function getErrorString($error) |
||
| 251 | { |
||
| 252 | global $langs; |
||
| 253 | |||
| 254 | $errors = array(); |
||
| 255 | |||
| 256 | $errors[1027] = $langs->trans("DateInvalid"); |
||
| 257 | |||
| 258 | return $errors[abs($error)]; |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Get object and lines from database |
||
| 263 | * |
||
| 264 | * @param int $rowid Id of object to load |
||
| 265 | * @param string $ref Ref of direct debit |
||
| 266 | * @return int >0 if OK, <0 if KO |
||
| 267 | */ |
||
| 268 | function fetch($rowid, $ref='') |
||
| 269 | { |
||
| 270 | global $conf; |
||
| 271 | |||
| 272 | $sql = "SELECT p.rowid, p.ref, p.amount, p.note"; |
||
| 273 | $sql.= ", p.datec as dc"; |
||
| 274 | $sql.= ", p.date_trans as date_trans"; |
||
| 275 | $sql.= ", p.method_trans, p.fk_user_trans"; |
||
| 276 | $sql.= ", p.date_credit as date_credit"; |
||
| 277 | $sql.= ", p.fk_user_credit"; |
||
| 278 | $sql.= ", p.statut"; |
||
| 279 | $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; |
||
| 280 | $sql.= " WHERE p.entity IN (".getEntity('facture').")"; |
||
| 281 | if ($rowid > 0) $sql.= " AND p.rowid = ".$rowid; |
||
| 282 | else $sql.= " AND p.ref = '".$this->db->escape($ref)."'"; |
||
| 283 | |||
| 284 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
||
| 285 | $result=$this->db->query($sql); |
||
| 286 | if ($result) |
||
| 287 | { |
||
| 288 | if ($this->db->num_rows($result)) |
||
| 289 | { |
||
| 290 | $obj = $this->db->fetch_object($result); |
||
| 291 | |||
| 292 | $this->id = $obj->rowid; |
||
| 293 | $this->ref = $obj->ref; |
||
| 294 | $this->amount = $obj->amount; |
||
| 295 | $this->note = $obj->note; |
||
| 296 | $this->datec = $this->db->jdate($obj->dc); |
||
| 297 | |||
| 298 | $this->date_trans = $this->db->jdate($obj->date_trans); |
||
| 299 | $this->method_trans = $obj->method_trans; |
||
| 300 | $this->user_trans = $obj->fk_user_trans; |
||
| 301 | |||
| 302 | $this->date_credit = $this->db->jdate($obj->date_credit); |
||
| 303 | $this->user_credit = $obj->fk_user_credit; |
||
| 304 | |||
| 305 | $this->statut = $obj->statut; |
||
| 306 | |||
| 307 | $this->_fetched = 1; |
||
| 308 | |||
| 309 | return 1; |
||
| 310 | } |
||
| 311 | else |
||
| 312 | { |
||
| 313 | dol_syslog(get_class($this)."::Fetch Erreur aucune ligne retournee"); |
||
| 314 | return -1; |
||
| 315 | } |
||
| 316 | } |
||
| 317 | else |
||
| 318 | { |
||
| 319 | return -2; |
||
| 320 | } |
||
| 321 | } |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Set credite and set status of linked invoices. Still used ?? |
||
| 325 | * |
||
| 326 | * @return int <0 if KO, >=0 if OK |
||
| 327 | */ |
||
| 328 | function set_credite() |
||
| 329 | { |
||
| 330 | global $user,$conf; |
||
| 331 | |||
| 332 | $error = 0; |
||
| 333 | |||
| 334 | if ($this->db->begin()) |
||
| 335 | { |
||
| 336 | $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; |
||
| 337 | $sql.= " SET statut = 1"; |
||
| 338 | $sql.= " WHERE rowid = ".$this->id; |
||
| 339 | $sql.= " AND entity = ".$conf->entity; |
||
| 340 | |||
| 341 | $result=$this->db->query($sql); |
||
| 342 | if (! $result) |
||
| 343 | { |
||
| 344 | dol_syslog(get_class($this)."::set_credite Erreur 1"); |
||
| 345 | $error++; |
||
| 346 | } |
||
| 347 | |||
| 348 | if (! $error) |
||
| 349 | { |
||
| 350 | $facs = array(); |
||
| 351 | $facs = $this->getListInvoices(); |
||
| 352 | |||
| 353 | $num=count($facs); |
||
| 354 | for ($i = 0; $i < $num; $i++) |
||
| 355 | { |
||
| 356 | /* Tag invoice as payed */ |
||
| 357 | dol_syslog(get_class($this)."::set_credite set_paid fac ".$facs[$i]); |
||
| 358 | $fac = new Facture($this->db); |
||
| 359 | $fac->fetch($facs[$i]); |
||
| 360 | $result = $fac->set_paid($user); |
||
| 361 | } |
||
| 362 | } |
||
| 363 | |||
| 364 | if (! $error) |
||
| 365 | { |
||
| 366 | $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; |
||
| 367 | $sql.= " SET statut = 2"; |
||
| 368 | $sql.= " WHERE fk_prelevement_bons = ".$this->id; |
||
| 369 | |||
| 370 | if (! $this->db->query($sql)) |
||
| 371 | { |
||
| 372 | dol_syslog(get_class($this)."::set_credite Erreur 1"); |
||
| 373 | $error++; |
||
| 374 | } |
||
| 375 | } |
||
| 376 | |||
| 377 | /* |
||
| 378 | * End of procedure |
||
| 379 | */ |
||
| 380 | if (! $error) |
||
| 381 | { |
||
| 382 | $this->db->commit(); |
||
| 383 | return 0; |
||
| 384 | } |
||
| 385 | else |
||
| 386 | { |
||
| 387 | $this->db->rollback(); |
||
| 388 | dol_syslog(get_class($this)."::set_credite ROLLBACK "); |
||
| 389 | |||
| 390 | return -1; |
||
| 391 | } |
||
| 392 | } |
||
| 393 | else |
||
| 394 | { |
||
| 395 | dol_syslog(get_class($this)."::set_credite Ouverture transaction SQL impossible "); |
||
| 396 | return -2; |
||
| 397 | } |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Set direct debit order to "credited" status. |
||
| 402 | * |
||
| 403 | * @param User $user Id of user |
||
| 404 | * @param int $date date of action |
||
| 405 | * @return int >0 if OK, <0 if KO |
||
| 406 | */ |
||
| 407 | function set_infocredit($user, $date) |
||
| 408 | { |
||
| 409 | global $conf,$langs; |
||
| 410 | |||
| 411 | $error = 0; |
||
| 412 | |||
| 413 | if ($this->_fetched == 1) |
||
| 414 | { |
||
| 415 | if ($date >= $this->date_trans) |
||
| 416 | { |
||
| 417 | if ($this->db->begin()) |
||
| 418 | { |
||
| 419 | $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons "; |
||
| 420 | $sql.= " SET fk_user_credit = ".$user->id; |
||
| 421 | $sql.= ", statut = 2"; |
||
| 422 | $sql.= ", date_credit = '".$this->db->idate($date)."'"; |
||
| 423 | $sql.= " WHERE rowid=".$this->id; |
||
| 424 | $sql.= " AND entity = ".$conf->entity; |
||
| 425 | $sql.= " AND statut = 1"; |
||
| 426 | |||
| 427 | if ($this->db->query($sql)) |
||
| 428 | { |
||
| 429 | |||
| 430 | $langs->load('withdrawals'); |
||
| 431 | $subject = $langs->trans("InfoCreditSubject", $this->ref); |
||
| 432 | $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date,'dayhour')); |
||
| 433 | |||
| 434 | //Add payment of withdrawal into bank |
||
| 435 | $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; |
||
| 436 | $facs = array(); |
||
| 437 | $amounts = array(); |
||
| 438 | $amountsperthirdparty = array(); |
||
| 439 | |||
| 440 | $facs = $this->getListInvoices(1); |
||
| 441 | |||
| 442 | // Loop on each invoice. $facs=array(0=>id, 1=>amount requested) |
||
| 443 | $num=count($facs); |
||
| 444 | for ($i = 0; $i < $num; $i++) |
||
| 445 | { |
||
| 446 | $fac = new Facture($this->db); |
||
| 447 | $fac->fetch($facs[$i][0]); |
||
| 448 | $amounts[$fac->id] = $facs[$i][1]; |
||
| 449 | $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1]; |
||
| 450 | |||
| 451 | $totalpaye = $fac->getSommePaiement(); |
||
| 452 | $totalcreditnotes = $fac->getSumCreditNotesUsed(); |
||
| 453 | $totaldeposits = $fac->getSumDepositsUsed(); |
||
| 454 | $alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits; |
||
| 455 | |||
| 456 | if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) { |
||
| 457 | $result = $fac->set_paid($user); |
||
| 458 | } |
||
| 459 | } |
||
| 460 | |||
| 461 | // Make one payment per customer |
||
| 462 | foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) |
||
| 463 | { |
||
| 464 | $paiement = new Paiement($this->db); |
||
| 465 | $paiement->datepaye = $date; |
||
| 466 | $paiement->amounts = $cursoramounts; // Array with detail of dispatching of payments for each invoice |
||
| 467 | $paiement->paiementid = 3; // |
||
| 468 | $paiement->num_paiement = $this->ref; // Set ref of direct debit note |
||
| 469 | $paiement->id_prelevement = $this->id; |
||
| 470 | |||
| 471 | $paiement_id = $paiement->create($user); |
||
| 472 | if ($paiement_id < 0) |
||
| 473 | { |
||
| 474 | dol_syslog(get_class($this)."::set_infocredit AddPayment Error"); |
||
| 475 | $error++; |
||
| 476 | } |
||
| 477 | else |
||
| 478 | { |
||
| 479 | $result=$paiement->addPaymentToBank($user,'payment','(WithdrawalPayment)',$bankaccount,'',''); |
||
| 480 | if ($result < 0) |
||
| 481 | { |
||
| 482 | dol_syslog(get_class($this)."::set_infocredit AddPaymentToBank Error"); |
||
| 483 | $error++; |
||
| 484 | } |
||
| 485 | } |
||
| 486 | //var_dump($paiement->amounts); |
||
| 487 | //var_dump($thirdpartyid); |
||
| 488 | //var_dump($cursoramounts); |
||
| 489 | } |
||
| 490 | |||
| 491 | // Update withdrawal line |
||
| 492 | // TODO: Translate to ligneprelevement.class.php |
||
| 493 | $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; |
||
| 494 | $sql.= " SET statut = 2"; |
||
| 495 | $sql.= " WHERE fk_prelevement_bons = ".$this->id; |
||
| 496 | |||
| 497 | if (! $this->db->query($sql)) |
||
| 498 | { |
||
| 499 | dol_syslog(get_class($this)."::set_infocredit Update lines Error"); |
||
| 500 | $error++; |
||
| 501 | } |
||
| 502 | |||
| 503 | } |
||
| 504 | else |
||
| 505 | { |
||
| 506 | dol_syslog(get_class($this)."::set_infocredit Update Bons Error"); |
||
| 507 | $error++; |
||
| 508 | } |
||
| 509 | |||
| 510 | /* |
||
| 511 | * End of procedure |
||
| 512 | */ |
||
| 513 | if ($error == 0) |
||
| 514 | { |
||
| 515 | $this->date_credit = $date; |
||
| 516 | $this->statut = 1; |
||
| 517 | |||
| 518 | $this->db->commit(); |
||
| 519 | return 0; |
||
| 520 | } |
||
| 521 | else |
||
| 522 | { |
||
| 523 | $this->db->rollback(); |
||
| 524 | dol_syslog("bon-prelevment::set_infocredit ROLLBACK "); |
||
| 525 | return -1; |
||
| 526 | } |
||
| 527 | } |
||
| 528 | else |
||
| 529 | { |
||
| 530 | dol_syslog(get_class($this)."::set_infocredit 1025 Open SQL transaction impossible "); |
||
| 531 | return -1025; |
||
| 532 | } |
||
| 533 | } |
||
| 534 | else |
||
| 535 | { |
||
| 536 | dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans "); |
||
| 537 | return -1027; |
||
| 538 | } |
||
| 539 | } |
||
| 540 | else |
||
| 541 | { |
||
| 542 | return -1026; |
||
| 543 | } |
||
| 544 | } |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Set withdrawal to transmited status |
||
| 548 | * |
||
| 549 | * @param User $user id of user |
||
| 550 | * @param int $date date of action |
||
| 551 | * @param string $method method of transmision to bank |
||
| 552 | * @return int >0 if OK, <0 if KO |
||
| 553 | */ |
||
| 554 | function set_infotrans($user, $date, $method) |
||
| 555 | { |
||
| 556 | global $conf,$langs; |
||
| 557 | |||
| 558 | $error = 0; |
||
| 559 | |||
| 560 | dol_syslog(get_class($this)."::set_infotrans Start",LOG_INFO); |
||
| 561 | if ($this->db->begin()) |
||
| 562 | { |
||
| 563 | $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons "; |
||
| 564 | $sql.= " SET fk_user_trans = ".$user->id; |
||
| 565 | $sql.= " , date_trans = '".$this->db->idate($date)."'"; |
||
| 566 | $sql.= " , method_trans = ".$method; |
||
| 567 | $sql.= " , statut = 1"; |
||
| 568 | $sql.= " WHERE rowid = ".$this->id; |
||
| 569 | $sql.= " AND entity = ".$conf->entity; |
||
| 570 | $sql.= " AND statut = 0"; |
||
| 571 | |||
| 572 | if ($this->db->query($sql)) |
||
| 573 | { |
||
| 574 | $this->method_trans = $method; |
||
| 575 | $langs->load('withdrawals'); |
||
| 576 | $subject = $langs->trans("InfoTransSubject", $this->ref); |
||
| 577 | $message = $langs->trans("InfoTransMessage", $this->ref, dolGetFirstLastname($user->firstname, $user->lastname)); |
||
| 578 | $message .=$langs->trans("InfoTransData", price($this->amount), $this->methodes_trans[$this->method_trans], dol_print_date($date,'day')); |
||
| 579 | |||
| 580 | // TODO Call trigger to create a notification using notification module |
||
| 581 | } |
||
| 582 | else |
||
| 583 | { |
||
| 584 | $error++; |
||
| 585 | } |
||
| 586 | |||
| 587 | if ($error == 0) |
||
| 588 | { |
||
| 589 | $this->date_trans = $date; |
||
| 590 | $this->statut = 1; |
||
| 591 | $this->db->commit(); |
||
| 592 | |||
| 593 | return 0; |
||
| 594 | } |
||
| 595 | else |
||
| 596 | { |
||
| 597 | $this->db->rollback(); |
||
| 598 | dol_syslog(get_class($this)."::set_infotrans ROLLBACK", LOG_ERR); |
||
| 599 | |||
| 600 | return -1; |
||
| 601 | } |
||
| 602 | } |
||
| 603 | else |
||
| 604 | { |
||
| 605 | |||
| 606 | dol_syslog(get_class($this)."::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT); |
||
| 607 | return -2; |
||
| 608 | } |
||
| 609 | } |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Get invoice list |
||
| 613 | * |
||
| 614 | * @param int $amounts If you want to get the amount of the order for each invoice |
||
| 615 | * @return array Id of invoices |
||
| 616 | */ |
||
| 617 | private function getListInvoices($amounts=0) |
||
| 669 | |||
| 670 | /** |
||
| 671 | * Returns amount of withdrawal |
||
| 672 | * |
||
| 673 | * @return double Total amount |
||
| 674 | */ |
||
| 675 | function SommeAPrelever() |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Get number of invoices to withdrawal |
||
| 709 | * TODO delete params banque and agence when not necesary |
||
| 710 | * |
||
| 711 | * @param int $banque dolibarr mysoc bank |
||
| 712 | * @param int $agence dolibarr mysoc agence |
||
| 713 | * @return int <O if KO, number of invoices if OK |
||
| 714 | */ |
||
| 715 | function NbFactureAPrelever($banque=0,$agence=0) |
||
| 746 | |||
| 747 | |||
| 748 | /** |
||
| 749 | * Create a withdraw |
||
| 750 | * TODO delete params banque and agence when not necesary |
||
| 751 | * |
||
| 752 | * @param int $banque dolibarr mysoc bank |
||
| 753 | * @param int $agence dolibarr mysoc bank office (guichet) |
||
| 754 | * @param string $mode real=do action, simu=test only |
||
| 755 | * @param string $format FRST, RCUR or ALL |
||
| 756 | * @param string $executiondate Date to execute the transfer |
||
| 757 | * @return int <0 if KO, nbre of invoice withdrawed if OK |
||
| 758 | */ |
||
| 759 | function Create($banque=0, $agence=0, $mode='real', $format='ALL',$executiondate='') |
||
| 1113 | |||
| 1114 | |||
| 1115 | /** |
||
| 1116 | * Get object and lines from database |
||
| 1117 | * |
||
| 1118 | * @param User $user Object user that delete |
||
| 1119 | * @return int >0 if OK, <0 if KO |
||
| 1120 | */ |
||
| 1121 | function delete($user=null) |
||
| 1152 | |||
| 1153 | |||
| 1154 | /** |
||
| 1155 | * Returns clickable name (with picto) |
||
| 1156 | * |
||
| 1157 | * @param int $withpicto link with picto |
||
| 1158 | * @param string $option link target |
||
| 1159 | * @return string URL of target |
||
| 1160 | */ |
||
| 1161 | function getNomUrl($withpicto=0,$option='') |
||
| 1181 | |||
| 1182 | |||
| 1183 | /** |
||
| 1184 | * Delete a notification def by id |
||
| 1185 | * |
||
| 1186 | * @param int $rowid id of notification |
||
| 1187 | * @return int 0 if OK, <0 if KO |
||
| 1188 | */ |
||
| 1189 | function DeleteNotificationById($rowid) |
||
| 1205 | |||
| 1206 | /** |
||
| 1207 | * Delete a notification |
||
| 1208 | * |
||
| 1209 | * @param int $user notification user |
||
| 1210 | * @param string $action notification action |
||
| 1211 | * @return int >0 if OK, <0 if KO |
||
| 1212 | */ |
||
| 1213 | function DeleteNotification($user, $action) |
||
| 1229 | |||
| 1230 | /** |
||
| 1231 | * Add a notification |
||
| 1232 | * |
||
| 1233 | * @param DoliDB $db database handler |
||
| 1234 | * @param int $user notification user |
||
| 1235 | * @param string $action notification action |
||
| 1236 | * @return int 0 if OK, <0 if KO |
||
| 1237 | */ |
||
| 1238 | function AddNotification($db, $user, $action) |
||
| 1263 | |||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * Generate a withdrawal file. |
||
| 1267 | * Generation Formats: |
||
| 1268 | * - Europe: SEPA (France: CFONB no more supported, Spain: AEB19 if external module EsAEB is enabled) |
||
| 1269 | * - Others countries: Warning message |
||
| 1270 | * File is generated with name this->filename |
||
| 1271 | * |
||
| 1272 | * @param string $format FRST, RCUR or ALL |
||
| 1273 | * @param string $executiondate Date to execute transfer |
||
| 1274 | * @return int 0 if OK, <0 if KO |
||
| 1275 | */ |
||
| 1276 | function generate($format='ALL',$executiondate='') |
||
| 1454 | |||
| 1455 | |||
| 1456 | /** |
||
| 1457 | * Write recipient of request (customer) |
||
| 1458 | * |
||
| 1459 | * @param int $rowid id of line |
||
| 1460 | * @param string $client_nom name of customer |
||
| 1461 | * @param string $rib_banque code of bank |
||
| 1462 | * @param string $rib_guichet code of bank office |
||
| 1463 | * @param string $rib_number bank account |
||
| 1464 | * @param float $amount amount |
||
| 1465 | * @param string $facnumber ref of invoice |
||
| 1466 | * @param int $facid id of invoice |
||
| 1467 | * @param string $rib_dom rib domiciliation |
||
| 1468 | * @return void |
||
| 1469 | */ |
||
| 1470 | function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $facnumber, $facid, $rib_dom='') |
||
| 1525 | |||
| 1526 | |||
| 1527 | /** |
||
| 1528 | * Build RUM number for a customer bank account |
||
| 1529 | * |
||
| 1530 | * @param string $row_code_client Customer code (soc.code_client) |
||
| 1531 | * @param int $row_datec Creation date of bank account (rib.datec) |
||
| 1532 | * @param string $row_drum Id of customer bank account (rib.rowid) |
||
| 1533 | * @return string RUM number |
||
| 1534 | */ |
||
| 1535 | static function buildRumNumber($row_code_client, $row_datec, $row_drum) |
||
| 1541 | |||
| 1542 | /** |
||
| 1543 | * Write recipient of request (customer) |
||
| 1544 | * |
||
| 1545 | * @param string $row_code_client soc.code_client as code, |
||
| 1546 | * @param string $row_nom pl.client_nom AS name, |
||
| 1547 | * @param string $row_address soc.address AS adr, |
||
| 1548 | * @param string $row_zip soc.zip |
||
| 1549 | * @param string $row_town soc.town |
||
| 1550 | * @param string $row_country_code c.code AS country, |
||
| 1551 | * @param string $row_cb pl.code_banque AS cb, Not used for SEPA |
||
| 1552 | * @param string $row_cg pl.code_guichet AS cg, Not used for SEPA |
||
| 1553 | * @param string $row_cc pl.number AS cc, Not used for SEPA |
||
| 1554 | * @param string $row_somme pl.amount AS somme, |
||
| 1555 | * @param string $row_facnumber f.facnumber |
||
| 1556 | * @param string $row_idfac pf.fk_facture AS idfac, |
||
| 1557 | * @param string $row_iban rib.iban_prefix AS iban, |
||
| 1558 | * @param string $row_bic rib.bic AS bic, |
||
| 1559 | * @param string $row_datec rib.datec, |
||
| 1560 | * @param string $row_drum rib.rowid used to generate rum |
||
| 1561 | * @return string Return string with SEPA part DrctDbtTxInf |
||
| 1562 | */ |
||
| 1563 | function EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_facnumber, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum) |
||
| 1615 | |||
| 1616 | |||
| 1617 | /** |
||
| 1618 | * Write sender of request (me) |
||
| 1619 | * |
||
| 1620 | * @return void |
||
| 1621 | */ |
||
| 1622 | function EnregEmetteur() |
||
| 1682 | |||
| 1683 | /** |
||
| 1684 | * Write sender of request (me). |
||
| 1685 | * Note: The tag PmtInf is opened here but closed into caller |
||
| 1686 | * |
||
| 1687 | * @param string $configuration conf |
||
| 1688 | * @param int $ladate Date |
||
| 1689 | * @param int $nombre 0 or 1 |
||
| 1690 | * @param float $total Total |
||
| 1691 | * @param string $CrLf End of line character |
||
| 1692 | * @param string $format FRST or RCUR or ALL |
||
| 1693 | * @return string String with SEPA Sender |
||
| 1694 | */ |
||
| 1695 | function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n', $format='FRST') |
||
| 1803 | |||
| 1804 | /** |
||
| 1805 | * Write end |
||
| 1806 | * |
||
| 1807 | * @param int $total total amount |
||
| 1808 | * @return void |
||
| 1809 | */ |
||
| 1810 | function EnregTotal($total) |
||
| 1864 | |||
| 1865 | /** |
||
| 1866 | * Return status label of object |
||
| 1867 | * |
||
| 1868 | * @param int $mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto |
||
| 1869 | * @return string Label |
||
| 1870 | */ |
||
| 1871 | function getLibStatut($mode=0) |
||
| 1875 | |||
| 1876 | /** |
||
| 1877 | * Return status label for a status |
||
| 1878 | * |
||
| 1879 | * @param int $statut id statut |
||
| 1880 | * @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 |
||
| 1881 | * @return string Label |
||
| 1882 | */ |
||
| 1883 | function LibStatut($statut,$mode=0) |
||
| 1933 | |||
| 1934 | } |
||
| 1935 | |||
| 1936 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: