%PDF- %PDF-
| Direktori : /var/www/pjold/app/Http/Controllers/ |
| Current File : /var/www/pjold/app/Http/Controllers/Planning.php |
<?php
use Illuminate\Support\Facades\Response;
namespace App\Http\Controllers;
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 Planning extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
if ((Session::get('idUtente') == 5) or (Session::get('idUtente') == 6) or (Session::get('idUtente') == 13) or (Session::get('idUtente') == 1) or (Session::get('idUtente') == 27)) {
$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', Session::get('idSettore'))
->sum('importo_c');
$oreAssegnate = DB::select(DB::raw("select sum(carico) as somma,mese from planning where id_settore=" . Session::get('idSettore') . " group by mese"));
$oreMeseCarico = array();
foreach ($oreAssegnate as $value) {
$oreMeseCarico[$value->mese] = ($value->somma);
}
$mesi = array(
'-',
'Gennaio',
'Febbraio',
'Marzo',
'Aprile',
'Maggio',
'Giugno',
'Luglio',
'Agosto',
'Settembre',
'Ottobre',
'Novembre',
'Dicembre'
);
return view('planning.index')
->withImportototale($importoTotale)
->withOrecarico($oreMeseCarico)
->withMesi($mesi);
} else {
return Redirect::action('gestioneOre@ore', [Session::get('idUtente')]);
}
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create($mese, $anno)
{
$mesePass = $mese;
$importoPianificato = 0;
//CREO ARRAY DEI TECNICI DI QUEL SETTORE
$capo = DB::table('utenti')
->where('id', Session::get('idUtente'))
->get();
$tecniciAppoggio = DB::table('utenti')
->where('attivo', 1)
->where('idsettore', $capo[0]->idsettore)
->get();
$valori_budget = array();
$budget = DB::table('budget')->where('idSettore', $capo[0]->idsettore)->get();
foreach ($budget as $valori) {
$valori_budget[$valori->mese] = $valori->importo;
}
foreach ($tecniciAppoggio as $key) {
$tecnici [$key->id] = $key->cognome;
$tecniciId = $key->id;
}
//RECUPERO LE ORE PER CIASCUN TECNICO FATTE NEL MESE per il caposettore
$oreAssegnate = Utility::oreCaricoMese($mese, $anno, Session::get('idUtente'));
//CREA ARRAY CON ID TECNICO E LE ORE ASSEGANTE
$oreAss = array();
foreach ($oreAssegnate as $value) {
$oreAss [$value->id_tecnico] = $value->somma;
}
$oreAssegnateNo = Utility::oreCaricoMeseNoComm($mese, $anno, Session::get('idUtente'));
//CREA ARRAY CON ID TECNICO E LE ORE ASSEGANTE
$oreAssNo = array();
foreach ($oreAssegnateNo as $value) {
$oreAssNo[$value->id_tecnico] = $value->somma;
}
//CREO ARRAY DEI TECNICI CON NOME
$tecniciAppoggio = DB::table('utenti')
->where('attivo', 1)
->where('settore', $capo[0]->settore)
->get();
foreach ($tecniciAppoggio as $key) {
if (isset ($oreAss [$key->id])) {
$dato = $oreAss [$key->id];
} else {
$dato = 0;
}
$tecniciOre [$key->id] = $key->cognome . " --- (occupato per: " . $dato . " )";
}
//RECUPERO LE ORE ASSENGNATE DAL CAPOSETTORE NEL MESE E ANNO SPECIFICO
$planning = DB::table('planning')
->join('utenti','utenti.id','=','planning.id_utente')
//->whereNotIn('id_commessa',['103','104'])
->where('mese', $mese)
->where('anno', $anno)
->where('planning.id_utente', Session::get('idUtente'))->get();
if (count($planning)) {
foreach ($planning as $key) {
$commesse[] = $key->id_commessa;
}
} else {
$commesse = array();
}
//CALCOLO IL VALORE DELLE ORE SCELTE DAL CAPOSETTORE
foreach ($planning as $item) {
$importoPianificato = $importoPianificato + (Utility::convertiore($item->carico) * 62.5 * $item->k);
}
//CREO ARRAY DEI NOMI CLIENTI
$account = DB::table('accounts')->select('id', 'name')->where('deleted', 0)->get();
foreach ($account as $item) {
$accounts [$item->id] = $item->name;
}
//CREO ARRAY DELLE COMMESSE DEL CRM
$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')
->whereIn('name', $commesse)
->get();
// return $commesseAppoggio;
$totaleCommesse = 0;
foreach ($commesseAppoggio as $key) {
$totaleCommesse = +$key->importo_c;
$commesse [$key->name] = $key;
}
$mesi = array(
'-',
'Gennaio',
'Febbraio',
'Marzo',
'Aprile',
'Maggio',
'Giugno',
'Luglio',
'Agosto',
'Settembre',
'Ottobre',
'Novembre',
'Dicembre'
);
$kTecnici = DB::table('utenti')->get();
foreach ($kTecnici as $item) {
$k_array[$item->id] = $item->k;
}
if(isset($valori_budget[$mese]))
{
$valore = $valori_budget[$mese];
}
else{
$valore =0;
}
return view('planning.create')
->withPianificato($importoPianificato)
->withImporto($totaleCommesse)
->withTecniciore($tecniciOre)
->withCommesse($commesse)
->withAccounts($accounts)
->withTecnici($tecnici)
->withMese($mesi[$mese])
->withMesenumero($mese)
->withAnno($anno)
->withPlanning($planning)
->withMesen($mesePass)
->withKutenti($k_array)
->withBudget($valore)
->withOreass($oreAss)
->withOreassno($oreAssNo);
}
public function addCommessa($mese, $anno)
{
$capo = DB::table('utenti')
->where('id', Session::get('idUtente'))
->get();
$account = DB::table('accounts')->select('id', 'name')->where('deleted', 0)->get();
foreach ($account as $item) {
$accounts [$item->id] = $item->name;
}
$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('project_cstm.settore_c', Session::get('idSettore'))
->where('projects_accounts.deleted', 0)
// ->where('estimated_start_date' ,'>', '2014-01-01')
->whereIn('status',['Draft','apertamafatturata'])
->get();
foreach ($commesseAppoggio as $key) {
$ore = Utility::totOre($key->importo_c, 62.5);
$oreFatte = Utility::totOreDo($key->name);
$rimanenza = (float)$ore - (float)$oreFatte;
$commesse [$key->name] = $key->name . "-" . $accounts [$key->account_id] . " - ore rimanenti: " . $rimanenza . " - " . substr($key->description, 0, 100);
}
$oreAssegnate = Utility::oreCaricoMese($mese, $anno, Session::get('idUtente'));
foreach ($oreAssegnate as $value) {
$oreAss [$value->id_tecnico] = $value->somma;
}
$tecniciAppoggio = DB::table('utenti')
->where('idsettore', $capo[0]->idsettore)
->where('attivo', 1)
->get();
foreach ($tecniciAppoggio as $key) {
if (isset ($oreAss [$key->id])) {
$dato = $oreAss [$key->id];
} else {
$dato = 0;
}
$tecnici [$key->id] = $key->cognome . " --- (occupato per: " . $dato . " )";
}
$mesi = array(
'-',
'Gennaio',
'Febbraio',
'Marzo',
'Aprile',
'Maggio',
'Giugno',
'Luglio',
'Agosto',
'Settembre',
'Ottobre',
'Novembre',
'Dicembre'
);
return view('planning.addCommessa')
->withCommesse($commesse)
->withTecnici($tecnici)
->withMese($mesi [$mese])
->withAnno($anno)
->withMesen($mese);
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$dati = $request->all();
if(isset($dati['programmata']))
{
$dati['programmata'] = 1;
}
$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('estimated_start_date' ,'>', '2014-01-01')
//where('status', 'Draft')
->where('name', $dati ['id_commessa'])->get();
$ore = Utility::totOre($commesseAppoggio [0]->importo_c, 62.5);
$id = DB::table('planning')->insertGetId($dati);
return Redirect::action('Planning@create', [
$dati ['mese'],
$dati ['anno']
]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
public function elencoplanning($mese, $anno)
{
$mesePass = $mese;
$importoPianificato = 0;
//CREO ARRAY DEI TECNICI DI QUEL SETTORE
$capo = DB::table('utenti')
->where('id', Session::get('idUtente'))
->get();
$tecniciAppoggio = DB::table('utenti')
->where('attivo', 1)
->get();
$budget = DB::table('budget')->where('idSettore', $capo[0]->idsettore)->get();
foreach ($budget as $valori) {
$valori_budget[$valori->mese] = $valori->importo;
}
foreach ($tecniciAppoggio as $key) {
$tecnici [$key->id] = $key->cognome;
$tecniciId = $key->id;
}
//RECUPERO LE ORE PER CIASCUN TECNICO FATTE NEL MESE per il caposettore
$oreAssegnate = Utility::oreCaricoMese($mese, $anno, Session::get('idUtente'));
//CREA ARRAY CON ID TECNICO E LE ORE ASSEGANTE
$oreAss = array();
foreach ($oreAssegnate as $value) {
$oreAss [$value->id_tecnico] = $value->somma;
}
//CREO ARRAY DEI TECNICI CON NOME
$tecniciAppoggio = DB::table('utenti')
->where('attivo', 1)
->where('settore', $capo[0]->settore)
->get();
foreach ($tecniciAppoggio as $key) {
if (isset ($oreAss [$key->id])) {
$dato = $oreAss [$key->id];
} else {
$dato = 0;
}
$tecniciOre [$key->id] = $key->cognome . " --- (occupato per: " . $dato . " )";
}
//RECUPERO LE ORE ASSENGNATE DAL CAPOSETTORE NEL MESE E ANNO SPECIFICO
$planning = DB::table('planning')
->where('mese', $mese)
->where('anno', $anno)
->get();
return $planning;
if (count($planning)) {
foreach ($planning as $key) {
$commesse[] = $key->id_commessa;
}
} else {
$commesse = array();
}
//CALCOLO IL VALORE DELLE ORE SCELTE DAL CAPOSETTORE
foreach ($planning as $item) {
return $item->carico * 62.5;
$importoPianificato = $importoPianificato + ($item->carico * 62.5);
}
//CREO ARRAY DEI NOMI CLIENTI
$account = DB::table('accounts')->select('id', 'name')->where('deleted', 0)->get();
foreach ($account as $item) {
$accounts [$item->id] = $item->name;
}
//CREO ARRAY DELLE COMMESSE DEL CRM
$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')
->whereIn('name', $commesse)
->get();
// return $commesseAppoggio;
$totaleCommesse = 0;
foreach ($commesseAppoggio as $key) {
$totaleCommesse = +$key->importo_c;
$commesse [$key->name] = $key;
}
$mesi = array(
'-',
'Gennaio',
'Febbraio',
'Marzo',
'Aprile',
'Maggio',
'Giugno',
'Luglio',
'Agosto',
'Settembre',
'Ottobre',
'Novembre',
'Dicembre'
);
$kTecnici = DB::table('utenti')->get();
foreach ($kTecnici as $item) {
$k_array[$item->id] = $item->k;
}
if(isset($valori_budget[$mese]))
{
$valore = $valori_budget[$mese];
}
else{
$valore =0;
}
return view('planning.elenco')
->withPianificato($importoPianificato)
->withImporto($totaleCommesse)
->withTecniciore($tecniciOre)
->withCommesse($commesse)
->withAccounts($accounts)
->withTecnici($tecnici)
->withMese($mesi [$mese])
->withAnno($anno)
->withPlanning($planning)
->withMesen($mesePass)
->withKutenti($k_array)
->withBudget($valore)
->withOreass($oreAss);
}
}