From 29910840610a658e5fa8364e523bd039c84b73d0 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 8 Feb 2016 10:50:40 +0100 Subject: [PATCH 1/4] fx accountancy --- htdocs/accountancy/journal/purchasesjournal.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 86232bb2029..7d9778f72b8 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -94,6 +94,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = $sql .= " JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = fd.fk_facture_fourn"; $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " WHERE f.fk_statut > 0 "; +$sql .= " AND fd.fk_code_ventilation > 0 "; if (! empty($conf->multicompany->enabled)) { $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; } From 05d7b14786a4c5d47768df2b8e3185d0b377be11 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 9 Feb 2016 19:11:19 +0100 Subject: [PATCH 2/4] Accoutancy --- htdocs/accountancy/bookkeeping/balance.php | 498 +++++++++++++++++++++ 1 file changed, 498 insertions(+) create mode 100644 htdocs/accountancy/bookkeeping/balance.php diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php new file mode 100644 index 00000000000..5e36e5f2a77 --- /dev/null +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -0,0 +1,498 @@ + + * Copyright (C) 2013-2014 Florian Henry + * Copyright (C) 2013-2015 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/balance.php + * \ingroup Accounting Expert + * \brief Balance of book keeping + */ +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_mvt_num = GETPOST('search_mvt_num', 'int'); +$search_doc_type = GETPOST("search_doc_type"); +$search_doc_ref = GETPOST("search_doc_ref"); +$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')); + +if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt")) { + $action = 'delbookkeepingyear'; +} +if (GETPOST("button_export_csv_x") || GETPOST("button_export_csv")) { + $action = 'export_csv'; +} + +$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_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha'); +if ($search_accountancy_code_end == - 1) { + $search_accountancy_code_end = ''; +} + +$search_accountancy_aux_code = GETPOST("search_accountancy_aux_code"); + +$search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha'); +if ($search_accountancy_aux_code_start == - 1) { + $search_accountancy_aux_code_start = ''; +} +$search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha'); +if ($search_accountancy_aux_code_end == - 1) { + $search_accountancy_aux_code_end = ''; +} +$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; + +$offset = $limit * $page; + +$object = new BookKeeping($db); + +$formventilation = new FormVentilation($db); +$formother = new FormOther($db); +$form = new Form($db); + +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + $search_mvt_num = ''; + $search_doc_type = ''; + $search_doc_ref = ''; + $search_doc_date = ''; + $search_accountancy_code = ''; + $search_accountancy_code_start = ''; + $search_accountancy_code_end = ''; + $search_accountancy_aux_code = ''; + $search_accountancy_aux_code_start = ''; + $search_accountancy_aux_code_end = ''; + $search_mvt_label = ''; + $search_direction = ''; + $search_ledger_code = ''; + $search_date_start = ''; + $search_date_end = ''; +} + +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_type)) { + $filter['t.doc_type'] = $search_doc_type; + $options .= '&search_doc_type=' . $search_doc_type; +} +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 (! empty($search_doc_ref)) { + $filter['t.doc_ref'] = $search_doc_ref; + $options .= '&search_doc_ref=' . $search_doc_ref; +} +if (! empty($search_accountancy_code)) { + $filter['t.numero_compte'] = $search_accountancy_code; + $options .= '&search_accountancy_code=' . $search_accountancy_code; +} +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_accountancy_code_end)) { + $filter['t.numero_compte<='] = $search_accountancy_code_end; + $options .= '&search_accountancy_code_end=' . $search_accountancy_code_end; +} +if (! empty($search_accountancy_aux_code)) { + $filter['t.code_tiers'] = $search_accountancy_aux_code; + $options .= '&search_accountancy_aux_code=' . $search_accountancy_aux_code; +} +if (! empty($search_accountancy_aux_code_start)) { + $filter['t.code_tiers>='] = $search_accountancy_aux_code_start; + $options .= '&search_accountancy_aux_code_start=' . $search_accountancy_aux_code_start; +} +if (! empty($search_accountancy_aux_code_end)) { + $filter['t.code_tiers<='] = $search_accountancy_aux_code_end; + $options .= '&search_accountancy_aux_code_end=' . $search_accountancy_aux_code_end; +} +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; +} +if (! empty($search_mvt_num)) { + $filter['t.piece_num'] = $search_mvt_num; + $options .= '&search_mvt_num=' . $search_mvt_num; +} + +/* + * Action + */ +if ($action == 'delbookkeeping') { + + $import_key = GETPOST('importkey', 'alpha'); + + if (! empty($import_key)) { + $result = $object->deleteByImportkey($import_key); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + Header("Location: list.php"); + exit(); + } +} elseif ($action == 'delbookkeepingyearconfirm') { + + $delyear = GETPOST('delyear', 'int'); + + if (! empty($delyear)) { + $result = $object->deleteByYear($delyear); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + Header("Location: list.php"); + exit(); + } +} elseif ($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'); + } + // if (!empty($options)) { + // Header("Location: list.php?".urldecode($options)); + // } else { + Header("Location: list.php"); + // } + exit(); + } +} elseif ($action == 'export_csv') { + $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; + $journal = 'bookkepping'; + + include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; + + $result = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + + foreach ( $object->lines as $line ) { + + if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) { + $sep = ";"; + // Model Cegid Expert Export + $date = dol_print_date($line->doc_date, '%d%m%Y'); + print $date . $sep; + print $line->code_journal . $sep; + print length_accountg($line->numero_compte) . $sep; + print ' ' . $sep; + print $line->sens . $sep; + print price($line->montant) . $sep; + print dol_trunc($line->label_compte, 32) . $sep; + print $line->doc_ref . $sep; + + /*print $line->piece_num . $sep; + print length_accounta($line->code_tiers) . $sep; + print . $sep; + print price($line->debit) . $sep; + print price($line->credit) . $sep;*/ + + print "\n"; + } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) { + + // Std export + $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE); + print $date . $sep; + print $line->doc_ref . $sep; + print length_accounta($line->numero_compte) . $sep; + print length_accountg($line->code_tiers) . $sep; + print price($line->debit) . $sep; + print price($line->credit) . $sep; + + /*print $line->piece_num . $sep; + print $line->label_compte . $sep; + print price($line->montant) . $sep; + print $line->sens . $sep;*/ + print $line->code_journal . $sep; + print "\n"; + } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 3) { + + // Coala export + $date = dol_print_date($line->doc_date, '%d/%m/%Y'); + print $date . $sep; + print $line->code_journal . $sep; + print length_accounta($line->numero_compte) . $sep; + print $line->piece_num . $sep; + print $line->doc_ref . $sep; + print price($line->debit) . $sep; + print price($line->credit) . $sep; + print 'E' . $sep; + print length_accountg($line->code_tiers) . $sep; + print "\n"; + } + } +} + +else { + + $title_page = $langs->trans("AccountBalance") . ' ' . 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->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter); + if ($nbtotalofrecords < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, $offset, $filter); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + + 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_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords); + + /*print '
'; + print ''; + print ''; + + print $formventilation->select_bookkeeping_importkey('importkey', GETPOST('importkey')); + + print '
'; + + print '
';*/ + + print '
'; + print '
' . "\n"; + //print '
'; + //print '' . $langs->trans("NewAccountingMvt") . ''; + // print '' . $langs->trans("Export") . ''; + print '
'; + + print '
'; + + print '
'; + print $langs->trans('DateStart') . ': '; + print $form->select_date($search_date_start, 'date_start', 0, 0, 1); + print $langs->trans('DateEnd') . ': '; + print $form->select_date($search_date_end, 'date_end', 0, 0, 1); + print '
'; + /* + print '
'; + print $langs->trans('From') . ' ' . $langs->trans('AccountAccounting') . ': '; + print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, ''); + print $langs->trans('To') . ' ' . $langs->trans('AccountAccounting') . ': '; + print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, ''); + print '
'; + print '
'; + print $langs->trans('From') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; + print $formventilation->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); + print $langs->trans('To') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; + print $formventilation->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); + print '
';*/ + + print ''; + print ''; + //print_liste_field_titre($langs->trans("NumPiece"), $_SERVER['PHP_SELF'], "t.piece_num", "", $options, "", $sortfield, $sortorder); + //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_liste_field_titre($langs->trans("Numerocompte"), $_SERVER['PHP_SELF'], "t.numero_compte", "", $options, "", $sortfield, $sortorder); + //print_liste_field_titre($langs->trans("Code_tiers"), $_SERVER['PHP_SELF'], "t.code_tiers", "", $options, "", $sortfield, $sortorder); + //print_liste_field_titre($langs->trans("Labelcompte"), $_SERVER['PHP_SELF'], "bk_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("Amount"), $_SERVER['PHP_SELF'], "t.montant", "", $options, 'align="center"', $sortfield, $sortorder); + // print_liste_field_titre($langs->trans("Sens"), $_SERVER['PHP_SELF'], "t.sens", "", $options, 'align="center"', $sortfield, $sortorder); + //print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $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("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); + print "\n"; + + print ''; + /*print ''; + print '';*/ + //print ''; + print ''; + // print ''; + /*print '';*/ + // print ''; + + /*print '';*/ + print ''; + print ''; + print ''; + // print ''; + // print ''; + //print ''; + print ''; + + print ''; + + $var = True; + + $total_debit = 0; + $total_credit = 0; + + foreach ( $object->lines as $line ) { + $var = ! $var; + + $total_debit += $line->debit; + $total_credit += $line->credit; + + print ""; + + //print ''; + //print ''; + //print ''; + print ''; + //print ''; + //print ''; + print ''; + print ''; + print ''; + // print ''; + // print ''; + //print ''; + print ''; + print "\n"; + } + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print "
'; + 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 $form->select_date($search_doc_date, 'doc_date', 0, 0, 1); + print '
'; + // print $langs->trans('From') . ' ' . $langs->trans('AccountAccounting') . ': '; + print $langs->trans('From'); + print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, ''); + // print $langs->trans('To') . ' ' . $langs->trans('AccountAccounting') . ': '; + print '
'; + print $langs->trans('To'); + print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, ''); + print '
'; + // print $langs->trans('From') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; + print $langs->trans('From'); + print $formventilation->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); + // print $langs->trans('To') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; + print '
'; + print $langs->trans('To'); + print $formventilation->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); + print '
'; + print ''; + print '     '; + print ''; + print ' '; + print ''; + print '
' . $line->piece_num . '' . dol_print_date($line->doc_date, 'day') . '' . $line->doc_ref . '' . length_accountg($line->numero_compte) . '' . length_accounta($line->code_tiers) . '' . $line->label_compte . '' . price($line->debit) . '' . price($line->credit) . '' . price($line->credit-$line->debit) . '' . price($line->montant) . '' . $line->sens . '' . $line->code_journal . ''; + //print '' . img_edit() . ''; + //print '' . img_delete() . ''; + print '
'; + print price($total_debit); + print ''; + print price($total_credit); + print ''.price($total_credit-$total_debit).'
"; + print '
'; + + llxFooter(); +} + +$db->close(); \ No newline at end of file From 44e39519b038448bc9498daf9e9636525da17994 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 9 Feb 2016 19:20:03 +0100 Subject: [PATCH 3/4] add accountancy balance --- htdocs/accountancy/bookkeeping/balance.php | 245 +----------------- .../accountancy/class/bookkeeping.class.php | 82 +++++- htdocs/core/menus/standard/eldy.lib.php | 3 +- 3 files changed, 97 insertions(+), 233 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 5e36e5f2a77..16027a42af4 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2014 Florian Henry + * Copyright (C) 2013-2016 Florian Henry * Copyright (C) 2013-2015 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify @@ -38,21 +38,8 @@ $page = GETPOST("page"); $sortorder = GETPOST("sortorder"); $sortfield = GETPOST("sortfield"); $action = GETPOST('action', 'alpha'); -$search_mvt_num = GETPOST('search_mvt_num', 'int'); -$search_doc_type = GETPOST("search_doc_type"); -$search_doc_ref = GETPOST("search_doc_ref"); $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')); - -if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt")) { - $action = 'delbookkeepingyear'; -} -if (GETPOST("button_export_csv_x") || GETPOST("button_export_csv")) { - $action = 'export_csv'; -} - -$search_accountancy_code = GETPOST("search_accountancy_code"); $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); if ($search_accountancy_code_start == - 1) { @@ -63,19 +50,9 @@ if ($search_accountancy_code_end == - 1) { $search_accountancy_code_end = ''; } -$search_accountancy_aux_code = GETPOST("search_accountancy_aux_code"); - -$search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha'); -if ($search_accountancy_aux_code_start == - 1) { - $search_accountancy_aux_code_start = ''; +if (GETPOST("button_export_csv_x") || GETPOST("button_export_csv")) { + $action = 'export_csv'; } -$search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha'); -if ($search_accountancy_aux_code_end == - 1) { - $search_accountancy_aux_code_end = ''; -} -$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; @@ -89,19 +66,8 @@ $form = new Form($db); if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { - $search_mvt_num = ''; - $search_doc_type = ''; - $search_doc_ref = ''; - $search_doc_date = ''; - $search_accountancy_code = ''; $search_accountancy_code_start = ''; $search_accountancy_code_end = ''; - $search_accountancy_aux_code = ''; - $search_accountancy_aux_code_start = ''; - $search_accountancy_aux_code_end = ''; - $search_mvt_label = ''; - $search_direction = ''; - $search_ledger_code = ''; $search_date_start = ''; $search_date_end = ''; } @@ -125,22 +91,6 @@ 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_type)) { - $filter['t.doc_type'] = $search_doc_type; - $options .= '&search_doc_type=' . $search_doc_type; -} -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 (! empty($search_doc_ref)) { - $filter['t.doc_ref'] = $search_doc_ref; - $options .= '&search_doc_ref=' . $search_doc_ref; -} -if (! empty($search_accountancy_code)) { - $filter['t.numero_compte'] = $search_accountancy_code; - $options .= '&search_accountancy_code=' . $search_accountancy_code; -} if (! empty($search_accountancy_code_start)) { $filter['t.numero_compte>='] = $search_accountancy_code_start; $options .= '&search_accountancy_code_start=' . $search_accountancy_code_start; @@ -149,85 +99,17 @@ if (! empty($search_accountancy_code_end)) { $filter['t.numero_compte<='] = $search_accountancy_code_end; $options .= '&search_accountancy_code_end=' . $search_accountancy_code_end; } -if (! empty($search_accountancy_aux_code)) { - $filter['t.code_tiers'] = $search_accountancy_aux_code; - $options .= '&search_accountancy_aux_code=' . $search_accountancy_aux_code; -} -if (! empty($search_accountancy_aux_code_start)) { - $filter['t.code_tiers>='] = $search_accountancy_aux_code_start; - $options .= '&search_accountancy_aux_code_start=' . $search_accountancy_aux_code_start; -} -if (! empty($search_accountancy_aux_code_end)) { - $filter['t.code_tiers<='] = $search_accountancy_aux_code_end; - $options .= '&search_accountancy_aux_code_end=' . $search_accountancy_aux_code_end; -} -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; -} -if (! empty($search_mvt_num)) { - $filter['t.piece_num'] = $search_mvt_num; - $options .= '&search_mvt_num=' . $search_mvt_num; -} /* * Action */ -if ($action == 'delbookkeeping') { - - $import_key = GETPOST('importkey', 'alpha'); - - if (! empty($import_key)) { - $result = $object->deleteByImportkey($import_key); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - Header("Location: list.php"); - exit(); - } -} elseif ($action == 'delbookkeepingyearconfirm') { - - $delyear = GETPOST('delyear', 'int'); - - if (! empty($delyear)) { - $result = $object->deleteByYear($delyear); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - Header("Location: list.php"); - exit(); - } -} elseif ($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'); - } - // if (!empty($options)) { - // Header("Location: list.php?".urldecode($options)); - // } else { - Header("Location: list.php"); - // } - exit(); - } -} elseif ($action == 'export_csv') { +if ($action == 'export_csv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; $journal = 'bookkepping'; include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; - $result = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter); + $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } @@ -312,131 +194,43 @@ else { setEventMessages($object->error, $object->errors, 'errors'); } - 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_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords); - /*print '
'; - print ''; - print ''; - - print $formventilation->select_bookkeeping_importkey('importkey', GETPOST('importkey')); - - print '
'; - - print '
';*/ - print '
'; print '
' . "\n"; - //print '
'; - //print '' . $langs->trans("NewAccountingMvt") . ''; - // print '' . $langs->trans("Export") . ''; print '
'; print '
'; - print '
'; - print $langs->trans('DateStart') . ': '; - print $form->select_date($search_date_start, 'date_start', 0, 0, 1); - print $langs->trans('DateEnd') . ': '; - print $form->select_date($search_date_end, 'date_end', 0, 0, 1); - print '
'; - /* - print '
'; - print $langs->trans('From') . ' ' . $langs->trans('AccountAccounting') . ': '; - print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, ''); - print $langs->trans('To') . ' ' . $langs->trans('AccountAccounting') . ': '; - print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, ''); - print '
'; - print '
'; - print $langs->trans('From') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; - print $formventilation->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); - print $langs->trans('To') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; - print $formventilation->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); - print '
';*/ + print '
'; + print $langs->trans('DateStart') . ': '; + print $form->select_date($search_date_start, 'date_start', 0, 0, 1); + print $langs->trans('DateEnd') . ': '; + print $form->select_date($search_date_end, 'date_end', 0, 0, 1); + print '
'; print ''; print ''; - //print_liste_field_titre($langs->trans("NumPiece"), $_SERVER['PHP_SELF'], "t.piece_num", "", $options, "", $sortfield, $sortorder); - //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_liste_field_titre($langs->trans("Numerocompte"), $_SERVER['PHP_SELF'], "t.numero_compte", "", $options, "", $sortfield, $sortorder); - //print_liste_field_titre($langs->trans("Code_tiers"), $_SERVER['PHP_SELF'], "t.code_tiers", "", $options, "", $sortfield, $sortorder); - //print_liste_field_titre($langs->trans("Labelcompte"), $_SERVER['PHP_SELF'], "bk_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("Amount"), $_SERVER['PHP_SELF'], "t.montant", "", $options, 'align="center"', $sortfield, $sortorder); - // print_liste_field_titre($langs->trans("Sens"), $_SERVER['PHP_SELF'], "t.sens", "", $options, 'align="center"', $sortfield, $sortorder); - //print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $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("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); print "\n"; print ''; - /*print ''; - print '';*/ - //print ''; print ''; - // print ''; - /*print '';*/ - // print ''; - /*print '';*/ print ''; print ''; print ''; - // print ''; - // print ''; - //print ''; + print '"; - //print ''; - //print ''; - //print ''; print ''; - //print ''; - //print ''; print ''; print ''; - print ''; - // print ''; - // print ''; - //print ''; + print ''; print ''; print "\n"; } @@ -485,7 +269,7 @@ else { print ''; - print ''; + print ''; print ''; print ''; @@ -494,5 +278,4 @@ else { llxFooter(); } - $db->close(); \ No newline at end of file diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index dbca9aeddd9..0015dfbf9e9 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2014 Juanjo Menent - * Copyright (C) 2015 Florian Henry + * Copyright (C) 2015-*2016 Florian Henry * Copyright (C) 2015 Raphaƫl Doursenaud * * This program is free software; you can redistribute it and/or modify @@ -642,6 +642,86 @@ class BookKeeping extends CommonObject } } + /** + * 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 * diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 0497b50308f..23f37e1b676 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -971,7 +971,8 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/accountancy/bookkeeping/list.php?leftmenu=bookkeeping",$langs->trans("Bookkeeping"),1,$user->rights->accounting->mouvements->lire, '', $mainmenu, 'bookkeeping'); if (empty($leftmenu) || preg_match('/bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/listbyyear.php",$langs->trans("ByYear"),2,$user->rights->accounting->mouvements->lire); if (empty($leftmenu) || preg_match('/bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/balancebymonth.php",$langs->trans("AccountBalanceByMonth"),2,$user->rights->accounting->mouvements->lire); - + if (empty($leftmenu) || preg_match('/bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/balance.php",$langs->trans("AccountBalance"),1,$user->rights->accounting->mouvements->lire); + // Reports $langs->load("compta"); From ef7e245432d431712015a3c60c24df387e3265f6 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 9 Feb 2016 19:23:17 +0100 Subject: [PATCH 4/4] g --- htdocs/core/menus/standard/eldy.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 23f37e1b676..4e6a219c055 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -969,9 +969,9 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu // General Ledger $newmenu->add("/accountancy/bookkeeping/list.php?leftmenu=bookkeeping",$langs->trans("Bookkeeping"),1,$user->rights->accounting->mouvements->lire, '', $mainmenu, 'bookkeeping'); + if (empty($leftmenu) || preg_match('/bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/balance.php",$langs->trans("AccountBalance"),1,$user->rights->accounting->mouvements->lire); if (empty($leftmenu) || preg_match('/bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/listbyyear.php",$langs->trans("ByYear"),2,$user->rights->accounting->mouvements->lire); if (empty($leftmenu) || preg_match('/bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/balancebymonth.php",$langs->trans("AccountBalanceByMonth"),2,$user->rights->accounting->mouvements->lire); - if (empty($leftmenu) || preg_match('/bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/balance.php",$langs->trans("AccountBalance"),1,$user->rights->accounting->mouvements->lire); // Reports $langs->load("compta");
'; - 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 $form->select_date($search_doc_date, 'doc_date', 0, 0, 1); - print '
'; - // print $langs->trans('From') . ' ' . $langs->trans('AccountAccounting') . ': '; print $langs->trans('From'); print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, ''); - // print $langs->trans('To') . ' ' . $langs->trans('AccountAccounting') . ': '; print '
'; print $langs->trans('To'); print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, ''); print '
'; - // print $langs->trans('From') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; - print $langs->trans('From'); - print $formventilation->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); - // print $langs->trans('To') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; - print '
'; - print $langs->trans('To'); - print $formventilation->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); - print '
'; - print ''; - print '     '; print ''; print ' '; @@ -458,21 +252,11 @@ else { print "
' . $line->piece_num . '' . dol_print_date($line->doc_date, 'day') . '' . $line->doc_ref . '' . length_accountg($line->numero_compte) . '' . length_accounta($line->code_tiers) . '' . $line->label_compte . '' . price($line->debit) . '' . price($line->credit) . '' . price($line->credit-$line->debit) . '' . price($line->montant) . '' . $line->sens . '' . $line->code_journal . '' . price($line->credit - $line->debit) . ''; - //print '' . img_edit() . ''; - //print '' . img_delete() . ''; print '
'; print price($total_credit); print ''.price($total_credit-$total_debit).'' . price($total_credit - $total_debit) . '