/sql/coa/be/

rtcut icon' href='/favicon.ico'/>
summaryrefslogtreecommitdiff
path: root/LedgerSMB/GL.pm
blob: c6fe103716f3aa0d9f0bb93fb337798c93bdcef5 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. # Copyright (C) 2006
  7. # This work contains copyrighted information from a number of sources all used
  8. # with permission.
  9. #
  10. # This file contains source code included with or based on SQL-Ledger which
  11. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  12. # under the GNU General Public License version 2 or, at your option, any later
  13. # version. For a full list including contact information of contributors,
  14. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  15. #
  16. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  17. # Copyright (C) 2000
  18. #
  19. # Author: DWS Systems Inc.
  20. # Web: http://www.sql-ledger.org
  21. #
  22. # Contributors:
  23. #
  24. #======================================================================
  25. #
  26. # This file has undergone whitespace cleanup.
  27. #
  28. #======================================================================
  29. #
  30. # General ledger backend code
  31. #
  32. #======================================================================
  33. package GL;
  34. sub delete_transaction {
  35. my ($self, $myconfig, $form) = @_;
  36. # connect to database
  37. my $dbh = $form->{dbh};
  38. my %audittrail = (
  39. tablename => 'gl',
  40. reference => $form->{reference},
  41. formname => 'transaction',
  42. action => 'deleted',
  43. id => $form->{id} );
  44. $form->audittrail($dbh, "", \%audittrail);
  45. my $id = $dbh->quote($form->{id});
  46. my $query = qq|DELETE FROM gl WHERE id = $id|;
  47. $dbh->do($query) || $form->dberror($query);
  48. $query = qq|DELETE FROM acc_trans WHERE trans_id = $id|;
  49. $dbh->do($query) || $form->dberror($query);
  50. # commit and redirect
  51. my $rc = $dbh->commit;
  52. $rc;
  53. }
  54. sub post_transaction {
  55. my ($self, $myconfig, $form) = @_;
  56. my $null;
  57. my $project_id;
  58. my $department_id;
  59. my $i;
  60. # connect to database, turn off AutoCommit
  61. my $dbh = $form->{dbh};
  62. my $query;
  63. my $sth;
  64. my $id = $dbh->quote($form->{id});
  65. if ($form->{id}) {
  66. $query = qq|SELECT id FROM gl WHERE id = $id|;
  67. ($form->{id}) = $dbh->selectrow_array($query);
  68. if ($form->{id}) {
  69. # delete individual transactions
  70. $query = qq|
  71. DELETE FROM acc_trans WHERE trans_id = $id|;
  72. $dbh->do($query) || $form->dberror($query);
  73. }
  74. }
  75. if (! $form->{id}) {
  76. my $uid = localtime;
  77. $uid .= "$$";
  78. $query = qq|
  79. INSERT INTO gl (reference, employee_id)
  80. VALUES ('$uid', (SELECT id FROM employee
  81. WHERE login = ?))|;
  82. $sth = $dbh->prepare($query);
  83. $sth->execute($form->{login}) || $form->dberror($query);
  84. $query = qq|
  85. SELECT id
  86. FROM gl
  87. WHERE reference = '$uid'|;
  88. ($form->{id}) = $dbh->selectrow_array($query);
  89. }
  90. ($null, $department_id) = split /--/, $form->{department};
  91. $department_id *= 1;
  92. $form->{reference} = $form->update_defaults(
  93. $myconfig, 'glnumber', $dbh)
  94. unless $form->{reference};
  95. $form->{reference} ||= $form->{id};
  96. $query = qq|
  97. UPDATE gl
  98. SET reference = |.$dbh->quote($form->{reference}).qq|,
  99. description = |.$dbh->quote($form->{description}).qq|,
  100. notes = |.$dbh->quote($form->{notes}).qq|,
  101. transdate = '$form->{transdate}',
  102. department_id = $department_id
  103. WHERE id = $form->{id}|;