%PDF- %PDF-
Direktori : /var/www/pjc/app/Http/Controllers/ |
Current File : /var/www/pjc/app/Http/Controllers/Fatturazione.php |
<?php use Illuminate\Support\Facades\Response; namespace App\Http\Controllers; use DB; use App\Http\Controllers\Controller; use App\Models\User; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Input; use Illuminate\Http\Request; class Fatturazione extends Controller { /** * Display a listing of the resource. * * @return Response */ public function index() { $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('status','Draft') ->get(); $account=DB::table('accounts') ->select('id','name') ->where('deleted',0) ->get(); foreach ($account as $item) { $accounts[$item->id]=$item->name; } foreach($commesse as $item) { $saldo = DB::select(DB::raw("select sum(importo) as somma from movimenti where commessa='".$item->name."'")); $saldi[$item->name]=$saldo[0]->somma; } $dati['saldi']=$saldi; $dati['commesse']=$commesse; $dati['accounts']=$accounts; $dati['dato']=$saldo[0]->somma; return view('fatturazione.index')->withDati($dati); } /** * Show the form for creating a new resource. * * @return Response */ public function create() { // } /** * Store a newly created resource in storage. * * @return Response */ public function store() { // } /** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // } /** * 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 fattura($id) { $riga = DB::table('movimenti')->where('id',$id)->first(); if($riga->fatturato == 0) { DB::table('movimenti')->where('id',$id)->update(array('fatturato' => 1)); } if($riga->fatturato == 1) { DB::table('movimenti')->where('id',$id)->update(array('fatturato' => 0)); } return Redirect::action('Fatturazione@elencoFatture'); } public function elencoFatture() { $commesse=DB::table('project') ->join('projects_accounts','projects_accounts.project_id','=','project.id') ->join('project_cstm','project_cstm.id_c','=','project.id') ->join('movimenti','movimenti.commessa','=','project.name') ->select('project.id','name','description','estimated_start_date','status','projects_accounts.account_id', 'project_cstm.importo_c','movimenti.tipologia','movimenti.importo','movimenti.data','movimenti.pagamento','movimenti.fatturato','movimenti.id') ->where('project.deleted',0) ->where('projects_accounts.deleted',0) ->where('status','Draft') ->where('movimenti.fatturato',0) ->get(); $commesseFatturate=DB::table('project') ->join('projects_accounts','projects_accounts.project_id','=','project.id') ->join('project_cstm','project_cstm.id_c','=','project.id') ->join('movimenti','movimenti.commessa','=','project.name') ->select('project.id','name','description','estimated_start_date','status','projects_accounts.account_id', 'project_cstm.importo_c','movimenti.tipologia','movimenti.importo','movimenti.data','movimenti.pagamento','movimenti.fatturato','movimenti.id') ->where('project.deleted',0) ->where('projects_accounts.deleted',0) ->where('status','Draft') ->where('movimenti.fatturato',1) ->get(); $account=DB::table('accounts') ->select('id','name') ->where('deleted',0) ->get(); foreach ($account as $item) { $accounts[$item->id]=$item->name; } $dati['commesse']=$commesse; $dati['accounts']=$accounts; $dati['commesseFatturate']=$commesseFatturate; return view('fatturazione.elenco')->withDati($dati); } }