mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Fixes for email reports
This commit is contained in:
parent
6966c5cc61
commit
8ff283e03b
@ -836,36 +836,62 @@ class BaseExport
|
||||
|
||||
protected function addClientFilter($query, $clients): Builder
|
||||
{
|
||||
$transformed_clients = $this->transformKeys(explode(',', $clients));
|
||||
|
||||
$query->whereIn('client_id', $transformed_clients);
|
||||
if(is_string($clients))
|
||||
$clients = explode(',', $clients);
|
||||
|
||||
$transformed_clients = $this->transformKeys($clients);
|
||||
|
||||
nlog($clients);
|
||||
nlog($transformed_clients);
|
||||
|
||||
if(count($transformed_clients) > 0)
|
||||
$query->whereIn('client_id', $transformed_clients);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function addVendorFilter($query, $vendors): Builder
|
||||
{
|
||||
$transformed_vendors = $this->transformKeys(explode(',', $vendors));
|
||||
|
||||
$query->whereIn('vendor_id', $transformed_vendors);
|
||||
if(is_string($vendors)) {
|
||||
$vendors = explode(',', $vendors);
|
||||
}
|
||||
|
||||
$transformed_vendors = $this->transformKeys($vendors);
|
||||
|
||||
if(count($transformed_vendors) > 0)
|
||||
$query->whereIn('vendor_id', $transformed_vendors);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function addProjectFilter($query, $projects): Builder
|
||||
{
|
||||
$transformed_projects = $this->transformKeys(explode(',', $projects));
|
||||
|
||||
$query->whereIn('project_id', $transformed_projects);
|
||||
if(is_string($projects)) {
|
||||
$projects = explode(',', $projects);
|
||||
}
|
||||
|
||||
$transformed_projects = $this->transformKeys($projects);
|
||||
|
||||
if(count($transformed_projects) > 0)
|
||||
$query->whereIn('project_id', $transformed_projects);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function addCategoryFilter($query, $expense_categories): Builder
|
||||
{
|
||||
$transformed_expense_categories = $this->transformKeys(explode(',', $expense_categories));
|
||||
|
||||
$query->whereIn('category_id', $transformed_expense_categories);
|
||||
if(is_string($expense_categories)) {
|
||||
$expense_categories = explode(',', $expense_categories);
|
||||
}
|
||||
|
||||
$transformed_expense_categories = $this->transformKeys($expense_categories);
|
||||
|
||||
|
||||
if(count($transformed_expense_categories) > 0)
|
||||
$query->whereIn('category_id', $transformed_expense_categories);
|
||||
|
||||
return $query;
|
||||
}
|
||||
@ -875,7 +901,6 @@ class BaseExport
|
||||
|
||||
$status_parameters = explode(',', $status);
|
||||
|
||||
|
||||
if(in_array('all', $status_parameters)) {
|
||||
return $query;
|
||||
}
|
||||
@ -931,6 +956,8 @@ class BaseExport
|
||||
|
||||
$date_range = $this->input['date_range'];
|
||||
|
||||
nlog($date_range);
|
||||
|
||||
if (array_key_exists('date_key', $this->input) && strlen($this->input['date_key']) > 1) {
|
||||
$this->date_key = $this->input['date_key'];
|
||||
}
|
||||
@ -1262,7 +1289,7 @@ class BaseExport
|
||||
|
||||
public function queueDocuments(Builder $query)
|
||||
{
|
||||
|
||||
nlog("queue docs pls");
|
||||
if($query->getModel() instanceof Document)
|
||||
$documents = $query->pluck('id')->toArray();
|
||||
else{
|
||||
@ -1274,6 +1301,7 @@ class BaseExport
|
||||
}
|
||||
|
||||
nlog($documents);
|
||||
|
||||
if(count($documents) > 0) {
|
||||
|
||||
$user = $this->company->owner();
|
||||
|
@ -104,6 +104,7 @@ class ExpenseExport extends BaseExport
|
||||
$query = $this->addCategoryFilter($query, $this->input['categories']);
|
||||
}
|
||||
|
||||
nlog($this->input);
|
||||
if($this->input['document_email_attachment'] ?? false) {
|
||||
$this->queueDocuments($query);
|
||||
}
|
||||
@ -122,6 +123,8 @@ class ExpenseExport extends BaseExport
|
||||
//insert the header
|
||||
$this->csv->insertOne($this->buildHeader());
|
||||
|
||||
nlog("expense counter = ");
|
||||
nlog($query->count());
|
||||
$query->cursor()
|
||||
->each(function ($expense) {
|
||||
$this->csv->insertOne($this->buildRow($expense));
|
||||
|
@ -29,7 +29,7 @@ class ClientDecorator extends Decorator implements DecoratorInterface
|
||||
|
||||
if($client && method_exists($this, $key)) {
|
||||
return $this->{$key}($client);
|
||||
} elseif($client && $client->{$key}) {
|
||||
} elseif($client && ($client->{$key} ?? false)) {
|
||||
return $client->{$key};
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ContactDecorator implements DecoratorInterface
|
||||
|
||||
if($contact && method_exists($this, $key)) {
|
||||
return $this->{$key}($contact);
|
||||
} elseif($contact && $contact->{$key}) {
|
||||
} elseif($contact && ($contact->{$key} ?? false)) {
|
||||
return $contact->{$key};
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class CreditDecorator implements DecoratorInterface
|
||||
|
||||
if($credit && method_exists($this, $key)) {
|
||||
return $this->{$key}($credit);
|
||||
} elseif($credit && $credit->{$key}) {
|
||||
} elseif($credit && ($credit->{$key} ?? false)) {
|
||||
return $credit->{$key};
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ExpenseDecorator implements DecoratorInterface
|
||||
|
||||
if($expense && method_exists($this, $key)) {
|
||||
return $this->{$key}($expense);
|
||||
} elseif($expense && $expense->{$key}) {
|
||||
} elseif($expense && ($expense->{$key} ?? false)) {
|
||||
return $expense->{$key};
|
||||
}
|
||||
|
||||
@ -35,6 +35,11 @@ class ExpenseDecorator implements DecoratorInterface
|
||||
|
||||
}
|
||||
|
||||
public function category(Expense $expense)
|
||||
{
|
||||
return $this->category_id($expense);
|
||||
}
|
||||
|
||||
public function category_id(Expense $expense)
|
||||
{
|
||||
return $expense->category ? $expense->category->name : '';
|
||||
|
@ -29,7 +29,7 @@ class InvoiceDecorator extends Decorator implements DecoratorInterface
|
||||
|
||||
if($invoice && method_exists($this, $key)) {
|
||||
return $this->{$key}($invoice);
|
||||
} elseif($invoice && $invoice->{$key}) {
|
||||
} elseif($invoice && ($invoice->{$key} ?? false)) {
|
||||
return $invoice->{$key};
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ class PaymentDecorator extends Decorator implements DecoratorInterface
|
||||
|
||||
if($payment && method_exists($this, $key)) {
|
||||
return $this->{$key}($payment);
|
||||
} elseif($payment && $payment->{$key}) {
|
||||
} elseif($payment && ($payment->{$key} ?? false)) {
|
||||
return $payment->{$key};
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ProductDecorator implements DecoratorInterface
|
||||
|
||||
if($product && method_exists($this, $key)) {
|
||||
return $this->{$key}($product);
|
||||
} elseif($product->{$key}) {
|
||||
} elseif($product->{$key} ?? false) {
|
||||
return $product->{$key} ?? '';
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class PurchaseOrderDecorator extends Decorator implements DecoratorInterface
|
||||
|
||||
if($purchase_order && method_exists($this, $key)) {
|
||||
return $this->{$key}($purchase_order);
|
||||
} elseif($purchase_order->{$key}) {
|
||||
} elseif($purchase_order->{$key} ?? false) {
|
||||
return $purchase_order->{$key} ?? '';
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class QuoteDecorator extends Decorator implements DecoratorInterface
|
||||
|
||||
if($quote && method_exists($this, $key)) {
|
||||
return $this->{$key}($quote);
|
||||
} elseif($quote->{$key}) {
|
||||
} elseif($quote->{$key} ?? false) {
|
||||
return $quote->{$key} ?? '';
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class RecurringInvoiceDecorator extends Decorator implements DecoratorInterface
|
||||
|
||||
if($recurring_invoice && method_exists($this, $key)) {
|
||||
return $this->{$key}($recurring_invoice);
|
||||
} elseif($recurring_invoice->{$key}) {
|
||||
} elseif($recurring_invoice->{$key} ?? false) {
|
||||
return $recurring_invoice->{$key} ?? '';
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ class TaskDecorator extends Decorator implements DecoratorInterface
|
||||
|
||||
if($task && method_exists($this, $key)) {
|
||||
return $this->{$key}($task);
|
||||
} elseif($task && $task->{$key}) {
|
||||
} elseif($task && $task->{$key} ?? false) {
|
||||
return $task->{$key};
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class VendorContactDecorator implements DecoratorInterface
|
||||
|
||||
if($contact && method_exists($this, $key)) {
|
||||
return $this->{$key}($contact);
|
||||
} elseif($contact && $contact->{$key}) {
|
||||
} elseif($contact && ($contact->{$key} ?? false)) {
|
||||
return $contact->{$key} ?? '';
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class VendorDecorator extends Decorator implements DecoratorInterface
|
||||
|
||||
if($vendor && method_exists($this, $key)) {
|
||||
return $this->{$key}($vendor);
|
||||
} elseif($vendor->{$key}) {
|
||||
} elseif($vendor->{$key} ?? false) {
|
||||
return $vendor->{$key} ?? '';
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,14 @@ class PaymentAppliedValidAmount implements Rule
|
||||
|
||||
$inv = $inv_collection->firstWhere('id', $invoice['invoice_id']);
|
||||
|
||||
if ($inv->balance < $invoice['amount']) {
|
||||
nlog($inv->status_id);
|
||||
nlog($inv->amount);
|
||||
nlog($invoice['amount']);
|
||||
|
||||
if($inv->status_id == Invoice::STATUS_DRAFT && $inv->amount >= $invoice['amount']){
|
||||
|
||||
}
|
||||
elseif ($inv->balance < $invoice['amount']) {
|
||||
$this->message = 'Amount cannot be greater than invoice balance';
|
||||
|
||||
return false;
|
||||
|
@ -56,7 +56,15 @@ class TaskScheduler implements ShouldQueue
|
||||
->where('next_run', '<=', now())
|
||||
->cursor()
|
||||
->each(function ($scheduler) {
|
||||
$this->doJob($scheduler);
|
||||
|
||||
nlog("Doing job {$scheduler->name}");
|
||||
|
||||
try {
|
||||
$scheduler->service()->runTask();
|
||||
} catch(\Exception $e) {
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -73,19 +81,19 @@ class TaskScheduler implements ShouldQueue
|
||||
->where('next_run', '<=', now())
|
||||
->cursor()
|
||||
->each(function ($scheduler) {
|
||||
$this->doJob($scheduler);
|
||||
|
||||
nlog("Doing job {$scheduler->name}");
|
||||
|
||||
try {
|
||||
/** @var \App\Models\Scheduler $scheduler */
|
||||
$scheduler->service()->runTask();
|
||||
} catch(\Exception $e) {
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private function doJob(Scheduler $scheduler)
|
||||
{
|
||||
nlog("Doing job {$scheduler->name}");
|
||||
|
||||
try {
|
||||
$scheduler->service()->runTask();
|
||||
} catch(\Exception $e) {
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class EmailPayment implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->company->is_disabled || (!$this->contact->email ?? false)) {
|
||||
if ($this->company->is_disabled || (!$this->contact?->email ?? false)) {
|
||||
nlog("company disabled - or - contact email not found");
|
||||
return;
|
||||
}
|
||||
|
@ -1144,6 +1144,8 @@ class Import implements ShouldQueue
|
||||
);
|
||||
|
||||
$key = "invoices_{$resource['id']}";
|
||||
|
||||
nlog($invoice->id);
|
||||
|
||||
$this->ids['invoices'][$key] = [
|
||||
'old' => $resource['id'],
|
||||
@ -1406,7 +1408,8 @@ class Import implements ShouldQueue
|
||||
$payment->save();
|
||||
}
|
||||
|
||||
|
||||
nlog($payment->id);
|
||||
|
||||
$old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id;
|
||||
|
||||
$this->ids['payments'] = [
|
||||
|
@ -67,8 +67,10 @@ class EmailQuotaNotification extends Notification
|
||||
$content = "Email quota exceeded by Account {$this->account->key} \n";
|
||||
|
||||
$owner = $this->account->companies()->first()->owner();
|
||||
$owner_name = $owner->present()->name() ?? 'No Owner Found';
|
||||
$owner_email = $owner->email ?? 'No Owner Email Found';
|
||||
|
||||
$content .= "Owner {$owner->present()->name() } | {$owner->email}";
|
||||
$content .= "Owner {$owner_name} | {$owner_email}";
|
||||
|
||||
return (new SlackMessage())
|
||||
->success()
|
||||
|
@ -59,21 +59,13 @@ class EmailReport
|
||||
{
|
||||
|
||||
$start_end_dates = $this->calculateStartAndEndDates($this->scheduler->parameters);
|
||||
$data = $this->scheduler->parameters;
|
||||
|
||||
$data = [];
|
||||
|
||||
$data = [
|
||||
'start_date' => $start_end_dates[0],
|
||||
'end_date' => $start_end_dates[1],
|
||||
'date_range' => 'custom',
|
||||
'client_id' => null,
|
||||
'report_keys' => []
|
||||
];
|
||||
|
||||
if (isset($this->scheduler->parameters['clients']) && count($this->scheduler->parameters['clients']) >= 1) {
|
||||
$data['clients'] = $this->transformKeys($this->scheduler->parameters['clients']);
|
||||
}
|
||||
|
||||
$data['start_date'] = $start_end_dates[0];
|
||||
$data['end_date'] = $start_end_dates[1];
|
||||
$data['date_range'] = $data['date_range'] ?? 'all';
|
||||
$data['report_keys'] = $data['report_keys'] ?? [];
|
||||
|
||||
$export = false;
|
||||
|
||||
match($this->scheduler->parameters['report_name']) {
|
||||
|
@ -73,7 +73,7 @@ class AccountEmailQuotaTest extends TestCase
|
||||
$company->track_inventory = true;
|
||||
$company->settings = $settings;
|
||||
$company->save();
|
||||
|
||||
/** @vart \App\Models\Account $account */
|
||||
$account->default_company_id = $company->id;
|
||||
$account->save();
|
||||
|
||||
|
@ -265,7 +265,7 @@ class ClientSettingsTest extends TestCase
|
||||
])->post('/api/v1/clients/', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($message);
|
||||
// nlog($message);
|
||||
}
|
||||
|
||||
$response->assertStatus(302);
|
||||
|
Loading…
Reference in New Issue
Block a user