1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Support creating inline vendors and categories

This commit is contained in:
Hillel Coren 2017-03-02 18:02:48 +02:00
parent 5939987068
commit 5f478af9a4
7 changed files with 80 additions and 60 deletions

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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);
}

View File

@ -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',
);

View File

@ -5,7 +5,6 @@
@include('money_script')
<style type="text/css">
.input-group-addon {
min-width: 40px;
@ -40,14 +39,12 @@
<div class="col-md-6">
{!! Former::select('vendor_id')->addOption('', '')
->data_bind('combobox: vendor_id')
->label(trans('texts.vendor'))
->addGroupClass('vendor-select') !!}
{!! Former::select('expense_category_id')->addOption('', '')
->data_bind('combobox: expense_category_id')
->label(trans('texts.category'))
->addGroupClass('category-select') !!}
->addGroupClass('expense-category-select') !!}
{!! Former::text('expense_date')
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))
@ -159,25 +156,28 @@
</div>
<div class="col-md-6">
{!! Former::textarea('public_notes')->rows(8) !!}
{!! Former::textarea('private_notes')->rows(8) !!}
{!! Former::textarea('public_notes')->rows(6) !!}
{!! Former::textarea('private_notes')->rows(6) !!}
@if ($account->hasFeature(FEATURE_DOCUMENTS))
<div class="form-group">
<label for="public_notes" class="control-label col-lg-4 col-sm-4">
{{trans('texts.documents')}}
</label>
<div class="col-lg-8 col-sm-8">
<div role="tabpanel" class="tab-pane" id="attached-documents" style="position:relative;z-index:9">
<div id="document-upload" class="dropzone">
<div data-bind="foreach: documents">
<input type="hidden" name="document_ids[]" data-bind="value: public_id"/>
</div>
</div>
</div>
</div>
</div>
@endif
</div>
</div>
@if ($account->hasFeature(FEATURE_DOCUMENTS))
<div clas="row">
<div class="col-md-2 col-sm-4"><div class="control-label" style="margin-bottom:10px;">{{trans('texts.expense_documents')}}</div></div>
<div class="col-md-12 col-sm-8">
<div role="tabpanel" class="tab-pane" id="attached-documents" style="position:relative;z-index:9">
<div id="document-upload" class="dropzone">
<div data-bind="foreach: documents">
<input type="hidden" name="document_ids[]" data-bind="value: public_id"/>
</div>
</div>
</div>
</div>
</div>
@endif
</div>
</div>
@ -225,6 +225,9 @@
var taxRates = {!! $taxRates !!};
var clientMap = {};
var vendorMap = {};
var categoryMap = {};
for (var i=0; i<clients.length; i++) {
var client = clients[i];
clientMap[client.public_id] = client;
@ -264,20 +267,37 @@
}
$(function() {
var vendorId = {{ $vendorPublicId ?: 0 }};
var $vendorSelect = $('select#vendor_id');
@if (Auth::user()->can('create', ENTITY_VENDOR))
$vendorSelect.append(new Option("{{ trans('texts.create_vendor')}}: $name", '-1'));
@endif
for (var i = 0; i < vendors.length; i++) {
var vendor = vendors[i];
vendorMap[vendor.public_id] = vendor;
$vendorSelect.append(new Option(getClientDisplayName(vendor), vendor.public_id));
}
$vendorSelect.combobox();
@include('partials/entity_combobox', ['entityType' => ENTITY_VENDOR])
if (vendorId) {
var vendor = vendorMap[vendorId];
setComboboxValue($('.vendor-select'), vendor.public_id, vendor.name);
}
var $categorySelect = $('select#expense_category_id');
var categoryId = {{ $categoryPublicId ?: 0 }};
var $expense_categorySelect = $('select#expense_category_id');
@if (Auth::user()->can('create', ENTITY_EXPENSE_CATEGORY))
$expense_categorySelect.append(new Option("{{ trans('texts.create_expense_category')}}: $name", '-1'));
@endif
for (var i = 0; i < categories.length; i++) {
var category = categories[i];
$categorySelect.append(new Option(category.name, category.public_id));
categoryMap[category.public_id] = category;
$expense_categorySelect.append(new Option(category.name, category.public_id));
}
@include('partials/entity_combobox', ['entityType' => ENTITY_EXPENSE_CATEGORY])
if (categoryId) {
var category = categoryMap[categoryId];
setComboboxValue($('.expense-category-select'), category.public_id, category.name);
}
$categorySelect.combobox();
$('#expense_date').datepicker('update', '{{ $expense ? $expense->expense_date : 'new Date()' }}');
@ -388,8 +408,8 @@
self.account_currency_id = ko.observable({{ $account->getCurrencyId() }});
self.client_id = ko.observable({{ $clientPublicId }});
self.vendor_id = ko.observable({{ $vendorPublicId }});
self.expense_category_id = ko.observable({{ $categoryPublicId }});
//self.vendor_id = ko.observable({{ $vendorPublicId }});
//self.expense_category_id = ko.observable({{ $categoryPublicId }});
self.mapping = {
'documents': {
@ -545,7 +565,6 @@
}
}
</script>
@stop

View File

@ -586,27 +586,7 @@
}
});
var projectName = '';
$projectSelect.combobox({
highlighter: function (item) {
if (item.indexOf("{{ trans('texts.create_project') }}") == 0) {
projectName = this.query;
return "{{ trans('texts.create_project') }}: " + this.query;
} else {
var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
return '<strong>' + match + '</strong>';
})
}
},
template: '<div class="combobox-container"> <input type="hidden" /> <div class="input-group"> <input type="text" name="project_name" autocomplete="off" /> <span class="input-group-addon dropdown-toggle" data-dropdown="dropdown"> <span class="caret" /> <i class="fa fa-times"></i> </span> </div> </div> ',
matcher: function (item) {
if (item.indexOf("{{ trans('texts.create_project') }}") == 0) {
return this.query.length;
}
return ~item.toLowerCase().indexOf(this.query.toLowerCase());
}
});
@include('partials/entity_combobox', ['entityType' => ENTITY_PROJECT])
if (projectId) {
var project = projectMap[projectId];
@ -619,4 +599,5 @@
</script>
@stop