| Conditions | 48 |
| Paths | > 20000 |
| Total Lines | 114 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 45 | function doc_getlinedesc($line, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0) |
||
| 46 | { |
||
| 47 | global $db, $conf, $langs; |
||
| 48 | |||
| 49 | $idprod = $line->fk_product; |
||
| 50 | $label = (!empty($line->label) ? $line->label : (!empty($line->libelle) ? $line->libelle : '')); |
||
| 51 | $desc = (!empty($line->desc) ? $line->desc : (!empty($line->description) ? $line->description : '')); |
||
| 52 | $ref_supplier = (!empty($line->ref_supplier) ? $line->ref_supplier : (!empty($line->ref_fourn) ? $line->ref_fourn : '')); // TODO Not yet saved for supplier invoices, only supplier orders |
||
| 53 | $note = (!empty($line->note) ? $line->note : ''); |
||
| 54 | |||
| 55 | if ($issupplierline) { |
||
| 56 | $prodser = new ProductFournisseur($db); |
||
| 57 | } else { |
||
| 58 | $prodser = new Product($db); |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($idprod) { |
||
| 62 | $prodser->fetch($idprod); |
||
| 63 | // If a predefined product and multilang and on other lang, we renamed label with label translated |
||
| 64 | if (getDolGlobalInt('MAIN_MULTILANGS') && ($outputlangs->defaultlang != $langs->defaultlang)) { |
||
| 65 | if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) { |
||
| 66 | $label = $prodser->multilangs[$outputlangs->defaultlang]["label"]; |
||
| 67 | } |
||
| 68 | if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) { |
||
| 69 | $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"]; |
||
| 70 | } |
||
| 71 | if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) { |
||
| 72 | $note = $prodser->multilangs[$outputlangs->defaultlang]["note"]; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | // Description short of product line |
||
| 78 | $libelleproduitservice = $label; |
||
| 79 | |||
| 80 | // Description long of product line |
||
| 81 | if ($desc && ($desc != $label)) { |
||
| 82 | if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except) { |
||
| 83 | $discount = new DiscountAbsolute($db); |
||
| 84 | $discount->fetch($line->fk_remise_except); |
||
| 85 | $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source; |
||
| 86 | $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $sourceref); |
||
| 87 | } elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except) { |
||
| 88 | $discount = new DiscountAbsolute($db); |
||
| 89 | $discount->fetch($line->fk_remise_except); |
||
| 90 | $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source; |
||
| 91 | $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $sourceref); |
||
| 92 | // Add date of deposit |
||
| 93 | if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) { |
||
| 94 | $libelleproduitservice .= ' (' . dol_print_date($discount->datec, 'day', '', $outputlangs) . ')'; |
||
| 95 | } |
||
| 96 | } elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except) { |
||
| 97 | $discount = new DiscountAbsolute($db); |
||
| 98 | $discount->fetch($line->fk_remise_except); |
||
| 99 | $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived", $discount->ref_facture_source); |
||
| 100 | } elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except) { |
||
| 101 | $discount = new DiscountAbsolute($db); |
||
| 102 | $discount->fetch($line->fk_remise_except); |
||
| 103 | $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid", $discount->ref_invoice_supplier_source); |
||
| 104 | } else { |
||
| 105 | if ($idprod) { |
||
| 106 | if (empty($hidedesc)) { |
||
| 107 | $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc); |
||
| 108 | } |
||
| 109 | } else { |
||
| 110 | $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | // If line linked to a product |
||
| 116 | if ($idprod) { |
||
| 117 | // On ajoute la ref |
||
| 118 | if ($prodser->ref) { |
||
| 119 | $prefix_prodserv = ""; |
||
| 120 | $ref_prodserv = ""; |
||
| 121 | if (getDolGlobalString('PRODUCT_ADD_TYPE_IN_DOCUMENTS')) { // In standard mode, we do not show this |
||
| 122 | if ($prodser->isService()) { |
||
| 123 | $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service") . " "; |
||
| 124 | } else { |
||
| 125 | $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product") . " "; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | if (empty($hideref)) { |
||
| 130 | if ($issupplierline) { |
||
| 131 | $ref_prodserv = $prodser->ref . ' (' . $outputlangs->trans("SupplierRef") . ' ' . $ref_supplier . ')'; // Show local ref and supplier ref |
||
| 132 | } else { |
||
| 133 | $ref_prodserv = $prodser->ref; // Show local ref only |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | $libelleproduitservice = $prefix_prodserv . $ref_prodserv . ($libelleproduitservice ? " - " : "") . $libelleproduitservice; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | if (!empty($line->date_start) || !empty($line->date_end)) { |
||
| 142 | $format = 'day'; |
||
| 143 | // Show duration if exists |
||
| 144 | if ($line->date_start && $line->date_end) { |
||
| 145 | $period = '(' . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($line->date_start, $format, false, $outputlangs), dol_print_date($line->date_end, $format, false, $outputlangs)) . ')'; |
||
| 146 | } |
||
| 147 | if ($line->date_start && !$line->date_end) { |
||
| 148 | $period = '(' . $outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($line->date_start, $format, false, $outputlangs)) . ')'; |
||
| 149 | } |
||
| 150 | if (!$line->date_start && $line->date_end) { |
||
| 151 | $period = '(' . $outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($line->date_end, $format, false, $outputlangs)) . ')'; |
||
| 152 | } |
||
| 153 | //print '>'.$outputlangs->charset_output.','.$period; |
||
| 154 | $libelleproduitservice = dol_concatdesc($libelleproduitservice, $period); |
||
| 155 | //print $libelleproduitservice; |
||
| 156 | } |
||
| 157 | |||
| 158 | return $libelleproduitservice; |
||
| 159 | } |
||
| 160 |