68 global
$conf, $user, $langs;
73 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
74 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
76 $facturestatic =
new Facture($this->db);
77 $societestatic =
new Societe($this->db);
79 $langs->load(
"bills");
81 $textHead = $langs->trans(
"BoxTitleOldestUnpaidCustomerBills");
82 $this->info_box_head = array(
83 '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>',
86 if ($user->hasRight(
'facture',
'lire')) {
87 $sql1 =
"SELECT s.rowid as socid, s.nom as name, s.name_alias, s.code_client, s.client";
89 $sql1 .=
", spe.accountancy_code_customer as code_compta_client";
91 $sql1 .=
", s.code_compta as code_compta_client";
93 $sql1 .=
", s.logo, s.email, s.entity";
94 $sql1 .=
", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
95 $sql1 .=
", f.ref, f.date_lim_reglement as datelimit";
97 $sql1 .=
", f.datef as date";
98 $sql1 .=
", f.total_ht";
99 $sql1 .=
", f.total_tva";
100 $sql1 .=
", f.total_ttc";
101 $sql1 .=
", f.paye, f.fk_statut as status, f.rowid as facid";
102 $sql1 .=
", SUM(pf.amount) as am";
103 $sql2 =
" FROM ".MAIN_DB_PREFIX.
"societe as s";
105 $sql2 .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
107 if (!$user->hasRight(
'societe',
'client',
'voir')) {
108 $sql2 .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
110 $sql2 .=
", ".MAIN_DB_PREFIX.
"facture as f";
111 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
112 $sql2 .=
" WHERE f.fk_soc = s.rowid";
113 $sql2 .=
" AND f.entity IN (".getEntity(
'invoice').
")";
114 $sql2 .=
" AND f.paye = 0";
115 $sql2 .=
" AND fk_statut = 1";
116 if (!$user->hasRight(
'societe',
'client',
'voir')) {
117 $sql2 .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
120 $sql2 .=
" AND s.rowid = ".((int) $user->socid);
122 $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,";
124 $sql3 .=
" spe.accountancy_code_customer,";
126 $sql3 .=
" s.code_compta,";
128 $sql3 .=
" f.rowid, f.ref, f.date_lim_reglement,";
129 $sql3 .=
" f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut";
130 $sql3 .=
" ORDER BY date_lim_reglement ASC, f.ref ASC";
131 $sql3 .= $this->db->plimit($this->max + 1, 0);
133 $sql = $sql1.$sql2.$sql3;
135 $result = $this->db->query($sql);
137 $num = $this->db->num_rows($result);
140 $l_due_date = $langs->trans(
'Late').
' ('.strtolower($langs->trans(
'DateDue')).
': %s)';
142 while ($line < min($num, $this->max)) {
143 $objp = $this->db->fetch_object($result);
145 $date = $this->db->jdate($objp->date);
146 $datelimit = $this->db->jdate($objp->datelimit);
148 $facturestatic->id = $objp->facid;
149 $facturestatic->ref = $objp->ref;
150 $facturestatic->type = $objp->type;
151 $facturestatic->total_ht = $objp->total_ht;
152 $facturestatic->total_tva = $objp->total_tva;
153 $facturestatic->total_ttc = $objp->total_ttc;
154 $facturestatic->date = $date;
155 $facturestatic->date_lim_reglement = $datelimit;
156 $facturestatic->statut = $objp->status;
157 $facturestatic->status = $objp->status;
159 $facturestatic->paye = $objp->paye;
160 $facturestatic->paid = $objp->paye;
161 $facturestatic->alreadypaid = $objp->am;
162 $facturestatic->totalpaid = $objp->am;
164 $societestatic->id = $objp->socid;
165 $societestatic->name = $objp->name;
167 $societestatic->code_client = $objp->code_client;
168 $societestatic->code_compta = $objp->code_compta_client;
169 $societestatic->code_compta_client = $objp->code_compta_client;
170 $societestatic->client = $objp->client;
171 $societestatic->logo = $objp->logo;
172 $societestatic->email = $objp->email;
173 $societestatic->entity = $objp->entity;
174 $societestatic->tva_intra = $objp->tva_intra;
176 $societestatic->idprof1 = !empty($objp->idprof1) ? $objp->idprof1 :
'';
177 $societestatic->idprof2 = !empty($objp->idprof2) ? $objp->idprof2 :
'';
178 $societestatic->idprof3 = !empty($objp->idprof3) ? $objp->idprof3 :
'';
179 $societestatic->idprof4 = !empty($objp->idprof4) ? $objp->idprof4 :
'';
180 $societestatic->idprof5 = !empty($objp->idprof5) ? $objp->idprof5 :
'';
181 $societestatic->idprof6 = !empty($objp->idprof6) ? $objp->idprof6 :
'';
184 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, $objp->type),
219 if ($this->max < $num) {
220 $this->info_box_contents[$line][] = array(
'td' =>
'colspan="6"',
'text' =>
'...');
230 $sql =
"SELECT SUM(f.total_ht) as total_ht ".$sql2;
232 $result = $this->db->query($sql);
233 $objp = $this->db->fetch_object($result);
234 $totalamount = $objp->total_ht;
237 $this->info_box_contents[$line][] = array(
238 'tr' =>
'class="liste_total_wrap"',
239 'td' =>
'class="liste_total"',
240 'text' => $langs->trans(
"Total"),
242 $this->info_box_contents[$line][] = array(
243 'td' =>
'class="liste_total"',
246 $this->info_box_contents[$line][] = array(
247 'td' =>
'class="right liste_total" ',
248 'text' =>
price($totalamount, 0, $langs, 0, -1, -1,
$conf->currency),
250 $this->info_box_contents[$line][] = array(
251 'td' =>
'class="liste_total"',
254 $this->info_box_contents[$line][] = array(
255 'td' =>
'class="liste_total"',
259 $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>'