27 require_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
28 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
36 public $boxcode =
"oldestunpaidcustomerbills";
37 public $boximg =
"object_bill";
38 public $boxlabel =
"BoxOldestUnpaidCustomerBills";
39 public $depends = array(
"facture");
48 public $info_box_head = array();
49 public $info_box_contents = array();
64 $this->hidden = empty($user->rights->facture->lire);
75 global $conf, $user, $langs;
79 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
80 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
85 $langs->load(
"bills");
87 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleOldestUnpaidCustomerBills", $max));
89 if ($user->rights->facture->lire) {
90 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
91 $sql .=
", s.code_client, s.client";
92 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
93 $sql .=
", spe.accountancy_code_customer as code_compta";
95 $sql .=
", s.code_compta";
97 $sql .=
", s.logo, s.email, s.entity";
98 $sql .=
", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
99 $sql .=
", f.ref, f.date_lim_reglement as datelimite";
101 $sql .=
", f.datef as date";
102 $sql .=
", f.total_ht";
103 $sql .=
", f.total_tva";
104 $sql .=
", f.total_ttc";
105 $sql .=
", f.paye, f.fk_statut as status, f.rowid as facid";
106 $sql .=
", sum(pf.amount) as am";
107 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
108 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
109 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
111 if (empty($user->rights->societe->client->voir) && !$user->socid) {
112 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
114 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
115 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid=pf.fk_facture ";
116 $sql .=
" WHERE f.fk_soc = s.rowid";
117 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
118 $sql .=
" AND f.paye = 0";
119 $sql .=
" AND fk_statut = 1";
120 if (empty($user->rights->societe->client->voir) && !$user->socid) {
121 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
124 $sql .=
" AND s.rowid = ".((int) $user->socid);
126 $sql .=
" GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
127 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
128 $sql .=
" spe.accountancy_code_customer as code_compta,";
130 $sql .=
" s.code_compta,";
132 $sql .=
" f.ref, f.date_lim_reglement,";
133 $sql .=
" f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.rowid";
135 $sql .=
" ORDER BY datelimite ASC, f.ref ASC ";
136 $sql .= $this->
db->plimit($max, 0);
138 $result = $this->
db->query($sql);
140 $num = $this->
db->num_rows($result);
144 $l_due_date = $langs->trans(
'Late').
' ('.strtolower($langs->trans(
'DateDue')).
': %s)';
146 while ($line < $num) {
147 $objp = $this->
db->fetch_object($result);
149 $datelimite = $this->
db->jdate($objp->datelimite);
151 $facturestatic->id = $objp->facid;
152 $facturestatic->ref = $objp->ref;
153 $facturestatic->type = $objp->type;
154 $facturestatic->total_ht = $objp->total_ht;
155 $facturestatic->total_tva = $objp->total_tva;
156 $facturestatic->total_ttc = $objp->total_ttc;
157 $facturestatic->statut = $objp->status;
158 $facturestatic->status = $objp->status;
159 $facturestatic->date = $this->
db->jdate($objp->date);
160 $facturestatic->date_lim_reglement = $this->
db->jdate($objp->datelimite);
161 $facturestatic->alreadypaid = $objp->paye;
163 $societestatic->id = $objp->socid;
164 $societestatic->name = $objp->name;
166 $societestatic->code_client = $objp->code_client;
167 $societestatic->code_compta = $objp->code_compta;
168 $societestatic->client = $objp->client;
169 $societestatic->logo = $objp->logo;
170 $societestatic->email = $objp->email;
171 $societestatic->entity = $objp->entity;
172 $societestatic->tva_intra = $objp->tva_intra;
173 $societestatic->idprof1 = $objp->idprof1;
174 $societestatic->idprof2 = $objp->idprof2;
175 $societestatic->idprof3 = $objp->idprof3;
176 $societestatic->idprof4 = $objp->idprof4;
177 $societestatic->idprof5 = $objp->idprof5;
178 $societestatic->idprof6 = $objp->idprof6;
181 if ($facturestatic->hasDelay()) {
185 $this->info_box_contents[$line][] = array(
186 'td' =>
'class="nowraponall"',
187 'text' => $facturestatic->getNomUrl(1),
192 $this->info_box_contents[$line][] = array(
193 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
194 'text' => $societestatic->getNomUrl(1,
'', 44),
198 $this->info_box_contents[$line][] = array(
199 'td' =>
'class="nowraponall right amount"',
200 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
203 $this->info_box_contents[$line][] = array(
208 $this->info_box_contents[$line][] = array(
209 'td' =>
'class="right" width="18"',
210 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
217 $this->info_box_contents[$line][0] = array(
218 'td' =>
'class="center opacitymedium"',
219 'text'=>$langs->trans(
"NoUnpaidCustomerBills")
223 $this->
db->free($result);
225 $this->info_box_contents[0][0] = array(
228 'text' => ($this->
db->error().
' sql='.$sql),
232 $this->info_box_contents[0][0] = array(
233 'td' =>
'class="nohover opacitymedium left"',
234 'text' => $langs->trans(
"ReadPermissionNotAllowed")
247 public function showBox($head =
null, $contents =
null, $nooutput = 0)
249 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
Class to manage invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last invoices.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
$conf db
API class for accounts.