diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 736aec48644..736581e9248 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -23,6 +23,7 @@ * \ingroup Advanced accountancy * \brief Balance of book keeping */ + require '../../main.inc.php'; // Class @@ -184,7 +185,7 @@ else { print_liste_field_titre($langs->trans("Labelcompte"), $_SERVER['PHP_SELF'], "t.label_compte", "", $options, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); - print_liste_field_titre($langs->trans("Solde"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Solde"), $_SERVER["PHP_SELF"], "", $options, "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); print "\n"; @@ -213,6 +214,9 @@ else { $total_debit = 0; $total_credit = 0; + $sous_total_debit = 0; + $sous_total_credit = 0; + $displayed_account = ""; foreach ( $object->lines as $line ) { $var = ! $var; @@ -220,33 +224,59 @@ else { $total_debit += $line->debit; $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); if(empty($description)){ $link = '' . img_edit_add() .''; } print ''; + + // Permet d'afficher le compte comptable + if ($root_account_description != $displayed_account) { + + // Affiche un Sous-Total par compte comptable + if ($displayed_account != "") { + print ''.$langs->trans("SubTotal") . ':'.price($sous_total_debit).''.price($sous_total_credit).''.price($sous_total_credit-$sous_total_debit).''; + print " \n"; + print ''; + } + + // Affiche le compte comptable en début de ligne + print ""; + print ''. $root_account_description .''; + print ''; + + $displayed_account = $root_account_description; + $sous_total_debit = 0; + $sous_total_credit = 0; + } + + // $object->get_compte_racine($line->numero_compte); + + print '' . length_accountg($line->numero_compte) . ''; print '' . $description . ''; print '' . number_format($line->debit, 2, ',', ' ') . ''; - print '' . number_format($line->credit, 2, ',', ' ') . ''; - print '' . number_format($line->credit - $line->debit, 2, ',', ' ') . ''; + print '' . number_format($line->credit, 2, ',', ' ') . ''; + print '' . number_format($line->credit - $line->debit, 2, ',', ' ') . ''; print '' . $link; print ''; print "\n"; + + // Comptabilise le sous-total + $sous_total_debit += $line->debit; + $sous_total_credit += $line->credit; + } - print ''; - print ''; - print ''; - print ''; - print price($total_debit); - print ''; - print ''; - print price($total_credit); - print ''; - print '' . price($total_credit - $total_debit) . ''; - print ''; - print ''; + print ''.$langs->trans("SubTotal") . ':'.price($sous_total_debit).''.price($sous_total_credit).''.price($sous_total_credit-$sous_total_debit).''; + print " \n"; + print ''; + + print ''.$langs->trans("AccountBalance") . ':'.price($total_debit).''.price($total_credit).''.price($total_credit-$total_debit).''; + print " \n"; + print ''; + print ""; print ''; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 23148213aa0..5eafa920973 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -258,7 +258,6 @@ if ($action == 'export_csv') { */ $title_page = $langs->trans("Bookkeeping") . ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end); - llxHeader('', $title_page); // List @@ -315,6 +314,7 @@ print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield print '
'; print '
' . "\n"; +print ''; print '
'; print ''; print '
'; diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php new file mode 100644 index 00000000000..ce62655465d --- /dev/null +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -0,0 +1,348 @@ + + * largely based on the great work of : + * - Copyright (C) 2013-2016 Olivier Geffroy + * - Copyright (C) 2013-2016 Florian Henry + * - Copyright (C) 2013-2016 Alexandre Spangaro + * + * 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/bookkeeping/listbyaccount.php + * \ingroup Advanced accountancy + * \brief List operation of book keeping ordered by account number + */ + +require '../../main.inc.php'; + +// Class +require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; + +// Langs +$langs->load("accountancy"); + +$page = GETPOST("page"); +$sortorder = GETPOST("sortorder"); +$sortfield = GETPOST("sortfield"); +$action = GETPOST('action', 'alpha'); +$search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); +$search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); +$search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); + + + +$search_accountancy_code = GETPOST("search_accountancy_code"); + +$search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); +if ($search_accountancy_code_start == - 1) { + $search_accountancy_code_start = ''; +} +$search_label_account = GETPOST('search_label_account', 'alpha'); + +$search_mvt_label = GETPOST('search_mvt_label', 'alpha'); +$search_direction = GETPOST('search_direction', 'alpha'); +$search_ledger_code = GETPOST('search_ledger_code', 'alpha'); + +$limit = GETPOST('limit') ? GETPOST('limit', 'int') : $conf->liste_limit; +if ($page == -1) { $page = 0 ; } +$offset = $limit * $page ; +$pageprev = $page - 1; +$pagenext = $page + 1; + +$object = new BookKeeping($db); + +$formventilation = new FormVentilation($db); +$formother = new FormOther($db); +$form = new Form($db); + + + + +if (empty($search_date_start)) { + $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y')); + $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y')); +} +if ($sortorder == "") + $sortorder = "ASC"; +if ($sortfield == "") + $sortfield = "t.rowid"; + + +$options = ''; +$filter = array (); + +if (! empty($search_date_start)) { + $filter['t.doc_date>='] = $search_date_start; + $options .= '&date_startmonth=' . GETPOST('date_startmonth', 'int') . '&date_startday=' . GETPOST('date_startday', 'int') . '&date_startyear=' . GETPOST('date_startyear', 'int'); +} +if (! empty($search_date_end)) { + $filter['t.doc_date<='] = $search_date_end; + $options .= '&date_endmonth=' . GETPOST('date_endmonth', 'int') . '&date_endday=' . GETPOST('date_endday', 'int') . '&date_endyear=' . GETPOST('date_endyear', 'int'); +} +if (! empty($search_doc_date)) { + $filter['t.doc_date'] = $search_doc_date; + $options .= '&doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&doc_dateday=' . GETPOST('doc_dateday', 'int') . '&doc_dateyear=' . GETPOST('doc_dateyear', 'int'); +} + + +if (!GETPOST("button_removefilter_x") && !GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + if (! empty($search_accountancy_code_start)) { + $filter['t.numero_compte'] = $search_accountancy_code_start; + $options .= '&search_accountancy_code_start=' . $search_accountancy_code_start; + } + if (! empty($search_label_account)) { + $filter['t.label_compte'] = $search_label_account; + $options .= '&search_label_account=' . $search_label_account; + } + if (! empty($search_mvt_label)) { + $filter['t.label_compte'] = $search_mvt_label; + $options .= '&search_mvt_label=' . $search_mvt_label; + } + if (! empty($search_direction)) { + $filter['t.sens'] = $search_direction; + $options .= '&search_direction=' . $search_direction; + } + if (! empty($search_ledger_code)) { + $filter['t.code_journal'] = $search_ledger_code; + $options .= '&search_ledger_code=' . $search_ledger_code; + } +} + +/* + * Action + */ + +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + $search_doc_date = ''; + $search_accountancy_code = ''; + $search_accountancy_code_start = ''; + $search_label_account = ''; + $search_mvt_label = ''; + $search_direction = ''; + $search_ledger_code = ''; +} + +if ($action == 'delmouvconfirm') { + + $mvt_num = GETPOST('mvt_num', 'int'); + + if (! empty($mvt_num)) { + $result = $object->deleteMvtNum($mvt_num); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + Header("Location: listbyaccount.php"); + exit(); + } +} + + +/* + * View + */ + +$title_page = $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By")) . ' ' . $langs->trans("AccountAccounting") . ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end); + +llxHeader('', $title_page); + +// List + +$nbtotalofrecords = 0; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter); + if ($nbtotalofrecords < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +$result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter); +if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); +} +$nbtotalofrecords = $result; + +if ($action == 'delmouv') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?mvt_num=' . GETPOST('mvt_num'), $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delmouvconfirm', '', 0, 1); + print $formconfirm; +} +if ($action == 'delbookkeepingyear') { + + $form_question = array (); + $delyear = GETPOST('delyear'); + + if (empty($delyear)) { + $delyear = dol_print_date(dol_now(), '%Y'); + } + $year_array = $formventilation->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array'); + + $form_question['delyear'] = array ( + 'name' => 'delyear', + 'type' => 'select', + 'label' => $langs->trans('DelYear'), + 'values' => $year_array, + 'default' => $delyear + ); + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1); + print $formconfirm; +} + + + + +print ''; + +print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords,'',0,'','',$limit); + +// Reverse sort order +if ( preg_match('/^asc/i', $sortorder) ) + $sortorder = "asc"; +else + $sortorder = "desc"; + +print '
' . "\n"; +print ''; +print '
'; + +print ''; +print ''; +print ''; +print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "t.doc_date", "", $options, "", $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder); +print ''; +print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="center"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); +print "\n"; + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print ''; + +$var = True; + +$total_debit = 0; +$total_credit = 0; +$sous_total_debit = 0; +$sous_total_credit = 0; +$displayed_account_number = ""; + +foreach ( $object->lines as $line ) { + $var = ! $var; + + $total_debit += $line->debit; + $total_credit += $line->credit; + + // Permet d'afficher le compte comptable + if (length_accountg($line->numero_compte) != $displayed_account_number) { + + // Affiche un Sous-Total par compte comptable + if ($displayed_account_number != "") { + print ''; + print "\n"; + print ''; + } + + // Affiche le compte comptable en début de ligne + print ""; + print ''; + print ''; + + $displayed_account_number = length_accountg($line->numero_compte); + $sous_total_debit = 0; + $sous_total_credit = 0; + } + + print ''; + print ''; + print ''; + print ''; + + // Affiche un lien vers la facture client/fournisseur + $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref); + if ($line->doc_type == 'supplier_invoice') + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + elseif ($line->doc_type == 'customer_invoice') + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + else + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + + + print ''; + print ''; + print ''; + print ''; + print "\n"; + + // Comptabilise le sous-total + $sous_total_debit += $line->debit; + $sous_total_credit += $line->credit; + +} + +// Affiche un Sous-Total du dernier compte comptable affiché +print ''; +print "\n"; +print ''; + + +// Affiche le Total +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print "
' . $langs->trans("AccountAccounting") . '' . $langs->trans("SuppliersInvoices") . ' / ' . $langs->trans("CustomersInvoices") . '
' . $object->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '') . ''; +print $langs->trans('From') . ': '; +print $form->select_date($search_date_start, 'date_start', 0, 0, 1); +print '
'; +print $langs->trans('to') . ': '; +print $form->select_date($search_date_end, 'date_end', 0, 0, 1); +print '
  '; +$searchpitco=$form->showFilterAndCheckAddButtons(0); +print $searchpitco; +print '
'.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).' 
'.length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte).'
 ' . dol_print_date($line->doc_date, 'day') . '' . $line->doc_ref . '' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . price($line->debit) . '' . price($line->credit) . '' . $line->code_journal . ''; + print '' . img_edit() . ' '; + print '' . img_delete() . ''; + print '
'.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).' 
'.$langs->trans("Total").':'; +print price($total_debit); +print ''; +print price($total_credit); +print '
"; +print ''; + +llxFooter(); + + +$db->close(); diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 79e66ab7cce..5832d44cd52 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -53,14 +53,14 @@ class BookKeeping extends CommonObject * * @var string Name of table without prefix where object is stored */ - public $table_element = 'accounting_bookkeeping'; - + public $table_element = 'accounting_bookkeeping'; + /** * * @var BookKeepingLine[] Lines */ public $lines = array (); - + /** * * @var int ID @@ -84,10 +84,10 @@ class BookKeeping extends CommonObject public $import_key; public $code_journal; public $piece_num; - + /** */ - + /** * Constructor * @@ -97,24 +97,22 @@ class BookKeeping extends CommonObject $this->db = $db; return 1; } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - - global $langs; - + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -160,32 +158,32 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + $this->db->begin(); - + $this->piece_num = 0; - + // first check if line not yet in bookkeeping $sql = "SELECT count(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sql .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; + $sql .= " WHERE doc_type = '" . $this->doc_type . "'"; $sql .= " AND fk_docdet = " . $this->fk_docdet; - $sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'"; - - dol_syslog(get_class($this) . ":: create ", LOG_DEBUG); + $sql .= " AND numero_compte = '" . $this->numero_compte . "'"; + + dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); - + if ($resql) { $row = $this->db->fetch_object($resql); if ($row->nb == 0) { - + // Determine piece_num $sqlnum = "SELECT piece_num"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'"; $sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'"; $sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'"; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -196,7 +194,7 @@ class BookKeeping extends CommonObject if (empty($this->piece_num)) { $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -204,19 +202,18 @@ class BookKeeping extends CommonObject $this->piece_num = $objnum->maxpiecenum; } } + dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); if (empty($this->piece_num)) { $this->piece_num = 1; } - - dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); - + $now = dol_now(); if (empty($this->date_create)) { $this->date_create = $now; } - + $sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " ("; - + $sql .= "doc_date"; $sql .= ", doc_type"; $sql .= ", doc_ref"; @@ -233,33 +230,33 @@ class BookKeeping extends CommonObject $sql .= ", import_key"; $sql .= ", code_journal"; $sql .= ", piece_num"; - + $sql .= ") VALUES ("; - - $sql .= "'" . $this->db->idate($this->doc_date) . "'"; - $sql .= ",'" . $this->db->escape($this->doc_type) . "'"; - $sql .= ",'" . $this->db->escape($this->doc_ref) . "'"; + + $sql .= "'" . $this->doc_date . "'"; + $sql .= ",'" . $this->doc_type . "'"; + $sql .= ",'" . $this->doc_ref . "'"; $sql .= "," . $this->fk_doc; $sql .= "," . $this->fk_docdet; - $sql .= ",'" . $this->db->escape($this->code_tiers) . "'"; - $sql .= ",'" . $this->db->escape($this->numero_compte) . "'"; + $sql .= ",'" . $this->code_tiers . "'"; + $sql .= ",'" . $this->numero_compte . "'"; $sql .= ",'" . $this->db->escape($this->label_compte) . "'"; $sql .= "," . $this->debit; $sql .= "," . $this->credit; $sql .= "," . $this->montant; - $sql .= ",'" . $this->db->escape($this->sens) . "'"; + $sql .= ",'" . $this->sens . "'"; $sql .= ",'" . $this->fk_user_author . "'"; $sql .= ",'" . $this->date_create . "'"; - $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; + $sql .= ",'" . $this->code_journal . "'"; $sql .= "," . $this->piece_num; - + $sql .= ")"; - - dol_syslog(get_class($this) . ":: create", LOG_DEBUG); + + dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if ($id > 0) { $this->id = $id; $result = 0; @@ -267,67 +264,67 @@ class BookKeeping extends CommonObject $result = - 2; $error ++; $this->errors[] = 'Error Create Error ' . $result . ' lecture ID'; - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 1; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 3; $error ++; - $this->errors[] = $langs->trans('BookeppingLineAlreayExists'); - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 5; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' $result='.$result.' '. implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error) { - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $result; } } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function createStd(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -373,13 +370,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add control on parameters values - + // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - + $sql .= 'doc_date,'; $sql .= 'doc_type,'; $sql .= 'doc_ref,'; @@ -396,9 +393,9 @@ class BookKeeping extends CommonObject $sql .= 'import_key,'; $sql .= 'code_journal,'; $sql .= 'piece_num'; - + $sql .= ') VALUES ('; - + $sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->doc_date) . "'") . ','; $sql .= ' ' . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ','; $sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ','; @@ -415,58 +412,58 @@ class BookKeeping extends CommonObject $sql .= ' ' . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ','; $sql .= ' ' . (! isset($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (! isset($this->piece_num) ? 'NULL' : $this->piece_num); - + $sql .= ')'; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $this->id; } } - + /** * Load object in memory from the database * * @param int $id Id object * @param string $ref Ref - * + * * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetch($id, $ref = null) { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -483,22 +480,22 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $ref) { $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; } else { $sql .= ' WHERE t.rowid = ' . $id; } - + $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); if ($numrows) { $obj = $this->db->fetch_object($resql); - + $this->id = $obj->rowid; - + $this->doc_date = $this->db->jdate($obj->doc_date); $this->doc_type = $obj->doc_type; $this->doc_ref = $obj->doc_ref; @@ -517,7 +514,7 @@ class BookKeeping extends CommonObject $this->piece_num = $obj->piece_num; } $this->db->free($resql); - + if ($numrows) { return 1; } else { @@ -526,12 +523,12 @@ class BookKeeping extends CommonObject } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - - /** + + /** * Load object in memory from the database * * @param string $sortorder Sort Order @@ -540,15 +537,15 @@ class BookKeeping extends CommonObject * @param int $offset offset limit * @param array $filter filter array * @param string $filtermode filter mode (AND or OR) - * + * * @return int <0 if KO, >0 if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -565,9 +562,9 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -582,33 +579,36 @@ class BookKeeping extends CommonObject $sqlwhere[] = $key . '=' . $value; } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') { $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; - } else { + } elseif ($key == 't.label_compte') { + $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; + }else { $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + // Affichage par compte comptable + $sql .= ' ORDER BY t.numero_compte ASC'; if (! empty($sortfield)) { - $sql .= $this->db->order($sortfield, $sortorder); + $sql .= ', ' . $sortfield . ' ' .$sortorder; } if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); - } + } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -625,20 +625,21 @@ class BookKeeping extends CommonObject $line->import_key = $obj->import_key; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->lines[] = $line; } $this->db->free($resql); - + return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + + /** * Load object in memory from the database * @@ -648,20 +649,34 @@ class BookKeeping extends CommonObject * @param int $offset offset limit * @param array $filter filter array * @param string $filtermode filter mode (AND or OR) - * + * * @return int <0 if KO, >0 if OK */ - public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.doc_date,"; + $sql .= " t.doc_type,"; + $sql .= " t.doc_ref,"; + $sql .= " t.fk_doc,"; + $sql .= " t.fk_docdet,"; + $sql .= " t.code_tiers,"; $sql .= " t.numero_compte,"; - $sql .= " SUM(t.debit) as debit,"; - $sql .= " SUM(t.credit) as credit"; - - + $sql .= " t.label_compte,"; + $sql .= " t.debit,"; + $sql .= " t.credit,"; + $sql .= " t.montant,"; + $sql .= " t.sens,"; + $sql .= " t.fk_user_author,"; + $sql .= " t.import_key,"; + $sql .= " t.code_journal,"; + $sql .= " t.piece_num"; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -681,13 +696,11 @@ class BookKeeping extends CommonObject } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - - $sql .= ' GROUP BY t.numero_compte'; - + if (! empty($sortfield)) { $sql .= $this->db->order($sortfield, $sortorder); } @@ -695,45 +708,141 @@ class BookKeeping extends CommonObject $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + + $line->id = $obj->rowid; + + $line->doc_date = $this->db->jdate($obj->doc_date); + $line->doc_type = $obj->doc_type; + $line->doc_ref = $obj->doc_ref; + $line->fk_doc = $obj->fk_doc; + $line->fk_docdet = $obj->fk_docdet; + $line->code_tiers = $obj->code_tiers; + $line->numero_compte = $obj->numero_compte; + $line->label_compte = $obj->label_compte; + $line->debit = $obj->debit; + $line->credit = $obj->credit; + $line->montant = $obj->montant; + $line->sens = $obj->sens; + $line->fk_user_author = $obj->fk_user_author; + $line->import_key = $obj->import_key; + $line->code_journal = $obj->code_journal; + $line->piece_num = $obj->piece_num; + + $this->lines[] = $line; + } + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK + */ + public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= " t.numero_compte,"; + $sql .= " SUM(t.debit) as debit,"; + $sql .= " SUM(t.credit) as credit"; + + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + + // Manage filter + $sqlwhere = array (); + if (count($filter) > 0) { + foreach ( $filter as $key => $value ) { + if ($key == 't.doc_date') { + $sqlwhere[] = $key . '=\'' . $this->db->idate($value) . '\''; + } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') { + $sqlwhere[] = $key . '\'' . $this->db->idate($value) . '\''; + } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.code_tiers>=' || $key == 't.code_tiers<=') { + $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\''; + } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { + $sqlwhere[] = $key . '=' . $value; + } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') { + $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; + } else { + $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + } + + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); + } + + $sql .= ' GROUP BY t.numero_compte'; + + if (! empty($sortfield)) { + $sql .= $this->db->order($sortfield, $sortorder); + } + if (! empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); + } + $this->lines = array (); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ( $obj = $this->db->fetch_object($resql) ) { + $line = new BookKeepingLine(); + $line->numero_compte = $obj->numero_compte; $line->debit = $obj->debit; $line->credit = $obj->credit; $this->lines[] = $line; } $this->db->free($resql); - + return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + /** * Update object into database * * @param User $user User that modifies * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function update(User $user, $notrigger = false) { $error = 0; - + dol_syslog(__METHOD__, LOG_DEBUG); - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -779,13 +888,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add a control on parameters values - + // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - + $sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ','; $sql .= ' doc_type = ' . (isset($this->doc_type) ? "'" . $this->db->escape($this->doc_type) . "'" : "null") . ','; $sql .= ' doc_ref = ' . (isset($this->doc_ref) ? "'" . $this->db->escape($this->doc_ref) . "'" : "null") . ','; @@ -802,71 +911,71 @@ class BookKeeping extends CommonObject $sql .= ' import_key = ' . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . ','; $sql .= ' code_journal = ' . (isset($this->code_journal) ? "'" . $this->db->escape($this->code_journal) . "'" : "null") . ','; $sql .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null"); - + $sql .= ' WHERE rowid=' . $this->id; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error && ! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_MODIFY',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete object in database * * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + $this->db->begin(); - + if (! $error) { if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_DELETE',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } } - + if (! $error) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql .= ' WHERE rowid=' . $this->id; - + $resql = $this->db->query($sql); if (! $resql) { $error ++; @@ -874,19 +983,19 @@ class BookKeeping extends CommonObject dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete bookkepping by importkey * @@ -895,14 +1004,14 @@ class BookKeeping extends CommonObject */ function deleteByImportkey($importkey) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE import_key = '" . $importkey . "'"; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -912,11 +1021,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Delete bookkepping by year * @@ -925,14 +1034,14 @@ class BookKeeping extends CommonObject */ function deleteByYear($delyear) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE YEAR(doc_date) = " . $delyear; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -942,54 +1051,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - - /** - * Delete bookkepping by year - * - * @param string $delyear year to delete - * @param string $deljournal journal to delete - * @return int Result - */ - function deleteByYearAndJournal($delyear,$deljournal) { - $this->db->begin(); - - $sqlwhere=array(); - - // first check if line not yet in bookkeeping - $sql = "DELETE"; - $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - if (!empty($delyear)) { - $sqlwhere[] .= " YEAR(doc_date) = " . $delyear; - } - if (!empty($deljournal)) { - $sqlwhere[] .= " code_journal = '" . $this->db->escape($deljournal)."'"; - } - - if (count($sqlwhere)>0) { - $sql.=" WHERE ".implode(' AND ', $sqlwhere); - - $resql = $this->db->query($sql); - - if (! $resql) { - $this->errors[] = "Error " . $this->db->lasterror(); - foreach ( $this->errors as $errmsg ) { - dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); - $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); - } - $this->db->rollback(); - return - 1; - } - - $this->db->commit(); - - } - return 1; - } - + /** * Delete bookkepping by piece number * @@ -998,14 +1064,14 @@ class BookKeeping extends CommonObject */ function deleteMvtNum($piecenum) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -1015,57 +1081,57 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone - * + * * @return int New id of clone */ public function createFromClone($fromid) { dol_syslog(__METHOD__, LOG_DEBUG); - + global $user; $error = 0; $object = new Accountingbookkeeping($this->db); - + $this->db->begin(); - + // Load source object $object->fetch($fromid); // Reset object $object->id = 0; - + // Clear fields // ... - + // Create clone $result = $object->create($user); - + // Other options if ($result < 0) { $error ++; $this->errors = $object->errors; dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + // End if (! $error) { $this->db->commit(); - + return $object->id; } else { $this->db->rollback(); - + return - 1; } } - + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -1074,7 +1140,7 @@ class BookKeeping extends CommonObject */ public function initAsSpecimen() { $this->id = 0; - + $this->doc_date = ''; $this->doc_type = ''; $this->doc_ref = ''; @@ -1092,7 +1158,7 @@ class BookKeeping extends CommonObject $this->code_journal = ''; $this->piece_num = ''; } - + /** * Load an accounting document into memory from database * @@ -1103,12 +1169,12 @@ class BookKeeping extends CommonObject $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - + $this->piece_num = $obj->piece_num; $this->code_journal = $obj->code_journal; $this->doc_date = $this->db->jdate($obj->doc_date); @@ -1119,10 +1185,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Return next number movement * @@ -1130,13 +1196,13 @@ class BookKeeping extends CommonObject */ public function getNextNumMvt() { $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); - + if ($result) { $obj = $this->db->fetch_object($result); - + return $obj->max; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1144,7 +1210,7 @@ class BookKeeping extends CommonObject return - 1; } } - + /** * Load all informations of accountancy document * @@ -1158,17 +1224,17 @@ class BookKeeping extends CommonObject $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - + while ( $obj = $this->db->fetch_object($result) ) { - + $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1183,7 +1249,7 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesmvt[] = $line; } } else { @@ -1191,10 +1257,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Export bookkeping * @@ -1207,20 +1273,20 @@ class BookKeeping extends CommonObject $sql .= " numero_compte, label_compte, debit, credit,"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG); - + $resql = $this->db->query($sql); - + if ($resql) { $this->linesexport = array (); - + $num = $this->db->num_rows($resql); while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1235,11 +1301,11 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesexport[] = $line; } $this->db->free($resql); - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1247,40 +1313,114 @@ class BookKeeping extends CommonObject return - 1; } } + + + + /** + * Return list of accounts with label by chart of accounts + * + * @param string $selectid Preselected chart of accounts + * @param string $htmlname Name of field in html form + * @param int $showempty Add an empty field + * @param array $event Event options + * @param int $select_in $selectid value is a aa.rowid (0 default) or aa.account_number (1) + * @param int $select_out set value returned by select 0=rowid (default), 1=account_number + * @param int $aabase set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number + * + * @return string String with HTML select + */ + function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') { + global $conf; + require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; + + $pcgver = $conf->global->CHARTOFACCOUNTS; + + $sql = "SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ab.numero_compte"; + $sql .= " AND aa.active = 1"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " ORDER BY account_number ASC"; + + dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); + $resql = $this->db->query($sql); + + if (!$resql) { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR); + return -1; + } + + $out = ajax_combobox($htmlname, $event); + + $options = array(); + $selected = null; + + while ($obj = $this->db->fetch_object($resql)) { + $label = length_accountg($obj->account_number) . ' - ' . $obj->label; + $label = dol_trunc($label, $trunclength); + + $select_value_in = $obj->rowid; + $select_value_out = $obj->rowid; + + if ($select_in == 1) { + $select_value_in = $obj->account_number; + } + if ($select_out == 1) { + $select_value_out = $obj->account_number; + } + + // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number + // Because same account_number can be share between different accounting_system and do have the same meaning + if (($selectid != '') && $selectid == $select_value_in) { + $selected = $select_value_out; + } + + $options[$select_value_out] = $label; + } + + $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300'); + $this->db->free($resql); + return $out; + } + + + /** - * Description of accounting account + * Description of a root accounting account * * @param string $account Accounting account - * @return string + * @return string */ - function get_compte_desc($account = null) - { + function get_compte_racine($account = null) + { global $conf; $pcgver = $conf->global->CHARTOFACCOUNTS; - $sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa "; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; - $sql .= " AND aa.account_number = '" . $account . "'"; - $sql .= " AND asy.rowid = " . $pcgver; - $sql .= " AND aa.active = 1"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid"; + + $sql = "SELECT root.account_number, root.label as label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as parent ON aa.account_parent = parent.rowid"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as root ON parent.account_parent = root.rowid"; + $sql .= " WHERE aa.account_number = '" . $account . "'"; + $sql .= " AND parent.active = 1"; + $sql .= " AND root.active = 1"; + dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $obj = ''; if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - } - - if(empty($obj->category)){ - return $obj->label; - }else{ - return $obj->label.' ('.$obj->category.')'; - + $obj = $this->db->fetch_object($resql); } + + return $obj->label; + } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); @@ -1288,7 +1428,46 @@ class BookKeeping extends CommonObject return -1; } } - + + + /** + * Description of accounting account + * + * @param string $account Accounting account + * @return string + */ + function get_compte_desc($account = null) + { + global $conf; + $pcgver = $conf->global->CHARTOFACCOUNTS; + $sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa "; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND aa.account_number = '" . $account . "'"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " AND aa.active = 1"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid"; + dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $obj = ''; + if ($this->db->num_rows($resql)) { + $obj = $this->db->fetch_object($resql); + } + + if(empty($obj->category)){ + return $obj->label; + }else{ + return $obj->label.' ('.$obj->category.')'; + + } + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); + return -1; + } + } + } /** diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 7ab1a53d230..c45c045e11d 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1971,6 +1971,11 @@ function getElementProperties($element_type) $module='resource'; $subelement='dolresource'; } + if ($element_type == 'propaldet') { + $classpath = 'comm/propal/class'; + $module='propal'; + $subelement='propaleligne'; + } $classfile = strtolower($subelement); $classname = ucfirst($subelement); diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index 8d040e06ed4..d0cf9a4a385 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -369,7 +369,7 @@ if (! empty($force_install_message)) trans("Port"); ?> - value=""> @@ -484,9 +484,27 @@ if (! empty($force_install_message))