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 = !($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)
91 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
92 $sql .=
", s.code_client, s.code_compta, s.client";
93 $sql .=
", s.logo, s.email, s.entity";
94 $sql .=
", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
95 $sql .=
", f.ref, f.date_lim_reglement as datelimite";
97 $sql .=
", f.datef as df";
98 $sql .=
", f.total as total_ht";
99 $sql .=
", f.tva as total_tva";
100 $sql .=
", f.total_ttc";
101 $sql .=
", f.paye, f.fk_statut as status, f.rowid as facid";
102 $sql .=
", sum(pf.amount) as am";
103 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
104 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
105 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
106 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid=pf.fk_facture ";
107 $sql .=
" WHERE f.fk_soc = s.rowid";
108 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
109 $sql .=
" AND f.paye = 0";
110 $sql .=
" AND fk_statut = 1";
111 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
112 if ($user->socid) $sql .=
" AND s.rowid = ".$user->socid;
113 $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,";
114 $sql .=
" f.ref, f.date_lim_reglement,";
115 $sql .=
" f.type, f.datef, f.total, f.tva, f.total_ttc, f.paye, f.fk_statut, f.rowid";
117 $sql .=
" ORDER BY datelimite ASC, f.ref ASC ";
118 $sql .= $this->
db->plimit($max, 0);
120 $result = $this->
db->query($sql);
123 $num = $this->
db->num_rows($result);
127 $l_due_date = $langs->trans(
'Late').
' ('.strtolower($langs->trans(
'DateDue')).
': %s)';
131 $objp = $this->
db->fetch_object($result);
132 $datelimite = $this->
db->jdate($objp->datelimite);
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_lim_reglement = $this->
db->jdate($objp->datelimite);
142 $facturestatic->alreadypaid = $objp->paye;
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->client = $objp->client;
150 $societestatic->logo = $objp->logo;
151 $societestatic->email = $objp->email;
152 $societestatic->entity = $objp->entity;
153 $societestatic->tva_intra = $objp->tva_intra;
154 $societestatic->idprof1 = $objp->idprof1;
155 $societestatic->idprof2 = $objp->idprof2;
156 $societestatic->idprof3 = $objp->idprof3;
157 $societestatic->idprof4 = $objp->idprof4;
158 $societestatic->idprof5 = $objp->idprof5;
159 $societestatic->idprof6 = $objp->idprof6;
162 if ($facturestatic->hasDelay()) {
166 $this->info_box_contents[$line][] = array(
167 'td' =>
'class="nowraponall"',
168 'text' => $facturestatic->getNomUrl(1),
173 $this->info_box_contents[$line][] = array(
174 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
175 'text' => $societestatic->getNomUrl(1,
'', 44),
179 $this->info_box_contents[$line][] = array(
180 'td' =>
'class="nowraponall right"',
181 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
184 $this->info_box_contents[$line][] = array(
185 'td' =>
'class="right"',
189 $this->info_box_contents[$line][] = array(
190 'td' =>
'class="right" width="18"',
191 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
197 if ($num == 0) $this->info_box_contents[$line][0] = array(
198 'td' =>
'class="center opacitymedium"',
199 'text'=>$langs->trans(
"NoUnpaidCustomerBills")
202 $this->
db->free($result);
204 $this->info_box_contents[0][0] = array(
207 'text' => ($this->
db->error().
' sql='.$sql),
211 $this->info_box_contents[0][0] = array(
212 'td' =>
'class="nohover opacitymedium left"',
213 'text' => $langs->trans(
"ReadPermissionNotAllowed")
226 public function showBox($head = null, $contents = null, $nooutput = 0)
228 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
dol_now($mode= 'auto')
Return date for now.
$conf db
API class for accounts.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
Class to manage third parties objects (customers, suppliers, prospects...)
__construct($db, $param)
Constructor.
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.
Class to manage the box to show last invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage invoices.