28 require
'../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.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(
"bills",
"companies",
"compta",
"accountancy",
"other",
"productbatch",
"products"));
43 $action =
GETPOST(
'action',
'aZ09');
44 $massaction =
GETPOST(
'massaction',
'alpha');
45 $show_files =
GETPOST(
'show_files',
'int');
46 $confirm =
GETPOST(
'confirm',
'alpha');
47 $toselect =
GETPOST(
'toselect',
'array');
50 $mesCasesCochees =
GETPOST(
'toselect',
'array');
53 $search_societe =
GETPOST(
'search_societe',
'alpha');
54 $search_lineid =
GETPOST(
'search_lineid',
'int');
55 $search_ref =
GETPOST(
'search_ref',
'alpha');
56 $search_invoice =
GETPOST(
'search_invoice',
'alpha');
57 $search_label =
GETPOST(
'search_label',
'alpha');
58 $search_desc =
GETPOST(
'search_desc',
'alpha');
59 $search_amount =
GETPOST(
'search_amount',
'alpha');
60 $search_account =
GETPOST(
'search_account',
'alpha');
61 $search_vat =
GETPOST(
'search_vat',
'alpha');
62 $search_day =
GETPOST(
"search_day",
"int");
63 $search_month =
GETPOST(
"search_month",
"int");
64 $search_year =
GETPOST(
"search_year",
"int");
65 $search_country =
GETPOST(
'search_country',
'alpha');
66 $search_tvaintra =
GETPOST(
'search_tvaintra',
'alpha');
68 $btn_ventil =
GETPOST(
'ventil',
'alpha');
71 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
72 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
73 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
75 if (empty($page) || $page < 0) { $page = 0; }
76 $offset = $limit * $page;
77 $pageprev = $page - 1;
78 $pagenext = $page + 1;
80 $sortfield =
"f.datef, f.ref, l.rowid";
82 if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
90 if (!$user->rights->accounting->bind->write)
94 $hookmanager->initHooks(array(
'accountancycustomerlist'));
98 $chartaccountcode =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
105 if (
GETPOST(
'cancel',
'alpha')) { $action =
'list'; $massaction =
''; }
106 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') { $massaction =
''; }
108 $parameters = array();
109 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
110 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
115 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha'))
117 $search_societe =
'';
120 $search_invoice =
'';
124 $search_account =
'';
129 $search_country =
'';
130 $search_tvaintra =
'';
134 $objectclass =
'AccountingAccount';
135 $permissiontoread = $user->rights->accounting->read;
136 $permissiontodelete = $user->rights->accounting->delete;
137 $uploaddir = $conf->accounting->dir_output;
138 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
142 if ($massaction ==
'ventil') {
146 if (!empty($mesCasesCochees)) {
147 $msg =
'<div>'.$langs->trans(
"SelectedLines").
': '.count($mesCasesCochees).
'</div>';
148 $msg .=
'<div class="detail">';
153 foreach ($mesCasesCochees as $maLigneCochee) {
154 $maLigneCourante = explode(
"_", $maLigneCochee);
155 $monId = $maLigneCourante[0];
156 $monCompte =
GETPOST(
'codeventil'.$monId);
160 $msg .=
'<div><span style="color:red">'.$langs->trans(
"Lineofinvoice", $monId).
' - '.$langs->trans(
"NoAccountSelected").
'</span></div>';
163 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"facturedet";
164 $sql .=
" SET fk_code_ventilation = ".((int) $monCompte);
165 $sql .=
" WHERE rowid = ".((int) $monId);
168 $accountventilated->fetch($monCompte,
'', 1);
170 dol_syslog(
"accountancy/customer/list.php sql=".$sql, LOG_DEBUG);
171 if ($db->query($sql)) {
172 $msg .=
'<div><span style="color:green">'.$langs->trans(
"Lineofinvoice", $monId).
' - '.$langs->trans(
"VentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'</span></div>';
175 $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>';
183 $msg .=
'<div>'.$langs->trans(
"EndProcessing").
'</div>';
193 $form =
new Form($db);
196 llxHeader(
'', $langs->trans(
"Ventilation"));
198 if (empty($chartaccountcode))
200 print $langs->trans(
"ErrorChartOfAccountSystemNotSelected");
208 $sql =
"SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype,";
209 $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,";
210 $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,";
211 $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,";
212 $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,";
213 $sql .=
" p.tosell as status, p.tobuy as status_buy,";
214 $sql .=
" aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export,";
215 $sql .=
" co.code as country_code, co.label as country_label,";
216 $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";
217 $parameters = array();
218 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
219 $sql .= $hookmanager->resPrint;
220 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
221 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
222 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
223 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facturedet as l ON f.rowid = l.fk_facture";
224 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = l.fk_product";
225 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON p.accountancy_code_sell = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa.entity = ".$conf->entity;
226 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa2 ON p.accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa2.entity = ".$conf->entity;
227 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa3 ON p.accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa3.entity = ".$conf->entity;
228 $sql .=
" WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
229 $sql .=
" AND l.product_type <= 2";
231 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
232 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
235 if ($search_societe) {
238 if ($search_lineid) {
241 if (strlen(trim($search_invoice))) {
244 if (strlen(trim($search_ref))) {
247 if (strlen(trim($search_label))) {
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 $sql .=
dolSqlDateFilter(
'f.datef', $search_day, $search_month, $search_year);
263 if (strlen(trim($search_country))) {
265 $country_code_in_EEC = $country_code_in_EEC_without_me =
'';
266 foreach ($arrayofcode as $key => $value)
268 $country_code_in_EEC .= ($country_code_in_EEC ?
"," :
"").
"'".$value.
"'";
269 if ($value != $mysoc->country_code) $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ?
"," :
"").
"'".$value.
"'";
271 if ($search_country ==
'special_allnotme') $sql .=
" AND co.code <> '".$db->escape($mysoc->country_code).
"'";
272 elseif ($search_country ==
'special_eec') $sql .= " AND co.
code IN (".$country_code_in_EEC.")";
273 elseif ($search_country == 'special_eecnotme') $sql .= " AND co.
code IN (".$country_code_in_EEC_without_me.")";
274 elseif ($search_country == 'special_noteec') $sql .= " AND co.
code NOT IN (".$country_code_in_EEC.")";
277 if (strlen(trim($search_tvaintra))) {
280 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
285 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
288 $parameters = array();
289 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
290 $sql .= $hookmanager->resPrint;
292 $sql .= $db->order($sortfield, $sortorder);
295 $nbtotalofrecords =
'';
296 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
298 $result = $db->query($sql);
299 $nbtotalofrecords = $db->num_rows($result);
300 if (($page * $limit) > $nbtotalofrecords)
307 $sql .= $db->plimit($limit + 1, $offset);
309 dol_syslog(
"accountancy/customer/list.php", LOG_DEBUG);
312 if ($db->type ==
'mysqli') {
313 $db->query(
"SET SQL_BIG_SELECTS=1");
315 $result = $db->query($sql);
317 $num_lines = $db->num_rows($result);
320 $arrayofselected = is_array($toselect) ? $toselect : array();
323 if (!empty($contextpage) && $contextpage !=
$_SERVER[
"PHP_SELF"]) $param .=
'&contextpage='.urlencode($contextpage);
324 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
325 if ($search_societe) $param .=
'&search_societe='.urlencode($search_societe);
326 if ($search_lineid) $param .=
'&search_lineid='.urlencode($search_lineid);
327 if ($search_day) $param .=
'&search_day='.urlencode($search_day);
328 if ($search_month) $param .=
'&search_month='.urlencode($search_month);
329 if ($search_year) $param .=
'&search_year='.urlencode($search_year);
330 if ($search_invoice) $param .=
'&search_invoice='.urlencode($search_invoice);
331 if ($search_ref) $param .=
'&search_ref='.urlencode($search_ref);
332 if ($search_desc) $param .=
'&search_desc='.urlencode($search_desc);
333 if ($search_amount) $param .=
'&search_amount='.urlencode($search_amount);
334 if ($search_vat) $param .=
'&search_vat='.urlencode($search_vat);
335 if ($search_country) $param .=
"&search_country=".urlencode($search_country);
336 if ($search_tvaintra) $param .=
"&search_tvaintra=".urlencode($search_tvaintra);
338 $arrayofmassactions = array(
339 'ventil'=>$langs->trans(
"Ventilate")
345 $massactionbutton = $form->selectMassAction(
'ventil', $arrayofmassactions, 1);
347 print '<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
348 print '<input type="hidden" name="action" value="ventil">';
349 if ($optioncss !=
'')
print '<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
350 print '<input type="hidden" name="token" value="'.newToken().
'">';
351 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
352 print '<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
353 print '<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
354 print '<input type="hidden" name="page" value="'.$page.
'">';
356 print_barre_liste($langs->trans(
"InvoiceLines"), $page,
$_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
358 print '<span class="opacitymedium">'.$langs->trans(
"DescVentilTodoCustomer").
'</span></br><br>';
360 if ($msg)
print $msg.
'<br>';
364 print '<div class="div-table-responsive">';
365 print '<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
368 print '<tr class="liste_titre_filter">';
369 print
'<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).
'"></td>';
370 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).
'"></td>';
371 print
'<td class="liste_titre center nowraponall minwidth100imp">';
372 if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
373 print
'<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_day" value="'.$search_day.
'">';
375 print
'<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month" value="'.$search_month.
'">';
376 $formother->select_year($search_year,
'search_year', 1, 20, 5);
378 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
380 print
'<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
381 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
382 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>';
383 print
'<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'"></td>';
384 print
'<td class="liste_titre">';
385 print $form->select_country($search_country,
'search_country',
'', 0,
'maxwidth125',
'code2', 1, 0, 1);
388 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).
'"></td>';
389 print
'<td class="liste_titre"></td>';
390 print
'<td class="liste_titre"></td>';
391 print
'<td class="center liste_titre">';
392 $searchpicto = $form->showFilterButtons();
397 print
'<tr class="liste_titre">';
400 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"f.datef, f.ref, l.rowid",
"", $param,
'', $sortfield, $sortorder,
'center ');
403 print_liste_field_titre(
"ProductDescription", $_SERVER[
"PHP_SELF"],
"l.description",
"", $param,
'', $sortfield, $sortorder);
404 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"l.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right maxwidth50 ');
405 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"l.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
408 print_liste_field_titre(
"VATIntraShort", $_SERVER[
"PHP_SELF"],
"s.tva_intra",
"", $param,
'', $sortfield, $sortorder);
412 if ($massactionbutton) $checkpicto = $form->showCheckAddButtons(
'checkforselect', 1);
416 $thirdpartystatic =
new Societe($db);
417 $facture_static =
new Facture($db);
418 $product_static =
new Product($db);
420 $isSellerInEEC =
isInEEC($mysoc);
422 $accountingaccount_codetotid_cache = array();
424 while ($i < min($num_lines, $limit)) {
425 $objp = $db->fetch_object($result);
427 $objp->code_sell_l =
'';
428 $objp->code_sell_p =
'';
430 $thirdpartystatic->id = $objp->socid;
431 $thirdpartystatic->name = $objp->name;
432 $thirdpartystatic->client = $objp->client;
433 $thirdpartystatic->fournisseur = $objp->fournisseur;
434 $thirdpartystatic->code_client = $objp->code_client;
435 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
436 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
437 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
438 $thirdpartystatic->email = $objp->email;
439 $thirdpartystatic->country_code = $objp->country_code;
441 $product_static->ref = $objp->product_ref;
442 $product_static->id = $objp->product_id;
443 $product_static->type = $objp->type;
444 $product_static->label = $objp->product_label;
445 $product_static->status = $objp->status;
446 $product_static->status_buy = $objp->status_buy;
447 $product_static->accountancy_code_sell = $objp->code_sell;
448 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
449 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
450 $product_static->accountancy_code_buy = $objp->code_buy;
451 $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
452 $product_static->accountancy_code_buy_export = $objp->code_buy_export;
454 $facture_static->ref = $objp->ref;
455 $facture_static->id = $objp->facid;
456 $facture_static->type = $objp->ftype;
458 $code_sell_p_notset =
'';
459 $objp->aarowid_suggest =
'';
461 $isBuyerInEEC =
isInEEC($objp);
464 $suggestedaccountingaccountbydefaultfor =
'';
465 if ($objp->type_l == 1) {
466 if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) {
467 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT :
'');
468 $suggestedaccountingaccountbydefaultfor =
'';
470 if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) {
471 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT :
'');
472 $suggestedaccountingaccountbydefaultfor =
'eecwithvat';
473 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) {
474 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT :
'');
475 $suggestedaccountingaccountbydefaultfor =
'eecwithoutvatnumber';
476 } elseif ($isSellerInEEC && $isBuyerInEEC) {
477 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT :
'');
478 $suggestedaccountingaccountbydefaultfor =
'eec';
480 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT :
'');
481 $suggestedaccountingaccountbydefaultfor =
'export';
484 } elseif ($objp->type_l == 0) {
485 if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) {
486 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT :
'');
487 $suggestedaccountingaccountbydefaultfor =
'';
489 if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) {
490 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT :
'');
491 $suggestedaccountingaccountbydefaultfor =
'eecwithvat';
492 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) {
493 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT :
'');
494 $suggestedaccountingaccountbydefaultfor =
'eecwithoutvatnumber';
495 } elseif ($isSellerInEEC && $isBuyerInEEC) {
496 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT :
'');
497 $suggestedaccountingaccountbydefaultfor =
'eec';
499 $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT :
'');
500 $suggestedaccountingaccountbydefaultfor =
'export';
504 if ($objp->code_sell_l == -1) $objp->code_sell_l =
'';
507 $suggestedaccountingaccountfor =
'';
508 if (($objp->country_code == $mysoc->country_code) || empty($objp->country_code)) {
509 $objp->code_sell_p = $objp->code_sell;
510 $objp->aarowid_suggest = $objp->aarowid;
511 $suggestedaccountingaccountfor =
'';
513 if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) {
514 $objp->code_sell_p = $objp->code_sell;
515 $objp->aarowid_suggest = $objp->aarowid;
516 $suggestedaccountingaccountfor =
'eecwithvat';
517 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) {
518 $objp->code_sell_p = $objp->code_sell;
519 $objp->aarowid_suggest = $objp->aarowid;
520 $suggestedaccountingaccountfor =
'eecwithoutvatnumber';
521 } elseif ($isSellerInEEC && $isBuyerInEEC) {
522 $objp->code_sell_p = $objp->code_sell_intra;
523 $objp->aarowid_suggest = $objp->aarowid_intra;
524 $suggestedaccountingaccountfor =
'eec';
526 $objp->code_sell_p = $objp->code_sell_export;
527 $objp->aarowid_suggest = $objp->aarowid_export;
528 $suggestedaccountingaccountfor =
'export';
533 if ($objp->description ==
"(DEPOSIT)") {
535 $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1);
536 $objp->code_sell_l = $accountdeposittoventilated->ref;
537 $objp->aarowid_suggest = $accountdeposittoventilated->rowid;
540 if (!empty($objp->code_sell_p)) {
543 $code_sell_p_notset =
'color:orange';
545 if (empty($objp->code_sell_l) && empty($objp->code_sell_p)) $code_sell_p_notset =
'color:red';
546 if ($suggestedaccountingaccountfor ==
'eecwithoutvatnumber' && empty($code_sell_p_notset)) $code_sell_p_notset =
'color:orange';
551 print
'<tr class="oddeven">';
554 print
'<td>'.$objp->rowid.
'</td>';
557 print
'<td class="nowraponall">'.$facture_static->getNomUrl(1).
'</td>';
559 print
'<td class="center">'.dol_print_date($db->jdate($objp->datef),
'day').
'</td>';
562 print
'<td class="tdoverflowmax150">';
563 if ($product_static->id > 0) {
564 print $product_static->getNomUrl(1);
566 if ($objp->product_label) print
'<br><span class="opacitymedium small">'.$objp->product_label.
'</span>';
569 print
'<td class="tdoverflowonsmartphone small">';
571 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
572 print $form->textwithtooltip(
dol_trunc($text, $trunclength), $objp->description);
575 print
'<td class="nowrap right">';
576 print
price($objp->total_ht);
580 if ($objp->vat_tx_l != $objp->vat_tx_p)
581 $code_vat_differ =
'font-weight:bold; text-decoration:blink; color:red';
582 print
'<td style="'.$code_vat_differ.
'" class="right">';
583 print
vatrate($objp->tva_tx_line.($objp->vat_src_code ?
' ('.$objp->vat_src_code.
')' :
''));
587 print
'<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1,
'customer').
'</td>';
591 $labelcountry = ($objp->country_code && ($langs->trans(
"Country".$objp->country_code) !=
"Country".$objp->country_code)) ? $langs->trans(
"Country".$objp->country_code) : $objp->country_label;
595 print
'<td>'.$objp->tva_intra.
'</td>';
599 $s =
'<span class="small">'.(($objp->type_l == 1) ? $langs->trans(
"DefaultForService") : $langs->trans(
"DefaultForProduct")).
': </span>';
601 if ($suggestedaccountingaccountbydefaultfor ==
'eec') $shelp .= $langs->trans(
"SaleEEC");
602 elseif ($suggestedaccountingaccountbydefaultfor ==
'export') $shelp .= $langs->trans("SaleExport");
603 $s .= ($objp->code_sell_l > 0 ?
length_accountg($objp->code_sell_l) : '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>');
604 print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
605 if ($objp->product_id > 0)
608 $s =
'<span class="small">'.(($objp->type_l == 1) ? $langs->trans(
"ThisService") : $langs->trans(
"ThisProduct")).
': </span>';
609 $shelp =
''; $ttype =
'help';
610 if ($suggestedaccountingaccountfor ==
'eec') $shelp = $langs->trans(
"SaleEEC");
611 elseif ($suggestedaccountingaccountfor ==
'eecwithvat') $shelp = $langs->trans("SaleEECWithVAT");
612 elseif ($suggestedaccountingaccountfor == 'eecwithoutvatnumber') {
613 $shelp = $langs->trans(
"SaleEECWithoutVATNumber");
616 elseif ($suggestedaccountingaccountfor ==
'export') $shelp = $langs->trans("SaleExport");
617 $s .= (empty($objp->code_sell_p) ? '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>' :
length_accountg($objp->code_sell_p));
618 print $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
625 $suggestedid = $objp->aarowid_suggest;
629 if (empty($suggestedid) && empty($objp->code_sell_p) && !empty($objp->code_sell_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC))
631 if (empty($accountingaccount_codetotid_cache[$objp->code_sell_l]))
634 $tmpaccount->fetch(0, $objp->code_sell_l, 1);
635 if ($tmpaccount->id > 0) {
636 $suggestedid = $tmpaccount->id;
638 $accountingaccount_codetotid_cache[$objp->code_sell_l] = $tmpaccount->id;
640 $suggestedid = $accountingaccount_codetotid_cache[$objp->code_sell_l];
643 print $formaccounting->select_account($suggestedid,
'codeventil'.$objp->rowid, 1, array(), 0, 0,
'codeventil maxwidth200 maxwidthonsmartphone',
'cachewithshowemptyone');
647 print
'<td class="center">';
649 $ischecked = $objp->aarowid_suggest;
650 if ($suggestedaccountingaccountfor ==
'eecwithoutvatnumber') $ischecked = 0;
651 print
'<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.
'" name="toselect[]" value="'.$objp->rowid.
"_".$i.
'"'.($ischecked ?
"checked" :
"").
'/>';
664 if ($db->type ==
'mysqli') {
665 $db->query(
"SET SQL_BIG_SELECTS=0");
669 print
'<script type="text/javascript" language="javascript">
670 jQuery(document).ready(function() {
671 jQuery(".codeventil").change(function() {
672 var s=$(this).attr("id").replace("codeventil", "")
673 console.log(s+" "+$(this).val());
674 if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
675 else jQuery(".checkforselect"+s).prop("checked", true);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
Class to manage products or services.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_SITUATION
Situation invoice.
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...
const TYPE_CREDIT_NOTE
Credit note invoice.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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...
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
print $_SERVER["PHP_SELF"]
Edit parameters.
const TYPE_DEPOSIT
Deposit invoice.
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
print
Draft customers invoices.
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.
Class to manage accounting accounts.
Class to manage invoices.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)