| Total Complexity | 568 |
| Total Lines | 2516 |
| Duplicated Lines | 0 % |
| Changes | 137 | ||
| Bugs | 15 | Features | 8 |
Complex classes like ActionsSubtotal 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 ActionsSubtotal, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 2 | class ActionsSubtotal |
||
| 3 | { |
||
| 4 | |||
| 5 | function __construct($db) |
||
| 13 | } |
||
| 14 | |||
| 15 | function printFieldListSelect($parameters, &$object, &$action, $hookmanager) { |
||
| 16 | |||
| 17 | global $type_element, $where; |
||
| 18 | |||
| 19 | $contexts = explode(':',$parameters['context']); |
||
| 20 | |||
| 21 | if(in_array('consumptionthirdparty',$contexts) && in_array($type_element, array('propal', 'order', 'invoice', 'supplier_order', 'supplier_invoice', 'supplier_proposal'))) { |
||
| 22 | $mod_num = TSubtotal::$module_number; |
||
| 23 | |||
| 24 | // Not a title (can't use TSubtotal class methods in sql) |
||
| 25 | $where.= ' AND (d.special_code != '.$mod_num.' OR d.product_type != 9 OR d.qty > 9)'; |
||
| 26 | // Not a subtotal (can't use TSubtotal class methods in sql) |
||
| 27 | $where.= ' AND (d.special_code != '.$mod_num.' OR d.product_type != 9 OR d.qty < 90)'; |
||
| 28 | // Not a free line text (can't use TSubtotal class methods in sql) |
||
| 29 | $where.= ' AND (d.special_code != '.$mod_num.' OR d.product_type != 9 OR d.qty != 50)'; |
||
| 30 | |||
| 31 | } |
||
| 32 | |||
| 33 | } |
||
| 34 | |||
| 35 | |||
| 36 | function createDictionaryFieldlist($parameters, &$object, &$action, $hookmanager) |
||
| 37 | { |
||
| 38 | global $conf; |
||
| 39 | |||
| 40 | if ($parameters['tabname'] == MAIN_DB_PREFIX.'c_subtotal_free_text') |
||
| 41 | { |
||
| 42 | // Merci Dolibarr de remplacer les textarea par un input text |
||
| 43 | if ((float) DOL_VERSION >= 6.0) |
||
| 44 | { |
||
| 45 | $value = ''; |
||
| 46 | $sql = 'SELECT content FROM '.MAIN_DB_PREFIX.'c_subtotal_free_text WHERE rowid = '.GETPOST('rowid'); |
||
| 47 | $resql = $this->db->query($sql); |
||
| 48 | if ($resql && ($obj = $this->db->fetch_object($resql))) $value = $obj->content; |
||
| 49 | } |
||
| 50 | |||
| 51 | ?> |
||
| 52 | <script type="text/javascript"> |
||
| 53 | $(function() { |
||
| 54 | |||
| 55 | <?php if ((float) DOL_VERSION >= 6.0) { ?> |
||
| 56 | if ($('input[name=content]').length > 0) |
||
| 57 | { |
||
| 58 | $('input[name=content]').each(function(i,item) { |
||
| 59 | var value = ''; |
||
| 60 | // Le dernier item correspond à l'édition |
||
| 61 | if (i == $('input[name=content]').length) value = <?php echo json_encode($value); ?>; |
||
| 62 | $(item).replaceWith($('<textarea name="content">'+value+'</textarea>')); |
||
| 63 | }); |
||
| 64 | |||
| 65 | <?php if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?> |
||
| 66 | $('textarea[name=content]').each(function(i, item) { |
||
| 67 | CKEDITOR.replace(item, { |
||
| 68 | toolbar: 'dolibarr_notes' |
||
| 69 | ,customConfig : ckeditorConfig |
||
| 70 | }); |
||
| 71 | }); |
||
| 72 | <?php } ?> |
||
| 73 | } |
||
| 74 | <?php } else { ?> |
||
| 75 | // <= 5.0 |
||
| 76 | // Le CKEditor est forcé sur la page dictionnaire, pas possible de mettre une valeur custom |
||
| 77 | // petit js qui supprimer le wysiwyg et affiche le textarea car avant la version 6.0 le wysiwyg sur une page de dictionnaire est inexploitable |
||
| 78 | <?php if (!empty($conf->fckeditor->enabled)) { ?> |
||
| 79 | CKEDITOR.on('instanceReady', function(ev) { |
||
| 80 | var editor = ev.editor; |
||
| 81 | |||
| 82 | if (editor.name == 'content') // Mon champ en bdd s'appel "content", pas le choix si je veux avoir un textarea sur une page de dictionnaire |
||
| 83 | { |
||
| 84 | editor.element.show(); |
||
| 85 | editor.destroy(); |
||
| 86 | } |
||
| 87 | }); |
||
| 88 | <?php } ?> |
||
| 89 | <?php } ?> |
||
| 90 | }); |
||
| 91 | </script> |
||
| 92 | <?php |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | /** Overloading the doActions function : replacing the parent's function with the one below |
||
| 97 | * @param $parameters array meta datas of the hook (context, etc...) |
||
| 98 | * @param $object CommonObject the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...) |
||
| 99 | * @param $action string current action (if set). Generally create or edit or null |
||
| 100 | * @param $hookmanager HookManager current hook manager |
||
| 101 | * @return void |
||
| 102 | */ |
||
| 103 | |||
| 104 | var $module_number = 104777; |
||
| 105 | |||
| 106 | function formObjectOptions($parameters, &$object, &$action, $hookmanager) |
||
| 107 | { |
||
| 108 | global $langs,$db,$user, $conf; |
||
| 109 | |||
| 110 | $langs->load('subtotal@subtotal'); |
||
| 111 | |||
| 112 | $contexts = explode(':',$parameters['context']); |
||
| 113 | |||
| 114 | if(in_array('ordercard',$contexts) || in_array('ordersuppliercard',$contexts) || in_array('propalcard',$contexts) || in_array('supplier_proposalcard',$contexts) || in_array('invoicecard',$contexts) || in_array('invoicesuppliercard',$contexts) || in_array('invoicereccard',$contexts)) { |
||
| 115 | |||
| 116 | $createRight = $user->rights->{$object->element}->creer; |
||
| 117 | if($object->element == 'facturerec' ) |
||
| 118 | { |
||
| 119 | $object->statut = 0; // hack for facture rec |
||
| 120 | $createRight = $user->rights->facture->creer; |
||
| 121 | } elseif($object->element == 'order_supplier' ) |
||
| 122 | { |
||
| 123 | $createRight = $user->rights->fournisseur->commande->creer; |
||
| 124 | } elseif($object->element == 'invoice_supplier' ) |
||
| 125 | { |
||
| 126 | $createRight = $user->rights->fournisseur->facture->creer; |
||
| 127 | } |
||
| 128 | |||
| 129 | if ($object->statut == 0 && $createRight) { |
||
| 130 | |||
| 131 | |||
| 132 | if($object->element=='facture')$idvar = 'facid'; |
||
| 133 | else $idvar='id'; |
||
| 134 | |||
| 135 | if(in_array($action, array('add_title_line', 'add_total_line', 'add_subtitle_line', 'add_subtotal_line', 'add_free_text')) ) |
||
| 136 | { |
||
| 137 | $level = GETPOST('level', 'int'); //New avec SUBTOTAL_USE_NEW_FORMAT |
||
| 138 | |||
| 139 | if($action=='add_title_line') { |
||
| 140 | $title = GETPOST('title'); |
||
| 141 | if(empty($title)) $title = $langs->trans('title'); |
||
| 142 | $qty = $level<1 ? 1 : $level ; |
||
| 143 | } |
||
| 144 | else if($action=='add_free_text') { |
||
| 145 | $title = GETPOST('title'); |
||
| 146 | |||
| 147 | if (empty($title)) { |
||
| 148 | $free_text = GETPOST('free_text', 'int'); |
||
| 149 | if (!empty($free_text)) { |
||
| 150 | $TFreeText = getTFreeText(); |
||
| 151 | if (!empty($TFreeText[$free_text])) { |
||
| 152 | $title = $TFreeText[$free_text]->content; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | } |
||
| 156 | if(empty($title)) $title = $langs->trans('subtotalAddLineDescription'); |
||
| 157 | $qty = 50; |
||
| 158 | } |
||
| 159 | else if($action=='add_subtitle_line') { |
||
| 160 | $title = GETPOST('title'); |
||
| 161 | if(empty($title)) $title = $langs->trans('subtitle'); |
||
| 162 | $qty = 2; |
||
| 163 | } |
||
| 164 | else if($action=='add_subtotal_line') { |
||
| 165 | $title = $langs->trans('SubSubTotal'); |
||
| 166 | $qty = 98; |
||
| 167 | } |
||
| 168 | else { |
||
| 169 | $title = GETPOST('title') ? GETPOST('title') : $langs->trans('SubTotal'); |
||
| 170 | $qty = $level ? 100-$level : 99; |
||
| 171 | } |
||
| 172 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 173 | |||
| 174 | if (!empty($conf->global->SUBTOTAL_AUTO_ADD_SUBTOTAL_ON_ADDING_NEW_TITLE) && $qty < 10) TSubtotal::addSubtotalMissing($object, $qty); |
||
| 175 | |||
| 176 | TSubtotal::addSubTotalLine($object, $title, $qty); |
||
| 177 | } |
||
| 178 | else if($action==='ask_deleteallline') { |
||
| 179 | $form=new Form($db); |
||
| 180 | |||
| 181 | $lineid = GETPOST('lineid','integer'); |
||
| 182 | $TIdForGroup = $this->getArrayOfLineForAGroup($object, $lineid); |
||
| 183 | |||
| 184 | $nbLines = count($TIdForGroup); |
||
| 185 | |||
| 186 | $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('deleteWithAllLines'), $langs->trans('ConfirmDeleteAllThisLines',$nbLines), 'confirm_delete_all_lines','',0,1); |
||
| 187 | print $formconfirm; |
||
| 188 | } |
||
| 189 | |||
| 190 | if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE)) |
||
| 191 | { |
||
| 192 | $this->showSelectTitleToAdd($object); |
||
| 193 | } |
||
| 194 | |||
| 195 | |||
| 196 | if($action!='editline') { |
||
| 197 | // New format is for 3.8 |
||
| 198 | $this->printNewFormat($object, $conf, $langs, $idvar); |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | elseif ((!empty($parameters['currentcontext']) && $parameters['currentcontext'] == 'orderstoinvoice') || in_array('orderstoinvoice',$contexts)) |
||
| 203 | { |
||
| 204 | ?> |
||
| 205 | <script type="text/javascript"> |
||
| 206 | $(function() { |
||
| 207 | var tr = $("<tr><td><?php echo $langs->trans('subtotal_add_title_bloc_from_orderstoinvoice'); ?></td><td><input type='checkbox' value='1' name='subtotal_add_title_bloc_from_orderstoinvoice' checked='checked' /></td></tr>") |
||
| 208 | $("textarea[name=note]").closest('tr').after(tr); |
||
| 209 | }); |
||
| 210 | </script> |
||
| 211 | <?php |
||
| 212 | |||
| 213 | } |
||
| 214 | |||
| 215 | return 0; |
||
| 216 | } |
||
| 217 | |||
| 218 | function printNewFormat(&$object, &$conf, &$langs, $idvar) |
||
| 219 | { |
||
| 220 | if (empty($conf->global->SUBTOTAL_ALLOW_ADD_BLOCK)) return false; |
||
| 221 | if (!empty($object->situation_cycle_ref) && $object->situation_counter > 1) return false; // Si facture de situation |
||
| 222 | ?> |
||
| 223 | <script type="text/javascript"> |
||
| 224 | $(document).ready(function() { |
||
| 225 | $('div.fiche div.tabsAction').append('<br />'); |
||
| 226 | |||
| 227 | $('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_title_line" rel="add_title_line" href="javascript:;" class="butAction"><?php echo $langs->trans('AddTitle' )?></a></div>'); |
||
| 228 | $('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_total_line" rel="add_total_line" href="javascript:;" class="butAction"><?php echo $langs->trans('AddSubTotal')?></a></div>'); |
||
| 229 | $('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_free_text" rel="add_free_text" href="javascript:;" class="butAction"><?php echo $langs->trans('AddFreeText')?></a></div>'); |
||
| 230 | |||
| 231 | |||
| 232 | function updateAllMessageForms(){ |
||
| 233 | for (instance in CKEDITOR.instances) { |
||
| 234 | CKEDITOR.instances[instance].updateElement(); |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | function promptSubTotal(action, titleDialog, label, url_to, url_ajax, params, use_textarea, show_free_text, show_under_title) { |
||
| 239 | $( "#dialog-prompt-subtotal" ).remove(); |
||
| 240 | |||
| 241 | var dialog_html = '<div id="dialog-prompt-subtotal" '+(action == 'addSubtotal' ? 'class="center"' : '')+' >'; |
||
| 242 | |||
| 243 | if (typeof show_under_title != 'undefined' && show_under_title) |
||
| 244 | { |
||
| 245 | var selectUnderTitle = <?php echo json_encode(getHtmlSelectTitle($object, true)); ?>; |
||
| 246 | dialog_html += selectUnderTitle + '<br /><br />'; |
||
| 247 | } |
||
| 248 | |||
| 249 | if (action == 'addTitle' || action == 'addFreeTxt') |
||
| 250 | { |
||
| 251 | if (typeof show_free_text != 'undefined' && show_free_text) |
||
| 252 | { |
||
| 253 | var selectFreeText = <?php echo json_encode(getHtmlSelectFreeText()); ?>; |
||
| 254 | dialog_html += selectFreeText + ' <?php echo $langs->transnoentities('subtotalFreeTextOrDesc'); ?><br />'; |
||
| 255 | } |
||
| 256 | |||
| 257 | if (typeof use_textarea != 'undefined' && use_textarea) dialog_html += '<textarea id="sub-total-title" rows="<?php echo ROWS_8; ?>" cols="80" placeholder="'+label+'"></textarea>'; |
||
| 258 | else dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />'; |
||
| 259 | } |
||
| 260 | |||
| 261 | if (action == 'addTitle' || action == 'addSubtotal') |
||
| 262 | { |
||
| 263 | if (action == 'addSubtotal') dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />'; |
||
| 264 | |||
| 265 | dialog_html += " <select name='subtotal_line_level'>"; |
||
| 266 | for (var i=1;i<10;i++) |
||
| 267 | { |
||
| 268 | dialog_html += "<option value="+i+"><?php echo $langs->trans('Level'); ?> "+i+"</option>"; |
||
| 269 | } |
||
| 270 | dialog_html += "</select>"; |
||
| 271 | } |
||
| 272 | |||
| 273 | dialog_html += '</div>'; |
||
| 274 | |||
| 275 | $('body').append(dialog_html); |
||
| 276 | |||
| 277 | <?php |
||
| 278 | $editorTool = empty($conf->global->FCKEDITOR_EDITORNAME)?'ckeditor':$conf->global->FCKEDITOR_EDITORNAME; |
||
| 279 | $editorConf = empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?false:$conf->global->FCKEDITOR_ENABLE_DETAILS; |
||
| 280 | if($editorConf && in_array($editorTool,array('textarea','ckeditor'))){ |
||
| 281 | ?> |
||
| 282 | if (action == 'addTitle' || action == 'addFreeTxt') |
||
| 283 | { |
||
| 284 | if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" ) |
||
| 285 | { |
||
| 286 | CKEDITOR.replace( 'sub-total-title', {toolbar: 'dolibarr_details', toolbarStartupExpanded: false} ); |
||
| 287 | } |
||
| 288 | } |
||
| 289 | <?php } ?> |
||
| 290 | |||
| 291 | $( "#dialog-prompt-subtotal" ).dialog({ |
||
| 292 | resizable: false, |
||
| 293 | height: 'auto', |
||
| 294 | width: 'auto', |
||
| 295 | modal: true, |
||
| 296 | title: titleDialog, |
||
| 297 | buttons: { |
||
| 298 | "Ok": function() { |
||
| 299 | if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" ){ updateAllMessageForms(); } |
||
| 300 | params.title = params.title = (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && "sub-total-title" in CKEDITOR.instances ? CKEDITOR.instances["sub-total-title"].getData() : $(this).find('#sub-total-title').val()); |
||
| 301 | params.under_title = $(this).find('select[name=under_title]').val(); |
||
| 302 | params.free_text = $(this).find('select[name=free_text]').val(); |
||
| 303 | params.level = $(this).find('select[name=subtotal_line_level]').val(); |
||
| 304 | |||
| 305 | $.ajax({ |
||
| 306 | url: url_ajax |
||
| 307 | ,type: 'POST' |
||
| 308 | ,data: params |
||
| 309 | }).done(function() { |
||
| 310 | document.location.href=url_to; |
||
| 311 | }); |
||
| 312 | |||
| 313 | $( this ).dialog( "close" ); |
||
| 314 | }, |
||
| 315 | "<?php echo $langs->trans('Cancel') ?>": function() { |
||
| 316 | $( this ).dialog( "close" ); |
||
| 317 | } |
||
| 318 | } |
||
| 319 | }); |
||
| 320 | } |
||
| 321 | |||
| 322 | $('a[rel=add_title_line]').click(function() |
||
| 323 | { |
||
| 324 | promptSubTotal('addTitle' |
||
| 325 | , "<?php echo $langs->trans('YourTitleLabel') ?>" |
||
| 326 | , "<?php echo $langs->trans('title'); ?>" |
||
| 327 | , '?<?php echo $idvar ?>=<?php echo $object->id; ?>' |
||
| 328 | , '<?php echo $_SERVER['PHP_SELF']; ?>' |
||
| 329 | , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_title_line'} |
||
| 330 | ); |
||
| 331 | }); |
||
| 332 | |||
| 333 | $('a[rel=add_total_line]').click(function() |
||
| 334 | { |
||
| 335 | promptSubTotal('addSubtotal' |
||
| 336 | , '<?php echo $langs->trans('YourSubtotalLabel') ?>' |
||
| 337 | , '<?php echo $langs->trans('subtotal'); ?>' |
||
| 338 | , '?<?php echo $idvar ?>=<?php echo $object->id; ?>' |
||
| 339 | , '<?php echo $_SERVER['PHP_SELF']; ?>' |
||
| 340 | , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_total_line'} |
||
| 341 | /*,false,false, <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?>*/ |
||
| 342 | ); |
||
| 343 | }); |
||
| 344 | |||
| 345 | $('a[rel=add_free_text]').click(function() |
||
| 346 | { |
||
| 347 | promptSubTotal('addFreeTxt' |
||
| 348 | , "<?php echo $langs->transnoentitiesnoconv('YourTextLabel') ?>" |
||
| 349 | , "<?php echo $langs->trans('subtotalAddLineDescription'); ?>" |
||
| 350 | , '?<?php echo $idvar ?>=<?php echo $object->id; ?>' |
||
| 351 | , '<?php echo $_SERVER['PHP_SELF']; ?>' |
||
| 352 | , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_free_text'} |
||
| 353 | , true |
||
| 354 | , true |
||
| 355 | , <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?> |
||
| 356 | ); |
||
| 357 | }); |
||
| 358 | }); |
||
| 359 | </script> |
||
| 360 | <?php |
||
| 361 | } |
||
| 362 | |||
| 363 | function showSelectTitleToAdd(&$object) |
||
| 364 | { |
||
| 365 | global $langs; |
||
| 366 | |||
| 367 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 368 | dol_include_once('/subtotal/lib/subtotal.lib.php'); |
||
| 369 | $TTitle = TSubtotal::getAllTitleFromDocument($object); |
||
| 370 | |||
| 371 | ?> |
||
| 372 | <script type="text/javascript"> |
||
| 373 | $(function() { |
||
| 374 | var add_button = $("#addline"); |
||
| 375 | |||
| 376 | if (add_button.length > 0) |
||
| 377 | { |
||
| 378 | add_button.closest('tr').prev('tr.liste_titre').children('td:last').addClass('center').text("<?php echo $langs->trans('subtotal_title_to_add_under_title'); ?>"); |
||
| 379 | var select_title = $(<?php echo json_encode(getHtmlSelectTitle($object)); ?>); |
||
| 380 | |||
| 381 | add_button.before(select_title); |
||
| 382 | } |
||
| 383 | }); |
||
| 384 | </script> |
||
| 385 | <?php |
||
| 386 | } |
||
| 387 | |||
| 388 | |||
| 389 | function formBuilddocOptions($parameters, &$object) { |
||
| 390 | /* Réponse besoin client */ |
||
| 391 | |||
| 392 | global $conf, $langs, $bc; |
||
| 393 | |||
| 394 | $action = GETPOST('action'); |
||
| 395 | $TContext = explode(':',$parameters['context']); |
||
| 396 | if ( |
||
| 397 | in_array('invoicecard',$TContext) |
||
| 398 | || in_array('invoicesuppliercard',$TContext) |
||
| 399 | || in_array('propalcard',$TContext) |
||
| 400 | || in_array('ordercard',$TContext) |
||
| 401 | || in_array('ordersuppliercard',$TContext) |
||
| 402 | || in_array('invoicereccard',$TContext) |
||
| 403 | ) |
||
| 404 | { |
||
| 405 | $hideInnerLines = isset( $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']][$object->id] ) ? $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']][$object->id] : 0; |
||
| 406 | $hidedetails = isset( $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']][$object->id] ) ? $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']][$object->id] : 0; |
||
| 407 | $hidepricesDefaultConf = !empty($conf->global->SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED)?$conf->global->SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED:0; |
||
| 408 | $hideprices= isset( $_SESSION['subtotal_hideprices_'.$parameters['modulepart']][$object->id] ) ? $_SESSION['subtotal_hideprices_'.$parameters['modulepart']][$object->id] : $hidepricesDefaultConf; |
||
| 409 | |||
| 410 | $var=false; |
||
| 411 | $out.= '<tr '.$bc[$var].'> |
||
| 412 | <td colspan="4" align="right"> |
||
| 413 | <label for="hideInnerLines">'.$langs->trans('HideInnerLines').'</label> |
||
| 414 | <input type="checkbox" onclick="if($(this).is(\':checked\')) { $(\'#hidedetails\').prop(\'checked\', \'checked\') }" id="hideInnerLines" name="hideInnerLines" value="1" '.(( $hideInnerLines ) ? 'checked="checked"' : '' ).' /> |
||
| 415 | </td> |
||
| 416 | </tr>'; |
||
| 417 | |||
| 418 | $var=!$var; |
||
| 419 | $out.= '<tr '.$bc[$var].'> |
||
| 420 | <td colspan="4" align="right"> |
||
| 421 | <label for="hidedetails">'.$langs->trans('SubTotalhidedetails').'</label> |
||
| 422 | <input type="checkbox" id="hidedetails" name="hidedetails" value="1" '.(( $hidedetails ) ? 'checked="checked"' : '' ).' /> |
||
| 423 | </td> |
||
| 424 | </tr>'; |
||
| 425 | |||
| 426 | $var=!$var; |
||
| 427 | $out.= '<tr '.$bc[$var].'> |
||
| 428 | <td colspan="4" align="right"> |
||
| 429 | <label for="hideprices">'.$langs->trans('SubTotalhidePrice').'</label> |
||
| 430 | <input type="checkbox" id="hideprices" name="hideprices" value="1" '.(( $hideprices ) ? 'checked="checked"' : '' ).' /> |
||
| 431 | </td> |
||
| 432 | </tr>'; |
||
| 433 | |||
| 434 | |||
| 435 | |||
| 436 | if ( |
||
| 437 | (in_array('propalcard',$TContext) && !empty($conf->global->SUBTOTAL_PROPAL_ADD_RECAP)) |
||
| 438 | || (in_array('ordercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP)) |
||
| 439 | || (in_array('ordersuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP)) |
||
| 440 | || (in_array('invoicecard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP)) |
||
| 441 | || (in_array('invoicesuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP)) |
||
| 442 | || (in_array('invoicereccard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP )) |
||
| 443 | ) |
||
| 444 | { |
||
| 445 | $var=!$var; |
||
| 446 | $out.= ' |
||
| 447 | <tr '.$bc[$var].'> |
||
| 448 | <td colspan="4" align="right"> |
||
| 449 | <label for="subtotal_add_recap">'.$langs->trans('subtotal_add_recap').'</label> |
||
| 450 | <input type="checkbox" id="subtotal_add_recap" name="subtotal_add_recap" value="1" '.( GETPOST('subtotal_add_recap') ? 'checked="checked"' : '' ).' /> |
||
| 451 | </td> |
||
| 452 | </tr>'; |
||
| 453 | } |
||
| 454 | |||
| 455 | |||
| 456 | $this->resprints = $out; |
||
| 457 | } |
||
| 458 | |||
| 459 | |||
| 460 | return 1; |
||
| 461 | } |
||
| 462 | |||
| 463 | function formEditProductOptions($parameters, &$object, &$action, $hookmanager) |
||
| 464 | { |
||
| 465 | |||
| 466 | if (in_array('invoicecard',explode(':',$parameters['context']))) |
||
| 467 | { |
||
| 468 | |||
| 469 | } |
||
| 470 | |||
| 471 | return 0; |
||
| 472 | } |
||
| 473 | |||
| 474 | function ODTSubstitutionLine(&$parameters, &$object, $action, $hookmanager) { |
||
| 475 | global $conf; |
||
| 476 | |||
| 477 | if($action === 'builddoc') { |
||
| 478 | |||
| 479 | $line = &$parameters['line']; |
||
| 480 | $object = &$parameters['object']; |
||
| 481 | $substitutionarray = &$parameters['substitutionarray']; |
||
| 482 | |||
| 483 | if($line->product_type == 9 && $line->special_code == $this->module_number) { |
||
| 484 | $substitutionarray['line_modsubtotal'] = 1; |
||
| 485 | |||
| 486 | $substitutionarray['line_price_ht'] |
||
| 487 | = $substitutionarray['line_price_vat'] |
||
| 488 | = $substitutionarray['line_price_ttc'] |
||
| 489 | = $substitutionarray['line_vatrate'] |
||
| 490 | = $substitutionarray['line_qty'] |
||
| 491 | = $substitutionarray['line_up'] |
||
| 492 | = ''; |
||
| 493 | |||
| 494 | if($line->qty>90) { |
||
| 495 | $substitutionarray['line_modsubtotal_total'] = true; |
||
| 496 | |||
| 497 | list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1); |
||
| 498 | |||
| 499 | $substitutionarray['line_price_ht'] = $total; |
||
| 500 | $substitutionarray['line_price_vat'] = $total_tva; |
||
| 501 | $substitutionarray['line_price_ttc'] = $total_ttc; |
||
| 502 | } else { |
||
| 503 | $substitutionarray['line_modsubtotal_title'] = true; |
||
| 504 | } |
||
| 505 | |||
| 506 | |||
| 507 | } |
||
| 508 | else{ |
||
| 509 | $substitutionarray['line_not_modsubtotal'] = true; |
||
| 510 | $substitutionarray['line_modsubtotal'] = 0; |
||
| 511 | } |
||
| 512 | |||
| 513 | } |
||
| 514 | |||
| 515 | } |
||
| 516 | |||
| 517 | function createFrom($parameters, &$object, $action, $hookmanager) { |
||
| 518 | |||
| 519 | if ( |
||
| 520 | in_array('invoicecard',explode(':',$parameters['context'])) |
||
| 521 | || in_array('invoicesuppliercard',explode(':',$parameters['context'])) |
||
| 522 | || in_array('propalcard',explode(':',$parameters['context'])) |
||
| 523 | || in_array('supplier_proposalcard',explode(':',$parameters['context'])) |
||
| 524 | || in_array('ordercard',explode(':',$parameters['context'])) |
||
| 525 | || in_array('ordersuppliercard',explode(':',$parameters['context'])) |
||
| 526 | || in_array('invoicereccard',explode(':',$parameters['context'])) |
||
| 527 | ) { |
||
| 528 | |||
| 529 | global $db; |
||
| 530 | |||
| 531 | $objFrom = $parameters['objFrom']; |
||
| 532 | |||
| 533 | foreach($objFrom->lines as $k=> &$lineOld) { |
||
| 534 | |||
| 535 | if($lineOld->product_type == 9 && $lineOld->info_bits > 0 ) { |
||
| 536 | |||
| 537 | $line = & $object->lines[$k]; |
||
| 538 | |||
| 539 | $idLine = (int) ($line->id ? $line->id : $line->rowid); |
||
| 540 | |||
| 541 | $db->query("UPDATE ".MAIN_DB_PREFIX.$line->table_element." |
||
| 542 | SET info_bits=".(int)$lineOld->info_bits." |
||
| 543 | WHERE rowid = ".$idLine." |
||
| 544 | "); |
||
| 545 | |||
| 546 | } |
||
| 547 | |||
| 548 | |||
| 549 | } |
||
| 550 | |||
| 551 | |||
| 552 | } |
||
| 553 | |||
| 554 | } |
||
| 555 | |||
| 556 | function doActions($parameters, &$object, $action, $hookmanager) |
||
| 557 | { |
||
| 558 | global $db, $conf, $langs,$user; |
||
| 559 | |||
| 560 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 561 | dol_include_once('/subtotal/lib/subtotal.lib.php'); |
||
| 562 | require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
||
| 563 | |||
| 564 | $showBlockExtrafields = GETPOST('showBlockExtrafields'); |
||
| 565 | |||
| 566 | if($object->element=='facture') $idvar = 'facid'; |
||
| 567 | else $idvar = 'id'; |
||
| 568 | |||
| 569 | if ($action == 'updateligne' || $action == 'updateline') |
||
| 570 | { |
||
| 571 | $found = false; |
||
| 572 | $lineid = GETPOST('lineid', 'int'); |
||
| 573 | foreach ($object->lines as &$line) |
||
| 574 | { |
||
| 575 | |||
| 576 | if ($line->id == $lineid && TSubtotal::isModSubtotalLine($line)) |
||
| 577 | { |
||
| 578 | $found = true; |
||
| 579 | if(TSubtotal::isTitle($line) && !empty($showBlockExtrafields)) { |
||
| 580 | $extrafieldsline = new ExtraFields($db); |
||
| 581 | $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); |
||
| 582 | $extrafieldsline->setOptionalsFromPost($extralabelsline, $line); |
||
| 583 | } |
||
| 584 | _updateSubtotalLine($object, $line); |
||
| 585 | _updateSubtotalBloc($object, $line); |
||
| 586 | |||
| 587 | TSubtotal::generateDoc($object); |
||
| 588 | break; |
||
| 589 | } |
||
| 590 | } |
||
| 591 | |||
| 592 | if ($found) |
||
| 593 | { |
||
| 594 | header('Location: '.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id); |
||
| 595 | exit; // Surtout ne pas laisser Dolibarr faire du traitement sur le updateligne sinon ça plante les données de la ligne |
||
| 596 | } |
||
| 597 | } |
||
| 598 | else if($action === 'builddoc') { |
||
| 599 | |||
| 600 | if ( |
||
| 601 | in_array('invoicecard',explode(':',$parameters['context'])) |
||
| 602 | || in_array('propalcard',explode(':',$parameters['context'])) |
||
| 603 | || in_array('ordercard',explode(':',$parameters['context'])) |
||
| 604 | || in_array('ordersuppliercard',explode(':',$parameters['context'])) |
||
| 605 | || in_array('invoicesuppliercard',explode(':',$parameters['context'])) |
||
| 606 | || in_array('supplier_proposalcard',explode(':',$parameters['context'])) |
||
| 607 | ) |
||
| 608 | { |
||
| 609 | if(in_array('invoicecard',explode(':',$parameters['context']))) { |
||
| 610 | $sessname = 'subtotal_hideInnerLines_facture'; |
||
| 611 | $sessname2 = 'subtotal_hidedetails_facture'; |
||
| 612 | $sessname3 = 'subtotal_hideprices_facture'; |
||
| 613 | } |
||
| 614 | elseif(in_array('invoicesuppliercard',explode(':',$parameters['context']))) { |
||
| 615 | $sessname = 'subtotal_hideInnerLines_facture_fournisseur'; |
||
| 616 | $sessname2 = 'subtotal_hidedetails_facture_fournisseur'; |
||
| 617 | $sessname3 = 'subtotal_hideprices_facture_fournisseur'; |
||
| 618 | } |
||
| 619 | elseif(in_array('propalcard',explode(':',$parameters['context']))) { |
||
| 620 | $sessname = 'subtotal_hideInnerLines_propal'; |
||
| 621 | $sessname2 = 'subtotal_hidedetails_propal'; |
||
| 622 | $sessname3 = 'subtotal_hideprices_propal'; |
||
| 623 | } |
||
| 624 | elseif(in_array('supplier_proposalcard',explode(':',$parameters['context']))) { |
||
| 625 | $sessname = 'subtotal_hideInnerLines_supplier_proposal'; |
||
| 626 | $sessname2 = 'subtotal_hidedetails_supplier_proposal'; |
||
| 627 | $sessname3 = 'subtotal_hideprices_supplier_proposal'; |
||
| 628 | } |
||
| 629 | elseif(in_array('ordercard',explode(':',$parameters['context']))) { |
||
| 630 | $sessname = 'subtotal_hideInnerLines_commande'; |
||
| 631 | $sessname2 = 'subtotal_hidedetails_commande'; |
||
| 632 | $sessname3 = 'subtotal_hideprices_commande'; |
||
| 633 | } |
||
| 634 | elseif(in_array('ordersuppliercard',explode(':',$parameters['context']))) { |
||
| 635 | $sessname = 'subtotal_hideInnerLines_commande_fournisseur'; |
||
| 636 | $sessname2 = 'subtotal_hidedetails_commande_fournisseur'; |
||
| 637 | $sessname3 = 'subtotal_hideprices_commande_fournisseur'; |
||
| 638 | } |
||
| 639 | else { |
||
| 640 | $sessname = 'subtotal_hideInnerLines_unknown'; |
||
| 641 | $sessname2 = 'subtotal_hidedetails_unknown'; |
||
| 642 | $sessname3 = 'subtotal_hideprices_unknown'; |
||
| 643 | } |
||
| 644 | |||
| 645 | global $hideprices; |
||
| 646 | |||
| 647 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 648 | if(!empty($_SESSION[$sessname]) && !is_array($_SESSION[$sessname][$object->id]) ) $_SESSION[$sessname] = array(); // prevent old system |
||
| 649 | $_SESSION[$sessname][$object->id] = $hideInnerLines; |
||
| 650 | |||
| 651 | $hidedetails= (int)GETPOST('hidedetails'); |
||
| 652 | if(!empty($_SESSION[$sessname2]) && !is_array($_SESSION[$sessname2][$object->id]) ) $_SESSION[$sessname2] = array(); // prevent old system |
||
| 653 | $_SESSION[$sessname2][$object->id] = $hidedetails; |
||
| 654 | |||
| 655 | $hideprices= (int)GETPOST('hideprices'); |
||
| 656 | if(!empty($_SESSION[$sessname3]) && !is_array($_SESSION[$sessname3][$object->id]) ) $_SESSION[$sessname3] = array(); // prevent old system |
||
| 657 | $_SESSION[$sessname3][$object->id] = $hideprices; |
||
| 658 | |||
| 659 | foreach($object->lines as &$line) { |
||
| 660 | if ($line->product_type == 9 && $line->special_code == $this->module_number) { |
||
| 661 | |||
| 662 | if($line->qty>=90) { |
||
| 663 | $line->modsubtotal_total = 1; |
||
| 664 | } |
||
| 665 | else{ |
||
| 666 | $line->modsubtotal_title = 1; |
||
| 667 | } |
||
| 668 | |||
| 669 | $line->total_ht = $this->getTotalLineFromObject($object, $line, ''); |
||
| 670 | } |
||
| 671 | } |
||
| 672 | } |
||
| 673 | |||
| 674 | } |
||
| 675 | else if($action === 'confirm_delete_all_lines' && GETPOST('confirm')=='yes') { |
||
| 676 | |||
| 677 | $Tab = $this->getArrayOfLineForAGroup($object, GETPOST('lineid')); |
||
| 678 | |||
| 679 | foreach($Tab as $idLine) { |
||
| 680 | /** |
||
| 681 | * @var $object Facture |
||
| 682 | */ |
||
| 683 | if($object->element=='facture') $object->deleteline($idLine); |
||
| 684 | /** |
||
| 685 | * @var $object Facture fournisseur |
||
| 686 | */ |
||
| 687 | else if($object->element=='invoice_supplier') |
||
| 688 | { |
||
| 689 | $object->deleteline($idLine); |
||
| 690 | } |
||
| 691 | /** |
||
| 692 | * @var $object Propal |
||
| 693 | */ |
||
| 694 | else if($object->element=='propal') $object->deleteline($idLine); |
||
| 695 | /** |
||
| 696 | * @var $object Propal Fournisseur |
||
| 697 | */ |
||
| 698 | else if($object->element=='supplier_proposal') $object->deleteline($idLine); |
||
| 699 | /** |
||
| 700 | * @var $object Commande |
||
| 701 | */ |
||
| 702 | else if($object->element=='commande') |
||
| 703 | { |
||
| 704 | if ((float) DOL_VERSION >= 5.0) $object->deleteline($user, $idLine); |
||
| 705 | else $object->deleteline($idLine); |
||
| 706 | } |
||
| 707 | /** |
||
| 708 | * @var $object Commande fournisseur |
||
| 709 | */ |
||
| 710 | else if($object->element=='order_supplier') |
||
| 711 | { |
||
| 712 | $object->deleteline($idLine); |
||
| 713 | } |
||
| 714 | /** |
||
| 715 | * @var $object Facturerec |
||
| 716 | */ |
||
| 717 | else if($object->element=='facturerec') $object->deleteline($idLine); |
||
| 718 | } |
||
| 719 | |||
| 720 | header('location:?id='.$object->id); |
||
| 721 | exit; |
||
| 722 | |||
| 723 | } |
||
| 724 | else if ($action == 'duplicate') |
||
| 725 | { |
||
| 726 | $lineid = GETPOST('lineid', 'int'); |
||
| 727 | $nbDuplicate = TSubtotal::duplicateLines($object, $lineid, true); |
||
| 728 | |||
| 729 | if ($nbDuplicate > 0) setEventMessage($langs->trans('subtotal_duplicate_success', $nbDuplicate)); |
||
| 730 | elseif ($nbDuplicate == 0) setEventMessage($langs->trans('subtotal_duplicate_lineid_not_found'), 'warnings'); |
||
| 731 | else setEventMessage($langs->trans('subtotal_duplicate_error'), 'errors'); |
||
| 732 | |||
| 733 | header('Location: ?id='.$object->id); |
||
| 734 | exit; |
||
| 735 | } |
||
| 736 | |||
| 737 | return 0; |
||
| 738 | } |
||
| 739 | |||
| 740 | function formAddObjectLine ($parameters, &$object, &$action, $hookmanager) { |
||
| 741 | return 0; |
||
| 742 | } |
||
| 743 | |||
| 744 | function changeRoundingMode($parameters, &$object, &$action, $hookmanager) |
||
| 745 | { |
||
| 746 | global $conf; |
||
| 747 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && !empty($object->table_element_line) && in_array($object->element, array('commande', 'facture', 'propal'))) |
||
| 748 | { |
||
| 749 | if ($object->element == 'commande') |
||
| 750 | $obj = new OrderLine($object->db); |
||
| 751 | if ($object->element == 'propal') |
||
| 752 | $obj = new PropaleLigne($object->db); |
||
| 753 | if ($object->element == 'facture') |
||
| 754 | $obj = new FactureLigne($object->db); |
||
| 755 | if (!empty($parameters['fk_element'])) |
||
| 756 | { |
||
| 757 | |||
| 758 | if($obj->fetch($parameters['fk_element'])){ |
||
| 759 | $obj->id= $obj->rowid; |
||
| 760 | if (empty($obj->array_options)) |
||
| 761 | $obj->fetch_optionals(); |
||
| 762 | if (!empty($obj->array_options['options_subtotal_nc'])) |
||
| 763 | return 1; |
||
| 764 | } |
||
| 765 | } |
||
| 766 | } |
||
| 767 | |||
| 768 | return 0; |
||
| 769 | } |
||
| 770 | |||
| 771 | function getArrayOfLineForAGroup(&$object, $lineid) { |
||
| 772 | $rang = $line->rang; |
||
| 773 | $qty_line = $line->qty; |
||
| 774 | |||
| 775 | $qty_line = 0; |
||
| 776 | |||
| 777 | $found = false; |
||
| 778 | |||
| 779 | $Tab= array(); |
||
| 780 | |||
| 781 | foreach($object->lines as $l) { |
||
| 782 | |||
| 783 | $lid = (!empty($l->rowid) ? $l->rowid : $l->id); |
||
| 784 | if($lid == $lineid) { |
||
| 785 | |||
| 786 | $found = true; |
||
| 787 | $qty_line = $l->qty; |
||
| 788 | } |
||
| 789 | |||
| 790 | if($found) { |
||
| 791 | |||
| 792 | $Tab[] = (!empty($l->rowid) ? $l->rowid : $l->id); |
||
| 793 | |||
| 794 | if($l->special_code==$this->module_number && (($l->qty==99 && $qty_line==1) || ($l->qty==98 && $qty_line==2)) ) { |
||
| 795 | break; // end of story |
||
| 796 | } |
||
| 797 | } |
||
| 798 | |||
| 799 | |||
| 800 | } |
||
| 801 | |||
| 802 | |||
| 803 | return $Tab; |
||
| 804 | |||
| 805 | } |
||
| 806 | |||
| 807 | /** |
||
| 808 | * TODO le calcul est faux dans certains cas, exemple : |
||
| 809 | * T1 |
||
| 810 | * |_ l1 => 50 € |
||
| 811 | * |_ l2 => 40 € |
||
| 812 | * |_ T2 |
||
| 813 | * |_l3 => 100 € |
||
| 814 | * |_ ST2 |
||
| 815 | * |_ l4 => 23 € |
||
| 816 | * |_ ST1 |
||
| 817 | * |
||
| 818 | * On obtiens ST2 = 100 ET ST1 = 123 € |
||
| 819 | * Alors qu'on devrais avoir ST2 = 100 ET ST1 = 213 € |
||
| 820 | * |
||
| 821 | * @param $use_level isn't used anymore |
||
| 822 | */ |
||
| 823 | function getTotalLineFromObject(&$object, &$line, $use_level=false, $return_all=0) { |
||
| 858 | } |
||
| 859 | |||
| 860 | /* |
||
| 861 | * Get the sum of situation invoice for last column |
||
| 862 | */ |
||
| 863 | function getTotalToPrintSituation(&$object, &$line) { |
||
| 864 | |||
| 865 | $rang = $line->rang; |
||
| 866 | $total = 0; |
||
| 867 | foreach($object->lines as $l) { |
||
| 868 | if($l->rang>=$rang) { |
||
| 869 | return price($total); |
||
| 870 | } |
||
| 871 | if (TSubtotal::isSubtotal($l)){ |
||
| 872 | $total = 0; |
||
| 873 | } else if ($l->situation_percent > 0 ){ |
||
| 874 | |||
| 875 | |||
| 876 | $prev_progress = $l->get_prev_progress($object->id); |
||
| 877 | $progress = ($l->situation_percent - $prev_progress) /100; |
||
| 878 | $total += ($l->total_ht/($l->situation_percent/100)) * $progress; |
||
| 879 | |||
| 880 | } |
||
| 881 | } |
||
| 882 | |||
| 883 | return price($total); |
||
| 884 | } |
||
| 885 | |||
| 886 | /** |
||
| 887 | * @param $pdf TCPDF PDF object |
||
| 888 | * @param $object CommonObject dolibarr object |
||
| 889 | * @param $line CommonObjectLine dolibarr object line |
||
| 890 | * @param $label string |
||
| 891 | * @param $description string |
||
| 892 | * @param $posx float horizontal position |
||
| 893 | * @param $posy float vertical position |
||
| 894 | * @param $w float width |
||
| 895 | * @param $h float height |
||
| 896 | */ |
||
| 897 | function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) { |
||
| 898 | global $conf,$subtotal_last_title_posy; |
||
| 899 | |||
| 900 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 901 | if (!empty($conf->global->SUBTOTAL_ONE_LINE_IF_HIDE_INNERLINES) && $hideInnerLines && !empty($subtotal_last_title_posy)) |
||
| 902 | { |
||
| 903 | $posy = $subtotal_last_title_posy; |
||
| 904 | $subtotal_last_title_posy = null; |
||
| 905 | } |
||
| 906 | |||
| 907 | $hidePriceOnSubtotalLines = (int) GETPOST('hide_price_on_subtotal_lines'); |
||
| 908 | |||
| 909 | $set_pagebreak_margin = false; |
||
| 910 | if(method_exists('Closure','bind')) { |
||
| 911 | $pageBreakOriginalValue = $pdf->AcceptPageBreak(); |
||
| 912 | $sweetsThief = function ($pdf) { |
||
| 913 | return $pdf->bMargin ; |
||
| 914 | }; |
||
| 915 | $sweetsThief = Closure::bind($sweetsThief, null, $pdf); |
||
| 916 | |||
| 917 | $bMargin = $sweetsThief($pdf); |
||
| 918 | |||
| 919 | $pdf->SetAutoPageBreak( false ); |
||
| 920 | |||
| 921 | $set_pagebreak_margin = true; |
||
| 922 | } |
||
| 923 | |||
| 924 | |||
| 925 | if($line->qty==99) |
||
| 926 | $pdf->SetFillColor(220,220,220); |
||
| 927 | elseif ($line->qty==98) |
||
| 928 | $pdf->SetFillColor(230,230,230); |
||
| 929 | else |
||
| 930 | $pdf->SetFillColor(240,240,240); |
||
| 931 | |||
| 932 | $style = 'B'; |
||
| 933 | if (!empty($conf->global->SUBTOTAL_SUBTOTAL_STYLE)) $style = $conf->global->SUBTOTAL_SUBTOTAL_STYLE; |
||
| 934 | |||
| 935 | $pdf->SetFont('', $style, 9); |
||
| 936 | |||
| 937 | $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'R',true); |
||
| 938 | // var_dump($bMargin); |
||
| 939 | $pageAfter = $pdf->getPage(); |
||
| 940 | |||
| 941 | //Print background |
||
| 942 | $cell_height = $pdf->getStringHeight($w, $label); |
||
| 943 | $pdf->SetXY($posx, $posy); |
||
| 944 | $pdf->MultiCell($pdf->page_largeur - $pdf->marge_droite, $cell_height, '', 0, '', 1); |
||
| 945 | |||
| 946 | if (!$hidePriceOnSubtotalLines) { |
||
| 947 | $total_to_print = price($line->total); |
||
| 948 | |||
| 949 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS)) |
||
| 950 | { |
||
| 951 | $TTitle = TSubtotal::getAllTitleFromLine($line); |
||
| 952 | foreach ($TTitle as &$line_title) |
||
| 953 | { |
||
| 954 | if (!empty($line_title->array_options['options_subtotal_nc'])) |
||
| 955 | { |
||
| 956 | $total_to_print = ''; // TODO Gestion "Compris/Non compris", voir si on affiche une annotation du genre "NC" |
||
| 957 | break; |
||
| 958 | } |
||
| 959 | } |
||
| 960 | } |
||
| 961 | |||
| 962 | if($total_to_print !== '') { |
||
| 963 | |||
| 964 | if (GETPOST('hideInnerLines')) |
||
| 965 | { |
||
| 966 | // Dans le cas des lignes cachés, le calcul est déjà fait dans la méthode beforePDFCreation et les lignes de sous-totaux sont déjà renseignés |
||
| 967 | // $line->TTotal_tva |
||
| 968 | // $line->total_ht |
||
| 969 | // $line->total_tva |
||
| 970 | // $line->total |
||
| 971 | // $line->total_ttc |
||
| 972 | } |
||
| 973 | else |
||
| 974 | { |
||
| 975 | list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1); |
||
| 976 | if(get_class($object) == 'Facture' && $object->type==Facture::TYPE_SITUATION){//Facture de situation |
||
| 977 | $total_to_print = $this->getTotalToPrintSituation($object, $line); |
||
| 978 | } else { |
||
| 979 | $total_to_print = price($total); |
||
| 980 | } |
||
| 981 | |||
| 982 | $line->total_ht = $total; |
||
| 983 | $line->total = $total; |
||
| 984 | $line->total_tva = $total_tva; |
||
| 985 | $line->total_ttc = $total_ttc; |
||
| 986 | } |
||
| 987 | } |
||
| 988 | |||
| 989 | $pdf->SetXY($pdf->postotalht, $posy); |
||
| 990 | if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin); |
||
| 991 | $pdf->MultiCell($pdf->page_largeur-$pdf->marge_droite-$pdf->postotalht, 3, $total_to_print, 0, 'R', 0); |
||
| 992 | } |
||
| 993 | else{ |
||
| 994 | if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin); |
||
| 995 | } |
||
| 996 | |||
| 997 | $posy = $posy + $cell_height; |
||
| 998 | $pdf->SetXY($posx, $posy); |
||
| 999 | |||
| 1000 | |||
| 1001 | } |
||
| 1002 | |||
| 1003 | /** |
||
| 1004 | * @param $pdf TCPDF PDF object |
||
| 1005 | * @param $object CommonObject dolibarr object |
||
| 1006 | * @param $line CommonObjectLine dolibarr object line |
||
| 1007 | * @param $label string |
||
| 1008 | * @param $description string |
||
| 1009 | * @param $posx float horizontal position |
||
| 1010 | * @param $posy float vertical position |
||
| 1011 | * @param $w float width |
||
| 1012 | * @param $h float height |
||
| 1013 | */ |
||
| 1014 | function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) { |
||
| 1015 | |||
| 1016 | global $db,$conf,$subtotal_last_title_posy; |
||
| 1017 | |||
| 1018 | $subtotal_last_title_posy = $posy; |
||
| 1019 | $pdf->SetXY ($posx, $posy); |
||
| 1020 | |||
| 1021 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 1022 | |||
| 1023 | |||
| 1024 | |||
| 1025 | $style = ($line->qty==1) ? 'BU' : 'BUI'; |
||
| 1026 | if (!empty($conf->global->SUBTOTAL_TITLE_STYLE)) $style = $conf->global->SUBTOTAL_TITLE_STYLE; |
||
| 1027 | |||
| 1028 | if($hideInnerLines) { |
||
| 1029 | if($line->qty==1)$pdf->SetFont('', $style, 9); |
||
| 1030 | else |
||
| 1031 | { |
||
| 1032 | if (!empty($conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES)) $style = $conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES; |
||
| 1033 | $pdf->SetFont('', $style, 9); |
||
| 1034 | } |
||
| 1035 | } |
||
| 1036 | else { |
||
| 1037 | |||
| 1038 | if($line->qty==1)$pdf->SetFont('', $style, 9); //TODO if super utile |
||
| 1039 | else $pdf->SetFont('', $style, 9); |
||
| 1040 | |||
| 1041 | } |
||
| 1042 | |||
| 1043 | if ($label === strip_tags($label) && $label === dol_html_entity_decode($label, ENT_QUOTES)) $pdf->MultiCell($w, $h, $label, 0, 'L'); // Pas de HTML dans la chaine |
||
| 1044 | else $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'J',true); // et maintenant avec du HTML |
||
| 1045 | |||
| 1046 | if($description && !$hidedesc) { |
||
| 1047 | $posy = $pdf->GetY(); |
||
| 1048 | |||
| 1049 | $pdf->SetFont('', '', 8); |
||
| 1050 | |||
| 1051 | $pdf->writeHTMLCell($w, $h, $posx, $posy, $description, 0, 1, false, true, 'J',true); |
||
| 1052 | |||
| 1053 | } |
||
| 1054 | |||
| 1055 | } |
||
| 1056 | |||
| 1057 | function pdf_writelinedesc_ref($parameters=array(), &$object, &$action='') { |
||
| 1058 | // ultimate PDF hook O_o |
||
| 1059 | |||
| 1060 | return $this->pdf_writelinedesc($parameters,$object,$action); |
||
| 1061 | |||
| 1062 | } |
||
| 1063 | |||
| 1064 | function isModSubtotalLine(&$parameters, &$object) { |
||
| 1065 | |||
| 1066 | if(is_array($parameters)) { |
||
| 1067 | $i = & $parameters['i']; |
||
| 1068 | } |
||
| 1069 | else { |
||
| 1070 | $i = (int)$parameters; |
||
| 1071 | } |
||
| 1072 | |||
| 1073 | |||
| 1074 | if($object->lines[$i]->special_code == $this->module_number && $object->lines[$i]->product_type == 9) { |
||
| 1075 | return true; |
||
| 1076 | } |
||
| 1077 | |||
| 1078 | return false; |
||
| 1079 | |||
| 1080 | } |
||
| 1081 | |||
| 1082 | function pdf_getlineqty($parameters=array(), &$object, &$action='') { |
||
| 1083 | global $conf,$hideprices; |
||
| 1084 | |||
| 1085 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1086 | |||
| 1087 | $this->resprints = ' '; |
||
| 1088 | |||
| 1089 | if((float)DOL_VERSION<=3.6) { |
||
| 1090 | return ''; |
||
| 1091 | } |
||
| 1092 | else if((float)DOL_VERSION>=3.8) { |
||
| 1093 | return 1; |
||
| 1094 | } |
||
| 1095 | |||
| 1096 | } |
||
| 1097 | elseif(!empty($hideprices)) { |
||
| 1098 | $this->resprints = $object->lines[$parameters['i']]->qty; |
||
| 1099 | return 1; |
||
| 1100 | } |
||
| 1101 | elseif (!empty($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY)) |
||
| 1102 | { |
||
| 1103 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 1104 | $hidedetails = (int)GETPOST('hidedetails'); |
||
| 1105 | if (empty($hideInnerLines) && !empty($hidedetails)) |
||
| 1106 | { |
||
| 1107 | $this->resprints = $object->lines[$parameters['i']]->qty; |
||
| 1108 | } |
||
| 1109 | } |
||
| 1110 | |||
| 1111 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1112 | else $i = (int)$parameters; |
||
| 1113 | |||
| 1114 | if (empty($object->lines[$i])) return 0; // hideInnerLines => override $object->lines et Dolibarr ne nous permet pas de mettre à jour la variable qui conditionne la boucle sur les lignes (PR faite pour 6.0) |
||
| 1115 | |||
| 1116 | if(empty($object->lines[$i]->array_options)) $object->lines[$i]->fetch_optionals(); |
||
| 1117 | |||
| 1118 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1119 | { |
||
| 1120 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1121 | { |
||
| 1122 | $this->resprints = ' '; |
||
| 1123 | return 1; |
||
| 1124 | } |
||
| 1125 | } |
||
| 1126 | |||
| 1127 | return 0; |
||
| 1128 | } |
||
| 1129 | |||
| 1130 | function pdf_getlinetotalexcltax($parameters=array(), &$object, &$action='') { |
||
| 1131 | global $conf, $hideprices, $hookmanager; |
||
| 1132 | |||
| 1133 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1134 | else $i = (int)$parameters; |
||
| 1135 | |||
| 1136 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1137 | |||
| 1138 | $this->resprints = ' '; |
||
| 1139 | |||
| 1140 | if((float)DOL_VERSION<=3.6) { |
||
| 1141 | return ''; |
||
| 1142 | } |
||
| 1143 | else if((float)DOL_VERSION>=3.8) { |
||
| 1144 | return 1; |
||
| 1145 | } |
||
| 1146 | |||
| 1147 | } |
||
| 1148 | elseif (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS)) |
||
| 1149 | { |
||
| 1150 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1151 | { |
||
| 1152 | if (!empty($object->lines[$i]->array_options['options_subtotal_nc'])) |
||
| 1153 | { |
||
| 1154 | $this->resprints = ' '; |
||
| 1155 | return 1; |
||
| 1156 | } |
||
| 1157 | |||
| 1158 | $TTitle = TSubtotal::getAllTitleFromLine($object->lines[$i]); |
||
| 1159 | foreach ($TTitle as &$line_title) |
||
| 1160 | { |
||
| 1161 | if (!empty($line_title->array_options['options_subtotal_nc'])) |
||
| 1162 | { |
||
| 1163 | $this->resprints = ' '; |
||
| 1164 | return 1; |
||
| 1165 | } |
||
| 1166 | } |
||
| 1167 | } |
||
| 1168 | } |
||
| 1169 | if ((int)GETPOST('hideInnerLines') && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)){ |
||
| 1170 | $this->resprints = price($object->lines[$i]->total_ht); |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | // Si la gestion C/NC est active et que je suis sur un ligne dont l'extrafield est coché |
||
| 1174 | if ( |
||
| 1175 | !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && |
||
| 1176 | (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) |
||
| 1177 | ) |
||
| 1178 | { |
||
| 1179 | // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue |
||
| 1180 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1181 | { |
||
| 1182 | $this->resprints = ' '; |
||
| 1183 | |||
| 1184 | // currentcontext à modifier celon l'appel |
||
| 1185 | $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinetotalexcltax', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i); |
||
| 1186 | return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) |
||
| 1187 | } |
||
| 1188 | } |
||
| 1189 | // Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble |
||
| 1190 | else if (!empty($hideprices)) |
||
| 1191 | { |
||
| 1192 | // Check if a title exist for this line && if the title have subtotal |
||
| 1193 | $lineTitle = TSubtotal::getParentTitleOfLine($object, $i); |
||
| 1194 | if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) |
||
| 1195 | { |
||
| 1196 | |||
| 1197 | $this->resprints = ' '; |
||
| 1198 | |||
| 1199 | // currentcontext à modifier celon l'appel |
||
| 1200 | $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinetotalexcltax', 'currentcontext'=>'subtotal_hideprices', 'i' => $i); |
||
| 1201 | return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) |
||
| 1202 | } |
||
| 1203 | } |
||
| 1204 | |||
| 1205 | return 0; |
||
| 1206 | } |
||
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Remplace le retour de la méthode qui l'appelle par un standard 1 ou autre chose celon le hook |
||
| 1210 | * @return int 1, 0, -1 |
||
| 1211 | */ |
||
| 1212 | private function callHook(&$object, &$hookmanager, $action, $params, $defaultReturn = 1) |
||
| 1213 | { |
||
| 1214 | $reshook=$hookmanager->executeHooks('subtotalHidePrices',$params, $object, $action); |
||
| 1215 | if ($reshook < 0) |
||
| 1216 | { |
||
| 1217 | $this->error = $hookmanager->error; |
||
| 1218 | $this->errors = $hookmanager->errors; |
||
| 1219 | return -1; |
||
| 1220 | } |
||
| 1221 | elseif (empty($reshook)) |
||
| 1222 | { |
||
| 1223 | $this->resprints .= $hookmanager->resprints; |
||
| 1224 | } |
||
| 1225 | else |
||
| 1226 | { |
||
| 1227 | $this->resprints = $hookmanager->resprints; |
||
| 1228 | |||
| 1229 | // override return (use $this->results['overrideReturn'] or $this->resArray['overrideReturn'] in other module action_xxxx.class.php ) |
||
| 1230 | if(isset($hookmanager->resArray['overrideReturn'])) |
||
| 1231 | { |
||
| 1232 | return $hookmanager->resArray['overrideReturn']; |
||
| 1233 | } |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | return $defaultReturn; |
||
| 1237 | } |
||
| 1238 | |||
| 1239 | function pdf_getlinetotalwithtax($parameters=array(), &$object, &$action='') { |
||
| 1240 | global $conf; |
||
| 1241 | |||
| 1242 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1243 | |||
| 1244 | $this->resprints = ' '; |
||
| 1245 | |||
| 1246 | if((float)DOL_VERSION<=3.6) { |
||
| 1247 | return ''; |
||
| 1248 | } |
||
| 1249 | else if((float)DOL_VERSION>=3.8) { |
||
| 1250 | return 1; |
||
| 1251 | } |
||
| 1252 | } |
||
| 1253 | |||
| 1254 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1255 | else $i = (int)$parameters; |
||
| 1256 | |||
| 1257 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1258 | { |
||
| 1259 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1260 | { |
||
| 1261 | $this->resprints = ' '; |
||
| 1262 | return 1; |
||
| 1263 | } |
||
| 1264 | } |
||
| 1265 | |||
| 1266 | return 0; |
||
| 1267 | } |
||
| 1268 | |||
| 1269 | function pdf_getlineunit($parameters=array(), &$object, &$action='') { |
||
| 1270 | global $conf; |
||
| 1271 | |||
| 1272 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1273 | $this->resprints = ' '; |
||
| 1274 | |||
| 1275 | if((float)DOL_VERSION<=3.6) { |
||
| 1276 | return ''; |
||
| 1277 | } |
||
| 1278 | else if((float)DOL_VERSION>=3.8) { |
||
| 1279 | return 1; |
||
| 1280 | } |
||
| 1281 | } |
||
| 1282 | |||
| 1283 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1284 | else $i = (int)$parameters; |
||
| 1285 | |||
| 1286 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1287 | { |
||
| 1288 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1289 | { |
||
| 1290 | $this->resprints = ' '; |
||
| 1291 | return 1; |
||
| 1292 | } |
||
| 1293 | } |
||
| 1294 | |||
| 1295 | return 0; |
||
| 1296 | } |
||
| 1297 | |||
| 1298 | function pdf_getlineupexcltax($parameters=array(), &$object, &$action='') { |
||
| 1299 | global $conf,$hideprices,$hookmanager; |
||
| 1300 | |||
| 1301 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1302 | $this->resprints = ' '; |
||
| 1303 | |||
| 1304 | if((float)DOL_VERSION<=3.6) { |
||
| 1305 | return ''; |
||
| 1306 | } |
||
| 1307 | else if((float)DOL_VERSION>=3.8) { |
||
| 1308 | return 1; |
||
| 1309 | } |
||
| 1310 | } |
||
| 1311 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1312 | else $i = (int)$parameters; |
||
| 1313 | |||
| 1314 | |||
| 1315 | // Si la gestion C/NC est active et que je suis sur un ligne dont l'extrafield est coché |
||
| 1316 | if ( |
||
| 1317 | !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && |
||
| 1318 | (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) |
||
| 1319 | ) |
||
| 1320 | { |
||
| 1321 | // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue |
||
| 1322 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1323 | { |
||
| 1324 | $this->resprints = ' '; |
||
| 1325 | |||
| 1326 | // currentcontext à modifier celon l'appel |
||
| 1327 | $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i); |
||
| 1328 | return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) |
||
| 1329 | |||
| 1330 | } |
||
| 1331 | } |
||
| 1332 | // Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble |
||
| 1333 | else if (!empty($hideprices)) |
||
| 1334 | { |
||
| 1335 | |||
| 1336 | // Check if a title exist for this line && if the title have subtotal |
||
| 1337 | $lineTitle = TSubtotal::getParentTitleOfLine($object, $i); |
||
| 1338 | if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) |
||
| 1339 | { |
||
| 1340 | |||
| 1341 | $this->resprints = ' '; |
||
| 1342 | |||
| 1343 | // currentcontext à modifier celon l'appel |
||
| 1344 | $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext'=>'subtotal_hideprices', 'i' => $i); |
||
| 1345 | return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) |
||
| 1346 | } |
||
| 1347 | } |
||
| 1348 | |||
| 1349 | return 0; |
||
| 1350 | } |
||
| 1351 | |||
| 1352 | function pdf_getlineupwithtax($parameters=array(), &$object, &$action='') { |
||
| 1353 | global $conf,$hideprices; |
||
| 1354 | |||
| 1355 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1356 | $this->resprints = ' '; |
||
| 1357 | if((float)DOL_VERSION<=3.6) { |
||
| 1358 | return ''; |
||
| 1359 | } |
||
| 1360 | else if((float)DOL_VERSION>=3.8) { |
||
| 1361 | return 1; |
||
| 1362 | } |
||
| 1363 | } |
||
| 1364 | |||
| 1365 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1366 | else $i = (int)$parameters; |
||
| 1367 | |||
| 1368 | if (!empty($hideprices) |
||
| 1369 | || (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1370 | ) |
||
| 1371 | { |
||
| 1372 | if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1373 | { |
||
| 1374 | $this->resprints = ' '; |
||
| 1375 | return 1; |
||
| 1376 | } |
||
| 1377 | } |
||
| 1378 | |||
| 1379 | return 0; |
||
| 1380 | } |
||
| 1381 | |||
| 1382 | function pdf_getlinevatrate($parameters=array(), &$object, &$action='') { |
||
| 1383 | global $conf,$hideprices,$hookmanager; |
||
| 1384 | |||
| 1385 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1386 | $this->resprints = ' '; |
||
| 1387 | |||
| 1388 | if((float)DOL_VERSION<=3.6) { |
||
| 1389 | return ''; |
||
| 1390 | } |
||
| 1391 | else if((float)DOL_VERSION>=3.8) { |
||
| 1392 | return 1; |
||
| 1393 | } |
||
| 1394 | } |
||
| 1395 | |||
| 1396 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1397 | else $i = (int)$parameters; |
||
| 1398 | |||
| 1399 | if (empty($object->lines[$i])) return 0; // hideInnerLines => override $object->lines et Dolibarr ne nous permet pas de mettre à jour la variable qui conditionne la boucle sur les lignes (PR faite pour 6.0) |
||
| 1400 | |||
| 1401 | $object->lines[$i]->fetch_optionals(); |
||
| 1402 | // Si la gestion C/NC est active et que je suis sur un ligne dont l'extrafield est coché |
||
| 1403 | if ( |
||
| 1404 | !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && |
||
| 1405 | (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) |
||
| 1406 | ) |
||
| 1407 | { |
||
| 1408 | // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue |
||
| 1409 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1410 | { |
||
| 1411 | $this->resprints = ' '; |
||
| 1412 | |||
| 1413 | // currentcontext à modifier celon l'appel |
||
| 1414 | $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i); |
||
| 1415 | return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) |
||
| 1416 | } |
||
| 1417 | } |
||
| 1418 | // Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble |
||
| 1419 | else if (!empty($hideprices)) |
||
| 1420 | { |
||
| 1421 | |||
| 1422 | // Check if a title exist for this line && if the title have subtotal |
||
| 1423 | $lineTitle = TSubtotal::getParentTitleOfLine($object, $i); |
||
| 1424 | if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) |
||
| 1425 | { |
||
| 1426 | |||
| 1427 | $this->resprints = ' '; |
||
| 1428 | |||
| 1429 | // currentcontext à modifier celon l'appel |
||
| 1430 | $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hideprices', 'i' => $i); |
||
| 1431 | return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) |
||
| 1432 | } |
||
| 1433 | } |
||
| 1434 | |||
| 1435 | return 0; |
||
| 1436 | } |
||
| 1437 | |||
| 1438 | function pdf_getlineprogress($parameters=array(), &$object, &$action) { |
||
| 1439 | global $conf; |
||
| 1440 | |||
| 1441 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1442 | $this->resprints = ' '; |
||
| 1443 | if((float)DOL_VERSION<=3.6) { |
||
| 1444 | return ''; |
||
| 1445 | } |
||
| 1446 | else if((float)DOL_VERSION>=3.8) { |
||
| 1447 | return 1; |
||
| 1448 | } |
||
| 1449 | } |
||
| 1450 | |||
| 1451 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1452 | else $i = (int)$parameters; |
||
| 1453 | |||
| 1454 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1455 | { |
||
| 1456 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1457 | { |
||
| 1458 | $this->resprints = ' '; |
||
| 1459 | return 1; |
||
| 1460 | } |
||
| 1461 | } |
||
| 1462 | |||
| 1463 | return 0; |
||
| 1464 | } |
||
| 1465 | |||
| 1466 | function add_numerotation(&$object) { |
||
| 1467 | global $conf; |
||
| 1468 | |||
| 1469 | if(!empty($conf->global->SUBTOTAL_USE_NUMEROTATION)) { |
||
| 1470 | |||
| 1471 | $TLevelTitre = array(); |
||
| 1472 | $prevlevel = 0; |
||
| 1473 | |||
| 1474 | foreach($object->lines as $k=>&$line) |
||
| 1475 | { |
||
| 1476 | if ($line->id > 0 && $this->isModSubtotalLine($k, $object) && $line->qty <= 10) |
||
| 1477 | { |
||
| 1478 | $TLineTitle[] = &$line; |
||
| 1479 | } |
||
| 1480 | } |
||
| 1481 | |||
| 1482 | if (!empty($TLineTitle)) $TTitleNumeroted = $this->formatNumerotation($TLineTitle); |
||
| 1483 | } |
||
| 1484 | |||
| 1485 | } |
||
| 1486 | |||
| 1487 | // TODO ne gère pas encore la numération des lignes "Totaux" |
||
| 1488 | private function formatNumerotation(&$TLineTitle, $line_reference='', $level=1, $prefix_num=0) |
||
| 1489 | { |
||
| 1490 | $TTitle = array(); |
||
| 1491 | |||
| 1492 | $i=1; |
||
| 1493 | $j=0; |
||
| 1494 | foreach ($TLineTitle as $k => &$line) |
||
| 1495 | { |
||
| 1496 | if (!empty($line_reference) && $line->rang <= $line_reference->rang) continue; |
||
| 1497 | if (!empty($line_reference) && $line->qty <= $line_reference->qty) break; |
||
| 1498 | |||
| 1499 | if ($line->qty == $level) |
||
| 1500 | { |
||
| 1501 | $TTitle[$j]['numerotation'] = ($prefix_num == 0) ? $i : $prefix_num.'.'.$i; |
||
| 1502 | //var_dump('Prefix == '.$prefix_num.' // '.$line->desc.' ==> numerotation == '.$TTitle[$j]['numerotation'].' ### '.$line->qty .'=='. $level); |
||
| 1503 | if (empty($line->label) && (float)DOL_VERSION < 6) |
||
| 1504 | { |
||
| 1505 | $line->label = !empty($line->desc) ? $line->desc : $line->description; |
||
| 1506 | $line->desc = $line->description = ''; |
||
| 1507 | } |
||
| 1508 | |||
| 1509 | $line->label = $TTitle[$j]['numerotation'].' '.$line->label; |
||
| 1510 | $TTitle[$j]['line'] = &$line; |
||
| 1511 | |||
| 1512 | $deep_level = $line->qty; |
||
| 1513 | do { |
||
| 1514 | $deep_level++; |
||
| 1515 | $TTitle[$j]['children'] = $this->formatNumerotation($TLineTitle, $line, $deep_level, $TTitle[$j]['numerotation']); |
||
| 1516 | } while (empty($TTitle[$j]['children']) && $deep_level <= 10); // Exemple si un bloc Titre lvl 1 contient pas de sous lvl 2 mais directement un sous lvl 5 |
||
| 1517 | // Rappel on peux avoir jusqu'a 10 niveau de titre |
||
| 1518 | |||
| 1519 | $i++; |
||
| 1520 | $j++; |
||
| 1521 | } |
||
| 1522 | } |
||
| 1523 | |||
| 1524 | return $TTitle; |
||
| 1525 | } |
||
| 1526 | |||
| 1527 | function setDocTVA(&$pdf, &$object) { |
||
| 1528 | |||
| 1529 | $hidedetails = (int)GETPOST('hidedetails'); |
||
| 1530 | |||
| 1531 | if(empty($hidedetails)) return false; |
||
| 1532 | |||
| 1533 | // TODO can't add VAT to document without lines... :-/ |
||
| 1534 | |||
| 1535 | return true; |
||
| 1536 | } |
||
| 1537 | |||
| 1538 | function beforePDFCreation($parameters=array(), &$object, &$action) |
||
| 1539 | { |
||
| 1540 | /** |
||
| 1541 | * @var $pdf TCPDF |
||
| 1542 | */ |
||
| 1543 | global $pdf,$conf, $langs; |
||
| 1544 | |||
| 1545 | // var_dump($object->lines); |
||
| 1546 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 1547 | |||
| 1548 | foreach($parameters as $key=>$value) { |
||
| 1549 | ${$key} = $value; |
||
| 1550 | } |
||
| 1551 | |||
| 1552 | $this->setDocTVA($pdf, $object); |
||
| 1553 | |||
| 1554 | $this->add_numerotation($object); |
||
| 1555 | |||
| 1556 | |||
| 1557 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 1558 | $hidedetails = (int)GETPOST('hidedetails'); |
||
| 1559 | |||
| 1560 | if ($hideInnerLines) { // si c une ligne de titre |
||
| 1561 | $fk_parent_line=0; |
||
| 1562 | $TLines =array(); |
||
| 1563 | |||
| 1564 | $original_count=count($object->lines); |
||
| 1565 | $TTvas = array(); // tableau de tva |
||
| 1566 | |||
| 1567 | foreach($object->lines as $k=>&$line) |
||
| 1568 | { |
||
| 1569 | |||
| 1570 | if($line->product_type==9 && $line->rowid>0) |
||
| 1571 | { |
||
| 1572 | $fk_parent_line = $line->rowid; |
||
| 1573 | |||
| 1574 | // Fix tk7201 - si on cache le détail, la TVA est renseigné au niveau du sous-total, l'erreur c'est s'il y a plusieurs sous-totaux pour les même lignes, ça va faire la somme |
||
| 1575 | if(TSubtotal::isSubtotal($line)) |
||
| 1576 | { |
||
| 1577 | /*$total = $this->getTotalLineFromObject($object, $line, ''); |
||
| 1578 | |||
| 1579 | $line->total_ht = $total; |
||
| 1580 | $line->total = $total; |
||
| 1581 | */ |
||
| 1582 | list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1); |
||
| 1583 | |||
| 1584 | if (TSubtotal::getNiveau($line) == 1) $line->TTotal_tva = $TTotal_tva; |
||
| 1585 | $line->total_ht = $total; |
||
| 1586 | $line->total_tva = $total_tva; |
||
| 1587 | $line->total = $line->total_ht; |
||
| 1588 | $line->total_ttc = $total_ttc; |
||
| 1589 | } |
||
| 1590 | |||
| 1591 | } |
||
| 1592 | |||
| 1593 | if ($hideInnerLines) |
||
| 1594 | { |
||
| 1595 | if(!empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)) |
||
| 1596 | { |
||
| 1597 | if($line->tva_tx != '0.000' && $line->product_type!=9){ |
||
| 1598 | |||
| 1599 | // on remplit le tableau de tva pour substituer les lignes cachées |
||
| 1600 | $TTvas[$line->tva_tx]['total_tva'] += $line->total_tva; |
||
| 1601 | $TTvas[$line->tva_tx]['total_ht'] += $line->total_ht; |
||
| 1602 | $TTvas[$line->tva_tx]['total_ttc'] += $line->total_ttc; |
||
| 1603 | } |
||
| 1604 | if($line->product_type==9 && $line->rowid>0) |
||
| 1605 | { |
||
| 1606 | //Cas où je doit cacher les produits et afficher uniquement les sous-totaux avec les titres |
||
| 1607 | // génère des lignes d'affichage des montants HT soumis à tva |
||
| 1608 | $nbtva = count($TTvas); |
||
| 1609 | if(!empty($nbtva)){ |
||
| 1610 | foreach ($TTvas as $tx =>$val){ |
||
| 1611 | $l = clone $line; |
||
| 1612 | $l->product_type = 1; |
||
| 1613 | $l->special_code = ''; |
||
| 1614 | $l->qty = 1; |
||
| 1615 | $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx)); |
||
| 1616 | $l->tva_tx = $tx; |
||
| 1617 | $l->total_ht = $val['total_ht']; |
||
| 1618 | $l->total_tva = $val['total_tva']; |
||
| 1619 | $l->total = $line->total_ht; |
||
| 1620 | $l->total_ttc = $val['total_ttc']; |
||
| 1621 | $TLines[] = $l; |
||
| 1622 | array_shift($TTvas); |
||
| 1623 | } |
||
| 1624 | } |
||
| 1625 | |||
| 1626 | // ajoute la ligne de sous-total |
||
| 1627 | $TLines[] = $line; |
||
| 1628 | } |
||
| 1629 | } else { |
||
| 1630 | |||
| 1631 | if($line->product_type==9 && $line->rowid>0) |
||
| 1632 | { |
||
| 1633 | // ajoute la ligne de sous-total |
||
| 1634 | $TLines[] = $line; |
||
| 1635 | } |
||
| 1636 | } |
||
| 1637 | |||
| 1638 | |||
| 1639 | } |
||
| 1640 | elseif ($hidedetails) |
||
| 1641 | { |
||
| 1642 | $TLines[] = $line; //Cas où je cache uniquement les prix des produits |
||
| 1643 | } |
||
| 1644 | |||
| 1645 | if ($line->product_type != 9) { // jusqu'au prochain titre ou total |
||
| 1646 | //$line->fk_parent_line = $fk_parent_line; |
||
| 1647 | |||
| 1648 | } |
||
| 1649 | |||
| 1650 | /*if($hideTotal) { |
||
| 1651 | $line->total = 0; |
||
| 1652 | $line->subprice= 0; |
||
| 1653 | }*/ |
||
| 1654 | |||
| 1655 | } |
||
| 1656 | |||
| 1657 | // cas incongru où il y aurait des produits en dessous du dernier sous-total |
||
| 1658 | $nbtva = count($TTvas); |
||
| 1659 | if(!empty($nbtva) && $hideInnerLines && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)) |
||
| 1660 | { |
||
| 1661 | foreach ($TTvas as $tx =>$val){ |
||
| 1662 | $l = clone $line; |
||
| 1663 | $l->product_type = 1; |
||
| 1664 | $l->special_code = ''; |
||
| 1665 | $l->qty = 1; |
||
| 1666 | $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx)); |
||
| 1667 | $l->tva_tx = $tx; |
||
| 1668 | $l->total_ht = $val['total_ht']; |
||
| 1669 | $l->total_tva = $val['total_tva']; |
||
| 1670 | $l->total = $line->total_ht; |
||
| 1671 | $l->total_ttc = $val['total_ttc']; |
||
| 1672 | $TLines[] = $l; |
||
| 1673 | array_shift($TTvas); |
||
| 1674 | } |
||
| 1675 | } |
||
| 1676 | |||
| 1677 | global $nblignes; |
||
| 1678 | $nblignes=count($TLines); |
||
| 1679 | |||
| 1680 | $object->lines = $TLines; |
||
| 1681 | |||
| 1682 | if($i>count($object->lines)) { |
||
| 1683 | $this->resprints = ''; |
||
| 1684 | return 0; |
||
| 1685 | } |
||
| 1686 | } |
||
| 1687 | |||
| 1688 | return 0; |
||
| 1689 | } |
||
| 1690 | |||
| 1691 | function pdf_writelinedesc($parameters=array(), &$object, &$action) |
||
| 1692 | { |
||
| 1693 | /** |
||
| 1694 | * @var $pdf TCPDF |
||
| 1695 | */ |
||
| 1696 | global $pdf,$conf; |
||
| 1697 | |||
| 1698 | foreach($parameters as $key=>$value) { |
||
| 1699 | ${$key} = $value; |
||
| 1700 | } |
||
| 1701 | |||
| 1702 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 1703 | $hidedetails = (int)GETPOST('hidedetails'); |
||
| 1704 | |||
| 1705 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1706 | |||
| 1707 | global $hideprices; |
||
| 1708 | |||
| 1709 | if(!empty($hideprices)) { |
||
| 1710 | foreach($object->lines as &$line) { |
||
| 1711 | if($line->fk_product_type!=9) $line->fk_parent_line = -1; |
||
| 1712 | } |
||
| 1713 | } |
||
| 1714 | |||
| 1715 | $line = &$object->lines[$i]; |
||
| 1716 | |||
| 1717 | if($line->info_bits>0) { // PAGE BREAK |
||
| 1718 | $pdf->addPage(); |
||
| 1719 | $posy = $pdf->GetY(); |
||
| 1720 | } |
||
| 1721 | |||
| 1722 | $label = $line->label; |
||
| 1723 | $description= !empty($line->desc) ? $outputlangs->convToOutputCharset($line->desc) : $outputlangs->convToOutputCharset($line->description); |
||
| 1724 | |||
| 1725 | if(empty($label)) { |
||
| 1726 | $label = $description; |
||
| 1727 | $description=''; |
||
| 1728 | } |
||
| 1729 | |||
| 1730 | if($line->qty>90) { |
||
| 1731 | |||
| 1732 | if ($conf->global->SUBTOTAL_USE_NEW_FORMAT) $label .= ' '.$this->getTitle($object, $line); |
||
| 1733 | |||
| 1734 | $pageBefore = $pdf->getPage(); |
||
| 1735 | $this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); |
||
| 1736 | $pageAfter = $pdf->getPage(); |
||
| 1737 | |||
| 1738 | if($pageAfter>$pageBefore) { |
||
| 1739 | //print "ST $pageAfter>$pageBefore<br>"; |
||
| 1740 | $pdf->rollbackTransaction(true); |
||
| 1741 | $pdf->addPage('','', true); |
||
| 1742 | $posy = $pdf->GetY(); |
||
| 1743 | $this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); |
||
| 1744 | $posy = $pdf->GetY(); |
||
| 1745 | //print 'add ST'.$pdf->getPage().'<br />'; |
||
| 1746 | } |
||
| 1747 | |||
| 1748 | $posy = $pdf->GetY(); |
||
| 1749 | return 1; |
||
| 1750 | } |
||
| 1751 | else if ($line->qty < 10) { |
||
| 1752 | $pageBefore = $pdf->getPage(); |
||
| 1753 | |||
| 1754 | $this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); |
||
| 1755 | $pageAfter = $pdf->getPage(); |
||
| 1756 | |||
| 1757 | |||
| 1758 | /*if($pageAfter>$pageBefore) { |
||
| 1759 | print "T $pageAfter>$pageBefore<br>"; |
||
| 1760 | $pdf->rollbackTransaction(true); |
||
| 1761 | $pdf->addPage('','', true); |
||
| 1762 | print 'add T'.$pdf->getPage().' '.$line->rowid.' '.$pdf->GetY().' '.$posy.'<br />'; |
||
| 1763 | |||
| 1764 | $posy = $pdf->GetY(); |
||
| 1765 | $this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); |
||
| 1766 | $posy = $pdf->GetY(); |
||
| 1767 | } |
||
| 1768 | */ |
||
| 1769 | $posy = $pdf->GetY(); |
||
| 1770 | return 1; |
||
| 1771 | } |
||
| 1772 | // if($line->rowid==47) exit; |
||
| 1773 | |||
| 1774 | return 0; |
||
| 1775 | } |
||
| 1776 | elseif (empty($object->lines[$parameters['i']])) |
||
| 1777 | { |
||
| 1778 | $this->resprints = -1; |
||
| 1779 | } |
||
| 1780 | |||
| 1781 | /* TODO je desactive parce que je comprends pas PH Style, mais à test |
||
| 1782 | else { |
||
| 1783 | |||
| 1784 | if($hideInnerLines) { |
||
| 1785 | $pdf->rollbackTransaction(true); |
||
| 1786 | } |
||
| 1787 | else { |
||
| 1788 | $labelproductservice=pdf_getlinedesc($object, $i, $outputlangs, $hideref, $hidedesc, $issupplierline); |
||
| 1789 | $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1); |
||
| 1790 | } |
||
| 1791 | |||
| 1792 | }*/ |
||
| 1793 | |||
| 1794 | |||
| 1795 | |||
| 1796 | } |
||
| 1797 | |||
| 1798 | /** |
||
| 1799 | * Permet de récupérer le titre lié au sous-total |
||
| 1800 | * |
||
| 1801 | * @return string |
||
| 1802 | */ |
||
| 1803 | function getTitle(&$object, &$currentLine) |
||
| 1804 | { |
||
| 1805 | $res = ''; |
||
| 1806 | |||
| 1807 | foreach ($object->lines as $line) |
||
| 1808 | { |
||
| 1809 | if ($line->id == $currentLine->id) break; |
||
| 1810 | |||
| 1811 | $qty_search = 100 - $currentLine->qty; |
||
| 1812 | |||
| 1813 | if ($line->product_type == 9 && $line->special_code == $this->module_number && $line->qty == $qty_search) |
||
| 1814 | { |
||
| 1815 | $res = ($line->label) ? $line->label : (($line->description) ? $line->description : $line->desc); |
||
| 1816 | } |
||
| 1817 | } |
||
| 1818 | |||
| 1819 | return $res; |
||
| 1820 | } |
||
| 1821 | |||
| 1822 | /** |
||
| 1823 | * @param $parameters array |
||
| 1824 | * @param $object CommonObject |
||
| 1825 | * @param $action string |
||
| 1826 | * @param $hookmanager HookManager |
||
| 1827 | * @return int |
||
| 1828 | */ |
||
| 1829 | function printObjectLine ($parameters, &$object, &$action, $hookmanager){ |
||
| 2247 | |||
| 2248 | } |
||
| 2249 | |||
| 2250 | |||
| 2251 | function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager) { |
||
| 2252 | global $conf,$langs; |
||
| 2253 | |||
| 2254 | if ($object->statut == 0 && !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && $action != 'editline') |
||
| 2255 | { |
||
| 2256 | |||
| 2257 | if($object->element == 'invoice_supplier' || $object->element == 'order_supplier') |
||
| 2258 | { |
||
| 2259 | foreach ($object->lines as $line) |
||
| 2260 | { |
||
| 2261 | // fetch optionals attributes and labels |
||
| 2262 | require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); |
||
| 2263 | $extrafields=new ExtraFields($this->db); |
||
| 2264 | $extralabels=$extrafields->fetch_name_optionals_label($object->table_element_line,true); |
||
| 2265 | $line->fetch_optionals($line->id,$extralabels); |
||
| 2266 | } |
||
| 2267 | } |
||
| 2268 | |||
| 2269 | $TSubNc = array(); |
||
| 2270 | foreach ($object->lines as &$l) |
||
| 2271 | { |
||
| 2272 | $TSubNc[$l->id] = (int) $l->array_options['options_subtotal_nc']; |
||
| 2273 | } |
||
| 2274 | |||
| 2275 | $form = new Form($db); |
||
| 2276 | ?> |
||
| 2277 | <script type="text/javascript"> |
||
| 2278 | $(function() { |
||
| 2279 | var subtotal_TSubNc = <?php echo json_encode($TSubNc); ?>; |
||
| 2280 | $("#tablelines tbody > tr").each(function(i, item) { |
||
| 2281 | if ($(item).children('.subtotal_nc').length == 0) |
||
| 2282 | { |
||
| 2283 | var id = $(item).attr('id'); |
||
| 2284 | |||
| 2285 | if ((typeof id != 'undefined' && id.indexOf('row-') >= 0) || $(item).hasClass('liste_titre')) |
||
| 2286 | { |
||
| 2287 | $(item).children('td:last-child').before('<td class="subtotal_nc"></td>'); |
||
| 2288 | |||
| 2289 | if ($(item).attr('rel') != 'subtotal' && typeof $(item).attr('id') != 'undefined') |
||
| 2290 | { |
||
| 2291 | var idSplit = $(item).attr('id').split('-'); |
||
| 2292 | $(item).children('td.subtotal_nc').append($('<input type="checkbox" id="subtotal_nc-'+idSplit[1]+'" class="subtotal_nc_chkbx" data-lineid="'+idSplit[1]+'" value="1" '+(typeof subtotal_TSubNc[idSplit[1]] != 'undefined' && subtotal_TSubNc[idSplit[1]] == 1 ? 'checked="checked"' : '')+' />')); |
||
| 2293 | } |
||
| 2294 | } |
||
| 2295 | else |
||
| 2296 | { |
||
| 2297 | $(item).append('<td class="subtotal_nc"></td>'); |
||
| 2298 | } |
||
| 2299 | } |
||
| 2300 | }); |
||
| 2301 | |||
| 2302 | $('#tablelines tbody tr.liste_titre:first .subtotal_nc').html(<?php echo json_encode($form->textwithtooltip($langs->trans('subtotal_nc_title'), $langs->trans('subtotal_nc_title_help'))); ?>); |
||
| 2303 | |||
| 2304 | function callAjaxUpdateLineNC(set, lineid, subtotal_nc) |
||
| 2305 | { |
||
| 2306 | $.ajax({ |
||
| 2307 | url: '<?php echo dol_buildpath('/subtotal/script/interface.php', 1); ?>' |
||
| 2308 | ,type: 'POST' |
||
| 2309 | ,data: { |
||
| 2310 | json:1 |
||
| 2311 | ,set: set |
||
| 2312 | ,element: '<?php echo $object->element; ?>' |
||
| 2313 | ,elementid: <?php echo (int) $object->id; ?> |
||
| 2314 | ,lineid: lineid |
||
| 2315 | ,subtotal_nc: subtotal_nc |
||
| 2316 | } |
||
| 2317 | }).done(function(response) { |
||
| 2318 | window.location.href = window.location.pathname + '?id=<?php echo $object->id; ?>&page_y=' + window.pageYOffset; |
||
| 2319 | }); |
||
| 2320 | } |
||
| 2321 | |||
| 2322 | $(".subtotal_nc_chkbx").change(function(event) { |
||
| 2323 | var lineid = $(this).data('lineid'); |
||
| 2324 | var subtotal_nc = 0 | $(this).is(':checked'); // Renvoi 0 ou 1 |
||
| 2325 | |||
| 2326 | callAjaxUpdateLineNC('updateLineNC', lineid, subtotal_nc); |
||
| 2327 | }); |
||
| 2328 | |||
| 2329 | }); |
||
| 2330 | |||
| 2331 | </script> |
||
| 2332 | <?php |
||
| 2333 | } |
||
| 2334 | |||
| 2335 | $this->_ajax_block_order_js($object); |
||
| 2336 | } |
||
| 2337 | |||
| 2338 | function afterPDFCreation($parameters, &$pdf, &$action, $hookmanager) |
||
| 2349 | } |
||
| 2350 | } |
||
| 2351 | } |
||
| 2352 | |||
| 2353 | // HTML 5 data for js |
||
| 2354 | private function _getHtmlData($parameters, &$object, &$action, $hookmanager) |
||
| 2355 | { |
||
| 2356 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 2357 | |||
| 2358 | $line = &$parameters['line']; |
||
| 2359 | |||
| 2360 | $ThtmlData['data-id'] = $line->id; |
||
| 2361 | $ThtmlData['data-product_type'] = $line->product_type; |
||
| 2362 | $ThtmlData['data-qty'] = 0; //$line->qty; |
||
| 2363 | $ThtmlData['data-level'] = TSubtotal::getNiveau($line); |
||
| 2364 | |||
| 2365 | if(TSubtotal::isTitle($line)){ |
||
| 2366 | $ThtmlData['data-issubtotal'] = 'title'; |
||
| 2367 | }elseif(TSubtotal::isSubtotal($line)){ |
||
| 2368 | $ThtmlData['data-issubtotal'] = 'subtotal'; |
||
| 2369 | } |
||
| 2370 | else{ |
||
| 2371 | $ThtmlData['data-issubtotal'] = 'freetext'; |
||
| 2372 | } |
||
| 2373 | |||
| 2374 | |||
| 2375 | // Change or add data from hooks |
||
| 2376 | $parameters = array_replace($parameters , array( 'ThtmlData' => $ThtmlData ) ); |
||
| 2377 | |||
| 2378 | // hook |
||
| 2379 | $reshook = $hookmanager->executeHooks('subtotalLineHtmlData',$parameters,$object,$action); // Note that $action and $object may have been modified by hook |
||
| 2380 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 2381 | if ($reshook>0) |
||
| 2382 | { |
||
| 2383 | $ThtmlData = $hookmanager->resArray; |
||
| 2384 | } |
||
| 2385 | |||
| 2386 | return $this->implodeHtmlData($ThtmlData); |
||
| 2387 | |||
| 2388 | } |
||
| 2389 | |||
| 2390 | |||
| 2391 | function implodeHtmlData($ThtmlData = array()) |
||
| 2405 | } |
||
| 2406 | |||
| 2407 | function _ajax_block_order_js($object) |
||
| 2408 | { |
||
| 2409 | global $conf,$tagidfortablednd,$filepath,$langs; |
||
| 2410 | |||
| 2411 | /* |
||
| 2412 | * this part of js is base on dolibarr htdocs/core/tpl/ajaxrow.tpl.php |
||
| 2413 | * for compatibility reasons we don't use tableDnD but jquery sortable |
||
| 2414 | */ |
||
| 2415 | |||
| 2518 | function getSubtotalTitleChilds(item) |
||
| 2519 | { |
||
| 2520 | var TcurrentChilds = []; // = JSON.parse(item.attr('data-childrens')); |
||
| 2521 | var level = item.data('level'); |
||
| 2522 | |||
| 2523 | var indexOfFirstSubtotal = -1; |
||
| 2524 | var indexOfFirstTitle = -1; |
||
| 2525 | |||
| 2526 | item.nextAll('[id^="row-"]').each(function(index){ |
||
| 2527 | |||
| 2588 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.