/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(InventoryRequest $request, $id) { $items = Item::find($id); $items->quantity = $items->quantity + Input::get('in_out_qty'); $items->save(); $inventories = new Inventory(); $inventories->item_id = $id; $inventories->user_id = Auth::user()->id; $inventories->in_out_qty = Input::get('in_out_qty'); $inventories->remarks = Input::get('remarks'); $inventories->save(); Session::flash('message', 'You have successfully updated item'); return Redirect::to('inventory/' . $id . '/edit'); }
public function checkInventory($item, $size) { $checkInventory = \App\Inventory::where('product_id', $item)->pluck($size) - $this->cartInventory($item, $size); if ($checkInventory > 0) { return 1; } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $update = \App\Inventory::find($id); $product_id = $update->product_id; $update->update($request->except('_token')); return $product_id; }
/** * Run the database seeds. * * @return void */ public function run() { $arr = json_decode($this->items); foreach ($arr as $item) { \App\Inventory::create(['name' => $item->name, 'quantity_on_hand' => $item->quantityOnHand, 'updated_at' => $item->updated_at, 'par' => $item->par, 'measurement' => $item->measurement]); } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $first = date('Y-m-d', mktime(0, 0, 0, date('m'), 1, date('Y'))); $last = date('Y-m-t', mktime(0, 0, 0, date('m'), 1, date('Y'))); $inventory_value = Inventory::select(DB::Raw('SUM(products.cost_price * inventories.quantity) as total_value'))->join('products', 'products.id', '=', 'inventories.product_id')->get(); $top_product = Sale::select('products.title', 'sales.product_id', DB::raw('count(sales.product_id) as sales_count'))->join('products', 'products.id', '=', 'sales.product_id')->whereBetween('sales.created_at', array($first, $last))->groupBy('sales.product_id')->orderBy('sales_count', 'desc')->take(10)->get(); return view('dashboard/dashboard')->with('top_product', $top_product)->with('total_value', $inventory_value); }
public function sync() { $timecard_data = Input::get('timecard_data'); $inventory_data = Input::get('inventory_data'); $positions_modified = Input::get('positions_modified'); $users_modified = Input::get('users_modified'); $timecard_modified = Input::get('timecard_modified'); $checklists_modified = Input::get('checklists_modified'); $inventory_modified = Input::get('inventory_modified'); foreach ($inventory_data as $entry) { $record = \App\Inventory::findOrFail($entry["guid"]); $record->quantity_on_hand = $entry["quantity_on_hand"]; $record->updated_at = Carbon::createFromTimestamp($entry["last_modified"], 'America/Chicago'); $record->save(); $adj = new \App\InventoryAdjustment(); $adj->inventory_id = $record->id; $adj->quantity_on_hand = $record->quantity_on_hand; $adj->save(); } $stamp = ""; foreach ($timecard_data as $entry) { $stamp = date_default_timezone_get(); $record = \App\Timecard::where('guid', $entry["guid"])->first(); if ($record) { $record->guid = $entry["guid"]; $record->clock_in = Carbon::createFromTimestamp($entry["clock_in"], 'America/Chicago'); if ($entry["clock_out"] == '0') { $record->clock_out = null; } else { $record->clock_out = Carbon::createFromTimestamp($entry["clock_out"], 'America/Chicago'); } $record->save(); } else { $record = new \App\Timecard(); $record->guid = $entry["guid"]; $record->clock_in = Carbon::createFromTimestamp($entry["clock_in"], 'America/Chicago'); if ($entry["clock_out"] == '0') { $record->clock_out = null; } else { $record->clock_out = Carbon::createFromTimestamp($entry["clock_out"], 'America/Chicago'); } $record->user_id = $entry["user_id"]; $record->position_id = $entry["position_id"]; $record->save(); } } $users_last_modified = Carbon::createFromTimestamp($users_modified)->toDateTimeString(); $users = \App\User::where('updated_at', '>', $users_last_modified)->get(); $timecard_last_modified = Carbon::createFromTimestamp($timecard_modified)->toDateTimeString(); $timecards = \App\Timecard::where('updated_at', '>', $timecard_last_modified)->get(); $positions_last_modified = Carbon::createFromTimestamp($positions_modified)->toDateTimeString(); $positions = \App\Position::withTrashed()->where('updated_at', '>', $positions_last_modified)->get(); $checklists_last_modified = Carbon::createFromTimestamp($checklists_modified)->toDateTimeString(); $checklist = \App\Checklist::withTrashed()->where('updated_at', '>', $checklists_last_modified)->get(); $inventory_last_modified = Carbon::createFromTimestamp($inventory_modified)->toDateTimeString(); $inventory = \App\Inventory::withTrashed()->where('updated_at', '>', $inventory_last_modified)->get(); return Response::json(["users" => $users, "checklist" => $checklist, "inventory" => $inventory, "timecards" => $timecards, "positions" => $positions]); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(SaleRequest $request) { $sales = new Sale(); $sales->customer_id = Input::get('customer_id'); $sales->user_id = Auth::user()->id; $sales->payment_type = Input::get('payment_type'); $sales->comments = Input::get('comments'); $sales->save(); // process sale items $saleItems = SaleTemp::all(); foreach ($saleItems as $value) { $saleItemsData = new SaleItem(); $saleItemsData->sale_id = $sales->id; $saleItemsData->item_id = $value->item_id; $saleItemsData->cost_price = $value->cost_price; $saleItemsData->selling_price = $value->selling_price; $saleItemsData->quantity = $value->quantity; $saleItemsData->total_cost = $value->total_cost; $saleItemsData->total_selling = $value->total_selling; $saleItemsData->save(); //process inventory $items = Item::find($value->item_id); if ($items->type == 1) { $inventories = new Inventory(); $inventories->item_id = $value->item_id; $inventories->user_id = Auth::user()->id; $inventories->in_out_qty = -$value->quantity; $inventories->remarks = 'SALE' . $sales->id; $inventories->save(); //process item quantity $items->quantity = $items->quantity - $value->quantity; $items->save(); } else { $itemkits = ItemKitItem::where('item_kit_id', $value->item_id)->get(); foreach ($itemkits as $item_kit_value) { $inventories = new Inventory(); $inventories->item_id = $item_kit_value->item_id; $inventories->user_id = Auth::user()->id; $inventories->in_out_qty = -($item_kit_value->quantity * $value->quantity); $inventories->remarks = 'SALE' . $sales->id; $inventories->save(); //process item quantity $item_quantity = Item::find($item_kit_value->item_id); $item_quantity->quantity = $item_quantity->quantity - $item_kit_value->quantity * $value->quantity; $item_quantity->save(); } } } //delete all data on SaleTemp model SaleTemp::truncate(); $itemssale = SaleItem::where('sale_id', $saleItemsData->sale_id)->get(); Session::flash('message', 'You have successfully added sales'); //return Redirect::to('receivings'); return view('sale.complete')->with('sales', $sales)->with('saleItemsData', $saleItemsData)->with('saleItems', $itemssale); }
public function show($id) { $data = Queue::find($id); $data->status = 'Consulting'; $data->save(); $ic = $data->pt_ic; $data2 = Patient::where('pt_ic', $ic)->first(); //$data3 = Record::where('pt_id', $data2); $inventory = Inventory::all(); return view('doctor.newcase')->with('data', $data)->with('data2', $data2)->with('inventory', $inventory); //->with('history',$data3); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $inv_types = InvType::all(); $inventories = Inventory::all(); $orders = array(); $order = new Order(); for ($i = 0; $i < 6; $i++) { $orders[$i] = $order->get_order_by_table($i + 1); } $page_title = 'Table Orders'; $date = date('Y-m-d'); return view('test', compact('page_title', 'date', 'inv_types', 'inventories', 'orders')); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(ReceivingRequest $request) { $receivings = new Receiving(); $receivings->supplier_id = Input::get('supplier_id'); $receivings->user_id = Auth::user()->id; $receivings->payment_type = Input::get('payment_type'); $receivings->comments = Input::get('comments'); $receivings->save(); // process receiving items $receivingItems = ReceivingTemp::all(); foreach ($receivingItems as $value) { $receivingItemsData = new ReceivingItem(); $receivingItemsData->receiving_id = $receivings->id; $receivingItemsData->item_id = $value->item_id; $receivingItemsData->cost_price = $value->cost_price; $receivingItemsData->quantity = $value->quantity; $receivingItemsData->total_cost = $value->total_cost; $receivingItemsData->save(); //process inventory $items = Item::find($value->item_id); $inventories = new Inventory(); $inventories->item_id = $value->item_id; $inventories->user_id = Auth::user()->id; $inventories->in_out_qty = $value->quantity; $inventories->remarks = 'RECV' . $receivings->id; $inventories->save(); //process item quantity $items->quantity = $items->quantity + $value->quantity; $items->save(); } //delete all data on ReceivingTemp model ReceivingTemp::truncate(); $itemsreceiving = ReceivingItem::where('receiving_id', $receivingItemsData->receiving_id)->get(); Session::flash('message', 'You have successfully added receivings'); //return Redirect::to('receivings'); return view('receiving.complete')->with('receivings', $receivings)->with('receivingItemsData', $receivingItemsData)->with('receivingItems', $itemsreceiving); }
public function reportDetailed(Request $request) { $from_date = Carbon::parse($request->get('from_date'))->startOfDay(); $to_date = Carbon::parse($request->get('to_date'))->endOfDay(); $inventory = Inventory::with(['stock' => function ($query) use($from_date, $to_date) { $query->whereBetween('stock.created_at', [$from_date, $to_date])->orderBy('stock.created_at'); }])->get(); foreach ($inventory as $item) { $total_changes = array_sum($item->stock->pluck('quantity')->toArray()); $starting_quantity = $item->quantity - $total_changes; foreach ($item->stock as $stock) { $stock->previous_quantity = number_format($starting_quantity, 1); $stock->updated_quantity = number_format($starting_quantity += $stock->quantity, 1); } } return $inventory; }
public function dispense($ic, $name) { $getID = Patient::where('pt_ic', $ic)->first(); //whole row $deID = $getID->id; //get the id from the ic $getcaseID = Record::where('pt_id', $deID)->first(); $caseID = $getcaseID->id; $disData = Dispensary::where('case_ref', $caseID)->first(); //xpe pakai first() sbb setiap case unik, case lain xpakai id ni $arrQty = explode("#", $disData->dispensed_quantity); $arrDrug = explode("#", $disData->dispensed_drug_code); //need declare $prices array x? $prices = array(); for ($x = 0; $x < count($arrDrug) - 1; $x++) { //get price of each drug into an array $hehe = Inventory::where('drug_name', $arrDrug[$x])->first(); $prices[$x] = $hehe->spu; } // $arrOne = count($arrDrug); // arr1 = druglist , arr2= respective qty of drug, arr3= respective price of drug $panel = Panel::all(); return view('staff.dispensary')->with('name', $name)->with('arr2', $arrQty)->with('arr1', $arrDrug)->with('arr3', $prices)->with('panel', $panel)->with('ptid', $deID); }
private function getInventory($id) { $inventory = Inventory::select(DB::raw('title, dvd, count(*) as quantity '))->join('movies', 'inventory.movie_id', '=', 'movies.id')->where('kiosk_id', $id)->where('isRented', 0)->groupBy('title', 'dvd')->get()->toArray(); return $inventory; }
public function delete($id) { $item = Inventory::findOrFail($id); $item->delete(); return redirect('/category/inventories'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $saleOrders = SaleOrder::where('id', $id)->first(); $products = SaleOrderDetail::whereSalesOrderId($id)->get(); if ($saleOrders->is_pos == 1) { foreach ($products as $product) { Inventory::wherePointOfSalesId($id)->delete(); $fields = ['product_id' => $product->product_id, 'location_id' => \Auth::user()->location]; $checkIfSaleExistingProduct = InventoryTotal::where($fields)->first(); $inventoryTotalDetail = $inventoryTotals = array(); $inventoryTotals = new InventoryTotal(); $inventoryTotal['total_qty'] = $checkIfSaleExistingProduct['total_qty'] + $product->qty * $product->conversion; $inventoryTotal['created_by'] = \Auth::user()->id; $inventoryTotal['updated_by'] = \Auth::user()->id; $inventoryTotals->where($fields)->update($inventoryTotal); $inventoryTotalDetails = new InventoryTotalDetail(); $fieldNews = ['product_id' => $product->product_id, 'location_id' => \Auth::user()->location, 'date' => date('Y-m-d')]; $checkIfSaleExistingProductInventoryDetail = InventoryTotalDetail::where($fieldNews)->first(); $inventoryTotalDetail['total_pos'] = $checkIfSaleExistingProductInventoryDetail['total_qty'] - $product->qty * $product->conversion; $inventoryTotalDetail['created_by'] = \Auth::user()->id; $inventoryTotalDetail['updated_by'] = \Auth::user()->id; $inventoryTotalDetails->where($fieldNews)->update($inventoryTotalDetail); } } else { Inventory::whereSalesOrderId($id)->delete(); } SaleOrderReceipt::whereSalesOrderId($id)->delete(); SaleOrderDetail::whereSalesOrderId($id)->delete(); $saleOrders = SaleOrder::find($id); $saleOrders->delete(); return Redirect::route('saleOrders.index')->with('flash_notice', 'You are successfully delete!'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function sale(SaleOrder $saleOrders, Request $request, SaleOrderDetail $saleOrderDetails, SaleOrderReceipt $saleOrderReceipts) { $exchangerate = DB::table('exchange_rates')->orderBy('id', 'desc')->first(); $rate = $exchangerate->riel; $inputs = Input::all(); $inputs['amount_riel'] = str_replace(",", "", $inputs['amount_riel']); $user = \Auth::user()->id; // To save sale order table $saleOrder = array(); $saleOrder['_token'] = $inputs['_token']; $saleOrder['location_id'] = Session::get('location_id'); $saleOrder['customer_id'] = 1; $saleOrder['so_code'] = $this->generateAutoCode("sales_orders", "so_code", 6, "SO"); $saleOrder['total_amount_riel'] = $inputs['total_amount_riel']; $saleOrder['total_amount_us'] = $inputs['total_amount_us']; $saleOrder['discount_riel'] = $inputs['custom-discount-riel']; $saleOrder['discount_us'] = $inputs['custom-discount-us']; $saleOrder['balance'] = $inputs['total_amount_riel'] - ($inputs['amount_riel'] + $inputs['amount_us'] * $rate + $inputs['custom-discount-riel'] + $inputs['custom-discount-us'] * $rate); $saleOrder['order_date'] = date('Y-m-d'); $saleOrder['due_date'] = date('Y-m-d'); $saleOrder['is_active'] = 1; $saleOrder['is_pos'] = 1; $saleOrder['created_by'] = $user; $saleOrder['updated_by'] = $user; $saleOrders->fill($saleOrder)->save(); $sale_order_id = $saleOrders->id; // To save sale order receipts table $saleOrderReceipt = array(); $saleOrderReceipt['sales_order_id'] = $sale_order_id; $saleOrderReceipt['exchange_rate_id'] = $exchangerate->id; $saleOrderReceipt['receipt_code'] = $this->generateAutoCode("sales_order_receipts", "receipt_code", 6, "RE"); $saleOrderReceipt['amount_us'] = $inputs['amount_us']; $saleOrderReceipt['amount_kh'] = $inputs['amount_riel']; $saleOrderReceipt['total_amount'] = $inputs['total_amount_riel']; $saleOrderReceipt['balance'] = $inputs['total_amount_riel'] - ($inputs['amount_riel'] + $inputs['amount_us'] * $rate + $inputs['custom-discount-riel'] + $inputs['custom-discount-us'] * $rate); $saleOrderReceipt['pay_date'] = date('Y-m-d'); $saleOrderReceipt['due_date'] = date('Y-m-d'); $saleOrderReceipt['created_by'] = $user; $saleOrderReceipt['updated_by'] = $user; $saleOrderReceipt['is_active'] = 1; $saleOrderReceipts->fill($saleOrderReceipt)->save(); // To save sale order detail table for ($i = 0; $i < count($inputs['id']) - 1; $i++) { $saleOrderDetail = new SaleOrderDetail(); $saleOrderDetail['sales_order_id'] = $sale_order_id; $saleOrderDetail['product_id'] = $inputs['id'][$i]; $saleOrderDetail['discount_price_riel'] = $inputs['txt_discount'][$i]; $saleOrderDetail['qty'] = $inputs['txt_qty'][$i]; $saleOrderDetail['qty_uom_id'] = 1; $saleOrderDetail['conversion'] = 1; $saleOrderDetail['unit_price'] = $inputs['txt_unit_price'][$i]; $saleOrderDetail['total_price_riel'] = $inputs['txt_total_by_item'][$i]; $saleOrderDetail->save(); } // Save to inventory for ($k = 0; $k < count($inputs['id']) - 1; $k++) { $fields = ['product_id' => $inputs['id'][$k], 'location_id' => Session::get('location_id')]; $checkIfSaleExistingProduct = InventoryTotal::where($fields)->first(); // Save to inventories table $inventory = new Inventory(); $inventory['point_of_sales_id'] = $sale_order_id; $inventory['product_id'] = $inputs['id'][$k]; $inventory['location_id'] = Session::get('location_id'); $inventory['qty'] = $inputs['txt_qty'][$k]; $inventory['sale_price'] = $inputs['txt_unit_price'][$k]; $inventory['date'] = date('Y-m-d'); $inventory['created_by'] = $user; $inventory['updated_by'] = $user; $inventory->save(); if (count($checkIfSaleExistingProduct) > 0) { //for existing product in inventory // Save to inventory_totals table $inventoryTotals = new InventoryTotal(); $inventoryTotal = array(); $inventoryTotal['total_qty'] = $checkIfSaleExistingProduct['total_qty'] - $inputs['txt_qty'][$k]; $inventoryTotal['created_by'] = $user; $inventoryTotal['updated_by'] = $user; $inventoryTotals->where($fields)->update($inventoryTotal); // Save to inventory_total_details table $inventoryTotalDetails = new InventoryTotalDetail(); $inventoryTotalDetail = array(); $fieldNews = ['product_id' => $inputs['id'][$k], 'location_id' => Session::get('location_id'), 'date' => date('Y-m-d')]; $checkIfSaleExistingProductInventoryDetail = InventoryTotalDetail::where($fieldNews)->first(); $inventoryTotalDetail['total_pos'] = $checkIfSaleExistingProductInventoryDetail['total_qty'] - $inputs['txt_qty'][$k]; $inventoryTotalDetail['created_by'] = $user; $inventoryTotalDetail['updated_by'] = $user; $inventoryTotalDetails->where($fieldNews)->update($inventoryTotalDetail); } else { // for a new product in inventory // Save to inventory_totals table $inventoryTotal = new InventoryTotal(); $inventoryTotal['product_id'] = $inputs['id'][$k]; $inventoryTotal['location_id'] = Session::get('location_id'); $inventoryTotal['total_qty'] = -1 * $inputs['txt_qty'][$k]; $inventoryTotal['created_by'] = $user; $inventoryTotal['updated_by'] = $user; $inventoryTotal->save(); // Save to inventory_total_details table $inventoryTotalDetail = new InventoryTotalDetail(); $inventoryTotalDetail['product_id'] = $inputs['id'][$k]; $inventoryTotalDetail['location_id'] = Session::get('location_id'); $inventoryTotalDetail['total_pos'] = -1 * $inputs['txt_qty'][$k]; $inventoryTotalDetail['date'] = date('Y-m-d'); $inventoryTotalDetail['created_by'] = $user; $inventoryTotalDetail['updated_by'] = $user; $inventoryTotalDetail->save(); } } echo $sale_order_id; exit; }
public function updateInventory($id) { $attributes = Input::all(); $inventory = Inventory::find($id); $result = $inventory->fill($attributes)->save(); if ($result) { return redirect()->action('HomeController@getInventory'); } }
public function completePayment(Request $request, SlackHandler $slacker) { // Set your secret key: remember to change this to your live secret key in production // See your keys here https://dashboard.stripe.com/account/apikeys Stripe::setApiKey(env('STRIPE_SK')); // Get the credit card details submitted by the form $token = $request->input('stripeToken'); // dd(\Session::get('cart_id')); if (!\Session::get('cart_id')) { return redirect()->route('alreadyPaid'); } if (\App\Shipping::where('cart_id', \Session::get('cart_id'))->pluck('payment_status') == 'Paid') { return redirect()->route('alreadyPaid'); } // $charge = 0; // $cart->checkoutPrice() // Create the charge on Stripe's servers - this will charge the user's card try { $charge = Charge::create(array("amount" => round($this->getCheckoutPrice()), "currency" => "usd", "source" => $token, "description" => \Session::get('cart_id'))); } catch (\Stripe\Error\Card $e) { // The card has been declined } $cart_id = \Session::get('cart_id'); $markPaid = \App\Shipping::where('cart_id', \Session::get('cart_id'))->first(); $markPaid->payment_status = 'Paid'; $markPaid->shipped_status = 'Not Shipped'; $markPaid->save(); $slacker->sendSaleMessage(); \App\Sale::create(array('customer_id' => $markPaid->email, 'cart_id' => \Session::get('cart_id'))); $purge = []; foreach (\App\Cart::where('customer_id', $cart_id)->get() as $purgeCarts) { $purge[] = $purgeCarts; $inventory = \App\Inventory::where('product_id', $purgeCarts->product_id)->pluck($purgeCarts->size); $newsize = $inventory - $purgeCarts->quantity; \DB::table('inventories')->where('product_id', $purgeCarts->product_id)->update(array($purgeCarts->size => $newsize)); } if (env('APP_ENV') == 'local') { \Mail::send('emails.productshipped', array('cart' => \App\Cart::where('customer_id', $cart_id)->get(), 'customer' => \App\Shipping::where('cart_id', $cart_id)->first()), function ($message) { $message->to(\App\Shipping::where('cart_id', \Session::get('cart_id'))->pluck('email'))->subject("Your Eternally Nocturnal Order"); }); } else { \Mail::send('emails.productshipped', array('cart' => \App\Cart::where('customer_id', $cart_id)->get(), 'customer' => \App\Shipping::where('cart_id', $cart_id)->first()), function ($message) { $message->to(\App\Shipping::where('cart_id', \Session::get('cart_id'))->pluck('email'))->subject("Your Eternally Nocturnal Order"); }); } \Session::forget('cart_id'); \Session::forget('checkoutAmt'); return redirect()->route('transSuccess'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(ItemRequest $request, $id) { $items = Item::find($id); // process inventory $inventories = new Inventory(); $inventories->item_id = $id; $inventories->user_id = Auth::user()->id; $inventories->in_out_qty = Input::get('quantity') - $items->quantity; $inventories->remarks = 'Manual Edit of Quantity'; $inventories->save(); // save update $items->upc_ean_isbn = Input::get('upc_ean_isbn'); $items->item_name = Input::get('item_name'); $items->size = Input::get('size'); $items->description = Input::get('description'); $items->cost_price = Input::get('cost_price'); $items->selling_price = Input::get('selling_price'); $items->quantity = Input::get('quantity'); $items->save(); // process avatar $image = $request->file('avatar'); if (!empty($image)) { $avatarName = 'item' . $id . '.' . $request->file('avatar')->getClientOriginalExtension(); $request->file('avatar')->move(base_path() . '/public/images/items/', $avatarName); $img = Image::make(base_path() . '/public/images/items/' . $avatarName); $img->resize(100, null, function ($constraint) { $constraint->aspectRatio(); }); $img->save(); $itemAvatar = Item::find($id); $itemAvatar->avatar = $avatarName; $itemAvatar->save(); } Session::flash('message', 'You have successfully updated item'); return Redirect::to('items'); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $inventory = Inventory::findOrFail($id); return view('inventory.edit', compact('inventory')); }
public function addInventory($inventory) { $inventory['product_id'] = $this->id; \App\Inventory::create($inventory); return; }
/** * A movie can be returned to any Kiosk so update kiosk and make movie available * * @param $id * @param $kiosk */ private function markReturned($id, $kiosk) { Inventory::where('id', $id)->update(['isRented' => 0, 'kiosk_id' => $kiosk]); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $orderID, $id) { // create the new Order $inventory = Inventory::find($id); $order = Order::find($orderID); $bullet = Bullet::find($request->bullet_id); // Get the data $inventory->boxes = $request->boxes; $inventory->rounds_per_box = $request->rounds_per_box; $inventory->rounds = $request->rounds_per_box * $request->boxes; $inventory->cost_per_box = $request->cost_per_box; $inventory->cost = $request->cost_per_box * $request->boxes; $inventory->notes = $request->notes; // Make relationships $inventory->bullet()->associate($bullet); $inventory->order()->associate($order); // Update the totals $inventory->order->updateCost(); $inventory->order->updateRounds(); $inventory->order->save(); // Save the Order $inventory->save(); // Update inventory for all Bullets Bullet::updateInventory(); session()->flash('message', 'Inventory has been Saved'); session()->flash('message-type', 'success'); return redirect()->action('InventoryController@show', [$order->id, $inventory->id]); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $item = \App\Inventory::findOrFail($id); $item->delete(); }
private function modifyQuantity(Request $request, $modifier) { $inventory = new Inventory(); $item = $inventory->where("product_id", "=", $request->product_id)->first(); $item->quantity = $item->quantity + $modifier; if ($item->quantity < 0) { $item->quantity = 0; return false; } $item->save(); return json_encode($item); }
public function deleteItem($conferenceId, $itemId) { $item = Inventory::where('conferenceID', $conferenceId)->where('id', $itemId); if ($item->delete()) { return response()->json(['message' => 'item_deleted'], 200); } else { return response()->json(['message' => 'item_could_not_be_deleted'], 500); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $inventory = Inventory::find($id); $inventory->delete(); Session::flash('flash_message', 'Successfully deleted!'); return redirect()->action('InvController@index'); }
public function save(CycleInventory $cycles, CycleProductDetail $cycleProducts) { $inputs = Input::all(); // To save sale order table $cycle = array(); $cycle['_token'] = $inputs['_token']; $cycle['date'] = $inputs['date']; $cycle['is_active'] = 1; $cycle['created_by'] = \Auth::user()->id; $cycle['updated_by'] = \Auth::user()->id; $cycles->fill($cycle)->save(); $cycle_inventory_id = $cycles->id; for ($i = 0; $i < count($inputs['product_id']); $i++) { if ($inputs['amount'][$i] != "") { // To save sale order detail table $cycleProduct = new CycleProductDetail(); $cycleProduct['cycle_inventory_id'] = $cycle_inventory_id; $cycleProduct['product_id'] = $inputs['product_id'][$i]; $cycleProduct['current_qty'] = $inputs['current_qty'][$i]; if ($inputs['actions'][$i] == 0) { // actions = 1 it mean add stock $cycleProduct['new_qty'] = $inputs['current_qty'][$i] + $inputs['amount'][$i]; $cycleProduct['actions'] = 0; } else { // actions = 1 it mean update stock $cycleProduct['new_qty'] = $inputs['amount'][$i]; $cycleProduct['actions'] = 1; } $cycleProduct['created_by'] = \Auth::user()->id; $cycleProduct['updated_by'] = \Auth::user()->id; $cycleProduct->save(); // condition to check if product is exist in inventory $fields = ['product_id' => $inputs['product_id'][$i], 'location_id' => Session::get('location_id')]; $checkIfSaleExistingProduct = InventoryTotal::where($fields)->first(); // Save to inventories table $inventory = new Inventory(); $inventory['cycle_inventory_id'] = $cycle_inventory_id; $inventory['product_id'] = $inputs['product_id'][$i]; $inventory['location_id'] = Session::get('location_id'); $inventory['qty'] = $inputs['amount'][$i]; if ($inputs['actions'][$i] == 0) { // actions = 1 it mean add stock $inventory['qty'] = $inputs['amount'][$i]; $inventory['actions'] = 0; } else { $inventory['qty'] = $inputs['amount'][$i] - $inputs['current_qty'][$i]; $inventory['actions'] = 1; } $inventory['date'] = $inputs['date']; $inventory['created_by'] = \Auth::user()->id; $inventory['updated_by'] = \Auth::user()->id; $inventory->save(); if (count($checkIfSaleExistingProduct) > 0) { //for existing product in inventory // Save to inventory_totals table $inventoryTotals = new InventoryTotal(); $inventoryTotal = array(); if ($inputs['actions'][$i] == 0) { // actions = 1 it mean add stock $inventoryTotal['total_qty'] = $checkIfSaleExistingProduct['total_qty'] + $inputs['amount'][$i]; } else { $inventoryTotal['total_qty'] = $inputs['amount'][$i]; } $inventoryTotal['created_by'] = \Auth::user()->id; $inventoryTotal['updated_by'] = \Auth::user()->id; $inventoryTotals->where($fields)->update($inventoryTotal); // Save to inventory_total_details table $inventoryTotalDetails = new InventoryTotalDetail(); $inventoryTotalDetail = array(); $fieldNews = ['product_id' => $inputs['product_id'][$i], 'location_id' => Session::get('location_id'), 'date' => $inputs['date']]; $checkIfCycleExistingProduct = InventoryTotalDetail::where($fieldNews)->first(); if ($inputs['actions'][$i] == 0) { // actions = 1 it mean add stock $inventoryTotalDetail['total_cycle'] = $checkIfCycleExistingProduct['total_cycle'] + $inputs['amount'][$i]; } else { $inventoryTotalDetail['total_cycle'] = $checkIfCycleExistingProduct['total_cycle'] + ($inputs['amount'][$i] - $inputs['current_qty'][$i]); } $inventoryTotalDetail['created_by'] = \Auth::user()->id; $inventoryTotalDetail['updated_by'] = \Auth::user()->id; $inventoryTotalDetails->where($fieldNews)->update($inventoryTotalDetail); } else { // for a new product in inventory // Save to inventory_totals table $inventoryTotal = new InventoryTotal(); $inventoryTotal['product_id'] = $inputs['product_id'][$i]; $inventoryTotal['location_id'] = Session::get('location_id'); $inventoryTotal['total_qty'] = $inputs['amount'][$i]; $inventoryTotal->save(); // Save to inventory_total_details table $inventoryTotalDetail = new InventoryTotalDetail(); $inventoryTotalDetail['product_id'] = $inputs['product_id'][$i]; $inventoryTotalDetail['location_id'] = Session::get('location_id'); $inventoryTotalDetail['total_cycle'] = $inputs['amount'][$i]; $inventoryTotalDetail['date'] = $inputs['date']; $inventoryTotalDetail->save(); } } } // update list of inventory when process save inventory completed $qty = Input::get('qty'); if ($qty == 1) { $inventory = Product::select('products.id AS product_id', 'products.name', 'products.code', 'pgroups.name AS product_group', 'total_qty')->leftJoin('inventory_totals', 'inventory_totals.product_id', '=', 'products.id')->join('pgroups', 'pgroups.id', '=', 'pgroup_id')->where('products.is_active', 1)->where('products.is_stock', 1)->where('total_qty', '>', 0)->orderBy('pgroups.name', 'ASC')->orderBy('products.name', 'ASC')->get(); } else { if ($qty <= 0 && $qty != "") { $inventory = Product::select('products.id AS product_id', 'products.name', 'products.code', 'pgroups.name AS product_group', 'total_qty')->leftJoin('inventory_totals', 'inventory_totals.product_id', '=', 'products.id')->join('pgroups', 'pgroups.id', '=', 'pgroup_id')->where('products.is_active', 1)->where('products.is_stock', 1)->where(function ($query) { $query->where('total_qty', '<', 0)->orWhere('total_qty', null); })->orderBy('pgroups.name', 'ASC')->orderBy('products.name', 'ASC')->get(); } else { $inventory = Product::select('products.id AS product_id', 'products.name', 'products.code', 'pgroups.name AS product_group', 'total_qty')->leftJoin('inventory_totals', 'inventory_totals.product_id', '=', 'products.id')->join('pgroups', 'pgroups.id', '=', 'pgroup_id')->where('products.is_active', 1)->where('products.is_stock', 1)->orderBy('pgroups.name', 'ASC')->orderBy('products.name', 'ASC')->get(); } } return Response::json($inventory); }