mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on migrations
This commit is contained in:
parent
0c9f982bdf
commit
63cc567244
@ -299,6 +299,9 @@ class CheckData extends Command
|
||||
|
||||
foreach (Client::cursor() as $client) {
|
||||
$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
|
||||
$credit_balance = $client->credits->where('is_deleted', false)->sum('balance');
|
||||
|
||||
$invoice_balance += $credit_balance;
|
||||
|
||||
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
|
||||
|
||||
@ -385,6 +388,9 @@ class CheckData extends Command
|
||||
foreach (Client::cursor() as $client) {
|
||||
//$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
|
||||
$invoice_balance = Invoice::where('client_id', $client->id)->where('is_deleted', false)->where('status_id', '>', 1)->withTrashed()->sum('balance');
|
||||
$client_balance = Credit::where('client_id', $client->id)->where('is_deleted', false)->withTrashed()->sum('balance');
|
||||
|
||||
$invoice_balance += $client_balance;
|
||||
|
||||
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
|
||||
|
||||
|
@ -74,6 +74,7 @@ use App\Repositories\VendorRepository;
|
||||
use App\Utils\Traits\CleanLineItems;
|
||||
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\SavesDocuments;
|
||||
use App\Utils\Traits\Uploadable;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@ -93,6 +94,7 @@ class Import implements ShouldQueue
|
||||
use MakesHash;
|
||||
use CleanLineItems;
|
||||
use Uploadable;
|
||||
use SavesDocuments;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@ -126,7 +128,7 @@ class Import implements ShouldQueue
|
||||
'task_statuses',
|
||||
'expenses',
|
||||
'tasks',
|
||||
// //'documents',
|
||||
'documents',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -150,7 +152,7 @@ class Import implements ShouldQueue
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
public $timeout = 864000;
|
||||
public $timeout = 0;
|
||||
|
||||
// public $backoff = 86430;
|
||||
|
||||
@ -184,8 +186,6 @@ class Import implements ShouldQueue
|
||||
$array = json_decode(file_get_contents($this->file_path), 1);
|
||||
$data = $array['data'];
|
||||
|
||||
info(array_keys($data));
|
||||
|
||||
foreach ($this->available_imports as $import) {
|
||||
|
||||
info("the key = {$import}");
|
||||
@ -903,10 +903,11 @@ info(array_keys($data));
|
||||
|
||||
private function processDocuments(array $data): void
|
||||
{
|
||||
Document::unguard();
|
||||
// Document::unguard();
|
||||
/* No validators since data provided by database is already valid. */
|
||||
|
||||
foreach ($data as $resource) {
|
||||
foreach($data as $resource)
|
||||
{
|
||||
$modified = $resource;
|
||||
|
||||
if (array_key_exists('invoice_id', $resource) && $resource['invoice_id'] && ! array_key_exists('invoices', $this->ids)) {
|
||||
@ -917,42 +918,67 @@ info(array_keys($data));
|
||||
throw new ResourceDependencyMissing('Processing documents failed, because of missing dependency - expenses.');
|
||||
}
|
||||
|
||||
/* Remove because of polymorphic joins. */
|
||||
unset($modified['invoice_id']);
|
||||
unset($modified['expense_id']);
|
||||
|
||||
if (array_key_exists('invoice_id', $resource) && $resource['invoice_id'] && array_key_exists('invoices', $this->ids)) {
|
||||
$modified['documentable_id'] = $this->transformId('invoices', $resource['invoice_id']);
|
||||
$modified['documentable_type'] = Invoice::class;
|
||||
$invoice_id = $this->transformId('invoices', $resource['invoice_id']);
|
||||
$entity = Invoice::where('id', $invoice_id)->withTrashed()->first();
|
||||
}
|
||||
|
||||
if (array_key_exists('expense_id', $resource) && $resource['expense_id'] && array_key_exists('expenses', $this->ids)) {
|
||||
$modified['documentable_id'] = $this->transformId('expenses', $resource['expense_id']);
|
||||
$modified['documentable_type'] = Expense::class;
|
||||
$expense_id = $this->transformId('expenses', $resource['expense_id']);
|
||||
$entity = Expense::where('id', $expense_id)->withTrashed()->first();
|
||||
}
|
||||
|
||||
$modified['user_id'] = $this->processUserId($resource);
|
||||
$modified['company_id'] = $this->company->id;
|
||||
$this->saveDocument(file_get_contents($resource['url']), $entity, $is_public = true);
|
||||
|
||||
$document = Document::create($modified);
|
||||
|
||||
// $entity = $modified['documentable_type']::find($modified['documentable_id']);
|
||||
// $entity->documents()->save($modified);
|
||||
|
||||
$old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id;
|
||||
|
||||
$this->ids['documents'] = [
|
||||
"documents_{$old_user_key}" => [
|
||||
'old' => $resource['id'],
|
||||
'new' => $document->id,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
Document::reguard();
|
||||
// foreach ($data as $resource) {
|
||||
// $modified = $resource;
|
||||
|
||||
/*Improve memory handling by setting everything to null when we have finished*/
|
||||
$data = null;
|
||||
// if (array_key_exists('invoice_id', $resource) && $resource['invoice_id'] && ! array_key_exists('invoices', $this->ids)) {
|
||||
// throw new ResourceDependencyMissing('Processing documents failed, because of missing dependency - invoices.');
|
||||
// }
|
||||
|
||||
// if (array_key_exists('expense_id', $resource) && $resource['expense_id'] && ! array_key_exists('expenses', $this->ids)) {
|
||||
// throw new ResourceDependencyMissing('Processing documents failed, because of missing dependency - expenses.');
|
||||
// }
|
||||
|
||||
// /* Remove because of polymorphic joins. */
|
||||
// unset($modified['invoice_id']);
|
||||
// unset($modified['expense_id']);
|
||||
|
||||
// if (array_key_exists('invoice_id', $resource) && $resource['invoice_id'] && array_key_exists('invoices', $this->ids)) {
|
||||
// $modified['documentable_id'] = $this->transformId('invoices', $resource['invoice_id']);
|
||||
// $modified['documentable_type'] = Invoice::class;
|
||||
// }
|
||||
|
||||
// if (array_key_exists('expense_id', $resource) && $resource['expense_id'] && array_key_exists('expenses', $this->ids)) {
|
||||
// $modified['documentable_id'] = $this->transformId('expenses', $resource['expense_id']);
|
||||
// $modified['documentable_type'] = Expense::class;
|
||||
// }
|
||||
|
||||
// $modified['user_id'] = $this->processUserId($resource);
|
||||
// $modified['company_id'] = $this->company->id;
|
||||
|
||||
// $document = Document::create($modified);
|
||||
|
||||
// // $entity = $modified['documentable_type']::find($modified['documentable_id']);
|
||||
// // $entity->documents()->save($modified);
|
||||
|
||||
// $old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id;
|
||||
|
||||
// $this->ids['documents'] = [
|
||||
// "documents_{$old_user_key}" => [
|
||||
// 'old' => $resource['id'],
|
||||
// 'new' => $document->id,
|
||||
// ],
|
||||
// ];
|
||||
// }
|
||||
|
||||
// Document::reguard();
|
||||
|
||||
// /*Improve memory handling by setting everything to null when we have finished*/
|
||||
// $data = null;
|
||||
}
|
||||
|
||||
private function processPaymentTerms(array $data) :void
|
||||
|
@ -53,7 +53,7 @@ class StartMigration implements ShouldQueue
|
||||
*/
|
||||
public $tries = 1;
|
||||
|
||||
public $timeout = 864000;
|
||||
public $timeout = 0;
|
||||
|
||||
// public $maxExceptions = 2;
|
||||
|
||||
|
@ -46,8 +46,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laracasts\Presenter\PresentableTrait;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasTableAlias;
|
||||
|
||||
class Company extends BaseModel
|
||||
{
|
||||
@ -55,8 +53,6 @@ class Company extends BaseModel
|
||||
use MakesHash;
|
||||
use CompanySettingsSaver;
|
||||
use ThrottlesEmail;
|
||||
use HasRelationships;
|
||||
use HasTableAlias;
|
||||
|
||||
const ENTITY_RECURRING_INVOICE = 'recurring_invoice';
|
||||
const ENTITY_CREDIT = 'credit';
|
||||
|
@ -13,11 +13,10 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
|
||||
class CompanyUser extends Pivot
|
||||
{
|
||||
use HasRelationships;
|
||||
|
||||
use SoftDeletes;
|
||||
|
||||
// protected $guarded = ['id'];
|
||||
@ -95,7 +94,6 @@ class CompanyUser extends Pivot
|
||||
//return $this->hasMany(CompanyToken::class);
|
||||
//return $this->hasOne(CompanyToken::class, 'user_id', 'user_id','company_id', 'company_id');
|
||||
|
||||
//return $this->hasOneDeep(CompanyToken::class, [CompanyUser::class], ['user_id','company_id'], ['company_id','company_id']);
|
||||
|
||||
//return $this->belongsTo(CompanyToken::class, 'user_id', 'user_id');
|
||||
|
||||
|
@ -33,7 +33,6 @@ use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laracasts\Presenter\PresentableTrait;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
|
||||
class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
@ -44,7 +43,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
use UserSessionAttributes;
|
||||
use UserSettings;
|
||||
use Filterable;
|
||||
use HasRelationships;
|
||||
use HasFactory;
|
||||
|
||||
protected $guard = 'user';
|
||||
|
@ -68,6 +68,7 @@ class Phantom
|
||||
$file_path = $path.$entity_obj->number.'.pdf';
|
||||
|
||||
$url = config('ninja.app_url').'phantom/'.$entity.'/'.$invitation->key.'?phantomjs_secret='.config('ninja.phantomjs_secret');
|
||||
info($url);
|
||||
|
||||
$key = config('ninja.phantomjs_key');
|
||||
$secret = config('ninja.phantomjs_key');
|
||||
|
@ -43,4 +43,30 @@ trait SavesDocuments
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveDocument($document, $entity, $is_public = true)
|
||||
{
|
||||
if ($entity instanceof Company) {
|
||||
$account = $entity->account;
|
||||
$company = $entity;
|
||||
} else {
|
||||
$account = $entity->company->account;
|
||||
$company = $entity->company;
|
||||
}
|
||||
|
||||
if (! $account->hasFeature(Account::FEATURE_DOCUMENTS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$document = UploadFile::dispatchNow(
|
||||
$document,
|
||||
UploadFile::DOCUMENT,
|
||||
$entity->user,
|
||||
$entity->company,
|
||||
$entity,
|
||||
null,
|
||||
$is_public
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@
|
||||
"fzaninotto/faker": "^1.4",
|
||||
"google/apiclient": "^2.7",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"halaxa/json-machine": "^0.4.0",
|
||||
"hashids/hashids": "^3.0",
|
||||
"intervention/image": "^2.5",
|
||||
"laracasts/presenter": "^0.2.1",
|
||||
@ -59,7 +58,6 @@
|
||||
"predis/predis": "^1.1",
|
||||
"sentry/sentry-laravel": "^2",
|
||||
"spatie/browsershot": "^3.37",
|
||||
"staudenmeir/eloquent-has-many-deep": "^1.11",
|
||||
"stripe/stripe-php": "^7.50",
|
||||
"turbo124/beacon": "^1",
|
||||
"turbo124/laravel-gmail": "^5.0",
|
||||
|
@ -38,14 +38,14 @@ return [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'retry_after' => 900000,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'retry_after' => 900000,
|
||||
'block_for' => 0,
|
||||
],
|
||||
|
||||
@ -63,7 +63,7 @@ return [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
'queue' => env('REDIS_QUEUE', 'default'),
|
||||
'retry_after' => 90,
|
||||
'retry_after' => 900000,
|
||||
'block_for' => null,
|
||||
],
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user