ad_page_contract {
@cvs-id $Id: items-return-2.tcl,v 1.1 2008/09/02 21:54:48 daveb Exp $
@author ported by Jerry Asher (jerry@theashergroup.com)
@author revised by Bart Teeuwisse (bart.teeuwisse@thecodemill.biz)
@revision-date April 2002
} {
refund_id:notnull,optional
order_id:notnull,naturalnum
{reason_for_return ""}
all_items_p:optional
item_id:optional,multiple
received_back_date:date,array,optional
received_back_time:time,array,optional
}
ad_require_permission [ad_conn package_id] admin
if { ! [info exists refund_id] } {
set refund_id [db_nextval refund_id_sequence]
}
if { [array exists received_back_date] && [array exists received_back_time] } {
set received_back_datetime $received_back_date(date)
if { [exists_and_not_null received_back_time(time)] } {
append received_back_datetime " [ec_timeentrywidget_time_check \"$received_back_time(time)\"]$received_back_time(ampm)"
} else {
append received_back_datetime " 12:00:00AM"
}
} else {
set received_back_datetime [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]
}
# The customer service rep must be logged on
set customer_service_rep [ad_get_user_id]
if {$customer_service_rep == 0} {
set return_url "[ad_conn url]?[export_entire_form_as_url_vars]"
ad_returnredirect "/register?[export_url_vars return_url]"
ad_script_abort
}
# Make sure they haven't already inserted this refund
if { [db_string get_refund_count "
select count(*)
from ec_refunds
where refund_id=:refund_id"] > 0 } {
ad_return_complaint 1 "
This refund has already been inserted into the database. Are you using an old form? Return to the order."
ad_script_abort
}
set exception_count 0
set exception_text ""
# They must have either checked "All items" and none of the rest, or
# at least one of the rest and not "All items". They also need to have
# shipment_date filled in
if { [info exists all_items_p] && [info exists item_id] } {
incr exception_count
append exception_text "
Please either check off \"All items\" or check off some of the items, but not both."
}
if { ![info exists all_items_p] && ![info exists item_id] } {
incr exception_count
append exception_text "
Please either check off \"All items\" or check off some of the items."
}
if { $exception_count > 0 } {
ad_return_complaint 1 $exception_text
ad_script_abort
}
set shipping_refund_percent [ad_parameter -package_id [ec_id] ShippingRefundPercent ecommerce]
if { ![info exists all_items_p] } {
set item_id_list $item_id
set sql [db_map all_items_select]
} else {
set sql [db_map selected_items_select]
}
# Generate a list of the items if they selected "All items" because,
# regardless of what happens elsewhere on the site (e.g. an item is
# added to the order, thereby causing the query for all items to
# return one more item), only the items that they confirm here should
# be recorded as part of this return.
if { [info exists all_items_p] } {
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
(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])