Index: openacs-4/packages/expense-tracking/expense-tracking.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/expense-tracking.info,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/expense-tracking.info 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,24 @@ + + + + + Expense Tracking + Expense Tracking + f + f + + + Hamilton Chua + Expense tracking package for managing line expenses for each class in a dotlrn community + Solutiong Grove + + + + + + + + + + + Index: openacs-4/packages/expense-tracking/sql/postgresql/expense-tracking-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/sql/postgresql/Attic/expense-tracking-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/sql/postgresql/expense-tracking-create.sql 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1 @@ + Index: openacs-4/packages/expense-tracking/sql/postgresql/expense-tracking-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/sql/postgresql/Attic/expense-tracking-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/sql/postgresql/expense-tracking-drop.sql 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1 @@ \ No newline at end of file Index: openacs-4/packages/expense-tracking/tcl/expense-tracking-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/tcl/expense-tracking-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/tcl/expense-tracking-procs.tcl 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,76 @@ +ad_library { + + Expense Tracking procs. + + @author Hamilton Chua (hamilton.chua@gmail.com) + @creation-date 2005-05-14 + @cvs-id $Id: expense-tracking-procs.tcl,v 1.1 2005/05/31 22:06:17 hamiltonc Exp $ +} + +namespace eval exptrack { + +ad_proc delete_expense { + {-exp_id:required } +} { + HAM (hamilton.chua@gmail.com) + Delete an expense item. +} { + db_transaction { db_exec_plsql delete_q {} } +} + +ad_proc add_expense { + {-id:required} + {-expense:required} + {-date } + {-amount } + {-class_key } + {-user_id } + {-community_id } +} { + HAM (hamilton.chua@gmail.com) + Add expense item +} { + set package_id [ad_conn package_id] + set creation_ip [ns_conn peeraddr] + + db_transaction { + set exp_id [db_exec_plsql add_q {}] + } + + # db_dml "add_expense" "insert into expenses (exp_id, exp_expense, exp_date, exp_amount, user_id, class_key, community_id, package_id) values (:id,:expense,:date,:amount,:user_id, :class_key,:community_id, :package_id)" +} + +ad_proc update_expense { + {-id:required} + {-expense:required} + {-date } + {-amount } + {-class_key } + {-user_id } + {-community_id } +} { + HAM (hamilton.chua@gmail.com) + Add expense item +} { + + db_transaction { + set exp_id [db_exec_plsql update_q {}] + } + + # db_dml "update_expense" "update expenses set exp_expense = :expense, exp_date = :date, exp_amount = :amount, class_key = :class_key, user_id = :user_id, community_id = :community_id where exp_id = :id" +} + +ad_proc get_expense { + {-id:required } +} { + HAM (hamilton.chua@gmail.com) + Retrieve expense record and put it into an array +} { + if { [db_0or1row "get_expense" "select exp_id, exp_expense, to_char(exp_date,'YYYY-MM-DD') as exp_date, exp_amount, user_id, class_key, community_id, exp_exported from expenses where exp_id = :id" -column_array exp_item] } { + return [array get exp_item] + } else { + return {} + } +} + +} \ No newline at end of file Index: openacs-4/packages/expense-tracking/tcl/expense-tracking-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/tcl/expense-tracking-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/tcl/expense-tracking-procs.xql 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,44 @@ + + + + postgresql7.3 + + + + select expenses__delete ( + :exp_id + ) + + + + + + select expenses__new ( + :id, + :expense, + :date, + :amount, + :class_key, + :community_id, + :user_id, + :package_id, + :creation_ip + ) + + + + + + select expenses__update ( + :id, + :expense, + :date, + :amount, + :class_key, + :community_id, + :user_id + ) + + + + Index: openacs-4/packages/expense-tracking/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/index.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/index.adp 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,4 @@ + +Expense TrackingFor admins only. Index: openacs-4/packages/expense-tracking/www/admin/addedit-expense.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/admin/addedit-expense.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/admin/addedit-expense.adp 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,5 @@ + +@title@ +"@title@" + + \ No newline at end of file Index: openacs-4/packages/expense-tracking/www/admin/addedit-expense.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/admin/addedit-expense.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/admin/addedit-expense.tcl 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,85 @@ +ad_page_contract { + Add new expense + + @author Hamilton Chua (hamilton.chua@gmail.com) + @creation-date 2005-05-14 + @cvs-id $Id: addedit-expense.tcl,v 1.1 2005/05/31 22:06:17 hamiltonc Exp $ + +} { + { exp_id:integer,optional } +} + +# initial vars +set package_id [ad_conn package_id] +set package_url [apm_package_url_from_id $package_id] +set user_id [auth::get_user_id] +set return_url "$package_url/admin" +set title "Add Expense" +set expenses_package_id [expenses::get_package_id] + +# HAM : FIXME +# do we still need to detect class_key ? +set class_key "" +set community_id [dotlrn_community::get_community_id] + +# determine if we're editing or adding +if {[ad_form_new_p -key exp_id]} { + # new entry + set cancel_url $return_url +} else { + set title "Edit Expense" + set cancel_url $return_url +} + +# generate the form + +ad_form -name new_expense \ +-export { return_url } \ +-form { + exp_id:key(acs_object_id_seq) + { expense:text + { label "Expense" } } + { exp_date:text(text) + {label "Date"} + {html {id sel1}} + {after_html { \[y-m-d \]} } } + { exp_amount:currency,to_sql(sql_number) + { label "Amount" } } +} + +# add support for categories +category::ad_form::add_widgets \ + -container_object_id $expenses_package_id \ + -categorized_object_id [value_if_exists exp_id] \ + -form_name new_expense + +ad_form -extend -name new_expense -new_request { + set exp_amount [template::util::currency::create "$" "0" "." "00" ] +} -edit_request { + array set exp_item [exptrack::get_expense -id $exp_id] + set expense $exp_item(exp_expense) + set exp_date $exp_item(exp_date) + set amount_split [split $exp_item(exp_amount) .] + set exp_amount [template::util::currency::create "$" [lindex $amount_split 0] "." [lindex $amount_split 1] ] +} -validate { + {exp_amount + { ![template::util::negative [template::util::currency::get_property whole_part $exp_amount]] } + "Amount can not be negative" + } + {exp_amount + { !"[template::util::currency::get_property whole_part $exp_amount].[template::util::currency::get_property fractional_part $exp_amount]" == "0.00" } + "Amount can not be zero" + } +} -on_submit { + set category_ids [category::ad_form::get_categories -container_object_id $expenses_package_id] +} -new_data { + exptrack::add_expense -id $exp_id -date $exp_date -expense $expense -amount $exp_amount -class_key $class_key -user_id $user_id -community_id $community_id + category::map_object -remove_old -object_id $exp_id $category_ids +} -edit_data { + exptrack::update_expense -id $exp_id -date $exp_date -expense $expense -amount $exp_amount -class_key $class_key -user_id $user_id -community_id $community_id + category::map_object -remove_old -object_id $exp_id $category_ids +} -after_submit { + ad_returnredirect "$package_url/admin" + ad_script_abort +} + Index: openacs-4/packages/expense-tracking/www/admin/delete-expense-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/admin/delete-expense-2.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/admin/delete-expense-2.tcl 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,17 @@ +ad_page_contract { + Delete a list of expenses + + @author Hamilton Chua (hamilton.chua@gmail.com) + @creation-date 2005-05-14 + @cvs-id $Id: delete-expense-2.tcl,v 1.1 2005/05/31 22:06:17 hamiltonc Exp $ +} { + exp_id:notnull +} -errors { + exp_id:notnull "At least one expense id is required" +} + +foreach id $exp_id { + exptrack::delete_expense -exp_id $id +} + +ad_returnredirect "index" Index: openacs-4/packages/expense-tracking/www/admin/delete-expense.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/admin/delete-expense.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/admin/delete-expense.adp 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,11 @@ + +@title@ + +@confirm_message;noquote@ +

+ +
+ @hidden_vars;noquote@ +
+
+ Index: openacs-4/packages/expense-tracking/www/admin/delete-expense.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/admin/delete-expense.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/admin/delete-expense.tcl 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,38 @@ +ad_page_contract { + Delete expenses + + @author Hamilton Chua (hamilton.chua@gmail.com) + @creation-date 2005-05-14 + @cvs-id $Id: delete-expense.tcl,v 1.1 2005/05/31 22:06:17 hamiltonc Exp $ +} { + exp_id:multiple,notnull +} -errors { + exp_id:notnull "You must provide the expenses to be deleted." +} + +set title "Delete Expenses" +set confirm_message "Are you sure you want to delete the following expense items?" + +# generate list of exp_item_id's for deletion +for {set i 0} {$i < [llength $exp_id]} {incr i} { + set id_$i [lindex $exp_id $i] + lappend bind_id_list ":id_$i" +} + +template::list::create \ + -name expense_items \ + -multirow expense_items\ + -elements { + exp_expense { + label "Expense" + } + exp_amount { + label "Amoumt" + display_template { $@expense_items.exp_amount@ } + } + } + +set items_for_delete [join $bind_id_list ","] +db_multirow expense_items item_del_query "select exp_expense, exp_date, exp_amount from expenses where exp_id in ($items_for_delete)" + +set hidden_vars [export_form_vars exp_id] Index: openacs-4/packages/expense-tracking/www/admin/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/admin/index.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/admin/index.adp 31 May 2005 22:06:17 -0000 1.1 @@ -0,0 +1,11 @@ + +@title@ + + + + + +

Add Expense +

No expenses for this class. + + Index: openacs-4/packages/expense-tracking/www/admin/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/admin/index.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/admin/index.tcl 31 May 2005 22:06:18 -0000 1.1 @@ -0,0 +1,64 @@ +ad_page_contract { + + List line expenses for a given class + + @author Hamilton Chua (hamilton.chua@gmail.com) + @creation-date 2005-05-14 + @cvs-id $Id: index.tcl,v 1.1 2005/05/31 22:06:18 hamiltonc Exp $ + +} { + orderby:optional +} + +set title "Expenses" +set context $title +set package_id [ad_conn package_id] + +# use list template to create list of expenses + +template::list::create \ + -name expenses \ + -multirow expenses \ + -key exp_id \ + -actions { + "Add Expense" "addedit-expense" "Add An Expense" + } -bulk_actions { + "Delete" "delete-expense" "Delete Expenses" + } -elements { + exp_date { + label "Date" + } + exp_expense { + label "Expense" + } + exp_amount { + label "Amount" + aggregate "sum" + aggregate_label "Total : $" + display_template { $ @expenses.exp_amount;noquote@ } + } + exp_exported { + label "Exported" + display_template { + + Yes + + + No + + } + } + action { + label "Action" + display_template { Edit | Delete} + } + } -orderby { + exp_date { orderby exp_date } + exp_amount { orderby exp_amount } + } + +# build the multirow + +set orderby_clause "[template::list::orderby_clause -name expenses -orderby]" + +db_multirow expenses get_expenses { } Index: openacs-4/packages/expense-tracking/www/admin/index.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/expense-tracking/www/admin/index.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/expense-tracking/www/admin/index.xql 31 May 2005 22:06:18 -0000 1.1 @@ -0,0 +1,12 @@ + + + + postgresql7.1 + + + + select exp_id, exp_expense, to_char(exp_date,'MM-DD-YYYY') as exp_date, exp_amount, exp_exported from expenses where package_id =:package_id $orderby_clause + + + + \ No newline at end of file