65 global $conf, $user, $langs;
69 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
70 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
75 $text = $langs->trans(
"BoxTitleLast".(
getDolGlobalString(
'MAIN_LASTBOX_ON_OBJECT_DATE') ?
"" :
"Modified").
"SupplierBills", $max);
76 $this->info_box_head = array(
77 'text' => $text.
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?sortfield=f.tms&sortorder=DESC"><span class="badge">...</span></a>'
80 if ($user->hasRight(
'fournisseur',
'facture',
'lire')) {
81 $langs->load(
"bills");
83 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
84 $sql .=
", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
85 $sql .=
", s.logo, s.email, s.entity";
86 $sql .=
", f.rowid as facid, f.ref, f.ref_supplier";
87 $sql .=
", f.total_ht";
88 $sql .=
", f.total_tva";
89 $sql .=
", f.total_ttc";
90 $sql .=
", f.paye, f.fk_statut as status";
91 $sql .=
', f.datef as date';
92 $sql .=
', f.datec as datec';
93 $sql .=
', f.date_lim_reglement as datelimite, f.tms, f.type';
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
95 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
96 if (!$user->hasRight(
'societe',
'client',
'voir')) {
97 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
99 $sql .=
" WHERE f.fk_soc = s.rowid";
100 $sql .=
" AND f.entity = ".$conf->entity;
101 if (!$user->hasRight(
'societe',
'client',
'voir')) {
102 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
105 $sql .=
" AND s.rowid = ".((int) $user->socid);
108 $sql .=
" ORDER BY f.datef DESC, f.ref DESC ";
110 $sql .=
" ORDER BY f.tms DESC, f.ref DESC ";
112 $sql .= $this->db->plimit($max, 0);
114 $result = $this->db->query($sql);
116 $num = $this->db->num_rows($result);
119 $l_due_date = $langs->trans(
'Late').
' ('.$langs->trans(
'DateDue').
': %s)';
121 while ($line < $num) {
122 $objp = $this->db->fetch_object($result);
124 $datelimite = $this->db->jdate($objp->datelimite);
125 $date = $this->db->jdate($objp->date);
126 $datem = $this->db->jdate($objp->tms);
128 $facturestatic->id = $objp->facid;
129 $facturestatic->ref = $objp->ref;
130 $facturestatic->total_ht = $objp->total_ht;
131 $facturestatic->total_tva = $objp->total_tva;
132 $facturestatic->total_ttc = $objp->total_ttc;
133 $facturestatic->date = $date;
134 $facturestatic->date_echeance = $datelimite;
135 $facturestatic->statut = $objp->status;
136 $facturestatic->status = $objp->status;
137 $facturestatic->ref_supplier = $objp->ref_supplier;
139 $alreadypaid = $facturestatic->getSommePaiement();
141 $facturestatic->alreadypaid = $alreadypaid ? $alreadypaid : 0;
143 $thirdpartystatic->id = $objp->socid;
144 $thirdpartystatic->name = $objp->name;
145 $thirdpartystatic->name_alias = $objp->name_alias;
146 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
147 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
148 $thirdpartystatic->fournisseur = $objp->fournisseur;
149 $thirdpartystatic->logo = $objp->logo;
150 $thirdpartystatic->email = $objp->email;
151 $thirdpartystatic->entity = $objp->entity;
155 if ($facturestatic->hasDelay()) {
160 $this->info_box_contents[$line][] = array(
161 'td' =>
'class="nowraponall"',
162 'text' => $facturestatic->getNomUrl(1),
167 $this->info_box_contents[$line][] = array(
168 'td' =>
'class="tdoverflowmax150"',
169 'text' => $objp->ref_supplier,
170 'tooltip' => $langs->trans(
'SupplierInvoice').
': '.($objp->ref ? $objp->ref : $objp->facid).
'<br>'.$langs->trans(
'RefSupplier').
': '.$objp->ref_supplier,
171 'url' => DOL_URL_ROOT.
"/fourn/facture/card.php?facid=".$objp->facid,
174 $this->info_box_contents[$line][] = array(
175 'td' =>
'class="tdoverflowmax150"',
176 'text' => $thirdpartystatic->getNomUrl(1,
'supplier'),
180 $this->info_box_contents[$line][] = array(
181 'td' =>
'class="nowraponall right amount"',
182 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
185 $this->info_box_contents[$line][] = array(
190 $this->info_box_contents[$line][] = array(
191 'td' =>
'class="right" width="18"',
192 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $alreadypaid, $objp->type),
205 $this->db->free($result);
207 $this->info_box_contents[0][0] = array(
210 'text' => ($this->db->error().
' sql='.$sql),
214 $this->info_box_contents[0][0] = array(
215 'td' =>
'class="nohover left"',
216 'text' =>
'<span class="opacitymedium">'.$langs->transnoentities(
"ReadPermissionNotAllowed").
'</span>'