Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Helpers/AccountUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function defaultdata($company_id = null)

private static function createAccountCategories($company_id)
{
$exist = AccountCategory::where('created_by', $company_id)->first();
$exist = AccountCategory::withoutGlobalScope('tenant')->where('created_by', $company_id)->first();
if($exist) return;

$categories = [
Expand All @@ -40,10 +40,10 @@ private static function createAccountCategories($company_id)

private static function createAccountTypes($company_id)
{
$exist = AccountType::where('created_by', $company_id)->first();
$exist = AccountType::withoutGlobalScope('tenant')->where('created_by', $company_id)->first();
if($exist) return;

$categories = AccountCategory::where('created_by', $company_id)->get()->keyBy('code');
$categories = AccountCategory::withoutGlobalScope('tenant')->where('created_by', $company_id)->get()->keyBy('code');
if(count($categories) == 0) return;

$accountTypes = [
Expand Down Expand Up @@ -80,10 +80,10 @@ private static function createAccountTypes($company_id)

private static function createChartOfAccounts($company_id)
{
$exist = ChartOfAccount::where('created_by', $company_id)->first();
$exist = ChartOfAccount::withoutGlobalScope('tenant')->where('created_by', $company_id)->first();
if($exist) return;

$accountTypes = AccountType::where('created_by', $company_id)->get()->keyBy('code');
$accountTypes = AccountType::withoutGlobalScope('tenant')->where('created_by', $company_id)->get()->keyBy('code');
if(count($accountTypes) == 0) return;

$chartOfAccounts = [
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/CustomerPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function updateStatus(Request $request, CustomerPayment $customerPayment)
$creditNoteApplication = CreditNoteApplication::where('payment_id', $customerPayment->id)->get();

foreach ($creditNoteApplication as $creditNote) {
$creditNoteModel = CreditNote::find($creditNote['credit_note_id']);
$creditNoteModel = CreditNote::findOrFail($creditNote['credit_note_id']);
$creditNoteModel->applied_amount += $creditNote['applied_amount'];
$creditNoteModel->balance_amount = $creditNoteModel->total_amount - $creditNoteModel->applied_amount;
$creditNoteModel->status = $creditNoteModel->balance_amount <= 0 ? 'applied' : 'partial';
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/VendorPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function updateStatus(Request $request, VendorPayment $vendorPayment)
$debitNoteApplication = DebitNoteApplication::where('payment_id', $vendorPayment->id)->get();

foreach ($debitNoteApplication as $debitNote) {
$debitNoteModel = DebitNote::find($debitNote['debit_note_id']);
$debitNoteModel = DebitNote::findOrFail($debitNote['debit_note_id']);
$debitNoteModel->applied_amount += $debitNote['applied_amount'];
$debitNoteModel->balance_amount = $debitNoteModel->total_amount - $debitNoteModel->applied_amount;
$debitNoteModel->status = $debitNoteModel->balance_amount <= 0 ? 'applied' : 'partial';
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/StoreAccountTypeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function authorize(): bool
public function rules(): array
{
return [
'category_id' => 'required|exists:account_categories,id',
'category_id' => 'required|exists:account_categories,id,created_by,' . creatorId(),
'name' => 'required|max:100|unique:account_types,name,NULL,id,created_by,' . creatorId(),
'code' => 'required|max:10|unique:account_types,code,NULL,id,created_by,' . creatorId(),
'normal_balance' => 'required',
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/StoreBankAccountRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function rules(): array
'swift_code' => 'nullable|string|max:11',
'routing_number' => 'nullable|string|max:20',
'is_active' => 'boolean',
'gl_account_id' => 'required|exists:chart_of_accounts,id'
'gl_account_id' => 'required|exists:chart_of_accounts,id,created_by,' . creatorId()
];
}
}
4 changes: 2 additions & 2 deletions src/Http/Requests/StoreBankTransferRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function rules()
{
return [
'transfer_date' => 'required|date',
'from_account_id' => 'required|exists:bank_accounts,id',
'to_account_id' => 'required|exists:bank_accounts,id|different:from_account_id',
'from_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId(),
'to_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId() . '|different:from_account_id',
'transfer_amount' => 'required|numeric|min:0.01',
'transfer_charges' => 'nullable|numeric|min:0',
'reference_number' => 'nullable|string|max:255',
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Requests/StoreChartOfAccountRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function rules(): array
'current_balance' => 'nullable|numeric|min:0',
'is_active' => 'boolean',
'description' => 'nullable|string|max:1000',
'account_type_id' => 'nullable|exists:account_types,id',
'parent_account_id' => 'nullable|exists:chart_of_accounts,id'
'account_type_id' => 'nullable|exists:account_types,id,created_by,' . creatorId(),
'parent_account_id' => 'nullable|exists:chart_of_accounts,id,created_by,' . creatorId()
];
}
}
6 changes: 3 additions & 3 deletions src/Http/Requests/StoreCustomerPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public function rules()
return [
'payment_date' => 'required|date|before_or_equal:today',
'customer_id' => 'required|exists:users,id',
'bank_account_id' => 'required|exists:bank_accounts,id',
'bank_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId(),
'reference_number' => 'nullable|string|max:100',
'payment_amount' => 'required|numeric|min:0',
'notes' => 'nullable|string',
'allocations' => 'nullable|array',
'allocations.*.invoice_id' => 'required|exists:sales_invoices,id',
'allocations.*.invoice_id' => 'required|exists:sales_invoices,id,created_by,' . creatorId(),
'allocations.*.amount' => 'required|numeric|min:0.01',
'credit_notes' => 'nullable|array',
'credit_notes.*.credit_note_id' => 'required|exists:credit_notes,id',
'credit_notes.*.credit_note_id' => 'required|exists:credit_notes,id,created_by,' . creatorId(),
'credit_notes.*.amount' => 'required|numeric|min:0.01'
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/StoreExpenseCategoriesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function rules(): array
return [
'category_name' => 'required',
'category_code' => 'required|unique:expense_categories,category_code',
'gl_account_id' => 'nullable|exists:chart_of_accounts,id',
'gl_account_id' => 'nullable|exists:chart_of_accounts,id,created_by,' . creatorId(),
'description' => 'nullable',
'is_active' => 'boolean'
];
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Requests/StoreExpenseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function rules(): array
{
return [
'expense_date' => 'required|date',
'category_id' => 'required|exists:expense_categories,id',
'bank_account_id' => 'required|exists:bank_accounts,id',
'chart_of_account_id' => 'required|exists:chart_of_accounts,id',
'category_id' => 'required|exists:expense_categories,id,created_by,' . creatorId(),
'bank_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId(),
'chart_of_account_id' => 'required|exists:chart_of_accounts,id,created_by,' . creatorId(),
'amount' => 'required|numeric|min:0',
'description' => 'nullable|string',
'reference_number' => 'nullable|string|max:255',
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/StoreRevenueCategoriesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function rules(): array
return [
'category_name' => 'required',
'category_code' => 'required|unique:revenue_categories,category_code',
'gl_account_id' => 'nullable|exists:chart_of_accounts,id',
'gl_account_id' => 'nullable|exists:chart_of_accounts,id,created_by,' . creatorId(),
'description' => 'nullable',
'is_active' => 'boolean'
];
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Requests/StoreRevenueRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function rules(): array
{
return [
'revenue_date' => 'required|date',
'category_id' => 'required|exists:revenue_categories,id',
'bank_account_id' => 'required|exists:bank_accounts,id',
'chart_of_account_id' => 'required|exists:chart_of_accounts,id',
'category_id' => 'required|exists:revenue_categories,id,created_by,' . creatorId(),
'bank_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId(),
'chart_of_account_id' => 'required|exists:chart_of_accounts,id,created_by,' . creatorId(),
'amount' => 'required|numeric|min:0',
'description' => 'nullable|string',
'reference_number' => 'nullable|string|max:255',
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Requests/StoreVendorPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public function rules()
return [
'payment_date' => 'required|date|before_or_equal:today',
'vendor_id' => 'required|exists:users,id',
'bank_account_id' => 'required|exists:bank_accounts,id',
'bank_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId(),
'reference_number' => 'nullable|string|max:100',
'payment_amount' => 'required|numeric|min:0',
'notes' => 'nullable|string',
'allocations' => 'nullable|array',
'allocations.*.invoice_id' => 'required|exists:purchase_invoices,id',
'allocations.*.invoice_id' => 'required|exists:purchase_invoices,id,created_by,' . creatorId(),
'allocations.*.amount' => 'required|numeric|min:0.01',
'debit_notes' => 'nullable|array',
'debit_notes.*.debit_note_id' => 'required|exists:debit_notes,id',
'debit_notes.*.debit_note_id' => 'required|exists:debit_notes,id,created_by,' . creatorId(),
'debit_notes.*.amount' => 'required|numeric|min:0.01'
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/UpdateBankAccountRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function rules(): array
'swift_code' => 'nullable|string|max:11',
'routing_number' => 'nullable|string|max:20',
'is_active' => 'boolean',
'gl_account_id' => 'required|exists:chart_of_accounts,id'
'gl_account_id' => 'required|exists:chart_of_accounts,id,created_by,' . creatorId()
];
}
}
4 changes: 2 additions & 2 deletions src/Http/Requests/UpdateBankTransferRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function rules()
{
return [
'transfer_date' => 'required|date',
'from_account_id' => 'required|exists:bank_accounts,id',
'to_account_id' => 'required|exists:bank_accounts,id|different:from_account_id',
'from_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId(),
'to_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId() . '|different:from_account_id',
'transfer_amount' => 'required|numeric|min:0.01',
'transfer_charges' => 'nullable|numeric|min:0',
'reference_number' => 'nullable|string|max:255',
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Requests/UpdateChartOfAccountRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function rules(): array
'current_balance' => 'nullable|numeric|min:0',
'is_active' => 'boolean',
'description' => 'nullable|string|max:1000',
'account_type_id' => 'nullable|exists:account_types,id',
'parent_account_id' => 'nullable|exists:chart_of_accounts,id'
'account_type_id' => 'nullable|exists:account_types,id,created_by,' . creatorId(),
'parent_account_id' => 'nullable|exists:chart_of_accounts,id,created_by,' . creatorId()
];
}
}
2 changes: 1 addition & 1 deletion src/Http/Requests/UpdateExpenseCategoriesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function rules(): array
return [
'category_name' => 'required',
'category_code' => 'required|unique:expense_categories,category_code,' . $this->route('expensecategories')->id,
'gl_account_id' => 'nullable|exists:chart_of_accounts,id',
'gl_account_id' => 'nullable|exists:chart_of_accounts,id,created_by,' . creatorId(),
'description' => 'nullable',
'is_active' => 'boolean'
];
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Requests/UpdateExpenseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function rules(): array
{
return [
'expense_date' => 'required|date',
'category_id' => 'required|exists:expense_categories,id',
'bank_account_id' => 'required|exists:bank_accounts,id',
'chart_of_account_id' => 'required|exists:chart_of_accounts,id',
'category_id' => 'required|exists:expense_categories,id,created_by,' . creatorId(),
'bank_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId(),
'chart_of_account_id' => 'required|exists:chart_of_accounts,id,created_by,' . creatorId(),
'amount' => 'required|numeric|min:0',
'description' => 'nullable|string',
'reference_number' => 'nullable|string|max:255',
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/UpdateRevenueCategoriesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function rules(): array
return [
'category_name' => 'required',
'category_code' => 'required|unique:revenue_categories,category_code,' . $this->route('revenuecategories')->id,
'gl_account_id' => 'nullable|exists:chart_of_accounts,id',
'gl_account_id' => 'nullable|exists:chart_of_accounts,id,created_by,' . creatorId(),
'description' => 'nullable',
'is_active' => 'boolean'
];
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Requests/UpdateRevenueRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function rules(): array
{
return [
'revenue_date' => 'required|date',
'category_id' => 'required|exists:revenue_categories,id',
'bank_account_id' => 'required|exists:bank_accounts,id',
'chart_of_account_id' => 'required|exists:chart_of_accounts,id',
'category_id' => 'required|exists:revenue_categories,id,created_by,' . creatorId(),
'bank_account_id' => 'required|exists:bank_accounts,id,created_by,' . creatorId(),
'chart_of_account_id' => 'required|exists:chart_of_accounts,id,created_by,' . creatorId(),
'amount' => 'required|numeric|min:0',
'description' => 'nullable|string',
'reference_number' => 'nullable|string|max:255',
Expand Down
3 changes: 2 additions & 1 deletion src/Models/AccountCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Zerp\Account\Models;

use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class AccountCategory extends Model
{
use HasFactory;
use HasFactory, TenantScoped;

protected $fillable = [
'name',
Expand Down
3 changes: 2 additions & 1 deletion src/Models/AccountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Zerp\Account\Models;

use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Zerp\Account\Models\AccountCategory;

class AccountType extends Model
{
use HasFactory;
use HasFactory, TenantScoped;

protected $fillable = [
'category_id',
Expand Down
3 changes: 2 additions & 1 deletion src/Models/BankAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Zerp\Account\Models;

use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Zerp\Account\Models\ChartOfAccount;

class BankAccount extends Model
{
use HasFactory;
use HasFactory, TenantScoped;

protected $fillable = [
'account_number',
Expand Down
3 changes: 3 additions & 0 deletions src/Models/BankTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Zerp\Account\Models;

use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\User;

class BankTransaction extends Model
{
use TenantScoped;

protected $fillable = [
'bank_account_id',
'transaction_date',
Expand Down
3 changes: 2 additions & 1 deletion src/Models/BankTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace Zerp\Account\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class BankTransfer extends Model
{
use HasFactory;
use HasFactory, TenantScoped;

protected $fillable = [
'transfer_number',
Expand Down
3 changes: 2 additions & 1 deletion src/Models/ChartOfAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Zerp\Account\Models;

use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Zerp\Account\Models\AccountType;

class ChartOfAccount extends Model
{
use HasFactory;
use HasFactory, TenantScoped;

protected $fillable = [
'account_code',
Expand Down
3 changes: 3 additions & 0 deletions src/Models/CreditNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Zerp\Account\Models;

use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -11,6 +12,8 @@

class CreditNote extends Model
{
use TenantScoped;

protected $fillable = [
'credit_note_number',
'credit_note_date',
Expand Down
3 changes: 3 additions & 0 deletions src/Models/CreditNoteApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Zerp\Account\Models;

use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CreditNoteApplication extends Model
{
use TenantScoped;

protected $fillable = [
'credit_note_id',
'payment_id',
Expand Down
6 changes: 6 additions & 0 deletions src/Models/CreditNoteItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

namespace Zerp\Account\Models;

use App\Models\Concerns\TenantScoped;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CreditNoteItem extends Model
{
use TenantScoped;

/** No created_by column; the parent creditNote carries the tenant boundary. */
public string $tenantParent = 'creditNote';

protected $fillable = [
'credit_note_id',
'product_id',
Expand Down
Loading
Loading