mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
Merge branch 'migration-issue' into 'master'
add calculate base expenses migration See merge request mohit.panjvani/crater-web!1332
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Expense;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CalculateBaseValuesForExpenses extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
if ($user) {
|
||||
$companyId = $user->companies()->first()->id;
|
||||
|
||||
$currency_id = CompanySetting::getSetting('currency', $companyId);
|
||||
|
||||
$expenses = Expense::where('company_id', $companyId)->where('currency_id', null)->get();
|
||||
if ($expenses) {
|
||||
$expenses->map(function ($expense) use ($currency_id) {
|
||||
$expense->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => 1,
|
||||
'base_amount' => $expense->amount,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user