31require
'../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
46$langs->loadLangs(array(
'companies',
'bills',
'products',
'supplier_proposal'));
48$action =
GETPOST(
'action',
'aZ');
54$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
55$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
57if (!empty($user->socid)) {
58 $socid = $user->socid;
62$hookmanager->initHooks(array(
'productstatsinvoice'));
66$extrafields->fetch_name_optionals_label(
'facture');
68$search_array_options = $extrafields->getOptionalsFromPost(
'facture',
'',
'search_');
70$showmessage =
GETPOST(
'showmessage');
74$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
75$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
77if (empty($page) || $page == -1) {
80$offset = $limit * $page;
87 $sortfield =
"f.datef";
92$search_date_startday =
GETPOSTINT(
'search_date_startday');
93if (!empty($search_date_startday)) {
94 $option .=
'&search_date_startday='.$search_date_startday;
96$search_date_startmonth =
GETPOSTINT(
'search_date_startmonth');
97if (!empty($search_date_startmonth)) {
98 $option .=
'&search_date_startmonth='.$search_date_startmonth;
100$search_date_startyear =
GETPOSTINT(
'search_date_startyear');
101if (!empty($search_date_startyear)) {
102 $option .=
'&search_date_startyear='.$search_date_startyear;
104$search_date_endday =
GETPOSTINT(
'search_date_endday');
105if (!empty($search_date_endday)) {
106 $option .=
'&search_date_endday='.$search_date_endday;
108$search_date_endmonth =
GETPOSTINT(
'search_date_endmonth');
109if (!empty($search_date_endmonth)) {
110 $option .=
'&search_date_endmonth='.$search_date_endmonth;
112$search_date_endyear =
GETPOSTINT(
'search_date_endyear');
113if (!empty($search_date_endyear)) {
114 $option .=
'&search_date_endyear='.$search_date_endyear;
116$search_date_start =
dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
117$search_date_end =
dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
119if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
120 $search_date_startday =
'';
121 $search_date_startmonth =
'';
122 $search_date_startyear =
'';
123 $search_date_endday =
'';
124 $search_date_endmonth =
'';
125 $search_date_endyear =
'';
126 $search_date_start =
'';
127 $search_date_end =
'';
130$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
137$toselect =
GETPOST(
'toselect',
'array:int');
138$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'invoicelist';
139$massaction =
GETPOST(
'massaction',
'alpha');
140$diroutputmassaction =
$conf->invoice->dir_output.
'/temp/massgeneration/'.$user->id;
142if (
GETPOST(
'cancel',
'alpha')) {
146if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
150 'f.ref' => array(
'label' =>
"Ref",
'checked' =>
'1',
'position' => 5),
151 's.nom' => array(
'label' =>
"ThirdParty",
'checked' =>
'1',
'position' => 50),
152 's.code_client' => array(
'label' =>
"CustomerCodeShort",
'checked' =>
'-1',
'position' => 52),
153 'f.datef' => array(
'label' =>
"DateInvoice",
'checked' =>
'1',
'position' => 60),
154 'd.qty' => array(
'label' =>
"Qty",
'checked' =>
'1',
'position' => 65),
155 'd.total_ht' => array(
'label' =>
"AmountHT",
'checked' =>
'1',
'position' => 70),
156 'f.fk_statut' => array(
'label' =>
"Status",
'checked' =>
'1',
'position' => 1000),
167$arrayofmassactions = array(
168 'presend' =>
img_picto(
'',
'email',
'class="pictofixedwidth"').$langs->trans(
"SendByMail"),
170$massactionbutton = $form->selectMassAction(
'', $arrayofmassactions);
171$arrayofselected = is_array($toselect) ? $toselect : array();
172$selectedfields = (count($arrayofmassactions) ? $form->showCheckAddButtons(
'checkforselect', 1) :
'');
178$parameters = array(
'socid' => $socid,
'arrayfields' => &$arrayfields);
179$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
183if (empty($reshook)) {
184 $objectclass =
'Facture';
185 $objectlabel =
'Invoices';
186 $permissiontoread = $user->hasRight(
"facture",
"lire");
187 $permissiontoadd = $user->hasRight(
"facture",
"creer");
188 $permissiontodelete = $user->hasRight(
"facture",
"supprimer");
189 $uploaddir =
$conf->invoice->dir_output;
191 if (isset($_POST[
'massaction'])) {
192 $massaction = $_POST[
'massaction'];
195 if (isset($_POST[
'confirmmassaction']) && isset($_POST[
'massaction']) && $_POST[
'massaction'] ==
'presend') {
196 global $arrayofselected;
198 $toselect = is_array($_POST[
'toselect']) ? $_POST[
'toselect'] : array();
199 $arrayofselected = array();
202 foreach ($toselect as $invoice_id) {
204 if ($objecttmp->fetch((
int) $invoice_id) > 0) {
206 if (empty($objecttmp->thirdparty) || !is_object($objecttmp->thirdparty)) {
207 $objecttmp->fetch_thirdparty();
211 if (!empty($objecttmp->thirdparty->email)) {
213 $arrayofselected[] = $invoice_id;
218 if (empty($arrayofselected)) {
219 setEventMessages($langs->trans(
"DefaultStatusEmptyMandatory").
' '.$langs->trans(
"Select"),
null,
'errors');
220 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
224 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
233if ($id > 0 || !empty($ref)) {
235 $result = $product->fetch($id, $ref);
239 $parameters = array(
'id' => $id);
240 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
245 $title = $langs->trans(
'ProductServiceCard');
249 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'Referers');
250 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
253 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'Referers');
254 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
257 llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'mod-product page-stats_facture');
261 $titre = $langs->trans(
"CardProduct".$product->type);
265 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
266 print $hookmanager->resPrint;
271 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1&type='.
$object->type.
'">'.$langs->trans(
"BackToList").
'</a>';
272 $object->next_prev_filter =
"(te.fk_product_type:=:".((int)
$object->type).
")";
275 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
279 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
281 print
'<div class="fichecenter">';
283 print
'<div class="clearboth"></div>';
284 print
'<table class="noborder tableforfield centpercent">';
291 print
'<div class="clearboth"></div>';
295 if ($showmessage && $nboflines > 1) {
297 } elseif ($user->hasRight(
'facture',
'lire')) {
298 $sql =
"SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,";
299 $sql .=
" f.ref, f.datef, f.paye, f.type, f.fk_statut as statut, f.rowid as facid,";
300 $sql .=
" d.rowid, d.total_ht as total_ht, d.qty";
301 if (!$user->hasRight(
'societe',
'client',
'voir')) {
302 $sql .=
", sc.fk_soc, sc.fk_user ";
305 if (!empty($extrafields->attributes[
'facture'][
'label'])) {
306 foreach ($extrafields->attributes[
'facture'][
'label'] as $key => $val) {
307 $sql .= ($extrafields->attributes[
'facture'][
'type'][$key] !=
'separate' ?
", ef.".$key.
" as options_".$key :
'');
311 $parameters = array();
312 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters,
$object, $action);
313 $sql .= $hookmanager->resPrint;
314 $sql = preg_replace(
'/,\s*$/',
'', $sql);
316 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
317 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
318 if (isset($extrafields->attributes[
'facture'][
'label']) && is_array($extrafields->attributes[
'facture'][
'label']) && count($extrafields->attributes[
'facture'][
'label'])) {
319 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
'facture'.
"_extrafields as ef on (f.rowid = ef.fk_object)";
321 $sql .=
", ".MAIN_DB_PREFIX.
"facturedet as d";
322 if (!$user->hasRight(
'societe',
'client',
'voir')) {
323 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
326 $parameters = array();
327 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters,
$object);
328 $sql .= $hookmanager->resPrint;
330 $sql .=
" WHERE f.fk_soc = s.rowid";
331 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
332 $sql .=
" AND d.fk_facture = f.rowid";
333 $sql .=
" AND d.fk_product = ".((int) $product->id);
334 if ($search_date_start) {
335 $sql .=
" AND f.datef >= '".$db->idate($search_date_start).
"'";
337 if ($search_date_end) {
338 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
340 if (!$user->hasRight(
'societe',
'client',
'voir')) {
341 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
344 $sql .=
" AND f.fk_soc = ".((int) $socid);
347 $extrafieldsobjectkey =
'facture';
348 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
350 $parameters = array();
351 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object, $action);
352 $sql .= $hookmanager->resPrint;
355 $parameters = array();
356 $reshook = $hookmanager->executeHooks(
'printFieldListHaving', $parameters,
$object, $action);
357 if (empty($reshook)) {
358 $sql .= empty($hookmanager->resPrint) ?
"" :
" HAVING 1=1 ".$hookmanager->resPrint;
360 $sql = $hookmanager->resPrint;
363 $sql .=
$db->order($sortfield, $sortorder);
370 $totalofrecords =
'';
372 $result =
$db->query($sql);
373 $totalofrecords =
$db->num_rows($result);
376 $sql .=
$db->plimit($limit + 1, $offset);
378 $result =
$db->query($sql);
380 $num =
$db->num_rows($result);
383 $num =
$db->num_rows($result);
384 while ($row =
$db->fetch_object($result)) {
390 $option .=
'&id='.$product->id;
392 if ($limit > 0 && $limit !=
$conf->liste_limit) {
393 $option .=
'&limit='.((int) $limit);
397 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
399 '@phan-var-force string $param';
401 $parameters = array(
'param' => &$param);
402 $reshook = $hookmanager->executeHooks(
'printFieldListSearchParam', $parameters,
$object, $action);
403 $option .= $hookmanager->resPrint;
405 print
'<span id="anchorundermenu" class="anchorundermenu"></span>';
406 print
'<form method="post" action="'.$_SERVER [
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
407 print
'<input type="hidden" name="token" value="'.newToken().
'">';
408 print
'<input type="hidden" name="page_y" value="">';
409 if (!empty($sortfield)) {
410 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
412 if (!empty($sortorder)) {
413 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
417 print_barre_liste($langs->trans(
"CustomersInvoices"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder, $massactionbutton, $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
419 if ($massaction ==
'presend' && !empty($arrayofselected)) {
421 $topicmail =
"SendBillRef";
422 $modelmail =
"facture_send";
424 $trackid =
'inv'.$id;
426 include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
430 $option .=
'&page='.urlencode((
string) ($page));
433 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
434 print
'<div class="divsearchfield">';
435 print $langs->trans(
'Period').
' ('.$langs->trans(
"DateInvoice").
') - ';
436 print $form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
437 print $form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
438 $parameters = array();
439 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters,
$object, $action);
440 print $hookmanager->resPrint;
442 print
'<div style="vertical-align: middle; display: inline-block">';
443 print
'<input type="image" class="liste_titre reposition" name="button_search" src="'.img_picto($langs->trans(
"Search"),
'search.png',
'', 0, 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"Search")).
'" title="'.
dol_escape_htmltag($langs->trans(
"Search")).
'">';
444 print
'<input type="image" class="liste_titre reposition" name="button_removefilter" src="'.img_picto($langs->trans(
"Search"),
'searchclear.png',
'', 0, 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"RemoveFilter")).
'" title="'.
dol_escape_htmltag($langs->trans(
"RemoveFilter")).
'">';
450 print
'<div class="div-table-responsive">';
451 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
452 print
'<tr class="liste_titre">';
454 if (
$conf->main_checkbox_left_column) {
455 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center"', $sortfield, $sortorder,
'maxwidthsearch ');
459 print_liste_field_titre(
"CustomerCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"", $option,
'', $sortfield, $sortorder);
460 print_liste_field_titre(
"DateInvoice", $_SERVER[
"PHP_SELF"],
"f.datef",
"", $option,
'align="center"', $sortfield, $sortorder);
461 print_liste_field_titre(
"Qty", $_SERVER[
"PHP_SELF"],
"d.qty",
"", $option,
'align="center"', $sortfield, $sortorder);
462 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
"d.total_ht",
"", $option,
'align="right"', $sortfield, $sortorder);
463 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"f.paye,f.fk_statut",
"", $option,
'align="right"', $sortfield, $sortorder);
465 $parameters = array(
'param' => $option,
'sortfield' => $sortfield,
'sortorder' => $sortorder);
466 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters,
$object, $action);
467 print $hookmanager->resPrint;
469 if (!
$conf->main_checkbox_left_column) {
470 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center"', $sortfield, $sortorder,
'maxwidthsearch ');
475 while ($i < min($num, $limit)) {
476 $objp = $all_rows[$i];
478 $objp->qty = -($objp->qty);
481 $total_ht += $objp->total_ht;
482 $total_qty += $objp->qty;
484 $invoicestatic->id = $objp->facid;
485 $invoicestatic->ref = $objp->ref;
486 $societestatic->fetch($objp->socid);
487 $paiement = $invoicestatic->getSommePaiement();
489 print
'<tr data-row-id="'.$invoicestatic->id.
'" class="oddeven row-with-select status2">';
492 if (
$conf->main_checkbox_left_column) {
493 print
'<td class="nowrap center">';
494 if (($massactionbutton || $massaction) && $contextpage !=
'poslist') {
496 if (in_array($invoicestatic->id, $arrayofselected)) {
499 print
'<input id="cb'.$invoicestatic->id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$invoicestatic->id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
507 print
'<td class="tdoverflowmax150">';
508 print $invoicestatic->getNomUrl(1);
510 print
'<td class="tdoverflowmax125">'.$societestatic->getNomUrl(1).
'</td>';
511 print
'<td class="tdoverflowmax125">'.dolPrintHTML($objp->code_client).
"</td>\n";
512 print
'<td class="center">';
514 print
'<td class="center">'.dolPrintHTML($objp->qty).
"</td>\n";
515 print
'<td class="right">'.price($objp->total_ht).
"</td>\n";
516 print
'<td class="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5, $paiement, $objp->type).
'</td>';
518 $parameters = array();
519 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters,
$object, $action);
520 print $hookmanager->resPrint;
523 if (!
$conf->main_checkbox_left_column) {
524 print
'<td class="nowrap center">';
525 if (($massactionbutton || $massaction) && $contextpage !=
'poslist') {
527 if (in_array($invoicestatic->id, $arrayofselected)) {
530 print
'<input id="cb'.$invoicestatic->id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$invoicestatic->id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
544 print
'<tr class="liste_total">';
545 if ($num < $limit && empty($offset)) {
546 print
'<td>'.$langs->trans(
"Total").
'</td>';
548 print
'<td>'.$form->textwithpicto($langs->trans(
"Total"), $langs->trans(
"Totalforthispage")).
'</td>';
550 print
'<td colspan="3"></td>';
551 print
'<td class="center">'.$total_qty.
'</td>';
552 print
'<td class="right">'.price($total_ht).
'</td>';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...
product_prepare_head($object)
Prepare array with list of tabs.
show_stats_for_company($product, $socid)
Show stats for a product.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.