From c02cd80b75a02df13fa2aa728c6676975e53025a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Nov 2019 10:11:30 +0100 Subject: [PATCH] Clean code --- htdocs/accountancy/bookkeeping/card.php | 4 ++-- .../class/accountancycategory.class.php | 6 ++++++ htdocs/comm/propal/class/propal.class.php | 4 ++-- htdocs/commande/class/commande.class.php | 8 ++++---- htdocs/compta/facture/class/facture.class.php | 5 +++-- .../class/expensereport.class.php | 5 ++--- htdocs/reception/card.php | 2 +- htdocs/societe/class/societe.class.php | 7 +++---- htdocs/takepos/invoice.php | 4 ++-- htdocs/ticket/class/ticket.class.php | 9 ++++++++- .../variants/class/ProductAttribute.class.php | 10 +++++----- .../class/ProductAttributeValue.class.php | 10 +++++----- .../class/ProductCombination.class.php | 14 ++++++------- .../ProductCombination2ValuePair.class.php | 10 +++++----- htdocs/webservices/server_invoice.php | 20 +++++++++---------- 15 files changed, 65 insertions(+), 53 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 80c9ffb7792..7a8a6612d4b 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -536,11 +536,11 @@ if ($action == 'create') print '' . $langs->trans("Status") . ''; print ''; if (empty($object->validated)) { - print ''; + print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } else { - print ''; + print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; } diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index d68c9fa54a7..5e99f3fc4a6 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -57,6 +57,12 @@ class AccountancyCategory // extends CommonObject */ public $table_element='c_accounting_category'; + /** + * @var int ID + * @deprecated + */ + public $rowid; + /** * @var int ID */ diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 3c0765830d6..27d876320c2 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -631,7 +631,7 @@ class Propal extends CommonObject if ($result > 0) { $this->db->commit(); - return $this->line->rowid; + return $this->line->id; } else { @@ -772,7 +772,7 @@ class Propal extends CommonObject $this->line->rang = $rangmax + 1; } - $this->line->rowid = $rowid; + $this->line->id = $rowid; $this->line->label = $label; $this->line->desc = $desc; $this->line->qty = $qty; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 6e01ba2f5e2..54ad29d32f4 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1565,7 +1565,7 @@ class Commande extends CommonOrder if ($result > 0) { $this->db->commit(); - return $this->line->rowid; + return $this->line->id; } else { @@ -3104,7 +3104,7 @@ class Commande extends CommonOrder $this->line->rang = $rangmax + 1; } - $this->line->rowid=$rowid; + $this->line->id=$rowid; $this->line->label=$label; $this->line->desc=$desc; $this->line->qty=$qty; @@ -4267,11 +4267,11 @@ class OrderLine extends CommonOrderLine $resql=$this->db->query($sql); if ($resql) { - $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'commandedet'); + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'commandedet'); + $this->rowid = $this->id; if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $this->id=$this->rowid; $result=$this->insertExtraFields(); if ($result < 0) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index df41f2e5595..2ac89f1dace 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1175,7 +1175,7 @@ class Facture extends CommonInvoice $this->availability_id = $object->availability_id; $this->demand_reason_id = $object->demand_reason_id; $this->date_livraison = $object->date_livraison; - $this->fk_delivery_address = $object->fk_delivery_address; + $this->fk_delivery_address = $object->fk_delivery_address; // deprecated $this->contact_id = $object->contactid; $this->ref_client = $object->ref_client; @@ -2016,7 +2016,7 @@ class Facture extends CommonInvoice $list_rowid_det = array(); foreach ($this->lines as $key => $invoiceline) { - $list_rowid_det[] = $invoiceline->rowid; + $list_rowid_det[] = $invoiceline->id; } // Consumned discounts are freed @@ -3133,6 +3133,7 @@ class Facture extends CommonInvoice $this->line->rang = $rangmax + 1; } + $this->line->id = $rowid; $this->line->rowid = $rowid; $this->line->label = $label; $this->line->desc = $desc; diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 91c69b0f3b3..ad21603efce 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1800,7 +1800,7 @@ class ExpenseReport extends CommonObject if ($result > 0) { $this->db->commit(); - return $this->line->rowid; + return $this->line->id; } else { @@ -2049,7 +2049,6 @@ class ExpenseReport extends CommonObject $this->line->fk_ecm_files = $fk_ecm_files; - $this->line->rowid = $rowid; $this->line->id = $rowid; // Select des infos sur le type fees @@ -2660,7 +2659,7 @@ class ExpenseReportLine $resql=$this->db->query($sql); if ($resql) { - $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'expensereport_det'); + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'expensereport_det'); if (! $fromaddline) { diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index cc4fad1cb60..d76ee06ab5a 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -1031,7 +1031,7 @@ if ($action == 'create') //var_dump($product->stock_warehouse[1]); print ''; - print ''; // ancre pour retourner sur la ligne + print ''; // ancre pour retourner sur la ligne // Show product and description $product_static->type = $line->fk_product_type; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index e73a060af40..027527d20d7 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4176,10 +4176,9 @@ class Societe extends CommonObject $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux '; $sql .= ' WHERE fk_soc = '.(int) $origin_id.') '; - $query = $db->query($sql); - - while ($result = $db->fetch_object($query)) { - $db->query('DELETE FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE rowid = '.$result->rowid); + $resql = $db->query($sql); + while ($obj = $db->fetch_object($resql)) { + $db->query('DELETE FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE rowid = '.$obj->rowid); } /** diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 3e26bec7ce4..60664b99b19 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -399,7 +399,7 @@ if ($action == "order" and $placeid != 0) $result = array_intersect($catsprinter1, $existing); $count = count($result); if ($count > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where rowid=$line->rowid"; + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where rowid=".$line->id; $db->query($sql); $order_receipt_printer1 .= ''.$line->product_label.''.$line->qty; if (!empty($line->array_options['options_order_notes'])) $order_receipt_printer1 .= "
(".$line->array_options['options_order_notes'].")"; @@ -416,7 +416,7 @@ if ($action == "order" and $placeid != 0) $result = array_intersect($catsprinter2, $existing); $count = count($result); if ($count > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where rowid=$line->rowid"; + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where rowid=".$line->id; $db->query($sql); $order_receipt_printer2 .= ''.$line->product_label.''.$line->qty; if (!empty($line->array_options['options_order_notes'])) $order_receipt_printer2 .= "
(".$line->array_options['options_order_notes'].")"; diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index d606fc1716c..5784fc22a3e 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -662,6 +662,7 @@ class Ticket extends CommonObject $line = new TicketsLine(); + $line->id = $obj->rowid; $line->rowid = $obj->rowid; $line->ref = $obj->ref; $line->track_id = $obj->track_id; @@ -2783,7 +2784,13 @@ class Ticket extends CommonObject */ class TicketsLine { - /** + /** + * @var int ID + * @deprecated + */ + public $rowid; + + /** * @var int ID */ public $id; diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php index 139c919bb18..1172d08f74d 100644 --- a/htdocs/variants/class/ProductAttribute.class.php +++ b/htdocs/variants/class/ProductAttribute.class.php @@ -86,12 +86,12 @@ class ProductAttribute return -1; } - $result = $this->db->fetch_object($query); + $obj = $this->db->fetch_object($query); - $this->id = $result->rowid; - $this->ref = $result->ref; - $this->label = $result->label; - $this->rang = $result->rang; + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->label = $obj->label; + $this->rang = $obj->rang; return 1; } diff --git a/htdocs/variants/class/ProductAttributeValue.class.php b/htdocs/variants/class/ProductAttributeValue.class.php index e2a99de90d2..0a26b3eace2 100644 --- a/htdocs/variants/class/ProductAttributeValue.class.php +++ b/htdocs/variants/class/ProductAttributeValue.class.php @@ -85,12 +85,12 @@ class ProductAttributeValue return -1; } - $result = $this->db->fetch_object($query); + $obj = $this->db->fetch_object($query); - $this->id = $result->rowid; - $this->fk_product_attribute = $result->fk_product_attribute; - $this->ref = $result->ref; - $this->value = $result->value; + $this->id = $obj->rowid; + $this->fk_product_attribute = $obj->fk_product_attribute; + $this->ref = $obj->ref; + $this->value = $obj->value; return 1; } diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 4849c44c898..4dfd40a8f53 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -104,14 +104,14 @@ class ProductCombination return -1; } - $result = $this->db->fetch_object($query); + $obj = $this->db->fetch_object($query); - $this->id = $result->rowid; - $this->fk_product_parent = $result->fk_product_parent; - $this->fk_product_child = $result->fk_product_child; - $this->variation_price = $result->variation_price; - $this->variation_price_percentage = $result->variation_price_percentage; - $this->variation_weight = $result->variation_weight; + $this->id = $obj->rowid; + $this->fk_product_parent = $obj->fk_product_parent; + $this->fk_product_child = $obj->fk_product_child; + $this->variation_price = $obj->variation_price; + $this->variation_price_percentage = $obj->variation_price_percentage; + $this->variation_weight = $obj->variation_weight; return 1; } diff --git a/htdocs/variants/class/ProductCombination2ValuePair.class.php b/htdocs/variants/class/ProductCombination2ValuePair.class.php index 4931efe54d5..e8ebbf57afd 100644 --- a/htdocs/variants/class/ProductCombination2ValuePair.class.php +++ b/htdocs/variants/class/ProductCombination2ValuePair.class.php @@ -128,12 +128,12 @@ class ProductCombination2ValuePair $return = array(); - while ($result = $this->db->fetch_object($query)) { + while ($obj = $this->db->fetch_object($query)) { $tmp = new ProductCombination2ValuePair($this->db); - $tmp->fk_prod_attr_val = $result->fk_prod_attr_val; - $tmp->fk_prod_attr = $result->fk_prod_attr; - $tmp->fk_prod_combination = $result->fk_prod_combination; - $tmp->id = $result->rowid; + $tmp->fk_prod_attr_val = $obj->fk_prod_attr_val; + $tmp->fk_prod_attr = $obj->fk_prod_attr; + $tmp->fk_prod_combination = $obj->fk_prod_combination; + $tmp->id = $obj->rowid; $return[] = $tmp; } diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 5e5163a71b6..f4d0762e3e1 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -322,7 +322,7 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '') { //var_dump($line); exit; $linesresp[]=array( - 'id'=>$line->rowid, + 'id'=>$line->id, 'type'=>$line->product_type, 'desc'=>dol_htmlcleanlastbr($line->desc), 'total_net'=>$line->total_ht, @@ -458,17 +458,17 @@ function getInvoicesForThirdParty($authentication, $idthirdparty) foreach($invoice->lines as $line) { $linesresp[]=array( - 'id'=>$line->rowid, - 'type'=>$line->product_type, - 'total_net'=>$line->total_ht, - 'total_vat'=>$line->total_tva, - 'total'=>$line->total_ttc, + 'id'=>$line->id, + 'type'=>$line->product_type, + 'total_net'=>$line->total_ht, + 'total_vat'=>$line->total_tva, + 'total'=>$line->total_ttc, 'vat_rate'=>$line->tva_tx, 'qty'=>$line->qty, - 'unitprice'=> $line->subprice, - 'date_start'=> $line->date_start?dol_print_date($line->date_start, 'dayrfc'):'', - 'date_end'=> $line->date_end?dol_print_date($line->date_end, 'dayrfc'):'', - 'product_id'=>$line->fk_product, + 'unitprice'=> $line->subprice, + 'date_start'=> $line->date_start?dol_print_date($line->date_start, 'dayrfc'):'', + 'date_end'=> $line->date_end?dol_print_date($line->date_end, 'dayrfc'):'', + 'product_id'=>$line->fk_product, 'product_ref'=>$line->product_ref, 'product_label'=>$line->product_label, 'product_desc'=>$line->product_desc,