diff --git a/Gemfile b/Gemfile index 01a87af7..b39a85a3 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,8 @@ gem 'sidekiq' # Pagination gem 'kaminari', '~> 0.16.3' +# Datatable +gem 'filterrific' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development @@ -91,4 +93,8 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'httparty', '~> 0.15.5' +# gem 'momentjs-rails', '>= 2.9.0' +# gem 'bootstrap-datepicker-rails' +# gem 'momentjs-rails', '>= 2.9.0' +# gem 'bootstrap3-datetimepicker-rails', '~> 4.17.47' gem 'bootstrap-datepicker-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 051e1595..4235d035 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -72,6 +72,7 @@ GEM faker (1.7.3) i18n (~> 0.5) ffi (1.9.18) + filterrific (2.1.2) font-awesome-rails (4.7.0.2) railties (>= 3.2, < 5.2) globalid (0.4.0) @@ -238,6 +239,7 @@ DEPENDENCIES database_cleaner factory_girl_rails (~> 4.0) faker + filterrific font-awesome-rails httparty (~> 0.15.5) jbuilder (~> 2.5) diff --git a/app/assets/javascripts/CRM.js b/app/assets/javascripts/CRM.js new file mode 100644 index 00000000..66f161af --- /dev/null +++ b/app/assets/javascripts/CRM.js @@ -0,0 +1,17 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require bootstrap +//= require jquery_ujs +//= require turbolinks +//= require cable \ No newline at end of file diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 7df365ec..2cddf699 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -40,31 +40,36 @@ $(document).ready(function(){ // complete for queue item $('.order-complete').on('click',function(){ - var _self= $(this); + var _self = $(this); // To know in ajax return var assigned_item_id=$(this).attr('id').substr(15); var params = { 'id':assigned_item_id }; - var station=$(this).parent().parent(".queue_station").parent().parent().attr('id'); $.ajax({ type: 'POST', url: '/oqs/update_delivery', data: params, dataType: 'json', - success: function(data){ - var queue_station=_self.parent().parent(".queue_station"); + success: function(data){ + for (i = 0; i < data.length; i++) { + var queue_station = $('#assigned_queue_' + data[i]).parent().parent(".queue_station"); + var station = queue_station.parent().parent().attr('id'); - // Remove a queue card from current station - queue_station.remove(); + // Remove a queue card from current station + queue_station.remove(); - // Remove a queue card from current station - queue_station.children('.card-footer').remove(); - - // Add removed queue card from station to completed - $("#completed").children('.card-columns').append(queue_station); + // Remove a queue card from current station + queue_station.children('.card-footer').remove(); + + // Add removed queue card from station to completed + $("#completed").children('.card-columns').append(queue_station); - // update queue item count in station - $("#"+station+"_count").text(parseInt($("#"+station+"_count").text())-1); - $("#completed_count").text(parseInt($("#completed_count").text())+1); + // update queue item count in each station + var station_count=parseInt($("#"+station+"_count").text()) - 1; + $("#"+station+"_count").text(station_count); + } + + // update queue item count in completed station + $("#completed_count").text(parseInt($("#completed_count").text()) + data.length); alert("updated!"); } diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 8ff96589..43f11f4b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,5 +17,142 @@ //= require turbolinks //= require cable //= require settings/processing_items -//= require bootstrap-datepicker +//= require bootstrap-datepicker/core +//= require bootstrap-datepicker/locales/bootstrap-datepicker.es + +$(document).on("focus", "[data-behaviour~='datepicker']", function(e){ + $(this).datepicker({"format": "yyyy-M-dd", "weekStart": 1, "autoclose": true}); + $('.dropdown-toggle').dropdown(); +}); + +/* +* ToDo Move to here from pages +* +* + + + +$(function(){ + $('#custom_excel').hide(); + + $('#custom_excel').click(function(){ + var url = $('#custom_excel').attr('data-url'); + $('#frm_report').attr('action',url) + $('#frm_report').submit(); + // window.location = url; + }); + + var item = $('#item').val(); + var payment_type = $('#payment_type'); + + if(item == 'order'){ + $('#cashier').hide(); + $('#waiter').show(); + if(payment_type){ + $('#payment_type').hide(); + } + } + else if(item == 'sale'){ + $('#waiter').hide(); + $('#cashier').show(); + } + else{ + $('#waiter').hide(); + $('#cashier').show(); + $("#item").val('sale'); + } +}); + +//Reset the form to pervious values +$("#branch").val(<%=params[:branch]%>); +$("#waiter").val("<%=params[:waiter]%>"); +$("#cashier").val(<%=params[:cashier]%>); +$("#product").val(<%=params[:product]%>); +$("#singer").val(<%=params[:singer]%>); +$("#item").val('<%=params[:item]%>'); +$("#guest_role").val('<%=params[:guest_role]%>'); + + +$("#from").val("<%=params[:from]%>"); +$("#to").val("<%=params[:to]%>"); +$("#sel_period").val(<%=params[:period]%>); +$("#sel_sale_type").val(<%=params[:sale_type]%>); + +<% if params[:period_type] == 1 || params[:period_type] == "1" %> + $("#rd_period_type_1").attr("checked","checked"); +<% else %> + $("#rd_period_type_0").attr("checked","checked"); +<% end %> +$(".btn-group button").removeClass("active"); +<% report_type = params[:report_type].blank? ? "0" : params[:report_type] %> +$("#btn_report_type_<%= report_type %>").addClass("active"); + +$('#item').change(function(){ + var item = $('#item').val(); + var payment_type = $('#payment_type'); + + if(item == 'sale'){ + $('#waiter').hide(); + $('#cashier').show(); + if(payment_type){ + $('#payment_type').show(); + } + } + else{ + $('#cashier').hide(); + $('#waiter').show(); + if(payment_type){ + $('#payment_type').hide(); + } + } +}); + +$(function(){ + var check_arr = []; + var search = '<%= params[:period_type] %>'; + if(search){ + if(parseInt(search) == 0){ + search_by_period(); + } + else{ + search_by_date(); + } + }else{ + search_by_period(); + } + $('#sel_period').change(function(){ + search_by_period(); + }); + function search_by_period(){ + var period = $('#sel_period').val(); + var period_type = 0; + var from = ""; + var to = ""; + } + + $('#from').change(function(){ + search_by_date(); + }); + + $('#to').change(function(){ + search_by_date(); + }); + function search_by_date(){ + var from = $('#from').val(); + var to = $('#to').val(); + var period = 0; + var period_type = 1; + if(to != '' && from != ''){ + shift_name = from + ',' + to; + check_arr.push(to); + // console.log(check_arr.length) + if(check_arr.length == 1){ + } + if(check_arr.length == 3){ + check_arr = []; + } + } + } +}); +*/ diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js index 739aa5f0..43efe3f2 100644 --- a/app/assets/javascripts/cable.js +++ b/app/assets/javascripts/cable.js @@ -5,6 +5,7 @@ //= require_self //= require_tree ./channels +// Temp Disable (function() { this.App || (this.App = {}); diff --git a/app/assets/javascripts/crm/dining_queues.coffee b/app/assets/javascripts/crm/dining_queues.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/crm/dining_queues.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 8ce3d0c4..dc3ab163 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -17,21 +17,32 @@ //= require cable $(document).ready(function(){ + // Enable/Disable Button + control_button("disabled"); + $(".orders").on('click', function(){ - var zone_name=$(this).find(".orders-table").text(); + $("#order-sub-total").text(''); + // $("#order-food").text(''); + // $("#order-beverage").text(''); + $("#order-discount").text(''); + $("#order-Tax").text(''); + $("#order-grand-total").text(''); + + var zone_name=$(this).find(".orders-table").text(); var receipt_no=$(this).find(".orders-receipt-no").text(); - var unique_id=$(this).find(".orders-id").text(); - var order_status=$(this).find(".orders-order-status").text().trim(); + var unique_id = $(this).find(".orders-id").text(); + var order_status=$(this).find(".orders-order-status").text().trim(); // Enable/Disable Button control_button(order_status); //for customer button - if(unique_id.charAt(0) == 'S'){ - $("#customer").removeAttr('disabled'); - }else{ - $("#customer").attr('disabled','disabled'); - } + $("#customer").removeAttr('disabled'); + + + var customer_id=$(this).find(".customer-id").text(); + show_customer_details(customer_id); + var cashier=""; var receipt_date=""; @@ -46,10 +57,10 @@ $(document).ready(function(){ // AJAX call for order $.ajax({ - type: "GET", - url: "origami/" + unique_id, - data: { 'id' : unique_id }, - success:function(result){ + type: "POST", + url: "/origami/" + unique_id, + data: { 'booking_id' : unique_id }, + success:function(result){ for (i = 0; i < result.length; i++) { var data = JSON.stringify(result[i]); var parse_data = JSON.parse(data); @@ -57,28 +68,30 @@ $(document).ready(function(){ // Receipt Header receipt_no = result[i].receipt_no; cashier = result[i].cashier_name; - receipt_date = result[i].receipt_date; + receipt_date = new Date(result[i].receipt_date); + show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() $("#receipt_no").text(receipt_no); - $("#cashier").text(cashier==null?"":cashier); - $("#receipt_date").text(receipt_date); + $("#cashier").text(cashier == null ? "" : cashier); + $("#receipt_date").text(show_date); //Receipt Charges sub_total += (parse_data.qty*parse_data.price); - discount_amount = parse_data.discount_amount; + + discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; tax_amount = parse_data.tax_amount; grand_total_amount = parse_data.grand_total_amount; $("#order-sub-total").text(sub_total); - $("#order-food").text(''); - $("#order-beverage").text(''); + // $("#order-food").text(''); + // $("#order-beverage").text(''); $("#order-discount").text(discount_amount); $("#order-Tax").text(tax_amount); $("#order-grand-total").text(grand_total_amount); // Ordered Items - var order_items_rows = "" + + var order_items_rows = "" + "" + parse_data.item_name + "" + "" + parse_data.qty + "" + "" + parse_data.qty*parse_data.price + "" + @@ -94,11 +107,11 @@ $(document).ready(function(){ $(this).addClass('selected-item'); }); - // Bill Request + // Bill Request $('#request_bills').click(function() { - var order_id=$(".selected-item").find(".orders-id").text(); + var order_id=$(".selected-item").find(".orders-id").text(); if(order_id!=""){ - window.location.href = '/origami/request_bills/'+ order_id + window.location.href = '/origami/' + order_id + '/request_bills' } else { alert("Please select an order!"); @@ -106,42 +119,50 @@ $(document).ready(function(){ return false; }); - // Discount for Payment + // Discount for Payment $('#discount').click(function() { - var order_id=$(".selected-item").find(".orders-id").text(); + var order_id=$(".selected-item").find(".orders-id").text(); if(order_id!=""){ - window.location.href = '/origami/discount/'+ order_id + window.location.href = '/origami/' + order_id + '/discount' } else { alert("Please select an order!"); - } - + } + return false; }); // Pay Discount for Payment - $("#pay-discount").on('click', function(){ + $("#pay-discount").on('click', function(e){ + e.preventDefault(); var sale_id = $('#sale-id').text(); + var sale_item_id = $('.selected-item').attr('id'); var sub_total = $('#order-sub-total').text(); var grand_total = $('#order-grand-total').text(); var discount_type = $('#discount-type').val(); - var discount_value = $('#discount-amount').val(); + var discount_value = $('#discount-amount').val(); var discount_amount = discount_value; + var ajax_url = "/origami/" + sale_id + "/discount"; + + if(sale_item_id != null){ + ajax_url = "/origami/" + sale_item_id + "/discount"; + } // For Percentage Discount - if(discount_type == 1){ + if(discount_type == 1){ discount_amount=(sub_total*discount_value)/100; } - var params = {'sale_id': sale_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount}; + var params = {'sale_id': sale_id, 'sale_item_id': sale_item_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount}; $.ajax({ type: "POST", - url: "/origami/discount", + url: ajax_url, data: params, success:function(result){ } }); }); + // Payment for Bill $('#pay-bill').click(function() { var sale_id=$(".selected-item").find(".orders-id").text(); @@ -150,17 +171,58 @@ $(document).ready(function(){ } else { alert("Please select an order!"); - } - + } + return false; }); $('#customer').click(function() { - var sale_id=$(".selected-item").find(".orders-id").text(); - window.location.href = '/crm/customers/'+ sale_id + "/assign_sale_id" + var sale = $(".selected-item").find(".orders-id").text(); + if (sale.substring(0, 3)=="SAL") { + var sale_id = sale + }else{ + var sale_id = $(".selected-item").find(".order-cid").text(); + } + window.location.href = '/origami/'+ sale_id + "/add_customer" + return false; }); + function show_customer_details(customer_id){ + + if(window.location.pathname.substring(0, 12) == "/origami/SAL"){ + var url = customer_id+"/get_customer/" + }else{ + var url = "origami/"+customer_id+"/get_customer/" + } + + $('.customer_detail').removeClass('hide'); + //Start Ajax + $.ajax({ + type: "GET", + url: url, + data: {}, + dataType: "json", + success: function(data) { + $("#customer_name").text(data["customer"].name); + $.each(data["response_data"]["data"], function (i) { + if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){ + var balance = data["response_data"]["data"][i]["balance"]; + console.log(balance); + if (balance == "0.0") { + $("#customer_amount").text('0.0'); + }else{ + $("#customer_amount").text(balance); + } + + + } + }); + } + }); + //End Ajax + } + /* For Receipt - Calculate discount or tax */ $('.cashier_number').on('click', function(event){ if(event.handled !== true) { @@ -168,7 +230,7 @@ $(document).ready(function(){ original_value = $('#discount-amount').val(); var input_type = $(this).attr("data-type"); - + switch (input_type) { case 'num': var input_value = $(this).attr("data-value"); @@ -179,13 +241,14 @@ $(document).ready(function(){ else{ $('#discount-amount').val(original_value + '' + input_value); update_balance(); - } + } break; case 'add': var input_value = $(this).attr("data-value"); - amount = parseInt(input_value) + parseInt(original_value); + amount = parseInt(input_value); $('#discount-amount').val(amount); + $('#discount-type').val(1); update_balance(); break; @@ -207,19 +270,29 @@ $(document).ready(function(){ } }); + $('.discount-item-row').on('click',function(){ + $('.discount-item-row').removeClass('selected-item'); + $(this).addClass('selected-item'); + }); + }); /* Button Control by Status */ -function control_button(order_status){ +function control_button(order_status){ if(order_status=="billed"){ $("#request_bills").prop('disabled', true); $("#discount").prop('disabled', false); - $("#pay").prop('disabled', false); + $("#pay-bill").prop('disabled', false); } else if(order_status=="new") { $("#request_bills").prop('disabled', false); $("#discount").prop('disabled', true); - $("#pay").prop('disabled', true); + $("#pay-bill").prop('disabled', true); + } + else { + $("#request_bills").prop('disabled', true); + $("#discount").prop('disabled', true); + $("#pay-bill").prop('disabled', true); } } @@ -236,9 +309,6 @@ function update_balance(){ } var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount; - $('#order-discount').text(discount_amount); + $('#order-discount').text(discount_amount); $('#order-grand-total').text(total); } - - - diff --git a/app/assets/javascripts/origami/redeem_payments.coffee b/app/assets/javascripts/origami/redeem_payments.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/origami/redeem_payments.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/settings/orders.coffee b/app/assets/javascripts/settings/orders.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/settings/orders.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index b0f802f1..f43cc3f9 100644 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -7,3 +7,5 @@ // min-height: 75rem; // padding-top: 4.5rem; // } + + diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index d8101494..d46e6ade 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -2,7 +2,7 @@ @import "bootstrap"; @import "font-awesome"; @import "theme"; -@import "bootstrap-datepicker3"; +@import 'bootstrap-datepicker'; /* Show it is fixed to the top */ // body { @@ -58,3 +58,19 @@ ul.dropdown-menu li a{ /*----- Header Bar -----*/ /*----- Header Bar -----*/ + +/*----- Layout ------ */ + +.margin-top-20 { + margin: 20px 0 0 0; +} + +/*----- Layout ------ */ + +/*--- Reset --- */ + +select.form-control { + height: inherit !important; +} + +/*--- Reset --- */ diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 0be16266..5e361f7e 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -7,17 +7,39 @@ // min-height: 75rem; // padding-top: 4.5rem; // } +.others-payment{ + line-height:100px; + text-align:center; + color:white; + width:300px; + height:100px; + font-size:18px; +} + +.orders-table { + cursor: pointer; +} .cashier_number{ - height:76px; - line-height:80px; + width: 33%; + height:70px; + line-height:70px; text-align:center; background:#54A5AF; - float:left; - margin:2px; + // float:left; + // margin:2px; + font-size:20px; + color:white; + // cursor:pointer; +} + +.pay{ + width: 98%; + height:211px; + line-height:211px; + text-align:center; font-size:20px; color:white; - cursor:pointer; } .cashier_number:hover{ @@ -25,15 +47,20 @@ } .long{ - width:100% + width:49%; } .sold { background-color: red; } +.paid { + background-color: green; +} + .selected-item { - background-color: blue; + color: #fff !important; + background-color: blue !important; } /* Reciept Style */ @@ -42,17 +69,17 @@ } .charges-name { - width: 80%; + width: 80%; text-align: left; } .item-name { - width: 60%; + width: 60%; text-align: left; } .item-attr { - width: 20%; + width: 20%; text-align: right; } @@ -70,9 +97,29 @@ background-color: #009900 } +.left{ + margin-left:1px; +} +.bottom{ + margin-bottom: 1px; +} /*----- Reset -----*/ select.form-control { height: inherit !important; } + +.form-horizontal .form-group { + margin-right: 0px !important; +} + +/* Discount */ + +.discount-item-row { + cursor: pointer; +} + +tr.discount-item-row:hover { + background-color: #e3e3e3 !important; +} diff --git a/app/assets/stylesheets/origami/redeem_payments.scss b/app/assets/stylesheets/origami/redeem_payments.scss new file mode 100644 index 00000000..8fdd1e53 --- /dev/null +++ b/app/assets/stylesheets/origami/redeem_payments.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the origami/redeem_payments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/settings/orders.scss b/app/assets/stylesheets/settings/orders.scss new file mode 100644 index 00000000..436ceee1 --- /dev/null +++ b/app/assets/stylesheets/settings/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the settings/orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index a98c8f3d..a01cc717 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -8,12 +8,18 @@ class Api::BillController < Api::ApiController #create Bill by Booking ID if (params[:booking_id]) - @sale = Sale.new - @status = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee.name) - + booking = Booking.find(params[:booking_id]) + if booking + if booking.sale_id.nil? + @sale = Sale.new + @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee.name) + else + @status = true + end + end elsif (params[:order_id]) @sale = Sale.new - @status = @sale.generate_invoice_from_order(params[:order_id], current_login_employee.name) + @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee.name) end end diff --git a/app/controllers/api/customers_controller.rb b/app/controllers/api/customers_controller.rb index 8ce2041c..2adc7c8a 100644 --- a/app/controllers/api/customers_controller.rb +++ b/app/controllers/api/customers_controller.rb @@ -9,4 +9,9 @@ class Api::CustomersController < ActionController::API def show @customer = Customer.find_by(params[:id]) end + + #Show customer detail by Order item + def get_customer_order + @customer = Customer.find(params[:id]) + end end diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index df9b1542..8bd348e2 100644 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -38,9 +38,8 @@ class Api::OrdersController < Api::ApiController #Create Table Booking or Room Booking - if !params["booking_id"].nil? && params[:booking_id].to_i > 0 - #@order.new_booking = false - @order.new_booking = true + if !params["booking_id"].nil? + @order.new_booking = false @order.booking_id = params[:booking_id] end diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 77e38f2c..c1ae1a01 100644 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,8 +1,77 @@ class BaseReportController < ActionController::Base - include LoginVerification + include LoginVerification + layout "application" - #before_action :check_installation - protect_from_forgery with: :exception + #before_action :check_installation + protect_from_forgery with: :exception + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def get_date_range_from_params + period_type = params[:period_type] + period = params[:period] + from = params[:from] + to = params[:to] + day_ref = Time.now + if period_type.to_i == 1 + if params[:from] && params[:to] + if params[:from] != "" && params[:to] !="" + from = DateTime.strptime(params[:from], "%m/%d/%Y") + to = DateTime.strptime(params[:to], "%m/%d/%Y") + else + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + end + end + else + case period.to_i + when PERIOD["today"] + + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + + when PERIOD["yesterday"] + from = (day_ref - 1.day).beginning_of_day.utc + to = (day_ref - 1.day).end_of_day.utc + + when PERIOD["this_week"] + from = Time.now.beginning_of_week.utc + to = Time.now.utc + when PERIOD["last_week"] + from = (day_ref - 7.day).beginning_of_week.utc + to = (day_ref - 7.day).end_of_week.utc + when PERIOD["last_7"] + from = (day_ref - 7.day).utc + to = Time.now.utc + when PERIOD["this_month"] + from = Time.now.beginning_of_month.utc + to = Time.now.utc + when PERIOD["last_month"] + from = (day_ref - 1.month).beginning_of_month.utc + to = (day_ref - 1.month).end_of_month.utc + when PERIOD["last_30"] + from = (day_ref - 30.day).utc + to = Time.now.utc + when PERIOD["this_year"] + from = Time.now.beginning_of_year.utc + to = Time.now.utc + when PERIOD["last_year"] + from = (day_ref - 1.year).beginning_of_year.utc + to = (day_ref - 1.year).end_of_year.utc + end + end + return from, to + end end diff --git a/app/controllers/crm/bookings_controller.rb b/app/controllers/crm/bookings_controller.rb index eeb19f75..65511512 100644 --- a/app/controllers/crm/bookings_controller.rb +++ b/app/controllers/crm/bookings_controller.rb @@ -1,4 +1,4 @@ -class Crm::BookingsController < ApplicationController +class Crm::BookingsController < BaseCrmController def update_booking booking = Booking.find(params[:booking_id]) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 325ac7dd..ed285f49 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -1,16 +1,26 @@ -class Crm::CustomersController < ApplicationController +class Crm::CustomersController < BaseCrmController before_action :set_crm_customer, only: [:show, :edit, :update, :destroy] # GET /crm/customers # GET /crm/customers.json def index - @sale_id = 0 - @crm_customers = Customer.all - @crm_customer = Customer.new - @membership = Customer.get_member_group - if @membership["status"] == true - @member_group = @membership["data"] + filter = params[:filter] + + if filter.nil? + @crm_customers = Customer.order("customer_id").page(params[:page]) + #@products = Product.order("name").page(params[:page]).per(5) + else + @crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page(params[:page]) end + #@crm_customers = Customer.all + @crm_customer = Customer.new + if @crm_customer.valid? + @crm_customer.errors.messages + end + # @membership = Customer.get_member_group + # if @membership["status"] == true + # @member_group = @membership["data"] + # end respond_to do |format| format.html # index.html.erb format.json { render json: @crm_customers } @@ -20,6 +30,15 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers/1 # GET /crm/customers/1.json def show + @orders = Order.where("customer_id=?", params[:id]) + + if @orders + @order_items = [] + @orders.each do |bo| + @order_items = @order_items + bo.order_items + end + + end end # GET /crm/customers/new @@ -35,27 +54,28 @@ class Crm::CustomersController < ApplicationController # POST /crm/customers # POST /crm/customers.json - def create + def create @crm_customers = Customer.new(customer_params) - + respond_to do |format| if @crm_customers.save - - name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] - date_of_birth = customer_params[:date_of_birth] - membership_id = params[:membership_id] + dob = customer_params[:date_of_birth] + member_group_id = params[:member_group_id] membership = MembershipSetting.find_by_membership_type("paypar_url") - app_token = membership.auth_token.to_s - url = membership.gateway_url.to_s + "/api/create_membership_customer".to_s + memberaction = MembershipAction.find_by_membership_type("create_membership_customer") + merchant_uid = memberaction.merchant_account_id.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - date_of_birth: date_of_birth, - membership_id: membership_id}.to_json, + + dob: dob, + + member_group_id: member_group_id,merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -63,77 +83,72 @@ class Crm::CustomersController < ApplicationController ) if response["status"] == true - puts "hhhhhhhhhhhhhhhhhh" - puts params[:sale_id] + customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - if params[:sale_id] != 0 - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } - else - format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: 'Customer was successfully created.' } - end + + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' } + else + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'} + end # format.json { render :index, status: :created, location: @crm_customers } else @crm_customers.destroy - - if params[:sale_id] != 0 - format.html { redirect_to crm_customers_path, notice: response["message"] } - + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} else - format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] } + format.html { redirect_to crm_customers_path, notice: response["message"] } end - end - - - # format.json { render :index, status: :created, location: @crm_customers } - else - if params[:sale_id] != 0 - format.html { redirect_to crm_customers_path} - format.json { render json: @crm_customers.errors, status: :unprocessable_entity } - - else - format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] } - end - + + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} + else + format.html { redirect_to crm_customers_path} + format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + end end - end + end +end # PATCH/PUT /crm/customers/1 # PATCH/PUT /crm/customers/1.json def update - + respond_to do |format| if @crm_customer.update(customer_params) name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] - date_of_birth = customer_params[:date_of_birth] - id = customer_params[:membership_id] + dob = customer_params[:date_of_birth] + id = @crm_customer.membership_id + member_group_id = params[:member_group_id] membership = MembershipSetting.find_by_membership_type("paypar_url") - app_token = membership.auth_token.to_s - url = membership.gateway_url.to_s + "/api/update_membership_customer".to_s - + memberaction = MembershipAction.find_by_membership_type("update_membership_customer") + merchant_uid = memberaction.merchant_account_id.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - date_of_birth: date_of_birth, - id: id}.to_json, + dob: dob, + id: id,member_group_id:member_group_id,merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } ) - + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } else - format.html { render :edit } + format.html { render :index } format.json { render json: @crm_customer.errors, status: :unprocessable_entity } end @@ -150,23 +165,6 @@ class Crm::CustomersController < ApplicationController end end - # DELETE /crm/customers/1 - # DELETE /crm/customers/1.json - def get_sale_id - - @sale_id = params[:sale_id] - @crm_customers = Customer.all - @crm_customer = Customer.new - @membership = Customer.get_member_group - if @membership["status"] == true - @member_group = @membership["data"] - end - respond_to do |format| - format.html { render action: "index"} - format.json { render json: @crm_customers } - end - end - private # Use callbacks to share common setup or constraints between actions. def set_crm_customer @@ -176,8 +174,6 @@ class Crm::CustomersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def customer_params - params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_type, :membership_authentication_code) + params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth) end end - - diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb new file mode 100644 index 00000000..9e8cd06c --- /dev/null +++ b/app/controllers/crm/dining_queues_controller.rb @@ -0,0 +1,74 @@ +class Crm::DiningQueuesController < BaseCrmController + before_action :set_dining_queue, only: [:show, :edit, :update, :destroy] + + # GET /crm/dining_queues + # GET /crm/dining_queues.json + def index + @dining_queues = DiningQueue.all + end + + # GET /crm/dining_queues/1 + # GET /crm/dining_queues/1.json + def show + end + + # GET /crm/dining_queues/new + def new + @dining_queue = DiningQueue.new + end + + # GET /crm/dining_queues/1/edit + def edit + end + + # POST /crm/dining_queues + # POST /crm/dining_queues.json + def create + @dining_queue = DiningQueue.new(dining_queue_params) + + respond_to do |format| + if @dining_queue.save + format.html { redirect_to crm_dining_queues_path, notice: 'Dining queue was successfully created.' } + format.json { render :show, status: :created, location: @dining_queue } + else + format.html { render :new } + format.json { render json: @dining_queue.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /crm/dining_queues/1 + # PATCH/PUT /crm/dining_queues/1.json + def update + respond_to do |format| + if @dining_queue.update(dining_queue_params) + format.html { redirect_to crm_dining_queues_path, notice: 'Dining queue was successfully updated.' } + format.json { render :show, status: :ok, location: @dining_queue } + else + format.html { render :edit } + format.json { render json: @dining_queue.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /crm/dining_queues/1 + # DELETE /crm/dining_queues/1.json + def destroy + @dining_queue.destroy + respond_to do |format| + format.html { redirect_to crm_dining_queues_path, notice: 'Dining queue was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_dining_queue + @dining_queue = DiningQueue.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def dining_queue_params + params.require(:dining_queue).permit(:name, :contact_no, :queue_no) + end +end diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb index 9ae2b413..d1ee475b 100644 --- a/app/controllers/crm/home_controller.rb +++ b/app/controllers/crm/home_controller.rb @@ -1,8 +1,13 @@ class Crm::HomeController < BaseCrmController def index - @booking = Booking.all + @booking = Booking.all @customer = Customer.all + from = Time.now.beginning_of_day.utc + to = Time.now.end_of_day.utc + @queue = DiningQueue.where('created_at BETWEEN ? AND ?', from, to).order('queue_no ASC') + + # .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 2b676f21..7af42166 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -27,10 +27,18 @@ class Oqs::HomeController < BaseOqsController # update delivery status when complete click def update_delivery_status + removed_item = [] assigned_item_id = params[:id] assigned_item=AssignedOrderItem.find(assigned_item_id) - assigned_item.delivery_status=true - assigned_item.save + assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); + + # update delivery status for completed same order items + assigned_items.each do |ai| + ai.delivery_status=true + ai.save + removed_item.push(ai.assigned_order_item_id) + end + render :json => removed_item.to_json end # Query for OQS with status diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index 8a12e439..1731f69c 100644 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -1,31 +1,39 @@ class Oqs::PrintController < ApplicationController + # Print Order Item def print unique_code="OrderItemPdf" assigned_item_id=params[:id] - assigned_order_item=AssignedOrderItem.select("order_id, item_code").where("assigned_order_item_id='" + assigned_item_id + "'") + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); + # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_item(print_settings,assigned_order_item[0].order_id, assigned_order_item[0].item_code ) - - # update print status when complete click - assigned_item=AssignedOrderItem.find(assigned_item_id) - assigned_item.print_status=true - assigned_item.save + order_queue_printer.print_order_item(print_settings,assigned_item.order_id, assigned_item.item_code ) + + # update print status for completed same order items + assigned_items.each do |ai| + ai.print_status=true + ai.save + end end + # Print Order Details def print_order_summary unique_code="OrderSummaryPdf" assigned_item_id=params[:id] - assigned_order_item=AssignedOrderItem.select("order_id").where('assigned_order_item_id='+assigned_item_id) + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); + # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_summary(print_settings,assigned_order_item[0].order_id) + order_queue_printer.print_order_summary(print_settings,assigned_item.order_id) - # update print status when complete click - assigned_item=AssignedOrderItem.find(assigned_item_id) - assigned_item.print_status=true - assigned_item.save + # update print status for completed same order items + assigned_items.each do |ai| + ai.print_status=true + ai.save + end end end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index d9bfc39b..14af5f49 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -1,7 +1,43 @@ class Origami::CustomersController < BaseOrigamiController #Form to add customer - def index + + end - def create + + # GET /crm/customers/1 + # GET /crm/customers/1.json + def show end + + + + def add_customer + + @sale_id = params[:sale_id] + filter = params[:filter] + + if filter.nil? + @crm_customers = Customer.order("name").page params[:page] + else + @crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page params[:page] + end + # @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(2) + @crm_customer = Customer.new + # @membership = Customer.get_member_group + # if @membership["status"] == true + # @member_group = @membership["data"] + # end + # puts "Errrrrrrrrrrrrrrrrr" + # puts @crm_customer.valid? + + + respond_to do |format| + # format.html { render :template => "crm/customers/index" } + format.html { render action: "index"} + format.json { render json: @crm_customers } + end + end + + end diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index daf68918..fb981a80 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -2,7 +2,7 @@ class Origami::DiscountsController < BaseOrigamiController #discount page show from origami index with selected order def index - sale_id = params[:id] + sale_id = params[:id] if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) end @@ -11,30 +11,34 @@ class Origami::DiscountsController < BaseOrigamiController #discount for selected order def create sale_id = params[:sale_id] + sale_item_id = params[:sale_item_id] discount_type = params[:discount_type] - discount_value = params[:discount_value] - discount_amount = params[:discount_amount] - grand_total = params[:grand_total] + discount_value = params[:discount_value] + discount_amount = params[:discount_amount] + grand_total = params[:grand_total] - if discount_type == 0 - remark="Discount " + discount_amount + " as net" - else - remark="Discount " + discount_amount + " as percentage" - end + if discount_type == 0 + remark="Discount " + discount_amount + " as net" + else + remark="Discount " + discount_amount + " as percentage" + end - #update discount for sale - sale = Sale.find(sale_id) - sale.total_discount = discount_amount - sale.grand_total = grand_total - sale.save + #update discount for sale + sale = Sale.find(sale_id) + sale.total_discount = sale.total_discount + discount_amount.to_f + sale.grand_total = grand_total + sale.save #save sale item for discount + if sale_item_id != nil + origin_sale_item = SaleItem.find(sale_item_id) + end sale_item = SaleItem.new #pull sale_item.sale_id = sale_id - sale_item.product_code = 0 - sale_item.product_name = "Discount" + sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id + sale_item.product_name = "Overall Discount" sale_item.remark = remark sale_item.qty = 1 @@ -45,7 +49,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.price = sale_item.qty * sale_item.unit_price sale_item.save - redirect_to origami_root_path + redirect_to origami_path(sale_id) end end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 9733e488..de526f81 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -1,28 +1,95 @@ class Origami::HomeController < BaseOrigamiController def index + if params[:booking_id] != nil + type=params[:booking_id].split('-')[0]; + # Sale + if type == "SAL" + @selected_item = Sale.find(params[:booking_id]) + @selected_item_type="Sale" + # Booking + else + @selected_item = Order.find(params[:booking_id]) + @selected_item_type="Order" + end + end + puts params[:booking_id] + + @completed_orders = Order.get_completed_order() @booking_orders = Order.get_booking_order_table() @booking_rooms = Order.get_booking_order_rooms() @orders = Order.get_orders() - end + end - def show - str = [] - type=params[:id].split('-')[0]; + def item_show + selection(params[:booking_id],1) + end + def selection(selected_id, is_ajax) + str = [] + type=selected_id.split('-')[0]; # Sale if type == "SAL" - @order_details = SaleItem.get_order_items_details(params[:id]) + @order_details = SaleItem.get_order_items_details(params[:booking_id]) @order_details.each do |ord_detail| str.push(ord_detail) end - render :json => str.to_json # Booking else - @order_details = OrderItem.get_order_items_details(params[:id]) + @order_details = OrderItem.get_order_items_details(params[:booking_id]) @order_details.each do |ord_detail| str.push(ord_detail) - end + end + end + if is_ajax == 1 render :json => str.to_json + else + str + end + end + + def update_sale_by_customer + + id = params[:sale_id][0,3] + if(id == "SAL") + sale = Sale.find(params[:sale_id]) + else + sale = Order.find(params[:sale_id]) + end + + status = sale.update_attributes(customer_id: params[:customer_id]) + + if status == true + render json: JSON.generate({:status => true}) + else + render json: JSON.generate({:status => false, :error_message => "Record not found"}) + end end + + def get_customer + + @customer = Customer.find(params[:customer_id]) + + membership = MembershipSetting.find_by_membership_type("paypar_url") + + memberaction = MembershipAction.find_by_membership_type("get_all_member_account") + merchant_uid = memberaction.merchant_account_id.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + + response = HTTParty.get(url, :body => { membership_id: @customer.membership_id,merchant_uid:merchant_uid}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + + respond_to do |format| + format.js do + render :json => { + :response_data => response.as_json, + :customer => @customer} + end + end + end + end diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb new file mode 100644 index 00000000..263e55f7 --- /dev/null +++ b/app/controllers/origami/mpu_controller.rb @@ -0,0 +1,17 @@ +class Origami::MpuController < BaseOrigamiController + + def index + @sale_id = params[:sale_id] + end + + def create + cash = params[:amount] + sale_id = params[:sale_id] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "mpu") + end + end + +end diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb index a5177b06..c050c3f3 100644 --- a/app/controllers/origami/others_payments_controller.rb +++ b/app/controllers/origami/others_payments_controller.rb @@ -5,6 +5,7 @@ class Origami::OthersPaymentsController < BaseOrigamiController @membership_rebate_balance = 0 @sale_id = params[:sale_id] @payment_method_setting = PaymentMethodSetting.all + # @sale_id = params[:sale_id] # sale_data = Sale.find_by_sale_id(@sale_id) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index c60efdac..134c9474 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -17,7 +17,17 @@ class Origami::PaymentsController < BaseOrigamiController def show sale_id = params[:sale_id] if Sale.exists?(sale_id) + @cash = 0.0 + @other = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) + @sale_data.sale_payments.each do |spay| + if spay.payment_method == "cash" + @cash = spay.payment_amount + end + if spay.payment_method == "mpu" || spay.payment_method == "paypar" + @other += spay.payment_amount + end + end end end diff --git a/app/controllers/origami/paypar_payments_controller.rb b/app/controllers/origami/paypar_payments_controller.rb index af5ce55f..0c3ea11f 100644 --- a/app/controllers/origami/paypar_payments_controller.rb +++ b/app/controllers/origami/paypar_payments_controller.rb @@ -8,7 +8,6 @@ class Origami::PayparPaymentsController < BaseOrigamiController saleObj = Sale.find(sale_id) sale_payment = SalePayment.new status,msg =sale_payment.process_payment(saleObj, @user, redeem_amount,payment_method) - if status == true @out = true, "Success!" else @@ -19,4 +18,4 @@ class Origami::PayparPaymentsController < BaseOrigamiController end end -end \ No newline at end of file +end diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb new file mode 100644 index 00000000..5fd386e8 --- /dev/null +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -0,0 +1,47 @@ +class Origami::RedeemPaymentsController < BaseOrigamiController + def index + @sale_id = params[:sale_id] + payment_method = params[:payment_method] + @membership_rebate_balance=0 + sale_data = Sale.find_by_sale_id(@sale_id) + if sale_data + if sale_data.customer_id + customer_data= Customer.find_by_customer_id(sale_data.customer_id) + if customer_data + @membership_id = customer_data.membership_id + if !@membership_id.nil? + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") + if membership_setting.gateway_url + member_actions =MembershipAction.find_by_membership_type("get_account_balance") + if member_actions.gateway_url + @campaign_type_id = member_actions.additional_parameter["campaign_type_id"] + url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s + merchant_uid= member_actions.merchant_account_id + membership_data = SalePayment.get_paypar_account(url,membership_setting.auth_token,@membership_id,@campaign_type_id,merchant_uid) + if membership_data["status"]==true + @membership_rebate_balance=membership_data["balance"] + @out = true, @membership_rebate_balance,@membership_id + end + else + @out =false,0 + end + else + @out = false,0 + end + + + else + @out = false, 0 + end + else + @out = false, 0 + end + else + @out = false, 0 + end + else + @out = false, 0 + end + @out = false, 0 + end +end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index d1aa9e61..58ba0b11 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -14,17 +14,23 @@ class Origami::RequestBillsController < BaseOrigamiController @sale_items = SaleItem.where("sale_id=?",@sale_id) else @sale_data = Sale.find_by_sale_id(check_booking.sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) end unique_code = "ReceiptBillPdf" - customer_name = Customer.select("name").where('customer_id=' + @sale_data.customer_id) + customer= Customer.where('customer_id=' + @sale_data.customer_id) print_settings=PrintSetting.find_by_unique_code(unique_code) + # find order id by sale id + sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id) + + # Calculate Food and Beverage Total + food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer_name) - redirect_to origami_root_path + printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total) + redirect_to origami_path(@sale_data.sale_id) end end diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb new file mode 100644 index 00000000..b4c701ae --- /dev/null +++ b/app/controllers/reports/daily_sale_controller.rb @@ -0,0 +1,21 @@ +class Reports::DailySaleController < BaseReportController + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def index + from, to = get_date_range_from_params + @sale_data = Sale.get_receipt_no_list(from,to) + @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) +end + +end \ No newline at end of file diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb new file mode 100644 index 00000000..8569c051 --- /dev/null +++ b/app/controllers/reports/receipt_no_controller.rb @@ -0,0 +1,15 @@ +class Reports::ReceiptNoController < BaseReportController + def index + from, to = get_date_range_from_params + puts "from..." + puts from + puts "to..." + puts to + @sale_data = Sale.get_receipt_no_list(from,to) + @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) + end + + def show + + end +end \ No newline at end of file diff --git a/app/controllers/settings/membership_actions_controller.rb b/app/controllers/settings/membership_actions_controller.rb index 6db1a45b..ad7311f2 100644 --- a/app/controllers/settings/membership_actions_controller.rb +++ b/app/controllers/settings/membership_actions_controller.rb @@ -4,44 +4,7 @@ class Settings::MembershipActionsController < ApplicationController # GET /settings/membership_actions # GET /settings/membership_actions.json def index - type = params[:type] - @sale_id = params[:sale_id] - if type.nil? - @settings_membership_actions = Settings::MembershipAction.all - else - membership_actions_data=Settings::MembershipAction.find_by_membership_type(type) - - if !membership_actions_data.nil? - url = params[:gateway_url].to_s + membership_actions_data.gateway_url.to_s - puts url.to_json - sale_data = Sale.find_by_sale_id(@sale_id) - if sale_data.customer_id - customer_data= Customer.find_by_customer_id(sale_data.customer_id) - @membership_id = customer_data.membership_id - @campaign_type_id =1 - if !@membership_id.nil? - membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_data = SalePayment.get_paypar_account(url,membership_setting.auth_token,@membership_id,@campaign_type_id) - if membership_data["status"]==true - @membership_rebate_balance=membership_data["balance"] - @out = true, @membership_rebate_balance - else - @out = false, 0 - end - else - @out = false, 0 - end - else - @out =false, 0 - end - # campaign_type_id=1 - # get_account_data = MembershipAction.get_account_data(url) - else - @out = false, 0 - end - render :json => @out.to_json - end - + @settings_membership_actions = MembershipAction.all end # GET /settings/membership_actions/1 @@ -51,7 +14,7 @@ class Settings::MembershipActionsController < ApplicationController # GET /settings/membership_actions/new def new - @settings_membership_action = Settings::MembershipAction.new + @settings_membership_action = MembershipAction.new end # GET /settings/membership_actions/1/edit @@ -61,11 +24,11 @@ class Settings::MembershipActionsController < ApplicationController # POST /settings/membership_actions # POST /settings/membership_actions.json def create - @settings_membership_action = Settings::MembershipAction.new(settings_membership_action_params) + @settings_membership_action = MembershipAction.new(settings_membership_action_params) respond_to do |format| if @settings_membership_action.save - format.html { redirect_to @settings_membership_action, notice: 'Membership action was successfully created.' } + format.html { redirect_to settings_membership_actions_path, notice: 'Membership action was successfully created.' } format.json { render :show, status: :created, location: @settings_membership_action } else format.html { render :new } @@ -79,7 +42,7 @@ class Settings::MembershipActionsController < ApplicationController def update respond_to do |format| if @settings_membership_action.update(settings_membership_action_params) - format.html { redirect_to @settings_membership_action, notice: 'Membership action was successfully updated.' } + format.html { redirect_to settings_membership_action_path, notice: 'Membership action was successfully updated.' } format.json { render :show, status: :ok, location: @settings_membership_action } else format.html { render :edit } @@ -101,11 +64,11 @@ class Settings::MembershipActionsController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_settings_membership_action - @settings_membership_action = Settings::MembershipAction.find(params[:id]) + @settings_membership_action = MembershipAction.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def settings_membership_action_params - params.require(:settings_membership_action).permit(:membership_type, :is_active, :gateway_communication_type, :gateway_url, :auth_token, :merchant_account_id, :created_by, :additional_parameter) + params.require(:membership_action).permit(:membership_type, :is_active, :gateway_communication_type, :gateway_url, :auth_token, :merchant_account_id, :created_by, :additional_parameter) end end diff --git a/app/controllers/settings/orders_controller.rb b/app/controllers/settings/orders_controller.rb new file mode 100644 index 00000000..b5bbdc1c --- /dev/null +++ b/app/controllers/settings/orders_controller.rb @@ -0,0 +1,32 @@ +class Settings::OrdersController < ApplicationController + def index + + filter = params[:filter] + if filter.nil? + orders = Order.order("order_id desc").limit(1000) + else + order = Order.where("order_id LIKE ?", "%#{filter}%").order("order_id desc").limit(1000).page(params[:page]) + if order.count > 0 + orders = order + else + orders = Order.order("order_id desc").limit(1000) + flash[:notice] = "There is no data." + end + end + @orders = Kaminari.paginate_array(orders).page(params[:page]).per(50) + respond_to do |format| + format.html # index.html.erb + format.json { render json: @orders } + end + end + def show + + @order = Order.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @order } + end + end + +end diff --git a/app/controllers/settings/sales_controller.rb b/app/controllers/settings/sales_controller.rb new file mode 100644 index 00000000..6bb58244 --- /dev/null +++ b/app/controllers/settings/sales_controller.rb @@ -0,0 +1,42 @@ +class Settings::SalesController < ApplicationController + def index + + search_date = params[:date] + receipt_no = params[:receipt_no] + today = Date.today + + if receipt_no.nil? && search_date.nil? + @sales = Sale.where("NOT sale_status = 'void'" ).order("sale_id desc").limit(500) + else + if !search_date.blank? && receipt_no.blank? + sale = Sale.where("DATE_FORMAT(receipt_date,'%Y-%b-%d') = ?", search_date).order("sale_id desc").limit(500).page(params[:page]) + elsif !search_date.blank? && !receipt_no.blank? + sale = Sale.where("receipt_no LIKE ? or DATE_FORMAT(receipt_date,'%Y-%b-%d') = ?", "%#{receipt_no}%", search_date).order("sale_id desc").limit(500).page(params[:page]) + else + sale = Sale.where("receipt_no LIKE ?", receipt_no).order("sale_id desc").limit(500).page(params[:page]) + end + if sale.count > 0 + @sales = sale + else + @sales = Sale.where("NOT sale_status = 'void'").order("sale_id desc").limit(500) + end + end + @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + respond_to do |format| + format.html # index.html.erb + format.json { render json: @sales } + end + end + + def show + + @sale = Sale.find(params[:id]) + # @sale_receivables = SaleReceivable.where('sale_id = ?', @sale.id) + respond_to do |format| + format.html # show.html.erb + format.json { render json: @sale } + end + end + + +end \ No newline at end of file diff --git a/app/helpers/crm/dining_queues_helper.rb b/app/helpers/crm/dining_queues_helper.rb new file mode 100644 index 00000000..af60bd52 --- /dev/null +++ b/app/helpers/crm/dining_queues_helper.rb @@ -0,0 +1,2 @@ +module Crm::DiningQueuesHelper +end diff --git a/app/helpers/origami/redeem_payments_helper.rb b/app/helpers/origami/redeem_payments_helper.rb new file mode 100644 index 00000000..7e9151cb --- /dev/null +++ b/app/helpers/origami/redeem_payments_helper.rb @@ -0,0 +1,2 @@ +module Origami::RedeemPaymentsHelper +end diff --git a/app/helpers/settings/orders_helper.rb b/app/helpers/settings/orders_helper.rb new file mode 100644 index 00000000..f5825365 --- /dev/null +++ b/app/helpers/settings/orders_helper.rb @@ -0,0 +1,2 @@ +module Settings::OrdersHelper +end diff --git a/app/models/crm.rb b/app/models/crm.rb new file mode 100644 index 00000000..3407e215 --- /dev/null +++ b/app/models/crm.rb @@ -0,0 +1,5 @@ +module Crm + def self.table_name_prefix + 'crm_' + end +end diff --git a/app/models/customer.rb b/app/models/customer.rb index afc17d79..b5e101cb 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -9,14 +9,16 @@ class Customer < ApplicationRecord validates_presence_of :name, :contact_no, :email validates :contact_no, uniqueness: true validates :email, uniqueness: true - + + paginates_per 50 def self.get_member_group - membership = MembershipSetting.find_by_membership_type("paypar_url") - app_token = membership.auth_token.to_s + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("get_all_member_group") + app_token = membership.auth_token.to_s - url = membership.gateway_url.to_s + "/api/get_all_member_group".to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s response = HTTParty.get(url, :body => { app_token: app_token}.to_json, :headers => { @@ -30,6 +32,14 @@ class Customer < ApplicationRecord end + def self.search(search) + if search + find(:all, :conditions => ['name LIKE ?', "%#{search}%"]) + else + find(:all) + end + end + def lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 9a4f7a75..a3f8948f 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -9,10 +9,11 @@ class DiningFacility < ApplicationRecord scope :active, -> {where(is_active: true)} def get_current_booking - booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='occupied' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1) + puts "enter booking" + booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1) if booking.count > 0 then - return booking[0] + return booking[0].booking_id else return nil end diff --git a/app/models/dining_queue.rb b/app/models/dining_queue.rb new file mode 100644 index 00000000..ea6a1381 --- /dev/null +++ b/app/models/dining_queue.rb @@ -0,0 +1,2 @@ +class DiningQueue < ApplicationRecord +end diff --git a/app/models/lookup.rb b/app/models/lookup.rb index e1b141df..5434cedd 100644 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -17,6 +17,10 @@ class Lookup < ApplicationRecord "Gateway Communication Type" => "gateway_communication_type"} end + # def self.get_by_type( lookup_type) + # Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] } + # end + def self.collection_of(type) Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] } diff --git a/app/models/membership_action.rb b/app/models/membership_action.rb new file mode 100644 index 00000000..93a4b3d8 --- /dev/null +++ b/app/models/membership_action.rb @@ -0,0 +1,2 @@ +class MembershipAction < ApplicationRecord +end diff --git a/app/models/order.rb b/app/models/order.rb index 4817c3ce..c1dfec43 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -25,14 +25,15 @@ class Order < ApplicationRecord booking = nil if self.new_booking + puts "a" booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking", :checkin_at => Time.now.utc, :checkin_by => self.employee_name, :booking_status => "assign" }) + table = DiningFacility.find(self.table_id) + table.status = "occupied" + table.save else - if (self.booking_id.to_i > 0 ) - booking = Booking.find(self.booking_id) - end - + booking = Booking.find(self.booking_id) end booking.save! @@ -222,20 +223,34 @@ class Order < ApplicationRecord #Origami: Cashier : to view booking order Table def self.get_booking_order_table - booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, + booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, sales.sale_status as sale_status, + orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id, bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") - .joins("left join orders on orders.order_id = booking_orders.order_id") + .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true) - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") + end + #Origami: Cashier : to view booking order Table + def self.get_completed_order + completed_orders = Booking.select("sales.receipt_no,orders.status as order_status,orders.order_id, + bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id") + .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") + .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") + .joins("left join orders on orders.order_id = booking_orders.order_id") + .joins("left join sales on sales.sale_id = bookings.sale_id") + .where("sales.sale_status='completed'") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") end #Origami: Cashier : to view order type Room def self.get_booking_order_rooms - booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status,bookings.booking_id, + booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status, sales.sale_status as sale_status, + orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id, + bookings.booking_id,orders.customer_id as customer_id, sales.sale_id as sale_id,dining_facilities.name as room_name") .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") @@ -243,7 +258,7 @@ class Order < ApplicationRecord .joins("left join sale_orders on sale_orders.order_id = orders.order_id") .joins("left join sales on sales.sale_id = sale_orders.sale_id") .where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true) - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id") end #Origami: Cashier : to view order type Room @@ -263,8 +278,9 @@ class Order < ApplicationRecord def self.get_orders from = Time.now.beginning_of_day.utc to = Time.now.end_of_day.utc - orders = Order.select("orders.order_id as order_id,sales.receipt_no,orders.status as order_status, - bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") + orders = Order.select("orders.order_id as order_id,sales.receipt_no,orders.status as order_status, sales.sale_status as sale_status, + orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id + ,bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") .joins("left join booking_orders on booking_orders.order_id = orders.order_id left join bookings on bookings.booking_id = booking_orders.order_id left join dining_facilities on dining_facilities.id = bookings.dining_facility_id @@ -272,7 +288,7 @@ class Order < ApplicationRecord left join sale_orders on sale_orders.order_id = orders.order_id left join sales on sales.sale_id = sale_orders.sale_id") .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) - .group("orders.order_id,order_items.order_items_id,dining_facilities.name,sales.receipt_no,bookings.booking_id,sales.sale_id") + .group("orders.order_id,order_items.order_items_id,dining_facilities.name,sales.receipt_no,bookings.booking_id,sales.sale_id,orders.customer_id") end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 5a0eaf25..9c928593 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -40,7 +40,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker left join bookings AS b ON b.booking_id = bo.booking_id left join dining_facilities AS df ON df.id = b.dining_facility_id left join customers as cus ON cus.customer_id = orders.customer_id") - .where("orders.order_id='" + code.to_s + "'") + .where("orders.order_id='" + code + "'") .group("order_items.item_code") end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index d203568f..a8a27db3 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -63,12 +63,13 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker self.print(filename) end -#Bill Receipt Print - def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name) + + #Bill Receipt Print + def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, food_total, beverage_total) #Use CUPS service #Generate PDF #Print - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total) pdf.render_file "tmp/receipt_bill.pdf" self.print("tmp/receipt_bill.pdf") end diff --git a/app/models/sale.rb b/app/models/sale.rb index b0f07cb0..52625917 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -3,7 +3,6 @@ class Sale < ApplicationRecord #primary key - need to be unique generated for multiple shops before_create :generate_custom_id - #before_create :generate_receipt_no belongs_to :cashier, :optional => true belongs_to :customer, :optional => true @@ -17,7 +16,6 @@ class Sale < ApplicationRecord scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } def generate_invoice_from_booking(booking_id, requested_by) - puts "get invoice from booking" booking = Booking.find(booking_id) status = false Rails.logger.debug "Booking -> " + booking.id.to_s @@ -33,7 +31,6 @@ class Sale < ApplicationRecord booking.sale_id = sale_id end order = booking.booking_orders.take.order - puts "add sale order" link_order_sale(order.id) return status, sale_id end @@ -231,9 +228,10 @@ class Sale < ApplicationRecord def link_order_sale(order_id) #create if it doesn't exist saleOrder = SaleOrder.where("sale_id=? and order_id=?", self.id, order_id).take - + if saleOrder.nil? - SaleOrder.create(:sale_id => self.id, :order_id => order_id) + sale_order = SaleOrder.new + sale_order.create_sale_order(self.id, order_id) end # if (SaleOrder.where("sale_id = #{self.id} and order_id=#{order_id}").nil?) # SaleOrder.create(:sale_id => self.id, :order_id => order_id) @@ -261,7 +259,12 @@ class Sale < ApplicationRecord end private + def generate_custom_id self.sale_id = SeedGenerator.generate_id(self.class.name, "SAL") end + + def self.get_receipt_no_list(from,to) + sale = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from,to) + end end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 5d87ff13..ef852bbd 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -1,6 +1,6 @@ class SaleItem < ApplicationRecord self.primary_key = "sale_item_id" - + #primary key - need to be unique generated for multiple shops before_create :generate_custom_id @@ -12,24 +12,53 @@ class SaleItem < ApplicationRecord def self.get_order_items_details(sale_id) - order_details = SaleItem.select("sales.total_tax as tax_amount, sales.grand_total as grand_total_amount , sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date, + order_details = SaleItem.select("sales.total_tax as tax_amount, sales.grand_total as grand_total_amount , sales.total_discount as discount_amount,sales.receipt_date as receipt_date, sales.cashier_name,sales.receipt_no,sale_items.product_name as item_name,sale_items.qty,sale_items.price,sale_items.unit_price as total_price") .joins("left join sales on sales.sale_id = sale_items.sale_id") .where("sale_items.sale_id=?",sale_id) # sale_orders = SaleOrder.where("sale_id=?",sale_id) # if sale_orders - # sale_orders.each do |sale_order| + # sale_orders.each do |sale_order| # order_details = SaleItem.select("sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date,sales.cashier_name,sales.receipt_no,sale_items.product_name as item_name,sale_items.qty,sale_items.price,sale_items.unit_price as total_price") # .joins("left join sales on sales.id = sale_items.sale_id") - # .where("sale_items.sale_id=?",sale_order.sale_id) + # .where("sale_items.sale_id=?",sale_order.sale_id) # return order_details # end # else # return false # end end - + + def self.calculate_food_beverage(sale_items) + food_prices=0 + beverage_prices=0 + + sale_items.each do |si| + food_price, beverage_price = self.get_price(si.sale_item_id) + + food_prices = food_prices + food_price + beverage_prices = beverage_prices + beverage_price + end + return food_prices, beverage_prices + end + + def self.get_price(sale_item_id) + food_price=0 + beverage_price=0 + + item=SaleItem.select("sale_items.price , menu_items.account_id") + .joins("left join menu_items on menu_items.item_code = sale_items.product_code") + .where("sale_items.sale_item_id=?", sale_item_id.to_s) + if item[0].account_id == 1 + food_price = item[0].price + else + beverage_price = item[0].price + end + + return food_price, beverage_price + end + private def generate_custom_id self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 15da1386..786054c9 100644 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -2,13 +2,22 @@ class SaleOrder < ApplicationRecord self.primary_key = "sale_order_id" #primary key - need to be unique generated for multiple shops - before_create :generate_custom_id + before_create :generate_sale_order_id belongs_to :sale belongs_to :order + def create_sale_order(sale, order) + self.sale_id = sale + self.order_id = order + self.save + + end + private - def generate_custom_id - self.sale_order_id = SeedGenerator.generate_id(self.class.name, "SOI") + def generate_sale_order_id + self.class.name + saleOrderId = SeedGenerator.generate_id(self.class.name, "SOI") + self.sale_order_id = saleOrderId end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 2545eae7..ffe881e6 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -66,9 +66,9 @@ class SalePayment < ApplicationRecord end - def self.get_paypar_account(url,token,membership_id,campaign_type_id) + def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid) response = HTTParty.get(url, - :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id}.to_json, + :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -78,13 +78,14 @@ class SalePayment < ApplicationRecord end - def self.redeem(paypar_url,token,membership_id,received_amount,sale_id,campaign_type_id) - membership_actions_data = Settings::MembershipAction.find_by_membership_type("redeem_url"); + def self.redeem(paypar_url,token,membership_id,received_amount,sale_id) + membership_actions_data = MembershipAction.find_by_membership_type("redeem"); if !membership_actions_data.nil? url = paypar_url.to_s + membership_actions_data.gateway_url.to_s - campaign_type_id = 1 + merchant_uid = membership_actions_data.merchant_account_id + campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"] response = HTTParty.post(url, - :body => { generic_customer_id:membership_id,total_amount:received_amount,receipet_no:sale_id,campaign_type_id:campaign_type_id,account_no:""}.to_json, + :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipet_no:sale_id,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -93,7 +94,7 @@ class SalePayment < ApplicationRecord else response =false; end - + puts response.to_json return response; end @@ -106,7 +107,6 @@ class SalePayment < ApplicationRecord self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) return payment_status @@ -134,7 +134,7 @@ class SalePayment < ApplicationRecord self.payment_method = method self.payment_amount = self.received_amount self.payment_reference = self.card_payment_reference - self.outstanding_amount = self.sale.grand_total- self.received_amount + self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f self.payment_status = "paid" payment_method = self.save! @@ -188,10 +188,9 @@ class SalePayment < ApplicationRecord self.payment_status = "pending" payment_method = self.save! - campaign_type_id =1; customer_data = Customer.find_by_customer_id(self.sale.customer_id) 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,campaign_type_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 SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid') sale_update_payment_status(self.received_amount.to_f) @@ -207,15 +206,66 @@ class SalePayment < ApplicationRecord def sale_update_payment_status(paid_amount) #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f - self.sale.amount_changed = paid_amount.to_f - self.sale.amount_received - if (self.sale.grand_total <= self.sale.amount_received.to_f && self.sale.amount_changed.to_f > 0) + self.sale.amount_changed = paid_amount.to_f - self.sale.amount_received.to_f + all_received_amount = 0.0 + sObj = Sale.find(self.sale_id) + sObj.sale_payments.each do |spay| + all_received_amount += spay.payment_amount.to_f + end + if (self.sale.grand_total <= all_received_amount) self.sale.payment_status = "paid" self.sale.sale_status = "completed" self.sale.save! + table_update_status(sObj) + rebat(sObj) end end + def table_update_status(sale_obj) + booking = Booking.find_by_sale_id(sale_obj.id) + if booking + table = DiningFacility.find(booking.dining_facility_id) + if table + table.status = "available" + table.save + end + end + end + + def rebat(sObj) + food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items) + generic_customer_id = sObj.customer.membership_id + if generic_customer_id != nil || generic_customer_id != "" + paypar = sObj.sale_payments + payparcost = 0 + paypar.each do |pp| + if pp.payment_method == "paypar" + payparcost = payparcost + pp.payment_amount + end + end + total_amount = food_prices - payparcost + puts "aaaa" + puts food_prices + puts payparcost + puts total_amount + receipt_no = sObj.receipt_no + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("rebate") + campaign_type_id = memberaction.additional_parameter["campaign_type_id"] + app_token = membership.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,total_amount: total_amount,campaign_type_id: campaign_type_id, + receipt_no: receipt_no}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }) + + puts response.to_json + end + end + private def generate_custom_id self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI") diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index 5e7864b6..fe896a4d 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -1,7 +1,9 @@ class SeedGenerator < ApplicationRecord + def self.generate_id(model, prefix) seed = SeedGenerator.find_by_model(model) new_receipt_no = 0 + if (seed.nil?) seed = SeedGenerator.new() seed.model = model @@ -16,8 +18,8 @@ class SeedGenerator < ApplicationRecord end padding_len = 15 - prefix.length - - return prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0') + saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0') + return saleOrderId end diff --git a/app/models/settings/membership_action.rb b/app/models/settings/membership_action.rb deleted file mode 100644 index 814e4b97..00000000 --- a/app/models/settings/membership_action.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Settings::MembershipAction < ApplicationRecord -end diff --git a/app/pdf/crm_order_pdf.rb b/app/pdf/crm_order_pdf.rb index 94fc5503..55d08ecc 100644 --- a/app/pdf/crm_order_pdf.rb +++ b/app/pdf/crm_order_pdf.rb @@ -1,6 +1,6 @@ class CrmOrderPdf < Prawn::Document attr_accessor :receipt_width,:price_column_width,:p_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_column_width,:item_description_width - def initialize(booking,order_items,print_settings) + def initialize(booking,order_items,printer_settings) self.p_width = 200 self.page_height = 1450 self.margin = 10 @@ -18,20 +18,19 @@ class CrmOrderPdf < Prawn::Document @half_qty = @qty_width / 2 #setting page margin and width super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.p_width, self.page_height]) - self.header_font_size = 7 + self.header_font_size = 10 self.item_font_size = 9 - header( booking.type, booking.dining_facility.name) + header( printer_settings.printer_name, printer_settings.name) stroke_horizontal_rule - order_detail(booking.checkin_by,booking.checkin_at,booking.dining_facility.name) + cashier_info(booking) line_items(order_items) - #all_total(order_items) end - def header (type, name) - text "#{type}", :size => self.header_font_size,:align => :center + def header (printer_name, name) + text "#{printer_name}", :size => self.header_font_size,:align => :center move_down 5 text "#{name}", :size => self.header_font_size,:align => :center # move_down self.item_height @@ -41,37 +40,37 @@ class CrmOrderPdf < Prawn::Document end - def order_detail(order_by,order_at,customer) + def cashier_info(booking) move_down 5 move_down 2 y_position = cursor - qty_column_width = self.p_width * 0.2 - item_description_width = self.p_width * 0.5 - price_column_width = self.p_width * 0.3 + bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + text "Order By:", :size => self.item_font_size,:align => :left + end - - - stroke_horizontal_rule + bounding_box([self.price_width, y_position], :width =>self.receipt_width) do + text "#{booking.checkin_by}" , :size => self.item_font_size, :align => :left + end move_down 5 + y_position = cursor - pad_top(15) { - # @item_width.to_i + @half_qty.to_i - text_box "Order By", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size - text_box "Order At", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "Customer", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - - } - + bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + text "Customer:", :size => self.item_font_size,:align => :left + end + bounding_box([self.price_width,y_position], :width =>self.price_width) do + text "#{booking.customer_id}" , :size => self.item_font_size,:align => :left + end move_down 5 - stroke_horizontal_rule -y_position = cursor - pad_top(15) { - text_box "#{order_by}", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "#{order_at.to_i}", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "#{customer}", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - - } + y_position = cursor + bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + text "Date:", :size => self.item_font_size,:align => :left + end + bounding_box([self.price_width,y_position], :width =>self.price_width) do + text "#{booking.checkin_at.strftime('%Y %m %d %h:%m')}" , :size => self.item_font_size,:align => :left + end + # stroke_horizontal_rule + move_down 5 end def line_items(order_items) @@ -97,10 +96,41 @@ y_position = cursor move_down 5 stroke_horizontal_rule - + add_line_item_row(order_items) + end - + def add_line_item_row(order_items) + y_position = cursor + move_down 5 + sub_total = 0.0 + order_items.each do |item| + + sub_total += item.qty*item.price + qty = item.qty + total_price = item.qty*item.price + price = item.price + item_name = item.item_name + + + y_position = cursor + + pad_top(15) { + # @item_width.to_i + @half_qty.to_i + text_box "#{item_name}", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size + text_box "#{price}", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + text_box "#{qty.to_i}", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + text_box "#{total_price}", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + + } + move_down 3 + end + stroke_horizontal_rule + move_down 5 + y_position = cursor + + end + end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 3044c578..f322de64 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -1,29 +1,46 @@ class OrderItemPdf < Prawn::Document - + attr_accessor :receipt_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:item_description_width def initialize(order_item, print_settings) - super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + self.page_width = 300 + self.page_height = 400 + self.margin = 10 + self.price_width = 50 + self.qty_width = 50 + self.item_width = self.page_width - (self.price_width + self.qty_width) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width) + self.receipt_width=130 + + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) # font "public/fonts/#{font_name}".to_s + ".ttf".to_s # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - font_size 9 - text "#{order_item.dining}", :size => 15 + # font "public/fonts/padauk.ttf" + self.header_font_size = 12 + self.item_font_size = 10 + + text "#{order_item.dining}", :size => self.header_font_size,:align => :center stroke_horizontal_rule move_down 5 #order_info - order_info(order_item.order_by,order_item.order_at, order_item.customer) + order_info(order_item.order_by,order_item.order_at) # order items order_items(order_item) end # Write Order Information to PDF - def order_info(order_by, order_at, customer) + def order_info(order_by, order_at) y_position = cursor - bounding_box([0,y_position], :width => 200, :height => 15) do - text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y-%m-%d")}", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width - 50, :height => self.item_height) do + text "OrderBy:#{order_by} ", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width - 50,y_position], :width => self.item_width + 50, :height => self.item_height) do + text "Date:#{order_at.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -35,12 +52,12 @@ class OrderItemPdf < Prawn::Document def order_items(order_item) y_position = cursor - bounding_box([0,y_position], :width => 180, :height => 15) do - text "Item", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Item", :size => self.item_font_size,:align => :left end - bounding_box([160,y_position], :width => 20, :height => 15) do - text "Qty", :size => 7,:align => :right + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + text "Qty", :size => self.item_font_size,:align => :right end stroke_horizontal_rule @@ -56,12 +73,12 @@ class OrderItemPdf < Prawn::Document move_down 5 - bounding_box([0,y_position], :width => 180, :height => 20) do - text "#{order_item.item_name}", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "#{order_item.item_name}", :size => self.item_font_size,:align => :left end - bounding_box([160,y_position], :width => 20, :height => 20) do - text "#{order_item.qty}", :size => 7,:align => :right + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + text "#{order_item.qty}", :size => self.item_font_size,:align => :right end move_down 5 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 8a7a1ad9..63d75a78 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -1,19 +1,30 @@ class OrderSummaryPdf < Prawn::Document - + attr_accessor :receipt_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:item_description_width def initialize(order, print_settings) - super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + self.page_width = 300 + self.page_height = 400 + self.margin = 10 + self.price_width = 60 + self.qty_width = 60 + self.item_width = self.page_width - (self.price_width + self.qty_width) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width) + self.receipt_width=130 + + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # font "public/fonts/#{font_name}".to_s + ".ttf".to_s # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" + self.header_font_size = 12 + self.item_font_size = 10 - font_size 9 - text "#{order[0].dining}", :size => 15 + text "#{order[0].dining}", :size => self.header_font_size,:align => :center stroke_horizontal_rule move_down 5 #order_info - order_info(order[0].order_by,order[0].order_at, order[0].customer) + order_info(order[0].order_by,order[0].order_at) # order items order_items(order) @@ -21,11 +32,15 @@ class OrderSummaryPdf < Prawn::Document end # Write Order Information to PDF - def order_info(order_by, order_at, customer) + def order_info(order_by, order_at) y_position = cursor - bounding_box([0,y_position], :width => 200, :height => 15) do - text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y-%m-%d")}", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width - 20, :height => self.item_height) do + text "OrderBy:#{order_by} ", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width - 20,y_position], :width => self.item_width + 20, :height => self.item_height) do + text "Date:#{order_at.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -37,12 +52,12 @@ class OrderSummaryPdf < Prawn::Document def order_items(order_item) y_position = cursor - bounding_box([0,y_position], :width => 180, :height => 15) do - text "Item", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Item", :size => self.item_font_size,:align => :left end - bounding_box([160,y_position], :width => 20, :height => 15) do - text "Qty", :size => 7,:align => :right + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + text "Qty", :size => self.item_font_size,:align => :right end stroke_horizontal_rule @@ -59,13 +74,13 @@ class OrderSummaryPdf < Prawn::Document move_down 5 order_item.each do|odi| - bounding_box([0,y_position], :width => 180, :height => 20) do - text "#{odi.item_name}", :size => 7,:align => :left - end + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "#{odi.item_name}", :size => self.item_font_size,:align => :left + end - bounding_box([160,y_position], :width => 20, :height => 20) do - text "#{odi.qty}", :size => 7,:align => :right - end + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + text "#{odi.qty}", :size => self.item_font_size,:align => :right + end end move_down 5 diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 5853b946..dbaea572 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,171 +1,184 @@ class ReceiptBillPdf < Prawn::Document - attr_accessor :receipt_width,:price_column_width,:p_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_column_width,:item_description_width - def initialize(printer_settings, sale_items, sale_data, customer_name) - self.p_width = 200 + attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width + def initialize(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total) + self.page_width = 250 self.page_height = 1450 self.margin = 10 - # self.price_width = self.p_width / 2 - self.price_width=80 - self.item_width = self.p_width - self.price_width - self.item_height = self.item_height - self.qty_column_width = self.p_width / 2 - self.item_description_width=self.p_width - self.price_width - self.receipt_width=130 + self.price_width = 40 + self.qty_width = 20 + self.total_width = 40 + self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)+(self.margin*4)) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) + self.label_width=80 - @item_width = self.p_width.to_i / 2 - @qty_width = @item_width.to_i / 3 - @double = @qty_width * 1.3 - @half_qty = @qty_width / 2 + # @item_width = self.page_width.to_i / 2 + # @qty_width = @item_width.to_i / 3 + # @double = @qty_width * 1.3 + # @half_qty = @qty_width / 2 #setting page margin and width - super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.p_width, self.page_height]) - self.header_font_size = 10 + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # font "public/fonts/#{font_name}".to_s + ".ttf".to_s + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + self.header_font_size = 11 self.item_font_size = 9 header( printer_settings.printer_name, printer_settings.name) - stroke_horizontal_rule - cashier_info(sale_data, customer_name) - line_items(sale_items) - all_total(sale_data) - + stroke_horizontal_rule + + cashier_info(sale_data, customer_name) + line_items(sale_items, food_total, beverage_total) + all_total(sale_data) + footer end def header (printer_name, name) - text "#{printer_name}", :size => self.header_font_size,:align => :center - move_down 5 - text "#{name}", :size => self.header_font_size,:align => :center - # move_down self.item_height - move_down 5 - - stroke_horizontal_rule + text "#{printer_name}", :left_margin => -10, :size => self.header_font_size,:align => :center + move_down 5 + text "#{name}", :size => self.header_font_size,:align => :center + # move_down self.item_height + move_down 5 + stroke_horizontal_rule end def cashier_info(sale_data, customer_name) - move_down 5 - move_down 2 + move_down 7 + # move_down 2 y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Receipt No:", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width, y_position], :width =>self.receipt_width) do - text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left + bounding_box([self.label_width, y_position], :width =>self.item_width) do + text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left end move_down 5 y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Customer:", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([self.label_width,y_position], :width =>self.item_width) do text "#{customer_name}" , :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do - text "Date:", :size => self.item_font_size,:align => :left + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Date:", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do - text "#{sale_data.receipt_date.strftime('%Y %m %d %h:%m')}" , :size => self.item_font_size,:align => :left + bounding_box([self.label_width,y_position], :width => self.item_width) do + text "#{sale_data.receipt_date.strftime('%Y-%m-%d %I:%M %p')}" , :size => self.item_font_size,:align => :left end - # stroke_horizontal_rule + + move_down 5 + stroke_horizontal_rule move_down 5 end - def line_items(sale_items) + def line_items(sale_items, food_total, beverage_total) y_position = cursor - qty_column_width = self.p_width * 0.2 - item_description_width = self.p_width * 0.5 - price_column_width = self.p_width * 0.3 - - - stroke_horizontal_rule - move_down 5 - y_position = cursor pad_top(15) { # @item_width.to_i + @half_qty.to_i - text_box "Items", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size - text_box "Price", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "Qty", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "Total", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix + text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "Total", :at =>[(self.item_width+self.price_width+2),y_position], :width => self.total_width+2, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down 5 stroke_horizontal_rule - add_line_item_row(sale_items) + add_line_item_row(sale_items, food_total, beverage_total) - end - def add_line_item_row(sale_items) + def add_line_item_row(sale_items, food_total, beverage_total) + item_name_width = (self.item_width+self.price_width) y_position = cursor move_down 5 sub_total = 0.0 - sale_items.each do |item| + sale_items.each do |item| + sub_total += (item.qty*item.unit_price) + qty = item.qty + total_price = item.qty*item.unit_price + price = item.unit_price + product_name = item.product_name + - sub_total += item.qty*item.unit_price - qty = item.qty - total_price = item.qty*item.unit_price - price = item.unit_price - product_name = item.product_name - + y_position = cursor - y_position = cursor + pad_top(15) { + # @item_width.to_i + @half_qty.to_i + text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size, :overflow => :shrink_to_fix + text_box "#{price}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{qty.to_i}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{total_price}", :at =>[(item_name_width+2),y_position], :width =>self.total_width+2, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - pad_top(15) { - # @item_width.to_i + @half_qty.to_i - text_box "#{product_name}", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size - text_box "#{price}", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "#{qty.to_i}", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "#{total_price}", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + } + move_down 3 + end - } - move_down 3 - end stroke_horizontal_rule + move_down 5 y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>item_name_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do - text "#{sub_total}" , :size => self.item_font_size,:align => :right + bounding_box([item_name_width,y_position], :width =>self.total_width) do + text "#{ sub_total }" , :size => self.item_font_size,:align => :right + end + + # Food and Beverage + food_beverage_total = food_total.to_s + "/" + beverage_total.to_s + + move_down 5 + + y_position = cursor + bounding_box([0,y_position], :width =>(item_name_width), :height => self.item_height) do + text "Food/Beverage Total", :size => self.item_font_size,:align => :left + end + bounding_box([item_name_width,y_position], :width =>self.total_width) do + text "#{ food_beverage_total }" , :size => self.item_font_size,:align => :right end end def all_total(sale_data) + item_name_width = self.item_width move_down 5 - y_position =cursor + y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>(item_name_width+self.price_width), :height => self.item_height) do text "Discount", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([(item_name_width+self.price_width),y_position], :width =>self.total_width) do text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right end move_down 5 - y_position =cursor + y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>(item_name_width+self.price_width), :height => self.item_height) do text "Total Tax", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([(item_name_width+self.price_width),y_position], :width =>self.total_width) do text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right end move_down 5 y_position = cursor move_down 5 - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>(item_name_width+self.price_width), :height => self.item_height) do text "Grand Total", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([(item_name_width+self.price_width),y_position], :width =>self.total_width) do text "#{sale_data.grand_total}" , :size => self.item_font_size,:align => :right end move_down 5 @@ -173,4 +186,14 @@ class ReceiptBillPdf < Prawn::Document end + def footer + move_down 5 + stroke_horizontal_rule + move_down 5 + + text "*** Thank You ***", :left_margin => -10, :size => self.header_font_size,:align => :center + + move_down 5 + end + end diff --git a/app/views/api/customers/get_customer_order.json.jbuilder b/app/views/api/customers/get_customer_order.json.jbuilder new file mode 100644 index 00000000..f00ce173 --- /dev/null +++ b/app/views/api/customers/get_customer_order.json.jbuilder @@ -0,0 +1,38 @@ +if (@customer) + json.id @customer.customer_id + json.name @customer.name + json.email @customer.email + json.contact_no @customer.contact_no + json.date_of_birth @customer.date_of_birth + + + @total_amount = 0.00 + @total_tax = 0.00 + + if @customer.orders + order_items = [] + @customer.orders.each do |bo| + order = Order.find(bo.order_id) + #if (order.status == "new") + order_items = order_items + order.order_items + #end + end + + json.order_items order_items do |item| + json.item_instance_code item.item_code + json.item_name item.item_name + json.price item.price + json.qty item.qty + json.options item.options + json.remark item.remark + json.item_status item.order_item_status + @total_amount = @total_amount + (item.price * item.qty) + end + + end + + json.sub_total @total_amount + json.commerical_tax @total_amount * 0.05 + json.total @total_amount + (@total_amount * 0.05) + +end \ No newline at end of file diff --git a/app/views/crm/customers/_error_messages.html.erb b/app/views/crm/customers/_error_messages.html.erb new file mode 100644 index 00000000..bbff284b --- /dev/null +++ b/app/views/crm/customers/_error_messages.html.erb @@ -0,0 +1,9 @@ +
+ +
diff --git a/app/views/crm/customers/_form.html.erb b/app/views/crm/customers/_form.html.erb index 758a52a2..c913651a 100644 --- a/app/views/crm/customers/_form.html.erb +++ b/app/views/crm/customers/_form.html.erb @@ -16,5 +16,5 @@ <%= f.button :submit %> <% end %> - + \ No newline at end of file diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 86f267b0..9f62b55b 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -11,7 +11,7 @@ -
+
@@ -21,6 +21,17 @@ + + + + @@ -40,7 +51,7 @@ @@ -48,66 +59,65 @@ <% end %>
+ <%= form_tag crm_customers_path, :method => :get do %> +
+ + +
+ <% end %> +
Select Name<%= crm_customer.contact_no %> <%= crm_customer.email %> - <%= link_to 'Destroy', crm_customer_path(crm_customer), method: :delete, data: { confirm: 'Are you sure?' } %> + <%= link_to 'Show', crm_customer_path(crm_customer) %>
+
+ + <%= paginate @crm_customers %>
- <%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> - - - <%= f.hidden_field :id, :class => "form-control col-md-6 " %> - -
- <%= f.input :name, :class => "form-control col-md-6 name" %> + <%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> -
-
- <%= f.input :company, :class => "form-control col-md-6 company" %> -
-
- <%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %> + + <%= f.error_notification %> + <%= f.hidden_field :id, :class => "form-control col-md-6 " %> + +
+ <%= f.input :name, :class => "form-control col-md-6 name" %> + +
+
+ <%= f.input :company, :class => "form-control col-md-6 company" %> +
+
+ <%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %> -
+
-
- <%= f.input :email, :class => "form-control col-md-6 email" %> -
+
+ <%= f.input :email, :class => "form-control col-md-6 email" %> +
-
- - <%= f.text_field :date_of_birth,:class=>"form-control datepicker date_of_birth",:readonly =>true, :value => @date_of_birth%> -
+
+ + <%= f.text_field :date_of_birth,:class => "form-control datepicker date_of_birth "%> +
-
- - <% @member_group.each do |member| %> - + <% Lookup.where("lookup_type = ?", "member_group_type" ).each do |member| %> + <%end %>
+ - -
- <%= f.input :membership_type, :class => "form-control col-md-6 membership_type" %> -
-
- <%= f.input :membership_authentication_code, :class => "form-control col-md-6 membership_authentication_code" %> - -
-
+
<%= f.button :submit, "Submit",:class => 'btn btn-primary ', :id => 'submit_customer' %> <%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'', :id => 'update_customer' %> -
- <%end%>
+ <%end%>
+ + + diff --git a/app/views/crm/customers/show.html.erb b/app/views/crm/customers/show.html.erb index da88e887..45529dc6 100644 --- a/app/views/crm/customers/show.html.erb +++ b/app/views/crm/customers/show.html.erb @@ -1,40 +1,84 @@ -

<%= notice %>

- -

- Name: - <%= @crm_customer.name %> -

- -

- Company: - <%= @crm_customer.company %> -

- -

- Contact no: - <%= @crm_customer.contact_no %> -

- -

- Email: - <%= @crm_customer.email %> -

- -

- Date of birth: - <%= @crm_customer.date_of_birth %> -

+
+
+ +
+
-

- Membership type: - <%= @crm_customer.membership_type %> -

+
+
+ +
+
+
+ + + + + + + + + + -

- Membership authentication code: - <%= @crm_customer.membership_authentication_code %> -

+ + + + + + + + + + +
NameEmailContact noCompanyDate Of Birth
<%= @crm_customer.name %><%= @crm_customer.email %><%= @crm_customer.contact_no %><%= @crm_customer.company %><%= @crm_customer.date_of_birth %>
+
+

Order Details

+ + + + + + + + + + + + + + + + <% @order_items.each do |order_item| %> + + + + + + + + + + <% end %> + +
Created at Menu ItemQTYUnit Price OptionStatusWaiter
<%= order_item.created_at %><%= order_item.item_name %><%= order_item.qty %><%= order_item.price %><%= order_item.options %><%= order_item.order_item_status %><%= order_item.item_order_by %>
+
+
+ +
+ + +
+ + + + -<%= link_to 'Edit', edit_crm_customer_path(@crm_customer) %> | -<%= link_to 'Back', crm_customers_path %> diff --git a/app/views/crm/dining_queues/_crm_dining_queue.json.jbuilder b/app/views/crm/dining_queues/_crm_dining_queue.json.jbuilder new file mode 100644 index 00000000..f2580e52 --- /dev/null +++ b/app/views/crm/dining_queues/_crm_dining_queue.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! crm_dining_queue, :id, :name, :contact, :queue_no, :created_at, :updated_at +json.url crm_dining_queue_url(crm_dining_queue, format: :json) diff --git a/app/views/crm/dining_queues/_form.html.erb b/app/views/crm/dining_queues/_form.html.erb new file mode 100644 index 00000000..a99f6b76 --- /dev/null +++ b/app/views/crm/dining_queues/_form.html.erb @@ -0,0 +1,16 @@ + +<%= simple_form_for([:crm,@dining_queue]) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :name %> + <%= f.input :contact_no %> + <%= f.input :queue_no %> + +
+ +
+ <%= f.button :submit %> +
+<% end %> + diff --git a/app/views/crm/dining_queues/edit.html.erb b/app/views/crm/dining_queues/edit.html.erb new file mode 100644 index 00000000..e5ca3b9f --- /dev/null +++ b/app/views/crm/dining_queues/edit.html.erb @@ -0,0 +1,11 @@ + +
+ + <%= render 'form', dining_queue: @dining_queue %> +
diff --git a/app/views/crm/dining_queues/index.html.erb b/app/views/crm/dining_queues/index.html.erb new file mode 100644 index 00000000..e7834b98 --- /dev/null +++ b/app/views/crm/dining_queues/index.html.erb @@ -0,0 +1,38 @@ + + + + +
+
+ + + + + + + + + + + + <% @dining_queues.each do |dining_queue| %> + + + + + + + <% end %> + +
NameContact NoQueue NoAction
<%= dining_queue.name %><%= dining_queue.contact_no %><%= dining_queue.queue_no %> + <%= link_to 'Edit', edit_crm_dining_queue_path(dining_queue) %> | <%= link_to 'Destroy', crm_dining_queue_path(dining_queue), method: :delete, data: { confirm: 'Are you sure?' } %>
+
+ diff --git a/app/views/crm/dining_queues/index.json.jbuilder b/app/views/crm/dining_queues/index.json.jbuilder new file mode 100644 index 00000000..979087b7 --- /dev/null +++ b/app/views/crm/dining_queues/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @crm_dining_queues, partial: 'crm_dining_queues/crm_dining_queue', as: :crm_dining_queue diff --git a/app/views/crm/dining_queues/new.html.erb b/app/views/crm/dining_queues/new.html.erb new file mode 100644 index 00000000..280a59b2 --- /dev/null +++ b/app/views/crm/dining_queues/new.html.erb @@ -0,0 +1,11 @@ + +
+ + <%= render 'form', dining_queue: @dining_queue %> +
\ No newline at end of file diff --git a/app/views/crm/dining_queues/show.html.erb b/app/views/crm/dining_queues/show.html.erb new file mode 100644 index 00000000..5e52a611 --- /dev/null +++ b/app/views/crm/dining_queues/show.html.erb @@ -0,0 +1,19 @@ +

<%= notice %>

+ +

+ Name: + <%= @crm_dining_queue.name %> +

+ +

+ Contact: + <%= @crm_dining_queue.contact %> +

+ +

+ Queue no: + <%= @crm_dining_queue.queue_no %> +

+ +<%= link_to 'Edit', edit_crm_dining_queue_path(@crm_dining_queue) %> | +<%= link_to 'Back', crm_dining_queues_path %> diff --git a/app/views/crm/dining_queues/show.json.jbuilder b/app/views/crm/dining_queues/show.json.jbuilder new file mode 100644 index 00000000..83c09bea --- /dev/null +++ b/app/views/crm/dining_queues/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "crm_dining_queues/crm_dining_queue", crm_dining_queue: @crm_dining_queue diff --git a/app/views/crm/home/_booking.html.erb b/app/views/crm/home/_booking.html.erb index 3a2a7684..fbe837a7 100644 --- a/app/views/crm/home/_booking.html.erb +++ b/app/views/crm/home/_booking.html.erb @@ -6,29 +6,29 @@ <% @booking.each do |booking| %> <% if booking.booking_status == "new" %>
-
- -

- <%= @i += 1 %> . <%= booking.dining_facility.name %> - - <%= booking.id %> -

- -

- - Order at <%= booking.checkin_at.strftime("%H,%m") %>, <%= booking.checkin_by %> - -

-
- -
+ @@ -214,14 +385,13 @@ - - - + + + - + - - + diff --git a/app/views/origami/mpu/create.json.jbuilder b/app/views/origami/mpu/create.json.jbuilder new file mode 100644 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/mpu/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb new file mode 100644 index 00000000..7b483a75 --- /dev/null +++ b/app/views/origami/mpu/index.html.erb @@ -0,0 +1,26 @@ +

MPU

+ + +Amount : + + + + + + diff --git a/app/views/origami/others_payments/index.html.erb b/app/views/origami/others_payments/index.html.erb index 77c06904..4b2397a2 100644 --- a/app/views/origami/others_payments/index.html.erb +++ b/app/views/origami/others_payments/index.html.erb @@ -1,177 +1,19 @@
- -
-
+ +
+
<% @payment_method_setting.each do |payment_method|%> -
-
<%= payment_method.payment_method %>
-
- <% end %> +
<%= payment_method.payment_method %>
+ <% end %>
- -
- -
-
-
-
-
-
1
-
2
-
3
-
-
-
-
1000
-
-
-
-
-
-
4
-
5
-
6
-
-
-
-
5000
-
-
-
-
-
-
7
-
8
-
9
-
-
-
-
10000
-
-
-
-
-
-
0
-
.
-
00
-
-
-
-
50000
-
-
-
-
-
-
-
DEL
-
CLR
-
-
-
-
PAY
-
-
-
-
- -
-
-
-
+ \ No newline at end of file +$('.others-payment').on('click',function(){ + var input_type = $(this).attr("data-type"); + var sale_id = $(this).attr("data-sale-id"); + window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment/" + input_type; +}) + diff --git a/app/views/origami/payments/create.json.jbuilder b/app/views/origami/payments/create.json.jbuilder new file mode 100644 index 00000000..08bf292c --- /dev/null +++ b/app/views/origami/payments/create.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 85505ef5..f9ae06b7 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1,25 +1,35 @@
-
+
- Receipt No : <%=@sale_data.receipt_no rescue ' '%> - Receipt Date : <%=@sale_data.receipt_date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%> - Table No <% if @sale_data%>- <%=@sale_data.receipt_no%><% end %> - Sale Id <% if @sale_data %><%=@sale_data.sale_id %><% end %> + + + + + + + + + + + + + +
Receipt No : <%=@sale_data.receipt_no rescue ' '%>Receipt Date : <%=@sale_data.receipt_date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>
Table No <% if @sale_data%>- <%=@sale_data.receipt_no%><% end %>Sale Id <% if @sale_data %><%=@sale_data.sale_id %><% end %>
Customer : Default CustomerPoints : 1234
- - +
+ - - + - +
ItemsQTY - Price + ItemsQTY + Price
@@ -71,99 +81,87 @@
-
-
AMOUNT DUE
-
<%= @sale_data.grand_total %>
+
+
Amount Due
+
<%= @sale_data.grand_total %>

-
CASH
-
0.0
+
Cash
+
<%= @cash %>

-
CREDIT
-
0.0
+
Credit
+
0.0

-
OTHERS PAYMENT
-
0.0
+
Others Payment
+
<%= @other %>

-
BALANCE
+
Balance
<%= @sale_data.grand_total %>

-
-
-
-
-
-
1
-
2
-
3
-
-
-
-
1000
+ +
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
-
-
-
-
4
-
5
-
6
-
+
+
+
1000
+
3000
-
-
5000
+
+
5000
+
10000
+
+
+
Pay
-
-
-
-
7
-
8
-
9
-
-
-
-
10000
-
-
-
-
-
-
0
-
.
-
00
-
-
-
-
50000
-
-
-
-
-
-
-
DEL
-
CLR
-
-
-
-
PAY
-
-
-
+ +
+
+ + +
diff --git a/app/views/reports/daily_sale_report.html.erb b/app/views/reports/daily_sale_report.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb b/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb new file mode 100644 index 00000000..1b4082f5 --- /dev/null +++ b/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb @@ -0,0 +1,211 @@ +
+
+ <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
+
+ + +
+
+ + +
+
+ + + +
+
+ + +
+
+ +
+
+ <% end %> + + + +
+
+ <% if defined? promotions %> + <%= select_tag "promotion", options_for_select(@promotions, :selected => params[:promotion_type]), :class => "form-control" %> + <% end %> + + <% if defined? menu_types %> + <%= select_tag "menu_type", options_for_select(@menu_types, :selected => params[:menu_type]), :class => "form-control" %> + <% end %> + + <% if defined? payments %> + <%= select_tag "payment_type", options_for_select(@payments, :selected => params[:payment_type]), :class => "form-control" %> + <% end %> + + <% if defined? shift_name %> + + <% end %> + + <% if defined? cashiers %> + <%= select_tag "cashier", options_from_collection_for_select(@cashiers,"id","name"),:prompt => "All Cashier Stations", :class => "form-control" %> + <% end %> + + <% if defined? singer %> + <%= select_tag "singer", options_from_collection_for_select(singer,"id","name"),:prompt => "All Vocal List", :class => "form-control" %> + <% end %> + + <% if defined? bsm %> + <%= select_tag "singer", options_from_collection_for_select(bsm,"id","name"),:prompt => "All BSM List", :class => "form-control" %> + <% end %> + + <% if defined? guest_role %> + <%= select_tag "guest_role", options_from_collection_for_select(@guest_role,"id","name"),:prompt => "Vocal/BSM List", :class => "form-control" %> + <% end %> + + <% if defined? list_by_payment_type %> + <%= select_tag "payment_type_list", options_for_select(@payment_list, :selected => params[:payment_type_list]), :class => "form-control" %> + <% end %> + + <% if defined? products %> + <%= select_tag "product", options_from_collection_for_select(@products,"id","name"),:prompt => "All Products", :class => "form-control" %> + <% end %> + + <% if defined? items %> + <%= select_tag "item", options_for_select(@items, :selected => params[:item_type]), :class => "form-control" %> + <% end %> +
+
+ + + + <% end %> +
+
+ + + + \ No newline at end of file diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb new file mode 100644 index 00000000..9d5c4f88 --- /dev/null +++ b/app/views/reports/receipt_no/index.html.erb @@ -0,0 +1,110 @@ + + +
+ <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_receipt_no_index_path} %> +
+
+ +
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + <% total_sales = 0 %> + <% net_sales = 0 %> + <% @sale_data.each do |sale| %> + <% total_sales = sale.total_amount.to_f - sale.total_discount.to_f%> + <% net_sales = total_sales.to_f + sale.total_tax.to_f%> + + + + + + + + + + + <% end %> + +
DateReceipt NoCashier NameGross SalesDiscountTotal SalesCTNett Sales
<%= sale.receipt_date.strftime("#{sale.receipt_date.day.ordinalize} %b") rescue '-' %><%=sale.receipt_no.to_s rescue ''%><%=sale.cashier_id rescue ''%><%= number_with_delimiter(sprintf("%.2f",sale.total_amount.to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale.total_discount.to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",total_sales.to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale.total_tax.to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",net_sales.to_f), :delimiter => ',') %>
+
+
+ +<%= paginate @sale_data %> + + \ No newline at end of file diff --git a/app/views/reports/receipt_no/index.xls.erb b/app/views/reports/receipt_no/index.xls.erb new file mode 100644 index 00000000..2191d814 --- /dev/null +++ b/app/views/reports/receipt_no/index.xls.erb @@ -0,0 +1,135 @@ +
+
+ +<% unless @sale_data.empty? %> +

<%=current_active_location.name%>

+

Sales Summary Report (BreadTalk)

+<% if params[:from]%> +

From Date : <%= params[:from] %> , To Date : <%= params[:to] %>

+<% end %> + + + + + + + + + + + + + + + + + + + + + <% void = 0 %> + <% card = 0 %> + <% credit_payment = 0 %> + <% cash = 0 %> + <% credit = 0 %> + <% foc = 0 %> + <% discount = 0 %> + <% total = 0 %> + <% count = 1 %> + <% discount_rev = 0 %> + <% total_rev = 0 %> + <% grand_rev = 0 %> + <% total_other_charges=0 %> + <% total_tax=0 %> + <% cash_received = 0 %> + <% total_cash_received = 0 %> + <% today_credit_payment_amount = 0 %> + <% old_location_id = 0%> + <% sub_total = 0 %> + <% count_of_void = 0 %> + <% flag = false %> + <% @sale_data.each do |sale| %> + <% credit_payment += sale[:credit_payment].to_f %> + <% card += sale[:card_amount].to_f %> + <% cash += sale[:cash_amount].to_f %> + <% credit += sale[:credit_amount].to_f %> + <% foc += sale[:foc_amount].to_f %> + <% discount += sale[:total_discount].to_f %> + <% total += sale[:grand_total].to_f %> + <% total_other_charges +=sale[:other_charges].to_f %> + <% total_tax +=sale[:total_tax].to_f %> + + <% cash_received = sale[:cash_amount].to_f + sale[:credit_payment].to_f%> + <% total_cash_received = cash.to_f + credit_payment.to_f%> + <% today_credit_payment_amount += sale[:today_credit_payment].to_f %> + + + + + + + + + + + + + + + <% total_void_amount = 0 %> + <% if !@daily_void.nil? %> + <% @daily_void.each do |d_v|%> + + <% if d_v[:daily_void_amt].to_i > 0 %> + <% if d_v[:location_id] == sale[:location_id] %> + <% if d_v[:date].utc.getlocal.strftime("%Y-%m-%d").to_s == sale[:sale_date].to_s%> + <%count_of_void+=1%> + + <%total_void_amount += d_v[:daily_void_amt].to_f%> + <% flag = true %> + + + + <%end %> + <% end%> + <% end%> + <% end%> + <% end%> + <% if flag == true%> + <% void += total_void_amount.to_f %> + + <% flag = false %> + <% end%> + <%if count_of_void == 0%> + + <%end %> + + + + +<%count_of_void= 0%> + <% count = count + 1 %> + <% end %> + + + + + + + + + + + + + + + + + +<% end %> +
Location NameDateCash SalesCredit SalesCredit ReceivedCard PaymentTotal DiscountTotal TaxesTotal Other ChargesFOC SalesVoid SalesGrand Total
<%= sale[:location].to_s rescue '-' %><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount].to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount].to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale[:credit_payment].to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale[:card_amount].to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale[:total_discount].to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale[:total_tax].to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale[:other_charges].to_f), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount].to_f), :delimiter => ',') %> <%= number_with_delimiter(sprintf("%.2f",total_void_amount.to_f), :delimiter => ',') %> <%= number_with_delimiter(sprintf("%.2f",0.to_f), :delimiter => ',') %> + <%= number_with_delimiter(sprintf("%.2f",((sale[:cash_amount].to_f + sale[:credit_amount].to_f + sale[:card_amount].to_f + sale[:credit_payment].to_f) - sale[:today_credit_payment].to_f) ).to_f, :delimiter => ',') %> +
Grand Total<%= number_with_delimiter(sprintf("%.2f",cash), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",credit ), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",credit_payment ), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",card ), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",discount ), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",total_tax ), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",total_other_charges ), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",foc ), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f",void ), :delimiter => ',') %><%= number_with_delimiter(sprintf("%.2f", (cash.to_f + credit.to_f + card.to_f + credit_payment.to_f) - today_credit_payment_amount.to_f ).to_f, :delimiter => ',') %>
+
+
\ No newline at end of file diff --git a/app/views/settings/membership_actions/_form.html.erb b/app/views/settings/membership_actions/_form.html.erb index 9f4a2cd5..3084d4ac 100644 --- a/app/views/settings/membership_actions/_form.html.erb +++ b/app/views/settings/membership_actions/_form.html.erb @@ -1,4 +1,4 @@ -<%= simple_form_for(@settings_membership_action) do |f| %> +<%= simple_form_for([:settings,@settings_membership_action]) do |f| %> <%= f.error_notification %>
diff --git a/app/views/settings/membership_actions/edit.html.erb b/app/views/settings/membership_actions/edit.html.erb index 3373d008..cd5cb98a 100644 --- a/app/views/settings/membership_actions/edit.html.erb +++ b/app/views/settings/membership_actions/edit.html.erb @@ -2,5 +2,5 @@ <%= render 'form', settings_membership_action: @settings_membership_action %> -<%= link_to 'Show', @settings_membership_action %> | +<%= link_to 'Show', settings_membership_action_path(@settings_membership_action) %> | <%= link_to 'Back', settings_membership_actions_path %> diff --git a/app/views/settings/membership_actions/index.html.erb b/app/views/settings/membership_actions/index.html.erb index 80b4420e..635fd34c 100644 --- a/app/views/settings/membership_actions/index.html.erb +++ b/app/views/settings/membership_actions/index.html.erb @@ -28,9 +28,9 @@ <%= settings_membership_action.merchant_account_id %> <%= settings_membership_action.created_by %> <%= settings_membership_action.additional_parameter %> - <%= link_to 'Show', settings_membership_action %> + <%= link_to 'Show', settings_membership_action_path(settings_membership_action) %> <%= link_to 'Edit', edit_settings_membership_action_path(settings_membership_action) %> - <%= link_to 'Destroy', settings_membership_action, method: :delete, data: { confirm: 'Are you sure?' } %> + <%= link_to 'Destroy', settings_membership_action_path(settings_membership_action), method: :delete, data: { confirm: 'Are you sure?' } %> <% end %> diff --git a/app/views/settings/orders/index.html.erb b/app/views/settings/orders/index.html.erb new file mode 100644 index 00000000..bd3df8fb --- /dev/null +++ b/app/views/settings/orders/index.html.erb @@ -0,0 +1,68 @@ +
+
+ +
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + <% @orders.each do |order| %> + + + + + + + + + + + <% end %> + +
+ <%= form_tag settings_orders_path, :method => :get do %> +
+ + +
+ <% end %> +
Order ID TypeCustomerOrder statusOrder dateItems CountAction
<%= order.order_id %><%= order.order_type %><%= order.customer.name rescue '-' %><%= order.status %> <%= order.date.strftime("%d-%m-%Y") %> <%= order.item_count %> <%= link_to 'Show', settings_order_path(order) %>
+
+ + <%= paginate @orders %> +
+
+ +
+
+ + + + + diff --git a/app/views/settings/orders/show.html.erb b/app/views/settings/orders/show.html.erb new file mode 100644 index 00000000..bd17dadb --- /dev/null +++ b/app/views/settings/orders/show.html.erb @@ -0,0 +1,85 @@ +
+
+ +
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + +
TypeCustomerOrder statusOrder dateOrder By
<%= @order.order_type %><%= @order.customer.name rescue '-' %><%= @order.status %> <%= @order.date.strftime("%d-%m-%Y") %> <%= @order.waiter rescue '-' %>
+

Order Items

+ + + + + + + + + + + + + + + + + <% @order.order_items.each do |order| %> + + + + + + + + + + + + <% end %> + +
Item NameQty Unit PriceTotal PriceOptionStatusOrder ByCreated at
<%= order.item_name %><%= order.qty %><%= order.price %><%= order.qty * order.price %> <%= order.options %> <%= order.order_item_status %> <%= order.item_order_by %> <%= order.created_at.strftime("%d-%m-%Y") %>
+ + Back + +
+
+ +
+
+ + + + + diff --git a/app/views/settings/sales/index.html.erb b/app/views/settings/sales/index.html.erb new file mode 100644 index 00000000..c53a6e8d --- /dev/null +++ b/app/views/settings/sales/index.html.erb @@ -0,0 +1,85 @@ +
+
+ +
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + <% @sales.each do |sale| %> + + + + + + + + + + + + <% end %> + +
+ <%= form_tag settings_sales_path, :method => :get do %> +
+ + + + +
+ <% end %> +
Sale Id Receipt no Grand totalTax amountCashierSales statusReceipt DateAction
<%= sale.sale_id %><%= sale.receipt_no %><%= sale.grand_total rescue '-' %><%= sale.total_tax %><%= sale.cashier_name rescue '-' %> <%= sale.sale_status %> <%= sale.receipt_date.strftime("%d-%m-%Y") %> <%= link_to 'Show', settings_sale_path(sale) %>
+
+ + <%= paginate @sales %> +
+
+ +
+
+ + + + + + + diff --git a/app/views/settings/sales/show.html.erb b/app/views/settings/sales/show.html.erb new file mode 100644 index 00000000..484de762 --- /dev/null +++ b/app/views/settings/sales/show.html.erb @@ -0,0 +1,103 @@ +
+
+ +
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + <% @sale.sale_items.each do |s| %> + + + + + + + + + <% end %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Receipt Date Receipt noCashierOSales statusReceipt generated at
<%= @sale.receipt_date.strftime("%d-%M-%Y") %><%= @sale.receipt_no %><%= @sale.cashier rescue '-' %> <%= @sale.sale_status %> <%= @sale.requested_at.strftime("%d-%m-%Y") %>
Sale item name QtyUnit priceTotal pirce Created at
<%=s.product_name rescue ' '%><%=s.qty rescue ' '%><%= number_with_precision(s.price, :precision => 2, :delimiter => ',') rescue ' '%><%= number_with_precision(s.qty * s.price, :precision => 2, :delimiter => ',') rescue ' '%><%=l s.created_at.utc.getlocal , :format => :short rescue ' ' %>
Total<%= number_with_precision(@sale.total_amount, :precision => 2, :delimiter => ',') rescue ' '%>
Tax<%= number_with_precision(@sale.total_tax, :precision => 2, :delimiter => ',') rescue ' '%>
Discount<%= number_with_precision(@sale.total_discount, :precision => 2, :delimiter => ',') rescue ' '%>
Grand Total<%= number_with_precision(@sale.grand_total, :precision => 2, :delimiter => ',') rescue ' '%>
 
Pay Amount<%= number_with_precision(@sale.amount_received, :precision => 2, :delimiter => ',') rescue ' '%>
Change<%= number_with_precision(@sale.amount_changed, :precision => 2, :delimiter => ',') rescue ' '%>
+ + + Back + +
+
+ +
+
+ + + + + diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index c4069679..9952a7bc 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -18,3 +18,7 @@ Rails.application.config.assets.precompile += %w( OQS.css ) Rails.application.config.assets.precompile += %w( OQS.js ) Rails.application.config.assets.precompile += %w( settings.css ) + +# --- Customer/ Customer - Crm ---- +Rails.application.config.assets.precompile += %w( CRM.css ) +Rails.application.config.assets.precompile += %w( CRM.js ) diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb new file mode 100644 index 00000000..bcf4e43b --- /dev/null +++ b/config/initializers/kaminari_config.rb @@ -0,0 +1,10 @@ +Kaminari.configure do |config| + config.default_per_page = 2 + # config.max_per_page = nil + # config.window = 4 + # config.outer_window = 0 + # config.left = 0 + # config.right = 0 + # config.page_method_name = :page + # config.param_name = :page +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 06539571..ced8af0a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,23 +1,17 @@ -# Files in the config/locales directory are used for internationalization -# and are automatically loaded by Rails. If you want to use locales other -# than English, add the necessary files in this directory. -# -# To use the locales, use `I18n.t`: -# -# I18n.t 'hello' -# -# In views, this is aliased to just `t`: -# -# <%= t('hello') %> -# -# To use a different locale, set it with `I18n.locale`: -# -# I18n.locale = :es -# -# This would use the information in config/locales/es.yml. -# -# To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. - en: - hello: "Hello world" + views: + pagination: + first: "« First" + last: "Last »" + previous: "‹ Prev" + next: "Next ›" + truncate: "…" + helpers: + page_entries_info: + one_page: + display_entries: + zero: "No %{entry_name} found" + one: "Displaying 1 %{entry_name}" + other: "Displaying all %{count} %{entry_name}" + more_pages: + display_entries: "Displaying %{entry_name} %{first} - %{last} of %{total} in total" diff --git a/config/routes.rb b/config/routes.rb index 6d7be02e..76e1498c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ require 'sidekiq/web' Rails.application.routes.draw do - + namespace :settings do resources :membership_actions end @@ -51,7 +51,9 @@ Rails.application.routes.draw do #Current active bookings resources :bookings, only: [:index, :show, :create, :update] - resources :customers, only: [:index, :show, :create, :update] + resources :customers + #get customer details by order items + get "customers/get_order/:id" => "customers#get_customer_order" #Generating Invoice and making payments - output render @sale resources :invoices, only: [:index, :show, :create, :update, :destroy ] do @@ -70,22 +72,36 @@ Rails.application.routes.draw do #--------- Cashier ------------# namespace :origami do root "home#index" - get "/:booking_id" => "home#show" do #origami/:booking_id will show - resources :discounts, only: [:index,:new, :create ] #add discount type - resources :customers, only: [:index,:new, :create ] #add customer type + get "/:booking_id" => "home#index" do #origami/:booking_id will show + # resources :discounts, only: [:index,:new, :create ] #add discount type + resources :customers #add customer type end - get "/request_bills/:id" => "request_bills#print" - get "/discount/:id" => "discounts#index" - post "/discount" => "discounts#create" + post '/:booking_id' => 'home#item_show' + + get "/:id/discount" => "discounts#index" + post "/:id/discount" => "discounts#create" + + get "/:id/request_bills" => "request_bills#print" #--------- Payment ------------# get 'sale/:sale_id/payment' => 'payments#show' - post 'payment_process' => 'payments#create' - post 'paypar_payment_process' => 'paypar_payments#create' + post 'payment/cash' => 'payments#create' + post 'payment/paypar' => 'paypar_payments#create' get 'sale/:sale_id/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/payment/others_payment' => "others_payments#index" + # get 'sale/:sale_id/payment/others_payment/:payment_method' => "redeem_payments#index" + + get 'sale/:sale_id/payment/others_payment/MPU' => "mpu#index" + post 'payment/mpu' => "mpu#create" + get 'sale/:sale_id/payment/others_payment/REDEEMREBATE' => "redeem_payments#index" + + #---------Add Customer --------------# + #resources :customers + get '/:sale_id/add_customer', to: "customers#add_customer" + get '/:customer_id/get_customer' => 'home#get_customer' + post '/:sale_id/update_sale' , to: "home#update_sale_by_customer"#update customer id in sale table end #--------- Waiter/Ordering Station ------------# @@ -97,11 +113,10 @@ Rails.application.routes.draw do #--------- Customer Relationship Management ------------# namespace :crm do - root "home#index" #queue number - get 'customers/:sale_id/assign_sale_id', to: "customers#get_sale_id", :as => "assign_sale"#get sale id with customer for crm + root "home#index" resources :customers + resources :dining_queues post "update_booking" , to: "bookings#update_booking", as: "update_booking"#assign and cancel - post "update_sale" , to: "home#update_sale_by_customer"#update customer id in sale table get '/print/:id', to: "home#print_order"#print order for crm end @@ -153,6 +168,10 @@ Rails.application.routes.draw do resources :tax_profiles #lookups resources :lookups + #orders + resources :orders + #sales + resources :sales #cashier_terminals resources :cashier_terminals #order_job_stations @@ -181,12 +200,13 @@ Rails.application.routes.draw do #--------- Reports Controller Sections ------------# namespace :reports do - resources :sales, :only => [:index, :show] - resources :orders, :only => [:index, :show] - resources :customers, :only => [:index, :show] - resources :products, :only => [:index, :show] - resources :inventory, :only => [:index, :show] - resources :employees, :only => [:index, :show] + resources :receipt_no, :only => [:index, :show] + # resources :sales, :only => [:index, :show] + # resources :orders, :only => [:index, :show] + # resources :customers, :only => [:index, :show] + # resources :products, :only => [:index, :show] + # resources :inventory, :only => [:index, :show] + # resources :employees, :only => [:index, :show] end #mount_compendium at: '/report' #, controller: 'reports' diff --git a/db/migrate/20170403140820_create_order_items.rb b/db/migrate/20170403140820_create_order_items.rb index b0f43c32..c5382030 100644 --- a/db/migrate/20170403140820_create_order_items.rb +++ b/db/migrate/20170403140820_create_order_items.rb @@ -13,6 +13,7 @@ class CreateOrderItems < ActiveRecord::Migration[5.1] t.string :options t.json :set_menu_items #this parameter is require to route the items correctly t.boolean :taxable, :null => false, :default => true + t.string :completed_by t.timestamps end end diff --git a/db/migrate/20170403153001_create_payment_method_settings.rb b/db/migrate/20170403153001_create_payment_method_settings.rb index 981d42d3..339a3187 100644 --- a/db/migrate/20170403153001_create_payment_method_settings.rb +++ b/db/migrate/20170403153001_create_payment_method_settings.rb @@ -7,7 +7,7 @@ class CreatePaymentMethodSettings < ActiveRecord::Migration[5.1] t.string :gateway_url t.string :auth_token t.string :merchant_account_id - + t.string :additional_parameters t.timestamps end end diff --git a/db/migrate/20170403174029_create_sale_orders.rb b/db/migrate/20170403174029_create_sale_orders.rb index e2b3fe40..a786163b 100644 --- a/db/migrate/20170403174029_create_sale_orders.rb +++ b/db/migrate/20170403174029_create_sale_orders.rb @@ -1,8 +1,8 @@ class CreateSaleOrders < ActiveRecord::Migration[5.1] def change create_table :sale_orders, :id => false do |t| - t.primary_key :sale_order_id #custom primary key - to ensure consistence for cloud syncing - + + t.string :sale_order_id, :limit => 16, :primary_key => true t.string :sale_id, foreign_key: true,:limit => 16 t.string :order_id, foreign_key: true, :limit => 16 diff --git a/db/migrate/20170421171849_add_company_address_email.rb b/db/migrate/20170421171849_add_company_address_email.rb deleted file mode 100644 index 3bf6602e..00000000 --- a/db/migrate/20170421171849_add_company_address_email.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddCompanyAddressEmail < ActiveRecord::Migration[5.1] - def change - add_column :order_items, :completed_by, :string - end -end diff --git a/db/migrate/20170608111602_additionparametertopaymentsettings.rb b/db/migrate/20170608111602_additionparametertopaymentsettings.rb deleted file mode 100644 index ec85c209..00000000 --- a/db/migrate/20170608111602_additionparametertopaymentsettings.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Additionparametertopaymentsettings < ActiveRecord::Migration[5.1] - def change - add_column :payment_method_settings, :additional_parameters, :string - end -end diff --git a/db/migrate/20170608104900_create_settings_membership_actions.rb b/db/migrate/20170611084537_create_membership_actions.rb similarity index 55% rename from db/migrate/20170608104900_create_settings_membership_actions.rb rename to db/migrate/20170611084537_create_membership_actions.rb index 2b9dd85d..c980ceac 100644 --- a/db/migrate/20170608104900_create_settings_membership_actions.rb +++ b/db/migrate/20170611084537_create_membership_actions.rb @@ -1,14 +1,14 @@ -class CreateSettingsMembershipActions < ActiveRecord::Migration[5.1] +class CreateMembershipActions < ActiveRecord::Migration[5.1] def change - create_table :settings_membership_actions do |t| - t.string :membership_type + create_table :membership_actions do |t| + t.string :membership_type t.boolean :is_active t.string :gateway_communication_type t.string :gateway_url t.string :auth_token t.string :merchant_account_id t.string :created_by - t.string :additional_parameter + t.json :additional_parameter t.timestamps end diff --git a/db/migrate/20170612031153_create_dining_queues.rb b/db/migrate/20170612031153_create_dining_queues.rb new file mode 100644 index 00000000..3cf26418 --- /dev/null +++ b/db/migrate/20170612031153_create_dining_queues.rb @@ -0,0 +1,12 @@ +class CreateDiningQueues < ActiveRecord::Migration[5.1] + def change + create_table :dining_queues do |t| + t.string :name + t.string :contact_no + t.string :queue_no + t.string :status + + t.timestamps + end + end +end diff --git a/db/seeds.rb b/db/seeds.rb index fc19164d..c802079f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -51,6 +51,10 @@ menu_item_type = Lookup.create([{lookup_type:'menu_item_type', name: 'SIMPLE', v {lookup_type:'menu_item_type', name: 'Set Menu', value: 'setMenu'}, {lookup_type:'menu_item_type', name: 'DIY', value: 'diy'}]) +member_group_type = Lookup.create([{lookup_type:'member_group_type', name: 'Platinum', value: '1'}, + {lookup_type:'member_group_type', name: 'Silver', value: '2'} + ]) + #menu_item_attribute:[size|] menu_item_attribute_type = Lookup.create([{lookup_type:'menu_item_attribute_type', name: 'Size', value: 'size'}]) # {lookup_type:'menu_item_attribute_type', name: 'Spicy', value: 'spicy'}, @@ -136,17 +140,29 @@ zone_queue_station = OrderQueueProcessByZone.create({order_queue_station: zone_o #Create Adminstrator employee admin_employee = Employee.create({name: "Administrator", role: "Administrator", password: "99999", emp_id:"999", created_by: "SYSTEM DEFAULT"}) -#Account for Menu Item Type (eg: Food, Beverage) -food = Account.create({title: "Food", account_type: "0"}) -beverage = Account.create({title: "Beverage", account_type: "1"}) - order_station1=PrintSetting.create({name: "OrderItemPdf", unique_code: "OrderItemPdf", printer_name: "EPSON-TM-T82-S-A"}) order_station2=PrintSetting.create({name: "Order Summary", unique_code: "OrderSummaryPdf", printer_name: "EPSON-TM-T82-S-A"}) request_bill_printer=PrintSetting.create({name: "Receipt Bill", unique_code: "ReceiptBillPdf", printer_name: "EPSON-TM-T82-S-A"}) +crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrderPdf", printer_name: "EPSON-TM-T82-S-A"}) + +member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "http://192.168.1.47:3006",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}) + +member_actions= MembershipAction.create([{membership_type:"get_account_balance",gateway_url:"/api/membership_campaigns/get_correspond_account_data",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, + {membership_type:"redeem",gateway_url:"/api/membership_campaigns/redeem",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, + {membership_type:"create_membership_customer",gateway_url:"/api/generic_customer/create_membership_customer",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, + {membership_type:"update_membership_customer",gateway_url:"/api/generic_customer/update_membership_customer",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, + {membership_type:"get_all_member_group",gateway_url:"/api/member_group/get_all_member_group",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, + {membership_type:"rebate",gateway_url:"/api/membership_campaigns/rebate",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, + {membership_type:"get_all_member_account",gateway_url:"/api/generic_customer/get_membership_data",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"} + ]) + +payment_methods = PaymentMethodSetting.create({payment_method:"MPU",gateway_url: "http//192.168.1.47:3006"}) + +payment_methods = PaymentMethodSetting.create({payment_method:"REDEEMREBATE",gateway_url: "http://192.168.1.47:3006",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}) + # shop = Shop.create( -# {name: "Beauty In The Pot", address: "address", township: "Yangon", city: "Yangon", state: "Yangon", -# country: "Myanmar", phone_no: "09123456789", reservation_no: "bip000001", license: "license", +# {name: "Beauty In The Pot", address: "address", township: "Yangon", city: "Yangon", state: "Yangon", +# country: "Myanmar", phone_no: "09123456789", reservation_no: "bip000001", license: "license", # activated_at: "2017-06-06", license_data: "license_data", base_currency: "Ks", id_prefix: "abc"} # ) - diff --git a/dump.rdb b/dump.rdb index 35382006..4d2c7d9e 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/lib/tasks/clear_data.rake b/lib/tasks/clear_data.rake new file mode 100644 index 00000000..c9e0fe22 --- /dev/null +++ b/lib/tasks/clear_data.rake @@ -0,0 +1,16 @@ +namespace :clear do + desc "Clear Data" + task :data => :environment do + BookingOrder.delete_all + Booking.delete_all + OrderItem.delete_all + AssignedOrderItem.delete_all + Order.delete_all + SaleOrder.delete_all + SaleItem.delete_all + Sale.delete_all + SaleAudit.delete_all + SalePayment.delete_all + puts "Clear Data Done." + end +end diff --git a/spec/controllers/crm/bookings_controller_spec.rb b/spec/controllers/crm/bookings_controller_spec.rb deleted file mode 100644 index 9a65a516..00000000 --- a/spec/controllers/crm/bookings_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Crm::BookingsController, type: :controller do - -end diff --git a/spec/controllers/crm/customers_controller_spec.rb b/spec/controllers/crm/customers_controller_spec.rb deleted file mode 100644 index 0a1a4ff6..00000000 --- a/spec/controllers/crm/customers_controller_spec.rb +++ /dev/null @@ -1,159 +0,0 @@ -require 'rails_helper' - -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. - -RSpec.describe Crm::CustomersController, type: :controller do - - # This should return the minimal set of attributes required to create a valid - # Crm::Customer. As you add validations to Crm::Customer, be sure to - # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } - - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # Crm::CustomersController. Be sure to keep this updated too. - let(:valid_session) { {} } - - describe "GET #index" do - it "assigns all crm_customers as @crm_customers" do - customer = Crm::Customer.create! valid_attributes - get :index, params: {}, session: valid_session - expect(assigns(:crm_customers)).to eq([customer]) - end - end - - describe "GET #show" do - it "assigns the requested crm_customer as @crm_customer" do - customer = Crm::Customer.create! valid_attributes - get :show, params: {id: customer.to_param}, session: valid_session - expect(assigns(:crm_customer)).to eq(customer) - end - end - - describe "GET #new" do - it "assigns a new crm_customer as @crm_customer" do - get :new, params: {}, session: valid_session - expect(assigns(:crm_customer)).to be_a_new(Crm::Customer) - end - end - - describe "GET #edit" do - it "assigns the requested crm_customer as @crm_customer" do - customer = Crm::Customer.create! valid_attributes - get :edit, params: {id: customer.to_param}, session: valid_session - expect(assigns(:crm_customer)).to eq(customer) - end - end - - describe "POST #create" do - context "with valid params" do - it "creates a new Crm::Customer" do - expect { - post :create, params: {crm_customer: valid_attributes}, session: valid_session - }.to change(Crm::Customer, :count).by(1) - end - - it "assigns a newly created crm_customer as @crm_customer" do - post :create, params: {crm_customer: valid_attributes}, session: valid_session - expect(assigns(:crm_customer)).to be_a(Crm::Customer) - expect(assigns(:crm_customer)).to be_persisted - end - - it "redirects to the created crm_customer" do - post :create, params: {crm_customer: valid_attributes}, session: valid_session - expect(response).to redirect_to(Crm::Customer.last) - end - end - - context "with invalid params" do - it "assigns a newly created but unsaved crm_customer as @crm_customer" do - post :create, params: {crm_customer: invalid_attributes}, session: valid_session - expect(assigns(:crm_customer)).to be_a_new(Crm::Customer) - end - - it "re-renders the 'new' template" do - post :create, params: {crm_customer: invalid_attributes}, session: valid_session - expect(response).to render_template("new") - end - end - end - - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested crm_customer" do - customer = Crm::Customer.create! valid_attributes - put :update, params: {id: customer.to_param, crm_customer: new_attributes}, session: valid_session - customer.reload - skip("Add assertions for updated state") - end - - it "assigns the requested crm_customer as @crm_customer" do - customer = Crm::Customer.create! valid_attributes - put :update, params: {id: customer.to_param, crm_customer: valid_attributes}, session: valid_session - expect(assigns(:crm_customer)).to eq(customer) - end - - it "redirects to the crm_customer" do - customer = Crm::Customer.create! valid_attributes - put :update, params: {id: customer.to_param, crm_customer: valid_attributes}, session: valid_session - expect(response).to redirect_to(customer) - end - end - - context "with invalid params" do - it "assigns the crm_customer as @crm_customer" do - customer = Crm::Customer.create! valid_attributes - put :update, params: {id: customer.to_param, crm_customer: invalid_attributes}, session: valid_session - expect(assigns(:crm_customer)).to eq(customer) - end - - it "re-renders the 'edit' template" do - customer = Crm::Customer.create! valid_attributes - put :update, params: {id: customer.to_param, crm_customer: invalid_attributes}, session: valid_session - expect(response).to render_template("edit") - end - end - end - - describe "DELETE #destroy" do - it "destroys the requested crm_customer" do - customer = Crm::Customer.create! valid_attributes - expect { - delete :destroy, params: {id: customer.to_param}, session: valid_session - }.to change(Crm::Customer, :count).by(-1) - end - - it "redirects to the crm_customers list" do - customer = Crm::Customer.create! valid_attributes - delete :destroy, params: {id: customer.to_param}, session: valid_session - expect(response).to redirect_to(crm_customers_url) - end - end - -end diff --git a/spec/controllers/origami/redeem_payments_controller_spec.rb b/spec/controllers/origami/redeem_payments_controller_spec.rb new file mode 100644 index 00000000..22e705d7 --- /dev/null +++ b/spec/controllers/origami/redeem_payments_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Origami::RedeemPaymentsController, type: :controller do + +end diff --git a/spec/controllers/settings/orders_controller_spec.rb b/spec/controllers/settings/orders_controller_spec.rb new file mode 100644 index 00000000..e715e84f --- /dev/null +++ b/spec/controllers/settings/orders_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Settings::OrdersController, type: :controller do + +end diff --git a/spec/helpers/crm/dining_queues_helper_spec.rb b/spec/helpers/crm/dining_queues_helper_spec.rb new file mode 100644 index 00000000..1f104e6b --- /dev/null +++ b/spec/helpers/crm/dining_queues_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Crm::DiningQueuesHelper. For example: +# +# describe Crm::DiningQueuesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Crm::DiningQueuesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/origami/redeem_payments_helper_spec.rb b/spec/helpers/origami/redeem_payments_helper_spec.rb new file mode 100644 index 00000000..580d73ff --- /dev/null +++ b/spec/helpers/origami/redeem_payments_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Origami::RedeemPaymentsHelper. For example: +# +# describe Origami::RedeemPaymentsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Origami::RedeemPaymentsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/settings/orders_helper_spec.rb b/spec/helpers/settings/orders_helper_spec.rb new file mode 100644 index 00000000..028e7209 --- /dev/null +++ b/spec/helpers/settings/orders_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Settings::OrdersHelper. For example: +# +# describe Settings::OrdersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Settings::OrdersHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/dining_queue_spec.rb b/spec/models/dining_queue_spec.rb new file mode 100644 index 00000000..185068c3 --- /dev/null +++ b/spec/models/dining_queue_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe DiningQueue, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/crm/crm_dining_queues_spec.rb b/spec/requests/crm/crm_dining_queues_spec.rb new file mode 100644 index 00000000..f8261136 --- /dev/null +++ b/spec/requests/crm/crm_dining_queues_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Crm::DiningQueues", type: :request do + describe "GET /crm_dining_queues" do + it "works! (now write some real specs)" do + get crm_dining_queues_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/crm/dining_queues_routing_spec.rb b/spec/routing/crm/dining_queues_routing_spec.rb new file mode 100644 index 00000000..20d81871 --- /dev/null +++ b/spec/routing/crm/dining_queues_routing_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +RSpec.describe Crm::DiningQueuesController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/crm/dining_queues").to route_to("crm/dining_queues#index") + end + + it "routes to #new" do + expect(:get => "/crm/dining_queues/new").to route_to("crm/dining_queues#new") + end + + it "routes to #show" do + expect(:get => "/crm/dining_queues/1").to route_to("crm/dining_queues#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/crm/dining_queues/1/edit").to route_to("crm/dining_queues#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/crm/dining_queues").to route_to("crm/dining_queues#create") + end + + it "routes to #update via PUT" do + expect(:put => "/crm/dining_queues/1").to route_to("crm/dining_queues#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/crm/dining_queues/1").to route_to("crm/dining_queues#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/crm/dining_queues/1").to route_to("crm/dining_queues#destroy", :id => "1") + end + + end +end diff --git a/spec/views/crm/dining_queues/edit.html.erb_spec.rb b/spec/views/crm/dining_queues/edit.html.erb_spec.rb new file mode 100644 index 00000000..d6649b45 --- /dev/null +++ b/spec/views/crm/dining_queues/edit.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "crm/dining_queues/edit", type: :view do + before(:each) do + @crm_dining_queue = assign(:crm_dining_queue, Crm::DiningQueue.create!( + :name => "MyString", + :contact => "MyString", + :queue_no => "MyString" + )) + end + + it "renders the edit crm_dining_queue form" do + render + + assert_select "form[action=?][method=?]", crm_dining_queue_path(@crm_dining_queue), "post" do + + assert_select "input[name=?]", "crm_dining_queue[name]" + + assert_select "input[name=?]", "crm_dining_queue[contact]" + + assert_select "input[name=?]", "crm_dining_queue[queue_no]" + end + end +end diff --git a/spec/views/crm/dining_queues/index.html.erb_spec.rb b/spec/views/crm/dining_queues/index.html.erb_spec.rb new file mode 100644 index 00000000..b368f621 --- /dev/null +++ b/spec/views/crm/dining_queues/index.html.erb_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe "crm/dining_queues/index", type: :view do + before(:each) do + assign(:crm_dining_queues, [ + Crm::DiningQueue.create!( + :name => "Name", + :contact => "Contact", + :queue_no => "Queue No" + ), + Crm::DiningQueue.create!( + :name => "Name", + :contact => "Contact", + :queue_no => "Queue No" + ) + ]) + end + + it "renders a list of crm/dining_queues" do + render + assert_select "tr>td", :text => "Name".to_s, :count => 2 + assert_select "tr>td", :text => "Contact".to_s, :count => 2 + assert_select "tr>td", :text => "Queue No".to_s, :count => 2 + end +end diff --git a/spec/views/crm/dining_queues/new.html.erb_spec.rb b/spec/views/crm/dining_queues/new.html.erb_spec.rb new file mode 100644 index 00000000..433d153d --- /dev/null +++ b/spec/views/crm/dining_queues/new.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "crm/dining_queues/new", type: :view do + before(:each) do + assign(:crm_dining_queue, Crm::DiningQueue.new( + :name => "MyString", + :contact => "MyString", + :queue_no => "MyString" + )) + end + + it "renders new crm_dining_queue form" do + render + + assert_select "form[action=?][method=?]", crm_dining_queues_path, "post" do + + assert_select "input[name=?]", "crm_dining_queue[name]" + + assert_select "input[name=?]", "crm_dining_queue[contact]" + + assert_select "input[name=?]", "crm_dining_queue[queue_no]" + end + end +end diff --git a/spec/views/crm/dining_queues/show.html.erb_spec.rb b/spec/views/crm/dining_queues/show.html.erb_spec.rb new file mode 100644 index 00000000..93d2554a --- /dev/null +++ b/spec/views/crm/dining_queues/show.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "crm/dining_queues/show", type: :view do + before(:each) do + @crm_dining_queue = assign(:crm_dining_queue, Crm::DiningQueue.create!( + :name => "Name", + :contact => "Contact", + :queue_no => "Queue No" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Name/) + expect(rendered).to match(/Contact/) + expect(rendered).to match(/Queue No/) + end +end diff --git a/test/system/dining_queues_test.rb b/test/system/dining_queues_test.rb new file mode 100644 index 00000000..680e9dc1 --- /dev/null +++ b/test/system/dining_queues_test.rb @@ -0,0 +1,9 @@ +require "application_system_test_case" + +class Crm::DiningQueuesTest < ApplicationSystemTestCase + # test "visiting the index" do + # visit crm_dining_queues_url + # + # assert_selector "h1", text: "Crm::DiningQueue" + # end +end