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");
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;
217 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
219 if ($object->nature == 4) {
221 $sql =
"SELECT COUNT(rowid) as nb";
222 $sql .=
" FROM " . MAIN_DB_PREFIX .
"bank_account";
223 $sql .=
" WHERE entity = " . (int) $conf->entity;
224 $sql .=
" AND fk_accountancy_journal IS NULL";
225 $sql .=
" AND clos=0";
226 $resql = $db->query($sql);
228 $obj = $db->fetch_object(
$resql);
230 print
'<br>' .
img_warning() .
' ' . $langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
231 print
' : ' . $langs->trans(
"AccountancyAreaDescBank", 9,
'<strong>' . $langs->transnoentitiesnoconv(
"MenuAccountancy") .
'-' . $langs->transnoentitiesnoconv(
"Setup") .
"-" . $langs->transnoentitiesnoconv(
"BankAccounts") .
'</strong>');
237 if ($some_mandatory_steps_of_setup_were_not_done) {
238 print
'<br><div class="warning">' .
img_warning() .
' ' . $langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
239 print
' : ' . $langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>' . $langs->transnoentitiesnoconv(
"MenuAccountancy") .
'-' . $langs->transnoentitiesnoconv(
"Setup") .
"-" . $langs->transnoentitiesnoconv(
"MenuDefaultAccounts") .
'</strong>');
242 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
243 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
244 print
'<input type="button" class="butAction" name="exportcsv" value="' . $langs->trans(
"ExportDraftJournal") .
'" onclick="launch_export();" />';
246 if ($account_accounting_not_defined) {
247 print
'<input type="button" class="butActionRefused classfortooltip" title="' .
dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")) .
'" value="' . $langs->trans(
"WriteBookKeeping") .
'" />';
249 if ($in_bookkeeping ==
'notyet') {
250 print
'<input type="button" class="butAction" name="writebookkeeping" value="' . $langs->trans(
"WriteBookKeeping") .
'" onclick="writebookkeeping();" />';
252 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">' . $langs->trans(
"WriteBookKeeping") .
'</a>';
259 <script type="text/javascript">
260 function launch_export() {
261 $("div.fiche form input[name=\"action\"]").val("exportcsv");
262 $("div.fiche form input[type=\"submit\"]").click();
263 $("div.fiche form input[name=\"action\"]").val("");
265 function writebookkeeping() {
266 console.log("click on writebookkeeping");
267 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
268 $("div.fiche form input[type=\"submit\"]").click();
269 $("div.fiche form input[name=\"action\"]").val("");
273 $object_label = $langs->trans(
"ObjectsRef");
274 if ($object->nature == 2 || $object->nature == 3) $object_label = $langs->trans(
"InvoiceRef");
275 if ($object->nature == 5) $object_label = $langs->trans(
"ExpenseReportRef");
282 print
'<div class="div-table-responsive">';
283 print
'<table class="noborder centpercent">';
284 print
'<tr class="liste_titre">';
285 print
'<td>' . $langs->trans(
"Date") .
'</td>';
286 print
'<td>' . $langs->trans(
"Piece") .
' (' . $object_label .
')</td>';
287 print
'<td>' . $langs->trans(
"AccountAccounting") .
'</td>';
288 print
'<td>' . $langs->trans(
"SubledgerAccount") .
'</td>';
289 print
'<td>' . $langs->trans(
"LabelOperation") .
'</td>';
290 if ($object->nature == 4) print
'<td class="center">' . $langs->trans(
"PaymentMode") .
'</td>';
291 print
'<td class="right">' . $langs->trans(
"Debit") .
'</td>';
292 print
'<td class="right">' . $langs->trans(
"Credit") .
'</td>';
295 if (is_array($journal_data) && !empty($journal_data)) {
296 foreach ($journal_data as $element_id => $element) {
297 foreach ($element[
'blocks'] as $lines) {
298 foreach ($lines as $line) {
299 print
'<tr class="oddeven">';
300 print
'<td>' . $line[
'date'] .
'</td>';
301 print
'<td>' . $line[
'piece'] .
'</td>';
302 print
'<td>' . $line[
'account_accounting'] .
'</td>';
303 print
'<td>' . $line[
'subledger_account'] .
'</td>';
304 print
'<td>' . $line[
'label_operation'] .
'</td>';
305 if ($object->nature == 4) print
'<td class="center">' . $line[
'payment_mode'] .
'</td>';
306 print
'<td class="right nowraponall">' . $line[
'debit'] .
'</td>';
307 print
'<td class="right nowraponall">' . $line[
'credit'] .
'</td>';