28 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
36 public $boxcode =
"goodcustomers";
37 public $boximg =
"object_company";
38 public $boxlabel =
"BoxGoodCustomers";
39 public $depends = array(
"societe");
48 public $info_box_head = array();
49 public $info_box_contents = array();
65 if (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled = 0;
66 if (empty($conf->global->MAIN_BOX_ENABLE_BEST_CUSTOMERS)) $this->enabled = 0;
68 $this->hidden = !($user->rights->societe->lire);
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(
"BoxTitleGoodCustomers", $max));
89 if ($user->rights->societe->lire)
91 $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,";
92 $sql .=
" count(*) as nbfact, sum(".$this->db->ifsql(
'f.paye=1',
'1',
'0').
") as nbfactpaye";
93 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"facture as f";
94 $sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
95 $sql .=
' AND s.rowid = f.fk_soc';
96 $sql .=
" GROUP BY s.rowid, s.nom, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms, s.status";
97 $sql .= $this->
db->order(
"nbfact",
"DESC");
98 $sql .= $this->
db->plimit($max, 0);
100 dol_syslog(get_class($this).
"::loadBox", LOG_DEBUG);
101 $result = $this->
db->query($sql);
104 $num = $this->
db->num_rows($result);
109 $objp = $this->
db->fetch_object($result);
110 $datem = $this->
db->jdate($objp->tms);
111 $thirdpartystatic->id = $objp->rowid;
112 $thirdpartystatic->name = $objp->name;
113 $thirdpartystatic->code_client = $objp->code_client;
114 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
115 $thirdpartystatic->client = $objp->client;
116 $thirdpartystatic->fournisseur = $objp->fournisseur;
117 $thirdpartystatic->logo = $objp->logo;
118 $nbfact = $objp->nbfact;
119 $nbimpaye = $objp->nbfact - $objp->nbfactpaye;
121 $this->info_box_contents[$line][] = array(
123 'text' => $thirdpartystatic->getNomUrl(1),
127 $this->info_box_contents[$line][] = array(
128 'td' =>
'class="right"',
132 $this->info_box_contents[$line][] = array(
133 'td' =>
'class="right"',
134 'text' => $nbfact.($nbimpaye != 0 ?
' ('.$nbimpaye.
')' :
'')
137 $this->info_box_contents[$line][] = array(
138 'td' =>
'class="right" width="18"',
139 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
145 if ($num == 0) $this->info_box_contents[$line][0] = array(
146 'td' =>
'class="center opacitymedium"',
147 'text'=>$langs->trans(
"NoRecordedCustomers")
150 $this->
db->free($result);
152 $this->info_box_contents[0][0] = array(
155 'text' => ($this->
db->error().
' sql='.$sql),
159 $this->info_box_contents[0][0] = array(
160 'td' =>
'class="nohover opacitymedium left"',
161 'text' => $langs->trans(
"ReadPermissionNotAllowed")
174 public function showBox($head = null, $contents = null, $nooutput = 0)
176 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
Class to manage the box to show last thirdparties.
__construct($db, $param= '')
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
$conf db
API class for accounts.
Class to manage third parties objects (customers, suppliers, prospects...)
loadBox($max=5)
Load data for box to show them later.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).