Advertisement
Guest User

Untitled

a guest
May 31st, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.42 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Planejamento\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use Planejamento\Http\Requests;
  7. use Planejamento\TalhaoSafra;
  8. use Planejamento\Bloco;
  9. use Planejamento\Divisao;
  10. use Planejamento\Filial;
  11. use Planejamento\Talhao;
  12. use DB;
  13.  
  14. class TalhaoSafraController extends Controller
  15. {
  16.     public function index(Request $request)
  17.     {
  18.         return response()->json([], 200);
  19.     }
  20.  
  21.     public function viewTalhao(Request $request)
  22.     {
  23.         $talhao = new TalhaoSafra;
  24.  
  25.         $talhoes = $talhao->viewTalhoes($request->codemp, $request->codfil, $request->codsaf);
  26.  
  27.         return response()->json($talhoes, 200)->setEncodingOptions(JSON_NUMERIC_CHECK);
  28.     }
  29.  
  30.     public function showTree(Request $request)
  31.     {
  32.         $return = [];
  33.  
  34.         $filial = Filial::where('codemp', $request->codemp)->where('codfil', $request->codfil)->get();
  35.  
  36.         for ($f=0; $f < $filial->count(); $f++) {
  37.             $return[$f] = $filial[$f]->toArray();
  38.             $return[$f]['text'] = $filial[$f]->sigfil;
  39.  
  40.             $divisao = Divisao::where('codemp', $filial[$f]->codemp)
  41.                               ->where('codfil', $filial[$f]->codfil)
  42.  
  43.                               ->orderby('desdv1')
  44.                               ->get();
  45.  
  46.  
  47.             for ($d=0; $d < $divisao->count(); $d++) {
  48.  
  49.                 $return[$f]["items"][$d] = $divisao[$d]->toArray();
  50.                 $return[$f]["items"][$d]['text'] = $divisao[$d]->desdv1;
  51.                 $return[$f]["items"][$d]['items'] = [];
  52.  
  53.                 $bloco = Bloco::where('codemp', $filial[$f]->codemp)
  54.                               ->where('codfil', $filial[$f]->codfil)
  55.                               ->whereIn('coddv2', function($query) use ($filial, $divisao, $f, $d, $request){
  56.                                   $query
  57.                                     ->select('coddv2')
  58.                                     ->from('e001dv3')
  59.                                     ->where('e001dv3.codemp', $filial[$f]->codemp)
  60.                                     ->where('e001dv3.codfil', $filial[$f]->codfil)
  61.                                     ->where('e001dv3.coddv1', $divisao[$d]->coddv1)
  62.                                     ->whereNotIn('e001dv3.iddiv3', function($query) use ($request){
  63.                                         $query
  64.                                             ->select('iddiv3')
  65.                                             ->from('e001pla')
  66.                                             ->where('codemp', $request->codemp)
  67.                                             ->where('codfil', $request->codfil)
  68.                                             ->where('codsaf', "'{$request->codsaf}'");
  69.                                     });
  70.                               })
  71.                               ->orderby('desdv2')
  72.                               ->get();
  73.  
  74.                 for ($b=0; $b < $bloco->count(); $b++) {
  75.                     $return[$f]["items"][$d]["items"][$b] = $bloco[$b]->toArray();
  76.                     $return[$f]["items"][$d]["items"][$b]['text'] = $bloco[$b]->desdv2;
  77.  
  78.                     $talhao = Talhao::where('codemp', $filial[$f]->codemp)
  79.                                     ->where('codfil', $filial[$f]->codfil)
  80.                                     ->where('coddv1', $divisao[$d]->coddv1)
  81.                                     ->where('coddv2', $bloco[$b]->coddv2)
  82.                                     ->whereNotIn('iddiv3', function($query) use ($request){
  83.                                         $query
  84.                                             ->select('iddiv3')
  85.                                             ->from('e001pla')
  86.                                             ->where('codemp', $request->codemp)
  87.                                             ->where('codfil', $request->codfil)
  88.                                             ->where('codsaf', $request->codsaf);
  89.                                     })
  90.                                     ->orderby('desdv3')
  91.                                     ->get();
  92.  
  93.                     for ($t=0; $t < $talhao->count(); $t++) {
  94.                         $return[$f]["items"][$d]["items"][$b]["items"][$t] = $talhao[$t]->toArray();
  95.                         $return[$f]["items"][$d]["items"][$b]["items"][$t]['text'] = $talhao[$t]->desdv3;
  96.                     }
  97.                 }
  98.             }
  99.         }
  100.  
  101.         return response()->json($return,200)->setEncodingOptions(JSON_NUMERIC_CHECK);
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement