From 4aab805b4edfbb536690b2c279e0078374d7b165 Mon Sep 17 00:00:00 2001 From: Laurent Magnin Date: Fri, 16 Apr 2021 12:39:39 +0200 Subject: [PATCH 001/132] FIX:Add ticket substition template --- htdocs/core/lib/functions.lib.php | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2b981530834..c3ce5128f57 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6838,6 +6838,28 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, /*$substitutionarray['__MEMBER_NOTE_PUBLIC__'] = '__MEMBER_NOTE_PUBLIC__'; $substitutionarray['__MEMBER_NOTE_PRIVATE__'] = '__MEMBER_NOTE_PRIVATE__';*/ } +// add variables subtitutions ticket + if (!empty($conf->ticket->enabled) && (!is_object($object) || $object->element == 'ticket')) { + $substitutionarray['__TICKET_TRACKID__'] = '__TICKET_TRACKID__'; + $substitutionarray['__TICKET_REF__'] = '__TICKET_REF__'; + $substitutionarray['__TICKET_SUBJECT__'] = '__TICKET_SUBJECT__'; + $substitutionarray['__TICKET_TYPE__'] = '__TICKET_TYPE__'; + $substitutionarray['__TICKET_SEVERITY__'] = '__TICKET_SEVERITY__'; + $substitutionarray['__TICKET_CATEGORY__'] = '__TICKET_CATEGORY__'; + $substitutionarray['__TICKET_ANALYTIC_CODE__'] = '__TICKET_ANALYTIC_CODE__'; + $substitutionarray['__TICKET_MESSAGE__'] = '__TICKET_MESSAGE__'; + $substitutionarray['__TICKET_PROGRESSION__'] = '__TICKET_PROGRESSION__'; + $substitutionarray['__TICKET_USER_ASSIGN__'] = '__TICKET_USER_ASSIGN__'; + $substitutionarray['__TICKET_USER_CREATE__'] = '__TICKET_USER_CREATE__'; + + +} + + + + + + if (!empty($conf->recruitment->enabled) && (!is_object($object) || $object->element == 'candidature')) { $substitutionarray['__CANDIDATE_FULLNAME__'] = '__CANDIDATE_FULLNAME__'; $substitutionarray['__CANDIDATE_FIRSTNAME__'] = '__CANDIDATE_FIRSTNAME__'; @@ -7025,6 +7047,21 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__CONTRACT_LOWEST_EXPIRATION_DATE__'] = dol_print_date($datenextexpiration, 'dayrfc'); $substitutionarray['__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] = dol_print_date($datenextexpiration, 'standard'); } +// add substition variable for ticket + if (is_object($object) && $object->element == 'ticket') { + $substitutionarray['__TICKET_TRACKID__'] = $object->track_id; + $substitutionarray['__TICKET_REF__'] = $object->ref; + $substitutionarray['__TICKET_SUBJECT__'] = $object->subject; + $substitutionarray['__TICKET_TYPE__'] = $object->type_code; + $substitutionarray['__TICKET_SEVERITY__'] = $object->severity_code; + $substitutionarray['__TICKET_CATEGORY__'] = $object->category_code; // For backward compatibility + $substitutionarray['__TICKET_ANALYTIC_CODE__'] = $object->category_code; + $substitutionarray['__TICKET_MESSAGE__'] = $object->message; + $substitutionarray['__TICKET_PROGRESSION__'] = $object->progress; + $substitutionarray['__TICKET_USER_ASSIGN__'] = dolGetFirstLastname($user->firstname, $user->lastname); + $substitutionarray['__TICKET_USER_CREATE__'] = dolGetFirstLastname($user->firstname, $user->lastname); + } + // Create dynamic tags for __EXTRAFIELD_FIELD__ if ($object->table_element && $object->id > 0) { From db0b00f93abcf4b804f5a9eaa25b76ada2902f0b Mon Sep 17 00:00:00 2001 From: Laurent Magnin Date: Fri, 2 Jul 2021 12:30:07 +0200 Subject: [PATCH 002/132] Standard ticket substitutions --- htdocs/core/lib/functions.lib.php | 26 +++++++++++++------------- htdocs/ticket/card.php | 25 ------------------------- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f25e13ee88c..149cbd8530a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6848,7 +6848,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, /*$substitutionarray['__MEMBER_NOTE_PUBLIC__'] = '__MEMBER_NOTE_PUBLIC__'; $substitutionarray['__MEMBER_NOTE_PRIVATE__'] = '__MEMBER_NOTE_PRIVATE__';*/ } -// add variables subtitutions ticket + // add variables subtitutions ticket if (!empty($conf->ticket->enabled) && (!is_object($object) || $object->element == 'ticket')) { $substitutionarray['__TICKET_TRACKID__'] = '__TICKET_TRACKID__'; $substitutionarray['__TICKET_REF__'] = '__TICKET_REF__'; @@ -6861,14 +6861,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__TICKET_PROGRESSION__'] = '__TICKET_PROGRESSION__'; $substitutionarray['__TICKET_USER_ASSIGN__'] = '__TICKET_USER_ASSIGN__'; $substitutionarray['__TICKET_USER_CREATE__'] = '__TICKET_USER_CREATE__'; - - -} - - - - - + } if (!empty($conf->recruitment->enabled) && (!is_object($object) || $object->element == 'candidature')) { $substitutionarray['__CANDIDATE_FULLNAME__'] = '__CANDIDATE_FULLNAME__'; @@ -7058,7 +7051,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__CONTRACT_LOWEST_EXPIRATION_DATE__'] = dol_print_date($datenextexpiration, 'dayrfc'); $substitutionarray['__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] = dol_print_date($datenextexpiration, 'standard'); } -// add substition variable for ticket + // add substition variable for ticket if (is_object($object) && $object->element == 'ticket') { $substitutionarray['__TICKET_TRACKID__'] = $object->track_id; $substitutionarray['__TICKET_REF__'] = $object->ref; @@ -7069,10 +7062,17 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__TICKET_ANALYTIC_CODE__'] = $object->category_code; $substitutionarray['__TICKET_MESSAGE__'] = $object->message; $substitutionarray['__TICKET_PROGRESSION__'] = $object->progress; - $substitutionarray['__TICKET_USER_ASSIGN__'] = dolGetFirstLastname($user->firstname, $user->lastname); - $substitutionarray['__TICKET_USER_CREATE__'] = dolGetFirstLastname($user->firstname, $user->lastname); - } + $userstat = new User($db); + if ($object->fk_user_assign > 0) { + $userstat->fetch($object->fk_user_assign); + $substitutionarray['__TICKET_USER_ASSIGN__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); + } + if ($object->fk_user_create > 0) { + $userstat->fetch($object->fk_user_create); + $substitutionarray['__TICKET_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); + } + } // Create dynamic tags for __EXTRAFIELD_FIELD__ if ($object->table_element && $object->id > 0) { diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 5faa7b201b7..7de6ea2d966 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -1347,31 +1347,6 @@ if ($action == 'create' || $action == 'presend') { $morehtmlright = ''; $help = ""; $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude, $object); - if ($object->fk_soc > 0) { - $substitutionarray['__THIRDPARTY_NAME__'] = $object->thirdparty->name; - } - $substitutionarray['__USER_SIGNATURE__'] = $user->signature; - $substitutionarray['__TICKET_TRACKID__'] = $object->track_id; - $substitutionarray['__TICKET_REF__'] = $object->ref; - $substitutionarray['__TICKET_SUBJECT__'] = $object->subject; - $substitutionarray['__TICKET_TYPE__'] = $object->type_code; - $substitutionarray['__TICKET_SEVERITY__'] = $object->severity_code; - $substitutionarray['__TICKET_CATEGORY__'] = $object->category_code; // For backward compatibility - $substitutionarray['__TICKET_ANALYTIC_CODE__'] = $object->category_code; - $substitutionarray['__TICKET_MESSAGE__'] = $object->message; - $substitutionarray['__TICKET_PROGRESSION__'] = $object->progress; - if ($object->fk_user_assign > 0) { - $userstat->fetch($object->fk_user_assign); - $substitutionarray['__TICKET_USER_ASSIGN__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); - } - - if ($object->fk_user_create > 0) { - $userstat->fetch($object->fk_user_create); - $substitutionarray['__TICKET_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); - } - foreach ($substitutionarray as $key => $val) { - $help .= $key.' -> '.$langs->trans($val).'
'; - } $morehtmlright .= $form->textwithpicto(''.$langs->trans("TicketMessageSubstitutionReplacedByGenericValues").'', $help, 1, 'helpclickable', '', 0, 3, 'helpsubstitution'); print '
'; From 5f40c2e9dde572e872796fc1d40538cc603867a0 Mon Sep 17 00:00:00 2001 From: Laurent Magnin Date: Fri, 19 Nov 2021 17:08:07 +0100 Subject: [PATCH 003/132] Update functions.lib.php --- htdocs/core/lib/functions.lib.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 648a2e6b0dc..f3a7a6116e9 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6992,7 +6992,6 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, // add variables subtitutions ticket if (!empty($conf->ticket->enabled) && (!is_object($object) || $object->element == 'ticket')) { $substitutionarray['__TICKET_TRACKID__'] = '__TICKET_TRACKID__'; - $substitutionarray['__TICKET_REF__'] = '__TICKET_REF__'; $substitutionarray['__TICKET_SUBJECT__'] = '__TICKET_SUBJECT__'; $substitutionarray['__TICKET_TYPE__'] = '__TICKET_TYPE__'; $substitutionarray['__TICKET_SEVERITY__'] = '__TICKET_SEVERITY__'; @@ -7001,7 +7000,6 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__TICKET_MESSAGE__'] = '__TICKET_MESSAGE__'; $substitutionarray['__TICKET_PROGRESSION__'] = '__TICKET_PROGRESSION__'; $substitutionarray['__TICKET_USER_ASSIGN__'] = '__TICKET_USER_ASSIGN__'; - $substitutionarray['__TICKET_USER_CREATE__'] = '__TICKET_USER_CREATE__'; } if (!empty($conf->recruitment->enabled) && (!is_object($object) || $object->element == 'candidature')) { From c8c6d5c1d24f5e9f091ff789f8fdb523a5522085 Mon Sep 17 00:00:00 2001 From: Laurent Magnin Date: Fri, 19 Nov 2021 17:09:51 +0100 Subject: [PATCH 004/132] Update functions.lib.php --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f3a7a6116e9..f2c968412b2 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7194,7 +7194,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, // add substition variable for ticket if (is_object($object) && $object->element == 'ticket') { $substitutionarray['__TICKET_TRACKID__'] = $object->track_id; - $substitutionarray['__TICKET_REF__'] = $object->ref; + $substitutionarray['__REF__'] = $object->ref; $substitutionarray['__TICKET_SUBJECT__'] = $object->subject; $substitutionarray['__TICKET_TYPE__'] = $object->type_code; $substitutionarray['__TICKET_SEVERITY__'] = $object->severity_code; @@ -7210,7 +7210,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, if ($object->fk_user_create > 0) { $userstat->fetch($object->fk_user_create); - $substitutionarray['__TICKET_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); + $substitutionarray['__USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); } } From 812e5a3b72b4c7aeaa6a5e6c0c2681a3706012c0 Mon Sep 17 00:00:00 2001 From: alsoft10 Date: Mon, 13 Dec 2021 16:02:27 +0530 Subject: [PATCH 005/132] Feature update : #19569 --- .../class/emailcollector.class.php | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index f4341109000..7e97cf9b110 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -2067,6 +2067,14 @@ class EmailCollector extends CommonObject $errorforactions++; $this->error = 'Failed to create ticket: '.$langs->trans($tickettocreate->error); $this->errors = $tickettocreate->errors; + } else { + if($attachments) { + $destdir = $conf->ticket->dir_output.'/'.$tickettocreate->ref; + if (!dol_is_dir($destdir)) { + dol_mkdir($destdir); + $this->getmsg($connection, $imapemail, $destdir); + } + } } } } @@ -2290,7 +2298,7 @@ class EmailCollector extends CommonObject * @param string $mid prefix * @return array Array with number and object */ - private function getmsg($mbox, $mid) + private function getmsg($mbox, $mid, $destdir='') { // input $mbox = IMAP stream, $mid = message id // output all the following: @@ -2311,7 +2319,7 @@ class EmailCollector extends CommonObject } else { // multipart: cycle through each part foreach ($s->parts as $partno0 => $p) { - $this->getpart($mbox, $mid, $p, $partno0 + 1); + $this->getpart($mbox, $mid, $p, $partno0 + 1, $destdir); } } } @@ -2340,7 +2348,7 @@ class EmailCollector extends CommonObject * @param string $partno Partno * @return void */ - private function getpart($mbox, $mid, $p, $partno) + private function getpart($mbox, $mid, $p, $partno, $destdir='') { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple global $htmlmsg, $plainmsg, $charset, $attachments; @@ -2378,6 +2386,39 @@ class EmailCollector extends CommonObject $filename = ($params['filename']) ? $params['filename'] : $params['name']; // filename may be encoded, so see imap_mime_header_decode() $attachments[$filename] = $data; // this is a problem if two files have same name + + // Get file name (with extension) + $file_name_complete = $params['filename']; + + + $destination = $destdir.'/'.$file_name_complete; + + // Extract file extension + $extension = pathinfo($file_name_complete, PATHINFO_EXTENSION); + + // Extract file name without extension + $file_name = pathinfo($file_name_complete, PATHINFO_FILENAME); + + // Save an original file name variable to track while renaming if file already exists + $file_name_original = $file_name; + + // Increment file name by 1 + $num = 1; + + /** + * Check if the same file name already exists in the upload folder, + * append increment number to the original filename + */ + while (file_exists($destdir."/" . $file_name . "." . $extension)) { + $file_name = (string) $file_name_original . ' (' . $num . ')'; + $file_name_complete = $file_name . "." . $extension; + $destination = $destdir.'/'.$file_name_complete; + $num++; + } + + + file_put_contents($destination, $data); + } // TEXT From 90f25ab21ac0759c4119386f654d87f5979b6ea8 Mon Sep 17 00:00:00 2001 From: Jay Yeo Date: Fri, 17 Dec 2021 12:09:14 +0700 Subject: [PATCH 006/132] FIX supplier_proposal when line update price U.P change 0 modify --- htdocs/supplier_proposal/class/supplier_proposal.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index ea10b4d7137..b239b6cc3da 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -725,6 +725,7 @@ class SupplierProposal extends CommonObject $total_ttc = $tabprice[2]; $total_localtax1 = $tabprice[9]; $total_localtax2 = $tabprice[10]; + $pu = $pu_ht = $tabprice[3]; // MultiCurrency $multicurrency_total_ht = $tabprice[16]; From 5dd0aa05495a500582ca7153c90c360948cc197c Mon Sep 17 00:00:00 2001 From: alsoft10 Date: Thu, 23 Dec 2021 18:14:12 +0530 Subject: [PATCH 007/132] Feature Update #19678 --- htdocs/main.inc.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 9753f4b3d83..be964015f75 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1744,6 +1744,14 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr } } } + + //If you want to load custom javascript file from your selected theme directory + if (!empty($conf->global->ALLOW_THEME_JS)) { + $theme_js = dol_buildpath('/theme/'.$conf->theme.'/'.$conf->theme.'.js', 0); + if (file_exists($theme_js)) { + print ''."\n"; + } + } if (!empty($head)) { print $head."\n"; From a2cb020394be4a2d2d955359f07ac8170cfd88ff Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 23 Dec 2021 12:45:26 +0000 Subject: [PATCH 008/132] Fixing style errors. --- .../emailcollector/class/emailcollector.class.php | 13 ++++++------- htdocs/main.inc.php | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 7e97cf9b110..243b93a55c3 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -2068,7 +2068,7 @@ class EmailCollector extends CommonObject $this->error = 'Failed to create ticket: '.$langs->trans($tickettocreate->error); $this->errors = $tickettocreate->errors; } else { - if($attachments) { + if ($attachments) { $destdir = $conf->ticket->dir_output.'/'.$tickettocreate->ref; if (!dol_is_dir($destdir)) { dol_mkdir($destdir); @@ -2298,7 +2298,7 @@ class EmailCollector extends CommonObject * @param string $mid prefix * @return array Array with number and object */ - private function getmsg($mbox, $mid, $destdir='') + private function getmsg($mbox, $mid, $destdir = '') { // input $mbox = IMAP stream, $mid = message id // output all the following: @@ -2348,7 +2348,7 @@ class EmailCollector extends CommonObject * @param string $partno Partno * @return void */ - private function getpart($mbox, $mid, $p, $partno, $destdir='') + private function getpart($mbox, $mid, $p, $partno, $destdir = '') { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple global $htmlmsg, $plainmsg, $charset, $attachments; @@ -2386,11 +2386,11 @@ class EmailCollector extends CommonObject $filename = ($params['filename']) ? $params['filename'] : $params['name']; // filename may be encoded, so see imap_mime_header_decode() $attachments[$filename] = $data; // this is a problem if two files have same name - + // Get file name (with extension) $file_name_complete = $params['filename']; - + $destination = $destdir.'/'.$file_name_complete; // Extract file extension @@ -2407,7 +2407,7 @@ class EmailCollector extends CommonObject /** * Check if the same file name already exists in the upload folder, - * append increment number to the original filename + * append increment number to the original filename */ while (file_exists($destdir."/" . $file_name . "." . $extension)) { $file_name = (string) $file_name_original . ' (' . $num . ')'; @@ -2418,7 +2418,6 @@ class EmailCollector extends CommonObject file_put_contents($destination, $data); - } // TEXT diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index be964015f75..345ef7b496e 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1744,9 +1744,9 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr } } } - + //If you want to load custom javascript file from your selected theme directory - if (!empty($conf->global->ALLOW_THEME_JS)) { + if (!empty($conf->global->ALLOW_THEME_JS)) { $theme_js = dol_buildpath('/theme/'.$conf->theme.'/'.$conf->theme.'.js', 0); if (file_exists($theme_js)) { print ''."\n"; From 82b14caa130d1ebf52f545e5b036ab0f81905613 Mon Sep 17 00:00:00 2001 From: BENKE Charlene <1179011+defrance@users.noreply.github.com> Date: Thu, 20 Jan 2022 17:06:03 +0100 Subject: [PATCH 009/132] FIX if we have PRODUCT_USE_UNITS, task fail we need public function getLabelOfUnit($type = 'long') fonction or printlineOriginLine fail --- htdocs/projet/class/task.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index d0b27caf326..f8f3b94eb45 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2014 Marcos García * Copyright (C) 2018 Frédéric France * Copyright (C) 2020 Juanjo Menent + * Copyright (C) 2022 Charlene Benke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; /** * Class to manage tasks */ -class Task extends CommonObject +class Task extends CommonObjectLine { /** * @var string ID to identify managed object From 7ca333f4d7c79df70be61520d26dfab62d813708 Mon Sep 17 00:00:00 2001 From: kamel Date: Mon, 24 Jan 2022 17:04:46 +0100 Subject: [PATCH 010/132] Fix the vat report by month and rate (with also the vat src code) --- htdocs/core/lib/tax.lib.php | 275 +++++++++++++++++++----------------- 1 file changed, 145 insertions(+), 130 deletions(-) diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 40e50544b22..3249166c083 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -696,7 +696,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')) { // Count on delivery date (use invoice date as delivery is unknown) - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef,"; @@ -739,7 +739,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " ORDER BY d.rowid, d.".$fk_facture; } else { // Count on payments date - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef,"; @@ -799,66 +799,71 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $rate = -1; $oldrowid = ''; while ($assoc = $db->fetch_array($resql)) { + $rate_key = $assoc['rate']; + if ($f_rate == 'tva_tx' && !empty($assoc['vat_src_code']) && !preg_match('/\(/', $rate_key)) { + $rate_key .= ' (' . $assoc['vat_src_code'] . ')'; + } + // Code to avoid warnings when array entry not defined - if (!isset($list[$assoc['rate']]['totalht'])) { - $list[$assoc['rate']]['totalht'] = 0; + if (!isset($list[$rate_key]['totalht'])) { + $list[$rate_key]['totalht'] = 0; } - if (!isset($list[$assoc['rate']]['vat'])) { - $list[$assoc['rate']]['vat'] = 0; + if (!isset($list[$rate_key]['vat'])) { + $list[$rate_key]['vat'] = 0; } - if (!isset($list[$assoc['rate']]['localtax1'])) { - $list[$assoc['rate']]['localtax1'] = 0; + if (!isset($list[$rate_key]['localtax1'])) { + $list[$rate_key]['localtax1'] = 0; } - if (!isset($list[$assoc['rate']]['localtax2'])) { - $list[$assoc['rate']]['localtax2'] = 0; + if (!isset($list[$rate_key]['localtax2'])) { + $list[$rate_key]['localtax2'] = 0; } if ($assoc['rowid'] != $oldrowid) { // Si rupture sur d.rowid $oldrowid = $assoc['rowid']; - $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; - $list[$assoc['rate']]['vat'] += $assoc['total_vat']; - $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; + $list[$rate_key]['totalht'] += $assoc['total_ht']; + $list[$rate_key]['vat'] += $assoc['total_vat']; + $list[$rate_key]['localtax1'] += $assoc['total_localtax1']; + $list[$rate_key]['localtax2'] += $assoc['total_localtax2']; } - $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; - $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; - $list[$assoc['rate']]['datef'][] = $db->jdate($assoc['datef']); - $list[$assoc['rate']]['datep'][] = $db->jdate($assoc['datep']); + $list[$rate_key]['dtotal_ttc'][] = $assoc['total_ttc']; + $list[$rate_key]['dtype'][] = $assoc['dtype']; + $list[$rate_key]['datef'][] = $db->jdate($assoc['datef']); + $list[$rate_key]['datep'][] = $db->jdate($assoc['datep']); - $list[$assoc['rate']]['company_name'][] = $assoc['company_name']; - $list[$assoc['rate']]['company_id'][] = $assoc['company_id']; - $list[$assoc['rate']]['company_alias'][] = $assoc['company_alias']; - $list[$assoc['rate']]['company_email'][] = $assoc['company_email']; - $list[$assoc['rate']]['company_tva_intra'][] = $assoc['company_tva_intra']; - $list[$assoc['rate']]['company_client'][] = $assoc['company_client']; - $list[$assoc['rate']]['company_fournisseur'][] = $assoc['company_fournisseur']; - $list[$assoc['rate']]['company_customer_code'][] = $assoc['company_customer_code']; - $list[$assoc['rate']]['company_supplier_code'][] = $assoc['company_supplier_code']; - $list[$assoc['rate']]['company_customer_accounting_code'][] = $assoc['company_customer_accounting_code']; - $list[$assoc['rate']]['company_supplier_accounting_code'][] = $assoc['company_supplier_accounting_code']; - $list[$assoc['rate']]['company_status'][] = $assoc['company_status']; + $list[$rate_key]['company_name'][] = $assoc['company_name']; + $list[$rate_key]['company_id'][] = $assoc['company_id']; + $list[$rate_key]['company_alias'][] = $assoc['company_alias']; + $list[$rate_key]['company_email'][] = $assoc['company_email']; + $list[$rate_key]['company_tva_intra'][] = $assoc['company_tva_intra']; + $list[$rate_key]['company_client'][] = $assoc['company_client']; + $list[$rate_key]['company_fournisseur'][] = $assoc['company_fournisseur']; + $list[$rate_key]['company_customer_code'][] = $assoc['company_customer_code']; + $list[$rate_key]['company_supplier_code'][] = $assoc['company_supplier_code']; + $list[$rate_key]['company_customer_accounting_code'][] = $assoc['company_customer_accounting_code']; + $list[$rate_key]['company_supplier_accounting_code'][] = $assoc['company_supplier_accounting_code']; + $list[$rate_key]['company_status'][] = $assoc['company_status']; - $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); - $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); + $list[$rate_key]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$rate_key]['ddate_end'][] = $db->jdate($assoc['date_end']); - $list[$assoc['rate']]['facid'][] = $assoc['facid']; - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; - $list[$assoc['rate']]['type'][] = $assoc['type']; - $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$rate_key]['facid'][] = $assoc['facid']; + $list[$rate_key]['facnum'][] = $assoc['facnum']; + $list[$rate_key]['type'][] = $assoc['type']; + $list[$rate_key]['ftotal_ttc'][] = $assoc['ftotal_ttc']; + $list[$rate_key]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; - $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; - $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; + $list[$rate_key]['totalht_list'][] = $assoc['total_ht']; + $list[$rate_key]['vat_list'][] = $assoc['total_vat']; + $list[$rate_key]['localtax1_list'][] = $assoc['total_localtax1']; + $list[$rate_key]['localtax2_list'][] = $assoc['total_localtax2']; - $list[$assoc['rate']]['pid'][] = $assoc['pid']; - $list[$assoc['rate']]['pref'][] = $assoc['pref']; - $list[$assoc['rate']]['ptype'][] = $assoc['ptype']; + $list[$rate_key]['pid'][] = $assoc['pid']; + $list[$rate_key]['pref'][] = $assoc['pref']; + $list[$rate_key]['ptype'][] = $assoc['ptype']; - $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; - $list[$assoc['rate']]['payment_ref'][] = $assoc['payment_ref']; - $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; + $list[$rate_key]['payment_id'][] = $assoc['payment_id']; + $list[$rate_key]['payment_ref'][] = $assoc['payment_ref']; + $list[$rate_key]['payment_amount'][] = $assoc['payment_amount']; $rate = $assoc['rate']; } @@ -876,7 +881,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice') || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { // Count on invoice date - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef,"; @@ -919,7 +924,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " ORDER BY d.rowid, d.".$fk_facture; } else { // Count on payments date - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef,"; @@ -979,66 +984,71 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $rate = -1; $oldrowid = ''; while ($assoc = $db->fetch_array($resql)) { + $rate_key = $assoc['rate']; + if ($f_rate == 'tva_tx' && !empty($assoc['vat_src_code']) && !preg_match('/\(/', $rate_key)) { + $rate_key .= ' (' . $assoc['vat_src_code'] . ')'; + } + // Code to avoid warnings when array entry not defined - if (!isset($list[$assoc['rate']]['totalht'])) { - $list[$assoc['rate']]['totalht'] = 0; + if (!isset($list[$rate_key]['totalht'])) { + $list[$rate_key]['totalht'] = 0; } - if (!isset($list[$assoc['rate']]['vat'])) { - $list[$assoc['rate']]['vat'] = 0; + if (!isset($list[$rate_key]['vat'])) { + $list[$rate_key]['vat'] = 0; } - if (!isset($list[$assoc['rate']]['localtax1'])) { - $list[$assoc['rate']]['localtax1'] = 0; + if (!isset($list[$rate_key]['localtax1'])) { + $list[$rate_key]['localtax1'] = 0; } - if (!isset($list[$assoc['rate']]['localtax2'])) { - $list[$assoc['rate']]['localtax2'] = 0; + if (!isset($list[$rate_key]['localtax2'])) { + $list[$rate_key]['localtax2'] = 0; } if ($assoc['rowid'] != $oldrowid) { // Si rupture sur d.rowid $oldrowid = $assoc['rowid']; - $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; - $list[$assoc['rate']]['vat'] += $assoc['total_vat']; - $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; + $list[$rate_key]['totalht'] += $assoc['total_ht']; + $list[$rate_key]['vat'] += $assoc['total_vat']; + $list[$rate_key]['localtax1'] += $assoc['total_localtax1']; + $list[$rate_key]['localtax2'] += $assoc['total_localtax2']; } - $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; - $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; - $list[$assoc['rate']]['datef'][] = $db->jdate($assoc['datef']); - $list[$assoc['rate']]['datep'][] = $db->jdate($assoc['datep']); + $list[$rate_key]['dtotal_ttc'][] = $assoc['total_ttc']; + $list[$rate_key]['dtype'][] = $assoc['dtype']; + $list[$rate_key]['datef'][] = $db->jdate($assoc['datef']); + $list[$rate_key]['datep'][] = $db->jdate($assoc['datep']); - $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); - $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); + $list[$rate_key]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$rate_key]['ddate_end'][] = $db->jdate($assoc['date_end']); - $list[$assoc['rate']]['company_name'][] = $assoc['company_name']; - $list[$assoc['rate']]['company_id'][] = $assoc['company_id']; - $list[$assoc['rate']]['company_alias'][] = $assoc['company_alias']; - $list[$assoc['rate']]['company_email'][] = $assoc['company_email']; - $list[$assoc['rate']]['company_tva_intra'][] = $assoc['company_tva_intra']; - $list[$assoc['rate']]['company_client'][] = $assoc['company_client']; - $list[$assoc['rate']]['company_fournisseur'][] = $assoc['company_fournisseur']; - $list[$assoc['rate']]['company_customer_code'][] = $assoc['company_customer_code']; - $list[$assoc['rate']]['company_supplier_code'][] = $assoc['company_supplier_code']; - $list[$assoc['rate']]['company_customer_accounting_code'][] = $assoc['company_customer_accounting_code']; - $list[$assoc['rate']]['company_supplier_accounting_code'][] = $assoc['company_supplier_accounting_code']; - $list[$assoc['rate']]['company_status'][] = $assoc['company_status']; + $list[$rate_key]['company_name'][] = $assoc['company_name']; + $list[$rate_key]['company_id'][] = $assoc['company_id']; + $list[$rate_key]['company_alias'][] = $assoc['company_alias']; + $list[$rate_key]['company_email'][] = $assoc['company_email']; + $list[$rate_key]['company_tva_intra'][] = $assoc['company_tva_intra']; + $list[$rate_key]['company_client'][] = $assoc['company_client']; + $list[$rate_key]['company_fournisseur'][] = $assoc['company_fournisseur']; + $list[$rate_key]['company_customer_code'][] = $assoc['company_customer_code']; + $list[$rate_key]['company_supplier_code'][] = $assoc['company_supplier_code']; + $list[$rate_key]['company_customer_accounting_code'][] = $assoc['company_customer_accounting_code']; + $list[$rate_key]['company_supplier_accounting_code'][] = $assoc['company_supplier_accounting_code']; + $list[$rate_key]['company_status'][] = $assoc['company_status']; - $list[$assoc['rate']]['facid'][] = $assoc['facid']; - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; - $list[$assoc['rate']]['type'][] = $assoc['type']; - $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$rate_key]['facid'][] = $assoc['facid']; + $list[$rate_key]['facnum'][] = $assoc['facnum']; + $list[$rate_key]['type'][] = $assoc['type']; + $list[$rate_key]['ftotal_ttc'][] = $assoc['ftotal_ttc']; + $list[$rate_key]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; - $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; - $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; + $list[$rate_key]['totalht_list'][] = $assoc['total_ht']; + $list[$rate_key]['vat_list'][] = $assoc['total_vat']; + $list[$rate_key]['localtax1_list'][] = $assoc['total_localtax1']; + $list[$rate_key]['localtax2_list'][] = $assoc['total_localtax2']; - $list[$assoc['rate']]['pid'][] = $assoc['pid']; - $list[$assoc['rate']]['pref'][] = $assoc['pref']; - $list[$assoc['rate']]['ptype'][] = $assoc['ptype']; + $list[$rate_key]['pid'][] = $assoc['pid']; + $list[$rate_key]['pref'][] = $assoc['pref']; + $list[$rate_key]['ptype'][] = $assoc['ptype']; - $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; - $list[$assoc['rate']]['payment_ref'][] = $assoc['payment_ref']; - $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; + $list[$rate_key]['payment_id'][] = $assoc['payment_id']; + $list[$rate_key]['payment_ref'][] = $assoc['payment_ref']; + $list[$rate_key]['payment_amount'][] = $assoc['payment_amount']; $rate = $assoc['rate']; } @@ -1056,7 +1066,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql = ''; // Count on payments date - $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,"; $sql .= " d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, "; $sql .= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,"; $sql .= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,"; @@ -1101,55 +1111,60 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $rate = -1; $oldrowid = ''; while ($assoc = $db->fetch_array($resql)) { + $rate_key = $assoc['rate']; + if ($f_rate == 'tva_tx' && !empty($assoc['vat_src_code']) && !preg_match('/\(/', $rate_key)) { + $rate_key .= ' (' . $assoc['vat_src_code'] . ')'; + } + // Code to avoid warnings when array entry not defined - if (!isset($list[$assoc['rate']]['totalht'])) { - $list[$assoc['rate']]['totalht'] = 0; + if (!isset($list[$rate_key]['totalht'])) { + $list[$rate_key]['totalht'] = 0; } - if (!isset($list[$assoc['rate']]['vat'])) { - $list[$assoc['rate']]['vat'] = 0; + if (!isset($list[$rate_key]['vat'])) { + $list[$rate_key]['vat'] = 0; } - if (!isset($list[$assoc['rate']]['localtax1'])) { - $list[$assoc['rate']]['localtax1'] = 0; + if (!isset($list[$rate_key]['localtax1'])) { + $list[$rate_key]['localtax1'] = 0; } - if (!isset($list[$assoc['rate']]['localtax2'])) { - $list[$assoc['rate']]['localtax2'] = 0; + if (!isset($list[$rate_key]['localtax2'])) { + $list[$rate_key]['localtax2'] = 0; } if ($assoc['rowid'] != $oldrowid) { // Si rupture sur d.rowid $oldrowid = $assoc['rowid']; - $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; - $list[$assoc['rate']]['vat'] += $assoc['total_vat']; - $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; + $list[$rate_key]['totalht'] += $assoc['total_ht']; + $list[$rate_key]['vat'] += $assoc['total_vat']; + $list[$rate_key]['localtax1'] += $assoc['total_localtax1']; + $list[$rate_key]['localtax2'] += $assoc['total_localtax2']; } - $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; - $list[$assoc['rate']]['dtype'][] = 'ExpenseReportPayment'; - $list[$assoc['rate']]['datef'][] = $assoc['datef']; - $list[$assoc['rate']]['company_name'][] = ''; - $list[$assoc['rate']]['company_id'][] = ''; - $list[$assoc['rate']]['user_id'][] = $assoc['fk_user_author']; - $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); - $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); + $list[$rate_key]['dtotal_ttc'][] = $assoc['total_ttc']; + $list[$rate_key]['dtype'][] = 'ExpenseReportPayment'; + $list[$rate_key]['datef'][] = $assoc['datef']; + $list[$rate_key]['company_name'][] = ''; + $list[$rate_key]['company_id'][] = ''; + $list[$rate_key]['user_id'][] = $assoc['fk_user_author']; + $list[$rate_key]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$rate_key]['ddate_end'][] = $db->jdate($assoc['date_end']); - $list[$assoc['rate']]['facid'][] = $assoc['facid']; - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; - $list[$assoc['rate']]['type'][] = $assoc['type']; - $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$rate_key]['facid'][] = $assoc['facid']; + $list[$rate_key]['facnum'][] = $assoc['facnum']; + $list[$rate_key]['type'][] = $assoc['type']; + $list[$rate_key]['ftotal_ttc'][] = $assoc['ftotal_ttc']; + $list[$rate_key]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; - $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; - $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; + $list[$rate_key]['totalht_list'][] = $assoc['total_ht']; + $list[$rate_key]['vat_list'][] = $assoc['total_vat']; + $list[$rate_key]['localtax1_list'][] = $assoc['total_localtax1']; + $list[$rate_key]['localtax2_list'][] = $assoc['total_localtax2']; - $list[$assoc['rate']]['pid'][] = $assoc['pid']; - $list[$assoc['rate']]['pref'][] = $assoc['pref']; - $list[$assoc['rate']]['ptype'][] = 'ExpenseReportPayment'; + $list[$rate_key]['pid'][] = $assoc['pid']; + $list[$rate_key]['pref'][] = $assoc['pref']; + $list[$rate_key]['ptype'][] = 'ExpenseReportPayment'; - $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; - $list[$assoc['rate']]['payment_ref'][] = $assoc['payment_ref']; - $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; + $list[$rate_key]['payment_id'][] = $assoc['payment_id']; + $list[$rate_key]['payment_ref'][] = $assoc['payment_ref']; + $list[$rate_key]['payment_amount'][] = $assoc['payment_amount']; $rate = $assoc['rate']; } From 2b5bc29d1baf549aab10e11f01ea2f1e69b5f40e Mon Sep 17 00:00:00 2001 From: lvessiller Date: Tue, 25 Jan 2022 10:00:33 +0100 Subject: [PATCH 011/132] NEW stock filter in reassort lists --- htdocs/product/reassort.php | 123 ++++++++++++++++----------------- htdocs/product/reassortlot.php | 96 +++++++++++++++---------- 2 files changed, 119 insertions(+), 100 deletions(-) diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 62bfd626f82..23258aa1e86 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -39,14 +39,14 @@ $action = GETPOST('action', 'aZ09'); $sref = GETPOST("sref", 'alpha'); $snom = GETPOST("snom", 'alpha'); $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); -$type = GETPOST("type", "int"); +$type = GETPOSTISSET('type') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT; $search_barcode = GETPOST("search_barcode", 'alpha'); -$catid = GETPOST('catid', 'int'); $toolowstock = GETPOST('toolowstock'); $tosell = GETPOST("tosell"); $tobuy = GETPOST("tobuy"); $fourn_id = GETPOST("fourn_id", 'int'); $sbarcode = GETPOST("sbarcode", 'int'); +$search_stock_physique = GETPOST('search_stock_physique', 'alpha'); $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); @@ -68,7 +68,11 @@ $offset = $limit * $page; // Load sale and categ filters $search_sale = GETPOST("search_sale"); -$search_categ = GETPOST("search_categ"); +if (GETPOSTISSET('catid')) { + $search_categ = GETPOST('catid', 'int'); +} else { + $search_categ = GETPOST('search_categ', 'int'); +} // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = GETPOST("canvas"); @@ -111,11 +115,10 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $tobuy = ""; $search_sale = ""; $search_categ = ""; - $type = ""; - $catid = ''; $toolowstock = ''; $fourn_id = ''; $sbarcode = ''; + $search_stock_physique = ''; } @@ -146,13 +149,22 @@ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e ON s.fk_entrepot = e.rowid A if (!empty($conf->global->PRODUCT_USE_UNITS)) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_units as u on p.fk_unit = u.rowid'; } -// We'll need this table joined to the select in order to filter by categ -if ($search_categ) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; -} $sql .= " WHERE p.entity IN (".getEntity('product').")"; -if ($search_categ) { - $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ +if (!empty($search_categ) && $search_categ != '-1') { + $sql .= " AND "; + if ($search_categ == -2) { + $sql .= " NOT EXISTS "; + } else { + $sql .= " EXISTS "; + } + $sql .= "("; + $sql .= " SELECT cp.fk_categorie, cp.fk_product"; + $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_product as cp"; + $sql .= " WHERE cp.fk_product = p.rowid"; // Join for the needed table to filter by categ + if ($search_categ > 0) { + $sql .= " AND cp.fk_categorie = " . ((int) $search_categ); + } + $sql .= ")"; } if ($sall) { $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); @@ -183,24 +195,32 @@ if (!empty($tobuy)) { if (!empty($canvas)) { $sql .= " AND p.canvas = '".$db->escape($canvas)."'"; } -if ($catid > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $catid); -} if ($fourn_id > 0) { $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id); } -// Insert categ filter -if ($search_categ > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $search_categ); -} $sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,"; $sql .= " p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock"; // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; +$sql_having = ''; if ($toolowstock) { - $sql .= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte"; + $sql_having .= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte"; +} +if ($search_stock_physique != '') { + //$natural_search_physique = natural_search('HAVING SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1); + $natural_search_physique = natural_search('SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1); + $natural_search_physique = " " . substr($natural_search_physique, 1, -1); // remove first "(" and last ")" characters + if (!empty($sql_having)) { + $sql_having .= " AND"; + } else { + $sql_having .= " HAVING"; + } + $sql_having .= $natural_search_physique; +} +if (!empty($sql_having)) { + $sql .= $sql_having; } $sql .= $db->order($sortfield, $sortorder); @@ -253,7 +273,7 @@ if ($resql) { if ($tobuy) { $param .= "&tobuy=".urlencode($tobuy); } - if ($type) { + if ($type != '') { $param .= "&type=".urlencode($type); } if ($fourn_id) { @@ -268,7 +288,7 @@ if ($resql) { if ($search_sale) { $param .= "&search_sale=".urlencode($search_sale); } - if ($search_categ) { + if (!empty($search_categ) && $search_categ != '-1') { $param .= "&search_categ=".urlencode($search_categ); } if ($toolowstock) { @@ -277,8 +297,8 @@ if ($resql) { if ($sbarcode) { $param .= "&sbarcode=".urlencode($sbarcode); } - if ($catid) { - $param .= "&catid=".urlencode($catid); + if ($search_stock_physique) { + $param .= '&search_stock_physique=' . urlencode($search_stock_physique); } llxHeader("", $texte, $helpurl); @@ -292,10 +312,10 @@ if ($resql) { print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'product', 0, '', '', $limit); - if (!empty($catid)) { + if ($search_categ > 0) { print "
"; $c = new Categorie($db); - $c->fetch($catid); + $c->fetch($search_categ); $ways = $c->print_all_ways(' > ', 'product/reassort.php'); print " > ".$ways[0]."
\n"; print "

"; @@ -306,7 +326,7 @@ if ($resql) { if (!empty($conf->categorie->enabled)) { $moreforfilter .= '
'; $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); - $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ'); + $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ', 1); $moreforfilter .= '
'; } @@ -323,32 +343,6 @@ if ($resql) { print '
'; } - $param = ''; - if ($tosell) { - $param .= "&tosell=".urlencode($tosell); - } - if ($tobuy) { - $param .= "&tobuy=".urlencode($tobuy); - } - if ($type) { - $param .= "&type=".urlencode($type); - } - if ($fourn_id) { - $param .= "&fourn_id=".urlencode($fourn_id); - } - if ($snom) { - $param .= "&snom=".urlencode($snom); - } - if ($sref) { - $param .= "&sref=".urlencode($sref); - } - if ($toolowstock) { - $param .= "&toolowstock=".urlencode($toolowstock); - } - if ($search_categ) { - $param .= "&search_categ=".urlencode($search_categ); - } - $formProduct = new FormProduct($db); $formProduct->loadWarehouses(); $warehouses_list = $formProduct->cache_warehouses; @@ -378,7 +372,10 @@ if ($resql) { // Stock limit print ' '; print ' '; - print ' '; + // Physical stock + print ''; + print ''; + print ''; if ($virtualdiffersfromphysical) { print ' '; } @@ -396,14 +393,14 @@ if ($resql) { //Line for column titles print ""; - print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", $param, "", "", $sortfield, $sortorder); - print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", $param, "", "", $sortfield, $sortorder); + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", '', $param, "", $sortfield, $sortorder); + print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", '', $param, "", $sortfield, $sortorder); if (!empty($conf->service->enabled) && $type == 1) { - print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", $param, "", '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", '', $param, "", $sortfield, $sortorder, 'center '); } - print_liste_field_titre("StockLimit", $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", $param, "", '', $sortfield, $sortorder, 'right '); - print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock", $param, "", '', $sortfield, $sortorder, 'right '); - print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", $param, "", '', $sortfield, $sortorder, 'right '); + print_liste_field_titre("StockLimit", $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", '', $param, "", $sortfield, $sortorder, 'right '); + print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock", '', $param, "", $sortfield, $sortorder, 'right '); + print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", '', $param, "", $sortfield, $sortorder, 'right '); // Details per warehouse if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) { // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context) if ($nb_warehouse > 1) { @@ -413,15 +410,15 @@ if ($resql) { } } if ($virtualdiffersfromphysical) { - print_liste_field_titre("VirtualStock", $_SERVER["PHP_SELF"], "", $param, "", '', $sortfield, $sortorder, 'right ', 'VirtualStockDesc'); + print_liste_field_titre("VirtualStock", $_SERVER["PHP_SELF"], "", '', $param, "", $sortfield, $sortorder, 'right ', 'VirtualStockDesc'); } // Units if (!empty($conf->global->PRODUCT_USE_UNITS)) { - print_liste_field_titre("Unit", $_SERVER["PHP_SELF"], "unit_short", $param, "", 'align="right"', $sortfield, $sortorder); + print_liste_field_titre("Unit", $_SERVER["PHP_SELF"], "unit_short", '', $param, 'align="right"', $sortfield, $sortorder); } print_liste_field_titre(''); - print_liste_field_titre("ProductStatusOnSell", $_SERVER["PHP_SELF"], "p.tosell", $param, "", '', $sortfield, $sortorder, 'right '); - print_liste_field_titre("ProductStatusOnBuy", $_SERVER["PHP_SELF"], "p.tobuy", $param, "", '', $sortfield, $sortorder, 'right '); + print_liste_field_titre("ProductStatusOnSell", $_SERVER["PHP_SELF"], "p.tosell", '', $param, "", $sortfield, $sortorder, 'right '); + print_liste_field_titre("ProductStatusOnBuy", $_SERVER["PHP_SELF"], "p.tobuy", '', $param, "", $sortfield, $sortorder, 'right '); // Hook fields $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index 2bd62b2ce22..c5463e3e4e2 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -41,16 +41,16 @@ $action = GETPOST('action', 'aZ09'); $sref = GETPOST("sref", 'alpha'); $snom = GETPOST("snom", 'alpha'); $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); -$type = GETPOST("type", "int"); +$type = GETPOSTISSET('type') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT; $search_barcode = GETPOST("search_barcode", 'alpha'); $search_warehouse = GETPOST('search_warehouse', 'alpha'); $search_batch = GETPOST('search_batch', 'alpha'); -$catid = GETPOST('catid', 'int'); $toolowstock = GETPOST('toolowstock'); $tosell = GETPOST("tosell"); $tobuy = GETPOST("tobuy"); $fourn_id = GETPOST("fourn_id", 'int'); $sbarcode = GETPOST("sbarcode", 'int'); +$search_stock_physique = GETPOST('search_stock_physique', 'alpha'); $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); @@ -72,7 +72,11 @@ $offset = $limit * $page; // Load sale and categ filters $search_sale = GETPOST("search_sale"); -$search_categ = GETPOST("search_categ"); +if (GETPOSTISSET('catid')) { + $search_categ = GETPOST('catid', 'int'); +} else { + $search_categ = GETPOST('search_categ', 'int'); +} // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = GETPOST("canvas"); @@ -102,13 +106,12 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $tobuy = ""; $search_sale = ""; $search_categ = ""; - $type = ""; - $catid = ''; $toolowstock = ''; $search_batch = ''; $search_warehouse = ''; $fourn_id = ''; $sbarcode = ''; + $search_stock_physique = ''; } @@ -135,13 +138,22 @@ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as ps on p.rowid = ps.fk_pro $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e on ps.fk_entrepot = e.rowid'; // Link on unique key $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb on pb.fk_product_stock = ps.rowid'; // Detail for each lot on each warehouse $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch'; // Link on unique key -// We'll need this table joined to the select in order to filter by categ -if ($search_categ > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; -} $sql .= " WHERE p.entity IN (".getEntity('product').")"; -if ($search_categ > 0) { - $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ +if (!empty($search_categ) && $search_categ != '-1') { + $sql .= " AND "; + if ($search_categ == -2) { + $sql .= " NOT EXISTS "; + } else { + $sql .= " EXISTS "; + } + $sql .= "("; + $sql .= " SELECT cp.fk_categorie, cp.fk_product"; + $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_product as cp"; + $sql .= " WHERE cp.fk_product = p.rowid"; // Join for the needed table to filter by categ + if ($search_categ > 0) { + $sql .= " AND cp.fk_categorie = " . ((int) $search_categ); + } + $sql .= ")"; } if ($sall) { $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); @@ -172,16 +184,9 @@ if (!empty($tobuy)) { if (!empty($canvas)) { $sql .= " AND p.canvas = '".$db->escape($canvas)."'"; } -if ($catid > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $catid); -} if ($fourn_id > 0) { $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id); } -// Insert categ filter -if ($search_categ > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $search_categ); -} if ($search_warehouse) { $sql .= natural_search("e.ref", $search_warehouse); } @@ -195,8 +200,22 @@ $sql .= " ps.fk_entrepot,"; $sql .= " e.ref, e.lieu, e.fk_parent,"; $sql .= " pb.batch, pb.eatby, pb.sellby,"; $sql .= " pl.rowid, pl.eatby, pl.sellby"; +$sql_having = ''; if ($toolowstock) { - $sql .= " HAVING SUM(".$db->ifsql('ps.reel IS NULL', '0', 'ps.reel').") < p.seuil_stock_alerte"; // Not used yet + $sql_having .= " HAVING SUM(".$db->ifsql('ps.reel IS NULL', '0', 'ps.reel').") < p.seuil_stock_alerte"; // Not used yet +} +if ($search_stock_physique != '') { + $natural_search_physique = natural_search('SUM(' . $db->ifsql('pb.qty IS NULL', '0', 'pb.qty') . ')', $search_stock_physique, 1, 1); + $natural_search_physique = " " . substr($natural_search_physique, 1, -1); // remove first "(" and last ")" characters + if (!empty($sql_having)) { + $sql_having .= " AND"; + } else { + $sql_having .= " HAVING"; + } + $sql_having .= $natural_search_physique; +} +if (!empty($sql_having)) { + $sql .= $sql_having; } $sql .= $db->order($sortfield, $sortorder); @@ -248,7 +267,7 @@ if ($resql) { if ($tobuy) { $param .= "&tobuy=".urlencode($tobuy); } - if ($type) { + if ($type != '') { $param .= "&type=".urlencode($type); } if ($fourn_id) { @@ -269,18 +288,18 @@ if ($resql) { if ($search_warehouse) { $param .= "&search_warehouse=".urlencode($search_warehouse); } - if ($catid) { - $param .= "&catid=".urlencode($catid); - } if ($toolowstock) { $param .= "&toolowstock=".urlencode($toolowstock); } if ($search_sale) { $param .= "&search_sale=".urlencode($search_sale); } - if ($search_categ > 0) { + if (!empty($search_categ) && $search_categ != '-1') { $param .= "&search_categ=".urlencode($search_categ); } + if ($search_stock_physique) { + $param .= '&search_stock_physique=' . urlencode($search_stock_physique); + } /*if ($eatby) $param.="&eatby=".$eatby; if ($sellby) $param.="&sellby=".$sellby;*/ @@ -295,10 +314,10 @@ if ($resql) { print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'product', 0, '', '', $limit, 0, 0, 1); - if (!empty($catid)) { + if ($search_categ > 0) { print "
"; $c = new Categorie($db); - $c->fetch($catid); + $c->fetch($search_categ); $ways = $c->print_all_ways(' > ', 'product/reassortlot.php'); print " > ".$ways[0]."
\n"; print "

"; @@ -309,7 +328,7 @@ if ($resql) { if (!empty($conf->categorie->enabled)) { $moreforfilter .= '
'; $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); - $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ'); + $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ', 1); $moreforfilter .= '
'; } //$moreforfilter.=$langs->trans("StockTooLow").' '; @@ -342,14 +361,17 @@ if ($resql) { } print ''; print ''; - print ' '; - print ' '; if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { print ' '; } if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { print ' '; } + // Physical stock + print ''; + print ''; + print ''; + print ' '; print ' '; print ' '; print ''; @@ -360,21 +382,21 @@ if ($resql) { //Line for column titles print ""; - print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", $param, "", "", $sortfield, $sortorder); - print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", $param, "", "", $sortfield, $sortorder); + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", '', $param, "", $sortfield, $sortorder); + print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", '', $param, "", $sortfield, $sortorder); if (!empty($conf->service->enabled) && $type == 1) { - print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", $param, "", '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", '', $param, "", $sortfield, $sortorder, 'center '); } - print_liste_field_titre("Warehouse", $_SERVER["PHP_SELF"], "e.ref", $param, "", '', $sortfield, $sortorder); + print_liste_field_titre("Warehouse", $_SERVER["PHP_SELF"], "e.ref", '', $param, "", $sortfield, $sortorder); //print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock",$param,"",'',$sortfield,$sortorder, 'right ); - print_liste_field_titre("Batch", $_SERVER["PHP_SELF"], "pb.batch", $param, "", '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("Batch", $_SERVER["PHP_SELF"], "pb.batch", '', $param, "", $sortfield, $sortorder, 'center '); if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { - print_liste_field_titre("SellByDate", $_SERVER["PHP_SELF"], "pb.sellby", $param, "", '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("SellByDate", $_SERVER["PHP_SELF"], "pb.sellby", '', $param, "", $sortfield, $sortorder, 'center '); } if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { - print_liste_field_titre("EatByDate", $_SERVER["PHP_SELF"], "pb.eatby", $param, "", '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("EatByDate", $_SERVER["PHP_SELF"], "pb.eatby", '', $param, "", $sortfield, $sortorder, 'center '); } - print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", $param, "", '', $sortfield, $sortorder, 'right '); + print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", '', $param, "", $sortfield, $sortorder, 'right '); // TODO Add info of running suppliers/customers orders //print_liste_field_titre("TheoreticalStock",$_SERVER["PHP_SELF"], "stock_theorique",$param,"",'',$sortfield,$sortorder, 'right '); print_liste_field_titre(''); From 4edbd5c4e3ff7f1d1ae8d5742dd44a50086a5239 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Tue, 25 Jan 2022 10:31:45 +0100 Subject: [PATCH 012/132] NEW : Creation of the function select_bom() used to display bom select list --- htdocs/bom/tpl/objectline_create.tpl.php | 2 +- htdocs/core/class/html.form.class.php | 51 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/htdocs/bom/tpl/objectline_create.tpl.php b/htdocs/bom/tpl/objectline_create.tpl.php index 7419c4618e0..0a3a3b34e7a 100644 --- a/htdocs/bom/tpl/objectline_create.tpl.php +++ b/htdocs/bom/tpl/objectline_create.tpl.php @@ -109,7 +109,7 @@ if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { if (!empty($conf->global->BOM_SUB_BOM)) { print '
'.$langs->trans("or").'
'.$langs->trans("BOM"); // TODO Add component to select a BOM - print ''; + $form->select_bom(); } print ''; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 88fca7b536a..fe47047150d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2362,6 +2362,57 @@ class Form } } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + + /** + * Return list of BOM for customer in Ajax if Ajax activated or go to select_produits_list + * + * @param int $selected Preselected BOM id + * @param string $htmlname Name of HTML select field (must be unique in page). + * @param int $limit Limit on number of returned lines + * @param int $status Sell status -1=Return all bom, 0=Draft BOM, 1=Validated BOM + * @param int $type type of the BOM (-1=Return all BOM, 0=Return disassemble BOM, 1=Return manufacturing BOM) + * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. + * @param string $morecss Add more css on select + * @return void|string + */ + public function select_bom($selected = '', $htmlname = 'bom_id', $limit = 0, $status = 1, $type = 1, $showempty = '1', $morecss = '', $nooutput = '') + { + // phpcs:enable + global $conf, $user, $langs, $db; + $error = 0; + $out = ''; + + $out .= ''; - $sql = 'SELECT b.rowid, b.ref, b.label'; + $sql = 'SELECT b.rowid, b.ref, b.label, b.fk_product'; $sql.= ' FROM '.MAIN_DB_PREFIX.'bom_bom as b'; - $sql .= ' WHERE b.entity IN ('.getEntity('bom').')'; - if(!empty($status)) $sql.= ' AND status = '.$status; - if(!empty($type)) $sql.= ' AND status = '. $type; + $sql.= ' WHERE b.entity IN ('.getEntity('bom').')'; + if(!empty($status)) $sql.= ' AND status = '. (int) $status; + if(!empty($type)) $sql.= ' AND status = '. (int) $type; if(!empty($limit)) $sql.= 'LIMIT '. (int) $limit; $resql = $db->query($sql); if($resql){ @@ -2399,8 +2407,10 @@ class Form $out .= '> '; } while ($obj = $db->fetch_object($resql)){ - if($obj->rowid == $selected) $out .= ''; - $out .= ''; + $product = new Product($db); + $res = $product->fetch($obj->fk_product); + if($obj->rowid == $selected) $out .= ''; + $out .= ''; } } else { $error++; From f37c04bc2f7ab59c407c261b27b03a92c25357f5 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Tue, 25 Jan 2022 12:06:40 +0100 Subject: [PATCH 014/132] NEW : Add the possibility to add sub-BOMs to BOM --- htdocs/bom/bom_card.php | 15 ++++++++++++--- htdocs/bom/tpl/objectline_view.tpl.php | 7 ------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 748aea4ddb2..26764072956 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -148,8 +148,17 @@ if (empty($reshook)) { $error = 0; // Set if we used free entry or predefined product - $idprod = (int) GETPOST('idprod', 'int'); - $bom_child = (int) GETPOST('bom_select', 'int'); + $bom_child_id = (int) GETPOST('bom_id', 'int'); + if($bom_child_id > 0){ + $bom_child = new BOM($db); + $res = $bom_child->fetch($bom_child_id); + if($res){ + $idprod = $bom_child->fk_product; + } + } else { + $idprod = (int) GETPOST('idprod', 'int'); + } + $qty = price2num(GETPOST('qty', 'alpha'), 'MS'); $qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS'); $disable_stock_change = GETPOST('disable_stock_change', 'int'); @@ -173,7 +182,7 @@ if (empty($reshook)) { $bomline = new BOMLine($db); $bomline->fk_bom = $id; $bomline->fk_product = $idprod; - $bomline->fk_bom_child = $bom_child; + $bomline->fk_bom_child = $bom_child_id; $bomline->qty = $qty; $bomline->qty_frozen = (int) $qty_frozen; $bomline->disable_stock_change = (int) $disable_stock_change; diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index 82626c12fec..f62143188eb 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -202,13 +202,6 @@ if ($resql) { // Product print ''.$sub_bom_product->getNomUrl(1).''; - // Sub-BOM - if ($sub_bom_line->fk_bom_child > 0) { - print ''.$sub_bom->getNomUrl(1).''; - } else { - print ' '; - } - // Qty print ''.price($sub_bom_line->qty * $line->qty, 0, '', 0, 0).''; if ($sub_bom_line->qty_frozen > 0) { From 08d830f4501c959129d8b48156f73bec23659478 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Tue, 25 Jan 2022 16:40:28 +0100 Subject: [PATCH 015/132] FIX : Fixing total_cost, qty_frozen and display problems --- htdocs/bom/tpl/objectline_view.tpl.php | 36 +++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index f62143188eb..0c74cee43ce 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -41,7 +41,7 @@ if (empty($object) || !is_object($object)) { } -global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax; +global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax, $langs; if (empty($dateSelector)) { $dateSelector = 0; @@ -83,8 +83,10 @@ $tmpproduct->fetch($line->fk_product); $tmpbom = new BOM($object->db); $res = $tmpbom->fetch($line->fk_bom_child); if ($tmpbom->id > 0) { - print $tmpbom->getNomUrl(1); print '' . (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? '(+)' : '(-)') . ' '; + print $tmpproduct->getNomUrl(1); + print ' '.$langs->trans('OR').' '; + print $tmpbom->getNomUrl(1); } else { print $tmpproduct->getNomUrl(1); print ' - '.$tmpproduct->label; @@ -176,7 +178,7 @@ if ($action == 'selectlines') { print ''; // Select of all the sub-BOM lines -$sql = 'SELECT rowid, fk_bom_child, fk_product FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl'; +$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl'; $sql.= ' WHERE fk_bom ='. (int) $tmpbom->id; $resql = $object->db->query($sql); @@ -199,14 +201,23 @@ if ($resql) { print ''; } - // Product - print ''.$sub_bom_product->getNomUrl(1).''; + // Product OR BOM + print ''; + if(!empty($obj->fk_bom_child)){ + print $sub_bom_product->getNomUrl(1); + print ' '.$langs->trans('OR').' '; + print $sub_bom->getNomUrl(1); + } else { + print $sub_bom_product->getNomUrl(1); + print ''; + } // Qty - print ''.price($sub_bom_line->qty * $line->qty, 0, '', 0, 0).''; if ($sub_bom_line->qty_frozen > 0) { - print ''.$sub_bom_line->qty_frozen.''; + print ''.price($sub_bom_line->qty, 0, '', 0, 0).''; + print ''.$langs->trans('Yes').''; } else { + print ''.price($sub_bom_line->qty * $line->qty, 0, '', 0, 0).''; print ' '; } @@ -221,9 +232,16 @@ if ($resql) { print ''.$sub_bom_line->efficiency.''; // Cost price if it's defined - if ($sub_bom_product->cost_price > 0) { + if (!empty($obj->fk_bom_child)) { + $bom = new BOM($object->db); + $bom->fetch($obj->fk_bom_child); + $bom->calculateCosts(); + $bom->total_cost * $line->qty; + print ''.price($bom->total_cost * $line->qty).''; + $total_cost+= $bom->total_cost * $line->qty; + } elseif ($sub_bom_product->cost_price > 0) { print ''.price($sub_bom_product->cost_price * $line->qty).''; - $total_cost.= $sub_bom_product->cost_price * $line->qty; + $total_cost+= $sub_bom_product->cost_price * $line->qty; } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined print ''.price($sub_bom_product->pmp * $line->qty).''; $total_cost.= $sub_bom_product->pmp * $line->qty; From ec1f78424742205349ca757190a67eb7ac03bc3a Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 26 Jan 2022 11:43:44 +0100 Subject: [PATCH 016/132] replace restricthtml to nohtml. --- htdocs/exports/export.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index c0a48b97222..544a9ead888 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -391,14 +391,14 @@ if ($step == 4 && $action == 'submitFormField') { $newcode = (string) preg_replace('/\./', '_', $code); //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n
"; $filterqualified = 1; - if (!GETPOSTISSET($newcode) || GETPOST($newcode, 'restricthtml') == '') { + if (!GETPOSTISSET($newcode) || GETPOST($newcode, 'nohtml') == '') { $filterqualified = 0; - } elseif (preg_match('/^List/', $type) && (is_numeric(GETPOST($newcode, 'restricthtml')) && GETPOST($newcode, 'restricthtml') <= 0)) { + } elseif (preg_match('/^List/', $type) && (is_numeric(GETPOST($newcode, 'nohtml')) && GETPOST($newcode, 'nohtml') <= 0)) { $filterqualified = 0; } if ($filterqualified) { //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n"; - $objexport->array_export_FilterValue[0][$code] = GETPOST($newcode, 'restricthtml'); + $objexport->array_export_FilterValue[0][$code] = GETPOST($newcode, 'nohtml'); } } $array_filtervalue = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : ''); From 23e5ff08ebcee4a9d0997d644cec5f5d481ebe11 Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 26 Jan 2022 12:07:06 +0100 Subject: [PATCH 017/132] change to alphawithlgt --- htdocs/exports/export.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 544a9ead888..3373a299586 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -391,14 +391,14 @@ if ($step == 4 && $action == 'submitFormField') { $newcode = (string) preg_replace('/\./', '_', $code); //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n
"; $filterqualified = 1; - if (!GETPOSTISSET($newcode) || GETPOST($newcode, 'nohtml') == '') { + if (!GETPOSTISSET($newcode) || GETPOST($newcode, 'alphawithlgt') == '') { $filterqualified = 0; - } elseif (preg_match('/^List/', $type) && (is_numeric(GETPOST($newcode, 'nohtml')) && GETPOST($newcode, 'nohtml') <= 0)) { + } elseif (preg_match('/^List/', $type) && (is_numeric(GETPOST($newcode, 'alphawithlgt')) && GETPOST($newcode, 'alphawithlgt') <= 0)) { $filterqualified = 0; } if ($filterqualified) { //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n"; - $objexport->array_export_FilterValue[0][$code] = GETPOST($newcode, 'nohtml'); + $objexport->array_export_FilterValue[0][$code] = GETPOST($newcode, 'alphawithlgt'); } } $array_filtervalue = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : ''); From 42f252b636fec9f16cf133c470c30408e6944aa5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 26 Jan 2022 12:39:41 +0100 Subject: [PATCH 018/132] Add one more test --- test/phpunit/SecurityTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index 6bece069cc9..2d14a35dce9 100644 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -359,7 +359,7 @@ class SecurityTest extends PHPUnit\Framework\TestCase $_POST['param8b']='objnotdefined\''; @@ -501,6 +501,10 @@ class SecurityTest extends PHPUnit\Framework\TestCase print __METHOD__." result param7 = ".$result."\n"; $this->assertEquals('"c:\this is a path~1\aaan &#x;;;;" abcdef', $result); + $result=GETPOST("param8e", 'restricthtml'); + print __METHOD__." result param8e = ".$result."\n"; + $this->assertEquals('', $result); + $result=GETPOST("param12", 'restricthtml'); print __METHOD__." result=".$result."\n"; $this->assertEquals(trim($_POST["param12"]), $result, 'Test a string with DOCTYPE and restricthtml'); @@ -519,7 +523,7 @@ class SecurityTest extends PHPUnit\Framework\TestCase $result=GETPOST("param15", 'restricthtml'); // src=>0xbeefed print __METHOD__." result=".$result."\n"; - $this->assertEquals("0xbeefed", $result, 'Test 15a'); // The GETPOST return a harmull string + $this->assertEquals("0xbeefed", $result, 'Test 15'); // The GETPOST return a harmull string // Test with restricthtml + MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES to test disabling of bad atrributes $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 1; From 60fff852abbad96965bb66c3a2b87af9427efd9d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 26 Jan 2022 12:53:06 +0100 Subject: [PATCH 019/132] Merge branch '14.0' of git@github.com:Dolibarr/dolibarr.git into 14.0 --- htdocs/core/modules/modUser.class.php | 2 +- htdocs/exports/export.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/modUser.class.php b/htdocs/core/modules/modUser.class.php index f7b6b9aec69..c4043779c64 100644 --- a/htdocs/core/modules/modUser.class.php +++ b/htdocs/core/modules/modUser.class.php @@ -239,7 +239,7 @@ class modUser extends DolibarrModules 'u.accountancy_code'=>'Text', 'u.address'=>"Text", 'u.zip'=>"Text", 'u.town'=>"Text", 'u.office_phone'=>'Text', 'u.user_mobile'=>'Text', 'u.office_fax'=>'Text', - 'u.email'=>'Text', 'u.datec'=>"Date", 'u.tms'=>"Date", 'u.admin'=>"Boolean", 'u.statut'=>'Status', 'u.note'=>"Text", 'u.datelastlogin'=>'Date', + 'u.email'=>'Text', 'u.datec'=>"Date", 'u.tms'=>"Date", 'u.admin'=>"Boolean", 'u.statut'=>'Status', 'u.note'=>"Text", 'u.signature'=>"Text", 'u.datelastlogin'=>'Date', 'u.fk_user'=>"List:user:login", 'u.birth'=>'Date', 'u.datepreviouslogin'=>'Date', 'u.fk_soc'=>"List:societe:nom:rowid", 'u.fk_member'=>"List:adherent:firstname", diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 3373a299586..df03b6a1cdc 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -389,16 +389,17 @@ if ($step == 4 && $action == 'submitFormField') { $_SESSION["export_filtered_fields"] = array(); foreach ($objexport->array_export_TypeFields[0] as $code => $type) { // $code: s.fieldname $value: Text|Boolean|List:ccc $newcode = (string) preg_replace('/\./', '_', $code); - //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n
"; + //print 'xxx '.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n
"; + $check = 'alphanohtml'; $filterqualified = 1; - if (!GETPOSTISSET($newcode) || GETPOST($newcode, 'alphawithlgt') == '') { + if (!GETPOSTISSET($newcode) || GETPOST($newcode, $check) == '') { $filterqualified = 0; - } elseif (preg_match('/^List/', $type) && (is_numeric(GETPOST($newcode, 'alphawithlgt')) && GETPOST($newcode, 'alphawithlgt') <= 0)) { + } elseif (preg_match('/^List/', $type) && (is_numeric(GETPOST($newcode, $check)) && GETPOST($newcode, $check) <= 0)) { $filterqualified = 0; } if ($filterqualified) { //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n"; - $objexport->array_export_FilterValue[0][$code] = GETPOST($newcode, 'alphawithlgt'); + $objexport->array_export_FilterValue[0][$code] = GETPOST($newcode, $check); } } $array_filtervalue = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : ''); From 6783ec80be17a4a4ed12468d5c1b06165125cc3d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 26 Jan 2022 14:17:32 +0100 Subject: [PATCH 020/132] Try a change on a file to trigger travis --- htdocs/projet/class/task.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index f8f3b94eb45..afb771c359c 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -41,7 +41,7 @@ class Task extends CommonObjectLine public $element = 'project_task'; /** - * @var string Name of table without prefix where object is stored + * @var string Name of table without prefix where object is stored */ public $table_element = 'projet_task'; From 36068d4279375d8b813d097f9deecd998babecb3 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Wed, 26 Jan 2022 14:41:36 +0100 Subject: [PATCH 021/132] FIX : Fixing total errors --- htdocs/bom/class/bom.class.php | 41 ++++++++++++++++++-------- htdocs/bom/tpl/objectline_view.tpl.php | 17 ++++------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 0520c76dde2..6f170fb066b 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -1064,26 +1064,41 @@ class BOM extends CommonObject $tmpproduct->cost_price = 0; $tmpproduct->pmp = 0; - $result = $tmpproduct->fetch($line->fk_product, '', '', '', 0, 1, 1); // We discard selling price and language loading - if ($result < 0) { - $this->error = $tmpproduct->error; - return -1; - } - $line->unit_cost = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp); - if (empty($line->unit_cost)) { - if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) { - $line->unit_cost = $productFournisseur->fourn_unitprice; + if(empty($line->fk_bom_child)){ + $result = $tmpproduct->fetch($line->fk_product, '', '', '', 0, 1, 1); // We discard selling price and language loading + if ($result < 0) { + $this->error = $tmpproduct->error; + return -1; + } + $line->unit_cost = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp); + if (empty($line->unit_cost)) { + if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) { + $line->unit_cost = $productFournisseur->fourn_unitprice; + } + } + + $line->total_cost = price2num($line->qty * $line->unit_cost, 'MT'); + + $this->total_cost += $line->total_cost; + } else { + $bom_child= new BOM($this->db); + $res = $bom_child->fetch($line->fk_bom_child); + if($res>0){ + $bom_child->calculateCosts(); + $this->total_cost += $bom_child->total_cost; + } else { + $this->error = $bom_child->error; + return -2; } } - $line->total_cost = price2num($line->qty * $line->unit_cost, 'MT'); - - $this->total_cost += $line->total_cost; } $this->total_cost = price2num($this->total_cost, 'MT'); - if ($this->qty) { + if ($this->qty > 0) { $this->unit_cost = price2num($this->total_cost / $this->qty, 'MU'); + } elseif ($this->qty < 0) { + $this->unit_cost = price2num($this->total_cost * $this->qty, 'MU'); } } } diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index 0c74cee43ce..fc40c8a54f2 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -232,27 +232,22 @@ if ($resql) { print ''.$sub_bom_line->efficiency.''; // Cost price if it's defined - if (!empty($obj->fk_bom_child)) { - $bom = new BOM($object->db); - $bom->fetch($obj->fk_bom_child); - $bom->calculateCosts(); - $bom->total_cost * $line->qty; - print ''.price($bom->total_cost * $line->qty).''; - $total_cost+= $bom->total_cost * $line->qty; - } elseif ($sub_bom_product->cost_price > 0) { + if ($sub_bom_product->cost_price > 0) { print ''.price($sub_bom_product->cost_price * $line->qty).''; $total_cost+= $sub_bom_product->cost_price * $line->qty; } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined print ''.price($sub_bom_product->pmp * $line->qty).''; $total_cost.= $sub_bom_product->pmp * $line->qty; } else { // Minimum purchase price if cost price and PMP aren't defined - $sql_supplier_price = 'SELECT MIN(price) AS min_price FROM '.MAIN_DB_PREFIX.'product_fournisseur_price'; + $sql_supplier_price = 'SELECT MIN(price) AS min_price, quantity AS qty FROM '.MAIN_DB_PREFIX.'product_fournisseur_price'; $sql_supplier_price.= ' WHERE fk_product = '. (int) $sub_bom_product->id; $resql_supplier_price = $object->db->query($sql_supplier_price); if ($resql_supplier_price) { $obj = $object->db->fetch_object($resql_supplier_price); - print ''.price($obj->min_price * $line->qty).''; - $total_cost+= $obj->min_price * $line->qty; + $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty; + + print ''.price($line_cost).''; + $total_cost+= $line_cost; } } From 6d3066a312b802ba92d7606e6c432d01f42db21b Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Wed, 26 Jan 2022 14:46:45 +0100 Subject: [PATCH 022/132] FIX : Fixing trads --- htdocs/bom/tpl/objectline_view.tpl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index fc40c8a54f2..e8550e9d6b6 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -85,7 +85,7 @@ $res = $tmpbom->fetch($line->fk_bom_child); if ($tmpbom->id > 0) { print '' . (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? '(+)' : '(-)') . ' '; print $tmpproduct->getNomUrl(1); - print ' '.$langs->trans('OR').' '; + print ' '.$langs->trans('or').' '; print $tmpbom->getNomUrl(1); } else { print $tmpproduct->getNomUrl(1); @@ -205,7 +205,7 @@ if ($resql) { print ''; if(!empty($obj->fk_bom_child)){ print $sub_bom_product->getNomUrl(1); - print ' '.$langs->trans('OR').' '; + print ' '.$langs->trans('or').' '; print $sub_bom->getNomUrl(1); } else { print $sub_bom_product->getNomUrl(1); From 9342fa8781b6df278054e6d92acf08696a88734c Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 26 Jan 2022 14:15:53 +0000 Subject: [PATCH 023/132] Fixing style errors. --- htdocs/bom/bom_card.php | 14 +++++++------- htdocs/bom/class/bom.class.php | 4 ++-- htdocs/bom/tpl/objectline_view.tpl.php | 16 ++++++++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 26764072956..d31e21e635b 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -149,13 +149,13 @@ if (empty($reshook)) { // Set if we used free entry or predefined product $bom_child_id = (int) GETPOST('bom_id', 'int'); - if($bom_child_id > 0){ - $bom_child = new BOM($db); - $res = $bom_child->fetch($bom_child_id); - if($res){ - $idprod = $bom_child->fk_product; - } - } else { + if ($bom_child_id > 0) { + $bom_child = new BOM($db); + $res = $bom_child->fetch($bom_child_id); + if ($res) { + $idprod = $bom_child->fk_product; + } + } else { $idprod = (int) GETPOST('idprod', 'int'); } diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 6f170fb066b..4923e9d0ca2 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -1064,7 +1064,7 @@ class BOM extends CommonObject $tmpproduct->cost_price = 0; $tmpproduct->pmp = 0; - if(empty($line->fk_bom_child)){ + if (empty($line->fk_bom_child)) { $result = $tmpproduct->fetch($line->fk_product, '', '', '', 0, 1, 1); // We discard selling price and language loading if ($result < 0) { $this->error = $tmpproduct->error; @@ -1083,7 +1083,7 @@ class BOM extends CommonObject } else { $bom_child= new BOM($this->db); $res = $bom_child->fetch($line->fk_bom_child); - if($res>0){ + if ($res>0) { $bom_child->calculateCosts(); $this->total_cost += $bom_child->total_cost; } else { diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index e8550e9d6b6..4360d521036 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -85,8 +85,8 @@ $res = $tmpbom->fetch($line->fk_bom_child); if ($tmpbom->id > 0) { print '' . (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? '(+)' : '(-)') . ' '; print $tmpproduct->getNomUrl(1); - print ' '.$langs->trans('or').' '; - print $tmpbom->getNomUrl(1); + print ' '.$langs->trans('or').' '; + print $tmpbom->getNomUrl(1); } else { print $tmpproduct->getNomUrl(1); print ' - '.$tmpproduct->label; @@ -203,14 +203,14 @@ if ($resql) { // Product OR BOM print ''; - if(!empty($obj->fk_bom_child)){ + if (!empty($obj->fk_bom_child)) { print $sub_bom_product->getNomUrl(1); print ' '.$langs->trans('or').' '; print $sub_bom->getNomUrl(1); - } else { + } else { print $sub_bom_product->getNomUrl(1); - print ''; - } + print ''; + } // Qty if ($sub_bom_line->qty_frozen > 0) { @@ -232,7 +232,7 @@ if ($resql) { print ''.$sub_bom_line->efficiency.''; // Cost price if it's defined - if ($sub_bom_product->cost_price > 0) { + if ($sub_bom_product->cost_price > 0) { print ''.price($sub_bom_product->cost_price * $line->qty).''; $total_cost+= $sub_bom_product->cost_price * $line->qty; } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined @@ -244,7 +244,7 @@ if ($resql) { $resql_supplier_price = $object->db->query($sql_supplier_price); if ($resql_supplier_price) { $obj = $object->db->fetch_object($resql_supplier_price); - $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty; + $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty; print ''.price($line_cost).''; $total_cost+= $line_cost; From 83d80cc3801b6df9723d2055002435687f2ddeb1 Mon Sep 17 00:00:00 2001 From: kamel Date: Wed, 26 Jan 2022 15:45:00 +0100 Subject: [PATCH 024/132] Correction recuperation de la vat_rate_show --- htdocs/compta/tva/quadri_detail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 4b44959bc1a..68dcaa55fb6 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -47,7 +47,7 @@ $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "produ $refresh = (GETPOSTISSET('submit') || GETPOSTISSET('vat_rate_show') || GETPOSTISSET('invoice_type')) ? true : false; $invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : ''; -$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'int') : -1; +$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'alphanohtml') : -1; include DOL_DOCUMENT_ROOT.'/compta/tva/initdatesforvat.inc.php'; From db57d1a99f8095aabef7663a88e51a5c4fad053d Mon Sep 17 00:00:00 2001 From: kamel Date: Wed, 26 Jan 2022 15:53:03 +0100 Subject: [PATCH 025/132] =?UTF-8?q?Correction=20lien=20pour=20afficher=20l?= =?UTF-8?q?e=20detail=20de=20la=20tva=20si=20la=20tva=20est=20pr=C3=A9sent?= =?UTF-8?q?e=20cot=C3=A9=20client=20en=20fournisseur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/tva/quadri_detail.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 68dcaa55fb6..1ba3e2ab28e 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -409,7 +409,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) { print ''; print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; @@ -643,7 +643,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) { print ''; print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; From d38ff3ad9b6fc60a672f08aea834265cccc54e1d Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Wed, 26 Jan 2022 15:53:30 +0100 Subject: [PATCH 026/132] FIX : Fixing stickler returns --- htdocs/core/class/html.form.class.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e7fd8d27967..caf20ffcbad 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2374,6 +2374,8 @@ class Form * @param int $type type of the BOM (-1=Return all BOM, 0=Return disassemble BOM, 1=Return manufacturing BOM) * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. * @param string $morecss Add more css on select + * @param string $nooutput + * @param string $forcecombo * @return void|string */ public function select_bom($selected = '', $htmlname = 'bom_id', $limit = 0, $status = 1, $type = 1, $showempty = '1', $morecss = '', $nooutput = '', $forcecombo = 0) @@ -2396,20 +2398,20 @@ class Form $sql = 'SELECT b.rowid, b.ref, b.label, b.fk_product'; $sql.= ' FROM '.MAIN_DB_PREFIX.'bom_bom as b'; $sql.= ' WHERE b.entity IN ('.getEntity('bom').')'; - if(!empty($status)) $sql.= ' AND status = '. (int) $status; - if(!empty($type)) $sql.= ' AND status = '. (int) $type; - if(!empty($limit)) $sql.= 'LIMIT '. (int) $limit; + if (!empty($status)) $sql.= ' AND status = '. (int) $status; + if (!empty($type)) $sql.= ' AND status = '. (int) $type; + if (!empty($limit)) $sql.= 'LIMIT '. (int) $limit; $resql = $db->query($sql); - if($resql){ + if ($resql) { if ($showempty) { $out .= ''; + if ($obj->rowid == $selected) $out .= ''; $out .= ''; } } else { From e52fb89182ce2b22a992015860859fbe1142e128 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Wed, 26 Jan 2022 16:36:58 +0100 Subject: [PATCH 027/132] FIX : Fixing stickler returns --- htdocs/core/class/html.form.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index caf20ffcbad..6c4c3b411b8 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2374,8 +2374,8 @@ class Form * @param int $type type of the BOM (-1=Return all BOM, 0=Return disassemble BOM, 1=Return manufacturing BOM) * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. * @param string $morecss Add more css on select - * @param string $nooutput - * @param string $forcecombo + * @param string $nooutput No print, return the output into a string + * @param int $forcecombo Force to use combo box * @return void|string */ public function select_bom($selected = '', $htmlname = 'bom_id', $limit = 0, $status = 1, $type = 1, $showempty = '1', $morecss = '', $nooutput = '', $forcecombo = 0) From 2e525a719d11eb77d0aa81f2720a6f8c8c9596dd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 26 Jan 2022 19:12:02 +0100 Subject: [PATCH 028/132] Fix selection of migration script --- htdocs/install/upgrade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 70257bba79e..1bc372c4c00 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -307,8 +307,8 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ $filelist = array(); $i = 0; $ok = 0; - $from = '^'.$newversionfrom; - $to = $newversionto.'\.sql$'; + $from = '^'.preg_quote($newversionfrom, '/'); + $to = preg_quote($newversionto.'.sql', '/').'$'; // Get files list $filesindir = array(); @@ -326,9 +326,9 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ // Define which file to run foreach ($filesindir as $file) { - if (preg_match('/'.$from.'/i', $file)) { + if (preg_match('/'.$from.'\-/i', $file)) { $filelist[] = $file; - } elseif (preg_match('/'.$to.'/i', $file)) { // First test may be false if we migrate from x.y.* to x.y.* + } elseif (preg_match('/\-'.$to.'/i', $file)) { // First test may be false if we migrate from x.y.* to x.y.* $filelist[] = $file; } } From 538c5f14d314cf96e0d30dfc734b542f2c3b0740 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 26 Jan 2022 19:56:02 +0100 Subject: [PATCH 029/132] Fix phpcs --- htdocs/core/class/commonobject.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index cf00dc0e317..dcc31870b1c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2266,6 +2266,8 @@ abstract class CommonObject */ public function setPaymentMethods($id) { + global $user; + $error = 0; $notrigger = 0; dol_syslog(get_class($this).'::setPaymentMethods('.$id.')'); From 928075bbf684c2f36064342fb634e3b920a943ea Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 26 Jan 2022 20:13:10 +0100 Subject: [PATCH 030/132] fix error in commande.class.php --- htdocs/commande/class/commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index e3b2c64c92a..c315a4fcd61 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -626,7 +626,7 @@ class Commande extends CommonOrder $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql .= " SET fk_statut = ".self::STATUS_DRAFT."',"; + $sql .= " SET fk_statut = ".self::STATUS_DRAFT.","; $sql .= " fk_user_modif = ".((int) $user->id); $sql .= " WHERE rowid = ".((int) $this->id); From 9dda41611673be6932aea9d19db7d67b56d57799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cserveny=2C=20Tam=C3=A1s?= Date: Wed, 26 Jan 2022 23:41:31 +0100 Subject: [PATCH 031/132] add datem and type parameters --- .../stock/class/api_stockmovements.class.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index 8291e910917..acce9d6ac51 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -156,14 +156,16 @@ class StockMovements extends DolibarrApi * $price Can be set to update AWP (Average Weighted Price) when you make a stock increase * $dlc Eat-by date. Will be used if lot does not exists yet and will be created. * $dluo Sell-by date. Will be used if lot does not exists yet and will be created. - * + * * @param int $product_id Id product id {@min 1} {@from body} {@required true} * @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true} * @param float $qty Qty to add (Use negative value for a stock decrease) {@from body} {@required true} + * @param string $type Optionally specify the type of movement. 1=input (stock increase by a stock transfer), 2=output (stock decrease by a stock transfer),3=output (stock decrease), 4=input (stock increase). {@from body} {@type int} * @param string $lot Lot {@from body} * @param string $movementcode Movement code {@example INV123} {@from body} * @param string $movementlabel Movement label {@example Inventory number 123} {@from body} * @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0). {@from body} + * @param string $datem Date of movement {@from body} {@type date} * @param string $dlc Eat-by date. {@from body} {@type date} * @param string $dluo Sell-by date. {@from body} {@type date} * @param string $origin_type Origin type (Element of source object, like 'project', 'inventory', ...) @@ -172,7 +174,7 @@ class StockMovements extends DolibarrApi * @return int ID of stock movement * @throws RestException */ - public function post($product_id, $warehouse_id, $qty, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) + public function post($product_id, $warehouse_id, $qty, $type='', $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) { if (!DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); @@ -183,17 +185,22 @@ class StockMovements extends DolibarrApi } // Type increase or decrease - $type = 2; - if ($qty >= 0) { - $type = 3; - } + if ($type == '') { + $type = 2; + if ($qty >= 0) { + $type = 3; + } + } else { + $type = $type - 1; + } require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $eatBy = empty($dluo) ? '' : dol_stringtotime($dluo); $sellBy = empty($dlc) ? '' : dol_stringtotime($dlc); + $dateMvt = empty($datem) ? '' : dol_stringtotime($datem); $this->stockmovement->setOrigin($origin_type, $origin_id); - if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $eatBy, $sellBy, $lot) <= 0) { + if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, $dateMvt, $eatBy, $sellBy, $lot) <= 0) { $errormessage = $this->stockmovement->error; if (empty($errormessage)) { $errormessage = join(',', $this->stockmovement->errors); From a6bd35c7d82e7e48ca63c8c693735d72a792e217 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 26 Jan 2022 22:52:07 +0000 Subject: [PATCH 032/132] Fixing style errors. --- .../stock/class/api_stockmovements.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index acce9d6ac51..fc745ef614d 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -156,7 +156,7 @@ class StockMovements extends DolibarrApi * $price Can be set to update AWP (Average Weighted Price) when you make a stock increase * $dlc Eat-by date. Will be used if lot does not exists yet and will be created. * $dluo Sell-by date. Will be used if lot does not exists yet and will be created. - * + * * @param int $product_id Id product id {@min 1} {@from body} {@required true} * @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true} * @param float $qty Qty to add (Use negative value for a stock decrease) {@from body} {@required true} @@ -174,7 +174,7 @@ class StockMovements extends DolibarrApi * @return int ID of stock movement * @throws RestException */ - public function post($product_id, $warehouse_id, $qty, $type='', $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) + public function post($product_id, $warehouse_id, $qty, $type = '', $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) { if (!DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); @@ -186,13 +186,13 @@ class StockMovements extends DolibarrApi // Type increase or decrease if ($type == '') { - $type = 2; - if ($qty >= 0) { - $type = 3; - } - } else { - $type = $type - 1; - } + $type = 2; + if ($qty >= 0) { + $type = 3; + } + } else { + $type = $type - 1; + } require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $eatBy = empty($dluo) ? '' : dol_stringtotime($dluo); From 5f0999665f232ed6647931856b76939ce1516929 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 27 Jan 2022 02:27:36 +0100 Subject: [PATCH 033/132] FIX Invoice - Clone - Don't report contact on an another thirdparty --- htdocs/compta/facture/class/facture.class.php | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index f8f246924e3..4feeb3d60b6 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1,22 +1,23 @@ - * Copyright (C) 2004-2013 Laurent Destailleur - * Copyright (C) 2004 Sebastien Di Cintio - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2014 Regis Houssin - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2007 Franky Van Liedekerke - * Copyright (C) 2010-2020 Juanjo Menent - * Copyright (C) 2012-2014 Christophe Battarel - * Copyright (C) 2012-2015 Marcos García - * Copyright (C) 2012 Cédric Salvador - * Copyright (C) 2012-2014 Raphaël Doursenaud - * Copyright (C) 2013 Cedric Gross - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2016 Ferran Marcet - * Copyright (C) 2018 Alexandre Spangaro - * Copyright (C) 2018 Nicolas ZABOURI +/* Copyright (C) 2002-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2004 Sebastien Di Cintio + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2014 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2007 Franky Van Liedekerke + * Copyright (C) 2010-2020 Juanjo Menent + * Copyright (C) 2012-2014 Christophe Battarel + * Copyright (C) 2012-2015 Marcos García + * Copyright (C) 2012 Cédric Salvador + * Copyright (C) 2012-2014 Raphaël Doursenaud + * Copyright (C) 2013 Cedric Gross + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2016 Ferran Marcet + * Copyright (C) 2018 Alexandre Spangaro + * Copyright (C) 2018 Nicolas ZABOURI + * Copyright (C) 2022 Sylvain Legrand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1159,6 +1160,9 @@ class Facture extends CommonInvoice $object->fetch($fromid); + // Load source object + $objFrom = clone $object; + // Change socid if needed if (!empty($this->socid) && $this->socid != $object->socid) { $objsoc = new Societe($this->db); @@ -1239,13 +1243,13 @@ class Facture extends CommonInvoice $this->errors = $object->errors; } else { // copy internal contacts - if ($object->copy_linked_contact($this, 'internal') < 0) { + if ($object->copy_linked_contact($objFrom, 'internal') < 0) { $error++; $this->error = $object->error; $this->errors = $object->errors; - } elseif ($this->socid == $object->socid) { + } elseif ($object->socid == $objFrom->socid) { // copy external contacts if same company - if ($object->copy_linked_contact($this, 'external') < 0) { + if ($object->copy_linked_contact($objFrom, 'external') < 0) { $error++; $this->error = $object->error; $this->errors = $object->errors; @@ -1256,7 +1260,7 @@ class Facture extends CommonInvoice if (!$error) { // Hook of thirdparty module if (is_object($hookmanager)) { - $parameters = array('objFrom'=>$this); + $parameters = array('objFrom'=>$objFrom); $action = ''; $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { From 4693b9702bbc77016aff152009be91fc759b0e2a Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 27 Jan 2022 06:20:11 +0100 Subject: [PATCH 034/132] Copyright --- htdocs/compta/tva/quadri_detail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 1ba3e2ab28e..15c45d6055b 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -6,7 +6,7 @@ * Copyright (C) 2014 Ferran Marcet * Copyright (C) 2018-2021 Frédéric France * Copyright (C) 2019 Eric Seigne - * Copyright (C) 2021 Open-Dsi + * Copyright (C) 2021-2022 Open-Dsi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From 2d0427a5b1da1396b00ba19942b6ef0299f176b0 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 27 Jan 2022 06:21:07 +0100 Subject: [PATCH 035/132] Update tax.lib.php --- htdocs/core/lib/tax.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 3249166c083..490b95cc92d 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -6,7 +6,7 @@ * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2015 Marcos García - * Copyright (C) 2021 Open-Dsi + * Copyright (C) 2021-2022 Open-Dsi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From ed9346dfb98718d579757ab6e4fa191565106415 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 27 Jan 2022 10:00:26 +0100 Subject: [PATCH 036/132] Works on replace MAIN_DB_PREFIX by $db->prefix() --- htdocs/user/class/api_users.class.php | 6 +++--- htdocs/user/class/userbankaccount.class.php | 8 +++---- htdocs/user/class/usergroup.class.php | 24 ++++++++++----------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index 68aa2b650f7..b2f8085de5a 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -82,9 +82,9 @@ class Users extends DolibarrApi //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe; $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."user as t"; + $sql .= " FROM ".$this->db->prefix()."user as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_user as c"; + $sql .= ", ".$this->db->prefix()."categorie_user as c"; } $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; if ($user_ids) { @@ -536,7 +536,7 @@ class Users extends DolibarrApi //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe; $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as t"; + $sql .= " FROM ".$this->db->prefix()."usergroup as t"; $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; if ($group_ids) { $sql .= " AND t.rowid IN (".$this->db->sanitize($group_ids).")"; diff --git a/htdocs/user/class/userbankaccount.class.php b/htdocs/user/class/userbankaccount.class.php index d9392ade9d7..42164ce8b2c 100644 --- a/htdocs/user/class/userbankaccount.class.php +++ b/htdocs/user/class/userbankaccount.class.php @@ -93,12 +93,12 @@ class UserBankAccount extends Account { $now = dol_now(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rib (fk_user, datec)"; + $sql = "INSERT INTO ".$this->db->prefix()."user_rib (fk_user, datec)"; $sql .= " VALUES (".$this->userid.", '".$this->db->idate($now)."')"; $resql = $this->db->query($sql); if ($resql) { if ($this->db->affected_rows($resql)) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user_rib"); + $this->id = $this->db->last_insert_id($this->db->prefix()."user_rib"); return $this->update($user); } @@ -123,7 +123,7 @@ class UserBankAccount extends Account $this->create(); } - $sql = "UPDATE ".MAIN_DB_PREFIX."user_rib SET"; + $sql = "UPDATE ".$this->db->prefix()."user_rib SET"; $sql .= " bank = '".$this->db->escape($this->bank)."'"; $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'"; $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'"; @@ -167,7 +167,7 @@ class UserBankAccount extends Account $sql = "SELECT rowid, fk_user, entity, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; $sql .= " owner_address, label, datec, tms as datem"; - $sql .= " FROM ".MAIN_DB_PREFIX."user_rib"; + $sql .= " FROM ".$this->db->prefix()."user_rib"; if ($id) { $sql .= " WHERE rowid = ".((int) $id); } diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index b1b3175aaa9..00e031c33f1 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -191,8 +191,8 @@ class UserGroup extends CommonObject $ret = array(); $sql = "SELECT g.rowid, ug.entity as usergroup_entity"; - $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g,"; - $sql .= " ".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= " FROM ".$this->db->prefix()."usergroup as g,"; + $sql .= " ".$this->db->prefix()."usergroup_user as ug"; $sql .= " WHERE ug.fk_usergroup = g.rowid"; $sql .= " AND ug.fk_user = ".((int) $userid); if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { @@ -241,9 +241,9 @@ class UserGroup extends CommonObject if (!empty($this->id)) { $sql .= ", ug.entity as usergroup_entity"; } - $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " FROM ".$this->db->prefix()."user as u"; if (!empty($this->id)) { - $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= ", ".$this->db->prefix()."usergroup_user as ug"; } $sql .= " WHERE 1 = 1"; if (!empty($this->id)) { @@ -315,7 +315,7 @@ class UserGroup extends CommonObject // Si on a demande ajout d'un droit en particulier, on recupere // les caracteristiques (module, perms et subperms) de ce droit. $sql = "SELECT module, perms, subperms"; - $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql .= " FROM ".$this->db->prefix()."rights_def"; $sql .= " WHERE id = ".((int) $rid); $sql .= " AND entity = ".((int) $entity); @@ -358,7 +358,7 @@ class UserGroup extends CommonObject if (!empty($whereforadd)) { //print "$module-$perms-$subperms"; $sql = "SELECT id"; - $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql .= " FROM ".$this->db->prefix()."rights_def"; $sql .= " WHERE entity = ".((int) $entity); if (!empty($whereforadd) && $whereforadd != 'allmodules') { $sql .= " AND ".$whereforadd; @@ -372,11 +372,11 @@ class UserGroup extends CommonObject $obj = $this->db->fetch_object($result); $nid = $obj->id; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity); + $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity); if (!$this->db->query($sql)) { $error++; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")"; + $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")"; if (!$this->db->query($sql)) { $error++; } @@ -437,7 +437,7 @@ class UserGroup extends CommonObject // Si on a demande supression d'un droit en particulier, on recupere // les caracteristiques module, perms et subperms de ce droit. $sql = "SELECT module, perms, subperms"; - $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql .= " FROM ".$this->db->prefix()."rights_def"; $sql .= " WHERE id = ".((int) $rid); $sql .= " AND entity = ".((int) $entity); @@ -485,7 +485,7 @@ class UserGroup extends CommonObject if (!empty($wherefordel)) { //print "$module-$perms-$subperms"; $sql = "SELECT id"; - $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql .= " FROM ".$this->db->prefix()."rights_def"; $sql .= " WHERE entity = ".((int) $entity); if (!empty($wherefordel) && $wherefordel != 'allmodules') { $sql .= " AND ".$wherefordel; @@ -503,7 +503,7 @@ class UserGroup extends CommonObject $nid = $obj->id; } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights"; + $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights"; $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid); $sql .= " AND entity = ".((int) $entity); if (!$this->db->query($sql)) { @@ -564,7 +564,7 @@ class UserGroup extends CommonObject * Recuperation des droits */ $sql = "SELECT r.module, r.perms, r.subperms "; - $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as u, ".MAIN_DB_PREFIX."rights_def as r"; + $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r"; $sql .= " WHERE r.id = u.fk_id"; $sql .= " AND r.entity = ".((int) $conf->entity); $sql .= " AND u.entity = ".((int) $conf->entity); From 116bcd1bdcaaa2f4efa7409fb7f056a08414d504 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 27 Jan 2022 10:12:10 +0100 Subject: [PATCH 037/132] FIX convert product class --- htdocs/product/class/api_products.class.php | 46 +-- .../product/class/html.formproduct.class.php | 12 +- htdocs/product/class/product.class.php | 304 +++++++++--------- htdocs/product/class/productbatch.class.php | 26 +- .../class/productcustomerprice.class.php | 28 +- .../class/productfournisseurprice.class.php | 8 +- .../class/propalmergepdfproduct.class.php | 16 +- 7 files changed, 220 insertions(+), 220 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 91edbe5eaff..d271631ca22 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -188,21 +188,21 @@ class Products extends DolibarrApi $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : ''; $sql = "SELECT t.rowid, t.ref, t.ref_ext"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as t"; + $sql .= " FROM ".$this->db->prefix()."product as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_product as c"; + $sql .= ", ".$this->db->prefix()."categorie_product as c"; } $sql .= ' WHERE t.entity IN ('.getEntity('product').')'; if ($variant_filter == 1) { - $sql .= ' AND t.rowid not in (select distinct fk_product_parent from '.MAIN_DB_PREFIX.'product_attribute_combination)'; - $sql .= ' AND t.rowid not in (select distinct fk_product_child from '.MAIN_DB_PREFIX.'product_attribute_combination)'; + $sql .= ' AND t.rowid not in (select distinct fk_product_parent from '.$this->db->prefix().'product_attribute_combination)'; + $sql .= ' AND t.rowid not in (select distinct fk_product_child from '.$this->db->prefix().'product_attribute_combination)'; } if ($variant_filter == 2) { - $sql .= ' AND t.rowid in (select distinct fk_product_parent from '.MAIN_DB_PREFIX.'product_attribute_combination)'; + $sql .= ' AND t.rowid in (select distinct fk_product_parent from '.$this->db->prefix().'product_attribute_combination)'; } if ($variant_filter == 3) { - $sql .= ' AND t.rowid in (select distinct fk_product_child from '.MAIN_DB_PREFIX.'product_attribute_combination)'; + $sql .= ' AND t.rowid in (select distinct fk_product_child from '.$this->db->prefix().'product_attribute_combination)'; } // Select products of given category @@ -861,11 +861,11 @@ class Products extends DolibarrApi } $sql = "SELECT t.rowid, t.ref, t.ref_ext"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as t"; + $sql .= " FROM ".$this->db->prefix()."product as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_product as c"; + $sql .= ", ".$this->db->prefix()."categorie_product as c"; } - $sql .= ", ".MAIN_DB_PREFIX."product_fournisseur_price as s"; + $sql .= ", ".$this->db->prefix()."product_fournisseur_price as s"; $sql .= ' WHERE t.entity IN ('.getEntity('product').')'; @@ -1013,7 +1013,7 @@ class Products extends DolibarrApi } $sql = "SELECT t.rowid, t.ref, t.ref_ext, t.label, t.rang, t.entity"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_attribute as t"; + $sql .= " FROM ".$this->db->prefix()."product_attribute as t"; $sql .= ' WHERE t.entity IN ('.getEntity('product').')'; // Add sql filters @@ -1094,8 +1094,8 @@ class Products extends DolibarrApi } } - $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v"; - $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; + $sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v"; + $sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); @@ -1122,7 +1122,7 @@ class Products extends DolibarrApi throw new RestException(401); } - $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".$this->db->prefix()."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1140,8 +1140,8 @@ class Products extends DolibarrApi $attr['rang'] = $result->rang; $attr['entity'] = $result->entity; - $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v"; - $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; + $sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v"; + $sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); @@ -1169,7 +1169,7 @@ class Products extends DolibarrApi throw new RestException(401); } - $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".$this->db->prefix()."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1187,8 +1187,8 @@ class Products extends DolibarrApi $attr['rang'] = $result->rang; $attr['entity'] = $result->entity; - $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v"; - $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; + $sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v"; + $sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); @@ -1322,7 +1322,7 @@ class Products extends DolibarrApi throw new RestException(401); } - $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix()."product_attribute_value WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1365,7 +1365,7 @@ class Products extends DolibarrApi $ref = trim($ref); - $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value"; + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix()."product_attribute_value"; $sql .= " WHERE ref LIKE '".$this->db->escape($ref)."' AND fk_product_attribute = ".((int) $id)." AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1408,7 +1408,7 @@ class Products extends DolibarrApi $ref = trim($ref); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute_value"; + $sql = "SELECT rowid FROM ".$this->db->prefix()."product_attribute_value"; $sql .= " WHERE ref LIKE '".$this->db->escape($ref)."' AND fk_product_attribute = ".((int) $id)." AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1485,8 +1485,8 @@ class Products extends DolibarrApi $return = array(); $sql = 'SELECT '; - $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value as v'; - $sql .= " WHERE v.fk_product_attribute IN (SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".$this->db->escape($ref)."')"; + $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.$this->db->prefix().'product_attribute_value as v'; + $sql .= " WHERE v.fk_product_attribute IN (SELECT rowid FROM ".$this->db->prefix()."product_attribute WHERE ref LIKE '".$this->db->escape($ref)."')"; $resql = $this->db->query($sql); diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index da10faa4f34..457da877ee9 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -102,12 +102,12 @@ class FormProduct } elseif ($sumStock) { $sql .= ", sum(ps.reel) as stock"; } - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_entrepot = e.rowid"; + $sql .= " FROM ".$this->db->prefix()."entrepot as e"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.fk_entrepot = e.rowid"; if (!empty($fk_product) && $fk_product > 0) { $sql .= " AND ps.fk_product = ".((int) $fk_product); if (!empty($batch)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($batch)."'"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($batch)."'"; } } $sql .= " WHERE e.entity IN (".getEntity('stock').")"; @@ -699,9 +699,9 @@ class FormProduct $this->cache_lot = array(); $productIdList = implode(',', $productIdArray); $sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.rowid = pb.fk_product_stock"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".getEntity('stock').")"; + $sql .= " FROM ".$this->db->prefix()."product_batch as pb"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.rowid = pb.fk_product_stock"; + $sql .= " LEFT JOIN ".$this->db->prefix()."entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".getEntity('stock').")"; if (!empty($productIdList)) { $sql .= " WHERE ps.fk_product IN (".$this->db->sanitize($productIdList).")"; } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 27b2bdaff2c..ec9494e77b0 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -689,7 +689,7 @@ class Product extends CommonObject if ($result >= 0) { $sql = "SELECT count(*) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."product"; + $sql .= " FROM ".$this->db->prefix()."product"; $sql .= " WHERE entity IN (".getEntity('product').")"; $sql .= " AND ref = '".$this->db->escape($this->ref)."'"; @@ -698,7 +698,7 @@ class Product extends CommonObject $obj = $this->db->fetch_object($result); if ($obj->nb == 0) { // Produit non deja existant - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product ("; + $sql = "INSERT INTO ".$this->db->prefix()."product ("; $sql .= "datec"; $sql .= ", entity"; $sql .= ", ref"; @@ -761,7 +761,7 @@ class Product extends CommonObject dol_syslog(get_class($this)."::Create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."product"); + $id = $this->db->last_insert_id($this->db->prefix()."product"); if ($id > 0) { $this->id = $id; @@ -782,9 +782,9 @@ class Product extends CommonObject // update accountancy for this entity if (!$error && !empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { - $this->db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = " .((int) $this->id) . " AND entity = " . ((int) $conf->entity)); + $this->db->query("DELETE FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = " .((int) $this->id) . " AND entity = " . ((int) $conf->entity)); - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_perentity ("; + $sql = "INSERT INTO " . $this->db->prefix() . "product_perentity ("; $sql .= " fk_product"; $sql .= ", entity"; $sql .= ", accountancy_code_buy"; @@ -1062,7 +1062,7 @@ class Product extends CommonObject foreach ($ObjW->detail_batch as $detail) { // Each lines of detail in product_batch of the current $ObjW = product_stock if ($detail->batch == $valueforundefinedlot || $detail->batch == 'Undefined') { // We discard this line, we will create it later - $sqlclean = "DELETE FROM ".MAIN_DB_PREFIX."product_batch WHERE batch in('Undefined', '".$this->db->escape($valueforundefinedlot)."') AND fk_product_stock = ".((int) $ObjW->id); + $sqlclean = "DELETE FROM ".$this->db->prefix()."product_batch WHERE batch in('Undefined', '".$this->db->escape($valueforundefinedlot)."') AND fk_product_stock = ".((int) $ObjW->id); $result = $this->db->query($sqlclean); if (!$result) { dol_print_error($this->db); @@ -1094,7 +1094,7 @@ class Product extends CommonObject $this->barcode = $this->get_barcode($this, $this->barcode_type_code); } - $sql = "UPDATE ".MAIN_DB_PREFIX."product"; + $sql = "UPDATE ".$this->db->prefix()."product"; $sql .= " SET label = '".$this->db->escape($this->label)."'"; if ($updatetype && ($this->isProduct() || $this->isService())) { @@ -1182,9 +1182,9 @@ class Product extends CommonObject // update accountancy for this entity if (!$error && !empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { - $this->db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = " . ((int) $this->id) . " AND entity = " . ((int) $conf->entity)); + $this->db->query("DELETE FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = " . ((int) $this->id) . " AND entity = " . ((int) $conf->entity)); - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_perentity ("; + $sql = "INSERT INTO " . $this->db->prefix() . "product_perentity ("; $sql .= " fk_product"; $sql .= ", entity"; $sql .= ", accountancy_code_buy"; @@ -1327,9 +1327,9 @@ class Product extends CommonObject // Delete from product_batch on product delete if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch'; + $sql = "DELETE FROM ".$this->db->prefix().'product_batch'; $sql .= " WHERE fk_product_stock IN ("; - $sql .= "SELECT rowid FROM ".MAIN_DB_PREFIX.'product_stock'; + $sql .= "SELECT rowid FROM ".$this->db->prefix().'product_stock'; $sql .= " WHERE fk_product = ".((int) $this->id).")"; $result = $this->db->query($sql); @@ -1344,7 +1344,7 @@ class Product extends CommonObject $elements = array('product_fournisseur_price', 'product_price', 'product_lang', 'categorie_product', 'product_stock', 'product_customer_price', 'product_lot'); // product_batch is done before foreach ($elements as $table) { if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; + $sql = "DELETE FROM ".$this->db->prefix().$table; $sql .= " WHERE fk_product = ".(int) $this->id; $result = $this->db->query($sql); @@ -1377,7 +1377,7 @@ class Product extends CommonObject // Delete from product_association if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association"; + $sql = "DELETE FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".(int) $this->id." OR fk_product_fils = ".(int) $this->id; $result = $this->db->query($sql); @@ -1398,7 +1398,7 @@ class Product extends CommonObject // Delete product if (!$error) { - $sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product"; + $sqlz = "DELETE FROM ".$this->db->prefix()."product"; $sqlz .= " WHERE rowid = ".(int) $this->id; $resultz = $this->db->query($sqlz); @@ -1456,14 +1456,14 @@ class Product extends CommonObject foreach ($langs_available as $key => $value) { if ($key == $current_lang) { $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql .= " FROM ".$this->db->prefix()."product_lang"; $sql .= " WHERE fk_product = ".((int) $this->id); $sql .= " AND lang = '".$this->db->escape($key)."'"; $result = $this->db->query($sql); if ($this->db->num_rows($result)) { // if there is already a description line for this language - $sql2 = "UPDATE ".MAIN_DB_PREFIX."product_lang"; + $sql2 = "UPDATE ".$this->db->prefix()."product_lang"; $sql2 .= " SET "; $sql2 .= " label='".$this->db->escape($this->label)."',"; $sql2 .= " description='".$this->db->escape($this->description)."'"; @@ -1472,7 +1472,7 @@ class Product extends CommonObject } $sql2 .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($key)."'"; } else { - $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_lang (fk_product, lang, label, description"; + $sql2 = "INSERT INTO ".$this->db->prefix()."product_lang (fk_product, lang, label, description"; if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2 .= ", note"; } @@ -1496,14 +1496,14 @@ class Product extends CommonObject } $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql .= " FROM ".$this->db->prefix()."product_lang"; $sql .= " WHERE fk_product = ".((int) $this->id); $sql .= " AND lang = '".$this->db->escape($key)."'"; $result = $this->db->query($sql); if ($this->db->num_rows($result)) { // if there is already a description line for this language - $sql2 = "UPDATE ".MAIN_DB_PREFIX."product_lang"; + $sql2 = "UPDATE ".$this->db->prefix()."product_lang"; $sql2 .= " SET "; $sql2 .= " label = '".$this->db->escape($this->multilangs["$key"]["label"])."',"; $sql2 .= " description = '".$this->db->escape($this->multilangs["$key"]["description"])."'"; @@ -1512,7 +1512,7 @@ class Product extends CommonObject } $sql2 .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($key)."'"; } else { - $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_lang (fk_product, lang, label, description"; + $sql2 = "INSERT INTO ".$this->db->prefix()."product_lang (fk_product, lang, label, description"; if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2 .= ", note"; } @@ -1558,7 +1558,7 @@ class Product extends CommonObject */ public function delMultiLangs($langtodelete, $user) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_lang"; + $sql = "DELETE FROM ".$this->db->prefix()."product_lang"; $sql .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($langtodelete)."'"; dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG); @@ -1612,7 +1612,7 @@ class Product extends CommonObject return -1; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET "; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET "; $sql .= "$field = '".$this->db->escape($value)."'"; $sql .= " WHERE rowid = ".((int) $this->id); @@ -1655,7 +1655,7 @@ class Product extends CommonObject $current_lang = $langs->getDefaultLang(); $sql = "SELECT lang, label, description, note as other"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql .= " FROM ".$this->db->prefix()."product_lang"; $sql .= " WHERE fk_product = ".((int) $this->id); $result = $this->db->query($sql); @@ -1731,7 +1731,7 @@ class Product extends CommonObject } // Add new price - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(price_level,date_price, fk_product, fk_user_author, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,"; + $sql = "INSERT INTO ".$this->db->prefix()."product_price(price_level,date_price, fk_product, fk_user_author, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,"; $sql .= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, price_min,price_min_ttc,price_by_qty,entity,fk_price_expression) "; $sql .= " VALUES(".($level ? ((int) $level) : 1).", '".$this->db->idate($now)."', ".((int) $this->id).", ".((int) $user->id).", ".((float) price2num($this->price)).", ".((float) price2num($this->price_ttc)).",'".$this->db->escape($this->price_base_type)."',".((int) $this->status).", ".((float) price2num($this->tva_tx)).", ".($this->default_vat_code ? ("'".$this->db->escape($this->default_vat_code)."'") : "null").", ".((int) $this->tva_npr).","; $sql .= " ".price2num($this->localtax1_tx).", ".price2num($this->localtax2_tx).", '".$this->db->escape($this->localtax1_type)."', '".$this->db->escape($this->localtax2_type)."', ".price2num($this->price_min).", ".price2num($this->price_min_ttc).", ".price2num($this->price_by_qty).", ".((int) $conf->entity).",".($this->fk_price_expression > 0 ? ((int) $this->fk_price_expression) : 'null'); @@ -1760,11 +1760,11 @@ class Product extends CommonObject public function log_price_delete($user, $rowid) { // phpcs:enable - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql = "DELETE FROM ".$this->db->prefix()."product_price_by_qty"; $sql .= " WHERE fk_product_price = ".((int) $rowid); $resql = $this->db->query($sql); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price"; + $sql = "DELETE FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE rowid=".((int) $rowid); $resql = $this->db->query($sql); if ($resql) { @@ -1912,7 +1912,7 @@ class Product extends CommonObject if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $sql .= ", pfp.packaging"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp"; $sql .= " WHERE pfp.rowid = ".((int) $prodfournprice); if ($qty > 0) { $sql .= " AND pfp.quantity <= ".((float) $qty); @@ -1966,7 +1966,7 @@ class Product extends CommonObject $sql .= " pfp.default_vat_code,"; $sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,"; $sql .= " pfp.packaging"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp"; $sql .= " WHERE pfp.fk_product = ".((int) $product_id); if ($fourn_ref != 'none') { $sql .= " AND pfp.ref_fourn = '".$this->db->escape($fourn_ref)."'"; @@ -2146,7 +2146,7 @@ class Product extends CommonObject // Ne pas mettre de quote sur les numeriques decimaux. // Ceci provoque des stockages avec arrondis en base au lieu des valeurs exactes. - $sql = "UPDATE ".MAIN_DB_PREFIX."product SET"; + $sql = "UPDATE ".$this->db->prefix()."product SET"; $sql .= " price_base_type='".$this->db->escape($newpricebase)."',"; $sql .= " price=".$price.","; $sql .= " price_ttc=".$price_ttc.","; @@ -2276,7 +2276,7 @@ class Product extends CommonObject $separatedStock = false; // Set to true will count stock from subtable llx_product_stock. It is slower than using denormalized field 'stock', but it is required when using multientity and shared warehouses. if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED)) { if (!empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) { - $checkPMPPerEntity = $this->db->query("SELECT pmp FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = ".((int) $id)." AND entity = ".(int) $conf->entity); + $checkPMPPerEntity = $this->db->query("SELECT pmp FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = ".((int) $id)." AND entity = ".(int) $conf->entity); if ($this->db->num_rows($checkPMPPerEntity)>0) { $separatedEntityPMP = true; } @@ -2300,12 +2300,12 @@ class Product extends CommonObject } else { $sql .= " p.stock"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product as p"; if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) || $separatedEntityPMP) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); + $sql .= " LEFT JOIN " . $this->db->prefix() . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); } if ($separatedStock) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as sp ON sp.fk_product = p.rowid AND sp.fk_entrepot IN (SELECT rowid FROM ".MAIN_DB_PREFIX."entrepot WHERE entity IN (".$this->db->sanitize($visibleWarehousesEntities)."))"; + $sql .= " LEFT JOIN " . $this->db->prefix() . "product_stock as sp ON sp.fk_product = p.rowid AND sp.fk_entrepot IN (SELECT rowid FROM ".$this->db->prefix()."entrepot WHERE entity IN (".$this->db->sanitize($visibleWarehousesEntities)."))"; } if ($id) { @@ -2455,7 +2455,7 @@ class Product extends CommonObject for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; $sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE entity IN (".getEntity('productprice').")"; $sql .= " AND price_level=".((int) $i); $sql .= " AND fk_product = ".((int) $this->id); @@ -2482,7 +2482,7 @@ class Product extends CommonObject if ($this->prices_by_qty[$i] == 1) { $sql = "SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql.= " FROM ".$this->db->prefix()."product_price_by_qty"; $sql.= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[$i]); $sql.= " ORDER BY quantity ASC"; $resultat=array(); @@ -2519,7 +2519,7 @@ class Product extends CommonObject } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) && empty($ignore_price_load)) { // prices per quantity $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; $sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE fk_product = ".((int) $this->id); $sql .= " ORDER BY date_price DESC, rowid DESC"; $sql .= " LIMIT 1"; @@ -2533,7 +2533,7 @@ class Product extends CommonObject // Récuperation de la liste des prix selon qty si flag positionné if ($this->prices_by_qty[0] == 1) { $sql = "SELECT rowid,price, unitprice, quantity, remise_percent, remise, remise, price_base_type"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql .= " FROM ".$this->db->prefix()."product_price_by_qty"; $sql .= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[0]); $sql .= " ORDER BY quantity ASC"; $resultat = array(); @@ -2565,7 +2565,7 @@ class Product extends CommonObject for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; $sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE entity IN (".getEntity('productprice').")"; $sql .= " AND price_level=".((int) $i); $sql .= " AND fk_product = ".((int) $this->id); @@ -2590,7 +2590,7 @@ class Product extends CommonObject // Récuperation de la liste des prix selon qty si flag positionné if ($this->prices_by_qty[$i] == 1) { $sql = "SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql .= " FROM ".$this->db->prefix()."product_price_by_qty"; $sql .= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[$i]); $sql .= " ORDER BY quantity ASC"; $resultat = array(); @@ -2668,10 +2668,10 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " SUM(mp.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."mrp_production as mp ON mp.fk_mo=c.rowid"; + $sql .= " FROM ".$this->db->prefix()."mrp_mo as c"; + $sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= "INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id); + $sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id); } $sql .= " WHERE "; $sql .= " c.entity IN (".getEntity('mo').")"; @@ -2728,8 +2728,8 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT b.rowid) as nb_toproduce,"; $sql .= " SUM(b.qty) as qty_toproduce"; - $sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as b"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."bom_bomline as bl ON bl.fk_bom=b.rowid"; + $sql .= " FROM ".$this->db->prefix()."bom_bom as b"; + $sql .= " INNER JOIN ".$this->db->prefix()."bom_bomline as bl ON bl.fk_bom=b.rowid"; $sql .= " WHERE "; $sql .= " b.entity IN (".getEntity('bom').")"; $sql .= " AND b.fk_product =".((int) $this->id); @@ -2747,8 +2747,8 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT bl.rowid) as nb_toconsume,"; $sql .= " SUM(bl.qty) as qty_toconsume"; - $sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as b"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."bom_bomline as bl ON bl.fk_bom=b.rowid"; + $sql .= " FROM ".$this->db->prefix()."bom_bom as b"; + $sql .= " INNER JOIN ".$this->db->prefix()."bom_bomline as bl ON bl.fk_bom=b.rowid"; $sql .= " WHERE "; $sql .= " b.entity IN (".getEntity('bom').")"; $sql .= " AND bl.fk_product =".((int) $this->id); @@ -2790,11 +2790,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_customers, COUNT(DISTINCT p.rowid) as nb,"; $sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd"; - $sql .= ", ".MAIN_DB_PREFIX."propal as p"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."propaldet as pd"; + $sql .= ", ".$this->db->prefix()."propal as p"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = pd.fk_propal"; $sql .= " AND p.fk_soc = s.rowid"; @@ -2865,11 +2865,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_suppliers, COUNT(DISTINCT p.rowid) as nb,"; $sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as pd"; - $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."supplier_proposaldet as pd"; + $sql .= ", ".$this->db->prefix()."supplier_proposal as p"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = pd.fk_supplier_proposal"; $sql .= " AND p.fk_soc = s.rowid"; @@ -2921,11 +2921,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; - $sql .= ", ".MAIN_DB_PREFIX."commande as c"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commandedet as cd"; + $sql .= ", ".$this->db->prefix()."commande as c"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; @@ -2976,10 +2976,10 @@ class Product extends CommonObject if (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) { if (!empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) { $adeduire = 0; - $sql = "SELECT sum(fd.qty) as count FROM ".MAIN_DB_PREFIX."facturedet fd "; - $sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON fd.fk_facture = f.rowid "; - $sql .= " JOIN ".MAIN_DB_PREFIX."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; - $sql .= " JOIN ".MAIN_DB_PREFIX."commande c ON el.fk_source = c.rowid "; + $sql = "SELECT sum(fd.qty) as count FROM ".$this->db->prefix()."facturedet fd "; + $sql .= " JOIN ".$this->db->prefix()."facture f ON fd.fk_facture = f.rowid "; + $sql .= " JOIN ".$this->db->prefix()."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; + $sql .= " JOIN ".$this->db->prefix()."commande c ON el.fk_source = c.rowid "; $sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id); dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); @@ -3023,11 +3023,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; - $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commande_fournisseurdet as cd"; + $sql .= ", ".$this->db->prefix()."commande_fournisseur as c"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; @@ -3081,13 +3081,13 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT e.fk_soc) as nb_customers, COUNT(DISTINCT e.rowid) as nb,"; $sql .= " COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed"; - $sql .= ", ".MAIN_DB_PREFIX."commandedet as cd"; - $sql .= ", ".MAIN_DB_PREFIX."commande as c"; - $sql .= ", ".MAIN_DB_PREFIX."expedition as e"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."expeditiondet as ed"; + $sql .= ", ".$this->db->prefix()."commandedet as cd"; + $sql .= ", ".$this->db->prefix()."commande as c"; + $sql .= ", ".$this->db->prefix()."expedition as e"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE e.rowid = ed.fk_expedition"; $sql .= " AND c.rowid = cd.fk_commande"; @@ -3166,11 +3166,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd"; - $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commande_fournisseur_dispatch as fd"; + $sql .= ", ".$this->db->prefix()."commande_fournisseur as cf"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE cf.rowid = fd.fk_commande"; $sql .= " AND cf.fk_soc = s.rowid"; @@ -3223,11 +3223,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT m.fk_soc) as nb_customers, COUNT(DISTINCT m.rowid) as nb,"; $sql .= " COUNT(mp.rowid) as nb_rows, SUM(mp.qty) as qty, role"; - $sql .= " FROM ".MAIN_DB_PREFIX."mrp_production as mp"; - $sql .= ", ".MAIN_DB_PREFIX."mrp_mo as m"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = m.fk_soc"; + $sql .= " FROM ".$this->db->prefix()."mrp_production as mp"; + $sql .= ", ".$this->db->prefix()."mrp_mo as m"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON s.rowid = m.fk_soc"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE m.rowid = mp.fk_mo"; $sql .= " AND m.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mrp').")"; @@ -3316,11 +3316,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; - $sql .= ", ".MAIN_DB_PREFIX."contrat as c"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."contratdet as cd"; + $sql .= ", ".$this->db->prefix()."contrat as c"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_contrat"; $sql .= " AND c.fk_soc = s.rowid"; @@ -3390,11 +3390,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_customers, COUNT(DISTINCT f.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(".$this->db->ifsql('f.type != 2', 'fd.qty', 'fd.qty * -1').") as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd"; - $sql .= ", ".MAIN_DB_PREFIX."facture as f"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."facturedet as fd"; + $sql .= ", ".$this->db->prefix()."facture as f"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = fd.fk_facture"; $sql .= " AND f.fk_soc = s.rowid"; @@ -3464,11 +3464,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as fd"; - $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."facture_fourn_det as fd"; + $sql .= ", ".$this->db->prefix()."facture_fourn as f"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = fd.fk_facture_fourn"; $sql .= " AND f.fk_soc = s.rowid"; @@ -3595,12 +3595,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT f.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as d, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."facturedet as d, ".$this->db->prefix()."facture as f, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = d.fk_facture"; if ($this->id > 0) { @@ -3648,12 +3648,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT f.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as d, ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."facture_fourn_det as d, ".$this->db->prefix()."facture_fourn as f, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = d.fk_facture_fourn"; if ($this->id > 0) { @@ -3699,12 +3699,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT p.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."propaldet as d, ".$this->db->prefix()."propal as p, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as prod"; + $sql .= ", ".$this->db->prefix()."product as prod"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = d.fk_propal"; if ($this->id > 0) { @@ -3751,12 +3751,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT p.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."supplier_proposaldet as d, ".$this->db->prefix()."supplier_proposal as p, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as prod"; + $sql .= ", ".$this->db->prefix()."product as prod"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = d.fk_supplier_proposal"; if ($this->id > 0) { @@ -3802,12 +3802,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as d, ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commandedet as d, ".$this->db->prefix()."commande as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = d.fk_commande"; if ($this->id > 0) { @@ -3853,12 +3853,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as d, ".MAIN_DB_PREFIX."commande_fournisseur as c, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commande_fournisseurdet as d, ".$this->db->prefix()."commande_fournisseur as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = d.fk_commande"; if ($this->id > 0) { @@ -3904,12 +3904,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as d, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."contratdet as d, ".$this->db->prefix()."contrat as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.entity IN (".getEntity('contract').")"; @@ -3958,12 +3958,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT d.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as d LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid"; + $sql .= " FROM ".$this->db->prefix()."mrp_mo as d LEFT JOIN ".$this->db->prefix()."societe as s ON d.fk_soc = s.rowid"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE d.entity IN (".getEntity('mo').")"; @@ -4021,21 +4021,21 @@ class Product extends CommonObject } // Check not already father of id_pere (to avoid father -> child -> father links) - $sql = "SELECT fk_product_pere from ".MAIN_DB_PREFIX."product_association"; + $sql = "SELECT fk_product_pere from ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $id_fils)." AND fk_product_fils = ".((int) $id_pere); if (!$this->db->query($sql)) { dol_print_error($this->db); return -1; } else { //Selection of the highest row - $sql = "SELECT MAX(rang) as max_rank FROM ".MAIN_DB_PREFIX."product_association"; + $sql = "SELECT MAX(rang) as max_rank FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $id_pere); $resql = $this->db->query($sql); if ($resql > 0) { $obj = $this->db->fetch_object($resql); $rank = $obj->max_rank + 1; //Addition of a product with the highest rank +1 - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_association(fk_product_pere,fk_product_fils,qty,incdec,rang)"; + $sql = "INSERT INTO ".$this->db->prefix()."product_association(fk_product_pere,fk_product_fils,qty,incdec,rang)"; $sql .= " VALUES (".((int) $id_pere).", ".((int) $id_fils).", ".price2num($qty, 'MS').", ".price2num($incdec, 'MS').", ".((int) $rank).")"; if (! $this->db->query($sql)) { dol_print_error($this->db); @@ -4077,7 +4077,7 @@ class Product extends CommonObject $qty = 1; } - $sql = 'UPDATE '.MAIN_DB_PREFIX.'product_association SET '; + $sql = 'UPDATE '.$this->db->prefix().'product_association SET '; $sql .= 'qty = '.price2num($qty, 'MS'); $sql .= ',incdec = '.price2num($incdec, 'MS'); $sql .= ' WHERE fk_product_pere = '.((int) $id_pere).' AND fk_product_fils = '.((int) $id_fils); @@ -4108,7 +4108,7 @@ class Product extends CommonObject $fk_child = 0; } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association"; + $sql = "DELETE FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $fk_parent); $sql .= " AND fk_product_fils = ".((int) $fk_child); @@ -4119,7 +4119,7 @@ class Product extends CommonObject } // Updated ranks so that none are missing - $sqlrank = "SELECT rowid, rang FROM ".MAIN_DB_PREFIX."product_association"; + $sqlrank = "SELECT rowid, rang FROM ".$this->db->prefix()."product_association"; $sqlrank.= " WHERE fk_product_pere = ".((int) $fk_parent); $sqlrank.= " ORDER BY rang"; $resqlrank = $this->db->query($sqlrank); @@ -4127,7 +4127,7 @@ class Product extends CommonObject $cpt = 0; while ($objrank = $this->db->fetch_object($resqlrank)) { $cpt++; - $sql = "UPDATE ".MAIN_DB_PREFIX."product_association"; + $sql = "UPDATE ".$this->db->prefix()."product_association"; $sql.= " SET rang = ".((int) $cpt); $sql.= " WHERE rowid = ".((int) $objrank->rowid); if (! $this->db->query($sql)) { @@ -4151,7 +4151,7 @@ class Product extends CommonObject { // phpcs:enable $sql = "SELECT fk_product_pere, qty, incdec"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_association"; + $sql .= " FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $fk_parent); $sql .= " AND fk_product_fils = ".((int) $fk_child); @@ -4201,7 +4201,7 @@ class Product extends CommonObject if ($ref_fourn) { $sql = "SELECT rowid, fk_product"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price"; $sql .= " WHERE fk_soc = ".((int) $id_fourn); $sql .= " AND ref_fourn = '".$this->db->escape($ref_fourn)."'"; $sql .= " AND fk_product <> ".((int) $this->id); @@ -4220,7 +4220,7 @@ class Product extends CommonObject } $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price"; $sql .= " WHERE fk_soc = ".((int) $id_fourn); if ($ref_fourn) { $sql .= " AND ref_fourn = '".$this->db->escape($ref_fourn)."'"; @@ -4237,7 +4237,7 @@ class Product extends CommonObject // The reference supplier does not exist, we create it for this product. if (empty($obj)) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price("; + $sql = "INSERT INTO ".$this->db->prefix()."product_fournisseur_price("; $sql .= "datec"; $sql .= ", entity"; $sql .= ", fk_product"; @@ -4258,7 +4258,7 @@ class Product extends CommonObject $sql .= ")"; if ($this->db->query($sql)) { - $this->product_fourn_price_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur_price"); + $this->product_fourn_price_id = $this->db->last_insert_id($this->db->prefix()."product_fournisseur_price"); return 1; } else { $this->error = $this->db->lasterror(); @@ -4290,7 +4290,7 @@ class Product extends CommonObject $list = array(); $sql = "SELECT DISTINCT p.fk_soc"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as p"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as p"; $sql .= " WHERE p.fk_product = ".((int) $this->id); $sql .= " AND p.entity = ".((int) $conf->entity); @@ -4325,7 +4325,7 @@ class Product extends CommonObject $this->db->begin(); // prices - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price ("; + $sql = "INSERT INTO ".$this->db->prefix()."product_price ("; $sql .= " entity"; $sql .= ", fk_product"; $sql .= ", date_price"; @@ -4378,7 +4378,7 @@ class Product extends CommonObject $sql .= ", multicurrency_tx"; $sql .= ", multicurrency_price"; $sql .= ", multicurrency_price_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE fk_product = ".((int) $fromId); $sql .= " ORDER BY date_price DESC"; if ($conf->global->PRODUIT_MULTIPRICES_LIMIT > 0) { @@ -4409,8 +4409,8 @@ class Product extends CommonObject // phpcs:enable $this->db->begin(); - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_association (fk_product_pere, fk_product_fils, qty)'; - $sql .= " SELECT ".$toId.", fk_product_fils, qty FROM ".MAIN_DB_PREFIX."product_association"; + $sql = 'INSERT INTO '.$this->db->prefix().'product_association (fk_product_pere, fk_product_fils, qty)'; + $sql .= " SELECT ".$toId.", fk_product_fils, qty FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $fromId); dol_syslog(get_class($this).'::clone_association', LOG_DEBUG); @@ -4439,10 +4439,10 @@ class Product extends CommonObject $now = dol_now(); // les fournisseurs - /*$sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur (" + /*$sql = "INSERT ".$this->db->prefix()."product_fournisseur (" . " datec, fk_product, fk_soc, ref_fourn, fk_user_author )" . " SELECT '".$this->db->idate($now)."', ".$toId.", fk_soc, ref_fourn, fk_user_author" - . " FROM ".MAIN_DB_PREFIX."product_fournisseur" + . " FROM ".$this->db->prefix()."product_fournisseur" . " WHERE fk_product = ".((int) $fromId); if ( ! $this->db->query($sql ) ) @@ -4452,10 +4452,10 @@ class Product extends CommonObject }*/ // les prix de fournisseurs. - $sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur_price ("; + $sql = "INSERT ".$this->db->prefix()."product_fournisseur_price ("; $sql .= " datec, fk_product, fk_soc, price, quantity, fk_user)"; $sql .= " SELECT '".$this->db->idate($now)."', ".((int) $toId).", fk_soc, price, quantity, fk_user"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price"; $sql .= " WHERE fk_product = ".((int) $fromId); dol_syslog(get_class($this).'::clone_fournisseurs', LOG_DEBUG); @@ -4573,7 +4573,7 @@ class Product extends CommonObject $nb = 0; $sql = "SELECT COUNT(pa.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa"; + $sql .= " FROM ".$this->db->prefix()."product_association as pa"; if ($mode == 0) { $sql .= " WHERE pa.fk_product_fils = ".((int) $this->id)." OR pa.fk_product_pere = ".((int) $this->id); } elseif ($mode == -1) { @@ -4603,7 +4603,7 @@ class Product extends CommonObject public function hasVariants() { $nb = 0; - $sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_parent = ".((int) $this->id); + $sql = "SELECT count(rowid) as nb FROM ".$this->db->prefix()."product_attribute_combination WHERE fk_product_parent = ".((int) $this->id); $sql .= " AND entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); @@ -4627,7 +4627,7 @@ class Product extends CommonObject { global $conf; if (!empty($conf->variants->enabled)) { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".((int) $this->id)." AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid FROM ".$this->db->prefix()."product_attribute_combination WHERE fk_product_child = ".((int) $this->id)." AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -4655,8 +4655,8 @@ class Product extends CommonObject { $sql = "SELECT p.rowid, p.label as label, p.ref as ref, pa.fk_product_pere as id, p.fk_product_type, pa.qty, pa.incdec, p.entity"; $sql .= ", p.tosell as status, p.tobuy as status_buy"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa,"; - $sql .= " ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product_association as pa,"; + $sql .= " ".$this->db->prefix()."product as p"; $sql .= " WHERE p.rowid = pa.fk_product_pere"; $sql .= " AND pa.fk_product_fils = ".((int) $this->id); @@ -4702,8 +4702,8 @@ class Product extends CommonObject $sql = "SELECT p.rowid, p.ref, p.label as label, p.fk_product_type,"; $sql .= " pa.qty as qty, pa.fk_product_fils as id, pa.incdec,"; $sql .= " pa.rowid as fk_association, pa.rang"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as p,"; - $sql .= " ".MAIN_DB_PREFIX."product_association as pa"; + $sql .= " FROM ".$this->db->prefix()."product as p,"; + $sql .= " ".$this->db->prefix()."product_association as pa"; $sql .= " WHERE p.rowid = pa.fk_product_fils"; $sql .= " AND pa.fk_product_pere = ".((int) $id); $sql .= " AND pa.fk_product_fils <> ".((int) $id); // This should not happens, it is to avoid infinite loop if it happens @@ -5088,7 +5088,7 @@ class Product extends CommonObject $langs->load('products'); if (isset($this->finished) && $this->finished >= 0) { - $sql = "SELECT label, code FROM ".MAIN_DB_PREFIX."c_product_nature where code = ".((int) $this->finished)." AND active=1"; + $sql = "SELECT label, code FROM ".$this->db->prefix()."c_product_nature where code = ".((int) $this->finished)." AND active=1"; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { $res = $this->db->fetch_array($resql); @@ -5249,8 +5249,8 @@ class Product extends CommonObject } $sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql .= ", ".MAIN_DB_PREFIX."entrepot as w"; + $sql .= " FROM ".$this->db->prefix()."product_stock as ps"; + $sql .= ", ".$this->db->prefix()."entrepot as w"; $sql .= " WHERE w.entity IN (".getEntity('stock').")"; $sql .= " AND w.rowid = ps.fk_entrepot"; $sql .= " AND ps.fk_product = ".((int) $this->id); @@ -5413,7 +5413,7 @@ class Product extends CommonObject { $result = array(); - $sql = "SELECT pb.batch, pb.eatby, pb.sellby, SUM(pb.qty) AS qty FROM ".MAIN_DB_PREFIX."product_batch as pb, ".MAIN_DB_PREFIX."product_stock as ps"; + $sql = "SELECT pb.batch, pb.eatby, pb.sellby, SUM(pb.qty) AS qty FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps"; $sql .= " WHERE pb.fk_product_stock = ps.rowid AND ps.fk_product = ".((int) $this->id)." AND pb.batch = '".$this->db->escape($batch)."'"; $sql .= " GROUP BY pb.batch, pb.eatby, pb.sellby"; dol_syslog(get_class($this)."::loadBatchInfo load first entry found for lot/serial = ".$batch, LOG_DEBUG); @@ -5647,7 +5647,7 @@ class Product extends CommonObject $this->nb = array(); $sql = "SELECT count(p.rowid) as nb, fk_product_type"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product as p"; $sql .= ' WHERE p.entity IN ('.getEntity($this->element, 1).')'; // Add where from hooks if (is_object($hookmanager)) { @@ -5805,7 +5805,7 @@ class Product extends CommonObject $label_type = 'short_label'; } - $sql = "SELECT ".$label_type.", code from ".MAIN_DB_PREFIX."c_units where rowid = ".((int) $this->fk_unit); + $sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit); $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { @@ -5913,7 +5913,7 @@ class Product extends CommonObject { global $conf, $db; - $sql = "SELECT rowid, level, fk_level, var_percent, var_min_percent FROM ".MAIN_DB_PREFIX."product_pricerules"; + $sql = "SELECT rowid, level, fk_level, var_percent, var_min_percent FROM ".$this->db->prefix()."product_pricerules"; $query = $this->db->query($sql); $rules = array(); @@ -5986,7 +5986,7 @@ class Product extends CommonObject { $sql = "SELECT p.rowid, p.ref, p.datec as date_creation, p.tms as date_modification,"; $sql .= " p.fk_user_author, p.fk_user_modif"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as p"; $sql .= " WHERE p.rowid = ".((int) $id); $result = $this->db->query($sql); diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index 9bd361858ba..4a8233a61eb 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -87,7 +87,7 @@ class Productbatch extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_batch ("; + $sql = "INSERT INTO ".$this->db->prefix()."product_batch ("; $sql .= "fk_product_stock,"; $sql .= "sellby,"; // no more used $sql .= "eatby,"; // no more used @@ -111,7 +111,7 @@ class Productbatch extends CommonObject $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().self::$_table_element); } // Commit or rollback @@ -149,8 +149,8 @@ class Productbatch extends CommonObject $sql .= " pl.eatby,"; $sql .= " pl.sellby"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as t INNER JOIN ".MAIN_DB_PREFIX."product_stock w on t.fk_product_stock = w.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl on pl.fk_product = w.fk_product and pl.batch = t.batch"; + $sql .= " FROM ".$this->db->prefix()."product_batch as t INNER JOIN ".$this->db->prefix()."product_stock w on t.fk_product_stock = w.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_lot as pl on pl.fk_product = w.fk_product and pl.batch = t.batch"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -199,7 +199,7 @@ class Productbatch extends CommonObject } // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.self::$_table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().self::$_table_element." SET"; $sql .= " fk_product_stock=".(isset($this->fk_product_stock) ? $this->fk_product_stock : "null").","; $sql .= " sellby=".(dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null').","; $sql .= " eatby=".(dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').","; @@ -245,7 +245,7 @@ class Productbatch extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element.""; + $sql = "DELETE FROM ".$this->db->prefix().self::$_table_element.""; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); @@ -383,7 +383,7 @@ class Productbatch extends CommonObject $sql .= " t.batch,"; $sql .= " t.qty,"; $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as t"; + $sql .= " FROM ".$this->db->prefix().self::$_table_element." as t"; $sql .= " WHERE fk_product_stock=".((int) $fk_product_stock); if (!empty($eatby)) { @@ -453,9 +453,9 @@ class Productbatch extends CommonObject $sql .= ", pl.rowid as lotid, pl.eatby as eatby, pl.sellby as sellby"; // TODO May add extrafields to ? } - $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as t"; + $sql .= " FROM ".$this->db->prefix()."product_batch as t"; if ($fk_product > 0) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.fk_product = ".((int) $fk_product)." AND pl.batch = t.batch"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_lot as pl ON pl.fk_product = ".((int) $fk_product)." AND pl.batch = t.batch"; // TODO May add extrafields to ? } $sql .= " WHERE fk_product_stock=".((int) $fk_product_stock); @@ -526,10 +526,10 @@ class Productbatch extends CommonObject $sql .= ", pl.sellby"; $sql .= ", pl.eatby"; $sql .= ", pb.qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lot as pl"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pl.fk_product"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch AS pb ON pl.batch = pb.batch"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock AS ps ON ps.rowid = pb.fk_product_stock"; + $sql .= " FROM ".$this->db->prefix()."product_lot as pl"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product as p ON p.rowid = pl.fk_product"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch AS pb ON pl.batch = pb.batch"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_stock AS ps ON ps.rowid = pb.fk_product_stock"; $sql .= " WHERE p.entity IN (".getEntity('product').")"; $sql .= " AND pl.fk_product = ".((int) $fk_product); if ($fk_warehouse > 0) { diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index a9444d1c569..1c91c3804d2 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -188,7 +188,7 @@ class Productcustomerprice extends CommonObject } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_customer_price("; + $sql = "INSERT INTO ".$this->db->prefix()."product_customer_price("; $sql .= "entity,"; $sql .= "datec,"; $sql .= "fk_product,"; @@ -240,7 +240,7 @@ class Productcustomerprice extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_customer_price"); + $this->id = $this->db->last_insert_id($this->db->prefix()."product_customer_price"); if (!$notrigger) { $result = $this->call_trigger('PRODUCT_CUSTOMER_PRICE_CREATE', $user); @@ -301,7 +301,7 @@ class Productcustomerprice extends CommonObject $sql .= " t.localtax2_tx,"; $sql .= " t.fk_user,"; $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t"; + $sql .= " FROM ".$this->db->prefix()."product_customer_price as t"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -392,9 +392,9 @@ class Productcustomerprice extends CommonObject $sql .= " t.import_key,"; $sql .= " soc.nom as socname,"; $sql .= " prod.ref as prodref"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t,"; - $sql .= " ".MAIN_DB_PREFIX."product as prod,"; - $sql .= " ".MAIN_DB_PREFIX."societe as soc"; + $sql .= " FROM ".$this->db->prefix()."product_customer_price as t,"; + $sql .= " ".$this->db->prefix()."product as prod,"; + $sql .= " ".$this->db->prefix()."societe as soc"; $sql .= " WHERE soc.rowid=t.fk_soc "; $sql .= " AND prod.rowid=t.fk_product "; $sql .= " AND prod.entity IN (".getEntity('product').")"; @@ -510,9 +510,9 @@ class Productcustomerprice extends CommonObject $sql .= " t.import_key,"; $sql .= " soc.nom as socname,"; $sql .= " prod.ref as prodref"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price_log as t"; - $sql .= " ,".MAIN_DB_PREFIX."product as prod"; - $sql .= " ,".MAIN_DB_PREFIX."societe as soc"; + $sql .= " FROM ".$this->db->prefix()."product_customer_price_log as t"; + $sql .= " ,".$this->db->prefix()."product as prod"; + $sql .= " ,".$this->db->prefix()."societe as soc"; $sql .= " WHERE soc.rowid=t.fk_soc"; $sql .= " AND prod.rowid=t.fk_product "; $sql .= " AND prod.entity IN (".getEntity('product').")"; @@ -675,7 +675,7 @@ class Productcustomerprice extends CommonObject // Do a copy of current record into log table // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_customer_price_log("; + $sql = "INSERT INTO ".$this->db->prefix()."product_customer_price_log("; $sql .= "entity,"; $sql .= "datec,"; @@ -720,7 +720,7 @@ class Productcustomerprice extends CommonObject $sql .= " t.fk_user,"; $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t"; + $sql .= " FROM ".$this->db->prefix()."product_customer_price as t"; $sql .= " WHERE t.rowid = ".((int) $this->id); $this->db->begin(); @@ -732,7 +732,7 @@ class Productcustomerprice extends CommonObject } // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."product_customer_price SET"; + $sql = "UPDATE ".$this->db->prefix()."product_customer_price SET"; $sql .= " entity=".$conf->entity.","; $sql .= " datec='".$this->db->idate(dol_now())."',"; @@ -813,7 +813,7 @@ class Productcustomerprice extends CommonObject // Find all susidiaries $sql = "SELECT s.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."societe as s"; $sql .= " WHERE s.parent = ".((int) $this->fk_soc); $sql .= " AND s.entity IN (".getEntity('societe').")"; @@ -911,7 +911,7 @@ class Productcustomerprice extends CommonObject } if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_customer_price"; + $sql = "DELETE FROM ".$this->db->prefix()."product_customer_price"; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); diff --git a/htdocs/product/class/productfournisseurprice.class.php b/htdocs/product/class/productfournisseurprice.class.php index d82d1784938..0ce6868fd0c 100644 --- a/htdocs/product/class/productfournisseurprice.class.php +++ b/htdocs/product/class/productfournisseurprice.class.php @@ -318,7 +318,7 @@ class ProductFournisseurPrice extends CommonObject $sql = 'SELECT '; $sql .= $this->getFieldList(); - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')'; else $sql .= ' WHERE 1 = 1'; // Manage filter @@ -433,7 +433,7 @@ class ProductFournisseurPrice extends CommonObject if (!empty($num)) { // Validate - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ref = '".$this->db->escape($num)."',"; $sql .= " status = ".self::STATUS_VALIDATED; if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."'"; @@ -462,7 +462,7 @@ class ProductFournisseurPrice extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'"; + $sql = 'UPDATE '.$this->db->prefix()."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } @@ -700,7 +700,7 @@ class ProductFournisseurPrice extends CommonObject { $sql = 'SELECT rowid, date_creation as datec, tms as datem,'; $sql .= ' fk_user_creat, fk_user_modif'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE t.rowid = '.((int) $id); $result = $this->db->query($sql); if ($result) { diff --git a/htdocs/product/class/propalmergepdfproduct.class.php b/htdocs/product/class/propalmergepdfproduct.class.php index 9663bea4756..00c492f91de 100644 --- a/htdocs/product/class/propalmergepdfproduct.class.php +++ b/htdocs/product/class/propalmergepdfproduct.class.php @@ -104,7 +104,7 @@ class Propalmergepdfproduct extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_merge_pdf_product("; + $sql = "INSERT INTO ".$this->db->prefix()."propal_merge_pdf_product("; $sql .= "fk_product,"; $sql .= "file_name,"; if ($conf->global->MAIN_MULTILANGS) { @@ -132,7 +132,7 @@ class Propalmergepdfproduct extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal_merge_pdf_product"); + $this->id = $this->db->last_insert_id($this->db->prefix()."propal_merge_pdf_product"); } // Commit or rollback @@ -173,7 +173,7 @@ class Propalmergepdfproduct extends CommonObject $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; + $sql .= " FROM ".$this->db->prefix()."propal_merge_pdf_product as t"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(__METHOD__, LOG_DEBUG); @@ -231,7 +231,7 @@ class Propalmergepdfproduct extends CommonObject $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; + $sql .= " FROM ".$this->db->prefix()."propal_merge_pdf_product as t"; $sql .= " WHERE t.fk_product = ".((int) $product_id); if (!empty($conf->global->MAIN_MULTILANGS) && !empty($lang)) { $sql .= " AND t.lang = '".$this->db->escape($lang)."'"; @@ -307,7 +307,7 @@ class Propalmergepdfproduct extends CommonObject // Put here code to add a control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."propal_merge_pdf_product SET"; + $sql = "UPDATE ".$this->db->prefix()."propal_merge_pdf_product SET"; $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; $sql .= " file_name=".(isset($this->file_name) ? "'".$this->db->escape($this->file_name)."'" : "null").","; @@ -357,7 +357,7 @@ class Propalmergepdfproduct extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product"; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(__METHOD__, LOG_DEBUG); @@ -400,7 +400,7 @@ class Propalmergepdfproduct extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product"; $sql .= " WHERE fk_product = ".((int) $product_id); if ($conf->global->MAIN_MULTILANGS && !empty($lang_id)) { @@ -444,7 +444,7 @@ class Propalmergepdfproduct extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product"; $sql .= " WHERE fk_product = ".((int) $this->fk_product)." AND file_name = '".$this->db->escape($this->file_name)."'"; dol_syslog(__METHOD__, LOG_DEBUG); From 9278c7cb859f0e9525673aef5846f105df8083bc Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 27 Jan 2022 10:15:08 +0100 Subject: [PATCH 038/132] FIX convert dynamic_price class --- .../class/price_expression.class.php | 14 +++++++------- .../class/price_global_variable.class.php | 12 ++++++------ .../price_global_variable_updater.class.php | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/htdocs/product/dynamic_price/class/price_expression.class.php b/htdocs/product/dynamic_price/class/price_expression.class.php index 564c2448e58..255908726d4 100644 --- a/htdocs/product/dynamic_price/class/price_expression.class.php +++ b/htdocs/product/dynamic_price/class/price_expression.class.php @@ -88,7 +88,7 @@ class PriceExpression } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "title, expression"; $sql .= ") VALUES ("; $sql .= " ".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "''").","; @@ -104,7 +104,7 @@ class PriceExpression } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); //if (! $notrigger) //{ @@ -148,7 +148,7 @@ class PriceExpression } $sql = "SELECT title, expression"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(__METHOD__); @@ -179,7 +179,7 @@ class PriceExpression { // phpcs:enable $sql = "SELECT rowid, title, expression"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " ORDER BY title"; dol_syslog(__METHOD__, LOG_DEBUG); @@ -215,7 +215,7 @@ class PriceExpression { // phpcs:enable $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE title = '".$this->db->escape($title)."'"; dol_syslog(__METHOD__, LOG_DEBUG); @@ -254,7 +254,7 @@ class PriceExpression } // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " title = ".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "''").","; $sql .= " expression = ".(isset($this->expression) ? "'".$this->db->escape($this->expression)."'" : "''").""; $sql .= " WHERE rowid = ".((int) $this->id); @@ -326,7 +326,7 @@ class PriceExpression //} if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(__METHOD__); diff --git a/htdocs/product/dynamic_price/class/price_global_variable.class.php b/htdocs/product/dynamic_price/class/price_global_variable.class.php index a7b22f2ef13..336fb024470 100644 --- a/htdocs/product/dynamic_price/class/price_global_variable.class.php +++ b/htdocs/product/dynamic_price/class/price_global_variable.class.php @@ -88,7 +88,7 @@ class PriceGlobalVariable $this->checkParameters(); // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "code, description, value"; $sql .= ") VALUES ("; $sql .= " ".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "''").","; @@ -105,7 +105,7 @@ class PriceGlobalVariable } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -142,7 +142,7 @@ class PriceGlobalVariable public function fetch($id) { $sql = "SELECT code, description, value"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(__METHOD__); @@ -179,7 +179,7 @@ class PriceGlobalVariable $this->checkParameters(); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " code = ".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "''").","; $sql .= " description = ".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "''").","; $sql .= " value = ".((float) $this->value); @@ -249,7 +249,7 @@ class PriceGlobalVariable } if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(__METHOD__); @@ -316,7 +316,7 @@ class PriceGlobalVariable public function listGlobalVariables() { $sql = "SELECT rowid, code, description, value"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " ORDER BY code"; dol_syslog(__METHOD__, LOG_DEBUG); diff --git a/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php b/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php index 8a9c1197a7f..317bc7fb5fd 100644 --- a/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php +++ b/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php @@ -100,7 +100,7 @@ class PriceGlobalVariableUpdater $this->checkParameters(); // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "type, description, parameters, fk_variable, update_interval, next_update, last_status"; $sql .= ") VALUES ("; $sql .= " ".((int) $this->type).","; @@ -121,7 +121,7 @@ class PriceGlobalVariableUpdater } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -158,7 +158,7 @@ class PriceGlobalVariableUpdater public function fetch($id) { $sql = "SELECT type, description, parameters, fk_variable, update_interval, next_update, last_status"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(__METHOD__); @@ -199,7 +199,7 @@ class PriceGlobalVariableUpdater $this->checkParameters(); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " type = ".((int) $this->type).","; $sql .= " description = ".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "''").","; $sql .= " parameters = ".(isset($this->parameters) ? "'".$this->db->escape($this->parameters)."'" : "''").","; @@ -274,7 +274,7 @@ class PriceGlobalVariableUpdater //} if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(__METHOD__); @@ -372,7 +372,7 @@ class PriceGlobalVariableUpdater public function listUpdaters() { $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); @@ -409,7 +409,7 @@ class PriceGlobalVariableUpdater public function listPendingUpdaters() { $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE next_update < ".dol_now(); dol_syslog(__METHOD__, LOG_DEBUG); @@ -568,7 +568,7 @@ class PriceGlobalVariableUpdater $this->checkParameters(); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " next_update = ".$this->next_update; $sql .= " WHERE rowid = ".((int) $this->id); @@ -612,7 +612,7 @@ class PriceGlobalVariableUpdater $this->checkParameters(); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " last_status = ".(isset($this->last_status) ? "'".$this->db->escape($this->last_status)."'" : "''"); $sql .= " WHERE rowid = ".((int) $this->id); From 7ff2678ef08aaa14e756a8edab725fefdef5ba3b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 27 Jan 2022 10:16:02 +0100 Subject: [PATCH 039/132] FIX convert inventory class --- htdocs/product/inventory/class/inventory.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index bb55bc1b143..f0157e52009 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -266,7 +266,7 @@ class Inventory extends CommonObject if ($this->status == self::STATUS_DRAFT) { // Delete inventory - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'inventorydet WHERE fk_inventory = '.((int) $this->id); + $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -277,9 +277,9 @@ class Inventory extends CommonObject // Scan existing stock to prefill the inventory $sql = 'SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,'; $sql .= ' pb.batch, pb.qty'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'product_stock as ps'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb ON pb.fk_product_stock = ps.rowid,'; - $sql .= ' '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'entrepot as e'; + $sql .= ' FROM '.$this->db->prefix().'product_stock as ps'; + $sql .= ' LEFT JOIN '.$this->db->prefix().'product_batch as pb ON pb.fk_product_stock = ps.rowid,'; + $sql .= ' '.$this->db->prefix().'product as p, '.$this->db->prefix().'entrepot as e'; $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; $sql .= ' AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid'; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { @@ -349,7 +349,7 @@ class Inventory extends CommonObject $this->db->begin(); // Delete inventory - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'inventorydet WHERE fk_inventory = '.((int) $this->id); + $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -642,7 +642,7 @@ class Inventory extends CommonObject { $sql = 'SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,'; $sql .= ' fk_user_creat, fk_user_modif, fk_user_valid'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE t.rowid = '.((int) $id); $result = $this->db->query($sql); if ($result) { From 07a47629d1a415be7c351a1f507bb41d7b085042 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 27 Jan 2022 10:17:11 +0100 Subject: [PATCH 040/132] FIX convert stock class --- .../stock/class/api_stockmovements.class.php | 2 +- .../stock/class/api_warehouses.class.php | 4 +-- htdocs/product/stock/class/entrepot.class.php | 32 +++++++++---------- .../stock/class/mouvementstock.class.php | 32 +++++++++---------- .../product/stock/class/productlot.class.php | 10 +++--- .../class/productstockentrepot.class.php | 12 +++---- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index 8291e910917..47e6c170a31 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -104,7 +104,7 @@ class StockMovements extends DolibarrApi } $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as t"; + $sql .= " FROM ".$this->db->prefix()."stock_mouvement as t"; //$sql.= ' WHERE t.entity IN ('.getEntity('stock').')'; $sql .= ' WHERE 1 = 1'; // Add sql filters diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php index 3a128a12680..0cf0e57fe3a 100644 --- a/htdocs/product/stock/class/api_warehouses.class.php +++ b/htdocs/product/stock/class/api_warehouses.class.php @@ -104,9 +104,9 @@ class Warehouses extends DolibarrApi } $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as t"; + $sql .= " FROM ".$this->db->prefix()."entrepot as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + $sql .= ", ".$this->db->prefix()."categorie_societe as c"; } $sql .= ' WHERE t.entity IN ('.getEntity('stock').')'; // Select warehouses of given category diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 617550c09dd..47d63b06568 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -204,13 +204,13 @@ class Entrepot extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)"; + $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)"; $sql .= " VALUES ('".$this->db->escape($this->label)."', ".((int) $conf->entity).", '".$this->db->idate($now)."', ".((int) $user->id).", ".($this->fk_parent > 0 ? ((int) $this->fk_parent) : "NULL").", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "NULL").")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."entrepot"); + $id = $this->db->last_insert_id($this->db->prefix()."entrepot"); if ($id > 0) { $this->id = $id; @@ -293,7 +293,7 @@ class Entrepot extends CommonObject $this->town = trim($this->town); $this->country_id = ($this->country_id > 0 ? $this->country_id : 0); - $sql = "UPDATE ".MAIN_DB_PREFIX."entrepot"; + $sql = "UPDATE ".$this->db->prefix()."entrepot"; $sql .= " SET ref = '".$this->db->escape($this->label)."'"; $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL"); $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL"); @@ -365,7 +365,7 @@ class Entrepot extends CommonObject $elements = array('stock_mouvement', 'product_stock', 'product_warehouse_properties'); foreach ($elements as $table) { if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; + $sql = "DELETE FROM ".$this->db->prefix().$table; $sql .= " WHERE fk_entrepot = ".((int) $this->id); $result = $this->db->query($sql); @@ -388,7 +388,7 @@ class Entrepot extends CommonObject } if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot"; + $sql = "DELETE FROM ".$this->db->prefix()."entrepot"; $sql .= " WHERE rowid = ".((int) $this->id); $resql1 = $this->db->query($sql); if (!$resql1) { @@ -400,7 +400,7 @@ class Entrepot extends CommonObject if (!$error) { // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql - $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)"; + $sql = "UPDATE ".$this->db->prefix()."product as p SET stock = (SELECT SUM(ps.reel) FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_product = p.rowid)"; $resql2 = $this->db->query($sql); if (!$resql2) { $error++; @@ -441,7 +441,7 @@ class Entrepot extends CommonObject $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,"; $sql .= " model_pdf, import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; + $sql .= " FROM ".$this->db->prefix()."entrepot"; if ($id) { $sql .= " WHERE rowid = ".((int) $id); } else { @@ -506,7 +506,7 @@ class Entrepot extends CommonObject public function info($id) { $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e"; + $sql .= " FROM ".$this->db->prefix()."entrepot as e"; $sql .= " WHERE e.rowid = ".((int) $id); dol_syslog(get_class($this)."::info", LOG_DEBUG); @@ -553,7 +553,7 @@ class Entrepot extends CommonObject $liste = array(); $sql = "SELECT rowid, ref as label"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; + $sql .= " FROM ".$this->db->prefix()."entrepot"; $sql .= " WHERE entity IN (".getEntity('stock').")"; $sql .= " AND statut = ".((int) $status); @@ -583,8 +583,8 @@ class Entrepot extends CommonObject $ret = array(); $sql = "SELECT count(distinct p.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product_stock as ps"; + $sql .= ", ".$this->db->prefix()."product as p"; $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id); $sql .= " AND ps.fk_product = p.rowid"; @@ -625,10 +625,10 @@ class Entrepot extends CommonObject } else { $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product_stock as ps"; + $sql .= ", ".$this->db->prefix()."product as p"; if ($separatedPMP) { - $sql .= ", ".MAIN_DB_PREFIX."product_perentity as pa"; + $sql .= ", ".$this->db->prefix()."product_perentity as pa"; } $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id); if ($separatedPMP) { @@ -819,7 +819,7 @@ class Entrepot extends CommonObject $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents $i = 0; while ($parentid > 0 && $i < $protection) { - $sql = "SELECT fk_parent FROM ".MAIN_DB_PREFIX."entrepot WHERE rowid = ".((int) $parentid); + $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot WHERE rowid = ".((int) $parentid); $resql = $this->db->query($sql); if ($resql) { $objarbo = $this->db->fetch_object($resql); @@ -853,7 +853,7 @@ class Entrepot extends CommonObject // phpcs:enable $sql = 'SELECT rowid - FROM '.MAIN_DB_PREFIX.'entrepot + FROM '.$this->db->prefix().'entrepot WHERE fk_parent = '.((int) $id); $resql = $this->db->query($sql); diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index a6bc6c2ec26..e79021e5534 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -287,7 +287,7 @@ class MouvementStock extends CommonObject // If found and eatby/sellby not defined into table and provided, we update table // If found and eatby/sellby not defined into table and not provided, we do nothing // If not found, we add record - $sql = "SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".MAIN_DB_PREFIX."product_lot as pb"; + $sql = "SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix()."product_lot as pb"; $sql .= " WHERE pb.fk_product = ".((int) $fk_product)." AND pb.batch = '".$this->db->escape($batch)."'"; dol_syslog(get_class($this)."::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG); $resql = $this->db->query($sql); @@ -435,7 +435,7 @@ class MouvementStock extends CommonObject $origin_id = 0; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement("; + $sql = "INSERT INTO ".$this->db->prefix()."stock_mouvement("; $sql .= " datem, fk_product, batch, eatby, sellby,"; $sql .= " fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet"; $sql .= ")"; @@ -457,7 +457,7 @@ class MouvementStock extends CommonObject $resql = $this->db->query($sql); if ($resql) { - $mvid = $this->db->last_insert_id(MAIN_DB_PREFIX."stock_mouvement"); + $mvid = $this->db->last_insert_id($this->db->prefix()."stock_mouvement"); $this->id = $mvid; } else { $this->error = $this->db->lasterror(); @@ -473,7 +473,7 @@ class MouvementStock extends CommonObject // Test if there is already a record for couple (warehouse / product), so later we will make an update or create. $alreadyarecord = 0; if (!$error) { - $sql = "SELECT rowid, reel FROM ".MAIN_DB_PREFIX."product_stock"; + $sql = "SELECT rowid, reel FROM ".$this->db->prefix()."product_stock"; $sql .= " WHERE fk_entrepot = ".((int) $entrepot_id)." AND fk_product = ".((int) $fk_product); // This is a unique key dol_syslog(get_class($this)."::_create check if a record already exists in product_stock", LOG_DEBUG); @@ -524,10 +524,10 @@ class MouvementStock extends CommonObject // Update stock quantity if (!$error) { if ($alreadyarecord > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + ".((float) $qty); + $sql = "UPDATE ".$this->db->prefix()."product_stock SET reel = reel + ".((float) $qty); $sql .= " WHERE fk_entrepot = ".((int) $entrepot_id)." AND fk_product = ".((int) $fk_product); } else { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock"; + $sql = "INSERT INTO ".$this->db->prefix()."product_stock"; $sql .= " (reel, fk_entrepot, fk_product) VALUES "; $sql .= " (".((float) $qty).", ".((int) $entrepot_id).", ".((int) $fk_product).")"; } @@ -538,7 +538,7 @@ class MouvementStock extends CommonObject $this->errors[] = $this->db->lasterror(); $error = -3; } elseif (empty($fk_product_stock)) { - $fk_product_stock = $this->db->last_insert_id(MAIN_DB_PREFIX."product_stock"); + $fk_product_stock = $this->db->last_insert_id($this->db->prefix()."product_stock"); } } @@ -559,11 +559,11 @@ class MouvementStock extends CommonObject if (!$error) { $newpmp = price2num($newpmp, 'MU'); - // $sql = "UPDATE ".MAIN_DB_PREFIX."product SET pmp = ".$newpmp.", stock = ".$this->db->ifsql("stock IS NULL", 0, "stock") . " + ".$qty; + // $sql = "UPDATE ".$this->db->prefix()."product SET pmp = ".$newpmp.", stock = ".$this->db->ifsql("stock IS NULL", 0, "stock") . " + ".$qty; // $sql.= " WHERE rowid = ".((int) $fk_product); // Update pmp + denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql - $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET pmp = ".((float) $newpmp).","; - $sql .= " stock=(SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)"; + $sql = "UPDATE ".$this->db->prefix()."product as p SET pmp = ".((float) $newpmp).","; + $sql .= " stock=(SELECT SUM(ps.reel) FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_product = p.rowid)"; $sql .= " WHERE rowid = ".((int) $fk_product); dol_syslog(get_class($this)."::_create update AWP", LOG_DEBUG); @@ -576,7 +576,7 @@ class MouvementStock extends CommonObject // If stock is now 0, we can remove entry into llx_product_stock, but only if there is no child lines into llx_product_batch (detail of batch, because we can imagine // having a lot1/qty=X and lot2/qty=-X, so 0 but we must not loose repartition of different lot. - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".MAIN_DB_PREFIX."product_batch as pb)"; + $sql = "DELETE FROM ".$this->db->prefix()."product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".$this->db->prefix()."product_batch as pb)"; $resql = $this->db->query($sql); // We do not test error, it can fails if there is child in batch details } @@ -644,7 +644,7 @@ class MouvementStock extends CommonObject $sql .= " t.eatby,"; $sql .= " t.sellby,"; $sql .= " t.fk_projet as fk_project"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE t.rowid = '.((int) $id); $resql = $this->db->query($sql); @@ -721,7 +721,7 @@ class MouvementStock extends CommonObject $pqtys = array(); $sql = "SELECT fk_product_pere, fk_product_fils, qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_association"; + $sql .= " FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $idProduct); $sql .= " AND incdec = 1"; @@ -824,7 +824,7 @@ class MouvementStock extends CommonObject { $nb = 0; - $sql = 'SELECT SUM(value) as nb from '.MAIN_DB_PREFIX.'stock_mouvement'; + $sql = 'SELECT SUM(value) as nb from '.$this->db->prefix().'stock_mouvement'; $sql .= ' WHERE fk_product = '.((int) $productidselected); $sql .= " AND datem < '".$this->db->idate($datebefore)."'"; @@ -1203,8 +1203,8 @@ class MouvementStock extends CommonObject $cpt = 0; $sql = "SELECT sum(pb.qty) as cpt"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."product_stock as ps ON ps.rowid = pb.fk_product_stock"; + $sql .= " FROM ".$this->db->prefix()."product_batch as pb"; + $sql .= " INNER JOIN ".$this->db->prefix()."product_stock as ps ON ps.rowid = pb.fk_product_stock"; $sql .= " WHERE ps.fk_product = " . ((int) $fk_product); $sql .= " AND pb.batch = '" . $this->db->escape($batch) . "'"; diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 360978ac736..9a9106a341b 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -188,7 +188,7 @@ class Productlot extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; $sql .= 'entity,'; $sql .= 'fk_product,'; $sql .= 'batch,'; @@ -230,7 +230,7 @@ class Productlot extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); // Actions on extra fields if (!$error) { @@ -296,7 +296,7 @@ class Productlot extends CommonObject $sql .= " t.fk_user_creat,"; $sql .= " t.fk_user_modif,"; $sql .= " t.import_key"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; if ($product_id > 0 && $batch != '') { $sql .= " WHERE t.batch = '".$this->db->escape($batch)."' AND t.fk_product = ".((int) $product_id); } else { @@ -394,7 +394,7 @@ class Productlot extends CommonObject } // Update request - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET'; $sql .= ' entity = '.(isset($this->entity) ? $this->entity : "null").','; $sql .= ' fk_product = '.(isset($this->fk_product) ? $this->fk_product : "null").','; $sql .= ' batch = '.(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").','; @@ -479,7 +479,7 @@ class Productlot extends CommonObject //} if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element; $sql .= ' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); diff --git a/htdocs/product/stock/class/productstockentrepot.class.php b/htdocs/product/stock/class/productstockentrepot.class.php index 9b32fe1fe5e..105e38c5136 100644 --- a/htdocs/product/stock/class/productstockentrepot.class.php +++ b/htdocs/product/stock/class/productstockentrepot.class.php @@ -113,7 +113,7 @@ class ProductStockEntrepot extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; $sql .= 'fk_product,'; $sql .= 'fk_entrepot,'; @@ -143,7 +143,7 @@ class ProductStockEntrepot extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); //if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -192,7 +192,7 @@ class ProductStockEntrepot extends CommonObject $sql .= " t.seuil_stock_alerte,"; $sql .= " t.desiredstock,"; $sql .= " t.import_key"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; if (!empty($id)) { $sql .= ' WHERE t.rowid = '.((int) $id); } else { @@ -265,7 +265,7 @@ class ProductStockEntrepot extends CommonObject $sql .= " t.import_key"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE 1=1'; @@ -355,7 +355,7 @@ class ProductStockEntrepot extends CommonObject // Put here code to add a control on parameters values // Update request - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET'; $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'").','; $sql .= ' fk_product = '.(isset($this->fk_product) ? $this->fk_product : "null").','; @@ -425,7 +425,7 @@ class ProductStockEntrepot extends CommonObject //} if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element; $sql .= ' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); From 399fffa81ed123db0c621a5f5f7c6e781b096994 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 27 Jan 2022 10:19:35 +0100 Subject: [PATCH 041/132] FIX convert core class --- htdocs/core/class/ccountry.class.php | 10 +- htdocs/core/class/comment.class.php | 12 +- .../core/class/commondocgenerator.class.php | 2 +- htdocs/core/class/commonincoterm.class.php | 8 +- htdocs/core/class/commoninvoice.class.php | 22 +- htdocs/core/class/commonobject.class.php | 232 +++++++++--------- htdocs/core/class/commonobjectline.class.php | 2 +- htdocs/core/class/coreobject.class.php | 2 +- htdocs/core/class/cproductnature.class.php | 12 +- htdocs/core/class/cstate.class.php | 10 +- htdocs/core/class/ctypent.class.php | 10 +- htdocs/core/class/ctyperesource.class.php | 12 +- htdocs/core/class/cunits.class.php | 14 +- htdocs/core/class/defaultvalues.class.php | 2 +- htdocs/core/class/discount.class.php | 38 +-- htdocs/core/class/dolreceiptprinter.class.php | 26 +- .../core/class/emailsenderprofile.class.php | 2 +- htdocs/core/class/events.class.php | 10 +- htdocs/core/class/extrafields.class.php | 38 +-- htdocs/core/class/fiscalyear.class.php | 16 +- htdocs/core/class/html.form.class.php | 150 +++++------ .../core/class/html.formaccounting.class.php | 20 +- htdocs/core/class/html.formadmin.class.php | 2 +- htdocs/core/class/html.formbarcode.class.php | 2 +- htdocs/core/class/html.formcompany.class.php | 20 +- htdocs/core/class/html.formcontract.class.php | 2 +- .../class/html.formexpensereport.class.php | 2 +- .../class/html.formintervention.class.php | 2 +- htdocs/core/class/html.formmail.class.php | 8 +- htdocs/core/class/html.formorder.class.php | 2 +- htdocs/core/class/html.formother.class.php | 18 +- htdocs/core/class/html.formprojet.class.php | 14 +- htdocs/core/class/html.formpropal.class.php | 2 +- .../class/html.formsocialcontrib.class.php | 4 +- htdocs/core/class/html.formticket.class.php | 10 +- htdocs/core/class/html.formwebsite.class.php | 4 +- htdocs/core/class/infobox.class.php | 8 +- htdocs/core/class/link.class.php | 14 +- htdocs/core/class/menubase.class.php | 18 +- htdocs/core/class/notify.class.php | 34 +-- htdocs/core/class/translate.class.php | 6 +- htdocs/core/class/validate.class.php | 4 +- 42 files changed, 413 insertions(+), 413 deletions(-) diff --git a/htdocs/core/class/ccountry.class.php b/htdocs/core/class/ccountry.class.php index 4f448845e80..7b46b0a08b0 100644 --- a/htdocs/core/class/ccountry.class.php +++ b/htdocs/core/class/ccountry.class.php @@ -111,7 +111,7 @@ class Ccountry // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country("; + $sql = "INSERT INTO ".$this->db->prefix()."c_country("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "code_iso,"; @@ -135,7 +135,7 @@ class Ccountry // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_country"); } // Commit or rollback @@ -169,7 +169,7 @@ class Ccountry // extends CommonObject $sql .= " t.code_iso,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_country as t"; + $sql .= " FROM ".$this->db->prefix()."c_country as t"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); } elseif ($code) { @@ -235,7 +235,7 @@ class Ccountry // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET"; + $sql = "UPDATE ".$this->db->prefix()."c_country SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " code_iso=".(isset($this->code_iso) ? "'".$this->db->escape($this->code_iso)."'" : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; @@ -278,7 +278,7 @@ class Ccountry // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country"; + $sql = "DELETE FROM ".$this->db->prefix()."c_country"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); diff --git a/htdocs/core/class/comment.class.php b/htdocs/core/class/comment.class.php index c2dd055522e..937ca6f7875 100644 --- a/htdocs/core/class/comment.class.php +++ b/htdocs/core/class/comment.class.php @@ -113,7 +113,7 @@ class Comment extends CommonObject $error = 0; // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "description"; $sql .= ", datec"; $sql .= ", fk_element"; @@ -146,7 +146,7 @@ class Comment extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); if (!$notrigger) { // Call trigger @@ -195,7 +195,7 @@ class Comment extends CommonObject $sql .= " c.fk_user_modif,"; $sql .= " c.entity,"; $sql .= " c.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -254,7 +254,7 @@ class Comment extends CommonObject // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").","; $sql .= " datec=".($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql .= " fk_element=".(isset($this->fk_element) ? $this->fk_element : "null").","; @@ -315,7 +315,7 @@ class Comment extends CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid=".((int) $this->id); $resql = $this->db->query($sql); @@ -364,7 +364,7 @@ class Comment extends CommonObject if (!empty($element_type) && !empty($fk_element)) { $sql = "SELECT"; $sql .= " c.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.fk_element = ".((int) $fk_element); $sql .= " AND c.element_type = '".$this->db->escape($element_type)."'"; $sql .= " AND c.entity = ".$conf->entity; diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 5d0242657ef..8a0ce49ce00 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -653,7 +653,7 @@ abstract class CommonDocGenerator if ($columns != "") { $columns = substr($columns, 0, strlen($columns) - 2); - $resql = $this->db->query("SELECT ".$columns." FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields AS ex INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '".$this->db->escape($line->ref_supplier)."'"); + $resql = $this->db->query("SELECT ".$columns." FROM ".$this->db->prefix()."product_fournisseur_price_extrafields AS ex INNER JOIN ".$this->db->prefix()."product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '".$this->db->escape($line->ref_supplier)."'"); if ($this->db->num_rows($resql) > 0) { $resql = $this->db->fetch_object($resql); diff --git a/htdocs/core/class/commonincoterm.class.php b/htdocs/core/class/commonincoterm.class.php index d0485acc5a9..e74d1428781 100644 --- a/htdocs/core/class/commonincoterm.class.php +++ b/htdocs/core/class/commonincoterm.class.php @@ -60,7 +60,7 @@ trait CommonIncoterm $this->label_incoterms = ''; if (!empty($this->fk_incoterms)) { - $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $result = $this->db->query($sql); if ($result) { $res = $this->db->fetch_object($result); @@ -80,7 +80,7 @@ trait CommonIncoterm */ public function getIncotermsForPDF() { - $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -106,7 +106,7 @@ trait CommonIncoterm public function setIncoterms($id_incoterm, $location) { if ($this->id && $this->table_element) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? ((int) $id_incoterm) : "null"); $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); $sql .= " WHERE rowid = ".((int) $this->id); @@ -116,7 +116,7 @@ trait CommonIncoterm $this->fk_incoterms = $id_incoterm; $this->location_incoterms = $location; - $sql = "SELECT libelle as label_incoterms FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT libelle as label_incoterms FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $res = $this->db->query($sql); if ($res) { $obj = $this->db->fetch_object($res); diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 74ff2141820..b6690a2cba2 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -131,7 +131,7 @@ abstract class CommonInvoice extends CommonObject } $sql = 'SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$table; + $sql .= ' FROM '.$this->db->prefix().$table; $sql .= " WHERE ".$field." = ".((int) $this->id); dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); @@ -227,7 +227,7 @@ abstract class CommonInvoice extends CommonObject $idarray = array(); $sql = 'SELECT rowid'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE fk_facture_source = ".((int) $this->id); $sql .= ' AND type = 2'; $resql = $this->db->query($sql); @@ -254,7 +254,7 @@ abstract class CommonInvoice extends CommonObject public function getIdReplacingInvoice($option = '') { $sql = 'SELECT rowid'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE fk_facture_source = ".((int) $this->id); $sql .= ' AND type < 2'; if ($option == 'validated') { @@ -308,7 +308,7 @@ abstract class CommonInvoice extends CommonObject } $sql = "SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code".$field3; - $sql .= " FROM ".MAIN_DB_PREFIX.$table." as pf, ".MAIN_DB_PREFIX.$table2." as p, ".MAIN_DB_PREFIX."c_paiement as t"; + $sql .= " FROM ".$this->db->prefix().$table." as pf, ".$this->db->prefix().$table2." as p, ".$this->db->prefix()."c_paiement as t"; $sql .= " WHERE pf.".$field." = ".((int) $this->id); $sql .= " AND pf.".$field2." = p.rowid"; $sql .= ' AND p.fk_paiement = t.id'; @@ -337,12 +337,12 @@ abstract class CommonInvoice extends CommonObject $sql = ''; if ($this->element == 'facture' || $this->element == 'invoice') { $sql = "SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture as f'; $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $this->id); $sql .= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or deposits (payments from deposits are always null except if FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is set) } elseif ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { $sql = "SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture_fourn as f'; $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $this->id); $sql .= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or deposits (payments from deposits are always null except if FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is set) } @@ -462,7 +462,7 @@ abstract class CommonInvoice extends CommonObject $type = 'supplier_invoice'; } - $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->id); + $sql = " SELECT COUNT(ab.rowid) as nb FROM ".$this->db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->id); $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); @@ -602,7 +602,7 @@ abstract class CommonInvoice extends CommonObject $cdr_decalage = 0; $sqltemp = 'SELECT c.type_cdr, c.nbjour, c.decalage'; - $sqltemp .= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c'; + $sqltemp .= ' FROM '.$this->db->prefix().'c_payment_term as c'; if (is_numeric($cond_reglement)) { $sqltemp .= " WHERE c.rowid=".((int) $cond_reglement); } else { @@ -698,7 +698,7 @@ abstract class CommonInvoice extends CommonObject $bac->fetch(0, $this->socid); $sql = 'SELECT count(*)'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; + $sql .= ' FROM '.$this->db->prefix().'prelevement_facture_demande'; if ($type == 'bank-transfer') { $sql .= ' WHERE fk_facture_fourn = '.((int) $this->id); } else { @@ -728,7 +728,7 @@ abstract class CommonInvoice extends CommonObject } if (is_numeric($amount) && $amount != 0) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande('; + $sql = 'INSERT INTO '.$this->db->prefix().'prelevement_facture_demande('; if ($type == 'bank-transfer') { $sql .= 'fk_facture_fourn, '; } else { @@ -800,7 +800,7 @@ abstract class CommonInvoice extends CommonObject public function demande_prelevement_delete($fuser, $did) { // phpcs:enable - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; + $sql = 'DELETE FROM '.$this->db->prefix().'prelevement_facture_demande'; $sql .= ' WHERE rowid = '.((int) $did); $sql .= ' AND traite = 0'; if ($this->db->query($sql)) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 58844439fc3..d2e1227ba75 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -536,7 +536,7 @@ abstract class CommonObject global $db, $conf; $sql = "SELECT rowid, ref, ref_ext"; - $sql .= " FROM ".MAIN_DB_PREFIX.$element; + $sql .= " FROM ".$this->db->prefix().$element; $sql .= " WHERE entity IN (".getEntity($element).")"; if ($id > 0) { @@ -1041,7 +1041,7 @@ abstract class CommonObject } else { // We look for id type_contact $sql = "SELECT tc.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; $sql .= " AND tc.source='".$this->db->escape($source)."'"; $sql .= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; @@ -1079,7 +1079,7 @@ abstract class CommonObject $this->db->begin(); // Insert into database - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; + $sql = "INSERT INTO ".$this->db->prefix()."element_contact"; $sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; $sql .= " VALUES (".$this->id.", ".((int) $fk_socpeople)." , "; $sql .= "'".$this->db->idate($datecreate)."'"; @@ -1148,7 +1148,7 @@ abstract class CommonObject { // phpcs:enable // Insert into database - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; + $sql = "UPDATE ".$this->db->prefix()."element_contact set"; $sql .= " statut = ".$statut; if ($type_contact_id) { $sql .= ", fk_c_type_contact = ".((int) $type_contact_id); @@ -1182,7 +1182,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; + $sql = "DELETE FROM ".$this->db->prefix()."element_contact"; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); @@ -1226,7 +1226,7 @@ abstract class CommonObject $listId = implode(",", $temp); } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; + $sql = "DELETE FROM ".$this->db->prefix()."element_contact"; $sql .= " WHERE element_id = ".((int) $this->id); if (!empty($listId)) { $sql .= " AND fk_c_type_contact IN (".$this->db->sanitize($listId).")"; @@ -1267,13 +1267,13 @@ abstract class CommonObject } $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql .= ", ".MAIN_DB_PREFIX."element_contact ec"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact tc"; + $sql .= ", ".$this->db->prefix()."element_contact ec"; if ($source == 'internal') { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."user t on ec.fk_socpeople = t.rowid"; } if ($source == 'external' || $source == 'thirdparty') { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."socpeople t on ec.fk_socpeople = t.rowid"; } $sql .= " WHERE ec.element_id = ".((int) $this->id); $sql .= " AND ec.fk_c_type_contact = tc.rowid"; @@ -1348,7 +1348,7 @@ abstract class CommonObject { $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; $sql .= " tc.code, tc.libelle"; - $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; + $sql .= " FROM (".$this->db->prefix()."element_contact as ec, ".$this->db->prefix()."c_type_contact as tc)"; $sql .= " WHERE ec.rowid =".((int) $rowid); $sql .= " AND ec.fk_c_type_contact=tc.rowid"; $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; @@ -1393,7 +1393,7 @@ abstract class CommonObject $tab = array(); $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; if ($activeonly == 1) { $sql .= " AND tc.active=1"; // only the active types @@ -1453,7 +1453,7 @@ abstract class CommonObject $tab = array(); $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sqlWhere = array(); if (!empty($element)) { @@ -1551,14 +1551,14 @@ abstract class CommonObject } $sql = "SELECT ec.fk_socpeople"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; + $sql .= " FROM ".$this->db->prefix()."element_contact as ec,"; if ($source == 'internal') { - $sql .= " ".MAIN_DB_PREFIX."user as c,"; + $sql .= " ".$this->db->prefix()."user as c,"; } if ($source == 'external') { - $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; + $sql .= " ".$this->db->prefix()."socpeople as c,"; } - $sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE ec.element_id = ".((int) $id); $sql .= " AND ec.fk_socpeople = c.rowid"; if ($source == 'internal') { @@ -1674,7 +1674,7 @@ abstract class CommonObject return 0; } - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element." WHERE ".$this->table_ref_field." LIKE '".$this->db->escape($ref)."' LIMIT 1"; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element." WHERE ".$this->table_ref_field." LIKE '".$this->db->escape($ref)."' LIMIT 1"; $query = $this->db->query($sql); @@ -1716,7 +1716,7 @@ abstract class CommonObject if ($idtype > 0) { if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) { // If data not already loaded $sql = "SELECT rowid, code, libelle as label, coder"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; + $sql .= " FROM ".$this->db->prefix()."c_barcode_type"; $sql .= " WHERE rowid = ".((int) $idtype); dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); $resql = $this->db->query($sql); @@ -1853,7 +1853,7 @@ abstract class CommonObject $result = false; - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; + $sql = "SELECT rowid FROM ".$this->db->prefix().$table; $sql .= " WHERE ".$field." = '".$this->db->escape($key)."'"; if (!empty($element)) { $sql .= " AND entity IN (".getEntity($element).")"; @@ -1886,7 +1886,7 @@ abstract class CommonObject { $result = false; if (!empty($id) && !empty($field) && !empty($table)) { - $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; + $sql = "SELECT ".$field." FROM ".$this->db->prefix().$table; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); @@ -1944,7 +1944,7 @@ abstract class CommonObject $fk_user_field = 'fk_user_mod'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; + $sql = "UPDATE ".$this->db->prefix().$table." SET "; if ($format == 'text') { $sql .= $field." = '".$this->db->escape($value)."'"; @@ -2044,20 +2044,20 @@ abstract class CommonObject } $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc; $sql = "SELECT MAX(te.".$fieldid.")"; - $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; + $sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te"; if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= ",".$this->db->prefix()."usergroup_user as ug"; } if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) { $tmparray = explode('@', $this->ismultientitymanaged); - $sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity + $sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity } elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid + $sql .= ", ".$this->db->prefix()."societe as s"; // If we need to link to societe to limit select to socid } elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid } if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; } $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) { @@ -2114,20 +2114,20 @@ abstract class CommonObject $this->ref_previous = $row[0]; $sql = "SELECT MIN(te.".$fieldid.")"; - $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; + $sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te"; if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= ",".$this->db->prefix()."usergroup_user as ug"; } if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) { $tmparray = explode('@', $this->ismultientitymanaged); - $sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity + $sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity } elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid + $sql .= ", ".$this->db->prefix()."societe as s"; // If we need to link to societe to limit select to socid } elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid } if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; } $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) { @@ -2226,7 +2226,7 @@ abstract class CommonObject return -1; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; if (!empty($this->fields['fk_project'])) { // Common case if ($projectid) { $sql .= " SET fk_project = ".((int) $projectid); @@ -2291,7 +2291,7 @@ abstract class CommonObject $fieldname = 'fk_typepayment'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2335,7 +2335,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'multicurrency_code'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = '".$this->db->escape($code)."'"; $sql .= ' WHERE rowid='.((int) $this->id); @@ -2373,7 +2373,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'multicurrency_tx'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".((float) $rate); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2581,7 +2581,7 @@ abstract class CommonObject $fieldname = 'cond_reglement_supplier'; } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2623,7 +2623,7 @@ abstract class CommonObject $fieldname = 'transport_mode_supplier'; } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2658,7 +2658,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'retained_warranty_fk_cond_reglement'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".((int) $id); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2691,7 +2691,7 @@ abstract class CommonObject $fieldname = 'fk_address'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".((int) $id); + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET ".$fieldname." = ".((int) $id); $sql .= " WHERE rowid = ".((int) $this->id)." AND fk_statut = 0"; if ($this->db->query($sql)) { @@ -2736,7 +2736,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_shipping_method = ".((int) $shipping_method_id); $sql .= " WHERE rowid=".((int) $this->id); $resql = $this->db->query($sql); @@ -2783,7 +2783,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_warehouse = ".((int) $warehouse_id); $sql .= " WHERE rowid=".((int) $this->id); @@ -2814,7 +2814,7 @@ abstract class CommonObject $newmodelpdf = dol_trunc($modelpdf, 255); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; $sql .= " WHERE rowid = ".((int) $this->id); @@ -2860,7 +2860,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_account = ".((int) $fk_account); $sql .= " WHERE rowid=".((int) $this->id); @@ -2917,7 +2917,7 @@ abstract class CommonObject // Count number of lines to reorder (according to choice $renum) $nl = 0; - $sql = "SELECT count(rowid) FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if (!$renum) { $sql .= ' AND rang = 0'; @@ -2939,7 +2939,7 @@ abstract class CommonObject $rows = array(); // We first search all lines that are parent lines (for multilevel details lines) - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if ($fk_parent_line) { $sql .= ' AND fk_parent_line IS NULL'; @@ -2987,7 +2987,7 @@ abstract class CommonObject { $rows = array(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND fk_parent_line = '.((int) $id); $sql .= ' ORDER BY rang ASC'; @@ -3065,7 +3065,7 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= ' WHERE rowid = '.((int) $rowid); dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); @@ -3111,11 +3111,11 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND rang = '.((int) ($rang - 1)); if ($this->db->query($sql)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang - 1)); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang - 1)); $sql .= ' WHERE rowid = '.((int) $rowid); if (!$this->db->query($sql)) { dol_print_error($this->db); @@ -3142,11 +3142,11 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND rang = '.((int) ($rang + 1)); if ($this->db->query($sql)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang + 1)); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang + 1)); $sql .= ' WHERE rowid = '.((int) $rowid); if (!$this->db->query($sql)) { dol_print_error($this->db); @@ -3165,7 +3165,7 @@ abstract class CommonObject */ public function getRangOfLine($rowid) { - $sql = "SELECT rang FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rang FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); @@ -3184,7 +3184,7 @@ abstract class CommonObject */ public function getIdOfLine($rang) { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= " AND rang = ".((int) $rang); $resql = $this->db->query($sql); @@ -3211,7 +3211,7 @@ abstract class CommonObject // Search the last rang with fk_parent_line if ($fk_parent_line) { - $sql = "SELECT max(".$positionfield.") FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT max(".$positionfield.") FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= " AND fk_parent_line = ".((int) $fk_parent_line); @@ -3227,7 +3227,7 @@ abstract class CommonObject } } else { // If not, search the last rang of element - $sql = "SELECT max(".$positionfield.") FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT max(".$positionfield.") FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); dol_syslog(get_class($this)."::line_max", LOG_DEBUG); @@ -3254,7 +3254,7 @@ abstract class CommonObject return -1; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; $sql .= " WHERE ".(isset($this->table_rowid) ? $this->table_rowid : 'rowid')." = ".((int) $this->id); @@ -3305,7 +3305,7 @@ abstract class CommonObject } else { $fieldusermod = "fk_user_modif"; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET note".$newsuffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL"); $sql .= ", ".$fieldusermod." = ".((int) $user->id); $sql .= " WHERE rowid = ".((int) $this->id); @@ -3429,7 +3429,7 @@ abstract class CommonObject $sql .= ', situation_percent'; } $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql .= " FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if ($exclspec) { $product_field = 'product_type'; @@ -3477,7 +3477,7 @@ abstract class CommonObject //var_dump($diff_when_using_price_ht.' '.$diff_on_current_total); if ($diff_when_using_price_ht && $diff_on_current_total) { - $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".price2num((float) $tmpcal[1]).", total_ttc = ".price2num((float) $tmpcal[2])." WHERE rowid = ".((int) $obj->rowid); + $sqlfix = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldtva." = ".price2num((float) $tmpcal[1]).", total_ttc = ".price2num((float) $tmpcal[2])." WHERE rowid = ".((int) $obj->rowid); dol_syslog('We found unconsistent data into detailed line (diff_when_using_price_ht = '.$diff_when_using_price_ht.' and diff_on_current_total = '.$diff_on_current_total.') for line rowid = '.$obj->rowid." (total vat of line calculated=".$tmpcal[1].", database=".$obj->total_tva."). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix, LOG_WARNING); $resqlfix = $this->db->query($sqlfix); if (!$resqlfix) { @@ -3521,7 +3521,7 @@ abstract class CommonObject dol_print_error('', $errmsg); exit; } - $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".price2num($obj->total_tva - $diff).", total_ttc = ".price2num($obj->total_ttc - $diff)." WHERE rowid = ".((int) $obj->rowid); + $sqlfix = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldtva." = ".price2num($obj->total_tva - $diff).", total_ttc = ".price2num($obj->total_ttc - $diff)." WHERE rowid = ".((int) $obj->rowid); dol_syslog('We found a difference of '.$diff.' for line rowid = '.$obj->rowid.". We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix); $resqlfix = $this->db->query($sqlfix); if (!$resqlfix) { @@ -3589,7 +3589,7 @@ abstract class CommonObject } if (empty($nodatabaseupdate)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = "UPDATE ".$this->db->prefix().$this->table_element.' SET'; $sql .= " ".$fieldht." = ".((float) price2num($this->total_ht)).","; $sql .= " ".$fieldtva." = ".((float) price2num($this->total_tva)).","; $sql .= " ".$fieldlocaltax1." = ".((float) price2num($this->total_localtax1)).","; @@ -3670,7 +3670,7 @@ abstract class CommonObject $this->db->begin(); $error = 0; - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_element ("; + $sql = "INSERT INTO " . $this->db->prefix() . "element_element ("; $sql .= "fk_source"; $sql .= ", sourcetype"; $sql .= ", fk_target"; @@ -3778,7 +3778,7 @@ abstract class CommonObject // Links between objects are stored in table element_element $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; + $sql .= ' FROM '.$this->db->prefix().'element_element'; $sql .= " WHERE "; if ($justsource || $justtarget) { if ($justsource) { @@ -3964,7 +3964,7 @@ abstract class CommonObject $this->db->begin(); $error = 0; - $sql = "UPDATE " . MAIN_DB_PREFIX . "element_element SET "; + $sql = "UPDATE " . $this->db->prefix() . "element_element SET "; if ($updatesource) { $sql .= "fk_source = " . ((int) $sourceid); $sql .= ", sourcetype = '" . $this->db->escape($sourcetype) . "'"; @@ -4053,7 +4053,7 @@ abstract class CommonObject } if (!$error) { - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_element"; + $sql = "DELETE FROM " . $this->db->prefix() . "element_element"; $sql .= " WHERE"; if ($rowid > 0) { $sql .= " rowid = " . ((int) $rowid); @@ -4105,7 +4105,7 @@ abstract class CommonObject global $db; - $sql = "SELECT ".$field_select." FROM ".MAIN_DB_PREFIX.$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); + $sql = "SELECT ".$field_select." FROM ".$this->db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); $resql = $db->query($sql); $TRes = array(); @@ -4134,7 +4134,7 @@ abstract class CommonObject global $db; - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); + $sql = "DELETE FROM ".$this->db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); $resql = $db->query($sql); if (empty($resql)) { @@ -4187,7 +4187,7 @@ abstract class CommonObject $fieldstatus = 'status'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; + $sql = "UPDATE ".$this->db->prefix().$elementTable; $sql .= " SET ".$fieldstatus." = ".((int) $status); // If status = 1 = validated, update also fk_user_valid // TODO Replace the test on $elementTable by doing a test on existence of the field in $this->fields @@ -4288,7 +4288,7 @@ abstract class CommonObject $ref = trim($ref); $sql = "SELECT rowid, canvas"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE entity IN (".getEntity($this->element).")"; if (!empty($id)) { $sql .= " AND rowid = ".((int) $id); @@ -4321,7 +4321,7 @@ abstract class CommonObject */ public function getSpecialCode($lineid) { - $sql = "SELECT special_code FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT special_code FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $lineid); $resql = $this->db->query($sql); if ($resql) { @@ -4363,7 +4363,7 @@ abstract class CommonObject foreach ($arraytoscan as $table => $elementname) { //print $id.'-'.$table.'-'.$elementname.'
'; // Check if third party can be deleted - $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; + $sql = "SELECT COUNT(*) as nb from ".$this->db->prefix().$table; $sql .= " WHERE ".$this->fk_element." = ".((int) $id); $resql = $this->db->query($sql); if ($resql) { @@ -4439,7 +4439,7 @@ abstract class CommonObject $total_discount = 0.00; $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql .= " FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); @@ -4579,7 +4579,7 @@ abstract class CommonObject $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET extraparams = ".(!empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); $sql .= " WHERE rowid = ".((int) $this->id); @@ -5074,7 +5074,7 @@ abstract class CommonObject // phpcs:enable $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; + $sql = "INSERT INTO ".$this->db->prefix()."element_resources ("; $sql .= "resource_id"; $sql .= ", resource_type"; $sql .= ", element_id"; @@ -5117,7 +5117,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; + $sql = "DELETE FROM ".$this->db->prefix()."element_resources"; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); @@ -5437,7 +5437,7 @@ abstract class CommonObject //var_dump($obj->update_main_doc_field);exit; if ($update_main_doc_field && !empty($this->table_element)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath."/".$ecmfile->filename)."'"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath."/".$ecmfile->filename)."'"; $sql .= " WHERE rowid = ".((int) $this->id); $resql = $this->db->query($sql); @@ -5601,7 +5601,7 @@ abstract class CommonObject // Request to get translation values for object $sql = "SELECT rowid, property, lang , value"; - $sql .= " FROM ".MAIN_DB_PREFIX."object_lang"; + $sql .= " FROM ".$this->db->prefix()."object_lang"; $sql .= " WHERE type_object = '".$this->db->escape($element)."'"; $sql .= " AND fk_object = ".((int) $this->id); @@ -5806,7 +5806,7 @@ abstract class CommonObject $sql .= ", ".$name; } } - $sql .= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; + $sql .= " FROM ".$this->db->prefix().$table_element."_extrafields"; $sql .= " WHERE fk_object = ".((int) $rowid); //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose @@ -5880,7 +5880,7 @@ abstract class CommonObject dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql_del = "DELETE FROM ".$this->db->prefix().$table_element."_extrafields WHERE fk_object = ".((int) $this->id); $resql = $this->db->query($sql_del); if (!$resql) { @@ -6080,10 +6080,10 @@ abstract class CommonObject dol_syslog(get_class($this)."::insertExtraFields delete then insert", LOG_DEBUG); - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql_del = "DELETE FROM ".$this->db->prefix().$table_element."_extrafields WHERE fk_object = ".((int) $this->id); $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; + $sql = "INSERT INTO ".$this->db->prefix().$table_element."_extrafields (fk_object"; foreach ($new_array_options as $key => $value) { $attributeKey = substr($key, 8); // Remove 'options_' prefix // Add field of attribut @@ -6231,13 +6231,13 @@ abstract class CommonObject foreach ($new_array_languages as $key => $langcodearray) { // $key = 'name', 'town', ... foreach ($langcodearray as $langcode => $value) { - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."object_lang"; + $sql_del = "DELETE FROM ".$this->db->prefix()."object_lang"; $sql_del .= " WHERE fk_object = ".((int) $this->id)." AND property = '".$this->db->escape($key)."' AND type_object = '".$this->db->escape($table_element)."'"; $sql_del .= " AND lang = '".$this->db->escape($langcode)."'"; $this->db->query($sql_del); if ($value !== '') { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."object_lang (fk_object, property, type_object, lang, value"; + $sql = "INSERT INTO ".$this->db->prefix()."object_lang (fk_object, property, type_object, lang, value"; $sql .= ") VALUES (".$this->id.", '".$this->db->escape($key)."', '".$this->db->escape($table_element)."', '".$this->db->escape($langcode)."', '".$this->db->escape($value)."'"; $sql .= ")"; @@ -6421,7 +6421,7 @@ abstract class CommonObject $linealreadyfound = 0; // Check if there is already a line for this object (in most cases, it is, but sometimes it is not, for example when extra field has been created after), so we must keep this overload) - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql = "SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->table_element."_extrafields WHERE fk_object = ".((int) $this->id); $resql = $this->db->query($sql); if ($resql) { $tmpobj = $this->db->fetch_object($resql); @@ -6432,9 +6432,9 @@ abstract class CommonObject if ($linealreadyfound) { if ($this->array_options["options_".$key] === null) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key." = null"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element."_extrafields SET ".$key." = null"; } else { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key." = '".$this->db->escape($this->array_options["options_".$key])."'"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element."_extrafields SET ".$key." = '".$this->db->escape($this->array_options["options_".$key])."'"; } $sql .= " WHERE fk_object = ".((int) $this->id); } else { @@ -6763,7 +6763,7 @@ abstract class CommonObject $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= " FROM ".MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= " FROM ".$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -6779,7 +6779,7 @@ abstract class CommonObject //We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= " as main, ".MAIN_DB_PREFIX.$InfoFieldList[0]."_extrafields as extra"; + $sql .= " as main, ".$this->db->prefix().$InfoFieldList[0]."_extrafields as extra"; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -6915,7 +6915,7 @@ abstract class CommonObject $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -6931,7 +6931,7 @@ abstract class CommonObject // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -7276,7 +7276,7 @@ abstract class CommonObject } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -7359,7 +7359,7 @@ abstract class CommonObject } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -8052,7 +8052,7 @@ abstract class CommonObject public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) { foreach ($tables as $table) { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.((int) $dest_id).' WHERE fk_soc = '.((int) $origin_id); + $sql = 'UPDATE '.$this->db->prefix().$table.' SET fk_soc = '.((int) $dest_id).' WHERE fk_soc = '.((int) $origin_id); if (!$db->query($sql)) { if ($ignoreerrors) { @@ -8776,7 +8776,7 @@ abstract class CommonObject $this->db->begin(); if (!$error) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element; $sql .= " (".implode(", ", $keys).')'; $sql .= " VALUES (".implode(", ", $values).")"; // $values can contains 'abc' or 123 @@ -8792,13 +8792,13 @@ abstract class CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); } // If we have a field ref with a default value of (PROV) if (!$error) { if (key_exists('ref', $this->fields) && $this->fields['ref']['notnull'] > 0 && key_exists('default', $this->fields['ref']) && $this->fields['ref']['default'] == '(PROV)') { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref = '(PROV".((int) $this->id).")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id); + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET ref = '(PROV".((int) $this->id).")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id); $resqlupdate = $this->db->query($sql); if ($resqlupdate === false) { @@ -8883,7 +8883,7 @@ abstract class CommonObject } $sql = "SELECT ".$fieldlist; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element.' as t'; if (!empty($id)) { $sql .= ' WHERE t.rowid = '.((int) $id); @@ -8938,7 +8938,7 @@ abstract class CommonObject $objectline = new $objectlineclassname($this->db); $sql = "SELECT ".$objectline->getFieldList('l'); - $sql .= " FROM ".MAIN_DB_PREFIX.$objectline->table_element." as l"; + $sql .= " FROM ".$this->db->prefix().$objectline->table_element." as l"; $sql .= " WHERE l.fk_".$this->db->escape($this->element)." = ".((int) $this->id); if ($morewhere) { $sql .= $morewhere; @@ -9028,7 +9028,7 @@ abstract class CommonObject }*/ } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode(', ', $tmp).' WHERE rowid='.((int) $this->id); + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET '.implode(', ', $tmp).' WHERE rowid='.((int) $this->id); $this->db->begin(); if (!$error) { @@ -9085,7 +9085,7 @@ abstract class CommonObject if ($forcechilddeletion) { // Force also delete of childtables that should lock deletion in standard case when option force is off foreach ($this->childtables as $table) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "DELETE FROM ".$this->db->prefix().$table." WHERE ".$this->fk_element." = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -9139,7 +9139,7 @@ abstract class CommonObject } } else { // Delete record in child table - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "DELETE FROM ".$this->db->prefix().$table." WHERE ".$this->fk_element." = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { @@ -9179,7 +9179,7 @@ abstract class CommonObject } if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.((int) $this->id); + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element.' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { @@ -9218,7 +9218,7 @@ abstract class CommonObject if (!empty($parentId) && !empty($parentField)) { $this->db->begin(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE ".$parentField." = ".(int) $parentId; // Manage filters @@ -9303,7 +9303,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $idline); dol_syslog(get_class($this)."::deleteLineCommon", LOG_DEBUG); @@ -9357,7 +9357,7 @@ abstract class CommonObject $statusfield = 'fk_statut'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ".$statusfield." = ".((int) $status); $sql .= " WHERE rowid = ".((int) $this->id); @@ -9594,8 +9594,8 @@ abstract class CommonObject require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $categorystatic = new Categorie($this->db); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type])." (fk_categorie, fk_product)"; - $sql .= " SELECT fk_categorie, $toId FROM ".MAIN_DB_PREFIX."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]); + $sql = "INSERT INTO ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type])." (fk_categorie, fk_product)"; + $sql .= " SELECT fk_categorie, $toId FROM ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]); $sql .= " WHERE fk_product = ".((int) $fromId); if (!$this->db->query($sql)) { @@ -9643,8 +9643,8 @@ abstract class CommonObject } // Delete ecm_files extrafields - $sql = "DELETE FROM ".MAIN_DB_PREFIX."ecm_files_extrafields WHERE fk_object IN ("; - $sql .= " SELECT rowid FROM ".MAIN_DB_PREFIX."ecm_files WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; + $sql = "DELETE FROM ".$this->db->prefix()."ecm_files_extrafields WHERE fk_object IN ("; + $sql .= " SELECT rowid FROM ".$this->db->prefix()."ecm_files WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; $sql .= " AND filepath = '".$this->db->escape($element)."/".$this->db->escape($this->ref)."' AND entity = ".((int) $conf->entity); // No need of getEntity here $sql .= ")"; @@ -9655,7 +9655,7 @@ abstract class CommonObject } // Delete ecm_files - $sql = "DELETE FROM ".MAIN_DB_PREFIX."ecm_files"; + $sql = "DELETE FROM ".$this->db->prefix()."ecm_files"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; $sql .= " AND filepath = '".$this->db->escape($element)."/".$this->db->escape($this->ref)."' AND entity = ".((int) $conf->entity); // No need of getEntity here @@ -9668,8 +9668,8 @@ abstract class CommonObject // Delete in database with mode 1 if ($mode == 1) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files_extrafields"; - $sql .= " WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id).")"; + $sql = 'DELETE FROM '.$this->db->prefix()."ecm_files_extrafields"; + $sql .= " WHERE fk_object IN (SELECT rowid FROM ".$this->db->prefix()."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id).")"; $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -9677,7 +9677,7 @@ abstract class CommonObject return false; } - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files"; + $sql = 'DELETE FROM '.$this->db->prefix()."ecm_files"; $sql .= " WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index d93d0b67ff9..487482a9b3c 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -93,7 +93,7 @@ abstract class CommonObjectLine extends CommonObject $label_type = 'code'; } - $sql = "SELECT ".$label_type.", code from ".MAIN_DB_PREFIX."c_units where rowid = ".((int) $this->fk_unit); + $sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit); $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index 33510186646..91b176f899d 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -183,7 +183,7 @@ class CoreObject extends CommonObject $this->{$className} = array(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$childTable." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "SELECT rowid FROM ".$this->db->prefix().$childTable." WHERE ".$this->fk_element." = ".((int) $this->id); $res = $this->db->query($sql); if ($res) { diff --git a/htdocs/core/class/cproductnature.class.php b/htdocs/core/class/cproductnature.class.php index 5b343b21dbc..1fe72f46738 100644 --- a/htdocs/core/class/cproductnature.class.php +++ b/htdocs/core/class/cproductnature.class.php @@ -102,7 +102,7 @@ class CProductNature // extends CommonObject global $conf, $langs; // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element."("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "label,"; @@ -125,7 +125,7 @@ class CProductNature // extends CommonObject $this->db->rollback(); return -1; } else { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); $this->db->commit(); return $this->id; } @@ -148,7 +148,7 @@ class CProductNature // extends CommonObject $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; $sql_where = array(); if ($id) { $sql_where[] = " t.rowid = ".((int) $id); @@ -202,7 +202,7 @@ class CProductNature // extends CommonObject $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { @@ -267,7 +267,7 @@ class CProductNature // extends CommonObject global $conf, $langs; // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " code=".(isset($this->code) ? ((int) $this->code) : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape(trim($this->label))."'" : "null").","; $sql .= " active=".(isset($this->active) ? ((int) $this->active) : "null"); @@ -302,7 +302,7 @@ class CProductNature // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid=".(int) $this->id; $this->db->begin(); diff --git a/htdocs/core/class/cstate.class.php b/htdocs/core/class/cstate.class.php index 2b9b1d6880e..36c3cb2c0fe 100644 --- a/htdocs/core/class/cstate.class.php +++ b/htdocs/core/class/cstate.class.php @@ -106,7 +106,7 @@ class Cstate // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_departements("; + $sql = "INSERT INTO ".$this->db->prefix()."c_departements("; $sql .= "rowid,"; $sql .= "code_departement,"; $sql .= "nom,"; @@ -128,7 +128,7 @@ class Cstate // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_departements"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_departements"); } // Commit or rollback @@ -161,7 +161,7 @@ class Cstate // extends CommonObject $sql .= " t.code_departement,"; $sql .= " t.nom,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_departements as t"; + $sql .= " FROM ".$this->db->prefix()."c_departements as t"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); } elseif ($code) { @@ -219,7 +219,7 @@ class Cstate // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_departements SET"; + $sql = "UPDATE ".$this->db->prefix()."c_departements SET"; $sql .= " code_departement=".(isset($this->code_departement) ? "'".$this->db->escape($this->code_departement)."'" : "null").","; $sql .= " nom=".(isset($this->nom) ? "'".$this->db->escape($this->nom)."'" : "null").","; $sql .= " active=".(isset($this->active) ? $this->active : "null").""; @@ -260,7 +260,7 @@ class Cstate // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_departements"; + $sql = "DELETE FROM ".$this->db->prefix()."c_departements"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); diff --git a/htdocs/core/class/ctypent.class.php b/htdocs/core/class/ctypent.class.php index c8421c54b1f..6de7de7d5cb 100644 --- a/htdocs/core/class/ctypent.class.php +++ b/htdocs/core/class/ctypent.class.php @@ -105,7 +105,7 @@ class Ctypent // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_typent("; + $sql = "INSERT INTO ".$this->db->prefix()."c_typent("; $sql .= "id,"; $sql .= "code,"; @@ -135,7 +135,7 @@ class Ctypent // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_typent"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_typent"); } // Commit or rollback @@ -170,7 +170,7 @@ class Ctypent // extends CommonObject $sql .= " t.fk_country as country_id,"; $sql .= " t.active,"; $sql .= " t.module"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_typent as t"; + $sql .= " FROM ".$this->db->prefix()."c_typent as t"; if ($id) { $sql .= " WHERE t.id = ".((int) $id); } elseif ($code) { @@ -232,7 +232,7 @@ class Ctypent // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_typent SET"; + $sql = "UPDATE ".$this->db->prefix()."c_typent SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " libelle=".(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").","; $sql .= " active=".(isset($this->active) ? $this->active : "null").","; @@ -275,7 +275,7 @@ class Ctypent // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_typent"; + $sql = "DELETE FROM ".$this->db->prefix()."c_typent"; $sql .= " WHERE id=".$this->id; $this->db->begin(); diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php index 891bf6bea10..9c568be4165 100644 --- a/htdocs/core/class/ctyperesource.class.php +++ b/htdocs/core/class/ctyperesource.class.php @@ -99,7 +99,7 @@ class Ctyperesource // Put here code to add control on parameters values // Insert request - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; $sql .= 'code,'; $sql .= 'label'; @@ -125,7 +125,7 @@ class Ctyperesource } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. @@ -168,7 +168,7 @@ class Ctyperesource $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; if ($id) { $sql .= " WHERE t.id = ".((int) $id); } elseif ($code) { @@ -233,7 +233,7 @@ class Ctyperesource $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; // Manage filter $sqlwhere = array(); @@ -307,7 +307,7 @@ class Ctyperesource // Put here code to add a control on parameters values // Update request - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET'; $sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").','; $sql .= ' label = '.(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").','; @@ -376,7 +376,7 @@ class Ctyperesource // If you need to delete child tables to, you can insert them here if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element; $sql .= ' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php index 7219f901c9f..5e7188c63ac 100644 --- a/htdocs/core/class/cunits.class.php +++ b/htdocs/core/class/cunits.class.php @@ -112,7 +112,7 @@ class CUnits // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_units("; + $sql = "INSERT INTO ".$this->db->prefix()."c_units("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "label,"; @@ -138,7 +138,7 @@ class CUnits // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_units"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_units"); } // Commit or rollback @@ -178,7 +178,7 @@ class CUnits // extends CommonObject $sql .= " t.unit_type,"; $sql .= " t.scale,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t"; + $sql .= " FROM ".$this->db->prefix()."c_units as t"; $sql_where = array(); if ($id) { $sql_where[] = " t.rowid = ".((int) $id); @@ -246,7 +246,7 @@ class CUnits // extends CommonObject $sql .= " t.unit_type,"; $sql .= " t.scale,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'c_units as t'; + $sql .= ' FROM '.$this->db->prefix().'c_units as t'; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { @@ -343,7 +343,7 @@ class CUnits // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_units SET"; + $sql = "UPDATE ".$this->db->prefix()."c_units SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " sortorder=".(isset($this->sortorder) ? "'".$this->db->escape($this->sortorder)."'" : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; @@ -389,7 +389,7 @@ class CUnits // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_units"; + $sql = "DELETE FROM ".$this->db->prefix()."c_units"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); @@ -471,7 +471,7 @@ class CUnits // extends CommonObject { $base = 10; // TODO : add base col into unit dictionary table - $unit = $this->db->getRow('SELECT scale, unit_type from '.MAIN_DB_PREFIX.'c_units WHERE rowid = '.intval($id)); + $unit = $this->db->getRow('SELECT scale, unit_type from '.$this->db->prefix().'c_units WHERE rowid = '.intval($id)); if ($unit) { // TODO : if base exist in unit dictionary table remove this convertion exception and update convertion infos in database exemple time hour currently scale 3600 will become scale 2 base 60 if ($unit->unit_type == 'time') { diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index f6edb58207c..bab0204fb3b 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -261,7 +261,7 @@ class DefaultValues extends CommonObject $sql = 'SELECT '; $sql .= $this->getFieldList(); - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE 1 = 1'; // Manage filter $sqlwhere = array(); diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index 46789352bd7..42b22473f10 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -139,9 +139,9 @@ class DiscountAbsolute $sql .= " sr.datec,"; $sql .= " f.ref as ref_facture_source, f.type as type_facture_source,"; $sql .= " fsup.ref as ref_invoice_supplier_source, fsup.type as type_invoice_supplier_source"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fsup ON sr.fk_invoice_supplier_source = fsup.rowid"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as sr"; + $sql .= " LEFT JOIN ".$this->db->prefix()."facture as f ON sr.fk_facture_source = f.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."facture_fourn as fsup ON sr.fk_invoice_supplier_source = fsup.rowid"; $sql .= " WHERE sr.entity IN (".getEntity('invoice').")"; if ($rowid) { $sql .= " AND sr.rowid = ".((int) $rowid); @@ -251,7 +251,7 @@ class DiscountAbsolute } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "INSERT INTO ".$this->db->prefix()."societe_remise_except"; $sql .= " (entity, datec, fk_soc, discount_type, fk_user, description,"; $sql .= " amount_ht, amount_tva, amount_ttc, tva_tx, vat_src_code,"; $sql .= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,"; @@ -267,7 +267,7 @@ class DiscountAbsolute dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except"); + $this->id = $this->db->last_insert_id($this->db->prefix()."societe_remise_except"); return $this->id; } else { $this->error = $this->db->lasterror().' - sql='.$sql; @@ -289,7 +289,7 @@ class DiscountAbsolute // Check if we can remove the discount if ($this->fk_facture_source) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except"; $sql .= " WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount $sql .= " OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit $sql .= " AND fk_facture_source = ".((int) $this->fk_facture_source); @@ -312,7 +312,7 @@ class DiscountAbsolute // Check if we can remove the discount if ($this->fk_invoice_supplier_source) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except"; $sql .= " WHERE (fk_invoice_supplier_line IS NOT NULL"; // Not used as absolute simple discount $sql .= " OR fk_invoice_supplier IS NOT NULL)"; // Not used as credit note and not used as deposit $sql .= " AND fk_invoice_supplier_source = ".((int) $this->fk_invoice_supplier_source); @@ -335,7 +335,7 @@ class DiscountAbsolute $this->db->begin(); // Delete but only if not used - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except "; + $sql = "DELETE FROM ".$this->db->prefix()."societe_remise_except "; if ($this->fk_facture_source) { $sql .= " WHERE fk_facture_source = ".((int) $this->fk_facture_source); // Delete all lines of same serie } elseif ($this->fk_invoice_supplier_source) { @@ -353,7 +353,7 @@ class DiscountAbsolute if ($result) { // If source of discount was a credit note or deposit, we change source statut. if ($this->fk_facture_source) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; + $sql = "UPDATE ".$this->db->prefix()."facture"; $sql .= " set paye=0, fk_statut=1"; $sql .= " WHERE (type = 2 or type = 3) AND rowid = ".((int) $this->fk_facture_source); @@ -368,7 +368,7 @@ class DiscountAbsolute return -1; } } elseif ($this->fk_invoice_supplier_source) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn"; + $sql = "UPDATE ".$this->db->prefix()."facture_fourn"; $sql .= " set paye=0, fk_statut=1"; $sql .= " WHERE (type = 2 or type = 3) AND rowid = ".((int) $this->fk_invoice_supplier_source); @@ -418,7 +418,7 @@ class DiscountAbsolute return -2; } - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "UPDATE ".$this->db->prefix()."societe_remise_except"; if (!empty($this->discount_type)) { if ($rowidline) { $sql .= " SET fk_invoice_supplier_line = ".((int) $rowidline); @@ -464,7 +464,7 @@ class DiscountAbsolute public function unlink_invoice() { // phpcs:enable - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "UPDATE ".$this->db->prefix()."societe_remise_except"; if (!empty($this->discount_type)) { $sql .= " SET fk_invoice_supplier_line = NULL, fk_invoice_supplier = NULL"; } else { @@ -501,7 +501,7 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getAvailableDiscounts discount_type=".$discount_type, LOG_DEBUG); $sql = "SELECT SUM(rc.amount_ttc) as amount, SUM(rc.multicurrency_amount_ttc) as multicurrency_amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc"; $sql .= " WHERE rc.entity = ".$conf->entity; $sql .= " AND rc.discount_type=".((int) $discount_type); if (!empty($discount_type)) { @@ -554,12 +554,12 @@ class DiscountAbsolute if ($invoice->element == 'facture' || $invoice->element == 'invoice') { $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture as f'; $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $invoice->id); $sql .= ' AND f.type = 3'; } elseif ($invoice->element == 'invoice_supplier') { $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture_fourn as f'; $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $invoice->id); $sql .= ' AND f.type = 3'; } else { @@ -595,12 +595,12 @@ class DiscountAbsolute if ($invoice->element == 'facture' || $invoice->element == 'invoice') { $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture as f'; $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $invoice->id); $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE.", ".$invoice::TYPE_SITUATION).')'; // Find discount coming from credit note or excess received } elseif ($invoice->element == 'invoice_supplier') { $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture_fourn as f'; $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $invoice->id); $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE).')'; // Find discount coming from credit note or excess paid } else { @@ -635,11 +635,11 @@ class DiscountAbsolute if ($invoice->element == 'facture' || $invoice->element == 'invoice') { $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc'; $sql .= ' WHERE rc.fk_facture IS NULL AND rc.fk_facture_source = '.((int) $invoice->id); } elseif ($invoice->element == 'invoice_supplier') { $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc'; $sql .= ' WHERE rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_source = '.((int) $invoice->id); } else { $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 9db069ab290..62f9b15e8b2 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -243,7 +243,7 @@ class dolReceiptPrinter extends Printer $line = 0; $obj = array(); $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt'; + $sql .= ' FROM '.$this->db->prefix().'printer_receipt'; $sql .= ' WHERE entity = '.$conf->entity; $resql = $this->db->query($sql); if ($resql) { @@ -311,7 +311,7 @@ class dolReceiptPrinter extends Printer $line = 0; $obj = array(); $sql = 'SELECT rowid, name, template'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; + $sql .= ' FROM '.$this->db->prefix().'printer_receipt_template'; $sql .= ' WHERE entity = '.$conf->entity; $resql = $this->db->query($sql); if ($resql) { @@ -391,7 +391,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt"; + $sql = "INSERT INTO ".$this->db->prefix()."printer_receipt"; $sql .= " (name, fk_type, fk_profile, parameter, entity)"; $sql .= " VALUES ('".$this->db->escape($name)."', ".((int) $type).", ".((int) $profile).", '".$this->db->escape($parameter)."', ".((int) $conf->entity).")"; $resql = $this->db->query($sql); @@ -417,7 +417,7 @@ class dolReceiptPrinter extends Printer global $conf; $error = 0; - $sql = "UPDATE ".MAIN_DB_PREFIX."printer_receipt"; + $sql = "UPDATE ".$this->db->prefix()."printer_receipt"; $sql .= " SET name='".$this->db->escape($name)."'"; $sql .= ", fk_type=".((int) $type); $sql .= ", fk_profile=".((int) $profile); @@ -442,7 +442,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt'; + $sql = 'DELETE FROM '.$this->db->prefix().'printer_receipt'; $sql .= ' WHERE rowid='.((int) $printerid); $resql = $this->db->query($sql); if (!$resql) { @@ -463,7 +463,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt_template"; + $sql = "INSERT INTO ".$this->db->prefix()."printer_receipt_template"; $sql .= " (name, template, entity) VALUES ('".$this->db->escape($name)."'"; $sql .= ", '".$this->db->escape($template)."', ".$conf->entity.")"; $resql = $this->db->query($sql); @@ -484,7 +484,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; + $sql = 'DELETE FROM '.$this->db->prefix().'printer_receipt_template'; $sql .= " WHERE rowid = ".((int) $templateid); $sql .= " AND entity = ".$conf->entity; $resql = $this->db->query($sql); @@ -508,7 +508,7 @@ class dolReceiptPrinter extends Printer global $conf; $error = 0; - $sql = "UPDATE ".MAIN_DB_PREFIX."printer_receipt_template"; + $sql = "UPDATE ".$this->db->prefix()."printer_receipt_template"; $sql .= " SET name='".$this->db->escape($name)."'"; $sql .= ", template='".$this->db->escape($template)."'"; $sql .= " WHERE rowid=".((int) $templateid); @@ -807,8 +807,8 @@ class dolReceiptPrinter extends Printer case 'DOL_PRINT_PAYMENT': $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; $sql .= " cp.code"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; + $sql .= " FROM ".$this->db->prefix()."paiement_facture as pf, ".$this->db->prefix()."paiement as p"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_paiement as cp ON p.fk_paiement = cp.id"; $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id); $sql .= " ORDER BY p.datep"; $resql = $this->db->query($sql); @@ -834,7 +834,7 @@ class dolReceiptPrinter extends Printer } break; case 'DOL_VALUE_PLACE': - $sql = "SELECT floor, label FROM ".MAIN_DB_PREFIX."takepos_floor_tables where rowid=".((int) str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $object->ref))); + $sql = "SELECT floor, label FROM ".$this->db->prefix()."takepos_floor_tables where rowid=".((int) str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $object->ref))); $resql = $this->db->query($sql); $obj = $this->db->fetch_object($resql); if ($obj) { @@ -874,7 +874,7 @@ class dolReceiptPrinter extends Printer global $conf; $error = 0; $sql = 'SELECT template'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; + $sql .= ' FROM '.$this->db->prefix().'printer_receipt_template'; $sql .= ' WHERE rowid = '.((int) $templateid); $sql .= ' AND entity = '.$conf->entity; $resql = $this->db->query($sql); @@ -911,7 +911,7 @@ class dolReceiptPrinter extends Printer } $error = 0; $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt'; + $sql .= ' FROM '.$this->db->prefix().'printer_receipt'; $sql .= ' WHERE rowid = '.((int) $printerid); $sql .= ' AND entity = '.((int) $conf->entity); $resql = $this->db->query($sql); diff --git a/htdocs/core/class/emailsenderprofile.class.php b/htdocs/core/class/emailsenderprofile.class.php index 0ee7eb118ac..a381b4d96c7 100644 --- a/htdocs/core/class/emailsenderprofile.class.php +++ b/htdocs/core/class/emailsenderprofile.class.php @@ -348,7 +348,7 @@ class EmailSenderProfile extends CommonObject public function info($id) { $sql = 'SELECT rowid, date_creation as datec, tms as datem'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE t.rowid = '.((int) $id); $result = $this->db->query($sql); if ($result) { diff --git a/htdocs/core/class/events.class.php b/htdocs/core/class/events.class.php index c8799ebbd5e..104f1567d44 100644 --- a/htdocs/core/class/events.class.php +++ b/htdocs/core/class/events.class.php @@ -152,7 +152,7 @@ class Events // extends CommonObject } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."events("; + $sql = "INSERT INTO ".$this->db->prefix()."events("; $sql .= "type,"; $sql .= "entity,"; $sql .= "ip,"; @@ -175,7 +175,7 @@ class Events // extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events"); + $this->id = $this->db->last_insert_id($this->db->prefix()."events"); return $this->id; } else { $this->error = "Error ".$this->db->lasterror(); @@ -202,7 +202,7 @@ class Events // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."events SET"; + $sql = "UPDATE ".$this->db->prefix()."events SET"; $sql .= " type='".$this->db->escape($this->type)."',"; $sql .= " dateevent='".$this->db->idate($this->dateevent)."',"; $sql .= " description='".$this->db->escape($this->description)."'"; @@ -237,7 +237,7 @@ class Events // extends CommonObject $sql .= " t.ip,"; $sql .= " t.user_agent,"; $sql .= " t.prefix_session"; - $sql .= " FROM ".MAIN_DB_PREFIX."events as t"; + $sql .= " FROM ".$this->db->prefix()."events as t"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -274,7 +274,7 @@ class Events // extends CommonObject */ public function delete($user) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."events"; + $sql = "DELETE FROM ".$this->db->prefix()."events"; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 4c0ec1ff5a5..9a011591afb 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -265,10 +265,10 @@ class ExtraFields 'default' => $default_value ); - $result = $this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); + $result = $this->db->DDLAddField($this->db->prefix().$table, $attrname, $field_desc); if ($result > 0) { if ($unique) { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; + $sql = "ALTER TABLE ".$this->db->prefix().$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; $resql = $this->db->query($sql, 1, 'dml'); } return 1; @@ -353,7 +353,7 @@ class ExtraFields $params = ''; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; + $sql = "INSERT INTO ".$this->db->prefix()."extrafields("; $sql .= " name,"; $sql .= " label,"; $sql .= " type,"; @@ -447,7 +447,7 @@ class ExtraFields if (!$error) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; + $sql .= " FROM ".$this->db->prefix()."extrafields"; $sql .= " WHERE elementtype = '".$this->db->escape($elementtype)."'"; $sql .= " AND name = '".$this->db->escape($attrname)."'"; //$sql.= " AND entity IN (0,".$conf->entity.")"; Do not test on entity here. We want to see if there is still on field remaning in other entities before deleting field in table @@ -455,7 +455,7 @@ class ExtraFields if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj->nb <= 0) { - $result = $this->db->DDLDropField(MAIN_DB_PREFIX.$table, $attrname); // This also drop the unique key + $result = $this->db->DDLDropField($this->db->prefix().$table, $attrname); // This also drop the unique key if ($result < 0) { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); @@ -492,7 +492,7 @@ class ExtraFields } if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql .= " AND entity IN (0,".$conf->entity.')'; $sql .= " AND elementtype = '".$this->db->escape($elementtype)."'"; @@ -597,7 +597,7 @@ class ExtraFields } if ($type != 'separate') { // No table update when separate type - $result = $this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); + $result = $this->db->DDLUpdateField($this->db->prefix().$table, $attrname, $field_desc); } if ($result > 0 || $type == 'separate') { if ($label) { @@ -606,9 +606,9 @@ class ExtraFields if ($result > 0) { $sql = ''; if ($unique) { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; + $sql = "ALTER TABLE ".$this->db->prefix().$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; } else { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname; + $sql = "ALTER TABLE ".$this->db->prefix().$table." DROP INDEX uk_".$table."_".$attrname; } dol_syslog(get_class($this).'::update', LOG_DEBUG); $resql = $this->db->query($sql, 1, 'dml'); @@ -699,20 +699,20 @@ class ExtraFields if ($entity === '' || $entity != '0') { // We dont want on all entities, we delete all and current - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql_del = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql_del .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql_del .= " AND entity IN (0, ".($entity === '' ? $conf->entity : $entity).")"; $sql_del .= " AND elementtype = '".$this->db->escape($elementtype)."'"; } else { // We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity) - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql_del = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql_del .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql_del .= " AND entity = 0"; $sql_del .= " AND elementtype = '".$this->db->escape($elementtype)."'"; } $resql1 = $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; + $sql = "INSERT INTO ".$this->db->prefix()."extrafields("; $sql .= " name,"; // This is code $sql .= " entity,"; $sql .= " label,"; @@ -812,7 +812,7 @@ class ExtraFields // We should not have several time this request. If we have, there is some optimization to do by calling a simple $extrafields->fetch_optionals() in top of code and not into subcode $sql = "SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, perms, langs, list, printable, totalizable, fielddefault, fieldcomputed, entity, enabled, help"; - $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; + $sql .= " FROM ".$this->db->prefix()."extrafields"; //$sql.= " WHERE entity IN (0,".$conf->entity.")"; // Filter is done later if ($elementtype) { $sql .= " WHERE elementtype = '".$this->db->escape($elementtype)."'"; // Filed with object->table_element @@ -1139,7 +1139,7 @@ class ExtraFields $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use curent entity filter if (strpos($InfoFieldList[4], '$ENTITY$') !== false) { @@ -1158,7 +1158,7 @@ class ExtraFields } //We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -1307,7 +1307,7 @@ class ExtraFields $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -1370,7 +1370,7 @@ class ExtraFields // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra.') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -1595,7 +1595,7 @@ class ExtraFields } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -1699,7 +1699,7 @@ class ExtraFields } $sql = "SELECT ".$keyList; - $sql .= " FROM ".MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= " FROM ".$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 0edae298f46..66eb09d62a4 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -134,7 +134,7 @@ class Fiscalyear extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear ("; + $sql = "INSERT INTO ".$this->db->prefix()."accounting_fiscalyear ("; $sql .= "label"; $sql .= ", date_start"; $sql .= ", date_end"; @@ -155,7 +155,7 @@ class Fiscalyear extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear"); + $this->id = $this->db->last_insert_id($this->db->prefix()."accounting_fiscalyear"); $result = $this->update($user); if ($result > 0) { @@ -191,7 +191,7 @@ class Fiscalyear extends CommonObject $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear"; + $sql = "UPDATE ".$this->db->prefix()."accounting_fiscalyear"; $sql .= " SET label = '".$this->db->escape($this->label)."'"; $sql .= ", date_start = '".$this->db->idate($this->date_start)."'"; $sql .= ", date_end = ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null"); @@ -221,7 +221,7 @@ class Fiscalyear extends CommonObject public function fetch($id) { $sql = "SELECT rowid, label, date_start, date_end, statut"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear"; + $sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear"; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -253,7 +253,7 @@ class Fiscalyear extends CommonObject { $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE rowid = ".((int) $id); + $sql = "DELETE FROM ".$this->db->prefix()."accounting_fiscalyear WHERE rowid = ".((int) $id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); $result = $this->db->query($sql); @@ -416,7 +416,7 @@ class Fiscalyear extends CommonObject { $sql = 'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,'; $sql .= ' fy.tms'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy'; + $sql .= ' FROM '.$this->db->prefix().'accounting_fiscalyear as fy'; $sql .= ' WHERE fy.rowid = '.((int) $id); dol_syslog(get_class($this)."::fetch info", LOG_DEBUG); @@ -464,7 +464,7 @@ class Fiscalyear extends CommonObject } $sql = "SELECT count(DISTINCT piece_num) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; + $sql .= " FROM ".$this->db->prefix()."accounting_bookkeeping"; $sql .= " WHERE entity IN (".getEntity('bookkeeping', 0).")"; $sql .= " AND doc_date >= '".$this->db->idate($datestart)."' and doc_date <= '".$this->db->idate($dateend)."'"; @@ -498,7 +498,7 @@ class Fiscalyear extends CommonObject } $sql = "SELECT count(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; + $sql .= " FROM ".$this->db->prefix()."accounting_bookkeeping "; $sql .= " WHERE entity IN (".getEntity('bookkeeping', 0).")"; $sql .= " AND doc_date >= '".$this->db->idate($datestart)."' and doc_date <= '".$this->db->idate($dateend)."'"; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index ff5f5d0d0a5..2ca4af802d2 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -886,7 +886,7 @@ class Form $atleastonefavorite = 0; $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_country"; + $sql .= " FROM ".$this->db->prefix()."c_country"; $sql .= " WHERE active > 0"; //$sql.= " ORDER BY code ASC"; @@ -1009,7 +1009,7 @@ class Form $incotermArray = array(); $sql = "SELECT rowid, code"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_incoterms"; + $sql .= " FROM ".$this->db->prefix()."c_incoterms"; $sql .= " WHERE active > 0"; $sql .= " ORDER BY code ASC"; @@ -1155,7 +1155,7 @@ class Form $langs->load("trips"); $sql = "SELECT c.code, c.label"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; + $sql .= " FROM ".$this->db->prefix()."c_type_fees as c"; $sql .= " WHERE active > 0"; $resql = $this->db->query($sql); @@ -1344,12 +1344,12 @@ class Form $sql .= ", s.address, s.zip, s.town"; $sql .= ", dictp.code as country_code"; } - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."societe as s"; if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid = s.fk_pays"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_country as dictp ON dictp.rowid = s.fk_pays"; } if (empty($user->rights->societe->client->voir) && !$user->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE s.entity IN (".getEntity('societe').")"; if (!empty($user->socid)) { @@ -1523,7 +1523,7 @@ class Form // On recherche les remises $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql .= " re.description, re.fk_facture_source"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as re"; $sql .= " WHERE re.fk_soc = ".(int) $socid; $sql .= " AND re.entity = ".$conf->entity; if ($filter) { @@ -1668,9 +1668,9 @@ class Form if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) { $sql .= ", s.nom as company, s.town AS company_town"; } - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; + $sql .= " FROM ".$this->db->prefix()."socpeople as sp"; if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) { - $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=sp.fk_soc"; + $sql .= " LEFT OUTER JOIN ".$this->db->prefix()."societe as s ON s.rowid=sp.fk_soc"; } $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")"; if ($socid > 0 || $socid == -1) { @@ -1922,9 +1922,9 @@ class Form if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { $sql .= ", e.label"; } - $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " FROM ".$this->db->prefix()."user as u"; if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid = u.entity"; + $sql .= " LEFT JOIN ".$this->db->prefix()."entity as e ON e.rowid = u.entity"; if ($force_entity) { $sql .= " WHERE u.entity IN (0, ".$this->db->sanitize($force_entity).")"; } else { @@ -1932,7 +1932,7 @@ class Form } } else { if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= " LEFT JOIN ".$this->db->prefix()."usergroup_user as ug"; $sql .= " ON ug.fk_user = u.rowid"; $sql .= " WHERE ug.entity = ".$conf->entity; } else { @@ -2431,9 +2431,9 @@ class Form if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) { //Product category - $sql .= ", (SELECT ".MAIN_DB_PREFIX."categorie_product.fk_categorie - FROM ".MAIN_DB_PREFIX."categorie_product - WHERE ".MAIN_DB_PREFIX."categorie_product.fk_product=p.rowid + $sql .= ", (SELECT ".$this->db->prefix()."categorie_product.fk_categorie + FROM ".$this->db->prefix()."categorie_product + WHERE ".$this->db->prefix()."categorie_product.fk_product=p.rowid LIMIT 1 ) AS categorie_product_id "; } @@ -2459,13 +2459,13 @@ class Form } // Price by quantity if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { - $sql .= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; + $sql .= ", (SELECT pp.rowid FROM ".$this->db->prefix()."product_price as pp WHERE pp.fk_product = p.rowid"; if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { $sql .= " AND price_level = ".((int) $price_level); } $sql .= " ORDER BY date_price"; $sql .= " DESC LIMIT 1) as price_rowid"; - $sql .= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable + $sql .= ", (SELECT pp.price_by_qty FROM ".$this->db->prefix()."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { $sql .= " AND price_level = ".((int) $price_level); } @@ -2473,29 +2473,29 @@ class Form $sql .= " DESC LIMIT 1) as price_by_qty"; $selectFields .= ", price_rowid, price_by_qty"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product as p"; if (count($warehouseStatusArray)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_product = p.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (".getEntity('stock').")"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.fk_product = p.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (".getEntity('stock').")"; $sql .= ' AND e.statut IN ('.$this->db->sanitize($this->db->escape(implode(',', $warehouseStatusArray))).')'; // Return line if product is inside the selected stock. If not, an empty line will be returned so we will count 0. } // include search in supplier ref if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; } //Price by customer if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_customer_price as pcp ON pcp.fk_soc=".((int) $socid)." AND pcp.fk_product=p.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_customer_price as pcp ON pcp.fk_soc=".((int) $socid)." AND pcp.fk_product=p.rowid"; } // Units if (!empty($conf->global->PRODUCT_USE_UNITS)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units u ON u.rowid = p.fk_unit"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_units u ON u.rowid = p.fk_unit"; } // Multilang : we add translation if (!empty($conf->global->MAIN_MULTILANGS)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid "; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_lang as pl ON pl.fk_product = p.rowid "; if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && !empty($socid)) { require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $soc = new Societe($db); @@ -2511,7 +2511,7 @@ class Form } if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; } $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; @@ -2639,7 +2639,7 @@ class Form if ((!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) { // Price by quantity will return many prices for the same product $sql = "SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql .= " FROM ".$this->db->prefix()."product_price_by_qty"; $sql .= " WHERE fk_product_price = ".((int) $objp->price_rowid); $sql .= " ORDER BY quantity ASC"; @@ -2879,7 +2879,7 @@ class Form // If we need a particular price level (from 1 to n) if (empty($hidepriceinlabel) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) { $sql = "SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE fk_product = ".((int) $objp->rowid); $sql .= " AND entity IN (".getEntity('productprice').")"; $sql .= " AND price_level = ".((int) $price_level); @@ -3140,15 +3140,15 @@ class Form if (!empty($conf->barcode->enabled)) { $sql .= ", pfp.barcode"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (".getEntity('product').") )"; + $sql .= " FROM ".$this->db->prefix()."product as p"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (".getEntity('product').") )"; if ($socid > 0) { $sql .= " AND pfp.fk_soc = ".((int) $socid); } - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON pfp.fk_soc = s.rowid"; // Units if (!empty($conf->global->PRODUCT_USE_UNITS)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units u ON u.rowid = p.fk_unit"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_units u ON u.rowid = p.fk_unit"; } $sql .= " WHERE p.entity IN (".getEntity('product').")"; if ($statut != -1) { @@ -3490,9 +3490,9 @@ class Form $sql = "SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,"; $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,"; $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; + $sql .= " FROM ".$this->db->prefix()."product as p"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON pfp.fk_soc = s.rowid"; $sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")"; $sql .= " AND p.tobuy = 1"; $sql .= " AND s.fournisseur = 1"; @@ -3588,7 +3588,7 @@ class Form // phpcs:enable // looking for users $sql = "SELECT a.rowid, a.label"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_address as a"; + $sql .= " FROM ".$this->db->prefix()."societe_address as a"; $sql .= " WHERE a.fk_soc = ".((int) $socid); $sql .= " ORDER BY a.label ASC"; @@ -3640,7 +3640,7 @@ class Form dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT rowid, code, libelle as label"; - $sql .= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; + $sql .= " FROM ".$this->db->prefix().'c_payment_term'; $sql .= " WHERE entity IN (".getEntity('c_payment_term').")"; $sql .= " AND active > 0"; $sql .= " ORDER BY sortorder"; @@ -3689,7 +3689,7 @@ class Form $langs->load('propal'); $sql = "SELECT rowid, code, label, position"; - $sql .= " FROM ".MAIN_DB_PREFIX.'c_availability'; + $sql .= " FROM ".$this->db->prefix().'c_availability'; $sql .= " WHERE active > 0"; $resql = $this->db->query($sql); @@ -3769,7 +3769,7 @@ class Form } $sql = "SELECT rowid, code, label"; - $sql .= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; + $sql .= " FROM ".$this->db->prefix().'c_input_reason'; $sql .= " WHERE active > 0"; $resql = $this->db->query($sql); @@ -3869,7 +3869,7 @@ class Form $this->cache_types_paiements = array(); $sql = "SELECT id, code, libelle as label, type, active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement"; + $sql .= " FROM ".$this->db->prefix()."c_paiement"; $sql .= " WHERE entity IN (".getEntity('c_paiement').")"; $resql = $this->db->query($sql); @@ -4131,7 +4131,7 @@ class Form $this->cache_transport_mode = array(); $sql = "SELECT rowid, code, label, active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_transport_mode"; + $sql .= " FROM ".$this->db->prefix()."c_transport_mode"; $sql .= " WHERE entity IN (".getEntity('c_transport_mode').")"; $resql = $this->db->query($sql); @@ -4249,7 +4249,7 @@ class Form $langs->load("deliveries"); $sql = "SELECT rowid, code, libelle as label"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; + $sql .= " FROM ".$this->db->prefix()."c_shipment_mode"; $sql .= " WHERE active > 0"; if ($filtre) { $sql .= " AND ".$filtre; @@ -4339,7 +4339,7 @@ class Form $opt = ''; $sql = 'SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture'; + $sql .= ' FROM '.$this->db->prefix().'facture'; $sql .= ' WHERE entity IN ('.getEntity('invoice').')'; $sql .= ' AND situation_counter >= 1'; $sql .= ' AND fk_soc = '.(int) $socid; @@ -4394,7 +4394,7 @@ class Form $return = ''; - $sql = 'SELECT rowid, label, code from '.$this->db->prefix().'c_units'; + $sql = "SELECT rowid, label, code FROM ".$this->db->prefix()."c_units"; $sql .= ' WHERE active > 0'; if (!empty($unit_type)) { $sql .= " AND unit_type = '".$this->db->escape($unit_type)."'"; @@ -5736,13 +5736,13 @@ class Form */ public function selectMultiCurrency($selected = '', $htmlname = 'multicurrency_code', $useempty = 0, $filter = '', $excludeConfCurrency = false) { - global $db, $conf, $langs, $user; + global $conf, $langs; $langs->loadCacheCurrencies(''); // Load ->cache_currencies $TCurrency = array(); - $sql = 'SELECT code FROM '.$this->db->prefix().'multicurrency'; + $sql = "SELECT code FROM ".$this->db->prefix()."multicurrency"; $sql .= " WHERE entity IN ('".getEntity('mutlicurrency')."')"; if ($filter) { $sql .= " AND ".$filter; @@ -6756,7 +6756,7 @@ class Form */ public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '') { - global $langs, $conf, $user, $db; + global $langs, $conf; $out = ''; $outarray = array(); @@ -6840,7 +6840,7 @@ class Form if (empty($outputmode)) return $out; return $outarray; } else { - dol_print_error($db); + dol_print_error($this->db); } } @@ -6857,8 +6857,6 @@ class Form */ protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '') { - global $langs, $conf, $user, $db; - $outkey = ''; $outval = ''; $outref = ''; @@ -6962,7 +6960,7 @@ class Form */ public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '') { - global $langs, $conf, $user, $db; + global $langs, $conf; $out = ''; $outarray = array(); @@ -7046,7 +7044,7 @@ class Form if (empty($outputmode)) return $out; return $outarray; } else { - dol_print_error($db); + dol_print_error($this->db); } } @@ -7063,8 +7061,6 @@ class Form */ protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '') { - global $langs, $conf, $user, $db; - $outkey = ''; $outval = ''; $outref = ''; @@ -7087,7 +7083,7 @@ class Form $outval .= $objRef; $opt .= "\n"; - $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtypem); + $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtype); } @@ -7169,7 +7165,7 @@ class Form */ public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '') { - global $langs, $conf, $user, $db; + global $langs, $conf; $out = ''; $outarray = array(); @@ -7253,7 +7249,7 @@ class Form if (empty($outputmode)) return $out; return $outarray; } else { - dol_print_error($db); + dol_print_error($this->db); } } @@ -7270,8 +7266,6 @@ class Form */ protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '') { - global $langs, $conf, $user, $db; - $outkey = ''; $outval = ''; $outref = ''; @@ -7294,7 +7288,7 @@ class Form $outval .= $objRef; $opt .= "\n"; - $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtypem); + $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtype); } /** @@ -7394,8 +7388,6 @@ class Form */ protected static function forgeCriteriaCallback($matches) { - global $db; - //dol_syslog("Convert matches ".$matches[1]); if (empty($matches[1])) { return ''; @@ -7408,11 +7400,11 @@ class Form $tmpescaped = $tmp[2]; $regbis = array(); if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis)) { - $tmpescaped = "'".$db->escape($regbis[1])."'"; + $tmpescaped = "'".$this->db->escape($regbis[1])."'"; } else { - $tmpescaped = $db->escape($tmpescaped); + $tmpescaped = $$this->db->escape($tmpescaped); } - return $db->escape($tmp[0]).' '.strtoupper($db->escape($tmp[1]))." ".$tmpescaped; + return $$this->db->escape($tmp[0]).' '.strtoupper($$this->db->escape($tmp[1]))." ".$tmpescaped; } /** @@ -8222,11 +8214,9 @@ class Form */ public function showCategories($id, $type, $rendermode = 0, $nolink = 0) { - global $db; - include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $cat = new Categorie($db); + $cat = new Categorie($this->db); $categories = $cat->containing($id, $type); if ($rendermode == 1) { @@ -9358,24 +9348,24 @@ class Form */ public function selectExpenseCategories($selected = '', $htmlname = 'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target = '', $default_selected = 0, $params = array(), $info_admin = 1) { - global $db, $langs, $user; + global $langs, $user; $out = ''; - $sql = 'SELECT rowid, label FROM '.$this->db->prefix().'c_exp_tax_cat WHERE active = 1'; - $sql .= ' AND entity IN (0,'.getEntity('exp_tax_cat').')'; + $sql = "SELECT rowid, label FROM ".$this->db->prefix()."c_exp_tax_cat WHERE active = 1"; + $sql .= " AND entity IN (0,".getEntity('exp_tax_cat').")"; if (!empty($excludeid)) { - $sql .= ' AND rowid NOT IN ('.$this->db->sanitize(implode(',', $excludeid)).')'; + $sql .= " AND rowid NOT IN (".$this->db->sanitize(implode(',', $excludeid)).")"; } - $sql .= ' ORDER BY label'; + $sql .= " ORDER BY label"; - $resql = $db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $out = ''; @@ -9387,10 +9377,10 @@ class Form if (!empty($target)) { $sql = "SELECT c.id FROM ".$this->db->prefix()."c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1"; - $resql = $db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - if ($db->num_rows($resql) > 0) { - $obj = $db->fetch_object($resql); + if ($this->db->num_rows($resql) > 0) { + $obj = $this->db->fetch_object($resql); $out .= ''."\n"; } - if (!defined('DISABLE_JQUERY_TABLEDND')) { - print ''."\n"; - } // jQuery jnotify if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && !defined('DISABLE_JQUERY_JNOTIFY')) { print ''."\n"; } + // Table drag and drop lines + if (empty($disableforlogin) && !defined('DISABLE_JQUERY_TABLEDND')) { + print ''."\n"; + } // Chart - if ((empty($conf->global->MAIN_JS_GRAPH) || $conf->global->MAIN_JS_GRAPH == 'chart') && !defined('DISABLE_JS_GRAPH')) { + if (empty($disableforlogin) && (empty($conf->global->MAIN_JS_GRAPH) || $conf->global->MAIN_JS_GRAPH == 'chart') && !defined('DISABLE_JS_GRAPH')) { print ''."\n"; } @@ -1694,7 +1695,7 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr if (!$disablejs && !empty($conf->use_javascript_ajax)) { // CKEditor - if ((!empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && !defined('DISABLE_CKEDITOR')) || defined('FORCE_CKEDITOR')) { + if (empty($disableforlogin) && (!empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && !defined('DISABLE_CKEDITOR')) || defined('FORCE_CKEDITOR')) { print ''."\n"; $pathckeditor = DOL_URL_ROOT.'/includes/ckeditor/ckeditor/'; $jsckeditor = 'ckeditor.js'; From 16aa562a131fdab3e309db9895eb949fea5c3df1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 29 Jan 2022 16:42:15 +0100 Subject: [PATCH 095/132] Debug v15 --- htdocs/societe/consumption.php | 12 +++++++----- htdocs/theme/eldy/global.inc.php | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index 596f9b6f3c6..fcb90df6c9b 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -79,8 +79,8 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $month = ''; } // Customer or supplier selected in drop box -$thirdTypeSelect = GETPOST("third_select_id"); -$type_element = GETPOST('type_element') ?GETPOST('type_element') : ''; +$thirdTypeSelect = GETPOST("third_select_id", 'az09'); +$type_element = GETPOST('type_element') ? GETPOST('type_element') : ''; // Load translation files required by the page $langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products")); @@ -441,9 +441,9 @@ if ($sql_select) { print ''; print ''; print ''; - print ''; // date + print ''; // date print $formother->select_month($month ? $month : -1, 'month', 1, 0, 'valignmiddle'); - $formother->select_year($year ? $year : -1, 'year', 1, 20, 1); + $formother->select_year($year ? $year : -1, 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly'); print ''; print ''; print ''; @@ -463,7 +463,7 @@ if ($sql_select) { // Titles with sort buttons print ''; print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left '); - print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center '); + print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left '); print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right '); @@ -500,6 +500,8 @@ if ($sql_select) { print $documentstaticline->getLibStatut(5); } elseif ($type_element == 'invoice') { print $documentstatic->getLibStatut(5, $objp->paid); + } elseif ($type_element == 'supplier_invoice') { + print $documentstatic->getLibStatut(5, $objp->paid); } else { print $documentstatic->getLibStatut(5); } diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index e347bf0395a..6b146b5b306 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -154,8 +154,9 @@ table.liste th.wrapcolumntitle.liste_titre:not(.maxwidthsearch), table.liste td. max-width: 100px; text-overflow: ellipsis; } -.liste_titre input[name=month_date_when], .liste_titre input[name=monthvalid], .liste_titre input[name=search_ordermonth], .liste_titre input[name=search_deliverymonth], +/*.liste_titre input[name=month_date_when], .liste_titre input[name=monthvalid], .liste_titre input[name=search_ordermonth], .liste_titre input[name=search_deliverymonth], .liste_titre input[name=search_smonth], .liste_titre input[name=search_month], .liste_titre input[name=search_emonth], .liste_titre input[name=smonth], .liste_titre input[name=month], .liste_titre select[name=month], +.liste_titre select[name=year], .liste_titre input[name=month_lim], .liste_titre input[name=month_start], .liste_titre input[name=month_end], .liste_titre input[name=month_create], .liste_titre input[name=search_month_lim], .liste_titre input[name=search_month_start], .liste_titre input[name=search_month_end], .liste_titre input[name=search_month_create], .liste_titre input[name=search_month_update], .liste_titre input[name=search_month_start], .liste_titre input[name=search_month_end], @@ -166,6 +167,7 @@ table.liste th.wrapcolumntitle.liste_titre:not(.maxwidthsearch), table.liste td. .liste_titre input[name=search_day_create], .liste_titre input[name=search_day_start], .liste_titre input[name=search_day_end], .liste_titre input[name=search_day_date_when], .liste_titre input[name=search_month_date_when], .liste_titre input[name=search_year_date_when], .liste_titre input[name=search_dtstartday], .liste_titre input[name=search_dtendday], .liste_titre input[name=search_dtstartmonth], .liste_titre input[name=search_dtendmonth], +*/ select#date_startday, select#date_startmonth, select#date_endday, select#date_endmonth, select#reday, select#remonth, input, input.flat, form.flat select, select, select.flat, .dataTables_length label select { border: none; From 23eda44ba7fb9becefc8ccd5f8d1cb68ec970d4d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 29 Jan 2022 16:42:15 +0100 Subject: [PATCH 096/132] Debug v15 --- htdocs/societe/consumption.php | 12 +++++++----- htdocs/theme/eldy/global.inc.php | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index 596f9b6f3c6..fcb90df6c9b 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -79,8 +79,8 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $month = ''; } // Customer or supplier selected in drop box -$thirdTypeSelect = GETPOST("third_select_id"); -$type_element = GETPOST('type_element') ?GETPOST('type_element') : ''; +$thirdTypeSelect = GETPOST("third_select_id", 'az09'); +$type_element = GETPOST('type_element') ? GETPOST('type_element') : ''; // Load translation files required by the page $langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products")); @@ -441,9 +441,9 @@ if ($sql_select) { print ''; print ''; print ''; - print ''; // date + print ''; // date print $formother->select_month($month ? $month : -1, 'month', 1, 0, 'valignmiddle'); - $formother->select_year($year ? $year : -1, 'year', 1, 20, 1); + $formother->select_year($year ? $year : -1, 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly'); print ''; print ''; print ''; @@ -463,7 +463,7 @@ if ($sql_select) { // Titles with sort buttons print ''; print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left '); - print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center '); + print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left '); print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right '); @@ -500,6 +500,8 @@ if ($sql_select) { print $documentstaticline->getLibStatut(5); } elseif ($type_element == 'invoice') { print $documentstatic->getLibStatut(5, $objp->paid); + } elseif ($type_element == 'supplier_invoice') { + print $documentstatic->getLibStatut(5, $objp->paid); } else { print $documentstatic->getLibStatut(5); } diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index bf1e9dc967e..8c315b7badf 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -154,8 +154,9 @@ table.liste th.wrapcolumntitle.liste_titre:not(.maxwidthsearch), table.liste td. max-width: 100px; text-overflow: ellipsis; } -.liste_titre input[name=month_date_when], .liste_titre input[name=monthvalid], .liste_titre input[name=search_ordermonth], .liste_titre input[name=search_deliverymonth], +/*.liste_titre input[name=month_date_when], .liste_titre input[name=monthvalid], .liste_titre input[name=search_ordermonth], .liste_titre input[name=search_deliverymonth], .liste_titre input[name=search_smonth], .liste_titre input[name=search_month], .liste_titre input[name=search_emonth], .liste_titre input[name=smonth], .liste_titre input[name=month], .liste_titre select[name=month], +.liste_titre select[name=year], .liste_titre input[name=month_lim], .liste_titre input[name=month_start], .liste_titre input[name=month_end], .liste_titre input[name=month_create], .liste_titre input[name=search_month_lim], .liste_titre input[name=search_month_start], .liste_titre input[name=search_month_end], .liste_titre input[name=search_month_create], .liste_titre input[name=search_month_update], .liste_titre input[name=search_month_start], .liste_titre input[name=search_month_end], @@ -166,6 +167,7 @@ table.liste th.wrapcolumntitle.liste_titre:not(.maxwidthsearch), table.liste td. .liste_titre input[name=search_day_create], .liste_titre input[name=search_day_start], .liste_titre input[name=search_day_end], .liste_titre input[name=search_day_date_when], .liste_titre input[name=search_month_date_when], .liste_titre input[name=search_year_date_when], .liste_titre input[name=search_dtstartday], .liste_titre input[name=search_dtendday], .liste_titre input[name=search_dtstartmonth], .liste_titre input[name=search_dtendmonth], +*/ select#date_startday, select#date_startmonth, select#date_endday, select#date_endmonth, select#reday, select#remonth, input, input.flat, form.flat select, select, select.flat, .dataTables_length label select { border: none; From 87f05067ca6bf53b0bd852aeafd9437908ccc708 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 29 Jan 2022 16:47:29 +0100 Subject: [PATCH 097/132] Fix rounding price --- htdocs/societe/consumption.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index fcb90df6c9b..3624f80187d 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -675,7 +675,7 @@ if ($sql_select) { print ''; print ''.$total_qty.''; print ''.price($total_ht).''; - print ''.price($total_ht / (empty($total_qty) ? 1 : $total_qty)).''; + print ''.price(price2num($total_ht / (empty($total_qty) ? 1 : $total_qty), 'MU')).''; print ""; print ''; From 5942bc57e666d2b659cad665230a4f454f83003c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 30 Jan 2022 01:03:07 +0100 Subject: [PATCH 098/132] Add DDOS protection --- dev/setup/apache/virtualhost | 145 +++++++++++++--------- htdocs/core/tpl/login.tpl.php | 7 +- htdocs/core/tpl/passwordforgotten.tpl.php | 6 + 3 files changed, 100 insertions(+), 58 deletions(-) diff --git a/dev/setup/apache/virtualhost b/dev/setup/apache/virtualhost index c3a2dff3e43..8c7682fe3d9 100644 --- a/dev/setup/apache/virtualhost +++ b/dev/setup/apache/virtualhost @@ -1,62 +1,93 @@ -#php_admin_value sendmail_path "/usr/sbin/sendmail -t -i" -#php_admin_value mail.force_extra_parameters "-f postmaster@mydomain.com" -php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f postmaster@mydomain.com" -php_admin_value open_basedir /tmp/:/home/../htdocs + #php_admin_value sendmail_path "/usr/sbin/sendmail -t -i" + #php_admin_value mail.force_extra_parameters "-f postmaster@mydomain.com" + php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f postmaster@mydomain.com" + php_admin_value open_basedir /tmp/:/home/.../htdocs:/home/.../dolibarr_documents: + + ServerName myvirtualalias + ServerAlias myvirtualalias + + UseCanonicalName On + + KeepAlive On + KeepAliveTimeout 5 + MaxKeepAliveRequests 20 + + AddDefaultCharset UTF-8 + + DocumentRoot "/home/.../htdocs" + + + AllowOverride None + Options -Indexes -MultiViews +FollowSymLinks -ExecCGI + Require all granted -ServerName myvirtualalias -ServerAlias myvirtualalias + # To restrict access by a HTTP basic auth + #AuthType Basic + #AuthName "Authenticate to backoffice" + #AuthUserFile /etc/apache2/.htpasswd + #require valid-user + + + # Leaving /public and /api, /dav, .well_known but also wrappers for document and viewimage accessible to everyone + + AuthType None + Require all granted + Satisfy any + + + AuthType None + Require all granted + Satisfy any + + + AuthType None + Require all granted + Satisfy any + + + AuthType None + Require all granted + Satisfy any + + + AuthType None + Require all granted + Satisfy any + -UseCanonicalName On - -AddDefaultCharset UTF-8 - -DocumentRoot "/home/.../htdocs" - - - AllowOverride None - Options -Indexes -MultiViews +FollowSymLinks -ExecCGI - Require all granted - - - - Deny from all - RemoveHandler .phtml .php .php3 .php4 .php5 .php6 .phps .cgi .exe .pl .asp .aspx .shtml .shtm .fcgi .fpl .jsp .htm .html .wml - AddType application/x-httpd-php-source .phtml .php .php3 .php4 .php5 .php6 .phps .cgi .exe .pl .asp .aspx .shtml .shtm .fcgi .fpl .jsp .htm .html .wml - - - -ErrorLog /var/log/apache2/myvirtualalias_error_log -TransferLog /var/log/apache2/myvirtualalias_access_log - -# Compress returned resources of type php pages, text file export, css and javascript -AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript - -AddType text/javascript .jgz -AddEncoding gzip .jgz -ExpiresActive On -ExpiresByType image/x-icon A2592000 -ExpiresByType image/gif A2592000 -ExpiresByType image/png A2592000 -ExpiresByType image/jpeg A2592000 -ExpiresByType text/css A2592000 -ExpiresByType text/javascript A2592000 -ExpiresByType application/x-javascript A2592000 -ExpiresByType application/javascript A2592000 - -SSLEngine On - -# A self-signed (snakeoil) certificate can be created by installing -# the ssl-cert package. See -# /usr/share/doc/apache2.2-common/README.Debian.gz for more info. -# If both key and certificate are stored in the same file, only the -# SSLCertificateFile directive is needed. -SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/cert.pem -SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem -SSLCertificateChainFile /etc/letsencrypt/live/www.mydomain.com/chain.pem - -#RewriteEngine on -#RewriteCond %{SERVER_PORT} ^80$ -#RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R] + + ErrorLog /var/log/apache2/myvirtualalias_error_log + TransferLog /var/log/apache2/myvirtualalias_access_log + + # Compress returned resources of type php pages, text file export, css and javascript + AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript + + AddType text/javascript .jgz + AddEncoding gzip .jgz + ExpiresActive On + ExpiresByType image/x-icon A2592000 + ExpiresByType image/gif A2592000 + ExpiresByType image/png A2592000 + ExpiresByType image/jpeg A2592000 + ExpiresByType text/css A2592000 + ExpiresByType text/javascript A2592000 + ExpiresByType application/x-javascript A2592000 + ExpiresByType application/javascript A2592000 + + SSLEngine On + + # A self-signed (snakeoil) certificate can be created by installing + # the ssl-cert package. See + # /usr/share/doc/apache2.2-common/README.Debian.gz for more info. + # If both key and certificate are stored in the same file, only the + # SSLCertificateFile directive is needed. + SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/cert.pem + SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem + SSLCertificateChainFile /etc/letsencrypt/live/www.mydomain.com/chain.pem + + #RewriteEngine on + #RewriteCond %{SERVER_PORT} ^80$ + #RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R] diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 93efffa687e..88c1428e8f9 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -30,11 +30,16 @@ if (empty($conf) || !is_object($conf)) { exit; } +// DDOS protection +$size = (int) $_SERVER['CONTENT_LENGTH']; +if ($size > 10000) { + http_response_code(413); + exit; +} require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - header('Cache-Control: Public, must-revalidate'); header("Content-type: text/html; charset=".$conf->file->character_set_client); diff --git a/htdocs/core/tpl/passwordforgotten.tpl.php b/htdocs/core/tpl/passwordforgotten.tpl.php index 97edcc1d3f2..b61ef22739a 100644 --- a/htdocs/core/tpl/passwordforgotten.tpl.php +++ b/htdocs/core/tpl/passwordforgotten.tpl.php @@ -27,6 +27,12 @@ if (empty($conf) || !is_object($conf)) { exit; } +// DDOS protection +$size = (int) $_SERVER['CONTENT_LENGTH']; +if ($size > 10000) { + http_response_code(413); + exit; +} require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; From 9e86e5ce93f35a358df79046882ebf2234640c85 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 30 Jan 2022 01:43:53 +0100 Subject: [PATCH 099/132] Fix creation of page --- htdocs/core/class/html.form.class.php | 50 +++++++-------- htdocs/website/index.php | 87 ++++++++++++++++----------- 2 files changed, 77 insertions(+), 60 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 88fca7b536a..5142bf00d4c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -7993,6 +7993,31 @@ class Form } } + // Try also magic suggest + $out .= ''."\n"; - if (is_array($array) && !empty($array)) { - if ($value_as_key) { - $array = array_combine($array, $array); - } - - if (!empty($array)) { - foreach ($array as $key => $value) { - $newval = ($translate ? $langs->trans($value) : $value); - $newval = ($key_in_label ? $key.' - '.$newval : $newval); - - $out .= '