1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/ProductApiController.php

93 lines
2.1 KiB
PHP
Raw Normal View History

2016-01-30 10:56:27 +01:00
<?php namespace App\Http\Controllers;
2016-01-30 10:57:47 +01:00
use App\Ninja\Transformers\ProductTransformer;
2016-01-30 10:56:27 +01:00
use Auth;
use Str;
use DB;
use Datatable;
use Utils;
use URL;
use View;
use Input;
use Session;
use Redirect;
use App\Models\Product;
use App\Models\TaxRate;
use App\Services\ProductService;
class ProductApiController extends BaseAPIController
{
protected $productService;
public function __construct(ProductService $productService)
{
parent::__construct();
$this->productService = $productService;
}
public function index()
{
2016-01-30 12:16:25 +01:00
//$products = Product::scope()->withTrashed()->orderBy('created_at', 'desc')->paginate();
//$products = $products
2016-01-30 11:51:52 +01:00
2016-01-30 12:18:30 +01:00
$products = Product::scope()->withTrashed();
2016-01-30 11:51:52 +01:00
$transformer = new ProductTransformer(\Auth::user()->account, $this->serializer);
2016-01-30 12:18:30 +01:00
$data = $this->createCollection($products, $transformer, 'products', $products->paginate());
2016-01-30 11:51:52 +01:00
return $this->response($data);
2016-01-30 10:56:27 +01:00
}
public function getDatatable()
{
return $this->productService->getDatatable(Auth::user()->account_id);
}
public function edit($publicId)
{
//stub
}
public function store()
{
return $this->save();
}
public function update($publicId)
{
return $this->save($publicId);
}
public function destroy()
{
//stub
}
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->default_tax_rate_id = Input::get('default_tax_rate_id');
$product->save();
2016-01-30 10:57:47 +01:00
$transformer = new ProductTransformer(\Auth::user()->account, Input::get('serializer'));
2016-01-30 10:56:27 +01:00
$data = $this->createItem($product, $transformer, 'products');
return $this->response($data);
}
}