Merge Invoice and Bill into Document
This commit is contained in:
37
app/Imports/Document/Documents.php
Normal file
37
app/Imports/Document/Documents.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Document;
|
||||
|
||||
use App\Imports\Document\Sheets\Documents as Base;
|
||||
use App\Imports\Document\Sheets\DocumentItems;
|
||||
use App\Imports\Document\Sheets\DocumentItemTaxes;
|
||||
use App\Imports\Document\Sheets\DocumentHistories;
|
||||
use App\Imports\Document\Sheets\DocumentTotals;
|
||||
use App\Imports\Document\Sheets\DocumentTransactions;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Documents implements WithMultipleSheets
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
public function __construct(string $type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
Str::plural($this->type) => new Base($this->type),
|
||||
$this->type . '_items' => new DocumentItems($this->type),
|
||||
$this->type . '_item_taxes' => new DocumentItemTaxes($this->type),
|
||||
$this->type . '_histories' => new DocumentHistories($this->type),
|
||||
$this->type . '_totals' => new DocumentTotals($this->type),
|
||||
$this->type . '_transactions' => new DocumentTransactions($this->type),
|
||||
];
|
||||
}
|
||||
}
|
||||
53
app/Imports/Document/Sheets/DocumentHistories.php
Normal file
53
app/Imports/Document/Sheets/DocumentHistories.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Document\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 DocumentHistories extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after laravel-excel 3.2 release
|
||||
if ($row[$this->type . '_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first();
|
||||
|
||||
$row['notify'] = (int) $row['notify'];
|
||||
|
||||
$row['type'] = $this->type;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
} else {
|
||||
$rules['bill_number'] = 'required|string';
|
||||
}
|
||||
|
||||
unset($rules['invoice_id'], $rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
66
app/Imports/Document/Sheets/DocumentItemTaxes.php
Normal file
66
app/Imports/Document/Sheets/DocumentItemTaxes.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Document\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 DocumentItemTaxes extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after laravel-excel 3.2 release
|
||||
if ($row[$this->type . '_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first();
|
||||
|
||||
if (empty($row[$this->type . '_item_id']) && !empty($row['item_name'])) {
|
||||
$item_id = Item::name($row['item_name'])->pluck('id')->first();
|
||||
$row[$this->type . '_item_id'] = DocumentItem::{$this->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'] = $this->type;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
} else {
|
||||
$rules['bill_number'] = 'required|string';
|
||||
}
|
||||
|
||||
unset($rules['invoice_id'], $rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
54
app/Imports/Document/Sheets/DocumentItems.php
Normal file
54
app/Imports/Document/Sheets/DocumentItems.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Document\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 DocumentItems extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_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['tax'] = (double) $row['tax'];
|
||||
$row['tax_id'] = 0;
|
||||
$row['type'] = $this->type;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
} else {
|
||||
$rules['bill_number'] = 'required|string';
|
||||
}
|
||||
|
||||
unset($rules['invoice_id'], $rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
45
app/Imports/Document/Sheets/DocumentTotals.php
Normal file
45
app/Imports/Document/Sheets/DocumentTotals.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Document\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 DocumentTotals extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first();
|
||||
$row['type'] = $this->type;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
} else {
|
||||
$rules['bill_number'] = 'required|string';
|
||||
}
|
||||
|
||||
unset($rules['invoice_id'], $rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
46
app/Imports/Document/Sheets/DocumentTransactions.php
Normal file
46
app/Imports/Document/Sheets/DocumentTransactions.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Document\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
use App\Models\Document\Document;
|
||||
|
||||
class DocumentTransactions extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['type'] = $this->type === Document::INVOICE_TYPE ? 'income' : 'expense';
|
||||
$row['account_id'] = $this->getAccountId($row);
|
||||
$row['category_id'] = $this->getCategoryId($row, $this->type === Document::INVOICE_TYPE ? 'income' : 'expense');
|
||||
$row['contact_id'] = $this->getContactId($row, $this->type === Document::INVOICE_TYPE ? 'customer' : 'vendor');
|
||||
$row['document_id'] = $this->getDocumentId($row);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
if ($this->type === Document::INVOICE_TYPE) {
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
} else {
|
||||
$rules['bill_number'] = 'required|string';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
56
app/Imports/Document/Sheets/Documents.php
Normal file
56
app/Imports/Document/Sheets/Documents.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Document\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 Documents extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
if ($this->type === Model::INVOICE_TYPE) {
|
||||
$row['document_number'] = $row['invoice_number'];
|
||||
$row['issued_at'] = $row['invoiced_at'];
|
||||
} else {
|
||||
$row['document_number'] = $row['bill_number'];
|
||||
$row['issued_at'] = $row['billed_at'];
|
||||
}
|
||||
|
||||
$row['category_id'] = $this->getCategoryId($row, $this->type === Model::INVOICE_TYPE ? 'income' : 'expense');
|
||||
$row['contact_id'] = $this->getContactId($row, $this->type === Model::INVOICE_TYPE ? 'customer' : 'vendor');
|
||||
$row['type'] = $this->type;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
if ($this->type === Model::INVOICE_TYPE) {
|
||||
$rules['invoice_number'] = Str::replaceFirst('unique:documents,NULL', 'unique:documents,document_number', $rules['document_number']);
|
||||
$rules['invoiced_at'] = $rules['issued_at'];
|
||||
} else {
|
||||
$rules['bill_number'] = Str::replaceFirst('unique:documents,NULL', 'unique:documents,document_number', $rules['document_number']);
|
||||
$rules['billed_at'] = $rules['issued_at'];
|
||||
}
|
||||
|
||||
unset($rules['document_number'], $rules['issued_at'], $rules['type']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Purchases;
|
||||
|
||||
use App\Imports\Purchases\Sheets\Bills as Base;
|
||||
use App\Imports\Purchases\Sheets\BillItems;
|
||||
use App\Imports\Purchases\Sheets\BillItemTaxes;
|
||||
use App\Imports\Purchases\Sheets\BillHistories;
|
||||
use App\Imports\Purchases\Sheets\BillTotals;
|
||||
use App\Imports\Purchases\Sheets\BillTransactions;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Bills implements WithMultipleSheets
|
||||
{
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
'bills' => new Base(),
|
||||
'bill_items' => new BillItems(),
|
||||
'bill_item_taxes' => new BillItemTaxes(),
|
||||
'bill_histories' => new BillHistories(),
|
||||
'bill_totals' => new BillTotals(),
|
||||
'bill_transactions' => new BillTransactions(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Purchase\BillHistory as Request;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillHistory as Model;
|
||||
|
||||
class BillHistories extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after laravel-excel 3.2 release
|
||||
if ($row['bill_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'bill_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['bill_id'] = (int) Bill::number($row['bill_number'])->pluck('id')->first();
|
||||
|
||||
$row['notify'] = (int) $row['notify'];
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Purchase\BillItemTax as Request;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillItem;
|
||||
use App\Models\Purchase\BillItemTax as Model;
|
||||
|
||||
class BillItemTaxes extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after laravel-excel 3.2 release
|
||||
if ($row['bill_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'bill_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['bill_id'] = (int) Bill::number($row['bill_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'] = BillItem::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'];
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Purchase\BillItem as Request;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillItem as Model;
|
||||
|
||||
class BillItems extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'bill_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['bill_id'] = (int) Bill::number($row['bill_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['tax'] = (double) $row['tax'];
|
||||
$row['tax_id'] = 0;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Purchase\BillTotal as Request;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillTotal as Model;
|
||||
|
||||
class BillTotals extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'bill_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['bill_id'] = (int) Bill::number($row['bill_number'])->pluck('id')->first();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
|
||||
class BillTransactions extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'bill_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['type'] = 'expense';
|
||||
$row['account_id'] = $this->getAccountId($row);
|
||||
$row['category_id'] = $this->getCategoryId($row, 'expense');
|
||||
$row['contact_id'] = $this->getContactId($row, 'vendor');
|
||||
$row['document_id'] = $this->getDocumentId($row);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Purchase\Bill as Model;
|
||||
use App\Http\Requests\Purchase\Bill as Request;
|
||||
|
||||
class Bills extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'bill_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['category_id'] = $this->getCategoryId($row, 'expense');
|
||||
$row['contact_id'] = $this->getContactId($row, 'vendor');
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales;
|
||||
|
||||
use App\Imports\Sales\Sheets\Invoices as Base;
|
||||
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\InvoiceTransactions;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Invoices implements WithMultipleSheets
|
||||
{
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
'invoices' => new Base(),
|
||||
'invoice_items' => new InvoiceItems(),
|
||||
'invoice_item_taxes' => new InvoiceItemTaxes(),
|
||||
'invoice_histories' => new InvoiceHistories(),
|
||||
'invoice_totals' => new InvoiceTotals(),
|
||||
'invoice_transactions' => new InvoiceTransactions(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Sale\InvoiceHistory as Request;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceHistory as Model;
|
||||
|
||||
class InvoiceHistories extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after laravel-excel 3.2 release
|
||||
if ($row['invoice_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['invoice_id'] = (int) Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
$row['notify'] = (int) $row['notify'];
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class InvoiceItemTaxes extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after laravel-excel 3.2 release
|
||||
if ($row['invoice_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['invoice_id'] = (int) 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();
|
||||
}
|
||||
|
||||
$row['tax_id'] = $this->getTaxId($row);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Sale\InvoiceItem as Request;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceItem as Model;
|
||||
|
||||
class InvoiceItems extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['invoice_id'] = (int) 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['tax'] = (double) $row['tax'];
|
||||
$row['tax_id'] = 0;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Sale\InvoiceTotal as Request;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceTotal as Model;
|
||||
|
||||
class InvoiceTotals extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['invoice_id'] = (int) Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
unset($rules['invoice_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\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 function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['type'] = 'income';
|
||||
$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);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['invoice_number'] = 'required|string';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Sale\Invoice as Request;
|
||||
use App\Models\Sale\Invoice as Model;
|
||||
|
||||
class Invoices extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'invoice_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['category_id'] = $this->getCategoryId($row, 'income');
|
||||
$row['contact_id'] = $this->getContactId($row, 'customer');
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user