subscription.php 46 KB

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