29 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
43 $langs->loadLangs(array(
"bills",
"companies",
"compta",
"accountancy",
"other",
"productbatch",
"products"));
45 $action =
GETPOST(
'action',
'aZ09');
46 $massaction =
GETPOST(
'massaction',
'alpha');
47 $confirm =
GETPOST(
'confirm',
'alpha');
48 $toselect =
GETPOST(
'toselect',
'array');
49 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'accountancysupplierlist';
50 $optioncss =
GETPOST(
'optioncss',
'alpha');
52 $default_account =
GETPOST(
'default_account',
'int');
55 $mesCasesCochees =
GETPOST(
'toselect',
'array');
58 $search_societe =
GETPOST(
'search_societe',
'alpha');
59 $search_lineid =
GETPOST(
'search_lineid',
'int');
60 $search_ref =
GETPOST(
'search_ref',
'alpha');
61 $search_ref_supplier =
GETPOST(
'search_ref_supplier',
'alpha');
62 $search_invoice =
GETPOST(
'search_invoice',
'alpha');
63 $search_label =
GETPOST(
'search_label',
'alpha');
64 $search_desc =
GETPOST(
'search_desc',
'alpha');
65 $search_amount =
GETPOST(
'search_amount',
'alpha');
66 $search_account =
GETPOST(
'search_account',
'alpha');
67 $search_vat =
GETPOST(
'search_vat',
'alpha');
68 $search_date_startday =
GETPOST(
'search_date_startday',
'int');
69 $search_date_startmonth =
GETPOST(
'search_date_startmonth',
'int');
70 $search_date_startyear =
GETPOST(
'search_date_startyear',
'int');
71 $search_date_endday =
GETPOST(
'search_date_endday',
'int');
72 $search_date_endmonth =
GETPOST(
'search_date_endmonth',
'int');
73 $search_date_endyear =
GETPOST(
'search_date_endyear',
'int');
74 $search_date_start =
dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
75 $search_date_end =
dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
76 $search_country =
GETPOST(
'search_country',
'alpha');
77 $search_tvaintra =
GETPOST(
'search_tvaintra',
'alpha');
80 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
81 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
82 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
84 if (empty($page) || $page < 0) {
87 $offset = $limit * $page;
88 $pageprev = $page - 1;
89 $pagenext = $page + 1;
91 $sortfield =
"f.datef, f.ref, l.rowid";
94 if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
102 $hookmanager->initHooks(array(
'accountancysupplierlist'));
113 if ($user->socid > 0) {
116 if (!$user->hasRight(
'accounting',
'mouvements',
'lire')) {
125 if (
GETPOST(
'cancel',
'alpha')) {
126 $action =
'list'; $massaction =
'';
128 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
132 $parameters = array();
133 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
138 if (empty($reshook)) {
140 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
141 $search_societe =
'';
144 $search_ref_supplier =
'';
145 $search_invoice =
'';
149 $search_account =
'';
151 $search_date_startday =
'';
152 $search_date_startmonth =
'';
153 $search_date_startyear =
'';
154 $search_date_endday =
'';
155 $search_date_endmonth =
'';
156 $search_date_endyear =
'';
157 $search_date_start =
'';
158 $search_date_end =
'';
159 $search_country =
'';
160 $search_tvaintra =
'';
164 $objectclass =
'AccountingAccount';
165 $permissiontoread = $user->hasRight(
'accounting',
'read');
166 $permissiontodelete = $user->hasRight(
'accounting',
'delete');
167 $uploaddir = $conf->accounting->dir_output;
168 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
172 if ($massaction ==
'ventil' && $user->hasRight(
'accounting',
'bind',
'write')) {
175 if (!empty($mesCasesCochees)) {
176 $msg =
'<div>'.$langs->trans(
"SelectedLines").
': '.count($mesCasesCochees).
'</div>';
177 $msg .=
'<div class="detail">';
182 foreach ($mesCasesCochees as $maLigneCochee) {
183 $maLigneCourante = explode(
"_", $maLigneCochee);
184 $monId = $maLigneCourante[0];
185 $monCompte =
GETPOST(
'codeventil'.$monId);
187 if ($monCompte <= 0) {
188 $msg .=
'<div><span class="error">'.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"NoAccountSelected").
'</span></div>';
191 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det";
192 $sql .=
" SET fk_code_ventilation = ".((int) $monCompte);
193 $sql .=
" WHERE rowid = ".((int) $monId);
196 $accountventilated->fetch($monCompte,
'', 1);
198 dol_syslog(
'accountancy/supplier/list.php', LOG_DEBUG);
199 if ($db->query(
$sql)) {
200 $msg .=
'<div><span class="green">'.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"VentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'</span></div>';
203 $msg .=
'<div><span class="error">'.$langs->trans(
"ErrorDB").
' : '.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"NotVentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'<br> <pre>'.
$sql.
'</pre></span></div>';
211 $msg .=
'<div>'.$langs->trans(
"EndProcessing").
'</div>';
215 if (
GETPOST(
'sortfield') ==
'f.datef, f.ref, l.rowid') {
216 $value = (
GETPOST(
'sortorder') ==
'asc,asc,asc' ? 0 : 1);
217 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
218 $res =
dolibarr_set_const($db,
"ACCOUNTING_LIST_SORT_VENTILATION_TODO", $value,
'yesno', 0,
'', $conf->entity);
229 llxHeader(
'', $langs->trans(
"SuppliersVentilation"));
231 if (empty($chartaccountcode)) {
232 print $langs->trans(
"ErrorChartOfAccountSystemNotSelected");
240 $sql =
"SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype, f.fk_facture_source,";
241 $sql .=
" l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
242 $sql .=
" p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,";
243 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
244 $sql .=
" ppe.accountancy_code_sell as code_sell, ppe.accountancy_code_sell_intra as code_sell_intra, ppe.accountancy_code_sell_export as code_sell_export,";
245 $sql .=
" ppe.accountancy_code_buy as code_buy, ppe.accountancy_code_buy_intra as code_buy_intra, ppe.accountancy_code_buy_export as code_buy_export,";
247 $sql .=
" p.accountancy_code_sell as code_sell, p.accountancy_code_sell_intra as code_sell_intra, p.accountancy_code_sell_export as code_sell_export,";
248 $sql .=
" p.accountancy_code_buy as code_buy, p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export,";
250 $sql .=
" p.tosell as status, p.tobuy as status_buy,";
251 $sql .=
" aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
252 $sql .=
" co.code as country_code, co.label as country_label,";
253 $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,";
254 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
255 $sql .=
" spe.accountancy_code_customer as code_compta_client,";
256 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
257 $sql .=
" spe.accountancy_code_buy as company_code_buy";
259 $sql .=
" s.code_compta as code_compta_client,";
260 $sql .=
" s.code_compta_fournisseur,";
261 $sql .=
" s.accountancy_code_buy as company_code_buy";
263 $parameters = array();
264 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
265 $sql .= $hookmanager->resPrint;
266 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
267 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
268 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
269 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
271 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
272 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
273 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = l.fk_product";
274 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
275 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
277 $alias_societe_perentity = empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED) ?
"s" :
"spe";
278 $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ?
"p" :
"ppe";
279 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON " . $alias_product_perentity .
".accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa.entity = ".$conf->entity;
280 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa2 ON " . $alias_product_perentity .
".accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa2.entity = ".$conf->entity;
281 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa3 ON " . $alias_product_perentity .
".accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa3.entity = ".$conf->entity;
282 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa4 ON " . $alias_societe_perentity .
".accountancy_code_buy = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa4.entity = ".$conf->entity;
283 $sql .=
" WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
284 $sql .=
" AND l.product_type <= 2";
286 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
287 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
290 if ($search_societe) {
293 if ($search_lineid) {
296 if (strlen(trim($search_invoice))) {
299 if (strlen(trim($search_ref))) {
305 if (strlen(trim($search_label))) {
308 if (strlen(trim($search_desc))) {
311 if (strlen(trim($search_amount))) {
314 if (strlen(trim($search_account))) {
317 if (strlen(trim($search_vat))) {
320 if ($search_date_start) {
321 $sql .=
" AND f.datef >= '".$db->idate($search_date_start).
"'";
323 if ($search_date_end) {
324 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
326 if (strlen(trim($search_country))) {
328 $country_code_in_EEC = $country_code_in_EEC_without_me =
'';
329 foreach ($arrayofcode as $key => $value) {
330 $country_code_in_EEC .= ($country_code_in_EEC ?
"," :
"").
"'".$value.
"'";
331 if ($value != $mysoc->country_code) {
332 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ?
"," :
"").
"'".$value.
"'";
335 if ($search_country ==
'special_allnotme') {
336 $sql .=
" AND co.code <> '".$db->escape($mysoc->country_code).
"'";
337 } elseif ($search_country ==
'special_eec') {
338 $sql .=
" AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).
")";
339 } elseif ($search_country ==
'special_eecnotme') {
340 $sql .=
" AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).
")";
341 } elseif ($search_country ==
'special_noteec') {
342 $sql .=
" AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).
")";
347 if (strlen(trim($search_tvaintra))) {
350 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
355 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn', 0).
")";
358 $parameters = array();
359 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
360 $sql .= $hookmanager->resPrint;
362 $sql .= $db->order($sortfield, $sortorder);
365 $nbtotalofrecords =
'';
367 $result = $db->query(
$sql);
368 $nbtotalofrecords = $db->num_rows($result);
369 if (($page * $limit) > $nbtotalofrecords) {
375 $sql .= $db->plimit($limit + 1, $offset);
377 dol_syslog(
'accountancy/supplier/list.php', LOG_DEBUG);
380 if ($db->type ==
'mysqli') {
381 $db->query(
"SET SQL_BIG_SELECTS=1");
384 $result = $db->query(
$sql);
386 $num_lines = $db->num_rows($result);
389 $arrayofselected = is_array($toselect) ? $toselect : array();
392 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
393 $param .=
'&contextpage='.urlencode($contextpage);
395 if ($limit > 0 && $limit != $conf->liste_limit) {
396 $param .=
'&limit='.((int) $limit);
398 if ($search_societe) {
399 $param .=
'&search_societe='.urlencode($search_societe);
401 if ($search_lineid) {
402 $param .=
'&search_lineid='.urlencode($search_lineid);
404 if ($search_date_startday) {
405 $param .=
'&search_date_startday='.urlencode($search_date_startday);
407 if ($search_date_startmonth) {
408 $param .=
'&search_date_startmonth='.urlencode($search_date_startmonth);
410 if ($search_date_startyear) {
411 $param .=
'&search_date_startyear='.urlencode($search_date_startyear);
413 if ($search_date_endday) {
414 $param .=
'&search_date_endday='.urlencode($search_date_endday);
416 if ($search_date_endmonth) {
417 $param .=
'&search_date_endmonth='.urlencode($search_date_endmonth);
419 if ($search_date_endyear) {
420 $param .=
'&search_date_endyear='.urlencode($search_date_endyear);
422 if ($search_invoice) {
423 $param .=
'&search_invoice='.urlencode($search_invoice);
426 $param .=
'&search_ref='.urlencode($search_ref);
428 if ($search_ref_supplier) {
429 $param .=
'&search_ref_supplier='.urlencode($search_ref_supplier);
432 $param .=
'&search_label='.urlencode($search_label);
435 $param .=
'&search_desc='.urlencode($search_desc);
437 if ($search_amount) {
438 $param .=
'&search_amount='.urlencode($search_amount);
441 $param .=
'&search_vat='.urlencode($search_vat);
443 if ($search_country) {
444 $param .=
"&search_country=".urlencode($search_country);
446 if ($search_tvaintra) {
447 $param .=
"&search_tvaintra=".urlencode($search_tvaintra);
450 $arrayofmassactions = array(
451 'ventil'=>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"Ventilate")
452 ,
'set_default_account'=>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"ConfirmPreselectAccount")
458 if ($massaction !==
'set_default_account') {
459 $massactionbutton =
$form->selectMassAction(
'ventil', $arrayofmassactions, 1);
462 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
463 print
'<input type="hidden" name="action" value="ventil">';
464 if ($optioncss !=
'') {
465 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
467 print
'<input type="hidden" name="token" value="'.newToken().
'">';
468 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
469 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
470 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
471 print
'<input type="hidden" name="page" value="'.$page.
'">';
473 print_barre_liste($langs->trans(
"InvoiceLines"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
475 if ($massaction ==
'set_default_account') {
476 $formquestion[]=array(
'type' =>
'other',
477 'name' =>
'set_default_account',
478 'label' => $langs->trans(
"AccountancyCode"),
479 'value' => $formaccounting->select_account(
'',
'default_account', 1, array(), 0, 0,
'maxwidth200 maxwidthonsmartphone',
'cachewithshowemptyone'));
480 print
$form->formconfirm($_SERVER[
"PHP_SELF"], $langs->trans(
"ConfirmPreselectAccount"), $langs->trans(
"ConfirmPreselectAccountQuestion", count($toselect)),
"confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
483 print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilTodoCustomer").
'</span></br><br>';
491 print
'<div class="div-table-responsive">';
492 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
495 print
'<tr class="liste_titre_filter">';
496 print
'<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).
'"></td>';
497 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).
'"></td>';
499 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
500 print
'<td class="liste_titre center">';
501 print
'<div class="nowrap">';
502 print
$form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
504 print
'<div class="nowrap">';
505 print
$form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
508 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
509 print
'<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
510 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
511 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" size="1" value="'.dol_escape_htmltag($search_vat).
'"></td>';
512 print
'<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'"></td>';
513 print
'<td class="liste_titre">';
514 print
$form->select_country($search_country,
'search_country',
'', 0,
'maxwidth100',
'code2', 1, 0, 1);
517 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).
'"></td>';
518 print
'<td class="liste_titre"></td>';
519 print
'<td class="liste_titre"></td>';
520 print
'<td class="center liste_titre">';
521 $searchpicto =
$form->showFilterButtons();
526 print
'<tr class="liste_titre">';
530 print_liste_field_titre(
"InvoiceLabel", $_SERVER[
"PHP_SELF"],
"f.libelle",
"", $param,
'', $sortfield, $sortorder);
531 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"f.datef, f.ref, l.rowid",
"", $param,
'', $sortfield, $sortorder,
'center ');
534 print_liste_field_titre(
"ProductDescription", $_SERVER[
"PHP_SELF"],
"l.description",
"", $param,
'', $sortfield, $sortorder);
535 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"l.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right maxwidth50 ');
536 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"l.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ',
'', 1);
539 print_liste_field_titre(
"VATIntraShort", $_SERVER[
"PHP_SELF"],
"s.tva_intra",
"", $param,
'', $sortfield, $sortorder);
543 if ($massactionbutton) {
544 $checkpicto =
$form->showCheckAddButtons(
'checkforselect', 1);
549 $thirdpartystatic =
new Societe($db);
552 $product_static =
new Product($db);
555 $accountingaccount_codetotid_cache = array();
557 while ($i < min($num_lines, $limit)) {
558 $objp = $db->fetch_object($result);
567 $thirdpartystatic->id = $objp->socid;
568 $thirdpartystatic->name = $objp->name;
569 $thirdpartystatic->client = $objp->client;
570 $thirdpartystatic->fournisseur = $objp->fournisseur;
571 $thirdpartystatic->code_client = $objp->code_client;
572 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
573 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
574 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
575 $thirdpartystatic->email = $objp->email;
576 $thirdpartystatic->country_code = $objp->country_code;
577 $thirdpartystatic->tva_intra = $objp->tva_intra;
578 $thirdpartystatic->code_compta_product = $objp->company_code_buy;
580 $product_static->ref = $objp->product_ref;
581 $product_static->id = $objp->product_id;
582 $product_static->type = $objp->type;
583 $product_static->label = $objp->product_label;
584 $product_static->status = $objp->status;
585 $product_static->status_buy = $objp->status_buy;
586 $product_static->accountancy_code_sell = $objp->code_sell;
587 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
588 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
589 $product_static->accountancy_code_buy = $objp->code_buy;
590 $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
591 $product_static->accountancy_code_buy_export = $objp->code_buy_export;
592 $product_static->tva_tx = $objp->tva_tx_prod;
594 $facturefourn_static->ref = $objp->ref;
595 $facturefourn_static->id = $objp->facid;
596 $facturefourn_static->type = $objp->ftype;
597 $facturefourn_static->ref_supplier = $objp->ref_supplier;
598 $facturefourn_static->label = $objp->invoice_label;
599 $facturefourn_static->date = $db->jdate($objp->datef);
600 $facturefourn_static->fk_facture_source = $objp->fk_facture_source;
602 $facturefourn_static_det->id = $objp->rowid;
603 $facturefourn_static_det->total_ht = $objp->total_ht;
604 $facturefourn_static_det->tva_tx = $objp->tva_tx_line;
605 $facturefourn_static_det->vat_src_code = $objp->vat_src_code;
606 $facturefourn_static_det->product_type = $objp->type_l;
607 $facturefourn_static_det->desc = $objp->description;
609 $accountingAccountArray = array(
610 'dom'=>$objp->aarowid,
611 'intra'=>$objp->aarowid_intra,
612 'export'=>$objp->aarowid_export,
613 'thirdparty' =>$objp->aarowid_thirdparty);
615 $code_buy_p_notset =
'';
616 $code_buy_t_notset =
'';
620 $return=$accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facturefourn_static, $facturefourn_static_det, $accountingAccountArray,
'supplier');
621 if (!is_array($return) && $return<0) {
624 $suggestedid=$return[
'suggestedid'];
625 $suggestedaccountingaccountfor=$return[
'suggestedaccountingaccountfor'];
626 $suggestedaccountingaccountbydefaultfor=$return[
'suggestedaccountingaccountbydefaultfor'];
627 $code_buy_l=$return[
'code_l'];
628 $code_buy_p=$return[
'code_p'];
629 $code_buy_t=$return[
'code_t'];
633 if (!empty($code_buy_p)) {
636 $code_buy_p_notset =
'color:orange';
638 if (empty($code_buy_l) && empty($code_buy_p)) {
639 $code_buy_p_notset =
'color:red';
650 print
'<tr class="oddeven">';
653 print
'<td>'.$facturefourn_static_det->id.
'</td>';
656 print
'<td class="nowraponall">'.$facturefourn_static->getNomUrl(1);
657 if ($objp->ref_supplier) {
658 print
'<br><span class="opacitymedium small">'.dol_escape_htmltag($objp->ref_supplier).
'</span>';
668 print
'<td class="tdoverflowmax100 small" title="'.dol_escape_htmltag($objp->invoice_label).
'">';
673 print
'<td class="center">'.dol_print_date($facturefourn_static->date,
'day').
'</td>';
676 print
'<td class="tdoverflowmax100">';
677 if ($product_static->id > 0) {
678 print $product_static->getNomUrl(1);
680 if ($product_static->label) {
681 print
'<br><span class="opacitymedium small">'.dol_escape_htmltag($product_static->label).
'</span>';
686 print
'<td class="tdoverflowonsmartphone small">';
688 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
689 print
$form->textwithtooltip(
dol_trunc($text, $trunclength), $facturefourn_static_det->desc);
692 print
'<td class="right nowraponall amount">';
693 print
price($objp->total_ht);
697 $code_vat_differ =
'';
701 print
'<td class="right'.($code_vat_differ?
' '.$code_vat_differ:
'').
'">';
702 print
vatrate($facturefourn_static_det->tva_tx.($facturefourn_static_det->vat_src_code ?
' ('.$facturefourn_static_det->vat_src_code.
')' :
''),
false, 0, 0, 1);
706 print
'<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1,
'supplier').
'</td>';
709 $labelcountry = ($objp->country_code && ($langs->trans(
"Country".$objp->country_code) !=
"Country".$objp->country_code)) ? $langs->trans(
"Country".$objp->country_code) : $objp->country_label;
710 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labelcountry).
'">';
715 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).
'">'.
dol_escape_htmltag($objp->tva_intra).
'</td>';
718 print
'<td class="small">';
719 $s =
'1. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans(
"DefaultForService") : $langs->trans(
"DefaultForProduct")).
': ';
720 $shelp =
''; $ttype =
'help';
721 if ($suggestedaccountingaccountbydefaultfor ==
'eec') {
722 $shelp .= $langs->trans(
"SaleEEC");
723 } elseif ($suggestedaccountingaccountbydefaultfor ==
'eecwithvat') {
724 $shelp = $langs->trans(
"SaleEECWithVAT");
725 } elseif ($suggestedaccountingaccountbydefaultfor ==
'eecwithoutvatnumber') {
726 $shelp = $langs->trans(
"SaleEECWithoutVATNumber");
728 } elseif ($suggestedaccountingaccountbydefaultfor ==
'export') {
729 $shelp .= $langs->trans(
"SaleExport");
731 $s .= ($code_buy_l > 0 ?
length_accountg($code_buy_l) :
'<span style="'.$code_buy_p_notset.
'">'.$langs->trans(
"NotDefined").
'</span>');
732 print
$form->textwithpicto($s, $shelp, 1, $ttype,
'', 0, 2,
'', 1);
733 if ($product_static->id > 0) {
735 $s =
'2. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans(
"ThisService") : $langs->trans(
"ThisProduct")).
': ';
736 $shelp =
''; $ttype =
'help';
737 if ($suggestedaccountingaccountfor ==
'eec') {
738 $shelp = $langs->trans(
"SaleEEC");
739 } elseif ($suggestedaccountingaccountfor ==
'eecwithvat') {
740 $shelp = $langs->trans(
"SaleEECWithVAT");
741 } elseif ($suggestedaccountingaccountfor ==
'eecwithoutvatnumber') {
742 $shelp = $langs->trans(
"SaleEECWithoutVATNumber");
744 } elseif ($suggestedaccountingaccountfor ==
'export') {
745 $shelp = $langs->trans(
"SaleExport");
747 $s .= (empty($code_buy_p) ?
'<span style="'.$code_buy_p_notset.
'">'.$langs->trans(
"NotDefined").
'</span>' :
length_accountg($code_buy_p));
748 print
$form->textwithpicto($s, $shelp, 1, $ttype,
'', 0, 2,
'', 1);
751 $s =
'2. '.(($objp->type_l == 1) ? $langs->trans(
"ThisService") : $langs->trans(
"ThisProduct")).
': ';
753 $s .= $langs->trans(
"NotDefined");
754 print
$form->textwithpicto($s, $shelp, 1,
'help',
'', 0, 2,
'', 1);
756 if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
758 $s =
'3. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans(
"ServiceForThisThirdparty") : $langs->trans(
"ProductForThisThirdparty")).
': ';
760 $s .= ($code_buy_t > 0 ?
length_accountg($code_buy_t) :
'<span style="'.$code_buy_t_notset.
'">'.$langs->trans(
"NotDefined").
'</span>');
761 print
$form->textwithpicto($s, $shelp, 1,
'help',
'', 0, 2,
'', 1);
767 print $formaccounting->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($objp->rowid.
"_".$i, $toselect)) ? $default_account : $suggestedid,
'codeventil'.$facturefourn_static_det->id, 1, array(), 0, 0,
'codeventil maxwidth150 maxwidthonsmartphone',
'cachewithshowemptyone');
771 print
'<td class="center">';
773 if (!empty($suggestedid) && $suggestedaccountingaccountfor !=
'' && $suggestedaccountingaccountfor !=
'eecwithoutvatnumber') {
777 if (!empty($toselect)) {
779 if (in_array($objp->rowid.
"_".$i, $toselect)) {
784 print
'<input type="checkbox" class="flat checkforselect checkforselect'.$facturefourn_static_det->id.
'" name="toselect[]" value="'.$facturefourn_static_det->id.
"_".$i.
'"'.($ischecked ?
" checked" :
"").
'/>';
790 if ($num_lines == 0) {
791 print
'<tr><td colspan="14"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
801 if ($db->type ==
'mysqli') {
802 $db->query(
"SET SQL_BIG_SELECTS=0");
806 print
'<script type="text/javascript">
807 jQuery(document).ready(function() {
808 jQuery(".codeventil").change(function() {
809 var s=$(this).attr("id").replace("codeventil", "")
810 console.log(s+" "+$(this).val());
811 if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
812 else jQuery(".checkforselect"+s).prop("checked", true);
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage accounting accounts.
const TYPE_SITUATION
Situation invoice.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage line invoices.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.