27 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
35 public $boxcode =
"customersoutstandingbillreached";
36 public $boximg =
"object_company";
37 public $boxlabel =
"BoxCustomersOutstandingBillReached";
38 public $depends = array(
"facture",
"societe");
47 public $info_box_head = array();
48 public $info_box_contents = array();
64 if (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled = 0;
66 $this->hidden = !($user->rights->societe->lire && empty($user->socid));
77 global $user, $langs, $conf;
78 $langs->load(
"boxes");
82 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
83 $thirdpartystatic =
new Societe($this->
db);
85 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastOutstandingBillReached", $max));
87 if ($user->rights->societe->lire)
89 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
90 $sql .=
", s.code_client, s.code_compta, s.client";
91 $sql .=
", s.logo, s.email, s.entity";
92 $sql .=
", s.outstanding_limit";
93 $sql .=
", s.datec, s.tms, s.status";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
95 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
96 $sql .=
" WHERE s.client IN (1, 3)";
97 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
98 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
99 if ($user->socid) $sql .=
" AND s.rowid = $user->socid";
100 $sql .=
" AND s.outstanding_limit > 0";
101 $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)";
102 $sql .=
" ORDER BY s.tms DESC";
105 dol_syslog(get_class($this).
"::loadBox", LOG_DEBUG);
106 $result = $this->
db->query($sql);
109 $num = $this->
db->num_rows($result);
111 $nboutstandingbillreachedcustomers = 0;
116 $objp = $this->
db->fetch_object($result);
117 $datec = $this->
db->jdate($objp->datec);
118 $datem = $this->
db->jdate($objp->tms);
120 $thirdpartystatic->id = $objp->socid;
121 $thirdpartystatic->name = $objp->name;
123 $thirdpartystatic->code_client = $objp->code_client;
124 $thirdpartystatic->code_compta = $objp->code_compta;
125 $thirdpartystatic->client = $objp->client;
126 $thirdpartystatic->logo = $objp->logo;
127 $thirdpartystatic->email = $objp->email;
128 $thirdpartystatic->entity = $objp->entity;
129 $thirdpartystatic->outstanding_limit = $objp->outstanding_limit;
131 $outstandingtotal = $thirdpartystatic->getOutstandingBills()[
'opened'];
132 $outstandinglimit = $thirdpartystatic->outstanding_limit;
134 if ($outstandingtotal >= $outstandinglimit)
136 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
138 'text' => $thirdpartystatic->getNomUrl(1,
'customer'),
142 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
143 'td' =>
'class="right" width="18"',
144 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
146 $nboutstandingbillreachedcustomers++;
152 if ($num == 0 || $nboutstandingbillreachedcustomers == 0) $this->info_box_contents[$line][0] = array(
153 'td' =>
'class="center"',
154 '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>'
181 public function showBox($head = null, $contents = null, $nooutput = 0)
183 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
Class to manage the box to show last thirdparties.
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...)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param= '')
Constructor.