Skip to content

Commit

Permalink
Input amount in payment
Browse files Browse the repository at this point in the history
  • Loading branch information
mnvx committed Dec 11, 2018
1 parent 2546d76 commit 9848098
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 26 deletions.
13 changes: 12 additions & 1 deletion app/Http/Controllers/ContributorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Http\Controllers;

use App\Model\Entity\Contributor;
use App\Model\Service\Eloquent\EloquentContributorService;
use App\Providers\AppServiceProvider;

class ContributorController extends CrudController
{
Expand All @@ -11,7 +13,16 @@ class ContributorController extends CrudController
*/
protected function getService()
{
return app(EloquentContributorService::class);
return app(AppServiceProvider::ELOQUENT_CONTRIBUTOR_SERVICE);
}

public function rate(int $id)
{
/** @var Contributor $contributor */
$contributor = $this->getService()->getObjectForEdit($id);
return $this->jsonSuccess([
'hour_rate' => $contributor->extra ? $contributor->extra->hour_rate : null,
]);
}

}
2 changes: 1 addition & 1 deletion app/Http/Controllers/IssueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IssueController extends CrudController
*/
protected function getService()
{
return app(EloquentIssueService::class);
return app(AppServiceProvider::ELOQUENT_ISSUE_SERVICE);
}

protected function prepareDataForIndex(FormRequest $request, array $data)
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/MilestoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Model\Service\Eloquent\EloquentMilestoneService;
use App\Providers\AppServiceProvider;

class MilestoneController extends CrudController
{
Expand All @@ -11,7 +12,7 @@ class MilestoneController extends CrudController
*/
protected function getService()
{
return app(EloquentMilestoneService::class);
return app(AppServiceProvider::ELOQUENT_GROUP_MILESTONE_SERVICE);
}

}
3 changes: 2 additions & 1 deletion app/Http/Controllers/NoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Model\Service\Eloquent\EloquentNoteService;
use App\Providers\AppServiceProvider;

class NoteController extends CrudController
{
Expand All @@ -11,7 +12,7 @@ class NoteController extends CrudController
*/
protected function getService()
{
return app(EloquentNoteService::class);
return app(AppServiceProvider::ELOQUENT_NOTE_SERVICE);
}

}
2 changes: 1 addition & 1 deletion app/Http/Controllers/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PaymentController extends CrudController
*/
protected function getService()
{
return app(EloquentPaymentService::class);
return app(AppServiceProvider::ELOQUENT_PAYMENT_SERVICE);
}

protected function prepareDataForCreate(FormRequest $request, array $data)
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Model\Service\Eloquent\EloquentProjectService;
use App\Providers\AppServiceProvider;

class ProjectController extends CrudController
{
Expand All @@ -11,7 +12,7 @@ class ProjectController extends CrudController
*/
protected function getService()
{
return app(EloquentProjectService::class);
return app(AppServiceProvider::ELOQUENT_PROJECT_SERVICE);
}

}
2 changes: 1 addition & 1 deletion app/Http/Controllers/TimeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TimeController extends CrudController
*/
protected function getService()
{
return app(EloquentSpentService::class);
return app(AppServiceProvider::ELOQUENT_SPENT_SERVICE);
}

protected function prepareDataForIndex(FormRequest $request, array $data)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UserController extends CrudController
*/
protected function getService()
{
return app(EloquentUserService::class);
return app(AppServiceProvider::ELOQUENT_USER_SERVICE);
}

protected function prepareDataForEdit(FormRequest $request, array $data)
Expand Down
1 change: 1 addition & 0 deletions app/Model/Entity/Contributor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @property string state
* @property string avatar_url
* @property string web_url
* @property ContributorExtra extra
*/
class Contributor extends EntityAbstract
{
Expand Down
9 changes: 8 additions & 1 deletion app/Model/Entity/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
* @property int id
* @property string title
* @property string description
* @property float amount
* @property float hour_rate
* @property float hours
* @property int status_id
* @property string payment_date
* @property int user_id
* @property int contributor_id
* @property int created_by_id
* @property int updated_by_id
*/
class Payment extends EntityAbstract
{
Expand All @@ -26,6 +31,8 @@ class Payment extends EntityAbstract
'id',
'title',
'description',
'amount',
'hour_rate',
'hours',
'status_id',
'payment_date',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AlterPaymentTableAddAmountAndHourRateColumns extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('payment', function (Blueprint $table) {
$table->decimal('amount')->nullable();
$table->decimal('hour_rate')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('payment', function (Blueprint $table)
{
$table->dropColumn('amount');
$table->dropColumn('hour_rate');
});
}
}
3 changes: 3 additions & 0 deletions database/seeds/RolePermissionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public function run()
$defaultPermissions,
User::ROLE_FINANCE =>
$defaultPermissions +
[
'contributor.rate' => 'contributor.rate',
] +
$this->generatePermissions('contributor', self::TYPE_VIEW) +
$this->generatePermissions('contributor', self::TYPE_WRITE) +
$this->generatePermissions('payment', self::TYPE_VIEW) +
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'Add' => 'Add',
'Added by mistake or occurs problem with payment' => 'Added by mistake or occurs problem with payment',
'Admin' => 'Admin',
'Amount' => 'Amount',
'Apply' => 'Apply',
'Assignee' => 'Assignee',
'Author' => 'Author',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/ru/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'Add' => 'Добавить',
'Added by mistake or occurs problem with payment' => 'Добавлено ошибочно или возникла проблема с платежом',
'Admin' => 'Администрирование',
'Amount' => 'Сумма',
'Apply' => 'Применить',
'Assignee' => 'Исполнитель',
'Author' => 'Автор',
Expand Down
5 changes: 1 addition & 4 deletions resources/views/gitpab/contributor/index_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
<tr>
<td class="col-md-1"><a href="{{ route('contributor.show', $item->id) }}">{{ $item->id }}</a></td>
<td class="col-md-4">
@if ($item->avatar_url)
<img src="{{ $item->avatar_url }}" class="cell-avatar"/>
@endif
{{ $item->name }}
@include('partial.table.td-contributor', ['item' => $item])
</td>
<td class="col-md-2">
<a href="{{ $item->web_url }}">{{ $item->username }}</a>
Expand Down
66 changes: 56 additions & 10 deletions resources/views/gitpab/payment/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

<div class="row">
<div class="col-md-6">
@include('partial.form.element.text', [
'name' => 'hours',
'label' => __('messages.Payed hours'),
@include('partial.form.element.select', [
'name' => 'contributor_id',
'label' => __('messages.Employer'),
'list' => $contributorList ?? [],
])
</div>
<div class="col-md-6">
@include('partial.form.element.text', [
'name' => 'title',
'label' => __('messages.Short comment'),
'name' => 'hour_rate',
'label' => __('messages.Hour rate'),
])
</div>
<div class="col-md-6">
@include('partial.form.element.select', [
'name' => 'contributor_id',
'label' => __('messages.Employer'),
'list' => $contributorList ?? [],
@include('partial.form.element.text', [
'name' => 'amount',
'label' => __('messages.Amount'),
])
</div>
<div class="col-md-6">
Expand All @@ -31,6 +31,20 @@
'list' => $statusList ?? [],
])
</div>
</div>
<div class="row">
<div class="col-md-6">
@include('partial.form.element.text', [
'name' => 'hours',
'label' => __('messages.Payed hours'),
])
</div>
<div class="col-md-6">
@include('partial.form.element.text', [
'name' => 'title',
'label' => __('messages.Short comment'),
])
</div>
<div class="col-md-6">
@include('partial.form.element.date', [
'name' => 'payment_date',
Expand All @@ -48,4 +62,36 @@
</div>
</div>

@endsection
@endsection

@push('js')
<script>
function calculateHours() {
console.log('-');
var payedHours = null;
if ($('[name="hour_rate"]').val()) {
payedHours = $('[name="amount"]').val() / $('[name="hour_rate"]').val();
payedHours = payedHours.toFixed(2);
}
$('[name="hours"]').val(payedHours);
}
$('[name="contributor_id"]').on('select2:select', function (e) {
$.get('{{ route('contributor.rate', '#contributor_id#') }}'.replace('#contributor_id#', e.params.data.id))
.done(function(response) {
if (response.status && response.status.result === 'success') {
$('[name="hour_rate"]').val(response.data.hour_rate);
calculateHours();
}
});
});
$('[name="hour_rate"]').on('input', function (e) {
calculateHours();
});
$('[name="amount"]').on('input', function (e) {
calculateHours();
});
</script>
@endpush
15 changes: 13 additions & 2 deletions resources/views/gitpab/payment/index_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
'orderLinkRoute' => $indexRoute,
])

@include('partial.table.thcell', [
'column' => 'amount',
'label' => __('messages.Amount'),
'order' => $order,
'orderDirection' => $orderDirection,
'orderLinkRoute' => $indexRoute
])

@include('partial.table.thcell', [
'column' => 'hours',
'label' => __('messages.Payed hours'),
Expand Down Expand Up @@ -72,9 +80,12 @@
@forelse ($itemsList->items() as $key => $item)
<tr>
<td class="col-md-1"><a href="{{ route('payment.show', $item->id) }}">{{ $item->id }}</a></td>
<td class="col-md-1">{{ $item->amount }}</td>
<td class="col-md-1">{{ $item->hours }}</td>
<td class="col-md-2">{{ $item->contributor->name }}</td>
<td class="col-md-3">{{ $item->title }}</td>
<td class="col-md-2">
@include('partial.table.td-contributor', ['item' => $item->contributor])
</td>
<td class="col-md-2">{{ $item->title }}</td>
<td class="col-md-1">@lang($item->status->title)</td>
<td class="col-md-1">{{ $item->payment_date }}</td>
<td class="col-md-1">
Expand Down
4 changes: 3 additions & 1 deletion resources/views/gitpab/user/index_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
<tr>
<td class="col-md-1"><a href="{{ route('user.show', $item->id) }}">{{ $item->id }}</a></td>
<td class="col-md-2">{{ $item->name }}</td>
<td class="col-md-2">{{ $item->contributor ? $item->contributor->name : '' }}</td>
<td class="col-md-2">
@include('partial.table.td-contributor', ['item' => $item->contributor])
</td>
<td class="col-md-2">{{ $item->email }}</td>
<td class="col-md-2">
@foreach ($item->roles as $role)
Expand Down
6 changes: 6 additions & 0 deletions resources/views/partial/table/td-contributor.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@if ($item)
@if ($item->avatar_url)
<img src="{{ $item->avatar_url }}" class="cell-avatar"/>
@endif
{{ $item->name }}
@endif
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@
Route::resource('payment', '\\' . PaymentController::class);
Route::resource('user', '\\' . UserController::class);

Route::get('/contributor/{id}/rate', '\\' . ContributorController::class . '@rate')
->name('contributor.rate');

});

0 comments on commit 9848098

Please sign in to comment.