forked from dtbaker/envato-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commission-split.php
179 lines (156 loc) · 6.13 KB
/
commission-split.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
*
* Very Basic Envato Commission Split Calculator
* Version 0.01
*
* Instructions!
*
* Change the values in the configuration area below.
* Upload these files to your website.
* Visit this script in your browser with the item id in the url, like this:
* http://yourwebsite.com/commission-splits.php?item_id=12345678
* Enter the envato recaptcha code if needed.
* Send this URL to the other author so they can track sales and their expected commissions.
* Yew!
*
*
*/
/** START CONFIGURATION AREA **/
// warning: make sure your server is secure before using this.
// this script makes use of features that are not possible with the Envato API, so an account password is required.
define('_ENVATO_USERNAME','your_envato_username');
define('_ENVATO_PASSWORD','your_envato_password');
$splits = array(
12345678 => array( // REPLACE THIS WITH THE ITEM ID YOU WISH TO CALCULATE COMMISSION SPLITS ON
'start_date' => '2/2013', // WHAT MONTH TO START COMMISSION CALCULATIONS FROM ( in m/Y format, eg: 1/2012 or 12/2011 )
'authors' => array(
'your_author_name_here' => array(
'split' => 0.5, // percentage here (eg: 50% is 0.5)
'total' => 0,
),
'other_author_name_here' => array(
'split' => 0.5, // percentage here (eg: 50% is 0.5)
'total' => 0,
),
// add more authors here if you need to split 3 or more ways.
),
),
// add more item configurations here if needed.
);
/** END CONFIGURATION AREA **/
$item_id = isset($_REQUEST['item_id']) ? (int)$_REQUEST['item_id'] : false;
if(!$item_id || !isset($splits[$item_id]))exit;
require_once 'class.envato_scraper.php';
$my_scraper = new envato_scraper();
$my_scraper->do_login(_ENVATO_USERNAME,_ENVATO_PASSWORD);
$statement = $my_scraper->get_statement($splits[$item_id]['start_date']);
$menu_months = array();
foreach($statement as $item){
if(isset($item['item_id']) && $item['item_id'] == $item_id){
$key = date('Y/m',$item['time']);
if(!isset($menu_months[$key]))$menu_months[$key] = array(
'sales'=> array(),
'label'=>date('F Y',$item['time']),
);
$menu_months[$key]['sales'][] = $item;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Commission Split</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
@media (max-width: 980px) {
/* Enable use of floated navbar text */
.navbar-text.pull-right {
float: none;
padding-left: 5px;
padding-right: 5px;
}
}
</style>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">Commission Split</a>
<div class="nav-collapse collapse">
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Months</li>
<?php foreach($menu_months as $key=>$menu_month){ ?>
<li><a href="#month<?php echo $key;?>"><?php echo $menu_month['label'];?></a></li>
<?php } ?>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<div class="hero-unit">
<h2>Commission Split Calculator!</h2>
<ul>
<?php foreach($splits[$item_id]['authors'] as $author_id => $split_data){ ?>
<li>
<?php echo $author_id;?> gets <?php echo $split_data['split']*100;?>%
</li>
<?php } ?>
</ul>
</div>
<div class="row-fluid">
<?php foreach($menu_months as $key=>$menu_month){
$month_totals = array();
?>
<h2 class="page-header" id="#month<?php echo $key;?>"><?php echo $menu_month['label'];?></h2>
<ul>
<?php foreach($menu_month['sales'] as $item){
foreach($splits[$item_id]['authors'] as $author_id => $split_data){
if(!isset($month_totals[$author_id]))$month_totals[$author_id]=0;
$month_totals[$author_id]+= $item['earnt'] * $split_data['split'];
$splits[$item_id]['authors'][$author_id]['total'] += $item['earnt'] * $split_data['split'];
}
?>
<li>
<?php echo date('Y-m-d H:i:s',$item['time']);?> sold for $<?php echo $item['amount'];?> at rate of <?php echo $item['rate'];?>% earning a total of <strong>$<?php echo $item['earnt'];?></strong>.
</li>
<?php } ?>
<?php foreach($month_totals as $author_id => $total){ ?>
<li><strong><?php echo $author_id;?> earnt $<?php echo $total;?></strong></li>
<?php } ?>
</ul>
<?php } ?>
</div><!--/row-->
</div><!--/span-->
</div><!--/row-->
<hr>
</div><!--/.fluid-container-->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</body>
</html>