Additional fields for entities

This commit is contained in:
David Bomba 2020-06-28 08:24:08 +10:00
parent 5bcbab3e0a
commit 8eed07b8f5
11 changed files with 158 additions and 9 deletions

View File

@ -83,6 +83,8 @@ class CheckData extends Command
$this->checkInvoiceBalances();
$this->checkClientBalances();
$this->checkContacts();
$this->checkCompanyData();
//$this->checkLogoFiles();
if (! $this->option('client_id')) {
@ -388,4 +390,67 @@ class CheckData extends Command
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
];
}
private function checkCompanyData()
{
$tables = [
'activities' => [
'invoice',
'client',
'client_contact',
'payment',
],
'invoices' => [
'client',
],
'payments' => [
'client',
],
'products' => [
],
];
foreach ($tables as $table => $entityTypes) {
foreach ($entityTypes as $entityType) {
$tableName = $this->pluralizeEntityType($entityType);
$field = $entityType;
if ($table == 'companies') {
$company_id = 'id';
} else {
$company_id = 'company_id';
}
$records = \DB::table($table)
->join($tableName, "{$tableName}.id", '=', "{$table}.{$field}_id")
->where("{$table}.{$company_id}", '!=', \DB::raw("{$tableName}.company_id"))
->get(["{$table}.id"]);
if ($records->count()) {
$this->isValid = false;
$this->logMessage($records->count() . " {$table} records with incorrect {$entityType} company id");
}
}
}
// foreach(User::cursor() as $user) {
// $records = Company::where('account_id',)
// }
}
public function pluralizeEntityType($type)
{
if ($type === 'company') {
return 'companies';
}
return $type . 's';
}
}

View File

@ -232,12 +232,12 @@ class CompanySettings extends BaseSettings
public $portal_custom_js = '';
public $client_can_register = false;
public $client_signup_terms = '';
public $client_signup_privacy_policy = '';
public $client_portal_terms = '';
public $client_portal_privacy_policy = '';
public static $casts = [
'client_signup_terms' => 'string',
'client_signup_privacy_policy' => 'string',
'client_portal_terms' => 'string',
'client_portal_privacy_policy' => 'string',
'client_can_register' => 'bool',
'portal_design_id' => 'string',
'late_fee_endless_percent' => 'float',

View File

@ -37,7 +37,7 @@ class ContactRegister
$company = Company::where('company_key', $request->company_key)->firstOrFail();
abort_unless($company->getSetting('client_can_register'), 404);
abort_unless($company->client_can_register, 404);
return $next($request);
}

View File

@ -66,7 +66,7 @@ class Credit extends BaseModel
'client_id',
'footer',
'design_id',
'exchange_rate',
];
protected $casts = [

View File

@ -100,6 +100,7 @@ class Invoice extends BaseModel
'custom_surcharge_tax4',
'design_id',
'assigned_user_id',
'exchange_rate'
];
protected $casts = [

View File

@ -70,6 +70,7 @@ class Quote extends BaseModel
'client_id',
'footer',
'design_id',
'exchange_rate'
];
protected $casts = [

View File

@ -193,4 +193,14 @@ class PaymentRepository extends BaseRepository
return $payment;
}
public function delete($payment)
{
if($payment->is_deleted)
return;
$payment->service()->deletePayment();
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace App\Services\Payment;
use App\Exceptions\PaymentRefundFailed;
use App\Factory\CreditFactory;
use App\Factory\InvoiceItemFactory;
use App\Models\Activity;
use App\Models\CompanyGateway;
use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
class DeletePayment
{
public $payment;
private $activity_repository;
public function __construct($payment)
{
$this->payment = $payment;
$this->activity_repository = new ActivityRepository();
}
public function run()
{
return $this->setStatus() //sets status of payment
->updateCreditables() //return the credits first
->updatePaymentables() //update the paymentable items
->adjustInvoices()
->save();
}
//
//reverse paymentables->invoices
//reverse paymentables->credits
//set refunded to amount
//set applied amount to 0
/**
* Saves the payment
*
* @return Payment $payment
*/
private function save()
{
$this->payment->save();
return $this->payment;
}
}

View File

@ -14,6 +14,7 @@ namespace App\Services\Payment;
use App\Factory\PaymentFactory;
use App\Models\Invoice;
use App\Models\Payment;
use App\Services\Payment\DeletePayment;
use App\Services\Payment\RefundPayment;
use App\Services\Payment\UpdateInvoicePayment;
@ -77,6 +78,11 @@ class PaymentService
return ((new RefundPayment($this->payment, $data)))->run();
}
public function deletePayment() :?Payment
{
return (new DeletePayment())->run();
}
public function updateInvoicePayment() :?Payment
{
return ((new UpdateInvoicePayment($this->payment)))->run();

View File

@ -149,6 +149,7 @@ class CreateUsersTable extends Migration
$table->boolean('fill_products')->default(true);
$table->boolean('update_products')->default(true);
$table->boolean('show_product_details')->default(true);
$table->boolean('client_can_register')->default(false);
$table->boolean('custom_surcharge_taxes1')->default(false);
$table->boolean('custom_surcharge_taxes2')->default(false);
@ -489,6 +490,7 @@ class CreateUsersTable extends Migration
$t->boolean('custom_surcharge_tax3')->default(false);
$t->boolean('custom_surcharge_tax4')->default(false);
$t->decimal('exchange_rate', 16, 4);
$t->decimal('amount', 16, 4);
$t->decimal('balance', 16, 4);
$t->decimal('partial', 16, 4)->nullable();
@ -566,6 +568,7 @@ class CreateUsersTable extends Migration
$t->boolean('custom_surcharge_tax3')->default(false);
$t->boolean('custom_surcharge_tax4')->default(false);
$t->decimal('exchange_rate', 16, 4);
$t->decimal('amount', 16, 4);
$t->decimal('balance', 16, 4);
$t->decimal('partial', 16, 4)->nullable();
@ -809,6 +812,7 @@ class CreateUsersTable extends Migration
$t->boolean('custom_surcharge_tax3')->default(false);
$t->boolean('custom_surcharge_tax4')->default(false);
$t->decimal('exchange_rate', 16, 4);
$t->decimal('amount', 16, 4);
$t->decimal('balance', 16, 4);
$t->decimal('partial', 16, 4)->nullable();

View File

@ -24,15 +24,15 @@
<div class="flex justify-between items-center mt-8">
<span class="inline-flex items-center" x-data="{ terms_of_service: false, privacy_policy: false }">
@if(!empty($company->settings->client_signup_terms) || !empty($company->settings->client_signup_privacy_policy))
@if(!empty($company->settings->client_portal_terms) || !empty($company->settings->client_portal_privacy_policy))
<input type="checkbox" name="terms" class="form-checkbox mr-2 cursor-pointer" checked>
<span class="text-sm text-gray-800">
{{ ctrans('texts.i_agree') }}
@endif
@includeWhen(!empty($company->settings->client_signup_terms), 'portal.ninja2020.auth.includes.register.popup', ['property' => 'terms_of_service', 'title' => ctrans('texts.terms_of_service'), 'content' => $company->settings->client_signup_terms])
@includeWhen(!empty($company->settings->client_signup_privacy_policy), 'portal.ninja2020.auth.includes.register.popup', ['property' => 'privacy_policy', 'title' => ctrans('texts.privacy_policy'), 'content' => $company->settings->client_signup_privacy_policy])
@includeWhen(!empty($company->settings->client_portal_terms), 'portal.ninja2020.auth.includes.register.popup', ['property' => 'terms_of_service', 'title' => ctrans('texts.terms_of_service'), 'content' => $company->settings->client_portal_terms])
@includeWhen(!empty($company->settings->client_portal_privacy_policy), 'portal.ninja2020.auth.includes.register.popup', ['property' => 'privacy_policy', 'title' => ctrans('texts.privacy_policy'), 'content' => $company->settings->client_portal_privacy_policy])
</span>
</span>