Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Saturday, October 17, 2026

Diff for web-apps/finance-manager/modules/Event.pm between version 1.1 and 1.2

version 1.1, 2004/02/11 10:52:53 version 1.2, 2004/04/13 06:42:06
Line 12 
Line 12 
 # 09/02/2004 - created  # 09/02/2004 - created
 #  #
   
 # $Platon$  # $Platon: web-apps/finance-manager/modules/Event.pm,v 1.1 2004/02/11 10:52:53 rajo Exp $
   
 package Event;  package Event;
   
Line 20  use strict;
Line 20  use strict;
   
 use Carp;  use Carp;
 use Exporter;  use Exporter;
   use DBI qw(:sql_types);
 use globals;  use globals;
   
 use vars qw($VERSION @ISA @EXPORT $AUTOLOAD);  use vars qw($VERSION @ISA @EXPORT $AUTOLOAD);
Line 36  sub new
Line 37  sub new
     my $self  = {};      my $self  = {};
   
     bless $self, $class;      bless $self, $class;
           $self->{__dbh} = $dbh;
         $self->_prepare_sql($globals, $dbh);          $self->_prepare_sql($globals, $dbh);
     $self->set(@_) if @_;          #$self->set(@_) if @_;
   
     return $self;      return $self;
 } # }}} new  } # }}} new
   
   
   # prepare SQL commands
   sub _prepare_sql($$;)
   { # {{{
   
           my ($self, $globals, $dbh) = @_;
   
           $self->{get_all_events} = $dbh->prepare(" /* get_all_events " . __FILE__ . ":" . __LINE__ . " */
                   SELECT
                           eventid, active,
                           name, description, note,
                           created, DATE_FORMAT(changed, '%Y-%m-%d %T') AS changed,
                           last_transaction, event_type,
                           from_source, to_source,
                           money, period, start_time, stop_time
                   FROM Event
                   ORDER BY eventid
           ") or croak "Can't get list of events: " . $dbh::errstr;
   
           $self->{get_event} = $dbh->prepare(" /* get_event " . __FILE__ . ":" . __LINE__ . " */
                   SELECT
                           eventid, active,
                           name, description, note,
                           created, DATE_FORMAT(changed, '%Y-%m-%d %T') AS changed,
                           last_transaction, event_type,
                           from_source, to_source,
                           money, period, start_time, stop_time
                   FROM Event
                   WHERE eventid = ?
           ") or croak "Can't get event: " . $dbh::errstr;
           $self->{get_event}->bind_param(1, 0, SQL_INTEGER);
   
           $self->{new_event} = $dbh->prepare(" /* new_event " . __FILE__ . ":" . __LINE__ . " */
                   INSERT INTO Event
                           (created, active, event_type, from_source, to_source, money, period,
                           start_time, stop_time, name, description, note)
                   VALUES (NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) /* 11x otaznik */
           ") or croak "Can't create new event: " . $dbh::errstr;
           foreach my $i (1..6) {
                   $self->{new_event}->bind_param($i, 0, SQL_INTEGER);
           }
   
           $self->{update_event} = $dbh->prepare(" /* new_event " . __FILE__ . ":" . __LINE__ . " */
                   UPDATE Event SET
                           active = ?, event_type = ?, from_source = ?, to_source = ?,
                           money = ?, period = ?, start_time = ?, stop_time = ?,
                           name = ?, description = ?, note = ?
                   WHERE eventid = ?
           ") or croak "Can't create new event: " . $dbh::errstr;
           foreach my $i (1..6, 12) {
                   $self->{update_event}->bind_param($i, 0, SQL_INTEGER);
           }
   
           $self->{log_event_op} = $dbh->prepare(" /* log_event_op " . __FILE__ . ":" . __LINE__ . " */
                   INSERT INTO EventLog
                           (action_type,
                           created, changed, last_transaction,
                           eventid, active,
                           event_type, money, from_source, to_source, period,
                           start_time, stop_time,
                           name, description, note)
                   VALUES
                           (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) /* 16x otaznik */
           ") or croak "Can't create Event log entry: " . $dbh::errstr;
   
   } # }}} _prepare_sql
   
   # return list of all finacial events
   sub list()
   { # {{{
           my ($self) = @_;
   
           $self->{get_all_events}->execute();
   
           return $self->{get_all_events}->fetchall_arrayref({});
   
   } # }}} list
   
   # return one event info
   sub get($;)
   { # {{{
           my ($self, $eventid) = @_;
   
           $self->{get_event}->execute($eventid);
           my $event_data = $self->{get_event}->fetchrow_hashref();
           $self->{get_event}->finish();
   
           return $event_data;
   } # }}} get
   
   # create new Event
   sub new_event($;)
   { # {{{
           my ($self, $data) = @_;
           my $dbh = $self->{__dbh};
   
           foreach my $key ('active', 'from_source', 'to_source', 'money', 'period', 'last_transaction', 'event_type',
                   'name', 'description', 'note') {
                   unless (defined $data->{$key}) {
                           croak "Undefined REQUIRED parameter '$key'";
                   }
           }
           foreach my $key ('active', 'from_source', 'to_source', 'money', 'period', 'event_type') {
                   if ($data->{$key} !~ m/^\d+$/) {
                           carp "Parameter '$key' ('$data->{$key}') is not numeric";
                           $data->{$key} = 0;
                   }
           }
   
           $dbh->begin_work();
   
           $self->{new_event}->execute(
                           $data->{active},
                           $data->{event_type}, $data->{from_source}, $data->{to_source}, $data->{money}, $data->{period},
                           $data->{start_time}, $data->{stop_time},
                           $data->{name}, $data->{description}, $data->{note}
           ) or do {
                   carp "ERROR::Event: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           my $eventid = $dbh->{'mysql_insertid'};
           $self->{log_event_op}->execute(
                           "added",
                           undef, undef, undef,
                           $eventid, $data->{active},
                           $data->{event_type}, $data->{money}, $data->{from_source}, $data->{to_source}, $data->{period},
                           $data->{start_time}, $data->{stop_time},
                           $data->{name}, $data->{description}, $data->{note}
           ) or do {
                   carp "ERROR::Event: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           $dbh->commit();
   
           return 1;
   } # }}} get
   
   sub update_event($;)
   { # {{{
           my ($self, $data) = @_;
           my $dbh = $self->{__dbh};
   
           foreach my $key ('eventid', 'active', 'from_source', 'to_source', 'money', 'period','event_type',
                   'last_transaction', 'start_time', 'stop_time',
                   'name', 'description', 'note') {
                   unless (defined $data->{$key}) {
                           croak "Undefined REQUIRED parameter '$key'";
                   }
           }
           foreach my $key ('eventid', 'active', 'from_source', 'to_source', 'money', 'period', 'event_type') {
                   if ($data->{$key} !~ m/^\d+$/) {
                           carp "Parameter '$key' ('$data->{$key}') is not numeric";
                           $data->{$key} = 0;
                   }
           }
   
           $dbh->begin_work();
   
           my $db_data = $self->get($data->{eventid});
   
           $self->{log_event_op}->execute(
                           "changed_from",
                           $db_data->{eventid}, $db_data->{active},
                           $db_data->{start_money}, $db_data->{stop_money}, $db_data->{money},
                           $db_data->{low_money}, $db_data->{medium_money}, $db_data->{high_money},
                           $db_data->{name}, $db_data->{description}, $db_data->{note}
           ) or do {
                   carp "ERROR::Event: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           $self->{update_event}->execute(
                           $data->{active},
                           $data->{start_money}, $data->{stop_money}, $data->{money},
                           $data->{low_money}, $data->{medium_money}, $data->{high_money},
                           $data->{name}, $data->{description}, $data->{note},
                           $data->{eventid}
           ) or do {
                   carp "ERROR::Event: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           $self->{log_event_op}->execute(
                           "changed_to",
                           $data->{eventid}, $data->{active},
                           $data->{start_money}, $data->{stop_money}, $data->{money},
                           $data->{low_money}, $data->{medium_money}, $data->{high_money},
                           $data->{name}, $data->{description}, $data->{note}
           ) or do {
                   carp "ERROR::Event: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           $dbh->commit();
   
           return 1;
   } # }}} get
   
   
   
 1;  1;
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top