/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, $orderID) { // create the new Order $inventory = new Inventory(); $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 added'); session()->flash('message-type', 'success'); return redirect()->action('InventoryController@show', [$order->id, $inventory->id]); }
protected function insertItem($conferenceId, $data) { $item = new Inventory(); $item->totalQuantity = $data['totalQuantity']; // $item->units = $data['units']; $item->itemName = $data['itemName']; $item->disposable = $data['disposable']; $item->conferenceID = $conferenceId; $item->save(); }
public function postCreate(Request $request) { $this->validate($request, ['title' => 'required|max:100']); $item = new Inventory(); $item->title = $request->title; $item->quantity = $request->quantity; $item->description = $request->description; $item->save(); return redirect('/category/inventories'); }
/** * 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'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $messages = ['required' => 'This field MUST not be empty.', 'unique' => 'The data EXISTED already.']; $rules = ['drug_name' => 'required', 'drug_lowlimit' => 'required', 'dateOfPurchase' => 'required', 'dateOfExpiry' => 'required', 'drug_supplier' => 'required', 'unitsOnHand' => 'required']; $validation = Validator::make($request->all(), $rules, $messages); if ($validation->fails()) { return redirect()->back()->withErrors($validation)->withInput($request->all()); } //data input $dName = $request->input('drug_name'); $dLow = $request->input('drug_lowlimit'); $dType = $request->input('drug_type'); $dRemarks = $request->input('drug_remarks'); $dPreCau = $request->input('drug_precaution'); $dDPur = $request->input('dateOfPurchase'); $dDExp = $request->input('dateOfExpiry'); $dSupp = $request->input('drug_supplier'); $suppID = Supplier::where('supp_name', $dSupp)->first(); //change name to ID $dInt = $request->input('intakeTime'); $dFreq = $request->input('frequency'); $dSpu = $request->input('spu'); $dUnitHnd = $request->input('unitsOnHand'); // $d_data = Supplier::find($dSupp); // $supp_id = $d_data->id; $inventory = new Inventory(); $inventory->drug_name = $dName; $inventory->drug_lowlimit = $dLow; $inventory->drug_type = $dType; $inventory->drug_remarks = $dRemarks; $inventory->drug_precaution = $dPreCau; $inventory->dateOfPurchase = $dDPur; $inventory->dateOfExpiry = $dDExp; $inventory->drug_supplier = $suppID->id; $inventory->intakeTime = $dInt; $inventory->frequency = $dFreq; $inventory->spu = $dSpu; $inventory->unitsOnHand = $dUnitHnd; $inventory->save(); Alert::success('Successfully added!')->persistent("Close")->autoclose(2000); return redirect()->action('InvController@index'); }
/** * 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); }
/** * 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'); }
/** * 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 saveInventory(Request $request) { $data = $request->all(); // Handle the type of disc added to inventory if ($data['type'] == 'DVD') { $data['dvd'] = 1; } if ($data['type'] == 'BluRay') { $data['bluRay'] = 1; } unset($data['type']); $qty = $data['quantity']; unset($data['quantity']); // Save each instance of inventory for ($i = 0; $i < $qty; $i++) { $inv = new Inventory(); $inv->fill($data); $inv->save(); } // dd($request->all()); return redirect('/kiosks/addInventory'); }
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']); // To save sale order table $exchangerate = DB::table('exchange_rates')->orderBy('id', 'desc')->first(); $rate = $exchangerate->riel; $saleOrder = array(); //$saleOrder['_token'] = $inputs['_token']; $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['updated_by'] = \Auth::user()->id; $saleOrders->whereId($inputs['sales_order_id'])->update($saleOrder); $sale_order_id = $inputs['sales_order_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'] = \Auth::user()->id; $saleOrderReceipt['updated_by'] = \Auth::user()->id; $saleOrderReceipt['is_active'] = 1; $saleOrderReceipts->where('sales_order_id', $sale_order_id)->update($saleOrderReceipt); $products = SaleOrderDetail::whereSalesOrderId($sale_order_id)->get(); // Update old qty inventoryTotalDetail and InventoryTotal $location = Session::get('location_id'); foreach ($products as $product) { $fields = ['product_id' => $product->product_id, 'location_id' => Session::get('location_id')]; $checkIfSaleExistingProducts = InventoryTotal::where($fields)->first(); $inventoryTotalDetail = $inventoryTotals = array(); $inventoryTotals = new InventoryTotal(); $inventoryTotal['total_qty'] = $checkIfSaleExistingProducts['total_qty'] + $product->qty * $product->conversion; $inventoryTotal['updated_by'] = \Auth::user()->id; $inventoryTotals->where($fields)->update($inventoryTotal); $inventoryTotalDetails = new InventoryTotalDetail(); $fieldNews = ['product_id' => $product->product_id, 'location_id' => Session::get('location_id')]; $checkIfSaleExistingProductInventoryDetail = InventoryTotalDetail::where($fieldNews)->first(); $inventoryTotalDetail['total_pos'] = $checkIfSaleExistingProductInventoryDetail['total_qty'] - $product->qty * $product->conversion; $inventoryTotalDetail['updated_by'] = \Auth::user()->id; $inventoryTotalDetails->where($fieldNews)->update($inventoryTotalDetail); } // Delete old saleOrderDetail $saleOrderDetails::whereSalesOrderId($sale_order_id)->delete(); // 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(); } // Delete inventory by sales_order_id Inventory::wherePointOfSalesId($sale_order_id)->delete(); // Save to inventory for ($k = 0; $k < count($inputs['id']) - 1; $k++) { $fields = ['product_id' => $inputs['id'][$k], 'location_id' => $location]; $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'] = $location; $inventory['qty'] = $inputs['txt_qty'][$k]; $inventory['sale_price'] = $inputs['txt_unit_price'][$k]; $inventory['date'] = date('Y-m-d'); $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(); $inventoryTotal['total_qty'] = $checkIfSaleExistingProduct['total_qty'] - $inputs['txt_qty'][$k]; $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['id'][$k], 'location_id' => $location, 'date' => date('Y-m-d')]; $checkIfSaleExistingProductInventoryDetail = InventoryTotalDetail::where($fieldNews)->first(); $inventoryTotalDetail['total_pos'] = $checkIfSaleExistingProductInventoryDetail['total_qty'] - $inputs['txt_qty'][$k]; $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['id'][$k]; $inventoryTotal['location_id'] = $location; $inventoryTotal['total_qty'] = -1 * $inputs['txt_qty'][$k]; $inventoryTotal['created_by'] = \Auth::user()->id; $inventoryTotal['updated_by'] = \Auth::user()->id; $inventoryTotal->save(); // Save to inventory_total_details table $inventoryTotalDetail = new InventoryTotalDetail(); $inventoryTotalDetail['product_id'] = $inputs['id'][$k]; $inventoryTotalDetail['location_id'] = $location; $inventoryTotalDetail['total_pos'] = -1 * $inputs['txt_qty'][$k]; $inventoryTotalDetail['date'] = date('Y-m-d'); $inventoryTotalDetail['created_by'] = \Auth::user()->id; $inventoryTotalDetail['updated_by'] = \Auth::user()->id; $inventoryTotalDetail->save(); } } echo $sale_order_id; exit; }
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); }