mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-13 19:25:22 +01:00
Merge pull request #19705 from atm-maxime/fix_supplier_credit_transfer
Fix supplier credit transfer
This commit is contained in:
@@ -52,8 +52,10 @@ if ($user->socid) {
|
||||
$socid = $user->socid;
|
||||
}
|
||||
|
||||
$moreparam = '';
|
||||
if ($type == 'bank-transfer') {
|
||||
$object = new FactureFournisseur($db);
|
||||
$moreparam = '&type='.$type;
|
||||
} else {
|
||||
$object = new Facture($db);
|
||||
}
|
||||
@@ -138,7 +140,7 @@ $form = new Form($db);
|
||||
$now = dol_now();
|
||||
|
||||
if ($type == 'bank-transfer') {
|
||||
$title = $langs->trans('InvoiceSupplier')." - ".$langs->trans('CreditTransfer');
|
||||
$title = $langs->trans('SupplierInvoice')." - ".$langs->trans('CreditTransfer');
|
||||
$helpurl = "";
|
||||
} else {
|
||||
$title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('StandingOrders');
|
||||
@@ -272,7 +274,7 @@ if ($object->id > 0) {
|
||||
|
||||
$object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
|
||||
|
||||
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '');
|
||||
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $moreparam, 0, '', '');
|
||||
|
||||
print '<div class="fichecenter">';
|
||||
print '<div class="fichehalfleft">';
|
||||
|
||||
@@ -102,22 +102,7 @@ if (empty($reshook)) {
|
||||
}
|
||||
}
|
||||
|
||||
// Seems to no be used and replaced with $action == 'infocredit'
|
||||
if ($action == 'confirm_credite' && GETPOST('confirm', 'alpha') == 'yes') {
|
||||
if ($object->statut == 2) {
|
||||
$res = -1;
|
||||
setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors');
|
||||
} else {
|
||||
$res = $object->set_credite();
|
||||
}
|
||||
|
||||
if ($res >= 0) {
|
||||
header("Location: card.php?id=".$id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'infotrans' && $user->rights->prelevement->bons->send) {
|
||||
if ($action == 'infotrans' && (($user->rights->prelevement->bons->send && $object->type != 'bank-transfer') || ($user->rights->paymentbybanktransfer->send && $object->type == 'bank-transfer'))) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
$dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
@@ -150,10 +135,10 @@ if (empty($reshook)) {
|
||||
}
|
||||
|
||||
// Set direct debit order to credited, create payment and close invoices
|
||||
if ($action == 'infocredit' && $user->rights->prelevement->bons->credit) {
|
||||
if ($action == 'infocredit' && (($user->rights->prelevement->bons->credit && $object->type != 'bank-transfer') || ($user->rights->paymentbybanktransfer->debit && $object->type == 'bank-transfer'))) {
|
||||
$dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
|
||||
if ($object->statut == 2) {
|
||||
if (($object->type != 'bank-transfer' && $object->statut == BonPrelevement::STATUS_CREDITED) || ($object->type == 'bank-transfer' && $object->statut == BonPrelevement::STATUS_DEBITED)) {
|
||||
$error = 1;
|
||||
setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors');
|
||||
} else {
|
||||
@@ -184,12 +169,6 @@ if ($id > 0 || $ref) {
|
||||
print '<div class="error">'.$object->getErrorString(GETPOST('error', 'alpha')).'</div>';
|
||||
}
|
||||
|
||||
/*if ($action == 'credite')
|
||||
{
|
||||
print $form->formconfirm("card.php?id=".$object->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite",'',1,1);
|
||||
|
||||
}*/
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?restore_lastsearch_values=1'.($object->type != 'bank-transfer' ? '' : '&type=bank-transfer').'">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
|
||||
@@ -307,6 +286,7 @@ if ($id > 0 || $ref) {
|
||||
}
|
||||
|
||||
if (!empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action == 'setcredited') {
|
||||
$btnLabel = ($object->type == 'bank-transfer') ? $langs->trans("ClassDebited") : $langs->trans("ClassCredited");
|
||||
print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="infocredit">';
|
||||
@@ -318,25 +298,27 @@ if ($id > 0 || $ref) {
|
||||
print '</td></tr>';
|
||||
print '</table>';
|
||||
print '<br><div class="center"><span class="opacitymedium">'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'</span></div>';
|
||||
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("ClassCredited")).'"></div>';
|
||||
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($btnLabel).'"></div>';
|
||||
print '</form>';
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
|
||||
// Actions
|
||||
if ($action != 'settransmitted' && $action != 'setcredited') {
|
||||
print "\n".'<div class="tabsAction">'."\n";
|
||||
|
||||
if (empty($object->date_trans) && $user->rights->prelevement->bons->send) {
|
||||
print '<a class="butAction" href="card.php?action=settransmitted&token='.newToken().'&id='.$object->id.'">'.$langs->trans("SetToStatusSent").'</a>';
|
||||
if (empty($object->date_trans)) {
|
||||
if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->send);
|
||||
else print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->send);
|
||||
}
|
||||
|
||||
if (!empty($object->date_trans) && $object->date_credit == 0) {
|
||||
print '<a class="butAction" href="card.php?action=setcredited&token='.newToken().'&id='.$object->id.'">'.$langs->trans("ClassCredited").'</a>';
|
||||
if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("ClassDebited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->debit);
|
||||
else print dolGetButtonAction($langs->trans("ClassCredited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->credit);
|
||||
}
|
||||
|
||||
print '<a class="butActionDelete" href="card.php?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
|
||||
if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->create);
|
||||
else print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->creer);
|
||||
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
@@ -332,74 +332,6 @@ class BonPrelevement extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Set credite and set status of linked invoices. Still used ??
|
||||
*
|
||||
* @return int <0 if KO, >=0 if OK
|
||||
*/
|
||||
public function set_credite()
|
||||
{
|
||||
// phpcs:enable
|
||||
global $user, $conf;
|
||||
|
||||
$error = 0;
|
||||
|
||||
if ($this->db->begin()) {
|
||||
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons";
|
||||
$sql .= " SET statut = ".self::STATUS_TRANSFERED;
|
||||
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||
$sql .= " AND entity = ".((int) $conf->entity);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if (!$result) {
|
||||
dol_syslog(get_class($this)."::set_credite Erreur 1");
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$facs = array();
|
||||
$facs = $this->getListInvoices();
|
||||
|
||||
$num = count($facs);
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
/* Tag invoice as paid */
|
||||
dol_syslog(get_class($this)."::set_credite set_paid fac ".$facs[$i]);
|
||||
$fac = new Facture($this->db);
|
||||
$fac->fetch($facs[$i]);
|
||||
$result = $fac->setPaid($user);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
|
||||
$sql .= " SET statut = 2";
|
||||
$sql .= " WHERE fk_prelevement_bons = ".((int) $this->id);
|
||||
|
||||
if (!$this->db->query($sql)) {
|
||||
dol_syslog(get_class($this)."::set_credite Erreur 1");
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* End of procedure
|
||||
*/
|
||||
if (!$error) {
|
||||
$this->db->commit();
|
||||
return 0;
|
||||
} else {
|
||||
$this->db->rollback();
|
||||
dol_syslog(get_class($this)."::set_credite ROLLBACK ");
|
||||
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
dol_syslog(get_class($this)."::set_credite Ouverture transaction SQL impossible ");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Set direct debit or credit transfer order to "paid" status.
|
||||
|
||||
@@ -15,6 +15,7 @@ BankTransferReceipt=Credit transfer order
|
||||
LatestBankTransferReceipts=Latest %s credit transfer orders
|
||||
LastWithdrawalReceipts=Latest %s direct debit files
|
||||
WithdrawalsLine=Direct debit order line
|
||||
CreditTransfer=Credit transfer
|
||||
CreditTransferLine=Credit transfer line
|
||||
WithdrawalsLines=Direct debit order lines
|
||||
CreditTransferLines=Credit transfer lines
|
||||
@@ -47,6 +48,7 @@ ThirdPartyBankCode=Third-party bank code
|
||||
NoInvoiceCouldBeWithdrawed=No invoice debited successfully. Check that invoices are on companies with a valid IBAN and that IBAN has a UMR (Unique Mandate Reference) with mode <strong>%s</strong>.
|
||||
WithdrawalCantBeCreditedTwice=This withdrawal receipt is already marked as credited; this can't be done twice, as this would potentially create duplicate payments and bank entries.
|
||||
ClassCredited=Classify credited
|
||||
ClassDebited=Classify debited
|
||||
ClassCreditedConfirm=Are you sure you want to classify this withdrawal receipt as credited on your bank account?
|
||||
TransData=Transmission date
|
||||
TransMetod=Transmission method
|
||||
|
||||
Reference in New Issue
Block a user