calcmens.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /* TVI
  3. * Copyright (C) 2015 Florian HENRY <florian.henry@open-concept.pro>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. /**
  20. * \file tvi/ajax/list.php
  21. * \brief File to return datables output
  22. */
  23. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal
  24. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
  25. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
  26. require '../main.inc.php';
  27. require DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
  28. $mens=GETPOST('mens');
  29. $capital=GETPOST('capital');
  30. $rate=GETPOST('rate');
  31. $echance=GETPOST('echeance');
  32. $nbterm=GETPOST('nbterm');
  33. top_httphead();
  34. $output=array();
  35. $object = new LoanSchedule($db);
  36. $int = ($capital*($rate/12));
  37. $int = round($int,2,PHP_ROUND_HALF_UP);
  38. $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP);
  39. $output[$echance]=array('cap_rest'=>$cap_rest,'cap_rest_str'=>price($cap_rest),'interet'=>$int,'interet_str'=>price($int,0,'',1),'mens'=>$mens);
  40. $echance++;
  41. $capital=$cap_rest;
  42. while ($echance<=$nbterm) {
  43. $mens = round($object->calcMonthlyPayments($capital, $rate, $nbterm-$echance+1), 2, PHP_ROUND_HALF_UP);
  44. $int = ($capital*($rate/12));
  45. $int = round($int,2,PHP_ROUND_HALF_UP);
  46. $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP);
  47. $output[$echance]=array('cap_rest'=>$cap_rest,'cap_rest_str'=>price($cap_rest),'interet'=>$int,'interet_str'=>price($int,0,'',1),'mens'=>$mens);
  48. $capital=$cap_rest;
  49. $echance++;
  50. }
  51. echo json_encode($output);