76 global $conf, $user, $langs;
81 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
82 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
84 $facturestatic =
new Facture($this->db);
85 $societestatic =
new Societe($this->db);
87 $langs->load(
"bills");
89 $textHead = $langs->trans(
"BoxTitleOldestUnpaidCustomerBills");
90 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleOldestUnpaidCustomerBills", $this->max),
'limit'=>
dol_strlen($textHead));
92 if ($user->hasRight(
'facture',
'lire')) {
93 $sql1 =
"SELECT s.rowid as socid, s.nom as name, s.name_alias, s.code_client, s.client";
95 $sql1 .=
", spe.accountancy_code_customer as code_compta";
97 $sql1 .=
", s.code_compta";
99 $sql1 .=
", s.logo, s.email, s.entity";
100 $sql1 .=
", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
101 $sql1 .=
", f.ref, f.date_lim_reglement as datelimite";
103 $sql1 .=
", f.datef as date";
104 $sql1 .=
", f.total_ht";
105 $sql1 .=
", f.total_tva";
106 $sql1 .=
", f.total_ttc";
107 $sql1 .=
", f.paye, f.fk_statut as status, f.rowid as facid";
108 $sql1 .=
", SUM(pf.amount) as am";
109 $sql2 =
" FROM ".MAIN_DB_PREFIX.
"societe as s";
111 $sql2 .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
113 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
114 $sql2 .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
116 $sql2 .=
", ".MAIN_DB_PREFIX.
"facture as f";
117 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
118 $sql2 .=
" WHERE f.fk_soc = s.rowid";
119 $sql2 .=
" AND f.entity IN (".getEntity(
'invoice').
")";
120 $sql2 .=
" AND f.paye = 0";
121 $sql2 .=
" AND fk_statut = 1";
122 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
123 $sql2 .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
126 $sql2 .=
" AND s.rowid = ".((int) $user->socid);
128 $sql3 =
" GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
130 $sql3 .=
" spe.accountancy_code_customer,";
132 $sql3 .=
" s.code_compta,";
134 $sql3 .=
" f.rowid, f.ref, f.date_lim_reglement,";
135 $sql3 .=
" f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut";
136 $sql3 .=
" ORDER BY datelimite ASC, f.ref ASC ";
137 $sql3 .= $this->db->plimit($this->max + 1, 0);
139 $sql = $sql1.$sql2.$sql3;
141 $result = $this->db->query($sql);
143 $num = $this->db->num_rows($result);
146 $l_due_date = $langs->trans(
'Late').
' ('.strtolower($langs->trans(
'DateDue')).
': %s)';
148 while ($line < min($num, $this->max)) {
149 $objp = $this->db->fetch_object($result);
151 $datelimite = $this->db->jdate($objp->datelimite);
153 $facturestatic->id = $objp->facid;
154 $facturestatic->ref = $objp->ref;
155 $facturestatic->type = $objp->type;
156 $facturestatic->total_ht = $objp->total_ht;
157 $facturestatic->total_tva = $objp->total_tva;
158 $facturestatic->total_ttc = $objp->total_ttc;
159 $facturestatic->statut = $objp->status;
160 $facturestatic->status = $objp->status;
161 $facturestatic->date = $this->db->jdate($objp->date);
162 $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
164 $facturestatic->paye = $objp->paye;
165 $facturestatic->alreadypaid = $objp->am;
167 $societestatic->id = $objp->socid;
168 $societestatic->name = $objp->name;
170 $societestatic->code_client = $objp->code_client;
171 $societestatic->code_compta = $objp->code_compta;
172 $societestatic->client = $objp->client;
173 $societestatic->logo = $objp->logo;
174 $societestatic->email = $objp->email;
175 $societestatic->entity = $objp->entity;
176 $societestatic->tva_intra = $objp->tva_intra;
177 $societestatic->idprof1 = $objp->idprof1;
178 $societestatic->idprof2 = $objp->idprof2;
179 $societestatic->idprof3 = $objp->idprof3;
180 $societestatic->idprof4 = $objp->idprof4;
181 $societestatic->idprof5 = $objp->idprof5;
182 $societestatic->idprof6 = $objp->idprof6;
185 if ($facturestatic->hasDelay()) {
189 $this->info_box_contents[$line][] = array(
190 'td' =>
'class="nowraponall"',
191 'text' => $facturestatic->getNomUrl(1),
196 $this->info_box_contents[$line][] = array(
197 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
198 'text' => $societestatic->getNomUrl(1,
'', 44),
202 $this->info_box_contents[$line][] = array(
203 'td' =>
'class="nowraponall right amount"',
204 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
207 $this->info_box_contents[$line][] = array(
212 $this->info_box_contents[$line][] = array(
213 'td' =>
'class="right" width="18"',
214 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
219 if ($this->max < $num) {
220 $this->info_box_contents[$line][] = array(
'td' =>
'colspan="6"',
'text' =>
'...');
225 $this->info_box_contents[$line][0] = array(
226 'td' =>
'class="center"',
227 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoUnpaidCustomerBills").
'</span>'
231 $sql =
"SELECT SUM(f.total_ht) as total_ht ".$sql2;
233 $result = $this->db->query($sql);
234 $objp = $this->db->fetch_object($result);
235 $totalamount = $objp->total_ht;
238 $this->info_box_contents[$line][] = array(
239 'tr' =>
'class="liste_total_wrap"',
240 'td' =>
'class="liste_total"',
241 'text' => $langs->trans(
"Total"),
243 $this->info_box_contents[$line][] = array(
244 'td' =>
'class="liste_total"',
247 $this->info_box_contents[$line][] = array(
248 'td' =>
'class="right liste_total" ',
249 'text' =>
price($totalamount, 0, $langs, 0, -1, -1, $conf->currency),
251 $this->info_box_contents[$line][] = array(
252 'td' =>
'class="liste_total"',
255 $this->info_box_contents[$line][] = array(
256 'td' =>
'class="liste_total"',
260 $this->db->free($result);
262 $this->info_box_contents[0][0] = array(
265 'text' => ($this->db->error().
' sql='.$sql),
269 $this->info_box_contents[0][0] = array(
270 'td' =>
'class="nohover left"',
271 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'