fix : move check if invoice module is enabled into paymentok.php

This commit is contained in:
Nicolas 2021-07-01 11:55:06 +02:00
parent 4e1fe23b7e
commit 9b71f1e16b
2 changed files with 63 additions and 58 deletions

View File

@ -2633,7 +2633,7 @@ if ($action == 'create' && $usercancreate)
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
// Show online payment link // Show online payment link
$useonlinepayment = ((!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)) && !empty($conf->facture->enabled)); $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) $useonlinepayment = 0; if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) $useonlinepayment = 0;
if ($object->statut != Commande::STATUS_DRAFT && $useonlinepayment) if ($object->statut != Commande::STATUS_DRAFT && $useonlinepayment)
{ {

View File

@ -742,80 +742,85 @@ if ($ispaymentok)
$currencyCodeType = $_SESSION['currencyCodeType']; $currencyCodeType = $_SESSION['currencyCodeType'];
// Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time) // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) { if (!empty($conf->banque->enabled)) {
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; if (!empty($FinalPaymentAmt) && $paymentTypeId > 0 ) {
$invoice = new Facture($db); include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
$result = $invoice->createFromOrder($object, $user); $invoice = new Facture($db);
if ($result > 0) { $result = $invoice->createFromOrder($object, $user);
$object->classifyBilled($user); if ($result > 0) {
$invoice->validate($user); $object->classifyBilled($user);
// Creation of payment line $invoice->validate($user);
include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; // Creation of payment line
$paiement = new Paiement($db); include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
$paiement->datepaye = $now; $paiement = new Paiement($db);
if ($currencyCodeType == $conf->currency) { $paiement->datepaye = $now;
$paiement->amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id if ($currencyCodeType == $conf->currency) {
} else { $paiement->amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
$paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching
$postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
$ispostactionok = -1;
$error++; // Not yet supported
}
$paiement->paiementid = $paymentTypeId;
$paiement->num_payment = '';
$paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress;
$paiement->ext_payment_id = $TRANSACTIONID;
$paiement->ext_payment_site = $service;
if (!$error) {
$paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
if ($paiement_id < 0) {
$postactionmessages[] = $paiement->error . ' ' . join("<br>\n", $paiement->errors);
$ispostactionok = -1;
$error++;
} else { } else {
$postactionmessages[] = 'Payment created'; $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching
$ispostactionok = 1;
$postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
$ispostactionok = -1;
$error++; // Not yet supported
} }
} $paiement->paiementid = $paymentTypeId;
$paiement->num_payment = '';
$paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress;
$paiement->ext_payment_id = $TRANSACTIONID;
$paiement->ext_payment_site = '';
if (!$error && !empty($conf->banque->enabled)) { if (!$error) {
$bankaccountid = 0; $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS; if ($paiement_id < 0) {
elseif ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
if ($bankaccountid > 0) {
$label = '(CustomerInvoicePayment)';
if ($object->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
$result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
if ($result < 0) {
$postactionmessages[] = $paiement->error . ' ' . join("<br>\n", $paiement->errors); $postactionmessages[] = $paiement->error . ' ' . join("<br>\n", $paiement->errors);
$ispostactionok = -1; $ispostactionok = -1;
$error++; $error++;
} else { } else {
$postactionmessages[] = 'Bank transaction of payment created'; $postactionmessages[] = 'Payment created';
$ispostactionok = 1; $ispostactionok = 1;
} }
} else {
$postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.';
$ispostactionok = -1;
$error++;
} }
}
if (!$error) { if (!$error && !empty($conf->banque->enabled)) {
$db->commit(); $bankaccountid = 0;
if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
elseif ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
if ($bankaccountid > 0) {
$label = '(CustomerInvoicePayment)';
if ($object->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
$result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
if ($result < 0) {
$postactionmessages[] = $paiement->error . ' ' . join("<br>\n", $paiement->errors);
$ispostactionok = -1;
$error++;
} else {
$postactionmessages[] = 'Bank transaction of payment created';
$ispostactionok = 1;
}
} else {
$postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.';
$ispostactionok = -1;
$error++;
}
}
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
} else { } else {
$db->rollback(); $postactionmessages[] = 'Failed to create invoice form order ' . $tmptag['ORD'] . '.';
$ispostactionok = -1;
} }
} else { } else {
$postactionmessages[] = 'Failed to create invoice form order ' . $tmptag['ORD'] . '.'; $postactionmessages[] = 'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt . ') or "payment type" (' . $paymentType . ') to record the payment of order ' . $tmptag['ORD'] . '. May be payment was already recorded.';
$ispostactionok = -1; $ispostactionok = -1;
} }
} else { } else {
$postactionmessages[] = 'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt . ') or "payment type" (' . $paymentType . ') to record the payment of order ' . $tmptag['ORD'] . '. May be payment was already recorded.'; $postactionmessages[] = 'Invoice module is not enable';
$ispostactionok = -1; $ispostactionok = -1;
} }
} else { } else {