27 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
40 $langs->loadLangs(array(
"bills",
"compta",
"accountancy",
"productbatch",
"products"));
42 $optioncss =
GETPOST(
'optioncss',
'aZ');
44 $account_parent =
GETPOST(
'account_parent');
45 $changeaccount =
GETPOST(
'changeaccount');
47 $search_societe =
GETPOST(
'search_societe',
'alpha');
48 $search_lineid =
GETPOST(
'search_lineid',
'int');
49 $search_ref =
GETPOST(
'search_ref',
'alpha');
50 $search_invoice =
GETPOST(
'search_invoice',
'alpha');
51 $search_label =
GETPOST(
'search_label',
'alpha');
52 $search_desc =
GETPOST(
'search_desc',
'alpha');
53 $search_amount =
GETPOST(
'search_amount',
'alpha');
54 $search_account =
GETPOST(
'search_account',
'alpha');
55 $search_vat =
GETPOST(
'search_vat',
'alpha');
56 $search_day =
GETPOST(
"search_day",
"int");
57 $search_month =
GETPOST(
"search_month",
"int");
58 $search_year =
GETPOST(
"search_year",
"int");
59 $search_country =
GETPOST(
'search_country',
'alpha');
60 $search_tvaintra =
GETPOST(
'search_tvaintra',
'alpha');
63 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
64 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
65 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
67 if (empty($page) || $page < 0) $page = 0;
68 $offset = $limit * $page;
69 $pageprev = $page - 1;
70 $pagenext = $page + 1;
72 $sortfield =
"f.datef, f.ref, fd.rowid";
74 if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
82 if (!$user->rights->accounting->bind->write)
93 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha'))
102 $search_account =
'';
107 $search_country =
'';
108 $search_tvaintra =
'';
111 if (is_array($changeaccount) && count($changeaccount) > 0) {
114 if (!(
GETPOST(
'account_parent',
'int') >= 0))
117 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Account")), null,
'errors');
124 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet as l";
125 $sql1 .=
" SET l.fk_code_ventilation=".(GETPOST(
'account_parent',
'int') > 0 ?
GETPOST(
'account_parent',
'int') :
'0');
126 $sql1 .=
' WHERE l.rowid IN ('.implode(
',', $changeaccount).
')';
128 dol_syslog(
'accountancy/customer/lines.php::changeaccount sql= '.$sql1);
129 $resql1 = $db->query($sql1);
142 $account_parent =
'';
151 $form =
new Form($db);
154 llxHeader(
'', $langs->trans(
"CustomersVentilation").
' - '.$langs->trans(
"Dispatched"));
156 print '<script type="text/javascript">
158 $(\'#select-all\').click(function(event) {
159 // Iterate each checkbox
160 $(\':checkbox\').each(function() {
164 $(\'#unselect-all\').click(function(event) {
165 // Iterate each checkbox
166 $(\':checkbox\').each(function() {
167 this.checked = false;
176 $sql =
"SELECT f.rowid as facid, f.ref as ref, f.type, f.datef, f.ref_client,";
177 $sql .=
" fd.rowid, fd.description, fd.product_type as line_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.vat_src_code, fd.total_ttc,";
178 $sql .=
" s.rowid as socid, s.nom as name, s.code_compta, s.code_client,";
179 $sql .=
" p.rowid as product_id, p.fk_product_type as product_type, p.ref as product_ref, p.label as product_label, p.tobuy, p.tosell,";
180 $sql .=
" p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
181 $sql .=
" aa.rowid as fk_compte, aa.account_number, aa.label, aa.labelshort,";
182 $sql .=
" fd.situation_percent,";
183 $sql .=
" co.code as country_code, co.label as country,";
184 $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";
185 $parameters = array();
186 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
187 $sql .= $hookmanager->resPrint;
188 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
189 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
190 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
191 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
192 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
193 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
194 $sql .=
" WHERE fd.fk_code_ventilation > 0";
195 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
196 $sql .=
" AND f.fk_statut > 0";
197 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
203 if ($search_societe) {
206 if ($search_lineid) {
209 if (strlen(trim($search_invoice))) {
212 if (strlen(trim($search_ref))) {
215 if (strlen(trim($search_label))) {
218 if (strlen(trim($search_desc))) {
221 if (strlen(trim($search_amount))) {
224 if (strlen(trim($search_account))) {
227 if (strlen(trim($search_vat))) {
230 $sql .=
dolSqlDateFilter(
'f.datef', $search_day, $search_month, $search_year);
231 if (strlen(trim($search_country))) {
233 $country_code_in_EEC = $country_code_in_EEC_without_me =
'';
234 foreach ($arrayofcode as $key => $value)
236 $country_code_in_EEC .= ($country_code_in_EEC ?
"," :
"").
"'".$value.
"'";
237 if ($value != $mysoc->country_code) $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ?
"," :
"").
"'".$value.
"'";
239 if ($search_country ==
'special_allnotme') $sql .=
" AND co.code <> '".$db->escape($mysoc->country_code).
"'";
240 elseif ($search_country ==
'special_eec') $sql .= " AND co.
code IN (".$country_code_in_EEC.")";
241 elseif ($search_country == 'special_eecnotme') $sql .= " AND co.
code IN (".$country_code_in_EEC_without_me.")";
242 elseif ($search_country == 'special_noteec') $sql .= " AND co.
code NOT IN (".$country_code_in_EEC.")";
245 if (strlen(trim($search_tvaintra))) {
248 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
249 $sql .= $db->order($sortfield, $sortorder);
252 $nbtotalofrecords =
'';
253 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
255 $result = $db->query($sql);
256 $nbtotalofrecords = $db->num_rows($result);
257 if (($page * $limit) > $nbtotalofrecords)
264 $sql .= $db->plimit($limit + 1, $offset);
266 dol_syslog(
"/accountancy/customer/lines.php", LOG_DEBUG);
267 $result = $db->query($sql);
269 $num_lines = $db->num_rows($result);
273 if (!empty($contextpage) && $contextpage !=
$_SERVER[
"PHP_SELF"]) $param .=
'&contextpage='.urlencode($contextpage);
274 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
275 if ($search_societe) $param .=
"&search_societe=".urlencode($search_societe);
276 if ($search_invoice) $param .=
"&search_invoice=".urlencode($search_invoice);
277 if ($search_ref) $param .=
"&search_ref=".urlencode($search_ref);
278 if ($search_label) $param .=
"&search_label=".urlencode($search_label);
279 if ($search_desc) $param .=
"&search_desc=".urlencode($search_desc);
280 if ($search_account) $param .=
"&search_account=".urlencode($search_account);
281 if ($search_vat) $param .=
"&search_vat=".urlencode($search_vat);
282 if ($search_day) $param .=
'&search_day='.urlencode($search_day);
283 if ($search_month) $param .=
'&search_month='.urlencode($search_month);
284 if ($search_year) $param .=
'&search_year='.urlencode($search_year);
285 if ($search_country) $param .=
"&search_country=".urlencode($search_country);
286 if ($search_tvaintra) $param .=
"&search_tvaintra=".urlencode($search_tvaintra);
288 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
289 print
'<input type="hidden" name="action" value="ventil">';
290 if ($optioncss !=
'') print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
291 print
'<input type="hidden" name="token" value="'.newToken().
'">';
292 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
293 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
294 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
295 print
'<input type="hidden" name="page" value="'.$page.
'">';
297 print_barre_liste($langs->trans(
"InvoiceLinesDone"), $page,
$_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num_lines, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
298 print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilDoneCustomer").
'</span><br>';
300 print
'<br><div class="inline-block divButAction">'.$langs->trans(
"ChangeAccount").
'<br>';
301 print $formaccounting->select_account($account_parent,
'account_parent', 2, array(), 0, 0,
'maxwidth300 maxwidthonsmartphone valignmiddle');
302 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"ChangeBinding").
'"/></div>';
306 print
'<div class="div-table-responsive">';
307 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
309 print
'<tr class="liste_titre_filter">';
310 print
'<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).
'"></td>';
311 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).
'"></td>';
312 print
'<td class="liste_titre center nowraponall">';
313 if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
314 print
'<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_day" value="'.dol_escape_htmltag($search_day).
'">';
316 print
'<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month" value="'.dol_escape_htmltag($search_month).
'">';
317 $formother->select_year($search_year,
'search_year', 1, 20, 5);
319 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
321 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
322 print
'<td class="liste_titre right"><input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
323 print
'<td class="liste_titre right"><input type="text" class="right flat maxwidth50" placeholder="%" name="search_vat" size="1" value="'.dol_escape_htmltag($search_vat).
'"></td>';
324 print
'<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'"></td>';
325 print
'<td class="liste_titre">';
326 print $form->select_country($search_country,
'search_country',
'', 0,
'maxwidth150',
'code2', 1, 0, 1);
329 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).
'"></td>';
330 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="'.dol_escape_htmltag($search_account).
'"></td>';
331 print
'<td class="liste_titre center">';
332 $searchpicto = $form->showFilterButtons();
334 print
"</td></tr>\n";
336 print
'<tr class="liste_titre">';
339 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"f.datef, f.ref, fd.rowid",
"", $param,
'', $sortfield, $sortorder,
'center ');
342 print_liste_field_titre(
"ProductDescription", $_SERVER[
"PHP_SELF"],
"fd.description",
"", $param,
'', $sortfield, $sortorder);
343 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"fd.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right ');
344 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"fd.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
347 print_liste_field_titre(
"VATIntra", $_SERVER[
"PHP_SELF"],
"s.tva_intra",
"", $param,
'', $sortfield, $sortorder);
348 print_liste_field_titre(
"AccountAccounting", $_SERVER[
"PHP_SELF"],
"aa.account_number",
"", $param,
'', $sortfield, $sortorder);
349 $checkpicto = $form->showCheckAddButtons();
353 $thirdpartystatic =
new Societe($db);
354 $facturestatic =
new Facture($db);
355 $productstatic =
new Product($db);
359 while ($i < min($num_lines, $limit)) {
360 $objp = $db->fetch_object($result);
362 $facturestatic->ref = $objp->ref;
363 $facturestatic->id = $objp->facid;
364 $facturestatic->type = $objp->ftype;
366 $thirdpartystatic->id = $objp->socid;
367 $thirdpartystatic->name = $objp->name;
368 $thirdpartystatic->client = $objp->client;
369 $thirdpartystatic->fournisseur = $objp->fournisseur;
370 $thirdpartystatic->code_client = $objp->code_client;
371 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
372 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
373 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
374 $thirdpartystatic->email = $objp->email;
375 $thirdpartystatic->country_code = $objp->country_code;
377 $productstatic->ref = $objp->product_ref;
378 $productstatic->id = $objp->product_id;
379 $productstatic->label = $objp->product_label;
380 $productstatic->type = $objp->line_type;
381 $productstatic->status = $objp->tosell;
382 $productstatic->status_buy = $objp->tobuy;
383 $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
384 $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
385 $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
387 $accountingaccountstatic->rowid = $objp->fk_compte;
388 $accountingaccountstatic->label = $objp->label;
389 $accountingaccountstatic->labelshort = $objp->labelshort;
390 $accountingaccountstatic->account_number = $objp->account_number;
392 print
'<tr class="oddeven">';
395 print
'<td>'.$objp->rowid.
'</td>';
398 print
'<td class="nowraponall">'.$facturestatic->getNomUrl(1).
'</td>';
401 print
'<td class="center">'.dol_print_date($db->jdate($objp->datef),
'day').
'</td>';
404 print
'<td class="tdoverflowmax100">';
405 if ($productstatic->id > 0) print $productstatic->getNomUrl(1);
406 if ($productstatic->id > 0 && $objp->product_label) print
'<br>';
407 if ($objp->product_label) print
'<span class="opacitymedium">'.$objp->product_label.
'</span>';
410 print
'<td class="tdoverflowonsmartphone">';
412 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
413 print $form->textwithtooltip(
dol_trunc($text, $trunclength), $objp->description);
416 print
'<td class="nowrap right">'.price($objp->total_ht).
'</td>';
418 print
'<td class="right">'.vatrate($objp->tva_tx.($objp->vat_src_code ?
' ('.$objp->vat_src_code.
')' :
'')).
'</td>';
421 print
'<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1,
'customer').
'</td>';
425 if ($objp->country_code)
427 print $langs->trans(
"Country".$objp->country_code).
' ('.$objp->country_code.
')';
431 print
'<td>'.$objp->tva_intra.
'</td>';
434 print $accountingaccountstatic->getNomUrl(0, 1, 1,
'', 1);
435 print
' <a class="editfielda" href="./card.php?id='.$objp->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].($param ?
'?'.$param :
'')).
'">';
439 print
'<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="'.$objp->rowid.
'"/></td>';
447 if ($nbtotalofrecords > $limit) {
448 print_barre_liste(
'', $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num_lines, $nbtotalofrecords,
'', 0,
'',
'', $limit, 1);
453 print $db->lasterror();
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.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
const TYPE_STANDARD
Standard invoice.
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.
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) ...
print $_SERVER["PHP_SELF"]
Edit parameters.
const TYPE_DEPOSIT
Deposit invoice.
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
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.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.