25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
32 $langs->loadLangs(array(
"compta",
"bills",
"other",
"main",
"accountancy"));
34 $socid =
GETPOST(
'socid',
'int');
36 $action =
GETPOST(
'action',
'aZ09');
39 if (empty($conf->accounting->enabled)) {
44 if (!$user->rights->accounting->fiscalyear->write)
49 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
55 $year_end = $year_start + 1;
56 $month_end = $month_start - 1;
62 $search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
64 $year_current = $year_start;
69 if ($action ==
'validate_movements_confirm' && $user->rights->accounting->fiscalyear->write) {
70 $result = $object->fetchAll();
83 if (is_array($object->lines))
85 foreach ($object->lines as $movement)
89 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"accounting_bookkeeping";
90 $sql .=
" SET date_validated = '".$db->idate($now).
"'";
91 $sql .=
" WHERE rowid = ".$movement->id;
92 $sql .=
" AND doc_date >= '" .
dol_print_date($date_start,
'dayrfc') .
"'";
93 $sql .=
" AND doc_date <= '" .
dol_print_date($date_end,
'dayrfc') .
"'";
95 dol_syslog(
"/accountancy/closure/index.php :: Function validate_movement_confirm Specify movements as validated sql=".$sql, LOG_DEBUG);
96 $result = $db->query($sql);
108 setEventMessages($langs->trans(
"AllMovementsWereRecordedAsValidated"), null,
'mesgs');
112 setEventMessages($langs->trans(
"NotAllMovementsCouldBeRecordedAsValidated"), null,
'errors');
114 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?year=".$year_start);
123 $form =
new Form($db);
128 if ($action ==
'validate_movements') {
129 $form_question = array();
131 $month = isset($conf->global->SOCIETE_FISCAL_MONTH_START) ? intval($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
132 $date_start =
new DateTime(sprintf(
'%04d-%02d-%02d', $year_start, $month, 1));
133 $date_end =
new DateTime(sprintf(
'%04d-%02d-%02d', $year_start, $month, 1));
134 $date_end->add(
new DateInterval(
'P1Y'));
135 $date_end->sub(
new DateInterval(
'P1D'));
137 $form_question[
'date_start'] = array(
138 'name' =>
'date_start',
140 'label' => $langs->trans(
'DateStart'),
141 'value' => $date_start->format(
'Y-m-d')
143 $form_question[
'date_end'] = array(
144 'name' =>
'date_end',
146 'label' => $langs->trans(
'DateEnd'),
147 'value' => $date_end->format(
'Y-m-d')
150 $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);
154 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
155 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
158 print load_fiche_titre($langs->trans(
"Closure").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
160 print '<span class="opacitymedium">'.$langs->trans(
"DescClosure").
'</span><br>';
166 $buttonvalidate =
'<a class="butAction" name="button_validate_movements" href="'.$_SERVER[
"PHP_SELF"].
'?action=validate_movements&year='.$year_start.
'">'.$langs->trans(
"ValidateMovements").
'</a>';
168 print_barre_liste($langs->trans(
"OverviewOfMovementsNotValidated"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonvalidate,
'', 0, 1, 1);
170 print '<div class="div-table-responsive-no-min">';
171 print
'<table class="noborder centpercent">';
172 for ($i = 1; $i <= 12; $i++) {
173 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
174 if ($j > 12) $j -= 12;
175 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
177 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
179 $sql =
"SELECT COUNT(b.rowid) as detail,";
180 for ($i = 1; $i <= 12; $i++) {
181 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
182 if ($j > 12) $j -= 12;
183 $sql .=
" SUM(".$db->ifsql(
'MONTH(b.doc_date)='.$j,
'1',
'0').
") AS month".str_pad($j, 2,
'0', STR_PAD_LEFT).
",";
185 $sql .=
" COUNT(b.rowid) as total";
186 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b";
187 $sql .=
" WHERE b.doc_date >= '".$db->idate($search_date_start).
"'";
188 $sql .=
" AND b.doc_date <= '".$db->idate($search_date_end).
"'";
189 $sql .=
" AND b.entity IN (".getEntity(
'bookkeeping', 0).
")";
190 $sql .=
" AND date_validated IS NULL";
192 dol_syslog(
'htdocs/accountancy/closure/index.php sql='.$sql, LOG_DEBUG);
193 $resql = $db->query($sql);
195 $num = $db->num_rows(
$resql);
197 while ($row = $db->fetch_row(
$resql)) {
198 print
'<tr class="oddeven">';
199 for ($i = 1; $i <= 12; $i++) {
200 print
'<td class="right">'.$row[$i].
'</td>';
202 print
'<td class="right"><b>'.$row[13].
'</b></td>';
208 print $db->lasterror();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
dol_now($mode= 'auto')
Return date for now.
Class to manage Ledger (General Ledger and Subledger)
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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 Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.