show and update changes in commission and report
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,7 +19,7 @@ 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
|
||||
@@ -77,14 +77,17 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
saleitemObj.unit_price = update_price
|
||||
saleitemObj.taxable_price = update_qty.to_f * update_price.to_f
|
||||
# saleitemObj.remark = 'edit'
|
||||
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
|
||||
|
||||
@@ -5,14 +5,42 @@ class ProductCommission < ApplicationRecord
|
||||
belongs_to :sale_item, foreign_key: 'sale_item_id'
|
||||
belongs_to :sale, foreign_key: 'sale_id'
|
||||
|
||||
def self.create_product_commission(saleItemObj)
|
||||
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
|
||||
|
||||
@@ -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' %>
|
||||
|
||||
Reference in New Issue
Block a user