25require
'../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
32$langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy"));
34$validatemonth =
GETPOST(
'validatemonth',
'int');
35$validateyear =
GETPOST(
'validateyear',
'int');
37$action =
GETPOST(
'action',
'aZ09');
41$month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
43 $year_start =
GETPOST(
"year",
'int');
50$year_end = $year_start + 1;
51$month_end = $month_start - 1;
56$search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
58$year_current = $year_start;
61if (!isModEnabled(
'accounting')) {
64if ($user->socid > 0) {
67if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
79if ($action ==
'validate_movements_confirm' && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
88 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"accounting_bookkeeping";
89 $sql .=
" SET date_validated = '".$db->idate($now).
"'";
90 $sql .=
" WHERE entity = " . ((int) $conf->entity);
91 $sql .=
" AND doc_date >= '" . $db->idate($date_start) .
"'";
92 $sql .=
" AND doc_date <= '" . $db->idate($date_end) .
"'";
93 $sql .=
" AND date_validated IS NULL";
95 dol_syslog(
"/accountancy/closure/index.php action=validate_movement_confirm -> Set movements as validated", LOG_DEBUG);
96 $result = $db->query($sql);
104 setEventMessages($langs->trans(
"AllMovementsWereRecordedAsValidated"),
null,
'mesgs');
106 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?year=".$year_start);
111 setEventMessages($langs->trans(
"NotAllMovementsCouldBeRecordedAsValidated"),
null,
'errors');
121$form =
new Form($db);
124$title = $langs->trans(
'Closure');
126$help_url =
'EN:Module_Double_Entry_Accounting';
130if ($action ==
'validate_movements') {
131 $form_question = array();
133 $month = isset($conf->global->SOCIETE_FISCAL_MONTH_START) ? intval($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
134 $date_start =
new DateTime(sprintf(
'%04d-%02d-%02d', $year_start, $month, 1));
135 $date_end =
new DateTime(sprintf(
'%04d-%02d-%02d', $year_start, $month, 1));
136 $date_end->add(
new DateInterval(
'P1Y'));
137 $date_end->sub(
new DateInterval(
'P1D'));
139 $form_question[
'date_start'] = array(
140 'name' =>
'date_start',
142 'label' => $langs->trans(
'DateStart'),
143 'value' => $date_start->format(
'Y-m-d')
145 $form_question[
'date_end'] = array(
146 'name' =>
'date_end',
148 'label' => $langs->trans(
'DateEnd'),
149 'value' => $date_end->format(
'Y-m-d')
152 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?year='.$year_start, $langs->trans(
'ValidateMovements'), $langs->trans(
'DescValidateMovements', $langs->transnoentitiesnoconv(
"RegistrationInAccounting")),
'validate_movements_confirm', $form_question,
'', 1, 300);
156$textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
157$textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
160print
load_fiche_titre($langs->trans(
"Closure").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
162print
'<span class="opacitymedium">'.$langs->trans(
"DescClosure").
'</span><br>';
168$buttonvalidate =
'<a class="butAction" name="button_validate_movements" href="'.$_SERVER[
"PHP_SELF"].
'?action=validate_movements&year='.$year_start.
'">'.$langs->trans(
"ValidateMovements").
'</a>';
170print_barre_liste($langs->trans(
"OverviewOfMovementsNotValidated"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonvalidate,
'', 0, 1, 0);
172print
'<div class="div-table-responsive-no-min">';
173print
'<table class="noborder centpercent">';
174for ($i = 1; $i <= 12; $i++) {
175 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
179 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
181print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
185 $sql =
"SELECT COUNT(b.rowid) as detail,";
186 for ($i = 1; $i <= 12; $i++) {
187 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
191 $sql .=
" SUM(".$db->ifsql(
"MONTH(b.doc_date)=".$j,
"1",
"0").
") AS month".str_pad($j, 2,
"0", STR_PAD_LEFT).
",";
193 $sql .=
" COUNT(b.rowid) as total";
194 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b";
195 $sql .=
" WHERE b.doc_date >= '".$db->idate($search_date_start).
"'";
196 $sql .=
" AND b.doc_date <= '".$db->idate($search_date_end).
"'";
197 $sql .=
" AND b.entity IN (".getEntity(
'bookkeeping', 0).
")";
199 $sql .=
" AND b.doc_date BETWEEN 0 AND 0";
202 $sql =
"SELECT COUNT(b.rowid) as detail,";
203 for ($i = 1; $i <= 12; $i++) {
204 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
208 $sql .=
" SUM(".$db->ifsql(
"MONTH(b.doc_date)=".$j,
"1",
"0").
") AS month".str_pad($j, 2,
"0", STR_PAD_LEFT).
",";
210 $sql .=
" COUNT(b.rowid) as total";
211 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b";
212 $sql .=
" WHERE b.doc_date >= '".$db->idate($search_date_start).
"'";
213 $sql .=
" AND b.doc_date <= '".$db->idate($search_date_end).
"'";
214 $sql .=
" AND b.entity IN (".getEntity(
'bookkeeping', 0).
")";
215 $sql .=
" AND date_validated IS NULL";
218dol_syslog(
'htdocs/accountancy/closure/index.php', LOG_DEBUG);
219$resql = $db->query($sql);
221 $num = $db->num_rows($resql);
223 while ($row = $db->fetch_row($resql)) {
224 print
'<tr class="oddeven">';
225 for ($i = 1; $i <= 12; $i++) {
226 print
'<td class="right">'.$row[$i].
'</td>';
228 print
'<td class="right"><b>'.$row[13].
'</b></td>';
234 print $db->lasterror();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage Ledger (General Ledger and Subledger)
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.