subscription.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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-2023 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. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  39. $langs->loadLangs(array("companies", "bills", "members", "users", "mails", 'other'));
  40. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  41. $action = GETPOST('action', 'aZ09');
  42. $confirm = GETPOST('confirm', 'alpha');
  43. $id = GETPOST('rowid', 'int') ?GETPOST('rowid', 'int') : GETPOST('id', 'int');
  44. $rowid = $id;
  45. $ref = GETPOST('ref', 'alphanohtml');
  46. $typeid = GETPOST('typeid', 'int');
  47. $cancel = GETPOST('cancel');
  48. // Load variable for pagination
  49. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  50. $sortfield = GETPOST('sortfield', 'aZ09comma');
  51. $sortorder = GETPOST('sortorder', 'aZ09comma');
  52. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  53. if (empty($page) || $page == -1) {
  54. $page = 0;
  55. } // If $page is not defined, or '' or -1
  56. $offset = $limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. // Default sort order (if not yet defined by previous GETPOST)
  60. if (!$sortfield) {
  61. $sortfield = "c.rowid";
  62. }
  63. if (!$sortorder) {
  64. $sortorder = "DESC";
  65. }
  66. $object = new Adherent($db);
  67. $extrafields = new ExtraFields($db);
  68. $adht = new AdherentType($db);
  69. // fetch optionals attributes and labels
  70. $extrafields->fetch_name_optionals_label($object->table_element);
  71. $errmsg = '';
  72. $defaultdelay = 1;
  73. $defaultdelayunit = 'y';
  74. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  75. $hookmanager->initHooks(array('subscription'));
  76. // PDF
  77. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  78. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  79. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  80. $datefrom = 0;
  81. $dateto = 0;
  82. $paymentdate = -1;
  83. // Fetch object
  84. if ($id > 0 || !empty($ref)) {
  85. // Load member
  86. $result = $object->fetch($id, $ref);
  87. // Define variables to know what current user can do on users
  88. $canadduser = ($user->admin || $user->hasRight("user", "user", "creer"));
  89. // Define variables to know what current user can do on properties of user linked to edited member
  90. if ($object->user_id) {
  91. // $User is the user who edits, $object->user_id is the id of the related user in the edited member
  92. $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "creer"))
  93. || (($user->id != $object->user_id) && $user->hasRight("user", "user", "creer")));
  94. $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "password"))
  95. || (($user->id != $object->user_id) && $user->hasRight("user", "user", "password")));
  96. }
  97. }
  98. // Define variables to determine what the current user can do on the members
  99. $canaddmember = $user->hasRight('adherent', 'creer');
  100. // Define variables to determine what the current user can do on the properties of a member
  101. if ($id) {
  102. $caneditfieldmember = $user->hasRight('adherent', 'creer');
  103. }
  104. // Security check
  105. $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
  106. /*
  107. * Actions
  108. */
  109. $parameters = array();
  110. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  111. if ($reshook < 0) {
  112. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  113. }
  114. // Create third party from a member
  115. if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) {
  116. if ($result > 0) {
  117. // Creation of thirdparty
  118. $company = new Societe($db);
  119. $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
  120. if ($result < 0) {
  121. $langs->load("errors");
  122. setEventMessages($company->error, $company->errors, 'errors');
  123. } else {
  124. $action = 'addsubscription';
  125. }
  126. } else {
  127. setEventMessages($object->error, $object->errors, 'errors');
  128. }
  129. }
  130. if (empty($reshook) && $action == 'setuserid' && ($user->rights->user->self->creer || $user->hasRight('user', 'user', 'creer'))) {
  131. $error = 0;
  132. if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only
  133. if (GETPOST("userid", 'int') != $user->id && GETPOST("userid", 'int') != $object->user_id) {
  134. $error++;
  135. setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
  136. }
  137. }
  138. if (!$error) {
  139. if (GETPOST("userid", 'int') != $object->user_id) { // If link differs from currently in database
  140. $result = $object->setUserId(GETPOST("userid", 'int'));
  141. if ($result < 0) {
  142. dol_print_error('', $object->error);
  143. }
  144. $action = '';
  145. }
  146. }
  147. }
  148. if (empty($reshook) && $action == 'setsocid') {
  149. $error = 0;
  150. if (!$error) {
  151. if (GETPOST('socid', 'int') != $object->fk_soc) { // If link differs from currently in database
  152. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
  153. $sql .= " WHERE fk_soc = '".GETPOST('socid', 'int')."'";
  154. $resql = $db->query($sql);
  155. if ($resql) {
  156. $obj = $db->fetch_object($resql);
  157. if ($obj && $obj->rowid > 0) {
  158. $othermember = new Adherent($db);
  159. $othermember->fetch($obj->rowid);
  160. $thirdparty = new Societe($db);
  161. $thirdparty->fetch(GETPOST('socid', 'int'));
  162. $error++;
  163. setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
  164. }
  165. }
  166. if (!$error) {
  167. $result = $object->setThirdPartyId(GETPOST('socid', 'int'));
  168. if ($result < 0) {
  169. dol_print_error('', $object->error);
  170. }
  171. $action = '';
  172. }
  173. }
  174. }
  175. }
  176. if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'subscription' && !$cancel) {
  177. $error = 0;
  178. $langs->load("banks");
  179. $result = $object->fetch($rowid);
  180. $result = $adht->fetch($object->typeid);
  181. // Subscription informations
  182. $datesubscription = 0;
  183. $datesubend = 0;
  184. $paymentdate = ''; // Do not use 0 here, default value is '' that means not filled where 0 means 1970-01-01
  185. if (GETPOST("reyear", "int") && GETPOST("remonth", "int") && GETPOST("reday", "int")) {
  186. $datesubscription = dol_mktime(0, 0, 0, GETPOST("remonth", "int"), GETPOST("reday", "int"), GETPOST("reyear", "int"));
  187. }
  188. if (GETPOST("endyear", 'int') && GETPOST("endmonth", 'int') && GETPOST("endday", 'int')) {
  189. $datesubend = dol_mktime(0, 0, 0, GETPOST("endmonth", 'int'), GETPOST("endday", 'int'), GETPOST("endyear", 'int'));
  190. }
  191. if (GETPOST("paymentyear", 'int') && GETPOST("paymentmonth", 'int') && GETPOST("paymentday", 'int')) {
  192. $paymentdate = dol_mktime(0, 0, 0, GETPOST("paymentmonth", 'int'), GETPOST("paymentday", 'int'), GETPOST("paymentyear", 'int'));
  193. }
  194. $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription
  195. $label = GETPOST("label");
  196. // Payment informations
  197. $accountid = GETPOST("accountid", 'int');
  198. $operation = GETPOST("operation", "alphanohtml"); // Payment mode
  199. $num_chq = GETPOST("num_chq", "alphanohtml");
  200. $emetteur_nom = GETPOST("chqemetteur");
  201. $emetteur_banque = GETPOST("chqbank");
  202. $option = GETPOST("paymentsave");
  203. if (empty($option)) {
  204. $option = 'none';
  205. }
  206. $sendalsoemail = GETPOST("sendmail", 'alpha');
  207. // Check parameters
  208. if (!$datesubscription) {
  209. $error++;
  210. $langs->load("errors");
  211. $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription"));
  212. setEventMessages($errmsg, null, 'errors');
  213. $action = 'addsubscription';
  214. }
  215. if (GETPOST('end') && !$datesubend) {
  216. $error++;
  217. $langs->load("errors");
  218. $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription"));
  219. setEventMessages($errmsg, null, 'errors');
  220. $action = 'addsubscription';
  221. }
  222. if (!$datesubend) {
  223. $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
  224. }
  225. if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate) {
  226. $error++;
  227. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
  228. setEventMessages($errmsg, null, 'errors');
  229. $action = 'addsubscription';
  230. }
  231. // Check if a payment is mandatory or not
  232. if ($adht->subscription) { // Member type need subscriptions
  233. if (!is_numeric($amount)) {
  234. // If field is '' or not a numeric value
  235. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
  236. setEventMessages($errmsg, null, 'errors');
  237. $error++;
  238. $action = 'addsubscription';
  239. } else {
  240. // If an amount has been provided, we check also fields that becomes mandatory when amount is not null.
  241. if (isModEnabled('banque') && GETPOST("paymentsave") != 'none') {
  242. if (GETPOST("subscription")) {
  243. if (!GETPOST("label")) {
  244. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
  245. setEventMessages($errmsg, null, 'errors');
  246. $error++;
  247. $action = 'addsubscription';
  248. }
  249. if (GETPOST("paymentsave") != 'invoiceonly' && !GETPOST("operation")) {
  250. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
  251. setEventMessages($errmsg, null, 'errors');
  252. $error++;
  253. $action = 'addsubscription';
  254. }
  255. if (GETPOST("paymentsave") != 'invoiceonly' && !(GETPOST("accountid", 'int') > 0)) {
  256. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount"));
  257. setEventMessages($errmsg, null, 'errors');
  258. $error++;
  259. $action = 'addsubscription';
  260. }
  261. } else {
  262. if (GETPOST("accountid", 'int')) {
  263. $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
  264. setEventMessages($errmsg, null, 'errors');
  265. $error++;
  266. $action = 'addsubscription';
  267. }
  268. }
  269. }
  270. }
  271. }
  272. // Record the subscription then complementary actions
  273. if (!$error && $action == 'subscription') {
  274. $db->begin();
  275. // Create subscription
  276. $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
  277. if ($crowid <= 0) {
  278. $error++;
  279. $errmsg = $object->error;
  280. setEventMessages($object->error, $object->errors, 'errors');
  281. }
  282. if (!$error) {
  283. $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque);
  284. if ($result < 0) {
  285. $error++;
  286. setEventMessages($object->error, $object->errors, 'errors');
  287. } else {
  288. // If an invoice was created, it is into $object->invoice
  289. }
  290. }
  291. if (!$error) {
  292. $db->commit();
  293. } else {
  294. $db->rollback();
  295. $action = 'addsubscription';
  296. }
  297. if (!$error) {
  298. setEventMessages("SubscriptionRecorded", null, 'mesgs');
  299. }
  300. // Send email
  301. if (!$error) {
  302. // Send confirmation Email
  303. if ($object->email && $sendalsoemail) { // $object is 'Adherent'
  304. $parameters = array(
  305. 'datesubscription' => $datesubscription,
  306. 'amount' => $amount,
  307. 'ccountid' => $accountid,
  308. 'operation' => $operation,
  309. 'label' => $label,
  310. 'num_chq' => $num_chq,
  311. 'emetteur_nom' => $emetteur_nom,
  312. 'emetteur_banque' => $emetteur_banque,
  313. 'datesubend' => $datesubend
  314. );
  315. $reshook = $hookmanager->executeHooks('sendMail', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  316. if ($reshook < 0) {
  317. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  318. }
  319. if (empty($reshook)) {
  320. $subject = '';
  321. $msg = '';
  322. // Send subscription email
  323. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  324. $formmail = new FormMail($db);
  325. // Set output language
  326. $outputlangs = new Translate('', $conf);
  327. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  328. // Load traductions files required by page
  329. $outputlangs->loadLangs(array("main", "members"));
  330. // Get email content from template
  331. $arraydefaultmessage = null;
  332. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  333. if (!empty($labeltouse)) {
  334. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  335. }
  336. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  337. $subject = $arraydefaultmessage->topic;
  338. $msg = $arraydefaultmessage->content;
  339. }
  340. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  341. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  342. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  343. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  344. // Attach a file ?
  345. $file = '';
  346. $listofpaths = array();
  347. $listofnames = array();
  348. $listofmimes = array();
  349. if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) {
  350. $invoicediroutput = $conf->facture->dir_output;
  351. $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
  352. $file = $fileparams['fullname'];
  353. $listofpaths = array($file);
  354. $listofnames = array(basename($file));
  355. $listofmimes = array(dol_mimetype($file));
  356. }
  357. $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
  358. $result = $object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
  359. if ($result < 0) {
  360. $errmsg = $object->error;
  361. setEventMessages($object->error, $object->errors, 'errors');
  362. } else {
  363. setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
  364. }
  365. }
  366. } else {
  367. setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
  368. }
  369. }
  370. // Clean some POST vars
  371. if (!$error) {
  372. $_POST["subscription"] = '';
  373. $_POST["accountid"] = '';
  374. $_POST["operation"] = '';
  375. $_POST["label"] = '';
  376. $_POST["num_chq"] = '';
  377. }
  378. }
  379. }
  380. /*
  381. * View
  382. */
  383. $form = new Form($db);
  384. $now = dol_now();
  385. $title = $langs->trans("Member")." - ".$langs->trans("Subscriptions");
  386. $help_url = "EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder";
  387. llxHeader("", $title, $help_url);
  388. $param = '';
  389. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  390. $param .= '&contextpage='.urlencode($contextpage);
  391. }
  392. if ($limit > 0 && $limit != $conf->liste_limit) {
  393. $param .= '&limit='.((int) $limit);
  394. }
  395. $param .= '&id='.$rowid;
  396. if ($optioncss != '') {
  397. $param .= '&optioncss='.urlencode($optioncss);
  398. }
  399. // Add $param from extra fields
  400. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  401. if ($rowid > 0) {
  402. $res = $object->fetch($rowid);
  403. if ($res < 0) {
  404. dol_print_error($db, $object->error);
  405. exit;
  406. }
  407. $adht->fetch($object->typeid);
  408. $head = member_prepare_head($object);
  409. $rowspan = 10;
  410. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  411. $rowspan++;
  412. }
  413. if (isModEnabled('societe')) {
  414. $rowspan++;
  415. }
  416. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  417. print '<input type="hidden" name="token" value="'.newToken().'">';
  418. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  419. print dol_get_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
  420. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  421. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
  422. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  423. $morehtmlref .= '</a>';
  424. dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  425. print '<div class="fichecenter">';
  426. print '<div class="fichehalfleft">';
  427. print '<div class="underbanner clearboth"></div>';
  428. print '<table class="border centpercent tableforfield">';
  429. // Login
  430. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  431. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
  432. }
  433. // Type
  434. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td>';
  435. print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  436. // Morphy
  437. print '<tr><td>'.$langs->trans("MemberNature").'</td>';
  438. print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
  439. print '</tr>';
  440. // Company
  441. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
  442. // Civility
  443. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
  444. print '</tr>';
  445. // Password
  446. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  447. print '<tr><td>'.$langs->trans("Password").'</td><td>';
  448. if ($object->pass) {
  449. print preg_replace('/./i', '*', $object->pass);
  450. } else {
  451. if ($user->admin) {
  452. print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
  453. }
  454. print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
  455. }
  456. if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
  457. $langs->load("errors");
  458. $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
  459. print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
  460. }
  461. print '</td></tr>';
  462. }
  463. // Date end subscription
  464. print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
  465. if ($object->datefin) {
  466. print dol_print_date($object->datefin, 'day');
  467. if ($object->hasDelay()) {
  468. print " ".img_warning($langs->trans("Late"));
  469. }
  470. } else {
  471. if ($object->need_subscription == 0) {
  472. print $langs->trans("SubscriptionNotNeeded");
  473. } elseif (!$adht->subscription) {
  474. print $langs->trans("SubscriptionNotRecorded");
  475. if (Adherent::STATUS_VALIDATED == $object->statut) {
  476. print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
  477. }
  478. } else {
  479. print $langs->trans("SubscriptionNotReceived");
  480. if (Adherent::STATUS_VALIDATED == $object->statut) {
  481. print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
  482. }
  483. }
  484. }
  485. print '</td></tr>';
  486. print '</table>';
  487. print '</div>';
  488. print '<div class="fichehalfright">';
  489. print '<div class="underbanner clearboth"></div>';
  490. print '<table class="border tableforfield centpercent">';
  491. // Tags / Categories
  492. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  493. print '<tr><td>'.$langs->trans("Categories").'</td>';
  494. print '<td colspan="2">';
  495. print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
  496. print '</td></tr>';
  497. }
  498. // Birth Date
  499. print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
  500. // Public
  501. print '<tr><td>'.$langs->trans("Public").'</td><td class="valeur">'.yn($object->public).'</td></tr>';
  502. // Other attributes
  503. $cols = 2;
  504. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  505. // Third party Dolibarr
  506. if (isModEnabled('societe')) {
  507. print '<tr><td>';
  508. print '<table class="nobordernopadding" width="100%"><tr><td>';
  509. print $langs->trans("LinkedToDolibarrThirdParty");
  510. print '</td>';
  511. if ($action != 'editthirdparty' && $user->hasRight('adherent', 'creer')) {
  512. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'), 1).'</a></td>';
  513. }
  514. print '</tr></table>';
  515. print '</td><td colspan="2" class="valeur">';
  516. if ($action == 'editthirdparty') {
  517. $htmlname = 'socid';
  518. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
  519. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  520. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  521. print '<input type="hidden" name="token" value="'.newToken().'">';
  522. print '<table class="nobordernopadding">';
  523. print '<tr><td>';
  524. print $form->select_company($object->fk_soc, 'socid', '', 1);
  525. print '</td>';
  526. print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  527. print '</tr></table></form>';
  528. } else {
  529. if ($object->fk_soc) {
  530. $company = new Societe($db);
  531. $result = $company->fetch($object->fk_soc);
  532. print $company->getNomUrl(1);
  533. // Show link to invoices
  534. $tmparray = $company->getOutstandingBills('customer');
  535. if (!empty($tmparray['refs'])) {
  536. print ' - '.img_picto($langs->trans("Invoices"), 'bill', 'class="paddingright"').'<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->socid.'">'.$langs->trans("Invoices").' ('.count($tmparray['refs']).')';
  537. // TODO Add alert if warning on at least one invoice late
  538. print '</a>';
  539. }
  540. } else {
  541. print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
  542. }
  543. }
  544. print '</td></tr>';
  545. }
  546. // Login Dolibarr - Link to user
  547. print '<tr><td>';
  548. print '<table class="nobordernopadding" width="100%"><tr><td>';
  549. print $langs->trans("LinkedToDolibarrUser");
  550. print '</td>';
  551. if ($action != 'editlogin' && $user->hasRight('adherent', 'creer')) {
  552. print '<td class="right">';
  553. if ($user->hasRight("user", "user", "creer")) {
  554. print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlogin&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
  555. }
  556. print '</td>';
  557. }
  558. print '</tr></table>';
  559. print '</td><td colspan="2" class="valeur">';
  560. if ($action == 'editlogin') {
  561. $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
  562. } else {
  563. if ($object->user_id) {
  564. $linkeduser = new User($db);
  565. $linkeduser->fetch($object->user_id);
  566. print $linkeduser->getNomUrl(-1);
  567. } else {
  568. print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
  569. }
  570. }
  571. print '</td></tr>';
  572. print "</table>\n";
  573. print "</div></div>\n";
  574. print '<div class="clearboth"></div>';
  575. print dol_get_fiche_end();
  576. /*
  577. * Action bar
  578. */
  579. // Button to create a new subscription if member no draft (-1) neither resiliated (0) neither excluded (-2)
  580. if ($user->hasRight('adherent', 'cotisation', 'creer')) {
  581. if ($action != 'addsubscription' && $action != 'create_thirdparty') {
  582. print '<div class="tabsAction">';
  583. if ($object->statut > 0) {
  584. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription&token='.newToken().'">'.$langs->trans("AddSubscription")."</a></div>";
  585. } else {
  586. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
  587. }
  588. print '</div>';
  589. }
  590. }
  591. /*
  592. * List of subscriptions
  593. */
  594. if ($action != 'addsubscription' && $action != 'create_thirdparty') {
  595. $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
  596. $sql .= " c.rowid as crowid, c.subscription,";
  597. $sql .= " c.datec, c.fk_type as cfk_type,";
  598. $sql .= " c.dateadh as dateh,";
  599. $sql .= " c.datef,";
  600. $sql .= " c.fk_bank,";
  601. $sql .= " b.rowid as bid,";
  602. $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
  603. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
  604. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
  605. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  606. $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".((int) $rowid);
  607. $sql .= $db->order($sortfield, $sortorder);
  608. $result = $db->query($sql);
  609. if ($result) {
  610. $subscriptionstatic = new Subscription($db);
  611. $num = $db->num_rows($result);
  612. print '<table class="noborder centpercent">'."\n";
  613. print '<tr class="liste_titre">';
  614. print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
  615. print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  616. print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  617. print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  618. print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  619. print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  620. if (isModEnabled('banque')) {
  621. print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  622. }
  623. print "</tr>\n";
  624. $accountstatic = new Account($db);
  625. $adh = new Adherent($db);
  626. $adht = new AdherentType($db);
  627. $i = 0;
  628. while ($i < $num) {
  629. $objp = $db->fetch_object($result);
  630. $adh->id = $objp->rowid;
  631. $adh->typeid = $objp->type;
  632. $subscriptionstatic->ref = $objp->crowid;
  633. $subscriptionstatic->id = $objp->crowid;
  634. $typeid = $objp->cfk_type;
  635. if ($typeid > 0) {
  636. $adht->fetch($typeid);
  637. }
  638. print '<tr class="oddeven">';
  639. print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
  640. print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
  641. print '<td class="center">';
  642. if ($typeid > 0) {
  643. print $adht->getNomUrl(1);
  644. }
  645. print '</td>';
  646. print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
  647. print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
  648. print '<td class="right">'.price($objp->subscription).'</td>';
  649. if (isModEnabled('banque')) {
  650. print '<td class="right">';
  651. if ($objp->bid) {
  652. $accountstatic->label = $objp->label;
  653. $accountstatic->id = $objp->baid;
  654. $accountstatic->number = $objp->number;
  655. $accountstatic->account_number = $objp->account_number;
  656. $accountstatic->currency_code = $objp->currency_code;
  657. if (isModEnabled('accounting') && $objp->fk_accountancy_journal > 0) {
  658. $accountingjournal = new AccountingJournal($db);
  659. $accountingjournal->fetch($objp->fk_accountancy_journal);
  660. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  661. }
  662. $accountstatic->ref = $objp->ref;
  663. print $accountstatic->getNomUrl(1);
  664. } else {
  665. print '&nbsp;';
  666. }
  667. print '</td>';
  668. }
  669. print "</tr>";
  670. $i++;
  671. }
  672. if (empty($num)) {
  673. $colspan = 6;
  674. if (isModEnabled('banque')) {
  675. $colspan++;
  676. }
  677. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  678. }
  679. print "</table>";
  680. } else {
  681. dol_print_error($db);
  682. }
  683. }
  684. if (($action != 'addsubscription' && $action != 'create_thirdparty')) {
  685. // Shon online payment link
  686. $useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
  687. if ($useonlinepayment) {
  688. print '<br>';
  689. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  690. print showOnlinePaymentUrl('membersubscription', $object->ref);
  691. print '<br>';
  692. }
  693. }
  694. /*
  695. * Add new subscription form
  696. */
  697. if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->hasRight('adherent', 'cotisation', 'creer')) {
  698. print '<br>';
  699. print load_fiche_titre($langs->trans("NewCotisation"));
  700. // Define default choice for complementary actions
  701. $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice
  702. $invoiceonly = 0; // 1 means option by default is invoice only
  703. $bankviainvoice = 0; // 1 means option by default is write to bank via invoice
  704. if (GETPOST('paymentsave')) {
  705. if (GETPOST('paymentsave') == 'bankdirect') {
  706. $bankdirect = 1;
  707. }
  708. if (GETPOST('paymentsave') == 'invoiceonly') {
  709. $invoiceonly = 1;
  710. }
  711. if (GETPOST('paymentsave') == 'bankviainvoice') {
  712. $bankviainvoice = 1;
  713. }
  714. } else {
  715. if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
  716. $bankviainvoice = 1;
  717. } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && isModEnabled('banque')) {
  718. $bankdirect = 1;
  719. } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
  720. $invoiceonly = 1;
  721. }
  722. }
  723. print "\n\n<!-- Form add subscription -->\n";
  724. if ($conf->use_javascript_ajax) {
  725. //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
  726. print "\n".'<script type="text/javascript">';
  727. print '$(document).ready(function () {
  728. $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect || $bankviainvoice) ? 'show()' : 'hide()').';
  729. $("#none, #invoiceonly").click(function() {
  730. $(".bankswitchclass").hide();
  731. $(".bankswitchclass2").hide();
  732. });
  733. $("#bankdirect, #bankviainvoice").click(function() {
  734. $(".bankswitchclass").show();
  735. $(".bankswitchclass2").show();
  736. });
  737. $("#selectoperation").change(function() {
  738. var code = $(this).val();
  739. if (code == "CHQ")
  740. {
  741. $(".fieldrequireddyn").addClass("fieldrequired");
  742. if ($("#fieldchqemetteur").val() == "")
  743. {
  744. $("#fieldchqemetteur").val($("#memberlabel").val());
  745. }
  746. }
  747. else
  748. {
  749. $(".fieldrequireddyn").removeClass("fieldrequired");
  750. }
  751. });
  752. ';
  753. if (GETPOST('paymentsave')) {
  754. print '$("#'.GETPOST('paymentsave', 'aZ09').'").prop("checked", true);';
  755. }
  756. print '});';
  757. print '</script>'."\n";
  758. }
  759. // Confirm create third party
  760. if ($action == 'create_thirdparty') {
  761. $companyalias = '';
  762. $fullname = $object->getFullName($langs);
  763. if ($object->morphy == 'mor') {
  764. $companyname = $object->company;
  765. if (!empty($fullname)) {
  766. $companyalias = $fullname;
  767. }
  768. } else {
  769. $companyname = $fullname;
  770. if (!empty($object->company)) {
  771. $companyalias = $object->company;
  772. }
  773. }
  774. // Create a form array
  775. $formquestion = array(
  776. array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
  777. array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
  778. );
  779. // If customer code was forced to "required", we ask it at creation to avoid error later
  780. if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) {
  781. $tmpcompany = new Societe($db);
  782. $tmpcompany->name = $companyname;
  783. $tmpcompany->get_codeclient($tmpcompany, 0);
  784. $customercode = $tmpcompany->code_client;
  785. $formquestion[] = array(
  786. 'label' => $langs->trans("CustomerCode"),
  787. 'type' => 'text',
  788. 'name' => 'customercode',
  789. 'value' => $customercode,
  790. 'morecss' => 'minwidth300',
  791. 'moreattr' => 'maxlength="128"',
  792. );
  793. }
  794. // @todo Add other extrafields mandatory for thirdparty creation
  795. print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
  796. }
  797. print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  798. print '<input type="hidden" name="token" value="'.newToken().'">';
  799. print '<input type="hidden" name="action" value="subscription">';
  800. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  801. print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
  802. print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
  803. print dol_get_fiche_head('');
  804. print "<table class=\"border\" width=\"100%\">\n";
  805. print '<tbody>';
  806. $today = dol_now();
  807. // Date payment
  808. if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) {
  809. $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
  810. }
  811. print '<tr>';
  812. // Date start subscription
  813. $currentyear = dol_print_date(time(), "%Y");
  814. $currentmonth = dol_print_date(time(), "%m");
  815. print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
  816. if (GETPOST('reday')) {
  817. $datefrom = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  818. }
  819. if (!$datefrom) {
  820. $datefrom = $object->datevalid;
  821. if ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > dol_now()) {
  822. $datefrom = dol_time_plus_duree($object->datefin, 1, 'd');
  823. } else {
  824. $datefrom = dol_get_first_day($currentyear);
  825. }
  826. }
  827. print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
  828. print "</td></tr>";
  829. // Date end subscription
  830. if (GETPOST('endday')) {
  831. $dateto = dol_mktime(0, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
  832. }
  833. if (!$dateto) {
  834. if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) {
  835. $dateto = dol_get_last_day($currentyear, $currentmonth);
  836. } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) {
  837. $dateto = dol_get_last_day($currentyear);
  838. } else {
  839. $dateto = -1; // By default, no date is suggested
  840. }
  841. }
  842. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
  843. print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
  844. print "</td></tr>";
  845. if ($adht->subscription) {
  846. // Amount
  847. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="subscription" size="6" value="'. price(GETPOSTISSET('subscription') ? GETPOST('subscription') : $adht->amount).'"> '.$langs->trans("Currency".$conf->currency) .'</td></tr>';
  848. // Label
  849. print '<tr><td>'.$langs->trans("Label").'</td>';
  850. print '<td><input name="label" type="text" size="32" value="';
  851. if (empty($conf->global->MEMBER_NO_DEFAULT_LABEL)) {
  852. print $langs->trans("Subscription").' '.dol_print_date(($datefrom ? $datefrom : time()), "%Y");
  853. }
  854. print '"></td></tr>';
  855. // Complementary action
  856. if ((isModEnabled('banque') || isModEnabled('facture')) && empty($conf->global->ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS)) {
  857. $company = new Societe($db);
  858. if ($object->fk_soc) {
  859. $result = $company->fetch($object->fk_soc);
  860. }
  861. // Title payments
  862. //print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
  863. // No more action
  864. print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
  865. print '</td>';
  866. print '<td>';
  867. print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice) ? ' checked' : '').'>';
  868. print '<label for="none"> '.$langs->trans("None").'</label><br>';
  869. // Add entry into bank accoun
  870. if (isModEnabled('banque')) {
  871. print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(!empty($bankdirect) ? ' checked' : '');
  872. print '><label for="bankdirect"> '.$langs->trans("MoreActionBankDirect").'</label><br>';
  873. }
  874. // Add invoice with no payments
  875. if (isModEnabled('societe') && isModEnabled('facture')) {
  876. print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(!empty($invoiceonly) ? ' checked' : '');
  877. //if (empty($object->fk_soc)) print ' disabled';
  878. print '><label for="invoiceonly"> '.$langs->trans("MoreActionInvoiceOnly");
  879. if ($object->fk_soc) {
  880. print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  881. } else {
  882. print ' (';
  883. if (empty($object->fk_soc)) {
  884. print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  885. }
  886. print $langs->trans("NoThirdPartyAssociatedToMember");
  887. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  888. print $langs->trans("CreateDolibarrThirdParty");
  889. print '</a>)';
  890. }
  891. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
  892. print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
  893. }
  894. if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled('product') || isModEnabled('service'))) {
  895. $prodtmp = new Product($db);
  896. $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  897. if ($result < 0) {
  898. setEventMessage($prodtmp->error, 'errors');
  899. }
  900. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  901. }
  902. print '</label><br>';
  903. }
  904. // Add invoice with payments
  905. if (isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
  906. print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(!empty($bankviainvoice) ? ' checked' : '');
  907. //if (empty($object->fk_soc)) print ' disabled';
  908. print '><label for="bankviainvoice"> '.$langs->trans("MoreActionBankViaInvoice");
  909. if ($object->fk_soc) {
  910. print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  911. } else {
  912. print ' (';
  913. if (empty($object->fk_soc)) {
  914. print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  915. }
  916. print $langs->trans("NoThirdPartyAssociatedToMember");
  917. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  918. print $langs->trans("CreateDolibarrThirdParty");
  919. print '</a>)';
  920. }
  921. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
  922. print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
  923. }
  924. if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled('product')|| isModEnabled('service'))) {
  925. $prodtmp = new Product($db);
  926. $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  927. if ($result < 0) {
  928. setEventMessage($prodtmp->error, 'errors');
  929. }
  930. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  931. }
  932. print '</label><br>';
  933. }
  934. print '</td></tr>';
  935. // Bank account
  936. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
  937. print img_picto('', 'bank_account');
  938. $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 2, '', 0, 'minwidth200');
  939. print "</td></tr>\n";
  940. // Payment mode
  941. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  942. print $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2, 1, 0, 0, 1, 'minwidth200', 1);
  943. print "</td></tr>\n";
  944. // Date of payment
  945. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  946. print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1);
  947. print "</td></tr>\n";
  948. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
  949. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  950. print '</td>';
  951. print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(!GETPOST('num_chq') ? '' : GETPOST('num_chq')).'"></td></tr>';
  952. print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
  953. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  954. print '</td>';
  955. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(!GETPOST('chqemetteur') ? '' : GETPOST('chqemetteur')).'"></td></tr>';
  956. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
  957. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  958. print '</td>';
  959. print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(!GETPOST('chqbank') ? '' : GETPOST('chqbank')).'"></td></tr>';
  960. }
  961. }
  962. print '<tr><td></td><td></td></tr>';
  963. print '<tr><td>'.$langs->trans("SendAcknowledgementByMail").'</td>';
  964. print '<td>';
  965. if (!$object->email) {
  966. print $langs->trans("NoEMail");
  967. } else {
  968. $adht = new AdherentType($db);
  969. $adht->fetch($object->typeid);
  970. // Send subscription email
  971. $subject = '';
  972. $msg = '';
  973. // Send subscription email
  974. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  975. $formmail = new FormMail($db);
  976. // Set output language
  977. $outputlangs = new Translate('', $conf);
  978. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  979. // Load traductions files required by page
  980. $outputlangs->loadLangs(array("main", "members"));
  981. // Get email content from template
  982. $arraydefaultmessage = null;
  983. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  984. if (!empty($labeltouse)) {
  985. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  986. }
  987. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  988. $subject = $arraydefaultmessage->topic;
  989. $msg = $arraydefaultmessage->content;
  990. }
  991. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  992. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  993. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  994. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  995. $tmp = '<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha') ? ' checked' : (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? ' checked' : '')).'>';
  996. $helpcontent = '';
  997. $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM').'<br>'."\n";
  998. $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
  999. $helpcontent .= '<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
  1000. if ($subjecttosend) {
  1001. $helpcontent .= $subjecttosend."\n";
  1002. } else {
  1003. $langs->load("errors");
  1004. $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
  1005. }
  1006. $helpcontent .= "<br>";
  1007. $helpcontent .= '<b>'.$langs->trans("MailText").'</b>:<br>';
  1008. if ($texttosend) {
  1009. $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
  1010. } else {
  1011. $langs->load("errors");
  1012. $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
  1013. }
  1014. print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
  1015. }
  1016. print '</td></tr>';
  1017. print '</tbody>';
  1018. print '</table>';
  1019. print dol_get_fiche_end();
  1020. print '<div class="center">';
  1021. $parameters = array();
  1022. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
  1023. if (empty($reshook)) {
  1024. print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
  1025. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1026. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1027. }
  1028. print '</div>';
  1029. print '</form>';
  1030. print "\n<!-- End form subscription -->\n\n";
  1031. }
  1032. //print '</td></tr>';
  1033. //print '</table>';
  1034. } else {
  1035. $langs->load("errors");
  1036. print $langs->trans("ErrorRecordNotFound");
  1037. }
  1038. // End of page
  1039. llxFooter();
  1040. $db->close();