mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 17:27:33 -04:00 
			
		
		
		
	Merge branch 'develop' of https://github.com/turbo124/invoiceninja into develop
This commit is contained in:
		
						commit
						aafe14eced
					
				| @ -3,6 +3,7 @@ | ||||
| use Session; | ||||
| use Utils; | ||||
| use Auth; | ||||
| use Log; | ||||
| use Input; | ||||
| use Response; | ||||
| use Request; | ||||
| @ -66,6 +67,10 @@ class BaseAPIController extends Controller | ||||
|         } else { | ||||
|             $this->manager->setSerializer(new ArraySerializer()); | ||||
|         } | ||||
|          | ||||
|         if (Utils::isNinjaDev()) { | ||||
|             \DB::enableQueryLog(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     protected function handleAction($request) | ||||
| @ -82,7 +87,13 @@ class BaseAPIController extends Controller | ||||
| 
 | ||||
|     protected function listResponse($query) | ||||
|     { | ||||
|         //\DB::enableQueryLog();
 | ||||
|         $transformerClass = EntityModel::getTransformerName($this->entityType); | ||||
|         $transformer = new $transformerClass(Auth::user()->account, Input::get('serializer'));         | ||||
| 
 | ||||
|         $include = $transformer->getDefaultIncludes(); | ||||
|         $include = $this->getRequestIncludes($include); | ||||
|         $query->with($include); | ||||
|              | ||||
|         if ($clientPublicId = Input::get('client_id')) { | ||||
|             $filter = function($query) use ($clientPublicId) { | ||||
|                 $query->where('public_id', '=', $clientPublicId); | ||||
| @ -98,12 +109,8 @@ class BaseAPIController extends Controller | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         $transformerClass = EntityModel::getTransformerName($this->entityType); | ||||
|         $transformer = new $transformerClass(Auth::user()->account, Input::get('serializer'));         | ||||
|          | ||||
|         $data = $this->createCollection($query, $transformer, $this->entityType); | ||||
| 
 | ||||
|         //return \DB::getQueryLog();
 | ||||
|         return $this->response($data); | ||||
|     } | ||||
| 
 | ||||
| @ -113,7 +120,7 @@ class BaseAPIController extends Controller | ||||
|         $transformer = new $transformerClass(Auth::user()->account, Input::get('serializer'));         | ||||
| 
 | ||||
|         $data = $this->createItem($item, $transformer, $this->entityType); | ||||
| 
 | ||||
|          | ||||
|         return $this->response($data); | ||||
|     } | ||||
| 
 | ||||
| @ -146,6 +153,12 @@ class BaseAPIController extends Controller | ||||
| 
 | ||||
|     protected function response($response) | ||||
|     { | ||||
|         if (Utils::isNinjaDev()) { | ||||
|             $count = count(\DB::getQueryLog()); | ||||
|             Log::info(Request::method() . ' - ' . Request::url() . ": $count queries"); | ||||
|             //Log::info(print_r(\DB::getQueryLog(), true));
 | ||||
|         } | ||||
|          | ||||
|         $index = Request::get('index') ?: 'data'; | ||||
| 
 | ||||
|         if ($index == 'none') { | ||||
| @ -178,9 +191,9 @@ class BaseAPIController extends Controller | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     protected function getIncluded() | ||||
|     protected function getRequestIncludes($data) | ||||
|     { | ||||
|         $data = ['user']; | ||||
|         $data[] = 'user'; | ||||
| 
 | ||||
|         $included = Request::get('include'); | ||||
|         $included = explode(',', $included); | ||||
|  | ||||
| @ -44,7 +44,6 @@ class ClientApiController extends BaseAPIController | ||||
|     public function index() | ||||
|     { | ||||
|         $clients = Client::scope() | ||||
|             ->with($this->getIncluded()) | ||||
|             ->orderBy('created_at', 'desc') | ||||
|             ->withTrashed(); | ||||
| 
 | ||||
|  | ||||
| @ -61,7 +61,7 @@ class InvoiceApiController extends BaseAPIController | ||||
|     { | ||||
|         $invoices = Invoice::scope() | ||||
|                         ->withTrashed() | ||||
|                         ->with(array_merge(['invoice_items'], $this->getIncluded())) | ||||
|                         ->with('invoice_items') | ||||
|                         ->orderBy('created_at', 'desc'); | ||||
| 
 | ||||
|         return $this->listResponse($invoices); | ||||
|  | ||||
| @ -49,7 +49,7 @@ class PaymentApiController extends BaseAPIController | ||||
|     { | ||||
|         $payments = Payment::scope() | ||||
|                         ->withTrashed() | ||||
|                         ->with(array_merge(['client.contacts', 'invitation', 'user', 'invoice'], $this->getIncluded()))                         | ||||
|                         ->with(['client.contacts', 'invitation', 'user', 'invoice'])                         | ||||
|                         ->orderBy('created_at', 'desc'); | ||||
| 
 | ||||
|         return $this->listResponse($payments); | ||||
|  | ||||
| @ -42,7 +42,6 @@ class TaskApiController extends BaseAPIController | ||||
|     { | ||||
|         $payments = Task::scope() | ||||
|                         ->withTrashed() | ||||
|                         ->with($this->getIncluded())                         | ||||
|                         ->orderBy('created_at', 'desc'); | ||||
| 
 | ||||
|         return $this->listResponse($payments); | ||||
|  | ||||
| @ -49,7 +49,6 @@ class VendorApiController extends BaseAPIController | ||||
|     public function index() | ||||
|     { | ||||
|         $vendors = Vendor::scope() | ||||
|                     ->with($this->getIncluded()) | ||||
|                     ->withTrashed() | ||||
|                     ->orderBy('created_at', 'desc'); | ||||
| 
 | ||||
|  | ||||
| @ -58,7 +58,7 @@ class ClientTransformer extends EntityTransformer | ||||
| 
 | ||||
|     public function includeInvoices(Client $client) | ||||
|     { | ||||
|         $transformer = new InvoiceTransformer($this->account, $this->serializer); | ||||
|         $transformer = new InvoiceTransformer($this->account, $this->serializer, $client); | ||||
|         return $this->includeCollection($client->invoices, $transformer, ENTITY_INVOICE); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -37,4 +37,9 @@ class EntityTransformer extends TransformerAbstract | ||||
|     { | ||||
|         return $date ? $date->getTimestamp() : null; | ||||
|     } | ||||
|      | ||||
|     public function getDefaultIncludes() | ||||
|     { | ||||
|         return $this->defaultIncludes; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -6,9 +6,15 @@ use League\Fractal; | ||||
| 
 | ||||
| class ExpenseTransformer extends EntityTransformer | ||||
| { | ||||
|     public function __construct($account = null, $serializer = null, $client = null) | ||||
|     { | ||||
|         parent::__construct($account, $serializer); | ||||
|          | ||||
|         $this->client = $client; | ||||
|     } | ||||
| 
 | ||||
|     public function transform(Expense $expense) | ||||
|     { | ||||
| 
 | ||||
|         return [ | ||||
|             'id' => (int) $expense->public_id, | ||||
|             'private_notes' => $expense->private_notes, | ||||
| @ -25,7 +31,7 @@ class ExpenseTransformer extends EntityTransformer | ||||
|             'exchange_rate' => (float) $expense->exchange_rate, | ||||
|             'invoice_currency_id' => (int) $expense->invoice_currency_id, | ||||
|             'is_deleted' => (bool) $expense->is_deleted, | ||||
|             'client_id' => isset($expense->client->public_id) ? (int) $expense->client->public_id : null, | ||||
|             'client_id' => $this->client ? $this->client->public_id : (isset($expense->client->public_id) ? (int) $expense->client->public_id : null), | ||||
|             'invoice_id' => isset($expense->invoice->public_id) ? (int) $expense->invoice->public_id : null, | ||||
|             'vendor_id' => isset($expense->vendor->public_id) ? (int) $expense->vendor->public_id : null, | ||||
|         ]; | ||||
|  | ||||
| @ -31,6 +31,13 @@ class InvoiceTransformer extends EntityTransformer | ||||
|         'expenses', | ||||
|     ]; | ||||
| 
 | ||||
|     public function __construct($account = null, $serializer = null, $client = null) | ||||
|     { | ||||
|         parent::__construct($account, $serializer); | ||||
|          | ||||
|         $this->client = $client; | ||||
|     } | ||||
| 
 | ||||
|     public function includeInvoiceItems(Invoice $invoice) | ||||
|     { | ||||
|         $transformer = new InvoiceItemTransformer($this->account, $this->serializer); | ||||
| @ -45,7 +52,7 @@ class InvoiceTransformer extends EntityTransformer | ||||
| 
 | ||||
|     public function includePayments(Invoice $invoice) | ||||
|     { | ||||
|         $transformer = new PaymentTransformer($this->account, $this->serializer); | ||||
|         $transformer = new PaymentTransformer($this->account, $this->serializer, $invoice); | ||||
|         return $this->includeCollection($invoice->payments, $transformer, ENTITY_PAYMENT); | ||||
|     } | ||||
| 
 | ||||
| @ -68,7 +75,7 @@ class InvoiceTransformer extends EntityTransformer | ||||
|             'id' => (int) $invoice->public_id, | ||||
|             'amount' => (float) $invoice->amount, | ||||
|             'balance' => (float) $invoice->balance, | ||||
|             'client_id' => (int) $invoice->client->public_id, | ||||
|             'client_id' => (int) ($this->client ? $this->client->public_id : $invoice->client->public_id), | ||||
|             'invoice_status_id' => (int) $invoice->invoice_status_id, | ||||
|             'updated_at' => $this->getTimestamp($invoice->updated_at), | ||||
|             'archived_at' => $this->getTimestamp($invoice->deleted_at), | ||||
|  | ||||
| @ -26,10 +26,11 @@ class PaymentTransformer extends EntityTransformer | ||||
|     ]; | ||||
| 
 | ||||
| 
 | ||||
|     public function __construct(Account $account) | ||||
|     public function __construct($account = null, $serializer = null, $invoice = null) | ||||
|     { | ||||
|         parent::__construct($account); | ||||
| 
 | ||||
|         parent::__construct($account, $serializer); | ||||
|          | ||||
|         $this->invoice = $invoice; | ||||
|     } | ||||
| 
 | ||||
|     public function includeInvoice(Payment $payment) | ||||
| @ -57,7 +58,7 @@ class PaymentTransformer extends EntityTransformer | ||||
|             'archived_at' => $this->getTimestamp($payment->deleted_at), | ||||
|             'is_deleted' => (bool) $payment->is_deleted, | ||||
|             'payment_type_id' => (int) $payment->payment_type_id, | ||||
|             'invoice_id' => (int) $payment->invoice->public_id, | ||||
|             'invoice_id' => (int) ($this->invoice ? $this->invoice->public_id : $payment->invoice->public_id), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| @ -48,6 +48,7 @@ class ExpenseCest | ||||
| 
 | ||||
|         // invoice expense
 | ||||
|         $I->executeJS('submitAction(\'invoice\')'); | ||||
|         $I->wait(3); | ||||
|         $I->click('Save'); | ||||
|         $I->wait(3); | ||||
|         $I->see($clientEmail); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user