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.
'/compta/facture/class/facture.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
42 $langs->loadLangs(array(
"bills",
"companies",
"compta",
"accountancy",
"other",
"productbatch",
"products"));
44 $action =
GETPOST(
'action',
'aZ09');
45 $massaction =
GETPOST(
'massaction',
'alpha');
46 $confirm =
GETPOST(
'confirm',
'alpha');
47 $toselect =
GETPOST(
'toselect',
'array');
48 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'accountancycustomerlist';
49 $optioncss =
GETPOST(
'optioncss',
'alpha');
51 $default_account =
GETPOST(
'default_account',
'int');
54 $mesCasesCochees =
GETPOST(
'toselect',
'array');
57 $search_societe =
GETPOST(
'search_societe',
'alpha');
58 $search_lineid =
GETPOST(
'search_lineid',
'int');
59 $search_ref =
GETPOST(
'search_ref',
'alpha');
60 $search_invoice =
GETPOST(
'search_invoice',
'alpha');
61 $search_label =
GETPOST(
'search_label',
'alpha');
62 $search_desc =
GETPOST(
'search_desc',
'alpha');
63 $search_amount =
GETPOST(
'search_amount',
'alpha');
64 $search_account =
GETPOST(
'search_account',
'alpha');
65 $search_vat =
GETPOST(
'search_vat',
'alpha');
66 $search_date_startday =
GETPOST(
'search_date_startday',
'int');
67 $search_date_startmonth =
GETPOST(
'search_date_startmonth',
'int');
68 $search_date_startyear =
GETPOST(
'search_date_startyear',
'int');
69 $search_date_endday =
GETPOST(
'search_date_endday',
'int');
70 $search_date_endmonth =
GETPOST(
'search_date_endmonth',
'int');
71 $search_date_endyear =
GETPOST(
'search_date_endyear',
'int');
72 $search_date_start =
dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
73 $search_date_end =
dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
74 $search_country =
GETPOST(
'search_country',
'alpha');
75 $search_tvaintra =
GETPOST(
'search_tvaintra',
'alpha');
78 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
79 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
80 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
82 if (empty($page) || $page < 0) {
85 $offset = $limit * $page;
86 $pageprev = $page - 1;
87 $pagenext = $page + 1;
89 $sortfield =
"f.datef, f.ref, l.rowid";
92 if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
100 $hookmanager->initHooks(array(
'accountancycustomerlist'));
111 if ($user->socid > 0) {
114 if (!$user->hasRight(
'accounting',
'mouvements',
'lire')) {
123 if (
GETPOST(
'cancel',
'alpha')) {
124 $action =
'list'; $massaction =
'';
126 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
130 $parameters = array();
131 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
136 if (empty($reshook)) {
138 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
139 $search_societe =
'';
142 $search_invoice =
'';
146 $search_account =
'';
148 $search_date_startday =
'';
149 $search_date_startmonth =
'';
150 $search_date_startyear =
'';
151 $search_date_endday =
'';
152 $search_date_endmonth =
'';
153 $search_date_endyear =
'';
154 $search_date_start =
'';
155 $search_date_end =
'';
156 $search_country =
'';
157 $search_tvaintra =
'';
161 $objectclass =
'AccountingAccount';
162 $permissiontoread = $user->hasRight(
'accounting',
'read');
163 $permissiontodelete = $user->hasRight(
'accounting',
'delete');
164 $uploaddir = $conf->accounting->dir_output;
165 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
169 if ($massaction ==
'ventil' && $user->hasRight(
'accounting',
'bind',
'write')) {
173 if (!empty($mesCasesCochees)) {
174 $msg =
'<div>'.$langs->trans(
"SelectedLines").
': '.count($mesCasesCochees).
'</div>';
175 $msg .=
'<div class="detail">';
180 foreach ($mesCasesCochees as $maLigneCochee) {
181 $maLigneCourante = explode(
"_", $maLigneCochee);
182 $monId = $maLigneCourante[0];
183 $monCompte =
GETPOST(
'codeventil'.$monId);
185 if ($monCompte <= 0) {
186 $msg .=
'<div><span style="color:red">'.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"NoAccountSelected").
'</span></div>';
189 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"facturedet";
190 $sql .=
" SET fk_code_ventilation = ".((int) $monCompte);
191 $sql .=
" WHERE rowid = ".((int) $monId);
194 $accountventilated->fetch($monCompte,
'', 1);
196 dol_syslog(
"accountancy/customer/list.php", LOG_DEBUG);
197 if ($db->query(
$sql)) {
198 $msg .=
'<div><span style="color:green">'.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"VentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'</span></div>';
201 $msg .=
'<div><span style="color:red">'.$langs->trans(
"ErrorDB").
' : '.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"NotVentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'<br> <pre>'.
$sql.
'</pre></span></div>';
209 $msg .=
'<div>'.$langs->trans(
"EndProcessing").
'</div>';
213 if (
GETPOST(
'sortfield') ==
'f.datef, f.ref, l.rowid') {
214 $value = (
GETPOST(
'sortorder') ==
'asc,asc,asc' ? 0 : 1);
215 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
216 $res =
dolibarr_set_const($db,
"ACCOUNTING_LIST_SORT_VENTILATION_TODO", $value,
'yesno', 0,
'', $conf->entity);
227 llxHeader(
'', $langs->trans(
"Ventilation"));
229 if (empty($chartaccountcode)) {
230 print $langs->trans(
"ErrorChartOfAccountSystemNotSelected");
238 $sql =
"SELECT f.rowid as facid, f.ref, f.datef, f.type as ftype, f.situation_cycle_ref, f.fk_facture_source,";
239 $sql .=
" l.rowid, l.fk_product, l.description, l.total_ht, l.situation_percent, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
240 $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,";
241 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
242 $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,";
243 $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,";
245 $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,";
246 $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,";
248 $sql .=
" p.tosell as status, p.tobuy as status_buy,";
249 $sql .=
" aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
250 $sql .=
" co.code as country_code, co.label as country_label,";
251 $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,";
252 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
253 $sql .=
" spe.accountancy_code_customer as code_compta_client,";
254 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
255 $sql .=
" spe.accountancy_code_sell as company_code_sell";
257 $sql .=
" s.code_compta as code_compta_client,";
258 $sql .=
" s.code_compta_fournisseur,";
259 $sql .=
" s.accountancy_code_sell as company_code_sell";
261 $parameters = array();
262 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
263 $sql .= $hookmanager->resPrint;
264 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
265 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
266 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
267 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
269 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
270 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facturedet as l ON f.rowid = l.fk_facture";
271 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = l.fk_product";
272 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
273 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
275 $alias_societe_perentity = empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED) ?
"s" :
"spe";
276 $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ?
"p" :
"ppe";
277 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON " . $alias_product_perentity .
".accountancy_code_sell = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa.entity = ".$conf->entity;
278 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa2 ON " . $alias_product_perentity .
".accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa2.entity = ".$conf->entity;
279 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa3 ON " . $alias_product_perentity .
".accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa3.entity = ".$conf->entity;
280 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa4 ON " . $alias_societe_perentity .
".accountancy_code_sell = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa4.entity = ".$conf->entity;
282 $sql .=
" WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
283 $sql .=
" AND l.product_type <= 2";
285 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
286 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
289 if ($search_societe) {
292 if ($search_lineid) {
295 if (strlen(trim($search_invoice))) {
298 if (strlen(trim($search_ref))) {
301 if (strlen(trim($search_label))) {
304 if (strlen(trim($search_desc))) {
307 if (strlen(trim($search_amount))) {
310 if (strlen(trim($search_account))) {
313 if (strlen(trim($search_vat))) {
316 if ($search_date_start) {
317 $sql .=
" AND f.datef >= '".$db->idate($search_date_start).
"'";
319 if ($search_date_end) {
320 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
322 if (strlen(trim($search_country))) {
324 $country_code_in_EEC = $country_code_in_EEC_without_me =
'';
325 foreach ($arrayofcode as $key => $value) {
326 $country_code_in_EEC .= ($country_code_in_EEC ?
"," :
"").
"'".$value.
"'";
327 if ($value != $mysoc->country_code) {
328 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ?
"," :
"").
"'".$value.
"'";
331 if ($search_country ==
'special_allnotme') {
332 $sql .=
" AND co.code <> '".$db->escape($mysoc->country_code).
"'";
333 } elseif ($search_country ==
'special_eec') {
334 $sql .=
" AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).
")";
335 } elseif ($search_country ==
'special_eecnotme') {
336 $sql .=
" AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).
")";
337 } elseif ($search_country ==
'special_noteec') {
338 $sql .=
" AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).
")";
343 if (strlen(trim($search_tvaintra))) {
346 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
351 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
354 $parameters = array();
355 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
356 $sql .= $hookmanager->resPrint;
358 $sql .= $db->order($sortfield, $sortorder);
361 $nbtotalofrecords =
'';
363 $result = $db->query(
$sql);
364 $nbtotalofrecords = $db->num_rows($result);
365 if (($page * $limit) > $nbtotalofrecords) {
371 $sql .= $db->plimit($limit + 1, $offset);
373 dol_syslog(
"accountancy/customer/list.php", LOG_DEBUG);
376 if ($db->type ==
'mysqli') {
377 $db->query(
"SET SQL_BIG_SELECTS=1");
380 $result = $db->query(
$sql);
382 $num_lines = $db->num_rows($result);
385 $arrayofselected = is_array($toselect) ? $toselect : array();
388 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
389 $param .=
'&contextpage='.urlencode($contextpage);
391 if ($limit > 0 && $limit != $conf->liste_limit) {
392 $param .=
'&limit='.((int) $limit);
394 if ($search_societe) {
395 $param .=
'&search_societe='.urlencode($search_societe);
397 if ($search_lineid) {
398 $param .=
'&search_lineid='.urlencode($search_lineid);
400 if ($search_date_startday) {
401 $param .=
'&search_date_startday='.urlencode($search_date_startday);
403 if ($search_date_startmonth) {
404 $param .=
'&search_date_startmonth='.urlencode($search_date_startmonth);
406 if ($search_date_startyear) {
407 $param .=
'&search_date_startyear='.urlencode($search_date_startyear);
409 if ($search_date_endday) {
410 $param .=
'&search_date_endday='.urlencode($search_date_endday);
412 if ($search_date_endmonth) {
413 $param .=
'&search_date_endmonth='.urlencode($search_date_endmonth);
415 if ($search_date_endyear) {
416 $param .=
'&search_date_endyear='.urlencode($search_date_endyear);
418 if ($search_invoice) {
419 $param .=
'&search_invoice='.urlencode($search_invoice);
422 $param .=
'&search_ref='.urlencode($search_ref);
425 $param .=
'&search_label='.urlencode($search_label);
428 $param .=
'&search_desc='.urlencode($search_desc);
430 if ($search_amount) {
431 $param .=
'&search_amount='.urlencode($search_amount);
434 $param .=
'&search_vat='.urlencode($search_vat);
436 if ($search_country) {
437 $param .=
"&search_country=".urlencode($search_country);
439 if ($search_tvaintra) {
440 $param .=
"&search_tvaintra=".urlencode($search_tvaintra);
443 $arrayofmassactions = array(
444 'ventil'=>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"Ventilate")
445 ,
'set_default_account'=>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"ConfirmPreselectAccount")
451 if ($massaction !==
'set_default_account') {
452 $massactionbutton =
$form->selectMassAction(
'ventil', $arrayofmassactions, 1);
455 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
456 print
'<input type="hidden" name="action" value="ventil">';
457 if ($optioncss !=
'') {
458 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
460 print
'<input type="hidden" name="token" value="'.newToken().
'">';
461 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
462 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
463 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
464 print
'<input type="hidden" name="page" value="'.$page.
'">';
466 print_barre_liste($langs->trans(
"InvoiceLines"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
468 if ($massaction ==
'set_default_account') {
469 $formquestion[]=array(
'type' =>
'other',
470 'name' =>
'set_default_account',
471 'label' => $langs->trans(
"AccountancyCode"),
472 'value' => $formaccounting->select_account(
'',
'default_account', 1, array(), 0, 0,
'maxwidth200 maxwidthonsmartphone',
'cachewithshowemptyone'));
473 print
$form->formconfirm($_SERVER[
"PHP_SELF"], $langs->trans(
"ConfirmPreselectAccount"), $langs->trans(
"ConfirmPreselectAccountQuestion", count($toselect)),
"confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
476 print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilTodoCustomer").
'</span></br><br>';
484 print
'<div class="div-table-responsive">';
485 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
488 print
'<tr class="liste_titre_filter">';
489 print
'<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).
'"></td>';
490 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).
'"></td>';
491 print
'<td class="liste_titre center">';
492 print
'<div class="nowrap">';
493 print
$form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
495 print
'<div class="nowrap">';
496 print
$form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
499 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
500 print
'<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
501 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
502 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>';
503 print
'<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'"></td>';
504 print
'<td class="liste_titre">';
505 print
$form->select_country($search_country,
'search_country',
'', 0,
'maxwidth100',
'code2', 1, 0, 1);
508 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).
'"></td>';
509 print
'<td class="liste_titre"></td>';
510 print
'<td class="liste_titre"></td>';
511 print
'<td class="center liste_titre">';
512 $searchpicto =
$form->showFilterButtons();
517 print
'<tr class="liste_titre">';
520 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"f.datef, f.ref, l.rowid",
"", $param,
'', $sortfield, $sortorder,
'center ');
523 print_liste_field_titre(
"ProductDescription", $_SERVER[
"PHP_SELF"],
"l.description",
"", $param,
'', $sortfield, $sortorder);
524 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"l.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right maxwidth50 ');
525 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"l.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ',
'', 1);
528 print_liste_field_titre(
"VATIntraShort", $_SERVER[
"PHP_SELF"],
"s.tva_intra",
"", $param,
'', $sortfield, $sortorder);
532 if ($massactionbutton) {
533 $checkpicto =
$form->showCheckAddButtons(
'checkforselect', 1);
538 $thirdpartystatic =
new Societe($db);
539 $facture_static =
new Facture($db);
541 $product_static =
new Product($db);
544 $accountingaccount_codetotid_cache = array();
546 while ($i < min($num_lines, $limit)) {
547 $objp = $db->fetch_object($result);
556 $thirdpartystatic->id = $objp->socid;
557 $thirdpartystatic->name = $objp->name;
558 $thirdpartystatic->client = $objp->client;
559 $thirdpartystatic->fournisseur = $objp->fournisseur;
560 $thirdpartystatic->code_client = $objp->code_client;
561 $thirdpartystatic->code_compta = $objp->code_compta_client;
562 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
563 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
564 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
565 $thirdpartystatic->email = $objp->email;
566 $thirdpartystatic->country_code = $objp->country_code;
567 $thirdpartystatic->tva_intra = $objp->tva_intra;
568 $thirdpartystatic->code_compta_product = $objp->company_code_sell;
570 $product_static->ref = $objp->product_ref;
571 $product_static->id = $objp->product_id;
572 $product_static->type = $objp->type;
573 $product_static->label = $objp->product_label;
574 $product_static->status = $objp->status;
575 $product_static->status_buy = $objp->status_buy;
576 $product_static->accountancy_code_sell = $objp->code_sell;
577 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
578 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
579 $product_static->accountancy_code_buy = $objp->code_buy;
580 $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
581 $product_static->accountancy_code_buy_export = $objp->code_buy_export;
582 $product_static->tva_tx = $objp->tva_tx_prod;
584 $facture_static->ref = $objp->ref;
585 $facture_static->id = $objp->facid;
586 $facture_static->type = $objp->ftype;
587 $facture_static->date = $db->jdate($objp->datef);
588 $facture_static->fk_facture_source = $objp->fk_facture_source;
590 $facture_static_det->id = $objp->rowid;
591 $facture_static_det->total_ht = $objp->total_ht;
592 $facture_static_det->tva_tx = $objp->tva_tx_line;
593 $facture_static_det->vat_src_code = $objp->vat_src_code;
594 $facture_static_det->product_type = $objp->type_l;
595 $facture_static_det->desc = $objp->description;
597 $accountingAccountArray = array(
598 'dom'=>$objp->aarowid,
599 'intra'=>$objp->aarowid_intra,
600 'export'=>$objp->aarowid_export,
601 'thirdparty' =>$objp->aarowid_thirdparty);
603 $code_sell_p_notset =
'';
604 $code_sell_t_notset =
'';
608 $return=$accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray,
'customer');
609 if (!is_array($return) && $return<0) {
612 $suggestedid=$return[
'suggestedid'];
613 $suggestedaccountingaccountfor=$return[
'suggestedaccountingaccountfor'];
614 $suggestedaccountingaccountbydefaultfor=$return[
'suggestedaccountingaccountbydefaultfor'];
615 $code_sell_l=$return[
'code_l'];
616 $code_sell_p=$return[
'code_p'];
617 $code_sell_t=$return[
'code_t'];
621 if (!empty($code_sell_p)) {
624 $code_sell_p_notset =
'color:orange';
626 if (empty($code_sell_l) && empty($code_sell_p)) {
627 $code_sell_p_notset =
'color:red';
629 if ($suggestedaccountingaccountfor ==
'eecwithoutvatnumber' && empty($code_sell_p_notset)) {
630 $code_sell_p_notset =
'color:orange';
638 print
'<tr class="oddeven">';
641 print
'<td>'.$facture_static_det->id.
'</td>';
644 print
'<td class="nowraponall">'.$facture_static->getNomUrl(1).
'</td>';
646 print
'<td class="center">'.dol_print_date($facture_static->date,
'day').
'</td>';
649 print
'<td class="tdoverflowmax100">';
650 if ($product_static->id > 0) {
651 print $product_static->getNomUrl(1);
653 if ($product_static->label) {
654 print
'<br><span class="opacitymedium small">'.dol_escape_htmltag($product_static->label).
'</span>';
659 print
'<td class="tdoverflowonsmartphone small">';
661 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
662 print
$form->textwithtooltip(
dol_trunc($text, $trunclength), $facture_static_det->desc);
666 print
'<td class="right nowraponall amount">';
669 $situation_ratio = 1;
671 if ($objp->situation_cycle_ref) {
673 if ($objp->situation_percent == 0) {
674 $situation_ratio = 0;
677 $line->fetch($objp->rowid);
680 $prev_progress = $line->get_prev_progress($objp->facid);
682 $situation_ratio = ($objp->situation_percent - $prev_progress) / $objp->situation_percent;
685 print
price($objp->total_ht * $situation_ratio);
687 print
price($objp->total_ht);
692 $code_vat_differ =
'';
693 if ($product_static->tva_tx !== $facture_static_det->tva_tx &&
price2num($product_static->tva_tx) &&
price2num($facture_static_det->tva_tx)) {
694 $code_vat_differ =
'warning bold';
696 print
'<td class="right'.($code_vat_differ?
' '.$code_vat_differ:
'').
'">';
697 print
vatrate($facture_static_det->tva_tx.($facture_static_det->vat_src_code ?
' ('.$facture_static_det->vat_src_code.
')' :
''));
701 print
'<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1,
'customer').
'</td>';
704 $labelcountry = ($objp->country_code && ($langs->trans(
"Country".$objp->country_code) !=
"Country".$objp->country_code)) ? $langs->trans(
"Country".$objp->country_code) : $objp->country_label;
705 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labelcountry).
'">';
710 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).
'">'.
dol_escape_htmltag($objp->tva_intra).
'</td>';
713 print
'<td class="small">';
715 $s =
'1. '.(($facture_static_det->product_type == 1) ? $langs->trans(
"DefaultForService") : $langs->trans(
"DefaultForProduct")).
': ';
716 $shelp =
''; $ttype =
'help';
717 if ($suggestedaccountingaccountbydefaultfor ==
'eec') {
718 $shelp .= $langs->trans(
"SaleEEC");
719 } elseif ($suggestedaccountingaccountbydefaultfor ==
'eecwithvat') {
720 $shelp = $langs->trans(
"SaleEECWithVAT");
721 } elseif ($suggestedaccountingaccountbydefaultfor ==
'eecwithoutvatnumber') {
722 $shelp = $langs->trans(
"SaleEECWithoutVATNumber");
724 } elseif ($suggestedaccountingaccountbydefaultfor ==
'export') {
725 $shelp .= $langs->trans(
"SaleExport");
727 $s .= ($code_sell_l > 0 ?
length_accountg($code_sell_l) :
'<span style="'.$code_sell_p_notset.
'">'.$langs->trans(
"NotDefined").
'</span>');
728 print
$form->textwithpicto($s, $shelp, 1, $ttype,
'', 0, 2,
'', 1);
730 if ($product_static->id > 0) {
732 $s =
'2. '.(($facture_static_det->product_type == 1) ? $langs->trans(
"ThisService") : $langs->trans(
"ThisProduct")).
': ';
733 $shelp =
''; $ttype =
'help';
734 if ($suggestedaccountingaccountfor ==
'eec') {
735 $shelp = $langs->trans(
"SaleEEC");
736 } elseif ($suggestedaccountingaccountfor ==
'eecwithvat') {
737 $shelp = $langs->trans(
"SaleEECWithVAT");
738 } elseif ($suggestedaccountingaccountfor ==
'eecwithoutvatnumber') {
739 $shelp = $langs->trans(
"SaleEECWithoutVATNumber");
741 } elseif ($suggestedaccountingaccountfor ==
'export') {
742 $shelp = $langs->trans(
"SaleExport");
744 $s .= (empty($code_sell_p) ?
'<span style="'.$code_sell_p_notset.
'">'.$langs->trans(
"NotDefined").
'</span>' :
length_accountg($code_sell_p));
745 print
$form->textwithpicto($s, $shelp, 1, $ttype,
'', 0, 2,
'', 1);
748 $s =
'2. '.(($objp->type_l == 1) ? $langs->trans(
"ThisService") : $langs->trans(
"ThisProduct")).
': ';
750 $s .= $langs->trans(
"NotDefined");
751 print
$form->textwithpicto($s, $shelp, 1,
'help',
'', 0, 2,
'', 1);
753 if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
755 $s =
'3. '.(($facture_static_det->product_type == 1) ? $langs->trans(
"ServiceForThisThirdparty") : $langs->trans(
"ProductForThisThirdparty")).
': ';
757 $s .= ($code_sell_t > 0 ?
length_accountg($code_sell_t) :
'<span style="'.$code_sell_t_notset.
'">'.$langs->trans(
"NotDefined").
'</span>');
758 print
$form->textwithpicto($s, $shelp, 1,
'help',
'', 0, 2,
'', 1);
764 print $formaccounting->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($objp->rowid.
"_".$i, $toselect)) ? $default_account : $suggestedid,
'codeventil'.$facture_static_det->id, 1, array(), 0, 0,
'codeventil maxwidth150 maxwidthonsmartphone',
'cachewithshowemptyone');
768 print
'<td class="center">';
770 if (!empty($suggestedid) && $suggestedaccountingaccountfor !=
'' && $suggestedaccountingaccountfor !=
'eecwithoutvatnumber') {
774 if (!empty($toselect)) {
776 if (in_array($objp->rowid.
"_".$i, $toselect)) {
781 print
'<input type="checkbox" class="flat checkforselect checkforselect'.$facture_static_det->id.
'" name="toselect[]" value="'.$facture_static_det->id.
"_".$i.
'"'.($ischecked ?
" checked" :
"").
'/>';
787 if ($num_lines == 0) {
788 print
'<tr><td colspan="13"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
798 if ($db->type ==
'mysqli') {
799 $db->query(
"SET SQL_BIG_SELECTS=0");
803 print
'<script type="text/javascript">
804 jQuery(document).ready(function() {
805 jQuery(".codeventil").change(function() {
806 var s=$(this).attr("id").replace("codeventil", "")
807 console.log(s+" "+$(this).val());
808 if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
809 else jQuery(".checkforselect"+s).prop("checked", true);