62 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 $langs->load(
"bills");
75 $textHead = $langs->trans(
"BoxTitleOldestUnpaidSupplierBills");
76 $this->info_box_head = array(
77 'text' => $langs->trans(
"BoxTitleOldestUnpaidSupplierBills", $this->max).
'<a class="paddingleft valignmiddle" href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?search_status=1&sortfield=f.date_lim_reglement,f.ref&sortorder=ASC,ASC"><span class="badge">...</span></a>',
81 if ($user->hasRight(
'fournisseur',
'facture',
'lire')) {
82 $sql1 =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
83 $sql1 .=
", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
84 $sql1 .=
", s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6";
85 $sql1 .=
", f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite";
86 $sql1 .=
", f.datef as df";
87 $sql1 .=
", f.total_ht";
88 $sql1 .=
", f.total_tva";
89 $sql1 .=
", f.total_ttc";
90 $sql1 .=
", f.paye, f.fk_statut as status, f.type";
92 $sql1 .=
", SUM(pf.amount) as am";
93 $sql2 =
" FROM ".MAIN_DB_PREFIX.
"societe as s";
94 $sql2 .=
",".MAIN_DB_PREFIX.
"facture_fourn as f";
95 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
96 if (!$user->hasRight(
'societe',
'client',
'voir')) {
97 $sql2 .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
99 $sql2 .=
" WHERE f.fk_soc = s.rowid";
100 $sql2 .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
101 $sql2 .=
" AND f.paye = 0";
102 $sql2 .=
" AND fk_statut = 1";
103 if (!$user->hasRight(
'societe',
'client',
'voir')) {
104 $sql2 .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
107 $sql2 .=
" AND s.rowid = ".((int) $user->socid);
109 $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,";
110 $sql3 .=
" f.rowid, f.ref, f.ref_supplier, f.date_lim_reglement,";
111 $sql3 .=
" f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.tms";
112 $sql3 .=
" ORDER BY datelimite ASC, f.ref_supplier ASC";
113 $sql3 .= $this->db->plimit($this->max + 1, 0);
115 $sql = $sql1.$sql2.$sql3;
117 $result = $this->db->query($sql);
119 $num = $this->db->num_rows($result);
122 $l_due_date = $langs->trans(
'Late').
' ('.strtolower($langs->trans(
'DateDue')).
': %s)';
124 while ($line < min($num, $this->max)) {
125 $objp = $this->db->fetch_object($result);
127 $datelimite = $this->db->jdate($objp->datelimite);
128 $date = $this->db->jdate($objp->df);
129 $datem = $this->db->jdate($objp->tms);
131 $facturestatic->id = $objp->facid;
132 $facturestatic->ref = $objp->ref;
133 $facturestatic->type = $objp->type;
134 $facturestatic->total_ht = $objp->total_ht;
135 $facturestatic->total_tva = $objp->total_tva;
136 $facturestatic->total_ttc = $objp->total_ttc;
137 $facturestatic->date = $date;
138 $facturestatic->date_echeance = $datelimite;
139 $facturestatic->statut = $objp->status;
140 $facturestatic->status = $objp->status;
144 $facturestatic->paye = $objp->paye;
145 $facturestatic->paid = $objp->paye;
146 $facturestatic->alreadypaid = $objp->am;
147 $facturestatic->totalpaid = $objp->am;
149 $thirdpartystatic->id = $objp->socid;
150 $thirdpartystatic->name = $objp->name;
151 $thirdpartystatic->name_alias = $objp->name_alias;
152 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
153 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
154 $thirdpartystatic->fournisseur = $objp->fournisseur;
155 $thirdpartystatic->logo = $objp->logo;
156 $thirdpartystatic->email = $objp->email;
157 $thirdpartystatic->entity = $objp->entity;
158 $thirdpartystatic->tva_intra = $objp->tva_intra;
159 $thirdpartystatic->idprof1 = !empty($objp->idprof1) ? $objp->idprof1 :
'';
160 $thirdpartystatic->idprof2 = !empty($objp->idprof2) ? $objp->idprof2 :
'';
161 $thirdpartystatic->idprof3 = !empty($objp->idprof3) ? $objp->idprof3 :
'';
162 $thirdpartystatic->idprof4 = !empty($objp->idprof4) ? $objp->idprof4 :
'';
163 $thirdpartystatic->idprof5 = !empty($objp->idprof5) ? $objp->idprof5 :
'';
164 $thirdpartystatic->idprof6 = !empty($objp->idprof6) ? $objp->idprof6 :
'';
167 if ($facturestatic->hasDelay()) {
172 $tooltip = $langs->trans(
'SupplierInvoice').
': '.($objp->ref ? $objp->ref : $objp->facid).
'<br>'.$langs->trans(
'RefSupplier').
': '.$objp->ref_supplier;
174 $this->info_box_contents[$line][] = array(
175 'td' =>
'class="nowraponall"',
176 'text' => $facturestatic->getNomUrl(1),
181 $this->info_box_contents[$line][] = array(
182 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
183 'text' => $thirdpartystatic->getNomUrl(1,
'', 44),
187 $this->info_box_contents[$line][] = array(
188 'td' =>
'class="nowraponall right amount"',
189 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1,
$conf->currency),
192 $this->info_box_contents[$line][] = array(
197 $this->info_box_contents[$line][] = array(
198 'td' =>
'class="right" width="18"',
199 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am, $objp->type),
204 if ($this->max < $num) {
205 $this->info_box_contents[$line][] = array(
'td' =>
'colspan="6"',
'text' =>
'...');
210 $this->info_box_contents[$line][0] = array(
211 'td' =>
'class="center" colspan="3"',
212 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoUnpaidSupplierBills").
'</span>',
215 $sql =
"SELECT SUM(f.total_ht) as total_ht ".$sql2;
217 $result = $this->db->query($sql);
218 $objp = $this->db->fetch_object($result);
219 $totalamount = $objp->total_ht;
222 $this->info_box_contents[$line][] = array(
223 'tr' =>
'class="liste_total_wrap"',
224 'td' =>
'class="liste_total"',
225 'text' => $langs->trans(
"Total"),
227 $this->info_box_contents[$line][] = array(
228 'td' =>
'class="liste_total"',
231 $this->info_box_contents[$line][] = array(
232 'td' =>
'class="right liste_total" ',
233 'text' =>
price($totalamount, 0, $langs, 0, -1, -1,
$conf->currency),
235 $this->info_box_contents[$line][] = array(
236 'td' =>
'class="liste_total"',
239 $this->info_box_contents[$line][] = array(
240 'td' =>
'class="liste_total"',
244 $this->db->free($result);
247 $this->info_box_contents[0][0] = array(
250 'text' => ($this->db->error().
' sql='.$sql),
254 $this->info_box_contents[0][0] = array(
255 'td' =>
'class="nohover left"',
256 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'