mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
commit
c22a3c2386
@ -55,7 +55,7 @@ class RecurringExpenseToExpenseFactory
|
||||
$expense->custom_value2 = $recurring_expense->custom_value2;
|
||||
$expense->custom_value3 = $recurring_expense->custom_value3;
|
||||
$expense->custom_value4 = $recurring_expense->custom_value4;
|
||||
$expense->transaction_id = $recurring_expense->transaction_id;
|
||||
$expense->transaction_id = null;
|
||||
$expense->category_id = $recurring_expense->category_id;
|
||||
$expense->payment_type_id = $recurring_expense->payment_type_id;
|
||||
$expense->project_id = $recurring_expense->project_id;
|
||||
|
@ -289,7 +289,6 @@ abstract class QueryFilters
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function without_deleted_clients(): Builder
|
||||
{
|
||||
@ -302,7 +301,6 @@ abstract class QueryFilters
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function without_deleted_vendors(): Builder
|
||||
{
|
||||
|
@ -44,9 +44,9 @@ class UpdateBankTransactionRequest extends Request
|
||||
$rules['vendor_id'] = 'bail|required|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
}
|
||||
|
||||
if (isset($this->expense_id)) {
|
||||
$rules['expense_id'] = 'bail|required|exists:expenses,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
}
|
||||
// if (isset($this->expense_id)) {
|
||||
// $rules['expense_id'] = 'bail|required|exists:expenses,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
// }
|
||||
|
||||
$rules['bank_integration_id'] = 'bail|required|exists:bank_integrations,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
|
||||
@ -67,9 +67,9 @@ class UpdateBankTransactionRequest extends Request
|
||||
$input['vendor_id'] = $this->decodePrimaryKey($input['vendor_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('expense_id', $input) && strlen($input['expense_id']) > 1) {
|
||||
$input['expense_id'] = $this->decodePrimaryKey($input['expense_id']);
|
||||
}
|
||||
// if (array_key_exists('expense_id', $input) && strlen($input['expense_id']) > 1) {
|
||||
// $input['expense_id'] = $this->decodePrimaryKey($input['expense_id']);
|
||||
// }
|
||||
|
||||
if (array_key_exists('ninja_category_id', $input) && strlen($input['ninja_category_id']) > 1) {
|
||||
$input['ninja_category_id'] = $this->decodePrimaryKey($input['ninja_category_id']);
|
||||
|
@ -148,7 +148,7 @@ class MatchBankTransactions implements ShouldQueue
|
||||
|
||||
private function linkExpense($input)
|
||||
{
|
||||
$this->bt = BankTransaction::find($input['id']);
|
||||
$this->bt = BankTransaction::withTrashed()->find($input['id']);
|
||||
|
||||
if (!$this->bt) {
|
||||
return $this;
|
||||
@ -243,7 +243,7 @@ class MatchBankTransactions implements ShouldQueue
|
||||
private function matchExpense($input) :self
|
||||
{
|
||||
//if there is a category id, pull it from Yodlee and insert - or just reuse!!
|
||||
$this->bt = BankTransaction::withTrashed()->find($input['id']);
|
||||
$this->bt = BankTransaction::find($input['id']);
|
||||
|
||||
if (!$this->bt || $this->bt->status_id == BankTransaction::STATUS_CONVERTED) {
|
||||
return $this;
|
||||
|
@ -111,7 +111,7 @@ class RecurringExpensesCron
|
||||
|
||||
$recurring_expense->next_send_date = $recurring_expense->nextSendDate();
|
||||
$recurring_expense->next_send_date_client = $recurring_expense->next_send_date;
|
||||
|
||||
$recurring_expense->last_sent_date = now();
|
||||
$recurring_expense->remaining_cycles = $recurring_expense->remainingCycles();
|
||||
$recurring_expense->save();
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ class Activity extends StaticModel
|
||||
];
|
||||
|
||||
|
||||
public function getHashedIdAttribute()
|
||||
public function getHashedIdAttribute(): string
|
||||
{
|
||||
return $this->encodePrimaryKey($this->id);
|
||||
}
|
||||
@ -285,109 +285,95 @@ class Activity extends StaticModel
|
||||
return self::class;
|
||||
}
|
||||
|
||||
|
||||
public function backup()
|
||||
public function backup(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Backup::class);
|
||||
}
|
||||
|
||||
|
||||
public function history()
|
||||
public function history(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Backup::class);
|
||||
}
|
||||
|
||||
public function user() :BelongsTo
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function contact()
|
||||
public function contact(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ClientContact::class, 'client_contact_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function client()
|
||||
public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function invoice()
|
||||
public function invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Invoice::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function vendor()
|
||||
public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vendor::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function recurring_invoice()
|
||||
public function recurring_invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RecurringInvoice::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function credit()
|
||||
public function credit(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Credit::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function quote()
|
||||
public function quote(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Quote::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function subscription()
|
||||
public function subscription(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Subscription::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function payment()
|
||||
public function payment(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Payment::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function expense()
|
||||
public function expense(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Expense::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function recurring_expense()
|
||||
public function recurring_expense(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RecurringExpense::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function purchase_order()
|
||||
public function purchase_order(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PurchaseOrder::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function vendor_contact()
|
||||
public function vendor_contact(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(VendorContact::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function task()
|
||||
public function task(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Task::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function company()
|
||||
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction onlyTrashed()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
|
||||
* @method static \Illuminate\Database\Eloquent\Account withTrashed()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction withoutTrashed()
|
||||
* @property-read \App\Models\Payment|null $payment
|
||||
* @mixin \Eloquent
|
||||
@ -137,12 +136,12 @@ class BankTransaction extends BaseModel
|
||||
|
||||
public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vendor::class);
|
||||
return $this->belongsTo(Vendor::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function expense(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Expense::class);
|
||||
return $this->belongsTo(Expense::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
|
@ -57,11 +57,11 @@ use Laracasts\Presenter\PresentableTrait;
|
||||
* @property string|null $private_notes
|
||||
* @property string|null $terms
|
||||
* @property string|null $tax_name1
|
||||
* @property string $tax_rate1
|
||||
* @property float $tax_rate1
|
||||
* @property string|null $tax_name2
|
||||
* @property string $tax_rate2
|
||||
* @property float $tax_rate2
|
||||
* @property string|null $tax_name3
|
||||
* @property string $tax_rate3
|
||||
* @property float $tax_rate3
|
||||
* @property string $total_taxes
|
||||
* @property int $uses_inclusive_taxes
|
||||
* @property string|null $custom_value1
|
||||
@ -90,7 +90,7 @@ use Laracasts\Presenter\PresentableTrait;
|
||||
* @property string|null $reminder2_sent
|
||||
* @property string|null $reminder3_sent
|
||||
* @property string|null $reminder_last_sent
|
||||
* @property string $paid_to_date
|
||||
* @property float $paid_to_date
|
||||
* @property int|null $subscription_id
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
|
||||
* @property-read int|null $activities_count
|
||||
|
@ -11,20 +11,23 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Jobs\Bank\MatchBankTransactions;
|
||||
use App\Models\Expense;
|
||||
use App\Models\BankTransaction;
|
||||
use App\Jobs\Bank\MatchBankTransactions;
|
||||
|
||||
/**
|
||||
* Class for bank transaction repository.
|
||||
*/
|
||||
class BankTransactionRepository extends BaseRepository
|
||||
{
|
||||
|
||||
public function save($data, BankTransaction $bank_transaction)
|
||||
{
|
||||
if (array_key_exists('bank_integration_id', $data)) {
|
||||
$bank_transaction->bank_integration_id = $data['bank_integration_id'];
|
||||
}
|
||||
|
||||
|
||||
$bank_transaction->fill($data);
|
||||
$bank_transaction->save();
|
||||
|
||||
@ -49,11 +52,16 @@ class BankTransactionRepository extends BaseRepository
|
||||
$bt->payment_id = null;
|
||||
}
|
||||
|
||||
if($bt->expense()->exists()) {
|
||||
$bt->expense->transaction_id = null;
|
||||
$bt->expense_id = null;
|
||||
}
|
||||
$e = Expense::whereIn('id', $this->transformKeys(explode(",", $bt->expense_id)))
|
||||
->cursor()
|
||||
->each(function ($expense){
|
||||
|
||||
$expense->transaction_id = null;
|
||||
$expense->saveQuietly();
|
||||
|
||||
});
|
||||
|
||||
$bt->expense_id = null;
|
||||
$bt->vendor_id = null;
|
||||
$bt->status_id = 1;
|
||||
$bt->invoice_ids = null;
|
||||
|
@ -146,6 +146,8 @@ class PaymentMigrationRepository extends BaseRepository
|
||||
}
|
||||
|
||||
if (array_key_exists('credits', $data) && is_array($data['credits']) && count($data['credits']) > 0) {
|
||||
|
||||
/** @var float $credit_totals **/
|
||||
$credit_totals = array_sum(array_column($data['credits'], 'amount'));
|
||||
|
||||
$credits = Credit::whereIn('id', array_column($data['credits'], 'credit_id'))->withTrashed()->get();
|
||||
|
@ -188,7 +188,7 @@ class PaymentRepository extends BaseRepository
|
||||
$paymentable->save();
|
||||
|
||||
$credit = $credit->service()->markSent()->save();
|
||||
(new ApplyCreditPayment($credit, $payment, $paid_credit['amount'], $credit->company))->handle();
|
||||
(new ApplyCreditPayment($credit, $payment, $paid_credit['amount']))->handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ class SubscriptionRepository extends BaseRepository
|
||||
DB::connection(config('database.default'))->beginTransaction();
|
||||
$data = [];
|
||||
|
||||
/** @var \App\Models\Client $client **/
|
||||
$client = Client::factory()->create([
|
||||
'user_id' => $subscription->user_id,
|
||||
'company_id' => $subscription->company_id,
|
||||
@ -56,6 +57,7 @@ class SubscriptionRepository extends BaseRepository
|
||||
'settings' => ClientSettings::defaults(),
|
||||
]);
|
||||
|
||||
/** @var \App\Models\ClientContact $contact **/
|
||||
$contact = ClientContact::factory()->create([
|
||||
'user_id' => $subscription->user_id,
|
||||
'company_id' => $subscription->company_id,
|
||||
|
@ -148,13 +148,16 @@ class TaskRepository extends BaseRepository
|
||||
* Store tasks in bulk.
|
||||
*
|
||||
* @param array $task
|
||||
* @return task|null
|
||||
* @return Task|null
|
||||
*/
|
||||
public function create($task): ?Task
|
||||
{
|
||||
/** @var \App\Models\User $user **/
|
||||
$user = auth()->user();
|
||||
|
||||
return $this->save(
|
||||
$task,
|
||||
TaskFactory::create(auth()->user()->company()->id, auth()->user()->id)
|
||||
TaskFactory::create($user->company()->id, $user->id)
|
||||
);
|
||||
}
|
||||
|
||||
@ -175,7 +178,7 @@ class TaskRepository extends BaseRepository
|
||||
/**
|
||||
* Sorts the task status order IF the old status has changed between requests
|
||||
*
|
||||
* @param stdCLass $old_task The old task object
|
||||
* @param \stdCLass $old_task The old task object
|
||||
* @param Task $new_task The new Task model
|
||||
* @return void
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ class TaskStatusRepository extends BaseRepository
|
||||
{
|
||||
public function delete($task_status)
|
||||
{
|
||||
/** @var \App\Models\TaskStatus $ts **/
|
||||
$ts = TaskStatus::where('company_id', $task_status->company_id)
|
||||
->first();
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Expense;
|
||||
use Tests\MockAccountData;
|
||||
use App\Models\BankIntegration;
|
||||
use App\Models\BankTransaction;
|
||||
@ -122,19 +123,31 @@ class BankTransactionApiTest extends TestCase
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$e = Expense::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$bank_transaction = BankTransaction::factory()->create([
|
||||
'bank_integration_id' => $bi->id,
|
||||
'user_id' => $this->user->id,
|
||||
'company_id' => $this->company->id,
|
||||
'payment_id' => $this->payment->id,
|
||||
'expense_id' => $this->expense->id,
|
||||
'expense_id' => "{$this->expense->hashed_id},{$e->hashed_id}",
|
||||
'invoice_ids' => $this->invoice->hashed_id,
|
||||
]);
|
||||
|
||||
$e->transaction_id = $bank_transaction->id;
|
||||
$e->save();
|
||||
|
||||
$this->expense->transaction_id = $bank_transaction->id;
|
||||
$this->expense->save();
|
||||
|
||||
$data = [
|
||||
'ids' => [$this->encodePrimaryKey($bank_transaction->id)],
|
||||
];
|
||||
|
||||
nlog($bank_transaction->toArray());
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
@ -146,6 +159,9 @@ class BankTransactionApiTest extends TestCase
|
||||
$this->assertEquals("", $arr['data'][0]['payment_id']);
|
||||
$this->assertEquals("", $arr['data'][0]['invoice_ids']);
|
||||
$this->assertEquals("", $arr['data'][0]['expense_id']);
|
||||
|
||||
$this->assertNull($e->fresh()->transaction_id);
|
||||
$this->assertNull($this->expense->fresh()->transaction_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user