79 global $user, $langs, $conf;
80 $langs->load(
"boxes");
84 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
85 $thirdpartystatic =
new Societe($this->db);
87 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastOutstandingBillReached", $max));
89 if ($user->hasRight(
'societe',
'lire')) {
90 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
91 $sql .=
", s.code_client, s.code_compta, s.client";
92 $sql .=
", s.logo, s.email, s.entity";
93 $sql .=
", s.outstanding_limit";
94 $sql .=
", s.datec, s.tms, s.status";
95 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
96 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
97 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
99 $sql .=
" WHERE s.client IN (1, 3)";
100 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
101 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
102 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
105 $sql .=
" AND s.rowid = $user->socid";
107 $sql .=
" AND s.outstanding_limit > 0";
108 $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)";
109 $sql .=
" ORDER BY s.tms DESC";
112 dol_syslog(get_class($this).
"::loadBox", LOG_DEBUG);
113 $result = $this->db->query($sql);
115 $num = $this->db->num_rows($result);
117 $nboutstandingbillreachedcustomers = 0;
120 while ($line < $num) {
121 $objp = $this->db->fetch_object($result);
122 $datec = $this->db->jdate($objp->datec);
123 $datem = $this->db->jdate($objp->tms);
125 $thirdpartystatic->id = $objp->socid;
126 $thirdpartystatic->name = $objp->name;
128 $thirdpartystatic->code_client = $objp->code_client;
129 $thirdpartystatic->code_compta = $objp->code_compta;
130 $thirdpartystatic->client = $objp->client;
131 $thirdpartystatic->logo = $objp->logo;
132 $thirdpartystatic->email = $objp->email;
133 $thirdpartystatic->entity = $objp->entity;
134 $thirdpartystatic->outstanding_limit = $objp->outstanding_limit;
136 $tmp = $thirdpartystatic->getOutstandingBills();
137 $outstandingtotal = $tmp[
'opened'];
138 $outstandinglimit = $thirdpartystatic->outstanding_limit;
140 if ($outstandingtotal >= $outstandinglimit) {
141 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
143 'text' => $thirdpartystatic->getNomUrl(1,
'customer'),
147 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
148 'td' =>
'class="right" width="18"',
149 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
151 $nboutstandingbillreachedcustomers++;
157 if ($num == 0 || $nboutstandingbillreachedcustomers == 0) {
158 $this->info_box_contents[0][] = array(
159 'td' =>
'class="center"',
160 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>'
164 $this->db->free($result);
166 $this->info_box_contents[0][0] = array(
169 'text' => ($this->db->error().
' sql='.$sql)
173 $this->info_box_contents[0][0] = array(
174 'td' =>
'class="nohover left"',
175 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'