added import and export recurring invoices
This commit is contained in:
26
app/Imports/Sales/RecurringInvoices/RecurringInvoices.php
Normal file
26
app/Imports/Sales/RecurringInvoices/RecurringInvoices.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\RecurringInvoices;
|
||||
|
||||
use App\Abstracts\ImportMultipleSheets;
|
||||
use App\Imports\Sales\RecurringInvoices\Sheets\Recurring;
|
||||
use App\Imports\Sales\RecurringInvoices\Sheets\RecurringInvoices as Base;
|
||||
use App\Imports\Sales\RecurringInvoices\Sheets\RecurringInvoiceItems;
|
||||
use App\Imports\Sales\RecurringInvoices\Sheets\RecurringInvoiceItemTaxes;
|
||||
use App\Imports\Sales\RecurringInvoices\Sheets\RecurringInvoiceHistories;
|
||||
use App\Imports\Sales\RecurringInvoices\Sheets\RecurringInvoiceTotals;
|
||||
|
||||
class RecurringInvoices extends ImportMultipleSheets
|
||||
{
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
'recurring_invoices' => new Base(),
|
||||
'recurring_invoice_items' => new RecurringInvoiceItems(),
|
||||
'recurring_invoice_item_taxes' => new RecurringInvoiceItemTaxes(),
|
||||
'recurring_invoice_histories' => new RecurringInvoiceHistories(),
|
||||
'recurring_invoice_totals' => new RecurringInvoiceTotals(),
|
||||
'recurring' => new Recurring(),
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Imports/Sales/RecurringInvoices/Sheets/Recurring.php
Normal file
27
app/Imports/Sales/RecurringInvoices/Sheets/Recurring.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Common\Recurring as Model;
|
||||
use Modules\BackupRestore\Abstracts\Import;
|
||||
|
||||
class Recurring extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['recurable_id'] = (int) Document::where('type', '=', Document::INVOICE_RECURRING_TYPE)
|
||||
->number($row['invoice_number'])
|
||||
->pluck('id')
|
||||
->first();
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Document\DocumentHistory as Request;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentHistory as Model;
|
||||
|
||||
class RecurringInvoiceHistories extends Import
|
||||
{
|
||||
public $request_class = Request::class;
|
||||
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row['invoice_number'] = (string) $row['invoice_number'];
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::where('type', '=', Document::INVOICE_RECURRING_TYPE)
|
||||
->number($row['invoice_number'])
|
||||
->pluck('id')
|
||||
->first();
|
||||
|
||||
$row['notify'] = (int) $row['notify'];
|
||||
|
||||
$row['type'] = Document::INVOICE_RECURRING_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Document\DocumentItemTax as Request;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentItem;
|
||||
use App\Models\Document\DocumentItemTax as Model;
|
||||
|
||||
class RecurringInvoiceItemTaxes extends Import
|
||||
{
|
||||
public $request_class = Request::class;
|
||||
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row['invoice_number'] = (string) $row['invoice_number'];
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::where('type', '=', Document::INVOICE_RECURRING_TYPE)
|
||||
->number($row['invoice_number'])
|
||||
->pluck('id')
|
||||
->first();
|
||||
|
||||
if (empty($row['document_item_id']) && !empty($row['item_name'])) {
|
||||
$item_id = Item::name($row['item_name'])->pluck('id')->first();
|
||||
|
||||
$row['document_item_id'] = DocumentItem::where('type', '=', Document::INVOICE_RECURRING_TYPE)
|
||||
->where('item_id', $item_id)
|
||||
->pluck('id')
|
||||
->first();
|
||||
}
|
||||
|
||||
$row['tax_id'] = $this->getTaxId($row);
|
||||
|
||||
if (empty($row['name']) && !empty($row['item_name'])) {
|
||||
$row['name'] = $row['item_name'];
|
||||
}
|
||||
|
||||
$row['amount'] = (double) $row['amount'];
|
||||
|
||||
$row['type'] = Document::INVOICE_RECURRING_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Document\DocumentItem as Request;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
|
||||
class RecurringInvoiceItems extends Import
|
||||
{
|
||||
public $request_class = Request::class;
|
||||
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row['invoice_number'] = (string) $row['invoice_number'];
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::where('type', '=', Document::INVOICE_RECURRING_TYPE)
|
||||
->number($row['invoice_number'])
|
||||
->pluck('id')
|
||||
->first();
|
||||
|
||||
if (empty($row['item_id']) && ! empty($row['item_name'])) {
|
||||
$row['item_id'] = $this->getItemIdFromName($row);
|
||||
|
||||
$row['name'] = $row['item_name'];
|
||||
}
|
||||
|
||||
$row['description'] = !empty($row['item_description']) ? $row['item_description'] : '';
|
||||
|
||||
$row['tax'] = (double) $row['tax'];
|
||||
$row['tax_id'] = 0;
|
||||
$row['type'] = Document::INVOICE_RECURRING_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Document\DocumentTotal as Request;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentTotal as Model;
|
||||
|
||||
class RecurringInvoiceTotals extends Import
|
||||
{
|
||||
public $request_class = Request::class;
|
||||
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row['invoice_number'] = (string) $row['invoice_number'];
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::where('type', '=', Document::INVOICE_RECURRING_TYPE)
|
||||
->number($row['invoice_number'])
|
||||
->pluck('id')
|
||||
->first();
|
||||
|
||||
$row['type'] = Document::INVOICE_RECURRING_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\RecurringInvoices\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Document\Document as Request;
|
||||
use App\Models\Document\Document as Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RecurringInvoices extends Import
|
||||
{
|
||||
public $request_class = Request::class;
|
||||
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row['invoice_number'] = (string) $row['invoice_number'];
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$country = array_search($row['contact_country'], trans('countries'));
|
||||
|
||||
$row['document_number'] = $row['invoice_number'];
|
||||
$row['issued_at'] = $row['invoiced_at'];
|
||||
$row['category_id'] = $this->getCategoryId($row, 'income');
|
||||
$row['contact_id'] = $this->getContactId($row, 'customer');
|
||||
$row['currency_code'] = $this->getCurrencyCode($row);
|
||||
$row['type'] = Model::INVOICE_RECURRING_TYPE;
|
||||
$row['contact_country'] = !empty($country) ? $country : null;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = Str::replaceFirst('unique:documents,NULL', 'unique:documents,document_number', $rules['document_number']);
|
||||
$rules['invoiced_at'] = $rules['issued_at'];
|
||||
$rules['currency_rate'] = 'required|gt:0';
|
||||
|
||||
unset($rules['document_number'], $rules['issued_at'], $rules['type']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user