public function anyImportPrice(){ set_time_limit(0); \Excel::load('gia.xls', function($reader) { $results = $reader->get(); foreach ($results as $row) { $row = $row->toArray(); $sku = $row['sku']; $product = Product::where('sku','=',$sku)->first(); $mproducts = MProduct::where('product_id','=',$product->id) ->where(function ($query){ $query->where('module_type','in_stock') ->orwhere('module_type','App\\Purchaseorder'); }) ->get(); foreach ($mproducts as $key => $value) { $sell_price = new SellPrice; $sell_price->name = "Giá hot cấp 2"; $sell_price->price = intval($row['gia_hot_cap_2']); $sell_price->product_id = $product->id; $sell_price->m_product_id = $value->id; $sell_price->save(); } } }); echo "done"; die; }
public function postDeleteProduct(Request $request){ $arr_return= array('status'=>'error'); $id = $request->has('id')?$request->input('id'):0; if($id){ $mproduct = MProduct::find($id); $id_product = $mproduct->m_product_id; $quantity = $mproduct->quantity; $specification = $mproduct->specification; $check = MProduct::where('id','=',$id)->delete(); if($check){ // $product = ProductStock::find($id_product); // $product->in_stock = $product->in_stock + $quantity*$specification; // $product->save(); $product = Product::find($mproduct->product_id); Log::create_log(\Auth::user()->id,'App\ReturnPurchaseorder','Xóa sản phẩm '.$product->sku.' đơn hàng trả nhà cung cấp số '.session('current_returnpurchaseorder')); $arr_return['status'] = 'success'; }else{ $arr_return['message'] = 'Saving fail !'; } } $returnpurchaseorder = ReturnPurchaseorder::find(session('current_returnpurchaseorder')); $returnpurchaseorder->updated_by = \Auth::user()->id; $returnpurchaseorder->save(); self::getListProduct(); return $arr_return; }