function _fiche_ligne(&$form, &$of, $type) { global $db, $conf, $langs, $hookmanager; //TODO rules guys ! To Facto ! AA $formProduct = new FormProduct($db); $PDOdb = new TPDOdb(); $TRes = array(); foreach ($of->TAssetOFLine as $k => &$TAssetOFLine) { $product =& $TAssetOFLine->product; if (is_null($product)) { $product = new Product($db); $product->fetch($TAssetOFLine->fk_product); $product->fetch_optionals(); } $conditionnement = $TAssetOFLine->conditionnement; if (!empty($conf->asset->enabled)) { $TAssetType = new TAsset_type(); $TAssetType->load($PDOdb, $product->array_options['options_type_asset']); $conditionnement_unit = $TAssetType->measuring_units == 'unit' || $TAssetType->gestion_stock == 'UNIT' ? 'unité(s)' : $TAssetOFLine->libUnite(); } else { $conditionnement_unit = 'unité(s)'; // TODO translate } //$conditionnement_unit = $TAssetOFLine->libUnite(); if ($TAssetOFLine->measuring_units != 'unit' && !empty($TAssetOFLine->measuring_units)) { $conditionnement_label = ' / ' . $conditionnement . " " . $conditionnement_unit; $conditionnement_label_edit = ' par ' . $form->texte('', 'TAssetOFLine[' . $k . '][conditionnement]', $conditionnement, 5, 5, '', '') . $conditionnement_unit; } else { $conditionnement_label = $conditionnement_label_edit = ''; } if ($TAssetOFLine->type == "NEEDED" && $type == "NEEDED") { $stock_needed = TAssetOF::getProductStock($product->id); $TLine = array('id' => $TAssetOFLine->getId(), 'idprod' => $form->hidden('TAssetOFLine[' . $k . '][fk_product]', $product->id), 'lot_number' => $of->status == 'DRAFT' ? $form->texte('', 'TAssetOFLine[' . $k . '][lot_number]', $TAssetOFLine->lot_number, 15, 50, 'type_product="NEEDED" fk_product="' . $product->id . '" rel="lot-' . $TAssetOFLine->getId() . '" ', 'TAssetOFLineLot') : $TAssetOFLine->lot_number, 'libelle' => $product->getNomUrl(1) . ' ' . $product->label . ' - ' . ($stock_needed > 0 ? $langs->trans("Stock") . " : " . $stock_needed : '<span style="color:red;font-weight:bold;">' . $langs->trans("Stock") . " : " . $stock_needed . '</span>') . _fiche_ligne_asset($PDOdb, $form, $of, $TAssetOFLine, 'NEEDED'), 'qty_needed' => $TAssetOFLine->qty_needed . $conditionnement_label, 'qty' => $of->status == 'DRAFT' ? $form->texte('', 'TAssetOFLine[' . $k . '][qty]', $TAssetOFLine->qty, 5, 50) : $TAssetOFLine->qty, 'qty_used' => $of->status == 'OPEN' || $of->status == 'CLOSE' ? $form->texte('', 'TAssetOFLine[' . $k . '][qty_used]', $TAssetOFLine->qty_used, 5, 50) : $TAssetOFLine->qty_used, 'qty_toadd' => $TAssetOFLine->qty - $TAssetOFLine->qty_used, 'workstations' => $conf->workstation->enabled ? $TAssetOFLine->visu_checkbox_workstation($db, $of, $form, 'TAssetOFLine[' . $k . '][fk_workstation][]') : '', 'delete' => $form->type_aff == 'edit' && ($of->status == 'DRAFT' || !empty($conf->global->OF_USE_DESTOCKAGE_PARTIEL) && $of->status != 'CLOSE' && empty($TAssetOFLine->qty_used)) ? '<a href="javascript:deleteLine(' . $TAssetOFLine->getId() . ',\'NEEDED\');">' . img_picto('Supprimer', 'delete.png') . '</a>' : '', 'fk_entrepot' => !empty($conf->global->ASSET_MANUAL_WAREHOUSE) && ($of->status == 'DRAFT' || $of->status == 'VALID') && $form->type_aff == 'edit' ? $formProduct->selectWarehouses($TAssetOFLine->fk_entrepot, 'TAssetOFLine[' . $k . '][fk_entrepot]', '', 0, 0, $TAssetOFLine->fk_product) : $TAssetOFLine->getLibelleEntrepot($PDOdb), 'note_private' => $of->status == 'DRAFT' ? $form->zonetexte('', 'TAssetOFLine[' . $k . '][note_private]', $TAssetOFLine->note_private, 50, 1) : $TAssetOFLine->note_private); $action = $form->type_aff; $parameter = array('of' => &$of, 'line' => &$TLine, 'type' => 'NEEDED'); $res = $hookmanager->executeHooks('lineObjectOptions', $parameter, $TAssetOFLine, $action); if ($res > 0 && !empty($hookmanager->resArray)) { $TLine = $hookmanager->resArray; } $TRes[] = $TLine; } elseif ($TAssetOFLine->type == "TO_MAKE" && $type == "TO_MAKE") { if (empty($TAssetOFLine->TFournisseurPrice)) { $TAssetOFLine->loadFournisseurPrice($PDOdb); } // Permet de sélectionner par défaut "(Fournisseur "Interne" => Fabrication interne)" si le produit TO_MAKE n'a pas de stock lorsqu'on est en mode edit et que la ligne TO_MAKE n'a pas encore de prix fournisseur enregistré dol_include_once('/product/class/product.class.php'); $p = new Product($db); $selected = 0; if ($p->fetch($TAssetOFLine->fk_product)) { $p->load_stock(); $p->stock_reel; if ($TAssetOFLine->type === 'TO_MAKE' && $p->stock_reel <= 0 && $_REQUEST['action'] === 'edit') { $selected = -2; } } // ************************************************************* $Tab = array(); foreach ($TAssetOFLine->TFournisseurPrice as &$objPrice) { $label = ""; //Si on a un prix fournisseur pour le produit if ($objPrice->price > 0) { $unit = $objPrice->quantity == 1 ? 'Unité' : 'Unités'; $label .= floatval($objPrice->price) . ' ' . $conf->currency . ' - ' . $objPrice->quantity . ' ' . $unit . ' -'; } //Affiche le nom du fournisseur $label .= ' (Fournisseur "' . utf8_encode($objPrice->name) . '"'; //Prix unitaire minimum si renseigné dans le PF if ($objPrice->quantity > 0) { ' ' . $objPrice->quantity . ' pièce(s) min,'; } //Affiche le type du PF : if ($objPrice->compose_fourni) { // soit on fabrique les composants $label .= ' => Fabrication interne'; } elseif ($objPrice->quantity <= 0) { // soit on a le produit finis déjà en stock $label .= ' => Sortie de stock'; } if ($objPrice->quantity > 0) { // soit on commande a un fournisseur $label .= ' => Commande fournisseur'; } $label .= ")"; $Tab[$objPrice->rowid] = array('label' => $label, 'compose_fourni' => $objPrice->compose_fourni ? $objPrice->compose_fourni : 0); } if ($conf->nomenclature->enabled) { dol_include_once('/nomenclature/class/nomenclature.class.php'); if ($of->status == 'DRAFT' && !$TAssetOFLine->nomenclature_valide) { $TNomenclature = TNomenclature::get($PDOdb, $TAssetOFLine->fk_product, true); if (count($TNomenclature) > 0) { $nomenclature = '<div>' . $form->combo('', 'TAssetOFLine[' . $k . '][fk_nomenclature]', $TNomenclature, $TAssetOFLine->fk_nomenclature); if ($form->type_aff == 'edit') { $nomenclature .= '<a href="#" class="valider_nomenclature" data-id_of="' . $of->getId() . '" data-product="' . $TAssetOFLine->fk_product . '" data-of_line="' . $TAssetOFLine->rowid . '">Valider</a>'; } else { $nomenclature .= " - Nomenclature à sélectionner"; } $nomenclature .= '</div>'; } else { $nomenclature = ''; } } else { $n = new TNomenclature(); $n->load($PDOdb, $TAssetOFLine->fk_nomenclature); $nomenclature = '<div>' . (string) $n; $picture = $TAssetOFLine->nomenclature_valide ? 'ok.png' : 'no.png'; $nomenclature .= ' <img src="img/' . $picture . '" style="padding-left: 2px; vertical-align: middle;" /></div>'; } } //($of->status=='DRAFT') ? $form->combo('', 'TAssetOFLine['.$k.'][fk_nomenclature]', _getArrayNomenclature($PDOdb, $TAssetOFLine), $TAssetOFLine->fk_nomenclature) : _getTitleNomenclature($PDOdb, $TAssetOFLine->fk_nomenclature) $stock_tomake = TAssetOF::getProductStock($product->id); $TLine = array('id' => $TAssetOFLine->getId(), 'idprod' => $form->hidden('TAssetOFLine[' . $k . '][fk_product]', $product->id), 'lot_number' => $of->status == 'DRAFT' ? $form->texte('', 'TAssetOFLine[' . $k . '][lot_number]', $TAssetOFLine->lot_number, 15, 50, 'type_product="TO_MAKE" fk_product="' . $product->id . '"', 'TAssetOFLineLot') : $TAssetOFLine->lot_number, 'libelle' => $product->getNomUrl(1) . ' ' . $product->label . ' - ' . $langs->trans("Stock") . " : " . $stock_tomake . _fiche_ligne_asset($PDOdb, $form, $of, $TAssetOFLine, false), 'nomenclature' => $nomenclature, 'addneeded' => $form->type_aff == 'edit' && $of->status == 'DRAFT' ? '<a href="#null" statut="' . $of->status . '" onclick="addAllLines(' . $of->getId() . ',' . $TAssetOFLine->getId() . ',this);">' . img_picto('Mettre à jour les produits nécessaires', 'object_technic.png') . '</a>' : '', 'qty' => $of->status == 'DRAFT' ? $form->texte('', 'TAssetOFLine[' . $k . '][qty]', $TAssetOFLine->qty, 5, 5, '', '') . $conditionnement_label_edit : $TAssetOFLine->qty . $conditionnement_label, 'qty_used' => $of->status == 'OPEN' || $of->status == 'CLOSE' ? $form->texte('', 'TAssetOFLine[' . $k . '][qty_used]', $TAssetOFLine->qty_used, 5, 5, '', '') . $conditionnement_label_edit : $TAssetOFLine->qty_used . $conditionnement_label, 'fk_product_fournisseur_price' => $form->combo('', 'TAssetOFLine[' . $k . '][fk_product_fournisseur_price]', $Tab, $TAssetOFLine->fk_product_fournisseur_price != 0 ? $TAssetOFLine->fk_product_fournisseur_price : $selected, 1, '', 'style="max-width:250px;"'), 'delete' => $form->type_aff == 'edit' && $of->status == 'DRAFT' ? '<a href="#null" onclick="deleteLine(' . $TAssetOFLine->getId() . ',\'TO_MAKE\');">' . img_picto('Supprimer', 'delete.png') . '</a>' : '', 'fk_entrepot' => !empty($conf->global->ASSET_MANUAL_WAREHOUSE) && ($of->status == 'DRAFT' || $of->status == 'VALID' || $of->status == 'NEEDOFFER' || $of->status == 'ONORDER' || $of->status == 'OPEN') && $form->type_aff == 'edit' ? $formProduct->selectWarehouses($TAssetOFLine->fk_entrepot, 'TAssetOFLine[' . $k . '][fk_entrepot]', '', 0, 0, $TAssetOFLine->fk_product) : $TAssetOFLine->getLibelleEntrepot($PDOdb)); $action = $form->type_aff; $parameter = array('of' => &$of, 'line' => &$TLine, 'type' => 'TO_MAKE'); $res = $hookmanager->executeHooks('lineObjectOptions', $parameter, $TAssetOFLine, $action); if ($res > 0 && !empty($hookmanager->resArray)) { $TLine = $hookmanager->resArray; } $TRes[] = $TLine; } } return $TRes; }
function _getArbo(&$PDOdb, &$TAssetOFLine, $fk_product, $fk_nomenclature) { include_once DOL_DOCUMENT_ROOT . '/custom/nomenclature/class/nomenclature.class.php'; $TRes = array(); //$TNomen = TNomenclature::get($PDOdb, $fk_product); $TCompare = array(); foreach ($TAssetOFLine->TAssetOFLine as $line) { // TODO manque encore les sous-sous-enfants $TCompare[$line->fk_product] = $line; // Ceci me permet de récupérer le fk_nomenclature associé à la ligne de l'OF } if ($fk_nomenclature) { $TNomen = new TNomenclature(); $TNomen->load($PDOdb, $fk_nomenclature); } else { $TNomen = TNomenclature::getDefaultNomenclature($PDOdb, $fk_product); } if (!empty($TNomen)) { foreach ($TNomen->TNomenclatureDet as $key => $TNomenclatureDet) { //Vérification que le produit de la nomenclature est bien dans la liste des lignes de l'OF if (isset($TCompare[$TNomenclatureDet->fk_product])) { $TRes[$TNomenclatureDet->fk_product] = array(0 => $TNomenclatureDet->fk_product, 1 => $TNomenclatureDet->qty, 'childs' => _getArbo($PDOdb, $TCompare[$TNomenclatureDet->fk_product], $TNomenclatureDet->fk_product, $TCompare[$TNomenclatureDet->fk_product]->fk_nomenclature)); } } } return $TRes; }
function addWorkStation(&$PDOdb, $fk_product, $fk_nomenclature = 0, $qty_needed = 1) { global $conf; if (!empty($conf->workstation->enabled)) { if ($conf->nomenclature->enabled) { if ($fk_nomenclature > 0) { dol_include_once('/nomenclature/class/nomenclature.class.php'); $n = new TNomenclature(); if ($n->load($PDOdb, $fk_nomenclature, true)) { foreach ($n->TNomenclatureWorkstation as &$nws) { if ($nws->nb_hour_manufacture > 0 || $nws->nb_hour_prepare > 0 || $conf->global->ASSET_AUTHORIZE_ADD_WORKSTATION_TIME_0_ON_OF) { $k = $this->addofworkstation($PDOdb, $nws->fk_workstation, $nws->nb_hour_prepare + $nws->nb_hour_manufacture * ($qty_needed / $n->qty_reference), $nws->nb_hour_prepare, $nws->nb_hour_manufacture * ($qty_needed / $n->qty_reference), $nws->rang, $nws->note_private, $nws->nb_days_before_beginning); $this->TAssetWorkstationOF[$k]->ws = $nws->workstation; } } } } } else { $sql = "SELECT fk_workstation as fk_asset_workstation, nb_hour"; $sql .= " FROM " . MAIN_DB_PREFIX . "workstation_product"; $sql .= " WHERE fk_product = " . $fk_product; $PDOdb->Execute($sql); while ($res = $PDOdb->Get_line()) { $k = $this->addofworkstation($PDOdb, $nws->fk_workstation, $res->nb_hour); $this->TAssetWorkstationOF[$k]->ws = $ws; } } } }