subscription.php 47 KB

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