public function anyAddProduct(Request $request){ $arr_return = array( "status"=>'success' ); $company_id = $request->has('company_id')?$request->input('company_id'):0; $module_id = session('current_returnpurchaseorder'); $module_type = 'App\ReturnPurchaseorder'; $arr_product = session('product_of_rpo'.session('current_returnpurchaseorder')); $arr_product_of_rpo = Mproduct::where('module_id','=',$module_id) ->where('module_type','=',$module_type) ->lists('m_product_id'); $log = ""; foreach ($arr_product as $key => $m_product_id) { if(!in_array($m_product_id, $arr_product_of_rpo)){ $product = MProduct::find($m_product_id); $mproduct = new MProduct; $mproduct->product_id = $product->product_id; $mproduct->m_product_id = $product->id; $mproduct->module_id = $module_id; $mproduct->company_id = $product->company_id; $mproduct->module_type = $module_type; $mproduct->specification = $product->specification; $mproduct->oum_id = $product->oum_id; $mproduct->origin_price = $product->origin_price; $mproduct->save(); $product = Product::find($mproduct->product_id); if($log==""){ $log .= "Thêm sản phẩm ".$product->sku; }else{ $log .= ", ".$product->sku; } } } $log_delete = ""; foreach ($arr_product_of_rpo as $key => $m_product_id) { if(!in_array($m_product_id, $arr_product)){ $mproduct = MProduct::where('module_id','=',$module_id) ->where('module_type','=',$module_type) ->where('m_product_id','=',$m_product_id)->first()->toArray(); $m_product_id_delete = $mproduct['m_product_id']; $quantity = $mproduct['quantity']; $check = MProduct::where('module_id','=',$module_id) ->where('module_type','=',$module_type) ->where('m_product_id','=',$m_product_id_delete)->delete(); $product = Product::find($mproduct['product_id']); if($log==""){ $log .= "xóa sản phẩm ".$product->sku; }else{ $log .= ", ".$product->sku; } } } if($log_delete !="") Log::create_log(\Auth::user()->id,'App\ReturnPurchaseorder',$log.' và .'.$log_delete.' đơn hàng trả nhà cung cấp số '.session('current_returnpurchaseorder')); else Log::create_log(\Auth::user()->id,'App\ReturnPurchaseorder',$log.' vào đơn hàng trả nhà cung cấp số '.session('current_returnpurchaseorder')); $returnpurchaseorder = ReturnPurchaseorder::find(session('current_returnpurchaseorder')); $returnpurchaseorder->updated_by = \Auth::user()->id; $returnpurchaseorder->save(); self::getListProduct(); return $arr_return; }
public function anyImportProduct(){ \Excel::load('kho-2015.xls', function($reader) { $results = $reader->get(); $company = Company::getDistributeList()->get()->toArray(); $arr_company = array(); foreach ($company as $key => $value) { $arr_company[$value['name']] = $value['id']; } // pr($arr_company);die; $arr_oum = array(); $oums = Oum::orderBy('name')->get()->toArray(); foreach ($oums as $key => $value) { $arr_oum[$value['name']] = $value['id']; } foreach ($results as $row) { $product = new Product; $product->name = $row['ten_san_pham']; $product->sku = $row['sku']; // $name_product = $row['ten_san_pham']; // $check1 = is_numeric(mb_strpos($name_product, "Áo")); // $check2 = is_numeric(mb_strpos($name_product, 'Váy')); // $check3 = is_numeric(mb_strpos($name_product, 'Quần')); // $check3 = is_numeric(mb_strpos($name_product, 'Đầm')); // $check4 = is_numeric(mb_strpos($name_product, 'Bộ')) && is_numeric(mb_strpos($name_product, 'ton')); // $check5 = is_numeric(mb_strpos($name_product, 'Bộ')) && is_numeric(mb_strpos($name_product, 'bo')); // $check6 = is_numeric(mb_strpos($name_product, 'Bộ')) && is_numeric(mb_strpos($name_product, 'thun')); // $check = $check1 || $check2 || $check3 || $check4 || $check5 || $check6; if($row['loai_san_pham'] == "Đồ dùng"){ $product->product_type = 2; }else{ $product->product_type = 1; } $product->status=0; $product->created_by = \Auth::user()->id; if($product->save()){ $mproduct = new MProduct; $mproduct->product_id = $product->id; $mproduct->module_id = 0; $mproduct->company_id = $arr_company[$row['nha_cung_cap']]; $mproduct->module_type = 'in_stock'; $mproduct->specification = $row['quy_cach']; $mproduct->oum_id = $arr_oum[$row['don_vi_ban']]; $mproduct->origin_price = intval(str_replace(",","",$row['gia_goc'])); $mproduct->quantity = $row['so_luong']; $mproduct->invest = intval(str_replace(",","",$row['gia_goc']))*intval($row['so_luong'])*intval($row['quy_cach']); if($mproduct->save()){ Product::where('id','=',$product->id)->update(['check_in_stock'=>1]); if(intval($row['gia_npp'])>0){ $sell_price = new SellPrice; $sell_price->name = "Giá NPP"; $sell_price->price = intval($row['gia_npp']); $sell_price->product_id = $product->id; $sell_price->m_product_id = $mproduct->id; $sell_price->save(); } if(intval($row['dai_ly'])>0){ $sell_price = new SellPrice; $sell_price->name = "Giá đại lý"; $sell_price->price = intval($row['dai_ly']); $sell_price->product_id = $product->id; $sell_price->m_product_id = $mproduct->id; $sell_price->save(); } if(intval($row['shop'])>0){ $sell_price = new SellPrice; $sell_price->name = "Giá bán shop"; $sell_price->price = intval($row['shop']); $sell_price->product_id = $product->id; $sell_price->m_product_id = $mproduct->id; $sell_price->save(); } if(intval($row['ban_le'])>0){ $sell_price = new SellPrice; $sell_price->name = "Giá bán lẻ"; $sell_price->price = intval($row['ban_le']); $sell_price->product_id = $product->id; $sell_price->m_product_id = $mproduct->id; $sell_price->save(); } } } } echo "Done"; die; }); }
public function anyAddProduct(Request $request){ $arr_return = array( "status"=>'success' ); $id = $request->has('id')?$request->input('id'):0; $company_id = $request->has('company_id')?$request->input('company_id'):0; $module_id = session('current_purchaseorder'); $module_type = 'App\Purchaseorder'; $arr_product = session('product_of_po'.session('current_purchaseorder')); $arr_product_of_po = Mproduct::where('module_id','=',$module_id) ->where('module_type','=',$module_type) ->lists('product_id'); $log = ""; foreach ($arr_product as $key => $product_id) { if(!in_array($product_id, $arr_product_of_po)){ $product = Product::find($product_id); $last_mproduct = Mproduct::where('product_id','=',$product_id)->get()->last(); $mproduct = new MProduct; $mproduct->company_id = $company_id; $mproduct->product_id = $product_id; $mproduct->module_id = $module_id; $mproduct->id = $id; $mproduct->module_type = $module_type; if($last_mproduct){ $mproduct->specification = $last_mproduct->specification; $mproduct->oum_id = $last_mproduct->oum_id; $mproduct->origin_price = $last_mproduct->origin_price; }else{ $mproduct->specification = 0; $mproduct->oum_id = 0; $mproduct->origin_price = 0; } $mproduct->save(); $last_sellprice = SellPrice::where('product_id','=',$product_id)->orderBy('m_product_id','desc')->first(); if($last_sellprice){ $arr_sellprice = SellPrice::where('m_product_id','=',$last_sellprice->m_product_id)->get()->toArray(); foreach ($arr_sellprice as $key => $value) { $sellprice = new SellPrice; $sellprice->name = $value['name']; $sellprice->price = $value['price']; $sellprice->m_product_id = $mproduct->id; $sellprice->product_id = $value['product_id']; $sellprice->save(); } } if(!$product->check_in_stock){ $product->check_in_stock = 1; $product->save(); } if($log==""){ $log .= "Thêm sản phẩm ".$product->sku; }else{ $log .= ", ".$product->sku; } } } $log_delete = ""; foreach ($arr_product_of_po as $key => $product_id) { if(!in_array($product_id, $arr_product)){ $product = Product::find($product_id); $mproduct = MProduct::where('module_id','=',$module_id) ->where('module_type','=',$module_type) ->where('product_id','=',$product_id)->first()->toArray(); $id_product = $mproduct['product_id']; $quantity = $mproduct['quantity']; $check = MProduct::where('module_id','=',$module_id) ->where('module_type','=',$module_type) ->where('product_id','=',$product_id)->delete(); if($check){ $product_stock = ProductStock::where('m_product_id','=',$mproduct['id'])->delete(); } if($log==""){ $log .= "xóa sản phẩm ".$product->sku; }else{ $log .= ", ".$product->sku; } } } if($log_delete !="") Log::create_log(\Auth::user()->id,'App\Purchaseorder',$log.' và .'.$log_delete.' đơn hàng đại lý trả số '.session('current_purchaseorder')); else Log::create_log(\Auth::user()->id,'App\Purchaseorder',$log.'vào đơn hàng mua số '.session('current_purchaseorder')); $purchaseorder = Purchaseorder::find(session('current_purchaseorder')); $purchaseorder->updated_by = \Auth::user()->id; $purchaseorder->save(); self::getListProduct(); return $arr_return; }