Exemplo n.º 1
0
 public static function getFullDetailed($poster)
 {
     $prices = Prices::getList(array('afisha_id' => $poster->id));
     if ($prices->count() == 0) {
         return null;
     }
     $pricesIdArr = array();
     foreach ($prices as $price) {
         $pricesIdArr[] = $price->id;
     }
     $orders = Orders::getList(array('afisha_id' => $poster->id));
     $seats = Seats::getList(array('price_id_in' => $pricesIdArr, 'group_by' => 'view_key'));
     $seatsArrVKey = array();
     foreach ($seats as $seat) {
         $seatsArrVKey[] = $seat->view_key;
     }
     $seatsNames = Afisha::getMapSeats($poster->filename, $seatsArrVKey);
     $adminBrone = array();
     $siteBrone = array();
     $residue = array();
     foreach ($seats as $key => $seat) {
         $findedInOrders = false;
         //            Search in orders
         foreach ($orders as $order) {
             $orderSeats = array_filter(explode(',', $order->seats_keys));
             if (in_array($seat->view_key, $orderSeats)) {
                 $findedInOrders = true;
                 //                    Admin brone
                 if ($order->admin_brone == 1) {
                     $adminBrone[$seatsNames[$seat->view_key]['row']][] = $seatsNames[$seat->view_key]['seat'];
                 } elseif ($order->status != 'success' && $order->created_at > time() - Config::get('reserved_days') * 24 * 60 * 60) {
                     $siteBrone[$seatsNames[$seat->view_key]['row']][] = $seatsNames[$seat->view_key]['seat'];
                 } elseif ($order->status != 'success' && $order->created_at < time() - Config::get('reserved_days') * 24 * 60 * 60) {
                     $residue[$seatsNames[$seat->view_key]['row']][] = $seatsNames[$seat->view_key]['seat'];
                 }
             }
         }
         if ($findedInOrders == false) {
             $residue[$seatsNames[$seat->view_key]['row']][] = $seatsNames[$seat->view_key]['seat'];
         }
     }
     return array('adminBrone' => $adminBrone, 'siteBrone' => $siteBrone, 'residue' => $residue);
 }
Exemplo n.º 2
0
 function indexAction()
 {
     if (User::info()->role_id != 2 && User::info()->see_all_cashier_stat == 0) {
         HTTP::redirect('/backend/cassier/inner/' . User::info()->id);
     }
     //            Set filter vars
     $date_s = NULL;
     $date_po = NULL;
     $status = NULL;
     $eventId = null;
     $creatorId = null;
     if (Arr::get($_GET, 'date_s')) {
         $date_s = strtotime(Arr::get($_GET, 'date_s'));
     }
     if (Arr::get($_GET, 'date_po')) {
         $date_po = strtotime(Arr::get($_GET, 'date_po'));
     }
     if (isset($this->pay_statuses[Arr::get($_GET, 'status')])) {
         $status = Arr::get($_GET, 'status', 1);
     }
     if (Arr::get($_GET, 'status') == 'null') {
         $status = 'null';
     }
     if (Arr::get($_GET, 'event') != 0) {
         $eventId = Arr::get($_GET, 'event');
     }
     if (Arr::get($_GET, 'creator_id') != 0) {
         $creatorId = Arr::get($_GET, 'creator_id');
     }
     if (User::info()->role_id != 2 && User::info()->see_all_cashier_stat == 0) {
         $creatorId = User::info()->id;
     }
     //            Select all admins
     $cassiers = DB::select($this->tablename . '.*', array('users_roles.name', 'role_name'))->from($this->tablename)->join('users_roles')->on('users_roles.id', '=', $this->tablename . '.role_id')->where('users_roles.alias', '!=', 'user')->where($this->tablename . '.status', '=', 1);
     if ($creatorId) {
         $cassiers->where($this->tablename . '.id', '=', $creatorId);
     }
     $cassiers = $cassiers->find_all();
     $totalCntOrders = DB::select(array(DB::expr('COUNT(*)'), 'count'))->from('afisha_orders')->where('creator_id', '!=', null)->where('payer_id', '!=', null);
     $this->setFilter($totalCntOrders, $date_s, $date_po, $status, $eventId, $creatorId, 'afisha_orders');
     $totalCntOrders = $totalCntOrders->count_all();
     $totalOrdersPrice = 0;
     $totalOrdersPriceQuery = DB::select()->from('afisha_orders')->where('creator_id', '!=', null)->where('payer_id', '!=', null);
     $this->setFilter($totalOrdersPriceQuery, $date_s, $date_po, $status, $eventId, $creatorId, 'afisha_orders');
     $totalOrdersPriceQuery = $totalOrdersPriceQuery->find_all();
     foreach ($totalOrdersPriceQuery as $order) {
         $totalOrdersPrice += Afisha::getTotalCost($order);
     }
     //            Make array with all need data
     $fullResult = array();
     $jsonOrders = array();
     $jsonPrices = array();
     foreach ($cassiers as $key => $cassier) {
         $fullResult[$cassier->id]['user'] = $cassier;
         $allOrders = DB::select(array(DB::expr('COUNT(*)'), 'count'))->from('afisha_orders')->where('payer_id', '=', $cassier->id);
         $this->setFilter($allOrders, $date_s, $date_po, $status, $eventId, $creatorId, 'afisha_orders');
         $allOrders = $allOrders->count_all();
         $fullResult[$cassier->id]['totalOrders'] = $allOrders;
         $successOrders = DB::select(array(DB::expr('COUNT(*)'), 'count'))->from('afisha_orders')->where('payer_id', '=', $cassier->id)->where('status', '=', 'success');
         $this->setFilter($successOrders, $date_s, $date_po, $status, $eventId, $creatorId, 'afisha_orders');
         $successOrders = $successOrders->count_all();
         $fullResult[$cassier->id]['totalSuccessOrders'] = $successOrders;
         $orders = DB::select()->from('afisha_orders')->where('payer_id', '=', $cassier->id);
         $this->setFilter($orders, $date_s, $date_po, $status, $eventId, $creatorId, 'afisha_orders');
         $orders = $orders->find_all();
         $justSeats = 0;
         $totalPrice = 0;
         foreach ($orders as $order) {
             $totalPrice += Afisha::getTotalCost($order);
             $justSeats += count(array_filter(explode(',', $order->seats_keys)));
         }
         $fullResult[$cassier->id]['countSeats'] = $justSeats;
         $fullResult[$cassier->id]['totalPrice'] = number_format($totalPrice, 0, ',', ' ');
         //                Json orders
         $jsonOrders[$key]['name'] = $cassier->name . ($cassier->email ? '<br/>(' . $cassier->email . ')' : '');
         //                Value from 0.00 to 1 Percent equal.
         $jsonOrders[$key]['y'] = $allOrders / $totalCntOrders;
         $jsonOrders[$key]['v'] = $allOrders;
         //                Json prices
         $jsonPrices[$key]['name'] = $cassier->name . ($cassier->email ? '<br/>(' . $cassier->email . ')' : '');
         $jsonPrices[$key]['y'] = $totalPrice / $totalOrdersPrice;
         $jsonPrices[$key]['price'] = number_format($totalPrice, 0, ',', ' ');
         $jsonPrices[$key]['cntSeats'] = $justSeats;
     }
     //            Rendering
     $this->_content = View::tpl(array('result' => $fullResult, 'jsonOrders' => json_encode($jsonOrders), 'jsonPrices' => json_encode($jsonPrices), 'events' => DB::select()->from('afisha')->where('place_id', 'IS NOT', null)->find_all(), 'creators' => $cassiers), $this->tpl_folder . '/Index');
 }
Exemplo n.º 3
0
 public static function getExcel($orders, $afisha)
 {
     $countOrders = $countPlaces = $totalCost = $countBrone = $countExpired = $countPayed = 0;
     $pay_statuses = Config::get('order.pay_statuses');
     $xls = new \PHPExcel();
     $xls->setActiveSheetIndex();
     $sheet = $xls->getActiveSheet();
     $sheet->setTitle($afisha->name);
     //        Header
     $sheet->mergeCells('A1:F1')->setCellValue('A1', $afisha->name . '(' . date('d-m-Y H:i:s') . ')');
     $sheet->setCellValue('A2', 'Номер заказа');
     $sheet->setCellValue('B2', 'Название события');
     $sheet->setCellValue('C2', 'Количество мест');
     $sheet->setCellValue('D2', 'Сумма заказа');
     $sheet->setCellValue('E2', 'Дата');
     $sheet->setCellValue('F2', 'Статус');
     $offset = 2;
     $row = 1;
     foreach ($orders as $key => $obj) {
         $row = $offset + ($key + 1);
         $places = count(array_filter(explode(',', $obj->seats_keys)));
         $cost = Afisha::getTotalCost($obj);
         if ($obj->status == 'success') {
             $status = $pay_statuses['success'];
             $countPayed++;
         } else {
             if ($obj->created_at > time() - Config::get('reserved_days') * 24 * 60 * 60 and $obj->status != 'success') {
                 $status = $pay_statuses['brone'];
                 $countBrone++;
             } else {
                 if ($obj->created_at < time() - Config::get('reserved_days') * 24 * 60 * 60 and $obj->status != 'success') {
                     $status = $pay_statuses['expired'];
                     $countExpired++;
                 } else {
                     $status = 'Не оплачено';
                 }
             }
         }
         $sheet->setCellValueByColumnAndRow(0, $row, $obj->id);
         $sheet->setCellValueByColumnAndRow(1, $row, $afisha->name);
         $sheet->setCellValueByColumnAndRow(2, $row, $places);
         $sheet->setCellValueByColumnAndRow(3, $row, number_format($cost, 0, '.', ' ') . ' грн');
         $sheet->setCellValueByColumnAndRow(4, $row, date('d.m.Y H:i', $obj->payed_at));
         $sheet->setCellValueByColumnAndRow(5, $row, $status);
         //            Calc
         $countOrders++;
         $countPlaces += $places;
         $totalCost += $cost;
     }
     //        Footer
     $row++;
     $sheet->setCellValueByColumnAndRow(0, $row, 'Кол-во заказов: ' . $countOrders);
     $sheet->setCellValueByColumnAndRow(1, $row, '');
     $sheet->setCellValueByColumnAndRow(2, $row, 'Кол-во мест: ' . $countPlaces);
     $sheet->setCellValueByColumnAndRow(3, $row, 'Сумма: ' . $totalCost);
     $sheet->setCellValueByColumnAndRow(4, $row, "Кол-во");
     $sheet->setCellValueByColumnAndRow(4, $row + 1, "Забронированных: " . $countBrone);
     $sheet->setCellValueByColumnAndRow(4, $row + 2, "Просроченных: " . $countExpired);
     $sheet->setCellValueByColumnAndRow(4, $row + 3, "Оплаченных: " . $countPayed);
     //        Set auto width
     foreach (range('A', $xls->getActiveSheet()->getHighestDataColumn()) as $col) {
         $xls->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
     }
     //        Save file
     // Выводим HTTP-заголовки
     header("Expires: Mon, 1 Apr 1974 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-type: application/vnd.ms-excel");
     header("Content-Disposition: attachment; filename=" . $afisha->alias . '_' . date('d-m-Y_H:i:s') . ".xls");
     // Выводим содержимое файла
     $objWriter = new \PHPExcel_Writer_Excel5($xls);
     $objWriter->save('php://output');
 }