accountancyaccount.class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/accountancy/class/accountancyaccount.class.php
  19. * \ingroup accounting
  20. * \brief Fichier de la classe des comptes comptables
  21. */
  22. /**
  23. * \class AccountancyAccount
  24. * \brief Classe permettant la gestion des comptes
  25. */
  26. class AccountancyAccount
  27. {
  28. var $db;
  29. var $error;
  30. var $rowid;
  31. var $fk_pcg_version;
  32. var $pcg_type;
  33. var $pcg_subtype;
  34. var $label;
  35. var $account_number;
  36. var $account_parent;
  37. /**
  38. * Constructor
  39. *
  40. * @param DoliDB $db Database handler
  41. */
  42. function __construct($db)
  43. {
  44. $this->db = $db;
  45. }
  46. /**
  47. * Insert account into database
  48. *
  49. * @param User $user User making add
  50. * @return int <0 if KO, Id line added if OK
  51. */
  52. function create($user)
  53. {
  54. $now=dol_now();
  55. $sql = "INSERT INTO ".MAIN_DB_PREFIX."accountingaccount";
  56. $sql.= " (date_creation, fk_user_author, numero,intitule)";
  57. $sql.= " VALUES ('".$this->db->idate($now)."',".$user->id.",'".$this->numero."','".$this->intitule."')";
  58. $resql = $this->db->query($sql);
  59. if ($resql)
  60. {
  61. $id = $this->db->last_insert_id(MAIN_DB_PREFIX."accountingaccount");
  62. if ($id > 0)
  63. {
  64. $this->id = $id;
  65. $result = $this->id;
  66. }
  67. else
  68. {
  69. $result = -2;
  70. $this->error="AccountancyAccount::Create Erreur $result";
  71. dol_syslog($this->error, LOG_ERR);
  72. }
  73. }
  74. else
  75. {
  76. $result = -1;
  77. $this->error="AccountancyAccount::Create Erreur $result";
  78. dol_syslog($this->error, LOG_ERR);
  79. }
  80. return $result;
  81. }
  82. }