added scope for collection export
This commit is contained in:
parent
0c6dd49902
commit
9b308e165a
@ -118,6 +118,37 @@ abstract class Model extends Eloquent implements Ownable
|
||||
return $query->paginate($limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to export the rows of the current page filtered and sorted.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $ids
|
||||
* @param $sort
|
||||
* @param $id_field
|
||||
*
|
||||
* @return \Illuminate\Support\LazyCollection
|
||||
*/
|
||||
public function scopeCollectForExport($query, $ids = [], $sort = 'name', $id_field = 'id')
|
||||
{
|
||||
$request = request();
|
||||
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn($id_field, (array) $ids);
|
||||
}
|
||||
|
||||
$search = $request->get('search');
|
||||
|
||||
$query->usingSearchString($search)->sortable($sort);
|
||||
|
||||
$page = (int) $request->get('page');
|
||||
$limit = (int) $request->get('limit', setting('default.list_limit', '25'));
|
||||
$offset = $page ? ($page - 1) * $limit : 0;
|
||||
|
||||
$query->offset($offset)->limit($limit);
|
||||
|
||||
return $query->cursor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include active models.
|
||||
*
|
||||
|
@ -11,13 +11,7 @@ class Transactions extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('account', 'category', 'contact', 'document')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('account', 'category', 'contact', 'document')->collectForExport($this->ids, ['paid_at' => 'desc']);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -12,18 +12,12 @@ class Transfers extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(
|
||||
return Model::with(
|
||||
'expense_transaction',
|
||||
'expense_transaction.account',
|
||||
'income_transaction',
|
||||
'income_transaction.account'
|
||||
)->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
)->collectForExport($this->ids);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class ItemTaxes extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('item', 'tax')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('item_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('item', 'tax')->collectForExport($this->ids, null, 'item_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class Items extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('category')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('category')->collectForExport($this->ids);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -11,13 +11,7 @@ class Payments extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('account', 'bill', 'category', 'contact')->expense()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('account', 'bill', 'category', 'contact')->expense()->collectForExport($this->ids, ['paid_at' => 'desc']);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class BillHistories extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::bill()->with('document')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('document')->bill()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class BillItemTaxes extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::bill()->with('document', 'item', 'tax')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('document', 'item', 'tax')->bill()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class BillItems extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::bill()->with('document', 'item')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('document', 'item')->bill()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class BillTotals extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::bill()->with('document')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('document')->bill()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -11,13 +11,7 @@ class BillTransactions extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('account', 'category', 'contact', 'document')->expense()->isDocument()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('account', 'category', 'contact', 'document')->expense()->isDocument()->collectForExport($this->ids, ['paid_at' => 'desc'], 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -11,13 +11,7 @@ class Bills extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::bill()->with('category')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('category')->bill()->collectForExport($this->ids, ['document_number' => 'desc']);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class Vendors extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::type('vendor')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::vendor()->collectForExport($this->ids);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
|
@ -9,13 +9,7 @@ class Customers extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::type('customer')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::customer()->collectForExport($this->ids);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
|
@ -11,13 +11,7 @@ class Revenues extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('account', 'category', 'contact', 'invoice')->income()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('account', 'category', 'contact', 'invoice')->income()->collectForExport($this->ids, ['paid_at' => 'desc']);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class InvoiceHistories extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::invoice()->with('document')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('document')->invoice()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class InvoiceItemTaxes extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::invoice()->with('document', 'item', 'tax')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('document', 'item', 'tax')->invoice()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class InvoiceItems extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::invoice()->with('document', 'item')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('document', 'item')->invoice()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class InvoiceTotals extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::invoice()->with('document')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('document')->invoice()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -4,8 +4,6 @@ namespace App\Exports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
use App\Models\Document\Document;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
@ -13,13 +11,7 @@ class InvoiceTransactions extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('account', 'category', 'contact', 'document')->income()->isDocument()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('account', 'category', 'contact', 'document')->income()->isDocument()->collectForExport($this->ids, ['paid_at' => 'desc'], 'document_id');
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -11,13 +11,7 @@ class Invoices extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::invoice()->with('category')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::with('category')->invoice()->collectForExport($this->ids, ['document_number' => 'desc']);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
|
@ -9,13 +9,7 @@ class Categories extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
return Model::collectForExport($this->ids);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
|
@ -10,7 +10,7 @@ return [
|
||||
'imported' => ':type imported!',
|
||||
'import_queued' => ':type import has been scheduled! You will receive an email when it is finished.',
|
||||
'exported' => ':type exported!',
|
||||
'export_queued' => ':type export has been scheduled! You will receive an email when it is ready to download.',
|
||||
'export_queued' => ':type export of the current page has been scheduled! You will receive an email when it is ready to download.',
|
||||
'enabled' => ':type enabled!',
|
||||
'disabled' => ':type disabled!',
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user