package IIe9611a9ba6126d2cc60c1b57d182f68b; use base qw/II720d6e18aa34327713eb014408fc9144/; use strict 'vars'; use Archive::Zip qw/AZ_OK/; use File::Temp qw/tempfile/; use IIa67e09caf104f2e50322b7bc59b766fb; use II8b55f24974af3d53369c3d9cea404f55::filters::text2xml; use IIbbd7c6cf33a8b724d5937c621b455d05; use IIf404c8dfc046e4729558b9aff233579c; use II1d17f4bae0cdcee9878216ee8bd5ec5d; BEGIN{*IIe9611a9ba6126d2cc60c1b57d182f68b::llllIlIlIlIlllII=\%{pack('H6','017613')^'D8E'};*IIe9611a9ba6126d2cc60c1b57d182f68b::lIllIlIlIIIlIIII=\&{pack('H24','525c58507473350b7e522c0c')^'?=1>NIF3I0T8'};$IIe9611a9ba6126d2cc60c1b57d182f68b::lllIIIIIllIlllll=pack('H18','786d0501147c1b6c6d')^'09QQK4T?9';$IIe9611a9ba6126d2cc60c1b57d182f68b::lIllIlIIllIlIlll=pack('H12','7d05761f7211')^'7L8S;R'};sub mnt { my ($class, $C) = @_; my $in = $C->{INPUT}; if ($in->{export}) { $class->mnt_export($C); } elsif ($in->{load}) { $class->mnt_load($C); } return; } BEGIN{*IIe9611a9ba6126d2cc60c1b57d182f68b::llIlIlllIlIIIlIl=\%{pack('H6','77036d')^'2M;'};*IIe9611a9ba6126d2cc60c1b57d182f68b::lIIlIIIlIlIIllIl=\&{pack('H24','5136523f0b0c39737557347b')^'<W;Q16JKB5LO'};$IIe9611a9ba6126d2cc60c1b57d182f68b::IllllIIlllIlIllI=pack('H18','1a026d090904051d0d')^'RV9YVLJNY';$IIe9611a9ba6126d2cc60c1b57d182f68b::IIIlIlllIllIlIll=pack('H12','7d7119077e76')^'78WK75'};sub mnt_export { my ($class, $C) = @_; my $in = $C->{INPUT}; for my $f (qw/date_from date_to/) { $in->{$f} = $in->{$f} =~ /^(\d{2})\.(\d{2})\.(\d{4})$/ ? "$3\-$2\-$1" : ''; } my @where; if ($in->{status}) { if ($in->{status} eq 'paid') { push @where, paid_only => 1; } elsif ($in->{status} eq 'unpaid') { push @where, paid_no => 1, cancelled => 0; } elsif ($in->{status} eq 'payable') { push @where, paid_no => 1, payable_only => 1, cancelled => 0; } } push @where, made_after => $in->{date_from} if $in->{date_from}; push @where, made_until => $in->{date_to} if $in->{date_to}; push @where, packs => $in->{pack_ids} if $in->{pack_ids}; push @where, prods => $in->{prod_ids} if $in->{prod_ids}; my @aff_ids; if ($in->{aff_ids}) { @aff_ids = split ',', $in->{aff_ids}; } else { @aff_ids = IIa67e09caf104f2e50322b7bc59b766fb::IIllllllllIllIII($IIa67e09caf104f2e50322b7bc59b766fb::llIIlIIlIlIlllIl{$IIe9611a9ba6126d2cc60c1b57d182f68b::lllIIIIIllIlllll},121,$IIa67e09caf104f2e50322b7bc59b766fb::llIIlIIlIlIlllIl{$IIbbd7c6cf33a8b724d5937c621b455d05::lllIlIlIlIIlIlII})->enum(FETCH => 'distinct ben_user_id', @where); } my $admin = IIbbd7c6cf33a8b724d5937c621b455d05::llIllIIlIIIlllIl($II720d6e18aa34327713eb014408fc9144::llIlIIIlIlIlIlIl{$II1d17f4bae0cdcee9878216ee8bd5ec5d::IIIIlIlllIIlllll},47,$II720d6e18aa34327713eb014408fc9144::llIlIIIlIlIlIlIl{$II1d17f4bae0cdcee9878216ee8bd5ec5d::lIIIIlIIIlIlllll})->getAdmin; my ($addXml, $xml); my $xmlenc = sub { II8b55f24974af3d53369c3d9cea404f55::filters::text2xml::text2xml(shift); }; $addXml = sub { my ($templ, $ctx) = @_; $templ =~ s/\[(\w+)\]/&$xmlenc($ctx->{$1})/ge; $xml .= $templ; return; }; &$addXml('<?xml version="1.0" encoding="utf-8"?>
<FantasosExportCommissionsData>
<owner> <id>[id]</id> <email>[email]</email> <fname>[fname]</fname> <lname>[lname]</lname> <name>[name]</name> <address>[address]</address> <city>[city]</city> <state>[state]</state> <zipcode>[zipcode]</zipcode> <country>[country]</country> <url>[url]</url> <company>[company]</company> <phone>[phone]</phone> </owner>
', $admin);	
&$addXml('	<selection> <date_from>[date_from]</date_from> <date_to>[date_to]</date_to> <aff_ids>[aff_ids]</aff_ids> <prod_ids>[prod_ids]</prod_ids> <pack_ids>[pack_ids]</pack_ids> <notes>[notes]</notes> </selection> <affiliates>
', $in);	
for my $aff_id (@aff_ids) { my $affiliate = IIe9611a9ba6126d2cc60c1b57d182f68b::lIllllIllllllllI($IIe9611a9ba6126d2cc60c1b57d182f68b::llIlIlllIlIIIlIl{$II1d17f4bae0cdcee9878216ee8bd5ec5d::IIIIlIlllIIlllll},114,$IIe9611a9ba6126d2cc60c1b57d182f68b::llIlIlllIlIIIlIl{$II1d17f4bae0cdcee9878216ee8bd5ec5d::IIIIlIlIlIlIIlIl})->get($aff_id); my $comms = IIf404c8dfc046e4729558b9aff233579c::IllIllIIIlIllIIl($IIe9611a9ba6126d2cc60c1b57d182f68b::llllIlIlIlIlllII{$IIf404c8dfc046e4729558b9aff233579c::IIIIllIIlIlIllll},121,$IIe9611a9ba6126d2cc60c1b57d182f68b::llllIlIlIlIlllII{$II1d17f4bae0cdcee9878216ee8bd5ec5d::IIIIlIlIlIlIIlIl})->search(@where, ben_user_id => $aff_id, ORDER => 'id'); my $total = 0; $total += $_->{amount} for @$comms; $affiliate->{total_comms} = II1d17f4bae0cdcee9878216ee8bd5ec5d::IIIIlIllIllIIlIl($II1d17f4bae0cdcee9878216ee8bd5ec5d::llllIllIIllIIllI{$IIf404c8dfc046e4729558b9aff233579c::IIIIllllIllIIIIl},81,$II1d17f4bae0cdcee9878216ee8bd5ec5d::llllIllIIllIIllI{$IIbbd7c6cf33a8b724d5937c621b455d05::IIllIIIlllIIIIll})->normalizeAmount($total); &$addXml('		<affiliate id="[id]"> <email>[email]</email> <fname>[fname]</fname> <lname>[lname]</lname> <name>[name]</name> <address>[address]</address> <city>[city]</city> <state>[state]</state> <zipcode>[zipcode]</zipcode> <country>[country]</country> <url>[url]</url> <company>[company]</company> <phone>[phone]</phone> <paypal_email>[paypal_email]</paypal_email> <commissions> <total>[total_comms]</total>
', $affiliate);
for my $c (@$comms) { &$addXml('				<commission id="[id]"> <ctime>[ctime]</ctime> <type>[type]</type> <descr>[descr]</descr> <amount>[amount]</amount> <tier>[tier]</tier> <sale_id>[sale_id]</sale_id> </commission>
', $c);
} &$addXml('			</commissions> </affiliate>
', {});
} &$addXml('	</affiliates> <notes>[notes]</notes>
</FantasosExportCommissionsData>
', { notes => $in->{notes} });
my $zip = Archive::Zip->new(); my $filename = "export_commissions_" . IIbbd7c6cf33a8b724d5937c621b455d05::llIllIIlIIIlllIl($IIe9611a9ba6126d2cc60c1b57d182f68b::llIlIlllIlIIIlIl{$IIe9611a9ba6126d2cc60c1b57d182f68b::IllllIIlllIlIllI},1010,$IIe9611a9ba6126d2cc60c1b57d182f68b::llIlIlllIlIIIlIl{$II720d6e18aa34327713eb014408fc9144::llIlIIIIIIlIIIIl})->new->format('%Y%m%d%H%M%S'); my $member = $zip->addString($xml, "$filename.xml"); $member->desiredCompressionLevel(9); print "Content-Type: application/zip; name=\"$filename.zip\"\n"; print "Content-Disposition: attachment; filename=\"$filename.zip\"\n\n"; $zip->writeToFileHandle(\*STDOUT); Zen->getRequest->finish; return; } BEGIN{*IIe9611a9ba6126d2cc60c1b57d182f68b::IIllIllIIlIlllll=\%{pack('H6','15770e')^'P9X'};*IIe9611a9ba6126d2cc60c1b57d182f68b::lIllllIllllllllI=\&{pack('H24','3735302b686b3d680e33476d')^'ZTYERQNP9Q?Y'};$IIe9611a9ba6126d2cc60c1b57d182f68b::IIIlIIlIllIlllIl=pack('H18','08180200060d0a0b6f')^'@LVPYEEX;';$IIe9611a9ba6126d2cc60c1b57d182f68b::lllIllIIIlllIIII=pack('H12','717c19037e77')^';5WO74'};sub mnt_load { my ($class, $C) = @_; my $in = $C->{INPUT}; return unless $in->{file}; my ($ext) = $in->{file}{fname} =~ /\.(\w+)$/; my $ext = lc($ext); my $data; if ($ext eq 'zip') { my ($zipFH, $zipFile) = tempfile(); binmode $zipFH; print $zipFH $in->{file}{data}; close $zipFH; my $zip = Archive::Zip->new($zipFile); my $found = 0; for my $memberName ($zip->memberNames) { if ($memberName =~ /\.xml$/i) { $found = 1; $data = $zip->contents($memberName); } } unless ($found) { $C->{ErrorLoadZipNoXML} = 1; return; } unlink $zipFile; } elsif ($ext eq 'xml') { $data = $in->{file}{data}; } else { $C->{ErrorLoadExt} = 1; return; } delete $in->{file}; my $idlist = join ', ', ($data =~ /<commission\s+id="(\d+)">/gi); my $dbc = IIf404c8dfc046e4729558b9aff233579c::IllIllIIIlIllIIl($IIf404c8dfc046e4729558b9aff233579c::IIlIllIIIIlllIlI{$IIa67e09caf104f2e50322b7bc59b766fb::llIlIIIlIllIIIll},121,$IIf404c8dfc046e4729558b9aff233579c::IIlIllIIIIlllIlI{$II720d6e18aa34327713eb014408fc9144::IlIIllIlllllIIll})->dbc; $dbc->do("update jin_commission set paid=1,paid_tstamp=now() where id in ($idlist)") if $idlist; $C->{LoadedCommissions} = $idlist; return; } 1; 