Browse Source

bugfix in customer sales

jose miguel 8 years ago
parent
commit
b012ad47e6

+ 0 - 1
Gemfile

@@ -75,7 +75,6 @@ gem 'will_paginate'
 gem "font-awesome-rails"
 gem "font-awesome-rails"
 gem 'carrierwave', '>= 1.0.0.rc', '< 2.0'
 gem 'carrierwave', '>= 1.0.0.rc', '< 2.0'
 gem 'mini_magick'
 gem 'mini_magick'
-gem 'pdfjs_viewer-rails'
 
 
 # gem 'ajax-datatables-rails', git: 'git://github.com/antillas21/ajax-datatables-rails.git', branch: 'master'
 # gem 'ajax-datatables-rails', git: 'git://github.com/antillas21/ajax-datatables-rails.git', branch: 'master'
 # gem 'amcharts.rb'
 # gem 'amcharts.rb'

+ 12 - 3
app/controllers/cash_registers_moves_controller.rb

@@ -239,6 +239,10 @@ class CashRegistersMovesController < ApplicationController
 
 
   def save_when_is_credit(credit)
   def save_when_is_credit(credit)
     abono = @cash_registers_move.quantity
     abono = @cash_registers_move.quantity
+    abono_this_credit = abono >= credit.rest ? credit.rest : abono
+
+    # por si abonan dinero de mas, checar cuanto debe de ser de esta venta, y separarlo.
+    # @cash_registers_move.quantity = abono_this_credit
     @credit_payment = CreditPayment.new
     @credit_payment = CreditPayment.new
     @credit_payment.credit_id = credit.id
     @credit_payment.credit_id = credit.id
     @credit_payment.customer_id = credit.customer_id
     @credit_payment.customer_id = credit.customer_id
@@ -246,15 +250,16 @@ class CashRegistersMovesController < ApplicationController
     @credit_payment.status = :active
     @credit_payment.status = :active
     @credit_payment.date_payment = Date.today
     @credit_payment.date_payment = Date.today
     @credit_payment.user_id = current_user.id
     @credit_payment.user_id = current_user.id
+    # @credit_payment.quantity = abono_this_credit
+    @credit_payment.quantity = abono_this_credit
 
 
     if @credit_payment.save
     if @credit_payment.save
       @cash_registers_move.credit_payment_id = @credit_payment.id
       @cash_registers_move.credit_payment_id = @credit_payment.id
       @cash_registers_move.concept = :credit_payment
       @cash_registers_move.concept = :credit_payment
-      @debt = Credit.where(customer_id: credit.customer_id).sum(:rest)
+
       if abono >= credit.rest # si se paga mas del adeudo de este credito
       if abono >= credit.rest # si se paga mas del adeudo de este credito
         abono -= credit.rest
         abono -= credit.rest
 
 
-        # @debt = credit.rest
         credit.update_attributes(rest: 0)
         credit.update_attributes(rest: 0)
         @sale.update_attributes(status: :paid)
         @sale.update_attributes(status: :paid)
 
 
@@ -264,13 +269,17 @@ class CashRegistersMovesController < ApplicationController
           # rubocop:disable Metrics/BlockNesting
           # rubocop:disable Metrics/BlockNesting
           if nextcredit.first.present?
           if nextcredit.first.present?
             if abono <= nextcredit.first.rest
             if abono <= nextcredit.first.rest
+              next_credit_payment = CreditPayment.create(customer_id: credit.customer_id, credit_id: nextcredit.first.id, pointsale_id: credit.pointsale_id, quantity: abono, status: 0, date_payment: Date.today, user_id: current_user.id)
+              # next_credit_abono = @cash_registers_move.dup
+              # next_credit_abono.quantity = abono
+              # next_credit_abono.credit_payment_id = next_credit_payment.id
+              # next_credit_abono.save
               nextcredit.first.update_attributes(rest: nextcredit.first.rest - abono)
               nextcredit.first.update_attributes(rest: nextcredit.first.rest - abono)
               sale = Sale.find_by_id(nextcredit.first.sale_id)
               sale = Sale.find_by_id(nextcredit.first.sale_id)
               sale.update_attributes(status: :parcial)
               sale.update_attributes(status: :parcial)
               abono -= nextcredit.first.rest
               abono -= nextcredit.first.rest
             else
             else
               abono -= nextcredit.first.rest
               abono -= nextcredit.first.rest
-              # @debt = nextcredit.first.rest
               nextcredit.first.update_attributes(rest: 0)
               nextcredit.first.update_attributes(rest: 0)
               sale = Sale.find_by_id(nextcredit.sale_id)
               sale = Sale.find_by_id(nextcredit.sale_id)
               sale.update_attributes(status: :paid)
               sale.update_attributes(status: :paid)

+ 12 - 17
app/controllers/customers_controller.rb

@@ -7,8 +7,8 @@ class CustomersController < ApplicationController
   add_breadcrumb "Clientes deudores", :debtors_path, only: [:debtors, :customer_sales]
   add_breadcrumb "Clientes deudores", :debtors_path, only: [:debtors, :customer_sales]
   add_breadcrumb "Detalle de ventas de clientes deudores", :customer_sales_path, only: :customer_sales
   add_breadcrumb "Detalle de ventas de clientes deudores", :customer_sales_path, only: :customer_sales
   add_breadcrumb "Nuevo " + I18n.t("breadcrumbs." + controller_name).singularize, :new_customer_path, only: :new
   add_breadcrumb "Nuevo " + I18n.t("breadcrumbs." + controller_name).singularize, :new_customer_path, only: :new
-  add_breadcrumb "Detalle del " + I18n.t("breadcrumbs." + controller_name).singularize , :customer_path, only: :show
-  add_breadcrumb "Editar " + I18n.t("breadcrumbs." + controller_name).singularize , :edit_customer_path, only: :edit
+  add_breadcrumb "Detalle del " + I18n.t("breadcrumbs." + controller_name).singularize, :customer_path, only: :show
+  add_breadcrumb "Editar " + I18n.t("breadcrumbs." + controller_name).singularize, :edit_customer_path, only: :edit
 
 
   before_action :set_customer, only: [:show, :edit, :update, :destroy]
   before_action :set_customer, only: [:show, :edit, :update, :destroy]
   before_action :get_filters, only: [:index, :show, :edit, :new, :debtors, :customer_sales]
   before_action :get_filters, only: [:index, :show, :edit, :new, :debtors, :customer_sales]
@@ -20,7 +20,7 @@ class CustomersController < ApplicationController
   end
   end
 
 
   def debtors
   def debtors
-    @customers = Customer.includes(:sales, :credits).vigentes
+    @customers = Customer.where("customers.status != 0").includes(:sales, :credits).order('credits.id DESC')
   end
   end
 
 
   def customer_sales
   def customer_sales
@@ -52,8 +52,7 @@ class CustomersController < ApplicationController
   end
   end
 
 
   # GET /customers/1/edit
   # GET /customers/1/edit
-  def edit
-  end
+  def edit; end
 
 
   # POST /customers
   # POST /customers
   # POST /customers.json
   # POST /customers.json
@@ -96,7 +95,7 @@ class CustomersController < ApplicationController
     end
     end
     respond_to do |format|
     respond_to do |format|
       if customer.save(validate: false)
       if customer.save(validate: false)
-        format.html { redirect_to customers_url, warning: "El cliente " + customer.nick_name + " fue "+ (customer.active? ? "activado" : "desactivado") + "." }
+        format.html { redirect_to customers_url, warning: "El cliente " + customer.nick_name + " fue " + (customer.active? ? "activado" : "desactivado") + "." }
         format.json { head :no_content }
         format.json { head :no_content }
       else
       else
         format.html { redirect_to customers_url }
         format.html { redirect_to customers_url }
@@ -118,23 +117,19 @@ class CustomersController < ApplicationController
   end
   end
 
 
   private
   private
-    # Use callbacks to share common setup or constraints between actions.
-    def set_customer
-      @customer = Customer.find(params[:id])
-    end
+
+  # Use callbacks to share common setup or constraints between actions.
+  def set_customer
+    @customer = Customer.find(params[:id])
+  end
 
 
   def get_filters
   def get_filters
-    if params[:current_page].blank?
-      @current_page = 1
-    else
-      @current_page = params[:current_page]
-    end
+    @current_page = params[:current_page].blank? ? 1 : params[:current_page]
     @filter = params[:filter]
     @filter = params[:filter]
   end
   end
 
 
   # Never trust parameters from the scary internet, only allow the white list through.
   # Never trust parameters from the scary internet, only allow the white list through.
   def customer_params
   def customer_params
-    params.require(:customer).permit(:nick_name, :phone, :email, :credit, :credit_limit, :time_limit, :notes, :status, billing_information_attributes:[ :id, :name, :rfc, :address, :num_ext, :num_int, :zipcode, :state_id, :county_id, :city, :suburb], contact_attributes:[ :id, :name, :last_name, :phone, :email ] )
-
+    params.require(:customer).permit(:nick_name, :phone, :email, :credit, :credit_limit, :time_limit, :notes, :status, billing_information_attributes: [:id, :name, :rfc, :address, :num_ext, :num_int, :zipcode, :state_id, :county_id, :city, :suburb], contact_attributes: [:id, :name, :last_name, :phone, :email])
   end
   end
 end
 end

+ 3 - 10
app/controllers/sales_controller.rb

@@ -296,17 +296,10 @@ class SalesController < ApplicationController
 
 
   def print_receipt
   def print_receipt
     respond_to do |format|
     respond_to do |format|
-      @sale = Sale.find(params[:sale_id])
-
-      unless File.exist?(Rails.public_path.join('pdfs', "ticket_venta_#{@sale.id}.pdf"))
-        pdf = render_to_string pdf: "ticket_venta_#{@sale.id}", template: "sales/receipt.pdf.erb", layout: 'receipt.html.erb', locals: { sale: @sale }, show_as_html: params.key?('debug'), page_width: '80mm', page_height: '300mm'
-        save_path = Rails.public_path.join('pdfs', "ticket_venta_#{@sale.id}.pdf")
-
-        File.open(save_path, 'wb') do |file|
-          file << pdf
-        end
+      sale = Sale.find(params[:sale_id])
+      format.pdf do
+        render pdf: "ticket_venta_#{sale.id}", template: "sales/receipt.pdf.erb", layout: 'receipt.html.erb', locals: { sale: sale }, show_as_html: params.key?('debug'), page_width: '80mm', page_height: '300mm'
       end
       end
-      format.js
     end
     end
   end
   end
 
 

+ 3 - 1
app/views/cash_outs/_form.html.erb

@@ -152,7 +152,8 @@
               <% when "expense"%>
               <% when "expense"%>
                 GASTO CANCELADO
                 GASTO CANCELADO
               <% when "credit_payment"%>
               <% when "credit_payment"%>
-                ABONO A CRÉDITO
+                <strong>ABONO A CRÉDITO </strong><br>
+                cliente: <%= move.credit_payment.customer.nick_name %>
               <% when "reserved_payment"%>
               <% when "reserved_payment"%>
                 ABONO A APARTADO
                 ABONO A APARTADO
               <% when "reserved_first_payment" %>
               <% when "reserved_first_payment" %>
@@ -261,6 +262,7 @@
   function addCashOut() {
   function addCashOut() {
     if ( !$('#submit_cash_out').hasClass('disabled') ) {
     if ( !$('#submit_cash_out').hasClass('disabled') ) {
       if ($('#cash_out_received_by_id').val()) {
       if ($('#cash_out_received_by_id').val()) {
+        $('#submit_cash_out').prop('disabled', true);
         $('#cash_out_form').submit();
         $('#cash_out_form').submit();
       } else {
       } else {
         toastr["error"]("Seleccione quien va a recibir el corte de caja.");
         toastr["error"]("Seleccione quien va a recibir el corte de caja.");

+ 5 - 0
app/views/cash_registers_moves/_abonoform.html.erb

@@ -106,6 +106,10 @@
     defaultDate: new Date()
     defaultDate: new Date()
   });
   });
 
 
+  $('form#cash_register_move_form').bind('ajax:complete', function() {
+    $('#save_move').attr('disabled', false);
+  });
+
   $('#dialog').removeClass('bs-modal-lg');
   $('#dialog').removeClass('bs-modal-lg');
   $('#dialog .modal-dialog').removeClass('modal-lg');
   $('#dialog .modal-dialog').removeClass('modal-lg');
 
 
@@ -159,6 +163,7 @@
   }
   }
 
 
   function submitForm() {
   function submitForm() {
+    $('#save_move').attr('disabled', true);
     $('#cash_register_move_form').submit();
     $('#cash_register_move_form').submit();
   }
   }
 
 

+ 6 - 11
app/views/cash_registers_moves/confirm_payments.js.erb

@@ -1,18 +1,13 @@
 <% if @sale.present? %>
 <% if @sale.present? %>
-
-	$("#notice").html("<%= flash[:notice] %>");
-  $.ajax({
-    type: "get",
-    url: '<%= print_receipt_path(@sale.id) %>',
-    dataType: 'script'
-  });
-
   window.location = "<%= new_sale_path %>";
   window.location = "<%= new_sale_path %>";
+  $("#notice").html("<%= flash[:notice] %>");
+  var ticket_window = window.open("<%= print_receipt_path(@sale.id, format: 'pdf') %>", 'New tab', '' );
+  ticket_window.print();
 
 
 <% elsif @products_return.present? %>
 <% elsif @products_return.present? %>
-	window.location = "<%= products_returns_path %>";
-	$("#notice").html("<%= flash[:notice] %>");
+  window.location = "<%= products_returns_path %>";
+  $("#notice").html("<%= flash[:notice] %>");
   var ticket_window = window.open("<%= print_return_receipt_path(@products_return.id, format: 'pdf') %>", 'New tab', '' );
   var ticket_window = window.open("<%= print_return_receipt_path(@products_return.id, format: 'pdf') %>", 'New tab', '' );
   ticket_window.print();
   ticket_window.print();
-<% end %>
 
 
+<% end %>

+ 1 - 1
app/views/customers/customer_sales.html.erb

@@ -214,7 +214,7 @@
 																</td>
 																</td>
 
 
 																<td class="text-center">
 																<td class="text-center">
-																<% if !abono.cancelled? && abono.cash_registers_move.open_cash_register.open?%>
+																<% if !abono.cancelled? && abono.cash_registers_move.present? && abono.cash_registers_move.open_cash_register.open?%>
 																		<%= link_to cash_move_delete_payment_path(:credit_payment_id => abono.id, :credit => credit.id) , method: :delete_credit_payment, :class => "btn btn-icon-only btn-danger", :title=>"Cancelar abono", data: { confirm: '¿Esta seguro que desea cancelar el abono?'}   do %> <i class="fa fa-ban"></i>
 																		<%= link_to cash_move_delete_payment_path(:credit_payment_id => abono.id, :credit => credit.id) , method: :delete_credit_payment, :class => "btn btn-icon-only btn-danger", :title=>"Cancelar abono", data: { confirm: '¿Esta seguro que desea cancelar el abono?'}   do %> <i class="fa fa-ban"></i>
 																		<% end %>
 																		<% end %>
 																<% end %>
 																<% end %>

+ 0 - 2
app/views/customers/debtors.html.erb

@@ -50,7 +50,6 @@
 											<table class="table table-striped table-bordered table-hover tableadvanced">
 											<table class="table table-striped table-bordered table-hover tableadvanced">
 												<thead>
 												<thead>
 													<tr>
 													<tr>
-														<th>#</th>
 														<th>Cliente</th>
 														<th>Cliente</th>
 														<th>Límite de crédito</th>
 														<th>Límite de crédito</th>
 														<th>Monto a pagar</th>
 														<th>Monto a pagar</th>
@@ -68,7 +67,6 @@
 													<% sales = Sale.where("customer_id = #{customer.id} and status != 1 and status != 2 and saletype = 0").order("date_sale DESC") %>
 													<% sales = Sale.where("customer_id = #{customer.id} and status != 1 and status != 2 and saletype = 0").order("date_sale DESC") %>
 													<% if sales.first.present? && sales.first.status != "2" && credito > 0 %>
 													<% if sales.first.present? && sales.first.status != "2" && credito > 0 %>
 													<tr>
 													<tr>
-														<td><%= key + 1 %></td>
 														<td><%= customer.nick_name %> </td>
 														<td><%= customer.nick_name %> </td>
 														<% if customer.status != "debtor" %>
 														<% if customer.status != "debtor" %>
 															<td><span class="label label-sm label-success"> <i class="fa fa-check"></i> Crédito </span> <br> $ <%= customer.credit_limit %></td>
 															<td><span class="label label-sm label-success"> <i class="fa fa-check"></i> Crédito </span> <br> $ <%= customer.credit_limit %></td>

+ 1 - 1
app/views/sales/index.html.erb

@@ -144,7 +144,7 @@
                             <i class="fa fa-search"></i>
                             <i class="fa fa-search"></i>
                           <% end %>
                           <% end %>
 
 
-                          <%= link_to print_receipt_path(sale_id: sale.id), remote: true, class:"btn btn-icon-only default", target: "blank", :title=>"Imprimir ticket" do %>
+                          <%= link_to print_receipt_path(sale.id, format: 'pdf'), {:class=>"btn btn-icon-only default", :target => "blank"} do %>
                             <i class="fa fa-print"></i>
                             <i class="fa fa-print"></i>
                           <% end %>
                           <% end %>
 
 

+ 0 - 24
app/views/sales/print_receipt.js.erb

@@ -1,24 +0,0 @@
-window.open('<%= pdfjs.reduced_path(file: "ticket_venta_#{@sale.id}.pdf") %>', '_blank', '');
-
-// ticket_window.onload = function() {
-//   ticket_window.print();
-// };
-
-
-// function ready(fn) {
-//   if (document.readyState != 'loading'){
-//     fn();
-//   } else if (document.addEventListener) {
-//     document.addEventListener('DOMContentLoaded', fn);
-//   } else {
-//     document.attachEvent('onreadystatechange', function() {
-//       if (document.readyState != 'loading')
-//         fn();
-//     });
-//   }
-// }
-
-
-// ready(function() {
-//   ticket_window.print();
-// });

+ 0 - 2
config/routes.rb

@@ -14,8 +14,6 @@ Rails.application.routes.draw do
     sign_up: 'cmon_let_me_in'
     sign_up: 'cmon_let_me_in'
   }
   }
 
 
-  mount PdfjsViewer::Rails::Engine => "/pdfs", as: 'pdfjs'
-
   devise_scope :user do
   devise_scope :user do
     get "login", to: "devise/sessions#new"
     get "login", to: "devise/sessions#new"
     get "logout", to: "devise/sessions#destroy"
     get "logout", to: "devise/sessions#destroy"

+ 7 - 0
db/migrate/20170527190559_remove_credit_payment_id_from_cash_move.rb

@@ -0,0 +1,7 @@
+class RemoveCreditPaymentIdFromCashMove < ActiveRecord::Migration
+  def change
+    if column_exists?(:cash_registers_moves, :credit_payment_id)
+      remove_column :cash_registers_moves, :credit_payment_id
+    end
+  end
+end

+ 5 - 0
db/migrate/20170527191257_add_cash_move_id_to_credit_payment.rb

@@ -0,0 +1,5 @@
+class AddCashMoveIdToCreditPayment < ActiveRecord::Migration
+  def change
+    add_column :credit_payments, :cash_registers_move_id, :integer, index: true, null: true
+  end
+end

+ 7 - 0
db/migrate/20170529170639_add_credit_payment_to_cash_moves_again.rb

@@ -0,0 +1,7 @@
+class AddCreditPaymentToCashMovesAgain < ActiveRecord::Migration
+  def change
+    unless column_exists?(:cash_registers_moves, :credit_payment_id)
+      add_column :cash_registers_moves, :credit_payment_id, :integer, index: true, null: true
+    end
+  end
+end

+ 7 - 0
db/migrate/20170529183330_remove_cash_registers_moves_from_credit_payment.rb

@@ -0,0 +1,7 @@
+class RemoveCashRegistersMovesFromCreditPayment < ActiveRecord::Migration
+  def change
+    if column_exists?(:credit_payments, :cash_registers_move_id)
+      remove_column :credit_payments, :cash_registers_move_id
+    end
+  end
+end

+ 27 - 7
db/schema.rb

@@ -11,7 +11,7 @@
 #
 #
 # It's strongly recommended that you check this file into your version control system.
 # It's strongly recommended that you check this file into your version control system.
 
 
-ActiveRecord::Schema.define(version: 20161214181936) do
+ActiveRecord::Schema.define(version: 20170529183330) do
 
 
   # These are extensions that must be enabled in order to support this database
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
   enable_extension "plpgsql"
@@ -129,13 +129,14 @@ ActiveRecord::Schema.define(version: 20161214181936) do
     t.integer  "cardnumber"
     t.integer  "cardnumber"
     t.integer  "purchase_id"
     t.integer  "purchase_id"
     t.integer  "expense_id"
     t.integer  "expense_id"
-    t.integer  "credit_payment_id"
     t.integer  "concept"
     t.integer  "concept"
     t.string   "ticket"
     t.string   "ticket"
     t.integer  "status",                                                   default: 1,   null: false
     t.integer  "status",                                                   default: 1,   null: false
     t.decimal  "received",                        precision: 10, scale: 2
     t.decimal  "received",                        precision: 10, scale: 2
     t.decimal  "change",                          precision: 10, scale: 2
     t.decimal  "change",                          precision: 10, scale: 2
     t.integer  "products_return_id"
     t.integer  "products_return_id"
+    t.integer  "deposit_id"
+    t.integer  "credit_payment_id"
   end
   end
 
 
   add_index "cash_registers_moves", ["open_cash_register_id"], name: "index_cash_registers_moves_on_open_cash_register_id", using: :btree
   add_index "cash_registers_moves", ["open_cash_register_id"], name: "index_cash_registers_moves_on_open_cash_register_id", using: :btree
@@ -228,6 +229,20 @@ ActiveRecord::Schema.define(version: 20161214181936) do
     t.integer  "is_public",                                         default: 0
     t.integer  "is_public",                                         default: 0
   end
   end
 
 
+  create_table "deposits", force: :cascade do |t|
+    t.integer  "open_cash_register_id"
+    t.decimal  "quantity",              default: 0.0, null: false
+    t.integer  "user_id"
+    t.integer  "status",                default: 1,   null: false
+    t.datetime "created_at",                          null: false
+    t.datetime "updated_at",                          null: false
+    t.string   "observations"
+    t.string   "deposit_code",                        null: false
+  end
+
+  add_index "deposits", ["open_cash_register_id"], name: "index_deposits_on_open_cash_register_id", using: :btree
+  add_index "deposits", ["user_id"], name: "index_deposits_on_user_id", using: :btree
+
   create_table "expenses", force: :cascade do |t|
   create_table "expenses", force: :cascade do |t|
     t.integer  "expensesconcept_id"
     t.integer  "expensesconcept_id"
     t.integer  "open_cash_register_id"
     t.integer  "open_cash_register_id"
@@ -347,6 +362,7 @@ ActiveRecord::Schema.define(version: 20161214181936) do
     t.datetime "ticket_img_updated_at"
     t.datetime "ticket_img_updated_at"
     t.integer  "haggle_in_sale_percent"
     t.integer  "haggle_in_sale_percent"
     t.string   "ticket_img"
     t.string   "ticket_img"
+    t.boolean  "print_ticket"
   end
   end
 
 
   create_table "pre_purchases", force: :cascade do |t|
   create_table "pre_purchases", force: :cascade do |t|
@@ -359,10 +375,10 @@ ActiveRecord::Schema.define(version: 20161214181936) do
     t.decimal  "amount",                                default: 0.0, null: false
     t.decimal  "amount",                                default: 0.0, null: false
     t.decimal  "tax",                                   default: 0.0, null: false
     t.decimal  "tax",                                   default: 0.0, null: false
     t.decimal  "total",                                 default: 0.0, null: false
     t.decimal  "total",                                 default: 0.0, null: false
-    t.integer  "quantity",                              default: 0,   null: false
     t.integer  "warehouse_id"
     t.integer  "warehouse_id"
     t.decimal  "price_base",   precision: 10, scale: 2
     t.decimal  "price_base",   precision: 10, scale: 2
     t.decimal  "exchange",     precision: 10, scale: 2
     t.decimal  "exchange",     precision: 10, scale: 2
+    t.decimal  "quantity",     precision: 10, scale: 2
   end
   end
 
 
   create_table "pre_sales", force: :cascade do |t|
   create_table "pre_sales", force: :cascade do |t|
@@ -377,10 +393,10 @@ ActiveRecord::Schema.define(version: 20161214181936) do
     t.decimal  "tax",                                                      default: 0.0, null: false
     t.decimal  "tax",                                                      default: 0.0, null: false
     t.decimal  "discount",                                                 default: 0.0, null: false
     t.decimal  "discount",                                                 default: 0.0, null: false
     t.decimal  "total",                                                    default: 0.0, null: false
     t.decimal  "total",                                                    default: 0.0, null: false
-    t.integer  "quantity",                                                 default: 0,   null: false
     t.integer  "special_price_id"
     t.integer  "special_price_id"
     t.decimal  "unit_price",                      precision: 10, scale: 2
     t.decimal  "unit_price",                      precision: 10, scale: 2
     t.decimal  "haggle",                          precision: 10, scale: 2, default: 0.0
     t.decimal  "haggle",                          precision: 10, scale: 2, default: 0.0
+    t.decimal  "quantity",                        precision: 10, scale: 2,               null: false
   end
   end
 
 
   create_table "pre_transfers", force: :cascade do |t|
   create_table "pre_transfers", force: :cascade do |t|
@@ -441,6 +457,7 @@ ActiveRecord::Schema.define(version: 20161214181936) do
     t.boolean  "is_in_dollars",                                                 default: false
     t.boolean  "is_in_dollars",                                                 default: false
     t.decimal  "price_base_dollars",                   precision: 10, scale: 2
     t.decimal  "price_base_dollars",                   precision: 10, scale: 2
     t.string   "img_product"
     t.string   "img_product"
+    t.decimal  "gain_margin",                          precision: 10, scale: 2, default: 0.0
   end
   end
 
 
   add_index "products", ["unit_id"], name: "index_products_on_unit_id", using: :btree
   add_index "products", ["unit_id"], name: "index_products_on_unit_id", using: :btree
@@ -503,13 +520,13 @@ ActiveRecord::Schema.define(version: 20161214181936) do
   create_table "purchase_details", force: :cascade do |t|
   create_table "purchase_details", force: :cascade do |t|
     t.integer  "purchase_id"
     t.integer  "purchase_id"
     t.integer  "product_id"
     t.integer  "product_id"
-    t.integer  "quantity"
     t.decimal  "price",       precision: 10, scale: 2, default: 0.0, null: false
     t.decimal  "price",       precision: 10, scale: 2, default: 0.0, null: false
     t.decimal  "amount",      precision: 10, scale: 2, default: 0.0, null: false
     t.decimal  "amount",      precision: 10, scale: 2, default: 0.0, null: false
     t.datetime "created_at",                                         null: false
     t.datetime "created_at",                                         null: false
     t.datetime "updated_at",                                         null: false
     t.datetime "updated_at",                                         null: false
     t.integer  "status",                               default: 1,   null: false
     t.integer  "status",                               default: 1,   null: false
     t.decimal  "tax",                                                null: false
     t.decimal  "tax",                                                null: false
+    t.decimal  "quantity",    precision: 10, scale: 2
   end
   end
 
 
   add_index "purchase_details", ["product_id"], name: "index_purchase_details_on_product_id", using: :btree
   add_index "purchase_details", ["product_id"], name: "index_purchase_details_on_product_id", using: :btree
@@ -591,6 +608,7 @@ ActiveRecord::Schema.define(version: 20161214181936) do
     t.integer  "status",       default: 1, null: false
     t.integer  "status",       default: 1, null: false
     t.datetime "created_at",               null: false
     t.datetime "created_at",               null: false
     t.datetime "updated_at",               null: false
     t.datetime "updated_at",               null: false
+    t.integer  "user_id"
   end
   end
 
 
   add_index "sellers", ["pointsale_id"], name: "index_sellers_on_pointsale_id", using: :btree
   add_index "sellers", ["pointsale_id"], name: "index_sellers_on_pointsale_id", using: :btree
@@ -721,8 +739,10 @@ ActiveRecord::Schema.define(version: 20161214181936) do
   create_table "units", force: :cascade do |t|
   create_table "units", force: :cascade do |t|
     t.string   "unit"
     t.string   "unit"
     t.integer  "status"
     t.integer  "status"
-    t.datetime "created_at", null: false
-    t.datetime "updated_at", null: false
+    t.datetime "created_at",                     null: false
+    t.datetime "updated_at",                     null: false
+    t.string   "abbreviation"
+    t.boolean  "can_be_divided", default: false
   end
   end
 
 
   create_table "users", force: :cascade do |t|
   create_table "users", force: :cascade do |t|

BIN
erd.pdf