mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge branch 'v5-develop' into v5-develop
This commit is contained in:
commit
b346445c35
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
|
7
.github/workflows/phpunit.yml
vendored
7
.github/workflows/phpunit.yml
vendored
@ -2,6 +2,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- v5-develop
|
||||
- v5-stable
|
||||
pull_request:
|
||||
branches:
|
||||
- v5-develop
|
||||
@ -101,12 +102,6 @@ jobs:
|
||||
restore-keys: |
|
||||
${{ runner.os }}-${{ matrix.php }}-composer-
|
||||
|
||||
# - name: Cache dependencies actions/cache@v3
|
||||
# uses: actions/cache@v3
|
||||
# with:
|
||||
# path: ~/.composer/cache/files
|
||||
# key: dependencies-${{ matrix.dependency-version }}-laravel-${{ matrix.laravel }}-php-${{ matrix.php-versions }}-composer-${{ hashFiles('composer.json') }}
|
||||
|
||||
- name: Install composer dependencies
|
||||
run: |
|
||||
composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
|
||||
|
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: |
|
||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -5,7 +5,9 @@
|
||||
/storage/*.key
|
||||
/storage/debugbar
|
||||
/storage/*
|
||||
/tests/bootstrap/
|
||||
/vendor
|
||||
/app/Console/Commands/vendor/
|
||||
/.idea
|
||||
/.vscode
|
||||
/.vagrant
|
||||
@ -17,6 +19,7 @@ yarn-error.log
|
||||
local_version.txt
|
||||
.env
|
||||
.phpunit.result.cache
|
||||
_ide_helper.php
|
||||
|
||||
/resources/assets/bower
|
||||
/public/logo
|
||||
@ -32,3 +35,5 @@ nbproject
|
||||
public/test.pdf
|
||||
public/storage/test.pdf
|
||||
/Modules
|
||||
_ide_helper_models.php
|
||||
_ide_helper.php
|
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), [Discord](https://discord.com/channels/1071654583870435439/1071654584390537279) [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.68
|
||||
5.5.86
|
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,12 +13,12 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Backup;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Design;
|
||||
use App\Models\Document;
|
||||
use App\Models\GroupSetting;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use stdClass;
|
||||
|
||||
class BackupUpdate extends Command
|
||||
{
|
||||
@ -60,7 +60,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 +77,128 @@ class BackupUpdate extends Command
|
||||
|
||||
//logos
|
||||
Company::cursor()
|
||||
->each(function ($company){
|
||||
->each(function ($company) {
|
||||
$company_logo_path = $company->settings->company_logo;
|
||||
|
||||
$company_logo = $company->present()->logo();
|
||||
if ($company_logo_path == 'https://invoicing.co/images/new_logo.png' || $company_logo_path == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if($company_logo == 'https://invoicing.co/images/new_logo.png')
|
||||
return;
|
||||
$logo = @file_get_contents($company_logo_path);
|
||||
$extension = @pathinfo($company->settings->company_logo, PATHINFO_EXTENSION);
|
||||
|
||||
if ($logo && $extension) {
|
||||
$path = "{$company->company_key}/{$company->company_key}.{$extension}";
|
||||
|
||||
$logo = @file_get_contents($company_logo);
|
||||
Storage::disk($this->option('disk'))->put($path, $logo);
|
||||
|
||||
if($logo){
|
||||
$url = Storage::disk($this->option('disk'))->url($path);
|
||||
|
||||
$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);
|
||||
}
|
||||
nlog("Company - Moving {$company_logo_path} logo to {$this->option('disk')} final URL = {$url}}");
|
||||
|
||||
$settings = $company->settings;
|
||||
$settings->company_logo = $url;
|
||||
$company->settings = $settings;
|
||||
;
|
||||
$company->save();
|
||||
}
|
||||
});
|
||||
|
||||
Client::withTrashed()
|
||||
->whereNotNull('settings->company_logo')
|
||||
->cursor()
|
||||
->each(function ($client) {
|
||||
$company_logo_path = $client->settings->company_logo;
|
||||
|
||||
$logo = @file_get_contents($company_logo_path);
|
||||
$extension = @pathinfo($company_logo_path, PATHINFO_EXTENSION);
|
||||
|
||||
if ($logo && $extension) {
|
||||
$path = "{$client->company->company_key}/{$client->client_hash}.{$extension}";
|
||||
|
||||
Storage::disk($this->option('disk'))->put($path, $logo);
|
||||
|
||||
$url = Storage::disk($this->option('disk'))->url($path);
|
||||
|
||||
nlog("Client - Moving {$company_logo_path} logo to {$this->option('disk')} final URL = {$url}}");
|
||||
|
||||
$settings = $client->settings;
|
||||
$settings->company_logo = $url;
|
||||
$client->settings = $settings;
|
||||
;
|
||||
$client->saveQuietly();
|
||||
}
|
||||
});
|
||||
|
||||
GroupSetting::withTrashed()
|
||||
->whereNotNull('settings->company_logo')
|
||||
->orWhere('settings->company_logo', '!=', '')
|
||||
->cursor()
|
||||
->each(function ($group) {
|
||||
$company_logo_path = $group->settings->company_logo;
|
||||
|
||||
if (!$company_logo_path) {
|
||||
return;
|
||||
}
|
||||
|
||||
$logo = @file_get_contents($company_logo_path);
|
||||
$extension = @pathinfo($company_logo_path, PATHINFO_EXTENSION);
|
||||
|
||||
if ($logo && $extension) {
|
||||
$path = "{$group->company->company_key}/{$group->hashed_id}.{$extension}";
|
||||
|
||||
Storage::disk($this->option('disk'))->put($path, $logo);
|
||||
|
||||
$url = Storage::disk($this->option('disk'))->url($path);
|
||||
|
||||
nlog("Group - Moving {$company_logo_path} logo to {$this->option('disk')} final URL = {$url}}");
|
||||
|
||||
$settings = $group->settings;
|
||||
$settings->company_logo = $url;
|
||||
$group->settings = $settings;
|
||||
;
|
||||
$group->saveQuietly();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
//documents
|
||||
Document::cursor()
|
||||
->each(function ($document){
|
||||
->each(function (Document $document) {
|
||||
$doc_bin = false;
|
||||
|
||||
$doc_bin = $document->getFile();
|
||||
try {
|
||||
$doc_bin = $document->getFile();
|
||||
} catch(\Exception $e) {
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
|
||||
if($doc_bin)
|
||||
if ($doc_bin) {
|
||||
Storage::disk($this->option('disk'))->put($document->url, $doc_bin);
|
||||
|
||||
$document->disk = $this->option('disk');
|
||||
$document->saveQuietly();
|
||||
|
||||
nlog("Documents - Moving {$document->url} to {$this->option('disk')}");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//backups
|
||||
Backup::cursor()
|
||||
->each(function ($backup){
|
||||
//backups
|
||||
Backup::whereNotNull('filename')
|
||||
->where('filename', '!=', '')
|
||||
->cursor()
|
||||
->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);
|
||||
|
||||
nlog("Backups - Moving {$backup->filename} to {$this->option('disk')}");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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,44 +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}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -302,7 +291,6 @@ class CheckData extends Command
|
||||
$new_contact->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function checkVendorContacts()
|
||||
@ -350,7 +338,6 @@ class CheckData extends Command
|
||||
}
|
||||
|
||||
if ($this->option('fix') == 'true') {
|
||||
|
||||
$vendors = Vendor::withTrashed()->doesntHave('contacts')->get();
|
||||
|
||||
foreach ($vendors as $vendor) {
|
||||
@ -363,7 +350,6 @@ class CheckData extends Command
|
||||
$new_contact->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -418,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;
|
||||
@ -446,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)
|
||||
@ -503,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;
|
||||
@ -512,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,
|
||||
@ -540,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
|
||||
@ -559,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;
|
||||
}
|
||||
@ -570,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');
|
||||
@ -580,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()
|
||||
@ -608,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))')
|
||||
@ -621,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')
|
||||
@ -656,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++;
|
||||
@ -665,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();
|
||||
@ -681,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();
|
||||
@ -702,7 +660,6 @@ class CheckData extends Command
|
||||
$this->isValid = false;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$this->logMessage("{$this->wrong_balances} clients with incorrect invoice balances");
|
||||
@ -710,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,
|
||||
@ -724,7 +681,7 @@ class CheckData extends Command
|
||||
GROUP BY clients.id
|
||||
HAVING invoice_balance != clients.balance
|
||||
ORDER BY clients.id;
|
||||
") );
|
||||
"));
|
||||
|
||||
return $results;
|
||||
}
|
||||
@ -736,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']) {
|
||||
@ -747,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");
|
||||
@ -767,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,
|
||||
@ -832,7 +772,7 @@ class CheckData extends Command
|
||||
GROUP BY clients.id
|
||||
HAVING(invoices_balance != clients.balance)
|
||||
ORDER BY clients.id;
|
||||
") );
|
||||
"));
|
||||
|
||||
return $results;
|
||||
}
|
||||
@ -844,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');
|
||||
@ -860,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()
|
||||
@ -899,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();
|
||||
@ -910,7 +843,6 @@ class CheckData extends Command
|
||||
$ledger->notes = 'Ledger Adjustment';
|
||||
$ledger->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1002,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)
|
||||
@ -1047,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}");
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1085,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;
|
||||
@ -1101,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();
|
||||
@ -1114,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){
|
||||
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();
|
||||
}
|
||||
|
||||
@ -117,12 +114,33 @@ class CreateSingleAccount extends Command
|
||||
'portal_domain' => 'http://ninja.test:8000',
|
||||
'track_inventory' => true
|
||||
]);
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$settings = $company->settings;
|
||||
$settings->invoice_terms = 'Default company invoice terms';
|
||||
$settings->quote_terms = 'Default company quote terms';
|
||||
$settings->invoice_footer = 'Default invoice footer';
|
||||
|
||||
$settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png';
|
||||
$settings->name = $faker->name();
|
||||
$settings->email = $faker->safeEmail();
|
||||
$settings->phone = $faker->phoneNumber();
|
||||
$settings->website = $faker->url();
|
||||
|
||||
$settings->address1 = $faker->streetName();
|
||||
$settings->address2 = $faker->streetAddress();
|
||||
$settings->city = $faker->city();
|
||||
$settings->state = $faker->state();
|
||||
$settings->postal_code = $faker->postcode();
|
||||
|
||||
$settings->country_id = '840';
|
||||
$settings->vat_number = 'vat number';
|
||||
$settings->id_number = 'id number';
|
||||
$settings->use_credits_payment = 'always';
|
||||
$settings->timezone_id = '1';
|
||||
$settings->entity_send_time = 0;
|
||||
$settings->name = $faker->name();
|
||||
|
||||
$company->settings = $settings;
|
||||
$company->client_registration_fields = ClientRegistrationFields::generate();
|
||||
$company->save();
|
||||
@ -201,7 +219,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 +377,6 @@ class CreateSingleAccount extends Command
|
||||
|
||||
private function createClient($company, $user)
|
||||
{
|
||||
|
||||
// dispatch(function () use ($company, $user) {
|
||||
|
||||
// });
|
||||
@ -630,30 +647,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 +688,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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,82 +20,102 @@ class ClientRegistrationFields
|
||||
[
|
||||
'key' => 'first_name',
|
||||
'required' => true,
|
||||
'visible' => true,
|
||||
],
|
||||
[
|
||||
'key' => 'last_name',
|
||||
'required' => true,
|
||||
'visible' => true,
|
||||
],
|
||||
[
|
||||
'key' => 'email',
|
||||
'required' => true,
|
||||
'visible' => true,
|
||||
],
|
||||
[
|
||||
'key' => 'phone',
|
||||
'required' => false,
|
||||
'visible' => true,
|
||||
],
|
||||
[
|
||||
'key' => 'password',
|
||||
'required' => true,
|
||||
'visible' => true,
|
||||
],
|
||||
[
|
||||
'key' => 'name',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'website',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'address1',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'address2',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'city',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'state',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'postal_code',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'country_id',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'custom_value1',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'custom_value2',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'custom_value3',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'custom_value4',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'public_notes',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'vat_number',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'currency_id',
|
||||
'required' => false,
|
||||
'visible' => false,
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -84,10 +84,14 @@ class ClientSettings extends BaseSettings
|
||||
*/
|
||||
public static function buildClientSettings($company_settings, $client_settings)
|
||||
{
|
||||
|
||||
if (! $client_settings) {
|
||||
return $company_settings;
|
||||
}
|
||||
|
||||
if(is_array($client_settings))
|
||||
$client_settings = (object)$client_settings;
|
||||
|
||||
foreach ($company_settings as $key => $value) {
|
||||
/* pseudo code
|
||||
if the property exists and is a string BUT has no length, treat it as TRUE
|
||||
|
@ -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';
|
||||
|
||||
@ -463,7 +463,13 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
public $accept_client_input_quote_approval = false;
|
||||
|
||||
public $allow_billable_task_items = true;
|
||||
|
||||
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',
|
||||
@ -762,7 +768,6 @@ class CompanySettings extends BaseSettings
|
||||
*/
|
||||
public static function defaults(): stdClass
|
||||
{
|
||||
|
||||
$data = (object) get_class_vars(self::class);
|
||||
|
||||
unset($data->casts);
|
||||
@ -834,7 +839,6 @@ class CompanySettings extends BaseSettings
|
||||
'$client.address1',
|
||||
'$client.address2',
|
||||
'$client.city_state_postal',
|
||||
'$client.postal_city',
|
||||
'$client.country',
|
||||
'$client.phone',
|
||||
'$contact.email',
|
||||
@ -846,7 +850,6 @@ class CompanySettings extends BaseSettings
|
||||
'$vendor.address1',
|
||||
'$vendor.address2',
|
||||
'$vendor.city_state_postal',
|
||||
'$vendor.postal_city',
|
||||
'$vendor.country',
|
||||
'$vendor.phone',
|
||||
'$contact.email',
|
||||
@ -871,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,13 +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\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use League\Flysystem\UnableToCreateDirectory;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
@ -67,6 +63,7 @@ class Handler extends ExceptionHandler
|
||||
Symfony\Component\Process\Exception\RuntimeException::class,
|
||||
InvalidArgumentException::class,
|
||||
RuntimeException::class,
|
||||
Aws\Exception\CredentialsException::class,
|
||||
];
|
||||
|
||||
protected $hostedDontReport = [
|
||||
@ -127,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) {
|
||||
@ -191,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));
|
||||
}
|
||||
@ -244,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);
|
||||
}
|
||||
@ -258,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;
|
||||
|
||||
|
@ -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');
|
||||
|
||||
|
@ -11,10 +11,38 @@
|
||||
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Models\Client;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class BaseExport
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public array $input;
|
||||
|
||||
public string $date_key = '';
|
||||
|
||||
public array $entity_keys = [];
|
||||
|
||||
public string $start_date = '';
|
||||
|
||||
public string $end_date = '';
|
||||
|
||||
public string $client_description = 'All Clients';
|
||||
|
||||
protected function filterByClients($query)
|
||||
{
|
||||
if (isset($this->input['client_id']) && $this->input['client_id'] != 'all') {
|
||||
|
||||
$client = Client::withTrashed()->find($this->input['client_id']);
|
||||
$this->client_description = $client->present()->name;
|
||||
return $query->where('client_id', $this->input['client_id']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function addDateRange($query)
|
||||
{
|
||||
$date_range = $this->input['date_range'];
|
||||
@ -32,28 +60,46 @@ class BaseExport
|
||||
}
|
||||
|
||||
switch ($date_range) {
|
||||
|
||||
case 'all':
|
||||
$this->start_date = 'All available data';
|
||||
$this->end_date = 'All available data';
|
||||
return $query;
|
||||
case 'last7':
|
||||
$this->start_date = now()->subDays(7)->format('Y-m-d');
|
||||
$this->end_date = now()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [now()->subDays(7), now()])->orderBy($this->date_key, 'ASC');
|
||||
case 'last30':
|
||||
$this->start_date = now()->subDays(30)->format('Y-m-d');
|
||||
$this->end_date = now()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [now()->subDays(30), now()])->orderBy($this->date_key, 'ASC');
|
||||
case 'this_month':
|
||||
$this->start_date = now()->startOfMonth()->format('Y-m-d');
|
||||
$this->end_date = now()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [now()->startOfMonth(), now()])->orderBy($this->date_key, 'ASC');
|
||||
case 'last_month':
|
||||
$this->start_date = now()->startOfMonth()->subMonth()->format('Y-m-d');
|
||||
$this->end_date = now()->startOfMonth()->subMonth()->endOfMonth()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [now()->startOfMonth()->subMonth(), now()->startOfMonth()->subMonth()->endOfMonth()])->orderBy($this->date_key, 'ASC');
|
||||
case 'this_quarter':
|
||||
$this->start_date = (new \Carbon\Carbon('-3 months'))->firstOfQuarter()->format('Y-m-d');
|
||||
$this->end_date = (new \Carbon\Carbon('-3 months'))->lastOfQuarter()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [(new \Carbon\Carbon('-3 months'))->firstOfQuarter(), (new \Carbon\Carbon('-3 months'))->lastOfQuarter()])->orderBy($this->date_key, 'ASC');
|
||||
case 'last_quarter':
|
||||
$this->start_date = (new \Carbon\Carbon('-6 months'))->firstOfQuarter()->format('Y-m-d');
|
||||
$this->end_date = (new \Carbon\Carbon('-6 months'))->lastOfQuarter()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [(new \Carbon\Carbon('-6 months'))->firstOfQuarter(), (new \Carbon\Carbon('-6 months'))->lastOfQuarter()])->orderBy($this->date_key, 'ASC');
|
||||
case 'this_year':
|
||||
$this->start_date = now()->startOfYear()->format('Y-m-d');
|
||||
$this->end_date = now()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [now()->startOfYear(), now()])->orderBy($this->date_key, 'ASC');
|
||||
case 'custom':
|
||||
$this->start_date = $custom_start_date->format('Y-m-d');
|
||||
$this->end_date = $custom_end_date->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [$custom_start_date, $custom_end_date])->orderBy($this->date_key, 'ASC');
|
||||
default:
|
||||
$this->start_date = now()->startOfYear()->format('Y-m-d');
|
||||
$this->end_date = now()->format('Y-m-d');
|
||||
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;
|
||||
|
||||
@ -25,19 +24,15 @@ class ClientExport extends BaseExport
|
||||
{
|
||||
private $company;
|
||||
|
||||
protected $input;
|
||||
|
||||
private $client_transformer;
|
||||
|
||||
private $contact_transformer;
|
||||
|
||||
private string $start_date;
|
||||
public Writer $csv;
|
||||
|
||||
private string $end_date;
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
protected string $date_key = 'created_at';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public array $entity_keys = [
|
||||
'address1' => 'client.address1',
|
||||
'address2' => 'client.address2',
|
||||
'balance' => 'client.balance',
|
||||
@ -181,11 +176,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');
|
||||
}
|
||||
|
@ -25,15 +25,15 @@ class ContactExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private ClientTransformer $client_transformer;
|
||||
|
||||
private ClientContactTransformer $contact_transformer;
|
||||
|
||||
protected string $date_key = 'created_at';
|
||||
public Writer $csv;
|
||||
|
||||
protected array $entity_keys = [
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
public array $entity_keys = [
|
||||
'address1' => 'client.address1',
|
||||
'address2' => 'client.address2',
|
||||
'balance' => 'client.balance',
|
||||
|
@ -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;
|
||||
@ -24,13 +23,13 @@ class CreditExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private CreditTransformer $credit_transformer;
|
||||
|
||||
protected string $date_key = 'created_at';
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'amount' => 'amount',
|
||||
'balance' => 'balance',
|
||||
'client' => 'client_id',
|
||||
|
@ -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;
|
||||
@ -25,13 +23,13 @@ class DocumentExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $entity_transformer;
|
||||
|
||||
protected $date_key = 'created_at';
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'record_type' => 'record_type',
|
||||
// 'record_name' => 'record_name',
|
||||
'name' => 'name',
|
||||
|
@ -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;
|
||||
@ -24,13 +23,13 @@ class ExpenseExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $expense_transformer;
|
||||
|
||||
protected $date_key = 'date';
|
||||
public string $date_key = 'date';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'amount' => 'amount',
|
||||
'category' => 'category_id',
|
||||
'client' => 'client_id',
|
||||
|
@ -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;
|
||||
@ -24,13 +23,13 @@ class InvoiceExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $invoice_transformer;
|
||||
|
||||
protected string $date_key = 'date';
|
||||
public string $date_key = 'date';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'amount' => 'amount',
|
||||
'balance' => 'balance',
|
||||
'client' => 'client_id',
|
||||
|
@ -24,13 +24,13 @@ class InvoiceItemExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $invoice_transformer;
|
||||
|
||||
protected string $date_key = 'date';
|
||||
public string $date_key = 'date';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'amount' => 'amount',
|
||||
'balance' => 'balance',
|
||||
'client' => 'client_id',
|
||||
@ -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,10 +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;
|
||||
use App\Utils\Ninja;
|
||||
@ -26,13 +23,13 @@ class PaymentExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $entity_transformer;
|
||||
|
||||
protected $date_key = 'date';
|
||||
public string $date_key = 'date';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'amount' => 'amount',
|
||||
'applied' => 'applied',
|
||||
'client' => 'client_id',
|
||||
|
@ -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;
|
||||
@ -26,13 +24,13 @@ class ProductExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $entity_transformer;
|
||||
|
||||
protected $date_key = 'created_at';
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'project' => 'project_id',
|
||||
'vendor' => 'vendor_id',
|
||||
'custom_value1' => 'custom_value1',
|
||||
|
@ -11,51 +11,59 @@
|
||||
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Utils\Ninja;
|
||||
use League\Csv\Writer;
|
||||
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\Facades\App;
|
||||
use League\Csv\Writer;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ProductSalesExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
protected $date_key = 'created_at';
|
||||
protected Collection $products;
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
private \Illuminate\Support\Collection $sales;
|
||||
|
||||
//translations => keys
|
||||
public array $entity_keys = [
|
||||
'date' => 'date',
|
||||
'product_key' => 'product_key',
|
||||
'notes' => 'notes',
|
||||
'quantity' => 'quantity',
|
||||
'cost' => 'price',
|
||||
'price' => 'cost',
|
||||
'markup' => 'markup',
|
||||
'discount' => 'discount',
|
||||
'net_total' => 'net_total',
|
||||
'profit' => 'profit',
|
||||
'line_total' => 'line_total',
|
||||
'gross_line_total' => 'gross_line_total',
|
||||
'status' => 'status',
|
||||
'tax_name1' => 'tax_name1',
|
||||
'tax_name2' => 'tax_name2',
|
||||
'tax_name3' => 'tax_name3',
|
||||
'tax_rate1' => 'tax_rate1',
|
||||
'tax_rate2' => 'tax_rate2',
|
||||
'tax_rate3' => 'tax_rate3',
|
||||
'tax_amount1' => 'tax_amount1',
|
||||
'tax_amount2' => 'tax_amount2',
|
||||
'tax_amount3' => 'tax_amount3',
|
||||
'is_amount_discount' => 'is_amount_discount',
|
||||
'currency' => 'currency',
|
||||
'client' => 'client',
|
||||
'custom_value1' => 'custom_value1',
|
||||
'custom_value2' => 'custom_value2',
|
||||
'custom_value3' => 'custom_value3',
|
||||
'custom_value4' => 'custom_value4',
|
||||
'product_key' => 'product_key',
|
||||
'notes' => 'notes',
|
||||
'cost' => 'cost',
|
||||
'price' => 'price',
|
||||
'quantity' => 'quantity',
|
||||
'tax_rate1' => 'tax_rate1',
|
||||
'tax_rate2' => 'tax_rate2',
|
||||
'tax_rate3' => 'tax_rate3',
|
||||
'tax_name1' => 'tax_name1',
|
||||
'tax_name2' => 'tax_name2',
|
||||
'tax_name3' => 'tax_name3',
|
||||
'is_amount_discount' => 'is_amount_discount',
|
||||
'discount' => 'discount',
|
||||
'line_total' => 'line_total',
|
||||
'gross_line_total' => 'gross_line_total',
|
||||
'status' => 'status',
|
||||
'date' => 'date',
|
||||
'currency' => 'currency',
|
||||
'client' => 'client',
|
||||
];
|
||||
|
||||
private array $decorate_keys = [
|
||||
@ -68,6 +76,7 @@ class ProductSalesExport extends BaseExport
|
||||
{
|
||||
$this->company = $company;
|
||||
$this->input = $input;
|
||||
$this->sales = collect();
|
||||
}
|
||||
|
||||
public function run()
|
||||
@ -78,6 +87,8 @@ class ProductSalesExport extends BaseExport
|
||||
$t = app('translator');
|
||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||
|
||||
$this->products = Product::where('company_id', $this->company->id)->withTrashed()->get();
|
||||
|
||||
//load the CSV document from a string
|
||||
$this->csv = Writer::createFromString();
|
||||
|
||||
@ -96,14 +107,59 @@ class ProductSalesExport extends BaseExport
|
||||
|
||||
$query = $this->addDateRange($query);
|
||||
|
||||
$query = $this->filterByClients($query);
|
||||
|
||||
$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));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$grouped = $this->sales->groupBy('product_key')->map(function ($key, $value){
|
||||
|
||||
$data = [
|
||||
'product' => $value,
|
||||
'quantity' => $key->sum('quantity'),
|
||||
'markup' => $key->sum('markup'),
|
||||
'profit' => $key->sum('profit'),
|
||||
'net_total' => $key->sum('net_total'),
|
||||
'discount' => $key->sum('discount'),
|
||||
'line_total' => $key->sum('line_total'),
|
||||
'tax_name1' => $key->whereNotNull('tax_name1')->where('tax_name1', '!=', '')->first() ? $key->whereNotNull('tax_name1')->where('tax_name1', '!=', '')->first()['tax_name1'] : '',
|
||||
'tax_name2' => $key->whereNotNull('tax_name2')->where('tax_name2', '!=', '')->first() ? $key->whereNotNull('tax_name2')->where('tax_name2', '!=', '')->first()['tax_name2'] : '',
|
||||
'tax_name3' => $key->whereNotNull('tax_name3')->where('tax_name3', '!=', '')->first() ? $key->whereNotNull('tax_name3')->where('tax_name3', '!=', '')->first()['tax_name3'] : '',
|
||||
'tax_amount1' => $key->sum('tax_amount1'),
|
||||
'tax_amount2' => $key->sum('tax_amount2'),
|
||||
'tax_amount3' => $key->sum('tax_amount3'),
|
||||
];
|
||||
|
||||
return $data;
|
||||
});
|
||||
|
||||
$this->csv->insertOne([]);
|
||||
$this->csv->insertOne([]);
|
||||
$this->csv->insertOne([]);
|
||||
$this->csv->insertOne([]);
|
||||
$this->csv->insertOne([ctrans('texts.clients'), ctrans('texts.type'), ctrans('texts.start_date'), ctrans('texts.end_date')]);
|
||||
$this->csv->insertOne([$this->client_description, ctrans('texts.product_sales'), $this->start_date, $this->end_date]);
|
||||
$this->csv->insertOne([]);
|
||||
|
||||
|
||||
if ($grouped->count() >=1) {
|
||||
$header = [];
|
||||
|
||||
foreach ($grouped->first() as $key => $value) {
|
||||
$header[] = ctrans("texts.{$key}");
|
||||
}
|
||||
|
||||
$this->csv->insertOne($header);
|
||||
|
||||
$grouped->each(function ($item) {
|
||||
$this->csv->insertOne(array_values($item));
|
||||
});
|
||||
}
|
||||
return $this->csv->toString();
|
||||
}
|
||||
|
||||
@ -122,17 +178,109 @@ class ProductSalesExport extends BaseExport
|
||||
$entity[$keyval] = '';
|
||||
}
|
||||
}
|
||||
$entity = $this->decorateAdvancedFields($invoice, $entity);
|
||||
|
||||
$this->sales->push($entity);
|
||||
|
||||
return $entity;
|
||||
|
||||
return $this->decorateAdvancedFields($invoice, $entity);
|
||||
}
|
||||
|
||||
private function decorateAdvancedFields(Invoice $invoice, $entity) :array
|
||||
{
|
||||
{
|
||||
$product = $this->getProduct($entity['product_key']);
|
||||
|
||||
$entity['cost'] = $product->cost ?? 0;
|
||||
$unit_cost = $entity['cost'] == 0 ? 1 : $entity['cost'];
|
||||
|
||||
$entity['client'] = $invoice->client->present()->name();
|
||||
$entity['currency'] = $invoice->client->currency()->code;
|
||||
$entity['status'] = $invoice->stringStatus($invoice->status_id);
|
||||
$entity['date'] = Carbon::parse($invoice->date)->format($this->company->date_format());
|
||||
|
||||
$entity['discount'] = $this->calculateDiscount($invoice, $entity);
|
||||
$entity['markup'] = round(((($entity['price'] - $entity['discount'] - $entity['cost']) / $unit_cost) * 100),2);
|
||||
|
||||
$entity['net_total'] = $entity['price'] - $entity['discount'];
|
||||
$entity['profit'] = $entity['price'] - $entity['discount'] - $entity['cost'];
|
||||
|
||||
if(strlen($entity['tax_name1']) > 1) {
|
||||
$entity['tax_name1'] = $entity['tax_name1'] . ' [' . $entity['tax_rate1'] . '%]';
|
||||
$entity['tax_amount1'] = $this->calculateTax($invoice, $entity['line_total'], $entity['tax_rate1']);
|
||||
}
|
||||
else
|
||||
$entity['tax_amount1'] = 0;
|
||||
|
||||
if(strlen($entity['tax_name2']) > 1) {
|
||||
$entity['tax_name2'] = $entity['tax_name2'] . ' [' . $entity['tax_rate2'] . '%]';
|
||||
$entity['tax_amount2'] = $this->calculateTax($invoice, $entity['line_total'], $entity['tax_rate2']);
|
||||
}
|
||||
else
|
||||
$entity['tax_amount2'] = 0;
|
||||
|
||||
if(strlen($entity['tax_name3']) > 1) {
|
||||
$entity['tax_name3'] = $entity['tax_name3'] . ' [' . $entity['tax_rate3'] . '%]';
|
||||
$entity['tax_amount3'] = $this->calculateTax($invoice, $entity['line_total'], $entity['tax_rate3']);
|
||||
}
|
||||
else
|
||||
$entity['tax_amount3'] = 0;
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* calculateTax
|
||||
*
|
||||
* @param mixed $invoice
|
||||
* @param float $amount
|
||||
* @param float $tax_rate
|
||||
* @return float
|
||||
*/
|
||||
private function calculateTax(Invoice $invoice, float $amount, float $tax_rate): float
|
||||
{
|
||||
$amount = $amount - ($amount * ($invoice->discount / 100));
|
||||
|
||||
if($invoice->uses_inclusive_taxes) {
|
||||
return round($amount - ($amount / (1 + ($tax_rate / 100))), 2);
|
||||
}
|
||||
else {
|
||||
return round(($amount * $tax_rate / 100), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* calculateDiscount
|
||||
*
|
||||
* @param mixed $invoice
|
||||
* @param mixed $entity
|
||||
* @return float
|
||||
*/
|
||||
private function calculateDiscount(Invoice $invoice , $entity) :float
|
||||
{
|
||||
if($entity['discount'] == 0)
|
||||
return 0;
|
||||
|
||||
if($invoice->is_amount_discount && $entity['discount'] != 0) {
|
||||
return $entity['discount'];
|
||||
}
|
||||
elseif(!$invoice->is_amount_discount && $entity['discount'] != 0) {
|
||||
return round($entity['line_total'] * ($entity['discount'] / 100), 2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* getProduct
|
||||
*
|
||||
* @param string $product_key
|
||||
* @return Product
|
||||
*/
|
||||
private function getProduct(string $product_key) :?Product
|
||||
{
|
||||
return $this->products->firstWhere('product_key', $product_key);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -24,13 +23,13 @@ class QuoteExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $quote_transformer;
|
||||
|
||||
protected string $date_key = 'date';
|
||||
public string $date_key = 'date';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'amount' => 'amount',
|
||||
'balance' => 'balance',
|
||||
'client' => 'client_id',
|
||||
|
@ -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;
|
||||
@ -24,13 +23,13 @@ class QuoteItemExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $quote_transformer;
|
||||
|
||||
protected string $date_key = 'date';
|
||||
public string $date_key = 'date';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'amount' => 'amount',
|
||||
'balance' => 'balance',
|
||||
'client' => 'client_id',
|
||||
|
@ -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;
|
||||
@ -24,13 +23,13 @@ class RecurringInvoiceExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $invoice_transformer;
|
||||
|
||||
protected string $date_key = 'date';
|
||||
public string $date_key = 'date';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'amount' => 'amount',
|
||||
'balance' => 'balance',
|
||||
'client' => 'client_id',
|
||||
|
@ -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;
|
||||
@ -27,15 +26,15 @@ class TaskExport extends BaseExport
|
||||
{
|
||||
private Company $company;
|
||||
|
||||
protected array $input;
|
||||
|
||||
private $entity_transformer;
|
||||
|
||||
protected $date_key = 'created_at';
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
private string $date_format = 'YYYY-MM-DD';
|
||||
|
||||
protected array $entity_keys = [
|
||||
public Writer $csv;
|
||||
|
||||
public array $entity_keys = [
|
||||
'start_date' => 'start_date',
|
||||
'end_date' => 'end_date',
|
||||
'duration' => 'duration',
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ class ClientContactFactory
|
||||
$client_contact->first_name = '';
|
||||
$client_contact->user_id = $user_id;
|
||||
$client_contact->company_id = $company_id;
|
||||
$client_contact->contact_key = Str::random(40);
|
||||
$client_contact->contact_key = Str::random(32);
|
||||
$client_contact->id = 0;
|
||||
$client_contact->send_email = true;
|
||||
|
||||
|
@ -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
|
||||
|
@ -22,7 +22,7 @@ class VendorContactFactory
|
||||
$vendor_contact->first_name = '';
|
||||
$vendor_contact->user_id = $user_id;
|
||||
$vendor_contact->company_id = $company_id;
|
||||
$vendor_contact->contact_key = Str::random(40);
|
||||
$vendor_contact->contact_key = Str::random(32);
|
||||
$vendor_contact->id = 0;
|
||||
|
||||
return $vendor_contact;
|
||||
|
@ -49,7 +49,6 @@ class BankIntegrationFilters extends QueryFilters
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('bank_account_name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,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');
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ class BankTransactionFilters extends QueryFilters
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('bank_transactions.description', 'like', '%'.$filter.'%');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -79,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 = [];
|
||||
@ -105,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;
|
||||
@ -132,17 +129,21 @@ class BankTransactionFilters extends QueryFilters
|
||||
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]);
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ class BankTransactionRuleFilters extends QueryFilters
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('bank_transaction_rules.name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,8 +147,9 @@ class ClientFilters extends QueryFilters
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
if($sort_col[0] == 'display_name')
|
||||
if ($sort_col[0] == 'display_name') {
|
||||
$sort_col[0] = 'name';
|
||||
}
|
||||
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
@ -165,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;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class DesignFilters extends QueryFilters
|
||||
*
|
||||
* @param string query filter
|
||||
* @return Builder
|
||||
*
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = ''): Builder
|
||||
@ -41,7 +41,7 @@ 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
|
||||
@ -62,6 +62,6 @@ class DesignFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter(): Builder
|
||||
{
|
||||
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,10 +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
|
||||
{
|
||||
@ -69,8 +69,9 @@ class DocumentFilters extends QueryFilters
|
||||
|
||||
public function company_documents($value = 'false')
|
||||
{
|
||||
if($value == 'true')
|
||||
if ($value == 'true') {
|
||||
return $this->builder->where('documentable_type', Company::class);
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
|
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