* Copyright (C) 2010-2011 Laurent Destailleur * Copyright (C) 2012-2013 Christophe Battarel * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2013 Florian Henry * Copyright (C) 2017 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Need to have following variables defined: * $object (invoice, order, ...) * $conf * $langs * $forceall (0 by default, 1 for supplier invoices/orders) * $element (used to test $user->hasRight($element, 'creer')) * $permtoedit (used to replace test $user->hasRight($element, 'creer')) * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) * $object_rights->creer initialized from = $object->getRights() * $disableedit, $disablemove, $disableremove * * $type, $text, $description, $line */ /** var ObjectLine $line */ require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php'; // Protection to avoid direct call of template if (empty($object) || !is_object($object)) { print "Error, template page can't be called as URL"; exit; } '@phan-var-force CommonObject $this @phan-var-force CommonObject $object'; global $filtertype; if (empty($filtertype)) { $filtertype = 0; } global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax, $langs; if (empty($dateSelector)) { $dateSelector = 0; } if (empty($forceall)) { $forceall = 0; } if (empty($senderissupplier)) { $senderissupplier = 0; } if (empty($inputalsopricewithtax)) { $inputalsopricewithtax = 0; } if (empty($outputalsopricetotalwithtax)) { $outputalsopricetotalwithtax = 0; } // add html5 elements if ($filtertype == 1) { $domData = ' data-element="'.$line->element.'service"'; } else { $domData = ' data-element="'.$line->element.'"'; } $domData .= ' data-id="'.$line->id.'"'; $domData .= ' data-qty="'.$line->qty.'"'; $domData .= ' data-product_type="'.$line->product_type.'"'; // Lines for extrafield $objectline = new BOMLine($object->db); $coldisplay = 0; print "\n"; print ''; // Line nb if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { print ''.($i + 1).''; $coldisplay++; } // Product print ''; print '
'; $coldisplay++; $tmpproduct = new Product($object->db); $tmpproduct->fetch($line->fk_product); $tmpbom = new BOM($object->db); $res = $tmpbom->fetch($line->fk_bom_child); if ($tmpbom->id > 0) { print $tmpproduct->getNomUrl(1); print ' '.$langs->trans("or").' '; print $tmpbom->getNomUrl(1); print ' '; print(!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT') ? img_picto('', 'folder') : img_picto('', 'folder-open')); print ''; } else { print $tmpproduct->getNomUrl(1); print ' - '.$tmpproduct->label; } // Line extrafield if (!empty($extrafields)) { $temps = $line->showOptionals($extrafields, 'view', array(), '', '', 1, 'line'); if (!empty($temps)) { print '
'; print $temps; print '
'; } } print ''; // Qty print ''; $coldisplay++; echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formatting role of function price print ''; if ($filtertype != 1) { if (getDolGlobalInt('PRODUCT_USE_UNITS')) { print ''; $label = measuringUnitString($line->fk_unit, '', '', 1); if ($label !== '') { print $langs->trans($label); } print ''; } print ''; $coldisplay++; echo $line->qty_frozen ? yn($line->qty_frozen) : ''; print ''; print ''; $coldisplay++; echo $line->disable_stock_change ? yn($line->disable_stock_change) : ''; // Yes, it is a quantity, not a price, but we just want the formatting role of function price print ''; print ''; $coldisplay++; echo $line->efficiency; print ''; } else { // Unit print ''; $coldisplay++; if (!empty($line->fk_unit)) { require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php'; $unit = new CUnits($this->db); $unit->fetch($line->fk_unit); print(isset($unit->label) ? " ".$langs->trans(ucwords($unit->label))." " : ''); } print ''; // Work station if (isModEnabled('workstation')) { $workstation = new Workstation($object->db); $res = $workstation->fetch($line->fk_default_workstation); print ''; $coldisplay++; if ($res > 0) { echo $workstation->getNomUrl(1); } print ''; } } // Cost $total_cost = 0; $tmpbom->calculateCosts(); print ''; $coldisplay++; if (!empty($line->fk_bom_child)) { echo ''.price($tmpbom->total_cost * $line->qty).''; } else { echo ''.price($line->total_cost).''; } print ''; if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines') { print ''; $coldisplay++; if (($line->info_bits & 2) == 2 || !empty($disableedit)) { } else { print 'id.'">'.img_edit().''; } print ''; print ''; $coldisplay++; if (($line->fk_prev_id == null) && empty($disableremove)) { //La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation print 'id.'">'; print img_delete(); print ''; } print ''; if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) { print ''; $coldisplay++; if ($i > 0) { print 'id.'">'; echo img_up('default', 0, 'imgupforline'); print ''; } if ($i < $num - 1) { print 'id.'">'; echo img_down('default', 0, 'imgdownforline'); print ''; } print ''; } else { print 'browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'>'; $coldisplay++; } } else { print ''; $coldisplay = $coldisplay + 3; } if ($action == 'selectlines') { print ''; print ''; print ''; } print ''; // Select of all the sub-BOM lines // From this point to the end of the file, we only take care of sub-BOM lines $sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl'; $sql.= ' WHERE fk_bom ='. (int) $tmpbom->id; $resql = $object->db->query($sql); if ($resql) { // Loop on all the sub-BOM lines if they exist while ($obj = $object->db->fetch_object($resql)) { $sub_bom_product = new Product($object->db); $sub_bom_product->fetch($obj->fk_product); $sub_bom = new BOM($object->db); if (!empty($obj->fk_bom_child)) { $sub_bom->fetch($obj->fk_bom_child); } $sub_bom_line = new BOMLine($object->db); $sub_bom_line->fetch($obj->rowid); //If hidden conf is set, we show directly all the sub-BOM lines if (!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT')) { print ''; } else { print ''; } // Product OR BOM print ''; if (!empty($obj->fk_bom_child)) { print $sub_bom_product->getNomUrl(1); print ' '.$langs->trans('or').' '; print $sub_bom->getNomUrl(1); } else { print $sub_bom_product->getNomUrl(1); print ''; } // Qty $label = $sub_bom_product->getLabelOfUnit('long'); if ($sub_bom_line->qty_frozen > 0) { print ''.price($sub_bom_line->qty, 0, '', 0, 0).''; if (getDolGlobalString('PRODUCT_USE_UNITS')) { print ''; if ($label !== '') { print $langs->trans($label); } print ''; } print ''.$langs->trans('Yes').''; } else { print ''.price($sub_bom_line->qty * $line->qty, 0, '', 0, 0).''; if (getDolGlobalString('PRODUCT_USE_UNITS')) { print ''; if ($label !== '') { print $langs->trans($label); } print ''; } print ' '; } // Disable stock change if ($sub_bom_line->disable_stock_change > 0) { print ''.$sub_bom_line->disable_stock_change.''; } else { print ' '; } // Efficiency print ''.$sub_bom_line->efficiency.''; // Cost if (!empty($sub_bom->id)) { $sub_bom->calculateCosts(); print ''.price(price2num($sub_bom->total_cost * $sub_bom_line->qty * $line->qty, 'MT')).''; $total_cost+= $sub_bom->total_cost * $sub_bom_line->qty * $line->qty; } elseif ($sub_bom_product->type == Product::TYPE_SERVICE && isModEnabled('workstation') && !empty($sub_bom_product->fk_default_workstation)) { //Convert qty to hour $unit = measuringUnitString($sub_bom_line->fk_unit, '', '', 1); $qty = convertDurationtoHour($sub_bom_line->qty, $unit); $workstation = new Workstation($this->db); $res = $workstation->fetch($sub_bom_product->fk_default_workstation); if ($res > 0) { $sub_bom_line->total_cost = (float) price2num($qty * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated), 'MT'); } print ''.price(price2num($sub_bom_line->total_cost, 'MT')).''; $this->total_cost += $line->total_cost; } elseif ($sub_bom_product->cost_price > 0) { print ''; print ''.price(price2num($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty, 'MT')).''; $total_cost+= $sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty; } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined print ''; print ''.price(price2num($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty, 'MT')).''; $total_cost.= $sub_bom_product->pmp * $sub_bom_line->qty * $line->qty; } else { // Minimum purchase price if cost price and PMP aren't defined $sql_supplier_price = 'SELECT MIN(price) AS min_price, quantity AS qty FROM '.MAIN_DB_PREFIX.'product_fournisseur_price'; $sql_supplier_price.= ' WHERE fk_product = '. (int) $sub_bom_product->id; $resql_supplier_price = $object->db->query($sql_supplier_price); if ($resql_supplier_price) { $obj = $object->db->fetch_object($resql_supplier_price); if (!empty($obj->qty) && !empty($sub_bom_line->qty) && !empty($line->qty)) { $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty * $line->qty; } else { $line_cost = $obj->min_price; } print ''.price2num($line_cost, 'MT').''; $total_cost+= $line_cost; } } print ''; print ''; print ''; } } print "\n";