sunnyman's (sunnyman) wrote in changelog,
sunnyman's
sunnyman
changelog

[ljcom] r12340: LJSUP-12390: Implement statistics report...

Committer: vtroitsky
LJSUP-12390: Implement statistics reports subsystem
U   trunk/htdocs/admin/accounts/paidsummary.bml
Modified: trunk/htdocs/admin/accounts/paidsummary.bml
===================================================================
--- trunk/htdocs/admin/accounts/paidsummary.bml	2012-07-24 14:38:51 UTC (rev 12339)
+++ trunk/htdocs/admin/accounts/paidsummary.bml	2012-07-24 14:42:10 UTC (rev 12340)
@@ -88,8 +88,9 @@
     if ($pay_method && $pay_method ne '') {
         $select_payments_sql .= " AND method = '$pay_method'";
     } else {
-    # select all stuff
-    #    $select_payments_sql .= " AND method <> 'free'";
+        # TOREMOVE: After we convert old data to a new one
+        # select all free carts too
+        # $select_payments_sql .= " AND method <> 'free'";
     }
 
     if ($users eq 'anon') {
@@ -127,7 +128,6 @@
                    or $users eq 'non-cyr' and LJ::SUP->is_sup_enabled($us->{$userid});
         }
     }
-    
 
     # Get the Items for these Payments
 
@@ -147,12 +147,13 @@
             my $piid  = $row->{piid};
 
             next unless ($payments_ref->{$payid});
-
+            # TOREMOVE: After we get rid of free refunds
             if ( $payments_ref->{$payid} && $payments_ref->{$payid}{method} eq 'free' ) {
                 unless ($row->{subitem} && $row->{subitem} =~ /^commercial/) {
                     delete $payments_ref->{$payid};
-                    next;
+                    next;       # skip this item
                 }
+                # left only free items that are refunds for commercial promo
             }
             $payitems_ref->{$piid} = LJ::Pay::Payment::PayItem->new_memonly(%$row);
             $piid_dates_ref->{$piid} = $payments_ref->{$payid}->{daterecv};
@@ -161,16 +162,27 @@
         }
     }
 
-
     # Get the refund amount on a per-payment and per-item basis
 
     my $payid_refunds_ref = {};
     my $piid_refunds_ref = {};
 
     foreach my $item (values %{ $payitems_ref || {} }) {
-        if ($item->{status} eq 'refund') {
-            $piid_refunds_ref->{$item->{piid}}    = -$item->{amt};
-            $payid_refunds_ref->{$item->{payid}} += -$item->{amt};
+        if ($item->{status} eq 'refund' || $payments_ref->{$item->{payid}}{method} eq 'free' ) {
+
+            # TODO: convert all free refund items into actual refunds 
+            if ($payments_ref->{$item->{payid}}{method} eq 'free') {
+                if ($item->get_prop('selfpromo_refund')) {
+                    my $amt = $item->get_prop('selfpromo_refund') / LJ::Pay::Wallet::EXCHANGE_RATE;
+                    $piid_refunds_ref->{$item->{piid}}    = -$amt;
+                    $payid_refunds_ref->{$item->{payid}} += -$amt;
+#warn "Calendar Refund ".$item->{payid}.'/'.$item->{piid}.':'.$amt;
+                }
+            } else {
+#warn "Refund ".$item->{payid}.'/'.$item->{piid}.':'.$item->{amt};
+                $piid_refunds_ref->{$item->{piid}}    = -$item->{amt};
+                $payid_refunds_ref->{$item->{payid}} += -$item->{amt};
+            }
         }
     }
 
@@ -188,10 +200,11 @@
 
         my $piids = $payid_piids_ref->{ $row->{'payid'} };
         my @items = map { $payitems_ref->{$_} } @$piids;
-        if ( @items == 1 && $items[0]->get_item eq 'selfpromo' ) {
+        if ( @items == 1 && $items[0]->get_item eq 'selfpromo' && $payments_ref->{ $row->{'payid'} }{'method'} ne 'free' ) {
             my $it = $items[0];
             $amount -= $it->get_prop('selfpromo_refund') /
                 LJ::Pay::Wallet::EXCHANGE_RATE;
+#warn "selfpromo ".$row->{payid}." amount: $amount";
         }
 
         # Determine if the hash key is labelled as positive or negative
@@ -261,10 +274,9 @@
         my $tokens = $payments_ref->{$it->{payid}}->{method} eq 'wallet';
 
         my $amount = $it->{'amt'};
-        if ( $it->get_item eq 'selfpromo' ) {
+        if ( $it->get_item eq 'selfpromo' && $payments_ref->{ $it->{'payid'} }{'method'} ne 'free' ) {
             $amount -= $it->get_prop('selfpromo_refund') /
                 LJ::Pay::Wallet::EXCHANGE_RATE;
-
 #warn "selfpromo ".$it->{payid}." amount: $amount";
         }
 
@@ -288,6 +300,10 @@
                 $subkey = "selfpromo $sp_type $sp_country";
             }
         }
+        elsif ($item eq 'notificationpromo') {
+            $item = 'selfpromo';
+            $subkey = 'notification';
+        }
         else {
             $subkey = ( UNIVERSAL::isa($it, 'LJ::Pay::Payment::PayItem::Addon::Sized')
                           ? ((split('-', $it->{subitem}))[0] . '-')

Tags: bml, ljcom, sunnyman, vtroitsky
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