updated commission for sale edit
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class Origami::SaleEditController < BaseOrigamiController
|
||||
authorize_resource :class => false
|
||||
authorize_resource class: false
|
||||
# Index for sale item void OR edit
|
||||
def edit
|
||||
sale_id = params[:sale_id]
|
||||
@@ -19,12 +19,13 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
@newsaleitem.qty = saleitemObj.qty * -1
|
||||
@newsaleitem.price = saleitemObj.price * -1
|
||||
@newsaleitem.is_taxable = 1
|
||||
@newsaleitem.product_name = saleitemObj.product_name + " - void"
|
||||
@newsaleitem.product_name = saleitemObj.product_name + ' - void'
|
||||
@newsaleitem.save
|
||||
|
||||
# re-calc tax
|
||||
saleObj = Sale.find(saleitemObj.sale_id)
|
||||
saleObj.compute_without_void
|
||||
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
|
||||
end
|
||||
|
||||
def item_foc
|
||||
@@ -44,6 +45,7 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
# re-calc tax
|
||||
saleObj = Sale.find(saleitemObj.sale_id)
|
||||
saleObj.compute_without_void
|
||||
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
|
||||
end
|
||||
|
||||
# def item_edit
|
||||
@@ -77,16 +79,19 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
saleitemObj.unit_price = update_price
|
||||
saleitemObj.taxable_price = update_qty.to_f * update_price.to_f
|
||||
# saleitemObj.remark = 'edit'
|
||||
if !saleitemObj.product_name.include? "updated"
|
||||
saleitemObj.product_name = saleitemObj.product_name + " - updated"
|
||||
|
||||
unless saleitemObj.product_name.include? 'updated'
|
||||
saleitemObj.product_name = saleitemObj.product_name + ' - updated'
|
||||
end
|
||||
|
||||
saleitemObj.save
|
||||
|
||||
# re-calc tax
|
||||
saleObj = Sale.find(saleitemObj.sale_id)
|
||||
saleObj.compute_without_void
|
||||
end
|
||||
|
||||
ProductCommission.edit_product_commission(saleitemObj)
|
||||
end
|
||||
|
||||
# make cancel void item
|
||||
def item_void_cancel
|
||||
@@ -104,6 +109,7 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
# re-calc tax
|
||||
saleObj = Sale.find(saleitemObj.sale_id)
|
||||
saleObj.compute_without_void
|
||||
ProductCommission.remove_product_commission(saleitemObj)
|
||||
end
|
||||
|
||||
# remove all void items
|
||||
@@ -117,6 +123,7 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
item.remark = nil
|
||||
end
|
||||
item.save
|
||||
ProductCommission.remove_product_commission(item)
|
||||
end
|
||||
|
||||
# re-calc tax
|
||||
@@ -127,5 +134,8 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
sale_id = params[:sale_id]
|
||||
saleObj = Sale.find(sale_id)
|
||||
saleObj.compute_without_void
|
||||
saleObj.sale_items.each do |item|
|
||||
ProductCommission.remove_product_commission(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,14 +5,67 @@ class ProductCommission < ApplicationRecord
|
||||
belongs_to :sale_item, foreign_key: 'sale_item_id'
|
||||
belongs_to :sale, foreign_key: 'sale_id'
|
||||
|
||||
def self.create_product_commission(newSaleItem, oldSaleItem)
|
||||
old_product_commission = ProductCommission.find_by_sale_item_id(oldSaleItem.id)
|
||||
return if old_product_commission.nil?
|
||||
menu_item = MenuItem.find_by_item_code(newSaleItem.product_code)
|
||||
return if menu_item.nil?
|
||||
product_commission = ProductCommission.new
|
||||
commission = Commission.where('product_code = ? AND is_active = ?', menu_item.id, true).take
|
||||
product_commission.product_code = menu_item.id
|
||||
product_commission.product_type = 'menu_item' # use for dummy data ToDo::need to change product type
|
||||
unless commission.nil?
|
||||
product_commission.commission_id = commission.id
|
||||
if commission.commission_type == 'Percentage'
|
||||
product_commission.price = newSaleItem.unit_price * (commission.amount / 100.0)
|
||||
product_commission.amount = product_commission.price * newSaleItem.qty
|
||||
elsif commission.commission_type == 'Net Amount'
|
||||
product_commission.price = commission.amount
|
||||
product_commission.amount = product_commission.price * newSaleItem.qty
|
||||
end
|
||||
end
|
||||
unless old_product_commission.nil?
|
||||
product_commission.commissioner_id = old_product_commission.commissioner_id
|
||||
end
|
||||
product_commission.qty = newSaleItem.qty
|
||||
product_commission.sale_id = newSaleItem.sale_id
|
||||
product_commission.sale_item_id = newSaleItem.sale_item_id
|
||||
product_commission.save
|
||||
end
|
||||
|
||||
def self.edit_product_commission(saleItemObj)
|
||||
menu_item = MenuItem.find_by_item_code(saleItemObj.product_code)
|
||||
commission = Commission.where('product_code = ? AND is_active = ?', menu_item.id, true).take
|
||||
product_commission = ProductCommission.where('sale_item_id = ?', saleItemObj.id).take
|
||||
|
||||
return if commission.nil?
|
||||
product_commission.qty = saleItemObj.qty
|
||||
if commission.commission_type == 'Percentage'
|
||||
product_commission.price = saleItemObj.unit_price * (commission.amount / 100.0)
|
||||
product_commission.amount = product_commission.price * saleItemObj.qty
|
||||
elsif commission.commission_type == 'Net Amount'
|
||||
product_commission.price = commission.amount
|
||||
product_commission.amount = product_commission.price * saleItemObj.qty
|
||||
end
|
||||
product_commission.save
|
||||
puts 'Edit Product Commission Success'
|
||||
end
|
||||
|
||||
def self.remove_product_commission(sale_item_id)
|
||||
transaction = ProductCommission.find_by_sale_item_id(sale_item_id)
|
||||
return if transaction.nil?
|
||||
transaction.destroy
|
||||
puts 'Remove Product Commission Success'
|
||||
end
|
||||
|
||||
def self.get_transaction(from, to, commissioner)
|
||||
transaction = self.all
|
||||
transaction = all
|
||||
if !from.nil? && !to.nil?
|
||||
transaction = transaction.where('updated_at between ? and ?', from, to)
|
||||
end
|
||||
if commissioner != 0
|
||||
transaction = transaction.where(commissioner_id: commissioner)
|
||||
end
|
||||
return transaction
|
||||
transaction
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,8 +28,13 @@ class Promotion < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.combine_item(saleObj)
|
||||
order_id = saleObj.sale_orders[0].order_id
|
||||
itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
|
||||
# order_id = saleObj.sale_orders[0].order_id
|
||||
# itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
|
||||
itemList = []
|
||||
saleObj.sale_orders.each do |so|
|
||||
itemList << OrderItem.where("order_id = ?",so.order_id).group(:item_instance_code).sum(:qty)
|
||||
end
|
||||
return itemList
|
||||
end
|
||||
|
||||
def self.is_promo_day(promoList, day, orderitemList, sale_id)
|
||||
@@ -46,13 +51,15 @@ class Promotion < ApplicationRecord
|
||||
|
||||
def self.find_promo_item(promo, orderitem, sale_id)
|
||||
# item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
|
||||
if promo.original_product.to_s == orderitem[0]
|
||||
if promo.min_qty.to_i > orderitem[1].to_i
|
||||
return false
|
||||
else
|
||||
check_promo_type(promo,orderitem, sale_id)
|
||||
end
|
||||
end
|
||||
orderitem.each do |odr_item|
|
||||
if promo.original_product.to_s == odr_item[0]
|
||||
if promo.min_qty.to_i > odr_item[1].to_i
|
||||
return false
|
||||
else
|
||||
check_promo_type(promo,odr_item, sale_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_promo_type(promo, orderitem, sale_id)
|
||||
@@ -126,7 +133,6 @@ class Promotion < ApplicationRecord
|
||||
# AA - 10 # 3 # BB # orderList, #S34345
|
||||
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id)
|
||||
puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s
|
||||
byebug
|
||||
promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty
|
||||
foc_qty = find_second_item_qty(sale_id, promo_product)
|
||||
if (foc_qty < promotion_qty)
|
||||
@@ -212,9 +218,11 @@ class Promotion < ApplicationRecord
|
||||
saleObj = Sale.find_by_sale_id(sale_id)
|
||||
itemList = combine_item(saleObj)
|
||||
itemList.each do |item|
|
||||
if item[0] == promo_item
|
||||
return item[1]
|
||||
end
|
||||
item.each do |i|
|
||||
if i[0] == promo_item
|
||||
return i[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<%= sale_item.qty %>
|
||||
</td>
|
||||
<td class='unit_price' width="20%">
|
||||
<%= sale_item.unit_price %>
|
||||
<%= sale_item.price %>
|
||||
</td>
|
||||
<td class='commissioner' width="20%">
|
||||
<% product_commission = ProductCommission.find_by_sale_item_id(sale_item.id) %>
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
<th colspan="7"> From Date : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - To Date : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Sale</th>
|
||||
<th>Sale Item</th>
|
||||
<th>Commissioner Name</th>
|
||||
<th>Product Name</th>
|
||||
<th>Qty</th>
|
||||
@@ -44,12 +46,10 @@
|
||||
|
||||
<% @transaction.each do |result| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= result.commissioner.name rescue '-' %>
|
||||
</td>
|
||||
<td>
|
||||
<%= result.commission.menu_item.name rescue '-' %>
|
||||
</td>
|
||||
<td><%= result.sale_id rescue '-' %></td>
|
||||
<td><%= result.sale_item_id rescue '-' %></td>
|
||||
<td><%= result.commissioner.name rescue '-' %></td>
|
||||
<td><%= result.commission.menu_item.name rescue '-' %></td>
|
||||
<td><%= sprintf "%.2f", result.qty.to_f.to_d rescue '-' %></td>
|
||||
<td><%= sprintf "%.2f", result.price.to_f.to_d rescue '-' %></td>
|
||||
<td><%= sprintf "%.2f", result.amount.to_f.to_d rescue '-' %></td>
|
||||
@@ -61,7 +61,7 @@
|
||||
<% end %>
|
||||
|
||||
<tr style="border-top: 3px solid grey;">
|
||||
<td colspan="2"></td>
|
||||
<td colspan="4"></td>
|
||||
<td><b><%= sprintf("%.2f", total_qty) rescue '-' %></b></td>
|
||||
<td><b><%= sprintf("%.2f", total_price) rescue '-' %></b></td>
|
||||
<td><b><%= sprintf("%.2f", total_amount) rescue '-' %></b></td>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<%= f.input :commission_type, :collection => ['Percentage','Net Amount'], prompt: 'Select Commission Type', class: 'form-control' %>
|
||||
<%= f.input :amount %>
|
||||
<label><%= f.check_box :is_active %> Active </label>
|
||||
|
||||
|
||||
</div><br>
|
||||
<div class="form-actions">
|
||||
<%= link_to 'Back', settings_commissions_path, class: 'btn btn-success' %>
|
||||
|
||||
@@ -41,16 +41,16 @@
|
||||
</div>
|
||||
|
||||
<div class="row checkboxes">
|
||||
<%= f.hidden_field :promo_day, :value => "", :class => "form-control col-md-1" %>
|
||||
<div class="col-md-1"><input class="select" type="checkbox" name="Sunday" value="0" id="0"> Sun</div>
|
||||
<div class="col-md-1"><input class="select" type="checkbox" name="Monday" value="1" id="1">Mon</div>
|
||||
<div class="col-md-1"><input class="select" type="checkbox" name="Tuesday" value="2" id="2"> Tue</div>
|
||||
<div class="col-md-1"><input class="select" type="checkbox" name="Wednesday" value="3" id="3"> Wed</div>
|
||||
<div class="col-md-1"><input class="select" type="checkbox" name="Thursday" value="4" id="4">Thu</div>
|
||||
<div class="col-md-1"><input class="select" type="checkbox" name="Friday" value="5" id="5">Fri</div>
|
||||
<div class="col-md-1"><input class="select" type="checkbox" name="Saturday" value="6" id="6">Sat</div>
|
||||
<%= f.hidden_field :promo_day, :value => "", :class => "form-control col-md-1" %>
|
||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Sunday" value="0" id="0"> Sun</div>
|
||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Monday" value="1" id="1">Mon</div>
|
||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Tuesday" value="2" id="2"> Tue</div>
|
||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Wednesday" value="3" id="3"> Wed</div>
|
||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Thursday" value="4" id="4">Thu</div>
|
||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Friday" value="5" id="5">Fri</div>
|
||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Saturday" value="6" id="6">Sat</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<%= f.input :promo_type,input_html: { class: "" },
|
||||
@@ -166,13 +166,13 @@ $(document).ready(function(){
|
||||
|
||||
|
||||
var form = document.getElementById("new_promotion");
|
||||
var inputs = form.getElementsByTagName("input");
|
||||
var inputs = $("input");
|
||||
var arr = [];
|
||||
var count = 0;
|
||||
var day = "[";
|
||||
|
||||
$(".select").click(function() {
|
||||
|
||||
|
||||
$(".selectDay").click(function() {
|
||||
|
||||
// debugger;
|
||||
day = "[";
|
||||
for (var j = 8; j <=15; j += 1){
|
||||
@@ -192,8 +192,8 @@ $(".select").click(function() {
|
||||
}
|
||||
document.getElementById("promotion_promo_day").value = '';
|
||||
document.getElementById("promotion_promo_day").value = day;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$("#promotion_original_product").select2();
|
||||
$(".item_code_place").select2();
|
||||
$(".item_code_place").on('change', function(event) {
|
||||
|
||||
Reference in New Issue
Block a user