[ic] My version of removing an item from an existing order and recalculating totals

Tim Good draco at edsd.com
Sat May 22 12:11:58 EDT 2004

Hello List,

I am slowly prodding along on a customization of interchange 
for a party rental business. As I move along I would like to
share my development in the event it may help others. 

I have seen other posts asking how to remove items from an
existing order. The interface in Edit Order was a little 
clunky and manual for me and my customer, so I developed this
little ditty. Please keep in mind some fields and variables 
used are for the delivery scheduling and party rental modules.
I still need to insert error checking on sql result returns.
Any feedback there is greatly appreciated. I would eventually 
like to return error codes instead of unused data. Also this has been 
tested on my environment only. 
(MySQL 3.23.58 on Redhat 8.0 non threaded Perl 5.8.2 interchange 5.2
I am using this tag within the order_view page in the Admin UI
Well here it is:

UserTag delitem Order curo delitem
UserTag delitem PosNumber 2
UserTag delitem Interpolate 1
UserTag delitem Documentation <<EOF


This tag uses the delitem(1) command to remove an orderline item form 
an existing order. This tag also recalculates the totals for the order.


    curo=current order number
    delitem=item to be remove from order and orderline table.


    <form name="deleteitem" action="[process]" method=post>
    <input type=hidden name=mv_session_id value="[data session id]">
    <input type=hidden name=mv_action value=back>
    <input type=hidden name=order value="[loop-data transactions
    <input type=hidden name=mv_nextpage value="@@MV_PAGE@@">

       [button text='delete' src='delsm.gif' hidetext=1 confirm="Are you
sure you want to this item?" form='deleteitem']
           mv_click='[delitem curo="[loop-code]" delitem="[sql-param

where loop-data is from [loop list="[value-extended order]"] (like in
order_view.html file) and 
sql-param is from [query list=1 table=orderline sql="select * from
orderline where order_number = '[loop-code]'"].
This would create a small image link to remove the respective item from
list of items in order.



UserTag delitem Routine <<EOR
sub {
        my ($curo,$delitem) = @_;

        my ($sql, $results, $deliteminfo, $orderinfo, $itemsub,
$iteminstall, $totcst, $numitems, $col_name_hashref,

        $sql = "select subtotal, install_chrg, quantity from orderline
where order_number = $curo and sku = $delitem";
        ($deliteminfo, $col_name_hashref, $col_name_arrayref) =
$Tag->query({ table=>'orderline', sql=>$sql, wantarray=>1 });

        $sql = "delete from orderline where order_number = $curo and sku
= $delitem";
        ($results, $col_name_hashref, $col_name_arrayref) =
$Tag->query({ table=>'orderline', sql=>$sql, wantarray=>1 });

        $sql = "select total_cost, nitems from transactions where
order_number = $curo";
        ($orderinfo, $col_name_hashref, $col_name_arrayref) =
$Tag->query({ table=>'transactions', sql=>$sql, wantarray=>1 });

        $totcst = $orderinfo->[0]->[0];
        $numitems -= $orderinfo->[0]->[1];
        $itemsub = $deliteminfo->[0]->[0];
        $iteminstall = $deliteminfo->[0]->[1];
        $totcst -= $itemsub + $iteminstall;

        $sql = "update transactions set total_cost = $totcst,nitems =
$numitems where order_number = $curo";
        ($results, $col_name_hashref, $col_name_arrayref) =
$Tag->query({ table=>'transactions', sql=>$sql, wantarray=>1 });

        return "order=$curo item=$delitem";


Hope this helps someone,

Tim Good

More information about the interchange-users mailing list