--- /tmp/dsg/dolibarr/htdocs/compta/prelevement/class/github_bonprelevement.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/prelevement/class/client_bonprelevement.class.php @@ -32,7 +32,6 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; @@ -67,9 +66,6 @@ public $emetteur_iban; public $emetteur_bic; public $emetteur_ics; - - public $date_trans; - public $user_trans; public $total; public $fetched; @@ -162,17 +158,21 @@ if ($this->db->query($sql)) { $result = 0; - } else { + } + else + { $result = -1; - $this->errors[] = get_class($this)."::AddFacture ".$this->db->lasterror; dol_syslog(get_class($this)."::AddFacture Error $result"); } - } else { + } + else + { $result = -2; - $this->errors[] = get_class($this)."::AddFacture linedid Empty"; dol_syslog(get_class($this)."::AddFacture Error $result"); } - } else { + } + else + { $result = -3; dol_syslog(get_class($this)."::AddFacture Error $result"); } @@ -207,18 +207,22 @@ $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes"; $sql .= " WHERE fk_prelevement_bons = ".$this->id; $sql .= " AND fk_soc =".$client_id; - $sql .= " AND code_banque = '".$this->db->escape($code_banque)."'"; - $sql .= " AND code_guichet = '".$this->db->escape($code_guichet)."'"; - $sql .= " AND number = '".$this->db->escape($number)."'"; + $sql .= " AND code_banque ='".$code_banque."'"; + $sql .= " AND code_guichet ='".$code_guichet."'"; + $sql .= " AND number ='".$number."'"; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - } else { + } + else + { $result = -1; } - } else { + } + else + { /* * No aggregate */ @@ -236,18 +240,19 @@ $sql .= ", ".$client_id; $sql .= ", '".$this->db->escape($client_nom)."'"; $sql .= ", '".price2num($amount)."'"; - $sql .= ", '".$this->db->escape($code_banque)."'"; - $sql .= ", '".$this->db->escape($code_guichet)."'"; - $sql .= ", '".$this->db->escape($number)."'"; - $sql .= ", '".$this->db->escape($number_key)."'"; + $sql .= ", '".$code_banque."'"; + $sql .= ", '".$code_guichet."'"; + $sql .= ", '".$number."'"; + $sql .= ", '".$number_key."'"; $sql .= ")"; if ($this->db->query($sql)) { $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_lignes"); $result = 0; - } else { - $this->errors[] = get_class($this)."::addline Error -2 ".$this->db->lasterror; + } + else + { dol_syslog(get_class($this)."::addline Error -2"); $result = -2; } @@ -290,7 +295,6 @@ $sql .= ", p.method_trans, p.fk_user_trans"; $sql .= ", p.date_credit as date_credit"; $sql .= ", p.fk_user_credit"; - $sql .= ", p.type"; $sql .= ", p.statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql .= " WHERE p.entity IN (".getEntity('invoice').")"; @@ -318,19 +322,21 @@ $this->date_credit = $this->db->jdate($obj->date_credit); $this->user_credit = $obj->fk_user_credit; - $this->type = $obj->type; - $this->status = $obj->status; - $this->statut = $obj->status; // For backward compatibility + $this->statut = $obj->status; // For backward compatibility $this->fetched = 1; return 1; - } else { + } + else + { dol_syslog(get_class($this)."::Fetch Erreur aucune ligne retournee"); return -1; } - } else { + } + else + { return -2; } } @@ -370,7 +376,7 @@ $num = count($facs); for ($i = 0; $i < $num; $i++) { - /* Tag invoice as paid */ + /* Tag invoice as payed */ dol_syslog(get_class($this)."::set_credite set_paid fac ".$facs[$i]); $fac = new Facture($this->db); $fac->fetch($facs[$i]); @@ -398,13 +404,17 @@ { $this->db->commit(); return 0; - } else { + } + else + { $this->db->rollback(); dol_syslog(get_class($this)."::set_credite ROLLBACK "); return -1; } - } else { + } + else + { dol_syslog(get_class($this)."::set_credite Ouverture transaction SQL impossible "); return -2; } @@ -412,7 +422,7 @@ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Set direct debit or credit transfer order to "paid" status. + * Set direct debit order to "credited" status. * * @param User $user Id of user * @param int $date date of action @@ -427,152 +437,132 @@ if ($this->fetched == 1) { - if ($date < $this->date_trans) - { - $this->error = 'DateOfMovementLowerThanDateOfFileTransmission'; - dol_syslog("bon-prelevment::set_infocredit 1027 ".$this->error); - return -1027; - } - - $this->db->begin(); - - $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons "; - $sql .= " SET fk_user_credit = ".$user->id; - $sql .= ", statut = ".self::STATUS_CREDITED; - $sql .= ", date_credit = '".$this->db->idate($date)."'"; - $sql .= " WHERE rowid=".$this->id; - $sql .= " AND entity = ".$conf->entity; - $sql .= " AND statut = ".self::STATUS_TRANSFERED; - - $resql = $this->db->query($sql); - if ($resql) - { - $langs->load('withdrawals'); - $subject = $langs->trans("InfoCreditSubject", $this->ref); - $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour')); - - //Add payment of withdrawal into bank - $bankaccount = ($this->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT); - $facs = array(); - $amounts = array(); - $amountsperthirdparty = array(); - - $facs = $this->getListInvoices(1); - - // Loop on each invoice. $facs=array(0=>id, 1=>amount requested) - $num = count($facs); - for ($i = 0; $i < $num; $i++) + if ($date >= $this->date_trans) + { + if ($this->db->begin()) { - if ($this->type == 'bank-transfer') { - $fac = new FactureFournisseur($this->db); - } else { - $fac = new Facture($this->db); - } - - $result = $fac->fetch($facs[$i][0]); - - $amounts[$fac->id] = $facs[$i][1]; - $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1]; - - $totalpaye = $fac->getSommePaiement(); - $totalcreditnotes = $fac->getSumCreditNotesUsed(); - $totaldeposits = $fac->getSumDepositsUsed(); - $alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits; - - // @TODO Move this after creation of payment - if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) { - $result = $fac->set_paid($user); - if ($result < 0) { - $this->error = $fac->error; - $this->errors = $fac->errors; + $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons "; + $sql .= " SET fk_user_credit = ".$user->id; + $sql .= ", statut = ".self::STATUS_CREDITED; + $sql .= ", date_credit = '".$this->db->idate($date)."'"; + $sql .= " WHERE rowid=".$this->id; + $sql .= " AND entity = ".$conf->entity; + $sql .= " AND statut = ".self::STATUS_TRANSFERED; + + if ($this->db->query($sql)) + { + $langs->load('withdrawals'); + $subject = $langs->trans("InfoCreditSubject", $this->ref); + $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour')); + + //Add payment of withdrawal into bank + $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; + $facs = array(); + $amounts = array(); + $amountsperthirdparty = array(); + + $facs = $this->getListInvoices(1); + + // Loop on each invoice. $facs=array(0=>id, 1=>amount requested) + $num = count($facs); + for ($i = 0; $i < $num; $i++) + { + $fac = new Facture($this->db); + $fac->fetch($facs[$i][0]); + $amounts[$fac->id] = $facs[$i][1]; + $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1]; + + $totalpaye = $fac->getSommePaiement(); + $totalcreditnotes = $fac->getSumCreditNotesUsed(); + $totaldeposits = $fac->getSumDepositsUsed(); + $alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits; + + if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) { + $result = $fac->set_paid($user); + } + } + + // Make one payment per customer + foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) + { + $paiement = new Paiement($this->db); + $paiement->datepaye = $date; + $paiement->amounts = $cursoramounts; // Array with detail of dispatching of payments for each invoice + $paiement->paiementid = 3; // + $paiement->num_payment = $this->ref; // Set ref of direct debit note + $paiement->num_paiement = $this->ref; // For backward compatibility + $paiement->id_prelevement = $this->id; + + $paiement_id = $paiement->create($user); + if ($paiement_id < 0) + { + dol_syslog(get_class($this)."::set_infocredit AddPayment Error"); + $error++; + } + else + { + $result = $paiement->addPaymentToBank($user, 'payment', '(WithdrawalPayment)', $bankaccount, '', ''); + if ($result < 0) + { + dol_syslog(get_class($this)."::set_infocredit AddPaymentToBank Error"); + $error++; + } + } + //var_dump($paiement->amounts); + //var_dump($thirdpartyid); + //var_dump($cursoramounts); + } + + // Update withdrawal line + // TODO: Translate to ligneprelevement.class.php + $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; + $sql .= " SET statut = 2"; + $sql .= " WHERE fk_prelevement_bons = ".$this->id; + + if (!$this->db->query($sql)) + { + dol_syslog(get_class($this)."::set_infocredit Update lines Error"); + $error++; } } - } - //var_dump($amountsperthirdparty);exit; - - // Make one payment per customer - foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) - { - if ($this->type == 'bank-transfer') { - $paiement = new PaiementFourn($this->db); - } else { - $paiement = new Paiement($this->db); - } - $paiement->datepaye = $date; - $paiement->amounts = $cursoramounts; // Array with detail of dispatching of payments for each invoice - - if ($this->type == 'bank-transfer') { - $paiement->paiementid = 2; - $paiement->paiementcode = 'VIR'; - } else { - $paiement->paiementid = 3; - $paiement->paiementcode = 'PRE'; - } - - $paiement->num_payment = $this->ref; // Set ref of direct debit note - $paiement->id_prelevement = $this->id; - - $paiement_id = $paiement->create($user); // This use ->paiementid, that is ID of payment mode - if ($paiement_id < 0) + else { - $error++; - $this->error = $paiement->error; - $this->errors = $paiement->errors; - dol_syslog(get_class($this)."::set_infocredit AddPayment Error ".$this->error); - } else { - if ($this->type == 'bank-transfer') { - $modeforaddpayment = 'payment_supplier'; - } else { - $modeforaddpayment = 'payment'; - } - - $result = $paiement->addPaymentToBank($user, $modeforaddpayment, '(WithdrawalPayment)', $bankaccount, '', ''); - if ($result < 0) - { - $error++; - $this->error = $paiement->error; - $this->errors = $paiement->errors; - dol_syslog(get_class($this)."::set_infocredit AddPaymentToBank Error ".$this->error); - } - } - //var_dump($paiement->amounts); - //var_dump($thirdpartyid); - //var_dump($cursoramounts); - } - - // Update withdrawal line - // TODO: Translate to ligneprelevement.class.php - if (!$error) { - $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; - $sql .= " SET statut = 2"; - $sql .= " WHERE fk_prelevement_bons = ".$this->id; - - if (!$this->db->query($sql)) { - dol_syslog(get_class($this)."::set_infocredit Update lines Error"); + dol_syslog(get_class($this)."::set_infocredit Update Bons Error"); $error++; } - } - } else { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this)."::set_infocredit Update Bons Error"); - $error++; - } - - /* - * End of procedure - */ - if ($error == 0) - { - $this->date_credit = $date; - $this->statut = self::STATUS_CREDITED; - - $this->db->commit(); - return 0; - } else { - $this->db->rollback(); - return -1; - } - } else { + + /* + * End of procedure + */ + if ($error == 0) + { + $this->date_credit = $date; + $this->statut = self::STATUS_CREDITED; + + $this->db->commit(); + return 0; + } + else + { + $this->db->rollback(); + dol_syslog("bon-prelevment::set_infocredit ROLLBACK "); + return -1; + } + } + else + { + dol_syslog(get_class($this)."::set_infocredit 1025 Open SQL transaction impossible "); + return -1025; + } + } + else + { + dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans "); + return -1027; + } + } + else + { return -1026; } } @@ -600,7 +590,7 @@ $sql .= " SET fk_user_trans = ".$user->id; $sql .= " , date_trans = '".$this->db->idate($date)."'"; $sql .= " , method_trans = ".$method; - $sql .= " , statut = ".self::STATUS_TRANSFERED; + $sql .= " , statut = 1"; $sql .= " WHERE rowid = ".$this->id; $sql .= " AND entity = ".$conf->entity; $sql .= " AND statut = 0"; @@ -614,7 +604,9 @@ $message .= $langs->trans("InfoTransData", price($this->amount), $this->methodes_trans[$this->method_trans], dol_print_date($date, 'day')); // TODO Call trigger to create a notification using notification module - } else { + } + else + { $error++; } @@ -622,17 +614,20 @@ { $this->date_trans = $date; $this->statut = 1; - $this->user_trans = $user->id; $this->db->commit(); return 0; - } else { + } + else + { $this->db->rollback(); dol_syslog(get_class($this)."::set_infotrans ROLLBACK", LOG_ERR); return -1; } - } else { + } + else + { dol_syslog(get_class($this)."::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT); return -2; } @@ -653,12 +648,7 @@ /* * Returns all invoices presented within same order */ - $sql = "SELECT "; - if ($this->type == 'bank-transfer') { - $sql .= " pf.fk_facture_fourn"; - } else { - $sql .= " pf.fk_facture"; - } + $sql = "SELECT fk_facture"; if ($amounts) $sql .= ", SUM(pl.amount)"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; @@ -667,13 +657,7 @@ $sql .= " AND pl.fk_prelevement_bons = p.rowid"; $sql .= " AND p.rowid = ".$this->id; $sql .= " AND p.entity = ".$conf->entity; - if ($amounts) { - if ($this->type == 'bank-transfer') { - $sql .= " GROUP BY fk_facture_fourn"; - } else { - $sql .= " GROUP BY fk_facture"; - } - } + if ($amounts) $sql .= " GROUP BY fk_facture"; $resql = $this->db->query($sql); if ($resql) @@ -687,7 +671,8 @@ { $row = $this->db->fetch_row($resql); if (!$amounts) $arr[$i] = $row[0]; - else { + else + { $arr[$i] = array( $row[0], $row[1] @@ -697,7 +682,9 @@ } } $this->db->free($resql); - } else { + } + else + { dol_syslog(get_class($this)."::getListInvoices Erreur"); } @@ -746,7 +733,9 @@ $this->db->free($resql); return $obj->nb; - } else { + } + else + { $error = 1; dol_syslog(get_class($this)."::SommeAPrelever Erreur -1"); dol_syslog($this->db->error()); @@ -809,7 +798,9 @@ $this->db->free($resql); return $obj->nb; - } else { + } + else + { $this->error = get_class($this)."::NbFactureAPrelever Erreur -1 sql=".$this->db->error(); return -1; } @@ -886,11 +877,14 @@ $sql .= " AND f.rowid = pfd.fk_facture_fourn"; } $sql .= " AND s.rowid = f.fk_soc"; - $sql .= " AND f.fk_statut = 1"; // Invoice validated + //if ($banque || $agence) $sql.= " AND s.rowid = sr.fk_soc"; + $sql .= " AND f.fk_statut = 1"; $sql .= " AND f.paye = 0"; $sql .= " AND pfd.traite = 0"; $sql .= " AND f.total_ttc > 0"; $sql .= " AND pfd.ext_payment_id IS NULL"; + //if ($banque) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'"; + //if ($agence) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'"; dol_syslog(__METHOD__."::Read invoices, sql=".$sql, LOG_DEBUG); @@ -914,7 +908,9 @@ } $this->db->free($resql); dol_syslog(__METHOD__."::Read invoices, ".$i." invoices to withdraw", LOG_DEBUG); - } else { + } + else + { $error++; dol_syslog(__METHOD__."::Read invoices error ".$this->db->error(), LOG_ERR); } @@ -934,14 +930,14 @@ foreach ($factures as $key => $fac) { if ($type != 'bank-transfer') { - $tmpinvoice = new Facture($this->db); + $fact = new Facture($this->db); } else { - $tmpinvoice = new FactureFournisseur($this->db); + $fact = new FactureFournisseur($this->db); } - $resfetch = $tmpinvoice->fetch($fac[0]); + $resfetch = $fact->fetch($fac[0]); if ($resfetch >= 0) // Field 0 of $fac is rowid of invoice { - if ($soc->fetch($tmpinvoice->socid) >= 0) + if ($soc->fetch($fact->socid) >= 0) { $bac = new CompanyBankAccount($this->db); $bac->fetch(0, $soc->id); @@ -964,19 +960,27 @@ $factures_prev_id[$i] = $fac[0]; $i++; //dol_syslog(__METHOD__."::RIB is ok", LOG_DEBUG); - } else { - dol_syslog(__METHOD__."::Check BAN Error on default bank number IBAN/BIC for thirdparty reported by verif() ".$tmpinvoice->socid." ".$soc->name, LOG_WARNING); - $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice ".$tmpinvoice->getNomUrl(0)." for thirdparty ".$soc->getNomUrl(0); - $this->thirdparty_in_error[$soc->id] = "Error on default bank number IBAN/BIC for invoice ".$tmpinvoice->getNomUrl(0)." for thirdparty ".$soc->getNomUrl(0); } - } else { + else + { + dol_syslog(__METHOD__."::Check BAN Error on default bank number IBAN/BIC for thirdparty reported by verif() ".$fact->socid." ".$soc->name, LOG_WARNING); + $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice ".$fact->getNomUrl(0)." for thirdparty ".$soc->getNomUrl(0); + $this->thirdparty_in_error[$soc->id] = "Error on default bank number IBAN/BIC for invoice ".$fact->getNomUrl(0)." for thirdparty ".$soc->getNomUrl(0); + } + } + else + { dol_syslog(__METHOD__."::Check BAN Failed to read company", LOG_WARNING); } - } else { + } + else + { dol_syslog(__METHOD__."::Check BAN Failed to read invoice", LOG_WARNING); } } - } else { + } + else + { dol_syslog(__METHOD__."::Check BAN No invoice to process", LOG_WARNING); } } @@ -999,12 +1003,16 @@ if (count($factures_prev) > 0) { - if ($mode == 'real') { + if ($mode == 'real') + { $ok = 1; - } else { - print $langs->trans("ModeWarning"); // "Option for real mode was not set, we stop after this simulation\n"; - } - } + } + else + { + print $langs->trans("ModeWarning"); //"Option for real mode was not set, we stop after this simulation\n"; + } + } + if ($ok) { @@ -1048,7 +1056,7 @@ // Create withdraw receipt in database $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons ("; - $sql .= "ref, entity, datec, type"; + $sql .= " ref, entity, datec, type"; $sql .= ") VALUES ("; $sql .= "'".$this->db->escape($ref)."'"; $sql .= ", ".$conf->entity; @@ -1062,11 +1070,15 @@ $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons"); $this->id = $prev_id; $this->ref = $ref; - } else { + } + else + { $error++; dol_syslog(__METHOD__."::Create withdraw receipt ".$this->db->lasterror(), LOG_ERR); } - } else { + } + else + { $error++; dol_syslog(__METHOD__."::Get last withdraw receipt ".$this->db->lasterror(), LOG_ERR); } @@ -1074,12 +1086,6 @@ if (!$error) { - if ($type != 'bank-transfer') { - $fact = new Facture($this->db); - } else { - $fact = new FactureFournisseur($this->db); - } - /* * Create withdrawal receipt in database */ @@ -1088,14 +1094,11 @@ foreach ($factures_prev as $fac) // Add a link in database for each invoice { // Fetch invoice - $result = $fact->fetch($fac[0]); - if ($result < 0) { - $this->error = 'ERRORBONPRELEVEMENT Failed to load invoice with id '.$fac[0]; - break; - } + $fact = new Facture($this->db); + $fact->fetch($fac[0]); /* - * Add standing order. This add record into llx_prelevement_lignes + * Add standing order * * $fac[0] : invoice_id * $fac[1] : ??? @@ -1106,7 +1109,9 @@ * $fac[6] : cle rib * $fac[7] : amount * $fac[8] : client nom + * $fac[2] : client id */ + $ri = $this->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type); if ($ri <> 0) { @@ -1121,11 +1126,11 @@ $sql .= " WHERE rowid = ".$fac[1]; $resql = $this->db->query($sql); + if (!$resql) { $error++; - $this->errors[] = $this->db->lasterror(); - dol_syslog(__METHOD__."::Update Error=".$this->db->lasterror(), LOG_ERR); + dol_syslog(__METHOD__."::Update Error=".$this->db->error(), LOG_ERR); } } } @@ -1134,10 +1139,10 @@ if (!$error) { /* - * Create file of type='direct-debit' for direct debit order or type='bank-transfer' for credit transfer into a XML file + * Create file of direct debit order or credit transfer into a XML file */ - dol_syslog(__METHOD__."::Init direct debit or credit transfer file for ".count($factures_prev)." invoices", LOG_DEBUG); + dol_syslog(__METHOD__."::Init direct debit file for ".count($factures_prev)." invoices", LOG_DEBUG); if (count($factures_prev) > 0) { @@ -1145,9 +1150,6 @@ $this->reference_remise = $ref; $id = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; - if ($type == 'bank-transfer') { - $id = $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT; - } $account = new Account($this->db); if ($account->fetch($id) > 0) { @@ -1166,34 +1168,27 @@ $this->factures = $factures_prev_id; $this->context['factures_prev'] = $factures_prev; - // Generation of direct debit or credti transfer file $this->filename (May be a SEPA file for european countries) - // This also set the property $this->total with amount that is included into file + // Generation of SEPA file $this->filename + // This also the the property $this->total that is included into file $result = $this->generate($format, $executiondate, $type); - if ($result < 0) { - /*var_dump($this->error); - var_dump($this->invoice_in_error); */ - $error++; - } } dol_syslog(__METHOD__."::End withdraw receipt, file ".$this->filename, LOG_DEBUG); } - //var_dump($this->total);exit; + //var_dump($factures_prev);exit; /* * Update total defined after generation of file */ - if (!$error) { - $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; - $sql .= " SET amount = ".price2num($this->total); - $sql .= " WHERE rowid = ".$this->id; - $sql .= " AND entity = ".$conf->entity; - - $resql = $this->db->query($sql); - if (!$resql) - { - $error++; - dol_syslog(__METHOD__."::Error update total: ".$this->db->error(), LOG_ERR); - } + $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; + $sql .= " SET amount = ".price2num($this->total); + $sql .= " WHERE rowid = ".$this->id; + $sql .= " AND entity = ".$conf->entity; + + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + dol_syslog(__METHOD__."::Error update total: ".$this->db->error(), LOG_ERR); } if (!$error && !$notrigger) @@ -1212,12 +1207,16 @@ if (!$error) { $this->db->commit(); - return count($factures_prev); - } else { + } + else + { $this->db->rollback(); - return -1; - } - } else { + } + + return count($factures_prev); + } + else + { return 0; } } @@ -1281,7 +1280,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } @@ -1306,7 +1307,7 @@ $result = ''; - $labeltoshow = 'PaymentByDirectDebit'; + $labeltoshow = 'Withdraw'; if ($this->type == 'bank-transfer') { $labeltoshow = 'PaymentByBankTransfer'; } @@ -1320,7 +1321,7 @@ $url = DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$this->id; if ($this->type == 'bank-transfer') { - $url = DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$this->id; + $url = DOL_URL_ROOT.'/compta/paymentbybanktransfer/card.php?id='.$this->id; } if ($option != 'nolink') @@ -1348,7 +1349,8 @@ $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) $linkclose = $hookmanager->resPrint; */ - } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); $linkstart = ''; @@ -1384,12 +1386,14 @@ $result = 0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; - $sql .= " WHERE rowid = ".((int) $rowid); + $sql .= " WHERE rowid = '".$rowid."'"; if ($this->db->query($sql)) { return 0; - } else { + } + else + { return -1; } } @@ -1408,12 +1412,14 @@ $result = 0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; - $sql .= " WHERE fk_user=".$user." AND fk_action='".$this->db->escape($action)."'"; + $sql .= " WHERE fk_user=".$user." AND fk_action='".$action."'"; if ($this->db->query($sql)) { return 0; - } else { + } + else + { return -1; } } @@ -1437,13 +1443,15 @@ $now = dol_now(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)"; - $sql .= " VALUES ('".$this->db->idate($now)."', ".$user.", 'NULL', 'NULL', '".$this->db->escape($action)."')"; + $sql .= " VALUES (".$db->idate($now).",".$user.", 'NULL', 'NULL', '".$action."')"; dol_syslog("adnotiff: ".$sql); if ($this->db->query($sql)) { $result = 0; - } else { + } + else + { $result = -1; dol_syslog(get_class($this)."::AddNotification Error $result"); } @@ -1462,7 +1470,7 @@ * * @param string $format FRST, RCUR or ALL * @param string $executiondate Date to execute transfer - * @param string $type 'direct-debit' or 'bank-transfer' + * @param string $type 'direct-debit' or 'credit-transfer' * @return int >=0 if OK, <0 if KO */ public function generate($format = 'ALL', $executiondate = '', $type = 'direct-debit') @@ -1490,9 +1498,12 @@ { $found++; - if ($type != 'bank-transfer') { + if ($type == 'bank-transfer') { + print 'TODO'; + exit; + } else { /** - * SECTION CREATION FICHIER SEPA - DIRECT DEBIT + * SECTION CREATION FICHIER SEPA */ // SEPA Initialisation $CrLf = "\n"; @@ -1514,10 +1525,9 @@ * Section Debitor (sepa Debiteurs bloc lines) */ - $sql = "SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; + $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; $sql .= " pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; - $sql .= " f.ref as fac, pf.fk_facture as idfac,"; - $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum"; + $sql .= " f.ref as fac, pf.fk_facture as idfac, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum"; $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql .= " ".MAIN_DB_PREFIX."facture as f,"; @@ -1528,51 +1538,46 @@ $sql .= " WHERE pl.fk_prelevement_bons = ".$this->id; $sql .= " AND pl.rowid = pf.fk_prelevement_lignes"; $sql .= " AND pf.fk_facture = f.rowid"; - $sql .= " AND f.fk_soc = soc.rowid"; $sql .= " AND soc.fk_pays = c.rowid"; + $sql .= " AND soc.rowid = f.fk_soc"; $sql .= " AND rib.fk_soc = f.fk_soc"; $sql .= " AND rib.default_rib = 1"; $sql .= " AND rib.type = 'ban'"; + //print $sql; // Define $fileDebiteurSection. One section DrctDbtTxInf per invoice. $resql = $this->db->query($sql); if ($resql) { - $cachearraytotestduplicate = array(); - $num = $this->db->num_rows($resql); while ($i < $num) { $obj = $this->db->fetch_object($resql); - - if (!empty($cachearraytotestduplicate[$obj->idfac])) { - $this->error = $langs->trans('ErrorCompanyHasDuplicateDefaultBAN', $obj->socid); - $this->invoice_in_error[$obj->idfac] = $this->error; - $result = -2; - break; - } - $cachearraytotestduplicate[$obj->idfac] = $obj->rowid; - $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec); - $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type); + $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum); $this->total = $this->total + $obj->somme; $i++; } $nbtotalDrctDbtTxInf = $i; - } else { - $this->error = $this->db->lasterror(); + } + else + { fputs($this->file, 'ERROR DEBITOR '.$sql.$CrLf); // DEBITOR = Customers $result = -2; } - // Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all $nbtotalDrctDbtTxInf + // Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all DrctDbtTxInf if ($result != -2) { - $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type); + $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format); + } + else + { + fputs($this->file, 'ERROR CREDITOR'.$CrLf); // CREDITOR = My company } /** - * SECTION CREATION SEPA FILE - ISO200022 + * SECTION CREATION SEPA FILE */ // SEPA File Header fputs($this->file, '<'.'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.'>'.$CrLf); @@ -1580,7 +1585,7 @@ fputs($this->file, ' '.$CrLf); // SEPA Group header fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.('DD/'.$dateTime_YMD.'/REF'.$this->id).''.$CrLf); + fputs($this->file, ' '.('PREL'.$dateTime_YMD.'/REF'.$this->id).''.$CrLf); fputs($this->file, ' '.$dateTime_ECMA.''.$CrLf); fputs($this->file, ' '.$i.''.$CrLf); fputs($this->file, ' '.$this->total.''.$CrLf); @@ -1605,127 +1610,43 @@ fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); fputs($this->file, ''.$CrLf); - } else { - /** - * SECTION CREATION FICHIER SEPA - CREDIT TRANSFER - */ - // SEPA Initialisation - $CrLf = "\n"; - - $now = dol_now(); - - $dateTime_ECMA = dol_print_date($now, '%Y-%m-%dT%H:%M:%S'); - - $date_actu = $now; - if (!empty($executiondate)) $date_actu = $executiondate; - - $dateTime_YMD = dol_print_date($date_actu, '%Y%m%d'); - $dateTime_YMDHMS = dol_print_date($date_actu, '%Y%m%d%H%M%S'); - $fileCrediteurSection = ''; - $fileEmetteurSection = ''; - $i = 0; - - /* - * Section Creditor (sepa Crediteurs bloc lines) - */ - - $sql = "SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; - $sql .= " pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; - $sql .= " f.ref as fac, pf.fk_facture_fourn as idfac,"; - $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum"; + } + } + + // Build file for Other Countries with unknow format + if (!$found) + { + if ($type == 'bank-transfer') { + $sql = "SELECT pl.amount"; $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql .= " ".MAIN_DB_PREFIX."facture_fourn as f,"; - $sql .= " ".MAIN_DB_PREFIX."prelevement_facture as pf,"; - $sql .= " ".MAIN_DB_PREFIX."societe as soc,"; - $sql .= " ".MAIN_DB_PREFIX."c_country as c,"; - $sql .= " ".MAIN_DB_PREFIX."societe_rib as rib"; + $sql .= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; $sql .= " WHERE pl.fk_prelevement_bons = ".$this->id; $sql .= " AND pl.rowid = pf.fk_prelevement_lignes"; $sql .= " AND pf.fk_facture_fourn = f.rowid"; - $sql .= " AND f.fk_soc = soc.rowid"; - $sql .= " AND soc.fk_pays = c.rowid"; - $sql .= " AND rib.fk_soc = f.fk_soc"; - $sql .= " AND rib.default_rib = 1"; - $sql .= " AND rib.type = 'ban'"; - - // Define $fileCrediteurSection. One section DrctDbtTxInf per invoice. + + // Lines + $i = 0; $resql = $this->db->query($sql); if ($resql) { - $cachearraytotestduplicate = array(); - $num = $this->db->num_rows($resql); + while ($i < $num) { $obj = $this->db->fetch_object($resql); - - if (!empty($cachearraytotestduplicate[$obj->idfac])) { - $this->error = $langs->trans('ErrorCompanyHasDuplicateDefaultBAN', $obj->socid); - $this->invoice_in_error[$obj->idfac] = $this->error; - $result = -2; - break; - } - $cachearraytotestduplicate[$obj->idfac] = $obj->rowid; - - $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec); - $fileCrediteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type); - $this->total = $this->total + $obj->somme; + $this->total = $this->total + $obj->amount; + + // TODO Write record into file $i++; } - $nbtotalDrctDbtTxInf = $i; - } else { - $this->error = $this->db->lasterror(); - fputs($this->file, 'ERROR CREDITOR '.$sql.$CrLf); // CREDITORS = Suppliers + } + else + { $result = -2; } - - // Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all $nbtotalDrctDbtTxInf - if ($result != -2) { - $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type); - } - - /** - * SECTION CREATION SEPA FILE - CREDIT TRANSFER - ISO200022 - */ - // SEPA File Header - fputs($this->file, '<'.'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.'>'.$CrLf); - fputs($this->file, ''.$CrLf); - fputs($this->file, ' '.$CrLf); - // SEPA Group header - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.('TRF/'.$dateTime_YMD.'/REF'.$this->id).''.$CrLf); - fputs($this->file, ' '.$dateTime_ECMA.''.$CrLf); - fputs($this->file, ' '.$i.''.$CrLf); - fputs($this->file, ' '.$this->total.''.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$conf->global->PAYMENTBYBANKTRANSFER_ICS.''.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$CrLf); - // SEPA File Emetteur (mycompany) - if ($result != -2) - { fputs($this-> file, $fileEmetteurSection); } - // SEPA File Creditors - if ($result != -2) - { fputs($this-> file, $fileCrediteurSection); } - // SEPA FILE FOOTER - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ''.$CrLf); - } - } - - // Build file for Other Countries with unknow format - if (!$found) - { - if ($type != 'bank-transfer') { + } else { $sql = "SELECT pl.amount"; $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; @@ -1750,35 +1671,9 @@ // TODO Write record into file $i++; } - } else { - $result = -2; - } - } else { - $sql = "SELECT pl.amount"; - $sql .= " FROM"; - $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; - $sql .= " ".MAIN_DB_PREFIX."facture_fourn as f,"; - $sql .= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; - $sql .= " WHERE pl.fk_prelevement_bons = ".$this->id; - $sql .= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql .= " AND pf.fk_facture_fourn = f.rowid"; - - // Lines - $i = 0; - $resql = $this->db->query($sql); - if ($resql) + } + else { - $num = $this->db->num_rows($resql); - - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $this->total = $this->total + $obj->amount; - - // TODO Write record into file - $i++; - } - } else { $result = -2; } } @@ -1795,22 +1690,6 @@ } return $result; - } - - - /** - * Generate dynamically a RUM number for a customer bank account - * - * @param string $row_code_client Customer code (soc.code_client) - * @param int $row_datec Creation date of bank account (rib.datec) - * @param string $row_drum Id of customer bank account (rib.rowid) - * @return string RUM number - */ - public static function buildRumNumber($row_code_client, $row_datec, $row_drum) - { - global $langs; - $pre = substr(dol_string_nospecial(dol_string_unaccent($langs->transnoentitiesnoconv('RUM'))), 0, 3); // Must always be on 3 char ('RUM' or 'UMR'. This is a protection against bad translation) - return $pre.'-'.$row_code_client.'-'.$row_drum.'-'.date('U', $row_datec); } @@ -1827,11 +1706,9 @@ * @param string $ref ref of invoice * @param int $facid id of invoice * @param string $rib_dom rib domiciliation - * @param string $type 'direct-debit' or 'bank-transfer' * @return void - * @see EnregDestinataireSEPA() - */ - public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom = '', $type = 'direct-debit') + */ + public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom = '') { // phpcs:enable fputs($this->file, "06"); @@ -1886,6 +1763,22 @@ fputs($this->file, substr(" ", 0, 5)); fputs($this->file, "\n"); + } + + + /** + * Build RUM number for a customer bank account + * + * @param string $row_code_client Customer code (soc.code_client) + * @param int $row_datec Creation date of bank account (rib.datec) + * @param string $row_drum Id of customer bank account (rib.rowid) + * @return string RUM number + */ + public static function buildRumNumber($row_code_client, $row_datec, $row_drum) + { + global $langs; + $pre = substr(dol_string_nospecial(dol_string_unaccent($langs->transnoentitiesnoconv('RUM'))), 0, 3); // Must always be on 3 char ('RUM' or 'UMR'. This is a protection against bad translation) + return $pre.'-'.$row_code_client.'-'.$row_drum.'-'.date('U', $row_datec); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1909,11 +1802,9 @@ * @param string $row_datec rib.datec, * @param string $row_drum rib.rowid used to generate rum * @param string $row_rum rib.rum Rum defined on company bank account - * @param string $type 'direct-debit' or 'bank-transfer' * @return string Return string with SEPA part DrctDbtTxInf - * @see EnregDestinataire() - */ - public function EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum, $type = 'direct-debit') + */ + public function EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum) { // phpcs:enable global $conf; @@ -1921,7 +1812,7 @@ include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $CrLf = "\n"; - $Rowing = sprintf("%010d", $row_idfac); + $Rowing = sprintf("%06d", $row_idfac); // Define value for RUM // Example: RUMCustomerCode-CustomerBankAccountId-01424448606 (note: Date is date of creation of CustomerBankAccountId) @@ -1930,108 +1821,57 @@ // Define date of RUM signature $DtOfSgntr = dol_print_date($row_datec, '%Y-%m-%d'); - if ($type != 'bank-transfer') { - // SEPA Paiement Information of buyer for Direct debit - $XML_DEBITOR = ''; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - // Add EndToEndId. Must be a unique ID for each payment (for example by including bank, buyer or seller, date, checksum) - $XML_DEBITOR .= ' '.(($conf->global->PRELEVEMENT_END_TO_END != "") ? $conf->global->PRELEVEMENT_END_TO_END : ('AS-'.dol_trunc($row_ref, 20)).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.round($row_somme, 2).''.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$Rum.''.$CrLf; - $XML_DEBITOR .= ' '.$DtOfSgntr.''.$CrLf; - $XML_DEBITOR .= ' false'.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$row_bic.''.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$row_country_code.''.$CrLf; - $addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""))); - $addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => ""))); - if (trim($addressline1)) $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).''.$CrLf; - if (trim($addressline2)) $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).''.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.preg_replace('/\s/', '', $row_iban).''.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - // A string with some information on payment - 140 max - $XML_DEBITOR .= ' '.(($conf->global->PRELEVEMENT_USTRD != "") ? $conf->global->PRELEVEMENT_USTRD : dol_trunc($row_ref, 135)).''.$CrLf; // 140 max - $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.$CrLf; - return $XML_DEBITOR; - } else { - // SEPA Paiement Information of seller for Credit Transfer - $XML_CREDITOR = ''; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - // Add EndToEndId. Must be a unique ID for each payment (for example by including bank, buyer or seller, date, checksum) - $XML_CREDITOR .= ' '.(($conf->global->PRELEVEMENT_END_TO_END != "") ? $conf->global->PRELEVEMENT_END_TO_END : ('AS-'.dol_trunc($row_ref, 20)).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.round($row_somme, 2).''.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - /* - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$Rum.''.$CrLf; - $XML_CREDITOR .= ' '.$DtOfSgntr.''.$CrLf; - $XML_CREDITOR .= ' false'.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - */ - //$XML_CREDITOR .= ' SLEV'.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$row_bic.''.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$row_country_code.''.$CrLf; - $addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""))); - $addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => ""))); - if (trim($addressline1)) $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).''.$CrLf; - if (trim($addressline2)) $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).''.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.preg_replace('/\s/', '', $row_iban).''.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - // A string with some information on payment - 140 max - $XML_CREDITOR .= ' '.(($conf->global->PRELEVEMENT_USTRD != "") ? $conf->global->PRELEVEMENT_USTRD : dol_trunc($row_ref, 135)).''.$CrLf; // 140 max - $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.$CrLf; - return $XML_CREDITOR; - } + $XML_DEBITOR = ''; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + // $XML_DEBITOR .=' '.('AS-'.dol_trunc($row_ref,20).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters + $XML_DEBITOR .= ' '.(($conf->global->PRELEVEMENT_END_TO_END != "") ? $conf->global->PRELEVEMENT_END_TO_END : ('AS-'.dol_trunc($row_ref, 20)).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.round($row_somme, 2).''.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$Rum.''.$CrLf; + $XML_DEBITOR .= ' '.$DtOfSgntr.''.$CrLf; + $XML_DEBITOR .= ' false'.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$row_bic.''.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$row_country_code.''.$CrLf; + $addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""))); + $addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => ""))); + if (trim($addressline1)) $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).''.$CrLf; + if (trim($addressline2)) $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).''.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.preg_replace('/\s/', '', $row_iban).''.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + // $XML_DEBITOR .=' '.($row_ref.'/'.$Rowing.'/'.$Rum).''.$CrLf; + // $XML_DEBITOR .=' '.dol_trunc($row_ref, 135).''.$CrLf; // 140 max + $XML_DEBITOR .= ' '.(($conf->global->PRELEVEMENT_USTRD != "") ? $conf->global->PRELEVEMENT_USTRD : dol_trunc($row_ref, 135)).''.$CrLf; // 140 max + $XML_DEBITOR .= ' '.$CrLf; + $XML_DEBITOR .= ' '.$CrLf; + return $XML_DEBITOR; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Write sender of request (me). - * - * @param string $type 'direct-debit' or 'bank-transfer' + * Write sender of request (me) + * * @return void - * @see EnregEmetteurSEPA() - */ - public function EnregEmetteur($type = 'direct-debit') + */ + public function EnregEmetteur() { // phpcs:enable fputs($this->file, "03"); @@ -2103,11 +1943,9 @@ * @param float $total Total * @param string $CrLf End of line character * @param string $format FRST or RCUR or ALL - * @param string $type 'direct-debit' or 'bank-transfer' * @return string String with SEPA Sender - * @see EnregEmetteur() - */ - public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf = '\n', $format = 'FRST', $type = 'direct-debit') + */ + public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf = '\n', $format = 'FRST') { // phpcs:enable // SEPA INITIALISATION @@ -2118,8 +1956,7 @@ $dateTime_YMDHMS = dol_print_date($ladate, '%Y-%m-%dT%H:%M:%S'); // Get data of bank account - //$id = $configuration->global->PRELEVEMENT_ID_BANKACCOUNT; - $id = ($type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT); + $id = $configuration->global->PRELEVEMENT_ID_BANKACCOUNT; $account = new Account($this->db); if ($account->fetch($id) > 0) { @@ -2135,7 +1972,7 @@ $this->raison_sociale = $account->proprio; } - // Get pending payments + // Récupération info demandeur $sql = "SELECT rowid, ref"; $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_bons as pb"; @@ -2146,134 +1983,74 @@ { $obj = $this->db->fetch_object($resql); + // DONNEES BRUTES : par la suite Rows['XXX'] de la requete au dessus $country = explode(':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY); $IdBon = sprintf("%05d", $obj->rowid); $RefBon = $obj->ref; - if ($type != 'bank-transfer') { - // SEPA Paiement Information of my company for Direct debit - $XML_SEPA_INFO = ''; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.('DD/'.$dateTime_YMD.'/ID'.$IdBon.'-'.$RefBon).''.$CrLf; - $XML_SEPA_INFO .= ' DD'.$CrLf; - $XML_SEPA_INFO .= ' '.$nombre.''.$CrLf; - $XML_SEPA_INFO .= ' '.$total.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' SEPA'.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' CORE'.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$format.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$dateTime_ETAD.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => ""))); - $addressline2 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => ""))); - if ($addressline1) $XML_SEPA_INFO .= ' '.$addressline1.''.$CrLf; - if ($addressline2) $XML_SEPA_INFO .= ' '.$addressline2.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.preg_replace('/\s/', '', $this->emetteur_iban).''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$this->emetteur_bic.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - /* $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$this->raison_sociale.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.''.$CrLf; - $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf;*/ - $XML_SEPA_INFO .= ' SLEV'.$CrLf; // Field "Responsible of fees". Must be SLEV - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$this->emetteur_ics.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' SEPA'.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - } else { - // SEPA Paiement Information of my company for Credit Transfer - $XML_SEPA_INFO = ''; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.('TRF/'.$dateTime_YMD.'/ID'.$IdBon.'-'.$RefBon).''.$CrLf; - $XML_SEPA_INFO .= ' TRF'.$CrLf; - //$XML_SEPA_INFO .= ' False'.$CrLf; - $XML_SEPA_INFO .= ' '.$nombre.''.$CrLf; - $XML_SEPA_INFO .= ' '.$total.''.$CrLf; - /* - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' SEPA'.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' TRF'.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' SECU'.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - */ - $XML_SEPA_INFO .= ' '.dol_print_date($dateTime_ETAD, 'dayrfc').''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => ""))); - $addressline2 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => ""))); - if ($addressline1) $XML_SEPA_INFO .= ' '.$addressline1.''.$CrLf; - if ($addressline2) $XML_SEPA_INFO .= ' '.$addressline2.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.preg_replace('/\s/', '', $this->emetteur_iban).''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$this->emetteur_bic.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - /* $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$this->raison_sociale.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.''.$CrLf; - $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf;*/ - $XML_SEPA_INFO .= ' SLEV'.$CrLf; // Field "Responsible of fees". Must be SLEV - /*$XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$this->emetteur_ics.''.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' SEPA'.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$CrLf;*/ - } - } else { + // SEPA Paiement Information + $XML_SEPA_INFO = ''; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.('PREL'.$dateTime_YMD.'/ID'.$IdBon.'-'.$RefBon).''.$CrLf; + $XML_SEPA_INFO .= ' DD'.$CrLf; + $XML_SEPA_INFO .= ' '.$nombre.''.$CrLf; + $XML_SEPA_INFO .= ' '.$total.''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' SEPA'.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' CORE'.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$format.''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$dateTime_ETAD.''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; + $addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => ""))); + $addressline2 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => ""))); + if ($addressline1) $XML_SEPA_INFO .= ' '.$addressline1.''.$CrLf; + if ($addressline2) $XML_SEPA_INFO .= ' '.$addressline2.''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.preg_replace('/\s/', '', $this->emetteur_iban).''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$this->emetteur_bic.''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + /* $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$this->raison_sociale.''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; + $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.''.$CrLf; + $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN.''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf;*/ + $XML_SEPA_INFO .= ' SLEV'.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$this->emetteur_ics.''.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' SEPA'.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + $XML_SEPA_INFO .= ' '.$CrLf; + } + else + { fputs($this->file, 'INCORRECT EMETTEUR '.$XML_SEPA_INFO.$CrLf); + $result = -2; } return $XML_SEPA_INFO; } --- /tmp/dsg/dolibarr/htdocs/compta/prelevement/class/github_ligneprelevement.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/prelevement/class/client_ligneprelevement.class.php @@ -37,9 +37,9 @@ public $id; /** - * @var DoliDB Database handler. - */ - public $db; + * @var DoliDB Database handler. + */ + public $db; public $statuts = array(); @@ -59,7 +59,7 @@ $langs->load("withdrawals"); $this->statuts[0] = $langs->trans("StatusWaiting"); - $this->statuts[2] = $langs->trans("StatusPaid"); + $this->statuts[2] = $langs->trans("StatusCredited"); $this->statuts[3] = $langs->trans("StatusRefused"); } @@ -96,13 +96,17 @@ $this->statut = $obj->statut; $this->bon_ref = $obj->ref; $this->bon_rowid = $obj->bon_rowid; - } else { + } + else + { $error++; dol_syslog("LignePrelevement::Fetch rowid=$rowid numrows=0"); } $this->db->free($resql); - } else { + } + else + { $error++; dol_syslog("LignePrelevement::Fetch rowid=$rowid"); dol_syslog($this->db->error()); @@ -111,7 +115,7 @@ return $error; } - /** + /** * Return status label of object * * @param int $mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto @@ -122,7 +126,7 @@ return $this->LibStatut($this->statut, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return status label for a status * @@ -132,23 +136,26 @@ */ public function LibStatut($status, $mode = 0) { - // phpcs:enable + // phpcs:enable global $langs; if ($mode == 0) { return $langs->trans($this->statuts[$status]); - } elseif ($mode == 1) + } + elseif ($mode == 1) { if ($status == 0) return img_picto($langs->trans($this->statuts[$status]), 'statut1').' '.$langs->trans($this->statuts[$status]); // Waiting elseif ($status == 2) return img_picto($langs->trans($this->statuts[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]); // Credited elseif ($status == 3) return img_picto($langs->trans($this->statuts[$status]), 'statut8').' '.$langs->trans($this->statuts[$status]); // Refused - } elseif ($mode == 2) + } + elseif ($mode == 2) { if ($status == 0) return img_picto($langs->trans($this->statuts[$status]), 'statut1'); elseif ($status == 2) return img_picto($langs->trans($this->statuts[$status]), 'statut6'); elseif ($status == 3) return img_picto($langs->trans($this->statuts[$status]), 'statut8'); - } elseif ($mode == 3) + } + elseif ($mode == 3) { if ($status == 0) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut1'); elseif ($status == 2) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut6'); --- /tmp/dsg/dolibarr/htdocs/compta/prelevement/class/github_rejetprelevement.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/prelevement/class/client_rejetprelevement.class.php @@ -15,6 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * */ /** @@ -35,11 +36,9 @@ public $id; /** - * @var DoliDB Database handler. - */ - public $db; - - public $type; //prelevement or bank transfer + * @var DoliDB Database handler. + */ + public $db; /** @@ -47,30 +46,28 @@ * * @param DoliDb $db Database handler * @param User $user Objet user - * @param string $type Type ('direct-debit' for direct debit or 'bank-transfer' for credit transfer) - */ - public function __construct($db, $user, $type) + */ + public function __construct($db, $user) { global $langs; $this->db = $db; $this->user = $user; - $this->type = $type; $this->motifs = array(); $this->facturer = array(); $this->motifs[0] = ""; //$langs->trans("StatusMotif0"); - $this->motifs[1] = $langs->trans("StatusMotif1"); - $this->motifs[2] = $langs->trans("StatusMotif2"); - $this->motifs[3] = $langs->trans("StatusMotif3"); - $this->motifs[4] = $langs->trans("StatusMotif4"); - $this->motifs[5] = $langs->trans("StatusMotif5"); - $this->motifs[6] = $langs->trans("StatusMotif6"); - $this->motifs[7] = $langs->trans("StatusMotif7"); - $this->motifs[8] = $langs->trans("StatusMotif8"); - - $this->facturer[0] = $langs->trans("NoInvoiceRefused"); + $this->motifs[1] = $langs->trans("StatusMotif1"); + $this->motifs[2] = $langs->trans("StatusMotif2"); + $this->motifs[3] = $langs->trans("StatusMotif3"); + $this->motifs[4] = $langs->trans("StatusMotif4"); + $this->motifs[5] = $langs->trans("StatusMotif5"); + $this->motifs[6] = $langs->trans("StatusMotif6"); + $this->motifs[7] = $langs->trans("StatusMotif7"); + $this->motifs[8] = $langs->trans("StatusMotif8"); + + $this->facturer[0] = $langs->trans("NoInvoiceRefused"); $this->facturer[1] = $langs->trans("InvoiceRefused"); } @@ -95,7 +92,7 @@ $now = dol_now(); dol_syslog("RejetPrelevement::Create id $id"); - $bankaccount = ($this->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT); + $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; $facs = $this->getListInvoices(1); $this->db->begin(); @@ -138,19 +135,13 @@ } $num = count($facs); - for ($i = 0; $i < $num; $i++) { - if ($this->type == 'bank-transfer') { - $fac = new FactureFournisseur($this->db); - $pai = new PaiementFourn($this->db); - } else { - $fac = new Facture($this->db); - $pai = new Paiement($this->db); - } - + for ($i = 0; $i < $num; $i++) + { + $fac = new Facture($this->db); $fac->fetch($facs[$i][0]); // Make a negative payment - //$pai = new Paiement($this->db); + $pai = new Paiement($this->db); $pai->amounts = array(); @@ -159,24 +150,29 @@ * PHP installs sends only the part integer negative */ - $pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * ($this->type == 'bank-transfer' ? 1 : -1)); + $pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * -1); $pai->datepaye = $date_rejet; $pai->paiementid = 3; // type of payment: withdrawal + $pai->num_paiement = $fac->ref; $pai->num_payment = $fac->ref; - if ($pai->create($this->user) < 0) { - // we call with no_commit + if ($pai->create($this->user) < 0) // we call with no_commit + { $error++; dol_syslog("RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]); - } else { + } + else + { $result = $pai->addPaymentToBank($user, 'payment', '(InvoiceRefused)', $bankaccount, '', ''); - if ($result < 0) { + if ($result < 0) + { dol_syslog("RejetPrelevement::Create AddPaymentToBan Error"); $error++; } // Payment validation - if ($pai->validate($user) < 0) { + if ($pai->valide() < 0) + { $error++; dol_syslog("RejetPrelevement::Create Error payment validation"); } @@ -195,13 +191,15 @@ { dol_syslog("RejetPrelevement::Create Commit"); $this->db->commit(); - } else { + } + else + { dol_syslog("RejetPrelevement::Create Rollback"); $this->db->rollback(); } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Send email to all users that has asked the withdraw request * @@ -210,7 +208,7 @@ */ private function _send_email($fac) { - // phpcs:enable + // phpcs:enable global $langs; $userid = 0; @@ -218,7 +216,7 @@ $sql = "SELECT fk_user_demande"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql .= " WHERE pfd.fk_prelevement_bons = ".$this->bon_id; - $sql .= " AND pfd.fk_facture".($this->type == 'bank-transfer' ? '_fourn=' : '=').$fac->id; + $sql .= " AND pfd.fk_facture = ".$fac->id; $resql = $this->db->query($sql); if ($resql) @@ -229,7 +227,9 @@ $row = $this->db->fetch_row($resql); $userid = $row[0]; } - } else { + } + else + { dol_syslog("RejetPrelevement::_send_email Erreur lecture user"); } @@ -262,12 +262,17 @@ $mailfile = new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $this->user->email, '', $trackid); $result = $mailfile->sendfile(); - if ($result) { + if ($result) + { dol_syslog("RejetPrelevement::_send_email email envoye"); - } else { + } + else + { dol_syslog("RejetPrelevement::_send_email Erreur envoi email"); } - } else { + } + else + { dol_syslog("RejetPrelevement::_send_email Userid invalide"); } } @@ -288,8 +293,7 @@ //Returns all invoices of a withdrawal $sql = "SELECT f.rowid as facid, pl.amount"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture as pf"; - if ($this->type == 'bank-transfer') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)"; - else $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)"; $sql .= " WHERE pf.fk_prelevement_lignes = ".$this->id; $sql .= " AND f.entity IN (".getEntity('invoice').")"; @@ -305,9 +309,9 @@ while ($i < $num) { $row = $this->db->fetch_row($resql); - if (!$amounts) { - $arr[$i] = $row[0]; - } else { + if (!$amounts) $arr[$i] = $row[0]; + else + { $arr[$i] = array( $row[0], $row[1] @@ -317,7 +321,9 @@ } } $this->db->free($resql); - } else { + } + else + { dol_syslog("getListInvoices", LOG_ERR); } @@ -344,19 +350,23 @@ { $obj = $this->db->fetch_object($resql); - $this->id = $rowid; - $this->date_rejet = $this->db->jdate($obj->dr); - $this->motif = $this->motifs[$obj->motif]; + $this->id = $rowid; + $this->date_rejet = $this->db->jdate($obj->dr); + $this->motif = $this->motifs[$obj->motif]; $this->invoicing = $this->facturer[$obj->afacturer]; $this->db->free($resql); return 0; - } else { + } + else + { dol_syslog("RejetPrelevement::Fetch Erreur rowid=$rowid numrows=0"); return -1; } - } else { + } + else + { dol_syslog("RejetPrelevement::Fetch Erreur rowid=$rowid"); return -2; }