merge with settings_backend
This commit is contained in:
@@ -36,11 +36,13 @@ class SaleItem < ApplicationRecord
|
|||||||
beverage_prices=0
|
beverage_prices=0
|
||||||
|
|
||||||
sale_items.each do |si|
|
sale_items.each do |si|
|
||||||
food_price, beverage_price = self.get_price(si.sale_item_id)
|
food_price, beverage_price = self.get_price(si.sale_item_id)
|
||||||
|
|
||||||
food_prices = food_prices + food_price
|
food_prices = food_prices + food_price
|
||||||
beverage_prices = beverage_prices + beverage_price
|
beverage_prices = beverage_prices + beverage_price
|
||||||
end
|
end
|
||||||
|
puts food_prices
|
||||||
|
puts beverage_prices
|
||||||
return food_prices, beverage_prices
|
return food_prices, beverage_prices
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -54,11 +56,22 @@ class SaleItem < ApplicationRecord
|
|||||||
.where("sale_items.sale_item_id=?", sale_item_id.to_s)
|
.where("sale_items.sale_item_id=?", sale_item_id.to_s)
|
||||||
if item[0].account_id == 1
|
if item[0].account_id == 1
|
||||||
food_price = item[0].price
|
food_price = item[0].price
|
||||||
else
|
else
|
||||||
beverage_price = item[0].price
|
beverage_price = item[0].price
|
||||||
end
|
end
|
||||||
|
|
||||||
return food_price, beverage_price
|
return food_price, beverage_price
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_overall_discount(sale_id)
|
||||||
|
price = 0.0
|
||||||
|
item=SaleItem.where("product_code=?", sale_id)
|
||||||
|
|
||||||
|
item.each do|i|
|
||||||
|
price += i.price
|
||||||
|
end
|
||||||
|
|
||||||
|
return price
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -67,15 +67,18 @@ class SalePayment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token)
|
def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token)
|
||||||
response = HTTParty.get(url,
|
begin
|
||||||
|
response = HTTParty.get(url,
|
||||||
:body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
:body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
||||||
:headers => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json'
|
'Accept' => 'application/json'
|
||||||
}
|
}, :timeout => 10
|
||||||
)
|
)
|
||||||
return response;
|
rescue Net::OpenTimeout
|
||||||
|
response = { status: false }
|
||||||
|
end
|
||||||
|
return response;
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id)
|
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id)
|
||||||
@@ -187,17 +190,17 @@ class SalePayment < ApplicationRecord
|
|||||||
payment_status = false
|
payment_status = false
|
||||||
|
|
||||||
#Next time - validate if the vochure number is valid - within
|
#Next time - validate if the vochure number is valid - within
|
||||||
self.payment_method = "paypar"
|
|
||||||
self.payment_amount = self.received_amount
|
|
||||||
self.payment_reference = self.voucher_no
|
|
||||||
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
|
||||||
self.payment_status = "pending"
|
|
||||||
payment_method = self.save!
|
|
||||||
|
|
||||||
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
|
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
|
||||||
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
|
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
|
||||||
membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id)
|
membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id)
|
||||||
if membership_data["status"]==true
|
if membership_data["status"]==true
|
||||||
|
self.payment_method = "paypar"
|
||||||
|
self.payment_amount = self.received_amount
|
||||||
|
self.payment_reference = self.voucher_no
|
||||||
|
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
||||||
|
self.payment_status = "pending"
|
||||||
|
payment_method = self.save!
|
||||||
SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid')
|
SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid')
|
||||||
sale_update_payment_status(self.received_amount.to_f)
|
sale_update_payment_status(self.received_amount.to_f)
|
||||||
|
|
||||||
@@ -251,7 +254,12 @@ class SalePayment < ApplicationRecord
|
|||||||
payparcost = payparcost + pp.payment_amount
|
payparcost = payparcost + pp.payment_amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
total_amount = food_prices - payparcost
|
overall_dis = SaleItem.get_overall_discount(sObj.id)
|
||||||
|
total_amount = food_prices - payparcost + overall_dis
|
||||||
|
puts "total_amount"
|
||||||
|
puts food_prices
|
||||||
|
puts payparcost
|
||||||
|
puts total_amount
|
||||||
if total_amount > 0
|
if total_amount > 0
|
||||||
receipt_no = sObj.receipt_no
|
receipt_no = sObj.receipt_no
|
||||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||||
@@ -272,7 +280,7 @@ class SalePayment < ApplicationRecord
|
|||||||
response = { status: false }
|
response = { status: false }
|
||||||
end
|
end
|
||||||
|
|
||||||
puts response.to_json
|
# puts response.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -96,6 +96,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
if(localStorage.getItem("cash") == null || localStorage.getItem("cash") == 'null'){}
|
||||||
|
else {
|
||||||
|
$('#validamount').attr("value",parseFloat("<%= @can_jcb %>") - parseFloat(localStorage.getItem("cash")));
|
||||||
|
}
|
||||||
|
});
|
||||||
// number key pad
|
// number key pad
|
||||||
$(document).on('click', '.cashier_number', function(event){
|
$(document).on('click', '.cashier_number', function(event){
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@@ -141,7 +147,7 @@ $(document).on('click', '.cashier_number', function(event){
|
|||||||
$('#jcb_pay').on('click',function(){
|
$('#jcb_pay').on('click',function(){
|
||||||
var amount = $('#amount').text();
|
var amount = $('#amount').text();
|
||||||
var sale_id = "<%= @sale_id %>";
|
var sale_id = "<%= @sale_id %>";
|
||||||
if(parseFloat(amount) <= "<%= @can_jcb %>"){
|
if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) ){
|
||||||
$.ajax({type: "POST",
|
$.ajax({type: "POST",
|
||||||
url: "<%= origami_payment_jcb_path %>",
|
url: "<%= origami_payment_jcb_path %>",
|
||||||
data: "amount="+ amount + "&sale_id="+ sale_id,
|
data: "amount="+ amount + "&sale_id="+ sale_id,
|
||||||
|
|||||||
@@ -96,6 +96,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
if(localStorage.getItem("cash") == null || localStorage.getItem("cash") == 'null'){}
|
||||||
|
else {
|
||||||
|
$('#validamount').attr("value",parseFloat("<%= @can_master %>") - parseFloat(localStorage.getItem("cash")));
|
||||||
|
}
|
||||||
|
});
|
||||||
$(document).on('click', '.cashier_number', function(event){
|
$(document).on('click', '.cashier_number', function(event){
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -138,7 +144,7 @@ $(document).on('click', '.cashier_number', function(event){
|
|||||||
$('#master_pay').on('click',function(){
|
$('#master_pay').on('click',function(){
|
||||||
var amount = $('#amount').text();
|
var amount = $('#amount').text();
|
||||||
var sale_id = "<%= @sale_id %>";
|
var sale_id = "<%= @sale_id %>";
|
||||||
if(parseFloat(amount) <= "<%= @can_master %>"){
|
if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) ){
|
||||||
$.ajax({type: "POST",
|
$.ajax({type: "POST",
|
||||||
url: "<%= origami_payment_master_path %>",
|
url: "<%= origami_payment_master_path %>",
|
||||||
data: "amount="+ amount + "&sale_id="+ sale_id,
|
data: "amount="+ amount + "&sale_id="+ sale_id,
|
||||||
|
|||||||
@@ -96,6 +96,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
if(localStorage.getItem("cash") == null || localStorage.getItem("cash") == 'null'){}
|
||||||
|
else {
|
||||||
|
$('#validamount').attr("value",parseFloat("<%= @can_mpu %>") - parseFloat(localStorage.getItem("cash")));
|
||||||
|
}
|
||||||
|
});
|
||||||
$(document).on('click', '.cashier_number', function(event){
|
$(document).on('click', '.cashier_number', function(event){
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -138,7 +144,7 @@ $(document).on('click', '.cashier_number', function(event){
|
|||||||
$('#mpu_pay').on('click',function(){
|
$('#mpu_pay').on('click',function(){
|
||||||
var amount = $('#amount').text();
|
var amount = $('#amount').text();
|
||||||
var sale_id = "<%= @sale_id %>";
|
var sale_id = "<%= @sale_id %>";
|
||||||
if(parseFloat(amount) <= "<%= @can_mpu %>"){
|
if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) ){
|
||||||
$.ajax({type: "POST",
|
$.ajax({type: "POST",
|
||||||
url: "<%= origami_payment_mpu_path %>",
|
url: "<%= origami_payment_mpu_path %>",
|
||||||
data: "amount="+ amount + "&sale_id="+ sale_id,
|
data: "amount="+ amount + "&sale_id="+ sale_id,
|
||||||
|
|||||||
@@ -96,6 +96,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
if(localStorage.getItem("cash") == null || localStorage.getItem("cash") == 'null'){}
|
||||||
|
else {
|
||||||
|
$('#validamount').attr("value",parseFloat("<%= @can_visa %>") - parseFloat(localStorage.getItem("cash")));
|
||||||
|
}
|
||||||
|
});
|
||||||
$(document).on('click', '.cashier_number', function(event){
|
$(document).on('click', '.cashier_number', function(event){
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -138,7 +144,7 @@ $(document).on('click', '.cashier_number', function(event){
|
|||||||
$('#visa_pay').on('click',function(){
|
$('#visa_pay').on('click',function(){
|
||||||
var amount = $('#amount').text();
|
var amount = $('#amount').text();
|
||||||
var sale_id = "<%= @sale_id %>";
|
var sale_id = "<%= @sale_id %>";
|
||||||
if(parseFloat(amount) <= "<%= @can_visa %>"){
|
if(parseFloat(amount) <= parseFloat($("#validamount").attr("value"))){
|
||||||
$.ajax({type: "POST",
|
$.ajax({type: "POST",
|
||||||
url: "<%= origami_payment_visa_path %>",
|
url: "<%= origami_payment_visa_path %>",
|
||||||
data: "amount="+ amount + "&sale_id="+ sale_id,
|
data: "amount="+ amount + "&sale_id="+ sale_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user