Merge Invoice and Bill into Document
This commit is contained in:
		@@ -1,12 +1,12 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\Api\Sales;
 | 
			
		||||
namespace App\Http\Controllers\Api\Document;
 | 
			
		||||
 | 
			
		||||
use App\Http\Requests\Banking\Transaction as Request;
 | 
			
		||||
use App\Jobs\Banking\CreateDocumentTransaction;
 | 
			
		||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
 | 
			
		||||
use App\Jobs\Banking\DeleteTransaction;
 | 
			
		||||
use App\Models\Banking\Transaction;
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Transformers\Banking\Transaction as Transformer;
 | 
			
		||||
use Dingo\Api\Routing\Helpers;
 | 
			
		||||
use Illuminate\Foundation\Bus\DispatchesJobs;
 | 
			
		||||
@@ -14,19 +14,19 @@ use Illuminate\Routing\Controller as BaseController;
 | 
			
		||||
use Illuminate\Foundation\Validation\ValidatesRequests;
 | 
			
		||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 | 
			
		||||
 | 
			
		||||
class InvoiceTransactions extends BaseController
 | 
			
		||||
class DocumentTransactions extends BaseController
 | 
			
		||||
{
 | 
			
		||||
    use Helpers, AuthorizesRequests, DispatchesJobs, ValidatesRequests;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Display a listing of the resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $invoice_id
 | 
			
		||||
     * @param  $document_id
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function index($invoice_id)
 | 
			
		||||
    public function index($document_id)
 | 
			
		||||
    {
 | 
			
		||||
        $transactions = Transaction::document($invoice_id)->get();
 | 
			
		||||
        $transactions = Transaction::document($document_id)->get();
 | 
			
		||||
 | 
			
		||||
        return $this->response->collection($transactions, new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
@@ -34,13 +34,13 @@ class InvoiceTransactions extends BaseController
 | 
			
		||||
    /**
 | 
			
		||||
     * Display the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $invoice_id
 | 
			
		||||
     * @param  $document_id
 | 
			
		||||
     * @param  $id
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function show($invoice_id, $id)
 | 
			
		||||
    public function show($document_id, $id)
 | 
			
		||||
    {
 | 
			
		||||
        $transaction = Transaction::document($invoice_id)->find($id);
 | 
			
		||||
        $transaction = Transaction::document($document_id)->find($id);
 | 
			
		||||
 | 
			
		||||
        return $this->response->item($transaction, new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
@@ -48,29 +48,29 @@ class InvoiceTransactions extends BaseController
 | 
			
		||||
    /**
 | 
			
		||||
     * Store a newly created resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $invoice_id
 | 
			
		||||
     * @param  $document_id
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function store($invoice_id, Request $request)
 | 
			
		||||
    public function store($document_id, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = Invoice::find($invoice_id);
 | 
			
		||||
        $document = Document::find($document_id);
 | 
			
		||||
 | 
			
		||||
        $transaction = $this->dispatch(new CreateDocumentTransaction($invoice, $request));
 | 
			
		||||
        $transaction = $this->dispatch(new CreateBankingDocumentTransaction($document, $request));
 | 
			
		||||
 | 
			
		||||
        return $this->response->created(url('api/invoices/' . $invoice_id . '/transactions/' . $transaction->id));
 | 
			
		||||
        return $this->response->created(route('documents.transactions.show', [$document_id, $transaction->id]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remove the specified resource from storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $invoice_id
 | 
			
		||||
     * @param  $document_id
 | 
			
		||||
     * @param  $id
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function destroy($invoice_id, $id)
 | 
			
		||||
    public function destroy($document_id, $id)
 | 
			
		||||
    {
 | 
			
		||||
        $transaction = Transaction::document($invoice_id)->find($id);
 | 
			
		||||
        $transaction = Transaction::document($document_id)->find($id);
 | 
			
		||||
 | 
			
		||||
        $this->dispatch(new DeleteTransaction($transaction));
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										91
									
								
								app/Http/Controllers/Api/Document/Documents.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								app/Http/Controllers/Api/Document/Documents.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,91 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\Api\Document;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\ApiController;
 | 
			
		||||
use App\Http\Requests\Document\Document as Request;
 | 
			
		||||
use App\Jobs\Document\CreateDocument;
 | 
			
		||||
use App\Jobs\Document\DeleteDocument;
 | 
			
		||||
use App\Jobs\Document\UpdateDocument;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Transformers\Document\Document as Transformer;
 | 
			
		||||
 | 
			
		||||
class Documents extends ApiController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Display a listing of the resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        $documents = Document::with('contact', 'histories', 'items', 'transactions')->collect(['issued_at'=> 'desc']);
 | 
			
		||||
 | 
			
		||||
        return $this->response->paginator($documents, new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Display the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $id
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function show($id)
 | 
			
		||||
    {
 | 
			
		||||
        // Check if we're querying by id or number
 | 
			
		||||
        if (is_numeric($id)) {
 | 
			
		||||
            $document = Document::find($id);
 | 
			
		||||
        } else {
 | 
			
		||||
            $document = Document::where('document_number', $id)->first();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->response->item($document, new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Store a newly created resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function store(Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $document = $this->dispatch(new CreateDocument($request));
 | 
			
		||||
 | 
			
		||||
        return $this->response->created(route('api.documents.show', $document->id));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the specified resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $document
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function update(Document $document, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $document = $this->dispatch(new UpdateDocument($document, $request));
 | 
			
		||||
 | 
			
		||||
        return $this->response->item($document->fresh(), new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remove the specified resource from storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Document $document
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function destroy(Document $document)
 | 
			
		||||
    {
 | 
			
		||||
        try {
 | 
			
		||||
            $this->dispatch(new DeleteDocument($document));
 | 
			
		||||
 | 
			
		||||
            return $this->response->noContent();
 | 
			
		||||
        } catch(\Exception $e) {
 | 
			
		||||
            $this->response->errorUnauthorized($e->getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,81 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\Api\Purchases;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\ApiController;
 | 
			
		||||
use App\Http\Requests\Purchase\Bill as Request;
 | 
			
		||||
use App\Jobs\Purchase\CreateBill;
 | 
			
		||||
use App\Jobs\Purchase\DeleteBill;
 | 
			
		||||
use App\Jobs\Purchase\UpdateBill;
 | 
			
		||||
use App\Models\Purchase\Bill;
 | 
			
		||||
use App\Transformers\Purchase\Bill as Transformer;
 | 
			
		||||
 | 
			
		||||
class Bills extends ApiController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Display a listing of the resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        $bills = Bill::with('contact', 'histories', 'items', 'transactions')->collect(['billed_at'=> 'desc']);
 | 
			
		||||
 | 
			
		||||
        return $this->response->paginator($bills, new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Display the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill  $bill
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function show(Bill $bill)
 | 
			
		||||
    {
 | 
			
		||||
        return $this->response->item($bill, new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Store a newly created resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function store(Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $bill = $this->dispatch(new CreateBill($request));
 | 
			
		||||
 | 
			
		||||
        return $this->response->created(route('api.bills.show', $bill->id));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the specified resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $bill
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function update(Bill $bill, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $bill = $this->dispatch(new UpdateBill($bill, $request));
 | 
			
		||||
 | 
			
		||||
        return $this->item($bill->fresh(), new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remove the specified resource from storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill  $bill
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function destroy(Bill $bill)
 | 
			
		||||
    {
 | 
			
		||||
        try {
 | 
			
		||||
            $this->dispatch(new DeleteBill($bill));
 | 
			
		||||
 | 
			
		||||
            return $this->response->noContent();
 | 
			
		||||
        } catch(\Exception $e) {
 | 
			
		||||
            $this->response->errorUnauthorized($e->getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,88 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\Api\Sales;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\ApiController;
 | 
			
		||||
use App\Http\Requests\Sale\Invoice as Request;
 | 
			
		||||
use App\Jobs\Sale\CreateInvoice;
 | 
			
		||||
use App\Jobs\Sale\DeleteInvoice;
 | 
			
		||||
use App\Jobs\Sale\UpdateInvoice;
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Transformers\Sale\Invoice as Transformer;
 | 
			
		||||
 | 
			
		||||
class Invoices extends ApiController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Display a listing of the resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        $invoices = Invoice::with('contact', 'histories', 'items', 'transactions')->collect(['invoiced_at'=> 'desc']);
 | 
			
		||||
 | 
			
		||||
        return $this->response->paginator($invoices, new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Display the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $id
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function show($id)
 | 
			
		||||
    {
 | 
			
		||||
        // Check if we're querying by id or number
 | 
			
		||||
        if (is_numeric($id)) {
 | 
			
		||||
            $invoice = Invoice::find($id);
 | 
			
		||||
        } else {
 | 
			
		||||
            $invoice = Invoice::where('invoice_number', $id)->first();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->response->item($invoice, new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Store a newly created resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function store(Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = $this->dispatch(new CreateInvoice($request));
 | 
			
		||||
 | 
			
		||||
        return $this->response->created(route('api.invoices.show', $invoice->id));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the specified resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $invoice
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function update(Invoice $invoice, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = $this->dispatch(new UpdateInvoice($invoice, $request));
 | 
			
		||||
 | 
			
		||||
        return $this->response->item($invoice->fresh(), new Transformer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remove the specified resource from storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice  $invoice
 | 
			
		||||
     * @return \Dingo\Api\Http\Response
 | 
			
		||||
     */
 | 
			
		||||
    public function destroy(Invoice $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        try {
 | 
			
		||||
            $this->dispatch(new DeleteInvoice($invoice));
 | 
			
		||||
 | 
			
		||||
            return $this->response->noContent();
 | 
			
		||||
        } catch(\Exception $e) {
 | 
			
		||||
            $this->response->errorUnauthorized($e->getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -303,7 +303,7 @@ class Items extends Controller
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                $item->total = money($total, $currency_code, true)->format();
 | 
			
		||||
                $item->total = $total;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,7 @@ use App\Events\Common\GlobalSearched;
 | 
			
		||||
use App\Models\Banking\Account;
 | 
			
		||||
use App\Models\Banking\Transaction;
 | 
			
		||||
use App\Models\Common\Contact;
 | 
			
		||||
use App\Models\Purchase\Bill;
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Models\Common\Item;
 | 
			
		||||
 | 
			
		||||
class Search extends Controller
 | 
			
		||||
@@ -52,13 +51,13 @@ class Search extends Controller
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $invoices = Invoice::usingSearchString($search->keyword)->get();
 | 
			
		||||
        $invoices = Document::invoice()->usingSearchString($search->keyword)->get();
 | 
			
		||||
 | 
			
		||||
        if ($invoices->count()) {
 | 
			
		||||
            foreach ($invoices as $invoice) {
 | 
			
		||||
                $search->results[] = (object) [
 | 
			
		||||
                    'id'    => $invoice->id,
 | 
			
		||||
                    'name'  => $invoice->invoice_number . ' - ' . $invoice->contact_name,
 | 
			
		||||
                    'name'  => $invoice->document_number . ' - ' . $invoice->contact_name,
 | 
			
		||||
                    'type'  => trans_choice('general.invoices', 1),
 | 
			
		||||
                    'color' => '#6da252',
 | 
			
		||||
                    'href'  => route('invoices.show', $invoice->id),
 | 
			
		||||
@@ -96,13 +95,13 @@ class Search extends Controller
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $bills = Bill::usingSearchString($search->keyword)->get();
 | 
			
		||||
        $bills = Document::bill()->usingSearchString($search->keyword)->get();
 | 
			
		||||
 | 
			
		||||
        if ($bills->count()) {
 | 
			
		||||
            foreach ($bills as $bill) {
 | 
			
		||||
                $search->results[] = (object) [
 | 
			
		||||
                    'id'    => $bill->id,
 | 
			
		||||
                    'name'  => $bill->bill_number . ' - ' . $bill->contact_name,
 | 
			
		||||
                    'name'  => $bill->document_number . ' - ' . $bill->contact_name,
 | 
			
		||||
                    'type'  => trans_choice('general.bills', 1),
 | 
			
		||||
                    'color' => '#ef3232',
 | 
			
		||||
                    'href'  => route('bills.show', $bill->id),
 | 
			
		||||
 
 | 
			
		||||
@@ -4,10 +4,10 @@ namespace App\Http\Controllers\Modals;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Http\Requests\Banking\Transaction as Request;
 | 
			
		||||
use App\Jobs\Banking\CreateDocumentTransaction;
 | 
			
		||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
 | 
			
		||||
use App\Models\Banking\Account;
 | 
			
		||||
use App\Models\Banking\Transaction;
 | 
			
		||||
use App\Models\Purchase\Bill;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
use App\Utilities\Modules;
 | 
			
		||||
use App\Traits\Uploads;
 | 
			
		||||
@@ -31,11 +31,11 @@ class BillTransactions extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for creating a new resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill  $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function create(Bill $bill)
 | 
			
		||||
    public function create(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
@@ -86,14 +86,14 @@ class BillTransactions extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Store a newly created resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill  $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     * @param  Request  $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function store(Bill $bill, Request $request)
 | 
			
		||||
    public function store(Document $bill, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateDocumentTransaction($bill, $request));
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateBankingDocumentTransaction($bill, $request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['redirect'] = route('bills.show', $bill->id);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										38
									
								
								app/Http/Controllers/Modals/Companies.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								app/Http/Controllers/Modals/Companies.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\Modals;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Models\Common\Company;
 | 
			
		||||
 | 
			
		||||
class Companies extends Controller
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Instantiate a new controller instance.
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        // Add CRUD permission check
 | 
			
		||||
        $this->middleware('permission:read-settings-company')->only('index', 'show', 'edit', 'export');
 | 
			
		||||
        $this->middleware('permission:update-settings-settings')->only('update', 'enable', 'disable');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for editing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Company  $company
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function edit(Company $company)
 | 
			
		||||
    {
 | 
			
		||||
        $html = view('modals.companies.edit', compact('company'))->render();
 | 
			
		||||
 | 
			
		||||
        return response()->json([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'error' => false,
 | 
			
		||||
            'message' => 'null',
 | 
			
		||||
            'html' => $html,
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -4,7 +4,9 @@ namespace App\Http\Controllers\Modals;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Http\Requests\Common\Contact as Request;
 | 
			
		||||
use App\Models\Common\Contact;
 | 
			
		||||
use App\Jobs\Common\CreateContact;
 | 
			
		||||
use App\Jobs\Common\UpdateContact;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
 | 
			
		||||
class Customers extends Controller
 | 
			
		||||
@@ -60,6 +62,7 @@ class Customers extends Controller
 | 
			
		||||
        $request['enabled'] = 1;
 | 
			
		||||
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateContact($request));
 | 
			
		||||
        $this->ajaxDispatch(new UpdateContact($customer, $request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['message'] = trans('messages.success.added', ['type' => trans_choice('general.customers', 1)]);
 | 
			
		||||
@@ -67,4 +70,54 @@ class Customers extends Controller
 | 
			
		||||
 | 
			
		||||
        return response()->json($response);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for editing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Contact  $customer
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function edit(Contact $customer)
 | 
			
		||||
    {
 | 
			
		||||
        $currencies = Currency::enabled()->pluck('name', 'code');
 | 
			
		||||
 | 
			
		||||
        $contact_selector = false;
 | 
			
		||||
 | 
			
		||||
        if (request()->has('contact_selector')) {
 | 
			
		||||
            $contact_selector = request()->get('contact_selector');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $rand = rand();
 | 
			
		||||
 | 
			
		||||
        $html = view('modals.customers.edit', compact('customer', 'currencies', 'contact_selector', 'rand'))->render();
 | 
			
		||||
 | 
			
		||||
        return response()->json([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'error' => false,
 | 
			
		||||
            'message' => 'null',
 | 
			
		||||
            'html' => $html,
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the specified resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Contact $customer
 | 
			
		||||
     * @param  Request $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function update(Contact $customer, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $request['enabled'] = 1;
 | 
			
		||||
 | 
			
		||||
        $response = $this->ajaxDispatch(new UpdateContact($customer, $request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['message'] = trans('messages.success.updated', ['type' => trans_choice('general.customers', 1)]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return response()->json($response);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										116
									
								
								app/Http/Controllers/Modals/InvoiceItemColumns.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								app/Http/Controllers/Modals/InvoiceItemColumns.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,116 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\Modals;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Http\Requests\Setting\Setting as Request;
 | 
			
		||||
 | 
			
		||||
class InvoiceItemColumns extends Controller
 | 
			
		||||
{
 | 
			
		||||
    public $skip_keys = ['company_id', '_method', '_token', '_prefix', '_template'];
 | 
			
		||||
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        // Add CRUD permission check
 | 
			
		||||
        $this->middleware('permission:read-settings-settings')->only('index', 'edit');
 | 
			
		||||
        $this->middleware('permission:update-settings-settings')->only('update', 'enable', 'disable');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for editing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Contact  $customer
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function edit()
 | 
			
		||||
    {
 | 
			
		||||
        $item_names = [
 | 
			
		||||
            'settings.invoice.item' => trans('settings.invoice.item'),
 | 
			
		||||
            'settings.invoice.product' => trans('settings.invoice.product'),
 | 
			
		||||
            'settings.invoice.service' =>  trans('settings.invoice.service'),
 | 
			
		||||
            'custom' => trans('settings.invoice.custom'),
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $price_names = [
 | 
			
		||||
            'settings.invoice.price' => trans('settings.invoice.price'),
 | 
			
		||||
            'settings.invoice.rate' => trans('settings.invoice.rate'),
 | 
			
		||||
            'custom' => trans('settings.invoice.custom'),
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $quantity_names = [
 | 
			
		||||
            'settings.invoice.quantity' => trans('settings.invoice.quantity'),
 | 
			
		||||
            'custom' => trans('settings.invoice.custom'),
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $payment_terms = [
 | 
			
		||||
            '0' => trans('settings.invoice.due_receipt'),
 | 
			
		||||
            '15' => trans('settings.invoice.due_days', ['days' => 15]),
 | 
			
		||||
            '30' => trans('settings.invoice.due_days', ['days' => 30]),
 | 
			
		||||
            '45' => trans('settings.invoice.due_days', ['days' => 45]),
 | 
			
		||||
            '60' => trans('settings.invoice.due_days', ['days' => 60]),
 | 
			
		||||
            '90' => trans('settings.invoice.due_days', ['days' => 90]),
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $html = view('modals.invoices.item_columns', compact(
 | 
			
		||||
            'item_names',
 | 
			
		||||
            'price_names',
 | 
			
		||||
            'quantity_names',
 | 
			
		||||
            'payment_terms'
 | 
			
		||||
        ))->render();
 | 
			
		||||
 | 
			
		||||
        return response()->json([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'error' => false,
 | 
			
		||||
            'message' => 'null',
 | 
			
		||||
            'html' => $html,
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the specified resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Request $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function update(Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $fields = $request->all();
 | 
			
		||||
        $prefix = $request->get('_prefix', 'invoice');
 | 
			
		||||
        $company_id = $request->get('company_id');
 | 
			
		||||
 | 
			
		||||
        if (empty($company_id)) {
 | 
			
		||||
            $company_id = session('company_id');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        foreach ($fields as $key => $value) {
 | 
			
		||||
            $real_key = $prefix . '.' . $key;
 | 
			
		||||
 | 
			
		||||
            // Don't process unwanted keys
 | 
			
		||||
            if (in_array($key, $this->skip_keys)) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            setting()->set($real_key, $value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Save all settings
 | 
			
		||||
        setting()->save();
 | 
			
		||||
 | 
			
		||||
        $message = trans('messages.success.updated', ['type' => trans_choice('general.settings', 2)]);
 | 
			
		||||
 | 
			
		||||
        $response = [
 | 
			
		||||
            'status' => null,
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'error' => false,
 | 
			
		||||
            'message' => $message,
 | 
			
		||||
            'data' => null,
 | 
			
		||||
            'redirect' => route('settings.invoice.edit'),
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        flash($message)->success();
 | 
			
		||||
 | 
			
		||||
        return response()->json($response);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -4,10 +4,10 @@ namespace App\Http\Controllers\Modals;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Http\Requests\Banking\Transaction as Request;
 | 
			
		||||
use App\Jobs\Banking\CreateDocumentTransaction;
 | 
			
		||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
 | 
			
		||||
use App\Models\Banking\Account;
 | 
			
		||||
use App\Models\Banking\Transaction;
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
use App\Utilities\Modules;
 | 
			
		||||
use App\Traits\Uploads;
 | 
			
		||||
@@ -31,11 +31,11 @@ class InvoiceTransactions extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for creating a new resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice  $invoice
 | 
			
		||||
     * @param  Document  $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function create(Invoice $invoice)
 | 
			
		||||
    public function create(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
@@ -91,14 +91,14 @@ class InvoiceTransactions extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Store a newly created resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param Invoice $invoice
 | 
			
		||||
     * @param Document $invoice
 | 
			
		||||
     * @param Request $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function store(Invoice $invoice, Request $request)
 | 
			
		||||
    public function store(Document $invoice, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateDocumentTransaction($invoice, $request));
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateBankingDocumentTransaction($invoice, $request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['redirect'] = route('invoices.show', $invoice->id);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,9 @@ namespace App\Http\Controllers\Modals;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Http\Requests\Common\Contact as Request;
 | 
			
		||||
use App\Models\Common\Contact;
 | 
			
		||||
use App\Jobs\Common\CreateContact;
 | 
			
		||||
use App\Jobs\Common\UpdateContact;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
 | 
			
		||||
class Vendors extends Controller
 | 
			
		||||
@@ -67,4 +69,54 @@ class Vendors extends Controller
 | 
			
		||||
 | 
			
		||||
        return response()->json($response);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for editing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Contact  $vendor
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function edit(Contact $vendor)
 | 
			
		||||
    {
 | 
			
		||||
        $currencies = Currency::enabled()->pluck('name', 'code');
 | 
			
		||||
 | 
			
		||||
        $contact_selector = false;
 | 
			
		||||
 | 
			
		||||
        if (request()->has('contact_selector')) {
 | 
			
		||||
            $contact_selector = request()->get('contact_selector');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $rand = rand();
 | 
			
		||||
 | 
			
		||||
        $html = view('modals.vendors.edit', compact('vendor', 'currencies', 'contact_selector', 'rand'))->render();
 | 
			
		||||
 | 
			
		||||
        return response()->json([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'error' => false,
 | 
			
		||||
            'message' => 'null',
 | 
			
		||||
            'html' => $html,
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the specified resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Contact $vendor
 | 
			
		||||
     * @param  Request $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function update(Contact $vendor, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $request['enabled'] = 1;
 | 
			
		||||
 | 
			
		||||
        $response = $this->ajaxDispatch(new UpdateContact($vendor, $request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['message'] = trans('messages.success.updated', ['type' => trans_choice('general.vendors', 1)]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return response()->json($response);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\Portal;
 | 
			
		||||
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Traits\Charts;
 | 
			
		||||
use App\Utilities\Chartjs;
 | 
			
		||||
use Date;
 | 
			
		||||
@@ -20,7 +20,7 @@ class Dashboard
 | 
			
		||||
    {
 | 
			
		||||
        $contact = user()->contact;
 | 
			
		||||
 | 
			
		||||
        $invoices = Invoice::accrued()->where('contact_id', $contact->id)->get();
 | 
			
		||||
        $invoices = Document::invoice()->accrued()->where('contact_id', $contact->id)->get();
 | 
			
		||||
 | 
			
		||||
        $start = Date::parse(request('start', Date::today()->startOfYear()->format('Y-m-d')));
 | 
			
		||||
        $end = Date::parse(request('end', Date::today()->endOfYear()->format('Y-m-d')));
 | 
			
		||||
 
 | 
			
		||||
@@ -4,18 +4,23 @@ namespace App\Http\Controllers\Portal;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Http\Requests\Portal\InvoiceShow as Request;
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Models\Setting\Category;
 | 
			
		||||
use App\Traits\Currencies;
 | 
			
		||||
use App\Traits\DateTime;
 | 
			
		||||
use App\Traits\Sales;
 | 
			
		||||
use App\Traits\Documents;
 | 
			
		||||
use App\Traits\Uploads;
 | 
			
		||||
use App\Utilities\Modules;
 | 
			
		||||
use Illuminate\Support\Facades\URL;
 | 
			
		||||
 | 
			
		||||
class Invoices extends Controller
 | 
			
		||||
{
 | 
			
		||||
    use DateTime, Currencies, Sales, Uploads;
 | 
			
		||||
    use DateTime, Currencies, Documents, Uploads;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    public $type = Document::INVOICE_TYPE;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Display a listing of the resource.
 | 
			
		||||
@@ -24,13 +29,13 @@ class Invoices extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        $invoices = Invoice::with('contact', 'histories', 'items', 'payments')
 | 
			
		||||
        $invoices = Document::invoice()->with('contact', 'histories', 'items', 'payments')
 | 
			
		||||
            ->accrued()->where('contact_id', user()->contact->id)
 | 
			
		||||
            ->collect(['invoice_number'=> 'desc']);
 | 
			
		||||
            ->collect(['document_number'=> 'desc']);
 | 
			
		||||
 | 
			
		||||
        $categories = collect(Category::income()->enabled()->orderBy('name')->pluck('name', 'id'));
 | 
			
		||||
 | 
			
		||||
        $statuses = $this->getInvoiceStatuses();
 | 
			
		||||
        $statuses = $this->getDocumentStatuses(Document::INVOICE_TYPE);
 | 
			
		||||
 | 
			
		||||
        return $this->response('portal.invoices.index', compact('invoices', 'categories', 'statuses'));
 | 
			
		||||
    }
 | 
			
		||||
@@ -38,15 +43,15 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for viewing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice  $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function show(Invoice $invoice, Request $request)
 | 
			
		||||
    public function show(Document $invoice, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $payment_methods = Modules::getPaymentMethods();
 | 
			
		||||
 | 
			
		||||
        event(new \App\Events\Sale\InvoiceViewed($invoice));
 | 
			
		||||
        event(new \App\Events\Document\DocumentViewed($invoice));
 | 
			
		||||
 | 
			
		||||
        return view('portal.invoices.show', compact('invoice', 'payment_methods'));
 | 
			
		||||
    }
 | 
			
		||||
@@ -54,11 +59,11 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for viewing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice  $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function printInvoice(Invoice $invoice, Request $request)
 | 
			
		||||
    public function printInvoice(Document $invoice, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = $this->prepareInvoice($invoice);
 | 
			
		||||
 | 
			
		||||
@@ -68,11 +73,11 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for viewing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice  $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function pdfInvoice(Invoice $invoice, Request $request)
 | 
			
		||||
    public function pdfInvoice(Document $invoice, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = $this->prepareInvoice($invoice);
 | 
			
		||||
 | 
			
		||||
@@ -91,16 +96,16 @@ class Invoices extends Controller
 | 
			
		||||
        return $pdf->download($file_name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function prepareInvoice(Invoice $invoice)
 | 
			
		||||
    protected function prepareInvoice(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $invoice->template_path = 'sales.invoices.print_' . setting('invoice.template' ,'default');
 | 
			
		||||
 | 
			
		||||
        event(new \App\Events\Sale\InvoicePrinting($invoice));
 | 
			
		||||
        event(new \App\Events\Document\DocumentPrinting($invoice));
 | 
			
		||||
 | 
			
		||||
        return $invoice;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function signed(Invoice $invoice)
 | 
			
		||||
    public function signed(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        if (empty($invoice)) {
 | 
			
		||||
            redirect()->route('login');
 | 
			
		||||
@@ -121,7 +126,7 @@ class Invoices extends Controller
 | 
			
		||||
        $print_action = URL::signedRoute('signed.invoices.print', [$invoice->id, 'company_id' => session('company_id')]);
 | 
			
		||||
        $pdf_action = URL::signedRoute('signed.invoices.pdf', [$invoice->id, 'company_id' => session('company_id')]);
 | 
			
		||||
 | 
			
		||||
        event(new \App\Events\Sale\InvoiceViewed($invoice));
 | 
			
		||||
        event(new \App\Events\Document\DocumentViewed($invoice));
 | 
			
		||||
 | 
			
		||||
        return view('portal.invoices.signed', compact('invoice', 'payment_methods', 'payment_actions', 'print_action', 'pdf_action'));
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,32 +3,37 @@
 | 
			
		||||
namespace App\Http\Controllers\Purchases;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Exports\Purchases\Bills as Export;
 | 
			
		||||
use App\Exports\Document\Documents as Export;
 | 
			
		||||
use App\Http\Requests\Common\Import as ImportRequest;
 | 
			
		||||
use App\Http\Requests\Purchase\Bill as Request;
 | 
			
		||||
use App\Http\Requests\Purchase\BillAddItem as ItemRequest;
 | 
			
		||||
use App\Imports\Purchases\Bills as Import;
 | 
			
		||||
use App\Jobs\Banking\CreateDocumentTransaction;
 | 
			
		||||
use App\Jobs\Purchase\CreateBill;
 | 
			
		||||
use App\Jobs\Purchase\DeleteBill;
 | 
			
		||||
use App\Jobs\Purchase\DuplicateBill;
 | 
			
		||||
use App\Jobs\Purchase\UpdateBill;
 | 
			
		||||
use App\Http\Requests\Document\Document as Request;
 | 
			
		||||
use App\Http\Requests\Document\DocumentAddItem as ItemRequest;
 | 
			
		||||
use App\Imports\Document\Documents as Import;
 | 
			
		||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
 | 
			
		||||
use App\Jobs\Document\CreateDocument;
 | 
			
		||||
use App\Jobs\Document\DeleteDocument;
 | 
			
		||||
use App\Jobs\Document\DuplicateDocument;
 | 
			
		||||
use App\Jobs\Document\UpdateDocument;
 | 
			
		||||
use App\Models\Banking\Account;
 | 
			
		||||
use App\Models\Common\Contact;
 | 
			
		||||
use App\Models\Common\Item;
 | 
			
		||||
use App\Models\Purchase\Bill;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Models\Setting\Category;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
use App\Models\Setting\Tax;
 | 
			
		||||
use App\Traits\Currencies;
 | 
			
		||||
use App\Traits\DateTime;
 | 
			
		||||
use App\Traits\Purchases;
 | 
			
		||||
use App\Traits\Documents;
 | 
			
		||||
use App\Traits\Uploads;
 | 
			
		||||
use App\Utilities\Modules;
 | 
			
		||||
 | 
			
		||||
class Bills extends Controller
 | 
			
		||||
{
 | 
			
		||||
    use Currencies, DateTime, Purchases, Uploads;
 | 
			
		||||
    use Currencies, DateTime, Documents, Uploads;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    public $type = Document::BILL_TYPE;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Display a listing of the resource.
 | 
			
		||||
@@ -37,7 +42,7 @@ class Bills extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        $bills = Bill::with('contact', 'transactions')->collect(['billed_at'=> 'desc']);
 | 
			
		||||
        $bills = Document::bill()->with('contact', 'transactions')->collect(['issued_at' => 'desc']);
 | 
			
		||||
 | 
			
		||||
        return $this->response('purchases.bills.index', compact('bills'));
 | 
			
		||||
    }
 | 
			
		||||
@@ -45,11 +50,11 @@ class Bills extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for viewing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill  $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function show(Bill $bill)
 | 
			
		||||
    public function show(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
@@ -100,11 +105,9 @@ class Bills extends Controller
 | 
			
		||||
 | 
			
		||||
        $taxes = Tax::enabled()->orderBy('name')->get();
 | 
			
		||||
 | 
			
		||||
        $categories = Category::expense()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
 | 
			
		||||
        $number = $this->getNextDocumentNumber(Document::BILL_TYPE);
 | 
			
		||||
 | 
			
		||||
        $number = $this->getNextBillNumber();
 | 
			
		||||
 | 
			
		||||
        return view('purchases.bills.create', compact('vendors', 'currencies', 'currency', 'items', 'taxes', 'categories', 'number'));
 | 
			
		||||
        return view('purchases.bills.create', compact('vendors', 'currencies', 'currency', 'items', 'taxes', 'number'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -116,7 +119,7 @@ class Bills extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function store(Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateBill($request));
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateDocument($request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['redirect'] = route('bills.show', $response['data']->id);
 | 
			
		||||
@@ -138,13 +141,13 @@ class Bills extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Duplicate the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function duplicate(Bill $bill)
 | 
			
		||||
    public function duplicate(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        $clone = $this->dispatch(new DuplicateBill($bill));
 | 
			
		||||
        $clone = $this->dispatch(new DuplicateDocument($bill));
 | 
			
		||||
 | 
			
		||||
        $message = trans('messages.success.duplicated', ['type' => trans_choice('general.bills', 1)]);
 | 
			
		||||
 | 
			
		||||
@@ -163,7 +166,7 @@ class Bills extends Controller
 | 
			
		||||
    public function import(ImportRequest $request)
 | 
			
		||||
    {
 | 
			
		||||
        try {
 | 
			
		||||
            \Excel::import(new Import(), $request->file('import'));
 | 
			
		||||
            \Excel::import(new Import(Document::BILL_TYPE), $request->file('import'));
 | 
			
		||||
        } catch (\Maatwebsite\Excel\Exceptions\SheetNotFoundException $e) {
 | 
			
		||||
            flash($e->getMessage())->error()->important();
 | 
			
		||||
 | 
			
		||||
@@ -180,11 +183,11 @@ class Bills extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for editing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill  $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function edit(Bill $bill)
 | 
			
		||||
    public function edit(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        $vendors = Contact::vendor()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
@@ -196,22 +199,20 @@ class Bills extends Controller
 | 
			
		||||
 | 
			
		||||
        $taxes = Tax::enabled()->orderBy('name')->get();
 | 
			
		||||
 | 
			
		||||
        $categories = Category::expense()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
        return view('purchases.bills.edit', compact('bill', 'vendors', 'currencies', 'currency', 'items', 'taxes', 'categories'));
 | 
			
		||||
        return view('purchases.bills.edit', compact('bill', 'vendors', 'currencies', 'currency', 'items', 'taxes'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the specified resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill $bill
 | 
			
		||||
     * @param  Request $request
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     * @param  Request  $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function update(Bill $bill, Request $request)
 | 
			
		||||
    public function update(Document $bill, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->ajaxDispatch(new UpdateBill($bill, $request));
 | 
			
		||||
        $response = $this->ajaxDispatch(new UpdateDocument($bill, $request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['redirect'] = route('bills.show', $response['data']->id);
 | 
			
		||||
@@ -237,9 +238,9 @@ class Bills extends Controller
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function destroy(Bill $bill)
 | 
			
		||||
    public function destroy(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->ajaxDispatch(new DeleteBill($bill));
 | 
			
		||||
        $response = $this->ajaxDispatch(new DeleteDocument($bill));
 | 
			
		||||
 | 
			
		||||
        $response['redirect'] = route('bills.index');
 | 
			
		||||
 | 
			
		||||
@@ -263,19 +264,19 @@ class Bills extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function export()
 | 
			
		||||
    {
 | 
			
		||||
        return \Excel::download(new Export(), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx');
 | 
			
		||||
        return \Excel::download(new Export(null, Document::BILL_TYPE), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark the bill as received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function markReceived(Bill $bill)
 | 
			
		||||
    public function markReceived(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        event(new \App\Events\Purchase\BillReceived($bill));
 | 
			
		||||
        event(new \App\Events\Document\DocumentReceived($bill));
 | 
			
		||||
 | 
			
		||||
        $message = trans('bills.messages.marked_received');
 | 
			
		||||
 | 
			
		||||
@@ -287,13 +288,13 @@ class Bills extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark the bill as cancelled.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function markCancelled(Bill $bill)
 | 
			
		||||
    public function markCancelled(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        event(new \App\Events\Purchase\BillCancelled($bill));
 | 
			
		||||
        event(new \App\Events\Document\DocumentCancelled($bill));
 | 
			
		||||
 | 
			
		||||
        $message = trans('bills.messages.marked_cancelled');
 | 
			
		||||
 | 
			
		||||
@@ -305,11 +306,11 @@ class Bills extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Print the bill.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function printBill(Bill $bill)
 | 
			
		||||
    public function printBill(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        $bill = $this->prepareBill($bill);
 | 
			
		||||
 | 
			
		||||
@@ -321,11 +322,11 @@ class Bills extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Download the PDF file of bill.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function pdfBill(Bill $bill)
 | 
			
		||||
    public function pdfBill(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        $bill = $this->prepareBill($bill);
 | 
			
		||||
 | 
			
		||||
@@ -345,14 +346,14 @@ class Bills extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark the bill as paid.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Bill $bill
 | 
			
		||||
     * @param  Document $bill
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function markPaid(Bill $bill)
 | 
			
		||||
    public function markPaid(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        try {
 | 
			
		||||
            $this->dispatch(new CreateDocumentTransaction($bill, []));
 | 
			
		||||
            $this->dispatch(new CreateBankingDocumentTransaction($bill, []));
 | 
			
		||||
 | 
			
		||||
            $message = trans('bills.messages.marked_paid');
 | 
			
		||||
 | 
			
		||||
@@ -397,7 +398,7 @@ class Bills extends Controller
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function prepareBill(Bill $bill)
 | 
			
		||||
    protected function prepareBill(Document $bill)
 | 
			
		||||
    {
 | 
			
		||||
        $paid = 0;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ use App\Jobs\Common\DeleteContact;
 | 
			
		||||
use App\Jobs\Common\UpdateContact;
 | 
			
		||||
use App\Models\Banking\Transaction;
 | 
			
		||||
use App\Models\Common\Contact;
 | 
			
		||||
use App\Models\Purchase\Bill;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
use App\Traits\Contacts;
 | 
			
		||||
use Date;
 | 
			
		||||
@@ -51,7 +51,7 @@ class Vendors extends Controller
 | 
			
		||||
        $counts = [];
 | 
			
		||||
 | 
			
		||||
        // Handle bills
 | 
			
		||||
        $bills = Bill::with('transactions')->where('contact_id', $vendor->id)->get();
 | 
			
		||||
        $bills = Document::bill()->with('transactions')->where('contact_id', $vendor->id)->get();
 | 
			
		||||
 | 
			
		||||
        $counts['bills'] = $bills->count();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ use App\Jobs\Common\DeleteContact;
 | 
			
		||||
use App\Jobs\Common\UpdateContact;
 | 
			
		||||
use App\Models\Banking\Transaction;
 | 
			
		||||
use App\Models\Common\Contact;
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
use Date;
 | 
			
		||||
use Illuminate\Http\Request as BaseRequest;
 | 
			
		||||
@@ -49,7 +49,7 @@ class Customers extends Controller
 | 
			
		||||
        $counts = [];
 | 
			
		||||
 | 
			
		||||
        // Handle invoices
 | 
			
		||||
        $invoices = Invoice::with('transactions')->where('contact_id', $customer->id)->get();
 | 
			
		||||
        $invoices = Document::invoice()->with('transactions')->where('contact_id', $customer->id)->get();
 | 
			
		||||
 | 
			
		||||
        $counts['invoices'] = $invoices->count();
 | 
			
		||||
 | 
			
		||||
@@ -87,7 +87,7 @@ class Customers extends Controller
 | 
			
		||||
 | 
			
		||||
        $limit = request('limit', setting('default.list_limit', '25'));
 | 
			
		||||
        $transactions = $this->paginate($transactions->sortByDesc('paid_at'), $limit);
 | 
			
		||||
        $invoices = $this->paginate($invoices->sortByDesc('invoiced_at'), $limit);
 | 
			
		||||
        $invoices = $this->paginate($invoices->sortByDesc('issued_at'), $limit);
 | 
			
		||||
 | 
			
		||||
        return view('sales.customers.show', compact('customer', 'counts', 'amounts', 'transactions', 'invoices'));
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,33 +3,28 @@
 | 
			
		||||
namespace App\Http\Controllers\Sales;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\Controller;
 | 
			
		||||
use App\Exports\Sales\Invoices as Export;
 | 
			
		||||
use App\Exports\Document\Documents as Export;
 | 
			
		||||
use App\Http\Requests\Common\Import as ImportRequest;
 | 
			
		||||
use App\Http\Requests\Sale\Invoice as Request;
 | 
			
		||||
use App\Http\Requests\Sale\InvoiceAddItem as ItemRequest;
 | 
			
		||||
use App\Imports\Sales\Invoices as Import;
 | 
			
		||||
use App\Jobs\Sale\CreateInvoice;
 | 
			
		||||
use App\Jobs\Sale\DeleteInvoice;
 | 
			
		||||
use App\Jobs\Sale\DuplicateInvoice;
 | 
			
		||||
use App\Jobs\Sale\UpdateInvoice;
 | 
			
		||||
use App\Models\Banking\Account;
 | 
			
		||||
use App\Models\Common\Contact;
 | 
			
		||||
use App\Models\Common\Item;
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Models\Setting\Category;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
use App\Models\Setting\Tax;
 | 
			
		||||
use App\Http\Requests\Document\Document as Request;
 | 
			
		||||
use App\Imports\Document\Documents as Import;
 | 
			
		||||
use App\Jobs\Document\CreateDocument;
 | 
			
		||||
use App\Jobs\Document\DeleteDocument;
 | 
			
		||||
use App\Jobs\Document\DuplicateDocument;
 | 
			
		||||
use App\Jobs\Document\UpdateDocument;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use App\Notifications\Sale\Invoice as Notification;
 | 
			
		||||
use App\Traits\Currencies;
 | 
			
		||||
use App\Traits\DateTime;
 | 
			
		||||
use App\Traits\Sales;
 | 
			
		||||
use App\Models\Setting\Currency;
 | 
			
		||||
use App\Traits\Documents;
 | 
			
		||||
use App\Utilities\Modules;
 | 
			
		||||
use File;
 | 
			
		||||
use Illuminate\Support\Facades\URL;
 | 
			
		||||
 | 
			
		||||
class Invoices extends Controller
 | 
			
		||||
{
 | 
			
		||||
    use Currencies, DateTime, Sales;
 | 
			
		||||
    use Documents;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    public $type = Document::INVOICE_TYPE;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Display a listing of the resource.
 | 
			
		||||
@@ -38,7 +33,7 @@ class Invoices extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        $invoices = Invoice::with('contact', 'transactions')->collect(['invoice_number'=> 'desc']);
 | 
			
		||||
        $invoices = Document::invoice()->with('contact', 'transactions')->collect(['document_number'=> 'desc']);
 | 
			
		||||
 | 
			
		||||
        return $this->response('sales.invoices.index', compact('invoices'));
 | 
			
		||||
    }
 | 
			
		||||
@@ -46,30 +41,14 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for viewing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice  $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function show(Invoice $invoice)
 | 
			
		||||
    public function show(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
        $currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray();
 | 
			
		||||
 | 
			
		||||
        $currency = Currency::where('code', $invoice->currency_code)->first();
 | 
			
		||||
 | 
			
		||||
        $account_currency_code = Account::where('id', setting('default.account'))->pluck('currency_code')->first();
 | 
			
		||||
 | 
			
		||||
        $customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
        $categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
        $payment_methods = Modules::getPaymentMethods();
 | 
			
		||||
 | 
			
		||||
        $signed_url = URL::signedRoute('signed.invoices.show', [$invoice->id, 'company_id' => session('company_id')]);
 | 
			
		||||
 | 
			
		||||
        $date_format = $this->getCompanyDateFormat();
 | 
			
		||||
 | 
			
		||||
        // Get Invoice Totals
 | 
			
		||||
        foreach ($invoice->totals_sorted as $invoice_total) {
 | 
			
		||||
            $invoice->{$invoice_total->code} = $invoice_total->amount;
 | 
			
		||||
@@ -83,7 +62,7 @@ class Invoices extends Controller
 | 
			
		||||
            $invoice->grand_total = round($invoice->total - $invoice->paid, $currency->precision);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return view('sales.invoices.show', compact('invoice', 'accounts', 'currencies', 'currency', 'account_currency_code', 'customers', 'categories', 'payment_methods', 'signed_url', 'date_format'));
 | 
			
		||||
        return view('sales.invoices.show', compact('invoice'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -93,21 +72,7 @@ class Invoices extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function create()
 | 
			
		||||
    {
 | 
			
		||||
        $customers = Contact::customer()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
        $currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray();
 | 
			
		||||
 | 
			
		||||
        $currency = Currency::where('code', setting('default.currency'))->first();
 | 
			
		||||
 | 
			
		||||
        $items = Item::enabled()->orderBy('name')->get();
 | 
			
		||||
 | 
			
		||||
        $taxes = Tax::enabled()->orderBy('name')->get();
 | 
			
		||||
 | 
			
		||||
        $categories = Category::income()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
        $number = $this->getNextInvoiceNumber();
 | 
			
		||||
 | 
			
		||||
        return view('sales.invoices.create', compact('customers', 'currencies', 'currency', 'items', 'taxes', 'categories', 'number'));
 | 
			
		||||
        return view('sales.invoices.create');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -119,7 +84,7 @@ class Invoices extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function store(Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateInvoice($request));
 | 
			
		||||
        $response = $this->ajaxDispatch(new CreateDocument($request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['redirect'] = route('invoices.show', $response['data']->id);
 | 
			
		||||
@@ -141,13 +106,13 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Duplicate the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice  $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function duplicate(Invoice $invoice)
 | 
			
		||||
    public function duplicate(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $clone = $this->dispatch(new DuplicateInvoice($invoice));
 | 
			
		||||
        $clone = $this->dispatch(new DuplicateDocument($invoice));
 | 
			
		||||
 | 
			
		||||
        $message = trans('messages.success.duplicated', ['type' => trans_choice('general.invoices', 1)]);
 | 
			
		||||
 | 
			
		||||
@@ -166,7 +131,7 @@ class Invoices extends Controller
 | 
			
		||||
    public function import(ImportRequest $request)
 | 
			
		||||
    {
 | 
			
		||||
        try {
 | 
			
		||||
            \Excel::import(new Import(), $request->file('import'));
 | 
			
		||||
            \Excel::import(new Import(Document::INVOICE_TYPE), $request->file('import'));
 | 
			
		||||
        } catch (\Maatwebsite\Excel\Exceptions\SheetNotFoundException $e) {
 | 
			
		||||
            flash($e->getMessage())->error()->important();
 | 
			
		||||
 | 
			
		||||
@@ -183,38 +148,26 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Show the form for editing the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function edit(Invoice $invoice)
 | 
			
		||||
    public function edit(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $customers = Contact::customer()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
        $currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray();
 | 
			
		||||
 | 
			
		||||
        $currency = Currency::where('code', $invoice->currency_code)->first();
 | 
			
		||||
 | 
			
		||||
        $items = Item::enabled()->orderBy('name')->get();
 | 
			
		||||
 | 
			
		||||
        $taxes = Tax::enabled()->orderBy('name')->get();
 | 
			
		||||
 | 
			
		||||
        $categories = Category::income()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
 | 
			
		||||
 | 
			
		||||
        return view('sales.invoices.edit', compact('invoice', 'customers', 'currencies', 'currency', 'items', 'taxes', 'categories'));
 | 
			
		||||
        return view('sales.invoices.edit', compact('invoice'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the specified resource in storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Request $request
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     * @param  Request  $request
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function update(Invoice $invoice, Request $request)
 | 
			
		||||
    public function update(Document $invoice, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->ajaxDispatch(new UpdateInvoice($invoice, $request));
 | 
			
		||||
        $response = $this->ajaxDispatch(new UpdateDocument($invoice, $request));
 | 
			
		||||
 | 
			
		||||
        if ($response['success']) {
 | 
			
		||||
            $response['redirect'] = route('invoices.show', $response['data']->id);
 | 
			
		||||
@@ -236,13 +189,13 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Remove the specified resource from storage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function destroy(Invoice $invoice)
 | 
			
		||||
    public function destroy(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->ajaxDispatch(new DeleteInvoice($invoice));
 | 
			
		||||
        $response = $this->ajaxDispatch(new DeleteDocument($invoice));
 | 
			
		||||
 | 
			
		||||
        $response['redirect'] = route('invoices.index');
 | 
			
		||||
 | 
			
		||||
@@ -266,19 +219,19 @@ class Invoices extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function export()
 | 
			
		||||
    {
 | 
			
		||||
        return \Excel::download(new Export(), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx');
 | 
			
		||||
        return \Excel::download(new Export(null, Document::INVOICE_TYPE), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark the invoice as sent.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function markSent(Invoice $invoice)
 | 
			
		||||
    public function markSent(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        event(new \App\Events\Sale\InvoiceSent($invoice));
 | 
			
		||||
        event(new \App\Events\Document\DocumentSent($invoice));
 | 
			
		||||
 | 
			
		||||
        $message = trans('invoices.messages.marked_sent');
 | 
			
		||||
 | 
			
		||||
@@ -290,13 +243,13 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark the invoice as cancelled.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function markCancelled(Invoice $invoice)
 | 
			
		||||
    public function markCancelled(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        event(new \App\Events\Sale\InvoiceCancelled($invoice));
 | 
			
		||||
        event(new \App\Events\Document\DocumentCancelled($invoice));
 | 
			
		||||
 | 
			
		||||
        $message = trans('invoices.messages.marked_cancelled');
 | 
			
		||||
 | 
			
		||||
@@ -308,11 +261,11 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Download the PDF file of invoice.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function emailInvoice(Invoice $invoice)
 | 
			
		||||
    public function emailInvoice(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        if (empty($invoice->contact_email)) {
 | 
			
		||||
            return redirect()->back();
 | 
			
		||||
@@ -326,7 +279,7 @@ class Invoices extends Controller
 | 
			
		||||
        $pdf = app('dompdf.wrapper');
 | 
			
		||||
        $pdf->loadHTML($html);
 | 
			
		||||
 | 
			
		||||
        $file_name = $this->getInvoiceFileName($invoice);
 | 
			
		||||
        $file_name = $this->getDocumentFileName($invoice);
 | 
			
		||||
 | 
			
		||||
        $file = storage_path('app/temp/' . $file_name);
 | 
			
		||||
 | 
			
		||||
@@ -346,7 +299,7 @@ class Invoices extends Controller
 | 
			
		||||
        unset($invoice->pdf_path);
 | 
			
		||||
        unset($invoice->reconciled);
 | 
			
		||||
 | 
			
		||||
        event(new \App\Events\Sale\InvoiceSent($invoice));
 | 
			
		||||
        event(new \App\Events\Document\DocumentSent($invoice));
 | 
			
		||||
 | 
			
		||||
        flash(trans('invoices.messages.email_sent'))->success();
 | 
			
		||||
 | 
			
		||||
@@ -356,11 +309,11 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Print the invoice.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function printInvoice(Invoice $invoice)
 | 
			
		||||
    public function printInvoice(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = $this->prepareInvoice($invoice);
 | 
			
		||||
 | 
			
		||||
@@ -372,11 +325,11 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Download the PDF file of invoice.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function pdfInvoice(Invoice $invoice)
 | 
			
		||||
    public function pdfInvoice(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = $this->prepareInvoice($invoice);
 | 
			
		||||
 | 
			
		||||
@@ -390,7 +343,7 @@ class Invoices extends Controller
 | 
			
		||||
 | 
			
		||||
        //$pdf->setPaper('A4', 'portrait');
 | 
			
		||||
 | 
			
		||||
        $file_name = $this->getInvoiceFileName($invoice);
 | 
			
		||||
        $file_name = $this->getDocumentFileName($invoice);
 | 
			
		||||
 | 
			
		||||
        return $pdf->download($file_name);
 | 
			
		||||
    }
 | 
			
		||||
@@ -398,14 +351,14 @@ class Invoices extends Controller
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark the invoice as paid.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  Invoice $invoice
 | 
			
		||||
     * @param  Document $invoice
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function markPaid(Invoice $invoice)
 | 
			
		||||
    public function markPaid(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        try {
 | 
			
		||||
            event(new \App\Events\Sale\PaymentReceived($invoice));
 | 
			
		||||
            event(new \App\Events\Document\PaymentReceived($invoice));
 | 
			
		||||
 | 
			
		||||
            $message = trans('invoices.messages.marked_paid');
 | 
			
		||||
 | 
			
		||||
@@ -419,38 +372,7 @@ class Invoices extends Controller
 | 
			
		||||
        return redirect()->back();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function addItem(ItemRequest $request)
 | 
			
		||||
    {
 | 
			
		||||
        $item_row = $request['item_row'];
 | 
			
		||||
        $currency_code = $request['currency_code'];
 | 
			
		||||
 | 
			
		||||
        $taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
 | 
			
		||||
 | 
			
		||||
        $currency = Currency::where('code', $currency_code)->first();
 | 
			
		||||
 | 
			
		||||
        if (empty($currency)) {
 | 
			
		||||
            $currency = Currency::where('code', setting('default.currency'))->first();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($currency) {
 | 
			
		||||
            // it should be integer for amount mask
 | 
			
		||||
            $currency->precision = (int) $currency->precision;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $html = view('sales.invoices.item', compact('item_row', 'taxes', 'currency'))->render();
 | 
			
		||||
 | 
			
		||||
        return response()->json([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'error'   => false,
 | 
			
		||||
            'data'    => [
 | 
			
		||||
                'currency' => $currency
 | 
			
		||||
            ],
 | 
			
		||||
            'message' => 'null',
 | 
			
		||||
            'html'    => $html,
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function prepareInvoice(Invoice $invoice)
 | 
			
		||||
    protected function prepareInvoice(Document $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $paid = 0;
 | 
			
		||||
 | 
			
		||||
@@ -468,9 +390,9 @@ class Invoices extends Controller
 | 
			
		||||
 | 
			
		||||
        $invoice->paid = $paid;
 | 
			
		||||
 | 
			
		||||
        $invoice->template_path = 'sales.invoices.print_' . setting('invoice.template' ,'default');
 | 
			
		||||
        $invoice->template_path = 'sales.invoices.print_' . setting('invoice.template');
 | 
			
		||||
 | 
			
		||||
        event(new \App\Events\Sale\InvoicePrinting($invoice));
 | 
			
		||||
        event(new \App\Events\Document\DocumentPrinting($invoice));
 | 
			
		||||
 | 
			
		||||
        return $invoice;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ class DateFormat
 | 
			
		||||
    public function handle($request, Closure $next)
 | 
			
		||||
    {
 | 
			
		||||
        if (($request->method() == 'POST') || ($request->method() == 'PATCH')) {
 | 
			
		||||
            $fields = ['paid_at', 'due_at', 'billed_at', 'invoiced_at', 'started_at', 'ended_at'];
 | 
			
		||||
            $fields = ['paid_at', 'due_at', 'issued_at', 'started_at', 'ended_at'];
 | 
			
		||||
 | 
			
		||||
            foreach ($fields as $field) {
 | 
			
		||||
                $date = $request->get($field);
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,7 @@ class Money
 | 
			
		||||
    {
 | 
			
		||||
        if ($request->method() == 'POST' || $request->method() == 'PATCH') {
 | 
			
		||||
            $amount = $request->get('amount');
 | 
			
		||||
            $bill_number = $request->get('bill_number');
 | 
			
		||||
            $invoice_number = $request->get('invoice_number');
 | 
			
		||||
            $document_number = $request->get('document_number');
 | 
			
		||||
            $sale_price = $request->get('sale_price');
 | 
			
		||||
            $purchase_price = $request->get('purchase_price');
 | 
			
		||||
            $opening_balance = $request->get('opening_balance');
 | 
			
		||||
@@ -30,7 +29,7 @@ class Money
 | 
			
		||||
                $request->request->set('amount', $amount);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (isset($bill_number) || isset($invoice_number) || !empty($items)) {
 | 
			
		||||
            if (isset($document_number) || !empty($items)) {
 | 
			
		||||
                if (!empty($items)) {
 | 
			
		||||
                    foreach ($items as $key => $item) {
 | 
			
		||||
                        if (!isset($item['price'])) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Middleware;
 | 
			
		||||
 | 
			
		||||
use App\Models\Sale\Invoice;
 | 
			
		||||
use App\Models\Document\Document;
 | 
			
		||||
use Closure;
 | 
			
		||||
 | 
			
		||||
class RedirectSignedIfAuthenticated
 | 
			
		||||
@@ -27,7 +27,7 @@ class RedirectSignedIfAuthenticated
 | 
			
		||||
        if ($request->segment(2) == 'invoices') {
 | 
			
		||||
            $page = 'invoices.show';
 | 
			
		||||
 | 
			
		||||
            $invoice = Invoice::find($request->segment(3));
 | 
			
		||||
            $invoice = Document::find($request->segment(3));
 | 
			
		||||
 | 
			
		||||
            $params = [$invoice->id];
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,13 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Sale;
 | 
			
		||||
namespace App\Http\Requests\Document;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
use Date;
 | 
			
		||||
use App\Models\Document\Document as Model;
 | 
			
		||||
use App\Utilities\Date;
 | 
			
		||||
use Illuminate\Support\Str;
 | 
			
		||||
 | 
			
		||||
class Invoice extends FormRequest
 | 
			
		||||
class Document extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
@@ -24,9 +26,13 @@ class Invoice extends FormRequest
 | 
			
		||||
     */
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        $type = $this->request->get('type', Model::INVOICE_TYPE);
 | 
			
		||||
 | 
			
		||||
        $type = Str::replaceFirst('-', '_', $type);
 | 
			
		||||
 | 
			
		||||
        // Check if store or update
 | 
			
		||||
        if ($this->getMethod() == 'PATCH') {
 | 
			
		||||
            $id = is_numeric($this->invoice) ? $this->invoice : $this->invoice->getAttribute('id');
 | 
			
		||||
            $id = is_numeric($this->$type) ? $this->$type : $this->{$type}->getAttribute('id');
 | 
			
		||||
        } else {
 | 
			
		||||
            $id = null;
 | 
			
		||||
        }
 | 
			
		||||
@@ -41,15 +47,15 @@ class Invoice extends FormRequest
 | 
			
		||||
        $company_id = $this->request->get('company_id');
 | 
			
		||||
 | 
			
		||||
        return [
 | 
			
		||||
            'invoice_number' => 'required|string|unique:invoices,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
 | 
			
		||||
            'type' => 'required|string',
 | 
			
		||||
            'document_number' => 'required|string|unique:documents,NULL,' . $id . ',id,type,' . $type . ',company_id,' . $company_id . ',deleted_at,NULL',
 | 
			
		||||
            'status' => 'required|string',
 | 
			
		||||
            'invoiced_at' => 'required|date_format:Y-m-d H:i:s',
 | 
			
		||||
            'issued_at' => 'required|date_format:Y-m-d H:i:s',
 | 
			
		||||
            'due_at' => 'required|date_format:Y-m-d H:i:s',
 | 
			
		||||
            'amount' => 'required',
 | 
			
		||||
            'items.*.name' => 'required|string',
 | 
			
		||||
            'items.*.quantity' => 'required',
 | 
			
		||||
            'items.*.price' => 'required|amount',
 | 
			
		||||
            'items.*.currency' => 'required|string|currency',
 | 
			
		||||
            'currency_code' => 'required|string|currency',
 | 
			
		||||
            'currency_rate' => 'required',
 | 
			
		||||
            'contact_id' => 'required|integer',
 | 
			
		||||
@@ -63,10 +69,10 @@ class Invoice extends FormRequest
 | 
			
		||||
    {
 | 
			
		||||
        if ($validator->errors()->count()) {
 | 
			
		||||
            // Set date
 | 
			
		||||
            $invoiced_at = Date::parse($this->request->get('invoiced_at'))->format('Y-m-d');
 | 
			
		||||
            $issued_at = Date::parse($this->request->get('issued_at'))->format('Y-m-d');
 | 
			
		||||
            $due_at = Date::parse($this->request->get('due_at'))->format('Y-m-d');
 | 
			
		||||
 | 
			
		||||
            $this->request->set('invoiced_at', $invoiced_at);
 | 
			
		||||
            $this->request->set('issued_at', $issued_at);
 | 
			
		||||
            $this->request->set('due_at', $due_at);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Purchase;
 | 
			
		||||
namespace App\Http\Requests\Document;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class BillAddItem extends FormRequest
 | 
			
		||||
class DocumentAddItem extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Sale;
 | 
			
		||||
namespace App\Http\Requests\Document;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class InvoiceHistory extends FormRequest
 | 
			
		||||
class DocumentHistory extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
@@ -24,7 +24,8 @@ class InvoiceHistory extends FormRequest
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'invoice_id' => 'required|integer',
 | 
			
		||||
            'type' => 'required|string',
 | 
			
		||||
            'document_id' => 'required|integer',
 | 
			
		||||
            'status' => 'required|string',
 | 
			
		||||
            'notify' => 'required|integer',
 | 
			
		||||
        ];
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Sale;
 | 
			
		||||
namespace App\Http\Requests\Document;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class InvoiceItem extends FormRequest
 | 
			
		||||
class DocumentItem extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
@@ -24,7 +24,8 @@ class InvoiceItem extends FormRequest
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'invoice_id' => 'required|integer',
 | 
			
		||||
            'type' => 'required|string',
 | 
			
		||||
            'document_id' => 'required|integer',
 | 
			
		||||
            'name' => 'required|string',
 | 
			
		||||
            'quantity' => 'required|integer',
 | 
			
		||||
            'price' => 'required',
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Sale;
 | 
			
		||||
namespace App\Http\Requests\Document;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class InvoiceItemTax extends FormRequest
 | 
			
		||||
class DocumentItemTax extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
@@ -24,8 +24,9 @@ class InvoiceItemTax extends FormRequest
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'invoice_id' => 'required|integer',
 | 
			
		||||
            'invoice_item_id' => 'required|integer',
 | 
			
		||||
            'type' => 'required|string',
 | 
			
		||||
            'document_id' => 'required|integer',
 | 
			
		||||
            'document_item_id' => 'required|integer',
 | 
			
		||||
            'tax_id' => 'required|integer',
 | 
			
		||||
            'name' => 'required|string',
 | 
			
		||||
            'amount' => 'required',
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Purchase;
 | 
			
		||||
namespace App\Http\Requests\Document;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class BillTotal extends FormRequest
 | 
			
		||||
class DocumentTotal extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
@@ -24,7 +24,8 @@ class BillTotal extends FormRequest
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'bill_id' => 'required|integer',
 | 
			
		||||
            'type' => 'required|string',
 | 
			
		||||
            'document_id' => 'required|integer',
 | 
			
		||||
            'name' => 'required|string',
 | 
			
		||||
            'amount' => 'required|amount',
 | 
			
		||||
            'sort_order' => 'required|integer',
 | 
			
		||||
@@ -1,84 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Purchase;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
use Date;
 | 
			
		||||
 | 
			
		||||
class Bill extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize()
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the validation rules that apply to the request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        // Check if store or update
 | 
			
		||||
        if ($this->getMethod() == 'PATCH') {
 | 
			
		||||
            $id = is_numeric($this->bill) ? $this->bill : $this->bill->getAttribute('id');
 | 
			
		||||
        } else {
 | 
			
		||||
            $id = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $attachment = 'nullable';
 | 
			
		||||
 | 
			
		||||
        if ($this->request->get('attachment', null)) {
 | 
			
		||||
            $attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Get company id
 | 
			
		||||
        $company_id = $this->request->get('company_id');
 | 
			
		||||
 | 
			
		||||
        return [
 | 
			
		||||
            'bill_number' => 'required|string|unique:bills,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
 | 
			
		||||
            'status' => 'required|string',
 | 
			
		||||
            'billed_at' => 'required|date_format:Y-m-d H:i:s',
 | 
			
		||||
            'due_at' => 'required|date_format:Y-m-d H:i:s',
 | 
			
		||||
            'amount' => 'required',
 | 
			
		||||
            'items.*.name' => 'required|string',
 | 
			
		||||
            'items.*.quantity' => 'required',
 | 
			
		||||
            'items.*.price' => 'required|amount',
 | 
			
		||||
            'items.*.currency' => 'required|string|currency',
 | 
			
		||||
            'currency_code' => 'required|string|currency',
 | 
			
		||||
            'currency_rate' => 'required',
 | 
			
		||||
            'contact_id' => 'required|integer',
 | 
			
		||||
            'contact_name' => 'required|string',
 | 
			
		||||
            'category_id' => 'required|integer',
 | 
			
		||||
            'attachment' => $attachment,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function withValidator($validator)
 | 
			
		||||
    {
 | 
			
		||||
        if ($validator->errors()->count()) {
 | 
			
		||||
            // Set date
 | 
			
		||||
            $billed_at = Date::parse($this->request->get('billed_at'))->format('Y-m-d');
 | 
			
		||||
            $due_at = Date::parse($this->request->get('due_at'))->format('Y-m-d');
 | 
			
		||||
 | 
			
		||||
            $this->request->set('billed_at', $billed_at);
 | 
			
		||||
            $this->request->set('due_at', $due_at);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function messages()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'items.*.name.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('general.name'))]),
 | 
			
		||||
            'items.*.quantity.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('bills.quantity'))]),
 | 
			
		||||
            'items.*.price.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('bills.price'))]),
 | 
			
		||||
            'items.*.currency.required' => trans('validation.custom.invalid_currency'),
 | 
			
		||||
            'items.*.currency.string' => trans('validation.custom.invalid_currency'),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,32 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Purchase;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class BillHistory extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize()
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the validation rules that apply to the request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'bill_id' => 'required|integer',
 | 
			
		||||
            'status' => 'required|string',
 | 
			
		||||
            'notify' => 'required|integer',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Purchase;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class BillItem extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize()
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the validation rules that apply to the request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'bill_id' => 'required|integer',
 | 
			
		||||
            'name' => 'required|string',
 | 
			
		||||
            'quantity' => 'required|integer',
 | 
			
		||||
            'price' => 'required',
 | 
			
		||||
            'total' => 'required',
 | 
			
		||||
            'tax' => 'required',
 | 
			
		||||
            'tax_id' => 'required',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,34 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Purchase;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class BillItemTax extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize()
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the validation rules that apply to the request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'bill_id' => 'required|integer',
 | 
			
		||||
            'bill_item_id' => 'required|integer',
 | 
			
		||||
            'tax_id' => 'required|integer',
 | 
			
		||||
            'name' => 'required|string',
 | 
			
		||||
            'amount' => 'required',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,31 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Sale;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class InvoiceAddItem extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize()
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the validation rules that apply to the request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'item_row' => 'required|integer',
 | 
			
		||||
            'currency_code' => 'required|string|currency',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,33 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\Sale;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class InvoiceTotal extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize()
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the validation rules that apply to the request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function rules()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'invoice_id' => 'required|integer',
 | 
			
		||||
            'name' => 'required|string',
 | 
			
		||||
            'amount' => 'required|amount',
 | 
			
		||||
            'sort_order' => 'required|integer',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										31
									
								
								app/Http/ViewComposers/DocumentType.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								app/Http/ViewComposers/DocumentType.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Http\ViewComposers;
 | 
			
		||||
 | 
			
		||||
use App\Http\Controllers\Portal\Invoices as PortalInvoices;
 | 
			
		||||
use App\Http\Controllers\Purchases\Bills;
 | 
			
		||||
use App\Http\Controllers\Sales\Invoices;
 | 
			
		||||
use Illuminate\View\View;
 | 
			
		||||
 | 
			
		||||
class DocumentType
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Bind data to the view.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  View  $view
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function compose(View $view)
 | 
			
		||||
    {
 | 
			
		||||
        if (!empty(request()->route())) {
 | 
			
		||||
            $route = request()->route();
 | 
			
		||||
 | 
			
		||||
            /** @var Invoices|Bills|PortalInvoices $controller */
 | 
			
		||||
            $controller = $route->getController();
 | 
			
		||||
 | 
			
		||||
            $view->with(['type' => $controller->type ?? '']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -20,19 +20,19 @@ class InvoiceText
 | 
			
		||||
        $text_items = setting('invoice.item_name', 'general.items');
 | 
			
		||||
 | 
			
		||||
        if ($text_items == 'custom') {
 | 
			
		||||
            $text_items = setting('invoice.item_input');
 | 
			
		||||
            $text_items = setting('invoice.item_name_input');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $text_quantity = setting('invoice.quantity_name', 'invoices.quantity');
 | 
			
		||||
 | 
			
		||||
        if ($text_quantity == 'custom') {
 | 
			
		||||
            $text_quantity = setting('invoice.quantity_input');
 | 
			
		||||
            $text_quantity = setting('invoice.quantity_name_input');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $text_price = setting('invoice.price_name', 'invoices.price');
 | 
			
		||||
 | 
			
		||||
        if ($text_price == 'custom') {
 | 
			
		||||
            $text_price = setting('invoice.price_input');
 | 
			
		||||
            $text_price = setting('invoice.price_name_input');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $text_override['items'] = $text_items;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user