subscription.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2012-2017 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/adherents/subscription.php
  25. * \ingroup member
  26. * \brief tab for Adding, editing, deleting a member's memberships
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  38. $langs->loadLangs(array("companies", "bills", "members", "users", "mails", 'other'));
  39. $action = GETPOST('action', 'alpha');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $rowid = GETPOST('rowid', 'int') ?GETPOST('rowid', 'int') : GETPOST('id', 'int');
  42. $typeid = GETPOST('typeid', 'int');
  43. // Load variable for pagination
  44. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'alpha');
  46. $sortorder = GETPOST('sortorder', 'alpha');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  49. $offset = $limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. // Default sort order (if not yet defined by previous GETPOST)
  53. if (!$sortfield) $sortfield = "c.rowid";
  54. if (!$sortorder) $sortorder = "DESC";
  55. // Security check
  56. $result = restrictedArea($user, 'adherent', $rowid, '', 'cotisation');
  57. $object = new Adherent($db);
  58. $extrafields = new ExtraFields($db);
  59. $adht = new AdherentType($db);
  60. // fetch optionals attributes and labels
  61. $extrafields->fetch_name_optionals_label($object->table_element);
  62. $errmsg = '';
  63. $defaultdelay = 1;
  64. $defaultdelayunit = 'y';
  65. if ($rowid) {
  66. // Load member
  67. $result = $object->fetch($rowid);
  68. // Define variables to know what current user can do on users
  69. $canadduser = ($user->admin || $user->rights->user->user->creer);
  70. // Define variables to know what current user can do on properties of user linked to edited member
  71. if ($object->user_id) {
  72. // $user is the user editing, $object->user_id is the user's id linked to the edited member
  73. $caneditfielduser = ((($user->id == $object->user_id) && $user->rights->user->self->creer)
  74. || (($user->id != $object->user_id) && $user->rights->user->user->creer));
  75. $caneditpassworduser = ((($user->id == $object->user_id) && $user->rights->user->self->password)
  76. || (($user->id != $object->user_id) && $user->rights->user->user->password));
  77. }
  78. }
  79. // Define variables to know what current user can do on members
  80. $canaddmember = $user->rights->adherent->creer;
  81. // Define variables to know what current user can do on properties of a member
  82. if ($rowid) {
  83. $caneditfieldmember = $user->rights->adherent->creer;
  84. }
  85. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  86. $hookmanager->initHooks(array('subscription'));
  87. // PDF
  88. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  89. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  90. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  91. /*
  92. * Actions
  93. */
  94. // Create third party from a member
  95. if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) {
  96. if ($result > 0) {
  97. // Creation of thirdparty
  98. $company = new Societe($db);
  99. $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
  100. if ($result < 0) {
  101. $langs->load("errors");
  102. setEventMessages($company->error, $company->errors, 'errors');
  103. } else {
  104. $action = 'addsubscription';
  105. }
  106. } else {
  107. setEventMessages($object->error, $object->errors, 'errors');
  108. }
  109. }
  110. if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer)) {
  111. $error = 0;
  112. if (empty($user->rights->user->user->creer)) { // If can edit only itself user, we can link to itself only
  113. if ($_POST["userid"] != $user->id && $_POST["userid"] != $object->user_id) {
  114. $error++;
  115. setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
  116. }
  117. }
  118. if (!$error) {
  119. if ($_POST["userid"] != $object->user_id) { // If link differs from currently in database
  120. $result = $object->setUserId($_POST["userid"]);
  121. if ($result < 0) dol_print_error('', $object->error);
  122. $_POST['action'] = '';
  123. $action = '';
  124. }
  125. }
  126. }
  127. if ($action == 'setsocid') {
  128. $error = 0;
  129. if (!$error) {
  130. if (GETPOST('socid', 'int') != $object->fk_soc) { // If link differs from currently in database
  131. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
  132. $sql .= " WHERE fk_soc = '".GETPOST('socid', 'int')."'";
  133. $resql = $db->query($sql);
  134. if ($resql) {
  135. $obj = $db->fetch_object($resql);
  136. if ($obj && $obj->rowid > 0) {
  137. $othermember = new Adherent($db);
  138. $othermember->fetch($obj->rowid);
  139. $thirdparty = new Societe($db);
  140. $thirdparty->fetch(GETPOST('socid', 'int'));
  141. $error++;
  142. setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
  143. }
  144. }
  145. if (!$error) {
  146. $result = $object->setThirdPartyId(GETPOST('socid', 'int'));
  147. if ($result < 0) dol_print_error('', $object->error);
  148. $_POST['action'] = '';
  149. $action = '';
  150. }
  151. }
  152. }
  153. }
  154. if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !$_POST["cancel"]) {
  155. $error = 0;
  156. $langs->load("banks");
  157. $result = $object->fetch($rowid);
  158. $result = $adht->fetch($object->typeid);
  159. // Subscription informations
  160. $datesubscription = 0;
  161. $datesubend = 0;
  162. $paymentdate = 0;
  163. if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"]) {
  164. $datesubscription = dol_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
  165. }
  166. if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"]) {
  167. $datesubend = dol_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]);
  168. }
  169. if ($_POST["paymentyear"] && $_POST["paymentmonth"] && $_POST["paymentday"]) {
  170. $paymentdate = dol_mktime(0, 0, 0, $_POST["paymentmonth"], $_POST["paymentday"], $_POST["paymentyear"]);
  171. }
  172. $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription
  173. $label = $_POST["label"];
  174. // Payment informations
  175. $accountid = $_POST["accountid"];
  176. $operation = $_POST["operation"]; // Payment mode
  177. $num_chq = GETPOST("num_chq", "alphanohtml");
  178. $emetteur_nom = $_POST["chqemetteur"];
  179. $emetteur_banque = $_POST["chqbank"];
  180. $option = $_POST["paymentsave"];
  181. if (empty($option)) $option = 'none';
  182. $sendalsoemail = GETPOST("sendmail", 'alpha');
  183. // Check parameters
  184. if (!$datesubscription) {
  185. $error++;
  186. $langs->load("errors");
  187. $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription"));
  188. setEventMessages($errmsg, null, 'errors');
  189. $action = 'addsubscription';
  190. }
  191. if (GETPOST('end') && !$datesubend) {
  192. $error++;
  193. $langs->load("errors");
  194. $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription"));
  195. setEventMessages($errmsg, null, 'errors');
  196. $action = 'addsubscription';
  197. }
  198. if (!$datesubend) {
  199. $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
  200. }
  201. if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate) {
  202. $error++;
  203. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
  204. setEventMessages($errmsg, null, 'errors');
  205. $action = 'addsubscription';
  206. }
  207. // Check if a payment is mandatory or not
  208. if (!$error && $adht->subscription) { // Member type need subscriptions
  209. if (!is_numeric($amount)) {
  210. // If field is '' or not a numeric value
  211. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
  212. setEventMessages($errmsg, null, 'errors');
  213. $error++;
  214. $action = 'addsubscription';
  215. } else {
  216. if (!empty($conf->banque->enabled) && $_POST["paymentsave"] != 'none') {
  217. if ($_POST["subscription"]) {
  218. if (!$_POST["label"]) $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
  219. if ($_POST["paymentsave"] != 'invoiceonly' && !$_POST["operation"]) $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
  220. if ($_POST["paymentsave"] != 'invoiceonly' && !($_POST["accountid"] > 0)) $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount"));
  221. } else {
  222. if ($_POST["accountid"]) $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
  223. }
  224. if ($errmsg) {
  225. $error++;
  226. setEventMessages($errmsg, null, 'errors');
  227. $error++;
  228. $action = 'addsubscription';
  229. }
  230. }
  231. }
  232. }
  233. // Record the subscription then complementary actions
  234. if (!$error && $action == 'subscription') {
  235. $db->begin();
  236. // Create subscription
  237. $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
  238. if ($crowid <= 0) {
  239. $error++;
  240. $errmsg = $object->error;
  241. setEventMessages($object->error, $object->errors, 'errors');
  242. }
  243. if (!$error) {
  244. $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque);
  245. if ($result < 0) {
  246. $error++;
  247. setEventMessages($object->error, $object->errors, 'errors');
  248. } else {
  249. // If an invoice was created, it is into $object->invoice
  250. }
  251. }
  252. if (!$error) {
  253. $db->commit();
  254. } else {
  255. $db->rollback();
  256. $action = 'addsubscription';
  257. }
  258. if (!$error) {
  259. setEventMessages("SubscriptionRecorded", null, 'mesgs');
  260. }
  261. // Send email
  262. if (!$error) {
  263. // Send confirmation Email
  264. if ($object->email && $sendalsoemail) { // $object is 'Adherent'
  265. $subject = '';
  266. $msg = '';
  267. // Send subscription email
  268. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  269. $formmail = new FormMail($db);
  270. // Set output language
  271. $outputlangs = new Translate('', $conf);
  272. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  273. // Load traductions files required by page
  274. $outputlangs->loadLangs(array("main", "members"));
  275. // Get email content from template
  276. $arraydefaultmessage = null;
  277. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  278. if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  279. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  280. $subject = $arraydefaultmessage->topic;
  281. $msg = $arraydefaultmessage->content;
  282. }
  283. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  284. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  285. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  286. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  287. // Attach a file ?
  288. $file = '';
  289. $listofpaths = array();
  290. $listofnames = array();
  291. $listofmimes = array();
  292. if (is_object($object->invoice)) {
  293. $invoicediroutput = $conf->facture->dir_output;
  294. $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
  295. $file = $fileparams['fullname'];
  296. $listofpaths = array($file);
  297. $listofnames = array(basename($file));
  298. $listofmimes = array(dol_mimetype($file));
  299. }
  300. $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
  301. $result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
  302. if ($result < 0) {
  303. $errmsg = $object->error;
  304. setEventMessages($object->error, $object->errors, 'errors');
  305. } else {
  306. setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
  307. }
  308. } else {
  309. setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
  310. }
  311. }
  312. // Clean some POST vars
  313. if (!$error) {
  314. $_POST["subscription"] = '';
  315. $_POST["accountid"] = '';
  316. $_POST["operation"] = '';
  317. $_POST["label"] = '';
  318. $_POST["num_chq"] = '';
  319. }
  320. }
  321. }
  322. /*
  323. * View
  324. */
  325. $form = new Form($db);
  326. $now = dol_now();
  327. $title = $langs->trans("Member")." - ".$langs->trans("Subscriptions");
  328. $helpurl = "EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros";
  329. llxHeader("", $title, $helpurl);
  330. $param = '';
  331. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  332. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
  333. $param .= '&id='.$rowid;
  334. if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
  335. // Add $param from extra fields
  336. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  337. if ($rowid > 0) {
  338. $res = $object->fetch($rowid);
  339. if ($res < 0) { dol_print_error($db, $object->error); exit; }
  340. $adht->fetch($object->typeid);
  341. $head = member_prepare_head($object);
  342. $rowspan = 10;
  343. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan++;
  344. if (!empty($conf->societe->enabled)) $rowspan++;
  345. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  346. print '<input type="hidden" name="token" value="'.newToken().'">';
  347. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  348. dol_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
  349. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  350. dol_banner_tab($object, 'rowid', $linkback);
  351. print '<div class="fichecenter">';
  352. print '<div class="fichehalfleft">';
  353. print '<div class="underbanner clearboth"></div>';
  354. print '<table class="border centpercent tableforfield">';
  355. // Login
  356. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  357. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  358. }
  359. // Type
  360. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  361. // Morphy
  362. print '<tr><td>'.$langs->trans("MemberNature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
  363. print '</tr>';
  364. // Company
  365. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->company.'</td></tr>';
  366. // Civility
  367. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'&nbsp;</td>';
  368. print '</tr>';
  369. // Password
  370. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  371. print '<tr><td>'.$langs->trans("Password").'</td><td>'.preg_replace('/./i', '*', $object->pass);
  372. if ((!empty($object->pass) || !empty($object->pass_crypted)) && empty($object->user_id)) {
  373. $langs->load("errors");
  374. $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
  375. print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
  376. }
  377. print '</td></tr>';
  378. }
  379. print '</table>';
  380. print '</div>';
  381. print '<div class="fichehalfright"><div class="ficheaddleft">';
  382. print '<div class="underbanner clearboth"></div>';
  383. print '<table class="border tableforfield" width="100%">';
  384. // Birthday
  385. print '<tr><td class="titlefield">'.$langs->trans("Birthday").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
  386. // Public
  387. print '<tr><td>'.$langs->trans("Public").'</td><td class="valeur">'.yn($object->public).'</td></tr>';
  388. // Categories
  389. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
  390. print '<tr><td>'.$langs->trans("Categories").'</td>';
  391. print '<td colspan="2">';
  392. print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
  393. print '</td></tr>';
  394. }
  395. // Other attributes
  396. $cols = 2;
  397. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  398. // Date end subscription
  399. print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
  400. if ($object->datefin) {
  401. print dol_print_date($object->datefin, 'day');
  402. if ($object->hasDelay()) {
  403. print " ".img_warning($langs->trans("Late"));
  404. }
  405. } else {
  406. if (!$adht->subscription) {
  407. print $langs->trans("SubscriptionNotRecorded");
  408. if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
  409. } else {
  410. print $langs->trans("SubscriptionNotReceived");
  411. if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
  412. }
  413. }
  414. print '</td></tr>';
  415. // Third party Dolibarr
  416. if (!empty($conf->societe->enabled)) {
  417. print '<tr><td>';
  418. print '<table class="nobordernopadding" width="100%"><tr><td>';
  419. print $langs->trans("LinkedToDolibarrThirdParty");
  420. print '</td>';
  421. if ($action != 'editthirdparty' && $user->rights->adherent->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'), 1).'</a></td>';
  422. print '</tr></table>';
  423. print '</td><td colspan="2" class="valeur">';
  424. if ($action == 'editthirdparty') {
  425. $htmlname = 'socid';
  426. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
  427. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  428. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  429. print '<input type="hidden" name="token" value="'.newToken().'">';
  430. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  431. print '<tr><td>';
  432. print $form->select_company($object->fk_soc, 'socid', '', 1);
  433. print '</td>';
  434. print '<td class="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  435. print '</tr></table></form>';
  436. } else {
  437. if ($object->fk_soc) {
  438. $company = new Societe($db);
  439. $result = $company->fetch($object->fk_soc);
  440. print $company->getNomUrl(1);
  441. } else {
  442. print $langs->trans("NoThirdPartyAssociatedToMember");
  443. }
  444. }
  445. print '</td></tr>';
  446. }
  447. // Login Dolibarr
  448. print '<tr><td>';
  449. print '<table class="nobordernopadding" width="100%"><tr><td>';
  450. print $langs->trans("LinkedToDolibarrUser");
  451. print '</td>';
  452. if ($action != 'editlogin' && $user->rights->adherent->creer) {
  453. print '<td class="right">';
  454. if ($user->rights->user->user->creer) {
  455. print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlogin&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
  456. }
  457. print '</td>';
  458. }
  459. print '</tr></table>';
  460. print '</td><td colspan="2" class="valeur">';
  461. if ($action == 'editlogin') {
  462. $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
  463. } else {
  464. if ($object->user_id) {
  465. $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'none');
  466. } else print $langs->trans("NoDolibarrAccess");
  467. }
  468. print '</td></tr>';
  469. print "</table>\n";
  470. print "</div></div></div>\n";
  471. print '<div style="clear:both"></div>';
  472. dol_fiche_end();
  473. print '</form>';
  474. /*
  475. * Action buttons
  476. */
  477. // Button to create a new subscription if member no draft neither resiliated
  478. if ($user->rights->adherent->cotisation->creer) {
  479. if ($action != 'addsubscription' && $action != 'create_thirdparty') {
  480. print '<div class="tabsAction">';
  481. if ($object->statut > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription">'.$langs->trans("AddSubscription")."</a></div>";
  482. else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
  483. print '</div>';
  484. }
  485. }
  486. /*
  487. * List of subscriptions
  488. */
  489. if ($action != 'addsubscription' && $action != 'create_thirdparty') {
  490. $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
  491. $sql .= " c.rowid as crowid, c.subscription,";
  492. $sql .= " c.datec, c.fk_type as cfk_type,";
  493. $sql .= " c.dateadh as dateh,";
  494. $sql .= " c.datef,";
  495. $sql .= " c.fk_bank,";
  496. $sql .= " b.rowid as bid,";
  497. $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
  498. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
  499. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
  500. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  501. $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".$rowid;
  502. $sql .= $db->order($sortfield, $sortorder);
  503. $result = $db->query($sql);
  504. if ($result) {
  505. $subscriptionstatic = new Subscription($db);
  506. $num = $db->num_rows($result);
  507. print '<table class="noborder centpercent">'."\n";
  508. print '<tr class="liste_titre">';
  509. print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
  510. print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  511. print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  512. print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  513. print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  514. print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  515. if (!empty($conf->banque->enabled)) {
  516. print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  517. }
  518. print "</tr>\n";
  519. $accountstatic = new Account($db);
  520. $adh = new Adherent($db);
  521. $adht = new AdherentType($db);
  522. $i = 0;
  523. while ($i < $num) {
  524. $objp = $db->fetch_object($result);
  525. $adh->id = $objp->rowid;
  526. $adh->typeid = $objp->type;
  527. $subscriptionstatic->ref = $objp->crowid;
  528. $subscriptionstatic->id = $objp->crowid;
  529. $typeid = ($objp->cfk_type > 0 ? $objp->cfk_type : $adh->typeid);
  530. if ($typeid > 0) {
  531. $adht->fetch($typeid);
  532. }
  533. print '<tr class="oddeven">';
  534. print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
  535. print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
  536. print '<td class="center">';
  537. if ($typeid > 0) {
  538. print $adht->getNomUrl(1);
  539. }
  540. print '</td>';
  541. print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
  542. print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
  543. print '<td class="right">'.price($objp->subscription).'</td>';
  544. if (!empty($conf->banque->enabled)) {
  545. print '<td class="right">';
  546. if ($objp->bid) {
  547. $accountstatic->label = $objp->label;
  548. $accountstatic->id = $objp->baid;
  549. $accountstatic->number = $objp->number;
  550. $accountstatic->account_number = $objp->account_number;
  551. $accountstatic->currency_code = $objp->currency_code;
  552. if (!empty($conf->accounting->enabled) && $objp->fk_accountancy_journal > 0) {
  553. $accountingjournal = new AccountingJournal($db);
  554. $accountingjournal->fetch($objp->fk_accountancy_journal);
  555. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  556. }
  557. $accountstatic->ref = $objp->ref;
  558. print $accountstatic->getNomUrl(1);
  559. } else {
  560. print '&nbsp;';
  561. }
  562. print '</td>';
  563. }
  564. print "</tr>";
  565. $i++;
  566. }
  567. if (empty($num)) {
  568. $colspan = 6;
  569. if (!empty($conf->banque->enabled)) $colspan++;
  570. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  571. }
  572. print "</table>";
  573. } else {
  574. dol_print_error($db);
  575. }
  576. }
  577. if (($action != 'addsubscription' && $action != 'create_thirdparty')) {
  578. // Shon online payment link
  579. $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
  580. if ($useonlinepayment) {
  581. print '<br>';
  582. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  583. print showOnlinePaymentUrl('membersubscription', $object->ref);
  584. print '<br>';
  585. }
  586. }
  587. /*
  588. * Add new subscription form
  589. */
  590. if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->rights->adherent->cotisation->creer) {
  591. print '<br>';
  592. print load_fiche_titre($langs->trans("NewCotisation"));
  593. // Define default choice for complementary actions
  594. $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice
  595. $invoiceonly = 0; // 1 means option by default is invoice only
  596. $bankviainvoice = 0; // 1 means option by default is write to bank via invoice
  597. if (GETPOST('paymentsave')) {
  598. if (GETPOST('paymentsave') == 'bankdirect') $bankdirect = 1;
  599. if (GETPOST('paymentsave') == 'invoiceonly') $invoiceonly = 1;
  600. if (GETPOST('paymentsave') == 'bankviainvoice') $bankviainvoice = 1;
  601. } else {
  602. if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && !empty($conf->banque->enabled) && !empty($conf->societe->enabled) && !empty($conf->facture->enabled)) $bankviainvoice = 1;
  603. elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && !empty($conf->banque->enabled)) $bankdirect = 1;
  604. elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && !empty($conf->banque->enabled) && !empty($conf->societe->enabled) && !empty($conf->facture->enabled)) $invoiceonly = 1;
  605. }
  606. print "\n\n<!-- Form add subscription -->\n";
  607. if ($conf->use_javascript_ajax) {
  608. //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
  609. print "\n".'<script type="text/javascript" language="javascript">';
  610. print '$(document).ready(function () {
  611. $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect || $bankviainvoice) ? 'show()' : 'hide()').';
  612. $("#none, #invoiceonly").click(function() {
  613. $(".bankswitchclass").hide();
  614. $(".bankswitchclass2").hide();
  615. });
  616. $("#bankdirect, #bankviainvoice").click(function() {
  617. $(".bankswitchclass").show();
  618. $(".bankswitchclass2").show();
  619. });
  620. $("#selectoperation").change(function() {
  621. var code = $(this).val();
  622. if (code == "CHQ")
  623. {
  624. $(".fieldrequireddyn").addClass("fieldrequired");
  625. if ($("#fieldchqemetteur").val() == "")
  626. {
  627. $("#fieldchqemetteur").val($("#memberlabel").val());
  628. }
  629. }
  630. else
  631. {
  632. $(".fieldrequireddyn").removeClass("fieldrequired");
  633. }
  634. });
  635. ';
  636. if (GETPOST('paymentsave')) print '$("#'.GETPOST('paymentsave').'").prop("checked",true);';
  637. print '});';
  638. print '</script>'."\n";
  639. }
  640. // Confirm create third party
  641. if ($action == 'create_thirdparty') {
  642. $companyalias = '';
  643. $fullname = $object->getFullName($langs);
  644. if ($object->morphy == 'mor') {
  645. $companyname = $object->company;
  646. if (!empty($fullname)) $companyalias = $fullname;
  647. } else {
  648. $companyname = $fullname;
  649. if (!empty($object->company)) $companyalias = $object->company;
  650. }
  651. // Create a form array
  652. $formquestion = array(
  653. array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
  654. array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
  655. );
  656. // If customer code was forced to "required", we ask it at creation to avoid error later
  657. if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) {
  658. $tmpcompany = new Societe($db);
  659. $tmpcompany->name = $companyname;
  660. $tmpcompany->get_codeclient($tmpcompany, 0);
  661. $customercode = $tmpcompany->code_client;
  662. $formquestion[] = array(
  663. 'label' => $langs->trans("CustomerCode"),
  664. 'type' => 'text',
  665. 'name' => 'customercode',
  666. 'value' => $customercode,
  667. 'morecss' => 'minwidth300',
  668. 'moreattr' => 'maxlength="128"',
  669. );
  670. }
  671. // @todo Add other extrafields mandatory for thirdparty creation
  672. print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
  673. }
  674. print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  675. print '<input type="hidden" name="token" value="'.newToken().'">';
  676. print '<input type="hidden" name="action" value="subscription">';
  677. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  678. print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
  679. print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
  680. dol_fiche_head('');
  681. print "<table class=\"border\" width=\"100%\">\n";
  682. print '<tbody>';
  683. $today = dol_now();
  684. $datefrom = 0;
  685. $dateto = 0;
  686. $paymentdate = -1;
  687. // Date payment
  688. if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) {
  689. $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
  690. }
  691. print '<tr>';
  692. // Date start subscription
  693. print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
  694. if (GETPOST('reday')) {
  695. $datefrom = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  696. }
  697. if (!$datefrom) {
  698. $datefrom = $object->datevalid;
  699. if ($object->datefin > 0) {
  700. $datefrom = dol_time_plus_duree($object->datefin, 1, 'd');
  701. }
  702. }
  703. print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
  704. print "</td></tr>";
  705. // Date end subscription
  706. if (GETPOST('endday')) {
  707. $dateto = dol_mktime(0, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
  708. }
  709. if (!$dateto) {
  710. $dateto = -1; // By default, no date is suggested
  711. }
  712. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
  713. print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
  714. print "</td></tr>";
  715. if ($adht->subscription) {
  716. // Amount
  717. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="subscription" size="6" value="'.GETPOST('subscription').'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
  718. // Label
  719. print '<tr><td>'.$langs->trans("Label").'</td>';
  720. print '<td><input name="label" type="text" size="32" value="';
  721. if (empty($conf->global->MEMBER_NO_DEFAULT_LABEL)) print $langs->trans("Subscription").' '.dol_print_date(($datefrom ? $datefrom : time()), "%Y");
  722. print '"></td></tr>';
  723. // Complementary action
  724. if ((!empty($conf->banque->enabled) || !empty($conf->facture->enabled)) && empty($conf->global->ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS)) {
  725. $company = new Societe($db);
  726. if ($object->fk_soc) {
  727. $result = $company->fetch($object->fk_soc);
  728. }
  729. // Title payments
  730. //print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
  731. // No more action
  732. print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
  733. print '</td>';
  734. print '<td>';
  735. print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice) ? ' checked' : '').'> '.$langs->trans("None").'<br>';
  736. // Add entry into bank accoun
  737. if (!empty($conf->banque->enabled)) {
  738. print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(!empty($bankdirect) ? ' checked' : '');
  739. print '> '.$langs->trans("MoreActionBankDirect").'<br>';
  740. }
  741. // Add invoice with no payments
  742. if (!empty($conf->societe->enabled) && !empty($conf->facture->enabled)) {
  743. print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(!empty($invoiceonly) ? ' checked' : '');
  744. //if (empty($object->fk_soc)) print ' disabled';
  745. print '> '.$langs->trans("MoreActionInvoiceOnly");
  746. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  747. else {
  748. print ' (';
  749. if (empty($object->fk_soc)) print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  750. print $langs->trans("NoThirdPartyAssociatedToMember");
  751. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  752. print $langs->trans("CreateDolibarrThirdParty");
  753. print '</a>)';
  754. }
  755. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
  756. if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) {
  757. $prodtmp = new Product($db);
  758. $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  759. if ($result < 0) {
  760. setEventMessage($prodtmp->error, 'errors');
  761. }
  762. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  763. }
  764. print '<br>';
  765. }
  766. // Add invoice with payments
  767. if (!empty($conf->banque->enabled) && !empty($conf->societe->enabled) && !empty($conf->facture->enabled)) {
  768. print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(!empty($bankviainvoice) ? ' checked' : '');
  769. //if (empty($object->fk_soc)) print ' disabled';
  770. print '> '.$langs->trans("MoreActionBankViaInvoice");
  771. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  772. else {
  773. print ' (';
  774. if (empty($object->fk_soc)) print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  775. print $langs->trans("NoThirdPartyAssociatedToMember");
  776. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  777. print $langs->trans("CreateDolibarrThirdParty");
  778. print '</a>)';
  779. }
  780. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
  781. if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) {
  782. $prodtmp = new Product($db);
  783. $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  784. if ($result < 0) {
  785. setEventMessage($prodtmp->error, 'errors');
  786. }
  787. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  788. }
  789. print '<br>';
  790. }
  791. print '</td></tr>';
  792. // Bank account
  793. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
  794. $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 1);
  795. print "</td></tr>\n";
  796. // Payment mode
  797. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  798. $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2);
  799. print "</td></tr>\n";
  800. // Date of payment
  801. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  802. print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1);
  803. print "</td></tr>\n";
  804. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
  805. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  806. print '</td>';
  807. print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(!GETPOST('num_chq') ? '' : GETPOST('num_chq')).'"></td></tr>';
  808. print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
  809. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  810. print '</td>';
  811. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(!GETPOST('chqemetteur') ? '' : GETPOST('chqemetteur')).'"></td></tr>';
  812. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
  813. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  814. print '</td>';
  815. print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(!GETPOST('chqbank') ? '' : GETPOST('chqbank')).'"></td></tr>';
  816. }
  817. }
  818. print '<tr><td></td><td></td></tr>';
  819. print '<tr><td>'.$langs->trans("SendAcknowledgementByMail").'</td>';
  820. print '<td>';
  821. if (!$object->email) {
  822. print $langs->trans("NoEMail");
  823. } else {
  824. $adht = new AdherentType($db);
  825. $adht->fetch($object->typeid);
  826. // Send subscription email
  827. $subject = '';
  828. $msg = '';
  829. // Send subscription email
  830. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  831. $formmail = new FormMail($db);
  832. // Set output language
  833. $outputlangs = new Translate('', $conf);
  834. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  835. // Load traductions files required by page
  836. $outputlangs->loadLangs(array("main", "members"));
  837. // Get email content from template
  838. $arraydefaultmessage = null;
  839. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  840. if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  841. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  842. $subject = $arraydefaultmessage->topic;
  843. $msg = $arraydefaultmessage->content;
  844. }
  845. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  846. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  847. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  848. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  849. $tmp = '<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha') ? ' checked' : (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? ' checked' : '')).'>';
  850. $helpcontent = '';
  851. $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
  852. $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
  853. $helpcontent .= '<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
  854. if ($subjecttosend) {
  855. $helpcontent .= $subjecttosend."\n";
  856. } else {
  857. $langs->load("errors");
  858. $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
  859. }
  860. $helpcontent .= "<br>";
  861. $helpcontent .= '<b>'.$langs->trans("MailText").'</b>:<br>';
  862. if ($texttosend) {
  863. $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
  864. } else {
  865. $langs->load("errors");
  866. $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
  867. }
  868. print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
  869. }
  870. print '</td></tr>';
  871. print '</tbody>';
  872. print '</table>';
  873. dol_fiche_end();
  874. print '<div class="center">';
  875. print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
  876. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  877. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  878. print '</div>';
  879. print '</form>';
  880. print "\n<!-- End form subscription -->\n\n";
  881. }
  882. //print '</td></tr>';
  883. //print '</table>';
  884. } else {
  885. $langs->load("errors");
  886. print $langs->trans("ErrorRecordNotFound");
  887. }
  888. // End of page
  889. llxFooter();
  890. $db->close();