1<?php
2/* Copyright (C) 2013-2016 Olivier Geffroy		<jeff@jeffinfo.com>
3 * Copyright (C) 2013-2021 Alexandre Spangaro	<aspangaro@open-dsi.fr>
4 * Copyright (C) 2014-2015 Ari Elbaz (elarifr)	<github@accedinfo.com>
5 * Copyright (C) 2014-2016 Florian Henry		<florian.henry@open-concept.pro>
6 * Copyright (C) 2014	   Juanjo Menent		<jmenent@2byte.es>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22/**
23 * \file 		htdocs/accountancy/customer/lines.php
24 * \ingroup 	Accountancy (Double entries)
25 * \brief 		Page of detail of the lines of ventilation of invoices customers
26 */
27require '../../main.inc.php';
28
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38
39// Load translation files required by the page
40$langs->loadLangs(array("bills", "compta", "accountancy", "productbatch", "products"));
41
42$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
43
44$account_parent = GETPOST('account_parent');
45$changeaccount = GETPOST('changeaccount');
46// Search Getpost
47$search_societe = GETPOST('search_societe', 'alpha');
48$search_lineid = GETPOST('search_lineid', 'int');
49$search_ref = GETPOST('search_ref', 'alpha');
50$search_invoice = GETPOST('search_invoice', 'alpha');
51$search_label = GETPOST('search_label', 'alpha');
52$search_desc = GETPOST('search_desc', 'alpha');
53$search_amount = GETPOST('search_amount', 'alpha');
54$search_account = GETPOST('search_account', 'alpha');
55$search_vat = GETPOST('search_vat', 'alpha');
56$search_date_startday = GETPOST('search_date_startday', 'int');
57$search_date_startmonth = GETPOST('search_date_startmonth', 'int');
58$search_date_startyear = GETPOST('search_date_startyear', 'int');
59$search_date_endday = GETPOST('search_date_endday', 'int');
60$search_date_endmonth = GETPOST('search_date_endmonth', 'int');
61$search_date_endyear = GETPOST('search_date_endyear', 'int');
62$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);	// Use tzserver
63$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
64$search_country = GETPOST('search_country', 'alpha');
65$search_tvaintra = GETPOST('search_tvaintra', 'alpha');
66
67// Load variable for pagination
68$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
69$sortfield = GETPOST('sortfield', 'aZ09comma');
70$sortorder = GETPOST('sortorder', 'aZ09comma');
71$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
72if (empty($page) || $page < 0) {
73	$page = 0;
74}
75$offset = $limit * $page;
76$pageprev = $page - 1;
77$pagenext = $page + 1;
78if (!$sortfield) {
79	$sortfield = "f.datef, f.ref, fd.rowid";
80}
81if (!$sortorder) {
82	if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
83		$sortorder = "DESC";
84	}
85}
86
87// Security check
88if (empty($conf->accounting->enabled)) {
89	accessforbidden();
90}
91if ($user->socid > 0) {
92	accessforbidden();
93}
94if (empty($user->rights->accounting->mouvements->lire)) {
95	accessforbidden();
96}
97
98
99$formaccounting = new FormAccounting($db);
100
101
102/*
103 * Actions
104 */
105
106// Purge search criteria
107if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
108	$search_societe = '';
109	$search_lineid = '';
110	$search_ref = '';
111	$search_invoice = '';
112	$search_label = '';
113	$search_desc = '';
114	$search_amount = '';
115	$search_account = '';
116	$search_vat = '';
117	$search_date_startday = '';
118	$search_date_startmonth = '';
119	$search_date_startyear = '';
120	$search_date_endday = '';
121	$search_date_endmonth = '';
122	$search_date_endyear = '';
123	$search_date_start = '';
124	$search_date_end = '';
125	$search_country = '';
126	$search_tvaintra = '';
127}
128
129if (is_array($changeaccount) && count($changeaccount) > 0 && $user->rights->accounting->bind->write) {
130	$error = 0;
131
132	if (!(GETPOST('account_parent', 'int') >= 0)) {
133		$error++;
134		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
135	}
136
137	if (!$error) {
138		$db->begin();
139
140		$sql1 = "UPDATE ".MAIN_DB_PREFIX."facturedet as l";
141		$sql1 .= " SET l.fk_code_ventilation=".(GETPOST('account_parent', 'int') > 0 ? GETPOST('account_parent', 'int') : '0');
142		$sql1 .= ' WHERE l.rowid IN ('.$db->sanitize(implode(',', $changeaccount)).')';
143
144		dol_syslog('accountancy/customer/lines.php::changeaccount sql= '.$sql1);
145		$resql1 = $db->query($sql1);
146		if (!$resql1) {
147			$error++;
148			setEventMessages($db->lasterror(), null, 'errors');
149		}
150		if (!$error) {
151			$db->commit();
152			setEventMessages($langs->trans("Save"), null, 'mesgs');
153		} else {
154			$db->rollback();
155			setEventMessages($db->lasterror(), null, 'errors');
156		}
157
158		$account_parent = ''; // Protection to avoid to mass apply it a second time
159	}
160}
161
162
163/*
164 * View
165 */
166
167$form = new Form($db);
168$formother = new FormOther($db);
169
170llxHeader('', $langs->trans("CustomersVentilation").' - '.$langs->trans("Dispatched"));
171
172print '<script type="text/javascript">
173			$(function () {
174				$(\'#select-all\').click(function(event) {
175				    // Iterate each checkbox
176				    $(\':checkbox\').each(function() {
177				    	this.checked = true;
178				    });
179			    });
180			    $(\'#unselect-all\').click(function(event) {
181				    // Iterate each checkbox
182				    $(\':checkbox\').each(function() {
183				    	this.checked = false;
184				    });
185			    });
186			});
187			 </script>';
188
189/*
190 * Customer Invoice lines
191 */
192$sql = "SELECT f.rowid as facid, f.ref as ref, f.type, f.datef, f.ref_client,";
193$sql .= " fd.rowid, fd.description, fd.product_type as line_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.vat_src_code, fd.total_ttc,";
194$sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.code_client,";
195$sql .= " p.rowid as product_id, p.fk_product_type as product_type, p.ref as product_ref, p.label as product_label,";
196if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
197	$sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
198} else {
199	$sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
200}
201$sql .= " aa.rowid as fk_compte, aa.account_number, aa.label as label_account, aa.labelshort as labelshort_account,";
202$sql .= " fd.situation_percent,";
203$sql .= " co.code as country_code, co.label as country,";
204$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, s.code_compta as code_compta_client, s.code_compta_fournisseur";
205$parameters = array();
206$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
207$sql .= $hookmanager->resPrint;
208$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
209$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
210if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
211	$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
212}
213$sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
214$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
215$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
216$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
217$sql .= " WHERE fd.fk_code_ventilation > 0";
218$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
219$sql .= " AND f.fk_statut > 0";
220if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
221	$sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
222} else {
223	$sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
224}
225// Add search filter like
226if ($search_societe) {
227	$sql .= natural_search('s.nom', $search_societe);
228}
229if ($search_lineid) {
230	$sql .= natural_search("fd.rowid", $search_lineid, 1);
231}
232if (strlen(trim($search_invoice))) {
233	$sql .= natural_search("f.ref", $search_invoice);
234}
235if (strlen(trim($search_ref))) {
236	$sql .= natural_search("p.ref", $search_ref);
237}
238if (strlen(trim($search_label))) {
239	$sql .= natural_search("p.label", $search_label);
240}
241if (strlen(trim($search_desc))) {
242	$sql .= natural_search("fd.description", $search_desc);
243}
244if (strlen(trim($search_amount))) {
245	$sql .= natural_search("fd.total_ht", $search_amount, 1);
246}
247if (strlen(trim($search_account))) {
248	$sql .= natural_search("aa.account_number", $search_account);
249}
250if (strlen(trim($search_vat))) {
251	$sql .= natural_search("fd.tva_tx", price2num($search_vat), 1);
252}
253if ($search_date_start) {
254	$sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
255}
256if ($search_date_end) {
257	$sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
258}
259if (strlen(trim($search_country))) {
260	$arrayofcode = getCountriesInEEC();
261	$country_code_in_EEC = $country_code_in_EEC_without_me = '';
262	foreach ($arrayofcode as $key => $value) {
263		$country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
264		if ($value != $mysoc->country_code) {
265			$country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
266		}
267	}
268	if ($search_country == 'special_allnotme') {
269		$sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
270	} elseif ($search_country == 'special_eec') {
271		$sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
272	} elseif ($search_country == 'special_eecnotme') {
273		$sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
274	} elseif ($search_country == 'special_noteec') {
275		$sql .= " AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
276	} else {
277		$sql .= natural_search("co.code", $search_country);
278	}
279}
280if (strlen(trim($search_tvaintra))) {
281	$sql .= natural_search("s.tva_intra", $search_tvaintra);
282}
283$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
284$sql .= $db->order($sortfield, $sortorder);
285
286// Count total nb of records
287$nbtotalofrecords = '';
288if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
289	$result = $db->query($sql);
290	$nbtotalofrecords = $db->num_rows($result);
291	if (($page * $limit) > $nbtotalofrecords) {	// if total resultset is smaller then paging size (filtering), goto and load page 0
292		$page = 0;
293		$offset = 0;
294	}
295}
296
297$sql .= $db->plimit($limit + 1, $offset);
298
299dol_syslog("/accountancy/customer/lines.php", LOG_DEBUG);
300$result = $db->query($sql);
301if ($result) {
302	$num_lines = $db->num_rows($result);
303	$i = 0;
304
305	$param = '';
306	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
307		$param .= '&contextpage='.urlencode($contextpage);
308	}
309	if ($limit > 0 && $limit != $conf->liste_limit) {
310		$param .= '&limit='.urlencode($limit);
311	}
312	if ($search_societe) {
313		$param .= "&search_societe=".urlencode($search_societe);
314	}
315	if ($search_invoice) {
316		$param .= "&search_invoice=".urlencode($search_invoice);
317	}
318	if ($search_ref) {
319		$param .= "&search_ref=".urlencode($search_ref);
320	}
321	if ($search_label) {
322		$param .= "&search_label=".urlencode($search_label);
323	}
324	if ($search_desc) {
325		$param .= "&search_desc=".urlencode($search_desc);
326	}
327	if ($search_account) {
328		$param .= "&search_account=".urlencode($search_account);
329	}
330	if ($search_vat) {
331		$param .= "&search_vat=".urlencode($search_vat);
332	}
333	if ($search_date_startday) {
334		$param .= '&search_date_startday='.urlencode($search_date_startday);
335	}
336	if ($search_date_startmonth) {
337		$param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
338	}
339	if ($search_date_startyear) {
340		$param .= '&search_date_startyear='.urlencode($search_date_startyear);
341	}
342	if ($search_date_endday) {
343		$param .= '&search_date_endday='.urlencode($search_date_endday);
344	}
345	if ($search_date_endmonth) {
346		$param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
347	}
348	if ($search_date_endyear) {
349		$param .= '&search_date_endyear='.urlencode($search_date_endyear);
350	}
351	if ($search_country) {
352		$param .= "&search_country=".urlencode($search_country);
353	}
354	if ($search_tvaintra) {
355		$param .= "&search_tvaintra=".urlencode($search_tvaintra);
356	}
357
358	print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
359	print '<input type="hidden" name="action" value="ventil">';
360	if ($optioncss != '') {
361		print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
362	}
363	print '<input type="hidden" name="token" value="'.newToken().'">';
364	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
365	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
366	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
367	print '<input type="hidden" name="page" value="'.$page.'">';
368
369	print_barre_liste($langs->trans("InvoiceLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
370	print '<span class="opacitymedium">'.$langs->trans("DescVentilDoneCustomer").'</span><br>';
371
372	print '<br><div class="inline-block divButAction paddingbottom">'.$langs->trans("ChangeAccount").' ';
373	print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
374	print '<input type="submit" class="button small valignmiddle" value="'.$langs->trans("ChangeBinding").'"/></div>';
375
376	$moreforfilter = '';
377
378	print '<div class="div-table-responsive">';
379	print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
380
381	print '<tr class="liste_titre_filter">';
382	print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'"></td>';
383	print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'"></td>';
384	print '<td class="liste_titre center">';
385	print '<div class="nowrap">';
386	print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
387	print '</div>';
388	print '<div class="nowrap">';
389	print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
390	print '</div>';
391	print '</td>';
392	print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
393	//print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
394	print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).'"></td>';
395	print '<td class="liste_titre right"><input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
396	print '<td class="liste_titre right"><input type="text" class="right flat maxwidth50" placeholder="%" name="search_vat" size="1" value="'.dol_escape_htmltag($search_vat).'"></td>';
397	print '<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
398	print '<td class="liste_titre">';
399	print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth150', 'code2', 1, 0, 1);
400	//print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
401	print '</td>';
402	print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'"></td>';
403	print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="'.dol_escape_htmltag($search_account).'"></td>';
404	print '<td class="liste_titre center">';
405	$searchpicto = $form->showFilterButtons();
406	print $searchpicto;
407	print "</td></tr>\n";
408
409	print '<tr class="liste_titre">';
410	print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "fd.rowid", "", $param, '', $sortfield, $sortorder);
411	print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
412	print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, fd.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
413	print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
414	//print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
415	print_liste_field_titre("ProductDescription", $_SERVER["PHP_SELF"], "fd.description", "", $param, '', $sortfield, $sortorder);
416	print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "fd.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
417	print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "fd.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
418	print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
419	print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
420	print_liste_field_titre("VATIntra", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
421	print_liste_field_titre("AccountAccounting", $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
422	$checkpicto = $form->showCheckAddButtons();
423	print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center ');
424	print "</tr>\n";
425
426	$thirdpartystatic = new Societe($db);
427	$facturestatic = new Facture($db);
428	$productstatic = new Product($db);
429	$accountingaccountstatic = new AccountingAccount($db);
430
431	$i = 0;
432	while ($i < min($num_lines, $limit)) {
433		$objp = $db->fetch_object($result);
434
435		$facturestatic->ref = $objp->ref;
436		$facturestatic->id = $objp->facid;
437		$facturestatic->type = $objp->ftype;
438
439		$thirdpartystatic->id = $objp->socid;
440		$thirdpartystatic->name = $objp->name;
441		$thirdpartystatic->client = $objp->client;
442		$thirdpartystatic->fournisseur = $objp->fournisseur;
443		$thirdpartystatic->code_client = $objp->code_client;
444		$thirdpartystatic->code_compta_client = $objp->code_compta_client;
445		$thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
446		$thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
447		$thirdpartystatic->email = $objp->email;
448		$thirdpartystatic->country_code = $objp->country_code;
449
450		$productstatic->ref = $objp->product_ref;
451		$productstatic->id = $objp->product_id;
452		$productstatic->label = $objp->product_label;
453		$productstatic->type = $objp->line_type;
454		$productstatic->status = $objp->tosell;
455		$productstatic->status_buy = $objp->tobuy;
456		$productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
457		$productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
458		$productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
459
460		$accountingaccountstatic->rowid = $objp->fk_compte;
461		$accountingaccountstatic->label = $objp->label_account;
462		$accountingaccountstatic->labelshort = $objp->labelshort_account;
463		$accountingaccountstatic->account_number = $objp->account_number;
464
465		print '<tr class="oddeven">';
466
467		// Line id
468		print '<td>'.$objp->rowid.'</td>';
469
470		// Ref Invoice
471		print '<td class="nowraponall">'.$facturestatic->getNomUrl(1).'</td>';
472
473		// Date invoice
474		print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day').'</td>';
475
476		// Ref Product
477		print '<td class="tdoverflowmax100">';
478		if ($productstatic->id > 0) {
479			print $productstatic->getNomUrl(1);
480		}
481		if ($productstatic->id > 0 && $objp->product_label) {
482			print '<br>';
483		}
484		if ($objp->product_label) {
485			print '<span class="opacitymedium">'.$objp->product_label.'</span>';
486		}
487		print '</td>';
488
489		print '<td class="tdoverflowonsmartphone">';
490		$text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
491		$trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
492		print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->description);
493		print '</td>';
494
495		print '<td class="right nowraponall amount">'.price($objp->total_ht).'</td>';
496
497		print '<td class="right">'.vatrate($objp->tva_tx.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : '')).'</td>';
498
499		// Thirdparty
500		print '<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1, 'customer').'</td>';
501
502		// Country
503		print '<td>';
504		if ($objp->country_code) {
505			print $langs->trans("Country".$objp->country_code).' ('.$objp->country_code.')';
506		}
507		print '</td>';
508
509		print '<td>'.$objp->tva_intra.'</td>';
510
511		print '<td>';
512		print $accountingaccountstatic->getNomUrl(0, 1, 1, '', 1);
513		print ' <a class="editfielda" href="./card.php?id='.$objp->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($param ? '?'.$param : '')).'">';
514		print img_edit();
515		print '</a></td>';
516
517		print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="'.$objp->rowid.'"/></td>';
518
519		print '</tr>';
520		$i++;
521	}
522	print '</table>';
523	print "</div>";
524
525	if ($nbtotalofrecords > $limit) {
526		print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
527	}
528
529	print '</form>';
530} else {
531	print $db->lasterror();
532}
533
534// End of page
535llxFooter();
536$db->close();
537