# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180727152745) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "audits", force: :cascade do |t|
    t.integer  "auditable_id"
    t.string   "auditable_type"
    t.integer  "associated_id"
    t.string   "associated_type"
    t.integer  "user_id"
    t.string   "user_type"
    t.string   "username"
    t.string   "action"
    t.text     "audited_changes"
    t.integer  "version",         default: 0
    t.string   "comment"
    t.string   "remote_address"
    t.string   "request_uuid"
    t.datetime "created_at"
  end

  add_index "audits", ["associated_id", "associated_type"], name: "associated_index", using: :btree
  add_index "audits", ["auditable_id", "auditable_type"], name: "auditable_index", using: :btree
  add_index "audits", ["created_at"], name: "index_audits_on_created_at", using: :btree
  add_index "audits", ["request_uuid"], name: "index_audits_on_request_uuid", using: :btree
  add_index "audits", ["user_id", "user_type"], name: "user_index", using: :btree

  create_table "available_products", force: :cascade do |t|
    t.integer  "product_id"
    t.integer  "pointsale_id"
    t.decimal  "stock_min",                                    default: 0.0
    t.decimal  "stock_max",                                    default: 0.0
    t.decimal  "stock",                                        default: 0.0
    t.datetime "created_at",                                                 null: false
    t.datetime "updated_at",                                                 null: false
    t.decimal  "price_sale",          precision: 10, scale: 2
    t.integer  "products_variant_id"
  end

  add_index "available_products", ["pointsale_id"], name: "index_available_products_on_pointsale_id", using: :btree
  add_index "available_products", ["product_id"], name: "index_available_products_on_product_id", using: :btree

  create_table "billing_informations", force: :cascade do |t|
    t.integer  "customer_id",             default: 0,  null: false
    t.string   "name",        limit: 255, default: "", null: false
    t.string   "rfc",         limit: 13,  default: "", null: false
    t.string   "address",     limit: 255, default: "", null: false
    t.integer  "zipcode",                 default: 0,  null: false
    t.string   "num_ext",                 default: "", null: false
    t.string   "num_int",                 default: "", null: false
    t.integer  "state_id",                default: 0,  null: false
    t.integer  "county_id",               default: 0,  null: false
    t.string   "city",                    default: "", null: false
    t.string   "suburb",                  default: "", null: false
    t.integer  "status",                  default: 1,  null: false
    t.datetime "created_at",                           null: false
    t.datetime "updated_at",                           null: false
    t.integer  "supplier_id",             default: 0,  null: false
  end

  add_index "billing_informations", ["county_id"], name: "index_billing_informations_on_county_id", using: :btree
  add_index "billing_informations", ["customer_id"], name: "index_billing_informations_on_customer_id", using: :btree
  add_index "billing_informations", ["state_id"], name: "index_billing_informations_on_state_id", using: :btree

  create_table "cash_out_details", force: :cascade do |t|
    t.integer  "cash_out_id"
    t.integer  "payment_method_id"
    t.datetime "created_at",                                               null: false
    t.datetime "updated_at",                                               null: false
    t.decimal  "incoming",          precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "total",             precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "adjustment",        precision: 10, scale: 2, default: 0.0, null: false
    t.text     "observations"
    t.decimal  "outgoing",          precision: 10, scale: 2, default: 0.0, null: false
  end

  add_index "cash_out_details", ["cash_out_id"], name: "index_cash_out_details_on_cash_out_id", using: :btree
  add_index "cash_out_details", ["payment_method_id"], name: "index_cash_out_details_on_payment_method_id", using: :btree

  create_table "cash_outs", force: :cascade do |t|
    t.integer  "open_cash_register_id"
    t.integer  "user_id"
    t.decimal  "amount_in",                                                    null: false
    t.decimal  "amount_out",                                                   null: false
    t.datetime "created_at",                                                   null: false
    t.datetime "updated_at",                                                   null: false
    t.integer  "received_by_id"
    t.decimal  "received_cash",         precision: 10, scale: 2, default: 0.0
    t.decimal  "cash_fund",             precision: 10, scale: 2, default: 0.0
    t.decimal  "physical_cash",         precision: 10, scale: 2, default: 0.0, null: false
    t.string   "observations"
  end

  add_index "cash_outs", ["open_cash_register_id"], name: "index_cash_outs_on_open_cash_register_id", using: :btree
  add_index "cash_outs", ["user_id"], name: "index_cash_outs_on_user_id", using: :btree

  create_table "cash_registers", force: :cascade do |t|
    t.string   "name"
    t.text     "description"
    t.integer  "pointsale_id"
    t.datetime "created_at",               null: false
    t.datetime "updated_at",               null: false
    t.integer  "main",         default: 0, null: false
    t.integer  "status",       default: 1, null: false
  end

  create_table "cash_registers_moves", force: :cascade do |t|
    t.integer  "open_cash_register_id"
    t.integer  "payment_method_id"
    t.decimal  "quantity",                                                 default: 0.0, null: false
    t.string   "move_type",             limit: 1,                                        null: false
    t.datetime "created_at",                                                             null: false
    t.datetime "updated_at",                                                             null: false
    t.integer  "sale_id"
    t.integer  "cardnumber"
    t.integer  "purchase_id"
    t.integer  "expense_id"
    t.integer  "concept"
    t.string   "ticket"
    t.integer  "status",                                                   default: 1,   null: false
    t.decimal  "received",                        precision: 10, scale: 2
    t.decimal  "change",                          precision: 10, scale: 2
    t.integer  "products_return_id"
    t.integer  "credit_payment_id"
  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", ["payment_method_id"], name: "index_cash_registers_moves_on_payment_method_id", using: :btree

  create_table "categories", force: :cascade do |t|
    t.string   "category"
    t.text     "description"
    t.integer  "status",      default: 1
    t.datetime "created_at",              null: false
    t.datetime "updated_at",              null: false
    t.integer  "parent_id",   default: 0, null: false
  end

  create_table "categories_products", id: false, force: :cascade do |t|
    t.integer "product_id"
    t.integer "category_id"
  end

  add_index "categories_products", ["category_id"], name: "index_categories_products_on_category_id", using: :btree
  add_index "categories_products", ["product_id"], name: "index_categories_products_on_product_id", using: :btree

  create_table "commissions", force: :cascade do |t|
    t.decimal  "commission_total"
    t.datetime "created_at",       null: false
    t.datetime "updated_at",       null: false
    t.integer  "pointsale_id"
    t.integer  "user_id"
    t.datetime "initial_date",     null: false
    t.datetime "final_date",       null: false
  end

  add_index "commissions", ["pointsale_id"], name: "index_commissions_on_pointsale_id", using: :btree

  create_table "contacts", force: :cascade do |t|
    t.string   "name",       limit: 255, default: "", null: false
    t.string   "last_name",  limit: 255, default: "", null: false
    t.string   "phone",      limit: 30,  default: "", null: false
    t.string   "email",      limit: 255, default: "", null: false
    t.text     "notes",                  default: "", null: false
    t.integer  "status",                 default: 1,  null: false
    t.datetime "created_at",                          null: false
    t.datetime "updated_at",                          null: false
  end

  create_table "credit_payments", force: :cascade do |t|
    t.integer  "customer_id"
    t.integer  "credit_id"
    t.integer  "pointsale_id"
    t.decimal  "quantity",     precision: 10, scale: 2, default: 0.0, null: false
    t.integer  "status",                                default: 0,   null: false
    t.date     "date_payment",                                        null: false
    t.datetime "created_at",                                          null: false
    t.datetime "updated_at",                                          null: false
    t.integer  "user_id"
  end

  add_index "credit_payments", ["credit_id"], name: "index_credit_payments_on_credit_id", using: :btree
  add_index "credit_payments", ["customer_id"], name: "index_credit_payments_on_customer_id", using: :btree
  add_index "credit_payments", ["pointsale_id"], name: "index_credit_payments_on_pointsale_id", using: :btree

  create_table "credits", force: :cascade do |t|
    t.integer  "customer_id"
    t.integer  "pointsale_id"
    t.integer  "sale_id"
    t.decimal  "total",        precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "rest",         precision: 10, scale: 2, default: 0.0, null: false
    t.integer  "status",                                default: 0,   null: false
    t.datetime "created_at",                                          null: false
    t.datetime "updated_at",                                          null: false
    t.string   "credit_note"
  end

  add_index "credits", ["customer_id"], name: "index_credits_on_customer_id", using: :btree
  add_index "credits", ["pointsale_id"], name: "index_credits_on_pointsale_id", using: :btree
  add_index "credits", ["sale_id"], name: "index_credits_on_sale_id", using: :btree

  create_table "customers", force: :cascade do |t|
    t.string   "nick_name",    limit: 255,                          default: "",   null: false
    t.string   "phone",        limit: 30,                           default: "",   null: false
    t.string   "email",        limit: 255,                          default: "",   null: false
    t.boolean  "credit",                                            default: true, null: false
    t.decimal  "credit_limit",             precision: 10, scale: 2, default: 0.0,  null: false
    t.integer  "time_limit",                                        default: 0,    null: false
    t.text     "notes",                                             default: "",   null: false
    t.integer  "status",                                            default: 1,    null: false
    t.datetime "created_at",                                                       null: false
    t.datetime "updated_at",                                                       null: false
    t.integer  "contact_id"
    t.integer  "is_public",                                         default: 0
  end

  create_table "expenses", force: :cascade do |t|
    t.integer  "expensesconcept_id"
    t.integer  "open_cash_register_id"
    t.decimal  "quantity",              default: 0.0, null: false
    t.integer  "status",                default: 1,   null: false
    t.datetime "created_at",                          null: false
    t.datetime "updated_at",                          null: false
    t.text     "observations"
    t.date     "expense_date"
    t.string   "expense_code"
  end

  add_index "expenses", ["expensesconcept_id"], name: "index_expenses_on_expensesconcept_id", using: :btree
  add_index "expenses", ["open_cash_register_id"], name: "index_expenses_on_open_cash_register_id", using: :btree

  create_table "expensesconcepts", force: :cascade do |t|
    t.string   "name"
    t.string   "description"
    t.boolean  "allpoints"
    t.integer  "status",                default: 1
    t.datetime "created_at",                        null: false
    t.datetime "updated_at",                        null: false
    t.integer  "expense_from_purchase", default: 0, null: false
  end

  create_table "expensesconcepts_pointsales", id: false, force: :cascade do |t|
    t.integer "expensesconcept_id"
    t.integer "pointsale_id"
  end

  create_table "inventories", force: :cascade do |t|
    t.integer  "pointsale_id"
    t.integer  "user_id"
    t.date     "inventory_date"
    t.text     "notes"
    t.datetime "created_at",     null: false
    t.datetime "updated_at",     null: false
  end

  add_index "inventories", ["pointsale_id"], name: "index_inventories_on_pointsale_id", using: :btree
  add_index "inventories", ["user_id"], name: "index_inventories_on_user_id", using: :btree

  create_table "inventories_moves", force: :cascade do |t|
    t.integer  "inventory_id"
    t.integer  "product_id"
    t.integer  "purchase_id"
    t.integer  "sale_id"
    t.decimal  "quantity",               default: 0.0, null: false
    t.string   "move_type",    limit: 1,               null: false
    t.datetime "created_at",                           null: false
    t.datetime "updated_at",                           null: false
    t.integer  "reason"
    t.integer  "transfer_id"
  end

  add_index "inventories_moves", ["inventory_id"], name: "index_inventories_moves_on_inventory_id", using: :btree
  add_index "inventories_moves", ["product_id"], name: "index_inventories_moves_on_product_id", using: :btree
  add_index "inventories_moves", ["purchase_id"], name: "index_inventories_moves_on_purchase_id", using: :btree
  add_index "inventories_moves", ["sale_id"], name: "index_inventories_moves_on_sale_id", using: :btree

  create_table "open_cash_registers", force: :cascade do |t|
    t.integer  "cash_register_id"
    t.integer  "user_id"
    t.decimal  "initial_cash",     precision: 10, scale: 2, default: 0.0
    t.decimal  "final_cash",       precision: 10, scale: 2, default: 0.0
    t.integer  "status",                                    default: 0
    t.datetime "created_at",                                              null: false
    t.datetime "updated_at",                                              null: false
  end

  add_index "open_cash_registers", ["cash_register_id"], name: "index_open_cash_registers_on_cash_register_id", using: :btree
  add_index "open_cash_registers", ["user_id"], name: "index_open_cash_registers_on_user_id", using: :btree

  create_table "payment_methods", force: :cascade do |t|
    t.string   "method",                 null: false
    t.integer  "status",     default: 1, null: false
    t.datetime "created_at",             null: false
    t.datetime "updated_at",             null: false
    t.integer  "reference"
    t.integer  "isCash",     default: 0, null: false
  end

  create_table "pointsales", force: :cascade do |t|
    t.string   "name"
    t.string   "address"
    t.text     "notes"
    t.integer  "status",                                              default: 1
    t.datetime "created_at",                                                        null: false
    t.datetime "updated_at",                                                        null: false
    t.text     "prefix"
    t.string   "img_pointsale_file_name"
    t.string   "img_pointsale_content_type"
    t.integer  "img_pointsale_file_size"
    t.datetime "img_pointsale_updated_at"
    t.string   "ticket_footer"
    t.string   "img_pointsale"
    t.decimal  "haggle_percent",             precision: 10, scale: 2, default: 0.0
  end

  create_table "pos_configs", force: :cascade do |t|
    t.integer  "cancel_partial_payment"
    t.integer  "refund_sale"
    t.integer  "days_cancel_sale"
    t.integer  "days_cancel_purchase"
    t.decimal  "tax_percent"
    t.string   "time_zone",               limit: 255,                          default: "",   null: false
    t.decimal  "gain_margin"
    t.datetime "created_at",                                                                  null: false
    t.datetime "updated_at",                                                                  null: false
    t.text     "ticket_description"
    t.integer  "days_cancel_reserved"
    t.decimal  "reserve_sale_percent",                precision: 10, scale: 2
    t.integer  "commission_percent"
    t.string   "ticket_footer"
    t.string   "ticket_img_file_name"
    t.string   "ticket_img_content_type"
    t.integer  "ticket_img_file_size"
    t.datetime "ticket_img_updated_at"
    t.integer  "haggle_in_sale_percent"
    t.string   "ticket_img"
    t.boolean  "enable_haggle",                                                default: true
  end

  create_table "pre_purchases", force: :cascade do |t|
    t.integer  "supplier_id"
    t.integer  "user_id"
    t.integer  "pointsale_id"
    t.integer  "product_id"
    t.datetime "created_at",                                          null: false
    t.datetime "updated_at",                                          null: false
    t.decimal  "amount",                                default: 0.0, null: false
    t.decimal  "tax",                                   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.decimal  "price_base",   precision: 10, scale: 2
    t.decimal  "exchange",     precision: 10, scale: 2
  end

  create_table "pre_sales", force: :cascade do |t|
    t.integer  "customer_id"
    t.integer  "user_id"
    t.integer  "open_cash_register_id"
    t.integer  "product_id"
    t.datetime "created_at",                                                             null: false
    t.datetime "updated_at",                                                             null: false
    t.integer  "sale_type",             limit: 2
    t.decimal  "amount",                                                   default: 0.0, null: false
    t.decimal  "tax",                                                      default: 0.0, null: false
    t.decimal  "discount",                                                 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.decimal  "unit_price",                      precision: 10, scale: 2
    t.decimal  "haggle",                          precision: 10, scale: 2, default: 0.0
  end

  create_table "pre_transfers", force: :cascade do |t|
    t.integer  "origin_id"
    t.integer  "destiny_id"
    t.integer  "user_id"
    t.integer  "product_id"
    t.integer  "quantity",             null: false
    t.datetime "created_at",           null: false
    t.datetime "updated_at",           null: false
    t.integer  "origin_is_pointsale",  null: false
    t.integer  "destiny_is_pointsale", null: false
  end

  add_index "pre_transfers", ["destiny_id"], name: "index_pre_transfers_on_destiny_id", using: :btree
  add_index "pre_transfers", ["origin_id"], name: "index_pre_transfers_on_origin_id", using: :btree
  add_index "pre_transfers", ["product_id"], name: "index_pre_transfers_on_product_id", using: :btree
  add_index "pre_transfers", ["user_id"], name: "index_pre_transfers_on_user_id", using: :btree

  create_table "product_wastes", force: :cascade do |t|
    t.integer  "product_id"
    t.decimal  "quantity",              precision: 10, scale: 2, default: 0.0, null: false
    t.string   "reason",                                         default: "",  null: false
    t.integer  "status",                                         default: 0,   null: false
    t.datetime "created_at",                                                   null: false
    t.datetime "updated_at",                                                   null: false
    t.integer  "user_id"
    t.integer  "pointsale_id"
    t.integer  "warehouse_id"
    t.integer  "products_return_in_id"
  end

  add_index "product_wastes", ["product_id"], name: "index_product_wastes_on_product_id", using: :btree

  create_table "products", force: :cascade do |t|
    t.string   "sku",                      limit: 30,                           default: "",    null: false
    t.string   "name",                     limit: 255,                          default: "",    null: false
    t.text     "description",                                                   default: "",    null: false
    t.decimal  "price_base",                           precision: 10, scale: 2, default: 0.0
    t.decimal  "price_sale",                           precision: 10, scale: 2, default: 0.0
    t.string   "img_product_file_name"
    t.string   "img_product_content_type"
    t.integer  "img_product_file_size"
    t.datetime "img_product_updated_at"
    t.boolean  "presentation",                                                  default: false, null: false
    t.boolean  "inventory",                                                     default: true,  null: false
    t.decimal  "content"
    t.integer  "status",                                                        default: 1,     null: false
    t.datetime "created_at",                                                                    null: false
    t.datetime "updated_at",                                                                    null: false
    t.integer  "unit_id"
    t.integer  "include_purchase_tax",                                          default: 0,     null: false
    t.integer  "include_sale_tax",                                              default: 0,     null: false
    t.string   "barcode"
    t.integer  "parent_id"
    t.text     "attributes_json"
    t.boolean  "is_parent",                                                     default: false
    t.boolean  "is_in_dollars",                                                 default: false
    t.decimal  "price_base_dollars",                   precision: 10, scale: 2
    t.string   "img_product"
  end

  add_index "products", ["unit_id"], name: "index_products_on_unit_id", using: :btree

  create_table "products_return_ins", force: :cascade do |t|
    t.integer  "products_return_id"
    t.integer  "product_id",                         null: false
    t.decimal  "quantity",                           null: false
    t.string   "reason"
    t.boolean  "is_wasted",          default: false
    t.decimal  "amount",             default: 0.0
    t.datetime "created_at",                         null: false
    t.datetime "updated_at",                         null: false
  end

  add_index "products_return_ins", ["product_id"], name: "index_products_return_ins_on_product_id", using: :btree
  add_index "products_return_ins", ["products_return_id"], name: "index_products_return_ins_on_products_return_id", using: :btree

  create_table "products_return_outs", force: :cascade do |t|
    t.integer  "products_return_id"
    t.integer  "product_id",                       null: false
    t.decimal  "quantity",                         null: false
    t.decimal  "amount",             default: 0.0
    t.datetime "created_at",                       null: false
    t.datetime "updated_at",                       null: false
  end

  add_index "products_return_outs", ["product_id"], name: "index_products_return_outs_on_product_id", using: :btree
  add_index "products_return_outs", ["products_return_id"], name: "index_products_return_outs_on_products_return_id", using: :btree

  create_table "products_returns", force: :cascade do |t|
    t.integer  "sale_id"
    t.integer  "user_id"
    t.string   "return_code",                                                null: false
    t.datetime "created_at",                                                 null: false
    t.datetime "updated_at",                                                 null: false
    t.integer  "pointsale_id",                                               null: false
    t.decimal  "new_amount",        precision: 10, scale: 2, default: 0.0
    t.decimal  "returned_amount",   precision: 10, scale: 2, default: 0.0
    t.decimal  "difference_amount", precision: 10, scale: 2, default: 0.0
    t.boolean  "is_money_returned",                          default: false
  end

  add_index "products_returns", ["sale_id"], name: "index_products_returns_on_sale_id", using: :btree
  add_index "products_returns", ["user_id"], name: "index_products_returns_on_user_id", using: :btree

  create_table "products_variants", force: :cascade do |t|
    t.integer  "product_id"
    t.text     "attributes_json",                                                  null: false
    t.string   "sku",             limit: 30,                          default: "", null: false
    t.string   "barcode"
    t.decimal  "price_sale",                 precision: 10, scale: 2
    t.integer  "status"
    t.datetime "created_at",                                                       null: false
    t.datetime "updated_at",                                                       null: false
  end

  add_index "products_variants", ["product_id"], name: "index_products_variants_on_product_id", using: :btree

  create_table "purchase_details", force: :cascade do |t|
    t.integer  "purchase_id"
    t.integer  "product_id"
    t.integer  "quantity"
    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.datetime "created_at",                                         null: false
    t.datetime "updated_at",                                         null: false
    t.integer  "status",                               default: 1,   null: false
    t.decimal  "tax",                                                null: false
  end

  add_index "purchase_details", ["product_id"], name: "index_purchase_details_on_product_id", using: :btree
  add_index "purchase_details", ["purchase_id"], name: "index_purchase_details_on_purchase_id", using: :btree

  create_table "purchases", force: :cascade do |t|
    t.integer  "supplier_id"
    t.integer  "pointsale_id"
    t.string   "purchase_code"
    t.decimal  "amount",        precision: 10, scale: 2, default: 0.0
    t.decimal  "tax",           precision: 10, scale: 2, default: 0.0
    t.decimal  "total",         precision: 10, scale: 2, default: 0.0
    t.text     "observations"
    t.date     "purchase_date"
    t.string   "user_id"
    t.datetime "created_at",                                             null: false
    t.datetime "updated_at",                                             null: false
    t.integer  "status",                                 default: 0,     null: false
    t.integer  "warehouse_id"
    t.boolean  "is_in_dollars",                          default: false
    t.decimal  "exchange",      precision: 10, scale: 2
  end

  create_table "sales", force: :cascade do |t|
    t.integer  "customer_id"
    t.integer  "user_id"
    t.integer  "open_cash_register_id"
    t.decimal  "amount",                          precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "tax",                             precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "discount",                        precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "total",                           precision: 10, scale: 2, default: 0.0, null: false
    t.integer  "status",                                                   default: 1,   null: false
    t.date     "date_sale",                                                              null: false
    t.datetime "created_at",                                                             null: false
    t.datetime "updated_at",                                                             null: false
    t.integer  "saletype",              limit: 2
    t.integer  "seller_id"
    t.string   "sale_code"
    t.date     "expiration_date"
    t.string   "credit_note"
  end

  add_index "sales", ["customer_id"], name: "index_sales_on_customer_id", using: :btree
  add_index "sales", ["open_cash_register_id"], name: "index_sales_on_open_cash_register_id", using: :btree
  add_index "sales", ["user_id"], name: "index_sales_on_user_id", using: :btree

  create_table "sales_details", force: :cascade do |t|
    t.integer  "sale_id"
    t.integer  "product_id"
    t.decimal  "quantity",                                                null: false
    t.decimal  "amount",           precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "tax",              precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "discount",         precision: 10, scale: 2, default: 0.0, null: false
    t.decimal  "total",            precision: 10, scale: 2, default: 0.0, null: false
    t.integer  "status",                                    default: 1,   null: false
    t.datetime "created_at",                                              null: false
    t.datetime "updated_at",                                              null: false
    t.integer  "special_price_id"
    t.decimal  "unit_price",       precision: 10, scale: 2
  end

  add_index "sales_details", ["product_id"], name: "index_sales_details_on_product_id", using: :btree
  add_index "sales_details", ["sale_id"], name: "index_sales_details_on_sale_id", using: :btree

  create_table "sales_sellercommissions", force: :cascade do |t|
    t.integer  "sellerscommission_id"
    t.integer  "sale_id"
    t.datetime "created_at",           null: false
    t.datetime "updated_at",           null: false
  end

  add_index "sales_sellercommissions", ["sale_id"], name: "index_sales_sellercommissions_on_sale_id", using: :btree
  add_index "sales_sellercommissions", ["sellerscommission_id"], name: "index_sales_sellercommissions_on_sellerscommission_id", using: :btree

  create_table "sellers", force: :cascade do |t|
    t.integer  "pointsale_id"
    t.string   "name",                     null: false
    t.string   "last_name",                null: false
    t.integer  "status",       default: 1, null: false
    t.datetime "created_at",               null: false
    t.datetime "updated_at",               null: false
  end

  add_index "sellers", ["pointsale_id"], name: "index_sellers_on_pointsale_id", using: :btree

  create_table "sellerscommissions", force: :cascade do |t|
    t.integer  "commission_id"
    t.integer  "seller_id"
    t.integer  "num_sales"
    t.decimal  "sales_total"
    t.decimal  "commission_calculated"
    t.decimal  "commission_paid"
    t.datetime "created_at",                                                            null: false
    t.datetime "updated_at",                                                            null: false
    t.integer  "commission_percent"
    t.decimal  "total_sold_cash",                precision: 10, scale: 2, default: 0.0
    t.decimal  "total_sold_credits_apartments",  precision: 10, scale: 2, default: 0.0
    t.decimal  "income_by_cash",                 precision: 10, scale: 2, default: 0.0
    t.decimal  "income_by_reserved_and_credits", precision: 10, scale: 2, default: 0.0
  end

  add_index "sellerscommissions", ["commission_id"], name: "index_sellerscommissions_on_commission_id", using: :btree
  add_index "sellerscommissions", ["seller_id"], name: "index_sellerscommissions_on_seller_id", using: :btree

  create_table "special_prices", force: :cascade do |t|
    t.integer  "product_id"
    t.integer  "customer_id"
    t.decimal  "price",       precision: 10, scale: 2
    t.decimal  "percent"
    t.integer  "status",                               default: 1, null: false
    t.datetime "created_at",                                       null: false
    t.datetime "updated_at",                                       null: false
    t.integer  "user_id"
  end

  add_index "special_prices", ["customer_id"], name: "index_special_prices_on_customer_id", using: :btree
  add_index "special_prices", ["product_id"], name: "index_special_prices_on_product_id", using: :btree

  create_table "spmx_counties", force: :cascade do |t|
    t.integer "id_",      null: false
    t.integer "state_id"
    t.string  "name",     null: false
  end

  add_index "spmx_counties", ["state_id"], name: "index_spmx_counties_on_state_id", using: :btree

  create_table "spmx_states", force: :cascade do |t|
    t.string "name", null: false
  end

  create_table "storers", force: :cascade do |t|
    t.integer  "user_id"
    t.integer  "warehouse_id"
    t.string   "name",                     null: false
    t.string   "last_name",                null: false
    t.integer  "status",       default: 1, null: false
    t.datetime "created_at",               null: false
    t.datetime "updated_at",               null: false
  end

  add_index "storers", ["user_id"], name: "index_storers_on_user_id", using: :btree
  add_index "storers", ["warehouse_id"], name: "index_storers_on_warehouse_id", using: :btree

  create_table "suppliers", force: :cascade do |t|
    t.string   "nick_name",  limit: 255, default: "", null: false
    t.string   "phone",      limit: 30,  default: "", null: false
    t.string   "email",      limit: 255, default: "", null: false
    t.text     "notes",                  default: "", null: false
    t.integer  "contact_id"
    t.integer  "status",                 default: 1,  null: false
    t.datetime "created_at",                          null: false
    t.datetime "updated_at",                          null: false
  end

  add_index "suppliers", ["contact_id"], name: "index_suppliers_on_contact_id", using: :btree

  create_table "taggings", force: :cascade do |t|
    t.integer  "tag_id"
    t.integer  "taggable_id"
    t.string   "taggable_type"
    t.integer  "tagger_id"
    t.string   "tagger_type"
    t.string   "context",       limit: 128
    t.datetime "created_at"
  end

  add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree
  add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree

  create_table "tags", force: :cascade do |t|
    t.string  "name"
    t.integer "taggings_count", default: 0
  end

  add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree

  create_table "transfer_details", force: :cascade do |t|
    t.integer  "transfer_id"
    t.integer  "product_id"
    t.decimal  "quantity",    precision: 10, scale: 2, default: 0.0, null: false
    t.integer  "status",                               default: 1,   null: false
    t.datetime "created_at",                                         null: false
    t.datetime "updated_at",                                         null: false
    t.integer  "adjustment"
    t.integer  "has_looses",                           default: 0
    t.integer  "has_surplus",                          default: 0
  end

  add_index "transfer_details", ["product_id"], name: "index_transfer_details_on_product_id", using: :btree
  add_index "transfer_details", ["transfer_id"], name: "index_transfer_details_on_transfer_id", using: :btree

  create_table "transfers", force: :cascade do |t|
    t.integer  "origin_id"
    t.integer  "destiny_id"
    t.date     "transfer_date",                    null: false
    t.integer  "user_id"
    t.integer  "status",               default: 1, null: false
    t.integer  "received_by_id"
    t.datetime "created_at",                       null: false
    t.datetime "updated_at",                       null: false
    t.text     "observations"
    t.date     "reception_date"
    t.integer  "origin_is_pointsale",              null: false
    t.integer  "destiny_is_pointsale",             null: false
  end

  add_index "transfers", ["destiny_id"], name: "index_transfers_on_destiny_id", using: :btree
  add_index "transfers", ["origin_id"], name: "index_transfers_on_origin_id", using: :btree
  add_index "transfers", ["received_by_id"], name: "index_transfers_on_received_by_id", using: :btree
  add_index "transfers", ["user_id"], name: "index_transfers_on_user_id", using: :btree

  create_table "units", force: :cascade do |t|
    t.string   "unit"
    t.integer  "status"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "users", force: :cascade do |t|
    t.string   "userid",                            default: "", null: false
    t.string   "first_name",                        default: "", null: false
    t.string   "last_name",                         default: "", null: false
    t.string   "usertype",                          default: "", null: false
    t.string   "email",                             default: "", null: false
    t.string   "encrypted_password",                default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",                     default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.inet     "current_sign_in_ip"
    t.inet     "last_sign_in_ip"
    t.datetime "created_at",                                     null: false
    t.datetime "updated_at",                                     null: false
    t.integer  "pointsale_id"
    t.string   "unique_session_id",      limit: 20
    t.integer  "status",                            default: 1,  null: false
    t.integer  "warehouse_id"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
  add_index "users", ["userid"], name: "index_users_on_userid", unique: true, using: :btree

  create_table "warehouse_stocks", force: :cascade do |t|
    t.integer  "warehouse_id"
    t.integer  "product_id"
    t.decimal  "stock_min",    default: 0.0
    t.decimal  "stock_max",    default: 0.0
    t.decimal  "stock",        default: 0.0
    t.datetime "created_at",                 null: false
    t.datetime "updated_at",                 null: false
  end

  add_index "warehouse_stocks", ["product_id"], name: "index_warehouse_stocks_on_product_id", using: :btree
  add_index "warehouse_stocks", ["warehouse_id"], name: "index_warehouse_stocks_on_warehouse_id", using: :btree

  create_table "warehouses", force: :cascade do |t|
    t.datetime "created_at",             null: false
    t.datetime "updated_at",             null: false
    t.string   "name"
    t.integer  "status",     default: 1, null: false
    t.string   "prefix",                 null: false
  end

  add_foreign_key "suppliers", "contacts"
end
