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;
99 $bankaccount = ($this->
type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
102 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/ligneprelevement.class.php';
109 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_rejet (";
110 $sql .=
"fk_prelevement_lignes";
111 $sql .=
", date_rejet";
113 $sql .=
", fk_user_creation";
114 $sql .=
", date_creation";
115 $sql .=
", afacturer";
116 $sql .=
") VALUES (";
118 $sql .=
", '".$this->db->idate($date_rejet).
"'";
119 $sql .=
", ".((int) $motif);
120 $sql .=
", ".((int) $user->id);
121 $sql .=
", '".$this->db->idate($now).
"'";
122 $sql .=
", ".((int) $facturation);
125 $result = $this->db->query($sql);
128 dol_syslog(
"RejetPrelevement::create Erreur 4");
129 dol_syslog(
"RejetPrelevement::create Erreur 4 $sql");
134 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes ";
135 $sql .=
" SET statut = 3";
136 $sql .=
" WHERE rowid = ".((int) $id);
138 if (!$this->db->query($sql)) {
139 dol_syslog(
"RejetPrelevement::create Erreur 5");
144 for ($i = 0; $i < $num; $i++) {
145 if ($this->
type ==
'bank-transfer') {
153 $fac->fetch($facs[$i][0]);
158 $pai->amounts = array();
165 $pai->amounts[$facs[$i][0]] =
price2num($facs[$i][1] * ($this->
type ==
'bank-transfer' ? 1 : -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]);
178 $result = $pai->addPaymentToBank($user,
'payment',
'(InvoiceRefused)', $bankaccount,
'',
'');
180 dol_syslog(
"RejetPrelevement::Create AddPaymentToBan Error");
185 if ($pai->validate($user) < 0) {
187 dol_syslog(
"RejetPrelevement::Create Error payment validation");
191 dol_syslog(
"RejetPrelevement::Create set_unpaid fac ".$fac->ref);
193 $fac->setUnpaid($user);
201 dol_syslog(
"RejetPrelevement::Create Commit");
204 dol_syslog(
"RejetPrelevement::Create Rollback");
205 $this->db->rollback();
223 $sql =
"SELECT fk_user_demande";
224 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
225 $sql .=
" WHERE pfd.fk_prelevement_bons = ".((int) $this->bon_id);
226 $sql .=
" AND pfd.fk_facture".($this->type ==
'bank-transfer' ?
'_fourn' :
'').
' = '.((
int) $fac->id);
228 $resql = $this->db->query($sql);
230 $num = $this->db->num_rows($resql);
232 $row = $this->db->fetch_row($resql);
236 dol_syslog(
"RejetPrelevement::_send_email Erreur lecture user");
240 $emuser =
new User($this->db);
241 $emuser->fetch($userid);
244 $soc->fetch($fac->socid);
246 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
248 $subject = $langs->transnoentities(
"InfoRejectSubject");
249 $sendto = $emuser->getFullName($langs).
" <".$emuser->email.
">";
250 $from = $this->
user->getFullName($langs).
" <".$this->
user->email.
">";
252 $trackid =
'use'.$emuser->id;
258 $socname = $soc->name;
259 $amount =
price($fac->total_ttc);
260 $userinfo = $this->
user->getFullName($langs);
262 $message = $langs->trans(
"InfoRejectMessage", $facref, $socname, $amount, $userinfo);
264 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $this->
user->email,
'', $trackid);
266 $result = $mailfile->sendfile();
268 dol_syslog(
"RejetPrelevement::_send_email email envoye");
270 dol_syslog(
"RejetPrelevement::_send_email Erreur envoi email");
273 dol_syslog(
"RejetPrelevement::_send_email Userid invalide");
291 $sql =
"SELECT f.rowid as facid, pl.amount";
292 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement as pf";
293 if ($this->
type ==
'bank-transfer') {
294 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)";
296 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON (pf.fk_facture = f.rowid)";
298 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
299 $sql .=
" WHERE pf.fk_prelevement_lignes = ".((int) $this->
id);
300 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
302 $resql = $this->db->query($sql);
304 $num = $this->db->num_rows($resql);
309 $row = $this->db->fetch_row($resql);
321 $this->db->free($resql);
338 $sql =
"SELECT pr.date_rejet as dr, motif, afacturer";
339 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_rejet as pr";
340 $sql .=
" WHERE pr.fk_prelevement_lignes =".((int) $rowid);
342 $resql = $this->db->query($sql);
344 if ($this->db->num_rows($resql)) {
345 $obj = $this->db->fetch_object($resql);
348 $this->date_rejet = $this->db->jdate($obj->dr);
349 $this->motif = $this->motifs[$obj->motif];
350 $this->invoicing = $this->facturer[$obj->afacturer];
352 $this->db->free($resql);
356 dol_syslog(
"RejetPrelevement::Fetch Erreur rowid=".$rowid.
" numrows=0");
360 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.
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.
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