24 require
'../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
30 $langs->loadLangs(array(
"banks",
"accountancy",
"compta",
"other",
"errors"));
32 $id_journal =
GETPOST(
'id_journal',
'int');
33 $action =
GETPOST(
'action',
'aZ09');
35 $date_startmonth =
GETPOST(
'date_startmonth');
36 $date_startday =
GETPOST(
'date_startday');
37 $date_startyear =
GETPOST(
'date_startyear');
38 $date_endmonth =
GETPOST(
'date_endmonth');
39 $date_endday =
GETPOST(
'date_endday');
40 $date_endyear =
GETPOST(
'date_endyear');
41 $in_bookkeeping =
GETPOST(
'in_bookkeeping');
42 if ($in_bookkeeping ==
'') {
43 $in_bookkeeping =
'notyet';
48 $result = $object->fetch($id_journal);
50 $id_journal = $object->id;
51 } elseif ($result < 0) {
53 } elseif ($result == 0) {
57 $hookmanager->initHooks(array(
'globaljournal', $object->nature.
'journal'));
58 $parameters = array();
60 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
61 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
63 if (empty($date_startmonth) || empty($date_endmonth)) {
66 $date_start = $dates[
'date_start'];
67 $date_end = $dates[
'date_end'];
68 $pastmonthyear = $dates[
'pastmonthyear'];
69 $pastmonth = $dates[
'pastmonth'];
72 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
78 if ($action ==
'writebookkeeping') $data_type =
'bookkeeping';
79 if ($action ==
'exportcsv') $data_type =
'csv';
80 $journal_data = $object->getData($user, $data_type, $date_start, $date_end, $in_bookkeeping);
81 if (!is_array($journal_data)) {
89 if ($user->socid > 0) {
92 if (empty($user->rights->accounting->mouvements->lire)) {
101 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
106 if ($action ==
'writebookkeeping') {
109 $result = $object->writeIntoBookkeeping($user, $journal_data);
112 $error = abs($result);
115 $nb_elements = count($journal_data);
116 if (empty($error) && $nb_elements > 0) {
118 } elseif ($nb_elements == $error) {
121 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"), null,
'warnings');
125 } elseif ($action ==
'exportcsv') {
127 $result = $object->exportCsv($journal_data, $date_end);
132 $filename =
'journal';
133 $type_export =
'journal';
135 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
136 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
147 $param =
'id_journal=' . $id_journal;
148 $param .=
'&date_startday=' . $date_startday;
149 $param .=
'&date_startmonth=' . $date_startmonth;
150 $param .=
'&date_startyear=' . $date_startyear;
151 $param .=
'&date_endday=' . $date_endday;
152 $param .=
'&date_endmonth=' . $date_endmonth;
153 $param .=
'&date_endyear=' . $date_endyear;
154 $param .=
'&in_bookkeeping=' . $in_bookkeeping;
155 header(
"Location: " . $_SERVER[
'PHP_SELF'] . ($param ?
'?' . $param :
''));
166 if ($object->nature == 2) {
167 $title = $langs->trans(
"SellsJournal");
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 $title = $langs->trans(
"PurchasesJournal");
172 $some_mandatory_steps_of_setup_were_not_done = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1';
173 $account_accounting_not_defined = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1';
174 } elseif ($object->nature == 4) {
175 $title = $langs->trans(
"FinanceJournal");
176 $some_mandatory_steps_of_setup_were_not_done = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
177 || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1'
178 || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1';
179 $account_accounting_not_defined = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
180 || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"" || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1';
181 } elseif ($object->nature == 5) {
182 $title = $langs->trans(
"ExpenseReportsJournal");
183 $some_mandatory_steps_of_setup_were_not_done = empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1';
184 $account_accounting_not_defined = empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1';
186 $title = $object->getLibType();
187 $some_mandatory_steps_of_setup_were_not_done =
false;
188 $account_accounting_not_defined =
false;
192 $nom = $title .
' | ' . $object->getNomUrl(0, 1, 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");
206 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
207 $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);
208 $period .=
' - ' . $langs->trans(
"JournalizationInLedgerStatus") .
' ' .
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
210 $varlink =
'id_journal=' . $id_journal;
214 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
216 if ($object->nature == 4) {
218 $sql =
"SELECT COUNT(rowid) as nb";
219 $sql .=
" FROM " . MAIN_DB_PREFIX .
"bank_account";
220 $sql .=
" WHERE entity = " . (int) $conf->entity;
221 $sql .=
" AND fk_accountancy_journal IS NULL";
222 $sql .=
" AND clos=0";
223 $resql = $db->query($sql);
225 $obj = $db->fetch_object(
$resql);
227 print
'<br>' .
img_warning() .
' ' . $langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
228 print
' : ' . $langs->trans(
"AccountancyAreaDescBank", 9,
'<strong>' . $langs->transnoentitiesnoconv(
"MenuAccountancy") .
'-' . $langs->transnoentitiesnoconv(
"Setup") .
"-" . $langs->transnoentitiesnoconv(
"BankAccounts") .
'</strong>');
234 if ($some_mandatory_steps_of_setup_were_not_done) {
235 print
'<br><div class="warning">' .
img_warning() .
' ' . $langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
236 print
' : ' . $langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>' . $langs->transnoentitiesnoconv(
"MenuAccountancy") .
'-' . $langs->transnoentitiesnoconv(
"Setup") .
"-" . $langs->transnoentitiesnoconv(
"MenuDefaultAccounts") .
'</strong>');
239 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
240 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
241 print
'<input type="button" class="butAction" name="exportcsv" value="' . $langs->trans(
"ExportDraftJournal") .
'" onclick="launch_export();" />';
243 if ($account_accounting_not_defined) {
244 print
'<input type="button" class="butActionRefused classfortooltip" title="' .
dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")) .
'" value="' . $langs->trans(
"WriteBookKeeping") .
'" />';
246 if ($in_bookkeeping ==
'notyet') {
247 print
'<input type="button" class="butAction" name="writebookkeeping" value="' . $langs->trans(
"WriteBookKeeping") .
'" onclick="writebookkeeping();" />';
249 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">' . $langs->trans(
"WriteBookKeeping") .
'</a>';
256 <script type="text/javascript">
257 function launch_export() {
258 $("div.fiche form input[name=\"action\"]").val("exportcsv");
259 $("div.fiche form input[type=\"submit\"]").click();
260 $("div.fiche form input[name=\"action\"]").val("");
262 function writebookkeeping() {
263 console.log("click on writebookkeeping");
264 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
265 $("div.fiche form input[type=\"submit\"]").click();
266 $("div.fiche form input[name=\"action\"]").val("");
270 $object_label = $langs->trans(
"ObjectsRef");
271 if ($object->nature == 2 || $object->nature == 3) $object_label = $langs->trans(
"InvoiceRef");
272 if ($object->nature == 5) $object_label = $langs->trans(
"ExpenseReportRef");
279 print
'<div class="div-table-responsive">';
280 print
'<table class="noborder centpercent">';
281 print
'<tr class="liste_titre">';
282 print
'<td>' . $langs->trans(
"Date") .
'</td>';
283 print
'<td>' . $langs->trans(
"Piece") .
' (' . $object_label .
')</td>';
284 print
'<td>' . $langs->trans(
"AccountAccounting") .
'</td>';
285 print
'<td>' . $langs->trans(
"SubledgerAccount") .
'</td>';
286 print
'<td>' . $langs->trans(
"LabelOperation") .
'</td>';
287 if ($object->nature == 4) print
'<td class="center">' . $langs->trans(
"PaymentMode") .
'</td>';
288 print
'<td class="right">' . $langs->trans(
"Debit") .
'</td>';
289 print
'<td class="right">' . $langs->trans(
"Credit") .
'</td>';
292 if (is_array($journal_data) && !empty($journal_data)) {
293 foreach ($journal_data as $element_id => $element) {
294 foreach ($element[
'blocks'] as $lines) {
295 foreach ($lines as $line) {
296 print
'<tr class="oddeven">';
297 print
'<td>' . $line[
'date'] .
'</td>';
298 print
'<td>' . $line[
'piece'] .
'</td>';
299 print
'<td>' . $line[
'account_accounting'] .
'</td>';
300 print
'<td>' . $line[
'subledger_account'] .
'</td>';
301 print
'<td>' . $line[
'label_operation'] .
'</td>';
302 if ($object->nature == 4) print
'<td class="center">' . $line[
'payment_mode'] .
'</td>';
303 print
'<td class="right nowraponall">' . $line[
'debit'] .
'</td>';
304 print
'<td class="right nowraponall">' . $line[
'credit'] .
'</td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a page used to transfer/dispatch data in accounting.
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...
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
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 ...
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.
Class to manage accounting accounts.