[tmp page_title]__COMPANY__ -- [L]Process Order Return[/L][/tmp] [tmp members_only]1[/tmp] @_TOP_@ [tmpn ret_num_items][/tmpn] [tmpn qty_over][/tmpn] [tmpn total_qty][/tmpn] [tmpn return_credit][/tmpn] [tmpn rma_number][/tmpn] [perl tables="orderline transactions userdb order_returns"] if(! $Values->{return_items}) { $Tag->warnings(q{ [L]No items were selected for return.[/L]
[L]Please use your browser's back button to return to the order and select at least one item from the order to return.[/L]
}); return; } my $on = $Values->{order_number}; my $tdb = $Db{transactions} or die ("No transactions DB!"); my $odb = $Db{orderline} or die ("No orderline DB!"); my $rdb = $Db{order_returns} or die ("No order_returns DB!"); my $trec = $tdb->row_hash($on); if(! $trec) { $Tag->warnings("Cannot find order $on, contact us."); return; } if($trec->{username} ne $Session->{username}) { $Tag->warnings("$on not your order! Contact us."); Log("$Session->{username} requested return $on not their order!"); return; } if($trec->{status} ne 'shipped') { $Tag->warnings("Returns can only be processed for fully-shipped orders. Contact us."); return; } my @items = split /\0/, $Values->{return_items}; my $num_items = @items; $Scratch->{ret_num_items} = $num_items; my $count = 0; my $total_credit = 0; my $total_qty = 0; my $qty_over = 0; foreach my $code (@items) { #Debug("Doing return for $code"); my $prior = $rdb->field($code, 'rma_number'); if($prior) { $Tag->warnings("Return already processed for line $code on RMA $prior! Skipping."); next; } my $rec = $odb->row_hash($code) or do { $Tag->warnings("No order entry $code!"); next; }; my $qty1 = $rec->{quantity}; my $qty2 = $Values->{"qty-$code"} or next; my $amount = $rec->{price} * $qty2; if($qty1 < $qty2) { $Tag->warnings(qq{ [L]You may not return more items than you originally purchased.[/L]
[L]Please use your browser's back to enter a more appropriate value.[/L]
}); $qty_over = 1; last; } else { #Debug("Doing record for $code"); push @done, { code => $code, nitems => $qty2, total => $amount, comment => "$qty2 returned, credit $amount", }; } $total_credit += $amount; $total_qty += $qty2; $count++; } return if $qty_over; ## Good return, now process ## Could replace with external request my $rma = $Tag->counter('etc/rma.number'); my $date = $Tag->time({ body => '%Y%m%d %H:%M:%S' }); $Scratch->{return_credit} = $total_credit; $Scratch->{total_qty} = $total_qty; $tdb->set_field($on, 'status', 'returned'); $tdb->set_field($on, 'archived', ''); foreach my $rec (@done) { #Debug("updating records for $code"); $rec->{order_number} = $on; $rec->{session} = $Session->{id}; $rec->{username} = $Session->{username}; $rec->{return_date} = $date; $rec->{rma_number} = $rma; my $code = delete $rec->{code}; my $comment = delete $rec->{comment}; $rdb->set_slice($code, $rec); $odb->set_slice($code, { status => 'returned', comment => $comment, }); } $Scratch->{rma_number} = $rma; return; [/perl] [wdisplay] [if scratch rma_number] [L PROCESS_RETURNS_PAR1]Your return has been processed. Please ship the item(s) to the address below and your account will be credited for the returned amount. A return confirmation has also been emailed to you.[/L]
[L]Be sure to list the RMA number issued below on your shipping label.[/L]

__COMPANY__ __ADDRESS__ __CITY__

[L]RMA Number[/L]: | [scratch rma_number]

[L]Order Number[/L]: | [value order_number]
[L]Number Of Items[/L]: | [scratch total_qty]
[L]Approximate Credit[/L]: | [currency][scratch return_credit][/currency]

[tmp return1] [comment] SEND REPORT OF NEW RETURN TO SHOP OWNER [/comment] [email to="__COMPANY__ <__ORDERS_TO__>" subject="__COMPANY__ - RMA: [scratch rma_number]" from="[value email] <[value email]>" reply="[value email] <[value email]>"] [L]Return request received.[/L] [L]Company[/L]: [value company] [L]Name[/L]: [value fname] [value lname] [L]Email[/L]: [value email] [L]Day Phone[/L]: [value phone_day] [L]Evening Phone[/L]: [value phone_night] [L]RMA Number[/L]: [scratch rma_number] [L]Date Issued[/L]: [tag time]%Y%m%d %H:%M:%S[/tag] [L]Order Number[/L]: [value order_number] [L]Item Quantity[/L]: [scratch total_qty] [L]Credit Amount[/L]: [currency][scratch return_credit][/currency] [/email] [/tmp] [tmp return1] [comment] SEND RETURN SUMMARY TO CUSTOMER [/comment] [email to="[value email]" subject="__COMPANY__ - RMA: [scratch rma_number]" from="__COMPANY__ <__ORDERS_TO__>" reply="__COMPANY__ <__ORDERS_TO__>"] [msg arg.0="__COMPANY__"]Hello and thank you for your interest in %s products.[/msg] [L]We have received your return request and have issued you an RMA number.[/L] [L]Please use the information below to process your return[/L]: [L]Shipping Address[/L]: __COMPANY__ __ADDRESS__ __CITY__ [L]Return Info[/L]: [L]RMA Number[/L]: [scratch rma_number] [L]Date Issued[/L]: [tag time]%Y%m%d %H:%M:%S[/tag] [L]Order Number[/L]: [value order_number] [L]Item Quantity[/L]: [scratch total_qty] [L]Credit Amount[/L]: [currency][scratch return_credit][/currency] [/email] [/tmp] [/if] @_BOTTOM_@