mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-28 04:01:10 -04:00 
			
		
		
		
	Compare commits
	
		
			48 Commits
		
	
	
		
			NickCrater
			...
			6.0.1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d877b16776 | |||
| eac1bbb622 | |||
| 4ef5e7e54b | |||
| e2bb414efe | |||
| 941bc4bdb8 | |||
| a14655d73b | |||
| d303b1a71c | |||
| f677a54c2a | |||
| 37fa96b29a | |||
| 147be77859 | |||
| 6ef2553423 | |||
| 22f6a48b5b | |||
| 897d759758 | |||
| bcd80377cf | |||
| dcb3ddecb9 | |||
| 1197215ff6 | |||
| 4ca56de585 | |||
| b7c344132d | |||
| 9eae813c24 | |||
| 54f76f7cbe | |||
| bdea879273 | |||
| 6c5dcfe227 | |||
| f79becad07 | |||
| c150c4edeb | |||
| d2dee7d511 | |||
| fa9134610c | |||
| 02aabacd50 | |||
| a20c0a5ef9 | |||
| df33776873 | |||
| faf1ef0998 | |||
| 65404d5d6f | |||
| cdc913d16c | |||
| c9d0a63854 | |||
| 2fd8d8a5f4 | |||
| 2765f35f98 | |||
| 9652e3bdf5 | |||
| f5c4f66165 | |||
| 848970fc08 | |||
| 37226fb35b | |||
| f59bae9518 | |||
| d2dcc44817 | |||
| 4a85a5d2ab | |||
| 7f04781604 | |||
| 99b1cc80c6 | |||
| 6ce74bd59f | |||
| b24350aba6 | |||
| 72398f0ac9 | |||
| fbe25517e2 | 
| @ -36,3 +36,5 @@ SANCTUM_STATEFUL_DOMAINS=crater.test | ||||
| SESSION_DOMAIN=crater.test | ||||
|  | ||||
| TRUSTED_PROXIES="*" | ||||
|  | ||||
| CRON_JOB_AUTH_TOKEN="" | ||||
|  | ||||
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,3 +1,4 @@ | ||||
| /Modules | ||||
| /node_modules | ||||
| /public/storage | ||||
| /public/hot | ||||
| @ -12,3 +13,4 @@ Homestead.yaml | ||||
| /.expo | ||||
| /.vscode | ||||
| /docker-compose/db/data/ | ||||
| .gitkeep | ||||
|  | ||||
							
								
								
									
										45
									
								
								app/Console/Commands/InstallModuleCommand.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								app/Console/Commands/InstallModuleCommand.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Console\Commands; | ||||
|  | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Console\Command; | ||||
|  | ||||
| class InstallModuleCommand extends Command | ||||
| { | ||||
|     /** | ||||
|      * The name and signature of the console command. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $signature = 'install:module {module} {version}'; | ||||
|  | ||||
|     /** | ||||
|      * The console command description. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $description = 'Install cloned module.'; | ||||
|  | ||||
|     /** | ||||
|      * Create a new command instance. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         parent::__construct(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Execute the console command. | ||||
|      * | ||||
|      * @return int | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         ModuleInstaller::complete($this->argument('module'), $this->argument('version')); | ||||
|  | ||||
|         return Command::SUCCESS; | ||||
|     } | ||||
| } | ||||
| @ -16,7 +16,8 @@ class Kernel extends ConsoleKernel | ||||
|     protected $commands = [ | ||||
|         Commands\ResetApp::class, | ||||
|         Commands\UpdateCommand::class, | ||||
|         Commands\CreateTemplateCommand::class | ||||
|         Commands\CreateTemplateCommand::class, | ||||
|         Commands\InstallModuleCommand::class, | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|  | ||||
							
								
								
									
										26
									
								
								app/Events/ModuleDisabledEvent.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/Events/ModuleDisabledEvent.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Events; | ||||
|  | ||||
| use Illuminate\Broadcasting\InteractsWithSockets; | ||||
| use Illuminate\Foundation\Events\Dispatchable; | ||||
| use Illuminate\Queue\SerializesModels; | ||||
|  | ||||
| class ModuleDisabledEvent | ||||
| { | ||||
|     use Dispatchable; | ||||
|     use InteractsWithSockets; | ||||
|     use SerializesModels; | ||||
|  | ||||
|     public $module; | ||||
|  | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function __construct($module) | ||||
|     { | ||||
|         $this->module = $module; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										26
									
								
								app/Events/ModuleEnabledEvent.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/Events/ModuleEnabledEvent.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Events; | ||||
|  | ||||
| use Illuminate\Broadcasting\InteractsWithSockets; | ||||
| use Illuminate\Foundation\Events\Dispatchable; | ||||
| use Illuminate\Queue\SerializesModels; | ||||
|  | ||||
| class ModuleEnabledEvent | ||||
| { | ||||
|     use Dispatchable; | ||||
|     use InteractsWithSockets; | ||||
|     use SerializesModels; | ||||
|  | ||||
|     public $module; | ||||
|  | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function __construct($module) | ||||
|     { | ||||
|         $this->module = $module; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										26
									
								
								app/Events/ModuleInstalledEvent.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/Events/ModuleInstalledEvent.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Events; | ||||
|  | ||||
| use Illuminate\Broadcasting\InteractsWithSockets; | ||||
| use Illuminate\Foundation\Events\Dispatchable; | ||||
| use Illuminate\Queue\SerializesModels; | ||||
|  | ||||
| class ModuleInstalledEvent | ||||
| { | ||||
|     use Dispatchable; | ||||
|     use InteractsWithSockets; | ||||
|     use SerializesModels; | ||||
|  | ||||
|     public $module; | ||||
|  | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function __construct($module) | ||||
|     { | ||||
|         $this->module = $module; | ||||
|     } | ||||
| } | ||||
| @ -83,6 +83,8 @@ class ConvertEstimateController extends Controller | ||||
|             'base_total' => $estimate->total * $exchange_rate, | ||||
|             'base_tax' => $estimate->tax * $exchange_rate, | ||||
|             'currency_id' => $estimate->currency_id, | ||||
|             'sales_tax_type' => $estimate->sales_tax_type, | ||||
|             'sales_tax_address_type' => $estimate->sales_tax_address_type, | ||||
|         ]); | ||||
|  | ||||
|         $invoice->unique_hash = Hashids::connection(Invoice::class)->encode($invoice->id); | ||||
|  | ||||
| @ -21,6 +21,9 @@ class SendEstimatePreviewController extends Controller | ||||
|  | ||||
|         $markdown = new Markdown(view(), config('mail.markdown')); | ||||
|  | ||||
|         return $markdown->render('emails.send.estimate', ['data' => $estimate->sendEstimateData($request->all())]); | ||||
|         $data = $estimate->sendEstimateData($request->all()); | ||||
|         $data['url'] = $estimate->estimatePdfUrl; | ||||
|  | ||||
|         return $markdown->render('emails.send.estimate', ['data' => $data]); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -39,7 +39,7 @@ class ExpensesController extends Controller | ||||
|     /** | ||||
|      * Store a newly created resource in storage. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request $request | ||||
|      * @param  \Crater\Http\Requests\ExpenseRequest $request | ||||
|      * @return \Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|     public function store(ExpenseRequest $request) | ||||
| @ -67,7 +67,7 @@ class ExpensesController extends Controller | ||||
|     /** | ||||
|      * Update the specified resource in storage. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request $request | ||||
|      * @param  \Crater\Http\Requests\ExpenseRequest $request | ||||
|      * @param  \Crater\Models\Expense $expense | ||||
|      * @return \Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|  | ||||
| @ -3,19 +3,19 @@ | ||||
| namespace Crater\Http\Controllers\V1\Admin\Expense; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Requests\ExpenseRequest; | ||||
| use Crater\Models\Expense; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class UploadReceiptController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Upload the expense receipts to storage. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request $request | ||||
|      * @param  \Crater\Http\Requests\ExpenseRequest $request | ||||
|      * @param  Expense $expense | ||||
|      * @return \Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|     public function __invoke(Request $request, Expense $expense) | ||||
|     public function __invoke(ExpenseRequest $request, Expense $expense) | ||||
|     { | ||||
|         $this->authorize('update', $expense); | ||||
|  | ||||
|  | ||||
| @ -8,6 +8,8 @@ use Crater\Http\Resources\UserResource; | ||||
| use Crater\Models\Company; | ||||
| use Crater\Models\CompanySetting; | ||||
| use Crater\Models\Currency; | ||||
| use Crater\Models\Module; | ||||
| use Crater\Models\Setting; | ||||
| use Crater\Traits\GeneratesMenuTrait; | ||||
| use Illuminate\Http\Request; | ||||
| use Silber\Bouncer\BouncerFacade; | ||||
| @ -47,6 +49,8 @@ class BootstrapController extends Controller | ||||
|  | ||||
|         BouncerFacade::refreshFor($current_user); | ||||
|  | ||||
|         $global_settings = Setting::getSettings(['api_token', 'admin_portal_theme']); | ||||
|  | ||||
|         return response()->json([ | ||||
|             'current_user' => new UserResource($current_user), | ||||
|             'current_user_settings' => $current_user_settings, | ||||
| @ -56,8 +60,10 @@ class BootstrapController extends Controller | ||||
|             'current_company_settings' => $current_company_settings, | ||||
|             'current_company_currency' => $current_company_currency, | ||||
|             'config' => config('crater'), | ||||
|             'global_settings' => $global_settings, | ||||
|             'main_menu' => $main_menu, | ||||
|             'setting_menu' => $setting_menu, | ||||
|             'modules' => Module::where('enabled', true)->pluck('name'), | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -20,6 +20,7 @@ class SearchController extends Controller | ||||
|         $user = $request->user(); | ||||
|  | ||||
|         $customers = Customer::applyFilters($request->only(['search'])) | ||||
|             ->whereCompany() | ||||
|             ->latest() | ||||
|             ->paginate(10); | ||||
|  | ||||
|  | ||||
| @ -76,6 +76,8 @@ class CloneInvoiceController extends Controller | ||||
|             'base_tax' => $invoice->tax * $exchange_rate, | ||||
|             'base_due_amount' => $invoice->total * $exchange_rate, | ||||
|             'currency_id' => $invoice->currency_id, | ||||
|             'sales_tax_type' => $invoice->sales_tax_type, | ||||
|             'sales_tax_address_type' => $invoice->sales_tax_address_type, | ||||
|         ]); | ||||
|  | ||||
|         $newInvoice->unique_hash = Hashids::connection(Invoice::class)->encode($newInvoice->id); | ||||
|  | ||||
| @ -21,6 +21,9 @@ class SendInvoicePreviewController extends Controller | ||||
|  | ||||
|         $markdown = new Markdown(view(), config('mail.markdown')); | ||||
|  | ||||
|         return $markdown->render('emails.send.invoice', ['data' => $invoice->sendInvoiceData($request->all())]); | ||||
|         $data = $invoice->sendInvoiceData($request->all()); | ||||
|         $data['url'] = $invoice->invoicePdfUrl; | ||||
|  | ||||
|         return $markdown->render('emails.send.invoice', ['data' => $data]); | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										25
									
								
								app/Http/Controllers/V1/Admin/Modules/ApiTokenController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								app/Http/Controllers/V1/Admin/Modules/ApiTokenController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class ApiTokenController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $response = ModuleInstaller::checkToken($request->api_token); | ||||
|  | ||||
|         return $response; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class CompleteModuleInstallationController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $response = ModuleInstaller::complete($request->module, $request->version); | ||||
|  | ||||
|         return response()->json([ | ||||
|             'success' => $response | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class CopyModuleController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $response = ModuleInstaller::copyFiles($request->module, $request->path); | ||||
|  | ||||
|         return response()->json([ | ||||
|             'success' => $response | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,32 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Events\ModuleDisabledEvent; | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Models\Module as ModelsModule; | ||||
| use Illuminate\Http\Request; | ||||
| use Nwidart\Modules\Facades\Module; | ||||
|  | ||||
| class DisableModuleController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request, string $module) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $module = ModelsModule::where('name', $module)->first(); | ||||
|         $module->update(['enabled' => false]); | ||||
|         $installedModule = Module::find($module->name); | ||||
|         $installedModule->disable(); | ||||
|  | ||||
|         ModuleDisabledEvent::dispatch($module); | ||||
|  | ||||
|         return response()->json(['success' => true]); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class DownloadModuleController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $response = ModuleInstaller::download($request->module, $request->version); | ||||
|  | ||||
|         return response()->json($response); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,32 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Events\ModuleEnabledEvent; | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Models\Module as ModelsModule; | ||||
| use Illuminate\Http\Request; | ||||
| use Nwidart\Modules\Facades\Module; | ||||
|  | ||||
| class EnableModuleController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request, string $module) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $module = ModelsModule::where('name', $module)->first(); | ||||
|         $module->update(['enabled' => true]); | ||||
|         $installedModule = Module::find($module->name); | ||||
|         $installedModule->enable(); | ||||
|  | ||||
|         ModuleEnabledEvent::dispatch($module); | ||||
|  | ||||
|         return response()->json(['success' => true]); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										33
									
								
								app/Http/Controllers/V1/Admin/Modules/ModuleController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								app/Http/Controllers/V1/Admin/Modules/ModuleController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\ModuleResource; | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class ModuleController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request, string $module) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $response = ModuleInstaller::getModule($module); | ||||
|  | ||||
|         if (! $response->success) { | ||||
|             return response()->json($response); | ||||
|         } | ||||
|  | ||||
|         return (new ModuleResource($response->module)) | ||||
|             ->additional(['meta' => [ | ||||
|                 'modules' => ModuleResource::collection(collect($response->modules)) | ||||
|             ]]); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										25
									
								
								app/Http/Controllers/V1/Admin/Modules/ModulesController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								app/Http/Controllers/V1/Admin/Modules/ModulesController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class ModulesController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $response = ModuleInstaller::getModules(); | ||||
|  | ||||
|         return $response; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,28 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class UnzipModuleController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $path = ModuleInstaller::unzip($request->module, $request->path); | ||||
|  | ||||
|         return response()->json([ | ||||
|             'success' => true, | ||||
|             'path' => $path | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Space\ModuleInstaller; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class UploadModuleController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $this->authorize('manage modules'); | ||||
|  | ||||
|         $response = ModuleInstaller::upload($request); | ||||
|  | ||||
|         return response()->json($response); | ||||
|     } | ||||
| } | ||||
| @ -22,6 +22,7 @@ class PaymentMethodsController extends Controller | ||||
|         $limit = $request->has('limit') ? $request->limit : 5; | ||||
|  | ||||
|         $paymentMethods = PaymentMethod::applyFilters($request->all()) | ||||
|             ->where('type', PaymentMethod::TYPE_GENERAL) | ||||
|             ->whereCompany() | ||||
|             ->latest() | ||||
|             ->paginateData($limit); | ||||
| @ -68,7 +69,7 @@ class PaymentMethodsController extends Controller | ||||
|     { | ||||
|         $this->authorize('update', $paymentMethod); | ||||
|  | ||||
|         $paymentMethod->update($request->validated()); | ||||
|         $paymentMethod->update($request->getPaymentMethodPayload()); | ||||
|  | ||||
|         return new PaymentMethodResource($paymentMethod); | ||||
|     } | ||||
|  | ||||
| @ -21,6 +21,9 @@ class SendPaymentPreviewController extends Controller | ||||
|  | ||||
|         $markdown = new Markdown(view(), config('mail.markdown')); | ||||
|  | ||||
|         return $markdown->render('emails.send.payment', ['data' => $payment->sendPaymentData($request->all())]); | ||||
|         $data = $payment->sendPaymentData($request->all()); | ||||
|         $data['url'] = $payment->paymentPdfUrl; | ||||
|  | ||||
|         return $markdown->render('emails.send.payment', ['data' => $data]); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -3,6 +3,8 @@ | ||||
| namespace Crater\Http\Controllers\V1\Admin\Settings; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Requests\AvatarRequest; | ||||
| use Crater\Http\Requests\CompanyLogoRequest; | ||||
| use Crater\Http\Requests\CompanyRequest; | ||||
| use Crater\Http\Requests\ProfileRequest; | ||||
| use Crater\Http\Resources\CompanyResource; | ||||
| @ -48,7 +50,7 @@ class CompanyController extends Controller | ||||
|  | ||||
|         $this->authorize('manage company', $company); | ||||
|  | ||||
|         $company->update($request->only('name')); | ||||
|         $company->update($request->getCompanyPayload()); | ||||
|  | ||||
|         $company->address()->updateOrCreate(['company_id' => $company->id], $request->address); | ||||
|  | ||||
| @ -58,10 +60,10 @@ class CompanyController extends Controller | ||||
|     /** | ||||
|      * Upload the company logo to storage. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request $request | ||||
|      * @param  \Crater\Http\Requests\CompanyLogoRequest $request | ||||
|      * @return \Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|     public function uploadCompanyLogo(Request $request) | ||||
|     public function uploadCompanyLogo(CompanyLogoRequest $request) | ||||
|     { | ||||
|         $company = Company::find($request->header('company')); | ||||
|  | ||||
| @ -89,10 +91,10 @@ class CompanyController extends Controller | ||||
|     /** | ||||
|      * Upload the Admin Avatar to public storage. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request $request | ||||
|      * @param  \Crater\Http\Requests\AvatarRequest $request | ||||
|      * @return \Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|     public function uploadAvatar(Request $request) | ||||
|     public function uploadAvatar(AvatarRequest $request) | ||||
|     { | ||||
|         $user = auth()->user(); | ||||
|  | ||||
|  | ||||
| @ -0,0 +1,28 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Settings; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Requests\GetSettingRequest; | ||||
| use Crater\Models\Setting; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class GetSettingsController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(GetSettingRequest $request) | ||||
|     { | ||||
|         $this->authorize('manage settings'); | ||||
|  | ||||
|         $setting = Setting::getSetting($request->key); | ||||
|  | ||||
|         return response()->json([ | ||||
|             $request->key => $setting | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -22,6 +22,7 @@ class TaxTypesController extends Controller | ||||
|         $limit = $request->has('limit') ? $request->limit : 5; | ||||
|  | ||||
|         $taxTypes = TaxType::applyFilters($request->all()) | ||||
|             ->where('type', TaxType::TYPE_GENERAL) | ||||
|             ->whereCompany() | ||||
|             ->latest() | ||||
|             ->paginateData($limit); | ||||
|  | ||||
| @ -0,0 +1,29 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Admin\Settings; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Requests\SettingRequest; | ||||
| use Crater\Models\Setting; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class UpdateSettingsController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(SettingRequest $request) | ||||
|     { | ||||
|         $this->authorize('manage settings'); | ||||
|  | ||||
|         Setting::setSettings($request->settings); | ||||
|  | ||||
|         return response()->json([ | ||||
|             'success' => true, | ||||
|             $request->settings | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,56 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Auth; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Illuminate\Foundation\Auth\SendsPasswordResetEmails; | ||||
| use Illuminate\Http\Request; | ||||
| use Password; | ||||
|  | ||||
| class ForgotPasswordController extends Controller | ||||
| { | ||||
|     /* | ||||
|     |-------------------------------------------------------------------------- | ||||
|     | Password Reset Controller | ||||
|     |-------------------------------------------------------------------------- | ||||
|     | | ||||
|     | This controller is responsible for handling password reset emails and | ||||
|     | includes a trait which assists in sending these notifications from | ||||
|     | your application to your users. Feel free to explore this trait. | ||||
|     | | ||||
|     */ | ||||
|  | ||||
|     use SendsPasswordResetEmails; | ||||
|  | ||||
|     public function broker() | ||||
|     { | ||||
|         return Password::broker('customers'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the response for a successful password reset link. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @param  string  $response | ||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|     protected function sendResetLinkResponse(Request $request, $response) | ||||
|     { | ||||
|         return response()->json([ | ||||
|             'message' => 'Password reset email sent.', | ||||
|             'data' => $response, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the response for a failed password reset link. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @param  string  $response | ||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|     protected function sendResetLinkFailedResponse(Request $request, $response) | ||||
|     { | ||||
|         return response('Email could not be sent to this email address.', 403); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										45
									
								
								app/Http/Controllers/V1/Customer/Auth/LoginController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								app/Http/Controllers/V1/Customer/Auth/LoginController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Auth; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Requests\Customer\CustomerLoginRequest; | ||||
| use Crater\Models\Company; | ||||
| use Crater\Models\Customer; | ||||
| use Hash; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
| use Illuminate\Validation\ValidationException; | ||||
|  | ||||
| class LoginController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Crater\Http\Requests\Customer\CustomerLoginRequest  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(CustomerLoginRequest $request, Company $company) | ||||
|     { | ||||
|         $user = Customer::where('email', $request->email) | ||||
|             ->where('company_id', $company->id) | ||||
|             ->first(); | ||||
|  | ||||
|         if (! $user || ! Hash::check($request->password, $user->password)) { | ||||
|             throw ValidationException::withMessages([ | ||||
|                 'email' => ['The provided credentials are incorrect.'], | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         if (! $user->enable_portal) { | ||||
|             throw ValidationException::withMessages([ | ||||
|                 'email' => ['Customer portal not available for this user.'], | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         Auth::guard('customer')->login($user); | ||||
|  | ||||
|         return response()->json([ | ||||
|             'success' => true | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,83 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Auth; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Providers\RouteServiceProvider; | ||||
| use Illuminate\Auth\Events\PasswordReset; | ||||
| use Illuminate\Foundation\Auth\ResetsPasswords; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Str; | ||||
| use Password; | ||||
|  | ||||
| class ResetPasswordController extends Controller | ||||
| { | ||||
|     /* | ||||
|     |-------------------------------------------------------------------------- | ||||
|     | Password Reset Controller | ||||
|     |-------------------------------------------------------------------------- | ||||
|     | | ||||
|     | This controller is responsible for handling password reset requests | ||||
|     | and uses a simple trait to include this behavior. You're free to | ||||
|     | explore this trait and override any methods you wish to tweak. | ||||
|     | | ||||
|     */ | ||||
|  | ||||
|     use ResetsPasswords; | ||||
|  | ||||
|     /** | ||||
|      * Where to redirect users after resetting their password. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $redirectTo = RouteServiceProvider::CUSTOMER_HOME; | ||||
|  | ||||
|     public function broker() | ||||
|     { | ||||
|         return Password::broker('customers'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the response for a successful password reset. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @param  string  $response | ||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|     protected function sendResetResponse(Request $request, $response) | ||||
|     { | ||||
|         return response()->json([ | ||||
|             'message' => 'Password reset successfully.', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Reset the given user's password. | ||||
|      * | ||||
|      * @param  \Illuminate\Contracts\Auth\CanResetPassword  $user | ||||
|      * @param  string  $password | ||||
|      * @return void | ||||
|      */ | ||||
|     protected function resetPassword($user, $password) | ||||
|     { | ||||
|         $user->password = $password; | ||||
|  | ||||
|         $user->setRememberToken(Str::random(60)); | ||||
|  | ||||
|         $user->save(); | ||||
|  | ||||
|         event(new PasswordReset($user)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the response for a failed password reset. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @param  string  $response | ||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse | ||||
|      */ | ||||
|     protected function sendResetFailedResponse(Request $request, $response) | ||||
|     { | ||||
|         return response('Failed, Invalid Token.', 403); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,36 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Estimate; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\Customer\EstimateResource; | ||||
| use Crater\Models\Company; | ||||
| use Crater\Models\Estimate; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class AcceptEstimateController extends Controller | ||||
| { | ||||
|     /** | ||||
|     * Handle the incoming request. | ||||
|     * | ||||
|     * @param  \Illuminate\Http\Request  $request | ||||
|     * @param  Estimate $estimate | ||||
|     * @return \Illuminate\Http\Response | ||||
|     */ | ||||
|     public function __invoke(Request $request, Company $company, $id) | ||||
|     { | ||||
|         $estimate = $company->estimates() | ||||
|             ->whereCustomer(Auth::guard('customer')->id()) | ||||
|             ->where('id', $id) | ||||
|             ->first(); | ||||
|  | ||||
|         if (! $estimate) { | ||||
|             return response()->json(['error' => 'estimate_not_found'], 404); | ||||
|         } | ||||
|  | ||||
|         $estimate->update($request->only('status')); | ||||
|  | ||||
|         return new EstimateResource($estimate); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,67 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Estimate; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\Customer\EstimateResource; | ||||
| use Crater\Models\Company; | ||||
| use Crater\Models\Estimate; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class EstimatesController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Display a listing of the resource. | ||||
|      * | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function index(Request $request) | ||||
|     { | ||||
|         $limit = $request->has('limit') ? $request->limit : 10; | ||||
|  | ||||
|         $estimates = Estimate::with([ | ||||
|                 'items', | ||||
|                 'customer', | ||||
|                 'taxes', | ||||
|                 'creator', | ||||
|             ]) | ||||
|             ->where('status', '<>', 'DRAFT') | ||||
|             ->whereCustomer(Auth::guard('customer')->id()) | ||||
|             ->applyFilters($request->only([ | ||||
|                 'status', | ||||
|                 'estimate_number', | ||||
|                 'from_date', | ||||
|                 'to_date', | ||||
|                 'orderByField', | ||||
|                 'orderBy', | ||||
|             ])) | ||||
|             ->latest() | ||||
|             ->paginateData($limit); | ||||
|  | ||||
|         return (EstimateResource::collection($estimates)) | ||||
|             ->additional(['meta' => [ | ||||
|                 'estimateTotalCount' => Estimate::where('status', '<>', 'DRAFT')->whereCustomer(Auth::guard('customer')->id())->count(), | ||||
|             ]]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Display the specified resource. | ||||
|      * | ||||
|      * @param  Estimate $estimate | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function show(Company $company, $id) | ||||
|     { | ||||
|         $estimate = $company->estimates() | ||||
|             ->whereCustomer(Auth::guard('customer')->id()) | ||||
|             ->where('id', $id) | ||||
|             ->first(); | ||||
|  | ||||
|         if (! $estimate) { | ||||
|             return response()->json(['error' => 'estimate_not_found'], 404); | ||||
|         } | ||||
|  | ||||
|         return new EstimateResource($estimate); | ||||
|     } | ||||
| } | ||||
| @ -3,41 +3,51 @@ | ||||
| namespace Crater\Http\Controllers\V1\Customer; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\EstimateResource; | ||||
| use Crater\Mail\EstimateViewedMail; | ||||
| use Crater\Models\CompanySetting; | ||||
| use Crater\Models\Customer; | ||||
| use Crater\Models\EmailLog; | ||||
| use Crater\Models\Estimate; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class EstimatePdfController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Estimate $estimate) | ||||
|     public function getPdf(EmailLog $emailLog, Request $request) | ||||
|     { | ||||
|         if ($estimate && ($estimate->status == Estimate::STATUS_SENT || $estimate->status == Estimate::STATUS_DRAFT)) { | ||||
|             $estimate->status = Estimate::STATUS_VIEWED; | ||||
|             $estimate->save(); | ||||
|             $notifyEstimateViewed = CompanySetting::getSetting( | ||||
|                 'notify_estimate_viewed', | ||||
|                 $estimate->company_id | ||||
|             ); | ||||
|         $estimate = Estimate::find($emailLog->mailable_id); | ||||
|  | ||||
|             if ($notifyEstimateViewed == 'YES') { | ||||
|                 $data['estimate'] = Estimate::findOrFail($estimate->id)->toArray(); | ||||
|                 $data['user'] = Customer::find($estimate->customer_id)->toArray(); | ||||
|                 $notificationEmail = CompanySetting::getSetting( | ||||
|                     'notification_email', | ||||
|         if (! $emailLog->isExpired()) { | ||||
|             if ($estimate && ($estimate->status == Estimate::STATUS_SENT || $estimate->status == Estimate::STATUS_DRAFT)) { | ||||
|                 $estimate->status = Estimate::STATUS_VIEWED; | ||||
|                 $estimate->save(); | ||||
|                 $notifyEstimateViewed = CompanySetting::getSetting( | ||||
|                     'notify_estimate_viewed', | ||||
|                     $estimate->company_id | ||||
|                 ); | ||||
|  | ||||
|                 \Mail::to($notificationEmail)->send(new EstimateViewedMail($data)); | ||||
|                 if ($notifyEstimateViewed == 'YES') { | ||||
|                     $data['estimate'] = Estimate::findOrFail($estimate->id)->toArray(); | ||||
|                     $data['user'] = Customer::find($estimate->customer_id)->toArray(); | ||||
|                     $notificationEmail = CompanySetting::getSetting( | ||||
|                         'notification_email', | ||||
|                         $estimate->company_id | ||||
|                     ); | ||||
|  | ||||
|                     \Mail::to($notificationEmail)->send(new EstimateViewedMail($data)); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             return $estimate->getGeneratedPDFOrStream('estimate'); | ||||
|         } | ||||
|  | ||||
|         return $estimate->getGeneratedPDFOrStream('estimate'); | ||||
|         abort(403, 'Link Expired.'); | ||||
|     } | ||||
|  | ||||
|     public function getEstimate(EmailLog $emailLog) | ||||
|     { | ||||
|         $estimate = Estimate::find($emailLog->mailable_id); | ||||
|  | ||||
|         return new EstimateResource($estimate); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,59 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Expense; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\Customer\ExpenseResource; | ||||
| use Crater\Models\Company; | ||||
| use Crater\Models\Expense; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class ExpensesController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Display a listing of the resource. | ||||
|      * | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function index(Request $request) | ||||
|     { | ||||
|         $limit = $request->has('limit') ? $request->limit : 10; | ||||
|  | ||||
|         $expenses = Expense::with('category', 'creator', 'fields') | ||||
|             ->whereUser(Auth::guard('customer')->id()) | ||||
|             ->applyFilters($request->only([ | ||||
|                 'expense_category_id', | ||||
|                 'from_date', | ||||
|                 'to_date', | ||||
|                 'orderByField', | ||||
|                 'orderBy', | ||||
|             ])) | ||||
|             ->paginateData($limit); | ||||
|  | ||||
|         return (ExpenseResource::collection($expenses)) | ||||
|             ->additional(['meta' => [ | ||||
|                 'expenseTotalCount' => Expense::whereCustomer(Auth::guard('customer')->id())->count(), | ||||
|             ]]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Display the specified resource. | ||||
|      * | ||||
|      * @param  \Crater\Models\Expense  $expense | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function show(Company $company, $id) | ||||
|     { | ||||
|         $expense = $company->expenses() | ||||
|             ->whereUser(Auth::guard('customer')->id()) | ||||
|             ->where('id', $id) | ||||
|             ->first(); | ||||
|  | ||||
|         if (! $expense) { | ||||
|             return response()->json(['error' => 'expense_not_found'], 404); | ||||
|         } | ||||
|  | ||||
|         return new ExpenseResource($expense); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,40 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\General; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\Customer\CustomerResource; | ||||
| use Crater\Models\Currency; | ||||
| use Crater\Models\Module; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class BootstrapController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $customer = Auth::guard('customer')->user(); | ||||
|  | ||||
|         foreach (\Menu::get('customer_portal_menu')->items->toArray() as $data) { | ||||
|             if ($customer) { | ||||
|                 $menu[] = [ | ||||
|                     'title' => $data->title, | ||||
|                     'link' => $data->link->path['url'], | ||||
|                 ]; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return (new CustomerResource($customer)) | ||||
|             ->additional(['meta' => [ | ||||
|                 'menu' => $menu, | ||||
|                 'current_customer_currency' => Currency::find($customer->currency_id), | ||||
|                 'modules' => Module::where('enabled', true)->pluck('name'), | ||||
|             ]]); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,45 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\General; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Models\Estimate; | ||||
| use Crater\Models\Invoice; | ||||
| use Crater\Models\Payment; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class DashboardController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         $user = Auth::guard('customer')->user(); | ||||
|  | ||||
|         $amountDue = Invoice::whereCustomer($user->id) | ||||
|             ->where('status', '<>', 'DRAFT') | ||||
|             ->sum('due_amount'); | ||||
|         $invoiceCount = Invoice::whereCustomer($user->id) | ||||
|             ->where('status', '<>', 'DRAFT') | ||||
|             ->count(); | ||||
|         $estimatesCount = Estimate::whereCustomer($user->id) | ||||
|             ->where('status', '<>', 'DRAFT') | ||||
|             ->count(); | ||||
|         $paymentCount = Payment::whereCustomer($user->id) | ||||
|             ->count(); | ||||
|  | ||||
|         return response()->json([ | ||||
|             'due_amount' => $amountDue, | ||||
|             'recentInvoices' => Invoice::whereCustomer($user->id)->where('status', '<>', 'DRAFT')->take(5)->latest()->get(), | ||||
|             'recentEstimates' => Estimate::whereCustomer($user->id)->where('status', '<>', 'DRAFT')->take(5)->latest()->get(), | ||||
|             'invoice_count' => $invoiceCount, | ||||
|             'estimate_count' => $estimatesCount, | ||||
|             'payment_count' => $paymentCount, | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,46 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\General; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Requests\Customer\CustomerProfileRequest; | ||||
| use Crater\Http\Resources\Customer\CustomerResource; | ||||
| use Crater\Models\Company; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class ProfileController extends Controller | ||||
| { | ||||
|     public function updateProfile(Company $company, CustomerProfileRequest $request) | ||||
|     { | ||||
|         $customer = Auth::guard('customer')->user(); | ||||
|  | ||||
|         $customer->update($request->validated()); | ||||
|  | ||||
|         if ($customer && $request->hasFile('customer_avatar')) { | ||||
|             $customer->clearMediaCollection('customer_avatar'); | ||||
|  | ||||
|             $customer->addMediaFromRequest('customer_avatar') | ||||
|             ->toMediaCollection('customer_avatar'); | ||||
|         } | ||||
|  | ||||
|         if ($request->billing !== null) { | ||||
|             $customer->shippingAddress()->delete(); | ||||
|             $customer->addresses()->create($request->getShippingAddress()); | ||||
|         } | ||||
|  | ||||
|         if ($request->shipping !== null) { | ||||
|             $customer->billingAddress()->delete(); | ||||
|             $customer->addresses()->create($request->getBillingAddress()); | ||||
|         } | ||||
|  | ||||
|         return new CustomerResource($customer); | ||||
|     } | ||||
|  | ||||
|     public function getUser(Request $request) | ||||
|     { | ||||
|         $customer = Auth::guard('customer')->user(); | ||||
|  | ||||
|         return new CustomerResource($customer); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,49 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Invoice; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\Customer\InvoiceResource; | ||||
| use Crater\Models\Company; | ||||
| use Crater\Models\Invoice; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class InvoicesController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Display a listing of the resource. | ||||
|      * | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function index(Request $request) | ||||
|     { | ||||
|         $limit = $request->has('limit') ? $request->limit : 10; | ||||
|  | ||||
|         $invoices = Invoice::with(['items', 'customer', 'creator', 'taxes']) | ||||
|             ->where('status', '<>', 'DRAFT') | ||||
|             ->applyFilters($request->all()) | ||||
|             ->whereCustomer(Auth::guard('customer')->id()) | ||||
|             ->latest() | ||||
|             ->paginateData($limit); | ||||
|  | ||||
|         return (InvoiceResource::collection($invoices)) | ||||
|             ->additional(['meta' => [ | ||||
|                 'invoiceTotalCount' => Invoice::where('status', '<>', 'DRAFT')->whereCustomer(Auth::guard('customer')->id())->count(), | ||||
|             ]]); | ||||
|     } | ||||
|  | ||||
|     public function show(Company $company, $id) | ||||
|     { | ||||
|         $invoice = $company->invoices() | ||||
|             ->whereCustomer(Auth::guard('customer')->id()) | ||||
|             ->where('id', $id) | ||||
|             ->first(); | ||||
|  | ||||
|         if (! $invoice) { | ||||
|             return response()->json(['error' => 'invoice_not_found'], 404); | ||||
|         } | ||||
|  | ||||
|         return new InvoiceResource($invoice); | ||||
|     } | ||||
| } | ||||
| @ -3,42 +3,59 @@ | ||||
| namespace Crater\Http\Controllers\V1\Customer; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\Customer\InvoiceResource as CustomerInvoiceResource; | ||||
| use Crater\Mail\InvoiceViewedMail; | ||||
| use Crater\Models\CompanySetting; | ||||
| use Crater\Models\Customer; | ||||
| use Crater\Models\EmailLog; | ||||
| use Crater\Models\Invoice; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class InvoicePdfController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Invoice $invoice) | ||||
|     public function getPdf(EmailLog $emailLog, Request $request) | ||||
|     { | ||||
|         if ($invoice && ($invoice->status == Invoice::STATUS_SENT || $invoice->status == Invoice::STATUS_DRAFT)) { | ||||
|             $invoice->status = Invoice::STATUS_VIEWED; | ||||
|             $invoice->viewed = true; | ||||
|             $invoice->save(); | ||||
|             $notifyInvoiceViewed = CompanySetting::getSetting( | ||||
|                 'notify_invoice_viewed', | ||||
|                 $invoice->company_id | ||||
|             ); | ||||
|         $invoice = Invoice::find($emailLog->mailable_id); | ||||
|  | ||||
|             if ($notifyInvoiceViewed == 'YES') { | ||||
|                 $data['invoice'] = Invoice::findOrFail($invoice->id)->toArray(); | ||||
|                 $data['user'] = Customer::find($invoice->customer_id)->toArray(); | ||||
|                 $notificationEmail = CompanySetting::getSetting( | ||||
|                     'notification_email', | ||||
|         if (! $emailLog->isExpired()) { | ||||
|             if ($invoice && ($invoice->status == Invoice::STATUS_SENT || $invoice->status == Invoice::STATUS_DRAFT)) { | ||||
|                 $invoice->status = Invoice::STATUS_VIEWED; | ||||
|                 $invoice->viewed = true; | ||||
|                 $invoice->save(); | ||||
|                 $notifyInvoiceViewed = CompanySetting::getSetting( | ||||
|                     'notify_invoice_viewed', | ||||
|                     $invoice->company_id | ||||
|                 ); | ||||
|  | ||||
|                 \Mail::to($notificationEmail)->send(new InvoiceViewedMail($data)); | ||||
|                 if ($notifyInvoiceViewed == 'YES') { | ||||
|                     $data['invoice'] = Invoice::findOrFail($invoice->id)->toArray(); | ||||
|                     $data['user'] = Customer::find($invoice->customer_id)->toArray(); | ||||
|                     $notificationEmail = CompanySetting::getSetting( | ||||
|                         'notification_email', | ||||
|                         $invoice->company_id | ||||
|                     ); | ||||
|  | ||||
|                     \Mail::to($notificationEmail)->send(new InvoiceViewedMail($data)); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if ($request->has('pdf')) { | ||||
|                 return $invoice->getGeneratedPDFOrStream('invoice'); | ||||
|             } | ||||
|  | ||||
|             return view('app')->with([ | ||||
|                 'customer_logo' => get_customer_logo($invoice->company_id), | ||||
|                 'current_theme' => get_customer_portal_theme($invoice->company_id) | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         return $invoice->getGeneratedPDFOrStream('invoice'); | ||||
|         abort(403, 'Link Expired.'); | ||||
|     } | ||||
|  | ||||
|     public function getInvoice(EmailLog $emailLog) | ||||
|     { | ||||
|         $invoice = Invoice::find($emailLog->mailable_id); | ||||
|  | ||||
|         return new CustomerInvoiceResource($invoice); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,23 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Payment; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\Customer\PaymentMethodResource; | ||||
| use Crater\Models\Company; | ||||
| use Crater\Models\PaymentMethod; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class PaymentMethodController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request, Company $company) | ||||
|     { | ||||
|         return PaymentMethodResource::collection(PaymentMethod::where('company_id', $company->id)->get()); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,61 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer\Payment; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\Customer\PaymentResource; | ||||
| use Crater\Models\Company; | ||||
| use Crater\Models\Payment; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class PaymentsController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Display a listing of the resource. | ||||
|      * | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function index(Request $request) | ||||
|     { | ||||
|         $limit = $request->has('limit') ? $request->limit : 10; | ||||
|  | ||||
|         $payments = Payment::with(['customer', 'invoice', 'paymentMethod', 'creator']) | ||||
|             ->whereCustomer(Auth::guard('customer')->id()) | ||||
|             ->leftJoin('invoices', 'invoices.id', '=', 'payments.invoice_id') | ||||
|             ->applyFilters($request->only([ | ||||
|                 'payment_number', | ||||
|                 'payment_method_id', | ||||
|                 'orderByField', | ||||
|                 'orderBy', | ||||
|             ])) | ||||
|             ->select('payments.*', 'invoices.invoice_number') | ||||
|             ->latest() | ||||
|             ->paginateData($limit); | ||||
|  | ||||
|         return (PaymentResource::collection($payments)) | ||||
|             ->additional(['meta' => [ | ||||
|                 'paymentTotalCount' => Payment::whereCustomer(Auth::guard('customer')->id())->count(), | ||||
|             ]]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Display the specified resource. | ||||
|      * | ||||
|      * @param  \Crater\Models\Payment  $payment | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function show(Company $company, $id) | ||||
|     { | ||||
|         $payment = $company->payments() | ||||
|             ->whereCustomer(Auth::guard('customer')->id()) | ||||
|             ->where('id', $id) | ||||
|             ->first(); | ||||
|  | ||||
|         if (! $payment) { | ||||
|             return response()->json(['error' => 'payment_not_found'], 404); | ||||
|         } | ||||
|  | ||||
|         return new PaymentResource($payment); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										28
									
								
								app/Http/Controllers/V1/Customer/PaymentPdfController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								app/Http/Controllers/V1/Customer/PaymentPdfController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Customer; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Http\Resources\PaymentResource; | ||||
| use Crater\Models\EmailLog; | ||||
| use Crater\Models\Payment; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class PaymentPdfController extends Controller | ||||
| { | ||||
|     public function getPdf(EmailLog $emailLog, Request $request) | ||||
|     { | ||||
|         if (! $emailLog->isExpired()) { | ||||
|             return $emailLog->mailable->getGeneratedPDFOrStream('payment'); | ||||
|         } | ||||
|  | ||||
|         abort(403, 'Link Expired.'); | ||||
|     } | ||||
|  | ||||
|     public function getPayment(EmailLog $emailLog) | ||||
|     { | ||||
|         $payment = Payment::find($emailLog->mailable_id); | ||||
|  | ||||
|         return new PaymentResource($payment); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										35
									
								
								app/Http/Controllers/V1/Modules/ScriptController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								app/Http/Controllers/V1/Modules/ScriptController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Services\Module\ModuleFacade; | ||||
| use DateTime; | ||||
| use Illuminate\Support\Arr; | ||||
| use Request; | ||||
|  | ||||
| class ScriptController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Serve the requested script. | ||||
|      * | ||||
|      * @param  \Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      * | ||||
|      * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException | ||||
|      */ | ||||
|     public function __invoke(Request $request, string $script) | ||||
|     { | ||||
|         $path = Arr::get(ModuleFacade::allScripts(), $script); | ||||
|  | ||||
|         abort_if(is_null($path), 404); | ||||
|  | ||||
|         return response( | ||||
|             file_get_contents($path), | ||||
|             200, | ||||
|             [ | ||||
|                 'Content-Type' => 'application/javascript', | ||||
|             ] | ||||
|         )->setLastModified(DateTime::createFromFormat('U', filemtime($path))); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										35
									
								
								app/Http/Controllers/V1/Modules/StyleController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								app/Http/Controllers/V1/Modules/StyleController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Modules; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Crater\Services\Module\ModuleFacade; | ||||
| use DateTime; | ||||
| use Illuminate\Support\Arr; | ||||
| use Request; | ||||
|  | ||||
| class StyleController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Serve the requested stylesheet. | ||||
|      * | ||||
|      * @param  \Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      * | ||||
|      * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException | ||||
|      */ | ||||
|     public function __invoke(Request $request, string $style) | ||||
|     { | ||||
|         $path = Arr::get(ModuleFacade::allStyles(), $style); | ||||
|  | ||||
|         abort_if(is_null($path), 404); | ||||
|  | ||||
|         return response( | ||||
|             file_get_contents($path), | ||||
|             200, | ||||
|             [ | ||||
|                 'Content-Type' => 'text/css', | ||||
|             ] | ||||
|         )->setLastModified(DateTime::createFromFormat('U', filemtime($path))); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										23
									
								
								app/Http/Controllers/V1/Webhook/CronJobController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								app/Http/Controllers/V1/Webhook/CronJobController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Controllers\V1\Webhook; | ||||
|  | ||||
| use Crater\Http\Controllers\Controller; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Artisan; | ||||
|  | ||||
| class CronJobController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Handle the incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function __invoke(Request $request) | ||||
|     { | ||||
|         Artisan::call('schedule:run'); | ||||
|  | ||||
|         return response()->json(['success' => true]); | ||||
|     } | ||||
| } | ||||
| @ -69,6 +69,9 @@ class Kernel extends HttpKernel | ||||
|         'redirect-if-unauthenticated' => \Crater\Http\Middleware\RedirectIfUnauthorized::class, | ||||
|         'customer-guest' => \Crater\Http\Middleware\CustomerGuest::class, | ||||
|         'company' => \Crater\Http\Middleware\CompanyMiddleware::class, | ||||
|         'pdf-auth' => \Crater\Http\Middleware\PdfMiddleware::class, | ||||
|         'cron-job' => \Crater\Http\Middleware\CronJobMiddleware::class, | ||||
|         'customer-portal' => \Crater\Http\Middleware\CustomerPortalMiddleware::class, | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|  | ||||
							
								
								
									
										25
									
								
								app/Http/Middleware/CronJobMiddleware.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								app/Http/Middleware/CronJobMiddleware.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Middleware; | ||||
|  | ||||
| use Closure; | ||||
| use Illuminate\Http\Request; | ||||
|  | ||||
| class CronJobMiddleware | ||||
| { | ||||
|     /** | ||||
|      * Handle an incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @param  \Closure  $next | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public function handle(Request $request, Closure $next) | ||||
|     { | ||||
|         if ($request->header('x-authorization-token') && $request->header('x-authorization-token') == config('services.cron_job.auth_token')) { | ||||
|             return $next($request); | ||||
|         } | ||||
|  | ||||
|         return response()->json(['unauthorized'], 401); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										30
									
								
								app/Http/Middleware/CustomerPortalMiddleware.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								app/Http/Middleware/CustomerPortalMiddleware.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Middleware; | ||||
|  | ||||
| use Closure; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class CustomerPortalMiddleware | ||||
| { | ||||
|     /** | ||||
|      * Handle an incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next | ||||
|      * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function handle(Request $request, Closure $next) | ||||
|     { | ||||
|         $user = Auth::guard('customer')->user(); | ||||
|  | ||||
|         if (! $user->enable_portal) { | ||||
|             Auth::guard('customer')->logout(); | ||||
|  | ||||
|             return response('Unauthorized.', 401); | ||||
|         } | ||||
|  | ||||
|         return $next($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										26
									
								
								app/Http/Middleware/PdfMiddleware.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/Http/Middleware/PdfMiddleware.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Middleware; | ||||
|  | ||||
| use Closure; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
|  | ||||
| class PdfMiddleware | ||||
| { | ||||
|     /** | ||||
|      * Handle an incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next | ||||
|      * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function handle(Request $request, Closure $next) | ||||
|     { | ||||
|         if (Auth::guard('web')->check() || Auth::guard('api')->check() || Auth::guard('customer')->check()) { | ||||
|             return $next($request); | ||||
|         } | ||||
|  | ||||
|         return redirect('/login'); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										40
									
								
								app/Http/Requests/AvatarRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								app/Http/Requests/AvatarRequest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Requests; | ||||
|  | ||||
| use Crater\Rules\Base64Mime; | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
|  | ||||
| class AvatarRequest extends FormRequest | ||||
| { | ||||
|     /** | ||||
|      * Determine if the user is authorized to make this request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize() | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the validation rules that apply to the request. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'admin_avatar' => [ | ||||
|                 'nullable', | ||||
|                 'file', | ||||
|                 'mimes:gif,jpg,png', | ||||
|                 'max:20000' | ||||
|             ], | ||||
|             'avatar' => [ | ||||
|                 'nullable', | ||||
|                 new Base64Mime(['gif', 'jpg', 'png']) | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| @ -3,6 +3,7 @@ | ||||
| namespace Crater\Http\Requests; | ||||
|  | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
| use Illuminate\Support\Str; | ||||
| use Illuminate\Validation\Rule; | ||||
|  | ||||
| class CompaniesRequest extends FormRequest | ||||
| @ -70,7 +71,8 @@ class CompaniesRequest extends FormRequest | ||||
|                 'name' | ||||
|             ]) | ||||
|             ->merge([ | ||||
|                 'owner_id' => $this->user()->id | ||||
|                 'owner_id' => $this->user()->id, | ||||
|                 'slug' => Str::slug($this->name) | ||||
|             ]) | ||||
|             ->toArray(); | ||||
|     } | ||||
|  | ||||
							
								
								
									
										34
									
								
								app/Http/Requests/CompanyLogoRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								app/Http/Requests/CompanyLogoRequest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Requests; | ||||
|  | ||||
| use Crater\Rules\Base64Mime; | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
|  | ||||
| class CompanyLogoRequest extends FormRequest | ||||
| { | ||||
|     /** | ||||
|      * Determine if the user is authorized to make this request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize() | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the validation rules that apply to the request. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'company_logo' => [ | ||||
|                 'nullable', | ||||
|                 new Base64Mime(['gif', 'jpg', 'png']) | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| @ -29,9 +29,22 @@ class CompanyRequest extends FormRequest | ||||
|                 'required', | ||||
|                 Rule::unique('companies')->ignore($this->header('company'), 'id'), | ||||
|             ], | ||||
|             'slug' => [ | ||||
|                 'nullable' | ||||
|             ], | ||||
|             'address.country_id' => [ | ||||
|                 'required', | ||||
|             ], | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     public function getCompanyPayload() | ||||
|     { | ||||
|         return collect($this->validated()) | ||||
|             ->only([ | ||||
|                 'name', | ||||
|                 'slug' | ||||
|             ]) | ||||
|             ->toArray(); | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										37
									
								
								app/Http/Requests/Customer/CustomerLoginRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								app/Http/Requests/Customer/CustomerLoginRequest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Requests\Customer; | ||||
|  | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
|  | ||||
| class CustomerLoginRequest extends FormRequest | ||||
| { | ||||
|     /** | ||||
|      * Determine if the user is authorized to make this request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize() | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the validation rules that apply to the request. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'email' => [ | ||||
|                 'required', | ||||
|                 'string' | ||||
|             ], | ||||
|             'password' => [ | ||||
|                 'required', | ||||
|                 'string' | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										116
									
								
								app/Http/Requests/Customer/CustomerProfileRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								app/Http/Requests/Customer/CustomerProfileRequest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,116 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Requests\Customer; | ||||
|  | ||||
| use Crater\Models\Address; | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
| use Illuminate\Support\Facades\Auth; | ||||
| use Illuminate\Validation\Rule; | ||||
|  | ||||
| class CustomerProfileRequest extends FormRequest | ||||
| { | ||||
|     /** | ||||
|      * Determine if the user is authorized to make this request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize() | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the validation rules that apply to the request. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'name' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'password' => [ | ||||
|                 'nullable', | ||||
|                 'min:8', | ||||
|             ], | ||||
|             'email' => [ | ||||
|                 'nullable', | ||||
|                 'email', | ||||
|                 Rule::unique('customers')->where('company_id', $this->header('company'))->ignore(Auth::id(), 'id'), | ||||
|             ], | ||||
|             'billing.name' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'billing.address_street_1' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'billing.address_street_2' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'billing.city' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'billing.state' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'billing.country_id' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'billing.zip' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'billing.phone' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'billing.fax' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.name' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.address_street_1' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.address_street_2' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.city' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.state' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.country_id' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.zip' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.phone' => [ | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'shipping.fax' => [ | ||||
|                 'nullable', | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     public function getShippingAddress() | ||||
|     { | ||||
|         return collect($this->shipping) | ||||
|             ->merge([ | ||||
|                 'type' => Address::SHIPPING_TYPE | ||||
|             ]) | ||||
|             ->toArray(); | ||||
|     } | ||||
|  | ||||
|     public function getBillingAddress() | ||||
|     { | ||||
|         return collect($this->billing) | ||||
|             ->merge([ | ||||
|                 'type' => Address::BILLING_TYPE | ||||
|             ]) | ||||
|             ->toArray(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										33
									
								
								app/Http/Requests/CustomerEstimateStatusRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								app/Http/Requests/CustomerEstimateStatusRequest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Requests; | ||||
|  | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
|  | ||||
| class CustomerEstimateStatusRequest extends FormRequest | ||||
| { | ||||
|     /** | ||||
|      * Determine if the user is authorized to make this request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize() | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the validation rules that apply to the request. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'status' => [ | ||||
|                 'required', | ||||
|                 'in:ACCEPTED,REJECTED', | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| @ -54,7 +54,8 @@ class CustomerRequest extends FormRequest | ||||
|                 'nullable', | ||||
|             ], | ||||
|             'enable_portal' => [ | ||||
|                 'nullable', | ||||
|  | ||||
|                 'boolean' | ||||
|             ], | ||||
|             'currency_id' => [ | ||||
|                 'nullable', | ||||
| @ -119,7 +120,7 @@ class CustomerRequest extends FormRequest | ||||
|             $rules['email'] = [ | ||||
|                 'email', | ||||
|                 'nullable', | ||||
|                 Rule::unique('customers')->ignore($this->route('customer')->id), | ||||
|                 Rule::unique('customers')->where('company_id', $this->header('company'))->ignore($this->route('customer')->id), | ||||
|             ]; | ||||
|         }; | ||||
|  | ||||
|  | ||||
| @ -51,6 +51,12 @@ class ExpenseRequest extends FormRequest | ||||
|             'currency_id' => [ | ||||
|                 'required' | ||||
|             ], | ||||
|             'attachment_receipt' => [ | ||||
|                 'nullable', | ||||
|                 'file', | ||||
|                 'mimes:jpg,png,pdf,doc,docx,xls,xlsx,ppt,pptx', | ||||
|                 'max:20000' | ||||
|             ] | ||||
|         ]; | ||||
|  | ||||
|         if ($companyCurrency && $this->currency_id) { | ||||
|  | ||||
							
								
								
									
										33
									
								
								app/Http/Requests/GetSettingRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								app/Http/Requests/GetSettingRequest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Requests; | ||||
|  | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
|  | ||||
| class GetSettingRequest extends FormRequest | ||||
| { | ||||
|     /** | ||||
|      * Determine if the user is authorized to make this request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize() | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the validation rules that apply to the request. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'key' => [ | ||||
|                 'required', | ||||
|                 'string' | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| @ -2,6 +2,7 @@ | ||||
|  | ||||
| namespace Crater\Http\Requests; | ||||
|  | ||||
| use Crater\Models\PaymentMethod; | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
| use Illuminate\Validation\Rule; | ||||
|  | ||||
| @ -43,4 +44,14 @@ class PaymentMethodRequest extends FormRequest | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     public function getPaymentMethodPayload() | ||||
|     { | ||||
|         return collect($this->validated()) | ||||
|             ->merge([ | ||||
|                 'company_id' => $this->header('company'), | ||||
|                 'type' => PaymentMethod::TYPE_GENERAL, | ||||
|             ]) | ||||
|             ->toArray(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -24,10 +24,7 @@ class SettingRequest extends FormRequest | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'key' => [ | ||||
|                 'required', | ||||
|             ], | ||||
|             'value' => [ | ||||
|             'settings' => [ | ||||
|                 'required', | ||||
|             ], | ||||
|         ]; | ||||
|  | ||||
| @ -2,6 +2,7 @@ | ||||
|  | ||||
| namespace Crater\Http\Requests; | ||||
|  | ||||
| use Crater\Models\TaxType; | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
| use Illuminate\Validation\Rule; | ||||
|  | ||||
| @ -28,6 +29,7 @@ class TaxTypeRequest extends FormRequest | ||||
|             'name' => [ | ||||
|                 'required', | ||||
|                 Rule::unique('tax_types') | ||||
|                 ->where('type', TaxType::TYPE_GENERAL) | ||||
|                 ->where('company_id', $this->header('company')) | ||||
|             ], | ||||
|             'percent' => [ | ||||
| @ -49,6 +51,7 @@ class TaxTypeRequest extends FormRequest | ||||
|                 'required', | ||||
|                 Rule::unique('tax_types') | ||||
|                     ->ignore($this->route('tax_type')->id) | ||||
|                     ->where('type', TaxType::TYPE_GENERAL) | ||||
|                     ->where('company_id', $this->header('company')) | ||||
|             ]; | ||||
|         } | ||||
| @ -60,7 +63,8 @@ class TaxTypeRequest extends FormRequest | ||||
|     { | ||||
|         return collect($this->validated()) | ||||
|             ->merge([ | ||||
|                 'company_id' => $this->header('company') | ||||
|                 'company_id' => $this->header('company'), | ||||
|                 'type' => TaxType::TYPE_GENERAL | ||||
|             ]) | ||||
|             ->toArray(); | ||||
|     } | ||||
|  | ||||
| @ -21,6 +21,7 @@ class CompanyResource extends JsonResource | ||||
|             'logo_path' => $this->logo_path, | ||||
|             'unique_hash' => $this->unique_hash, | ||||
|             'owner_id' => $this->owner_id, | ||||
|             'slug' => $this->slug, | ||||
|             'address' => $this->when($this->address()->exists(), function () { | ||||
|                 return new AddressResource($this->address); | ||||
|             }), | ||||
|  | ||||
| @ -2,6 +2,7 @@ | ||||
|  | ||||
| namespace Crater\Http\Resources; | ||||
|  | ||||
| use Crater\Models\CompanySetting; | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class CustomFieldValueResource extends JsonResource | ||||
| @ -28,6 +29,7 @@ class CustomFieldValueResource extends JsonResource | ||||
|             'custom_field_id' => $this->custom_field_id, | ||||
|             'company_id' => $this->company_id, | ||||
|             'default_answer' => $this->defaultAnswer, | ||||
|             'default_formatted_answer' => $this->dateTimeFormat(), | ||||
|             'custom_field' => $this->when($this->customField()->exists(), function () { | ||||
|                 return new CustomFieldResource($this->customField); | ||||
|             }), | ||||
| @ -36,4 +38,24 @@ class CustomFieldValueResource extends JsonResource | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     public function dateTimeFormat() | ||||
|     { | ||||
|         $key = getCustomFieldValueKey($this->type); | ||||
|  | ||||
|         $answer = $this->default_answer; | ||||
|         if (! $answer) { | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         if ($key == 'date_time_answer') { | ||||
|             return $answer->format('Y-m-d H:i'); | ||||
|         } | ||||
|  | ||||
|         if ($key == 'date_answer') { | ||||
|             return $answer->format(CompanySetting::getSetting('carbon_date_format', $this->company_id)); | ||||
|         } | ||||
|  | ||||
|         return $answer; | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/AddressCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/AddressCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class AddressCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										40
									
								
								app/Http/Resources/Customer/AddressResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								app/Http/Resources/Customer/AddressResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class AddressResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'address_street_1' => $this->address_street_1, | ||||
|             'address_street_2' => $this->address_street_2, | ||||
|             'city' => $this->city, | ||||
|             'state' => $this->state, | ||||
|             'country_id' => $this->country_id, | ||||
|             'zip' => $this->zip, | ||||
|             'phone' => $this->phone, | ||||
|             'fax' => $this->fax, | ||||
|             'type' => $this->type, | ||||
|             'user_id' => $this->user_id, | ||||
|             'company_id' => $this->company_id, | ||||
|             'customer_id' => $this->customer_id, | ||||
|             'country' => $this->when($this->country()->exists(), function () { | ||||
|                 return new CountryResource($this->country); | ||||
|             }), | ||||
|             'user' => $this->when($this->user()->exists(), function () { | ||||
|                 return new UserResource($this->user); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										30
									
								
								app/Http/Resources/Customer/CompanyResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								app/Http/Resources/Customer/CompanyResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class CompanyResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'slug' => $this->slug, | ||||
|             'logo' => $this->logo, | ||||
|             'logo_path' => $this->logo_path, | ||||
|             'unique_hash' => $this->unique_hash, | ||||
|             'owner_id' => $this->owner_id, | ||||
|             'address' => $this->when($this->address()->exists(), function () { | ||||
|                 return new AddressResource($this->address); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/CountryCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/CountryCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class CountryCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										24
									
								
								app/Http/Resources/Customer/CountryResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								app/Http/Resources/Customer/CountryResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class CountryResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'code' => $this->code, | ||||
|             'name' => $this->name, | ||||
|             'phonecode' => $this->phonecode, | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/CurrencyCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/CurrencyCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class CurrencyCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										29
									
								
								app/Http/Resources/Customer/CurrencyResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/Http/Resources/Customer/CurrencyResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class CurrencyResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'code' => $this->code, | ||||
|             'symbol' => $this->symbol, | ||||
|             'precision' => $this->precision, | ||||
|             'thousand_separator' => $this->thousand_separator, | ||||
|             'decimal_separator' => $this->decimal_separator, | ||||
|             'swap_currency_symbol' => $this->swap_currency_symbol, | ||||
|             'exchange_rate' => $this->exchange_rate | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/CustomFieldCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/CustomFieldCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class CustomFieldCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										42
									
								
								app/Http/Resources/Customer/CustomFieldResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								app/Http/Resources/Customer/CustomFieldResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class CustomFieldResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'slug' => $this->slug, | ||||
|             'label' => $this->label, | ||||
|             'model_type' => $this->model_type, | ||||
|             'type' => $this->type, | ||||
|             'placeholder' => $this->placeholder, | ||||
|             'options' => $this->options, | ||||
|             'boolean_answer' => $this->boolean_answer, | ||||
|             'date_answer' => $this->date_answer, | ||||
|             'time_answer' => $this->time_answer, | ||||
|             'string_answer' => $this->string_answer, | ||||
|             'number_answer' => $this->number_answer, | ||||
|             'date_time_answer' => $this->date_time_answer, | ||||
|             'is_required' => $this->is_required, | ||||
|             'in_use' => $this->in_use, | ||||
|             'order' => $this->order, | ||||
|             'company_id' => $this->company_id, | ||||
|             'default_answer' => $this->default_answer, | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/CustomFieldValueCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/CustomFieldValueCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class CustomFieldValueCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										39
									
								
								app/Http/Resources/Customer/CustomFieldValueResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								app/Http/Resources/Customer/CustomFieldValueResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class CustomFieldValueResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'custom_field_valuable_type' => $this->custom_field_valuable_type, | ||||
|             'custom_field_valuable_id' => $this->custom_field_valuable_id, | ||||
|             'type' => $this->type, | ||||
|             'boolean_answer' => $this->boolean_answer, | ||||
|             'date_answer' => $this->date_answer, | ||||
|             'time_answer' => $this->time_answer, | ||||
|             'string_answer' => $this->string_answer, | ||||
|             'number_answer' => $this->number_answer, | ||||
|             'date_time_answer' => $this->date_time_answer, | ||||
|             'custom_field_id' => $this->custom_field_id, | ||||
|             'company_id' => $this->company_id, | ||||
|             'default_answer' => $this->defaultAnswer, | ||||
|             'custom_field' => $this->when($this->customField()->exists(), function () { | ||||
|                 return new CustomFieldResource($this->customField); | ||||
|             }), | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/CustomerCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/CustomerCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class CustomerCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										51
									
								
								app/Http/Resources/Customer/CustomerResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								app/Http/Resources/Customer/CustomerResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class CustomerResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'email' => $this->email, | ||||
|             'phone' => $this->phone, | ||||
|             'contact_name' => $this->contact_name, | ||||
|             'company_name' => $this->company_name, | ||||
|             'website' => $this->website, | ||||
|             'enable_portal' => $this->enable_portal, | ||||
|             'currency_id' => $this->currency_id, | ||||
|             'company_id' => $this->company_id, | ||||
|             'facebook_id' => $this->facebook_id, | ||||
|             'google_id' => $this->google_id, | ||||
|             'github_id' => $this->github_id, | ||||
|             'formatted_created_at' => $this->formattedCreatedAt, | ||||
|             'avatar' => $this->avatar, | ||||
|             'prefix' => $this->prefix, | ||||
|             'billing' => $this->when($this->billingAddress()->exists(), function () { | ||||
|                 return new AddressResource($this->billingAddress); | ||||
|             }), | ||||
|             'shipping' => $this->when($this->shippingAddress()->exists(), function () { | ||||
|                 return new AddressResource($this->shippingAddress); | ||||
|             }), | ||||
|             'fields' => $this->when($this->fields()->exists(), function () { | ||||
|                 return CustomFieldValueResource::collection($this->fields); | ||||
|             }), | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|             'currency' => $this->when($this->currency()->exists(), function () { | ||||
|                 return new CurrencyResource($this->currency); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/EstimateCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/EstimateCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class EstimateCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/EstimateItemCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/EstimateItemCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class EstimateItemCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										45
									
								
								app/Http/Resources/Customer/EstimateItemResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								app/Http/Resources/Customer/EstimateItemResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class EstimateItemResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'description' => $this->description, | ||||
|             'discount_type' => $this->discount_type, | ||||
|             'quantity' => $this->quantity, | ||||
|             'unit_name' => $this->unit_name, | ||||
|             'discount' => $this->discount, | ||||
|             'discount_val' => $this->discount_val, | ||||
|             'price' => $this->price, | ||||
|             'tax' => $this->tax, | ||||
|             'total' => $this->total, | ||||
|             'item_id' => $this->item_id, | ||||
|             'estimate_id' => $this->estimate_id, | ||||
|             'company_id' => $this->company_id, | ||||
|             'exchange_rate' => $this->exchange_rate, | ||||
|             'base_discount_val' => $this->base_discount_val, | ||||
|             'base_price' => $this->base_price, | ||||
|             'base_tax' => $this->base_tax, | ||||
|             'base_total' => $this->base_total, | ||||
|             'taxes' => $this->when($this->taxes()->exists(), function () { | ||||
|                 return TaxResource::collection($this->taxes); | ||||
|             }), | ||||
|             'fields' => $this->when($this->fields()->exists(), function () { | ||||
|                 return CustomFieldValueResource::collection($this->fields); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										65
									
								
								app/Http/Resources/Customer/EstimateResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								app/Http/Resources/Customer/EstimateResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,65 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class EstimateResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'estimate_date' => $this->estimate_date, | ||||
|             'expiry_date' => $this->expiry_date, | ||||
|             'estimate_number' => $this->estimate_number, | ||||
|             'status' => $this->status, | ||||
|             'reference_number' => $this->reference_number, | ||||
|             'tax_per_item' => $this->tax_per_item, | ||||
|             'discount_per_item' => $this->discount_per_item, | ||||
|             'notes' => $this->notes, | ||||
|             'discount' => $this->discount, | ||||
|             'discount_type' => $this->discount_type, | ||||
|             'discount_val' => $this->discount_val, | ||||
|             'sub_total' => $this->sub_total, | ||||
|             'total' => $this->total, | ||||
|             'tax' => $this->tax, | ||||
|             'unique_hash' => $this->unique_hash, | ||||
|             'template_name' => $this->template_name, | ||||
|             'customer_id' => $this->customer_id, | ||||
|             'exchange_rate' => $this->exchange_rate, | ||||
|             'base_discount_val' => $this->base_discount_val, | ||||
|             'base_sub_total' => $this->base_sub_total, | ||||
|             'base_total' => $this->base_total, | ||||
|             'base_tax' => $this->base_tax, | ||||
|             'currency_id' => $this->currency_id, | ||||
|             'formatted_expiry_date' => $this->formattedExpiryDate, | ||||
|             'formatted_estimate_date' => $this->formattedEstimateDate, | ||||
|             'estimate_pdf_url' => $this->estimatePdfUrl, | ||||
|             'items' => $this->when($this->items()->exists(), function () { | ||||
|                 return EstimateItemResource::collection($this->items); | ||||
|             }), | ||||
|             'customer' => $this->when($this->customer()->exists(), function () { | ||||
|                 return new CustomerResource($this->customer); | ||||
|             }), | ||||
|             'taxes' => $this->when($this->taxes()->exists(), function () { | ||||
|                 return TaxResource::collection($this->taxes); | ||||
|             }), | ||||
|             'fields' => $this->when($this->fields()->exists(), function () { | ||||
|                 return CustomFieldValueResource::collection($this->fields); | ||||
|             }), | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|             'currency' => $this->when($this->currency()->exists(), function () { | ||||
|                 return new CurrencyResource($this->currency); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/ExpenseCategoryCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/ExpenseCategoryCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class ExpenseCategoryCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										29
									
								
								app/Http/Resources/Customer/ExpenseCategoryResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/Http/Resources/Customer/ExpenseCategoryResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class ExpenseCategoryResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'description' => $this->description, | ||||
|             'company_id' => $this->company_id, | ||||
|             'amount' => $this->amount, | ||||
|             'formatted_created_at' => $this->formattedCreatedAt, | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/ExpenseCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/ExpenseCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class ExpenseCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										54
									
								
								app/Http/Resources/Customer/ExpenseResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								app/Http/Resources/Customer/ExpenseResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class ExpenseResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'expense_date' => $this->expense_date, | ||||
|             'amount' => $this->amount, | ||||
|             'notes' => $this->notes, | ||||
|             'customer_id' => $this->customer_id, | ||||
|             'attachment_receipt_url' => $this->receipt_url, | ||||
|             'attachment_receipt' => $this->receipt, | ||||
|             'attachment_receipt_meta' => $this->receipt_meta, | ||||
|             'company_id' => $this->company_id, | ||||
|             'expense_category_id' => $this->expense_category_id, | ||||
|             'formatted_expense_date' => $this->formattedExpenseDate, | ||||
|             'formatted_created_at' => $this->formattedCreatedAt, | ||||
|             'exchange_rate' => $this->exchange_rate, | ||||
|             'currency_id' => $this->currency_id, | ||||
|             'base_amount' => $this->base_amount, | ||||
|             'payment_method_id' => $this->payment_method_id, | ||||
|             'customer' => $this->when($this->customer()->exists(), function () { | ||||
|                 return new CustomerResource($this->customer); | ||||
|             }), | ||||
|             'expense_category' => $this->when($this->category()->exists(), function () { | ||||
|                 return new ExpenseCategoryResource($this->category); | ||||
|             }), | ||||
|             'fields' => $this->when($this->fields()->exists(), function () { | ||||
|                 return CustomFieldValueResource::collection($this->fields); | ||||
|             }), | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|             'currency' => $this->when($this->currency()->exists(), function () { | ||||
|                 return new CurrencyResource($this->currency); | ||||
|             }), | ||||
|             'payment_method' => $this->when($this->paymentMethod()->exists(), function () { | ||||
|                 return new PaymentMethodResource($this->paymentMethod); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/InvoiceCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/InvoiceCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class InvoiceCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/InvoiceItemCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/InvoiceItemCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class InvoiceItemCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										46
									
								
								app/Http/Resources/Customer/InvoiceItemResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								app/Http/Resources/Customer/InvoiceItemResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,46 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class InvoiceItemResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'description' => $this->description, | ||||
|             'discount_type' => $this->discount_type, | ||||
|             'price' => $this->price, | ||||
|             'quantity' => $this->quantity, | ||||
|             'unit_name' => $this->unit_name, | ||||
|             'discount' => $this->discount, | ||||
|             'discount_val' => $this->discount_val, | ||||
|             'tax' => $this->tax, | ||||
|             'total' => $this->total, | ||||
|             'invoice_id' => $this->invoice_id, | ||||
|             'item_id' => $this->item_id, | ||||
|             'company_id' => $this->company_id, | ||||
|             'base_price' => $this->base_price, | ||||
|             'exchange_rate' => $this->exchange_rate, | ||||
|             'base_discount_val' => $this->base_discount_val, | ||||
|             'base_tax' => $this->base_tax, | ||||
|             'base_total' => $this->base_total, | ||||
|             'recurring_invoice_id' => $this->recurring_invoice_id, | ||||
|             'taxes' => $this->when($this->taxes()->exists(), function () { | ||||
|                 return TaxResource::collection($this->taxes); | ||||
|             }), | ||||
|             'fields' => $this->when($this->fields()->exists(), function () { | ||||
|                 return CustomFieldValueResource::collection($this->fields); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										73
									
								
								app/Http/Resources/Customer/InvoiceResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								app/Http/Resources/Customer/InvoiceResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,73 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class InvoiceResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'invoice_date' => $this->invoice_date, | ||||
|             'due_date' => $this->due_date, | ||||
|             'invoice_number' => $this->invoice_number, | ||||
|             'reference_number' => $this->reference_number, | ||||
|             'status' => $this->status, | ||||
|             'paid_status' => $this->paid_status, | ||||
|             'tax_per_item' => $this->tax_per_item, | ||||
|             'discount_per_item' => $this->discount_per_item, | ||||
|             'notes' => $this->notes, | ||||
|             'discount_type' => $this->discount_type, | ||||
|             'discount' => $this->discount, | ||||
|             'discount_val' => $this->discount_val, | ||||
|             'sub_total' => $this->sub_total, | ||||
|             'total' => $this->total, | ||||
|             'tax' => $this->tax, | ||||
|             'due_amount' => $this->due_amount, | ||||
|             'sent' => $this->sent, | ||||
|             'viewed' => $this->viewed, | ||||
|             'unique_hash' => $this->unique_hash, | ||||
|             'template_name' => $this->template_name, | ||||
|             'customer_id' => $this->customer_id, | ||||
|             'recurring_invoice_id' => $this->recurring_invoice_id, | ||||
|             'sequence_number' => $this->sequence_number, | ||||
|             'base_discount_val' => $this->base_discount_val, | ||||
|             'base_sub_total' => $this->base_sub_total, | ||||
|             'base_total' => $this->base_total, | ||||
|             'base_tax' => $this->base_tax, | ||||
|             'base_due_amount' => $this->base_due_amount, | ||||
|             'currency_id' => $this->currency_id, | ||||
|             'formatted_created_at' => $this->formattedCreatedAt, | ||||
|             'invoice_pdf_url' => $this->invoicePdfUrl, | ||||
|             'formatted_invoice_date' => $this->formattedInvoiceDate, | ||||
|             'formatted_due_date' => $this->formattedDueDate, | ||||
|             'payment_module_enabled' => $this->payment_module_enabled, | ||||
|             'items' => $this->when($this->items()->exists(), function () { | ||||
|                 return InvoiceItemResource::collection($this->items); | ||||
|             }), | ||||
|             'customer' => $this->when($this->customer()->exists(), function () { | ||||
|                 return new CustomerResource($this->customer); | ||||
|             }), | ||||
|             'taxes' => $this->when($this->taxes()->exists(), function () { | ||||
|                 return TaxResource::collection($this->taxes); | ||||
|             }), | ||||
|             'fields' => $this->when($this->fields()->exists(), function () { | ||||
|                 return CustomFieldValueResource::collection($this->fields); | ||||
|             }), | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|             'currency' => $this->when($this->currency()->exists(), function () { | ||||
|                 return new CurrencyResource($this->currency); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/ItemCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/ItemCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class ItemCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/PaymentCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/PaymentCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class PaymentCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/PaymentMethodCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/PaymentMethodCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class PaymentMethodCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										26
									
								
								app/Http/Resources/Customer/PaymentMethodResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/Http/Resources/Customer/PaymentMethodResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class PaymentMethodResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'name' => $this->name, | ||||
|             'company_id' => $this->company_id, | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										58
									
								
								app/Http/Resources/Customer/PaymentResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								app/Http/Resources/Customer/PaymentResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,58 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class PaymentResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'payment_number' => $this->payment_number, | ||||
|             'payment_date' => $this->payment_date, | ||||
|             'notes' => $this->notes, | ||||
|             'amount' => $this->amount, | ||||
|             'unique_hash' => $this->unique_hash, | ||||
|             'invoice_id' => $this->invoice_id, | ||||
|             'company_id' => $this->company_id, | ||||
|             'payment_method_id' => $this->payment_method_id, | ||||
|             'customer_id' => $this->customer_id, | ||||
|             'exchange_rate' => $this->exchange_rate, | ||||
|             'base_amount' => $this->base_amount, | ||||
|             'currency_id' => $this->currency_id, | ||||
|             'transaction_id' => $this->transaction_id, | ||||
|             'formatted_created_at' => $this->formattedCreatedAt, | ||||
|             'formatted_payment_date' => $this->formattedPaymentDate, | ||||
|             'payment_pdf_url' => $this->paymentPdfUrl, | ||||
|             'customer' => $this->when($this->customer()->exists(), function () { | ||||
|                 return new CustomerResource($this->customer); | ||||
|             }), | ||||
|             'invoice' => $this->when($this->invoice()->exists(), function () { | ||||
|                 return new InvoiceResource($this->invoice); | ||||
|             }), | ||||
|             'payment_method' => $this->when($this->paymentMethod()->exists(), function () { | ||||
|                 return new PaymentMethodResource($this->paymentMethod); | ||||
|             }), | ||||
|             'fields' => $this->when($this->fields()->exists(), function () { | ||||
|                 return CustomFieldValueResource::collection($this->fields); | ||||
|             }), | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|             'currency' => $this->when($this->currency()->exists(), function () { | ||||
|                 return new CurrencyResource($this->currency); | ||||
|             }), | ||||
|             'transaction' => $this->when($this->transaction()->exists(), function () { | ||||
|                 return new TransactionResource($this->transaction); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/Http/Resources/Customer/RecurringInvoiceCollection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Http/Resources/Customer/RecurringInvoiceCollection.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||||
|  | ||||
| class RecurringInvoiceCollection extends ResourceCollection | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource collection into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return parent::toArray($request); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										68
									
								
								app/Http/Resources/Customer/RecurringInvoiceResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								app/Http/Resources/Customer/RecurringInvoiceResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,68 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Http\Resources\Customer; | ||||
|  | ||||
| use Illuminate\Http\Resources\Json\JsonResource; | ||||
|  | ||||
| class RecurringInvoiceResource extends JsonResource | ||||
| { | ||||
|     /** | ||||
|      * Transform the resource into an array. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request  $request | ||||
|      * @return array | ||||
|      */ | ||||
|     public function toArray($request) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $this->id, | ||||
|             'starts_at' => $this->starts_at, | ||||
|             'formatted_starts_at' => $this->formattedStartsAt, | ||||
|             'formatted_created_at' => $this->formattedCreatedAt, | ||||
|             'formatted_next_invoice_at' => $this->formattedNextInvoiceAt, | ||||
|             'formatted_limit_date' => $this->formattedLimitDate, | ||||
|             'send_automatically' => $this->send_automatically, | ||||
|             'customer_id' => $this->customer_id, | ||||
|             'company_id' => $this->company_id, | ||||
|             'status' => $this->status, | ||||
|             'next_invoice_at' => $this->next_invoice_at, | ||||
|             'frequency' => $this->frequency, | ||||
|             'limit_by' => $this->limit_by, | ||||
|             'limit_count' => $this->limit_count, | ||||
|             'limit_date' => $this->limit_date, | ||||
|             'exchange_rate' => $this->exchange_rate, | ||||
|             'tax_per_item' => $this->tax_per_item, | ||||
|             'discount_per_item' => $this->discount_per_item, | ||||
|             'notes' => $this->notes, | ||||
|             'discount_type' => $this->discount_type, | ||||
|             'discount' => $this->discount, | ||||
|             'discount_val' => $this->discount_val, | ||||
|             'sub_total' => $this->sub_total, | ||||
|             'total' => $this->total, | ||||
|             'tax' => $this->tax, | ||||
|             'due_amount' => $this->due_amount, | ||||
|             'template_name' => $this->template_name, | ||||
|             'fields' => $this->when($this->fields()->exists(), function () { | ||||
|                 return CustomFieldValueResource::collection($this->fields); | ||||
|             }), | ||||
|             'items' => $this->when($this->items()->exists(), function () { | ||||
|                 return InvoiceItemResource::collection($this->items); | ||||
|             }), | ||||
|             'customer' => $this->when($this->customer()->exists(), function () { | ||||
|                 return new CustomerResource($this->customer); | ||||
|             }), | ||||
|             'company' => $this->when($this->company()->exists(), function () { | ||||
|                 return new CompanyResource($this->company); | ||||
|             }), | ||||
|             'invoices' => $this->when($this->invoices()->exists(), function () { | ||||
|                 return InvoiceResource::collection($this->invoices); | ||||
|             }), | ||||
|             'taxes' => $this->when($this->taxes()->exists(), function () { | ||||
|                 return TaxResource::collection($this->taxes); | ||||
|             }), | ||||
|             'currency' => $this->when($this->currency()->exists(), function () { | ||||
|                 return new CurrencyResource($this->currency); | ||||
|             }), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user
	