Seperate Document Import/Export files into Invoice/Bill

This commit is contained in:
Burak Çakırel
2020-12-25 19:25:38 +03:00
parent de3c22299c
commit 3b965a39d2
45 changed files with 981 additions and 539 deletions

View 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',
];
}
}

View 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',
];
}
}

View 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',
];
}
}

View 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',
];
}
}

View File

@@ -0,0 +1,65 @@
<?php
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;
class InvoiceTransactions extends Export implements WithColumnFormatting
{
public function collection()
{
$model = Model::with('account', 'category', 'contact', 'document')->invoice()->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->invoice_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 [
'invoice_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,
];
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Exports\Sales\Sheets;
use App\Abstracts\Export;
use App\Models\Document\Document as Model;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class Invoices extends Export
{
public function collection()
{
$model = Model::invoice()->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->invoice_number = $model->document_number;
$model->invoiced_at = $model->issued_at;
return parent::map($model);
}
public function fields(): array
{
return [
'invoice_number',
'order_number',
'status',
'invoiced_at',
'due_at',
'amount',
'currency_code',
'currency_rate',
'category_name',
'contact_name',
'contact_email',
'contact_tax_number',
'contact_phone',
'contact_address',
'notes',
'footer',
];
}
public function columnFormats(): array
{
return [
'D' => NumberFormat::FORMAT_DATE_YYYYMMDD,
'E' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
}