66 global $conf, $user, $langs;
71 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
72 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
74 $facturestatic =
new Facture($this->db);
75 $societestatic =
new Societe($this->db);
77 $langs->load(
"bills");
79 $textHead = $langs->trans(
"BoxTitleOldestUnpaidCustomerBills");
80 $this->info_box_head = array(
81 '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>',
84 if ($user->hasRight(
'facture',
'lire')) {
85 $sql1 =
"SELECT s.rowid as socid, s.nom as name, s.name_alias, s.code_client, s.client";
87 $sql1 .=
", spe.accountancy_code_customer as code_compta_client";
89 $sql1 .=
", s.code_compta as code_compta_client";
91 $sql1 .=
", s.logo, s.email, s.entity";
92 $sql1 .=
", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
93 $sql1 .=
", f.ref, f.date_lim_reglement as datelimit";
95 $sql1 .=
", f.datef as date";
96 $sql1 .=
", f.total_ht";
97 $sql1 .=
", f.total_tva";
98 $sql1 .=
", f.total_ttc";
99 $sql1 .=
", f.paye, f.fk_statut as status, f.rowid as facid";
100 $sql1 .=
", SUM(pf.amount) as am";
101 $sql2 =
" FROM ".MAIN_DB_PREFIX.
"societe as s";
103 $sql2 .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
105 if (!$user->hasRight(
'societe',
'client',
'voir')) {
106 $sql2 .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
108 $sql2 .=
", ".MAIN_DB_PREFIX.
"facture as f";
109 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
110 $sql2 .=
" WHERE f.fk_soc = s.rowid";
111 $sql2 .=
" AND f.entity IN (".getEntity(
'invoice').
")";
112 $sql2 .=
" AND f.paye = 0";
113 $sql2 .=
" AND fk_statut = 1";
114 if (!$user->hasRight(
'societe',
'client',
'voir')) {
115 $sql2 .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
118 $sql2 .=
" AND s.rowid = ".((int) $user->socid);
120 $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,";
122 $sql3 .=
" spe.accountancy_code_customer,";
124 $sql3 .=
" s.code_compta,";
126 $sql3 .=
" f.rowid, f.ref, f.date_lim_reglement,";
127 $sql3 .=
" f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut";
128 $sql3 .=
" ORDER BY date_lim_reglement ASC, f.ref ASC";
129 $sql3 .= $this->db->plimit($this->max + 1, 0);
131 $sql = $sql1.$sql2.$sql3;
133 $result = $this->db->query($sql);
135 $num = $this->db->num_rows($result);
138 $l_due_date = $langs->trans(
'Late').
' ('.strtolower($langs->trans(
'DateDue')).
': %s)';
140 while ($line < min($num, $this->max)) {
141 $objp = $this->db->fetch_object($result);
143 $date = $this->db->jdate($objp->date);
144 $datelimit = $this->db->jdate($objp->datelimit);
146 $facturestatic->id = $objp->facid;
147 $facturestatic->ref = $objp->ref;
148 $facturestatic->type = $objp->type;
149 $facturestatic->total_ht = $objp->total_ht;
150 $facturestatic->total_tva = $objp->total_tva;
151 $facturestatic->total_ttc = $objp->total_ttc;
152 $facturestatic->date = $date;
153 $facturestatic->date_lim_reglement = $datelimit;
154 $facturestatic->statut = $objp->status;
155 $facturestatic->status = $objp->status;
157 $facturestatic->paye = $objp->paye;
158 $facturestatic->paid = $objp->paye;
159 $facturestatic->alreadypaid = $objp->am;
160 $facturestatic->totalpaid = $objp->am;
162 $societestatic->id = $objp->socid;
163 $societestatic->name = $objp->name;
165 $societestatic->code_client = $objp->code_client;
166 $societestatic->code_compta = $objp->code_compta_client;
167 $societestatic->code_compta_client = $objp->code_compta_client;
168 $societestatic->client = $objp->client;
169 $societestatic->logo = $objp->logo;
170 $societestatic->email = $objp->email;
171 $societestatic->entity = $objp->entity;
172 $societestatic->tva_intra = $objp->tva_intra;
174 $societestatic->idprof1 = !empty($objp->idprof1) ? $objp->idprof1 :
'';
175 $societestatic->idprof2 = !empty($objp->idprof2) ? $objp->idprof2 :
'';
176 $societestatic->idprof3 = !empty($objp->idprof3) ? $objp->idprof3 :
'';
177 $societestatic->idprof4 = !empty($objp->idprof4) ? $objp->idprof4 :
'';
178 $societestatic->idprof5 = !empty($objp->idprof5) ? $objp->idprof5 :
'';
179 $societestatic->idprof6 = !empty($objp->idprof6) ? $objp->idprof6 :
'';
182 if ($facturestatic->hasDelay()) {
187 $this->info_box_contents[$line][] = array(
188 'td' =>
'class="nowraponall"',
189 'text' => $facturestatic->getNomUrl(1),
194 $this->info_box_contents[$line][] = array(
195 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
196 'text' => $societestatic->getNomUrl(1,
'', 44),
200 $this->info_box_contents[$line][] = array(
201 'td' =>
'class="nowraponall right amount"',
202 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
205 $this->info_box_contents[$line][] = array(
210 $this->info_box_contents[$line][] = array(
211 'td' =>
'class="right" width="18"',
212 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am, $objp->type),
217 if ($this->max < $num) {
218 $this->info_box_contents[$line][] = array(
'td' =>
'colspan="6"',
'text' =>
'...');
223 $this->info_box_contents[$line][0] = array(
224 'td' =>
'class="center" colspan="3"',
225 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoUnpaidCustomerBills").
'</span>'
228 $sql =
"SELECT SUM(f.total_ht) as total_ht ".$sql2;
230 $result = $this->db->query($sql);
231 $objp = $this->db->fetch_object($result);
232 $totalamount = $objp->total_ht;
235 $this->info_box_contents[$line][] = array(
236 'tr' =>
'class="liste_total_wrap"',
237 'td' =>
'class="liste_total"',
238 'text' => $langs->trans(
"Total"),
240 $this->info_box_contents[$line][] = array(
241 'td' =>
'class="liste_total"',
244 $this->info_box_contents[$line][] = array(
245 'td' =>
'class="right liste_total" ',
246 'text' =>
price($totalamount, 0, $langs, 0, -1, -1, $conf->currency),
248 $this->info_box_contents[$line][] = array(
249 'td' =>
'class="liste_total"',
252 $this->info_box_contents[$line][] = array(
253 'td' =>
'class="liste_total"',
257 $this->db->free($result);
260 $this->info_box_contents[0][0] = array(
263 'text' => ($this->db->error().
' sql='.$sql),
267 $this->info_box_contents[0][0] = array(
268 'td' =>
'class="nohover left"',
269 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'