purchases fix price
This commit is contained in:
parent
5d63a7058d
commit
a4d1ea0ec2
|
@ -14,7 +14,8 @@ class ProductBatch extends Model
|
|||
'branch_id',
|
||||
'batch_code',
|
||||
'quantity',
|
||||
'purchase_price',
|
||||
'unit_price',
|
||||
'price',
|
||||
'expired_date',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
|
@ -22,7 +23,8 @@ class ProductBatch extends Model
|
|||
|
||||
protected $casts = [
|
||||
'quantity' => 'integer',
|
||||
'purchase_price' => 'decimal:2',
|
||||
'unit_price' => 'decimal:2',
|
||||
'price' => 'decimal:2',
|
||||
'expired_date' => 'date'
|
||||
];
|
||||
|
||||
|
@ -54,7 +56,8 @@ class ProductBatch extends Model
|
|||
// Update existing batch
|
||||
$batch->update([
|
||||
'quantity' => $batch->quantity + $data['quantity'],
|
||||
'purchase_price' => $data['purchase_price'], // Update price to latest
|
||||
'unit_price' => $data['unit_price'], // Update price to latest
|
||||
'price' => $data['price'], // Update price to latest
|
||||
'updated_by' => auth()->user()->name
|
||||
]);
|
||||
return $batch;
|
||||
|
@ -66,7 +69,8 @@ class ProductBatch extends Model
|
|||
'branch_id' => $data['branch_id'],
|
||||
'batch_code' => $data['batch_code'] ?? null,
|
||||
'quantity' => $data['quantity'],
|
||||
'purchase_price' => $data['purchase_price'],
|
||||
'unit_price' => $data['unit_price'],
|
||||
'price' => $data['price'],
|
||||
'expired_date' => $data['expired_date'],
|
||||
'purchase_id' => $data['purchase_id'],
|
||||
'created_by' => auth()->user()->name,
|
||||
|
|
|
@ -16,6 +16,7 @@ class PurchaseDetail extends Model
|
|||
'product_id',
|
||||
'product_name',
|
||||
'quantity',
|
||||
'unit_price',
|
||||
'price',
|
||||
'sub_total',
|
||||
'created_by',
|
||||
|
|
|
@ -90,7 +90,8 @@ class PurchaseController extends Controller
|
|||
'products' => 'required|array|min:1',
|
||||
'products.*.product_id' => 'required|exists:products,id',
|
||||
'products.*.qty' => 'required|integer|min:1',
|
||||
'products.*.purchase_price' => 'required|numeric|min:0',
|
||||
'products.*.unit_price' => 'required|numeric|min:0',
|
||||
'products.*.price' => 'required|numeric|min:0',
|
||||
'products.*.expired_date' => 'nullable|date|after:today',
|
||||
'discount_percentage' => 'nullable|numeric|min:0',
|
||||
'discount_amount' => 'nullable|numeric|min:0',
|
||||
|
@ -158,8 +159,8 @@ class PurchaseController extends Controller
|
|||
'product_code' => Product::findOrFail($product['product_id'])->product_code,
|
||||
'qty' => $product['qty'],
|
||||
// 'price' => $product['purchase_price'],
|
||||
'unit_price' => $product['purchase_price'],
|
||||
'subtotal' => $product['qty'] * $product['purchase_price'],
|
||||
'unit_price' => $product['unit_price'],
|
||||
'subtotal' => $product['qty'] * $product['unit_price'],
|
||||
'product_discount_amount' => 0,
|
||||
'product_discount_type' => 'fixed',
|
||||
'product_tax_amount' => 0
|
||||
|
@ -170,7 +171,8 @@ class PurchaseController extends Controller
|
|||
'product_id' => $product['product_id'],
|
||||
'branch_id' => session('active_branch'),
|
||||
'qty' => $product['qty'],
|
||||
'purchase_price' => $product['purchase_price'],
|
||||
'unit_price' => $product['unit_price'],
|
||||
'price' => $product['price'],
|
||||
'exp_date' => $product['expired_date'],
|
||||
'purchase_id' => $purchase->id,
|
||||
'batch_code' => $purchase->reference_no . '-' . $product['product_id'],
|
||||
|
@ -255,7 +257,7 @@ class PurchaseController extends Controller
|
|||
'id' => $purchase_detail->product_id,
|
||||
'name' => $purchase_detail->product_name,
|
||||
'qty' => $purchase_detail->quantity,
|
||||
'price' => $purchase_detail->price,
|
||||
'unit_price' => $purchase_detail->unit_price,
|
||||
'weight' => 1,
|
||||
'options' => [
|
||||
'product_discount' => $purchase_detail->product_discount_amount,
|
||||
|
@ -315,7 +317,7 @@ class PurchaseController extends Controller
|
|||
'product_name' => $cart_item->name,
|
||||
'product_code' => $cart_item->options->code,
|
||||
'qty' => $cart_item->qty,
|
||||
'price' => $cart_item->price * 100,
|
||||
//'price' => $cart_item->price * 100,
|
||||
'unit_price' => $cart_item->price * 100,
|
||||
'subtotal' => $cart_item->options->subtotal * 100,
|
||||
'product_discount_amount' => $cart_item->options->product_discount * 100,
|
||||
|
|
|
@ -34,7 +34,7 @@ class CreatePurchase extends Component
|
|||
'items' => 'required|array|min:1',
|
||||
'items.*.product_id' => 'required|exists:products,id',
|
||||
'items.*.qty' => 'required|integer|min:1',
|
||||
'items.*.purchase_price' => 'required|numeric|min:0',
|
||||
'items.*.price' => 'required|numeric|min:0',
|
||||
'items.*.unit_price' => 'required|numeric|min:0',
|
||||
'discount' => 'nullable|numeric|min:0',
|
||||
'discount_percentage' => 'nullable|numeric|min:0|max:100',
|
||||
|
@ -56,8 +56,8 @@ class CreatePurchase extends Component
|
|||
'items.*.product_id.exists' => 'Selected product is invalid',
|
||||
'items.*.qty.required' => 'Quantity is required',
|
||||
'items.*.qty.min' => 'Quantity must be at least 1',
|
||||
'items.*.purchase_price.required' => 'Purchase price is required',
|
||||
'items.*.purchase_price.min' => 'Purchase price must be greater than 0',
|
||||
'items.*.price.required' => 'Purchase price is required',
|
||||
'items.*.price.min' => 'Purchase price must be greater than 0',
|
||||
'items.*.unit_price.required' => 'Unit price is required',
|
||||
'items.*.unit_price.min' => 'Unit price must be greater than 0',
|
||||
'discount.numeric' => 'Discount must be a number',
|
||||
|
@ -80,7 +80,7 @@ class CreatePurchase extends Component
|
|||
$this->items[] = [
|
||||
'product_id' => '',
|
||||
'qty' => 1,
|
||||
'purchase_price' => 0,
|
||||
'price' => 0,
|
||||
'unit_price' => 0,
|
||||
'discount' => 0,
|
||||
'discount_type' => null,
|
||||
|
@ -181,7 +181,7 @@ class CreatePurchase extends Component
|
|||
'product_name' => $product->product_name,
|
||||
// 'product_code' => $product->product_code,
|
||||
'qty' => $item['qty'],
|
||||
// 'price' => $item['purchase_price'],
|
||||
//'price' => $item['price'],
|
||||
'unit_price' => $item['unit_price'],
|
||||
'subtotal' => $item['qty'] * $item['unit_price'],
|
||||
'product_discount_amount' => $item['discount'] ?? 0,
|
||||
|
@ -197,7 +197,8 @@ class CreatePurchase extends Component
|
|||
'branch_id' => session('branch_id') ?? session('active_branch') ?? 1,
|
||||
'batch_code' => $this->reference_no . '-' . $item['product_id'],
|
||||
'qty' => $item['qty'],
|
||||
'unit_price' => $item['purchase_price'],
|
||||
'unit_price' => $item['unit_price'],
|
||||
'price' => $item['price'],
|
||||
'exp_date' => null,
|
||||
'purchase_id' => $purchase->id,
|
||||
'created_by' => auth()->user()->name ?? 'system',
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
<th>Product</th>
|
||||
<th>Quantity</th>
|
||||
<th>Purchase Price</th>
|
||||
<th>Unit Price</th>
|
||||
<th>Sell Price</th>
|
||||
<th>Discount</th>
|
||||
<th>Tax</th>
|
||||
<th>Subtotal</th>
|
||||
|
@ -173,14 +173,16 @@
|
|||
<input type="number" class="form-control" wire:model="items.{{ $index }}.qty" min="1">
|
||||
@error("items.{$index}.qty") <span class="text-danger">{{ $message }}</span> @enderror
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" class="form-control" wire:model="items.{{ $index }}.purchase_price" min="0" step="0.01">
|
||||
@error("items.{$index}.purchase_price") <span class="text-danger">{{ $message }}</span> @enderror
|
||||
</td>
|
||||
{{-- saya ganti jadi price --}}
|
||||
<td>
|
||||
<input type="number" class="form-control" wire:model="items.{{ $index }}.unit_price" min="0" step="0.01">
|
||||
@error("items.{$index}.unit_price") <span class="text-danger">{{ $message }}</span> @enderror
|
||||
</td>
|
||||
{{-- bagian ini saya ganti ke unit_price --}}
|
||||
<td>
|
||||
<input type="number" class="form-control" wire:model="items.{{ $index }}.price" min="0" step="0.01">
|
||||
@error("items.{$index}.price") <span class="text-danger">{{ $message }}</span> @enderror
|
||||
</td>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<input type="number" class="form-control" wire:model="items.{{ $index }}.discount" min="0" step="0.01">
|
||||
|
@ -207,7 +209,7 @@
|
|||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="6" class="text-right"><strong>Subtotal:</strong></td>
|
||||
<td colspan="6" class="text-right"><strong>Total:</strong></td>
|
||||
<td colspan="2">
|
||||
<strong>{{ number_format($total_amount, 2) }}</strong>
|
||||
</td>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('product_batches', function (Blueprint $table) {
|
||||
$table->decimal('price', 15, 2)->nullable()->after('unit_price');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('product_batches', function (Blueprint $table) {
|
||||
$table->dropColumn('price');
|
||||
});
|
||||
}
|
||||
|
||||
};
|
Loading…
Reference in New Issue