浏览代码

Merge branch 'chemi_branch' of SML/pos-boutique into master

Jose Miguel Ledon 6 年之前
父节点
当前提交
6d9541c7a2

+ 1 - 1
app/controllers/pos_configs_controller.rb

@@ -52,6 +52,6 @@ class PosConfigsController < ApplicationController
   # Never trust parameters from the scary internet, only allow the white list through.
   def pos_config_params
     params[:pos_config]
-    params.require(:pos_config).permit(:cancel_partial_payment, :refund_sale, :days_cancel_sale, :days_cancel_purchase, :tax_percent, :time_zone, :gain_margin, :ticket_description, :reserve_sale_percent, :days_cancel_reserved, :commission_percent, :ticket_footer, :ticket_img, :ticket_img_cache, :haggle_in_sale_percent, :enable_haggle)
+    params.require(:pos_config).permit(:cancel_partial_payment, :refund_sale, :days_cancel_sale, :days_cancel_purchase, :tax_percent, :time_zone, :gain_margin, :ticket_description, :reserve_sale_percent, :days_cancel_reserved, :commission_percent, :ticket_footer, :ticket_img, :ticket_img_cache, :haggle_in_sale_percent, :enable_haggle, :add_iva_to_pre_sales)
   end
 end

+ 7 - 1
app/models/pre_sale.rb

@@ -46,7 +46,13 @@ class PreSale < ActiveRecord::Base
     end
     self.tax = 0.0
     if product.include_sale_tax?
-      self.tax = ((PosConfig.first.tax_percent / 100) * amount).round(2)
+      pos_config = PosConfig.first
+      if pos_config.add_iva_to_pre_sales?
+        self.tax = ((pos_config.tax_percent.to_f / 100) * amount).round(2)
+      else
+        self.amount = ((amount * 100) / (100 + pos_config.tax_percent.to_f)).round(2)
+        self.tax = ((pos_config.tax_percent.to_f / 100) * amount).round(2)
+      end
     end
     self.total = amount + tax
     true

+ 15 - 0
app/models/product.rb

@@ -469,6 +469,7 @@ class Product < ActiveRecord::Base
     products = Product.vigentes
     products.each do |product|
       product.generate_barcode
+      product.skip_sku_validation = true
       product.save
     end
   end
@@ -499,5 +500,19 @@ class Product < ActiveRecord::Base
     end
     puts "TERMINÉ, generé: #{counter} imagenes de barcode"
   end
+
+  def self.generate_sku_existing_prods
+    products = Product.vigentes
+    products.each do |product|
+      product.sku = if product.category.parent.present?
+        # es subcategory
+        "#{product.category.parent.category.slice(0..2)}-#{product.id}-#{product.category.gsub(/[aeiou]/i, '').slice(0..2).upcase}-#{product.id}"
+      else
+        "#{product.category.category.slice(0..2)}-#{product.id}"
+      end
+      product.skip_sku_validation = true
+      product.save
+    end
+  end
 end
 

+ 20 - 1
app/views/pos_configs/_form.html.erb

@@ -88,8 +88,23 @@
           </div>
         </div>
         <div class="form-group">
+          <%= f.label :add_iva_to_pre_sales, { class: "col-md-3 col-sm-3 control-label" } do %> ¿Sumar o desglosar IVA en venta? <span class="required">*</span><% end %>
+          <div class="col-md-1 col-sm-2">
+            <%= f.check_box(:add_iva_to_pre_sales,
+              {
+                class: "make-switch",
+                data: {
+                  on_color: "success",
+                  off_color: "danger",
+                  on_text: "Sumar",
+                  off_text: "Desglosar"
+                }
+              }, "true","false"
+            ) %>
+            <%= f.hidden_field :add_iva_to_pre_sales %>
+          </div>
           <div id="haggle_div" class="<%= 'hidden' unless @pos_config.enable_haggle %>">
-            <%= f.label :haggle_in_sale_percent, { class: "col-md-3 col-sm-3 control-label" } do %>Porcentaje máximo de regateo para ventas
+            <%= f.label :haggle_in_sale_percent, { class: "col-md-2 col-sm-2 col-md-offset-1 control-label" } do %>% máximo de regateo en ventas
               <span class="required">*</span>
             <% end %>
             <div class="col-md-3 col-sm-2">
@@ -172,4 +187,8 @@
     }
     $('input[name="pos_config[enable_haggle]"]').val(state);
   });
+
+  $('input[name="pos_config[add_iva_to_pre_sales]"]').on('switchChange.bootstrapSwitch', function(event, state) {
+    $('input[name="pos_config[add_iva_to_pre_sales]"]').val(state);
+  });
 </script>

+ 1 - 1
app/views/pre_sales/_pre_sale.html.erb

@@ -1,5 +1,5 @@
 <tr id="pre_sale_<%= pre_sale.id %>">
-  <td> # <%= hidden_field_tag 'include_tax', pre_sale.product.include_sale_tax %> </td>
+  <td> # <%= hidden_field_tag "amount_" + pre_sale.id.to_s, pre_sale.amount %></td>
   <td><%= pre_sale.product.sku %></td>
   <td class="text-center"><img src="<%= pre_sale.product.small_img %>" width="100" height="100"/></td>
   <td>

+ 31 - 42
app/views/sales/_form.html.erb

@@ -1,6 +1,7 @@
 <%= form_for(@sale, :remote => true, :html => {:class=>"form-horizontal form-barcode", :id=> "sale_form"}) do |f| %>
 	<div class="portlet-body form">
 		<%= hidden_field_tag :barcode_for_sale %>
+		<%= hidden_field_tag "add_iva_to_pre_sales", @pos_config.add_iva_to_pre_sales %>
 		<!-- este error explanation se usa para mostrar errores de presales e inventarios -->
 		<!-- <div id="error_explanation"></div> -->
 		<!-- este error explanation es cuando falla alguna validacion de la venta en sí -->
@@ -492,13 +493,15 @@
 						pre_sale: { quantity: input.val() }
 					},
 					success: function(xhr, status, error) {
-            var tax_ = xhr.tax;
-            var discount_ = xhr.discount;
-            var total_ = xhr.total;
+						var amount_ = xhr.amount;
+						var tax_ = xhr.tax;
+						var discount_ = xhr.discount;
+						var total_ = xhr.total;
 
-            $("#tax_" + preSaleId).val(tax_);
-            $("#discount_" + preSaleId).val(discount_);
-            $("#total_" + preSaleId).val(total_);
+						$("#amount_" + preSaleId).val(amount_);
+						$("#tax_" + preSaleId).val(tax_);
+						$("#discount_" + preSaleId).val(discount_);
+						$("#total_" + preSaleId).val(total_);
 
 						input.closest('tr').find('td:eq(6) label').text("$ " + xhr.tax);
 						input.closest('tr').find('td:eq(7) label').text("$ " + xhr.discount);
@@ -512,19 +515,21 @@
 						var data = JSON.parse(xhr.responseText);
 						input.val(data.quantity);
 						toastr["error"](data.errors);
+						var amount_ = (Math.round(data.presale.amount * 100) / 100).toFixed(2);
 						var tax_ = (Math.round(data.presale.tax * 100) / 100).toFixed(2);
-            var discount_ = (Math.round(data.presale.discount * 100) / 100).toFixed(2);
-            var total_ = (Math.round(data.presale.total * 100) / 100).toFixed(2);
+						var discount_ = (Math.round(data.presale.discount * 100) / 100).toFixed(2);
+						var total_ = (Math.round(data.presale.total * 100) / 100).toFixed(2);
 
-            $("#tax_" + preSaleId).val(tax_);
-            $("#discount_" + preSaleId).val(discount_);
-            $("#total_" + preSaleId).val(total_);
+						$("#amount_" + preSaleId).val(amount_);
+						$("#tax_" + preSaleId).val(tax_);
+						$("#discount_" + preSaleId).val(discount_);
+						$("#total_" + preSaleId).val(total_);
 
-            input.closest('tr').find('td:eq(6) label').text("$ " + tax_);
-            input.closest('tr').find('td:eq(7) label').text("$ " + discount_);
-            input.closest('tr').find('td:eq(8) label').text("$ " + total_);
+						input.closest('tr').find('td:eq(6) label').text("$ " + tax_);
+						input.closest('tr').find('td:eq(7) label').text("$ " + discount_);
+						input.closest('tr').find('td:eq(8) label').text("$ " + total_);
 
-            calculateTotals();
+						calculateTotals();
 					}
 				});
 			}, 500);
@@ -536,37 +541,21 @@
 		var discount = 0;
 		var tax = 0;
 		var total = 0;
-
-		// if($('#products_table').dataTable().fnGetData().length > 0) {
-		// 	$('#products_table tbody tr').each(function() {
-		// 		// quantity = parseFloat(($(this).find('td:nth-child(5) input').val()));
-		// 		// price = parseFloat($(this).find('td:nth-child(6)').text());
-		// 		// amount += (quantity * price);
-		// 		amount += parseFloat($(this).find('td:nth-child(9)').text()); // importe
-		// 	});
-		// }
-
 		$('#products_table').dataTable().fnGetNodes().forEach(function(row) {
-      quantity = parseFloat(($(row).find('td:nth-child(5) input').val()));
-      price = parseFloat($(row).find('td:nth-child(6) input').val());
-      amount += (quantity * price);
-      tax += parseFloat($(row).find('td:nth-child(7) input').val());
-      discount += parseFloat($(row).find('td:nth-child(8) input').val());
-    });
+			quantity = parseFloat(($(row).find('td:nth-child(5) input').val()));
+			price = parseFloat($(row).find('td:nth-child(6) input').val());
+			amount += parseFloat(($(row).find('td:nth-child(1) input').val()));
+			tax += parseFloat($(row).find('td:nth-child(7) input').val());
+			discount += parseFloat($(row).find('td:nth-child(8) input').val());
+		});
 
-		// $('#products_table tbody tr td:nth-child(7)').each(function() {
-		// 	tax += parseFloat($(this).text());
-		// });
-		// $('#products_table tbody tr td:nth-child(8)').each(function() {
-		// 	discount += parseFloat($(this).text());
-		// });
+		amount = amount + discount;
+		total = amount + tax - discount;
 
-		total = amount + tax;
-		total -= discount;
 		$('#tax').val((Math.round(tax * 100) / 100).toFixed(2));
-    $('#discount').val((Math.round(discount * 100) / 100).toFixed(2));
-    $('#amount').val((Math.round(amount * 100) / 100).toFixed(2));
-    $('#total').val((Math.round(total * 100) / 100).toFixed(2));
+		$('#discount').val((Math.round(discount * 100) / 100).toFixed(2));
+		$('#amount').val((Math.round(amount * 100) / 100).toFixed(2));
+		$('#total').val((Math.round(total * 100) / 100).toFixed(2));
 		if(total < parseFloat($("#available_credit").val())) {
 			$('#types_credit').attr('disabled', false);
 			$('#types_credit').closest('label').removeClass('disabled');

+ 10 - 9
app/views/sales/create_haggle.js.erb

@@ -1,14 +1,15 @@
-$('#products_table tbody tr').each(function() {
- 	trTxt = $(this).attr('id');
+$('#products_table').dataTable().fnGetNodes().forEach(function(row) {
+ 	trTxt = $(row).attr('id');
  	id = parseInt(trTxt.substring(trTxt.lastIndexOf('_') + 1, trTxt.length));
  	if (id == <%= @pre_sale.id %>) {
- 		$(this).find('td:eq(7) label').text('<%= number_to_currency(@pre_sale.discount, precision: 2) %>');
-    $(this).find('td:eq(7) input').val('<%= @pre_sale.discount.round(2) %>');
-    $(this).find('td:eq(6) label').text('<%= number_to_currency(@pre_sale.tax, precision: 2) %>');
-    $(this).find('td:eq(6) input').val('<%= @pre_sale.tax.round(2) %>');
- 		$(this).find('td:eq(8) label').text('<%= number_to_currency(@pre_sale.total, precision: 2) %>');
-    $(this).find('td:eq(8) input').val('<%= @pre_sale.total.round(2) %>');
- 		$(this).find(".hagglebutton").addClass("disabled").click(function(e){ e.preventDefault();});
+		$(row).find('td:eq(0) input').val('<%= @pre_sale.amount.round(2) %>');
+		$(row).find('td:eq(7) label').text('<%= number_to_currency(@pre_sale.discount, precision: 2) %>');
+		$(row).find('td:eq(7) input').val('<%= @pre_sale.discount.round(2) %>');
+		$(row).find('td:eq(6) label').text('<%= number_to_currency(@pre_sale.tax, precision: 2) %>');
+		$(row).find('td:eq(6) input').val('<%= @pre_sale.tax.round(2) %>');
+		$(row).find('td:eq(8) label').text('<%= number_to_currency(@pre_sale.total, precision: 2) %>');
+		$(row).find('td:eq(8) input').val('<%= @pre_sale.total.round(2) %>');
+ 		$(row).find(".hagglebutton").addClass("disabled").click(function(e){ e.preventDefault();});
  	}
 });
 calculateTotals();

+ 5 - 0
db/migrate/20190205081621_add_column_add_iva_to_pre_sales_in_pos_config.rb

@@ -0,0 +1,5 @@
+class AddColumnAddIvaToPreSalesInPosConfig < ActiveRecord::Migration
+  def change
+    add_column :pos_configs, :add_iva_to_pre_sales, :boolean, default: false
+  end
+end

+ 22 - 4
db/schema.rb

@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20181221220426) do
+ActiveRecord::Schema.define(version: 20190205081621) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -361,10 +361,10 @@ ActiveRecord::Schema.define(version: 20181221220426) do
     t.integer  "days_cancel_sale"
     t.integer  "days_cancel_purchase"
     t.decimal  "tax_percent"
-    t.string   "time_zone",               limit: 255,                          default: "",   null: false
+    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.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
@@ -377,6 +377,7 @@ ActiveRecord::Schema.define(version: 20181221220426) do
     t.integer  "haggle_in_sale_percent"
     t.string   "ticket_img"
     t.boolean  "enable_haggle",                                                default: true
+    t.boolean  "add_iva_to_pre_sales",                                         default: false
   end
 
   create_table "pre_purchases", force: :cascade do |t|
@@ -585,6 +586,16 @@ ActiveRecord::Schema.define(version: 20181221220426) do
     t.decimal  "exchange",      precision: 10, scale: 2
   end
 
+  create_table "roles", force: :cascade do |t|
+    t.string   "name"
+    t.integer  "resource_id"
+    t.string   "resource_type"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
+
+  add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree
+
   create_table "sales", force: :cascade do |t|
     t.integer  "customer_id"
     t.integer  "user_id"
@@ -813,6 +824,13 @@ ActiveRecord::Schema.define(version: 20181221220426) do
   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 "users_roles", id: false, force: :cascade do |t|
+    t.integer "user_id"
+    t.integer "role_id"
+  end
+
+  add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree
+
   create_table "warehouse_stocks", force: :cascade do |t|
     t.integer  "warehouse_id"
     t.integer  "product_id"

二进制
erd.pdf