mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-28 20:21:10 -04:00 
			
		
		
		
	Compare commits
	
		
			10 Commits
		
	
	
		
			dark-sideb
			...
			mail-sende
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| dea73bcdf8 | |||
| aececb8575 | |||
| 2bea727d19 | |||
| aede1f76d0 | |||
| 959aa257b4 | |||
| b4aa254b68 | |||
| c1f2af5174 | |||
| 05d5ce26fd | |||
| 393fe20010 | |||
| 57bdbd2897 | 
							
								
								
									
										9
									
								
								.github/workflows/uffizzi-build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								.github/workflows/uffizzi-build.yml
									
									
									
									
										vendored
									
									
								
							| @ -14,8 +14,6 @@ jobs: | |||||||
|     steps: |     steps: | ||||||
|       - name: Checkout git repo |       - name: Checkout git repo | ||||||
|         uses: actions/checkout@v3 |         uses: actions/checkout@v3 | ||||||
|       - name: Set up Docker Buildx |  | ||||||
|         uses: docker/setup-buildx-action@v2         |  | ||||||
|       - name: Generate UUID image name |       - name: Generate UUID image name | ||||||
|         id: uuid |         id: uuid | ||||||
|         run: echo "UUID_TAG_APP=$(uuidgen)" >> $GITHUB_ENV |         run: echo "UUID_TAG_APP=$(uuidgen)" >> $GITHUB_ENV | ||||||
| @ -33,11 +31,10 @@ jobs: | |||||||
|           tags: ${{ steps.meta.outputs.tags }} |           tags: ${{ steps.meta.outputs.tags }} | ||||||
|           labels: ${{ steps.meta.outputs.labels }} |           labels: ${{ steps.meta.outputs.labels }} | ||||||
|           file: ./uffizzi/Dockerfile |           file: ./uffizzi/Dockerfile | ||||||
|           cache-from: type=gha |  | ||||||
|           cache-to: type=gha,mode=max |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   build-nginx: |   build-nginx: | ||||||
|  |     needs:  | ||||||
|  |       - build-application | ||||||
|     name: Build and Push `nginx` |     name: Build and Push `nginx` | ||||||
|     runs-on: ubuntu-latest |     runs-on: ubuntu-latest | ||||||
|     if: ${{ github.event_name != 'pull_request' || github.event.action != 'closed' }} |     if: ${{ github.event_name != 'pull_request' || github.event.action != 'closed' }} | ||||||
| @ -65,6 +62,8 @@ jobs: | |||||||
|           tags: ${{ steps.meta.outputs.tags }} |           tags: ${{ steps.meta.outputs.tags }} | ||||||
|           labels: ${{ steps.meta.outputs.labels }} |           labels: ${{ steps.meta.outputs.labels }} | ||||||
|           file: ./uffizzi/nginx/Dockerfile |           file: ./uffizzi/nginx/Dockerfile | ||||||
|  |           build-args: | | ||||||
|  |             BASE_IMAGE=${{ needs.build-application.outputs.tags }} | ||||||
|           cache-from: type=gha |           cache-from: type=gha | ||||||
|           cache-to: type=gha,mode=max |           cache-to: type=gha,mode=max | ||||||
|  |  | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -16,4 +16,5 @@ Homestead.yaml | |||||||
| .gitkeep | .gitkeep | ||||||
| /public/docs | /public/docs | ||||||
| /.scribe | /.scribe | ||||||
| !storage/fonts/.gitkeep | !storage/fonts/.gitkeep | ||||||
|  | .DS_Store | ||||||
|  | |||||||
| @ -55,7 +55,7 @@ class CreateTemplateCommand extends Command | |||||||
|         copy(public_path("/build/img/PDF/{$type}1.png"), public_path("/build/img/PDF/{$templateName}.png")); |         copy(public_path("/build/img/PDF/{$type}1.png"), public_path("/build/img/PDF/{$templateName}.png")); | ||||||
|         copy(resource_path("/static/img/PDF/{$type}1.png"), resource_path("/static/img/PDF/{$templateName}.png")); |         copy(resource_path("/static/img/PDF/{$type}1.png"), resource_path("/static/img/PDF/{$templateName}.png")); | ||||||
|  |  | ||||||
|         $path = resource_path("app/pdf/{$type}/{$templateName}.blade.php"); |         $path = resource_path("views/app/pdf/{$type}/{$templateName}.blade.php"); | ||||||
|         $type = ucfirst($type); |         $type = ucfirst($type); | ||||||
|         $this->info("{$type} Template created successfully at ".$path); |         $this->info("{$type} Template created successfully at ".$path); | ||||||
|  |  | ||||||
|  | |||||||
| @ -103,7 +103,6 @@ class CustomerStatsController extends Controller | |||||||
|         ) |         ) | ||||||
|             ->whereCompany() |             ->whereCompany() | ||||||
|             ->whereCustomer($customer->id) |             ->whereCustomer($customer->id) | ||||||
|             ->where('status', '<>', Invoice::STATUS_DRAFT) |  | ||||||
|             ->sum('total'); |             ->sum('total'); | ||||||
|         $totalReceipts = Payment::whereBetween( |         $totalReceipts = Payment::whereBetween( | ||||||
|             'payment_date', |             'payment_date', | ||||||
|  | |||||||
| @ -104,7 +104,6 @@ class DashboardController extends Controller | |||||||
|             'invoice_date', |             'invoice_date', | ||||||
|             [$startDate->format('Y-m-d'), $start->format('Y-m-d')] |             [$startDate->format('Y-m-d'), $start->format('Y-m-d')] | ||||||
|         ) |         ) | ||||||
|             ->where('status', '<>', Invoice::STATUS_DRAFT) |  | ||||||
|             ->whereCompany() |             ->whereCompany() | ||||||
|             ->sum('base_total'); |             ->sum('base_total'); | ||||||
|  |  | ||||||
| @ -142,7 +141,6 @@ class DashboardController extends Controller | |||||||
|         $recent_due_invoices = Invoice::with('customer') |         $recent_due_invoices = Invoice::with('customer') | ||||||
|             ->whereCompany() |             ->whereCompany() | ||||||
|             ->where('base_due_amount', '>', 0) |             ->where('base_due_amount', '>', 0) | ||||||
|             ->where('status', '<>', Invoice::STATUS_DRAFT) |  | ||||||
|             ->take(5) |             ->take(5) | ||||||
|             ->latest() |             ->latest() | ||||||
|             ->get(); |             ->get(); | ||||||
|  | |||||||
| @ -24,7 +24,6 @@ class InvoicesController extends Controller | |||||||
|         $limit = $request->has('limit') ? $request->limit : 10; |         $limit = $request->has('limit') ? $request->limit : 10; | ||||||
|  |  | ||||||
|         $invoices = Invoice::whereCompany() |         $invoices = Invoice::whereCompany() | ||||||
|             ->whereTabFilters($request->tab_status) |  | ||||||
|             ->join('customers', 'customers.id', '=', 'invoices.customer_id') |             ->join('customers', 'customers.id', '=', 'invoices.customer_id') | ||||||
|             ->applyFilters($request->all()) |             ->applyFilters($request->all()) | ||||||
|             ->select('invoices.*', 'customers.name') |             ->select('invoices.*', 'customers.name') | ||||||
|  | |||||||
| @ -0,0 +1,24 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace Crater\Http\Controllers\V1\Admin\MailSender; | ||||||
|  |  | ||||||
|  | use Crater\Http\Controllers\Controller; | ||||||
|  | use Crater\Http\Resources\MailSenderResource; | ||||||
|  | use Crater\Models\MailSender; | ||||||
|  | use Illuminate\Http\Request; | ||||||
|  |  | ||||||
|  | class GetAllMailSendersController extends Controller | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Handle the incoming request. | ||||||
|  |      * | ||||||
|  |      * @param  \Illuminate\Http\Request  $request | ||||||
|  |      * @return \Illuminate\Http\Response | ||||||
|  |      */ | ||||||
|  |     public function __invoke(Request $request) | ||||||
|  |     { | ||||||
|  |         $mailSenders = MailSender::whereCompany()->get(); | ||||||
|  |  | ||||||
|  |         return MailSenderResource::collection($mailSenders); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,98 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace Crater\Http\Controllers\V1\Admin\MailSender; | ||||||
|  |  | ||||||
|  | use Crater\Http\Controllers\Controller; | ||||||
|  | use Crater\Http\Requests\MailSenderRequest; | ||||||
|  | use Crater\Http\Resources\MailSenderResource; | ||||||
|  | use Crater\Models\MailSender; | ||||||
|  | use Illuminate\Http\Request; | ||||||
|  |  | ||||||
|  | class MailSenderController extends Controller | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Display a listing of the resource. | ||||||
|  |      * | ||||||
|  |      * @return \Illuminate\Http\Response | ||||||
|  |      */ | ||||||
|  |     public function index(Request $request) | ||||||
|  |     { | ||||||
|  |         $this->authorize('viewAny', MailSender::class); | ||||||
|  |  | ||||||
|  |         $limit = $request->has('limit') ? $request->limit : 10; | ||||||
|  |  | ||||||
|  |         $mailSenders = MailSender::whereCompany() | ||||||
|  |             ->applyFilters($request->all()) | ||||||
|  |             ->paginateData($limit); | ||||||
|  |  | ||||||
|  |         return (MailSenderResource::collection($mailSenders)) | ||||||
|  |             ->additional(['meta' => [ | ||||||
|  |                 'mail_sender_total_count' => MailSender::whereCompany()->count(), | ||||||
|  |             ]]); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |      /** | ||||||
|  |      * Store a newly created resource in storage. | ||||||
|  |      * | ||||||
|  |      * @param  \Illuminate\Http\Request  $request | ||||||
|  |      * @return \Illuminate\Http\Response | ||||||
|  |      */ | ||||||
|  |     public function store(MailSenderRequest $request) | ||||||
|  |     { | ||||||
|  |         $this->authorize('create', MailSender::class); | ||||||
|  |  | ||||||
|  |         $mailSender = MailSender::createFromRequest($request); | ||||||
|  |  | ||||||
|  |         return new MailSenderResource($mailSender); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Display the specified resource. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\SenderMail  $senderMail | ||||||
|  |      * @return \Illuminate\Http\Response | ||||||
|  |      */ | ||||||
|  |     public function show(MailSender $mailSender) | ||||||
|  |     { | ||||||
|  |         $this->authorize('view', $mailSender); | ||||||
|  |  | ||||||
|  |         return new MailSenderResource($mailSender); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Update the specified resource in storage. | ||||||
|  |      * | ||||||
|  |      * @param  \Illuminate\Http\Request  $request | ||||||
|  |      * @param  \Crater\Models\SenderMail  $senderMail | ||||||
|  |      * @return \Illuminate\Http\Response | ||||||
|  |      */ | ||||||
|  |     public function update(MailSenderRequest $request, MailSender $mailSender) | ||||||
|  |     { | ||||||
|  |         $this->authorize('update', $mailSender); | ||||||
|  |  | ||||||
|  |         $mailSender->updateFromRequest($request); | ||||||
|  |  | ||||||
|  |         return new MailSenderResource($mailSender); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Remove the specified resource from storage. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\SenderMail  $senderMail | ||||||
|  |      * @return \Illuminate\Http\Response | ||||||
|  |      */ | ||||||
|  |     public function destroy(MailSender $mailSender) | ||||||
|  |     { | ||||||
|  |         $this->authorize('delete', $mailSender); | ||||||
|  |  | ||||||
|  |         if ($mailSender->is_default) { | ||||||
|  |            return respondJson('You can\'t remove default mail sender.', 'You can\'t remove default mail sender.'); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $mailSender->delete(); | ||||||
|  |  | ||||||
|  |         return response()->json([ | ||||||
|  |             'success' => true, | ||||||
|  |         ]); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -3,80 +3,29 @@ | |||||||
| namespace Crater\Http\Controllers\V1\Admin\Settings; | namespace Crater\Http\Controllers\V1\Admin\Settings; | ||||||
|  |  | ||||||
| use Crater\Http\Controllers\Controller; | use Crater\Http\Controllers\Controller; | ||||||
| use Crater\Http\Requests\MailEnvironmentRequest; | use Crater\Http\Requests\TestMailDriverRequest; | ||||||
| use Crater\Mail\TestMail; | use Crater\Mail\TestMail; | ||||||
| use Crater\Models\Setting; | use Crater\Models\MailSender; | ||||||
| use Crater\Space\EnvironmentManager; |  | ||||||
| use Illuminate\Http\JsonResponse; |  | ||||||
| use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||||
| use Mail; | use Mail; | ||||||
|  |  | ||||||
| class MailConfigurationController extends Controller | class MailConfigurationController extends Controller | ||||||
| { | { | ||||||
|     /** |     public function TestMailDriver(TestMailDriverRequest $request) | ||||||
|      * @var EnvironmentManager |  | ||||||
|      */ |  | ||||||
|     protected $environmentManager; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param EnvironmentManager $environmentManager |  | ||||||
|      */ |  | ||||||
|     public function __construct(EnvironmentManager $environmentManager) |  | ||||||
|     { |  | ||||||
|         $this->environmentManager = $environmentManager; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * |  | ||||||
|      * @param MailEnvironmentRequest $request |  | ||||||
|      * @return JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function saveMailEnvironment(MailEnvironmentRequest $request) |  | ||||||
|     { |     { | ||||||
|         $this->authorize('manage email config'); |         $this->authorize('manage email config'); | ||||||
|  |  | ||||||
|         $setting = Setting::getSetting('profile_complete'); |         MailSender::setMailConfiguration($request->mail_sender_id); | ||||||
|         $results = $this->environmentManager->saveMailVariables($request); |  | ||||||
|  |  | ||||||
|         if ($setting !== 'COMPLETED') { |         Mail::to($request->to)->send(new TestMail($request->subject, $request->message)); | ||||||
|             Setting::setSetting('profile_complete', 4); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return response()->json($results); |         return response()->json([ | ||||||
|  |             'success' => true, | ||||||
|  |         ]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public function getMailEnvironment() |     public function getMailDrivers(Request $request) | ||||||
|     { |     { | ||||||
|         $this->authorize('manage email config'); |  | ||||||
|  |  | ||||||
|         $MailData = [ |  | ||||||
|             'mail_driver' => config('mail.driver'), |  | ||||||
|             'mail_host' => config('mail.host'), |  | ||||||
|             'mail_port' => config('mail.port'), |  | ||||||
|             'mail_username' => config('mail.username'), |  | ||||||
|             'mail_password' => config('mail.password'), |  | ||||||
|             'mail_encryption' => config('mail.encryption'), |  | ||||||
|             'from_name' => config('mail.from.name'), |  | ||||||
|             'from_mail' => config('mail.from.address'), |  | ||||||
|             'mail_mailgun_endpoint' => config('services.mailgun.endpoint'), |  | ||||||
|             'mail_mailgun_domain' => config('services.mailgun.domain'), |  | ||||||
|             'mail_mailgun_secret' => config('services.mailgun.secret'), |  | ||||||
|             'mail_ses_key' => config('services.ses.key'), |  | ||||||
|             'mail_ses_secret' => config('services.ses.secret'), |  | ||||||
|         ]; |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         return response()->json($MailData); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * |  | ||||||
|      * @return JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function getMailDrivers() |  | ||||||
|     { |  | ||||||
|         $this->authorize('manage email config'); |  | ||||||
|  |  | ||||||
|         $drivers = [ |         $drivers = [ | ||||||
|             'smtp', |             'smtp', | ||||||
|             'mail', |             'mail', | ||||||
| @ -87,21 +36,4 @@ class MailConfigurationController extends Controller | |||||||
|  |  | ||||||
|         return response()->json($drivers); |         return response()->json($drivers); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public function testEmailConfig(Request $request) |  | ||||||
|     { |  | ||||||
|         $this->authorize('manage email config'); |  | ||||||
|  |  | ||||||
|         $this->validate($request, [ |  | ||||||
|             'to' => 'required|email', |  | ||||||
|             'subject' => 'required', |  | ||||||
|             'message' => 'required', |  | ||||||
|         ]); |  | ||||||
|  |  | ||||||
|         Mail::to($request->to)->send(new TestMail($request->subject, $request->message)); |  | ||||||
|  |  | ||||||
|         return response()->json([ |  | ||||||
|             'success' => true, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ use Crater\Models\CompanySetting; | |||||||
| use Crater\Models\Customer; | use Crater\Models\Customer; | ||||||
| use Crater\Models\EmailLog; | use Crater\Models\EmailLog; | ||||||
| use Crater\Models\Estimate; | use Crater\Models\Estimate; | ||||||
|  | use Crater\Models\MailSender; | ||||||
| use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||||
|  |  | ||||||
| class EstimatePdfController extends Controller | class EstimatePdfController extends Controller | ||||||
| @ -27,14 +28,16 @@ class EstimatePdfController extends Controller | |||||||
|                 ); |                 ); | ||||||
|  |  | ||||||
|                 if ($notifyEstimateViewed == 'YES') { |                 if ($notifyEstimateViewed == 'YES') { | ||||||
|                     $data['estimate'] = Estimate::findOrFail($estimate->id)->toArray(); |                     $notificationEmail = CompanySetting::getSetting('notification_email', $estimate->company_id); | ||||||
|                     $data['user'] = Customer::find($estimate->customer_id)->toArray(); |                     $mailSender = MailSender::where('company_id', $estimate->company_id)->where('is_default', true)->first(); | ||||||
|                     $notificationEmail = CompanySetting::getSetting( |                     MailSender::setMailConfiguration($mailSender->id); | ||||||
|                         'notification_email', |  | ||||||
|                         $estimate->company_id |  | ||||||
|                     ); |  | ||||||
|  |  | ||||||
|                     \Mail::to($notificationEmail)->send(new EstimateViewedMail($data)); |                     $data['from_address'] = $mailSender->from_address; | ||||||
|  |                     $data['from_name'] = $mailSender->from_name; | ||||||
|  |                     $data['user'] = Customer::find($estimate->customer_id)->toArray(); | ||||||
|  |                     $data['estimate'] = Estimate::findOrFail($estimate->id)->toArray(); | ||||||
|  |  | ||||||
|  |                     send_mail(new EstimateViewedMail($data), $mailSender, $notificationEmail); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ use Crater\Models\CompanySetting; | |||||||
| use Crater\Models\Customer; | use Crater\Models\Customer; | ||||||
| use Crater\Models\EmailLog; | use Crater\Models\EmailLog; | ||||||
| use Crater\Models\Invoice; | use Crater\Models\Invoice; | ||||||
|  | use Crater\Models\MailSender; | ||||||
| use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||||
|  |  | ||||||
| class InvoicePdfController extends Controller | class InvoicePdfController extends Controller | ||||||
| @ -28,14 +29,16 @@ class InvoicePdfController extends Controller | |||||||
|                 ); |                 ); | ||||||
|  |  | ||||||
|                 if ($notifyInvoiceViewed == 'YES') { |                 if ($notifyInvoiceViewed == 'YES') { | ||||||
|  |                     $notificationEmail = CompanySetting::getSetting('notification_email', $invoice->company_id); | ||||||
|  |                     $mailSender = MailSender::where('company_id', $invoice->company_id)->where('is_default', true)->first(); | ||||||
|  |                     MailSender::setMailConfiguration($mailSender->id); | ||||||
|  |  | ||||||
|  |                     $data['from_address'] = $mailSender->from_address; | ||||||
|  |                     $data['from_name'] = $mailSender->from_name; | ||||||
|                     $data['invoice'] = Invoice::findOrFail($invoice->id)->toArray(); |                     $data['invoice'] = Invoice::findOrFail($invoice->id)->toArray(); | ||||||
|                     $data['user'] = Customer::find($invoice->customer_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)); |                     send_mail(new InvoiceViewedMail($data), $mailSender, $notificationEmail); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | |||||||
| @ -4,6 +4,7 @@ namespace Crater\Http\Middleware; | |||||||
|  |  | ||||||
| use Closure; | use Closure; | ||||||
| use Crater\Models\FileDisk; | use Crater\Models\FileDisk; | ||||||
|  | use Crater\Models\MailSender; | ||||||
|  |  | ||||||
| class ConfigMiddleware | class ConfigMiddleware | ||||||
| { | { | ||||||
| @ -28,6 +29,12 @@ class ConfigMiddleware | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         $default_mail_sender = MailSender::where('company_id', $request->header('company'))->where('is_default', true)->first(); | ||||||
|  |  | ||||||
|  |         if ($default_mail_sender) { | ||||||
|  |             $default_mail_sender->setMailConfiguration($default_mail_sender->id); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return $next($request); |         return $next($request); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ | |||||||
| namespace Crater\Http\Requests; | namespace Crater\Http\Requests; | ||||||
|  |  | ||||||
| use Illuminate\Foundation\Http\FormRequest; | use Illuminate\Foundation\Http\FormRequest; | ||||||
|  | use Illuminate\Support\Str; | ||||||
| use Illuminate\Validation\Rule; | use Illuminate\Validation\Rule; | ||||||
|  |  | ||||||
| class CompaniesRequest extends FormRequest | class CompaniesRequest extends FormRequest | ||||||
| @ -33,10 +34,6 @@ class CompaniesRequest extends FormRequest | |||||||
|             'currency' => [ |             'currency' => [ | ||||||
|                 'required' |                 'required' | ||||||
|             ], |             ], | ||||||
|             'slug' => [ |  | ||||||
|                 'required', |  | ||||||
|                 Rule::unique('companies') |  | ||||||
|             ], |  | ||||||
|             'address.name' => [ |             'address.name' => [ | ||||||
|                 'nullable', |                 'nullable', | ||||||
|             ], |             ], | ||||||
| @ -71,11 +68,11 @@ class CompaniesRequest extends FormRequest | |||||||
|     { |     { | ||||||
|         return collect($this->validated()) |         return collect($this->validated()) | ||||||
|             ->only([ |             ->only([ | ||||||
|                 'name', |                 'name' | ||||||
|                 'slug' |  | ||||||
|             ]) |             ]) | ||||||
|             ->merge([ |             ->merge([ | ||||||
|                 'owner_id' => $this->user()->id |                 'owner_id' => $this->user()->id, | ||||||
|  |                 'slug' => Str::slug($this->name) | ||||||
|             ]) |             ]) | ||||||
|             ->toArray(); |             ->toArray(); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -30,8 +30,7 @@ class CompanyRequest extends FormRequest | |||||||
|                 Rule::unique('companies')->ignore($this->header('company'), 'id'), |                 Rule::unique('companies')->ignore($this->header('company'), 'id'), | ||||||
|             ], |             ], | ||||||
|             'slug' => [ |             'slug' => [ | ||||||
|                 'required', |                 'nullable' | ||||||
|                 Rule::unique('companies')->ignore($this->header('company'), 'id'), |  | ||||||
|             ], |             ], | ||||||
|             'address.country_id' => [ |             'address.country_id' => [ | ||||||
|                 'required', |                 'required', | ||||||
|  | |||||||
							
								
								
									
										85
									
								
								app/Http/Requests/MailSenderRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								app/Http/Requests/MailSenderRequest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,85 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace Crater\Http\Requests; | ||||||
|  |  | ||||||
|  | use Illuminate\Validation\Rule; | ||||||
|  | use Illuminate\Foundation\Http\FormRequest; | ||||||
|  |  | ||||||
|  | class MailSenderRequest 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() | ||||||
|  |     { | ||||||
|  |         $rules = [ | ||||||
|  |             'name' => [ | ||||||
|  |                 'required', | ||||||
|  |                 Rule::unique('mail_senders') | ||||||
|  |                 ->where('company_id', $this->header('company')) | ||||||
|  |             ], | ||||||
|  |             'driver' => [ | ||||||
|  |                 'required', | ||||||
|  |             ], | ||||||
|  |             'is_default' => [ | ||||||
|  |                 'nullable' | ||||||
|  |             ], | ||||||
|  |             'bcc' => [ | ||||||
|  |                 'nullable' | ||||||
|  |             ], | ||||||
|  |             'cc' => [ | ||||||
|  |                 'nullable' | ||||||
|  |             ], | ||||||
|  |             'from_address' => [ | ||||||
|  |                 'nullable' | ||||||
|  |             ], | ||||||
|  |             'from_name' => [ | ||||||
|  |                 'nullable' | ||||||
|  |             ], | ||||||
|  |             'settings' => [ | ||||||
|  |                 'nullable' | ||||||
|  |             ], | ||||||
|  |             'settings.*' => [ | ||||||
|  |                 'nullable' | ||||||
|  |             ] | ||||||
|  |         ]; | ||||||
|  |  | ||||||
|  |         if ($this->isMethod('PUT')) { | ||||||
|  |             $rules['name'] = [ | ||||||
|  |                 'nullable', | ||||||
|  |                 Rule::unique('mail_senders') | ||||||
|  |                     ->ignore($this->route('mail_sender')->id) | ||||||
|  |                     ->where('company_id', $this->header('company')) | ||||||
|  |             ]; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $rules; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function getMailSenderPayload() | ||||||
|  |     { | ||||||
|  |         $data = $this->validated(); | ||||||
|  |  | ||||||
|  |         if ($data['settings'] && $data['settings']['encryption'] == 'none') { | ||||||
|  |             $data['settings']['encryption'] = ''; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return collect($data) | ||||||
|  |             ->merge([ | ||||||
|  |                 'company_id' => $this->header('company'), | ||||||
|  |             ]) | ||||||
|  |             ->toArray(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -30,7 +30,7 @@ class SendEstimatesRequest extends FormRequest | |||||||
|             'body' => [ |             'body' => [ | ||||||
|                 'required', |                 'required', | ||||||
|             ], |             ], | ||||||
|             'from' => [ |             'mail_sender_id' => [ | ||||||
|                 'required', |                 'required', | ||||||
|             ], |             ], | ||||||
|             'to' => [ |             'to' => [ | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ class SendInvoiceRequest extends FormRequest | |||||||
|             'subject' => [ |             'subject' => [ | ||||||
|                 'required', |                 'required', | ||||||
|             ], |             ], | ||||||
|             'from' => [ |             'mail_sender_id' => [ | ||||||
|                 'required', |                 'required', | ||||||
|             ], |             ], | ||||||
|             'to' => [ |             'to' => [ | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ class SendPaymentRequest extends FormRequest | |||||||
|             'body' => [ |             'body' => [ | ||||||
|                 'required', |                 'required', | ||||||
|             ], |             ], | ||||||
|             'from' => [ |             'mail_sender_id' => [ | ||||||
|                 'required', |                 'required', | ||||||
|             ], |             ], | ||||||
|             'to' => [ |             'to' => [ | ||||||
|  | |||||||
							
								
								
									
										39
									
								
								app/Http/Requests/TestMailDriverRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								app/Http/Requests/TestMailDriverRequest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace Crater\Http\Requests; | ||||||
|  |  | ||||||
|  | use Illuminate\Foundation\Http\FormRequest; | ||||||
|  |  | ||||||
|  | class TestMailDriverRequest 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 [ | ||||||
|  |             'to' => [ | ||||||
|  |                 'required', | ||||||
|  |                 'email' | ||||||
|  |             ], | ||||||
|  |             'subject' => [ | ||||||
|  |                 'required' | ||||||
|  |             ], | ||||||
|  |             'message' => [ | ||||||
|  |                 'required' | ||||||
|  |             ], | ||||||
|  |         ]; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -23,7 +23,7 @@ class EstimateResource extends JsonResource | |||||||
|             'reference_number' => $this->reference_number, |             'reference_number' => $this->reference_number, | ||||||
|             'tax_per_item' => $this->tax_per_item, |             'tax_per_item' => $this->tax_per_item, | ||||||
|             'discount_per_item' => $this->discount_per_item, |             'discount_per_item' => $this->discount_per_item, | ||||||
|             'notes' => $this->notes, |             'notes' => $this->getNotes(), | ||||||
|             'discount' => $this->discount, |             'discount' => $this->discount, | ||||||
|             'discount_type' => $this->discount_type, |             'discount_type' => $this->discount_type, | ||||||
|             'discount_val' => $this->discount_val, |             'discount_val' => $this->discount_val, | ||||||
|  | |||||||
							
								
								
									
										30
									
								
								app/Http/Resources/MailSenderResource.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								app/Http/Resources/MailSenderResource.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace Crater\Http\Resources; | ||||||
|  |  | ||||||
|  | use Illuminate\Http\Resources\Json\JsonResource; | ||||||
|  |  | ||||||
|  | class MailSenderResource extends JsonResource | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Transform the resource into an array. | ||||||
|  |      * | ||||||
|  |      * @param  \Illuminate\Http\Request  $request | ||||||
|  |      * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable | ||||||
|  |      */ | ||||||
|  |     public function toArray($request) | ||||||
|  |     { | ||||||
|  |         return [ | ||||||
|  |             'id' => $this->id, | ||||||
|  |             'name' => $this->name, | ||||||
|  |             'driver' => $this->driver, | ||||||
|  |             'is_default' => $this->is_default, | ||||||
|  |             'bcc' => $this->bcc, | ||||||
|  |             'cc' => $this->cc, | ||||||
|  |             'from_address' => $this->from_address, | ||||||
|  |             'from_name' => $this->from_name, | ||||||
|  |             'company_id' => $this->company_id, | ||||||
|  |             'settings' => $this->settings | ||||||
|  |         ]; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -18,7 +18,7 @@ class PaymentResource extends JsonResource | |||||||
|             'id' => $this->id, |             'id' => $this->id, | ||||||
|             'payment_number' => $this->payment_number, |             'payment_number' => $this->payment_number, | ||||||
|             'payment_date' => $this->payment_date, |             'payment_date' => $this->payment_date, | ||||||
|             'notes' => $this->notes, |             'notes' => $this->getNotes(), | ||||||
|             'amount' => $this->amount, |             'amount' => $this->amount, | ||||||
|             'unique_hash' => $this->unique_hash, |             'unique_hash' => $this->unique_hash, | ||||||
|             'invoice_id' => $this->invoice_id, |             'invoice_id' => $this->invoice_id, | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ class EstimateViewedMail extends Mailable | |||||||
|      */ |      */ | ||||||
|     public function build() |     public function build() | ||||||
|     { |     { | ||||||
|         return $this->from(config('mail.from.address'), config('mail.from.name')) |         return $this->from($this->data['from_address'], $this->data['from_name']) | ||||||
|                     ->markdown('emails.viewed.estimate', ['data', $this->data]); |                     ->markdown('emails.viewed.estimate', ['data', $this->data]); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ class InvoiceViewedMail extends Mailable | |||||||
|      */ |      */ | ||||||
|     public function build() |     public function build() | ||||||
|     { |     { | ||||||
|         return $this->from(config('mail.from.address'), config('mail.from.name')) |         return $this->from($this->data['from_address'], $this->data['from_name']) | ||||||
|                     ->markdown('emails.viewed.invoice', ['data', $this->data]); |                     ->markdown('emails.viewed.invoice', ['data', $this->data]); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ class SendEstimateMail extends Mailable | |||||||
|     public function build() |     public function build() | ||||||
|     { |     { | ||||||
|         $log = EmailLog::create([ |         $log = EmailLog::create([ | ||||||
|             'from' => $this->data['from'], |             'from' => $this->data['from_address'], | ||||||
|             'to' => $this->data['to'], |             'to' => $this->data['to'], | ||||||
|             'subject' => $this->data['subject'], |             'subject' => $this->data['subject'], | ||||||
|             'body' => $this->data['body'], |             'body' => $this->data['body'], | ||||||
| @ -47,9 +47,10 @@ class SendEstimateMail extends Mailable | |||||||
|  |  | ||||||
|         $this->data['url'] = route('estimate', ['email_log' => $log->token]); |         $this->data['url'] = route('estimate', ['email_log' => $log->token]); | ||||||
|  |  | ||||||
|         $mailContent = $this->from($this->data['from'], config('mail.from.name')) |         $mailContent = $this->from($this->data['from_address'], $this->data['from_name']) | ||||||
|                     ->subject($this->data['subject']) |             ->subject($this->data['subject']) | ||||||
|                     ->markdown('emails.send.estimate', ['data', $this->data]); |             ->markdown("emails.send.estimate", ['data', $this->data]); | ||||||
|  |  | ||||||
|  |  | ||||||
|         if ($this->data['attach']['data']) { |         if ($this->data['attach']['data']) { | ||||||
|             $mailContent->attachData( |             $mailContent->attachData( | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ class SendInvoiceMail extends Mailable | |||||||
|     public function build() |     public function build() | ||||||
|     { |     { | ||||||
|         $log = EmailLog::create([ |         $log = EmailLog::create([ | ||||||
|             'from' => $this->data['from'], |             'from' => $this->data['from_address'], | ||||||
|             'to' => $this->data['to'], |             'to' => $this->data['to'], | ||||||
|             'subject' => $this->data['subject'], |             'subject' => $this->data['subject'], | ||||||
|             'body' => $this->data['body'], |             'body' => $this->data['body'], | ||||||
| @ -47,9 +47,9 @@ class SendInvoiceMail extends Mailable | |||||||
|  |  | ||||||
|         $this->data['url'] = route('invoice', ['email_log' => $log->token]); |         $this->data['url'] = route('invoice', ['email_log' => $log->token]); | ||||||
|  |  | ||||||
|         $mailContent = $this->from($this->data['from'], config('mail.from.name')) |         $mailContent = $this->from($this->data['from_address'], $this->data['from_name']) | ||||||
|             ->subject($this->data['subject']) |             ->subject($this->data['subject']) | ||||||
|             ->markdown('emails.send.invoice', ['data', $this->data]); |             ->markdown("emails.send.invoice", ['data', $this->data]); | ||||||
|  |  | ||||||
|         if ($this->data['attach']['data']) { |         if ($this->data['attach']['data']) { | ||||||
|             $mailContent->attachData( |             $mailContent->attachData( | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ class SendPaymentMail extends Mailable | |||||||
|     public function build() |     public function build() | ||||||
|     { |     { | ||||||
|         $log = EmailLog::create([ |         $log = EmailLog::create([ | ||||||
|             'from' => $this->data['from'], |             'from' => $this->data['from_address'], | ||||||
|             'to' => $this->data['to'], |             'to' => $this->data['to'], | ||||||
|             'subject' => $this->data['subject'], |             'subject' => $this->data['subject'], | ||||||
|             'body' => $this->data['body'], |             'body' => $this->data['body'], | ||||||
| @ -47,9 +47,9 @@ class SendPaymentMail extends Mailable | |||||||
|  |  | ||||||
|         $this->data['url'] = route('payment', ['email_log' => $log->token]); |         $this->data['url'] = route('payment', ['email_log' => $log->token]); | ||||||
|  |  | ||||||
|         $mailContent = $this->from($this->data['from'], config('mail.from.name')) |         $mailContent = $this->from($this->data['from_address'], $this->data['from_name']) | ||||||
|                     ->subject($this->data['subject']) |             ->subject($this->data['subject']) | ||||||
|                     ->markdown('emails.send.payment', ['data', $this->data]); |             ->markdown("emails.send.payment", ['data', $this->data]); | ||||||
|  |  | ||||||
|         if ($this->data['attach']['data']) { |         if ($this->data['attach']['data']) { | ||||||
|             $mailContent->attachData( |             $mailContent->attachData( | ||||||
|  | |||||||
| @ -217,7 +217,7 @@ class Company extends Model implements HasMedia | |||||||
|             'estimate_billing_address_format' => $billingAddressFormat, |             'estimate_billing_address_format' => $billingAddressFormat, | ||||||
|             'payment_company_address_format' => $companyAddressFormat, |             'payment_company_address_format' => $companyAddressFormat, | ||||||
|             'payment_from_customer_address_format' => $paymentFromCustomerAddress, |             'payment_from_customer_address_format' => $paymentFromCustomerAddress, | ||||||
|             'currency' => request()->currency ?? 1, |             'currency' => request()->currency ?? 13, | ||||||
|             'time_zone' => 'Asia/Kolkata', |             'time_zone' => 'Asia/Kolkata', | ||||||
|             'language' => 'en', |             'language' => 'en', | ||||||
|             'fiscal_year' => '1-12', |             'fiscal_year' => '1-12', | ||||||
|  | |||||||
| @ -5,10 +5,10 @@ namespace Crater\Models; | |||||||
| use App; | use App; | ||||||
| use Barryvdh\DomPDF\Facade as PDF; | use Barryvdh\DomPDF\Facade as PDF; | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use Crater\Mail\SendEstimateMail; |  | ||||||
| use Crater\Services\SerialNumberFormatter; | use Crater\Services\SerialNumberFormatter; | ||||||
| use Crater\Traits\GeneratesPdfTrait; | use Crater\Traits\GeneratesPdfTrait; | ||||||
| use Crater\Traits\HasCustomFieldsTrait; | use Crater\Traits\HasCustomFieldsTrait; | ||||||
|  | use Crater\Traits\MailTrait; | ||||||
| use Illuminate\Database\Eloquent\Factories\HasFactory; | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||||||
| use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||||
| use Illuminate\Support\Facades\Storage; | use Illuminate\Support\Facades\Storage; | ||||||
| @ -20,6 +20,7 @@ use Vinkla\Hashids\Facades\Hashids; | |||||||
| class Estimate extends Model implements HasMedia | class Estimate extends Model implements HasMedia | ||||||
| { | { | ||||||
|     use HasFactory; |     use HasFactory; | ||||||
|  |     use MailTrait; | ||||||
|     use InteractsWithMedia; |     use InteractsWithMedia; | ||||||
|     use GeneratesPdfTrait; |     use GeneratesPdfTrait; | ||||||
|     use HasCustomFieldsTrait; |     use HasCustomFieldsTrait; | ||||||
| @ -363,7 +364,7 @@ class Estimate extends Model implements HasMedia | |||||||
|             $this->save(); |             $this->save(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         \Mail::to($data['to'])->send(new SendEstimateMail($data)); |         $this->setMail('estimate', $data); | ||||||
|  |  | ||||||
|         return [ |         return [ | ||||||
|             'success' => true, |             'success' => true, | ||||||
| @ -483,8 +484,7 @@ class Estimate extends Model implements HasMedia | |||||||
|             '{ESTIMATE_DATE}' => $this->formattedEstimateDate, |             '{ESTIMATE_DATE}' => $this->formattedEstimateDate, | ||||||
|             '{ESTIMATE_EXPIRY_DATE}' => $this->formattedExpiryDate, |             '{ESTIMATE_EXPIRY_DATE}' => $this->formattedExpiryDate, | ||||||
|             '{ESTIMATE_NUMBER}' => $this->estimate_number, |             '{ESTIMATE_NUMBER}' => $this->estimate_number, | ||||||
|             '{PDF_LINK}' => $this->estimatePdfUrl, |             '{ESTIMATE_REF_NUMBER}' => $this->reference_number, | ||||||
|             '{TOTAL_AMOUNT}' => format_money_pdf($this->total, $this->customer->currency) |  | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -240,7 +240,7 @@ class Expense extends Model implements HasMedia | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if ($request->hasFile('attachment_receipt')) { |         if ($request->hasFile('attachment_receipt')) { | ||||||
|             $expense->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts', 'local'); |             $expense->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts'); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if ($request->customFields) { |         if ($request->customFields) { | ||||||
| @ -262,12 +262,12 @@ class Expense extends Model implements HasMedia | |||||||
|             ExchangeRateLog::addExchangeRateLog($this); |             ExchangeRateLog::addExchangeRateLog($this); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (isset($request->is_attachment_receipt_removed) && $request->is_attachment_receipt_removed == "true") { |         if (isset($request->is_attachment_receipt_removed) && (bool) $request->is_attachment_receipt_removed) { | ||||||
|             $this->clearMediaCollection('receipts'); |             $this->clearMediaCollection('receipts'); | ||||||
|         } |         } | ||||||
|         if ($request->hasFile('attachment_receipt')) { |         if ($request->hasFile('attachment_receipt')) { | ||||||
|             $this->clearMediaCollection('receipts'); |             $this->clearMediaCollection('receipts'); | ||||||
|             $this->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts', 'local'); |             $this->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts'); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if ($request->customFields) { |         if ($request->customFields) { | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ use Crater\Mail\SendInvoiceMail; | |||||||
| use Crater\Services\SerialNumberFormatter; | use Crater\Services\SerialNumberFormatter; | ||||||
| use Crater\Traits\GeneratesPdfTrait; | use Crater\Traits\GeneratesPdfTrait; | ||||||
| use Crater\Traits\HasCustomFieldsTrait; | use Crater\Traits\HasCustomFieldsTrait; | ||||||
|  | use Crater\Traits\MailTrait; | ||||||
| use Illuminate\Database\Eloquent\Factories\HasFactory; | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||||||
| use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||||
| use Illuminate\Support\Facades\Storage; | use Illuminate\Support\Facades\Storage; | ||||||
| @ -21,6 +22,7 @@ use Vinkla\Hashids\Facades\Hashids; | |||||||
| class Invoice extends Model implements HasMedia | class Invoice extends Model implements HasMedia | ||||||
| { | { | ||||||
|     use HasFactory; |     use HasFactory; | ||||||
|  |     use MailTrait; | ||||||
|     use InteractsWithMedia; |     use InteractsWithMedia; | ||||||
|     use GeneratesPdfTrait; |     use GeneratesPdfTrait; | ||||||
|     use HasCustomFieldsTrait; |     use HasCustomFieldsTrait; | ||||||
| @ -187,6 +189,16 @@ class Invoice extends Model implements HasMedia | |||||||
|         return Carbon::parse($this->invoice_date)->format($dateFormat); |         return Carbon::parse($this->invoice_date)->format($dateFormat); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public function scopeWhereStatus($query, $status) | ||||||
|  |     { | ||||||
|  |         return $query->where('invoices.status', $status); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function scopeWherePaidStatus($query, $status) | ||||||
|  |     { | ||||||
|  |         return $query->where('invoices.paid_status', $status); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public function scopeWhereDueStatus($query, $status) |     public function scopeWhereDueStatus($query, $status) | ||||||
|     { |     { | ||||||
|         return $query->whereIn('invoices.paid_status', [ |         return $query->whereIn('invoices.paid_status', [ | ||||||
| @ -224,40 +236,6 @@ class Invoice extends Model implements HasMedia | |||||||
|         $query->orderBy($orderByField, $orderBy); |         $query->orderBy($orderByField, $orderBy); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public function scopeWhereStatus($query, $status) |  | ||||||
|     { |  | ||||||
|         return $query->where('invoices.status', $status); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public function scopeWherePaidStatus($query, $status) |  | ||||||
|     { |  | ||||||
|         return $query->where('invoices.paid_status', $status); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public function scopeWhereTabFilters($query, $status) |  | ||||||
|     { |  | ||||||
|         if ($status == "DRAFT") { |  | ||||||
|             return $query->where('invoices.status', $status); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if ($status == "SENT") { |  | ||||||
|             return $query->whereIn('invoices.status', [ |  | ||||||
|                 self::STATUS_SENT, |  | ||||||
|                 self::STATUS_VIEWED, |  | ||||||
|                 self::STATUS_COMPLETED |  | ||||||
|             ]); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if ($status == 'DUE') { |  | ||||||
|             return $query->whereIn('invoices.paid_status', [ |  | ||||||
|                 self::STATUS_UNPAID, |  | ||||||
|                 self::STATUS_PARTIALLY_PAID, |  | ||||||
|             ]); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return ; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public function scopeApplyFilters($query, array $filters) |     public function scopeApplyFilters($query, array $filters) | ||||||
|     { |     { | ||||||
|         $filters = collect($filters); |         $filters = collect($filters); | ||||||
| @ -273,11 +251,17 @@ class Invoice extends Model implements HasMedia | |||||||
|                 $filters->get('status') == self::STATUS_PAID |                 $filters->get('status') == self::STATUS_PAID | ||||||
|             ) { |             ) { | ||||||
|                 $query->wherePaidStatus($filters->get('status')); |                 $query->wherePaidStatus($filters->get('status')); | ||||||
|  |             } elseif ($filters->get('status') == 'DUE') { | ||||||
|  |                 $query->whereDueStatus($filters->get('status')); | ||||||
|             } else { |             } else { | ||||||
|                 $query->whereStatus($filters->get('status')); |                 $query->whereStatus($filters->get('status')); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if ($filters->get('paid_status')) { | ||||||
|  |             $query->wherePaidStatus($filters->get('status')); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         if ($filters->get('invoice_id')) { |         if ($filters->get('invoice_id')) { | ||||||
|             $query->whereInvoice($filters->get('invoice_id')); |             $query->whereInvoice($filters->get('invoice_id')); | ||||||
|         } |         } | ||||||
| @ -482,7 +466,7 @@ class Invoice extends Model implements HasMedia | |||||||
|     { |     { | ||||||
|         $data = $this->sendInvoiceData($data); |         $data = $this->sendInvoiceData($data); | ||||||
|  |  | ||||||
|         \Mail::to($data['to'])->send(new SendInvoiceMail($data)); |         $this->setMail('invoice', $data); | ||||||
|  |  | ||||||
|         if ($this->status == Invoice::STATUS_DRAFT) { |         if ($this->status == Invoice::STATUS_DRAFT) { | ||||||
|             $this->status = Invoice::STATUS_SENT; |             $this->status = Invoice::STATUS_SENT; | ||||||
| @ -669,9 +653,7 @@ class Invoice extends Model implements HasMedia | |||||||
|             '{INVOICE_DATE}' => $this->formattedInvoiceDate, |             '{INVOICE_DATE}' => $this->formattedInvoiceDate, | ||||||
|             '{INVOICE_DUE_DATE}' => $this->formattedDueDate, |             '{INVOICE_DUE_DATE}' => $this->formattedDueDate, | ||||||
|             '{INVOICE_NUMBER}' => $this->invoice_number, |             '{INVOICE_NUMBER}' => $this->invoice_number, | ||||||
|             '{PDF_LINK}' => $this->invoicePdfUrl, |             '{INVOICE_REF_NUMBER}' => $this->reference_number, | ||||||
|             '{DUE_AMOUNT}' => format_money_pdf($this->due_amount, $this->customer->currency), |  | ||||||
|             '{TOTAL_AMOUNT}' => format_money_pdf($this->total, $this->customer->currency) |  | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
							
								
								
									
										111
									
								
								app/Models/MailSender.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								app/Models/MailSender.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,111 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace Crater\Models; | ||||||
|  |  | ||||||
|  | use Crater\Http\Requests\MailSenderRequest; | ||||||
|  | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||||||
|  | use Illuminate\Database\Eloquent\Model; | ||||||
|  | use Config; | ||||||
|  |  | ||||||
|  | class MailSender extends Model | ||||||
|  | { | ||||||
|  |     use HasFactory; | ||||||
|  |  | ||||||
|  |     protected $guarded = [ | ||||||
|  |         'id' | ||||||
|  |     ]; | ||||||
|  |  | ||||||
|  |     protected $casts = [ | ||||||
|  |         'settings' => 'array', | ||||||
|  |         'is_default' => 'boolean' | ||||||
|  |     ]; | ||||||
|  |  | ||||||
|  |     public function company() | ||||||
|  |     { | ||||||
|  |         return $this->belongsTo(Company::class); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function scopeWhereOrder($query, $orderByField, $orderBy) | ||||||
|  |     { | ||||||
|  |         $query->orderBy($orderByField, $orderBy); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function scopeApplyFilters($query, array $filters) | ||||||
|  |     { | ||||||
|  |         $filters = collect($filters); | ||||||
|  |  | ||||||
|  |         if ($filters->get('orderByField') || $filters->get('orderBy')) { | ||||||
|  |             $field = $filters->get('orderByField') ? $filters->get('orderByField') : 'name'; | ||||||
|  |             $orderBy = $filters->get('orderBy') ? $filters->get('orderBy') : 'desc'; | ||||||
|  |             $query->whereOrder($field, $orderBy); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function scopePaginateData($query, $limit) | ||||||
|  |     { | ||||||
|  |         if ($limit == 'all') { | ||||||
|  |             return $query->get(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $query->paginate($limit); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function scopeWhereCompany($query) | ||||||
|  |     { | ||||||
|  |         $query->where('mail_senders.company_id', request()->header('company')); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static function createFromRequest(MailSenderRequest $request) | ||||||
|  |     { | ||||||
|  |         $senderMail = self::create($request->getMailSenderPayload()); | ||||||
|  |  | ||||||
|  |         if ($request->is_default) { | ||||||
|  |             $senderMail->removeOtherDefaultMailSenders($request); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $senderMail; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function updateFromRequest(MailSenderRequest $request) | ||||||
|  |     { | ||||||
|  |         $data = $request->getMailSenderPayload(); | ||||||
|  |  | ||||||
|  |         $this->update($data); | ||||||
|  |  | ||||||
|  |         if ($request->is_default) { | ||||||
|  |             $this->removeOtherDefaultMailSenders($request); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $this; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static function setMailConfiguration($id, $check = null) | ||||||
|  |     { | ||||||
|  |         $mailSender = MailSender::find($id); | ||||||
|  |  | ||||||
|  |         $settings = $mailSender->settings; | ||||||
|  |         $settings['driver'] = $mailSender->driver; | ||||||
|  |         $settings['from'] = [ | ||||||
|  |             'address' => $mailSender->from_address, | ||||||
|  |             'name' => $mailSender->from_name | ||||||
|  |         ]; | ||||||
|  |         $settings['sendmail'] = config('mail.sendmail'); | ||||||
|  |         $settings['markdown'] = config('mail.markdown'); | ||||||
|  |         $settings['log_channel'] = config('mail.log_channel'); | ||||||
|  |  | ||||||
|  |         Config::set('mail', $settings); | ||||||
|  |  | ||||||
|  |         if ($check) { | ||||||
|  |             return $mailSender; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function removeOtherDefaultMailSenders($request) { | ||||||
|  |         MailSender::where('company_id', $request->header('company')) | ||||||
|  |             ->where('is_default', true) | ||||||
|  |             ->where('id', '<>', $this->id) | ||||||
|  |             ->update(['is_default' => false]); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -5,10 +5,10 @@ namespace Crater\Models; | |||||||
| use Barryvdh\DomPDF\Facade as PDF; | use Barryvdh\DomPDF\Facade as PDF; | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use Crater\Jobs\GeneratePaymentPdfJob; | use Crater\Jobs\GeneratePaymentPdfJob; | ||||||
| use Crater\Mail\SendPaymentMail; |  | ||||||
| use Crater\Services\SerialNumberFormatter; | use Crater\Services\SerialNumberFormatter; | ||||||
| use Crater\Traits\GeneratesPdfTrait; | use Crater\Traits\GeneratesPdfTrait; | ||||||
| use Crater\Traits\HasCustomFieldsTrait; | use Crater\Traits\HasCustomFieldsTrait; | ||||||
|  | use Crater\Traits\MailTrait; | ||||||
| use Illuminate\Database\Eloquent\Factories\HasFactory; | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||||||
| use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||||
| use Spatie\MediaLibrary\HasMedia; | use Spatie\MediaLibrary\HasMedia; | ||||||
| @ -18,6 +18,7 @@ use Vinkla\Hashids\Facades\Hashids; | |||||||
| class Payment extends Model implements HasMedia | class Payment extends Model implements HasMedia | ||||||
| { | { | ||||||
|     use HasFactory; |     use HasFactory; | ||||||
|  |     use MailTrait; | ||||||
|     use InteractsWithMedia; |     use InteractsWithMedia; | ||||||
|     use GeneratesPdfTrait; |     use GeneratesPdfTrait; | ||||||
|     use HasCustomFieldsTrait; |     use HasCustomFieldsTrait; | ||||||
| @ -135,7 +136,7 @@ class Payment extends Model implements HasMedia | |||||||
|     { |     { | ||||||
|         $data = $this->sendPaymentData($data); |         $data = $this->sendPaymentData($data); | ||||||
|  |  | ||||||
|         \Mail::to($data['to'])->send(new SendPaymentMail($data)); |         $this->setMail('payment', $data); | ||||||
|  |  | ||||||
|         return [ |         return [ | ||||||
|             'success' => true, |             'success' => true, | ||||||
| @ -435,8 +436,7 @@ class Payment extends Model implements HasMedia | |||||||
|             '{PAYMENT_DATE}' => $this->formattedPaymentDate, |             '{PAYMENT_DATE}' => $this->formattedPaymentDate, | ||||||
|             '{PAYMENT_MODE}' => $this->paymentMethod ? $this->paymentMethod->name : null, |             '{PAYMENT_MODE}' => $this->paymentMethod ? $this->paymentMethod->name : null, | ||||||
|             '{PAYMENT_NUMBER}' => $this->payment_number, |             '{PAYMENT_NUMBER}' => $this->payment_number, | ||||||
|             '{PDF_LINK}' => $this->paymentPdfUrl, |             '{PAYMENT_AMOUNT}' => $this->reference_number, | ||||||
|             '{PAYMENT_AMOUNT}' => format_money_pdf($this->amount, $this->customer->currency) |  | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
							
								
								
									
										123
									
								
								app/Policies/MailSenderPolicy.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								app/Policies/MailSenderPolicy.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,123 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace Crater\Policies; | ||||||
|  |  | ||||||
|  | use Crater\Models\MailSender; | ||||||
|  | use Crater\Models\User; | ||||||
|  | use Illuminate\Auth\Access\HandlesAuthorization; | ||||||
|  | use Silber\Bouncer\BouncerFacade; | ||||||
|  |  | ||||||
|  | class MailSenderPolicy | ||||||
|  | { | ||||||
|  |     use HandlesAuthorization; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Determine whether the user can view any models. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\User  $user | ||||||
|  |      * @return \Illuminate\Auth\Access\Response|bool | ||||||
|  |      */ | ||||||
|  |     public function viewAny(User $user) | ||||||
|  |     { | ||||||
|  |         if (BouncerFacade::can('view-mail-sender', MailSender::class)) { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Determine whether the user can view the model. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\User  $user | ||||||
|  |      * @param  \Crater\Models\MailSender  $mailSender | ||||||
|  |      * @return \Illuminate\Auth\Access\Response|bool | ||||||
|  |      */ | ||||||
|  |     public function view(User $user, MailSender $mailSender) | ||||||
|  |     { | ||||||
|  |         if (BouncerFacade::can('view-mail-sender', $mailSender) && $user->hasCompany($mailSender->company_id)) { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Determine whether the user can create models. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\User  $user | ||||||
|  |      * @return \Illuminate\Auth\Access\Response|bool | ||||||
|  |      */ | ||||||
|  |     public function create(User $user) | ||||||
|  |     { | ||||||
|  |         if (BouncerFacade::can('create-mail-sender', MailSender::class)) { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Determine whether the user can update the model. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\User  $user | ||||||
|  |      * @param  \Crater\Models\MailSender  $mailSender | ||||||
|  |      * @return \Illuminate\Auth\Access\Response|bool | ||||||
|  |      */ | ||||||
|  |     public function update(User $user, MailSender $mailSender) | ||||||
|  |     { | ||||||
|  |         if (BouncerFacade::can('edit-mail-sender', $mailSender) && $user->hasCompany($mailSender->company_id)) { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Determine whether the user can delete the model. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\User  $user | ||||||
|  |      * @param  \Crater\Models\MailSender  $mailSender | ||||||
|  |      * @return \Illuminate\Auth\Access\Response|bool | ||||||
|  |      */ | ||||||
|  |     public function delete(User $user, MailSender $mailSender) | ||||||
|  |     { | ||||||
|  |         if (BouncerFacade::can('delete-mail-sender', $mailSender) && $user->hasCompany($mailSender->company_id)) { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Determine whether the user can restore the model. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\User  $user | ||||||
|  |      * @param  \Crater\Models\MailSender  $mailSender | ||||||
|  |      * @return \Illuminate\Auth\Access\Response|bool | ||||||
|  |      */ | ||||||
|  |     public function restore(User $user, MailSender $mailSender) | ||||||
|  |     { | ||||||
|  |         if (BouncerFacade::can('delete-mail-sender', $mailSender) && $user->hasCompany($mailSender->company_id)) { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Determine whether the user can permanently delete the model. | ||||||
|  |      * | ||||||
|  |      * @param  \Crater\Models\User  $user | ||||||
|  |      * @param  \Crater\Models\MailSender  $mailSender | ||||||
|  |      * @return \Illuminate\Auth\Access\Response|bool | ||||||
|  |      */ | ||||||
|  |     public function forceDelete(User $user, MailSender $mailSender) | ||||||
|  |     { | ||||||
|  |         if (BouncerFacade::can('delete-mail-sender', $mailSender) && $user->hasCompany($mailSender->company_id)) { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -39,6 +39,7 @@ class AuthServiceProvider extends ServiceProvider | |||||||
|         \Crater\Models\CustomField::class => \Crater\Policies\CustomFieldPolicy::class, |         \Crater\Models\CustomField::class => \Crater\Policies\CustomFieldPolicy::class, | ||||||
|         \Crater\Models\User::class => \Crater\Policies\UserPolicy::class, |         \Crater\Models\User::class => \Crater\Policies\UserPolicy::class, | ||||||
|         \Crater\Models\Item::class => \Crater\Policies\ItemPolicy::class, |         \Crater\Models\Item::class => \Crater\Policies\ItemPolicy::class, | ||||||
|  |         \Crater\Models\MailSender::class => \Crater\Policies\MailSenderPolicy::class, | ||||||
|         \Silber\Bouncer\Database\Role::class => \Crater\Policies\RolePolicy::class, |         \Silber\Bouncer\Database\Role::class => \Crater\Policies\RolePolicy::class, | ||||||
|         \Crater\Models\Unit::class => \Crater\Policies\UnitPolicy::class, |         \Crater\Models\Unit::class => \Crater\Policies\UnitPolicy::class, | ||||||
|         \Crater\Models\RecurringInvoice::class => \Crater\Policies\RecurringInvoicePolicy::class, |         \Crater\Models\RecurringInvoice::class => \Crater\Policies\RecurringInvoicePolicy::class, | ||||||
|  | |||||||
| @ -223,204 +223,6 @@ class EnvironmentManager | |||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|     * Save the mail content to the .env file. |  | ||||||
|     * |  | ||||||
|     * @param Request $request |  | ||||||
|     * @return array |  | ||||||
|     */ |  | ||||||
|     public function saveMailVariables(MailEnvironmentRequest $request) |  | ||||||
|     { |  | ||||||
|         $mailData = $this->getMailData($request); |  | ||||||
|  |  | ||||||
|         try { |  | ||||||
|             file_put_contents($this->envPath, str_replace( |  | ||||||
|                 $mailData['old_mail_data'], |  | ||||||
|                 $mailData['new_mail_data'], |  | ||||||
|                 file_get_contents($this->envPath) |  | ||||||
|             )); |  | ||||||
|  |  | ||||||
|             if ($mailData['extra_old_mail_data']) { |  | ||||||
|                 file_put_contents($this->envPath, str_replace( |  | ||||||
|                     $mailData['extra_old_mail_data'], |  | ||||||
|                     $mailData['extra_mail_data'], |  | ||||||
|                     file_get_contents($this->envPath) |  | ||||||
|                 )); |  | ||||||
|             } else { |  | ||||||
|                 file_put_contents( |  | ||||||
|                     $this->envPath, |  | ||||||
|                     "\n".$mailData['extra_mail_data'], |  | ||||||
|                     FILE_APPEND |  | ||||||
|                 ); |  | ||||||
|             } |  | ||||||
|         } catch (Exception $e) { |  | ||||||
|             return [ |  | ||||||
|                 'error' => 'mail_variables_save_error', |  | ||||||
|             ]; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return [ |  | ||||||
|             'success' => 'mail_variables_save_successfully', |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private function getMailData($request) |  | ||||||
|     { |  | ||||||
|         $mailFromCredential = ""; |  | ||||||
|         $extraMailData = ""; |  | ||||||
|         $extraOldMailData = ""; |  | ||||||
|         $oldMailData = ""; |  | ||||||
|         $newMailData = ""; |  | ||||||
|  |  | ||||||
|         if (env('MAIL_FROM_ADDRESS') !== null && env('MAIL_FROM_NAME') !== null) { |  | ||||||
|             $mailFromCredential = |  | ||||||
|                 'MAIL_FROM_ADDRESS='.config('mail.from.address')."\n". |  | ||||||
|                 'MAIL_FROM_NAME="'.config('mail.from.name')."\"\n\n"; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         switch ($request->mail_driver) { |  | ||||||
|             case 'smtp': |  | ||||||
|  |  | ||||||
|                 $oldMailData = |  | ||||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". |  | ||||||
|                     'MAIL_HOST='.config('mail.host')."\n". |  | ||||||
|                     'MAIL_PORT='.config('mail.port')."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". |  | ||||||
|                     $mailFromCredential; |  | ||||||
|  |  | ||||||
|                 $newMailData = |  | ||||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". |  | ||||||
|                     'MAIL_HOST='.$request->mail_host."\n". |  | ||||||
|                     'MAIL_PORT='.$request->mail_port."\n". |  | ||||||
|                     'MAIL_USERNAME='.$request->mail_username."\n". |  | ||||||
|                     'MAIL_PASSWORD='.$request->mail_password."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". |  | ||||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". |  | ||||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; |  | ||||||
|  |  | ||||||
|                 break; |  | ||||||
|  |  | ||||||
|             case 'mailgun': |  | ||||||
|                 $oldMailData = |  | ||||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". |  | ||||||
|                     'MAIL_HOST='.config('mail.host')."\n". |  | ||||||
|                     'MAIL_PORT='.config('mail.port')."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". |  | ||||||
|                     $mailFromCredential; |  | ||||||
|  |  | ||||||
|                 $newMailData = |  | ||||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". |  | ||||||
|                     'MAIL_HOST='.$request->mail_host."\n". |  | ||||||
|                     'MAIL_PORT='.$request->mail_port."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". |  | ||||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". |  | ||||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; |  | ||||||
|  |  | ||||||
|                 $extraMailData = |  | ||||||
|                     'MAILGUN_DOMAIN='.$request->mail_mailgun_domain."\n". |  | ||||||
|                     'MAILGUN_SECRET='.$request->mail_mailgun_secret."\n". |  | ||||||
|                     'MAILGUN_ENDPOINT='.$request->mail_mailgun_endpoint."\n"; |  | ||||||
|  |  | ||||||
|                 if (env('MAILGUN_DOMAIN') !== null && env('MAILGUN_SECRET') !== null && env('MAILGUN_ENDPOINT') !== null) { |  | ||||||
|                     $extraOldMailData = |  | ||||||
|                         'MAILGUN_DOMAIN='.config('services.mailgun.domain')."\n". |  | ||||||
|                         'MAILGUN_SECRET='.config('services.mailgun.secret')."\n". |  | ||||||
|                         'MAILGUN_ENDPOINT='.config('services.mailgun.endpoint')."\n"; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 break; |  | ||||||
|  |  | ||||||
|             case 'ses': |  | ||||||
|                 $oldMailData = |  | ||||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". |  | ||||||
|                     'MAIL_HOST='.config('mail.host')."\n". |  | ||||||
|                     'MAIL_PORT='.config('mail.port')."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". |  | ||||||
|                     $mailFromCredential; |  | ||||||
|  |  | ||||||
|                 $newMailData = |  | ||||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". |  | ||||||
|                     'MAIL_HOST='.$request->mail_host."\n". |  | ||||||
|                     'MAIL_PORT='.$request->mail_port."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". |  | ||||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". |  | ||||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; |  | ||||||
|  |  | ||||||
|                 $extraMailData = |  | ||||||
|                     'SES_KEY='.$request->mail_ses_key."\n". |  | ||||||
|                     'SES_SECRET='.$request->mail_ses_secret."\n"; |  | ||||||
|  |  | ||||||
|                 if (env('SES_KEY') !== null && env('SES_SECRET') !== null) { |  | ||||||
|                     $extraOldMailData = |  | ||||||
|                         'SES_KEY='.config('services.ses.key')."\n". |  | ||||||
|                         'SES_SECRET='.config('services.ses.secret')."\n"; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 break; |  | ||||||
|  |  | ||||||
|             case 'mail': |  | ||||||
|                 $oldMailData = |  | ||||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". |  | ||||||
|                     'MAIL_HOST='.config('mail.host')."\n". |  | ||||||
|                     'MAIL_PORT='.config('mail.port')."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". |  | ||||||
|                     $mailFromCredential; |  | ||||||
|  |  | ||||||
|                 $newMailData = |  | ||||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". |  | ||||||
|                     'MAIL_HOST='.config('mail.host')."\n". |  | ||||||
|                     'MAIL_PORT='.config('mail.port')."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". |  | ||||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". |  | ||||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; |  | ||||||
|  |  | ||||||
|                 break; |  | ||||||
|  |  | ||||||
|             case 'sendmail': |  | ||||||
|                 $oldMailData = |  | ||||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". |  | ||||||
|                     'MAIL_HOST='.config('mail.host')."\n". |  | ||||||
|                     'MAIL_PORT='.config('mail.port')."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". |  | ||||||
|                     $mailFromCredential; |  | ||||||
|  |  | ||||||
|                 $newMailData = |  | ||||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". |  | ||||||
|                     'MAIL_HOST='.config('mail.host')."\n". |  | ||||||
|                     'MAIL_PORT='.config('mail.port')."\n". |  | ||||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". |  | ||||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". |  | ||||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". |  | ||||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". |  | ||||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; |  | ||||||
|  |  | ||||||
|                 break; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return [ |  | ||||||
|             'old_mail_data' => $oldMailData, |  | ||||||
|             'new_mail_data' => $newMailData, |  | ||||||
|             'extra_mail_data' => $extraMailData, |  | ||||||
|             'extra_old_mail_data' => $extraOldMailData, |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Save the disk content to the .env file. |      * Save the disk content to the .env file. | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ use Crater\Models\Currency; | |||||||
| use Crater\Models\CustomField; | use Crater\Models\CustomField; | ||||||
| use Crater\Models\Setting; | use Crater\Models\Setting; | ||||||
| use Illuminate\Support\Str; | use Illuminate\Support\Str; | ||||||
|  | use Illuminate\Mail\Mailable; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Get company setting |  * Get company setting | ||||||
| @ -70,6 +71,42 @@ function set_active($path, $active = 'active') | |||||||
|     return call_user_func_array('Request::is', (array)$path) ? $active : ''; |     return call_user_func_array('Request::is', (array)$path) ? $active : ''; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Send Mail | ||||||
|  |  * | ||||||
|  |  * @param Mailable $mailable | ||||||
|  |  * @param object $mailSender | ||||||
|  |  * @return string $to | ||||||
|  |  */ | ||||||
|  | function send_mail(Mailable $mailable, object $mailSender = null, string $to) | ||||||
|  | { | ||||||
|  |     if ($mailSender->bcc && $mailSender->cc) { | ||||||
|  |         \Mail::to($to) | ||||||
|  |                 ->bcc(explode(',', $mailSender->bcc)) | ||||||
|  |                 ->cc(explode(',', $mailSender->cc)) | ||||||
|  |                 ->send($mailable); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if ($mailSender->bcc && $mailSender->cc == null) { | ||||||
|  |         \Mail::to($to) | ||||||
|  |             ->bcc(explode(',', $mailSender->bcc)) | ||||||
|  |             ->send($mailable); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if ($mailSender->bcc == null && $mailSender->cc) { | ||||||
|  |         \Mail::to($to) | ||||||
|  |             ->cc(explode(',', $mailSender->cc)) | ||||||
|  |             ->send($mailable); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if ($mailSender->bcc == null && $mailSender->cc == null) { | ||||||
|  |         \Mail::to($to) | ||||||
|  |             ->send($mailable); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @param $path |  * @param $path | ||||||
|  * @return mixed |  * @return mixed | ||||||
|  | |||||||
							
								
								
									
										40
									
								
								app/Traits/MailTrait.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								app/Traits/MailTrait.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace Crater\Traits; | ||||||
|  |  | ||||||
|  | use Crater\Mail\EstimateViewedMail; | ||||||
|  | use Crater\Mail\InvoiceViewedMail; | ||||||
|  | use Crater\Mail\SendEstimateMail; | ||||||
|  | use Crater\Mail\SendInvoiceMail; | ||||||
|  | use Crater\Mail\SendPaymentMail; | ||||||
|  | use Crater\Models\MailSender; | ||||||
|  |  | ||||||
|  | trait MailTrait | ||||||
|  | { | ||||||
|  |     public function setMail($model, $data) | ||||||
|  |     { | ||||||
|  |         $mailSender = MailSender::setMailConfiguration($data['mail_sender_id'], true); | ||||||
|  |  | ||||||
|  |         $data['from_address'] = $mailSender->from_address; | ||||||
|  |         $data['from_name'] = $mailSender->from_name; | ||||||
|  |  | ||||||
|  |         switch ($model) { | ||||||
|  |             case 'invoice': | ||||||
|  |                send_mail(new SendInvoiceMail($data), $mailSender, $data['to']); | ||||||
|  |  | ||||||
|  |                 break; | ||||||
|  |  | ||||||
|  |             case 'estimate': | ||||||
|  |                send_mail(new SendEstimateMail($data), $mailSender, $data['to']); | ||||||
|  |  | ||||||
|  |                 break; | ||||||
|  |  | ||||||
|  |             case 'payment': | ||||||
|  |                send_mail(new SendPaymentMail($data), $mailSender, $data['to']); | ||||||
|  |  | ||||||
|  |                 break; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -7,6 +7,7 @@ use Crater\Models\ExchangeRateProvider; | |||||||
| use Crater\Models\Expense; | use Crater\Models\Expense; | ||||||
| use Crater\Models\Invoice; | use Crater\Models\Invoice; | ||||||
| use Crater\Models\Item; | use Crater\Models\Item; | ||||||
|  | use Crater\Models\MailSender; | ||||||
| use Crater\Models\Note; | use Crater\Models\Note; | ||||||
| use Crater\Models\Payment; | use Crater\Models\Payment; | ||||||
| use Crater\Models\RecurringInvoice; | use Crater\Models\RecurringInvoice; | ||||||
| @ -397,6 +398,41 @@ return [ | |||||||
|             ] |             ] | ||||||
|         ], |         ], | ||||||
|  |  | ||||||
|  |         // Mail Sender | ||||||
|  |         [ | ||||||
|  |             "name" => "view mail sender", | ||||||
|  |             "ability" => "view-mail-sender", | ||||||
|  |             "model" => MailSender::class, | ||||||
|  |             'owner_only' => false, | ||||||
|  |         ], | ||||||
|  |         [ | ||||||
|  |             "name" => "create mail sender", | ||||||
|  |             "ability" => "create-mail-sender", | ||||||
|  |             "model" => MailSender::class, | ||||||
|  |             'owner_only' => false, | ||||||
|  |             "depends_on" => [ | ||||||
|  |                 'view-mail-sender', | ||||||
|  |             ] | ||||||
|  |         ], | ||||||
|  |         [ | ||||||
|  |             "name" => "edit mail sender", | ||||||
|  |             "ability" => "edit-mail-sender", | ||||||
|  |             "model" => MailSender::class, | ||||||
|  |             'owner_only' => false, | ||||||
|  |             "depends_on" => [ | ||||||
|  |                 'view-mail-sender', | ||||||
|  |             ] | ||||||
|  |         ], | ||||||
|  |         [ | ||||||
|  |             "name" => "delete mail sender", | ||||||
|  |             "ability" => "delete-mail-sender", | ||||||
|  |             "model" => MailSender::class, | ||||||
|  |             'owner_only' => false, | ||||||
|  |             "depends_on" => [ | ||||||
|  |                 'view-mail-sender', | ||||||
|  |             ] | ||||||
|  |         ], | ||||||
|  |  | ||||||
|         // Settings |         // Settings | ||||||
|         [ |         [ | ||||||
|             "name" => "view company dashboard", |             "name" => "view company dashboard", | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ use Crater\Models\ExchangeRateProvider; | |||||||
| use Crater\Models\Expense; | use Crater\Models\Expense; | ||||||
| use Crater\Models\Invoice; | use Crater\Models\Invoice; | ||||||
| use Crater\Models\Item; | use Crater\Models\Item; | ||||||
|  | use Crater\Models\MailSender; | ||||||
| use Crater\Models\Note; | use Crater\Models\Note; | ||||||
| use Crater\Models\Payment; | use Crater\Models\Payment; | ||||||
| use Crater\Models\RecurringInvoice; | use Crater\Models\RecurringInvoice; | ||||||
| @ -225,6 +226,17 @@ return [ | |||||||
|             'ability' => 'view-all-notes', |             'ability' => 'view-all-notes', | ||||||
|             'model' => Note::class |             'model' => Note::class | ||||||
|         ], |         ], | ||||||
|  |         [ | ||||||
|  |             'title' => 'settings.menu_title.mail_sender', | ||||||
|  |             'group' => '', | ||||||
|  |             'name' => 'Mail Sender', | ||||||
|  |             'link' => '/admin/settings/mail-sender', | ||||||
|  |             'icon' => 'MailIcon', | ||||||
|  |             'owner_only' => false, | ||||||
|  |             'ability' => 'view-mail-sender', | ||||||
|  |             'model' => MailSender::class | ||||||
|  |         ], | ||||||
|  |  | ||||||
|         [ |         [ | ||||||
|             'title' => 'settings.menu_title.expense_category', |             'title' => 'settings.menu_title.expense_category', | ||||||
|             'group' => '', |             'group' => '', | ||||||
| @ -235,16 +247,6 @@ return [ | |||||||
|             'ability' => 'view-expense', |             'ability' => 'view-expense', | ||||||
|             'model' => Expense::class |             'model' => Expense::class | ||||||
|         ], |         ], | ||||||
|         [ |  | ||||||
|             'title' => 'settings.mail.mail_config', |  | ||||||
|             'group' => '', |  | ||||||
|             'name' => 'Mail Configuration', |  | ||||||
|             'link' => '/admin/settings/mail-configuration', |  | ||||||
|             'icon' => 'MailIcon', |  | ||||||
|             'owner_only' => true, |  | ||||||
|             'ability' => '', |  | ||||||
|             'model' => '' |  | ||||||
|         ], |  | ||||||
|         [ |         [ | ||||||
|             'title' => 'settings.menu_title.file_disk', |             'title' => 'settings.menu_title.file_disk', | ||||||
|             'group' => '', |             'group' => '', | ||||||
| @ -275,6 +277,7 @@ return [ | |||||||
|             'ability' => '', |             'ability' => '', | ||||||
|             'model' => '' |             'model' => '' | ||||||
|         ], |         ], | ||||||
|  |  | ||||||
|     ], |     ], | ||||||
|  |  | ||||||
|     /* |     /* | ||||||
|  | |||||||
| @ -27,6 +27,7 @@ return [ | |||||||
|             'tokenizer', |             'tokenizer', | ||||||
|             'JSON', |             'JSON', | ||||||
|             'cURL', |             'cURL', | ||||||
|  |             'zip', | ||||||
|         ], |         ], | ||||||
|         'apache' => [ |         'apache' => [ | ||||||
|             'mod_rewrite', |             'mod_rewrite', | ||||||
|  | |||||||
| @ -0,0 +1,106 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | use Crater\Models\Company; | ||||||
|  | use Crater\Models\MailSender; | ||||||
|  | use Crater\Models\User; | ||||||
|  | use Illuminate\Database\Migrations\Migration; | ||||||
|  | use Illuminate\Database\Schema\Blueprint; | ||||||
|  | use Illuminate\Support\Facades\Schema; | ||||||
|  | use Silber\Bouncer\BouncerFacade; | ||||||
|  |  | ||||||
|  | class CreateMailSendersTable extends Migration | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Run the migrations. | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function up() | ||||||
|  |     { | ||||||
|  |         Schema::create('mail_senders', function (Blueprint $table) { | ||||||
|  |             $table->id(); | ||||||
|  |             $table->string('name'); | ||||||
|  |             $table->string('driver'); | ||||||
|  |             $table->boolean('is_default')->default(false); | ||||||
|  |             $table->string('bcc')->nullable(); | ||||||
|  |             $table->string('cc')->nullable(); | ||||||
|  |             $table->string('from_address')->nullable(); | ||||||
|  |             $table->string('from_name')->nullable(); | ||||||
|  |             $table->json('settings')->nullable(); | ||||||
|  |             $table->integer('company_id')->unsigned()->nullable(); | ||||||
|  |             $table->foreign('company_id')->references('id')->on('companies'); | ||||||
|  |             $table->timestamps(); | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         $users = User::where('role', 'super admin')->get(); | ||||||
|  |  | ||||||
|  |         foreach ($users as $user) { | ||||||
|  |             BouncerFacade::allow($user)->toManage(MailSender::class); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $companies = Company::all(); | ||||||
|  |  | ||||||
|  |         $companies->map(function ($company) { | ||||||
|  |             if (env('MAIL_DRIVER') == 'smtp') { | ||||||
|  |                 $settings = [ | ||||||
|  |                     'MAIL_HOST' => env('MAIL_HOST'), | ||||||
|  |                     'MAIL_PORT' => env('MAIL_PORT'), | ||||||
|  |                     'MAIL_USERNAME' => env('MAIL_USERNAME'), | ||||||
|  |                     'MAIL_PASSWORD' => env('MAIL_PASSWORD'), | ||||||
|  |                     'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION') | ||||||
|  |                 ]; | ||||||
|  |                 $this->createSender($settings, $company->id); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (env('MAIL_DRIVER') == 'mail' || env('MAIL_DRIVER') == 'sendmail') { | ||||||
|  |                 $this->createSender(null, $company->id); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (env('MAIL_DRIVER') == 'mailgun') { | ||||||
|  |                 $settings = [ | ||||||
|  |                     'MAILGUN_DOMAIN' => env('MAILGUN_DOMAIN'), | ||||||
|  |                     'MAILGUN_SECRET' => env('MAILGUN_SECRET'), | ||||||
|  |                     'MAILGUN_ENDPOINT' => env('MAILGUN_ENDPOINT'), | ||||||
|  |                 ]; | ||||||
|  |                 $this->createSender($settings, $company->id); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (env('MAIL_DRIVER') == 'ses') { | ||||||
|  |                 $settings = [ | ||||||
|  |                     'MAIL_HOST' => env('MAIL_HOST'), | ||||||
|  |                     'MAIL_PORT' => env('MAIL_PORT'), | ||||||
|  |                     'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION'), | ||||||
|  |                     'MAILGUN_DOMAIN' => env('MAILGUN_DOMAIN'), | ||||||
|  |                     'SES_KEY' => env('SES_KEY'), | ||||||
|  |                     'SES_SECRET' => env('SES_SECRET'), | ||||||
|  |                 ]; | ||||||
|  |                 $this->createSender($settings, $company->id); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function createSender($settings, $company_id) | ||||||
|  |     { | ||||||
|  |         $data = [ | ||||||
|  |             'name' => env('MAIL_DRIVER'), | ||||||
|  |             'driver' => env('MAIL_DRIVER'), | ||||||
|  |             'is_default' => true, | ||||||
|  |             'from_address' => env('MAIL_FROM_ADDRESS'), | ||||||
|  |             'from_name' => env('MAIL_FROM_NAME'), | ||||||
|  |             'settings' => $settings ?? null, | ||||||
|  |             'company_id' => $company_id | ||||||
|  |         ]; | ||||||
|  |  | ||||||
|  |         MailSender::create($data); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Reverse the migrations. | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function down() | ||||||
|  |     { | ||||||
|  |         Schema::dropIfExists('mail_senders'); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -27,7 +27,7 @@ | |||||||
|     "vite": "^2.6.1" |     "vite": "^2.6.1" | ||||||
|   }, |   }, | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "@headlessui/vue": "^1.5.0", |     "@headlessui/vue": "^1.4.0", | ||||||
|     "@heroicons/vue": "^1.0.1", |     "@heroicons/vue": "^1.0.1", | ||||||
|     "@popperjs/core": "^2.9.2", |     "@popperjs/core": "^2.9.2", | ||||||
|     "@stripe/stripe-js": "^1.21.2", |     "@stripe/stripe-js": "^1.21.2", | ||||||
| @ -48,8 +48,7 @@ | |||||||
|     "mini-svg-data-uri": "^1.3.3", |     "mini-svg-data-uri": "^1.3.3", | ||||||
|     "moment": "^2.29.1", |     "moment": "^2.29.1", | ||||||
|     "pinia": "^2.0.4", |     "pinia": "^2.0.4", | ||||||
|     "v-calendar": "3.0.0-alpha.8", |     "v-money3": "^3.13.5", | ||||||
|     "v-money3": "3.16.1", |  | ||||||
|     "v-tooltip": "^4.0.0-alpha.1", |     "v-tooltip": "^4.0.0-alpha.1", | ||||||
|     "vue": "^3.2.0-beta.5", |     "vue": "^3.2.0-beta.5", | ||||||
|     "vue-flatpickr-component": "^9.0.3", |     "vue-flatpickr-component": "^9.0.3", | ||||||
|  | |||||||
| @ -47,8 +47,6 @@ const ExpenseCategory = () => | |||||||
|   import('@/scripts/admin/views/settings/ExpenseCategorySetting.vue') |   import('@/scripts/admin/views/settings/ExpenseCategorySetting.vue') | ||||||
| const ExchangeRateSetting = () => | const ExchangeRateSetting = () => | ||||||
|   import('@/scripts/admin/views/settings/ExchangeRateProviderSetting.vue') |   import('@/scripts/admin/views/settings/ExchangeRateProviderSetting.vue') | ||||||
| const MailConfig = () => |  | ||||||
|   import('@/scripts/admin/views/settings/MailConfigSetting.vue') |  | ||||||
| const FileDisk = () => | const FileDisk = () => | ||||||
|   import('@/scripts/admin/views/settings/FileDiskSetting.vue') |   import('@/scripts/admin/views/settings/FileDiskSetting.vue') | ||||||
| const Backup = () => import('@/scripts/admin/views/settings/BackupSetting.vue') | const Backup = () => import('@/scripts/admin/views/settings/BackupSetting.vue') | ||||||
| @ -56,6 +54,8 @@ const UpdateApp = () => | |||||||
|   import('@/scripts/admin/views/settings/UpdateAppSetting.vue') |   import('@/scripts/admin/views/settings/UpdateAppSetting.vue') | ||||||
| const RolesSettings = () => | const RolesSettings = () => | ||||||
|   import('@/scripts/admin/views/settings/RolesSettings.vue') |   import('@/scripts/admin/views/settings/RolesSettings.vue') | ||||||
|  | const MailSender = () => | ||||||
|  |   import('@/scripts/admin/views/settings/mail-sender/Index.vue') | ||||||
|  |  | ||||||
| // Items | // Items | ||||||
| const ItemsIndex = () => import('@/scripts/admin/views/items/Index.vue') | const ItemsIndex = () => import('@/scripts/admin/views/items/Index.vue') | ||||||
| @ -302,13 +302,6 @@ export default [ | |||||||
|             meta: { ability: abilities.VIEW_EXPENSE }, |             meta: { ability: abilities.VIEW_EXPENSE }, | ||||||
|             component: ExpenseCategory, |             component: ExpenseCategory, | ||||||
|           }, |           }, | ||||||
|  |  | ||||||
|           { |  | ||||||
|             path: 'mail-configuration', |  | ||||||
|             name: 'mailconfig', |  | ||||||
|             meta: { isOwner: true }, |  | ||||||
|             component: MailConfig, |  | ||||||
|           }, |  | ||||||
|           { |           { | ||||||
|             path: 'file-disk', |             path: 'file-disk', | ||||||
|             name: 'file-disk', |             name: 'file-disk', | ||||||
| @ -327,6 +320,13 @@ export default [ | |||||||
|             meta: { isOwner: true }, |             meta: { isOwner: true }, | ||||||
|             component: UpdateApp, |             component: UpdateApp, | ||||||
|           }, |           }, | ||||||
|  |           { | ||||||
|  |             path: 'mail-sender', | ||||||
|  |             name: 'mailsender', | ||||||
|  |             meta: { ability: abilities.VIEW_MAIL_SENDER }, | ||||||
|  |             component: MailSender, | ||||||
|  |           }, | ||||||
|  |  | ||||||
|         ], |         ], | ||||||
|       }, |       }, | ||||||
|  |  | ||||||
|  | |||||||
							
								
								
									
										123
									
								
								resources/scripts/admin/components/FeedbackAlert.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								resources/scripts/admin/components/FeedbackAlert.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,123 @@ | |||||||
|  | <template> | ||||||
|  |   <!-- warning alert --> | ||||||
|  |   <div | ||||||
|  |     v-if="type == 'warning'" | ||||||
|  |     class="rounded-md p-4 m-5" | ||||||
|  |     :class="{ | ||||||
|  |       'bg-yellow-50': type == 'warning', | ||||||
|  |       'bg-blue-50': type == 'info', | ||||||
|  |       'bg-red-50': type == 'error', | ||||||
|  |       'bg-green-50': type == 'success', | ||||||
|  |     }" | ||||||
|  |   > | ||||||
|  |     <div class="flex"> | ||||||
|  |       <div class="flex-shrink-0"> | ||||||
|  |         <!-- Heroicon name: solid/exclamation --> | ||||||
|  |         <svg | ||||||
|  |           v-if="type == 'warning'" | ||||||
|  |           class="h-5 w-5 text-yellow-400" | ||||||
|  |           xmlns="http://www.w3.org/2000/svg" | ||||||
|  |           viewBox="0 0 20 20" | ||||||
|  |           fill="currentColor" | ||||||
|  |           aria-hidden="true" | ||||||
|  |         > | ||||||
|  |           <path | ||||||
|  |             fill-rule="evenodd" | ||||||
|  |             d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" | ||||||
|  |             clip-rule="evenodd" | ||||||
|  |           /> | ||||||
|  |         </svg> | ||||||
|  |         <!-- Heroicon name: solid/information-circle --> | ||||||
|  |         <svg | ||||||
|  |           v-else-if="type == 'info'" | ||||||
|  |           class="h-5 w-5 text-blue-400" | ||||||
|  |           xmlns="http://www.w3.org/2000/svg" | ||||||
|  |           viewBox="0 0 20 20" | ||||||
|  |           fill="currentColor" | ||||||
|  |           aria-hidden="true" | ||||||
|  |         > | ||||||
|  |           <path | ||||||
|  |             fill-rule="evenodd" | ||||||
|  |             d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" | ||||||
|  |             clip-rule="evenodd" | ||||||
|  |           /> | ||||||
|  |         </svg> | ||||||
|  |         <!-- Heroicon name: solid/x-circle --> | ||||||
|  |         <svg | ||||||
|  |           v-else-if="type == 'error'" | ||||||
|  |           class="h-5 w-5 text-red-400" | ||||||
|  |           xmlns="http://www.w3.org/2000/svg" | ||||||
|  |           viewBox="0 0 20 20" | ||||||
|  |           fill="currentColor" | ||||||
|  |           aria-hidden="true" | ||||||
|  |         > | ||||||
|  |           <path | ||||||
|  |             fill-rule="evenodd" | ||||||
|  |             d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" | ||||||
|  |             clip-rule="evenodd" | ||||||
|  |           /> | ||||||
|  |         </svg> | ||||||
|  |         <!-- Heroicon name: solid/check-circle --> | ||||||
|  |         <svg | ||||||
|  |           v-else | ||||||
|  |           class="h-5 w-5 text-green-400" | ||||||
|  |           xmlns="http://www.w3.org/2000/svg" | ||||||
|  |           viewBox="0 0 20 20" | ||||||
|  |           fill="currentColor" | ||||||
|  |           aria-hidden="true" | ||||||
|  |         > | ||||||
|  |           <path | ||||||
|  |             fill-rule="evenodd" | ||||||
|  |             d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" | ||||||
|  |             clip-rule="evenodd" | ||||||
|  |           /> | ||||||
|  |         </svg> | ||||||
|  |       </div> | ||||||
|  |       <div class="ml-3"> | ||||||
|  |         <h3 | ||||||
|  |           class="text-sm font-medium" | ||||||
|  |           :class="{ | ||||||
|  |             'text-yellow-800': type == 'warning', | ||||||
|  |             'text-blue-800': type == 'info', | ||||||
|  |             'text-red-800': type == 'error', | ||||||
|  |             'text-green-800': type == 'success', | ||||||
|  |           }" | ||||||
|  |         > | ||||||
|  |           {{ title }} | ||||||
|  |         </h3> | ||||||
|  |         <div | ||||||
|  |           class="text-sm" | ||||||
|  |           :class="{ | ||||||
|  |             'text-yellow-700': type == 'warning', | ||||||
|  |             'text-blue-700': type == 'info', | ||||||
|  |             'text-red-700': type == 'error', | ||||||
|  |             'text-green-700': type == 'success', | ||||||
|  |           }" | ||||||
|  |         > | ||||||
|  |           <p>{{ description }}</p> | ||||||
|  |         </div> | ||||||
|  |         <slot name="action"></slot> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <script setup> | ||||||
|  | const props = defineProps({ | ||||||
|  |   title: { | ||||||
|  |     type: String, | ||||||
|  |     default: null, | ||||||
|  |     required: false, | ||||||
|  |   }, | ||||||
|  |   description: { | ||||||
|  |     type: String, | ||||||
|  |     default: null, | ||||||
|  |     required: false, | ||||||
|  |   }, | ||||||
|  |   type: { | ||||||
|  |     type: String, | ||||||
|  |     default: 'success', | ||||||
|  |     required: true, | ||||||
|  |   }, | ||||||
|  | }) | ||||||
|  | </script> | ||||||
| @ -64,7 +64,7 @@ function mergeExistingValues() { | |||||||
|   if (props.isEdit) { |   if (props.isEdit) { | ||||||
|     props.store[props.storeProp].fields.forEach((field) => { |     props.store[props.storeProp].fields.forEach((field) => { | ||||||
|       const existingIndex = props.store[props.storeProp].customFields.findIndex( |       const existingIndex = props.store[props.storeProp].customFields.findIndex( | ||||||
|         (f) => f.id == field.custom_field_id |         (f) => f.id === field.custom_field_id | ||||||
|       ) |       ) | ||||||
|  |  | ||||||
|       if (existingIndex > -1) { |       if (existingIndex > -1) { | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ import { computed } from 'vue' | |||||||
| const props = defineProps({ | const props = defineProps({ | ||||||
|   modelValue: { |   modelValue: { | ||||||
|     type: String, |     type: String, | ||||||
|     default: moment().format('YYYY-MM-DD HH:mm'), |     default: moment().format('YYYY-MM-DD hh:MM'), | ||||||
|   }, |   }, | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  | |||||||
| @ -0,0 +1,111 @@ | |||||||
|  | <template> | ||||||
|  |   <BaseDropdown> | ||||||
|  |     <template #activator> | ||||||
|  |       <BaseButton v-if="route.name === 'mailsender.view'" variant="primary"> | ||||||
|  |         <BaseIcon name="DotsHorizontalIcon" class="h-5 text-white" /> | ||||||
|  |       </BaseButton> | ||||||
|  |       <BaseIcon v-else name="DotsHorizontalIcon" class="h-5 text-gray-500" /> | ||||||
|  |     </template> | ||||||
|  |  | ||||||
|  |     <!-- edit mail-sender  --> | ||||||
|  |     <BaseDropdownItem @click="editMailSender(row.id)"> | ||||||
|  |       <BaseIcon | ||||||
|  |         name="PencilIcon" | ||||||
|  |         class="w-5 h-5 mr-3 text-gray-400 group-hover:text-gray-500" | ||||||
|  |       /> | ||||||
|  |       {{ $t('general.edit') }} | ||||||
|  |     </BaseDropdownItem> | ||||||
|  |  | ||||||
|  |     <!-- send test mail-sender  --> | ||||||
|  |     <BaseDropdownItem @click="openMailSenderTestModal(row.id)"> | ||||||
|  |       <BaseIcon | ||||||
|  |         name="PaperAirplaneIcon" | ||||||
|  |         class="w-5 h-5 mr-3 text-gray-400 group-hover:text-gray-500" | ||||||
|  |       /> | ||||||
|  |       {{ $t('general.send_test_mail') }} | ||||||
|  |     </BaseDropdownItem> | ||||||
|  |  | ||||||
|  |     <!-- delete mail-sender  --> | ||||||
|  |     <BaseDropdownItem v-if="!row.is_default" @click="removeMailSender(row.id)"> | ||||||
|  |       <BaseIcon | ||||||
|  |         name="TrashIcon" | ||||||
|  |         class="w-5 h-5 mr-3 text-gray-400 group-hover:text-gray-500" | ||||||
|  |       /> | ||||||
|  |       {{ $t('general.delete') }} | ||||||
|  |     </BaseDropdownItem> | ||||||
|  |   </BaseDropdown> | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <script setup> | ||||||
|  | import { useDialogStore } from '@/scripts/stores/dialog' | ||||||
|  | import { useI18n } from 'vue-i18n' | ||||||
|  | import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender' | ||||||
|  | import { useRoute, useRouter } from 'vue-router' | ||||||
|  | import { inject } from 'vue' | ||||||
|  | import { useModalStore } from '@/scripts/stores/modal' | ||||||
|  |  | ||||||
|  | const props = defineProps({ | ||||||
|  |   row: { | ||||||
|  |     type: Object, | ||||||
|  |     default: null, | ||||||
|  |   }, | ||||||
|  |   table: { | ||||||
|  |     type: Object, | ||||||
|  |     default: null, | ||||||
|  |   }, | ||||||
|  |   loadData: { | ||||||
|  |     type: Function, | ||||||
|  |     default: null, | ||||||
|  |   }, | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const pre_t = 'settings.mail_sender' | ||||||
|  | const dialogStore = useDialogStore() | ||||||
|  | const { t } = useI18n() | ||||||
|  | const mailSenderStore = useMailSenderStore() | ||||||
|  | const route = useRoute() | ||||||
|  | const modalStore = useModalStore() | ||||||
|  |  | ||||||
|  | async function editMailSender(id) { | ||||||
|  |   await mailSenderStore.fetchMailSender(id) | ||||||
|  |   modalStore.openModal({ | ||||||
|  |     title: t(`${pre_t}.edit_mail_sender`), | ||||||
|  |     componentName: 'MailSenderModal', | ||||||
|  |     size: 'md', | ||||||
|  |     refreshData: props.loadData && props.loadData, | ||||||
|  |   }) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function removeMailSender(id) { | ||||||
|  |   dialogStore | ||||||
|  |     .openDialog({ | ||||||
|  |       title: t('general.are_you_sure'), | ||||||
|  |       message: t(`${pre_t}.confirm_delete`), | ||||||
|  |       yesLabel: t('general.ok'), | ||||||
|  |       noLabel: t('general.cancel'), | ||||||
|  |       variant: 'danger', | ||||||
|  |       hideNoButton: false, | ||||||
|  |       size: 'lg', | ||||||
|  |     }) | ||||||
|  |     .then(async (res) => { | ||||||
|  |       if (res) { | ||||||
|  |         let response = await mailSenderStore.deleteMailSender(id) | ||||||
|  |         if (response.data.success) { | ||||||
|  |           props.loadData && props.loadData() | ||||||
|  |           return true | ||||||
|  |         } | ||||||
|  |         props.loadData && props.loadData() | ||||||
|  |       } | ||||||
|  |     }) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function openMailSenderTestModal(id) { | ||||||
|  |   modalStore.openModal({ | ||||||
|  |     title: t(`general.send_test_mail`), | ||||||
|  |     componentName: 'MailSenderTestModal', | ||||||
|  |     size: 'md', | ||||||
|  |     id: id, | ||||||
|  |     refreshData: props.loadData && props.loadData, | ||||||
|  |   }) | ||||||
|  | } | ||||||
|  | </script> | ||||||
| @ -48,24 +48,6 @@ | |||||||
|             /> |             /> | ||||||
|           </BaseInputGroup> |           </BaseInputGroup> | ||||||
|  |  | ||||||
|           <BaseInputGroup |  | ||||||
|             :label="$tc('settings.company_info.company_slug')" |  | ||||||
|             :help-text="$t('settings.company_info.company_slug_help_text')" |  | ||||||
|             :error=" |  | ||||||
|               v$.newCompanyForm.slug.$error && |  | ||||||
|               v$.newCompanyForm.slug.$errors[0].$message |  | ||||||
|             " |  | ||||||
|             :content-loading="isFetchingInitialData" |  | ||||||
|             required |  | ||||||
|           > |  | ||||||
|             <BaseInput |  | ||||||
|               v-model="newCompanyForm.slug" |  | ||||||
|               :invalid="v$.newCompanyForm.slug.$error" |  | ||||||
|               :content-loading="isFetchingInitialData" |  | ||||||
|               @input="v$.newCompanyForm.slug.$touch()" |  | ||||||
|             /> |  | ||||||
|           </BaseInputGroup> |  | ||||||
|  |  | ||||||
|           <BaseInputGroup |           <BaseInputGroup | ||||||
|             :content-loading="isFetchingInitialData" |             :content-loading="isFetchingInitialData" | ||||||
|             :label="$tc('settings.company_info.country')" |             :label="$tc('settings.company_info.country')" | ||||||
| @ -148,7 +130,7 @@ | |||||||
|  |  | ||||||
| <script setup> | <script setup> | ||||||
| import { useModalStore } from '@/scripts/stores/modal' | import { useModalStore } from '@/scripts/stores/modal' | ||||||
| import { computed, onMounted, ref, reactive, watch } from 'vue' | import { computed, onMounted, ref, reactive } from 'vue' | ||||||
| import { useI18n } from 'vue-i18n' | import { useI18n } from 'vue-i18n' | ||||||
| import { required, minLength, helpers } from '@vuelidate/validators' | import { required, minLength, helpers } from '@vuelidate/validators' | ||||||
| import { useVuelidate } from '@vuelidate/core' | import { useVuelidate } from '@vuelidate/core' | ||||||
| @ -170,7 +152,6 @@ let companyLogoName = ref(null) | |||||||
|  |  | ||||||
| const newCompanyForm = reactive({ | const newCompanyForm = reactive({ | ||||||
|   name: null, |   name: null, | ||||||
|   slug: null, |  | ||||||
|   currency: '', |   currency: '', | ||||||
|   address: { |   address: { | ||||||
|     country_id: null, |     country_id: null, | ||||||
| @ -181,9 +162,6 @@ const modalActive = computed(() => { | |||||||
|   return modalStore.active && modalStore.componentName === 'CompanyModal' |   return modalStore.active && modalStore.componentName === 'CompanyModal' | ||||||
| }) | }) | ||||||
|  |  | ||||||
| const slugValidator = (value) => { |  | ||||||
|   return value == slugify(value) |  | ||||||
| } |  | ||||||
| const rules = { | const rules = { | ||||||
|   newCompanyForm: { |   newCompanyForm: { | ||||||
|     name: { |     name: { | ||||||
| @ -193,17 +171,6 @@ const rules = { | |||||||
|         minLength(3) |         minLength(3) | ||||||
|       ), |       ), | ||||||
|     }, |     }, | ||||||
|     slug: { |  | ||||||
|       required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       minLength: helpers.withMessage( |  | ||||||
|         t('validation.name_min_length', { count: 3 }), |  | ||||||
|         minLength(3) |  | ||||||
|       ), |  | ||||||
|       slugValidator: helpers.withMessage( |  | ||||||
|         t('validation.invalid_slug'), |  | ||||||
|         slugValidator |  | ||||||
|       ), |  | ||||||
|     }, |  | ||||||
|     address: { |     address: { | ||||||
|       country_id: { |       country_id: { | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |         required: helpers.withMessage(t('validation.required'), required), | ||||||
| @ -276,7 +243,6 @@ async function submitCompanyData() { | |||||||
|  |  | ||||||
| function resetNewCompanyForm() { | function resetNewCompanyForm() { | ||||||
|   newCompanyForm.name = '' |   newCompanyForm.name = '' | ||||||
|   newCompanyForm.slug = '' |  | ||||||
|   newCompanyForm.currency = '' |   newCompanyForm.currency = '' | ||||||
|   newCompanyForm.address.country_id = '' |   newCompanyForm.address.country_id = '' | ||||||
|  |  | ||||||
| @ -291,24 +257,4 @@ function closeCompanyModal() { | |||||||
|     v$.value.$reset() |     v$.value.$reset() | ||||||
|   }, 300) |   }, 300) | ||||||
| } | } | ||||||
|  |  | ||||||
| // watcher for if change company name then auto fill company slug value |  | ||||||
| watch( |  | ||||||
|   () => newCompanyForm.name, |  | ||||||
|   (currentValue) => { |  | ||||||
|     newCompanyForm.slug = slugify(currentValue) |  | ||||||
|   } |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| function slugify(string) { |  | ||||||
|   return string |  | ||||||
|     .toString() |  | ||||||
|     .trim() |  | ||||||
|     .toLowerCase() |  | ||||||
|     .replace(/\s+/g, '-') |  | ||||||
|     .replace(/[^\w\-]+/g, '') |  | ||||||
|     .replace(/\-\-+/g, '-') |  | ||||||
|     .replace(/^-+/, '') |  | ||||||
|     .replace(/-+$/, '') |  | ||||||
| } |  | ||||||
| </script> | </script> | ||||||
|  | |||||||
| @ -453,7 +453,7 @@ | |||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script setup> | <script setup> | ||||||
| import { computed, onMounted, ref } from 'vue' | import { computed, ref } from 'vue' | ||||||
| import { useRoute } from 'vue-router' | import { useRoute } from 'vue-router' | ||||||
| import { useI18n } from 'vue-i18n' | import { useI18n } from 'vue-i18n' | ||||||
|  |  | ||||||
| @ -549,7 +549,6 @@ const rules = computed(() => { | |||||||
|     website: { |     website: { | ||||||
|       url: helpers.withMessage(t('validation.invalid_url'), url), |       url: helpers.withMessage(t('validation.invalid_url'), url), | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|     billing: { |     billing: { | ||||||
|       address_street_1: { |       address_street_1: { | ||||||
|         maxLength: helpers.withMessage( |         maxLength: helpers.withMessage( | ||||||
|  | |||||||
| @ -0,0 +1,287 @@ | |||||||
|  | <template> | ||||||
|  |   <BaseModal | ||||||
|  |     :show="modalStore.active && modalStore.componentName === 'MailSenderModal'" | ||||||
|  |   > | ||||||
|  |     <template #header> | ||||||
|  |       <div class="flex justify-between w-full"> | ||||||
|  |         {{ modalStore.title }} | ||||||
|  |         <BaseIcon | ||||||
|  |           name="XIcon" | ||||||
|  |           class="h-6 w-6 text-gray-500 cursor-pointer" | ||||||
|  |           @click="closeMailSenderModal" | ||||||
|  |         /> | ||||||
|  |       </div> | ||||||
|  |     </template> | ||||||
|  |     <form action="" @submit.prevent="submitMailSenderData"> | ||||||
|  |       <div class="p-4 sm:p-6 my-2"> | ||||||
|  |         <!-- Name --> | ||||||
|  |         <BaseInputGrid> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.name`)" | ||||||
|  |             :error="v$.name.$error && v$.name.$errors[0].$message" | ||||||
|  |             :help-text="$t(`${pre_t}.name_help`)" | ||||||
|  |             required | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model.trim="mailSenderStore.currentMailSender.name" | ||||||
|  |               :invalid="v$.name.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.name.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- From Name --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.from_name`)" | ||||||
|  |             :error="v$.from_name.$error && v$.from_name.$errors[0].$message" | ||||||
|  |             required | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="mailSenderStore.currentMailSender.from_name" | ||||||
|  |               :invalid="v$.from_name.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.from_name.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- From Address --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.from_address`)" | ||||||
|  |             :error=" | ||||||
|  |               v$.from_address.$error && v$.from_address.$errors[0].$message | ||||||
|  |             " | ||||||
|  |             required | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="mailSenderStore.currentMailSender.from_address" | ||||||
|  |               :invalid="v$.from_address.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.from_address.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- CC --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.cc`)" | ||||||
|  |             :error="v$.cc.$error && v$.cc.$errors[0].$message" | ||||||
|  |             :help-text="$t(`${pre_t}.email_list`)" | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="mailSenderStore.currentMailSender.cc" | ||||||
|  |               :invalid="v$.cc.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.cc.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- BCC --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.bcc`)" | ||||||
|  |             :error="v$.bcc.$error && v$.bcc.$errors[0].$message" | ||||||
|  |             :help-text="$t(`${pre_t}.email_list`)" | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="mailSenderStore.currentMailSender.bcc" | ||||||
|  |               :invalid="v$.bcc.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.bcc.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- Mail Driver --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.driver`)" | ||||||
|  |             :error="v$.driver.$error && v$.driver.$errors[0].$message" | ||||||
|  |             required | ||||||
|  |           > | ||||||
|  |             <BaseMultiselect | ||||||
|  |               v-model="mailSenderStore.currentMailSender.driver" | ||||||
|  |               :options="mailSenderStore.mail_drivers" | ||||||
|  |               :can-deselect="false" | ||||||
|  |               :invalid="v$.driver.$error" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <component | ||||||
|  |             :is="loadMailDriver" | ||||||
|  |             :mail-sender-store="mailSenderStore" | ||||||
|  |           /> | ||||||
|  |         </BaseInputGrid> | ||||||
|  |  | ||||||
|  |         <BaseDivider class="mt-4 mb-0" /> | ||||||
|  |  | ||||||
|  |         <!-- Is Default? --> | ||||||
|  |         <BaseSwitchSection | ||||||
|  |           v-if="!mailSenderStore.isDisable" | ||||||
|  |           v-model="mailSenderStore.currentMailSender.is_default" | ||||||
|  |           :title="$t(`${pre_t}.is_default`)" | ||||||
|  |           :description="$t(`${pre_t}.is_default_description`)" | ||||||
|  |         /> | ||||||
|  |       </div> | ||||||
|  |  | ||||||
|  |       <div | ||||||
|  |         class="z-0 flex justify-end p-4 border-t border-solid border--200 border-modal-bg" | ||||||
|  |       > | ||||||
|  |         <BaseButton | ||||||
|  |           class="mr-3 text-sm" | ||||||
|  |           variant="primary-outline" | ||||||
|  |           type="button" | ||||||
|  |           @click="closeMailSenderModal" | ||||||
|  |         > | ||||||
|  |           {{ $t('general.cancel') }} | ||||||
|  |         </BaseButton> | ||||||
|  |         <BaseButton | ||||||
|  |           :loading="isSaving" | ||||||
|  |           :disabled="isSaving" | ||||||
|  |           variant="primary" | ||||||
|  |           type="submit" | ||||||
|  |         > | ||||||
|  |           <template #left="slotProps"> | ||||||
|  |             <BaseIcon | ||||||
|  |               v-if="!isSaving" | ||||||
|  |               name="SaveIcon" | ||||||
|  |               :class="slotProps.class" | ||||||
|  |             /> | ||||||
|  |           </template> | ||||||
|  |           {{ | ||||||
|  |             mailSenderStore.isEdit ? $t('general.update') : $t('general.save') | ||||||
|  |           }} | ||||||
|  |         </BaseButton> | ||||||
|  |       </div> | ||||||
|  |     </form> | ||||||
|  |   </BaseModal> | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <script setup> | ||||||
|  | import { computed, onMounted, ref } from 'vue' | ||||||
|  | import { useI18n } from 'vue-i18n' | ||||||
|  | import { required, email, minLength, helpers } from '@vuelidate/validators' | ||||||
|  | import { useVuelidate } from '@vuelidate/core' | ||||||
|  | import { useModalStore } from '@/scripts/stores/modal' | ||||||
|  | import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender' | ||||||
|  | import SmtpDriver from '@/scripts/admin/views/settings/mail-sender/SmtpDriver.vue' | ||||||
|  | import MailgunDriver from '@/scripts/admin/views/settings/mail-sender/MailgunDriver.vue' | ||||||
|  | import SesDriver from '@/scripts/admin/views/settings/mail-sender/SesDriver.vue' | ||||||
|  |  | ||||||
|  | const pre_t = 'settings.mail_sender' | ||||||
|  | const modalStore = useModalStore() | ||||||
|  | const mailSenderStore = useMailSenderStore() | ||||||
|  | const { t } = useI18n() | ||||||
|  | let isSaving = ref(false) | ||||||
|  |  | ||||||
|  | const loadMailDriver = computed(() => { | ||||||
|  |   switch (mailSenderStore.currentMailSender.driver) { | ||||||
|  |     case 'smtp': | ||||||
|  |       return SmtpDriver | ||||||
|  |     case 'mail': | ||||||
|  |       return false | ||||||
|  |     case 'sendmail': | ||||||
|  |       return false | ||||||
|  |     case 'mailgun': | ||||||
|  |       return MailgunDriver | ||||||
|  |     case 'ses': | ||||||
|  |       return SesDriver | ||||||
|  |     default: | ||||||
|  |       return false | ||||||
|  |   } | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | // This is multiple email custom validation | ||||||
|  | const multiEmail = (value) => { | ||||||
|  |   if (value == '' || value === null) return true | ||||||
|  |   const emailRegex = | ||||||
|  |     /^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i | ||||||
|  |  | ||||||
|  |   const emailArr = value.split(',') | ||||||
|  |   let isValid = emailArr.every((v) => { | ||||||
|  |     return emailRegex.test(v) | ||||||
|  |   }) | ||||||
|  |   return isValid | ||||||
|  | } | ||||||
|  |  | ||||||
|  | const rules = computed(() => { | ||||||
|  |   return { | ||||||
|  |     name: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |       minLength: helpers.withMessage( | ||||||
|  |         t('validation.name_min_length', { count: 3 }), | ||||||
|  |         minLength(3) | ||||||
|  |       ), | ||||||
|  |     }, | ||||||
|  |     from_name: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |     from_address: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |       email: helpers.withMessage(t('validation.email_incorrect'), email), | ||||||
|  |     }, | ||||||
|  |     cc: { | ||||||
|  |       multiEmail: helpers.withMessage( | ||||||
|  |         t('validation.email_incorrect'), | ||||||
|  |         multiEmail | ||||||
|  |       ), | ||||||
|  |     }, | ||||||
|  |     bcc: { | ||||||
|  |       multiEmail: helpers.withMessage( | ||||||
|  |         t('validation.email_incorrect'), | ||||||
|  |         multiEmail | ||||||
|  |       ), | ||||||
|  |     }, | ||||||
|  |     driver: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |   } | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const v$ = useVuelidate( | ||||||
|  |   rules, | ||||||
|  |   computed(() => mailSenderStore.currentMailSender) | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | async function submitMailSenderData() { | ||||||
|  |   v$.value.$touch() | ||||||
|  |   if (v$.value.$invalid) { | ||||||
|  |     return true | ||||||
|  |   } | ||||||
|  |   try { | ||||||
|  |     const action = mailSenderStore.isEdit | ||||||
|  |       ? mailSenderStore.updateMailSender | ||||||
|  |       : mailSenderStore.addMailSender | ||||||
|  |     isSaving.value = true | ||||||
|  |  | ||||||
|  |     var mailDriverConfig = null | ||||||
|  |     switch (mailSenderStore.currentMailSender.driver) { | ||||||
|  |       case 'smtp': | ||||||
|  |         mailDriverConfig = mailSenderStore.smtpConfig | ||||||
|  |         break | ||||||
|  |       case 'mailgun': | ||||||
|  |         mailDriverConfig = mailSenderStore.mailgunConfig | ||||||
|  |         break | ||||||
|  |       case 'ses': | ||||||
|  |         mailDriverConfig = mailSenderStore.sesConfig | ||||||
|  |         break | ||||||
|  |     } | ||||||
|  |     mailSenderStore.currentMailSender.settings = mailDriverConfig | ||||||
|  |  | ||||||
|  |     let res = await action(mailSenderStore.currentMailSender) | ||||||
|  |     isSaving.value = false | ||||||
|  |     modalStore.refreshData ? modalStore.refreshData(res.data.data) : '' | ||||||
|  |     closeMailSenderModal() | ||||||
|  |   } catch (err) { | ||||||
|  |     isSaving.value = false | ||||||
|  |     return true | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function closeMailSenderModal() { | ||||||
|  |   modalStore.closeModal() | ||||||
|  |   setTimeout(() => { | ||||||
|  |     mailSenderStore.resetCurrentMailSender() | ||||||
|  |     v$.value.$reset() | ||||||
|  |   }, 300) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | onMounted(async () => { | ||||||
|  |   await mailSenderStore.fetchMailDrivers() | ||||||
|  | }) | ||||||
|  | </script> | ||||||
| @ -0,0 +1,208 @@ | |||||||
|  | <template> | ||||||
|  |   <BaseModal :show="modalActive" @open="setInitialData"> | ||||||
|  |     <template #header> | ||||||
|  |       <div class="flex justify-between w-full"> | ||||||
|  |         {{ modalStore.title }} | ||||||
|  |         <BaseIcon | ||||||
|  |           name="XIcon" | ||||||
|  |           class="w-6 h-6 text-gray-500 cursor-pointer" | ||||||
|  |           @click="closeTestModal" | ||||||
|  |         /> | ||||||
|  |       </div> | ||||||
|  |     </template> | ||||||
|  |     <form action="" @submit.prevent="onTestMailSend"> | ||||||
|  |       <div class="p-4 md:p-8"> | ||||||
|  |         <BaseInputGrid layout="one-column"> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.title`)" | ||||||
|  |             variant="horizontal" | ||||||
|  |             :content-loading="isFetchingInitialData" | ||||||
|  |             :error=" | ||||||
|  |               v$.mail_sender_id.$error && v$.mail_sender_id.$errors[0].$message | ||||||
|  |             " | ||||||
|  |           > | ||||||
|  |             <BaseMultiselect | ||||||
|  |               v-model="formData.mail_sender_id" | ||||||
|  |               :invalid="v$.mail_sender_id.$error" | ||||||
|  |               label="name" | ||||||
|  |               :options="mailSenderStore.mailSenders" | ||||||
|  |               value-prop="id" | ||||||
|  |               :can-deselect="false" | ||||||
|  |               :can-clear="false" | ||||||
|  |               :placeholder="$t(`${pre_t}.select_mail_sender`)" | ||||||
|  |               searchable | ||||||
|  |               track-by="name" | ||||||
|  |               :content-loading="isFetchingInitialData" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t('general.to')" | ||||||
|  |             :error="v$.to.$error && v$.to.$errors[0].$message" | ||||||
|  |             variant="horizontal" | ||||||
|  |             required | ||||||
|  |             :content-loading="isFetchingInitialData" | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="formData.to" | ||||||
|  |               type="text" | ||||||
|  |               :invalid="v$.to.$error" | ||||||
|  |               :content-loading="isFetchingInitialData" | ||||||
|  |               @input="v$.to.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t('general.subject')" | ||||||
|  |             :error="v$.subject.$error && v$.subject.$errors[0].$message" | ||||||
|  |             variant="horizontal" | ||||||
|  |             required | ||||||
|  |             :content-loading="isFetchingInitialData" | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="formData.subject" | ||||||
|  |               type="text" | ||||||
|  |               :invalid="v$.subject.$error" | ||||||
|  |               :content-loading="isFetchingInitialData" | ||||||
|  |               @input="v$.subject.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t('general.message')" | ||||||
|  |             :error="v$.message.$error && v$.message.$errors[0].$message" | ||||||
|  |             variant="horizontal" | ||||||
|  |             required | ||||||
|  |             :content-loading="isFetchingInitialData" | ||||||
|  |           > | ||||||
|  |             <BaseTextarea | ||||||
|  |               v-model="formData.message" | ||||||
|  |               rows="4" | ||||||
|  |               cols="50" | ||||||
|  |               :invalid="v$.message.$error" | ||||||
|  |               :content-loading="isFetchingInitialData" | ||||||
|  |               @input="v$.message.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |         </BaseInputGrid> | ||||||
|  |       </div> | ||||||
|  |       <div | ||||||
|  |         class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid" | ||||||
|  |       > | ||||||
|  |         <BaseButton | ||||||
|  |           variant="primary-outline" | ||||||
|  |           type="button" | ||||||
|  |           class="mr-3" | ||||||
|  |           :content-loading="isFetchingInitialData" | ||||||
|  |           @click="closeTestModal()" | ||||||
|  |         > | ||||||
|  |           {{ $t('general.cancel') }} | ||||||
|  |         </BaseButton> | ||||||
|  |  | ||||||
|  |         <BaseButton | ||||||
|  |           :loading="isSaving" | ||||||
|  |           variant="primary" | ||||||
|  |           type="submit" | ||||||
|  |           :content-loading="isFetchingInitialData" | ||||||
|  |         > | ||||||
|  |           <template #left="slotProps"> | ||||||
|  |             <BaseIcon | ||||||
|  |               v-if="!isSaving" | ||||||
|  |               name="PaperAirplaneIcon" | ||||||
|  |               :class="slotProps.class" | ||||||
|  |             /> | ||||||
|  |           </template> | ||||||
|  |           {{ $t('general.send') }} | ||||||
|  |         </BaseButton> | ||||||
|  |       </div> | ||||||
|  |     </form> | ||||||
|  |   </BaseModal> | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <script setup> | ||||||
|  | import { reactive, ref, computed } from 'vue' | ||||||
|  | import { useI18n } from 'vue-i18n' | ||||||
|  | import { required, email, maxLength, helpers } from '@vuelidate/validators' | ||||||
|  | import useVuelidate from '@vuelidate/core' | ||||||
|  | import { useModalStore } from '@/scripts/stores/modal' | ||||||
|  | import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender' | ||||||
|  |  | ||||||
|  | const pre_t = 'settings.mail_sender' | ||||||
|  | const modalStore = useModalStore() | ||||||
|  | const mailSenderStore = useMailSenderStore() | ||||||
|  | const { t } = useI18n() | ||||||
|  | let isSaving = ref(false) | ||||||
|  | let formData = reactive({ | ||||||
|  |   mail_sender_id: '', | ||||||
|  |   to: '', | ||||||
|  |   subject: '', | ||||||
|  |   message: '', | ||||||
|  | }) | ||||||
|  | const isFetchingInitialData = ref(false) | ||||||
|  |  | ||||||
|  | const modalActive = computed(() => { | ||||||
|  |   return modalStore.active && modalStore.componentName === 'MailSenderTestModal' | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | function setInitialData() { | ||||||
|  |   isFetchingInitialData.value = true | ||||||
|  |   formData.mail_sender_id = modalStore.id | ||||||
|  |   setTimeout(() => { | ||||||
|  |     isFetchingInitialData.value = false | ||||||
|  |   }, 100) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | const rules = { | ||||||
|  |   mail_sender_id: { | ||||||
|  |     required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |   }, | ||||||
|  |   to: { | ||||||
|  |     required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     email: helpers.withMessage(t('validation.email_incorrect'), email), | ||||||
|  |   }, | ||||||
|  |   subject: { | ||||||
|  |     required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     maxLength: helpers.withMessage( | ||||||
|  |       t('validation.subject_maxlength'), | ||||||
|  |       maxLength(100) | ||||||
|  |     ), | ||||||
|  |   }, | ||||||
|  |   message: { | ||||||
|  |     required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     maxLength: helpers.withMessage( | ||||||
|  |       t('validation.message_maxlength'), | ||||||
|  |       maxLength(255) | ||||||
|  |     ), | ||||||
|  |   }, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | const v$ = useVuelidate(rules, formData) | ||||||
|  |  | ||||||
|  | function resetFormData() { | ||||||
|  |   formData.mail_sender_id = '' | ||||||
|  |   formData.to = '' | ||||||
|  |   formData.subject = '' | ||||||
|  |   formData.message = '' | ||||||
|  |  | ||||||
|  |   v$.value.$reset() | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function onTestMailSend() { | ||||||
|  |   v$.value.$touch() | ||||||
|  |   if (v$.value.$invalid) { | ||||||
|  |     return true | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   isSaving.value = true | ||||||
|  |   let response = await mailSenderStore.sendTestMail(formData) | ||||||
|  |   if (response.data) { | ||||||
|  |     closeTestModal() | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | function closeTestModal() { | ||||||
|  |   modalStore.closeModal() | ||||||
|  |   setTimeout(() => { | ||||||
|  |     isSaving.value = false | ||||||
|  |     modalStore.resetModalData() | ||||||
|  |     resetFormData() | ||||||
|  |   }, 300) | ||||||
|  | } | ||||||
|  | </script> | ||||||
| @ -16,18 +16,28 @@ | |||||||
|     </template> |     </template> | ||||||
|  |  | ||||||
|     <form v-if="!isPreview" action=""> |     <form v-if="!isPreview" action=""> | ||||||
|       <div class="px-8 py-8 sm:p-6"> |       <!-- v-if --> | ||||||
|  |       <div v-if="isMailSenderExist" class="px-8 py-8 sm:p-6"> | ||||||
|         <BaseInputGrid layout="one-column"> |         <BaseInputGrid layout="one-column"> | ||||||
|           <BaseInputGroup |           <BaseInputGroup | ||||||
|             :label="$t('general.from')" |             :label="$tc('settings.mail_sender.title', 1)" | ||||||
|             required |             required | ||||||
|             :error="v$.from.$error && v$.from.$errors[0].$message" |             :error=" | ||||||
|  |               v$.mail_sender_id.$error && v$.mail_sender_id.$errors[0].$message | ||||||
|  |             " | ||||||
|           > |           > | ||||||
|             <BaseInput |             <BaseMultiselect | ||||||
|               v-model="estimateMailForm.from" |               v-model="estimateMailForm.mail_sender_id" | ||||||
|               type="text" |               :invalid="v$.mail_sender_id.$error" | ||||||
|               :invalid="v$.from.$error" |               label="name" | ||||||
|               @input="v$.from.$touch()" |               :options="mailSenders" | ||||||
|  |               value-prop="id" | ||||||
|  |               :can-deselect="false" | ||||||
|  |               :can-clear="false" | ||||||
|  |               :placeholder="$t(`settings.mail_sender.select_mail_sender`)" | ||||||
|  |               searchable | ||||||
|  |               track-by="name" | ||||||
|  |               :content-loading="isFetchingInitialData" | ||||||
|             /> |             /> | ||||||
|           </BaseInputGroup> |           </BaseInputGroup> | ||||||
|           <BaseInputGroup |           <BaseInputGroup | ||||||
| @ -62,6 +72,45 @@ | |||||||
|           </BaseInputGroup> |           </BaseInputGroup> | ||||||
|         </BaseInputGrid> |         </BaseInputGrid> | ||||||
|       </div> |       </div> | ||||||
|  |       <!-- v-else --> | ||||||
|  |       <div v-else-if="!isMailSenderExist && !isFetchingInitialData"> | ||||||
|  |         <FeedbackAlert | ||||||
|  |           :title="$t('settings.mail_sender.no_mail_sender_found')" | ||||||
|  |           :description=" | ||||||
|  |             $t('settings.mail_sender.no_mail_sender_found_description') | ||||||
|  |           " | ||||||
|  |           type="warning" | ||||||
|  |         > | ||||||
|  |           <template #action> | ||||||
|  |             <div class="mt-4"> | ||||||
|  |               <div class="-mx-2 -my-1.5 flex"> | ||||||
|  |                 <button | ||||||
|  |                   type="button" | ||||||
|  |                   class=" | ||||||
|  |                     bg-yellow-50 | ||||||
|  |                     px-2 | ||||||
|  |                     py-1.5 | ||||||
|  |                     rounded-md | ||||||
|  |                     text-sm | ||||||
|  |                     font-medium | ||||||
|  |                     text-yellow-800 | ||||||
|  |                     hover:bg-yellow-100 | ||||||
|  |                     focus:outline-none | ||||||
|  |                     focus:ring-2 | ||||||
|  |                     focus:ring-offset-2 | ||||||
|  |                     focus:ring-offset-yellow-50 | ||||||
|  |                     focus:ring-yellow-600 | ||||||
|  |                   " | ||||||
|  |                   @click="gotoMailSender" | ||||||
|  |                 > | ||||||
|  |                   {{ $t('settings.mail_sender.manage_mail_sender') }} | ||||||
|  |                 </button> | ||||||
|  |               </div> | ||||||
|  |             </div> | ||||||
|  |           </template> | ||||||
|  |         </FeedbackAlert> | ||||||
|  |       </div> | ||||||
|  |       <!-- end v-if-else --> | ||||||
|       <div |       <div | ||||||
|         class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid" |         class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid" | ||||||
|       > |       > | ||||||
| @ -75,6 +124,7 @@ | |||||||
|         </BaseButton> |         </BaseButton> | ||||||
|  |  | ||||||
|         <BaseButton |         <BaseButton | ||||||
|  |           v-if="isMailSenderExist" | ||||||
|           :loading="isLoading" |           :loading="isLoading" | ||||||
|           :disabled="isLoading" |           :disabled="isLoading" | ||||||
|           variant="primary" |           variant="primary" | ||||||
| @ -141,18 +191,24 @@ import { useModalStore } from '@/scripts/stores/modal' | |||||||
| import { useEstimateStore } from '@/scripts/admin/stores/estimate' | import { useEstimateStore } from '@/scripts/admin/stores/estimate' | ||||||
| import { useNotificationStore } from '@/scripts/stores/notification' | import { useNotificationStore } from '@/scripts/stores/notification' | ||||||
| import { useCompanyStore } from '@/scripts/admin/stores/company' | import { useCompanyStore } from '@/scripts/admin/stores/company' | ||||||
| import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver' | import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender' | ||||||
|  | import FeedbackAlert from '@/scripts/admin/components/FeedbackAlert.vue' | ||||||
|  | import { useRouter } from 'vue-router' | ||||||
|  |  | ||||||
| const modalStore = useModalStore() | const modalStore = useModalStore() | ||||||
| const estimateStore = useEstimateStore() | const estimateStore = useEstimateStore() | ||||||
| const notificationStore = useNotificationStore() | const notificationStore = useNotificationStore() | ||||||
| const companyStore = useCompanyStore() | const companyStore = useCompanyStore() | ||||||
| const mailDriverStore = useMailDriverStore() | const mailSenderStore = useMailSenderStore() | ||||||
|  | const router = useRouter() | ||||||
|  |  | ||||||
| const { t } = useI18n() | const { t } = useI18n() | ||||||
| const isLoading = ref(false) | const isLoading = ref(false) | ||||||
| const templateUrl = ref('') | const templateUrl = ref('') | ||||||
| const isPreview = ref(false) | const isPreview = ref(false) | ||||||
|  | const mailSenders = ref(null) | ||||||
|  | const isFetchingInitialData = ref(false) | ||||||
|  | const emailTemplates = ref(null) | ||||||
|  |  | ||||||
| const estimateMailFields = ref([ | const estimateMailFields = ref([ | ||||||
|   'customer', |   'customer', | ||||||
| @ -164,7 +220,7 @@ const estimateMailFields = ref([ | |||||||
|  |  | ||||||
| let estimateMailForm = reactive({ | let estimateMailForm = reactive({ | ||||||
|   id: null, |   id: null, | ||||||
|   from: null, |   mail_sender_id: null, | ||||||
|   to: null, |   to: null, | ||||||
|   subject: 'New Estimate', |   subject: 'New Estimate', | ||||||
|   body: null, |   body: null, | ||||||
| @ -181,9 +237,8 @@ const modalData = computed(() => { | |||||||
| }) | }) | ||||||
|  |  | ||||||
| const rules = { | const rules = { | ||||||
|   from: { |   mail_sender_id: { | ||||||
|     required: helpers.withMessage(t('validation.required'), required), |     required: helpers.withMessage(t('validation.required'), required), | ||||||
|     email: helpers.withMessage(t('validation.email_incorrect'), email), |  | ||||||
|   }, |   }, | ||||||
|   to: { |   to: { | ||||||
|     required: helpers.withMessage(t('validation.required'), required), |     required: helpers.withMessage(t('validation.required'), required), | ||||||
| @ -207,20 +262,26 @@ function cancelPreview() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function setInitialData() { | async function setInitialData() { | ||||||
|   let admin = await companyStore.fetchBasicMailConfig() |  | ||||||
|  |  | ||||||
|   estimateMailForm.id = modalStore.id |   estimateMailForm.id = modalStore.id | ||||||
|  |  | ||||||
|   if (admin.data) { |  | ||||||
|     estimateMailForm.from = admin.data.from_mail |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   if (modalData.value) { |   if (modalData.value) { | ||||||
|     estimateMailForm.to = modalData.value.customer.email |     estimateMailForm.to = modalData.value.customer.email | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   estimateMailForm.body = |   estimateMailForm.body = | ||||||
|     companyStore.selectedCompanySettings.estimate_mail_body |     companyStore.selectedCompanySettings.estimate_mail_body | ||||||
|  |  | ||||||
|  |   isFetchingInitialData.value = true | ||||||
|  |   let mailSenderData = await mailSenderStore.fetchMailSenders({ limit: 'all' }) | ||||||
|  |   if (mailSenderData.data) { | ||||||
|  |     mailSenders.value = mailSenderData.data.data | ||||||
|  |     let defaultMailSender = mailSenderData.data.data.find( | ||||||
|  |       (mailSender) => mailSender.is_default == true | ||||||
|  |     ) | ||||||
|  |     estimateMailForm.mail_sender_id = defaultMailSender | ||||||
|  |       ? defaultMailSender.id | ||||||
|  |       : null | ||||||
|  |     isFetchingInitialData.value = false | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function submitForm() { | async function submitForm() { | ||||||
| @ -274,4 +335,18 @@ function closeSendEstimateModal() { | |||||||
|     templateUrl.value = null |     templateUrl.value = null | ||||||
|   }, 300) |   }, 300) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function getTickImage() { | ||||||
|  |   const imgUrl = new URL('/img/tick.png', import.meta.url) | ||||||
|  |   return imgUrl | ||||||
|  | } | ||||||
|  |  | ||||||
|  | const isMailSenderExist = computed(() => { | ||||||
|  |   return mailSenders.value && mailSenders.value.length | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | function gotoMailSender() { | ||||||
|  |   closeSendEstimateModal() | ||||||
|  |   router.push('/admin/settings/mail-sender') | ||||||
|  | } | ||||||
| </script> | </script> | ||||||
|  | |||||||
| @ -15,18 +15,28 @@ | |||||||
|       </div> |       </div> | ||||||
|     </template> |     </template> | ||||||
|     <form v-if="!isPreview" action=""> |     <form v-if="!isPreview" action=""> | ||||||
|       <div class="px-8 py-8 sm:p-6"> |       <!-- v-if --> | ||||||
|  |       <div v-if="isMailSenderExist" class="px-8 py-8 sm:p-6"> | ||||||
|         <BaseInputGrid layout="one-column" class="col-span-7"> |         <BaseInputGrid layout="one-column" class="col-span-7"> | ||||||
|           <BaseInputGroup |           <BaseInputGroup | ||||||
|             :label="$t('general.from')" |             :label="$tc('settings.mail_sender.title', 1)" | ||||||
|             required |             required | ||||||
|             :error="v$.from.$error && v$.from.$errors[0].$message" |             :error=" | ||||||
|  |               v$.mail_sender_id.$error && v$.mail_sender_id.$errors[0].$message | ||||||
|  |             " | ||||||
|           > |           > | ||||||
|             <BaseInput |             <BaseMultiselect | ||||||
|               v-model="invoiceMailForm.from" |               v-model="invoiceMailForm.mail_sender_id" | ||||||
|               type="text" |               :invalid="v$.mail_sender_id.$error" | ||||||
|               :invalid="v$.from.$error" |               label="name" | ||||||
|               @input="v$.from.$touch()" |               :options="mailSenders" | ||||||
|  |               value-prop="id" | ||||||
|  |               :can-deselect="false" | ||||||
|  |               :can-clear="false" | ||||||
|  |               :placeholder="$t(`settings.mail_sender.select_mail_sender`)" | ||||||
|  |               searchable | ||||||
|  |               track-by="name" | ||||||
|  |               :content-loading="isFetchingInitialData" | ||||||
|             /> |             /> | ||||||
|           </BaseInputGroup> |           </BaseInputGroup> | ||||||
|           <BaseInputGroup |           <BaseInputGroup | ||||||
| @ -65,6 +75,45 @@ | |||||||
|           </BaseInputGroup> |           </BaseInputGroup> | ||||||
|         </BaseInputGrid> |         </BaseInputGrid> | ||||||
|       </div> |       </div> | ||||||
|  |       <!-- v-else --> | ||||||
|  |       <div v-else-if="!isMailSenderExist && !isFetchingInitialData"> | ||||||
|  |         <FeedbackAlert | ||||||
|  |           :title="$t('settings.mail_sender.no_mail_sender_found')" | ||||||
|  |           :description=" | ||||||
|  |             $t('settings.mail_sender.no_mail_sender_found_description') | ||||||
|  |           " | ||||||
|  |           type="warning" | ||||||
|  |         > | ||||||
|  |           <template #action> | ||||||
|  |             <div class="mt-4"> | ||||||
|  |               <div class="-mx-2 -my-1.5 flex"> | ||||||
|  |                 <button | ||||||
|  |                   type="button" | ||||||
|  |                   class=" | ||||||
|  |                     bg-yellow-50 | ||||||
|  |                     px-2 | ||||||
|  |                     py-1.5 | ||||||
|  |                     rounded-md | ||||||
|  |                     text-sm | ||||||
|  |                     font-medium | ||||||
|  |                     text-yellow-800 | ||||||
|  |                     hover:bg-yellow-100 | ||||||
|  |                     focus:outline-none | ||||||
|  |                     focus:ring-2 | ||||||
|  |                     focus:ring-offset-2 | ||||||
|  |                     focus:ring-offset-yellow-50 | ||||||
|  |                     focus:ring-yellow-600 | ||||||
|  |                   " | ||||||
|  |                   @click="gotoMailSender" | ||||||
|  |                 > | ||||||
|  |                   {{ $t('settings.mail_sender.manage_mail_sender') }} | ||||||
|  |                 </button> | ||||||
|  |               </div> | ||||||
|  |             </div> | ||||||
|  |           </template> | ||||||
|  |         </FeedbackAlert> | ||||||
|  |       </div> | ||||||
|  |       <!-- end v-if-else --> | ||||||
|       <div |       <div | ||||||
|         class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid" |         class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid" | ||||||
|       > |       > | ||||||
| @ -77,6 +126,7 @@ | |||||||
|           {{ $t('general.cancel') }} |           {{ $t('general.cancel') }} | ||||||
|         </BaseButton> |         </BaseButton> | ||||||
|         <BaseButton |         <BaseButton | ||||||
|  |           v-if="isMailSenderExist" | ||||||
|           :loading="isLoading" |           :loading="isLoading" | ||||||
|           :disabled="isLoading" |           :disabled="isLoading" | ||||||
|           variant="primary" |           variant="primary" | ||||||
| @ -154,18 +204,24 @@ import { useI18n } from 'vue-i18n' | |||||||
| import { useInvoiceStore } from '@/scripts/admin/stores/invoice' | import { useInvoiceStore } from '@/scripts/admin/stores/invoice' | ||||||
| import { useVuelidate } from '@vuelidate/core' | import { useVuelidate } from '@vuelidate/core' | ||||||
| import { required, email, helpers } from '@vuelidate/validators' | import { required, email, helpers } from '@vuelidate/validators' | ||||||
| import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver' | import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender' | ||||||
|  | import FeedbackAlert from '@/scripts/admin/components/FeedbackAlert.vue' | ||||||
|  | import { useRouter } from 'vue-router' | ||||||
|  |  | ||||||
| const modalStore = useModalStore() | const modalStore = useModalStore() | ||||||
| const companyStore = useCompanyStore() | const companyStore = useCompanyStore() | ||||||
| const notificationStore = useNotificationStore() | const notificationStore = useNotificationStore() | ||||||
| const invoiceStore = useInvoiceStore() | const invoiceStore = useInvoiceStore() | ||||||
| const mailDriverStore = useMailDriverStore() | const mailSenderStore = useMailSenderStore() | ||||||
|  | const router = useRouter() | ||||||
|  |  | ||||||
| const { t } = useI18n() | const { t } = useI18n() | ||||||
| let isLoading = ref(false) | let isLoading = ref(false) | ||||||
| const templateUrl = ref('') | const templateUrl = ref('') | ||||||
| const isPreview = ref(false) | const isPreview = ref(false) | ||||||
|  | const mailSenders = ref(null) | ||||||
|  | const isFetchingInitialData = ref(false) | ||||||
|  | const emailTemplates = ref(null) | ||||||
|  |  | ||||||
| const emit = defineEmits(['update']) | const emit = defineEmits(['update']) | ||||||
|  |  | ||||||
| @ -179,7 +235,7 @@ const invoiceMailFields = ref([ | |||||||
|  |  | ||||||
| const invoiceMailForm = reactive({ | const invoiceMailForm = reactive({ | ||||||
|   id: null, |   id: null, | ||||||
|   from: null, |   mail_sender_id: null, | ||||||
|   to: null, |   to: null, | ||||||
|   subject: 'New Invoice', |   subject: 'New Invoice', | ||||||
|   body: null, |   body: null, | ||||||
| @ -198,9 +254,8 @@ const modalData = computed(() => { | |||||||
| }) | }) | ||||||
|  |  | ||||||
| const rules = { | const rules = { | ||||||
|   from: { |   mail_sender_id: { | ||||||
|     required: helpers.withMessage(t('validation.required'), required), |     required: helpers.withMessage(t('validation.required'), required), | ||||||
|     email: helpers.withMessage(t('validation.email_incorrect'), email), |  | ||||||
|   }, |   }, | ||||||
|   to: { |   to: { | ||||||
|     required: helpers.withMessage(t('validation.required'), required), |     required: helpers.withMessage(t('validation.required'), required), | ||||||
| @ -224,19 +279,25 @@ function cancelPreview() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function setInitialData() { | async function setInitialData() { | ||||||
|   let admin = await companyStore.fetchBasicMailConfig() |  | ||||||
|  |  | ||||||
|   invoiceMailForm.id = modalStore.id |   invoiceMailForm.id = modalStore.id | ||||||
|  |  | ||||||
|   if (admin.data) { |  | ||||||
|     invoiceMailForm.from = admin.data.from_mail |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   if (modalData.value) { |   if (modalData.value) { | ||||||
|     invoiceMailForm.to = modalData.value.customer.email |     invoiceMailForm.to = modalData.value.customer.email | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   invoiceMailForm.body = companyStore.selectedCompanySettings.invoice_mail_body |   invoiceMailForm.body = companyStore.selectedCompanySettings.invoice_mail_body | ||||||
|  |  | ||||||
|  |   isFetchingInitialData.value = true | ||||||
|  |   let mailSenderData = await mailSenderStore.fetchMailSenders({ limit: 'all' }) | ||||||
|  |   if (mailSenderData.data) { | ||||||
|  |     mailSenders.value = mailSenderData.data.data | ||||||
|  |     let defaultMailSender = mailSenderData.data.data.find( | ||||||
|  |       (mailSender) => mailSender.is_default == true | ||||||
|  |     ) | ||||||
|  |     invoiceMailForm.mail_sender_id = defaultMailSender | ||||||
|  |       ? defaultMailSender.id | ||||||
|  |       : null | ||||||
|  |     isFetchingInitialData.value = false | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function submitForm() { | async function submitForm() { | ||||||
| @ -287,4 +348,18 @@ function closeSendInvoiceModal() { | |||||||
|     templateUrl.value = null |     templateUrl.value = null | ||||||
|   }, 300) |   }, 300) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function getTickImage() { | ||||||
|  |   const imgUrl = new URL('/img/tick.png', import.meta.url) | ||||||
|  |   return imgUrl | ||||||
|  | } | ||||||
|  |  | ||||||
|  | const isMailSenderExist = computed(() => { | ||||||
|  |   return mailSenders.value && mailSenders.value.length | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | function gotoMailSender() { | ||||||
|  |   closeSendInvoiceModal() | ||||||
|  |   router.push('/admin/settings/mail-sender') | ||||||
|  | } | ||||||
| </script> | </script> | ||||||
|  | |||||||
| @ -15,18 +15,28 @@ | |||||||
|       </div> |       </div> | ||||||
|     </template> |     </template> | ||||||
|     <form v-if="!isPreview" action=""> |     <form v-if="!isPreview" action=""> | ||||||
|       <div class="px-8 py-8 sm:p-6"> |       <!-- v-if --> | ||||||
|  |       <div v-if="isMailSenderExist" class="px-8 py-8 sm:p-6"> | ||||||
|         <BaseInputGrid layout="one-column" class="col-span-7"> |         <BaseInputGrid layout="one-column" class="col-span-7"> | ||||||
|           <BaseInputGroup |           <BaseInputGroup | ||||||
|             :label="$t('general.from')" |             :label="$tc('settings.mail_sender.title', 1)" | ||||||
|             required |             required | ||||||
|             :error="v$.from.$error && v$.from.$errors[0].$message" |             :error=" | ||||||
|  |               v$.mail_sender_id.$error && v$.mail_sender_id.$errors[0].$message | ||||||
|  |             " | ||||||
|           > |           > | ||||||
|             <BaseInput |             <BaseMultiselect | ||||||
|               v-model="paymentMailForm.from" |               v-model="paymentMailForm.mail_sender_id" | ||||||
|               type="text" |               :invalid="v$.mail_sender_id.$error" | ||||||
|               :invalid="v$.from.$error" |               label="name" | ||||||
|               @input="v$.from.$touch()" |               :options="mailSenders" | ||||||
|  |               value-prop="id" | ||||||
|  |               :can-deselect="false" | ||||||
|  |               :can-clear="false" | ||||||
|  |               :placeholder="$t(`settings.mail_sender.select_mail_sender`)" | ||||||
|  |               searchable | ||||||
|  |               track-by="name" | ||||||
|  |               :content-loading="isFetchingInitialData" | ||||||
|             /> |             /> | ||||||
|           </BaseInputGroup> |           </BaseInputGroup> | ||||||
|           <BaseInputGroup |           <BaseInputGroup | ||||||
| @ -65,6 +75,45 @@ | |||||||
|           </BaseInputGroup> |           </BaseInputGroup> | ||||||
|         </BaseInputGrid> |         </BaseInputGrid> | ||||||
|       </div> |       </div> | ||||||
|  |       <!-- v-else --> | ||||||
|  |       <div v-else-if="!isMailSenderExist && !isFetchingInitialData"> | ||||||
|  |         <FeedbackAlert | ||||||
|  |           :title="$t('settings.mail_sender.no_mail_sender_found')" | ||||||
|  |           :description=" | ||||||
|  |             $t('settings.mail_sender.no_mail_sender_found_description') | ||||||
|  |           " | ||||||
|  |           type="warning" | ||||||
|  |         > | ||||||
|  |           <template #action> | ||||||
|  |             <div class="mt-4"> | ||||||
|  |               <div class="-mx-2 -my-1.5 flex"> | ||||||
|  |                 <button | ||||||
|  |                   type="button" | ||||||
|  |                   class=" | ||||||
|  |                     bg-yellow-50 | ||||||
|  |                     px-2 | ||||||
|  |                     py-1.5 | ||||||
|  |                     rounded-md | ||||||
|  |                     text-sm | ||||||
|  |                     font-medium | ||||||
|  |                     text-yellow-800 | ||||||
|  |                     hover:bg-yellow-100 | ||||||
|  |                     focus:outline-none | ||||||
|  |                     focus:ring-2 | ||||||
|  |                     focus:ring-offset-2 | ||||||
|  |                     focus:ring-offset-yellow-50 | ||||||
|  |                     focus:ring-yellow-600 | ||||||
|  |                   " | ||||||
|  |                   @click="gotoMailSender" | ||||||
|  |                 > | ||||||
|  |                   {{ $t('settings.mail_sender.manage_mail_sender') }} | ||||||
|  |                 </button> | ||||||
|  |               </div> | ||||||
|  |             </div> | ||||||
|  |           </template> | ||||||
|  |         </FeedbackAlert> | ||||||
|  |       </div> | ||||||
|  |       <!-- end v-if-else --> | ||||||
|       <div |       <div | ||||||
|         class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid" |         class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid" | ||||||
|       > |       > | ||||||
| @ -77,6 +126,7 @@ | |||||||
|           {{ $t('general.cancel') }} |           {{ $t('general.cancel') }} | ||||||
|         </BaseButton> |         </BaseButton> | ||||||
|         <BaseButton |         <BaseButton | ||||||
|  |           v-if="isMailSenderExist" | ||||||
|           :loading="isLoading" |           :loading="isLoading" | ||||||
|           :disabled="isLoading" |           :disabled="isLoading" | ||||||
|           variant="primary" |           variant="primary" | ||||||
| @ -154,20 +204,26 @@ import { usePaymentStore } from '@/scripts/admin/stores/payment' | |||||||
| import { useCompanyStore } from '@/scripts/admin/stores/company' | import { useCompanyStore } from '@/scripts/admin/stores/company' | ||||||
| import { useNotificationStore } from '@/scripts/stores/notification' | import { useNotificationStore } from '@/scripts/stores/notification' | ||||||
| import { useModalStore } from '@/scripts/stores/modal' | import { useModalStore } from '@/scripts/stores/modal' | ||||||
| import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver' |  | ||||||
| import { useDialogStore } from '@/scripts/stores/dialog' | import { useDialogStore } from '@/scripts/stores/dialog' | ||||||
|  | import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender' | ||||||
|  | import FeedbackAlert from '@/scripts/admin/components/FeedbackAlert.vue' | ||||||
|  | import { useRouter } from 'vue-router' | ||||||
|  |  | ||||||
| const paymentStore = usePaymentStore() | const paymentStore = usePaymentStore() | ||||||
| const companyStore = useCompanyStore() | const companyStore = useCompanyStore() | ||||||
| const modalStore = useModalStore() | const modalStore = useModalStore() | ||||||
| const notificationStore = useNotificationStore() | const notificationStore = useNotificationStore() | ||||||
| const mailDriversStore = useMailDriverStore() |  | ||||||
| const dialogStore = useDialogStore() | const dialogStore = useDialogStore() | ||||||
|  | const mailSenderStore = useMailSenderStore() | ||||||
|  | const router = useRouter() | ||||||
|  |  | ||||||
| const { t } = useI18n() | const { t } = useI18n() | ||||||
| let isLoading = ref(false) | let isLoading = ref(false) | ||||||
| const templateUrl = ref('') | const templateUrl = ref('') | ||||||
| const isPreview = ref(false) | const isPreview = ref(false) | ||||||
|  | const mailSenders = ref(null) | ||||||
|  | const isFetchingInitialData = ref(false) | ||||||
|  | const emailTemplates = ref(null) | ||||||
|  |  | ||||||
| const paymentMailFields = ref([ | const paymentMailFields = ref([ | ||||||
|   'customer', |   'customer', | ||||||
| @ -179,7 +235,7 @@ const paymentMailFields = ref([ | |||||||
|  |  | ||||||
| const paymentMailForm = reactive({ | const paymentMailForm = reactive({ | ||||||
|   id: null, |   id: null, | ||||||
|   from: null, |   mail_sender_id: null, | ||||||
|   to: null, |   to: null, | ||||||
|   subject: 'New Payment', |   subject: 'New Payment', | ||||||
|   body: null, |   body: null, | ||||||
| @ -198,9 +254,8 @@ const modalData = computed(() => { | |||||||
| }) | }) | ||||||
|  |  | ||||||
| const rules = { | const rules = { | ||||||
|   from: { |   mail_sender_id: { | ||||||
|     required: helpers.withMessage(t('validation.required'), required), |     required: helpers.withMessage(t('validation.required'), required), | ||||||
|     email: helpers.withMessage(t('validation.email_incorrect'), email), |  | ||||||
|   }, |   }, | ||||||
|   to: { |   to: { | ||||||
|     required: helpers.withMessage(t('validation.required'), required), |     required: helpers.withMessage(t('validation.required'), required), | ||||||
| @ -221,18 +276,25 @@ function cancelPreview() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function setInitialData() { | async function setInitialData() { | ||||||
|   let admin = await companyStore.fetchBasicMailConfig() |  | ||||||
|   paymentMailForm.id = modalStore.id |   paymentMailForm.id = modalStore.id | ||||||
|  |  | ||||||
|   if (admin.data) { |  | ||||||
|     paymentMailForm.from = admin.data.from_mail |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   if (modalData.value) { |   if (modalData.value) { | ||||||
|     paymentMailForm.to = modalData.value.customer.email |     paymentMailForm.to = modalData.value.customer.email | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   paymentMailForm.body = companyStore.selectedCompanySettings.payment_mail_body |   paymentMailForm.body = companyStore.selectedCompanySettings.payment_mail_body | ||||||
|  |  | ||||||
|  |   isFetchingInitialData.value = true | ||||||
|  |   let mailSenderData = await mailSenderStore.fetchMailSenders({ limit: 'all' }) | ||||||
|  |   if (mailSenderData.data) { | ||||||
|  |     mailSenders.value = mailSenderData.data.data | ||||||
|  |     let defaultMailSender = mailSenderData.data.data.find( | ||||||
|  |       (mailSender) => mailSender.is_default == true | ||||||
|  |     ) | ||||||
|  |     paymentMailForm.mail_sender_id = defaultMailSender | ||||||
|  |       ? defaultMailSender.id | ||||||
|  |       : null | ||||||
|  |     isFetchingInitialData.value = false | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function sendPaymentData() { | async function sendPaymentData() { | ||||||
| @ -280,4 +342,18 @@ function closeSendPaymentModal() { | |||||||
|     modalStore.resetModalData() |     modalStore.resetModalData() | ||||||
|   }, 300) |   }, 300) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function getTickImage() { | ||||||
|  |   const imgUrl = new URL('/img/tick.png', import.meta.url) | ||||||
|  |   return imgUrl | ||||||
|  | } | ||||||
|  |  | ||||||
|  | const isMailSenderExist = computed(() => { | ||||||
|  |   return mailSenders.value && mailSenders.value.length | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | function gotoMailSender() { | ||||||
|  |   closeSendPaymentModal() | ||||||
|  |   router.push('/admin/settings/mail-sender') | ||||||
|  | } | ||||||
| </script> | </script> | ||||||
|  | |||||||
| @ -15,13 +15,6 @@ | |||||||
|       bg-gradient-to-r |       bg-gradient-to-r | ||||||
|       from-primary-500 |       from-primary-500 | ||||||
|       to-primary-400 |       to-primary-400 | ||||||
|       dark:from-gray-700/70 dark:to-gray-800/70 |  | ||||||
|       bg-primary-500 |  | ||||||
|       dark:bg-transparent |  | ||||||
|       dark:backdrop-blur-xl |  | ||||||
|       dark:shadow-glass |  | ||||||
|       dark:border |  | ||||||
|       dark:border-white/10 |  | ||||||
|     " |     " | ||||||
|   > |   > | ||||||
|     <router-link |     <router-link | ||||||
| @ -60,7 +53,6 @@ | |||||||
|         cursor-pointer |         cursor-pointer | ||||||
|         md:hidden md:ml-0 |         md:hidden md:ml-0 | ||||||
|         hover:bg-gray-100 |         hover:bg-gray-100 | ||||||
|         dark:bg-gray-800 dark:border-gray-500 dark:border |  | ||||||
|       " |       " | ||||||
|       @click.prevent="onToggle" |       @click.prevent="onToggle" | ||||||
|     > |     > | ||||||
|  | |||||||
| @ -15,9 +15,7 @@ | |||||||
|         leave-from="opacity-100" |         leave-from="opacity-100" | ||||||
|         leave-to="opacity-0" |         leave-to="opacity-0" | ||||||
|       > |       > | ||||||
|         <DialogOverlay |         <DialogOverlay class="fixed inset-0 bg-gray-600 bg-opacity-75" /> | ||||||
|           class="fixed inset-0 bg-gray-600 bg-opacity-75 dark:bg-gray-900/90" |  | ||||||
|         /> |  | ||||||
|       </TransitionChild> |       </TransitionChild> | ||||||
|  |  | ||||||
|       <TransitionChild |       <TransitionChild | ||||||
| @ -29,9 +27,7 @@ | |||||||
|         leave-from="translate-x-0" |         leave-from="translate-x-0" | ||||||
|         leave-to="-translate-x-full" |         leave-to="-translate-x-full" | ||||||
|       > |       > | ||||||
|         <div |         <div class="relative flex flex-col flex-1 w-full max-w-xs bg-white"> | ||||||
|           class="relative flex flex-col flex-1 w-full max-w-xs bg-white dark:bg-gray-800" |  | ||||||
|         > |  | ||||||
|           <TransitionChild |           <TransitionChild | ||||||
|             as="template" |             as="template" | ||||||
|             enter="ease-in-out duration-300" |             enter="ease-in-out duration-300" | ||||||
| @ -44,17 +40,18 @@ | |||||||
|             <div class="absolute top-0 right-0 pt-2 -mr-12"> |             <div class="absolute top-0 right-0 pt-2 -mr-12"> | ||||||
|               <button |               <button | ||||||
|                 class=" |                 class=" | ||||||
|                 flex |                   flex | ||||||
|                 items-center |                   items-center | ||||||
|                 justify-center |                   justify-center | ||||||
|                 w-10 |                   w-10 | ||||||
|                 h-10 |                   h-10 | ||||||
|                 ml-1 |                   ml-1 | ||||||
|                 rounded-full |                   rounded-full | ||||||
|                 focus:outline-none |                   focus:outline-none | ||||||
|                 focus:ring-2 |                   focus:ring-2 | ||||||
|                 focus:ring-inset |                   focus:ring-inset | ||||||
|                 focus:ring-white" |                   focus:ring-white | ||||||
|  |                 " | ||||||
|                 @click="globalStore.setSidebarVisibility(false)" |                 @click="globalStore.setSidebarVisibility(false)" | ||||||
|               > |               > | ||||||
|                 <span class="sr-only">Close sidebar</span> |                 <span class="sr-only">Close sidebar</span> | ||||||
| @ -85,8 +82,8 @@ | |||||||
|                 :to="item.link" |                 :to="item.link" | ||||||
|                 :class="[ |                 :class="[ | ||||||
|                   hasActiveUrl(item.link) |                   hasActiveUrl(item.link) | ||||||
|                     ? 'text-primary-500 border-primary-500 bg-gray-100 dark:shadow-glass dark:backdrop-blur-xl dark:hover:bg-gray-700  dark:bg-gray-700/50 dark:text-primary-400 dark:font-medium' |                     ? 'text-primary-500 border-primary-500 bg-gray-100 ' | ||||||
|                     : 'text-black dark:text-gray-300', |                     : 'text-black', | ||||||
|                   'cursor-pointer px-0 pl-4 py-3 border-transparent flex items-center border-l-4 border-solid text-sm not-italic font-medium', |                   'cursor-pointer px-0 pl-4 py-3 border-transparent flex items-center border-l-4 border-solid text-sm not-italic font-medium', | ||||||
|                 ]" |                 ]" | ||||||
|                 @click="globalStore.setSidebarVisibility(false)" |                 @click="globalStore.setSidebarVisibility(false)" | ||||||
| @ -103,10 +100,6 @@ | |||||||
|                 /> |                 /> | ||||||
|                 {{ $t(item.title) }} |                 {{ $t(item.title) }} | ||||||
|               </router-link> |               </router-link> | ||||||
|               <LightDarkSwitch |  | ||||||
|                 :show-label="false" |  | ||||||
|                 class="absolute right-6 top-6 !w-auto" |  | ||||||
|               /> |  | ||||||
|             </nav> |             </nav> | ||||||
|           </div> |           </div> | ||||||
|         </div> |         </div> | ||||||
| @ -120,16 +113,17 @@ | |||||||
|   <!-- DESKTOP MENU --> |   <!-- DESKTOP MENU --> | ||||||
|   <div |   <div | ||||||
|     class=" |     class=" | ||||||
|     hidden |       hidden | ||||||
|     w-56 |       w-56 | ||||||
|     h-screen |       h-screen | ||||||
|     bg-white |       pb-32 | ||||||
|     border-r border-gray-200 border-solid |       overflow-y-auto | ||||||
|     xl:w-64 |       bg-white | ||||||
|     md:fixed md:flex md:flex-col md:inset-y-0 |       border-r border-gray-200 border-solid | ||||||
|     pt-16 |       xl:w-64 | ||||||
|     dark:border-gray-800 |       md:fixed md:flex md:flex-col md:inset-y-0 | ||||||
|     dark:bg-gray-800/80" |       pt-16 | ||||||
|  |     " | ||||||
|   > |   > | ||||||
|     <div |     <div | ||||||
|       v-for="menu in globalStore.menuGroups" |       v-for="menu in globalStore.menuGroups" | ||||||
| @ -142,8 +136,8 @@ | |||||||
|         :to="item.link" |         :to="item.link" | ||||||
|         :class="[ |         :class="[ | ||||||
|           hasActiveUrl(item.link) |           hasActiveUrl(item.link) | ||||||
|             ? 'text-primary-500 border-primary-500 bg-gray-100 dark:border-primary-400 dark:shadow-glass dark:backdrop-blur-xl dark:hover:bg-gray-700 dark:bg-gray-700/50 dark:text-primary-400 dark:font-medium' |             ? 'text-primary-500 border-primary-500 bg-gray-100 ' | ||||||
|             : 'text-black dark:hover:bg-transparent dark:hover:text-white dark:text-gray-300', |             : 'text-black', | ||||||
|           'cursor-pointer px-0 pl-6 hover:bg-gray-50 py-3 group flex items-center border-l-4 border-solid border-transparent text-sm not-italic font-medium', |           'cursor-pointer px-0 pl-6 hover:bg-gray-50 py-3 group flex items-center border-l-4 border-solid border-transparent text-sm not-italic font-medium', | ||||||
|         ]" |         ]" | ||||||
|       > |       > | ||||||
| @ -151,8 +145,8 @@ | |||||||
|           :name="item.icon" |           :name="item.icon" | ||||||
|           :class="[ |           :class="[ | ||||||
|             hasActiveUrl(item.link) |             hasActiveUrl(item.link) | ||||||
|               ? 'text-primary-500 group-hover:text-primary-500 dark:text-primary-400 dark:group-hover:text-primary-500 ' |               ? 'text-primary-500 group-hover:text-primary-500 ' | ||||||
|               : 'text-gray-400 group-hover:text-black dark:text-gray-400 dark:group-hover:text-white', |               : 'text-gray-400 group-hover:text-black', | ||||||
|             'mr-4 shrink-0 h-5 w-5 ', |             'mr-4 shrink-0 h-5 w-5 ', | ||||||
|           ]" |           ]" | ||||||
|         /> |         /> | ||||||
| @ -160,9 +154,6 @@ | |||||||
|         {{ $t(item.title) }} |         {{ $t(item.title) }} | ||||||
|       </router-link> |       </router-link> | ||||||
|     </div> |     </div> | ||||||
|     <LightDarkSwitch |  | ||||||
|       class="absolute bottom-0 py-4 border-t border-gray-200 dark:border-gray-700" |  | ||||||
|     /> |  | ||||||
|   </div> |   </div> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| @ -178,7 +169,6 @@ import { | |||||||
|  |  | ||||||
| import { useRoute } from 'vue-router' | import { useRoute } from 'vue-router' | ||||||
| import { useGlobalStore } from '@/scripts/admin/stores/global' | import { useGlobalStore } from '@/scripts/admin/stores/global' | ||||||
| import LightDarkSwitch from '@/scripts/components/LightDarkSwitcher.vue' |  | ||||||
|  |  | ||||||
| const route = useRoute() | const route = useRoute() | ||||||
| const globalStore = useGlobalStore() | const globalStore = useGlobalStore() | ||||||
|  | |||||||
| @ -184,20 +184,6 @@ export const useCompanyStore = (useWindow = false) => { | |||||||
|       setDefaultCurrency(data) { |       setDefaultCurrency(data) { | ||||||
|         this.defaultCurrency = data.currency |         this.defaultCurrency = data.currency | ||||||
|       }, |       }, | ||||||
|  |  | ||||||
|       checkCompanyHasCurrencyTransactions() { |  | ||||||
|         return new Promise((resolve, reject) => { |  | ||||||
|           axios |  | ||||||
|             .get(`/api/v1/company/has-transactions`) |  | ||||||
|             .then((response) => { |  | ||||||
|               resolve(response) |  | ||||||
|             }) |  | ||||||
|             .catch((err) => { |  | ||||||
|               handleError(err) |  | ||||||
|               reject(err) |  | ||||||
|             }) |  | ||||||
|         }) |  | ||||||
|       }, |  | ||||||
|     }, |     }, | ||||||
|   })() |   })() | ||||||
| } | } | ||||||
|  | |||||||
| @ -34,7 +34,6 @@ export const useGlobalStore = (useWindow = false) => { | |||||||
|       isAppLoaded: false, |       isAppLoaded: false, | ||||||
|       isSidebarOpen: false, |       isSidebarOpen: false, | ||||||
|       areCurrenciesLoading: false, |       areCurrenciesLoading: false, | ||||||
|       isDarkModeOn: false, |  | ||||||
|  |  | ||||||
|       downloadReport: null, |       downloadReport: null, | ||||||
|     }), |     }), | ||||||
| @ -71,8 +70,8 @@ export const useGlobalStore = (useWindow = false) => { | |||||||
|               moduleStore.apiToken = response.data.global_settings.api_token |               moduleStore.apiToken = response.data.global_settings.api_token | ||||||
|               moduleStore.enableModules = response.data.modules |               moduleStore.enableModules = response.data.modules | ||||||
|  |  | ||||||
|               // company store |                 // company store | ||||||
|               companyStore.companies = response.data.companies |                 companyStore.companies = response.data.companies | ||||||
|               companyStore.selectedCompany = response.data.current_company |               companyStore.selectedCompany = response.data.current_company | ||||||
|               companyStore.setSelectedCompany(response.data.current_company) |               companyStore.setSelectedCompany(response.data.current_company) | ||||||
|               companyStore.selectedCompanySettings = |               companyStore.selectedCompanySettings = | ||||||
|  | |||||||
| @ -1,146 +0,0 @@ | |||||||
| import axios from 'axios' |  | ||||||
| import { defineStore } from 'pinia' |  | ||||||
| import { useNotificationStore } from '@/scripts/stores/notification' |  | ||||||
| import { handleError } from '@/scripts/helpers/error-handling' |  | ||||||
|  |  | ||||||
| export const useMailDriverStore = (useWindow = false) => { |  | ||||||
|   const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore |  | ||||||
|   const { global } = window.i18n |  | ||||||
|  |  | ||||||
|   return defineStoreFunc({ |  | ||||||
|     id: 'mail-driver', |  | ||||||
|  |  | ||||||
|     state: () => ({ |  | ||||||
|       mailConfigData: null, |  | ||||||
|       mail_driver: 'smtp', |  | ||||||
|       mail_drivers: [], |  | ||||||
|  |  | ||||||
|       basicMailConfig: { |  | ||||||
|         mail_driver: '', |  | ||||||
|         mail_host: '', |  | ||||||
|         from_mail: '', |  | ||||||
|         from_name: '', |  | ||||||
|       }, |  | ||||||
|  |  | ||||||
|       mailgunConfig: { |  | ||||||
|         mail_driver: '', |  | ||||||
|         mail_mailgun_domain: '', |  | ||||||
|         mail_mailgun_secret: '', |  | ||||||
|         mail_mailgun_endpoint: '', |  | ||||||
|         from_mail: '', |  | ||||||
|         from_name: '', |  | ||||||
|       }, |  | ||||||
|  |  | ||||||
|       sesConfig: { |  | ||||||
|         mail_driver: '', |  | ||||||
|         mail_host: '', |  | ||||||
|         mail_port: null, |  | ||||||
|         mail_ses_key: '', |  | ||||||
|         mail_ses_secret: '', |  | ||||||
|         mail_encryption: 'tls', |  | ||||||
|         from_mail: '', |  | ||||||
|         from_name: '', |  | ||||||
|       }, |  | ||||||
|  |  | ||||||
|       smtpConfig: { |  | ||||||
|         mail_driver: '', |  | ||||||
|         mail_host: '', |  | ||||||
|         mail_port: null, |  | ||||||
|         mail_username: '', |  | ||||||
|         mail_password: '', |  | ||||||
|         mail_encryption: 'tls', |  | ||||||
|         from_mail: '', |  | ||||||
|         from_name: '', |  | ||||||
|       }, |  | ||||||
|     }), |  | ||||||
|  |  | ||||||
|     actions: { |  | ||||||
|       fetchMailDrivers() { |  | ||||||
|         return new Promise((resolve, reject) => { |  | ||||||
|           axios |  | ||||||
|             .get('/api/v1/mail/drivers') |  | ||||||
|             .then((response) => { |  | ||||||
|               if (response.data) { |  | ||||||
|                 this.mail_drivers = response.data |  | ||||||
|               } |  | ||||||
|               resolve(response) |  | ||||||
|             }) |  | ||||||
|             .catch((err) => { |  | ||||||
|               handleError(err) |  | ||||||
|               reject(err) |  | ||||||
|             }) |  | ||||||
|         }) |  | ||||||
|       }, |  | ||||||
|  |  | ||||||
|       fetchMailConfig() { |  | ||||||
|         return new Promise((resolve, reject) => { |  | ||||||
|           axios |  | ||||||
|             .get('/api/v1/mail/config') |  | ||||||
|             .then((response) => { |  | ||||||
|               if (response.data) { |  | ||||||
|                 this.mailConfigData = response.data |  | ||||||
|                 this.mail_driver = response.data.mail_driver |  | ||||||
|               } |  | ||||||
|               resolve(response) |  | ||||||
|             }) |  | ||||||
|             .catch((err) => { |  | ||||||
|               handleError(err) |  | ||||||
|               reject(err) |  | ||||||
|             }) |  | ||||||
|         }) |  | ||||||
|       }, |  | ||||||
|  |  | ||||||
|       updateMailConfig(data) { |  | ||||||
|         return new Promise((resolve, reject) => { |  | ||||||
|           axios |  | ||||||
|             .post('/api/v1/mail/config', data) |  | ||||||
|             .then((response) => { |  | ||||||
|               const notificationStore = useNotificationStore() |  | ||||||
|               if (response.data.success) { |  | ||||||
|                 notificationStore.showNotification({ |  | ||||||
|                   type: 'success', |  | ||||||
|                   message: global.t('wizard.success.' + response.data.success), |  | ||||||
|                 }) |  | ||||||
|               } else { |  | ||||||
|                 notificationStore.showNotification({ |  | ||||||
|                   type: 'error', |  | ||||||
|                   message: global.t('wizard.errors.' + response.data.error), |  | ||||||
|                 }) |  | ||||||
|               } |  | ||||||
|               resolve(response) |  | ||||||
|             }) |  | ||||||
|             .catch((err) => { |  | ||||||
|               handleError(err) |  | ||||||
|               reject(err) |  | ||||||
|             }) |  | ||||||
|         }) |  | ||||||
|       }, |  | ||||||
|  |  | ||||||
|       sendTestMail(data) { |  | ||||||
|         return new Promise((resolve, reject) => { |  | ||||||
|           axios |  | ||||||
|             .post('/api/v1/mail/test', data) |  | ||||||
|             .then((response) => { |  | ||||||
|               const notificationStore = useNotificationStore() |  | ||||||
|               if (response.data.success) { |  | ||||||
|                 notificationStore.showNotification({ |  | ||||||
|                   type: 'success', |  | ||||||
|                   message: global.t('general.send_mail_successfully'), |  | ||||||
|                 }) |  | ||||||
|               } else { |  | ||||||
|                 notificationStore.showNotification({ |  | ||||||
|                   type: 'error', |  | ||||||
|                   message: global.t('validation.something_went_wrong'), |  | ||||||
|                 }) |  | ||||||
|               } |  | ||||||
|               resolve(response) |  | ||||||
|             }) |  | ||||||
|             .catch((err) => { |  | ||||||
|               handleError(err) |  | ||||||
|               reject(err) |  | ||||||
|             }) |  | ||||||
|         }) |  | ||||||
|       }, |  | ||||||
|     }, |  | ||||||
|   })() |  | ||||||
| } |  | ||||||
							
								
								
									
										202
									
								
								resources/scripts/admin/stores/mail-sender.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								resources/scripts/admin/stores/mail-sender.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,202 @@ | |||||||
|  | import axios from 'axios' | ||||||
|  | import { defineStore } from 'pinia' | ||||||
|  | import { useNotificationStore } from '@/scripts/stores/notification' | ||||||
|  | import { handleError } from '@/scripts/helpers/error-handling' | ||||||
|  | import mailSenderStub from '@/scripts/admin/stub/mail-sender.js' | ||||||
|  |  | ||||||
|  | export const useMailSenderStore = (useWindow = false) => { | ||||||
|  |   const pre_t = 'settings.mail_sender' | ||||||
|  |   const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore | ||||||
|  |   const { global } = window.i18n | ||||||
|  |  | ||||||
|  |   return defineStoreFunc({ | ||||||
|  |     id: 'mailSender', | ||||||
|  |  | ||||||
|  |     state: () => ({ | ||||||
|  |       mailSenders: [], | ||||||
|  |       mail_drivers: [], // list of mail drivers | ||||||
|  |       currentMailSender: { ...mailSenderStub.basicConfig }, | ||||||
|  |       smtpConfig: { ...mailSenderStub.smtpConfig }, | ||||||
|  |       mailgunConfig: { ...mailSenderStub.mailgunConfig }, | ||||||
|  |       sesConfig: { ...mailSenderStub.sesConfig }, | ||||||
|  |       mail_encryptions: ['none', 'tls', 'ssl', 'starttls'], | ||||||
|  |       isDisable: false | ||||||
|  |     }), | ||||||
|  |  | ||||||
|  |     getters: { | ||||||
|  |       isEdit: (state) => (state.currentMailSender.id ? true : false), | ||||||
|  |     }, | ||||||
|  |  | ||||||
|  |     actions: { | ||||||
|  |       resetCurrentMailSender() { | ||||||
|  |         this.currentMailSender = { ...mailSenderStub.basicConfig } | ||||||
|  |         this.smtpConfig = { ...mailSenderStub.smtpConfig } | ||||||
|  |         this.mailgunConfig = { ...mailSenderStub.mailgunConfig } | ||||||
|  |         this.sesConfig = { ...mailSenderStub.sesConfig } | ||||||
|  |         this.isDisable = false | ||||||
|  |       }, | ||||||
|  |  | ||||||
|  |       fetchMailDrivers() { | ||||||
|  |         return new Promise((resolve, reject) => { | ||||||
|  |           axios | ||||||
|  |             .get('/api/v1/mail-drivers') | ||||||
|  |             .then((response) => { | ||||||
|  |               if (response.data) { | ||||||
|  |                 this.mail_drivers = response.data | ||||||
|  |               } | ||||||
|  |               resolve(response) | ||||||
|  |             }) | ||||||
|  |             .catch((err) => { | ||||||
|  |               handleError(err) | ||||||
|  |               reject(err) | ||||||
|  |             }) | ||||||
|  |         }) | ||||||
|  |       }, | ||||||
|  |  | ||||||
|  |  | ||||||
|  |       fetchMailSenders(params) { | ||||||
|  |         return new Promise((resolve, reject) => { | ||||||
|  |           axios | ||||||
|  |             .get(`/api/v1/mail-senders`, { params }) | ||||||
|  |             .then((response) => { | ||||||
|  |               this.mailSenders = response.data.data | ||||||
|  |               resolve(response) | ||||||
|  |             }) | ||||||
|  |             .catch((err) => { | ||||||
|  |               handleError(err) | ||||||
|  |               reject(err) | ||||||
|  |             }) | ||||||
|  |         }) | ||||||
|  |       }, | ||||||
|  |  | ||||||
|  |       fetchMailSender(id) { | ||||||
|  |         return new Promise((resolve, reject) => { | ||||||
|  |           axios | ||||||
|  |             .get(`/api/v1/mail-senders/${id}`) | ||||||
|  |             .then((response) => { | ||||||
|  |               this.currentMailSender = response.data.data | ||||||
|  |               this.isDisable = response.data.data.is_default | ||||||
|  |               if (response.data.data.settings) { | ||||||
|  |                 var settings = response.data.data.settings | ||||||
|  |                 const encryptionNone = settings.encryption == '' || settings.encryption == undefined | ||||||
|  |                 switch (response.data.data.driver) { | ||||||
|  |                   case 'smtp': | ||||||
|  |                     this.smtpConfig = settings | ||||||
|  |                     encryptionNone ? this.smtpConfig.encryption = 'none' : '' | ||||||
|  |                     break | ||||||
|  |                   case 'mailgun': | ||||||
|  |                     this.mailgunConfig = settings | ||||||
|  |                     break | ||||||
|  |                   case 'ses': | ||||||
|  |                     this.sesConfig = settings | ||||||
|  |                     encryptionNone ? this.sesConfig.encryption = 'none' : '' | ||||||
|  |                     break | ||||||
|  |                 } | ||||||
|  |               } | ||||||
|  |               resolve(response) | ||||||
|  |             }) | ||||||
|  |             .catch((err) => { | ||||||
|  |               handleError(err) | ||||||
|  |               reject(err) | ||||||
|  |             }) | ||||||
|  |         }) | ||||||
|  |       }, | ||||||
|  |  | ||||||
|  |       addMailSender(data) { | ||||||
|  |         const notificationStore = useNotificationStore() | ||||||
|  |         return new Promise((resolve, reject) => { | ||||||
|  |           axios | ||||||
|  |             .post('/api/v1/mail-senders', data) | ||||||
|  |             .then((response) => { | ||||||
|  |               this.mailSenders.push(response.data.data) | ||||||
|  |               notificationStore.showNotification({ | ||||||
|  |                 type: 'success', | ||||||
|  |                 message: global.t(`${pre_t}.created_message`), | ||||||
|  |               }) | ||||||
|  |               resolve(response) | ||||||
|  |             }) | ||||||
|  |             .catch((err) => { | ||||||
|  |               handleError(err) | ||||||
|  |               reject(err) | ||||||
|  |             }) | ||||||
|  |         }) | ||||||
|  |       }, | ||||||
|  |  | ||||||
|  |       updateMailSender(data) { | ||||||
|  |         const notificationStore = useNotificationStore() | ||||||
|  |         return new Promise((resolve, reject) => { | ||||||
|  |           axios | ||||||
|  |             .put(`/api/v1/mail-senders/${data.id}`, data) | ||||||
|  |             .then((response) => { | ||||||
|  |               if (response.data) { | ||||||
|  |                 let pos = this.mailSenders.findIndex( | ||||||
|  |                   (mailSender) => mailSender.id === response.data.data.id | ||||||
|  |                 ) | ||||||
|  |                 this.mailSenders[pos] = data | ||||||
|  |                 notificationStore.showNotification({ | ||||||
|  |                   type: 'success', | ||||||
|  |                   message: global.t(`${pre_t}.updated_message`), | ||||||
|  |                 }) | ||||||
|  |               } | ||||||
|  |               resolve(response) | ||||||
|  |             }) | ||||||
|  |             .catch((err) => { | ||||||
|  |               handleError(err) | ||||||
|  |               reject(err) | ||||||
|  |             }) | ||||||
|  |         }) | ||||||
|  |       }, | ||||||
|  |  | ||||||
|  |       deleteMailSender(id) { | ||||||
|  |         return new Promise((resolve, reject) => { | ||||||
|  |           axios | ||||||
|  |             .delete(`/api/v1/mail-senders/${id}`) | ||||||
|  |             .then((response) => { | ||||||
|  |               if (response.data.success) { | ||||||
|  |                 let index = this.mailSenders.findIndex( | ||||||
|  |                   (mailSender) => mailSender.id === id | ||||||
|  |                 ) | ||||||
|  |                 this.mailSenders.splice(index, 1) | ||||||
|  |                 const notificationStore = useNotificationStore() | ||||||
|  |                 notificationStore.showNotification({ | ||||||
|  |                   type: 'success', | ||||||
|  |                   message: global.t(`${pre_t}.deleted_message`), | ||||||
|  |                 }) | ||||||
|  |               } | ||||||
|  |               resolve(response) | ||||||
|  |             }) | ||||||
|  |             .catch((err) => { | ||||||
|  |               handleError(err) | ||||||
|  |               reject(err) | ||||||
|  |             }) | ||||||
|  |         }) | ||||||
|  |       }, | ||||||
|  |  | ||||||
|  |       sendTestMail(data) { | ||||||
|  |         return new Promise((resolve, reject) => { | ||||||
|  |           axios | ||||||
|  |             .post('/api/v1/mail-test', data) | ||||||
|  |             .then((response) => { | ||||||
|  |               const notificationStore = useNotificationStore() | ||||||
|  |               if (response.data.success) { | ||||||
|  |                 notificationStore.showNotification({ | ||||||
|  |                   type: 'success', | ||||||
|  |                   message: global.t('general.send_mail_successfully'), | ||||||
|  |                 }) | ||||||
|  |               } else { | ||||||
|  |                 notificationStore.showNotification({ | ||||||
|  |                   type: 'error', | ||||||
|  |                   message: global.t('validation.something_went_wrong'), | ||||||
|  |                 }) | ||||||
|  |               } | ||||||
|  |               resolve(response) | ||||||
|  |             }) | ||||||
|  |             .catch((err) => { | ||||||
|  |               handleError(err) | ||||||
|  |               reject(err) | ||||||
|  |             }) | ||||||
|  |         }) | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |   })() | ||||||
|  | } | ||||||
| @ -25,6 +25,7 @@ export const useUsersStore = (useWindow = false) => { | |||||||
|         password: null, |         password: null, | ||||||
|         phone: null, |         phone: null, | ||||||
|         companies: [], |         companies: [], | ||||||
|  |         sender_id: null, | ||||||
|       }, |       }, | ||||||
|     }), |     }), | ||||||
|  |  | ||||||
|  | |||||||
| @ -64,6 +64,13 @@ export default { | |||||||
|   EDIT_ROLE: 'edit-role', |   EDIT_ROLE: 'edit-role', | ||||||
|   VIEW_ROLE: 'view-role', |   VIEW_ROLE: 'view-role', | ||||||
|  |  | ||||||
|  |   // Mail Sender | ||||||
|  |   CREATE_MAIL_SENDER: 'view-mail-sender', | ||||||
|  |   DELETE_MAIL_SENDER: 'delete-mail-sender', | ||||||
|  |   EDIT_MAIL_SENDER: 'edit-mail-sender', | ||||||
|  |   VIEW_MAIL_SENDER: 'view-mail-sender', | ||||||
|  |  | ||||||
|  |  | ||||||
|   // exchange rates |   // exchange rates | ||||||
|   VIEW_EXCHANGE_RATE: 'view-exchange-rate-provider', |   VIEW_EXCHANGE_RATE: 'view-exchange-rate-provider', | ||||||
|   CREATE_EXCHANGE_RATE: 'create-exchange-rate-provider', |   CREATE_EXCHANGE_RATE: 'create-exchange-rate-provider', | ||||||
|  | |||||||
| @ -15,5 +15,6 @@ export default function () { | |||||||
|     customFields: [], |     customFields: [], | ||||||
|     fields: [], |     fields: [], | ||||||
|     enable_portal: false, |     enable_portal: false, | ||||||
|  |     mail_sender_id: null, | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										31
									
								
								resources/scripts/admin/stub/mail-sender.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								resources/scripts/admin/stub/mail-sender.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | |||||||
|  | export default { | ||||||
|  |   basicConfig: { | ||||||
|  |     name: '', | ||||||
|  |     from_name: '', | ||||||
|  |     from_address: '', | ||||||
|  |     cc: '', | ||||||
|  |     bcc: '', | ||||||
|  |     is_default: false, | ||||||
|  |     driver: 'smtp', // 'smtp', 'mail', 'sendmail', 'mailgun', 'ses' | ||||||
|  |     settings: '', | ||||||
|  |   }, | ||||||
|  |   smtpConfig: { | ||||||
|  |     host: '', | ||||||
|  |     port: null, | ||||||
|  |     username: '', | ||||||
|  |     password: '', | ||||||
|  |     encryption: 'tls', // 'tls', 'ssl', 'starttls' | ||||||
|  |   }, | ||||||
|  |   mailgunConfig: { | ||||||
|  |     domain: '', | ||||||
|  |     secret: '', | ||||||
|  |     endpoint: '', | ||||||
|  |   }, | ||||||
|  |   sesConfig: { | ||||||
|  |     host: '', | ||||||
|  |     port: null, | ||||||
|  |     encryption: 'tls', // 'tls', 'ssl', 'starttls' | ||||||
|  |     ses_key: '', | ||||||
|  |     ses_secret: '', | ||||||
|  |   }, | ||||||
|  | } | ||||||
| @ -256,6 +256,7 @@ | |||||||
|                   /> </template |                   /> </template | ||||||
|               ></BaseInput> |               ></BaseInput> | ||||||
|             </BaseInputGroup> |             </BaseInputGroup> | ||||||
|  |             <!-- && setPasswordMethod !== 'manual' --> | ||||||
|           </BaseInputGrid> |           </BaseInputGrid> | ||||||
|         </div> |         </div> | ||||||
|  |  | ||||||
| @ -650,10 +651,7 @@ const rules = computed(() => { | |||||||
|       }, |       }, | ||||||
|  |  | ||||||
|       email: { |       email: { | ||||||
|         required: helpers.withMessage( |         required: helpers.withMessage(t('validation.required'), required), | ||||||
|           t('validation.required'), |  | ||||||
|           requiredIf(customerStore.currentCustomer.enable_portal == true) |  | ||||||
|         ), |  | ||||||
|         email: helpers.withMessage(t('validation.email_incorrect'), email), |         email: helpers.withMessage(t('validation.email_incorrect'), email), | ||||||
|       }, |       }, | ||||||
|       password: { |       password: { | ||||||
|  | |||||||
| @ -32,8 +32,6 @@ | |||||||
|           :content-loading="isLoading" |           :content-loading="isLoading" | ||||||
|           :calendar-button="true" |           :calendar-button="true" | ||||||
|           calendar-button-icon="calendar" |           calendar-button-icon="calendar" | ||||||
|           :show-extra-options="true" |  | ||||||
|           :source-date="estimateStore.newEstimate.estimate_date" |  | ||||||
|         /> |         /> | ||||||
|       </BaseInputGroup> |       </BaseInputGroup> | ||||||
|  |  | ||||||
|  | |||||||
| @ -3,75 +3,238 @@ | |||||||
|     :title="$t('wizard.mail.mail_config')" |     :title="$t('wizard.mail.mail_config')" | ||||||
|     :description="$t('wizard.mail.mail_config_desc')" |     :description="$t('wizard.mail.mail_config_desc')" | ||||||
|   > |   > | ||||||
|     <form action="" @submit.prevent="next"> |     <form action="" @submit.prevent="submitMailSenderData"> | ||||||
|       <component |       <div class="p-4 sm:p-6 my-2"> | ||||||
|         :is="mailDriverStore.mail_driver" |         <!-- Name --> | ||||||
|         :config-data="mailDriverStore.mailConfigData" |         <BaseInputGrid> | ||||||
|         :is-saving="isSaving" |           <BaseInputGroup | ||||||
|         :is-fetching-initial-data="isFetchingInitialData" |             :label="$t(`${pre_t}.name`)" | ||||||
|         @on-change-driver="(val) => changeDriver(val)" |             :error="v$.name.$error && v$.name.$errors[0].$message" | ||||||
|         @submit-data="next" |             :help-text="$t(`${pre_t}.name_help`)" | ||||||
|       /> |             required | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model.trim="mailSenderStore.currentMailSender.name" | ||||||
|  |               :invalid="v$.name.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.name.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- From Name --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.from_name`)" | ||||||
|  |             :error="v$.from_name.$error && v$.from_name.$errors[0].$message" | ||||||
|  |             required | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="mailSenderStore.currentMailSender.from_name" | ||||||
|  |               :invalid="v$.from_name.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.from_name.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- From Address --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.from_address`)" | ||||||
|  |             :error=" | ||||||
|  |               v$.from_address.$error && v$.from_address.$errors[0].$message | ||||||
|  |             " | ||||||
|  |             required | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="mailSenderStore.currentMailSender.from_address" | ||||||
|  |               :invalid="v$.from_address.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.from_address.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- CC --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.cc`)" | ||||||
|  |             :error="v$.cc.$error && v$.cc.$errors[0].$message" | ||||||
|  |             :help-text="$t(`${pre_t}.email_list`)" | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="mailSenderStore.currentMailSender.cc" | ||||||
|  |               :invalid="v$.cc.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.cc.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- BCC --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.bcc`)" | ||||||
|  |             :error="v$.bcc.$error && v$.bcc.$errors[0].$message" | ||||||
|  |             :help-text="$t(`${pre_t}.email_list`)" | ||||||
|  |           > | ||||||
|  |             <BaseInput | ||||||
|  |               v-model="mailSenderStore.currentMailSender.bcc" | ||||||
|  |               :invalid="v$.bcc.$error" | ||||||
|  |               type="text" | ||||||
|  |               @input="v$.bcc.$touch()" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <!-- Mail Driver --> | ||||||
|  |           <BaseInputGroup | ||||||
|  |             :label="$t(`${pre_t}.driver`)" | ||||||
|  |             :error="v$.driver.$error && v$.driver.$errors[0].$message" | ||||||
|  |             required | ||||||
|  |           > | ||||||
|  |             <BaseMultiselect | ||||||
|  |               v-model="mailSenderStore.currentMailSender.driver" | ||||||
|  |               :options="mailSenderStore.mail_drivers" | ||||||
|  |               :can-deselect="false" | ||||||
|  |               :invalid="v$.driver.$error" | ||||||
|  |             /> | ||||||
|  |           </BaseInputGroup> | ||||||
|  |  | ||||||
|  |           <component | ||||||
|  |             :is="loadMailDriver" | ||||||
|  |             :mail-sender-store="mailSenderStore" | ||||||
|  |           /> | ||||||
|  |         </BaseInputGrid> | ||||||
|  |         <BaseDivider class="my-4" /> | ||||||
|  |  | ||||||
|  |         <BaseButton | ||||||
|  |           :loading="isSaving" | ||||||
|  |           :disabled="isSaving" | ||||||
|  |           variant="primary" | ||||||
|  |           type="submit" | ||||||
|  |         > | ||||||
|  |           <template #left="slotProps"> | ||||||
|  |             <BaseIcon | ||||||
|  |               v-if="!isSaving" | ||||||
|  |               name="SaveIcon" | ||||||
|  |               :class="slotProps.class" | ||||||
|  |             /> | ||||||
|  |           </template> | ||||||
|  |           {{ $t('wizard.save_cont') }} | ||||||
|  |         </BaseButton> | ||||||
|  |       </div> | ||||||
|     </form> |     </form> | ||||||
|   </BaseWizardStep> |   </BaseWizardStep> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script> | <script setup> | ||||||
| import Smtp from './mail-driver/SmtpMailDriver.vue' | import { computed, ref, inject, onMounted } from 'vue' | ||||||
| import Mailgun from './mail-driver/MailgunMailDriver.vue' | import { useI18n } from 'vue-i18n' | ||||||
| import Ses from './mail-driver/SesMailDriver.vue' | import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender' | ||||||
| import Basic from './mail-driver/BasicMailDriver.vue' | import { useVuelidate } from '@vuelidate/core' | ||||||
| import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver' | import { required, email, minLength, helpers } from '@vuelidate/validators' | ||||||
| import { ref } from 'vue' | import MailSenderDropdown from '@/scripts/admin/components/dropdowns/MailSenderIndexDropdown.vue' | ||||||
|  | import MailSenderTestModal from '@/scripts/admin/components/modal-components/MailSenderTestModal.vue' | ||||||
|  | import SmtpDriver from '@/scripts/admin/views/settings/mail-sender/SmtpDriver.vue' | ||||||
|  | import MailgunDriver from '@/scripts/admin/views/settings/mail-sender/MailgunDriver.vue' | ||||||
|  | import SesDriver from '@/scripts/admin/views/settings/mail-sender/SesDriver.vue' | ||||||
|  |  | ||||||
| export default { | const pre_t = 'settings.mail_sender' | ||||||
|   components: { | const mailSenderStore = useMailSenderStore() | ||||||
|     Smtp, | const { t } = useI18n() | ||||||
|     Mailgun, | const table = ref(null) | ||||||
|     Ses, | const utils = inject('utils') | ||||||
|     sendmail: Basic, | let isSaving = ref(false) | ||||||
|     Mail: Basic, | const emit = defineEmits(['next']) | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   emits: ['next'], | const loadMailDriver = computed(() => { | ||||||
|  |   switch (mailSenderStore.currentMailSender.driver) { | ||||||
|  |     case 'smtp': | ||||||
|  |       return SmtpDriver | ||||||
|  |       break | ||||||
|  |     case 'mail': | ||||||
|  |       return false | ||||||
|  |       break | ||||||
|  |     case 'sendmail': | ||||||
|  |       return false | ||||||
|  |       break | ||||||
|  |     case 'mailgun': | ||||||
|  |       return MailgunDriver | ||||||
|  |       break | ||||||
|  |     case 'ses': | ||||||
|  |       return SesDriver | ||||||
|  |       break | ||||||
|  |     default: | ||||||
|  |       return false | ||||||
|  |   } | ||||||
|  | }) | ||||||
|  |  | ||||||
|   setup(props, { emit }) { | // This is multiple email custom validation | ||||||
|     const isSaving = ref(false) | const multiEmail = (value) => { | ||||||
|     const isFetchingInitialData = ref(false) |   if (value == '' || value === null) return true | ||||||
|  |   const emailRegex = | ||||||
|  |     /^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i | ||||||
|  |  | ||||||
|     const mailDriverStore = useMailDriverStore() |   const emailArr = value.split(',') | ||||||
|  |   let isValid = emailArr.every((v) => { | ||||||
|     mailDriverStore.mail_driver = 'mail' |     return emailRegex.test(v) | ||||||
|  |   }) | ||||||
|     loadData() |   return isValid | ||||||
|  |  | ||||||
|     function changeDriver(value) { |  | ||||||
|       mailDriverStore.mail_driver = value |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     async function loadData() { |  | ||||||
|       isFetchingInitialData.value = true |  | ||||||
|       await mailDriverStore.fetchMailDrivers() |  | ||||||
|       isFetchingInitialData.value = false |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     async function next(mailConfigData) { |  | ||||||
|       isSaving.value = true |  | ||||||
|       let res = await mailDriverStore.updateMailConfig(mailConfigData) |  | ||||||
|       isSaving.value = false |  | ||||||
|  |  | ||||||
|       if (res.data.success) { |  | ||||||
|         await emit('next', 5) |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return { |  | ||||||
|       mailDriverStore, |  | ||||||
|       isSaving, |  | ||||||
|       isFetchingInitialData, |  | ||||||
|       changeDriver, |  | ||||||
|       next, |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | const rules = computed(() => { | ||||||
|  |   return { | ||||||
|  |     name: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |       minLength: helpers.withMessage( | ||||||
|  |         t('validation.name_min_length', { count: 3 }), | ||||||
|  |         minLength(3) | ||||||
|  |       ), | ||||||
|  |     }, | ||||||
|  |     from_name: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |     from_address: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |       email: helpers.withMessage(t('validation.email_incorrect'), email), | ||||||
|  |     }, | ||||||
|  |     cc: { | ||||||
|  |       multiEmail: helpers.withMessage( | ||||||
|  |         t('validation.email_incorrect'), | ||||||
|  |         multiEmail | ||||||
|  |       ), | ||||||
|  |     }, | ||||||
|  |     bcc: { | ||||||
|  |       multiEmail: helpers.withMessage( | ||||||
|  |         t('validation.email_incorrect'), | ||||||
|  |         multiEmail | ||||||
|  |       ), | ||||||
|  |     }, | ||||||
|  |     driver: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |   } | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const v$ = useVuelidate( | ||||||
|  |   rules, | ||||||
|  |   computed(() => mailSenderStore.currentMailSender) | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | async function submitMailSenderData() { | ||||||
|  |   v$.value.$touch() | ||||||
|  |   if (v$.value.$invalid) { | ||||||
|  |     return true | ||||||
|  |   } | ||||||
|  |   try { | ||||||
|  |     let data = { | ||||||
|  |       ...mailSenderStore.currentMailSender, | ||||||
|  |       is_default: true, | ||||||
|  |     } | ||||||
|  |     await mailSenderStore.addMailSender(data) | ||||||
|  |     isSaving.value = true | ||||||
|  |     emit('next') | ||||||
|  |     isSaving.value = false | ||||||
|  |   } catch (err) { | ||||||
|  |     isSaving.value = false | ||||||
|  |     return true | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | onMounted(async () => { | ||||||
|  |   await mailSenderStore.fetchMailDrivers() | ||||||
|  | }) | ||||||
| </script> | </script> | ||||||
|  | |||||||
| @ -34,24 +34,6 @@ | |||||||
|           /> |           /> | ||||||
|         </BaseInputGroup> |         </BaseInputGroup> | ||||||
|  |  | ||||||
|         <BaseInputGroup |  | ||||||
|           :label="$tc('wizard.company_slug')" |  | ||||||
|           :help-text="$t('wizard.company_slug_help_text')" |  | ||||||
|           :error=" |  | ||||||
|             v$.companyForm.slug.$error && |  | ||||||
|             v$.companyForm.slug.$errors[0].$message |  | ||||||
|           " |  | ||||||
|           required |  | ||||||
|         > |  | ||||||
|           <BaseInput |  | ||||||
|             v-model="companyForm.slug" |  | ||||||
|             :invalid="v$.companyForm.slug.$error" |  | ||||||
|             type="text" |  | ||||||
|             name="slug" |  | ||||||
|             @input="v$.companyForm.slug.$touch()" |  | ||||||
|           /> |  | ||||||
|         </BaseInputGroup> |  | ||||||
|  |  | ||||||
|         <BaseInputGroup |         <BaseInputGroup | ||||||
|           :label="$t('wizard.country')" |           :label="$t('wizard.country')" | ||||||
|           :error=" |           :error=" | ||||||
| @ -75,7 +57,9 @@ | |||||||
|             track-by="name" |             track-by="name" | ||||||
|           /> |           /> | ||||||
|         </BaseInputGroup> |         </BaseInputGroup> | ||||||
|  |       </div> | ||||||
|  |  | ||||||
|  |       <div class="grid grid-cols-1 gap-4 mb-4 md:grid-cols-2 md:mb-6"> | ||||||
|         <BaseInputGroup :label="$t('wizard.state')"> |         <BaseInputGroup :label="$t('wizard.state')"> | ||||||
|           <BaseInput |           <BaseInput | ||||||
|             v-model="companyForm.address.state" |             v-model="companyForm.address.state" | ||||||
| @ -160,9 +144,9 @@ | |||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script setup> | <script setup> | ||||||
| import { ref, computed, onMounted, reactive, watch } from 'vue' | import { ref, computed, onMounted, reactive } from 'vue' | ||||||
| import { useI18n } from 'vue-i18n' | import { useI18n } from 'vue-i18n' | ||||||
| import { required, minLength, maxLength, helpers } from '@vuelidate/validators' | import { required, maxLength, helpers } from '@vuelidate/validators' | ||||||
| import { useVuelidate } from '@vuelidate/core' | import { useVuelidate } from '@vuelidate/core' | ||||||
| import { useGlobalStore } from '@/scripts/admin/stores/global' | import { useGlobalStore } from '@/scripts/admin/stores/global' | ||||||
| import { useCompanyStore } from '@/scripts/admin/stores/company' | import { useCompanyStore } from '@/scripts/admin/stores/company' | ||||||
| @ -178,7 +162,6 @@ let logoFileName = ref(null) | |||||||
|  |  | ||||||
| const companyForm = reactive({ | const companyForm = reactive({ | ||||||
|   name: null, |   name: null, | ||||||
|   slug: null, |  | ||||||
|   address: { |   address: { | ||||||
|     address_street_1: '', |     address_street_1: '', | ||||||
|     address_street_2: '', |     address_street_2: '', | ||||||
| @ -205,28 +188,10 @@ onMounted(async () => { | |||||||
|   })?.id |   })?.id | ||||||
| }) | }) | ||||||
|  |  | ||||||
| const slugValidator = (value) => { |  | ||||||
|   return value == slugify(value) |  | ||||||
| } |  | ||||||
| const rules = { | const rules = { | ||||||
|   companyForm: { |   companyForm: { | ||||||
|     name: { |     name: { | ||||||
|       required: helpers.withMessage(t('validation.required'), required), |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|       minLength: helpers.withMessage( |  | ||||||
|         t('validation.name_min_length', { count: 3 }), |  | ||||||
|         minLength(3) |  | ||||||
|       ), |  | ||||||
|     }, |  | ||||||
|     slug: { |  | ||||||
|       required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       minLength: helpers.withMessage( |  | ||||||
|         t('validation.name_min_length', { count: 3 }), |  | ||||||
|         minLength(3) |  | ||||||
|       ), |  | ||||||
|       slugValidator: helpers.withMessage( |  | ||||||
|         t('validation.invalid_slug'), |  | ||||||
|         slugValidator |  | ||||||
|       ), |  | ||||||
|     }, |     }, | ||||||
|     address: { |     address: { | ||||||
|       country_id: { |       country_id: { | ||||||
| @ -284,24 +249,4 @@ async function next() { | |||||||
|     emit('next', 7) |     emit('next', 7) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| // watcher for if change company name then auto fill company slug value |  | ||||||
| watch( |  | ||||||
|   () => companyForm.name, |  | ||||||
|   (currentValue) => { |  | ||||||
|     companyForm.slug = slugify(currentValue) |  | ||||||
|   } |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| function slugify(string) { |  | ||||||
|   return string |  | ||||||
|     .toString() |  | ||||||
|     .trim() |  | ||||||
|     .toLowerCase() |  | ||||||
|     .replace(/\s+/g, '-') |  | ||||||
|     .replace(/[^\w\-]+/g, '') |  | ||||||
|     .replace(/\-\-+/g, '-') |  | ||||||
|     .replace(/^-+/, '') |  | ||||||
|     .replace(/-+$/, '') |  | ||||||
| } |  | ||||||
| </script> | </script> | ||||||
|  | |||||||
| @ -56,7 +56,7 @@ | |||||||
|         <BaseMultiselect |         <BaseMultiselect | ||||||
|           v-model="filters.status" |           v-model="filters.status" | ||||||
|           :groups="true" |           :groups="true" | ||||||
|           :options="invoiceStatus" |           :options="status" | ||||||
|           searchable |           searchable | ||||||
|           :placeholder="$t('general.select_a_status')" |           :placeholder="$t('general.select_a_status')" | ||||||
|           @update:modelValue="setActiveTab" |           @update:modelValue="setActiveTab" | ||||||
| @ -130,27 +130,11 @@ | |||||||
|         " |         " | ||||||
|       > |       > | ||||||
|         <!-- Tabs --> |         <!-- Tabs --> | ||||||
|         <BaseTabGroup |         <BaseTabGroup class="-mb-5" @change="setStatusFilter"> | ||||||
|           class="-mb-5" |           <BaseTab :title="$t('general.all')" filter="" /> | ||||||
|           :selected-index="selectedIndex" |           <BaseTab :title="$t('general.draft')" filter="DRAFT" /> | ||||||
|           @change="changeTabStatus" |           <BaseTab :title="$t('general.sent')" filter="SENT" /> | ||||||
|         > |           <BaseTab :title="$t('general.due')" filter="DUE" /> | ||||||
|           <BaseTab |  | ||||||
|             :title="invoiceTabStatus[0].title" |  | ||||||
|             :tab-status="invoiceTabStatus[0].value" |  | ||||||
|           /> |  | ||||||
|           <BaseTab |  | ||||||
|             :title="invoiceTabStatus[1].title" |  | ||||||
|             :tab-status="invoiceTabStatus[1].value" |  | ||||||
|           /> |  | ||||||
|           <BaseTab |  | ||||||
|             :title="invoiceTabStatus[2].title" |  | ||||||
|             :tab-status="invoiceTabStatus[2].value" |  | ||||||
|           /> |  | ||||||
|           <BaseTab |  | ||||||
|             :title="invoiceTabStatus[3].title" |  | ||||||
|             :tab-status="invoiceTabStatus[3].value" |  | ||||||
|           /> |  | ||||||
|         </BaseTabGroup> |         </BaseTabGroup> | ||||||
|  |  | ||||||
|         <BaseDropdown |         <BaseDropdown | ||||||
| @ -305,10 +289,10 @@ const utils = inject('$utils') | |||||||
| const table = ref(null) | const table = ref(null) | ||||||
| const showFilters = ref(false) | const showFilters = ref(false) | ||||||
|  |  | ||||||
| const invoiceStatus = ref([ | const status = ref([ | ||||||
|   { |   { | ||||||
|     label: 'Status', |     label: 'Status', | ||||||
|     options: ['DRAFT', 'SENT', 'VIEWED', 'COMPLETED'], |     options: ['DRAFT', 'DUE', 'SENT', 'VIEWED', 'COMPLETED'], | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     label: 'Paid Status', |     label: 'Paid Status', | ||||||
| @ -316,29 +300,10 @@ const invoiceStatus = ref([ | |||||||
|   }, |   }, | ||||||
|   , |   , | ||||||
| ]) | ]) | ||||||
|  |  | ||||||
| const invoiceTabStatus = { |  | ||||||
|   0: { |  | ||||||
|     title: t('general.all'), |  | ||||||
|     value: '', |  | ||||||
|   }, |  | ||||||
|   1: { |  | ||||||
|     title: t('general.draft'), |  | ||||||
|     value: 'DRAFT', |  | ||||||
|   }, |  | ||||||
|   2: { |  | ||||||
|     title: t('general.sent'), |  | ||||||
|     value: 'SENT', |  | ||||||
|   }, |  | ||||||
|   3: { |  | ||||||
|     title: t('general.due'), |  | ||||||
|     value: 'DUE', |  | ||||||
|   }, |  | ||||||
| } |  | ||||||
| const isRequestOngoing = ref(true) | const isRequestOngoing = ref(true) | ||||||
|  | const activeTab = ref('general.draft') | ||||||
| const router = useRouter() | const router = useRouter() | ||||||
| const userStore = useUserStore() | const userStore = useUserStore() | ||||||
| const selectedIndex = ref(0) |  | ||||||
|  |  | ||||||
| let filters = reactive({ | let filters = reactive({ | ||||||
|   customer_id: '', |   customer_id: '', | ||||||
| @ -346,7 +311,6 @@ let filters = reactive({ | |||||||
|   from_date: '', |   from_date: '', | ||||||
|   to_date: '', |   to_date: '', | ||||||
|   invoice_number: '', |   invoice_number: '', | ||||||
|   tab_status: '', |  | ||||||
| }) | }) | ||||||
|  |  | ||||||
| const showEmptyScreen = computed( | const showEmptyScreen = computed( | ||||||
| @ -437,7 +401,6 @@ async function fetchData({ page, filter, sort }) { | |||||||
|     from_date: filters.from_date, |     from_date: filters.from_date, | ||||||
|     to_date: filters.to_date, |     to_date: filters.to_date, | ||||||
|     invoice_number: filters.invoice_number, |     invoice_number: filters.invoice_number, | ||||||
|     tab_status: filters.tab_status, |  | ||||||
|     orderByField: sort.fieldName || 'created_at', |     orderByField: sort.fieldName || 'created_at', | ||||||
|     orderBy: sort.order || 'desc', |     orderBy: sort.order || 'desc', | ||||||
|     page, |     page, | ||||||
| @ -460,9 +423,29 @@ async function fetchData({ page, filter, sort }) { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| function changeTabStatus(val, index) { | function setStatusFilter(val) { | ||||||
|   filters.tab_status = val['tab-status'] |   if (activeTab.value == val.title) { | ||||||
|   selectedIndex.value = index |     return true | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   activeTab.value = val.title | ||||||
|  |  | ||||||
|  |   switch (val.title) { | ||||||
|  |     case t('general.draft'): | ||||||
|  |       filters.status = 'DRAFT' | ||||||
|  |       break | ||||||
|  |     case t('general.sent'): | ||||||
|  |       filters.status = 'SENT' | ||||||
|  |       break | ||||||
|  |  | ||||||
|  |     case t('general.due'): | ||||||
|  |       filters.status = 'DUE' | ||||||
|  |       break | ||||||
|  |  | ||||||
|  |     default: | ||||||
|  |       filters.status = '' | ||||||
|  |       break | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| function setFilters() { | function setFilters() { | ||||||
| @ -480,6 +463,8 @@ function clearFilter() { | |||||||
|   filters.from_date = '' |   filters.from_date = '' | ||||||
|   filters.to_date = '' |   filters.to_date = '' | ||||||
|   filters.invoice_number = '' |   filters.invoice_number = '' | ||||||
|  |  | ||||||
|  |   activeTab.value = t('general.all') | ||||||
| } | } | ||||||
|  |  | ||||||
| async function removeMultipleInvoices() { | async function removeMultipleInvoices() { | ||||||
| @ -520,21 +505,39 @@ function toggleFilter() { | |||||||
| function setActiveTab(val) { | function setActiveTab(val) { | ||||||
|   switch (val) { |   switch (val) { | ||||||
|     case 'DRAFT': |     case 'DRAFT': | ||||||
|       selectedIndex.value = 1 |       activeTab.value = t('general.draft') | ||||||
|  |       break | ||||||
|  |     case 'SENT': | ||||||
|  |       activeTab.value = t('general.sent') | ||||||
|  |       break | ||||||
|  |  | ||||||
|  |     case 'DUE': | ||||||
|  |       activeTab.value = t('general.due') | ||||||
|       break |       break | ||||||
|  |  | ||||||
|     case 'SENT': |  | ||||||
|     case 'VIEWED': |  | ||||||
|     case 'COMPLETED': |     case 'COMPLETED': | ||||||
|  |       activeTab.value = t('invoices.completed') | ||||||
|  |       break | ||||||
|  |  | ||||||
|     case 'PAID': |     case 'PAID': | ||||||
|       selectedIndex.value = 2 |       activeTab.value = t('invoices.paid') | ||||||
|       break |       break | ||||||
|  |  | ||||||
|     case 'UNPAID': |     case 'UNPAID': | ||||||
|  |       activeTab.value = t('invoices.unpaid') | ||||||
|  |       break | ||||||
|  |  | ||||||
|     case 'PARTIALLY_PAID': |     case 'PARTIALLY_PAID': | ||||||
|       selectedIndex.value = 3 |       activeTab.value = t('invoices.partially_paid') | ||||||
|  |       break | ||||||
|  |  | ||||||
|  |     case 'VIEWED': | ||||||
|  |       activeTab.value = t('invoices.viewed') | ||||||
|  |       break | ||||||
|  |  | ||||||
|  |     default: | ||||||
|  |       activeTab.value = t('general.all') | ||||||
|       break |       break | ||||||
|   } |   } | ||||||
|   filters.tab_status = invoiceTabStatus[selectedIndex.value].value |  | ||||||
| } | } | ||||||
| </script> | </script> | ||||||
|  | |||||||
| @ -32,8 +32,6 @@ | |||||||
|           :content-loading="isLoading" |           :content-loading="isLoading" | ||||||
|           :calendar-button="true" |           :calendar-button="true" | ||||||
|           calendar-button-icon="calendar" |           calendar-button-icon="calendar" | ||||||
|           :show-extra-options="true" |  | ||||||
|           :source-date="invoiceStore.newInvoice.invoice_date" |  | ||||||
|         /> |         /> | ||||||
|       </BaseInputGroup> |       </BaseInputGroup> | ||||||
|  |  | ||||||
|  | |||||||
| @ -82,9 +82,9 @@ | |||||||
|             required |             required | ||||||
|           > |           > | ||||||
|             <BaseCustomerSelectInput |             <BaseCustomerSelectInput | ||||||
|               v-if="!isLoadingContent" |  | ||||||
|               v-model="paymentStore.currentPayment.customer_id" |               v-model="paymentStore.currentPayment.customer_id" | ||||||
|               :content-loading="isLoadingContent" |               :content-loading="isLoadingContent" | ||||||
|  |               v-if="!isLoadingContent" | ||||||
|               :invalid="v$.currentPayment.customer_id.$error" |               :invalid="v$.currentPayment.customer_id.$error" | ||||||
|               :placeholder="$t('customers.select_a_customer')" |               :placeholder="$t('customers.select_a_customer')" | ||||||
|               show-action |               show-action | ||||||
| @ -423,7 +423,7 @@ function onCustomerChange(customer_id) { | |||||||
|   if (customer_id) { |   if (customer_id) { | ||||||
|     let data = { |     let data = { | ||||||
|       customer_id: customer_id, |       customer_id: customer_id, | ||||||
|       tab_status: 'DUE', |       status: 'DUE', | ||||||
|       limit: 'all', |       limit: 'all', | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -446,11 +446,7 @@ function onCustomerChange(customer_id) { | |||||||
|           paymentStore.currentPayment.selectedCustomer = res2.data.data |           paymentStore.currentPayment.selectedCustomer = res2.data.data | ||||||
|           paymentStore.currentPayment.customer = res2.data.data |           paymentStore.currentPayment.customer = res2.data.data | ||||||
|           paymentStore.currentPayment.currency = res2.data.data.currency |           paymentStore.currentPayment.currency = res2.data.data.currency | ||||||
|           if ( |           if(isEdit.value && !customerStore.editCustomer && paymentStore.currentPayment.customer_id) { | ||||||
|             isEdit.value && |  | ||||||
|             !customerStore.editCustomer && |  | ||||||
|             paymentStore.currentPayment.customer_id |  | ||||||
|           ) { |  | ||||||
|             customerStore.editCustomer = res2.data.data |             customerStore.editCustomer = res2.data.data | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -28,19 +28,6 @@ | |||||||
|           /> |           /> | ||||||
|         </BaseInputGroup> |         </BaseInputGroup> | ||||||
|  |  | ||||||
|         <BaseInputGroup |  | ||||||
|           :label="$tc('settings.company_info.company_slug')" |  | ||||||
|           :help-text="$t('settings.company_info.company_slug_help_text')" |  | ||||||
|           :error="v$.slug.$error && v$.slug.$errors[0].$message" |  | ||||||
|           required |  | ||||||
|         > |  | ||||||
|           <BaseInput |  | ||||||
|             v-model="companyForm.slug" |  | ||||||
|             :invalid="v$.slug.$error" |  | ||||||
|             @blur="v$.slug.$touch()" |  | ||||||
|           /> |  | ||||||
|         </BaseInputGroup> |  | ||||||
|  |  | ||||||
|         <BaseInputGroup :label="$tc('settings.company_info.phone')"> |         <BaseInputGroup :label="$tc('settings.company_info.phone')"> | ||||||
|           <BaseInput v-model="companyForm.address.phone" /> |           <BaseInput v-model="companyForm.address.phone" /> | ||||||
|         </BaseInputGroup> |         </BaseInputGroup> | ||||||
| @ -173,7 +160,6 @@ let isSaving = ref(false) | |||||||
|  |  | ||||||
| const companyForm = reactive({ | const companyForm = reactive({ | ||||||
|   name: null, |   name: null, | ||||||
|   slug: null, |  | ||||||
|   logo: null, |   logo: null, | ||||||
|   address: { |   address: { | ||||||
|     address_street_1: '', |     address_street_1: '', | ||||||
| @ -207,14 +193,7 @@ const rules = computed(() => { | |||||||
|     name: { |     name: { | ||||||
|       required: helpers.withMessage(t('validation.required'), required), |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|       minLength: helpers.withMessage( |       minLength: helpers.withMessage( | ||||||
|         t('validation.name_min_length', { count: 3 }), |         t('validation.name_min_length'), | ||||||
|         minLength(3) |  | ||||||
|       ), |  | ||||||
|     }, |  | ||||||
|     slug: { |  | ||||||
|       required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       minLength: helpers.withMessage( |  | ||||||
|         t('validation.name_min_length', { count: 3 }), |  | ||||||
|         minLength(3) |         minLength(3) | ||||||
|       ), |       ), | ||||||
|     }, |     }, | ||||||
|  | |||||||
| @ -8,11 +8,7 @@ | |||||||
|         <BaseInputGroup |         <BaseInputGroup | ||||||
|           :content-loading="isFetchingInitialData" |           :content-loading="isFetchingInitialData" | ||||||
|           :label="$tc('settings.preferences.currency')" |           :label="$tc('settings.preferences.currency')" | ||||||
|           :help-text=" |           :help-text="$t('settings.preferences.company_currency_unchangeable')" | ||||||
|             isCurrencyDisabled |  | ||||||
|               ? $t('settings.preferences.company_currency_unchangeable') |  | ||||||
|               : '' |  | ||||||
|           " |  | ||||||
|           :error="v$.currency.$error && v$.currency.$errors[0].$message" |           :error="v$.currency.$error && v$.currency.$errors[0].$message" | ||||||
|           required |           required | ||||||
|         > |         > | ||||||
| @ -25,7 +21,7 @@ | |||||||
|             :searchable="true" |             :searchable="true" | ||||||
|             track-by="name" |             track-by="name" | ||||||
|             :invalid="v$.currency.$error" |             :invalid="v$.currency.$error" | ||||||
|             :disabled="isCurrencyDisabled" |             disabled | ||||||
|             class="w-full" |             class="w-full" | ||||||
|           > |           > | ||||||
|           </BaseMultiselect> |           </BaseMultiselect> | ||||||
| @ -191,7 +187,6 @@ const { t, tm } = useI18n() | |||||||
| let isSaving = ref(false) | let isSaving = ref(false) | ||||||
| let isDataSaving = ref(false) | let isDataSaving = ref(false) | ||||||
| let isFetchingInitialData = ref(false) | let isFetchingInitialData = ref(false) | ||||||
| let isCurrencyDisabled = ref(true) |  | ||||||
|  |  | ||||||
| const settingsForm = reactive({ ...companyStore.selectedCompanySettings }) | const settingsForm = reactive({ ...companyStore.selectedCompanySettings }) | ||||||
|  |  | ||||||
| @ -287,14 +282,10 @@ setInitialData() | |||||||
| async function setInitialData() { | async function setInitialData() { | ||||||
|   isFetchingInitialData.value = true |   isFetchingInitialData.value = true | ||||||
|   Promise.all([ |   Promise.all([ | ||||||
|     companyStore.checkCompanyHasCurrencyTransactions(), |  | ||||||
|     globalStore.fetchCurrencies(), |     globalStore.fetchCurrencies(), | ||||||
|     globalStore.fetchDateFormats(), |     globalStore.fetchDateFormats(), | ||||||
|     globalStore.fetchTimeZones(), |     globalStore.fetchTimeZones(), | ||||||
|   ]).then(([res1]) => { |   ]).then(([res1]) => { | ||||||
|     if (res1.data?.has_transactions == false) { |  | ||||||
|       isCurrencyDisabled.value = false |  | ||||||
|     } |  | ||||||
|     isFetchingInitialData.value = false |     isFetchingInitialData.value = false | ||||||
|   }) |   }) | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,158 +0,0 @@ | |||||||
| <template> |  | ||||||
|   <form @submit.prevent="saveEmailConfig"> |  | ||||||
|     <BaseInputGrid> |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.driver')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.basicMailConfig.mail_driver.$error && |  | ||||||
|           v$.basicMailConfig.mail_driver.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseMultiselect |  | ||||||
|           v-model="mailDriverStore.basicMailConfig.mail_driver" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :options="mailDrivers" |  | ||||||
|           :can-deselect="false" |  | ||||||
|           :invalid="v$.basicMailConfig.mail_driver.$error" |  | ||||||
|           @update:modelValue="onChangeDriver" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.from_mail')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.basicMailConfig.from_mail.$error && |  | ||||||
|           v$.basicMailConfig.from_mail.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.basicMailConfig.from_mail" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="from_mail" |  | ||||||
|           :invalid="v$.basicMailConfig.from_mail.$error" |  | ||||||
|           @input="v$.basicMailConfig.from_mail.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.from_name')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.basicMailConfig.from_name.$error && |  | ||||||
|           v$.basicMailConfig.from_name.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.basicMailConfig.from_name" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="name" |  | ||||||
|           :invalid="v$.basicMailConfig.from_name.$error" |  | ||||||
|           @input="v$.basicMailConfig.from_name.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|     </BaseInputGrid> |  | ||||||
|     <div class="flex mt-8"> |  | ||||||
|       <BaseButton |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :disabled="isSaving" |  | ||||||
|         :loading="isSaving" |  | ||||||
|         variant="primary" |  | ||||||
|         type="submit" |  | ||||||
|       > |  | ||||||
|         <template #left="slotProps"> |  | ||||||
|           <BaseIcon v-if="!isSaving" :class="slotProps.class" name="SaveIcon" /> |  | ||||||
|         </template> |  | ||||||
|         {{ $t('general.save') }} |  | ||||||
|       </BaseButton> |  | ||||||
|       <slot /> |  | ||||||
|     </div> |  | ||||||
|   </form> |  | ||||||
| </template> |  | ||||||
|  |  | ||||||
| <script setup> |  | ||||||
| import { onMounted, computed } from 'vue' |  | ||||||
| import { required, email, helpers } from '@vuelidate/validators' |  | ||||||
| import useVuelidate from '@vuelidate/core' |  | ||||||
| import { useI18n } from 'vue-i18n' |  | ||||||
| import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver' |  | ||||||
|  |  | ||||||
| const props = defineProps({ |  | ||||||
|   configData: { |  | ||||||
|     type: Object, |  | ||||||
|     require: true, |  | ||||||
|     default: Object, |  | ||||||
|   }, |  | ||||||
|   isSaving: { |  | ||||||
|     type: Boolean, |  | ||||||
|     require: true, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   isFetchingInitialData: { |  | ||||||
|     type: Boolean, |  | ||||||
|     require: true, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   mailDrivers: { |  | ||||||
|     type: Array, |  | ||||||
|     require: true, |  | ||||||
|     default: Array, |  | ||||||
|   }, |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const emit = defineEmits(['submit-data', 'on-change-driver']) |  | ||||||
|  |  | ||||||
| const mailDriverStore = useMailDriverStore() |  | ||||||
| const { t } = useI18n() |  | ||||||
|  |  | ||||||
| const rules = computed(() => { |  | ||||||
|   return { |  | ||||||
|     basicMailConfig: { |  | ||||||
|       mail_driver: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       from_mail: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|         email: helpers.withMessage(t('validation.email_incorrect'), email), |  | ||||||
|       }, |  | ||||||
|       from_name: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|     }, |  | ||||||
|   } |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const v$ = useVuelidate( |  | ||||||
|   rules, |  | ||||||
|   computed(() => mailDriverStore) |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| onMounted(() => { |  | ||||||
|   for (const key in mailDriverStore.basicMailConfig) { |  | ||||||
|     if (props.configData.hasOwnProperty(key)) { |  | ||||||
|       mailDriverStore.$patch((state) => { |  | ||||||
|         state.basicMailConfig[key] = props.configData[key] |  | ||||||
|       }) |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| async function saveEmailConfig() { |  | ||||||
|   v$.value.basicMailConfig.$touch() |  | ||||||
|   if (!v$.value.basicMailConfig.$invalid) { |  | ||||||
|     emit('submit-data', mailDriverStore.basicMailConfig) |  | ||||||
|   } |  | ||||||
|   return false |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function onChangeDriver() { |  | ||||||
|   v$.value.basicMailConfig.mail_driver.$touch() |  | ||||||
|   emit('on-change-driver', mailDriverStore.basicMailConfig.mail_driver) |  | ||||||
| } |  | ||||||
| </script> |  | ||||||
| @ -1,247 +0,0 @@ | |||||||
| <template> |  | ||||||
|   <form @submit.prevent="saveEmailConfig"> |  | ||||||
|     <BaseInputGrid> |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.driver')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.mailgunConfig.mail_driver.$error && |  | ||||||
|           v$.mailgunConfig.mail_driver.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseMultiselect |  | ||||||
|           v-model="mailDriverStore.mailgunConfig.mail_driver" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :options="mailDrivers" |  | ||||||
|           :can-deselect="false" |  | ||||||
|           :invalid="v$.mailgunConfig.mail_driver.$error" |  | ||||||
|           @update:modelValue="onChangeDriver" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.mailgun_domain')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.mailgunConfig.mail_mailgun_domain.$error && |  | ||||||
|           v$.mailgunConfig.mail_mailgun_domain.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.mailgunConfig.mail_mailgun_domain" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="mailgun_domain" |  | ||||||
|           :invalid="v$.mailgunConfig.mail_mailgun_domain.$error" |  | ||||||
|           @input="v$.mailgunConfig.mail_mailgun_domain.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.mailgun_secret')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.mailgunConfig.mail_mailgun_secret.$error && |  | ||||||
|           v$.mailgunConfig.mail_mailgun_secret.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.mailgunConfig.mail_mailgun_secret" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :type="getInputType" |  | ||||||
|           name="mailgun_secret" |  | ||||||
|           autocomplete="off" |  | ||||||
|           :invalid="v$.mailgunConfig.mail_mailgun_secret.$error" |  | ||||||
|           @input="v$.mailgunConfig.mail_mailgun_secret.$touch()" |  | ||||||
|         > |  | ||||||
|           <template #right> |  | ||||||
|             <BaseIcon |  | ||||||
|               v-if="isShowPassword" |  | ||||||
|               class="mr-1 text-gray-500 cursor-pointer" |  | ||||||
|               name="EyeOffIcon" |  | ||||||
|               @click="isShowPassword = !isShowPassword" |  | ||||||
|             /> |  | ||||||
|             <BaseIcon |  | ||||||
|               v-else |  | ||||||
|               class="mr-1 text-gray-500 cursor-pointer" |  | ||||||
|               name="EyeIcon" |  | ||||||
|               @click="isShowPassword = !isShowPassword" |  | ||||||
|             /> |  | ||||||
|           </template> |  | ||||||
|         </BaseInput> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.mailgun_endpoint')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.mailgunConfig.mail_mailgun_endpoint.$error && |  | ||||||
|           v$.mailgunConfig.mail_mailgun_endpoint.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.mailgunConfig.mail_mailgun_endpoint" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="mailgun_endpoint" |  | ||||||
|           :invalid="v$.mailgunConfig.mail_mailgun_endpoint.$error" |  | ||||||
|           @input="v$.mailgunConfig.mail_mailgun_endpoint.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.from_mail')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.mailgunConfig.from_mail.$error && |  | ||||||
|           v$.mailgunConfig.from_mail.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.mailgunConfig.from_mail" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="from_mail" |  | ||||||
|           :invalid="v$.mailgunConfig.from_mail.$error" |  | ||||||
|           @input="v$.mailgunConfig.from_mail.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.from_name')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.mailgunConfig.from_name.$error && |  | ||||||
|           v$.mailgunConfig.from_name.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.mailgunConfig.from_name" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="from_name" |  | ||||||
|           :invalid="v$.mailgunConfig.from_name.$error" |  | ||||||
|           @input="v$.mailgunConfig.from_name.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|     </BaseInputGrid> |  | ||||||
|     <div class="flex my-10"> |  | ||||||
|       <BaseButton |  | ||||||
|         :disabled="isSaving" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :loading="isSaving" |  | ||||||
|         variant="primary" |  | ||||||
|         type="submit" |  | ||||||
|       > |  | ||||||
|         <template #left="slotProps"> |  | ||||||
|           <BaseIcon v-if="!isSaving" name="SaveIcon" :class="slotProps.class" /> |  | ||||||
|         </template> |  | ||||||
|         {{ $t('general.save') }} |  | ||||||
|       </BaseButton> |  | ||||||
|       <slot /> |  | ||||||
|     </div> |  | ||||||
|   </form> |  | ||||||
| </template> |  | ||||||
|  |  | ||||||
| <script setup> |  | ||||||
| import { onMounted, ref, computed } from 'vue' |  | ||||||
| import { required, email, helpers } from '@vuelidate/validators' |  | ||||||
| import useVuelidate from '@vuelidate/core' |  | ||||||
| import { useI18n } from 'vue-i18n' |  | ||||||
| import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver' |  | ||||||
|  |  | ||||||
| const props = defineProps({ |  | ||||||
|   configData: { |  | ||||||
|     type: Object, |  | ||||||
|     require: true, |  | ||||||
|     default: Object, |  | ||||||
|   }, |  | ||||||
|   isSaving: { |  | ||||||
|     type: Boolean, |  | ||||||
|     require: true, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   isFetchingInitialData: { |  | ||||||
|     type: Boolean, |  | ||||||
|     require: true, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   mailDrivers: { |  | ||||||
|     type: Array, |  | ||||||
|     require: true, |  | ||||||
|     default: Array, |  | ||||||
|   }, |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const emit = defineEmits(['submit-data', 'on-change-driver']) |  | ||||||
|  |  | ||||||
| const mailDriverStore = useMailDriverStore() |  | ||||||
| const { t } = useI18n() |  | ||||||
|  |  | ||||||
| let isShowPassword = ref(false) |  | ||||||
|  |  | ||||||
| const getInputType = computed(() => { |  | ||||||
|   if (isShowPassword.value) { |  | ||||||
|     return 'text' |  | ||||||
|   } |  | ||||||
|   return 'password' |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const rules = computed(() => { |  | ||||||
|   return { |  | ||||||
|     mailgunConfig: { |  | ||||||
|       mail_driver: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_mailgun_domain: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_mailgun_endpoint: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_mailgun_secret: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       from_mail: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|         email, |  | ||||||
|       }, |  | ||||||
|       from_name: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|     }, |  | ||||||
|   } |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const v$ = useVuelidate( |  | ||||||
|   rules, |  | ||||||
|   computed(() => mailDriverStore) |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| onMounted(() => { |  | ||||||
|   for (const key in mailDriverStore.mailgunConfig) { |  | ||||||
|     if (props.configData.hasOwnProperty(key)) { |  | ||||||
|       mailDriverStore.mailgunConfig[key] = props.configData[key] |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| async function saveEmailConfig() { |  | ||||||
|   v$.value.mailgunConfig.$touch() |  | ||||||
|   if (!v$.value.mailgunConfig.$invalid) { |  | ||||||
|     emit('submit-data', mailDriverStore.mailgunConfig) |  | ||||||
|   } |  | ||||||
|   return false |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function onChangeDriver() { |  | ||||||
|   v$.value.mailgunConfig.mail_driver.$touch() |  | ||||||
|   emit('on-change-driver', mailDriverStore.mailgunConfig.mail_driver) |  | ||||||
| } |  | ||||||
| </script> |  | ||||||
| @ -1,294 +0,0 @@ | |||||||
| <template> |  | ||||||
|   <form @submit.prevent="saveEmailConfig"> |  | ||||||
|     <BaseInputGrid> |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.driver')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.sesConfig.mail_driver.$error && |  | ||||||
|           v$.sesConfig.mail_driver.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseMultiselect |  | ||||||
|           v-model="mailDriverStore.sesConfig.mail_driver" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :options="mailDrivers" |  | ||||||
|           :can-deselect="false" |  | ||||||
|           :invalid="v$.sesConfig.mail_driver.$error" |  | ||||||
|           @update:modelValue="onChangeDriver" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.host')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.sesConfig.mail_host.$error && |  | ||||||
|           v$.sesConfig.mail_host.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.sesConfig.mail_host" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="mail_host" |  | ||||||
|           :invalid="v$.sesConfig.mail_host.$error" |  | ||||||
|           @input="v$.sesConfig.mail_host.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.port')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.sesConfig.mail_port.$error && |  | ||||||
|           v$.sesConfig.mail_port.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.sesConfig.mail_port" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="mail_port" |  | ||||||
|           :invalid="v$.sesConfig.mail_port.$error" |  | ||||||
|           @input="v$.sesConfig.mail_port.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.encryption')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.sesConfig.mail_encryption.$error && |  | ||||||
|           v$.sesConfig.mail_encryption.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseMultiselect |  | ||||||
|           v-model.trim="mailDriverStore.sesConfig.mail_encryption" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :options="encryptions" |  | ||||||
|           :invalid="v$.sesConfig.mail_encryption.$error" |  | ||||||
|           placeholder="Select option" |  | ||||||
|           @input="v$.sesConfig.mail_encryption.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.from_mail')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.sesConfig.from_mail.$error && |  | ||||||
|           v$.sesConfig.from_mail.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.sesConfig.from_mail" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="from_mail" |  | ||||||
|           :invalid="v$.sesConfig.from_mail.$error" |  | ||||||
|           @input="v$.sesConfig.from_mail.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.from_name')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.sesConfig.from_name.$error && |  | ||||||
|           v$.sesConfig.from_name.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.sesConfig.from_name" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="name" |  | ||||||
|           :invalid="v$.sesConfig.from_name.$error" |  | ||||||
|           @input="v$.sesConfig.from_name.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.ses_key')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.sesConfig.mail_ses_key.$error && |  | ||||||
|           v$.sesConfig.mail_ses_key.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.sesConfig.mail_ses_key" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="mail_ses_key" |  | ||||||
|           :invalid="v$.sesConfig.mail_ses_key.$error" |  | ||||||
|           @input="v$.sesConfig.mail_ses_key.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.ses_secret')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.sesConfig.mail_ses_secret.$error && |  | ||||||
|           v$.mail_ses_secret.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.sesConfig.mail_ses_secret" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :type="getInputType" |  | ||||||
|           name="mail_ses_secret" |  | ||||||
|           autocomplete="off" |  | ||||||
|           :invalid="v$.sesConfig.mail_ses_secret.$error" |  | ||||||
|           @input="v$.sesConfig.mail_ses_secret.$touch()" |  | ||||||
|         > |  | ||||||
|           <template #right> |  | ||||||
|             <BaseIcon |  | ||||||
|               v-if="isShowPassword" |  | ||||||
|               class="mr-1 text-gray-500 cursor-pointer" |  | ||||||
|               name="EyeOffIcon" |  | ||||||
|               @click="isShowPassword = !isShowPassword" |  | ||||||
|             /> |  | ||||||
|             <BaseIcon |  | ||||||
|               v-else |  | ||||||
|               class="mr-1 text-gray-500 cursor-pointer" |  | ||||||
|               name="EyeIcon" |  | ||||||
|               @click="isShowPassword = !isShowPassword" |  | ||||||
|             /> |  | ||||||
|           </template> |  | ||||||
|         </BaseInput> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|     </BaseInputGrid> |  | ||||||
|  |  | ||||||
|     <div class="flex my-10"> |  | ||||||
|       <BaseButton |  | ||||||
|         :disabled="isSaving" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :loading="isSaving" |  | ||||||
|         variant="primary" |  | ||||||
|         type="submit" |  | ||||||
|       > |  | ||||||
|         <template #left="slotProps"> |  | ||||||
|           <BaseIcon v-if="!isSaving" name="SaveIcon" :class="slotProps.class" /> |  | ||||||
|         </template> |  | ||||||
|         {{ $t('general.save') }} |  | ||||||
|       </BaseButton> |  | ||||||
|       <slot /> |  | ||||||
|     </div> |  | ||||||
|   </form> |  | ||||||
| </template> |  | ||||||
|  |  | ||||||
| <script setup> |  | ||||||
| import { computed, onMounted, reactive, ref } from 'vue' |  | ||||||
| import { required, email, numeric, helpers } from '@vuelidate/validators' |  | ||||||
| import useVuelidate from '@vuelidate/core' |  | ||||||
| import { useI18n } from 'vue-i18n' |  | ||||||
| import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver' |  | ||||||
|  |  | ||||||
| const props = defineProps({ |  | ||||||
|   configData: { |  | ||||||
|     type: Object, |  | ||||||
|     require: true, |  | ||||||
|     default: Object, |  | ||||||
|   }, |  | ||||||
|   isSaving: { |  | ||||||
|     type: Boolean, |  | ||||||
|     require: true, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   isFetchingInitialData: { |  | ||||||
|     type: Boolean, |  | ||||||
|     require: true, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   mailDrivers: { |  | ||||||
|     type: Array, |  | ||||||
|     require: true, |  | ||||||
|     default: Array, |  | ||||||
|   }, |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const emit = defineEmits(['submit-data', 'on-change-driver']) |  | ||||||
|  |  | ||||||
| const mailDriverStore = useMailDriverStore() |  | ||||||
| const { t } = useI18n() |  | ||||||
|  |  | ||||||
| let isShowPassword = ref(false) |  | ||||||
| const encryptions = reactive(['tls', 'ssl', 'starttls']) |  | ||||||
|  |  | ||||||
| const rules = computed(() => { |  | ||||||
|   return { |  | ||||||
|     sesConfig: { |  | ||||||
|       mail_driver: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_host: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_port: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|         numeric, |  | ||||||
|       }, |  | ||||||
|       mail_ses_key: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_ses_secret: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_encryption: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       from_mail: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|         email: helpers.withMessage(t('validation.email_incorrect'), email), |  | ||||||
|       }, |  | ||||||
|       from_name: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|     }, |  | ||||||
|   } |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const v$ = useVuelidate( |  | ||||||
|   rules, |  | ||||||
|   computed(() => mailDriverStore) |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| const getInputType = computed(() => { |  | ||||||
|   if (isShowPassword.value) { |  | ||||||
|     return 'text' |  | ||||||
|   } |  | ||||||
|   return 'password' |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| onMounted(() => { |  | ||||||
|   for (const key in mailDriverStore.sesConfig) { |  | ||||||
|     if (props.configData.hasOwnProperty(key)) { |  | ||||||
|       mailDriverStore.sesConfig[key] = props.configData[key] |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| async function saveEmailConfig() { |  | ||||||
|   v$.value.sesConfig.$touch() |  | ||||||
|   if (!v$.value.sesConfig.$invalid) { |  | ||||||
|     emit('submit-data', mailDriverStore.sesConfig) |  | ||||||
|   } |  | ||||||
|   return false |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function onChangeDriver() { |  | ||||||
|   v$.value.sesConfig.mail_driver.$touch() |  | ||||||
|   emit('on-change-driver', mailDriverStore.sesConfig.mail_driver) |  | ||||||
| } |  | ||||||
| </script> |  | ||||||
| @ -1,275 +0,0 @@ | |||||||
| <template> |  | ||||||
|   <form @submit.prevent="saveEmailConfig"> |  | ||||||
|     <BaseInputGrid> |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.driver')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.smtpConfig.mail_driver.$error && |  | ||||||
|           v$.smtpConfig.mail_driver.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseMultiselect |  | ||||||
|           v-model="mailDriverStore.smtpConfig.mail_driver" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :options="mailDrivers" |  | ||||||
|           :can-deselect="false" |  | ||||||
|           :invalid="v$.smtpConfig.mail_driver.$error" |  | ||||||
|           @update:modelValue="onChangeDriver" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.host')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.smtpConfig.mail_host.$error && |  | ||||||
|           v$.smtpConfig.mail_host.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.smtpConfig.mail_host" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="mail_host" |  | ||||||
|           :invalid="v$.smtpConfig.mail_host.$error" |  | ||||||
|           @input="v$.smtpConfig.mail_host.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :label="$t('settings.mail.username')" |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.smtpConfig.mail_username" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="db_name" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :label="$t('settings.mail.password')" |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.smtpConfig.mail_password" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :type="getInputType" |  | ||||||
|           name="password" |  | ||||||
|         > |  | ||||||
|           <template #right> |  | ||||||
|             <BaseIcon |  | ||||||
|               v-if="isShowPassword" |  | ||||||
|               class="mr-1 text-gray-500 cursor-pointer" |  | ||||||
|               name="EyeOffIcon" |  | ||||||
|               @click="isShowPassword = !isShowPassword" |  | ||||||
|             /> |  | ||||||
|             <BaseIcon |  | ||||||
|               v-else |  | ||||||
|               class="mr-1 text-gray-500 cursor-pointer" |  | ||||||
|               name="EyeIcon" |  | ||||||
|               @click="isShowPassword = !isShowPassword" |  | ||||||
|             /> |  | ||||||
|           </template> |  | ||||||
|         </BaseInput> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.port')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.smtpConfig.mail_port.$error && |  | ||||||
|           v$.smtpConfig.mail_port.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.smtpConfig.mail_port" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="mail_port" |  | ||||||
|           :invalid="v$.smtpConfig.mail_port.$error" |  | ||||||
|           @input="v$.smtpConfig.mail_port.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.encryption')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.smtpConfig.mail_encryption.$error && |  | ||||||
|           v$.smtpConfig.mail_encryption.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseMultiselect |  | ||||||
|           v-model.trim="mailDriverStore.smtpConfig.mail_encryption" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           :options="encryptions" |  | ||||||
|           :searchable="true" |  | ||||||
|           :show-labels="false" |  | ||||||
|           placeholder="Select option" |  | ||||||
|           :invalid="v$.smtpConfig.mail_encryption.$error" |  | ||||||
|           @input="v$.smtpConfig.mail_encryption.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.from_mail')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.smtpConfig.from_mail.$error && |  | ||||||
|           v$.smtpConfig.from_mail.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.smtpConfig.from_mail" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="from_mail" |  | ||||||
|           :invalid="v$.smtpConfig.from_mail.$error" |  | ||||||
|           @input="v$.smtpConfig.from_mail.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|  |  | ||||||
|       <BaseInputGroup |  | ||||||
|         :label="$t('settings.mail.from_name')" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :error=" |  | ||||||
|           v$.smtpConfig.from_name.$error && |  | ||||||
|           v$.smtpConfig.from_name.$errors[0].$message |  | ||||||
|         " |  | ||||||
|         required |  | ||||||
|       > |  | ||||||
|         <BaseInput |  | ||||||
|           v-model.trim="mailDriverStore.smtpConfig.from_name" |  | ||||||
|           :content-loading="isFetchingInitialData" |  | ||||||
|           type="text" |  | ||||||
|           name="from_name" |  | ||||||
|           :invalid="v$.smtpConfig.from_name.$error" |  | ||||||
|           @input="v$.smtpConfig.from_name.$touch()" |  | ||||||
|         /> |  | ||||||
|       </BaseInputGroup> |  | ||||||
|     </BaseInputGrid> |  | ||||||
|  |  | ||||||
|     <div class="flex my-10"> |  | ||||||
|       <BaseButton |  | ||||||
|         :disabled="isSaving" |  | ||||||
|         :content-loading="isFetchingInitialData" |  | ||||||
|         :loading="isSaving" |  | ||||||
|         type="submit" |  | ||||||
|         variant="primary" |  | ||||||
|       > |  | ||||||
|         <template #left="slotProps"> |  | ||||||
|           <BaseIcon v-if="!isSaving" name="SaveIcon" :class="slotProps.class" /> |  | ||||||
|         </template> |  | ||||||
|         {{ $t('general.save') }} |  | ||||||
|       </BaseButton> |  | ||||||
|       <slot /> |  | ||||||
|     </div> |  | ||||||
|   </form> |  | ||||||
| </template> |  | ||||||
|  |  | ||||||
| <script setup> |  | ||||||
| import { reactive, onMounted, ref, computed } from 'vue' |  | ||||||
| import { required, email, numeric, helpers } from '@vuelidate/validators' |  | ||||||
| import useVuelidate from '@vuelidate/core' |  | ||||||
| import { useI18n } from 'vue-i18n' |  | ||||||
| import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver' |  | ||||||
|  |  | ||||||
| const props = defineProps({ |  | ||||||
|   configData: { |  | ||||||
|     type: Object, |  | ||||||
|     require: true, |  | ||||||
|     default: Object, |  | ||||||
|   }, |  | ||||||
|   isSaving: { |  | ||||||
|     type: Boolean, |  | ||||||
|     require: true, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   isFetchingInitialData: { |  | ||||||
|     type: Boolean, |  | ||||||
|     require: true, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   mailDrivers: { |  | ||||||
|     type: Array, |  | ||||||
|     require: true, |  | ||||||
|     default: Array, |  | ||||||
|   }, |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const emit = defineEmits(['submit-data', 'on-change-driver']) |  | ||||||
|  |  | ||||||
| const mailDriverStore = useMailDriverStore() |  | ||||||
| const { t } = useI18n() |  | ||||||
|  |  | ||||||
| let isShowPassword = ref(false) |  | ||||||
| const encryptions = reactive(['tls', 'ssl', 'starttls']) |  | ||||||
|  |  | ||||||
| const getInputType = computed(() => { |  | ||||||
|   if (isShowPassword.value) { |  | ||||||
|     return 'text' |  | ||||||
|   } |  | ||||||
|   return 'password' |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const rules = computed(() => { |  | ||||||
|   return { |  | ||||||
|     smtpConfig: { |  | ||||||
|       mail_driver: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_host: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       mail_port: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|         numeric: helpers.withMessage(t('validation.numbers_only'), numeric), |  | ||||||
|       }, |  | ||||||
|       mail_encryption: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|       from_mail: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|         email: helpers.withMessage(t('validation.email_incorrect'), email), |  | ||||||
|       }, |  | ||||||
|       from_name: { |  | ||||||
|         required: helpers.withMessage(t('validation.required'), required), |  | ||||||
|       }, |  | ||||||
|     }, |  | ||||||
|   } |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const v$ = useVuelidate( |  | ||||||
|   rules, |  | ||||||
|   computed(() => mailDriverStore) |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| onMounted(() => { |  | ||||||
|   for (const key in mailDriverStore.smtpConfig) { |  | ||||||
|     if (props.configData.hasOwnProperty(key)) { |  | ||||||
|       mailDriverStore.smtpConfig[key] = props.configData[key] |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| async function saveEmailConfig() { |  | ||||||
|   v$.value.smtpConfig.$touch() |  | ||||||
|   if (!v$.value.smtpConfig.$invalid) { |  | ||||||
|     emit('submit-data', mailDriverStore.smtpConfig) |  | ||||||
|   } |  | ||||||
|   return false |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function onChangeDriver() { |  | ||||||
|   v$.value.smtpConfig.mail_driver.$touch() |  | ||||||
|   emit('on-change-driver', mailDriverStore.smtpConfig.mail_driver) |  | ||||||
| } |  | ||||||
| </script> |  | ||||||
							
								
								
									
										136
									
								
								resources/scripts/admin/views/settings/mail-sender/Index.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								resources/scripts/admin/views/settings/mail-sender/Index.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,136 @@ | |||||||
|  | <template> | ||||||
|  |   <BaseSettingCard | ||||||
|  |     :title="$tc(`${pre_t}.title`, 2)" | ||||||
|  |     :description="$t(`${pre_t}.description`)" | ||||||
|  |   > | ||||||
|  |     <MailSenderModal /> | ||||||
|  |     <MailSenderTestModal /> | ||||||
|  |  | ||||||
|  |     <template #action> | ||||||
|  |       <BaseButton | ||||||
|  |         type="submit" | ||||||
|  |         variant="primary-outline" | ||||||
|  |         @click="openMailSenderModal" | ||||||
|  |       > | ||||||
|  |         <template #left="slotProps"> | ||||||
|  |           <BaseIcon :class="slotProps.class" name="PlusIcon" /> | ||||||
|  |         </template> | ||||||
|  |         {{ $t(`${pre_t}.add_new_mail_sender`) }} | ||||||
|  |       </BaseButton> | ||||||
|  |     </template> | ||||||
|  |  | ||||||
|  |     <BaseTable | ||||||
|  |       ref="table" | ||||||
|  |       class="mt-16" | ||||||
|  |       :data="fetchData" | ||||||
|  |       :columns="mailSenderColumns" | ||||||
|  |     > | ||||||
|  |       <template #cell-is_default="{ row }"> | ||||||
|  |         <BaseBadge | ||||||
|  |           :bg-color=" | ||||||
|  |             utils.getBadgeStatusColor(row.data.is_default ? 'YES' : 'NO') | ||||||
|  |               .bgColor | ||||||
|  |           " | ||||||
|  |           :color=" | ||||||
|  |             utils.getBadgeStatusColor(row.data.is_default ? 'YES' : 'NO').color | ||||||
|  |           " | ||||||
|  |         > | ||||||
|  |           {{ row.data.is_default ? $t('general.yes') : $t('general.no') }} | ||||||
|  |         </BaseBadge> | ||||||
|  |       </template> | ||||||
|  |  | ||||||
|  |       <template #cell-actions="{ row }"> | ||||||
|  |         <MailSenderDropdown | ||||||
|  |           :row="row.data" | ||||||
|  |           :table="table" | ||||||
|  |           :load-data="refreshTable" | ||||||
|  |         /> | ||||||
|  |       </template> | ||||||
|  |     </BaseTable> | ||||||
|  |   </BaseSettingCard> | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <script setup> | ||||||
|  | import { computed, ref, inject } from 'vue' | ||||||
|  | import { useI18n } from 'vue-i18n' | ||||||
|  | import { useModalStore } from '@/scripts/stores/modal' | ||||||
|  | import MailSenderModal from '@/scripts/admin/components/modal-components/MailSenderModal.vue' | ||||||
|  | import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender' | ||||||
|  | import MailSenderDropdown from '@/scripts/admin/components/dropdowns/MailSenderIndexDropdown.vue' | ||||||
|  | import MailSenderTestModal from '@/scripts/admin/components/modal-components/MailSenderTestModal.vue' | ||||||
|  |  | ||||||
|  | const pre_t = 'settings.mail_sender' | ||||||
|  | const modalStore = useModalStore() | ||||||
|  | const mailSenderStore = useMailSenderStore() | ||||||
|  | const { t } = useI18n() | ||||||
|  | const table = ref(null) | ||||||
|  | const utils = inject('utils') | ||||||
|  |  | ||||||
|  | function openMailSenderModal() { | ||||||
|  |   modalStore.openModal({ | ||||||
|  |     title: t(`${pre_t}.add_new_mail_sender`), | ||||||
|  |     componentName: 'MailSenderModal', | ||||||
|  |     size: 'md', | ||||||
|  |     refreshData: refreshTable, | ||||||
|  |   }) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | const mailSenderColumns = computed(() => { | ||||||
|  |   return [ | ||||||
|  |     { | ||||||
|  |       key: 'name', | ||||||
|  |       label: t(`${pre_t}.name`), | ||||||
|  |       thClass: 'extra', | ||||||
|  |       tdClass: 'font-medium text-gray-900', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       key: 'driver', | ||||||
|  |       label: t(`${pre_t}.driver`), | ||||||
|  |       thClass: 'extra', | ||||||
|  |       tdClass: 'font-medium text-gray-900', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       key: 'from_address', | ||||||
|  |       label: t(`${pre_t}.from_address`), | ||||||
|  |       thClass: 'extra', | ||||||
|  |       tdClass: 'font-medium text-gray-900', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       key: 'is_default', | ||||||
|  |       label: t(`${pre_t}.is_default`), | ||||||
|  |       thClass: 'extra', | ||||||
|  |       tdClass: 'font-medium text-gray-900', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       key: 'actions', | ||||||
|  |       label: '', | ||||||
|  |       tdClass: 'text-right text-sm font-medium', | ||||||
|  |       sortable: false, | ||||||
|  |     }, | ||||||
|  |   ] | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | async function fetchData({ page, filter, sort }) { | ||||||
|  |   let data = { | ||||||
|  |     orderByField: sort.fieldName || 'created_at', | ||||||
|  |     orderBy: sort.order || 'desc', | ||||||
|  |     page, | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   let response = await mailSenderStore.fetchMailSenders(data) | ||||||
|  |  | ||||||
|  |   return { | ||||||
|  |     data: response.data.data, | ||||||
|  |     pagination: { | ||||||
|  |       totalPages: response.data.meta.last_page, | ||||||
|  |       currentPage: page, | ||||||
|  |       totalCount: response.data.meta.total, | ||||||
|  |       limit: response.data.meta.per_page ? response.data.meta.per_page : 10, | ||||||
|  |     }, | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function refreshTable() { | ||||||
|  |   table.value && table.value.refresh() | ||||||
|  | } | ||||||
|  | </script> | ||||||
| @ -0,0 +1,104 @@ | |||||||
|  | <template> | ||||||
|  |   <!-- Domain --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.domain`)" | ||||||
|  |     :error="v$.domain.$error && v$.domain.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model.trim="mailSenderStore.mailgunConfig.domain" | ||||||
|  |       :invalid="v$.domain.$error" | ||||||
|  |       type="text" | ||||||
|  |       @input="v$.domain.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- Mailgun Secret --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.secret`)" | ||||||
|  |     :error="v$.secret.$error && v$.secret.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model="mailSenderStore.mailgunConfig.secret" | ||||||
|  |       :type="getInputType" | ||||||
|  |       autocomplete="off" | ||||||
|  |       :invalid="v$.secret.$error" | ||||||
|  |       @input="v$.secret.$touch()" | ||||||
|  |     > | ||||||
|  |       <template #right> | ||||||
|  |         <BaseIcon | ||||||
|  |           v-if="isShowPassword" | ||||||
|  |           class="mr-1 text-gray-500 cursor-pointer" | ||||||
|  |           name="EyeOffIcon" | ||||||
|  |           @click="isShowPassword = !isShowPassword" | ||||||
|  |         /> | ||||||
|  |         <BaseIcon | ||||||
|  |           v-else | ||||||
|  |           class="mr-1 text-gray-500 cursor-pointer" | ||||||
|  |           name="EyeIcon" | ||||||
|  |           @click="isShowPassword = !isShowPassword" | ||||||
|  |         /> | ||||||
|  |       </template> | ||||||
|  |     </BaseInput> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- Mailgun Endpoint --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.endpoint`)" | ||||||
|  |     :error="v$.endpoint.$error && v$.endpoint.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model.trim="mailSenderStore.mailgunConfig.endpoint" | ||||||
|  |       type="text" | ||||||
|  |       :invalid="v$.endpoint.$error" | ||||||
|  |       @input="v$.endpoint.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <script setup> | ||||||
|  | import { computed, ref } from "vue" | ||||||
|  | import { useI18n } from "vue-i18n" | ||||||
|  | import { required, email, numeric, helpers } from "@vuelidate/validators" | ||||||
|  | import { useVuelidate } from "@vuelidate/core" | ||||||
|  |  | ||||||
|  | const pre_t = "settings.mail_sender.mailgun_config" | ||||||
|  | const { t } = useI18n() | ||||||
|  |  | ||||||
|  | const props = defineProps({ | ||||||
|  |   mailSenderStore: { | ||||||
|  |     type: Object, | ||||||
|  |     require: true, | ||||||
|  |     default: Object, | ||||||
|  |   }, | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | let isShowPassword = ref(false) | ||||||
|  | const getInputType = computed(() => { | ||||||
|  |   if (isShowPassword.value) { | ||||||
|  |     return "text" | ||||||
|  |   } | ||||||
|  |   return "password" | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const rules = computed(() => { | ||||||
|  |   return { | ||||||
|  |     domain: { | ||||||
|  |       required: helpers.withMessage(t("validation.required"), required), | ||||||
|  |     }, | ||||||
|  |     endpoint: { | ||||||
|  |       required: helpers.withMessage(t("validation.required"), required), | ||||||
|  |     }, | ||||||
|  |     secret: { | ||||||
|  |       required: helpers.withMessage(t("validation.required"), required), | ||||||
|  |     }, | ||||||
|  |   } | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const v$ = useVuelidate( | ||||||
|  |   rules, | ||||||
|  |   computed(() => props.mailSenderStore.mailgunConfig) | ||||||
|  | ) | ||||||
|  | </script> | ||||||
							
								
								
									
										143
									
								
								resources/scripts/admin/views/settings/mail-sender/SesDriver.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								resources/scripts/admin/views/settings/mail-sender/SesDriver.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,143 @@ | |||||||
|  | <template> | ||||||
|  |   <!-- Host --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.host`)" | ||||||
|  |     :error="v$.host.$error && v$.host.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model.trim="mailSenderStore.sesConfig.host" | ||||||
|  |       :invalid="v$.host.$error" | ||||||
|  |       type="text" | ||||||
|  |       @input="v$.host.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- Port --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.port`)" | ||||||
|  |     :error="v$.port.$error && v$.port.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model.trim="mailSenderStore.sesConfig.port" | ||||||
|  |       type="text" | ||||||
|  |       :invalid="v$.port.$error" | ||||||
|  |       @input="v$.port.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- Encryption --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.encryption`)" | ||||||
|  |     :error="v$.encryption.$error && v$.encryption.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseMultiselect | ||||||
|  |       v-model.trim="mailSenderStore.sesConfig.encryption" | ||||||
|  |       :options="encryptions" | ||||||
|  |       :searchable="true" | ||||||
|  |       :show-labels="false" | ||||||
|  |       :placeholder="$t('general.select_option')" | ||||||
|  |       :invalid="v$.encryption.$error" | ||||||
|  |       @input="v$.encryption.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- SES Key --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.ses_key`)" | ||||||
|  |     :error="v$.ses_key.$error && v$.ses_key.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model.trim="mailSenderStore.sesConfig.ses_key" | ||||||
|  |       type="text" | ||||||
|  |       :invalid="v$.ses_key.$error" | ||||||
|  |       @input="v$.ses_key.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- SES Secret --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.ses_secret`)" | ||||||
|  |     :error="v$.ses_secret.$error && v$.ses_secret.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model="mailSenderStore.sesConfig.ses_secret" | ||||||
|  |       :type="getInputType" | ||||||
|  |       autocomplete="off" | ||||||
|  |       :invalid="v$.ses_secret.$error" | ||||||
|  |       @input="v$.ses_secret.$touch()" | ||||||
|  |     > | ||||||
|  |       <template #right> | ||||||
|  |         <BaseIcon | ||||||
|  |           v-if="isShowPassword" | ||||||
|  |           class="mr-1 text-gray-500 cursor-pointer" | ||||||
|  |           name="EyeOffIcon" | ||||||
|  |           @click="isShowPassword = !isShowPassword" | ||||||
|  |         /> | ||||||
|  |         <BaseIcon | ||||||
|  |           v-else | ||||||
|  |           class="mr-1 text-gray-500 cursor-pointer" | ||||||
|  |           name="EyeIcon" | ||||||
|  |           @click="isShowPassword = !isShowPassword" | ||||||
|  |         /> | ||||||
|  |       </template> | ||||||
|  |     </BaseInput> | ||||||
|  |   </BaseInputGroup> | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <script setup> | ||||||
|  | import { computed, ref, reactive } from 'vue' | ||||||
|  | import { useI18n } from 'vue-i18n' | ||||||
|  | import { required, email, numeric, helpers } from '@vuelidate/validators' | ||||||
|  | import { useVuelidate } from '@vuelidate/core' | ||||||
|  |  | ||||||
|  | const pre_t = 'settings.mail_sender.ses_config' | ||||||
|  | const { t } = useI18n() | ||||||
|  |  | ||||||
|  | const props = defineProps({ | ||||||
|  |   mailSenderStore: { | ||||||
|  |     type: Object, | ||||||
|  |     require: true, | ||||||
|  |     default: Object, | ||||||
|  |   }, | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | let isShowPassword = ref(false) | ||||||
|  | const getInputType = computed(() => { | ||||||
|  |   if (isShowPassword.value) { | ||||||
|  |     return 'text' | ||||||
|  |   } | ||||||
|  |   return 'password' | ||||||
|  | }) | ||||||
|  | const encryptions = props.mailSenderStore.mail_encryptions | ||||||
|  |  | ||||||
|  | const rules = computed(() => { | ||||||
|  |   return { | ||||||
|  |     host: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |     port: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |       numeric, | ||||||
|  |     }, | ||||||
|  |     encryption: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |     ses_key: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |     ses_secret: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |   } | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const v$ = useVuelidate( | ||||||
|  |   rules, | ||||||
|  |   computed(() => props.mailSenderStore.sesConfig) | ||||||
|  | ) | ||||||
|  | </script> | ||||||
| @ -0,0 +1,120 @@ | |||||||
|  | <template> | ||||||
|  |   <!-- Host --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.host`)" | ||||||
|  |     :error="v$.host.$error && v$.host.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model.trim="mailSenderStore.smtpConfig.host" | ||||||
|  |       :invalid="v$.host.$error" | ||||||
|  |       type="text" | ||||||
|  |       @input="v$.host.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- Port --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.port`)" | ||||||
|  |     :error="v$.port.$error && v$.port.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseInput | ||||||
|  |       v-model.trim="mailSenderStore.smtpConfig.port" | ||||||
|  |       type="text" | ||||||
|  |       :invalid="v$.port.$error" | ||||||
|  |       @input="v$.port.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- Username --> | ||||||
|  |   <BaseInputGroup :label="$t(`${pre_t}.username`)"> | ||||||
|  |     <BaseInput v-model.trim="mailSenderStore.smtpConfig.username" type="text" /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- Password --> | ||||||
|  |   <BaseInputGroup :label="$t(`${pre_t}.password`)"> | ||||||
|  |     <BaseInput | ||||||
|  |       v-model="mailSenderStore.smtpConfig.password" | ||||||
|  |       :type="getInputType" | ||||||
|  |     > | ||||||
|  |       <template #right> | ||||||
|  |         <BaseIcon | ||||||
|  |           v-if="isShowPassword" | ||||||
|  |           class="mr-1 text-gray-500 cursor-pointer" | ||||||
|  |           name="EyeOffIcon" | ||||||
|  |           @click="isShowPassword = !isShowPassword" | ||||||
|  |         /> | ||||||
|  |         <BaseIcon | ||||||
|  |           v-else | ||||||
|  |           class="mr-1 text-gray-500 cursor-pointer" | ||||||
|  |           name="EyeIcon" | ||||||
|  |           @click="isShowPassword = !isShowPassword" | ||||||
|  |         /> | ||||||
|  |       </template> | ||||||
|  |     </BaseInput> | ||||||
|  |   </BaseInputGroup> | ||||||
|  |  | ||||||
|  |   <!-- Encryption --> | ||||||
|  |   <BaseInputGroup | ||||||
|  |     :label="$t(`${pre_t}.encryption`)" | ||||||
|  |     :error="v$.encryption.$error && v$.encryption.$errors[0].$message" | ||||||
|  |     required | ||||||
|  |   > | ||||||
|  |     <BaseMultiselect | ||||||
|  |       v-model.trim="mailSenderStore.smtpConfig.encryption" | ||||||
|  |       :options="encryptions" | ||||||
|  |       :searchable="true" | ||||||
|  |       :show-labels="false" | ||||||
|  |       :placeholder="$t('general.select_option')" | ||||||
|  |       :invalid="v$.encryption.$error" | ||||||
|  |       @input="v$.encryption.$touch()" | ||||||
|  |     /> | ||||||
|  |   </BaseInputGroup> | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <script setup> | ||||||
|  | import { computed, ref, reactive } from 'vue' | ||||||
|  | import { useI18n } from 'vue-i18n' | ||||||
|  | import { required, numeric, helpers } from '@vuelidate/validators' | ||||||
|  | import { useVuelidate } from '@vuelidate/core' | ||||||
|  |  | ||||||
|  | const pre_t = 'settings.mail_sender.smtp_config' | ||||||
|  | const { t } = useI18n() | ||||||
|  |  | ||||||
|  | const props = defineProps({ | ||||||
|  |   mailSenderStore: { | ||||||
|  |     type: Object, | ||||||
|  |     require: true, | ||||||
|  |     default: Object, | ||||||
|  |   }, | ||||||
|  | }) | ||||||
|  | let isShowPassword = ref(false) | ||||||
|  | const getInputType = computed(() => { | ||||||
|  |   if (isShowPassword.value) { | ||||||
|  |     return 'text' | ||||||
|  |   } | ||||||
|  |   return 'password' | ||||||
|  | }) | ||||||
|  | const encryptions = props.mailSenderStore.mail_encryptions | ||||||
|  |  | ||||||
|  | const rules = computed(() => { | ||||||
|  |   return { | ||||||
|  |     host: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |     port: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |       numeric: helpers.withMessage(t('validation.numbers_only'), numeric), | ||||||
|  |     }, | ||||||
|  |     encryption: { | ||||||
|  |       required: helpers.withMessage(t('validation.required'), required), | ||||||
|  |     }, | ||||||
|  |   } | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const v$ = useVuelidate( | ||||||
|  |   rules, | ||||||
|  |   computed(() => props.mailSenderStore.smtpConfig) | ||||||
|  | ) | ||||||
|  | </script> | ||||||
| @ -162,7 +162,7 @@ | |||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script setup> | <script setup> | ||||||
| import { ref, computed, reactive } from 'vue' | import { ref, computed, reactive, onMounted } from 'vue' | ||||||
| import { useRouter, useRoute } from 'vue-router' | import { useRouter, useRoute } from 'vue-router' | ||||||
| import { useCompanyStore } from '@/scripts/admin/stores/company' | import { useCompanyStore } from '@/scripts/admin/stores/company' | ||||||
| import { | import { | ||||||
|  | |||||||
| @ -1,101 +0,0 @@ | |||||||
| <!-- This example requires Tailwind CSS v2.0+ --> |  | ||||||
| <script lang="ts" setup> |  | ||||||
| import { Switch, SwitchGroup, SwitchLabel } from '@headlessui/vue' |  | ||||||
| import { useGlobalStore } from '@/scripts/admin/stores/global' |  | ||||||
| import { computed, ref } from 'vue' |  | ||||||
| defineProps({ |  | ||||||
|   showLabel: { |  | ||||||
|     type: Boolean, |  | ||||||
|     default: true, |  | ||||||
|   }, |  | ||||||
|   vertical: { |  | ||||||
|     type: Boolean, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const globalStore = useGlobalStore() |  | ||||||
|  |  | ||||||
| const enabled = ref( |  | ||||||
|   localStorage.getItem('theme') === 'dark' || |  | ||||||
|     document.documentElement.classList.contains('dark') |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| globalStore.isDarkModeOn = enabled |  | ||||||
|  |  | ||||||
| function onChange(val) { |  | ||||||
|   if (val) { |  | ||||||
|     localStorage.theme = 'dark' |  | ||||||
|     document.documentElement.classList.add('dark') |  | ||||||
|     document.documentElement.style.setProperty('color-scheme', 'dark') |  | ||||||
|     globalStore.isDarkModeOn = true |  | ||||||
|   } else { |  | ||||||
|     localStorage.theme = 'light' |  | ||||||
|     document.documentElement.classList.remove('dark') |  | ||||||
|     document.documentElement.style.setProperty('color-scheme', 'light') |  | ||||||
|     globalStore.isDarkModeOn = false |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| </script> |  | ||||||
|  |  | ||||||
| <template> |  | ||||||
|   <div class="w-full flex justify-center"> |  | ||||||
|     <SwitchGroup |  | ||||||
|       as="div" |  | ||||||
|       class="flex items-center" |  | ||||||
|       :class="vertical ? 'flex-col justify-center' : 'flex-row'" |  | ||||||
|     > |  | ||||||
|       <Switch |  | ||||||
|         v-model="enabled" |  | ||||||
|         class="relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 dark:ring-offset-gray-700" |  | ||||||
|         :class="[enabled ? 'bg-primary-600' : 'bg-gray-200']" |  | ||||||
|         @update:modelValue="onChange" |  | ||||||
|       > |  | ||||||
|         <span class="sr-only">Use setting</span> |  | ||||||
|         <span |  | ||||||
|           class="pointer-events-none relative inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200" |  | ||||||
|           :class="[enabled ? 'translate-x-5' : 'translate-x-0']" |  | ||||||
|         > |  | ||||||
|           <span |  | ||||||
|             class="absolute inset-0 h-full w-full flex items-center justify-center transition-opacity" |  | ||||||
|             :class="[ |  | ||||||
|               enabled |  | ||||||
|                 ? 'opacity-0 ease-out duration-100' |  | ||||||
|                 : 'opacity-100 ease-in duration-200', |  | ||||||
|             ]" |  | ||||||
|             aria-hidden="true" |  | ||||||
|           > |  | ||||||
|             <BaseIcon class="h-3 w-3 text-yellow-500" name="SunIcon" /> |  | ||||||
|           </span> |  | ||||||
|           <span |  | ||||||
|             class="absolute inset-0 h-full w-full flex items-center justify-center transition-opacity" |  | ||||||
|             :class="[ |  | ||||||
|               enabled |  | ||||||
|                 ? 'opacity-100 ease-in duration-200' |  | ||||||
|                 : 'opacity-0 ease-out duration-100', |  | ||||||
|             ]" |  | ||||||
|             aria-hidden="true" |  | ||||||
|           > |  | ||||||
|             <BaseIcon class="h-3 w-3 text-primary-500" name="MoonIcon" /> |  | ||||||
|           </span> |  | ||||||
|         </span> |  | ||||||
|       </Switch> |  | ||||||
|       <SwitchLabel |  | ||||||
|         v-if="showLabel" |  | ||||||
|         as="span" |  | ||||||
|         class="cursor-pointer" |  | ||||||
|         :class="vertical ? 'px-1 text-center mt-2' : 'ml-3'" |  | ||||||
|       > |  | ||||||
|         <span |  | ||||||
|           v-if="enabled" |  | ||||||
|           class="text-sm font-medium text-gray-500 dark:text-gray-400" |  | ||||||
|         > |  | ||||||
|           Dark Mode |  | ||||||
|         </span> |  | ||||||
|         <span v-else class="text-sm font-medium text-gray-500"> |  | ||||||
|           Light Mode |  | ||||||
|         </span> |  | ||||||
|       </SwitchLabel> |  | ||||||
|     </SwitchGroup> |  | ||||||
|   </div> |  | ||||||
| </template> |  | ||||||
| @ -126,7 +126,7 @@ onMounted(() => { | |||||||
| }) | }) | ||||||
|  |  | ||||||
| const value = computed({ | const value = computed({ | ||||||
|   get: () => (props.modelValue ? props.modelValue : ''), |   get: () => props.modelValue, | ||||||
|   set: (value) => { |   set: (value) => { | ||||||
|     emit('update:modelValue', value) |     emit('update:modelValue', value) | ||||||
|   }, |   }, | ||||||
| @ -195,9 +195,7 @@ async function getFields() { | |||||||
|           { label: 'Date', value: 'INVOICE_DATE' }, |           { label: 'Date', value: 'INVOICE_DATE' }, | ||||||
|           { label: 'Due Date', value: 'INVOICE_DUE_DATE' }, |           { label: 'Due Date', value: 'INVOICE_DUE_DATE' }, | ||||||
|           { label: 'Number', value: 'INVOICE_NUMBER' }, |           { label: 'Number', value: 'INVOICE_NUMBER' }, | ||||||
|           { label: 'PDF Link', value: 'PDF_LINK' }, |           { label: 'Ref Number', value: 'INVOICE_REF_NUMBER' }, | ||||||
|           { label: 'Due Amount', value: 'DUE_AMOUNT' }, |  | ||||||
|           { label: 'Total Amount', value: 'TOTAL_AMOUNT' }, |  | ||||||
|           ...invoiceFields.value.map((i) => ({ |           ...invoiceFields.value.map((i) => ({ | ||||||
|             label: i.label, |             label: i.label, | ||||||
|             value: i.slug, |             value: i.slug, | ||||||
| @ -213,8 +211,7 @@ async function getFields() { | |||||||
|           { label: 'Date', value: 'ESTIMATE_DATE' }, |           { label: 'Date', value: 'ESTIMATE_DATE' }, | ||||||
|           { label: 'Expiry Date', value: 'ESTIMATE_EXPIRY_DATE' }, |           { label: 'Expiry Date', value: 'ESTIMATE_EXPIRY_DATE' }, | ||||||
|           { label: 'Number', value: 'ESTIMATE_NUMBER' }, |           { label: 'Number', value: 'ESTIMATE_NUMBER' }, | ||||||
|           { label: 'PDF Link', value: 'PDF_LINK' }, |           { label: 'Ref Number', value: 'ESTIMATE_REF_NUMBER' }, | ||||||
|           { label: 'Total Amount', value: 'TOTAL_AMOUNT' }, |  | ||||||
|           ...estimateFields.value.map((i) => ({ |           ...estimateFields.value.map((i) => ({ | ||||||
|             label: i.label, |             label: i.label, | ||||||
|             value: i.slug, |             value: i.slug, | ||||||
| @ -231,7 +228,6 @@ async function getFields() { | |||||||
|           { label: 'Number', value: 'PAYMENT_NUMBER' }, |           { label: 'Number', value: 'PAYMENT_NUMBER' }, | ||||||
|           { label: 'Mode', value: 'PAYMENT_MODE' }, |           { label: 'Mode', value: 'PAYMENT_MODE' }, | ||||||
|           { label: 'Amount', value: 'PAYMENT_AMOUNT' }, |           { label: 'Amount', value: 'PAYMENT_AMOUNT' }, | ||||||
|           { label: 'PDF Link', value: 'PDF_LINK' }, |  | ||||||
|           ...paymentFields.value.map((i) => ({ |           ...paymentFields.value.map((i) => ({ | ||||||
|             label: i.label, |             label: i.label, | ||||||
|             value: i.slug, |             value: i.slug, | ||||||
|  | |||||||
| @ -7,108 +7,52 @@ | |||||||
|     /> |     /> | ||||||
|   </BaseContentPlaceholders> |   </BaseContentPlaceholders> | ||||||
|  |  | ||||||
|   <div v-else :class="computedContainerClass"> |   <div v-else :class="computedContainerClass" class="relative flex flex-row"> | ||||||
|     <date-picker |     <svg | ||||||
|       ref="vCalendar" |       v-if="showCalendarIcon && !hasIconSlot" | ||||||
|       v-model="date" |       viewBox="0 0 20 20" | ||||||
|       :mode="mode" |       fill="currentColor" | ||||||
|       :is24hr="time24hr" |       class=" | ||||||
|       class="w-full" |         absolute | ||||||
|       color="indigo" |         w-4 | ||||||
|       :input-debounce="500" |         h-4 | ||||||
|       :update-on-input="false" |         mx-2 | ||||||
|       :is-range="false" |         my-2.5 | ||||||
|       trim-weeks |         text-sm | ||||||
|       :is-required="isRequired" |         not-italic | ||||||
|       :popover="{ |         font-black | ||||||
|         visibility: disabled ? 'hidden' : 'focus', |         text-gray-400 | ||||||
|         showDelay: 0, |         cursor-pointer | ||||||
|         hideDelay: 1, |       " | ||||||
|       }" |       @click="onClickDp" | ||||||
|       :attributes="attrs" |  | ||||||
|       :model-config="config" |  | ||||||
|       :masks="masks" |  | ||||||
|       :locale="global.locale" |  | ||||||
|     > |     > | ||||||
|       <template |       <path | ||||||
|         #default="{ inputValue, inputEvents, togglePopover, hidePopover }" |         fill-rule="evenodd" | ||||||
|       > |         d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" | ||||||
|         <!-- calendar icon --> |         clip-rule="evenodd" | ||||||
|         <svg |       ></path> | ||||||
|           v-if="showCalendarIcon && !hasIconSlot" |     </svg> | ||||||
|           viewBox="0 0 20 20" |  | ||||||
|           fill="currentColor" |  | ||||||
|           class=" |  | ||||||
|             absolute |  | ||||||
|             w-4 |  | ||||||
|             h-4 |  | ||||||
|             mx-2 |  | ||||||
|             my-2.5 |  | ||||||
|             text-sm |  | ||||||
|             not-italic |  | ||||||
|             font-black |  | ||||||
|             text-gray-400 |  | ||||||
|             cursor-pointer |  | ||||||
|           " |  | ||||||
|           @click="togglePopover()" |  | ||||||
|         > |  | ||||||
|           <path |  | ||||||
|             fill-rule="evenodd" |  | ||||||
|             d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" |  | ||||||
|             clip-rule="evenodd" |  | ||||||
|           ></path> |  | ||||||
|         </svg> |  | ||||||
|  |  | ||||||
|         <slot v-if="showCalendarIcon && hasIconSlot" name="icon" /> |     <slot v-if="showCalendarIcon && hasIconSlot" name="icon" /> | ||||||
|  |  | ||||||
|         <input |     <FlatPickr | ||||||
|           :value="inputValue" |       ref="dp" | ||||||
|           :class="[defaultInputClass, inputInvalidClass, inputDisabledClass]" |       v-model="date" | ||||||
|           readonly |       v-bind="$attrs" | ||||||
|           v-on="inputEvents" |       :disabled="disabled" | ||||||
|           @blur="hidePopover()" |       :config="config" | ||||||
|         /> |       :class="[defaultInputClass, inputInvalidClass, inputDisabledClass]" | ||||||
|       </template> |     /> | ||||||
|  |  | ||||||
|       <template v-if="showExtraOptions" #footer> |  | ||||||
|         <div |  | ||||||
|           class="bg-gray-100 grid grid-cols-3 gap-2 p-2 border-t rounded-b-lg" |  | ||||||
|         > |  | ||||||
|           <button type="button" class="extra-button" @click="moveToDate(sourceDate)"> |  | ||||||
|             {{ global.t('date_picker.same_day') }} |  | ||||||
|           </button> |  | ||||||
|  |  | ||||||
|           <button type="button" class="extra-button" @click="withInDays(7)"> |  | ||||||
|             {{ global.t('date_picker.within_7_days') }} |  | ||||||
|           </button> |  | ||||||
|  |  | ||||||
|           <button type="button" class="extra-button" @click="withInDays(15)"> |  | ||||||
|             {{ global.t('date_picker.within_15_days') }} |  | ||||||
|           </button> |  | ||||||
|  |  | ||||||
|           <button type="button" class="extra-button" @click="withInDays(30)"> |  | ||||||
|             {{ global.t('date_picker.within_30_days') }} |  | ||||||
|           </button> |  | ||||||
|  |  | ||||||
|           <button type="button" class="extra-button" @click="withInDays(45)"> |  | ||||||
|             {{ global.t('date_picker.within_45_days') }} |  | ||||||
|           </button> |  | ||||||
|  |  | ||||||
|           <button type="button" class="extra-button" @click="withInDays(60)"> |  | ||||||
|             {{ global.t('date_picker.within_60_days') }} |  | ||||||
|           </button> |  | ||||||
|         </div> |  | ||||||
|       </template> |  | ||||||
|     </date-picker> |  | ||||||
|   </div> |   </div> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script type="text/babel" setup> | <script type="text/babel" setup> | ||||||
| import { Calendar, DatePicker } from 'v-calendar' | import FlatPickr from 'vue-flatpickr-component' | ||||||
| import 'v-calendar/dist/style.css' | import 'flatpickr/dist/flatpickr.css' | ||||||
| import { computed, reactive, watch, ref, useSlots } from 'vue' | import { computed, reactive, watch, ref, useSlots } from 'vue' | ||||||
| import { useCompanyStore } from '@/scripts/admin/stores/company' | import { useCompanyStore } from '@/scripts/admin/stores/company' | ||||||
| import moment from 'moment' |  | ||||||
|  | const dp = ref(null) | ||||||
|  |  | ||||||
| const props = defineProps({ | const props = defineProps({ | ||||||
|   modelValue: { |   modelValue: { | ||||||
| @ -146,31 +90,36 @@ const props = defineProps({ | |||||||
|   defaultInputClass: { |   defaultInputClass: { | ||||||
|     type: String, |     type: String, | ||||||
|     default: |     default: | ||||||
|       'border-2 font-base pl-8 py-2 outline-none focus:ring-primary-400 focus:outline-none focus:border-primary-400 block w-full sm:text-sm border-gray-200 rounded-md text-black', |       'font-base pl-8 py-2 outline-none focus:ring-primary-400 focus:outline-none focus:border-primary-400 block w-full sm:text-sm border-gray-200 rounded-md text-black', | ||||||
|   }, |   }, | ||||||
|   time24hr: { |   time24hr: { | ||||||
|     type: Boolean, |     type: Boolean, | ||||||
|     default: false, |     default: false, | ||||||
|   }, |   }, | ||||||
|   isRequired: { |  | ||||||
|     type: Boolean, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   showExtraOptions: { |  | ||||||
|     type: Boolean, |  | ||||||
|     default: false, |  | ||||||
|   }, |  | ||||||
|   sourceDate: { |  | ||||||
|     type: [String, Date], |  | ||||||
|     default: () => new Date(), |  | ||||||
|   } |  | ||||||
| }) | }) | ||||||
|  |  | ||||||
| const emit = defineEmits(['update:modelValue']) | const emit = defineEmits(['update:modelValue']) | ||||||
|  |  | ||||||
| const slots = useSlots() | const slots = useSlots() | ||||||
|  |  | ||||||
| const companyStore = useCompanyStore() | const companyStore = useCompanyStore() | ||||||
| const { global } = window.i18n |  | ||||||
| const vCalendar = ref(null) | let config = reactive({ | ||||||
|  |   altInput: true, | ||||||
|  |   enableTime: props.enableTime, | ||||||
|  |   time_24hr: props.time24hr, | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const date = computed({ | ||||||
|  |   get: () => props.modelValue, | ||||||
|  |   set: (value) => { | ||||||
|  |     emit('update:modelValue', value) | ||||||
|  |   }, | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | const carbonFormat = computed(() => { | ||||||
|  |   return companyStore.selectedCompanySettings?.carbon_date_format | ||||||
|  | }) | ||||||
|  |  | ||||||
| const hasIconSlot = computed(() => { | const hasIconSlot = computed(() => { | ||||||
|   return !!slots.icon |   return !!slots.icon | ||||||
| @ -186,6 +135,7 @@ const inputInvalidClass = computed(() => { | |||||||
|   if (props.invalid) { |   if (props.invalid) { | ||||||
|     return 'border-red-400 ring-red-400 focus:ring-red-400 focus:border-red-400' |     return 'border-red-400 ring-red-400 focus:ring-red-400 focus:border-red-400' | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   return '' |   return '' | ||||||
| }) | }) | ||||||
|  |  | ||||||
| @ -193,97 +143,35 @@ const inputDisabledClass = computed(() => { | |||||||
|   if (props.disabled) { |   if (props.disabled) { | ||||||
|     return 'border border-solid rounded-md outline-none input-field box-border-2 base-date-picker-input placeholder-gray-400 bg-gray-200 text-gray-600 border-gray-200' |     return 'border border-solid rounded-md outline-none input-field box-border-2 base-date-picker-input placeholder-gray-400 bg-gray-200 text-gray-600 border-gray-200' | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   return '' |   return '' | ||||||
| }) | }) | ||||||
|  |  | ||||||
| // to convert YYYY-MM-DD | YYYY-MM-DD HH:mm format | function onClickDp(params) { | ||||||
| function convertYMDFormat(date) { |   dp.value.fp.open() | ||||||
|   let format = props.enableTime ? 'YYYY-MM-DD HH:mm' : 'YYYY-MM-DD' |  | ||||||
|   return date ? moment(date).format(format) : date |  | ||||||
| } | } | ||||||
|  |  | ||||||
| const date = computed({ |  | ||||||
|   get: () => props.modelValue, |  | ||||||
|   set: (value) => { |  | ||||||
|     emit('update:modelValue', value) |  | ||||||
|   }, |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const mode = computed(() => { |  | ||||||
|   return props.enableTime ? 'dateTime' : 'date' |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const config = reactive({ |  | ||||||
|   type: 'string', |  | ||||||
|   mask: 'YYYY-MM-DD', // Uses 'iso' if missing |  | ||||||
|   //timeAdjust: '00:00:00', |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const masks = reactive({ |  | ||||||
|   input: null, |  | ||||||
|   inputDateTime: null, |  | ||||||
|   inputDateTime24hr: null, |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| const attrs = reactive([ |  | ||||||
|   { |  | ||||||
|     dates: new Date(), |  | ||||||
|     highlight: { |  | ||||||
|       fillMode: 'outline', |  | ||||||
|     }, |  | ||||||
|     /* popover: { |  | ||||||
|       label: 'Today Date', |  | ||||||
|       visibility: 'hover', |  | ||||||
|     }, */ |  | ||||||
|   }, |  | ||||||
| ]) |  | ||||||
|  |  | ||||||
| const carbonFormat = computed(() => { |  | ||||||
|   return companyStore.selectedCompanySettings?.moment_date_format |  | ||||||
| }) |  | ||||||
|  |  | ||||||
| watch( | watch( | ||||||
|   () => carbonFormat, |   () => props.enableTime, | ||||||
|   () => { |   (val) => { | ||||||
|     if (!props.enableTime) { |     if (props.enableTime) { | ||||||
|       masks.input = carbonFormat.value ? carbonFormat.value : 'DD MMM YYYY' |       config.enableTime = props.enableTime | ||||||
|       config.mask = 'YYYY-MM-DD' |  | ||||||
|     } else { |  | ||||||
|       let timeFormat = 'HH:mm' |  | ||||||
|       if (props.time24hr) { |  | ||||||
|         masks.inputDateTime24hr = carbonFormat.value |  | ||||||
|           ? `${carbonFormat.value} ${timeFormat}` |  | ||||||
|           : `DD MMM YYYY ${timeFormat}` |  | ||||||
|       } else { |  | ||||||
|         masks.inputDateTime = carbonFormat.value |  | ||||||
|           ? `${carbonFormat.value} ${timeFormat}` |  | ||||||
|           : `DD MMM YYYY ${timeFormat}` |  | ||||||
|       } |  | ||||||
|       config.mask = `YYYY-MM-DD ${timeFormat}` |  | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   { immediate: true } |   { immediate: true } | ||||||
| ) | ) | ||||||
|  |  | ||||||
| async function moveToDate(_date) { | watch( | ||||||
|   const calendar = vCalendar.value |   () => carbonFormat, | ||||||
|   _date = _date ? _date : convertYMDFormat(new Date()) |   () => { | ||||||
|   date.value = _date |     if (!props.enableTime) { | ||||||
|   // await calendar.move(_date) |       config.altFormat = carbonFormat.value ? carbonFormat.value : 'd M Y' | ||||||
|   calendar.hidePopover() |     } else { | ||||||
| } |       config.altFormat = carbonFormat.value | ||||||
|  |         ? `${carbonFormat.value} H:i ` | ||||||
| async function withInDays(noOfDays) { |         : 'd M Y H:i' | ||||||
|   if (!noOfDays) return false |     } | ||||||
|  |   }, | ||||||
|   let newDate = moment(props.sourceDate).add(noOfDays, 'days').toDate() |   { immediate: true } | ||||||
|   newDate = convertYMDFormat(newDate) | ) | ||||||
|   moveToDate(newDate) |  | ||||||
| } |  | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <style scoped> |  | ||||||
| .extra-button { |  | ||||||
|   @apply bg-primary-500 text-white text-sm font-semibold px-2 py-1 rounded hover:bg-primary-700; |  | ||||||
| } |  | ||||||
| </style> |  | ||||||
|  | |||||||
| @ -54,7 +54,6 @@ | |||||||
|               bg-white |               bg-white | ||||||
|               rounded-lg |               rounded-lg | ||||||
|               text-left |               text-left | ||||||
|               overflow-hidden |  | ||||||
|               relative |               relative | ||||||
|               shadow-xl |               shadow-xl | ||||||
|               transition-all |               transition-all | ||||||
|  | |||||||
| @ -1,10 +1,6 @@ | |||||||
| <template> | <template> | ||||||
|   <div> |   <div> | ||||||
|     <TabGroup |     <TabGroup :default-index="defaultIndex" @change="onChange"> | ||||||
|       :selected-index="selectedIndex" |  | ||||||
|       :default-index="defaultIndex" |  | ||||||
|       @change="onChange" |  | ||||||
|     > |  | ||||||
|       <TabList |       <TabList | ||||||
|         :class="[ |         :class="[ | ||||||
|           'flex border-b border-grey-light', |           'flex border-b border-grey-light', | ||||||
| @ -58,10 +54,6 @@ const props = defineProps({ | |||||||
|     type: Number, |     type: Number, | ||||||
|     default: 0, |     default: 0, | ||||||
|   }, |   }, | ||||||
|   selectedIndex: { |  | ||||||
|     type: Number, |  | ||||||
|     default: 0, |  | ||||||
|   }, |  | ||||||
|   filter: { |   filter: { | ||||||
|     type: String, |     type: String, | ||||||
|     default: null, |     default: null, | ||||||
| @ -75,6 +67,6 @@ const slots = useSlots() | |||||||
| const tabs = computed(() => slots.default().map((tab) => tab.props)) | const tabs = computed(() => slots.default().map((tab) => tab.props)) | ||||||
|  |  | ||||||
| function onChange(d) { | function onChange(d) { | ||||||
|   emit('change', tabs.value[d], d) |   emit('change', tabs.value[d]) | ||||||
| } | } | ||||||
| </script> | </script> | ||||||
|  | |||||||
| @ -7,12 +7,12 @@ export function usePopper(options) { | |||||||
|   let popper = ref(null) |   let popper = ref(null) | ||||||
|  |  | ||||||
|   onMounted(() => { |   onMounted(() => { | ||||||
|     watchEffect((onInvalidate) => { |     watchEffect(onInvalidate => { | ||||||
|       if (!container.value) return |       if (!container.value) return | ||||||
|       if (!activator.value) return |       if (!activator.value) return | ||||||
|  |  | ||||||
|       let containerEl = container.value.el || container.value |       let containerEl = container.value.el || container.value | ||||||
|       let activatorEl = activator.value.$el || activator.value |       let activatorEl = activator.value.el || activator.value | ||||||
|  |  | ||||||
|       if (!(activatorEl instanceof HTMLElement)) return |       if (!(activatorEl instanceof HTMLElement)) return | ||||||
|       if (!(containerEl instanceof HTMLElement)) return |       if (!(containerEl instanceof HTMLElement)) return | ||||||
|  | |||||||
| @ -100,7 +100,9 @@ | |||||||
|     "pay_invoice": "Pay Invoice", |     "pay_invoice": "Pay Invoice", | ||||||
|     "login_successfully": "Logged in successfully!", |     "login_successfully": "Logged in successfully!", | ||||||
|     "logged_out_successfully": "Logged out successfully", |     "logged_out_successfully": "Logged out successfully", | ||||||
|     "mark_as_default": "Mark as default" |     "mark_as_default": "Mark as default", | ||||||
|  |     "select_option": "Select option", | ||||||
|  |     "send_test_mail": "Send Test Mail" | ||||||
|   }, |   }, | ||||||
|   "dashboard": { |   "dashboard": { | ||||||
|     "select_year": "Select year", |     "select_year": "Select year", | ||||||
| @ -233,7 +235,8 @@ | |||||||
|     "updated_message": "Customer updated successfully", |     "updated_message": "Customer updated successfully", | ||||||
|     "address_updated_message": "Address Information Updated succesfully", |     "address_updated_message": "Address Information Updated succesfully", | ||||||
|     "deleted_message": "Customer deleted successfully | Customers deleted successfully", |     "deleted_message": "Customer deleted successfully | Customers deleted successfully", | ||||||
|     "edit_currency_not_allowed": "Cannot change currency once transactions created." |     "edit_currency_not_allowed": "Cannot change currency once transactions created.", | ||||||
|  |     "select_sender": "Select Sender" | ||||||
|   }, |   }, | ||||||
|   "items": { |   "items": { | ||||||
|     "title": "Items", |     "title": "Items", | ||||||
| @ -728,7 +731,8 @@ | |||||||
|     "updated_message": "User updated successfully", |     "updated_message": "User updated successfully", | ||||||
|     "deleted_message": "User deleted successfully | Users deleted successfully", |     "deleted_message": "User deleted successfully | Users deleted successfully", | ||||||
|     "select_company_role": "Select Role for {company}", |     "select_company_role": "Select Role for {company}", | ||||||
|     "companies": "Companies" |     "companies": "Companies", | ||||||
|  |     "select_sender": "Select Sender" | ||||||
|   }, |   }, | ||||||
|   "reports": { |   "reports": { | ||||||
|     "title": "Report", |     "title": "Report", | ||||||
| @ -807,7 +811,8 @@ | |||||||
|       "payment_modes": "Payment Modes", |       "payment_modes": "Payment Modes", | ||||||
|       "notes": "Notes", |       "notes": "Notes", | ||||||
|       "exchange_rate": "Exchange Rate", |       "exchange_rate": "Exchange Rate", | ||||||
|       "address_information": "Address Information" |       "address_information": "Address Information", | ||||||
|  |       "mail_sender": "Mail Senders" | ||||||
|     }, |     }, | ||||||
|     "address_information": { |     "address_information": { | ||||||
|       "section_description": "  You can update Your Address information using form below." |       "section_description": "  You can update Your Address information using form below." | ||||||
| @ -863,8 +868,6 @@ | |||||||
|     "company_info": { |     "company_info": { | ||||||
|       "company_info": "Company info", |       "company_info": "Company info", | ||||||
|       "company_name": "Company Name", |       "company_name": "Company Name", | ||||||
|       "company_slug": "Company Slug", |  | ||||||
|       "company_slug_help_text": "A unique URL friendly name for your company (It will appear on Customer Portal URL)", |  | ||||||
|       "company_logo": "Company Logo", |       "company_logo": "Company Logo", | ||||||
|       "section_description": "Information about your company that will be displayed on invoices, estimates and other documents created by Crater.", |       "section_description": "Information about your company that will be displayed on invoices, estimates and other documents created by Crater.", | ||||||
|       "phone": "Phone", |       "phone": "Phone", | ||||||
| @ -1313,6 +1316,51 @@ | |||||||
|       "state_placeholder": "Example: CA", |       "state_placeholder": "Example: CA", | ||||||
|       "zip_placeholder": "Example: 90024", |       "zip_placeholder": "Example: 90024", | ||||||
|       "invalid_address": "Please provide valid address details." |       "invalid_address": "Please provide valid address details." | ||||||
|  |     }, | ||||||
|  |     "mail_sender": { | ||||||
|  |       "title": "Mail Sender | Mail Senders", | ||||||
|  |       "description": "Configure & test your mail senders for the selected company.", | ||||||
|  |       "add_new_mail_sender": "New Mail Sender", | ||||||
|  |       "name": "Sender Name", | ||||||
|  |       "name_help": "Type a name to identify the sender for users.", | ||||||
|  |       "driver": "Mail Driver", | ||||||
|  |       "is_default": "Set as default", | ||||||
|  |       "is_default_description": "You can only set one sender as default at a given time.", | ||||||
|  |       "cc": "CC", | ||||||
|  |       "bcc": "BCC", | ||||||
|  |       "from_address": "From Mail Address", | ||||||
|  |       "from_name": "From Mail Name", | ||||||
|  |       "edit_mail_sender": "Edit Mail Sender", | ||||||
|  |       "delete_mail_sender": "Delete Mail Sender", | ||||||
|  |       "confirm_delete": "You will not be able to recover this Mail Sender", | ||||||
|  |       "created_message": "Mail Sender created successfully", | ||||||
|  |       "updated_message": "Mail Sender updated successfully", | ||||||
|  |       "deleted_message": "Mail Sender deleted successfully", | ||||||
|  |       "default_record_exists": "Default mail sender already exist", | ||||||
|  |       "email_list": "Supports a comma separated list of email addresses", | ||||||
|  |       "select_mail_sender": "Select Mail Sender", | ||||||
|  |       "manage_mail_sender": "Manage Mail Senders", | ||||||
|  |       "no_mail_sender_found": "No mail senders found!", | ||||||
|  |       "no_mail_sender_found_description": "You must configure at-least one mail sender for the selected company in order to continue.", | ||||||
|  |       "smtp_config": { | ||||||
|  |         "host": "Host", | ||||||
|  |         "port": "Port", | ||||||
|  |         "username": "Username", | ||||||
|  |         "password": "Password", | ||||||
|  |         "encryption": "Encryption" | ||||||
|  |       }, | ||||||
|  |       "mailgun_config": { | ||||||
|  |         "domain": "Domain", | ||||||
|  |         "secret": "Maingun Secret", | ||||||
|  |         "endpoint": "Mailgun Endpoint" | ||||||
|  |       }, | ||||||
|  |       "ses_config": { | ||||||
|  |         "host": "Host", | ||||||
|  |         "port": "Port", | ||||||
|  |         "encryption": "Encryption", | ||||||
|  |         "ses_key": "SES Key", | ||||||
|  |         "ses_secret": "SES Secret" | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   "wizard": { |   "wizard": { | ||||||
| @ -1326,8 +1374,6 @@ | |||||||
|     "company_info": "Company Information", |     "company_info": "Company Information", | ||||||
|     "company_info_desc": "This information will be displayed on invoices. Note that you can edit this later on settings page.", |     "company_info_desc": "This information will be displayed on invoices. Note that you can edit this later on settings page.", | ||||||
|     "company_name": "Company Name", |     "company_name": "Company Name", | ||||||
|     "company_slug": "Company Slug", |  | ||||||
|     "company_slug_help_text": "A unique URL friendly name for your company (It will appear on Customer Portal URL)", |  | ||||||
|     "company_logo": "Company Logo", |     "company_logo": "Company Logo", | ||||||
|     "logo_preview": "Logo Preview", |     "logo_preview": "Logo Preview", | ||||||
|     "preferences": "Company Preferences", |     "preferences": "Company Preferences", | ||||||
| @ -1458,8 +1504,7 @@ | |||||||
|     "at_least_one_ability": "Please select atleast one Permission.", |     "at_least_one_ability": "Please select atleast one Permission.", | ||||||
|     "valid_driver_key": "Please enter a valid {driver} key.", |     "valid_driver_key": "Please enter a valid {driver} key.", | ||||||
|     "valid_exchange_rate": "Please enter a valid exchange rate.", |     "valid_exchange_rate": "Please enter a valid exchange rate.", | ||||||
|     "company_name_not_same": "Company name must match with given name.", |     "company_name_not_same": "Company name must match with given name." | ||||||
|     "invalid_slug": "Invalid Slug" |  | ||||||
|   }, |   }, | ||||||
|   "errors": { |   "errors": { | ||||||
|     "starter_plan": "This feature is available on Starter plan and onwards!", |     "starter_plan": "This feature is available on Starter plan and onwards!", | ||||||
| @ -1527,13 +1572,5 @@ | |||||||
|   "pdf_bill_to": "Bill to,", |   "pdf_bill_to": "Bill to,", | ||||||
|   "pdf_ship_to": "Ship to,", |   "pdf_ship_to": "Ship to,", | ||||||
|   "pdf_received_from": "Received from:", |   "pdf_received_from": "Received from:", | ||||||
|   "pdf_tax_label": "Tax", |   "pdf_tax_label": "Tax" | ||||||
|   "date_picker": { |  | ||||||
|     "same_day": "Same Day", |  | ||||||
|     "within_7_days": "Within 7 Days", |  | ||||||
|     "within_15_days": "Within 15 Days", |  | ||||||
|     "within_30_days": "Within 30 Days", |  | ||||||
|     "within_45_days": "Within 45 Days", |  | ||||||
|     "within_60_days": "Within 60 Days" |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ | |||||||
|     <meta name="csrf-token" content="{{ csrf_token() }}"> |     <meta name="csrf-token" content="{{ csrf_token() }}"> | ||||||
|  |  | ||||||
|     <!-- Module Styles --> |     <!-- Module Styles --> | ||||||
|     @foreach (\Crater\Services\Module\ModuleFacade::allStyles() as $name => $path) |     @foreach(\Crater\Services\Module\ModuleFacade::allStyles() as $name => $path) | ||||||
|         <link rel="stylesheet" href="/modules/styles/{{ $name }}"> |         <link rel="stylesheet" href="/modules/styles/{{ $name }}"> | ||||||
|     @endforeach |     @endforeach | ||||||
|  |  | ||||||
| @ -25,8 +25,8 @@ | |||||||
| </head> | </head> | ||||||
|  |  | ||||||
| <body | <body | ||||||
|     class="h-full overflow-hidden bg-gray-100 dark:bg-gray-900 dark:text-white font-base |     class="h-full overflow-hidden bg-gray-100 font-base | ||||||
|     @if (isset($current_theme)) theme-{{ $current_theme }} @else theme-{{ get_app_setting('admin_portal_theme') ?? 'crater' }} @endif "> |     @if(isset($current_theme)) theme-{{ $current_theme }} @else theme-{{get_app_setting('admin_portal_theme') ?? 'crater'}} @endif "> | ||||||
|  |  | ||||||
|     <!-- Module Scripts --> |     <!-- Module Scripts --> | ||||||
|     @foreach (\Crater\Services\Module\ModuleFacade::allScripts() as $name => $path) |     @foreach (\Crater\Services\Module\ModuleFacade::allScripts() as $name => $path) | ||||||
| @ -38,14 +38,6 @@ | |||||||
|     @endforeach |     @endforeach | ||||||
|  |  | ||||||
|     <script type="module"> |     <script type="module"> | ||||||
|         if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { |  | ||||||
|             document.documentElement.classList.add('dark') |  | ||||||
|             document.documentElement.style.setProperty('color-scheme', 'dark'); |  | ||||||
|         } else { |  | ||||||
|             document.documentElement.classList.remove('dark') |  | ||||||
|             document.documentElement.style.setProperty('color-scheme', 'light') |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         @if(isset($customer_logo)) |         @if(isset($customer_logo)) | ||||||
|  |  | ||||||
|         window.customer_logo = "/storage/{{$customer_logo}}" |         window.customer_logo = "/storage/{{$customer_logo}}" | ||||||
| @ -65,12 +57,12 @@ | |||||||
|  |  | ||||||
|         window.login_page_description = "{{$login_page_description}}" |         window.login_page_description = "{{$login_page_description}}" | ||||||
|  |  | ||||||
|         @endif |         @endif      | ||||||
|         @if(isset($copyright_text)) |         @if(isset($copyright_text)) | ||||||
|  |  | ||||||
|         window.copyright_text = "{{$copyright_text}}" |         window.copyright_text = "{{$copyright_text}}" | ||||||
|  |  | ||||||
|         @endif |         @endif     | ||||||
|  |  | ||||||
|         window.Crater.start() |         window.Crater.start() | ||||||
|     </script> |     </script> | ||||||
|  | |||||||
| @ -47,6 +47,8 @@ use Crater\Http\Controllers\V1\Admin\Invoice\SendInvoiceController; | |||||||
| use Crater\Http\Controllers\V1\Admin\Invoice\SendInvoicePreviewController; | use Crater\Http\Controllers\V1\Admin\Invoice\SendInvoicePreviewController; | ||||||
| use Crater\Http\Controllers\V1\Admin\Item\ItemsController; | use Crater\Http\Controllers\V1\Admin\Item\ItemsController; | ||||||
| use Crater\Http\Controllers\V1\Admin\Item\UnitsController; | use Crater\Http\Controllers\V1\Admin\Item\UnitsController; | ||||||
|  | use Crater\Http\Controllers\V1\Admin\MailSender\GetAllMailSendersController; | ||||||
|  | use Crater\Http\Controllers\V1\Admin\MailSender\MailSenderController; | ||||||
| use Crater\Http\Controllers\V1\Admin\Mobile\AuthController; | use Crater\Http\Controllers\V1\Admin\Mobile\AuthController; | ||||||
| use Crater\Http\Controllers\V1\Admin\Modules\ApiTokenController; | use Crater\Http\Controllers\V1\Admin\Modules\ApiTokenController; | ||||||
| use Crater\Http\Controllers\V1\Admin\Modules\CompleteModuleInstallationController; | use Crater\Http\Controllers\V1\Admin\Modules\CompleteModuleInstallationController; | ||||||
| @ -401,13 +403,11 @@ Route::prefix('/v1')->group(function () { | |||||||
|             // Mails |             // Mails | ||||||
|             //---------------------------------- |             //---------------------------------- | ||||||
|  |  | ||||||
|             Route::get('/mail/drivers', [MailConfigurationController::class, 'getMailDrivers']); |             Route::apiResource('mail-senders', MailSenderController::class); | ||||||
|  |  | ||||||
|             Route::get('/mail/config', [MailConfigurationController::class, 'getMailEnvironment']); |             Route::get('/mail-drivers', [MailConfigurationController::class, 'getMailDrivers']); | ||||||
|  |  | ||||||
|             Route::post('/mail/config', [MailConfigurationController::class, 'saveMailEnvironment']); |             Route::post('/mail-test', [MailConfigurationController::class, 'TestMailDriver']); | ||||||
|  |  | ||||||
|             Route::post('/mail/test', [MailConfigurationController::class, 'testEmailConfig']); |  | ||||||
|  |  | ||||||
|             Route::get('/company/mail/config', GetCompanyMailConfigurationController::class); |             Route::get('/company/mail/config', GetCompanyMailConfigurationController::class); | ||||||
|  |  | ||||||
|  | |||||||
| @ -19,7 +19,6 @@ module.exports = { | |||||||
|     './resources/scripts/**/*.js', |     './resources/scripts/**/*.js', | ||||||
|     './resources/scripts/**/*.vue', |     './resources/scripts/**/*.vue', | ||||||
|   ], |   ], | ||||||
|   darkMode: 'class', |  | ||||||
|   theme: { |   theme: { | ||||||
|     extend: { |     extend: { | ||||||
|       colors: { |       colors: { | ||||||
|  | |||||||
| @ -415,31 +415,32 @@ test('update estimate with EUR currency', function () { | |||||||
|  |  | ||||||
|     $response = putJson('api/v1/estimates/'.$estimate->id, $estimate2); |     $response = putJson('api/v1/estimates/'.$estimate->id, $estimate2); | ||||||
|  |  | ||||||
|     $estimate_assert = collect($estimate2) |     $this->assertDatabaseHas('estimates', [ | ||||||
|         ->only([ |         'id' => $estimate['id'], | ||||||
|             'id', |         'template_name' => $estimate2['template_name'], | ||||||
|             'template_name', |         'estimate_number' => $estimate2['estimate_number'], | ||||||
|             'estimate_number', |         'discount_type' => $estimate2['discount_type'], | ||||||
|             'discount_type', |         'discount_val' => $estimate2['discount_val'], | ||||||
|             'discount_val', |         'sub_total' => $estimate2['sub_total'], | ||||||
|             'sub_total', |         'discount' => $estimate2['discount'], | ||||||
|             'discount', |         'customer_id' => $estimate2['customer_id'], | ||||||
|             'customer_id', |         'total' => $estimate2['total'], | ||||||
|             'total', |         'tax' => $estimate2['tax'], | ||||||
|             'tax' |         'exchange_rate' => $estimate2['exchange_rate'], | ||||||
|         ]) |         'base_discount_val' => $estimate2['base_discount_val'], | ||||||
|         ->toArray(); |         'base_sub_total' => $estimate2['base_sub_total'], | ||||||
|  |         'base_total' => $estimate2['base_total'], | ||||||
|  |         'base_tax' => $estimate2['base_tax'], | ||||||
|  |     ]); | ||||||
|  |  | ||||||
|     $this->assertDatabaseHas('estimates', $estimate_assert); |     $this->assertDatabaseHas('estimate_items', [ | ||||||
|  |         'estimate_id' => $estimate2['items'][0]['estimate_id'], | ||||||
|     $estimate_item_assert = collect($estimate2['items'][0]) |         'exchange_rate' => $estimate2['items'][0]['exchange_rate'], | ||||||
|         ->only([ |         'base_price' => $estimate2['items'][0]['base_price'], | ||||||
|             'estimate_id', |         'base_discount_val' => $estimate2['items'][0]['base_discount_val'], | ||||||
|             'amount' |         'base_tax' => $estimate2['items'][0]['base_tax'], | ||||||
|         ]) |         'base_total' => $estimate2['items'][0]['base_total'], | ||||||
|         ->toArray(); |     ]); | ||||||
|  |  | ||||||
|     $this->assertDatabaseHas('estimate_items', $estimate_item_assert); |  | ||||||
|  |  | ||||||
|     $response->assertStatus(200); |     $response->assertStatus(200); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -37,15 +37,13 @@ test('create expense', function () { | |||||||
|  |  | ||||||
|     postJson('api/v1/expenses', $expense)->assertStatus(201); |     postJson('api/v1/expenses', $expense)->assertStatus(201); | ||||||
|  |  | ||||||
|     $expense = collect($expense) |     $this->assertDatabaseHas('expenses', [ | ||||||
|         ->only([ |         'notes' => $expense['notes'], | ||||||
|             'notes', |         'expense_category_id' => $expense['expense_category_id'], | ||||||
|             'expense_category_id', |         'amount' => $expense['amount'], | ||||||
|             'amount' |         'exchange_rate' => $expense['exchange_rate'], | ||||||
|         ]) |         'base_amount' => $expense['base_amount'], | ||||||
|         ->toArray(); |     ]); | ||||||
|  |  | ||||||
|     $this->assertDatabaseHas('expenses', $expense); |  | ||||||
| }); | }); | ||||||
|  |  | ||||||
| test('store validates using a form request', function () { | test('store validates using a form request', function () { | ||||||
| @ -148,13 +146,11 @@ test('update expense with EUR currency', function () { | |||||||
|  |  | ||||||
|     putJson('api/v1/expenses/'.$expense->id, $expense2)->assertOk(); |     putJson('api/v1/expenses/'.$expense->id, $expense2)->assertOk(); | ||||||
|  |  | ||||||
|     $expense2 = collect($expense2) |     $this->assertDatabaseHas('expenses', [ | ||||||
|         ->only([ |         'id' => $expense->id, | ||||||
|             'id', |         'expense_category_id' => $expense2['expense_category_id'], | ||||||
|             'expense_category_id', |         'amount' => $expense2['amount'], | ||||||
|             'amount' |         'exchange_rate' => $expense2['exchange_rate'], | ||||||
|         ]) |         'base_amount' => $expense2['base_amount'], | ||||||
|         ->toArray(); |     ]); | ||||||
|  |  | ||||||
|     $this->assertDatabaseHas('expenses', $expense2); |  | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ use Crater\Models\Tax; | |||||||
| use Crater\Models\User; | use Crater\Models\User; | ||||||
| use Illuminate\Support\Facades\Artisan; | use Illuminate\Support\Facades\Artisan; | ||||||
| use Laravel\Sanctum\Sanctum; | use Laravel\Sanctum\Sanctum; | ||||||
|  |  | ||||||
| use function Pest\Laravel\getJson; | use function Pest\Laravel\getJson; | ||||||
| use function Pest\Laravel\postJson; | use function Pest\Laravel\postJson; | ||||||
| use function Pest\Laravel\putJson; | use function Pest\Laravel\putJson; | ||||||
| @ -430,36 +431,31 @@ test('update invoice with EUR currency', function () { | |||||||
|  |  | ||||||
|     putJson('api/v1/invoices/'.$invoice->id, $invoice2)->assertOk(); |     putJson('api/v1/invoices/'.$invoice->id, $invoice2)->assertOk(); | ||||||
|  |  | ||||||
|     $invoice_assert = collect($invoice2) |     $this->assertDatabaseHas('invoices', [ | ||||||
|         ->only([ |         'id' => $invoice['id'], | ||||||
|             'invoice_number', |         'invoice_number' => $invoice2['invoice_number'], | ||||||
|             'template_name', |         'sub_total' => $invoice2['sub_total'], | ||||||
|             'sub_total', |         'total' => $invoice2['total'], | ||||||
|             'total', |         'tax' => $invoice2['tax'], | ||||||
|             'tax', |         'discount' => $invoice2['discount'], | ||||||
|             'discount', |         'customer_id' => $invoice2['customer_id'], | ||||||
|             'customer_id', |         'template_name' => $invoice2['template_name'], | ||||||
|         ]) |         'exchange_rate' => $invoice2['exchange_rate'], | ||||||
|         ->toArray(); |         'base_total' => $invoice2['base_total'], | ||||||
|  |     ]); | ||||||
|  |  | ||||||
|     $this->assertDatabaseHas('invoices', $invoice_assert); |     $this->assertDatabaseHas('invoice_items', [ | ||||||
|  |         'invoice_id' => $invoice2['items'][0]['invoice_id'], | ||||||
|  |         'item_id' => $invoice2['items'][0]['item_id'], | ||||||
|  |         'name' => $invoice2['items'][0]['name'], | ||||||
|  |         'exchange_rate' => $invoice2['items'][0]['exchange_rate'], | ||||||
|  |         'base_price' => $invoice2['items'][0]['base_price'], | ||||||
|  |         'base_total' => $invoice2['items'][0]['base_total'], | ||||||
|  |     ]); | ||||||
|  |  | ||||||
|     $invoice_item_assert = collect($invoice2['items'][0]) |     $this->assertDatabaseHas('taxes', [ | ||||||
|         ->only([ |         'amount' => $invoice2['taxes'][0]['amount'], | ||||||
|             'invoice_id', |         'name' => $invoice2['taxes'][0]['name'], | ||||||
|             'item_id', |         'base_amount' => $invoice2['taxes'][0]['base_amount'], | ||||||
|             'name', |     ]); | ||||||
|         ]) |  | ||||||
|         ->toArray(); |  | ||||||
|  |  | ||||||
|     $this->assertDatabaseHas('invoice_items', $invoice_item_assert); |  | ||||||
|  |  | ||||||
|     $invoice_tax_assert = collect($invoice2['taxes'][0]) |  | ||||||
|         ->only([ |  | ||||||
|             'name', |  | ||||||
|             'amount' |  | ||||||
|         ]) |  | ||||||
|         ->toArray(); |  | ||||||
|  |  | ||||||
|     $this->assertDatabaseHas('taxes', $invoice_tax_assert); |  | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -11,7 +11,8 @@ RUN apt-get update && apt-get install -y \ | |||||||
|     unzip \ |     unzip \ | ||||||
|     libzip-dev \ |     libzip-dev \ | ||||||
|     libmagickwand-dev \ |     libmagickwand-dev \ | ||||||
|     mariadb-client |     mariadb-client \ | ||||||
|  |     npm | ||||||
|  |  | ||||||
| # Clear cache | # Clear cache | ||||||
| RUN apt-get clean && rm -rf /var/lib/apt/lists/* | RUN apt-get clean && rm -rf /var/lib/apt/lists/* | ||||||
| @ -45,4 +46,19 @@ RUN chmod -R 775 composer.json composer.lock \ | |||||||
| RUN chown -R $(whoami):$(whoami) /var/log/ | RUN chown -R $(whoami):$(whoami) /var/log/ | ||||||
| RUN chmod -R 775 /var/log | RUN chmod -R 775 /var/log | ||||||
|  |  | ||||||
|  | # Cleanup manually generated build files | ||||||
|  | RUN rm -rf /var/www/public/build | ||||||
|  | RUN npm config set user 0 | ||||||
|  | RUN npm config set unsafe-perm true | ||||||
|  | # Frontend bulding | ||||||
|  | RUN sed -i 's/DB_CONNECTION=mysql/DB_CONNECTION=sqlite/g' /var/www/.env | ||||||
|  | RUN sed -i 's/DB_DATABASE=crater/DB_DATABASE=\/tmp\/crater.sqlite/g' /var/www/.env | ||||||
|  | RUN touch /tmp/crater.sqlite | ||||||
|  | RUN composer install --no-interaction --prefer-dist | ||||||
|  | RUN npm i -f | ||||||
|  | RUN npm install --save-dev sass | ||||||
|  | RUN export NODE_OPTIONS="--max-old-space-size=4096" && /usr/bin/npx vite build --target=es2020 | ||||||
|  | RUN sed -i 's/DB_CONNECTION=sqlite/DB_CONNECTION=mysql/g' /var/www/.env | ||||||
|  | RUN sed -i 's/DB_DATABASE=\/tmp\/crater.sqlite/DB_DATABASE=crater/g' /var/www/.env | ||||||
|  |  | ||||||
| USER crater-user | USER crater-user | ||||||
|  | |||||||
| @ -1,7 +1,9 @@ | |||||||
|  | ARG BASE_IMAGE | ||||||
|  |  | ||||||
|  | FROM $BASE_IMAGE as build | ||||||
| FROM nginx:1.17-alpine | FROM nginx:1.17-alpine | ||||||
|  |  | ||||||
| RUN rm /etc/nginx/conf.d/default.conf | RUN rm /etc/nginx/conf.d/default.conf | ||||||
|  |  | ||||||
| COPY ./ /var/www | COPY --from=build /var/www /var/www | ||||||
| COPY ./uffizzi/nginx/nginx /etc/nginx/conf.d/ | COPY ./uffizzi/nginx/nginx /etc/nginx/conf.d/ | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	