A free open source IT asset/license management system
Added currency and supplier to modal and importer
snipea86bc77b2189
diff --git a/app/Http/Requests/AdjustQuantityRequest.php b/app/Http/Requests/AdjustQuantityRequest.phpindex 94c34d68b6..554866d0c4 100644--- a/app/Http/Requests/AdjustQuantityRequest.php+++ b/app/Http/Requests/AdjustQuantityRequest.php@@ -31,6 +31,22 @@ class AdjustQuantityRequest extends FormRequest'amount' => ['required', 'integer'],'note' => ['required', 'string', 'max:65535'],'order_number' => ['nullable', 'string', 'max:191'],+ // Acquisition metadata that feeds Order / OrderItem creation+ // via HandlesAdjustQuantity::resolveOrderForAdjustment. All+ // optional — audit-only submissions leave them blank and no+ // Order row is generated. supplier_id lookup goes through+ // resolveOrderForAdjustment (not a direct exists rule here)+ // so the caller sees a clean error instead of the+ // hard-coded validation message.+ 'supplier_id' => ['nullable', 'integer', 'exists:suppliers,id'],+ 'purchase_date' => ['nullable', 'date_format:Y-m-d'],+ // Per-unit cost — matches Snipe-IT's existing purchase_cost+ // semantic. Lands on OrderItem.price. gte:0 protects against+ // negative-value posts; max mirrors the widest decimal(20,4).+ 'unit_cost' => ['nullable', 'numeric', 'gte:0', 'max:9999999999999999.9999'],+ // Currency free-text (matches locations.currency /+ // settings.default_currency shape). Lands on Order.currency.+ 'currency' => ['nullable', 'string', 'max:10'],// Optional receipt/invoice/PO scan. Attaches to the same// QuantityAdjust action_log row via its filename column,// not a separate 'uploaded' entry, so the download surfacesdiff --git a/app/Http/Traits/HandlesAdjustQuantity.php b/app/Http/Traits/HandlesAdjustQuantity.phpindex 6c9234e957..6863d456c0 100644--- a/app/Http/Traits/HandlesAdjustQuantity.php+++ b/app/Http/Traits/HandlesAdjustQuantity.php@@ -89,12 +89,18 @@ trait HandlesAdjustQuantity$orderNumber = trim((string) $request->input('order_number', ''));$supplierId = $request->filled('supplier_id') ? (int) $request->input('supplier_id') : null;$purchaseDate = $request->filled('purchase_date') ? $request->input('purchase_date') : null;+ $unitCost = $request->filled('unit_cost') ? (float) $request->input('unit_cost') : null;+ $currency = $request->filled('currency') ? trim((string) $request->input('currency')) : null;// No acquisition context in the request means don't create an// Order. Audit-only submissions (zero delta with no supplier /- // order number / date) fall through here so we don't accrete- // meaningless Order rows for pure inventory counts.- if ($orderNumber === '' && $supplierId === null && $purchaseDate === null) {+ // order number / date / cost) fall through here so we don't+ // accrete meaningless Order rows for pure inventory counts.+ if ($orderNumber === ''+ && $supplierId === null+ && $purchaseDate === null+ && $unitCost === null+ && ($currency === null || $currency === '')) {return null;}@@ -108,6 +114,7 @@ trait HandlesAdjustQuantity],['purchase_date' => $purchaseDate,+ 'currency' => $currency !== '' ? $currency : null,'created_by' => auth()->id(),],);@@ -120,7 +127,7 @@ trait HandlesAdjustQuantity// records the absolute number of units the line represents,// and the delta sign lives on the sibling action_log.'qty' => max(1, abs($delta)),- 'price' => null,+ 'price' => $unitCost,]);return $order->id;diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.phpindex 0ed75a1e75..8fd4aac7e1 100644--- a/app/Importer/ItemImporter.php+++ b/app/Importer/ItemImporter.php@@ -249,6 +249,14 @@ class ItemImporter extends Importer$purchaseCost = $model->purchase_cost ?? null;$qty = (int) ($model->qty ?? 1);+ // Only stamp Order.currency when the CSV actually carries it in+ // a `currency` column. Falling back to the system default here+ // would assert info we don't have — a row's purchase_date can+ // be historical (from when the install's currency was+ // different), so imports leave currency null unless the CSV is+ // explicit about it.+ $currency = trim((string) $this->findCsvMatch($row, 'currency'));+$order = \App\Models\Order::firstOrCreate(['order_number' => $orderNumber,@@ -257,6 +265,7 @@ class ItemImporter extends Importer],['purchase_date' => $purchaseDate,+ 'currency' => $currency !== '' ? $currency : null,'created_by' => $this->created_by,],);diff --git a/database/migrations/2026_08_03_142000_backfill_orders_from_inventory_tables.php b/database/migrations/2026_08_03_142000_backfill_orders_from_inventory_tables.phpindex 2ed9f2011d..74a64dc58d 100644--- a/database/migrations/2026_08_03_142000_backfill_orders_from_inventory_tables.php+++ b/database/migrations/2026_08_03_142000_backfill_orders_from_inventory_tables.php@@ -46,6 +46,16 @@ return new class extends Migration// Keeps us from hitting the DB with a lookup per source row.$orderIndex = [];+ // Order.currency stays NULL for backfilled rows. The source+ // inventory tables didn't have their own currency column, and+ // stamping every historical Order with today's system+ // default_currency would fabricate information we don't+ // actually have — orders placed years ago may have been in a+ // different currency than the install's current setting.+ // Downstream display code can fall back to+ // $snipeSettings->default_currency at render time (matching how+ // the pre-Orders info panels rendered purchase_cost anyway).+foreach (self::SOURCES as $modelClass => $table) {// Defensive skip: if a source table has already had its// order_number column dropped (partial rerun, hand rollback,diff --git a/resources/assets/js/snipeit.js b/resources/assets/js/snipeit.jsindex e7f5b87b29..2957c96532 100755--- a/resources/assets/js/snipeit.js+++ b/resources/assets/js/snipeit.js@@ -181,6 +181,17 @@ $(function () {$amount.val('');$modal.find('#adjustQuantityOrder').val('');+ // Reset the acquisition-metadata fields between opens so an+ // order left half-filled by one operator doesn't bleed into the+ // next click. Supplier is a select2, so use .val('').trigger('change')+ // rather than setting the raw <select>; currency reverts to+ // whatever the modal was originally rendered with (its DOM value+ // attribute, i.e. the system default_currency).+ $modal.find('#adjustQuantitySupplier').val('').trigger('change');+ $modal.find('#adjustQuantityPurchaseDate').val('');+ $modal.find('#adjustQuantityUnitCost').val('');+ var $currency = $modal.find('#adjustQuantityCurrency');+ $currency.val($currency.prop('defaultValue') || '');$modal.find('#adjustQuantityNote').val('');$modal.find('#adjustQuantityFile').val('');// js-uploadFile paints selected filenames into #{id}-info; clear it toodiff --git a/resources/views/blade/modals/adjust-quantity.blade.php b/resources/views/blade/modals/adjust-quantity.blade.phpindex ec68fa84e8..ceabfb91fe 100644--- a/resources/views/blade/modals/adjust-quantity.blade.php+++ b/resources/views/blade/modals/adjust-quantity.blade.php@@ -34,6 +34,72 @@<input type="text" class="form-control" id="adjustQuantityOrder" name="order_number" maxlength="191"></div>+ {{-- Inlined js-data-ajax select instead of <x-input.supplier-select>+ for the same reason the file-upload input is inlined below: the+ shared component uses a Bootstrap 3 horizontal-form scaffold+ (col-md-3 label + col-md-7 input) that collides with the+ modal-footer top border. snipeit.js auto-initializes any+ .js-data-ajax select. --}}+ <div class="form-group">+ <label for="adjustQuantitySupplier">{{ trans('general.supplier') }}</label>+ <select+ class="js-data-ajax form-control"+ data-endpoint="suppliers"+ data-placeholder="{{ trans('general.select_supplier') }}"+ name="supplier_id"+ id="adjustQuantitySupplier"+ style="width: 100%"+ aria-label="{{ trans('general.supplier') }}"+ >+ <option value=""></option>+ </select>+ </div>++ <div class="form-group">+ <label for="adjustQuantityPurchaseDate">{{ trans('general.purchase_date') }}</label>+ <x-input.datepicker+ id="adjustQuantityPurchaseDate"+ name="purchase_date"+ :end_date="'0d'"+ />+ </div>++ {{-- Unit cost + currency side by side. Bootstrap 3+ input-group doesn't handle a form-control addon+ cleanly (the addon slot expects a span, not a+ second input), so this uses a plain row / col+ split instead. Currency is editable and left+ blank on open — pre-filling with the system+ default would assert info we don't have per+ event (Snipe-IT's historical currency handling+ is squishy already). Placeholder hints at the+ system default without stamping it. --}}+ <div class="row">+ <div class="col-md-8 form-group" style="padding-right: 5px;">+ <label for="adjustQuantityUnitCost">{{ trans('general.unit_cost') }}</label>+ <input+ type="number"+ class="form-control"+ id="adjustQuantityUnitCost"+ name="unit_cost"+ step="0.0001"+ min="0"+ inputmode="decimal"+ >+ </div>+ <div class="col-md-4 form-group" style="padding-left: 5px;">+ <label for="adjustQuantityCurrency">{{ trans('general.currency') }}</label>+ <input+ type="text"+ class="form-control"+ id="adjustQuantityCurrency"+ name="currency"+ maxlength="10"+ placeholder="{{ $snipeSettings->default_currency }}"+ >+ </div>+ </div>+<div class="form-group"><label for="adjustQuantityNote">{{ trans('general.notes') }}</label><textarea class="form-control" id="adjustQuantityNote" name="note" rows="3" maxlength="65535" required></textarea>