| Total Complexity | 530 |
| Total Lines | 2319 |
| Duplicated Lines | 0 % |
| Changes | 124 | ||
| Bugs | 10 | Features | 7 |
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) |
||
|
|
|||
| 6 | { |
||
| 7 | global $langs; |
||
| 8 | |||
| 9 | $this->db = $db; |
||
| 10 | $langs->load('subtotal@subtotal'); |
||
| 11 | |||
| 12 | $this->allow_move_block_lines = true; |
||
| 13 | } |
||
| 14 | |||
| 15 | |||
| 16 | function createDictionaryFieldlist($parameters, &$object, &$action, $hookmanager) |
||
| 26 | $(function() { |
||
| 27 | CKEDITOR.on('instanceReady', function(ev) { |
||
| 28 | var editor = ev.editor; |
||
| 29 | |||
| 30 | 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 |
||
| 31 | { |
||
| 32 | editor.element.show(); |
||
| 33 | editor.destroy(); |
||
| 34 | } |
||
| 35 | }); |
||
| 36 | }); |
||
| 37 | </script> |
||
| 38 | <?php |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | /** Overloading the doActions function : replacing the parent's function with the one below |
||
| 43 | * @param $parameters array meta datas of the hook (context, etc...) |
||
| 44 | * @param $object CommonObject the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...) |
||
| 45 | * @param $action string current action (if set). Generally create or edit or null |
||
| 46 | * @param $hookmanager HookManager current hook manager |
||
| 47 | * @return void |
||
| 48 | */ |
||
| 49 | |||
| 50 | var $module_number = 104777; |
||
| 51 | |||
| 52 | function formObjectOptions($parameters, &$object, &$action, $hookmanager) |
||
| 53 | { |
||
| 54 | global $langs,$db,$user, $conf; |
||
| 55 | |||
| 56 | $langs->load('subtotal@subtotal'); |
||
| 57 | |||
| 58 | $contexts = explode(':',$parameters['context']); |
||
| 59 | |||
| 60 | 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)) { |
||
| 61 | |||
| 62 | $createRight = $user->rights->{$object->element}->creer; |
||
| 63 | if($object->element == 'facturerec' ) |
||
| 64 | { |
||
| 65 | $object->statut = 0; // hack for facture rec |
||
| 66 | $createRight = $user->rights->facture->creer; |
||
| 67 | } elseif($object->element == 'order_supplier' ) |
||
| 68 | { |
||
| 69 | $createRight = $user->rights->fournisseur->commande->creer; |
||
| 70 | } elseif($object->element == 'invoice_supplier' ) |
||
| 71 | { |
||
| 72 | $createRight = $user->rights->fournisseur->facture->creer; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($object->statut == 0 && $createRight) { |
||
| 76 | |||
| 77 | |||
| 78 | if($object->element=='facture')$idvar = 'facid'; |
||
| 79 | else $idvar='id'; |
||
| 80 | |||
| 81 | if(in_array($action, array('add_title_line', 'add_total_line', 'add_subtitle_line', 'add_subtotal_line', 'add_free_text')) ) |
||
| 82 | { |
||
| 83 | $level = GETPOST('level', 'int'); //New avec SUBTOTAL_USE_NEW_FORMAT |
||
| 84 | |||
| 85 | if($action=='add_title_line') { |
||
| 86 | $title = GETPOST('title'); |
||
| 87 | if(empty($title)) $title = $langs->trans('title'); |
||
| 88 | $qty = $level<1 ? 1 : $level ; |
||
| 89 | } |
||
| 90 | else if($action=='add_free_text') { |
||
| 91 | $title = GETPOST('title'); |
||
| 92 | |||
| 93 | if (empty($title)) { |
||
| 94 | $free_text = GETPOST('free_text', 'int'); |
||
| 95 | if (!empty($free_text)) { |
||
| 96 | $TFreeText = getTFreeText(); |
||
| 97 | if (!empty($TFreeText[$free_text])) { |
||
| 98 | $title = $TFreeText[$free_text]->content; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | if(empty($title)) $title = $langs->trans('subtotalAddLineDescription'); |
||
| 103 | $qty = 50; |
||
| 104 | } |
||
| 105 | else if($action=='add_subtitle_line') { |
||
| 106 | $title = GETPOST('title'); |
||
| 107 | if(empty($title)) $title = $langs->trans('subtitle'); |
||
| 108 | $qty = 2; |
||
| 109 | } |
||
| 110 | else if($action=='add_subtotal_line') { |
||
| 111 | $title = $langs->trans('SubSubTotal'); |
||
| 112 | $qty = 98; |
||
| 113 | } |
||
| 114 | else { |
||
| 115 | $title = GETPOST('title') ? GETPOST('title') : $langs->trans('SubTotal'); |
||
| 116 | $qty = $level ? 100-$level : 99; |
||
| 117 | } |
||
| 118 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 119 | |||
| 120 | if (!empty($conf->global->SUBTOTAL_AUTO_ADD_SUBTOTAL_ON_ADDING_NEW_TITLE) && $qty < 10) TSubtotal::addSubtotalMissing($object, $qty); |
||
| 121 | |||
| 122 | TSubtotal::addSubTotalLine($object, $title, $qty); |
||
| 123 | } |
||
| 124 | else if($action==='ask_deleteallline') { |
||
| 125 | $form=new Form($db); |
||
| 126 | |||
| 127 | $lineid = GETPOST('lineid','integer'); |
||
| 128 | $TIdForGroup = $this->getArrayOfLineForAGroup($object, $lineid); |
||
| 129 | |||
| 130 | $nbLines = count($TIdForGroup); |
||
| 131 | |||
| 132 | $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('deleteWithAllLines'), $langs->trans('ConfirmDeleteAllThisLines',$nbLines), 'confirm_delete_all_lines','',0,1); |
||
| 133 | print $formconfirm; |
||
| 134 | } |
||
| 135 | |||
| 136 | if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE)) |
||
| 137 | { |
||
| 138 | $this->showSelectTitleToAdd($object); |
||
| 139 | } |
||
| 140 | |||
| 141 | |||
| 142 | if($action!='editline') { |
||
| 143 | // New format is for 3.8 |
||
| 144 | $this->printNewFormat($object, $conf, $langs, $idvar); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | elseif ((!empty($parameters['currentcontext']) && $parameters['currentcontext'] == 'orderstoinvoice') || in_array('orderstoinvoice',$contexts)) |
||
| 149 | { |
||
| 150 | ?> |
||
| 151 | <script type="text/javascript"> |
||
| 152 | $(function() { |
||
| 153 | 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>") |
||
| 154 | $("textarea[name=note]").closest('tr').after(tr); |
||
| 155 | }); |
||
| 156 | </script> |
||
| 157 | <?php |
||
| 158 | |||
| 159 | } |
||
| 160 | |||
| 161 | return 0; |
||
| 162 | } |
||
| 163 | |||
| 164 | function printNewFormat(&$object, &$conf, &$langs, $idvar) |
||
| 165 | { |
||
| 166 | if (empty($conf->global->SUBTOTAL_ALLOW_ADD_BLOCK)) return false; |
||
| 167 | if (!empty($object->situation_cycle_ref) && $object->situation_counter > 1) return false; // Si facture de situation |
||
| 168 | ?> |
||
| 169 | <script type="text/javascript"> |
||
| 170 | $(document).ready(function() { |
||
| 171 | $('div.fiche div.tabsAction').append('<br />'); |
||
| 172 | |||
| 173 | $('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>'); |
||
| 174 | $('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>'); |
||
| 175 | $('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>'); |
||
| 176 | |||
| 177 | |||
| 178 | function updateAllMessageForms(){ |
||
| 179 | for (instance in CKEDITOR.instances) { |
||
| 180 | CKEDITOR.instances[instance].updateElement(); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | function promptSubTotal(action, titleDialog, label, url_to, url_ajax, params, use_textarea, show_free_text, show_under_title) { |
||
| 185 | $( "#dialog-prompt-subtotal" ).remove(); |
||
| 186 | |||
| 187 | var dialog_html = '<div id="dialog-prompt-subtotal" '+(action == 'addSubtotal' ? 'class="center"' : '')+' >'; |
||
| 188 | |||
| 189 | if (typeof show_under_title != 'undefined' && show_under_title) |
||
| 190 | { |
||
| 191 | var selectUnderTitle = <?php echo json_encode(getHtmlSelectTitle($object, true)); ?>; |
||
| 192 | dialog_html += selectUnderTitle + '<br /><br />'; |
||
| 193 | } |
||
| 194 | |||
| 195 | if (action == 'addTitle' || action == 'addFreeTxt') |
||
| 196 | { |
||
| 197 | if (typeof show_free_text != 'undefined' && show_free_text) |
||
| 198 | { |
||
| 199 | var selectFreeText = <?php echo json_encode(getHtmlSelectFreeText()); ?>; |
||
| 200 | dialog_html += selectFreeText + ' <?php echo $langs->transnoentities('subtotalFreeTextOrDesc'); ?><br />'; |
||
| 201 | } |
||
| 202 | |||
| 203 | if (typeof use_textarea != 'undefined' && use_textarea) dialog_html += '<textarea id="sub-total-title" rows="<?php echo ROWS_8; ?>" cols="80" placeholder="'+label+'"></textarea>'; |
||
| 204 | else dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />'; |
||
| 205 | } |
||
| 206 | |||
| 207 | if (action == 'addTitle' || action == 'addSubtotal') |
||
| 208 | { |
||
| 209 | if (action == 'addSubtotal') dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />'; |
||
| 210 | |||
| 211 | dialog_html += " <select name='subtotal_line_level'>"; |
||
| 212 | for (var i=1;i<10;i++) |
||
| 213 | { |
||
| 214 | dialog_html += "<option value="+i+"><?php echo $langs->trans('Level'); ?> "+i+"</option>"; |
||
| 215 | } |
||
| 216 | dialog_html += "</select>"; |
||
| 217 | } |
||
| 218 | |||
| 219 | dialog_html += '</div>'; |
||
| 220 | |||
| 221 | $('body').append(dialog_html); |
||
| 222 | |||
| 223 | <?php |
||
| 224 | $editorTool = empty($conf->global->FCKEDITOR_EDITORNAME)?'ckeditor':$conf->global->FCKEDITOR_EDITORNAME; |
||
| 225 | $editorConf = empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?false:$conf->global->FCKEDITOR_ENABLE_DETAILS; |
||
| 226 | if($editorConf && in_array($editorTool,array('textarea','ckeditor'))){ |
||
| 227 | ?> |
||
| 228 | if (action == 'addTitle' || action == 'addFreeTxt') |
||
| 229 | { |
||
| 230 | if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" ) |
||
| 231 | { |
||
| 232 | CKEDITOR.replace( 'sub-total-title', {toolbar: 'dolibarr_details', toolbarStartupExpanded: false} ); |
||
| 233 | } |
||
| 234 | } |
||
| 235 | <?php } ?> |
||
| 236 | |||
| 237 | $( "#dialog-prompt-subtotal" ).dialog({ |
||
| 238 | resizable: false, |
||
| 239 | height: 'auto', |
||
| 240 | width: 'auto', |
||
| 241 | modal: true, |
||
| 242 | title: titleDialog, |
||
| 243 | buttons: { |
||
| 244 | "Ok": function() { |
||
| 245 | if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" ){ updateAllMessageForms(); } |
||
| 246 | 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()); |
||
| 247 | params.under_title = $(this).find('select[name=under_title]').val(); |
||
| 248 | params.free_text = $(this).find('select[name=free_text]').val(); |
||
| 249 | params.level = $(this).find('select[name=subtotal_line_level]').val(); |
||
| 250 | |||
| 251 | $.ajax({ |
||
| 252 | url: url_ajax |
||
| 253 | ,type: 'POST' |
||
| 254 | ,data: params |
||
| 255 | }).done(function() { |
||
| 256 | document.location.href=url_to; |
||
| 257 | }); |
||
| 258 | |||
| 259 | $( this ).dialog( "close" ); |
||
| 260 | }, |
||
| 261 | "<?php echo $langs->trans('Cancel') ?>": function() { |
||
| 262 | $( this ).dialog( "close" ); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | }); |
||
| 266 | } |
||
| 267 | |||
| 268 | $('a[rel=add_title_line]').click(function() |
||
| 269 | { |
||
| 270 | promptSubTotal('addTitle' |
||
| 271 | , "<?php echo $langs->trans('YourTitleLabel') ?>" |
||
| 272 | , "<?php echo $langs->trans('title'); ?>" |
||
| 273 | , '?<?php echo $idvar ?>=<?php echo $object->id; ?>' |
||
| 274 | , '<?php echo $_SERVER['PHP_SELF']; ?>' |
||
| 275 | , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_title_line'} |
||
| 276 | ); |
||
| 277 | }); |
||
| 278 | |||
| 279 | $('a[rel=add_total_line]').click(function() |
||
| 280 | { |
||
| 281 | promptSubTotal('addSubtotal' |
||
| 282 | , '<?php echo $langs->trans('YourSubtotalLabel') ?>' |
||
| 283 | , '<?php echo $langs->trans('subtotal'); ?>' |
||
| 284 | , '?<?php echo $idvar ?>=<?php echo $object->id; ?>' |
||
| 285 | , '<?php echo $_SERVER['PHP_SELF']; ?>' |
||
| 286 | , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_total_line'} |
||
| 287 | /*,false,false, <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?>*/ |
||
| 288 | ); |
||
| 289 | }); |
||
| 290 | |||
| 291 | $('a[rel=add_free_text]').click(function() |
||
| 292 | { |
||
| 293 | promptSubTotal('addFreeTxt' |
||
| 294 | , "<?php echo $langs->transnoentitiesnoconv('YourTextLabel') ?>" |
||
| 295 | , "<?php echo $langs->trans('subtotalAddLineDescription'); ?>" |
||
| 296 | , '?<?php echo $idvar ?>=<?php echo $object->id; ?>' |
||
| 297 | , '<?php echo $_SERVER['PHP_SELF']; ?>' |
||
| 298 | , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_free_text'} |
||
| 299 | , true |
||
| 300 | , true |
||
| 301 | , <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?> |
||
| 302 | ); |
||
| 303 | }); |
||
| 304 | }); |
||
| 305 | </script> |
||
| 306 | <?php |
||
| 307 | } |
||
| 308 | |||
| 309 | function showSelectTitleToAdd(&$object) |
||
| 310 | { |
||
| 311 | global $langs; |
||
| 312 | |||
| 313 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 314 | dol_include_once('/subtotal/lib/subtotal.lib.php'); |
||
| 315 | $TTitle = TSubtotal::getAllTitleFromDocument($object); |
||
| 316 | |||
| 317 | ?> |
||
| 318 | <script type="text/javascript"> |
||
| 319 | $(function() { |
||
| 320 | var add_button = $("#addline"); |
||
| 321 | |||
| 322 | if (add_button.length > 0) |
||
| 323 | { |
||
| 324 | add_button.closest('tr').prev('tr.liste_titre').children('td:last').addClass('center').text("<?php echo $langs->trans('subtotal_title_to_add_under_title'); ?>"); |
||
| 325 | var select_title = $(<?php echo json_encode(getHtmlSelectTitle($object)); ?>); |
||
| 326 | |||
| 327 | add_button.before(select_title); |
||
| 328 | } |
||
| 329 | }); |
||
| 330 | </script> |
||
| 331 | <?php |
||
| 332 | } |
||
| 333 | |||
| 334 | |||
| 335 | function formBuilddocOptions($parameters) { |
||
| 336 | /* Réponse besoin client */ |
||
| 337 | |||
| 338 | global $conf, $langs, $bc; |
||
| 339 | |||
| 340 | $action = GETPOST('action'); |
||
| 341 | $TContext = explode(':',$parameters['context']); |
||
| 342 | if ( |
||
| 343 | in_array('invoicecard',$TContext) |
||
| 344 | || in_array('invoicesuppliercard',$TContext) |
||
| 345 | || in_array('propalcard',$TContext) |
||
| 346 | || in_array('ordercard',$TContext) |
||
| 347 | || in_array('ordersuppliercard',$TContext) |
||
| 348 | || in_array('invoicereccard',$TContext) |
||
| 349 | ) |
||
| 350 | { |
||
| 351 | $hideInnerLines = isset( $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']] ) ? $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']] : 0; |
||
| 352 | $hidedetails = isset( $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']] ) ? $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']] : 0; |
||
| 353 | $hideprices= isset( $_SESSION['subtotal_hideprices_'.$parameters['modulepart']] ) ? $_SESSION['subtotal_hideprices_'.$parameters['modulepart']] : 0; |
||
| 354 | |||
| 355 | $var=false; |
||
| 356 | $out.= '<tr '.$bc[$var].'> |
||
| 357 | <td colspan="4" align="right"> |
||
| 358 | <label for="hideInnerLines">'.$langs->trans('HideInnerLines').'</label> |
||
| 359 | <input type="checkbox" onclick="if($(this).is(\':checked\')) { $(\'#hidedetails\').prop(\'checked\', \'checked\') }" id="hideInnerLines" name="hideInnerLines" value="1" '.(( $hideInnerLines ) ? 'checked="checked"' : '' ).' /> |
||
| 360 | </td> |
||
| 361 | </tr>'; |
||
| 362 | |||
| 363 | $var=!$var; |
||
| 364 | $out.= '<tr '.$bc[$var].'> |
||
| 365 | <td colspan="4" align="right"> |
||
| 366 | <label for="hidedetails">'.$langs->trans('SubTotalhidedetails').'</label> |
||
| 367 | <input type="checkbox" id="hidedetails" name="hidedetails" value="1" '.(( $hidedetails ) ? 'checked="checked"' : '' ).' /> |
||
| 368 | </td> |
||
| 369 | </tr>'; |
||
| 370 | |||
| 371 | $var=!$var; |
||
| 372 | $out.= '<tr '.$bc[$var].'> |
||
| 373 | <td colspan="4" align="right"> |
||
| 374 | <label for="hidedetails">'.$langs->trans('SubTotalhidePrice').'</label> |
||
| 375 | <input type="checkbox" id="hideprices" name="hideprices" value="1" '.(( $hideprices ) ? 'checked="checked"' : '' ).' /> |
||
| 376 | </td> |
||
| 377 | </tr>'; |
||
| 378 | |||
| 379 | |||
| 380 | |||
| 381 | if ( |
||
| 382 | (in_array('propalcard',$TContext) && !empty($conf->global->SUBTOTAL_PROPAL_ADD_RECAP)) |
||
| 383 | || (in_array('ordercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP)) |
||
| 384 | || (in_array('ordersuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP)) |
||
| 385 | || (in_array('invoicecard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP)) |
||
| 386 | || (in_array('invoicesuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP)) |
||
| 387 | || (in_array('invoicereccard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP )) |
||
| 388 | ) |
||
| 389 | { |
||
| 390 | $var=!$var; |
||
| 391 | $out.= ' |
||
| 392 | <tr '.$bc[$var].'> |
||
| 393 | <td colspan="4" align="right"> |
||
| 394 | <label for="subtotal_add_recap">'.$langs->trans('subtotal_add_recap').'</label> |
||
| 395 | <input type="checkbox" id="subtotal_add_recap" name="subtotal_add_recap" value="1" '.( GETPOST('subtotal_add_recap') ? 'checked="checked"' : '' ).' /> |
||
| 396 | </td> |
||
| 397 | </tr>'; |
||
| 398 | } |
||
| 399 | |||
| 400 | |||
| 401 | $this->resprints = $out; |
||
| 402 | } |
||
| 403 | |||
| 404 | |||
| 405 | return 1; |
||
| 406 | } |
||
| 407 | |||
| 408 | function formEditProductOptions($parameters, &$object, &$action, $hookmanager) |
||
| 409 | { |
||
| 410 | |||
| 411 | if (in_array('invoicecard',explode(':',$parameters['context']))) |
||
| 412 | { |
||
| 413 | |||
| 414 | } |
||
| 415 | |||
| 416 | return 0; |
||
| 417 | } |
||
| 418 | |||
| 419 | function ODTSubstitutionLine(&$parameters, &$object, $action, $hookmanager) { |
||
| 420 | global $conf; |
||
| 421 | |||
| 422 | if($action === 'builddoc') { |
||
| 423 | |||
| 424 | $line = &$parameters['line']; |
||
| 425 | $object = &$parameters['object']; |
||
| 426 | $substitutionarray = &$parameters['substitutionarray']; |
||
| 427 | |||
| 428 | if($line->product_type == 9 && $line->special_code == $this->module_number) { |
||
| 429 | $substitutionarray['line_modsubtotal'] = 1; |
||
| 430 | |||
| 431 | $substitutionarray['line_price_ht'] |
||
| 432 | = $substitutionarray['line_price_vat'] |
||
| 433 | = $substitutionarray['line_price_ttc'] |
||
| 434 | = $substitutionarray['line_vatrate'] |
||
| 435 | = $substitutionarray['line_qty'] |
||
| 436 | = $substitutionarray['line_up'] |
||
| 437 | = ''; |
||
| 438 | |||
| 439 | if($line->qty>90) { |
||
| 440 | $substitutionarray['line_modsubtotal_total'] = true; |
||
| 441 | |||
| 442 | list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1); |
||
| 443 | |||
| 444 | $substitutionarray['line_price_ht'] = $total; |
||
| 445 | $substitutionarray['line_price_vat'] = $total_tva; |
||
| 446 | $substitutionarray['line_price_ttc'] = $total_ttc; |
||
| 447 | } else { |
||
| 448 | $substitutionarray['line_modsubtotal_title'] = true; |
||
| 449 | } |
||
| 450 | |||
| 451 | |||
| 452 | } |
||
| 453 | else{ |
||
| 454 | $substitutionarray['line_not_modsubtotal'] = true; |
||
| 455 | $substitutionarray['line_modsubtotal'] = 0; |
||
| 456 | } |
||
| 457 | |||
| 458 | } |
||
| 459 | |||
| 460 | } |
||
| 461 | |||
| 462 | function createFrom($parameters, &$object, $action, $hookmanager) { |
||
| 463 | |||
| 464 | if ( |
||
| 465 | in_array('invoicecard',explode(':',$parameters['context'])) |
||
| 466 | || in_array('invoicesuppliercard',explode(':',$parameters['context'])) |
||
| 467 | || in_array('propalcard',explode(':',$parameters['context'])) |
||
| 468 | || in_array('supplier_proposalcard',explode(':',$parameters['context'])) |
||
| 469 | || in_array('ordercard',explode(':',$parameters['context'])) |
||
| 470 | || in_array('ordersuppliercard',explode(':',$parameters['context'])) |
||
| 471 | || in_array('invoicereccard',explode(':',$parameters['context'])) |
||
| 472 | ) { |
||
| 473 | |||
| 474 | global $db; |
||
| 475 | |||
| 476 | $objFrom = $parameters['objFrom']; |
||
| 477 | |||
| 478 | foreach($objFrom->lines as $k=> &$lineOld) { |
||
| 479 | |||
| 480 | if($lineOld->product_type == 9 && $lineOld->info_bits > 0 ) { |
||
| 481 | |||
| 482 | $line = & $object->lines[$k]; |
||
| 483 | |||
| 484 | $idLine = (int) ($line->id ? $line->id : $line->rowid); |
||
| 485 | |||
| 486 | $db->query("UPDATE ".MAIN_DB_PREFIX.$line->table_element." |
||
| 487 | SET info_bits=".(int)$lineOld->info_bits." |
||
| 488 | WHERE rowid = ".$idLine." |
||
| 489 | "); |
||
| 490 | |||
| 491 | } |
||
| 492 | |||
| 493 | |||
| 494 | } |
||
| 495 | |||
| 496 | |||
| 497 | } |
||
| 498 | |||
| 499 | } |
||
| 500 | |||
| 501 | function doActions($parameters, &$object, $action, $hookmanager) |
||
| 502 | { |
||
| 503 | global $db, $conf, $langs,$user; |
||
| 504 | |||
| 505 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 506 | dol_include_once('/subtotal/lib/subtotal.lib.php'); |
||
| 507 | require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
||
| 508 | |||
| 509 | $showBlockExtrafields = GETPOST('showBlockExtrafields'); |
||
| 510 | |||
| 511 | if($object->element=='facture') $idvar = 'facid'; |
||
| 512 | else $idvar = 'id'; |
||
| 513 | |||
| 514 | if ($action == 'updateligne' || $action == 'updateline') |
||
| 515 | { |
||
| 516 | $found = false; |
||
| 517 | $lineid = GETPOST('lineid', 'int'); |
||
| 518 | foreach ($object->lines as &$line) |
||
| 519 | { |
||
| 520 | |||
| 521 | if ($line->id == $lineid && TSubtotal::isModSubtotalLine($line)) |
||
| 522 | { |
||
| 523 | $found = true; |
||
| 524 | if(TSubtotal::isTitle($line) && !empty($showBlockExtrafields)) { |
||
| 525 | $extrafieldsline = new ExtraFields($db); |
||
| 526 | $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); |
||
| 527 | $extrafieldsline->setOptionalsFromPost($extralabelsline, $line); |
||
| 528 | } |
||
| 529 | _updateSubtotalLine($object, $line); |
||
| 530 | _updateSubtotalBloc($object, $line); |
||
| 531 | |||
| 532 | TSubtotal::generateDoc($object); |
||
| 533 | break; |
||
| 534 | } |
||
| 535 | } |
||
| 536 | |||
| 537 | if ($found) |
||
| 538 | { |
||
| 539 | header('Location: '.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id); |
||
| 540 | exit; // Surtout ne pas laisser Dolibarr faire du traitement sur le updateligne sinon ça plante les données de la ligne |
||
| 541 | } |
||
| 542 | } |
||
| 543 | else if($action === 'builddoc') { |
||
| 544 | |||
| 545 | if ( |
||
| 546 | in_array('invoicecard',explode(':',$parameters['context'])) |
||
| 547 | || in_array('propalcard',explode(':',$parameters['context'])) |
||
| 548 | || in_array('ordercard',explode(':',$parameters['context'])) |
||
| 549 | || in_array('ordersuppliercard',explode(':',$parameters['context'])) |
||
| 550 | || in_array('invoicesuppliercard',explode(':',$parameters['context'])) |
||
| 551 | || in_array('supplier_proposalcard',explode(':',$parameters['context'])) |
||
| 552 | ) |
||
| 553 | { |
||
| 554 | if(in_array('invoicecard',explode(':',$parameters['context']))) { |
||
| 555 | $sessname = 'subtotal_hideInnerLines_facture'; |
||
| 556 | $sessname2 = 'subtotal_hidedetails_facture'; |
||
| 557 | $sessname3 = 'subtotal_hideprices_facture'; |
||
| 558 | } |
||
| 559 | elseif(in_array('invoicesuppliercard',explode(':',$parameters['context']))) { |
||
| 560 | $sessname = 'subtotal_hideInnerLines_facture_fournisseur'; |
||
| 561 | $sessname2 = 'subtotal_hidedetails_facture_fournisseur'; |
||
| 562 | $sessname3 = 'subtotal_hideprices_facture_fournisseur'; |
||
| 563 | } |
||
| 564 | elseif(in_array('propalcard',explode(':',$parameters['context']))) { |
||
| 565 | $sessname = 'subtotal_hideInnerLines_propal'; |
||
| 566 | $sessname2 = 'subtotal_hidedetails_propal'; |
||
| 567 | $sessname3 = 'subtotal_hideprices_propal'; |
||
| 568 | } |
||
| 569 | elseif(in_array('supplier_proposalcard',explode(':',$parameters['context']))) { |
||
| 570 | $sessname = 'subtotal_hideInnerLines_supplier_proposal'; |
||
| 571 | $sessname2 = 'subtotal_hidedetails_supplier_proposal'; |
||
| 572 | $sessname3 = 'subtotal_hideprices_supplier_proposal'; |
||
| 573 | } |
||
| 574 | elseif(in_array('ordercard',explode(':',$parameters['context']))) { |
||
| 575 | $sessname = 'subtotal_hideInnerLines_commande'; |
||
| 576 | $sessname2 = 'subtotal_hidedetails_commande'; |
||
| 577 | $sessname3 = 'subtotal_hideprices_commande'; |
||
| 578 | } |
||
| 579 | elseif(in_array('ordersuppliercard',explode(':',$parameters['context']))) { |
||
| 580 | $sessname = 'subtotal_hideInnerLines_commande_fournisseur'; |
||
| 581 | $sessname2 = 'subtotal_hidedetails_commande_fournisseur'; |
||
| 582 | $sessname3 = 'subtotal_hideprices_commande_fournisseur'; |
||
| 583 | } |
||
| 584 | else { |
||
| 585 | $sessname = 'subtotal_hideInnerLines_unknown'; |
||
| 586 | $sessname2 = 'subtotal_hidedetails_unknown'; |
||
| 587 | $sessname3 = 'subtotal_hideprices_unknown'; |
||
| 588 | } |
||
| 589 | |||
| 590 | global $hideprices; |
||
| 591 | |||
| 592 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 593 | $_SESSION[$sessname] = $hideInnerLines; |
||
| 594 | |||
| 595 | $hidedetails= (int)GETPOST('hidedetails'); |
||
| 596 | $_SESSION[$sessname2] = $hidedetails; |
||
| 597 | |||
| 598 | $hideprices= (int)GETPOST('hideprices'); |
||
| 599 | $_SESSION[$sessname3] = $hideprices; |
||
| 600 | |||
| 601 | foreach($object->lines as &$line) { |
||
| 602 | if ($line->product_type == 9 && $line->special_code == $this->module_number) { |
||
| 603 | |||
| 604 | if($line->qty>=90) { |
||
| 605 | $line->modsubtotal_total = 1; |
||
| 606 | } |
||
| 607 | else{ |
||
| 608 | $line->modsubtotal_title = 1; |
||
| 609 | } |
||
| 610 | |||
| 611 | $line->total_ht = $this->getTotalLineFromObject($object, $line, ''); |
||
| 612 | } |
||
| 613 | } |
||
| 614 | } |
||
| 615 | |||
| 616 | } |
||
| 617 | else if($action === 'confirm_delete_all_lines' && GETPOST('confirm')=='yes') { |
||
| 618 | |||
| 619 | $Tab = $this->getArrayOfLineForAGroup($object, GETPOST('lineid')); |
||
| 620 | |||
| 621 | foreach($Tab as $idLine) { |
||
| 622 | /** |
||
| 623 | * @var $object Facture |
||
| 624 | */ |
||
| 625 | if($object->element=='facture') $object->deleteline($idLine); |
||
| 626 | /** |
||
| 627 | * @var $object Facture fournisseur |
||
| 628 | */ |
||
| 629 | else if($object->element=='invoice_supplier') |
||
| 630 | { |
||
| 631 | $object->deleteline($idLine); |
||
| 632 | } |
||
| 633 | /** |
||
| 634 | * @var $object Propal |
||
| 635 | */ |
||
| 636 | else if($object->element=='propal') $object->deleteline($idLine); |
||
| 637 | /** |
||
| 638 | * @var $object Propal Fournisseur |
||
| 639 | */ |
||
| 640 | else if($object->element=='supplier_proposal') $object->deleteline($idLine); |
||
| 641 | /** |
||
| 642 | * @var $object Commande |
||
| 643 | */ |
||
| 644 | else if($object->element=='commande') |
||
| 645 | { |
||
| 646 | if ((float) DOL_VERSION >= 5.0) $object->deleteline($user, $idLine); |
||
| 647 | else $object->deleteline($idLine); |
||
| 648 | } |
||
| 649 | /** |
||
| 650 | * @var $object Commande fournisseur |
||
| 651 | */ |
||
| 652 | else if($object->element=='order_supplier') |
||
| 653 | { |
||
| 654 | $object->deleteline($idLine); |
||
| 655 | } |
||
| 656 | /** |
||
| 657 | * @var $object Facturerec |
||
| 658 | */ |
||
| 659 | else if($object->element=='facturerec') $object->deleteline($idLine); |
||
| 660 | } |
||
| 661 | |||
| 662 | header('location:?id='.$object->id); |
||
| 663 | exit; |
||
| 664 | |||
| 665 | } |
||
| 666 | else if ($action == 'duplicate') |
||
| 667 | { |
||
| 668 | $lineid = GETPOST('lineid', 'int'); |
||
| 669 | $nbDuplicate = TSubtotal::duplicateLines($object, $lineid, true); |
||
| 670 | |||
| 671 | if ($nbDuplicate > 0) setEventMessage($langs->trans('subtotal_duplicate_success', $nbDuplicate)); |
||
| 672 | elseif ($nbDuplicate == 0) setEventMessage($langs->trans('subtotal_duplicate_lineid_not_found'), 'warnings'); |
||
| 673 | else setEventMessage($langs->trans('subtotal_duplicate_error'), 'errors'); |
||
| 674 | |||
| 675 | header('Location: ?id='.$object->id); |
||
| 676 | exit; |
||
| 677 | } |
||
| 678 | |||
| 679 | return 0; |
||
| 680 | } |
||
| 681 | |||
| 682 | function formAddObjectLine ($parameters, &$object, &$action, $hookmanager) { |
||
| 683 | return 0; |
||
| 684 | } |
||
| 685 | |||
| 686 | function getArrayOfLineForAGroup(&$object, $lineid) { |
||
| 687 | $rang = $line->rang; |
||
| 688 | $qty_line = $line->qty; |
||
| 689 | |||
| 690 | $qty_line = 0; |
||
| 691 | |||
| 692 | $found = false; |
||
| 693 | |||
| 694 | $Tab= array(); |
||
| 695 | |||
| 696 | foreach($object->lines as $l) { |
||
| 697 | |||
| 698 | $lid = (!empty($l->rowid) ? $l->rowid : $l->id); |
||
| 699 | if($lid == $lineid) { |
||
| 700 | |||
| 701 | $found = true; |
||
| 702 | $qty_line = $l->qty; |
||
| 703 | } |
||
| 704 | |||
| 705 | if($found) { |
||
| 706 | |||
| 707 | $Tab[] = (!empty($l->rowid) ? $l->rowid : $l->id); |
||
| 708 | |||
| 709 | if($l->special_code==$this->module_number && (($l->qty==99 && $qty_line==1) || ($l->qty==98 && $qty_line==2)) ) { |
||
| 710 | break; // end of story |
||
| 711 | } |
||
| 712 | } |
||
| 713 | |||
| 714 | |||
| 715 | } |
||
| 716 | |||
| 717 | |||
| 718 | return $Tab; |
||
| 719 | |||
| 720 | } |
||
| 721 | |||
| 722 | /** |
||
| 723 | * TODO le calcul est faux dans certains cas, exemple : |
||
| 724 | * T1 |
||
| 725 | * |_ l1 => 50 € |
||
| 726 | * |_ l2 => 40 € |
||
| 727 | * |_ T2 |
||
| 728 | * |_l3 => 100 € |
||
| 729 | * |_ ST2 |
||
| 730 | * |_ l4 => 23 € |
||
| 731 | * |_ ST1 |
||
| 732 | * |
||
| 733 | * On obtiens ST2 = 100 ET ST1 = 123 € |
||
| 734 | * Alors qu'on devrais avoir ST2 = 100 ET ST1 = 213 € |
||
| 735 | * |
||
| 736 | * @param $use_level isn't used anymore |
||
| 737 | */ |
||
| 738 | function getTotalLineFromObject(&$object, &$line, $use_level=false, $return_all=0) { |
||
| 773 | } |
||
| 774 | |||
| 775 | /* |
||
| 776 | * Get the sum of situation invoice for last column |
||
| 777 | */ |
||
| 778 | function getTotalToPrintSituation(&$object, &$line) { |
||
| 779 | |||
| 780 | $rang = $line->rang; |
||
| 781 | $total = 0; |
||
| 782 | foreach($object->lines as $l) { |
||
| 783 | if($l->rang>=$rang) { |
||
| 784 | return price($total); |
||
| 785 | } |
||
| 786 | if (TSubtotal::isSubtotal($l)){ |
||
| 787 | $total = 0; |
||
| 788 | } else if ($l->situation_percent > 0 ){ |
||
| 789 | |||
| 790 | |||
| 791 | $prev_progress = $l->get_prev_progress($object->id); |
||
| 792 | $progress = ($l->situation_percent - $prev_progress) /100; |
||
| 793 | $total += ($l->total_ht/($l->situation_percent/100)) * $progress; |
||
| 794 | |||
| 795 | } |
||
| 796 | } |
||
| 797 | |||
| 798 | return price($total); |
||
| 799 | } |
||
| 800 | |||
| 801 | /** |
||
| 802 | * @param $pdf TCPDF PDF object |
||
| 803 | * @param $object CommonObject dolibarr object |
||
| 804 | * @param $line CommonObjectLine dolibarr object line |
||
| 805 | * @param $label string |
||
| 806 | * @param $description string |
||
| 807 | * @param $posx float horizontal position |
||
| 808 | * @param $posy float vertical position |
||
| 809 | * @param $w float width |
||
| 810 | * @param $h float height |
||
| 811 | */ |
||
| 812 | function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) { |
||
| 914 | |||
| 915 | |||
| 916 | } |
||
| 917 | |||
| 918 | /** |
||
| 919 | * @param $pdf TCPDF PDF object |
||
| 920 | * @param $object CommonObject dolibarr object |
||
| 921 | * @param $line CommonObjectLine dolibarr object line |
||
| 922 | * @param $label string |
||
| 923 | * @param $description string |
||
| 924 | * @param $posx float horizontal position |
||
| 925 | * @param $posy float vertical position |
||
| 926 | * @param $w float width |
||
| 927 | * @param $h float height |
||
| 928 | */ |
||
| 929 | function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) { |
||
| 930 | |||
| 931 | global $db,$conf,$subtotal_last_title_posy; |
||
| 932 | |||
| 933 | $subtotal_last_title_posy = $posy; |
||
| 934 | $pdf->SetXY ($posx, $posy); |
||
| 935 | |||
| 936 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 937 | |||
| 938 | |||
| 939 | |||
| 940 | $style = ($line->qty==1) ? 'BU' : 'BUI'; |
||
| 941 | if (!empty($conf->global->SUBTOTAL_TITLE_STYLE)) $style = $conf->global->SUBTOTAL_TITLE_STYLE; |
||
| 942 | |||
| 943 | if($hideInnerLines) { |
||
| 944 | if($line->qty==1)$pdf->SetFont('', $style, 9); |
||
| 945 | else |
||
| 946 | { |
||
| 947 | if (!empty($conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES)) $style = $conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES; |
||
| 948 | $pdf->SetFont('', $style, 9); |
||
| 949 | } |
||
| 950 | } |
||
| 951 | else { |
||
| 952 | |||
| 953 | if($line->qty==1)$pdf->SetFont('', $style, 9); //TODO if super utile |
||
| 954 | else $pdf->SetFont('', $style, 9); |
||
| 955 | |||
| 956 | } |
||
| 957 | |||
| 958 | 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 |
||
| 959 | else $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'J',true); // et maintenant avec du HTML |
||
| 960 | |||
| 961 | if($description && !$hidedesc) { |
||
| 962 | $posy = $pdf->GetY(); |
||
| 963 | |||
| 964 | $pdf->SetFont('', '', 8); |
||
| 965 | |||
| 966 | $pdf->writeHTMLCell($w, $h, $posx, $posy, $description, 0, 1, false, true, 'J',true); |
||
| 967 | |||
| 968 | } |
||
| 969 | |||
| 970 | } |
||
| 971 | |||
| 972 | function pdf_writelinedesc_ref($parameters=array(), &$object, &$action='') { |
||
| 973 | // ultimate PDF hook O_o |
||
| 974 | |||
| 975 | return $this->pdf_writelinedesc($parameters,$object,$action); |
||
| 976 | |||
| 977 | } |
||
| 978 | |||
| 979 | function isModSubtotalLine(&$parameters, &$object) { |
||
| 994 | |||
| 995 | } |
||
| 996 | |||
| 997 | function pdf_getlineqty($parameters=array(), &$object, &$action='') { |
||
| 998 | global $conf,$hideprices; |
||
| 999 | |||
| 1000 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1001 | |||
| 1002 | $this->resprints = ' '; |
||
| 1003 | |||
| 1004 | if((float)DOL_VERSION<=3.6) { |
||
| 1005 | return ''; |
||
| 1006 | } |
||
| 1007 | else if((float)DOL_VERSION>=3.8) { |
||
| 1008 | return 1; |
||
| 1009 | } |
||
| 1010 | |||
| 1011 | } |
||
| 1012 | elseif(!empty($hideprices)) { |
||
| 1013 | $this->resprints = $object->lines[$parameters['i']]->qty; |
||
| 1014 | return 1; |
||
| 1015 | } |
||
| 1016 | elseif (!empty($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY)) |
||
| 1017 | { |
||
| 1018 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 1019 | $hidedetails = (int)GETPOST('hidedetails'); |
||
| 1020 | if (empty($hideInnerLines) && !empty($hidedetails)) |
||
| 1021 | { |
||
| 1022 | $this->resprints = $object->lines[$parameters['i']]->qty; |
||
| 1023 | } |
||
| 1024 | } |
||
| 1025 | |||
| 1026 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1027 | else $i = (int)$parameters; |
||
| 1028 | |||
| 1029 | 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) |
||
| 1030 | |||
| 1031 | if(empty($object->lines[$i]->array_options)) $object->lines[$i]->fetch_optionals(); |
||
| 1032 | |||
| 1033 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1034 | { |
||
| 1035 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1036 | { |
||
| 1037 | $this->resprints = ' '; |
||
| 1038 | return 1; |
||
| 1039 | } |
||
| 1040 | } |
||
| 1041 | |||
| 1042 | return 0; |
||
| 1043 | } |
||
| 1044 | |||
| 1045 | function pdf_getlinetotalexcltax($parameters=array(), &$object, &$action='') { |
||
| 1046 | global $conf, $hideprices; |
||
| 1047 | |||
| 1048 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1049 | |||
| 1050 | $this->resprints = ' '; |
||
| 1051 | |||
| 1052 | if((float)DOL_VERSION<=3.6) { |
||
| 1053 | return ''; |
||
| 1054 | } |
||
| 1055 | else if((float)DOL_VERSION>=3.8) { |
||
| 1056 | return 1; |
||
| 1057 | } |
||
| 1058 | |||
| 1059 | } |
||
| 1060 | elseif (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS)) |
||
| 1061 | { |
||
| 1062 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1063 | else $i = (int)$parameters; |
||
| 1064 | |||
| 1065 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1066 | { |
||
| 1067 | if (!empty($object->lines[$i]->array_options['options_subtotal_nc'])) |
||
| 1068 | { |
||
| 1069 | $this->resprints = ' '; |
||
| 1070 | return 1; |
||
| 1071 | } |
||
| 1072 | |||
| 1073 | $TTitle = TSubtotal::getAllTitleFromLine($object->lines[$i]); |
||
| 1074 | foreach ($TTitle as &$line_title) |
||
| 1075 | { |
||
| 1076 | if (!empty($line_title->array_options['options_subtotal_nc'])) |
||
| 1077 | { |
||
| 1078 | $this->resprints = ' '; |
||
| 1079 | return 1; |
||
| 1080 | } |
||
| 1081 | } |
||
| 1082 | } |
||
| 1083 | } |
||
| 1084 | if ((int)GETPOST('hideInnerLines') && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)){ |
||
| 1085 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1086 | else $i = (int)$parameters; |
||
| 1087 | $this->resprints = price($object->lines[$i]->total_ht); |
||
| 1088 | } |
||
| 1089 | if (!empty($hideprices) |
||
| 1090 | || (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1091 | ) |
||
| 1092 | { |
||
| 1093 | if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1094 | { |
||
| 1095 | $this->resprints = ' '; |
||
| 1096 | return 1; |
||
| 1097 | } |
||
| 1098 | } |
||
| 1099 | |||
| 1100 | return 0; |
||
| 1101 | } |
||
| 1102 | |||
| 1103 | function pdf_getlinetotalwithtax($parameters=array(), &$object, &$action='') { |
||
| 1104 | global $conf; |
||
| 1105 | |||
| 1106 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1107 | |||
| 1108 | $this->resprints = ' '; |
||
| 1109 | |||
| 1110 | if((float)DOL_VERSION<=3.6) { |
||
| 1111 | return ''; |
||
| 1112 | } |
||
| 1113 | else if((float)DOL_VERSION>=3.8) { |
||
| 1114 | return 1; |
||
| 1115 | } |
||
| 1116 | } |
||
| 1117 | |||
| 1118 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1119 | else $i = (int)$parameters; |
||
| 1120 | |||
| 1121 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1122 | { |
||
| 1123 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1124 | { |
||
| 1125 | $this->resprints = ' '; |
||
| 1126 | return 1; |
||
| 1127 | } |
||
| 1128 | } |
||
| 1129 | |||
| 1130 | return 0; |
||
| 1131 | } |
||
| 1132 | |||
| 1133 | function pdf_getlineunit($parameters=array(), &$object, &$action='') { |
||
| 1134 | global $conf; |
||
| 1135 | |||
| 1136 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1137 | $this->resprints = ' '; |
||
| 1138 | |||
| 1139 | if((float)DOL_VERSION<=3.6) { |
||
| 1140 | return ''; |
||
| 1141 | } |
||
| 1142 | else if((float)DOL_VERSION>=3.8) { |
||
| 1143 | return 1; |
||
| 1144 | } |
||
| 1145 | } |
||
| 1146 | |||
| 1147 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1148 | else $i = (int)$parameters; |
||
| 1149 | |||
| 1150 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1151 | { |
||
| 1152 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1153 | { |
||
| 1154 | $this->resprints = ' '; |
||
| 1155 | return 1; |
||
| 1156 | } |
||
| 1157 | } |
||
| 1158 | |||
| 1159 | return 0; |
||
| 1160 | } |
||
| 1161 | |||
| 1162 | function pdf_getlineupexcltax($parameters=array(), &$object, &$action='') { |
||
| 1163 | global $conf,$hideprices; |
||
| 1164 | |||
| 1165 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1166 | $this->resprints = ' '; |
||
| 1167 | |||
| 1168 | if((float)DOL_VERSION<=3.6) { |
||
| 1169 | return ''; |
||
| 1170 | } |
||
| 1171 | else if((float)DOL_VERSION>=3.8) { |
||
| 1172 | return 1; |
||
| 1173 | } |
||
| 1174 | } |
||
| 1175 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1176 | else $i = (int)$parameters; |
||
| 1177 | |||
| 1178 | if (!empty($hideprices) |
||
| 1179 | || (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1180 | ) |
||
| 1181 | { |
||
| 1182 | if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1183 | { |
||
| 1184 | $this->resprints = ' '; |
||
| 1185 | return 1; |
||
| 1186 | } |
||
| 1187 | } |
||
| 1188 | |||
| 1189 | return 0; |
||
| 1190 | } |
||
| 1191 | |||
| 1192 | function pdf_getlineupwithtax($parameters=array(), &$object, &$action='') { |
||
| 1193 | global $conf,$hideprices; |
||
| 1194 | |||
| 1195 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1196 | $this->resprints = ' '; |
||
| 1197 | if((float)DOL_VERSION<=3.6) { |
||
| 1198 | return ''; |
||
| 1199 | } |
||
| 1200 | else if((float)DOL_VERSION>=3.8) { |
||
| 1201 | return 1; |
||
| 1202 | } |
||
| 1203 | } |
||
| 1204 | |||
| 1205 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1206 | else $i = (int)$parameters; |
||
| 1207 | |||
| 1208 | if (!empty($hideprices) |
||
| 1209 | || (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1210 | ) |
||
| 1211 | { |
||
| 1212 | if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1213 | { |
||
| 1214 | $this->resprints = ' '; |
||
| 1215 | return 1; |
||
| 1216 | } |
||
| 1217 | } |
||
| 1218 | |||
| 1219 | return 0; |
||
| 1220 | } |
||
| 1221 | |||
| 1222 | function pdf_getlinevatrate($parameters=array(), &$object, &$action='') { |
||
| 1223 | global $conf; |
||
| 1224 | |||
| 1225 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1226 | $this->resprints = ' '; |
||
| 1227 | |||
| 1228 | if((float)DOL_VERSION<=3.6) { |
||
| 1229 | return ''; |
||
| 1230 | } |
||
| 1231 | else if((float)DOL_VERSION>=3.8) { |
||
| 1232 | return 1; |
||
| 1233 | } |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1237 | else $i = (int)$parameters; |
||
| 1238 | |||
| 1239 | 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) |
||
| 1240 | |||
| 1241 | $object->lines[$i]->fetch_optionals(); |
||
| 1242 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1243 | { |
||
| 1244 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1245 | { |
||
| 1246 | $this->resprints = ' '; |
||
| 1247 | return 1; |
||
| 1248 | } |
||
| 1249 | } |
||
| 1250 | |||
| 1251 | return 0; |
||
| 1252 | } |
||
| 1253 | |||
| 1254 | function pdf_getlineprogress($parameters=array(), &$object, &$action) { |
||
| 1255 | global $conf; |
||
| 1256 | |||
| 1257 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1258 | $this->resprints = ' '; |
||
| 1259 | if((float)DOL_VERSION<=3.6) { |
||
| 1260 | return ''; |
||
| 1261 | } |
||
| 1262 | else if((float)DOL_VERSION>=3.8) { |
||
| 1263 | return 1; |
||
| 1264 | } |
||
| 1265 | } |
||
| 1266 | |||
| 1267 | if(is_array($parameters)) $i = & $parameters['i']; |
||
| 1268 | else $i = (int)$parameters; |
||
| 1269 | |||
| 1270 | if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) |
||
| 1271 | { |
||
| 1272 | if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC))) |
||
| 1273 | { |
||
| 1274 | $this->resprints = ' '; |
||
| 1275 | return 1; |
||
| 1276 | } |
||
| 1277 | } |
||
| 1278 | |||
| 1279 | return 0; |
||
| 1280 | } |
||
| 1281 | |||
| 1282 | function add_numerotation(&$object) { |
||
| 1283 | global $conf; |
||
| 1284 | |||
| 1285 | if(!empty($conf->global->SUBTOTAL_USE_NUMEROTATION)) { |
||
| 1286 | |||
| 1287 | $TLevelTitre = array(); |
||
| 1288 | $prevlevel = 0; |
||
| 1289 | |||
| 1290 | foreach($object->lines as $k=>&$line) |
||
| 1291 | { |
||
| 1292 | if ($line->id > 0 && $this->isModSubtotalLine($k, $object) && $line->qty <= 10) |
||
| 1293 | { |
||
| 1294 | $TLineTitle[] = &$line; |
||
| 1295 | } |
||
| 1296 | } |
||
| 1297 | |||
| 1298 | if (!empty($TLineTitle)) $TTitleNumeroted = $this->formatNumerotation($TLineTitle); |
||
| 1299 | } |
||
| 1300 | |||
| 1301 | } |
||
| 1302 | |||
| 1303 | // TODO ne gère pas encore la numération des lignes "Totaux" |
||
| 1304 | private function formatNumerotation(&$TLineTitle, $line_reference='', $level=1, $prefix_num=0) |
||
| 1305 | { |
||
| 1306 | $TTitle = array(); |
||
| 1307 | |||
| 1308 | $i=1; |
||
| 1309 | $j=0; |
||
| 1310 | foreach ($TLineTitle as $k => &$line) |
||
| 1311 | { |
||
| 1312 | if (!empty($line_reference) && $line->rang <= $line_reference->rang) continue; |
||
| 1313 | if (!empty($line_reference) && $line->qty <= $line_reference->qty) break; |
||
| 1314 | |||
| 1315 | if ($line->qty == $level) |
||
| 1316 | { |
||
| 1317 | $TTitle[$j]['numerotation'] = ($prefix_num == 0) ? $i : $prefix_num.'.'.$i; |
||
| 1318 | //var_dump('Prefix == '.$prefix_num.' // '.$line->desc.' ==> numerotation == '.$TTitle[$j]['numerotation'].' ### '.$line->qty .'=='. $level); |
||
| 1319 | if (empty($line->label) && (float)DOL_VERSION < 6) |
||
| 1320 | { |
||
| 1321 | $line->label = !empty($line->desc) ? $line->desc : $line->description; |
||
| 1322 | $line->desc = $line->description = ''; |
||
| 1323 | } |
||
| 1324 | |||
| 1325 | $line->label = $TTitle[$j]['numerotation'].' '.$line->label; |
||
| 1326 | $TTitle[$j]['line'] = &$line; |
||
| 1327 | |||
| 1328 | $deep_level = $line->qty; |
||
| 1329 | do { |
||
| 1330 | $deep_level++; |
||
| 1331 | $TTitle[$j]['children'] = $this->formatNumerotation($TLineTitle, $line, $deep_level, $TTitle[$j]['numerotation']); |
||
| 1332 | } 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 |
||
| 1333 | // Rappel on peux avoir jusqu'a 10 niveau de titre |
||
| 1334 | |||
| 1335 | $i++; |
||
| 1336 | $j++; |
||
| 1337 | } |
||
| 1338 | } |
||
| 1339 | |||
| 1340 | return $TTitle; |
||
| 1341 | } |
||
| 1342 | |||
| 1343 | function setDocTVA(&$pdf, &$object) { |
||
| 1344 | |||
| 1345 | $hidedetails = (int)GETPOST('hidedetails'); |
||
| 1346 | |||
| 1347 | if(empty($hidedetails)) return false; |
||
| 1348 | |||
| 1349 | // TODO can't add VAT to document without lines... :-/ |
||
| 1350 | |||
| 1351 | return true; |
||
| 1352 | } |
||
| 1353 | |||
| 1354 | function beforePDFCreation($parameters=array(), &$object, &$action) |
||
| 1355 | { |
||
| 1356 | /** |
||
| 1357 | * @var $pdf TCPDF |
||
| 1358 | */ |
||
| 1359 | global $pdf,$conf, $langs; |
||
| 1360 | |||
| 1361 | // var_dump($object->lines); |
||
| 1362 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 1363 | |||
| 1364 | foreach($parameters as $key=>$value) { |
||
| 1365 | ${$key} = $value; |
||
| 1366 | } |
||
| 1367 | |||
| 1368 | $this->setDocTVA($pdf, $object); |
||
| 1369 | |||
| 1370 | $this->add_numerotation($object); |
||
| 1371 | |||
| 1372 | |||
| 1373 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 1374 | $hidedetails = (int)GETPOST('hidedetails'); |
||
| 1375 | |||
| 1376 | if ($hideInnerLines) { // si c une ligne de titre |
||
| 1377 | $fk_parent_line=0; |
||
| 1378 | $TLines =array(); |
||
| 1379 | |||
| 1380 | $original_count=count($object->lines); |
||
| 1381 | $TTvas = array(); // tableau de tva |
||
| 1382 | |||
| 1383 | foreach($object->lines as $k=>&$line) |
||
| 1384 | { |
||
| 1385 | |||
| 1386 | if($line->product_type==9 && $line->rowid>0) |
||
| 1387 | { |
||
| 1388 | $fk_parent_line = $line->rowid; |
||
| 1389 | |||
| 1390 | // 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 |
||
| 1391 | if(TSubtotal::isSubtotal($line)) |
||
| 1392 | { |
||
| 1393 | /*$total = $this->getTotalLineFromObject($object, $line, ''); |
||
| 1394 | |||
| 1395 | $line->total_ht = $total; |
||
| 1396 | $line->total = $total; |
||
| 1397 | */ |
||
| 1398 | list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1); |
||
| 1399 | |||
| 1400 | if (TSubtotal::getNiveau($line) == 1) $line->TTotal_tva = $TTotal_tva; |
||
| 1401 | $line->total_ht = $total; |
||
| 1402 | $line->total_tva = $total_tva; |
||
| 1403 | $line->total = $line->total_ht; |
||
| 1404 | $line->total_ttc = $total_ttc; |
||
| 1405 | } |
||
| 1406 | |||
| 1407 | } |
||
| 1408 | |||
| 1409 | if ($hideInnerLines) |
||
| 1410 | { |
||
| 1411 | if(!empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)) |
||
| 1412 | { |
||
| 1413 | if($line->tva_tx != '0.000' && $line->product_type!=9){ |
||
| 1414 | |||
| 1415 | // on remplit le tableau de tva pour substituer les lignes cachées |
||
| 1416 | $TTvas[$line->tva_tx]['total_tva'] += $line->total_tva; |
||
| 1417 | $TTvas[$line->tva_tx]['total_ht'] += $line->total_ht; |
||
| 1418 | $TTvas[$line->tva_tx]['total_ttc'] += $line->total_ttc; |
||
| 1419 | } |
||
| 1420 | if($line->product_type==9 && $line->rowid>0) |
||
| 1421 | { |
||
| 1422 | //Cas où je doit cacher les produits et afficher uniquement les sous-totaux avec les titres |
||
| 1423 | // génère des lignes d'affichage des montants HT soumis à tva |
||
| 1424 | $nbtva = count($TTvas); |
||
| 1425 | if(!empty($nbtva)){ |
||
| 1426 | foreach ($TTvas as $tx =>$val){ |
||
| 1427 | $l = clone $line; |
||
| 1428 | $l->product_type = 1; |
||
| 1429 | $l->special_code = ''; |
||
| 1430 | $l->qty = 1; |
||
| 1431 | $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx)); |
||
| 1432 | $l->tva_tx = $tx; |
||
| 1433 | $l->total_ht = $val['total_ht']; |
||
| 1434 | $l->total_tva = $val['total_tva']; |
||
| 1435 | $l->total = $line->total_ht; |
||
| 1436 | $l->total_ttc = $val['total_ttc']; |
||
| 1437 | $TLines[] = $l; |
||
| 1438 | array_shift($TTvas); |
||
| 1439 | } |
||
| 1440 | } |
||
| 1441 | |||
| 1442 | // ajoute la ligne de sous-total |
||
| 1443 | $TLines[] = $line; |
||
| 1444 | } |
||
| 1445 | } else { |
||
| 1446 | |||
| 1447 | if($line->product_type==9 && $line->rowid>0) |
||
| 1448 | { |
||
| 1449 | // ajoute la ligne de sous-total |
||
| 1450 | $TLines[] = $line; |
||
| 1451 | } |
||
| 1452 | } |
||
| 1453 | |||
| 1454 | |||
| 1455 | } |
||
| 1456 | elseif ($hidedetails) |
||
| 1457 | { |
||
| 1458 | $TLines[] = $line; //Cas où je cache uniquement les prix des produits |
||
| 1459 | } |
||
| 1460 | |||
| 1461 | if ($line->product_type != 9) { // jusqu'au prochain titre ou total |
||
| 1462 | //$line->fk_parent_line = $fk_parent_line; |
||
| 1463 | |||
| 1464 | } |
||
| 1465 | |||
| 1466 | /*if($hideTotal) { |
||
| 1467 | $line->total = 0; |
||
| 1468 | $line->subprice= 0; |
||
| 1469 | }*/ |
||
| 1470 | |||
| 1471 | } |
||
| 1472 | |||
| 1473 | // cas incongru où il y aurait des produits en dessous du dernier sous-total |
||
| 1474 | $nbtva = count($TTvas); |
||
| 1475 | if(!empty($nbtva) && $hideInnerLines && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)) |
||
| 1476 | { |
||
| 1477 | foreach ($TTvas as $tx =>$val){ |
||
| 1478 | $l = clone $line; |
||
| 1479 | $l->product_type = 1; |
||
| 1480 | $l->special_code = ''; |
||
| 1481 | $l->qty = 1; |
||
| 1482 | $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx)); |
||
| 1483 | $l->tva_tx = $tx; |
||
| 1484 | $l->total_ht = $val['total_ht']; |
||
| 1485 | $l->total_tva = $val['total_tva']; |
||
| 1486 | $l->total = $line->total_ht; |
||
| 1487 | $l->total_ttc = $val['total_ttc']; |
||
| 1488 | $TLines[] = $l; |
||
| 1489 | array_shift($TTvas); |
||
| 1490 | } |
||
| 1491 | } |
||
| 1492 | |||
| 1493 | global $nblignes; |
||
| 1494 | $nblignes=count($TLines); |
||
| 1495 | |||
| 1496 | $object->lines = $TLines; |
||
| 1497 | |||
| 1498 | if($i>count($object->lines)) { |
||
| 1499 | $this->resprints = ''; |
||
| 1500 | return 0; |
||
| 1501 | } |
||
| 1502 | } |
||
| 1503 | |||
| 1504 | return 0; |
||
| 1505 | } |
||
| 1506 | |||
| 1507 | function pdf_writelinedesc($parameters=array(), &$object, &$action) |
||
| 1508 | { |
||
| 1509 | /** |
||
| 1510 | * @var $pdf TCPDF |
||
| 1511 | */ |
||
| 1512 | global $pdf,$conf; |
||
| 1513 | |||
| 1514 | foreach($parameters as $key=>$value) { |
||
| 1515 | ${$key} = $value; |
||
| 1516 | } |
||
| 1517 | |||
| 1518 | $hideInnerLines = (int)GETPOST('hideInnerLines'); |
||
| 1519 | $hidedetails = (int)GETPOST('hidedetails'); |
||
| 1520 | |||
| 1521 | if($this->isModSubtotalLine($parameters,$object) ){ |
||
| 1522 | |||
| 1523 | global $hideprices; |
||
| 1524 | |||
| 1525 | if(!empty($hideprices)) { |
||
| 1526 | foreach($object->lines as &$line) { |
||
| 1527 | if($line->fk_product_type!=9) $line->fk_parent_line = -1; |
||
| 1528 | } |
||
| 1529 | } |
||
| 1530 | |||
| 1531 | $line = &$object->lines[$i]; |
||
| 1532 | |||
| 1533 | if($line->info_bits>0) { // PAGE BREAK |
||
| 1534 | $pdf->addPage(); |
||
| 1535 | $posy = $pdf->GetY(); |
||
| 1536 | } |
||
| 1537 | |||
| 1538 | $label = $line->label; |
||
| 1539 | $description= !empty($line->desc) ? $outputlangs->convToOutputCharset($line->desc) : $outputlangs->convToOutputCharset($line->description); |
||
| 1540 | |||
| 1541 | if(empty($label)) { |
||
| 1542 | $label = $description; |
||
| 1543 | $description=''; |
||
| 1544 | } |
||
| 1545 | |||
| 1546 | if($line->qty>90) { |
||
| 1547 | |||
| 1548 | if ($conf->global->SUBTOTAL_USE_NEW_FORMAT) $label .= ' '.$this->getTitle($object, $line); |
||
| 1549 | |||
| 1550 | $pageBefore = $pdf->getPage(); |
||
| 1551 | $this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); |
||
| 1552 | $pageAfter = $pdf->getPage(); |
||
| 1553 | |||
| 1554 | if($pageAfter>$pageBefore) { |
||
| 1555 | //print "ST $pageAfter>$pageBefore<br>"; |
||
| 1556 | $pdf->rollbackTransaction(true); |
||
| 1557 | $pdf->addPage('','', true); |
||
| 1558 | $posy = $pdf->GetY(); |
||
| 1559 | $this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); |
||
| 1560 | $posy = $pdf->GetY(); |
||
| 1561 | //print 'add ST'.$pdf->getPage().'<br />'; |
||
| 1562 | } |
||
| 1563 | |||
| 1564 | $posy = $pdf->GetY(); |
||
| 1565 | return 1; |
||
| 1566 | } |
||
| 1567 | else if ($line->qty < 10) { |
||
| 1568 | $pageBefore = $pdf->getPage(); |
||
| 1569 | |||
| 1570 | $this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); |
||
| 1571 | $pageAfter = $pdf->getPage(); |
||
| 1572 | |||
| 1573 | |||
| 1574 | /*if($pageAfter>$pageBefore) { |
||
| 1575 | print "T $pageAfter>$pageBefore<br>"; |
||
| 1576 | $pdf->rollbackTransaction(true); |
||
| 1577 | $pdf->addPage('','', true); |
||
| 1578 | print 'add T'.$pdf->getPage().' '.$line->rowid.' '.$pdf->GetY().' '.$posy.'<br />'; |
||
| 1579 | |||
| 1580 | $posy = $pdf->GetY(); |
||
| 1581 | $this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); |
||
| 1582 | $posy = $pdf->GetY(); |
||
| 1583 | } |
||
| 1584 | */ |
||
| 1585 | $posy = $pdf->GetY(); |
||
| 1586 | return 1; |
||
| 1587 | } |
||
| 1588 | // if($line->rowid==47) exit; |
||
| 1589 | |||
| 1590 | return 0; |
||
| 1591 | } |
||
| 1592 | elseif (empty($object->lines[$parameters['i']])) |
||
| 1593 | { |
||
| 1594 | $this->resprints = -1; |
||
| 1595 | } |
||
| 1596 | |||
| 1597 | /* TODO je desactive parce que je comprends pas PH Style, mais à test |
||
| 1598 | else { |
||
| 1599 | |||
| 1600 | if($hideInnerLines) { |
||
| 1601 | $pdf->rollbackTransaction(true); |
||
| 1602 | } |
||
| 1603 | else { |
||
| 1604 | $labelproductservice=pdf_getlinedesc($object, $i, $outputlangs, $hideref, $hidedesc, $issupplierline); |
||
| 1605 | $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1); |
||
| 1606 | } |
||
| 1607 | |||
| 1608 | }*/ |
||
| 1609 | |||
| 1610 | |||
| 1611 | |||
| 1612 | } |
||
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Permet de récupérer le titre lié au sous-total |
||
| 1616 | * |
||
| 1617 | * @return string |
||
| 1618 | */ |
||
| 1619 | function getTitle(&$object, &$currentLine) |
||
| 1620 | { |
||
| 1621 | $res = ''; |
||
| 1622 | |||
| 1623 | foreach ($object->lines as $line) |
||
| 1624 | { |
||
| 1625 | if ($line->id == $currentLine->id) break; |
||
| 1626 | |||
| 1627 | $qty_search = 100 - $currentLine->qty; |
||
| 1628 | |||
| 1629 | if ($line->product_type == 9 && $line->special_code == $this->module_number && $line->qty == $qty_search) |
||
| 1630 | { |
||
| 1631 | $res = ($line->label) ? $line->label : (($line->description) ? $line->description : $line->desc); |
||
| 1632 | } |
||
| 1633 | } |
||
| 1634 | |||
| 1635 | return $res; |
||
| 1636 | } |
||
| 1637 | |||
| 1638 | /** |
||
| 1639 | * @param $parameters array |
||
| 1640 | * @param $object CommonObject |
||
| 1641 | * @param $action string |
||
| 1642 | * @param $hookmanager HookManager |
||
| 1643 | * @return int |
||
| 1644 | */ |
||
| 1645 | function printObjectLine ($parameters, &$object, &$action, $hookmanager){ |
||
| 2063 | |||
| 2064 | } |
||
| 2065 | |||
| 2066 | |||
| 2067 | function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager) { |
||
| 2068 | global $conf,$langs; |
||
| 2069 | |||
| 2070 | if ($object->statut == 0 && !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && $action != 'editline') |
||
| 2071 | { |
||
| 2072 | $TSubNc = array(); |
||
| 2073 | foreach ($object->lines as &$l) |
||
| 2074 | { |
||
| 2075 | $TSubNc[$l->id] = (int) $l->array_options['options_subtotal_nc']; |
||
| 2076 | } |
||
| 2077 | |||
| 2078 | $form = new Form($db); |
||
| 2079 | ?> |
||
| 2080 | <script type="text/javascript"> |
||
| 2081 | $(function() { |
||
| 2082 | var subtotal_TSubNc = <?php echo json_encode($TSubNc); ?>; |
||
| 2083 | $("#tablelines tbody > tr").each(function(i, item) { |
||
| 2084 | if ($(item).children('.subtotal_nc').length == 0) |
||
| 2085 | { |
||
| 2086 | var id = $(item).attr('id'); |
||
| 2087 | |||
| 2088 | if ((typeof id != 'undefined' && id.indexOf('row-') >= 0) || $(item).hasClass('liste_titre')) |
||
| 2089 | { |
||
| 2090 | $(item).children('td:last-child').before('<td class="subtotal_nc"></td>'); |
||
| 2091 | |||
| 2092 | if ($(item).attr('rel') != 'subtotal' && typeof $(item).attr('id') != 'undefined') |
||
| 2093 | { |
||
| 2094 | var idSplit = $(item).attr('id').split('-'); |
||
| 2095 | $(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"' : '')+' />')); |
||
| 2096 | } |
||
| 2097 | } |
||
| 2098 | else |
||
| 2099 | { |
||
| 2100 | $(item).append('<td class="subtotal_nc"></td>'); |
||
| 2101 | } |
||
| 2102 | } |
||
| 2103 | }); |
||
| 2104 | |||
| 2105 | $('#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'))); ?>); |
||
| 2106 | |||
| 2107 | function callAjaxUpdateLineNC(set, lineid, subtotal_nc) |
||
| 2108 | { |
||
| 2109 | $.ajax({ |
||
| 2110 | url: '<?php echo dol_buildpath('/subtotal/script/interface.php', 1); ?>' |
||
| 2111 | ,type: 'POST' |
||
| 2112 | ,data: { |
||
| 2113 | json:1 |
||
| 2114 | ,set: set |
||
| 2115 | ,element: '<?php echo $object->element; ?>' |
||
| 2116 | ,elementid: <?php echo (int) $object->id; ?> |
||
| 2117 | ,lineid: lineid |
||
| 2118 | ,subtotal_nc: subtotal_nc |
||
| 2119 | } |
||
| 2120 | }).done(function(response) { |
||
| 2121 | window.location.href = window.location.pathname + '?id=<?php echo $object->id; ?>&page_y=' + window.pageYOffset; |
||
| 2122 | }); |
||
| 2123 | } |
||
| 2124 | |||
| 2125 | $(".subtotal_nc_chkbx").change(function(event) { |
||
| 2126 | var lineid = $(this).data('lineid'); |
||
| 2127 | var subtotal_nc = 0 | $(this).is(':checked'); // Renvoi 0 ou 1 |
||
| 2128 | |||
| 2129 | callAjaxUpdateLineNC('updateLineNC', lineid, subtotal_nc); |
||
| 2130 | }); |
||
| 2131 | |||
| 2132 | }); |
||
| 2133 | |||
| 2134 | </script> |
||
| 2135 | <?php |
||
| 2136 | } |
||
| 2137 | |||
| 2138 | $this->_ajax_block_order_js($object); |
||
| 2139 | } |
||
| 2140 | |||
| 2141 | function afterPDFCreation($parameters, &$pdf, &$action, $hookmanager) |
||
| 2152 | } |
||
| 2153 | } |
||
| 2154 | } |
||
| 2155 | |||
| 2156 | // HTML 5 data for js |
||
| 2157 | private function _getHtmlData($parameters, &$object, &$action, $hookmanager) |
||
| 2158 | { |
||
| 2159 | dol_include_once('/subtotal/class/subtotal.class.php'); |
||
| 2160 | |||
| 2161 | $line = &$parameters['line']; |
||
| 2162 | |||
| 2163 | $ThtmlData['data-id'] = $line->id; |
||
| 2164 | $ThtmlData['data-product_type'] = $line->product_type; |
||
| 2165 | $ThtmlData['data-qty'] = 0; //$line->qty; |
||
| 2166 | $ThtmlData['data-level'] = TSubtotal::getNiveau($line); |
||
| 2167 | |||
| 2168 | if(TSubtotal::isTitle($line)){ |
||
| 2169 | $ThtmlData['data-issubtotal'] = 'title'; |
||
| 2170 | }elseif(TSubtotal::isSubtotal($line)){ |
||
| 2171 | $ThtmlData['data-issubtotal'] = 'subtotal'; |
||
| 2172 | } |
||
| 2173 | else{ |
||
| 2174 | $ThtmlData['data-issubtotal'] = 'freetext'; |
||
| 2175 | } |
||
| 2176 | |||
| 2177 | |||
| 2178 | // Change or add data from hooks |
||
| 2179 | $parameters = array_replace($parameters , array( 'ThtmlData' => $ThtmlData ) ); |
||
| 2180 | |||
| 2181 | // hook |
||
| 2182 | $reshook = $hookmanager->executeHooks('subtotalLineHtmlData',$parameters,$object,$action); // Note that $action and $object may have been modified by hook |
||
| 2183 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 2184 | if ($reshook>0) |
||
| 2185 | { |
||
| 2186 | $ThtmlData = $hookmanager->resArray; |
||
| 2187 | } |
||
| 2188 | |||
| 2189 | return $this->implodeHtmlData($ThtmlData); |
||
| 2190 | |||
| 2191 | } |
||
| 2192 | |||
| 2193 | |||
| 2194 | function implodeHtmlData($ThtmlData = array()) |
||
| 2208 | } |
||
| 2209 | |||
| 2210 | function _ajax_block_order_js($object) |
||
| 2211 | { |
||
| 2212 | global $conf,$tagidfortablednd,$filepath,$langs; |
||
| 2213 | |||
| 2321 | function getSubtotalTitleChilds(item) |
||
| 2322 | { |
||
| 2323 | var TcurrentChilds = []; // = JSON.parse(item.attr('data-childrens')); |
||
| 2324 | var level = item.data('level'); |
||
| 2325 | |||
| 2326 | var indexOfFirstSubtotal = -1; |
||
| 2391 |
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.