Merge Invoice and Bill into Document

This commit is contained in:
Burak Çakırel
2020-12-24 01:28:38 +03:00
parent 830cc05957
commit 0c1424db47
436 changed files with 31655 additions and 37350 deletions

View File

@@ -25,9 +25,9 @@ class Transactions extends Export
$model->category_name = $model->category->name;
if ($model->type == 'income') {
$model->invoice_bill_number = $model->invoice ? $model->invoice->invoice_number : 0;
$model->invoice_bill_number = $model->invoice->document_number ?? 0;
} else {
$model->invoice_bill_number = $model->bill ? $model->bill->bill_number : 0;
$model->invoice_bill_number = $model->bill->document_number ?? 0;
}
return parent::map($model);

View File

@@ -0,0 +1,40 @@
<?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),
];
}
}

View File

@@ -0,0 +1,54 @@
<?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());
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Exports\Document\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
{
public function collection()
{
$model = Model::{$this->type}()->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 [];
}
if ($this->type === Document::INVOICE_TYPE) {
$model->invoice_number = $document->document_number;
} else {
$model->bill_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 [
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
'item_name',
'tax_rate',
'amount',
];
}
public function title(): string
{
return Str::replaceFirst('document', $this->type, parent::title());
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Exports\Document\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
{
public function collection()
{
$model = Model::{$this->type}()->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 [];
}
if ($this->type === Document::INVOICE_TYPE) {
$model->invoice_number = $document->document_number;
} else {
$model->bill_number = $document->document_number;
}
$model->item_name = $model->item->name;
return parent::map($model);
}
public function fields(): array
{
return [
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
'item_name',
'quantity',
'price',
'total',
'tax',
];
}
public function title(): string
{
return Str::replaceFirst('document', $this->type, parent::title());
}
}

View File

@@ -0,0 +1,55 @@
<?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());
}
}

View File

@@ -1,17 +1,19 @@
<?php
namespace App\Exports\Purchases\Sheets;
namespace App\Exports\Document\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 BillTransactions extends Export implements WithColumnFormatting
class DocumentTransactions extends Export implements WithColumnFormatting
{
public function collection()
{
$model = Model::with('account', 'category', 'contact', 'bill')->expense()->isDocument()->usingSearchString(request('search'));
$model = Model::with('account', 'category', 'contact', 'document')->income()->isDocument()->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('document_id', (array) $this->ids);
@@ -22,13 +24,18 @@ class BillTransactions extends Export implements WithColumnFormatting
public function map($model): array
{
$bill = $model->bill;
$document = $model->document;
if (empty($bill)) {
if (empty($document)) {
return [];
}
$model->bill_number = $bill->bill_number;
if ($this->type === Document::INVOICE_TYPE) {
$model->invoice_number = $document->document_number;
} else {
$model->bill_number = $document->document_number;
}
$model->account_name = $model->account->name;
$model->category_name = $model->category->name;
$model->contact_email = $model->contact->email;
@@ -39,7 +46,7 @@ class BillTransactions extends Export implements WithColumnFormatting
public function fields(): array
{
return [
'bill_number',
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
'paid_at',
'amount',
'currency_code',
@@ -60,4 +67,9 @@ class BillTransactions extends Export implements WithColumnFormatting
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
public function title(): string
{
return Str::replaceFirst('document', $this->type, parent::title());
}
}

View File

@@ -1,17 +1,17 @@
<?php
namespace App\Exports\Sales\Sheets;
namespace App\Exports\Document\Sheets;
use App\Abstracts\Export;
use App\Models\Sale\Invoice as Model;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use App\Models\Document\Document as Model;
use Illuminate\Support\Str;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class Invoices extends Export implements WithColumnFormatting
class Documents extends Export
{
public function collection()
{
$model = Model::with('category')->usingSearchString(request('search'));
$model = Model::{$this->type}()->with('category')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);
@@ -24,16 +24,24 @@ class Invoices extends Export implements WithColumnFormatting
{
$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;
}
return parent::map($model);
}
public function fields(): array
{
return [
'invoice_number',
$this->type === Model::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
'order_number',
'status',
'invoiced_at',
$this->type === Model::INVOICE_TYPE ? 'invoiced_at' : 'billed_at',
'due_at',
'amount',
'currency_code',
@@ -49,6 +57,11 @@ class Invoices extends Export implements WithColumnFormatting
];
}
public function title(): string
{
return Str::replaceFirst('document', $this->type, parent::title());
}
public function columnFormats(): array
{
return [

View File

@@ -1,33 +0,0 @@
<?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),
];
}
}

View File

@@ -21,7 +21,7 @@ class Payments extends Export
public function map($model): array
{
$model->account_name = $model->account->name;
$model->bill_number = $model->bill ? $model->bill->bill_number : 0;
$model->bill_number = $model->bill->document_number ?? 0;
$model->contact_email = $model->contact->email;
$model->category_name = $model->category->name;

View File

@@ -1,43 +0,0 @@
<?php
namespace App\Exports\Purchases\Sheets;
use App\Abstracts\Export;
use App\Models\Purchase\BillHistory as Model;
class BillHistories extends Export
{
public function collection()
{
$model = Model::with('bill')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('bill_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$bill = $model->bill;
if (empty($bill)) {
return [];
}
$model->bill_number = $bill->bill_number;
return parent::map($model);
}
public function fields(): array
{
return [
'bill_number',
'status',
'notify',
'description',
];
}
}

View File

@@ -1,45 +0,0 @@
<?php
namespace App\Exports\Purchases\Sheets;
use App\Abstracts\Export;
use App\Models\Purchase\BillItemTax as Model;
class BillItemTaxes extends Export
{
public function collection()
{
$model = Model::with('bill', 'item', 'tax')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('bill_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$bill = $model->bill;
if (empty($bill)) {
return [];
}
$model->bill_number = $bill->bill_number;
$model->item_name = $model->item->name;
$model->tax_rate = $model->tax->rate;
return parent::map($model);
}
public function fields(): array
{
return [
'bill_number',
'item_name',
'tax_rate',
'amount',
];
}
}

View File

@@ -1,46 +0,0 @@
<?php
namespace App\Exports\Purchases\Sheets;
use App\Abstracts\Export;
use App\Models\Purchase\BillItem as Model;
class BillItems extends Export
{
public function collection()
{
$model = Model::with('bill', 'item')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('bill_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$bill = $model->bill;
if (empty($bill)) {
return [];
}
$model->bill_number = $bill->bill_number;
$model->item_name = $model->item->name;
return parent::map($model);
}
public function fields(): array
{
return [
'bill_number',
'item_name',
'quantity',
'price',
'total',
'tax',
];
}
}

View File

@@ -1,44 +0,0 @@
<?php
namespace App\Exports\Purchases\Sheets;
use App\Abstracts\Export;
use App\Models\Purchase\BillTotal as Model;
class BillTotals extends Export
{
public function collection()
{
$model = Model::with('bill')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('bill_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$bill = $model->bill;
if (empty($bill)) {
return [];
}
$model->bill_number = $bill->bill_number;
return parent::map($model);
}
public function fields(): array
{
return [
'bill_number',
'code',
'name',
'amount',
'sort_order',
];
}
}

View File

@@ -1,59 +0,0 @@
<?php
namespace App\Exports\Purchases\Sheets;
use App\Abstracts\Export;
use App\Models\Purchase\Bill as Model;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class Bills extends Export implements WithColumnFormatting
{
public function collection()
{
$model = Model::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;
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',
'footer',
];
}
public function columnFormats(): array
{
return [
'D' => NumberFormat::FORMAT_DATE_YYYYMMDD,
'E' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
}

View File

@@ -1,33 +0,0 @@
<?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),
];
}
}

View File

@@ -21,7 +21,7 @@ class Revenues extends Export
public function map($model): array
{
$model->account_name = $model->account->name;
$model->invoice_number = $model->invoice ? $model->invoice->invoice_number : 0;
$model->invoice_number = $model->invoice->document_number ?? 0;
$model->contact_email = $model->contact->email;
$model->category_name = $model->category->name;

View File

@@ -1,43 +0,0 @@
<?php
namespace App\Exports\Sales\Sheets;
use App\Abstracts\Export;
use App\Models\Sale\InvoiceHistory as Model;
class InvoiceHistories extends Export
{
public function collection()
{
$model = Model::with('invoice')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$invoice = $model->invoice;
if (empty($invoice)) {
return [];
}
$model->invoice_number = $invoice->invoice_number;
return parent::map($model);
}
public function fields(): array
{
return [
'invoice_number',
'status',
'notify',
'description',
];
}
}

View File

@@ -1,45 +0,0 @@
<?php
namespace App\Exports\Sales\Sheets;
use App\Abstracts\Export;
use App\Models\Sale\InvoiceItemTax as Model;
class InvoiceItemTaxes extends Export
{
public function collection()
{
$model = Model::with('invoice', 'item', 'tax')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$invoice = $model->invoice;
if (empty($invoice)) {
return [];
}
$model->invoice_number = $invoice->invoice_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

@@ -1,46 +0,0 @@
<?php
namespace App\Exports\Sales\Sheets;
use App\Abstracts\Export;
use App\Models\Sale\InvoiceItem as Model;
class InvoiceItems extends Export
{
public function collection()
{
$model = Model::with('invoice', 'item')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$invoice = $model->invoice;
if (empty($invoice)) {
return [];
}
$model->invoice_number = $invoice->invoice_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

@@ -1,44 +0,0 @@
<?php
namespace App\Exports\Sales\Sheets;
use App\Abstracts\Export;
use App\Models\Sale\InvoiceTotal as Model;
class InvoiceTotals extends Export
{
public function collection()
{
$model = Model::with('invoice')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$invoice = $model->invoice;
if (empty($invoice)) {
return [];
}
$model->invoice_number = $invoice->invoice_number;
return parent::map($model);
}
public function fields(): array
{
return [
'invoice_number',
'code',
'name',
'amount',
'sort_order',
];
}
}

View File

@@ -1,63 +0,0 @@
<?php
namespace App\Exports\Sales\Sheets;
use App\Abstracts\Export;
use App\Models\Banking\Transaction as Model;
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', 'invoice')->income()->isDocument()->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('document_id', (array) $this->ids);
}
return $model->cursor();
}
public function map($model): array
{
$invoice = $model->invoice;
if (empty($invoice)) {
return [];
}
$model->invoice_number = $invoice->invoice_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,
];
}
}