added import and export recurring invoices
This commit is contained in:
46
app/Imports/Sales/Invoices/Sheets/InvoiceHistories.php
Normal file
46
app/Imports/Sales/Invoices/Sheets/InvoiceHistories.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Invoices\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 InvoiceHistories 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::invoice()->number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
$row['notify'] = (int) $row['notify'];
|
||||
|
||||
$row['type'] = Document::INVOICE_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
64
app/Imports/Sales/Invoices/Sheets/InvoiceItemTaxes.php
Normal file
64
app/Imports/Sales/Invoices/Sheets/InvoiceItemTaxes.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Invoices\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 InvoiceItemTaxes 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);
|
||||
|
||||
$document = Document::with('items')->invoice()->number($row['invoice_number'])->first();
|
||||
|
||||
$row['document_id'] = (int) $document->id;
|
||||
|
||||
if (empty($row['document_item_id']) && !empty($row['item_name'])) {
|
||||
$document_items_ids = $document->items->pluck('item_id')->toArray();
|
||||
|
||||
$item_id = Item::name($row['item_name'])->whereIn('id', $document_items_ids)->pluck('id')->first();
|
||||
|
||||
$row['document_item_id'] = DocumentItem::invoice()->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_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
54
app/Imports/Sales/Invoices/Sheets/InvoiceItems.php
Normal file
54
app/Imports/Sales/Invoices/Sheets/InvoiceItems.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Invoices\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 InvoiceItems 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::invoice()->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_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
43
app/Imports/Sales/Invoices/Sheets/InvoiceTotals.php
Normal file
43
app/Imports/Sales/Invoices/Sheets/InvoiceTotals.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Invoices\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 InvoiceTotals 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::invoice()->number($row['invoice_number'])->pluck('id')->first();
|
||||
$row['type'] = Document::INVOICE_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
45
app/Imports/Sales/Invoices/Sheets/InvoiceTransactions.php
Normal file
45
app/Imports/Sales/Invoices/Sheets/InvoiceTransactions.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Invoices\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
|
||||
class InvoiceTransactions 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['type'] = 'income';
|
||||
$row['currency_code'] = $this->getCurrencyCode($row);
|
||||
$row['account_id'] = $this->getAccountId($row);
|
||||
$row['category_id'] = $this->getCategoryId($row, 'income');
|
||||
$row['contact_id'] = $this->getContactId($row, 'customer');
|
||||
$row['document_id'] = $this->getDocumentId($row);
|
||||
$row['number'] = $row['transaction_number'];
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function prepareRules(array $rules): array
|
||||
{
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
53
app/Imports/Sales/Invoices/Sheets/Invoices.php
Normal file
53
app/Imports/Sales/Invoices/Sheets/Invoices.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Invoices\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 Invoices 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_TYPE;
|
||||
$row['contact_country'] = !empty($country) ? $country : null;
|
||||
$row['parent_id'] = $this->getParentId($row) ?? 0;
|
||||
|
||||
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