62 global $conf, $user, $langs;
66 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
67 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
69 $facturestatic =
new Facture($this->db);
70 $societestatic =
new Societe($this->db);
72 $langs->load(
"bills");
74 $text = $langs->trans(
"BoxTitleLast".(
getDolGlobalString(
'MAIN_LASTBOX_ON_OBJECT_DATE') ?
"" :
"Modified").
"CustomerBills", $max);
75 $this->info_box_head = array(
76 'text' => $text.
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/compta/facture/list.php?sortfield=f.tms&sortorder=DESC"><span class="badge">...</span></a>',
80 if ($user->hasRight(
'facture',
'lire')) {
81 $sql =
"SELECT f.rowid as facid";
82 $sql .=
", f.ref, f.type, f.total_ht";
83 $sql .=
", f.total_tva";
84 $sql .=
", f.total_ttc";
85 $sql .=
", f.datef as date";
86 $sql .=
", f.paye, f.fk_statut as status, f.datec, f.tms";
87 $sql .=
", f.date_lim_reglement as datelimite";
88 $sql .=
", s.rowid as socid, s.nom as name, s.name_alias";
89 $sql .=
", s.code_client, s.code_compta, s.client";
90 $sql .=
", s.logo, s.email, s.entity";
91 $sql .=
", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
92 $sql .=
", SUM(pf.amount) as am";
93 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
94 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture,";
95 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
96 if (!$user->hasRight(
'societe',
'client',
'voir')) {
97 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
99 $sql .=
" WHERE f.fk_soc = s.rowid";
100 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
101 if (!$user->hasRight(
'societe',
'client',
'voir')) {
102 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
105 $sql .=
" AND s.rowid = ".((int) $user->socid);
107 $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,";
108 $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";
110 $sql .=
" ORDER BY f.datef DESC, f.ref DESC ";
112 $sql .=
" ORDER BY f.tms DESC, f.ref DESC ";
114 $sql .= $this->db->plimit($max, 0);
116 $result = $this->db->query($sql);
118 $num = $this->db->num_rows($result);
122 $l_due_date = $langs->trans(
'Late').
' ('.$langs->trans(
'DateDue').
': %s)';
124 while ($line < $num) {
125 $objp = $this->db->fetch_object($result);
127 $datelimite = $this->db->jdate($objp->datelimite);
128 $datem = $this->db->jdate($objp->tms);
130 $facturestatic->id = $objp->facid;
131 $facturestatic->ref = $objp->ref;
132 $facturestatic->type = $objp->type;
133 $facturestatic->total_ht = $objp->total_ht;
134 $facturestatic->total_tva = $objp->total_tva;
135 $facturestatic->total_ttc = $objp->total_ttc;
136 $facturestatic->statut = $objp->status;
137 $facturestatic->status = $objp->status;
138 $facturestatic->date = $this->db->jdate($objp->date);
139 $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
141 $facturestatic->paye = $objp->paye;
142 $facturestatic->alreadypaid = $objp->am;
144 $societestatic->id = $objp->socid;
145 $societestatic->name = $objp->name;
147 $societestatic->code_client = $objp->code_client;
148 $societestatic->code_compta = $objp->code_compta;
149 $societestatic->code_compta_client = $objp->code_compta;
150 $societestatic->client = $objp->client;
151 $societestatic->logo = $objp->logo;
152 $societestatic->email = $objp->email;
153 $societestatic->entity = $objp->entity;
154 $societestatic->tva_intra = $objp->tva_intra;
155 $societestatic->idprof1 = $objp->idprof1;
156 $societestatic->idprof2 = $objp->idprof2;
157 $societestatic->idprof3 = $objp->idprof3;
158 $societestatic->idprof4 = $objp->idprof4;
159 $societestatic->idprof5 = $objp->idprof5;
160 $societestatic->idprof6 = $objp->idprof6;
163 if ($facturestatic->hasDelay()) {
168 $this->info_box_contents[$line][] = array(
169 'td' =>
'class="nowraponall"',
170 'text' => $facturestatic->getNomUrl(1),
175 $this->info_box_contents[$line][] = array(
176 'td' =>
'class="tdoverflowmax200"',
177 'text' => $societestatic->getNomUrl(1,
'', 40),
181 $this->info_box_contents[$line][] = array(
182 'td' =>
'class="right nowraponall amount"',
183 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
186 $this->info_box_contents[$line][] = array(
191 $this->info_box_contents[$line][] = array(
192 'td' =>
'class="right" width="18"',
193 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
200 $this->info_box_contents[$line][0] = array(
201 'td' =>
'class="center"',
202 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedInvoices").
'</span>',
206 $this->db->free($result);
208 $this->info_box_contents[0][0] = array(
211 'text' => ($this->db->error().
' sql='.$sql),
215 $this->info_box_contents[0][0] = array(
216 'td' =>
'class="nohover left"',
217 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'