mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add all task to invoice by project #1650
This commit is contained in:
parent
c31ba08a4c
commit
c4e74f35d1
@ -6,6 +6,7 @@ use App\Http\Requests\CreateProjectRequest;
|
||||
use App\Http\Requests\ProjectRequest;
|
||||
use App\Http\Requests\UpdateProjectRequest;
|
||||
use App\Models\Client;
|
||||
use App\Models\Project;
|
||||
use App\Ninja\Datatables\ProjectDatatable;
|
||||
use App\Ninja\Repositories\ProjectRepository;
|
||||
use App\Services\ProjectService;
|
||||
@ -95,6 +96,11 @@ class ProjectController extends BaseController
|
||||
|
||||
Session::flash('message', trans('texts.updated_project'));
|
||||
|
||||
$action = Input::get('action');
|
||||
if (in_array($action, ['archive', 'delete', 'restore', 'invoice'])) {
|
||||
return self::bulk();
|
||||
}
|
||||
|
||||
return redirect()->to($project->getRoute());
|
||||
}
|
||||
|
||||
@ -102,6 +108,42 @@ class ProjectController extends BaseController
|
||||
{
|
||||
$action = Input::get('action');
|
||||
$ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids');
|
||||
|
||||
if ($action == 'invoice') {
|
||||
$data = [];
|
||||
$clientPublicId = false;
|
||||
$lastClientId = false;
|
||||
$lastProjectId = false;
|
||||
$projects = Project::scope($ids)
|
||||
->with(['client', 'tasks' => function ($query) {
|
||||
$query->whereNull('invoice_id');
|
||||
}])
|
||||
->get();
|
||||
foreach ($projects as $project) {
|
||||
if (! $clientPublicId) {
|
||||
$clientPublicId = $project->client->public_id;
|
||||
}
|
||||
if ($lastClientId && $lastClientId != $project->client_id) {
|
||||
return redirect('projects')->withError(trans('texts.project_error_multiple_clients'));
|
||||
}
|
||||
$lastClientId = $project->client_id;
|
||||
|
||||
foreach ($project->tasks as $task) {
|
||||
if ($task->is_running) {
|
||||
return redirect('projects')->withError(trans('texts.task_error_running'));
|
||||
}
|
||||
$showProject = $lastProjectId != $task->project_id;
|
||||
$data[] = [
|
||||
'publicId' => $task->public_id,
|
||||
'description' => $task->present()->invoiceDescription(auth()->user()->account, $showProject),
|
||||
'duration' => $task->getHours(),
|
||||
'cost' => $task->getRate(),
|
||||
];
|
||||
$lastProjectId = $task->project_id;
|
||||
}
|
||||
}
|
||||
return redirect("invoices/create/{$clientPublicId}")->with('tasks', $data);
|
||||
} else {
|
||||
$count = $this->projectService->bulk($ids, $action);
|
||||
|
||||
if ($count > 0) {
|
||||
@ -113,3 +155,4 @@ class ProjectController extends BaseController
|
||||
return redirect()->to('/projects');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,14 @@ class Project extends EntityModel
|
||||
{
|
||||
return $this->belongsTo('App\Models\Client')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function tasks()
|
||||
{
|
||||
return $this->hasMany('App\Models\Task');
|
||||
}
|
||||
}
|
||||
|
||||
Project::creating(function ($project) {
|
||||
|
@ -59,6 +59,15 @@ class ProjectDatatable extends EntityDatatable
|
||||
return Auth::user()->can('editByOwner', [ENTITY_PROJECT, $model->user_id]);
|
||||
},
|
||||
],
|
||||
[
|
||||
trans('texts.invoice_project'),
|
||||
function ($model) {
|
||||
return "javascript:submitForm_project('invoice', {$model->public_id})";
|
||||
},
|
||||
function ($model) {
|
||||
return Auth::user()->can('create', ENTITY_INVOICE);
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1994,14 +1994,14 @@ $LANG = array(
|
||||
'created_project' => 'Successfully created project',
|
||||
'archived_project' => 'Successfully archived project',
|
||||
'archived_projects' => 'Successfully archived :count projects',
|
||||
'restore_project' => 'Restore project',
|
||||
'restore_project' => 'Restore Project',
|
||||
'restored_project' => 'Successfully restored project',
|
||||
'delete_project' => 'Delete project',
|
||||
'delete_project' => 'Delete Project',
|
||||
'deleted_project' => 'Successfully deleted project',
|
||||
'deleted_projects' => 'Successfully deleted :count projects',
|
||||
'delete_expense_category' => 'Delete category',
|
||||
'deleted_expense_category' => 'Successfully deleted category',
|
||||
'delete_product' => 'Delete product',
|
||||
'delete_product' => 'Delete Product',
|
||||
'deleted_product' => 'Successfully deleted product',
|
||||
'deleted_products' => 'Successfully deleted :count products',
|
||||
'restored_product' => 'Successfully restored product',
|
||||
@ -2586,7 +2586,8 @@ $LANG = array(
|
||||
'edit_subscription' => 'Edit Subscription',
|
||||
'archive_subscription' => 'Archive Subscription',
|
||||
'archived_subscription' => 'Successfully archived subscription',
|
||||
|
||||
'project_error_multiple_clients' => 'The projects can\'t belong to different clients',
|
||||
'invoice_project' => 'Invoice Project',
|
||||
|
||||
);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
</div>
|
||||
|
||||
<div class="pull-left">
|
||||
@if (in_array($entityType, [ENTITY_TASK, ENTITY_INVOICE, ENTITY_PRODUCT]))
|
||||
@if (in_array($entityType, [ENTITY_TASK, ENTITY_INVOICE, ENTITY_PRODUCT, ENTITY_PROJECT]))
|
||||
@can('create', 'invoice')
|
||||
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm_'.$entityType.'("invoice")'])->appendIcon(Icon::create('check')) !!}
|
||||
@endcan
|
||||
|
@ -3,7 +3,7 @@
|
||||
@section('content')
|
||||
|
||||
{!! Former::open($url)
|
||||
->addClass('col-md-10 col-md-offset-1 warn-on-exit')
|
||||
->addClass('col-md-10 col-md-offset-1 warn-on-exit main-form')
|
||||
->method($method)
|
||||
->rules([
|
||||
'name' => 'required',
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
<span style="display:none">
|
||||
{!! Former::text('public_id') !!}
|
||||
{!! Former::text('action') !!}
|
||||
</span>
|
||||
|
||||
<div class="row">
|
||||
@ -55,9 +56,27 @@
|
||||
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(HTMLUtils::previousUrl('/projects'))->appendIcon(Icon::create('remove-circle')) !!}
|
||||
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
|
||||
@if ($project && Auth::user()->can('create', ENTITY_TASK))
|
||||
{!! Button::primary(trans('texts.new_task'))->large()
|
||||
->asLinkTo(url('/tasks/create/' . ($project->client ? $project->client->public_id : '0'). '/' . $project->public_id))
|
||||
->appendIcon(Icon::create('plus-sign')) !!}
|
||||
{!! DropdownButton::normal(trans('texts.more_actions'))
|
||||
->withContents([
|
||||
[
|
||||
'url' => url('/tasks/create/' . ($project->client ? $project->client->public_id : '0'). '/' . $project->public_id),
|
||||
'label' => trans('texts.new_task'),
|
||||
],
|
||||
[
|
||||
'url' => 'javascript:submitAction("invoice")',
|
||||
'label' => trans('texts.invoice_project'),
|
||||
],
|
||||
\DropdownButton::DIVIDER,
|
||||
[
|
||||
'url' => 'javascript:submitAction("archive")',
|
||||
'label' => trans('texts.archive_project')
|
||||
],
|
||||
[
|
||||
'url' => 'javascript:onDeleteClick()',
|
||||
'label' => trans('texts.delete_project')
|
||||
],
|
||||
])
|
||||
->large() !!}
|
||||
@endif
|
||||
</center>
|
||||
|
||||
@ -68,6 +87,17 @@
|
||||
var clients = {!! $clients !!};
|
||||
var clientMap = {};
|
||||
|
||||
function submitAction(action) {
|
||||
$('#action').val(action);
|
||||
$('.main-form').submit();
|
||||
}
|
||||
|
||||
function onDeleteClick() {
|
||||
sweetConfirm(function() {
|
||||
submitAction('delete');
|
||||
});
|
||||
}
|
||||
|
||||
$(function() {
|
||||
var $clientSelect = $('select#client_id');
|
||||
for (var i=0; i<clients.length; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user