mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #673 from turbo124/testing_email
Send invoice via API. Product API Class implementation
This commit is contained in:
commit
4a9a9dc823
@ -249,6 +249,26 @@ class InvoiceApiController extends BaseAPIController
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function emailInvoicev2()
|
||||
{
|
||||
$data = Input::all();
|
||||
$error = null;
|
||||
|
||||
$invoice = Invoice::scope($data['id'])->firstOrFail();
|
||||
|
||||
$this->mailer->sendInvoice($invoice);
|
||||
|
||||
if($error) {
|
||||
$response['error'] = "There was an error sending the invoice";
|
||||
}
|
||||
else {
|
||||
$response = json_encode(RESULT_SUCCESS, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
$headers = Utils::getApiHeaders();
|
||||
return Response::make($response, $error ? 400 : 200, $headers);
|
||||
}
|
||||
|
||||
public function emailInvoice()
|
||||
{
|
||||
$data = Input::all();
|
||||
|
88
app/Http/Controllers/ProductApiController.php
Normal file
88
app/Http/Controllers/ProductApiController.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
use App\Ninja\Transformers\ProductTransformer;
|
||||
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()
|
||||
{
|
||||
|
||||
$products = Product::scope()->withTrashed();
|
||||
$products = $products->paginate();
|
||||
|
||||
$paginator = Product::scope()->withTrashed()->paginate();
|
||||
|
||||
$transformer = new ProductTransformer(\Auth::user()->account, $this->serializer);
|
||||
$data = $this->createCollection($products, $transformer, 'products', $paginator);
|
||||
|
||||
return $this->response($data);
|
||||
|
||||
}
|
||||
|
||||
public function getDatatable()
|
||||
{
|
||||
return $this->productService->getDatatable(Auth::user()->account_id);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
public function update($publicId)
|
||||
{
|
||||
return $this->save($publicId);
|
||||
}
|
||||
|
||||
public function destroy($publicId)
|
||||
{
|
||||
//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();
|
||||
|
||||
$transformer = new ProductTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($product, $transformer, 'products');
|
||||
|
||||
return $this->response($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ class VerifyCsrfToken extends BaseVerifier {
|
||||
|
||||
private $openRoutes = [
|
||||
'signup/register',
|
||||
'api/v1/*',
|
||||
'api/v1/login',
|
||||
'api/v1/clients/*',
|
||||
'api/v1/clients',
|
||||
|
@ -230,7 +230,9 @@ Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
|
||||
Route::resource('tasks', 'TaskApiController');
|
||||
Route::post('hooks', 'IntegrationController@subscribe');
|
||||
Route::post('email_invoice', 'InvoiceApiController@emailInvoice');
|
||||
Route::post('email_invoicev2', 'InvoiceApiController@emailInvoicev2');
|
||||
Route::get('user_accounts','AccountApiController@getUserAccounts');
|
||||
Route::resource('products', 'ProductApiController');
|
||||
|
||||
// Vendor
|
||||
Route::resource('vendors', 'VendorApiController');
|
||||
|
Loading…
x
Reference in New Issue
Block a user