27 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
41 $langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy",
"productbatch",
"products"));
43 $optioncss =
GETPOST(
'optioncss',
'aZ');
45 $account_parent =
GETPOST(
'account_parent');
46 $changeaccount =
GETPOST(
'changeaccount');
48 $search_societe =
GETPOST(
'search_societe',
'alpha');
49 $search_lineid =
GETPOST(
'search_lineid',
'int');
50 $search_ref =
GETPOST(
'search_ref',
'alpha');
51 $search_invoice =
GETPOST(
'search_invoice',
'alpha');
53 $search_label =
GETPOST(
'search_label',
'alpha');
54 $search_desc =
GETPOST(
'search_desc',
'alpha');
55 $search_amount =
GETPOST(
'search_amount',
'alpha');
56 $search_account =
GETPOST(
'search_account',
'alpha');
57 $search_vat =
GETPOST(
'search_vat',
'alpha');
58 $search_date_startday =
GETPOST(
'search_date_startday',
'int');
59 $search_date_startmonth =
GETPOST(
'search_date_startmonth',
'int');
60 $search_date_startyear =
GETPOST(
'search_date_startyear',
'int');
61 $search_date_endday =
GETPOST(
'search_date_endday',
'int');
62 $search_date_endmonth =
GETPOST(
'search_date_endmonth',
'int');
63 $search_date_endyear =
GETPOST(
'search_date_endyear',
'int');
64 $search_date_start =
dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
65 $search_date_end =
dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
66 $search_country =
GETPOST(
'search_country',
'alpha');
67 $search_tvaintra =
GETPOST(
'search_tvaintra',
'alpha');
70 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
71 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
72 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
74 if (empty($page) || $page < 0) {
77 $offset = $limit * $page;
78 $pageprev = $page - 1;
79 $pagenext = $page + 1;
81 $sortfield =
"f.datef, f.ref, l.rowid";
84 if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
97 if ($user->socid > 0) {
100 if (!$user->hasRight(
'accounting',
'mouvements',
'lire')) {
113 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
114 $search_societe =
'';
117 $search_invoice =
'';
122 $search_account =
'';
124 $search_date_startday =
'';
125 $search_date_startmonth =
'';
126 $search_date_startyear =
'';
127 $search_date_endday =
'';
128 $search_date_endmonth =
'';
129 $search_date_endyear =
'';
130 $search_date_start =
'';
131 $search_date_end =
'';
132 $search_country =
'';
133 $search_tvaintra =
'';
136 if (is_array($changeaccount) && count($changeaccount) > 0 && $user->hasRight(
'accounting',
'bind',
'write')) {
139 if (!(
GETPOST(
'account_parent',
'int') >= 0)) {
141 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Account")),
null,
'errors');
147 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det";
148 $sql1 .=
" SET fk_code_ventilation=".(GETPOST(
'account_parent',
'int') > 0 ?
GETPOST(
'account_parent',
'int') :
'0');
149 $sql1 .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $changeaccount)).
')';
151 dol_syslog(
'accountancy/supplier/lines.php::changeaccount sql= '.$sql1);
152 $resql1 = $db->query($sql1);
165 $account_parent =
'';
169 if (
GETPOST(
'sortfield') ==
'f.datef, f.ref, l.rowid') {
170 $value = (
GETPOST(
'sortorder') ==
'asc,asc,asc' ? 0 : 1);
171 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
172 $res =
dolibarr_set_const($db,
"ACCOUNTING_LIST_SORT_VENTILATION_DONE", $value,
'yesno', 0,
'', $conf->entity);
183 llxHeader(
'', $langs->trans(
"SuppliersVentilation").
' - '.$langs->trans(
"Dispatched"));
185 print
'<script type="text/javascript">
187 $(\'#select-all\').click(function(event) {
188 // Iterate each checkbox
189 $(\':checkbox\').each(function() {
193 $(\'#unselect-all\').click(function(event) {
194 // Iterate each checkbox
195 $(\':checkbox\').each(function() {
196 this.checked = false;
205 $sql =
"SELECT f.rowid as facid, f.ref as ref, f.ref_supplier, f.type as ftype, f.libelle as invoice_label, f.datef, f.fk_soc,";
206 $sql .=
" l.rowid, l.fk_product, l.product_type as line_type, l.description, l.total_ht , l.qty, l.tva_tx, l.vat_src_code,";
207 $sql .=
" aa.rowid as fk_compte, aa.label as label_account, aa.labelshort as labelshort_account, aa.account_number,";
208 $sql .=
" p.rowid as product_id, p.fk_product_type as product_type, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tobuy, p.tosell,";
209 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
210 $sql .=
" ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
212 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
214 $sql .=
" co.code as country_code, co.label as country,";
215 $sql .=
" s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
216 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
217 $sql .=
", spe.accountancy_code_customer as code_compta_client";
218 $sql .=
", spe.accountancy_code_supplier as code_compta_fournisseur";
220 $sql .=
", s.code_compta as code_compta_client";
221 $sql .=
", s.code_compta_fournisseur";
223 $parameters = array();
224 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
225 $sql .= $hookmanager->resPrint;
226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as l";
227 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = l.fk_product";
228 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
229 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
231 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = l.fk_code_ventilation";
232 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON f.rowid = l.fk_facture_fourn";
233 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
234 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
235 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
237 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
238 $sql .=
" WHERE f.rowid = l.fk_facture_fourn and f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 ";
240 if ($search_societe) {
243 if ($search_lineid) {
246 if (strlen(trim($search_invoice))) {
252 if (strlen(trim($search_label))) {
255 if (strlen(trim($search_ref))) {
258 if (strlen(trim($search_desc))) {
261 if (strlen(trim($search_amount))) {
264 if (strlen(trim($search_account))) {
267 if (strlen(trim($search_vat))) {
270 if ($search_date_start) {
271 $sql .=
" AND f.datef >= '".$db->idate($search_date_start).
"'";
273 if ($search_date_end) {
274 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
276 if (strlen(trim($search_country))) {
278 $country_code_in_EEC = $country_code_in_EEC_without_me =
'';
279 foreach ($arrayofcode as $key => $value) {
280 $country_code_in_EEC .= ($country_code_in_EEC ?
"," :
"").
"'".$value.
"'";
281 if ($value != $mysoc->country_code) {
282 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ?
"," :
"").
"'".$value.
"'";
285 if ($search_country ==
'special_allnotme') {
286 $sql .=
" AND co.code <> '".$db->escape($mysoc->country_code).
"'";
287 } elseif ($search_country ==
'special_eec') {
288 $sql .=
" AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).
")";
289 } elseif ($search_country ==
'special_eecnotme') {
290 $sql .=
" AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).
")";
291 } elseif ($search_country ==
'special_noteec') {
292 $sql .=
" AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).
")";
297 if (strlen(trim($search_tvaintra))) {
300 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn', 0).
")";
303 $parameters = array();
304 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
305 $sql .= $hookmanager->resPrint;
307 $sql .= $db->order($sortfield, $sortorder);
310 $nbtotalofrecords =
'';
312 $result = $db->query(
$sql);
313 $nbtotalofrecords = $db->num_rows($result);
314 if (($page * $limit) > $nbtotalofrecords) {
320 $sql .= $db->plimit($limit + 1, $offset);
322 dol_syslog(
"accountancy/supplier/lines.php", LOG_DEBUG);
323 $result = $db->query(
$sql);
325 $num_lines = $db->num_rows($result);
329 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
330 $param .=
'&contextpage='.urlencode($contextpage);
332 if ($limit > 0 && $limit != $conf->liste_limit) {
333 $param .=
'&limit='.((int) $limit);
335 if ($search_societe) {
336 $param .=
"&search_societe=".urlencode($search_societe);
338 if ($search_invoice) {
339 $param .=
"&search_invoice=".urlencode($search_invoice);
342 $param .=
"&search_ref=".urlencode($search_ref);
348 $param .=
"&search_label=".urlencode($search_label);
351 $param .=
"&search_desc=".urlencode($search_desc);
353 if ($search_account) {
354 $param .=
"&search_account=".urlencode($search_account);
357 $param .=
"&search_vat=".urlencode($search_vat);
359 if ($search_date_startday) {
360 $param .=
'&search_date_startday='.urlencode($search_date_startday);
362 if ($search_date_startmonth) {
363 $param .=
'&search_date_startmonth='.urlencode($search_date_startmonth);
365 if ($search_date_startyear) {
366 $param .=
'&search_date_startyear='.urlencode($search_date_startyear);
368 if ($search_date_endday) {
369 $param .=
'&search_date_endday='.urlencode($search_date_endday);
371 if ($search_date_endmonth) {
372 $param .=
'&search_date_endmonth='.urlencode($search_date_endmonth);
374 if ($search_date_endyear) {
375 $param .=
'&search_date_endyear='.urlencode($search_date_endyear);
377 if ($search_country) {
378 $param .=
"&search_country=".urlencode($search_country);
380 if ($search_tvaintra) {
381 $param .=
"&search_tvaintra=".urlencode($search_tvaintra);
384 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
385 print
'<input type="hidden" name="action" value="ventil">';
386 if ($optioncss !=
'') {
387 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
389 print
'<input type="hidden" name="token" value="'.newToken().
'">';
390 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
391 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
392 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
393 print
'<input type="hidden" name="page" value="'.$page.
'">';
395 print_barre_liste($langs->trans(
"InvoiceLinesDone"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num_lines, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
396 print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilDoneSupplier").
'</span><br>';
398 print
'<br><div class="inline-block divButAction paddingbottom">'.$langs->trans(
"ChangeAccount").
' ';
399 print $formaccounting->select_account($account_parent,
'account_parent', 2, array(), 0, 0,
'maxwidth300 maxwidthonsmartphone valignmiddle');
400 print
'<input type="submit" class="button small valignmiddle" value="'.$langs->trans(
"ChangeBinding").
'"/></div>';
404 print
'<div class="div-table-responsive">';
405 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
408 print
'<tr class="liste_titre_filter">';
409 print
'<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).
'"></td>';
410 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).
'"></td>';
412 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
413 print
'<td class="liste_titre center">';
414 print
'<div class="nowrap">';
415 print
$form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
417 print
'<div class="nowrap">';
418 print
$form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
421 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
422 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
423 print
'<td class="liste_titre right"><input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
424 print
'<td class="liste_titre right"><input type="text" class="right flat maxwidth50" name="search_vat" placeholder="%" size="1" value="'.dol_escape_htmltag($search_vat).
'"></td>';
425 print
'<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'"></td>';
426 print
'<td class="liste_titre">';
427 print
$form->select_country($search_country,
'search_country',
'', 0,
'maxwidth100',
'code2', 1, 0, 1);
430 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).
'"></td>';
431 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="'.dol_escape_htmltag($search_account).
'"></td>';
432 print
'<td class="liste_titre center">';
433 $searchpicto =
$form->showFilterButtons();
435 print
"</td></tr>\n";
437 print
'<tr class="liste_titre">';
441 print_liste_field_titre(
"InvoiceLabel", $_SERVER[
"PHP_SELF"],
"f.libelle",
"", $param,
'', $sortfield, $sortorder);
442 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"f.datef, f.ref, l.rowid",
"", $param,
'', $sortfield, $sortorder,
'center ');
445 print_liste_field_titre(
"ProductDescription", $_SERVER[
"PHP_SELF"],
"l.description",
"", $param,
'', $sortfield, $sortorder);
446 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"l.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right ');
447 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"l.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
450 print_liste_field_titre(
"VATIntraShort", $_SERVER[
"PHP_SELF"],
"s.tva_intra",
"", $param,
'', $sortfield, $sortorder);
451 print_liste_field_titre(
"AccountAccounting", $_SERVER[
"PHP_SELF"],
"aa.account_number",
"", $param,
'', $sortfield, $sortorder);
452 $checkpicto =
$form->showCheckAddButtons();
456 $thirdpartystatic =
new Societe($db);
462 while ($i < min($num_lines, $limit)) {
463 $objp = $db->fetch_object($result);
465 $facturefournisseur_static->ref = $objp->ref;
466 $facturefournisseur_static->id = $objp->facid;
467 $facturefournisseur_static->type = $objp->ftype;
468 $facturefournisseur_static->ref_supplier = $objp->ref_supplier;
469 $facturefournisseur_static->label = $objp->invoice_label;
471 $thirdpartystatic->id = $objp->socid;
472 $thirdpartystatic->name = $objp->name;
473 $thirdpartystatic->client = $objp->client;
474 $thirdpartystatic->fournisseur = $objp->fournisseur;
475 $thirdpartystatic->code_client = $objp->code_client;
476 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
477 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
478 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
479 $thirdpartystatic->email = $objp->email;
480 $thirdpartystatic->country_code = $objp->country_code;
482 $productstatic->ref = $objp->product_ref;
483 $productstatic->id = $objp->product_id;
484 $productstatic->label = $objp->product_label;
485 $productstatic->type = $objp->line_type;
486 $productstatic->status = $objp->tosell;
487 $productstatic->status_buy = $objp->tobuy;
488 $productstatic->accountancy_code_buy = $objp->accountancy_code_buy;
489 $productstatic->accountancy_code_buy_intra = $objp->accountancy_code_buy_intra;
490 $productstatic->accountancy_code_buy_export = $objp->accountancy_code_buy_export;
492 $accountingaccountstatic->rowid = $objp->fk_compte;
493 $accountingaccountstatic->label = $objp->label_account;
494 $accountingaccountstatic->labelshort = $objp->labelshort_account;
495 $accountingaccountstatic->account_number = $objp->account_number;
497 print
'<tr class="oddeven">';
500 print
'<td>'.$objp->rowid.
'</td>';
503 print
'<td class="nowraponall">'.$facturefournisseur_static->getNomUrl(1);
504 if ($objp->ref_supplier) {
505 print
'<br><span class="opacitymedium small">'.dol_escape_htmltag($objp->ref_supplier).
'</span>';
517 print
'<td class="tdoverflowonsmartphone small" title="'.dol_escape_htmltag($objp->invoice_label).
'">';
518 print $objp->invoice_label;
522 print
'<td class="center">'.dol_print_date($db->jdate($objp->datef),
'day').
'</td>';
525 print
'<td class="tdoverflowmax100">';
526 if ($productstatic->id > 0) {
527 print $productstatic->getNomUrl(1);
529 if ($productstatic->id > 0 && $objp->product_label) {
532 if ($objp->product_label) {
533 print
'<span class="opacitymedium">'.$objp->product_label.
'</span>';
537 print
'<td class="tdoverflowonsmartphone small">';
539 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
540 print
$form->textwithtooltip(
dol_trunc($text, $trunclength), $objp->description);
543 print
'<td class="right nowraponall amount">'.price($objp->total_ht).
'</td>';
545 print
'<td class="right">'.vatrate($objp->tva_tx.($objp->vat_src_code ?
' ('.$objp->vat_src_code.
')' :
'')).
'</td>';
548 print
'<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1,
'supplier').
'</td>';
552 if ($objp->country_code) {
553 print $langs->trans(
"Country".$objp->country_code).
' ('.$objp->country_code.
')';
557 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).
'">'.
dol_escape_htmltag($objp->tva_intra).
'</td>';
560 print $accountingaccountstatic->getNomUrl(0, 1, 1,
'', 1);
561 print
' <a class="editfielda" href="./card.php?id='.$objp->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].($param ?
'?'.$param :
'')).
'">';
564 print
'<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="'.$objp->rowid.
'"/></td>';
569 if ($num_lines == 0) {
570 print
'<tr><td colspan="13"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
576 if ($nbtotalofrecords > $limit) {
577 print_barre_liste(
'', $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num_lines, $nbtotalofrecords,
'', 0,
'',
'', $limit, 1);
582 print $db->lasterror();