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

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Exports\Purchases\Sheets;
use App\Abstracts\Export;
use App\Models\Document\DocumentItemTax as Model;
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();
}
public function map($model): array
{
$document = $model->document;
if (empty($document)) {
return [];
}
$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 [
'bill_number',
'item_name',
'tax_rate',
'amount',
];
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Exports\Purchases\Sheets;
use App\Abstracts\Export;
use App\Models\Document\DocumentItem as Model;
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();
}
public function map($model): array
{
$document = $model->document;
if (empty($document)) {
return [];
}
$model->bill_number = $document->document_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

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

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

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