%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/pjc/app/Http/Controllers/
Upload File :
Create Path :
Current File : /var/www/pjc/app/Http/Controllers/gestioneOre.php

<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Response;

use DB;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Utility;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;

class gestioneOre extends Controller
{
    public function removep($id, $mese, $anno)
    {
        DB::table('planning')->where('id', $id)->delete();

        return Redirect::action('Planning@create', [$mese,$anno]);
    }

    public function login()
    {
        return view('login');
    }

    public function loginProcess(Request $request)
    {
        $data= $request->all();
        $user=DB::table('utenti')->where('cognome', $data['user'])->where('attivo',1)->get();
        $ok=DB::table('utenti')->where('cognome', $data['user'])->where('attivo',1)->count();

        if ($ok) {
            Session::put('users', $data['user']);
            Session::put('settore', $user[0]->settore);
            Session::put('idSettore', $user[0]->idsettore);
            Session::put('idUtente', $user[0]->id);
            return Redirect::action('gestioneOre@ore', [$user[0]->id]);
        } else {
            return view('login');
        }
    }

    public function delete($id)
    {
        if (Session::get('idUtente')!=27) {
            $check=DB::table('ore')->where('id', $id)->where('idUtente', Session::get('idUtente'))->count();

            if ($check) {
                DB::table('ore')
                    ->where('id', $id)
                        ->update(array('canc' => 1));
                return Redirect::back()->with('message', 'Ora eliminata');
            } else {
                return Redirect::back()->with('message', 'Non puoi eliminare le ore non tue');
            }
        } else {
            DB::table('ore')
                    ->where('id', $id)
                       ->update(array('canc' => 1));
            return Redirect::back()->with('message', 'Ora eliminata');
        }
    }

    public function updateOre($id)
    {
        $commesseAppoggio = DB::table('project')
            ->join('projects_accounts', 'projects_accounts.project_id', '=', 'project.id')
            ->join('project_cstm', 'project_cstm.id_c', '=', 'project.id')
            ->select('project.id', 'name', 'description')
            ->where('project.deleted', 0)
            ->where('projects_accounts.deleted', 0)
            //->where ( 'status', 'Draft' )
            ->get();

        foreach ($commesseAppoggio as $item) {
            $commesseArray[$item->name]=$item->name." - ".$item->description;
        }

        $ore=DB::table('ore')
                    ->where('id', $id)
                    ->get();
        if (Session::get('idUtente')!=22) {
            $check=DB::table('ore')->where('id', $id)->where('idUtente', Session::get('idUtente'))->count();


            if ($check) {
            } else {
                return Redirect::back()->with('message', 'Non puoi modificare le ore non tue');
            }
        }




        return view('gestioneOre.update')->withDati($ore)->withCommessearray($commesseArray);
    }

    public function saveUpdate(Request $request)
    {
        $data=$request->all();


        DB::table('ore')
            ->where('id', $data['id'])
            ->update($data);
        return Redirect::action('gestioneOre@vcommessa', [$data['commessa']]);
    }

    public function logout()
    {
        Session::flush();
        return Redirect::action('gestioneOre@login');
    }
    public function commesse($id = 0)
    {
        $utente=Session::get('idUtente');
        if (!isset($utente)) {
            return Redirect::action('gestioneOre@login');
        }

        //		$account=DB::table('accounts')
        //			->select('id','name')
        //			->where('deleted',0)
        //			->get();

        //		foreach ($account as $item) {
        //			$accounts[$item->id]=$item->name;
        //		}

        //		if($id <> 0)
        //		{
        //			$commesse=DB::table('project')
        //			->join('projects_accounts','projects_accounts.project_id','=','project.id')
        //			->join('project_cstm','project_cstm.id_c','=','project.id')
        //			->select('project.id','name','description','estimated_start_date','status','projects_accounts.account_id','project_cstm.importo_c')
        //			->where('project.deleted',0)
        //			->where('projects_accounts.deleted',0)
        //				->where('project_cstm.settore_c', $id)
        //			//->where('estimated_start_date' ,'>', '2014-01-01')
        //			->whereIn('status',['Draft','apertamafatturata'])
        //			->take(400)
        //			->get();
        //		}
        //		else
        //		{
        //			$commesse=DB::table('project')
        //				->join('projects_accounts','projects_accounts.project_id','=','project.id')
        //				->join('project_cstm','project_cstm.id_c','=','project.id')
        //				->select('project.id','name','description','estimated_start_date','status','projects_accounts.account_id','project_cstm.importo_c')
        //				->where('project.deleted',0)
        //				->where('projects_accounts.deleted',0)
//
        //				->whereIn('status',['Draft','apertamafatturata'])
//                ->take(100)
        //				->get();
        //		}

        $dati['id']=1;
        //			$dati['commesse'] = $commesse;
        //			$dati['accounts'] = $accounts;
        if ($id == 0) {
            $dati['id'] = Session::get('idSettore');
        } else {
            $dati['id'] = $id;
        }

        return view('gestioneOre.commesse')->withDati($dati);
    }



    public function commesseSubList(Request $request)
    {
        $tabella = "commesse_aperte";
        $id = $request->get('id_type') == 0 ? null : $request->get('id_type');

        switch ($id) {
            case 1:
                $tabella = "commesse_aperte";
                break;
            case 2:
                $tabella = "commesse_aperte";
                break;
            case 3:
                $tabella = "commesse_aperte";
                break;
            case 4:
                $tabella = "commesse_aperte";
                break;
            case 5:
                $tabella = "commesse_aperte";
                break;
            case 6:
                $tabella = "commesse_aperte";
                break;

            case 7:
                $tabella = "commesse_aperte";
                break;
                case 8:
                    $tabella = "commesse_aperte";
                    break;
                    case 9:
                        $tabella = "commesse_aperte";
                        break;
                        case 10:
                            $tabella = "commesse_aperte";
                            break;
                            case 11:
                                $tabella = "commesse_aperte";
                                break;

            case 12:
                $tabella = "commesse_chiuse";
                break;
            case 13:
                $tabella = "commesse_tutte";
                break;
        }

        $commesse = DB::table($tabella);



        $id = $request->get('id_type') == 0 ? null : $request->get('id_type');
        if ($id) {
            if (($id <> 12) and ($id <> 13)) {
                $commesse->where('settore_c', $id);
            }
        }



        $totalcommesse = clone $commesse;

        $search_string = $request->get('search')['value'];
        if ($search_string) {
            $commesse = DB::table($tabella)
                ->where('nome', 'like', '%'.$search_string.'%')
                ->orWhere('ragione_sociale', 'like', '%'.$search_string.'%')
                ->orWhere('descrizione', 'like', '%'.$search_string.'%');
        }

        $enumCol = array('nome', 'ragione_sociale', 'descrizione', 'data_inizio', 'stato','ore','completato');

        if ($request->get('order')[0]['column'] == 6) {
            $commesse->orderByRaw("CAST(".$enumCol[ $request->get('order')[0]['column'] ] ." as UNSIGNED)".$request->get('order')[0]['dir']);
        } else {
            $commesse->orderBy($enumCol[ $request->get('order')[0]['column'] ], $request->get('order')[0]['dir']);
        }
        $allcommesse = clone $commesse;
        $subcommesse = clone $commesse;

        $subcommesse->offset($request->get('start'))->take($request->get('length'));

        $data = array();
        $stato = "";


        foreach ($subcommesse->get() as $item) {
            if ($item->stato == 'Draft') {
                $stato = "Aperta";
            }
            if ($item->stato == 'apertamafatturata') {
                $stato = "Aperta ma fatturata";
            }



            $data[] = array(
                '<a href="' . action('gestioneOre@vcommessa', $item->nome) . '" target="_blank">' . $item->nome . '</a>',
                $item->ragione_sociale,
                $item->descrizione,
                $item->data_inizio,
                $stato,
                Utility::totOreDo($item->nome) . '/' . Utility::totOre($item->importo_c, '62.5'),
                '<div class="progress">'
                . '<div class="progress-bar ' . $item->completato  . ' progress-bar-striped '.Utility::statoPerc($item->completato).'" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: ' . Utility::percentuale(Utility::totOreDo($item->nome), Utility::totOre($item->importo_c, '62.5')) . '%">'
                . '<p class="text-left">' . $item->completato  . '% </p>'
                . '</div>'
                . '</div>'
            );
        }


        $response = [
            'draw' => intval($request->get('draw')),
            'recordsTotal' => intval($totalcommesse->count()),
            'recordsFiltered' => count($allcommesse->get()),
            'data' => $data
        ];

        return \Response::json($response, 200, []);
    }



    public function utenti()
    {
        return view('gestioneOre.utenti');
    }

    public function statistiche()
    {
        return view('gestioneOre.statistiche');
    }

    public function add($id, $planning = 0, $mese = 0, $anno = 0)
    {
        $utente=Session::get('idUtente');
        if (!isset($utente)) {
            return Redirect::action('gestioneOre@login');
        }

        $riga = DB::table('planning')->where('id', $id)->first();
        return view('gestioneOre.add')->withDati($riga->id_commessa)->withPlanning($planning)->withMese($mese)->withAnno($anno)->withRiga($riga);
    }

    public function addOre($id = 0, Request $request)
    {
        $data=$request->all();


        $utente=DB::table('utenti')->where('id', $data['idUtente'])->first();
        $data['k'] = $utente->k;

        $commessa=DB::table('project')
            ->join('projects_accounts', 'projects_accounts.project_id', '=', 'project.id')
            ->join('project_cstm', 'project_cstm.id_c', '=', 'project.id')
            ->select('project.id', 'name', 'description', 'estimated_start_date', 'status', 'projects_accounts.account_id', 'project_cstm.importo_c')
            ->where('project.deleted', 0)
            ->where('projects_accounts.deleted', 0)
            ->where('name', $data['commessa'])
            ->get();

        $ore=Utility::totOre($commessa[0]->importo_c, 62.5);

        //FINE CONTROLLO

        $idriga=$data['idriga'];
        $programmata=$data['programmata'];
        $mese=$data['mese'];
        $anno = $data['anno'];

        unset($data['planning']);
        unset($data['mese']);
        unset($data['anno']);
        $ex=DB::table('planning')->where('id', $idriga)->first();

        $k=DB::table('utenti')->where('id', $ex->id_tecnico)->first();
        unset($data['programmata']);
        unset($data['idriga']);

        //			if($programmata <> 0)
        //			{

        $valore=Utility::convertiore($data['tempo']);



        $valore_vecchio = Utility::convertiore($ex->fatte);


        DB::table('planning')->where('id', $idriga)->update(array('fatte' => Utility::convertioretime($valore + $valore_vecchio)));
        $data['idUtente']=$ex->id_tecnico;

        $data['oreNette']=	Utility::convertioretime(Utility::convertiore($data['tempo'])*$k->k);
        $data['utente']=$ex->id_tecnico;

        //DB::table('ore')->insertGetId($data);

        //			}

        $oreNette = Utility::convertiore($data['tempo']) * $utente->k;

        $data['oreNette']=	Utility::convertioretime(Utility::convertiore($data['tempo'])*$k->k);



        $id = DB::table('ore')->insertGetId($data);

        if ($programmata <> 0) {
            return Redirect::action('gestioneOre@ore', [$ex->id_tecnico])->with('message', 'Ore inserite correttamente');
        }

        if ($id==0) {
            return Redirect::action('gestioneOre@commesse')->with('message', 'Ore inserite correttamente');
        } else {
            return Redirect::action('gestioneOre@vcommessa', [$data['commessa']])->with('message', 'Ore inserite correttamente');
        }
    }

    public function vcommessa($id)
    {
        $utente=Session::get('idUtente');
        if (!isset($utente)) {
            return Redirect::action('gestioneOre@login');
        }

        $commessa=DB::table('project')
            ->join('projects_accounts', 'projects_accounts.project_id', '=', 'project.id')
            ->join('project_cstm', 'project_cstm.id_c', '=', 'project.id')
            ->select('project.id', 'name', 'description', 'estimated_start_date', 'status', 'projects_accounts.account_id', 'project_cstm.importo_c', 'project_cstm.tipo_di_pagamento_c as tipoPagamento', 'project.status')
            ->where('project.deleted', 0)
            ->where('projects_accounts.deleted', 0)
            ->where('name', $id)

            ->get();


        $ore=DB::table('ore')
            ->join('utenti', 'utenti.id', '=', 'ore.idUtente')
            ->select('ore.id', 'ore.idUtente', 'ore.data', 'ore.commessa', 'ore.tempo', 'ore.descrizione', 'ore.utente', 'utenti.settore', 'utenti.cognome', 'ore.oreNette')
            ->where('commessa', $id)
            ->where('canc', 0)
            ->get();


        $somma = DB::select(DB::raw("select sec_to_time(sum(time_to_sec(tempo))) as somma from ore where ore.canc=0 and commessa='".$id."'"));


        $saldo = DB::select(DB::raw("select sum(importo) as somma from movimenti where commessa='".$id."'"));


        $dati['stato']=array('Draft'=>'Aperta','In Review'=>'Chiusa e fatturata','Published'=>'Chiusa in attesa di fattura','fallimento'=>'Fallimento','in_sospeso'=>'In sospeso','da_ripresentare'=>'Da ripresentare anno 2016','fatturatanolavorata'=>'Fatturata non lavorata');
        $dati['id']=$id;
        $dati['ore']=$ore;
        $dati['somma']=$somma;
        $dati['totOreDo']=Utility::totOreDo($commessa[0]->name);
        $dati['totOre']=Utility::totOre($commessa[0]->importo_c, '62.5');
        $dati['movimenti']=DB::table('movimenti')->where('commessa', $id)->get();
        $dati['commessa']=$commessa;
        $dati['tipologia']=array(2 => 'Acconto', 1 => 'Saldo');
        $dati['dato']=$saldo[0]->somma;




        return view('gestioneOre.vcommessa')->withdati($dati)->withCommessa($commessa);
    }


    public function sommario()
    {
        $utenti=DB::table('utenti')->where('attivo', 1)->get();
        $giorni=30;
        for ($i=1;$i<$giorni;$i++) {
            $date[]=date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-$i, date("Y")));
        }
        foreach ($utenti as $item) {
            for ($i=1;$i<$giorni;$i++) {
                $oreFatte=Utility::getOreUtente(date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-$i, date("Y"))), $item->id);

                $ore[$item->cognome][date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-$i, date("Y")))]=$oreFatte;
                $id[$item->cognome]=$item->id;
            }
        }
        $dati['id']=$id;
        $dati['utenti']=$utenti;
        $dati['ore']=$ore;
        $dati['date']=$date;





        return view('gestioneOre.sommario')->withdati($dati);
    }

    public function utente($id)
    {
        if ((Session::get('idUtente')==$id)or(Session::get('idUtente')==22)or(Session::get('idUtente')==27)) {
            $utente=DB::table('utenti')->where('id', $id)->get();
            $ore=DB::table('ore')
                ->select('ore.id', 'ore.commessa', 'ore.descrizione', 'ore.ragione', 'ore.data', 'ore.tempo', 'ore.idUtente', 'ore.oreNette')
            ->join('project', 'project.name', '=', 'ore.commessa')
            ->where('idUtente', $id)->orderBy('data', 'desc')
            ->where('canc', 0)
            ->orderBy('data', 'ASC')
            ->get();

            $account=DB::table('accounts')
            ->select('id', 'name')
            ->where('deleted', 0)
            ->get();

            foreach ($account as $item) {
                $accounts[$item->id]=$item->name;
            }

            for ($i=0; $i < 8; $i++) {
                $giorni[date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-$i, date("Y")))]=Utility::totOreDoUtente($id, date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-$i, date("Y"))));
            }

            $dati['utente']=$utente;
            $dati['ore']=$ore;
            $dati['accounts']=$accounts;
            $dati['giorni']=$giorni;


            return view('gestioneOre.vutente')->withdati($dati);
        } else {
            return Redirect::back()->with('message', 'Non puoi vedere questo utente');
        }
    }

    public function utility()
    {

        /* $ore=DB::table('ore')
            ->select('id','tempo1')
            ->get();

        foreach ($ore as $item)
        {
            $tempo=$item->tempo1;
            if(count($tempo) == 1)
            {
                $tempo="0".$tempo.":00:00";
            }
            if(count($tempo) == 2)
            {
                $tempo=$tempo.":00:00";
            }
            if(count($tempo) == 4)
            {
                $tempo="0".$tempo.":00";
            }
            if(count($tempo) == 5)
            {
                $tempo=$tempo.":00";
            }
            DB::table('ore')
            ->where('id', $item->id)
            ->update(array('tempo' => $tempo));
        } */
        /*
        $ore=DB::table('ore')
           ->select('id','data2')
           ->get();

        foreach ($ore as $item)
        {
           $data=$item->data2;
           $appoggio=explode("/", $data);
           $dataOk="20".$appoggio[2]."-".$appoggio[1]."-".$appoggio[0];



           DB::table('ore')
           ->where('id', $item->id)
           ->update(array('data' => $dataOk));
        }
        */

        /* $utenti=DB::table('utenti')
            ->select('cognome','id')
            ->get();

        foreach ($utenti as $item ) {
            DB::table('ore')
            ->where('utente', $item->cognome)
            ->update(array('idUtente' => $item->id));
        } */

        /*$commesse=DB::table('project')
            ->join('projects_accounts','projects_accounts.project_id','=','project.id')
            ->join('project_cstm','project_cstm.id_c','=','project.id')
            ->select('project.id','name','description','estimated_start_date','status','projects_accounts.account_id','project_cstm.importo_c')
            ->where('project.deleted',0)
            ->where('projects_accounts.deleted',0)
            ->get();


        foreach ($commesse as $item) {

            $totOreDo=Utility::totOreDo($item->name);
            $totOre=Utility::totOre($item->importo_c,62.5);
            $perc=Utility::percentuale($totOreDo,$totOre);
            if ($perc !=0)
            {

            }
            else
            {
                $perc=0;
            }
            if ($totOreDo !=0)
            {

            }
            else
            {
                $totOreDo=0;
            }

            $id = DB::table('calc')->insertGetId(array('commessa'=> $item->name, 'totore' => $totOre,'sommaore' => $totOreDo,'perc' => $perc));

        } */

        DB::table('test')->insertGetId(array('data'=> 'ciao'));
    }

    public function getMail()
    {
        if (Utility::giornoData(date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-1))) == 'Dom') {
            $i=2;
        } else {
            $i=1;
        }

        $send=array();

        $utenti=DB::table('utenti')->where('attivo', 1)->get();
        foreach ($utenti as $item) {
            $ore=Utility::totOreDoutente($item->id, date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-$i)));

            if ($ore <= 7) {
                Mail::send('gestioneOre.mail', array('ore' => $ore ,'data' => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-1))), function ($message) use ($item) {
                    $message->to('info@sermatech.it', $item->cognome)->cc('s.malagoli@sermatech.it')->subject('Controllo ore');
                });
                $send[]=$item->cognome;
            }
        }

        return $send;
    }

    public function ore($idutente, $mese = 0, $anno = 0)
    {
        $oreAssegnate = DB::table('planning')->where('id_tecnico', $idutente)->orderBy('mese', 'asc')->get();

        $commesseAppoggio = DB::table('project')
        ->join('projects_accounts', 'projects_accounts.project_id', '=', 'project.id')
        ->join('project_cstm', 'project_cstm.id_c', '=', 'project.id')
        ->select('project.id', 'name', 'description', 'estimated_start_date', 'status', 'projects_accounts.account_id', 'project_cstm.importo_c')
        ->where('project.deleted', 0)
        ->where('projects_accounts.deleted', 0)
        //->where ( 'status', 'Draft' )
                ->get();

        $totaleCommesse=0;
        foreach ($commesseAppoggio as $key) {
            $totaleCommesse =+ $key->importo_c;
            $commesse [$key->name] = $key;
        }

        $account = DB::table('accounts')->select('id', 'name')->where('deleted', 0)->get();

        foreach ($account as $item) {
            $accounts [$item->id] = $item->name;
        }

        $mesi = array(
                '-',
                                'Gennaio',
                'Febbraio',
                'Marzo',
                'Aprile',
                'Maggio',
                'Giugno',
                'Luglio',
                'Agosto',
                'Settembre',
                'Ottobre',
                'Novembre',
                'Dicembre'
        );


        //return $accounts;
        return view('gestioneOre.oreassegnate')
                    ->withPlanning($oreAssegnate)
                    ->withCommesse($commesse)
                    ->withAccounts($accounts)
                    ->withMesi($mesi);
    }

    public function summary($settore)
    {
        $importoTotale=0; //Importo di tutte le commesse del settore
            $importoCarico=0; //Importo di tutte le ore assegnate per 62.5

            $importoTotale = DB::table('project')
        ->join('projects_accounts', 'projects_accounts.project_id', '=', 'project.id')
        ->join('project_cstm', 'project_cstm.id_c', '=', 'project.id')
        ->select('project.id', 'name', 'description', 'estimated_start_date', 'status', 'projects_accounts.account_id', 'project_cstm.importo_c')
        ->where('project.deleted', 0)
        ->where('projects_accounts.deleted', 0)
        //->where ( 'status', 'Draft' )
                ->where('settore_c', $settore)
                ->sum('importo_c');

        $oreAssegnate = DB::select(DB::raw("select sum(carico) as somma,mese from planning group by mese"));


        foreach ($oreAssegnate as $value) {
            $oreMeseCarico[$value->mese] = $value->somma;
        }




        return $oreMeseCarico;
    }

    public function addoreglobal($id = 0)
    {
        $utenti=DB::table('utenti')->where('attivo', 1)->get();

	

        foreach ($utenti as $item) {
            $utentiArray[$item->id]=$item->cognome;
        }

        $commesseAppoggio = DB::table('project')
           // ->leftjoin('projects_accounts', 'projects_accounts.project_id', '=', 'project.id')
           // ->leftjoin('project_cstm', 'project_cstm.id_c', '=', 'project.id')
            ->select('project.id', 'name', 'description')
	    ->where('project.deleted', 0)
            ->get();



        foreach ($commesseAppoggio as $item) {
            $commesseArray[$item->name]=$item->name." - ".htmlspecialchars(substr($item->description, 0, 50), ENT_QUOTES);
        }



        return view('gestioneOre.addglobal')->withUtenti($utentiArray)->withCommesse($commesseArray)->withTecnico($id);
    }

    public function saveoreglobal(Request $request)
    {
        $data=$request->all();



        $utente=DB::table('utenti')->where('id', $data['idUtente'])->first();
        $data['k'] = $utente->k;

        $data['oreNette']=Utility::calcolak($data['idUtente'], $data['tempo']);

        //DEVO CONTROLLARE CHE L'INSERIMENTO DELLE ORE NON FACCIA SUPERARE IL 120%
        $somma = Utility::totOreDo($data['commessa']);

        $commessa=DB::table('project')
            ->join('projects_accounts', 'projects_accounts.project_id', '=', 'project.id')
            ->join('project_cstm', 'project_cstm.id_c', '=', 'project.id')
            ->select('project.id', 'name', 'description', 'estimated_start_date', 'status', 'projects_accounts.account_id', 'project_cstm.importo_c')
            ->where('project.deleted', 0)
            ->where('projects_accounts.deleted', 0)
            ->where('name', $data['commessa'])
            ->get();

        $ore=Utility::totOre($commessa[0]->importo_c, 62.5);



        //FINE CONTROLLO



        $id = DB::table('ore')->insertGetId($data);


        return Redirect::action('gestioneOre@utente', [$data['idUtente']])->with('message', 'Ore inserite correttamente');
    }

    public function calcolak()
    {
        $kutenti = DB::table('utenti')->get();

        foreach ($kutenti as $item) {
            $k[$item->id]=$item->k;
        }

        $ore = DB::table('ore')->select('id', 'tempo', 'idUtente')->where('canc', 0)->get();

        foreach ($ore as $item) {
            /*DB::table('ore1')
                ->where('id', $item->id)
                ->update(array('tempo' => $item->tempo/$k[$item->idUtente],'k' => $k[$item->idUtente]));*/
            $parsed = date_parse($item->tempo);
            //return $parsed;
            $seconds= $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second'];


            $tempo = $seconds * $k[$item->idUtente]; // esempio (in secondi)
            $secondi = $tempo % 60;
            $tempo = ($tempo - $secondi) / 60; // in minuti
            $minuti = $tempo % 60;
            $tempo = ($tempo - $minuti) / 60; // in ore
            $ore = $tempo % 24;


            if ($ore == 0) {
                $ore = "00";
            }

            if ($minuti == 0) {
                $minuti = "00";
            }

            $tempoConvert="$ore:$minuti:00";
            $tempi[$item->id]=$item->tempo."-".$tempoConvert;


            DB::table('ore')
                ->where('id', $item->id)
                ->update(array('k'=> $k[$item->idUtente],'oreNette'=> $tempoConvert ));
        }

        return $tempi;
    }

    public function addmovimento(Request $request)
    {
        DB::table('movimenti')->insertGetId($request->all());

        return Redirect::action('gestioneOre@vcommessa', [$request->get('commessa')]);
    }
}

Zerion Mini Shell 1.0