28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.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',
'companies',
'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(
'productstatssupplierinvoice'));
52 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
53 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
54 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
56 if (empty($page) || $page == -1) {
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
66 $sortfield =
"f.datef";
68 $search_month =
GETPOST(
'search_month',
'int');
69 $search_year =
GETPOST(
'search_year',
'int');
71 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
76 $result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
84 $societestatic =
new Societe($db);
89 if ($id > 0 || !empty($ref)) {
91 $result = $product->fetch($id, $ref);
95 $parameters = array(
'id' => $id);
96 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
101 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
105 $titre = $langs->trans(
"CardProduct".$product->type);
109 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
110 print $hookmanager->resPrint;
115 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
118 if ($user->socid && !in_array(
'product', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
124 print
'<div class="fichecenter">';
126 print
'<div class="underbanner clearboth"></div>';
127 print
'<table class="border tableforfield" width="100%">';
134 print
'<div style="clear:both"></div>';
139 if ($user->rights->fournisseur->facture->lire) {
140 $sql =
"SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client, d.rowid, d.total_ht as line_total_ht,";
141 $sql .=
" f.rowid as facid, f.ref, f.ref_supplier, f.datef, f.libelle as label, f.total_ht, f.total_ttc, f.total_tva, f.paye, f.fk_statut as statut, d.qty";
142 if (empty($user->rights->societe->client->voir) && !$socid) {
143 $sql .=
", sc.fk_soc, sc.fk_user ";
145 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
146 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
147 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn_det as d";
148 if (empty($user->rights->societe->client->voir) && !$socid) {
149 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
151 $sql .=
" WHERE f.fk_soc = s.rowid";
152 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn').
")";
153 $sql .=
" AND d.fk_facture_fourn = f.rowid";
154 $sql .=
" AND d.fk_product = ".((int) $product->id);
155 if (!empty($search_month)) {
156 $sql .=
' AND MONTH(f.datef) IN ('.$db->sanitize($search_month).
')';
158 if (!empty($search_year)) {
159 $sql .=
' AND YEAR(f.datef) IN ('.$db->sanitize($search_year).
')';
161 if (empty($user->rights->societe->client->voir) && !$socid) {
162 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
165 $sql .=
" AND f.fk_soc = ".((int) $socid);
167 $sql .=
" ORDER BY $sortfield $sortorder ";
174 $totalofrecords =
'';
175 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
176 $result = $db->query($sql);
177 $totalofrecords = $db->num_rows($result);
180 $sql .= $db->plimit($limit + 1, $offset);
182 $result = $db->query($sql);
184 $num = $db->num_rows($result);
186 $option .=
'&id='.$product->id;
188 if ($limit > 0 && $limit != $conf->liste_limit) {
189 $option .=
'&limit='.urlencode($limit);
191 if (!empty($search_month)) {
192 $option .=
'&search_month='.urlencode($search_month);
194 if (!empty($search_year)) {
195 $option .=
'&search_year='.urlencode($search_year);
198 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
199 print
'<input type="hidden" name="token" value="'.newToken().
'">';
200 if (!empty($sortfield)) {
201 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
203 if (!empty($sortorder)) {
204 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
207 print_barre_liste($langs->trans(
"SuppliersInvoices"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
210 $option .=
'&page='.urlencode($page);
213 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
214 print
'<div class="divsearchfield">';
215 print $langs->trans(
'Period').
' ('.$langs->trans(
"DateInvoice").
') - ';
216 print $langs->trans(
'Month').
':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.
'"> ';
217 print $langs->trans(
'Year').
':'.$formother->selectyear($search_year ? $search_year : - 1,
'search_year', 1, 20, 5);
218 print
'<div style="vertical-align: middle; display: inline-block">';
219 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")).
'">';
220 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")).
'">';
226 print
'<div class="div-table-responsive">';
227 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
228 print
'<tr class="liste_titre">';
231 print_liste_field_titre(
"SupplierCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"", $option,
'', $sortfield, $sortorder);
232 print_liste_field_titre(
"DateInvoice", $_SERVER[
"PHP_SELF"],
"f.datef",
"", $option,
'align="center"', $sortfield, $sortorder);
233 print_liste_field_titre(
"Qty", $_SERVER[
"PHP_SELF"],
"d.qty",
"", $option,
'align="center"', $sortfield, $sortorder);
234 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
"d.total_ht",
"", $option,
'align="right"', $sortfield, $sortorder);
235 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"f.paye,f.fk_statut",
"", $option,
'align="right"', $sortfield, $sortorder);
239 while ($i < min($num, $limit)) {
240 $objp = $db->fetch_object($result);
242 $total_ht += $objp->line_total_ht;
243 $total_qty += $objp->qty;
245 $supplierinvoicestatic->id = $objp->facid;
246 $supplierinvoicestatic->ref = $objp->ref;
247 $supplierinvoicestatic->ref_supplier = $objp->ref_supplier;
248 $supplierinvoicestatic->libelle = $objp->label;
249 $supplierinvoicestatic->label = $objp->label;
250 $supplierinvoicestatic->total_ht = $objp->total_ht;
251 $supplierinvoicestatic->total_ttc = $objp->total_ttc;
252 $supplierinvoicestatic->total_tva = $objp->total_tva;
254 $societestatic->fetch($objp->socid);
256 print
'<tr class="oddeven">';
258 print $supplierinvoicestatic->getNomUrl(1);
260 print
'<td>'.$societestatic->getNomUrl(1).
'</td>';
261 print
"<td>".$objp->code_client.
"</td>\n";
262 print
'<td class="center">';
263 print
dol_print_date($db->jdate($objp->datef),
'dayhour').
"</td>";
264 print
'<td class="center">'.$objp->qty.
"</td>\n";
265 print
'<td align="right">'.price($objp->line_total_ht).
"</td>\n";
266 print
'<td align="right">'.$supplierinvoicestatic->LibStatut($objp->paye, $objp->statut, 5).
'</td>';
271 print
'<tr class="liste_total">';
273 print
'<td class="left">'.$langs->trans(
"Total").
'</td>';
275 print
'<td class="left">'.$langs->trans(
"Totalforthispage").
'</td>';
277 print
'<td colspan="3"></td>';
278 print
'<td class="center">'.$total_qty.
'</td>';
279 print
'<td align="right">'.price($total_ht).
'</td>';