65 public $labelsofinvoicing;
82 $this->motifs = array();
83 $this->labelsofinvoicing = array();
85 $this->motifs[0] =
"";
86 $this->motifs[1] = $langs->trans(
"StatusMotif1");
87 $this->motifs[2] = $langs->trans(
"StatusMotif2");
88 $this->motifs[3] = $langs->trans(
"StatusMotif3");
89 $this->motifs[4] = $langs->trans(
"StatusMotif4");
90 $this->motifs[5] = $langs->trans(
"StatusMotif5");
91 $this->motifs[6] = $langs->trans(
"StatusMotif6");
92 $this->motifs[7] = $langs->trans(
"StatusMotif7");
93 $this->motifs[8] = $langs->trans(
"StatusMotif8");
95 $this->labelsofinvoicing[0] = $langs->trans(
"NoInvoiceRefused");
96 $this->labelsofinvoicing[1] = $langs->trans(
"InvoiceRefused");
110 public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0)
116 $this->bon_id = $bonid;
119 dol_syslog(
"RejetPrelevement::Create id ".$id);
124 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/ligneprelevement.class.php';
131 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_rejet (";
132 $sql .=
"fk_prelevement_lignes";
133 $sql .=
", date_rejet";
135 $sql .=
", fk_user_creation";
136 $sql .=
", date_creation";
137 $sql .=
", afacturer";
138 $sql .=
") VALUES (";
140 $sql .=
", '".$this->db->idate($date_rejet).
"'";
141 $sql .=
", ".((int) $motif);
142 $sql .=
", ".((int) $user->id);
143 $sql .=
", '".$this->db->idate($now).
"'";
144 $sql .=
", ".((int) $facturation);
147 $result = $this->db->query($sql);
150 dol_syslog(
"RejetPrelevement::create Erreur 4 $sql");
155 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes ";
156 $sql .=
" SET statut = 3";
157 $sql .=
" WHERE rowid = ".((int) $id);
159 if (!$this->db->query($sql)) {
160 dol_syslog(
"RejetPrelevement::create Erreur 5");
165 for ($i = 0; $i < $num; $i++) {
166 if ($this->
type ==
'bank-transfer') {
174 $fac->fetch($facs[$i][0]);
176 $amountrejected = $facs[$i][1];
180 $pai->amounts = array();
184 $pai->amounts[$facs[$i][0]] =
price2num($amountrejected * -1);
186 $pai->datepaye = $date_rejet;
187 $pai->paiementid = 3;
188 $pai->num_paiement = $langs->trans(
'Rejection').
' '.$fac->ref;
189 $pai->num_payment = $langs->trans(
'Rejection').
' '.$fac->ref;
190 $pai->id_prelevement = $this->bon_id;
191 $pai->num_prelevement = $lipre->bon_ref;
193 if ($pai->create($this->user) < 0) {
195 dol_syslog(
"RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
199 if ($this->
type ==
'bank-transfer') {
200 $mode =
'payment_supplier';
203 $result = $pai->addPaymentToBank($user, $mode,
'(InvoiceRefused)', $bankaccount,
'',
'');
205 dol_syslog(
"RejetPrelevement::Create AddPaymentToBan Error");
210 if ($pai->validate($user) < 0) {
212 dol_syslog(
"RejetPrelevement::Create Error payment validation");
216 dol_syslog(
"RejetPrelevement::Create set_unpaid fac ".$fac->ref);
218 $fac->setUnpaid($user);
226 dol_syslog(
"RejetPrelevement::Create Commit");
231 dol_syslog(
"RejetPrelevement::Create Rollback");
232 $this->db->rollback();
252 $sql =
"SELECT fk_user_demande";
253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
254 $sql .=
" WHERE pfd.fk_prelevement_bons = ".((int) $this->bon_id);
255 $sql .=
" AND pfd.fk_facture".($this->type ==
'bank-transfer' ?
'_fourn' :
'').
' = '.((
int) $fac->id);
257 $resql = $this->db->query($sql);
259 $num = $this->db->num_rows($resql);
261 $row = $this->db->fetch_row($resql);
265 dol_syslog(
"RejetPrelevement::_send_email Erreur lecture user");
269 $emuser =
new User($this->db);
270 $emuser->fetch($userid);
273 $soc->fetch($fac->socid);
275 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
277 $subject = $langs->transnoentities(
"InfoRejectSubject");
278 $sendto = $emuser->getFullName($langs).
" <".$emuser->email.
">";
279 $from = $this->
user->getFullName($langs).
" <".$this->
user->email.
">";
281 $trackid =
'use'.$emuser->id;
287 $socname = $soc->name;
288 $amount =
price($fac->total_ttc);
289 $userinfo = $this->
user->getFullName($langs);
291 $message = $langs->trans(
"InfoRejectMessage", $facref, $socname, $amount, $userinfo);
293 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $this->
user->email,
'', $trackid);
295 $result = $mailfile->sendfile();
297 dol_syslog(
"RejetPrelevement::_send_email email envoye");
299 dol_syslog(
"RejetPrelevement::_send_email Erreur envoi email");
302 dol_syslog(
"RejetPrelevement::_send_email Userid invalide");
320 $sql =
"SELECT f.rowid as facid, pl.amount";
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement as pf";
322 if ($this->
type ==
'bank-transfer') {
323 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)";
325 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON (pf.fk_facture = f.rowid)";
327 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
328 $sql .=
" WHERE pf.fk_prelevement_lignes = ".((int) $this->
id);
329 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
331 $resql = $this->db->query($sql);
333 $num = $this->db->num_rows($resql);
338 $row = $this->db->fetch_row($resql);
350 $this->db->free($resql);
366 $sql =
"SELECT pr.date_rejet as dr, motif, afacturer";
367 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_rejet as pr";
368 $sql .=
" WHERE pr.fk_prelevement_lignes =".((int) $rowid);
370 $resql = $this->db->query($sql);
372 if ($this->db->num_rows($resql)) {
373 $obj = $this->db->fetch_object($resql);
376 $this->date_rejet = $this->db->jdate($obj->dr);
377 $this->motif = $this->motifs[$obj->motif];
378 $this->invoicing = $this->labelsofinvoicing[$obj->afacturer];
380 $this->db->free($resql);
384 dol_syslog(
"RejetPrelevement::Fetch Erreur rowid=".$rowid.
" numrows=0");
388 dol_syslog(
"RejetPrelevement::Fetch Erreur rowid=".$rowid);
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage withdrawals.
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage standing orders rejects.
_send_email($fac)
Send email to all users that has asked the withdraw request.
getListInvoices($amounts=0)
Retrieve the list of invoices.
__construct($db, $user, $type)
Constructor.
create($user, $id, $motif, $date_rejet, $bonid, $facturation=0)
Create a reject.
fetch($rowid)
Retrieve withdrawal object.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type