71 global $user, $langs, $conf;
72 $langs->load(
"boxes");
76 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
77 $thirdpartystatic =
new Societe($this->db);
79 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastOutstandingBillReached", $max));
81 if ($user->hasRight(
'societe',
'lire')) {
82 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
83 $sql .=
", s.code_client, s.code_compta, s.client";
84 $sql .=
", s.logo, s.email, s.entity";
85 $sql .=
", s.outstanding_limit";
86 $sql .=
", s.datec, s.tms, s.status";
87 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
88 if (!$user->hasRight(
'societe',
'client',
'voir')) {
89 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
91 $sql .=
" WHERE s.client IN (1, 3)";
92 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
93 if (!$user->hasRight(
'societe',
'client',
'voir')) {
94 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
97 $sql .=
" AND s.rowid = $user->socid";
99 $sql .=
" AND s.outstanding_limit > 0";
100 $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)";
101 $sql .=
" ORDER BY s.tms DESC";
104 dol_syslog(get_class($this).
"::loadBox", LOG_DEBUG);
105 $result = $this->db->query($sql);
107 $num = $this->db->num_rows($result);
109 $nboutstandingbillreachedcustomers = 0;
112 while ($line < $num) {
113 $objp = $this->db->fetch_object($result);
114 $datec = $this->db->jdate($objp->datec);
115 $datem = $this->db->jdate($objp->tms);
117 $thirdpartystatic->id = $objp->socid;
118 $thirdpartystatic->name = $objp->name;
120 $thirdpartystatic->code_client = $objp->code_client;
121 $thirdpartystatic->code_compta = $objp->code_compta;
122 $thirdpartystatic->code_compta_client = $objp->code_compta;
123 $thirdpartystatic->client = $objp->client;
124 $thirdpartystatic->logo = $objp->logo;
125 $thirdpartystatic->email = $objp->email;
126 $thirdpartystatic->entity = $objp->entity;
127 $thirdpartystatic->outstanding_limit = $objp->outstanding_limit;
129 $tmp = $thirdpartystatic->getOutstandingBills();
130 $outstandingtotal = $tmp[
'opened'];
131 $outstandinglimit = $thirdpartystatic->outstanding_limit;
133 if ($outstandingtotal >= $outstandinglimit) {
134 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
136 'text' => $thirdpartystatic->getNomUrl(1,
'customer'),
140 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
141 'td' =>
'class="right" width="18"',
142 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
144 $nboutstandingbillreachedcustomers++;
150 if ($num == 0 || $nboutstandingbillreachedcustomers == 0) {
151 $this->info_box_contents[0][] = array(
152 'td' =>
'class="center"',
153 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>'
157 $this->db->free($result);
159 $this->info_box_contents[0][0] = array(
162 'text' => ($this->db->error().
' sql='.$sql)
166 $this->info_box_contents[0][0] = array(
167 'td' =>
'class="nohover left"',
168 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'