subscription.php 46 KB

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