added import and export recurring invoices
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales;
|
||||
namespace App\Exports\Sales\Invoices;
|
||||
|
||||
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 App\Exports\Sales\Invoices\Sheets\Invoices as Base;
|
||||
use App\Exports\Sales\Invoices\Sheets\InvoiceItems;
|
||||
use App\Exports\Sales\Invoices\Sheets\InvoiceItemTaxes;
|
||||
use App\Exports\Sales\Invoices\Sheets\InvoiceHistories;
|
||||
use App\Exports\Sales\Invoices\Sheets\InvoiceTotals;
|
||||
use App\Exports\Sales\Invoices\Sheets\InvoiceTransactions;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
namespace App\Exports\Sales\Invoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentHistory as Model;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
namespace App\Exports\Sales\Invoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentItemTax as Model;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
namespace App\Exports\Sales\Invoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
namespace App\Exports\Sales\Invoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentTotal as Model;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
namespace App\Exports\Sales\Invoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\Sheets;
|
||||
namespace App\Exports\Sales\Invoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document as Model;
|
||||
36
app/Exports/Sales/RecurringInvoices/RecurringInvoices.php
Normal file
36
app/Exports/Sales/RecurringInvoices/RecurringInvoices.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\RecurringInvoices;
|
||||
|
||||
use App\Exports\Sales\RecurringInvoices\Sheets\Recurring;
|
||||
use App\Exports\Sales\RecurringInvoices\Sheets\RecurringInvoices as Base;
|
||||
use App\Exports\Sales\RecurringInvoices\Sheets\RecurringInvoiceItems;
|
||||
use App\Exports\Sales\RecurringInvoices\Sheets\RecurringInvoiceItemTaxes;
|
||||
use App\Exports\Sales\RecurringInvoices\Sheets\RecurringInvoiceHistories;
|
||||
use App\Exports\Sales\RecurringInvoices\Sheets\RecurringInvoiceTotals;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class RecurringInvoices implements WithMultipleSheets
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
public $ids;
|
||||
|
||||
public function __construct($ids = null)
|
||||
{
|
||||
$this->ids = $ids;
|
||||
}
|
||||
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
new Recurring($this->ids),
|
||||
new Base($this->ids),
|
||||
new RecurringInvoiceItems($this->ids),
|
||||
new RecurringInvoiceItemTaxes($this->ids),
|
||||
new RecurringInvoiceHistories($this->ids),
|
||||
new RecurringInvoiceTotals($this->ids),
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Exports/Sales/RecurringInvoices/Sheets/Recurring.php
Normal file
36
app/Exports/Sales/RecurringInvoices/Sheets/Recurring.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Common\Recurring as Model;
|
||||
|
||||
class Recurring extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::invoice()->cursor();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->invoice_number = $model->recurable->document_number;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'recurable_type',
|
||||
'invoice_number',
|
||||
'frequency',
|
||||
'interval',
|
||||
'started_at',
|
||||
'status',
|
||||
'limit_by',
|
||||
'limit_count',
|
||||
'auto_send',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentHistory as Model;
|
||||
|
||||
class RecurringInvoiceHistories extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('document')->invoiceRecurring()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentItemTax as Model;
|
||||
|
||||
class RecurringInvoiceItemTaxes extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('document', 'item', 'tax')->invoiceRecurring()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
|
||||
class RecurringInvoiceItems extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('document', 'item')->invoiceRecurring()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
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->item_description = $model->item->description;
|
||||
$model->item_type = $model->item->type;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'invoice_number',
|
||||
'item_name',
|
||||
'item_description',
|
||||
'item_type',
|
||||
'quantity',
|
||||
'price',
|
||||
'total',
|
||||
'tax',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentTotal as Model;
|
||||
|
||||
class RecurringInvoiceTotals extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('document')->invoiceRecurring()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document as Model;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class RecurringInvoices extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('category')->invoiceRecurring()->collectForExport($this->ids, ['document_number' => 'desc']);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$country = null;
|
||||
|
||||
if ($model->contact_country && array_key_exists($model->contact_country, trans('countries'))) {
|
||||
$country = trans('countries.' . $model->contact_country);
|
||||
}
|
||||
|
||||
$model->category_name = $model->category->name;
|
||||
$model->invoice_number = $model->document_number;
|
||||
$model->invoiced_at = $model->issued_at;
|
||||
$model->contact_country = $country;
|
||||
|
||||
|
||||
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',
|
||||
'contact_country',
|
||||
'contact_state',
|
||||
'contact_zip_code',
|
||||
'contact_city',
|
||||
'notes',
|
||||
'footer',
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'D' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
'E' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user