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. 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 diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index d1cee5ff59d..029550192f0 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -238,18 +238,18 @@ if ($action == 'create') { print $formaccounting->select_account($object->account_parent, 'account_parent', 1, null, 0, 0, 'minwidth200'); print ''; - // Category - print ''.$langs->trans("AccountingCategory").''; - print ''; - $formaccounting->select_accounting_category($object->account_category, 'account_category', 1, 0, 1); - print ''; - // Chart of accounts type print ''.$langs->trans("Pcgtype").''; print ''; print ''; print ''; + // Category + print ''.$langs->trans("AccountingCategory").''; + print ''; + $formaccounting->select_accounting_category($object->account_category, 'account_category', 1, 0, 1); + print ''; + print ''; print dol_get_fiche_end(); @@ -300,18 +300,18 @@ if ($action == 'create') { print $formaccounting->select_account($object->account_parent, 'account_parent', 1); print ''; - // Category - print ''.$langs->trans("AccountingCategory").''; - print ''; - $formaccounting->select_accounting_category($object->account_category, 'account_category', 1); - print ''; - // Chart of accounts type print ''.$langs->trans("Pcgtype").''; print ''; print ''; print ''; + // Category + print ''.$langs->trans("AccountingCategory").''; + print ''; + $formaccounting->select_accounting_category($object->account_category, 'account_category', 1); + print ''; + print ''; print dol_get_fiche_end(); diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index b0e813be970..1547983da0c 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -78,7 +78,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) { @@ -242,10 +242,12 @@ if ($action != 'export_csv') print ''; } + $colspan = (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE) ? 5 : 4); + print ''; print ''; - print ''; print_liste_field_titre("AccountAccounting", $_SERVER['PHP_SELF'], "t.numero_compte", "", $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); @@ -278,22 +280,30 @@ if ($action != 'export_csv') $accountingaccountstatic = new AccountingAccount($db); - $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"; + // TODO Debug - This feature 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. + 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) { + // reset before the fetch (in case of the fetch fails) + $accountingaccountstatic->id = 0; + $accountingaccountstatic->account_number = ''; + $accountingaccountstatic->fetch(null, $line->numero_compte, true); if (!empty($accountingaccountstatic->account_number)) { $accounting_account = $accountingaccountstatic->getNomUrl(0, 1); @@ -311,8 +321,8 @@ if ($action != 'export_csv') $root_account_description = $tmparrayforrootaccount['label']; $root_account_number = $tmparrayforrootaccount['account_number']; - if (empty($accountingaccountstatic->account_number)) { - $link = ''.img_edit_add().''; + if (empty($accountingaccountstatic->label) && $accountingaccountstatic->id > 0) { + $link = ''.img_edit().''; } if (!empty($show_subgroup)) @@ -322,17 +332,22 @@ if ($action != 'export_csv') // Show subtotal per accounting account if ($displayed_account != "") { 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 ''; } // Show first line of a break print ''; - print ''; + print ''; print ''; $displayed_account = $root_account_number; @@ -344,10 +359,14 @@ if ($action != 'export_csv') 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"; @@ -360,12 +379,28 @@ if ($action != 'export_csv') if (!empty($show_subgroup)) { - print ''; + print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) 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 ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + print ''; + } else { + print ''; + } print "\n"; print ''; 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'; 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'; 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 '
'; + print ''; print $langs->trans('From'); print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, ''); print ' '; @@ -261,7 +263,7 @@ if ($action != 'export_csv') print '
'.$langs->trans("SubTotal").':'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_opening_balance + $sous_total_credit - $sous_total_debit)).''.price(price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit)).''.price(price2num($sous_total_debit - $sous_total_credit)).'
'.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').''.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').'
'.$accounting_account.''.price($opening_balance).''.price($opening_balance).''.price($line->debit).''.price($line->credit).''.price(price2num($opening_balance + $line->debit - $line->credit, 'MT')).''.price(price2num($opening_balance + $line->debit - $line->credit, 'MT')).''.price(price2num($line->debit - $line->credit, 'MT')).''.$link; print '
'.$langs->trans("SubTotal").':'.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')) . '' . price(price2num($sous_total_debit - $sous_total_credit, 'MT')) . '
'.$langs->trans("AccountBalance").':'.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')) . '' . price(price2num($total_debit - $total_credit, 'MT')) . '
'.$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 '
'; @@ -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/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/limits.php b/htdocs/admin/limits.php index 34da6f7d34e..9132cc4b4d1 100644 --- a/htdocs/admin/limits.php +++ b/htdocs/admin/limits.php @@ -299,7 +299,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); diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index e9984316394..472777ee898 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'); @@ -1139,7 +1137,7 @@ if ($mode == 'deploy') { print ' '; - print ''; + print ''; if (!empty($conf->global->MAIN_UPLOAD_DOC)) { if ($user->admin) { diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php index 80454403a32..1100b86f412 100644 --- a/htdocs/admin/system/dolibarr.php +++ b/htdocs/admin/system/dolibarr.php @@ -224,7 +224,7 @@ if (($thousand != ',' && $thousand != '.') || ($thousand != ' ')) print '  => price(1234.56)'.price(1234.56).''."\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 ''.$langs->trans("CurrentTimeZone").''; // Timezone server PHP $a = getServerTimeZoneInt('now'); 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); 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/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"; } diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f572f6110bf..10a2238088b 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -600,6 +600,7 @@ class Propal extends CommonObject // Clean vat code $reg = array(); $vat_src_code = ''; + $reg = array(); if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; @@ -771,7 +772,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/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/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index d8fdb51141e..3cc0fa72ae6 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3060,7 +3060,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/bank/class/paymentvarious.class.php b/htdocs/compta/bank/class/paymentvarious.class.php index 6c2e12ba500..d05e2d339a6 100644 --- a/htdocs/compta/bank/class/paymentvarious.class.php +++ b/htdocs/compta/bank/class/paymentvarious.class.php @@ -200,7 +200,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)."',"; diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index dfdad0b589b..0efe367089c 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -408,7 +408,7 @@ if ($action == 'create') // Subledger account if (!empty($conf->accounting->enabled)) { - print ''.$langs->trans("SubledgerAccount").'aaaa'; + print ''.$langs->trans("SubledgerAccount").''; print ''; if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, ''); 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/compta/facture/card.php b/htdocs/compta/facture/card.php index 733325f901b..d9c272df559 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -4738,7 +4738,15 @@ if ($action == 'create') print ''; print $paymentstatic->getNomUrl(1); print ''; - print ''.dol_print_date($db->jdate($objp->dp), 'dayhour').''; + print ''; + $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 = ($langs->trans("PaymentType".$objp->payment_code) != ("PaymentType".$objp->payment_code)) ? $langs->trans("PaymentType".$objp->payment_code) : $objp->payment_label; print ''.$label.' '.$objp->num_payment.''; if (!empty($conf->banque->enabled)) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 9c0d191f0cf..29e78f90af8 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -853,7 +853,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,7 +1033,9 @@ class FactureRec extends CommonInvoice $pu_ht = price2num($pu_ht); $pu_ttc = price2num($pu_ttc); $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); if (empty($txlocaltax1)) $txlocaltax1 = 0; @@ -1057,6 +1061,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 ac1270ed550..24f5b748e52 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3283,7 +3283,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/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 863e841f716..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) @@ -1171,9 +1171,19 @@ class Paiement extends CommonObject if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips $result = ''; + $label = img_picto('', $this->picto).' '.$langs->trans("Payment").'
'; $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/contrat/card.php b/htdocs/contrat/card.php index 2e692dc25c4..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; /* @@ -383,9 +384,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 +396,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/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 9bdb1d5a846..36edee80669 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1465,7 +1465,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/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); 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 { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 33a09f541c6..8c1765620ec 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() @@ -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. @@ -7123,9 +7131,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/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/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/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/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) { product->enabled) || !empty($conf->service->enabled)) { ?> - + - "> + "> global->DISPLAY_MARGIN_RATES)) diff --git a/htdocs/fichinter/class/fichinterrec.class.php b/htdocs/fichinter/class/fichinterrec.class.php index 046d35b62ce..418e1232bb8 100644 --- a/htdocs/fichinter/class/fichinterrec.class.php +++ b/htdocs/fichinter/class/fichinterrec.class.php @@ -491,7 +491,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; @@ -499,7 +501,6 @@ class FichinterRec extends Fichinter $pu = $pu_ttc; } - // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 6c6347f67f7..5464116c1ed 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2546,9 +2546,12 @@ class CommandeFournisseur extends CommonOrder $remise_percent = price2num($remise_percent); $qty = price2num($qty); + 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/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/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/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); 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; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index d4233dc4d82..bda6502aeed 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -251,7 +251,7 @@ PaymentsNotLinkedToProduct=Payment not linked to any product / service OpeningBalance=Opening balance ShowOpeningBalance=Show opening balance HideOpeningBalance=Hide opening balance -ShowSubtotalByGroup=Show subtotal by group +ShowSubtotalByGroup=Show subtotal by level Pcgtype=Group of account PcgtypeDesc=Group of account are used as predefined 'filter' and 'grouping' criteria for some accounting reports. For example, 'INCOME' or 'EXPENSE' are used as groups for accounting accounts of products to build the expense/income report. @@ -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 diff --git a/htdocs/langs/en_US/cashdesk.lang b/htdocs/langs/en_US/cashdesk.lang index 8e529fe92f2..88ff8fecdb6 100644 --- a/htdocs/langs/en_US/cashdesk.lang +++ b/htdocs/langs/en_US/cashdesk.lang @@ -99,7 +99,8 @@ 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 -ControlCashOpening=Control cash desk at opening POS +SaleStartedAt=Sale started at %s +ControlCashOpening=Control cash popup at opening POS CloseCashFence=Close cash desk control CashReport=Cash report MainPrinterToUse=Main printer to use 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 ''; diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 648ce4840fe..a624daf8afb 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -533,9 +533,6 @@ if ($resql) //'builddoc'=>$langs->trans("PDFMerge"), //'presend'=>$langs->trans("SendByMail"), ); - - $rightskey = 'produit'; - if ($type == Product::TYPE_SERVICE) $rightskey = 'service'; if ($user->rights->{$rightskey}->supprimer) $arrayofmassactions['predelete'] = "".$langs->trans("Delete"); if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); 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 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 ''.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', $conf->global->SOCIETE_EMAIL_MANDATORY).''; + print ''.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', empty($conf->global->SOCIETE_EMAIL_MANDATORY) ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).''; print ''.img_picto('', 'object_email').' '; print ''.$form->editfieldkey('Web', 'url', '', $object, 0).''; print ''.img_picto('', 'globe').' '; @@ -1366,7 +1366,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; } elseif (!empty($object->socialnetworks[$key])) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 0aeb64aa427..4c25a002a8f 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,44 +842,42 @@ 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; } 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; } } 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,28 +950,21 @@ 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) - { - if ($rescode == -1) - { + if ($rescode != 0 && $rescode != -5) { + if ($rescode == -1) { $this->errors[] = 'ErrorBadCustomerCodeSyntax'; - } elseif ($rescode == -2) - { + } elseif ($rescode == -2) { $this->errors[] = 'ErrorCustomerCodeRequired'; - } elseif ($rescode == -3) - { + } elseif ($rescode == -3) { $this->errors[] = 'ErrorCustomerCodeAlreadyUsed'; - } elseif ($rescode == -4) - { + } elseif ($rescode == -4) { $this->errors[] = 'ErrorPrefixRequired'; } else { $this->errors[] = 'ErrorUnknownOnCustomerCodeCheck'; @@ -974,22 +974,16 @@ class Societe extends CommonObject } } - if ($this->fournisseur) - { + if ($this->fournisseur) { $rescode = $this->check_codefournisseur(); - if ($rescode <> 0) - { - if ($rescode == -1) - { + if ($rescode != 0 && $rescode != -5) { + if ($rescode == -1) { $this->errors[] = 'ErrorBadSupplierCodeSyntax'; - } elseif ($rescode == -2) - { + } elseif ($rescode == -2) { $this->errors[] = 'ErrorSupplierCodeRequired'; - } elseif ($rescode == -3) - { + } elseif ($rescode == -3) { $this->errors[] = 'ErrorSupplierCodeAlreadyUsed'; - } elseif ($rescode == -4) - { + } elseif ($rescode == -4) { $this->errors[] = 'ErrorPrefixRequired'; } else { $this->errors[] = 'ErrorUnknownOnSupplierCodeCheck'; @@ -1000,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").')'; @@ -1024,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").')'; @@ -1036,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").')'; } @@ -1059,7 +1042,9 @@ class Societe extends CommonObject } } - if ($error) $result = -4; + if ($error) { + $result = -4; + } return $result; } @@ -1082,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; @@ -1126,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; } @@ -1142,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); @@ -1152,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; @@ -1205,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 "; @@ -1272,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"); @@ -1327,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"); } @@ -1345,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); } @@ -1368,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"); @@ -1380,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 @@ -1395,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++; } @@ -1413,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; @@ -1449,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; @@ -1490,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'; @@ -1533,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; @@ -1642,7 +1647,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; @@ -1702,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; } @@ -1719,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'; @@ -1730,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]); @@ -1804,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); } } @@ -1859,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; } @@ -1872,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; } @@ -1906,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(); @@ -1925,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; @@ -1941,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; @@ -1969,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(); @@ -1988,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; @@ -2004,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; @@ -2037,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. } @@ -2076,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; + } } /** @@ -2101,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; @@ -2127,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)) { @@ -2143,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; @@ -2187,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; } @@ -2205,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; } @@ -2228,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 { @@ -2298,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"); } } @@ -2327,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.' - '; @@ -2356,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.= '
';*/ @@ -2375,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 @@ -2478,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; @@ -2501,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; } @@ -2533,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"); @@ -2559,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) @@ -2581,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.">"; } @@ -2612,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 : ''); @@ -2670,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++; @@ -2703,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); @@ -2737,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 { @@ -2841,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(); @@ -2873,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(); @@ -2902,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; @@ -2936,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; @@ -2976,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; @@ -3010,20 +3016,22 @@ 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() { // 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(); @@ -3054,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 { @@ -3081,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; } @@ -3098,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 @@ -3127,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; @@ -3168,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"; @@ -3192,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 { @@ -3208,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 @@ -3228,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; @@ -3340,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); @@ -3420,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 { @@ -3447,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; @@ -3493,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; @@ -3529,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; @@ -3551,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; } @@ -3582,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 : ''; @@ -3608,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 { @@ -3658,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 @@ -3677,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 @@ -3701,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; @@ -3715,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; @@ -3820,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; + } } /** @@ -3845,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; + } } /** @@ -3866,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; @@ -3900,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; @@ -3955,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); } } @@ -4009,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; @@ -4021,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(); + } } /** @@ -4047,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; @@ -4059,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(); + } } /** @@ -4086,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(); @@ -4095,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())."'"; @@ -4109,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 { @@ -4127,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(); @@ -4147,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(); } } @@ -4181,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"); + } } @@ -4203,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"); @@ -4293,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; @@ -4325,7 +4409,6 @@ class Societe extends CommonObject $salesrep = array($salesrep); } - $to_del = array(); // Nothing to delete $to_add = $salesrep; if ($onlyAdd === false) { @@ -4347,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; } @@ -4365,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; + } } /** @@ -4394,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; } 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); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 8a74b14095b..a939b95ffca 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -416,10 +416,12 @@ 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; @@ -673,7 +675,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); diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 961168221f6..ec012a8ddcd 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -167,6 +167,7 @@ var pageactions=0; var place=""; var editaction="qty"; var editnumber=""; +var invoiceid=0; /* var app = this; @@ -483,17 +484,18 @@ function TakeposOrderNotes() { } function Refresh() { - console.log("Refresh"); - $("#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); }); } 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; @@ -831,7 +833,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {