purchases fix qty&subtotal
This commit is contained in:
parent
a4d1ea0ec2
commit
1f6021249e
|
@ -15,18 +15,18 @@ class PurchaseDetail extends Model
|
||||||
'purchase_id',
|
'purchase_id',
|
||||||
'product_id',
|
'product_id',
|
||||||
'product_name',
|
'product_name',
|
||||||
'quantity',
|
'qty',
|
||||||
'unit_price',
|
'unit_price',
|
||||||
'price',
|
'price',
|
||||||
'sub_total',
|
'subtotal',
|
||||||
'created_by',
|
'created_by',
|
||||||
'updated_by'
|
'updated_by'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'quantity' => 'integer',
|
'qty' => 'integer',
|
||||||
'price' => 'decimal:2',
|
'price' => 'decimal:2',
|
||||||
'sub_total' => 'decimal:2'
|
'subtotal' => 'decimal:2'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $with = ['product'];
|
protected $with = ['product'];
|
||||||
|
|
|
@ -256,7 +256,7 @@ class PurchaseController extends Controller
|
||||||
$cart->add([
|
$cart->add([
|
||||||
'id' => $purchase_detail->product_id,
|
'id' => $purchase_detail->product_id,
|
||||||
'name' => $purchase_detail->product_name,
|
'name' => $purchase_detail->product_name,
|
||||||
'qty' => $purchase_detail->quantity,
|
'qty' => $purchase_detail->qty,
|
||||||
'unit_price' => $purchase_detail->unit_price,
|
'unit_price' => $purchase_detail->unit_price,
|
||||||
'weight' => 1,
|
'weight' => 1,
|
||||||
'options' => [
|
'options' => [
|
||||||
|
@ -264,7 +264,7 @@ class PurchaseController extends Controller
|
||||||
'product_discount_type' => $purchase_detail->product_discount_type,
|
'product_discount_type' => $purchase_detail->product_discount_type,
|
||||||
'subtotal' => $purchase_detail->subtotal,
|
'subtotal' => $purchase_detail->subtotal,
|
||||||
'code' => $purchase_detail->product_code,
|
'code' => $purchase_detail->product_code,
|
||||||
'stock' => Product::findOrFail($purchase_detail->product_id)->product_quantity,
|
'stock' => Product::findOrFail($purchase_detail->product_id)->product_qty,
|
||||||
'product_tax' => $purchase_detail->product_tax_amount,
|
'product_tax' => $purchase_detail->product_tax_amount,
|
||||||
'unit_price' => $purchase_detail->unit_price
|
'unit_price' => $purchase_detail->unit_price
|
||||||
]
|
]
|
||||||
|
@ -290,7 +290,7 @@ class PurchaseController extends Controller
|
||||||
if ($purchase->status == 'Completed') {
|
if ($purchase->status == 'Completed') {
|
||||||
$product = Product::findOrFail($purchase_detail->product_id);
|
$product = Product::findOrFail($purchase_detail->product_id);
|
||||||
$product->update([
|
$product->update([
|
||||||
'product_quantity' => $product->product_quantity - $purchase_detail->qty
|
'product_qty' => $product->product_qty - $purchase_detail->qty
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$purchase_detail->delete();
|
$purchase_detail->delete();
|
||||||
|
@ -328,7 +328,7 @@ class PurchaseController extends Controller
|
||||||
if ($request->status == 'Completed') {
|
if ($request->status == 'Completed') {
|
||||||
$product = Product::findOrFail($cart_item->id);
|
$product = Product::findOrFail($cart_item->id);
|
||||||
$product->update([
|
$product->update([
|
||||||
'product_quantity' => $product->product_quantity + $cart_item->qty
|
'product_qty' => $product->product_qty + $cart_item->qty
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue