add credit note payment process for online order

This commit is contained in:
phyusin
2018-09-17 11:15:34 +06:30
parent 07a6e45edc
commit 19fa2ecf54
12 changed files with 248 additions and 78 deletions

View File

@@ -48,4 +48,30 @@ class Origami::CreditPaymentsController < BaseOrigamiController
end
end
def create_credit_payment
arr_sale = JSON.parse(params[:data])
if !ShiftSale.current_shift.nil?
if !arr_sale.nil?
arr_sale.each do |arr_sale|
arr_sale.each do |sale|
if(Sale.exists?(sale[0]))
saleObj = Sale.find(sale[0])
remark = "credit note payment for Receipt No #{saleObj.receipt_no}"
sale_payment = SalePayment.new
@status, @sale = sale_payment.process_payment(saleObj, current_user, sale[1], "cash", remark, true)
end
end
end
end
if @status
render :json => {status: true}
else
render :json => {status: false, message: 'Some error occurred!'}
end
else
render :json => {status: false, message: 'No current shift open for this employee!'}
end
end
end

View File

@@ -2,6 +2,7 @@ class Reports::CreditPaymentController < BaseReportController
authorize_resource :class => false
def index
@filter_for_credit = [['All',''],['Paid','paid'],['Unpaid','unpaid']]
@sources = [["All",''], ["Cashier","cashier"],["Quick Service","quick_service"],["Online Order","doemal_order"]]
from, to = get_date_range_from_params
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED)
@@ -18,7 +19,8 @@ authorize_resource :class => false
end
@filter = params[:filter_check]
@sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to,@filter)
@order_source = params[:order_source]
@sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to,@filter,@order_source)
@from = from
@to = to

View File

@@ -6,27 +6,34 @@ class Transactions::CreditNotesController < ApplicationController
# GET /transactions/sales
# GET /transactions/sales.json
def index
@sources = [["All",''], ["Cashier","cashier"],["Quick Service","quick_service"],["Online Order","doemal_order"]]
@customers = Customer.all
filter = params[:filter]
customer = params[:customer]
from = params[:from]
to = params[:to]
if filter.nil? && from.nil? && to.nil? && customer.nil?
@credit_notes = Sale.where('payment_status = ?', Sale::SALE_STATUS_OUTSTANDING)
@credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20)
else
sale = Sale.search_credit_sales(customer,filter,from,to)
if sale.count > 0
@credit_notes = sale
@credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20)
else
@credit_notes = 0
end
end
filter = params[:filter]
customer = params[:customer]
from = params[:from]
to = params[:to]
order_source = params[:order_source]
if filter.nil? && from.nil? && to.nil? && customer.nil? && order_source.nil?
@credit_notes = Sale.select("sales.*, orders.source")
.joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.where("(CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount)
FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote')
THEN NULL ELSE payment_method='creditnote' END)")
.joins(" JOIN bookings ON bookings.sale_id=sales.sale_id")
.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
.joins(" JOIN orders ON orders.order_id=booking_orders.order_id")
@credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20)
else
sale = Sale.search_credit_sales(customer,filter,from,to,order_source)
if !sale.nil?
@credit_notes = sale
@credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20)
else
@credit_notes = 0
end
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @credit_notes }

View File

@@ -64,6 +64,7 @@ class OrderReservation < ApplicationRecord
order_reservation.transaction_ref = order_reserve[:reference]
if order_reserve[:order_info]
order_reservation.item_count = order_reserve[:order_info][:items].count
order_reservation.payment_methods = order_reserve[:payment_info][:payment_methods].to_json
order_reservation.payment_type = order_reserve[:payment_info][:payment_type]
order_reservation.payment_status = order_reserve[:payment_info][:payment_status]
order_reservation.payment_ref = order_reserve[:payment_info][:payment_ref]
@@ -164,8 +165,12 @@ class OrderReservation < ApplicationRecord
#end rounding adjustment
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user, saleObj.grand_total, "cash")
if(order.payment_type == "COD")
sale_payment.process_payment(saleObj, current_user, saleObj.grand_total, "cash")
else
remark = "credit payment for Receipt No #{saleObj.receipt_no}"
@status, @sale = sale_payment.process_payment(saleObj, current_user, saleObj.grand_total, "creditnote", remark)
end
#order status send to doemal
callback_response = send_status_to_ordering(order.callback_url,order.transaction_ref,DELIVERED)
#order reservation status updated

View File

@@ -737,7 +737,7 @@ class Sale < ApplicationRecord
end
def self.search_credit_sales(customer,filter,from,to)
def self.search_credit_sales(customer,filter,from,to,order_source="")
if filter.blank?
keyword = ''
else
@@ -750,12 +750,30 @@ class Sale < ApplicationRecord
custo = "and customer_id = '#{customer}'"
end
if from.present? && to.present?
sale = Sale.all.joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and sp.payment_method = 'creditnote' #{keyword} #{custo}", from,to)
if order_source.blank?
source = ""
else
sale = Sale.all.joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.where("sp.payment_method ='creditnote' #{keyword} #{custo}")
if order_source == "cashier"
source = "and orders.source='cashier' or orders.source='emenu'"
else
source = "and orders.source='#{order_source}'"
end
end
if from.present? && to.present?
sale = Sale.select("sales.*,orders.source").joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.joins(" JOIN bookings ON bookings.sale_id=sales.sale_id")
.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
.joins(" JOIN orders ON orders.order_id=booking_orders.order_id")
.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and (CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount)
FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) #{keyword} #{custo} #{source}", from,to)
else
sale = Sale.select("sales.*,orders.source").joins(" JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.joins(" JOIN bookings ON bookings.sale_id=sales.sale_id")
.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
.joins(" JOIN orders ON orders.order_id=booking_orders.order_id")
.where("(CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount)
FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) #{keyword} #{custo} #{source}")
end
end
@@ -1186,7 +1204,7 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
return query
end
def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter)
def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source)
sub_query = "SELECT (CASE WHEN SUM(payment_amount) > 0
THEN DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') ELSE '-' END)
FROM `sale_payments`
@@ -1223,10 +1241,19 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter)
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
WHERE sale_audits.sale_id = s.sale_id) = 0"
end
if order_source.blank?
source = ""
else
if order_source == "cashier"
source = "and orders.source='cashier' or orders.source='emenu'"
else
source = "and orders.source='#{order_source}'"
end
end
query = SalePayment.select("s.receipt_no, sale_payments.*,
SUM(sale_payments.payment_amount) as payment_amount,
s.receipt_date as sale_date,
orders.source as order_source,
s.cashier_name as cashier_name,
(#{sub_query}) as credit_payment_receipt_date,
(#{sub_query1}) as credit_payment,
@@ -1234,13 +1261,16 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter)
(#{sub_query2}) as credit_payment_shift_name")
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.joins("INNER JOIN shift_sales ss ON ss.id = s.shift_sale_id")
.joins("INNER JOIN bookings ON bookings.sale_id=s.sale_id")
.joins("INNER JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
.joins("INNER JOIN orders ON orders.order_id=booking_orders.order_id")
if shift.present?
query = query.where("sale_payments.payment_method= 'creditnote' and s.sale_status = 'completed' #{filter_check} and s.shift_sale_id in (?)",shift.to_a)
query = query.where("sale_payments.payment_method= 'creditnote' and s.sale_status = 'completed' #{filter_check} and s.shift_sale_id in (?) #{source}",shift.to_a)
elsif shift_sale_range.present?
query = query.where("sale_payments.payment_method='creditnote' and s.sale_status = 'completed' #{filter_check} and s.shift_sale_id in (?)",shift_sale_range.to_a)
query = query.where("sale_payments.payment_method='creditnote' and s.sale_status = 'completed' #{filter_check} and s.shift_sale_id in (?) #{source}",shift_sale_range.to_a)
else
query = query.where("sale_payments.payment_method='creditnote' and s.sale_status = 'completed' #{filter_check} and s.receipt_date between ? and ? ",from,to)
query = query.where("sale_payments.payment_method='creditnote' and s.sale_status = 'completed' #{filter_check} and s.receipt_date between ? and ? #{source}",from,to)
end
query = query.group("s.sale_id")
end

View File

@@ -24,6 +24,10 @@
<%= select_tag "filter_check", options_for_select(@filter_for_credit, :selected => params[:filter_check]), :class => "form-control", :style => "height: 37px;" %>
</div>
<% end %>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<label class="font-14"><%= t("views.right_panel.detail.order_source") %></label>
<%= select_tag "order_source", options_for_select(@sources, :selected => params[:order_source]), :class => "form-control" %>
</div>
<div class="form-group col-md-2">
<!-- <label class="">Select Shift Period</label> -->
<label class="font-20">From</label>
@@ -37,12 +41,14 @@
<label class="font-20">All Shift</label>
<select class="form-control select" name="shift_name" id="shift_name" style="height: 37px;">
</select>
</div>
<div class="form-group col-md-1 ">
</div>
</div>
<div class="row clearfix">
<div class="form-group col-md-12" align="right">
<br>
<input type="submit" value="Generate Report" class='btn btn-primary'>
</div>
</div>
</div>
</div>
<% end %>
<% end %>
</div>

View File

@@ -47,6 +47,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.order_source") %></th>
<th> <%= t :cashier %> <%= t("views.right_panel.detail.name") %></th>
<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
<th> <%= t("views.right_panel.detail.credit_amount") %> </th>
@@ -70,6 +71,15 @@
<td><%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%></td>
<% end %>
<td><%= credit.receipt_no rescue '-' %></td>
<td>
<%if credit.order_source == "cashier" || credit.order_source == "emenu" %>
Cashier
<% elsif credit.order_source == "quick_service" %>
Quick Service
<% else %>
Online Order
<% end %>
</td>
<td><%= credit.cashier_name rescue '-' %></td>
<td><%= credit.sale.customer.name rescue '-' %></td>
<td><%= number_with_precision(credit.payment_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>

View File

@@ -19,6 +19,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.order_source") %></th>
<th> <%= t :cashier %> <%= t("views.right_panel.detail.name") %></th>
<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
<th> <%= t("views.right_panel.detail.credit_amount") %> </th>
@@ -42,6 +43,15 @@
<td><%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%></td>
<% end %>
<td><%= credit.receipt_no rescue '-' %></td>
<td>
<%if credit.order_source == "cashier" || credit.order_source == "emenu" %>
Cashier
<% elsif credit.order_source == "quick_service" %>
Quick Service
<% else %>
Online Order
<% end %>
</td>
<td><%= credit.cashier_name rescue '-' %></td>
<td><%= credit.sale.customer.name rescue '-' %></td>
<td><%= credit.payment_amount rescue '-' %></td>

View File

@@ -34,13 +34,17 @@
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<label class="font-14"><%= t("views.right_panel.detail.select_customer") %></label>
<select class="selectpicker form-control col-md-12 " name="customer" style="height: 40px" >
<select class="selectpicker form-control col-md-12" name="customer">
<option value=""><%= t("views.right_panel.detail.select_customer") %></option>
<% @customers.each do |customer| %>
<option value="<%= customer.customer_id %>">
<%= customer.name %></option>
<%end %>
</select>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<label class="font-14"><%= t("views.right_panel.detail.order_source") %></label>
<%= select_tag "order_source", options_for_select(@sources, :selected => params[:order_source]), :class => "form-control" %>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<label class="font-14"><%= t("views.right_panel.detail.from") %></label>
@@ -67,38 +71,61 @@
</div>
<div class="card">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th><%= t("views.right_panel.detail.sale_id") %></th>
<th><%= t("views.right_panel.detail.receipt_no") %></th>
<th><%= t("views.right_panel.detail.credit_amount") %></th>
<th><%= t :cashier %></th>
<th><%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
<th><%= t("views.right_panel.detail.receipt_date") %></th>
</tr>
</thead>
<tbody>
<% if @credit_notes != 0 %>
<% @credit_notes.each do |sale| %>
<tr>
<td><%= link_to sale.sale_id, transactions_sale_path(sale) %></td>
<td><%= sale.receipt_no %></td>
<td><%credit = SalePayment.where('sale_id = ? AND payment_method=?', sale.sale_id,"creditnote").first %>
<%= credit.payment_amount rescue '-' %>
</td>
<td><%= sale.cashier_name rescue '-' %></td>
<td><%= link_to sale.customer.name, crm_customer_path(sale.customer_id) %></td>
<td> <%= sale.receipt_date.strftime("%d-%m-%Y %I:%M %p") %> </td>
</tr>
<% if (!@credit_notes.empty?) && (params[:order_source] == "doemal_order") %>
<div class="row pt-3 pb-3 pr-3 float-right">
<div class="col-md-12 col-sm-12 col-lg-12">
<button class="btn btn-lg bg-blue waves-effect credit_payment"><%= t :credit %> <%= t :payment %></button>
</div>
</div>
<% end %>
<table class="table table-striped">
<thead>
<tr>
<% if params[:order_source] == "doemal_order" %>
<th></th>
<% end %>
<% else %>
<tr><td colspan="8"><strong><p style="text-align: center"><%= t("views.right_panel.detail.no_data_txt") %>....</p></strong></td></tr>
<% end %>
</tbody>
</table>
<th><%= t("views.right_panel.detail.sale_id") %></th>
<th><%= t("views.right_panel.detail.receipt_no") %></th>
<th><%= t("views.right_panel.detail.credit_amount") %></th>
<th><%= t :cashier %></th>
<th><%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
<th><%= t("views.right_panel.detail.order_source") %></th>
<th><%= t("views.right_panel.detail.receipt_date") %></th>
</tr>
</thead>
<tbody>
<% if @credit_notes != 0 %>
<% @credit_notes.each do |sale| %>
<tr>
<% if params[:order_source] == "doemal_order" %>
<td><input type="checkbox" class="" name="chk_order" value="<%= sale.sale_id %>"></td>
<% end %>
<td><%= link_to sale.sale_id, transactions_sale_path(sale) %></td>
<td><%= sale.receipt_no %></td>
<td class="credit_<%= sale.sale_id %>"><%credit = SalePayment.where('sale_id = ? AND payment_method=?', sale.sale_id,"creditnote").first %>
<%= credit.payment_amount rescue '-' %>
</td>
<td><%= sale.cashier_name rescue '-' %></td>
<td><%= link_to sale.customer.name, crm_customer_path(sale.customer_id) %></td>
<td>
<%if sale.source == "cashier" || sale.source == "emenu" %>
Cashier
<% elsif sale.source == "quick_service" %>
Quick Service
<% else %>
Online Order
<% end %>
</td>
<td> <%= sale.receipt_date.strftime("%d-%m-%Y %I:%M %p") %> </td>
</tr>
<% end %>
<% else %>
<tr><td colspan="8"><strong><p style="text-align: center"><%= t("views.right_panel.detail.no_data_txt") %>....</p></strong></td></tr>
<% end %>
</tbody>
</table>
<br>
<% if @credit_notes != 0 %>
<%= paginate @credit_notes %>
@@ -109,20 +136,64 @@
</div>
</div>
<!--
<script type="text/javascript">
var arr_sale = [];
$(function () {
$('.datepicker').datepicker({
format : 'dd-mm-yyyy',
autoclose: true
});
$('.datepicker').attr('ReadOnly','true');
$('.datepicker').css('cursor','pointer');
$("input[name='chk_order']").on('click',function(){
var arr = {};
if($(this).is(':checked')){
arr[$(this).val()] = parseFloat($(".credit_"+$(this).val()).html());
// console.log(arr);
arr_sale.push(arr);
}else{
arr[$(this).val()] = parseFloat($(".credit_"+$(this).val()).html());
arr_sale = removeItem(arr_sale, arr, $(this).val());
}
// console.log(arr_sale);
});
$(".credit_payment").on('click', function(){
$.ajax({
type: 'POST',
url: '/origami/payment/credit_payment',
data: {data: JSON.stringify(arr_sale)},
success: function (result) {
// console.log(result);
if (result.status == true) {
swal({
title: "Information!",
text: "Credit Payment Successfully",
html: true,
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick: false
}, function () {
window.location.reload();
});
}else{
swal("Opps",result.message,"warning");
}
}
});
});
});
</script> -->
function removeItem(arr_item, remove, sale_id){
if((arr_item!=undefined) && (arr_item!=null)){
if(arr_item.length > 0){
$.each(arr_item, function(i_key, i_value){
$.each(i_value, function(key,val){
if(key == sale_id){
arr_item.splice(arr_item.indexOf(key),1);
}
});
});
}
}
return arr_item;
}
</script>

View File

@@ -497,6 +497,7 @@ en:
out_time: "Out Time"
transaction_fee: "Transaction Fee"
checked_by: "Checked By"
order_source: "Order Source"
code_txt: "code "
charge_txt: "charge"

View File

@@ -491,6 +491,7 @@ mm:
out_time: "Out Time"
transaction_fee: "Transaction Fee"
checked_by: "Checked By"
order_source: "Order Source"
code_txt: "ကုတ်ဒ် "
charge_txt: "ကောက်ခံသည်"

View File

@@ -202,6 +202,7 @@ scope "(:locale)", locale: /en|mm/ do
post 'payment/junctionpay' => 'junction_pay#create'
post 'payment/dinga' => 'dinga#create'
post 'payment/gift_voucher' => 'gift_voucher#create'
post 'payment/credit_payment' => 'credit_payments#create_credit_payment'
post 'payment/:type/change_tax' => 'payments#change_tax', :defaults => {:format => 'json'}