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();
181 $pai->amounts[$facs[$i][0]] =
price2num($amountrejected * -1);
183 $pai->datepaye = $date_rejet;
184 $pai->paiementid = 3;
185 $pai->num_paiement = $langs->trans(
'Rejection').
' '.$fac->ref;
186 $pai->num_payment = $langs->trans(
'Rejection').
' '.$fac->ref;
187 $pai->id_prelevement = $this->bon_id;
188 $pai->num_prelevement = $lipre->bon_ref;
190 if ($pai->create($this->user) < 0) {
192 dol_syslog(
"RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
196 if ($this->
type ==
'bank-transfer') {
197 $mode =
'payment_supplier';
200 $result = $pai->addPaymentToBank($user, $mode,
'(InvoiceRefused)', $bankaccount,
'',
'');
202 dol_syslog(
"RejetPrelevement::Create AddPaymentToBan Error");
207 if ($pai->validate($user) < 0) {
209 dol_syslog(
"RejetPrelevement::Create Error payment validation");
213 dol_syslog(
"RejetPrelevement::Create set_unpaid fac ".$fac->ref);
215 $fac->setUnpaid($user);
223 dol_syslog(
"RejetPrelevement::Create Commit");
228 dol_syslog(
"RejetPrelevement::Create Rollback");
229 $this->db->rollback();
249 $sql =
"SELECT fk_user_demande";
250 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
251 $sql .=
" WHERE pfd.fk_prelevement_bons = ".((int) $this->bon_id);
252 $sql .=
" AND pfd.fk_facture".($this->type ==
'bank-transfer' ?
'_fourn' :
'').
' = '.((
int) $fac->id);
254 $resql = $this->db->query($sql);
256 $num = $this->db->num_rows($resql);
258 $row = $this->db->fetch_row($resql);
262 dol_syslog(
"RejetPrelevement::_send_email Erreur lecture user");
266 $emuser =
new User($this->db);
267 $emuser->fetch($userid);
270 $soc->fetch($fac->socid);
272 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
274 $subject = $langs->transnoentities(
"InfoRejectSubject");
275 $sendto = $emuser->getFullName($langs).
" <".$emuser->email.
">";
276 $from = $this->
user->getFullName($langs).
" <".$this->
user->email.
">";
278 $trackid =
'use'.$emuser->id;
284 $socname = $soc->name;
285 $amount =
price($fac->total_ttc);
286 $userinfo = $this->
user->getFullName($langs);
288 $message = $langs->trans(
"InfoRejectMessage", $facref, $socname, $amount, $userinfo);
290 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $this->
user->email,
'', $trackid);
292 $result = $mailfile->sendfile();
294 dol_syslog(
"RejetPrelevement::_send_email email envoye");
296 dol_syslog(
"RejetPrelevement::_send_email Erreur envoi email");
299 dol_syslog(
"RejetPrelevement::_send_email Userid invalid");
317 $sql =
"SELECT f.rowid as facid, pl.amount";
318 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement as pf";
319 if ($this->
type ==
'bank-transfer') {
320 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)";
322 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON (pf.fk_facture = f.rowid)";
324 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
325 $sql .=
" WHERE pf.fk_prelevement_lignes = ".((int) $this->
id);
326 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
328 $resql = $this->db->query($sql);
330 $num = $this->db->num_rows($resql);
335 $row = $this->db->fetch_row($resql);
347 $this->db->free($resql);
363 $sql =
"SELECT pr.date_rejet as dr, motif, afacturer";
364 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_rejet as pr";
365 $sql .=
" WHERE pr.fk_prelevement_lignes =".((int) $rowid);
367 $resql = $this->db->query($sql);
369 if ($this->db->num_rows($resql)) {
370 $obj = $this->db->fetch_object($resql);
373 $this->date_rejet = $this->db->jdate($obj->dr);
374 $this->motif = $this->motifs[$obj->motif];
375 $this->invoicing = $this->labelsofinvoicing[$obj->afacturer];
377 $this->db->free($resql);
381 dol_syslog(
"RejetPrelevement::Fetch Erreur rowid=".$rowid.
" numrows=0");
385 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.
$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