Merge branch '2.1-dev' of github.com:akaunting/akaunting into 2.1-dev
This commit is contained in:
commit
c620a75e81
@ -15,15 +15,9 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
|||||||
{
|
{
|
||||||
public $ids;
|
public $ids;
|
||||||
|
|
||||||
/**
|
public function __construct($ids = null)
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $type;
|
|
||||||
|
|
||||||
public function __construct($ids = null, string $type = '')
|
|
||||||
{
|
{
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
$this->type = $type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function title(): string
|
public function title(): string
|
||||||
|
@ -164,6 +164,7 @@ abstract class PaymentController extends BaseController
|
|||||||
$request['amount'] = $invoice->amount;
|
$request['amount'] = $invoice->amount;
|
||||||
$request['payment_method'] = $this->alias;
|
$request['payment_method'] = $this->alias;
|
||||||
$request['reference'] = $this->getReference($invoice);
|
$request['reference'] = $this->getReference($invoice);
|
||||||
|
$request['type'] = 'income';
|
||||||
|
|
||||||
event(new PaymentReceived($invoice, $request));
|
event(new PaymentReceived($invoice, $request));
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,6 @@ abstract class Import implements ToModel, SkipsOnError, SkipsOnFailure, WithBatc
|
|||||||
|
|
||||||
public $empty_field = 'empty---';
|
public $empty_field = 'empty---';
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $type;
|
|
||||||
|
|
||||||
public function __construct(string $type = '')
|
|
||||||
{
|
|
||||||
$this->type = $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
$row['company_id'] = session('company_id');
|
$row['company_id'] = session('company_id');
|
||||||
|
@ -5,7 +5,7 @@ namespace App\BulkActions\Purchases;
|
|||||||
use App\Abstracts\BulkAction;
|
use App\Abstracts\BulkAction;
|
||||||
use App\Events\Document\DocumentCancelled;
|
use App\Events\Document\DocumentCancelled;
|
||||||
use App\Events\Document\DocumentReceived;
|
use App\Events\Document\DocumentReceived;
|
||||||
use App\Exports\Document\Documents as Export;
|
use App\Exports\Purchases\Bills as Export;
|
||||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
|
use App\Jobs\Banking\CreateBankingDocumentTransaction;
|
||||||
use App\Jobs\Document\CreateDocumentHistory;
|
use App\Jobs\Document\CreateDocumentHistory;
|
||||||
use App\Jobs\Document\DeleteDocument;
|
use App\Jobs\Document\DeleteDocument;
|
||||||
@ -48,7 +48,7 @@ class Bills extends BulkAction
|
|||||||
$bills = $this->getSelectedRecords($request);
|
$bills = $this->getSelectedRecords($request);
|
||||||
|
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
$this->dispatch(new CreateBankingDocumentTransaction($bill, []));
|
$this->dispatch(new CreateBankingDocumentTransaction($bill, ['type' => 'expense']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +100,6 @@ class Bills extends BulkAction
|
|||||||
{
|
{
|
||||||
$selected = $this->getSelectedInput($request);
|
$selected = $this->getSelectedInput($request);
|
||||||
|
|
||||||
return \Excel::download(new Export($selected, Document::BILL_TYPE), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx');
|
return \Excel::download(new Export($selected), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use App\Events\Document\DocumentCancelled;
|
|||||||
use App\Events\Document\DocumentCreated;
|
use App\Events\Document\DocumentCreated;
|
||||||
use App\Events\Document\DocumentSent;
|
use App\Events\Document\DocumentSent;
|
||||||
use App\Events\Document\PaymentReceived;
|
use App\Events\Document\PaymentReceived;
|
||||||
use App\Exports\Document\Documents as Export;
|
use App\Exports\Sales\Invoices as Export;
|
||||||
use App\Jobs\Document\DeleteDocument;
|
use App\Jobs\Document\DeleteDocument;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class Invoices extends BulkAction
|
|||||||
$invoices = $this->getSelectedRecords($request);
|
$invoices = $this->getSelectedRecords($request);
|
||||||
|
|
||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
event(new PaymentReceived($invoice));
|
event(new PaymentReceived($invoice, ['type' => 'income']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +103,6 @@ class Invoices extends BulkAction
|
|||||||
{
|
{
|
||||||
$selected = $this->getSelectedInput($request);
|
$selected = $this->getSelectedInput($request);
|
||||||
|
|
||||||
return \Excel::download(new Export($selected, Document::INVOICE_TYPE), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx');
|
return \Excel::download(new Export($selected), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Console\Commands;
|
|||||||
use App\Events\Document\DocumentReminded;
|
use App\Events\Document\DocumentReminded;
|
||||||
use App\Models\Common\Company;
|
use App\Models\Common\Company;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
|
use App\Notifications\Purchase\Bill as Notification;
|
||||||
use App\Utilities\Overrider;
|
use App\Utilities\Overrider;
|
||||||
use Date;
|
use Date;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
@ -84,7 +85,7 @@ class BillReminder extends Command
|
|||||||
|
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
try {
|
try {
|
||||||
event(new DocumentReminded($bill));
|
event(new DocumentReminded($bill, Notification::class));
|
||||||
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
|
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Console\Commands;
|
|||||||
use App\Events\Document\DocumentReminded;
|
use App\Events\Document\DocumentReminded;
|
||||||
use App\Models\Common\Company;
|
use App\Models\Common\Company;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
|
use App\Notifications\Sale\Invoice as Notification;
|
||||||
use App\Utilities\Overrider;
|
use App\Utilities\Overrider;
|
||||||
use Date;
|
use Date;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
@ -84,7 +85,7 @@ class InvoiceReminder extends Command
|
|||||||
|
|
||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
try {
|
try {
|
||||||
event(new DocumentReminded($invoice));
|
event(new DocumentReminded($invoice, Notification::class));
|
||||||
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
|
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
|
|
||||||
|
@ -3,18 +3,22 @@
|
|||||||
namespace App\Events\Document;
|
namespace App\Events\Document;
|
||||||
|
|
||||||
use App\Abstracts\Event;
|
use App\Abstracts\Event;
|
||||||
|
use App\Models\Document\Document;
|
||||||
|
|
||||||
class DocumentReminded extends Event
|
class DocumentReminded extends Event
|
||||||
{
|
{
|
||||||
public $document;
|
public $document;
|
||||||
|
public $notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
*
|
*
|
||||||
* @param $document
|
* @param $document
|
||||||
|
* @param $notification
|
||||||
*/
|
*/
|
||||||
public function __construct($document)
|
public function __construct(Document $document, string $notification)
|
||||||
{
|
{
|
||||||
$this->document = $document;
|
$this->document = $document;
|
||||||
|
$this->notification = $notification;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Exports\Document;
|
|
||||||
|
|
||||||
use App\Exports\Document\Sheets\Documents as Base;
|
|
||||||
use App\Exports\Document\Sheets\DocumentItems;
|
|
||||||
use App\Exports\Document\Sheets\DocumentItemTaxes;
|
|
||||||
use App\Exports\Document\Sheets\DocumentHistories;
|
|
||||||
use App\Exports\Document\Sheets\DocumentTotals;
|
|
||||||
use App\Exports\Document\Sheets\DocumentTransactions;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
|
||||||
|
|
||||||
class Documents implements WithMultipleSheets
|
|
||||||
{
|
|
||||||
public $ids;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $type;
|
|
||||||
|
|
||||||
public function __construct($ids = null, string $type = '')
|
|
||||||
{
|
|
||||||
$this->ids = $ids;
|
|
||||||
$this->type = $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sheets(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
Str::plural($this->type) => new Base($this->ids, $this->type),
|
|
||||||
$this->type . '_items' => new DocumentItems($this->ids, $this->type),
|
|
||||||
$this->type . '_item_taxes' => new DocumentItemTaxes($this->ids, $this->type),
|
|
||||||
$this->type . '_histories' => new DocumentHistories($this->ids, $this->type),
|
|
||||||
$this->type . '_totals' => new DocumentTotals($this->ids, $this->type),
|
|
||||||
$this->type . '_transactions' => new DocumentTransactions($this->ids, $this->type),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Exports\Document\Sheets;
|
|
||||||
|
|
||||||
use App\Abstracts\Export;
|
|
||||||
use App\Models\Document\Document;
|
|
||||||
use App\Models\Document\DocumentHistory as Model;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class DocumentHistories extends Export
|
|
||||||
{
|
|
||||||
public function collection()
|
|
||||||
{
|
|
||||||
$model = Model::{$this->type}()->with('document')->usingSearchString(request('search'));
|
|
||||||
|
|
||||||
if (!empty($this->ids)) {
|
|
||||||
$model->whereIn('document_id', (array) $this->ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $model->cursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function map($model): array
|
|
||||||
{
|
|
||||||
$document = $model->document;
|
|
||||||
|
|
||||||
if (empty($document)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->type === Document::INVOICE_TYPE) {
|
|
||||||
$model->invoice_number = $document->document_number;
|
|
||||||
} else {
|
|
||||||
$model->bill_number = $document->document_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::map($model);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fields(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
|
||||||
'status',
|
|
||||||
'notify',
|
|
||||||
'description',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function title(): string
|
|
||||||
{
|
|
||||||
return Str::replaceFirst('document', $this->type, parent::title());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Exports\Document\Sheets;
|
|
||||||
|
|
||||||
use App\Abstracts\Export;
|
|
||||||
use App\Models\Document\Document;
|
|
||||||
use App\Models\Document\DocumentTotal as Model;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class DocumentTotals extends Export
|
|
||||||
{
|
|
||||||
public function collection()
|
|
||||||
{
|
|
||||||
$model = Model::{$this->type}()->with('document')->usingSearchString(request('search'));
|
|
||||||
|
|
||||||
if (!empty($this->ids)) {
|
|
||||||
$model->whereIn('document_id', (array) $this->ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $model->cursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function map($model): array
|
|
||||||
{
|
|
||||||
$document = $model->document;
|
|
||||||
|
|
||||||
if (empty($document)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->type === Document::INVOICE_TYPE) {
|
|
||||||
$model->invoice_number = $document->document_number;
|
|
||||||
} else {
|
|
||||||
$model->bill_number = $document->document_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::map($model);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fields(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
|
||||||
'code',
|
|
||||||
'name',
|
|
||||||
'amount',
|
|
||||||
'sort_order',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function title(): string
|
|
||||||
{
|
|
||||||
return Str::replaceFirst('document', $this->type, parent::title());
|
|
||||||
}
|
|
||||||
}
|
|
33
app/Exports/Purchases/Bills.php
Normal file
33
app/Exports/Purchases/Bills.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Purchases;
|
||||||
|
|
||||||
|
use App\Exports\Purchases\Sheets\Bills as Base;
|
||||||
|
use App\Exports\Purchases\Sheets\BillItems;
|
||||||
|
use App\Exports\Purchases\Sheets\BillItemTaxes;
|
||||||
|
use App\Exports\Purchases\Sheets\BillHistories;
|
||||||
|
use App\Exports\Purchases\Sheets\BillTotals;
|
||||||
|
use App\Exports\Purchases\Sheets\BillTransactions;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||||
|
|
||||||
|
class Bills implements WithMultipleSheets
|
||||||
|
{
|
||||||
|
public $ids;
|
||||||
|
|
||||||
|
public function __construct($ids = null)
|
||||||
|
{
|
||||||
|
$this->ids = $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'bills' => new Base($this->ids),
|
||||||
|
'bill_items' => new BillItems($this->ids),
|
||||||
|
'bill_item_taxes' => new BillItemTaxes($this->ids),
|
||||||
|
'bill_histories' => new BillHistories($this->ids),
|
||||||
|
'bill_totals' => new BillTotals($this->ids),
|
||||||
|
'bill_transactions' => new BillTransactions($this->ids),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
43
app/Exports/Purchases/Sheets/BillHistories.php
Normal file
43
app/Exports/Purchases/Sheets/BillHistories.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Purchases\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Document\DocumentHistory as Model;
|
||||||
|
|
||||||
|
class BillHistories extends Export
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
$model = Model::bill()->with('document')->usingSearchString(request('search'));
|
||||||
|
|
||||||
|
if (!empty($this->ids)) {
|
||||||
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Exports\Document\Sheets;
|
namespace App\Exports\Purchases\Sheets;
|
||||||
|
|
||||||
use App\Abstracts\Export;
|
use App\Abstracts\Export;
|
||||||
use App\Models\Document\Document;
|
|
||||||
use App\Models\Document\DocumentItemTax as Model;
|
use App\Models\Document\DocumentItemTax as Model;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class DocumentItemTaxes extends Export
|
class BillItemTaxes extends Export
|
||||||
{
|
{
|
||||||
public function collection()
|
public function collection()
|
||||||
{
|
{
|
||||||
$model = Model::{$this->type}()->with('document', 'item', 'tax')->usingSearchString(request('search'));
|
$model = Model::bill()->with('document', 'item', 'tax')->usingSearchString(request('search'));
|
||||||
|
|
||||||
if (!empty($this->ids)) {
|
if (!empty($this->ids)) {
|
||||||
$model->whereIn('document_id', (array) $this->ids);
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
@ -28,12 +26,7 @@ class DocumentItemTaxes extends Export
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->type === Document::INVOICE_TYPE) {
|
|
||||||
$model->invoice_number = $document->document_number;
|
|
||||||
} else {
|
|
||||||
$model->bill_number = $document->document_number;
|
$model->bill_number = $document->document_number;
|
||||||
}
|
|
||||||
|
|
||||||
$model->item_name = $model->item->name;
|
$model->item_name = $model->item->name;
|
||||||
$model->tax_rate = $model->tax->rate;
|
$model->tax_rate = $model->tax->rate;
|
||||||
|
|
||||||
@ -43,15 +36,10 @@ class DocumentItemTaxes extends Export
|
|||||||
public function fields(): array
|
public function fields(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
'bill_number',
|
||||||
'item_name',
|
'item_name',
|
||||||
'tax_rate',
|
'tax_rate',
|
||||||
'amount',
|
'amount',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function title(): string
|
|
||||||
{
|
|
||||||
return Str::replaceFirst('document', $this->type, parent::title());
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,17 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Exports\Document\Sheets;
|
namespace App\Exports\Purchases\Sheets;
|
||||||
|
|
||||||
use App\Abstracts\Export;
|
use App\Abstracts\Export;
|
||||||
use App\Models\Document\Document;
|
|
||||||
use App\Models\Document\DocumentItem as Model;
|
use App\Models\Document\DocumentItem as Model;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class DocumentItems extends Export
|
class BillItems extends Export
|
||||||
{
|
{
|
||||||
public function collection()
|
public function collection()
|
||||||
{
|
{
|
||||||
$model = Model::{$this->type}()->with('document', 'item')->usingSearchString(request('search'));
|
$model = Model::bill()->with('document', 'item')->usingSearchString(request('search'));
|
||||||
|
|
||||||
if (!empty($this->ids)) {
|
if (!empty($this->ids)) {
|
||||||
$model->whereIn('document_id', (array) $this->ids);
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
@ -28,12 +26,7 @@ class DocumentItems extends Export
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->type === Document::INVOICE_TYPE) {
|
|
||||||
$model->invoice_number = $document->document_number;
|
|
||||||
} else {
|
|
||||||
$model->bill_number = $document->document_number;
|
$model->bill_number = $document->document_number;
|
||||||
}
|
|
||||||
|
|
||||||
$model->item_name = $model->item->name;
|
$model->item_name = $model->item->name;
|
||||||
|
|
||||||
return parent::map($model);
|
return parent::map($model);
|
||||||
@ -42,7 +35,7 @@ class DocumentItems extends Export
|
|||||||
public function fields(): array
|
public function fields(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
'bill_number',
|
||||||
'item_name',
|
'item_name',
|
||||||
'quantity',
|
'quantity',
|
||||||
'price',
|
'price',
|
||||||
@ -50,9 +43,4 @@ class DocumentItems extends Export
|
|||||||
'tax',
|
'tax',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function title(): string
|
|
||||||
{
|
|
||||||
return Str::replaceFirst('document', $this->type, parent::title());
|
|
||||||
}
|
|
||||||
}
|
}
|
44
app/Exports/Purchases/Sheets/BillTotals.php
Normal file
44
app/Exports/Purchases/Sheets/BillTotals.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Purchases\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Document\DocumentTotal as Model;
|
||||||
|
|
||||||
|
class BillTotals extends Export
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
$model = Model::bill()->with('document')->usingSearchString(request('search'));
|
||||||
|
|
||||||
|
if (!empty($this->ids)) {
|
||||||
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
63
app/Exports/Purchases/Sheets/BillTransactions.php
Normal file
63
app/Exports/Purchases/Sheets/BillTransactions.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Purchases\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()
|
||||||
|
{
|
||||||
|
$model = Model::with('account', 'category', 'contact', 'document')->bill()->isDocument()->usingSearchString(request('search'));
|
||||||
|
|
||||||
|
if (!empty($this->ids)) {
|
||||||
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
return parent::map($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'bill_number',
|
||||||
|
'paid_at',
|
||||||
|
'amount',
|
||||||
|
'currency_code',
|
||||||
|
'currency_rate',
|
||||||
|
'account_name',
|
||||||
|
'contact_email',
|
||||||
|
'category_name',
|
||||||
|
'description',
|
||||||
|
'payment_method',
|
||||||
|
'reference',
|
||||||
|
'reconciled',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function columnFormats(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
59
app/Exports/Purchases/Sheets/Bills.php
Normal file
59
app/Exports/Purchases/Sheets/Bills.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Purchases\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Document\Document as Model;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
|
||||||
|
class Bills extends Export
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
$model = Model::bill()->with('category')->usingSearchString(request('search'));
|
||||||
|
|
||||||
|
if (!empty($this->ids)) {
|
||||||
|
$model->whereIn('id', (array) $this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($model): array
|
||||||
|
{
|
||||||
|
$model->category_name = $model->category->name;
|
||||||
|
$model->bill_number = $model->document_number;
|
||||||
|
$model->billed_at = $model->issued_at;
|
||||||
|
|
||||||
|
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',
|
||||||
|
'notes',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function columnFormats(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'D' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||||
|
'E' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
33
app/Exports/Sales/Invoices.php
Normal file
33
app/Exports/Sales/Invoices.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Sales;
|
||||||
|
|
||||||
|
use App\Exports\Sales\Sheets\Invoices as Base;
|
||||||
|
use App\Exports\Sales\Sheets\InvoiceItems;
|
||||||
|
use App\Exports\Sales\Sheets\InvoiceItemTaxes;
|
||||||
|
use App\Exports\Sales\Sheets\InvoiceHistories;
|
||||||
|
use App\Exports\Sales\Sheets\InvoiceTotals;
|
||||||
|
use App\Exports\Sales\Sheets\InvoiceTransactions;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||||
|
|
||||||
|
class Invoices implements WithMultipleSheets
|
||||||
|
{
|
||||||
|
public $ids;
|
||||||
|
|
||||||
|
public function __construct($ids = null)
|
||||||
|
{
|
||||||
|
$this->ids = $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'invoices' => new Base($this->ids),
|
||||||
|
'invoice_items' => new InvoiceItems($this->ids),
|
||||||
|
'invoice_item_taxes' => new InvoiceItemTaxes($this->ids),
|
||||||
|
'invoice_histories' => new InvoiceHistories($this->ids),
|
||||||
|
'invoice_totals' => new InvoiceTotals($this->ids),
|
||||||
|
'invoice_transactions' => new InvoiceTransactions($this->ids),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
43
app/Exports/Sales/Sheets/InvoiceHistories.php
Normal file
43
app/Exports/Sales/Sheets/InvoiceHistories.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Sales\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Document\DocumentHistory as Model;
|
||||||
|
|
||||||
|
class InvoiceHistories extends Export
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
$model = Model::invoice()->with('document')->usingSearchString(request('search'));
|
||||||
|
|
||||||
|
if (!empty($this->ids)) {
|
||||||
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($model): array
|
||||||
|
{
|
||||||
|
$document = $model->document;
|
||||||
|
|
||||||
|
if (empty($document)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->invoice_number = $document->document_number;
|
||||||
|
|
||||||
|
return parent::map($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'invoice_number',
|
||||||
|
'status',
|
||||||
|
'notify',
|
||||||
|
'description',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
45
app/Exports/Sales/Sheets/InvoiceItemTaxes.php
Normal file
45
app/Exports/Sales/Sheets/InvoiceItemTaxes.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Sales\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Document\DocumentItemTax as Model;
|
||||||
|
|
||||||
|
class InvoiceItemTaxes extends Export
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
$model = Model::invoice()->with('document', 'item', 'tax')->usingSearchString(request('search'));
|
||||||
|
|
||||||
|
if (!empty($this->ids)) {
|
||||||
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($model): array
|
||||||
|
{
|
||||||
|
$document = $model->document;
|
||||||
|
|
||||||
|
if (empty($document)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->invoice_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 [
|
||||||
|
'invoice_number',
|
||||||
|
'item_name',
|
||||||
|
'tax_rate',
|
||||||
|
'amount',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
46
app/Exports/Sales/Sheets/InvoiceItems.php
Normal file
46
app/Exports/Sales/Sheets/InvoiceItems.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Sales\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Document\DocumentItem as Model;
|
||||||
|
|
||||||
|
class InvoiceItems extends Export
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
$model = Model::invoice()->with('document', 'item')->usingSearchString(request('search'));
|
||||||
|
|
||||||
|
if (!empty($this->ids)) {
|
||||||
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($model): array
|
||||||
|
{
|
||||||
|
$document = $model->document;
|
||||||
|
|
||||||
|
if (empty($document)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->invoice_number = $document->document_number;
|
||||||
|
$model->item_name = $model->item->name;
|
||||||
|
|
||||||
|
return parent::map($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'invoice_number',
|
||||||
|
'item_name',
|
||||||
|
'quantity',
|
||||||
|
'price',
|
||||||
|
'total',
|
||||||
|
'tax',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
44
app/Exports/Sales/Sheets/InvoiceTotals.php
Normal file
44
app/Exports/Sales/Sheets/InvoiceTotals.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Sales\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Document\DocumentTotal as Model;
|
||||||
|
|
||||||
|
class InvoiceTotals extends Export
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
$model = Model::invoice()->with('document')->usingSearchString(request('search'));
|
||||||
|
|
||||||
|
if (!empty($this->ids)) {
|
||||||
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($model): array
|
||||||
|
{
|
||||||
|
$document = $model->document;
|
||||||
|
|
||||||
|
if (empty($document)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->invoice_number = $document->document_number;
|
||||||
|
|
||||||
|
return parent::map($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'invoice_number',
|
||||||
|
'code',
|
||||||
|
'name',
|
||||||
|
'amount',
|
||||||
|
'sort_order',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Exports\Document\Sheets;
|
namespace App\Exports\Sales\Sheets;
|
||||||
|
|
||||||
use App\Abstracts\Export;
|
use App\Abstracts\Export;
|
||||||
use App\Models\Banking\Transaction as Model;
|
use App\Models\Banking\Transaction as Model;
|
||||||
@ -9,11 +9,11 @@ use Illuminate\Support\Str;
|
|||||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
|
||||||
class DocumentTransactions extends Export implements WithColumnFormatting
|
class InvoiceTransactions extends Export implements WithColumnFormatting
|
||||||
{
|
{
|
||||||
public function collection()
|
public function collection()
|
||||||
{
|
{
|
||||||
$model = Model::with('account', 'category', 'contact', 'document')->{$this->type}()->isDocument()->usingSearchString(request('search'));
|
$model = Model::with('account', 'category', 'contact', 'document')->invoice()->isDocument()->usingSearchString(request('search'));
|
||||||
|
|
||||||
if (!empty($this->ids)) {
|
if (!empty($this->ids)) {
|
||||||
$model->whereIn('document_id', (array) $this->ids);
|
$model->whereIn('document_id', (array) $this->ids);
|
||||||
@ -30,12 +30,7 @@ class DocumentTransactions extends Export implements WithColumnFormatting
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->type === Document::INVOICE_TYPE) {
|
|
||||||
$model->invoice_number = $document->document_number;
|
$model->invoice_number = $document->document_number;
|
||||||
} else {
|
|
||||||
$model->bill_number = $document->document_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
$model->account_name = $model->account->name;
|
$model->account_name = $model->account->name;
|
||||||
$model->category_name = $model->category->name;
|
$model->category_name = $model->category->name;
|
||||||
$model->contact_email = $model->contact->email;
|
$model->contact_email = $model->contact->email;
|
||||||
@ -46,7 +41,7 @@ class DocumentTransactions extends Export implements WithColumnFormatting
|
|||||||
public function fields(): array
|
public function fields(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
$this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
'invoice_number',
|
||||||
'paid_at',
|
'paid_at',
|
||||||
'amount',
|
'amount',
|
||||||
'currency_code',
|
'currency_code',
|
||||||
@ -67,9 +62,4 @@ class DocumentTransactions extends Export implements WithColumnFormatting
|
|||||||
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function title(): string
|
|
||||||
{
|
|
||||||
return Str::replaceFirst('document', $this->type, parent::title());
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,17 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Exports\Document\Sheets;
|
namespace App\Exports\Sales\Sheets;
|
||||||
|
|
||||||
use App\Abstracts\Export;
|
use App\Abstracts\Export;
|
||||||
use App\Models\Document\Document as Model;
|
use App\Models\Document\Document as Model;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
|
||||||
class Documents extends Export
|
class Invoices extends Export
|
||||||
{
|
{
|
||||||
public function collection()
|
public function collection()
|
||||||
{
|
{
|
||||||
$model = Model::{$this->type}()->with('category')->usingSearchString(request('search'));
|
$model = Model::invoice()->with('category')->usingSearchString(request('search'));
|
||||||
|
|
||||||
if (!empty($this->ids)) {
|
if (!empty($this->ids)) {
|
||||||
$model->whereIn('id', (array) $this->ids);
|
$model->whereIn('id', (array) $this->ids);
|
||||||
@ -23,14 +22,8 @@ class Documents extends Export
|
|||||||
public function map($model): array
|
public function map($model): array
|
||||||
{
|
{
|
||||||
$model->category_name = $model->category->name;
|
$model->category_name = $model->category->name;
|
||||||
|
|
||||||
if ($this->type === Model::INVOICE_TYPE) {
|
|
||||||
$model->invoice_number = $model->document_number;
|
$model->invoice_number = $model->document_number;
|
||||||
$model->invoiced_at = $model->issued_at;
|
$model->invoiced_at = $model->issued_at;
|
||||||
} else {
|
|
||||||
$model->bill_number = $model->document_number;
|
|
||||||
$model->billed_at = $model->issued_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::map($model);
|
return parent::map($model);
|
||||||
}
|
}
|
||||||
@ -38,10 +31,10 @@ class Documents extends Export
|
|||||||
public function fields(): array
|
public function fields(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
$this->type === Model::INVOICE_TYPE ? 'invoice_number' : 'bill_number',
|
'invoice_number',
|
||||||
'order_number',
|
'order_number',
|
||||||
'status',
|
'status',
|
||||||
$this->type === Model::INVOICE_TYPE ? 'invoiced_at' : 'billed_at',
|
'invoiced_at',
|
||||||
'due_at',
|
'due_at',
|
||||||
'amount',
|
'amount',
|
||||||
'currency_code',
|
'currency_code',
|
||||||
@ -57,11 +50,6 @@ class Documents extends Export
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function title(): string
|
|
||||||
{
|
|
||||||
return Str::replaceFirst('document', $this->type, parent::title());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function columnFormats(): array
|
public function columnFormats(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
@ -62,7 +62,7 @@ class Dashboards extends Controller
|
|||||||
$dashboard = $this->dispatch(new CreateDashboard([
|
$dashboard = $this->dispatch(new CreateDashboard([
|
||||||
'company_id' => session('company_id'),
|
'company_id' => session('company_id'),
|
||||||
'name' => trans_choice('general.dashboards', 1),
|
'name' => trans_choice('general.dashboards', 1),
|
||||||
'with_widgets' => true,
|
'default_widgets' => true,
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
namespace App\Http\Controllers\Purchases;
|
namespace App\Http\Controllers\Purchases;
|
||||||
|
|
||||||
use App\Abstracts\Http\Controller;
|
use App\Abstracts\Http\Controller;
|
||||||
use App\Exports\Document\Documents as Export;
|
use App\Exports\Purchases\Bills as Export;
|
||||||
use App\Http\Requests\Common\Import as ImportRequest;
|
use App\Http\Requests\Common\Import as ImportRequest;
|
||||||
use App\Http\Requests\Document\Document as Request;
|
use App\Http\Requests\Document\Document as Request;
|
||||||
use App\Imports\Document\Documents as Import;
|
use App\Imports\Purchases\Bills as Import;
|
||||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
|
use App\Jobs\Banking\CreateBankingDocumentTransaction;
|
||||||
use App\Jobs\Document\CreateDocument;
|
use App\Jobs\Document\CreateDocument;
|
||||||
use App\Jobs\Document\DeleteDocument;
|
use App\Jobs\Document\DeleteDocument;
|
||||||
@ -131,7 +131,7 @@ class Bills extends Controller
|
|||||||
public function import(ImportRequest $request)
|
public function import(ImportRequest $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
\Excel::import(new Import(Document::BILL_TYPE), $request->file('import'));
|
\Excel::import(new Import(), $request->file('import'));
|
||||||
} catch (\Maatwebsite\Excel\Exceptions\SheetNotFoundException $e) {
|
} catch (\Maatwebsite\Excel\Exceptions\SheetNotFoundException $e) {
|
||||||
flash($e->getMessage())->error()->important();
|
flash($e->getMessage())->error()->important();
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ class Bills extends Controller
|
|||||||
*/
|
*/
|
||||||
public function export()
|
public function export()
|
||||||
{
|
{
|
||||||
return \Excel::download(new Export(null, Document::BILL_TYPE), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx');
|
return \Excel::download(new Export(), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,7 +233,7 @@ class Bills extends Controller
|
|||||||
{
|
{
|
||||||
event(new \App\Events\Document\DocumentReceived($bill));
|
event(new \App\Events\Document\DocumentReceived($bill));
|
||||||
|
|
||||||
$message = trans('bills.messages.marked_received');
|
$message = trans('general.messages.marked_received', ['type' => trans_choice('general.bills', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ class Bills extends Controller
|
|||||||
{
|
{
|
||||||
event(new \App\Events\Document\DocumentCancelled($bill));
|
event(new \App\Events\Document\DocumentCancelled($bill));
|
||||||
|
|
||||||
$message = trans('bills.messages.marked_cancelled');
|
$message = trans('general.messages.marked_cancelled', ['type' => trans_choice('general.bills', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
|
|
||||||
@ -308,9 +308,9 @@ class Bills extends Controller
|
|||||||
public function markPaid(Document $bill)
|
public function markPaid(Document $bill)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->dispatch(new CreateBankingDocumentTransaction($bill, []));
|
$this->dispatch(new CreateBankingDocumentTransaction($bill, ['type' => 'expense']));
|
||||||
|
|
||||||
$message = trans('bills.messages.marked_paid');
|
$message = trans('general.messages.marked_paid', ['type' => trans_choice('general.bills', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
namespace App\Http\Controllers\Sales;
|
namespace App\Http\Controllers\Sales;
|
||||||
|
|
||||||
use App\Abstracts\Http\Controller;
|
use App\Abstracts\Http\Controller;
|
||||||
use App\Exports\Document\Documents as Export;
|
use App\Exports\Sales\Invoices as Export;
|
||||||
use App\Http\Requests\Common\Import as ImportRequest;
|
use App\Http\Requests\Common\Import as ImportRequest;
|
||||||
use App\Http\Requests\Document\Document as Request;
|
use App\Http\Requests\Document\Document as Request;
|
||||||
use App\Imports\Document\Documents as Import;
|
use App\Imports\Sales\Invoices as Import;
|
||||||
use App\Jobs\Document\CreateDocument;
|
use App\Jobs\Document\CreateDocument;
|
||||||
use App\Jobs\Document\DeleteDocument;
|
use App\Jobs\Document\DeleteDocument;
|
||||||
use App\Jobs\Document\DuplicateDocument;
|
use App\Jobs\Document\DuplicateDocument;
|
||||||
@ -131,7 +131,7 @@ class Invoices extends Controller
|
|||||||
public function import(ImportRequest $request)
|
public function import(ImportRequest $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
\Excel::import(new Import(Document::INVOICE_TYPE), $request->file('import'));
|
\Excel::import(new Import(), $request->file('import'));
|
||||||
} catch (\Maatwebsite\Excel\Exceptions\SheetNotFoundException $e) {
|
} catch (\Maatwebsite\Excel\Exceptions\SheetNotFoundException $e) {
|
||||||
flash($e->getMessage())->error()->important();
|
flash($e->getMessage())->error()->important();
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ class Invoices extends Controller
|
|||||||
*/
|
*/
|
||||||
public function export()
|
public function export()
|
||||||
{
|
{
|
||||||
return \Excel::download(new Export(null, Document::INVOICE_TYPE), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx');
|
return \Excel::download(new Export(), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,7 +233,7 @@ class Invoices extends Controller
|
|||||||
{
|
{
|
||||||
event(new \App\Events\Document\DocumentSent($invoice));
|
event(new \App\Events\Document\DocumentSent($invoice));
|
||||||
|
|
||||||
$message = trans('invoices.messages.marked_sent');
|
$message = trans('documents.messages.marked_sent', ['type' => trans_choice('general.invoices', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ class Invoices extends Controller
|
|||||||
{
|
{
|
||||||
event(new \App\Events\Document\DocumentCancelled($invoice));
|
event(new \App\Events\Document\DocumentCancelled($invoice));
|
||||||
|
|
||||||
$message = trans('invoices.messages.marked_cancelled');
|
$message = trans('general.messages.marked_cancelled', ['type' => trans_choice('general.invoices', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ class Invoices extends Controller
|
|||||||
|
|
||||||
event(new \App\Events\Document\DocumentSent($invoice));
|
event(new \App\Events\Document\DocumentSent($invoice));
|
||||||
|
|
||||||
flash(trans('invoices.messages.email_sent'))->success();
|
flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.invoices', 1)]))->success();
|
||||||
|
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
@ -358,9 +358,9 @@ class Invoices extends Controller
|
|||||||
public function markPaid(Document $invoice)
|
public function markPaid(Document $invoice)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
event(new \App\Events\Document\PaymentReceived($invoice));
|
event(new \App\Events\Document\PaymentReceived($invoice, ['type' => 'income']));
|
||||||
|
|
||||||
$message = trans('invoices.messages.marked_paid');
|
$message = trans('general.messages.marked_paid', ['type' => trans_choice('general.invoices', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
<?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),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
26
app/Imports/Purchases/Bills.php
Normal file
26
app/Imports/Purchases/Bills.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?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,18 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Imports\Document\Sheets;
|
namespace App\Imports\Purchases\Sheets;
|
||||||
|
|
||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Http\Requests\Document\DocumentHistory as Request;
|
use App\Http\Requests\Document\DocumentHistory as Request;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
use App\Models\Document\DocumentHistory as Model;
|
use App\Models\Document\DocumentHistory as Model;
|
||||||
|
|
||||||
class DocumentHistories extends Import
|
class BillHistories extends Import
|
||||||
{
|
{
|
||||||
public function model(array $row)
|
public function model(array $row)
|
||||||
{
|
{
|
||||||
// @todo remove after laravel-excel 3.2 release
|
// @todo remove after laravel-excel 3.2 release
|
||||||
if ($row[$this->type . '_number'] == $this->empty_field) {
|
if ($row['bill_number'] === $this->empty_field) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,17 +21,17 @@ class DocumentHistories extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
if ($this->isEmpty($row, 'bill_number')) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = parent::map($row);
|
$row = parent::map($row);
|
||||||
|
|
||||||
$row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first();
|
$row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first();
|
||||||
|
|
||||||
$row['notify'] = (int) $row['notify'];
|
$row['notify'] = (int) $row['notify'];
|
||||||
|
|
||||||
$row['type'] = $this->type;
|
$row['type'] = Document::BILL_TYPE;
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
@ -40,13 +40,9 @@ class DocumentHistories extends Import
|
|||||||
{
|
{
|
||||||
$rules = (new Request())->rules();
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
if ($this->type === Document::INVOICE_TYPE) {
|
|
||||||
$rules['invoice_number'] = 'required|string';
|
|
||||||
} else {
|
|
||||||
$rules['bill_number'] = 'required|string';
|
$rules['bill_number'] = 'required|string';
|
||||||
}
|
|
||||||
|
|
||||||
unset($rules['invoice_id'], $rules['bill_id']);
|
unset($rules['bill_id']);
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Imports\Document\Sheets;
|
namespace App\Imports\Purchases\Sheets;
|
||||||
|
|
||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Http\Requests\Document\DocumentItemTax as Request;
|
use App\Http\Requests\Document\DocumentItemTax as Request;
|
||||||
@ -9,12 +9,12 @@ use App\Models\Document\Document;
|
|||||||
use App\Models\Document\DocumentItem;
|
use App\Models\Document\DocumentItem;
|
||||||
use App\Models\Document\DocumentItemTax as Model;
|
use App\Models\Document\DocumentItemTax as Model;
|
||||||
|
|
||||||
class DocumentItemTaxes extends Import
|
class BillItemTaxes extends Import
|
||||||
{
|
{
|
||||||
public function model(array $row)
|
public function model(array $row)
|
||||||
{
|
{
|
||||||
// @todo remove after laravel-excel 3.2 release
|
// @todo remove after laravel-excel 3.2 release
|
||||||
if ($row[$this->type . '_number'] == $this->empty_field) {
|
if ($row['bill_number'] === $this->empty_field) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,17 +23,17 @@ class DocumentItemTaxes extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
if ($this->isEmpty($row, 'bill_number')) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = parent::map($row);
|
$row = parent::map($row);
|
||||||
|
|
||||||
$row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first();
|
$row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first();
|
||||||
|
|
||||||
if (empty($row[$this->type . '_item_id']) && !empty($row['item_name'])) {
|
if (empty($row['bill_item_id']) && !empty($row['item_name'])) {
|
||||||
$item_id = Item::name($row['item_name'])->pluck('id')->first();
|
$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['bill_item_id'] = DocumentItem::bill()->where('item_id', $item_id)->pluck('id')->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
$row['tax_id'] = $this->getTaxId($row);
|
$row['tax_id'] = $this->getTaxId($row);
|
||||||
@ -44,7 +44,7 @@ class DocumentItemTaxes extends Import
|
|||||||
|
|
||||||
$row['amount'] = (double) $row['amount'];
|
$row['amount'] = (double) $row['amount'];
|
||||||
|
|
||||||
$row['type'] = $this->type;
|
$row['type'] = Document::BILL_TYPE;
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
@ -53,13 +53,9 @@ class DocumentItemTaxes extends Import
|
|||||||
{
|
{
|
||||||
$rules = (new Request())->rules();
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
if ($this->type === Document::INVOICE_TYPE) {
|
|
||||||
$rules['invoice_number'] = 'required|string';
|
|
||||||
} else {
|
|
||||||
$rules['bill_number'] = 'required|string';
|
$rules['bill_number'] = 'required|string';
|
||||||
}
|
|
||||||
|
|
||||||
unset($rules['invoice_id'], $rules['bill_id']);
|
unset($rules['bill_id']);
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Imports\Document\Sheets;
|
namespace App\Imports\Purchases\Sheets;
|
||||||
|
|
||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Http\Requests\Document\DocumentItem as Request;
|
use App\Http\Requests\Document\DocumentItem as Request;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
use App\Models\Document\DocumentItem as Model;
|
use App\Models\Document\DocumentItem as Model;
|
||||||
|
|
||||||
class DocumentItems extends Import
|
class BillItems extends Import
|
||||||
{
|
{
|
||||||
public function model(array $row)
|
public function model(array $row)
|
||||||
{
|
{
|
||||||
@ -16,13 +16,13 @@ class DocumentItems extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
if ($this->isEmpty($row, $this->type . '_number')) {
|
if ($this->isEmpty($row, 'bill_number')) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = parent::map($row);
|
$row = parent::map($row);
|
||||||
|
|
||||||
$row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first();
|
$row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first();
|
||||||
|
|
||||||
if (empty($row['item_id']) && !empty($row['item_name'])) {
|
if (empty($row['item_id']) && !empty($row['item_name'])) {
|
||||||
$row['item_id'] = $this->getItemIdFromName($row);
|
$row['item_id'] = $this->getItemIdFromName($row);
|
||||||
@ -32,7 +32,7 @@ class DocumentItems extends Import
|
|||||||
|
|
||||||
$row['tax'] = (double) $row['tax'];
|
$row['tax'] = (double) $row['tax'];
|
||||||
$row['tax_id'] = 0;
|
$row['tax_id'] = 0;
|
||||||
$row['type'] = $this->type;
|
$row['type'] = Document::BILL_TYPE;
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
@ -41,13 +41,9 @@ class DocumentItems extends Import
|
|||||||
{
|
{
|
||||||
$rules = (new Request())->rules();
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
if ($this->type === Document::INVOICE_TYPE) {
|
|
||||||
$rules['invoice_number'] = 'required|string';
|
|
||||||
} else {
|
|
||||||
$rules['bill_number'] = 'required|string';
|
$rules['bill_number'] = 'required|string';
|
||||||
}
|
|
||||||
|
|
||||||
unset($rules['invoice_id'], $rules['bill_id']);
|
unset($rules['bill_id']);
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
41
app/Imports/Purchases/Sheets/BillTotals.php
Normal file
41
app/Imports/Purchases/Sheets/BillTotals.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Purchases\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 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['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first();
|
||||||
|
$row['type'] = Document::BILL_TYPE;
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
|
$rules['bill_number'] = 'required|string';
|
||||||
|
|
||||||
|
unset($rules['bill_id']);
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
41
app/Imports/Purchases/Sheets/BillTransactions.php
Normal file
41
app/Imports/Purchases/Sheets/BillTransactions.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Purchases\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Import;
|
||||||
|
use App\Http\Requests\Banking\Transaction as Request;
|
||||||
|
use App\Models\Banking\Transaction as Model;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
45
app/Imports/Purchases/Sheets/Bills.php
Normal file
45
app/Imports/Purchases/Sheets/Bills.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Purchases\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 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['document_number'] = $row['bill_number'];
|
||||||
|
$row['issued_at'] = $row['billed_at'];
|
||||||
|
$row['category_id'] = $this->getCategoryId($row, 'expense');
|
||||||
|
$row['contact_id'] = $this->getContactId($row, 'vendor');
|
||||||
|
$row['type'] = Model::BILL_TYPE;
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
}
|
27
app/Imports/Sales/Invoices.php
Normal file
27
app/Imports/Sales/Invoices.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
49
app/Imports/Sales/Sheets/InvoiceHistories.php
Normal file
49
app/Imports/Sales/Sheets/InvoiceHistories.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Sales\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 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['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 rules(): array
|
||||||
|
{
|
||||||
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
|
$rules['invoice_number'] = 'required|string';
|
||||||
|
|
||||||
|
unset($rules['invoice_id']);
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
62
app/Imports/Sales/Sheets/InvoiceItemTaxes.php
Normal file
62
app/Imports/Sales/Sheets/InvoiceItemTaxes.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Sales\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 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['document_id'] = (int) Document::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'] = 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 rules(): array
|
||||||
|
{
|
||||||
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
|
$rules['invoice_number'] = 'required|string';
|
||||||
|
|
||||||
|
unset($rules['invoice_id']);
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
50
app/Imports/Sales/Sheets/InvoiceItems.php
Normal file
50
app/Imports/Sales/Sheets/InvoiceItems.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Sales\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 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['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['tax'] = (double) $row['tax'];
|
||||||
|
$row['tax_id'] = 0;
|
||||||
|
$row['type'] = Document::INVOICE_TYPE;
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
|
$rules['invoice_number'] = 'required|string';
|
||||||
|
|
||||||
|
unset($rules['invoice_id']);
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
41
app/Imports/Sales/Sheets/InvoiceTotals.php
Normal file
41
app/Imports/Sales/Sheets/InvoiceTotals.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Sales\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 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['document_id'] = (int) Document::invoice()->number($row['invoice_number'])->pluck('id')->first();
|
||||||
|
$row['type'] = Document::INVOICE_TYPE;
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
|
$rules['invoice_number'] = 'required|string';
|
||||||
|
|
||||||
|
unset($rules['invoice_id']);
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
41
app/Imports/Sales/Sheets/InvoiceTransactions.php
Normal file
41
app/Imports/Sales/Sheets/InvoiceTransactions.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
45
app/Imports/Sales/Sheets/Invoices.php
Normal file
45
app/Imports/Sales/Sheets/Invoices.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Sales\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 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['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['type'] = Model::INVOICE_TYPE;
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$rules = (new Request())->rules();
|
||||||
|
|
||||||
|
$rules['invoice_number'] = Str::replaceFirst('unique:documents,NULL', 'unique:documents,document_number', $rules['document_number']);
|
||||||
|
$rules['invoiced_at'] = $rules['issued_at'];
|
||||||
|
|
||||||
|
unset($rules['document_number'], $rules['issued_at'], $rules['type']);
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
@ -73,7 +73,6 @@ class CreateBankingDocumentTransaction extends Job
|
|||||||
|
|
||||||
$this->request['company_id'] = $this->model->company_id;
|
$this->request['company_id'] = $this->model->company_id;
|
||||||
$this->request['currency_code'] = isset($this->request['currency_code']) ? $this->request['currency_code'] : $this->model->currency_code;
|
$this->request['currency_code'] = isset($this->request['currency_code']) ? $this->request['currency_code'] : $this->model->currency_code;
|
||||||
$this->request['type'] = ($this->model->type === Document::INVOICE_TYPE) ? 'income' : 'expense';
|
|
||||||
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->format('Y-m-d');
|
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->format('Y-m-d');
|
||||||
$this->request['currency_rate'] = config('money.' . $this->request['currency_code'] . '.rate');
|
$this->request['currency_rate'] = config('money.' . $this->request['currency_code'] . '.rate');
|
||||||
$this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account');
|
$this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account');
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Models\Auth\User;
|
||||||
use App\Models\Common\Dashboard;
|
use App\Models\Common\Dashboard;
|
||||||
use App\Models\Common\Widget;
|
use App\Models\Common\Widget;
|
||||||
use App\Utilities\Widgets;
|
use App\Utilities\Widgets;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class CreateDashboard extends Job
|
class CreateDashboard extends Job
|
||||||
{
|
{
|
||||||
@ -33,40 +35,89 @@ class CreateDashboard extends Job
|
|||||||
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
|
$users = $this->getUsers();
|
||||||
|
|
||||||
|
if (empty($users)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->dashboard = Dashboard::create($this->request->only(['company_id', 'name', 'enabled']));
|
$this->dashboard = Dashboard::create($this->request->only(['company_id', 'name', 'enabled']));
|
||||||
|
|
||||||
$this->attachToUser();
|
$this->dashboard->users()->attach($users);
|
||||||
|
|
||||||
if ($this->request->has('with_widgets')) {
|
$this->checkAndCreateWidgets();
|
||||||
$this->createWidgets();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->dashboard;
|
return $this->dashboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function attachToUser()
|
protected function getUsers()
|
||||||
{
|
{
|
||||||
|
$list = [];
|
||||||
|
|
||||||
if ($this->request->has('users')) {
|
if ($this->request->has('users')) {
|
||||||
$user = $this->request->get('users');
|
$user_ids = Arr::wrap($this->request->get('users'));
|
||||||
|
|
||||||
|
foreach($user_ids as $user_id) {
|
||||||
|
$user = User::find($user_id);
|
||||||
|
|
||||||
|
if (!$this->shouldCreateDashboardFor($user)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$list[] = $user->id;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$user = user();
|
$user = user();
|
||||||
|
|
||||||
|
if ($this->shouldCreateDashboardFor($user)) {
|
||||||
|
$list[] = $user->id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($user)) {
|
return $list;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dashboard->users()->attach($user);
|
protected function shouldCreateDashboardFor($user)
|
||||||
}
|
|
||||||
|
|
||||||
protected function createWidgets()
|
|
||||||
{
|
{
|
||||||
$widgets = Widgets::getClasses(false);
|
if (empty($user)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't create dashboard if user can't access admin panel (i.e. customer with login)
|
||||||
|
if ($user->cannot('read-admin-panel')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkAndCreateWidgets()
|
||||||
|
{
|
||||||
$sort = 1;
|
$sort = 1;
|
||||||
|
|
||||||
|
if ($this->request->has('default_widgets')) {
|
||||||
|
$widgets = Widgets::getClasses(false);
|
||||||
|
|
||||||
|
$this->createWidgets($widgets, $sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request->has('custom_widgets')) {
|
||||||
|
$widgets = $this->request->get('custom_widgets');
|
||||||
|
|
||||||
|
$this->createWidgets($widgets, $sort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createWidgets($widgets, &$sort)
|
||||||
|
{
|
||||||
foreach ($widgets as $class => $name) {
|
foreach ($widgets as $class => $name) {
|
||||||
|
// It's just an array of classes
|
||||||
|
if (is_numeric($class)) {
|
||||||
|
$class = $name;
|
||||||
|
$name = (new $class())->getDefaultName();
|
||||||
|
}
|
||||||
|
|
||||||
Widget::create([
|
Widget::create([
|
||||||
'company_id' => $this->dashboard->company_id,
|
'company_id' => $this->dashboard->company_id,
|
||||||
'dashboard_id' => $this->dashboard->id,
|
'dashboard_id' => $this->dashboard->id,
|
||||||
|
@ -6,7 +6,6 @@ use App\Events\Document\DocumentCancelled as Event;
|
|||||||
use App\Jobs\Document\CancelDocument;
|
use App\Jobs\Document\CancelDocument;
|
||||||
use App\Jobs\Document\CreateDocumentHistory;
|
use App\Jobs\Document\CreateDocumentHistory;
|
||||||
use App\Traits\Jobs;
|
use App\Traits\Jobs;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class MarkDocumentCancelled
|
class MarkDocumentCancelled
|
||||||
{
|
{
|
||||||
@ -22,7 +21,6 @@ class MarkDocumentCancelled
|
|||||||
{
|
{
|
||||||
$this->dispatch(new CancelDocument($event->document));
|
$this->dispatch(new CancelDocument($event->document));
|
||||||
|
|
||||||
$type = Str::plural($event->document->type);
|
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans('general.messages.marked_cancelled', ['type' => ''])));
|
||||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans("$type.messages.marked_cancelled")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Listeners\Document;
|
|||||||
use App\Events\Document\DocumentReceived as Event;
|
use App\Events\Document\DocumentReceived as Event;
|
||||||
use App\Jobs\Document\CreateDocumentHistory;
|
use App\Jobs\Document\CreateDocumentHistory;
|
||||||
use App\Traits\Jobs;
|
use App\Traits\Jobs;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class MarkDocumentReceived
|
class MarkDocumentReceived
|
||||||
{
|
{
|
||||||
@ -25,7 +24,6 @@ class MarkDocumentReceived
|
|||||||
$event->document->save();
|
$event->document->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = Str::plural($event->document->type);
|
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans('general.messages.marked_received', ['type' => ''])));
|
||||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans("$type.messages.marked_received")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Listeners\Document;
|
|||||||
use App\Events\Document\DocumentSent as Event;
|
use App\Events\Document\DocumentSent as Event;
|
||||||
use App\Jobs\Document\CreateDocumentHistory;
|
use App\Jobs\Document\CreateDocumentHistory;
|
||||||
use App\Traits\Jobs;
|
use App\Traits\Jobs;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class MarkDocumentSent
|
class MarkDocumentSent
|
||||||
{
|
{
|
||||||
@ -25,8 +24,6 @@ class MarkDocumentSent
|
|||||||
$event->document->save();
|
$event->document->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = Str::plural($event->document->type);
|
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans('documents.messages.marked_sent', ['type' => ''])));
|
||||||
|
|
||||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans("$type.messages.marked_sent")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Listeners\Document;
|
|||||||
use App\Events\Document\DocumentViewed as Event;
|
use App\Events\Document\DocumentViewed as Event;
|
||||||
use App\Jobs\Document\CreateDocumentHistory;
|
use App\Jobs\Document\CreateDocumentHistory;
|
||||||
use App\Traits\Jobs;
|
use App\Traits\Jobs;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class MarkDocumentViewed
|
class MarkDocumentViewed
|
||||||
{
|
{
|
||||||
@ -30,8 +29,6 @@ class MarkDocumentViewed
|
|||||||
$document->status = 'viewed';
|
$document->status = 'viewed';
|
||||||
$document->save();
|
$document->save();
|
||||||
|
|
||||||
$type = Str::plural($document->type);
|
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans('general.messages.marked_viewed', ['type' => ''])));
|
||||||
|
|
||||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans("$type.messages.marked_viewed")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
namespace App\Listeners\Document;
|
namespace App\Listeners\Document;
|
||||||
|
|
||||||
use App\Events\Document\DocumentReminded as Event;
|
use App\Events\Document\DocumentReminded as Event;
|
||||||
use App\Models\Document\Document;
|
|
||||||
use App\Notifications\Sale\Invoice as InvoiceNotification;
|
|
||||||
use App\Notifications\Purchase\Bill as BillNotification;
|
|
||||||
|
|
||||||
class SendDocumentReminderNotification
|
class SendDocumentReminderNotification
|
||||||
{
|
{
|
||||||
@ -18,11 +15,7 @@ class SendDocumentReminderNotification
|
|||||||
public function handle(Event $event)
|
public function handle(Event $event)
|
||||||
{
|
{
|
||||||
$document = $event->document;
|
$document = $event->document;
|
||||||
|
$notification = $event->notification;
|
||||||
$notification = InvoiceNotification::class;
|
|
||||||
if ($document->type === Document::BILL_TYPE) {
|
|
||||||
$notification = BillNotification::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify the customer
|
// Notify the customer
|
||||||
if ($document->contact && !empty($document->contact_email)) {
|
if ($document->contact && !empty($document->contact_email)) {
|
||||||
|
@ -23,7 +23,7 @@ class Document implements Scope
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = request()->get('type') ?: Str::singular(request()->segment(2, ''));
|
$type = Str::singular(request()->segment(2, ''));
|
||||||
|
|
||||||
// Apply document scope
|
// Apply document scope
|
||||||
$builder->where($model->getTable() . '.type', '=', $type);
|
$builder->where($model->getTable() . '.type', '=', $type);
|
||||||
|
@ -404,7 +404,7 @@ trait Permissions
|
|||||||
$route = app(Route::class);
|
$route = app(Route::class);
|
||||||
|
|
||||||
// Get the controller array
|
// Get the controller array
|
||||||
$arr = array_reverse(explode('\\', explode('@', $route->getActionName())[0]));
|
$arr = array_reverse(explode('\\', explode('@', $route->getAction()['uses'])[0]));
|
||||||
|
|
||||||
$controller = '';
|
$controller = '';
|
||||||
|
|
||||||
|
@ -327,6 +327,7 @@ class Document extends AbstractFactory
|
|||||||
case 'paid':
|
case 'paid':
|
||||||
$payment_request = [
|
$payment_request = [
|
||||||
'paid_at' => $updated_document->due_at,
|
'paid_at' => $updated_document->due_at,
|
||||||
|
'type' => 'income',
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($init_status === 'partial') {
|
if ($init_status === 'partial') {
|
||||||
|
@ -33,7 +33,7 @@ class Dashboards extends Seeder
|
|||||||
$this->dispatch(new CreateDashboard([
|
$this->dispatch(new CreateDashboard([
|
||||||
'company_id' => $company_id,
|
'company_id' => $company_id,
|
||||||
'name' => trans_choice('general.dashboards', 1),
|
'name' => trans_choice('general.dashboards', 1),
|
||||||
'with_widgets' => true,
|
'default_widgets' => true,
|
||||||
'users' => $user_id,
|
'users' => $user_id,
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Events\Purchase;
|
namespace App\Events\Purchase;
|
||||||
|
|
||||||
use App\Events\Document\DocumentReminded;
|
use App\Events\Document\DocumentReminded;
|
||||||
|
use App\Models\Document\Document;
|
||||||
|
use App\Notifications\Purchase\Bill as Notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@ -10,4 +12,8 @@ use App\Events\Document\DocumentReminded;
|
|||||||
*/
|
*/
|
||||||
class BillReminded extends DocumentReminded
|
class BillReminded extends DocumentReminded
|
||||||
{
|
{
|
||||||
|
public function __construct(Document $document)
|
||||||
|
{
|
||||||
|
parent::__construct($document, Notification::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Events\Sale;
|
namespace App\Events\Sale;
|
||||||
|
|
||||||
use App\Events\Document\DocumentReminded;
|
use App\Events\Document\DocumentReminded;
|
||||||
|
use App\Models\Document\Document;
|
||||||
|
use App\Notifications\Sale\Invoice as Notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@ -10,4 +12,8 @@ use App\Events\Document\DocumentReminded;
|
|||||||
*/
|
*/
|
||||||
class InvoiceReminded extends DocumentReminded
|
class InvoiceReminded extends DocumentReminded
|
||||||
{
|
{
|
||||||
|
public function __construct(Document $document)
|
||||||
|
{
|
||||||
|
parent::__construct($document, Notification::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Exports\Purchases;
|
|
||||||
|
|
||||||
use App\Exports\Document\Documents;
|
|
||||||
use App\Models\Document\Document;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @see Document
|
|
||||||
*/
|
|
||||||
class Bills extends Documents
|
|
||||||
{
|
|
||||||
public function __construct($ids = null, string $type = '')
|
|
||||||
{
|
|
||||||
parent::__construct($ids, Document::BILL_TYPE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Exports\Sales;
|
|
||||||
|
|
||||||
use App\Exports\Document\Documents;
|
|
||||||
use App\Models\Document\Document;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @see Document
|
|
||||||
*/
|
|
||||||
class Invoices extends Documents
|
|
||||||
{
|
|
||||||
public function __construct($ids = null, string $type = '')
|
|
||||||
{
|
|
||||||
parent::__construct($ids, Document::INVOICE_TYPE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Imports\Purchases;
|
|
||||||
|
|
||||||
use App\Imports\Document\Documents;
|
|
||||||
use App\Models\Document\Document;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @see Documents
|
|
||||||
*/
|
|
||||||
class Bills extends Documents
|
|
||||||
{
|
|
||||||
public function __construct(string $type = '')
|
|
||||||
{
|
|
||||||
parent::__construct(Document::BILL_TYPE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Imports\Sales;
|
|
||||||
|
|
||||||
use App\Imports\Document\Documents;
|
|
||||||
use App\Models\Document\Document;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @see Documents
|
|
||||||
*/
|
|
||||||
class Invoices extends Documents
|
|
||||||
{
|
|
||||||
public function __construct(string $type = '')
|
|
||||||
{
|
|
||||||
parent::__construct(Document::INVOICE_TYPE);
|
|
||||||
}
|
|
||||||
}
|
|
11
modules/BC21/Jobs/Banking/CreateDocumentTransaction.php
Normal file
11
modules/BC21/Jobs/Banking/CreateDocumentTransaction.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* @see CreateBankingDocumentTransaction
|
||||||
|
*/
|
||||||
|
class CreateDocumentTransaction extends CreateBankingDocumentTransaction
|
||||||
|
{
|
||||||
|
}
|
@ -23,6 +23,7 @@
|
|||||||
{{ trans('general.confirm') }}
|
{{ trans('general.confirm') }}
|
||||||
</button>
|
</button>
|
||||||
{!! Form::hidden('payment_method', $setting['code'], ['v-model' => 'form.payment_method']) !!}
|
{!! Form::hidden('payment_method', $setting['code'], ['v-model' => 'form.payment_method']) !!}
|
||||||
|
{!! Form::hidden('type', 'income', ['v-model' => 'form.type']) !!}
|
||||||
{!! Form::close() !!}
|
{!! Form::close() !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -118,7 +118,7 @@ class Payment extends PaymentController
|
|||||||
$total_paid_match = ((double) $request['mc_gross'] == $document->amount);
|
$total_paid_match = ((double) $request['mc_gross'] == $document->amount);
|
||||||
|
|
||||||
if ($receiver_match && $total_paid_match) {
|
if ($receiver_match && $total_paid_match) {
|
||||||
event(new PaymentReceived($document, $request));
|
event(new PaymentReceived($document, $request->merge(['type' => 'income'])));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$receiver_match) {
|
if (!$receiver_match) {
|
||||||
|
@ -49,9 +49,6 @@ return [
|
|||||||
],
|
],
|
||||||
|
|
||||||
'messages' => [
|
'messages' => [
|
||||||
'marked_received' => 'Bill marked as received!',
|
|
||||||
'marked_paid' => 'Bill marked as paid!',
|
|
||||||
'marked_cancelled' => 'Bill marked as cancelled!',
|
|
||||||
'draft' => 'This is a <b>DRAFT</b> bill and will be reflected to charts after it gets received.',
|
'draft' => 'This is a <b>DRAFT</b> bill and will be reflected to charts after it gets received.',
|
||||||
|
|
||||||
'status' => [
|
'status' => [
|
||||||
|
12
resources/lang/en-GB/documents.php
Normal file
12
resources/lang/en-GB/documents.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'messages' => [
|
||||||
|
'email_sent' => ':type email has been sent!',
|
||||||
|
'marked_sent' => ':type marked as sent!',
|
||||||
|
'marked_paid' => ':type marked as paid!',
|
||||||
|
'marked_viewed' => ':type marked as viewed!',
|
||||||
|
'marked_cancelled' => ':type marked as cancelled!',
|
||||||
|
'marked_received' => ':type marked as received!',
|
||||||
|
],
|
||||||
|
];
|
@ -53,11 +53,6 @@ return [
|
|||||||
],
|
],
|
||||||
|
|
||||||
'messages' => [
|
'messages' => [
|
||||||
'email_sent' => 'Invoice email has been sent!',
|
|
||||||
'marked_sent' => 'Invoice marked as sent!',
|
|
||||||
'marked_paid' => 'Invoice marked as paid!',
|
|
||||||
'marked_viewed' => 'Invoice marked as viewed!',
|
|
||||||
'marked_cancelled' => 'Invoice marked as cancelled!',
|
|
||||||
'email_required' => 'No email address for this customer!',
|
'email_required' => 'No email address for this customer!',
|
||||||
'draft' => 'This is a <b>DRAFT</b> invoice and will be reflected to charts after it gets sent.',
|
'draft' => 'This is a <b>DRAFT</b> invoice and will be reflected to charts after it gets sent.',
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user