diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 66838b8c2e2..075b30174b3 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -94,34 +94,90 @@ if (!$user->hasRight('accounting', 'mouvements', 'lire')) { /* * Actions */ - -if ($cancel) { - header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php'); - exit; -} - -if ($action == "confirm_update") { - $error = 0; - - if (((float) $debit != 0.0) && ((float) $credit != 0.0)) { - $error++; - setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); - $action = 'update'; - } - if (empty($accountingaccount_number) || $accountingaccount_number == '-1') { - $error++; - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); - $action = 'update'; +$parameters = array(); //***HOOK +$reshook_onBeforeActions = $hookmanager->executeHooks('onBeforeActions', $parameters, $object, $action); //***HOOK Note that $action and $object may have been modified by some hooks +if ($reshook_onBeforeActions < 0) { //***HOOK + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); //***HOOK +} //***HOOK +if (empty($reshook_onBeforeActions)) { //***HOOK + if ($cancel) { + header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php'); + exit; } + + if ($action == "confirm_update") { + $error = 0; - if (!$error) { - $object = new BookKeeping($db); - - $result = $object->fetch($id, null, $mode); - if ($result < 0) { + if (((float) $debit != 0.0) && ((float) $credit != 0.0)) { $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } else { + setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); + $action = 'update'; + } + if (empty($accountingaccount_number) || $accountingaccount_number == '-1') { + $error++; + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); + $action = 'update'; + } + + if (!$error) { + $object = new BookKeeping($db); + + $result = $object->fetch($id, null, $mode); + if ($result < 0) { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } else { + $object->numero_compte = $accountingaccount_number; + $object->subledger_account = $subledger_account; + $object->subledger_label = $subledger_label; + $object->label_compte = $accountingaccount_label; + $object->label_operation = $label_operation; + $object->debit = $debit; + $object->credit = $credit; + + if ((float) $debit != 0.0) { + $object->montant = $debit; // deprecated + $object->amount = $debit; + $object->sens = 'D'; + } + if ((float) $credit != 0.0) { + $object->montant = $credit; // deprecated + $object->amount = $credit; + $object->sens = 'C'; + } + + $result = $object->update($user, false, $mode); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + if ($mode != '_tmp') { + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + } + + $debit = 0; + $credit = 0; + + $action = ''; + } + } + } + } elseif ($action == "add") { + $error = 0; + + if (((float) $debit != 0.0) && ((float) $credit != 0.0)) { + $error++; + setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); + $action = ''; + } + if (empty($accountingaccount_number) || $accountingaccount_number == '-1') { + $error++; + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); + $action = ''; + } + + if (!$error) { + $object = new BookKeeping($db); + $object->numero_compte = $accountingaccount_number; $object->subledger_account = $subledger_account; $object->subledger_label = $subledger_label; @@ -129,19 +185,28 @@ if ($action == "confirm_update") { $object->label_operation = $label_operation; $object->debit = $debit; $object->credit = $credit; + $object->doc_date = (string) GETPOST('doc_date', 'alpha'); + $object->doc_type = (string) GETPOST('doc_type', 'alpha'); + $object->piece_num = $piece_num; + $object->doc_ref = (string) GETPOST('doc_ref', 'alpha'); + $object->code_journal = $journal_code; + $object->journal_label = $journal_label; + $object->fk_doc = GETPOSTINT('fk_doc'); + $object->fk_docdet = GETPOSTINT('fk_docdet'); if ((float) $debit != 0.0) { $object->montant = $debit; // deprecated $object->amount = $debit; $object->sens = 'D'; } + if ((float) $credit != 0.0) { $object->montant = $credit; // deprecated $object->amount = $credit; $object->sens = 'C'; } - $result = $object->update($user, false, $mode); + $result = $object->createStd($user, false, $mode); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } else { @@ -155,113 +220,70 @@ if ($action == "confirm_update") { $action = ''; } } - } -} elseif ($action == "add") { - $error = 0; - - if (((float) $debit != 0.0) && ((float) $credit != 0.0)) { - $error++; - setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); - $action = ''; - } - if (empty($accountingaccount_number) || $accountingaccount_number == '-1') { - $error++; - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); - $action = ''; - } - - if (!$error) { + } elseif ($action == "confirm_delete") { $object = new BookKeeping($db); - $object->numero_compte = $accountingaccount_number; - $object->subledger_account = $subledger_account; - $object->subledger_label = $subledger_label; - $object->label_compte = $accountingaccount_label; - $object->label_operation = $label_operation; - $object->debit = $debit; - $object->credit = $credit; - $object->doc_date = (string) GETPOST('doc_date', 'alpha'); - $object->doc_type = (string) GETPOST('doc_type', 'alpha'); - $object->piece_num = $piece_num; - $object->doc_ref = (string) GETPOST('doc_ref', 'alpha'); - $object->code_journal = $journal_code; - $object->journal_label = $journal_label; - $object->fk_doc = GETPOSTINT('fk_doc'); - $object->fk_docdet = GETPOSTINT('fk_docdet'); + $result = $object->fetch($id, null, $mode); + $piece_num = $object->piece_num; - if ((float) $debit != 0.0) { - $object->montant = $debit; // deprecated - $object->amount = $debit; - $object->sens = 'D'; - } - - if ((float) $credit != 0.0) { - $object->montant = $credit; // deprecated - $object->amount = $credit; - $object->sens = 'C'; - } - - $result = $object->createStd($user, false, $mode); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } else { - if ($mode != '_tmp') { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + $result = $object->delete($user, false, $mode); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); } + } + $action = ''; + } elseif ($action == "confirm_create") { + $error = 0; - $debit = 0; - $credit = 0; + $object = new BookKeeping($db); - $action = ''; + if (!$journal_code || $journal_code == '-1') { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors'); + $action = 'create'; + $error++; + } + if (!GETPOST('doc_ref', 'alpha')) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors'); + $action = 'create'; + $error++; + } + + if (!$error) { + $object->label_compte = ''; + $object->debit = 0; + $object->credit = 0; + $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear')); + $object->doc_type = GETPOST('doc_type', 'alpha'); + $object->piece_num = GETPOSTINT('next_num_mvt'); + $object->doc_ref = GETPOST('doc_ref', 'alpha'); + $object->code_journal = $journal_code; + $object->journal_label = $journal_label; + $object->fk_doc = 0; + $object->fk_docdet = 0; + $object->montant = 0; // deprecated + $object->amount = 0; + + $result = $object->createStd($user, 0, $mode); + $reshook = $hookmanager->executeHooks('onConfirmCreate_onAfterCreateEmptyLine', $parameters, $object, $action); //***HOOK Note that $action and $object may have been modified by some hooks + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + if ($mode != '_tmp') { + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + } + $action = ''; + $id = $object->id; + $piece_num = $object->piece_num; + } } } -} elseif ($action == "confirm_delete") { - $object = new BookKeeping($db); - $result = $object->fetch($id, null, $mode); - $piece_num = $object->piece_num; - - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - $result = $object->delete($user, false, $mode); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - $action = ''; -} elseif ($action == "confirm_create") { - $error = 0; - - $object = new BookKeeping($db); - - if (!$journal_code || $journal_code == '-1') { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors'); - $action = 'create'; - $error++; - } - if (!GETPOST('doc_ref', 'alpha')) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors'); - $action = 'create'; - $error++; - } - - if (!$error) { - $object->label_compte = ''; - $object->debit = 0; - $object->credit = 0; - $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear')); - $object->doc_type = GETPOST('doc_type', 'alpha'); - $object->piece_num = GETPOSTINT('next_num_mvt'); - $object->doc_ref = GETPOST('doc_ref', 'alpha'); - $object->code_journal = $journal_code; - $object->journal_label = $journal_label; - $object->fk_doc = 0; - $object->fk_docdet = 0; - $object->montant = 0; // deprecated - $object->amount = 0; - - $result = $object->createStd($user, 0, $mode); + if ($action == 'setdate') { + $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) { setEventMessages($object->error, $object->errors, 'errors'); } else { @@ -269,440 +291,405 @@ if ($action == "confirm_update") { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); } $action = ''; - $id = $object->id; - $piece_num = $object->piece_num; } } -} -if ($action == 'setdate') { - $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) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - if ($mode != '_tmp') { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + if ($action == 'setjournal') { + $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode); + $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + if ($mode != '_tmp') { + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + } + $action = ''; } - $action = ''; } -} -if ($action == 'setjournal') { - $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode); - $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - if ($mode != '_tmp') { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + if ($action == 'setdocref') { + $refdoc = GETPOST('doc_ref', 'alpha'); + $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + if ($mode != '_tmp') { + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + } + $action = ''; } - $action = ''; } -} -if ($action == 'setdocref') { - $refdoc = GETPOST('doc_ref', 'alpha'); - $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - if ($mode != '_tmp') { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + // Validate transaction + if ($action == 'valid') { + $result = $object->transformTransaction(0, $piece_num); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + header("Location: list.php?sortfield=t.piece_num&sortorder=asc"); + exit; } - $action = ''; } -} - -// Validate transaction -if ($action == 'valid') { - $result = $object->transformTransaction(0, $piece_num); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - header("Location: list.php?sortfield=t.piece_num&sortorder=asc"); - exit; - } -} +} //***HOOK +$reshook_onAfterActions = $hookmanager->executeHooks('onAfterActions', $parameters, $object, $action); ///***HOOK Note that $action and $object may have been modified by some hooks /* * View */ +$reshook_onBeforeView = $hookmanager->executeHooks('onBeforeView', $parameters, $object, $action); //***HOOK Note that $action and $object may have been modified by some hooks +if ($reshook_onBeforeView < 0) { //***HOOK + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); //***HOOK Error +} //***HOOK +if (empty($reshook_onBeforeView)) { //***HOOK Return 0 so execute the standard prog. + $form = new Form($db); + $formaccounting = new FormAccounting($db); -$form = new Form($db); -$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); -$title = $langs->trans("CreateMvts"); -$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double'; -llxHeader('', $title, $help_url); - -// Confirmation to delete the command -if ($action == 'delete') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1); - print $formconfirm; -} - -if ($action == 'create') { - print load_fiche_titre($title); - - $object = new BookKeeping($db); - $next_num_mvt = $object->getNextNumMvt('_tmp'); - - if (empty($next_num_mvt)) { - dol_print_error(null, 'Failed to get next piece number'); + // Confirmation to delete the command + if ($action == 'delete') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1); + print $formconfirm; } - print '
'; -} else { - $object = new BookKeeping($db); - $result = $object->fetchPerMvt($piece_num, $mode); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - - if (!empty($object->piece_num)) { - $backlink = ''.$langs->trans('BackToList').''; - - if ($mode == '_tmp') { - print load_fiche_titre($langs->trans("CreateMvts"), $backlink); - } else { - print load_fiche_titre($langs->trans("UpdateMvts"), $backlink); + if (empty($next_num_mvt)) { + dol_print_error(null, 'Failed to get next piece number'); } - $head = array(); - $h = 0; - $head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.$object->piece_num.($mode ? '&mode='.$mode : ''); - $head[$h][1] = $langs->trans("Transaction"); - $head[$h][2] = 'transaction'; - $h++; + print '