#!/usr/bin/perl use DBI; use CGI qw(:cgi); use feature qw(switch); no warnings qw(experimental::smartmatch); ############################################################################## # # # configuration options are kept in a separate file # # # ############################################################################## do "./f20-budget.config.pl"; ############################################################################## # # # main CGI loop # # # ############################################################################## $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = '10000000'; $q = new CGI; $action=$q->param("action"); $password=$q->param('password'); $askpassword=$q->param('askpassword'); $delete_id=$q->param("delete_id"); $edit_id=$q->param("edit_id"); $budget_id=$q->param("budget_id"); $agent_id=$q->param("agent_id"); $edit_agent_id=$q->param("edit_agent_id"); $new_auto_name=$q->param('new_auto_name'); $new_auto_name =~ s/\'/\'\'/g; $new_auto_location=$q->param('new_auto_location'); $new_auto_location =~ s/\'/\'\'/g; $new_auto_remarks=$q->param('new_auto_remarks'); $new_auto_remarks =~ s/\'/\'\'/g; $new_auto_url=$q->param('new_auto_url'); $new_auto_url =~ s/\'/\'\'/g; $new_name=$q->param('new_name'); $new_name =~ s/\'/\'\'/g; $new_codename=$q->param('new_codename'); $new_codename =~ s/\'/\'\'/g; $new_pseudo=$q->param('new_pseudo'); $new_pseudo =~ s/\'/\'\'/g; $new_firstname=$q->param('new_firstname'); $new_firstname =~ s/\'/\'\'/g; $new_lastname=$q->param('new_lastname'); $new_lastname =~ s/\'/\'\'/g; $new_lastname=$q->param('new_lastname'); $new_fullname =~ s/\'/\'\'/g; $new_fullname=$q->param('new_fullname'); $new_agent=$q->param('new_agent'); $new_location=$q->param('new_location'); $new_location =~ s/\'/\'\'/g; $new_remarks=$q->param('new_remarks'); $new_remarks =~ s/\'/\'\'/g; $new_url=$q->param('new_url'); $new_url =~ s/\'/\'\'/g; $new_amount=$q->param('new_amount'); $new_amount = sprintf "%.2f",$new_amount; ## 2 decimal places $new_url=$q->param("new_url"); #$new_url=~ s/http\:\/\///g; # don't remove http:// $new_item = sanitise($q->param("new_item")); $new_labour = sanitise($q->param("new_labour")); $new_resource = sanitise($q->param("new_resource")); $new_status = sanitise($q->param("new_status")); $new_lstatus = sanitise($q->param("new_lstatus")); $new_rstatus = sanitise($q->param("new_rstatus")); $type = sanitise($q->param("type")); for ( $i=0; $i<=50; $i+=1) { $new_status{$i} = sanitise($q->param("new_status$i")); $type{$i} = sanitise($q->param("type$i")); $new_item{$i} = sanitise($q->param("new_item$i")); $new_resource{$i} = sanitise($q->param("new_resource$i")); $new_labour{$i} = sanitise($q->param("new_labour$i")); $new_status{$i} = sanitise($q->param("new_status$i")); $new_lstatus{$i} = sanitise($q->param("new_lstatus$i")); $new_rstatus{$i} = sanitise($q->param("new_rstatus$i")); $new_firstname{$i} = sanitise($q->param("new_firstname$i")); $new_lastname{$i} = sanitise($q->param("new_lastname$i")); $new_codename{$i} = sanitise($q->param("new_codename$i")); $cost{$i}=~ s/\€/@euro/g; $cost{$i} = $q->param("cost$i"); $new_cost{$i}=~ s/\€/@euro/g; $new_cost{$i} = $q->param("new_cost$i"); $currency{$i} = $q->param("currency$i"); } ($second, $minute, $hour, $currentdayofmonth, $month, $year, $weekday, $dayofyear, $IsDST) = localtime(time); $currentmonth=$month+1; $currentyear=$year+'1900'; $new_day=$q->param("'new_day"); $new_month=$q->param("new_month"); $new_year=$q->param("new_year"); $new_date=$q->param('new_year') . $q->param("new_month") . $q->param("new_day"); $new_start_date=$q->param('new_start_year') . $q->param("new_start_month") . $q->param("new_start_day"); $new_end_date=$q->param('new_end_year') . $q->param("new_end_month") . $q->param("new_end_day"); $new_print_date=$q->param('new_print_year') . $q->param("new_print_month") . $q->param("new_print_day"); $new_deliver_day=$q->param("new_deliver_day"); $new_deliver_date=$q->param('new_deliver_year') . $q->param("new_deliver_month") . $q->param("new_deliver_day"); if ($new_name eq '') { $new_name=$new_auto_name; } if ($new_location eq '') { $new_location=$new_auto_location; } if ($new_remarks eq '') { $new_remarks=$new_auto_remarks; } if ($new_url eq '') { $new_remarks=$new_auto_url; } given ($action) { when('select_budget') {&select_budget; } when('add_form') {&add_form; } when('add_budget') {&add_budget; } when('add_budget_information') {&add_budget_information; } when('prepare_agents') {&prepare_agents; } when('input_agents') {&input_agents; } when('edit_agent') {&edit_agent; } when('update_agent') {&update_agent; } when('edit_form') {&edit_form; } when('edit_select_form') {&edit_select_form; } when('edit_budget') {&edit_budget; } when('list_budgets') {&list_budgets; } when('prepare_budget') {&prepare_budget; } when('prepare_money') {&prepare_money; } when('input_budget') {&input_budget; } when('input_money') {&input_money; } when('prepare_expenditure') {&prepare_expenditure; } when('input_expenditure') {&input_expenditure; } when('compile_budget') {&compile_budget; } when('display_budgets') {&display_budgets; } when('present_budget') {&present_budget; } when('delete_form') {&delete_form; } when('delete_budget') {&delete_budget; } when('select_budget') {&select_budget; } when('upload_image') {&upload_image; } #default {&display_budgets; } default { &select_budget; } } exit; # saniti[sz]e parameters and sql inputs as needed sub sanitise { my $string = shift; $string =~ s/\'/\'\'/g; # convert ' to '' $string =~ s/\x92/’/g; # convert "RIGHT SINGLE QUOTATION MARK" to html return $string; } ############################################################################## # # # select budget # # # ############################################################################## sub select_budget { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT name from budgets ORDER BY id DESC); my $sth = $dbh->prepare($sql); $sth->execute; my $sql2 = qq( SELECT DISTINCT firstname, lastname from agents ORDER BY firstname); my $sth2 = $dbh->prepare($sql2); $sth2->execute; &print_header; print <
END ## name budget print(qq(\n)); ## enter agent code print <
feral budget generator: enter agent
 
budget:
enter your agent codename:
END &print_footer; $dbh->disconnect; } ############################################################################## # # # prepare budget # # # ############################################################################## sub prepare_budget { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT * from budgets WHERE name="$new_name" ); my $sth = $dbh->prepare($sql); $sth->execute; ## identify agent by codename my $sql2 = qq( SELECT * from agents where codename ="$new_codename" ); my $sth2 = $dbh->prepare($sql2); $sth2->execute; while (my $record = $sth->fetchrow_hashref) { if (my $record2 = $sth2->fetchrow_hashref) { my $sql3 = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id WHERE finance.budget_id='$record->{id}' AND finance.agent_id ='$record2->{id}' ); my $sth3 = $dbh->prepare($sql3); $sth3->execute; &print_header; print <
feral budget generator
Instructions

Enter your budget requests & contributions. You can return to edit your entries at any time.

)); print(qq()); $i++ } if ($i<=5) { print <)); print(qq()); } } print(qq(
budget name:
$record->{name}
your name: $record2->{firstname} $record2->{lastname}
request money your monetary requests from the f20 budget (all sums in €)
END my $sql4 = qq( SELECT * from expenditure where budget_id='$record->{id}' AND agent_id ='$record2->{id}' ); my $sth4 = $dbh->prepare($sql4); $sth4->execute; for ($i=1;$i<=5;$i++) { while (my $record4 = $sth4->fetchrow_hashref) { print <$i.$currency item
$i.€ item
\n)); print(qq(
)); print(qq()); print(qq(\n)); ## resources section !!! read-in notworking !!! print(qq(\n)); print(qq()); my $sql5 = qq( SELECT * from nonfinance where budget_id=$record->{id} AND agent_id =$record2->{id} AND kind='labour' ); my $sth5 = $dbh->prepare($sql5); $sth5->execute; my $sqlCL = qq( SELECT count(id) AS count from nonfinance where budget_id=$record->{id} AND agent_id =$record2->{id} AND kind='labour' ); my $sthCL = $dbh->prepare($sqlCL); $sthCL->execute; while (my $recordCL = $sthCL->fetchrow_hashref) { my $t = $recordCL->{count}; for ($i=1;$i<=$t;$i++) { while (my $record5 = $sth5->fetchrow_hashref) { print(qq(\n)); print(qq(\n)); print(qq(\n)); $i++ } } print(qq()); } print(qq(\n)); print(qq()); my $sql5 = qq( SELECT * from nonfinance where budget_id=$record->{id} AND agent_id =$record2->{id} AND kind='resources' ); my $sth5 = $dbh->prepare($sql5); $sth5->execute; my $sqlCR = qq( SELECT count(id) AS count from nonfinance where budget_id=$record->{id} AND agent_id =$record2->{id} AND kind='resources' ); my $sthCR = $dbh->prepare($sqlCR); $sthCR->execute; while (my $recordCR = $sthCR->fetchrow_hashref) { my $t = $recordCR->{count}; for ($i=1;$i<=$t;$i++) { while (my $record5 = $sth5->fetchrow_hashref) { print(qq(\n)); print(qq(\n)); print(qq(\n)); $i++ } } print < END } print <
input moneyyour monetary contribution to the budget (direct payments for materials/services, donations to f20, as a sum total)
fetchrow_hashref) { print(qq(value="$record3->{amount}" )); } print(qq( size="3" maxsize="5">
 
input labourthings you commit to doing, non-remunerated. (check the box if this labour has already been deployed)
$i.{status} eq 'delivered') { print"CHECKED" }; print(qq(>
)); print(qq(enter a number to add budget lines
 
input resourcesmaterials, spaces, tools, previous work etc (check the box if your resource has already been deployed)
$i.{status} eq 'delivered') { print "CHECKED" }; print(qq(>
enter a number to add budget lines
 
notesfor your own reference only, these notes will not show up in the shared budget
END # print "OR add budget linesfor labour &/or resources "; # $sthCL->execute; # while (my $recordCL = $sthCL->fetchrow_hashref) { # print ""; # print " add this many budget lines for labour [after $recordCL->{count}]\n"; # } # $sthCR->execute; # whle (my $recordCR = $sthCR->fetchrow_hashref) { # print ""; # print " add this many budget lines for resources [after $recordCR->{count}]\n"; # } } else { & print_header; print(qq(codename not recognised. please retry\n)); } } &print_footer; $dbh->disconnect; } ############################################################################## # # # input budget: input individual budet items - money & resources # # # ############################################################################## sub input_budget { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); &print_header; print(qq(
\n)); print(qq(\n)); print(qq(
<\n)); ## delete expenditure line for agent + budget, if exists my $sqld = qq( DELETE from expenditure where budget_id="$budget_id" AND agent_id="$agent_id"); my $sthd= $dbh->prepare($sqld); $sthd->execute; ## input new expenditure lines for agent for ($i=1; $i<=8; $i++) { if ($new_item{$i} ne '') { my $sql = (qq{INSERT INTO expenditure (budget_id, agent_id, status, type, item, cost, currency) VALUES ($budget_id, $agent_id, '$new_status{$i}', '$type{$i}', '$new_item{$i}', $new_cost{$i}, '€')}); my $sth = $dbh->prepare($sql); $sth->execute; } } ## read in finance for agent my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); my $sth = $dbh->prepare($sql); $sth->execute; #while (my $record = $sth->fetchrow_hashref) { print(qq(\n)); ## delete finance line for agent + budget, if exists my $sqld = qq( DELETE from finance where budget_id="$budget_id" AND agent_id="$agent_id"); my $sthd= $dbh->prepare($sqld); $sthd->execute; ## input money into finance # if ($new_amount ne '') { if ($new_amount eq '') { $new_amount=0; } my $sqli = (qq{INSERT INTO finance (budget_id, agent_id, amount) VALUES ($budget_id, $agent_id, $new_amount)}); my $sthi = $dbh->prepare($sqli); $sthi->execute; my $sqld = qq( DELETE from nonfinance where budget_id="$budget_id" AND agent_id="$agent_id"); my $sthd= $dbh->prepare($sqld); $sthd->execute; ## input labour into nonfinance for agent for ($i=1; $i<=8; $i++) { if ($new_labour{$i} ne '') { my $sqll = (qq{INSERT INTO nonfinance (budget_id, agent_id, item, kind, status) VALUES ($budget_id, $agent_id, "$new_labour{$i}", "labour", "$new_lstatus{$i}")}); my $sthl = $dbh->prepare($sqll); $sthl->execute; } } ## input resources into nonfinance for agent for ($i=1; $i<=8; $i++) { if ($new_resource{$i} ne '') { my $sqlr = (qq{INSERT INTO nonfinance (budget_id, agent_id, item, kind, status) VALUES ($budget_id, $agent_id, "$new_resource{$i}", "resources", "$new_rstatus{$i}")}); my $sthr = $dbh->prepare($sqlr); $sthr->execute; } } ## read back in to get these values from the db, not from the cgi my $sqlv = (qq{SELECT DISTINCT item, cost, expenditure.currency, type, fullname from expenditure RIGHT JOIN agents on expenditure.agent_id=agents.id LEFT JOIN finance on expenditure.agent_id=finance.agent_id WHERE expenditure.agent_id=$agent_id AND expenditure.budget_id=$budget_id}); my $sthv = $dbh->prepare($sqlv); $sthv->execute; my $sqln = (qq{ SELECT fullname from agents where id=$agent_id}); my $sthn = $dbh->prepare($sqln); $sthn->execute; while (my $recordn = $sthn->fetchrow_hashref) { print(qq( )); } # print(qq(\n)); } } print(qq(\n)); print(qq(\n)); $sth->execute; while (my $record = $sth->fetchrow_hashref) { print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(
feral budget generator: $record->{name}
$projectname: $recordn->{fullname}
your PROPOSITION: )); while (my $recordv = $sthv->fetchrow_hashref) { if ($recordv->{item} ne '') { print(qq(
$recordv->{$currency} $recordv->{$cost} $recordv->{$item} $recordv->{$type}
\n)); print(qq(\n)); } &print_footer; } ############################################################################### # input money sub input_money { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); &print_header; print(qq(
\n)); print(qq(\n)); print(qq(
\n)); ## read in finance for agent+ budget my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); my $sth = $dbh->prepare($sql); $sth->execute; while (my $record = $sth->fetchrow_hashref) { if ($record->{id} ne '') { ## delete finance line for agent + budget, if exists my $sqld = qq( DELETE from finance where budget_id="$budget_id" AND agent_id="$agent_id"); my $sthd= $dbh->prepare($sqld); $sthd->execute; } } ## input money into finance if ($new_amount eq '') { $new_amount=0; } my $sqli = (qq{INSERT INTO finance (budget_id, agent_id, amount) VALUES ($budget_id, $agent_id, $new_amount)}); my $sthi = $dbh->prepare($sqli); $sthi->execute; #} print(qq(\n)); print(qq( )); print(qq(\n)); print(qq(\n)); print(qq( )); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(
feral budget generator: $record->{name}
your name:$new_fullname
your monetary contribution:€$new_amount
\n)); print(qq(\n)); &print_footer; } ############################################################################## # # # compile budget: lay out the whole budget as it assembles # # # ############################################################################## sub compile_budget { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sqld = qq( SELECT * FROM nonfinance LEFT JOIN agents ON nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' ORDER BY nonfinance.item); my $sthd = $dbh->prepare($sqld); $sthd->execute; my $sqlol = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status!='delivered' AND kind='labour' ORDER BY nonfinance.item); my $sthol = $dbh->prepare($sqlol); $sthol->execute; my $sqlor = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status!='delivered' AND kind='resources' ORDER BY nonfinance.item); my $sthor = $dbh->prepare($sqlor); $sthor->execute; my $sqldl = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' AND kind='labour' ORDER BY nonfinance.item); my $sthdl = $dbh->prepare($sqldl); $sthdl->execute; my $sqldr = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' AND kind='resources' ORDER BY nonfinance.item); my $sthdr = $dbh->prepare($sqldr); $sthdr->execute; ## count potential deposits my $sqla = qq( SELECT COUNT(fullname) AS qty FROM agents WHERE budget_id=$budget_id AND status!='staff'); my $stha = $dbh->prepare($sqla); $stha->execute; ## count deposits received my $sqlar = qq( SELECT COUNT(fullname) AS qty FROM agents WHERE budget_id=$budget_id AND status='deposit'); my $sthar = $dbh->prepare($sqlar); $sthar->execute; my $sqlc = qq( SELECT COUNT(*) FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agent.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id); my $sthc = $dbh->prepare($sqlc); $sthc->execute; my $sqlf = qq( SELECT * FROM finance WHERE budget_id=$budget_id ORDER by amount); my $sthf = $dbh->prepare($sqlf); $sthf->execute; my $sqlb = qq( SELECT *, date_format(deliver_date,'%d-%m-%Y') AS end_date FROM budgets LEFT JOIN locations on budgets.location=locations.structure WHERE budgets.id=$budget_id); my $sthb = $dbh->prepare($sqlb); $sthb->execute; my $sqlfc = qq( SELECT COUNT(id) AS count FROM finance WHERE budget_id=$budget_id); my $sthfc = $dbh->prepare($sqlfc); $sthfc->execute; my $sqls = qq( SELECT SUM(amount) FROM finance WHERE budget_id=$budget_id); my $sths = $dbh->prepare($sqls); $sths->execute; my $sqlse = qq( SELECT SUM(cost) FROM expenditure WHERE budget_id=$budget_id); my $sthse = $dbh->prepare($sqlse); $sthse->execute; my $sqlr = qq( SELECT name, fullname, codename FROM finance LEFT JOIN agents ON finance.agent_id=agents.id LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); my $sthr = $dbh->prepare($sqlr); $sthr->execute; my $sqlef = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='fee' ORDER BY expenditure.item); my $sthef = $dbh->prepare($sqlef); $sthef->execute; my $sqlem = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='materials' ORDER BY expenditure.item); my $sthem = $dbh->prepare($sqlem); $sthem->execute; my $sqlex = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='misc' ORDER BY expenditure.item); my $sthex = $dbh->prepare($sqlex); $sthex->execute; $sthb->execute; my $recordb = $sthb->fetchrow_hashref; # page header &print_header; # budget header print <
feral budget generator | | $website_url/$script_name
$projectname | | $recordb->{location} | | budget adjustments to $currentyear-$currentmonth-$currentdayofmonth
END if ($agent_id ne "") { while (my $recordfc = $sthfc->fetchrow_hashref) { print <[$recordfc->{count}]. This budget will remain open for editing until $recordb->{end_date}. Monetary items will be kept anonymous (although identifable to the budget r/administrators). Labour & resources will be tagged with the name of the contributor. END } } print <
END # CGI parameter forms $sthr->execute; while (my $recordr = $sthr->fetchrow_hashref) { print< END } if ($agent_id eq "") { print< END } else { print< END } # budget columns print <
END print_title("FINANCIAL"); print_subtitle("OUTGOINGS: / money requested or supplied"); print_subtitle("Labour / paid"); while (my $recordef = $sthef->fetchrow_hashref) { my $cost = $recordef->{cost}; $display_cost = sprintf "%.2f",$cost; $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma print <

$recordef->{item}

$recordef->{currency}$display_cost

END } print_subtitle("Resources / remunerated"); while (my $recordem = $sthem->fetchrow_hashref) { my $cost = $recordem->{cost}; $display_cost = sprintf "%.2f",$cost; $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma print_item("$recordem->{item}","$recordem->{currency}$display_cost"); } print_subtitle("Miscellaneous"); while (my $recordex = $sthex->fetchrow_hashref) { my $cost = $recordex->{cost}; $display_cost = sprintf "%.2f",$cost; $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma print_item("$recordex->{item}", ">$recordex->{currency}$display_cost"); } print_subtitle("INCOME: / donations, contributions, sums, funds"); while (my $recordf = $sthf->fetchrow_hashref) { print_item("", sprintf("€%.2f", $recordf->{amount})); } ## actual paid deposits while (my $recordar = $sthar->fetchrow_hashref) { while (my @sum = $sths->fetchrow_array()) { $deposits = $recordar->{qty}*50; $running = $sum[0]+$deposits; $display_running = sprintf "%.2f",$running; $display_running =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma print_subtotal(" "); # spacing before running lines print_subtotal("RUNNING total IN:", "€$display_running"); } } while (my @sumex = $sthse->fetchrow_array()) { $runningex = $sumex[0]; $surplus = $running - $runningex; $display_runningex = sprintf "%.2f",$runningex; $display_runningex =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma $display_surplus = sprintf "%.2f",$surplus; $display_surplus =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma print_subtotal("RUNNING total OUT:","€$display_runningex"); print_subtotal(" "); # spacing between running & balance lines print_subtotal("BALANCE OF FINANCIAL TRADE:"," €$display_surplus"); } print < )); &print_footer; } # capitalise the initials of a name from a record sub get_initials { $record = shift; my $first=$record->{firstname} ; my $last=$record->{lastname} ; $first_init = substr($first, 0, 1); $last_init = substr($last, 0, 1); $first_init =~ s/^([a-z])/\U$1/; $last_init =~ s/^([a-z])/\U$1/; return "$first_init$last_init" } ############################################################################ # prepare expenditure sub prepare_expenditure { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT item, cost, currency, firstname, lastname, type FROM expenditure LEFT JOIN agents on expenditure.agent_id = agents.id WHERE expenditure.budget_id = $budget_id ORDER BY fullname); my $sth = $dbh->prepare($sql); $sth->execute; my $sqln = qq( SELECT name FROM budgets where id = $budget_id); my $sthn = $dbh->prepare($sqln); $sthn->execute; &print_header; print(qq(
\n)); print(qq(\n)); print(qq(
\n)); print(qq(\n)); while (my $recordn = $sthn->fetchrow_hashref) { print(qq()); } print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); for ($i=1;$i<=23;$i++) { while (my $record = $sth->fetchrow_hashref) { my $cost = $record->{cost}; $dec_cost = sprintf "%.2f",$cost; ## 2 decimal places my $first=$record->{firstname} ; my $last=$record->{lastname} ; $first_init = substr($first, 0, 1); $last_init = substr($last, 0, 1); $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); $i++ } print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); } print(qq(\n)); print(qq(\n)); print(qq(\n)); } ############################################################################ # input expenditure sub input_expenditure { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); # clear previous entries my $sql_del = (qq{DELETE FROM expenditure WHERE budget_id=$budget_id}); my $sth_del = $dbh->prepare($sql_del); $sth_del->execute; for ($i=1; $i<=25; $i++) { if ($new_item{$i} ne '') { my $sql = (qq{INSERT INTO expenditure (budget_id, item, cost, currency) VALUES ($budget_id, '$new_item{$i}', $cost{$i}, '$currency{$i}')}); my $sth = $dbh->prepare($sql); $sth->execute; } } # read back expenditure info my $sql2 = qq( SELECT budget_id, item, cost, currency FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' ORDER BY expenditure.id); my $sth2 = $dbh->prepare($sql2); $sth2->execute; &print_header; print(qq(
\n)); print(qq(
feral budget generator
Expenditure: $recordn->{name}
agentitemcostkind
$i.[$first_init$last_init]
$i.


\n)); print(qq(
\n)); print(qq(\n)); print(qq()); print(qq(
feral budget generator
Expenditure
\n)); print(qq( \n)); while (my $record2 = $sth2->fetchrow_hashref) { my $cost = $record2->{cost}; $dec_cost = sprintf "%.2f",$cost; ## 2 decimal places # print(qq( \n)); print(qq( \n)); } print(qq(\n)); print(qq(
item cost
$record2->{item} $record2->{currency}$record2->{cost}
$record2->{item} $dec_cost
\n)); print(qq(\n)); print(qq(
\n)); my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); my $sth = $dbh->prepare($sql); $sth->execute; $sth->execute; while (my $record = $sth->fetchrow_hashref) { print(qq(
\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(
\n)); print(qq(\n)); } # print(qq(

add or ammend more expenditure items\n)); # print(qq(

got to view the budget as a whole\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); $dbh->disconnect; } ############################################################################ # prepare agents sub prepare_agents { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT * FROM agents WHERE budget_id = $budget_id ORDER BY lastname); my $sth = $dbh->prepare($sql); $sth->execute; my $sqlc = qq( SELECT COUNT(*) AS count FROM agents WHERE budget_id = $budget_id); my $sthc = $dbh->prepare($sqlc); $sthc->execute; my $sqln = qq( SELECT name FROM budgets where id = $budget_id); my $sthn = $dbh->prepare($sqln); $sthn->execute; &print_header; print(qq(
\n)); print(qq(\n)); print(qq(
\n)); print(qq(\n)); while (my $recordn = $sthn->fetchrow_hashref) { print(qq()); } print(qq(\n)); for ($i=1;$i<=50;$i++) { while (my $record = $sth->fetchrow_hashref) { print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); $i++ } } print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); while (my $recordc = $sthc->fetchrow_hashref) { my $c = ($recordc->{count}); for ($i=1+$c;$i<=50;$i++) { print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); # $i++ } } print(qq(\n)); print(qq(\n)); print(qq(\n)); } ############################################################################ # edit agent sub edit_agent { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); # read in agent data &print_header; print(qq(
\n)); print(qq(
feral budget generator
Agents: $recordn->{name}
firstnamelastnamecodename
$record->{firstname}$record->{lastname}$record->{codename}
$i.


\n)); print(qq(\n)); } ############################################################################## # # # printing and formatting # # # ############################################################################## ## print a title sub print_title { my $string = shift; print <$string END } ## print a subtitle sub print_subtitle { my $string = shift; print <$string END } ## print a budget subtotal line with a description and optional amount sub print_subtotal { my $string = shift; my $amount = shift; if (not $amount) { $amount = ""; } print <

$string

$amount

END } ## print standard budget item with a description and optional amount sub print_item { my $string = shift; my $amount = shift; if (not $amount) { $amount = ""; } print <

$string

$amount

END } ## print the page header sub print_header { print < feral budget generator END } ## print a standard footer sub print_footer { print < END } ## print the admin footer sub adminfooter { print(qq(
\n)); print(qq(\n)); print(qq(
\n)); print(qq(\n)); print(qq()); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(
feral budget generator
Edit agent
\n)); print(qq(\n)); print(qq(
\n)); print(qq(
\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); $dbh->disconnect; } ############################################################################ # update agent sub update_agent { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = (qq{UPDATE agents set firstname='$new_firstname', lastname='$new_lastname', fullname='$new_firstname $new_lastname', codename='$new_codename' WHERE budget_id=$budget_id AND id=$edit_agent_id}); my $sth = $dbh->prepare($sql); $sth->execute; # read back agent info &print_header; print(qq(
\n)); print(qq(
\n)); print(qq(
\n)); print(qq(\n)); print(qq(
feral budget generator
\n)); print(qq(
\n)); print(qq(
\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); $dbh->disconnect; } ############################################################################ # input agents sub input_agents { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); for ($i=1; $i<=50; $i++) { if ($new_firstname{$i} ne '') { my $sql = (qq{INSERT INTO agents (budget_id, firstname, lastname, fullname, codename) VALUES ($budget_id, '$new_firstname{$i}', '$new_lastname{$i}', '$new_firstname{$i} $new_lastname{$i} ','$new_codename{$i}')}); # my $sql = (qq{INSERT INTO agents (budget_id, firstname, lastname, codename) VALUES ($budget_id, '$new_firstname{i}', '$new_lastname{i}', '$new_codename{i}')}); my $sth = $dbh->prepare($sql); $sth->execute; } } # read back agent info &print_header; print(qq(
\n)); print(qq(
\n)); print(qq(
\n)); print(qq(\n)); print(qq(
feral budget generator
\n)); print(qq(
\n)); print(qq(
\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); $dbh->disconnect; } ############################################################################ # add form sub add_form { &print_header; print(qq(
\n)); print(qq( $projectname: add a budget \n)); my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); my $sth = $dbh->prepare($sql); $sth->execute; print(qq(

 

\n)); print(qq(\n)); print(qq(
\n)); print(qq()); while (my $record = $sth->fetchrow_hashref) { print(qq()); print(qq()); print(qq()); print(qq()); } print(qq(\n)); $dbh->disconnect; print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); #print(qq(\n)); #print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(
BudgetDate
)); print(qq($record->{name} $record->{date}
 
add a new budget
\n)); print(qq(
date
)); print(qq(

\n)); print(qq(
 
password

\n)); &print_footer; $dbh->disconnect; } ############################################################################### # add budget sub add_budget { #if ($password eq $admin_password) { ### test if workshop exists already in database if ($new_name ne '') { $new_name_found='false'; my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT name FROM budgets); my $sth = $dbh->prepare($sql); $sth->execute; while (my $record = $sth->fetchrow_hashref) { if ($record->{name} eq $new_name) { $new_name_found='true'; } } if ($new_name_found eq 'false') { my $sql = (qq{INSERT INTO budgets (name) VALUES ('$new_name')}); my $sth = $dbh->prepare($sql); $sth->execute; my $sql2 = (qq{ SELECT * from budgets where name='$new_name'}); my $sth2 = $dbh->prepare($sql2); $sth2->execute; $dbh->disconnect; &print_header; while (my $record2 = $sth2->fetchrow_hashref) { print(qq(
\n)); print(qq(\n)); print(qq(\n)); print(qq(
budget added $new_name
\n)); } &print_footer; } else { &print_header; print(qq(duplicate budget entry
\n)); &print_footer; } } else { &print_header; print(qq(no budget entered
\n)); &print_footer; } #} else { #&print_header; #print(qq(

Wrong password !

\n)); #&print_footer; # } } ############################################################################### # add budget information sub add_budget_information { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = (qq{UPDATE budgets SET location='$new_location', deliver_date='$new_deliver_date', remarks='$new_remarks', WHERE name='$new_name'}); my $sth = $dbh->prepare($sql); $sth->execute; $dbh->disconnect; &print_header; print(qq(

\n)); print(qq( $projectname: $new_name added )); #print(qq($add_information \n)); print(qq(

view all budgets

\n)); print(qq(

\n)); &print_footer; } ############################################################################### # edit select form: select which budget to edit sub edit_select_form { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); my $sth = $dbh->prepare($sql); $sth->execute; &print_header; print(qq(
\n)); print(qq( edit a budget
\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); while (my $record = $sth->fetchrow_hashref) { print(qq(\n)); print(qq(\n)); print(qq(
\n)); print(qq( $record->{name}\n)); } print(qq(
\n)); $dbh->disconnect; &print_footer; } ############################################################################### # edit form: edit selected budget sub edit_form { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT * FROM budgets WHERE id=$edit_id); my $sth = $dbh->prepare($sql); $sth->execute; &print_header; print(qq(
\n)); print(qq(

$projectname: edit budget

\n)); # print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); while (my $record = $sth->fetchrow_hashref) { print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); # print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(
 
location
url
Remarks: When, where, who
password
\n)); print(qq(
\n)); } &print_footer; } ############################################################################### # present budget: present singlebudget sub present_budget { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT * FROM budgets WHERE id=$edit_id); my $sth = $dbh->prepare($sql); $sth->execute; &print_header; # print(qq(
\n)); print(qq(

$projectname: budget notes

\n)); # print(qq(\n)); print(qq(\n)); print(qq(\n)); while (my $record = $sth->fetchrow_hashref) { $record->{remarks} =~ s/\n/\
/g; print(qq(\n)); print(qq(\n)); # print(qq(\n)); print(qq(\n)); print(qq(\n)); # print(qq(\n)); # print(qq(\n)); print(qq(\n)); print(qq(
$record->{name}, \n)); print(qq($record->{location} 
$record->{url}
Remarks: When, where, who
$record->{remarks}
password
\n)); print(qq(
\n)); } &print_footer; } ############################################################################### # edit budget: edit budget results sub edit_budget { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); #if ($password eq $admin_password) { &print_header; ### update budgets table my $sql_update = (qq{UPDATE budgets SET name='$new_name', location='$new_location', url='$new_url', remarks='$new_remarks', deliver_date="$new_deliver_date" WHERE id='$edit_id'}); my $sth_update = $dbh->prepare($sql_update); $sth_update->execute; ### display results my $sql = qq( SELECT * FROM budgets WHERE id = '$edit_id'); my $sth = $dbh->prepare($sql); $sth->execute; while (my $record = $sth->fetchrow_hashref) { print(qq(
\n)); # print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(
updated
$record->{name}

)); } $dbh->disconnect; &print_footer; } ############################################################################### # delete form: select a budget to delete sub delete_form { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); my $sth = $dbh->prepare($sql); $sth->execute; &print_header; print(qq(
\n)); print(qq( delete a budget
\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); while (my $record = $sth->fetchrow_hashref) { # print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); print(qq(
\n)); print(qq( $record->{name}\n)); print(qq($record->{location}\n)); } print(qq(
password
\n)); $dbh->disconnect; &print_footer; } ############################################################################### # delete budget: budget delete results sub delete_budget { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = (qq{SELECT * FROM budgets WHERE id = '$delete_id'}); my $sth = $dbh->prepare($sql); $sth->execute; my $sql2 = (qq{DELETE FROM budgets WHERE id = '$delete_id'}); my $sth2 = $dbh->prepare($sql2); $sth2->execute; while (my $record = $sth->fetchrow_hashref) { &print_header; print(qq($record->{name} deleted\n)); } &print_footer; $dbh->disconnect; } ############################################################################### # display budget: displays all budgets sub display_budgets { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); my $sth = $dbh->prepare($sql); $sth->execute; &print_header; print(qq(
\n)); print(qq(

$projectname: all budgets: edit mode

\n)); print(qq(\n)); print(qq(\n)); while (my $record = $sth->fetchrow_hashref) { print(qq(\n)); print(qq()); print(qq()); print(qq()); print(qq()); # print(qq()); print(qq(\n)); } $dbh->disconnect; print(qq(
BudgetLocationDateURL
$record->{name}$record->{location}$record->{deliver_date}$record->{url}
\n)); &print_footer; } ############################################################################### # list budgets: list all budgets, non-edit mode sub list_budgets { my $dbh = DBI->connect($db_conect,$db_user,$db_pass) or die ("can't connect: $DBI::errstr"); my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); my $sth = $dbh->prepare($sql); $sth->execute; &print_header; print(qq(
\n)); print(qq(

$projectname: all budgets: read-only

\n)); print(qq(\n)); print(qq(\n)); while (my $record = $sth->fetchrow_hashref) { print(qq(\n)); print(qq()); print(qq()); print(qq()); print(qq()); # print(qq()); print(qq(\n)); } $dbh->disconnect; print(qq(
BudgetLocationDateURL
$record->{name}$record->{location}$record->{deliver_date}$record->{url}
\n)); &print_footer; } ############################################################################################## # select start date subroutine sub select_start_date { ### day print(qq(
\n)); ### month print(qq(\n)); ### year print(qq(

all budgets: edit

all budgets: list

add a budget \ \; \|\n)); print(qq(delete a budget \ \; \n)); print(qq(\n)); print(qq(\n)); print(qq(\n)); }