70 global $user, $langs, $conf;
71 $langs->load(
"boxes");
75 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
76 $thirdpartystatic =
new Societe($this->db);
78 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastOutstandingBillReached", $max));
80 if ($user->hasRight(
'societe',
'lire')) {
81 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
82 $sql .=
", s.code_client, s.code_compta, s.client";
83 $sql .=
", s.logo, s.email, s.entity";
84 $sql .=
", s.outstanding_limit";
85 $sql .=
", s.datec, s.tms, s.status";
86 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
87 if (!$user->hasRight(
'societe',
'client',
'voir')) {
88 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
90 $sql .=
" WHERE s.client IN (1, 3)";
91 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
92 if (!$user->hasRight(
'societe',
'client',
'voir')) {
93 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
96 $sql .=
" AND s.rowid = $user->socid";
98 $sql .=
" AND s.outstanding_limit > 0";
99 $sql .=
" AND s.rowid IN (SELECT fk_soc from ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_statut = 1 and f.fk_soc = s.rowid)";
100 $sql .=
" ORDER BY s.tms DESC";
103 dol_syslog(get_class($this).
"::loadBox", LOG_DEBUG);
104 $result = $this->db->query($sql);
106 $num = $this->db->num_rows($result);
108 $nboutstandingbillreachedcustomers = 0;
111 while ($line < $num) {
112 $objp = $this->db->fetch_object($result);
113 $datec = $this->db->jdate($objp->datec);
114 $datem = $this->db->jdate($objp->tms);
116 $thirdpartystatic->id = $objp->socid;
117 $thirdpartystatic->name = $objp->name;
119 $thirdpartystatic->code_client = $objp->code_client;
120 $thirdpartystatic->code_compta = $objp->code_compta;
121 $thirdpartystatic->client = $objp->client;
122 $thirdpartystatic->logo = $objp->logo;
123 $thirdpartystatic->email = $objp->email;
124 $thirdpartystatic->entity = $objp->entity;
125 $thirdpartystatic->outstanding_limit = $objp->outstanding_limit;
127 $tmp = $thirdpartystatic->getOutstandingBills();
128 $outstandingtotal = $tmp[
'opened'];
129 $outstandinglimit = $thirdpartystatic->outstanding_limit;
131 if ($outstandingtotal >= $outstandinglimit) {
132 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
134 'text' => $thirdpartystatic->getNomUrl(1,
'customer'),
138 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
139 'td' =>
'class="right" width="18"',
140 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
142 $nboutstandingbillreachedcustomers++;
148 if ($num == 0 || $nboutstandingbillreachedcustomers == 0) {
149 $this->info_box_contents[0][] = array(
150 'td' =>
'class="center"',
151 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>'
155 $this->db->free($result);
157 $this->info_box_contents[0][0] = array(
160 'text' => ($this->db->error().
' sql='.$sql)
164 $this->info_box_contents[0][0] = array(
165 'td' =>
'class="nohover left"',
166 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'