From 44019955402ec5f509fdb5d97011389fd1bddfb7 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 9 Feb 2016 19:22:52 +0100 Subject: [PATCH 1/2] Accountancy feature --- htdocs/accountancy/bookkeeping/balance.php | 281 ++++++++++++++++++ htdocs/accountancy/bookkeeping/listbyyear.php | 4 +- .../accountancy/class/bookkeeping.class.php | 82 ++++- htdocs/core/menus/standard/eldy.lib.php | 1 + 4 files changed, 365 insertions(+), 3 deletions(-) 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..16027a42af4 --- /dev/null +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -0,0 +1,281 @@ + + * Copyright (C) 2013-2016 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_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_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 = ''; +} + +if (GETPOST("button_export_csv_x") || GETPOST("button_export_csv")) { + $action = 'export_csv'; +} + +$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_accountancy_code_start = ''; + $search_accountancy_code_end = ''; + $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_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; +} + +/* + * Action + */ +if ($action == 'export_csv') { + $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; + $journal = 'bookkepping'; + + include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; + + $result = $object->fetchAll($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'); + } + + print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords); + + print '
'; + print '
' . "\n"; + 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 ''; + print_liste_field_titre($langs->trans("Numerocompte"), $_SERVER['PHP_SELF'], "t.numero_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("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); + print "\n"; + + 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 "\n"; + } + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print "
'; + print $langs->trans('From'); + print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, ''); + print '
'; + print $langs->trans('To'); + print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, ''); + print '
   '; + print ''; + print ' '; + print ''; + print '
' . length_accountg($line->numero_compte) . '' . price($line->debit) . '' . price($line->credit) . '' . price($line->credit - $line->debit) . ''; + 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 diff --git a/htdocs/accountancy/bookkeeping/listbyyear.php b/htdocs/accountancy/bookkeeping/listbyyear.php index e9751e0f12e..3ec0a704407 100644 --- a/htdocs/accountancy/bookkeeping/listbyyear.php +++ b/htdocs/accountancy/bookkeeping/listbyyear.php @@ -208,8 +208,8 @@ print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit print_liste_field_titre($langs->trans("Amount"), $_SERVER['PHP_SELF'], "t.montant", "", $options, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Sens"), $_SERVER['PHP_SELF'], "t.sens", "", $options, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, "", $sortfield, $sortorder); -print ''; -print ''; +print ''; +print ''; print "\n"; print ''; 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 e0da649e53b..65b35014376 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -986,6 +986,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu // General Ledger if (preg_match('/accountancy/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/list.php?leftmenu=accountancy_bookkeeping",$langs->trans("Bookkeeping"),1,$user->rights->accounting->mouvements->lire, '', $mainmenu, 'bookkeeping'); + if (preg_match('/accountancy_bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/balance.php?leftmenu=accountancy_bookkeeping",$langs->trans("AccountBalance"),2,$user->rights->accounting->mouvements->lire); if (preg_match('/accountancy_bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/listbyyear.php?leftmenu=accountancy_bookkeeping",$langs->trans("ByYear"),2,$user->rights->accounting->mouvements->lire); if (preg_match('/accountancy_bookkeeping/',$leftmenu)) $newmenu->add("/accountancy/bookkeeping/balancebymonth.php?leftmenu=accountancy_bookkeeping",$langs->trans("AccountBalanceByMonth"),2,$user->rights->accounting->mouvements->lire); From 1306a606a8ac7ea379ece9ecf62302dd0032d3c1 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 9 Feb 2016 20:01:43 +0100 Subject: [PATCH 2/2] NEW : Margins module - Check/update buying price on invoice lines --- htdocs/margin/checkMargins.php | 254 ++++++++++++++++++++++++++++++ htdocs/margin/lib/margins.lib.php | 9 ++ 2 files changed, 263 insertions(+) create mode 100644 htdocs/margin/checkMargins.php diff --git a/htdocs/margin/checkMargins.php b/htdocs/margin/checkMargins.php new file mode 100644 index 00000000000..ac53d079298 --- /dev/null +++ b/htdocs/margin/checkMargins.php @@ -0,0 +1,254 @@ + + * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 2015 Marcos García + * Copyright (C) 2016 Florian Henry + * + * 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/margin/checkMargins.php + * \ingroup margin + * \brief Check margins + */ +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT . '/margin/lib/margins.lib.php'; + +$langs->load("companies"); +$langs->load("bills"); +$langs->load("products"); +$langs->load("margins"); + +// Security check + +if ($user->rights->margins->creer) { + $agentid = $user->id; +} else { + accessforbidden(); +} + +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +if (! $sortorder) + $sortorder = "DESC"; +if (! $sortfield) { + $sortfield = 'f.rowid'; +} +$page = GETPOST("page", 'int'); +if ($page == - 1) { + $page = 0; +} +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; + +// Both test are required to be compatible with all browsers +if (GETPOST("button_search_x") || GETPOST("button_search")) { + $action = 'search'; +} elseif (GETPOST("button_updatemagins_x") || GETPOST("button_updatemagins")) { + $action = 'update'; +} + +if ($action == 'update') { + $datapost = $_POST; + + foreach ( $datapost as $key => $value ) { + if (strpos($key, 'buyingprice_') !== false) { + $tmp_array = explode('_', $key); + if (count($tmp_array) > 0) { + $invoicedet_id = $tmp_array[1]; + if (! empty($invoicedet_id)) { + $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facturedet'; + $sql .= ' SET buy_price_ht=\'' . price2num($value) . '\''; + $sql .= ' WHERE rowid=' . $invoicedet_id; + $result = $db->query($sql); + if (!$result) { + setEventMessages($db->lasterror, null, 'errors'); + } + } + } + } + } +} + +$startdate = $enddate = ''; + +$startdate = dol_mktime(0, 0, 0, GETPOST('startdatemonth', 'int'), GETPOST('startdateday', 'int'), GETPOST('startdateyear', 'int')); +$enddate = dol_mktime(23, 59, 59, GETPOST('enddatemonth', 'int'), GETPOST('enddateday', 'int'), GETPOST('enddateyear', 'int')); + +if (! empty($startdate)) { + $options .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int'); +} +if (! empty($enddate)) { + $options .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int'); +} + +/* + * View + */ + +$userstatic = new User($db); +$companystatic = new Societe($db); +$invoicestatic = new Facture($db); +$productstatic = new Product($db); + +$form = new Form($db); + +$title = $langs->trans("CheckMargins"); + +llxHeader('', $title); + +// print_fiche_titre($text); + +// Show tabs +$head = marges_prepare_head($user); +$picto = 'margin'; +dol_fiche_head($head, 'checkMargins', $title, 0, $picto); + +print '
'; +print ''; + +// Start date +print ''; +print ''; +print ''; +print ''; +print ''; +print "
' . $langs->trans('StartDate') . ' (' . $langs->trans("DateValidation") . ')'; +$form->select_date($startdate, 'startdate', '', '', 1, "sel", 1, 1); +print '' . $langs->trans('EndDate') . ' (' . $langs->trans("DateValidation") . ')'; +$form->select_date($enddate, 'enddate', '', '', 1, "sel", 1, 1); +print ''; +print ''; +print '
"; + +$sql = "SELECT"; +$sql .= " f.facnumber, f.rowid as invoiceid, d.rowid as invoicedetid, d.buy_price_ht, d.total_ht, d.subprice, d.label, d.description , d.qty"; +$sql .= " ,d.fk_product"; +$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f "; +$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as d ON d.fk_facture = f.rowid"; +$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON d.fk_product = p.rowid"; +$sql .= " WHERE f.fk_statut > 0"; +$sql .= " AND f.entity = " . getEntity('facture', 1); +if (! empty($startdate)) + $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'"; +if (! empty($enddate)) + $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'"; +$sql .= " AND d.buy_price_ht IS NOT NULL"; +$sql .= $db->order($sortfield, $sortorder); + +$nbtotalofrecords = 0; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + + dol_syslog(__FILE__, LOG_DEBUG); + $result = $db->query($sql); + if ($result) { + $nbtotalofrecords = $db->num_rows($result); + } else { + setEventMessages($db->lasterror, null, 'errors'); + } +} + +$sql .= $db->plimit($conf->liste_limit + 1, $offset); + +dol_syslog(__FILE__, LOG_DEBUG); +$result = $db->query($sql); +if ($result) { + $num = $db->num_rows($result); + + print '
'; + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $nbtotalofrecords, ''); + + print ""; + + print ''; + + print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "f.ref", "", $options, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "", "", $options, 'width=20%', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("UnitPriceHT"), $_SERVER["PHP_SELF"], "d.subprice", "", $options, 'align="right"', $sortfield, $sortorder); + if ($conf->global->MARGIN_TYPE == "1") { + print_liste_field_titre($langs->trans("BuyingPrice"), $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $options, 'align="right"', $sortfield, $sortorder); + } else { + print_liste_field_titre($langs->trans("CostPrice"), $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $options, 'align="right"', $sortfield, $sortorder); + } + print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", $options, 'align="right"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("AmountTTC"), $_SERVER["PHP_SELF"], "d.total_ht", "", $options, 'align="right"', $sortfield, $sortorder); + + print "\n"; + + if ($num > 0) { + $var = true; + + while ( $objp = $db->fetch_object($result) ) { + $var = ! $var; + + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print "\n"; + + $i ++; + } + } + print "
'; + $result_inner = $invoicestatic->fetch($objp->invoiceid); + if ($result_inner < 0) { + setEventMessages($invoicestatic->error, null, 'errors'); + } else { + print $invoicestatic->getNomUrl(1); + } + print ''; + if (! empty($objp->fk_product)) { + $result_inner = $productstatic->fetch($objp->fk_product); + if ($result_inner < 0) { + setEventMessages($productstatic->error, null, 'errors'); + } else { + print $productstatic->getNomUrl(1); + } + } else { + print $objp->label; + print ' '; + print $objp->description; + } + print ''; + print price($objp->subprice); + print ''; + print ''; + print ''; + print $objp->qty; + print ''; + print price($objp->total_ht); + print '
"; +} else { + dol_print_error($db); +} + +print '
' . "\n"; +print '
'; +print '
'; +print '
'; + +$db->free($result); + +llxFooter(); +$db->close(); \ No newline at end of file diff --git a/htdocs/margin/lib/margins.lib.php b/htdocs/margin/lib/margins.lib.php index ce100d49390..2a3d0775eaa 100644 --- a/htdocs/margin/lib/margins.lib.php +++ b/htdocs/margin/lib/margins.lib.php @@ -1,6 +1,7 @@ * Copyright (C) 2014-2015 Marcos García + * Copyright (C) 2016 Florian Henry * * 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 @@ -87,6 +88,14 @@ function marges_prepare_head() $head[$h][1] = $langs->trans($title); $head[$h][2] = 'agentMargins'; + + if ($user->rights->margins->creer) { + $h++; + $head[$h][0] = DOL_URL_ROOT."/margin/checkMargins.php"; + $head[$h][1] = $langs->trans('CheckMargins'); + $head[$h][2] = 'checkMargins'; + } + return $head; }