Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Planejamento\Http\Controllers;
- use Illuminate\Http\Request;
- use Planejamento\Http\Requests;
- use Planejamento\TalhaoSafra;
- use Planejamento\Bloco;
- use Planejamento\Divisao;
- use Planejamento\Filial;
- use Planejamento\Talhao;
- use DB;
- class TalhaoSafraController extends Controller
- {
- public function index(Request $request)
- {
- return response()->json([], 200);
- }
- public function viewTalhao(Request $request)
- {
- $talhao = new TalhaoSafra;
- $talhoes = $talhao->viewTalhoes($request->codemp, $request->codfil, $request->codsaf);
- return response()->json($talhoes, 200)->setEncodingOptions(JSON_NUMERIC_CHECK);
- }
- public function showTree(Request $request)
- {
- $return = [];
- $filial = Filial::where('codemp', $request->codemp)->where('codfil', $request->codfil)->get();
- for ($f=0; $f < $filial->count(); $f++) {
- $return[$f] = $filial[$f]->toArray();
- $return[$f]['text'] = $filial[$f]->sigfil;
- $divisao = Divisao::where('codemp', $filial[$f]->codemp)
- ->where('codfil', $filial[$f]->codfil)
- ->orderby('desdv1')
- ->get();
- for ($d=0; $d < $divisao->count(); $d++) {
- $return[$f]["items"][$d] = $divisao[$d]->toArray();
- $return[$f]["items"][$d]['text'] = $divisao[$d]->desdv1;
- $return[$f]["items"][$d]['items'] = [];
- $bloco = Bloco::where('codemp', $filial[$f]->codemp)
- ->where('codfil', $filial[$f]->codfil)
- ->whereIn('coddv2', function($query) use ($filial, $divisao, $f, $d, $request){
- $query
- ->select('coddv2')
- ->from('e001dv3')
- ->where('e001dv3.codemp', $filial[$f]->codemp)
- ->where('e001dv3.codfil', $filial[$f]->codfil)
- ->where('e001dv3.coddv1', $divisao[$d]->coddv1)
- ->whereNotIn('e001dv3.iddiv3', function($query) use ($request){
- $query
- ->select('iddiv3')
- ->from('e001pla')
- ->where('codemp', $request->codemp)
- ->where('codfil', $request->codfil)
- ->where('codsaf', "'{$request->codsaf}'");
- });
- })
- ->orderby('desdv2')
- ->get();
- for ($b=0; $b < $bloco->count(); $b++) {
- $return[$f]["items"][$d]["items"][$b] = $bloco[$b]->toArray();
- $return[$f]["items"][$d]["items"][$b]['text'] = $bloco[$b]->desdv2;
- $talhao = Talhao::where('codemp', $filial[$f]->codemp)
- ->where('codfil', $filial[$f]->codfil)
- ->where('coddv1', $divisao[$d]->coddv1)
- ->where('coddv2', $bloco[$b]->coddv2)
- ->whereNotIn('iddiv3', function($query) use ($request){
- $query
- ->select('iddiv3')
- ->from('e001pla')
- ->where('codemp', $request->codemp)
- ->where('codfil', $request->codfil)
- ->where('codsaf', $request->codsaf);
- })
- ->orderby('desdv3')
- ->get();
- for ($t=0; $t < $talhao->count(); $t++) {
- $return[$f]["items"][$d]["items"][$b]["items"][$t] = $talhao[$t]->toArray();
- $return[$f]["items"][$d]["items"][$b]["items"][$t]['text'] = $talhao[$t]->desdv3;
- }
- }
- }
- }
- return response()->json($return,200)->setEncodingOptions(JSON_NUMERIC_CHECK);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement