Browse Source

product waste in cashier

Jose Miguel Ledon Nieblas 8 years ago
parent
commit
d9e8c4c399
3 changed files with 43 additions and 54 deletions
  1. 18 27
      app/controllers/product_wastes_controller.rb
  2. 22 27
      app/models/ability.rb
  3. 3 0
      config/navigation.rb

+ 18 - 27
app/controllers/product_wastes_controller.rb

@@ -6,7 +6,7 @@ class ProductWastesController < ApplicationController
 
   ##--- Breadcrum_rails
   add_breadcrumb I18n.t("breadcrumbs." + controller_name), :product_wastes_path
-  add_breadcrumb "Nueva merma de productos" , :new_product_waste_path, only: :new
+  add_breadcrumb "Nueva merma de productos", :new_product_waste_path, only: :new
 
   before_action :set_pos_config, only: [:show, :edit, :update, :destroy]
 
@@ -15,17 +15,15 @@ class ProductWastesController < ApplicationController
   def index
     if current_user.usertype == 'A'
       @product_wastes = ProductWaste.includes(:product, :user, :pointsale, :warehouse).activos
-    elsif current_user.usertype == 'G'
-      @product_wastes = ProductWaste.includes(:product, :user).where(:pointsale_id => current_user.pointsale_id).activos
+    elsif current_user.usertype == 'G' || current_user.usertype == 'C'
+      @product_wastes = ProductWaste.includes(:product, :user).where(pointsale_id: current_user.pointsale_id).activos
     elsif current_user.usertype == 'S'
-      @product_wastes = ProductWaste.includes(:product, :user).where(:warehouse_id => current_user.warehouse_id).activos
+      @product_wastes = ProductWaste.includes(:product, :user).where(warehouse_id: current_user.warehouse_id).activos
     end
   end
 
   # GET /product_wastes/new
-  def new
-  end
-
+  def new; end
 
   # POST /product_wastes
   # POST /product_wastes.json
@@ -37,12 +35,10 @@ class ProductWastesController < ApplicationController
 
       if current_user.usertype == 'S'
         @product_waste.warehouse_id = current_user.warehouse_id
-        @stock = WarehouseStock.find_by(:warehouse_id => @product_waste.warehouse_id,
-        :product_id => @product_waste.product_id)
+        @stock = WarehouseStock.find_by(warehouse_id: @product_waste.warehouse_id, product_id: @product_waste.product_id)
       else
         @product_waste.pointsale_id = current_user.pointsale_id
-        @stock = AvailableProduct.find_by(:pointsale_id => @product_waste.pointsale_id,
-        :product_id => @product_waste.product_id)
+        @stock = AvailableProduct.find_by(pointsale_id: @product_waste.pointsale_id, product_id: @product_waste.product_id)
       end
       if @stock.stock >= @product_waste.quantity
         @product_waste.audit_comment = "Merma del producto #{@product_waste.product.name}  creada"
@@ -79,14 +75,8 @@ class ProductWastesController < ApplicationController
   def destroy
     respond_to do |format|
       @product_waste.audit_comment = "Merma del producto #{@product_waste.product.name}  eliminada."
-      if @product_waste.update_attributes(:status => :inactive)
-        if current_user.usertype == "S"
-          @stock = WarehouseStock.find_by(:warehouse_id => @product_waste.warehouse_id,
-          :product_id => @product_waste.product_id)
-        else
-          @stock = AvailableProduct.find_by(:pointsale_id => @product_waste.pointsale_id,
-          :product_id => @product_waste.product_id)
-        end
+      if @product_waste.update_attributes(status: :inactive)
+        @stock = current_user.usertype == "S" ? WarehouseStock.find_by(warehouse_id: @product_waste.warehouse_id, product_id: @product_waste.product_id) : AvailableProduct.find_by(pointsale_id: @product_waste.pointsale_id, product_id: @product_waste.product_id)
         @stock.stock = @stock.stock + @product_waste.quantity
         @stock.save
 
@@ -99,13 +89,14 @@ class ProductWastesController < ApplicationController
   end
 
   private
-    # Use callbacks to share common setup or constraints between actions.
-    def set_product_waste
-      @product_waste = ProductWaste.find(params[:id])
-    end
 
-    # Never trust parameters from the scary internet, only allow the white list through.
-    def product_waste_params
-      params.require(:product_waste).permit(:warehouse_id, :pointsale_id, :product_id, :quantity, :reason, :status)
-    end
+  # Use callbacks to share common setup or constraints between actions.
+  def set_product_waste
+    @product_waste = ProductWaste.find(params[:id])
+  end
+
+  # Never trust parameters from the scary internet, only allow the white list through.
+  def product_waste_params
+    params.require(:product_waste).permit(:warehouse_id, :pointsale_id, :product_id, :quantity, :reason, :status)
+  end
 end

+ 22 - 27
app/models/ability.rb

@@ -11,12 +11,12 @@ class Ability
     #     can :read, :all
     #   end
     #
-    # The first argument to `can` is the action you are giving the user 
+    # The first argument to `can` is the action you are giving the user
     # permission to do.
     # If you pass :manage it will apply to every action. Other common actions
     # here are :read, :create, :update and :destroy.
     #
-    # The second argument is the resource the user can perform the action on. 
+    # The second argument is the resource the user can perform the action on.
     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
     # class of the resource.
     #
@@ -28,41 +28,36 @@ class Ability
     #
     # See the wiki for details:
     # https://github.com/ryanb/cancan/wiki/Defining-Abilities
-    alias_action :create, :read, :update,  :to => :cru
-    
+    alias_action :create, :read, :update, to: :cru
+
     user ||= User.new
-    
-    if user.usertype == "A"
-        # Cajas registradoras
-        can :read, [CashRegister, Purchase, PaymentMethod, ProductsReturn]
-        # Categorías
 
-        can :manage, [Category, Customer, BillingInformation, Expensesconcept, Pointsale, Product, 
-            Supplier, Unit, Sale, PosConfig, Purchase, SpecialPrice, ProductWaste, Seller, CashOut, 
-            Transfer, Expense, User, Warehouse, Commission, Sellerscommission]
+    if user.usertype == "A"
+      # Cajas registradoras
+      can :read, [CashRegister, Purchase, PaymentMethod, ProductsReturn]
+      # Categorias
+      can :manage, [Category, Customer, BillingInformation, Expensesconcept, Pointsale, Product, Supplier, Unit, Sale, PosConfig, Purchase, SpecialPrice, ProductWaste, Seller, CashOut, Transfer, Expense, User, Warehouse, Commission, Sellerscommission]
 
     elsif user.usertype == "G"
-        # Cajas registradoras
-        can :manage, [CashRegister, Purchase, Product, PrePurchase, Seller, Sale, Expense, ProductWaste, Transfer, OpenCashRegister, CashOut, Supplier, Customer, Credit, CreditPayment, Commission, Sellerscommission, ProductsReturn]
-
-        # Categorías
-        can :read, [Category, SpecialPrice, Expensesconcept, Credit, CreditPayment, Unit]
-        # Clientes
-        can :cru, [Customer, BillingInformation, Pointsale, User, Warehouse, Credit, CreditPayment, Commission, Sellerscommission]
+      # Cajas registradoras
+      can :manage, [CashRegister, Purchase, Product, PrePurchase, Seller, Sale, Expense, ProductWaste, Transfer, OpenCashRegister, CashOut, Supplier, Customer, Credit, CreditPayment, Commission, Sellerscommission, ProductsReturn]
+      # Categorias
+      can :read, [Category, SpecialPrice, Expensesconcept, Credit, CreditPayment, Unit]
+      # Clientes
+      can :cru, [Customer, BillingInformation, Pointsale, User, Warehouse, Credit, CreditPayment, Commission, Sellerscommission]
 
     elsif user.usertype == "C"
-        # Cajas registradoras
-        can :read, [Product, Pointsale, Customer, BillingInformation, Seller, SpecialPrice, Expensesconcept, Credit, CreditPayment]
-        # ventas
-        can :cru, [Credit, CreditPayment]
+      # Cajas registradoras
+      can :read, [Product, Pointsale, Customer, BillingInformation, Seller, SpecialPrice, Expensesconcept, Credit, CreditPayment]
+      # ventas
+      can :cru, [Credit, CreditPayment]
 
-        can :manage, [CashRegister, PreSale, OpenCashRegister, Sale, Customer, Credit, CreditPayment, CashOut, Expense, Transfer, ProductsReturn]
+      can :manage, [CashRegister, PreSale, OpenCashRegister, Sale, Customer, Credit, CreditPayment, CashOut, Expense, Transfer, ProductsReturn, ProductWaste]
 
     elsif user.usertype == "S"
-        can :read, [CashRegister, Product, Pointsale, Customer, BillingInformation, Seller, SpecialPrice, Expensesconcept]
+      can :read, [CashRegister, Product, Pointsale, Customer, BillingInformation, Seller, SpecialPrice, Expensesconcept]
 
-        can :manage, [Transfer, ProductWaste]
+      can :manage, [Transfer, ProductWaste]
     end
-
   end
 end

+ 3 - 0
config/navigation.rb

@@ -212,6 +212,9 @@ SimpleNavigation::Configuration.run do |navigation|
       # productos
       primary.item :products, { icon: "fa fa-fw fa-cubes", text: "Productos" }, products_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
         sub_nav.item :stock_by_pointsale, 'Existencias', stock_by_pointsale_path
+        sub_nav.item :divider_after_stock_by_pointsale, '#', divider: true
+        sub_nav.item :list_waste, 'Nueva merma de productos', new_product_waste_path
+        sub_nav.item :list_waste_of_products, 'Lista de mermas de productos', product_wastes_path
       end
       # ventas
       primary.item :sales, { icon: "fa fa-fw fa-money", text: "Ventas" }, sales_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|