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

@@ -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,63 +0,0 @@
<?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', 'bill')->expense()->isDocument()->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('document_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->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

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