adaptation of the payment for the booth location case

This commit is contained in:
Dorian Vabre 2021-04-27 12:30:49 +02:00
parent 151819b7ad
commit b24b297a40
4 changed files with 341 additions and 45 deletions

View File

@ -119,5 +119,6 @@ ConfAttendeeSubscriptionConfirmation = Confirmation of your subscription to a co
#
# Payment page
#
Attendee = Participant
PaymentConferenceAttendee = Paiement de participation à une conférence
Attendee = Attendee
PaymentConferenceAttendee = Conference attendee payment
PaymentBoothLocation = Booth location payment

View File

@ -142,6 +142,23 @@ if ($source == 'conferencesubscription') {
}
}
}
} elseif ($source == 'boothlocation') {
// Getting the amount to pay, the invoice, finding the thirdparty
$invoiceid = GETPOST('ref');
$invoice = new Facture($db);
$resultinvoice = $invoice->fetch($invoiceid);
if ($resultinvoice <= 0) {
setEventMessages(null, $invoice->errors, "errors");
} else {
$amount = price2num($invoice->total_ttc);
// Finding the associated thirdparty
$thirdparty = new Societe($db);
$resultthirdparty = $thirdparty->fetch($invoice->socid);
if ($resultthirdparty <= 0) {
setEventMessages(null, $thirdparty->errors, "errors");
}
$object = $thirdparty;
}
}
@ -1862,6 +1879,96 @@ if ($source == 'conferencesubscription') {
print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
}
if ($source == 'boothlocation') {
$found = true;
$langs->load("members");
if (GETPOST('fulltag', 'alpha')) {
$fulltag = GETPOST('fulltag', 'alpha');
} else {
$fulltag = 'BOO='.GETPOST("booth").'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
if (!empty($TAG)) {
$tag = $TAG; $fulltag .= '.TAG='.$TAG;
}
}
$fulltag = dol_string_unaccent($fulltag);
// Creditor
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("Creditor");
print '</td><td class="CTableRow'.($var ? '1' : '2').'"><b>'.$creditor.'</b>';
print '<input type="hidden" name="creditor" value="'.$creditor.'">';
print '</td></tr>'."\n";
// Debitor
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("Attendee");
print '</td><td class="CTableRow'.($var ? '1' : '2').'"><b>';
print $thirdparty->name;
print '</b>';
print '</td></tr>'."\n";
// Object
$text = '<b>'.$langs->trans("PaymentBoothLocation").'</b>';
if (GETPOST('desc', 'alpha')) {
$text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
}
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("Designation");
print '</td><td class="CTableRow'.($var ? '1' : '2').'">'.$text;
print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($invoice->id).'">';
print '</td></tr>'."\n";
// Amount
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("Amount");
print '</td><td class="CTableRow'.($var ? '1' : '2').'">';
$valtoshow = $amount;
print '<b>'.price($valtoshow).'</b>';
print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("PaymentCode");
print '</td><td class="CTableRow'.($var ? '1' : '2').'"><b style="word-break: break-all;">'.$fulltag.'</b>';
print '<input type="hidden" name="tag" value="'.$tag.'">';
print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
print '</td></tr>'."\n";
// Shipping address
$shipToName = $thirdparty->getFullName($langs);
$shipToStreet = $thirdparty->address;
$shipToCity = $thirdparty->town;
$shipToState = $thirdparty->state_code;
$shipToCountryCode = $thirdparty->country_code;
$shipToZip = $thirdparty->zip;
$shipToStreet2 = '';
$phoneNum = $thirdparty->phone;
if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
print '<!-- Shipping address information -->';
print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
} else {
print '<!-- Shipping address not complete, so we don t use it -->'."\n";
}
print '<input type="hidden" name="thirdparty_id" value="'.$thirdparty->id.'">'."\n";
print '<input type="hidden" name="email" value="'.$thirdparty->email.'">'."\n";
$labeldesc = $langs->trans("PaymentSubscription");
if (GETPOST('desc', 'alpha')) {
$labeldesc = GETPOST('desc', 'alpha');
}
print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
}
if (!$found && !$mesg) {
$mesg = $langs->trans("ErrorBadParameters");
}

View File

@ -104,7 +104,6 @@ if (empty($FULLTAG)) {
}
$source = GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha');
$ref = GETPOST('ref');
$invoiceref = GETPOST('invoice');
$suffix = GETPOST("suffix", 'aZ09');
$membertypeid = GETPOST("membertypeid", 'int');
@ -893,48 +892,51 @@ if ($ispaymentok) {
// Sending mail
$thirdparty = new Societe($db);
$thirdparty->fetch($attendeetovalidate->fk_soc);
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
// Set output language
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
// Load traductions files required by page
$outputlangs->loadLangs(array("main", "members"));
// Get email content from template
$arraydefaultmessage = null;
$labeltouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
if (!empty($labeltouse)) {
$arraydefaultmessage = $formmail->getEMailTemplate($db, 'eventorganization_send', $user, $outputlangs, $labeltouse, 1, '');
}
if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
$subject = $arraydefaultmessage->topic;
$msg = $arraydefaultmessage->content;
}
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
complete_substitutions_array($substitutionarray, $outputlangs, $object);
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
$texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
$sendto = $thirdparty->email;
$from = $conf->global->MAILING_EMAIL_FROM;
$urlback = $_SERVER["REQUEST_URI"];
$ishtml = dol_textishtml($texttosend); // May contain urls
$mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
$result = $mailfile->sendfile();
if ($result) {
dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
$resultthirdparty = $thirdparty->fetch($attendeetovalidate->fk_soc);
if ($resultthirdparty < 0) {
setEventMessages(null, $attendeetovalidate->errors, "errors");
} else {
dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
// Set output language
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
// Load traductions files required by page
$outputlangs->loadLangs(array("main", "members"));
// Get email content from template
$arraydefaultmessage = null;
$labeltouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
if (!empty($labeltouse)) {
$arraydefaultmessage = $formmail->getEMailTemplate($db, 'eventorganization_send', $user, $outputlangs, $labeltouse, 1, '');
}
if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
$subject = $arraydefaultmessage->topic;
$msg = $arraydefaultmessage->content;
}
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
complete_substitutions_array($substitutionarray, $outputlangs, $object);
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
$texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
$sendto = $thirdparty->email;
$from = $conf->global->MAILING_EMAIL_FROM;
$urlback = $_SERVER["REQUEST_URI"];
$ishtml = dol_textishtml($texttosend); // May contain urls
$mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
$result = $mailfile->sendfile();
if ($result) {
dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
} else {
dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
}
}
}
} else {
@ -951,6 +953,192 @@ if ($ispaymentok) {
}
} elseif (array_key_exists('BOO', $tmptag) && $tmptag['BOO'] > 0) {
// @todo BOOTH CASE (to copy and adapt from above)
// Record payment
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$object = new Facture($db);
$result = $object->fetch($ref);
if ($result) {
$FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
$paymentTypeId = 0;
if ($paymentmethod == 'paybox') {
$paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
}
if ($paymentmethod == 'paypal') {
$paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
}
if ($paymentmethod == 'stripe') {
$paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
}
if (empty($paymentTypeId)) {
$paymentType = $_SESSION["paymentType"];
if (empty($paymentType)) {
$paymentType = 'CB';
}
$paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
}
$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)
if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
$resultvalidate = $object->validate($user);
if ($resultvalidate < 0) {
$postactionmessages[] = 'Cannot validate invoice';
$ispostactionok = -1;
$error++; // Not yet supported
} else {
$db->begin();
// Creation of payment line
include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
$paiement = new Paiement($db);
$paiement->datepaye = $now;
if ($currencyCodeType == $conf->currency) {
$paiement->amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
} else {
$paiement->multicurrency_amounts = array($object->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 {
$postactionmessages[] = 'Payment created';
$ispostactionok = 1;
}
}
if (!$error && !empty($conf->banque->enabled)) {
$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) {
// Putting the booth to "suggested" state
$booth = new ConferenceOrBooth($db);
$resultbooth = $booth->fetch($tmptag['BOO']);
if ($resultbooth < 0) {
$error++;
setEventMessages(null, $booth->errors, "errors");
} else {
$booth->setStatut(CONFERENCEORBOOTH::STATUS_SUGGESTED);
$resultboothupdate = $booth->update($user);
if ($resultboothupdate<0) {
// Finding the thirdparty by getting the invoice
$invoice = new Facture($db);
$resultinvoice = $invoice->fetch($ref);
if ($resultinvoice<0) {
$postactionmessages[] = 'Could not find the associated invoice.';
$ispostactionok = -1;
$error++;
} else {
$thirdparty = new Societe($db);
$resultthirdparty = $thirdparty->fetch($invoice->socid);
if ($resultthirdparty<0) {
$error++;
setEventMessages(null, $thirdparty->errors, "errors");
} else {
// Sending mail
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
// Set output language
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
// Load traductions files required by page
$outputlangs->loadLangs(array("main", "members"));
// Get email content from template
$arraydefaultmessage = null;
$labeltouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
if (!empty($labeltouse)) {
$arraydefaultmessage = $formmail->getEMailTemplate($db, 'eventorganization_send', $user, $outputlangs, $labeltouse, 1, '');
}
if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
$subject = $arraydefaultmessage->topic;
$msg = $arraydefaultmessage->content;
}
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
complete_substitutions_array($substitutionarray, $outputlangs, $object);
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
$texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
$sendto = $thirdparty->email;
$from = $conf->global->MAILING_EMAIL_FROM;
$urlback = $_SERVER["REQUEST_URI"];
$ishtml = dol_textishtml($texttosend); // May contain urls
$mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
$result = $mailfile->sendfile();
if ($result) {
dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
} else {
dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
}
}
}
}
}
}
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
}
} else {
$postactionmessages[] = 'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.') or "payment type" ('.$paymentType.') to record the payment of invoice '.$tmptag['ATT'].'. May be payment was already recorded.';
$ispostactionok = -1;
}
} else {
$postactionmessages[] = 'Invoice paid '.$tmptag['ATT'].' was not found';
$ispostactionok = -1;
}
} else {
// Nothing done
}

View File

@ -434,7 +434,7 @@ if (empty($reshook) && $action == 'add') {
$valid = true;
$sourcetouse = 'boothlocation';
$reftouse = $facture->id;
$redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source='.$sourcetouse.'&ref='.$reftouse;
$redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source='.$sourcetouse.'&ref='.$reftouse.'&booth='.$conforbooth->id;
if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
$redirection .= '&securekey='.dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $sourcetouse . $reftouse, 2); // Use the source in the hash to avoid duplicates if the references are identical