forked from Wavyzz/dolibarr
Merge branch '12.0' of git@github.com:Dolibarr/dolibarr.git into develop
Conflicts: htdocs/compta/facture/class/facture.class.php
This commit is contained in:
@@ -652,6 +652,160 @@ abstract class CommonInvoice extends CommonObject
|
||||
|
||||
return $datelim;
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Create a withdrawal request for a direct debit order or a credit transfer order.
|
||||
* Use the remain to pay excluding all existing open direct debit requests.
|
||||
*
|
||||
* @param User $fuser User asking the direct debit transfer
|
||||
* @param float $amount Amount we request direct debit for
|
||||
* @param string $type 'direct-debit' or 'bank-transfer'
|
||||
* @param string $sourcetype Source ('facture' or 'supplier_invoice')
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'facture')
|
||||
{
|
||||
// phpcs:enable
|
||||
global $conf;
|
||||
|
||||
$error = 0;
|
||||
|
||||
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
|
||||
|
||||
if ($this->statut > self::STATUS_DRAFT && $this->paye == 0)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
|
||||
$bac = new CompanyBankAccount($this->db);
|
||||
$bac->fetch(0, $this->socid);
|
||||
|
||||
$sql = 'SELECT count(*)';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande';
|
||||
if ($type == 'bank-transfer') {
|
||||
$sql .= ' WHERE fk_facture_fourn = '.$this->id;
|
||||
} else {
|
||||
$sql .= ' WHERE fk_facture = '.$this->id;
|
||||
}
|
||||
$sql .= ' AND ext_payment_id IS NULL'; // To exclude record done for some online payments
|
||||
$sql .= ' AND traite = 0';
|
||||
|
||||
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$row = $this->db->fetch_row($resql);
|
||||
if ($row[0] == 0)
|
||||
{
|
||||
$now = dol_now();
|
||||
|
||||
$totalpaye = $this->getSommePaiement();
|
||||
$totalcreditnotes = $this->getSumCreditNotesUsed();
|
||||
$totaldeposits = $this->getSumDepositsUsed();
|
||||
//print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
|
||||
|
||||
// We can also use bcadd to avoid pb with floating points
|
||||
// For example print 239.2 - 229.3 - 9.9; does not return 0.
|
||||
//$resteapayer=bcadd($this->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
|
||||
//$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
|
||||
if (empty($amount)) $amount = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
|
||||
|
||||
if (is_numeric($amount) && $amount != 0)
|
||||
{
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande(';
|
||||
if ($type == 'bank-transfer') {
|
||||
$sql .= 'fk_facture_fourn, ';
|
||||
} else {
|
||||
$sql .= 'fk_facture, ';
|
||||
}
|
||||
$sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, entity)';
|
||||
$sql .= ' VALUES ('.$this->id;
|
||||
$sql .= ",'".price2num($amount)."'";
|
||||
$sql .= ",'".$this->db->idate($now)."'";
|
||||
$sql .= ",".$fuser->id;
|
||||
$sql .= ",'".$this->db->escape($bac->code_banque)."'";
|
||||
$sql .= ",'".$this->db->escape($bac->code_guichet)."'";
|
||||
$sql .= ",'".$this->db->escape($bac->number)."'";
|
||||
$sql .= ",'".$this->db->escape($bac->cle_rib)."'";
|
||||
$sql .= ",'".$this->db->escape($sourcetype)."'";
|
||||
$sql .= ",".$conf->entity;
|
||||
$sql .= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql)
|
||||
{
|
||||
$this->error = $this->db->lasterror();
|
||||
dol_syslog(get_class($this).'::demandeprelevement Erreur');
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = 'WithdrawRequestErrorNilAmount';
|
||||
dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount');
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
// Force payment mode of invoice to withdraw
|
||||
$payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', 1);
|
||||
if ($payment_mode_id > 0)
|
||||
{
|
||||
$result = $this->setPaymentMethods($payment_mode_id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($error) return -1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = "A request already exists";
|
||||
dol_syslog(get_class($this).'::demandeprelevement Impossible de creer une demande, demande deja en cours');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = $this->db->error();
|
||||
dol_syslog(get_class($this).'::demandeprelevement Erreur -2');
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = "Status of invoice does not allow this";
|
||||
dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->statut, $this->paye, $this->mode_reglement_id");
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Remove a direct debit request or a credit transfer request
|
||||
*
|
||||
* @param User $fuser User making delete
|
||||
* @param int $did ID of request to delete
|
||||
* @return int <0 if OK, >0 if KO
|
||||
*/
|
||||
public function demande_prelevement_delete($fuser, $did)
|
||||
{
|
||||
// phpcs:enable
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande';
|
||||
$sql .= ' WHERE rowid = '.$did;
|
||||
$sql .= ' AND traite = 0';
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = $this->db->lasterror();
|
||||
dol_syslog(get_class($this).'::demande_prelevement_delete Error '.$this->error);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1127,7 +1127,7 @@ class DolGraph
|
||||
foreach ($legends as $val) // Loop on each serie
|
||||
{
|
||||
if ($i > 0) $this->stringtoshow .= ', ';
|
||||
$this->stringtoshow .= "'".$val."'";
|
||||
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val,32))."'";
|
||||
$i++;
|
||||
}
|
||||
|
||||
@@ -1189,7 +1189,7 @@ class DolGraph
|
||||
foreach ($legends as $val) // Loop on each serie
|
||||
{
|
||||
if ($i > 0) $this->stringtoshow .= ', ';
|
||||
$this->stringtoshow .= "'".$val."'";
|
||||
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val,32))."'";
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -5545,10 +5545,17 @@ class Form
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.dol_print_date(dol_now(), '%Y', 'tzuser').'\');';
|
||||
} elseif ($addnowlink == 2)
|
||||
{
|
||||
/* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
|
||||
* This break application for foreign languages.
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
|
||||
*/
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date(dol_now(), 'day', 'tzuser').'\');';
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.dol_print_date(dol_now(), '%d', 'tzuser').'\');';
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.dol_print_date(dol_now(), '%m', 'tzuser').'\');';
|
||||
$reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.dol_print_date(dol_now(), '%Y', 'tzuser').'\');';
|
||||
}
|
||||
/*if ($usecalendar == "eldy")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user