From f273273129526bb0ecaccf2a42932a96166fa449 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 22 Dec 2020 06:57:55 +0100 Subject: [PATCH 1/5] FIX: Accountancy - Retire entire opening balance feature --- htdocs/accountancy/bookkeeping/balance.php | 46 +++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 29e56cd4233..961a012f396 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -77,7 +77,7 @@ $form = new Form($db); if (empty($search_date_start) && !GETPOSTISSET('formfilteraction')) { $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear "; - $sql .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'"; + $sql .= " WHERE date_start < '".$db->idate(dol_now())."' AND date_end > '".$db->idate(dol_now())."'"; $sql .= $db->plimit(1); $res = $db->query($sql); if ($res->num_rows > 0) { @@ -237,7 +237,7 @@ if ($action != 'export_csv') print ''; print ''; - print ''; print_liste_field_titre("AccountAccounting", $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); - print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); + // print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Balance", $_SERVER["PHP_SELF"], "", $param, "", 'class="right"', $sortfield, $sortorder); @@ -265,10 +265,13 @@ if ($action != 'export_csv') $total_credit = 0; $sous_total_debit = 0; $sous_total_credit = 0; - $total_opening_balance = 0; - $sous_total_opening_balance = 0; + // $total_opening_balance = 0; + // $sous_total_opening_balance = 0; $displayed_account = ""; + // TODO Debug - In French accounting, this functionality is dangerous, it takes all the entries and adds all the accounts + // without time and class limits (Class 6 and 7 accounts ???) and does not take into account the "a-nouveau" journal. + /* $sql = "SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t"; $sql .= " WHERE t.entity = ".$conf->entity; // Never do sharing into accounting features @@ -282,6 +285,7 @@ if ($action != 'export_csv') $arr = $resql->fetch_array(); $opening_balances["'".$arr['numero_compte']."'"] = $arr['opening_balance']; } + */ foreach ($object->lines as $line) { @@ -290,8 +294,8 @@ if ($action != 'export_csv') $total_credit += $line->credit; $description = $object->get_compte_desc($line->numero_compte); // Search description of the account $root_account_description = $object->get_compte_racine($line->numero_compte); - $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0; - $total_opening_balance += $opening_balance; + // $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0; + // $total_opening_balance += $opening_balance; if (empty($description)) { $link = ''.img_edit_add().''; } @@ -302,30 +306,34 @@ if ($action != 'export_csv') { // Display a sub-total per account if ($displayed_account != "") { - print ''; + print ''; + // print ''; + print ''; + print ''; + print ''; print "\n"; print ''; } // Show first line of a break print ''; - print ''; + print ''; print ''; $displayed_account = $root_account_description; $sous_total_debit = 0; $sous_total_credit = 0; - $sous_total_opening_balance = 0; + // $sous_total_opening_balance = 0; } // $object->get_compte_racine($line->numero_compte); print ''; print ''; - print ''; + // print ''; print ''; print ''; - print ''; + print ''; print ''; print "\n"; @@ -333,14 +341,22 @@ if ($action != 'export_csv') // Records the sub-total $sous_total_debit += $line->debit; $sous_total_credit += $line->credit; - $sous_total_opening_balance += $opening_balance; + // $sous_total_opening_balance += $opening_balance; } - print ''; + print ''; + // print ''; + print ''; + print ''; + print ''; print "\n"; print ''; - print ''; + print ''; + // print ''; + print ''; + print ''; + print ''; print "\n"; print ''; From 26791714cee70a00bc05243c49645c0d47ee4cff Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 28 Dec 2020 03:07:33 +0100 Subject: [PATCH 2/5] Fix : Introduce constant ACCOUNTANCY_SHOW_OPENING_BALANCE --- htdocs/accountancy/bookkeeping/balance.php | 76 +++++++++++++--------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 961a012f396..b71c633b1e5 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -237,7 +237,8 @@ if ($action != 'export_csv') print '
'; + print ''; print $langs->trans('From'); print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, ''); print ' '; @@ -254,7 +254,7 @@ if ($action != 'export_csv') print '
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_credit - $sous_total_debit)).'
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_credit - $sous_total_debit)).' 
'.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').''.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').'
'.length_accountg($line->numero_compte).''.$description.''.price($opening_balance).''.price($opening_balance).''.price($line->debit).''.price($line->credit).''.price($opening_balance + $line->debit - $line->credit).''.price(/*$opening_balance +*/ $line->debit - $line->credit).''.$link; print '
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit, 'MT')).'
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num(/*$sous_total_opening_balance +*/ $sous_total_debit - $sous_total_credit, 'MT')).' 
'.$langs->trans("AccountBalance").':'.price($total_opening_balance).''.price($total_debit).''.price($total_credit).''.price(price2num($total_opening_balance + $total_debit - $total_credit, 'MT')).'
'.$langs->trans("AccountBalance").':'.price($total_opening_balance).''.price($total_debit).''.price($total_credit).''.price(price2num(/*$total_opening_balance +*/ $total_debit - $total_credit, 'MT')).' 
'; print ''; - print ''; print_liste_field_titre("AccountAccounting", $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); - // print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Balance", $_SERVER["PHP_SELF"], "", $param, "", 'class="right"', $sortfield, $sortorder); @@ -265,27 +266,29 @@ if ($action != 'export_csv') $total_credit = 0; $sous_total_debit = 0; $sous_total_credit = 0; - // $total_opening_balance = 0; - // $sous_total_opening_balance = 0; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + $total_opening_balance = 0; + $sous_total_opening_balance = 0; + } $displayed_account = ""; // TODO Debug - In French accounting, this functionality is dangerous, it takes all the entries and adds all the accounts // without time and class limits (Class 6 and 7 accounts ???) and does not take into account the "a-nouveau" journal. - /* - $sql = "SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t"; - $sql .= " WHERE t.entity = ".$conf->entity; // Never do sharing into accounting features - $sql .= " AND t.doc_date < '".$db->idate($search_date_start)."'"; - $sql .= " GROUP BY t.numero_compte"; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + $sql = "SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; + $sql .= " WHERE t.entity = " . $conf->entity; // Never do sharing into accounting features + $sql .= " AND t.doc_date < '" . $db->idate($search_date_start) . "'"; + $sql .= " GROUP BY t.numero_compte"; - $resql = $db->query($sql); - $nrows = $resql->num_rows; - $opening_balances = array(); - for ($i = 0; $i < $nrows; $i++) { - $arr = $resql->fetch_array(); - $opening_balances["'".$arr['numero_compte']."'"] = $arr['opening_balance']; + $resql = $db->query($sql); + $nrows = $resql->num_rows; + $opening_balances = array(); + for ($i = 0; $i < $nrows; $i++) { + $arr = $resql->fetch_array(); + $opening_balances["'" . $arr['numero_compte'] . "'"] = $arr['opening_balance']; + } } - */ foreach ($object->lines as $line) { @@ -294,8 +297,10 @@ if ($action != 'export_csv') $total_credit += $line->credit; $description = $object->get_compte_desc($line->numero_compte); // Search description of the account $root_account_description = $object->get_compte_racine($line->numero_compte); - // $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0; - // $total_opening_balance += $opening_balance; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0; + $total_opening_balance += $opening_balance; + } if (empty($description)) { $link = ''.img_edit_add().''; } @@ -307,7 +312,7 @@ if ($action != 'export_csv') // Display a sub-total per account if ($displayed_account != "") { print ''; - // print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''; print ''; print ''; print ''; @@ -317,23 +322,28 @@ if ($action != 'export_csv') // Show first line of a break print ''; - print ''; + $colspan = (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE) ? 7 : 6); + print ''; print ''; $displayed_account = $root_account_description; $sous_total_debit = 0; $sous_total_credit = 0; - // $sous_total_opening_balance = 0; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) $sous_total_opening_balance = 0; } // $object->get_compte_racine($line->numero_compte); print ''; print ''; - // print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''; print ''; print ''; - print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + print ''; + } else { + print ''; + } print ''; print "\n"; @@ -341,22 +351,30 @@ if ($action != 'export_csv') // Records the sub-total $sous_total_debit += $line->debit; $sous_total_credit += $line->credit; - // $sous_total_opening_balance += $opening_balance; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) $sous_total_opening_balance += $opening_balance; } print ''; - // print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''; print ''; print ''; - print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + print ''; + } else { + print ''; + } print "\n"; print ''; print ''; - // print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''; print ''; print ''; - print ''; + if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) { + print ''; + } else { + print ''; + } print "\n"; print ''; From 87a452c6f401eb63e8161fb4740948a9d8f990a4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 12:16:01 +0100 Subject: [PATCH 3/5] Fix warning --- htdocs/user/class/user.class.php | 2 +- htdocs/webservices/server_contact.php | 6 +++--- htdocs/webservices/server_order.php | 4 ++-- htdocs/webservices/server_other.php | 6 +++--- htdocs/webservices/server_user.php | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 98e70cf66b7..7f9c87ab7a7 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1806,7 +1806,7 @@ class User extends CommonObject $adh->pass = $this->pass; - $adh->societe = (empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe); + //$adh->societe = (empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe); $adh->address = $this->address; $adh->town = $this->town; diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index 6fc521a43c7..97b219c7aba 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -270,10 +270,10 @@ function getContact($authentication, $id, $ref_ext) if ($result > 0) { // Only internal user who have contact read permission - // Or for external user who have contact read permission, with restrict on societe_id + // Or for external user who have contact read permission, with restrict on socid if ( - $fuser->rights->societe->contact->lire && !$fuser->societe_id - || ($fuser->rights->societe->contact->lire && ($fuser->societe_id == $contact->socid)) + $fuser->rights->societe->contact->lire && !$fuser->socid + || ($fuser->rights->societe->contact->lire && ($fuser->socid == $contact->socid)) ) { $contact_result_fields = array( 'id' => $contact->id, diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 361b2a08f4a..5cc964dde4e 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -367,7 +367,7 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; // Check parameters if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) @@ -516,7 +516,7 @@ function getOrdersForThirdParty($authentication, $idthirdparty) $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; // Check parameters if (!$error && empty($idthirdparty)) diff --git a/htdocs/webservices/server_other.php b/htdocs/webservices/server_other.php index 61f53f7e275..3494f928cde 100644 --- a/htdocs/webservices/server_other.php +++ b/htdocs/webservices/server_other.php @@ -208,7 +208,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '') $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; // Check parameters if (!$error && (!$file || !$modulepart)) @@ -234,7 +234,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '') $original_file = $check_access['original_file']; // Basic protection (against external users only) - if ($fuser->societe_id > 0) + if ($fuser->socid > 0) { if ($sqlprotectagainstexternals) { @@ -246,7 +246,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '') while ($i < $num) { $obj = $db->fetch_object($resql); - if ($fuser->societe_id != $obj->fk_soc) + if ($fuser->socid != $obj->fk_soc) { $accessallowed = 0; break; diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 8619a952ea1..6c4e472d1c7 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -485,7 +485,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; if (!$error && !$thirdpartywithuser) { @@ -502,7 +502,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) $thirdparty = new Societe($db); // If a contact / company already exists with the email, return the corresponding socid - $sql = "SELECT s.rowid as societe_id FROM ".MAIN_DB_PREFIX."societe as s"; + $sql = "SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid"; $sql .= " WHERE s.entity=".$conf->entity; $sql .= " AND s.email='".$db->escape($thirdpartywithuser['email'])."'"; @@ -690,7 +690,7 @@ function setUserPassword($authentication, $shortuser) $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if ($fuser->societe_id) $socid = $fuser->societe_id; + if ($fuser->socid) $socid = $fuser->socid; if (!$error && !$shortuser) { From 7e9fcfe6649b681aa1e98c100c9c776c211db54c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 12:31:33 +0100 Subject: [PATCH 4/5] Fix warning --- htdocs/webservices/server_order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 5cc964dde4e..7f2f2ebd43f 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -387,10 +387,10 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') if ($result > 0) { // Security for external user - if ($socid && ($socid != $order->socid)) + if ($socid && (empty($order->socid) || $socid != $order->socid)) { $error++; - $errorcode = 'PERMISSION_DENIED'; $errorlabel = $order->socid.'User does not have permission for this request'; + $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } if (!$error) From e34fb394a0078ac8e19a14d6059b796166c3d8fc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Dec 2020 12:38:45 +0100 Subject: [PATCH 5/5] Fix warning --- htdocs/webservices/server_productorservice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index d35dc705b6f..f04ade49f05 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -154,7 +154,7 @@ if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafie } } -if (is_array($extrafield_array)) $productorservice_fields = array_merge($productorservice_fields, $extrafield_array); +if (!empty($extrafield_array) && is_array($extrafield_array)) $productorservice_fields = array_merge($productorservice_fields, $extrafield_array); // Define other specific objects $server->wsdl->addComplexType(
'; + $colspan = (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE) ? 6 : 5); + print ''; print $langs->trans('From'); print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, ''); print ' '; @@ -254,7 +255,7 @@ if ($action != 'export_csv') print '
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_credit - $sous_total_debit)).'
'.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').''.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').'
'.length_accountg($line->numero_compte).''.$description.''.price($opening_balance).''.price($opening_balance).''.price($line->debit).''.price($line->credit).''.price(/*$opening_balance +*/ $line->debit - $line->credit).''.price($opening_balance + $line->debit - $line->credit).''.price($line->debit - $line->credit).''.$link; print '
'.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num(/*$sous_total_opening_balance +*/ $sous_total_debit - $sous_total_credit, 'MT')).'' . price(price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit, 'MT')) . '' . price(price2num($sous_total_debit - $sous_total_credit, 'MT')) . ' 
'.$langs->trans("AccountBalance").':'.price($total_opening_balance).''.price($total_opening_balance).''.price($total_debit).''.price($total_credit).''.price(price2num(/*$total_opening_balance +*/ $total_debit - $total_credit, 'MT')).'' . price(price2num($total_opening_balance + $total_debit - $total_credit, 'MT')) . '' . price(price2num($total_debit - $total_credit, 'MT')) . '