61 $this->motifs = array();
62 $this->facturer = array();
64 $this->motifs[0] =
"";
65 $this->motifs[1] = $langs->trans(
"StatusMotif1");
66 $this->motifs[2] = $langs->trans(
"StatusMotif2");
67 $this->motifs[3] = $langs->trans(
"StatusMotif3");
68 $this->motifs[4] = $langs->trans(
"StatusMotif4");
69 $this->motifs[5] = $langs->trans(
"StatusMotif5");
70 $this->motifs[6] = $langs->trans(
"StatusMotif6");
71 $this->motifs[7] = $langs->trans(
"StatusMotif7");
72 $this->motifs[8] = $langs->trans(
"StatusMotif8");
74 $this->facturer[0] = $langs->trans(
"NoInvoiceRefused");
75 $this->facturer[1] = $langs->trans(
"InvoiceRefused");
89 public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0)
95 $this->bon_id = $bonid;
98 dol_syslog(
"RejetPrelevement::Create id ".$id);
103 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/ligneprelevement.class.php';
110 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_rejet (";
111 $sql .=
"fk_prelevement_lignes";
112 $sql .=
", date_rejet";
114 $sql .=
", fk_user_creation";
115 $sql .=
", date_creation";
116 $sql .=
", afacturer";
117 $sql .=
") VALUES (";
119 $sql .=
", '".$this->db->idate($date_rejet).
"'";
120 $sql .=
", ".((int) $motif);
121 $sql .=
", ".((int) $user->id);
122 $sql .=
", '".$this->db->idate($now).
"'";
123 $sql .=
", ".((int) $facturation);
126 $result = $this->db->query($sql);
129 dol_syslog(
"RejetPrelevement::create Erreur 4");
130 dol_syslog(
"RejetPrelevement::create Erreur 4 $sql");
135 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes ";
136 $sql .=
" SET statut = 3";
137 $sql .=
" WHERE rowid = ".((int) $id);
139 if (!$this->db->query($sql)) {
140 dol_syslog(
"RejetPrelevement::create Erreur 5");
145 for ($i = 0; $i < $num; $i++) {
146 if ($this->
type ==
'bank-transfer') {
154 $fac->fetch($facs[$i][0]);
156 $amountrejected = $facs[$i][1];
160 $pai->amounts = array();
164 $pai->amounts[$facs[$i][0]] =
price2num($amountrejected * -1);
166 $pai->datepaye = $date_rejet;
167 $pai->paiementid = 3;
168 $pai->num_paiement = $fac->ref;
169 $pai->num_payment = $fac->ref;
170 $pai->id_prelevement = $this->bon_id;
171 $pai->num_prelevement = $lipre->bon_ref;
173 if ($pai->create($this->user) < 0) {
176 dol_syslog(
"RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
180 if ($this->
type ==
'bank-transfer') {
181 $mode =
'payment_supplier';
184 $result = $pai->addPaymentToBank($user, $mode,
'(InvoiceRefused)', $bankaccount,
'',
'');
186 dol_syslog(
"RejetPrelevement::Create AddPaymentToBan Error");
191 if ($pai->validate($user) < 0) {
193 dol_syslog(
"RejetPrelevement::Create Error payment validation");
197 dol_syslog(
"RejetPrelevement::Create set_unpaid fac ".$fac->ref);
199 $fac->setUnpaid($user);
207 dol_syslog(
"RejetPrelevement::Create Commit");
212 dol_syslog(
"RejetPrelevement::Create Rollback");
213 $this->db->rollback();
233 $sql =
"SELECT fk_user_demande";
234 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
235 $sql .=
" WHERE pfd.fk_prelevement_bons = ".((int) $this->bon_id);
236 $sql .=
" AND pfd.fk_facture".($this->type ==
'bank-transfer' ?
'_fourn' :
'').
' = '.((
int) $fac->id);
238 $resql = $this->db->query($sql);
240 $num = $this->db->num_rows($resql);
242 $row = $this->db->fetch_row($resql);
246 dol_syslog(
"RejetPrelevement::_send_email Erreur lecture user");
250 $emuser =
new User($this->db);
251 $emuser->fetch($userid);
254 $soc->fetch($fac->socid);
256 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
258 $subject = $langs->transnoentities(
"InfoRejectSubject");
259 $sendto = $emuser->getFullName($langs).
" <".$emuser->email.
">";
260 $from = $this->
user->getFullName($langs).
" <".$this->
user->email.
">";
262 $trackid =
'use'.$emuser->id;
268 $socname = $soc->name;
269 $amount =
price($fac->total_ttc);
270 $userinfo = $this->
user->getFullName($langs);
272 $message = $langs->trans(
"InfoRejectMessage", $facref, $socname, $amount, $userinfo);
274 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $this->
user->email,
'', $trackid);
276 $result = $mailfile->sendfile();
278 dol_syslog(
"RejetPrelevement::_send_email email envoye");
280 dol_syslog(
"RejetPrelevement::_send_email Erreur envoi email");
283 dol_syslog(
"RejetPrelevement::_send_email Userid invalide");
301 $sql =
"SELECT f.rowid as facid, pl.amount";
302 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement as pf";
303 if ($this->
type ==
'bank-transfer') {
304 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)";
306 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON (pf.fk_facture = f.rowid)";
308 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
309 $sql .=
" WHERE pf.fk_prelevement_lignes = ".((int) $this->
id);
310 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
312 $resql = $this->db->query($sql);
314 $num = $this->db->num_rows($resql);
319 $row = $this->db->fetch_row($resql);
331 $this->db->free($resql);
348 $sql =
"SELECT pr.date_rejet as dr, motif, afacturer";
349 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_rejet as pr";
350 $sql .=
" WHERE pr.fk_prelevement_lignes =".((int) $rowid);
352 $resql = $this->db->query($sql);
354 if ($this->db->num_rows($resql)) {
355 $obj = $this->db->fetch_object($resql);
358 $this->date_rejet = $this->db->jdate($obj->dr);
359 $this->motif = $this->motifs[$obj->motif];
360 $this->invoicing = $this->facturer[$obj->afacturer];
362 $this->db->free($resql);
366 dol_syslog(
"RejetPrelevement::Fetch Erreur rowid=".$rowid.
" numrows=0");
370 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