Commit b2733f9f by hannan

crud upload attachment files

parent cc0a7c6f
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateNotesAttachementTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notes_attachement', function (Blueprint $table) {
$table->increments('id');
$table->integer('fk_timesheet_master')->nullable();
$table->string('path')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('notes_attachement');
}
}
......@@ -505,7 +505,7 @@
<table id="printtable5" class="ui celled structured table unstackable">
<thead>
<tr>
<th colspan="2" class="center aligned">Note</th>
<th colspan="2" class="center aligned">Notes</th>
</tr>
</thead>
<tbody>
......@@ -523,6 +523,30 @@
@endif
</tbody>
</table>
@if(data_get($check,'attachement'))
<table id="printtable5" class="ui celled structured table unstackable">
<thead>
<tr>
<th colspan="2" class="center aligned">Notes Attachment</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width: 13.5%;">Notes Attachement</td>
<td>
<a href="{{ asset(data_get($check,'attachement.path'))}}" target="_blank">
<button class="ui active button">
<i class="download icon"></i>
Download
</button>
</a>
</td>
</tr>
</tbody>
</table>
@endif
</div>
<div class="ui segment">
......
......@@ -2,14 +2,44 @@
@section('content')
<div class="ui small modal uploadmodal">
<div class="header">
Upload Attachment
</div>
<div class="content">
<form class="ui form" action="/action/upload" method="POST" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" name="id" value="{{$fk_tm_id}}">
<div class="field">
<label>Title</label>
<input type="file" name="attachment" id="uploadfile" style="">
</div>
<button class="ui blue button" type="submit">Upload</button>
</form>
</div>
</div>
<div class="ui unstackable segment">
<a class="ui blue left ribbon label">Senarai Notes</a>
<a href="{{ route('timesheet::form.penambahannote') }}" class="ui right floated small purple labeled icon button">
<i class="plus icon"></i>Upload Attachment
</a>
<a href="{{ route('timesheet::form.penambahannote') }}" class="ui right floated small yellow labeled icon button">
<i class="plus icon"></i>Add New Notes
</a><br>
kalau user dept bdd, display upload files.
<!-- <form action="">
<label for="uploadfile" class="ui right floated small purple labeled icon button">
<i class="plus icon"></i>Upload Attachment
</label>
<input type="file" name="attachment" id="uploadfile" style="display: none;">
</form> -->
<button class="ui right floated small purple labeled icon button" id="uploadmodal">
<i class="file icon"></i>
Upload File
</button>
<a href="{{ route('timesheet::form.penambahannote') }}" class="ui right floated small yellow labeled icon button">
<i class="plus icon"></i>Add New Notes
</a><br><br>
<table class="ui celled padded table">
<thead>
<tr>
......@@ -30,9 +60,7 @@
@endforeach
</tbody>
</table>
<form action="">
<input type="file" name="attachment">
</form><br>
<button class="center aligned ui teal compact labeled icon button" onclick="window.location.href='{{ route('timesheet::form.overheadForm', ['phase' => $phase, 'month' => $month]) }}';">
<i class="angle double left icon"></i>
Overhead Form
......@@ -44,3 +72,23 @@
</div>
@endsection
@push('script')
<script>
$(function(){
$("#uploadmodal").click(function()
{
$(".uploadmodal").modal('show');
});
$(".uploadmodal").modal(
{
closable: true
});
$(".uploadmodal").modal('attach events', '.close.button');
});
</script>
@endpush
\ No newline at end of file
......@@ -70,6 +70,7 @@ Route::group(
Route::post('nonchargeableselectmonthphase', ['uses' => 'FormController@nonchargeableselectmonthphase', 'as' => 'form.nonchargeableselectmonthphase']);
Route::post('overheadselectmonthphase', ['uses' => 'FormController@overheadselectmonthphase', 'as' => 'form.overheadselectmonthphase']);
Route::post('noteselectmonthphase', ['uses' => 'FormController@noteselectmonthphase', 'as' => 'form.noteselectmonthphase']);
Route::post('action/upload', ['uses' => 'FormController@uploadAttachement', 'as' => 'form.upload']);
// nonChargeableForm
Route::post('addnonchargeabletask',['uses' => 'FormController@addnonchargeabletask', 'as' => 'form.addnonchargeabletask']);
......
......@@ -321,7 +321,9 @@ class DashboardController extends Controller
->where('tm_year', $year)
->where('tm_month', $month)
->where('tm_phase', $phase)
->with('attachement')
->first();
if($check)
{
......
......@@ -24,6 +24,8 @@ use App\Mail\StatusReject;
use Mail;
use Curl;
use Auth;
use Portal\Timesheet\Model\NotesAttachement;
class FormController extends Controller
{
......@@ -1100,4 +1102,77 @@ class FormController extends Controller
return redirect()->route('timesheet::form.notelist', ['year'=> $data->tm_year, 'month' =>$data->tm_month, 'phase' => $data->tm_phase, 'fk_tm_id' => $data->fk_tm_id])->with('success', 'Note Added');;
}
/**
* undocumented function
*
* @return void
* @author
**/
public function uploadAttachement(Request $request)
{
// dd($request->attachment);
$check = NotesAttachement::where('fk_timesheet_master',$request->id)->first();
$folder = "notes";
$date = date('Ymd');
$id = $request->id;
$files = $request->attachment;
if (!file_exists(public_path().'/uploads')) {
mkdir(public_path()."/uploads");
}
if (!file_exists(public_path().'/uploads/timesheet')) {
mkdir(public_path()."/uploads/timesheet");
}
if (!file_exists(public_path().'/uploads/timesheet/'.$folder)) {
mkdir(public_path()."/uploads/timesheet/".$folder);
}
if (!file_exists(public_path().'/uploads/timesheet/notes/'.$id)) {
mkdir(public_path()."/uploads/timesheet/notes/".$id);
}
$path = public_path()."/uploads/timesheet/notes/".$id;
$filename= $files->getClientOriginalName();
$shortpath = "/uploads/timesheet/notes/".$id."/".$filename;
// $photo->move($path, $photo->getClientOriginalName());
$filename= $files->getClientOriginalName();
$extension = $files->getClientOriginalExtension();
$size= $files->getSize();
$files->move($path, $files->getClientOriginalName());
if($check){
$upd = NotesAttachement::where('fk_timesheet_master',$request->id)->first();
// $upd->fk_timesheet_master = $request->id;
$upd->path = $shortpath;
$upd->save();
}else{
$upd = new NotesAttachement;
$upd->fk_timesheet_master = $request->id;
$upd->path = $shortpath;
$upd->save();
}
return redirect()->back()->withSuccess('Berjaya mengemaskini attachment');
}
}
\ No newline at end of file
<?php
namespace Portal\Timesheet\Model;
use Illuminate\Database\Eloquent\Model;
class NotesAttachement extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'notes_attachement';
/**
* undocumented function
*
* @return void
* @author
**/
public function timesheet()
{
return $this->belongsTo('Portal\Timesheet\Model\ts_master','fk_timesheet_master','id');
}
}
......@@ -24,9 +24,9 @@ class Ts_master extends Model
* @return void
* @author
**/
public function info()
public function attachement()
{
return $this->hasOne('Portal\Timesheet\Model\NotesAttachement','fk_timesheet_master','id');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment