本文整理汇总了PHP中app\Item::decreaseStock方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::decreaseStock方法的具体用法?PHP Item::decreaseStock怎么用?PHP Item::decreaseStock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Item
的用法示例。
在下文中一共展示了Item::decreaseStock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store(Request $request)
{
try {
$counter = $request->input('counter');
ItemOut::create($request->all());
$data = ItemOut::orderBy('created_at', 'desc')->first();
echo $counter;
for ($i = 0; $i < $counter; $i++) {
$qty = $request->input('qty' . strval($i));
$itemId = $request->input('item_id' . strval($i));
$isItemAvailable = Item::where('id', 'like', '%' . $itemId . '%')->first();
// Item::findOrFail($itemId);
if (is_null($isItemAvailable)) {
ItemOut::destroy($data->id);
return redirect('itemout')->with('message', 'Data dengan kode barang: ' . $itemId . ', tidak ada');
} else {
DetailItemOut::create(['qty' => $qty, 'item_id' => $itemId, 'item_out_id' => $data->id]);
Item::decreaseStock($itemId, $qty);
}
}
return redirect('itemout')->with('message', 'Data berhasil dibuat!');
} catch (\Illuminate\Database\QueryException $e) {
return redirect('itemout')->with('message', 'Data dengan email tersebut sudah digunakan!');
} catch (\PDOException $e) {
return redirect('itemout')->with('message', 'Data dengan email tersebut sudah digunakan!');
}
}
示例2: store
public function store(Request $request)
{
try {
$counter = $request->input('counter');
$transactionDate = $request->input('date');
Transaction::create($request->all());
$data = Transaction::orderBy('created_at', 'desc')->first();
ItemOut::create(['date' => $transactionDate, 'description' => 'kode transaksi ' . $data->id]);
$dataOut = ItemOut::orderBy('created_at', 'desc')->first();
$total = 0;
for ($i = 0; $i < $counter; $i++) {
echo "counter: " . $counter . "/";
$qty = $request->input('qty' . strval($i));
$priceId = $request->input('price_id' . strval($i));
$subtotal = $request->input('subtotal' . strval($i));
$total = $total + $subtotal;
$price = Price::where('id', '=', $priceId)->first();
$isItemAvailable = Item::where('id', '=', $price->item_id)->first();
if (is_null($isItemAvailable)) {
Transaction::destroy($data->id);
return redirect('transaction')->with('message', 'Data dengan kode barang: ' . $price->item_id . ', tidak ada');
} else {
DetailTransaction::create(['qty' => $qty, 'price_id' => $priceId, 'transaction_id' => $data->id, 'subtotal' => $subtotal]);
DetailItemOut::create(['qty' => $qty, 'item_id' => $price->item_id, 'item_out_id' => $dataOut->id]);
Item::decreaseStock($price->item_id, $qty);
}
}
$updateTransaction = Transaction::where('id', '=', $data->id)->first();
$updateTransaction->total_price = $total;
$updateTransaction->save();
return redirect('transaction')->with('message', 'Data berhasil dibuat!');
} catch (\Illuminate\Database\QueryException $e) {
return redirect('transaction')->with('message', 'Data dengan transaksi tersebut sudah digunakan!');
} catch (\PDOException $e) {
return redirect('transaction')->with('message', 'Data dengan transaksi tersebut sudah digunakan!');
}
}