1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Merge branch 'master' of github.com:hillelcoren/invoice-ninja

This commit is contained in:
Hillel Coren 2016-02-01 15:58:59 +02:00
commit 1a2c2712d0
6 changed files with 72 additions and 30 deletions

View File

@ -4,6 +4,7 @@ use Auth;
use Utils;
use Response;
use Input;
use Validator;
use Cache;
use App\Models\Client;
use App\Models\Account;
@ -101,4 +102,42 @@ class AccountApiController extends BaseAPIController
{
return $this->processLogin($request);
}
public function update(Request $request)
{
$rules = array(
'name' => 'required',
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
$data = $validator->messages();
return $this->errorResponse($data);
} else {
$account = Auth::user()->account;
$account->name = trim(Input::get('name'));
$account->id_number = trim(Input::get('id_number'));
$account->vat_number = trim(Input::get('vat_number'));
$account->work_email = trim(Input::get('work_email'));
$account->website = trim(Input::get('website'));
$account->work_phone = trim(Input::get('work_phone'));
$account->address1 = trim(Input::get('address1'));
$account->address2 = trim(Input::get('address2'));
$account->city = trim(Input::get('city'));
$account->state = trim(Input::get('state'));
$account->postal_code = trim(Input::get('postal_code'));
$account->country_id = Input::get('country_id') ? Input::get('country_id') : null;
$account->size_id = Input::get('size_id') ? Input::get('size_id') : null;
$account->industry_id = Input::get('industry_id') ? Input::get('industry_id') : null;
$account->email_footer = Input::get('email_footer');
$account->save();
$transformer = new AccountTransformer(null, $request->serializer);
$account = $this->createItem($account, $transformer, 'account');
return $this->response($account);
}
}
}

View File

@ -107,6 +107,17 @@ class BaseAPIController extends Controller
return Response::make($response, 200, $headers);
}
protected function errorResponse($response)
{
$error['error'] = $response;
$error = json_encode($error, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders();
return Response::make($error, 400, $headers);
}
protected function getIncluded()
{
$data = ['user'];

View File

@ -249,7 +249,7 @@ class InvoiceApiController extends BaseAPIController
return $item;
}
public function emailInvoicev2()
public function emailInvoice()
{
$data = Input::all();
$error = null;
@ -269,31 +269,6 @@ class InvoiceApiController extends BaseAPIController
return Response::make($response, $error ? 400 : 200, $headers);
}
public function emailInvoice()
{
$data = Input::all();
$error = null;
if (!isset($data['id'])) {
$error = trans('validation.required', ['attribute' => 'id']);
} else {
$invoice = Invoice::scope($data['id'])->first();
if (!$invoice) {
$error = trans('validation.not_in', ['attribute' => 'id']);
} else {
$this->mailer->sendInvoice($invoice);
}
}
if ($error) {
$response = json_encode($error, JSON_PRETTY_PRINT);
} else {
$response = json_encode(RESULT_SUCCESS, JSON_PRETTY_PRINT);
}
$headers = Utils::getApiHeaders();
return Response::make($response, $error ? 400 : 200, $headers);
}
/**
* @SWG\Put(

View File

@ -1,5 +1,6 @@
<?php namespace App\Http\Controllers;
use App\Ninja\Repositories\ProductRepository;
use App\Ninja\Transformers\ProductTransformer;
use Auth;
use Str;
@ -20,11 +21,14 @@ class ProductApiController extends BaseAPIController
{
protected $productService;
public function __construct(ProductService $productService)
protected $productRepo;
public function __construct(ProductService $productService, ProductRepository $productRepo)
{
parent::__construct();
$this->productService = $productService;
$this->productRepo = $productRepo;
}
public function index()
@ -52,14 +56,25 @@ class ProductApiController extends BaseAPIController
return $this->save();
}
public function update($publicId)
public function update(\Illuminate\Http\Request $request, $publicId)
{
return $this->save($publicId);
if ($request->action == ACTION_ARCHIVE) {
$product = Product::scope($publicId)->withTrashed()->firstOrFail();
$this->productRepo->archive($product);
$transformer = new ProductTransformer(\Auth::user()->account, Input::get('serializer'));
$data = $this->createItem($product, $transformer, 'products');
return $this->response($data);
}
else
return $this->save($publicId);
}
public function destroy($publicId)
{
//stub
//stub
}
private function save($productPublicId = false)

View File

@ -219,6 +219,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
Route::post('login', 'AccountApiController@login');
Route::get('static', 'AccountApiController@getStaticData');
Route::get('accounts', 'AccountApiController@show');
Route::put('accounts', 'AccountApiController@update');
Route::resource('clients', 'ClientApiController');
Route::get('quotes', 'QuoteApiController@index');
Route::resource('quotes', 'QuoteApiController');

View File

@ -16,6 +16,7 @@ class ProductTransformer extends EntityTransformer
'account_key' =>$this->account->account_key,
'default_tax_rate_id' =>$product->default_tax_rate_id,
'updated_at' =>$this->getTimestamp($product->updated_at),
'archived_at' => $this->getTimestamp($product->deleted_at),
];
}
}