From 509a7f1f8eb23db1760d4503d3112acda04f4c1d Mon Sep 17 00:00:00 2001 From: Jerry Jalava Date: Tue, 22 Apr 2008 16:08:48 +0300 Subject: [PATCH] Added two new examples. Simple exporters for expense & hour reports --- plugins/ajatus/examples/export_expenses.php | 76 ++++++++++++++++++ plugins/ajatus/examples/export_hours.php | 115 ++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 plugins/ajatus/examples/export_expenses.php create mode 100644 plugins/ajatus/examples/export_hours.php diff --git a/plugins/ajatus/examples/export_expenses.php b/plugins/ajatus/examples/export_expenses.php new file mode 100644 index 0000000..122505f --- /dev/null +++ b/plugins/ajatus/examples/export_expenses.php @@ -0,0 +1,76 @@ + 'couchdb_server', + 'db' => $db + )); +} +catch (ajatus_exception $e) +{ + die( "Error initializing Ajatus! Reason:\n{$e}\n" ); +} + +$expense_reports = $ajatus->types->expense->all(array + ( + 'additional_map_values' => array + ( + 'description' => 'doc.value.description' + ) + ) +)->rows; + +$report_count = count($expense_reports); + +$status_for_everyone = array(); +$totals_for_users = array(); + +foreach ($expense_reports as $expense) +{ + $reporter = $expense->value->creator->val; + $amount = $expense->value->amount->val; + + $description = $report->value->description->val; + + $date_ts = ajatus_helpers_date::jsdatetime_to_unixtime($expense->value->date->val); + + $identifier = (string) date("Y-m", $date_ts); + + if (! isset($status_for_everyone[$identifier])) + { + $status_for_everyone[$identifier] = 0; + } + + if (! isset($status_for_users[$identifier])) + { + $status_for_users[$identifier] = array(); + } + + if (! isset($status_for_users[$identifier][$reporter])) + { + $status_for_users[$identifier][$reporter] = 0; + } + + $status_for_everyone[$identifier] += $amount; + $status_for_users[$identifier][$reporter] += $amount; +} +ksort($status_for_everyone); + +foreach ($status_for_everyone as $identifier => $month_total) +{ + echo "{$identifier}\n------------\n"; + + foreach ($status_for_users[$identifier] as $reporter => $total) + { + echo " {$reporter} => {$total}\n"; + } + + echo "Total: {$month_total}\n\n"; +} + +?> \ No newline at end of file diff --git a/plugins/ajatus/examples/export_hours.php b/plugins/ajatus/examples/export_hours.php new file mode 100644 index 0000000..2eb4ebf --- /dev/null +++ b/plugins/ajatus/examples/export_hours.php @@ -0,0 +1,115 @@ + 'couchdb_server', + 'db' => $db + )); +} +catch (ajatus_exception $e) +{ + die( "Error initializing Ajatus! Reason:\n{$e}\n" ); +} + +$by_tags_search = false; +$tags_to_search = array(); + +if (count($argv) >= 2) +{ + $by_tags_search = true; + for ($i=1; $itypes->hourreport->get_by_tags(array('client:nemein'), array(), array + ( + 'description' => 'doc.value.description' + ) + ); +} +else +{ + $hour_reports = $ajatus->types->hourreport->all(array + ( + 'additional_map_values' => array + ( + 'description' => 'doc.value.description' + ) + ) + )->rows; +} + +$report_count = count($hour_reports); + +if ($report_count == 0) +{ + die("No hour reports found!\n"); +} + +echo "Founded {$report_count} hour reports.\n"; + +$status_for_everyone = array(); +$totals_for_users = array(); +foreach ($hour_reports as $report) +{ + $reporter = $report->value->creator->val; + + if (empty($reporter)) + { + continue; + } + + $date_ts = ajatus_helpers_date::jsdatetime_to_unixtime($report->value->date->val); + $hours = (int) $report->value->hours->val; + + $description = $report->value->description->val; + + $identifier = (string) date("Y-m", $date_ts); + + if (! isset($totals_for_everyone[$identifier])) + { + $totals_for_everyone[$identifier] = 0; + } + + if (! isset($totals_for_users[$identifier])) + { + $totals_for_users[$identifier] = array(); + } + + if (! isset($totals_for_users[$identifier][$reporter])) + { + $totals_for_users[$identifier][$reporter] = 0; + } + + $totals_for_everyone[$identifier] += $hours; + $totals_for_users[$identifier][$reporter] += $hours; + + // $date_str = strftime("%x", $date_ts); + // echo "User: {$reporter} reported {$hours} hours in {$date_str} with description: {$description}\n"; +} +ksort($totals_for_everyone); + +foreach ($totals_for_everyone as $identifier => $count) +{ + echo "Month: {$identifier}\n----------------------\n"; + + foreach ($totals_for_users[$identifier] as $user => $ucount) + { + echo " {$user} => {$ucount}\n"; + } + + echo "Total: {$count}\n\n"; +} + +?> \ No newline at end of file -- 2.11.4.GIT