function loadLines(&$PDOdb, $id_expeditionLine)
 {
     $sql = "SELECT rowid FROM " . $this->get_table() . " WHERE fk_expeditiondet = " . $id_expeditionLine . " ORDER BY rang";
     $TIdExpedet = TRequeteCore::_get_id_by_sql($PDOdb, $sql);
     foreach ($TIdExpedet as $idexpedet) {
         $dispatchdetail_temp = new TDispatchDetail();
         $dispatchdetail_temp->load($PDOdb, $idexpedet);
         $this->lines[] = $dispatchdetail_temp;
         $this->nbLines = $this->nbLines + 1;
     }
 }
function _addExpeditiondetLine(&$PDOdb, &$TImport, &$expedition, $numserie)
{
    global $db;
    //Charge l'asset lié au numéro de série dans le fichier
    $asset = new TAsset();
    if ($asset->loadBy($PDOdb, $numserie, 'serial_number')) {
        //Charge le produit associé à l'équipement
        $prodAsset = new Product($db);
        $prodAsset->fetch($asset->fk_product);
        $fk_line_expe = (int) GETPOST('lineexpeditionid');
        if (empty($fk_line_expe)) {
            //Récupération de l'indentifiant de la ligne d'expédition concerné par le produit
            foreach ($expedition->lines as $expeline) {
                if ($expeline->fk_product == $prodAsset->id) {
                    $fk_line_expe = $expeline->line_id;
                }
            }
        }
        //Sauvegarde (ajout/MAJ) des lignes de détail d'expédition
        $dispatchdetail = new TDispatchDetail();
        //Si déjà existant => MAj
        $PDOdb->Execute("SELECT rowid FROM " . MAIN_DB_PREFIX . "expeditiondet_asset WHERE fk_asset = " . $asset->rowid . " AND fk_expeditiondet = " . $fk_line_expe . " ");
        if ($PDOdb->Get_line()) {
            $dispatchdetail->load($PDOdb, $PDOdb->Get_field('rowid'));
        }
        $keys = array_keys($TImport);
        $rang = $keys[count($keys) - 1];
        $dispatchdetail->fk_expeditiondet = $fk_line_expe;
        $dispatchdetail->fk_asset = $asset->rowid;
        $dispatchdetail->rang = $rang;
        $dispatchdetail->lot_number = $asset->lot_number;
        $dispatchdetail->weight = GETPOST('quantity') ? GETPOST('quantity') : $asset->contenancereel_value;
        $dispatchdetail->weight_reel = GETPOST('quantity') ? GETPOST('quantity') : $asset->contenancereel_value;
        $dispatchdetail->weight_unit = $asset->contenancereel_units;
        $dispatchdetail->weight_reel_unit = $asset->contenancereel_units;
        $dispatchdetail->save($PDOdb);
        //Rempli le tableau utilisé pour l'affichage des lignes
        $TImport[] = array('ref' => $prodAsset->ref, 'numserie' => $numserie, 'fk_product' => $prodAsset->id, 'fk_expeditiondet' => $expedition->id, 'lot_number' => $asset->lot_number, 'quantity' => GETPOST('quantity') ? GETPOST('quantity') : $asset->contenancereel_value, 'quantity_unit' => GETPOST('quantity') ? GETPOST('quantity') : $asset->contenancereel_units);
    }
    //pre($TImport,true);
    return $TImport;
}
 /** 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;
     }
 }