mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-12 14:12:44 +01:00
Support creating inline vendors and categories
This commit is contained in:
parent
57830316ad
commit
4e31686f56
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\ExpenseCategory;
|
||||
use App\Models\Vendor;
|
||||
|
||||
class ExpenseRequest extends EntityRequest
|
||||
{
|
||||
@ -25,28 +26,32 @@ class ExpenseRequest extends EntityRequest
|
||||
$input = $this->all();
|
||||
|
||||
// check if we're creating a new expense category
|
||||
if ($this->expense_category_id == '-1'
|
||||
&& trim($this->expense_category_name)
|
||||
&& $this->user()->can('create', ENTITY_EXPENSE_CATEGORY))
|
||||
{
|
||||
$category = app('App\Ninja\Repositories\ExpenseCategoryRepository')->save([
|
||||
'name' => trim($this->expense_category_name),
|
||||
]);
|
||||
$input['expense_category_id'] = $category->id;
|
||||
if ($this->expense_category_id == '-1') {
|
||||
$data = [
|
||||
'name' => trim($this->expense_category_name)
|
||||
];
|
||||
if (ExpenseCategory::validate($data) === true) {
|
||||
$category = app('App\Ninja\Repositories\ExpenseCategoryRepository')->save($data);
|
||||
$input['expense_category_id'] = $category->id;
|
||||
} else {
|
||||
$input['expense_category_id'] = null;
|
||||
}
|
||||
} elseif ($this->expense_category_id) {
|
||||
$input['expense_category_id'] = ExpenseCategory::getPrivateId($this->expense_category_id);
|
||||
}
|
||||
|
||||
// check if we're creating a new vendor
|
||||
if ($this->vendor_id == '-1'
|
||||
&& trim($this->vendor_name)
|
||||
&& $this->user()->can('create', ENTITY_VENDOR))
|
||||
{
|
||||
$vendor = app('App\Ninja\Repositories\VendorRepository')->save([
|
||||
'name' => trim($this->vendor_name),
|
||||
]);
|
||||
// TODO change to private id once service is refactored
|
||||
$input['vendor_id'] = $vendor->public_id;
|
||||
if ($this->vendor_id == '-1') {
|
||||
$data = [
|
||||
'name' => trim($this->vendor_name)
|
||||
];
|
||||
if (Vendor::validate($data) === true) {
|
||||
$vendor = app('App\Ninja\Repositories\VendorRepository')->save($data);
|
||||
// TODO change to private id once service is refactored
|
||||
$input['vendor_id'] = $vendor->public_id;
|
||||
} else {
|
||||
$input['vendor_id'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Project;
|
||||
|
||||
class TaskRequest extends EntityRequest
|
||||
{
|
||||
@ -13,15 +14,17 @@ class TaskRequest extends EntityRequest
|
||||
$input = $this->all();
|
||||
|
||||
// check if we're creating a new project
|
||||
if ($this->project_id == '-1'
|
||||
&& trim($this->project_name)
|
||||
&& $this->user()->can('create', ENTITY_PROJECT))
|
||||
{
|
||||
$project = app('App\Ninja\Repositories\ProjectRepository')->save([
|
||||
if ($this->project_id == '-1') {
|
||||
$project = [
|
||||
'name' => trim($this->project_name),
|
||||
'client_id' => Client::getPrivateId($this->client),
|
||||
]);
|
||||
$input['project_id'] = $project->public_id;
|
||||
];
|
||||
if (Project::validate($project) === true) {
|
||||
$project = app('App\Ninja\Repositories\ProjectRepository')->save($project);
|
||||
$input['project_id'] = $project->public_id;
|
||||
} else {
|
||||
$input['project_id'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Str;
|
||||
use Auth;
|
||||
use Eloquent;
|
||||
use Utils;
|
||||
@ -258,16 +259,22 @@ class EntityModel extends Eloquent
|
||||
* @param $data
|
||||
* @param $entityType
|
||||
* @param mixed $entity
|
||||
*
|
||||
* TODO Remove $entityType parameter
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function validate($data, $entityType, $entity = false)
|
||||
public static function validate($data, $entityType = false, $entity = false)
|
||||
{
|
||||
if (! $entityType) {
|
||||
$className = get_called_class();
|
||||
$entityBlank = new $className();
|
||||
$entityType = $entityBlank->getEntityType();
|
||||
}
|
||||
|
||||
// Use the API request if it exists
|
||||
$action = $entity ? 'update' : 'create';
|
||||
$requestClass = sprintf('App\\Http\\Requests\\%s%sAPIRequest', ucwords($action), ucwords($entityType));
|
||||
$requestClass = sprintf('App\\Http\\Requests\\%s%sAPIRequest', ucwords($action), Str::studly($entityType));
|
||||
if (! class_exists($requestClass)) {
|
||||
$requestClass = sprintf('App\\Http\\Requests\\%s%sRequest', ucwords($action), ucwords($entityType));
|
||||
$requestClass = sprintf('App\\Http\\Requests\\%s%sRequest', ucwords($action), Str::studly($entityType));
|
||||
}
|
||||
|
||||
$request = new $requestClass();
|
||||
|
@ -540,9 +540,7 @@
|
||||
var clientId = $('input[name=client]').val();
|
||||
var projectId = $('input[name=project_id]').val();
|
||||
var project = projectMap[projectId];
|
||||
if (projectId == '-1') {
|
||||
e.preventDefault();return;
|
||||
} else if (project && ((project.client && project.client.public_id == clientId) || !project.client)) {
|
||||
if (project && ((project.client && project.client.public_id == clientId) || !project.client)) {
|
||||
e.preventDefault();return;
|
||||
}
|
||||
setComboboxValue($('.project-select'), '', '');
|
||||
@ -550,7 +548,9 @@
|
||||
$projectCombobox.find('option').remove().end().combobox('refresh');
|
||||
$projectCombobox.append(new Option('', ''));
|
||||
@if (Auth::user()->can('create', ENTITY_PROJECT))
|
||||
$projectCombobox.append(new Option("{{ trans('texts.create_project')}}: $name", '-1'));
|
||||
if (clientId) {
|
||||
$projectCombobox.append(new Option("{{ trans('texts.create_project')}}: $name", '-1'));
|
||||
}
|
||||
@endif
|
||||
var list = clientId ? (projectsForClientMap.hasOwnProperty(clientId) ? projectsForClientMap[clientId] : []).concat(projectsForAllClients) : projects;
|
||||
for (var i=0; i<list.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user