28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
35 $langs->loadLangs(array(
'companies',
'bills',
'products',
'supplier_proposal'));
41 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
42 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
44 if (!empty($user->socid)) {
45 $socid = $user->socid;
49 $hookmanager->initHooks(array(
'productstatsinvoice'));
51 $showmessage =
GETPOST(
'showmessage');
54 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
55 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
56 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
58 if (empty($page) || $page == -1) {
61 $offset = $limit * $page;
62 $pageprev = $page - 1;
63 $pagenext = $page + 1;
68 $sortfield =
"f.datef";
71 $search_month =
GETPOST(
'search_month',
'int');
72 $search_year =
GETPOST(
'search_year',
'int');
74 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
79 $result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
86 $invoicestatic =
new Facture($db);
87 $societestatic =
new Societe($db);
92 if ($id > 0 || !empty($ref)) {
94 $result = $product->fetch($id, $ref);
98 $parameters = array(
'id'=>$id);
99 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
104 $title = $langs->trans(
'ProductServiceCard');
106 $shortlabel =
dol_trunc($object->label, 16);
108 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'Referers');
109 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
112 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'Referers');
113 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
120 $titre = $langs->trans(
"CardProduct".$product->type);
124 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
125 print $hookmanager->resPrint;
130 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
133 if ($user->socid && !in_array(
'product', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
139 print
'<div class="fichecenter">';
141 print
'<div class="underbanner clearboth"></div>';
142 print
'<table class="border tableforfield" width="100%">';
149 print
'<div style="clear:both"></div>';
153 if ($showmessage && $nboflines > 1) {
154 print
'<span class="opacitymedium">'.$langs->trans(
"ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv(
"Referers")).
'</span>';
155 } elseif ($user->rights->facture->lire) {
156 $sql =
"SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,";
157 $sql .=
" f.ref, f.datef, f.paye, f.type, f.fk_statut as statut, f.rowid as facid,";
158 $sql .=
" d.rowid, d.total_ht as total_ht, d.qty";
159 if (empty($user->rights->societe->client->voir) && !$socid) {
160 $sql .=
", sc.fk_soc, sc.fk_user ";
162 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
163 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
164 $sql .=
", ".MAIN_DB_PREFIX.
"facturedet as d";
165 if (empty($user->rights->societe->client->voir) && !$socid) {
166 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
168 $sql .=
" WHERE f.fk_soc = s.rowid";
169 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
170 $sql .=
" AND d.fk_facture = f.rowid";
171 $sql .=
" AND d.fk_product = ".((int) $product->id);
172 if (!empty($search_month)) {
173 $sql .=
' AND MONTH(f.datef) IN ('.$db->sanitize($search_month).
')';
175 if (!empty($search_year)) {
176 $sql .=
' AND YEAR(f.datef) IN ('.$db->sanitize($search_year).
')';
178 if (empty($user->rights->societe->client->voir) && !$socid) {
179 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
182 $sql .=
" AND f.fk_soc = ".((int) $socid);
184 $sql .= $db->order($sortfield, $sortorder);
191 $totalofrecords =
'';
192 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
193 $result = $db->query($sql);
194 $totalofrecords = $db->num_rows($result);
197 $sql .= $db->plimit($limit + 1, $offset);
199 $result = $db->query($sql);
201 $num = $db->num_rows($result);
203 $option .=
'&id='.$product->id;
205 if ($limit > 0 && $limit != $conf->liste_limit) {
206 $option .=
'&limit='.urlencode($limit);
208 if (!empty($search_month)) {
209 $option .=
'&search_month='.urlencode($search_month);
211 if (!empty($search_year)) {
212 $option .=
'&search_year='.urlencode($search_year);
215 print
'<form method="post" action="'.$_SERVER [
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
216 print
'<input type="hidden" name="token" value="'.newToken().
'">';
217 if (!empty($sortfield)) {
218 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
220 if (!empty($sortorder)) {
221 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
224 print_barre_liste($langs->trans(
"CustomersInvoices"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
227 $option .=
'&page='.urlencode($page);
230 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
231 print
'<div class="divsearchfield">';
232 print $langs->trans(
'Period').
' ('.$langs->trans(
"DateInvoice").
') - ';
233 print $langs->trans(
'Month').
':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.
'"> ';
234 print $langs->trans(
'Year').
':'.$formother->selectyear($search_year ? $search_year : - 1,
'search_year', 1, 20, 5);
235 print
'<div style="vertical-align: middle; display: inline-block">';
236 print
'<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans(
"Search"),
'search.png',
'',
'', 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"Search")).
'" title="'.
dol_escape_htmltag($langs->trans(
"Search")).
'">';
237 print
'<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans(
"Search"),
'searchclear.png',
'',
'', 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"RemoveFilter")).
'" title="'.
dol_escape_htmltag($langs->trans(
"RemoveFilter")).
'">';
243 print
'<div class="div-table-responsive">';
244 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
245 print
'<tr class="liste_titre">';
248 print_liste_field_titre(
"CustomerCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"", $option,
'', $sortfield, $sortorder);
249 print_liste_field_titre(
"DateInvoice", $_SERVER[
"PHP_SELF"],
"f.datef",
"", $option,
'align="center"', $sortfield, $sortorder);
250 print_liste_field_titre(
"Qty", $_SERVER[
"PHP_SELF"],
"d.qty",
"", $option,
'align="center"', $sortfield, $sortorder);
251 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
"d.total_ht",
"", $option,
'align="right"', $sortfield, $sortorder);
252 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"f.paye,f.fk_statut",
"", $option,
'align="right"', $sortfield, $sortorder);
256 while ($i < min($num, $limit)) {
257 $objp = $db->fetch_object($result);
260 $objp->qty = -($objp->qty);
263 $total_ht += $objp->total_ht;
264 $total_qty += $objp->qty;
266 $invoicestatic->id = $objp->facid;
267 $invoicestatic->ref = $objp->ref;
268 $societestatic->fetch($objp->socid);
269 $paiement = $invoicestatic->getSommePaiement();
271 print
'<tr class="oddeven">';
273 print $invoicestatic->getNomUrl(1);
275 print
'<td>'.$societestatic->getNomUrl(1).
'</td>';
276 print
"<td>".$objp->code_client.
"</td>\n";
277 print
'<td class="center">';
278 print
dol_print_date($db->jdate($objp->datef),
'dayhour').
"</td>";
279 print
'<td class="center">'.$objp->qty.
"</td>\n";
280 print
'<td align="right">'.price($objp->total_ht).
"</td>\n";
281 print
'<td align="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5, $paiement, $objp->type).
'</td>';
286 print
'<tr class="liste_total">';
288 print
'<td class="left">'.$langs->trans(
"Total").
'</td>';
290 print
'<td class="left">'.$langs->trans(
"Totalforthispage").
'</td>';
292 print
'<td colspan="3"></td>';
293 print
'<td class="center">'.$total_qty.
'</td>';
294 print
'<td align="right">'.price($total_ht).
'</td>';