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 (!$user->hasRight(
'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");
281 print
'<div class="div-table-responsive">';
282 print
'<table class="noborder centpercent">';
283 print
'<tr class="liste_titre">';
284 print
'<td>' . $langs->trans(
"Date") .
'</td>';
285 print
'<td>' . $langs->trans(
"Piece") .
' (' . $object_label .
')</td>';
286 print
'<td>' . $langs->trans(
"AccountAccounting") .
'</td>';
287 print
'<td>' . $langs->trans(
"SubledgerAccount") .
'</td>';
288 print
'<td>' . $langs->trans(
"LabelOperation") .
'</td>';
289 if ($object->nature == 4) print
'<td class="center">' . $langs->trans(
"PaymentMode") .
'</td>';
290 print
'<td class="right">' . $langs->trans(
"AccountingDebit") .
'</td>';
291 print
'<td class="right">' . $langs->trans(
"AccountingCredit") .
'</td>';
294 if (is_array($journal_data) && !empty($journal_data)) {
295 foreach ($journal_data as $element_id => $element) {
296 foreach ($element[
'blocks'] as $lines) {
297 foreach ($lines as $line) {
298 print
'<tr class="oddeven">';
299 print
'<td>' . $line[
'date'] .
'</td>';
300 print
'<td>' . $line[
'piece'] .
'</td>';
301 print
'<td>' . $line[
'account_accounting'] .
'</td>';
302 print
'<td>' . $line[
'subledger_account'] .
'</td>';
303 print
'<td>' . $line[
'label_operation'] .
'</td>';
304 if ($object->nature == 4) print
'<td class="center">' . $line[
'payment_mode'] .
'</td>';
305 print
'<td class="right nowraponall">' . $line[
'debit'] .
'</td>';
306 print
'<td class="right nowraponall">' . $line[
'credit'] .
'</td>';
317 if ($object->nature == 4) {
320 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';