65 global $conf, $user, $langs;
70 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
71 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
73 $facturestatic =
new Facture($this->db);
74 $societestatic =
new Societe($this->db);
76 $langs->load(
"bills");
78 $textHead = $langs->trans(
"BoxTitleOldestUnpaidCustomerBills");
79 $this->info_box_head = array(
80 'text' => $langs->trans(
"BoxTitleOldestUnpaidCustomerBills", $this->max).
'<a class="paddingleft valignmiddle" href="'.DOL_URL_ROOT.
'/compta/facture/list.php?search_status=1&sortfield=f.date_lim_reglement,f.ref&sortorder=ASC,ASC"><span class="badge">...</span></a>',
83 if ($user->hasRight(
'facture',
'lire')) {
84 $sql1 =
"SELECT s.rowid as socid, s.nom as name, s.name_alias, s.code_client, s.client";
86 $sql1 .=
", spe.accountancy_code_customer as code_compta_client";
88 $sql1 .=
", s.code_compta as code_compta_client";
90 $sql1 .=
", s.logo, s.email, s.entity";
91 $sql1 .=
", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
92 $sql1 .=
", f.ref, f.date_lim_reglement as datelimit";
94 $sql1 .=
", f.datef as date";
95 $sql1 .=
", f.total_ht";
96 $sql1 .=
", f.total_tva";
97 $sql1 .=
", f.total_ttc";
98 $sql1 .=
", f.paye, f.fk_statut as status, f.rowid as facid";
99 $sql1 .=
", SUM(pf.amount) as am";
100 $sql2 =
" FROM ".MAIN_DB_PREFIX.
"societe as s";
102 $sql2 .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
104 if (!$user->hasRight(
'societe',
'client',
'voir')) {
105 $sql2 .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
107 $sql2 .=
", ".MAIN_DB_PREFIX.
"facture as f";
108 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
109 $sql2 .=
" WHERE f.fk_soc = s.rowid";
110 $sql2 .=
" AND f.entity IN (".getEntity(
'invoice').
")";
111 $sql2 .=
" AND f.paye = 0";
112 $sql2 .=
" AND fk_statut = 1";
113 if (!$user->hasRight(
'societe',
'client',
'voir')) {
114 $sql2 .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
117 $sql2 .=
" AND s.rowid = ".((int) $user->socid);
119 $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,";
121 $sql3 .=
" spe.accountancy_code_customer as code_compta,";
123 $sql3 .=
" s.code_compta,";
125 $sql3 .=
" f.rowid, f.ref, f.date_lim_reglement,";
126 $sql3 .=
" f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut";
127 $sql3 .=
" ORDER BY date_lim_reglement ASC, f.ref ASC";
128 $sql3 .= $this->db->plimit($this->max + 1, 0);
130 $sql = $sql1.$sql2.$sql3;
132 $result = $this->db->query($sql);
134 $num = $this->db->num_rows($result);
137 $l_due_date = $langs->trans(
'Late').
' ('.strtolower($langs->trans(
'DateDue')).
': %s)';
139 while ($line < min($num, $this->max)) {
140 $objp = $this->db->fetch_object($result);
142 $date = $this->db->jdate($objp->date);
143 $datelimit = $this->db->jdate($objp->datelimit);
145 $facturestatic->id = $objp->facid;
146 $facturestatic->ref = $objp->ref;
147 $facturestatic->type = $objp->type;
148 $facturestatic->total_ht = $objp->total_ht;
149 $facturestatic->total_tva = $objp->total_tva;
150 $facturestatic->total_ttc = $objp->total_ttc;
151 $facturestatic->date = $date;
152 $facturestatic->date_lim_reglement = $datelimit;
153 $facturestatic->statut = $objp->status;
154 $facturestatic->status = $objp->status;
156 $facturestatic->paye = $objp->paye;
157 $facturestatic->paid = $objp->paye;
158 $facturestatic->alreadypaid = $objp->am;
159 $facturestatic->totalpaid = $objp->am;
161 $societestatic->id = $objp->socid;
162 $societestatic->name = $objp->name;
164 $societestatic->code_client = $objp->code_client;
165 $societestatic->code_compta = $objp->code_compta_client;
166 $societestatic->code_compta_client = $objp->code_compta_client;
167 $societestatic->client = $objp->client;
168 $societestatic->logo = $objp->logo;
169 $societestatic->email = $objp->email;
170 $societestatic->entity = $objp->entity;
171 $societestatic->tva_intra = $objp->tva_intra;
173 $societestatic->idprof1 = !empty($objp->idprof1) ? $objp->idprof1 :
'';
174 $societestatic->idprof2 = !empty($objp->idprof2) ? $objp->idprof2 :
'';
175 $societestatic->idprof3 = !empty($objp->idprof3) ? $objp->idprof3 :
'';
176 $societestatic->idprof4 = !empty($objp->idprof4) ? $objp->idprof4 :
'';
177 $societestatic->idprof5 = !empty($objp->idprof5) ? $objp->idprof5 :
'';
178 $societestatic->idprof6 = !empty($objp->idprof6) ? $objp->idprof6 :
'';
181 if ($facturestatic->hasDelay()) {
186 $this->info_box_contents[$line][] = array(
187 'td' =>
'class="nowraponall"',
188 'text' => $facturestatic->getNomUrl(1),
193 $this->info_box_contents[$line][] = array(
194 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
195 'text' => $societestatic->getNomUrl(1,
'', 44),
199 $this->info_box_contents[$line][] = array(
200 'td' =>
'class="nowraponall right amount"',
201 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
204 $this->info_box_contents[$line][] = array(
209 $this->info_box_contents[$line][] = array(
210 'td' =>
'class="right" width="18"',
211 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am, $objp->type),
216 if ($this->max < $num) {
217 $this->info_box_contents[$line][] = array(
'td' =>
'colspan="6"',
'text' =>
'...');
222 $this->info_box_contents[$line][0] = array(
223 'td' =>
'class="center" colspan="3"',
224 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoUnpaidCustomerBills").
'</span>'
227 $sql =
"SELECT SUM(f.total_ht) as total_ht ".$sql2;
229 $result = $this->db->query($sql);
230 $objp = $this->db->fetch_object($result);
231 $totalamount = $objp->total_ht;
234 $this->info_box_contents[$line][] = array(
235 'tr' =>
'class="liste_total_wrap"',
236 'td' =>
'class="liste_total"',
237 'text' => $langs->trans(
"Total"),
239 $this->info_box_contents[$line][] = array(
240 'td' =>
'class="liste_total"',
243 $this->info_box_contents[$line][] = array(
244 'td' =>
'class="right liste_total" ',
245 'text' =>
price($totalamount, 0, $langs, 0, -1, -1, $conf->currency),
247 $this->info_box_contents[$line][] = array(
248 'td' =>
'class="liste_total"',
251 $this->info_box_contents[$line][] = array(
252 'td' =>
'class="liste_total"',
256 $this->db->free($result);
259 $this->info_box_contents[0][0] = array(
262 'text' => ($this->db->error().
' sql='.$sql),
266 $this->info_box_contents[0][0] = array(
267 'td' =>
'class="nohover left"',
268 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'