update shift and multiple

This commit is contained in:
Aung Myo
2018-08-07 14:51:17 +06:30
parent 81a387e522
commit 6cbdca4ce6
3 changed files with 59 additions and 27 deletions

View File

@@ -130,9 +130,9 @@ class Origami::PaymentsController < BaseOrigamiController
sale_payment = SalePayment.new
if path.include? ("credit_payment")
sale_payment.process_payment(saleObj, current_user.name, cash, "cash", nil, true)
sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true)
else
sale_payment.process_payment(saleObj, current_user.name, cash, "cash")
sale_payment.process_payment(saleObj, current_user, cash, "cash")
end
if !path.include? ("credit_payment")

View File

@@ -6,13 +6,15 @@ class SalePayment < ApplicationRecord
belongs_to :sale
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by
def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil,payment_for=false)
self.sale = invoice
self.received_amount = cash_amount
self.payment_reference = remark
puts action_by
puts "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
self.action_by = action_by
#get all payment for this invoices
if payment_for
invoice_sale_payments = SalePayment.get_sale_payment_for_credit(invoice)
@@ -84,12 +86,12 @@ class SalePayment < ApplicationRecord
remark = "#{self.sale_payment_id}||#{shift_sale_id} -> #{remark}"
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by.name)
if payment_method == "cash"
update_shift_for_credit_payment
end
else
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by.name)
end
# update complete order items in oqs
@@ -107,7 +109,7 @@ class SalePayment < ApplicationRecord
else
#record an payment in sale-audit
remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by)
sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by.name)
return false, "No outstanding Amount"
end
@@ -620,15 +622,25 @@ class SalePayment < ApplicationRecord
# update for cashier shift
def update_shift
shift = ShiftSale.current_open_shift(self.action_by.id)
if shift.nil?
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
end
if !shift.nil?
shift.update(self.sale)
self.sale.shift_sale_id = shift.id
self.sale.cashier_id = shift.employee_id
self.sale.cashier_name = Employee.find(shift.employee_id).name
self.sale.save
else
shift = ShiftSale.current_shift
shift.update(self.sale)
self.sale.shift_sale_id = shift.id
self.sale.cashier_id = shift.employee_id
self.sale.cashier_name = Employee.find(shift.employee_id).name
self.sale.save
end
end

View File

@@ -43,24 +43,36 @@
<th><%= t("views.right_panel.detail.giftvoucher_sales") %></th>
</tr>
</thead>
<% if @print_settings.precision.to_i > 0
precision = @print_settings.precision
else
precision = 0
end
#check delimiter
if @print_settings.delimiter
delimiter = ","
else
delimiter = ""
end
%>
<% unless @sale_data.empty? %>
<tbody>
<% @sale_data.each do |sale| %>
<tr>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:mpu_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:master_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:visa_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:jcb_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:unionpay_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:alipay_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:paymal_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:dinga_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:junctionpay_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:paypar_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]-sale[:total_change_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_delimiter(sprintf("%.2f",sale[:giftvoucher_amount]), :delimiter => ',') rescue '-'%></td>
<td><%= number_with_precision(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:paymal_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
</tr>
<% end %>
@@ -81,7 +93,7 @@
<tr>
<th> <%= t("views.right_panel.detail.shift_name") %> </th>
<th> <%= t("views.right_panel.detail.receipt_no") %></th>
<th><%= t("views.right_panel.detail.receipt_no") %></th>
<th> <%= t :cashier %> <%= t("views.right_panel.detail.name") %></th>
<th> <%= t :payment_method %></th>
<th> <%= t("views.right_panel.detail.amount") %> </th>
@@ -91,7 +103,11 @@
<tbody>
<% total = 0 %>
<% @pyament_method.each do |payment| %>
<% total += payment.payment_amount %>
<% if payment.payment_method === 'cash'
total += payment.payment_amount - payment.change_amount
else
total += payment.payment_amount
end%>
<tr>
<% if @shift_from.nil? && @shift_to.nil? %>
<td><%= payment.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%></td>
@@ -102,8 +118,12 @@
<td><%= payment.cashier_name rescue '-' %></td>
<!--<td><%= payment.sale.customer.name rescue '-' %></td>-->
<td><%= payment.payment_method rescue '-' %></td>
<td><%= payment.payment_amount rescue '-' %></td>
<td><%= payment.sale.grand_total rescue '-' %></td>
<% if payment.payment_method === 'cash' %>
<td><%= number_with_precision(payment.payment_amount - payment.change_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> </td>
<%else%>
<td><%= number_with_precision(payment.payment_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> </td>
<%end%>
<td><%= number_with_precision(payment.sale.grand_total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
</tr>
@@ -111,7 +131,7 @@
<%if total>0%>
<tr>
<td colspan="4" style="text-align: right;"><strong >Total </strong></td>
<td colspan="2"><strong><%=total%></strong></td>
<td colspan="2"><strong><%=number_with_precision(total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %></strong></td>
</tr>
<%end%>
</tbody>