74 global $user, $langs, $conf;
75 $langs->load(
"boxes");
79 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
80 $thirdpartystatic =
new Societe($this->db);
82 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleGoodCustomers", $max));
84 if ($user->hasRight(
'societe',
'lire')) {
85 $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,";
86 $sql .=
" count(*) as nbfact, sum(".$this->db->ifsql(
'f.paye=1',
'1',
'0').
") as nbfactpaye";
87 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"facture as f";
88 $sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
89 $sql .=
' AND s.rowid = f.fk_soc';
90 $sql .=
" GROUP BY s.rowid, s.nom, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms, s.status";
91 $sql .= $this->db->order(
"nbfact",
"DESC");
92 $sql .= $this->db->plimit($max, 0);
94 dol_syslog(get_class($this).
"::loadBox", LOG_DEBUG);
95 $result = $this->db->query($sql);
97 $num = $this->db->num_rows($result);
100 while ($line < $num) {
101 $objp = $this->db->fetch_object($result);
102 $datem = $this->db->jdate($objp->tms);
103 $thirdpartystatic->id = $objp->rowid;
104 $thirdpartystatic->name = $objp->name;
105 $thirdpartystatic->code_client = $objp->code_client;
106 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
107 $thirdpartystatic->client = $objp->client;
108 $thirdpartystatic->fournisseur = $objp->fournisseur;
109 $thirdpartystatic->logo = $objp->logo;
110 $nbfact = $objp->nbfact;
111 $nbimpaye = $objp->nbfact - $objp->nbfactpaye;
113 $this->info_box_contents[$line][] = array(
114 'td' =>
'class="tdoverflowmax150"',
115 'text' => $thirdpartystatic->getNomUrl(1),
119 $this->info_box_contents[$line][] = array(
120 'td' =>
'class="center nowraponall"',
124 $this->info_box_contents[$line][] = array(
125 'td' =>
'class="right"',
126 'text' => $nbfact.($nbimpaye != 0 ?
' ('.$nbimpaye.
')' :
'')
129 $this->info_box_contents[$line][] = array(
130 'td' =>
'class="right" width="18"',
131 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
138 $this->info_box_contents[$line][0] = array(
139 'td' =>
'class="center"',
140 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedCustomers").
'</span>'
144 $this->db->free($result);
146 $this->info_box_contents[0][0] = array(
149 'text' => ($this->db->error().
' sql='.$sql),
153 $this->info_box_contents[0][0] = array(
154 'td' =>
'class="nohover left"',
155 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'