Merge pull request #15067 from prietojc/12.0

FIX: Payment by BankTransfer
This commit is contained in:
Laurent Destailleur 2020-10-22 15:59:19 +02:00 committed by GitHub
commit 648efbc0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 19 deletions

6
htdocs/compta/prelevement/card.php Normal file → Executable file
View File

@ -225,7 +225,7 @@ if ($id > 0 || $ref)
print '<table class="border centpercent tableforfield">'; print '<table class="border centpercent tableforfield">';
$acc = new Account($db); $acc = new Account($db);
$result = $acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT); $result = $acc->fetch(($object->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT));
print '<tr><td class="titlefield">'; print '<tr><td class="titlefield">';
$labelofbankfield = "BankToReceiveWithdraw"; $labelofbankfield = "BankToReceiveWithdraw";
@ -404,7 +404,7 @@ if ($id > 0 || $ref)
print "<td>"; print "<td>";
print $ligne->LibStatut($obj->statut, 2); print $ligne->LibStatut($obj->statut, 2);
print "&nbsp;"; print "&nbsp;";
print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'">'; print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'&type='.$object->type.'">';
print sprintf("%06s", $obj->rowid); print sprintf("%06s", $obj->rowid);
print '</a></td>'; print '</a></td>';
@ -430,7 +430,7 @@ if ($id > 0 || $ref)
if ($user->rights->prelevement->bons->credit) if ($user->rights->prelevement->bons->credit)
{ {
//print '<a class="butActionDelete" href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>'; //print '<a class="butActionDelete" href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
print '<a href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>'; print '<a href="line.php?action=rejet&type='.$object->type.'&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
} }
else else
{ {

View File

@ -469,7 +469,7 @@ class BonPrelevement extends CommonObject
$message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour')); $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour'));
//Add payment of withdrawal into bank //Add payment of withdrawal into bank
$bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; $bankaccount = ($this->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
$facs = array(); $facs = array();
$amounts = array(); $amounts = array();
$amountsperthirdparty = array(); $amountsperthirdparty = array();
@ -1766,7 +1766,7 @@ class BonPrelevement extends CommonObject
fputs($this->file, ' <Id>'.$CrLf); fputs($this->file, ' <Id>'.$CrLf);
fputs($this->file, ' <PrvtId>'.$CrLf); fputs($this->file, ' <PrvtId>'.$CrLf);
fputs($this->file, ' <Othr>'.$CrLf); fputs($this->file, ' <Othr>'.$CrLf);
fputs($this->file, ' <Id>'.$conf->global->PRELEVEMENT_ICS.'</Id>'.$CrLf); fputs($this->file, ' <Id>'.$conf->global->PAYMENTBYBANKTRANSFER_ICS.'</Id>'.$CrLf);
fputs($this->file, ' </Othr>'.$CrLf); fputs($this->file, ' </Othr>'.$CrLf);
fputs($this->file, ' </PrvtId>'.$CrLf); fputs($this->file, ' </PrvtId>'.$CrLf);
fputs($this->file, ' </Id>'.$CrLf); fputs($this->file, ' </Id>'.$CrLf);
@ -2185,7 +2185,8 @@ class BonPrelevement extends CommonObject
$dateTime_YMDHMS = dol_print_date($ladate, '%Y-%m-%dT%H:%M:%S'); $dateTime_YMDHMS = dol_print_date($ladate, '%Y-%m-%dT%H:%M:%S');
// Get data of bank account // Get data of bank account
$id = $configuration->global->PRELEVEMENT_ID_BANKACCOUNT; //$id = $configuration->global->PRELEVEMENT_ID_BANKACCOUNT;
$id = ($type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
$account = new Account($this->db); $account = new Account($this->db);
if ($account->fetch($id) > 0) if ($account->fetch($id) > 0)
{ {

View File

@ -39,6 +39,8 @@ class RejetPrelevement
* @var DoliDB Database handler. * @var DoliDB Database handler.
*/ */
public $db; public $db;
public $type; //prelevement or bank transfer
/** /**
@ -47,12 +49,13 @@ class RejetPrelevement
* @param DoliDb $db Database handler * @param DoliDb $db Database handler
* @param User $user Objet user * @param User $user Objet user
*/ */
public function __construct($db, $user) public function __construct($db, $user, $type)
{ {
global $langs; global $langs;
$this->db = $db; $this->db = $db;
$this->user = $user; $this->user = $user;
$this->type = $type;
$this->motifs = array(); $this->motifs = array();
$this->facturer = array(); $this->facturer = array();
@ -92,7 +95,7 @@ class RejetPrelevement
$now = dol_now(); $now = dol_now();
dol_syslog("RejetPrelevement::Create id $id"); dol_syslog("RejetPrelevement::Create id $id");
$bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; $bankaccount = ($this->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
$facs = $this->getListInvoices(1); $facs = $this->getListInvoices(1);
$this->db->begin(); $this->db->begin();
@ -137,11 +140,19 @@ class RejetPrelevement
$num = count($facs); $num = count($facs);
for ($i = 0; $i < $num; $i++) for ($i = 0; $i < $num; $i++)
{ {
$fac = new Facture($this->db); 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);
}
$fac->fetch($facs[$i][0]); $fac->fetch($facs[$i][0]);
// Make a negative payment // Make a negative payment
$pai = new Paiement($this->db); //$pai = new Paiement($this->db);
$pai->amounts = array(); $pai->amounts = array();
@ -150,7 +161,7 @@ class RejetPrelevement
* PHP installs sends only the part integer negative * PHP installs sends only the part integer negative
*/ */
$pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * -1); $pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * ($this->type == 'bank-transfer' ? 1: -1));
$pai->datepaye = $date_rejet; $pai->datepaye = $date_rejet;
$pai->paiementid = 3; // type of payment: withdrawal $pai->paiementid = 3; // type of payment: withdrawal
$pai->num_paiement = $fac->ref; $pai->num_paiement = $fac->ref;
@ -216,7 +227,7 @@ class RejetPrelevement
$sql = "SELECT fk_user_demande"; $sql = "SELECT fk_user_demande";
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql .= " WHERE pfd.fk_prelevement_bons = ".$this->bon_id; $sql .= " WHERE pfd.fk_prelevement_bons = ".$this->bon_id;
$sql .= " AND pfd.fk_facture = ".$fac->id; $sql .= " AND pfd.fk_facture".($this->type == 'bank-transfer' ? '_fourn=': '=').$fac->id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
@ -293,7 +304,10 @@ class RejetPrelevement
//Returns all invoices of a withdrawal //Returns all invoices of a withdrawal
$sql = "SELECT f.rowid as facid, pl.amount"; $sql = "SELECT f.rowid as facid, pl.amount";
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture as pf"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture as pf";
$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)";
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."prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.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 .= " WHERE pf.fk_prelevement_lignes = ".$this->id;
$sql .= " AND f.entity IN (".getEntity('invoice').")"; $sql .= " AND f.entity IN (".getEntity('invoice').")";

0
htdocs/compta/prelevement/index.php Normal file → Executable file
View File

13
htdocs/compta/prelevement/line.php Normal file → Executable file
View File

@ -97,11 +97,11 @@ if ($action == 'confirm_rejet')
if ($lipre->fetch($id) == 0) if ($lipre->fetch($id) == 0)
{ {
$rej = new RejetPrelevement($db, $user); $rej = new RejetPrelevement($db, $user,$type);
$rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int')); $rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int'));
header("Location: line.php?id=".$id); header("Location: line.php?id=".$id.'&type='.$type);
exit; exit;
} }
} }
@ -112,7 +112,7 @@ if ($action == 'confirm_rejet')
} }
else else
{ {
header("Location: line.php?id=".$id); header("Location: line.php?id=".$id.'&type='.$type);
exit; exit;
} }
} }
@ -134,7 +134,7 @@ llxHeader('', $title);
$head = array(); $head = array();
$h = 0; $h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id.'&type='.$type;
$head[$h][1] = $title; $head[$h][1] = $title;
$hselected = $h; $hselected = $h;
$h++; $h++;
@ -203,11 +203,12 @@ if ($id)
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($lipre->socid); $soc->fetch($lipre->socid);
$rej = new RejetPrelevement($db, $user); $rej = new RejetPrelevement($db, $user, $type);
print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">'; print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="confirm_rejet">'; print '<input type="hidden" name="action" value="confirm_rejet">';
print '<input type="hidden" name="type" value="'.$type.'">';
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
@ -258,7 +259,7 @@ if ($id)
if ($lipre->statut == 2) { if ($lipre->statut == 2) {
if ($user->rights->prelevement->bons->credit) if ($user->rights->prelevement->bons->credit)
{ {
print '<a class="butActionDelete" href="line.php?action=rejet&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>'; print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
} }
else else
{ {