66 public $labelsofinvoicing;
83 $this->motifs = array();
84 $this->labelsofinvoicing = array();
86 $this->motifs[0] =
"";
87 $this->motifs[1] = $langs->trans(
"StatusMotif1");
88 $this->motifs[2] = $langs->trans(
"StatusMotif2");
89 $this->motifs[3] = $langs->trans(
"StatusMotif3");
90 $this->motifs[4] = $langs->trans(
"StatusMotif4");
91 $this->motifs[5] = $langs->trans(
"StatusMotif5");
92 $this->motifs[6] = $langs->trans(
"StatusMotif6");
93 $this->motifs[7] = $langs->trans(
"StatusMotif7");
94 $this->motifs[8] = $langs->trans(
"StatusMotif8");
96 $this->labelsofinvoicing[0] = $langs->trans(
"NoInvoiceRefused");
97 $this->labelsofinvoicing[1] = $langs->trans(
"InvoiceRefused");
111 public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0)
117 $this->bon_id = $bonid;
120 dol_syslog(
"RejetPrelevement::Create id ".$id);
125 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/ligneprelevement.class.php';
132 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_rejet (";
133 $sql .=
"fk_prelevement_lignes";
134 $sql .=
", date_rejet";
136 $sql .=
", fk_user_creation";
137 $sql .=
", date_creation";
138 $sql .=
", afacturer";
139 $sql .=
") VALUES (";
141 $sql .=
", '".$this->db->idate($date_rejet).
"'";
142 $sql .=
", ".((int) $motif);
143 $sql .=
", ".((int) $user->id);
144 $sql .=
", '".$this->db->idate($now).
"'";
145 $sql .=
", ".((int) $facturation);
148 $result = $this->db->query($sql);
151 dol_syslog(
"RejetPrelevement::create Erreur 4 $sql");
156 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes ";
157 $sql .=
" SET statut = 3";
158 $sql .=
" WHERE rowid = ".((int) $id);
160 if (!$this->db->query($sql)) {
161 dol_syslog(
"RejetPrelevement::create Erreur 5");
166 for ($i = 0; $i < $num; $i++) {
167 if ($this->
type ==
'bank-transfer') {
175 $fac->fetch($facs[$i][0]);
177 $amountrejected = $facs[$i][1];
181 $pai->amounts = array();
182 $pai->amounts[$facs[$i][0]] =
price2num($amountrejected * -1);
184 $pai->datepaye = $date_rejet;
185 $pai->paiementid = 3;
186 $pai->num_paiement = $langs->trans(
'Rejection').
' '.$fac->ref;
187 $pai->num_payment = $langs->trans(
'Rejection').
' '.$fac->ref;
188 $pai->id_prelevement = $this->bon_id;
189 $pai->num_prelevement = $lipre->bon_ref;
191 if ($pai->create($this->user) < 0) {
193 dol_syslog(
"RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
197 if ($this->
type ==
'bank-transfer') {
198 $mode =
'payment_supplier';
201 $result = $pai->addPaymentToBank($user, $mode,
'(InvoiceRefused)', $bankaccount,
'',
'');
203 dol_syslog(
"RejetPrelevement::Create AddPaymentToBan Error");
208 if ($pai->validate($user) < 0) {
210 dol_syslog(
"RejetPrelevement::Create Error payment validation");
214 dol_syslog(
"RejetPrelevement::Create set_unpaid fac ".$fac->ref);
216 $fac->setUnpaid($user);
224 dol_syslog(
"RejetPrelevement::Create Commit");
229 dol_syslog(
"RejetPrelevement::Create Rollback");
230 $this->db->rollback();
250 $sql =
"SELECT fk_user_demande";
251 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
252 $sql .=
" WHERE pfd.fk_prelevement_bons = ".((int) $this->bon_id);
253 $sql .=
" AND pfd.fk_facture".($this->type ==
'bank-transfer' ?
'_fourn' :
'').
' = '.((
int) $fac->id);
255 $resql = $this->db->query($sql);
257 $num = $this->db->num_rows($resql);
259 $row = $this->db->fetch_row($resql);
263 dol_syslog(
"RejetPrelevement::_send_email Erreur lecture user");
267 $emuser =
new User($this->db);
268 $emuser->fetch($userid);
271 $soc->fetch($fac->socid);
273 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
275 $subject = $langs->transnoentities(
"InfoRejectSubject");
276 $sendto = $emuser->getFullName($langs).
" <".$emuser->email.
">";
277 $from = $this->
user->getFullName($langs).
" <".$this->
user->email.
">";
279 $trackid =
'use'.$emuser->id;
285 $socname = $soc->name;
286 $amount =
price($fac->total_ttc);
287 $userinfo = $this->
user->getFullName($langs);
289 $message = $langs->trans(
"InfoRejectMessage", $facref, $socname, $amount, $userinfo);
291 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $this->
user->email,
'', $trackid);
293 $result = $mailfile->sendfile();
295 dol_syslog(
"RejetPrelevement::_send_email email envoye");
297 dol_syslog(
"RejetPrelevement::_send_email Erreur envoi email");
300 dol_syslog(
"RejetPrelevement::_send_email Userid invalid");
318 $sql =
"SELECT f.rowid as facid, pl.amount";
319 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement as pf";
320 if ($this->
type ==
'bank-transfer') {
321 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)";
323 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON (pf.fk_facture = f.rowid)";
325 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
326 $sql .=
" WHERE pf.fk_prelevement_lignes = ".((int) $this->
id);
327 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
329 $resql = $this->db->query($sql);
331 $num = $this->db->num_rows($resql);
336 $row = $this->db->fetch_row($resql);
348 $this->db->free($resql);
364 $sql =
"SELECT pr.date_rejet as dr, motif, afacturer";
365 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_rejet as pr";
366 $sql .=
" WHERE pr.fk_prelevement_lignes =".((int) $rowid);
368 $resql = $this->db->query($sql);
370 if ($this->db->num_rows($resql)) {
371 $obj = $this->db->fetch_object($resql);
374 $this->date_rejet = $this->db->jdate($obj->dr);
375 $this->motif = $this->motifs[$obj->motif];
376 $this->invoicing = $this->labelsofinvoicing[$obj->afacturer];
378 $this->db->free($resql);
382 dol_syslog(
"RejetPrelevement::Fetch Erreur rowid=".$rowid.
" numrows=0");
386 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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db user
Active Directory does not allow anonymous connections.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type