diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 70309a0428d..8f08f1c1d2f 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -90,6 +90,8 @@ if (!$user->hasRight('accounting', 'mouvements', 'lire')) { accessforbidden(); } +$permissiontoadd = $user->hasRight('accounting', 'mouvements', 'creer'); + /* * Actions @@ -106,7 +108,7 @@ if (empty($reshook)) { exit; } - if ($action == "confirm_update") { + if ($action == "confirm_update" && $permissiontoadd) { $error = 0; if (((float) $debit != 0.0) && ((float) $credit != 0.0)) { @@ -162,7 +164,7 @@ if (empty($reshook)) { } } } - } elseif ($action == "add") { + } elseif ($action == "add" && $permissiontoadd) { $error = 0; if (((float) $debit != 0.0) && ((float) $credit != 0.0)) { @@ -221,7 +223,7 @@ if (empty($reshook)) { $action = ''; } } - } elseif ($action == "confirm_delete") { + } elseif ($action == "confirm_delete" && $permissiontoadd) { $object = new BookKeeping($db); $result = $object->fetch($id, null, $mode); @@ -238,7 +240,7 @@ if (empty($reshook)) { } } $action = ''; - } elseif ($action == "confirm_create") { + } elseif ($action == "confirm_create" && $permissiontoadd) { $error = 0; $object = new BookKeeping($db); @@ -287,7 +289,7 @@ if (empty($reshook)) { } } - if ($action == 'setdate') { + if ($action == 'setdate' && $permissiontoadd) { $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear')); $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode); if ($result < 0) { @@ -300,7 +302,7 @@ if (empty($reshook)) { } } - if ($action == 'setjournal') { + if ($action == 'setjournal' && $permissiontoadd) { $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode); $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode); if ($result < 0) { @@ -313,7 +315,7 @@ if (empty($reshook)) { } } - if ($action == 'setdocref') { + if ($action == 'setdocref' && $permissiontoadd) { $refdoc = GETPOST('doc_ref', 'alpha'); $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode); if ($result < 0) { @@ -327,7 +329,7 @@ if (empty($reshook)) { } // Validate transaction - if ($action == 'valid') { + if ($action == 'valid' && $permissiontoadd) { $result = $object->transformTransaction(0, $piece_num); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -338,9 +340,12 @@ if (empty($reshook)) { } } + + /* * View */ + $form = new Form($db); $formaccounting = new FormAccounting($db); @@ -460,12 +465,16 @@ if ($action == 'create') { print $langs->trans('Docdate'); print ''; if ($action != 'editdate') { - print 'piece_num)).'&mode='.urlencode((string) ($mode)).'">'.img_edit($langs->transnoentitiesnoconv('SetDate'), 1).''; + print ''; + if ($permissiontoadd) { + print 'piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('SetDate'), 1).''; + } + print ''; } print ''; print ''; if ($action == 'editdate') { - print '
'; + print ''; if ($optioncss != '') { print ''; } @@ -487,12 +496,16 @@ if ($action == 'create') { print $langs->trans('Codejournal'); print ''; if ($action != 'editjournal') { - print 'piece_num)).'&mode='.urlencode((string) ($mode)).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + print ''; + if ($permissiontoadd) { + print 'piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + } + print ''; } print ''; print ''; if ($action == 'editjournal') { - print ''; + print ''; if ($optioncss != '') { print ''; } @@ -514,12 +527,16 @@ if ($action == 'create') { print $langs->trans('Piece'); print ''; if ($action != 'editdocref') { - print 'piece_num)).'&mode='.urlencode((string) ($mode)).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + print ''; + if ($permissiontoadd) { + print 'piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + } + print ''; } print ''; print ''; if ($action == 'editdocref') { - print ''; + print ''; if ($optioncss != '') { print ''; } @@ -692,20 +709,20 @@ if ($action == 'create') { } foreach ($object->linesmvt as $line) { - print ''; $total_debit += $line->debit; $total_credit += $line->credit; if ($action == 'update' && $line->id == $id) { + print ''; print ''; print ''; print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500'); print ''; print ''; // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because: - // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases. - // Also, it is not possible to use a value that is not in the list. - // Also, the label is not automatically filled when a value is selected. + // - It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases. + // - Also, it is not possible to use a value that is not in the list. + // - Also, the label is not automatically filled when a value is selected. if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) { print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label'); } else { @@ -715,14 +732,16 @@ if ($action == 'create') { print '
subledger_label).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccountLabel")).'">'; print ''; print 'label_operation).'">'; - print 'debit)).'">'; - print 'credit)).'">'; + print 'debit)).'">'; + print 'credit)).'">'; print ''; print ''."\n"; print ''; print ''; + print "\n"; } elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) { - if ($action == "" || $action == 'add') { + if (($action == "" || $action == 'add') && $permissiontoadd) { + print ''; print ''; print ''; print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500'); @@ -739,24 +758,26 @@ if ($action == 'create') { } print '
'; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; print ''; + print "\n"; } } else { + print ''; print ''; $resultfetch = $accountingaccount->fetch(null, $line->numero_compte, true); print ''; if ($resultfetch > 0) { print $accountingaccount->getNomUrl(0, 1, 1, '', 0); } else { - print $line->numero_compte.' ('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')'; + print dol_escape_htmltag($line->numero_compte).' ('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')'; } print ''; print ''.length_accounta($line->subledger_account); if ($line->subledger_label) { - print ' - '.$line->subledger_label.''; + print ' - '.dol_escape_htmltag($line->subledger_label).''; } print ''; print ''.$line->label_operation.''; @@ -764,34 +785,35 @@ if ($action == 'create') { print ''.($line->credit != 0 ? price($line->credit) : '').''; print ''; - if (empty($line->date_export) && empty($line->date_validation)) { - print 'id . '&piece_num=' . urlencode($line->piece_num) . '&mode=' . urlencode($mode) . '&token=' . urlencode(newToken()) . '">'; - print img_edit('', 0, 'class="marginrightonly"'); - print '  '; - } else { - print ''; - print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"'); - print '  '; - } - - if (empty($line->date_validation)) { - $actiontodelete = 'delete'; - if ($mode == '_tmp' || $action != 'delmouv') { - $actiontodelete = 'confirm_delete'; + if ($permissiontoadd) { + if (empty($line->date_export) && empty($line->date_validation)) { + print 'id . '&piece_num=' . urlencode($line->piece_num) . '&mode=' . urlencode((string) $mode) . '&token=' . urlencode(newToken()) . '">'; + print img_edit('', 0, 'class="marginrightonly"'); + print '  '; + } else { + print ''; + print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"'); + print '  '; } - print ''; - print img_delete(); - print ''; - } else { - print ''; - print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated")); - print ''; - } + if (empty($line->date_validation)) { + $actiontodelete = 'delete'; + if ($mode == '_tmp' || $action != 'delmouv') { + $actiontodelete = 'confirm_delete'; + } + print ''; + print img_delete(); + print ''; + } else { + print ''; + print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated")); + print ''; + } + } print ''; + print "\n"; } - print "\n"; } $total_debit = price2num($total_debit, 'MT'); @@ -804,7 +826,7 @@ if ($action == 'create') { print ''; print ''; - if ($mode == '_tmp' && $action == '') { + if ($mode == '_tmp' && $action == '' && $permissiontoadd) { print '
'; print '
'; if ($total_debit == $total_credit) { diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 8a1c9facc24..e38bcd94993 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1422,7 +1422,7 @@ class BookKeeping extends CommonObject $this->piece_num = (int) $this->piece_num; } - $result = $this->canModifyBookkeeping($this->id); + $result = $this->canModifyBookkeeping($this->id, $mode); if ($result < 0) { return -1; } elseif ($result == 0) { @@ -2397,13 +2397,13 @@ class BookKeeping extends CommonObject $bookkeeping = new BookKeeping($this->db); $result = $bookkeeping->fetch($id, null, $mode); + if ($result <= 0) { return $result; } - if (!empty($conf->cache['active_fiscal_period_cached']) && is_array($conf->cache['active_fiscal_period_cached'])) { foreach ($conf->cache['active_fiscal_period_cached'] as $fiscal_period) { - if ($fiscal_period['date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period['date_end']) { + if (!empty($fiscal_period['date_start']) && $fiscal_period['date_start'] <= $bookkeeping->doc_date && (empty($fiscal_period['date_end']) || $bookkeeping->doc_date <= $fiscal_period['date_end'])) { return 1; } } @@ -2447,7 +2447,7 @@ class BookKeeping extends CommonObject if (!empty($conf->cache['active_fiscal_period_cached']) && is_array($conf->cache['active_fiscal_period_cached'])) { foreach ($conf->cache['active_fiscal_period_cached'] as $fiscal_period) { - if ($fiscal_period['date_start'] <= $date && $date <= $fiscal_period['date_end']) { + if (!empty($fiscal_period['date_start']) && $fiscal_period['date_start'] <= $date && (empty($fiscal_period['date_end']) || $date <= $fiscal_period['date_end'])) { return 1; } }