75 global $user, $langs, $conf;
76 $langs->load(
"boxes");
80 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
81 $thirdpartystatic =
new Societe($this->db);
83 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleGoodCustomers", $max));
85 if ($user->hasRight(
'societe',
'lire')) {
86 $sql =
"SELECT s.rowid, s.nom as name, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms as datem, s.status as status,";
87 $sql .=
" count(*) as nbfact, sum(".$this->db->ifsql(
'f.paye=1',
'1',
'0').
") as nbfactpaye";
88 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"facture as f";
89 $sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
90 $sql .=
' AND s.rowid = f.fk_soc';
91 $sql .=
" GROUP BY s.rowid, s.nom, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms, s.status";
92 $sql .= $this->db->order(
"nbfact",
"DESC");
93 $sql .= $this->db->plimit($max, 0);
95 dol_syslog(get_class($this).
"::loadBox", LOG_DEBUG);
96 $result = $this->db->query($sql);
98 $num = $this->db->num_rows($result);
101 while ($line < $num) {
102 $objp = $this->db->fetch_object($result);
103 $datem = $this->db->jdate($objp->tms);
104 $thirdpartystatic->id = $objp->rowid;
105 $thirdpartystatic->name = $objp->name;
106 $thirdpartystatic->code_client = $objp->code_client;
107 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
108 $thirdpartystatic->client = $objp->client;
109 $thirdpartystatic->fournisseur = $objp->fournisseur;
110 $thirdpartystatic->logo = $objp->logo;
111 $nbfact = $objp->nbfact;
112 $nbimpaye = $objp->nbfact - $objp->nbfactpaye;
114 $this->info_box_contents[$line][] = array(
115 'td' =>
'class="tdoverflowmax150"',
116 'text' => $thirdpartystatic->getNomUrl(1),
120 $this->info_box_contents[$line][] = array(
121 'td' =>
'class="center nowraponall"',
125 $this->info_box_contents[$line][] = array(
126 'td' =>
'class="right"',
127 'text' => $nbfact.($nbimpaye != 0 ?
' ('.$nbimpaye.
')' :
'')
130 $this->info_box_contents[$line][] = array(
131 'td' =>
'class="right" width="18"',
132 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
139 $this->info_box_contents[$line][0] = array(
140 'td' =>
'class="center"',
141 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedCustomers").
'</span>'
145 $this->db->free($result);
147 $this->info_box_contents[0][0] = array(
150 'text' => ($this->db->error().
' sql='.$sql),
154 $this->info_box_contents[0][0] = array(
155 'td' =>
'class="nohover left"',
156 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'