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/Source.pm between version 1.3 and 1.4

version 1.3, 2004/04/04 17:44:16 version 1.4, 2004/04/09 09:17:44
Line 12 
Line 12 
 # 09/02/2004 - created  # 09/02/2004 - created
 #  #
   
 # $Platon: scripts/perl/finance-manager/modules/Source.pm,v 1.1 2004/02/11 10:52:53 rajo Exp $  # $Platon: web-apps/finance-manager/modules/Source.pm,v 1.3 2004/04/04 17:44:16 rajo Exp $
   
 package Source;  package Source;
   
Line 26  use globals;
Line 26  use globals;
 use vars qw($VERSION @ISA @EXPORT $AUTOLOAD);  use vars qw($VERSION @ISA @EXPORT $AUTOLOAD);
   
 @ISA     = qw(Exporter);  @ISA     = qw(Exporter);
 @EXPORT  = qw( list );  @EXPORT  = qw( list get new_source update_source );
 $VERSION = '0.1';  $VERSION = '0.1';
   
 sub new  sub new
Line 37  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 @_;
   
Line 55  sub _prepare_sql($$;)
Line 56  sub _prepare_sql($$;)
                         sourceid, active,                          sourceid, active,
                         name, description, note,                          name, description, note,
                         created, DATE_FORMAT(changed, '%Y-%m-%d %T') AS changed,                          created, DATE_FORMAT(changed, '%Y-%m-%d %T') AS changed,
                           last_transaction,
                         money, start_money, stop_money,                          money, start_money, stop_money,
                         low_money, medium_money, high_money                          low_money, medium_money, high_money
                 FROM Source                  FROM Source
Line 66  sub _prepare_sql($$;)
Line 68  sub _prepare_sql($$;)
                         sourceid, active,                          sourceid, active,
                         name, description, note,                          name, description, note,
                         created, DATE_FORMAT(changed, '%Y-%m-%d %T') AS changed,                          created, DATE_FORMAT(changed, '%Y-%m-%d %T') AS changed,
                           last_transaction,
                         money, start_money, stop_money,                          money, start_money, stop_money,
                         low_money, medium_money, high_money                          low_money, medium_money, high_money
                 FROM Source                  FROM Source
Line 76  sub _prepare_sql($$;)
Line 79  sub _prepare_sql($$;)
         $self->{new_source} = $dbh->prepare(" /* new_source " . __FILE__ . ":" . __LINE__ . " */          $self->{new_source} = $dbh->prepare(" /* new_source " . __FILE__ . ":" . __LINE__ . " */
                 INSERT INTO Source                  INSERT INTO Source
                         (created, active,                          (created, active,
                         start_money, stop_money,                          start_money, stop_money, money,
                         low_money, medium_money, high_money,                          low_money, medium_money, high_money,
                         name, description, note)                          name, description, note)
                 VALUES (NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?) /* 10x otaznik */                  VALUES (NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) /* 10x otaznik */
         ") or croak "Can't create new source: " . $dbh::errstr;          ") or croak "Can't create new source: " . $dbh::errstr;
         foreach my $i (1..6) {          foreach my $i (1..7) {
                 $self->{new_source}->bind_param($i, 0, SQL_INTEGER);                  $self->{new_source}->bind_param($i, 0, SQL_INTEGER);
         }          }
   
           $self->{update_source} = $dbh->prepare(" /* new_source " . __FILE__ . ":" . __LINE__ . " */
                   UPDATE Source SET
                           active = ?,
                           start_money = ?, stop_money = ?, money = ?,
                           low_money = ?, medium_money = ?, high_money = ?,
                           name = ?, description = ?, note = ?
                   WHERE sourceid = ?
           ") or croak "Can't create new source: " . $dbh::errstr;
           foreach my $i (1..7, 11) {
                   $self->{update_source}->bind_param($i, 0, SQL_INTEGER);
           }
   
           $self->{log_source_op} = $dbh->prepare(" /* log_source_op " . __FILE__ . ":" . __LINE__ . " */
                   INSERT INTO SourceLog
                           (created, changed, last_transaction,
                           action_type,
                           sourceid, active,
                           start_money, stop_money, money,
                           low_money, medium_money, high_money,
                           name, description, note)
                   VALUES
                           (NOW(), NOW(), NOW(),
                           ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) /* 12x otaznik */
           ") or croak "Can't create Source log entry: " . $dbh::errstr;
   
 } # }}} _prepare_sql  } # }}} _prepare_sql
   
Line 114  sub get($;)
Line 142  sub get($;)
 sub new_source($;)  sub new_source($;)
 { # {{{  { # {{{
         my ($self, $data) = @_;          my ($self, $data) = @_;
           my $dbh = $self->{__dbh};
   
         foreach my $key ('active', 'start_money', 'stop_money',          foreach my $key ('active', 'start_money', 'stop_money', 'money',
                 'low_money', 'medium_money', 'high_money',                  'low_money', 'medium_money', 'high_money',
                 'name', 'description', 'note') {                  'name', 'description', 'note') {
                 unless (defined $data->{$key}) {                  unless (defined $data->{$key}) {
                         croak "Undefined REQUIRED parameter '$key'";                          croak "Undefined REQUIRED parameter '$key'";
                 }                  }
         }          }
         foreach my $key ('active', 'start_money', 'stop_money',          foreach my $key ('active', 'start_money', 'stop_money', 'money',
                 'low_money', 'medium_money', 'high_money') {                  'low_money', 'medium_money', 'high_money') {
                 if ($data->{$key} !~ m/^\d+$/) {                  if ($data->{$key} !~ m/^\d+$/) {
                         carp "Parameter '$key' ('$data->{$key}') is not numeric";                          carp "Parameter '$key' ('$data->{$key}') is not numeric";
Line 130  sub new_source($;)
Line 159  sub new_source($;)
                 }                  }
         }          }
   
           $dbh->begin_work();
   
         $self->{new_source}->execute(          $self->{new_source}->execute(
                         $data->{active},                          $data->{active},
                         $data->{start_money}, $data->{stop_money},                          $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::Source: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           my $sourceid = $dbh->{'mysql_insertid'};
           $self->{log_source_op}->execute(
                           "added",
                           $sourceid, $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::Source: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           $dbh->commit();
   
           return 1;
   } # }}} get
   
   sub update_source($;)
   { # {{{
           my ($self, $data) = @_;
           my $dbh = $self->{__dbh};
   
           foreach my $key ('active', 'start_money', 'stop_money', 'money',
                   'low_money', 'medium_money', 'high_money',
                   'name', 'description', 'note') {
                   unless (defined $data->{$key}) {
                           croak "Undefined REQUIRED parameter '$key'";
                   }
           }
           foreach my $key ('sourceid', 'active', 'start_money', 'stop_money', 'money',
                   'low_money', 'medium_money', 'high_money') {
                   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->{sourceid});
   
           $self->{log_source_op}->execute(
                           "changed_from",
                           $db_data->{sourceid}, $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::Source: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           $self->{update_source}->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->{sourceid}
           ) or do {
                   carp "ERROR::Source: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           $self->{log_source_op}->execute(
                           "changed_to",
                           $data->{sourceid}, $data->{active},
                           $data->{start_money}, $data->{stop_money}, $data->{money},
                         $data->{low_money}, $data->{medium_money}, $data->{high_money},                          $data->{low_money}, $data->{medium_money}, $data->{high_money},
                         $data->{name}, $data->{description}, $data->{note}                          $data->{name}, $data->{description}, $data->{note}
         );          ) or do {
                   carp "ERROR::Source: " . __FILE__ . ":" . __LINE__ . ": " . $dbh->errstr;
                   $dbh->rollback();
                   return 0;
           };
   
           $dbh->commit();
   
         return 1;          return 1;
 } # }}} get  } # }}} get

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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