mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 00:14:31 -04:00
Working on the API
This commit is contained in:
parent
ddd5915ca1
commit
c493f6e49a
@ -60,7 +60,35 @@ class AccountApiController extends BaseAPIController
|
||||
public function show(Request $request)
|
||||
{
|
||||
$account = Auth::user()->account;
|
||||
$account->loadAllData();
|
||||
$updatedAt = $request->updated_at ? date('Y-m-d H:i:s', $request->updated_at) : false;
|
||||
|
||||
if ($updatedAt) {
|
||||
$account->load(['users' => function($query) use ($updatedAt) {
|
||||
$query->where('updated_at', '>=', $updatedAt);
|
||||
}])
|
||||
->load(['clients' => function($query) use ($updatedAt) {
|
||||
$query->where('updated_at', '>=', $updatedAt)->with('contacts');
|
||||
}])
|
||||
->load(['invoices' => function($query) use ($updatedAt) {
|
||||
$query->where('updated_at', '>=', $updatedAt)->with('invoice_items', 'user', 'client');
|
||||
}])
|
||||
->load(['products' => function($query) use ($updatedAt) {
|
||||
$query->where('updated_at', '>=', $updatedAt);
|
||||
}])
|
||||
->load(['tax_rates' => function($query) use ($updatedAt) {
|
||||
$query->where('updated_at', '>=', $updatedAt);
|
||||
}]);
|
||||
} else {
|
||||
$account->load(
|
||||
'users',
|
||||
'clients.contacts',
|
||||
'invoices.invoice_items',
|
||||
'invoices.user',
|
||||
'invoices.client',
|
||||
'products',
|
||||
'tax_rates'
|
||||
);
|
||||
}
|
||||
|
||||
$transformer = new AccountTransformer(null, $request->serializer);
|
||||
$account = $this->createItem($account, $transformer, 'account');
|
||||
|
@ -50,7 +50,8 @@ class InvoiceApiController extends BaseAPIController
|
||||
$paginator = Invoice::scope();
|
||||
$invoices = Invoice::scope()
|
||||
->with(array_merge(['invoice_items'], $this->getIncluded()))
|
||||
->where('invoices.is_quote', '=', false);
|
||||
->where('invoices.is_quote', '=', false)
|
||||
->where('invoices.is_recurring', '=', false);
|
||||
|
||||
if ($clientPublicId = Input::get('client_id')) {
|
||||
$filter = function($query) use ($clientPublicId) {
|
||||
|
@ -17,14 +17,8 @@ use App\Models\Invoice;
|
||||
use App\Models\Client;
|
||||
use App\Models\Account;
|
||||
use App\Models\Product;
|
||||
use App\Models\Country;
|
||||
use App\Models\TaxRate;
|
||||
use App\Models\Currency;
|
||||
use App\Models\Size;
|
||||
use App\Models\Industry;
|
||||
use App\Models\PaymentTerm;
|
||||
use App\Models\InvoiceDesign;
|
||||
use App\Models\AccountGateway;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Gateway;
|
||||
use App\Ninja\Mailers\ContactMailer as Mailer;
|
||||
|
@ -92,7 +92,7 @@ class PublicClientController extends BaseController
|
||||
public function invoiceDatatable()
|
||||
{
|
||||
if (!$invitation = $this->getInvitation()) {
|
||||
return false;
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->invoiceRepo->getClientDatatable($invitation->contact_id, ENTITY_INVOICE, Input::get('sSearch'));
|
||||
|
@ -515,11 +515,6 @@ class Account extends Eloquent
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function loadAllData()
|
||||
{
|
||||
$this->load('clients.getInvoices.invoice_items', 'clients.getQuotes.invoice_items', 'users', 'clients.contacts');
|
||||
}
|
||||
|
||||
public function loadLocalizationSettings($client = false)
|
||||
{
|
||||
$this->load('timezone', 'date_format', 'datetime_format', 'language');
|
||||
|
@ -101,27 +101,6 @@ class Client extends EntityModel
|
||||
return $this->hasMany('App\Models\Invoice');
|
||||
}
|
||||
|
||||
public function getInvoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Invoice')
|
||||
->where('is_quote', '=', false)
|
||||
->where('is_recurring', '=', false);
|
||||
}
|
||||
|
||||
public function getRecurringInvoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Invoice')
|
||||
->where('is_quote', '=', false)
|
||||
->where('is_recurring', '=', true);
|
||||
}
|
||||
|
||||
public function getQuotes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Invoice')
|
||||
->where('is_quote', '=', true)
|
||||
->where('is_recurring', '=', false);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Payment');
|
||||
|
@ -388,13 +388,8 @@ class InvoiceRepository extends BaseRepository
|
||||
}
|
||||
|
||||
if ($item['product_key']) {
|
||||
if (!\Auth::user()->account->update_products) {
|
||||
continue;
|
||||
}
|
||||
$productKey = trim($item['product_key']);
|
||||
if (strtotime($productKey)) {
|
||||
continue;
|
||||
}
|
||||
if (\Auth::user()->account->update_products && ! strtotime($productKey)) {
|
||||
$product = Product::findProductByKey($productKey);
|
||||
if (!$product) {
|
||||
$product = Product::createNew();
|
||||
@ -404,6 +399,7 @@ class InvoiceRepository extends BaseRepository
|
||||
$product->cost = $item['cost'];
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
|
||||
$invoiceItem = InvoiceItem::createNew();
|
||||
$invoiceItem->product_id = isset($product) ? $product->id : null;
|
||||
|
@ -14,7 +14,6 @@ class AccountTransformer extends EntityTransformer
|
||||
'users',
|
||||
// 'clients',
|
||||
'invoices',
|
||||
'contacts',
|
||||
'products',
|
||||
'taxRates'
|
||||
];
|
||||
@ -37,12 +36,6 @@ class AccountTransformer extends EntityTransformer
|
||||
return $this->includeCollection($account->invoices, $transformer, 'invoices');
|
||||
}
|
||||
|
||||
public function includeContacts(Account $account)
|
||||
{
|
||||
$transformer = new ContactTransformer($account, $this->serializer);
|
||||
return $this->includeCollection($account->contacts, $transformer, 'contacts');
|
||||
}
|
||||
|
||||
public function includeProducts(Account $account)
|
||||
{
|
||||
$transformer = new ProductTransformer($account, $this->serializer);
|
||||
@ -55,7 +48,6 @@ class AccountTransformer extends EntityTransformer
|
||||
return $this->includeCollection($account->tax_rates, $transformer, 'taxRates');
|
||||
}
|
||||
|
||||
|
||||
public function transform(Account $account)
|
||||
{
|
||||
return [
|
||||
@ -65,8 +57,8 @@ class AccountTransformer extends EntityTransformer
|
||||
'timezone_id' => (int) $account->timezone_id,
|
||||
'date_format_id' => (int) $account->date_format_id,
|
||||
'datetime_format_id' => (int) $account->datetime_format_id,
|
||||
'updated_at' => $account->updated_at,
|
||||
'deleted_at' => $account->deleted_at,
|
||||
'updated_at' => $this->getTimestamp($account->updated_at),
|
||||
'archived_at' => $this->getTimestamp($account->deleted_at),
|
||||
'address1' => $account->address1,
|
||||
'address2' => $account->address2,
|
||||
'city' => $account->city,
|
||||
|
@ -17,8 +17,8 @@ class ClientTransformer extends EntityTransformer
|
||||
* @SWG\Property(property="paid_to_date", type="float", example=10, readOnly=true)
|
||||
* @SWG\Property(property="user_id", type="integer", example=1)
|
||||
* @SWG\Property(property="account_key", type="string", example="123456")
|
||||
* @SWG\Property(property="updated_at", type="date-time", example="2016-01-01 12:10:00")
|
||||
* @SWG\Property(property="deleted_at", type="date-time", example="2016-01-01 12:10:00")
|
||||
* @SWG\Property(property="updated_at", type="timestamp", example="")
|
||||
* @SWG\Property(property="archived_at", type="timestamp", example="1451160233")
|
||||
* @SWG\Property(property="address1", type="string", example="10 Main St.")
|
||||
* @SWG\Property(property="address2", type="string", example="1st Floor")
|
||||
* @SWG\Property(property="city", type="string", example="New York")
|
||||
@ -43,7 +43,6 @@ class ClientTransformer extends EntityTransformer
|
||||
protected $availableIncludes = [
|
||||
'contacts',
|
||||
'invoices',
|
||||
'quotes',
|
||||
];
|
||||
|
||||
public function includeContacts(Client $client)
|
||||
@ -55,13 +54,7 @@ class ClientTransformer extends EntityTransformer
|
||||
public function includeInvoices(Client $client)
|
||||
{
|
||||
$transformer = new InvoiceTransformer($this->account, $this->serializer);
|
||||
return $this->includeCollection($client->getInvoices, $transformer, ENTITY_INVOICE);
|
||||
}
|
||||
|
||||
public function includeQuotes(Client $client)
|
||||
{
|
||||
$transformer = new QuoteTransformer($this->account, $this->serializer);
|
||||
return $this->includeCollection($client->getQuotes, $transformer, ENTITY_QUOTE);
|
||||
return $this->includeCollection($client->invoices, $transformer, ENTITY_INVOICE);
|
||||
}
|
||||
|
||||
public function transform(Client $client)
|
||||
@ -73,8 +66,8 @@ class ClientTransformer extends EntityTransformer
|
||||
'paid_to_date' => (float) $client->paid_to_date,
|
||||
'user_id' => (int) $client->user->public_id + 1,
|
||||
'account_key' => $this->account->account_key,
|
||||
'updated_at' => $client->updated_at,
|
||||
'deleted_at' => $client->deleted_at,
|
||||
'updated_at' => $this->getTimestamp($client->updated_at),
|
||||
'archived_at' => $this->getTimestamp($client->deleted_at),
|
||||
'address1' => $client->address1,
|
||||
'address2' => $client->address2,
|
||||
'city' => $client->city,
|
||||
|
@ -13,8 +13,8 @@ class ContactTransformer extends EntityTransformer
|
||||
'first_name' => $contact->first_name,
|
||||
'last_name' => $contact->last_name,
|
||||
'email' => $contact->email,
|
||||
'updated_at' => $contact->updated_at,
|
||||
'deleted_at' => $contact->deleted_at,
|
||||
'updated_at' => $this->getTimestamp($contact->updated_at),
|
||||
'archived_at' => $this->getTimestamp($contact->deleted_at),
|
||||
'is_primary' => (bool) $contact->is_primary,
|
||||
'phone' => $contact->phone,
|
||||
'last_login' => $contact->last_login,
|
||||
|
@ -32,4 +32,9 @@ class EntityTransformer extends TransformerAbstract
|
||||
|
||||
return $this->item($data, $transformer, $entityType);
|
||||
}
|
||||
|
||||
protected function getTimestamp($date)
|
||||
{
|
||||
return $date ? $date->getTimestamp() : null;
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ class InvoiceItemTransformer extends EntityTransformer
|
||||
'product_key' => $item->product_key,
|
||||
'account_key' => $this->account->account_key,
|
||||
'user_id' => (int) $item->user_id,
|
||||
'updated_at' => $item->updated_at,
|
||||
'deleted_at' => $item->deleted_at,
|
||||
'updated_at' => $this->getTimestamp($item->updated_at),
|
||||
'archived_at' => $this->getTimestamp($item->deleted_at),
|
||||
'product_key' => $item->product_key,
|
||||
'notes' => $item->notes,
|
||||
'cost' => (float) $item->cost,
|
||||
|
@ -38,8 +38,8 @@ class InvoiceTransformer extends EntityTransformer
|
||||
'balance' => (float) $invoice->balance,
|
||||
'client_id' => (int) $invoice->client->public_id,
|
||||
'invoice_status_id' => (int) $invoice->invoice_status_id,
|
||||
'updated_at' => $invoice->updated_at,
|
||||
'deleted_at' => $invoice->deleted_at,
|
||||
'updated_at' => $this->getTimestamp($invoice->updated_at),
|
||||
'archived_at' => $this->getTimestamp($invoice->deleted_at),
|
||||
'invoice_number' => $invoice->invoice_number,
|
||||
'discount' => (double) $invoice->discount,
|
||||
'po_number' => $invoice->po_number,
|
||||
@ -48,6 +48,7 @@ class InvoiceTransformer extends EntityTransformer
|
||||
'terms' => $invoice->terms,
|
||||
'public_notes' => $invoice->public_notes,
|
||||
'is_deleted' => (bool) $invoice->is_deleted,
|
||||
'is_quote' => (bool) $invoice->is_quote,
|
||||
'is_recurring' => (bool) $invoice->is_recurring,
|
||||
'frequency_id' => (int) $invoice->frequency_id,
|
||||
'start_date' => $invoice->start_date,
|
||||
|
@ -25,8 +25,8 @@ class TaxRateTransformer extends EntityTransformer
|
||||
'id' => (int) $taxRate->public_id,
|
||||
'name' => $taxRate->name,
|
||||
'rate' => (float) $taxRate->rate,
|
||||
'updated_at' => $taxRate->updated_at,
|
||||
'archived_at' => $taxRate->deleted_at,
|
||||
'updated_at' => $this->getTimestamp($taxRate->updated_at),
|
||||
'archived_at' => $this->getTimestamp($taxRate->deleted_at),
|
||||
'account_key' => $this->account->account_key,
|
||||
];
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ class UserTransformer extends EntityTransformer
|
||||
'last_name' => $user->last_name,
|
||||
'email' => $user->email,
|
||||
'account_key' => $user->account->account_key,
|
||||
'updated_at' => $user->updated_at,
|
||||
'deleted_at' => $user->deleted_at,
|
||||
'updated_at' => $this->getTimestamp($user->updated_at),
|
||||
'deleted_at' => $this->getTimestamp($user->deleted_at),
|
||||
'phone' => $user->phone,
|
||||
'username' => $user->username,
|
||||
'registered' => (bool) $user->registered,
|
||||
|
Loading…
x
Reference in New Issue
Block a user