function _autocomplete_lot_number(&$PDOdb, $productid) { global $db, $conf, $langs; $langs->load('other'); dol_include_once('/core/lib/product.lib.php'); $sql = "SELECT DISTINCT(lot_number),rowid, SUM(contenancereel_value) as qty, contenancereel_units as unit\n\t\t\tFROM " . MAIN_DB_PREFIX . "asset\n\t\t\tWHERE fk_product = " . $productid . " GROUP BY lot_number,contenancereel_units,rowid"; $PDOdb->Execute($sql); $TLotNumber = array(''); $PDOdb->Execute($sql); $Tres = $PDOdb->Get_All(); foreach ($Tres as $res) { $asset = new TAsset(); $asset->load($PDOdb, $res->rowid); $asset->load_asset_type($PDOdb); //pre($asset,true);exit; $TLotNumber[$res->lot_number]['lot_number'] = $res->lot_number; $TLotNumber[$res->lot_number]['label'] = $res->lot_number . " / " . $res->qty . " " . ($asset->assetType->measuring_units == 'unit' ? 'unité(s)' : measuring_units_string($res->unit, $asset->assetType->measuring_units)); } return $TLotNumber; }
/** Overloading the doActions function : replacing the parent's function with the one below * @param parameters meta datas of the hook (context, etc...) * @param object the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...) * @param action current action (if set). Generally create or edit or null * @return void */ function beforePDFCreation($parameters, &$object, &$action, $hookmanager) { // pour implementation dans Dolibarr 3.7 if (in_array('pdfgeneration', explode(':', $parameters['context']))) { define('INC_FROM_DOLIBARR', true); dol_include_once('/dispatch/config.php'); dol_include_once('/asset/class/asset.class.php'); dol_include_once('/dispatch/class/dispatchdetail.class.php'); global $conf; if (isset($parameters['object']) && get_class($object) == 'Expedition') { $PDOdb = new TPDOdb(); foreach ($object->lines as &$line) { $sql = 'SELECT DISTINCT(lot_number),rowid FROM ' . MAIN_DB_PREFIX . 'expeditiondet_asset WHERE fk_expeditiondet = ' . $line->line_id; $PDOdb->Execute($sql); $TRes = $PDOdb->Get_All(); if (count($TRes) > 0) { $line->desc .= "<br>Lot(s) expédié(s) : "; foreach ($TRes as $res) { $dispatchDetail = new TDispatchDetail(); $dispatchDetail->load($PDOdb, $res->rowid); $asset = new TAsset(); $asset->load($PDOdb, $dispatchDetail->fk_asset); $asset->load_asset_type($PDOdb); $unite = $asset->assetType->measuring_units == 'unit' ? 'unité(s)' : measuring_units_string($dispatchDetail->weight_reel_unit, $asset->assetType->measuring_units); $desc = "<br>- " . $res->lot_number . " x " . $dispatchDetail->weight_reel . " " . $unite; if (empty($conf->global->DISPATCH_HIDE_DLUO_PDF)) { $desc .= ' (DLUO : ' . $asset->get_date('dluo') . ')'; } $line->desc .= $desc; } } } } //pre($object,true);exit; } }
private function create_flacon_stock_mouvement(&$PDOdb, &$linedetail, $numref, $fk_soc = 0) { global $user, $langs, $conf; dol_include_once('/asset/class/asset.class.php'); dol_include_once('/product/class/product.class.php'); dol_include_once('/expedition/class/expedition.class.php'); $asset = new TAsset(); $asset->load($PDOdb, $linedetail->fk_asset); if ($conf->global->clilatoxan) { $poids_destocke = $this->calcule_poids_destocke($PDOdb, $linedetail); $poids_destocke = $poids_destocke * pow(10, $asset->contenancereel_units); } else { $poids_destocke = $linedetail->weight_reel; } /*pre($linedetail,true); echo $poids_destocke;exit;*/ //$asset->contenancereel_value = $asset->contenancereel_value - $poids_destocke; $asset->fk_societe_localisation = $fk_soc; //Vas destocker l'équipement mais pas dolibarr $asset->save($PDOdb, $user, $langs->trans("ShipmentValidatedInDolibarr", $numref), -$poids_destocke, false, 0, true); /*$stock = new TAssetStock; $stock->mouvement_stock($PDOdb, $user, $asset->getId(), -$poids_destocke, $langs->trans("ShipmentValidatedInDolibarr",$numref), $linedetail->fk_expeditiondet); */ return $poids_destocke; }
function _action() { global $user, $db, $conf, $langs; $PDOdb = new TPDOdb(); //$PDOdb->debug=true; /******************************************************************* * ACTIONS * * Put here all code to do according to value of "action" parameter ********************************************************************/ $action = __get('action', 'view'); switch ($action) { case 'new': case 'add': $assetOf = new TAssetOF(); $assetOf->set_values($_REQUEST); $fk_product = __get('fk_product', 0, 'int'); $fk_nomenclature = __get('fk_nomenclature', 0, 'int'); _fiche($PDOdb, $assetOf, 'edit', $fk_product, $fk_nomenclature); break; case 'edit': $assetOf = new TAssetOF(); $assetOf->load($PDOdb, $_REQUEST['id']); _fiche($PDOdb, $assetOf, 'edit'); break; case 'create': case 'save': $assetOf = new TAssetOF(); if (!empty($_REQUEST['id'])) { $assetOf->load($PDOdb, $_REQUEST['id'], false); $mode = 'view'; } else { $mode = $action == 'create' ? 'view' : 'edit'; } $assetOf->set_values($_REQUEST); $fk_product = __get('fk_product_to_add', 0); $quantity_to_create = __get('quantity_to_create', 1); $fk_nomenclature = __get('fk_nomenclature', 0); if ($fk_product > 0) { $assetOf->addLine($PDOdb, $fk_product, 'TO_MAKE', $quantity_to_create, 0, '', $fk_nomenclature); } if (!empty($_REQUEST['TAssetOFLine'])) { foreach ($_REQUEST['TAssetOFLine'] as $k => $row) { if (!isset($assetOf->TAssetOFLine[$k])) { $assetOf->TAssetOFLine[$k] = new TAssetOFLine(); } if (!empty($conf->global->ASSET_DEFINED_WORKSTATION_BY_NEEDED)) { $assetOf->TAssetOFLine[$k]->set_workstations($PDOdb, $row['fk_workstation']); unset($row['fk_workstation']); } $assetOf->TAssetOFLine[$k]->set_values($row); } foreach ($assetOf->TAssetOFLine as &$line) { $line->TAssetOFLine = array(); } } if (!empty($_REQUEST['TAssetWorkstationOF'])) { foreach ($_REQUEST['TAssetWorkstationOF'] as $k => $row) { //Association des utilisateurs à un poste de travail if (!empty($conf->global->ASSET_DEFINED_USER_BY_WORKSTATION)) { $assetOf->TAssetWorkstationOF[$k]->set_users($PDOdb, $row['fk_user']); unset($row['fk_user']); } //Association des opérations à une poste de travail (mode opératoire) if (!empty($conf->global->ASSET_DEFINED_OPERATION_BY_WORKSTATION)) { $assetOf->TAssetWorkstationOF[$k]->set_tasks($PDOdb, $row['fk_task']); unset($row['fk_task']); } $assetOf->TAssetWorkstationOF[$k]->set_values($row); } } $assetOf->entity = $conf->entity; //Permet de mettre à jour le lot de l'OF parent if (!empty($assetOf->fk_assetOf_parent)) { $assetOf->update_parent = true; } $assetOf->save($PDOdb); _fiche($PDOdb, $assetOf, $mode); break; case 'valider': $error = 0; $assetOf = new TAssetOF(); $id = GETPOST('id'); if (empty($id)) { exit('Where is Waldo ?'); } $assetOf->load($PDOdb, $id); //Si use_lot alors check de la saisie du lot pour chaque ligne avant validation if (!empty($conf->global->USE_LOT_IN_OF) && !empty($conf->global->OF_LOT_MANDATORY)) { if (!$assetOf->checkLotIsFill()) { _fiche($PDOdb, $assetOf, 'view'); break; } } $res = $assetOf->validate($PDOdb); if ($res > 0) { //Relaod de l'objet OF parce que createOfAndCommandesFourn() fait tellement de truc que c'est le bordel $assetOf = new TAssetOF(); if (!empty($_REQUEST['id'])) { $assetOf->load($PDOdb, $_REQUEST['id'], false); } } _fiche($PDOdb, $assetOf, 'view'); break; case 'lancer': $assetOf = new TAssetOF(); $id = GETPOST('id'); if (empty($id)) { exit('Where is Waldo ?'); } $assetOf->load($PDOdb, $id); $assetOf->openOF($PDOdb); $assetOf->load($PDOdb, $id); _fiche($PDOdb, $assetOf, 'view'); break; case 'terminer': $assetOf = new TAssetOF(); $assetOf->load($PDOdb, $_REQUEST['id']); $assetOf->closeOF($PDOdb); $assetOf->load($PDOdb, $_REQUEST['id']); _fiche($PDOdb, $assetOf, 'view'); break; case 'delete': $assetOf = new TAssetOF(); $assetOf->load($PDOdb, $_REQUEST['id']); //$PDOdb->db->debug=true; $assetOf->delete($PDOdb); header('Location: ' . dol_buildpath('/of/liste_of.php?delete_ok=1', 1)); exit; break; case 'view': $assetOf = new TAssetOF(); $assetOf->load($PDOdb, $_REQUEST['id']); _fiche($PDOdb, $assetOf, 'view'); break; case 'createDocOF': $id_of = $_REQUEST['id']; $assetOf = new TAssetOF(); $assetOf->load($PDOdb, $id_of, false); $TOFToGenerate = array($assetOf->rowid); if ($conf->global->ASSET_CONCAT_PDF) { $assetOf->getListeOFEnfants($PDOdb, $TOFToGenerate, $assetOf->rowid); } // var_dump($TOFToGenerate);exit; foreach ($TOFToGenerate as $id_of) { $assetOf = new TAssetOF(); $assetOf->load($PDOdb, $id_of, false); //echo $id_of; $TRes[] = generateODTOF($PDOdb, $assetOf); //echo '...ok<br />'; } $TFilePath = get_tab_file_path($TRes); // var_dump($TFilePath);exit; if ($conf->global->ASSET_CONCAT_PDF) { ob_start(); $pdf = pdf_getInstance(); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($langs)); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) { $pdf->SetCompression(false); } //$pdf->SetCompression(false); $pagecount = concatPDFOF($pdf, $TFilePath); if ($pagecount) { $pdf->Output($TFilePath[0], 'F'); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } } ob_clean(); } header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=of&entity=1&file=" . $TRes[0]['dir_name'] . "/" . $TRes[0]['num_of'] . ".pdf"); break; case 'control': $assetOf = new TAssetOF(); $assetOf->load($PDOdb, $_REQUEST['id']); $subAction = __get('subAction', false); if ($subAction) { $assetOf->updateControl($PDOdb, $subAction); } _fiche_control($PDOdb, $assetOf); break; case 'addAssetLink': $assetOf = new TAssetOF(); $assetOf->load($PDOdb, __get('id', 0, 'int')); $idLine = __get('idLine', 0, 'int'); $idAsset = __get('idAsset', 0, 'int'); if ($idLine && $idAsset) { $find = false; foreach ($assetOf->TAssetOFLine as $TAssetOFLine) { if ($TAssetOFLine->getId() == $idLine) { $find = true; $asset = new TAsset(); $asset->load($PDOdb, $idAsset); $TAssetOFLine->addAssetLink($asset); break; } } if (!$find) { setEventMessage('Erreur sur l\'identifiant de l\'équipement', 'errors'); } } else { setEventMessage('Erreur sur la saisie de l\'équipement.', 'errors'); } _fiche($PDOdb, $assetOf, 'edit'); break; case 'deleteAssetLink': $assetOf = new TAssetOF(); $assetOf->load($PDOdb, __get('id', 0, 'int')); $idLine = __get('idLine', 0, 'int'); $idAsset = __get('idAsset', 0, 'int'); if ($idLine && $idAsset) { TAsset::del_element_element($PDOdb, $idLine, $idAsset, 'TAsset'); } else { setEventMessage('Erreur sur un des identifiants', 'errors'); } _fiche($PDOdb, $assetOf, 'edit'); break; default: $assetOf = new TAssetOF(); $assetOf->load($PDOdb, $_REQUEST['id'], false); _fiche($PDOdb, $assetOf, 'view'); break; } }
function getAssetLinked(&$PDOdb, $only_ids = false) { global $conf; if (!empty($conf->asset->enabled)) { $Tab = $TId = array(); $TId = TAsset::get_element_element($this->getId(), 'TAssetOFLine', 'TAsset'); if ($only_ids) { return $TId; } //pre($TId,true); foreach ($TId as $id) { $asset = new TAsset(); if ($asset->load($PDOdb, $id)) { $Tab[] = $asset; } } return $Tab; } return array(); }