Q:

How can show custom discount after shipping row in cart?

I am giving my customer a extra discount. For that I am using this code
<?php 

class Karmick_Refer_Model_Cart_Discount extends Mage_Sales_Model_Quote_Address_Total_Abstract {

    public function collect(Mage_Sales_Model_Quote_Address $address) {
        $referBlock = new Karmick_Refer_Block_Refer();
        if(Mage::getSingleton('customer/session')->isLoggedIn()){
         $customer_data=Mage::getSingleton('customer/session')->getCustomer();
                $referCustomerData = $referBlock->getUserByCode($customer_data->getId());
                $discount = (float)$referCustomerData->getWalletAmount();
                //$subTotal = Mage::helper('checkout/cart')->getQuote()->getSubtotal();
                 $baseTotals = array_sum($address->getAllBaseTotalAmounts());
                if((float)$baseTotals <= $discount){
                    $discount = (float)$baseTotals;
                }
        if($discount != '' && $discount != (float)'0.00')
        {
            if ($address->getData('address_type') == 'billing')
                return $this;
              //your discount percent
                $grandTotal = $address->getGrandTotal();
                $baseGrandTotal = $address->getBaseGrandTotal();
                $totals = array_sum($address->getAllTotalAmounts());
                $baseTotals = array_sum($address->getAllBaseTotalAmounts());

                $formattedPrice = Mage::helper('core')->currency($discount, false, false);
                $discount = $formattedPrice;
                $address->setFeeAmount(- $discount);
                $address->setBaseFeeAmount(- $discount);

                $address->setGrandTotal($grandTotal + $address->getFeeAmount());
                $address->setBaseGrandTotal($baseGrandTotal + $address->getBaseFeeAmount());
        }
        }
        return $this;
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address) {

        $referBlock = new Karmick_Refer_Block_Refer();
          $customer_data=Mage::getSingleton('customer/session')->getCustomer();
                $referCustomerData = $referBlock->getUserByCode($customer_data->getId());
                $discount = (float)$referCustomerData->getWalletAmount();
        if($discount != '' && $discount != (float)'0.00'):
        $amt = $address->getFeeAmount();
        $address->addTotal(array(
                'code'=>$this->getCode(),
                'title'=>Mage::helper('catalog')->__('Successfull Referral Discount'),
                'value'=> $amt
        ));
        endif;
        return $this;
    }

}

?> 

And this is working properly.
But the place of viewing the discount is wrong

How can i show it after shipping cost row??

A:

After a long search i found a solution for this.
First go to 

Admin -> System -> Config -> Sales -> Checkout Totals Sort Order

There i see all row shorting order

When i change discount to 30 and shippng to 20. And i get my result.
Hope this will help someone to solve his problem too. Happy Learning.

