예제 #1
0
 public function csv_statementAction()
 {
     $this->setInvokeArg('noViewRenderer', true);
     if (JO_Session::get('user_id')) {
         $data = array();
         $statements = Model_Orders::getStatement(JO_Session::get('user_id'));
         if ($statements) {
             $month = $statements[0]['month'];
             $data[] = array(ucfirst($this->translate('Date')), $this->translate('Type'), $this->translate('Amount'), $this->translate('Details'));
             $st = array();
             $cnt = count($statements);
             for ($i = 0; $i < $cnt; $i++) {
                 if ($statements[$i]['type'] == 'deposit') {
                     $statements[$i]['price'] = WM_Currency::normalize($statements[$i]['price']);
                     $statements[$i]['details'] = $this->translate('Deposit money');
                 } elseif ($statements[$i]['type'] == 'withdraw') {
                     $statements[$i]['price'] = WM_Currency::normalize(-$statements[$i]['price']);
                     $statements[$i]['details'] = $this->translate('Earning money');
                 } elseif ($statements[$i]['type'] == 'order') {
                     if ($statements[$i]['user_id'] == JO_Session::get('user_id')) {
                         $statements[$i]['type'] = $this->translate('buy');
                         $statements[$i]['price'] = WM_Currency::normalize($statements[$i]['price']);
                     } else {
                         $statements[$i]['type'] = $this->translate('sale');
                         $statements[$i]['price'] = WM_Currency::normalize($statements[$i]['receive']);
                     }
                     $statements[$i]['details'] = $statements[$i]['item_name'];
                 } elseif ($statements[$i]['type'] == 'referrals') {
                     if ($statements[$i]['item_name'] == 1) {
                         $statements[$i]['details'] = $this->translate('Referral / deposit');
                     } else {
                         $statements[$i]['details'] = $this->translate('Referral / sale');
                     }
                     $statements[$i]['price'] = WM_Currency::normalize($statements[$i]['price']);
                 } elseif ($statements[$i]['type'] == 'membership') {
                     $statements[$i]['price'] = WM_Currency::format($statements[$i]['price']);
                     $statements[$i]['details'] = $this->translate('Membership money');
                 }
                 $st[] = array($statements[$i]['day'], $statements[$i]['type'], $statements[$i]['price'], $statements[$i]['details']);
                 if (isset($statements[$i + 1]['month']) && $month != $statements[$i + 1]['month']) {
                     $st[] = array('month' => $statements[$i]['month']);
                     $month = $statements[$i + 1]['month'];
                 } elseif ($i == $cnt - 1) {
                     $st[] = array('month' => $statements[$i]['month']);
                 }
             }
         }
         $st = array_reverse($st);
         $data = array_merge($data, $st);
         $csv = new Helper_CSVWriter($data);
         $csv->headers(JO_Session::get('firstname') . '_' . JO_Session::get('lastname') . '_' . $this->translate('Statement'));
         $csv->output();
     }
     die;
 }