63 global $conf, $user, $langs;
67 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
68 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
73 $text = $langs->trans(
"BoxTitleLast".(
getDolGlobalString(
'MAIN_LASTBOX_ON_OBJECT_DATE') ?
"" :
"Modified").
"SupplierBills", $max);
74 $this->info_box_head = array(
75 'text' => $text.
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?sortfield=f.tms&sortorder=DESC"><span class="badge">...</span></a>'
78 if ($user->hasRight(
'fournisseur',
'facture',
'lire')) {
79 $langs->load(
"bills");
81 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
82 $sql .=
", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
83 $sql .=
", s.logo, s.email, s.entity";
84 $sql .=
", f.rowid as facid, f.ref, f.ref_supplier";
85 $sql .=
", f.total_ht";
86 $sql .=
", f.total_tva";
87 $sql .=
", f.total_ttc";
88 $sql .=
", f.paye, f.fk_statut as status";
89 $sql .=
', f.datef as date';
90 $sql .=
', f.datec as datec';
91 $sql .=
', f.date_lim_reglement as datelimite, f.tms, f.type';
92 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
93 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
94 if (!$user->hasRight(
'societe',
'client',
'voir')) {
95 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
97 $sql .=
" WHERE f.fk_soc = s.rowid";
98 $sql .=
" AND f.entity = ".$conf->entity;
99 if (!$user->hasRight(
'societe',
'client',
'voir')) {
100 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
103 $sql .=
" AND s.rowid = ".((int) $user->socid);
106 $sql .=
" ORDER BY f.datef DESC, f.ref DESC ";
108 $sql .=
" ORDER BY f.tms DESC, f.ref DESC ";
110 $sql .= $this->db->plimit($max, 0);
112 $result = $this->db->query($sql);
114 $num = $this->db->num_rows($result);
117 $l_due_date = $langs->trans(
'Late').
' ('.$langs->trans(
'DateDue').
': %s)';
119 while ($line < $num) {
120 $objp = $this->db->fetch_object($result);
122 $datelimite = $this->db->jdate($objp->datelimite);
123 $date = $this->db->jdate($objp->date);
124 $datem = $this->db->jdate($objp->tms);
126 $facturestatic->id = $objp->facid;
127 $facturestatic->ref = $objp->ref;
128 $facturestatic->total_ht = $objp->total_ht;
129 $facturestatic->total_tva = $objp->total_tva;
130 $facturestatic->total_ttc = $objp->total_ttc;
131 $facturestatic->date = $date;
132 $facturestatic->date_echeance = $datelimite;
133 $facturestatic->statut = $objp->status;
134 $facturestatic->status = $objp->status;
135 $facturestatic->ref_supplier = $objp->ref_supplier;
137 $alreadypaid = $facturestatic->getSommePaiement();
139 $facturestatic->alreadypaid = $alreadypaid ? $alreadypaid : 0;
141 $thirdpartystatic->id = $objp->socid;
142 $thirdpartystatic->name = $objp->name;
143 $thirdpartystatic->name_alias = $objp->name_alias;
144 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
145 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
146 $thirdpartystatic->fournisseur = $objp->fournisseur;
147 $thirdpartystatic->logo = $objp->logo;
148 $thirdpartystatic->email = $objp->email;
149 $thirdpartystatic->entity = $objp->entity;
153 if ($facturestatic->hasDelay()) {
158 $this->info_box_contents[$line][] = array(
159 'td' =>
'class="nowraponall"',
160 'text' => $facturestatic->getNomUrl(1),
165 $this->info_box_contents[$line][] = array(
166 'td' =>
'class="tdoverflowmax150"',
167 'text' => $objp->ref_supplier,
168 'tooltip' => $langs->trans(
'SupplierInvoice').
': '.($objp->ref ? $objp->ref : $objp->facid).
'<br>'.$langs->trans(
'RefSupplier').
': '.$objp->ref_supplier,
169 'url' => DOL_URL_ROOT.
"/fourn/facture/card.php?facid=".$objp->facid,
172 $this->info_box_contents[$line][] = array(
173 'td' =>
'class="tdoverflowmax150"',
174 'text' => $thirdpartystatic->getNomUrl(1,
'supplier'),
178 $this->info_box_contents[$line][] = array(
179 'td' =>
'class="nowraponall right amount"',
180 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
183 $this->info_box_contents[$line][] = array(
188 $this->info_box_contents[$line][] = array(
189 'td' =>
'class="right" width="18"',
190 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $alreadypaid, $objp->type),
197 $this->info_box_contents[$line][0] = array(
198 'td' =>
'class="center"',
199 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoModifiedSupplierBills").
'</span>',
203 $this->db->free($result);
205 $this->info_box_contents[0][0] = array(
208 'text' => ($this->db->error().
' sql='.$sql),
212 $this->info_box_contents[0][0] = array(
213 'td' =>
'class="nohover left"',
214 'text' =>
'<span class="opacitymedium">'.$langs->transnoentities(
"ReadPermissionNotAllowed").
'</span>'