public function postUpdateMproduct(Request $request){ $arr_return= array('status'=>'error','amount'=>0); $id = $request->has('id')?$request->input('id'):0; $log=""; if($id){ $mproduct = MProduct::find($id); $mproduct_po = Mproduct::find($mproduct->m_product_id); $mproduct_so = Mproduct::find($mproduct->m_product_id_so); $mproduct_rso_before = Mproduct::where('m_product_id_so','=',$mproduct_so->id) ->where('module_type','=','App\\ReturnSaleorder') ->where('company_id','=',$mproduct->company_id) ->get(); $mproduct_so->con_lai = $mproduct_so->quantity * $mproduct_so->specification; foreach ($mproduct_rso_before as $key => $value) { $mproduct_so->con_lai -= $value->quantity * $value->specification; } $so_luong_con = $mproduct_so->con_lai; if($request->has('oum_id') && $mproduct->oum_id != $request->input('oum_id')){ $old = Oum::find($mproduct->oum_id); $new = Oum::find($request->input('oum_id')); if($old){ $log .= 'đơn vị từ "'.$old->name.'" thành "'.$new->name.'" '; }else{ $log .= 'đơn vị từ " " thành "'.$new->name.'" '; } } if($request->has('sell_price') && $mproduct->sell_price != $request->input('sell_price')){ $log .= 'giá bán từ "'.$mproduct->sell_price.'" thành "'.$request->input('sell_price').'" '; } if($request->has('specification') && $mproduct->specification != $request->input('specification')){ $log .= 'quy cách từ "'.$mproduct->specification.'" thành "'.$request->input('specification').'" '; } if($request->has('quantity') && $mproduct->quantity != $request->input('quantity')){ $log .= 'số lượng từ "'.$mproduct->quantity.'" thành "'.$request->input('quantity').'" '; } $mproduct->oum_id = $request->has('oum_id')?$request->input('oum_id'):0; $mproduct->sell_price = $request->has('sell_price')?$request->input('sell_price'):0; $mproduct->specification = $request->has('specification')?$request->input('specification'):0; $old_quantity = $mproduct->quantity ; $mproduct->quantity = $request->has('quantity')?$request->input('quantity'):0; $check_return = ($mproduct_so->con_lai - $mproduct->quantity*$mproduct->specification) >=0; $mproduct->origin_price = $mproduct_so->origin_price; $mproduct->amount = $mproduct->specification* $mproduct->quantity* $mproduct->sell_price; $mproduct->invest = $mproduct->specification* $mproduct->quantity* $mproduct->origin_price; // if($product_stock->in_stock >=0){ if( $check_return ){ if($mproduct->save()){ $product = Product::find($mproduct->product_id); Log::create_log(\Auth::user()->id,'App\ReturnSaleorder','cập nhật '.$log.' sản phẩm '.$product->sku.' đơn hàng đại lý trả số '.session('current_returnsaleorder')); $arr_return['status'] = 'success'; $arr_return['amount'] = number_format( $mproduct->amount ); }else{ $arr_return['message'] = 'Saving fail !'; } }else{ $arr_return['message'] = 'Số lượng sản phẩm trả về lớn hơn số lượng còn lại trong kho <br/> Số lượng còn lại trong kho là '.$so_luong_con.' cái'; } // }else{ // $arr_return['message'] = 'Số lượng trả hàng lớn hơn số lượng đã bán'; // } } //Init array $list_product = array(); //Get value $returnsaleorder = ReturnSaleorder::find(session('current_returnsaleorder')); $list_product = MProduct::select('m_products.*','products.sku','products.name')->where('module_type','=','App\ReturnSaleorder') ->where('module_id','=',$id) ->where('company_id','=',$returnsaleorder['company_id']) ->leftJoin('products','products.id','=','m_products.product_id') ->addSelect('oums.name as oum_name') ->leftJoin('oums','oums.id','=','m_products.oum_id') ->get()->toArray(); \Cache::put('list_product_rso'.\Auth::user()->id, $list_product, 30); $returnsaleorder->updated_by = \Auth::user()->id; $returnsaleorder->save(); self::getListProduct(); return $arr_return; }
public function postUpdateMproduct(Request $request){ $arr_return= array('status'=>'error','invest'=>0); $id = $request->has('id')?$request->input('id'):0; $log=""; if($id){ $mproduct = MProduct::find($id); $mproduct_po = Mproduct::find($mproduct->m_product_id); if($request->has('oum_id') && $mproduct->oum_id != $request->input('oum_id')){ $old = Oum::find($mproduct->oum_id); $new = Oum::find($request->input('oum_id')); if($old){ $log .= 'đơn vị từ "'.$old->name.'" thành "'.$new->name.'" '; }else{ $log .= 'đơn vị từ " " thành "'.$new->name.'" '; } } if($request->has('sell_price') && $mproduct->sell_price != $request->input('sell_price')){ $log .= 'giá bán từ "'.$mproduct->sell_price.'" thành "'.$request->input('sell_price').'" '; } if($request->has('specification') && $mproduct->specification != $request->input('specification')){ $log .= 'quy cách từ "'.$mproduct->specification.'" thành "'.$request->input('specification').'" '; } if($request->has('quantity') && $mproduct->quantity != $request->input('quantity')){ $log .= 'số lượng từ "'.$mproduct->quantity.'" thành "'.$request->input('quantity').'" '; } $mproduct->oum_id = $request->has('oum_id')?$request->input('oum_id'):0; $mproduct->origin_price = $request->has('origin_price')?$request->input('origin_price'):0; $mproduct->specification = $request->has('specification')?$request->input('specification'):0; $old_quantity = $mproduct->quantity ; $mproduct->quantity = $request->has('quantity')?$request->input('quantity'):0; $product_stock = ProductStock::where('m_product_id','=',$mproduct_po->id)->first(); $so_luong_con = $product_stock->in_stock; $product_stock->in_stock = $product_stock->in_stock - ($mproduct->quantity*$mproduct->specification); $mproduct->invest = $mproduct->specification* $mproduct->quantity* $mproduct->origin_price; if($product_stock->in_stock >=0){ if( !$mproduct->status){ if($mproduct->save()){ $product = Product::find($mproduct->product_id); Log::create_log(\Auth::user()->id,'App\ReturnPurchaseorder','cập nhật '.$log.' sản phẩm '.$product->sku.' đơn hàng trả nhà cung cấp số '.session('current_returnpurchaseorder')); $arr_return['status'] = 'success'; $arr_return['invest'] = number_format( $mproduct->invest ); }else{ $arr_return['message'] = 'Saving fail !'; } }else{ $arr_return['message'] = 'Đơn hàng đã hoàn thành không thể cập nhật'; } }else{ $arr_return['message'] = 'Số lượng trả '.$mproduct->name.' lớn hơn số lượng đã nhập<br/> Số lượng đã nhập là '.$so_luong_con.' cái'; } } $id = session('current_returnpurchaseorder'); //Init array $list_product = array(); //Get value $returnpurchaseorder = ReturnPurchaseorder::find(session('current_returnpurchaseorder')); $list_product = MProduct::select('m_products.*','products.sku','products.name')->where('module_type','=','App\ReturnPurchaseorder') ->where('module_id','=',$id) ->where('company_id','=',$returnpurchaseorder['company_id']) ->leftJoin('products','products.id','=','m_products.product_id') ->addSelect('oums.name as oum_name') ->leftJoin('oums','oums.id','=','m_products.oum_id') ->get()->toArray(); \Cache::put('list_product_rpo'.\Auth::user()->id, $list_product, 30); $returnpurchaseorder->updated_by = \Auth::user()->id; $returnpurchaseorder->save(); self::getListProduct(); return $arr_return; }
public function getDeleteOum($id) { $arr_return = array( "status"=>"error" ); $oum = Oum::find($id); if($oum->delete()){ $arr_return['status'] = 'success'; }else{ $arr_return['message']= "Delete fail"; } return $arr_return; }