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