Standardize code of the fetch_lines()
This commit is contained in:
parent
35c57988a0
commit
95dc25587c
@ -1782,8 +1782,9 @@ class Propal extends CommonObject
|
||||
*/
|
||||
public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $filters = '')
|
||||
{
|
||||
global $langs, $conf;
|
||||
// phpcs:enable
|
||||
global $langs, $conf;
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
$sql = 'SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,';
|
||||
|
||||
@ -2031,8 +2031,9 @@ class Commande extends CommonOrder
|
||||
*/
|
||||
public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
|
||||
{
|
||||
global $langs, $conf;
|
||||
// phpcs:enable
|
||||
global $langs, $conf;
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
$sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.label as custom_label, l.description, l.price, l.qty, l.vat_src_code, l.tva_tx, l.ref_ext,';
|
||||
|
||||
@ -658,18 +658,18 @@ class FactureRec extends CommonInvoice
|
||||
*/
|
||||
public function fetch_lines()
|
||||
{
|
||||
global $extrafields;
|
||||
|
||||
// phpcs:enable
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
// Retrieve all extrafield for line
|
||||
// fetch optionals attributes and labels
|
||||
if (!is_object($extrafields)) {
|
||||
/*if (!is_object($extrafields)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
$extrafields = new ExtraFields($this->db);
|
||||
}
|
||||
$extrafields->fetch_name_optionals_label($this->table_element_line, true);
|
||||
*/
|
||||
|
||||
$sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
|
||||
$sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
|
||||
|
||||
@ -1775,8 +1775,9 @@ class Facture extends CommonInvoice
|
||||
*/
|
||||
public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
|
||||
{
|
||||
global $langs, $conf;
|
||||
// phpcs:enable
|
||||
global $langs, $conf;
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
$sql = 'SELECT l.rowid, l.fk_facture, l.fk_product, l.fk_parent_line, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,';
|
||||
|
||||
@ -751,15 +751,14 @@ class Contrat extends CommonObject
|
||||
* Load lines array into this->lines.
|
||||
* This set also nbofserviceswait, nbofservicesopened, nbofservicesexpired and nbofservicesclosed
|
||||
*
|
||||
* @param int $only_product Return only physical products
|
||||
* @param int $loadalsotranslation Return translation for products
|
||||
*
|
||||
* @return ContratLigne[] Return array of contract lines
|
||||
* @param int $only_services 0=Default, 1=Force only services (depending on setup, we may also have physical products in a contract)
|
||||
* @param int $loadalsotranslation 0=Default, 1=Load also translations of product descriptions
|
||||
* @return ContratLigne[] Return array of contract lines
|
||||
*/
|
||||
public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
|
||||
public function fetch_lines($only_services = 0, $loadalsotranslation = 0)
|
||||
{
|
||||
// phpcs:enable
|
||||
global $langs, $conf, $extrafields;
|
||||
global $langs, $conf;
|
||||
|
||||
$this->nbofservices = 0;
|
||||
$this->nbofserviceswait = 0;
|
||||
@ -773,13 +772,15 @@ class Contrat extends CommonObject
|
||||
|
||||
$now = dol_now();
|
||||
|
||||
/*
|
||||
if (!is_object($extrafields)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
$extrafields = new ExtraFields($this->db);
|
||||
}
|
||||
|
||||
$line = new ContratLigne($this->db);
|
||||
$extrafields->fetch_name_optionals_label($line->table_element, true);
|
||||
$extrafields->fetch_name_optionals_label(ContratLigne::$table_element, true);
|
||||
*/
|
||||
|
||||
$this->lines = array();
|
||||
$pos = 0;
|
||||
@ -802,6 +803,9 @@ class Contrat extends CommonObject
|
||||
$sql .= " d.product_type as type";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contratdet as d LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
|
||||
$sql .= " WHERE d.fk_contrat = ".((int) $this->id);
|
||||
if ($only_services == 1) {
|
||||
$sql .= " AND d.product_type = 1";
|
||||
}
|
||||
$sql .= " ORDER by d.rowid ASC";
|
||||
|
||||
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
||||
@ -814,6 +818,7 @@ class Contrat extends CommonObject
|
||||
$objp = $this->db->fetch_object($result);
|
||||
|
||||
$line = new ContratLigne($this->db);
|
||||
|
||||
$line->id = $objp->rowid;
|
||||
$line->ref = $objp->rowid;
|
||||
$line->fk_contrat = $objp->fk_contrat;
|
||||
@ -840,7 +845,7 @@ class Contrat extends CommonObject
|
||||
$line->type = $objp->type;
|
||||
|
||||
$line->fk_fournprice = $objp->fk_fournprice;
|
||||
$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
|
||||
$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_fournprice, $objp->pa_ht);
|
||||
$line->pa_ht = $marginInfos[0];
|
||||
|
||||
$line->fk_user_author = $objp->fk_user_author;
|
||||
@ -882,6 +887,7 @@ class Contrat extends CommonObject
|
||||
}
|
||||
|
||||
$this->lines[$pos] = $line;
|
||||
|
||||
$this->lines_id_index_mapper[$line->id] = $pos;
|
||||
|
||||
//dol_syslog("1 ".$line->desc);
|
||||
|
||||
@ -796,10 +796,10 @@ class Delivery extends CommonObject
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num) {
|
||||
$line = new DeliveryLine($this->db);
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$line = new DeliveryLine($this->db);
|
||||
|
||||
$line->id = $obj->rowid;
|
||||
$line->label = $obj->custom_label;
|
||||
$line->description = $obj->description;
|
||||
|
||||
@ -1571,9 +1571,12 @@ class Expedition extends CommonObject
|
||||
{
|
||||
// phpcs:enable
|
||||
global $conf, $mysoc;
|
||||
// TODO: recuperer les champs du document associe a part
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
// NOTE: This fetch_lines is special because it groups all lines with the same origin_line_id into one line.
|
||||
// TODO: See if we can restore a common fetch_lines (one line = one record)
|
||||
|
||||
$sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked, cd.product_type, cd.fk_unit";
|
||||
$sql .= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
|
||||
$sql .= ", cd.vat_src_code, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.info_bits, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht";
|
||||
@ -1585,7 +1588,7 @@ class Expedition extends CommonObject
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
|
||||
$sql .= " WHERE ed.fk_expedition = ".((int) $this->id);
|
||||
$sql .= " AND ed.fk_origin_line = cd.rowid";
|
||||
$sql .= " ORDER BY cd.rang, ed.fk_origin_line";
|
||||
$sql .= " ORDER BY cd.rang, ed.fk_origin_line"; // We need after a break on fk_origin_line but when there is no break on fk_origin_line, cd.rang is same so we can add it as first order criteria.
|
||||
|
||||
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
@ -1603,22 +1606,21 @@ class Expedition extends CommonObject
|
||||
$this->total_localtax1 = 0;
|
||||
$this->total_localtax2 = 0;
|
||||
|
||||
$line = new ExpeditionLigne($this->db);
|
||||
$shipmentlinebatch = new ExpeditionLineBatch($this->db);
|
||||
|
||||
while ($i < $num) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
if ($originline == $obj->fk_origin_line) {
|
||||
if ($originline > 0 && $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;
|
||||
$line->entrepot_id = $obj->fk_entrepot; // this is a property of a shipment line
|
||||
$line->qty_shipped = $obj->qty_shipped; // this is a property of a shipment line
|
||||
}
|
||||
|
||||
$detail_entrepot = new stdClass;
|
||||
$detail_entrepot = new stdClass();
|
||||
$detail_entrepot->entrepot_id = $obj->fk_entrepot;
|
||||
$detail_entrepot->qty_shipped = $obj->qty_shipped;
|
||||
$detail_entrepot->line_id = $obj->line_id;
|
||||
@ -1714,6 +1716,8 @@ class Expedition extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
$line->fetch_optionals();
|
||||
|
||||
if ($originline != $obj->fk_origin_line) {
|
||||
$this->lines[$lineindex] = $line;
|
||||
$lineindex++;
|
||||
@ -1724,7 +1728,7 @@ class Expedition extends CommonObject
|
||||
$line->total_ttc += $tabprice[2];
|
||||
$line->total_tva += $tabprice[1];
|
||||
}
|
||||
$line->fetch_optionals();
|
||||
|
||||
$i++;
|
||||
$originline = $obj->fk_origin_line;
|
||||
}
|
||||
|
||||
@ -1320,11 +1320,13 @@ class Fichinter extends CommonObject
|
||||
// phpcs:enable
|
||||
$this->lines = array();
|
||||
|
||||
$sql = 'SELECT rowid, fk_fichinter, description, duree, date, rang';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet';
|
||||
$sql .= ' WHERE fk_fichinter = '.((int) $this->id).' ORDER BY rang ASC, date ASC';
|
||||
$sql = "SELECT rowid, fk_fichinter, description, duree, date, rang";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."fichinterdet";
|
||||
$sql .= " WHERE fk_fichinter = ".((int) $this->id);
|
||||
$sql .= " ORDER BY rang ASC, date ASC";
|
||||
|
||||
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
|
||||
@ -348,6 +348,8 @@ class FichinterRec extends Fichinter
|
||||
public function fetch_lines($sall = 0)
|
||||
{
|
||||
// phpcs:enable
|
||||
$this->lines = array();
|
||||
|
||||
$sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, ';
|
||||
$sql .= ' l.price, l.qty, l.tva_tx, l.remise, l.remise_percent, l.subprice, l.duree, ';
|
||||
$sql .= ' l.total_ht, l.total_tva, l.total_ttc,';
|
||||
@ -358,13 +360,15 @@ class FichinterRec extends Fichinter
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
|
||||
$sql .= ' WHERE l.fk_fichinter = '.((int) $this->id);
|
||||
|
||||
dol_syslog('FichInter-rec::fetch_lines', LOG_DEBUG);
|
||||
dol_syslog('FichinterRec::fetch_lines', LOG_DEBUG);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
while ($i < $num) {
|
||||
$objp = $this->db->fetch_object($result);
|
||||
|
||||
$line = new FichinterLigne($this->db);
|
||||
|
||||
$line->id = $objp->rowid;
|
||||
|
||||
@ -504,7 +504,8 @@ class CommandeFournisseur extends CommonOrder
|
||||
$sql .= " ORDER BY l.rang, l.rowid";
|
||||
//print $sql;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch get lines", LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$num = $this->db->num_rows($result);
|
||||
|
||||
@ -681,18 +681,17 @@ class FactureFournisseurRec extends CommonInvoice
|
||||
*/
|
||||
public function fetch_lines()
|
||||
{
|
||||
global $extrafields;
|
||||
|
||||
// phpcs:enable
|
||||
$this->lines = array();
|
||||
|
||||
// Retrieve all extrafield for line
|
||||
// fetch optionals attributes and labels
|
||||
if (!is_object($extrafields)) {
|
||||
/*if (!is_object($extrafields)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
$extrafields = new ExtraFields($this->db);
|
||||
}
|
||||
$extrafields->fetch_name_optionals_label($this->table_element_line, true);
|
||||
*/
|
||||
|
||||
$sql = 'SELECT l.rowid,';
|
||||
$sql .= ' l.fk_facture_fourn, l.fk_parent_line, l.fk_product, l.ref, l.label, l.description,';
|
||||
@ -710,12 +709,14 @@ class FactureFournisseurRec extends CommonInvoice
|
||||
$sql .= ' ORDER BY l.rang';
|
||||
|
||||
dol_syslog('FactureFournisseurRec::fetch_lines', LOG_DEBUG);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
while ($i < $num) {
|
||||
$objp = $this->db->fetch_object($result);
|
||||
|
||||
$line = new FactureFournisseurLigneRec($this->db);
|
||||
|
||||
$line->id = $objp->rowid;
|
||||
|
||||
@ -1041,6 +1041,7 @@ class FactureFournisseur extends CommonInvoice
|
||||
$sql .= ' ORDER BY f.rang, f.rowid';
|
||||
|
||||
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
||||
|
||||
$resql_rows = $this->db->query($sql);
|
||||
if ($resql_rows) {
|
||||
$num_rows = $this->db->num_rows($resql_rows);
|
||||
|
||||
@ -492,10 +492,12 @@ class Opensurveysondage extends CommonObject
|
||||
public function fetch_lines()
|
||||
{
|
||||
// phpcs:enable
|
||||
$ret = array();
|
||||
$this->lines = array();
|
||||
|
||||
$sql = "SELECT id_users, nom as name, reponses FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
|
||||
$sql = "SELECT id_users, nom as name, reponses";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
|
||||
$sql .= " WHERE id_sondage = '".$this->db->escape($this->id_sondage)."'";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
if ($resql) {
|
||||
@ -505,15 +507,13 @@ class Opensurveysondage extends CommonObject
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$tmp = array('id_users'=>$obj->id_users, 'nom'=>$obj->name, 'reponses'=>$obj->reponses);
|
||||
|
||||
$ret[] = $tmp;
|
||||
$this->lines[] = $tmp;
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
$this->lines = $ret;
|
||||
|
||||
return count($this->lines);
|
||||
}
|
||||
|
||||
|
||||
@ -1164,21 +1164,25 @@ class Reception extends CommonObject
|
||||
public function fetch_lines()
|
||||
{
|
||||
// phpcs:enable
|
||||
dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php');
|
||||
$this->lines = array();
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
|
||||
|
||||
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->id);
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
if (!empty($resql)) {
|
||||
$this->lines = array();
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$line = new CommandeFournisseurDispatch($this->db);
|
||||
|
||||
$line->fetch($obj->rowid);
|
||||
$line->fetch_product();
|
||||
|
||||
$sql_commfourndet = 'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent';
|
||||
$sql_commfourndet .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet';
|
||||
$sql_commfourndet .= ' WHERE rowid = '.((int) $line->fk_commandefourndet);
|
||||
$sql_commfourndet .= ' ORDER BY rang';
|
||||
|
||||
$resql_commfourndet = $this->db->query($sql_commfourndet);
|
||||
if (!empty($resql_commfourndet)) {
|
||||
$obj = $this->db->fetch_object($resql_commfourndet);
|
||||
|
||||
@ -483,14 +483,15 @@ class ProductAttribute extends CommonObject
|
||||
* Load array lines
|
||||
*
|
||||
* @param string $filters Filter on other fields
|
||||
*
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function fetch_lines($filters = '')
|
||||
{
|
||||
// phpcs:enable
|
||||
global $langs;
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
$error = 0;
|
||||
|
||||
// Clean parameters
|
||||
|
||||
Loading…
Reference in New Issue
Block a user