forked from Wavyzz/dolibarr
FIX Maxi debug edit/delete accounting transaction
This commit is contained in:
@@ -35,18 +35,20 @@ require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.php';
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array("accountancy", "bills", "compta"));
|
||||
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
$cancel = GETPOST('cancel', 'aZ09');
|
||||
$confirm = GETPOST('confirm', 'alpha');
|
||||
|
||||
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
|
||||
|
||||
$id = GETPOSTINT('id'); // id of record
|
||||
$mode = GETPOST('mode', 'aZ09'); // '' or '_tmp'
|
||||
$piece_num = GETPOSTINT("piece_num"); // id of transaction (several lines share the same transaction id)
|
||||
$piece_num = GETPOSTINT("piece_num") ? GETPOSTINT("piece_num") : GETPOST('ref'); // id of transaction (several lines share the same transaction id)
|
||||
|
||||
$accountingaccount = new AccountingAccount($db);
|
||||
$accountingjournal = new AccountingJournal($db);
|
||||
@@ -78,6 +80,9 @@ if (!empty($update)) {
|
||||
$action = 'confirm_update';
|
||||
}
|
||||
|
||||
// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
|
||||
$hookmanager->initHooks(array('bookkeepingcard', 'globalcard'));
|
||||
|
||||
$object = new BookKeeping($db);
|
||||
|
||||
// Security check
|
||||
@@ -92,6 +97,7 @@ if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
|
||||
}
|
||||
|
||||
$permissiontoadd = $user->hasRight('accounting', 'mouvements', 'creer');
|
||||
$permissiontodelete = $user->hasRight('accounting', 'mouvements', 'supprimer');
|
||||
|
||||
|
||||
/*
|
||||
@@ -211,6 +217,7 @@ if (empty($reshook)) {
|
||||
}
|
||||
|
||||
$result = $object->createStd($user, false, $mode);
|
||||
|
||||
if ($result < 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
} else {
|
||||
@@ -224,7 +231,7 @@ if (empty($reshook)) {
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
} elseif ($action == "confirm_delete" && $permissiontoadd) {
|
||||
} elseif ($action == "confirm_delete" && $permissiontoadd) { // Delete line
|
||||
$object = new BookKeeping($db);
|
||||
|
||||
$result = $object->fetch($id, null, $mode);
|
||||
@@ -273,6 +280,7 @@ if (empty($reshook)) {
|
||||
$object->amount = 0;
|
||||
|
||||
$result = $object->createStd($user, 0, $mode);
|
||||
|
||||
if ($result < 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
|
||||
@@ -339,6 +347,66 @@ if (empty($reshook)) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all lines into the transaction
|
||||
$toselect = explode(',', GETPOST('toselect', 'alphanohtml'));
|
||||
|
||||
if ($action == 'deletebookkeepingwriting' && $confirm == "yes" && $permissiontodelete) {
|
||||
$db->begin();
|
||||
|
||||
if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
|
||||
$lettering = new Lettering($db);
|
||||
$nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
|
||||
if ($nb_lettering < 0) {
|
||||
setEventMessages('', $lettering->errors, 'errors');
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
$nbok = 0;
|
||||
$result = 0;
|
||||
if (!$error) {
|
||||
foreach ($toselect as $toselectid) {
|
||||
$result = $object->fetch($toselectid);
|
||||
if ($result >= 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
|
||||
$result = $object->deleteMvtNum($object->piece_num);
|
||||
if ($result >= 0) {
|
||||
$nbok += $result;
|
||||
} else {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
} elseif ($result < 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$error++;
|
||||
break;
|
||||
} elseif (isset($object->date_validation) && $object->date_validation != '') {
|
||||
setEventMessages($langs->trans("ValidatedRecordWhereFound"), null, 'errors');
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
|
||||
// Message for elements well deleted
|
||||
if ($nbok > 1) {
|
||||
setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
|
||||
} elseif ($nbok > 0) {
|
||||
setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
|
||||
} else {
|
||||
setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
|
||||
}
|
||||
|
||||
header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?noreset=1');
|
||||
exit;
|
||||
} else {
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -352,6 +420,7 @@ $formaccounting = new FormAccounting($db);
|
||||
|
||||
$title = $langs->trans("CreateMvts");
|
||||
$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double';
|
||||
|
||||
llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-consultation page-card');
|
||||
|
||||
// Confirmation to delete the command
|
||||
@@ -431,11 +500,11 @@ if ($action == 'create') {
|
||||
if (!empty($object->piece_num)) {
|
||||
$backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>';
|
||||
|
||||
if ($mode == '_tmp') {
|
||||
/*if ($mode == '_tmp') {
|
||||
print load_fiche_titre($langs->trans("CreateMvts"), $backlink);
|
||||
} else {
|
||||
print load_fiche_titre($langs->trans("UpdateMvts"), $backlink);
|
||||
}
|
||||
}*/
|
||||
|
||||
$head = array();
|
||||
$h = 0;
|
||||
@@ -446,13 +515,22 @@ if ($action == 'create') {
|
||||
|
||||
print dol_get_fiche_head($head, 'transaction', '', -1);
|
||||
|
||||
//dol_banner_tab($object, '', $backlink);
|
||||
$object->ref = $object->piece_num;
|
||||
$object->label = $object->doc_ref;
|
||||
|
||||
$morehtmlref .= '<div style="clear: both;"></div>';
|
||||
$morehtmlref .= '<div class="refidno opacitymedium">';
|
||||
$morehtmlref .= $object->label;
|
||||
$morehtmlref .= '</div>';
|
||||
|
||||
print dol_banner_tab($object, 'ref', $backlink, 1, 'piece_num', 'piece_num', $morehtmlref);
|
||||
|
||||
print '<div class="fichecenter">';
|
||||
|
||||
print '<div class="fichehalfleft">';
|
||||
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
print '<table class="border tableforfield" width="100%">';
|
||||
print '<table class="border tableforfield centpercent">';
|
||||
|
||||
// Account movement
|
||||
print '<tr>';
|
||||
@@ -460,6 +538,37 @@ if ($action == 'create') {
|
||||
print '<td>'.($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp '.$object->piece_num.'">'.$langs->trans("Draft").'</span>' : $object->piece_num).'</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Ref document
|
||||
print '<tr><td>';
|
||||
print '<table class="nobordernopadding centpercent"><tr><td>';
|
||||
print $langs->trans('Piece');
|
||||
print '</td>';
|
||||
if ($action != 'editdocref') {
|
||||
print '<td class="right">';
|
||||
if ($permissiontoadd) {
|
||||
print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdocref&token='.newToken().'&piece_num='.((int) $object->piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a>';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
print '</tr></table>';
|
||||
print '</td><td>';
|
||||
if ($action == 'editdocref') {
|
||||
print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
|
||||
if ($optioncss != '') {
|
||||
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
|
||||
}
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="setdocref">';
|
||||
print '<input type="hidden" name="mode" value="'.$mode.'">';
|
||||
print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
|
||||
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
|
||||
print '</form>';
|
||||
} else {
|
||||
print $object->doc_ref;
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Date
|
||||
print '<tr><td>';
|
||||
print '<table class="nobordernopadding centpercent"><tr><td>';
|
||||
@@ -522,41 +631,11 @@ if ($action == 'create') {
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Ref document
|
||||
print '<tr><td>';
|
||||
print '<table class="nobordernopadding centpercent"><tr><td>';
|
||||
print $langs->trans('Piece');
|
||||
print '</td>';
|
||||
if ($action != 'editdocref') {
|
||||
print '<td class="right">';
|
||||
if ($permissiontoadd) {
|
||||
print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdocref&token='.newToken().'&piece_num='.((int) $object->piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a>';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
print '</tr></table>';
|
||||
print '</td><td>';
|
||||
if ($action == 'editdocref') {
|
||||
print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
|
||||
if ($optioncss != '') {
|
||||
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
|
||||
}
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="setdocref">';
|
||||
print '<input type="hidden" name="mode" value="'.$mode.'">';
|
||||
print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
|
||||
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
|
||||
print '</form>';
|
||||
} else {
|
||||
print $object->doc_ref;
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
print '<div class="fichehalfright">';
|
||||
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
@@ -651,21 +730,52 @@ if ($action == 'create') {
|
||||
|
||||
print '</div>';
|
||||
|
||||
print dol_get_fiche_end();
|
||||
|
||||
print '</div>';
|
||||
print '<div class="clearboth"></div>';
|
||||
|
||||
print '<br>';
|
||||
|
||||
print dol_get_fiche_end();
|
||||
|
||||
|
||||
$result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
|
||||
|
||||
if ($result < 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
} else {
|
||||
// Variable that contains all transaction lines
|
||||
$tmptoselect = array();
|
||||
$atleastonevalidated = 0;
|
||||
$atleastoneexported = 0;
|
||||
foreach ($object->linesmvt as $line) {
|
||||
$tmptoselect[] = $line->id;
|
||||
if (!empty($line->date_validation)) {
|
||||
$atleastonevalidated = 1;
|
||||
}
|
||||
if (!empty($line->date_export) || !empty($line->date_validation)) {
|
||||
$atleastoneexported = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode != '_tmp' && !$atleastonevalidated) {
|
||||
print "\n".'<div class="tabsAction">'."\n";
|
||||
|
||||
$parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
if (empty($reshook)) {
|
||||
if ($permissiontodelete) {
|
||||
if (!isset($hookmanager->resArray['no_button_edit']) || $hookmanager->resArray['no_button_edit'] != 1) {
|
||||
print dolGetButtonAction('', $langs->trans('Delete'), 'delete', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=deletebookkeepingwriting&confirm=yes&token='.newToken().'&piece_num='.((int) $object->piece_num).'&toselect='.implode(',', $tmptoselect), '', $permissiontodelete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
// List of movements
|
||||
print load_fiche_titre($langs->trans("ListeMvts"), '', '');
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="post">';
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
|
||||
if ($optioncss != '') {
|
||||
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
|
||||
}
|
||||
@@ -745,7 +855,7 @@ if ($action == 'create') {
|
||||
print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
|
||||
print '<!-- td columns in add mode -->';
|
||||
print '<td>';
|
||||
print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
|
||||
print $formaccounting->select_account($action == 'add' ? GETPOST('accountingaccount_number') : '', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
// TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
|
||||
@@ -830,10 +940,12 @@ if ($action == 'create') {
|
||||
if ($mode == '_tmp' && $action == '' && $permissiontoadd) {
|
||||
print '<br>';
|
||||
print '<div class="center">';
|
||||
if ($total_debit == $total_credit) {
|
||||
print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'&action=valid">'.$langs->trans("ValidTransaction").'</a>';
|
||||
if (empty($total_debit) && empty($total_debit)) {
|
||||
print '<input type="submit" class="button" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("EnterNonEmptyLinesFirst")).'" value="'.dol_escape_htmltag($langs->trans("ValidTransaction")).'">';
|
||||
} elseif ($total_debit == $total_credit) {
|
||||
print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'&action=valid&token='.newToken().'">'.$langs->trans("ValidTransaction").'</a>';
|
||||
} else {
|
||||
print '<input type="submit" class="button" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("MvtNotCorrectlyBalanced", $debit, $credit)).'" value="'.dol_escape_htmltag($langs->trans("ValidTransaction")).'">';
|
||||
print '<input type="submit" class="button" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("MvtNotCorrectlyBalanced", $total_debit, $total_credit)).'" value="'.dol_escape_htmltag($langs->trans("ValidTransaction")).'">';
|
||||
}
|
||||
|
||||
print ' ';
|
||||
|
||||
@@ -1704,7 +1704,7 @@ class BookKeeping extends CommonObject
|
||||
*
|
||||
* @param int $piecenum Piecenum to delete
|
||||
* @param string $mode Mode ('' or '_tmp')
|
||||
* @return int Result
|
||||
* @return int Nb of record deleted
|
||||
*/
|
||||
public function deleteMvtNum($piecenum, $mode = '')
|
||||
{
|
||||
@@ -1715,6 +1715,8 @@ class BookKeeping extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
|
||||
$nbprocessed = 0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// first check if line not yet in bookkeeping
|
||||
@@ -1735,10 +1737,13 @@ class BookKeeping extends CommonObject
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
} else {
|
||||
$nbprocessed = $this->db->affected_rows($resql);
|
||||
}
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
|
||||
return $nbprocessed;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2346,12 +2351,20 @@ class BookKeeping extends CommonObject
|
||||
|
||||
$sql_list = array();
|
||||
if (!empty($conf->cache['active_fiscal_period_cached']) && is_array($conf->cache['active_fiscal_period_cached'])) {
|
||||
$i = 0;
|
||||
foreach ($conf->cache['active_fiscal_period_cached'] as $fiscal_period) {
|
||||
$sql_list[] = "('" . $this->db->idate($fiscal_period['date_start']) . "' <= ".$this->db->sanitize($alias)."doc_date AND ".$this->db->sanitize($alias)."doc_date <= '" . $this->db->idate($fiscal_period['date_end']) . "')";
|
||||
$sql_list[$i] = "(";
|
||||
$sql_list[$i] .= "'".$this->db->idate($fiscal_period['date_start']) . "' <= ".$this->db->sanitize($alias)."doc_date";
|
||||
if (!empty($fiscal_period['date_end'])) {
|
||||
$sql_list[$i] .= " AND ";
|
||||
$sql_list[$i] .= $this->db->sanitize($alias)."doc_date <= '" . $this->db->idate($fiscal_period['date_end'])."'";
|
||||
}
|
||||
$sql_list[$i] .= ")";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$sqlsanitized = implode(' OR ', $sql_list);
|
||||
self::$can_modify_bookkeeping_sql_cached[$alias] = !empty($sql_list) ? " AND (".$sqlsanitized.")" : "";
|
||||
self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ? "" : " AND (".$sqlsanitized.")";
|
||||
}
|
||||
|
||||
return self::$can_modify_bookkeeping_sql_cached[$alias];
|
||||
|
||||
@@ -300,7 +300,7 @@ if (!empty($current_fiscal_period)) {
|
||||
print load_fiche_titre($langs->trans("Closure") . " - " . $fiscal_period_nav_text, '', 'title_accountancy');
|
||||
|
||||
if (empty($current_fiscal_period)) {
|
||||
print $langs->trans('ErrorNoFiscalPeriodActiveFound', $langs->trans("Accounting"), $langs->trans("Setup"), $langs->trans("FiscalPeriod"));
|
||||
print $langs->trans('ErrorNoFiscalPeriodActiveFound', $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("FiscalPeriod"));
|
||||
}
|
||||
|
||||
if (isset($current_fiscal_period)) {
|
||||
|
||||
@@ -2678,7 +2678,7 @@ function dol_get_fiche_end($notab = 0)
|
||||
* @param CommonObject $object Object to show
|
||||
* @param string $paramid Name of parameter to use to name the id into the URL next/previous link
|
||||
* @param string $morehtml More html content to output just before the nav bar
|
||||
* @param int $shownav Show Condition (navigation is shown if value is 1)
|
||||
* @param int|bool $shownav Show Condition (navigation is shown if value is 1 or true)
|
||||
* @param string $fieldid Name of the field in DB to use to select next et previous (we make the select max and min on this field). Use 'none' for no prev/next search.
|
||||
* @param string $fieldref Name of the field (object->ref) to use to select next et previous
|
||||
* @param string $morehtmlref More html to show after the ref (see $morehtmlleft for before)
|
||||
@@ -3030,6 +3030,11 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
|
||||
$morehtmlref = $hookmanager->resPrint;
|
||||
}
|
||||
|
||||
// $morehtml is the right part (link "Back to list")
|
||||
// $morehtmlleft is the picto or photo of banner
|
||||
// $morehtmlstatus is part under the status
|
||||
// $morehtmlright is part of htmlright
|
||||
|
||||
print '<div class="'.($onlybanner ? 'arearefnobottom ' : 'arearef ').'heightref valignmiddle centpercent">';
|
||||
print $form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
|
||||
print '</div>';
|
||||
|
||||
Reference in New Issue
Block a user