%PDF- %PDF-
| Direktori : /var/www/pjc/app/ |
| Current File : /var/www/pjc/app/Utility.php |
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class Utility extends Model
{
static public function totOre($importo, $costo) {
return number_format( $importo / $costo, 1 );
}
static public function totOreDoutente($id, $data) {
$somma = DB::select ( DB::raw ( "select sec_to_time(sum(time_to_sec(oreNette))) as somma from ore where ore.canc=0 and idUtente=$id and data='$data'" ) );
if ($somma[0]->somma) {
$valore = explode ( ":", $somma [0]->somma );
return $valore [0] . ":" . $valore [1];
} else {
return "00:00";
}
}
static public function totOreDo($id) {
$somma = DB::select ( DB::raw ( "select sec_to_time(sum(time_to_sec(oreNette))) as somma from ore where ore.canc=0 and commessa='" . $id . "'" ) );
$valore = explode ( ":", $somma [0]->somma );
if ($valore [0] == 838) {
$ore = DB::table ( 'ore' )->select ( 'oreNette' )->where ( 'commessa', $id )->where ( 'canc', 0 )->get ();
$totaleOre = 0;
foreach ( $ore as $item ) {
$tempo = explode ( ":", $item->oreNette );
$dec = 0;
if ($tempo [1] == 30) {
$dec = 5;
}
$valore1 = $tempo[0] . "." . $dec;
$totaleOre = $totaleOre + $valore1;
}
return $totaleOre;
}
return $valore [0];
}
static public function percentuale($oreFatte, $oreTot) {
if (($oreFatte > 0) and ($oreTot > 0)) {
$percentuale = ($oreFatte / $oreTot) * 100;
return ceil ( $percentuale );
}
}
static public function statoPerc($id) {
if ($id <= 60) {
return "progress-bar-success";
}
if (($id > 60) && ($id < 90)) {
return "progress-bar-warning";
}
if ($id >= 90) {
return "progress-bar-danger";
}
}
static public function getOreUtente($data, $id) {
$somma = DB::select ( DB::raw ( "select sec_to_time(sum(time_to_sec(oreNette))) as somma from ore where ore.canc=0 and data='" . $data . "' and idUtente=" . $id ) );
return $somma;
}
static public function calcTotali() {
$totOreDo = DB::select ( DB::raw ( "select sec_to_time(sum(time_to_sec(oreNette))) as somma from ore where ore.canc=0 and commessa='" . $id . "'" ) );
$importo = DB::table ( 'project' )->join ( 'projects_accounts', 'projects_accounts.project_id', '=', 'project.id' )->join ( 'project_cstm', 'project_cstm.id_c', '=', 'project.id' )->select ( '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', $commessa )->get ();
}
static public function giornoData($data) {
$data = explode ( "-", $data );
$g = $data [2];
$m = $data [1];
$a = $data [0];
$gShort = array (
'Domenica',
'Lunedì',
'Marted',
'Mercoledì',
'Giovedi',
'Venerdi',
'Sabato'
);
$ts = mktime ( 0, 0, 0, $m, $g, $a );
$gd = getdate ( $ts );
return $gShort [$gd ['wday']];
}
static public function oreCaricoMese($mese, $anno, $utente) {
$ore = DB::select ( DB::raw ( "SELECT id_tecnico, sec_to_time(sum(time_to_sec(carico))) as somma FROM planning where id_utente =". $utente ." and mese =" . $mese . " and anno=" . $anno . " Group by id_tecnico " ) );
return $ore;
}
static public function oreCaricoMeseNoComm($mese, $anno, $utente) {
$ore = DB::select ( DB::raw ( "SELECT id_tecnico, sec_to_time(sum(time_to_sec(carico))) as somma FROM planning where id_utente =". $utente ." and mese =" . $mese . " and anno=" . $anno . " and id_commessa NOT IN ('104') Group by id_tecnico " ) );
return $ore;
}
static public function oreCaricoMeseTot($mese, $anno, $utente,$tipo = 0) {
if($tipo)
{
//$ore = DB::select ( DB::raw ( "SELECT sec_to_time(sum(time_to_sec(carico))) as somma FROM planning where programmata = 0 and id_utente =". $utente ." and mese =" . $mese . " and anno=" . $anno ) );
$ore = DB::table('planning')
->where('programmata',0)
->where('id_utente',$utente)
->where('mese',$mese)
->where('anno',$anno)
->get();
$totale_ore=0;
foreach($ore as $item)
{
$numero = Utility::convertiore($item->carico);
$totale_ore = $totale_ore + $numero;
}
return Utility::convertioretime($totale_ore);
}
else
{
//$ore = DB::select ( DB::raw ( "SELECT sec_to_time(sum(time_to_sec(carico))) as somma FROM planning where id_utente =". $utente ." and mese =" . $mese . " and anno=" . $anno ) );
$ore = DB::table('planning')
->where('id_utente',$utente)
->where('mese',$mese)
->where('anno',$anno)
->get();
$totale_ore=0;
foreach($ore as $item)
{
$numero = Utility::convertiore($item->carico);
$totale_ore = $totale_ore + $numero;
}
return Utility::convertioretime($totale_ore);
}
return $ore [0]->somma;
}
static public function oreCaricoMeseTot2($mese, $anno, $settore) {
$ore = DB::select ( DB::raw ( "SELECT sec_to_time(sum(time_to_sec(carico))) as somma FROM planning where id_settore =". $settore ." and mese =" . $mese . " and anno=" . $anno ) );
return $ore [0]->somma;
}
static public function oreCommessaMese ($mese)
{
}
static public function calcolak($utente,$ore)
{
$kutenti = DB::table('utenti')->where('id',$utente)->first();
$parsed = date_parse($ore);
$seconds= $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second'];
$tempo = $seconds * $kutenti->k; // 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";
return $tempoConvert;
}
static public function convertiore($ore)
{
$dati = explode(':',$ore);
return $dati[0] + ($dati[1]/60);
}
static public function GetOrePlanningFatte($idTecnico,$mese,$anno)
{
$ore = DB::select ( DB::raw ( "SELECT sec_to_time(sum(time_to_sec(fatte))) as somma FROM planning where id_tecnico =". $idTecnico ." and mese =" . $mese . " and anno=" . $anno ) );
return $ore;
}
static public function GetOreFatte($idTecnico,$mese,$anno)
{
$ore = DB::select ( DB::raw ( "SELECT sec_to_time(sum(time_to_sec(tempo))) as somma FROM ore where canc =0 and idutente =". $idTecnico ." and MONTH(data) =" . $mese . " and YEAR(data)=20" . $anno ) );
return $ore;
}
static public function convertioretime($ore)
{
$dati = explode('.',$ore);
if(isset($dati[1]))
{
if($dati[1] == 0)
{
$time = $dati[0].":00:00";
}
if($dati[1] == 5)
{
$time = $dati[0].":30:00";
}
if($dati[1] == 25)
{
$time = $dati[0].":15:00";
}
if($dati[1] == 75)
{
$time = $dati[0].":45:00";
}
}
else
{
$time = $dati[0].":00:00";
}
return $time;
}
}