72 global $conf, $user, $langs;
77 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
78 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
83 $langs->load(
"bills");
85 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleOldestUnpaidSupplierBills", $this->max));
87 if ($user->hasRight(
'fournisseur',
'facture',
'lire')) {
88 $sql1 =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
89 $sql1 .=
", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
90 $sql1 .=
", s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6";
91 $sql1 .=
", f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite";
92 $sql1 .=
", f.datef as df";
93 $sql1 .=
", f.total_ht";
94 $sql1 .=
", f.total_tva";
95 $sql1 .=
", f.total_ttc";
96 $sql1 .=
", f.paye, f.fk_statut as status, f.type";
98 $sql1 .=
", SUM(pf.amount) as am";
99 $sql2 =
" FROM ".MAIN_DB_PREFIX.
"societe as s";
100 $sql2 .=
",".MAIN_DB_PREFIX.
"facture_fourn as f";
101 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
102 if (empty($user->rights->societe->client->voir) && !$user->socid) {
103 $sql2 .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
105 $sql2 .=
" WHERE f.fk_soc = s.rowid";
106 $sql2 .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
107 $sql2 .=
" AND f.paye = 0";
108 $sql2 .=
" AND fk_statut = 1";
109 if (empty($user->rights->societe->client->voir) && !$user->socid) {
110 $sql2 .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
113 $sql2 .=
" AND s.rowid = ".((int) $user->socid);
115 $sql3 =
" GROUP BY s.rowid, s.nom, s.name_alias, s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
116 $sql3 .=
" f.rowid, f.ref, f.ref_supplier, f.date_lim_reglement,";
117 $sql3 .=
" f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.tms";
118 $sql3 .=
" ORDER BY datelimite DESC, f.ref_supplier DESC ";
119 $sql3 .= $this->db->plimit($this->max + 1, 0);
121 $sql = $sql1.$sql2.$sql3;
123 $result = $this->db->query($sql);
125 $num = $this->db->num_rows($result);
128 $l_due_date = $langs->trans(
'Late').
' ('.strtolower($langs->trans(
'DateDue')).
': %s)';
130 while ($line < min($num, $this->max)) {
131 $objp = $this->db->fetch_object($result);
133 $datelimite = $this->db->jdate($objp->datelimite);
134 $date = $this->db->jdate($objp->df);
135 $datem = $this->db->jdate($objp->tms);
137 $facturestatic->id = $objp->facid;
138 $facturestatic->ref = $objp->ref;
139 $facturestatic->type = $objp->type;
140 $facturestatic->total_ht = $objp->total_ht;
141 $facturestatic->total_tva = $objp->total_tva;
142 $facturestatic->total_ttc = $objp->total_ttc;
143 $facturestatic->date = $date;
144 $facturestatic->date_echeance = $datelimite;
145 $facturestatic->statut = $objp->status;
146 $facturestatic->status = $objp->status;
150 $facturestatic->paye = $objp->paye;
151 $facturestatic->alreadypaid = $objp->am;
153 $thirdpartystatic->id = $objp->socid;
154 $thirdpartystatic->name = $objp->name;
155 $thirdpartystatic->name_alias = $objp->name_alias;
156 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
157 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
158 $thirdpartystatic->fournisseur = $objp->fournisseur;
159 $thirdpartystatic->logo = $objp->logo;
160 $thirdpartystatic->email = $objp->email;
161 $thirdpartystatic->entity = $objp->entity;
162 $thirdpartystatic->tva_intra = $objp->tva_intra;
163 $thirdpartystatic->idprof1 = !empty($objp->idprof1) ? $objp->idprof1 :
'';
164 $thirdpartystatic->idprof2 = !empty($objp->idprof2) ? $objp->idprof2 :
'';
165 $thirdpartystatic->idprof3 = !empty($objp->idprof3) ? $objp->idprof3 :
'';
166 $thirdpartystatic->idprof4 = !empty($objp->idprof4) ? $objp->idprof4 :
'';
167 $thirdpartystatic->idprof5 = !empty($objp->idprof5) ? $objp->idprof5 :
'';
168 $thirdpartystatic->idprof6 = !empty($objp->idprof6) ? $objp->idprof6 :
'';
171 if ($facturestatic->hasDelay()) {
175 $tooltip = $langs->trans(
'SupplierInvoice').
': '.($objp->ref ? $objp->ref : $objp->facid).
'<br>'.$langs->trans(
'RefSupplier').
': '.$objp->ref_supplier;
177 $this->info_box_contents[$line][] = array(
178 'td' =>
'class="nowraponall"',
179 'text' => $facturestatic->getNomUrl(1),
184 $this->info_box_contents[$line][] = array(
185 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
186 'text' => $thirdpartystatic->getNomUrl(1,
'', 44),
190 $this->info_box_contents[$line][] = array(
191 'td' =>
'class="nowraponall right amount"',
192 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
195 $this->info_box_contents[$line][] = array(
200 $this->info_box_contents[$line][] = array(
201 'td' =>
'class="right" width="18"',
202 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am, $objp->type),
207 if ($this->max < $num) {
208 $this->info_box_contents[$line][] = array(
'td' =>
'colspan="6"',
'text' =>
'...');
213 $this->info_box_contents[$line][0] = array(
214 'td' =>
'class="center opacitymedium"',
215 'text'=>$langs->trans(
"NoUnpaidSupplierBills"),
219 $sql =
"SELECT SUM(f.total_ht) as total_ht ".$sql2;
221 $result = $this->db->query($sql);
222 $objp = $this->db->fetch_object($result);
223 $totalamount = $objp->total_ht;
226 $this->info_box_contents[$line][] = array(
227 'tr' =>
'class="liste_total_wrap"',
228 'td' =>
'class="liste_total"',
229 'text' => $langs->trans(
"Total"),
231 $this->info_box_contents[$line][] = array(
232 'td' =>
'class="liste_total"',
235 $this->info_box_contents[$line][] = array(
236 'td' =>
'class="right liste_total" ',
237 'text' =>
price($totalamount, 0, $langs, 0, -1, -1, $conf->currency),
239 $this->info_box_contents[$line][] = array(
240 'td' =>
'class="liste_total"',
243 $this->info_box_contents[$line][] = array(
244 'td' =>
'class="liste_total"',
248 $this->db->free($result);
250 $this->info_box_contents[0][0] = array(
253 'text' => ($this->db->error().
' sql='.$sql),
257 $this->info_box_contents[0][0] = array(
258 'td' =>
'class="nohover opacitymedium left"',
259 'text' => $langs->trans(
"ReadPermissionNotAllowed")