added import and export recurring bills
This commit is contained in:
36
app/Exports/Purchases/Bills/Bills.php
Normal file
36
app/Exports/Purchases/Bills/Bills.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Bills;
|
||||
|
||||
use App\Exports\Purchases\Bills\Sheets\Bills as Base;
|
||||
use App\Exports\Purchases\Bills\Sheets\BillItems;
|
||||
use App\Exports\Purchases\Bills\Sheets\BillItemTaxes;
|
||||
use App\Exports\Purchases\Bills\Sheets\BillHistories;
|
||||
use App\Exports\Purchases\Bills\Sheets\BillTotals;
|
||||
use App\Exports\Purchases\Bills\Sheets\BillTransactions;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Bills implements WithMultipleSheets
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
public $ids;
|
||||
|
||||
public function __construct($ids = null)
|
||||
{
|
||||
$this->ids = $ids;
|
||||
}
|
||||
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
new Base($this->ids),
|
||||
new BillItems($this->ids),
|
||||
new BillItemTaxes($this->ids),
|
||||
new BillHistories($this->ids),
|
||||
new BillTotals($this->ids),
|
||||
new BillTransactions($this->ids),
|
||||
];
|
||||
}
|
||||
}
|
||||
37
app/Exports/Purchases/Bills/Sheets/BillHistories.php
Normal file
37
app/Exports/Purchases/Bills/Sheets/BillHistories.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Bills\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentHistory as Model;
|
||||
|
||||
class BillHistories extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('document')->bill()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
39
app/Exports/Purchases/Bills/Sheets/BillItemTaxes.php
Normal file
39
app/Exports/Purchases/Bills/Sheets/BillItemTaxes.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Bills\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentItemTax as Model;
|
||||
|
||||
class BillItemTaxes extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('document', 'item', 'tax')->bill()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
44
app/Exports/Purchases/Bills/Sheets/BillItems.php
Normal file
44
app/Exports/Purchases/Bills/Sheets/BillItems.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Bills\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
|
||||
class BillItems extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('document', 'item')->bill()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
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->item_description = $model->item->description;
|
||||
$model->item_type = $model->item->type;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_number',
|
||||
'item_name',
|
||||
'item_description',
|
||||
'item_type',
|
||||
'quantity',
|
||||
'price',
|
||||
'total',
|
||||
'tax',
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Exports/Purchases/Bills/Sheets/BillTotals.php
Normal file
38
app/Exports/Purchases/Bills/Sheets/BillTotals.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Bills\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\DocumentTotal as Model;
|
||||
|
||||
class BillTotals extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('document')->bill()->collectForExport($this->ids, null, 'document_id');
|
||||
}
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
59
app/Exports/Purchases/Bills/Sheets/BillTransactions.php
Normal file
59
app/Exports/Purchases/Bills/Sheets/BillTransactions.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Bills\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()
|
||||
{
|
||||
return Model::with('account', 'category', 'contact', 'document')->expense()->isDocument()->collectForExport($this->ids, ['paid_at' => 'desc'], 'document_id');
|
||||
}
|
||||
|
||||
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;
|
||||
$model->transaction_number = $model->number;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_number',
|
||||
'transaction_number',
|
||||
'paid_at',
|
||||
'amount',
|
||||
'currency_code',
|
||||
'currency_rate',
|
||||
'account_name',
|
||||
'contact_email',
|
||||
'category_name',
|
||||
'description',
|
||||
'payment_method',
|
||||
'reference',
|
||||
'reconciled',
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'C' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
];
|
||||
}
|
||||
}
|
||||
67
app/Exports/Purchases/Bills/Sheets/Bills.php
Normal file
67
app/Exports/Purchases/Bills/Sheets/Bills.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Purchases\Bills\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Document\Document as Model;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class Bills extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Model::with('category')->bill()->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->bill_number = $model->document_number;
|
||||
$model->billed_at = $model->issued_at;
|
||||
$model->contact_country = $country;
|
||||
$model->parent_number = Model::billRecurring()->find($model->parent_id)?->document_number;
|
||||
|
||||
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',
|
||||
'contact_country',
|
||||
'contact_state',
|
||||
'contact_zip_code',
|
||||
'contact_city',
|
||||
'notes',
|
||||
'parent_number'
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'D' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
'E' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user