@extends('layouts.order-master') @section('css') @endsection @section('title') Order @endsection @section('content')
@isset($order)
@method('put') @else @endisset @csrf
@isset($order) Edit Order @else Add Order @endisset
{{--
--}}
{{--
--}}
@if (Auth::user()->company_profile->show_purchase_order_details_in_order == 1)
@endif
Report
Add Items
@if (Auth::user()->company_profile->show_foc == 1) @endif @isset($orderItems) @php $tabIndex = 0; @endphp @if (count($orderItems) > 0) @foreach ($orderItems as $key => $orderItem) @php $flag = false; if ($orderItem->batch_id != null) { $lastInward = \App\Models\StockLedger::where([ 'business_key' => Auth::user()->business_key, 'stock_item_id' => $orderItem->stock_item_id, 'batch_id' => $orderItem->batch_id, ]) ->where(function ($query) { $query ->where('batch_price', '!=', null) ->orWhere('batch_discount', '!=', null); }) ->orderBy('date', 'desc') ->first(); if ($lastInward) { if ($lastInward->batch_price != null) { if ( $lastInward->accounting_voucher_item_id != null ) { $batchItem = \App\Models\AccountingVoucherItem::where( 'id', $lastInward->accounting_voucher_item_id, )->first(); } elseif ( $lastInward->inventory_voucher_item_id != null ) { $batchItem = \App\Models\InventoryVoucherItem::where( 'id', $lastInward->inventory_voucher_item_id, )->first(); } elseif ( $lastInward->stock_item_location_id != null ) { $batchItem = \App\Models\StockItemLocation::where( 'id', $lastInward->stock_item_location_id, )->first(); } if ( $orderItem->unit_id == $batchItem->unit_id ) { $sellingPrice = $batchItem->batch_price; } else { $purchaseUnitQty = \App\Models\StockItemUnits::where( [ 'business_key' => Auth::user() ->business_key, 'stock_item_id' => $orderItem->stock_item_id, 'unit_id' => $batchItem->unit_id, ], )->first()->unit_qty; $currentUnitQty = \App\Models\StockItemUnits::where( [ 'business_key' => Auth::user() ->business_key, 'stock_item_id' => $orderItem->stock_item_id, 'unit_id' => $orderItem->unit_id, ], )->first()->unit_qty; $basePrice = $batchItem->batch_price / $purchaseUnitQty; $sellingPrice = round( $basePrice * $currentUnitQty, 3, ); } if ( $orderItem->price < $sellingPrice && $sellingPrice - $orderItem->price > 0.01 ) { $flag = true; } } } } else { $stockItemUnit = \App\Models\StockItemUnits::where( 'stock_item_id', $orderItem->stock_item_id, ) ->where('unit_id', $orderItem->unit_id) ->first(); if ($stockItemUnit) { $sellingPrice = $stockItemUnit->unit_selling_price; if ( $orderItem->price < $sellingPrice && $sellingPrice - $orderItem->price > 0.01 ) { $flag = true; } } } @endphp @php $key = $key + 1; @endphp @if (Auth::user()->company_profile->show_foc == 1) @php $focqty = \App\models\OrderItem::where( 'foc_id', $orderItem->id, ) ->where( 'stock_item_id', $orderItem->stock_item_id, ) ->where('unit_id', $orderItem->unit_id) ->first(); $focqty = $focqty ? $focqty->quantity : ''; @endphp @endif @php $tabIndex = $tabIndex + 8; @endphp @endforeach @endif @endisset @if (Auth::user()->company_profile->show_foc == 1) @endif
SN    Item Stock MRP Qty UnitFocPrice Price(Inc GST) Gross Value Disc% Taxable Value Tax Total Remarks
{{ $key }}
---
batch_id != null) @php $lastInward = App\Models\StockLedger::where([ 'business_key' => Auth::user()->business_key, 'stock_item_id' => $orderItem->stock_item_id, 'batch_id' => $orderItem->batch_id, ]) ->where(function ($query) { $query->where('batch_mrp', '!=', null); }) ->orderBy('date', 'desc') ->first(); @endphp @if ($lastInward) value="{{ $lastInward->batch_mrp }}" @else value="{{ $orderItem->stockItem->getMrp($order->order_date) }}" @endif @else value="{{ $orderItem->stockItem->getMrp($order->order_date) }}" @endif id="mrp_{{ $key }}" readonly class="form-control min-width60 form-input-box">
Batch: {{ $orderItem->batch?->name ?? '' }} {{-- --}} {{-- @if (($orderItem->stock_availability != null && $orderItem->stock_availability != 0) || $orderItem->status_remarks != null) --}} {{-- @if ($orderItem->stock_availability == 'NS') --}} {{-- Stock Availability : {{ $orderItem->stock_availability }} @else --}} @if ($orderItem->stock_availability != null && $orderItem->stock_availability != 0) Stock Shortage : {{ $orderItem->stock_availability }}
@endif @if ($orderItem->status_remarks != null) Stock Remarks : {{ $orderItem->status_remarks }}

@endif {{-- @endif --}} {{-- @endif --}} @php $stockledger = \App\Models\StockLedger::select( 'stock_item_id', DB::raw('SUM(inwards) as total_inwards'), DB::raw('SUM(outwards) as total_outwards'), )->where( 'stock_item_id', $orderItem->stock_item_id, ); $stockledger = $stockledger->where( 'stock_location_id', $order->stock_location_id, ); $stockledger = $stockledger ->groupBy('stock_item_id') ->first(); $inwards = 0; $outwards = 0; if ($stockledger) { $inwards = $stockledger->total_inwards; $outwards = $stockledger->total_outwards; } $stock_availability = $inwards - $outwards; $order_base_qty = \App\Models\OrderItem::select( DB::raw('SUM(base_qty) as base_qty'), ) ->where( 'stock_item_id', $orderItem->stock_item_id, ) ->groupBy('stock_item_id') ->whereHas('order', function ($q) use ( $order, ) { $q->where( 'business_key', Auth::user()->business_key, ) ->where( 'order_code', '<', $order->order_code, ) ->where( 'status', '!=', 'Cancelled', ) ->whereNull( 'accounting_voucher_id', ); }) ->first()->base_qty ?? 0; $stock_availability = $stock_availability - $order_base_qty; @endphp @if ($stock_availability < 0) Available Stock:{{ $stock_availability }} @endif
{{ isset($orderItems) ? $orderItems->sum('total') : '0.00' }}
{{--
Discount :
Freight/Etc :
Round Off :
{{ isset($order) ? $order->round_off : '0.00' }}
Grand Total :
{{ isset($order) ? $order->amount : '0.00' }}
--}} @isset($order) @foreach ($order->additionalLedgers as $orderLedger) @endforeach @endisset
Discount :
Freight/Etc :
amount }} required>
Round Off :
{{ isset($order) ? $order->round_off : '0.00' }}
Grand Total :
{{ isset($order) ? $order->amount : '0.00' }}
* Stock is based on the base unit of the item
{{-- Print Modal --}} {{-- --}} {{-- Price History Modal --}} {{-- Batch Modal --}} {{-- Next Order Edit Modal --}} @endsection @section('script') @endsection