mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge branch 'v5-develop' into design_changes
This commit is contained in:
commit
19fdd9e96e
65
.env.cypress
Normal file
65
.env.cypress
Normal file
@ -0,0 +1,65 @@
|
||||
APP_NAME="Invoice Ninja"
|
||||
APP_ENV=local
|
||||
APP_KEY=base64:xV0ixUbXIGjeWImmcjCYL8/XespgcEk+dTTPlM17dNE=
|
||||
APP_DEBUG=true
|
||||
APP_DOMAIN=ninja.test:8000
|
||||
|
||||
APP_URL=http://ninja.test:8000/
|
||||
#APP_URL=https://ninja.test
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
MULTI_DB_ENABLED=false
|
||||
|
||||
DB_HOST1=127.0.0.1
|
||||
DB_DATABASE1=db-ninja-01
|
||||
DB_USERNAME1=ninja
|
||||
DB_PASSWORD1=ninja
|
||||
DB_PORT1=3306
|
||||
|
||||
DB_HOST2=127.0.0.1
|
||||
DB_DATABASE2=db-ninja-02
|
||||
DB_USERNAME2=ninja
|
||||
DB_PASSWORD2=ninja
|
||||
DB_PORT2=3306
|
||||
|
||||
DEMO_MODE=false
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
REQUIRE_HTTPS=false
|
||||
BROADCAST_DRIVER=pusher
|
||||
CACHE_DRIVER=redis
|
||||
QUEUE_CONNECTION=database
|
||||
SESSION_DRIVER=redis
|
||||
SESSION_DOMAIN=.ninja.test
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
PUSHER_APP_ID="ninja"
|
||||
PUSHER_APP_KEY="ninja"
|
||||
PUSHER_APP_SECRET="ninja"
|
||||
PUSHER_APP_CLUSTER="ninja1"
|
||||
|
||||
MAIL_MAILER=log
|
||||
MAIL_HOST=localhost
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
|
||||
MAIL_FROM_ADDRESS=''
|
||||
MAIL_FROM_NAME=''
|
||||
|
||||
GOOGLE_MAPS_API_KEY=
|
||||
|
||||
NINJA_ENVIRONMENT=selfhost
|
||||
|
||||
HASH_SALT=
|
||||
|
||||
FILESYSTEM_DRIVER=public
|
||||
|
||||
PDF_GENERATOR=snappdf
|
||||
|
||||
MIX_ASSET_URL=false
|
1
.github/workflows/phpunit.yml
vendored
1
.github/workflows/phpunit.yml
vendored
@ -2,6 +2,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- v5-develop
|
||||
- v5-stable
|
||||
pull_request:
|
||||
branches:
|
||||
- v5-develop
|
||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -18,7 +18,7 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
ref: v5-stable
|
||||
ref: v5-develop
|
||||
|
||||
- name: Copy .env file
|
||||
run: |
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,7 +5,9 @@
|
||||
/storage/*.key
|
||||
/storage/debugbar
|
||||
/storage/*
|
||||
/tests/bootstrap/
|
||||
/vendor
|
||||
/app/Console/Commands/vendor/
|
||||
/.idea
|
||||
/.vscode
|
||||
/.vagrant
|
||||
|
19
.php_cs
19
.php_cs
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
$finder = Symfony\Component\Finder\Finder::create()
|
||||
->notPath('vendor')
|
||||
->notPath('bootstrap')
|
||||
->notPath('storage')
|
||||
->notPath('node_modules')
|
||||
->in(__DIR__)
|
||||
->name('*.php')
|
||||
->notName('*.blade.php');
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setRules([
|
||||
'@PSR2' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
|
||||
'no_unused_imports' => true,
|
||||
])
|
||||
->setFinder($finder);
|
10
README.md
10
README.md
@ -10,9 +10,7 @@
|
||||
|
||||
## [Hosted](https://www.invoiceninja.com) | [Self-Hosted](https://www.invoiceninja.org)
|
||||
|
||||
Join us on [Slack](http://slack.invoiceninja.com), [Discourse](https://forum.invoiceninja.com) -
|
||||
or [StackOverflow](https://stackoverflow.com/tags/invoice-ninja/) if you like,
|
||||
just make sure to add the `invoice-ninja` tag to your question.
|
||||
Join us on [Slack](http://slack.invoiceninja.com), [Discord](https://discord.gg/ZwEdtfCwXA), [Support Forum](https://forum.invoiceninja.com)
|
||||
|
||||
## Introduction
|
||||
|
||||
@ -24,16 +22,16 @@ All Pro and Enterprise features from the hosted app are included in the open cod
|
||||
We offer a $30 per year white-label license to remove the Invoice Ninja branding from client facing parts of the app.
|
||||
|
||||
* [Videos](https://www.youtube.com/@appinvoiceninja)
|
||||
* [API Documentation](https://app.swaggerhub.com/apis/invoiceninja/invoiceninja)
|
||||
* [API Documentation](https://api-docs.invoicing.co/)
|
||||
* [APP Documentation](https://invoiceninja.github.io/)
|
||||
* [Support Forum](https://forum.invoiceninja.com)
|
||||
* [StackOverflow](https://stackoverflow.com/tags/invoice-ninja/)
|
||||
|
||||
## Setup
|
||||
|
||||
### Mobile Apps
|
||||
* [iPhone](https://apps.apple.com/app/id1503970375?platform=iphone)
|
||||
* [Android](https://play.google.com/store/apps/details?id=com.invoiceninja.app)
|
||||
* [F-Droid](https://f-droid.org/en/packages/com.invoiceninja.app)
|
||||
|
||||
### Desktop Apps
|
||||
* [macOS](https://apps.apple.com/app/id1503970375?platform=mac)
|
||||
@ -55,7 +53,7 @@ We offer a $30 per year white-label license to remove the Invoice Ninja branding
|
||||
git clone https://github.com/invoiceninja/invoiceninja.git
|
||||
git checkout v5-stable
|
||||
cp .env.example .env
|
||||
composer update
|
||||
composer i -o --no-dev
|
||||
php artisan key:generate
|
||||
```
|
||||
|
||||
|
@ -1 +1 @@
|
||||
5.5.64
|
||||
5.5.71
|
28081
_ide_helper.php
Normal file
28081
_ide_helper.php
Normal file
File diff suppressed because it is too large
Load Diff
17
_ide_helper_custom.php
Normal file
17
_ide_helper_custom.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Mail
|
||||
{
|
||||
class Mailer
|
||||
{
|
||||
public function postmark_config(string $key)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function mailgun_config(string $key)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -14,11 +14,9 @@ namespace App\Console\Commands;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Backup;
|
||||
use App\Models\Company;
|
||||
use App\Models\Design;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use stdClass;
|
||||
|
||||
class BackupUpdate extends Command
|
||||
{
|
||||
@ -60,7 +58,6 @@ class BackupUpdate extends Command
|
||||
if (! config('ninja.db.multi_db_enabled')) {
|
||||
$this->handleOnDb();
|
||||
} else {
|
||||
|
||||
//multiDB environment, need to
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
MultiDB::setDB($db);
|
||||
@ -78,50 +75,43 @@ class BackupUpdate extends Command
|
||||
|
||||
//logos
|
||||
Company::cursor()
|
||||
->each(function ($company){
|
||||
->each(function ($company) {
|
||||
$company_logo = $company->present()->logo();
|
||||
|
||||
$company_logo = $company->present()->logo();
|
||||
if ($company_logo == 'https://invoicing.co/images/new_logo.png') {
|
||||
return;
|
||||
}
|
||||
|
||||
if($company_logo == 'https://invoicing.co/images/new_logo.png')
|
||||
return;
|
||||
$logo = @file_get_contents($company_logo);
|
||||
|
||||
$logo = @file_get_contents($company_logo);
|
||||
|
||||
if($logo){
|
||||
|
||||
$path = str_replace("https://objects.invoicing.co/", "", $company->present()->logo());
|
||||
$path = str_replace("https://v5-at-backup.us-southeast-1.linodeobjects.com/", "", $path);
|
||||
|
||||
Storage::disk($this->option('disk'))->put($path, $logo);
|
||||
}
|
||||
if ($logo) {
|
||||
$path = str_replace("https://objects.invoicing.co/", "", $company->present()->logo());
|
||||
$path = str_replace("https://v5-at-backup.us-southeast-1.linodeobjects.com/", "", $path);
|
||||
|
||||
Storage::disk($this->option('disk'))->put($path, $logo);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//documents
|
||||
Document::cursor()
|
||||
->each(function ($document){
|
||||
|
||||
->each(function ($document) {
|
||||
$doc_bin = $document->getFile();
|
||||
|
||||
if($doc_bin)
|
||||
if ($doc_bin) {
|
||||
Storage::disk($this->option('disk'))->put($document->url, $doc_bin);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//backups
|
||||
//backups
|
||||
Backup::cursor()
|
||||
->each(function ($backup){
|
||||
->each(function ($backup) {
|
||||
$backup_bin = Storage::disk('s3')->get($backup->filename);
|
||||
|
||||
$backup_bin = Storage::disk('s3')->get($backup->filename);
|
||||
|
||||
if($backup_bin)
|
||||
if ($backup_bin) {
|
||||
Storage::disk($this->option('disk'))->put($backup->filename, $backup_bin);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,7 @@ use App\Models\CreditInvitation;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Paymentable;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use App\Models\Quote;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
@ -102,7 +100,7 @@ class CheckData extends Command
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$time_start = microtime(true);
|
||||
$time_start = microtime(true);
|
||||
|
||||
$database_connection = $this->option('database') ? $this->option('database') : 'Connected to Default DB';
|
||||
$fix_status = $this->option('fix') ? "Fixing Issues" : "Just checking issues ";
|
||||
@ -113,8 +111,8 @@ class CheckData extends Command
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
$this->checkInvoiceBalances();
|
||||
$this->checkClientBalanceEdgeCases();
|
||||
$this->checkInvoiceBalances();
|
||||
$this->checkClientBalanceEdgeCases();
|
||||
$this->checkPaidToDatesNew();
|
||||
$this->checkContacts();
|
||||
$this->checkVendorContacts();
|
||||
@ -128,7 +126,7 @@ class CheckData extends Command
|
||||
$this->checkCompanyTokens();
|
||||
$this->checkUserState();
|
||||
|
||||
if(Ninja::isHosted()){
|
||||
if (Ninja::isHosted()) {
|
||||
$this->checkAccountStatuses();
|
||||
$this->checkNinjaPortalUrls();
|
||||
}
|
||||
@ -162,46 +160,35 @@ class CheckData extends Command
|
||||
|
||||
private function checkCompanyTokens()
|
||||
{
|
||||
|
||||
CompanyUser::doesnthave('token')->cursor()->each(function ($cu){
|
||||
|
||||
if($cu->user){
|
||||
CompanyUser::doesnthave('token')->cursor()->each(function ($cu) {
|
||||
if ($cu->user) {
|
||||
$this->logMessage("Creating missing company token for user # {$cu->user->id} for company id # {$cu->company->id}");
|
||||
(new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->logMessage("Dangling User ID # {$cu->id}");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function checkOauthSanity()
|
||||
{
|
||||
User::where('oauth_provider_id', '1')->cursor()->each(function ($user){
|
||||
|
||||
User::where('oauth_provider_id', '1')->cursor()->each(function ($user) {
|
||||
$this->logMessage("Invalid provider ID for user id# {$user->id}");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private function checkDuplicateRecurringInvoices()
|
||||
{
|
||||
|
||||
if(Ninja::isHosted())
|
||||
{
|
||||
if (Ninja::isHosted()) {
|
||||
$c = Client::on('db-ninja-01')->where('company_id', config('ninja.ninja_default_company_id'))
|
||||
->with('recurring_invoices')
|
||||
->cursor()
|
||||
->each(function ($client){
|
||||
if($client->recurring_invoices()->where('is_deleted', 0)->where('deleted_at', null)->count() > 1)
|
||||
$this->logMessage("Duplicate Recurring Invoice => {$client->custom_value1}");
|
||||
->each(function ($client) {
|
||||
if ($client->recurring_invoices()->where('is_deleted', 0)->where('deleted_at', null)->count() > 1) {
|
||||
$this->logMessage("Duplicate Recurring Invoice => {$client->custom_value1}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -304,7 +291,6 @@ class CheckData extends Command
|
||||
$new_contact->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function checkVendorContacts()
|
||||
@ -352,7 +338,6 @@ class CheckData extends Command
|
||||
}
|
||||
|
||||
if ($this->option('fix') == 'true') {
|
||||
|
||||
$vendors = Vendor::withTrashed()->doesntHave('contacts')->get();
|
||||
|
||||
foreach ($vendors as $vendor) {
|
||||
@ -365,7 +350,6 @@ class CheckData extends Command
|
||||
$new_contact->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -420,27 +404,22 @@ class CheckData extends Command
|
||||
User::withTrashed()
|
||||
->where('deleted_at', '0000-00-00 00:00:00.000000')
|
||||
->cursor()
|
||||
->each(function ($user){
|
||||
->each(function ($user) {
|
||||
$user->restore();
|
||||
});
|
||||
}
|
||||
|
||||
private function checkEntityInvitations()
|
||||
{
|
||||
|
||||
RecurringInvoiceInvitation::where('deleted_at',"0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
|
||||
InvoiceInvitation::where('deleted_at',"0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
|
||||
QuoteInvitation::where('deleted_at',"0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
|
||||
CreditInvitation::where('deleted_at',"0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
|
||||
RecurringInvoiceInvitation::where('deleted_at', "0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
|
||||
InvoiceInvitation::where('deleted_at', "0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
|
||||
QuoteInvitation::where('deleted_at', "0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
|
||||
CreditInvitation::where('deleted_at', "0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
|
||||
|
||||
|
||||
collect([Invoice::class, Quote::class, Credit::class, PurchaseOrder::class])->each(function ($entity){
|
||||
|
||||
if($entity::doesntHave('invitations')->count() > 0)
|
||||
{
|
||||
|
||||
collect([Invoice::class, Quote::class, Credit::class, PurchaseOrder::class])->each(function ($entity) {
|
||||
if ($entity::doesntHave('invitations')->count() > 0) {
|
||||
$entity::doesntHave('invitations')->cursor()->each(function ($entity) {
|
||||
|
||||
$client_vendor_key = 'client_id';
|
||||
$contact_id = 'client_contact_id';
|
||||
$contact_class = ClientContact::class;
|
||||
@ -448,55 +427,47 @@ class CheckData extends Command
|
||||
$entity_key = \Illuminate\Support\Str::of(class_basename($entity))->snake()->append('_id')->value;
|
||||
$entity_obj = get_class($entity).'Invitation';
|
||||
|
||||
if($entity instanceof PurchaseOrder){
|
||||
if ($entity instanceof PurchaseOrder) {
|
||||
$client_vendor_key = 'vendor_id';
|
||||
$contact_id = 'vendor_contact_id';
|
||||
$contact_class = VendorContact::class;
|
||||
}
|
||||
|
||||
$invitation = false;
|
||||
$invitation = false;
|
||||
|
||||
//check contact exists!
|
||||
if($contact_class::where('company_id', $entity->company_id)->where($client_vendor_key,$entity->{$client_vendor_key})->exists())
|
||||
{
|
||||
//check contact exists!
|
||||
if ($contact_class::where('company_id', $entity->company_id)->where($client_vendor_key, $entity->{$client_vendor_key})->exists()) {
|
||||
$contact = $contact_class::where('company_id', $entity->company_id)->where($client_vendor_key, $entity->{$client_vendor_key})->first();
|
||||
|
||||
$contact = $contact_class::where('company_id', $entity->company_id)->where($client_vendor_key,$entity->{$client_vendor_key})->first();
|
||||
|
||||
//double check if an archived invite exists
|
||||
if($contact && $entity_obj::withTrashed()->where($entity_key, $entity->id)->where($contact_id, $contact->id)->count() != 0) {
|
||||
$i = $entity_obj::withTrashed()->where($entity_key, $entity->id)->where($contact_id, $contact->id)->first();
|
||||
$i->restore();
|
||||
$this->logMessage("Found a valid contact and invitation restoring for {$entity_key} - {$entity->id}");
|
||||
}
|
||||
else {
|
||||
$invitation = new $entity_obj();
|
||||
$invitation->company_id = $entity->company_id;
|
||||
$invitation->user_id = $entity->user_id;
|
||||
$invitation->{$entity_key} = $entity->id;
|
||||
$invitation->{$contact_id} = $contact->id;
|
||||
$invitation->key = Str::random(config('ninja.key_length'));
|
||||
$this->logMessage("Add invitation for {$entity_key} - {$entity->id}");
|
||||
}
|
||||
//double check if an archived invite exists
|
||||
if ($contact && $entity_obj::withTrashed()->where($entity_key, $entity->id)->where($contact_id, $contact->id)->count() != 0) {
|
||||
$i = $entity_obj::withTrashed()->where($entity_key, $entity->id)->where($contact_id, $contact->id)->first();
|
||||
$i->restore();
|
||||
$this->logMessage("Found a valid contact and invitation restoring for {$entity_key} - {$entity->id}");
|
||||
} else {
|
||||
$invitation = new $entity_obj();
|
||||
$invitation->company_id = $entity->company_id;
|
||||
$invitation->user_id = $entity->user_id;
|
||||
$invitation->{$entity_key} = $entity->id;
|
||||
$invitation->{$contact_id} = $contact->id;
|
||||
$invitation->key = Str::random(config('ninja.key_length'));
|
||||
$this->logMessage("Add invitation for {$entity_key} - {$entity->id}");
|
||||
}
|
||||
else
|
||||
$this->logMessage("No contact present, so cannot add invitation for {$entity_key} - {$entity->id}");
|
||||
|
||||
try{
|
||||
|
||||
if($invitation)
|
||||
$invitation->save();
|
||||
} else {
|
||||
$this->logMessage("No contact present, so cannot add invitation for {$entity_key} - {$entity->id}");
|
||||
}
|
||||
catch(\Exception $e){
|
||||
|
||||
try {
|
||||
if ($invitation) {
|
||||
$invitation->save();
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
$this->logMessage($e->getMessage());
|
||||
$invitation = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function fixInvitations($entities, $entity)
|
||||
@ -505,8 +476,7 @@ class CheckData extends Command
|
||||
|
||||
$entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation';
|
||||
|
||||
foreach($entities as $entity)
|
||||
{
|
||||
foreach ($entities as $entity) {
|
||||
$invitation = new $entity_obj();
|
||||
$invitation->company_id = $entity->company_id;
|
||||
$invitation->user_id = $entity->user_id;
|
||||
@ -514,20 +484,17 @@ class CheckData extends Command
|
||||
$invitation->client_contact_id = ClientContact::whereClientId($entity->client_id)->first()->id;
|
||||
$invitation->key = Str::random(config('ninja.key_length'));
|
||||
|
||||
try{
|
||||
try {
|
||||
$invitation->save();
|
||||
}
|
||||
catch(\Exception $e){
|
||||
} catch(\Exception $e) {
|
||||
$invitation = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function clientPaidToDateQuery()
|
||||
{
|
||||
$results = \DB::select( \DB::raw("
|
||||
$results = \DB::select(\DB::raw("
|
||||
SELECT
|
||||
clients.id as client_id,
|
||||
clients.paid_to_date as client_paid_to_date,
|
||||
@ -542,14 +509,14 @@ class CheckData extends Command
|
||||
GROUP BY clients.id
|
||||
HAVING payments_applied != client_paid_to_date
|
||||
ORDER BY clients.id;
|
||||
") );
|
||||
"));
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function clientCreditPaymentables($client)
|
||||
{
|
||||
$results = \DB::select( \DB::raw("
|
||||
$results = \DB::select(\DB::raw("
|
||||
SELECT
|
||||
SUM(paymentables.amount - paymentables.refunded) as credit_payment
|
||||
FROM payments
|
||||
@ -561,7 +528,7 @@ class CheckData extends Command
|
||||
AND paymentables.amount > 0
|
||||
AND payments.is_deleted = 0
|
||||
AND payments.client_id = ?;
|
||||
"), [App\Models\Credit::class, $client->id] );
|
||||
"), [App\Models\Credit::class, $client->id]);
|
||||
|
||||
return $results;
|
||||
}
|
||||
@ -572,8 +539,7 @@ class CheckData extends Command
|
||||
|
||||
$this->wrong_paid_to_dates = 0;
|
||||
|
||||
foreach($clients_to_check as $_client)
|
||||
{
|
||||
foreach ($clients_to_check as $_client) {
|
||||
$client = Client::withTrashed()->find($_client->client_id);
|
||||
|
||||
$credits_from_reversal = Credit::withTrashed()->where('client_id', $client->id)->where('is_deleted', 0)->whereNotNull('invoice_id')->sum('amount');
|
||||
@ -582,26 +548,22 @@ class CheckData extends Command
|
||||
|
||||
$total_paid_to_date = $_client->payments_applied + $credits_used_for_payments[0]->credit_payment - $credits_from_reversal;
|
||||
|
||||
if(round($total_paid_to_date,2) != round($_client->client_paid_to_date,2)){
|
||||
|
||||
if (round($total_paid_to_date, 2) != round($_client->client_paid_to_date, 2)) {
|
||||
$this->wrong_paid_to_dates++;
|
||||
|
||||
$this->logMessage($client->present()->name().' id = # '.$client->id." - Client Paid To Date = {$client->paid_to_date} != Invoice Payments = {$total_paid_to_date} - {$_client->payments_applied} + {$credits_used_for_payments[0]->credit_payment}");
|
||||
|
||||
$this->isValid = false;
|
||||
|
||||
if($this->option('paid_to_date')){
|
||||
if ($this->option('paid_to_date')) {
|
||||
$this->logMessage("# {$client->id} " . $client->present()->name().' - '.$client->number." Fixing {$client->paid_to_date} to {$total_paid_to_date}");
|
||||
$client->paid_to_date = $total_paid_to_date;
|
||||
$client->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->logMessage("{$this->wrong_paid_to_dates} clients with incorrect paid to dates");
|
||||
|
||||
}
|
||||
|
||||
private function checkPaidToDates()
|
||||
@ -610,12 +572,12 @@ class CheckData extends Command
|
||||
$credit_total_applied = 0;
|
||||
|
||||
$clients = DB::table('clients')
|
||||
->leftJoin('payments', function($join) {
|
||||
->leftJoin('payments', function ($join) {
|
||||
$join->on('payments.client_id', '=', 'clients.id')
|
||||
->where('payments.is_deleted', 0)
|
||||
->whereIn('payments.status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]);
|
||||
->whereIn('payments.status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]);
|
||||
})
|
||||
->where('clients.is_deleted',0)
|
||||
->where('clients.is_deleted', 0)
|
||||
->where('clients.updated_at', '>', now()->subDays(2))
|
||||
->groupBy('clients.id')
|
||||
->havingRaw('clients.paid_to_date != sum(coalesce(payments.amount - payments.refunded, 0))')
|
||||
@ -623,32 +585,28 @@ class CheckData extends Command
|
||||
|
||||
/* Due to accounting differences we need to perform a second loop here to ensure there actually is an issue */
|
||||
$clients->each(function ($client_record) use ($credit_total_applied) {
|
||||
|
||||
$client = Client::withTrashed()->find($client_record->id);
|
||||
|
||||
$total_invoice_payments = 0;
|
||||
|
||||
foreach ($client->invoices()->where('is_deleted', false)->where('status_id', '>', 1)->get() as $invoice) {
|
||||
|
||||
$total_invoice_payments += $invoice->payments()
|
||||
->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||
->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||
->selectRaw('sum(paymentables.amount - paymentables.refunded) as p')
|
||||
->pluck('p')
|
||||
->first();
|
||||
|
||||
}
|
||||
|
||||
//commented IN 27/06/2021 - sums ALL client payments AND the unapplied amounts to match the client paid to date
|
||||
$p = Payment::where('client_id', $client->id)
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||
->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||
->sum(DB::Raw('amount - applied'));
|
||||
|
||||
$total_invoice_payments += $p;
|
||||
|
||||
// 10/02/21
|
||||
foreach ($client->payments as $payment) {
|
||||
|
||||
$credit_total_applied += $payment->paymentables()
|
||||
->where('paymentable_type', App\Models\Credit::class)
|
||||
->selectRaw('sum(paymentables.amount - paymentables.refunded) as p')
|
||||
@ -658,7 +616,7 @@ class CheckData extends Command
|
||||
|
||||
if ($credit_total_applied < 0) {
|
||||
$total_invoice_payments += $credit_total_applied;
|
||||
}
|
||||
}
|
||||
|
||||
if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) {
|
||||
$this->wrong_paid_to_dates++;
|
||||
@ -667,7 +625,7 @@ class CheckData extends Command
|
||||
|
||||
$this->isValid = false;
|
||||
|
||||
if($this->option('paid_to_date')){
|
||||
if ($this->option('paid_to_date')) {
|
||||
$this->logMessage("# {$client->id} " . $client->present()->name().' - '.$client->number." Fixing {$client->paid_to_date} to {$total_invoice_payments}");
|
||||
$client->paid_to_date = $total_invoice_payments;
|
||||
$client->save();
|
||||
@ -683,11 +641,9 @@ class CheckData extends Command
|
||||
$this->wrong_balances = 0;
|
||||
|
||||
Client::cursor()->where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->each(function ($client) {
|
||||
|
||||
$client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($client) {
|
||||
|
||||
$total_paid = $invoice->payments()
|
||||
->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||
->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||
->selectRaw('sum(paymentables.amount - paymentables.refunded) as p')
|
||||
->pluck('p')
|
||||
->first();
|
||||
@ -704,7 +660,6 @@ class CheckData extends Command
|
||||
$this->isValid = false;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$this->logMessage("{$this->wrong_balances} clients with incorrect invoice balances");
|
||||
@ -712,7 +667,7 @@ class CheckData extends Command
|
||||
|
||||
private function clientBalanceQuery()
|
||||
{
|
||||
$results = \DB::select( \DB::raw("
|
||||
$results = \DB::select(\DB::raw("
|
||||
SELECT
|
||||
SUM(invoices.balance) as invoice_balance,
|
||||
clients.id as client_id,
|
||||
@ -726,7 +681,7 @@ class CheckData extends Command
|
||||
GROUP BY clients.id
|
||||
HAVING invoice_balance != clients.balance
|
||||
ORDER BY clients.id;
|
||||
") );
|
||||
"));
|
||||
|
||||
return $results;
|
||||
}
|
||||
@ -738,8 +693,7 @@ class CheckData extends Command
|
||||
|
||||
$clients = $this->clientBalanceQuery();
|
||||
|
||||
foreach($clients as $client)
|
||||
{
|
||||
foreach ($clients as $client) {
|
||||
$client = (array)$client;
|
||||
|
||||
if ((string) $client['invoice_balance'] != (string) $client['client_balance']) {
|
||||
@ -749,18 +703,14 @@ class CheckData extends Command
|
||||
|
||||
$this->logMessage($client_object->present()->name().' - '.$client_object->id." - calculated client balances do not match Invoice Balances = ". $client['invoice_balance'] ." - Client Balance = ".rtrim($client['client_balance'], '0'));
|
||||
|
||||
if($this->option('client_balance')){
|
||||
|
||||
if ($this->option('client_balance')) {
|
||||
$this->logMessage("# {$client_object->id} " . $client_object->present()->name().' - '.$client_object->number." Fixing {$client_object->balance} to " . $client['invoice_balance']);
|
||||
$client_object->balance = $client['invoice_balance'];
|
||||
$client_object->save();
|
||||
|
||||
}
|
||||
|
||||
$this->isValid = false;
|
||||
|
||||
$this->isValid = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->logMessage("{$this->wrong_paid_to_dates} clients with incorrect client balances");
|
||||
@ -769,58 +719,46 @@ class CheckData extends Command
|
||||
private function checkClientBalanceEdgeCases()
|
||||
{
|
||||
Client::query()
|
||||
->where('is_deleted',false)
|
||||
->where('is_deleted', false)
|
||||
->where('balance', '!=', 0)
|
||||
->cursor()
|
||||
->each(function ($client){
|
||||
->each(function ($client) {
|
||||
$count = Invoice::withTrashed()
|
||||
->where('client_id', $client->id)
|
||||
->where('is_deleted', false)
|
||||
->whereIn('status_id', [2,3])
|
||||
->count();
|
||||
|
||||
$count = Invoice::withTrashed()
|
||||
->where('client_id', $client->id)
|
||||
->where('is_deleted',false)
|
||||
->whereIn('status_id', [2,3])
|
||||
->count();
|
||||
if ($count == 0) {
|
||||
//factor in over payments to the client balance
|
||||
$over_payment = Payment::where('client_id', $client->id)
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [1,4])
|
||||
->selectRaw('sum(amount - applied) as p')
|
||||
->pluck('p')
|
||||
->first();
|
||||
|
||||
if($count == 0){
|
||||
|
||||
//factor in over payments to the client balance
|
||||
$over_payment = Payment::where('client_id', $client->id)
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [1,4])
|
||||
->selectRaw('sum(amount - applied) as p')
|
||||
->pluck('p')
|
||||
->first();
|
||||
$over_payment = $over_payment*-1;
|
||||
|
||||
$over_payment = $over_payment*-1;
|
||||
|
||||
if(floatval($over_payment) == floatval($client->balance)){
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$this->logMessage("# {$client->id} # {$client->name} {$client->balance} is invalid should be {$over_payment}");
|
||||
|
||||
}
|
||||
if (floatval($over_payment) == floatval($client->balance)) {
|
||||
} else {
|
||||
$this->logMessage("# {$client->id} # {$client->name} {$client->balance} is invalid should be {$over_payment}");
|
||||
}
|
||||
|
||||
|
||||
if($this->option('client_balance') && (floatval($over_payment) != floatval($client->balance) )){
|
||||
|
||||
$this->logMessage("# {$client->id} " . $client->present()->name().' - '.$client->number." Fixing {$client->balance} to 0");
|
||||
|
||||
$client->balance = $over_payment;
|
||||
$client->save();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if ($this->option('client_balance') && (floatval($over_payment) != floatval($client->balance))) {
|
||||
$this->logMessage("# {$client->id} " . $client->present()->name().' - '.$client->number." Fixing {$client->balance} to 0");
|
||||
|
||||
$client->balance = $over_payment;
|
||||
$client->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function invoiceBalanceQuery()
|
||||
{
|
||||
$results = \DB::select( \DB::raw("
|
||||
$results = \DB::select(\DB::raw("
|
||||
SELECT
|
||||
clients.id,
|
||||
clients.balance,
|
||||
@ -834,7 +772,7 @@ class CheckData extends Command
|
||||
GROUP BY clients.id
|
||||
HAVING(invoices_balance != clients.balance)
|
||||
ORDER BY clients.id;
|
||||
") );
|
||||
"));
|
||||
|
||||
return $results;
|
||||
}
|
||||
@ -846,8 +784,7 @@ class CheckData extends Command
|
||||
|
||||
$_clients = $this->invoiceBalanceQuery();
|
||||
|
||||
foreach($_clients as $_client)
|
||||
{
|
||||
foreach ($_clients as $_client) {
|
||||
$client = Client::withTrashed()->find($_client->id);
|
||||
|
||||
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3])->sum('balance');
|
||||
@ -862,27 +799,22 @@ class CheckData extends Command
|
||||
|
||||
$this->isValid = false;
|
||||
|
||||
if($this->option('client_balance')){
|
||||
|
||||
if ($this->option('client_balance')) {
|
||||
$this->logMessage("# {$client->id} " . $client->present()->name().' - '.$client->number." Fixing {$client->balance} to {$invoice_balance}");
|
||||
$client->balance = $invoice_balance;
|
||||
$client->save();
|
||||
|
||||
}
|
||||
|
||||
if($ledger && (number_format($invoice_balance, 4) != number_format($ledger->balance, 4)))
|
||||
{
|
||||
if ($ledger && (number_format($invoice_balance, 4) != number_format($ledger->balance, 4))) {
|
||||
$ledger->adjustment = $invoice_balance;
|
||||
$ledger->balance = $invoice_balance;
|
||||
$ledger->notes = 'Ledger Adjustment';
|
||||
$ledger->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->logMessage("{$this->wrong_balances} clients with incorrect balances");
|
||||
|
||||
}
|
||||
|
||||
private function checkLedgerBalances()
|
||||
@ -901,8 +833,7 @@ class CheckData extends Command
|
||||
$this->isValid = false;
|
||||
|
||||
|
||||
if($this->option('ledger_balance')){
|
||||
|
||||
if ($this->option('ledger_balance')) {
|
||||
$this->logMessage("# {$client->id} " . $client->present()->name().' - '.$client->number." Fixing {$client->balance} to {$invoice_balance}");
|
||||
$client->balance = $invoice_balance;
|
||||
$client->save();
|
||||
@ -912,7 +843,6 @@ class CheckData extends Command
|
||||
$ledger->notes = 'Ledger Adjustment';
|
||||
$ledger->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1004,31 +934,27 @@ class CheckData extends Command
|
||||
|
||||
public function checkAccountStatuses()
|
||||
{
|
||||
Account::where('plan_expires', '<=', now()->subDays(2))->cursor()->each(function ($account){
|
||||
|
||||
Account::where('plan_expires', '<=', now()->subDays(2))->cursor()->each(function ($account) {
|
||||
$client = Client::on('db-ninja-01')->where('company_id', config('ninja.ninja_default_company_id'))->where('custom_value2', $account->key)->first();
|
||||
|
||||
if($client){
|
||||
if ($client) {
|
||||
$payment = Payment::on('db-ninja-01')
|
||||
->where('company_id', config('ninja.ninja_default_company_id'))
|
||||
->where('client_id', $client->id)
|
||||
->where('date', '>=', now()->subDays(2))
|
||||
->exists();
|
||||
|
||||
if($payment)
|
||||
if ($payment) {
|
||||
$this->logMessage("I found a payment for {$account->key}");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function checkClientSettings()
|
||||
{
|
||||
|
||||
if ($this->option('fix') == 'true') {
|
||||
|
||||
// Client::query()->whereNull('settings->currency_id')->cursor()->each(function ($client){
|
||||
|
||||
// if(is_array($client->settings) && count($client->settings) == 0)
|
||||
@ -1049,36 +975,25 @@ class CheckData extends Command
|
||||
// });
|
||||
|
||||
|
||||
Client::query()->whereNull('country_id')->cursor()->each(function ($client){
|
||||
|
||||
Client::query()->whereNull('country_id')->cursor()->each(function ($client) {
|
||||
$client->country_id = $client->company->settings->country_id;
|
||||
$client->save();
|
||||
|
||||
$this->logMessage("Fixing country for # {$client->id}");
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function checkVendorSettings()
|
||||
{
|
||||
|
||||
if ($this->option('fix') == 'true')
|
||||
{
|
||||
|
||||
Vendor::query()->whereNull('currency_id')->orWhere('currency_id', '')->cursor()->each(function ($vendor){
|
||||
|
||||
if ($this->option('fix') == 'true') {
|
||||
Vendor::query()->whereNull('currency_id')->orWhere('currency_id', '')->cursor()->each(function ($vendor) {
|
||||
$vendor->currency_id = $vendor->company->settings->currency_id;
|
||||
$vendor->save();
|
||||
|
||||
$this->logMessage("Fixing vendor currency for # {$vendor->id}");
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1087,14 +1002,12 @@ class CheckData extends Command
|
||||
{
|
||||
$this->wrong_paid_status = 0;
|
||||
|
||||
foreach(Invoice::with(['payments'])->where('is_deleted',0)->where('balance', '>', 0)->whereHas('payments')->where('status_id', 4)->cursor() as $invoice)
|
||||
{
|
||||
foreach (Invoice::with(['payments'])->where('is_deleted', 0)->where('balance', '>', 0)->whereHas('payments')->where('status_id', 4)->cursor() as $invoice) {
|
||||
$this->wrong_paid_status++;
|
||||
|
||||
$this->logMessage("# {$invoice->id} " . ' - '.$invoice->number." - Marked as paid, but balance = {$invoice->balance}");
|
||||
|
||||
if($this->option('balance_status')){
|
||||
|
||||
if ($this->option('balance_status')) {
|
||||
$val = $invoice->balance;
|
||||
|
||||
$invoice->balance = 0;
|
||||
@ -1103,8 +1016,7 @@ class CheckData extends Command
|
||||
|
||||
$p = $invoice->payments->first();
|
||||
|
||||
if($p && (int)$p->amount == 0)
|
||||
{
|
||||
if ($p && (int)$p->amount == 0) {
|
||||
$p->amount = $val;
|
||||
$p->applied = $val;
|
||||
$p->save();
|
||||
@ -1116,62 +1028,48 @@ class CheckData extends Command
|
||||
|
||||
|
||||
$this->logMessage("Fixing {$invoice->id} settings payment to {$val}");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->logMessage($this->wrong_paid_status." wrong invoices with bad balance state");
|
||||
|
||||
}
|
||||
|
||||
public function checkNinjaPortalUrls()
|
||||
{
|
||||
|
||||
$wrong_count = CompanyUser::where('is_owner',1)->where('ninja_portal_url', '')->count();
|
||||
$wrong_count = CompanyUser::where('is_owner', 1)->where('ninja_portal_url', '')->count();
|
||||
|
||||
$this->logMessage("Missing ninja portal Urls = {$wrong_count}");
|
||||
|
||||
if(!$this->option('portal_url'))
|
||||
if (!$this->option('portal_url')) {
|
||||
return;
|
||||
}
|
||||
|
||||
CompanyUser::where('is_owner',1)->where('ninja_portal_url', '')->cursor()->each(function ($cu){
|
||||
CompanyUser::where('is_owner', 1)->where('ninja_portal_url', '')->cursor()->each(function ($cu) {
|
||||
$cc = ClientContact::on('db-ninja-01')->where('company_id', config('ninja.ninja_default_company_id'))->where('email', $cu->user->email)->first();
|
||||
|
||||
$cc = ClientContact::on('db-ninja-01')->where('company_id', config('ninja.ninja_default_company_id'))->where('email', $cu->user->email)->first();
|
||||
|
||||
if($cc){
|
||||
$ninja_portal_url = "https://invoiceninja.invoicing.co/client/ninja/{$cc->contact_key}/{$cu->company->company_key}";
|
||||
if ($cc) {
|
||||
$ninja_portal_url = "https://invoiceninja.invoicing.co/client/ninja/{$cc->contact_key}/{$cu->account->key}";
|
||||
|
||||
$cu->ninja_portal_url = $ninja_portal_url;
|
||||
$cu->save();
|
||||
|
||||
$this->logMessage("Fixing - {$ninja_portal_url}");
|
||||
}
|
||||
else{
|
||||
|
||||
} else {
|
||||
$c = Client::on('db-ninja-01')->where("company_id", config('ninja.ninja_default_company_id'))->where('custom_value2', $cu->account->key)->first();
|
||||
|
||||
if($c)
|
||||
{
|
||||
|
||||
$cc = $c->contacts()->first();
|
||||
if ($c) {
|
||||
$cc = $c->contacts()->first();
|
||||
|
||||
if($cc)
|
||||
{
|
||||
if ($cc) {
|
||||
$ninja_portal_url = "https://invoiceninja.invoicing.co/client/ninja/{$cc->contact_key}/{$cu->account->key}";
|
||||
|
||||
$cu->ninja_portal_url = $ninja_portal_url;
|
||||
$cu->save();
|
||||
|
||||
$this->logMessage("Fixing - {$ninja_portal_url}");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App;
|
||||
use App\Factory\ClientContactFactory;
|
||||
use App\Models\Account;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Backup;
|
||||
@ -24,7 +22,6 @@ use App\Models\CompanyGateway;
|
||||
use App\Models\CompanyLedger;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Credit;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\Design;
|
||||
@ -53,13 +50,7 @@ use App\Models\User;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\VendorContact;
|
||||
use App\Models\Webhook;
|
||||
use App\Utils\Ninja;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Mail;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Class CheckDb.
|
||||
|
@ -11,41 +11,21 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\DataMapper\ClientRegistrationFields;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\FeesAndLimits;
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceItemFactory;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Jobs\Company\CreateCompanyPaymentTerms;
|
||||
use App\Jobs\Company\CreateCompanyTaskStatuses;
|
||||
use App\Jobs\Util\VersionCheck;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\Country;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\VendorContact;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Carbon\Carbon;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateAccount extends Command
|
||||
@ -94,7 +74,10 @@ class CreateAccount extends Command
|
||||
'portal_domain' => config('ninja.app_url'),
|
||||
'portal_mode' => 'domain',
|
||||
]);
|
||||
|
||||
|
||||
$company->client_registration_fields = ClientRegistrationFields::generate();
|
||||
$company->save();
|
||||
|
||||
$account->default_company_id = $company->id;
|
||||
$account->save();
|
||||
|
||||
@ -136,7 +119,6 @@ class CreateAccount extends Command
|
||||
(new VersionCheck())->handle();
|
||||
|
||||
$this->warmCache();
|
||||
|
||||
}
|
||||
|
||||
private function warmCache()
|
||||
@ -158,7 +140,6 @@ class CreateAccount extends Command
|
||||
if ($tableData->count()) {
|
||||
Cache::forever($name, $tableData);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,13 +50,11 @@ use App\Utils\Ninja;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Carbon\Carbon;
|
||||
use Database\Factories\BankTransactionRuleFactory;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use stdClass;
|
||||
|
||||
class CreateSingleAccount extends Command
|
||||
@ -80,9 +78,9 @@ class CreateSingleAccount extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
if (Ninja::isHosted() || config('ninja.is_docker') || !$this->confirm('Are you sure you want to inject dummy data?'))
|
||||
if (Ninja::isHosted() || config('ninja.is_docker') || !$this->confirm('Are you sure you want to inject dummy data?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->invoice_repo = new InvoiceRepository();
|
||||
|
||||
@ -103,8 +101,7 @@ class CreateSingleAccount extends Command
|
||||
{
|
||||
$this->info('Creating Small Account and Company');
|
||||
|
||||
if($user = User::where('email','small@example.com')->first())
|
||||
{
|
||||
if ($user = User::where('email', 'small@example.com')->first()) {
|
||||
$user->account->delete();
|
||||
}
|
||||
|
||||
@ -201,7 +198,7 @@ class CreateSingleAccount extends Command
|
||||
$btr = BankTransactionRule::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'applies_to' => (bool)rand(0,1) ? 'CREDIT' : 'DEBIT',
|
||||
'applies_to' => (bool)rand(0, 1) ? 'CREDIT' : 'DEBIT',
|
||||
]);
|
||||
|
||||
$client = Client::factory()->create([
|
||||
@ -359,7 +356,6 @@ class CreateSingleAccount extends Command
|
||||
|
||||
private function createClient($company, $user)
|
||||
{
|
||||
|
||||
// dispatch(function () use ($company, $user) {
|
||||
|
||||
// });
|
||||
@ -630,30 +626,29 @@ class CreateSingleAccount extends Command
|
||||
$cached_tables = config('ninja.cached_tables');
|
||||
|
||||
foreach ($cached_tables as $name => $class) {
|
||||
// check that the table exists in case the migration is pending
|
||||
if (! Schema::hasTable((new $class())->getTable())) {
|
||||
continue;
|
||||
}
|
||||
if ($name == 'payment_terms') {
|
||||
$orderBy = 'num_days';
|
||||
} elseif ($name == 'fonts') {
|
||||
$orderBy = 'sort_order';
|
||||
} elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
|
||||
$orderBy = 'name';
|
||||
} else {
|
||||
$orderBy = 'id';
|
||||
}
|
||||
$tableData = $class::orderBy($orderBy)->get();
|
||||
if ($tableData->count()) {
|
||||
Cache::forever($name, $tableData);
|
||||
}
|
||||
// check that the table exists in case the migration is pending
|
||||
if (! Schema::hasTable((new $class())->getTable())) {
|
||||
continue;
|
||||
}
|
||||
if ($name == 'payment_terms') {
|
||||
$orderBy = 'num_days';
|
||||
} elseif ($name == 'fonts') {
|
||||
$orderBy = 'sort_order';
|
||||
} elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
|
||||
$orderBy = 'name';
|
||||
} else {
|
||||
$orderBy = 'id';
|
||||
}
|
||||
$tableData = $class::orderBy($orderBy)->get();
|
||||
if ($tableData->count()) {
|
||||
Cache::forever($name, $tableData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createGateways($company, $user)
|
||||
{
|
||||
if (config('ninja.testvars.stripe') && ($this->gateway == 'all' || $this->gateway == 'stripe')) {
|
||||
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $company->id;
|
||||
$cg->user_id = $user->id;
|
||||
@ -672,8 +667,6 @@ class CreateSingleAccount extends Command
|
||||
|
||||
$cg->fees_and_limits = $fees_and_limits;
|
||||
$cg->save();
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (config('ninja.testvars.paypal') && ($this->gateway == 'all' || $this->gateway == 'paypal')) {
|
||||
|
@ -380,7 +380,6 @@ class CreateTestData extends Command
|
||||
|
||||
private function createClient($company, $user)
|
||||
{
|
||||
|
||||
// dispatch(function () use ($company, $user) {
|
||||
|
||||
// });
|
||||
|
@ -257,7 +257,6 @@ class DemoMode extends Command
|
||||
|
||||
private function createClient($company, $user, $assigned_user_id = null)
|
||||
{
|
||||
|
||||
// dispatch(function () use ($company, $user) {
|
||||
|
||||
// });
|
||||
|
@ -56,7 +56,6 @@ class DesignUpdate extends Command
|
||||
if (! config('ninja.db.multi_db_enabled')) {
|
||||
$this->handleOnDb();
|
||||
} else {
|
||||
|
||||
//multiDB environment, need to
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
MultiDB::setDB($db);
|
||||
|
@ -11,27 +11,19 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Exceptions\MigrationValidatorFailed;
|
||||
use App\Exceptions\NonExistingMigrationFile;
|
||||
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
||||
use App\Exceptions\ResourceDependencyMissing;
|
||||
use App\Exceptions\ResourceNotAvailableForMigration;
|
||||
use App\Jobs\Util\Import;
|
||||
use App\Jobs\Util\StartMigration;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\MigrationFailed;
|
||||
use App\Models\Account;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use DirectoryIterator;
|
||||
use Faker\Factory;
|
||||
use Faker\Generator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use ZipArchive;
|
||||
|
||||
class HostedMigrations extends Command
|
||||
|
@ -11,9 +11,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use App\Utils\CurlUtils;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
120
app/Console/Commands/OpenApiYaml.php
Normal file
120
app/Console/Commands/OpenApiYaml.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class OpenApiYaml extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ninja:openapi';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Build OpenApi YAML';
|
||||
|
||||
private array $directories = [
|
||||
'/components/schemas',
|
||||
'/paths/'
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->faker = Factory::create();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$path = base_path('openapi');
|
||||
|
||||
$directory = new DirectoryIterator($path);
|
||||
|
||||
$this->info($directory);
|
||||
|
||||
foreach ($directory as $file) {
|
||||
$this->info($file);
|
||||
}
|
||||
|
||||
Storage::disk('base')->delete('/openapi/api-docs.yaml');
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/info.yaml'));
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/paths.yaml'));
|
||||
|
||||
//iterate paths
|
||||
$directory = new DirectoryIterator($path . '/paths/');
|
||||
|
||||
foreach ($directory as $file) {
|
||||
if ($file->isFile() && ! $file->isDot()) {
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents("{$path}/paths/{$file->getFilename()}"));
|
||||
}
|
||||
}
|
||||
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components.yaml'));
|
||||
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/responses.yaml'));
|
||||
|
||||
$directory = new DirectoryIterator($path . '/components/responses/');
|
||||
|
||||
foreach ($directory as $file) {
|
||||
if ($file->isFile() && ! $file->isDot()) {
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents("{$path}/components/responses/{$file->getFilename()}"));
|
||||
}
|
||||
}
|
||||
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/parameters.yaml'));
|
||||
|
||||
$directory = new DirectoryIterator($path . '/components/parameters/');
|
||||
|
||||
foreach ($directory as $file) {
|
||||
if ($file->isFile() && ! $file->isDot()) {
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents("{$path}/components/parameters/{$file->getFilename()}"));
|
||||
}
|
||||
}
|
||||
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/schemas.yaml'));
|
||||
|
||||
//iterate schemas
|
||||
|
||||
$directory = new DirectoryIterator($path . '/components/schemas/');
|
||||
|
||||
foreach ($directory as $file) {
|
||||
if ($file->isFile() && ! $file->isDot()) {
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents("{$path}/components/schemas/{$file->getFilename()}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/schemas/account.yaml'));
|
||||
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/misc/misc.yaml'));
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\Util\VersionCheck;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
@ -11,12 +11,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Backup;
|
||||
use App\Models\Design;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use stdClass;
|
||||
|
||||
class ReactBuilder extends Command
|
||||
{
|
||||
|
@ -14,7 +14,6 @@ namespace App\Console\Commands;
|
||||
use App\DataMapper\InvoiceItem;
|
||||
use App\Events\Invoice\InvoiceWasEmailed;
|
||||
use App\Jobs\Entity\EmailEntity;
|
||||
use App\Jobs\Ninja\SendReminders;
|
||||
use App\Jobs\Util\WebhookHandler;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Invoice;
|
||||
@ -97,7 +96,6 @@ class SendRemindersCron extends Command
|
||||
$invoice->save();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function calcLateFee($invoice, $template) :Invoice
|
||||
|
@ -13,22 +13,14 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Factory\ClientFactory;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceInvitationFactory;
|
||||
use App\Jobs\Invoice\CreateEntityPdf;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Mail\Migration\MaxCompanies;
|
||||
use App\Mail\TemplateEmail;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendTestEmails extends Command
|
||||
{
|
||||
|
@ -11,14 +11,10 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Backup;
|
||||
use App\Models\Design;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use stdClass;
|
||||
|
||||
class TranslationsExport extends Command
|
||||
{
|
||||
@ -98,42 +94,35 @@ class TranslationsExport extends Command
|
||||
{
|
||||
$type =$this->option('type') ?? 'export';
|
||||
|
||||
if($type == 'import')
|
||||
if ($type == 'import') {
|
||||
$this->import();
|
||||
}
|
||||
|
||||
if($type == 'export')
|
||||
if ($type == 'export') {
|
||||
$this->export();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function import()
|
||||
{
|
||||
//loop and
|
||||
|
||||
foreach($this->langs as $lang)
|
||||
{
|
||||
|
||||
foreach ($this->langs as $lang) {
|
||||
$import_file = "textsphp_{$lang}.php";
|
||||
$dir = $this->option('path') ?? storage_path('lang_import/');
|
||||
$path = $dir.$import_file;
|
||||
|
||||
if(file_exists($path)){
|
||||
if (file_exists($path)) {
|
||||
$this->logMessage($path);
|
||||
|
||||
$trans = file_get_contents($path);
|
||||
|
||||
file_put_contents(lang_path("/{$lang}/texts.php"), $trans);
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
} else {
|
||||
$this->logMessage("Could not open file");
|
||||
$this->logMessage($path);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +136,7 @@ class TranslationsExport extends Command
|
||||
$translations = Lang::getLoader()->load($lang, 'texts');
|
||||
|
||||
Storage::disk('local')->put("lang/{$lang}/{$lang}.json", json_encode(Arr::dot($translations), JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function logMessage($str)
|
||||
@ -156,5 +145,4 @@ class TranslationsExport extends Command
|
||||
$this->info($str);
|
||||
$this->log .= $str."\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,17 +11,11 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\ValidationRules\ValidClientGroupSettingsRule;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Backup;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Design;
|
||||
use App\Utils\Traits\ClientGroupSettingsSaver;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use stdClass;
|
||||
|
||||
class TypeCheck extends Command
|
||||
{
|
||||
|
@ -15,14 +15,13 @@ use App\Jobs\Cron\AutoBillCron;
|
||||
use App\Jobs\Cron\RecurringExpensesCron;
|
||||
use App\Jobs\Cron\RecurringInvoicesCron;
|
||||
use App\Jobs\Cron\SubscriptionCron;
|
||||
use App\Jobs\Ledger\LedgerBalanceUpdate;
|
||||
use App\Jobs\Invoice\InvoiceCheckLateWebhook;
|
||||
use App\Jobs\Ninja\AdjustEmailQuota;
|
||||
use App\Jobs\Ninja\BankTransactionSync;
|
||||
use App\Jobs\Ninja\CompanySizeCheck;
|
||||
use App\Jobs\Ninja\QueueSize;
|
||||
use App\Jobs\Ninja\SystemMaintenance;
|
||||
use App\Jobs\Ninja\TaskScheduler;
|
||||
use App\Jobs\Invoice\InvoiceCheckLateWebhook;
|
||||
use App\Jobs\Quote\QuoteCheckExpired;
|
||||
use App\Jobs\Subscription\CleanStaleInvoiceOrder;
|
||||
use App\Jobs\Util\DiskCleanup;
|
||||
@ -96,16 +95,13 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
|
||||
if (Ninja::isSelfHost()) {
|
||||
|
||||
$schedule->call(function () {
|
||||
Account::whereNotNull('id')->update(['is_scheduler_running' => true]);
|
||||
})->everyFiveMinutes();
|
||||
|
||||
}
|
||||
|
||||
/* Run hosted specific jobs */
|
||||
if (Ninja::isHosted()) {
|
||||
|
||||
$schedule->job(new AdjustEmailQuota)->dailyAt('23:30')->withoutOverlapping();
|
||||
|
||||
/* Pulls in bank transactions from third party services */
|
||||
@ -119,15 +115,12 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('02:20')->withoutOverlapping()->name('check-data-db-2-job')->onOneServer();
|
||||
|
||||
$schedule->command('ninja:s3-cleanup')->dailyAt('23:15')->withoutOverlapping()->name('s3-cleanup-job')->onOneServer();
|
||||
|
||||
}
|
||||
|
||||
if (config('queue.default') == 'database' && Ninja::isSelfHost() && config('ninja.internal_queue_enabled') && ! config('ninja.is_docker')) {
|
||||
|
||||
$schedule->command('queue:work database --stop-when-empty --memory=256')->everyMinute()->withoutOverlapping();
|
||||
|
||||
$schedule->command('queue:restart')->everyFiveMinutes()->withoutOverlapping();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,5 +57,4 @@ class BaseSettings
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
public $page_layout = 'portrait';
|
||||
|
||||
public $font_size = 7; //@implemented
|
||||
public $font_size = 16; //@implemented
|
||||
|
||||
public $primary_font = 'Roboto';
|
||||
|
||||
@ -442,6 +442,8 @@ class CompanySettings extends BaseSettings
|
||||
public $send_email_on_mark_paid = false;
|
||||
|
||||
public $postmark_secret = '';
|
||||
|
||||
public $custom_sending_email = '';
|
||||
|
||||
public $mailgun_secret = '';
|
||||
|
||||
@ -459,7 +461,17 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
public $show_shipping_address = false;
|
||||
|
||||
public $accept_client_input_quote_approval = false;
|
||||
|
||||
public $allow_billable_task_items = false;
|
||||
|
||||
public $show_task_item_description = false;
|
||||
|
||||
public static $casts = [
|
||||
'show_task_item_description' => 'bool',
|
||||
'allow_billable_task_items' => 'bool',
|
||||
'accept_client_input_quote_approval' => 'bool',
|
||||
'custom_sending_email' => 'string',
|
||||
'show_paid_stamp' => 'bool',
|
||||
'show_shipping_address' => 'bool',
|
||||
'company_logo_size' => 'string',
|
||||
@ -756,7 +768,6 @@ class CompanySettings extends BaseSettings
|
||||
*/
|
||||
public static function defaults(): stdClass
|
||||
{
|
||||
|
||||
$data = (object) get_class_vars(self::class);
|
||||
|
||||
unset($data->casts);
|
||||
@ -828,7 +839,6 @@ class CompanySettings extends BaseSettings
|
||||
'$client.address1',
|
||||
'$client.address2',
|
||||
'$client.city_state_postal',
|
||||
'$client.postal_city',
|
||||
'$client.country',
|
||||
'$client.phone',
|
||||
'$contact.email',
|
||||
@ -840,7 +850,6 @@ class CompanySettings extends BaseSettings
|
||||
'$vendor.address1',
|
||||
'$vendor.address2',
|
||||
'$vendor.city_state_postal',
|
||||
'$vendor.postal_city',
|
||||
'$vendor.country',
|
||||
'$vendor.phone',
|
||||
'$contact.email',
|
||||
@ -865,7 +874,6 @@ class CompanySettings extends BaseSettings
|
||||
'$company.address1',
|
||||
'$company.address2',
|
||||
'$company.city_state_postal',
|
||||
'$company.postal_city',
|
||||
'$company.country',
|
||||
],
|
||||
'invoice_details' => [
|
||||
|
@ -20,7 +20,6 @@ class EmailTemplateDefaults
|
||||
App::setLocale($locale);
|
||||
|
||||
switch ($template) {
|
||||
|
||||
/* Template */
|
||||
|
||||
case 'email_template_invoice':
|
||||
@ -65,7 +64,7 @@ class EmailTemplateDefaults
|
||||
return self::emailPurchaseOrderTemplate();
|
||||
break;
|
||||
|
||||
/* Subject */
|
||||
/* Subject */
|
||||
case 'email_subject_purchase_order':
|
||||
return self::emailPurchaseOrderSubject();
|
||||
case 'email_subject_invoice':
|
||||
@ -240,7 +239,6 @@ class EmailTemplateDefaults
|
||||
|
||||
public static function emailStatementTemplate()
|
||||
{
|
||||
|
||||
$statement_message = '<p>$client<br><br>'.self::transformText('client_statement_body').'<br></p>';
|
||||
|
||||
return $statement_message;
|
||||
|
@ -11,24 +11,20 @@
|
||||
|
||||
namespace App\DataMapper\Schedule;
|
||||
|
||||
use App\Models\Client;
|
||||
use stdClass;
|
||||
|
||||
class ClientStatement
|
||||
class EmailStatement
|
||||
{
|
||||
|
||||
/**
|
||||
* Defines the template name
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $template = 'client_statement';
|
||||
public string $template = 'email_statement';
|
||||
|
||||
/**
|
||||
* An array of clients hashed_ids
|
||||
*
|
||||
* Leave blank if this action should apply to all clients
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public array $clients = [];
|
||||
@ -36,17 +32,21 @@ class ClientStatement
|
||||
/**
|
||||
* The consts to be used to define the date_range variable of the statement
|
||||
*/
|
||||
public const THIS_MONTH = 'this_month';
|
||||
public const THIS_QUARTER = 'this_quarter';
|
||||
public const THIS_YEAR = 'this_year';
|
||||
public const PREVIOUS_MONTH = 'previous_month';
|
||||
public const PREVIOUS_QUARTER = 'previous_quarter';
|
||||
public const PREVIOUS_YEAR = 'previous_year';
|
||||
public const CUSTOM_RANGE = "custom_range";
|
||||
public const LAST7 = "last7_days";
|
||||
public const LAST30 = "last30_days";
|
||||
public const LAST365 = "last365_days";
|
||||
public const THIS_MONTH = "this_month";
|
||||
public const LAST_MONTH = "last_month";
|
||||
public const THIS_QUARTER = "this_quarter";
|
||||
public const LAST_QUARTER = "last_quarter";
|
||||
public const THIS_YEAR = "this_year";
|
||||
public const LAST_YEAR = "last_year";
|
||||
public const CUSTOM_RANGE = "custom";
|
||||
|
||||
|
||||
/**
|
||||
* The date range the statement should include
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $date_range = 'this_month';
|
||||
@ -54,7 +54,7 @@ class ClientStatement
|
||||
/**
|
||||
* If a custom range is select for the date range then
|
||||
* the start_date should be supplied in Y-m-d format
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $start_date = '';
|
||||
@ -62,7 +62,7 @@ class ClientStatement
|
||||
/**
|
||||
* If a custom range is select for the date range then
|
||||
* the end_date should be supplied in Y-m-d format
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $end_date = '';
|
||||
@ -87,10 +87,8 @@ class ClientStatement
|
||||
* String const which defines whether
|
||||
* the invoices to be shown are either
|
||||
* paid or unpaid
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $status = 'paid'; // paid | unpaid
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,6 @@ namespace App\Events\PurchaseOrder;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use App\Models\VendorContact;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
|
@ -4,11 +4,8 @@ namespace App\Events\Subscription;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
|
19
app/Exceptions/ClientHostedMigrationException.php
Normal file
19
app/Exceptions/ClientHostedMigrationException.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ClientHostedMigrationException extends Exception
|
||||
{
|
||||
// ..
|
||||
}
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Exceptions\InternalPDFFailure;
|
||||
use App\Exceptions\PhantomPDFFailure;
|
||||
use App\Exceptions\StripeConnectFailure;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
@ -29,14 +25,13 @@ use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use League\Flysystem\UnableToCreateDirectory;
|
||||
use PDOException;
|
||||
use Sentry\Laravel\Integration;
|
||||
use Sentry\State\Scope;
|
||||
use Symfony\Component\Console\Exception\CommandNotFoundException;
|
||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use League\Flysystem\UnableToCreateDirectory;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
@ -68,6 +63,7 @@ class Handler extends ExceptionHandler
|
||||
Symfony\Component\Process\Exception\RuntimeException::class,
|
||||
InvalidArgumentException::class,
|
||||
RuntimeException::class,
|
||||
Aws\Exception\CredentialsException::class,
|
||||
];
|
||||
|
||||
protected $hostedDontReport = [
|
||||
@ -128,7 +124,6 @@ class Handler extends ExceptionHandler
|
||||
if ($this->validException($exception) && $this->sentryShouldReport($exception)) {
|
||||
Integration::captureUnhandledException($exception);
|
||||
}
|
||||
|
||||
} elseif (app()->bound('sentry')) {
|
||||
Integration::configureScope(function (Scope $scope): void {
|
||||
if (auth()->guard('contact') && auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) {
|
||||
@ -192,10 +187,11 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
protected function sentryShouldReport(Throwable $e)
|
||||
{
|
||||
if(Ninja::isHosted())
|
||||
if (Ninja::isHosted()) {
|
||||
$dontReport = array_merge($this->hostedDontReport, $this->internalDontReport);
|
||||
else
|
||||
} else {
|
||||
$dontReport = array_merge($this->selfHostDontReport, $this->internalDontReport);
|
||||
}
|
||||
|
||||
return is_null(Arr::first($dontReport, fn ($type) => $e instanceof $type));
|
||||
}
|
||||
@ -222,7 +218,7 @@ class Handler extends ExceptionHandler
|
||||
return response()->json(['message'=>'Too many requests'], 429);
|
||||
// } elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) {
|
||||
// return response()->json(['message'=>'Fatal error'], 500); //@deprecated
|
||||
} elseif ($exception instanceof AuthorizationException) {
|
||||
} elseif ($exception instanceof AuthorizationException && $request->expectsJson()) {
|
||||
return response()->json(['message'=> $exception->getMessage()], 401);
|
||||
} elseif ($exception instanceof TokenMismatchException) {
|
||||
return redirect()
|
||||
@ -245,7 +241,7 @@ class Handler extends ExceptionHandler
|
||||
return response()->json(['message' => $exception->getMessage()], 400);
|
||||
} elseif ($exception instanceof StripeConnectFailure) {
|
||||
return response()->json(['message' => $exception->getMessage()], 400);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
@ -259,7 +255,7 @@ class Handler extends ExceptionHandler
|
||||
$guard = Arr::get($exception->guards(), 0);
|
||||
|
||||
switch ($guard) {
|
||||
case 'contact':
|
||||
case 'contact':
|
||||
$login = 'client.login';
|
||||
break;
|
||||
case 'user':
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
33
app/Exceptions/Ninja/ClientPortalAuthorizationException.php
Normal file
33
app/Exceptions/Ninja/ClientPortalAuthorizationException.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Exceptions\Ninja;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ClientPortalAuthorizationException extends Exception
|
||||
{
|
||||
public function report()
|
||||
{
|
||||
// ..
|
||||
}
|
||||
|
||||
public function render($request)
|
||||
{
|
||||
return view('errors.client-error', [
|
||||
'account' => auth()->guard('contact')->check() ? auth()->guard('contact')->user()->user->account : false,
|
||||
'company' => auth()->guard('contact')->check() ? auth()->guard('contact')->user()->company : false,
|
||||
'title' => ctrans('texts.error_title'),
|
||||
'message' => $this->getMessage(),
|
||||
'code' => $this->getCode(),
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
@ -13,8 +23,7 @@ class PaymentFailed extends Exception
|
||||
|
||||
public function render($request)
|
||||
{
|
||||
if (auth()->guard('contact')->user() || ($request->has('cko-session-id') && $request->query('cko-session-id') )) {
|
||||
|
||||
if (auth()->guard('contact')->user() || ($request->has('cko-session-id') && $request->query('cko-session-id'))) {
|
||||
return render('gateways.unsuccessful', [
|
||||
'message' => $this->getMessage(),
|
||||
'code' => $this->getCode(),
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
@ -26,7 +36,6 @@ class PaymentRefundFailed extends Exception
|
||||
*/
|
||||
public function render($request)
|
||||
{
|
||||
|
||||
// $msg = 'Unable to refund the transaction';
|
||||
$msg = ctrans('texts.warning_local_refund');
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
@ -26,7 +36,6 @@ class YodleeApiException extends Exception
|
||||
*/
|
||||
public function render($request)
|
||||
{
|
||||
|
||||
// $msg = 'Unable to refund the transaction';
|
||||
$msg = ctrans('texts.error');
|
||||
|
||||
|
@ -32,7 +32,6 @@ class BaseExport
|
||||
}
|
||||
|
||||
switch ($date_range) {
|
||||
|
||||
case 'all':
|
||||
return $query;
|
||||
case 'last7':
|
||||
@ -53,7 +52,6 @@ class BaseExport
|
||||
return $query->whereBetween($this->date_key, [$custom_start_date, $custom_end_date])->orderBy($this->date_key, 'ASC');
|
||||
default:
|
||||
return $query->whereBetween($this->date_key, [now()->startOfYear(), now()])->orderBy($this->date_key, 'ASC');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ use App\Models\Company;
|
||||
use App\Transformers\ClientContactTransformer;
|
||||
use App\Transformers\ClientTransformer;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use League\Csv\Writer;
|
||||
|
||||
@ -181,11 +180,13 @@ class ClientExport extends BaseExport
|
||||
|
||||
private function calculateStatus($client)
|
||||
{
|
||||
if($client->is_deleted)
|
||||
if ($client->is_deleted) {
|
||||
return ctrans('texts.deleted');
|
||||
}
|
||||
|
||||
if($client->deleted_at)
|
||||
if ($client->deleted_at) {
|
||||
return ctrans('texts.arcvived');
|
||||
}
|
||||
|
||||
return ctrans('texts.active');
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Credit;
|
||||
use App\Transformers\CreditTransformer;
|
||||
|
@ -12,9 +12,7 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Document;
|
||||
use App\Transformers\DocumentTransformer;
|
||||
use App\Utils\Ninja;
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Expense;
|
||||
use App\Transformers\ExpenseTransformer;
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use App\Transformers\InvoiceTransformer;
|
||||
|
@ -100,7 +100,6 @@ class InvoiceItemExport extends BaseExport
|
||||
|
||||
public function run()
|
||||
{
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
App::forgetInstance('translator');
|
||||
App::setLocale($this->company->locale());
|
||||
@ -110,8 +109,9 @@ class InvoiceItemExport extends BaseExport
|
||||
//load the CSV document from a string
|
||||
$this->csv = Writer::createFromString();
|
||||
|
||||
if(count($this->input['report_keys']) == 0)
|
||||
if (count($this->input['report_keys']) == 0) {
|
||||
$this->input['report_keys'] = array_values($this->entity_keys);
|
||||
}
|
||||
|
||||
//insert the header
|
||||
$this->csv->insertOne($this->buildHeader());
|
||||
@ -119,19 +119,16 @@ class InvoiceItemExport extends BaseExport
|
||||
$query = Invoice::query()
|
||||
->withTrashed()
|
||||
->with('client')->where('company_id', $this->company->id)
|
||||
->where('is_deleted',0);
|
||||
->where('is_deleted', 0);
|
||||
|
||||
$query = $this->addDateRange($query);
|
||||
|
||||
$query->cursor()
|
||||
->each(function ($invoice){
|
||||
|
||||
->each(function ($invoice) {
|
||||
$this->iterateItems($invoice);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return $this->csv->toString();
|
||||
|
||||
return $this->csv->toString();
|
||||
}
|
||||
|
||||
private function iterateItems(Invoice $invoice)
|
||||
@ -140,81 +137,71 @@ class InvoiceItemExport extends BaseExport
|
||||
|
||||
$transformed_items = [];
|
||||
|
||||
foreach($invoice->line_items as $item)
|
||||
{
|
||||
foreach ($invoice->line_items as $item) {
|
||||
$item_array = [];
|
||||
|
||||
foreach(array_values($this->input['report_keys']) as $key){
|
||||
|
||||
if(str_contains($key, "item.")){
|
||||
|
||||
foreach (array_values($this->input['report_keys']) as $key) {
|
||||
if (str_contains($key, "item.")) {
|
||||
$key = str_replace("item.", "", $key);
|
||||
|
||||
if(property_exists($item, $key))
|
||||
if (property_exists($item, $key)) {
|
||||
$item_array[$key] = $item->{$key};
|
||||
else
|
||||
} else {
|
||||
$item_array[$key] = '';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$entity = [];
|
||||
|
||||
foreach(array_values($this->input['report_keys']) as $key)
|
||||
{
|
||||
foreach (array_values($this->input['report_keys']) as $key) {
|
||||
$keyval = array_search($key, $this->entity_keys);
|
||||
|
||||
if(array_key_exists($key, $transformed_items))
|
||||
if (array_key_exists($key, $transformed_items)) {
|
||||
$entity[$keyval] = $transformed_items[$key];
|
||||
else
|
||||
} else {
|
||||
$entity[$keyval] = "";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$transformed_items = array_merge($transformed_invoice, $item_array);
|
||||
$entity = $this->decorateAdvancedFields($invoice, $transformed_items);
|
||||
|
||||
$this->csv->insertOne($entity);
|
||||
|
||||
$this->csv->insertOne($entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function buildRow(Invoice $invoice) :array
|
||||
{
|
||||
|
||||
$transformed_invoice = $this->invoice_transformer->transform($invoice);
|
||||
|
||||
$entity = [];
|
||||
|
||||
foreach(array_values($this->input['report_keys']) as $key){
|
||||
|
||||
foreach (array_values($this->input['report_keys']) as $key) {
|
||||
$keyval = array_search($key, $this->entity_keys);
|
||||
|
||||
if(array_key_exists($key, $transformed_invoice))
|
||||
if (array_key_exists($key, $transformed_invoice)) {
|
||||
$entity[$keyval] = $transformed_invoice[$key];
|
||||
else
|
||||
} else {
|
||||
$entity[$keyval] = "";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->decorateAdvancedFields($invoice, $entity);
|
||||
|
||||
}
|
||||
|
||||
private function decorateAdvancedFields(Invoice $invoice, array $entity) :array
|
||||
{
|
||||
if(in_array('currency_id', $this->input['report_keys']))
|
||||
if (in_array('currency_id', $this->input['report_keys'])) {
|
||||
$entity['currency'] = $invoice->client->currency() ? $invoice->client->currency()->code : $invoice->company->currency()->code;
|
||||
}
|
||||
|
||||
// if(in_array('client_id', $this->input['report_keys']))
|
||||
$entity['client'] = $invoice->client->present()->name();
|
||||
$entity['client'] = $invoice->client->present()->name();
|
||||
|
||||
// if(in_array('status_id', $this->input['report_keys']))
|
||||
$entity['status'] = $invoice->stringStatus($invoice->status_id);
|
||||
$entity['status'] = $invoice->stringStatus($invoice->status_id);
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,9 +12,7 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Document;
|
||||
use App\Models\Payment;
|
||||
use App\Transformers\PaymentTransformer;
|
||||
|
@ -12,9 +12,7 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Document;
|
||||
use App\Models\Product;
|
||||
use App\Transformers\ProductTransformer;
|
||||
|
@ -12,17 +12,13 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Document;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Product;
|
||||
use App\Transformers\ProductTransformer;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use League\Csv\Writer;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class ProductSalesExport extends BaseExport
|
||||
{
|
||||
@ -98,10 +94,9 @@ class ProductSalesExport extends BaseExport
|
||||
|
||||
$query->cursor()
|
||||
->each(function ($invoice) {
|
||||
|
||||
foreach($invoice->line_items as $item)
|
||||
$this->csv->insertOne($this->buildRow($invoice, $item));
|
||||
|
||||
foreach ($invoice->line_items as $item) {
|
||||
$this->csv->insertOne($this->buildRow($invoice, $item));
|
||||
}
|
||||
});
|
||||
|
||||
return $this->csv->toString();
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Quote;
|
||||
use App\Transformers\QuoteTransformer;
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Quote;
|
||||
use App\Transformers\QuoteTransformer;
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Transformers\RecurringInvoiceTransformer;
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\DateFormat;
|
||||
use App\Models\Task;
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\BankIntegration;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BankIntegrationFactory
|
||||
{
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\BankTransaction;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BankTransactionFactory
|
||||
{
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\BankTransactionRule;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BankTransactionRuleFactory
|
||||
{
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\ClientGatewayToken;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ClientGatewayTokenFactory
|
||||
{
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Factory;
|
||||
|
||||
use App\DataMapper\FeesAndLimits;
|
||||
use App\Models\CompanyGateway;
|
||||
|
||||
class CompanyGatewayFactory
|
||||
|
@ -13,7 +13,6 @@ namespace App\Factory;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PurchaseOrderFactory
|
||||
{
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PurchaseOrderInvitationFactory
|
||||
|
@ -13,7 +13,6 @@ namespace App\Factory;
|
||||
|
||||
use App\Models\Expense;
|
||||
use App\Models\RecurringExpense;
|
||||
use App\Utils\Helpers;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
@ -175,7 +174,10 @@ class RecurringExpenseToExpenseFactory
|
||||
$replacement = sprintf('%s to %s', $_left, $_right);
|
||||
|
||||
$value = preg_replace(
|
||||
sprintf('/%s/', preg_quote($match)), $replacement, $value, 1
|
||||
sprintf('/%s/', preg_quote($match)),
|
||||
$replacement,
|
||||
$value,
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -196,7 +198,10 @@ class RecurringExpenseToExpenseFactory
|
||||
|
||||
if (! Str::contains($match, ['-', '+', '/', '*'])) {
|
||||
$value = preg_replace(
|
||||
sprintf('/%s/', $matches->keys()->first()), $replacements['literal'][$matches->keys()->first()], $value, 1
|
||||
sprintf('/%s/', $matches->keys()->first()),
|
||||
$replacements['literal'][$matches->keys()->first()],
|
||||
$value,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
@ -236,7 +241,10 @@ class RecurringExpenseToExpenseFactory
|
||||
}
|
||||
|
||||
$value = preg_replace(
|
||||
$target, $output, $value, 1
|
||||
$target,
|
||||
$output,
|
||||
$value,
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\User;
|
||||
|
||||
class UserFactory
|
||||
|
@ -26,10 +26,11 @@ class BankIntegrationFilters extends QueryFilters
|
||||
*/
|
||||
public function name(string $name = ''): Builder
|
||||
{
|
||||
if(strlen($name) >=1)
|
||||
return $this->builder->where('bank_account_name', 'like', '%'.$name.'%');
|
||||
if (strlen($name) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
return $this->builder->where('bank_account_name', 'like', '%'.$name.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,7 +49,6 @@ class BankIntegrationFilters extends QueryFilters
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('bank_account_name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,7 +67,6 @@ class BankIntegrationFilters extends QueryFilters
|
||||
$filters = explode(',', $filter);
|
||||
|
||||
return $this->builder->where(function ($query) use ($filters) {
|
||||
|
||||
if (in_array(parent::STATUS_ACTIVE, $filters)) {
|
||||
$query->orWhereNull('deleted_at');
|
||||
}
|
||||
@ -90,9 +89,13 @@ class BankIntegrationFilters extends QueryFilters
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort): Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
@ -27,10 +27,11 @@ class BankTransactionFilters extends QueryFilters
|
||||
*/
|
||||
public function name(string $name = ''): Builder
|
||||
{
|
||||
if(strlen($name) >=1)
|
||||
return $this->builder->where('bank_account_name', 'like', '%'.$name.'%');
|
||||
|
||||
return $this->builder;
|
||||
if (strlen($name) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where('bank_account_name', 'like', '%'.$name.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +41,7 @@ class BankTransactionFilters extends QueryFilters
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
@ -49,7 +50,6 @@ class BankTransactionFilters extends QueryFilters
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('bank_transactions.description', 'like', '%'.$filter.'%');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ class BankTransactionFilters extends QueryFilters
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function client_status(string $value = '') :Builder
|
||||
public function client_status(string $value = ''): Builder
|
||||
{
|
||||
if (strlen($value) == 0) {
|
||||
return $this->builder;
|
||||
@ -78,8 +78,7 @@ class BankTransactionFilters extends QueryFilters
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$this->builder->where(function ($query) use ($status_parameters){
|
||||
|
||||
$this->builder->where(function ($query) use ($status_parameters) {
|
||||
$status_array = [];
|
||||
|
||||
$debit_or_withdrawal_array = [];
|
||||
@ -104,14 +103,13 @@ class BankTransactionFilters extends QueryFilters
|
||||
$debit_or_withdrawal_array[] = 'DEBIT';
|
||||
}
|
||||
|
||||
if(count($status_array) >=1) {
|
||||
if (count($status_array) >=1) {
|
||||
$query->whereIn('status_id', $status_array);
|
||||
}
|
||||
|
||||
if(count($debit_or_withdrawal_array) >=1) {
|
||||
if (count($debit_or_withdrawal_array) >=1) {
|
||||
$query->orWhereIn('base_type', $debit_or_withdrawal_array);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return $this->builder;
|
||||
@ -123,24 +121,29 @@ class BankTransactionFilters extends QueryFilters
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort) : Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if(!is_array($sort_col))
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
if($sort_col[0] == 'deposit')
|
||||
if ($sort_col[0] == 'deposit') {
|
||||
return $this->builder->where('base_type', 'CREDIT')->orderBy('amount', $sort_col[1]);
|
||||
}
|
||||
|
||||
if($sort_col[0] == 'withdrawal')
|
||||
if ($sort_col[0] == 'withdrawal') {
|
||||
return $this->builder->where('base_type', 'DEBIT')->orderBy('amount', $sort_col[1]);
|
||||
}
|
||||
|
||||
if($sort_col[0] == 'status')
|
||||
if ($sort_col[0] == 'status') {
|
||||
$sort_col[0] = 'status_id';
|
||||
}
|
||||
|
||||
if(in_array($sort_col[0],['invoices','expense']))
|
||||
if (in_array($sort_col[0], ['invoices','expense'])) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
@ -11,11 +11,7 @@
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use App\Models\BankTransactionRule;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
/**
|
||||
* BankTransactionRuleilters.
|
||||
@ -30,10 +26,11 @@ class BankTransactionRuleFilters extends QueryFilters
|
||||
*/
|
||||
public function name(string $name = ''): Builder
|
||||
{
|
||||
if(strlen($name) >=1)
|
||||
return $this->builder->where('name', 'like', '%'.$name.'%');
|
||||
|
||||
return $this->builder;
|
||||
if (strlen($name) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where('name', 'like', '%'.$name.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +40,7 @@ class BankTransactionRuleFilters extends QueryFilters
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
@ -52,7 +49,6 @@ class BankTransactionRuleFilters extends QueryFilters
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('bank_transaction_rules.name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,26 +57,17 @@ class BankTransactionRuleFilters extends QueryFilters
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort) : Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base query.
|
||||
*
|
||||
* @param int company_id
|
||||
* @param User $user
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the query by the users company ID.
|
||||
*
|
||||
|
@ -11,11 +11,7 @@
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
/**
|
||||
* ClientFilters.
|
||||
@ -30,10 +26,11 @@ class ClientFilters extends QueryFilters
|
||||
*/
|
||||
public function name(string $name = ''): Builder
|
||||
{
|
||||
if(strlen($name) >=1)
|
||||
return $this->builder->where('name', 'like', '%'.$name.'%');
|
||||
if (strlen($name) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
return $this->builder->where('name', 'like', '%'.$name.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,8 +39,12 @@ class ClientFilters extends QueryFilters
|
||||
* @param string $balance
|
||||
* @return Builder
|
||||
*/
|
||||
public function balance(string $balance): Builder
|
||||
public function balance(string $balance = ''): Builder
|
||||
{
|
||||
if (strlen($balance) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$parts = $this->split($balance);
|
||||
|
||||
return $this->builder->where('balance', $parts->operator, $parts->value);
|
||||
@ -55,27 +56,29 @@ class ClientFilters extends QueryFilters
|
||||
* @param string balance
|
||||
* @return Builder
|
||||
*/
|
||||
public function between_balance(string $balance): Builder
|
||||
public function between_balance(string $balance = ''): Builder
|
||||
{
|
||||
$parts = explode(':', $balance);
|
||||
|
||||
if (! is_array($parts)) {
|
||||
if (!is_array($parts) || count($parts) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->whereBetween('balance', [$parts[0], $parts[1]]);
|
||||
}
|
||||
|
||||
public function email(string $email = ''):Builder
|
||||
public function email(string $email = ''): Builder
|
||||
{
|
||||
return
|
||||
if (strlen($email) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$this->builder->whereHas('contacts', function ($query) use ($email) {
|
||||
return $this->builder->whereHas('contacts', function ($query) use ($email) {
|
||||
$query->where('email', $email);
|
||||
});
|
||||
}
|
||||
|
||||
public function client_id(string $client_id = '') :Builder
|
||||
public function client_id(string $client_id = ''): Builder
|
||||
{
|
||||
if (strlen($client_id) == 0) {
|
||||
return $this->builder;
|
||||
@ -84,13 +87,21 @@ class ClientFilters extends QueryFilters
|
||||
return $this->builder->where('id', $this->decodePrimaryKey($client_id));
|
||||
}
|
||||
|
||||
public function id_number(string $id_number = ''):Builder
|
||||
public function id_number(string $id_number = ''): Builder
|
||||
{
|
||||
if (strlen($id_number) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where('id_number', $id_number);
|
||||
}
|
||||
|
||||
public function number(string $number = ''):Builder
|
||||
public function number(string $number = ''): Builder
|
||||
{
|
||||
if (strlen($number) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where('number', $number);
|
||||
}
|
||||
|
||||
@ -101,7 +112,7 @@ class ClientFilters extends QueryFilters
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
@ -128,12 +139,17 @@ class ClientFilters extends QueryFilters
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort) : Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if($sort_col[0] == 'display_name')
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
if ($sort_col[0] == 'display_name') {
|
||||
$sort_col[0] = 'name';
|
||||
}
|
||||
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
@ -150,11 +166,10 @@ class ClientFilters extends QueryFilters
|
||||
|
||||
public function filter_details(string $filter = '')
|
||||
{
|
||||
|
||||
if($filter == 'true')
|
||||
if ($filter == 'true') {
|
||||
return $this->builder->select('id', 'name', 'number', 'id_number');
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
@ -26,7 +25,7 @@ class CompanyGatewayFilters extends QueryFilters
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
@ -43,10 +42,14 @@ class CompanyGatewayFilters extends QueryFilters
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort) : Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ class CreditFilters extends QueryFilters
|
||||
* @param string credit_status The credit status as seen by the client
|
||||
* @return Builder
|
||||
*/
|
||||
public function credit_status(string $value = '') :Builder
|
||||
public function credit_status(string $value = ''): Builder
|
||||
{
|
||||
if (strlen($value) == 0) {
|
||||
return $this->builder;
|
||||
@ -44,17 +44,21 @@ class CreditFilters extends QueryFilters
|
||||
|
||||
$credit_filters = [];
|
||||
|
||||
if (in_array('draft', $status_parameters))
|
||||
if (in_array('draft', $status_parameters)) {
|
||||
$credit_filters[] = Credit::STATUS_DRAFT;
|
||||
}
|
||||
|
||||
if (in_array('partial', $status_parameters))
|
||||
if (in_array('partial', $status_parameters)) {
|
||||
$credit_filters[] = Credit::STATUS_PARTIAL;
|
||||
}
|
||||
|
||||
if (in_array('applied', $status_parameters))
|
||||
if (in_array('applied', $status_parameters)) {
|
||||
$credit_filters[] = Credit::STATUS_APPLIED;
|
||||
}
|
||||
|
||||
if(count($credit_filters) >=1)
|
||||
if (count($credit_filters) >=1) {
|
||||
$this->builder->whereIn('status_id', $credit_filters);
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
@ -66,7 +70,7 @@ class CreditFilters extends QueryFilters
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
@ -85,16 +89,29 @@ class CreditFilters extends QueryFilters
|
||||
});
|
||||
}
|
||||
|
||||
public function number(string $number = ''): Builder
|
||||
{
|
||||
if (strlen($number) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where('number', $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the list based on $sort.
|
||||
*
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort) : Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
||||
@ -123,7 +140,7 @@ class CreditFilters extends QueryFilters
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
private function contactViewFilter() : Builder
|
||||
private function contactViewFilter(): Builder
|
||||
{
|
||||
return $this->builder
|
||||
->whereCompanyId(auth()->guard('contact')->user()->company->id)
|
||||
|
@ -23,7 +23,7 @@ class DesignFilters extends QueryFilters
|
||||
*
|
||||
* @param string query filter
|
||||
* @return Builder
|
||||
*
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = ''): Builder
|
||||
@ -32,7 +32,7 @@ class DesignFilters extends QueryFilters
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('designs.name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
@ -41,17 +41,18 @@ class DesignFilters extends QueryFilters
|
||||
* Sorts the list based on $sort.
|
||||
*
|
||||
* @param string sort formatted as column|asc
|
||||
*
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort): Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if(is_array($sort_col))
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +62,6 @@ class DesignFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter(): Builder
|
||||
{
|
||||
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||
return $this->builder->where('company_id', auth()->user()->company()->id)->orWhere('company_id', null)->orderBy('id','asc');
|
||||
return $this->builder->where('company_id', auth()->user()->company()->id)->orWhere('company_id', null)->orderBy('id', 'asc');
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,10 @@ class DocumentFilters extends QueryFilters
|
||||
* Overriding method as client_id does
|
||||
* not exist on this model, just pass
|
||||
* back the builder
|
||||
*
|
||||
* @param string $client_id The client hashed id.
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function client_id(string $client_id = ''): Builder
|
||||
{
|
||||
@ -54,21 +55,23 @@ class DocumentFilters extends QueryFilters
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort = '') : Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if(is_array($sort_col))
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
||||
|
||||
public function company_documents($value = 'false')
|
||||
{
|
||||
if($value == 'true')
|
||||
if ($value == 'true') {
|
||||
return $this->builder->where('documentable_type', Company::class);
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
|
@ -25,14 +25,13 @@ class ExpenseCategoryFilters extends QueryFilters
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where('name', 'like', '%'.$filter.'%');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,12 +40,17 @@ class ExpenseCategoryFilters extends QueryFilters
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort) : Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['name']))
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['name'])) {
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
||||
|
||||
return $this->builder;
|
||||
|
@ -25,7 +25,7 @@ class ExpenseFilters extends QueryFilters
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
@ -53,7 +53,7 @@ class ExpenseFilters extends QueryFilters
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function client_status(string $value = '') :Builder
|
||||
public function client_status(string $value = ''): Builder
|
||||
{
|
||||
if (strlen($value) == 0) {
|
||||
return $this->builder;
|
||||
@ -65,52 +65,40 @@ class ExpenseFilters extends QueryFilters
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$this->builder->where(function ($query) use($status_parameters){
|
||||
|
||||
$this->builder->where(function ($query) use ($status_parameters) {
|
||||
if (in_array('logged', $status_parameters)) {
|
||||
|
||||
$query->orWhere(function ($query){
|
||||
$query->orWhere(function ($query) {
|
||||
$query->where('amount', '>', 0)
|
||||
->whereNull('invoice_id')
|
||||
->whereNull('payment_date')
|
||||
->where('should_be_invoiced',false);
|
||||
->where('should_be_invoiced', false);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (in_array('pending', $status_parameters)) {
|
||||
|
||||
$query->orWhere(function ($query){
|
||||
$query->where('should_be_invoiced',true)
|
||||
$query->orWhere(function ($query) {
|
||||
$query->where('should_be_invoiced', true)
|
||||
->whereNull('invoice_id');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (in_array('invoiced', $status_parameters)) {
|
||||
|
||||
$query->orWhere(function ($query){
|
||||
$query->orWhere(function ($query) {
|
||||
$query->whereNotNull('invoice_id');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (in_array('paid', $status_parameters)) {
|
||||
|
||||
$query->orWhere(function ($query){
|
||||
$query->orWhere(function ($query) {
|
||||
$query->whereNotNull('payment_date');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (in_array('unpaid', $status_parameters)) {
|
||||
|
||||
$query->orWhere(function ($query){
|
||||
$query->orWhere(function ($query) {
|
||||
$query->whereNull('payment_date');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// nlog($this->builder->toSql());
|
||||
@ -123,25 +111,36 @@ class ExpenseFilters extends QueryFilters
|
||||
*/
|
||||
public function match_transactions($value = '')
|
||||
{
|
||||
|
||||
if($value == 'true')
|
||||
{
|
||||
return $this->builder->where('is_deleted',0)->whereNull('transaction_id');
|
||||
if ($value == 'true') {
|
||||
return $this->builder->where('is_deleted', 0)->whereNull('transaction_id');
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
public function number(string $number = ''): Builder
|
||||
{
|
||||
if (strlen($number) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where('number', $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the list based on $sort.
|
||||
*
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort) : Builder
|
||||
public function sort(string $sort = ''): Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['public_notes', 'date', 'id_number', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4'])) {
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user