1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Apply Laravel coding style

Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the code style applied by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] ruleset to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started.

For more information on customizing the code style applied by Shift, [watch this short video][4].

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://github.com/squizlabs/PHP_CodeSniffer
[3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
[4]: https://laravelshift.com/videos/shift-code-style
This commit is contained in:
Shift 2022-06-21 09:57:17 +00:00
parent 8eed25ed22
commit 19080933b6
No known key found for this signature in database
GPG Key ID: 5A96F038425C5A1C
1363 changed files with 28235 additions and 31395 deletions

View File

@ -66,39 +66,25 @@ class BackupUpdate extends Command
$this->handleOnDb();
}
MultiDB::setDB($current_db);
MultiDB::setDB($current_db);
}
}
private function handleOnDb()
{
set_time_limit(0);
Backup::whereHas('activity')->whereRaw('html_backup IS NOT NULL')->cursor()->each( function ($backup) {
if(strlen($backup->html_backup) > 1 && $backup->activity->invoice->exists()){
$client = $backup->activity->invoice->client;
$backup->storeRemotely($backup->html_backup, $client);
}else if(strlen($backup->html_backup) > 1 && $backup->activity->quote->exists()){
$client = $backup->activity->quote->client;
$backup->storeRemotely($backup->html_backup, $client);
}else if(strlen($backup->html_backup) > 1 && $backup->activity->credit->exists()){
$client = $backup->activity->credit->client;
$backup->storeRemotely($backup->html_backup, $client);
}
Backup::whereHas('activity')->whereRaw('html_backup IS NOT NULL')->cursor()->each(function ($backup) {
if (strlen($backup->html_backup) > 1 && $backup->activity->invoice->exists()) {
$client = $backup->activity->invoice->client;
$backup->storeRemotely($backup->html_backup, $client);
} elseif (strlen($backup->html_backup) > 1 && $backup->activity->quote->exists()) {
$client = $backup->activity->quote->client;
$backup->storeRemotely($backup->html_backup, $client);
} elseif (strlen($backup->html_backup) > 1 && $backup->activity->credit->exists()) {
$client = $backup->activity->credit->client;
$backup->storeRemotely($backup->html_backup, $client);
}
});
}
}

View File

@ -91,21 +91,20 @@ class CheckData extends Command
protected $wrong_paid_status = 0;
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 ";
$fix_status = $this->option('fix') ? 'Fixing Issues' : 'Just checking issues ';
$this->logMessage(date('Y-m-d h:i:s').' Running CheckData... on ' . $database_connection . " Fix Status = {$fix_status}");
$this->logMessage(date('Y-m-d h:i:s').' Running CheckData... on '.$database_connection." Fix Status = {$fix_status}");
if ($database = $this->option('database')) {
config(['database.default' => $database]);
}
$this->checkInvoiceBalances();
$this->checkInvoiceBalances();
$this->checkPaidToDatesNew();
$this->checkContacts();
@ -114,15 +113,16 @@ class CheckData extends Command
$this->checkCompanyData();
$this->checkBalanceVsPaidStatus();
if(Ninja::isHosted())
if (Ninja::isHosted()) {
$this->checkAccountStatuses();
}
if (! $this->option('client_id')) {
$this->checkOAuth();
}
$this->logMessage('Done: '.strtoupper($this->isValid ? Account::RESULT_SUCCESS : Account::RESULT_FAILURE));
$this->logMessage('Total execution time in seconds: ' . (microtime(true) - $time_start));
$this->logMessage('Total execution time in seconds: '.(microtime(true) - $time_start));
$errorEmail = config('ninja.error_email');
@ -235,7 +235,7 @@ class CheckData extends Command
if ($this->option('fix') == 'true') {
foreach ($clients as $client) {
$this->logMessage("Fixing missing contacts #{$client->id}");
$new_contact = ClientContactFactory::create($client->company_id, $client->user_id);
$new_contact->client_id = $client->id;
$new_contact->contact_key = Str::random(40);
@ -243,7 +243,6 @@ class CheckData extends Command
$new_contact->save();
}
}
}
private function checkVendorContacts()
@ -291,12 +290,11 @@ class CheckData extends Command
}
if ($this->option('fix') == 'true') {
$vendors = Vendor::withTrashed()->doesntHave('contacts')->get();
foreach ($vendors as $vendor) {
$this->logMessage("Fixing missing vendor contacts #{$vendor->id}");
$new_contact = VendorContactFactory::create($vendor->company_id, $vendor->user_id);
$new_contact->vendor_id = $vendor->id;
$new_contact->contact_key = Str::random(40);
@ -304,10 +302,8 @@ class CheckData extends Command
$new_contact->save();
}
}
}
private function checkFailedJobs()
{
if (config('ninja.testvars.travis')) {
@ -356,36 +352,32 @@ class CheckData extends Command
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]);
$entities = ['invoice', 'quote', 'credit', 'recurring_invoice'];
foreach($entities as $entity)
{
foreach ($entities as $entity) {
$table = "{$entity}s";
$invitation_table = "{$entity}_invitations";
$entities = DB::table($table)
->leftJoin($invitation_table, function ($join) use($invitation_table, $table, $entity){
$entities = DB::table($table)
->leftJoin($invitation_table, function ($join) use ($invitation_table, $table, $entity) {
$join->on("{$invitation_table}.{$entity}_id", '=', "{$table}.id");
// ->whereNull("{$invitation_table}.deleted_at");
// ->whereNull("{$invitation_table}.deleted_at");
})
->groupBy("{$table}.id", "{$table}.user_id", "{$table}.company_id", "{$table}.client_id")
->havingRaw("count({$invitation_table}.id) = 0")
->get(["{$table}.id", "{$table}.user_id", "{$table}.company_id", "{$table}.client_id"]);
$this->logMessage($entities->count()." {$table} without any invitations");
$this->logMessage($entities->count()." {$table} without any invitations");
if ($this->option('fix') == 'true')
$this->fixInvitations($entities, $entity);
if ($this->option('fix') == 'true') {
$this->fixInvitations($entities, $entity);
}
}
}
private function fixInvitations($entities, $entity)
@ -394,8 +386,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;
@ -403,20 +394,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,
@ -431,14 +419,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
@ -450,8 +438,8 @@ 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;
}
@ -460,9 +448,8 @@ class CheckData extends Command
$clients_to_check = $this->clientPaidToDateQuery();
$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');
@ -471,26 +458,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')){
$this->logMessage("# {$client->id} " . $client->present()->name.' - '.$client->number." Fixing {$client->paid_to_date} to {$total_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()
@ -499,12 +482,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]);
})
->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))')
@ -512,19 +495,16 @@ 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])
->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
@ -537,7 +517,6 @@ class CheckData extends Command
// 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')
@ -547,7 +526,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++;
@ -556,8 +535,8 @@ class CheckData extends Command
$this->isValid = false;
if($this->option('paid_to_date')){
$this->logMessage("# {$client->id} " . $client->present()->name.' - '.$client->number." Fixing {$client->paid_to_date} to {$total_invoice_payments}");
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();
}
@ -572,9 +551,7 @@ 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])
->selectRaw('sum(paymentables.amount - paymentables.refunded) as p')
@ -585,7 +562,7 @@ class CheckData extends Command
$calculated_paid_amount = $invoice->amount - $invoice->balance - $total_credit;
if ((string)$total_paid != (string)($invoice->amount - $invoice->balance - $total_credit)) {
if ((string) $total_paid != (string) ($invoice->amount - $invoice->balance - $total_credit)) {
$this->wrong_balances++;
$this->logMessage($client->present()->name.' - '.$client->id." - Total Paid = {$total_paid} != Calculated Total = {$calculated_paid_amount}");
@ -593,7 +570,6 @@ class CheckData extends Command
$this->isValid = false;
}
});
});
$this->logMessage("{$this->wrong_balances} clients with incorrect invoice balances");
@ -601,7 +577,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,
@ -615,8 +591,8 @@ class CheckData extends Command
GROUP BY clients.id
HAVING invoice_balance != clients.balance
ORDER BY clients.id;
") );
'));
return $results;
}
@ -627,29 +603,24 @@ class CheckData extends Command
$clients = $this->clientBalanceQuery();
foreach($clients as $client)
{
$client = (array)$client;
foreach ($clients as $client) {
$client = (array) $client;
if ((string) $client['invoice_balance'] != (string) $client['client_balance']) {
$this->wrong_paid_to_dates++;
$client_object = Client::withTrashed()->find($client['client_id']);
$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')){
$this->logMessage("# {$client_object->id} " . $client_object->present()->name.' - '.$client_object->number." Fixing {$client_object->balance} to " . $client['invoice_balance']);
$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')) {
$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");
@ -657,7 +628,7 @@ class CheckData extends Command
private function invoiceBalanceQuery()
{
$results = \DB::select( \DB::raw("
$results = \DB::select(\DB::raw('
SELECT
clients.id,
clients.balance,
@ -671,8 +642,8 @@ class CheckData extends Command
GROUP BY clients.id
HAVING(invoices_balance != clients.balance)
ORDER BY clients.id;
") );
'));
return $results;
}
@ -683,11 +654,10 @@ 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');
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2, 3])->sum('balance');
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
@ -695,31 +665,26 @@ class CheckData extends Command
$this->wrong_balances++;
$ledger_balance = $ledger ? $ledger->balance : 0;
$this->logMessage("# {$client->id} " . $client->present()->name.' - '.$client->number." - Balance Failure - Invoice Balances = {$invoice_balance} Client Balance = {$client->balance} Ledger Balance = {$ledger_balance}");
$this->logMessage("# {$client->id} ".$client->present()->name.' - '.$client->number." - Balance Failure - Invoice Balances = {$invoice_balance} Client Balance = {$client->balance} Ledger Balance = {$ledger_balance}");
$this->isValid = false;
if($this->option('client_balance')){
$this->logMessage("# {$client->id} " . $client->present()->name.' - '.$client->number." Fixing {$client->balance} to {$invoice_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()
@ -728,19 +693,17 @@ class CheckData extends Command
$this->wrong_paid_to_dates = 0;
foreach (Client::where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->cursor() as $client) {
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3])->sum('balance');
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2, 3])->sum('balance');
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
if ($ledger && number_format($ledger->balance, 4) != number_format($client->balance, 4)) {
$this->wrong_balances++;
$this->logMessage("# {$client->id} " . $client->present()->name.' - '.$client->number." - Balance Failure - Client Balance = {$client->balance} Ledger Balance = {$ledger->balance}");
$this->logMessage("# {$client->id} ".$client->present()->name.' - '.$client->number." - Balance Failure - Client Balance = {$client->balance} Ledger Balance = {$ledger->balance}");
$this->isValid = false;
if($this->option('ledger_balance')){
$this->logMessage("# {$client->id} " . $client->present()->name.' - '.$client->number." Fixing {$client->balance} to {$invoice_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();
@ -749,7 +712,6 @@ class CheckData extends Command
$ledger->notes = 'Ledger Adjustment';
$ledger->save();
}
}
}
@ -841,22 +803,20 @@ 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)
$this->logMessage("I found a payment for {$account->key}");
if ($payment) {
$this->logMessage("I found a payment for {$account->key}");
}
}
});
}
@ -864,24 +824,21 @@ class CheckData extends Command
{
$this->wrong_paid_status = 0;
foreach(Invoice::with(['payments'])->whereHas('payments')->where('status_id', 4)->where('balance', '>', 0)->where('is_deleted',0)->cursor() as $invoice)
{
foreach (Invoice::with(['payments'])->whereHas('payments')->where('status_id', 4)->where('balance', '>', 0)->where('is_deleted', 0)->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')){
$this->logMessage("# {$invoice->id} ".' - '.$invoice->number." - Marked as paid, but balance = {$invoice->balance}");
if ($this->option('balance_status')) {
$val = $invoice->balance;
$invoice->balance = 0;
$invoice->paid_to_date=$val;
$invoice->paid_to_date = $val;
$invoice->save();
$p = $invoice->payments->first();
if($p && (int)$p->amount == 0)
{
if ($p && (int) $p->amount == 0) {
$p->amount = $val;
$p->applied = $val;
$p->save();
@ -891,14 +848,10 @@ class CheckData extends Command
$pivot->save();
}
$this->logMessage("Fixing {$invoice->id} settings payment to {$val}");
}
}
$this->logMessage($this->wrong_paid_status." wrong invoices with bad balance state");
$this->logMessage($this->wrong_paid_status.' wrong invoices with bad balance state');
}
}
}

View File

@ -36,8 +36,8 @@ use App\Models\GroupSetting;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\Paymentable;
use App\Models\PaymentHash;
use App\Models\Product;
use App\Models\Project;
use App\Models\Quote;
@ -61,13 +61,11 @@ use Illuminate\Support\Str;
use Mail;
use Symfony\Component\Console\Input\InputOption;
/**
* Class CheckDb.
*/
class CheckDb extends Command
{
protected $signature = 'ninja:check-db';
protected $description = 'Check MultiDB';
@ -118,33 +116,30 @@ class CheckDb extends Command
public function handle()
{
$this->LogMessage('Checking - V5_DB1');
$this->LogMessage("Checking - V5_DB1");
foreach($this->entities as $entity) {
foreach ($this->entities as $entity) {
$count_db_1 = $entity::on('db-ninja-01')->count();
$count_db_2 = $entity::on('db-ninja-02a')->count();
$diff = $count_db_1 - $count_db_2;
if($diff != 0)
if ($diff != 0) {
$this->logMessage("{$entity} DB1: {$count_db_1} - DB2: {$count_db_2} - diff = {$diff}");
}
}
$this->LogMessage("Checking - V5_DB2");
foreach($this->entities as $entity) {
$this->LogMessage('Checking - V5_DB2');
foreach ($this->entities as $entity) {
$count_db_1 = $entity::on('db-ninja-02')->count();
$count_db_2 = $entity::on('db-ninja-01a')->count();
$diff = $count_db_1 - $count_db_2;
if($diff != 0)
if ($diff != 0) {
$this->logMessage("{$entity} DB1: {$count_db_1} - DB2: {$count_db_2} - diff = {$diff}");
}
}
}
@ -154,5 +149,4 @@ class CheckDb extends Command
$this->info($str);
$this->log .= $str."\n";
}
}

View File

@ -51,10 +51,12 @@ use Illuminate\Support\Str;
class CreateAccount extends Command
{
use MakesHash, GeneratesCounter;
/**
* @var string
*/
protected $description = 'Create Single Account';
/**
* @var string
*/
@ -82,12 +84,10 @@ class CreateAccount extends Command
$this->warmCache();
$this->createAccount();
}
private function createAccount()
{
$account = Account::factory()->create();
$company = Company::factory()->create([
'account_id' => $account->id,
@ -134,7 +134,6 @@ class CreateAccount extends Command
CreateCompanyPaymentTerms::dispatchNow($company, $user);
CreateCompanyTaskStatuses::dispatchNow($company, $user);
VersionCheck::dispatchNow();
}
private function warmCache()
@ -164,5 +163,4 @@ class CreateAccount extends Command
}
}
}
}

View File

@ -57,9 +57,9 @@ use stdClass;
class CreateSingleAccount extends Command
{
use MakesHash, GeneratesCounter;
protected $description = 'Create Single Sample Account';
protected $signature = 'ninja:create-single-account {gateway=all} {--database=db-ninja-01}';
protected $invoice_repo;
@ -75,12 +75,13 @@ class CreateSingleAccount extends Command
*/
public function handle()
{
if (config('ninja.is_docker')) {
return;
}
if(config('ninja.is_docker'))
return;
if (!$this->confirm('Are you sure you want to inject dummy data?'))
if (! $this->confirm('Are you sure you want to inject dummy data?')) {
return;
}
$this->invoice_repo = new InvoiceRepository();
@ -105,10 +106,10 @@ class CreateSingleAccount extends Command
$company = Company::factory()->create([
'account_id' => $account->id,
'slack_webhook_url' => config('ninja.notification.slack'),
'default_password_timeout' => 30*60000,
'default_password_timeout' => 30 * 60000,
'portal_mode' => 'domain',
'portal_domain' => 'http://ninja.test:8000',
'track_inventory' => true
'track_inventory' => true,
]);
$settings = $company->settings;
@ -153,33 +154,31 @@ class CreateSingleAccount extends Command
]);
Product::factory()->count(1)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'company_id' => $company->id,
]);
TaxRate::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'name' => 'GST',
'rate' => 10
'rate' => 10,
]);
TaxRate::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'name' => 'VAT',
'rate' => 17.5
'rate' => 17.5,
]);
TaxRate::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'name' => 'CA Sales Tax',
'rate' => 5
'rate' => 5,
]);
$this->info('Creating '.$this->count.' clients');
for ($x = 0; $x < $this->count; $x++) {
@ -227,18 +226,18 @@ class CreateSingleAccount extends Command
$client = $company->clients->random();
$this->info('creating task for client #' . $client->id);
$this->info('creating task for client #'.$client->id);
$this->createTask($client);
$client = $company->clients->random();
$this->info('creating project for client #' . $client->id);
$this->info('creating project for client #'.$client->id);
$this->createProject($client);
$this->info('creating credit for client #' . $client->id);
$this->info('creating credit for client #'.$client->id);
$this->createCredit($client);
$this->info('creating recurring invoice for client # ' . $client->id);
$this->info('creating recurring invoice for client # '.$client->id);
$this->createRecurringInvoice($client);
}
@ -250,7 +249,7 @@ class CreateSingleAccount extends Command
private function createSubsData($company, $user)
{
$gs = GroupSettingFactory::create($company->id, $user->id);
$gs->name = "plans";
$gs->name = 'plans';
$gs->save();
$p1 = Product::factory()->create([
@ -290,7 +289,7 @@ class CreateSingleAccount extends Command
];
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->name = "Pro Plan";
$sub->name = 'Pro Plan';
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p1->hashed_id}";
$sub->webhook_configuration = $webhook_config;
@ -299,7 +298,7 @@ class CreateSingleAccount extends Command
$sub->save();
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->name = "Enterprise Plan";
$sub->name = 'Enterprise Plan';
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p2->hashed_id}";
$sub->webhook_configuration = $webhook_config;
@ -308,7 +307,7 @@ class CreateSingleAccount extends Command
$sub->save();
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->name = "Free Plan";
$sub->name = 'Free Plan';
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p3->hashed_id}";
$sub->webhook_configuration = $webhook_config;
@ -324,28 +323,28 @@ class CreateSingleAccount extends Command
// });
$client = Client::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'company_id' => $company->id,
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
'email' => 'user@example.com'
]);
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
'email' => 'user@example.com',
]);
ClientContact::factory()->count(rand(1, 2))->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
]);
$client->number = $this->getNextClientNumber($client);
$settings = $client->settings;
$settings->currency_id = "1";
$settings->currency_id = '1';
// $settings->use_credits_payment = "always";
$client->settings = $settings;
@ -359,48 +358,48 @@ class CreateSingleAccount extends Command
private function createExpense($client)
{
Expense::factory()->count(rand(1, 2))->create([
'user_id' => $client->user->id,
'client_id' => $client->id,
'company_id' => $client->company->id,
]);
'user_id' => $client->user->id,
'client_id' => $client->id,
'company_id' => $client->company->id,
]);
}
private function createVendor($client)
{
$vendor = Vendor::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
VendorContact::factory()->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 1,
]);
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 1,
]);
VendorContact::factory()->count(rand(1, 2))->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 0,
]);
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 0,
]);
}
private function createTask($client)
{
$vendor = Task::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
}
private function createProject($client)
{
$vendor = Project::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
}
private function createInvoice($client)
@ -517,7 +516,6 @@ class CreateSingleAccount extends Command
$quote->service()->createInvitations();
}
private function buildCreditItem()
{
$line_items = [];
@ -538,11 +536,9 @@ class CreateSingleAccount extends Command
$line_items[] = $item;
return $line_items;
}
private function buildLineItems($count = 1)
{
$line_items = [];
@ -614,7 +610,6 @@ class CreateSingleAccount extends Command
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;
@ -633,8 +628,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')) {
@ -742,7 +735,6 @@ class CreateSingleAccount extends Command
$cg->save();
}
if (config('ninja.testvars.paytrace.decrypted') && ($this->gateway == 'all' || $this->gateway == 'paytrace')) {
$cg = new CompanyGateway;
$cg->company_id = $company->id;
@ -756,7 +748,6 @@ class CreateSingleAccount extends Command
$cg->save();
$gateway_types = $cg->driver()->gatewayTypes();
$fees_and_limits = new stdClass;

View File

@ -48,10 +48,12 @@ use Illuminate\Support\Str;
class CreateTestData extends Command
{
use MakesHash, GeneratesCounter;
/**
* @var string
*/
protected $description = 'Create Test Data';
/**
* @var string
*/
@ -66,14 +68,16 @@ class CreateTestData extends Command
*/
public function handle()
{
if(config('ninja.is_docker'))
if (config('ninja.is_docker')) {
return;
}
if (!$this->confirm('Are you sure you want to inject dummy data?'))
return;
if (! $this->confirm('Are you sure you want to inject dummy data?')) {
return;
}
$this->invoice_repo = new InvoiceRepository();
$this->info(date('r').' Running CreateTestData...');
$this->count = $this->argument('count');
@ -125,14 +129,14 @@ class CreateTestData extends Command
'is_admin' => 1,
'is_locked' => 0,
'notifications' => CompanySettings::notificationDefaults(),
// 'permissions' => '',
// 'permissions' => '',
'settings' => null,
]);
Product::factory()->count(50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'company_id' => $company->id,
]);
$this->info('Creating '.$this->count.' clients');
@ -219,15 +223,14 @@ class CreateTestData extends Command
'is_admin' => 1,
'is_locked' => 0,
'notifications' => CompanySettings::notificationDefaults(),
// 'permissions' => '',
// 'permissions' => '',
'settings' => null,
]);
Product::factory()->count(50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'company_id' => $company->id,
]);
$this->count = $this->count * 10;
@ -317,14 +320,14 @@ class CreateTestData extends Command
'is_admin' => 1,
'is_locked' => 0,
'notifications' => CompanySettings::notificationDefaults(),
// 'permissions' => '',
// 'permissions' => '',
'settings' => null,
]);
Product::factory()->count(15000)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'company_id' => $company->id,
]);
$this->count = $this->count * 10;
@ -382,30 +385,29 @@ class CreateTestData extends Command
// });
$client = Client::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'company_id' => $company->id,
]);
Document::factory()->count(50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
'documentable_type' => Client::class,
'documentable_id' => $client->id
]);
'user_id' => $user->id,
'company_id' => $company->id,
'documentable_type' => Client::class,
'documentable_id' => $client->id,
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
]);
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
]);
ClientContact::factory()->count(rand(1, 5))->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
]);
$client->number = $this->getNextClientNumber($client);
@ -422,70 +424,69 @@ class CreateTestData extends Command
private function createExpense($client)
{
Expense::factory()->count(rand(1, 5))->create([
'user_id' => $client->user->id,
'client_id' => $client->id,
'company_id' => $client->company->id,
]);
'user_id' => $client->user->id,
'client_id' => $client->id,
'company_id' => $client->company->id,
]);
}
private function createVendor($client)
{
$vendor = Vendor::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(50)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Vendor::class,
'documentable_id' => $vendor->id
]);
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Vendor::class,
'documentable_id' => $vendor->id,
]);
VendorContact::factory()->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 1,
]);
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 1,
]);
VendorContact::factory()->count(rand(1, 5))->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 0,
]);
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 0,
]);
}
private function createTask($client)
{
$vendor = Task::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Task::class,
'documentable_id' => $vendor->id
]);
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Task::class,
'documentable_id' => $vendor->id,
]);
}
private function createProject($client)
{
$vendor = Project::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Project::class,
'documentable_id' => $vendor->id
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Project::class,
'documentable_id' => $vendor->id,
]);
}
private function createInvoice($client)
@ -537,16 +538,15 @@ class CreateTestData extends Command
$invoice = $invoice->service()->markPaid()->save();
}
Document::factory()->count(5)->create([
'user_id' => $invoice->user->id,
'company_id' => $invoice->company_id,
'documentable_type' => Invoice::class,
'documentable_id' => $invoice->id
]);
Document::factory()->count(5)->create([
'user_id' => $invoice->user->id,
'company_id' => $invoice->company_id,
'documentable_type' => Invoice::class,
'documentable_id' => $invoice->id,
]);
RecurringInvoice::factory()->create(['user_id' => $invoice->user->id, 'company_id' => $invoice->company->id, 'client_id' => $invoice->client_id]);
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
}

View File

@ -73,8 +73,9 @@ class DemoMode extends Command
{
set_time_limit(0);
if(config('ninja.is_docker'))
if (config('ninja.is_docker')) {
return;
}
$this->invoice_repo = new InvoiceRepository();
@ -182,7 +183,7 @@ class DemoMode extends Command
'is_admin' => 1,
'is_locked' => 0,
'notifications' => CompanySettings::notificationDefaults(),
// 'permissions' => '',
// 'permissions' => '',
'settings' => null,
]);
@ -217,9 +218,9 @@ class DemoMode extends Command
}
Product::factory()->count(50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'company_id' => $company->id,
]);
$this->info('Creating '.$this->count.' clients');
@ -265,22 +266,22 @@ class DemoMode extends Command
// });
$client = Client::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'company_id' => $company->id,
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
]);
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
]);
ClientContact::factory()->count(rand(1, 5))->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
]);
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
]);
$client->number = $this->getNextClientNumber($client);
@ -299,41 +300,37 @@ class DemoMode extends Command
private function createExpense($client)
{
Expense::factory()->count(rand(1, 5))->create([
'user_id' => $client->user_id,
'client_id' => $client->id,
'company_id' => $client->company_id,
]);
Expense::all()->each(function ($expense){
'user_id' => $client->user_id,
'client_id' => $client->id,
'company_id' => $client->company_id,
]);
Expense::all()->each(function ($expense) {
$expense->number = $this->getNextExpenseNumber($expense);
$expense->save();
});
}
private function createVendor($client, $assigned_user_id = null)
{
$vendor = Vendor::factory()->create([
'user_id' => $client->user_id,
'company_id' => $client->company_id,
]);
'user_id' => $client->user_id,
'company_id' => $client->company_id,
]);
VendorContact::factory()->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company_id,
'is_primary' => 1,
]);
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company_id,
'is_primary' => 1,
]);
VendorContact::factory()->count(rand(1, 5))->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company_id,
'is_primary' => 0,
]);
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company_id,
'is_primary' => 0,
]);
$vendor->number = $this->getNextVendorNumber($vendor);
$vendor->save();
@ -342,25 +339,24 @@ class DemoMode extends Command
private function createTask($client, $assigned_user_id = null)
{
$task = Task::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'client_id' => $client->id
]);
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'client_id' => $client->id,
]);
$task->status_id = TaskStatus::all()->random()->id;
$task->number = $this->getNextTaskNumber($task);
$task->save();
}
private function createProject($client, $assigned_user_id = null)
{
$project = Project::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'client_id' => $client->id,
]);
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'client_id' => $client->id,
]);
$project->number = $this->getNextProjectNumber($project);
$project->save();

View File

@ -64,11 +64,8 @@ class DesignUpdate extends Command
$this->handleOnDb($db);
}
MultiDB::setDB($current_db);
MultiDB::setDB($current_db);
}
}
private function handleOnDb()

View File

@ -71,26 +71,27 @@ class HostedMigrations extends Command
public function handle()
{
$this->buildCache();
if(!MultiDB::userFindAndSetDb($this->option('email'))){
$this->info("Could not find a user with that email address");
if (! MultiDB::userFindAndSetDb($this->option('email'))) {
$this->info('Could not find a user with that email address');
return;
}
$user = User::where('email', $this->option('email'))->first();
if(!$user){
$this->info("There was a problem getting the user, did you set the right DB?");
if (! $user) {
$this->info('There was a problem getting the user, did you set the right DB?');
return;
}
$path = public_path('storage/migrations/import');
$directory = new DirectoryIterator($path);
foreach ($directory as $file) {
if ($file->getExtension() === 'zip') {
$company = $user->companies()->first();
$this->info('Started processing: '.$file->getBasename().' at '.now());
@ -104,14 +105,13 @@ class HostedMigrations extends Command
}
$filename = pathinfo($file->getRealPath(), PATHINFO_FILENAME);
$zip->extractTo(public_path("storage/migrations/{$filename}"));
$zip->close();
$import_file = public_path("storage/migrations/$filename/migration.json");
Import::dispatch($import_file, $user->companies()->first(), $user);
} catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) {
\Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
@ -122,5 +122,4 @@ class HostedMigrations extends Command
}
}
}
}

View File

@ -41,21 +41,16 @@ class HostedUsers extends Command
*/
public function handle()
{
Company::on('db-ninja-01')->each(function ($company){
if(Ninja::isHosted())
Company::on('db-ninja-01')->each(function ($company) {
if (Ninja::isHosted()) {
\Modules\Admin\Jobs\Account\NinjaUser::dispatchNow([], $company);
}
});
Company::on('db-ninja-02')->each(function ($company){
if(Ninja::isHosted())
Company::on('db-ninja-02')->each(function ($company) {
if (Ninja::isHosted()) {
\Modules\Admin\Jobs\Account\NinjaUser::dispatchNow([], $company);
}
});
}
}

View File

@ -77,9 +77,9 @@ class ImportMigrations extends Command
public function handle()
{
$this->buildCache();
$path = $this->option('path') ?? public_path('storage/migrations/import');
$directory = new DirectoryIterator($path);
foreach ($directory as $file) {
@ -98,7 +98,7 @@ class ImportMigrations extends Command
}
$filename = pathinfo($file->getRealPath(), PATHINFO_FILENAME);
$zip->extractTo(public_path("storage/migrations/{$filename}"));
$zip->close();
@ -124,7 +124,7 @@ class ImportMigrations extends Command
$user = User::factory()->create([
'account_id' => $account->id,
'email' => Str::random(10) . "@example.com",
'email' => Str::random(10).'@example.com',
'confirmation_code' => $this->createDbHash($company->db),
]);
@ -137,7 +137,7 @@ class ImportMigrations extends Command
'name' => 'First token',
'token' => Str::random(64),
]);
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,

View File

@ -23,7 +23,6 @@ class MobileLocalization extends Command
*/
protected $description = 'Generate mobile localization resources';
/**
* Create a new command instance.
*
@ -83,9 +82,9 @@ class MobileLocalization extends Command
$text = $resources->$key;
}
$text = str_replace(array('<b>', '</b>'), '', $text);
$text = str_replace(array('<i>', '</i>'), '', $text);
$text = str_replace(array('<strong>', '</strong>'), '', $text);
$text = str_replace(['<b>', '</b>'], '', $text);
$text = str_replace(['<i>', '</i>'], '', $text);
$text = str_replace(['<strong>', '</strong>'], '', $text);
echo "'$key': '$text',\n";
}
@ -103,11 +102,11 @@ class MobileLocalization extends Command
$end = strpos($data, '},', $start);
$data = substr($data, $start, $end - $start - 5);
$data = str_replace("\n", "", $data);
$data = str_replace("\"", "\'", $data);
$data = str_replace("'", "\"", $data);
$data = str_replace("\n", '', $data);
$data = str_replace('"', "\'", $data);
$data = str_replace("'", '"', $data);
return json_decode('{' . rtrim($data, ',') . '}');
return json_decode('{'.rtrim($data, ',').'}');
}
protected function getOptions()
@ -116,5 +115,4 @@ class MobileLocalization extends Command
['type', null, InputOption::VALUE_OPTIONAL, 'Type', null],
];
}
}

View File

@ -52,15 +52,10 @@ class ParallelCheckData extends Command
public function handle()
{
$hash = Str::random(32);
Company::cursor()->each(function ($company) use ($hash){
CheckCompanyData::dispatch($company, $hash)->onQueue('checkdata');
});
$hash = Str::random(32);
Company::cursor()->each(function ($company) use ($hash) {
CheckCompanyData::dispatch($company, $hash)->onQueue('checkdata');
});
}
}
}

View File

@ -50,24 +50,22 @@ class PostUpdate extends Command
info("I wasn't able to migrate the data.");
}
info("finished migrating");
info('finished migrating');
$output = [];
// exec('vendor/bin/composer install --no-dev -o', $output);
info(print_r($output,1));
info("finished running composer install ");
info(print_r($output, 1));
info('finished running composer install ');
try {
Artisan::call('optimize');
} catch (\Exception $e) {
info("I wasn't able to optimize.");
}
info("optimized");
info('optimized');
try {
Artisan::call('view:clear');
@ -75,7 +73,7 @@ class PostUpdate extends Command
info("I wasn't able to clear the views.");
}
info("view cleared");
info('view cleared');
try {
Artisan::call('queue:restart');
@ -83,11 +81,10 @@ class PostUpdate extends Command
info("I wasn't able to restart the queue.");
}
info("queue restarted");
info('queue restarted');
VersionCheck::dispatch();
info("Sent for version check");
info('Sent for version check');
}
}

View File

@ -56,33 +56,19 @@ class ReactBuilder extends Command
$directoryIterator = new \RecursiveDirectoryIterator(public_path('react'), \RecursiveDirectoryIterator::SKIP_DOTS);
foreach (new \RecursiveIteratorIterator($directoryIterator) as $file) {
if(str_contains($file->getFileName(), '.js')) {
if(str_contains($file->getFileName(), 'index.')){
$includes .= '<script type="module" crossorigin src="/react/' . $file->getFileName() . '"></script>'."\n";
}
else{
$includes .= '<link rel="modulepreload" href="/react/' . $file->getFileName() . '">'."\n";
if (str_contains($file->getFileName(), '.js')) {
if (str_contains($file->getFileName(), 'index.')) {
$includes .= '<script type="module" crossorigin src="/react/'.$file->getFileName().'"></script>'."\n";
} else {
$includes .= '<link rel="modulepreload" href="/react/'.$file->getFileName().'">'."\n";
}
}
}
if(str_contains($file->getFileName(), '.css')) {
$includes .= '<link rel="stylesheet" href="/react/' . $file->getFileName() . '">'."\n";
}
if (str_contains($file->getFileName(), '.css')) {
$includes .= '<link rel="stylesheet" href="/react/'.$file->getFileName().'">'."\n";
}
}
file_put_contents(resource_path('views/react/head.blade.php'), $includes);
}
}

View File

@ -42,10 +42,10 @@ class S3Cleanup extends Command
*/
public function handle()
{
if(!Ninja::isHosted())
if (! Ninja::isHosted()) {
return;
}
$c1 = Company::on('db-ninja-01')->pluck('company_key');
$c2 = Company::on('db-ninja-02')->pluck('company_key');
@ -53,23 +53,20 @@ class S3Cleanup extends Command
$directories = Storage::disk(config('filesystems.default'))->directories();
$this->LogMessage("Disk Cleanup");
$this->LogMessage('Disk Cleanup');
foreach($directories as $dir)
{
if(!in_array($dir, $merged))
{
$this->logMessage("Deleting $dir");
foreach ($directories as $dir) {
if (! in_array($dir, $merged)) {
$this->logMessage("Deleting $dir");
/* Ensure we are not deleting the root folder */
if(strlen($dir) > 1)
Storage::disk(config('filesystems.default'))->deleteDirectory($dir);
/* Ensure we are not deleting the root folder */
if (strlen($dir) > 1) {
Storage::disk(config('filesystems.default'))->deleteDirectory($dir);
}
}
$this->logMessage("exiting");
}
}
$this->logMessage('exiting');
}
private function logMessage($str)

View File

@ -29,6 +29,7 @@ use Illuminate\Support\Facades\App;
class SendRemindersCron extends Command
{
use MakesReminders, MakesDates;
/**
* The name and signature of the console command.
*
@ -60,56 +61,49 @@ class SendRemindersCron extends Command
*/
public function handle()
{
Invoice::where('next_send_date', '<=', now()->toDateTimeString())
->whereNull('deleted_at')
->where('is_deleted', 0)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('balance', '>', 0)
->whereHas('client', function ($query) {
$query->where('is_deleted',0)
->where('deleted_at', NULL);
$query->where('is_deleted', 0)
->where('deleted_at', null);
})
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
$query->where('is_disabled', 0);
})
->with('invitations')->cursor()->each(function ($invoice) {
if ($invoice->isPayable()) {
$reminder_template = $invoice->calculateTemplate('invoice');
$invoice->service()->touchReminder($reminder_template)->save();
$invoice = $this->calcLateFee($invoice, $reminder_template);
if ($invoice->isPayable()) {
$reminder_template = $invoice->calculateTemplate('invoice');
$invoice->service()->touchReminder($reminder_template)->save();
$invoice = $this->calcLateFee($invoice, $reminder_template);
//check if this reminder needs to be emailed
if (in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3']) && $invoice->client->getSetting('enable_'.$reminder_template)) {
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
nlog("Firing reminder email for invoice {$invoice->number}");
});
//check if this reminder needs to be emailed
if(in_array($reminder_template, ['reminder1','reminder2','reminder3']) && $invoice->client->getSetting("enable_".$reminder_template))
{
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
nlog("Firing reminder email for invoice {$invoice->number}");
});
if ($invoice->invitations->count() > 0) {
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $reminder_template));
}
}
$invoice->service()->setReminder()->save();
} else {
$invoice->next_send_date = null;
$invoice->save();
}
});
if ($invoice->invitations->count() > 0) {
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $reminder_template));
}
}
$invoice->service()->setReminder()->save();
} else {
$invoice->next_send_date = null;
$invoice->save();
}
});
// SendReminders::dispatchNow();
// SendReminders::dispatchNow();
// $this->webHookOverdueInvoices();
// $this->webHookExpiredQuotes();
}
private function calcLateFee($invoice, $template) :Invoice
private function calcLateFee($invoice, $template) :Invoice
{
$late_fee_amount = 0;
$late_fee_percent = 0;
@ -151,7 +145,6 @@ class SendRemindersCron extends Command
*/
private function setLateFee($invoice, $amount, $percent) :Invoice
{
App::forgetInstance('translator');
$t = app('translator');
$t->replace(Ninja::transformTranslations($invoice->client->getMergedSettings()));
@ -187,49 +180,20 @@ class SendRemindersCron extends Command
$invoice->calc()->getInvoice()->save();
$invoice->fresh();
$invoice->service()->deletePdf();
/* Refresh the client here to ensure the balance is fresh */
$client = $invoice->client;
$client = $client->fresh();
nlog("adjusting client balance and invoice balance by ". ($invoice->balance - $temp_invoice_balance));
nlog('adjusting client balance and invoice balance by '.($invoice->balance - $temp_invoice_balance));
$client->service()->updateBalance($invoice->balance - $temp_invoice_balance)->save();
$invoice->ledger()->updateInvoiceBalance($invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$invoice->number}");
return $invoice;
}
private function webHookOverdueInvoices()
{
if (! config('ninja.db.multi_db_enabled')) {
$this->executeWebhooks();
} else {
@ -240,12 +204,10 @@ class SendRemindersCron extends Command
$this->executeWebhooks();
}
}
}
private function webHookExpiredQuotes()
{
}
private function executeWebhooks()
@ -255,21 +217,18 @@ class SendRemindersCron extends Command
->where('balance', '>', 0)
->whereDate('due_date', '<=', now()->subDays(1)->startOfDay())
->cursor();
$invoices->each(function ($invoice) {
WebhookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company);
});
$quotes = Quote::where('is_deleted', 0)
->where('status_id', Quote::STATUS_SENT)
->whereDate('due_date', '<=', now()->subDays(1)->startOfDay())
->cursor();
$quotes->each(function ($quote) {
WebhookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company);
});
}
}

View File

@ -40,25 +40,17 @@ class SubdomainFill extends Command
*/
public function handle()
{
$c1 = Company::on('db-ninja-01')->whereNull('subdomain')->orWhere('subdomain', '')->get();
$c2 = Company::on('db-ninja-02')->whereNull('subdomain')->orWhere('subdomain', '')->get();
$c1->each(function ($company){
$c1->each(function ($company) {
$company->subdomain = MultiDB::randomSubdomainGenerator();
$company->save();
});
$c2->each(function ($company){
$c2->each(function ($company) {
$company->subdomain = MultiDB::randomSubdomainGenerator();
$company->save();
});
}
}

View File

@ -69,8 +69,9 @@ class TranslationsExport extends Command
'sv',
'th',
'tr_TR',
'zh_TW'
'zh_TW',
];
/**
* Create a new command instance.
*
@ -88,19 +89,14 @@ class TranslationsExport extends Command
*/
public function handle()
{
Storage::makeDirectory(storage_path('lang'));
foreach($this->langs as $lang)
{
foreach ($this->langs as $lang) {
Storage::makeDirectory(storage_path("lang/{$lang}"));
$translations = Lang::getLoader()->load($lang,'texts');
$translations = Lang::getLoader()->load($lang, 'texts');
Storage::put(storage_path("lang/{$lang}/{$lang}.json"), json_encode(Arr::dot($translations), JSON_UNESCAPED_UNICODE));
}
}
}

View File

@ -43,7 +43,6 @@ class TypeCheck extends Command
protected $log = '';
/**
* Create a new command instance.
*
@ -65,91 +64,74 @@ class TypeCheck extends Command
$current_db = config('database.default');
if($this->option('all'))
{
if ($this->option('all')) {
if (! config('ninja.db.multi_db_enabled')) {
$this->checkAll();
$this->checkAll();
} else {
foreach (MultiDB::$dbs as $db)
{
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$this->checkAll();
}
MultiDB::setDB($current_db);
}
}
if($this->option('client_id'))
{
if ($this->option('client_id')) {
$client = MultiDB::findAndSetDbByClientId($this->option('client_id'));
if($client)
if ($client) {
$this->checkClient($client);
else
} else {
$this->logMessage(date('Y-m-d h:i:s').' Could not find this client');
}
}
if($this->option('company_id'))
{
if ($this->option('company_id')) {
$company = MultiDB::findAndSetDbByCompanyId($this->option('company_id'));
if($company)
if ($company) {
$this->checkCompany($company);
else
} else {
$this->logMessage(date('Y-m-d h:i:s').' Could not find this company');
}
}
}
private function checkClient($client)
{
$this->logMessage(date('Y-m-d h:i:s').' Checking Client => ' . $client->present()->name(). " " . $client->id);
$entity_settings = $this->checkSettingType($client->settings);
$entity_settings->md5 = md5(time());
$client->settings = $entity_settings;
$client->save();
$this->logMessage(date('Y-m-d h:i:s').' Checking Client => '.$client->present()->name().' '.$client->id);
$entity_settings = $this->checkSettingType($client->settings);
$entity_settings->md5 = md5(time());
$client->settings = $entity_settings;
$client->save();
}
private function checkCompany($company)
{
$this->logMessage(date('Y-m-d h:i:s').' Checking Company => ' . $company->present()->name(). " " . $company->id);
$company->saveSettings((array)$company->settings, $company);
$this->logMessage(date('Y-m-d h:i:s').' Checking Company => '.$company->present()->name().' '.$company->id);
$company->saveSettings((array) $company->settings, $company);
}
private function checkAll()
{
$this->logMessage(date('Y-m-d h:i:s').' Checking all clients and companies.');
Client::withTrashed()->cursor()->each( function ($client) {
Client::withTrashed()->cursor()->each(function ($client) {
$this->logMessage("Checking client {$client->id}");
$entity_settings = $this->checkSettingType($client->settings);
$entity_settings->md5 = md5(time());
$client->settings = $entity_settings;
$client->save();
});
Company::cursor()->each( function ($company) {
Company::cursor()->each(function ($company) {
$this->logMessage("Checking company {$company->id}");
$company->saveSettings($company->settings, $company);
});
}
private function logMessage($str)
@ -159,4 +141,3 @@ class TypeCheck extends Command
$this->log .= $str."\n";
}
}

View File

@ -51,7 +51,6 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->job(new VersionCheck)->daily();
$schedule->job(new DiskCleanup)->daily()->withoutOverlapping();
@ -78,17 +77,14 @@ class Kernel extends ConsoleKernel
$schedule->job(new SystemMaintenance)->weekly()->withoutOverlapping();
if(Ninja::isSelfHost())
{
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();
$schedule->job(new SendFailedEmails)->daily()->withoutOverlapping();
@ -98,17 +94,13 @@ class Kernel extends ConsoleKernel
$schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('02:05')->withoutOverlapping();
$schedule->command('ninja:s3-cleanup')->dailyAt('23:15')->withoutOverlapping();
}
if (config('queue.default') == 'database' && Ninja::isSelfHost() && config('ninja.internal_queue_enabled') && !config('ninja.is_docker')) {
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();
}
}
/**
@ -118,7 +110,7 @@ class Kernel extends ConsoleKernel
*/
protected function commands()
{
$this->load(__DIR__ . '/Commands');
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}

View File

@ -53,7 +53,8 @@ class AccountPlatform extends GenericMixedMetric
public $string_metric7 = 'ip_address';
public function __construct($string_metric5, $string_metric6, $string_metric7) {
public function __construct($string_metric5, $string_metric6, $string_metric7)
{
$this->string_metric5 = $string_metric5;
$this->string_metric6 = $string_metric6;
$this->string_metric7 = $string_metric7;

View File

@ -52,6 +52,7 @@ class DbQuery extends GenericMixedMetric
public $string_metric6 = 'url';
public $string_metric7 = 'ip_address';
/**
* The counter
* set to 1.
@ -62,7 +63,8 @@ class DbQuery extends GenericMixedMetric
public $double_metric2 = 1;
public function __construct($string_metric5, $string_metric6, $int_metric1, $double_metric2, $string_metric7) {
public function __construct($string_metric5, $string_metric6, $int_metric1, $double_metric2, $string_metric7)
{
$this->int_metric1 = $int_metric1;
$this->string_metric5 = $string_metric5;
$this->string_metric6 = $string_metric6;

View File

@ -71,7 +71,8 @@ class EmailFailure extends GenericMixedMetric
*/
public $string_metric7 = '';
public function __construct($string_metric7) {
public function __construct($string_metric7)
{
$this->string_metric7 = $string_metric7;
}
}

View File

@ -15,7 +15,6 @@ use Turbo124\Beacon\ExampleMetric\GenericMixedMetric;
class EmailSuccess extends GenericMixedMetric
{
/**
* The type of Sample.
*
@ -72,8 +71,8 @@ class EmailSuccess extends GenericMixedMetric
*/
public $string_metric7 = '';
public function __construct($string_metric7) {
public function __construct($string_metric7)
{
$this->string_metric7 = $string_metric7;
}
}

View File

@ -71,7 +71,8 @@ class EmailBounce extends GenericMixedMetric
*/
public $int_metric1 = 1;
public function __construct($string_metric5,$string_metric6,$string_metric7) {
public function __construct($string_metric5, $string_metric6, $string_metric7)
{
$this->string_metric5 = $string_metric5;
$this->string_metric6 = $string_metric6;
$this->string_metric7 = $string_metric7;

View File

@ -71,7 +71,8 @@ class EmailSpam extends GenericMixedMetric
*/
public $int_metric1 = 1;
public function __construct($string_metric5,$string_metric6,$string_metric7) {
public function __construct($string_metric5, $string_metric6, $string_metric7)
{
$this->string_metric5 = $string_metric5;
$this->string_metric6 = $string_metric6;
$this->string_metric7 = $string_metric7;

View File

@ -15,7 +15,6 @@ use Turbo124\Beacon\ExampleMetric\GenericMixedMetric;
class QueueSize extends GenericMixedMetric
{
/**
* The type of Sample.
*
@ -72,8 +71,8 @@ class QueueSize extends GenericMixedMetric
*/
public $string_metric7 = '';
public function __construct($int_metric1) {
public function __construct($int_metric1)
{
$this->int_metric1 = $int_metric1;
}
}

View File

@ -12,7 +12,6 @@
namespace App\DataMapper\Billing;
class SubscriptionContextMapper
{
/**

View File

@ -12,7 +12,6 @@
namespace App\DataMapper\Billing;
class WebhookConfiguration
{
/**
@ -33,11 +32,11 @@ class WebhookConfiguration
/**
* @var string
*/
public $post_purchase_body = '';
public $post_purchase_body = '';
/**
* @var string
*/
*/
public $post_purchase_rest_method = 'POST';
/**

View File

@ -13,89 +13,88 @@ namespace App\DataMapper;
class ClientRegistrationFields
{
public static function generate()
{
$data =
$data =
[
[
'key' => 'first_name',
'required' => true
'required' => true,
],
[
'key' => 'last_name',
'required' => true
'required' => true,
],
[
'key' => 'email',
'required' => true
'required' => true,
],
[
'key' => 'phone',
'required' => false
'required' => false,
],
[
'key' => 'password',
'required' => true
],
'required' => true,
],
[
'key' => 'name',
'required' => false
'required' => false,
],
[
'key' => 'website',
'required' => false
'required' => false,
],
[
'key' => 'address1',
'required' => false
'required' => false,
],
[
'key' => 'address2',
'required' => false
'required' => false,
],
[
'key' => 'city',
'required' => false
'required' => false,
],
[
'key' => 'state',
'required' => false
'required' => false,
],
[
'key' => 'postal_code',
'required' => false
],
'required' => false,
],
[
'key' => 'country_id',
'required' => false
],
'required' => false,
],
[
'key' => 'custom_value1',
'required' => false
],
'required' => false,
],
[
'key' => 'custom_value2',
'required' => false
'required' => false,
],
[
'key' => 'custom_value3',
'required' => false
],
'required' => false,
],
[
'key' => 'custom_value4',
'required' => false
],
'required' => false,
],
[
'key' => 'public_notes',
'required' => false
],
'required' => false,
],
[
'key' => 'vat_number',
'required' => false
],
'required' => false,
],
];
return $data;
}
}
}

View File

@ -30,6 +30,7 @@ class ClientSettings extends BaseSettings
* Settings which which are unique to client settings.
*/
public $industry_id;
public $size_id;
public static $casts = [

View File

@ -28,20 +28,29 @@ class CompanySettings extends BaseSettings
public $lock_invoices = 'off'; //off,when_sent,when_paid //@implemented
public $enable_client_portal_tasks = false; //@ben to implement
public $show_all_tasks_client_portal = 'invoiced'; // all, uninvoiced, invoiced
public $enable_client_portal_password = false; //@implemented
public $enable_client_portal = true; //@implemented
public $enable_client_portal_dashboard = false; // @TODO There currently is no dashboard so this is pending
public $signature_on_pdf = false; //@implemented
public $document_email_attachment = false; //@TODO I assume this is 3rd party attachments on the entity to be included
public $portal_design_id = '1'; //?@deprecated
public $timezone_id = ''; //@implemented
public $date_format_id = ''; //@implemented
public $military_time = false; // @TODOImplemented in Tasks only?
public $language_id = ''; //@implemented
public $show_currency_code = false; //@implemented
public $company_gateway_ids = ''; //@implemented
@ -49,243 +58,379 @@ class CompanySettings extends BaseSettings
public $currency_id = '1'; //@implemented
public $custom_value1 = ''; //@implemented
public $custom_value2 = ''; //@implemented
public $custom_value3 = ''; //@implemented
public $custom_value4 = ''; //@implemented
public $default_task_rate = 0; // @TODO Where do we inject this?
public $payment_terms = ''; //@implemented
public $send_reminders = true; //@TODO
public $custom_message_dashboard = ''; // @TODO There currently is no dashboard so this is pending
public $custom_message_unpaid_invoice = '';
public $custom_message_paid_invoice = '';
public $custom_message_unapproved_quote = '';
public $auto_archive_quote = false; //@implemented
public $auto_convert_quote = true; //@implemented
public $auto_email_invoice = true; //@only used for Recurring Invoices, if set to false, we never send?
public $entity_send_time = 6;
public $inclusive_taxes = false; //@implemented
public $quote_footer = ''; //@implmented
public $translations;
public $counter_number_applied = 'when_saved'; // when_saved , when_sent //@implemented
public $quote_number_applied = 'when_saved'; // when_saved , when_sent //@implemented
/* Counters */
public $invoice_number_pattern = ''; //@implemented
public $invoice_number_counter = 1; //@implemented
public $recurring_invoice_number_pattern = ''; //@implemented
public $recurring_invoice_number_counter = 1; //@implemented
public $quote_number_pattern = ''; //@implemented
public $quote_number_counter = 1; //@implemented
public $client_number_pattern = ''; //@implemented
public $client_number_counter = 1; //@implemented
public $credit_number_pattern = ''; //@implemented
public $credit_number_counter = 1; //@implemented
public $task_number_pattern = ''; //@implemented
public $task_number_counter = 1; //@implemented
public $expense_number_pattern = ''; //@implemented
public $expense_number_counter = 1; //@implemented
public $recurring_expense_number_pattern = '';
public $recurring_expense_number_counter = 1;
public $recurring_quote_number_pattern = '';
public $recurring_quote_number_counter = 1;
public $vendor_number_pattern = ''; //@implemented
public $vendor_number_counter = 1; //@implemented
public $ticket_number_pattern = ''; //@implemented
public $ticket_number_counter = 1; //@implemented
public $payment_number_pattern = ''; //@implemented
public $payment_number_counter = 1; //@implemented
public $project_number_pattern = ''; //@implemented
public $project_number_counter = 1; //@implemented
public $purchase_order_number_pattern = ''; //@implemented
public $purchase_order_number_counter = 1; //@implemented
public $shared_invoice_quote_counter = false; //@implemented
public $shared_invoice_credit_counter = false; //@implemented
public $recurring_number_prefix = ''; //@implemented
public $reset_counter_frequency_id = '0'; //@implemented
public $reset_counter_date = ''; //@implemented
public $counter_padding = 4; //@implemented
public $auto_bill = 'off'; //off,always,optin,optout //@implemented
public $auto_bill_date = 'on_due_date'; // on_due_date , on_send_date //@implemented
public $invoice_terms = ''; //@implemented
public $quote_terms = ''; //@implemented
public $invoice_taxes = 0; // ? used in AP only?
public $invoice_design_id = 'Wpmbk5ezJn'; //@implemented
public $quote_design_id = 'Wpmbk5ezJn'; //@implemented
public $credit_design_id = 'Wpmbk5ezJn'; //@implemented
public $purchase_order_design_id = 'Wpmbk5ezJn';
public $purchase_order_footer = ''; //@implemented
public $purchase_order_terms = ''; //@implemented
public $purchase_order_public_notes = ''; //@implemented
public $require_purchase_order_signature = false; //@TODO ben to confirm
public $invoice_footer = ''; //@implemented
public $credit_footer = ''; //@implemented
public $credit_terms = ''; //@implemented
public $invoice_labels = ''; //@TODO used in AP only?
public $tax_name1 = ''; //@TODO where do we use this?
public $tax_rate1 = 0; //@TODO where do we use this?
public $tax_name2 = ''; //@TODO where do we use this?
public $tax_rate2 = 0; //@TODO where do we use this?
public $tax_name3 = ''; //@TODO where do we use this?
public $tax_rate3 = 0; //@TODO where do we use this?
public $payment_type_id = '0'; //@TODO where do we use this?
public $valid_until = ''; //@implemented
public $show_accept_invoice_terms = false; //@TODO ben to confirm
public $show_accept_quote_terms = false; //@TODO ben to confirm
public $require_invoice_signature = false; //@TODO ben to confirm
public $require_quote_signature = false; //@TODO ben to confirm
//email settings
public $email_sending_method = 'default'; //enum 'default','gmail','office365' //@implemented
public $gmail_sending_user_id = '0'; //@implemented
public $reply_to_email = ''; //@implemented
public $reply_to_name = ''; //@implemented
public $bcc_email = ''; //@TODO
public $pdf_email_attachment = false; //@implemented
public $ubl_email_attachment = false; //@implemented
public $email_style = 'light'; //plain, light, dark, custom //@implemented
public $email_style_custom = ''; //the template itself //@implemented
public $email_subject_invoice = ''; //@implemented
public $email_subject_quote = ''; //@implemented
public $email_subject_credit = ''; //@implemented
public $email_subject_payment = ''; //@implemented
public $email_subject_payment_partial = ''; //@implemented
public $email_subject_statement = ''; //@implemented
public $email_subject_purchase_order = ''; //@implemented
public $email_template_purchase_order = ''; //@implemented
public $email_template_invoice = ''; //@implemented
public $email_template_credit = ''; //@implemented
public $email_template_quote = ''; //@implemented
public $email_template_payment = ''; //@implemented
public $email_template_payment_partial = ''; //@implemented
public $email_template_statement = ''; //@implemented
public $email_subject_reminder1 = ''; //@implemented
public $email_subject_reminder2 = ''; //@implemented
public $email_subject_reminder3 = ''; //@implemented
public $email_subject_reminder_endless = ''; //@implemented
public $email_template_reminder1 = ''; //@implemented
public $email_template_reminder2 = ''; //@implemented
public $email_template_reminder3 = ''; //@implemented
public $email_template_reminder_endless = ''; //@implemented
public $email_signature = ''; //@implemented
public $enable_email_markup = true; //@TODO -
public $email_subject_custom1 = ''; //@TODO
public $email_subject_custom2 = ''; //@TODO
public $email_subject_custom3 = ''; //@TODO
public $email_template_custom1 = ''; //@TODO
public $email_template_custom2 = ''; //@TODO
public $email_template_custom3 = ''; //@TODO
public $enable_reminder1 = false; //@implmemented
public $enable_reminder2 = false; //@implmemented
public $enable_reminder3 = false; //@implmemented
public $enable_reminder_endless = false; //@implmemented
public $num_days_reminder1 = 0;//@implmemented
public $num_days_reminder2 = 0;//@implmemented
public $num_days_reminder3 = 0;//@implmemented
public $num_days_reminder1 = 0; //@implmemented
public $num_days_reminder2 = 0; //@implmemented
public $num_days_reminder3 = 0; //@implmemented
public $schedule_reminder1 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
public $schedule_reminder3 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
public $reminder_send_time = 0; //number of seconds from UTC +0 to send reminders @TODO
public $late_fee_amount1 = 0; //@implemented
public $late_fee_amount2 = 0; //@implemented
public $late_fee_amount3 = 0; //@implemented
public $late_fee_percent1 = 0; //@implemented
public $late_fee_percent2 = 0; //@implemented
public $late_fee_percent3 = 0; //@implemented
public $endless_reminder_frequency_id = '0'; //@implemented
public $late_fee_endless_amount = 0; //@implemented
public $late_fee_endless_percent = 0; //@implemented
public $client_online_payment_notification = true; //@todo implement in notifications check this bool prior to sending payment notification to client
public $client_manual_payment_notification = true; //@todo implement in notifications check this bool prior to sending manual payment notification to client
/* Company Meta data that we can use to build sub companies*/
public $name = ''; //@implemented
public $company_logo = ''; //@implemented
public $website = ''; //@implemented
public $address1 = ''; //@implemented
public $address2 = ''; //@implemented
public $city = ''; //@implemented
public $state = ''; //@implemented
public $postal_code = ''; //@implemented
public $phone = ''; //@implemented
public $email = ''; //@implemented
public $country_id; //@implemented
public $vat_number = ''; //@implemented
public $id_number = ''; //@implemented
public $page_size = 'A4'; //Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6
public $page_layout = 'portrait';
public $font_size = 7; //@implemented
public $primary_font = 'Roboto';
public $secondary_font = 'Roboto';
public $primary_color = '#298AAB';
public $secondary_color = '#7081e0';
public $page_numbering = false;
public $page_numbering_alignment = 'C'; //C,R,L
public $hide_paid_to_date = false; //@TODO where?
public $embed_documents = false; //@TODO where?
public $all_pages_header = false; //@deprecated 31-05-2021
public $all_pages_footer = false; //@deprecated 31-05-2021
public $pdf_variables = ''; //@implemented
public $portal_custom_head = ''; //@TODO @BEN
public $portal_custom_css = ''; //@TODO @BEN
public $portal_custom_footer = ''; //@TODO @BEN
public $portal_custom_js = ''; //@TODO @BEN
public $client_can_register = false; //@deorecated 04/06/2021
public $client_portal_terms = ''; //@TODO @BEN
public $client_portal_privacy_policy = ''; //@TODO @BEN
public $client_portal_enable_uploads = false; //@implemented
public $client_portal_allow_under_payment = false; //@implemented
public $client_portal_under_payment_minimum = 0; //@implemented
public $client_portal_allow_over_payment = false; //@implemented
public $use_credits_payment = 'off'; //always, option, off //@implemented
public $hide_empty_columns_on_pdf = false;
public $email_from_name = '';
public $auto_archive_invoice_cancelled = false;
public static $casts = [

View File

@ -26,12 +26,11 @@ class DefaultSettings extends BaseSettings
/**
* @return stdClass
*
*/
public static function userSettings() : stdClass
{
return (object) [
// class_basename(User::class) => self::userSettingsObject(),
// class_basename(User::class) => self::userSettingsObject(),
];
}
@ -41,7 +40,7 @@ class DefaultSettings extends BaseSettings
private static function userSettingsObject() : stdClass
{
return (object) [
// 'per_page' => self::$per_page,
// 'per_page' => self::$per_page,
];
}
}

View File

@ -162,11 +162,9 @@ class EmailTemplateDefaults
public static function emailPurchaseOrderTemplate()
{
$purchase_order_message = '<p>$vendor<br><br>'.self::transformText('purchase_order_message').'</p><div class="center">$view_button</div>';
return $purchase_order_message;
}
public static function emailPaymentTemplate()
@ -249,6 +247,6 @@ class EmailTemplateDefaults
{
//preformat the string, removing trailing colons.
return str_replace(':', '$', rtrim( ctrans('texts.'.$string), ":"));
return str_replace(':', '$', rtrim(ctrans('texts.'.$string), ':'));
}
}

View File

@ -20,67 +20,123 @@ use stdClass;
class FreeCompanySettings extends BaseSettings
{
use MakesHash;
/*Group settings based on functionality*/
public $credit_design_id = 'VolejRejNm';
public $client_number_pattern = '';
public $client_number_counter = 1;
public $credit_number_pattern = '';
public $credit_number_counter = 1;
public $currency_id = '1';
public $custom_value1 = '';
public $custom_value2 = '';
public $custom_value3 = '';
public $custom_value4 = '';
public $date_format_id = '';
// public $enabled_item_tax_rates = 0;
public $expense_number_pattern = '';
public $expense_number_counter = 1;
public $inclusive_taxes = false;
public $invoice_design_id = 'VolejRejNm';
public $invoice_number_pattern = '';
public $invoice_number_counter = 1;
public $invoice_taxes = 0;
public $language_id = '';
public $military_time = false;
public $payment_number_pattern = '';
public $payment_number_counter = 1;
public $payment_terms = '';
public $payment_type_id = '0';
public $portal_design_id = '1';
public $quote_design_id = 'VolejRejNm';
public $quote_number_pattern = '';
public $quote_number_counter = 1;
public $timezone_id = '';
public $show_currency_code = false;
public $company_gateway_ids = '';
public $task_number_pattern = '';
public $task_number_counter = 1;
public $tax_name1 = '';
public $tax_rate1 = 0;
public $tax_name2 = '';
public $tax_rate2 = 0;
public $tax_name3 = '';
public $tax_rate3 = 0;
public $ticket_number_pattern = '';
public $ticket_number_counter = 1;
public $translations;
public $vendor_number_pattern = '';
public $vendor_number_counter = 1;
/* Company Meta data that we can use to build sub companies*/
public $address1 = '';
public $address2 = '';
public $city = '';
public $company_logo = '';
public $country_id;
public $email = '';
public $id_number = '';
public $name = '';
public $phone = '';
public $postal_code = '';
public $state = '';
public $vat_number = '';
public $website = '';
public static $casts = [

View File

@ -22,8 +22,7 @@ use App\Models\TransactionEvent;
*/
class BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::INVOICE_MARK_PAID;
public $event_id = TransactionEvent::INVOICE_MARK_PAID;
public array $model = [
'client_id',
@ -56,7 +55,7 @@ class BaseTransaction implements TransactionInterface
{
// $invoice = $data['invoice'];
// $payment = $data['payment'];
// $client = $data['client'];
// $client = $data['client'];
// $credit = $data['credit'];
// $payment_request = $data['payment']['payment_request'];
// $metadata = $data['metadata'];
@ -95,6 +94,5 @@ class BaseTransaction implements TransactionInterface
// 'credit_status' => $credit?->status_id,
// 'timestamp' => time(),
// ];
}
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class ClientStatusTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::CLIENT_STATUS;
public $event_id = TransactionEvent::CLIENT_STATUS;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class GatewayPaymentMadeTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::GATEWAY_PAYMENT_MADE;
public $event_id = TransactionEvent::GATEWAY_PAYMENT_MADE;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class InvoiceCancelledTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::INVOICE_CANCELLED;
public $event_id = TransactionEvent::INVOICE_CANCELLED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class InvoiceDeletedTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::INVOICE_DELETED;
public $event_id = TransactionEvent::INVOICE_DELETED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class InvoiceFeeAppliedTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::INVOICE_FEE_APPLIED;
public $event_id = TransactionEvent::INVOICE_FEE_APPLIED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class InvoicePaymentTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::INVOICE_PAYMENT_APPLIED;
public $event_id = TransactionEvent::INVOICE_PAYMENT_APPLIED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class InvoiceReversalTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::INVOICE_REVERSED;
public $event_id = TransactionEvent::INVOICE_REVERSED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class InvoiceUpdatedTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::INVOICE_UPDATED;
public $event_id = TransactionEvent::INVOICE_UPDATED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class MarkPaidTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::INVOICE_MARK_PAID;
public $event_id = TransactionEvent::INVOICE_MARK_PAID;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class PaymentAppliedTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::PAYMENT_APPLIED;
public $event_id = TransactionEvent::PAYMENT_APPLIED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class PaymentDeletedTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::PAYMENT_DELETED;
public $event_id = TransactionEvent::PAYMENT_DELETED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class PaymentFailedTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::PAYMENT_FAILED;
public $event_id = TransactionEvent::PAYMENT_FAILED;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class PaymentMadeTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::PAYMENT_MADE;
public $event_id = TransactionEvent::PAYMENT_MADE;
}

View File

@ -22,7 +22,5 @@ use App\Models\TransactionEvent;
*/
class PaymentRefundedTransaction extends BaseTransaction implements TransactionInterface
{
public $event_id = TransactionEvent::PAYMENT_REFUND;
public $event_id = TransactionEvent::PAYMENT_REFUND;
}

View File

@ -28,7 +28,7 @@ class ClientWasRestored
public $client;
public $fromDeleted;
public $company;
public $event_vars;

View File

@ -28,6 +28,7 @@ class CreditWasEmailed
public $event_vars;
public $template;
/**
* Create a new event instance.
*

View File

@ -21,6 +21,7 @@ use Illuminate\Queue\SerializesModels;
class CreditWasMarkedSent
{
use SerializesModels;
/**
* @var Credit
*/

View File

@ -32,6 +32,7 @@ class CreditWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -32,6 +32,7 @@ class DesignWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -32,6 +32,7 @@ class DocumentWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -32,6 +32,7 @@ class ExpenseWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -32,7 +32,7 @@ class InvoiceWasRestored
public $company;
public $event_vars;
/**
* Create a new event instance.
*

View File

@ -26,8 +26,11 @@ class PaymentWasRestored
* @var Payment
*/
public $payment;
public $fromDeleted;
public $company;
public $event_vars;
/**

View File

@ -32,6 +32,7 @@ class ProductWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -34,6 +34,7 @@ class PurchaseOrderWasAccepted
public $event_vars;
public $contact;
/**
* Create a new event instance.
*

View File

@ -32,6 +32,7 @@ class PurchaseOrderWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -30,6 +30,7 @@ class QuoteWasEmailed
public $event_vars;
public $template;
/**
* Create a new event instance.
*

View File

@ -29,6 +29,7 @@ class QuoteWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -32,6 +32,7 @@ class RecurringExpenseWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -32,7 +32,7 @@ class RecurringInvoiceWasRestored
public $company;
public $event_vars;
/**
* Create a new event instance.
*

View File

@ -32,7 +32,7 @@ class RecurringQuoteWasRestored
public $company;
public $event_vars;
/**
* Create a new event instance.
*

View File

@ -2,8 +2,8 @@
namespace App\Events\Subscription;
use App\Models\Subscription;
use App\Models\Company;
use App\Models\Subscription;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;

View File

@ -32,6 +32,7 @@ class SubscriptionWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -32,6 +32,7 @@ class TaskWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -32,6 +32,7 @@ class VendorWasRestored
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*

View File

@ -77,37 +77,33 @@ class Handler extends ExceptionHandler
{
if (! Schema::hasTable('accounts')) {
info('account table not found');
return;
}
if(Ninja::isHosted() && !($exception instanceof ValidationException)){
if (Ninja::isHosted() && ! ($exception instanceof ValidationException)) {
app('sentry')->configureScope(function (Scope $scope): void {
$name = 'hosted@invoiceninja.com';
if(auth()->guard('contact') && auth()->guard('contact')->user()){
$name = "Contact = ".auth()->guard('contact')->user()->email;
if (auth()->guard('contact') && auth()->guard('contact')->user()) {
$name = 'Contact = '.auth()->guard('contact')->user()->email;
$key = auth()->guard('contact')->user()->company->account->key;
}
elseif (auth()->guard('user') && auth()->guard('user')->user()){
$name = "Admin = ".auth()->guard('user')->user()->email;
} elseif (auth()->guard('user') && auth()->guard('user')->user()) {
$name = 'Admin = '.auth()->guard('user')->user()->email;
$key = auth()->user()->account->key;
}
else
} else {
$key = 'Anonymous';
$scope->setUser([
'id' => $key,
'email' => 'hosted@invoiceninja.com',
'name' => $name,
]);
}
$scope->setUser([
'id' => $key,
'email' => 'hosted@invoiceninja.com',
'name' => $name,
]);
});
app('sentry')->captureException($exception);
}
elseif (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->captureException($exception);
} elseif (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->configureScope(function (Scope $scope): void {
if (auth()->guard('contact') && auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) {
$scope->setUser([
@ -130,28 +126,33 @@ class Handler extends ExceptionHandler
}
parent::report($exception);
}
private function validException($exception)
{
if (strpos($exception->getMessage(), 'file_put_contents') !== false)
if (strpos($exception->getMessage(), 'file_put_contents') !== false) {
return false;
}
if (strpos($exception->getMessage(), 'Permission denied') !== false)
return false;
if (strpos($exception->getMessage(), 'flock') !== false)
if (strpos($exception->getMessage(), 'Permission denied') !== false) {
return false;
}
if (strpos($exception->getMessage(), 'expects parameter 1 to be resource') !== false)
if (strpos($exception->getMessage(), 'flock') !== false) {
return false;
}
if (strpos($exception->getMessage(), 'fwrite()') !== false)
if (strpos($exception->getMessage(), 'expects parameter 1 to be resource') !== false) {
return false;
if(strpos($exception->getMessage(), 'LockableFile') !== false)
}
if (strpos($exception->getMessage(), 'fwrite()') !== false) {
return false;
}
if (strpos($exception->getMessage(), 'LockableFile') !== false) {
return false;
}
return true;
}
@ -168,11 +169,11 @@ class Handler extends ExceptionHandler
{
if ($exception instanceof ModelNotFoundException && $request->expectsJson()) {
return response()->json(['message'=>$exception->getMessage()], 400);
}elseif($exception instanceof InternalPDFFailure && $request->expectsJson()){
} elseif ($exception instanceof InternalPDFFailure && $request->expectsJson()) {
return response()->json(['message' => $exception->getMessage()], 500);
}elseif($exception instanceof PhantomPDFFailure && $request->expectsJson()){
} elseif ($exception instanceof PhantomPDFFailure && $request->expectsJson()) {
return response()->json(['message' => $exception->getMessage()], 500);
}elseif($exception instanceof FilePermissionsFailure) {
} elseif ($exception instanceof FilePermissionsFailure) {
return response()->json(['message' => $exception->getMessage()], 500);
} elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) {
return response()->json(['message'=>'Too many requests'], 429);
@ -202,7 +203,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);
}

View File

@ -13,7 +13,7 @@ class PaymentFailed extends Exception
public function render($request)
{
if (auth()->user() || ($request->has('cko-session-id') && $request->query('cko-session-id') )) {
if (auth()->user() || ($request->has('cko-session-id') && $request->query('cko-session-id'))) {
return render('gateways.unsuccessful', [
'message' => $this->getMessage(),
'code' => $this->getCode(),

View File

@ -30,12 +30,12 @@ class PaymentRefundFailed extends Exception
// $msg = 'Unable to refund the transaction';
$msg = ctrans('texts.warning_local_refund');
if($this->getMessage() && strlen($this->getMessage()) >=1 )
if ($this->getMessage() && strlen($this->getMessage()) >= 1) {
$msg = $this->getMessage();
}
return response()->json([
'message' => $msg,
], 401);
'message' => $msg,
], 401);
}
}

View File

@ -13,12 +13,9 @@ class SystemError extends Exception
public function render($request)
{
return view('errors.guest', [
'message' => $this->getMessage(),
'code' => $this->getCode(),
]);
}
}

View File

@ -15,28 +15,22 @@ use Illuminate\Support\Carbon;
class BaseExport
{
protected function addDateRange($query)
{
$date_range = $this->input['date_range'];
if(array_key_exists('date_key', $this->input) && strlen($this->input['date_key']) > 1)
if (array_key_exists('date_key', $this->input) && strlen($this->input['date_key']) > 1) {
$this->date_key = $this->input['date_key'];
try{
$custom_start_date = Carbon::parse($this->input['start_date']);
$custom_end_date = Carbon::parse($this->input['end_date']);
}
catch(\Exception $e){
try {
$custom_start_date = Carbon::parse($this->input['start_date']);
$custom_end_date = Carbon::parse($this->input['end_date']);
} catch (\Exception $e) {
$custom_start_date = now()->startOfYear();
$custom_end_date = now();
}
switch ($date_range) {
case 'all':
@ -61,26 +55,23 @@ class BaseExport
return $query->whereBetween($this->date_key, [now()->startOfYear(), now()])->orderBy($this->date_key, 'ASC');
}
}
protected function buildHeader() :array
{
$header = [];
foreach($this->input['report_keys'] as $value){
foreach ($this->input['report_keys'] as $value) {
$key = array_search($value, $this->entity_keys);
$key = array_search ($value, $this->entity_keys);
$key = str_replace("item.", "", $key);
$key = str_replace("invoice.", "", $key);
$key = str_replace("client.", "", $key);
$key = str_replace("contact.", "", $key);
$key = str_replace('item.', '', $key);
$key = str_replace('invoice.', '', $key);
$key = str_replace('client.', '', $key);
$key = str_replace('contact.', '', $key);
$header[] = ctrans("texts.{$key}");
}
return $header;
}
}
}

View File

@ -17,9 +17,9 @@ 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;
use Illuminate\Support\Carbon;
class ClientExport extends BaseExport
{
@ -95,7 +95,6 @@ class ClientExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -105,8 +104,9 @@ class ClientExport 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());
@ -114,69 +114,65 @@ class ClientExport extends BaseExport
$query = Client::query()->with('contacts')
->withTrashed()
->where('company_id', $this->company->id)
->where('is_deleted',0);
->where('is_deleted', 0);
$query = $this->addDateRange($query);
$query->cursor()
->each(function ($client){
$this->csv->insertOne($this->buildRow($client));
});
return $this->csv->toString();
->each(function ($client) {
$this->csv->insertOne($this->buildRow($client));
});
return $this->csv->toString();
}
private function buildRow(Client $client) :array
{
$transformed_contact = false;
$transformed_client = $this->client_transformer->transform($client);
if($contact = $client->contacts()->first())
if ($contact = $client->contacts()->first()) {
$transformed_contact = $this->contact_transformer->transform($contact);
}
$entity = [];
foreach(array_values($this->input['report_keys']) as $key){
foreach (array_values($this->input['report_keys']) as $key) {
$parts = explode('.', $key);
$parts = explode(".",$key);
$keyval = array_search($key, $this->entity_keys);
if($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) {
if ($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) {
$entity[$keyval] = $transformed_client[$parts[1]];
}
elseif($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) {
} elseif ($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) {
$entity[$keyval] = $transformed_contact[$parts[1]];
} else {
$entity[$keyval] = '';
}
else
$entity[$keyval] = "";
}
return $this->decorateAdvancedFields($client, $entity);
}
private function decorateAdvancedFields(Client $client, array $entity) :array
{
if (in_array('client.country_id', $this->input['report_keys'])) {
$entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : '';
}
if(in_array('client.country_id', $this->input['report_keys']))
$entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : "";
if (in_array('client.shipping_country_id', $this->input['report_keys'])) {
$entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : '';
}
if(in_array('client.shipping_country_id', $this->input['report_keys']))
$entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : "";
if(in_array('client.currency', $this->input['report_keys']))
if (in_array('client.currency', $this->input['report_keys'])) {
$entity['currency'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code;
}
if(in_array('client.industry_id', $this->input['report_keys']))
$entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : "";
if (in_array('client.industry_id', $this->input['report_keys'])) {
$entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : '';
}
return $entity;
}
}

View File

@ -91,7 +91,6 @@ class ContactExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -101,8 +100,9 @@ class ContactExport 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());
@ -112,19 +112,15 @@ class ContactExport extends BaseExport
$query = $this->addDateRange($query);
$query->cursor()->each(function ($contact){
$this->csv->insertOne($this->buildRow($contact));
$query->cursor()->each(function ($contact) {
$this->csv->insertOne($this->buildRow($contact));
});
return $this->csv->toString();
return $this->csv->toString();
}
private function buildRow(ClientContact $contact) :array
{
$transformed_contact = false;
$transformed_client = $this->client_transformer->transform($contact->client);
@ -132,41 +128,40 @@ class ContactExport extends BaseExport
$entity = [];
foreach(array_values($this->input['report_keys']) as $key){
$parts = explode(".",$key);
foreach (array_values($this->input['report_keys']) as $key) {
$parts = explode('.', $key);
$keyval = array_search($key, $this->entity_keys);
if($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) {
if ($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) {
$entity[$keyval] = $transformed_client[$parts[1]];
}
elseif($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) {
} elseif ($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) {
$entity[$keyval] = $transformed_contact[$parts[1]];
} else {
$entity[$keyval] = '';
}
else
$entity[$keyval] = "";
}
return $this->decorateAdvancedFields($contact->client, $entity);
}
private function decorateAdvancedFields(Client $client, array $entity) :array
{
if (in_array('client.country_id', $this->input['report_keys'])) {
$entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : '';
}
if(in_array('client.country_id', $this->input['report_keys']))
$entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : "";
if (in_array('client.shipping_country_id', $this->input['report_keys'])) {
$entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : '';
}
if(in_array('client.shipping_country_id', $this->input['report_keys']))
$entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : "";
if(in_array('client.currency', $this->input['report_keys']))
if (in_array('client.currency', $this->input['report_keys'])) {
$entity['currency'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code;
}
if(in_array('client.industry_id', $this->input['report_keys']))
$entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : "";
if (in_array('client.industry_id', $this->input['report_keys'])) {
$entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : '';
}
return $entity;
}
}

View File

@ -65,7 +65,7 @@ class CreditExport extends BaseExport
'tax_rate3' => 'tax_rate3',
'terms' => 'terms',
'total_taxes' => 'total_taxes',
'currency' => 'currency'
'currency' => 'currency',
];
private array $decorate_keys = [
@ -84,7 +84,6 @@ class CreditExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -94,71 +93,69 @@ class CreditExport 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());
$query = Credit::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 ($credit){
$this->csv->insertOne($this->buildRow($credit));
});
return $this->csv->toString();
->each(function ($credit) {
$this->csv->insertOne($this->buildRow($credit));
});
return $this->csv->toString();
}
private function buildRow(Credit $credit) :array
{
$transformed_credit = $this->credit_transformer->transform($credit);
$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_credit))
if (array_key_exists($key, $transformed_credit)) {
$entity[$keyval] = $transformed_credit[$key];
else
} else {
$entity[$keyval] = '';
}
}
return $this->decorateAdvancedFields($credit, $entity);
}
private function decorateAdvancedFields(Credit $credit, array $entity) :array
{
if (in_array('country_id', $this->input['report_keys'])) {
$entity['country'] = $credit->client->country ? ctrans("texts.country_{$credit->client->country->name}") : '';
}
if(in_array('country_id', $this->input['report_keys']))
$entity['country'] = $credit->client->country ? ctrans("texts.country_{$credit->client->country->name}") : "";
if (in_array('currency_id', $this->input['report_keys'])) {
$entity['currency_id'] = $credit->client->currency() ? $credit->client->currency()->code : $invoice->company->currency()->code;
}
if(in_array('currency_id', $this->input['report_keys']))
$entity['currency_id'] = $credit->client->currency() ? $credit->client->currency()->code : $invoice->company->currency()->code;;
if (in_array('invoice_id', $this->input['report_keys'])) {
$entity['invoice'] = $credit->invoice ? $credit->invoice->number : '';
}
if(in_array('invoice_id', $this->input['report_keys']))
$entity['invoice'] = $credit->invoice ? $credit->invoice->number : "";
if(in_array('client_id', $this->input['report_keys']))
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $credit->client->present()->name();
}
if(in_array('status_id',$this->input['report_keys']))
if (in_array('status_id', $this->input['report_keys'])) {
$entity['status'] = $credit->stringStatus($credit->status_id);
}
return $entity;
}
}

View File

@ -52,7 +52,6 @@ class DocumentExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -62,8 +61,9 @@ class DocumentExport 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());
@ -73,47 +73,41 @@ class DocumentExport extends BaseExport
$query = $this->addDateRange($query);
$query->cursor()
->each(function ($entity){
$this->csv->insertOne($this->buildRow($entity));
});
return $this->csv->toString();
->each(function ($entity) {
$this->csv->insertOne($this->buildRow($entity));
});
return $this->csv->toString();
}
private function buildRow(Document $document) :array
{
$transformed_entity = $this->entity_transformer->transform($document);
$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_entity))
if (array_key_exists($key, $transformed_entity)) {
$entity[$keyval] = $transformed_entity[$key];
else
$entity[$keyval] = '';
} else {
$entity[$keyval] = '';
}
}
return $this->decorateAdvancedFields($document, $entity);
}
private function decorateAdvancedFields(Document $document, array $entity) :array
{
if(in_array('record_type', $this->input['report_keys']))
if (in_array('record_type', $this->input['report_keys'])) {
$entity['record_type'] = class_basename($document->documentable);
}
// if(in_array('record_name', $this->input['report_keys']))
// $entity['record_name'] = $document->hashed_id;
return $entity;
}
}

View File

@ -82,7 +82,6 @@ class ExpenseExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -92,8 +91,9 @@ class ExpenseExport 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());
@ -102,69 +102,67 @@ class ExpenseExport extends BaseExport
->with('client')
->withTrashed()
->where('company_id', $this->company->id)
->where('is_deleted',0);
->where('is_deleted', 0);
$query = $this->addDateRange($query);
$query->cursor()
->each(function ($expense){
$this->csv->insertOne($this->buildRow($expense));
});
return $this->csv->toString();
->each(function ($expense) {
$this->csv->insertOne($this->buildRow($expense));
});
return $this->csv->toString();
}
private function buildRow(Expense $expense) :array
{
$transformed_expense = $this->expense_transformer->transform($expense);
$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_expense))
if (array_key_exists($key, $transformed_expense)) {
$entity[$keyval] = $transformed_expense[$key];
else
} else {
$entity[$keyval] = '';
}
}
return $this->decorateAdvancedFields($expense, $entity);
}
private function decorateAdvancedFields(Expense $expense, array $entity) :array
{
if(in_array('currency_id', $this->input['report_keys']))
$entity['currency'] = $expense->currency ? $expense->currency->code : "";
if (in_array('currency_id', $this->input['report_keys'])) {
$entity['currency'] = $expense->currency ? $expense->currency->code : '';
}
if(in_array('client_id', $this->input['report_keys']))
$entity['client'] = $expense->client ? $expense->client->present()->name() : "";
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $expense->client ? $expense->client->present()->name() : '';
}
if(in_array('invoice_id', $this->input['report_keys']))
$entity['invoice'] = $expense->invoice ? $expense->invoice->number : "";
if (in_array('invoice_id', $this->input['report_keys'])) {
$entity['invoice'] = $expense->invoice ? $expense->invoice->number : '';
}
if(in_array('category_id', $this->input['report_keys']))
$entity['category'] = $expense->category ? $expense->category->name : "";
if (in_array('category_id', $this->input['report_keys'])) {
$entity['category'] = $expense->category ? $expense->category->name : '';
}
if(in_array('vendor_id', $this->input['report_keys']))
$entity['vendor'] = $expense->vendor ? $expense->vendor->name : "";
if (in_array('vendor_id', $this->input['report_keys'])) {
$entity['vendor'] = $expense->vendor ? $expense->vendor->name : '';
}
if(in_array('payment_type_id', $this->input['report_keys']))
$entity['payment_type'] = $expense->payment_type ? $expense->payment_type->name : "";
if(in_array('project_id', $this->input['report_keys']))
$entity['project'] = $expense->project ? $expense->project->name : "";
if (in_array('payment_type_id', $this->input['report_keys'])) {
$entity['payment_type'] = $expense->payment_type ? $expense->payment_type->name : '';
}
if (in_array('project_id', $this->input['report_keys'])) {
$entity['project'] = $expense->project ? $expense->project->name : '';
}
return $entity;
}
}

View File

@ -63,7 +63,7 @@ class InvoiceExport extends BaseExport
'tax_rate3' => 'tax_rate3',
'terms' => 'terms',
'total_taxes' => 'total_taxes',
'currency_id' => 'currency_id'
'currency_id' => 'currency_id',
];
private array $decorate_keys = [
@ -84,7 +84,6 @@ class InvoiceExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -94,9 +93,10 @@ class InvoiceExport 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());
@ -104,57 +104,55 @@ class InvoiceExport extends BaseExport
->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){
$this->csv->insertOne($this->buildRow($invoice));
});
return $this->csv->toString();
->each(function ($invoice) {
$this->csv->insertOne($this->buildRow($invoice));
});
return $this->csv->toString();
}
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('country_id', $this->input['report_keys']))
$entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : "";
if (in_array('country_id', $this->input['report_keys'])) {
$entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : '';
}
if(in_array('currency_id', $this->input['report_keys']))
if (in_array('currency_id', $this->input['report_keys'])) {
$entity['currency_id'] = $invoice->client->currency() ? $invoice->client->currency()->code : $invoice->company->currency()->code;
}
if(in_array('client_id', $this->input['report_keys']))
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $invoice->client->present()->name();
}
if(in_array('status_id',$this->input['report_keys']))
if (in_array('status_id', $this->input['report_keys'])) {
$entity['status'] = $invoice->stringStatus($invoice->status_id);
}
return $entity;
}
}

View File

@ -99,7 +99,6 @@ class InvoiceItemExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -109,27 +108,25 @@ 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());
$query = Invoice::query()
->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)
@ -138,76 +135,68 @@ 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.")){
$key = str_replace("item.", "", $key);
foreach (array_values($this->input['report_keys']) as $key) {
if (str_contains($key, 'item.')) {
$key = str_replace('item.', '', $key);
$item_array[$key] = $item->{$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
$entity[$keyval] = "";
} 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
$entity[$keyval] = "";
} 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']))
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $invoice->client->present()->name();
}
if(in_array('status_id', $this->input['report_keys']))
if (in_array('status_id', $this->input['report_keys'])) {
$entity['status'] = $invoice->stringStatus($invoice->status_id);
}
return $entity;
}
}

View File

@ -73,7 +73,6 @@ class PaymentExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -83,8 +82,9 @@ class PaymentExport 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());
@ -94,66 +94,66 @@ class PaymentExport extends BaseExport
$query = $this->addDateRange($query);
$query->cursor()
->each(function ($entity){
$this->csv->insertOne($this->buildRow($entity));
});
return $this->csv->toString();
->each(function ($entity) {
$this->csv->insertOne($this->buildRow($entity));
});
return $this->csv->toString();
}
private function buildRow(Payment $payment) :array
{
$transformed_entity = $this->entity_transformer->transform($payment);
$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_entity))
if (array_key_exists($key, $transformed_entity)) {
$entity[$keyval] = $transformed_entity[$key];
else
} else {
$entity[$keyval] = '';
}
}
return $this->decorateAdvancedFields($payment, $entity);
}
private function decorateAdvancedFields(Payment $payment, array $entity) :array
{
if(in_array('status_id', $this->input['report_keys']))
if (in_array('status_id', $this->input['report_keys'])) {
$entity['status'] = $payment->stringStatus($payment->status_id);
}
if(in_array('vendor_id', $this->input['report_keys']))
if (in_array('vendor_id', $this->input['report_keys'])) {
$entity['vendor'] = $payment->vendor()->exists() ? $payment->vendor->name : '';
}
if(in_array('project_id', $this->input['report_keys']))
if (in_array('project_id', $this->input['report_keys'])) {
$entity['project'] = $payment->project()->exists() ? $payment->project->name : '';
}
if(in_array('currency_id', $this->input['report_keys']))
if (in_array('currency_id', $this->input['report_keys'])) {
$entity['currency'] = $payment->currency()->exists() ? $payment->currency->code : '';
}
if(in_array('exchange_currency_id', $this->input['report_keys']))
if (in_array('exchange_currency_id', $this->input['report_keys'])) {
$entity['exchange_currency'] = $payment->exchange_currency()->exists() ? $payment->exchange_currency->code : '';
}
if(in_array('client_id', $this->input['report_keys']))
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $payment->client->present()->name();
}
if(in_array('type_id', $this->input['report_keys']))
if (in_array('type_id', $this->input['report_keys'])) {
$entity['type'] = $payment->translatedType();
}
if(in_array('gateway_type_id', $this->input['report_keys']))
$entity['gateway'] = $payment->gateway_type ? $payment->gateway_type->name : "Unknown Type";
if (in_array('gateway_type_id', $this->input['report_keys'])) {
$entity['gateway'] = $payment->gateway_type ? $payment->gateway_type->name : 'Unknown Type';
}
return $entity;
}
}

View File

@ -66,7 +66,6 @@ class ProductExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -76,8 +75,9 @@ class ProductExport 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());
@ -87,49 +87,42 @@ class ProductExport extends BaseExport
$query = $this->addDateRange($query);
$query->cursor()
->each(function ($entity){
$this->csv->insertOne($this->buildRow($entity));
});
return $this->csv->toString();
->each(function ($entity) {
$this->csv->insertOne($this->buildRow($entity));
});
return $this->csv->toString();
}
private function buildRow(Product $product) :array
{
$transformed_entity = $this->entity_transformer->transform($product);
$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_entity))
if (array_key_exists($key, $transformed_entity)) {
$entity[$keyval] = $transformed_entity[$key];
else
} else {
$entity[$keyval] = '';
}
}
return $this->decorateAdvancedFields($product, $entity);
}
private function decorateAdvancedFields(Product $product, array $entity) :array
{
if(in_array('vendor_id', $this->input['report_keys']))
if (in_array('vendor_id', $this->input['report_keys'])) {
$entity['vendor'] = $product->vendor()->exists() ? $product->vendor->name : '';
}
if(array_key_exists('project_id', $this->input['report_keys']))
if (array_key_exists('project_id', $this->input['report_keys'])) {
$entity['project'] = $product->project()->exists() ? $product->project->name : '';
}
return $entity;
}
}

View File

@ -70,7 +70,7 @@ class QuoteExport extends BaseExport
private array $decorate_keys = [
'client',
'currency',
'invoice'
'invoice',
];
public function __construct(Company $company, array $input)
@ -82,7 +82,6 @@ class QuoteExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -92,8 +91,9 @@ class QuoteExport 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());
@ -101,58 +101,55 @@ class QuoteExport extends BaseExport
$query = Quote::query()
->with('client')
->where('company_id', $this->company->id)
->where('is_deleted',0);
->where('is_deleted', 0);
$query = $this->addDateRange($query);
$query->cursor()
->each(function ($quote){
$this->csv->insertOne($this->buildRow($quote));
});
return $this->csv->toString();
->each(function ($quote) {
$this->csv->insertOne($this->buildRow($quote));
});
return $this->csv->toString();
}
private function buildRow(Quote $quote) :array
{
$transformed_quote = $this->quote_transformer->transform($quote);
$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_quote))
if (array_key_exists($key, $transformed_quote)) {
$entity[$keyval] = $transformed_quote[$key];
else
} else {
$entity[$keyval] = '';
}
}
return $this->decorateAdvancedFields($quote, $entity);
}
private function decorateAdvancedFields(Quote $quote, array $entity) :array
{
if(in_array('currency_id', $this->input['report_keys']))
if (in_array('currency_id', $this->input['report_keys'])) {
$entity['currency'] = $quote->client->currency()->code;
}
if(in_array('client_id', $this->input['report_keys']))
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $quote->client->present()->name();
}
if(in_array('status_id',$this->input['report_keys']))
if (in_array('status_id', $this->input['report_keys'])) {
$entity['status'] = $quote->stringStatus($quote->status_id);
}
if(in_array('invoice_id', $this->input['report_keys']))
$entity['invoice'] = $quote->invoice ? $quote->invoice->number : "";
if (in_array('invoice_id', $this->input['report_keys'])) {
$entity['invoice'] = $quote->invoice ? $quote->invoice->number : '';
}
return $entity;
}
}

View File

@ -85,7 +85,6 @@ class QuoteItemExport extends BaseExport
'custom_value4' => 'item.custom_value4',
];
private array $decorate_keys = [
'client',
'currency',
@ -100,7 +99,6 @@ class QuoteItemExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -110,28 +108,25 @@ class QuoteItemExport 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());
$query = Quote::query()
->with('client')->where('company_id', $this->company->id)
->where('is_deleted',0);
->where('is_deleted', 0);
$query = $this->addDateRange($query);
$query->cursor()
->each(function ($quote){
->each(function ($quote) {
$this->iterateItems($quote);
});
});
return $this->csv->toString();
return $this->csv->toString();
}
private function iterateItems(Quote $quote)
@ -140,76 +135,68 @@ class QuoteItemExport extends BaseExport
$transformed_items = [];
foreach($quote->line_items as $item)
{
foreach ($quote->line_items as $item) {
$item_array = [];
foreach(array_values($this->input['report_keys']) as $key){
if(str_contains($key, "item.")){
$key = str_replace("item.", "", $key);
foreach (array_values($this->input['report_keys']) as $key) {
if (str_contains($key, 'item.')) {
$key = str_replace('item.', '', $key);
$item_array[$key] = $item->{$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
$entity[$keyval] = "";
} else {
$entity[$keyval] = '';
}
}
$transformed_items = array_merge($transformed_quote, $item_array);
$entity = $this->decorateAdvancedFields($quote, $transformed_items);
$this->csv->insertOne($entity);
$this->csv->insertOne($entity);
}
}
private function buildRow(Quote $quote) :array
{
$transformed_quote = $this->quote_transformer->transform($quote);
$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_quote))
if (array_key_exists($key, $transformed_quote)) {
$entity[$keyval] = $transformed_quote[$key];
else
$entity[$keyval] = "";
} else {
$entity[$keyval] = '';
}
}
return $this->decorateAdvancedFields($quote, $entity);
}
private function decorateAdvancedFields(Quote $quote, array $entity) :array
{
if(in_array('currency_id', $this->input['report_keys']))
if (in_array('currency_id', $this->input['report_keys'])) {
$entity['currency'] = $quote->client->currency() ? $quote->client->currency()->code : $quote->company->currency()->code;
}
if(in_array('client_id', $this->input['report_keys']))
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $quote->client->present()->name();
}
if(in_array('status_id', $this->input['report_keys']))
if (in_array('status_id', $this->input['report_keys'])) {
$entity['status'] = $quote->stringStatus($quote->status_id);
}
return $entity;
}
}

View File

@ -74,7 +74,7 @@ class RecurringInvoiceExport extends BaseExport
'currency',
'status',
'vendor',
'project'
'project',
];
public function __construct(Company $company, array $input)
@ -86,7 +86,6 @@ class RecurringInvoiceExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -96,8 +95,9 @@ class RecurringInvoiceExport 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());
@ -105,64 +105,63 @@ class RecurringInvoiceExport extends BaseExport
$query = RecurringInvoice::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){
$this->csv->insertOne($this->buildRow($invoice));
});
return $this->csv->toString();
->each(function ($invoice) {
$this->csv->insertOne($this->buildRow($invoice));
});
return $this->csv->toString();
}
private function buildRow(RecurringInvoice $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(RecurringInvoice $invoice, array $entity) :array
{
if(in_array('country_id', $this->input['report_keys']))
$entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : "";
if (in_array('country_id', $this->input['report_keys'])) {
$entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : '';
}
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']))
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $invoice->client->present()->name();
}
if(in_array('status_id',$this->input['report_keys']))
if (in_array('status_id', $this->input['report_keys'])) {
$entity['status'] = $invoice->stringStatus($invoice->status_id);
}
if(in_array('project_id',$this->input['report_keys']))
$entity['project'] = $invoice->project ? $invoice->project->name : "";
if (in_array('project_id', $this->input['report_keys'])) {
$entity['project'] = $invoice->project ? $invoice->project->name : '';
}
if(in_array('vendor_id',$this->input['report_keys']))
$entity['vendor'] = $invoice->vendor ? $invoice->vendor->name : "";
if (in_array('vendor_id', $this->input['report_keys'])) {
$entity['vendor'] = $invoice->vendor ? $invoice->vendor->name : '';
}
return $entity;
}
}

View File

@ -71,7 +71,6 @@ class TaskExport extends BaseExport
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
@ -79,15 +78,15 @@ class TaskExport extends BaseExport
$t->replace(Ninja::transformTranslations($this->company->settings));
$this->date_format = DateFormat::find($this->company->settings->date_format_id)->format;
//load the CSV document from a string
$this->csv = Writer::createFromString();
ksort($this->entity_keys);
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());
@ -97,59 +96,50 @@ class TaskExport extends BaseExport
$query = $this->addDateRange($query);
$query->cursor()
->each(function ($entity){
$this->buildRow($entity);
});
return $this->csv->toString();
->each(function ($entity) {
$this->buildRow($entity);
});
return $this->csv->toString();
}
private function buildRow(Task $task)
private function buildRow(Task $task)
{
$entity = [];
$transformed_entity = $this->entity_transformer->transform($task);
if(is_null($task->time_log) || (is_array(json_decode($task->time_log,1)) && count(json_decode($task->time_log,1)) == 0)){
foreach(array_values($this->input['report_keys']) as $key){
if (is_null($task->time_log) || (is_array(json_decode($task->time_log, 1)) && count(json_decode($task->time_log, 1)) == 0)) {
foreach (array_values($this->input['report_keys']) as $key) {
$keyval = array_search($key, $this->entity_keys);
if(array_key_exists($key, $transformed_entity))
if (array_key_exists($key, $transformed_entity)) {
$entity[$keyval] = $transformed_entity[$key];
else
$entity[$keyval] = '';
} else {
$entity[$keyval] = '';
}
}
$entity['start_date'] = "";
$entity['end_date'] = "";
$entity['duration'] = "";
$entity['start_date'] = '';
$entity['end_date'] = '';
$entity['duration'] = '';
$entity = $this->decorateAdvancedFields($task, $entity);
ksort($entity);
$this->csv->insertOne($entity);
}
elseif(is_array(json_decode($task->time_log,1)) && count(json_decode($task->time_log,1)) > 0) {
foreach(array_values($this->input['report_keys']) as $key){
} elseif (is_array(json_decode($task->time_log, 1)) && count(json_decode($task->time_log, 1)) > 0) {
foreach (array_values($this->input['report_keys']) as $key) {
$keyval = array_search($key, $this->entity_keys);
if(array_key_exists($key, $transformed_entity))
if (array_key_exists($key, $transformed_entity)) {
$entity[$keyval] = $transformed_entity[$key];
else
$entity[$keyval] = '';
} else {
$entity[$keyval] = '';
}
}
$this->iterateLogs($task, $entity);
}
}
private function iterateLogs(Task $task, array $entity)
@ -157,48 +147,51 @@ class TaskExport extends BaseExport
$timezone = Timezone::find($task->company->settings->timezone_id);
$timezone_name = 'US/Eastern';
if($timezone)
if ($timezone) {
$timezone_name = $timezone->name;
}
$logs = json_decode($task->time_log,1);
$date_format_default = "Y-m-d";
$logs = json_decode($task->time_log, 1);
$date_format_default = 'Y-m-d';
$date_format = DateFormat::find($task->company->settings->date_format_id);
if($date_format)
if ($date_format) {
$date_format_default = $date_format->format;
}
foreach($logs as $key => $item)
{
if(in_array("start_date", $this->input['report_keys'])){
foreach ($logs as $key => $item) {
if (in_array('start_date', $this->input['report_keys'])) {
$entity['start_date'] = Carbon::createFromTimeStamp($item[0])->setTimezone($timezone_name)->format($date_format_default);
}
if(in_array("end_date", $this->input['report_keys']) && $item[1] > 0){
if (in_array('end_date', $this->input['report_keys']) && $item[1] > 0) {
$entity['end_date'] = Carbon::createFromTimeStamp($item[1])->setTimezone($timezone_name)->format($date_format_default);
}
if(in_array("end_date", $this->input['report_keys']) && $item[1] == 0){
if (in_array('end_date', $this->input['report_keys']) && $item[1] == 0) {
$entity['end_date'] = ctrans('texts.is_running');
}
if(in_array("duration", $this->input['report_keys'])){
if (in_array('duration', $this->input['report_keys'])) {
$entity['duration'] = $task->calcDuration();
}
if(!array_key_exists('duration', $entity))
$entity['duration'] = "";
if (! array_key_exists('duration', $entity)) {
$entity['duration'] = '';
}
if(!array_key_exists('start_date', $entity))
$entity['start_date'] = "";
if (! array_key_exists('start_date', $entity)) {
$entity['start_date'] = '';
}
if(!array_key_exists('end_date', $entity))
$entity['end_date'] = "";
if (! array_key_exists('end_date', $entity)) {
$entity['end_date'] = '';
}
$entity = $this->decorateAdvancedFields($task, $entity);
ksort($entity);
$this->csv->insertOne($entity);
@ -206,25 +199,26 @@ class TaskExport extends BaseExport
unset($entity['end_date']);
unset($entity['duration']);
}
}
private function decorateAdvancedFields(Task $task, array $entity) :array
{
if(in_array('status_id', $this->input['report_keys']))
if (in_array('status_id', $this->input['report_keys'])) {
$entity['status'] = $task->status()->exists() ? $task->status->name : '';
}
if(in_array('project_id', $this->input['report_keys']))
if (in_array('project_id', $this->input['report_keys'])) {
$entity['project'] = $task->project()->exists() ? $task->project->name : '';
}
if(in_array('client_id', $this->input['report_keys']))
$entity['client'] = $task->client ? $task->client->present()->name() : "";
if (in_array('client_id', $this->input['report_keys'])) {
$entity['client'] = $task->client ? $task->client->present()->name() : '';
}
if(in_array('invoice_id', $this->input['report_keys']))
$entity['invoice'] = $task->invoice ? $task->invoice->number : "";
if (in_array('invoice_id', $this->input['report_keys'])) {
$entity['invoice'] = $task->invoice ? $task->invoice->number : '';
}
return $entity;
}
}

View File

@ -25,7 +25,7 @@ class ClientGatewayTokenFactory
$client_gateway_token->is_deleted = false;
$client_gateway_token->token = '';
$client_gateway_token->routing_number = '';
return $client_gateway_token;
}
}

View File

@ -28,11 +28,12 @@ class CloneQuoteToInvoiceFactory
unset($quote_array['invoice_id']);
unset($quote_array['id']);
unset($quote_array['invitations']);
//preserve terms if they exist on Quotes
//if(array_key_exists('terms', $quote_array) && strlen($quote_array['terms']) < 2)
if(!$quote->company->use_quote_terms_on_conversion)
if (! $quote->company->use_quote_terms_on_conversion) {
unset($quote_array['terms']);
}
// unset($quote_array['public_notes']);
unset($quote_array['footer']);

View File

@ -37,12 +37,13 @@ class CompanyFactory
//$company->custom_fields = (object) ['invoice1' => '1', 'invoice2' => '2', 'client1'=>'3'];
$company->custom_fields = (object) [];
$company->client_registration_fields = ClientRegistrationFields::generate();
if(Ninja::isHosted())
if (Ninja::isHosted()) {
$company->subdomain = MultiDB::randomSubdomainGenerator();
else
} else {
$company->subdomain = '';
}
$company->enabled_modules = config('ninja.enabled_modules'); //32767;//8191; //4095
$company->default_password_timeout = 1800000;
$company->markdown_email_enabled = false;

View File

@ -24,7 +24,7 @@ class CompanyGatewayFactory
$company_gateway->require_billing_address = false;
$company_gateway->require_shipping_address = false;
$company_gateway->config = encrypt(json_encode(new \stdClass));
return $company_gateway;
}
}

View File

@ -23,7 +23,7 @@ class ExpenseCategoryFactory
$expense->name = '';
$expense->is_deleted = false;
$expense->color = '';
return $expense;
}
}

View File

@ -42,7 +42,7 @@ class ExpenseFactory
$expense->tax_amount1 = 0;
$expense->tax_amount2 = 0;
$expense->tax_amount3 = 0;
return $expense;
}
}

View File

@ -18,8 +18,8 @@ class GroupSettingFactory
{
public static function create(int $company_id, int $user_id) :GroupSetting
{
$settings = new \stdClass;
$settings->entity = Client::class;
$settings = new \stdClass;
$settings->entity = Client::class;
$gs = new GroupSetting;
$gs->name = '';

View File

@ -49,7 +49,7 @@ class InvoiceFactory
$invoice->user_id = $user_id;
$invoice->company_id = $company_id;
$invoice->recurring_id = null;
return $invoice;
}
}

View File

@ -40,7 +40,7 @@ class InvoiceItemFactory
$item->custom_value2 = '';
$item->custom_value3 = '';
$item->custom_value4 = '';
$item->type_id = "1";
$item->type_id = '1';
return $item;
}
@ -71,7 +71,7 @@ class InvoiceItemFactory
// $item->custom_value4 = $faker->realText(10);
$item->tax_name1 = 'GST';
$item->tax_rate1 = 10.00;
$item->type_id = "1";
$item->type_id = '1';
$data[] = $item;
}
@ -105,7 +105,7 @@ class InvoiceItemFactory
// $item->custom_value4 = $faker->realText(10);
$item->tax_name1 = '';
$item->tax_rate1 = 0;
$item->type_id = "1";
$item->type_id = '1';
$data[] = $item;
}

View File

@ -31,7 +31,7 @@ class ProjectFactory
$project->custom_value3 = '';
$project->custom_value4 = '';
$project->is_deleted = 0;
return $project;
}
}

Some files were not shown because too many files have changed in this diff Show More