From f273273129526bb0ecaccf2a42932a96166fa449 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 22 Dec 2020 06:57:55 +0100 Subject: [PATCH 01/51] FIX: Accountancy - Retire entire opening balance feature --- htdocs/accountancy/bookkeeping/balance.php | 46 +++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 29e56cd4233..961a012f396 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -77,7 +77,7 @@ $form = new Form($db); if (empty($search_date_start) && !GETPOSTISSET('formfilteraction')) { $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear "; - $sql .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'"; + $sql .= " WHERE date_start < '".$db->idate(dol_now())."' AND date_end > '".$db->idate(dol_now())."'"; $sql .= $db->plimit(1); $res = $db->query($sql); if ($res->num_rows > 0) { @@ -237,7 +237,7 @@ if ($action != 'export_csv') print ''; print ''; - print ''; print_liste_field_titre("AccountAccounting", $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); - print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); + // print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Balance", $_SERVER["PHP_SELF"], "", $param, "", 'class="right"', $sortfield, $sortorder); @@ -265,10 +265,13 @@ if ($action != 'export_csv') $total_credit = 0; $sous_total_debit = 0; $sous_total_credit = 0; - $total_opening_balance = 0; - $sous_total_opening_balance = 0; + // $total_opening_balance = 0; + // $sous_total_opening_balance = 0; $displayed_account = ""; + // TODO Debug - In French accounting, this functionality is dangerous, it takes all the entries and adds all the accounts + // without time and class limits (Class 6 and 7 accounts ???) and does not take into account the "a-nouveau" journal. + /* $sql = "SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t"; $sql .= " WHERE t.entity = ".$conf->entity; // Never do sharing into accounting features @@ -282,6 +285,7 @@ if ($action != 'export_csv') $arr = $resql->fetch_array(); $opening_balances["'".$arr['numero_compte']."'"] = $arr['opening_balance']; } + */ foreach ($object->lines as $line) { @@ -290,8 +294,8 @@ if ($action != 'export_csv') $total_credit += $line->credit; $description = $object->get_compte_desc($line->numero_compte); // Search description of the account $root_account_description = $object->get_compte_racine($line->numero_compte); - $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0; - $total_opening_balance += $opening_balance; + // $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0; + // $total_opening_balance += $opening_balance; if (empty($description)) { $link = ''.img_edit_add().''; } @@ -302,30 +306,34 @@ if ($action != 'export_csv') { // Display a sub-total per account if ($displayed_account != "") { - print ''; + print ''; + // print ''; + print ''; + print ''; + print ''; print "\n"; print ''; } // Show first line of a break print ''; - print ''; + print ''; print ''; $displayed_account = $root_account_description; $sous_total_debit = 0; $sous_total_credit = 0; - $sous_total_opening_balance = 0; + // $sous_total_opening_balance = 0; } // $object->get_compte_racine($line->numero_compte); print ''; print ''; - print ''; + // print ''; print ''; print ''; - print ''; + print ''; print ''; print "\n"; @@ -333,14 +341,22 @@ if ($action != 'export_csv') // Records the sub-total $sous_total_debit += $line->debit; $sous_total_credit += $line->credit; - $sous_total_opening_balance += $opening_balance; + // $sous_total_opening_balance += $opening_balance; } - print ''; + print ''; + // print ''; + print ''; + print ''; + print ''; print "\n"; print ''; - print ''; + print ''; + // print ''; + print ''; + print ''; + print ''; print "\n"; print ''; From 26791714cee70a00bc05243c49645c0d47ee4cff Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 28 Dec 2020 03:07:33 +0100 Subject: [PATCH 02/51] Fix : Introduce constant ACCOUNTANCY_SHOW_OPENING_BALANCE --- htdocs/accountancy/bookkeeping/balance.php | 76 +++++++++++++--------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 961a012f396..b71c633b1e5 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -237,7 +237,8 @@ if ($action != 'export_csv') print '
'; + print ''; print $langs->trans('From'); print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, ''); print ' '; @@ -254,7 +254,7 @@ if ($action != 'export_csv') print '
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_credit - $sous_total_debit)).'
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_credit - $sous_total_debit)).' 
'.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').''.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').'
'.length_accountg($line->numero_compte).''.$description.''.price($opening_balance).''.price($opening_balance).''.price($line->debit).''.price($line->credit).''.price($opening_balance + $line->debit - $line->credit).''.price(/*$opening_balance +*/ $line->debit - $line->credit).''.$link; print '
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit, 'MT')).'
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num(/*$sous_total_opening_balance +*/ $sous_total_debit - $sous_total_credit, 'MT')).' 
'.$langs->trans("AccountBalance").':'.price($total_opening_balance).''.price($total_debit).''.price($total_credit).''.price(price2num($total_opening_balance + $total_debit - $total_credit, 'MT')).'
'.$langs->trans("AccountBalance").':'.price($total_opening_balance).''.price($total_debit).''.price($total_credit).''.price(price2num(/*$total_opening_balance +*/ $total_debit - $total_credit, 'MT')).' 
'; print ''; - print ''; print_liste_field_titre("AccountAccounting", $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); - // print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Balance", $_SERVER["PHP_SELF"], "", $param, "", 'class="right"', $sortfield, $sortorder); @@ -265,27 +266,29 @@ if ($action != 'export_csv') $total_credit = 0; $sous_total_debit = 0; $sous_total_credit = 0; - // $total_opening_balance = 0; - // $sous_total_opening_balance = 0; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + $total_opening_balance = 0; + $sous_total_opening_balance = 0; + } $displayed_account = ""; // TODO Debug - In French accounting, this functionality is dangerous, it takes all the entries and adds all the accounts // without time and class limits (Class 6 and 7 accounts ???) and does not take into account the "a-nouveau" journal. - /* - $sql = "SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t"; - $sql .= " WHERE t.entity = ".$conf->entity; // Never do sharing into accounting features - $sql .= " AND t.doc_date < '".$db->idate($search_date_start)."'"; - $sql .= " GROUP BY t.numero_compte"; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + $sql = "SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; + $sql .= " WHERE t.entity = " . $conf->entity; // Never do sharing into accounting features + $sql .= " AND t.doc_date < '" . $db->idate($search_date_start) . "'"; + $sql .= " GROUP BY t.numero_compte"; - $resql = $db->query($sql); - $nrows = $resql->num_rows; - $opening_balances = array(); - for ($i = 0; $i < $nrows; $i++) { - $arr = $resql->fetch_array(); - $opening_balances["'".$arr['numero_compte']."'"] = $arr['opening_balance']; + $resql = $db->query($sql); + $nrows = $resql->num_rows; + $opening_balances = array(); + for ($i = 0; $i < $nrows; $i++) { + $arr = $resql->fetch_array(); + $opening_balances["'" . $arr['numero_compte'] . "'"] = $arr['opening_balance']; + } } - */ foreach ($object->lines as $line) { @@ -294,8 +297,10 @@ if ($action != 'export_csv') $total_credit += $line->credit; $description = $object->get_compte_desc($line->numero_compte); // Search description of the account $root_account_description = $object->get_compte_racine($line->numero_compte); - // $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0; - // $total_opening_balance += $opening_balance; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0; + $total_opening_balance += $opening_balance; + } if (empty($description)) { $link = ''.img_edit_add().''; } @@ -307,7 +312,7 @@ if ($action != 'export_csv') // Display a sub-total per account if ($displayed_account != "") { print ''; - // print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''; print ''; print ''; print ''; @@ -317,23 +322,28 @@ if ($action != 'export_csv') // Show first line of a break print ''; - print ''; + $colspan = (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE) ? 7 : 6); + print ''; print ''; $displayed_account = $root_account_description; $sous_total_debit = 0; $sous_total_credit = 0; - // $sous_total_opening_balance = 0; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) $sous_total_opening_balance = 0; } // $object->get_compte_racine($line->numero_compte); print ''; print ''; - // print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''; print ''; print ''; - print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + print ''; + } else { + print ''; + } print ''; print "\n"; @@ -341,22 +351,30 @@ if ($action != 'export_csv') // Records the sub-total $sous_total_debit += $line->debit; $sous_total_credit += $line->credit; - // $sous_total_opening_balance += $opening_balance; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) $sous_total_opening_balance += $opening_balance; } print ''; - // print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''; print ''; print ''; - print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + print ''; + } else { + print ''; + } print "\n"; print ''; print ''; - // print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''; print ''; print ''; - print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + print ''; + } else { + print ''; + } print "\n"; print ''; From d9a2e2e402edfac75175e6c1e00e68980286620e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 02:06:42 +0100 Subject: [PATCH 03/51] Responsive --- htdocs/admin/modules.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index e9984316394..4316130e739 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -475,24 +475,22 @@ print load_fiche_titre($langs->trans("ModulesSetup"), '', 'title_setup'); if ($mode == 'common' || $mode == 'commonkanban') { $desc = $langs->trans("ModulesDesc", '{picto}'); $desc = str_replace('{picto}', img_picto('', 'switch_off'), $desc); - print ''.$desc."
\n"; + print ''.$desc."

\n"; } if ($mode == 'marketplace') { - print ''.$langs->trans("ModulesMarketPlaceDesc")."
\n"; + print ''.$langs->trans("ModulesMarketPlaceDesc")."

\n"; } if ($mode == 'deploy') { - print ''.$langs->trans("ModulesDeployDesc", $langs->transnoentitiesnoconv("AvailableModules"))."
\n"; + print ''.$langs->trans("ModulesDeployDesc", $langs->transnoentitiesnoconv("AvailableModules"))."

\n"; } if ($mode == 'develop') { - print ''.$langs->trans("ModulesDevelopDesc")."
\n"; + print ''.$langs->trans("ModulesDevelopDesc")."

\n"; } + $head = modules_prepare_head(); -print "
\n"; - - if ($mode == 'common' || $mode == 'commonkanban') { dol_set_focus('#search_keyword'); From e07486b6265423d0bb59cdd1450312b81e22f64c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 02:20:10 +0100 Subject: [PATCH 04/51] Fix columns of download of list of targets of emailing --- htdocs/comm/mailing/cibles.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 6d9587961c6..bcf1e9c1e3b 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -131,8 +131,8 @@ if (GETPOST('exportcsv', 'int')) header('Content-Disposition: attachment;filename='.$completefilename); // List of selected targets - $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.tms,"; - $sql .= " mc.source_url, mc.source_id, mc.source_type, mc.error_text"; + $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut as status, mc.date_envoi, mc.tms,"; + $sql .= " mc.source_id, mc.source_type, mc.error_text"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; $sql .= " WHERE mc.fk_mailing=".$object->id; $sql .= $db->order($sortfield, $sortorder); @@ -146,16 +146,16 @@ if (GETPOST('exportcsv', 'int')) while ($obj = $db->fetch_object($resql)) { print $obj->rowid.$sep; - print $obj->lastname.$sep; - print $obj->firstname.$sep; + print '"'.$obj->lastname.'"'.$sep; + print '"'.$obj->firstname.'"'.$sep; print $obj->email.$sep; print $obj->other.$sep; - print $obj->date_envoi.$sep; print $obj->tms.$sep; - print $obj->source_url.$sep; - print $obj->source_id.$sep; print $obj->source_type.$sep; - print $obj->error_text.$sep; + print $obj->source_id.$sep; + print $obj->date_envoi.$sep; + print $obj->status.$sep; + print '"'.$obj->error_text.'"'.$sep; print "\n"; } From 7b93c34c0f22e1a3a679a6e846b812ce87a3b3e5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 03:48:11 +0100 Subject: [PATCH 05/51] Fix phpunits --- htdocs/core/lib/functions.lib.php | 2 +- .../modules/mailings/xinputfile.modules.php | 1 - htdocs/includes/nusoap/lib/nusoap.php | 2 +- test/phpunit/FunctionsLibTest.php | 29 +++++++++++++++++++ test/phpunit/WebservicesInvoicesTest.php | 9 ++++-- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 33a09f541c6..909f786beec 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3032,7 +3032,7 @@ function dol_print_address($address, $htmlid, $element, $id, $noprint = 0, $char /** * Return true if email syntax is ok. * - * @param string $address email (Ex: "toto@examle.com", "John Do ") + * @param string $address email (Ex: "toto@examle.com". Long form "John Do " will be false) * @param int $acceptsupervisorkey If 1, the special string '__SUPERVISOREMAIL__' is also accepted as valid * @return boolean true if email syntax is OK, false if KO or empty string * @see isValidMXRecord() diff --git a/htdocs/core/modules/mailings/xinputfile.modules.php b/htdocs/core/modules/mailings/xinputfile.modules.php index afc691f3e2e..a31d1c41483 100644 --- a/htdocs/core/modules/mailings/xinputfile.modules.php +++ b/htdocs/core/modules/mailings/xinputfile.modules.php @@ -162,7 +162,6 @@ class mailing_xinputfile extends MailingTargets if (!empty($buffer)) { //print 'xx'.dol_strlen($buffer).empty($buffer)."
\n"; - $id = $cpt; if (isValidEMail($email)) { if ($old <> $email) diff --git a/htdocs/includes/nusoap/lib/nusoap.php b/htdocs/includes/nusoap/lib/nusoap.php index 459f4aeb7b6..7e0ebd94da4 100644 --- a/htdocs/includes/nusoap/lib/nusoap.php +++ b/htdocs/includes/nusoap/lib/nusoap.php @@ -6125,7 +6125,7 @@ class wsdl extends nusoap_base { $rows = sizeof($value); $contents = ''; foreach($value as $k => $v) { - $this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]"); + $this->debug("serializing array element: $k of type: ".$typeDef['arrayType']); //if (strpos($typeDef['arrayType'], ':') ) { if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) { $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 7cbb6af5955..8dc903642e0 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -131,6 +131,35 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; } + /** + * testIsValidEmail + * + * @return void + */ + public function testIsValidEmail() + { + // Nb of line is same than entry text + + $input="bidon@bademail"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertFalse($result, 'Check isValidEmail '.$input); + + $input="test@yahoo.com"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'Check isValidEmail '.$input); + + $input="The name of sender "; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertFalse($result, 'Check isValidEmail '.$input); + + $input="1234.abcdefg@domainame.com.br"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'Check isValidEmail '.$input); + } /** * testIsValidMXRecord diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index beb3e844809..ca9d827f2b8 100644 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -61,6 +61,9 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase protected $ns = 'http://www.dolibarr.org/ns/'; + protected $pass = 'admin'; + + /** * Constructor * We save global variables into local variables @@ -248,7 +251,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, 'sourceapplication'=>'DEMO', 'login'=>'admin', - 'password'=>'admin', + 'password'=>$this->pass, 'entity'=>''); // Test URL @@ -304,7 +307,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, 'sourceapplication'=>'DEMO', 'login'=>'admin', - 'password'=>'admin', + 'password'=>$this->pass, 'entity'=>''); // Test URL @@ -403,7 +406,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, 'sourceapplication'=>'DEMO', 'login'=>'admin', - 'password'=>'admin', + 'password'=>$this->pass, 'entity'=>''); // Test URL From af41c068222099e6576c75e847951603487c212e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 04:27:16 +0100 Subject: [PATCH 06/51] Fix warnings --- htdocs/categories/class/categorie.class.php | 2 ++ htdocs/core/lib/functions.lib.php | 4 ++-- htdocs/core/lib/functions2.lib.php | 2 +- htdocs/core/modules/societe/mod_codeclient_elephant.php | 4 ++-- htdocs/core/modules/societe/mod_codecompta_digitaria.php | 5 +++-- htdocs/societe/card.php | 6 +++--- htdocs/user/class/user.class.php | 1 + 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 8e2f07ec4fc..7f8e415e4b1 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1146,6 +1146,8 @@ class Categorie extends CommonObject // First build full array $motherof //$this->load_motherof(); // Disabled because already done by caller of build_path_from_id_categ + // $this->cats[$id_categ] is supposed to be already an array. We just want to complete it with property fullpath and fulllabel + // Define fullpath and fulllabel $this->cats[$id_categ]['fullpath'] = '_'.$id_categ; $this->cats[$id_categ]['fulllabel'] = $this->cats[$id_categ]['label']; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 909f786beec..a156f35292e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7123,9 +7123,9 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen foreach (array_keys($array) as $key) { if (is_object($array[$key])) { - $temp[$key] = $array[$key]->$index; + $temp[$key] = empty($array[$key]->$index) ? 0 : $array[$key]->$index; } else { - $temp[$key] = $array[$key][$index]; + $temp[$key] = empty($array[$key][$index]) ? 0 : $array[$key][$index]; } } diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 8391c6aab06..a77f38f8f66 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1252,7 +1252,7 @@ function check_value($mask, $value) //print "masktri=".$masktri." maskcounter=".$maskcounter." maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode." maskraz=".$maskraz." maskoffset=".$maskoffset."
\n"; if (function_exists('mb_strrpos')) { - $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 'UTF-8'); + $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0, 'UTF-8'); } else { $posnumstart = strrpos($maskwithnocode, $maskcounter); diff --git a/htdocs/core/modules/societe/mod_codeclient_elephant.php b/htdocs/core/modules/societe/mod_codeclient_elephant.php index 9b870bd5dd2..18947732b16 100644 --- a/htdocs/core/modules/societe/mod_codeclient_elephant.php +++ b/htdocs/core/modules/societe/mod_codeclient_elephant.php @@ -212,8 +212,8 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode // Get Mask value $mask = ''; - if ($type == 0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; - if ($type == 1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; + if ($type == 0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER) ? '' : $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; + if ($type == 1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER) ? '' : $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; if (!$mask) { $this->error = 'NotConfigured'; diff --git a/htdocs/core/modules/societe/mod_codecompta_digitaria.php b/htdocs/core/modules/societe/mod_codecompta_digitaria.php index 961fa1a4e73..ea25a480d45 100644 --- a/htdocs/core/modules/societe/mod_codecompta_digitaria.php +++ b/htdocs/core/modules/societe/mod_codecompta_digitaria.php @@ -157,6 +157,8 @@ class mod_codecompta_digitaria extends ModeleAccountancyCode $i = 0; $this->code = ''; + $disponibility = 0; + if (is_object($societe)) { dol_syslog("mod_codecompta_digitaria::get_code search code for type=".$type." & company=".(!empty($societe->name) ? $societe->name : '')); @@ -216,8 +218,7 @@ class mod_codecompta_digitaria extends ModeleAccountancyCode } } - if ($disponibility == 0) - { + if ($disponibility == 0) { return 0; // return ok } else { return -1; // return ko diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 0fc33232c5d..7fccdf994b9 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -109,7 +109,7 @@ if ($object->id > 0) { $permissiontoread = $user->rights->societe->lire; $permissiontoadd = $user->rights->societe->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php -$permissiontodelete = $user->rights->societe->delete || ($permissiontoadd && isset($object->status) && $object->status == 0); +$permissiontodelete = $user->rights->societe->supprimer || ($permissiontoadd && isset($object->status) && $object->status == 0); $permissionnote = $user->rights->societe->creer; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->societe->creer; // Used by the include of actions_dellink.inc.php $upload_dir = $conf->societe->multidir_output[isset($object->entity) ? $object->entity : 1]; @@ -1355,7 +1355,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print 'browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_phoning_fax').' '; // Email / Web - print '
'; + print ''; print ''; print ''; print ''; @@ -1366,7 +1366,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; print ''; print ''; print ''; } elseif (!empty($object->socialnetworks[$key])) { diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index eb92bd51eb9..98e70cf66b7 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2418,6 +2418,7 @@ class User extends CommonObject } $result = ''; $label = ''; + $companylink = ''; if (!empty($this->photo)) { $label .= '
'; From c3326a0963dccb3224d30c841ca4509d1483fc2c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 04:30:37 +0100 Subject: [PATCH 07/51] FIX Creation of thirdparty when setup is empty --- htdocs/societe/class/societe.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 35b52243804..3842a8cd2a9 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -940,7 +940,7 @@ class Societe extends CommonObject if ($this->client) { $rescode = $this->check_codeclient(); - if ($rescode <> 0) + if ($rescode != 0 && $rescode != -5) { if ($rescode == -1) { @@ -965,7 +965,7 @@ class Societe extends CommonObject if ($this->fournisseur) { $rescode = $this->check_codefournisseur(); - if ($rescode <> 0) + if ($rescode != 0 && $rescode != -5) { if ($rescode == -1) { @@ -979,7 +979,7 @@ class Societe extends CommonObject { $this->errors[] = 'ErrorSupplierCodeAlreadyUsed'; } - elseif ($rescode == -5) + elseif ($rescode == -4) { $this->errors[] = 'ErrorPrefixRequired'; } @@ -3057,6 +3057,8 @@ class Societe extends CommonObject * -2 ErrorCustomerCodeRequired * -3 ErrorCustomerCodeAlreadyUsed * -4 ErrorPrefixRequired + * -5 NotConfigured - Setup empty so any value may be ok or not + * -6 Other (see this->error) */ public function check_codefournisseur() { From f4986570716bb6e43ab7489483810263c62f7c01 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 04:44:48 +0100 Subject: [PATCH 08/51] Fix warning --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 993dd900a27..69b934aeeff 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -863,7 +863,7 @@ class Societe extends CommonObject $this->db->commit(); return $this->id; } else { - dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',', $this->errors), LOG_ERR); + dol_syslog(get_class($this)."::Create echec update ".$this->error.(empty($this->errors) ? '' : ' '.join(',', $this->errors)), LOG_ERR); $this->db->rollback(); return -4; } From abca44be0d94c1096d80663120a535b80e3fea10 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 04:52:47 +0100 Subject: [PATCH 09/51] More logs --- test/phpunit/WebservicesInvoicesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index ca9d827f2b8..6bedda43fa4 100644 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -275,7 +275,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase print "\n"; } - print __METHOD__." result=".$result['result']['result_code']."\n"; + print __METHOD__." result=".$result['result']['result_code']." ".$result['result']['result_label']."\n"; $this->assertEquals('OK', $result['result']['result_code']); $this->assertEquals('ref-phpunit-2', $result['ref_ext']); From ae7d3abdc54031f31683ef3a8c2e1ca1d789c3b0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 05:00:51 +0100 Subject: [PATCH 10/51] css --- htdocs/theme/eldy/global.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index e6991388ad0..1c807b7b2b1 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -35,7 +35,7 @@ --oddevencolor: #202020; --colorboxstatsborder: #e0e0e0; --dolgraphbg: rgba(255,255,255,0); - --fieldrequiredcolor: #804000; + --fieldrequiredcolor: #700040; --colortextbacktab: #; --colorboxiconbg: #eee; --refidnocolor:#444; From 4267828ee6f1c80a46a190fcf892b6ab0ee44c1b Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Tue, 29 Dec 2020 14:47:16 +0100 Subject: [PATCH 11/51] FIX add line php warning when no customer relative discount history. --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 69b934aeeff..13290850da3 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1634,7 +1634,7 @@ class Societe extends CommonObject $this->prefix_comm = $obj->prefix_comm; - $this->remise_percent = price2num($obj->remise_client); // 0.000000 must be 0 + $this->remise_percent = $obj->remise_client ? price2num($obj->remise_client) : 0; // 0.000000 must be 0 $this->remise_supplier_percent = $obj->remise_supplier; $this->mode_reglement_id = $obj->mode_reglement; $this->cond_reglement_id = $obj->cond_reglement; From 87da0a276d236529052b071aed3bd0d5eb9ef279 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 16:13:03 +0100 Subject: [PATCH 12/51] Doc --- SECURITY.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 6dc6e0f33b5..08ca64e4a4c 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -55,8 +55,7 @@ ONLY vulnerabilities discovered, when the following setup on test platform is us * $dolibarr_nocsrfcheck must be kept to the value 0 into conf.php (this is the default value) * $dolibarr_main_force_https must be set to something else than 0. * The constant MAIN_SECURITY_CSRF_WITH_TOKEN must be set to 1 into backoffice menu Home - Setup - Other (this protection should be set to 1 soon by default) -* The module DebugBar must NOT be enabled (by default, this module is not enabled. This is a developer tool) -* The module ModuleBuilder must NOT be enabled (by default, this module is not enabled. This is a developer tool) +* The module DebugBar and ModuleBuilder must NOT be enabled (by default, this module is not enabled. This is a developer tool) * ONLY security reports on modules provided by default and with the "stable" status are valid (troubles into "experimental", "developement" or external modules are not valid vulnerabilities). * The root of web server must link to htdocs and the documents directory must be outside of the web server root (this is the default when using the default installer but may differs with external installer). * The web server setup must be done so only the documents directory is in write mode. The root directory called htdocs must be readonly. From 620a088827324709301b50d4b42d13c48eedfd3e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 16:33:58 +0100 Subject: [PATCH 13/51] Fix warning --- htdocs/webservices/server_invoice.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 15db912ff47..7397b8ca2a6 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -777,12 +777,11 @@ function updateInvoice($authentication, $invoice) $object->generateDocument($object->model_pdf, $outputlangs); } } - if ($invoice['status'] == Facture::STATUS_CLOSED) - { - $result = $object->set_paid($fuser, $invoice->close_code, $invoice->close_note); + if ($invoice['status'] == Facture::STATUS_CLOSED) { + $result = $object->set_paid($fuser, $invoice['close_code'], $invoice['close_note']); } if ($invoice['status'] == Facture::STATUS_ABANDONED) - $result = $object->set_canceled($fuser, $invoice->close_code, $invoice->close_note); + $result = $object->set_canceled($fuser, $invoice['close_code'], $invoice['close_note']); } } From e4c3499cad6b8f9133bc3ef2969a1421f9c92baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 28 Dec 2020 21:08:56 +0100 Subject: [PATCH 14/51] remove warnings Conflicts: htdocs/societe/class/societe.class.php --- htdocs/societe/class/societe.class.php | 1315 +++++++++++++----------- 1 file changed, 701 insertions(+), 614 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 69b934aeeff..95edf32f082 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -784,17 +784,24 @@ class Societe extends CommonObject $error = 0; // Clean parameters - if (empty($this->status)) $this->status = 0; + if (empty($this->status)) { + $this->status = 0; + } $this->name = $this->name ?trim($this->name) : trim($this->nom); $this->setUpperOrLowerCase(); $this->nom = $this->name; // For backward compatibility - if (empty($this->client)) $this->client = 0; - if (empty($this->fournisseur)) $this->fournisseur = 0; + if (empty($this->client)) { + $this->client = 0; + } + if (empty($this->fournisseur)) { + $this->fournisseur = 0; + } $this->import_key = trim($this->import_key); - if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - if (empty($this->fk_multicurrency)) - { + if (!empty($this->multicurrency_code)) { + $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + } + if (empty($this->fk_multicurrency)) { $this->multicurrency_code = ''; $this->fk_multicurrency = 0; } @@ -806,15 +813,18 @@ class Societe extends CommonObject $this->db->begin(); // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) - if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this, 0); - if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1); + if ($this->code_client == -1 || $this->code_client === 'auto') { + $this->get_codeclient($this, 0); + } + if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') { + $this->get_codefournisseur($this, 1); + } // Check more parameters (including mandatory setup // If error, this->errors[] is filled $result = $this->verify(); - if ($result >= 0) - { + if ($result >= 0) { $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)"; @@ -832,33 +842,32 @@ class Societe extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe"); $ret = $this->update($this->id, $user, 0, 1, 1, 'add'); // Ajout du commercial affecte - if ($this->commercial_id != '' && $this->commercial_id != -1) - { + if ($this->commercial_id != '' && $this->commercial_id != -1) { $this->add_commercial($user, $this->commercial_id); } // si un commercial cree un client il lui est affecte automatiquement - elseif (empty($user->rights->societe->client->voir)) - { + elseif (empty($user->rights->societe->client->voir)) { $this->add_commercial($user, $user->id); } - if ($ret >= 0) - { + if ($ret >= 0) { // Call trigger $result = $this->call_trigger('COMPANY_CREATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers - } else $error++; + } else { + $error++; + } - if (!$error) - { + if (!$error) { dol_syslog(get_class($this)."::Create success id=".$this->id); $this->db->commit(); return $this->id; @@ -868,8 +877,7 @@ class Societe extends CommonObject return -4; } } else { - if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...) $result = -1; } else { @@ -916,8 +924,7 @@ class Societe extends CommonObject $contact->phone_pro = $this->phone; $result = $contact->create($user); - if ($result < 0) - { + if ($result < 0) { $this->error = $contact->error; $this->errors = $contact->errors; dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR); @@ -943,17 +950,14 @@ class Societe extends CommonObject $this->name = trim($this->name); $this->nom = $this->name; // For backward compatibility - if (!$this->name) - { + if (!$this->name) { $this->errors[] = 'ErrorBadThirdPartyName'; $result = -2; } - if ($this->client) - { + if ($this->client) { $rescode = $this->check_codeclient(); - if ($rescode != 0 && $rescode != -5) - { + if ($rescode != 0 && $rescode != -5) { if ($rescode == -1) { $this->errors[] = 'ErrorBadCustomerCodeSyntax'; } elseif ($rescode == -2) { @@ -970,11 +974,9 @@ class Societe extends CommonObject } } - if ($this->fournisseur) - { + if ($this->fournisseur) { $rescode = $this->check_codefournisseur(); - if ($rescode != 0 && $rescode != -5) - { + if ($rescode != 0 && $rescode != -5) { if ($rescode == -1) { $this->errors[] = 'ErrorBadSupplierCodeSyntax'; } elseif ($rescode == -2) { @@ -992,22 +994,17 @@ class Societe extends CommonObject // Check for duplicate or mandatory fields defined into setup $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL'); - foreach ($array_to_check as $key) - { + foreach ($array_to_check as $key) { $keymin = strtolower($key); $i = (int) preg_replace('/[^0-9]/', '', $key); $vallabel = $this->$keymin; - if ($i > 0) - { - if ($this->isACompany()) - { + if ($i > 0) { + if ($this->isACompany()) { // Check for mandatory prof id (but only if country is same than ours) - if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) - { + if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) { $idprof_mandatory = 'SOCIETE_'.$key.'_MANDATORY'; - if (!$vallabel && !empty($conf->global->$idprof_mandatory)) - { + if (!$vallabel && !empty($conf->global->$idprof_mandatory)) { $langs->load("errors"); $error++; $this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')'; @@ -1016,10 +1013,8 @@ class Societe extends CommonObject } // Check for unicity on profid - if (!$error && $vallabel && $this->id_prof_verifiable($i)) - { - if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) - { + if (!$error && $vallabel && $this->id_prof_verifiable($i)) { + if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { $langs->load("errors"); $error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; @@ -1028,21 +1023,17 @@ class Societe extends CommonObject } else { //var_dump($conf->global->SOCIETE_EMAIL_UNIQUE); //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY); - if ($key == 'EMAIL') - { + if ($key == 'EMAIL') { // Check for mandatory - if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) - { + if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) { $langs->load("errors"); $error++; $this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')'; } // Check for unicity - if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) - { - if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) - { + if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) { + if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { $langs->load("errors"); $error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; } @@ -1051,7 +1042,9 @@ class Societe extends CommonObject } } - if ($error) $result = -4; + if ($error) { + $result = -4; + } return $result; } @@ -1074,7 +1067,9 @@ class Societe extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - if (empty($id)) $id = $this->id; + if (empty($id)) { + $id = $this->id; + } $error = 0; @@ -1118,11 +1113,14 @@ class Societe extends CommonObject $this->tva_assuj = trim($this->tva_assuj); $this->tva_intra = dol_sanitizeFileName($this->tva_intra, ''); - if (empty($this->status)) $this->status = 0; + if (empty($this->status)) { + $this->status = 0; + } - if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - if (empty($this->fk_multicurrency)) - { + if (!empty($this->multicurrency_code)) { + $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + } + if (empty($this->fk_multicurrency)) { $this->multicurrency_code = ''; $this->fk_multicurrency = 0; } @@ -1134,8 +1132,12 @@ class Societe extends CommonObject $this->localtax1_value = trim($this->localtax1_value); $this->localtax2_value = trim($this->localtax2_value); - if ($this->capital != '') $this->capital = price2num(trim($this->capital)); - if (!is_numeric($this->capital)) $this->capital = ''; // '' = undef + if ($this->capital != '') { + $this->capital = price2num(trim($this->capital)); + } + if (!is_numeric($this->capital)) { + $this->capital = ''; // '' = undef + } $this->effectif_id = trim($this->effectif_id); $this->forme_juridique_code = trim($this->forme_juridique_code); @@ -1144,41 +1146,44 @@ class Societe extends CommonObject $this->barcode = trim($this->barcode); // For automatic creation - if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this, 0); - if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1); + if ($this->code_client == -1 || $this->code_client === 'auto') { + $this->get_codeclient($this, 0); + } + if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') { + $this->get_codefournisseur($this, 1); + } $this->code_compta = trim($this->code_compta); $this->code_compta_fournisseur = trim($this->code_compta_fournisseur); // Check parameters. More tests are done later in the ->verify() - if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) - { + if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) { $langs->load("errors"); $this->error = $langs->trans("BadValueForParameterClientOrSupplier"); return -1; } $customer = false; - if (!empty($allowmodcodeclient) && !empty($this->client)) - { + if (!empty($allowmodcodeclient) && !empty($this->client)) { // Attention get_codecompta peut modifier le code suivant le module utilise - if (empty($this->code_compta)) - { + if (empty($this->code_compta)) { $ret = $this->get_codecompta('customer'); - if ($ret < 0) return -1; + if ($ret < 0) { + return -1; + } } $customer = true; } $supplier = false; - if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) - { + if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) { // Attention get_codecompta peut modifier le code suivant le module utilise - if ($this->code_compta_fournisseur == "") - { + if ($this->code_compta_fournisseur == "") { $ret = $this->get_codecompta('supplier'); - if ($ret < 0) return -1; + if ($ret < 0) { + return -1; + } } $supplier = true; @@ -1197,33 +1202,31 @@ class Societe extends CommonObject // Check name is required and codes are ok or unique. // If error, this->errors[] is filled $result = 0; - if ($action != 'add' && $action != 'merge') - { + if ($action != 'add' && $action != 'merge') { // We don't check when update called during a create because verify was already done. // For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error $result = $this->verify(); // If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update // So we can update record that were using and old numbering rule. - if (is_array($this->errors)) - { - if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) - { - if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message + if (is_array($this->errors)) { + if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) { + if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) { + unset($this->errors[$key]); // Remove error message + } } - if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) - { - if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message + if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) { + if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) { + unset($this->errors[$key]); // Remove error message + } } - if (empty($this->errors)) // If there is no more error, we can make like if there is no error at all - { + if (empty($this->errors)) { // If there is no more error, we can make like if there is no error at all $result = 0; } } } - if ($result >= 0) - { + if ($result >= 0) { dol_syslog(get_class($this)."::update verify ok or not done"); $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET "; @@ -1264,29 +1267,32 @@ class Societe extends CommonObject // Local taxes $sql .= ",localtax1_assuj = ".($this->localtax1_assuj != '' ? "'".$this->db->escape($this->localtax1_assuj)."'" : "null"); $sql .= ",localtax2_assuj = ".($this->localtax2_assuj != '' ? "'".$this->db->escape($this->localtax2_assuj)."'" : "null"); - if ($this->localtax1_assuj == 1) - { - if ($this->localtax1_value != '') - { + if ($this->localtax1_assuj == 1) { + if ($this->localtax1_value != '') { $sql .= ",localtax1_value =".$this->localtax1_value; - } else $sql .= ",localtax1_value =0.000"; - } else $sql .= ",localtax1_value =0.000"; + } else { + $sql .= ",localtax1_value =0.000"; + } + } else { + $sql .= ",localtax1_value =0.000"; + } - if ($this->localtax2_assuj == 1) - { - if ($this->localtax2_value != '') - { + if ($this->localtax2_assuj == 1) { + if ($this->localtax2_value != '') { $sql .= ",localtax2_value =".$this->localtax2_value; - } else $sql .= ",localtax2_value =0.000"; - } else $sql .= ",localtax2_value =0.000"; + } else { + $sql .= ",localtax2_value =0.000"; + } + } else { + $sql .= ",localtax2_value =0.000"; + } $sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital); $sql .= ",prefix_comm = ".(!empty($this->prefix_comm) ? "'".$this->db->escape($this->prefix_comm)."'" : "null"); $sql .= ",fk_effectif = ".(!empty($this->effectif_id) ? "'".$this->db->escape($this->effectif_id)."'" : "null"); - if (isset($this->stcomm_id)) - { + if (isset($this->stcomm_id)) { $sql .= ",fk_stcomm=".(!empty($this->stcomm_id) ? $this->stcomm_id : "0"); } $sql .= ",fk_typent = ".(!empty($this->typent_id) ? "'".$this->db->escape($this->typent_id)."'" : "0"); @@ -1319,14 +1325,12 @@ class Societe extends CommonObject $sql .= ", fk_incoterms = ".$this->fk_incoterms; $sql .= ", location_incoterms = ".(!empty($this->location_incoterms) ? "'".$this->db->escape($this->location_incoterms)."'" : "null"); - if ($customer) - { + if ($customer) { $sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null"); $sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null"); } - if ($supplier) - { + if ($supplier) { $sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null"); $sql .= ", code_compta_fournisseur = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); } @@ -1337,17 +1341,13 @@ class Societe extends CommonObject $sql .= " WHERE rowid = ".(int) $id; $resql = $this->db->query($sql); - if ($resql) - { - if (is_object($this->oldcopy)) // If we have information on old values - { - if ($this->oldcopy->country_id != $this->country_id) - { + if ($resql) { + if (is_object($this->oldcopy)) { // If we have information on old values + if ($this->oldcopy->country_id != $this->country_id) { unset($this->country_code); unset($this->country); } - if ($this->oldcopy->state_id != $this->state_id) - { + if ($this->oldcopy->state_id != $this->state_id) { unset($this->state_code); unset($this->state); } @@ -1360,11 +1360,9 @@ class Societe extends CommonObject $nbrowsaffected = $this->db->affected_rows($resql); - if (!$error && $nbrowsaffected) - { + if (!$error && $nbrowsaffected) { // Update information on linked member if it is an update - if (!$nosyncmember && !empty($conf->adherent->enabled)) - { + if (!$nosyncmember && !empty($conf->adherent->enabled)) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; dol_syslog(get_class($this)."::update update linked member"); @@ -1372,8 +1370,7 @@ class Societe extends CommonObject $lmember = new Adherent($this->db); $result = $lmember->fetch(0, 0, $this->id); - if ($result > 0) - { + if ($result > 0) { $lmember->company = $this->name; //$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname; // We keep firstname and lastname of member unchanged //$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname; // We keep firstname and lastname of member unchanged @@ -1387,15 +1384,13 @@ class Societe extends CommonObject $lmember->country_id = $this->country_id; $result = $lmember->update($user, 0, 1, 1, 1); // Use nosync to 1 to avoid cyclic updates - if ($result < 0) - { + if ($result < 0) { $this->error = $lmember->error; $this->errors = array_merge($this->errors, $lmember->errors); dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR); $error++; } - } elseif ($result < 0) - { + } elseif ($result < 0) { $this->error = $lmember->error; $error++; } @@ -1405,34 +1400,30 @@ class Societe extends CommonObject $action = 'update'; // Actions on extra fields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } // Actions on extra languages - if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) // For avoid conflicts if trigger used - { + if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) { // For avoid conflicts if trigger used $result = $this->insertExtraLanguages(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error && $call_trigger) - { + if (!$error && $call_trigger) { // Call trigger $result = $this->call_trigger('COMPANY_MODIFY', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { dol_syslog(get_class($this)."::Update success"); $this->db->commit(); return 1; @@ -1441,8 +1432,7 @@ class Societe extends CommonObject return -1; } } else { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { // Doublon $this->error = $langs->trans("ErrorDuplicateField"); $result = -1; @@ -1482,7 +1472,9 @@ class Societe extends CommonObject global $langs; global $conf; - if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1; + if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) { + return -1; + } $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.address, s.datec as date_creation, s.prefix_comm'; $sql .= ', s.status'; @@ -1525,30 +1517,51 @@ class Societe extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_remise as sr ON sr.rowid = (SELECT MAX(rowid) FROM '.MAIN_DB_PREFIX.'societe_remise WHERE fk_soc = s.rowid AND entity IN ('.getEntity('discount').'))'; $sql .= ' WHERE s.entity IN ('.getEntity($this->element).')'; - if ($rowid) $sql .= ' AND s.rowid = '.$rowid; - if ($ref) $sql .= " AND s.nom = '".$this->db->escape($ref)."'"; - if ($ref_alias) $sql .= " AND s.name_alias = '".$this->db->escape($ref_alias)."'"; - if ($ref_ext) $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'"; - if ($barcode) $sql .= " AND s.barcode = '".$this->db->escape($barcode)."'"; - if ($idprof1) $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'"; - if ($idprof2) $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'"; - if ($idprof3) $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'"; - if ($idprof4) $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'"; - if ($idprof5) $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'"; - if ($idprof6) $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'"; - if ($email) $sql .= " AND s.email = '".$this->db->escape($email)."'"; + if ($rowid) { + $sql .= ' AND s.rowid = '.$rowid; + } + if ($ref) { + $sql .= " AND s.nom = '".$this->db->escape($ref)."'"; + } + if ($ref_alias) { + $sql .= " AND s.name_alias = '".$this->db->escape($ref_alias)."'"; + } + if ($ref_ext) { + $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'"; + } + if ($barcode) { + $sql .= " AND s.barcode = '".$this->db->escape($barcode)."'"; + } + if ($idprof1) { + $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'"; + } + if ($idprof2) { + $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'"; + } + if ($idprof3) { + $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'"; + } + if ($idprof4) { + $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'"; + } + if ($idprof5) { + $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'"; + } + if ($idprof6) { + $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'"; + } + if ($email) { + $sql .= " AND s.email = '".$this->db->escape($email)."'"; + } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); - if ($num > 1) - { + if ($num > 1) { $this->error = 'Fetch found several records. Rename one of thirdparties to avoid duplicate.'; dol_syslog($this->error, LOG_ERR); $result = -2; - } elseif ($num) // $num = 1 - { + } elseif ($num) { // $num = 1 $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -1694,7 +1707,9 @@ class Societe extends CommonObject } // Use first price level if level not defined for third party - if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) $this->price_level = 1; + if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) { + $this->price_level = 1; + } return $result; } @@ -1711,7 +1726,9 @@ class Societe extends CommonObject { global $langs, $conf, $user; - if (empty($fuser)) $fuser = $user; + if (empty($fuser)) { + $fuser = $user; + } require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1722,49 +1739,42 @@ class Societe extends CommonObject // Test if child exists $objectisused = $this->isObjectUsed($id); - if (empty($objectisused)) - { + if (empty($objectisused)) { $this->db->begin(); // User is mandatory for trigger call - if (!$error && $call_trigger) - { + if (!$error && $call_trigger) { // Call trigger $result = $this->call_trigger('COMPANY_DELETE', $fuser); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $static_cat = new Categorie($this->db); $toute_categs = array(); // Fill $toute_categs array with an array of (type => array of ("Categorie" instance)) - if ($this->client || $this->prospect) - { + if ($this->client || $this->prospect) { $toute_categs['customer'] = $static_cat->containing($this->id, Categorie::TYPE_CUSTOMER); } - if ($this->fournisseur) - { + if ($this->fournisseur) { $toute_categs['supplier'] = $static_cat->containing($this->id, Categorie::TYPE_SUPPLIER); } // Remove each "Categorie" - foreach ($toute_categs as $type => $categs_type) - { - foreach ($categs_type as $cat) - { + foreach ($toute_categs as $type => $categs_type) { + foreach ($categs_type as $cat) { $cat->del_type($this, $type); } } } - if (!$error) - { - foreach ($this->childtablesoncascade as $tabletodelete) - { + if (!$error) { + foreach ($this->childtablesoncascade as $tabletodelete) { $deleteFromObject = explode(':', $tabletodelete); if (count($deleteFromObject) >= 2) { $className = str_replace('@', '', $deleteFromObject[0]); @@ -1796,51 +1806,42 @@ class Societe extends CommonObject } // Removed extrafields - if (!$error) - { + if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); } } // Remove links to subsidiaries companies - if (!$error) - { + if (!$error) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET parent = NULL"; $sql .= " WHERE parent = ".$id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $error++; $this->errors[] = $this->db->lasterror(); } } // Remove third party - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe"; $sql .= " WHERE rowid = ".$id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $error++; $this->errors[] = $this->db->lasterror(); } } - if (!$error) - { + if (!$error) { $this->db->commit(); // Delete directory - if (!empty($conf->societe->multidir_output[$entity])) - { + if (!empty($conf->societe->multidir_output[$entity])) { $docdir = $conf->societe->multidir_output[$entity]."/".$id; - if (dol_is_dir($docdir)) - { + if (dol_is_dir($docdir)) { dol_delete_dir_recursive($docdir); } } @@ -1851,7 +1852,9 @@ class Societe extends CommonObject $this->db->rollback(); return -1; } - } else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING); + } else { + dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING); + } return 0; } @@ -1864,20 +1867,22 @@ class Societe extends CommonObject public function set_as_client() { // phpcs:enable - if ($this->id) - { + if ($this->id) { $newclient = 1; - if ($this->client == 2 || $this->client == 3) $newclient = 3; //If prospect, we keep prospect tag + if ($this->client == 2 || $this->client == 3) { + $newclient = 3; //If prospect, we keep prospect tag + } $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET client = ".$newclient; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->client = $newclient; return 1; - } else return -1; + } else { + return -1; + } } return 0; } @@ -1898,16 +1903,14 @@ class Societe extends CommonObject // Parameter cleaning $note = trim($note); - if (!$note) - { + if (!$note) { $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NoteReason")); return -2; } dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id); - if ($this->id) - { + if ($this->id) { $this->db->begin(); $now = dol_now(); @@ -1917,8 +1920,7 @@ class Societe extends CommonObject $sql .= " SET remise_client = '".$this->db->escape($remise)."'"; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->db->rollback(); $this->error = $this->db->error(); return -1; @@ -1933,8 +1935,7 @@ class Societe extends CommonObject $sql .= ")"; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->db->rollback(); $this->error = $this->db->lasterror(); return -1; @@ -1961,16 +1962,14 @@ class Societe extends CommonObject // Parameter cleaning $note = trim($note); - if (!$note) - { + if (!$note) { $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NoteReason")); return -2; } dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id); - if ($this->id) - { + if ($this->id) { $this->db->begin(); $now = dol_now(); @@ -1980,8 +1979,7 @@ class Societe extends CommonObject $sql .= " SET remise_supplier = '".$this->db->escape($remise)."'"; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->db->rollback(); $this->error = $this->db->error(); return -1; @@ -1996,8 +1994,7 @@ class Societe extends CommonObject $sql .= ")"; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->db->rollback(); $this->error = $this->db->lasterror(); return -1; @@ -2029,24 +2026,20 @@ class Societe extends CommonObject $desc = trim($desc); // Check parameters - if (!$remise > 0) - { + if (!$remise > 0) { $this->error = $langs->trans("ErrorWrongValueForParameter", "1"); return -1; } - if (!$desc) - { + if (!$desc) { $this->error = $langs->trans("ErrorWrongValueForParameter", "3"); return -2; } - if ($this->id > 0) - { + if ($this->id > 0) { // Clean vat code $reg = array(); $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $vatrate, $reg)) - { + if (preg_match('/\((.*)\)/', $vatrate, $reg)) { $vat_src_code = $reg[1]; $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. } @@ -2068,14 +2061,15 @@ class Societe extends CommonObject $discount->description = $desc; $result = $discount->create($user); - if ($result > 0) - { + if ($result > 0) { return $result; } else { $this->error = $discount->error; return -3; } - } else return 0; + } else { + return 0; + } } /** @@ -2093,8 +2087,7 @@ class Societe extends CommonObject $discountstatic = new DiscountAbsolute($this->db); $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type); - if ($result >= 0) - { + if ($result >= 0) { return $result; } else { $this->error = $discountstatic->error; @@ -2119,13 +2112,14 @@ class Societe extends CommonObject $sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo"; $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u"; - if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) - { + if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql .= " WHERE ((ug.fk_user = sc.fk_user"; $sql .= " AND ug.entity = ".$conf->entity.")"; $sql .= " OR u.admin = 1)"; - } else $sql .= " WHERE entity in (0, ".$conf->entity.")"; + } else { + $sql .= " WHERE entity in (0, ".$conf->entity.")"; + } $sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id; if (empty($sortfield) && empty($sortorder)) { @@ -2135,16 +2129,13 @@ class Societe extends CommonObject $sql .= $this->db->order($sortfield, $sortorder); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); - if (empty($mode)) - { + if (empty($mode)) { $reparray[$i]['id'] = $obj->rowid; $reparray[$i]['lastname'] = $obj->lastname; $reparray[$i]['firstname'] = $obj->firstname; @@ -2179,16 +2170,14 @@ class Societe extends CommonObject public function set_price_level($price_level, User $user) { // phpcs:enable - if ($this->id) - { + if ($this->id) { $now = dol_now(); $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET price_level = '".$this->db->escape($price_level)."'"; $sql .= " WHERE rowid = ".$this->id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { dol_print_error($this->db); return -1; } @@ -2197,8 +2186,7 @@ class Societe extends CommonObject $sql .= " (datec, fk_soc, price_level, fk_user_author)"; $sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")"; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { dol_print_error($this->db); return -1; } @@ -2220,50 +2208,42 @@ class Societe extends CommonObject // phpcs:enable $error = 0; - if ($this->id > 0 && $commid > 0) - { + if ($this->id > 0 && $commid > 0) { $this->db->begin(); - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux"; $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); $error++; } } - if (!$error) - { + if (!$error) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux"; $sql .= " (fk_soc, fk_user)"; $sql .= " VALUES (".$this->id.", ".$commid.")"; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); $error++; } } - if (!$error) - { + if (!$error) { $this->context = array('commercial_modified'=>$commid); $result = $this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE', $user); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -2290,15 +2270,15 @@ class Societe extends CommonObject $this->context = array('commercial_modified'=>$commid); $result = $this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } - if ($this->id > 0 && $commid > 0) - { + if ($this->id > 0 && $commid > 0) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux "; $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { dol_syslog(get_class($this)."::del_commercial Erreur"); } } @@ -2319,17 +2299,22 @@ class Societe extends CommonObject { global $conf, $langs, $hookmanager; - if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + if (!empty($conf->dol_no_mouse_hover)) { + $notooltip = 1; // Force disable tooltips + } $name = $this->name ? $this->name : $this->nom; if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) { - if (empty($option) && $this->client > 0) $option = 'customer'; - if (empty($option) && $this->fournisseur > 0) $option = 'supplier'; + if (empty($option) && $this->client > 0) { + $option = 'customer'; + } + if (empty($option) && $this->fournisseur > 0) { + $option = 'supplier'; + } } - if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) - { + if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) { $code = ''; if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) { $code = $this->code_client.' - '; @@ -2348,18 +2333,18 @@ class Societe extends CommonObject } } - if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')'; + if (!empty($this->name_alias)) { + $name .= ' ('.$this->name_alias.')'; + } $result = ''; $label = ''; $linkstart = ''; $linkend = ''; - if (!empty($this->logo) && class_exists('Form')) - { + if (!empty($this->logo) && class_exists('Form')) { $label .= '
'; $label .= Form::showphoto('societe', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. $label .= '
'; - } elseif (!empty($this->logo_squarred) && class_exists('Form')) - { + } elseif (!empty($this->logo_squarred) && class_exists('Form')) { /*$label.= '
'; $label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. $label.= '
';*/ @@ -2367,43 +2352,34 @@ class Societe extends CommonObject $label .= '
'; - if ($option == 'customer' || $option == 'compta' || $option == 'category') - { + if ($option == 'customer' || $option == 'compta' || $option == 'category') { $label .= img_picto('', $this->picto).' '.$langs->trans("Customer").''; $linkstart = ''.$langs->trans("Prospect").''; $linkstart = ''.$langs->trans("Supplier").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowCompany"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' class="classfortooltip refurl"'; - /* + /* $hookmanager->initHooks(array('thirdpartydao')); $parameters=array('id'=>$this->id); $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks @@ -2470,15 +2466,18 @@ class Societe extends CommonObject $linkend = ''; global $user; - if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid) - { + if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid) { $linkstart = ''; $linkend = ''; } $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name); + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name); + } $result .= $linkend; global $action; @@ -2493,8 +2492,11 @@ class Societe extends CommonObject 'save_lastsearch_value'=> $save_lastsearch_value ); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) $result = $hookmanager->resPrint; - else $result .= $hookmanager->resPrint; + if ($reshook > 0) { + $result = $hookmanager->resPrint; + } else { + $result .= $hookmanager->resPrint; + } return $result; } @@ -2525,10 +2527,11 @@ class Societe extends CommonObject $langs->load('companies'); $statusType = 'status4'; - if ($status == 0) $statusType = 'status6'; + if ($status == 0) { + $statusType = 'status6'; + } - if (empty($this->labelStatus) || empty($this->labelStatusShort)) - { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) { $this->labelStatus[0] = $langs->trans("ActivityCeased"); $this->labelStatus[1] = $langs->trans("InActivity"); $this->labelStatusShort[0] = $langs->trans("ActivityCeased"); @@ -2551,9 +2554,10 @@ class Societe extends CommonObject global $langs; $contact_emails = $this->contact_property_array('email', 1); - if ($this->email && $addthirdparty) - { - if (empty($this->name)) $this->name = $this->nom; + if ($this->email && $addthirdparty) { + if (empty($this->name)) { + $this->name = $this->nom; + } $contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->email.">"; } //var_dump($contact_emails) @@ -2573,9 +2577,10 @@ class Societe extends CommonObject $contact_phone = $this->contact_property_array('mobile'); - if (!empty($this->phone)) // If a phone of thirdparty is defined, we add it ot mobile of contacts - { - if (empty($this->name)) $this->name = $this->nom; + if (!empty($this->phone)) { // If a phone of thirdparty is defined, we add it ot mobile of contacts + if (empty($this->name)) { + $this->name = $this->nom; + } // TODO: Tester si tel non deja present dans tableau contact $contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->phone.">"; } @@ -2604,36 +2609,36 @@ class Societe extends CommonObject $sql .= " ORDER BY lastname, firstname"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $nump = $this->db->num_rows($resql); - if ($nump) - { + if ($nump) { $sepa = "("; $sepb = ")"; - if ($mode == 'email') - { + if ($mode == 'email') { //$sepa="<"; $sepb=">"; $sepa = "<"; $sepb = ">"; } $i = 0; - while ($i < $nump) - { + while ($i < $nump) { $obj = $this->db->fetch_object($resql); - if ($mode == 'email') $property = $obj->email; - elseif ($mode == 'mobile') $property = $obj->phone_mobile; - else $property = $obj->$mode; + if ($mode == 'email') { + $property = $obj->email; + } elseif ($mode == 'mobile') { + $property = $obj->phone_mobile; + } else { + $property = $obj->$mode; + } // Show all contact. If hidedisabled is 1, showonly contacts with status = 1 - if ($obj->status == 1 || empty($hidedisabled)) - { - if (empty($property)) - { - if ($mode == 'email') $property = $langs->transnoentitiesnoconv("NoEMail"); - elseif ($mode == 'mobile') $property = $langs->transnoentitiesnoconv("NoMobilePhone"); + if ($obj->status == 1 || empty($hidedisabled)) { + if (empty($property)) { + if ($mode == 'email') { + $property = $langs->transnoentitiesnoconv("NoEMail"); + } elseif ($mode == 'mobile') { + $property = $langs->transnoentitiesnoconv("NoMobilePhone"); + } } - if (!empty($obj->poste)) - { + if (!empty($obj->poste)) { $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ? " - ".$obj->poste : "").(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : ''); } else { $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : ''); @@ -2662,14 +2667,11 @@ class Societe extends CommonObject $sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $nump = $this->db->num_rows($resql); - if ($nump) - { + if ($nump) { $i = 0; - while ($i < $nump) - { + while ($i < $nump) { $obj = $this->db->fetch_object($resql); $contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname, $obj->lastname); $i++; @@ -2695,14 +2697,11 @@ class Societe extends CommonObject $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $nump = $this->db->num_rows($resql); - if ($nump) - { + if ($nump) { $i = 0; - while ($i < $nump) - { + while ($i < $nump) { $obj = $this->db->fetch_object($resql); $contact = new Contact($this->db); $contact->fetch($obj->rowid); @@ -2729,23 +2728,26 @@ class Societe extends CommonObject // phpcs:enable $contact_property = ''; - if (empty($rowid)) return ''; + if (empty($rowid)) { + return ''; + } $sql = "SELECT rowid, email, phone_mobile, lastname, firstname"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople"; $sql .= " WHERE rowid = ".((int) $rowid); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $nump = $this->db->num_rows($resql); - if ($nump) - { + if ($nump) { $obj = $this->db->fetch_object($resql); - if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">"; - elseif ($mode == 'mobile') $contact_property = $obj->phone_mobile; + if ($mode == 'email') { + $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">"; + } elseif ($mode == 'mobile') { + $contact_property = $obj->phone_mobile; + } } return $contact_property; } else { @@ -2833,15 +2835,15 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); @@ -2865,15 +2867,15 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); @@ -2894,23 +2896,29 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module); - if ($mod->code_modifiable_null && !$this->code_client) return 1; - if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1; - if ($mod->code_modifiable) return 1; // A mettre en dernier + if ($mod->code_modifiable_null && !$this->code_client) { + return 1; + } + if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) { + return 1; + } + if ($mod->code_modifiable) { + return 1; // A mettre en dernier + } return 0; } else { return 0; @@ -2928,23 +2936,29 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module); - if ($mod->code_modifiable_null && !$this->code_fournisseur) return 1; - if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1; - if ($mod->code_modifiable) return 1; // A mettre en dernier + if ($mod->code_modifiable_null && !$this->code_fournisseur) { + return 1; + } + if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) { + return 1; + } + if ($mod->code_modifiable) { + return 1; // A mettre en dernier + } return 0; } else { return 0; @@ -2968,25 +2982,25 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); - dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module); - $result = $mod->verif($this->db, $this->code_client, $this, 0); - if ($result) { // If error - $this->error = $mod->error; - $this->errors = $mod->errors; - } + dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module); + $result = $mod->verif($this->db, $this->code_client, $this, 0); + if ($result) { // If error + $this->error = $mod->error; + $this->errors = $mod->errors; + } return $result; } else { return 0; @@ -3009,15 +3023,15 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); @@ -3048,26 +3062,28 @@ class Societe extends CommonObject // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) { $res = false; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php'); - if ($res) break; + if ($res) { + break; + } } - if ($res) - { + if ($res) { $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON; $mod = new $classname; // Set code count in $mod->code $result = $mod->get_code($this->db, $this, $type); - if ($type == 'customer') $this->code_compta = $mod->code; - elseif ($type == 'supplier') $this->code_compta_fournisseur = $mod->code; + if ($type == 'customer') { + $this->code_compta = $mod->code; + } elseif ($type == 'supplier') { + $this->code_compta_fournisseur = $mod->code; + } return $result; } else { @@ -3075,8 +3091,11 @@ class Societe extends CommonObject return -1; } } else { - if ($type == 'customer') $this->code_compta = ''; - elseif ($type == 'supplier') $this->code_compta_fournisseur = ''; + if ($type == 'customer') { + $this->code_compta = ''; + } elseif ($type == 'supplier') { + $this->code_compta_fournisseur = ''; + } return 0; } @@ -3092,21 +3111,21 @@ class Societe extends CommonObject public function set_parent($id) { // phpcs:enable - if ($this->id) - { + if ($this->id) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET parent = ".($id > 0 ? $id : "null"); $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this).'::set_parent', LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->parent = $id; return 1; } else { return -1; } - } else return -1; + } else { + return -1; + } } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3121,8 +3140,7 @@ class Societe extends CommonObject // phpcs:enable global $conf; - switch ($idprof) - { + switch ($idprof) { case 1: $ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ? false : true); break; @@ -3162,8 +3180,7 @@ class Societe extends CommonObject // phpcs:enable $field = $idprof; - switch ($idprof) // For backward compatibility - { + switch ($idprof) { // For backward compatibility case '1': case 'idprof1': $field = "siren"; @@ -3186,14 +3203,15 @@ class Societe extends CommonObject case '6': $field = "idprof6"; break; - } + } //Verify duplicate entries $sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$this->db->escape($value)."' AND entity IN (".getEntity('societe').")"; - if ($socid) $sql .= " AND rowid <> ".$socid; + if ($socid) { + $sql .= " AND rowid <> ".$socid; + } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); $count = $obj->idprof; } else { @@ -3202,8 +3220,11 @@ class Societe extends CommonObject } $this->db->free($resql); - if ($count > 0) return true; - else return false; + if ($count > 0) { + return true; + } else { + return false; + } } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3222,111 +3243,144 @@ class Societe extends CommonObject $ok = 1; - if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1; + if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) { + return 1; + } // Check SIREN if country FR - if ($idprof == 1 && $soc->country_code == 'FR') - { + if ($idprof == 1 && $soc->country_code == 'FR') { $chaine = trim($this->idprof1); $chaine = preg_replace('/(\s)/', '', $chaine); - if (!is_numeric($chaine)) return -1; - if (dol_strlen($chaine) != 9) return -1; + if (!is_numeric($chaine)) { + return -1; + } + if (dol_strlen($chaine) != 9) { + return -1; + } // on prend chaque chiffre un par un // si son index (position dans la chaîne en commence à 0 au premier caractère) est impair // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9 // on ajoute cette valeur à la somme totale $sum = 0; - for ($index = 0; $index < 9; $index++) - { + for ($index = 0; $index < 9; $index++) { $number = (int) $chaine[$index]; - if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; } + if (($index % 2) != 0) { + if (($number *= 2) > 9) { + $number -= 9; + } + } $sum += $number; } // le numéro est valide si la somme des chiffres est multiple de 10 - if (($sum % 10) != 0) return -1; + if (($sum % 10) != 0) { + return -1; + } } // Verifie SIRET si pays FR - if ($idprof == 2 && $soc->country_code == 'FR') - { + if ($idprof == 2 && $soc->country_code == 'FR') { $chaine = trim($this->idprof2); $chaine = preg_replace('/(\s)/', '', $chaine); - if (!is_numeric($chaine)) return -1; - if (dol_strlen($chaine) != 14) return -1; + if (!is_numeric($chaine)) { + return -1; + } + if (dol_strlen($chaine) != 14) { + return -1; + } // on prend chaque chiffre un par un // si son index (position dans la chaîne en commence à 0 au premier caractère) est pair // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9 // on ajoute cette valeur à la somme totale $sum = 0; - for ($index = 0; $index < 14; $index++) - { + for ($index = 0; $index < 14; $index++) { $number = (int) $chaine[$index]; - if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; } + if (($index % 2) == 0) { + if (($number *= 2) > 9) { + $number -= 9; + } + } $sum += $number; } // le numéro est valide si la somme des chiffres est multiple de 10 - if (($sum % 10) != 0) return -1; + if (($sum % 10) != 0) { + return -1; + } } //Verify CIF/NIF/NIE if pays ES //Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad - if ($idprof == 1 && $soc->country_code == 'ES') - { + if ($idprof == 1 && $soc->country_code == 'ES') { $string = trim($this->idprof1); $string = preg_replace('/(\s)/', '', $string); $string = strtoupper($string); //Check format - if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) - return 0; + if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) { + return 0; + } $num = array(); - for ($i = 0; $i < 9; $i++) - { + for ($i = 0; $i < 9; $i++) { $num[$i] = substr($string, $i, 1); } //Check NIF - if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) - if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) + if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) { + if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) { return 1; - else return -1; + } else { + return -1; + } + } //algorithm checking type code CIF $sum = $num[2] + $num[4] + $num[6]; - for ($i = 1; $i < 8; $i += 2) - $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1)); + for ($i = 1; $i < 8; $i += 2) { + $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1)); + } $n = 10 - substr($sum, strlen($sum) - 1, 1); //Chek special NIF - if (preg_match('/^[KLM]{1}/', $string)) - if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) + if (preg_match('/^[KLM]{1}/', $string)) { + if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) { return 1; - else return -1; + } else { + return -1; + } + } //Check CIF - if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) - if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) + if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) { + if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) { return 2; - else return -2; + } else { + return -2; + } + } //Check NIE T - if (preg_match('/^[T]{1}/', $string)) - if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) + if (preg_match('/^[T]{1}/', $string)) { + if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) { return 3; - else return -3; + } else { + return -3; + } + } //Check NIE XYZ - if (preg_match('/^[XYZ]{1}/', $string)) - if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1)) + if (preg_match('/^[XYZ]{1}/', $string)) { + if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1)) { return 3; - else return -3; + } else { + return -3; + } + } //Can not be verified return -4; @@ -3334,8 +3388,7 @@ class Societe extends CommonObject //Verify NIF if country is PT //Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad - if ($idprof == 1 && $soc->country_code == 'PT') - { + if ($idprof == 1 && $soc->country_code == 'PT') { $string = trim($this->idprof1); $string = preg_replace('/(\s)/', '', $string); @@ -3414,8 +3467,7 @@ class Societe extends CommonObject // phpcs:enable $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = '.$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); $count = $obj->numproj; } else { @@ -3441,10 +3493,8 @@ class Societe extends CommonObject $sql .= " WHERE s.rowid = ".$id; $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { + if ($result) { + if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; @@ -3487,11 +3537,13 @@ class Societe extends CommonObject $isacompany = 1; } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) { $isacompany = 1; - } elseif (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') - { + } elseif (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') { // TODO Add a field is_a_company into dictionary - if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany = 0; - else $isacompany = 1; + if (preg_match('/^TE_PRIVATE/', $this->typent_code)) { + $isacompany = 0; + } else { + $isacompany = 1; + } } return $isacompany; @@ -3523,10 +3575,8 @@ class Societe extends CommonObject $sql .= " WHERE type = ".Categorie::TYPE_SUPPLIER; $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $this->SupplierCategories[$obj->rowid] = $obj->label; } return 0; @@ -3545,12 +3595,13 @@ class Societe extends CommonObject public function AddFournisseurInCategory($categorie_id) { // phpcs:enable - if ($categorie_id > 0 && $this->id > 0) - { + if ($categorie_id > 0 && $this->id > 0) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) "; $sql .= " VALUES (".$categorie_id.", ".$this->id.")"; - if ($resql = $this->db->query($sql)) return 0; + if ($resql = $this->db->query($sql)) { + return 0; + } } else { return 0; } @@ -3576,7 +3627,9 @@ class Societe extends CommonObject dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); $name = $socname ? $socname : $member->societe; - if (empty($name)) $name = $member->getFullName($langs); + if (empty($name)) { + $name = $member->getFullName($langs); + } $alias = $socalias ? $socalias : ''; @@ -3602,15 +3655,13 @@ class Societe extends CommonObject // Cree et positionne $this->id $result = $this->create($user); - if ($result >= 0) - { + if ($result >= 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; $sql .= " SET fk_soc=".$this->id; $sql .= " WHERE rowid=".$member->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->db->commit(); return $this->id; } else { @@ -3652,12 +3703,10 @@ class Societe extends CommonObject // We define country_id, country_code and country $country_id = $country_code = $country_label = ''; - if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) - { + if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) { $tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY); $country_id = $tmp[0]; - if (!empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label" - { + if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label" $country_code = $tmp[1]; $country_label = $tmp[2]; } else // For backward compatibility @@ -3671,17 +3720,17 @@ class Societe extends CommonObject $this->country_id = $country_id; $this->country_code = $country_code; $this->country = $country_label; - if (is_object($langs)) $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label; + if (is_object($langs)) { + $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label; + } //TODO This could be replicated for region but function `getRegion` didn't exist, so I didn't added it. // We define state_id, state_code and state $state_id = 0; $state_code = $state_label = ''; - if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) - { + if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) { $tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_STATE); $state_id = $tmp[0]; - if (!empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" - { + if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" $state_code = $tmp[1]; $state_label = $tmp[2]; } else // For backward compatibility @@ -3695,7 +3744,9 @@ class Societe extends CommonObject $this->state_id = $state_id; $this->state_code = $state_code; $this->state = $state_label; - if (is_object($langs)) $this->state = ($langs->trans('State'.$state_code) != 'State'.$state_code) ? $langs->trans('State'.$state_code) : $state_label; + if (is_object($langs)) { + $this->state = ($langs->trans('State'.$state_code) != 'State'.$state_code) ? $langs->trans('State'.$state_code) : $state_label; + } $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL; $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX; @@ -3709,12 +3760,24 @@ class Societe extends CommonObject $this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL; $this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL; $this->socialnetworks = array(); - if (!empty($this->facebook_url)) $this->socialnetworks['facebook'] = $this->facebook_url; - if (!empty($this->twitter_url)) $this->socialnetworks['twitter'] = $this->twitter_url; - if (!empty($this->linkedin_url)) $this->socialnetworks['linkedin'] = $this->linkedin_url; - if (!empty($this->instagram_url)) $this->socialnetworks['instagram'] = $this->instagram_url; - if (!empty($this->youtube_url)) $this->socialnetworks['youtube'] = $this->youtube_url; - if (!empty($this->github_url)) $this->socialnetworks['github'] = $this->github_url; + if (!empty($this->facebook_url)) { + $this->socialnetworks['facebook'] = $this->facebook_url; + } + if (!empty($this->twitter_url)) { + $this->socialnetworks['twitter'] = $this->twitter_url; + } + if (!empty($this->linkedin_url)) { + $this->socialnetworks['linkedin'] = $this->linkedin_url; + } + if (!empty($this->instagram_url)) { + $this->socialnetworks['instagram'] = $this->instagram_url; + } + if (!empty($this->youtube_url)) { + $this->socialnetworks['youtube'] = $this->youtube_url; + } + if (!empty($this->github_url)) { + $this->socialnetworks['github'] = $this->github_url; + } // Id prof generiques $this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ? '' : $conf->global->MAIN_INFO_SIREN; @@ -3814,15 +3877,20 @@ class Societe extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'"; $sql .= " AND t.active = 1"; - if (empty($localTaxNum)) $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')"; - elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'"; - elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'"; + if (empty($localTaxNum)) { + $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')"; + } elseif ($localTaxNum == 1) { + $sql .= " AND t.localtax1_type <> '0'"; + } elseif ($localTaxNum == 2) { + $sql .= " AND t.localtax2_type <> '0'"; + } $resql = $this->db->query($sql); - if ($resql) - { - return ($this->db->num_rows($resql) > 0); - } else return false; + if ($resql) { + return ($this->db->num_rows($resql) > 0); + } else { + return false; + } } /** @@ -3839,10 +3907,11 @@ class Societe extends CommonObject dol_syslog("useNPR", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { return ($this->db->num_rows($resql) > 0); - } else return false; + } else { + return false; + } } /** @@ -3860,10 +3929,9 @@ class Societe extends CommonObject dol_syslog("useRevenueStamp", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - return (($obj->nb > 0) ?true:false); + return (($obj->nb > 0) ?true:false); } else { $this->error = $this->db->lasterror(); return false; @@ -3894,8 +3962,7 @@ class Societe extends CommonObject $lib = $langs->trans("ProspectLevel".$fk_prospectlevel); // If lib not found in language file, we get label from cache/databse - if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) - { + if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) { $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label'); } return $lib; @@ -3949,30 +4016,45 @@ class Societe extends CommonObject $langs->load('customers'); if ($mode == 2) { - if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); - elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); - elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); - elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); - elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); - else { + if ($status == '-1' || $status == 'ST_NO') { + return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); + } elseif ($status == '0' || $status == 'ST_NEVER') { + return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); + } elseif ($status == '1' || $status == 'ST_TODO') { + return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); + } elseif ($status == '2' || $status == 'ST_PEND') { + return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); + } elseif ($status == '3' || $status == 'ST_DONE') { + return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); + } else { return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label); } } elseif ($mode == 3) { - if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto); - elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto); - elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto); - elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto); - elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto); - else { + if ($status == '-1' || $status == 'ST_NO') { + return img_action($langs->trans("StatusProspect-1"), -1, $picto); + } elseif ($status == '0' || $status == 'ST_NEVER') { + return img_action($langs->trans("StatusProspect0"), 0, $picto); + } elseif ($status == '1' || $status == 'ST_TODO') { + return img_action($langs->trans("StatusProspect1"), 1, $picto); + } elseif ($status == '2' || $status == 'ST_PEND') { + return img_action($langs->trans("StatusProspect2"), 2, $picto); + } elseif ($status == '3' || $status == 'ST_DONE') { + return img_action($langs->trans("StatusProspect3"), 3, $picto); + } else { return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto); } } elseif ($mode == 4) { - if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); - elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); - elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); - elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); - elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); - else { + if ($status == '-1' || $status == 'ST_NO') { + return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); + } elseif ($status == '0' || $status == 'ST_NEVER') { + return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); + } elseif ($status == '1' || $status == 'ST_TODO') { + return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); + } elseif ($status == '2' || $status == 'ST_PEND') { + return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); + } elseif ($status == '3' || $status == 'ST_DONE') { + return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); + } else { return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label); } } @@ -4003,7 +4085,9 @@ class Societe extends CommonObject public function getOutstandingProposals($mode = 'customer') { $table = 'propal'; - if ($mode == 'supplier') $table = 'supplier_proposal'; + if ($mode == 'supplier') { + $table = 'supplier_proposal'; + } $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; $sql .= " WHERE fk_soc = ".$this->id; @@ -4015,21 +4099,22 @@ class Societe extends CommonObject dol_syslog("getOutstandingProposals", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; while ($obj = $this->db->fetch_object($resql)) { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; - if ($obj->status != 0) // Not a draft - { + if ($obj->status != 0) { + // Not a draft $outstandingOpened += $obj->total_ttc; } } return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' - } else return array(); + } else { + return array(); + } } /** @@ -4041,7 +4126,9 @@ class Societe extends CommonObject public function getOutstandingOrders($mode = 'customer') { $table = 'commande'; - if ($mode == 'supplier') $table = 'commande_fournisseur'; + if ($mode == 'supplier') { + $table = 'commande_fournisseur'; + } $sql = "SELECT rowid, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; $sql .= " WHERE fk_soc = ".$this->id; @@ -4053,21 +4140,22 @@ class Societe extends CommonObject dol_syslog("getOutstandingOrders", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; while ($obj = $this->db->fetch_object($resql)) { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; - if ($obj->status != 0) // Not a draft - { + if ($obj->status != 0) { + // Not a draft $outstandingOpened += $obj->total_ttc; } } return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' - } else return array(); + } else { + return array(); + } } /** @@ -4080,7 +4168,9 @@ class Societe extends CommonObject public function getOutstandingBills($mode = 'customer', $late = 0) { $table = 'facture'; - if ($mode == 'supplier') $table = 'facture_fourn'; + if ($mode == 'supplier') { + $table = 'facture_fourn'; + } /* Accurate value of remain to pay is to sum remaintopay for each invoice $paiement = $invoice->getSommePaiement(); @@ -4089,8 +4179,11 @@ class Societe extends CommonObject $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); */ - if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; - else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + if ($mode == 'supplier') { + $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + } else { + $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + } $sql .= " WHERE fk_soc = ".$this->id; if (!empty($late)) { $sql .= " AND date_lim_reglement < '".$this->db->idate(dol_now())."'"; @@ -4103,13 +4196,11 @@ class Societe extends CommonObject dol_syslog("getOutstandingBills", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; - if ($mode == 'supplier') - { + if ($mode == 'supplier') { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; $tmpobject = new FactureFournisseur($this->db); } else { @@ -4121,17 +4212,15 @@ class Societe extends CommonObject if ($obj->status != $tmpobject::STATUS_DRAFT // Not a draft && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code == 'replaced') // Not a replaced invoice - ) - { + ) { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; } if ($obj->paye == 0 && $obj->status != $tmpobject::STATUS_DRAFT // Not a draft && $obj->status != $tmpobject::STATUS_ABANDONED // Not abandonned - && $obj->status != $tmpobject::STATUS_CLOSED) // Not classified as paid - //$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason - { + && $obj->status != $tmpobject::STATUS_CLOSED) { // Not classified as paid + //$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason $paiement = $tmpobject->getSommePaiement(); $creditnotes = $tmpobject->getSumCreditNotesUsed(); $deposits = $tmpobject->getSumDepositsUsed(); @@ -4141,8 +4230,7 @@ class Societe extends CommonObject //if credit note is converted but not used // TODO Do this also for customer ? - if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) - { + if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) { $outstandingOpened -= $tmpobject->getSumFromThisCreditNotesNotUsed(); } } @@ -4175,10 +4263,15 @@ class Societe extends CommonObject global $langs; $langs->load('companies'); - if ($status == 0) return $langs->trans("NorProspectNorCustomer"); - elseif ($status == 1) return $langs->trans("Customer"); - elseif ($status == 2) return $langs->trans("Prospect"); - elseif ($status == 3) return $langs->trans("ProspectCustomer"); + if ($status == 0) { + return $langs->trans("NorProspectNorCustomer"); + } elseif ($status == 1) { + return $langs->trans("Customer"); + } elseif ($status == 2) { + return $langs->trans("Prospect"); + } elseif ($status == 3) { + return $langs->trans("ProspectCustomer"); + } } @@ -4197,21 +4290,20 @@ class Societe extends CommonObject { global $conf, $user, $langs; - if (!empty($moreparams) && !empty($moreparams['use_companybankid'])) - { + if (!empty($moreparams) && !empty($moreparams['use_companybankid'])) { $modelpath = "core/modules/bank/doc/"; include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; $companybankaccount = new CompanyBankAccount($this->db); $result = $companybankaccount->fetch($moreparams['use_companybankid']); - if (!$result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors); + if (!$result) { + dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors); + } $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } else { // Positionne le modele sur le nom du modele a utiliser - if (!dol_strlen($modele)) - { - if (!empty($conf->global->COMPANY_ADDON_PDF)) - { + if (!dol_strlen($modele)) { + if (!empty($conf->global->COMPANY_ADDON_PDF)) { $modele = $conf->global->COMPANY_ADDON_PDF; } else { print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined"); @@ -4287,11 +4379,9 @@ class Societe extends CommonObject } } foreach ($to_add as $add) { - if ($c->fetch($add) > 0) - { + if ($c->fetch($add) > 0) { $result = $c->add_type($this, $type_categ); - if ($result < 0) - { + if ($result < 0) { $error++; $this->error = $c->error; $this->errors = $c->errors; @@ -4319,7 +4409,6 @@ class Societe extends CommonObject $salesrep = array($salesrep); } - $to_del = array(); // Nothing to delete $to_add = $salesrep; if ($onlyAdd === false) { @@ -4341,8 +4430,7 @@ class Societe extends CommonObject } foreach ($to_add as $add) { $result = $this->add_commercial($user, $add); - if ($result < 0) - { + if ($result < 0) { $error++; break; } @@ -4359,22 +4447,22 @@ class Societe extends CommonObject */ public function setThirdpartyType($typent_id) { - if ($this->id) - { + if ($this->id) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET fk_typent = ".($typent_id > 0 ? $typent_id : "null"); $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this).'::setThirdpartyType', LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->typent_id = $typent_id; - $this->typent_code = dol_getIdFromCode($db, $this->$typent_id, 'c_typent', 'id', 'code'); + $this->typent_code = dol_getIdFromCode($this->db, $this->$typent_id, 'c_typent', 'id', 'code'); return 1; } else { return -1; } - } else return -1; + } else { + return -1; + } } /** @@ -4388,8 +4476,7 @@ class Societe extends CommonObject */ public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) { - if ($origin_id == $dest_id) - { + if ($origin_id == $dest_id) { dol_syslog('Error: Try to merge a thirdparty into itself'); return false; } From 483ea559f52c63bd12054a6ea8b4a435c4777403 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 16:54:28 +0100 Subject: [PATCH 15/51] Fix warning #15823 --- htdocs/webservices/server_productorservice.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index 473a720f46a..d35dc705b6f 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -536,7 +536,7 @@ function createProductOrService($authentication, $product) $newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null; $newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null; - $newobject->seuil_stock_alert = isset($product['stock_alert']) ? $product['stock_alert'] : null; + $newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null; $newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0; if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3); @@ -705,15 +705,15 @@ function updateProductOrService($authentication, $product) $newobject->barcode_type = $product['barcode_type']; } - $newobject->stock_reel = $product['stock_real']; - $newobject->pmp = $product['pmp']; - $newobject->seuil_stock_alert = $product['stock_alert']; + $newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null; + $newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null; + $newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null; - $newobject->country_id = $product['country_id']; - if ($product['country_code']) $newobject->country_id = getCountry($product['country_code'], 3); - $newobject->customcode = $product['customcode']; + $newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0; + if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3); + $newobject->customcode = isset($product['customcode']) ? $product['customcode'] : ''; - $newobject->canvas = $product['canvas']; + $newobject->canvas = isset($product['canvas']) ? $product['canvas'] : ''; $elementtype = 'product'; From 057945f6934c7f3946ce51f9016a237b0c261277 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Dec 2020 17:04:39 +0100 Subject: [PATCH 16/51] Fix bad var --- htdocs/core/boxes/box_scheduled_jobs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/boxes/box_scheduled_jobs.php b/htdocs/core/boxes/box_scheduled_jobs.php index 2ac81c80d16..804c9a0fa96 100644 --- a/htdocs/core/boxes/box_scheduled_jobs.php +++ b/htdocs/core/boxes/box_scheduled_jobs.php @@ -103,7 +103,7 @@ class box_scheduled_jobs extends ModeleBoxes $nextrun = $this->db->jdate($objp->datenextrun); if (empty($nextrun)) $nextrun = $this->db->jdate($objp->datestart); - if ($line == 0 || ($nextrun < $cronstatic->datenextrun && (empty($objp->nbrun) || empty($objp->maxrun) || $objp->nbrun < $obj->maxrun))) { + if ($line == 0 || ($nextrun < $cronstatic->datenextrun && (empty($objp->nbrun) || empty($objp->maxrun) || $objp->nbrun < $objp->maxrun))) { $cronstatic->id = $objp->rowid; $cronstatic->ref = $objp->rowid; $cronstatic->label = $langs->trans($objp->label); From 0e2b7d8b3c9fc50d01239cdd01929e5e2ed141d9 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 30 Dec 2020 07:23:26 +0100 Subject: [PATCH 17/51] Remove typo --- htdocs/compta/bank/various_payment/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index ddad89e22fc..0e3c80a6ef8 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -392,7 +392,7 @@ if ($action == 'create') // Subledger account if (!empty($conf->accounting->enabled)) { - print '
'; + print ''; print ''."\n"; // Timezone $txt = $langs->trans("OSTZ").' (variable system TZ): '.(!empty($_ENV["TZ"]) ? $_ENV["TZ"] : $langs->trans("NotDefined")).'
'."\n"; -$txt .= $langs->trans("PHPTZ").' (php.ini date.timezone): '.(ini_get("date.timezone") ?ini_get("date.timezone") : $langs->trans("NotDefined")).''."
\n"; // date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php +$txt .= $langs->trans("PHPTZ").' (date_default_timezone_get() / php.ini date.timezone): '.(getServerTimeZoneString()." / ".(ini_get("date.timezone") ? ini_get("date.timezone") : $langs->trans("NotDefined")))."
\n"; // date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php $txt .= $langs->trans("Dolibarr constant MAIN_SERVER_TZ").': '.(empty($conf->global->MAIN_SERVER_TZ) ? $langs->trans("NotDefined") : $conf->global->MAIN_SERVER_TZ); print ''; - print ''; + print ''; $label = ($langs->trans("PaymentType".$objp->payment_code) != ("PaymentType".$objp->payment_code)) ? $langs->trans("PaymentType".$objp->payment_code) : $objp->payment_label; print ''; if (!empty($conf->banque->enabled)) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 7a759dde543..4583f0376ae 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -1201,7 +1201,16 @@ class Paiement extends CommonObject $result = ''; $label = ''.$langs->trans("ShowPayment").'
'; $label .= ''.$langs->trans("Ref").': '.$this->ref; - if ($this->datepaye ? $this->datepaye : $this->date) $label .= '
'.$langs->trans("Date").': '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour'); + $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date); + if ($dateofpayment) { + $label .= '
'.$langs->trans("Date").': '; + $tmparray = dol_getdate($dateofpayment); + if ($tmparray['seconds'] == 0 && $tmparray['minutes'] == 0 && ($tmparray['hours'] == 0 || $tmparray['hours'] == 12)) { // We set hours to 0:00 or 12:00 because we don't know it + $label .= dol_print_date($dateofpayment, 'day'); + } else { // Hours was set to real date of payment (special case for POS for example) + $label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser'); + } + } if ($mode == 'withlistofinvoices') { $arraybill = $this->getBillsArray(); diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 1022308c308..0909f1b3cca 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -158,7 +158,7 @@ if ($action == 'valid' && $user->rights->facture->creer) if ($invoice->total_ttc < 0) { $invoice->type = $invoice::TYPE_CREDIT_NOTE; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE "; - $sql .= "fk_soc = '".$invoice->socid."' "; + $sql .= "fk_soc = ".((int) $invoice->socid)." "; $sql .= "AND type <> ".Facture::TYPE_CREDIT_NOTE." "; $sql .= "AND fk_statut >= ".$invoice::STATUS_VALIDATED." "; $sql .= "ORDER BY rowid DESC"; @@ -763,13 +763,13 @@ $( document ).ready(function() { if ($resql) { while ($obj = $db->fetch_object($resql)) { echo '$("#customerandsales").append(\''; - echo 'jdate($obj->datec), '%H:%M'))).'" onclick="place=\\\''; + echo 'jdate($obj->datec), '%H:%M', 'tzuser'))).'" onclick="place=\\\''; $num_sale = str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $obj->ref)); echo $num_sale; if (str_replace("-", "", $num_sale) > $max_sale) $max_sale = str_replace("-", "", $num_sale); echo '\\\';Refresh();">'; if ($placeid == $obj->rowid) echo ""; - echo dol_print_date($db->jdate($obj->datec), '%H:%M'); + echo dol_print_date($db->jdate($obj->datec), '%H:%M', 'tzuser'); if ($placeid == $obj->rowid) echo ""; echo '\');'; } From 1eb88333569da70e46f160ab68a9e80a2b1f2124 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 23:39:51 +0100 Subject: [PATCH 28/51] Fix total when no data --- .../accountancy/bookkeeping/listbyaccount.php | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 0b063adb1ff..4847dfd2e9a 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -749,40 +749,42 @@ while ($i < min($num, $limit)) $i++; } -// Show sub-total of last shown account -if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING) || empty($arrayfields['t.lettering_code']['checked'])) { - $colnumber = 3; - $colnumberend = 7; -} else { - $colnumber = 4; - $colnumberend = 7; +if ($num > 0) { + // Show sub-total of last shown account + if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING) || empty($arrayfields['t.lettering_code']['checked'])) { + $colnumber = 3; + $colnumberend = 7; + } else { + $colnumber = 4; + $colnumberend = 7; + } + $colspan = $totalarray['nbfield'] - $colnumber; + $colspanend = $totalarray['nbfield'] - $colnumberend; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + // Show balance of last shown account + $balance = $sous_total_debit - $sous_total_credit; + print ''; + print ''; + if ($balance > 0) + { + print ''; + print ''; + } else { + print ''; + print ''; + } + print ''; + print ''; } -$colspan = $totalarray['nbfield'] - $colnumber; -$colspanend = $totalarray['nbfield'] - $colnumberend; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -// Show balance of last shown account -$balance = $sous_total_debit - $sous_total_credit; -print ''; -print ''; -if ($balance > 0) -{ - print ''; - print ''; -} else { - print ''; - print ''; -} -print ''; -print ''; // Show total line include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; From e17d4b8220e2e9e5f1aa27cc4421f9d9cad31706 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 23:51:55 +0100 Subject: [PATCH 29/51] Fix total when no data --- .../bookkeeping/listbysubaccount.php | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/listbysubaccount.php b/htdocs/accountancy/bookkeeping/listbysubaccount.php index 2bdf5e11d09..abbf5df60e7 100644 --- a/htdocs/accountancy/bookkeeping/listbysubaccount.php +++ b/htdocs/accountancy/bookkeeping/listbysubaccount.php @@ -761,40 +761,42 @@ while ($i < min($num, $limit)) $i++; } -// Show sub-total of last shown account -if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING) || empty($arrayfields['t.lettering_code']['checked'])) { - $colnumber = 3; - $colnumberend = 7; -} else { - $colnumber = 4; - $colnumberend = 7; +if ($num > 0) { + // Show sub-total of last shown account + if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING) || empty($arrayfields['t.lettering_code']['checked'])) { + $colnumber = 3; + $colnumberend = 7; + } else { + $colnumber = 4; + $colnumberend = 7; + } + $colspan = $totalarray['nbfield'] - $colnumber; + $colspanend = $totalarray['nbfield'] - $colnumberend; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + // Show balance of last shown account + $balance = $sous_total_debit - $sous_total_credit; + print ''; + print ''; + if ($balance > 0) + { + print ''; + print ''; + } else { + print ''; + print ''; + } + print ''; + print ''; } -$colspan = $totalarray['nbfield'] - $colnumber; -$colspanend = $totalarray['nbfield'] - $colnumberend; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -// Show balance of last shown account -$balance = $sous_total_debit - $sous_total_credit; -print ''; -print ''; -if ($balance > 0) -{ - print ''; - print ''; -} else { - print ''; - print ''; -} -print ''; -print ''; // Show total line include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; From 46160614b84861e3a62b2f17e4f21f8f84c2f35a Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 31 Dec 2020 03:30:18 +0100 Subject: [PATCH 30/51] Typo --- htdocs/adherents/card.php | 2 +- htdocs/admin/modules.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 418c5cc5674..94904d877e7 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -1761,7 +1761,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { if ($linktoelem) print ($somethingshown?'':'
').$linktoelem; */ - // Shon online payment link + // Show online payment link $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)); if ($useonlinepayment) { diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 4316130e739..472777ee898 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -1137,7 +1137,7 @@ if ($mode == 'deploy') { print ' '; - print ''; + print ''; if (!empty($conf->global->MAIN_UPLOAD_DOC)) { if ($user->admin) { From 9e8c6eb0a107da911083bdce8f25b68da4e5fc0b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 31 Dec 2020 15:05:17 +0100 Subject: [PATCH 31/51] FIX #15849 --- htdocs/core/tpl/objectline_create.tpl.php | 4 ++-- htdocs/product/fournisseurs.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index f028c00d704..1c526f225aa 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -386,10 +386,10 @@ if ($nolinesbefore) {
global->DISPLAY_MARGIN_RATES)) diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index cf5e4fa5b53..2aadd4b3813 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -490,9 +490,9 @@ if ($id > 0 || $ref) if ($rowid) { print ''; - print ''; + print ''; } else { - print ''; + print ''; } print ''; print ''; From c5b419ecb5200c74d8cf24585ca49235f90b17bb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 31 Dec 2020 15:45:59 +0100 Subject: [PATCH 32/51] Removed useless file --- build.xml | 102 ------------------------------------------------------ 1 file changed, 102 deletions(-) delete mode 100644 build.xml diff --git a/build.xml b/build.xml deleted file mode 100644 index c6995ce95f3..00000000000 --- a/build.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 37437901601df5e4ba2d08ba883b3ea8be6c0747 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 31 Dec 2020 15:49:25 +0100 Subject: [PATCH 33/51] Fix warning --- htdocs/webservices/server_order.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 7f2f2ebd43f..8c278768990 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -364,6 +364,7 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') $objectresp = array(); $errorcode = ''; $errorlabel = ''; $error = 0; + $socid = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); @@ -387,7 +388,7 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') if ($result > 0) { // Security for external user - if ($socid && (empty($order->socid) || $socid != $order->socid)) + if ($socid && $socid != $order->socid) { $error++; $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; From d834f6023dcce665043983e61cf0694d270da258 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 31 Dec 2020 16:06:54 +0100 Subject: [PATCH 34/51] Fix rounding --- htdocs/core/class/html.form.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 492a4899376..4ed39694720 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2652,14 +2652,14 @@ class Form if (!empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) { if (!empty($user->rights->stock->lire)) { - $opt .= ' - '.$langs->trans("Stock").':'.$objp->stock; + $opt .= ' - '.$langs->trans("Stock").': '.price(price2num($objp->stock, 'MS')); if ($objp->stock > 0) { $outval .= ' - '; } elseif ($objp->stock <= 0) { $outval .= ' - '; } - $outval .= $langs->transnoentities("Stock").':'.$objp->stock; + $outval .= $langs->transnoentities("Stock").': '.price(price2num($objp->stock, 'MS')); $outval .= ''; if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) // Warning, this option may slow down combo list generation { @@ -2989,14 +2989,14 @@ class Form $novirtualstock = ($showstockinlist == 2); if (!empty($user->rights->stock->lire)) { - $outvallabel .= ' - '.$langs->trans("Stock").':'.$objp->stock; + $outvallabel .= ' - '.$langs->trans("Stock").': '.price(price2num($objp->stock, 'MS')); if ($objp->stock > 0) { $optlabel .= ' - '; } elseif ($objp->stock <= 0) { $optlabel .= ' - '; } - $optlabel .= $langs->transnoentities("Stock").':'.$objp->stock; + $optlabel .= $langs->transnoentities("Stock").':'.price(price2num($objp->stock, 'MS')); $optlabel .= ''; if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) // Warning, this option may slow down combo list generation { From d2345ea96c977077d757951545c41ba7aafd63c1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 31 Dec 2020 16:55:29 +0100 Subject: [PATCH 35/51] Fix warning --- htdocs/webservices/server_thirdparty.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 12b2d3315c8..cd930f47ad3 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -468,12 +468,12 @@ function createThirdParty($authentication, $thirdparty) $newobject->capital = $thirdparty['capital']; - $newobject->barcode = $thirdparty['barcode']; - $newobject->tva_assuj = $thirdparty['vat_used']; - $newobject->tva_intra = $thirdparty['vat_number']; + $newobject->barcode = empty($thirdparty['barcode']) ? '' : $thirdparty['barcode']; + $newobject->tva_assuj = empty($thirdparty['vat_used']) ? 0 : $thirdparty['vat_used']; + $newobject->tva_intra = empty($thirdparty['vat_number']) ? '' : $thirdparty['vat_number']; - $newobject->canvas = $thirdparty['canvas']; - $newobject->particulier = $thirdparty['individual']; + $newobject->canvas = empty($thirdparty['canvas']) ? '' : $thirdparty['canvas']; + $newobject->particulier = empty($thirdparty['individual']) ? 0 : $thirdparty['individual']; $elementtype = 'societe'; From ede38dec3052509c49fddd00da282429319c77d4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Jan 2021 20:56:34 +0100 Subject: [PATCH 36/51] Fix warning --- htdocs/webservices/server_thirdparty.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index cd930f47ad3..4bed0e1be3b 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -486,7 +486,9 @@ function createThirdParty($authentication, $thirdparty) foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; - $newobject->array_options[$key] = $thirdparty[$key]; + if (isset($thirdparty[$key])) { + $newobject->array_options[$key] = $thirdparty[$key]; + } } } From 37e9d139827b1167db475938b4de53dab57a7b86 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Jan 2021 21:25:37 +0100 Subject: [PATCH 37/51] Fix warning --- htdocs/webservices/server_thirdparty.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 4bed0e1be3b..7c97159d0bb 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -510,7 +510,7 @@ function createThirdParty($authentication, $thirdparty) $db->commit(); // Patch to add capability to associate (one) sale representative - if ($thirdparty['commid'] && $thirdparty['commid'] > 0) + if (!empty($thirdparty['commid']) && $thirdparty['commid'] > 0) $newobject->add_commercial($fuser, $thirdparty["commid"]); $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref); From f328bdc3f998f7b6122cd506dec180de4d9fa03d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Jan 2021 22:05:12 +0100 Subject: [PATCH 38/51] Fix var name --- htdocs/admin/tools/listevents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/tools/listevents.php b/htdocs/admin/tools/listevents.php index 00c4bdc36dd..57fc2d07011 100644 --- a/htdocs/admin/tools/listevents.php +++ b/htdocs/admin/tools/listevents.php @@ -211,7 +211,7 @@ if ($result) if ($search_user) $param .= '&search_user='.urlencode($search_user); if ($search_desc) $param .= '&search_desc='.urlencode($search_desc); if ($search_ua) $param .= '&search_ua='.urlencode($search_ua); - if ($search_prefix_sessiona) $param .= '&search_prefix_session='.urlencode($search_prefix_session); + if ($search_prefix_session) $param .= '&search_prefix_session='.urlencode($search_prefix_session); if ($date_startmonth) $param .= "&date_startmonth=".urlencode($date_startmonth); if ($date_startday) $param .= "&date_startday=".urlencode($date_startday); if ($date_startyear) $param .= "&date_startyear=".urlencode($date_startyear); From 3cb71ef53e6cbf775fbf920d314be8db8c4d65d8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Jan 2021 22:55:22 +0100 Subject: [PATCH 39/51] Code comment --- htdocs/install/mysql/migration/repair.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index 033db4620d1..6d662e64893 100644 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -475,7 +475,7 @@ UPDATE llx_chargesociales SET date_creation = tms WHERE date_creation IS NULL; -- VMYSQL4.1 SET sql_mode = 'NO_ZERO_DATE'; -- VMYSQL4.1 update llx_inventory set date_cre = null where DATE(STR_TO_DATE(date_cre, '%Y-%m-%d')) IS NULL; --- Note that you can manually set the default value of a date to CURRENT_TIMESTAMP with: +-- Note that you can manually set the default value of a date or datetime to CURRENT_TIMESTAMP with: --ALTER TABLE llx_table modify column columnname datetime DEFAULT CURRENT_TIMESTAMP; From eb3b0ad6729abf46f078489fe3acee2049351e82 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 13:24:06 +0100 Subject: [PATCH 40/51] Fix warning --- htdocs/webservices/server_thirdparty.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 7c97159d0bb..a4f7e21221d 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -329,8 +329,9 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') 'supplier_code' => $thirdparty->code_fournisseur, 'customer_code_accountancy' => $thirdparty->code_compta, 'supplier_code_accountancy' => $thirdparty->code_compta_fournisseur, - 'fk_user_author' => $thirdparty->fk_user_author, + 'user_creation' => $thirdparty->fk_user_creat, 'date_creation' => dol_print_date($thirdparty->date_creation, 'dayhourrfc'), + 'user_modification' => $thirdparty->fk_user_modif, 'date_modification' => dol_print_date($thirdparty->date_modification, 'dayhourrfc'), 'address' => $thirdparty->address, 'zip' => $thirdparty->zip, From 791a509c6c0c7dd9e1aa6d9b9a7be5d9fac01401 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 13:26:50 +0100 Subject: [PATCH 41/51] Fix warning --- htdocs/webservices/server_thirdparty.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index a4f7e21221d..6d44fe41ff6 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -370,7 +370,9 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') { foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { - $thirdparty_result_fields = array_merge($thirdparty_result_fields, array('options_'.$key => $thirdparty->array_options['options_'.$key])); + if (isset($thirdparty->array_options['options_'.$key])) { + $thirdparty_result_fields = array_merge($thirdparty_result_fields, array('options_'.$key => $thirdparty->array_options['options_'.$key])); + } } } @@ -623,7 +625,9 @@ function updateThirdParty($authentication, $thirdparty) foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; - $object->array_options[$key] = $thirdparty[$key]; + if (isset($thirdparty[$key])) { + $object->array_options[$key] = $thirdparty[$key]; + } } } @@ -728,7 +732,9 @@ function getListOfThirdParties($authentication, $filterthirdparty) { foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { - $extrafieldsOptions['options_'.$key] = $obj->{$key}; + if (isset($obj->{$key})) { + $extrafieldsOptions['options_'.$key] = $obj->{$key}; + } } } From 2727fd70b7167025154922ae1b1094d802c34951 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 2 Jan 2021 14:00:24 +0100 Subject: [PATCH 42/51] FIX: Accountancy - Debug experimental function to validate movements --- htdocs/accountancy/closure/index.php | 88 ++++++++++++- htdocs/accountancy/closure/validate.php | 156 ------------------------ htdocs/core/menus/standard/eldy.lib.php | 4 - htdocs/langs/en_US/accountancy.lang | 4 +- 4 files changed, 89 insertions(+), 163 deletions(-) delete mode 100644 htdocs/accountancy/closure/validate.php diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index ed8fc8ecc7e..a8531ca0887 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -25,11 +25,16 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; // Load translation files required by the page $langs->loadLangs(array("compta", "bills", "other", "main", "accountancy")); +$socid = GETPOST('socid', 'int'); + +$action = GETPOST('action', 'aZ09'); + // Security check if (empty($conf->accounting->enabled)) { accessforbidden(); @@ -39,6 +44,7 @@ if ($user->socid > 0) if (!$user->rights->accounting->fiscalyear->write) accessforbidden(); +$object = new BookKeeping($db); $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); if (GETPOST("year", 'int')) $year_start = GETPOST("year", 'int'); @@ -60,14 +66,91 @@ $year_current = $year_start; /* * Actions */ +if ($action == 'validate_movements_confirm' && $user->rights->accounting->fiscalyear->write) { + $result = $object->fetchAll(); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + // Specify as export : update field date_validated on selected month/year + $error = 0; + $db->begin(); + + $date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); + $date_end = dol_mktime(23, 59, 59, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); + + if (is_array($object->lines)) + { + foreach ($object->lines as $movement) + { + $now = dol_now(); + + $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping"; + $sql .= " SET date_validated = '".$db->idate($now)."'"; + $sql .= " WHERE rowid = ".$movement->id; + $sql .= " AND doc_date >= '" . dol_print_date($date_start, 'dayrfc') . "'"; + $sql .= " AND doc_date <= '" . dol_print_date($date_end, 'dayrfc') . "'"; + + dol_syslog("/accountancy/closure/index.php :: Function validate_movement_confirm Specify movements as validated sql=".$sql, LOG_DEBUG); + $result = $db->query($sql); + if (!$result) + { + $error++; + break; + } + } + } + + if (!$error) + { + $db->commit(); + setEventMessages($langs->trans("AllMovementsWereRecordedAsValidated"), null, 'mesgs'); + } else { + $error++; + $db->rollback(); + setEventMessages($langs->trans("NotAllMovementsCouldBeRecordedAsValidated"), null, 'errors'); + } + header("Location: ".$_SERVER['PHP_SELF']."?year=".$year_start); + exit; + } +} /* * View */ +$form = new Form($db); +$formaccounting = new FormAccounting($db); + llxHeader('', $langs->trans("Closure")); +if ($action == 'validate_movements') { + $form_question = array(); + + $month = isset($conf->global->SOCIETE_FISCAL_MONTH_START) ? intval($conf->global->SOCIETE_FISCAL_MONTH_START) : 1; + $date_start = new DateTime(sprintf('%04d-%02d-%02d', $year_start, $month, 1)); + $date_end = new DateTime(sprintf('%04d-%02d-%02d', $year_start, $month, 1)); + $date_end->add(new DateInterval('P1Y')); + $date_end->sub(new DateInterval('P1D')); + + $form_question['date_start'] = array( + 'name' => 'date_start', + 'type' => 'date', + 'label' => $langs->trans('DateStart'), + 'value' => $date_start->format('Y-m-d') + ); + $form_question['date_end'] = array( + 'name' => 'date_end', + 'type' => 'date', + 'label' => $langs->trans('DateEnd'), + 'value' => $date_end->format('Y-m-d') + ); + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?year='.$year_start, $langs->trans('ValidateMovements'), $langs->trans('DescValidateMovements', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'validate_movements_confirm', $form_question, '', 1, 300); + print $formconfirm; +} + $textprevyear = ''.img_previous().''; $textnextyear = ' '.img_next().''; @@ -80,9 +163,9 @@ print '
'; $y = $year_current; -$buttonbind = ''.$langs->trans("ValidateMovements").''; +$buttonvalidate = ''.$langs->trans("ValidateMovements").''; -print_barre_liste($langs->trans("OverviewOfMovementsNotValidated"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1); +print_barre_liste($langs->trans("OverviewOfMovementsNotValidated"), '', '', '', '', '', '', -1, '', '', 0, $buttonvalidate, '', 0, 1, 1); print '
'; print '
'; + $colspan = (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE) ? 6 : 5); + print ''; print $langs->trans('From'); print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, ''); print ' '; @@ -254,7 +255,7 @@ if ($action != 'export_csv') print '
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_credit - $sous_total_debit)).'
'.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').''.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').'
'.length_accountg($line->numero_compte).''.$description.''.price($opening_balance).''.price($opening_balance).''.price($line->debit).''.price($line->credit).''.price(/*$opening_balance +*/ $line->debit - $line->credit).''.price($opening_balance + $line->debit - $line->credit).''.price($line->debit - $line->credit).''.$link; print '
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num(/*$sous_total_opening_balance +*/ $sous_total_debit - $sous_total_credit, 'MT')).'' . price(price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit, 'MT')) . '' . price(price2num($sous_total_debit - $sous_total_credit, 'MT')) . ' 
'.$langs->trans("AccountBalance").':'.price($total_opening_balance).''.price($total_opening_balance).''.price($total_debit).''.price($total_credit).''.price(price2num(/*$total_opening_balance +*/ $total_debit - $total_credit, 'MT')).'' . price(price2num($total_opening_balance + $total_debit - $total_credit, 'MT')) . '' . price(price2num($total_debit - $total_credit, 'MT')) . ' 
'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', $conf->global->SOCIETE_EMAIL_MANDATORY).'
'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', empty($conf->global->SOCIETE_EMAIL_MANDATORY) ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).''.img_picto('', 'object_email').'
'.$form->editfieldkey('Web', 'url', '', $object, 0).''.img_picto('', 'globe').'
'; - print ''; + print ''; print '
'.$langs->trans("SubledgerAccount").'aaaa
'.$langs->trans("SubledgerAccount").''; if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { From a336e4509802386f15c50afa977b5bd521ca475a Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 30 Dec 2020 08:11:20 +0100 Subject: [PATCH 18/51] FIX: #15751 Miscellaneous payment type change to 0 after updating subledger --- htdocs/compta/bank/class/paymentvarious.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/bank/class/paymentvarious.class.php b/htdocs/compta/bank/class/paymentvarious.class.php index aec104028c0..348c24acd83 100644 --- a/htdocs/compta/bank/class/paymentvarious.class.php +++ b/htdocs/compta/bank/class/paymentvarious.class.php @@ -137,7 +137,7 @@ class PaymentVarious extends CommonObject $sql .= " datev='".$this->db->idate($this->datev)."',"; $sql .= " sens=".(int) $this->sens.","; $sql .= " amount=".price2num($this->amount).","; - $sql .= " fk_typepayment=".(int) $this->fk_typepayment.","; + $sql .= " fk_typepayment=".(int) $this->type_payment.","; $sql .= " num_payment='".$this->db->escape($this->num_payment)."',"; $sql .= " label='".$this->db->escape($this->label)."',"; $sql .= " note='".$this->db->escape($this->note)."',"; From 87a452c6f401eb63e8161fb4740948a9d8f990a4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 12:16:01 +0100 Subject: [PATCH 19/51] Fix warning --- htdocs/user/class/user.class.php | 2 +- htdocs/webservices/server_contact.php | 6 +++--- htdocs/webservices/server_order.php | 4 ++-- htdocs/webservices/server_other.php | 6 +++--- htdocs/webservices/server_user.php | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 98e70cf66b7..7f9c87ab7a7 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1806,7 +1806,7 @@ class User extends CommonObject $adh->pass = $this->pass; - $adh->societe = (empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe); + //$adh->societe = (empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe); $adh->address = $this->address; $adh->town = $this->town; diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index 6fc521a43c7..97b219c7aba 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -270,10 +270,10 @@ function getContact($authentication, $id, $ref_ext) if ($result > 0) { // Only internal user who have contact read permission - // Or for external user who have contact read permission, with restrict on societe_id + // Or for external user who have contact read permission, with restrict on socid if ( - $fuser->rights->societe->contact->lire && !$fuser->societe_id - || ($fuser->rights->societe->contact->lire && ($fuser->societe_id == $contact->socid)) + $fuser->rights->societe->contact->lire && !$fuser->socid + || ($fuser->rights->societe->contact->lire && ($fuser->socid == $contact->socid)) ) { $contact_result_fields = array( 'id' => $contact->id, diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 361b2a08f4a..5cc964dde4e 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -367,7 +367,7 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; // Check parameters if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) @@ -516,7 +516,7 @@ function getOrdersForThirdParty($authentication, $idthirdparty) $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; // Check parameters if (!$error && empty($idthirdparty)) diff --git a/htdocs/webservices/server_other.php b/htdocs/webservices/server_other.php index 61f53f7e275..3494f928cde 100644 --- a/htdocs/webservices/server_other.php +++ b/htdocs/webservices/server_other.php @@ -208,7 +208,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '') $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; // Check parameters if (!$error && (!$file || !$modulepart)) @@ -234,7 +234,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '') $original_file = $check_access['original_file']; // Basic protection (against external users only) - if ($fuser->societe_id > 0) + if ($fuser->socid > 0) { if ($sqlprotectagainstexternals) { @@ -246,7 +246,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '') while ($i < $num) { $obj = $db->fetch_object($resql); - if ($fuser->societe_id != $obj->fk_soc) + if ($fuser->socid != $obj->fk_soc) { $accessallowed = 0; break; diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 8619a952ea1..6c4e472d1c7 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -485,7 +485,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; if (!$error && !$thirdpartywithuser) { @@ -502,7 +502,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) $thirdparty = new Societe($db); // If a contact / company already exists with the email, return the corresponding socid - $sql = "SELECT s.rowid as societe_id FROM ".MAIN_DB_PREFIX."societe as s"; + $sql = "SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid"; $sql .= " WHERE s.entity=".$conf->entity; $sql .= " AND s.email='".$db->escape($thirdpartywithuser['email'])."'"; @@ -690,7 +690,7 @@ function setUserPassword($authentication, $shortuser) $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; if (!$error && !$shortuser) { From 7e9fcfe6649b681aa1e98c100c9c776c211db54c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 12:31:33 +0100 Subject: [PATCH 20/51] Fix warning --- htdocs/webservices/server_order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 5cc964dde4e..7f2f2ebd43f 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -387,10 +387,10 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') if ($result > 0) { // Security for external user - if ($socid && ($socid != $order->socid)) + if ($socid && (empty($order->socid) || $socid != $order->socid)) { $error++; - $errorcode = 'PERMISSION_DENIED'; $errorlabel = $order->socid.'User does not have permission for this request'; + $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } if (!$error) From e34fb394a0078ac8e19a14d6059b796166c3d8fc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 12:38:45 +0100 Subject: [PATCH 21/51] Fix warning --- htdocs/webservices/server_productorservice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index d35dc705b6f..f04ade49f05 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -154,7 +154,7 @@ if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafie } } -if (is_array($extrafield_array)) $productorservice_fields = array_merge($productorservice_fields, $extrafield_array); +if (!empty($extrafield_array) && is_array($extrafield_array)) $productorservice_fields = array_merge($productorservice_fields, $extrafield_array); // Define other specific objects $server->wsdl->addComplexType( From 6a63fea184d0d0c2dfe8378acb4d6dc61968cadb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 13:00:10 +0100 Subject: [PATCH 22/51] FIX #15817 --- htdocs/salaries/class/paymentsalary.class.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/htdocs/salaries/class/paymentsalary.class.php b/htdocs/salaries/class/paymentsalary.class.php index 6aee986396b..807d3537775 100644 --- a/htdocs/salaries/class/paymentsalary.class.php +++ b/htdocs/salaries/class/paymentsalary.class.php @@ -88,6 +88,11 @@ class PaymentSalary extends CommonObject */ public $fk_user_modif; + /** + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. + */ + public $fields = array(); + /** * Constructor From 1ec763fc14f324ea1301fafefd00d3d72bf7b667 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 21:22:54 +0100 Subject: [PATCH 23/51] FIX When creating a new POS sell, the creation date must be modified. --- htdocs/takepos/index.php | 7 ++++--- htdocs/takepos/invoice.php | 13 ++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index d3fc6b7416a..4eeb9dcf9a7 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -448,7 +448,7 @@ function TakeposOrderNotes() { } function Refresh() { - console.log("Refresh"); + console.log("Refresh by reloading place="+place); $("#poslines").load("invoice.php?place="+place, function() { //$('#poslines').scrollTop($('#poslines')[0].scrollHeight); }); @@ -456,9 +456,10 @@ function Refresh() { function New() { // If we go here,it means $conf->global->TAKEPOS_BAR_RESTAURANT is not defined - console.log("New with place = , js place="+place); - invoiceid = $("#invoiceid").val(); + + console.log("New with place = , js place="+place+", invoiceid="+invoiceid); + $.getJSON('/takepos/ajax/ajax.php?action=getInvoice&id='+invoiceid, function(data) { var r; diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 493202376a9..0bc6087409d 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -395,16 +395,9 @@ if ($action == "deleteline") { } } +// Action to delete or discard an invoice if ($action == "delete") { // $placeid is the invoice id (it differs from place) and is defined if the place is set and the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')', so the fetch at begining of page works. - - /*$reg = array(); - if (preg_match('/^(\d+)-(\d+)$/', $place, $reg)) { - - $place = $reg[1]; - var_dump($place); - }*/ - if ($placeid > 0) { $result = $invoice->fetch($placeid); @@ -422,7 +415,9 @@ if ($action == "delete") { } } - $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".$conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}; + $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; + $sql .= " SET fk_soc=".$conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}.", "; + $sql .= " datec = '".$db->idate(dol_now())."'"; $sql .= " WHERE ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'"; $resql1 = $db->query($sql); From 6ef7d3db79b3eda90d89cedb980c6cc50e374750 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 21:43:04 +0100 Subject: [PATCH 24/51] FIX Dates of sales start in TakePOS --- htdocs/langs/en_US/cashdesk.lang | 1 + htdocs/takepos/index.php | 2 +- htdocs/takepos/invoice.php | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/langs/en_US/cashdesk.lang b/htdocs/langs/en_US/cashdesk.lang index 8e529fe92f2..bb433583797 100644 --- a/htdocs/langs/en_US/cashdesk.lang +++ b/htdocs/langs/en_US/cashdesk.lang @@ -99,6 +99,7 @@ CashDeskRefNumberingModules=Numbering module for POS sales CashDeskGenericMaskCodes6 =
{TN} tag is used to add the terminal number TakeposGroupSameProduct=Group same products lines StartAParallelSale=Start a new parallel sale +SaleStartedAt=Sale started at %s ControlCashOpening=Control cash desk at opening POS CloseCashFence=Close cash desk control CashReport=Cash report diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index ef6ca77722a..5e75749dc00 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -832,7 +832,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
  => price(1234.56)'.price(1234.56).'
'.$langs->trans("CurrentTimeZone").''; // Timezone server PHP $a = getServerTimeZoneInt('now'); From 65edc377c3515cbea7a40d27e4d69d9e8773e39e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 22:53:21 +0100 Subject: [PATCH 27/51] FIX Visible date of payment --- htdocs/compta/facture/card.php | 10 +++++++++- htdocs/compta/paiement/class/paiement.class.php | 11 ++++++++++- htdocs/takepos/invoice.php | 6 +++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index aa07de4867e..0970aff1b45 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -4848,7 +4848,15 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $paymentstatic->getNomUrl(1); print ''.dol_print_date($db->jdate($objp->dp), 'dayhour').''; + $dateofpayment = $db->jdate($objp->dp); + $tmparray = dol_getdate($dateofpayment); + if ($tmparray['seconds'] == 0 && $tmparray['minutes'] == 0 && ($tmparray['hours'] == 0 || $tmparray['hours'] == 12)) { // We set hours to 0:00 or 12:00 because we don't know it + print dol_print_date($dateofpayment, 'day'); + } else { // Hours was set to real date of payment (special case for POS for example) + print dol_print_date($dateofpayment, 'dayhour', 'tzuser'); + } + print ''.$label.' '.$objp->num_payment.'
'.$langs->trans("TotalForAccount").' '.$accountg.':'.price($sous_total_debit).''.price($sous_total_credit).'
'.$langs->trans("Balance").':'; + print price($sous_total_debit - $sous_total_credit); + print ''; + print price($sous_total_credit - $sous_total_debit); + print '
'.$langs->trans("TotalForAccount").' '.$accountg.':'.price($sous_total_debit).''.price($sous_total_credit).'
'.$langs->trans("Balance").':'; - print price($sous_total_debit - $sous_total_credit); - print ''; - print price($sous_total_credit - $sous_total_debit); - print '
'.$langs->trans("TotalForAccount").' '.$accountg.':'.price($sous_total_debit).''.price($sous_total_credit).'
'.$langs->trans("Balance").':'; + print price($sous_total_debit - $sous_total_credit); + print ''; + print price($sous_total_credit - $sous_total_debit); + print '
'.$langs->trans("TotalForAccount").' '.$accountg.':'.price($sous_total_debit).''.price($sous_total_credit).'
'.$langs->trans("Balance").':'; - print price($sous_total_debit - $sous_total_credit); - print ''; - print price($sous_total_credit - $sous_total_debit); - print '
product->enabled) || !empty($conf->service->enabled)) { ?> - + - "> + ">
'; @@ -104,6 +187,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b"; $sql .= " WHERE b.doc_date >= '".$db->idate($search_date_start)."'"; $sql .= " AND b.doc_date <= '".$db->idate($search_date_end)."'"; $sql .= " AND b.entity IN (".getEntity('bookkeeping', 0).")"; // We don't share object for accountancy +$sql .= " AND date_validated IS NULL"; dol_syslog('htdocs/accountancy/closure/index.php sql='.$sql, LOG_DEBUG); $resql = $db->query($sql); diff --git a/htdocs/accountancy/closure/validate.php b/htdocs/accountancy/closure/validate.php deleted file mode 100644 index 1013ad1b6ce..00000000000 --- a/htdocs/accountancy/closure/validate.php +++ /dev/null @@ -1,156 +0,0 @@ - - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * \file htdocs/accountancy/closure/validate.php - * \ingroup Accountancy - * \brief Validate entries page - */ - -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; - -// Load translation files required by the page -$langs->loadLangs(array("compta", "bills", "other", "main", "accountancy")); - -// Security check -if (empty($conf->accounting->enabled)) { - accessforbidden(); -} -if ($user->socid > 0) - accessforbidden(); - if (!$user->rights->accounting->fiscalyear->write) - accessforbidden(); - - -$month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); -if (GETPOST("year", 'int')) $year_start = GETPOST("year", 'int'); -else { - $year_start = dol_print_date(dol_now(), '%Y'); - if (dol_print_date(dol_now(), '%m') < $month_start) $year_start--; // If current month is lower that starting fiscal month, we start last year -} -$year_end = $year_start + 1; -$month_end = $month_start - 1; -if ($month_end < 1) -{ - $month_end = 12; - $year_end--; -} -$search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); -$search_date_end = dol_get_last_day($year_end, $month_end); -$year_current = $year_start; - -/* - * Actions - */ - -if ($action == 'validate') -{ - $now = dol_now(); - - // Update database - $db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping as b"; - $sql .= " SET b.date_validated = '".$db->idate($now)."'"; - $sql .= ' WHERE b.date_validated IS NULL'; - - dol_syslog("htdocs/accountancy/closure/validate.php validate", LOG_DEBUG); - $resql = $db->query($sql); - if (!$resql1) { - $error++; - $db->rollback(); - setEventMessages($db->lasterror(), null, 'errors'); - } else { - $db->commit(); - } - // End clean database -} - - -/* - * View - */ - -llxHeader('', $langs->trans("ValidateMovements")); - -$textprevyear = ''.img_previous().''; -$textnextyear = ' '.img_next().''; - - -print load_fiche_titre($langs->trans("ValidateMovements")." ".$textprevyear." ".$langs->trans("Year")." ".$year_start." ".$textnextyear, '', 'title_accountancy'); - -print $langs->trans("DescValidateMovements").'
'; -print '
'; - - -$y = $year_current; - -print_barre_liste($langs->trans("SelectMonthAndValidate"), '', '', '', '', '', '', -1, '', '', 0, '', 'class="right"', 0, 1, 1); - -print '
'; -print '
'; -print ''; -for ($i = 1; $i <= 12; $i++) { - $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1; - if ($j > 12) $j -= 12; - print ''; -} -print ''; - -print ''; -$sql = "SELECT COUNT(b.rowid) as detail,"; -for ($i = 1; $i <= 12; $i++) { - $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1; - if ($j > 12) $j -= 12; - $sql .= " SUM(".$db->ifsql('MONTH(b.doc_date)='.$j, '1', '0').") AS month".str_pad($j, 2, '0', STR_PAD_LEFT).","; -} -$sql .= " COUNT(b.rowid) as total"; -$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b"; -$sql .= " WHERE b.doc_date >= '".$db->idate($search_date_start)."'"; -$sql .= " AND b.doc_date <= '".$db->idate($search_date_end)."'"; -$sql .= " AND b.entity IN (".getEntity('bookkeeping', 0).")"; // We don't share object for accountancy - -dol_syslog('htdocs/accountancy/closure/index.php sql='.$sql, LOG_DEBUG); -$resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); - - while ($row = $db->fetch_row($resql)) { - for ($i = 1; $i <= 12; $i++) { - print ''; - } - print ''; - } - - $db->free($resql); -} else { - print $db->lasterror(); // Show last sql error -} -print ''; -print "
'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).''.$langs->trans("Total").'
'.$row[$i].'

'; - print ''; - print '
'.$row[13].'
\n"; - -print '
'.$langs->trans("ValidateMovements").'
'; -print ''; - -// End of page -llxFooter(); -$db->close(); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 85b63a6f4e3..46950bdc50c 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1334,10 +1334,6 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM // Closure if (!empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2) { $newmenu->add("/accountancy/closure/index.php?mainmenu=accountancy&leftmenu=accountancy_closure", $langs->trans("MenuAccountancyClosure"), 1, $user->rights->accounting->fiscalyear->write, '', $mainmenu, 'closure'); - - if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_closure/', $leftmenu)) { - $newmenu->add("/accountancy/closure/validate.php?leftmenu=accountancy_closure", $langs->trans("MenuAccountancyValidationMovements"), 2, $user->rights->accounting->fiscalyear->write); - } } // Reports diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index c7ce4ac6b0b..bda6502aeed 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -274,11 +274,13 @@ DescVentilExpenseReport=Consult here the list of expense report lines bound (or DescVentilExpenseReportMore=If you setup accounting account on type of expense report lines, the application will be able to make all the binding between your expense report lines and the accounting account of your chart of accounts, just in one click with the button "%s". If account was not set on fees dictionary or if you still have some lines not bound to any account, you will have to make a manual binding from the menu "%s". DescVentilDoneExpenseReport=Consult here the list of the lines of expenses reports and their fees accounting account +Closure=Annual closure DescClosure=Consult here the number of movements by month who are not validated & fiscal years already open OverviewOfMovementsNotValidated=Step 1/ Overview of movements not validated. (Necessary to close a fiscal year) +AllMovementsWereRecordedAsValidated=All movements were recorded as validated +NotAllMovementsCouldBeRecordedAsValidated=Not all movements could be recorded as validated ValidateMovements=Validate movements DescValidateMovements=Any modification or deletion of writing, lettering and deletes will be prohibited. All entries for an exercise must be validated otherwise closing will not be possible -SelectMonthAndValidate=Select month and validate movements ValidateHistory=Bind Automatically AutomaticBindingDone=Automatic binding done From a8d15fafd22707600afb54339ca1b6aef03914ad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 14:17:54 +0100 Subject: [PATCH 43/51] Fix missing span --- htdocs/admin/limits.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/limits.php b/htdocs/admin/limits.php index caf2192a9a3..ed3578522d4 100644 --- a/htdocs/admin/limits.php +++ b/htdocs/admin/limits.php @@ -293,7 +293,7 @@ if (empty($mysoc->country_code)) print ''.$langs->trans("UnitPriceOfProduct").": ".price2num($s, 'MU'); print " x ".$langs->trans("Quantity").": ".$qty; print " - ".$langs->trans("VAT").": ".$vat.'%'; - print '   ->   '.$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."
\n"; + print '   ->   '.$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."
\n"; $s = 10 / 3; $qty = 2; $vat = 10; $tmparray = calcul_price_total($qty, price2num($s, 'MU'), 0, $vat, -1, -1, 0, 'HT', 0, 0, $mysoc, $localtax_array); From 601d4618d4c7bd50ab2e287df8f8ba1a3161cb76 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 14:52:37 +0100 Subject: [PATCH 44/51] Missing vat rates --- htdocs/install/mysql/data/llx_c_tva.sql | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/htdocs/install/mysql/data/llx_c_tva.sql b/htdocs/install/mysql/data/llx_c_tva.sql index 793b29ab640..7156812fb01 100644 --- a/htdocs/install/mysql/data/llx_c_tva.sql +++ b/htdocs/install/mysql/data/llx_c_tva.sql @@ -35,6 +35,16 @@ delete from llx_c_tva; +-- ALGERIA (id country=13) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 131, 13, '0','0','TVA 0%', 1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 132, 13, '9','0','TVA 9%',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 133, 13, '19','0','TVA 19%', 1); + +-- ANGOLA (id country=35) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 351, 35, '0','0','VAT Rate 0', 1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 352, 35, '7','0','VAT reduced rate',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 353, 35, '14','0','VAT standard rate',1); + -- ARGENTINA (id country=23) insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (231, 23, '0','0','IVA Rate 0', 1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (232, 23,'10.5','0','IVA reduced rate',1); @@ -202,6 +212,13 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 1 insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 173, 17, '19','0','Algemeen BTW tarief',1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 174, 17, '21','0','Algemeen BTW tarief (vanaf 1 oktober 2012)',0); +-- NEW CALEDONIA (id country=165) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1651, 165, '0','0','VAT Rate 0', 1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1652, 165, '3','0','VAT standard 3', 1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1653, 165, '6','0','VAT standard 6', 1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1654, 165, '11','0','VAT standard rate', 1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1655, 165, '22','0','VAT standard high', 1); + -- NEW ZEALAND (id country=166) insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1661, 166, '0','0','VAT Rate 0', 1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1662, 166, '15','0','VAT standard rate', 1); @@ -361,16 +378,6 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (23 insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (2322,232, '12','0','VAT 12%',1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (2323,232, '8','0','VAT 8%',1); --- ALGERIA(id country=13) -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 131, 13, '0','0','TVA 0%', 1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 132, 13, '9','0','TVA 9%',1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 133, 13, '19','0','TVA 19%', 1); - --- ANGOLA (id country=35) -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 351, 35, '0','0','VAT Rate 0', 1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 352, 35, '7','0','VAT reduced rate',1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 353, 35, '14','0','VAT standard rate',1); - -- Example of code to insert a vat rate 0 for each country --delete from llx_c_tva where rowid = 1181; -- to delete a record that does not follow rules for rowid (fk_pays+'1') --insert into llx_c_tva(rowid, fk_pays, taux, recuperableonly, note, active) SELECT CONCAT(c.rowid, '1'), c.rowid, 0, 0, 'No VAT', 1 from llx_c_country as c where c.rowid not in (select fk_pays from llx_c_tva); From d46eb08083a5239a0e9196d968e3b2b4bb556363 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 15:36:19 +0100 Subject: [PATCH 45/51] More log and use id to refresh/reload an invoice. --- htdocs/takepos/index.php | 5 +++-- htdocs/takepos/invoice.php | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 4bfeaa57b75..51b6334a2c9 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -155,6 +155,7 @@ var pageactions=0; var place=""; var editaction="qty"; var editnumber=""; +var invoiceid=0; /* var app = this; @@ -448,8 +449,8 @@ function TakeposOrderNotes() { } function Refresh() { - console.log("Refresh by reloading place="+place); - $("#poslines").load("invoice.php?place="+place, function() { + console.log("Refresh by reloading place="+place+" invoiceid="+invoiceid); + $("#poslines").load("invoice.php?place="+place+"&invoiceid="+invoiceid, function() { //$('#poslines').scrollTop($('#poslines')[0].scrollHeight); }); } diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 0909f1b3cca..f31bb90bfcd 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -742,7 +742,7 @@ function DolibarrTakeposPrinting(id) { $( document ).ready(function() { - console.log("Set customer info and sales in header"); + console.log("Set customer info and sales in header placeid= status=statut; ?>"); trans("Customer"); @@ -757,7 +757,14 @@ $( document ).ready(function() { global->TAKEPOS_CAN_EDIT_IF_ALREADY_VALIDATED)) { + // By default, only invoices with a ref not already defined can in list of open invoice we can edit. + $sql .= " WHERE ref LIKE '(PROV-POS".$_SESSION["takeposterminal"]."-0%'"; + } else { + // If TAKEPOS_CAN_EDIT_IF_ALREADY_VALIDATED set, we show also draft invoice that already has a reference defined + $sql .= " WHERE pos_source = ".$_SESSION["takeposterminal"]; + $sql .= " AND module_source = 'takepos'"; + } $sql .= $db->order('datec', 'ASC'); $resql = $db->query($sql); if ($resql) { @@ -767,7 +774,9 @@ $( document ).ready(function() { $num_sale = str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $obj->ref)); echo $num_sale; if (str_replace("-", "", $num_sale) > $max_sale) $max_sale = str_replace("-", "", $num_sale); - echo '\\\';Refresh();">'; + echo '\\\'; invoiceid=\\\''; + echo $obj->rowid; + echo '\\\'; Refresh();">'; if ($placeid == $obj->rowid) echo ""; echo dol_print_date($db->jdate($obj->datec), '%H:%M', 'tzuser'); if ($placeid == $obj->rowid) echo ""; @@ -775,7 +784,7 @@ $( document ).ready(function() { } echo '$("#customerandsales").append(\'\');'; + echo '\\\'; invoiceid=0; Refresh();">\');'; } else { dol_print_error($db); } From 02ae06f24abdd2e7c45f704568c61e3778ef03a8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 15:52:12 +0100 Subject: [PATCH 46/51] Fix warning --- htdocs/webservices/server_thirdparty.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 6d44fe41ff6..d7ded82cc3f 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -329,9 +329,9 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') 'supplier_code' => $thirdparty->code_fournisseur, 'customer_code_accountancy' => $thirdparty->code_compta, 'supplier_code_accountancy' => $thirdparty->code_compta_fournisseur, - 'user_creation' => $thirdparty->fk_user_creat, + 'user_creation' => $thirdparty->user_creation, 'date_creation' => dol_print_date($thirdparty->date_creation, 'dayhourrfc'), - 'user_modification' => $thirdparty->fk_user_modif, + 'user_modification' => $thirdparty->user_modification, 'date_modification' => dol_print_date($thirdparty->date_modification, 'dayhourrfc'), 'address' => $thirdparty->address, 'zip' => $thirdparty->zip, From 2d22c1d5d167622b46f97765cfd7b31dd5bfdc80 Mon Sep 17 00:00:00 2001 From: Aisuko <17001223+AisukoWasTaken@users.noreply.github.com> Date: Fri, 1 Jan 2021 22:53:01 +0100 Subject: [PATCH 47/51] Fix wrong cast for pos_change The variable pos_change was cast in "int" where it should be cast in "float". It results in rounded value making the receipt showing wrong cash exchange. --- htdocs/compta/paiement/class/paiement.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 28635a2df60..6b7f1612836 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -294,7 +294,7 @@ class Paiement extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, ref_ext, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, ext_payment_id, ext_payment_site, fk_user_creat, pos_change)"; $sql .= " VALUES (".$conf->entity.", '".$this->db->escape($this->ref)."', '".$this->db->escape($this->ref_ext)."', '".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', ".$total.", ".$mtotal.", ".$this->paiementid.", "; - $sql .= "'".$this->db->escape($num_payment)."', '".$this->db->escape($note)."', ".($this->ext_payment_id ? "'".$this->db->escape($this->ext_payment_id)."'" : "null").", ".($this->ext_payment_site ? "'".$this->db->escape($this->ext_payment_site)."'" : "null").", ".$user->id.", ".((int) $this->pos_change).")"; + $sql .= "'".$this->db->escape($num_payment)."', '".$this->db->escape($note)."', ".($this->ext_payment_id ? "'".$this->db->escape($this->ext_payment_id)."'" : "null").", ".($this->ext_payment_site ? "'".$this->db->escape($this->ext_payment_site)."'" : "null").", ".$user->id.", ".((float) $this->pos_change).")"; $resql = $this->db->query($sql); if ($resql) From ce0abd17fe543c12606f585ca9085925072deb5a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 16:18:16 +0100 Subject: [PATCH 48/51] Debug v13 --- htdocs/commande/card.php | 6 +++--- htdocs/compta/facture/card-rec.php | 8 ++++---- htdocs/contrat/card.php | 8 ++++---- htdocs/core/lib/functions.lib.php | 18 +++++++++++++----- htdocs/fourn/commande/card.php | 10 +++++----- htdocs/fourn/facture/card.php | 10 +++++----- htdocs/supplier_proposal/card.php | 10 +++++----- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 213819b0915..2ea5c37bf39 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -631,9 +631,9 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); - $price_ht = GETPOST('price_ht'); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); $prod_entry_mode = GETPOST('prod_entry_mode'); if ($prod_entry_mode == 'free') { diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index b978de677a9..097585dbea0 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -437,9 +437,9 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); - $price_ht = GETPOST('price_ht'); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); $prod_entry_mode = GETPOST('prod_entry_mode', 'alpha'); if ($prod_entry_mode == 'free') { @@ -450,7 +450,7 @@ if (empty($reshook)) $tva_tx = ''; } - $qty = GETPOST('qty'.$predef); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = GETPOST('remise_percent'.$predef); // Extrafields diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 2e692dc25c4..d07b8dcc60e 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -383,9 +383,9 @@ if (empty($reshook)) { // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); - $price_ht = price2num(GETPOST('price_ht')); - $price_ht_devise = price2num(GETPOST('multicurrency_price_ht')); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht', 'CR'); if (GETPOST('prod_entry_mode', 'alpha') == 'free') { $idprod = 0; @@ -395,7 +395,7 @@ if (empty($reshook)) $tva_tx = ''; } - $qty = price2num(GETPOST('qty'.$predef)); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = ((GETPOST('remise_percent'.$predef) != '') ? GETPOST('remise_percent'.$predef) : 0); if ($qty == '') diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a156f35292e..8c1765620ec 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4810,7 +4810,7 @@ function price($amount, $form = 0, $outlangs = '', $trunc = 1, $rounding = -1, $ * 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT) * 'MT'=Round to Max for totals with Tax (MAIN_MAX_DECIMALS_TOT) * 'MS'=Round to Max for stock quantity (MAIN_MAX_DECIMALS_STOCK) - * 'CR'=Currency rate + * 'CR'=Foreign currency accurancy * Numeric = Nb of digits for rounding * @param int $option Put 1 if you know that content is already universal format number (so no correction on decimal will be done) * Put 2 if you know that number is a user input (so we know we don't have to fix decimal separator). @@ -4871,10 +4871,18 @@ function price2num($amount, $rounding = '', $option = 0) if ($rounding) { $nbofdectoround = ''; - if ($rounding == 'MU') $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT; - elseif ($rounding == 'MT') $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT; - elseif ($rounding == 'MS') $nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK; - elseif ($rounding == 'CR') $nbofdectoround = 8; + if ($rounding == 'MU') { + $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT; + } + elseif ($rounding == 'MT') { + $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT; + } + elseif ($rounding == 'MS') { + $nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK; + } + elseif ($rounding == 'CR') { + $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8); + } elseif (is_numeric($rounding)) $nbofdectoround = $rounding; //print "RR".$amount.' - '.$nbofdectoround.'
'; if (dol_strlen($nbofdectoround)) $amount = round(is_string($amount) ? (float) $amount : $amount, $nbofdectoround); // $nbofdectoround can be 0. diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 987b80aa3ea..710657e1c16 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -356,24 +356,24 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); $prod_entry_mode = GETPOST('prod_entry_mode'); if ($prod_entry_mode == 'free') { $idprod = 0; - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); } else { $idprod = GETPOST('idprod', 'int'); - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = ''; } - $qty = GETPOST('qty'.$predef); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = GETPOST('remise_percent'.$predef); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index c615817e36f..998ef884766 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1175,7 +1175,7 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); @@ -1183,17 +1183,17 @@ if (empty($reshook)) if ($prod_entry_mode == 'free') { $idprod = 0; - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); } else { $idprod = GETPOST('idprod', 'int'); - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = ''; } - $qty = GETPOST('qty'.$predef); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = GETPOST('remise_percent'.$predef); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index ae40784aa68..a571a207bc5 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -540,24 +540,24 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); $ref_supplier = GETPOST('fourn_ref', 'alpha'); $prod_entry_mode = GETPOST('prod_entry_mode'); if ($prod_entry_mode == 'free') { $idprod = 0; - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); } else { $idprod = GETPOST('idprod', 'int'); - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = ''; } - $qty = GETPOST('qty'.$predef); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = GETPOST('remise_percent'.$predef); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); From fd4dab495f010fc170c94ab3e6d5a47be7e7f605 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 16:51:34 +0100 Subject: [PATCH 49/51] FIX Bad cleaning of VAT rate when numbers are into code --- htdocs/comm/propal/class/propal.class.php | 5 ++++- htdocs/commande/class/commande.class.php | 4 +++- htdocs/compta/facture/class/facture-rec.class.php | 11 ++++++++--- htdocs/compta/facture/class/facture.class.php | 4 +++- htdocs/contrat/class/contrat.class.php | 1 - htdocs/fichinter/class/fichinterrec.class.php | 4 +++- htdocs/fourn/class/fournisseur.commande.class.php | 4 +++- .../class/supplier_proposal.class.php | 11 ++++++++--- 8 files changed, 32 insertions(+), 12 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 144374ab47c..9d6b6c201c5 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -602,6 +602,7 @@ class Propal extends CommonObject // Clean vat code $vat_src_code = ''; + $reg = array(); if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; @@ -779,7 +780,9 @@ class Propal extends CommonObject $qty = price2num($qty); $pu = price2num($pu); $pu_ht_devise = price2num($pu_ht_devise); - $txtva = price2num($txtva); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); $pa_ht = price2num($pa_ht); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 5402d31ba7d..49f8005980f 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3120,7 +3120,9 @@ class Commande extends CommonOrder $pu = price2num($pu); $pa_ht = price2num($pa_ht); $pu_ht_devise = price2num($pu_ht_devise); - $txtva = price2num($txtva); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index c5bd8a987ac..85ecb3f969d 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -849,7 +849,9 @@ class FactureRec extends CommonInvoice $qty = price2num($qty); $pu_ht = price2num($pu_ht); $pu_ttc = price2num($pu_ttc); - $txtva = price2num($txtva); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); if (empty($txtva)) $txtva = 0; @@ -1031,8 +1033,10 @@ class FactureRec extends CommonInvoice $pu_ht = price2num($pu_ht); $pu_ttc = price2num($pu_ttc); $pu_ht_devise = price2num($pu_ht_devise); - $txtva = price2num($txtva); - $txlocaltax1 = price2num($txlocaltax1); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } + $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); if (empty($txlocaltax1)) $txlocaltax1 = 0; if (empty($txlocaltax2)) $txlocaltax2 = 0; @@ -1059,6 +1063,7 @@ class FactureRec extends CommonInvoice // Clean vat code $vat_src_code = ''; + $reg = array(); if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 4bfc36a3e78..392817b0368 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3311,7 +3311,9 @@ class Facture extends CommonInvoice $pu = price2num($pu); $pu_ht_devise = price2num($pu_ht_devise); $pa_ht = price2num($pa_ht); - $txtva = price2num($txtva); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index e38c24565dd..13f0ba644d0 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1502,7 +1502,6 @@ class Contrat extends CommonObject $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - $txtva = price2num($txtva); $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); diff --git a/htdocs/fichinter/class/fichinterrec.class.php b/htdocs/fichinter/class/fichinterrec.class.php index 5b3dfb3a2fc..2d678514182 100644 --- a/htdocs/fichinter/class/fichinterrec.class.php +++ b/htdocs/fichinter/class/fichinterrec.class.php @@ -473,7 +473,9 @@ class FichinterRec extends Fichinter if (!$info_bits) $info_bits = 0; $pu_ht = price2num($pu_ht); $pu_ttc = price2num($pu_ttc); - $txtva = price2num($txtva); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } if ($price_base_type == 'HT') { $pu = $pu_ht; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index af283d8cdf0..123b1eb0046 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2633,7 +2633,9 @@ class CommandeFournisseur extends CommonOrder if (!$qty) $qty = 1; $pu = price2num($pu); $pu_ht_devise = price2num($pu_ht_devise); - $txtva = price2num($txtva); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 33c80f9b6b1..9822c171cd8 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -423,10 +423,13 @@ class SupplierProposal extends CommonObject $qty = price2num($qty); $pu_ht = price2num($pu_ht); $pu_ttc = price2num($pu_ttc); - $txtva = price2num($txtva); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); - $pa_ht = price2num($pa_ht); + + $pa_ht = price2num($pa_ht); if ($price_base_type == 'HT') { $pu = $pu_ht; @@ -682,7 +685,9 @@ class SupplierProposal extends CommonObject $remise_percent = price2num($remise_percent); $qty = price2num($qty); $pu = price2num($pu); - $txtva = price2num($txtva); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); $pa_ht = price2num($pa_ht); From 982f8eb95d2be6300cbcdc2400a8bdf016a76335 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 17:03:26 +0100 Subject: [PATCH 50/51] Fix syntax error --- htdocs/contrat/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index d07b8dcc60e..9b1a3b34808 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -385,7 +385,7 @@ if (empty($reshook)) $predef = ''; $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); $price_ht = price2num(GETPOST('price_ht'), 'MU'); - $price_ht_devise = price2num(GETPOST('multicurrency_price_ht', 'CR'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht', 'CR')); if (GETPOST('prod_entry_mode', 'alpha') == 'free') { $idprod = 0; From 2d1121031a886398a31594684785ed8040bc8558 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 17:04:08 +0100 Subject: [PATCH 51/51] var not defined --- htdocs/contrat/card.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 9b1a3b34808..64f8fd92477 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -89,6 +89,7 @@ $extralabelslines = $extrafields->fetch_name_optionals_label($object->table_elem $permissionnote = $user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->contrat->creer; // Used by the include of actions_dellink.inc.php +$error = 0; /*