card_subscriptions.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/adherents/card_subscriptions.php
  21. * \ingroup member
  22. * \brief Onglet d'ajout, edition, suppression des adhesions d'un adherent
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/adherents/class/cotisation.class.php");
  30. require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
  31. require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
  32. $langs->load("companies");
  33. $langs->load("bills");
  34. $langs->load("members");
  35. $langs->load("users");
  36. $langs->load("mails");
  37. // Security check
  38. if (! $user->rights->adherent->cotisation->lire) accessforbidden();
  39. $adh = new Adherent($db);
  40. $adho = new ExtraFields($db);
  41. $adht = new AdherentType($db);
  42. $errmsg='';
  43. $defaultdelay=1;
  44. $defaultdelayunit='y';
  45. $action=GETPOST('action');
  46. $rowid=GETPOST('rowid');
  47. $typeid=GETPOST('typeid');
  48. if ($rowid)
  49. {
  50. // Load member
  51. $result = $adh->fetch($rowid);
  52. // Define variables to know what current user can do on users
  53. $canadduser=($user->admin || $user->rights->user->user->creer);
  54. // Define variables to know what current user can do on properties of user linked to edited member
  55. if ($adh->user_id)
  56. {
  57. // $user est le user qui edite, $adh->user_id est l'id de l'utilisateur lies au membre edite
  58. $caneditfielduser=( (($user->id == $adh->user_id) && $user->rights->user->self->creer)
  59. || (($user->id != $adh->user_id) && $user->rights->user->user->creer) );
  60. $caneditpassworduser=( (($user->id == $adh->user_id) && $user->rights->user->self->password)
  61. || (($user->id != $adh->user_id) && $user->rights->user->user->password) );
  62. }
  63. }
  64. // Define variables to know what current user can do on members
  65. $canaddmember=$user->rights->adherent->creer;
  66. // Define variables to know what current user can do on properties of a member
  67. if ($rowid)
  68. {
  69. $caneditfieldmember=$user->rights->adherent->creer;
  70. }
  71. /*
  72. * Actions
  73. */
  74. // Create third party from a member
  75. if ($action == 'confirm_create_thirdparty' && $_POST["confirm"] == 'yes' && $user->rights->societe->creer)
  76. {
  77. if ($result > 0)
  78. {
  79. // Creation user
  80. $company = new Societe($db);
  81. $result=$company->create_from_member($adh,$_POST["companyname"]);
  82. if ($result < 0)
  83. {
  84. $langs->load("errors");
  85. $errmsg=$langs->trans($company->error);
  86. $errmsgs=$company->errors;
  87. }
  88. else
  89. {
  90. $action='addsubscription';
  91. }
  92. }
  93. else
  94. {
  95. $errmsg=$adh->error;
  96. }
  97. }
  98. if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
  99. {
  100. $error=0;
  101. if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
  102. {
  103. if ($_POST["userid"] != $user->id && $_POST["userid"] != $adh->user_id)
  104. {
  105. $error++;
  106. $mesg='<div class="error">'.$langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly").'</div>';
  107. }
  108. }
  109. if (! $error)
  110. {
  111. if ($_POST["userid"] != $adh->user_id) // If link differs from currently in database
  112. {
  113. $result=$adh->setUserId($_POST["userid"]);
  114. if ($result < 0) dol_print_error($adh->db,$adh->error);
  115. $_POST['action']='';
  116. $action='';
  117. }
  118. }
  119. }
  120. if ($action == 'setsocid')
  121. {
  122. $error=0;
  123. if (! $error)
  124. {
  125. if (GETPOST("socid") != $adh->fk_soc) // If link differs from currently in database
  126. {
  127. $sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
  128. $sql.=" WHERE fk_soc = '".GETPOST("socid")."'";
  129. $resql = $db->query($sql);
  130. if ($resql)
  131. {
  132. $obj = $db->fetch_object($resql);
  133. if ($obj && $obj->rowid > 0)
  134. {
  135. $othermember=new Adherent($db);
  136. $othermember->fetch($obj->rowid);
  137. $thirdparty=new Societe($db);
  138. $thirdparty->fetch(GETPOST("socid"));
  139. $error++;
  140. $mesg='<div class="error">'.$langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty",$othermember->getFullName($langs),$othermember->login,$thirdparty->nom).'</div>';
  141. }
  142. }
  143. if (! $error)
  144. {
  145. $result=$adh->setThirdPartyId(GETPOST("socid"));
  146. if ($result < 0) dol_print_error($adh->db,$adh->error);
  147. $_POST['action']='';
  148. $action='';
  149. }
  150. }
  151. }
  152. }
  153. if ($user->rights->adherent->cotisation->creer && $action == 'cotisation' && ! $_POST["cancel"])
  154. {
  155. $error=0;
  156. $langs->load("banks");
  157. $result=$adh->fetch($rowid);
  158. $result=$adht->fetch($adh->typeid);
  159. // Subscription informations
  160. $datecotisation=0;
  161. $datesubend=0;
  162. $paymentdate=0;
  163. if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"])
  164. {
  165. $datecotisation=dol_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
  166. }
  167. if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"])
  168. {
  169. $datesubend=dol_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]);
  170. }
  171. if ($_POST["paymentyear"] && $_POST["paymentmonth"] && $_POST["paymentday"])
  172. {
  173. $paymentdate=dol_mktime(0, 0, 0, $_POST["paymentmonth"], $_POST["paymentday"], $_POST["paymentyear"]);
  174. }
  175. $cotisation=$_POST["cotisation"]; // Amount of subscription
  176. $label=$_POST["label"];
  177. // Payment informations
  178. $accountid=$_POST["accountid"];
  179. $operation=$_POST["operation"]; // Payment mode
  180. $num_chq=$_POST["num_chq"];
  181. $emetteur_nom=$_POST["chqemetteur"];
  182. $emetteur_banque=$_POST["chqbank"];
  183. $option=$_POST["paymentsave"];
  184. if (empty($option)) $option='none';
  185. // Check parameters
  186. if (! $datecotisation)
  187. {
  188. $error++;
  189. $errmsg=$langs->trans("BadDateFormat");
  190. $action='addsubscription';
  191. }
  192. if (! $datesubend)
  193. {
  194. $datesubend=dol_time_plus_duree(dol_time_plus_duree($datecotisation,$defaultdelay,$defaultdelayunit),-1,'d');
  195. }
  196. if (($option == 'bankviainvoice' || $option == 'bankdirect') && ! $paymentdate)
  197. {
  198. $error++;
  199. $errmsg=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
  200. $action='addsubscription';
  201. }
  202. // Check if a payment is mandatory or not
  203. if (! $error && $adht->cotisation) // Type adherent soumis a cotisation
  204. {
  205. if (! is_numeric($_POST["cotisation"]))
  206. {
  207. // If field is '' or not a numeric value
  208. $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"));
  209. $error++;
  210. $action='addsubscription';
  211. }
  212. else
  213. {
  214. if ($conf->banque->enabled && $_POST["paymentsave"] != 'none')
  215. {
  216. if ($_POST["cotisation"])
  217. {
  218. if (! $_POST["label"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
  219. if ($_POST["paymentsave"] != 'invoiceonly' && ! $_POST["operation"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode"));
  220. if ($_POST["paymentsave"] != 'invoiceonly' && ! $_POST["accountid"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("FinancialAccount"));
  221. }
  222. else
  223. {
  224. if ($_POST["accountid"]) $errmsg=$langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
  225. }
  226. if ($errmsg) $action='addsubscription';
  227. }
  228. }
  229. }
  230. if (! $error && $action=='cotisation')
  231. {
  232. $db->begin();
  233. // Create subscription
  234. $crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $option);
  235. if ($crowid <= 0)
  236. {
  237. $error++;
  238. $errmsg=$adh->error;
  239. }
  240. if (! $error)
  241. {
  242. // Insert into bank account directlty (if option choosed for) + link to llx_cotisation if option is 'bankdirect'
  243. if ($option == 'bankdirect' && $accountid)
  244. {
  245. require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
  246. $acct=new Account($db);
  247. $result=$acct->fetch($accountid);
  248. $dateop=$paymentdate;
  249. $insertid=$acct->addline($dateop, $operation, $label, $cotisation, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
  250. if ($insertid > 0)
  251. {
  252. $inserturlid=$acct->add_url_line($insertid, $adh->id, DOL_URL_ROOT.'/adherents/fiche.php?rowid=', $adh->getFullname($langs), 'member');
  253. if ($inserturlid > 0)
  254. {
  255. // Met a jour la table cotisation
  256. $sql ="UPDATE ".MAIN_DB_PREFIX."cotisation SET fk_bank=".$insertid;
  257. $sql.=" WHERE rowid=".$crowid;
  258. dol_syslog("Adherent::cotisation sql=".$sql);
  259. $resql = $db->query($sql);
  260. if (! $resql)
  261. {
  262. $error=$db->lasterror();
  263. }
  264. }
  265. else
  266. {
  267. $error=$acct->error;
  268. }
  269. }
  270. else
  271. {
  272. $error=$acct->error;
  273. }
  274. }
  275. // If option choosed, we create invoice
  276. if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly')
  277. {
  278. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  279. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/paymentterm.class.php");
  280. $invoice=new Facture($db);
  281. $customer=new Societe($db);
  282. $result=$customer->fetch($adh->fk_soc);
  283. if ($result <= 0)
  284. {
  285. $errmsg=$customer->error;
  286. $error++;
  287. }
  288. // Create draft invoice
  289. $invoice->type=0;
  290. $invoice->cond_reglement_id=$customer->cond_reglement_id;
  291. if (empty($invoice->cond_reglement_id))
  292. {
  293. $paymenttermstatic=new PaymentTerm($db);
  294. $invoice->cond_reglement_id=$paymenttermstatic->getDefaultId();
  295. if (empty($invoice->cond_reglement_id))
  296. {
  297. $error++;
  298. $errmsg='ErrorNoPaymentTermRECEPFound';
  299. }
  300. }
  301. $invoice->socid=$adh->fk_soc;
  302. $invoice->date=$datecotisation;
  303. $result=$invoice->create($user);
  304. if ($result <= 0)
  305. {
  306. $errmsg=$invoice->error;
  307. $error++;
  308. }
  309. // Add line to draft invoice
  310. $idprodsubscription=0;
  311. $vattouse=get_default_tva($mysoc, $customer, $idprodsubscription);
  312. //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
  313. $result=$invoice->addline($invoice->id,$label,0,1,$vattouse,0,0,$idprodsubscription,0,$datecotisation,$datesubend,0,0,'','TTC',$cotisation,1);
  314. if ($result <= 0)
  315. {
  316. $errmsg=$invoice->error;
  317. $error++;
  318. }
  319. // Validate invoice
  320. $result=$invoice->validate($user);
  321. // Add payment onto invoice
  322. if ($option == 'bankviainvoice' && $accountid)
  323. {
  324. require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php');
  325. require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
  326. require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php');
  327. // Creation de la ligne paiement
  328. $amounts[$invoice->id] = price2num($cotisation);
  329. $paiement = new Paiement($db);
  330. $paiement->datepaye = $paymentdate;
  331. $paiement->amounts = $amounts;
  332. $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement');
  333. $paiement->num_paiement = $num_chq;
  334. $paiement->note = $label;
  335. if (! $error)
  336. {
  337. $paiement_id = $paiement->create($user);
  338. if (! $paiement_id > 0)
  339. {
  340. $errmsg=$paiement->error;
  341. $error++;
  342. }
  343. }
  344. if (! $error)
  345. {
  346. $bank_line_id=$paiement->addPaymentToBank($user,'payment','(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque);
  347. if (! $bank_line_id > 0)
  348. {
  349. $errmsg=$paiement->error;
  350. $error++;
  351. }
  352. // Update fk_bank for subscriptions
  353. $sql = 'UPDATE llx_cotisation set fk_bank='.$bank_line_id;
  354. $sql.= ' WHERE rowid='.$crowid;
  355. dol_syslog('sql='.$sql);
  356. $result = $db->query($sql);
  357. if (! $result)
  358. {
  359. $error++;
  360. }
  361. }
  362. }
  363. }
  364. }
  365. if (! $error)
  366. {
  367. $db->commit();
  368. }
  369. else
  370. {
  371. $db->rollback();
  372. $action = 'addsubscription';
  373. }
  374. // Send email
  375. if (! $error)
  376. {
  377. // Send confirmation Email
  378. if ($adh->email && $_POST["sendmail"])
  379. {
  380. $subjecttosend=$adh->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
  381. $texttosend=$adh->makeSubstitution($adht->getMailOnSubscription());
  382. $result=$adh->send_an_email($texttosend,$subjecttosend,array(),array(),array(),"","",0,-1);
  383. if ($result < 0) $errmsg=$adh->error;
  384. }
  385. $_POST["cotisation"]='';
  386. $_POST["accountid"]='';
  387. $_POST["operation"]='';
  388. $_POST["label"]='';
  389. $_POST["num_chq"]='';
  390. }
  391. }
  392. }
  393. /*
  394. * View
  395. */
  396. $html = new Form($db);
  397. $now=dol_now();
  398. llxHeader('',$langs->trans("Subscriptions"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  399. if ($rowid)
  400. {
  401. $result=$adh->fetch($rowid);
  402. $result=$adh->fetch_optionals($rowid);
  403. $adht->fetch($adh->typeid);
  404. // fetch optionals attributes and labels
  405. $adho->fetch_optionals();
  406. $head = member_prepare_head($adh);
  407. dol_fiche_head($head, 'subscription', $langs->trans("Member"), 0, 'user');
  408. $rowspan=9;
  409. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan+=1;
  410. if ($conf->societe->enabled) $rowspan++;
  411. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  412. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  413. print '<input type="hidden" name="rowid" value="'.$adh->id.'">';
  414. print '<table class="border" width="100%">';
  415. // Ref
  416. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  417. print '<td class="valeur" colspan="2">';
  418. print $html->showrefnav($adh,'rowid');
  419. print '</td></tr>';
  420. $showphoto='<td rowspan="'.$rowspan.'" align="center" valign="middle" width="25%">'.$html->showphoto('memberphoto',$adh).'</td>';
  421. // Login
  422. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  423. {
  424. print '<tr><td>'.$langs->trans("Login").'</td><td class="valeur">'.$adh->login.'&nbsp;</td>';
  425. print $showphoto; $showphoto='';
  426. print '</tr>';
  427. }
  428. // Morphy
  429. print '<tr><td>'.$langs->trans("Nature").'</td><td class="valeur" >'.$adh->getmorphylib().'</td>';
  430. print $showphoto; $showphoto='';
  431. print '</tr>';
  432. // Type
  433. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  434. // Company
  435. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$adh->societe.'</td></tr>';
  436. // Civility
  437. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$adh->getCivilityLabel().'&nbsp;</td>';
  438. print '</tr>';
  439. // Name
  440. print '<tr><td>'.$langs->trans("Lastname").'</td><td class="valeur">'.$adh->lastname.'&nbsp;</td>';
  441. print '</tr>';
  442. // Firstname
  443. print '<tr><td>'.$langs->trans("Firstname").'</td><td class="valeur">'.$adh->firstname.'&nbsp;</td>';
  444. print '</tr>';
  445. // Status
  446. print '<tr><td>'.$langs->trans("Status").'</td><td class="valeur">'.$adh->getLibStatut(4).'</td></tr>';
  447. // Date end subscription
  448. print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
  449. if ($adh->datefin)
  450. {
  451. print dol_print_date($adh->datefin,'day');
  452. if ($adh->datefin < ($now - $conf->adherent->cotisation->warning_delay) && $adh->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
  453. }
  454. else
  455. {
  456. print $langs->trans("SubscriptionNotReceived");
  457. if ($adh->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
  458. }
  459. print '</td></tr>';
  460. // Third party Dolibarr
  461. if ($conf->societe->enabled)
  462. {
  463. print '<tr><td>';
  464. print '<table class="nobordernopadding" width="100%"><tr><td>';
  465. print $langs->trans("LinkedToDolibarrThirdParty");
  466. print '</td>';
  467. if ($_GET['action'] != 'editthirdparty' && $user->rights->adherent->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&amp;rowid='.$adh->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'),1).'</a></td>';
  468. print '</tr></table>';
  469. print '</td><td class="valeur">';
  470. if ($_GET['action'] == 'editthirdparty')
  471. {
  472. $htmlname='socid';
  473. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
  474. print '<input type="hidden" name="rowid" value="'.$adh->id.'">';
  475. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  476. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  477. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  478. print '<tr><td>';
  479. print $html->select_societes($adh->fk_soc,'socid','',1);
  480. print '</td>';
  481. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  482. print '</tr></table></form>';
  483. }
  484. else
  485. {
  486. if ($adh->fk_soc)
  487. {
  488. $company=new Societe($db);
  489. $result=$company->fetch($adh->fk_soc);
  490. print $company->getNomUrl(1);
  491. }
  492. else
  493. {
  494. print $langs->trans("NoThirdPartyAssociatedToMember");
  495. }
  496. }
  497. print '</td></tr>';
  498. }
  499. // Login Dolibarr
  500. print '<tr><td>';
  501. print '<table class="nobordernopadding" width="100%"><tr><td>';
  502. print $langs->trans("LinkedToDolibarrUser");
  503. print '</td>';
  504. if ($_GET['action'] != 'editlogin' && $user->rights->adherent->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlogin&amp;rowid='.$adh->id.'">'.img_edit($langs->trans('SetLinkToUser'),1).'</a></td>';
  505. print '</tr></table>';
  506. print '</td><td class="valeur">';
  507. if ($_GET['action'] == 'editlogin')
  508. {
  509. /*$include=array();
  510. if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
  511. {
  512. $include=array($adh->user_id,$user->id);
  513. }*/
  514. print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'userid','');
  515. }
  516. else
  517. {
  518. if ($adh->user_id)
  519. {
  520. print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'none');
  521. }
  522. else print $langs->trans("NoDolibarrAccess");
  523. }
  524. print '</td></tr>';
  525. print "</table>\n";
  526. print '</form>';
  527. dol_fiche_end();
  528. dol_htmloutput_errors($errmsg,$errmsgs);
  529. /*
  530. * Barre d'actions
  531. */
  532. // Lien nouvelle cotisation si non brouillon et non resilie
  533. if ($user->rights->adherent->cotisation->creer)
  534. {
  535. if ($action != 'addsubscription' && $action != 'create_thirdparty')
  536. {
  537. print '<div class="tabsAction">';
  538. if ($adh->statut > 0) print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription">'.$langs->trans("AddSubscription")."</a>";
  539. else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a>';
  540. print "<br>\n";
  541. print '</div>';
  542. print '<br>';
  543. }
  544. }
  545. /*
  546. * List of subscriptions
  547. */
  548. if ($action != 'addsubscription' && $action != 'create_thirdparty')
  549. {
  550. $sql = "SELECT d.rowid, d.prenom, d.nom, d.societe,";
  551. $sql.= " c.rowid as crowid, c.cotisation,";
  552. $sql.= " c.dateadh,";
  553. $sql.= " c.datef,";
  554. $sql.= " c.fk_bank,";
  555. $sql.= " b.rowid as bid,";
  556. $sql.= " ba.rowid as baid, ba.label, ba.bank";
  557. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."cotisation as c";
  558. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
  559. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  560. $sql.= " WHERE d.rowid = c.fk_adherent AND d.rowid=".$rowid;
  561. $result = $db->query($sql);
  562. if ($result)
  563. {
  564. $cotisationstatic=new Cotisation($db);
  565. $accountstatic=new Account($db);
  566. $num = $db->num_rows($result);
  567. $i = 0;
  568. print "<table class=\"noborder\" width=\"100%\">\n";
  569. print '<tr class="liste_titre">';
  570. print '<td>'.$langs->trans("Ref").'</td>';
  571. print '<td align="center">'.$langs->trans("DateSubscription").'</td>';
  572. print '<td align="center">'.$langs->trans("DateEnd").'</td>';
  573. print '<td align="right">'.$langs->trans("Amount").'</td>';
  574. if ($conf->banque->enabled)
  575. {
  576. print '<td align="right">'.$langs->trans("Account").'</td>';
  577. }
  578. print "</tr>\n";
  579. $var=True;
  580. while ($i < $num)
  581. {
  582. $objp = $db->fetch_object($result);
  583. $var=!$var;
  584. print "<tr $bc[$var]>";
  585. $cotisationstatic->ref=$objp->crowid;
  586. $cotisationstatic->id=$objp->crowid;
  587. print '<td>'.$cotisationstatic->getNomUrl(1).'</td>';
  588. print '<td align="center">'.dol_print_date($db->jdate($objp->dateadh),'day')."</td>\n";
  589. print '<td align="center">'.dol_print_date($db->jdate($objp->datef),'day')."</td>\n";
  590. print '<td align="right">'.price($objp->cotisation).'</td>';
  591. if ($conf->banque->enabled)
  592. {
  593. print '<td align="right">';
  594. if ($objp->bid)
  595. {
  596. $accountstatic->label=$objp->label;
  597. $accountstatic->id=$objp->baid;
  598. print $accountstatic->getNomUrl(1);
  599. }
  600. else
  601. {
  602. print '&nbsp;';
  603. }
  604. print '</td>';
  605. }
  606. print "</tr>";
  607. $i++;
  608. }
  609. print "</table>";
  610. }
  611. else
  612. {
  613. dol_print_error($db);
  614. }
  615. }
  616. /*
  617. * Add new subscription form
  618. */
  619. if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->rights->adherent->cotisation->creer)
  620. {
  621. print '<br>';
  622. print_fiche_titre($langs->trans("NewCotisation"));
  623. $bankdirect=0; // Option to write to bank is on by default
  624. $bankviainvoice=0; // Option to write via invoice is on by default
  625. $invoiceonly=0;
  626. if ($conf->banque->enabled && $conf->global->ADHERENT_BANK_USE && (empty($_POST['paymentsave']) || $_POST["paymentsave"] == 'bankdirect')) $bankdirect=1;
  627. if ($conf->banque->enabled && $conf->societe->enabled && $conf->facture->enabled && $adh->fk_soc) $bankviainvoice=1;
  628. print "\n\n<!-- Form add subscription -->\n";
  629. if ($conf->use_javascript_ajax)
  630. {
  631. print "\n".'<script type="text/javascript" language="javascript">';
  632. print 'jQuery(document).ready(function () {
  633. jQuery(".bankswitchclass").'.($bankdirect||$bankviainvoice||in_array(GETPOST('paymentsave'),array('bankdirect','bankviainvoice'))?'show()':'hide()').';
  634. jQuery(".bankswitchclass2").'.($bankdirect||$bankviainvoice||in_array(GETPOST('paymentsave'),array('bankdirect','bankviainvoice'))?'show()':'hide()').';
  635. jQuery("#none").click(function() {
  636. jQuery(".bankswitchclass").hide();
  637. jQuery(".bankswitchclass2").hide();
  638. });
  639. jQuery("#bankdirect").click(function() {
  640. jQuery(".bankswitchclass").show();
  641. jQuery(".bankswitchclass2").show();
  642. });
  643. jQuery("#bankviainvoice").click(function() {
  644. jQuery(".bankswitchclass").show();
  645. jQuery(".bankswitchclass2").show();
  646. });
  647. jQuery("#invoiceonly").click(function() {
  648. jQuery(".bankswitchclass").hide();
  649. jQuery(".bankswitchclass2").hide();
  650. });
  651. jQuery("#selectoperation").change(function() {
  652. code=jQuery("#selectoperation option:selected").val();
  653. if (code == \'CHQ\')
  654. {
  655. jQuery(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
  656. if (jQuery(\'#fieldchqemetteur\').val() == \'\')
  657. {
  658. jQuery(\'#fieldchqemetteur\').val(jQuery(\'#memberlabel\').val());
  659. }
  660. }
  661. else
  662. {
  663. jQuery(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
  664. }
  665. });
  666. ';
  667. if (GETPOST('paymentsave')) print 'jQuery("#'.GETPOST('paymentsave').'").attr(\'checked\',true);';
  668. print '});';
  669. print '</script>'."\n";
  670. }
  671. // Confirm create third party
  672. if ($_GET["action"] == 'create_thirdparty')
  673. {
  674. $name = $adh->getFullName($langs);
  675. if (! empty($name))
  676. {
  677. if ($adh->societe) $name.=' ('.$adh->societe.')';
  678. }
  679. else
  680. {
  681. $name=$adh->societe;
  682. }
  683. // Create a form array
  684. $formquestion=array(
  685. array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $name));
  686. $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?rowid=".$adh->id,$langs->trans("CreateDolibarrThirdParty"),$langs->trans("ConfirmCreateThirdParty"),"confirm_create_thirdparty",$formquestion,1);
  687. if ($ret == 'html') print '<br>';
  688. }
  689. print '<form name="cotisation" method="post" action="'.$_SERVER["PHP_SELF"].'">';
  690. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  691. print '<input type="hidden" name="action" value="cotisation">';
  692. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  693. print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($adh->getFullName($langs)).'">';
  694. print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($company->name).'">';
  695. print "<table class=\"border\" width=\"100%\">\n";
  696. $today=mktime();
  697. $datefrom=0;
  698. $dateto=0;
  699. $paymentdate=-1;
  700. // Date payment
  701. if ($_POST["paymentyear"] && $_POST["paymentmonth"] && $_POST["paymentday"])
  702. {
  703. $paymentdate=dol_mktime(0, 0, 0, $_POST["paymentmonth"], $_POST["paymentday"], $_POST["paymentyear"]);
  704. }
  705. // Date start subscription
  706. print '<tr><td width="30%" class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
  707. if ($_POST["reday"])
  708. {
  709. $datefrom=dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
  710. }
  711. if (! $datefrom)
  712. {
  713. if ($adh->datefin > 0)
  714. {
  715. $datefrom=dol_time_plus_duree($adh->datefin,1,'d');
  716. }
  717. else
  718. {
  719. $datefrom=mktime();
  720. }
  721. }
  722. $html->select_date($datefrom,'','','','',"cotisation");
  723. print "</td></tr>";
  724. // Date end subscription
  725. if ($_POST["endday"])
  726. {
  727. $dateto=dol_mktime(0,0,0,$_POST["endmonth"],$_POST["endday"],$_POST["endyear"]);
  728. }
  729. if (! $dateto)
  730. {
  731. $dateto=-1; // By default, no date is suggested
  732. }
  733. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
  734. $html->select_date($dateto,'end','','','',"cotisation");
  735. print "</td></tr>";
  736. if ($adht->cotisation)
  737. {
  738. // Amount
  739. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="cotisation" size="6" value="'.$_POST["cotisation"].'"> '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
  740. // Label
  741. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
  742. print '<td><input name="label" type="text" size="32" value="'.$langs->trans("Subscription").' ';
  743. print dol_print_date(($datefrom?$datefrom:time()),"%Y").'" ></td></tr>';
  744. // Complementary action
  745. if ($conf->banque->enabled || $conf->facture->enabled)
  746. {
  747. $company=new Societe($db);
  748. if ($adh->fk_soc)
  749. {
  750. $result=$company->fetch($adh->fk_soc);
  751. }
  752. // Title payments
  753. //print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
  754. // Define a way to write payment
  755. print '<tr><td valign="top" class="fieldrequired">'.$langs->trans('MoreActions');
  756. print '</td>';
  757. print '<td>';
  758. print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(!$bankdirect&&!$bankviainvoice?' checked="true"':'').'> '.$langs->trans("None").'<br>';
  759. if ($conf->banque->enabled)
  760. {
  761. print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.($bankdirect?' checked="true"':'');
  762. print '> '.$langs->trans("MoreActionBankDirect").'<br>';
  763. }
  764. if ($conf->banque->enabled && $conf->societe->enabled && $conf->facture->enabled)
  765. {
  766. print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.($bankviainvoice?' checked="true"':'');
  767. if (empty($adh->fk_soc) || empty($bankviainvoice)) print ' disabled="true"';
  768. print '> '.$langs->trans("MoreActionBankViaInvoice");
  769. if ($adh->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  770. else
  771. {
  772. print ' ('.$langs->trans("NoThirdPartyAssociatedToMember");
  773. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$adh->id.'&amp;action=create_thirdparty">';
  774. print $langs->trans("CreateDolibarrThirdParty");
  775. print '</a>)';
  776. }
  777. print '<br>';
  778. }
  779. if ($conf->societe->enabled && $conf->facture->enabled)
  780. {
  781. print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.($invoiceonly?' checked="true"':'');
  782. if (empty($adh->fk_soc) || empty($bankviainvoice)) print ' disabled="true"';
  783. print '> '.$langs->trans("MoreActionInvoiceOnly");
  784. if ($adh->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  785. else
  786. {
  787. print ' ('.$langs->trans("NoThirdPartyAssociatedToMember");
  788. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$adh->id.'&amp;action=create_thirdparty">';
  789. print $langs->trans("CreateDolibarrThirdParty");
  790. print '</a>)';
  791. }
  792. print '<br>';
  793. }
  794. print '</td></tr>';
  795. // Bank account
  796. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
  797. $html->select_comptes($_POST["accountid"],'accountid',0,'',1);
  798. print "</td></tr>\n";
  799. // Payment mode
  800. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  801. $html->select_types_paiements($_POST["operation"],'operation','',2);
  802. print "</td></tr>\n";
  803. // Date of payment
  804. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  805. $html->select_date($paymentdate?$paymentdate:-1,'payment',0,0,1,'cotisation',1,1);
  806. print "</td></tr>\n";
  807. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
  808. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  809. print '</td>';
  810. print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(empty($_POST['num_chq'])?'':$_POST['num_chq']).'"></td></tr>';
  811. print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
  812. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  813. print '</td>';
  814. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(empty($_POST['chqemetteur'])?$facture->client->nom:$_POST['chqemetteur']).'"></td></tr>';
  815. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
  816. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  817. print '</td>';
  818. print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(empty($_POST['chqbank'])?'':$_POST['chqbank']).'"></td></tr>';
  819. }
  820. }
  821. print '<tr><td colspan="2">&nbsp;</td>';
  822. print '<tr><td width="30%">'.$langs->trans("SendAcknowledgementByMail").'</td>';
  823. print '<td>';
  824. if (! $adh->email)
  825. {
  826. print $langs->trans("NoEMail");
  827. }
  828. else
  829. {
  830. $adht = new AdherentType($db);
  831. $adht->fetch($adh->typeid);
  832. $subjecttosend=$adh->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
  833. $texttosend=$adh->makeSubstitution($adht->getMailOnSubscription());
  834. $tmp='<input name="sendmail" type="checkbox"'.($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL?' checked="true"':'').'>';
  835. $helpcontent='';
  836. $helpcontent.='<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
  837. $helpcontent.='<b>'.$langs->trans("MailRecipient").'</b>: '.$adh->email.'<br>'."\n";
  838. $helpcontent.='<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
  839. $helpcontent.=$subjecttosend."\n";
  840. $helpcontent.="<br>";
  841. $helpcontent.='<b>'.$langs->trans("Content").'</b>:<br>';
  842. $helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
  843. print $html->textwithpicto($tmp,$helpcontent,1,'help');
  844. }
  845. print '</td></tr>';
  846. print '</table>';
  847. print '<br>';
  848. print '<center>';
  849. print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
  850. print ' &nbsp; &nbsp; ';
  851. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  852. print '</center>';
  853. print '</form>';
  854. print "\n<!-- End form subscription -->\n\n";
  855. }
  856. //print '</td></tr>';
  857. //print '</table>';
  858. }
  859. else
  860. {
  861. $langs->load("errors");
  862. print $langs->trans("ErrorRecordNotFound");
  863. }
  864. $db->close();
  865. llxFooter();
  866. ?>