PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/public/paybox/newpayment.php

https://bitbucket.org/speedealing/speedealing
PHP | 781 lines | 575 code | 108 blank | 98 comment | 112 complexity | 71440f0199caadd7ae23c5fdeb59fdb3 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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/public/paybox/newpayment.php
  21. * \ingroup paybox
  22. * \brief File to offer a way to make a payment for a particular Dolibarr entity
  23. * \author Laurent Destailleur
  24. */
  25. define("NOLOGIN",1); // This means this output page does not require to be logged.
  26. define("NOCSRFCHECK",1); // We accept to go on this page from external web site.
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/paybox/lib/paybox.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  32. // Security check
  33. if (empty($conf->paybox->enabled)) accessforbidden('',1,1,1);
  34. $langs->load("main");
  35. $langs->load("other");
  36. $langs->load("dict");
  37. $langs->load("bills");
  38. $langs->load("companies");
  39. $langs->load("errors");
  40. $langs->load("paybox");
  41. // Input are:
  42. // type ('invoice','order','contractline'),
  43. // id (object id),
  44. // amount (required if id is empty),
  45. // tag (a free text, required if type is empty)
  46. // currency (iso code)
  47. $suffix=GETPOST("suffix",'alpha');
  48. $amount=price2num(GETPOST("amount"));
  49. if (! GETPOST("currency",'alpha')) $currency=$conf->currency;
  50. else $currency=GETPOST("currency",'alpha');
  51. if (! GETPOST("action"))
  52. {
  53. if (! GETPOST("amount") && ! GETPOST("source"))
  54. {
  55. dol_print_error('',$langs->trans('ErrorBadParameters')." - amount or source");
  56. exit;
  57. }
  58. if (is_numeric($amount) && ! GETPOST("tag") && ! GETPOST("source"))
  59. {
  60. dol_print_error('',$langs->trans('ErrorBadParameters')." - tag or source");
  61. exit;
  62. }
  63. if (GETPOST("source") && ! GETPOST("ref"))
  64. {
  65. dol_print_error('',$langs->trans('ErrorBadParameters')." - ref");
  66. exit;
  67. }
  68. }
  69. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  70. $urlok=$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/paymentok.php?';
  71. $urlko=$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/paymentko.php?';
  72. // Complete urls
  73. $SOURCE=GETPOST("source",'alpha');
  74. $ref=$REF=GETPOST('ref','alpha');
  75. $TAG=GETPOST("tag",'alpha');
  76. $FULLTAG=GETPOST("fulltag",'alpha'); // fulltag is tag with more informations
  77. $SECUREKEY=GETPOST("securekey"); // Secure key
  78. if (! empty($SOURCE))
  79. {
  80. $urlok.='source='.urlencode($SOURCE).'&';
  81. $urlko.='source='.urlencode($SOURCE).'&';
  82. }
  83. if (! empty($REF))
  84. {
  85. $urlok.='ref='.urlencode($REF).'&';
  86. $urlko.='ref='.urlencode($REF).'&';
  87. }
  88. if (!empty($TAG))
  89. {
  90. $urlok.='tag='.urlencode($TAG).'&';
  91. $urlko.='tag='.urlencode($TAG).'&';
  92. }
  93. if (!empty($FULLTAG))
  94. {
  95. $urlok.='fulltag='.urlencode($FULLTAG).'&';
  96. $urlko.='fulltag='.urlencode($FULLTAG).'&';
  97. }
  98. $urlok=preg_replace('/&$/','',$urlok); // Remove last &
  99. $urlko=preg_replace('/&$/','',$urlko); // Remove last &
  100. // Check security token
  101. $valid=true;
  102. /*
  103. * Actions
  104. */
  105. if (GETPOST("action") == 'dopayment')
  106. {
  107. $PRICE=price2num(GETPOST("newamount"),'MT');
  108. $email=GETPOST("email");
  109. $mesg='';
  110. if (empty($PRICE) || ! is_numeric($PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount"));
  111. elseif (empty($email)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail"));
  112. elseif (! isValidEMail($email)) $mesg=$langs->trans("ErrorBadEMail",$email);
  113. elseif (empty($FULLTAG)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode"));
  114. elseif (dol_strlen($urlok) > 150) $mesg='Error urlok too long '.$urlok;
  115. elseif (dol_strlen($urlko) > 150) $mesg='Error urlko too long '.$urlko;
  116. if (empty($mesg))
  117. {
  118. dol_syslog("newpayment.php call paybox api and do redirect", LOG_DEBUG);
  119. print_paybox_redirect($PRICE, $conf->currency, $email, $urlok, $urlko, $FULLTAG);
  120. session_destroy();
  121. exit;
  122. }
  123. }
  124. /*
  125. * View
  126. */
  127. llxHeaderPayBox($langs->trans("PaymentForm"));
  128. // Common variables
  129. $creditor=$mysoc->name;
  130. $paramcreditor='PAYBOX_CREDITOR_'.$suffix;
  131. if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor;
  132. else if (! empty($conf->global->PAYBOX_CREDITOR)) $creditor=$conf->global->PAYBOX_CREDITOR;
  133. print '<span id="dolpaymentspan"></span>'."\n";
  134. print '<center>';
  135. print '<form id="dolpaymentform" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  136. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  137. print '<input type="hidden" name="action" value="dopayment">';
  138. print '<input type="hidden" name="tag" value="'.GETPOST("tag",'alpha').'">';
  139. print '<input type="hidden" name="suffix" value="'.GETPOST("suffix",'alpha').'">';
  140. print "\n";
  141. print '<!-- Form to send a Paybox payment -->'."\n";
  142. print '<!-- PAYBOX_CREDITOR = '.$conf->global->PAYPAL_CREDITOR.' -->'."\n";
  143. print '<!-- creditor = '.$creditor.' -->'."\n";
  144. print '<!-- urlok = '.$urlok.' -->'."\n";
  145. print '<!-- urlko = '.$urlko.' -->'."\n";
  146. print "\n";
  147. print '<table id="dolpaymenttable" summary="Payment form">'."\n";
  148. // Show logo (search order: logo defined by PAYBOX_LOGO_suffix, then PAYBOX_LOGO, then small company logo, large company logo, theme logo, common logo)
  149. $width=0;
  150. // Define logo and logosmall
  151. $logosmall=$mysoc->logo_small;
  152. $logo=$mysoc->logo;
  153. $paramlogo='PAYBOX_LOGO_'.$suffix;
  154. if (! empty($conf->global->$paramlogo)) $logosmall=$conf->global->$paramlogo;
  155. else if (! empty($conf->global->PAYBOX_LOGO)) $logosmall=$conf->global->PAYBOX_LOGO;
  156. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  157. // Define urllogo
  158. $urllogo='';
  159. if (! empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall))
  160. {
  161. $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('thumbs/'.$logosmall);
  162. }
  163. elseif (! empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo))
  164. {
  165. $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode($logo);
  166. $width=96;
  167. }
  168. // Output html code for logo
  169. if ($urllogo)
  170. {
  171. print '<tr>';
  172. print '<td align="center"><img id="dolpaymentlogo" title="'.$title.'" src="'.$urllogo.'"';
  173. if ($width) print ' width="'.$width.'"';
  174. print '></td>';
  175. print '</tr>'."\n";
  176. }
  177. // Output introduction text
  178. $text='';
  179. if (! empty($conf->global->PAYBOX_NEWFORM_TEXT))
  180. {
  181. $langs->load("members");
  182. if (preg_match('/^\((.*)\)$/',$conf->global->PAYBOX_NEWFORM_TEXT,$reg)) $text.=$langs->trans($reg[1])."<br>\n";
  183. else $text.=$conf->global->PAYBOX_NEWFORM_TEXT."<br>\n";
  184. $text='<tr><td align="center"><br>'.$text.'<br></td></tr>'."\n";
  185. }
  186. if (empty($text))
  187. {
  188. $text.='<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnPaymentPage").'</strong><br></td></tr>'."\n";
  189. $text.='<tr><td class="textpublicpayment"><br>'.$langs->trans("ThisScreenAllowsYouToPay",$creditor).'<br><br></td></tr>'."\n";
  190. }
  191. print $text;
  192. // Output payment summary form
  193. print '<tr><td align="center">';
  194. print '<table with="100%" id="tablepublicpayment">';
  195. print '<tr class="liste_total"><td align="left" colspan="2">'.$langs->trans("ThisIsInformationOnPayment").' :</td></tr>'."\n";
  196. $found=false;
  197. $error=0;
  198. $var=false;
  199. // Free payment
  200. if (! GETPOST("source") && $valid)
  201. {
  202. $found=true;
  203. $tag=GETPOST("tag");
  204. $fulltag=$tag;
  205. // Creditor
  206. $var=!$var;
  207. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
  208. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
  209. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  210. print '</td></tr>'."\n";
  211. // Amount
  212. $var=!$var;
  213. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
  214. if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
  215. print '</td><td class="CTableRow'.($var?'1':'2').'">';
  216. if (empty($amount) || ! is_numeric($amount))
  217. {
  218. print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
  219. print '<input class="flat" size=8 type="text" name="newamount" value="'.GETPOST("newamount","int").'">';
  220. }
  221. else {
  222. print '<b>'.price($amount).'</b>';
  223. print '<input type="hidden" name="amount" value="'.$amount.'">';
  224. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  225. }
  226. // Currency
  227. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  228. print '<input type="hidden" name="currency" value="'.$currency.'">';
  229. print '</td></tr>'."\n";
  230. // Tag
  231. $var=!$var;
  232. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
  233. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
  234. print '<input type="hidden" name="tag" value="'.$tag.'">';
  235. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  236. print '</td></tr>'."\n";
  237. // EMail
  238. $var=!$var;
  239. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("YourEMail");
  240. print ' ('.$langs->trans("ToComplete").')';
  241. print '</td><td class="CTableRow'.($var?'1':'2').'"><input class="flat" type="text" name="email" size="48" value="'.GETPOST("email").'"></td></tr>'."\n";
  242. }
  243. // Payment on customer order
  244. if (GETPOST("source") == 'order' && $valid)
  245. {
  246. $found=true;
  247. $langs->load("orders");
  248. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  249. $order=new Commande($db);
  250. $result=$order->fetch('',$ref);
  251. if ($result < 0)
  252. {
  253. $mesg=$order->error;
  254. $error++;
  255. }
  256. else
  257. {
  258. $result=$order->fetch_thirdparty($order->socid);
  259. }
  260. $amount=$order->total_ttc;
  261. if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
  262. $amount=price2num($amount);
  263. $fulltag='IR='.$order->ref.'.TPID='.$order->thirdparty->id;
  264. //$fulltag.='.TP='.strtr($order->thirdparty->name,"-"," "); We disable this because url that will contains FULLTAG must be lower than 150
  265. if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
  266. $fulltag=dol_string_unaccent($fulltag);
  267. // Creditor
  268. $var=!$var;
  269. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
  270. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
  271. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  272. print '</td></tr>'."\n";
  273. // Debitor
  274. $var=!$var;
  275. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("ThirdParty");
  276. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$order->thirdparty->name.'</b>';
  277. // Object
  278. $var=!$var;
  279. $text='<b>'.$langs->trans("PaymentOrderRef",$order->ref).'</b>';
  280. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Designation");
  281. print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
  282. print '<input type="hidden" name="source" value="'.GETPOST("source",'alpha').'">';
  283. print '<input type="hidden" name="ref" value="'.$order->ref.'">';
  284. print '</td></tr>'."\n";
  285. // Amount
  286. $var=!$var;
  287. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
  288. if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
  289. print '</td><td class="CTableRow'.($var?'1':'2').'">';
  290. if (empty($amount) || ! is_numeric($amount))
  291. {
  292. print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
  293. print '<input class="flat" size=8 type="text" name="newamount" value="'.GETPOST("newamount","int").'">';
  294. }
  295. else {
  296. print '<b>'.price($amount).'</b>';
  297. print '<input type="hidden" name="amount" value="'.$amount.'">';
  298. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  299. }
  300. // Currency
  301. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  302. print '<input type="hidden" name="currency" value="'.$currency.'">';
  303. print '</td></tr>'."\n";
  304. // Tag
  305. $var=!$var;
  306. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
  307. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
  308. print '<input type="hidden" name="tag" value="'.$tag.'">';
  309. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  310. print '</td></tr>'."\n";
  311. // EMail
  312. $var=!$var;
  313. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("YourEMail");
  314. print ' ('.$langs->trans("ToComplete").')';
  315. $email=$order->thirdparty->email;
  316. $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:''));
  317. print '</td><td class="CTableRow'.($var?'1':'2').'"><input class="flat" type="text" name="email" size="48" value="'.$email.'"></td></tr>'."\n";
  318. }
  319. // Payment on customer invoice
  320. if (GETPOST("source") == 'invoice' && $valid)
  321. {
  322. $found=true;
  323. $langs->load("bills");
  324. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  325. $invoice=new Facture($db);
  326. $result=$invoice->fetch('',$ref);
  327. if ($result < 0)
  328. {
  329. $mesg=$invoice->error;
  330. $error++;
  331. }
  332. else
  333. {
  334. $result=$invoice->fetch_thirdparty($invoice->socid);
  335. }
  336. $amount=price2num($invoice->total_ttc - $invoice->getSommePaiement());
  337. if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
  338. $amount=price2num($amount);
  339. $fulltag='IR='.$invoice->ref.'.TPID='.$invoice->thirdparty->id;
  340. //$fulltag.='.TP='.strtr($invoice->thirdparty->name,"-"," "); We disable this because url that will contains FULLTAG must be lower than 150
  341. if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
  342. $fulltag=dol_string_unaccent($fulltag);
  343. // Creditor
  344. $var=!$var;
  345. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
  346. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
  347. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  348. print '</td></tr>'."\n";
  349. // Debitor
  350. $var=!$var;
  351. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("ThirdParty");
  352. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$invoice->thirdparty->name.'</b>';
  353. // Object
  354. $var=!$var;
  355. $text='<b>'.$langs->trans("PaymentInvoiceRef",$invoice->ref).'</b>';
  356. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Designation");
  357. print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
  358. print '<input type="hidden" name="source" value="'.GETPOST("source",'alpha').'">';
  359. print '<input type="hidden" name="ref" value="'.$invoice->ref.'">';
  360. print '</td></tr>'."\n";
  361. // Amount
  362. $var=!$var;
  363. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
  364. if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
  365. print '</td><td class="CTableRow'.($var?'1':'2').'">';
  366. if (empty($amount) || ! is_numeric($amount))
  367. {
  368. print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
  369. print '<input class="flat" size=8 type="text" name="newamount" value="'.GETPOST("newamount","int").'">';
  370. }
  371. else {
  372. print '<b>'.price($amount).'</b>';
  373. print '<input type="hidden" name="amount" value="'.$amount.'">';
  374. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  375. }
  376. // Currency
  377. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  378. print '<input type="hidden" name="currency" value="'.$currency.'">';
  379. print '</td></tr>'."\n";
  380. // Tag
  381. $var=!$var;
  382. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
  383. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
  384. print '<input type="hidden" name="tag" value="'.$tag.'">';
  385. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  386. print '</td></tr>'."\n";
  387. // EMail
  388. $var=!$var;
  389. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("YourEMail");
  390. print ' ('.$langs->trans("ToComplete").')';
  391. $email=$invoice->thirdparty->email;
  392. $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:''));
  393. print '</td><td class="CTableRow'.($var?'1':'2').'"><input class="flat" type="text" name="email" size="48" value="'.$email.'"></td></tr>'."\n";
  394. }
  395. // Payment on contract line
  396. if (GETPOST("source") == 'contractline' && $valid)
  397. {
  398. $found=true;
  399. $langs->load("contracts");
  400. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  401. $contractline=new ContratLigne($db);
  402. $result=$contractline->fetch('',$ref);
  403. if ($result < 0)
  404. {
  405. $mesg=$contractline->error;
  406. $error++;
  407. }
  408. else
  409. {
  410. if ($contractline->fk_contrat > 0)
  411. {
  412. $contract=new Contrat($db);
  413. $result=$contract->fetch($contractline->fk_contrat);
  414. if ($result > 0)
  415. {
  416. $result=$contract->fetch_thirdparty($contract->socid);
  417. }
  418. else
  419. {
  420. $mesg=$contract->error;
  421. $error++;
  422. }
  423. }
  424. else
  425. {
  426. $mesg='ErrorRecordNotFound';
  427. $error++;
  428. }
  429. }
  430. $amount=$contractline->total_ttc;
  431. if ($contractline->fk_product)
  432. {
  433. $product=new Product($db);
  434. $result=$product->fetch($contractline->fk_product);
  435. // We define price for product (TODO Put this in a method in product class)
  436. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  437. {
  438. $pu_ht = $product->multiprices[$contract->thirdparty->price_level];
  439. $pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level];
  440. $price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level];
  441. }
  442. else
  443. {
  444. $pu_ht = $product->price;
  445. $pu_ttc = $product->price_ttc;
  446. $price_base_type = $product->price_base_type;
  447. }
  448. $amount=$pu_ttc;
  449. if (empty($amount))
  450. {
  451. dol_print_error('','ErrorNoPriceDefinedForThisProduct');
  452. exit;
  453. }
  454. }
  455. if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
  456. $amount=price2num($amount);
  457. $fulltag='CLR='.$contractline->ref.'.CR='.$contract->ref.'.TPID='.$contract->thirdparty->id;
  458. //$fulltag.='.TP='.strtr($contract->thirdparty->name,"-"," "); We disable this because url that will contains FULLTAG must be lower than 150
  459. if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
  460. $fulltag=dol_string_unaccent($fulltag);
  461. $qty=1;
  462. if (GETPOST('qty')) $qty=GETPOST('qty');
  463. // Creditor
  464. $var=!$var;
  465. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
  466. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
  467. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  468. print '</td></tr>'."\n";
  469. // Debitor
  470. $var=!$var;
  471. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("ThirdParty");
  472. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$contract->thirdparty->name.'</b>';
  473. // Object
  474. $var=!$var;
  475. $text='<b>'.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).'</b>';
  476. if ($contractline->fk_product)
  477. {
  478. $text.='<br>'.$product->ref.($product->libelle?' - '.$product->libelle:'');
  479. }
  480. if ($contractline->description) $text.='<br>'.dol_htmlentitiesbr($contractline->description);
  481. //if ($contractline->date_fin_validite) {
  482. // $text.='<br>'.$langs->trans("DateEndPlanned").': ';
  483. // $text.=dol_print_date($contractline->date_fin_validite);
  484. //}
  485. if ($contractline->date_fin_validite)
  486. {
  487. $text.='<br>'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_fin_validite);
  488. }
  489. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Designation");
  490. print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
  491. print '<input type="hidden" name="source" value="'.GETPOST("source",'alpha').'">';
  492. print '<input type="hidden" name="ref" value="'.$contractline->ref.'">';
  493. print '</td></tr>'."\n";
  494. // Quantity
  495. $var=!$var;
  496. $label=$langs->trans("Quantity");
  497. $qty=1;
  498. $duration='';
  499. if ($contractline->fk_product)
  500. {
  501. if ($product->isservice() && $product->duration_value > 0)
  502. {
  503. $label=$langs->trans("Duration");
  504. // TODO Put this in a global method
  505. if ($product->duration_value > 1)
  506. {
  507. $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("DurationDays"),"w"=>$langs->trans("DurationWeeks"),"m"=>$langs->trans("DurationMonths"),"y"=>$langs->trans("DurationYears"));
  508. }
  509. else
  510. {
  511. $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("DurationDay"),"w"=>$langs->trans("DurationWeek"),"m"=>$langs->trans("DurationMonth"),"y"=>$langs->trans("DurationYear"));
  512. }
  513. $duration=$product->duration_value.' '.$dur[$product->duration_unit];
  514. }
  515. }
  516. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$label.'</td>';
  517. print '<td class="CTableRow'.($var?'1':'2').'"><b>'.($duration?$duration:$qty).'</b>';
  518. print '<input type="hidden" name="newqty" value="'.dol_escape_htmltag($qty).'">';
  519. print '</b></td></tr>'."\n";
  520. // Amount
  521. $var=!$var;
  522. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
  523. if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
  524. print '</td><td class="CTableRow'.($var?'1':'2').'">';
  525. if (empty($amount) || ! is_numeric($amount))
  526. {
  527. print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
  528. print '<input class="flat" size=8 type="text" name="newamount" value="'.GETPOST("newamount","int").'">';
  529. }
  530. else {
  531. print '<b>'.price($amount).'</b>';
  532. print '<input type="hidden" name="amount" value="'.$amount.'">';
  533. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  534. }
  535. // Currency
  536. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  537. print '<input type="hidden" name="currency" value="'.$currency.'">';
  538. print '</td></tr>'."\n";
  539. // Tag
  540. $var=!$var;
  541. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
  542. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
  543. print '<input type="hidden" name="tag" value="'.$tag.'">';
  544. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  545. print '</td></tr>'."\n";
  546. // EMail
  547. $var=!$var;
  548. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("YourEMail");
  549. print ' ('.$langs->trans("ToComplete").')';
  550. $email=$contract->thirdparty->email;
  551. $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:''));
  552. print '</td><td class="CTableRow'.($var?'1':'2').'"><input class="flat" type="text" name="email" size="48" value="'.$email.'"></td></tr>'."\n";
  553. }
  554. // Payment on member subscription
  555. if (GETPOST("source") == 'membersubscription' && $valid)
  556. {
  557. $found=true;
  558. $langs->load("members");
  559. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  560. require_once DOL_DOCUMENT_ROOT.'/adherents/class/cotisation.class.php';
  561. $member=new Adherent($db);
  562. $result=$member->fetch('',$ref);
  563. if ($result < 0)
  564. {
  565. $mesg=$member->error;
  566. $error++;
  567. }
  568. else
  569. {
  570. $subscription=new Cotisation($db);
  571. }
  572. $amount=$subscription->total_ttc;
  573. if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
  574. $amount=price2num($amount);
  575. $fulltag='MID='.$member->id;
  576. //$fulltag.='.M='.dol_trunc(strtr($member->getFullName($langs),"-"," "),12); We disable this because url that will contains FULLTAG must be lower than 150
  577. if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
  578. $fulltag=dol_string_unaccent($fulltag);
  579. // Creditor
  580. $var=!$var;
  581. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
  582. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
  583. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  584. print '</td></tr>'."\n";
  585. // Debitor
  586. $var=!$var;
  587. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Member");
  588. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>';
  589. if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe;
  590. else print $member->getFullName($langs);
  591. print '</b>';
  592. // Object
  593. $var=!$var;
  594. $text='<b>'.$langs->trans("PaymentSubscription").'</b>';
  595. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Designation");
  596. print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
  597. print '<input type="hidden" name="source" value="'.GETPOST("source",'alpha').'">';
  598. print '<input type="hidden" name="ref" value="'.$member->ref.'">';
  599. print '</td></tr>'."\n";
  600. if ($member->last_subscription_date || $member->last_subscription_amount)
  601. {
  602. // Last subscription date
  603. $var=!$var;
  604. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("LastSubscriptionDate");
  605. print '</td><td class="CTableRow'.($var?'1':'2').'">'.dol_print_date($member->last_subscription_date,'day');
  606. print '</td></tr>'."\n";
  607. // Last subscription amount
  608. $var=!$var;
  609. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("LastSubscriptionAmount");
  610. print '</td><td class="CTableRow'.($var?'1':'2').'">'.price($member->last_subscription_amount);
  611. print '</td></tr>'."\n";
  612. if (empty($amount) && ! GETPOST('newamount')) $_GET['newamount']=$member->last_subscription_amount;
  613. }
  614. // Amount
  615. $var=!$var;
  616. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
  617. if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
  618. print '</td><td class="CTableRow'.($var?'1':'2').'">';
  619. if (empty($amount) || ! is_numeric($amount))
  620. {
  621. $valtoshow=GETPOST("newamount",'int');
  622. if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow);
  623. print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
  624. print '<input class="flat" size="8" type="text" name="newamount" value="'.$valtoshow.'">';
  625. }
  626. else {
  627. $valtoshow=$amount;
  628. if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow);
  629. print '<b>'.price($valtoshow).'</b>';
  630. print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
  631. print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
  632. }
  633. // Currency
  634. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  635. print '<input type="hidden" name="currency" value="'.$currency.'">';
  636. print '</td></tr>'."\n";
  637. // Tag
  638. $var=!$var;
  639. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
  640. print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
  641. print '<input type="hidden" name="tag" value="'.$tag.'">';
  642. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  643. print '</td></tr>'."\n";
  644. // EMail
  645. $var=!$var;
  646. print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("YourEMail");
  647. $email=$member->email;
  648. $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:''));
  649. if (empty($email)) print ' ('.$langs->trans("ToComplete").')';
  650. print '</td><td class="CTableRow'.($var?'1':'2').'"><input class="flat" type="text" name="email" size="48" value="'.$email.'"></td></tr>'."\n";
  651. }
  652. if (! $found && ! $mesg) $mesg=$langs->trans("ErrorBadParameters");
  653. if ($mesg) print '<tr><td align="center" colspan="2"><br><div class="warning">'.$mesg.'</div></td></tr>'."\n";
  654. print '</table>'."\n";
  655. print "\n";
  656. if ($found && ! $error) // We are in a management option and no error
  657. {
  658. print '<br><input class="button" type="submit" name="dopayment" value="'.$langs->trans("PayBoxDoPayment").'">';
  659. //print '<tr><td align="center" colspan="2">'.$langs->trans("YouWillBeRedirectedOnPayBox").'...</td></tr>';
  660. }
  661. else
  662. {
  663. dol_print_error_email();
  664. }
  665. print '</td></tr>'."\n";
  666. print '</table>'."\n";
  667. print '</form>'."\n";
  668. print '</center>'."\n";
  669. print '<br>';
  670. html_print_paybox_footer($mysoc,$langs);
  671. llxFooterPayBox();
  672. $db->close();
  673. ?>