From 70eaf8d6f7ee56713f3b907d7c82d97665482af6 Mon Sep 17 00:00:00 2001 From: Pasqualino Ferrentino Date: Wed, 12 Sep 2007 16:25:10 +0200 Subject: [PATCH] Added the GetCreditReportCommand --- .../GetCreditReportCommand.pm} | 47 ++++++++++++++----- src/lib/Bcd/Data/CreditsAndDebits.pm | 7 ++- src/lib/Bcd/Data/Invoices.pm | 8 ++++ src/script/bcd.pl | 2 +- src/script/db/psql/create-bc-schema | 4 +- src/t/TestCreditsAndDebits.pm | 6 ++- .../lib/breadcrumbs/Controller/CreditsAndDebits.pm | 52 ++++++++++++++++++++++ .../breadcrumbs/lib/breadcrumbs/Controller/User.pm | 2 +- web-site/breadcrumbs/root/src/cad_index.tt | 2 + .../breadcrumbs/t/controller_CreditsAndDebits.t | 10 +++++ 10 files changed, 123 insertions(+), 17 deletions(-) copy src/lib/Bcd/{Data/Invoices.pm => Commands/GetCreditReportCommand.pm} (52%) create mode 100644 web-site/breadcrumbs/lib/breadcrumbs/Controller/CreditsAndDebits.pm create mode 100644 web-site/breadcrumbs/root/src/cad_index.tt create mode 100644 web-site/breadcrumbs/t/controller_CreditsAndDebits.t diff --git a/src/lib/Bcd/Data/Invoices.pm b/src/lib/Bcd/Commands/GetCreditReportCommand.pm similarity index 52% copy from src/lib/Bcd/Data/Invoices.pm copy to src/lib/Bcd/Commands/GetCreditReportCommand.pm index 8b1a4a9..7c8ebd5 100644 --- a/src/lib/Bcd/Data/Invoices.pm +++ b/src/lib/Bcd/Commands/GetCreditReportCommand.pm @@ -1,4 +1,4 @@ -package Bcd::Data::Invoices; +package Bcd::Commands::GetCreditReportCommand; # This file is part of the breadcrumbs daemon (bcd). # Copyright (C) 2007 Pasqualino Ferrentino @@ -23,25 +23,48 @@ package Bcd::Data::Invoices; use strict; use warnings; +use threads; +use threads::shared; + +use Bcd::Commands::SessionCommand; +use base(qq/Bcd::Commands::SessionCommand/); use Data::Dumper; -use Bcd::Constants::InvoicesConstants; +use Bcd::Data::WebSite; +use constant NAME => "cad_get_credit_report"; -sub init_db { - my ($class, $stash) = @_; +sub get_name{ + return NAME; +} - my $conn = $stash->get_connection(); +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); - #ok, now I should insert the values in the table... - my $sth = $conn->prepare(qq{insert into invoices_statuses values(?,?)}); + #no parameters, I have only the session + $self->{"privilege_required"} = Bcd::Data::Users::ANT_ROLE; - foreach (Bcd::Constants::InvoicesConstants::LIST_INVOICES_STATES){ - $sth->bind_param(1, $_->[0]); - $sth->bind_param(2, $_->[1]); - $sth->execute(); - } + bless ($self, $class); + return $self; } +sub _exec{ + my ($self, $stash ) = @_; + + my $my_id = $stash->get_session_id($self->{session_id}); + + + + #I should get the score + my $score = Bcd::Data::CreditsAndDebits->get_net_ant_credit($stash, $my_id); + + $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_OK; +} + +sub _add_your_specific_output{ + my ($self, $output) = @_; + +} 1; diff --git a/src/lib/Bcd/Data/CreditsAndDebits.pm b/src/lib/Bcd/Data/CreditsAndDebits.pm index a79ab77..5242cde 100644 --- a/src/lib/Bcd/Data/CreditsAndDebits.pm +++ b/src/lib/Bcd/Data/CreditsAndDebits.pm @@ -173,8 +173,9 @@ sub get_ant_credit_score{ my ($class, $stash, $id_user) = @_; my $credit = $class->get_ant_credit($stash, $id_user); my $debit = $class->get_ant_debit($stash, $id_user); + my $frozen_debit = $class->get_ant_frozen_credit($stash, $id_user); - return credit_score($credit, $debit); + return credit_score($credit, $debit + $frozen_debit); } sub get_ant_credit_score_if_it_emits_this_cheque{ @@ -182,7 +183,9 @@ sub get_ant_credit_score_if_it_emits_this_cheque{ my $credit = $class->get_ant_credit($stash, $id_user); my $debit = $class->get_ant_debit($stash, $id_user); + my $frozen_debit = $class->get_ant_frozen_credit($stash, $id_user); $debit += $amount_cheque; + $debit += $frozen_debit; return credit_score($credit, $debit); } @@ -191,6 +194,8 @@ sub get_maximum_debt_to_reach_this_rate{ my $total_credit = Bcd::Data::CreditsAndDebits->get_ant_credit($stash, $id_user); my $total_debit = Bcd::Data::CreditsAndDebits->get_ant_debit ($stash, $id_user); + my $frozen_debit = $class->get_ant_frozen_credit($stash, $id_user); + $total_debit += $frozen_debit; #mmm if the total debit and total credit are below the minimum #then I can reach the minimum diff --git a/src/lib/Bcd/Data/Invoices.pm b/src/lib/Bcd/Data/Invoices.pm index 8b1a4a9..0aa9713 100644 --- a/src/lib/Bcd/Data/Invoices.pm +++ b/src/lib/Bcd/Data/Invoices.pm @@ -28,6 +28,14 @@ use Data::Dumper; use Bcd::Constants::InvoicesConstants; +#this function should create a new invoice +sub create_new_invoice{ + my ($class, $stash, $user_to, $ads_id, $quantity) = @_; + + #some other considerations.... +} + + sub init_db { my ($class, $stash) = @_; diff --git a/src/script/bcd.pl b/src/script/bcd.pl index c421e6f..7b0d6ae 100755 --- a/src/script/bcd.pl +++ b/src/script/bcd.pl @@ -43,7 +43,7 @@ use Getopt::Long; use Data::Dumper; use Pod::Usage; use constant { - BCD_VERSION => '0.6', + BCD_VERSION => '0.7', }; $SIG{CHLD} = 'IGNORE'; diff --git a/src/script/db/psql/create-bc-schema b/src/script/db/psql/create-bc-schema index 25e8f17..41aa40a 100644 --- a/src/script/db/psql/create-bc-schema +++ b/src/script/db/psql/create-bc-schema @@ -623,7 +623,9 @@ create table invoices( id_status smallint references invoices_statuses, --every invoice is tied to a particular ad in the system - id_ad integer references ads, + --AND to a particular locus in the system. + id_ad integer references ads, + id_locus integer references users_in_sites, user_to integer references users on delete restrict, date timestamp default(now()), diff --git a/src/t/TestCreditsAndDebits.pm b/src/t/TestCreditsAndDebits.pm index 3b485f8..273e66c 100644 --- a/src/t/TestCreditsAndDebits.pm +++ b/src/t/TestCreditsAndDebits.pm @@ -184,7 +184,11 @@ sub test_get_maximum_cheque{ $self->assert_equals(51240, $max_cheque); #some debit - Bcd::Data::CreditsAndDebits->ant_credits_ant($stash, 19, 16, 27000); + Bcd::Data::CreditsAndDebits->ant_credits_ant($stash, 19, 16, 17000); + + #some frozen debit + my $sql = qq{INSERT INTO frozen_credits VALUES(16, 10000)}; + $stash->prep_exec($sql); $max_cheque = Bcd::Data::CreditsAndDebits->get_maximum_debt_to_reach_this_rate ($stash, 16, R_MAX); diff --git a/web-site/breadcrumbs/lib/breadcrumbs/Controller/CreditsAndDebits.pm b/web-site/breadcrumbs/lib/breadcrumbs/Controller/CreditsAndDebits.pm new file mode 100644 index 0000000..afda712 --- /dev/null +++ b/web-site/breadcrumbs/lib/breadcrumbs/Controller/CreditsAndDebits.pm @@ -0,0 +1,52 @@ +package breadcrumbs::Controller::CreditsAndDebits; + +use strict; +use warnings; +use breadcrumbs::Controller::BcController; +use base 'breadcrumbs::Controller::BcController'; +use NEXT; + +sub new { + my $class = shift; + my $self = $class->NEXT::new(@_); + + bless ($self, $class); + return $self; +} + +=head1 NAME + +breadcrumbs::Controller::CreditsAndDebits - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + + +=head2 index + +=cut + +sub index : Private { + my ( $self, $c ) = @_; + + $c->stash->{template} = "cad_index.tt"; +} + + +=head1 AUTHOR + +Pasqualino Ferrentino,,, + +=head1 LICENSE + +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; diff --git a/web-site/breadcrumbs/lib/breadcrumbs/Controller/User.pm b/web-site/breadcrumbs/lib/breadcrumbs/Controller/User.pm index f27a825..64cabcf 100644 --- a/web-site/breadcrumbs/lib/breadcrumbs/Controller/User.pm +++ b/web-site/breadcrumbs/lib/breadcrumbs/Controller/User.pm @@ -652,7 +652,7 @@ sub _make_menu{ breadcrumbs::util::MenuUtils->add_menu_entry('/cashantnesteuro', 'Gestione cassa', $menu, $c); } - + breadcrumbs::util::MenuUtils->add_menu_entry('/creditsanddebits', 'Crediti e debiti', $menu, $c); breadcrumbs::util::MenuUtils->add_menu_entry('/cashusertao', 'C/C in Tao', $menu, $c); breadcrumbs::util::MenuUtils->add_menu_entry('/cashusereuro', 'C/C in Euro', $menu, $c); breadcrumbs::util::MenuUtils->add_menu_entry('/userads', 'I miei annunci', $menu, $c); diff --git a/web-site/breadcrumbs/root/src/cad_index.tt b/web-site/breadcrumbs/root/src/cad_index.tt new file mode 100644 index 0000000..5b2575d --- /dev/null +++ b/web-site/breadcrumbs/root/src/cad_index.tt @@ -0,0 +1,2 @@ + +Ma che bello. \ No newline at end of file diff --git a/web-site/breadcrumbs/t/controller_CreditsAndDebits.t b/web-site/breadcrumbs/t/controller_CreditsAndDebits.t new file mode 100644 index 0000000..9e967c5 --- /dev/null +++ b/web-site/breadcrumbs/t/controller_CreditsAndDebits.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More tests => 3; + +BEGIN { use_ok 'Catalyst::Test', 'breadcrumbs' } +BEGIN { use_ok 'breadcrumbs::Controller::CreditsAndDebits' } + +ok( request('/creditsanddebits')->is_success, 'Request should succeed' ); + + -- 2.11.4.GIT