Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r11122: LJSUP-10243 (Financial reporting for sel...

Committer: ailyin
LJSUP-10243 (Financial reporting for self-promo)
U   trunk/htdocs/admin/accounts/paidsummary.bml
Modified: trunk/htdocs/admin/accounts/paidsummary.bml
===================================================================
--- trunk/htdocs/admin/accounts/paidsummary.bml	2011-10-26 15:18:58 UTC (rev 11121)
+++ trunk/htdocs/admin/accounts/paidsummary.bml	2011-10-26 15:48:07 UTC (rev 11122)
@@ -1,5 +1,6 @@
 <?_code
 {
+#line 3
     use strict;
     use vars qw(%GET);
     use LJ::TimeUtil;
@@ -173,28 +174,38 @@
     # Iterate over payments
     foreach my $row (sort { $a->{payid} <=> $b->{payid} } values %{ $payments_ref || {} }) {
 
+        my $amount = $row->{'amount'};
+
+        my $piids = $payid_piids_ref->{ $row->{'payid'} };
+        my @items = map { $payitems_ref->{$_} } @$piids;
+        if ( @items == 1 && $items[0]->get_item eq 'selfpromo' ) {
+            my $it = $items[0];
+            $amount -= $it->get_prop('selfpromo_refund') /
+                LJ::Pay::Wallet::EXCHANGE_RATE;
+        }
+
         # Determine if the hash key is labelled as positive or negative
-        my $ctkey  = $row->{amount} >= 0 ? 'cnt_pos' : 'cnt_neg';
-        my $amtkey = $row->{amount} >= 0 ? 'amt_pos' : 'amt_neg';
+        my $ctkey  = $amount >= 0 ? 'cnt_pos' : 'cnt_neg';
+        my $amtkey = $amount >= 0 ? 'amt_pos' : 'amt_neg';
 
         # Get the date and refund amount
         my $date = substr($row->{daterecv}, 0, 10);
         my $refund = $payid_refunds_ref->{$row->{payid}};
-        my $tokens = $row->{method} eq 'wallet' ? $row->{amount} : 0;
+        my $tokens = $row->{method} eq 'wallet' ? $amount : 0;
 
         # Update the overall stats, as well as the daily stats
         foreach my $s (\%stats, $stats{daily}->{$date}) {
             # Overall/Daily Stats
             $s->{$ctkey}++;
-            $s->{amount}  += $row->{amount};
-            $s->{$amtkey} += $row->{amount};
+            $s->{amount}  += $amount;
+            $s->{$amtkey} += $amount;
             $s->{refund}  += $refund;
             $s->{tokens}  += $tokens;
 
             # Method Breakout Stats for HTML output
             $s->{method}->{$row->{method}}->{$ctkey}++;
-            $s->{method}->{$row->{method}}->{$amtkey} += $row->{amount};
-            $s->{method}->{$row->{method}}->{amount}  += $row->{amount};
+            $s->{method}->{$row->{method}}->{$amtkey} += $amount;
+            $s->{method}->{$row->{method}}->{amount}  += $amount;
             $s->{method}->{$row->{method}}->{tokens}  += $tokens;
             $s->{method}->{$row->{method}}->{refund}  += $refund if $refund;
         }
@@ -239,6 +250,12 @@
         my $refund = $piid_refunds_ref->{$it->{piid}};
         my $tokens = $payments_ref->{$it->{payid}}->{method} eq 'wallet';
 
+        my $amount = $it->{'amt'};
+        if ( $it->get_item eq 'selfpromo' ) {
+            $amount -= $it->get_prop('selfpromo_refund') /
+                LJ::Pay::Wallet::EXCHANGE_RATE;
+        }
+
         # find item and subitem key strings
         my $item = $it->{item};
         my $subkey;
@@ -246,7 +263,7 @@
             $subkey = $it->{subitem};
         }
         elsif ($item eq 'coupon') {
-            $subkey = $it->{amt};
+            $subkey = $amount;
         }
         else {
             $subkey = ( UNIVERSAL::isa($it, 'LJ::Pay::Payment::PayItem::Addon::Sized')
@@ -257,17 +274,17 @@
 
         # $subkey = 'zero' if $subkey == 0; 
 
-        my $ctkey  = $it->{amt} >= 0 ? 'cnt_pos' : 'cnt_neg';
-        my $amtkey = $it->{amt} >= 0 ? 'amt_pos' : 'amt_neg';
+        my $ctkey  = $amount >= 0 ? 'cnt_pos' : 'cnt_neg';
+        my $amtkey = $amount >= 0 ? 'amt_pos' : 'amt_neg';
         my $date = substr($piid_dates_ref->{$it->{piid}}, 0,10);
 
         # Update Daily stats
         foreach my $s ($stats{daily}->{$date}->{item}->{$item}) {
             foreach my $ssub ($s, $s->{sub}->{$subkey}) {
                 $ssub->{$ctkey}++;
-                $ssub->{$amtkey} += $it->{amt};
-                $ssub->{amount}  += $it->{amt};
-                $ssub->{tokens}  += $it->{amt} if $tokens;
+                $ssub->{$amtkey} += $amount;
+                $ssub->{amount}  += $amount;
+                $ssub->{tokens}  += $amount if $tokens;
                 $ssub->{refund}  += $refund if $refund;
             }
         }
@@ -279,9 +296,9 @@
             foreach my $ssub ($s, $s->{sub}->{$subkey}) {
                 foreach my $recurring ($recur, 'Total') {
                     $ssub->{$recurring}->{$ctkey}  ++;
-                    $ssub->{$recurring}->{$amtkey} += $it->{amt};
-                    $ssub->{$recurring}->{amount}  += $it->{amt};
-                    $ssub->{$recurring}->{tokens}  += $it->{amt} if $tokens;
+                    $ssub->{$recurring}->{$amtkey} += $amount;
+                    $ssub->{$recurring}->{amount}  += $amount;
+                    $ssub->{$recurring}->{tokens}  += $amount if $tokens;
                     $ssub->{$recurring}->{refund}  += $refund if $refund;
                 }
             }

Tags: ailyin, andy, bml, ljcom
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments