<?php

use Illuminate\Support\Facades\Log;

/*
|--------------------------------------------------------------------------
| Module Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for this module.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::group(['prefix' => Config::get('app.api_path'), 'middleware' => ['web', 'auth']], function () {
	
    Route::resource('invoices/sales', 'App\Modules\Invoices\controllers\api\v1\SalesControllerREST');
    Route::resource('invoices/invoices', 'App\Modules\Invoices\controllers\api\v1\InvoicesControllerREST');
    Route::resource('invoices/quotes', 'App\Modules\Invoices\controllers\api\v1\QuotesControllerREST');
    Route::resource('invoices/purchase-orders', 'App\Modules\Invoices\controllers\api\v1\PurchaseOrdersControllerREST');
    Route::resource('invoices.item', 'App\Modules\Invoices\InvoiceItemControllerREST');
    Route::resource('invoices/transactions', 'App\Modules\Invoices\controllers\api\v1\InvoiceTransactionsControllerREST', [
        'only' => ['store', 'update', 'destroy'],
        'names' => [
            'store' => 'invoices.transactions.store',
            'update' => 'invoices.transactions.update',
            'destroy' => 'invoices.transactions.destroy',
        ]
    ]);
    Route::post('invoices/convert-to-invoice/{id}', 'App\Modules\Invoices\controllers\api\v1\QuotesControllerREST@convertToInvoice');
    Route::post('invoices/transactions/online-payment', 'App\Modules\Invoices\controllers\api\v1\InvoiceTransactionsControllerREST@onlinePayment');
    Route::post('invoices/send-to-xero/{id}', 'App\Modules\Invoices\controllers\api\v1\InvoicesControllerREST@sendToXero');
    Route::post('invoices/sales/send-to-xero/{id}', 'App\Modules\Invoices\controllers\api\v1\SalesControllerREST@sendToXero');
    Route::post('invoices/email-invoice', 'App\Modules\Invoices\controllers\api\v1\InvoicesControllerREST@emailInvoice');
    Route::post('invoices/sales/email-invoice', 'App\Modules\Invoices\controllers\api\v1\SalesControllerREST@emailInvoice');

});

/*
|--------------------------------------------------------------------------
| Pages rendered on the server
|--------------------------------------------------------------------------
|
| This group routes are pages rendered on the server.
| All the pages require the user to be authentificated.
|
*/

Route::group(['middleware' => ['web', 'auth']], function () {
    Route::get('invoices', 'App\\Modules\\Invoices\\SalesController@getIndex');
});
