diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index 9a871514215..4f795274ad2 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -39,6 +39,9 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
+if (!empty($conf->margin->enabled)) {
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
+}
require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
@@ -203,6 +206,10 @@ $arrayfields = array(
'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>200),
'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>210),
'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>220), // Not enabled by default because slow
+ 'total_pa' => array('label' => ($conf->global->MARGIN_TYPE == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (empty($conf->margin->enabled)?0:1)),
+ 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (empty($conf->margin->enabled)?0:1)),
+ 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (empty($conf->margin->enabled) || empty($conf->global->DISPLAY_MARGIN_RATES)?0:1)),
+ 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (empty($conf->margin->enabled) || empty($conf->global->DISPLAY_MARK_RATES)?0:1)),
'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
'f.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))),
@@ -405,6 +412,10 @@ if ($massaction == 'makepayment'){
$form = new Form($db);
$formother = new FormOther($db);
$formfile = new FormFile($db);
+$formmargin = null;
+if (!empty($conf->margin->enabled)) {
+ $formmargin = new FormMargin($db);
+}
$bankaccountstatic = new Account($db);
$facturestatic = new Facture($db);
$formcompany = new FormCompany($db);
@@ -1019,6 +1030,26 @@ if ($resql)
print '
';
print ' | ';
}
+ if (!empty($arrayfields['total_pa']['checked']))
+ {
+ print '';
+ print ' | ';
+ }
+ if (!empty($arrayfields['total_margin']['checked']))
+ {
+ print '';
+ print ' | ';
+ }
+ if (!empty($arrayfields['total_margin_rate']['checked']))
+ {
+ print '';
+ print ' | ';
+ }
+ if (!empty($arrayfields['total_mark_rate']['checked']))
+ {
+ print '';
+ print ' | ';
+ }
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
@@ -1102,6 +1133,10 @@ if ($resql)
if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
if (!empty($arrayfields['multicurrency_rtp']['checked'])) print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
+ if (!empty($arrayfields['total_pa']['checked'])) print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
+ if (!empty($arrayfields['total_margin']['checked'])) print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
+ if (!empty($arrayfields['total_margin_rate']['checked'])) print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
+ if (!empty($arrayfields['total_mark_rate']['checked'])) print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields
@@ -1205,6 +1240,12 @@ if ($resql)
$facturestatic->alreadypaid = $paiement;
+ $marginInfo = array();
+ if (!empty($conf->margin->enabled)) {
+ $facturestatic->fetch_lines();
+ $marginInfo = $formmargin->getMarginInfosArray($facturestatic);
+ }
+
print '' . price($marginInfo['pa_total']) . '';
+ if (!$i) $totalarray['nbfield']++;
+ }
+ // Total margin
+ if (!empty($arrayfields['total_margin']['checked']))
+ {
+ print '| ' . price($marginInfo['total_margin']) . ' | ';
+ if (!$i) $totalarray['nbfield']++;
+ }
+ // Total margin rate
+ if (!empty($arrayfields['total_margin_rate']['checked']))
+ {
+ print '' . (($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%') . ' | ';
+ if (!$i) $totalarray['nbfield']++;
+ }
+ // total mark rate
+ if (!empty($arrayfields['total_mark_rate']['checked']))
+ {
+ print '' . (($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%') . ' | ';
+ if (!$i) $totalarray['nbfield']++;
+ }
+
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
// Fields from hook
diff --git a/htdocs/document.php b/htdocs/document.php
index bc0cc1eb933..a608dfe820e 100644
--- a/htdocs/document.php
+++ b/htdocs/document.php
@@ -173,7 +173,7 @@ $refname = basename(dirname($original_file)."/");
if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart');
// Check security and set return info with full path of file
-$check_access = dol_check_secure_access_document($modulepart, $original_file, $entity, $refname);
+$check_access = dol_check_secure_access_document($modulepart, $original_file, $entity, $user, $refname);
$accessallowed = $check_access['accessallowed'];
$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
$fullpath_original_file = $check_access['original_file']; // $fullpath_original_file is now a full path name