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 .= '
'; + $morehtmlref .= $object->label; + $morehtmlref .= '
'; + + print dol_banner_tab($object, 'ref', $backlink, 1, 'piece_num', 'piece_num', $morehtmlref); print '
'; + print '
'; print '
'; - print ''; + print '
'; // Account movement print ''; @@ -464,6 +546,37 @@ if ($action == 'create') { print ''; print ''; + // Ref document + print ''; + print ''; + // Date print ''; print ''; print ''; print '
'.($mode == '_tmp' ? ''.$langs->trans("Draft").'' : $object->piece_num).'
'; + print ''; + if ($action != 'editdocref') { + print ''; + } + print '
'; + print $langs->trans('Piece'); + print ''; + if ($permissiontoadd) { + print 'piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + } + print '
'; + print '
'; + if ($action == 'editdocref') { + print '
'; + if ($optioncss != '') { + print ''; + } + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + } else { + print $object->doc_ref; + } + print '
'; print ''; print ''; - // Ref document - print ''; - print ''; - print '
'; @@ -526,41 +639,11 @@ if ($action == 'create') { print '
'; - print ''; - if ($action != 'editdocref') { - print ''; - } - print '
'; - print $langs->trans('Piece'); - print ''; - if ($permissiontoadd) { - print 'piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; - } - print '
'; - print '
'; - if ($action == 'editdocref') { - print '
'; - if ($optioncss != '') { - print ''; - } - print ''; - print ''; - print ''; - print ''; - print ''; - 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 '
'; + print ''; if ($optioncss != '') { print ''; } @@ -757,7 +871,7 @@ if ($action == 'create') { print '
'; - 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 ''; // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because: @@ -842,10 +956,12 @@ if ($action == 'create') { if ($mode == '_tmp' && $action == '' && $permissiontoadd) { print '
'; print '
'; - if ($total_debit == $total_credit) { - print ''.$langs->trans("ValidTransaction").''; + if (empty($total_debit) && empty($total_debit)) { + print ''; + } elseif ($total_debit == $total_credit) { + print ''.$langs->trans("ValidTransaction").''; } else { - print ''; + print ''; } print '   '; diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 89ed928d99b..2ba936fec11 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -2349,12 +2349,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]; diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index 8aab1a26575..1846aafbb75 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -301,7 +301,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)) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2792d60f7d3..9ef772d014e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2768,19 +2768,19 @@ function dol_get_fiche_end($notab = 0) * Show tab footer of a card. * Note: $object->next_prev_filter can be set to restrict select to find next or previous record by $form->showrefnav. * - * @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|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) - * @param string $moreparam More param to add in nav link url. - * @param int $nodbprefix Do not include DB prefix to forge table name - * @param string $morehtmlleft More html code to show before the ref (see $morehtmlref for after) - * @param string $morehtmlstatus More html code to show under navigation arrows - * @param int $onlybanner Put this to 1, if the card will contains only a banner (this add css 'arearefnobottom' on div) - * @param string $morehtmlright More html code to show before navigation arrows + * @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|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) + * @param string $moreparam More param to add in nav link url. + * @param int $nodbprefix Do not include DB prefix to forge table name + * @param string $morehtmlleft More html code to show before the ref (see $morehtmlref for after) + * @param string $morehtmlstatus More html code to show under navigation arrows + * @param int $onlybanner Put this to 1, if the card will contains only a banner (this add css 'arearefnobottom' on div) + * @param string $morehtmlright More html code to show before navigation arrows * @return void */ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldid = 'rowid', $fieldref = 'ref', $morehtmlref = '', $moreparam = '', $nodbprefix = 0, $morehtmlleft = '', $morehtmlstatus = '', $onlybanner = 0, $morehtmlright = '') @@ -3126,6 +3126,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 '
'; print $form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright); print '
';