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 =
isModEnabled(
'invoice') ?
$conf->invoice->dir_output.
'/temp/massgeneration/'.$user->id :
'';
142if (
GETPOST(
'cancel',
'alpha')) {
146if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
154 'f.ref' => array(
'label' =>
"Ref",
'checked' =>
'1',
'position' => 5),
155 's.nom' => array(
'label' =>
"ThirdParty",
'checked' =>
'1',
'position' => 50),
156 's.code_client' => array(
'label' =>
"CustomerCodeShort",
'checked' =>
'-1',
'position' => 52),
157 'f.datef' => array(
'label' =>
"DateInvoice",
'checked' =>
'1',
'position' => 60),
158 'd.qty' => array(
'label' =>
"Qty",
'checked' =>
'1',
'position' => 65),
159 'd.total_ht' => array(
'label' =>
"AmountHT",
'checked' =>
'1',
'position' => 70),
160 'f.fk_statut' => array(
'label' =>
"Status",
'checked' =>
'1',
'position' => 1000),
171$arrayofmassactions = array();
173 $arrayofmassactions[
'presend'] =
img_picto(
'',
'email',
'class="pictofixedwidth"').$langs->trans(
"SendByMail");
175$massactionbutton = $form->selectMassAction(
'', $arrayofmassactions);
176$arrayofselected = is_array($toselect) ? $toselect : array();
177$selectedfields = (count($arrayofmassactions) ? $form->showCheckAddButtons(
'checkforselect', 1) :
'');
183$parameters = array(
'socid' => $socid,
'arrayfields' => &$arrayfields);
184$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
189 $objectclass =
'Facture';
190 $objectlabel =
'Invoices';
191 $permissiontoread = $user->hasRight(
"facture",
"lire");
192 $permissiontoadd = $user->hasRight(
"facture",
"creer");
193 $permissiontodelete = $user->hasRight(
"facture",
"supprimer");
194 $uploaddir =
$conf->invoice->dir_output;
196 if (isset($_POST[
'massaction'])) {
197 $massaction = $_POST[
'massaction'];
200 if (isset($_POST[
'confirmmassaction']) && isset($_POST[
'massaction']) && $_POST[
'massaction'] ==
'presend') {
201 global $arrayofselected;
203 $toselect = is_array($_POST[
'toselect']) ? $_POST[
'toselect'] : array();
204 $arrayofselected = array();
207 foreach ($toselect as $invoice_id) {
209 if ($objecttmp->fetch((
int) $invoice_id) > 0) {
211 if (empty($objecttmp->thirdparty) || !is_object($objecttmp->thirdparty)) {
212 $objecttmp->fetch_thirdparty();
216 if (!empty($objecttmp->thirdparty->email)) {
218 $arrayofselected[] = $invoice_id;
223 if (empty($arrayofselected)) {
224 setEventMessages($langs->trans(
"DefaultStatusEmptyMandatory").
' '.$langs->trans(
"Select"),
null,
'errors');
225 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
229 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
238if ($id > 0 || !empty($ref)) {
240 $result = $product->fetch($id, $ref);
244 $parameters = array(
'id' => $id);
245 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
250 $title = $langs->trans(
'ProductServiceCard');
254 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'Referers');
255 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
258 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'Referers');
259 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
262 llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'mod-product page-stats_facture');
266 $titre = $langs->trans(
"CardProduct".$product->type);
270 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
271 print $hookmanager->resPrint;
276 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1&type='.
$object->type.
'">'.$langs->trans(
"BackToList").
'</a>';
277 $object->next_prev_filter =
"(te.fk_product_type:=:".((int)
$object->type).
")";
280 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
284 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
286 print
'<div class="fichecenter">';
288 print
'<div class="clearboth"></div>';
289 print
'<table class="noborder tableforfield centpercent">';
296 print
'<div class="clearboth"></div>';
300 if ($showmessage && $nboflines > 1) {
302 } elseif ($user->hasRight(
'facture',
'lire')) {
303 $sql =
"SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,";
304 $sql .=
" f.ref, f.datef, f.paye, f.type, f.fk_statut as statut, f.rowid as facid,";
305 $sql .=
" d.rowid, d.total_ht as total_ht, d.qty";
306 if (!$user->hasRight(
'societe',
'client',
'voir')) {
307 $sql .=
", sc.fk_soc, sc.fk_user ";
310 if (!empty($extrafields->attributes[
'facture'][
'label'])) {
311 foreach ($extrafields->attributes[
'facture'][
'label'] as $key => $val) {
312 $sql .= ($extrafields->attributes[
'facture'][
'type'][$key] !=
'separate' ?
", ef.".$key.
" as options_".$key :
'');
316 $parameters = array();
317 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters,
$object, $action);
318 $sql .= $hookmanager->resPrint;
319 $sql = preg_replace(
'/,\s*$/',
'', $sql);
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
322 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
323 if (isset($extrafields->attributes[
'facture'][
'label']) && is_array($extrafields->attributes[
'facture'][
'label']) && count($extrafields->attributes[
'facture'][
'label'])) {
324 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
'facture'.
"_extrafields as ef on (f.rowid = ef.fk_object)";
326 $sql .=
", ".MAIN_DB_PREFIX.
"facturedet as d";
327 if (!$user->hasRight(
'societe',
'client',
'voir')) {
328 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
331 $parameters = array();
332 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters,
$object);
333 $sql .= $hookmanager->resPrint;
335 $sql .=
" WHERE f.fk_soc = s.rowid";
336 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
337 $sql .=
" AND d.fk_facture = f.rowid";
338 $sql .=
" AND d.fk_product = ".((int) $product->id);
339 if ($search_date_start) {
340 $sql .=
" AND f.datef >= '".$db->idate($search_date_start).
"'";
342 if ($search_date_end) {
343 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
345 if (!$user->hasRight(
'societe',
'client',
'voir')) {
346 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
349 $sql .=
" AND f.fk_soc = ".((int) $socid);
352 $extrafieldsobjectkey =
'facture';
353 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
355 $parameters = array();
356 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object, $action);
357 $sql .= $hookmanager->resPrint;
360 $parameters = array();
361 $reshook = $hookmanager->executeHooks(
'printFieldListHaving', $parameters,
$object, $action);
362 if (empty($reshook)) {
363 $sql .= empty($hookmanager->resPrint) ?
"" :
" HAVING 1=1 ".$hookmanager->resPrint;
365 $sql = $hookmanager->resPrint;
368 $sql .=
$db->order($sortfield, $sortorder);
375 $totalofrecords =
'';
377 $result =
$db->query($sql);
378 $totalofrecords =
$db->num_rows($result);
381 $sql .=
$db->plimit($limit + 1, $offset);
383 $result =
$db->query($sql);
385 $num =
$db->num_rows($result);
388 $num =
$db->num_rows($result);
389 while ($row =
$db->fetch_object($result)) {
395 $option .=
'&id='.$product->id;
397 if ($limit > 0 && $limit !=
$conf->liste_limit) {
398 $option .=
'&limit='.((int) $limit);
402 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
404 '@phan-var-force string $param';
406 $parameters = array(
'param' => &$param);
407 $reshook = $hookmanager->executeHooks(
'printFieldListSearchParam', $parameters,
$object, $action);
408 $option .= $hookmanager->resPrint;
410 print
'<span id="anchorundermenu" class="anchorundermenu"></span>';
411 print
'<form method="post" action="'.$_SERVER [
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
412 print
'<input type="hidden" name="token" value="'.newToken().
'">';
413 print
'<input type="hidden" name="page_y" value="">';
414 if (!empty($sortfield)) {
415 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
417 if (!empty($sortorder)) {
418 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
422 print_barre_liste($langs->trans(
"CustomersInvoices"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder, $massactionbutton, $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
424 if ($massaction ==
'presend' && !empty($arrayofselected)) {
426 $topicmail =
"SendBillRef";
427 $modelmail =
"facture_send";
429 $trackid =
'inv'.$id;
431 include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
435 $option .=
'&page='.urlencode((
string) ($page));
438 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
439 print
'<div class="divsearchfield">';
440 print $langs->trans(
'Period').
' ('.$langs->trans(
"DateInvoice").
') - ';
441 print $form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
442 print $form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
443 $parameters = array();
444 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters,
$object, $action);
445 print $hookmanager->resPrint;
447 print
'<div style="vertical-align: middle; display: inline-block">';
448 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")).
'">';
449 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")).
'">';
456 print
'<div class="div-table-responsive">';
457 print
'<table class="tagtable liste listwithfilterbefore centpercent">';
458 print
'<tr class="liste_titre">';
460 if (
$conf->main_checkbox_left_column) {
461 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center"', $sortfield, $sortorder,
'maxwidthsearch ');
466 print_liste_field_titre(
"CustomerCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"", $option,
'', $sortfield, $sortorder);
467 print_liste_field_titre(
"DateInvoice", $_SERVER[
"PHP_SELF"],
"f.datef",
"", $option,
'align="center"', $sortfield, $sortorder);
468 print_liste_field_titre(
"Qty", $_SERVER[
"PHP_SELF"],
"d.qty",
"", $option,
'align="center"', $sortfield, $sortorder);
469 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
"d.total_ht",
"", $option,
'align="right"', $sortfield, $sortorder);
470 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"f.paye,f.fk_statut",
"", $option,
'align="right"', $sortfield, $sortorder);
472 $parameters = array(
'param' => $option,
'sortfield' => $sortfield,
'sortorder' => $sortorder);
473 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters,
$object, $action);
474 print $hookmanager->resPrint;
476 if (!
$conf->main_checkbox_left_column) {
477 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center"', $sortfield, $sortorder,
'maxwidthsearch ');
482 while ($i < min($num, $limit)) {
483 $objp = $all_rows[$i];
485 $objp->qty = -($objp->qty);
488 $total_ht += $objp->total_ht;
489 $total_qty += $objp->qty;
491 $invoicestatic->id = $objp->facid;
492 $invoicestatic->ref = $objp->ref;
493 $societestatic->fetch($objp->socid);
494 $paiement = $invoicestatic->getSommePaiement();
496 print
'<tr data-row-id="'.$invoicestatic->id.
'" class="oddeven row-with-select status2">';
499 if (
$conf->main_checkbox_left_column) {
500 print
'<td class="nowrap center">';
501 if (($massactionbutton || $massaction) && $contextpage !=
'poslist') {
503 if (in_array($invoicestatic->id, $arrayofselected)) {
506 print
'<input id="cb'.$invoicestatic->id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$invoicestatic->id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
514 print
'<td class="tdoverflowmax150">';
515 print $invoicestatic->getNomUrl(1);
517 print
'<td class="tdoverflowmax125">'.$societestatic->getNomUrl(1).
'</td>';
518 print
'<td class="tdoverflowmax125">'.dolPrintHTML($objp->code_client).
"</td>\n";
519 print
'<td class="center">';
521 print
'<td class="center">'.dolPrintHTML($objp->qty).
"</td>\n";
522 print
'<td class="right">'.price($objp->total_ht).
"</td>\n";
523 print
'<td class="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5, $paiement, $objp->type).
'</td>';
525 $parameters = array();
526 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters,
$object, $action);
527 print $hookmanager->resPrint;
530 if (!
$conf->main_checkbox_left_column) {
531 print
'<td class="nowrap center">';
532 if (($massactionbutton || $massaction) && $contextpage !=
'poslist') {
534 if (in_array($invoicestatic->id, $arrayofselected)) {
537 print
'<input id="cb'.$invoicestatic->id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$invoicestatic->id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
551 print
'<tr class="liste_total">';
552 if ($num < $limit && empty($offset)) {
553 print
'<td>'.$langs->trans(
"Total").
'</td>';
555 print
'<td>'.$form->textwithpicto($langs->trans(
"Total"), $langs->trans(
"Totalforthispage")).
'</td>';
557 print
'<td colspan="'.$colspan.
'"></td>';
558 print
'<td class="center">'.$total_qty.
'</td>';
559 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)
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.