78 public $labelsofinvoicing;
95 $this->motifs = array();
96 $this->labelsofinvoicing = array();
98 $this->motifs[0] =
"";
99 $this->motifs[1] = $langs->trans(
"StatusMotif1");
100 $this->motifs[2] = $langs->trans(
"StatusMotif2");
101 $this->motifs[3] = $langs->trans(
"StatusMotif3");
102 $this->motifs[4] = $langs->trans(
"StatusMotif4");
103 $this->motifs[5] = $langs->trans(
"StatusMotif5");
104 $this->motifs[6] = $langs->trans(
"StatusMotif6");
105 $this->motifs[7] = $langs->trans(
"StatusMotif7");
106 $this->motifs[8] = $langs->trans(
"StatusMotif8");
108 $this->labelsofinvoicing[0] = $langs->trans(
"NoInvoiceRefused");
109 $this->labelsofinvoicing[1] = $langs->trans(
"InvoiceRefused");
123 public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0)
129 $this->bon_id = $bonid;
132 dol_syslog(
"RejetPrelevement::Create id ".$id);
137 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/ligneprelevement.class.php';
144 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_rejet (";
145 $sql .=
"fk_prelevement_lignes";
146 $sql .=
", date_rejet";
148 $sql .=
", fk_user_creation";
149 $sql .=
", date_creation";
150 $sql .=
", afacturer";
151 $sql .=
") VALUES (";
153 $sql .=
", '".$this->db->idate($date_rejet).
"'";
154 $sql .=
", ".((int) $motif);
155 $sql .=
", ".((int) $user->id);
156 $sql .=
", '".$this->db->idate($now).
"'";
157 $sql .=
", ".((int) $facturation);
160 $result = $this->db->query($sql);
163 dol_syslog(
"RejetPrelevement::create Erreur 4 $sql");
168 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes ";
169 $sql .=
" SET statut = 3";
170 $sql .=
" WHERE rowid = ".((int) $id);
172 if (!$this->db->query($sql)) {
173 dol_syslog(
"RejetPrelevement::create Erreur 5");
178 for ($i = 0; $i < $num; $i++) {
179 if ($this->
type ==
'bank-transfer') {
187 $fac->fetch($facs[$i][0]);
189 $amountrejected = $facs[$i][1];
193 $pai->amounts = array();
194 $pai->amounts[$facs[$i][0]] =
price2num($amountrejected * -1);
196 $pai->datepaye = $date_rejet;
197 $pai->paiementid = 3;
198 $pai->num_paiement = $langs->trans(
'Rejection').
' '.$fac->ref;
199 $pai->num_payment = $langs->trans(
'Rejection').
' '.$fac->ref;
200 $pai->id_prelevement = $this->bon_id;
201 $pai->num_prelevement = $lipre->bon_ref;
203 if ($pai->create($this->user) < 0) {
205 dol_syslog(
"RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
209 if ($this->
type ==
'bank-transfer') {
210 $mode =
'payment_supplier';
213 $result = $pai->addPaymentToBank($user, $mode,
'(InvoiceRefused)', $bankaccount,
'',
'');
215 dol_syslog(
"RejetPrelevement::Create AddPaymentToBan Error");
220 if ($pai->validate($user) < 0) {
222 dol_syslog(
"RejetPrelevement::Create Error payment validation");
226 dol_syslog(
"RejetPrelevement::Create set_unpaid fac ".$fac->ref);
228 $fac->setUnpaid($user);
236 dol_syslog(
"RejetPrelevement::Create Commit");
241 dol_syslog(
"RejetPrelevement::Create Rollback");
242 $this->db->rollback();
262 $sql =
"SELECT fk_user_demande";
263 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
264 $sql .=
" WHERE pfd.fk_prelevement_bons = ".((int) $this->bon_id);
265 $sql .=
" AND pfd.fk_facture".($this->type ==
'bank-transfer' ?
'_fourn' :
'').
' = '.((
int) $fac->id);
267 $resql = $this->db->query($sql);
269 $num = $this->db->num_rows($resql);
271 $row = $this->db->fetch_row($resql);
275 dol_syslog(
"RejetPrelevement::_send_email Erreur lecture user");
279 $emuser =
new User($this->db);
280 $emuser->fetch($userid);
283 $soc->fetch($fac->socid);
285 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
287 $subject = $langs->transnoentities(
"InfoRejectSubject");
288 $sendto = $emuser->getFullName($langs).
" <".$emuser->email.
">";
289 $from = $this->
user->getFullName($langs).
" <".$this->
user->email.
">";
291 $trackid =
'use'.$emuser->id;
297 $socname = $soc->name;
298 $amount =
price($fac->total_ttc);
299 $userinfo = $this->
user->getFullName($langs);
301 $message = $langs->trans(
"InfoRejectMessage", $facref, $socname, $amount, $userinfo);
303 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $this->
user->email,
'', $trackid);
305 $result = $mailfile->sendfile();
307 dol_syslog(
"RejetPrelevement::_send_email email envoye");
309 dol_syslog(
"RejetPrelevement::_send_email Erreur envoi email");
312 dol_syslog(
"RejetPrelevement::_send_email Userid invalid");
331 $sql =
"SELECT f.rowid as facid, pl.amount";
332 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement as pf";
333 if ($this->
type ==
'bank-transfer') {
334 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)";
336 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON (pf.fk_facture = f.rowid)";
338 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
339 $sql .=
" WHERE pf.fk_prelevement_lignes = ".((int) $this->
id);
340 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
342 $resql = $this->db->query($sql);
344 $num = $this->db->num_rows($resql);
349 $row = $this->db->fetch_row($resql);
361 $this->db->free($resql);
377 $sql =
"SELECT pr.date_rejet as dr, motif, afacturer";
378 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_rejet as pr";
379 $sql .=
" WHERE pr.fk_prelevement_lignes =".((int) $rowid);
381 $resql = $this->db->query($sql);
383 if ($this->db->num_rows($resql)) {
384 $obj = $this->db->fetch_object($resql);
387 $this->date_rejet = $this->db->jdate($obj->dr);
388 $this->motif = $this->motifs[$obj->motif];
389 $this->invoicing = $this->labelsofinvoicing[$obj->afacturer];
391 $this->db->free($resql);
395 dol_syslog(
"RejetPrelevement::Fetch Erreur rowid=".$rowid.
" numrows=0");
399 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$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