From a5c59640d69af93aa1f989b03ec3337f72abf779 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 7 Jun 2018 11:05:19 +0630 Subject: [PATCH] Pull from master --- app/assets/javascripts/addorder.js | 21 +- app/assets/javascripts/custom.js | 2 +- app/assets/javascripts/order_reservation.js | 6 +- app/assets/javascripts/origami.js | 1 - .../order_reservation_controller.rb | 18 +- app/controllers/crm/customers_controller.rb | 487 +++++++++--------- app/controllers/home_controller.rb | 2 +- .../origami/dashboard_controller.rb | 37 +- app/models/customer.rb | 2 +- app/models/menu_category.rb | 13 +- app/models/order_reservation.rb | 19 +- app/models/sale.rb | 28 +- app/views/origami/payments/show.html.erb | 6 +- .../pending_order/completed_sale.html.erb | 138 ++++- config/routes.rb | 2 +- 15 files changed, 484 insertions(+), 298 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 3fea4c6b..a9bd453a 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -6,8 +6,8 @@ $(function() { //click menu sidebar menu category $(".product").on("click", function(){ - var url = $(this).attr('data-ref'); - show_product_list(url); + // /var url = $(this).attr('data-ref'); + // /show_product_list(url); }); //show menu item list when click menu category function show_product_list(url_item){ @@ -24,6 +24,7 @@ $(function() { if (type ==-1 && modify_order == -1){ url_item = url_item } + console.log(url_item) //Start Ajax $.ajax({ type: "GET", @@ -56,16 +57,17 @@ $(function() { image_path = "/image/logo.png"; } - row = '
' - +'
' + row = '
' + +'
' + +'
' +'
'+ product[field].name +'
' +"'; $('.menu_items_list').append(row); } @@ -500,6 +503,7 @@ $(function() { //click item row for add order $(document).on('click', '.menu_item_box', function(event){ + $('.attributes-list').empty(); $('.options-list').empty(); $('#modal_box_img').empty(); @@ -515,7 +519,6 @@ $(function() { $('.add_to_order').removeAttr('data-options'); $('#count').val(1); - change_qty_plus_minus("count","plus","minus"); // data = $(this).parent().children().children('.add_icon'); diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index e14cc205..64835a3b 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -168,4 +168,4 @@ function audioPlayBackground(shop_code,audio){ audio.play(); // },10000); } -/* end order reservation function */ +/* end order reservation function */ \ No newline at end of file diff --git a/app/assets/javascripts/order_reservation.js b/app/assets/javascripts/order_reservation.js index f187a2db..e51086b5 100644 --- a/app/assets/javascripts/order_reservation.js +++ b/app/assets/javascripts/order_reservation.js @@ -1,3 +1,5 @@ +//= require custom.js + $(function() { $("#discount").hide(); $(".expected_time").hide(); @@ -307,8 +309,8 @@ function show_order_detail(url,sr_no){ item_price = items[i].unit_price; } var total = items[i].qty * item_price; - if(items[i].options!='[]'){ - row = '' + if(items[i].options!='[]' && items[i].options!="" && items[i].options!=null){ + row = '' +''+items[i].item_name +'
' +' '+items[i].options+'
'+ diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 67911d9e..32c7f81e 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -15,7 +15,6 @@ //= require BSBMaterial/turbolink_admin.js //= require BSBMaterial/demo.js //= require custom.js -//= require order_reservation.js /* Constant Varaibles */ _CREDIT_PAYMENTS_ = "/   CREDIT PAYMENTS"; diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 6d323f52..9fb392fe 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -14,14 +14,20 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController end if status - check_customer = Customer.find_by_email_and_membership_id_and_customer_type(params[:email],params[:membership_id],'Doemal') - if !check_customer.nil? - customer_id = check_customer.customer_id + if params[:customer_id] && !params[:customer_id].nil? + customer = OrderReservation.addCustomer(params) + customer_id = customer.customer_id else - customer = OrderReservation.addCustomer(params) - customer_id = customer.id + check_customer = Customer.find_by_email_and_membership_id_and_customer_type(params[:email],params[:membership_id],'Doemal') + if !check_customer.nil? + customer_id = check_customer.customer_id + else + customer = OrderReservation.addCustomer(params) + customer_id = customer.customer_id + end end - if !customer_id.nil? + + if customer_id.nil? render :json => { :status => false, :message => "email and customer are already existed!" } else render :json => { :status => true, :data => { :customer_id => customer_id} } diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 97f75135..18e87308 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -98,14 +98,154 @@ class Crm::CustomersController < BaseCrmController # POST /crm/customers.json def create # Remove "" default first - params[:customer][:tax_profiles].delete_at(0) - @crm_customers = Customer.new(customer_params) + params[:customer][:tax_profiles].delete_at(0) + @checked_contact = Customer.find_by_contact_no(customer_params[:contact_no]) + if @checked_contact.nil? + respond_to do |format| + @crm_customers = Customer.new(customer_params) - respond_to do |format| - if @crm_customers.save - # update tax profile - customer = Customer.find(@crm_customers.customer_id) - customer.update_attributes(tax_profiles: params[:customer][:tax_profiles]) + if @crm_customers.save + # update tax profile + customer = Customer.find(@crm_customers.customer_id) + customer.update_attributes(tax_profiles: params[:customer][:tax_profiles]) + name = customer_params[:name] + phone = customer_params[:contact_no] + email = customer_params[:email] + dob = customer_params[:date_of_birth] + address = customer_params[:address] + nrc = customer_params[:nrc_no] + card_no = customer_params[:card_no] + paypar_account_no = customer_params[:paypar_account_no] + member_group_id = params[:member_group_id] + + if member_group_id.present? + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("create_membership_customer") + merchant_uid = memberaction.merchant_account_id.to_s + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + + member_params = { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc,card_no:card_no, + member_group_id: member_group_id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json + + # Check for paypar account exists + # if paypar_account_no != nil || paypar_account_no != '' + if paypar_account_no.present? + member_params = { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc,card_no:card_no, + paypar_account_no: paypar_account_no, + member_group_id: member_group_id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json + end + + begin + response = HTTParty.post(url, + :body => member_params, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' + }, + :timeout => 10 + ) + + rescue HTTParty::Error + response = {"status" => false, "message" => "Can't open membership server "} + + rescue Net::OpenTimeout + response = {"status" => false, "message" => "Can't open membership server "} + + rescue OpenURI::HTTPError + response = {"status" => false, "message" => "Can't open membership server "} + + rescue SocketError + response = {"status" => false, "message" => "Can't open membership server "} + end + Rails.logger.debug "--------------Create Member---------" + Rails.logger.debug response.to_json + if response["status"] == true + customer = Customer.find(@crm_customers.customer_id) + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) + + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], 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 + customer = Customer.find(@crm_customers.customer_id) + + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + else + status = customer.update_attributes(membership_type:member_group_id) + end + + # When paypar account no not exist in paypar + if response["message"] == "Account has not exist." + customer.destroy + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer cannot created.' + response["message"]} + else + format.html { redirect_to crm_customers_path, notice: 'Customer cannot created.' + response["message"] } + end + end + + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created.' + response["message"]} + else + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' + response["message"] } + end + end + else + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created. noted'} + else + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created. ' } + end + end + else + if params[:sale_id] + flash[:errors] = @crm_customers.errors + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]} + format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + else + flash[:errors] = @crm_customers.errors + format.html { redirect_to crm_customers_path} + format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + end + end + end + else + flash[:errors] = {"contact_no":["has already been taken"]} + respond_to do |format| + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]} + else + format.html { redirect_to crm_customers_path} + end + format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + end + end #end of contact no checked + end + # PATCH/PUT /crm/customers/1 + # PATCH/PUT /crm/customers/1.json + def update + # Remove "" default first + params[:customer][:tax_profiles].delete_at(0) + @checked_contact = nil + @existed_contact = Customer.find_by_customer_id_and_contact_no(customer_params[:id], customer_params[:contact_no]) + if @existed_contact.nil? + @checked_contact = Customer.find_by_contact_no(customer_params[:contact_no]) + end + if !@existed_contact.nil? || @checked_contact.nil? + respond_to do |format| + if @crm_customer.update(customer_params) + # update tax profile + @crm_customer.update_attributes(tax_profiles: params[:customer][:tax_profiles]) name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] @@ -114,9 +254,10 @@ class Crm::CustomersController < BaseCrmController nrc = customer_params[:nrc_no] card_no = customer_params[:card_no] paypar_account_no = customer_params[:paypar_account_no] - member_group_id = params[:member_group_id] + id = @crm_customer.membership_id + member_group_id = params[:member_group_id] - if member_group_id.present? + if !id.present? && !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s @@ -124,255 +265,139 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - member_group_id: member_group_id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json + dob: dob,address: address,nrc:nrc,card_no:card_no, + member_group_id: member_group_id, + id:id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json # Check for paypar account exists # if paypar_account_no != nil || paypar_account_no != '' if paypar_account_no.present? member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - paypar_account_no: paypar_account_no, - member_group_id: member_group_id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json - end + dob: dob,address: address,nrc:nrc,card_no:card_no, + paypar_account_no: paypar_account_no, + member_group_id: member_group_id, + id:id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json + end begin response = HTTParty.post(url, :body => member_params, :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json; version=3' + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' }, :timeout => 10 - ) + ) + rescue Net::OpenTimeout + response = { status: false } - rescue HTTParty::Error - response = {"status" => false, "message" => "Can't open membership server "} + rescue OpenURI::HTTPError + response = { status: false} - rescue Net::OpenTimeout - response = {"status" => false, "message" => "Can't open membership server "} - - rescue OpenURI::HTTPError - response = {"status" => false, "message" => "Can't open membership server "} - - rescue SocketError - response = {"status" => false, "message" => "Can't open membership server "} + rescue SocketError + response = { status: false} end - Rails.logger.debug "--------------Create Member---------" + customer = Customer.find(@crm_customer.customer_id) + Rails.logger.debug "--------Update Member response -------" Rails.logger.debug response.to_json if response["status"] == true - customer = Customer.find(@crm_customers.customer_id) - status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) + + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) - if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], 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 } + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated'} else - customer = Customer.find(@crm_customers.customer_id) - - # Check membership id and bind to user - if response["membership_id"] != nil - status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) - else - status = customer.update_attributes(membership_type:member_group_id) - end - - # When paypar account no not exist in paypar - if response["message"] == "Account has not exist." - customer.destroy - if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer cannot created.' + response["message"]} - else - format.html { redirect_to crm_customers_path, notice: 'Customer cannot created.' + response["message"] } - end - end - - if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created.' + response["message"]} - else - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' + response["message"] } - end - end - else - if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created. noted'} + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) else - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created. ' } - end - end - else + status = customer.update_attributes(membership_type:member_group_id) + end - if params[:sale_id] - flash[:errors] = @crm_customers.errors - format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]} - format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + format.html { redirect_to crm_customers_path, notice: response["error"] } + end else - flash[:errors] = @crm_customers.errors - format.html { redirect_to crm_customers_path} - format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("update_membership_customer") + merchant_uid = memberaction.merchant_account_id.to_s + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + + member_params = { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc,card_no:card_no, + member_group_id: member_group_id, + id:id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json + + # Check for paypar account exists + if paypar_account_no.present? + member_params = { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc,card_no:card_no, + paypar_account_no: paypar_account_no, + member_group_id: member_group_id, + id:id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json + end + + begin + response = HTTParty.post(url, + :body => member_params, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' + }, + :timeout => 10 + ) + rescue Net::OpenTimeout + response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} + end + Rails.logger.debug "--------Update Member response -------" + Rails.logger.debug response.to_json + if response["status"] == true + customer = Customer.find(@crm_customer.customer_id) + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + else + status = customer.update_attributes(membership_type:member_group_id ) + end + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } + format.json { render :show, status: :ok, location: @crm_customer } + else + customer = Customer.find(@crm_customer.customer_id) + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + else + status = customer.update_attributes(membership_type:member_group_id ) + end + format.html { redirect_to crm_customers_path, notice: response["message"] } + end end - end - - end -end - # PATCH/PUT /crm/customers/1 - # PATCH/PUT /crm/customers/1.json - def update - # Remove "" default first - params[:customer][:tax_profiles].delete_at(0) - respond_to do |format| - if @crm_customer.update(customer_params) - # update tax profile - @crm_customer.update_attributes(tax_profiles: params[:customer][:tax_profiles]) - name = customer_params[:name] - phone = customer_params[:contact_no] - email = customer_params[:email] - dob = customer_params[:date_of_birth] - address = customer_params[:address] - nrc = customer_params[:nrc_no] - card_no = customer_params[:card_no] - paypar_account_no = customer_params[:paypar_account_no] - id = @crm_customer.membership_id - member_group_id = params[:member_group_id] - - if !id.present? && !member_group_id.nil? - membership = MembershipSetting.find_by_membership_type("paypar_url") - memberaction = MembershipAction.find_by_membership_type("create_membership_customer") - merchant_uid = memberaction.merchant_account_id.to_s - auth_token = memberaction.auth_token.to_s - url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - - member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - member_group_id: member_group_id, - id:id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json - - # Check for paypar account exists - # if paypar_account_no != nil || paypar_account_no != '' - if paypar_account_no.present? - member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - paypar_account_no: paypar_account_no, - member_group_id: member_group_id, - id:id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json - end - - begin - response = HTTParty.post(url, - :body => member_params, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json; version=3' - }, - :timeout => 10 - ) - rescue Net::OpenTimeout - response = { status: false } - - rescue OpenURI::HTTPError - response = { status: false} - - rescue SocketError - response = { status: false} - end - customer = Customer.find(@crm_customer.customer_id) - Rails.logger.debug "--------Update Member response -------" - Rails.logger.debug response.to_json - if response["status"] == true - - status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) - - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated'} - else - # Check membership id and bind to user - if response["membership_id"] != nil - status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) - else - status = customer.update_attributes(membership_type:member_group_id) - end - - format.html { redirect_to crm_customers_path, notice: response["error"] } - end else - membership = MembershipSetting.find_by_membership_type("paypar_url") - memberaction = MembershipAction.find_by_membership_type("update_membership_customer") - merchant_uid = memberaction.merchant_account_id.to_s - auth_token = memberaction.auth_token.to_s - url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - - member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - member_group_id: member_group_id, - id:id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json - - # Check for paypar account exists - if paypar_account_no.present? - member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - paypar_account_no: paypar_account_no, - member_group_id: member_group_id, - id:id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json - end - - begin - response = HTTParty.post(url, - :body => member_params, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json; version=3' - }, - :timeout => 10 - ) - rescue Net::OpenTimeout - response = { status: false } - - rescue OpenURI::HTTPError - response = { status: false} - - rescue SocketError - response = { status: false} - end - Rails.logger.debug "--------Update Member response -------" - Rails.logger.debug response.to_json - if response["status"] == true - customer = Customer.find(@crm_customer.customer_id) - # Check membership id and bind to user - if response["membership_id"] != nil - status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) - else - status = customer.update_attributes(membership_type:member_group_id ) - end - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } - format.json { render :show, status: :ok, location: @crm_customer } - else - customer = Customer.find(@crm_customer.customer_id) - # Check membership id and bind to user - if response["membership_id"] != nil - status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) - else - status = customer.update_attributes(membership_type:member_group_id ) - end - format.html { redirect_to crm_customers_path, notice: response["message"] } - end + flash[:errors] = @crm_customer.errors + format.html { redirect_to crm_customers_path} + format.json { render json: @crm_customer.errors, status: :unprocessable_entity } end - - else - - flash[:errors] = @crm_customer.errors - format.html { redirect_to crm_customers_path} - format.json { render json: @crm_customer.errors, status: :unprocessable_entity } end - + else + flash[:errors] = {"contact_no":["has already been taken"]} + respond_to do |format| + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]} + else + format.html { redirect_to crm_customers_path} + end + format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + end end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index e23da859..325cb241 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -67,7 +67,7 @@ class HomeController < ApplicationController redirect_to origami_root_path elsif @employee.role == "waiter" session[:session_token] = @employee.token_session - redirect_to origami_dashboard_path + route_by_role(@employee) elsif @employee.role == "account" session[:session_token] = @employee.token_session redirect_to reports_dailysale_index_path diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index a633c9e1..ab7bde82 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -25,15 +25,18 @@ class Origami::DashboardController < BaseOrigamiController @sale_data = Array.new @total_payment_methods = Sale.total_payment_methods(today,current_user) - - @total_payment_methods.each do |payment| - if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" - pay = Sale.payment_sale('card', today, current_user) - @sale_data.push({'card' => pay.payment_amount}) - else - pay = Sale.payment_sale(payment.payment_method, today, current_user) - @sale_data.push({payment.payment_method => pay.payment_amount}) - end + if !@total_payment_methods.nil? + @total_payment_methods.each do |payment| + if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" + pay = Sale.payment_sale('card', today, current_user) + @sale_data.push({'card' => pay.payment_amount}) + else + pay = Sale.payment_sale(payment.payment_method, today, current_user) + @sale_data.push({payment.payment_method => pay.payment_amount}) + end + end + else + @sale_data = nil end @summ_sale = Sale.summary_sale_receipt(today,current_user) @total_customer = Sale.total_customer(today,current_user) @@ -45,12 +48,16 @@ class Origami::DashboardController < BaseOrigamiController @total_order = Sale.total_order(today,current_user) @total_accounts = Sale.total_account(today,current_user) @account_data = Array.new - @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today,current_user) - if !acc.nil? - @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) - end - end + if !@total_accounts.nil? + @total_accounts.each do |account| + acc = Sale.account_data(account.account_id, today,current_user) + if !acc.nil? + @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) + end + end + else + @account_data = nil + end @top_items = Sale.top_items(today,current_user) @total_foc_items = Sale.total_foc_items(today,current_user) diff --git a/app/models/customer.rb b/app/models/customer.rb index b05caaf6..a88f79c0 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -10,7 +10,7 @@ class Customer < ApplicationRecord has_many :sales validates_presence_of :name, :contact_no, :email #,:card_no - validates :contact_no, uniqueness: true, numericality: true + validates :contact_no, numericality: true #uniqueness: true, validates :email, uniqueness: true,format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create } # validates :card_no, uniqueness: true # validates :paypar_account_no, uniqueness: true diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 218bacb8..63bdf6ef 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -57,9 +57,15 @@ class MenuCategory < ApplicationRecord to = 24 to = to * 3600 + to_t.min* 60 + to_t.sec else - h += 24 to = h*3600 + to_t.min* 60 + to_t.sec + c = current_t.hour + if c < 12 + + c +=24 + current = c*3600 + current_t.min* 60 + current_t.sec + + end end else # (after) noon if h > 12 @@ -72,6 +78,7 @@ class MenuCategory < ApplicationRecord day = Date.today.wday dayresult = menu.valid_days.include?(day.to_s) + if current.between?(from, to) && menu.valid_days.include?(day.to_s) return true else @@ -108,3 +115,7 @@ class MenuCategory < ApplicationRecord end end + + + + diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 4e9235dc..67fef50f 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -22,7 +22,11 @@ class OrderReservation < ApplicationRecord else gender = "Male" end - customer = Customer.new + if params[:customer_id] && !params[:customer_id].nil? + customer = Customer.find(params[:customer_id]) + else + customer = Customer.new + end customer.name = params[:name] customer.email = params[:email] customer.contact_no = params[:contact_no] ? params[:contact_no] : '' @@ -33,7 +37,6 @@ class OrderReservation < ApplicationRecord customer.customer_type = "Doemal" customer.tax_profiles = ["2"] customer.save - # unless customer.valid? # render json: { # status: 422, @@ -319,13 +322,10 @@ class OrderReservation < ApplicationRecord if order_reservation.length > 0 if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - ActionCable.server.broadcast "check_new_order_channel",data: order_reservation, shop_code: shop_code,from:from else from = "" end - # if ENV["SERVER_MODE"] == 'cloud' - # ActionCable.server.broadcast "check_new_order_channel",data: order_reservation, shop_code: shop_code - # end + ActionCable.server.broadcast "check_new_order_channel",data: order_reservation, shop_code: shop_code,from:from end end @@ -340,13 +340,10 @@ class OrderReservation < ApplicationRecord if order_reservation.length > 0 if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - ActionCable.server.broadcast "check_order_send_to_kitchen_channel",data: order_reservation, shop_code: shop_code,from:from else from = "" end - # if ENV["SERVER_MODE"] == 'cloud' - # ActionCable.server.broadcast "check_order_send_to_kitchen_channel",data: order_reservation, shop_code: shop_code - # end + ActionCable.server.broadcast "check_order_send_to_kitchen_channel",data: order_reservation, shop_code: shop_code,from:from end end @@ -361,10 +358,10 @@ class OrderReservation < ApplicationRecord if order_reservation.length > 0 if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - ActionCable.server.broadcast "check_order_ready_to_delivery_channel",data: order_reservation, shop_code: shop_code,from:from else from = "" end + ActionCable.server.broadcast "check_order_ready_to_delivery_channel",data: order_reservation, shop_code: shop_code,from:from end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 790e52f3..6c5ed5b6 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -870,9 +870,9 @@ def self.get_item_query(type) elsif type == "discount" sale_type = "i.status = 'Discount'" elsif type == "foc" - sale_type = "i.status = 'foc' and i.qty > 0" + sale_type = "i.status = 'foc' and i.item_instance_code IS NOT NULL and i.qty > 0" elsif type == "void" - sale_type = "i.status = 'void' and i.qty > 0" + sale_type = "i.status = 'void' and i.item_instance_code IS NOT NULL and i.qty > 0" elsif type == "other" sale_type = "i.item_instance_code IS NULL" end @@ -907,12 +907,8 @@ end def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) # date_type_selection = get_sql_function_for_report_type(report_type) - if type == "other" - other_charges = self.get_other_charges() - query = self.get_item_query(type) - else - query = self.get_item_query(type) - end + + query = self.get_item_query(type) discount_query = 0 total_card_amount = 0 @@ -921,12 +917,16 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) total_foc_amount = 0 total_grand_total = 0 - other_charges = self.get_other_charges() + if type.nil? || type == 'all' || type == "other" + other_charges = self.get_other_charges() + end product = self.get_product_sale() if shift.present? query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) - other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + end product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) @@ -947,7 +947,9 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) ### => get all sales range in shift_sales elsif shift_sale_range.present? query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) - other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + end product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) @@ -968,7 +970,9 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) else query = query.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) - other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + end product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 9262e05c..ae9458b6 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -35,7 +35,11 @@
Customer : - + <% if @cashier_type == 'quick_service' %> + + <% else %> + <%= @sale_data.customer.name%> + <% end %>
Checkin Time : <%if !@checkin_time.nil?%><%= @checkin_time.utc.getlocal.strftime("%I:%M %p") %> diff --git a/app/views/origami/pending_order/completed_sale.html.erb b/app/views/origami/pending_order/completed_sale.html.erb index 507d698e..21caa906 100644 --- a/app/views/origami/pending_order/completed_sale.html.erb +++ b/app/views/origami/pending_order/completed_sale.html.erb @@ -169,14 +169,79 @@
- + <% if current_user.role != "waiter" %> - - - + <% if @sale.sale_status != 'void' && @sale.sale_status != 'waste' && @sale.sale_status != 'spoile' %> + <% if current_user.role == "cashier" %> + Void + <% else %> +