| Total Complexity | 54 |
| Total Lines | 550 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like CompanyPaymentMode 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 CompanyPaymentMode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class CompanyPaymentMode extends CommonObject |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var string ID to identify managed object |
||
| 37 | */ |
||
| 38 | public $element = 'companypaymentmode'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string Name of table without prefix where object is stored |
||
| 42 | */ |
||
| 43 | public $table_element = 'societe_rib'; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var int Does companypaymentmode support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
||
| 47 | */ |
||
| 48 | public $ismultientitymanaged = 2; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var int Does companypaymentmode support extrafields ? 0=No, 1=Yes |
||
| 52 | */ |
||
| 53 | public $isextrafieldmanaged = 0; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string String with name of icon for companypaymentmode. Must be the part after the 'object_' into object_companypaymentmode.png |
||
| 57 | */ |
||
| 58 | public $picto = 'generic'; |
||
| 59 | |||
| 60 | |||
| 61 | const STATUS_ENABLED = 1; |
||
| 62 | const STATUS_CANCELED = 0; |
||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * 'type' if the field format. |
||
| 67 | * 'label' the translation key. |
||
| 68 | * 'enabled' is a condition when the field must be managed. |
||
| 69 | * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing) |
||
| 70 | * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). |
||
| 71 | * 'index' if we want an index in database. |
||
| 72 | * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). |
||
| 73 | * 'position' is the sort order of field. |
||
| 74 | * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. |
||
| 75 | * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). |
||
| 76 | * 'help' is a string visible as a tooltip on field |
||
| 77 | * 'comment' is not used. You can store here any text of your choice. It is not used by application. |
||
| 78 | * 'default' is a default value for creation (can still be replaced by the global setup of default values) |
||
| 79 | * 'showoncombobox' if field must be shown into the label of combobox |
||
| 80 | */ |
||
| 81 | |||
| 82 | // BEGIN MODULEBUILDER PROPERTIES |
||
| 83 | /** |
||
| 84 | * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. |
||
| 85 | */ |
||
| 86 | public $fields=array( |
||
| 87 | 'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10), |
||
| 88 | 'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15), |
||
| 89 | 'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30), |
||
| 90 | 'bank' =>array('type'=>'varchar(255)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-2, 'position'=>35), |
||
| 91 | 'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-2, 'position'=>40), |
||
| 92 | 'code_guichet' =>array('type'=>'varchar(6)', 'label'=>'Code guichet', 'enabled'=>1, 'visible'=>-2, 'position'=>45), |
||
| 93 | 'number' =>array('type'=>'varchar(255)', 'label'=>'Number', 'enabled'=>1, 'visible'=>-2, 'position'=>50), |
||
| 94 | 'cle_rib' =>array('type'=>'varchar(5)', 'label'=>'Cle rib', 'enabled'=>1, 'visible'=>-2, 'position'=>55), |
||
| 95 | 'bic' =>array('type'=>'varchar(20)', 'label'=>'Bic', 'enabled'=>1, 'visible'=>-2, 'position'=>60), |
||
| 96 | 'iban_prefix' =>array('type'=>'varchar(34)', 'label'=>'Iban prefix', 'enabled'=>1, 'visible'=>-2, 'position'=>65), |
||
| 97 | 'domiciliation' =>array('type'=>'varchar(255)', 'label'=>'Domiciliation', 'enabled'=>1, 'visible'=>-2, 'position'=>70), |
||
| 98 | 'proprio' =>array('type'=>'varchar(60)', 'label'=>'Proprio', 'enabled'=>1, 'visible'=>-2, 'position'=>75), |
||
| 99 | 'owner_address' =>array('type'=>'text', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-2, 'position'=>80), |
||
| 100 | 'default_rib' =>array('type'=>'tinyint(4)', 'label'=>'Default rib', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>85), |
||
| 101 | 'rum' =>array('type'=>'varchar(32)', 'label'=>'Rum', 'enabled'=>1, 'visible'=>-2, 'position'=>90), |
||
| 102 | 'date_rum' =>array('type'=>'date', 'label'=>'Date rum', 'enabled'=>1, 'visible'=>-2, 'position'=>95), |
||
| 103 | 'frstrecur' =>array('type'=>'varchar(16)', 'label'=>'Frstrecur', 'enabled'=>1, 'visible'=>-2, 'position'=>100), |
||
| 104 | 'type' =>array('type'=>'varchar(32)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-2, 'position'=>110), |
||
| 105 | 'last_four' =>array('type'=>'varchar(4)', 'label'=>'Last four', 'enabled'=>1, 'visible'=>-2, 'position'=>115), |
||
| 106 | 'card_type' =>array('type'=>'varchar(255)', 'label'=>'Card type', 'enabled'=>1, 'visible'=>-2, 'position'=>120), |
||
| 107 | 'cvn' =>array('type'=>'varchar(255)', 'label'=>'Cvn', 'enabled'=>1, 'visible'=>-2, 'position'=>125), |
||
| 108 | 'exp_date_month' =>array('type'=>'integer', 'label'=>'Exp date month', 'enabled'=>1, 'visible'=>-2, 'position'=>130), |
||
| 109 | 'exp_date_year' =>array('type'=>'integer', 'label'=>'Exp date year', 'enabled'=>1, 'visible'=>-2, 'position'=>135), |
||
| 110 | 'country_code' =>array('type'=>'varchar(10)', 'label'=>'Country code', 'enabled'=>1, 'visible'=>-2, 'position'=>140), |
||
| 111 | 'approved' =>array('type'=>'integer', 'label'=>'Approved', 'enabled'=>1, 'visible'=>-2, 'position'=>145), |
||
| 112 | 'email' =>array('type'=>'varchar(255)', 'label'=>'Email', 'enabled'=>1, 'visible'=>-2, 'position'=>150), |
||
| 113 | 'max_total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Max total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>155), |
||
| 114 | 'preapproval_key' =>array('type'=>'varchar(255)', 'label'=>'Preapproval key', 'enabled'=>1, 'visible'=>-2, 'position'=>160), |
||
| 115 | 'total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>165), |
||
| 116 | 'stripe_card_ref' =>array('type'=>'varchar(128)', 'label'=>'Stripe card ref', 'enabled'=>1, 'visible'=>-2, 'position'=>170), |
||
| 117 | 'stripe_account' =>array('type'=>'varchar(128)', 'label'=>'Stripe account', 'enabled'=>1, 'visible'=>-2, 'position'=>171), |
||
| 118 | 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175), |
||
| 119 | 'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180), |
||
| 120 | 'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185), |
||
| 121 | 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20), |
||
| 122 | 'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25), |
||
| 123 | 'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105), |
||
| 124 | //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185), |
||
| 125 | ); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var int ID |
||
| 129 | */ |
||
| 130 | public $rowid; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var int Thirdparty ID |
||
| 134 | */ |
||
| 135 | public $fk_soc; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var string company payment mode label |
||
| 139 | */ |
||
| 140 | public $label; |
||
| 141 | |||
| 142 | public $bank; |
||
| 143 | public $code_banque; |
||
| 144 | public $code_guichet; |
||
| 145 | public $number; |
||
| 146 | public $cle_rib; |
||
| 147 | public $bic; |
||
| 148 | public $iban_prefix; |
||
| 149 | public $domiciliation; |
||
| 150 | public $proprio; |
||
| 151 | public $owner_address; |
||
| 152 | public $default_rib; |
||
| 153 | public $rum; |
||
| 154 | public $date_rum; |
||
| 155 | public $frstrecur; |
||
| 156 | public $type; |
||
| 157 | public $last_four; |
||
| 158 | public $card_type; |
||
| 159 | public $cvn; |
||
| 160 | public $exp_date_month; |
||
| 161 | public $exp_date_year; |
||
| 162 | public $country_code; |
||
| 163 | public $approved; |
||
| 164 | public $email; |
||
| 165 | public $max_total_amount_of_all_payments; |
||
| 166 | public $preapproval_key; |
||
| 167 | public $total_amount_of_all_payments; |
||
| 168 | public $stripe_card_ref; |
||
| 169 | public $stripe_account; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var int Status |
||
| 173 | */ |
||
| 174 | public $status; |
||
| 175 | |||
| 176 | public $starting_date; |
||
| 177 | public $ending_date; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Date creation record (datec) |
||
| 181 | * |
||
| 182 | * @var integer |
||
| 183 | */ |
||
| 184 | public $datec; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Date modification record (tms) |
||
| 188 | * |
||
| 189 | * @var integer |
||
| 190 | */ |
||
| 191 | public $tms; |
||
| 192 | |||
| 193 | public $import_key; |
||
| 194 | // END MODULEBUILDER PROPERTIES |
||
| 195 | |||
| 196 | |||
| 197 | |||
| 198 | // If this object has a subtable with lines |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @var int Name of subtable line |
||
| 202 | */ |
||
| 203 | //public $table_element_line = 'companypaymentmodedet'; |
||
| 204 | /** |
||
| 205 | * @var int Field with ID of parent key if this field has a parent |
||
| 206 | */ |
||
| 207 | //public $fk_element = 'fk_companypaymentmode'; |
||
| 208 | /** |
||
| 209 | * @var int Name of subtable class that manage subtable lines |
||
| 210 | */ |
||
| 211 | //public $class_element_line = 'CompanyPaymentModeline'; |
||
| 212 | /** |
||
| 213 | * @var array List of child tables. To test if we can delete object. |
||
| 214 | */ |
||
| 215 | //protected $childtables=array(); |
||
| 216 | /** |
||
| 217 | * @var CompanyPaymentModeLine[] Array of subtable lines |
||
| 218 | */ |
||
| 219 | //public $lines = array(); |
||
| 220 | |||
| 221 | |||
| 222 | |||
| 223 | /** |
||
| 224 | * Constructor |
||
| 225 | * |
||
| 226 | * @param DoliDb $db Database handler |
||
| 227 | */ |
||
| 228 | public function __construct(DoliDB $db) |
||
| 229 | { |
||
| 230 | global $conf; |
||
| 231 | |||
| 232 | $this->db = $db; |
||
| 233 | |||
| 234 | if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0; |
||
| 235 | if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0; |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Create object into database |
||
| 240 | * |
||
| 241 | * @param User $user User that creates |
||
| 242 | * @param bool $notrigger false=launch triggers after, true=disable triggers |
||
| 243 | * @return int <0 if KO, Id of created object if OK |
||
| 244 | */ |
||
| 245 | public function create(User $user, $notrigger = false) |
||
| 246 | { |
||
| 247 | $idpayment = $this->createCommon($user, $notrigger); |
||
| 248 | |||
| 249 | return $idpayment; |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Clone and object into another one |
||
| 254 | * |
||
| 255 | * @param User $user User that creates |
||
| 256 | * @param int $fromid Id of object to clone |
||
| 257 | * @return mixed New object created, <0 if KO |
||
| 258 | */ |
||
| 259 | public function createFromClone(User $user, $fromid) |
||
| 260 | { |
||
| 261 | global $hookmanager, $langs; |
||
| 262 | $error = 0; |
||
| 263 | |||
| 264 | dol_syslog(__METHOD__, LOG_DEBUG); |
||
| 265 | |||
| 266 | $object = new self($this->db); |
||
| 267 | |||
| 268 | $this->db->begin(); |
||
| 269 | |||
| 270 | // Load source object |
||
| 271 | $object->fetchCommon($fromid); |
||
| 272 | // Reset some properties |
||
| 273 | unset($object->id); |
||
| 274 | unset($object->fk_user_creat); |
||
| 275 | unset($object->import_key); |
||
| 276 | |||
| 277 | // Clear fields |
||
| 278 | $object->ref = "copy_of_".$object->ref; |
||
| 279 | $object->title = $langs->trans("CopyOf")." ".$object->title; |
||
| 280 | // ... |
||
| 281 | |||
| 282 | // Create clone |
||
| 283 | $object->context['createfromclone'] = 'createfromclone'; |
||
| 284 | $result = $object->createCommon($user); |
||
| 285 | if ($result < 0) { |
||
| 286 | $error++; |
||
| 287 | $this->error = $object->error; |
||
| 288 | $this->errors = $object->errors; |
||
| 289 | } |
||
| 290 | |||
| 291 | unset($object->context['createfromclone']); |
||
| 292 | |||
| 293 | // End |
||
| 294 | if (!$error) { |
||
| 295 | $this->db->commit(); |
||
| 296 | return $object; |
||
| 297 | } else { |
||
| 298 | $this->db->rollback(); |
||
| 299 | return -1; |
||
| 300 | } |
||
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Load object in memory from the database |
||
| 305 | * |
||
| 306 | * @param int $id Id object |
||
| 307 | * @param string $ref Ref |
||
| 308 | * @param int $socid Id of company to get first default payment mode |
||
| 309 | * @param string $type Filter on type ('ban', 'card', ...) |
||
| 310 | * @param string $morewhere More SQL filters (' AND ...') |
||
| 311 | * @return int <0 if KO, 0 if not found, >0 if OK |
||
| 312 | */ |
||
| 313 | public function fetch($id, $ref = null, $socid = 0, $type = '', $morewhere = '') |
||
| 314 | { |
||
| 315 | if ($socid) $morewhere.= " AND fk_soc = ".$this->db->escape($socid)." AND default_rib = 1"; |
||
| 316 | if ($type) $morewhere.= " AND type = '".$this->db->escape($type)."'"; |
||
| 317 | |||
| 318 | $result = $this->fetchCommon($id, $ref, $morewhere); |
||
| 319 | //if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines(); |
||
| 320 | return $result; |
||
| 321 | } |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Load object lines in memory from the database |
||
| 325 | * |
||
| 326 | * @return int <0 if KO, 0 if not found, >0 if OK |
||
| 327 | */ |
||
| 328 | /*public function fetchLines() |
||
| 329 | { |
||
| 330 | $this->lines=array(); |
||
| 331 | |||
| 332 | // Load lines with object CompanyPaymentModeLine |
||
| 333 | |||
| 334 | return count($this->lines)?1:0; |
||
| 335 | }*/ |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Update object into database |
||
| 339 | * |
||
| 340 | * @param User $user User that modifies |
||
| 341 | * @param bool $notrigger false=launch triggers after, true=disable triggers |
||
| 342 | * @return int <0 if KO, >0 if OK |
||
| 343 | */ |
||
| 344 | public function update(User $user, $notrigger = false) |
||
| 345 | { |
||
| 346 | return $this->updateCommon($user, $notrigger); |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Delete object in database |
||
| 351 | * |
||
| 352 | * @param User $user User that deletes |
||
| 353 | * @param bool $notrigger false=launch triggers after, true=disable triggers |
||
| 354 | * @return int <0 if KO, >0 if OK |
||
| 355 | */ |
||
| 356 | public function delete(User $user, $notrigger = false) |
||
| 357 | { |
||
| 358 | return $this->deleteCommon($user, $notrigger); |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Return a link to the object card (with optionaly the picto) |
||
| 363 | * |
||
| 364 | * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
||
| 365 | * @param string $option On what the link point to ('nolink', ...) |
||
| 366 | * @param int $notooltip 1=Disable tooltip |
||
| 367 | * @param string $morecss Add more css on link |
||
| 368 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
||
| 369 | * @return string String with URL |
||
| 370 | */ |
||
| 371 | public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
||
| 372 | { |
||
| 373 | global $db, $conf, $langs; |
||
| 374 | global $dolibarr_main_authentication, $dolibarr_main_demo; |
||
| 375 | global $menumanager; |
||
| 376 | |||
| 377 | if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips |
||
| 378 | |||
| 379 | $result = ''; |
||
| 380 | $companylink = ''; |
||
| 381 | |||
| 382 | $label = '<u>' . $langs->trans("CompanyPaymentMode") . '</u>'; |
||
| 383 | $label.= '<br>'; |
||
| 384 | $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref; |
||
| 385 | |||
| 386 | $url = dol_buildpath('/monmodule/companypaymentmode_card.php', 1).'?id='.$this->id; |
||
| 387 | |||
| 388 | if ($option != 'nolink') |
||
| 389 | { |
||
| 390 | // Add param to save lastsearch_values or not |
||
| 391 | $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
||
| 392 | if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
||
| 393 | if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
||
| 394 | } |
||
| 395 | |||
| 396 | $linkclose=''; |
||
| 397 | if (empty($notooltip)) |
||
| 398 | { |
||
| 399 | if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
||
| 400 | { |
||
| 401 | $label=$langs->trans("ShowCompanyPaymentMode"); |
||
| 402 | $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; |
||
| 403 | } |
||
| 404 | $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; |
||
| 405 | $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; |
||
| 406 | } |
||
| 407 | else $linkclose = ($morecss?' class="'.$morecss.'"':''); |
||
| 408 | |||
| 409 | $linkstart = '<a href="'.$url.'"'; |
||
| 410 | $linkstart.=$linkclose.'>'; |
||
| 411 | $linkend='</a>'; |
||
| 412 | |||
| 413 | $result .= $linkstart; |
||
| 414 | 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); |
||
| 415 | if ($withpicto != 2) $result.= $this->ref; |
||
| 416 | $result .= $linkend; |
||
| 417 | //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); |
||
| 418 | |||
| 419 | return $result; |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Set a Payment mode as Default |
||
| 424 | * |
||
| 425 | * @param int $id Payment mode ID |
||
| 426 | * @param string $alltypes 1=The default is for all payment types instead of per type |
||
| 427 | * @return int 0 if KO, 1 if OK |
||
| 428 | */ |
||
| 429 | public function setAsDefault($id = 0, $alltypes = 0) |
||
| 430 | { |
||
| 431 | $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib"; |
||
| 432 | $sql1.= " WHERE rowid = ".($id?$id:$this->id); |
||
| 433 | |||
| 434 | dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
||
| 435 | $result1 = $this->db->query($sql1); |
||
| 436 | if ($result1) |
||
| 437 | { |
||
| 438 | if ($this->db->num_rows($result1) == 0) |
||
| 439 | { |
||
| 440 | return 0; |
||
| 441 | } |
||
| 442 | else |
||
| 443 | { |
||
| 444 | $obj = $this->db->fetch_object($result1); |
||
| 445 | |||
| 446 | $type = ''; |
||
| 447 | if (empty($alltypes)) $type = $obj->type; |
||
| 448 | |||
| 449 | $this->db->begin(); |
||
| 450 | |||
| 451 | $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0, tms = tms"; |
||
| 452 | $sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc; |
||
| 453 | if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'"; |
||
| 454 | dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
||
| 455 | $result2 = $this->db->query($sql2); |
||
| 456 | |||
| 457 | $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1"; |
||
| 458 | $sql3.= " WHERE rowid = ".$obj->id; |
||
| 459 | if ($type) $sql3.= " AND type = '".$this->db->escape($type)."'"; |
||
| 460 | dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
||
| 461 | $result3 = $this->db->query($sql3); |
||
| 462 | |||
| 463 | if (!$result2 || !$result3) |
||
| 464 | { |
||
| 465 | dol_print_error($this->db); |
||
| 466 | $this->db->rollback(); |
||
| 467 | return -1; |
||
| 468 | } |
||
| 469 | else |
||
| 470 | { |
||
| 471 | $this->db->commit(); |
||
| 472 | return 1; |
||
| 473 | } |
||
| 474 | } |
||
| 475 | } |
||
| 476 | else |
||
| 477 | { |
||
| 478 | dol_print_error($this->db); |
||
| 479 | return -1; |
||
| 480 | } |
||
| 481 | } |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Return label of the status |
||
| 485 | * |
||
| 486 | * @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 |
||
| 487 | * @return string Label of status |
||
| 488 | */ |
||
| 489 | public function getLibStatut($mode = 0) |
||
| 490 | { |
||
| 491 | return $this->LibStatut($this->status, $mode); |
||
| 492 | } |
||
| 493 | |||
| 494 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 495 | /** |
||
| 496 | * Return the status |
||
| 497 | * |
||
| 498 | * @param int $status Id status |
||
| 499 | * @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 |
||
| 500 | * @return string Label of status |
||
| 501 | */ |
||
| 502 | public function LibStatut($status, $mode = 0) |
||
| 503 | { |
||
| 504 | // phpcs:enable |
||
| 505 | if (empty($this->labelStatus) || empty($this->labelStatusShort)) |
||
| 506 | { |
||
| 507 | global $langs; |
||
| 508 | //$langs->load("mymodule"); |
||
| 509 | $this->labelStatus[self::STATUS_ENABLED] = $langs->trans('Enabled'); |
||
| 510 | $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled'); |
||
| 511 | $this->labelStatusShort[self::STATUS_ENABLED] = $langs->trans('Enabled'); |
||
| 512 | $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled'); |
||
| 513 | } |
||
| 514 | |||
| 515 | $statusType = 'status5'; |
||
| 516 | if ($status == self::STATUS_ENABLED) $statusType = 'status4'; |
||
| 517 | |||
| 518 | return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Load the info information in the object |
||
| 523 | * |
||
| 524 | * @param int $id Id of object |
||
| 525 | * @return void |
||
| 526 | */ |
||
| 527 | public function info($id) |
||
| 528 | { |
||
| 529 | $sql = 'SELECT rowid, date_creation as datec, tms as datem,'; |
||
| 530 | $sql.= ' fk_user_creat, fk_user_modif'; |
||
| 531 | $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
||
| 532 | $sql.= ' WHERE t.rowid = '.$id; |
||
| 533 | $result=$this->db->query($sql); |
||
| 534 | if ($result) |
||
| 535 | { |
||
| 536 | if ($this->db->num_rows($result)) |
||
| 537 | { |
||
| 538 | $obj = $this->db->fetch_object($result); |
||
| 539 | $this->id = $obj->rowid; |
||
| 540 | if ($obj->fk_user_author) |
||
| 541 | { |
||
| 542 | $cuser = new User($this->db); |
||
| 543 | $cuser->fetch($obj->fk_user_author); |
||
| 544 | $this->user_creation = $cuser; |
||
| 545 | } |
||
| 546 | |||
| 547 | if ($obj->fk_user_valid) |
||
| 548 | { |
||
| 549 | $vuser = new User($this->db); |
||
| 550 | $vuser->fetch($obj->fk_user_valid); |
||
| 551 | $this->user_validation = $vuser; |
||
| 552 | } |
||
| 553 | |||
| 554 | if ($obj->fk_user_cloture) |
||
| 555 | { |
||
| 556 | $cluser = new User($this->db); |
||
| 557 | $cluser->fetch($obj->fk_user_cloture); |
||
| 558 | $this->user_cloture = $cluser; |
||
| 559 | } |
||
| 560 | |||
| 561 | $this->date_creation = $this->db->jdate($obj->datec); |
||
| 562 | $this->date_modification = $this->db->jdate($obj->datem); |
||
| 563 | $this->date_validation = $this->db->jdate($obj->datev); |
||
| 564 | } |
||
| 565 | |||
| 566 | $this->db->free($result); |
||
| 567 | } |
||
| 568 | else |
||
| 569 | { |
||
| 570 | dol_print_error($this->db); |
||
| 571 | } |
||
| 572 | } |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Initialise object with example values |
||
| 576 | * Id must be 0 if object instance is a specimen |
||
| 577 | * |
||
| 578 | * @return void |
||
| 579 | */ |
||
| 580 | public function initAsSpecimen() |
||
| 583 | } |
||
| 584 | } |
||
| 585 |