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.
'/accountancy/class/accountingjournal.class.php';
31$langs->loadLangs(array(
"banks",
"accountancy",
"compta",
"other",
"errors"));
33$id_journal =
GETPOST(
'id_journal',
'int');
34$action =
GETPOST(
'action',
'aZ09');
36$date_startmonth =
GETPOST(
'date_startmonth');
37$date_startday =
GETPOST(
'date_startday');
38$date_startyear =
GETPOST(
'date_startyear');
39$date_endmonth =
GETPOST(
'date_endmonth');
40$date_endday =
GETPOST(
'date_endday');
41$date_endyear =
GETPOST(
'date_endyear');
42$in_bookkeeping =
GETPOST(
'in_bookkeeping');
43if ($in_bookkeeping ==
'') {
44 $in_bookkeeping =
'notyet';
49$result = $object->fetch($id_journal);
51 $id_journal = $object->id;
52} elseif ($result < 0) {
54} elseif ($result == 0) {
58$hookmanager->initHooks(array(
'globaljournal', $object->nature.
'journal'));
61$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
62$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
64if (empty($date_startmonth)) {
67 $date_start = $dates[
'date_start'];
68 $pastmonthyear = $dates[
'pastmonthyear'];
69 $pastmonth = $dates[
'pastmonth'];
71if (empty($date_endmonth)) {
74 $date_end = $dates[
'date_end'];
75 $pastmonthyear = $dates[
'pastmonthyear'];
76 $pastmonth = $dates[
'pastmonth'];
79if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
85if ($action ==
'writebookkeeping') {
86 $data_type =
'bookkeeping';
88if ($action ==
'exportcsv') {
91$journal_data = $object->getData($user, $data_type, $date_start, $date_end, $in_bookkeeping);
92if (!is_array($journal_data)) {
97if (!isModEnabled(
'accounting')) {
100if ($user->socid > 0) {
103if (!$user->hasRight(
'accounting',
'mouvements',
'lire')) {
112$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
117if ($action ==
'writebookkeeping') {
120 $result = $object->writeIntoBookkeeping($user, $journal_data);
123 $error = abs($result);
126 $nb_elements = count($journal_data);
127 if (empty($error) && $nb_elements > 0) {
129 } elseif ($nb_elements == $error) {
132 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
136} elseif ($action ==
'exportcsv') {
138 $result = $object->exportCsv($journal_data, $date_end);
143 $filename =
'journal';
144 $type_export =
'journal';
146 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
147 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
158 $param =
'id_journal=' . $id_journal;
159 $param .=
'&date_startday=' . $date_startday;
160 $param .=
'&date_startmonth=' . $date_startmonth;
161 $param .=
'&date_startyear=' . $date_startyear;
162 $param .=
'&date_endday=' . $date_endday;
163 $param .=
'&date_endmonth=' . $date_endmonth;
164 $param .=
'&date_endyear=' . $date_endyear;
165 $param .=
'&in_bookkeeping=' . $in_bookkeeping;
166 header(
"Location: " . $_SERVER[
'PHP_SELF'] . ($param ?
'?' . $param :
''));
175$form =
new Form($db);
177if ($object->nature == 2) {
180} elseif ($object->nature == 3) {
183} elseif ($object->nature == 4) {
189} elseif ($object->nature == 5) {
193 $title = $object->getLibType();
194 $some_mandatory_steps_of_setup_were_not_done =
false;
195 $account_accounting_not_defined =
false;
198$title = $langs->trans(
"GenerationOfAccountingEntries") .
' - ' . $object->getNomUrl(0, 2, 1,
'', 1);
207$description = $langs->trans(
"DescJournalOnlyBindedVisible") .
'<br>';
208if ($object->nature == 2 || $object->nature == 3) {
210 $description .= $langs->trans(
"DepositsAreNotIncluded");
212 $description .= $langs->trans(
"DepositsAreIncluded");
215 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
219$listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
220$period = $form->selectDate($date_start ? $date_start : -1,
'date_start', 0, 0, 0,
'', 1, 0) .
' - ' . $form->selectDate($date_end ? $date_end : -1,
'date_end', 0, 0, 0,
'', 1, 0);
221$period .=
' - ' . $langs->trans(
"JournalizationInLedgerStatus") .
' ' . $form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
223$varlink =
'id_journal=' . $id_journal;
225journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
230 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
231 $resql = $db->query($sql);
233 $obj = $db->fetch_object($resql);
235 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
236 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
237 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
246if ($object->nature == 4) {
248 $sql =
"SELECT COUNT(rowid) as nb";
249 $sql .=
" FROM " . MAIN_DB_PREFIX .
"bank_account";
250 $sql .=
" WHERE entity = " . (int) $conf->entity;
251 $sql .=
" AND fk_accountancy_journal IS NULL";
252 $sql .=
" AND clos=0";
253 $resql = $db->query($sql);
255 $obj = $db->fetch_object($resql);
257 print
'<br>' .
img_warning() .
' ' . $langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
258 print
' : ' . $langs->trans(
"AccountancyAreaDescBank", 9,
'<strong>' . $langs->transnoentitiesnoconv(
"MenuAccountancy") .
'-' . $langs->transnoentitiesnoconv(
"Setup") .
"-" . $langs->transnoentitiesnoconv(
"BankAccounts") .
'</strong>');
266if ($some_mandatory_steps_of_setup_were_not_done) {
267 print
'<br><div class="warning">' .
img_warning() .
' ' . $langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
268 print
' : ' . $langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>' . $langs->transnoentitiesnoconv(
"MenuAccountancy") .
'-' . $langs->transnoentitiesnoconv(
"Setup") .
"-" . $langs->transnoentitiesnoconv(
"MenuDefaultAccounts") .
'</strong>');
271print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
272if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
273 print
'<input type="button" class="butAction" name="exportcsv" value="' . $langs->trans(
"ExportDraftJournal") .
'" onclick="launch_export();" />';
275if ($account_accounting_not_defined) {
276 print
'<input type="button" class="butActionRefused classfortooltip" title="' .
dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")) .
'" value="' . $langs->trans(
"WriteBookKeeping") .
'" />';
278 if ($in_bookkeeping ==
'notyet') {
279 print
'<input type="button" class="butAction" name="writebookkeeping" value="' . $langs->trans(
"WriteBookKeeping") .
'" onclick="writebookkeeping();" />';
281 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">' . $langs->trans(
"WriteBookKeeping") .
'</a>';
288 <script type="text/javascript">
289 function launch_export() {
290 $("div.fiche form input[name=\"action\"]").val("exportcsv");
291 $("div.fiche form input[type=\"submit\"]").click();
292 $("div.fiche form input[name=\"action\"]").val("");
294 function writebookkeeping() {
295 console.log("click on writebookkeeping");
296 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
297 $("div.fiche form input[type=\"submit\"]").click();
298 $("div.fiche form input[name=\"action\"]").val("");
302$object_label = $langs->trans(
"ObjectsRef");
303if ($object->nature == 2 || $object->nature == 3) {
304 $object_label = $langs->trans(
"InvoiceRef");
306if ($object->nature == 5) {
307 $object_label = $langs->trans(
"ExpenseReportRef");
316print
'<div class="div-table-responsive">';
317print
'<table class="noborder centpercent">';
318print
'<tr class="liste_titre">';
319print
'<td>' . $langs->trans(
"Date") .
'</td>';
320print
'<td>' . $langs->trans(
"Piece") .
' (' . $object_label .
')</td>';
321print
'<td>' . $langs->trans(
"AccountAccounting") .
'</td>';
322print
'<td>' . $langs->trans(
"SubledgerAccount") .
'</td>';
323print
'<td>' . $langs->trans(
"LabelOperation") .
'</td>';
324if ($object->nature == 4) {
325 print
'<td class="center">' . $langs->trans(
"PaymentMode") .
'</td>';
327print
'<td class="right">' . $langs->trans(
"AccountingDebit") .
'</td>';
328print
'<td class="right">' . $langs->trans(
"AccountingCredit") .
'</td>';
331if (is_array($journal_data) && !empty($journal_data)) {
332 foreach ($journal_data as $element_id => $element) {
333 foreach ($element[
'blocks'] as $lines) {
334 foreach ($lines as $line) {
335 print
'<tr class="oddeven">';
336 print
'<td>' . $line[
'date'] .
'</td>';
337 print
'<td>' . $line[
'piece'] .
'</td>';
338 print
'<td>' . $line[
'account_accounting'] .
'</td>';
339 print
'<td>' . $line[
'subledger_account'] .
'</td>';
340 print
'<td>' . $line[
'label_operation'] .
'</td>';
341 if ($object->nature == 4) {
342 print
'<td class="center">' . $line[
'payment_mode'] .
'</td>';
344 print
'<td class="right nowraponall">' . $line[
'debit'] .
'</td>';
345 print
'<td class="right nowraponall">' . $line[
'credit'] .
'</td>';
356 if ($object->nature == 4) {
359 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a page used to transfer/dispatch data in accounting.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage accounting journals.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
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...
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.