Index: openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-2.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-2.tcl 5 Aug 2005 05:57:43 -0000 1.2 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-2.tcl 12 Aug 2005 10:10:14 -0000 1.3 @@ -93,18 +93,47 @@ set item_id_list [list] } +# See if a credit card was used for this purchase +set method [db_string method { + select method + from dotlrn_ecommerce_transactions + where order_id = :order_id +} -default cc] + +if { $method == "invoice" } { + if { [db_0or1row cc_transaction_in_invoice { + select 1 + where exists (select * + from dotlrn_ecommerce_transaction_invoice_payments + where order_id = :order_id + and method = 'cc') + }] } { + set method cc + } +} + set items_to_print "" db_foreach get_return_item_list $sql { if { [info exists all_items_p] } { lappend item_id_list $item_id } + + if { $method == "cc" } { append items_to_print " $product_name - (out of [ec_pretty_price $price_charged]) + (by credit card out of [ec_pretty_price $price_charged]); (manually out of [ec_pretty_price $price_charged]) " + } else { + append items_to_print " + + $product_name + (manually out of [ec_pretty_price $price_charged]) + + " + } } append doc_body " Index: openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-3-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-3-postgresql.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-3-postgresql.xql 3 Aug 2005 22:45:46 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-3-postgresql.xql 12 Aug 2005 10:10:14 -0000 1.2 @@ -41,7 +41,7 @@ - select coalesce(ec_cash_amount_to_refund(:total_amount_to_refund, :order_id),0) + select coalesce(ec_cash_amount_to_refund((:total_amount_to_refund::float + :total_amount_to_refund_manually::float)::numeric, :order_id::integer),0) Index: openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-3.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-3.tcl 5 Aug 2005 02:52:53 -0000 1.2 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-3.tcl 12 Aug 2005 10:10:14 -0000 1.3 @@ -21,7 +21,8 @@ received_back_datetime reason_for_return item_id_list - price_to_refund:array + price_to_refund:array,optional + price_to_refund_manually:array shipping_to_refund:array base_shipping_to_refund } @@ -51,6 +52,7 @@ # Add up the items' price/shipping/tax to refund as we go set total_price_to_refund 0 +set total_price_to_refund_manually 0 set total_shipping_to_refund 0 set total_price_tax_to_refund 0 set total_shipping_tax_to_refund 0 @@ -62,17 +64,24 @@ where i.product_id=p.product_id and i.item_id in ([join $item_id_list ", "])" { - if { [empty_string_p $price_to_refund($item_id)] } { + if { ! [array exists price_to_refund] } { + foreach _item [array names price_to_refund_manually] { + set price_to_refund($_item) 0 + } + } + + if { [empty_string_p price_to_refund($item_id)] || [empty_string_p price_to_refund_manually($item_id)] } { incr exception_count append exception_text "
  • Please enter a price to refund for $product_name." - } elseif {[regexp {[^0-9\.]} $price_to_refund($item_id)]} { + } elseif {[regexp {[^0-9\.]} $price_to_refund($item_id)] || [regexp {[^0-9\.]} $price_to_refund_manually($item_id)]} { incr exception_count append exception_text "
  • Please enter a purely numeric price to refund for $product_name (no letters or special characters)." - } elseif { $price_to_refund($item_id) > $price_charged } { + } elseif { ($price_to_refund($item_id) + $price_to_refund_manually($item_id)) > $price_charged } { incr exception_count append exception_text "
  • Please enter a price to refund for $product_name that is less than or equal to [ec_pretty_price $price_charged]." } else { set total_price_to_refund [expr $total_price_to_refund + $price_to_refund($item_id)] + set total_price_to_refund_manually [expr $total_price_to_refund_manually + $price_to_refund_manually($item_id)] # Tax will be the minimum of the tax actually charged and the # tax that would have been charged on the price to refund (tax @@ -135,17 +144,33 @@ set total_tax_to_refund [expr $total_price_tax_to_refund + $total_shipping_tax_to_refund] set total_amount_to_refund [expr $total_price_to_refund + $total_shipping_to_refund + $total_tax_to_refund] +set total_amount_to_refund_manually [expr $total_price_to_refund_manually + $total_shipping_to_refund + $total_tax_to_refund] # Determine how much of this will be refunded in cash set cash_amount_to_refund [db_string get_cash_refunded " select nvl(ec_cash_amount_to_refund(:total_amount_to_refund,:order_id),0) from dual"] +# Calculate how much to refund to the credit card and how much to +# refund manually +if { $total_amount_to_refund >= $cash_amount_to_refund } { + # Requested amount to refund to credit card is greater than what + # is available for refund (the rest probably paid via gift + # certs/scholarship), give priority to credit card refunds than + # manual refunds + set cash_amount_to_refund_cc $cash_amount_to_refund + set cash_amount_to_refund_manually 0 +} else { + # Give priority to credit card refunds, the rest refund manually + set cash_amount_to_refund_cc $total_amount_to_refund + set cash_amount_to_refund_manually [expr $cash_amount_to_refund - $total_amount_to_refund] +} + # Calculate gift certificate amount and tax to refund -set certificate_amount_to_reinstate [expr $total_amount_to_refund - $cash_amount_to_refund] -if { $certificate_amount_to_reinstate < 0 } { +set certificate_amount_to_reinstate [expr ($total_amount_to_refund + $total_amount_to_refund_manually) - $cash_amount_to_refund] +if { $certificate_amount_to_reinstate < 0.01 } { # Because of rounding @@ -179,29 +204,6 @@ set billing_city "" } -append doc_body " - [ad_admin_header "Refund Totals"] - -

    Refund Totals

    - - [ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index" "Orders"] [list "one?[export_url_vars order_id]" "One"] "Refund Totals"] - -
    -
    - [export_entire_form] - [export_form_vars cash_amount_to_refund certificate_amount_to_reinstate] -
    -

    Total refund amount: [ec_pretty_price $total_amount_to_refund] (price: [ec_pretty_price $total_price_to_refund], shipping: [ec_pretty_price $total_shipping_to_refund], tax: [ec_pretty_price $total_tax_to_refund])

    -
      -
    • [ec_pretty_price $certificate_amount_to_reinstate] will be reinstated in gift certificates.
      -
    • [ec_pretty_price $cash_amount_to_refund] will be refunded to the customer's credit card.
      -
    " - -# Request the credit card number to be re-entered if it is no longer -# on file, yet there is money to refund. - -# Only ask for credit card info if credit card was used in purchase - set method [db_string method { select method from dotlrn_ecommerce_transactions @@ -220,6 +222,45 @@ } } +append doc_body " + [ad_admin_header "Refund Totals"] +$total_amount_to_refund, $total_amount_to_refund_manually, $cash_amount_to_refund, $certificate_amount_to_reinstate, [expr ($total_amount_to_refund + $total_amount_to_refund_manually) - $cash_amount_to_refund] +

    Refund Totals

    + + [ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index" "Orders"] [list "one?[export_url_vars order_id]" "One"] "Refund Totals"] + +
    + + [export_entire_form] + [export_form_vars cash_amount_to_refund certificate_amount_to_reinstate cash_amount_to_refund_cc cash_amount_to_refund_manually] +
    +

    Total refund amount: [ec_pretty_price [expr $total_amount_to_refund + $total_amount_to_refund_manually]] (price: [ec_pretty_price [expr $total_price_to_refund + $total_price_to_refund_manually]], shipping: [ec_pretty_price $total_shipping_to_refund], tax: [ec_pretty_price $total_tax_to_refund])

    +
      " + +if { $certificate_amount_to_reinstate > 0 } { + if { $method == "scholarship" } { + append doc_body "
    • [ec_pretty_price $certificate_amount_to_reinstate] will be reinstated in the scholarship fund.
      " + } else { + append doc_body "
    • [ec_pretty_price $certificate_amount_to_reinstate] will be reinstated in gift certificates.
      " + } +} + +if { $method == "cc" } { + append doc_body " +
    • [ec_pretty_price $cash_amount_to_refund_cc] will be refunded to the customer's credit card.
      " +} + +append doc_body " +
    • [ec_pretty_price $cash_amount_to_refund_manually] will be refunded to the customer manually.
      " + +append doc_body " +
    " + +# Request the credit card number to be re-entered if it is no longer +# on file, yet there is money to refund. + +# Only ask for credit card info if credit card was used in purchase + if { [empty_string_p $creditcard_number] && $cash_amount_to_refund > 0 && $method == "cc" } { append doc_body "

    Please re-enter the credit card number of the card used for this order:

    Index: openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-4-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-4-postgresql.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-4-postgresql.xql 5 Aug 2005 02:52:53 -0000 1.2 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-4-postgresql.xql 12 Aug 2005 10:10:14 -0000 1.3 @@ -8,7 +8,7 @@ insert into ec_refunds (refund_id, order_id, refund_amount, refund_date, refunded_by, refund_reasons) values - (:refund_id, :order_id, :cash_amount_to_refund, current_timestamp, :customer_service_rep,:reason_for_return) + (:refund_id, :order_id, :cash_amount_to_refund_cc, current_timestamp, :customer_service_rep,:reason_for_return) Index: openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-4.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-4.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-4.tcl 8 Aug 2005 13:10:07 -0000 1.4 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/ecommerce/items-return-4.tcl 12 Aug 2005 10:10:14 -0000 1.5 @@ -32,10 +32,13 @@ received_back_datetime reason_for_return item_id_list:notnull - price_to_refund:array + price_to_refund:array,optional + price_to_refund_manually:array shipping_to_refund:array base_shipping_to_refund cash_amount_to_refund:optional + cash_amount_to_refund_cc:optional + cash_amount_to_refund_manually:optional certificate_amount_to_reinstate creditcard_id:optional @@ -44,6 +47,12 @@ creditcard_last_four:optional } +if { ! [array exists price_to_refund] } { + foreach _item [array names price_to_refund_manually] { + set price_to_refund($_item) 0 + } +} + set method [db_string method { select method from dotlrn_ecommerce_transactions @@ -95,7 +104,7 @@ # Check if money needs to be refunded and if the credit card number is # still on file. -if { [expr $cash_amount_to_refund] > 0 && $method == "cc" } { +if { $cash_amount_to_refund > 0 && $method == "cc" } { # Make sure that all the credit card information is there. @@ -174,7 +183,7 @@ insert into ec_refunds (refund_id, order_id, refund_amount, refund_date, refunded_by, refund_reasons) values - (:refund_id, :order_id, :cash_amount_to_refund, sysdate, :customer_service_rep,:reason_for_return)" + (:refund_id, :order_id, :cash_amount_to_refund_cc, sysdate, :customer_service_rep,:reason_for_return)" foreach item_id $item_id_list { @@ -238,7 +247,7 @@ # amount can exceed the charge amount when the order was shipped # in parts and the customer returned items from various shipments. -set refund_amount $cash_amount_to_refund +set refund_amount $cash_amount_to_refund_cc while { $refund_amount > 0 && $method == "cc" } { # See if the refund matches a single charge transaction. The @@ -512,6 +521,9 @@ set refunded_date=sysdate where transaction_id=:pgw_transaction_id" append results_explanation "

    Refund transaction $pgw_transaction_id for [ec_pretty_price $transaction_amount] is complete!

    ";# + if { $cash_amount_to_refund_manually > 0 } { + append results_explanation "

    The amount [ec_pretty_price $cash_amount_to_refund_manually] is to be refunded manually

    ";# + } } } else { @@ -528,6 +540,9 @@ set page_title "No credit card refund needed." set results_explanation "No credit card refund was necessary because the entire amount was refunded to the gift certificates the customer used when purchasing the order." } +} elseif { $cash_amount_to_refund_manually > 0 } { + set page_title "Refund results" + append results_explanation "

    The amount [ec_pretty_price $cash_amount_to_refund_manually] is to be refunded manually

    ";# } else { set page_title "No credit card refund needed." set results_explanation "No credit card refund was necessary because the entire amount was refunded to the gift certificates the customer used when purchasing the order."