コード例 #1
0
ファイル: Ajax.php プロジェクト: piotrazsko/accounting
 public function action_export()
 {
     if (Request::initial()->is_ajax()) {
         $ajax = new Model_Stanki();
         $result = $ajax->get_all();
         $filename = './public/media/csv/result_' . date('G.i_d.m') . '.csv';
         $file = fopen($filename, 'w');
         $arr = array('№', 'Дата', 'Время', 'Товар', 'Категолрия', 'Количество', 'Курс у.е.', 'Цена', 'Оплачено наличными', 'Оплачено через карточку', 'Уплачено по безналичному расчету', 'Название организации', 'Отгрузка', 'Продавец', 'Акция', 'Магазин', 'Адресс', 'Телефон', 'ФИО', 'Номер карты друга', 'Примечание', '%');
         foreach ($arr as &$val) {
             $val = iconv("UTF-8", "Windows-1251", $val);
         }
         fputcsv($file, $arr, ';', '"');
         foreach ($result as $value) {
             foreach ($value as &$val) {
                 $val = iconv("UTF-8", "Windows-1251", $val);
             }
             fputcsv($file, $value, ';', '"');
         }
         fclose($file);
         chmod($filename, 0777);
         echo $filename;
     }
 }
コード例 #2
0
ファイル: Admin.php プロジェクト: piotrazsko/accounting
 public function action_edit_order()
 {
     if (!Auth::instance()->logged_in('admin')) {
         $this->redirect('http://localhost/login');
     } else {
         $db = new Model_Stanki();
         $stores = $db->get_store();
         $sellers = $db->get_all_seller();
         $content = View::factory('admin/edit_order');
         $content->store = $stores;
         $content->seller = $sellers;
         $this->template->scripts = array('jquery', 'bootstrap.min', 'jquery-ui.min', 'scrollTo', 'admin', 'script', 'edit');
         $this->template->styles = array('jquery-ui.min', 'jquery-ui.theme.min', 'bootstrap.min', 'style');
         if ($id = Request::current()->param('id') == 'filter') {
             $date1 = Arr::get($_GET, 'date1', '');
             $date2 = Arr::get($_GET, 'date2', '');
             $seller = Arr::get($_GET, 'seller', '0');
             $store = Arr::get($_GET, 'store', '0');
             $item = Arr::get($_GET, 'item', '');
             $category = Arr::get($_GET, 'category', '');
             if ($date1 != 0) {
                 $date1 = strtotime($date1);
             } else {
                 $date1 = '0';
             }
             if ($date2 != 0) {
                 $date2 = strtotime($date2);
             } else {
                 $date2 = time();
             }
             // проверяем выбор в фильтрах выставления магазинов и даты
             if ($seller != '0' and $store == '0') {
                 $res = $db->get_seller($seller, $date1, $date2);
             }
             if ($store != '0' and $seller == '0') {
                 $res = $db->get_for_store($store, $date1, $date2);
             }
             if ($store != '0' and $seller !== '0') {
                 $res = $db->get_filter($store, $seller, $date1, $date2);
             }
             if ($store == '0' and $seller == '0') {
                 $res = $db->get_date($date1, $date2);
             }
             //далее расмотрим даты их фильтр
             $res = $this->filter($item, $category, $res);
             $arr = array();
             $page = Arr::get($_GET, 'page', '0');
             $size = Arr::get($_GET, 'size', count($res));
             $count = count($res);
             $n_page = ($count - $count % $size) / $size;
             if ($page > $n_page) {
                 $page = $n_page;
             }
             $n = $size * ($page + 1);
             $k = $size * $page;
             //посчитаем общее число страниц
             if ($page == $n_page) {
                 $n = $k + $count % $size;
             }
             for ($i = $k; $i < $n; ++$i) {
                 $arr[] = $res[$i];
             }
             $content->n_page = $n_page + 1;
             $content->db = $arr;
             $this->template->content = $content;
         } else {
             //рассматриваем вариантпейджинг на начальной странице(решение не самое лучшее но какое получилось)
             $res = $db->get_all();
             $arr = array();
             $page = 0;
             $count = count($res);
             $size = 30;
             $n = $size * ($page + 1);
             $k = $size * $page;
             $n_page = ($count - $count % $size) / $size;
             if ($page == $n_page) {
                 $n = $k + $count % $size;
             }
             for ($i = $k; $i < $n; ++$i) {
                 $arr[] = $res[$i];
             }
             $content->n_page = $n_page + 1;
             $content->db = $arr;
             $this->template->content = $content;
         }
     }
 }