SHARE
TWEET

Untitled

Orion55 Feb 5th, 2016 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Http\Requests;
  6. use DB;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Pagination\LengthAwarePaginator;
  9. use Exception;
  10. use Mail;
  11. use Monolog\Logger;
  12. use Monolog\Handler\RotatingFileHandler;
  13. use Monolog\Processor\WebProcessor;
  14. use Monolog\Formatter\LineFormatter;
  15. use Auth;
  16.  
  17. class DeponController extends Controller
  18. {
  19.     private $orkl;
  20.     private $accs1;
  21.     private $logger;
  22.  
  23.     public function  index(Request $request)
  24.     {
  25.         $perPage = 12;
  26.         $currentPage = $request->get('page', 1);
  27.         $sql1 = "SELECT contnum, totalsum, enddate, closedate, contstatus, rowidtochar (rowid) row1
  28.                      FROM (SELECT t.contnum,
  29.                                   t.totalsum,
  30.                                   t.enddate,
  31.                                   t.closedate,
  32.                                   t.contstatus,
  33.                                   row_number() over(order by t.contstatus asc, t.enddate) rnk
  34.                              FROM mbcont t)
  35.                     WHERE rnk BETWEEN ? AND ?";
  36.         $accs = $this->orkl->select($sql1, array(($currentPage - 1) * $perPage, $currentPage * $perPage));
  37.         $paginator = new LengthAwarePaginator($this->accs1, count($this->accs1), $perPage, $currentPage);
  38.         $paginator->setPath($request->getBasePath());
  39.         return view('main.index', compact('accs', 'paginator'));
  40.     }
  41.  
  42.     public function __construct()
  43.     {
  44.         $this->middleware('auth');
  45.  
  46.         $this->logger = new Logger('Depon_logger');
  47.         $handler = new RotatingFileHandler(storage_path('logs\depon.log'), Logger::INFO);
  48.         $this->logger->pushHandler($handler);
  49.         $handler->setFormatter(new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %extra% %context%\n"));
  50.         $this->logger->pushProcessor(new WebProcessor);
  51.  
  52.         try {
  53.             $this->orkl = DB::connection('oracle');
  54.         } catch (Exception $e) {
  55.             $this->logger->addError("Ошибка! " . $e->getMessage());
  56.             dd("Ошибка! " . $e->getMessage());
  57.         }
  58.         $sql2 = 'select t.contnum from MBCONT t';
  59.         $this->accs1 = $this->orkl->select($sql2);
  60.     }
  61.  
  62.     public function search(Request $request)
  63.     {
  64.         $this->validate($request, ['search1' => 'required']);
  65.         $request->flashOnly('search1');
  66.  
  67.         $sql3 = "select t.contnum, t.totalsum, t.enddate, t.closedate, t.contstatus, rowidtochar (rowid) row1 from MBCONT t where contnum like ?";
  68.         $param = '%' . $request->search1 . '%';
  69.         $accs = $this->orkl->select($sql3, array($param));
  70.  
  71.         return view('main.index', compact('accs'));
  72.     }
  73.  
  74.     public function clear()
  75.     {
  76.         return redirect('/depon')->with('search1', '');
  77.     }
  78.  
  79.     public function edit($id = null)
  80.     {
  81.         if ($id == null) {
  82.             return redirect('/depon');
  83.         }
  84.         $sql3 = "select t.contnum, t.totalsum, t.enddate, t.closedate, rowidtochar (?) row1 from MBCONT t where rowid = CHARTOROWID(?)";
  85.         $param = $id;
  86.         $dep = $this->orkl->selectOne($sql3, array($param, $param));
  87.         return view('main.edit', compact('dep'));
  88.     }
  89.  
  90.     private function report1($mas1)
  91.     {
  92.         $email1 = DB::table('settings')->where('name1', 'depon_email')->value('val1');
  93.         try {
  94.             $data = ['contnum' => $mas1["contnum"], 'totalsum' => $mas1["totalsum"], 'enddate' => $mas1["enddate"], 'closedate' => $mas1["closedate1"], 'email' => $email1, 'subject' => $mas1["str1"]];
  95.             Mail::send('email.deponclose', $data, function ($message) use ($data) {
  96.                 $message->to($data['email']);
  97.                 $message->subject($data['subject']);
  98.             });
  99.         } catch (Exception $e) {
  100.             $mas1["sess"]->flash('errors', 'Email на' . $email1 . ' не удалось отправить!');
  101.             $this->logger->addError('Email на' . $email1 . ' не удалось отправить!');
  102.         }
  103.  
  104.         $user = Auth::user();
  105.         $this->logger->addInfo('User Name: ' . $user->getAttributeValue('name') . ' | User Email: ' . $user->getAttributeValue('email') . ' | ' . $mas1["str1"]);
  106.     }
  107.  
  108.     public function editpost($id = null, Request $request)
  109.     {
  110.         if ($id == null) {
  111.             return redirect('/depon');
  112.         }
  113.         switch ($request->submit) {
  114.             case "cancel_dep":
  115.                 return redirect('/depon');
  116.                 break;
  117.             case "sum_dep":
  118.                 $this->validate($request, ['totalsum' => 'required|numeric']);
  119.  
  120.                 $sql1 = "update mbcont t set t.totalsum = ? where rowid = CHARTOROWID (?)";
  121.                 $this->orkl->update($sql1, array($request->totalsum, $id));
  122.  
  123.                 $mas = [
  124.                     "str1" => 'Сумма договора ' . $request->contnum . ' успешно изменена на ' . $request->totalsum . '!',
  125.                     "contnum" => $request->contnum,
  126.                     "totalsum" => $request->totalsum,
  127.                     "enddate" => $request->enddate,
  128.                     "closedate1" => null,
  129.                     "sess" => $request->session()
  130.                 ];
  131.                 $this->report1($mas);
  132.  
  133.                 return redirect('/depon')->with('status', 'success')->with('message', $mas["str1"]);
  134.                 break;
  135.             case "close_dep":
  136.                 $this->validate($request, ['closedate' => 'required|date']);
  137.  
  138.                 $sql1 = "update mbcont t set t.closedate = to_date(?, 'dd-mm-yyyy'), t.ContStatus = 2 where rowid = CHARTOROWID(?)";
  139.                 $this->orkl->update($sql1, array($request->closedate, $id));
  140.  
  141.                 $mas = [
  142.                     "str1" => 'Договор ' . $request->contnum . ' успешно закрыт!',
  143.                     "contnum" => $request->contnum,
  144.                     "totalsum" => $request->totalsum,
  145.                     "enddate" => $request->enddate,
  146.                     "closedate1" => $request->closedate,
  147.                     "sess" => $request->session()
  148.                 ];
  149.                 $this->report1($mas);
  150.  
  151.                 return redirect('/depon')->with('status', 'success')->with('message', $mas["str1"]);
  152.                 break;
  153.             default:
  154.                 return redirect('/depon');
  155.         }
  156.     }
  157.  
  158.     public function settget()
  159.     {
  160.         $email1 = DB::table('settings')->where('name1', 'depon_email')->value('val1');
  161.         return view('main.sett', ['email' => $email1]);
  162.     }
  163.  
  164.     public function settpost(Request $request)
  165.     {
  166.         switch ($request->submit) {
  167.             case "cancel_sett":
  168.                 return redirect('/depon');
  169.                 break;
  170.             case "ok_sett":
  171.                 $this->validate($request, ['depon_email' => 'required']);
  172.                 DB::table('settings')->where('name1', 'depon_email')->update(['val1' => $request->depon_email]);
  173.                 return redirect('/depon');
  174.                 break;
  175.             default:
  176.                 return redirect('/depon');
  177.         }
  178.     }
  179. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top