mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Additional column checks prior to export queries
This commit is contained in:
parent
06233240ce
commit
64f3af9c31
@ -109,7 +109,7 @@ class ActivityExport extends BaseExport
|
|||||||
$query = Activity::query()
|
$query = Activity::query()
|
||||||
->where('company_id', $this->company->id);
|
->where('company_id', $this->company->id);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'activities');
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
@ -1245,13 +1245,13 @@ class BaseExport
|
|||||||
* @param Builder $query
|
* @param Builder $query
|
||||||
* @return Builder
|
* @return Builder
|
||||||
*/
|
*/
|
||||||
protected function addDateRange(Builder $query): Builder
|
protected function addDateRange(Builder $query, ?string $table_name = null): Builder
|
||||||
{
|
{
|
||||||
$query = $this->applyProductFilters($query);
|
$query = $this->applyProductFilters($query);
|
||||||
|
|
||||||
$date_range = $this->input['date_range'];
|
$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->table_name && $this->columnExists($table_name, $this->input['date_key']))) {
|
||||||
$this->date_key = $this->input['date_key'];
|
$this->date_key = $this->input['date_key'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1608,5 +1608,18 @@ class BaseExport
|
|||||||
ZipDocuments::dispatch($documents, $this->company, $user);
|
ZipDocuments::dispatch($documents, $this->company, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that the column exists
|
||||||
|
* on the table prior to adding it to
|
||||||
|
* the query builder
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @param string $column
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function columnExists($table, $column): bool
|
||||||
|
{
|
||||||
|
return \Illuminate\Support\Facades\Schema::hasColumn($table, $column);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ class ClientExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query,' clients');
|
||||||
|
|
||||||
if($this->input['document_email_attachment'] ?? false) {
|
if($this->input['document_email_attachment'] ?? false) {
|
||||||
$this->queueDocuments($query);
|
$this->queueDocuments($query);
|
||||||
|
@ -63,7 +63,7 @@ class ContactExport extends BaseExport
|
|||||||
$q->where('is_deleted', false);
|
$q->where('is_deleted', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'client_contacts');
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ class CreditExport extends BaseExport
|
|||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
->where('is_deleted', $this->input['include_deleted'] ?? false);
|
->where('is_deleted', $this->input['include_deleted'] ?? false);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'credits');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class DocumentExport extends BaseExport
|
|||||||
|
|
||||||
$query = Document::query()->where('company_id', $this->company->id);
|
$query = Document::query()->where('company_id', $this->company->id);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'documents');
|
||||||
|
|
||||||
if($this->input['document_email_attachment'] ?? false) {
|
if($this->input['document_email_attachment'] ?? false) {
|
||||||
$this->queueDocuments($query);
|
$this->queueDocuments($query);
|
||||||
|
@ -89,7 +89,7 @@ class ExpenseExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'expenses');
|
||||||
|
|
||||||
if($this->input['status'] ?? false) {
|
if($this->input['status'] ?? false) {
|
||||||
$query = $this->addExpenseStatusFilter($query, $this->input['status']);
|
$query = $this->addExpenseStatusFilter($query, $this->input['status']);
|
||||||
|
@ -67,7 +67,7 @@ class InvoiceExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class InvoiceItemExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class PaymentExport extends BaseExport
|
|||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
->where('is_deleted', 0);
|
->where('is_deleted', 0);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'payments');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -75,12 +75,11 @@ class ProductExport extends BaseExport
|
|||||||
->withTrashed()
|
->withTrashed()
|
||||||
->where('company_id', $this->company->id);
|
->where('company_id', $this->company->id);
|
||||||
|
|
||||||
|
if(!$this->input['include_deleted'] ?? false) { //@phpstan-ignore-line
|
||||||
if(!$this->input['include_deleted'] ?? false) {
|
|
||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'products');
|
||||||
|
|
||||||
if($this->input['document_email_attachment'] ?? false) {
|
if($this->input['document_email_attachment'] ?? false) {
|
||||||
$this->queueDocuments($query);
|
$this->queueDocuments($query);
|
||||||
|
@ -129,7 +129,7 @@ class ProductSalesExport extends BaseExport
|
|||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]);
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
$query = $this->filterByClients($query);
|
$query = $this->filterByClients($query);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class PurchaseOrderExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'purchase_orders');
|
||||||
|
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
@ -71,7 +71,7 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'purchase_orders');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class QuoteExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'quotes');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class QuoteItemExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'quotes');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class RecurringInvoiceExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'recurring_invoices');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class TaskExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'tasks');
|
||||||
|
|
||||||
$clients = &$this->input['client_id'];
|
$clients = &$this->input['client_id'];
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class VendorExport extends BaseExport
|
|||||||
$query->where('is_deleted', 0);
|
$query->where('is_deleted', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'vendors');
|
||||||
|
|
||||||
if($this->input['document_email_attachment'] ?? false) {
|
if($this->input['document_email_attachment'] ?? false) {
|
||||||
$this->queueDocuments($query);
|
$this->queueDocuments($query);
|
||||||
|
@ -45,7 +45,8 @@ class StoreProjectRequest extends Request
|
|||||||
$rules['name'] = 'required';
|
$rules['name'] = 'required';
|
||||||
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
|
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
|
||||||
$rules['budgeted_hours'] = 'sometimes|numeric';
|
$rules['budgeted_hours'] = 'sometimes|numeric';
|
||||||
|
$rules['task_rate'] = 'required|bail|numeric';
|
||||||
|
|
||||||
if (isset($this->number)) {
|
if (isset($this->number)) {
|
||||||
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id);
|
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id);
|
||||||
}
|
}
|
||||||
@ -79,6 +80,8 @@ class StoreProjectRequest extends Request
|
|||||||
$input['budgeted_hours'] = 0;
|
$input['budgeted_hours'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$input['task_rate'] = isset($input['task_rate']) ? $input['task_rate'] : 0;
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ class ARDetailReport extends BaseExport
|
|||||||
->orderBy('due_date', 'ASC')
|
->orderBy('due_date', 'ASC')
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
$query = $this->filterByClients($query);
|
$query = $this->filterByClients($query);
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class ClientBalanceReport extends BaseExport
|
|||||||
$query = Invoice::query()->where('client_id', $client->id)
|
$query = Invoice::query()->where('client_id', $client->id)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
$client->present()->name(),
|
$client->present()->name(),
|
||||||
|
@ -103,7 +103,7 @@ class ClientSalesReport extends BaseExport
|
|||||||
$query = Invoice::query()->where('client_id', $client->id)
|
$query = Invoice::query()->where('client_id', $client->id)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]);
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
$amount = $query->sum('amount');
|
$amount = $query->sum('amount');
|
||||||
$balance = $query->sum('balance');
|
$balance = $query->sum('balance');
|
||||||
|
@ -81,7 +81,7 @@ class TaxSummaryReport extends BaseExport
|
|||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->orderBy('balance', 'desc');
|
->orderBy('balance', 'desc');
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
$this->csv->insertOne([ctrans('texts.tax_summary')]);
|
$this->csv->insertOne([ctrans('texts.tax_summary')]);
|
||||||
$this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]);
|
$this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]);
|
||||||
|
@ -69,7 +69,7 @@ class UserSalesReport extends BaseExport
|
|||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]);
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]);
|
||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
$query = $this->filterByClients($query);
|
$query = $this->filterByClients($query);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user