build_withdrawal_file.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env php
  2. <?php
  3. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2005-2010 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 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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file scripts/withdrawals/build_withdrawal_file.php
  21. * \ingroup prelevement
  22. * \brief Script de prelevement
  23. */
  24. if (!defined('NOSESSION')) {
  25. define('NOSESSION', '1');
  26. }
  27. $sapi_type = php_sapi_name();
  28. $script_file = basename(__FILE__);
  29. $path = __DIR__.'/';
  30. // Test if batch mode
  31. if (substr($sapi_type, 0, 3) == 'cgi') {
  32. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  33. exit(-1);
  34. }
  35. require_once $path."../../htdocs/master.inc.php";
  36. require_once DOL_DOCUMENT_ROOT."/compta/prelevement/class/bonprelevement.class.php";
  37. require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
  38. require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
  39. require_once DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php";
  40. // Global variables
  41. $version = constant('DOL_VERSION');
  42. $error = 0;
  43. /*
  44. * Main
  45. */
  46. @set_time_limit(0);
  47. print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
  48. dol_syslog($script_file." launched with arg ".join(',', $argv));
  49. $datetimeprev = dol_now();
  50. $month = strftime("%m", $datetimeprev);
  51. $year = strftime("%Y", $datetimeprev);
  52. $user = new user($db);
  53. $user->fetch($conf->global->PRELEVEMENT_USER);
  54. if (!isset($argv[1])) { // Check parameters
  55. print "This script check invoices with a withdrawal request and\n";
  56. print "then create payment and build a withdraw file.\n";
  57. print "Usage: ".$script_file." simu|real\n";
  58. exit(-1);
  59. }
  60. $withdrawreceipt = new BonPrelevement($db);
  61. // $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty
  62. $result = $withdrawreceipt->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $argv[1]);
  63. $db->close();
  64. exit(0);