mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Working on products
This commit is contained in:
parent
6e86f1904a
commit
2c4d635432
@ -199,34 +199,6 @@ class AccountController extends \BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
public function getProducts()
|
||||
{
|
||||
$query = DB::table('products')
|
||||
->where('products.account_id', '=', Auth::user()->account_id)
|
||||
->where('products.deleted_at', '=', null)
|
||||
->select('products.public_id', 'products.product_key', 'products.notes', 'products.cost');
|
||||
|
||||
|
||||
return Datatable::query($query)
|
||||
->addColumn('product_key', function($model) { return link_to('company/products/' . $model->public_id . '/edit', $model->product_key); })
|
||||
->addColumn('notes', function($model) { return $model->notes; })
|
||||
->addColumn('cost', function($model) { return Utils::formatMoney($model->cost); })
|
||||
->addColumn('dropdown', function($model)
|
||||
{
|
||||
return '<div class="btn-group tr-action" style="visibility:hidden;">
|
||||
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
|
||||
'.trans('texts.select').' <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="' . URL::to('company/products/'.$model->public_id) . '/edit">'.uctrans('texts.edit_product').'</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="' . URL::to('company/products/'.$model->public_id) . '/archive">'.uctrans('texts.archive_product').'</a></li>
|
||||
</ul>
|
||||
</div>';
|
||||
})
|
||||
->make();
|
||||
}
|
||||
|
||||
public function doSection($section = ACCOUNT_DETAILS)
|
||||
{
|
||||
if ($section == ACCOUNT_DETAILS)
|
||||
@ -263,59 +235,6 @@ class AccountController extends \BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
public function showProduct($productPublicId)
|
||||
{
|
||||
$data = [
|
||||
'product' => Product::scope($productPublicId)->firstOrFail(),
|
||||
'url' => 'company/products/' . $productPublicId,
|
||||
'title' => trans('texts.edit_product')
|
||||
];
|
||||
|
||||
return View::make('accounts.product', $data);
|
||||
}
|
||||
|
||||
public function createProduct()
|
||||
{
|
||||
$data = [
|
||||
'product' => null,
|
||||
'url' => 'company/products/',
|
||||
'title' => trans('texts.create_product')
|
||||
];
|
||||
|
||||
return View::make('accounts.product', $data);
|
||||
}
|
||||
|
||||
public function saveProduct($productPublicId = false)
|
||||
{
|
||||
if ($productPublicId)
|
||||
{
|
||||
$product = Product::scope($productPublicId)->firstOrFail();
|
||||
}
|
||||
else
|
||||
{
|
||||
$product = Product::createNew();
|
||||
}
|
||||
|
||||
$product->product_key = trim(Input::get('product_key'));
|
||||
$product->notes = trim(Input::get('notes'));
|
||||
$product->cost = trim(Input::get('cost'));
|
||||
$product->save();
|
||||
|
||||
$message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product');
|
||||
Session::flash('message', $message);
|
||||
|
||||
return Redirect::to('company/products');
|
||||
}
|
||||
|
||||
public function archiveProduct($productPublicId)
|
||||
{
|
||||
$product = Product::scope($productPublicId)->firstOrFail();
|
||||
$product->delete();
|
||||
|
||||
Session::flash('message', trans('texts.archived_product'));
|
||||
return Redirect::to('company/products');
|
||||
}
|
||||
|
||||
private function saveProducts()
|
||||
{
|
||||
$account = Auth::user()->account;
|
||||
|
100
app/controllers/ProductController.php
Normal file
100
app/controllers/ProductController.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
class ProductController extends \BaseController {
|
||||
|
||||
public function getDatatable()
|
||||
{
|
||||
$query = DB::table('products')
|
||||
->where('products.account_id', '=', Auth::user()->account_id)
|
||||
->where('products.deleted_at', '=', null)
|
||||
->select('products.public_id', 'products.product_key', 'products.notes', 'products.cost');
|
||||
|
||||
|
||||
return Datatable::query($query)
|
||||
->addColumn('product_key', function($model) { return link_to('products/' . $model->public_id . '/edit', $model->product_key); })
|
||||
->addColumn('notes', function($model) { return $model->notes; })
|
||||
->addColumn('cost', function($model) { return Utils::formatMoney($model->cost); })
|
||||
->addColumn('dropdown', function($model)
|
||||
{
|
||||
return '<div class="btn-group tr-action" style="visibility:hidden;">
|
||||
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
|
||||
'.trans('texts.select').' <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="' . URL::to('products/'.$model->public_id) . '/edit">'.uctrans('texts.edit_product').'</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="' . URL::to('products/'.$model->public_id) . '/archive">'.uctrans('texts.archive_product').'</a></li>
|
||||
</ul>
|
||||
</div>';
|
||||
})
|
||||
->make();
|
||||
}
|
||||
|
||||
public function edit($publicId)
|
||||
{
|
||||
$data = [
|
||||
'showBreadcrumbs' => false,
|
||||
'product' => Product::scope($publicId)->firstOrFail(),
|
||||
'method' => 'PUT',
|
||||
'url' => 'products/' . $publicId,
|
||||
'title' => trans('texts.edit_product')
|
||||
];
|
||||
|
||||
return View::make('accounts.product', $data);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data = [
|
||||
'showBreadcrumbs' => false,
|
||||
'product' => null,
|
||||
'method' => 'POST',
|
||||
'url' => 'products',
|
||||
'title' => trans('texts.create_product')
|
||||
];
|
||||
|
||||
return View::make('accounts.product', $data);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
public function update($publicId)
|
||||
{
|
||||
return $this->save($publicId);
|
||||
}
|
||||
|
||||
private function save($productPublicId = false)
|
||||
{
|
||||
if ($productPublicId)
|
||||
{
|
||||
$product = Product::scope($productPublicId)->firstOrFail();
|
||||
}
|
||||
else
|
||||
{
|
||||
$product = Product::createNew();
|
||||
}
|
||||
|
||||
$product->product_key = trim(Input::get('product_key'));
|
||||
$product->notes = trim(Input::get('notes'));
|
||||
$product->cost = trim(Input::get('cost'));
|
||||
$product->save();
|
||||
|
||||
$message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product');
|
||||
Session::flash('message', $message);
|
||||
|
||||
return Redirect::to('company/products');
|
||||
}
|
||||
|
||||
public function archive($publicId)
|
||||
{
|
||||
$product = Product::scope($publicId)->firstOrFail();
|
||||
$product->delete();
|
||||
|
||||
Session::flash('message', trans('texts.archived_product'));
|
||||
return Redirect::to('company/products');
|
||||
}
|
||||
|
||||
}
|
@ -207,9 +207,13 @@ class InvoiceRepository
|
||||
$product->product_key = trim($item->product_key);
|
||||
}
|
||||
|
||||
$product->notes = $item->notes;
|
||||
$product->cost = $item->cost;
|
||||
//$product->qty = $item->qty;
|
||||
if (\Auth::user()->account->update_products)
|
||||
{
|
||||
$product->notes = $item->notes;
|
||||
$product->cost = $item->cost;
|
||||
//$product->qty = $item->qty;
|
||||
}
|
||||
|
||||
$product->save();
|
||||
}
|
||||
|
||||
|
@ -61,11 +61,16 @@ Route::group(array('before' => 'auth'), function()
|
||||
Route::get('view_archive/{entity_type}/{visible}', 'AccountController@setTrashVisible');
|
||||
Route::get('force_inline_pdf', 'UserController@forcePDFJS');
|
||||
|
||||
Route::get('api/products', array('as'=>'api.products', 'uses'=>'AccountController@getProducts'));
|
||||
Route::get('company/products/{product_id}/edit', 'AccountController@showProduct');
|
||||
Route::get('company/products/{product_id}/archive', 'AccountController@archiveProduct');
|
||||
Route::get('company/products/create', 'AccountController@createProduct');
|
||||
Route::get('api/products', array('as'=>'api.products', 'uses'=>'ProductController@getDatatable'));
|
||||
Route::resource('products', 'ProductController');
|
||||
Route::get('products/{product_id}/archive', 'ProductController@archive');
|
||||
|
||||
/*
|
||||
Route::get('company/products/{product_id}/edit', 'ProductController@showProduct');
|
||||
Route::get('company/products/{product_id}/archive', 'ProductController@archiveProduct');
|
||||
Route::get('company/products/create', 'ProductController@createProduct');
|
||||
Route::post('company/products/{product_id?}', 'AccountController@saveProduct');
|
||||
*/
|
||||
|
||||
Route::get('account/getSearchData', array('as' => 'getSearchData', 'uses' => 'AccountController@getSearchData'));
|
||||
Route::get('company/{section?}', 'AccountController@showSection');
|
||||
|
@ -3,7 +3,7 @@
|
||||
@section('content')
|
||||
@parent
|
||||
|
||||
{{ Former::open($url)->addClass('col-md-8 col-md-offset-2 warn-on-exit') }}
|
||||
{{ Former::open($url)->method($method)->addClass('col-md-8 col-md-offset-2 warn-on-exit') }}
|
||||
|
||||
|
||||
{{ Former::legend($title) }}
|
||||
@ -14,7 +14,7 @@
|
||||
@endif
|
||||
|
||||
{{ Former::text('product_key') }}
|
||||
{{ Former::textarea('notes') }}
|
||||
{{ Former::textarea('notes')->data_bind("value: wrapped_notes, valueUpdate: 'afterkeydown'") }}
|
||||
{{ Former::text('cost') }}
|
||||
|
||||
{{ Former::actions(
|
||||
@ -24,4 +24,31 @@
|
||||
|
||||
{{ Former::close() }}
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function ViewModel(data) {
|
||||
var self = this;
|
||||
@if ($product)
|
||||
self.notes = ko.observable(wordWrapText('{{ str_replace(["\r\n","\r","\n"], '\n', addslashes($product->notes)) }}', 300));
|
||||
@else
|
||||
self.notes = ko.observable('');
|
||||
@endif
|
||||
|
||||
self.wrapped_notes = ko.computed({
|
||||
read: function() {
|
||||
return self.notes();
|
||||
},
|
||||
write: function(value) {
|
||||
value = wordWrapText(value, 235);
|
||||
self.notes(value);
|
||||
},
|
||||
owner: this
|
||||
});
|
||||
}
|
||||
|
||||
window.model = new ViewModel();
|
||||
ko.applyBindings(model);
|
||||
|
||||
</script>
|
||||
|
||||
@stop
|
@ -15,7 +15,7 @@
|
||||
{{ Former::actions( Button::lg_success_submit(trans('texts.save'))->append_with_icon('floppy-disk') ) }}
|
||||
{{ Former::close() }}
|
||||
|
||||
{{ Button::success_link(URL::to('company/products/create'), trans("texts.create_product"), array('class' => 'pull-right'))->append_with_icon('plus-sign') }}
|
||||
{{ Button::success_link(URL::to('products/create'), trans("texts.create_product"), array('class' => 'pull-right'))->append_with_icon('plus-sign') }}
|
||||
|
||||
{{ Datatable::table()
|
||||
->addColumn(
|
||||
|
@ -562,19 +562,21 @@
|
||||
refreshPDF();
|
||||
});
|
||||
|
||||
$('.datalist').on('input', function() {
|
||||
var key = $(this).val();
|
||||
for (var i=0; i<products.length; i++) {
|
||||
var product = products[i];
|
||||
if (product.product_key == key) {
|
||||
var model = ko.dataFor(this);
|
||||
//model.notes(product.notes);
|
||||
//model.cost(product.cost);
|
||||
//model.qty(product.qty);
|
||||
break;
|
||||
@if (Auth::user()->account->fill_products)
|
||||
$('.datalist').on('input', function() {
|
||||
var key = $(this).val();
|
||||
for (var i=0; i<products.length; i++) {
|
||||
var product = products[i];
|
||||
if (product.product_key == key) {
|
||||
var model = ko.dataFor(this);
|
||||
model.notes(product.notes);
|
||||
model.cost(accounting.toFixed(product.cost,2));
|
||||
//model.qty(product.qty);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@endif
|
||||
}
|
||||
|
||||
function createInvoiceModel() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user