Merge pull request #9483 from ptibogxiv/patch-54

New donation module
This commit is contained in:
Laurent Destailleur 2018-09-12 17:34:21 +02:00 committed by GitHub
commit 10becd2046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 129 additions and 27 deletions

View File

@ -236,6 +236,24 @@ function getOnlinePaymentUrl($mode, $type, $ref='', $amount='9.99', $freetag='yo
}
}
}
if ($type == 'donation')
{
$out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=donation&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='donation_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
{
if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
else
{
$out.='&securekey='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + donation_ref)";
if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
$out.=($mode?'</font>':'');
}
}
}
// For multicompany
if (! empty($out) && ! empty($conf->multicompany->enabled)) $out.="&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities

View File

@ -1,4 +1,4 @@
<?php
<<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@destailleur.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -118,6 +118,28 @@ if (! empty($conf->adherent->enabled))
}
print '<br>';
}
if (! empty($conf->don->enabled))
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnDonation",$servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1,'donation')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{
$langs->load("members");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Don")).': ';
print '<input type="text class="flat" id="generate_donation_ref" name="generate_donation_ref" value="'.GETPOST('generate_donation_ref','alpha').'" size="10">';
print '<input type="submit" class="none reposition button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_donation_ref'))
{
print '<br> -> <strong>';
$url=getOnlinePaymentUrl(0,'donation',GETPOST('generate_donation_ref','alpha'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
print '<br>';
}
if (! empty($conf->use_javascript_ajax))
{
@ -140,3 +162,4 @@ print info_admin($langs->trans("YouCanAddTagOnUrl"));
print '<!-- END PHP TEMPLATE ONLINEPAYMENTLINKS -->';

View File

@ -4,6 +4,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2018 Thibault FOUCART <support@ptibogxiv.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,23 +27,24 @@
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
if (! empty($conf->projet->enabled))
require_once DOL_DOCUMENT_ROOT . '/core/modules/dons/modules_don.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/donation.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmargin.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
if (! empty($conf->projet->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$langs->load("companies");
$langs->load("donations");
$langs->load("bills");
$langs->loadLangs(array("bills","companies","donations")); // File with generic data
$id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
$action=GETPOST('action','alpha');
@ -325,18 +327,54 @@ if ($action == 'create')
print '<table class="border" width="100%">';
print '<tbody>';
// Date
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Date").'</td><td>';
$form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1);
print '</td>';
// Amount
print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" value="'.dol_escape_htmltag(GETPOST("amount")).'" size="10"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1);
print "</td></tr>\n";
// Ref
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans('Ref') . '</td><td colspan="2">' . $langs->trans('Draft') . '</td></tr>';
if (! empty($conf->societe->enabled)) {
// Thirdparty
print '<td class="fieldrequired">' . $langs->trans('Customer') . '</td>';
if ($soc->id > 0 && ! GETPOST('fac_rec','alpha'))
{
print '<td colspan="2">';
print $soc->getNomUrl(1);
print '<input type="hidden" name="socid" value="' . $soc->id . '">';
// Outstanding Bill
$outstandingBills = $soc->get_OutstandingBill();
print ' (' . $langs->trans('CurrentOutstandingBill') . ': ';
print price($outstandingBills, '', $langs, 0, 0, -1, $conf->currency);
if ($soc->outstanding_limit != '')
{
if ($outstandingBills > $soc->outstanding_limit) print img_warning($langs->trans("OutstandingBillReached"));
print ' / ' . price($soc->outstanding_limit, '', $langs, 0, 0, -1, $conf->currency);
}
print ')';
print '</td>';
}
else
{
print '<td colspan="2">';
print $form->select_company($soc->id, 'socid', '(s.client = 1 OR s.client = 3) AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300');
// Option to reload page to retrieve customer informations. Note, this clear other input
if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE))
{
print '<script type="text/javascript">
$(document).ready(function() {
$("#socid").change(function() {
var socid = $(this).val();
var fac_rec = $(\'#fac_rec\').val();
// reload page
window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&fac_rec="+fac_rec;
});
});
</script>';
}
print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'">'.$langs->trans("AddThirdParty").'</a>';
print '</td>';
}
print '</tr>' . "\n";
} else {
print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" value="'.dol_escape_htmltag(GETPOST("societe")).'" class="maxwidth200"></td></tr>';
print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" value="'.dol_escape_htmltag(GETPOST("lastname")).'" class="maxwidth200"></td></tr>';
@ -346,18 +384,31 @@ if ($action == 'create')
// Zip / Town
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
print ' ';
print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
print '</tr>';
// Country
// Country
print '<tr><td><label for="selectcountry_id">'.$langs->trans('Country').'</label></td><td class="maxwidthonsmartphone">';
print $form->select_country(GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id);
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print '</td></tr>';
print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.dol_escape_htmltag(GETPOST("email")).'" class="maxwidth200"></td></tr>';
print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.dol_escape_htmltag(GETPOST("email")).'" class="maxwidth200"></td></tr>';
}
// Date
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Date").'</td><td>';
$form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1);
print '</td>';
// Amount
print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" value="'.dol_escape_htmltag(GETPOST("amount")).'" size="10"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1);
print "</td></tr>\n";
// Payment mode
print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
@ -790,6 +841,16 @@ if (! empty($id) && $action != 'edit')
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('don'));
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
// Show online payment link
$useonlinepayment = (! empty($conf->paypal->enabled) || ! empty($conf->stripe->enabled) || ! empty($conf->paybox->enabled));
if ($useonlinepayment) //$object->statut != Facture::STATUS_DRAFT &&
{
print '<br><!-- Link to pay -->'."\n";
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
print showOnlinePaymentUrl('donation', $object->ref).'<br>';
}
print '</div><div class="fichehalfright"><div class="ficheaddleft">';