human friendly invoice import/export
This commit is contained in:
@@ -7,7 +7,7 @@ use App\Imports\Sales\Sheets\InvoiceItems;
|
||||
use App\Imports\Sales\Sheets\InvoiceItemTaxes;
|
||||
use App\Imports\Sales\Sheets\InvoiceHistories;
|
||||
use App\Imports\Sales\Sheets\InvoiceTotals;
|
||||
use App\Imports\Sales\Sheets\InvoiceTranactions;
|
||||
use App\Imports\Sales\Sheets\InvoiceTransactions;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Invoices implements WithMultipleSheets
|
||||
@@ -20,7 +20,7 @@ class Invoices implements WithMultipleSheets
|
||||
'invoice_item_taxes' => new InvoiceItemTaxes(),
|
||||
'invoice_histories' => new InvoiceHistories(),
|
||||
'invoice_totals' => new InvoiceTotals(),
|
||||
'invoice_transactions' => new InvoiceTranactions(),
|
||||
'invoice_transactions' => new InvoiceTransactions(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Sale\InvoiceHistory as Model;
|
||||
use App\Http\Requests\Sale\InvoiceHistory as Request;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceHistory as Model;
|
||||
|
||||
class InvoiceHistories extends Import
|
||||
{
|
||||
@@ -17,6 +18,8 @@ class InvoiceHistories extends Import
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['invoice_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
$row['notify'] = (int) $row['notify'];
|
||||
|
||||
return $row;
|
||||
@@ -24,6 +27,11 @@ class InvoiceHistories extends Import
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,69 @@
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Sale\InvoiceItemTax as Request;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceItem;
|
||||
use App\Models\Sale\InvoiceItemTax as Model;
|
||||
use App\Models\Setting\Tax;
|
||||
|
||||
class InvoiceItemTaxes extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after 3.2 release
|
||||
if ($row['invoice_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row['invoice_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['invoice_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
if (empty($row['invoice_item_id']) && !empty($row['item_name'])) {
|
||||
$item_id = Item::name($row['item_name'])->pluck('id')->first();
|
||||
$row['invoice_item_id'] = InvoiceItem::where('item_id', $item_id)->pluck('id')->first();
|
||||
}
|
||||
|
||||
if (empty($row['tax_id']) && !empty($row['tax_name'])) {
|
||||
$row['tax_id'] = Tax::name($row['tax_name'])->pluck('id')->first();
|
||||
}
|
||||
|
||||
if (empty($row['tax_id']) && !empty($row['tax_rate'])) {
|
||||
$row['tax_id'] = Tax::firstOrCreate([
|
||||
'rate' => $row['tax_rate'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'normal',
|
||||
'name' => $row['tax_rate'],
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
if (empty($row['name']) && !empty($row['item_name'])) {
|
||||
$row['name'] = $row['item_name'];
|
||||
}
|
||||
|
||||
$row['amount'] = (double) $row['amount'];
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Sale\InvoiceItem as Model;
|
||||
use App\Http\Requests\Sale\InvoiceItem as Request;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceItem as Model;
|
||||
|
||||
class InvoiceItems extends Import
|
||||
{
|
||||
@@ -13,8 +15,38 @@ class InvoiceItems extends Import
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['invoice_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
if (empty($row['item_id']) && !empty($row['item_name'])) {
|
||||
$row['item_id'] = Item::firstOrCreate([
|
||||
'name' => $row['item_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'sale_price' => $row['price'],
|
||||
'purchase_price' => $row['price'],
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
|
||||
$row['name'] = $row['item_name'];
|
||||
}
|
||||
|
||||
$row['tax'] = (double) $row['tax'];
|
||||
$row['tax_id'] = 0;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Sale\InvoiceTotal as Model;
|
||||
use App\Http\Requests\Sale\InvoiceTotal as Request;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceTotal as Model;
|
||||
|
||||
class InvoiceTotals extends Import
|
||||
{
|
||||
@@ -13,8 +14,22 @@ class InvoiceTotals extends Import
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['invoice_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
|
||||
class InvoiceTranactions extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['type'] = 'income';
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
}
|
||||
}
|
||||
109
app/Imports/Sales/Sheets/InvoiceTransactions.php
Normal file
109
app/Imports/Sales/Sheets/InvoiceTransactions.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class InvoiceTransactions extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['type'] = 'income';
|
||||
|
||||
if (empty($row['account_id']) && !empty($row['account_name'])) {
|
||||
$row['account_id'] = Account::firstOrCreate([
|
||||
'name' => $row['account_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'number' => Account::max('number') + 1,
|
||||
'currency_code' => setting('default.currency'),
|
||||
'opening_balance' => 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
if (empty($row['account_id']) && !empty($row['account_number'])) {
|
||||
$row['account_id'] = Account::firstOrCreate([
|
||||
'number' => $row['account_number'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'name' => $row['account_number'],
|
||||
'currency_code' => setting('default.currency'),
|
||||
'opening_balance' => 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
if (empty($row['account_id']) && !empty($row['currency_code'])) {
|
||||
$row['account_id'] = Account::firstOrCreate([
|
||||
'currency_code' => $row['currency_code'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'name' => $row['currency_code'],
|
||||
'number' => Account::max('number') + 1,
|
||||
'opening_balance' => 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
if (empty($row['contact_id']) && !empty($row['contact_name'])) {
|
||||
$row['contact_id'] = Contact::firstOrCreate([
|
||||
'name' => $row['contact_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'customer',
|
||||
'currency_code' => setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
if (empty($row['contact_id']) && !empty($row['contact_email'])) {
|
||||
$row['contact_id'] = Contact::firstOrCreate([
|
||||
'email' => $row['contact_email'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'customer',
|
||||
'name' => $row['contact_email'],
|
||||
'currency_code' => setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
if (empty($row['category_id']) && !empty($row['category_name'])) {
|
||||
$row['category_id'] = Category::firstOrCreate([
|
||||
'name' => $row['category_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'income',
|
||||
'color' => '#' . dechex(rand(0x000000, 0xFFFFFF)),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
$row['document_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Sale\Invoice as Model;
|
||||
use App\Http\Requests\Sale\Invoice as Request;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Sale\Invoice as Model;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class Invoices extends Import
|
||||
{
|
||||
@@ -13,6 +15,47 @@ class Invoices extends Import
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
if (empty($row['contact_id']) && !empty($row['contact_name'])) {
|
||||
$row['contact_id'] = Contact::firstOrCreate([
|
||||
'name' => $row['contact_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'customer',
|
||||
'currency_code' => setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
if (empty($row['contact_id']) && !empty($row['contact_email'])) {
|
||||
$row['contact_id'] = Contact::firstOrCreate([
|
||||
'email' => $row['contact_email'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'customer',
|
||||
'name' => $row['contact_email'],
|
||||
'currency_code' => setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
if (empty($row['category_id']) && !empty($row['category_name'])) {
|
||||
$row['category_id'] = Category::firstOrCreate([
|
||||
'name' => $row['category_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'income',
|
||||
'color' => '#' . dechex(rand(0x000000, 0xFFFFFF)),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
|
||||
Reference in New Issue
Block a user