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.
'/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');
43 if ($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'));
59 $parameters = array();
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);
64 if (empty($date_startmonth) || empty($date_endmonth)) {
67 $date_start = $dates[
'date_start'];
68 $date_end = $dates[
'date_end'];
69 $pastmonthyear = $dates[
'pastmonthyear'];
70 $pastmonth = $dates[
'pastmonth'];
73 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
79 if ($action ==
'writebookkeeping') $data_type =
'bookkeeping';
80 if ($action ==
'exportcsv') $data_type =
'csv';
81 $journal_data = $object->getData($user, $data_type, $date_start, $date_end, $in_bookkeeping);
82 if (!is_array($journal_data)) {
90 if ($user->socid > 0) {
93 if (empty($user->rights->accounting->mouvements->lire)) {
102 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
107 if ($action ==
'writebookkeeping') {
110 $result = $object->writeIntoBookkeeping($user, $journal_data);
113 $error = abs($result);
116 $nb_elements = count($journal_data);
117 if (empty($error) && $nb_elements > 0) {
119 } elseif ($nb_elements == $error) {
122 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
126 } elseif ($action ==
'exportcsv') {
128 $result = $object->exportCsv($journal_data, $date_end);
133 $filename =
'journal';
134 $type_export =
'journal';
136 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
137 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
148 $param =
'id_journal=' . $id_journal;
149 $param .=
'&date_startday=' . $date_startday;
150 $param .=
'&date_startmonth=' . $date_startmonth;
151 $param .=
'&date_startyear=' . $date_startyear;
152 $param .=
'&date_endday=' . $date_endday;
153 $param .=
'&date_endmonth=' . $date_endmonth;
154 $param .=
'&date_endyear=' . $date_endyear;
155 $param .=
'&in_bookkeeping=' . $in_bookkeeping;
156 header(
"Location: " . $_SERVER[
'PHP_SELF'] . ($param ?
'?' . $param :
''));
167 if ($object->nature == 2) {
168 $some_mandatory_steps_of_setup_were_not_done = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1';
169 $account_accounting_not_defined = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1';
170 } elseif ($object->nature == 3) {
171 $some_mandatory_steps_of_setup_were_not_done = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1';
172 $account_accounting_not_defined = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1';
173 } elseif ($object->nature == 4) {
174 $some_mandatory_steps_of_setup_were_not_done = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
175 || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1'
176 || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1';
177 $account_accounting_not_defined = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
178 || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1';
179 } elseif ($object->nature == 5) {
180 $some_mandatory_steps_of_setup_were_not_done = empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1';
181 $account_accounting_not_defined = empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1';
183 $title = $object->getLibType();
184 $some_mandatory_steps_of_setup_were_not_done =
false;
185 $account_accounting_not_defined =
false;
188 $title = $langs->trans(
"GenerationOfAccountingEntries") .
' - ' . $object->getNomUrl(0, 2, 1,
'', 1);
197 $description = $langs->trans(
"DescJournalOnlyBindedVisible") .
'<br>';
198 if ($object->nature == 2 || $object->nature == 3) {
199 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
200 $description .= $langs->trans(
"DepositsAreNotIncluded");
202 $description .= $langs->trans(
"DepositsAreIncluded");
204 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
205 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
209 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
210 $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);
211 $period .=
' - ' . $langs->trans(
"JournalizationInLedgerStatus") .
' ' .
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
213 $varlink =
'id_journal=' . $id_journal;
215 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
217 if ($object->nature == 4) {
219 $sql =
"SELECT COUNT(rowid) as nb";
220 $sql .=
" FROM " . MAIN_DB_PREFIX .
"bank_account";
221 $sql .=
" WHERE entity = " . (int) $conf->entity;
222 $sql .=
" AND fk_accountancy_journal IS NULL";
223 $sql .=
" AND clos=0";
224 $resql = $db->query($sql);
226 $obj = $db->fetch_object(
$resql);
228 print
'<br>' .
img_warning() .
' ' . $langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
229 print
' : ' . $langs->trans(
"AccountancyAreaDescBank", 9,
'<strong>' . $langs->transnoentitiesnoconv(
"MenuAccountancy") .
'-' . $langs->transnoentitiesnoconv(
"Setup") .
"-" . $langs->transnoentitiesnoconv(
"BankAccounts") .
'</strong>');
235 if ($some_mandatory_steps_of_setup_were_not_done) {
236 print
'<br><div class="warning">' .
img_warning() .
' ' . $langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
237 print
' : ' . $langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>' . $langs->transnoentitiesnoconv(
"MenuAccountancy") .
'-' . $langs->transnoentitiesnoconv(
"Setup") .
"-" . $langs->transnoentitiesnoconv(
"MenuDefaultAccounts") .
'</strong>');
240 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
241 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
242 print
'<input type="button" class="butAction" name="exportcsv" value="' . $langs->trans(
"ExportDraftJournal") .
'" onclick="launch_export();" />';
244 if ($account_accounting_not_defined) {
245 print
'<input type="button" class="butActionRefused classfortooltip" title="' .
dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")) .
'" value="' . $langs->trans(
"WriteBookKeeping") .
'" />';
247 if ($in_bookkeeping ==
'notyet') {
248 print
'<input type="button" class="butAction" name="writebookkeeping" value="' . $langs->trans(
"WriteBookKeeping") .
'" onclick="writebookkeeping();" />';
250 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">' . $langs->trans(
"WriteBookKeeping") .
'</a>';
257 <script type="text/javascript">
258 function launch_export() {
259 $("div.fiche form input[name=\"action\"]").val("exportcsv");
260 $("div.fiche form input[type=\"submit\"]").click();
261 $("div.fiche form input[name=\"action\"]").val("");
263 function writebookkeeping() {
264 console.log("click on writebookkeeping");
265 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
266 $("div.fiche form input[type=\"submit\"]").click();
267 $("div.fiche form input[name=\"action\"]").val("");
271 $object_label = $langs->trans(
"ObjectsRef");
272 if ($object->nature == 2 || $object->nature == 3) $object_label = $langs->trans(
"InvoiceRef");
273 if ($object->nature == 5) $object_label = $langs->trans(
"ExpenseReportRef");
280 print
'<div class="div-table-responsive">';
281 print
'<table class="noborder centpercent">';
282 print
'<tr class="liste_titre">';
283 print
'<td>' . $langs->trans(
"Date") .
'</td>';
284 print
'<td>' . $langs->trans(
"Piece") .
' (' . $object_label .
')</td>';
285 print
'<td>' . $langs->trans(
"AccountAccounting") .
'</td>';
286 print
'<td>' . $langs->trans(
"SubledgerAccount") .
'</td>';
287 print
'<td>' . $langs->trans(
"LabelOperation") .
'</td>';
288 if ($object->nature == 4) print
'<td class="center">' . $langs->trans(
"PaymentMode") .
'</td>';
289 print
'<td class="right">' . $langs->trans(
"AccountingDebit") .
'</td>';
290 print
'<td class="right">' . $langs->trans(
"AccountingCredit") .
'</td>';
293 if (is_array($journal_data) && !empty($journal_data)) {
294 foreach ($journal_data as $element_id => $element) {
295 foreach ($element[
'blocks'] as $lines) {
296 foreach ($lines as $line) {
297 print
'<tr class="oddeven">';
298 print
'<td>' . $line[
'date'] .
'</td>';
299 print
'<td>' . $line[
'piece'] .
'</td>';
300 print
'<td>' . $line[
'account_accounting'] .
'</td>';
301 print
'<td>' . $line[
'subledger_account'] .
'</td>';
302 print
'<td>' . $line[
'label_operation'] .
'</td>';
303 if ($object->nature == 4) print
'<td class="center">' . $line[
'payment_mode'] .
'</td>';
304 print
'<td class="right nowraponall">' . $line[
'debit'] .
'</td>';
305 print
'<td class="right nowraponall">' . $line[
'credit'] .
'</td>';
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 accounts.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.