Merge Invoice and Bill into Document
This commit is contained in:
		@@ -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),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,59 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Exports\Sales\Sheets;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Export;
 | 
			
		||||
use App\Models\Sale\Invoice as Model;
 | 
			
		||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
 | 
			
		||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
 | 
			
		||||
 | 
			
		||||
class Invoices 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 [
 | 
			
		||||
            '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,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user