/** * Load lines * * @return int >0 if OK, Otherwise if KO */ function fetch_lines() { global $conf, $mysoc; // TODO: recuperer les champs du document associe a part $sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked"; $sql .= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva"; $sql .= ", cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.price, cd.subprice, cd.remise_percent"; $sql .= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot"; $sql .= ", p.ref as product_ref, p.label as product_label, p.fk_product_type"; $sql .= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch"; $sql .= " FROM (" . MAIN_DB_PREFIX . "expeditiondet as ed,"; $sql .= " " . MAIN_DB_PREFIX . "commandedet as cd)"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = cd.fk_product"; $sql .= " WHERE ed.fk_expedition = " . $this->id; $sql .= " AND ed.fk_origin_line = cd.rowid"; $sql .= " ORDER BY cd.rang, ed.fk_origin_line"; dol_syslog(get_class($this) . "::fetch_lines", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { include_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'; $num = $this->db->num_rows($resql); $i = 0; $lineindex = 0; $originline = 0; $this->total_ht = 0; $this->total_tva = 0; $this->total_ttc = 0; $this->total_localtax1 = 0; $this->total_localtax2 = 0; while ($i < $num) { $obj = $this->db->fetch_object($resql); if ($originline == $obj->fk_origin_line) { $line->entrepot_id = 0; // entrepod_id in details_entrepot $line->qty_shipped += $obj->qty_shipped; } else { $line = new ExpeditionLigne($this->db); $line->entrepot_id = $obj->fk_entrepot; $line->qty_shipped = $obj->qty_shipped; } $detail_entrepot = new stdClass(); $detail_entrepot->entrepot_id = $obj->fk_entrepot; $detail_entrepot->qty_shipped = $obj->qty_shipped; $line->details_entrepot[] = $detail_entrepot; $line->line_id = $obj->line_id; $line->rowid = $obj->line_id; // TODO deprecated $line->id = $obj->line_id; $line->fk_origin_line = $obj->fk_origin_line; $line->origin_line_id = $obj->fk_origin_line; // TODO deprecated $line->fk_product = $obj->fk_product; $line->fk_product_type = $obj->fk_product_type; $line->ref = $obj->product_ref; // TODO deprecated $line->product_ref = $obj->product_ref; $line->product_label = $obj->product_label; $line->libelle = $obj->product_label; // TODO deprecated $line->product_tobatch = $obj->product_tobatch; $line->label = $obj->custom_label; $line->description = $obj->description; $line->qty_asked = $obj->qty_asked; $line->weight = $obj->weight; $line->weight_units = $obj->weight_units; $line->length = $obj->length; $line->length_units = $obj->length_units; $line->surface = $obj->surface; $line->surface_units = $obj->surface_units; $line->volume = $obj->volume; $line->volume_units = $obj->volume_units; // For invoicing $tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc); // We force type to 0 $line->desc = $obj->description; // We need ->desc because some code into CommonObject use desc (property defined for other elements) $line->qty = $line->qty_shipped; $line->total_ht = $tabprice[0]; $line->total_localtax1 = $tabprice[9]; $line->total_localtax2 = $tabprice[10]; $line->total_ttc = $tabprice[2]; $line->total_tva = $tabprice[1]; $line->tva_tx = $obj->tva_tx; $line->localtax1_tx = $obj->localtax1_tx; $line->localtax2_tx = $obj->localtax2_tx; $line->price = $obj->price; $line->subprice = $obj->subprice; $line->remise_percent = $obj->remise_percent; $this->total_ht += $tabprice[0]; $this->total_tva += $tabprice[1]; $this->total_ttc += $tabprice[2]; $this->total_localtax1 += $tabprice[9]; $this->total_localtax2 += $tabprice[10]; $line->detail_batch = array(); // Eat-by date if (!empty($conf->productbatch->enabled) && $obj->line_id > 0) { require_once DOL_DOCUMENT_ROOT . '/expedition/class/expeditionbatch.class.php'; $newdetailbatch = ExpeditionLineBatch::fetchAll($this->db, $obj->line_id); if (is_array($newdetailbatch)) { if ($originline != $obj->fk_origin_line) { $line->detail_batch = $newdetailbatch; } else { $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch); } } } if ($originline != $obj->fk_origin_line) { $this->lines[$lineindex] = $line; $lineindex++; } else { $line->total_ht += $tabprice[0]; $line->total_localtax1 += $tabprice[9]; $line->total_localtax2 += $tabprice[10]; $line->total_ttc += $tabprice[2]; $line->total_tva += $tabprice[1]; } $i++; $originline = $obj->fk_origin_line; } $this->db->free($resql); return 1; } else { $this->error = $this->db->error(); return -3; } }