Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form-2.tcl,v
diff -u -r1.10 -r1.11
--- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form-2.tcl 3 Aug 2005 22:46:40 -0000 1.10
+++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form-2.tcl 5 Aug 2005 05:40:09 -0000 1.11
@@ -104,6 +104,8 @@
{method cc}
internal_account:optional
+
+ {scholarship_p 0}
}
# We need them to be logged in
Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.adp,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.adp 5 Jul 2005 23:57:38 -0000 1.4
+++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.adp 5 Aug 2005 05:40:09 -0000 1.5
@@ -17,7 +17,15 @@
#dotlrn-ecommerce.lt_1_Please_review_your_#
#dotlrn-ecommerce.Order_list#
@items_ul;noquote@
+
+
+ #dotlrn-ecommerce.Scholarships#
+
+ @scholarships.title@; Amount Granted @scholarships.grant_amount@
+
+
+
#dotlrn-ecommerce.lt_2_Complete_this_infor#
-
+
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.tcl,v
diff -u -r1.17 -r1.18
--- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.tcl 3 Aug 2005 22:46:40 -0000 1.17
+++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.tcl 5 Aug 2005 05:40:09 -0000 1.18
@@ -861,4 +861,19 @@
}
append hidden_vars [export_form_vars billing_address_id shipping_address_id user_id participant_id]
+# Get scholarships
+db_multirow scholarships scholarships {
+ select f.title, sum(g.grant_amount) as grant_amount
+ from scholarship_fundi f,
+ scholarship_fund_grants g,
+ ec_gift_certificates gc
+ where f.fund_id = g.fund_id
+ and g.gift_certificate_id = gc.gift_certificate_id
+ and g.user_id = :user_id
+
+ group by f.title
+} {
+ set grant_amount [ec_pretty_price $grant_amount]
+}
+
db_release_unused_handles
Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.adp 3 Aug 2005 22:46:40 -0000 1.1
+++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.adp 5 Aug 2005 05:40:09 -0000 1.2
@@ -7,18 +7,20 @@
You have not granted any scholarship amount
-
- The scholarship granted does not cover the order amount
-
+
+
+ The scholarship granted does not cover the order amount of @pretty_total_price@.
+
+
+ The scholarship covers the order amount of @pretty_total_price@.
+
+
- The scholarship granted exceeds the order amount.
- The balance shall be granted to the user as a gift certificate.
+ The scholarship granted exceeds the order amount of @pretty_total_price@.
+ The balance can be used by the user in future purchases.
-
- The scholarship covers the order amount
-
Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.tcl 3 Aug 2005 22:46:40 -0000 1.1
+++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.tcl 5 Aug 2005 05:40:09 -0000 1.2
@@ -23,6 +23,34 @@
set total_amount 0
+# Assume there's a valid order_id
+set user_session_id [ec_get_user_session_id]
+set order_id [db_string get_order_id "
+ select order_id
+ from ec_orders
+ where user_session_id = :user_session_id
+ and order_state = 'in_basket'" -default ""]
+
+set order_total 0
+set last_product_id 0
+
+db_foreach order_details_select {
+ select i.price_charged, p.product_id, count(*) as quantity, c.offer_code
+ from ec_items i, ec_products p
+ left join ec_user_session_offer_codes c on (c.product_id = p.product_id and c.user_session_id = :user_session_id)
+ where i.order_id = :order_id
+ and i.product_id = p.product_id
+ group by p.product_name, p.one_line_description, p.product_id, i.price_name, i.price_charged, i.color_choice, i.size_choice, i.style_choice, c.offer_code
+} {
+ if {$product_id != $last_product_id} {
+ set lowest_price [lindex [ec_lowest_price_and_price_name_for_an_item $product_id $user_id $offer_code] 0]
+ }
+
+ set order_total [expr $order_total + $quantity * $lowest_price]
+}
+set order_total_price_pre_gift_certificate $order_total
+
+
foreach one_fund_id $fund_id {
if { [db_0or1row scholarship {
select sf.*
@@ -40,48 +68,64 @@
# Invalid value
template::multirow append scholarships $one_fund_id $title $description $amount 0 0 "You entered an invalid amount"
} else {
- if { $amount < $amount_to_grant } {
- template::multirow append scholarships $one_fund_id $title $description $amount 0 0 "You entered an amount greater than what the fund can accommodate"
+ # if { $amount < $amount_to_grant } {
+ # template::multirow append scholarships $one_fund_id $title $description $amount 0 0 "You entered an amount greater than what the fund can accommodate"
+
+ # } else {
+ # Valid
+ db_transaction {
+
+ set gift_certificate_id [db_nextval ec_gift_cert_id_sequence]
+ set random_string [ec_generate_random_string 10]
+ set claim_check "scholarship-$random_string-$gift_certificate_id"
+ set peeraddr [ns_conn peeraddr]
+ set gc_months [ad_parameter -package_id [ec_id] GiftCertificateMonths ecommerce]
- } else {
- # Valid
- template::multirow append scholarships $one_fund_id $title $description [expr $amount - $amount_to_grant] $amount_to_grant 1 "Granted"
- set total_amount [expr $total_amount + $amount_to_grant]
+ set viewing_user_id [ad_conn user_id]
+
+ db_dml insert_new_gc_into_db [subst {
+ insert into ec_gift_certificates
+ (gift_certificate_id, gift_certificate_state, amount, issue_date, purchased_by, expires, last_modified, last_modifying_user, modified_ip_address, user_id)
+ values
+ (:gift_certificate_id, 'authorized', :amount_to_grant, current_timestamp, :viewing_user_id, current_timestamp + '$gc_months months'::interval, current_timestamp, :viewing_user_id, :peeraddr, :user_id)
+ }]
+
+ db_dml insert_scholarship_grant {
+ insert into scholarship_fund_grants
+ (fund_id, user_id, gift_certificate_id, grant_amount)
+ values
+ (:one_fund_id, :user_id, :gift_certificate_id, :amount_to_grant)
+ }
+
}
+
+ template::multirow append scholarships $one_fund_id $title $description [ec_pretty_price [expr $amount - $amount_to_grant]] [ec_pretty_price $amount_to_grant] 1 "Granted"
+ set total_amount [expr $total_amount + $amount_to_grant]
+ # }
}
}
-
}
}
template::list::create \
-name scholarships \
-multirow scholarships \
+ -no_data "No scholarship granted" \
-elements {
title { label Title }
description { label Description }
- amount_left { label "Amount in Fund" }
amount_granted { label "Amount Granted" }
message { label "Comments" }
}
-# Assume there's a valid order_id
-set user_session_id [ec_get_user_session_id]
-set order_id [db_string get_order_id "
- select order_id
- from ec_orders
- where user_session_id = :user_session_id
- and order_state = 'in_basket'" -default ""]
-
-set price_shipping_gift_certificate_and_tax [ec_price_shipping_gift_certificate_and_tax_in_an_order $order_id]
-set order_total_price_pre_gift_certificate [expr [lindex $price_shipping_gift_certificate_and_tax 0] + [lindex $price_shipping_gift_certificate_and_tax 1]]
-
if { $total_amount >= $order_total_price_pre_gift_certificate } {
# Scholarship covers order
set next_url $return_url
} else {
- set next_url [export_vars -base checkout-one-form]
+ set next_url [export_vars -base checkout-one-form { user_id }]
}
set back_url [export_vars -base checkout-scholarships { user_id return_url }]
-set amountsub [expr $total_amount - $order_total_price_pre_gift_certificate]
\ No newline at end of file
+set amountsub [expr $total_amount - $order_total_price_pre_gift_certificate]
+
+set pretty_total_price [ec_pretty_price $order_total_price_pre_gift_certificate]
Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.adp 3 Aug 2005 22:46:40 -0000 1.1
+++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.adp 5 Aug 2005 05:40:09 -0000 1.2
@@ -1,3 +1,4 @@
+ #dotlrn-ecommerce.Grant_Scholarships#
Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.tcl 3 Aug 2005 22:46:40 -0000 1.1
+++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.tcl 5 Aug 2005 05:40:09 -0000 1.2
@@ -20,12 +20,11 @@
-key fund_id \
-name scholarships \
-multirow scholarships \
- -bulk_actions {Purchase checkout-scholarships-2 Purchase} \
+ -bulk_actions {Continue checkout-scholarships-2 Continue} \
-bulk_action_export_vars { user_id return_url } \
-elements {
title { label "Title" }
description { label "Description" }
- amount { label "Amount in Fund" }
grant_amount {
label "Amount to Grant"
display_template {
Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order.tcl 3 Aug 2005 22:46:40 -0000 1.6
+++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order.tcl 5 Aug 2005 05:40:09 -0000 1.7
@@ -249,8 +249,6 @@
if {$hard_goods_cost > 0} {
- ns_log notice "DEBUG:: hard"
-
# The order contains hard goods that come at a cost.
if {$soft_goods_cost > 0} {
@@ -769,6 +767,7 @@
(:creditcard_id, :transaction_id, :order_id, :transaction_amount, 'charge', sysdate)"
array set response [ec_creditcard_authorization $order_id $transaction_id]
+
set result $response(response_code)
set transaction_id $response(transaction_id)
if { [string equal $result "authorized"] } {