close #3221 Feature: Ability to change document colour and contact based on invoice..
This commit is contained in:
parent
1f385bc9b3
commit
8eb2c86a77
|
|
@ -9,13 +9,14 @@ use App\Models\Document\Document;
|
|||
use App\Models\Setting\Currency;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Traits\Documents;
|
||||
use App\Traits\Tailwind;
|
||||
use App\Traits\ViewComponents;
|
||||
use App\Utilities\Date;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
abstract class Form extends Component
|
||||
{
|
||||
use Documents, ViewComponents;
|
||||
use Documents, Tailwind, ViewComponents;
|
||||
|
||||
public const OBJECT_TYPE = 'document';
|
||||
public const DEFAULT_TYPE = 'invoice';
|
||||
|
|
@ -263,6 +264,21 @@ abstract class Form extends Component
|
|||
|
||||
/** @var string */
|
||||
public $classAttachment;
|
||||
|
||||
/** @var bool */
|
||||
public $hideTemplate;
|
||||
|
||||
/** @var bool */
|
||||
public $hideBackgroundColor;
|
||||
|
||||
/** @var array */
|
||||
public $templates;
|
||||
|
||||
/** @var string */
|
||||
public $template;
|
||||
|
||||
/** @var string */
|
||||
public $backgroundColor;
|
||||
/* -- Advanced End -- */
|
||||
|
||||
/* -- Buttons End -- */
|
||||
|
|
@ -300,6 +316,8 @@ abstract class Form extends Component
|
|||
bool $hideFooter = false, string $classFooter = '', string $footer = '',
|
||||
bool $hideCategory = false, string $classCategory = '', string $typeCategory = '', $categoryId = '',
|
||||
bool $hideAttachment = false, string $classAttachment = '',
|
||||
bool $hideTemplate = false, bool $hideBackgroundColor = false,
|
||||
array $templates = [], string $template = '', string $backgroundColor = '',
|
||||
bool $hideButtons = false, string $cancelRoute = '', $hideSendTo = false
|
||||
) {
|
||||
$this->type = $type;
|
||||
|
|
@ -426,6 +444,13 @@ abstract class Form extends Component
|
|||
|
||||
$this->hideAttachment = $hideAttachment;
|
||||
$this->classAttachment = !empty($classAttachment) ? $classAttachment : 'sm:col-span-4';
|
||||
|
||||
$this->hideTemplate = $hideTemplate;
|
||||
$this->hideBackgroundColor = $hideBackgroundColor;
|
||||
|
||||
$this->templates = $this->getTemplates($type, $templates);
|
||||
$this->template = $this->getDocumentTemplate($type, $template);
|
||||
$this->backgroundColor = $this->getBackgroundColor($type, $backgroundColor);
|
||||
/** Advanced End */
|
||||
|
||||
/** Buttons Start */
|
||||
|
|
@ -1307,4 +1332,64 @@ abstract class Form extends Component
|
|||
|
||||
return setting('default.' . $this->typeCategory . '_category');
|
||||
}
|
||||
|
||||
protected function getTemplates($type, $templates)
|
||||
{
|
||||
if (! empty($templates)) {
|
||||
return $templates;
|
||||
}
|
||||
|
||||
$templates = $this->getDocumentTemplates($type);
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
protected function getDocumentTemplate($type, $documentTemplate)
|
||||
{
|
||||
if (! empty($documentTemplate)) {
|
||||
return $documentTemplate;
|
||||
}
|
||||
|
||||
if (! empty($this->document) && ! empty($this->document->template)) {
|
||||
return $this->document->template;
|
||||
}
|
||||
|
||||
if ($template = config('type.document.' . $type . '.template', false)) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
$documentTemplate = setting($this->getDocumentSettingKey($type, 'template'), 'default');
|
||||
|
||||
return $documentTemplate;
|
||||
}
|
||||
|
||||
protected function getBackgroundColor($type, $backgroundColor)
|
||||
{
|
||||
if (! empty($backgroundColor)) {
|
||||
return $backgroundColor;
|
||||
}
|
||||
|
||||
if (! empty($this->document) && $this->document->color !== '') {
|
||||
return $this->getHexCodeOfTailwindClass($this->document->color);
|
||||
}
|
||||
|
||||
// checking setting color
|
||||
$key = $this->getDocumentSettingKey($type, 'color');
|
||||
|
||||
if (! empty(setting($key))) {
|
||||
$backgroundColor = setting($key);
|
||||
}
|
||||
|
||||
// checking config color
|
||||
if (empty($backgroundColor) && $background_color = config('type.document.' . $type . '.color', false)) {
|
||||
$backgroundColor = $background_color;
|
||||
}
|
||||
|
||||
// set default color
|
||||
if (empty($backgroundColor)) {
|
||||
$backgroundColor = '#55588b';
|
||||
}
|
||||
|
||||
return $this->getHexCodeOfTailwindClass($backgroundColor);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -925,11 +925,28 @@ abstract class Show extends Component
|
|||
return $documentTemplate;
|
||||
}
|
||||
|
||||
if (! empty($this->document) && ! empty($this->document->template)) {
|
||||
$document_templates = $this->getDocumentTemplates($type);
|
||||
|
||||
$template = 'default';
|
||||
|
||||
foreach ($document_templates as $template) {
|
||||
if ($template['id'] != $this->document->template) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$template = $template['template'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
if ($template = config('type.' . static::OBJECT_TYPE . '.' . $type . '.template', false)) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
$documentTemplate = setting($this->getDocumentSettingKey($type, 'template'), 'default');
|
||||
$documentTemplate = setting($this->getDocumentSettingKey($type, 'template'), 'default');
|
||||
|
||||
return $documentTemplate;
|
||||
}
|
||||
|
|
@ -1002,6 +1019,10 @@ abstract class Show extends Component
|
|||
return $backgroundColor;
|
||||
}
|
||||
|
||||
if (! empty($this->document) && $this->document->color !== '') {
|
||||
return $this->getHexCodeOfTailwindClass($this->document->color);
|
||||
}
|
||||
|
||||
// checking setting color
|
||||
$key = $this->getDocumentSettingKey($type, 'color');
|
||||
|
||||
|
|
|
|||
|
|
@ -205,11 +205,28 @@ abstract class Template extends Component
|
|||
return $documentTemplate;
|
||||
}
|
||||
|
||||
if (! empty($this->document) && ! empty($this->document->template)) {
|
||||
$document_templates = $this->getDocumentTemplates($type);
|
||||
|
||||
$template = 'default';
|
||||
|
||||
foreach ($document_templates as $template) {
|
||||
if ($template['id'] != $this->document->template) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$template = $template['template'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
if ($template = config('type.document.' . $type . '.template', false)) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
$documentTemplate = setting($this->getDocumentSettingKey($type, 'template'), 'default');
|
||||
$documentTemplate = setting($this->getDocumentSettingKey($type, 'template'), 'default');
|
||||
|
||||
return $documentTemplate;
|
||||
}
|
||||
|
|
@ -282,6 +299,10 @@ abstract class Template extends Component
|
|||
return $backgroundColor;
|
||||
}
|
||||
|
||||
if (! empty($this->document) && $this->document->color !== '') {
|
||||
return $this->getHexCodeOfTailwindClass($this->document->color);
|
||||
}
|
||||
|
||||
// checking setting color
|
||||
$key = $this->getDocumentSettingKey($type, 'color');
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Document;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DocumentTemplates
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $type;
|
||||
|
||||
public $templates;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $type
|
||||
* @param $templates
|
||||
*/
|
||||
public function __construct($type, $templates)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->templates = $templates;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners\Update\V31;
|
||||
|
||||
use App\Abstracts\Listeners\Update as Listener;
|
||||
use App\Events\Install\UpdateFinished as Event;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Version3112 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '3.1.12';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($this->skipThisUpdate($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log::channel('stdout')->info('Updating to 3.1.12 version...');
|
||||
|
||||
$this->updateDatabase();
|
||||
|
||||
Log::channel('stdout')->info('Done!');
|
||||
}
|
||||
|
||||
public function updateDatabase(): void
|
||||
{
|
||||
Log::channel('stdout')->info('Updating database...');
|
||||
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
|
||||
Log::channel('stdout')->info('Database updated.');
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +58,8 @@ class Document extends Model
|
|||
'subheading',
|
||||
'notes',
|
||||
'footer',
|
||||
'template',
|
||||
'color',
|
||||
'parent_id',
|
||||
'created_from',
|
||||
'created_by',
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class Event extends Provider
|
|||
'App\Listeners\Update\V31\Version315',
|
||||
'App\Listeners\Update\V31\Version317',
|
||||
'App\Listeners\Update\V31\Version318',
|
||||
'App\Listeners\Update\V31\Version3112',
|
||||
],
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\Auth\Login',
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use App\Models\Document\Document;
|
|||
use App\Abstracts\View\Components\Documents\Document as DocumentComponent;
|
||||
use App\Utilities\Date;
|
||||
use App\Traits\Transactions;
|
||||
use App\Events\Document\DocumentTemplates;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\DNSCheckValidation;
|
||||
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
|
||||
|
|
@ -270,4 +271,38 @@ trait Documents
|
|||
{
|
||||
return Str::replace('-recurring', '', $recurring_type);
|
||||
}
|
||||
|
||||
public function getDocumentTemplates($type)
|
||||
{
|
||||
$templates = new \stdClass();
|
||||
$templates->templates = collect();
|
||||
$config_templates = config('type.document.' . $type . '.templates', [
|
||||
[
|
||||
'id' => 'default',
|
||||
'name' => trans('settings.invoice.default'),
|
||||
'image' => asset('assets/img/templates/default.png'),
|
||||
'template' => 'default',
|
||||
],
|
||||
[
|
||||
'id' => 'classic',
|
||||
'name' => trans('settings.invoice.classic'),
|
||||
'image' => asset('assets/img/templates/classic.png'),
|
||||
'template' => 'classic',
|
||||
],
|
||||
[
|
||||
'id' => 'modern',
|
||||
'name' => trans('settings.invoice.modern'),
|
||||
'image' => asset('assets/img/templates/modern.png'),
|
||||
'template' => 'modern',
|
||||
],
|
||||
]);
|
||||
|
||||
foreach ($config_templates as $config_template) {
|
||||
$templates->templates->push($config_template);
|
||||
}
|
||||
|
||||
event(new DocumentTemplates($type, $templates));
|
||||
|
||||
return $templates->templates;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
$table->string('template')->nullable()->after('footer');
|
||||
$table->string('color')->nullable()->after('template');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
$table->dropColumn('template');
|
||||
$table->dropColumn('color');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -33,6 +33,31 @@
|
|||
<x-form.group.attachment />
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if (! $hideTemplate)
|
||||
<x-form.group.select
|
||||
name="template"
|
||||
label="{{ trans_choice('general.templates', 1) }}"
|
||||
:options="$templates"
|
||||
:selected="$template"
|
||||
>
|
||||
<template #option="{option}">
|
||||
<span class="w-full flex h-16 items-center">
|
||||
<div class="w-12 h-12 flex items-center justify-center text-2xl font-regular border border-gray-300 rounded-full p-6">
|
||||
<img src="@{{ option.option.image }}" class="h-60 my-3" alt="Classic" />
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col text-black text-sm font-medium ml-2 sm:ml-4">
|
||||
<span>@{{ option.option.name }}</span>
|
||||
</div>
|
||||
</span>
|
||||
</template>
|
||||
</x-form.group.select>
|
||||
@endif
|
||||
|
||||
@if (! $hideBackgroundColor)
|
||||
<x-form.group.color name="color" label="{{ trans('general.color') }}" :value="$backgroundColor" />
|
||||
@endif
|
||||
</div>
|
||||
</x-slot>
|
||||
</x-form.accordion>
|
||||
|
|
|
|||
Loading…
Reference in New Issue