64 global $conf, $user, $langs;
68 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
69 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
71 $facturestatic =
new Facture($this->db);
72 $societestatic =
new Societe($this->db);
74 $langs->load(
"bills");
76 $text = $langs->trans(
"BoxTitleLast".(
getDolGlobalString(
'MAIN_LASTBOX_ON_OBJECT_DATE') ?
"" :
"Modified").
"CustomerBills", $max);
77 $this->info_box_head = array(
78 'text' => $text.
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/compta/facture/list.php?sortfield=f.tms&sortorder=DESC"><span class="badge">...</span></a>',
82 if ($user->hasRight(
'facture',
'lire')) {
83 $sql =
"SELECT f.rowid as facid";
84 $sql .=
", f.ref, f.type, f.total_ht";
85 $sql .=
", f.total_tva";
86 $sql .=
", f.total_ttc";
87 $sql .=
", f.datef as date";
88 $sql .=
", f.paye, f.fk_statut as status, f.datec, f.tms";
89 $sql .=
", f.date_lim_reglement as datelimite";
90 $sql .=
", s.rowid as socid, s.nom as name, s.name_alias";
91 $sql .=
", s.code_client, s.code_compta, s.client";
92 $sql .=
", s.logo, s.email, s.entity";
93 $sql .=
", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
94 $sql .=
", SUM(pf.amount) as am";
95 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
96 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture,";
97 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
98 if (!$user->hasRight(
'societe',
'client',
'voir')) {
99 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
101 $sql .=
" WHERE f.fk_soc = s.rowid";
102 $sql .=
" AND f.fk_statut > 0";
103 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
104 if (!$user->hasRight(
'societe',
'client',
'voir')) {
105 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
108 $sql .=
" AND s.rowid = ".((int) $user->socid);
110 $sql .=
" GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.code_compta, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
111 $sql .=
" f.rowid, f.ref, f.type, f.total_ht, f.total_tva, f.total_ttc, f.datef, f.paye, f.fk_statut, f.datec, f.tms, f.date_lim_reglement";
113 $sql .=
" ORDER BY f.datef DESC, f.ref DESC ";
115 $sql .=
" ORDER BY f.tms DESC, f.ref DESC ";
117 $sql .= $this->db->plimit($max, 0);
119 $result = $this->db->query($sql);
121 $num = $this->db->num_rows($result);
125 $l_due_date = $langs->trans(
'Late').
' ('.$langs->trans(
'DateDue').
': %s)';
127 while ($line < $num) {
128 $objp = $this->db->fetch_object($result);
130 $datelimite = $this->db->jdate($objp->datelimite);
131 $datem = $this->db->jdate($objp->tms);
133 $facturestatic->id = $objp->facid;
134 $facturestatic->ref = $objp->ref;
135 $facturestatic->type = $objp->type;
136 $facturestatic->total_ht = $objp->total_ht;
137 $facturestatic->total_tva = $objp->total_tva;
138 $facturestatic->total_ttc = $objp->total_ttc;
139 $facturestatic->statut = $objp->status;
140 $facturestatic->status = $objp->status;
141 $facturestatic->date = $this->db->jdate($objp->date);
142 $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
144 $facturestatic->paye = $objp->paye;
145 $facturestatic->alreadypaid = $objp->am;
147 $societestatic->id = $objp->socid;
148 $societestatic->name = $objp->name;
150 $societestatic->code_client = $objp->code_client;
151 $societestatic->code_compta = $objp->code_compta;
152 $societestatic->code_compta_client = $objp->code_compta;
153 $societestatic->client = $objp->client;
154 $societestatic->logo = $objp->logo;
155 $societestatic->email = $objp->email;
156 $societestatic->entity = $objp->entity;
157 $societestatic->tva_intra = $objp->tva_intra;
158 $societestatic->idprof1 = $objp->idprof1;
159 $societestatic->idprof2 = $objp->idprof2;
160 $societestatic->idprof3 = $objp->idprof3;
161 $societestatic->idprof4 = $objp->idprof4;
162 $societestatic->idprof5 = $objp->idprof5;
163 $societestatic->idprof6 = $objp->idprof6;
166 if ($facturestatic->hasDelay()) {
171 $this->info_box_contents[$line][] = array(
172 'td' =>
'class="nowraponall"',
173 'text' => $facturestatic->getNomUrl(1),
178 $this->info_box_contents[$line][] = array(
179 'td' =>
'class="tdoverflowmax200"',
180 'text' => $societestatic->getNomUrl(1,
'', 40),
184 $this->info_box_contents[$line][] = array(
185 'td' =>
'class="right nowraponall amount"',
186 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
189 $this->info_box_contents[$line][] = array(
194 $this->info_box_contents[$line][] = array(
195 'td' =>
'class="right" width="18"',
196 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
209 $this->db->free($result);
211 $this->info_box_contents[0][0] = array(
214 'text' => ($this->db->error().
' sql='.$sql),
218 $this->info_box_contents[0][0] = array(
219 'td' =>
'class="nohover left"',
220 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'