33 require
'../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
44 $langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"errors"));
46 $id_journal =
GETPOST(
'id_journal',
'int');
47 $action =
GETPOST(
'action',
'aZ09');
49 $date_startmonth =
GETPOST(
'date_startmonth');
50 $date_startday =
GETPOST(
'date_startday');
51 $date_startyear =
GETPOST(
'date_startyear');
52 $date_endmonth =
GETPOST(
'date_endmonth');
53 $date_endday =
GETPOST(
'date_endday');
54 $date_endyear =
GETPOST(
'date_endyear');
55 $in_bookkeeping =
GETPOST(
'in_bookkeeping');
56 if ($in_bookkeeping ==
'') $in_bookkeeping =
'notyet';
64 $hookmanager->initHooks(array(
'sellsjournal'));
65 $parameters = array();
71 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
77 $accountingjournalstatic->fetch($id_journal);
78 $journal = $accountingjournalstatic->code;
79 $journal_label = $accountingjournalstatic->label;
81 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
82 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
84 if (empty($date_startmonth) || empty($date_endmonth))
88 $date_start = $dates[
'date_start'];
89 $date_end = $dates[
'date_end'];
90 $pastmonthyear = $dates[
'pastmonthyear'];
91 $pastmonth = $dates[
'pastmonth'];
94 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end)))
100 $sql =
"SELECT f.rowid, f.ref, f.type, f.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code,";
101 $sql .=
" fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code,";
102 $sql .=
" s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
103 $sql .=
" p.rowid as pid, p.ref as pref, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
104 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
105 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
106 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
107 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
108 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
109 $sql .=
" WHERE fd.fk_code_ventilation > 0";
110 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
')';
111 $sql .=
" AND f.fk_statut > 0";
112 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
117 $sql .=
" AND fd.product_type IN (0,1)";
118 if ($date_start && $date_end)
119 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
121 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
122 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
125 if ($in_bookkeeping ==
'already')
127 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
130 if ($in_bookkeeping ==
'notyet')
132 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
135 $sql .=
" ORDER BY f.datef";
138 dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
139 $result = $db->query($sql);
146 $tablocaltax1 = array();
147 $tablocaltax2 = array();
148 $tabcompany = array();
150 $num = $db->num_rows($result);
153 $cptcli = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER !=
"")) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER :
'NotDefined';
154 $cpttva = (!empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT :
'NotDefined';
158 $obj = $db->fetch_object($result);
161 $compta_soc = (!empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
163 $compta_prod = $obj->compte;
164 if (empty($compta_prod)) {
165 if ($obj->product_type == 0)
166 $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT :
'NotDefined';
168 $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT :
'NotDefined';
172 $vatdata =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), $mysoc, $mysoc, 0);
173 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
174 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
175 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
178 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code))
180 $def_tva[$obj->rowid][$compta_tva][
vatrate($obj->tva_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
'')] = (
vatrate($obj->tva_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''));
184 $line->fetch($obj->fdid);
187 $prev_progress = $line->get_prev_progress($obj->rowid);
191 if ($obj->situation_percent == 0) {
192 $situation_ratio = 0;
194 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
197 $situation_ratio = 1;
201 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
202 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
203 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
204 $tabfac[$obj->rowid][
"type"] = $obj->type;
205 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
206 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
210 if (!isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc] = 0;
211 if (!isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod] = 0;
212 if (!isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0;
213 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
214 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
216 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
217 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
218 if (empty($line->tva_npr)) $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
219 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
220 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
221 $tabcompany[$obj->rowid] = array(
223 'name' => $obj->name,
224 'code_client' => $obj->code_client,
225 'code_compta' => $compta_soc
234 $errorforinvoice = array();
237 foreach ($tabfac as $key => $val) {
238 $sql =
"SELECT COUNT(fd.rowid) as nb";
239 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
240 $sql .=
" WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
241 $sql .=
" AND fd.total_ttc <> 0 AND fk_facture = ".$key;
242 $resql = $db->query($sql);
245 $obj = $db->fetch_object(
$resql);
248 $errorforinvoice[$key] =
'somelinesarenotbound';
256 if ($action ==
'writebookkeeping') {
260 $companystatic =
new Societe($db);
261 $invoicestatic =
new Facture($db);
263 foreach ($tabfac as $key => $val) {
271 $companystatic->id = $tabcompany[$key][
'id'];
272 $companystatic->name = $tabcompany[$key][
'name'];
273 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
274 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
275 $companystatic->code_client = $tabcompany[$key][
'code_client'];
276 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
277 $companystatic->client = 3;
279 $invoicestatic->id = $key;
280 $invoicestatic->ref = (string) $val[
"ref"];
281 $invoicestatic->type = $val[
"type"];
282 $invoicestatic->close_code = $val[
"close_code"];
287 $replacedinvoice = 0;
288 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED)
290 $replacedinvoice = 1;
291 $alreadydispatched = $invoicestatic->getVentilExportCompta();
292 if ($alreadydispatched) $replacedinvoice = 2;
296 if ($replacedinvoice == 1)
303 if ($errorforinvoice[$key] ==
'somelinesarenotbound')
307 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']), null,
'errors');
313 foreach ($tabttc[$key] as $k => $mt) {
315 $bookkeeping->doc_date = $val[
"date"];
316 $bookkeeping->date_lim_reglement = $val[
"datereg"];
317 $bookkeeping->doc_ref = $val[
"ref"];
318 $bookkeeping->date_creation = $now;
319 $bookkeeping->doc_type =
'customer_invoice';
320 $bookkeeping->fk_doc = $key;
321 $bookkeeping->fk_docdet = 0;
322 $bookkeeping->thirdparty_code = $companystatic->code_client;
323 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
324 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
325 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
327 $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER,
true);
328 $bookkeeping->label_compte = $accountingaccount->label;
330 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount");
331 $bookkeeping->montant = $mt;
332 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
333 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
334 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
335 $bookkeeping->code_journal = $journal;
336 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
337 $bookkeeping->fk_user_author = $user->id;
338 $bookkeeping->entity = $conf->entity;
340 $totaldebit += $bookkeeping->debit;
341 $totalcredit += $bookkeeping->credit;
343 $result = $bookkeeping->create($user);
345 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists')
349 $errorforinvoice[$key] =
'alreadyjournalized';
354 $errorforinvoice[$key] =
'other';
364 foreach ($tabht[$key] as $k => $mt) {
366 if ($accountingaccount->fetch(null, $k,
true)) {
368 $bookkeeping->doc_date = $val[
"date"];
369 $bookkeeping->date_lim_reglement = $val[
"datereg"];
370 $bookkeeping->doc_ref = $val[
"ref"];
371 $bookkeeping->date_creation = $now;
372 $bookkeeping->doc_type =
'customer_invoice';
373 $bookkeeping->fk_doc = $key;
374 $bookkeeping->fk_docdet = 0;
375 $bookkeeping->thirdparty_code = $companystatic->code_client;
376 $bookkeeping->subledger_account =
'';
377 $bookkeeping->subledger_label =
'';
378 $bookkeeping->numero_compte = $k;
379 $bookkeeping->label_compte = $accountingaccount->label;
380 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$accountingaccount->label;
381 $bookkeeping->montant = $mt;
382 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
383 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
384 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
385 $bookkeeping->code_journal = $journal;
386 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
387 $bookkeeping->fk_user_author = $user->id;
388 $bookkeeping->entity = $conf->entity;
390 $totaldebit += $bookkeeping->debit;
391 $totalcredit += $bookkeeping->credit;
393 $result = $bookkeeping->create($user);
395 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists')
399 $errorforinvoice[$key] =
'alreadyjournalized';
404 $errorforinvoice[$key] =
'other';
415 $listoftax = array(0, 1, 2);
416 foreach ($listoftax as $numtax)
418 $arrayofvat = $tabtva;
419 if ($numtax == 1) $arrayofvat = $tablocaltax1;
420 if ($numtax == 2) $arrayofvat = $tablocaltax2;
422 foreach ($arrayofvat[$key] as $k => $mt) {
425 $bookkeeping->doc_date = $val[
"date"];
426 $bookkeeping->date_lim_reglement = $val[
"datereg"];
427 $bookkeeping->doc_ref = $val[
"ref"];
428 $bookkeeping->date_creation = $now;
429 $bookkeeping->doc_type =
'customer_invoice';
430 $bookkeeping->fk_doc = $key;
431 $bookkeeping->fk_docdet = 0;
432 $bookkeeping->thirdparty_code = $companystatic->code_client;
433 $bookkeeping->subledger_account =
'';
434 $bookkeeping->subledger_label =
'';
435 $bookkeeping->numero_compte = $k;
437 $accountingaccount->fetch($k, null,
true);
438 $bookkeeping->label_compte = $accountingaccount->label;
440 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
441 $bookkeeping->montant = $mt;
442 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
443 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
444 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
445 $bookkeeping->code_journal = $journal;
446 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
447 $bookkeeping->fk_user_author = $user->id;
448 $bookkeeping->entity = $conf->entity;
450 $totaldebit += $bookkeeping->debit;
451 $totalcredit += $bookkeeping->credit;
453 $result = $bookkeeping->create($user);
455 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists')
459 $errorforinvoice[$key] =
'alreadyjournalized';
464 $errorforinvoice[$key] =
'other';
474 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT')))
478 $errorforinvoice[$key] =
'amountsnotbalanced';
479 setEventMessages(
'Try to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.', null,
'errors');
490 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"), null,
'errors');
498 if (empty($error) && count($tabpay) > 0) {
500 } elseif (count($tabpay) == $error) {
503 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"), null,
'warnings');
509 if (count($tabpay) != $error)
511 $param =
'id_journal='.$id_journal;
512 $param .=
'&date_startday='.$date_startday;
513 $param .=
'&date_startmonth='.$date_startmonth;
514 $param .=
'&date_startyear='.$date_startyear;
515 $param .=
'&date_endday='.$date_endday;
516 $param .=
'&date_endmonth='.$date_endmonth;
517 $param .=
'&date_endyear='.$date_endyear;
518 $param .=
'&in_bookkeeping='.$in_bookkeeping;
519 header(
"Location: ".
$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
530 $form =
new Form($db);
533 if ($action ==
'exportcsv') {
534 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
536 $filename =
'journal';
537 $type_export =
'journal';
538 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
540 $companystatic =
new Client($db);
541 $invoicestatic =
new Facture($db);
543 foreach ($tabfac as $key => $val)
545 $companystatic->id = $tabcompany[$key][
'id'];
546 $companystatic->name = $tabcompany[$key][
'name'];
547 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
548 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
549 $companystatic->code_client = $tabcompany[$key][
'code_client'];
550 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
551 $companystatic->client = 3;
553 $invoicestatic->id = $key;
554 $invoicestatic->ref = (string) $val[
"ref"];
555 $invoicestatic->type = $val[
"type"];
556 $invoicestatic->close_code = $val[
"close_code"];
561 $replacedinvoice = 0;
562 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED)
564 $replacedinvoice = 1;
565 $alreadydispatched = $invoicestatic->getVentilExportCompta();
566 if ($alreadydispatched) $replacedinvoice = 2;
570 if ($replacedinvoice == 1)
576 foreach ($tabttc[$key] as $k => $mt) {
578 print '"'.$key.
'"'.$sep;
579 print '"'.$date.
'"'.$sep;
580 print '"'.$val[
"ref"].
'"'.$sep;
581 print '"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
582 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
583 print '"'.$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER.
'"'.$sep;
584 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
585 print '"'.$langs->trans(
"Thirdparty").
'"'.$sep;
586 print '"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Thirdparty").
'"'.$sep;
587 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
588 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
589 print '"'.$journal.
'"';
595 foreach ($tabht[$key] as $k => $mt) {
597 $accountingaccount->fetch(null, $k,
true);
599 print '"'.$key.
'"'.$sep;
600 print '"'.$date.
'"'.$sep;
601 print '"'.$val[
"ref"].
'"'.$sep;
602 print '"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
603 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
604 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
606 print '"'.utf8_decode(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
607 print '"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.
dol_trunc($accountingaccount->label, 32).
'"'.$sep;
608 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
609 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
610 print '"'.$journal.
'"';
616 $listoftax = array(0, 1, 2);
617 foreach ($listoftax as $numtax) {
618 $arrayofvat = $tabtva;
619 if ($numtax == 1) $arrayofvat = $tablocaltax1;
620 if ($numtax == 2) $arrayofvat = $tablocaltax2;
622 foreach ($arrayofvat[$key] as $k => $mt) {
624 print '"'.$key.
'"'.$sep;
625 print '"'.$date.
'"'.$sep;
626 print '"'.$val[
"ref"].
'"'.$sep;
627 print '"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
628 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
629 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
631 print '"'.$langs->trans(
"VAT").
' - '.join(
', ', $def_tva[$key][$k]).
' %"'.$sep;
632 print '"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'').
'"'.$sep;
633 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
634 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
635 print '"'.$journal.
'"';
645 if (empty($action) || $action ==
'view') {
646 llxHeader(
'', $langs->trans(
"SellsJournal"));
648 $nom = $langs->trans(
"SellsJournal").
' | '.$accountingjournalstatic->getNomUrl(0, 1, 1,
'', 1);
653 $description .= $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
654 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
655 $description .= $langs->trans(
"DepositsAreNotIncluded");
657 $description .= $langs->trans(
"DepositsAreIncluded");
660 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
661 $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);
662 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
664 $varlink =
'id_journal='.$id_journal;
666 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
669 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
671 print img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
672 print ' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>');
674 print '<div class="tabsAction tabsActionNoBottom">';
675 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet')
print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
676 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
677 print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
679 if ($in_bookkeeping ==
'notyet')
print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
680 else print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
686 <script type="text/javascript">
687 function launch_export() {
688 $("div.fiche form input[name=\"action\"]").val("exportcsv");
689 $("div.fiche form input[type=\"submit\"]").click();
690 $("div.fiche form input[name=\"action\"]").val("");
692 function writebookkeeping() {
693 console.log("click on writebookkeeping");
694 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
695 $("div.fiche form input[type=\"submit\"]").click();
696 $("div.fiche form input[name=\"action\"]").val("");
706 print '<div class="div-table-responsive">';
707 print "<table class=\"noborder\" width=\"100%\">";
708 print "<tr class=\"liste_titre\">";
709 print "<td>".$langs->trans(
"Date").
"</td>";
710 print "<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
711 print "<td>".$langs->trans(
"AccountAccounting").
"</td>";
712 print "<td>".$langs->trans(
"SubledgerAccount").
"</td>";
713 print "<td>".$langs->trans(
"LabelOperation").
"</td>";
714 print '<td class="center">'.$langs->trans(
"Debit").
"</td>";
715 print '<td class="center">'.$langs->trans(
"Credit").
"</td>";
720 $companystatic =
new Client($db);
721 $invoicestatic =
new Facture($db);
723 foreach ($tabfac as $key => $val)
725 $companystatic->id = $tabcompany[$key][
'id'];
726 $companystatic->name = $tabcompany[$key][
'name'];
727 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
728 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
729 $companystatic->code_client = $tabcompany[$key][
'code_client'];
730 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
731 $companystatic->client = 3;
733 $invoicestatic->id = $key;
734 $invoicestatic->ref = (string) $val[
"ref"];
735 $invoicestatic->type = $val[
"type"];
736 $invoicestatic->close_code = $val[
"close_code"];
741 $replacedinvoice = 0;
742 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED)
744 $replacedinvoice = 1;
745 $alreadydispatched = $invoicestatic->getVentilExportCompta();
746 if ($alreadydispatched) $replacedinvoice = 2;
750 if ($replacedinvoice == 1)
752 print '<tr class="oddeven">';
753 print "<!-- Replaced invoice -->";
754 print "<td>".$date.
"</td>";
755 print "<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
758 print $langs->trans(
"Replaced");
765 print '<td class="right"></td>';
766 print '<td class="right"></td>';
771 if ($errorforinvoice[$key] ==
'somelinesarenotbound')
773 print '<tr class="oddeven">';
774 print "<!-- Some lines are not bound -->";
775 print "<td>".$date.
"</td>";
776 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
779 print '<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
786 print '<td class="right"></td>';
787 print '<td class="right"></td>';
792 foreach ($tabttc[$key] as $k => $mt)
794 print '<tr class="oddeven">';
795 print "<!-- Thirdparty -->";
796 print "<td>".$date.
"</td>";
797 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
800 $accountoshow =
length_accounta($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
801 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined')
803 print '<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
804 }
else print $accountoshow;
809 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined')
811 print '<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
812 }
else print $accountoshow;
814 print "<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
815 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
816 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
821 foreach ($tabht[$key] as $k => $mt)
824 $accountingaccount->fetch(null, $k,
true);
826 print '<tr class="oddeven">';
827 print "<!-- Product -->";
828 print "<td>".$date.
"</td>";
829 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
833 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined')
835 print '<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
836 }
else print $accountoshow;
841 $companystatic->id = $tabcompany[$key][
'id'];
842 $companystatic->name = $tabcompany[$key][
'name'];
843 print "<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$accountingaccount->label.
"</td>";
844 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
845 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
850 $listoftax = array(0, 1, 2);
851 foreach ($listoftax as $numtax)
853 $arrayofvat = $tabtva;
854 if ($numtax == 1) $arrayofvat = $tablocaltax1;
855 if ($numtax == 2) $arrayofvat = $tablocaltax2;
857 foreach ($arrayofvat[$key] as $k => $mt) {
859 print '<tr class="oddeven">';
860 print "<!-- VAT -->";
861 print "<td>".$date.
"</td>";
862 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
866 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined')
868 print '<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"Sale").
')</span>';
869 }
else print $accountoshow;
874 print "<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
876 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
877 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
Class to manage customers or prospects.
const TYPE_REPLACEMENT
Replacement invoice.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
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.
const TYPE_SITUATION
Situation invoice.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage Ledger (General Ledger and Subledger)
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.
Class to manage third parties objects (customers, suppliers, prospects...)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
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 ...
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
print $_SERVER["PHP_SELF"]
Edit parameters.
const TYPE_DEPOSIT
Deposit invoice.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
Class to manage accounting accounts.
Class to manage accounting accounts.
Class to manage invoices.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
Class to manage invoice lines.