Moved to _dev

This commit is contained in:
2025-09-20 16:11:47 +02:00
parent fb1a8753b7
commit b2ba11fcd3
1670 changed files with 224899 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace Crater\Console\Commands;
use Carbon\Carbon;
use Crater\Models\Estimate;
use Illuminate\Console\Command;
class CheckEstimateStatus extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check:estimates:status';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check invoices status.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$date = Carbon::now();
$status = [Estimate::STATUS_ACCEPTED, Estimate::STATUS_REJECTED, Estimate::STATUS_EXPIRED];
$estimates = Estimate::whereNotIn('status', $status)->whereDate('expiry_date', '<', $date)->get();
foreach ($estimates as $estimate) {
$estimate->status = Estimate::STATUS_EXPIRED;
printf("Estimate %s is EXPIRED \n", $estimate->estimate_number);
$estimate->save();
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Crater\Console\Commands;
use Carbon\Carbon;
use Crater\Models\Invoice;
use Illuminate\Console\Command;
class CheckInvoiceStatus extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check:invoices:status';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check invoices status.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$date = Carbon::now();
$invoices = Invoice::whereNotIn('status', [Invoice::STATUS_COMPLETED, Invoice::STATUS_DRAFT])
->where('overdue', false)
->whereDate('due_date', '<', $date)
->get();
foreach ($invoices as $invoice) {
$invoice->overdue = true;
printf("Invoice %s is OVERDUE \n", $invoice->invoice_number);
$invoice->save();
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Crater\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class CreateTemplateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:template {name} {--type=}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create estimate or invoice pdf template. ';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$templateName = $this->argument('name');
$type = $this->option('type');
if (! $type) {
$type = $this->choice('Create a template for?', ['invoice', 'estimate']);
}
if (Storage::disk('views')->exists("/app/pdf/{$type}/{$templateName}.blade.php")) {
$this->info("Template with given name already exists.");
return 0;
}
Storage::disk('views')->copy("/app/pdf/{$type}/{$type}1.blade.php", "/app/pdf/{$type}/{$templateName}.blade.php");
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"));
$path = resource_path("views/app/pdf/{$type}/{$templateName}.blade.php");
$type = ucfirst($type);
$this->info("{$type} Template created successfully at ".$path);
return 0;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Crater\Console\Commands;
use Crater\Space\ModuleInstaller;
use Illuminate\Console\Command;
class InstallModuleCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:module {module} {version}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install cloned module.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
ModuleInstaller::complete($this->argument('module'), $this->argument('version'));
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace Crater\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Support\Facades\Artisan;
class ResetApp extends Command
{
use ConfirmableTrait;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'reset:app {--force}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Clean database, database_created and public/storage folder';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (! $this->confirmToProceed()) {
return;
}
$this->info('Running migrate:fresh');
Artisan::call('migrate:fresh --seed --force');
$this->info('Seeding database');
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$path = base_path('.env');
if (file_exists($path)) {
file_put_contents($path, str_replace(
'APP_DEBUG=true',
'APP_DEBUG=false',
file_get_contents($path)
));
}
$this->info('App has been reset successfully');
}
}

View File

@@ -0,0 +1,241 @@
<?php
namespace Crater\Console\Commands;
use Crater\Models\Setting;
use Crater\Space\Updater;
use Illuminate\Console\Command;
// Implementation taken from Akaunting - https://github.com/akaunting/akaunting
class UpdateCommand extends Command
{
public $installed;
public $version;
public $response;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'crater:update';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Automatically update your crater app';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
set_time_limit(3600); // 1 hour
$this->installed = $this->getInstalledVersion();
$this->response = $this->getLatestVersionResponse();
$this->version = ($this->response) ? $this->response->version : false;
if ($this->response == 'extension_required') {
$this->info('Sorry! Your system does not meet the minimum requirements for this update.');
$this->info('Please retry after installing the required version/extensions.');
return;
}
if (! $this->version) {
$this->info('No Update Available! You are already on the latest version.');
return;
}
if (! $this->confirm("Do you wish to update to {$this->version}?")) {
return;
}
if (! $path = $this->download()) {
return;
}
if (! $path = $this->unzip($path)) {
return;
}
if (! $this->copyFiles($path)) {
return;
}
if (isset($this->response->deleted_files) && ! empty($this->response->deleted_files)) {
if (! $this->deleteFiles($this->response->deleted_files)) {
return;
}
}
if (! $this->migrateUpdate()) {
return;
}
if (! $this->finish()) {
return;
}
$this->info('Successfully updated to '.$this->version);
}
public function getInstalledVersion()
{
return Setting::getSetting('version');
}
public function getLatestVersionResponse()
{
$this->info('Your currently installed version is '.$this->installed);
$this->line('');
$this->info('Checking for update...');
try {
$response = Updater::checkForUpdate($this->installed);
if ($response->success) {
$extensions = $response->version->extensions;
$is_required = false;
foreach ($extensions as $key => $extension) {
if (! $extension) {
$is_required = true;
$this->info('❌ '.$key);
}
$this->info('✅ '.$key);
}
if ($is_required) {
return 'extension_required';
}
return $response->version;
}
return false;
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
}
public function download()
{
$this->info('Downloading update...');
try {
$path = Updater::download($this->version, 1);
if (! is_string($path)) {
$this->error('Download exception');
return false;
}
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return $path;
}
public function unzip($path)
{
$this->info('Unzipping update package...');
try {
$path = Updater::unzip($path);
if (! is_string($path)) {
$this->error('Unzipping exception');
return false;
}
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return $path;
}
public function copyFiles($path)
{
$this->info('Copying update files...');
try {
Updater::copyFiles($path);
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return true;
}
public function deleteFiles($files)
{
$this->info('Deleting unused old files...');
try {
Updater::deleteFiles($files);
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return true;
}
public function migrateUpdate()
{
$this->info('Running Migrations...');
try {
Updater::migrateUpdate();
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return true;
}
public function finish()
{
$this->info('Finishing update...');
try {
Updater::finishUpdate($this->installed, $this->version);
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return true;
}
}