diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 096c2a88d50..dcd36d22c00 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -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('bookkeepingccard', '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'); /* @@ -180,7 +186,11 @@ if (empty($reshook)) { } if (!$error) { - $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear')); + if (GETPOSTINT('doc_datemonth') && GETPOSTINT('doc_dateday') && GETPOSTINT('doc_dateyear')) { + $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear')); + } else { + $datedoc = (int) GETPOSTINT('doc_date'); // TODO Use instead the mode day-month-year + } $object = new BookKeeping($db); @@ -213,6 +223,7 @@ if (empty($reshook)) { } $result = $object->createStd($user, false, $mode); + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } else { @@ -226,7 +237,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); @@ -277,6 +288,7 @@ if (empty($reshook)) { $object->amount = 0; $result = $object->createStd($user, 0, $mode); + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -343,6 +355,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++; + } 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(); + } + } } @@ -356,6 +428,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 @@ -435,11 +508,11 @@ if ($action == 'create') { if (!empty($object->piece_num)) { $backlink = ''.$langs->trans('BackToList').''; - 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; @@ -450,13 +523,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 .= '
'; + $morehtmlref .= '| '.($mode == '_tmp' ? ''.$langs->trans("Draft").'' : $object->piece_num).' | '; print '|||||
';
+ print '
| '; + if ($action == 'editdocref') { + print ''; + } else { + print $object->doc_ref; + } + print ' | '; + print '||||
';
print '
';
print '';
@@ -663,21 +746,52 @@ if ($action == 'create') {
print ' ';
- print dol_get_fiche_end();
-
+ print '';
print '';
- print ''; + + 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 && !$atleastoneexported) { + print "\n".' '."\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().'&toselect='.implode(',', $tmptoselect), '', $permissiontodelete);
+ }
+ }
+ }
+
+ print ' ';
+ }
+
// List of movements
print load_fiche_titre($langs->trans("ListeMvts"), '', '');
- print ' |