diff --git a/app/Http/Requests/ExpenseRequest.php b/app/Http/Requests/ExpenseRequest.php index 03ee478ebb65..d192463ba9f2 100644 --- a/app/Http/Requests/ExpenseRequest.php +++ b/app/Http/Requests/ExpenseRequest.php @@ -24,11 +24,24 @@ class ExpenseRequest extends EntityRequest { $input = $this->all(); - if ($this->expense_category_id) { + if ($this->expense_category_id == '-1' && $this->user()->can('create', ENTITY_EXPENSE_CATEGORY)) { + $category = app('App\Ninja\Repositories\ExpenseCategoryRepository')->save([ + 'name' => $this->expense_category_name, + ]); + $input['expense_category_id'] = $category->id; + } elseif ($this->expense_category_id) { $input['expense_category_id'] = ExpenseCategory::getPrivateId($this->expense_category_id); - $this->replace($input); } + if ($this->vendor_id == '-1' && $this->user()->can('create', ENTITY_VENDOR)) { + $vendor = app('App\Ninja\Repositories\VendorRepository')->save([ + 'name' => $this->vendor_name, + ]); + $input['vendor_id'] = $vendor->public_id; + } + + $this->replace($input); + return $this->all(); } } diff --git a/app/Http/Requests/TaskRequest.php b/app/Http/Requests/TaskRequest.php index a9af01ada365..f18a478d3da2 100644 --- a/app/Http/Requests/TaskRequest.php +++ b/app/Http/Requests/TaskRequest.php @@ -2,6 +2,8 @@ namespace App\Http\Requests; +use App\Models\Client; + class TaskRequest extends EntityRequest { protected $entityType = ENTITY_TASK; @@ -11,10 +13,10 @@ class TaskRequest extends EntityRequest $input = $this->all(); // check if we're creating a new project - if ($this->input('project_id') == '-1' && $this->user()->can('create', ENTITY_PROJECT)) { - $project = app('App\Services\ProjectService')->save([ - 'name' => $this->input('project_name'), - 'client_id' => $this->input('client') + if ($this->project_id == '-1' && $this->user()->can('create', ENTITY_PROJECT)) { + $project = app('App\Ninja\Repositories\ProjectRepository')->save([ + 'name' => $this->project_name, + 'client_id' => Client::getPrivateId($this->client), ]); $input['project_id'] = $project->public_id; } diff --git a/app/Ninja/Repositories/VendorRepository.php b/app/Ninja/Repositories/VendorRepository.php index 0b5364841753..e0729a8f7a09 100644 --- a/app/Ninja/Repositories/VendorRepository.php +++ b/app/Ninja/Repositories/VendorRepository.php @@ -85,7 +85,14 @@ class VendorRepository extends BaseRepository $vendor->save(); $first = true; - $vendorcontacts = isset($data['vendor_contact']) ? [$data['vendor_contact']] : $data['vendor_contacts']; + if (isset($data['vendor_contact'])) { + $vendorcontacts = [$data['vendor_contact']]; + } elseif (isset($data['vendor_contacts'])) { + $vendorcontacts = $data['vendor_contacts']; + } else { + $vendorcontacts = [[]]; + } + $vendorcontactIds = []; foreach ($vendorcontacts as $vendorcontact) { diff --git a/app/Services/VendorService.php b/app/Services/VendorService.php index 9670fe30b198..846d4be87ff0 100644 --- a/app/Services/VendorService.php +++ b/app/Services/VendorService.php @@ -57,10 +57,6 @@ class VendorService extends BaseService */ public function save(array $data, Vendor $vendor = null) { - if (Auth::user()->account->isNinjaAccount() && isset($data['plan'])) { - $this->ninjaRepo->updatePlanDetails($data['public_id'], $data); - } - return $this->vendorRepo->save($data, $vendor); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index c0166e19cf75..b797bc571131 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2393,6 +2393,8 @@ $LANG = array( 'created_payment_and_credit' => 'Successfully created payment and credit', 'created_payment_and_credit_emailed_client' => 'Successfully created payment and credit, and emailed client', 'create_project' => 'Create project', + 'create_vendor' => 'Create vendor', + 'create_expense_category' => 'Create category', ); diff --git a/resources/views/expenses/edit.blade.php b/resources/views/expenses/edit.blade.php index c07103a3d4e4..77169bc1813d 100644 --- a/resources/views/expenses/edit.blade.php +++ b/resources/views/expenses/edit.blade.php @@ -5,7 +5,6 @@ @include('money_script') -