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) {
95 if ($user->socid > 0) {
98 if (empty($user->rights->accounting->mouvements->lire)) {
111 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
112 $search_societe =
'';
115 $search_invoice =
'';
120 $search_account =
'';
122 $search_date_startday =
'';
123 $search_date_startmonth =
'';
124 $search_date_startyear =
'';
125 $search_date_endday =
'';
126 $search_date_endmonth =
'';
127 $search_date_endyear =
'';
128 $search_date_start =
'';
129 $search_date_end =
'';
130 $search_country =
'';
131 $search_tvaintra =
'';
134 if (is_array($changeaccount) && count($changeaccount) > 0 && $user->rights->accounting->bind->write) {
137 if (!(
GETPOST(
'account_parent',
'int') >= 0)) {
139 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Account")),
null,
'errors');
145 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det";
146 $sql1 .=
" SET fk_code_ventilation=".(GETPOST(
'account_parent',
'int') > 0 ?
GETPOST(
'account_parent',
'int') :
'0');
147 $sql1 .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $changeaccount)).
')';
149 dol_syslog(
'accountancy/supplier/lines.php::changeaccount sql= '.$sql1);
150 $resql1 = $db->query($sql1);
163 $account_parent =
'';
175 llxHeader(
'', $langs->trans(
"SuppliersVentilation").
' - '.$langs->trans(
"Dispatched"));
177 print
'<script type="text/javascript">
179 $(\'#select-all\').click(function(event) {
180 // Iterate each checkbox
181 $(\':checkbox\').each(function() {
185 $(\'#unselect-all\').click(function(event) {
186 // Iterate each checkbox
187 $(\':checkbox\').each(function() {
188 this.checked = false;
197 $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,";
198 $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,";
199 $sql .=
" aa.rowid as fk_compte, aa.label as label_account, aa.labelshort as labelshort_account, aa.account_number,";
200 $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,";
201 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
202 $sql .=
" ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
204 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
206 $sql .=
" co.code as country_code, co.label as country,";
207 $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";
208 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
209 $sql .=
", spe.accountancy_code_customer as code_compta_client";
210 $sql .=
", spe.accountancy_code_supplier as code_compta_fournisseur";
212 $sql .=
", s.code_compta as code_compta_client";
213 $sql .=
", s.code_compta_fournisseur";
215 $parameters = array();
216 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
217 $sql .= $hookmanager->resPrint;
218 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as l";
219 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = l.fk_product";
220 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
221 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
223 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = l.fk_code_ventilation";
224 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON f.rowid = l.fk_facture_fourn";
225 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
226 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
227 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
229 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
230 $sql .=
" WHERE f.rowid = l.fk_facture_fourn and f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 ";
232 if ($search_societe) {
235 if ($search_lineid) {
238 if (strlen(trim($search_invoice))) {
239 $sql .=
natural_search(array(
"f.ref",
"f.ref_supplier"), $search_invoice);
244 if (strlen(trim($search_label))) {
247 if (strlen(trim($search_ref))) {
250 if (strlen(trim($search_desc))) {
253 if (strlen(trim($search_amount))) {
256 if (strlen(trim($search_account))) {
259 if (strlen(trim($search_vat))) {
262 if ($search_date_start) {
263 $sql .=
" AND f.datef >= '".$db->idate($search_date_start).
"'";
265 if ($search_date_end) {
266 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
268 if (strlen(trim($search_country))) {
270 $country_code_in_EEC = $country_code_in_EEC_without_me =
'';
271 foreach ($arrayofcode as $key => $value) {
272 $country_code_in_EEC .= ($country_code_in_EEC ?
"," :
"").
"'".$value.
"'";
273 if ($value != $mysoc->country_code) {
274 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ?
"," :
"").
"'".$value.
"'";
277 if ($search_country ==
'special_allnotme') {
278 $sql .=
" AND co.code <> '".$db->escape($mysoc->country_code).
"'";
279 } elseif ($search_country ==
'special_eec') {
280 $sql .=
" AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).
")";
281 } elseif ($search_country ==
'special_eecnotme') {
282 $sql .=
" AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).
")";
283 } elseif ($search_country ==
'special_noteec') {
284 $sql .=
" AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).
")";
289 if (strlen(trim($search_tvaintra))) {
292 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn', 0).
")";
295 $parameters = array();
296 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
297 $sql .= $hookmanager->resPrint;
299 $sql .= $db->order($sortfield, $sortorder);
303 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
304 $result = $db->query($sql);
312 $sql .= $db->plimit($limit + 1, $offset);
314 dol_syslog(
"accountancy/supplier/lines.php", LOG_DEBUG);
315 $result = $db->query($sql);
317 $num_lines = $db->num_rows($result);
321 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
322 $param .=
'&contextpage='.urlencode($contextpage);
324 if ($limit > 0 && $limit != $conf->liste_limit) {
325 $param .=
'&limit='.urlencode($limit);
327 if ($search_societe) {
328 $param .=
"&search_societe=".urlencode($search_societe);
330 if ($search_invoice) {
331 $param .=
"&search_invoice=".urlencode($search_invoice);
334 $param .=
"&search_ref=".urlencode($search_ref);
340 $param .=
"&search_label=".urlencode($search_label);
343 $param .=
"&search_desc=".urlencode($search_desc);
345 if ($search_account) {
346 $param .=
"&search_account=".urlencode($search_account);
349 $param .=
"&search_vat=".urlencode($search_vat);
351 if ($search_date_startday) {
352 $param .=
'&search_date_startday='.urlencode($search_date_startday);
354 if ($search_date_startmonth) {
355 $param .=
'&search_date_startmonth='.urlencode($search_date_startmonth);
357 if ($search_date_startyear) {
358 $param .=
'&search_date_startyear='.urlencode($search_date_startyear);
360 if ($search_date_endday) {
361 $param .=
'&search_date_endday='.urlencode($search_date_endday);
363 if ($search_date_endmonth) {
364 $param .=
'&search_date_endmonth='.urlencode($search_date_endmonth);
366 if ($search_date_endyear) {
367 $param .=
'&search_date_endyear='.urlencode($search_date_endyear);
369 if ($search_country) {
370 $param .=
"&search_country=".urlencode($search_country);
372 if ($search_tvaintra) {
373 $param .=
"&search_tvaintra=".urlencode($search_tvaintra);
376 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
377 print
'<input type="hidden" name="action" value="ventil">';
378 if ($optioncss !=
'') {
379 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
381 print
'<input type="hidden" name="token" value="'.newToken().
'">';
382 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
383 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
384 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
385 print
'<input type="hidden" name="page" value="'.$page.
'">';
387 print_barre_liste($langs->trans(
"InvoiceLinesDone"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num_lines,
$nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
388 print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilDoneSupplier").
'</span><br>';
390 print
'<br><div class="inline-block divButAction paddingbottom">'.$langs->trans(
"ChangeAccount").
' ';
391 print $formaccounting->select_account($account_parent,
'account_parent', 2, array(), 0, 0,
'maxwidth300 maxwidthonsmartphone valignmiddle');
392 print
'<input type="submit" class="button small valignmiddle" value="'.$langs->trans(
"ChangeBinding").
'"/></div>';
396 print
'<div class="div-table-responsive">';
397 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
400 print
'<tr class="liste_titre_filter">';
401 print
'<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).
'"></td>';
402 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).
'"></td>';
404 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
405 print
'<td class="liste_titre center">';
406 print
'<div class="nowrap">';
407 print
$form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
409 print
'<div class="nowrap">';
410 print
$form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
413 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
414 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
415 print
'<td class="liste_titre right"><input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
416 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>';
417 print
'<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'"></td>';
418 print
'<td class="liste_titre">';
419 print
$form->select_country($search_country,
'search_country',
'', 0,
'maxwidth100',
'code2', 1, 0, 1);
422 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).
'"></td>';
423 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="'.dol_escape_htmltag($search_account).
'"></td>';
424 print
'<td class="liste_titre center">';
425 $searchpicto =
$form->showFilterButtons();
427 print
"</td></tr>\n";
429 print
'<tr class="liste_titre">';
433 print_liste_field_titre(
"InvoiceLabel", $_SERVER[
"PHP_SELF"],
"f.libelle",
"", $param,
'', $sortfield, $sortorder);
434 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"f.datef, f.ref, l.rowid",
"", $param,
'', $sortfield, $sortorder,
'center ');
437 print_liste_field_titre(
"ProductDescription", $_SERVER[
"PHP_SELF"],
"l.description",
"", $param,
'', $sortfield, $sortorder);
438 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"l.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right ');
439 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"l.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
442 print_liste_field_titre(
"VATIntraShort", $_SERVER[
"PHP_SELF"],
"s.tva_intra",
"", $param,
'', $sortfield, $sortorder);
443 print_liste_field_titre(
"AccountAccounting", $_SERVER[
"PHP_SELF"],
"aa.account_number",
"", $param,
'', $sortfield, $sortorder);
444 $checkpicto =
$form->showCheckAddButtons();
448 $thirdpartystatic =
new Societe($db);
454 while ($i < min($num_lines, $limit)) {
455 $objp = $db->fetch_object($result);
457 $facturefournisseur_static->ref = $objp->ref;
458 $facturefournisseur_static->id = $objp->facid;
459 $facturefournisseur_static->type = $objp->ftype;
460 $facturefournisseur_static->ref_supplier = $objp->ref_supplier;
461 $facturefournisseur_static->label = $objp->invoice_label;
463 $thirdpartystatic->id = $objp->socid;
464 $thirdpartystatic->name = $objp->name;
465 $thirdpartystatic->client = $objp->client;
466 $thirdpartystatic->fournisseur = $objp->fournisseur;
467 $thirdpartystatic->code_client = $objp->code_client;
468 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
469 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
470 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
471 $thirdpartystatic->email = $objp->email;
472 $thirdpartystatic->country_code = $objp->country_code;
474 $productstatic->ref = $objp->product_ref;
475 $productstatic->id = $objp->product_id;
476 $productstatic->label = $objp->product_label;
477 $productstatic->type = $objp->line_type;
478 $productstatic->status = $objp->tosell;
479 $productstatic->status_buy = $objp->tobuy;
480 $productstatic->accountancy_code_buy = $objp->accountancy_code_buy;
481 $productstatic->accountancy_code_buy_intra = $objp->accountancy_code_buy_intra;
482 $productstatic->accountancy_code_buy_export = $objp->accountancy_code_buy_export;
484 $accountingaccountstatic->rowid = $objp->fk_compte;
485 $accountingaccountstatic->label = $objp->label_account;
486 $accountingaccountstatic->labelshort = $objp->labelshort_account;
487 $accountingaccountstatic->account_number = $objp->account_number;
489 print
'<tr class="oddeven">';
492 print
'<td>'.$objp->rowid.
'</td>';
495 print
'<td class="nowraponall">'.$facturefournisseur_static->getNomUrl(1);
496 if ($objp->ref_supplier) {
497 print
'<br><span class="opacitymedium small">'.dol_escape_htmltag($objp->ref_supplier).
'</span>';
509 print
'<td class="tdoverflowonsmartphone small" title="'.dol_escape_htmltag($objp->invoice_label).
'">';
510 print $objp->invoice_label;
514 print
'<td class="center">'.dol_print_date($db->jdate($objp->datef),
'day').
'</td>';
517 print
'<td class="tdoverflowmax100">';
518 if ($productstatic->id > 0) {
519 print $productstatic->getNomUrl(1);
521 if ($productstatic->id > 0 && $objp->product_label) {
524 if ($objp->product_label) {
525 print
'<span class="opacitymedium">'.$objp->product_label.
'</span>';
529 print
'<td class="tdoverflowonsmartphone small">';
531 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
532 print
$form->textwithtooltip(
dol_trunc($text, $trunclength), $objp->description);
535 print
'<td class="right nowraponall amount">'.price($objp->total_ht).
'</td>';
537 print
'<td class="right">'.vatrate($objp->tva_tx.($objp->vat_src_code ?
' ('.$objp->vat_src_code.
')' :
'')).
'</td>';
540 print
'<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1,
'supplier').
'</td>';
544 if ($objp->country_code) {
545 print $langs->trans(
"Country".$objp->country_code).
' ('.$objp->country_code.
')';
549 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).
'">'.
dol_escape_htmltag($objp->tva_intra).
'</td>';
552 print $accountingaccountstatic->getNomUrl(0, 1, 1,
'', 1);
553 print
' <a class="editfielda" href="./card.php?id='.$objp->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].($param ?
'?'.$param :
'')).
'">';
556 print
'<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="'.$objp->rowid.
'"/></td>';
561 if ($num_lines == 0) {
562 print
'<tr><td colspan="13"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
569 print_barre_liste(
'', $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num_lines,
$nbtotalofrecords,
'', 0,
'',
'', $limit, 1);
574 print $db->lasterror();