Seperate Document Import/Export files into Invoice/Bill
This commit is contained in:
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Document;
|
||||
|
||||
use App\Exports\Document\Sheets\Documents as Base;
|
||||
use App\Exports\Document\Sheets\DocumentItems;
|
||||
use App\Exports\Document\Sheets\DocumentItemTaxes;
|
||||
use App\Exports\Document\Sheets\DocumentHistories;
|
||||
use App\Exports\Document\Sheets\DocumentTotals;
|
||||
use App\Exports\Document\Sheets\DocumentTransactions;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Documents implements WithMultipleSheets
|
||||
{
|
||||
public $ids;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
public function __construct($ids = null, string $type = '')
|
||||
{
|
||||
$this->ids = $ids;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
Str::plural($this->type) => new Base($this->ids, $this->type),
|
||||
$this->type . '_items' => new DocumentItems($this->ids, $this->type),
|
||||
$this->type . '_item_taxes' => new DocumentItemTaxes($this->ids, $this->type),
|
||||
$this->type . '_histories' => new DocumentHistories($this->ids, $this->type),
|
||||
$this->type . '_totals' => new DocumentTotals($this->ids, $this->type),
|
||||
$this->type . '_transactions' => new DocumentTransactions($this->ids, $this->type),
|
||||
];
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Document\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentHistory as Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DocumentHistories extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::{$this->type}()->with('document')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$model->invoice_number = $document->document_number;
|
||||
} else {
|
||||
$model->bill_number = $document->document_number;
|
||||
}
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
||||
'status',
|
||||
'notify',
|
||||
'description',
|
||||
];
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return Str::replaceFirst('document', $this->type, parent::title());
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Document\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentTotal as Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DocumentTotals extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::{$this->type}()->with('document')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$model->invoice_number = $document->document_number;
|
||||
} else {
|
||||
$model->bill_number = $document->document_number;
|
||||
}
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
||||
'code',
|
||||
'name',
|
||||
'amount',
|
||||
'sort_order',
|
||||
];
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return Str::replaceFirst('document', $this->type, parent::title());
|
||||
}
|
||||
}
|
33
app/Exports/Purchases/Bills.php
Normal file
33
app/Exports/Purchases/Bills.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases;
|
||||
|
||||
use App\Exports\Purchases\Sheets\Bills as Base;
|
||||
use App\Exports\Purchases\Sheets\BillItems;
|
||||
use App\Exports\Purchases\Sheets\BillItemTaxes;
|
||||
use App\Exports\Purchases\Sheets\BillHistories;
|
||||
use App\Exports\Purchases\Sheets\BillTotals;
|
||||
use App\Exports\Purchases\Sheets\BillTransactions;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Bills implements WithMultipleSheets
|
||||
{
|
||||
public $ids;
|
||||
|
||||
public function __construct($ids = null)
|
||||
{
|
||||
$this->ids = $ids;
|
||||
}
|
||||
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
'bills' => new Base($this->ids),
|
||||
'bill_items' => new BillItems($this->ids),
|
||||
'bill_item_taxes' => new BillItemTaxes($this->ids),
|
||||
'bill_histories' => new BillHistories($this->ids),
|
||||
'bill_totals' => new BillTotals($this->ids),
|
||||
'bill_transactions' => new BillTransactions($this->ids),
|
||||
];
|
||||
}
|
||||
}
|
43
app/Exports/Purchases/Sheets/BillHistories.php
Normal file
43
app/Exports/Purchases/Sheets/BillHistories.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentHistory as Model;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$model->bill_number = $document->document_number;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_number',
|
||||
'status',
|
||||
'notify',
|
||||
'description',
|
||||
];
|
||||
}
|
||||
}
|
@ -1,17 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Document\Sheets;
|
||||
namespace App\Exports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentItemTax as Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DocumentItemTaxes extends Export
|
||||
class BillItemTaxes extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::{$this->type}()->with('document', 'item', 'tax')->usingSearchString(request('search'));
|
||||
$model = Model::bill()->with('document', 'item', 'tax')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
@ -28,12 +26,7 @@ class DocumentItemTaxes extends Export
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$model->invoice_number = $document->document_number;
|
||||
} else {
|
||||
$model->bill_number = $document->document_number;
|
||||
}
|
||||
|
||||
$model->bill_number = $document->document_number;
|
||||
$model->item_name = $model->item->name;
|
||||
$model->tax_rate = $model->tax->rate;
|
||||
|
||||
@ -43,15 +36,10 @@ class DocumentItemTaxes extends Export
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
||||
'bill_number',
|
||||
'item_name',
|
||||
'tax_rate',
|
||||
'amount',
|
||||
];
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return Str::replaceFirst('document', $this->type, parent::title());
|
||||
}
|
||||
}
|
@ -1,17 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Document\Sheets;
|
||||
namespace App\Exports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DocumentItems extends Export
|
||||
class BillItems extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::{$this->type}()->with('document', 'item')->usingSearchString(request('search'));
|
||||
$model = Model::bill()->with('document', 'item')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
@ -28,12 +26,7 @@ class DocumentItems extends Export
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$model->invoice_number = $document->document_number;
|
||||
} else {
|
||||
$model->bill_number = $document->document_number;
|
||||
}
|
||||
|
||||
$model->bill_number = $document->document_number;
|
||||
$model->item_name = $model->item->name;
|
||||
|
||||
return parent::map($model);
|
||||
@ -42,7 +35,7 @@ class DocumentItems extends Export
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
||||
'bill_number',
|
||||
'item_name',
|
||||
'quantity',
|
||||
'price',
|
||||
@ -50,9 +43,4 @@ class DocumentItems extends Export
|
||||
'tax',
|
||||
];
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return Str::replaceFirst('document', $this->type, parent::title());
|
||||
}
|
||||
}
|
44
app/Exports/Purchases/Sheets/BillTotals.php
Normal file
44
app/Exports/Purchases/Sheets/BillTotals.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentTotal as Model;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$model->bill_number = $document->document_number;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_number',
|
||||
'code',
|
||||
'name',
|
||||
'amount',
|
||||
'sort_order',
|
||||
];
|
||||
}
|
||||
}
|
63
app/Exports/Purchases/Sheets/BillTransactions.php
Normal file
63
app/Exports/Purchases/Sheets/BillTransactions.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class BillTransactions extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('account', 'category', 'contact', 'document')->bill()->isDocument()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$model->bill_number = $document->document_number;
|
||||
$model->account_name = $model->account->name;
|
||||
$model->category_name = $model->category->name;
|
||||
$model->contact_email = $model->contact->email;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_number',
|
||||
'paid_at',
|
||||
'amount',
|
||||
'currency_code',
|
||||
'currency_rate',
|
||||
'account_name',
|
||||
'contact_email',
|
||||
'category_name',
|
||||
'description',
|
||||
'payment_method',
|
||||
'reference',
|
||||
'reconciled',
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
];
|
||||
}
|
||||
}
|
59
app/Exports/Purchases/Sheets/Bills.php
Normal file
59
app/Exports/Purchases/Sheets/Bills.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document as Model;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class Bills extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::bill()->with('category')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->category_name = $model->category->name;
|
||||
$model->bill_number = $model->document_number;
|
||||
$model->billed_at = $model->issued_at;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_number',
|
||||
'order_number',
|
||||
'status',
|
||||
'billed_at',
|
||||
'due_at',
|
||||
'amount',
|
||||
'currency_code',
|
||||
'currency_rate',
|
||||
'category_name',
|
||||
'contact_name',
|
||||
'contact_email',
|
||||
'contact_tax_number',
|
||||
'contact_phone',
|
||||
'contact_address',
|
||||
'notes',
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'D' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
'E' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
];
|
||||
}
|
||||
}
|
33
app/Exports/Sales/Invoices.php
Normal file
33
app/Exports/Sales/Invoices.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales;
|
||||
|
||||
use App\Exports\Sales\Sheets\Invoices as Base;
|
||||
use App\Exports\Sales\Sheets\InvoiceItems;
|
||||
use App\Exports\Sales\Sheets\InvoiceItemTaxes;
|
||||
use App\Exports\Sales\Sheets\InvoiceHistories;
|
||||
use App\Exports\Sales\Sheets\InvoiceTotals;
|
||||
use App\Exports\Sales\Sheets\InvoiceTransactions;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Invoices implements WithMultipleSheets
|
||||
{
|
||||
public $ids;
|
||||
|
||||
public function __construct($ids = null)
|
||||
{
|
||||
$this->ids = $ids;
|
||||
}
|
||||
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
'invoices' => new Base($this->ids),
|
||||
'invoice_items' => new InvoiceItems($this->ids),
|
||||
'invoice_item_taxes' => new InvoiceItemTaxes($this->ids),
|
||||
'invoice_histories' => new InvoiceHistories($this->ids),
|
||||
'invoice_totals' => new InvoiceTotals($this->ids),
|
||||
'invoice_transactions' => new InvoiceTransactions($this->ids),
|
||||
];
|
||||
}
|
||||
}
|
43
app/Exports/Sales/Sheets/InvoiceHistories.php
Normal file
43
app/Exports/Sales/Sheets/InvoiceHistories.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentHistory as Model;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$model->invoice_number = $document->document_number;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'invoice_number',
|
||||
'status',
|
||||
'notify',
|
||||
'description',
|
||||
];
|
||||
}
|
||||
}
|
45
app/Exports/Sales/Sheets/InvoiceItemTaxes.php
Normal file
45
app/Exports/Sales/Sheets/InvoiceItemTaxes.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentItemTax as Model;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$model->invoice_number = $document->document_number;
|
||||
$model->item_name = $model->item->name;
|
||||
$model->tax_rate = $model->tax->rate;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'invoice_number',
|
||||
'item_name',
|
||||
'tax_rate',
|
||||
'amount',
|
||||
];
|
||||
}
|
||||
}
|
46
app/Exports/Sales/Sheets/InvoiceItems.php
Normal file
46
app/Exports/Sales/Sheets/InvoiceItems.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$model->invoice_number = $document->document_number;
|
||||
$model->item_name = $model->item->name;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'invoice_number',
|
||||
'item_name',
|
||||
'quantity',
|
||||
'price',
|
||||
'total',
|
||||
'tax',
|
||||
];
|
||||
}
|
||||
}
|
44
app/Exports/Sales/Sheets/InvoiceTotals.php
Normal file
44
app/Exports/Sales/Sheets/InvoiceTotals.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentTotal as Model;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$document = $model->document;
|
||||
|
||||
if (empty($document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$model->invoice_number = $document->document_number;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'invoice_number',
|
||||
'code',
|
||||
'name',
|
||||
'amount',
|
||||
'sort_order',
|
||||
];
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Document\Sheets;
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
@ -9,11 +9,11 @@ use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class DocumentTransactions extends Export implements WithColumnFormatting
|
||||
class InvoiceTransactions extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('account', 'category', 'contact', 'document')->{$this->type}()->isDocument()->usingSearchString(request('search'));
|
||||
$model = Model::with('account', 'category', 'contact', 'document')->invoice()->isDocument()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
@ -30,12 +30,7 @@ class DocumentTransactions extends Export implements WithColumnFormatting
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$model->invoice_number = $document->document_number;
|
||||
} else {
|
||||
$model->bill_number = $document->document_number;
|
||||
}
|
||||
|
||||
$model->invoice_number = $document->document_number;
|
||||
$model->account_name = $model->account->name;
|
||||
$model->category_name = $model->category->name;
|
||||
$model->contact_email = $model->contact->email;
|
||||
@ -46,7 +41,7 @@ class DocumentTransactions extends Export implements WithColumnFormatting
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
||||
'invoice_number',
|
||||
'paid_at',
|
||||
'amount',
|
||||
'currency_code',
|
||||
@ -67,9 +62,4 @@ class DocumentTransactions extends Export implements WithColumnFormatting
|
||||
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
];
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return Str::replaceFirst('document', $this->type, parent::title());
|
||||
}
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Document\Sheets;
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document as Model;
|
||||
use Illuminate\Support\Str;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class Documents extends Export
|
||||
class Invoices extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::{$this->type}()->with('category')->usingSearchString(request('search'));
|
||||
$model = Model::invoice()->with('category')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
@ -23,14 +22,8 @@ class Documents extends Export
|
||||
public function map($model): array
|
||||
{
|
||||
$model->category_name = $model->category->name;
|
||||
|
||||
if ($this->type === Model::INVOICE_TYPE) {
|
||||
$model->invoice_number = $model->document_number;
|
||||
$model->invoiced_at = $model->issued_at;
|
||||
} else {
|
||||
$model->bill_number = $model->document_number;
|
||||
$model->billed_at = $model->issued_at;
|
||||
}
|
||||
$model->invoice_number = $model->document_number;
|
||||
$model->invoiced_at = $model->issued_at;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
@ -38,10 +31,10 @@ class Documents extends Export
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
$this->type === Model::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
||||
'invoice_number',
|
||||
'order_number',
|
||||
'status',
|
||||
$this->type === Model::INVOICE_TYPE ? 'invoiced_at' : 'billed_at',
|
||||
'invoiced_at',
|
||||
'due_at',
|
||||
'amount',
|
||||
'currency_code',
|
||||
@ -57,11 +50,6 @@ class Documents extends Export
|
||||
];
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return Str::replaceFirst('document', $this->type, parent::title());
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
Reference in New Issue
Block a user