public function csv_earningsAction() { $this->setInvokeArg('noViewRenderer', true); if (JO_Session::get('user_id')) { $data = array(); $earnings = Model_Orders::getEarnings(JO_Session::get('user_id')); $total_f = 0; $total_clicks_f = $total_registred_f = $total_deposits_f = $total_earnings_f = $total_f = 0; if ($earnings) { $data = array(array($this->translate('Referrals')), array($this->translate('Month'), $this->translate('Clickthoughs'), $this->translate('Registered'), $this->translate('Deposits'), $this->translate('Earnings'))); foreach ($earnings as $earning) { $total_clicks_f += $earning['gast']; $total_registred_f += $earning['register']; $total_deposits_f += $earning['deposit']; $total_earnings_f += $earning['sales']; $earning['sales'] = WM_Currency::normalize($earning['sales']); $data[] = array($earning['date'], $earning['gast'], $earning['register'], $earning['deposit'], $earning['sales']); } $total_f += $total_earnings_f; $total_earnings_f = WM_Currency::normalize($total_earnings_f); $data[] = array($this->translate('Totals'), $total_clicks_f, $total_registred_f, $total_deposits_f, $total_earnings_f); } $sales = Model_Orders::getSalesByUser(JO_Session::get('user_id')); $sales_f = array(); if ($sales) { $data[] = array($this->translate('Sales')); $data[] = array($this->translate('Month'), $this->translate('Sales'), $this->translate('Earnings')); $month = $sales[0]['month']; $total_sales = $total_earnings = $total_sales_cnt_f = $total_earnings_cnt_f = 0; $cnt = count($sales); for ($i = 0; $i < $cnt; $i++) { $total_sales += $sales[$i]['sales']; $total_earnings += $sales[$i]['earnings']; $sales[$i]['earnings'] = WM_Currency::normalize($sales[$i]['earnings']); $sales_f[] = array($sales[$i]['day'], $sales[$i]['sales'], $sales[$i]['earnings']); if (isset($sales[$i + 1]['month']) && $month != $sales[$i + 1]['month']) { $sales_f[] = array($sales[$i]['month'], $total_sales, WM_Currency::normalize($total_earnings)); $total_sales_cnt_f += $total_sales; $total_earnings_cnt_f += $total_earnings; $total_f += $total_earnings; $total_sales = $total_earnings = 0; $month = $sales[$i + 1]['month']; } elseif ($i + 1 == $cnt) { $sales_f[] = array($sales[$i]['month'], $total_sales, WM_Currency::normalize($total_earnings)); $total_sales_cnt_f += $total_sales; $total_earnings_cnt_f += $total_earnings; $total_f += $total_earnings; } } } $sales_f = array_reverse($sales_f); $data = array_merge($data, $sales_f); $data[] = array($this->translate('Totals'), $total_sales_cnt_f, WM_Currency::normalize($total_earnings_cnt_f)); $data[] = array($this->translate('Total Earnings'), WM_Currency::normalize($total_f)); $csv = new Helper_CSVWriter($data); $csv->headers(JO_Session::get('firstname') . '_' . JO_Session::get('lastname') . '_' . $this->translate('Earnings')); $csv->output(); } die; }