subscription.php 46 KB

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