makes model purchase a suggestion on create

This commit is contained in:
Godfrey M 2024-08-13 12:33:48 -07:00
parent 0c75d41751
commit 67dc202e42
7 changed files with 15 additions and 67 deletions

View file

@ -174,12 +174,7 @@ class AssetModelsController extends Controller
->update(['asset_eol_date' => DB::raw('null')]);
}
}
if($model->wasChanged('purchase_cost')){
if ($model->purchase_cost !== '') {
$model->assets()->whereNotNull('purchase_cost')->where('purchase_cost_explicit', false)
->update(['purchase_cost' => $model->purchase_cost] );
}
}
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
}

View file

@ -135,13 +135,7 @@ class AssetsController extends Controller
$asset->user_id = Auth::id();
$asset->status_id = request('status_id');
$asset->warranty_months = request('warranty_months', null);
if($request->filled('purchase_cost')) {
$asset->purchase_cost = $request->input('purchase_cost', null);
}
else if($asset->model->purchase_cost !== null) {
$asset->purchase_cost = $asset->model->purchase_cost;
}
$asset->purchase_cost_explicit = Asset::purchaseCostExplicit($asset, $request);
$asset->purchase_cost = request('purchase_cost') ? request('purchase_cost') : $asset->model?->purchase_cost;
$asset->purchase_date = request('purchase_date', null);
$asset->asset_eol_date = request('asset_eol_date', null);
$asset->assigned_to = request('assigned_to', null);
@ -309,20 +303,11 @@ class AssetsController extends Controller
$asset->status_id = $request->input('status_id', null);
$asset->warranty_months = $request->input('warranty_months', null);
if($request->filled('purchase_cost')) {
$asset->purchase_cost = $request->input('purchase_cost', null);
}
else if($asset->model->purchase_cost !== null) {
$asset->purchase_cost = $asset->model->purchase_cost;
}
else{
$asset->purchase_cost = null;
}
$asset->purchase_cost_explicit = Asset::purchaseCostExplicit($asset, $request);
$asset->purchase_cost = $request->input('purchase_cost', null);
$asset->purchase_date = $request->input('purchase_date', null);
$asset->next_audit_date = $request->input('next_audit_date', null);
if ($request->filled('purchase_date') && !$request->filled('asset_eol_date') && ($asset->model->eol > 0)) {
$asset->purchase_date = $request->input('purchase_date', null);
$asset->purchase_date = $request->input('purchase_date', null);
$asset->asset_eol_date = Carbon::parse($request->input('purchase_date'))->addMonths($asset->model->eol)->format('Y-m-d');
$asset->eol_explicit = false;
} elseif ($request->filled('asset_eol_date')) {

View file

@ -968,19 +968,6 @@ class Asset extends Depreciable
}
return $cost;
}
public static function purchaseCostExplicit($asset, $request)
{
if ($request->input('purchase_cost')) {
if ($asset->model->purchase_cost) {
if ($request->input('purchase_cost') !== $asset->model->purchase_cost) {
return true;
}
return false;
}
}
return false;
}
/**
* -----------------------------------------------
* BEGIN MUTATORS

View file

@ -12,28 +12,9 @@ return new class extends Migration
*/
public function up(): void
{
Schema::table('assets', function (Blueprint $table) {
if (!Schema::hasColumn('assets', 'purchase_cost_explicit')) {
$table->boolean('purchase_cost_explicit')->default(false)->after('purchase_cost');
}
});
Schema::table('models', function (Blueprint $table) {
$table->decimal('purchase_cost', 8, 2)->default(null)->nullable()->after('min_amt');
});
Asset::whereNotNull('purchase_cost')->with('model')->chunkById(500, function ($assetsWithPurchaseCosts) {
foreach ($assetsWithPurchaseCosts as $asset) {
if($asset->purchase_cost) {
if ($asset->purchase_cost !== $asset->model->purchase_cost) {
DB::table('assets')->where('id', $asset->id)->update(['purchase_cost_explicit' => true]);
}
}
else {
DB::table('assets')->where('id', $asset->id)->update(['purchase_cost_explicit' => false]);
}
}
});
}
/**
@ -41,10 +22,6 @@ return new class extends Migration
*/
public function down(): void
{
Schema::table('assets', function (Blueprint $table) {
$table->dropColumn('purchase_cost_explicit');
});
Schema::table('models', function (Blueprint $table) {
$table->dropColumn('purchase_cost');
});

View file

@ -225,7 +225,8 @@ return [
'previous' => 'Previous',
'processing' => 'Processing',
'profile' => 'Your profile',
'purchase_cost' => 'Purchase Cost',
'purchase_cost' => 'Purchase Cost',
'purchase_cost_help' => 'Leave purchase cost blank if the model has a purchase cost you would like to use.',
'purchase_date' => 'Purchase Date',
'qty' => 'QTY',
'quantity' => 'Quantity',

View file

@ -43,4 +43,4 @@
@include ('partials.forms.edit.image-upload', ['image_path' => app('models_upload_path')])
@stop
@stop

View file

@ -5,14 +5,17 @@
<div class="input-group col-md-4" style="padding-left: 0px;">
<input class="form-control" type="text" name="purchase_cost" aria-label="purchase_cost" id="purchase_cost" value="{{ (old('purchase_cost', Helper::formatCurrencyOutput($item->purchase_cost))) }}" />
<span class="input-group-addon">
@if (isset($currency_type))
{{ $currency_type }}
@else
{{ $snipeSettings->default_currency }}
@endif
@if (isset($currency_type))
{{ $currency_type }}
@else
{{ $snipeSettings->default_currency }}
@endif
</span>
</div>
<div class="col-md-9" style="padding-left: 0px;">
@if(Route::is('hardware.create'))
<p class="help-block">{{trans('general.purchase_cost_help')}}</p>
@endif
{!! $errors->first('purchase_cost', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>